Browse Source

Fixing staves

Andrea Condoluci 9 năm trước cách đây
mục cha
commit
c47f673a10

+ 2 - 2
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -72,7 +72,7 @@ export class VexFlowConverter {
         return [fund + acc + "/" + octave, acc];
     }
 
-    public static StaveNote(notes: GraphicalNote[]): Vex.Flow.StaveNote {
+    public static StaveNote(notes: GraphicalNote[], clef: string): Vex.Flow.StaveNote {
         let keys: string[] = [];
         let duration: string = VexFlowConverter.duration(notes[0].sourceNote.Length);
         let accidentals: string[] = [];
@@ -89,7 +89,7 @@ export class VexFlowConverter {
         }
         let vfnote: Vex.Flow.StaveNote = new Vex.Flow.StaveNote({
             auto_stem: true,
-            clef: "treble", // FIXME!!
+            clef: clef,
             duration: duration,
             keys: keys,
         });

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

@@ -26,11 +26,12 @@ export class VexFlowMeasure extends StaffMeasure {
     public vfVoices: { [voiceID: number]: Vex.Flow.Voice; };
     public formatVoices: (width: number) => void;
     public unit: number = 10.0;
+
     private stave: Vex.Flow.Stave;
+    private vfclef: string;
 
     private beams: { [voiceID: number]: [Beam, VexFlowStaffEntry[]][]; } = {};
     private vfbeams: { [voiceID: number]: Vex.Flow.Beam[]; } = {};
-    //private duration: Fraction;
 
     public setAbsoluteCoordinates(x: number, y: number): void {
         this.stave.setX(x);
@@ -80,8 +81,8 @@ export class VexFlowMeasure extends StaffMeasure {
      */
     public addClefAtBegin(clef: ClefInstruction): void {
         this.octaveOffset = clef.OctaveOffset;
-        let vfclef: string = VexFlowConverter.Clef(clef);
-        this.stave.addClef(vfclef, undefined, undefined, Vex.Flow.Modifier.Position.BEGIN);
+        this.vfclef = VexFlowConverter.Clef(clef);
+        this.stave.addClef(this.vfclef, undefined, undefined, Vex.Flow.Modifier.Position.BEGIN);
         this.increaseBeginInstructionWidth();
     }
 
@@ -230,7 +231,7 @@ export class VexFlowMeasure extends StaffMeasure {
                         resolution: Vex.Flow.RESOLUTION,
                     }).setMode(Vex.Flow.Voice.Mode.SOFT);
                 }
-                let vfnote: Vex.Flow.StaveNote = VexFlowConverter.StaveNote(gnotes[voiceID]);
+                let vfnote: Vex.Flow.StaveNote = VexFlowConverter.StaveNote(gnotes[voiceID], this.vfclef);
                 (graphicalStaffEntry as VexFlowStaffEntry).vfNotes[voiceID] = vfnote;
                 vfVoices[voiceID].addTickable(vfnote);
             }

+ 3 - 6
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -768,8 +768,7 @@ export class InstrumentReader {
               this.abstractInstructions.splice(i, 1);
             }
           }
-        }
-        if (key <= this.activeClefs.length && clefInstruction === this.activeClefs[key - 1]) {
+        } else { //if (key <= this.activeClefs.length && clefInstruction === this.activeClefs[key - 1]) {
           this.abstractInstructions.splice(i, 1);
         }
       }
@@ -813,8 +812,7 @@ export class InstrumentReader {
               }
             }
           }
-        }
-        if (this.activeKey !== undefined && this.activeKey === keyInstruction) {
+        } else {
           this.abstractInstructions.splice(i, 1);
         }
       }
@@ -838,8 +836,7 @@ export class InstrumentReader {
               firstStaffEntry.Instructions.push(newRhythmInstruction);
             }
           }
-        }
-        if (this.activeRhythm !== undefined && this.activeRhythm === rhythmInstruction) {
+        } else {
           this.abstractInstructions.splice(i, 1);
         }
       }