Browse Source

Fixed a lot of fraction comparissons.
Fixed Tie Dict by overriding toString() - The Dictionary does not work well regarding the keys...

Matthias 8 years ago
parent
commit
ac0be9e618

+ 1 - 0
package.json

@@ -28,6 +28,7 @@
   "dependencies": {
     "es6-promise": "^3.2.1",
     "jszip": "^3.0.0",
+    "shortid": "^2.2.6",
     "typescript-collections": "^1.1.2",
     "vexflow": "^1.2.53"
   },

+ 2 - 2
src/MusicalScore/Graphical/GraphicalMusicSheet.ts

@@ -303,7 +303,7 @@ export class GraphicalMusicSheet {
 
     public getOrCreateVerticalContainer(timestamp: Fraction): VerticalGraphicalStaffEntryContainer {
         if (this.verticalGraphicalStaffEntryContainers.length === 0 ||
-            timestamp .lt(CollectionUtil.getLastElement(this.verticalGraphicalStaffEntryContainers).AbsoluteTimestamp)) {
+            (CollectionUtil.getLastElement(this.verticalGraphicalStaffEntryContainers).AbsoluteTimestamp).lt(timestamp)) {
             let verticalGraphicalStaffEntryContainer: VerticalGraphicalStaffEntryContainer =
                 new VerticalGraphicalStaffEntryContainer(this.numberOfStaves, timestamp);
             this.verticalGraphicalStaffEntryContainers.push(verticalGraphicalStaffEntryContainer);
@@ -820,7 +820,7 @@ export class GraphicalMusicSheet {
                 let graphicalNotes: GraphicalNote[] = graphicalStaffEntry.notes[idx2];
                 for (let idx3: number = 0, len3: number = graphicalNotes.length; idx3 < len3; ++idx3) {
                     let note: GraphicalNote = graphicalNotes[idx3];
-                    if (note.graphicalNoteLength > maxLength) {
+                    if (maxLength.lt(note.graphicalNoteLength)) {
                         maxLength = note.graphicalNoteLength;
                     }
                 }

+ 4 - 4
src/MusicalScore/Graphical/GraphicalStaffEntry.ts

@@ -112,7 +112,7 @@ export abstract class GraphicalStaffEntry extends GraphicalObject {
                 let note: Note = graphicalNote.sourceNote;
                 if (
                     note.Pitch !== undefined && note.Pitch.FundamentalNote === tieNote.Pitch.FundamentalNote
-                    && note.Pitch.Octave === tieNote.Pitch.Octave && this.getAbsoluteTimestamp() === tieNote.getAbsoluteTimestamp()
+                    && note.Pitch.Octave === tieNote.Pitch.Octave && this.getAbsoluteTimestamp().Equals(tieNote.getAbsoluteTimestamp())
                 ) {
                     return graphicalNote;
                 }
@@ -139,7 +139,7 @@ export abstract class GraphicalStaffEntry extends GraphicalObject {
             let graphicalNotes: GraphicalNote[] = this.notes[idx];
             for (let idx2: number = 0, len2: number = graphicalNotes.length; idx2 < len2; ++idx2) {
                 let graphicalNote: GraphicalNote = graphicalNotes[idx2];
-                if (graphicalNote.sourceNote === baseNote && this.getAbsoluteTimestamp() === baseNote.getAbsoluteTimestamp()) {
+                if (graphicalNote.sourceNote === baseNote && this.getAbsoluteTimestamp().Equals(baseNote.getAbsoluteTimestamp())) {
                     return graphicalNote;
                 }
             }
@@ -213,7 +213,7 @@ export abstract class GraphicalStaffEntry extends GraphicalObject {
             for (let idx2: number = 0, len2: number = graphicalNotes.length; idx2 < len2; ++idx2) {
                 let graphicalNote: GraphicalNote = graphicalNotes[idx2];
                 let calNoteLen: Fraction = graphicalNote.graphicalNoteLength;
-                if (calNoteLen < minLength && calNoteLen.Numerator > 0) {
+                if (calNoteLen.lt(minLength) && calNoteLen.Numerator > 0) {
                     minLength = calNoteLen;
                 }
             }
@@ -228,7 +228,7 @@ export abstract class GraphicalStaffEntry extends GraphicalObject {
             for (let idx2: number = 0, len2: number = graphicalNotes.length; idx2 < len2; ++idx2) {
                 let graphicalNote: GraphicalNote = graphicalNotes[idx2];
                 let calNoteLen: Fraction = graphicalNote.graphicalNoteLength;
-                if (calNoteLen > maxLength && calNoteLen.Numerator > 0) {
+                if (maxLength.lt(calNoteLen)  && calNoteLen.Numerator > 0) {
                     maxLength = calNoteLen;
                 }
             }

+ 3 - 3
src/MusicalScore/Graphical/MusicSheetCalculator.ts

@@ -1079,8 +1079,8 @@ export abstract class MusicSheetCalculator {
                 let octaveShiftValue: OctaveEnum = OctaveEnum.NONE;
                 if (openOctaveShifts[staffIndex] !== undefined) {
                     let octaveShiftParams: OctaveShiftParams = openOctaveShifts[staffIndex];
-                    if (sourceStaffEntry.AbsoluteTimestamp >= octaveShiftParams.getAbsoluteStartTimestamp &&
-                        sourceStaffEntry.AbsoluteTimestamp <= octaveShiftParams.getAbsoluteEndTimestamp) {
+                    if (octaveShiftParams.getAbsoluteStartTimestamp.lte(sourceStaffEntry.AbsoluteTimestamp)  &&
+                        sourceStaffEntry.AbsoluteTimestamp.lte(octaveShiftParams.getAbsoluteEndTimestamp)) {
                         octaveShiftValue = octaveShiftParams.getOpenOctaveShift.Type;
                     }
                 }
@@ -1295,7 +1295,7 @@ export abstract class MusicSheetCalculator {
                             for (let idx6: number = 0, len6: number = graphicalStaffEntry.sourceStaffEntry.VoiceEntries.length; idx6 < len6; ++idx6) {
                                 let voiceEntry: VoiceEntry = graphicalStaffEntry.sourceStaffEntry.VoiceEntries[idx6];
                                 if (voiceEntry.OrnamentContainer !== undefined) {
-                                    if (voiceEntry.hasTie() && graphicalStaffEntry.relInMeasureTimestamp !== voiceEntry.Timestamp) {
+                                    if (voiceEntry.hasTie() && !graphicalStaffEntry.relInMeasureTimestamp.Equals(voiceEntry.Timestamp)) {
                                         continue;
                                     }
                                     this.layoutOrnament(voiceEntry.OrnamentContainer, voiceEntry, graphicalStaffEntry);

+ 6 - 6
src/MusicalScore/Graphical/StaffMeasure.ts

@@ -128,7 +128,7 @@ export abstract class StaffMeasure extends GraphicalObject {
     public findGraphicalStaffEntryFromTimestamp(relativeTimestamp: Fraction): GraphicalStaffEntry {
         for (let idx: number = 0, len: number = this.staffEntries.length; idx < len; ++idx) {
             let graphicalStaffEntry: GraphicalStaffEntry = this.staffEntries[idx];
-            if (graphicalStaffEntry.relInMeasureTimestamp === relativeTimestamp) {
+            if (graphicalStaffEntry.relInMeasureTimestamp.Equals(relativeTimestamp)) {
                 return graphicalStaffEntry;
             }
         }
@@ -138,7 +138,7 @@ export abstract class StaffMeasure extends GraphicalObject {
     public findGraphicalStaffEntryFromVerticalContainerTimestamp(absoluteTimestamp: Fraction): GraphicalStaffEntry {
         for (let idx: number = 0, len: number = this.staffEntries.length; idx < len; ++idx) {
             let graphicalStaffEntry: GraphicalStaffEntry = this.staffEntries[idx];
-            if (graphicalStaffEntry.sourceStaffEntry.VerticalContainerParent.getAbsoluteTimestamp() === absoluteTimestamp) {
+            if (graphicalStaffEntry.sourceStaffEntry.VerticalContainerParent.getAbsoluteTimestamp().Equals(absoluteTimestamp)) {
                 return graphicalStaffEntry;
             }
         }
@@ -151,7 +151,7 @@ export abstract class StaffMeasure extends GraphicalObject {
             let graphicalStaffEntry: GraphicalStaffEntry = this.staffEntries[idx];
             duration.Add(graphicalStaffEntry.findStaffEntryMinNoteLength());
         }
-        return duration === this.parentSourceMeasure.Duration;
+        return duration.Equals(this.parentSourceMeasure.Duration);
     }
 
     public hasMultipleVoices(): boolean {
@@ -202,7 +202,7 @@ export abstract class StaffMeasure extends GraphicalObject {
                     }
                 }
             }
-            if (voiceDuration > duration) {
+            if (duration.lt(voiceDuration)) {
                 duration = Fraction.createFromFraction(voiceDuration);
             }
         }
@@ -216,11 +216,11 @@ export abstract class StaffMeasure extends GraphicalObject {
 
     public addGraphicalStaffEntryAtTimestamp(staffEntry: GraphicalStaffEntry): void {
         if (staffEntry !== undefined) {
-            if (this.staffEntries.length === 0 || this.staffEntries[this.staffEntries.length - 1].relInMeasureTimestamp < staffEntry.relInMeasureTimestamp) {
+            if (this.staffEntries.length === 0 || this.staffEntries[this.staffEntries.length - 1].relInMeasureTimestamp.lt(staffEntry.relInMeasureTimestamp)) {
                 this.staffEntries.push(staffEntry);
             } else {
                 for (let i: number = this.staffEntries.length - 1; i >= 0; i--) {
-                    if (this.staffEntries[i].relInMeasureTimestamp < staffEntry.relInMeasureTimestamp) {
+                    if (this.staffEntries[i].relInMeasureTimestamp.lt(staffEntry.relInMeasureTimestamp)) {
                         this.staffEntries.splice(i + 1, 0, staffEntry);
                         break;
                     }

+ 1 - 1
src/MusicalScore/MusicParts/MusicPartManager.ts

@@ -79,7 +79,7 @@ export class MusicPartManager /*implements ISelectionListener*/ {
                     curTimestampTransform.curRepetition = jumpRep;
                     curTimestampTransform.curRepetitionIteration = iterator.CurrentJumpResponsibleRepetitionIterationBeforeJump;
                     for (let i: number = this.timestamps.length - 2; i >= 0; i--) {
-                        if (jumpRep.AbsoluteTimestamp > timestamps[i].to || timestamps[i].curRepetition !== undefined) {
+                        if (timestamps[i].to.lt(jumpRep.AbsoluteTimestamp) || timestamps[i].curRepetition !== undefined) {
                             break;
                         }
                         timestamps[i].nextBackJump = curTimestampTransform.nextBackJump;

+ 11 - 11
src/MusicalScore/MusicParts/MusicPartManagerIterator.ts

@@ -383,24 +383,24 @@ export class MusicPartManagerIterator {
         while (
           this.currentDynamicEntryIndex > 0 && (
             this.currentDynamicEntryIndex >= timeSortedDynamics.length ||
-            timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp >= this.CurrentSourceTimestamp
+            this.CurrentSourceTimestamp.lte(timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp)
           )
         ) {
             this.currentDynamicEntryIndex--;
         }
         while (
           this.currentDynamicEntryIndex < timeSortedDynamics.length &&
-          timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp < this.CurrentSourceTimestamp
+          timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp.lt(this.CurrentSourceTimestamp)
         ) {
             this.currentDynamicEntryIndex++;
         }
         while (
           this.currentDynamicEntryIndex < timeSortedDynamics.length
-          && timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp === this.CurrentSourceTimestamp
+          && timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp.Equals(this.CurrentSourceTimestamp)
         ) {
             let dynamicsContainer: DynamicsContainer = timeSortedDynamics[this.currentDynamicEntryIndex];
             let staffIndex: number = dynamicsContainer.staffNumber;
-            if (this.CurrentSourceTimestamp === dynamicsContainer.parMultiExpression().AbsoluteTimestamp) {
+            if (this.CurrentSourceTimestamp.Equals(dynamicsContainer.parMultiExpression().AbsoluteTimestamp)) {
                 if (dynamicsContainer.continuousDynamicExpression !== undefined) {
                     this.activeDynamicExpressions[staffIndex] = dynamicsContainer.continuousDynamicExpression;
                 } else if (dynamicsContainer.instantaneousDynamicExpression !== undefined) {
@@ -418,12 +418,12 @@ export class MusicPartManagerIterator {
                     let continuousDynamic: ContinuousDynamicExpression = <ContinuousDynamicExpression>this.activeDynamicExpressions[staffIndex];
                     startTime = continuousDynamic.StartMultiExpression.AbsoluteTimestamp;
                     endTime = continuousDynamic.EndMultiExpression.AbsoluteTimestamp;
-                    if (this.CurrentSourceTimestamp >= startTime && this.CurrentSourceTimestamp <= endTime) {
+                    if (startTime.lte(this.CurrentSourceTimestamp) && this.CurrentSourceTimestamp.lte(endTime)) {
                         this.currentDynamicChangingExpressions.push(new DynamicsContainer(continuousDynamic, staffIndex));
                     }
                 } else {
                     let instantaniousDynamic: InstantaniousDynamicExpression = <InstantaniousDynamicExpression>this.activeDynamicExpressions[staffIndex];
-                    if (this.CurrentSourceTimestamp === instantaniousDynamic.ParentMultiExpression.AbsoluteTimestamp) {
+                    if (this.CurrentSourceTimestamp.Equals(instantaniousDynamic.ParentMultiExpression.AbsoluteTimestamp)) {
                         this.currentDynamicChangingExpressions.push(new DynamicsContainer(instantaniousDynamic, staffIndex));
                     }
                 }
@@ -433,21 +433,21 @@ export class MusicPartManagerIterator {
 
         while (this.currentTempoEntryIndex > 0 && (
           this.currentTempoEntryIndex >= timeSortedTempoExpressions.length
-          || timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp >= this.CurrentSourceTimestamp
+          || this.CurrentSourceTimestamp.lte(timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp)
         )) {
             this.currentTempoEntryIndex--;
         }
 
         while (
           this.currentTempoEntryIndex < timeSortedTempoExpressions.length &&
-          timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp < this.CurrentSourceTimestamp
+          timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp.lt(this.CurrentSourceTimestamp)
         ) {
             this.currentTempoEntryIndex++;
         }
 
         while (
           this.currentTempoEntryIndex < timeSortedTempoExpressions.length
-          && timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp === this.CurrentSourceTimestamp
+          && timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp.Equals(this.CurrentSourceTimestamp)
         ) {
             this.activeTempoExpression = timeSortedTempoExpressions[this.currentTempoEntryIndex];
             this.currentTempoEntryIndex++;
@@ -458,8 +458,8 @@ export class MusicPartManagerIterator {
             if (this.activeTempoExpression.ContinuousTempo !== undefined) {
                 endTime = this.activeTempoExpression.ContinuousTempo.AbsoluteEndTimestamp;
             }
-            if (   this.CurrentSourceTimestamp >= this.activeTempoExpression.AbsoluteTimestamp
-                || this.CurrentSourceTimestamp <= endTime
+            if (   this.activeTempoExpression.AbsoluteTimestamp.lte(this.CurrentSourceTimestamp)
+                || this.CurrentSourceTimestamp.lte(endTime)
             ) {
                 this.currentTempoChangingExpression = this.activeTempoExpression;
             }

+ 1 - 1
src/MusicalScore/MusicSheet.ts

@@ -463,7 +463,7 @@ export class MusicSheet /*implements ISettableMusicSheet, IComparable<MusicSheet
             let sm: SourceMeasure = this.sourceMeasures[idx];
             for (let idx2: number = 0, len2: number = sm.VerticalSourceStaffEntryContainers.length; idx2 < len2; ++idx2) {
                 let vssec: VerticalSourceStaffEntryContainer = sm.VerticalSourceStaffEntryContainers[idx2];
-                if (Fraction.Equal(timeStamp, vssec.getAbsoluteTimestamp())) {
+                if (timeStamp.Equals(vssec.getAbsoluteTimestamp())) {
                     return sm;
                 }
             }

+ 2 - 2
src/MusicalScore/ScoreIO/MusicSheetReader.ts

@@ -372,7 +372,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
             return true;
         }
         if (this.previousMeasure !== undefined) {
-            return Fraction.plus(this.previousMeasure.Duration, maxInstrumentDuration).CompareTo(activeRhythm) === 0;
+            return Fraction.plus(this.previousMeasure.Duration, maxInstrumentDuration).Equals(activeRhythm);
         }
         return false;
     }
@@ -381,7 +381,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         let counter: number = 0;
         for (let idx: number = 0, len: number = instrumentsDurations.length; idx < len; ++idx) {
             let instrumentsDuration: Fraction = instrumentsDurations[idx];
-            if (instrumentsDuration === maxInstrumentDuration) {
+            if (instrumentsDuration.Equals(maxInstrumentDuration)) {
                 counter++;
             }
         }

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

@@ -449,7 +449,7 @@ export class VoiceGenerator {
                         let voiceEntry: VoiceEntry = nextStaffEntry.VoiceEntries[idx];
                         if (voiceEntry.ParentVoice === this.voice) {
                             let candidateNote: Note = voiceEntry.Notes[0];
-                            if (candidateNote.Length <= new Fraction(1, 8)) {
+                            if (candidateNote.Length.lte(new Fraction(1, 8))) {
                                 this.openBeam.addNoteToBeam(candidateNote);
                                 this.openBeam = undefined;
                             } else {
@@ -654,7 +654,7 @@ export class VoiceGenerator {
                 let notes: Note[] = CollectionUtil.last(tuplet.Notes);
                 let lastTupletVoiceEntry: VoiceEntry = notes[0].ParentVoiceEntry;
                 let noteList: Note[];
-                if (lastTupletVoiceEntry.Timestamp === this.currentVoiceEntry.Timestamp) {
+                if (lastTupletVoiceEntry.Timestamp.Equals(this.currentVoiceEntry.Timestamp)) {
                     noteList = notes;
                 } else {
                     noteList = [];

+ 1 - 1
src/MusicalScore/VoiceData/Expressions/ContinuousExpressions/ContinuousDynamicExpression.ts

@@ -101,7 +101,7 @@ export class ContinuousDynamicExpression extends AbstractExpression {
             );
         }
         if (currentAbsoluteTimestamp.lt(continuousAbsoluteStartTimestamp)) { return -1; }
-        if (currentAbsoluteTimestamp.lt(continuousAbsoluteEndTimestamp)) { return -2; }
+        if (continuousAbsoluteEndTimestamp.lt(currentAbsoluteTimestamp)) { return -2; }
         let interpolationRatio: number =
             Fraction.minus(currentAbsoluteTimestamp, continuousAbsoluteStartTimestamp).RealValue
             / Fraction.minus(continuousAbsoluteEndTimestamp, continuousAbsoluteStartTimestamp).RealValue;

+ 1 - 1
src/MusicalScore/VoiceData/Expressions/ContinuousExpressions/ContinuousTempoExpression.ts

@@ -72,7 +72,7 @@ export class ContinuousTempoExpression extends AbstractTempoExpression {
             this.parentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp, this.parentMultiTempoExpression.Timestamp
         );
         if (currentAbsoluteTimestamp.lt(continuousAbsoluteStartTimestamp)) { return -1; }
-        if (currentAbsoluteTimestamp.lt(this.absoluteEndTimestamp)) { return -2; }
+        if (this.absoluteEndTimestamp.lt(currentAbsoluteTimestamp)) { return -2; }
         let interpolationRatio: number =
             Fraction.minus(currentAbsoluteTimestamp, continuousAbsoluteStartTimestamp).RealValue
             / Fraction.minus(this.absoluteEndTimestamp, continuousAbsoluteStartTimestamp).RealValue;

+ 1 - 0
src/MusicalScore/VoiceData/SourceMeasure.ts

@@ -279,6 +279,7 @@ export class SourceMeasure {
                 maxDuration = instrumentsDuration;
             }
         }
+
         return Fraction.max(maxDuration, maxInstDuration);
     }
 

+ 2 - 2
src/MusicalScore/VoiceData/SourceStaffEntry.ts

@@ -181,10 +181,10 @@ export class SourceStaffEntry {
             for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
                 let note: Note = voiceEntry.Notes[idx2];
                 if (note.NoteTie !== undefined) {
-                    if (duration > note.calculateNoteLengthWithoutTie()) {
+                    if (note.calculateNoteLengthWithoutTie().lt(duration)) {
                         duration = note.calculateNoteLengthWithoutTie();
                     }
-                } else if (duration > note.Length) {
+                } else if (note.Length.lt(duration)) {
                     duration = note.Length;
                 }
             }

+ 6 - 1
src/MusicalScore/VoiceData/Tie.ts

@@ -2,9 +2,12 @@ import {Note} from "./Note";
 import {Beam} from "./Beam";
 import {Fraction} from "../../Common/DataObjects/Fraction";
 import {Tuplet} from "./Tuplet";
+import {BaseIdClass} from "./BaseIdClass";
+
+export class Tie extends BaseIdClass {
 
-export class Tie {
     constructor(note: Note) {
+        super();
         this.start = note;
     }
     private start: Note;
@@ -14,6 +17,7 @@ export class Tie {
     private fractions: Fraction[] = [];
     private noteHasBeenCreated: boolean[] = [];
     private baseNoteYPosition: number;
+
     public get Start(): Note {
         return this.start;
     }
@@ -67,6 +71,7 @@ export class Tie {
         for (let idx: number = 0, len: number = this.noteHasBeenCreated.length; idx < len; ++idx) {
             if (!this.noteHasBeenCreated[idx]) { return false; }
         }
+
         return true;
     }
 }

+ 2 - 1
typings.json

@@ -1,7 +1,8 @@
 {
   "globalDependencies": {
     "chai": "registry:dt/chai#3.4.0+20160317120654",
-    "mocha": "registry:dt/mocha#2.2.5+20160317120654"
+    "mocha": "registry:dt/mocha#2.2.5+20160317120654",
+    "shortid": "registry:dt/shortid#0.0.0+20160316155526"
   },
   "dependencies": {
     "es6-promise": "registry:npm/es6-promise#3.0.0+20160211003958",