diff --git a/src/importer/Gp3To5Importer.ts b/src/importer/Gp3To5Importer.ts index 1c04b129d..b50ce3138 100644 --- a/src/importer/Gp3To5Importer.ts +++ b/src/importer/Gp3To5Importer.ts @@ -261,38 +261,34 @@ export class Gp3To5Importer extends ScoreImporter { if ((flags & 0x08) !== 0) { newMasterBar.repeatCount = this.data.readByte() + (this._versionNumber >= 500 ? 0 : 1); } - // alternate endings - if ((flags & 0x10) !== 0) { - if (this._versionNumber < 500) { - let currentMasterBar: MasterBar | null = previousMasterBar; - // get the already existing alternatives to ignore them - let existentAlternatives: number = 0; - while (currentMasterBar) { - // found another repeat ending? - if (currentMasterBar.isRepeatEnd && currentMasterBar !== previousMasterBar) { - break; - } - // found the opening? - if (currentMasterBar.isRepeatStart) { - break; - } - existentAlternatives = existentAlternatives | currentMasterBar.alternateEndings; - currentMasterBar = currentMasterBar.previousMasterBar; + // alternate endings (pre GP5) + if ((flags & 0x10) !== 0 && this._versionNumber < 500) { + let currentMasterBar: MasterBar | null = previousMasterBar; + // get the already existing alternatives to ignore them + let existentAlternatives: number = 0; + while (currentMasterBar) { + // found another repeat ending? + if (currentMasterBar.isRepeatEnd && currentMasterBar !== previousMasterBar) { + break; } - // now calculate the alternative for this bar - let repeatAlternative: number = 0; - let repeatMask: number = this.data.readByte(); - for (let i: number = 0; i < 8; i++) { - // only add the repeating if it is not existing - let repeating: number = 1 << i; - if (repeatMask > i && (existentAlternatives & repeating) === 0) { - repeatAlternative = repeatAlternative | repeating; - } + // found the opening? + if (currentMasterBar.isRepeatStart) { + break; } - newMasterBar.alternateEndings = repeatAlternative; - } else { - newMasterBar.alternateEndings = this.data.readByte(); + existentAlternatives = existentAlternatives | currentMasterBar.alternateEndings; + currentMasterBar = currentMasterBar.previousMasterBar; } + // now calculate the alternative for this bar + let repeatAlternative: number = 0; + let repeatMask: number = this.data.readByte(); + for (let i: number = 0; i < 8; i++) { + // only add the repeating if it is not existing + let repeating: number = 1 << i; + if (repeatMask > i && (existentAlternatives & repeating) === 0) { + repeatAlternative = repeatAlternative | repeating; + } + } + newMasterBar.alternateEndings = repeatAlternative; } // marker if ((flags & 0x20) !== 0) { @@ -314,7 +310,7 @@ export class Gp3To5Importer extends ScoreImporter { this.data.skip(4); } // better alternate ending mask in GP5 - if (this._versionNumber >= 500 && (flags & 0x10) === 0) { + if (this._versionNumber >= 500) { newMasterBar.alternateEndings = this.data.readByte(); } // tripletfeel diff --git a/test-data/guitarpro5/alternate-endings-section-error.gp5 b/test-data/guitarpro5/alternate-endings-section-error.gp5 new file mode 100644 index 000000000..a89c4530e Binary files /dev/null and b/test-data/guitarpro5/alternate-endings-section-error.gp5 differ diff --git a/test/importer/Gp5Importer.test.ts b/test/importer/Gp5Importer.test.ts index c6fd22b8a..25df9b4bb 100644 --- a/test/importer/Gp5Importer.test.ts +++ b/test/importer/Gp5Importer.test.ts @@ -161,6 +161,15 @@ describe('Gp5ImporterTest', () => { GpImporterTestHelper.checkColors(score); }); + it('alternate-endings-section-error', async () => { + const reader = await GpImporterTestHelper.prepareImporterWithFile('guitarpro5/alternate-endings-section-error.gp5'); + const score: Score = reader.readScore(); + expect(score.masterBars.length).toBe(2); + expect(score.masterBars[1].alternateEndings).toBe(4); + expect(score.masterBars[1].section).toBeTruthy(); + expect(score.masterBars[1].section?.text).toBe("Outro"); + }); + it('canon', async () => { const reader = await GpImporterTestHelper.prepareImporterWithFile('guitarpro5/canon.gp5'); let score: Score = reader.readScore();