Skip to content

Commit

Permalink
add/remove tab staves when measures are added/removed
Browse files Browse the repository at this point in the history
Also add some SmoTabNote routines that will be used later.
  • Loading branch information
AaronDavidNewman committed May 24, 2024
1 parent 3252f1d commit 1f6e139
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/render/vex/vxMeasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class VxMeasure implements VxMeasureIf {
if (this.smoTabStave.showStems) {
tabNote.render_options.draw_stem = true;
tabNote.render_options.draw_dots = true;
tabNote.render_options.draw_stem_through_stave = smoTabNote.flagThrough;
}
} else {
tabNote = new VF.StaveNote(noteParams);
Expand Down
2 changes: 1 addition & 1 deletion src/smo/data/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ export class SmoNote implements Transposable {
const pitch = SmoMusic.transposePitchForKey(original, originalKey, destinationKey, offset);
note.pitches[index] = pitch;
}
}
}
SmoNote.sortPitches(note);
return note;
}
Expand Down
6 changes: 5 additions & 1 deletion src/smo/data/noteModifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ export interface SmoTabNoteParams {
positions: SmoFretPosition[]
noteId: string,
flagState: number,
flagThrough: boolean,
noteHead: number,
isAssigned: boolean
}
Expand All @@ -1099,6 +1100,7 @@ export class SmoTabNote extends SmoNoteModifierBase {
noteId: '',
isAssigned: false,
flagState: SmoTabNote.flagStates.None,
flagThrough: false,
noteHead: SmoTabNote.noteHeads.number
}));
}
Expand All @@ -1107,6 +1109,7 @@ export class SmoTabNote extends SmoNoteModifierBase {
isAssigned: boolean;
noteHead: number;
flagState: number;
flagThrough: boolean;
static get flagStates() {
return { None: 0, Up: 1, Down: -1 };
}
Expand All @@ -1120,11 +1123,12 @@ export class SmoTabNote extends SmoNoteModifierBase {
this.isAssigned = params.isAssigned;
this.noteHead = params.noteHead;
this.flagState = params.flagState;
this.flagThrough = params.flagThrough;
}
serialize(): SmoTabNoteParamsSer {
var params = { ctor: 'SmoTabNote' };
smoSerialize.serializedMergeNonDefault(SmoTabNote.defaults,
['positions', 'noteId', 'isAssigned', 'noteHead', 'flagState'], this, params);
['positions', 'noteId', 'isAssigned', 'noteHead', 'flagState', 'flagThrough'], this, params);
if (!isSmoTabNoteParamsSer(params)) {
throw 'bad params in SmoTabNote';
}
Expand Down
2 changes: 1 addition & 1 deletion src/smo/data/staffModifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ export class SmoTabStave extends StaffModifierBase {
const positions = SmoTabStave.getDefaultPositionsForStaff(note.pitches, this.stringPitches, transposeIndex);
return new SmoTabNote({
positions, noteId: note.attrs.id, isAssigned: false, flagState: SmoTabNote.flagStates.None,
noteHead: SmoTabNote.noteHeads.number
noteHead: SmoTabNote.noteHeads.number, flagThrough: false
});
}
constructor(params: SmoTabStaveParams) {
Expand Down
7 changes: 7 additions & 0 deletions src/smo/data/systemStaff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,9 @@ export class SmoSystemStaff implements SmoObjectParams {
nm.push(measure);
}
});
this.tabStaves.forEach((ts) => {
ts.endSelector.measure = this.measures.length - 1;
});
const sm: StaffModifierBase[] = [];
this.modifiers.forEach((mod) => {
// Bug: if we are deleting a measure before the selector, change the measure number.
Expand Down Expand Up @@ -861,6 +864,10 @@ export class SmoSystemStaff implements SmoObjectParams {
mod.endSelector.measure += 1;
}
});
// If there is a tab stave, it should extend the length of the stave.
this.tabStaves.forEach((ts) => {
ts.endSelector.measure = this.measures.length - 1;
});
this.numberMeasures();
}
}
16 changes: 16 additions & 0 deletions src/smo/xform/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ export class SmoOperation {
const note = selection.note;
if (measure && note) {
const pitchar: Pitch[] = [];
const tabStave: SmoTabStave | undefined = selection.staff.getTabStaveForMeasure(selection.selector);
note.pitches.forEach((opitch, pitchIx) => {
// Only translate selected pitches
const shouldXpose = selection.selector.pitches.length === 0 ||
Expand Down Expand Up @@ -482,6 +483,21 @@ export class SmoOperation {
pitchar.push(trans as Pitch);
});
note.pitches = pitchar;
// If this note has a tab stave, try to preserve the assigned string.
// If not possible, find the default string/fret for the note
if (note.tabNote) {
note.tabNote.positions.forEach((pp, ix) => {
if (pp.fret + offset > 0) {
pp.fret = pp.fret + offset;
} else if (tabStave && note.pitches.length > ix) {
const position = SmoTabStave.getDefaultPositionForStaff(note.pitches[ix], tabStave.stringPitches, offset);
pp.fret = position.fret;
pp.string = position.string;
} else {
pp.fret = 0;
}
});
}
return true;
}
return false;
Expand Down

0 comments on commit 1f6e139

Please sign in to comment.