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: 20 additions & 4 deletions packages/alphatab/src/exporter/AlphaTexExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
type AlphaTexScoreNode,
type AlphaTexStringLiteral,
type AlphaTexArgumentList,
type IAlphaTexAstNode
type IAlphaTexAstNode,
AlphaTexDotTokenNode,
AlphaTexAtTokenNode
} from '@coderline/alphatab/importer/alphaTex/AlphaTexAst';
import type { IAlphaTexLanguageImportHandler } from '@coderline/alphatab/importer/alphaTex/IAlphaTexLanguageImportHandler';
import { IOHelper } from '@coderline/alphatab/io/IOHelper';
Expand Down Expand Up @@ -181,7 +183,7 @@ class AlphaTexPrinter {
this._writeComments(n.leadingComments);

this._writeValue(n.noteValue);
this._writeToken(n.noteStringDot, false);
this._writeToken(n.noteStringSeparator, false);
this._writeValue(n.noteString);

if (n.noteEffects) {
Expand Down Expand Up @@ -378,6 +380,9 @@ class AlphaTexPrinter {
case AlphaTexNodeType.Dot:
this._writer.write('.');
break;
case AlphaTexNodeType.At:
this._writer.write('@');
break;
case AlphaTexNodeType.Backslash:
this._writer.write('\\');
break;
Expand Down Expand Up @@ -658,6 +663,17 @@ export class AlphaTexExporter extends ScoreExporter {
nodeType: AlphaTexNodeType.String,
text: PercussionMapper.getArticulationName(data)
} as AlphaTexStringLiteral;

if (!Number.isNaN(data.string)) {
note.noteStringSeparator = {
nodeType: AlphaTexNodeType.At
} as AlphaTexAtTokenNode;
const stringNumber = data.beat.voice.bar.staff.tuning.length - data.string + 1;
note.noteString = {
nodeType: AlphaTexNodeType.Number,
value: stringNumber
};
}
} else if (data.isPiano) {
note.noteValue = {
nodeType: AlphaTexNodeType.Ident,
Expand All @@ -668,9 +684,9 @@ export class AlphaTexExporter extends ScoreExporter {
nodeType: AlphaTexNodeType.Number,
value: data.fret
} as AlphaTexNumberLiteral;
note.noteStringDot = {
note.noteStringSeparator = {
nodeType: AlphaTexNodeType.Dot
};
} as AlphaTexDotTokenNode;
const stringNumber = data.beat.voice.bar.staff.tuning.length - data.string + 1;
note.noteString = {
nodeType: AlphaTexNodeType.Number,
Expand Down
4 changes: 4 additions & 0 deletions packages/alphatab/src/exporter/GpifWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ export class GpifWriter {
}
}

if (note.isPercussion) {
this._writeSimplePropertyNode(properties, 'String', 'String', (note.string - 1).toString());
}

if (note.isPiano) {
this._writeSimplePropertyNode(properties, 'Octave', 'Number', note.octave.toString());
this._writeSimplePropertyNode(properties, 'Tone', 'Step', note.tone.toString());
Expand Down
53 changes: 42 additions & 11 deletions packages/alphatab/src/importer/AlphaTexImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,10 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
// Note value
let isDead: boolean = false;
let isTie: boolean = false;
let numericValue: number = -1;
let numericValue: number = Number.NaN;
let articulationValue: string = '';
let octave: number = -1;
let tone: number = -1;
let octave: number = Number.NaN;
let tone: number = Number.NaN;
let accidentalMode = NoteAccidentalMode.Default;
const noteValue = node.noteValue as AlphaTexAstNode;
let detectedNoteKind: AlphaTexStaffNoteKind | undefined = undefined;
Expand All @@ -570,7 +570,7 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
isTie = str === '-';
if (isTie || isDead) {
numericValue = 0;
if (node.noteStringDot && node.noteString) {
if (node.noteStringSeparator && node.noteString) {
detectedNoteKind = AlphaTexStaffNoteKind.Fretted;
} else {
detectedNoteKind = undefined; // don't know on those notes
Expand Down Expand Up @@ -668,19 +668,19 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
return;
}

const noteString: number = node.noteString!.value;
if (noteString < 1 || noteString > this._state.currentStaff!.tuning.length) {
const frettedNoteString: number = node.noteString!.value;
if (frettedNoteString < 1 || frettedNoteString > this._state.currentStaff!.tuning.length) {
this.addSemanticDiagnostic({
code: AlphaTexDiagnosticCode.AT208,
message: `Note string is out of range. Available range: 1-${this._state.currentStaff!.tuning.length}`,
severity: AlphaTexDiagnosticsSeverity.Error,
start: noteValue.end,
end: noteValue.end
start: node.noteString.start,
end: node.noteString.end
});
return;
}

note.string = this._state.currentStaff!.tuning.length - (noteString - 1);
note.string = this._state.currentStaff!.tuning.length - (frettedNoteString - 1);
if (!isTie) {
note.fret = numericValue;
}
Expand Down Expand Up @@ -716,6 +716,34 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
this._state.articulationUniqueIdToIndex.set(articulationValue, articulationIndex);
}
note.percussionArticulation = articulationIndex;

if (node.noteString) {
const percussionNoteString: number = node.noteString!.value;
if (percussionNoteString < 1 || percussionNoteString > this._state.currentStaff!.tuning.length) {
this.addSemanticDiagnostic({
code: AlphaTexDiagnosticCode.AT208,
message: `Note string is out of range. Available range: 1-${this._state.currentStaff!.tuning.length}`,
severity: AlphaTexDiagnosticsSeverity.Error,
start: node.noteString.start,
end: node.noteString.end
});
return;
}
note.string = this._state.currentStaff!.tuning.length - (percussionNoteString - 1);
} else {
// find free string
for (let i = 0; i < this._state.currentStaff!.tuning.length; i++) {
const s = this._state.currentStaff!.tuning.length - i;
if (!beat.noteStringLookup.has(s)) {
note.string = s;
break;
}
}
if (Number.isNaN(note.string)) {
note.string = this._state.currentStaff!.tuning.length;
}
}

break;
}
}
Expand All @@ -742,6 +770,7 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
switch (staffNoteKind) {
case AlphaTexStaffNoteKind.Pitched:
staff.isPercussion = false;
staff.showTablature = false;
staff.stringTuning.reset();
if (!this._state.staffHasExplicitDisplayTransposition.has(staff)) {
staff.displayTranspositionPitch = 0;
Expand All @@ -755,6 +784,7 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
case AlphaTexStaffNoteKind.Articulation:
staff.isPercussion = true;
staff.stringTuning.reset();
staff.stringTuning.tunings = [0, 0, 0, 0, 0, 0];
if (!this._state.staffHasExplicitDisplayTransposition.has(staff)) {
staff.displayTranspositionPitch = 0;
}
Expand Down Expand Up @@ -813,7 +843,9 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
// reset to defaults
staff.stringTuning.reset();

if (program === 15) {
if (staff.isPercussion) {
staff.stringTuning.tunings = [0, 0, 0, 0, 0, 0];
} else if (program === 15) {
// dulcimer E4 B3 G3 D3 A2 E2
staff.stringTuning.tunings = Tuning.getDefaultTuningFor(6)!.tunings;
} else if (program >= 24 && program <= 31) {
Expand Down Expand Up @@ -1097,7 +1129,6 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter

public applyPercussionStaff(staff: Staff) {
staff.isPercussion = true;
staff.showTablature = false;
staff.track.playbackInfo.program = 0;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/alphatab/src/importer/Gp3To5Importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,7 @@ export class Gp3To5Importer extends ScoreImporter {
newNote.percussionArticulation = Gp3To5Importer._gp5PercussionInstrumentMap.has(newNote.fret)
? Gp3To5Importer._gp5PercussionInstrumentMap.get(newNote.fret)!
: newNote.fret;
newNote.string = -1;
newNote.fret = -1;
newNote.fret = Number.NaN;
}
if (swapAccidentals) {
const accidental = ModelUtils.computeAccidental(
Expand Down
16 changes: 3 additions & 13 deletions packages/alphatab/src/importer/GpifParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,6 @@ export class GpifParser {

const track: Track = new Track();
track.ensureStaveCount(1);
const staff: Staff = track.staves[0];
staff.showStandardNotation = true;
const trackId: string = node.getAttribute('id');

for (const c of node.childElements()) {
Expand Down Expand Up @@ -979,10 +977,6 @@ export class GpifParser {
}
}

if (!staff.isPercussion) {
staff.showTablature = true;
}

break;
case 'DiagramCollection':
case 'ChordCollection':
Expand Down Expand Up @@ -1161,8 +1155,6 @@ export class GpifParser {
}
for (const staff of track.staves) {
staff.stringTuning.tunings = tuning;
staff.showStandardNotation = true;
staff.showTablature = true;
}
break;
case 'DiagramCollection':
Expand Down Expand Up @@ -2437,7 +2429,7 @@ export class GpifParser {
case 'Octave':
note.octave = GpifParser._parseIntSafe(c.findChildElement('Number')?.innerText, 0);
// when exporting GP6 from GP7 the tone might be missing
if (note.tone === -1) {
if (Number.isNaN(note.tone)) {
note.tone = 0;
}
break;
Expand Down Expand Up @@ -2779,12 +2771,10 @@ export class GpifParser {
for (const noteId of this._notesOfBeat.get(beatId)!) {
if (noteId !== GpifParser._invalidId) {
const note = NoteCloner.clone(this._noteById.get(noteId)!);
// reset midi value for non-percussion staves
if (staff.isPercussion) {
note.fret = -1;
note.string = -1;
note.fret = Number.NaN;
} else {
note.percussionArticulation = -1;
note.percussionArticulation = Number.NaN;
}
beat.addNote(note);
if (this._tappedNotes.has(noteId)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/alphatab/src/importer/MusicXmlImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1903,8 +1903,9 @@ export class MusicXmlImporter extends ScoreImporter {
break;
case 'percussion':
bar.clef = Clef.Neutral;
if(bar.index === 0){
if (bar.index === 0) {
bar.staff.isPercussion = true;
bar.staff.showTablature = false;
}
break;
case 'tab':
Expand Down
4 changes: 1 addition & 3 deletions packages/alphatab/src/importer/PartConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export class PartConfiguration {
if (trackIndex < score.tracks.length) {
const track: Track = score.tracks[trackIndex];
for (const staff of track.staves) {
if(!staff.isPercussion){
staff.showTablature = trackConfig.showTablature;
}
staff.showTablature = trackConfig.showTablature;
staff.showStandardNotation = trackConfig.showStandardNotation;
staff.showSlash = trackConfig.showSlash;
staff.showNumbered = trackConfig.showNumbered;
Expand Down
Loading
Loading