Procházet zdrojové kódy

Noted height corrected

Andrea Condoluci před 9 roky
rodič
revize
707f950193

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

@@ -113,7 +113,7 @@ declare namespace Vex {
     }
 
     export class Beam {
-      constructor(notes: StaveNote[]);
+      constructor(notes: StaveNote[], auto_stem: boolean);
       public setContext(ctx: CanvasContext): Beam;
       public draw(): void;
     }

+ 2 - 0
src/Common/FileIO/Xml.ts

@@ -22,6 +22,8 @@ export class IXmlElement {
         // Look for a value
         if (elem.childNodes.length === 1 && elem.childNodes[0].nodeType === Node.TEXT_NODE) {
             this.value = elem.childNodes[0].nodeValue;
+        } else {
+            this.value = "";
         }
     }
 

+ 11 - 6
src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts

@@ -11,6 +11,7 @@ import {AccidentalEnum} from "../../../Common/DataObjects/pitch";
 import {NoteEnum} from "../../../Common/DataObjects/pitch";
 import {VexFlowGraphicalNote} from "./VexFlowGraphicalNote";
 import {GraphicalNote} from "../GraphicalNote";
+import Clef = Vex.Flow.Clef;
 
 export class VexFlowConverter {
     private static majorMap: {[_: number]: string; } = {
@@ -47,9 +48,9 @@ export class VexFlowConverter {
      * @param pitch
      * @returns {string[]}
      */
-    public static pitch(pitch: Pitch, octaveOffset: number): [string, string] {
+    public static pitch(pitch: Pitch, clef: ClefInstruction): [string, string, ClefInstruction] {
         let fund: string = NoteEnum[pitch.FundamentalNote].toLowerCase();
-        let octave: number = pitch.Octave + octaveOffset + 3;
+        let octave: number = pitch.Octave + clef.OctaveOffset + 3; // FIXME + 3
         let acc: string = "";
 
         switch (pitch.Accidental) {
@@ -69,15 +70,16 @@ export class VexFlowConverter {
                 break;
             default:
         }
-        return [fund + acc + "/" + octave, acc];
+        return [fund + acc + "/" + octave, acc, clef];
     }
 
-    public static StaveNote(notes: GraphicalNote[], clef: string): Vex.Flow.StaveNote {
+    public static StaveNote(notes: GraphicalNote[]): Vex.Flow.StaveNote {
         let keys: string[] = [];
         let duration: string = VexFlowConverter.duration(notes[0].sourceNote.Length);
         let accidentals: string[] = [];
+        let vfclef: string;
         for (let note of notes) {
-            let res: [string, string] = (note as VexFlowGraphicalNote).vfpitch;
+            let res: [string, string, ClefInstruction] = (note as VexFlowGraphicalNote).vfpitch;
             if (res === undefined) {
                 keys = ["b/4"];
                 accidentals = [];
@@ -86,10 +88,13 @@ export class VexFlowConverter {
             }
             keys.push(res[0]);
             accidentals.push(res[1]);
+            if (!vfclef) {
+                vfclef = VexFlowConverter.Clef(res[2]);
+            }
         }
         let vfnote: Vex.Flow.StaveNote = new Vex.Flow.StaveNote({
             auto_stem: true,
-            clef: clef,
+            clef: vfclef,
             duration: duration,
             keys: keys,
         });

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

@@ -8,11 +8,11 @@ export class VexFlowGraphicalNote extends GraphicalNote {
     constructor(note: Note, parent: GraphicalStaffEntry, activeClef: ClefInstruction) {
         super(note, parent);
         if (note.Pitch) {
-            this.vfpitch = VexFlowConverter.pitch(note.Pitch, activeClef.OctaveOffset);
+            this.vfpitch = VexFlowConverter.pitch(note.Pitch, activeClef);
         } else {
             this.vfpitch = undefined;
         }
     }
 
-    public vfpitch: [string, string];
+    public vfpitch: [string, string, ClefInstruction];
 }

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

@@ -28,7 +28,6 @@ export class VexFlowMeasure extends StaffMeasure {
     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[]; } = {};
@@ -81,8 +80,8 @@ export class VexFlowMeasure extends StaffMeasure {
      */
     public addClefAtBegin(clef: ClefInstruction): void {
         this.octaveOffset = clef.OctaveOffset;
-        this.vfclef = VexFlowConverter.Clef(clef);
-        this.stave.addClef(this.vfclef, undefined, undefined, Vex.Flow.Modifier.Position.BEGIN);
+        let vfclef: string = VexFlowConverter.Clef(clef);
+        this.stave.addClef(vfclef, undefined, undefined, Vex.Flow.Modifier.Position.BEGIN);
         this.increaseBeginInstructionWidth();
     }
 
@@ -141,7 +140,6 @@ export class VexFlowMeasure extends StaffMeasure {
         this.stave.setWidth(width * this.unit);
         if (this.formatVoices) {
             this.formatVoices((width - this.beginInstructionsWidth - this.endInstructionsWidth) * this.unit);
-            this.formatVoices = undefined;
         }
     }
 
@@ -213,7 +211,7 @@ export class VexFlowMeasure extends StaffMeasure {
                     for (let entry of beam[1]) {
                         notes.push((entry as VexFlowStaffEntry).vfNotes[voiceID]);
                     }
-                    vfbeams.push(new Vex.Flow.Beam(notes));
+                    vfbeams.push(new Vex.Flow.Beam(notes, true));
                 }
             }
         }
@@ -231,7 +229,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], this.vfclef);
+                let vfnote: Vex.Flow.StaveNote = VexFlowConverter.StaveNote(gnotes[voiceID]);
                 (graphicalStaffEntry as VexFlowStaffEntry).vfNotes[voiceID] = vfnote;
                 vfVoices[voiceID].addTickable(vfnote);
             }

+ 1 - 2
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer.ts

@@ -23,7 +23,6 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
 
     private renderer: Vex.Flow.Renderer;
     private ctx: Vex.Flow.CanvasContext;
-    private counter: number = 0;
 
     public drawSheet(graphicalMusicSheet: GraphicalMusicSheet): void {
         // FIXME units
@@ -39,7 +38,7 @@ export class VexFlowMusicSheetDrawer extends MusicSheetDrawer {
     protected drawMeasure(measure: VexFlowMeasure): void {
         measure.setAbsoluteCoordinates(
             measure.PositionAndShape.AbsolutePosition.x * (measure as VexFlowMeasure).unit,
-            measure.PositionAndShape.AbsolutePosition.y * (measure as VexFlowMeasure).unit + (this.counter += 5)
+            measure.PositionAndShape.AbsolutePosition.y * (measure as VexFlowMeasure).unit
         );
         return measure.draw(this.ctx);
     }

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

@@ -648,7 +648,7 @@ export class VoiceGenerator {
         return this.openTupletNumber;
     }
     private handleTimeModificationNode(noteNode: IXmlElement): void {
-        if (Object.keys(this.tupletDict).length !== 0) {
+        if (this.openTupletNumber in this.tupletDict) {
             try {
                 let tuplet: Tuplet = this.tupletDict[this.openTupletNumber];
                 let notes: Note[] = CollectionUtil.last(tuplet.Notes);