Skip to content
Open
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
9 changes: 9 additions & 0 deletions packages/alphatab/src/exporter/GpifWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ export class GpifWriter {

this._writeNoteProperties(noteNode, note);

const gpVelocity = note.gpVelocity;
if (gpVelocity !== null) {
noteNode.addElement('Velocity').innerText = gpVelocity.toString();
}
const gpRelativeVelocity = note.gpRelativeVelocity;
if (gpRelativeVelocity !== null) {
noteNode.addElement('RelativeVelocity').innerText = gpRelativeVelocity.toString();
}

if (note.isGhost) {
noteNode.addElement('AntiAccent').innerText = 'normal';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/alphatab/src/generated/SerializerSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export class SerializerSchema {
/**
* A hash of the field ids, keys and types of all serialized classes (50 classes).
*/
public static readonly fingerprint: number = 0x4671941c;
public static readonly fingerprint: number = 0xc4a8feb8;
}
2 changes: 2 additions & 0 deletions packages/alphatab/src/generated/model/NoteCloner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export class NoteCloner {
clone.durationPercent = original.durationPercent;
clone.accidentalMode = original.accidentalMode;
clone.dynamics = original.dynamics;
clone.gpVelocity = original.gpVelocity;
clone.gpRelativeVelocity = original.gpRelativeVelocity;
clone.ornament = original.ornament;
return clone;
}
Expand Down
16 changes: 12 additions & 4 deletions packages/alphatab/src/generated/model/NoteSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { IObjectWriter } from "@coderline/alphatab/io/IObjectWriter";
* @internal
*/
export class NoteSerializer {
private static readonly _fields: RecordFields = new RecordFields(["id", "accentuated", "bendtype", "bendstyle", "iscontinuedbend", "bendpoints", "fret", "string", "showstringnumber", "octave", "tone", "percussionarticulation", "isvisible", "islefthandtapped", "ishammerpullorigin", "isslurdestination", "harmonictype", "harmonicvalue", "isghost", "isletring", "ispalmmute", "isdead", "isstaccato", "slideintype", "slideouttype", "vibrato", "istiedestination", "lefthandfinger", "righthandfinger", "trillvalue", "trillspeed", "istrillstart", "durationpercent", "accidentalmode", "dynamics", "ornament", "style"]);
private static readonly _fields: RecordFields = new RecordFields(["id", "accentuated", "bendtype", "bendstyle", "iscontinuedbend", "bendpoints", "fret", "string", "showstringnumber", "octave", "tone", "percussionarticulation", "isvisible", "islefthandtapped", "ishammerpullorigin", "isslurdestination", "harmonictype", "harmonicvalue", "isghost", "isletring", "ispalmmute", "isdead", "isstaccato", "slideintype", "slideouttype", "vibrato", "istiedestination", "lefthandfinger", "righthandfinger", "trillvalue", "trillspeed", "istrillstart", "durationpercent", "accidentalmode", "dynamics", "gpvelocity", "gprelativevelocity", "ornament", "style"]);
public static read(obj: Note, reader: IObjectReader): void {
reader.readRecord(NoteSerializer._fields, (id, k, r) => {
switch (id) {
Expand Down Expand Up @@ -138,9 +138,15 @@ export class NoteSerializer {
obj.dynamics = JsonHelper.parseEnum<DynamicValue>(r.readValue(), DynamicValue)!;
return true;
case 35:
obj.ornament = JsonHelper.parseEnum<NoteOrnament>(r.readValue(), NoteOrnament)!;
obj.gpVelocity = r.readValue() as number | null;
return true;
case 36:
obj.gpRelativeVelocity = r.readValue() as number | null;
return true;
case 37:
obj.ornament = JsonHelper.parseEnum<NoteOrnament>(r.readValue(), NoteOrnament)!;
return true;
case 38:
if (r.isNullish()) {
obj.style = undefined;
}
Expand Down Expand Up @@ -221,9 +227,11 @@ export class NoteSerializer {
w.numberField(32, obj.durationPercent);
w.numberField(33, obj.accidentalMode as number);
w.numberField(34, obj.dynamics as number);
w.numberField(35, obj.ornament as number);
w.valueField(35, obj.gpVelocity);
w.valueField(36, obj.gpRelativeVelocity);
w.numberField(37, obj.ornament as number);
if (obj.style) {
w.field(36);
w.field(38);
NoteStyleSerializer.write(obj.style, w);
}
obj.toJson(w);
Expand Down
6 changes: 6 additions & 0 deletions packages/alphatab/src/importer/GpifParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,12 @@ export class GpifParser {
case 'Properties':
this._parseNoteProperties(c, note, noteId);
break;
case 'Velocity':
note.gpVelocity = GpifParser._parseIntSafe(c.innerText, 0);
break;
case 'RelativeVelocity':
note.gpRelativeVelocity = GpifParser._parseFloatSafe(c.innerText, 0);
break;
case 'AntiAccent':
if (c.innerText.toLowerCase() === 'normal') {
note.isGhost = true;
Expand Down
15 changes: 15 additions & 0 deletions packages/alphatab/src/model/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,21 @@ export class Note {
*/
public dynamics: DynamicValue = DynamicValue.F;

/**
* Guitar Pro's optional per-note MIDI velocity field. Preserved on GP import
* and export; alphaTab playback currently uses {@link dynamics} instead.
* @since 1.10.0
*/
public gpVelocity: number | null = null;

/**
* Guitar Pro's optional per-note relative velocity field in decibels.
* Preserved on GP import and export; not currently applied to playback.
* @since 1.10.0
*/
public gpRelativeVelocity: number | null = null;


/**
* @clone_ignore
* @json_ignore
Expand Down
13 changes: 13 additions & 0 deletions packages/alphatab/test/exporter/Gp7Exporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ import { TestPlatform } from 'test/TestPlatform';
import { describe, expect, it } from 'vitest';

describe('Gp7ExporterTest', () => {
it('preserves per-note GP velocity metadata through repeated round trips', () => {
for (const relative of [2.75, -1.5]) {
const score = ScoreLoader.loadAlphaTex('3.3.4');
const note = score.tracks[0].staves[0].bars[0].voices[0].beats[0].notes[0];
note.gpVelocity = 100;
note.gpRelativeVelocity = relative;
const imported = prepareImporterWithBytes(exportGp7(score)).readScore();
const roundTripped = prepareImporterWithBytes(exportGp7(imported)).readScore();
const result = roundTripped.tracks[0].staves[0].bars[0].voices[0].beats[0].notes[0];
expect(result.gpVelocity).toBe(100);
expect(result.gpRelativeVelocity).toBe(relative);
}
});
async function loadScore(name: string): Promise<Score | null> {
try {
const data = await TestPlatform.loadFile(`test-data/${name}`);
Expand Down
2 changes: 2 additions & 0 deletions packages/alphatab/test/generated/SerializerFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,8 @@ export class SerializerFill {
obj.durationPercent = 7.25;
obj.accidentalMode = SerializerFill.otherEnumValue(NoteAccidentalMode, obj.accidentalMode) as NoteAccidentalMode;
obj.dynamics = SerializerFill.otherEnumValue(DynamicValue, obj.dynamics) as DynamicValue;
obj.gpVelocity = 7.25;
obj.gpRelativeVelocity = 7.25;
obj.ornament = SerializerFill.otherEnumValue(NoteOrnament, obj.ornament) as NoteOrnament;
{
const v0 = new NoteStyle();
Expand Down
5 changes: 5 additions & 0 deletions website/docs/releases/release1_10.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { AlphaTab } from '@site/src/components/AlphaTab';

## 1.10.0

#### Guitar Pro: preserve per-note velocity metadata
https://github.com/CoderLine/alphaTab/pull/3022

The Guitar Pro importer and exporter preserve optional per-note absolute and relative velocity metadata. alphaTab playback continues to use note dynamics.

### Music Notation

#### render: transposed tabs on playable strings
Expand Down
Loading