Browse Source

Fixed bug with accidentals

Andrea Condoluci 9 years ago
parent
commit
7038f656d7

+ 7 - 9
src/MusicalScore/Graphical/AccidentalCalculator.ts

@@ -28,10 +28,8 @@ export class AccidentalCalculator {
 
 
     public doCalculationsAtEndOfMeasure(): void {
     public doCalculationsAtEndOfMeasure(): void {
         this.currentInMeasureNoteAlterationsDict.clear();
         this.currentInMeasureNoteAlterationsDict.clear();
-        for (let key in this.keySignatureNoteAlterationsDict) {
-            if (this.keySignatureNoteAlterationsDict.hasOwnProperty(key)) {
-                this.currentInMeasureNoteAlterationsDict[key] = this.keySignatureNoteAlterationsDict[key];
-            }
+        for (let key of this.keySignatureNoteAlterationsDict.keys()) {
+            this.currentInMeasureNoteAlterationsDict.setValue(key, this.keySignatureNoteAlterationsDict.getValue(key));
         }
         }
     }
     }
 
 
@@ -42,21 +40,21 @@ export class AccidentalCalculator {
         let pitchKey: number = <number>pitch.FundamentalNote + pitch.Octave * 12;
         let pitchKey: number = <number>pitch.FundamentalNote + pitch.Octave * 12;
         let pitchKeyGivenInMeasureDict: boolean = this.currentInMeasureNoteAlterationsDict.containsKey(pitchKey);
         let pitchKeyGivenInMeasureDict: boolean = this.currentInMeasureNoteAlterationsDict.containsKey(pitchKey);
         if (
         if (
-            (pitchKeyGivenInMeasureDict && this.currentInMeasureNoteAlterationsDict[pitchKey] !== pitch.Accidental)
+            (pitchKeyGivenInMeasureDict && this.currentInMeasureNoteAlterationsDict.getValue(pitchKey) !== pitch.Accidental)
             || (!pitchKeyGivenInMeasureDict && pitch.Accidental !== AccidentalEnum.NONE)
             || (!pitchKeyGivenInMeasureDict && pitch.Accidental !== AccidentalEnum.NONE)
         ) {
         ) {
             if (this.currentAlterationsComparedToKeyInstructionDict.indexOf(pitchKey) === -1) {
             if (this.currentAlterationsComparedToKeyInstructionDict.indexOf(pitchKey) === -1) {
                 this.currentAlterationsComparedToKeyInstructionDict.push(pitchKey);
                 this.currentAlterationsComparedToKeyInstructionDict.push(pitchKey);
             }
             }
-            this.currentInMeasureNoteAlterationsDict[pitchKey] = pitch.Accidental;
+            this.currentInMeasureNoteAlterationsDict.setValue(pitchKey, pitch.Accidental);
             this.symbolFactory.addGraphicalAccidental(graphicalNote, pitch, grace, graceScalingFactor);
             this.symbolFactory.addGraphicalAccidental(graphicalNote, pitch, grace, graceScalingFactor);
         } else if (
         } else if (
             this.currentAlterationsComparedToKeyInstructionDict.indexOf(pitchKey) !== -1
             this.currentAlterationsComparedToKeyInstructionDict.indexOf(pitchKey) !== -1
-            && ((pitchKeyGivenInMeasureDict && this.currentInMeasureNoteAlterationsDict[pitchKey] !== pitch.Accidental)
+            && ((pitchKeyGivenInMeasureDict && this.currentInMeasureNoteAlterationsDict.getValue(pitchKey) !== pitch.Accidental)
             || (!pitchKeyGivenInMeasureDict && pitch.Accidental === AccidentalEnum.NONE))
             || (!pitchKeyGivenInMeasureDict && pitch.Accidental === AccidentalEnum.NONE))
         ) {
         ) {
             delete this.currentAlterationsComparedToKeyInstructionDict[pitchKey];
             delete this.currentAlterationsComparedToKeyInstructionDict[pitchKey];
-            this.currentInMeasureNoteAlterationsDict[pitchKey] = pitch.Accidental;
+            this.currentInMeasureNoteAlterationsDict.setValue(pitchKey, pitch.Accidental);
             this.symbolFactory.addGraphicalAccidental(graphicalNote, pitch, grace, graceScalingFactor);
             this.symbolFactory.addGraphicalAccidental(graphicalNote, pitch, grace, graceScalingFactor);
         }
         }
     }
     }
@@ -73,7 +71,7 @@ export class AccidentalCalculator {
         this.currentAlterationsComparedToKeyInstructionDict.length = 0;
         this.currentAlterationsComparedToKeyInstructionDict.length = 0;
         for (let octave: number = -9; octave < 9; octave++) {
         for (let octave: number = -9; octave < 9; octave++) {
             for (let i: number = 0; i < noteEnums.length; i++) {
             for (let i: number = 0; i < noteEnums.length; i++) {
-                this.keySignatureNoteAlterationsDict[<number>noteEnums[i] + octave * 12] = keyAccidentalType;
+                this.keySignatureNoteAlterationsDict.setValue(<number>noteEnums[i] + octave * 12, keyAccidentalType);
             }
             }
         }
         }
         this.doCalculationsAtEndOfMeasure();
         this.doCalculationsAtEndOfMeasure();

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

@@ -52,7 +52,7 @@ export class VexFlowConverter {
         // The octave seems to need a shift of three FIXME?
         // The octave seems to need a shift of three FIXME?
         let octave: number = pitch.Octave + clef.OctaveOffset + 3;
         let octave: number = pitch.Octave + clef.OctaveOffset + 3;
         let acc: string = VexFlowConverter.accidental(pitch.Accidental);
         let acc: string = VexFlowConverter.accidental(pitch.Accidental);
-        return [fund + "b/" + octave, acc, clef];
+        return [fund + "n/" + octave, acc, clef];
     }
     }
 
 
     /**
     /**
@@ -64,6 +64,7 @@ export class VexFlowConverter {
         let acc: string;
         let acc: string;
         switch (accidental) {
         switch (accidental) {
             case AccidentalEnum.NONE:
             case AccidentalEnum.NONE:
+                acc = "n";
                 break;
                 break;
             case AccidentalEnum.FLAT:
             case AccidentalEnum.FLAT:
                 acc = "b";
                 acc = "b";