Browse Source

Fixed bugs in reading clef,key, rhythm instructions.
Added comments how and where to use the accidental info.

Matthias 9 years ago
parent
commit
0906f25469

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

@@ -51,23 +51,23 @@ export class VexFlowConverter {
         let octave: number = pitch.Octave + clef.OctaveOffset + 3; // FIXME + 3
         let acc: string = "";
 
-        switch (pitch.Accidental) {
-            case AccidentalEnum.NONE:
-                break;
-            case AccidentalEnum.FLAT:
-                acc = "b";
-                break;
-            case AccidentalEnum.SHARP:
-                acc = "#";
-                break;
-            case AccidentalEnum.DOUBLESHARP:
-                acc = "##";
-                break;
-            case AccidentalEnum.DOUBLEFLAT:
-                acc = "bb";
-                break;
-            default:
-        }
+        // switch (pitch.Accidental) {
+        //     case AccidentalEnum.NONE:
+        //         break;
+        //     case AccidentalEnum.FLAT:
+        //         acc = "b";
+        //         break;
+        //     case AccidentalEnum.SHARP:
+        //         acc = "#";
+        //         break;
+        //     case AccidentalEnum.DOUBLESHARP:
+        //         acc = "##";
+        //         break;
+        //     case AccidentalEnum.DOUBLEFLAT:
+        //         acc = "bb";
+        //         break;
+        //     default:
+        // }
         return [fund + acc + "/" + octave, acc, clef];
     }
 

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

