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
24 changes: 23 additions & 1 deletion packages/alphatab/src/importer/Gp3To5Importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ import { BeamDirection } from '@coderline/alphatab/rendering/utils/BeamDirection
*/
export class Gp3To5Importer extends ScoreImporter {
private static readonly _versionString: string = 'FICHIER GUITAR PRO ';

// NOTE: General Midi only defines percussion instruments from 35-81
// Guitar Pro 5 allowed GS extensions (27-34 and 82-87)
// GP7-8 do not have all these definitions anymore, this lookup ensures some fallback
// (even if they are not correct)
// we can support this properly in future when we allow custom alphaTex articulation definitions
// then we don't need to rely on GP specifics anymore but handle things on export/import
private static readonly _gp5PercussionInstrumentMap = new Map<number, number>([
// High Q -> GS "High Q / Filter Snap"
[27, 42],
// Slap
[28, 60],
// Scratch Push
[29, 29],
// Scratch Pull
[30, 30],
// Square Click
[32, 31]
]);

private _versionNumber: number = 0;
private _score!: Score;
private _globalTripletFeel: TripletFeel = TripletFeel.NoTripletFeel;
Expand Down Expand Up @@ -1225,7 +1245,9 @@ export class Gp3To5Importer extends ScoreImporter {
}

if (bar.staff.isPercussion) {
newNote.percussionArticulation = newNote.fret;
newNote.percussionArticulation = Gp3To5Importer._gp5PercussionInstrumentMap.has(newNote.fret)
? Gp3To5Importer._gp5PercussionInstrumentMap.get(newNote.fret)!
: newNote.fret;
newNote.string = -1;
newNote.fret = -1;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/alphatab/src/model/PercussionMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,8 @@ export class PercussionMapper {
}
}

return 'unknown';
// unknown combination, should not happen, fallback to some default value (Snare hit)
return 'Snare (hit)';
}

public static getArticulation(n: Note): InstrumentArticulation | null {
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/alphatab/test/exporter/AlphaTexExporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ describe('AlphaTexExporterTest', () => {
await testRoundTripEqual(`conversion/full-song.gp5`);
});

it('gp5-articulation', async () => {
await testRoundTripEqual(`guitarpro5/percussion-all.gp5`);
});

it('gp6-to-alphaTex', async () => {
await testRoundTripEqual(`conversion/full-song.gpx`);
});
Expand Down
16 changes: 16 additions & 0 deletions packages/alphatab/test/importer/Gp5Importer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BeamDirection } from '@coderline/alphatab/rendering/utils/BeamDirection
import { GpImporterTestHelper } from 'test/importer/GpImporterTestHelper';
import { expect } from 'chai';
import { Clef } from '@coderline/alphatab/model/Clef';
import { PercussionMapper } from '@coderline/alphatab/model/PercussionMapper';

describe('Gp5ImporterTest', () => {
it('score-info', async () => {
Expand Down Expand Up @@ -553,4 +554,19 @@ describe('Gp5ImporterTest', () => {
expect(score.tracks[2].staves[0].bars[0].clef).to.equal(Clef.F4);
expect(score.tracks[3].staves[0].bars[0].clef).to.equal(Clef.F4);
});

it('percusson', async () => {
const score = (await GpImporterTestHelper.prepareImporterWithFile('guitarpro5/percussion-all.gp5')).readScore();

let beat: Beat | null = score.tracks[0].staves[0].bars[0].voices[0].beats[0];

while (beat) {
if (beat.notes.length === 1) {
const articulationName = PercussionMapper.getArticulationName(beat.notes[0]);
const hasArticulation = PercussionMapper.instrumentArticulationNames.has(articulationName);
expect(hasArticulation).to.be.true;
beat = beat.nextBeat;
}
}
});
});
Loading