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

Fixed bug with beginInstructionWidth

Andrea Condoluci 9 лет назад
Родитель
Сommit
35d8da6b5a

+ 1 - 0
external/vexflow/vexflow.d.ts

@@ -59,6 +59,7 @@ declare namespace Vex {
       public getNoteStartX(): number;
       public getNoteEndX(): number;
       public setNoteStartX(x: number): Stave;
+      public setKeySignature(keySpec: any, cancelKeySpec: any, position: any): Stave;
       public format(): void;
       public getSpacingBetweenLines(): number;
       public getNumLines(): number;

+ 8 - 10
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -38,8 +38,6 @@ export class VexFlowMeasure extends StaffMeasure {
     private beams: { [voiceID: number]: [Beam, VexFlowStaffEntry[]][]; } = {};
     // VexFlow Beams
     private vfbeams: { [voiceID: number]: Vex.Flow.Beam[]; };
-    // The actual, unmodified beginInstructionWidth
-    private realBegin: number = 0;
 
     // Sets the absolute coordinates of the VFStave on the canvas
     public setAbsoluteCoordinates(x: number, y: number): void {
@@ -108,11 +106,12 @@ export class VexFlowMeasure extends StaffMeasure {
      * @param currentClef the valid clef. Needed to put the accidentals on the right y-positions.
      */
     public addKeyAtBegin(currentKey: KeyInstruction, previousKey: KeyInstruction, currentClef: ClefInstruction): void {
-        let keySig: Vex.Flow.KeySignature = new Vex.Flow.KeySignature(
+        this.stave.setKeySignature(
             VexFlowConverter.keySignature(currentKey),
-            VexFlowConverter.keySignature(previousKey)
+            VexFlowConverter.keySignature(previousKey),
+            undefined
         );
-        this.stave.addModifier(keySig, Vex.Flow.Modifier.Position.BEGIN);
+        this.updateInstructionWidth();
     }
 
     /**
@@ -182,7 +181,7 @@ export class VexFlowMeasure extends StaffMeasure {
      */
     public draw(ctx: Vex.Flow.CanvasContext): void {
         // Force the width of the Begin Instructions
-        this.stave.setNoteStartX(this.stave.getNoteStartX() + 10.0 * (- this.realBegin + this.beginInstructionsWidth));
+        this.stave.setNoteStartX(this.stave.getX() + 10.0 * this.beginInstructionsWidth);
         // Draw stave lines
         this.stave.setContext(ctx).draw();
         // Draw all voices
@@ -314,9 +313,8 @@ export class VexFlowMeasure extends StaffMeasure {
     //}
 
     private updateInstructionWidth(): void {
-        this.stave.format();
-        this.realBegin = this.stave.getNoteStartX() / 10.0;
-        this.beginInstructionsWidth = this.stave.getNoteStartX() / 10.0;
-        this.endInstructionsWidth = this.stave.getNoteEndX() / 10.0;
+        //this.stave.format();
+        this.beginInstructionsWidth = (this.stave.getNoteStartX() - this.stave.getX()) / 10.0;
+        this.endInstructionsWidth = (this.stave.getNoteEndX() - this.stave.getX()) / 10.0;
     }
 }

+ 1 - 0
src/OSMD/OSMD.ts

@@ -161,6 +161,7 @@ export class OSMD {
      * FIXME: Probably unnecessary
      */
     private reset(): void {
+        this.cursor.hide();
         this.sheet = undefined;
         this.graphic = undefined;
         this.zoom = 1.0;