Browse Source

fix(alignment): fix alignment of notes following dotted rest

vfNote.duration needs the "r" flag for rest note after the "d"s for each dot of the note, not before.
fix #484
tested with multiple dotted rests and general test samples from Demo.
sschmid 6 years ago
parent
commit
a7eb53df6f
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

+ 6 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -176,6 +176,7 @@ export class VexFlowConverter {
         let alignCenter: boolean = false;
         let xShift: number = 0;
         let slashNoteHead: boolean = false;
+        let isRest: boolean = false;
         for (const note of notes) {
             if (numDots < note.numberOfDots) {
                 numDots = note.numberOfDots;
@@ -183,6 +184,7 @@ export class VexFlowConverter {
 
             // if it is a rest:
             if (note.sourceNote.isRest()) {
+                isRest = true;
                 keys = ["b/4"];
                 // if it is a full measure rest:
                 if (note.parentVoiceEntry.parentStaffEntry.parentMeasure.parentSourceMeasure.Duration.RealValue <= frac.RealValue) {
@@ -196,7 +198,6 @@ export class VexFlowConverter {
                     xShift = EngravingRules.Rules.WholeRestXShiftVexflow * unitInPixels; // TODO find way to make dependent on the modifiers
                     // affects VexFlowStaffEntry.calculateXPosition()
                 }
-                duration += "r";
                 break;
             }
 
@@ -223,6 +224,10 @@ export class VexFlowConverter {
         if (slashNoteHead) {
             duration += "s"; // we have to specify a slash note head like this in Vexflow
         }
+        if (isRest) {
+            // "r" has to be put after the "d"s for rest notes.
+            duration += "r";
+        }
 
         let vfnote: Vex.Flow.StaveNote;