Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/importer/GpifParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class GpifParser {
private _lyricsByTrack!: Map<string, Lyrics[]>;
private _hasAnacrusis: boolean = false;
private _articulationByName!: Map<string, InstrumentArticulation>;
private _skipApplyLyrics: boolean = false;

public parseXml(xml: string, settings: Settings): void {
this._masterTrackAutomations = new Map<string, Automation[]>();
Expand All @@ -110,6 +111,8 @@ export class GpifParser {
this._noteById = new Map<string, Note>();
this._tappedNotes = new Map<string, boolean>();
this._lyricsByTrack = new Map<string, Lyrics[]>();
this._skipApplyLyrics = false;

let dom: XmlDocument;
try {
dom = new XmlDocument(xml);
Expand All @@ -120,7 +123,7 @@ export class GpifParser {
this.parseDom(dom);
this.buildModel();
this.score.finish(settings);
if (this._lyricsByTrack.size > 0) {
if (!this._skipApplyLyrics && this._lyricsByTrack.size > 0) {
this._lyricsByTrack.forEach((lyrics, t) => {
let track: Track = this._tracksById.get(t)!;
track.applyLyrics(lyrics);
Expand Down Expand Up @@ -1396,12 +1399,32 @@ export class GpifParser {
break;
}
break;
case 'Lyrics':
beat.lyrics = this.parseBeatLyrics(c);
this._skipApplyLyrics = true;
break;
}
}
}
this._beatById.set(beatId, beat);
}

private parseBeatLyrics(node: XmlNode): string[] | null {
const lines: string[] = [];

for (let c of node.childNodes) {
if (c.nodeType === XmlNodeType.Element) {
switch (c.localName) {
case 'Line':
lines.push(c.innerText);
break;
}
}
}

return lines;
}

private parseBeatXProperties(node: XmlNode, beat: Beat): void {
for (let c of node.childNodes) {
if (c.nodeType === XmlNodeType.Element) {
Expand Down
Binary file added test-data/guitarpro7/beat-lyrics.gp
Binary file not shown.
14 changes: 14 additions & 0 deletions test/importer/Gp7Importer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,4 +856,18 @@ describe('Gp7ImporterTest', () => {
);
expect(score.tracks[0].staves[0].bars[4].voices[0].beats[0].notes[0].fret).toEqual(20);
});

it('beat-lyrics', async () => {
const reader = await prepareGp7ImporterWithFile('guitarpro7/beat-lyrics.gp');
let score: Score = reader.readScore();
expect(score.tracks[0].staves[0].bars[0].voices[0].beats[0].lyrics![0]).toBe("This");
expect(score.tracks[0].staves[0].bars[0].voices[0].beats[1].lyrics![0]).toBe("is");
expect(score.tracks[0].staves[0].bars[0].voices[0].beats[2].lyrics![0]).toBe("a");
expect(score.tracks[0].staves[0].bars[0].voices[0].beats[3].lyrics![0]).toBe("test file");
expect(score.tracks[0].staves[0].bars[1].voices[0].beats[0].lyrics![0]).toBe("for");
expect(score.tracks[0].staves[0].bars[1].voices[0].beats[1].lyrics![0]).toBe("lyrics");
expect(score.tracks[0].staves[0].bars[1].voices[0].beats[2].lyrics).toBe(null);
expect(score.tracks[0].staves[0].bars[1].voices[0].beats[3].lyrics).toBe(null);
});

});