浏览代码

Edits from last week

Andrea Condoluci 9 年之前
父节点
当前提交
c812b911cf

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

@@ -23,11 +23,13 @@ declare namespace Vex {
 
     export class Voice {
       constructor(time: any);
+      public static Mode: any;
 
       public getBoundingBox(): BoundingBox;
       public setStave(stave: Stave): Voice;
       public addTickables(notes: StaveNote[]): Voice;
       public addTickable(note: StaveNote): Voice;
+      public setMode(mode: any): Voice;
     }
 
     export class StaveNote {
@@ -52,6 +54,7 @@ declare namespace Vex {
       public getWidth(): number;
       public setWidth(width: number): Stave;
       public getNoteStartX(): number;
+      public getNoteEndX(): number;
       public format(): void;
       public getSpacingBetweenLines(): number;
       public getNumLines(): number;

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

@@ -22,11 +22,18 @@ export class VexFlowConverter {
     };
 
     public static duration(fraction: Fraction): string {
-        return undefined;
+        // FIXME TODO
+        return "q";
     }
 
+    /**
+     * Takes a Pitch and returns a string representing a VexFlow pitch,
+     * which has the form "b/4", plus its alteration (accidental)
+     * @param pitch
+     * @returns {string[]}
+     */
     public static pitch(pitch: Pitch): [string, string] {
-        let fund: string = NoteEnum[pitch.FundamentalNote];
+        let fund: string = NoteEnum[pitch.FundamentalNote].toLowerCase();
         let octave: number = pitch.Octave;
         let acc: string = "";
 
@@ -51,7 +58,7 @@ export class VexFlowConverter {
     }
 
     public static StaveNote(voiceEntry: VoiceEntry): Vex.Flow.StaveNote {
-        let keys: string[] = []; //["b/4"]
+        let keys: string[] = [];
         let duration: string = VexFlowConverter.duration(voiceEntry.Notes[0].Length);
         let accidentals: string[] = [];
         for (let note of voiceEntry.Notes) {

+ 9 - 0
src/MusicalScore/Graphical/VexFlow/VexFlowGraphicalNote.ts

@@ -0,0 +1,9 @@
+import {GraphicalNote} from "../GraphicalNote";
+import {Note} from "../../VoiceData/Note";
+import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
+
+export class VexFlowGraphicalNote extends GraphicalNote {
+    constructor(note: Note, parent: GraphicalStaffEntry) {
+        super(note, parent);
+    }
+}

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

@@ -104,10 +104,12 @@ export class VexFlowMeasure extends StaffMeasure {
     }
 
     /**
-     * This method sets the x-position relative to the staffline. (y-Position is always 0 relative to the staffline)
+     * Set the x-position relative to the staffline.
+     * (y-Position is always 0 relative to the staffline)
      * @param x
      */
     public setPositionInStaffline(x: number): void {
+        // Already implemented in VexFlow, it does _not_ call .format()
         this.stave.setX(x);
     }
 
@@ -116,8 +118,12 @@ export class VexFlowMeasure extends StaffMeasure {
      * @param width
      */
     public setWidth(width: number): void {
-        // FIXME: this should consider modifiers!
-        this.stave.setWidth(width);
+        // Widths in PS and VexFlow work differently.
+        // In VexFlow, width is only the width of the actual voices, without considering
+        // modifiers like clefs. In PS, width is the total width of the stave.
+        // @Andrea: The following could be improved by storing the values in this object.
+        //          Now it calls .format() implicitly.
+        this.stave.setWidth(width - (this.stave.getNoteEndX() - this.stave.getWidth()));
     }
 
     /**
@@ -153,6 +159,7 @@ export class VexFlowMeasure extends StaffMeasure {
                     num_beats: num,
                     resolution: Vex.Flow.RESOLUTION,
                 });
+                voice.setMode(Vex.Flow.Voice.Mode.SOFT);
                 voice.addTickables(notes[id]);
                 voices[id] = voice;
             }