Преглед изворни кода

fix(stemDirection): fix beam with grace note in middle bug (#413)

fix #413
sschmidTU пре 6 година
родитељ
комит
a71496c5fb

+ 10 - 3
src/MusicalScore/Graphical/MusicSheetCalculator.ts

@@ -1628,6 +1628,12 @@ export abstract class MusicSheetCalculator {
                 openOctaveShifts[staffIndex] = undefined;
             }
         }
+        // check wantedStemDirections of beam notes at end of measure (e.g. for beam with grace notes)
+        for (const staffEntry of measure.staffEntries) {
+            for (const voiceEntry of staffEntry.graphicalVoiceEntries) {
+                this.setBeamNotesWantedStemDirections(voiceEntry.parentVoiceEntry);
+            }
+        }
         // if there are no staffEntries in this measure, create a rest for the whole measure:
         if (measure.staffEntries.length === 0) {
             const sourceStaffEntry: SourceStaffEntry = new SourceStaffEntry(
@@ -2305,10 +2311,11 @@ export abstract class MusicSheetCalculator {
                 }
             }
         }
+        // setBeamNotesWantedStemDirections() will be called at end of measure (createGraphicalMeasure)
+    }
 
-        // ToDo: shift code to end of measure to only check once for all beams
-        // check for a beam:
-        // if this voice entry currently has no desired direction yet:
+    /** Sets a voiceEntry's stem direction to one already set in other notes in its beam, if it has one. */
+    private setBeamNotesWantedStemDirections(voiceEntry: VoiceEntry): void {
         if (voiceEntry.WantedStemDirection === StemDirectionType.Undefined &&
             voiceEntry.Notes.length > 0) {
             const beam: Beam = voiceEntry.Notes[0].NoteBeam;

+ 4 - 3
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -283,19 +283,20 @@ export class VexFlowConverter {
             }
         }
 
+        // add accidentals
         for (let i: number = 0, len: number = notes.length; i < len; i += 1) {
             (notes[i] as VexFlowGraphicalNote).setIndex(vfnote, i);
             if (accidentals[i]) {
-                if (accidentals[i] === "++") {
+                if (accidentals[i] === "++") { // triple sharp
                     vfnote.addAccidental(i, new Vex.Flow.Accidental("##"));
                     vfnote.addAccidental(i, new Vex.Flow.Accidental("#"));
                     continue;
-                } else if (accidentals[i] === "bbs") {
+                } else if (accidentals[i] === "bbs") { // triple flat
                     vfnote.addAccidental(i, new Vex.Flow.Accidental("bb"));
                     vfnote.addAccidental(i, new Vex.Flow.Accidental("b"));
                     continue;
                 }
-                vfnote.addAccidental(i, new Vex.Flow.Accidental(accidentals[i]));
+                vfnote.addAccidental(i, new Vex.Flow.Accidental(accidentals[i])); // normal accidental
             }
         }
         for (let i: number = 0, len: number = numDots; i < len; ++i) {

+ 0 - 1
src/MusicalScore/ScoreIO/VoiceGenerator.ts

@@ -423,7 +423,6 @@ export class VoiceGenerator {
    * Handle the currentVoiceBeam.
    * @param node
    * @param note
-   * @param grace
    */
   private createBeam(node: IXmlElement, note: Note): void {
     try {