transform keys and text service
This commit is contained in:
@@ -17,7 +17,6 @@ export interface Line {
|
||||
text: string;
|
||||
}
|
||||
|
||||
|
||||
export interface Section {
|
||||
type: SectionType;
|
||||
number: number;
|
||||
@@ -32,5 +31,40 @@ export class TextRenderingService {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
private regexSection = /(Strophe|Refrain|Bridge)/;
|
||||
private regexChords = /\b([CDEFGAHBcdefgahb](#|##|b|bb|sus|maj|maj7|min|aug|\d+|\/[CDEFGAHBcdefgahb])?\b)/;
|
||||
|
||||
public parse(text: string): Section[] {
|
||||
const arrayOfLines = text.split(/\r?\n/).filter(_ => _);
|
||||
const sections = arrayOfLines.reduce((array, line) => {
|
||||
if (line.match(this.regexSection)) return [...array, {
|
||||
type: this.getSectionTypeOfLine(line),
|
||||
number: -1,
|
||||
lines: []
|
||||
}];
|
||||
array[array.length - 1].lines.push(this.getLineOfLineText(line));
|
||||
return array;
|
||||
}, [] as Section[]);
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
private getLineOfLineText(text: string): Line {
|
||||
const matches = !!text.match(this.regexChords);
|
||||
const type = matches ? LineType.chrod : LineType.text;
|
||||
return {type, text}
|
||||
}
|
||||
|
||||
private getSectionTypeOfLine(line: string): SectionType {
|
||||
const typeString = line.match(this.regexSection)[1];
|
||||
switch (typeString) {
|
||||
case "Strophe":
|
||||
return SectionType.Verse;
|
||||
case "Refrain":
|
||||
return SectionType.Chorus;
|
||||
case "Bridge":
|
||||
return SectionType.Bridge;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user