Browse Source

Fixed bug in measure number calculation.
Fixed wrong fraction comparisons.
Fixed tie graphical note creation.

Matthias 8 năm trước cách đây
mục cha
commit
a9fdf86d8f

+ 21 - 1
src/MusicalScore/Graphical/GraphicalNote.ts

@@ -10,16 +10,28 @@ import {MusicSheetCalculator} from "./MusicSheetCalculator";
 import {BoundingBox} from "./BoundingBox";
 
 export class GraphicalNote extends GraphicalObject {
-    constructor(note: Note, parent: GraphicalStaffEntry) {
+    constructor(note: Note, parent: GraphicalStaffEntry, graphicalNoteLength: Fraction = undefined) {
         super();
         this.sourceNote = note;
         this.parentStaffEntry = parent;
         this.PositionAndShape = new BoundingBox(this, parent.PositionAndShape);
+        if (graphicalNoteLength !== undefined) {
+            this.graphicalNoteLength = graphicalNoteLength;
+        } else {
+            if (note.NoteTie !== undefined) {
+                this.graphicalNoteLength = note.calculateNoteLengthWithoutTie();
+            } else {
+                this.graphicalNoteLength = note.Length;
+            }
+        }
+
+        this.numberOfDots = this.calculateNumberOfNeededDots(this.graphicalNoteLength);
     }
 
     public sourceNote: Note;
     public graphicalNoteLength: Fraction;
     public parentStaffEntry: GraphicalStaffEntry;
+    public numberOfDots: number;
 
     public get ParentList(): GraphicalNote[] {
         for (let idx: number = 0, len: number = this.parentStaffEntry.notes.length; idx < len; ++idx) {
@@ -38,4 +50,12 @@ export class GraphicalNote extends GraphicalObject {
         }
         return transposedPitch;
     }
+
+    private calculateNumberOfNeededDots(fraction: Fraction): number {
+        let dotCount: number = 0;
+        if (this.sourceNote === undefined || this.sourceNote.NoteTuplet === undefined) {
+            dotCount = Math.floor(Math.log(fraction.Numerator) / Math.LN2);
+        }
+        return Math.min(3, dotCount);
+    }
 }

+ 71 - 28
src/MusicalScore/Graphical/MusicSheetCalculator.ts

@@ -36,7 +36,6 @@ import {TextAlignment} from "../../Common/Enums/TextAlignment";
 import {VerticalGraphicalStaffEntryContainer} from "./VerticalGraphicalStaffEntryContainer";
 import {KeyInstruction} from "../VoiceData/Instructions/KeyInstruction";
 import {AbstractNotationInstruction} from "../VoiceData/Instructions/AbstractNotationInstruction";
-import {ClefEnum} from "../VoiceData/Instructions/ClefInstruction";
 import {TechnicalInstruction} from "../VoiceData/Instructions/TechnicalInstruction";
 import {Pitch} from "../../Common/DataObjects/Pitch";
 import {LinkedVoice} from "../VoiceData/LinkedVoice";
@@ -194,10 +193,9 @@ export abstract class MusicSheetCalculator {
         throw new Error("abstract, not implemented");
     }
 
-    protected createGraphicalTieNote(beams: Beam[], activeClef: ClefInstruction,
-                                     octaveShiftValue: OctaveEnum,
-                                     graphicalStaffEntry: GraphicalStaffEntry, duration: Fraction, numberOfDots: number,
-                                     openTie: Tie, isLastTieNote: boolean): void {
+    protected handleTiedGraphicalNote(tiedGraphicalNote: GraphicalNote, beams: Beam[], activeClef: ClefInstruction,
+                                      octaveShiftValue: OctaveEnum, graphicalStaffEntry: GraphicalStaffEntry, duration: Fraction,
+                                      openTie: Tie, isLastTieNote: boolean): void {
         throw new Error("abstract, not implemented");
     }
 
@@ -230,8 +228,8 @@ export abstract class MusicSheetCalculator {
         throw new Error("abstract, not implemented");
     }
 
-    protected handleTie(tie: Tie, startGraphicalStaffEntry: GraphicalStaffEntry, staffIndex: number,
-                        measureIndex: number): void {
+    protected createGraphicalTie(tie: Tie, startGse: GraphicalStaffEntry, endGse: GraphicalStaffEntry, startNote: GraphicalNote,
+                                 endNote: GraphicalNote): GraphicalTie {
         throw new Error("abstract, not implemented");
     }
 
@@ -526,11 +524,10 @@ export abstract class MusicSheetCalculator {
                 continue;
             }
             let graphicalNote: GraphicalNote;
-            let numberOfDots: number = note.calculateNumberOfNeededDots();
             if (grace) {
-                graphicalNote = this.symbolFactory.createGraceNote(note, numberOfDots, graphicalStaffEntry, activeClef, octaveShiftValue);
+                graphicalNote = this.symbolFactory.createGraceNote(note, graphicalStaffEntry, activeClef, octaveShiftValue);
             } else {
-                graphicalNote = this.symbolFactory.createNote(note, numberOfDots, graphicalStaffEntry, activeClef, octaveShiftValue);
+                graphicalNote = this.symbolFactory.createNote(note, graphicalStaffEntry, activeClef, octaveShiftValue, undefined);
             }
             if (note.NoteTie !== undefined) {
                 MusicSheetCalculator.addTieToTieTimestampsDict(tieTimestampListDict, note);
@@ -591,51 +588,59 @@ export abstract class MusicSheetCalculator {
 
     protected handleOpenTies(measure: StaffMeasure, beams: Beam[], tieTimestampListDict: Dictionary<Tie, Fraction[]>,
                              activeClef: ClefInstruction, octaveShiftParams: OctaveShiftParams): void {
-        CollectionUtil.removeDictElementIfTrue(tieTimestampListDict, function (openTie: Tie, tieTimestamps: Fraction[]): boolean {
+        CollectionUtil.removeDictElementIfTrue(this, tieTimestampListDict, function (thisPointer: MusicSheetCalculator, openTie: Tie, tieTimestamps: Fraction[]): boolean {
             // for (let m: number = tieTimestampListDict.size() - 1; m >= 0; m--) {
             //     let keyValuePair: KeyValuePair<Tie, Fraction[]> = tieTimestampListDict.ElementAt(m);
             //     let openTie: Tie = keyValuePair.Key;
             //    let tieTimestamps: Fraction[] = keyValuePair.Value;
             let absoluteTimestamp: Fraction = undefined;
-            let k: number;
+
             let removeTie: boolean = false;
-            for (; k < tieTimestamps.length; k++) {
+            for (let k: number = 0; k < tieTimestamps.length; k++) {
                 if (!openTie.NoteHasBeenCreated[k]) {
                     absoluteTimestamp = tieTimestamps[k];
-                    if (absoluteTimestamp >= Fraction.plus(measure.parentSourceMeasure.AbsoluteTimestamp, measure.parentSourceMeasure.Duration)) {
+                    if (Fraction.plus(measure.parentSourceMeasure.AbsoluteTimestamp, measure.parentSourceMeasure.Duration).lte(absoluteTimestamp)) {
                         continue;
                     }
                     let graphicalStaffEntry: GraphicalStaffEntry = undefined;
                     if (absoluteTimestamp !== undefined) {
                         for (let idx: number = 0, len: number = measure.staffEntries.length; idx < len; ++idx) {
                             let gse: GraphicalStaffEntry = measure.staffEntries[idx];
-                            if (gse.getAbsoluteTimestamp() === absoluteTimestamp) {
+                            if (gse.getAbsoluteTimestamp().Equals(absoluteTimestamp)) {
                                 graphicalStaffEntry = gse;
                                 break;
                             }
                         }
                         if (graphicalStaffEntry === undefined) {
-                            graphicalStaffEntry = this.createStaffEntryForTieNote(measure, absoluteTimestamp, openTie);
+                            graphicalStaffEntry = thisPointer.createStaffEntryForTieNote(measure, absoluteTimestamp, openTie);
                         }
                     }
                     if (graphicalStaffEntry !== undefined) {
                         let octaveShiftValue: OctaveEnum = OctaveEnum.NONE;
                         if (octaveShiftParams !== undefined) {
-                            if (graphicalStaffEntry.getAbsoluteTimestamp() >= octaveShiftParams.getAbsoluteStartTimestamp &&
-                                graphicalStaffEntry.getAbsoluteTimestamp() <= octaveShiftParams.getAbsoluteEndTimestamp) {
+                            if (octaveShiftParams.getAbsoluteStartTimestamp.lte(graphicalStaffEntry.getAbsoluteTimestamp()) &&
+                                graphicalStaffEntry.getAbsoluteTimestamp().lte(octaveShiftParams.getAbsoluteEndTimestamp)) {
                                 octaveShiftValue = octaveShiftParams.getOpenOctaveShift.Type;
                             }
                         }
                         let isLastTieNote: boolean = k === tieTimestamps.length - 1;
                         let tieFraction: Fraction = openTie.Fractions[k];
-                        let numberOfDots: number = openTie.Start.calculateNumberOfNeededDots();
-                        this.createGraphicalTieNote(
-                            beams, activeClef, octaveShiftValue, graphicalStaffEntry, tieFraction, numberOfDots, openTie, isLastTieNote
-                        );
+                        // GraphicalNote points to tieStartNote, but must get the correct Length (eg the correct Fraction of tieStartNote's Length)
+                        let tiedGraphicalNote: GraphicalNote = thisPointer.symbolFactory.createNote(   openTie.Start, graphicalStaffEntry, activeClef,
+                                                                                                octaveShiftValue, tieFraction);
+
+                        let graphicalNotes: GraphicalNote[] =
+                            graphicalStaffEntry.findOrCreateGraphicalNotesListFromGraphicalNote(tiedGraphicalNote);
+                        graphicalStaffEntry.addGraphicalNoteToListAtCorrectYPosition(graphicalNotes, tiedGraphicalNote);
+                        graphicalStaffEntry.PositionAndShape.ChildElements.push(tiedGraphicalNote.PositionAndShape);
+
+                        thisPointer.handleTiedGraphicalNote(   tiedGraphicalNote, beams, activeClef, octaveShiftValue, graphicalStaffEntry, tieFraction,
+                                                        openTie, isLastTieNote);
+
                         let tieStartNote: Note = openTie.Start;
                         if (isLastTieNote && tieStartNote.ParentVoiceEntry.Articulations.length === 1 &&
                             tieStartNote.ParentVoiceEntry.Articulations[0] === ArticulationEnum.fermata) {
-                            this.symbolFactory.addFermataAtTiedEndNote(tieStartNote, graphicalStaffEntry);
+                            thisPointer.symbolFactory.addFermataAtTiedEndNote(tieStartNote, graphicalStaffEntry);
                         }
                         openTie.NoteHasBeenCreated[k] = true;
                         if (openTie.allGraphicalNotesHaveBeenCreated()) {
@@ -904,6 +909,45 @@ export abstract class MusicSheetCalculator {
         }
     }
 
+    private handleTie(tie: Tie, startGraphicalStaffEntry: GraphicalStaffEntry, staffIndex: number, measureIndex: number): void {
+        let startGse: GraphicalStaffEntry = startGraphicalStaffEntry;
+        let endGse: GraphicalStaffEntry = undefined;
+        let startNote: GraphicalNote = undefined;
+        let endNote: GraphicalNote = undefined;
+        for (let i: number = 0; i < tie.Fractions.length; i++) {
+            let verticalGraphicalStaffEntryContainer: VerticalGraphicalStaffEntryContainer;
+            let endTimestamp: Fraction;
+            let startContainerIndex: number = startGraphicalStaffEntry.parentVerticalContainer.Index;
+            if (i === 0) {
+                endTimestamp = Fraction.plus(startGraphicalStaffEntry.getAbsoluteTimestamp(), tie.Start.calculateNoteLengthWithoutTie());
+            } else {
+                endTimestamp = Fraction.plus(startGse.getAbsoluteTimestamp(), tie.Fractions[i - 1]);
+            }
+            verticalGraphicalStaffEntryContainer = this.graphicalMusicSheet.GetVerticalContainerFromTimestamp(endTimestamp, startContainerIndex + 1);
+            if (verticalGraphicalStaffEntryContainer !== undefined) {
+                endGse = verticalGraphicalStaffEntryContainer.StaffEntries[staffIndex];
+                startNote = startGse.findEndTieGraphicalNoteFromNote(tie.Start);
+                if (endGse !== undefined) {
+                    endNote = endGse.findEndTieGraphicalNoteFromNote(tie.Start);
+                }
+            }
+            if (startNote !== undefined && endNote !== undefined && endGse !== undefined) {
+                let graphicalTie: GraphicalTie = this.createGraphicalTie(tie, startGse, endGse, startNote, endNote);
+                startGse.GraphicalTies.push(graphicalTie);
+                if (this.staffEntriesWithGraphicalTies.indexOf(startGse) >= 0) {
+                    this.staffEntriesWithGraphicalTies.push(startGse);
+                }
+            }
+            if (endGse !== undefined) {
+                if (endGse.parentMeasure !== startGse.parentMeasure) {
+                    measureIndex++;
+                }
+                startGse = endGse;
+                endGse = this.graphicalMusicSheet.findNextGraphicalStaffEntry(staffIndex, measureIndex, startGse);
+            }
+        }
+    }
+
     private createAccidentalCalculators(): AccidentalCalculator[] {
         let accidentalCalculators: AccidentalCalculator[] = [];
         let firstSourceMeasure: SourceMeasure = this.graphicalMusicSheet.ParentMusicSheet.getFirstSourceMeasure();
@@ -1094,12 +1138,10 @@ export abstract class MusicSheetCalculator {
             graphicalStaffEntry.relInMeasureTimestamp = new Fraction(0, 1);
             let graphicalNotes: GraphicalNote[] = [];
             graphicalStaffEntry.notes.push(graphicalNotes);
-            let numberOfDots: number = note.calculateNumberOfNeededDots();
             let graphicalNote: GraphicalNote = this.symbolFactory.createNote(   note,
-                                                                                numberOfDots,
                                                                                 graphicalStaffEntry,
-                                                                                new ClefInstruction(ClefEnum.G, 0, 2),
-                                                                                OctaveEnum.NONE);
+                                                                                new ClefInstruction(),
+                                                                                OctaveEnum.NONE, undefined);
             graphicalNotes.push(graphicalNote);
             graphicalStaffEntry.PositionAndShape.ChildElements.push(graphicalNote.PositionAndShape);
         }
@@ -1112,6 +1154,7 @@ export abstract class MusicSheetCalculator {
             this.symbolFactory.createGraphicalTechnicalInstruction(technicalInstruction, graphicalStaffEntry);
         }
     }
+
     private checkNoteForAccidental(graphicalNote: GraphicalNote, accidentalCalculator: AccidentalCalculator, activeClef: ClefInstruction,
                                    octaveEnum: OctaveEnum, grace: boolean = false): void {
         let pitch: Pitch = graphicalNote.sourceNote.Pitch;
@@ -1141,7 +1184,7 @@ export abstract class MusicSheetCalculator {
         graphicalStaffEntry = this.symbolFactory.createStaffEntry(openTie.Start.ParentStaffEntry, measure);
         graphicalStaffEntry.relInMeasureTimestamp = Fraction.minus(absoluteTimestamp, measure.parentSourceMeasure.AbsoluteTimestamp);
         this.resetYPositionForLeadSheet(graphicalStaffEntry.PositionAndShape);
-        measure.addGraphicalStaffEntry(graphicalStaffEntry);
+        measure.addGraphicalStaffEntryAtTimestamp(graphicalStaffEntry);
         return graphicalStaffEntry;
     }
 

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

@@ -90,7 +90,7 @@ export class VexFlowConverter {
     public static StaveNote(notes: GraphicalNote[]): Vex.Flow.StaveNote {
         let keys: string[] = [];
         let accidentals: string[] = [];
-        let frac: Fraction = notes[0].sourceNote.Length;
+        let frac: Fraction = notes[0].graphicalNoteLength;
         let duration: string = VexFlowConverter.duration(frac);
         let vfclef: string;
         for (let note of notes) {

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

@@ -5,10 +5,12 @@ import {GraphicalStaffEntry} from "../GraphicalStaffEntry";
 import {ClefInstruction} from "../../VoiceData/Instructions/ClefInstruction";
 import {VexFlowConverter} from "./VexFlowConverter";
 import {Pitch} from "../../../Common/DataObjects/Pitch";
+import {Fraction} from "../../../Common/DataObjects/Fraction";
+import {OctaveEnum} from "../../VoiceData/Expressions/ContinuousExpressions/OctaveShift";
 
 export class VexFlowGraphicalNote extends GraphicalNote {
-    constructor(note: Note, parent: GraphicalStaffEntry, activeClef: ClefInstruction) {
-        super(note, parent);
+    constructor(note: Note, parent: GraphicalStaffEntry, activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE,  graphicalNoteLength: Fraction = undefined) {
+        super(note, parent, graphicalNoteLength);
         this.clef = activeClef;
         if (note.Pitch) {
             this.vfpitch = VexFlowConverter.pitch(note.Pitch, this.clef);

+ 5 - 4
src/MusicalScore/Graphical/VexFlow/VexFlowGraphicalSymbolFactory.ts

@@ -18,6 +18,7 @@ import {GraphicalNote} from "../GraphicalNote";
 import {Pitch} from "../../../Common/DataObjects/Pitch";
 import {TechnicalInstruction} from "../../VoiceData/Instructions/TechnicalInstruction";
 import {VexFlowGraphicalNote} from "./VexFlowGraphicalNote";
+import {Fraction} from "../../../Common/DataObjects/Fraction";
 
 export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
     /**
@@ -91,10 +92,10 @@ export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
      * @param octaveShift   The currently active octave transposition enum, needed for positioning the note vertically
      * @returns {GraphicalNote}
      */
-    public createNote(note: Note, numberOfDots: number, graphicalStaffEntry: GraphicalStaffEntry,
-                      activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE): GraphicalNote {
+    public createNote(note: Note, graphicalStaffEntry: GraphicalStaffEntry,
+                      activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE,  graphicalNoteLength: Fraction = undefined): GraphicalNote {
         // Creates the note:
-        let graphicalNote: GraphicalNote = new VexFlowGraphicalNote(note, graphicalStaffEntry, activeClef);
+        let graphicalNote: GraphicalNote = new VexFlowGraphicalNote(note, graphicalStaffEntry, activeClef, octaveShift, graphicalNoteLength);
         // Adds the note to the right (graphical) voice (mynotes)
         let voiceID: number = note.ParentVoiceEntry.ParentVoice.VoiceId;
         let mynotes: { [id: number]: GraphicalNote[]; } = (graphicalStaffEntry as VexFlowStaffEntry).graphicalNotes;
@@ -114,7 +115,7 @@ export class VexFlowGraphicalSymbolFactory implements IGraphicalSymbolFactory {
      * @param octaveShift
      * @returns {GraphicalNote}
      */
-    public createGraceNote(note: Note, numberOfDots: number, graphicalStaffEntry: GraphicalStaffEntry,
+    public createGraceNote(note: Note, graphicalStaffEntry: GraphicalStaffEntry,
                            activeClef: ClefInstruction, octaveShift: OctaveEnum = OctaveEnum.NONE): GraphicalNote {
         return new GraphicalNote(note, graphicalStaffEntry);
     }

+ 9 - 7
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts

@@ -98,6 +98,12 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
         return width;
     }
 
+    protected createGraphicalTie(tie: Tie, startGse: GraphicalStaffEntry, endGse: GraphicalStaffEntry,
+                                 startNote: GraphicalNote, endNote: GraphicalNote): GraphicalTie {
+        return new GraphicalTie(tie, startNote, endNote);
+    }
+
+
     protected updateStaffLineBorders(staffLine: StaffLine): void {
         return;
     }
@@ -165,10 +171,6 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
         return;
     }
 
-    protected handleTie(tie: Tie, startGraphicalStaffEntry: GraphicalStaffEntry, staffIndex: number, measureIndex: number): void {
-        return;
-    }
-
     protected layoutGraphicalTie(tie: GraphicalTie, tieIsAtSystemBreak: boolean): void {
         return;
     }
@@ -189,9 +191,9 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
         return;
     }
 
-    protected createGraphicalTieNote(beams: Beam[], activeClef: ClefInstruction,
-                                     octaveShiftValue: OctaveEnum, graphicalStaffEntry: GraphicalStaffEntry, duration: Fraction, numberOfDots: number,
-                                     openTie: Tie, isLastTieNote: boolean): void {
+    protected handleTiedGraphicalNote(  tiedGraphicalNote: GraphicalNote, beams: Beam[], activeClef: ClefInstruction,
+                                        octaveShiftValue: OctaveEnum, graphicalStaffEntry: GraphicalStaffEntry, duration: Fraction,
+                                        openTie: Tie, isLastTieNote: boolean): void {
         return;
     }
 

+ 4 - 3
src/MusicalScore/Interfaces/IGraphicalSymbolFactory.ts

@@ -12,6 +12,7 @@ import {OctaveEnum} from "../VoiceData/Expressions/ContinuousExpressions/OctaveS
 import {GraphicalNote} from "../Graphical/GraphicalNote";
 import {Pitch} from "../../Common/DataObjects/Pitch";
 import {TechnicalInstruction} from "../VoiceData/Instructions/TechnicalInstruction";
+import {Fraction} from "../../Common/DataObjects/Fraction";
 export interface IGraphicalSymbolFactory {
     createMusicSystem(page: GraphicalMusicPage, systemIndex: number): MusicSystem;
     createStaffLine(parentSystem: MusicSystem, parentStaff: Staff): StaffLine;
@@ -19,9 +20,9 @@ export interface IGraphicalSymbolFactory {
     createExtraStaffMeasure(staffLine: StaffLine): StaffMeasure;
     createStaffEntry(sourceStaffEntry: SourceStaffEntry, measure: StaffMeasure): GraphicalStaffEntry;
     createGraceStaffEntry(staffEntryParent: GraphicalStaffEntry, measure: StaffMeasure): GraphicalStaffEntry;
-    createNote(note: Note, numberOfDots: number, graphicalStaffEntry: GraphicalStaffEntry, activeClef: ClefInstruction,
-        octaveShift: OctaveEnum): GraphicalNote;
-    createGraceNote(note: Note, numberOfDots: number, graphicalStaffEntry: GraphicalStaffEntry, activeClef: ClefInstruction,
+    createNote(note: Note, graphicalStaffEntry: GraphicalStaffEntry, activeClef: ClefInstruction,
+        octaveShift: OctaveEnum, graphicalNoteLength: Fraction): GraphicalNote;
+    createGraceNote(note: Note, graphicalStaffEntry: GraphicalStaffEntry, activeClef: ClefInstruction,
         octaveShift: OctaveEnum): GraphicalNote;
     addGraphicalAccidental(graphicalNote: GraphicalNote, pitch: Pitch, grace: boolean, graceScalingFactor: number): void;
     addFermataAtTiedEndNote(tiedNote: Note, graphicalStaffEntry: GraphicalStaffEntry): void;

+ 4 - 3
src/MusicalScore/ScoreIO/MusicSheetReader.ts

@@ -152,7 +152,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                 this.musicSheet.addMeasure(this.currentMeasure);
                 this.checkIfRhythmInstructionsAreSetAndEqual(instrumentReaders);
                 this.checkSourceMeasureForundefinedEntries();
-                this.setSourceMeasureDuration(instrumentReaders, sourceMeasureCounter);
+                sourceMeasureCounter = this.setSourceMeasureDuration(instrumentReaders, sourceMeasureCounter);
                 MusicSheetReader.doCalculationsAfterDurationHasBeenSet(instrumentReaders);
                 this.currentMeasure.AbsoluteTimestamp = this.currentFraction.clone();
                 this.musicSheet.SheetErrors.finalizeMeasure(this.currentMeasure.MeasureNumber);
@@ -308,7 +308,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         return false;
     }
 
-    private setSourceMeasureDuration(instrumentReaders: InstrumentReader[], sourceMeasureCounter: number): void {
+    private setSourceMeasureDuration(instrumentReaders: InstrumentReader[], sourceMeasureCounter: number): number {
         let activeRhythm: Fraction = new Fraction(0, 1);
         let instrumentsMaxTieNoteFractions: Fraction[] = [];
         for (let instrumentReader of instrumentReaders) {
@@ -357,6 +357,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                 }
             }
         }
+        return sourceMeasureCounter;
     }
 
     private checkFractionsForEquivalence(maxInstrumentDuration: Fraction, activeRhythm: Fraction): void {
@@ -367,7 +368,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
     }
 
     private checkIfMeasureIsImplicit(maxInstrumentDuration: Fraction, activeRhythm: Fraction): boolean {
-        if (this.previousMeasure === undefined && maxInstrumentDuration < activeRhythm) {
+        if (this.previousMeasure === undefined && maxInstrumentDuration.lt(activeRhythm)) {
             return true;
         }
         if (this.previousMeasure !== undefined) {

+ 9 - 15
src/MusicalScore/VoiceData/Note.ts

@@ -117,21 +117,6 @@ export class Note {
         }
         return originalLength;
     }
-    public calculateNoteLengthWithDots(): Fraction {
-        // FIXME is this function the same as this.calculateNoteLengthWithoutTie?
-        if (this.tie !== undefined) {
-            return this.calculateNoteLengthWithoutTie();
-        }
-        return this.length;
-    }
-    public calculateNumberOfNeededDots(fraction: Fraction = this.length): number {
-        // FIXME (Andrea) Test if correct
-        if (this.tuplet === undefined) {
-            return Math.floor(Math.log(fraction.Numerator) / Math.LN2);
-        } else {
-            return 0;
-        }
-    }
     public ToString(): string {
         if (this.pitch !== undefined) {
             return this.Pitch.ToString() + ", length: " + this.length.toString();
@@ -174,6 +159,15 @@ export class Note {
     //        return 64;
     //    }
     //}
+
+    private calculateNumberOfNeededDots(fraction: Fraction = this.length): number {
+        // FIXME (Andrea) Test if correct
+        if (this.tuplet === undefined) {
+            return Math.floor(Math.log(fraction.Numerator) / Math.LN2);
+        } else {
+            return 0;
+        }
+    }
 }
 
 export enum Appearance {

+ 2 - 2
src/Util/CollectionUtil.ts

@@ -23,10 +23,10 @@ export class CollectionUtil {
      * @param dict
      * @param iterationFunction
      */
-    public static removeDictElementIfTrue<T, V>(dict: Dictionary<T, V>, iterationFunction: (key: T, value: V) => boolean): void {
+    public static removeDictElementIfTrue<S, T, V>(thisPointer: S, dict: Dictionary<T, V>, iterationFunction: (thisPointer: S, key: T, value: V) => boolean): void {
         let toDeleteEntries: T[] = [];
         dict.forEach(function (key: T, value: V): void {
-            let shallDelete: boolean = iterationFunction(key, value);
+            let shallDelete: boolean = iterationFunction(thisPointer, key, value);
             if (shallDelete) {
                 toDeleteEntries.push(key);
             }