Просмотр исходного кода

refactor: add some safety "null" checks for GhostNotes

sschmid 5 лет назад
Родитель
Сommit
5c5032b2b4

+ 1 - 1
src/MusicalScore/Graphical/GraphicalVoiceEntry.ts

@@ -143,7 +143,7 @@ export class GraphicalVoiceEntry extends GraphicalObject {
         }
         const stemStyle: Object = { fillStyle: stemColor, strokeStyle: stemColor };
 
-        if (vfStaveNote.setStemStyle) {
+        if (vfStaveNote && vfStaveNote.setStemStyle) {
             if (!stemTransparent) {
                 this.parentVoiceEntry.StemColor = stemColor;
             }

+ 4 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -925,7 +925,10 @@ export class VexFlowMeasure extends GraphicalMeasure {
                         // add clef as NoteSubGroup so that we get modifier layouting
                         const clefModifier: NoteSubGroup = new NoteSubGroup( [vfse.vfClefBefore] );
                         // The cast is necesary because...vexflow -> see types
-                        (vexFlowVoiceEntry.vfStaveNote as Vex.Flow.StaveNote).addModifier(0, clefModifier);
+                        if (vexFlowVoiceEntry.vfStaveNote.getCategory && vexFlowVoiceEntry.vfStaveNote.getCategory() === "stavenotes") {
+                            // GhostNotes and other StemmableNotes don't have this function
+                            (vexFlowVoiceEntry.vfStaveNote as Vex.Flow.StaveNote).addModifier(0, clefModifier);
+                        }
                     }
                 }