@@ -8,6 +8,7 @@ export class VexFlowGraphicalNote extends GraphicalNote {
     constructor(note: Note, parent: GraphicalStaffEntry, activeClef: ClefInstruction) {
         super(note, parent);
         if (note.Pitch) {
+            // ToDo: don't use accidental info here - set it in factory.
             this.vfpitch = VexFlowConverter.pitch(note.Pitch, activeClef);
         } else {
             this.vfpitch = undefined;

+ 3 - 1
src/MusicalScore/Graphical/VexFlow/VexFlowGraphicalSymbolFactory.ts

@@ -127,7 +127,9 @@ export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
      * @param graceScalingFactor
      */
     public addGraphicalAccidental(graphicalNote: GraphicalNote, pitch: Pitch, grace: boolean, graceScalingFactor: number): void {
-        return;
+        let note: VexFlowGraphicalNote = <VexFlowGraphicalNote> graphicalNote;
+        // ToDo: set accidental here from pitch.Accidental
+        //note.vfpitch = 
     }
 
     /**

+ 7 - 7
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -735,7 +735,7 @@ export class InstrumentReader {
                         === this.instrument.Staves.indexOf(this.currentStaffEntry.ParentStaff)) {
                         let newClefInstruction: ClefInstruction = clefInstruction;
                         newClefInstruction.Parent = this.currentStaffEntry;
-                        this.currentStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
+                        this.currentStaffEntry.removeFirstInstructionOfTypeClefInstruction();
                         this.currentStaffEntry.Instructions.push(newClefInstruction);
                         this.activeClefs[key - 1] = clefInstruction;
                         this.abstractInstructions.splice(i, 1);
@@ -757,7 +757,7 @@ export class InstrumentReader {
                                     undefined && !(firstSse.Instructions[0] instanceof ClefInstruction)) {
                                     firstStaffEntry = firstSse;
                                     newClefInstruction.Parent = firstStaffEntry;
-                                    firstStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
+                                    firstStaffEntry.removeFirstInstructionOfTypeClefInstruction();
                                     firstStaffEntry.Instructions.splice(0, 0, newClefInstruction);
                                     this.activeClefsHaveBeenInitialized[key - 1] = true;
                                 } else {
@@ -772,7 +772,7 @@ export class InstrumentReader {
                                     firstStaffEntry = new SourceStaffEntry(undefined, undefined);
                                 } else {
                                     firstStaffEntry = first.FirstInstructionsStaffEntries[sseIndex];
-                                    firstStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
+                                    firstStaffEntry.removeFirstInstructionOfTypeClefInstruction();
                                 }
                                 newClefInstruction.Parent = firstStaffEntry;
                                 firstStaffEntry.Instructions.splice(0, 0, newClefInstruction);
@@ -788,7 +788,7 @@ export class InstrumentReader {
                         }
                     }
                 }
-                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);
                 }
             }
@@ -833,7 +833,7 @@ export class InstrumentReader {
                         }
                     }
                 }
-                if (this.activeKey !== undefined && this.activeKey === keyInstruction) {
+                else {
                     this.abstractInstructions.splice(i, 1);
                 }
             }
@@ -851,14 +851,14 @@ export class InstrumentReader {
                                 this.currentMeasure.FirstInstructionsStaffEntries[j] = firstStaffEntry;
                             } else {
                                 firstStaffEntry = this.currentMeasure.FirstInstructionsStaffEntries[j];
-                                firstStaffEntry.removeFirstInstructionOfType<RhythmInstruction>();
+                                firstStaffEntry.removeFirstInstructionOfTypeRhythmInstruction();
                             }
                             newRhythmInstruction.Parent = firstStaffEntry;
                             firstStaffEntry.Instructions.push(newRhythmInstruction);
                         }
                     }
                 }
-                if (this.activeRhythm !== undefined && this.activeRhythm === rhythmInstruction) {
+                else {
                     this.abstractInstructions.splice(i, 1);
                 }
             }

+ 34 - 25
src/MusicalScore/VoiceData/SourceStaffEntry.ts

@@ -77,31 +77,30 @@ export class SourceStaffEntry {
         this.chordSymbolContainer = value;
     }
 
-    public removeAllInstructionsOfType<T>(): number {
-        let i: number = 0;
-        let ret: number = 0;
-        while (i < this.instructions.length) {
-            let instruction: Object = this.instructions[i];
-            if (<T>instruction !== undefined) {
-                this.instructions.splice(i, 1);
-                ret++;
-            } else {
-                i++;
-            }
-        }
-        return ret;
-    }
-
-    public removeFirstInstructionOfType<T>(): boolean {
-        for (let i: number = 0; i < this.instructions.length; i++) {
-            let instruction: Object = this.instructions[i];
-            if (<T>instruction !== undefined) {
-                this.instructions.splice(i, 1);
-                return true;
-            }
-        }
-        return false;
-    }
+    // public removeAllInstructionsOfType(type: AbstractNotationInstruction): number {
+    //     let i: number = 0;
+    //     let ret: number = 0;
+    //     while (i < this.instructions.length) {
+    //         let instruction: AbstractNotationInstruction = this.instructions[i];
+    //         if (instruction instanceof type) {
+    //             this.instructions.splice(i, 1);
+    //             ret++;
+    //         } else {
+    //             i++;
+    //         }
+    //     }
+    //     return ret;
+    // }
+    //
+    // public removeFirstInstructionOfType(type: AbstractNotationInstruction): boolean {
+    //     for (let i: number = 0; i < this.instructions.length; i++) {
+    //         if (this.instructions[i] instanceof type) {
+    //             this.instructions.splice(i, 1);
+    //             return true;
+    //         }
+    //     }
+    //     return false;
+    // }
 
     public removeAllInstructionsOfTypeClefInstruction(): number {
         let i: number = 0;
@@ -165,6 +164,16 @@ export class SourceStaffEntry {
         return ret;
     }
 
+    public removeFirstInstructionOfTypeRhythmInstruction(): boolean {
+        for (let i: number = 0; i < this.instructions.length; i++) {
+            if (this.instructions[i] instanceof RhythmInstruction) {
+                this.instructions.splice(i, 1);
+                return true;
+            }
+        }
+        return false;
+    }
+
     public calculateMinNoteLength(): Fraction {
         let duration: Fraction = new Fraction(Number.MAX_VALUE, 1);
         for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {

+ 1 - 1
test/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetDrawer.ts

@@ -9,7 +9,7 @@ import {IXmlElement} from "../../../../src/Common/FileIO/Xml";
 describe("VexFlow Music Sheet Drawer", () => {
 
     it(".drawSheet (Clementi pt. 1)", (done: MochaDone) => {
-        let path: string = "test/data/MuzioClementi_SonatinaOpus36No1_Part1.xml";
+        let path: string = "test/data/MuzioClementi_SonatinaOpus36No1_Part2.xml";
         // "test/data/MuzioClementi_SonatinaOpus36No1_Part1.xml";
         let score: IXmlElement = TestUtils.getScore(path);
         chai.expect(score).to.not.be.undefined;