bugfixing

This commit is contained in:
2020-06-14 15:46:24 +02:00
parent 1e1e127f13
commit 19b28453d3
36 changed files with 175 additions and 97 deletions

View File

@@ -21,7 +21,7 @@ export class FileService {
public async delete(path: string, songId: string, fileId: string) {
const ref = this.storage.ref(path);
await ref.delete().toPromise()
await ref.delete().toPromise();
await this.fileDataService.delete(songId, fileId);
}
}

View File

@@ -34,12 +34,12 @@ export class SongService {
const song = await this.read(songId);
const edits = song.edits ?? [];
const user = await this.userService.currentUser();
edits.push({username: user.name, timestamp: Timestamp.now()})
edits.push({username: user.name, timestamp: Timestamp.now()});
await this.songDataService.update$(songId, {...data, edits});
}
public async new(number: number, title: string): Promise<string> {
return await this.songDataService.add({number, title, status: 'draft', legalType: 'open'})
return await this.songDataService.add({number, title, status: 'draft', legalType: 'open'});
}
public async delete(songId: string): Promise<void> {

View File

@@ -90,7 +90,7 @@ Cool bridge without any chords
const service: TextRenderingService = TestBed.inject(TextRenderingService);
const text = `Strophe
g# F# E g# F# E
text`
text`;
const sections = service.parse(text, null);
expect(sections[0].lines[0].type).toBe(LineType.chord);
expect(sections[0].lines[0].text).toBe('g# F# E g# F# E');

View File

@@ -17,7 +17,9 @@ export class TextRenderingService {
}
public parse(text: string, transpose: TransposeMode): Section[] {
if (!text) return [];
if (!text) {
return [];
}
const arrayOfLines = text.split(/\r?\n/).filter(_ => _);
const indices = {
[SectionType.Bridge]: 0,
@@ -26,18 +28,22 @@ export class TextRenderingService {
};
return arrayOfLines.reduce((array, line) => {
const type = this.getSectionTypeOfLine(line);
if (line.match(this.regexSection)) return [...array, {
type: type,
number: indices[type]++,
lines: []
}];
if (line.match(this.regexSection)) {
return [...array, {
type,
number: indices[type]++,
lines: []
}];
}
array[array.length - 1].lines.push(this.getLineOfLineText(line, transpose));
return array;
}, [] as Section[]);
}
private getLineOfLineText(text: string, transpose: TransposeMode): Line {
if (!text) return null;
if (!text) {
return null;
}
const cords = this.readChords(text);
const hasMatches = cords.length > 0;
const type = hasMatches ? LineType.chord : LineType.text;
@@ -49,16 +55,20 @@ export class TextRenderingService {
}
private getSectionTypeOfLine(line: string): SectionType {
if (!line) return null;
if (!line) {
return null;
}
const match = line.match(this.regexSection);
if (!match || match.length < 2) return null;
if (!match || match.length < 2) {
return null;
}
const typeString = match[1];
switch (typeString) {
case "Strophe":
case 'Strophe':
return SectionType.Verse;
case "Refrain":
case 'Refrain':
return SectionType.Chorus;
case "Bridge":
case 'Bridge':
return SectionType.Bridge;
}
}
@@ -76,14 +86,18 @@ export class TextRenderingService {
length: match[0].length,
position: regex.lastIndex - match[0].length,
};
if (match[3]) chord.slashChord = match[3];
if (match[4]) chord.add = match[4];
if (match[3]) {
chord.slashChord = match[3];
}
if (match[4]) {
chord.add = match[4];
}
chords.push(chord);
}
const chordCount = chords.reduce((acc: number, cur: Chord) => acc + cur.length, 0);
const lineCount = chordLine.replace(/\s/g, "").length;
const lineCount = chordLine.replace(/\s/g, '').length;
const isChrod = chordCount * 1.2 > lineCount;
return isChrod ? chords : [];
}

View File

@@ -1,4 +1,4 @@
export interface TransposeMode {
baseKey: string;
targetKey: string
targetKey: string;
}

View File

@@ -10,7 +10,9 @@ import {Line} from './line';
export class TransposeService {
public transpose(line: Line, baseKey: string, targetKey: string): Line {
if (line.type !== LineType.chord) return line;
if (line.type !== LineType.chord) {
return line;
}
const difference = this.getDistance(baseKey, targetKey);
const map = this.getMap(baseKey, difference);
@@ -21,7 +23,9 @@ export class TransposeService {
}
public renderChords(line: Line): Line {
if (line.type !== LineType.chord) return line;
if (line.type !== LineType.chord) {
return line;
}
const renderedLine = this.renderLine(line.chords);
return {...line, text: renderedLine};
@@ -37,7 +41,9 @@ export class TransposeService {
public getMap(baseKey: string, difference: number) {
const scale = getScaleType(baseKey);
if (!scale) return null;
if (!scale) {
return null;
}
const map = {};
for (let i = 0; i < 12; i++) {
const source = scale[0][i];
@@ -71,7 +77,7 @@ export class TransposeService {
const post = template.substr(pos + newLength);
template = pre + renderedChord + post;
})
});
return template.trimRight();
}