Skip to content

Commit

Permalink
clean up clefNote changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronDavidNewman committed Feb 25, 2024
1 parent 5277b3d commit 1bb58fc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/application/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ import { SmoMusic } from '../smo/data/music';
import { SmoAudioPitch } from '../smo/data/music';
import { SmoSelection, SmoSelector } from '../smo/xform/selections';
import { SmoOrnament, SmoArticulation, SmoDynamicText, SmoGraceNote, SmoMicrotone, SmoLyric,
SmoArpeggio } from '../smo/data/noteModifiers';
SmoArpeggio, SmoClefChange } from '../smo/data/noteModifiers';
import { SmoSystemStaff } from '../smo/data/systemStaff';
import { SmoSystemGroup, SmoAudioPlayerSettings, SmoScorePreferences } from '../smo/data/scoreModifiers';
import { SmoTextGroup, SmoTextGroupParams } from '../smo/data/scoreText';
Expand Down Expand Up @@ -230,7 +230,7 @@ export const Smo = {
SmoVolta, SmoMeasureText, SmoTempoText, TimeSignature,
// note modifiers
SmoOrnament,
SmoArticulation, SmoDynamicText, SmoGraceNote, SmoMicrotone, SmoLyric, SmoArpeggio,
SmoArticulation, SmoDynamicText, SmoGraceNote, SmoMicrotone, SmoLyric, SmoArpeggio, SmoClefChange,
// Smo Transformers
SmoSelection, SmoSelector, SmoDuration, UndoBuffer, SmoToVex, SmoOperation,
// new score bootstrap
Expand Down
4 changes: 3 additions & 1 deletion src/render/vex/vxMeasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,17 @@ export class VxMeasure implements VxMeasureIf {
let i = 0;
this.voiceNotes = [];
const voice = this.smoMeasure.voices[voiceIx];
let clefNoteAdded = false;
for (i = 0;
i < voice.notes.length; ++i) {
const smoNote = voice.notes[i];
const vexNote = this.createVexNote(smoNote, i, voiceIx);
this.noteToVexMap[smoNote.attrs.id] = vexNote.noteData.staveNote;
this.vexNotes.push(vexNote.noteData.staveNote);
if (vexNote.noteData.smoNote.clefNote) {
if (vexNote.noteData.smoNote.clefNote && !clefNoteAdded) {
const cf = new VF.ClefNote(vexNote.noteData.smoNote.clefNote.clef, 'small');
this.voiceNotes.push(cf);
clefNoteAdded = true; // ignore 2nd in a measure
}
this.voiceNotes.push(vexNote.noteData.staveNote);
if (isNaN(smoNote.ticks.numerator) || isNaN(smoNote.ticks.denominator)
Expand Down
6 changes: 6 additions & 0 deletions src/smo/data/measure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ export class SmoMeasure implements SmoMeasureParams, TickMappable {
if (curTick + noteTicks >= clefChangeTick) {
smoNote.clef = clefChange;
}
// Remove any redundant clef changes later in the measure
if (curTick + noteTicks > clefChangeTick) {
if (smoNote.clefNote && smoNote.clefNote.clef === clefChange) {
smoNote.clefNote = null;
}
}
curTick += noteTicks;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/smo/data/noteModifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export abstract class SmoNoteModifierBase implements SmoModifierBase {
}

export function isClefChangeParamsSer(params: Partial<SmoClefChangeParamsSer>): params is SmoClefChangeParamsSer {
if (typeof(params.clef) === 'string') {
if (typeof(params.clef) === 'string' && params.ctor === 'SmoClefChange') {
return true;
}
return false;
Expand Down Expand Up @@ -95,7 +95,7 @@ export class SmoClefChange extends SmoNoteModifierBase {
}
}
serialize(): SmoClefChangeParamsSer {
const params: Partial<SmoClefChangeParamsSer> = { ctor: 'SmoGraceNote' };
const params: Partial<SmoClefChangeParamsSer> = { ctor: 'SmoClefChange' };
params.clef = this.clef;
if (!isClefChangeParamsSer(params)) {
throw('corrupt clef change');
Expand Down

0 comments on commit 1bb58fc

Please sign in to comment.