Selaa lähdekoodia

Linting pt. 1

Andrea Condoluci 9 vuotta sitten
vanhempi
commit
d5c828ffaa

+ 13 - 5
src/Common/DataObjects/fraction.ts

@@ -1,13 +1,15 @@
 // TODO: implement operators!
 "use strict";
 export class Fraction /*implements IComparable, IComparer<Fraction> */{
-   constructor(numerator: number = 0, denominator: number = 1, simplify: boolean = true) {
+   constructor(
+     numerator: number = 0,
+     denominator: number = 1,
+     simplify: boolean = true
+   ) {
        this.numerator = numerator;
        this.denominator = denominator;
 
-       if (simplify) {
-            this.simplify();
-       }
+       if (simplify) { this.simplify(); }
        this.setRealValue();
    }
 
@@ -16,11 +18,17 @@ export class Fraction /*implements IComparable, IComparer<Fraction> */{
     private denominator: number = 1;
     private realValue: number;
 
+    public static Equal(f1: Fraction, f2: Fraction): boolean {
+      // FIXME
+      return f1.Denominator() === f2.Denominator() &&
+      f1.Numerator() === f2.Numerator();
+    }
+
     public static CreateFractionFromFraction(fraction: Fraction): Fraction {
         return new Fraction(fraction.numerator, fraction.denominator);
     }
 
-    public static plus (f1: Fraction , f2: Fraction): Fraction {
+    public static plus (f1: Fraction, f2: Fraction): Fraction {
         let sum: Fraction = Fraction.CreateFractionFromFraction(f1);
         sum.Add(f2);
         return sum;

+ 85 - 75
src/MusicalScore/Instrument.ts

@@ -6,16 +6,22 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         this.idString = idString;
         this.nameLabel = new Label(idString);
     }
+
+    public Transpose: number = 0;
+    public Highlight: boolean;
+    public InstrumentParameterChanged: InstrumentParameterChangedDelegate;
+
     private phonicScoreInterface: IPhonicScoreInterface;
     private voices: List<Voice> = new List<Voice>();
     private staves: List<Staff> = new List<Staff>();
     private nameLabel: Label;
-    private range: ToneRange;
+    // private range: ToneRange;
     private idString: string;
     private id: number;
     private hasLyrics: boolean = false;
     private hasChordSymbols: boolean = false;
-    private playbackTranspose: number = 0;
+    // private playback
+
     private lyricVersesNumbers: List<number> = new List<number>();
     private subInstruments: List<SubInstrument> = new List<SubInstrument>();
     public get Voices(): List<Voice> {
@@ -70,8 +76,8 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         return this.subInstruments[0].Volume;
     }
     public set Volume(value: number) {
-        for (var idx: number = 0, len = this.subInstruments.Count; idx < len; ++idx) {
-            var subInstrument: SubInstrument = this.subInstruments[idx];
+        for (let idx: number = 0, len: number = this.subInstruments.Count; idx < len; ++idx) {
+            let subInstrument: SubInstrument = this.subInstruments[idx];
             subInstrument.Volume = value;
         }
     }
@@ -81,162 +87,166 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
     public set PlaybackTranspose(value: number) {
         this.playbackTranspose = value;
     }
-    public Highlight: boolean;
+
     public get SubInstruments(): List<SubInstrument> {
         return this.subInstruments;
     }
     public getSubInstrument(subInstrumentIdString: string): SubInstrument {
-        for (var idx: number = 0, len = this.subInstruments.Count; idx < len; ++idx) {
-            var subInstrument: SubInstrument = this.subInstruments[idx];
-            if (subInstrument.IdString == subInstrumentIdString) {
+        for (let idx: number = 0, len: number = this.subInstruments.Count; idx < len; ++idx) {
+            let subInstrument: SubInstrument = this.subInstruments[idx];
+            if (subInstrument.IdString === subInstrumentIdString) {
                 return subInstrument;
             }
         }
-        return null;
+        return undefined;
     }
     public get Visible(): boolean {
-        if (this.voices.Count > 0)
+        if (this.voices.Count > 0) {
             return this.Voices[0].Visible;
-        else return false;
+        } else {
+            return false;
+        }
     }
     public set Visible(value: boolean) {
-        for (var idx: number = 0, len = this.Voices.Count; idx < len; ++idx) {
-            var v: Voice = this.Voices[idx];
+        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+            let v: Voice = this.Voices[idx];
             v.Visible = value;
         }
     }
     public get Audible(): boolean {
-        var result: boolean = false;
-        for (var idx: number = 0, len = this.Voices.Count; idx < len; ++idx) {
-            var v: Voice = this.Voices[idx];
+        let result: boolean = false;
+        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+            let v: Voice = this.Voices[idx];
             result = result || v.Audible;
         }
         return result;
     }
     public set Audible(value: boolean) {
-        for (var idx: number = 0, len = this.Voices.Count; idx < len; ++idx) {
-            var v: Voice = this.Voices[idx];
+        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+            let v: Voice = this.Voices[idx];
             v.Audible = value;
         }
-        for (var idx: number = 0, len = this.staves.Count; idx < len; ++idx) {
-            var staff: Staff = this.staves[idx];
+        for (let idx: number = 0, len: number = this.staves.Count; idx < len; ++idx) {
+            let staff: Staff = this.staves[idx];
             staff.Audible = value;
         }
     }
     public get Following(): boolean {
-        var result: boolean = false;
-        for (var idx: number = 0, len = this.Voices.Count; idx < len; ++idx) {
-            var v: Voice = this.Voices[idx];
+        let result: boolean = false;
+        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+            let v: Voice = this.Voices[idx];
             result = result || v.Following;
         }
         return result;
     }
     public set Following(value: boolean) {
-        for (var idx: number = 0, len = this.Voices.Count; idx < len; ++idx) {
-            var v: Voice = this.Voices[idx];
+        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+            let v: Voice = this.Voices[idx];
             v.Following = value;
         }
-        for (var idx: number = 0, len = this.staves.Count; idx < len; ++idx) {
-            var staff: Staff = this.staves[idx];
+        for (let idx: number = 0, len: number = this.staves.Count; idx < len; ++idx) {
+            let staff: Staff = this.staves[idx];
             staff.Following = value;
         }
     }
     public SetVoiceAudible(voiceId: number, audible: boolean): void {
-        for (var idx: number = 0, len = this.Voices.Count; idx < len; ++idx) {
-            var v: Voice = this.Voices[idx];
-            if (v.VoiceId == voiceId) {
+        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+            let v: Voice = this.Voices[idx];
+            if (v.VoiceId === voiceId) {
                 v.Audible = audible;
                 break;
             }
         }
     }
     public SetVoiceFollowing(voiceId: number, following: boolean): void {
-        for (var idx: number = 0, len = this.Voices.Count; idx < len; ++idx) {
-            var v: Voice = this.Voices[idx];
-            if (v.VoiceId == voiceId) {
+        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+            let v: Voice = this.Voices[idx];
+            if (v.VoiceId === voiceId) {
                 v.Following = following;
                 break;
             }
         }
     }
     public SetStaffAudible(staffId: number, audible: boolean): void {
-        var staff: Staff = this.staves[staffId - 1];
+        let staff: Staff = this.staves[staffId - 1];
         staff.Audible = audible;
         if (audible) {
-            for (var idx: number = 0, len = staff.Voices.Count; idx < len; ++idx) {
-                var v: Voice = staff.Voices[idx];
+            for (let idx: number = 0, len: number = staff.Voices.Count; idx < len; ++idx) {
+                let v: Voice = staff.Voices[idx];
                 v.Audible = true;
             }
-        }
-        else {
-            for (var idx: number = 0, len = staff.Voices.Count; idx < len; ++idx) {
-                var voice: Voice = staff.Voices[idx];
-                var isAudibleInOtherStaves: boolean = false;
-                for (var idx2: number = 0, len2 = this.Staves.Count; idx2 < len2; ++idx2) {
-                    var st: Staff = this.Staves[idx2];
-                    if (st.Id == staffId || !st.Audible)
-                        continue;
-                    for (var idx3: number = 0, len3 = st.Voices.Count; idx3 < len3; ++idx3) {
-                        var v: Voice = st.Voices[idx3];
-                        if (v == voice)
+        } else {
+            for (let idx: number = 0, len: number = staff.Voices.Count; idx < len; ++idx) {
+                let voice: Voice = staff.Voices[idx];
+                let isAudibleInOtherStaves: boolean = false;
+                for (let idx2: number = 0, len2: number = this.Staves.Count; idx2 < len2; ++idx2) {
+                    let st: Staff = this.Staves[idx2];
+                    if (st.Id === staffId || !st.Audible) { continue; }
+                    for (let idx3: number = 0, len3: number = st.Voices.Count; idx3 < len3; ++idx3) {
+                        let v: Voice = st.Voices[idx3];
+                        if (v === voice) {
                             isAudibleInOtherStaves = true;
+                        }
                     }
                 }
-                if (!isAudibleInOtherStaves)
+                if (!isAudibleInOtherStaves) {
                     voice.Audible = false;
+                }
             }
         }
     }
     public SetStaffFollow(staffId: number, follow: boolean): void {
-        var staff: Staff = this.staves[staffId - 1];
+        let staff: Staff = this.staves[staffId - 1];
         staff.Following = follow;
         if (follow) {
-            for (var idx: number = 0, len = staff.Voices.Count; idx < len; ++idx) {
-                var v: Voice = staff.Voices[idx];
+            for (let idx: number = 0, len: number = staff.Voices.Count; idx < len; ++idx) {
+                let v: Voice = staff.Voices[idx];
                 v.Following = true;
             }
-        }
-        else {
-            for (var idx: number = 0, len = staff.Voices.Count; idx < len; ++idx) {
-                var voice: Voice = staff.Voices[idx];
-                var isFollowingInOtherStaves: boolean = false;
-                for (var idx2: number = 0, len2 = this.Staves.Count; idx2 < len2; ++idx2) {
-                    var st: Staff = this.Staves[idx2];
-                    if (st.Id == staffId || !st.Following)
-                        continue;
-                    for (var idx3: number = 0, len3 = st.Voices.Count; idx3 < len3; ++idx3) {
-                        var v: Voice = st.Voices[idx3];
-                        if (v == voice)
+        } else {
+            for (let idx: number = 0, len: number = staff.Voices.Count; idx < len; ++idx) {
+                let voice: Voice = staff.Voices[idx];
+                let isFollowingInOtherStaves: boolean = false;
+                for (let idx2: number = 0, len2: number = this.Staves.Count; idx2 < len2; ++idx2) {
+                    let st: Staff = this.Staves[idx2];
+                    if (st.Id === staffId || !st.Following) { continue; }
+                    for (let idx3: number = 0, len3: number = st.Voices.Count; idx3 < len3; ++idx3) {
+                        let v: Voice = st.Voices[idx3];
+                        if (v === voice) {
                             isFollowingInOtherStaves = true;
+                        }
                     }
                 }
-                if (!isFollowingInOtherStaves)
+                if (!isFollowingInOtherStaves) {
                     voice.Following = false;
+                }
             }
         }
     }
     public areAllVoiceVisible(): boolean {
-        var counter: number = 0;
-        for (var idx: number = 0, len = this.Voices.Count; idx < len; ++idx) {
-            var voice: Voice = this.Voices[idx];
-            if (voice.Visible)
+        let counter: number = 0;
+        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+            let voice: Voice = this.Voices[idx];
+            if (voice.Visible) {
                 counter++;
+            }
         }
-        if (counter == this.voices.Count)
+        if (counter === this.voices.Count) {
             return true;
+        }
         return false;
     }
     public createStaves(numberOfStaves: number): void {
-        for (var i: number = 0; i < numberOfStaves; i++) {
-            var staff: Staff = new Staff(this, i + 1);
+        for (let i: number = 0; i < numberOfStaves; i++) {
+            let staff: Staff = new Staff(this, i + 1);
             this.staves.Add(staff);
         }
     }
     public SetInstrumentParameter(parameter: InstrumentParameters, value: Object): void {
         this.phonicScoreInterface.RequestInstrumentParameter(this.Id, parameter, value);
     }
-    public InstrumentParameterChanged: InstrumentParameterChangedDelegate;
+
     public Dispose(): void {
-        this.InstrumentParameterChanged = null;
+        this.InstrumentParameterChanged = undefined;
     }
-}
+}

+ 2 - 2
src/MusicalScore/InstrumentalGroup.ts

@@ -12,7 +12,7 @@ export class InstrumentalGroup {
     private musicSheet: MusicSheet;
     private parent: InstrumentalGroup;
     private instrumentalGroups: List<InstrumentalGroup> = new List<InstrumentalGroup>();
-    private instruments: List<Instrument> = new List<Instrument>();
+    //private instruments: List<Instrument> = new List<Instrument>();
     public get InstrumentalGroups(): List<InstrumentalGroup> {
         return this.instrumentalGroups;
     }
@@ -28,4 +28,4 @@ export class InstrumentalGroup {
     public get GetMusicSheet(): MusicSheet {
         return this.musicSheet;
     }
-}
+}

+ 1 - 1
src/MusicalScore/Interfaces/IQualityFeedbackTone.ts

@@ -3,4 +3,4 @@ export interface IQualityFeedbackTone {
     TimingScore: number;
     PitchScore: number;
     getOverallQualityFeedbackScore(): number;
-}
+}

+ 14 - 16
src/MusicalScore/Label.ts

@@ -1,26 +1,24 @@
 export class Label {
-    constructor() {
+  constructor(arg1: any, alignment: PSTextAlignment) {
+      if (arg1 instanceof string) {
+          this.text = <string>arg1;
+      } else if (arg1 instanceof FontInfo.MusicFontSymbol) {
+          this.font = PSFonts.PhonicScore;
+          let symbolInfo: FontInfo.SymbolInfo = FontInfo.Info.getSymbolInfo(<FontInfo.MusicFontSymbol>arg1);
+          this.text = symbolInfo.symbol;
+      }
+      if (alignment !== undefined) {
+          this.textAlignment = alignment;
+      }
+  }
 
-    }
-    constructor(text: string) {
-        this.text = text;
-    }
-    constructor(text: string, alignment: PSTextAlignment) {
-        this.text = text;
-        this.textAlignment = alignment;
-    }
-    constructor(symbol: FontInfo.MusicFontSymbol, alignment: PSTextAlignment) {
-        this.font = PSFonts.PhonicScore;
-        var symbolInfo: FontInfo.SymbolInfo = FontInfo.Info.getSymbolInfo(symbol);
-        this.text = symbolInfo.symbol;
-        this.textAlignment = alignment;
-    }
     private text: string;
     private color: PSColor = PSColor.Black;
     private font: PSFonts = PSFonts.TimesNewRoman;
     private fontStyle: PSFontStyles = PSFontStyles.Regular;
     private textAlignment: PSTextAlignment = PSTextAlignment.LeftBottom;
     private fontHeight: number = 2;
+
     public get Text(): string {
         return this.text;
     }
@@ -60,4 +58,4 @@ export class Label {
     public ToString(): string {
         return this.Text;
     }
-}
+}

+ 54 - 47
src/MusicalScore/MusicParts/MusicPartManager.ts

@@ -1,7 +1,4 @@
 export class MusicPartManager implements ISelectionListener {
-    constructor() {
-
-    }
     constructor(musicSheet: MusicSheet) {
         this.musicSheet = musicSheet;
     }
@@ -19,49 +16,21 @@ export class MusicPartManager implements ISelectionListener {
         this.sheetEnd = this.musicSheet.SelectionEnd = this.musicSheet.SheetEndTimestamp;
         this.calcMapping();
     }
-    private calcMapping(): void {
-        this.timestamps = new List<TimestampTransform>();
-        var iterator: MusicPartManagerIterator = this.getIterator();
-        var currentRepetition: Repetition = iterator.CurrentRepetition;
-        var curTimestampTransform: TimestampTransform = new TimestampTransform(new Fraction(iterator.CurrentEnrolledTimestamp),
-            new Fraction(iterator.CurrentSourceTimestamp), null, 0);
-        this.timestamps.Add(curTimestampTransform);
-        while (!iterator.EndReached) {
-            if (iterator.JumpOccurred || currentRepetition != iterator.CurrentRepetition) {
-                currentRepetition = iterator.CurrentRepetition;
-                if (iterator.BackJumpOccurred) {
-                    var jumpRep: Repetition = iterator.JumpResponsibleRepetition;
-                    curTimestampTransform.nextBackJump = iterator.CurrentEnrolledTimestamp;
-                    curTimestampTransform.curRepetition = jumpRep;
-                    curTimestampTransform.curRepetitionIteration = iterator.CurrentJumpResponsibleRepetitionIterationBeforeJump;
-                    for (var i: number = this.timestamps.Count - 2; i >= 0; i--) {
-                        if (jumpRep.AbsoluteTimestamp > this.timestamps[i].to || this.timestamps[i].curRepetition != null)
-                            break;
-                        this.timestamps[i].nextBackJump = curTimestampTransform.nextBackJump;
-                        this.timestamps[i].curRepetition = jumpRep;
-                        this.timestamps[i].curRepetitionIteration = curTimestampTransform.curRepetitionIteration;
-                    }
-                }
-                curTimestampTransform = new TimestampTransform(new Fraction(iterator.CurrentEnrolledTimestamp),
-                    new Fraction(iterator.CurrentSourceTimestamp), null, 0);
-                this.timestamps.Add(curTimestampTransform);
-            }
-            iterator.moveToNext();
-        }
-    }
     public getCurrentRepetitionTimestampTransform(curEnrolledTimestamp: Fraction): TimestampTransform {
-        var curTransform: TimestampTransform = null;
-        for (var i: number = this.timestamps.Count - 1; i >= 0; i--) {
+        let curTransform: TimestampTransform = undefined;
+        for (let i: number = this.timestamps.Count - 1; i >= 0; i--) {
             curTransform = this.timestamps[i];
-            if (curEnrolledTimestamp >= curTransform.$from)
+            if (curEnrolledTimestamp >= curTransform.$from) {
                 return curTransform;
+            }
         }
         return this.timestamps[0];
     }
     public absoluteEnrolledToSheetTimestamp(timestamp: Fraction): Fraction {
-        if (this.timestamps.Count == 0)
+        if (this.timestamps.Count === 0) {
             return timestamp;
-        var transform: TimestampTransform = this.getCurrentRepetitionTimestampTransform(timestamp);
+        }
+        let transform: TimestampTransform = this.getCurrentRepetitionTimestampTransform(timestamp);
         return timestamp + (transform.to - transform.$from);
     }
     public get Parts(): List<PartListEntry> {
@@ -74,26 +43,64 @@ export class MusicPartManager implements ISelectionListener {
         return new MusicPartManagerIterator(this, this.musicSheet.SelectionStart, this.musicSheet.SelectionEnd);
     }
     public getIterator(start: Fraction): MusicPartManagerIterator {
-        return new MusicPartManagerIterator(this, start, null);
+        return new MusicPartManagerIterator(this, start, undefined);
     }
     public setSelectionStart(beginning: Fraction): void {
         this.musicSheet.SelectionStart = beginning;
-        this.musicSheet.SelectionEnd = null;
+        this.musicSheet.SelectionEnd = undefined;
     }
     public setSelectionRange(start: Fraction, end: Fraction): void {
-        this.musicSheet.SelectionStart = start == null ? this.sheetStart : start;
-        this.musicSheet.SelectionEnd = end == null ? this.sheetEnd : end;
+        this.musicSheet.SelectionStart = start === undefined ? this.sheetStart : start;
+        this.musicSheet.SelectionEnd = end === undefined ? this.sheetEnd : end;
     }
-}
-export module MusicPartManager {
+    private calcMapping(): void {
+        this.timestamps = new List<TimestampTransform>();
+        let iterator: MusicPartManagerIterator = this.getIterator();
+        let currentRepetition: Repetition = iterator.CurrentRepetition;
+        let curTimestampTransform: TimestampTransform = new TimestampTransform(
+            new Fraction(iterator.CurrentEnrolledTimestamp),
+            new Fraction(iterator.CurrentSourceTimestamp),
+            undefined,
+            0,
+        );
+        this.timestamps.Add(curTimestampTransform);
+        while (!iterator.EndReached) {
+            if (iterator.JumpOccurred || currentRepetition !== iterator.CurrentRepetition) {
+                currentRepetition = iterator.CurrentRepetition;
+                if (iterator.BackJumpOccurred) {
+                    let jumpRep: Repetition = iterator.JumpResponsibleRepetition;
+                    curTimestampTransform.nextBackJump = iterator.CurrentEnrolledTimestamp;
+                    curTimestampTransform.curRepetition = jumpRep;
+                    curTimestampTransform.curRepetitionIteration = iterator.CurrentJumpResponsibleRepetitionIterationBeforeJump;
+                    for (let i: number = this.timestamps.Count - 2; i >= 0; i--) {
+                        if (jumpRep.AbsoluteTimestamp > this.timestamps[i].to || this.timestamps[i].curRepetition !== undefined) {
+                            break;
+                        }
+                        this.timestamps[i].nextBackJump = curTimestampTransform.nextBackJump;
+                        this.timestamps[i].curRepetition = jumpRep;
+                        this.timestamps[i].curRepetitionIteration = curTimestampTransform.curRepetitionIteration;
+                    }
+                }
+                curTimestampTransform = new TimestampTransform(
+                    new Fraction(iterator.CurrentEnrolledTimestamp),
+                    new Fraction(iterator.CurrentSourceTimestamp),
+                    undefined,
+                    0,
+                );
+                this.timestamps.Add(curTimestampTransform);
+            }
+            iterator.moveToNext();
+        }
+    }
+
     export class TimestampTransform {
         constructor(sourceTimestamp: Fraction, enrolledTimestamp: Fraction, repetition: Repetition, curRepetitionIteration: number) {
             this.$from = sourceTimestamp;
             this.to = enrolledTimestamp;
             this.curRepetition = repetition;
             this.curRepetitionIteration = curRepetitionIteration;
-            this.nextBackJump = null;
-            this.nextForwardJump = null;
+            this.nextBackJump = undefined;
+            this.nextForwardJump = undefined;
         }
         public $from: Fraction;
         public to: Fraction;
@@ -102,4 +109,4 @@ export module MusicPartManager {
         public curRepetition: Repetition;
         public curRepetitionIteration: number;
     }
-}
+}

+ 201 - 150
src/MusicalScore/MusicParts/MusicPartManagerIterator.ts

@@ -1,48 +1,44 @@
 export class MusicPartManagerIterator {
     constructor(manager: MusicPartManager) {
-        this(manager, null);
+        this(manager, undefined);
 
     }
     constructor(manager: MusicPartManager, startTimestamp: Fraction) {
-        this(manager, startTimestamp, null);
+        this(manager, startTimestamp, undefined);
 
     }
     constructor(manager: MusicPartManager, startTimestamp: Fraction, endTimestamp: Fraction) {
         try {
             this.frontReached = true;
             this.manager = manager;
-            this.currentVoiceEntries = null;
+            this.currentVoiceEntries = undefined;
             this.frontReached = false;
-            for (var idx: number = 0, len = manager.MusicSheet.Repetitions.Count; idx < len; ++idx) {
-                var rep: Repetition = manager.MusicSheet.Repetitions[idx];
+            for (let idx: number = 0, len: number = manager.MusicSheet.Repetitions.Count; idx < len; ++idx) {
+                let rep: Repetition = manager.MusicSheet.Repetitions[idx];
                 this.repetitionIterationCountDict.Add(rep, 1);
             }
-            for (var i: number = 0; i < manager.MusicSheet.getCompleteNumberOfStaves(); i++) {
-                this.activeDynamicExpressions.Add(null);
+            for (let i: number = 0; i < manager.MusicSheet.getCompleteNumberOfStaves(); i++) {
+                this.activeDynamicExpressions.Add(undefined);
             }
             this.currentMeasure = this.manager.MusicSheet.SourceMeasures[0];
-            if (startTimestamp == null)
-                return
+            if (startTimestamp === undefined) { return; }
             do {
                 this.moveToNext();
-            }
-            while ((this.currentVoiceEntries == null || this.currentTimeStamp < startTimestamp) && !this.endReached);
-            for (var staffIndex: number = 0; staffIndex < this.activeDynamicExpressions.Count; staffIndex++) {
-                if (this.activeDynamicExpressions[staffIndex] != null) {
+            } while ((this.currentVoiceEntries === undefined || this.currentTimeStamp < startTimestamp) && !this.endReached);
+            for (let staffIndex: number = 0; staffIndex < this.activeDynamicExpressions.Count; staffIndex++) {
+                if (this.activeDynamicExpressions[staffIndex] !== undefined) {
                     if (this.activeDynamicExpressions[staffIndex] instanceof ContinuousDynamicExpression) {
-                        var continuousDynamic: ContinuousDynamicExpression = <ContinuousDynamicExpression>this.activeDynamicExpressions[staffIndex];
+                        let continuousDynamic: ContinuousDynamicExpression = <ContinuousDynamicExpression>this.activeDynamicExpressions[staffIndex];
                         this.currentDynamicChangingExpressions.Add(new DynamicsContainer(continuousDynamic, staffIndex));
-                    }
-                    else {
-                        var instantaniousDynamic: InstantaniousDynamicExpression = <InstantaniousDynamicExpression>this.activeDynamicExpressions[staffIndex];
+                    } else {
+                        let instantaniousDynamic: InstantaniousDynamicExpression = <InstantaniousDynamicExpression>this.activeDynamicExpressions[staffIndex];
                         this.currentDynamicChangingExpressions.Add(new DynamicsContainer(instantaniousDynamic, staffIndex));
                     }
                 }
             }
             this.currentTempoChangingExpression = this.activeTempoExpression;
-        }
-        catch (err) {
-
+        } catch (err) {
+            console.log("MusicPartManagerIterator: Exception."); // FIXME
         }
 
     }
@@ -60,13 +56,13 @@ export class MusicPartManagerIterator {
     private currentDynamicChangingExpressions: List<DynamicsContainer> = new List<DynamicsContainer>();
     private currentTempoChangingExpression: MultiTempoExpression;
     private repetitionIterationCountDict: Dictionary<Repetition, number> = new Dictionary<Repetition, number>();
-    private currentRepetition: Repetition = null;
+    private currentRepetition: Repetition = undefined;
     private endReached: boolean = false;
     private frontReached: boolean = false;
     private currentTimeStamp: Fraction = new Fraction(new Fraction(0, 1));
     private currentEnrolledMeasureTimestamp: Fraction = new Fraction(new Fraction(0, 1));
     private currentVerticalContainerInMeasureTimestamp: Fraction = new Fraction(new Fraction(0, 1));
-    private jumpResponsibleRepetition: Repetition = null;
+    private jumpResponsibleRepetition: Repetition = undefined;
     private activeDynamicExpressions: List<AbstractExpression> = new List<AbstractExpression>();
     private activeTempoExpression: MultiTempoExpression;
     public get EndReached(): boolean {
@@ -82,13 +78,15 @@ export class MusicPartManagerIterator {
         return this.currentRepetition;
     }
     public get CurrentRepetitionIteration(): number {
-        if (this.CurrentRepetition != null)
+        if (this.CurrentRepetition !== undefined) {
             return this.repetitionIterationCountDict[this.CurrentRepetition];
+        }
         return 0;
     }
     public get CurrentJumpResponsibleRepetitionIterationBeforeJump(): number {
-        if (this.jumpResponsibleRepetition != null)
+        if (this.jumpResponsibleRepetition !== undefined) {
             return this.repetitionIterationCountDict[this.jumpResponsibleRepetition] - 1;
+        }
         return 0;
     }
     public get CurrentVoiceEntries(): List<VoiceEntry> {
@@ -119,7 +117,7 @@ export class MusicPartManagerIterator {
         return this.jumpResponsibleRepetition;
     }
     public clone(): MusicPartManagerIterator {
-        var ret: MusicPartManagerIterator = new MusicPartManagerIterator(this.manager);
+        let ret: MusicPartManagerIterator = new MusicPartManagerIterator(this.manager);
         ret.currentVoiceEntryIndex = this.currentVoiceEntryIndex;
         ret.currentMappingPart = this.currentMappingPart;
         ret.currentPartIndex = this.currentPartIndex;
@@ -129,12 +127,13 @@ export class MusicPartManagerIterator {
         return ret;
     }
     public CurrentVisibleVoiceEntries(instrument: Instrument): List<VoiceEntry> {
-        var ret: List<VoiceEntry> = new List<VoiceEntry>();
-        if (this.currentVoiceEntries == null)
+        let ret: List<VoiceEntry> = new List<VoiceEntry>();
+        if (this.currentVoiceEntries === undefined) {
             return ret;
-        for (var idx: number = 0, len = this.currentVoiceEntries.Count; idx < len; ++idx) {
-            var entry: VoiceEntry = this.currentVoiceEntries[idx];
-            if (entry.ParentVoice.Parent.IdString == instrument.IdString) {
+        }
+        for (let idx: number = 0, len: number = this.currentVoiceEntries.Count; idx < len; ++idx) {
+            let entry: VoiceEntry = this.currentVoiceEntries[idx];
+            if (entry.ParentVoice.Parent.IdString === instrument.IdString) {
                 this.getVisibleEntries(entry, ret);
                 return ret;
             }
@@ -142,22 +141,23 @@ export class MusicPartManagerIterator {
         return ret;
     }
     public CurrentVisibleVoiceEntries(): List<VoiceEntry> {
-        var voiceEntries: List<VoiceEntry> = new List<VoiceEntry>();
-        if (this.currentVoiceEntries != null) {
-            for (var idx: number = 0, len = this.currentVoiceEntries.Count; idx < len; ++idx) {
-                var entry: VoiceEntry = this.currentVoiceEntries[idx];
+        let voiceEntries: List<VoiceEntry> = new List<VoiceEntry>();
+        if (this.currentVoiceEntries !== undefined) {
+            for (let idx: number = 0, len: number = this.currentVoiceEntries.Count; idx < len; ++idx) {
+                let entry: VoiceEntry = this.currentVoiceEntries[idx];
                 this.getVisibleEntries(entry, voiceEntries);
             }
         }
         return voiceEntries;
     }
     public CurrentAudibleVoiceEntries(instrument: Instrument): List<VoiceEntry> {
-        var ret: List<VoiceEntry> = new List<VoiceEntry>();
-        if (this.currentVoiceEntries == null)
+        let ret: List<VoiceEntry> = new List<VoiceEntry>();
+        if (this.currentVoiceEntries === undefined) {
             return ret;
-        for (var idx: number = 0, len = this.currentVoiceEntries.Count; idx < len; ++idx) {
-            var entry: VoiceEntry = this.currentVoiceEntries[idx];
-            if (entry.ParentVoice.Parent.IdString == instrument.IdString) {
+        }
+        for (let idx: number = 0, len: number = this.currentVoiceEntries.Count; idx < len; ++idx) {
+            let entry: VoiceEntry = this.currentVoiceEntries[idx];
+            if (entry.ParentVoice.Parent.IdString === instrument.IdString) {
                 this.getAudibleEntries(entry, ret);
                 return ret;
             }
@@ -165,10 +165,10 @@ export class MusicPartManagerIterator {
         return ret;
     }
     public CurrentAudibleVoiceEntries(): List<VoiceEntry> {
-        var voiceEntries: List<VoiceEntry> = new List<VoiceEntry>();
-        if (this.currentVoiceEntries != null) {
-            for (var idx: number = 0, len = this.currentVoiceEntries.Count; idx < len; ++idx) {
-                var entry: VoiceEntry = this.currentVoiceEntries[idx];
+        let voiceEntries: List<VoiceEntry> = new List<VoiceEntry>();
+        if (this.currentVoiceEntries !== undefined) {
+            for (let idx: number = 0, len: number = this.currentVoiceEntries.Count; idx < len; ++idx) {
+                let entry: VoiceEntry = this.currentVoiceEntries[idx];
                 this.getAudibleEntries(entry, voiceEntries);
             }
         }
@@ -178,12 +178,13 @@ export class MusicPartManagerIterator {
         return this.currentDynamicChangingExpressions;
     }
     public CurrentScoreFollowingVoiceEntries(instrument: Instrument): List<VoiceEntry> {
-        var ret: List<VoiceEntry> = new List<VoiceEntry>();
-        if (this.currentVoiceEntries == null)
+        let ret: List<VoiceEntry> = new List<VoiceEntry>();
+        if (this.currentVoiceEntries === undefined) {
             return ret;
-        for (var idx: number = 0, len = this.currentVoiceEntries.Count; idx < len; ++idx) {
-            var entry: VoiceEntry = this.currentVoiceEntries[idx];
-            if (entry.ParentVoice.Parent.IdString == instrument.IdString) {
+        }
+        for (let idx: number = 0, len: number = this.currentVoiceEntries.Count; idx < len; ++idx) {
+            let entry: VoiceEntry = this.currentVoiceEntries[idx];
+            if (entry.ParentVoice.Parent.IdString === instrument.IdString) {
                 this.getScoreFollowingEntries(entry, ret);
                 return ret;
             }
@@ -191,10 +192,10 @@ export class MusicPartManagerIterator {
         return ret;
     }
     public CurrentScoreFollowingVoiceEntries(): List<VoiceEntry> {
-        var voiceEntries: List<VoiceEntry> = new List<VoiceEntry>();
-        if (this.currentVoiceEntries != null) {
-            for (var idx: number = 0, len = this.currentVoiceEntries.Count; idx < len; ++idx) {
-                var entry: VoiceEntry = this.currentVoiceEntries[idx];
+        let voiceEntries: List<VoiceEntry> = new List<VoiceEntry>();
+        if (this.currentVoiceEntries !== undefined) {
+            for (let idx: number = 0, len: number = this.currentVoiceEntries.Count; idx < len; ++idx) {
+                let entry: VoiceEntry = this.currentVoiceEntries[idx];
                 this.getScoreFollowingEntries(entry, voiceEntries);
             }
         }
@@ -205,20 +206,19 @@ export class MusicPartManagerIterator {
     }
     public moveToNext(): void {
         this.ForwardJumpOccurred = this.BackJumpOccurred = false;
-        if (this.endReached)
-            return
-        if (this.currentVoiceEntries != null)
+        if (this.endReached) { return; }
+        if (this.currentVoiceEntries !== undefined) {
             this.currentVoiceEntries.Clear();
+        }
         this.recursiveMove();
-        if (this.currentMeasure == null) {
+        if (this.currentMeasure === undefined) {
             this.currentTimeStamp = new Fraction(99999, 1);
         }
     }
     public moveToNextVisibleVoiceEntry(notesOnly: boolean): void {
         while (!this.endReached) {
             this.moveToNext();
-            if (this.checkEntries(notesOnly))
-                return
+            if (this.checkEntries(notesOnly)) { return; }
         }
     }
     private resetRepetitionIterationCount(repetition: Repetition): number {
@@ -227,24 +227,23 @@ export class MusicPartManagerIterator {
     }
     private incrementRepetitionIterationCount(repetition: Repetition): number {
         if (this.repetitionIterationCountDict.ContainsKey(repetition)) {
-            var newIteration: number = this.repetitionIterationCountDict[repetition] + 1;
+            let newIteration: number = this.repetitionIterationCountDict[repetition] + 1;
             this.repetitionIterationCountDict[repetition] = newIteration;
             return newIteration;
-        }
-        else {
+        } else {
             this.repetitionIterationCountDict.Add(repetition, 1);
             return 1;
         }
     }
     private setRepetitionIterationCount(repetition: Repetition, iterationCount: number): void {
-        if (this.repetitionIterationCountDict.ContainsKey(repetition))
+        if (this.repetitionIterationCountDict.ContainsKey(repetition)) {
             this.repetitionIterationCountDict[repetition] = iterationCount;
-        else {
+        } else {
             this.repetitionIterationCountDict.Add(repetition, iterationCount);
         }
     }
-    private moveTempoIndexToTimestamp(measureNumber: number): void {
-        for (var index: number = 0; index < this.manager.MusicSheet.TimestampSortedTempoExpressionsList.Count; index++) {
+/*    private moveTempoIndexToTimestamp(measureNumber: number): void {
+        for (let index: number = 0; index < this.manager.MusicSheet.TimestampSortedTempoExpressionsList.Count; index++) {
             if (this.manager.MusicSheet.TimestampSortedTempoExpressionsList[index].SourceMeasureParent.MeasureNumber >= measureNumber) {
                 this.currentTempoEntryIndex = Math.Max(-1, index - 1);
                 return
@@ -255,25 +254,25 @@ export class MusicPartManagerIterator {
         if (this.currentTempoEntryIndex >= this.manager.MusicSheet.TimestampSortedTempoExpressionsList.Count - 1) {
             return new Fraction(99999, 1);
         }
-        return this.manager.MusicSheet.TimestampSortedTempoExpressionsList[this.currentTempoEntryIndex + 1].SourceMeasureParent.AbsoluteTimestamp + this.manager.MusicSheet.TimestampSortedTempoExpressionsList[this.currentTempoEntryIndex + 1].Timestamp;
+        return this.manager.MusicSheet.TimestampSortedTempoExpressionsList[this.currentTempoEntryIndex + 1].SourceMeasureParent.AbsoluteTimestamp +
+        this.manager.MusicSheet.TimestampSortedTempoExpressionsList[this.currentTempoEntryIndex + 1].Timestamp;
     }
     private moveToNextDynamic(): void {
         this.currentDynamicEntryIndex++;
         this.currentDynamicChangingExpressions.Clear();
-        var curDynamicEntry: DynamicsContainer = this.manager.MusicSheet.TimestampSortedDynamicExpressionsList[this.currentDynamicEntryIndex];
+        let curDynamicEntry: DynamicsContainer = this.manager.MusicSheet.TimestampSortedDynamicExpressionsList[this.currentDynamicEntryIndex];
         this.currentDynamicChangingExpressions.Add(curDynamicEntry);
-        var tsNow: Fraction = curDynamicEntry.parMultiExpression().AbsoluteTimestamp;
-        for (var i: number = this.currentDynamicEntryIndex + 1; i < this.manager.MusicSheet.TimestampSortedDynamicExpressionsList.Count; i++) {
+        let tsNow: Fraction = curDynamicEntry.parMultiExpression().AbsoluteTimestamp;
+        for (let i: number = this.currentDynamicEntryIndex + 1; i < this.manager.MusicSheet.TimestampSortedDynamicExpressionsList.Count; i++) {
             curDynamicEntry = this.manager.MusicSheet.TimestampSortedDynamicExpressionsList[i];
-            if ((curDynamicEntry.parMultiExpression().AbsoluteTimestamp != tsNow))
-                break;
+            if ((curDynamicEntry.parMultiExpression().AbsoluteTimestamp !== tsNow)) { break; }
             this.currentDynamicEntryIndex = i;
             this.currentDynamicChangingExpressions.Add(curDynamicEntry);
         }
     }
     private moveDynamicIndexToTimestamp(absoluteTimestamp: Fraction): void {
-        var dynamics: List<DynamicsContainer> = this.manager.MusicSheet.TimestampSortedDynamicExpressionsList;
-        for (var index: number = 0; index < dynamics.Count; index++) {
+        let dynamics: List<DynamicsContainer> = this.manager.MusicSheet.TimestampSortedDynamicExpressionsList;
+        for (let index: number = 0; index < dynamics.Count; index++) {
             if (dynamics[index].parMultiExpression().AbsoluteTimestamp >= absoluteTimestamp) {
                 this.currentDynamicEntryIndex = Math.Max(0, index - 1);
                 return
@@ -287,50 +286,67 @@ export class MusicPartManagerIterator {
         return this.manager.MusicSheet.TimestampSortedDynamicExpressionsList[this.currentDynamicEntryIndex + 1].parMultiExpression().AbsoluteTimestamp;
     }
     private handleRepetitionsAtMeasureBegin(): void {
-        for (var idx: number = 0, len = this.currentMeasure.FirstRepetitionInstructions.Count; idx < len; ++idx) {
-            var repetitionInstruction: RepetitionInstruction = this.currentMeasure.FirstRepetitionInstructions[idx];
-            if (repetitionInstruction.ParentRepetition == null)
+        for (let idx: number = 0, len: number = this.currentMeasure.FirstRepetitionInstructions.Count; idx < len; ++idx) {
+            let repetitionInstruction: RepetitionInstruction = this.currentMeasure.FirstRepetitionInstructions[idx];
+            if (repetitionInstruction.ParentRepetition === undefined)
                 continue;
-            var currentRepetition: Repetition = repetitionInstruction.ParentRepetition;
+            let currentRepetition: Repetition = repetitionInstruction.ParentRepetition;
             this.currentRepetition = currentRepetition;
-            if (currentRepetition.StartIndex == this.currentMeasureIndex) {
-                if (this.JumpResponsibleRepetition != null && currentRepetition != this.JumpResponsibleRepetition && currentRepetition.StartIndex >= this.JumpResponsibleRepetition.StartIndex && currentRepetition.EndIndex <= this.JumpResponsibleRepetition.EndIndex)
+            if (currentRepetition.StartIndex === this.currentMeasureIndex) {
+                if (
+                  this.JumpResponsibleRepetition !== undefined &&
+                  currentRepetition !== this.JumpResponsibleRepetition &&
+                  currentRepetition.StartIndex >= this.JumpResponsibleRepetition.StartIndex &&
+                  currentRepetition.EndIndex <= this.JumpResponsibleRepetition.EndIndex
+                ) {
                     this.resetRepetitionIterationCount(currentRepetition);
+                }
             }
         }
     }
+*/
     private handleRepetitionsAtMeasureEnd(): void {
-        for (var idx: number = 0, len = this.currentMeasure.LastRepetitionInstructions.Count; idx < len; ++idx) {
-            var repetitionInstruction: RepetitionInstruction = this.currentMeasure.LastRepetitionInstructions[idx];
-            var currentRepetition: Repetition = repetitionInstruction.ParentRepetition;
-            if (currentRepetition == null)
-                continue;
+        for (let idx: number = 0, len: number = this.currentMeasure.LastRepetitionInstructions.Count; idx < len; ++idx) {
+            let repetitionInstruction: RepetitionInstruction = this.currentMeasure.LastRepetitionInstructions[idx];
+            let currentRepetition: Repetition = repetitionInstruction.ParentRepetition;
+            if (currentRepetition === undefined) { continue; }
             if (currentRepetition.BackwardJumpInstructions.Contains(repetitionInstruction)) {
                 if (this.repetitionIterationCountDict[currentRepetition] < currentRepetition.UserNumberOfRepetitions) {
                     this.doBackJump(currentRepetition);
                     this.BackJumpOccurred = true;
-                    return
+                    return;
                 }
             }
-            if (repetitionInstruction == currentRepetition.ForwardJumpInstruction) {
-                if (this.JumpResponsibleRepetition != null && currentRepetition != this.JumpResponsibleRepetition && currentRepetition.StartIndex >= this.JumpResponsibleRepetition.StartIndex && currentRepetition.EndIndex <= this.JumpResponsibleRepetition.EndIndex)
+            if (repetitionInstruction === currentRepetition.ForwardJumpInstruction) {
+                if (
+                  this.JumpResponsibleRepetition !== undefined
+                  && currentRepetition !== this.JumpResponsibleRepetition
+                  && currentRepetition.StartIndex >= this.JumpResponsibleRepetition.StartIndex
+                  && currentRepetition.EndIndex <= this.JumpResponsibleRepetition.EndIndex
+                ) {
                     this.resetRepetitionIterationCount(currentRepetition);
-                var forwardJumpTargetMeasureIndex: number = currentRepetition.getForwardJumpTargetForIteration(this.repetitionIterationCountDict[currentRepetition]);
+                }
+
+                let forwardJumpTargetMeasureIndex: number = currentRepetition.getForwardJumpTargetForIteration(
+                  this.repetitionIterationCountDict[currentRepetition]
+                );
                 if (forwardJumpTargetMeasureIndex >= 0) {
                     this.currentMeasureIndex = forwardJumpTargetMeasureIndex;
                     this.currentMeasure = this.manager.MusicSheet.SourceMeasures[this.currentMeasureIndex];
                     this.currentVoiceEntryIndex = -1;
                     this.jumpResponsibleRepetition = currentRepetition;
                     this.ForwardJumpOccurred = true;
-                    return
+                    return;
                 }
-                if (forwardJumpTargetMeasureIndex == -2)
+                if (forwardJumpTargetMeasureIndex === -2) {
                     this.endReached = true;
+                }
             }
         }
         this.currentMeasureIndex++;
-        if (this.JumpResponsibleRepetition != null && this.currentMeasureIndex > this.JumpResponsibleRepetition.EndIndex)
-            this.jumpResponsibleRepetition = null;
+        if (this.JumpResponsibleRepetition !== undefined && this.currentMeasureIndex > this.JumpResponsibleRepetition.EndIndex) {
+            this.jumpResponsibleRepetition = undefined;
+        }
     }
     private doBackJump(currentRepetition: Repetition): void {
         this.currentMeasureIndex = currentRepetition.getBackwardJumpTarget();
@@ -340,10 +356,14 @@ export class MusicPartManagerIterator {
         this.jumpResponsibleRepetition = currentRepetition;
     }
     private activateCurrentRhythmInstructions(): void {
-        if (this.currentMeasure != null && this.currentMeasure.FirstInstructionsStaffEntries.Count > 0 && this.currentMeasure.FirstInstructionsStaffEntries[0] != null) {
-            var instructions: List<AbstractNotationInstruction> = this.currentMeasure.FirstInstructionsStaffEntries[0].Instructions;
-            for (var idx: number = 0, len = instructions.Count; idx < len; ++idx) {
-                var abstractNotationInstruction: AbstractNotationInstruction = instructions[idx];
+        if (
+          this.currentMeasure !== undefined &&
+          this.currentMeasure.FirstInstructionsStaffEntries.Count > 0 &&
+          this.currentMeasure.FirstInstructionsStaffEntries[0] !== undefined
+        ) {
+            let instructions: List<AbstractNotationInstruction> = this.currentMeasure.FirstInstructionsStaffEntries[0].Instructions;
+            for (let idx: number = 0, len: number = instructions.Count; idx < len; ++idx) {
+                let abstractNotationInstruction: AbstractNotationInstruction = instructions[idx];
                 if (abstractNotationInstruction instanceof RhythmInstruction) {
                     this.manager.MusicSheet.SheetPlaybackSetting.Rhythm = (<RhythmInstruction>abstractNotationInstruction).Rhythm;
                 }
@@ -351,76 +371,107 @@ export class MusicPartManagerIterator {
         }
     }
     private activateCurrentDynamicOrTempoInstructions(): void {
-        var timeSortedDynamics: List<DynamicsContainer> = this.manager.MusicSheet.TimestampSortedDynamicExpressionsList;
-        while (this.currentDynamicEntryIndex > 0 && (this.currentDynamicEntryIndex >= timeSortedDynamics.Count || timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp >= this.CurrentSourceTimestamp))
+        let timeSortedDynamics: List<DynamicsContainer> = this.manager.MusicSheet.TimestampSortedDynamicExpressionsList;
+        while (
+          this.currentDynamicEntryIndex > 0 && (
+            this.currentDynamicEntryIndex >= timeSortedDynamics.Count ||
+            timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp >= this.CurrentSourceTimestamp
+          )
+        ) {
             this.currentDynamicEntryIndex--;
-        while (this.currentDynamicEntryIndex < timeSortedDynamics.Count && timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp < this.CurrentSourceTimestamp)
+        }
+        while (
+          this.currentDynamicEntryIndex < timeSortedDynamics.Count &&
+          timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp < this.CurrentSourceTimestamp
+        ) {
             this.currentDynamicEntryIndex++;
-        while (this.currentDynamicEntryIndex < timeSortedDynamics.Count && timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp == this.CurrentSourceTimestamp) {
-            var dynamicsContainer: DynamicsContainer = timeSortedDynamics[this.currentDynamicEntryIndex];
-            var staffIndex: number = dynamicsContainer.StaffNumber;
-            if (this.CurrentSourceTimestamp == dynamicsContainer.parMultiExpression().AbsoluteTimestamp) {
-                if (dynamicsContainer.ContinuousDynamicExpression != null) {
+        }
+        while (
+          this.currentDynamicEntryIndex < timeSortedDynamics.Count
+          && timeSortedDynamics[this.currentDynamicEntryIndex].parMultiExpression().AbsoluteTimestamp === this.CurrentSourceTimestamp
+        ) {
+            let dynamicsContainer: DynamicsContainer = timeSortedDynamics[this.currentDynamicEntryIndex];
+            let staffIndex: number = dynamicsContainer.StaffNumber;
+            if (this.CurrentSourceTimestamp === dynamicsContainer.parMultiExpression().AbsoluteTimestamp) {
+                if (dynamicsContainer.ContinuousDynamicExpression !== undefined) {
                     this.activeDynamicExpressions[staffIndex] = dynamicsContainer.ContinuousDynamicExpression;
-                }
-                else if (dynamicsContainer.InstantaniousDynamicExpression != null) {
+                } else if (dynamicsContainer.InstantaniousDynamicExpression !== undefined) {
                     this.activeDynamicExpressions[staffIndex] = dynamicsContainer.InstantaniousDynamicExpression;
                 }
             }
             this.currentDynamicEntryIndex++;
         }
         this.currentDynamicChangingExpressions.Clear();
-        for (var staffIndex: number = 0; staffIndex < this.activeDynamicExpressions.Count; staffIndex++) {
-            if (this.activeDynamicExpressions[staffIndex] != null) {
-                var startTime: Fraction;
-                var endTime: Fraction;
+        for (let staffIndex: number = 0; staffIndex < this.activeDynamicExpressions.Count; staffIndex++) {
+            if (this.activeDynamicExpressions[staffIndex] !== undefined) {
+                let startTime: Fraction;
+                let endTime: Fraction;
                 if (this.activeDynamicExpressions[staffIndex] instanceof ContinuousDynamicExpression) {
-                    var continuousDynamic: ContinuousDynamicExpression = <ContinuousDynamicExpression>this.activeDynamicExpressions[staffIndex];
+                    let continuousDynamic: ContinuousDynamicExpression = <ContinuousDynamicExpression>this.activeDynamicExpressions[staffIndex];
                     startTime = continuousDynamic.StartMultiExpression.AbsoluteTimestamp;
                     endTime = continuousDynamic.EndMultiExpression.AbsoluteTimestamp;
-                    if (this.CurrentSourceTimestamp >= startTime && this.CurrentSourceTimestamp <= endTime)
+                    if (this.CurrentSourceTimestamp >= startTime && this.CurrentSourceTimestamp <= endTime) {
                         this.currentDynamicChangingExpressions.Add(new DynamicsContainer(continuousDynamic, staffIndex));
-                }
-                else {
-                    var instantaniousDynamic: InstantaniousDynamicExpression = <InstantaniousDynamicExpression>this.activeDynamicExpressions[staffIndex];
-                    if (this.CurrentSourceTimestamp == instantaniousDynamic.ParentMultiExpression.AbsoluteTimestamp)
+                    }
+                } else {
+                    let instantaniousDynamic: InstantaniousDynamicExpression = <InstantaniousDynamicExpression>this.activeDynamicExpressions[staffIndex];
+                    if (this.CurrentSourceTimestamp === instantaniousDynamic.ParentMultiExpression.AbsoluteTimestamp) {
                         this.currentDynamicChangingExpressions.Add(new DynamicsContainer(instantaniousDynamic, staffIndex));
+                    }
                 }
             }
         }
-        var timeSortedTempoExpressions: List<MultiTempoExpression> = this.manager.MusicSheet.TimestampSortedTempoExpressionsList;
-        while (this.currentTempoEntryIndex > 0 && (this.currentTempoEntryIndex >= timeSortedTempoExpressions.Count || timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp >= this.CurrentSourceTimestamp))
+        let timeSortedTempoExpressions: List<MultiTempoExpression> = this.manager.MusicSheet.TimestampSortedTempoExpressionsList;
+
+        while (this.currentTempoEntryIndex > 0 && (
+          this.currentTempoEntryIndex >= timeSortedTempoExpressions.Count
+          || timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp >= this.CurrentSourceTimestamp
+        )) {
             this.currentTempoEntryIndex--;
-        while (this.currentTempoEntryIndex < timeSortedTempoExpressions.Count && timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp < this.CurrentSourceTimestamp)
+        }
+
+        while (
+          this.currentTempoEntryIndex < timeSortedTempoExpressions.Count &&
+          timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp < this.CurrentSourceTimestamp
+        ) {
             this.currentTempoEntryIndex++;
-        while (this.currentTempoEntryIndex < timeSortedTempoExpressions.Count && timeSortedTempoExpressions[this.currentTempoEntryIndex].AbsoluteTimestamp == this.CurrentSourceTimestamp) {
+        }
+
+        while (
+          this.currentTempoEntryIndex < timeSortedTempoExpressions.Count
+          && timeSortedTempoExpressions[this.currentTempoEntryIndex]
+              .AbsoluteTimestamp === this.CurrentSourceTimestamp
+        ) {
             this.activeTempoExpression = timeSortedTempoExpressions[this.currentTempoEntryIndex];
             this.currentTempoEntryIndex++;
         }
-        this.currentTempoChangingExpression = null;
-        if (this.activeTempoExpression != null) {
-            var endTime: Fraction = this.activeTempoExpression.AbsoluteTimestamp;
-            if (this.activeTempoExpression.ContinuousTempo != null)
+        this.currentTempoChangingExpression = undefined;
+        if (this.activeTempoExpression !== undefined) {
+            let endTime: Fraction = this.activeTempoExpression.AbsoluteTimestamp;
+            if (this.activeTempoExpression.ContinuousTempo !== undefined) {
                 endTime = this.activeTempoExpression.ContinuousTempo.AbsoluteEndTimestamp;
-            if (this.CurrentSourceTimestamp >= this.activeTempoExpression.AbsoluteTimestamp || this.CurrentSourceTimestamp <= endTime)
+            }
+            if (this.CurrentSourceTimestamp >= this.activeTempoExpression.AbsoluteTimestamp || this.CurrentSourceTimestamp <= endTime) {
                 this.currentTempoChangingExpression = this.activeTempoExpression;
+            }
         }
     }
     private recursiveMove(): void {
         this.currentVoiceEntryIndex++;
-        if (this.currentVoiceEntryIndex == 0) {
+        if (this.currentVoiceEntryIndex === 0) {
             this.handleRepetitionsAtMeasureBegin();
             this.activateCurrentRhythmInstructions();
         }
         if (this.currentVoiceEntryIndex >= 0 && this.currentVoiceEntryIndex < this.currentMeasure.VerticalSourceStaffEntryContainers.Count) {
-            var currentContainer: VerticalSourceStaffEntryContainer = this.currentMeasure.VerticalSourceStaffEntryContainers[this.currentVoiceEntryIndex];
+            let currentContainer: VerticalSourceStaffEntryContainer = this.currentMeasure.VerticalSourceStaffEntryContainers[this.currentVoiceEntryIndex];
             this.currentVoiceEntries = this.getVoiceEntries(currentContainer);
             this.currentVerticalContainerInMeasureTimestamp = currentContainer.Timestamp;
             this.currentTimeStamp = new Fraction(this.currentMeasure.AbsoluteTimestamp + this.currentVerticalContainerInMeasureTimestamp);
-            if (this.currentTimeStamp >= this.manager.MusicSheet.SelectionEnd)
+            if (this.currentTimeStamp >= this.manager.MusicSheet.SelectionEnd) {
                 this.endReached = true;
+            }
             this.activateCurrentDynamicOrTempoInstructions();
-            return
+            return;
         }
         this.currentEnrolledMeasureTimestamp.Add(this.currentMeasure.Duration);
         this.handleRepetitionsAtMeasureEnd();
@@ -429,49 +480,49 @@ export class MusicPartManagerIterator {
             this.currentTimeStamp = new Fraction(this.currentMeasure.AbsoluteTimestamp + this.currentVerticalContainerInMeasureTimestamp);
             this.currentVoiceEntryIndex = -1;
             this.recursiveMove();
-            return
+            return;
         }
         this.currentVerticalContainerInMeasureTimestamp = new Fraction();
-        this.currentMeasure = null;
-        this.currentVoiceEntries = null;
+        this.currentMeasure = undefined;
+        this.currentVoiceEntries = undefined;
         this.endReached = true;
     }
     private checkEntries(notesOnly: boolean): boolean {
-        var tlist: List<VoiceEntry> = this.CurrentVisibleVoiceEntries();
+        let tlist: List<VoiceEntry> = this.CurrentVisibleVoiceEntries();
         if (tlist.Count > 0) {
-            if (!notesOnly)
-                return true;
-            for (var idx: number = 0, len = tlist.Count; idx < len; ++idx) {
-                var entry: VoiceEntry = tlist[idx];
-                if (entry.Notes[0].Pitch != null)
-                    return true;
+            if (!notesOnly) { return true; }
+            for (let idx: number = 0, len: number = tlist.Count; idx < len; ++idx) {
+                let entry: VoiceEntry = tlist[idx];
+                if (entry.Notes[0].Pitch !== undefined) { return true; }
             }
         }
         return false;
     }
     private getVisibleEntries(entry: VoiceEntry, visibleEntries: List<VoiceEntry>): void {
-        if (entry.ParentVoice.Visible)
+        if (entry.ParentVoice.Visible) {
             visibleEntries.Add(entry);
+        }
     }
     private getAudibleEntries(entry: VoiceEntry, audibleEntries: List<VoiceEntry>): void {
-        if (entry.ParentVoice.Audible)
+        if (entry.ParentVoice.Audible) {
             audibleEntries.Add(entry);
+        }
     }
     private getScoreFollowingEntries(entry: VoiceEntry, followingEntries: List<VoiceEntry>): void {
-        if (entry.ParentVoice.Following && entry.ParentVoice.Parent.Following)
+        if (entry.ParentVoice.Following && entry.ParentVoice.Parent.Following) {
             followingEntries.Add(entry);
+        }
     }
     private getVoiceEntries(container: VerticalSourceStaffEntryContainer): List<VoiceEntry> {
-        var entries: List<VoiceEntry> = new List<VoiceEntry>();
-        for (var idx: number = 0, len = container.StaffEntries.Count; idx < len; ++idx) {
-            var sourceStaffEntry: SourceStaffEntry = container.StaffEntries[idx];
-            if (sourceStaffEntry == null)
-                continue;
-            for (var idx2: number = 0, len2 = sourceStaffEntry.VoiceEntries.Count; idx2 < len2; ++idx2) {
-                var voiceEntry: VoiceEntry = sourceStaffEntry.VoiceEntries[idx2];
+        let entries: List<VoiceEntry> = new List<VoiceEntry>();
+        for (let idx: number = 0, len: number = container.StaffEntries.Count; idx < len; ++idx) {
+            let sourceStaffEntry: SourceStaffEntry = container.StaffEntries[idx];
+            if (sourceStaffEntry === undefined) { continue; }
+            for (let idx2: number = 0, len2: number = sourceStaffEntry.VoiceEntries.Count; idx2 < len2; ++idx2) {
+                let voiceEntry: VoiceEntry = sourceStaffEntry.VoiceEntries[idx2];
                 entries.Add(voiceEntry);
             }
         }
         return entries;
     }
-}
+}

+ 114 - 103
src/MusicalScore/MusicSheet.ts

@@ -1,19 +1,20 @@
-export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
-{
+export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet> {
     constructor() {
         try {
             this.Rules = EngravingRules.Rules;
+        } catch (ex) {
+            console.log("MusicSheet Error: EngravingRules"); // FIXME
         }
-        catch (ex) {
-
-        }
-
         this.playbackSettings = this.SheetPlaybackSetting = new PlaybackSettings(new Fraction(4, 4, false), 100);
         this.UserStartTempoInBPM = 100;
         this.PageWidth = 120;
         this.MusicPartManager = new MusicPartManager(this);
     }
-    private idString: string = "kjgdfuilhsdaöoihfsvjh";
+    public static defaultTitle: string = "[kein Titel]";
+    public UserStartTempoInBPM: number;
+    public PageWidth: number;
+
+    private idString: string = "kjgdfuilhsda�oihfsvjh";
     private sourceMeasures: List<SourceMeasure> = new List<SourceMeasure>();
     private repetitions: List<Repetition> = new List<Repetition>();
     private dynListStaves: List<List<DynamicsContainer>> = new List<List<DynamicsContainer>>();
@@ -27,9 +28,9 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
     private subtitle: Label;
     private composer: Label;
     private lyricist: Label;
-    private languages: List<Language> = new List<Language>();
-    private activeLanguage: Language;
-    private musicPartManager: MusicPartManager = null;
+    // private languages: List<Language> = new List<Language>();
+    // private activeLanguage: Language;
+    private musicPartManager: MusicPartManager = undefined;
     private musicSheetErrors: MusicSheetErrors = new MusicSheetErrors();
     private staves: List<Staff> = new List<Staff>();
     private selectionStart: Fraction;
@@ -39,11 +40,11 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
     private drawErroneousMeasures: boolean = false;
     private hasBeenOpenedForTheFirstTime: boolean = false;
     private currentEnrolledPosition: Fraction = new Fraction(0, 1);
-    private musicSheetParameterObject: MusicSheetParameterObject = null;
+    private musicSheetParameterObject: MusicSheetParameterObject = undefined;
     private engravingRules: EngravingRules;
     private phonicScoreInterface: IPhonicScoreInterface;
     private musicSheetParameterChangedDelegate: MusicSheetParameterChangedDelegate;
-    public static defaultTitle: string = "[kein Titel]";
+
     public get PhonicScoreInterface(): IPhonicScoreInterface {
         return this.phonicScoreInterface;
     }
@@ -99,7 +100,6 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         this.playbackSettings.BeatsPerMinute = startTempo;
         this.UserStartTempoInBPM = startTempo;
     }
-    public UserStartTempoInBPM: number;
     public get DefaultStartTempoInBpm(): number {
         return this.defaultStartTempoInBpm;
     }
@@ -107,7 +107,6 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         this.defaultStartTempoInBpm = value;
         this.InitializeStartTempoInBPM(value);
     }
-    public PageWidth: number;
     public get Path(): string {
         return this.path;
     }
@@ -118,24 +117,32 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         return this.staves;
     }
     public get TitleString(): string {
-        if (this.title != null)
+        if (this.title !== undefined) {
             return this.title.Text;
-        else return string.Empty;
+        } else {
+            return string.Empty;
+        }
     }
     public get SubtitleString(): string {
-        if (this.subtitle != null)
+        if (this.subtitle !== undefined) {
             return this.subtitle.Text;
-        else return string.Empty;
+        } else {
+            return string.Empty;
+        }
     }
     public get ComposerString(): string {
-        if (this.composer != null)
+        if (this.composer !== undefined) {
             return this.composer.Text;
-        else return string.Empty;
+        } else {
+            return string.Empty;
+        }
     }
     public get LyricistString(): string {
-        if (this.lyricist != null)
+        if (this.lyricist !== undefined) {
             return this.lyricist.Text;
-        else return string.Empty;
+        } else {
+            return string.Empty;
+        }
     }
     public get Title(): Label {
         return this.title;
@@ -196,28 +203,30 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         measure.MeasureListIndex = this.SourceMeasures.Count - 1;
     }
     public checkForInstrumentWithNoVoice(): void {
-        for (var idx: number = 0, len = this.instruments.Count; idx < len; ++idx) {
-            var instrument: Instrument = this.instruments[idx];
-            if (instrument.Voices.Count == 0) {
-                var voice: Voice = new Voice(instrument, 1);
+        for (let idx: number = 0, len: number = this.instruments.Count; idx < len; ++idx) {
+            let instrument: Instrument = this.instruments[idx];
+            if (instrument.Voices.Count === 0) {
+                let voice: Voice = new Voice(instrument, 1);
                 instrument.Voices.Add(voice);
             }
         }
     }
     public getStaffFromIndex(staffIndexInMusicSheet: number): Staff {
-        if (this.staves.Count > staffIndexInMusicSheet)
+        if (this.staves.Count > staffIndexInMusicSheet) {
             return this.staves[staffIndexInMusicSheet];
-        else return null;
+        } else {
+            return undefined;
+        }
     }
     public getIndexFromStaff(staff: Staff): number {
         return staff.IdInMusicSheet;
     }
     public fillStaffList(): void {
-        var i: number = 0;
-        for (var idx: number = 0, len = this.instruments.Count; idx < len; ++idx) {
-            var instrument: Instrument = this.instruments[idx];
-            for (var idx2: number = 0, len2 = instrument.Staves.Count; idx2 < len2; ++idx2) {
-                var staff: Staff = instrument.Staves[idx2];
+        let i: number = 0;
+        for (let idx: number = 0, len: number = this.instruments.Count; idx < len; ++idx) {
+            let instrument: Instrument = this.instruments[idx];
+            for (let idx2: number = 0, len2: number = instrument.Staves.Count; idx2 < len2; ++idx2) {
+                let staff: Staff = instrument.Staves[idx2];
                 staff.IdInMusicSheet = i;
                 this.staves.Add(staff);
                 i++;
@@ -231,23 +240,25 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         this.musicPartManager = value;
     }
     public getCompleteNumberOfStaves(): number {
-        var number: number = 0;
-        for (var idx: number = 0, len = this.instruments.Count; idx < len; ++idx) {
-            var instrument: Instrument = this.instruments[idx];
+        let number: number = 0;
+        for (let idx: number = 0, len: number = this.instruments.Count; idx < len; ++idx) {
+            let instrument: Instrument = this.instruments[idx];
             number += instrument.Staves.Count;
         }
         return number;
     }
     public getListOfMeasuresFromIndeces(start: number, end: number): List<SourceMeasure> {
-        var measures: List<SourceMeasure> = new List<SourceMeasure>();
-        for (var i: number = start; i <= end; i++)
+        let measures: List<SourceMeasure> = new List<SourceMeasure>();
+        for (let i: number = start; i <= end; i++) {
             measures.Add(this.sourceMeasures[i]);
+        }
         return measures;
     }
     public getNextSourceMeasure(measure: SourceMeasure): SourceMeasure {
-        var index: number = this.sourceMeasures.IndexOf(measure);
-        if (index == this.sourceMeasures.Count - 1)
+        let index: number = this.sourceMeasures.IndexOf(measure);
+        if (index === this.sourceMeasures.Count - 1) {
             return measure;
+        }
         return this.sourceMeasures[index + 1];
     }
     public getFirstSourceMeasure(): SourceMeasure {
@@ -257,12 +268,12 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         return this.sourceMeasures[this.sourceMeasures.Count - 1];
     }
     public resetAllNoteStates(): void {
-        var iterator: MusicPartManagerIterator = this.MusicPartManager.getIterator();
-        while (!iterator.EndReached && iterator.CurrentVoiceEntries != null) {
-            for (var idx: number = 0, len = iterator.CurrentVoiceEntries.Count; idx < len; ++idx) {
-                var voiceEntry: VoiceEntry = iterator.CurrentVoiceEntries[idx];
-                for (var idx2: number = 0, len2 = voiceEntry.Notes.Count; idx2 < len2; ++idx2) {
-                    var note: Note = voiceEntry.Notes[idx2];
+        let iterator: MusicPartManagerIterator = this.MusicPartManager.getIterator();
+        while (!iterator.EndReached && iterator.CurrentVoiceEntries !== undefined) {
+            for (let idx: number = 0, len: number = iterator.CurrentVoiceEntries.Count; idx < len; ++idx) {
+                let voiceEntry: VoiceEntry = iterator.CurrentVoiceEntries[idx];
+                for (let idx2: number = 0, len2: number = voiceEntry.Notes.Count; idx2 < len2; ++idx2) {
+                    let note: Note = voiceEntry.Notes[idx2];
                     note.State = NoteState.Normal;
                 }
             }
@@ -273,78 +284,79 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         return this.Instruments.IndexOf(instrument);
     }
     public getGlobalStaffIndexOfFirstStaff(instrument: Instrument): number {
-        var instrumentIndex: number = this.getMusicSheetInstrumentIndex(instrument);
-        var staffLineIndex: number = 0;
-        for (var i: number = 0; i < instrumentIndex; i++)
+        let instrumentIndex: number = this.getMusicSheetInstrumentIndex(instrument);
+        let staffLineIndex: number = 0;
+        for (let i: number = 0; i < instrumentIndex; i++) {
             staffLineIndex += this.Instruments[i].Staves.Count;
+        }
         return staffLineIndex;
     }
     public setRepetitionNewUserNumberOfRepetitions(index: number, value: number): void {
-        var repIndex: number = 0;
-        for (var i: number = 0; i < this.repetitions.Count; i++) {
+        let repIndex: number = 0;
+        for (let i: number = 0; i < this.repetitions.Count; i++) {
             if (this.repetitions[i] instanceof Repetition) {
-                if (index == repIndex) {
+                if (index === repIndex) {
                     (<Repetition>this.repetitions[i]).UserNumberOfRepetitions = value;
                     break;
+                } else {
+                    repIndex++;
                 }
-                else repIndex++;
             }
         }
     }
     public getRepetitionByIndex(index: number): Repetition {
-        var repIndex: number = 0;
-        for (var i: number = 0; i < this.repetitions.Count; i++) {
+        let repIndex: number = 0;
+        for (let i: number = 0; i < this.repetitions.Count; i++) {
             if (this.repetitions[i] instanceof Repetition) {
-                if (index == repIndex)
+                if (index === repIndex) {
                     return <Repetition>this.repetitions[i];
+                }
                 repIndex++;
             }
         }
-        return null;
+        return undefined;
     }
     public CompareTo(other: MusicSheet): number {
         return this.Title.Text.CompareTo(other.Title.Text);
     }
     public get IInstruments(): List<IInstrument> {
-        var list: List<IInstrument> = new List<IInstrument>();
-        for (var idx: number = 0, len = this.instruments.Count; idx < len; ++idx) {
-            var instr: Instrument = this.instruments[idx];
+        let list: List<IInstrument> = new List<IInstrument>();
+        for (let idx: number = 0, len: number = this.instruments.Count; idx < len; ++idx) {
+            let instr: Instrument = this.instruments[idx];
             list.Add(instr);
         }
         return list;
     }
     public get IInitializableInstruments(): List<ISettableInstrument> {
-        var list: List<ISettableInstrument> = new List<ISettableInstrument>();
-        for (var idx: number = 0, len = this.instruments.Count; idx < len; ++idx) {
-            var instr: Instrument = this.instruments[idx];
+        let list: List<ISettableInstrument> = new List<ISettableInstrument>();
+        for (let idx: number = 0, len: number = this.instruments.Count; idx < len; ++idx) {
+            let instr: Instrument = this.instruments[idx];
             list.Add(instr);
         }
         return list;
     }
     public get IRepetitions(): List<IRepetition> {
         try {
-            var repetitions: List<IRepetition> = new List<IRepetition>();
-            for (var idx: number = 0, len = this.repetitions.Count; idx < len; ++idx) {
-                var partListEntry: PartListEntry = this.repetitions[idx];
+            let repetitions: List<IRepetition> = new List<IRepetition>();
+            for (let idx: number = 0, len: number = this.repetitions.Count; idx < len; ++idx) {
+                let partListEntry: PartListEntry = this.repetitions[idx];
                 if (partListEntry instanceof Repetition) {
                     repetitions.Add(<Repetition>partListEntry);
                 }
             }
             return repetitions;
-        }
-        catch (ex) {
+        } catch (ex) {
             Logger.DefaultLogger.LogError(LogLevel.NORMAL, "MusicSheet.IRepetitions get: ", ex);
-            return null;
+            return undefined;
         }
 
     }
     public GetExpressionsStartTempoInBPM(): number {
         if (this.TimestampSortedTempoExpressionsList.Count > 0) {
-            var me: MultiTempoExpression = this.TimestampSortedTempoExpressionsList[0];
-            if (me.InstantaniousTempo != null) {
+            let me: MultiTempoExpression = this.TimestampSortedTempoExpressionsList[0];
+            if (me.InstantaniousTempo !== undefined) {
                 return me.InstantaniousTempo.TempoInBpm;
-            }
-            else if (me.ContinuousTempo != null) {
+            } else if (me.ContinuousTempo !== undefined) {
                 return me.ContinuousTempo.StartTempo;
             }
         }
@@ -353,18 +365,16 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
     public get Errors(): Dictionary<number, List<string>> {
         try {
             return this.musicSheetErrors.MeasureErrors;
-        }
-        catch (ex) {
+        } catch (ex) {
             Logger.DefaultLogger.LogError(LogLevel.NORMAL, "MusicSheet.Errors get: ", ex);
-            return null;
+            return undefined;
         }
 
     }
     public get FirstMeasureNumber(): number {
         try {
             return this.getFirstSourceMeasure().MeasureNumber;
-        }
-        catch (ex) {
+        } catch (ex) {
             Logger.DefaultLogger.LogError(LogLevel.NORMAL, "MusicSheet.FirstMeasureNumber: ", ex);
             return 0;
         }
@@ -373,8 +383,7 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
     public get LastMeasureNumber(): number {
         try {
             return this.getLastSourceMeasure().MeasureNumber;
-        }
-        catch (ex) {
+        } catch (ex) {
             Logger.DefaultLogger.LogError(LogLevel.NORMAL, "MusicSheet.LastMeasureNumber: ", ex);
             return 0;
         }
@@ -393,23 +402,24 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         this.transpose = value;
     }
     public SetMusicSheetParameter(parameter: MusicSheetParameters, value: Object): void {
-        if (this.PhonicScoreInterface != null)
+        if (this.PhonicScoreInterface !== undefined) {
             this.PhonicScoreInterface.RequestMusicSheetParameter(parameter, value);
-        else {
-            var oldValue: Object = 0;
-            if (parameter == MusicSheetParameters.MusicSheetTranspose) {
+        } else {
+            let oldValue: Object = 0;
+            if (parameter === MusicSheetParameters.MusicSheetTranspose) {
                 oldValue = this.Transpose;
                 this.Transpose = <number>value;
             }
-            if (parameter == MusicSheetParameters.StartTempoInBPM) {
+            if (parameter === MusicSheetParameters.StartTempoInBPM) {
                 oldValue = this.UserStartTempoInBPM;
                 this.UserStartTempoInBPM = <number>value;
             }
-            if (parameter == MusicSheetParameters.HighlightErrors) {
+            if (parameter === MusicSheetParameters.HighlightErrors) {
                 oldValue = value;
             }
-            if (this.MusicSheetParameterChanged != null)
-                MusicSheetParameterChanged(null, parameter, value, oldValue);
+            if (this.MusicSheetParameterChanged !== undefined) {
+                MusicSheetParameterChanged(undefined, parameter, value, oldValue);
+            }
         }
     }
     public get MusicSheetParameterChanged(): MusicSheetParameterChangedDelegate {
@@ -428,26 +438,26 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         this.idString = value;
     }
     public Dispose(): void {
-        this.MusicSheetParameterChanged = null;
-        for (var idx: number = 0, len = this.IInstruments.Count; idx < len; ++idx) {
-            var instrument: IInstrument = this.IInstruments[idx];
+        this.MusicSheetParameterChanged = undefined;
+        for (let idx: number = 0, len: number = this.IInstruments.Count; idx < len; ++idx) {
+            let instrument: IInstrument = this.IInstruments[idx];
             instrument.Dispose();
         }
     }
     public getEnrolledSelectionStartTimeStampWorkaround(): Fraction {
-        var iter: MusicPartManagerIterator = this.MusicPartManager.getIterator(this.SelectionStart);
+        let iter: MusicPartManagerIterator = this.MusicPartManager.getIterator(this.SelectionStart);
         return new Fraction(iter.CurrentEnrolledTimestamp);
     }
     public get SheetEndTimestamp(): Fraction {
-        var lastMeasure: SourceMeasure = this.getLastSourceMeasure();
+        let lastMeasure: SourceMeasure = this.getLastSourceMeasure();
         return lastMeasure.AbsoluteTimestamp + lastMeasure.Duration;
     }
     public getSourceMeasureFromTimeStamp(timeStamp: Fraction): SourceMeasure {
-        for (var idx: number = 0, len = this.SourceMeasures.Count; idx < len; ++idx) {
-            var sm: SourceMeasure = this.SourceMeasures[idx];
-            for (var idx2: number = 0, len2 = sm.VerticalSourceStaffEntryContainers.Count; idx2 < len2; ++idx2) {
-                var vssec: VerticalSourceStaffEntryContainer = sm.VerticalSourceStaffEntryContainers[idx2];
-                if (timeStamp == vssec.getAbsoluteTimestamp()) {
+        for (let idx: number = 0, len: number = this.SourceMeasures.Count; idx < len; ++idx) {
+            let sm: SourceMeasure = this.SourceMeasures[idx];
+            for (let idx2: number = 0, len2: number = sm.VerticalSourceStaffEntryContainers.Count; idx2 < len2; ++idx2) {
+                let vssec: VerticalSourceStaffEntryContainer = sm.VerticalSourceStaffEntryContainers[idx2];
+                if (timeStamp === vssec.getAbsoluteTimestamp()) {
                     return sm;
                 }
             }
@@ -455,11 +465,12 @@ export class MusicSheet implements ISettableMusicSheet, IComparable<MusicSheet>
         return this.findSourceMeasureFromTimeStamp(timeStamp);
     }
     public findSourceMeasureFromTimeStamp(timeStamp: Fraction): SourceMeasure {
-        for (var idx: number = 0, len = this.SourceMeasures.Count; idx < len; ++idx) {
-            var sm: SourceMeasure = this.SourceMeasures[idx];
-            if (sm.AbsoluteTimestamp >= timeStamp && timeStamp < sm.AbsoluteTimestamp + sm.Duration)
+        for (let idx: number = 0, len: number = this.SourceMeasures.Count; idx < len; ++idx) {
+            let sm: SourceMeasure = this.SourceMeasures[idx];
+            if (sm.AbsoluteTimestamp >= timeStamp && timeStamp < sm.AbsoluteTimestamp + sm.Duration) {
                 return sm;
+            }
         }
-        return null;
+        return undefined;
     }
-}
+}

+ 8 - 9
src/MusicalScore/MusicSource/MappingSourceMusicPart.ts

@@ -1,7 +1,6 @@
-export class MappingSourceMusicPart implements IComparable, IComparable<MappingSourceMusicPart>
-{
+export class MappingSourceMusicPart implements IComparable, IComparable<MappingSourceMusicPart> {
     constructor(sourceMusicPart: SourceMusicPart, startTimestamp: Fraction) {
-        this(sourceMusicPart, null, startTimestamp, -1, false);
+        this(sourceMusicPart, undefined, startTimestamp, -1, false);
 
     }
     constructor(sourceMusicPart: SourceMusicPart, parentPartListEntry: Repetition, startTimestamp: Fraction, repetitionRun: number, isEnding: boolean) {
@@ -19,13 +18,13 @@ export class MappingSourceMusicPart implements IComparable, IComparable<MappingS
     private repetitionRun: number = -1;
     private isEnding: boolean;
     public get IsRepetition(): boolean {
-        return this.parentRepetition != null;
+        return this.parentRepetition !== undefined;
     }
     public get IsEnding(): boolean {
         return this.isEnding;
     }
     public get IsLastRepetitionRun(): boolean {
-        return this.IsRepetition && (this.repetitionRun + 1 == this.parentRepetition.UserNumberOfRepetitions);
+        return this.IsRepetition && (this.repetitionRun + 1 === this.parentRepetition.UserNumberOfRepetitions);
     }
     public get RepetitionRun(): number {
         return this.repetitionRun;
@@ -40,12 +39,12 @@ export class MappingSourceMusicPart implements IComparable, IComparable<MappingS
         return this.startTimestamp;
     }
     public CompareTo(obj: Object): number {
-        var comp: MappingSourceMusicPart = __as__<MappingSourceMusicPart>(obj, MappingSourceMusicPart);
-        if (comp != null)
+        let comp: MappingSourceMusicPart = __as__<MappingSourceMusicPart>(obj, MappingSourceMusicPart);
+        if (comp !== undefined) {
             return this.startTimestamp.CompareTo(comp.startTimestamp);
-        else return 1;
+        } else { return 1; }
     }
     public CompareTo(other: MappingSourceMusicPart): number {
         return this.CompareTo(<Object>other);
     }
-}
+}

+ 8 - 4
src/MusicalScore/MusicSource/PartListEntry.ts

@@ -2,22 +2,26 @@ export class PartListEntry {
     constructor(musicSheet: MusicSheet) {
         this.musicSheet = musicSheet;
     }
+
+    public AbsoluteTimestamp: Fraction;
+    public StartIndex: number;
+    public EndIndex: number;
+
     protected enrolledTimestamps: List<Fraction> = new List<Fraction>();
     protected visible: boolean = true;
+
     private musicSheet: MusicSheet;
-    public AbsoluteTimestamp: Fraction;
+
     public get Visible(): boolean {
         return this.visible;
     }
     public set Visible(value: boolean) {
         this.visible = value;
     }
-    public StartIndex: number;
-    public EndIndex: number;
     public getFirstSourceMeasure(): SourceMeasure {
         return this.musicSheet.SourceMeasures[this.StartIndex];
     }
     public getLastSourceMeasure(): SourceMeasure {
         return this.musicSheet.SourceMeasures[this.EndIndex];
     }
-}
+}

+ 49 - 46
src/MusicalScore/MusicSource/Repetition.ts

@@ -1,13 +1,14 @@
 export class Repetition extends PartListEntry implements IRepetition {
-    constructor(musicSheet: MusicSheet) {
-        super(musicSheet);
-        this.musicSheet = musicSheet;
-    }
     constructor(musicSheet: MusicSheet, virtualOverallRepetition: boolean) {
         super(musicSheet);
         this.musicSheet = musicSheet;
         this.virtualOverallRepetition = virtualOverallRepetition;
     }
+
+    public StartMarker: RepetitionInstruction;
+    public EndMarker: RepetitionInstruction;
+    public ForwardJumpInstruction: RepetitionInstruction;
+
     private backwardJumpInstructions: List<RepetitionInstruction> = new List<RepetitionInstruction>();
     private endingParts: List<RepetitionEndingPart> = new List<RepetitionEndingPart>();
     private endingIndexDict: Dictionary<number, RepetitionEndingPart> = new Dictionary<number, RepetitionEndingPart>();
@@ -18,9 +19,7 @@ export class Repetition extends PartListEntry implements IRepetition {
     private repetitonIterationOrder: List<number> = new List<number>();
     private numberOfEndings: number = 1;
     private virtualOverallRepetition: boolean;
-    public StartMarker: RepetitionInstruction;
-    public EndMarker: RepetitionInstruction;
-    public ForwardJumpInstruction: RepetitionInstruction;
+
     public get BackwardJumpInstructions(): List<RepetitionInstruction> {
         return this.backwardJumpInstructions;
     }
@@ -37,9 +36,8 @@ export class Repetition extends PartListEntry implements IRepetition {
         this.visibles = value;
     }
     public get DefaultNumberOfRepetitions(): number {
-        var defaultNumber: number = 2;
-        if (this.virtualOverallRepetition)
-            defaultNumber = 1;
+        let defaultNumber: number = 2;
+        if (this.virtualOverallRepetition) { defaultNumber = 1; }
         return Math.Max(Math.Max(defaultNumber, this.endingIndexDict.Count), this.checkRepetitionForMultipleLyricVerses());
     }
     public get UserNumberOfRepetitions(): number {
@@ -48,48 +46,50 @@ export class Repetition extends PartListEntry implements IRepetition {
     public set UserNumberOfRepetitions(value: number) {
         this.userNumberOfRepetitions = value;
         this.repetitonIterationOrder.Clear();
-        var endingsDiff: number = this.userNumberOfRepetitions - this.NumberOfEndings;
-        for (var i: number = 1; i <= this.userNumberOfRepetitions; i++) {
-            if (i <= endingsDiff)
+        let endingsDiff: number = this.userNumberOfRepetitions - this.NumberOfEndings;
+        for (let i: number = 1; i <= this.userNumberOfRepetitions; i++) {
+            if (i <= endingsDiff) {
                 this.repetitonIterationOrder.Add(1);
-            else {
+            } else {
                 this.repetitonIterationOrder.Add(i - endingsDiff);
             }
         }
     }
     public getForwardJumpTargetForIteration(iteration: number): number {
-        var endingIndex: number = this.repetitonIterationOrder[iteration - 1];
-        if (this.endingIndexDict.ContainsKey(endingIndex))
+        let endingIndex: number = this.repetitonIterationOrder[iteration - 1];
+        if (this.endingIndexDict.ContainsKey(endingIndex)) {
             return this.endingIndexDict[endingIndex].part.StartIndex;
+        }
         return -1;
     }
     public getBackwardJumpTarget(): number {
         return this.StartMarker.MeasureIndex;
     }
     public SetEndingStartIndex(endingNumbers: List<number>, startIndex: number): void {
-        var part: RepetitionEndingPart = new RepetitionEndingPart(new SourceMusicPart(this.musicSheet, startIndex, startIndex));
+        let part: RepetitionEndingPart = new RepetitionEndingPart(new SourceMusicPart(this.musicSheet, startIndex, startIndex));
         this.endingParts.Add(part);
-        for (var idx: number = 0, len = endingNumbers.Count; idx < len; ++idx) {
-            var endingNumber: number = endingNumbers[idx];
+        for (let idx: number = 0, len: number = endingNumbers.Count; idx < len; ++idx) {
+            let endingNumber: number = endingNumbers[idx];
             try {
                 this.endingIndexDict.Add(endingNumber, part);
                 part.endingIndices.Add(endingNumber);
-                if (this.numberOfEndings < endingNumber)
+                if (this.numberOfEndings < endingNumber) {
                     this.numberOfEndings = endingNumber;
-            }
-            catch (err) {
-
+                }
+            } catch (err) {
+                console.log("Repetition: Exception."); // FIXME
             }
 
         }
     }
     public SetEndingStartIndex(endingNumber: number, startIndex: number): void {
-        var part: RepetitionEndingPart = new RepetitionEndingPart(new SourceMusicPart(this.musicSheet, startIndex, startIndex));
+        let part: RepetitionEndingPart = new RepetitionEndingPart(new SourceMusicPart(this.musicSheet, startIndex, startIndex));
         this.endingParts.Add(part);
         this.endingIndexDict.Add(endingNumber, part);
         part.endingIndices.Add(endingNumber);
-        if (this.numberOfEndings < endingNumber)
+        if (this.numberOfEndings < endingNumber) {
             this.numberOfEndings = endingNumber;
+        }
     }
     public setEndingEndIndex(endingNumber: number, endIndex: number): void {
         if (this.endingIndexDict.ContainsKey(endingNumber)) {
@@ -112,26 +112,28 @@ export class Repetition extends PartListEntry implements IRepetition {
         return this.StartMarker.MeasureIndex;
     }
     public get EndIndex(): number {
-        if (this.BackwardJumpInstructions.Count == 0)
+        if (this.BackwardJumpInstructions.Count === 0) {
             return this.StartIndex;
-        var result: number = this.BackwardJumpInstructions.Last().MeasureIndex;
-        if (this.endingIndexDict.ContainsKey(this.NumberOfEndings))
+        }
+        let result: number = this.BackwardJumpInstructions.Last().MeasureIndex;
+        if (this.endingIndexDict.ContainsKey(this.NumberOfEndings)) {
             result = Math.Max(this.endingIndexDict[this.NumberOfEndings].part.EndIndex, result);
+        }
         return result;
     }
     private checkRepetitionForMultipleLyricVerses(): number {
-        var lyricVerses: number = 0;
-        var start: number = this.StartIndex;
-        var end: number = this.EndIndex;
-        for (var measureIndex: number = start; measureIndex <= end; measureIndex++) {
-            var sourceMeasure: SourceMeasure = this.musicSheet.SourceMeasures[measureIndex];
-            for (var i: number = 0; i < sourceMeasure.CompleteNumberOfStaves; i++) {
-                for (var j: number = 0; j < sourceMeasure.VerticalSourceStaffEntryContainers.Count; j++) {
-                    if (sourceMeasure.VerticalSourceStaffEntryContainers[j][i] != null) {
-                        var sourceStaffEntry: SourceStaffEntry = sourceMeasure.VerticalSourceStaffEntryContainers[j][i];
-                        var verses: number = 0;
-                        for (var idx: number = 0, len = sourceStaffEntry.VoiceEntries.Count; idx < len; ++idx) {
-                            var voiceEntry: VoiceEntry = sourceStaffEntry.VoiceEntries[idx];
+        let lyricVerses: number = 0;
+        let start: number = this.StartIndex;
+        let end: number = this.EndIndex;
+        for (let measureIndex: number = start; measureIndex <= end; measureIndex++) {
+            let sourceMeasure: SourceMeasure = this.musicSheet.SourceMeasures[measureIndex];
+            for (let i: number = 0; i < sourceMeasure.CompleteNumberOfStaves; i++) {
+                for (let j: number = 0; j < sourceMeasure.VerticalSourceStaffEntryContainers.Count; j++) {
+                    if (sourceMeasure.VerticalSourceStaffEntryContainers[j][i] !== undefined) {
+                        let sourceStaffEntry: SourceStaffEntry = sourceMeasure.VerticalSourceStaffEntryContainers[j][i];
+                        let verses: number = 0;
+                        for (let idx: number = 0, len: number = sourceStaffEntry.VoiceEntries.Count; idx < len; ++idx) {
+                            let voiceEntry: VoiceEntry = sourceStaffEntry.VoiceEntries[idx];
                             verses += voiceEntry.LyricsEntries.Count;
                         }
                         lyricVerses = Math.Max(lyricVerses, verses);
@@ -147,8 +149,8 @@ export class Repetition extends PartListEntry implements IRepetition {
     public get LastSourceMeasureNumber(): number {
         return getLastSourceMeasure().MeasureNumber;
     }
-}
-export module Repetition {
+
+
     export class RepetitionEndingPart {
         constructor(endingPart: SourceMusicPart) {
             this.part = endingPart;
@@ -156,13 +158,14 @@ export module Repetition {
         public part: SourceMusicPart;
         public endingIndices: List<number> = new List<number>();
         public ToString(): string {
-            var result: string = "";
-            if (this.endingIndices.Count > 0)
+            let result: string = "";
+            if (this.endingIndices.Count > 0) {
                 result += this.endingIndices[0];
-            for (var i: number = 1; i < this.endingIndices.Count; i++) {
+            }
+            for (let i: number = 1; i < this.endingIndices.Count; i++) {
                 result += ", " + this.endingIndices[i];
             }
             return result;
         }
     }
-}
+}

+ 1 - 1
src/MusicalScore/MusicSource/SourceMusicPart.ts

@@ -41,4 +41,4 @@ export class SourceMusicPart extends PartListEntry {
     public setEndIndex(index: number): void {
         this.endIndex = index;
     }
-}
+}

+ 905 - 874
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -1,930 +1,961 @@
 export class InstrumentReader {
-    constructor(repetitionInstructionReader: RepetitionInstructionReader, xmlMeasureList: IEnumerable<IXmlElement>, instrument: Instrument) {
-        this.repetitionInstructionReader = repetitionInstructionReader;
-        this.xmlMeasureList = xmlMeasureList.ToArray();
-        this.musicSheet = instrument.GetMusicSheet;
-        this.instrument = instrument;
-        this.activeClefs = new Array(instrument.Staves.Count);
-        this.activeClefsHaveBeenInitialized = new Array(instrument.Staves.Count);
-        for (var i: number = 0; i < instrument.Staves.Count; i++)
-            this.activeClefsHaveBeenInitialized[i] = false;
-        createExpressionGenerators(instrument.Staves.Count);
-        this.slurReader = MusicSymbolModuleFactory.createSlurReader(this.musicSheet);
+  constructor(repetitionInstructionReader: RepetitionInstructionReader, xmlMeasureList: IEnumerable<IXmlElement>, instrument: Instrument) {
+    this.repetitionInstructionReader = repetitionInstructionReader;
+    this.xmlMeasureList = xmlMeasureList.ToArray();
+    this.musicSheet = instrument.GetMusicSheet;
+    this.instrument = instrument;
+    this.activeClefs = new Array(instrument.Staves.Count);
+    this.activeClefsHaveBeenInitialized = new Array(instrument.Staves.Count);
+    for (let i: number = 0; i < instrument.Staves.Count; i++) {
+      this.activeClefsHaveBeenInitialized[i] = false;
     }
-    private repetitionInstructionReader: RepetitionInstructionReader;
-    private xmlMeasureList: IXmlElement[];
-    private musicSheet: MusicSheet;
-    private slurReader: SlurReader;
-    private instrument: Instrument;
-    private voiceGeneratorsDict: Dictionary<number, VoiceGenerator> = new Dictionary<number, VoiceGenerator>();
-    private staffMainVoiceGeneratorDict: Dictionary<Staff, VoiceGenerator> = new Dictionary<Staff, VoiceGenerator>();
-    private inSourceMeasureInstrumentIndex: number;
-    private divisions: number = 0;
-    private currentMeasure: SourceMeasure;
-    private previousMeasure: SourceMeasure;
-    private currentXmlMeasureIndex: number = 0;
-    private currentStaff: Staff;
-    private currentStaffEntry: SourceStaffEntry;
-    private activeClefs: ClefInstruction[];
-    private activeKey: KeyInstruction;
-    private activeRhythm: RhythmInstruction;
-    private activeClefsHaveBeenInitialized: boolean[];
-    private activeKeyHasBeenInitialized: boolean = false;
-    private abstractInstructions: List<KeyValuePairClass<number, AbstractNotationInstruction>> = new List<KeyValuePairClass<number, AbstractNotationInstruction>>();
-    private openChordSymbolContainer: ChordSymbolContainer;
-    private expressionReaders: ExpressionReader[];
-    private currentVoiceGenerator: VoiceGenerator;
-    private openSlurDict: Dictionary<number, Slur> = new Dictionary<number, Slur>();
-    private maxTieNoteFraction: Fraction;
-    public get ActiveKey(): KeyInstruction {
-        return this.activeKey;
+    createExpressionGenerators(instrument.Staves.Count);
+    this.slurReader = MusicSymbolModuleFactory.createSlurReader(this.musicSheet);
+  }
+  private repetitionInstructionReader: RepetitionInstructionReader;
+  private xmlMeasureList: IXmlElement[];
+  private musicSheet: MusicSheet;
+  private slurReader: SlurReader;
+  private instrument: Instrument;
+  private voiceGeneratorsDict: Dictionary<number, VoiceGenerator> = new Dictionary<number, VoiceGenerator>();
+  private staffMainVoiceGeneratorDict: Dictionary<Staff, VoiceGenerator> = new Dictionary<Staff, VoiceGenerator>();
+  private inSourceMeasureInstrumentIndex: number;
+  private divisions: number = 0;
+  private currentMeasure: SourceMeasure;
+  private previousMeasure: SourceMeasure;
+  private currentXmlMeasureIndex: number = 0;
+  private currentStaff: Staff;
+  private currentStaffEntry: SourceStaffEntry;
+  private activeClefs: ClefInstruction[];
+  private activeKey: KeyInstruction;
+  private activeRhythm: RhythmInstruction;
+  private activeClefsHaveBeenInitialized: boolean[];
+  private activeKeyHasBeenInitialized: boolean = false;
+  private abstractInstructions: List<KeyValuePairClass<number, AbstractNotationInstruction>> =
+    new List<KeyValuePairClass<number, AbstractNotationInstruction>>();
+  private openChordSymbolContainer: ChordSymbolContainer;
+  private expressionReaders: ExpressionReader[];
+  private currentVoiceGenerator: VoiceGenerator;
+  // private openSlurDict: Dictionary<number, Slur> = new Dictionary<number, Slur>();
+  private maxTieNoteFraction: Fraction;
+  public get ActiveKey(): KeyInstruction {
+    return this.activeKey;
+  }
+  public get MaxTieNoteFraction(): Fraction {
+    return this.maxTieNoteFraction;
+  }
+  public get ActiveRhythm(): RhythmInstruction {
+    return this.activeRhythm;
+  }
+  public set ActiveRhythm(value: RhythmInstruction) {
+    this.activeRhythm = value;
+  }
+  public readNextXmlMeasure(currentMeasure: SourceMeasure, measureStartAbsoluteTimestamp: Fraction, guitarPro: boolean): boolean {
+    if (this.currentXmlMeasureIndex >= this.xmlMeasureList.length) {
+      return false;
     }
-    public get MaxTieNoteFraction(): Fraction {
-        return this.maxTieNoteFraction;
+    this.currentMeasure = currentMeasure;
+    this.inSourceMeasureInstrumentIndex = this.musicSheet.getGlobalStaffIndexOfFirstStaff(this.instrument);
+    if (this.repetitionInstructionReader !== undefined) {
+      this.repetitionInstructionReader.prepareReadingMeasure(currentMeasure, this.currentXmlMeasureIndex);
     }
-    public get ActiveRhythm(): RhythmInstruction {
-        return this.activeRhythm;
-    }
-    public set ActiveRhythm(value: RhythmInstruction) {
-        this.activeRhythm = value;
-    }
-    public readNextXmlMeasure(currentMeasure: SourceMeasure, measureStartAbsoluteTimestamp: Fraction, guitarPro: boolean): boolean {
-        if (this.currentXmlMeasureIndex >= this.xmlMeasureList.length)
-            return false;
-        this.currentMeasure = currentMeasure;
-        this.inSourceMeasureInstrumentIndex = this.musicSheet.getGlobalStaffIndexOfFirstStaff(this.instrument);
-        if (this.repetitionInstructionReader != null)
-            this.repetitionInstructionReader.prepareReadingMeasure(currentMeasure, this.currentXmlMeasureIndex);
-        var currentFraction: Fraction = new Fraction(0, 1);
-        var previousFraction: Fraction = new Fraction(0, 1);
-        var divisionsException: boolean = false;
-        this.maxTieNoteFraction = new Fraction(0, 1);
-        var lastNoteWasGrace: boolean = false;
-        try {
-            var xmlMeasureListArr: IXmlElement[] = this.xmlMeasureList[this.currentXmlMeasureIndex].Elements().ToArray();
-            for (var idx: number = 0, len = xmlMeasureListArr.length; idx < len; ++idx) {
-                var xmlNode: IXmlElement = xmlMeasureListArr[idx];
-                if (xmlNode.Name == "note") {
-                    if ((xmlNode.HasAttributes && xmlNode.Attribute("print-object") != null && xmlNode.Attribute("print-spacing") != null)) {
-                        continue;
-                    }
-                    var noteStaff: number = 1;
-                    if (this.instrument.Staves.Count > 1) {
-                        try {
-                            if (xmlNode.Element("staff") != null)
-                                noteStaff = StringToNumberConverter.ToInteger(xmlNode.Element("staff").Value);
-                        }
-                        catch (ex) {
-                            Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readNextXmlMeasure.get staff number", ex);
-                            noteStaff = 1;
-                        }
+    let currentFraction: Fraction = new Fraction(0, 1);
+    let previousFraction: Fraction = new Fraction(0, 1);
+    let divisionsException: boolean = false;
+    this.maxTieNoteFraction = new Fraction(0, 1);
+    let lastNoteWasGrace: boolean = false;
+    try {
+      let xmlMeasureListArr: IXmlElement[] = this.xmlMeasureList[this.currentXmlMeasureIndex].Elements().ToArray();
+      for (let idx: number = 0, len: number = xmlMeasureListArr.length; idx < len; ++idx) {
+        let xmlNode: IXmlElement = xmlMeasureListArr[idx];
+        if (xmlNode.Name === "note") {
+          if ((xmlNode.HasAttributes && xmlNode.Attribute("print-object") !== undefined && xmlNode.Attribute("print-spacing") !== undefined)) {
+            continue;
+          }
+          let noteStaff: number = 1;
+          if (this.instrument.Staves.Count > 1) {
+            try {
+              if (xmlNode.Element("staff") !== undefined) {
+                noteStaff = StringToNumberConverter.ToInteger(xmlNode.Element("staff").Value);
+              }
+            } catch (ex) {
+              Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readNextXmlMeasure.get staff number", ex);
+              noteStaff = 1;
+            }
 
-                    }
-                    this.currentStaff = this.instrument.Staves[noteStaff - 1];
-                    var isChord: boolean = xmlNode.Element("chord") != null;
-                    if (xmlNode.Element("voice") != null) {
-                        var noteVoice: number = StringToNumberConverter.ToInteger(xmlNode.Element("voice").Value);
-                        this.currentVoiceGenerator = this.getOrCreateVoiceGenerator(noteVoice, noteStaff - 1);
-                    }
-                    else {
-                        if (!isChord || this.currentVoiceGenerator == null)
-                            this.currentVoiceGenerator = this.getOrCreateVoiceGenerator(1, noteStaff - 1);
-                    }
-                    var noteDivisions: number = 0;
-                    var noteDuration: Fraction = new Fraction(0, 1);
-                    var isTuplet: boolean = false;
-                    if (xmlNode.Element("duration") != null) {
-                        try {
-                            noteDivisions = StringToNumberConverter.ToInteger(xmlNode.Element("duration").Value);
-                            noteDuration = new Fraction(noteDivisions, 4 * this.divisions);
-                            if (noteDivisions == 0) {
-                                noteDuration = this.getNoteDurationFromTypeNode(xmlNode);
-                            }
-                            if (xmlNode.Element("time-modification") != null) {
-                                noteDuration = this.getNoteDurationForTuplet(xmlNode);
-                                isTuplet = true;
-                            }
-                        }
-                        catch (ex) {
-                            var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/NoteDurationError", "Invalid Note Duration.");
-                            this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                            Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readNextXmlMeasure", errorMsg, ex);
-                            continue;
-                        }
+          }
+          this.currentStaff = this.instrument.Staves[noteStaff - 1];
+          let isChord: boolean = xmlNode.Element("chord") !== undefined;
+          if (xmlNode.Element("voice") !== undefined) {
+            let noteVoice: number = StringToNumberConverter.ToInteger(xmlNode.Element("voice").Value);
+            this.currentVoiceGenerator = this.getOrCreateVoiceGenerator(noteVoice, noteStaff - 1);
+          } else {
+            if (!isChord || this.currentVoiceGenerator === undefined) {
+              this.currentVoiceGenerator = this.getOrCreateVoiceGenerator(1, noteStaff - 1);
+            }
+          }
+          let noteDivisions: number = 0;
+          let noteDuration: Fraction = new Fraction(0, 1);
+          let isTuplet: boolean = false;
+          if (xmlNode.Element("duration") !== undefined) {
+            try {
+              noteDivisions = StringToNumberConverter.ToInteger(xmlNode.Element("duration").Value);
+              noteDuration = new Fraction(noteDivisions, 4 * this.divisions);
+              if (noteDivisions === 0) {
+                noteDuration = this.getNoteDurationFromTypeNode(xmlNode);
+              }
+              if (xmlNode.Element("time-modification") !== undefined) {
+                noteDuration = this.getNoteDurationForTuplet(xmlNode);
+                isTuplet = true;
+              }
+            } catch (ex) {
+              let errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/NoteDurationError", "Invalid Note Duration.");
+              this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+              Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readNextXmlMeasure", errorMsg, ex);
+              continue;
+            }
 
-                    }
-                    var restNote: boolean = xmlNode.Element("rest") != null;
-                    var isGraceNote: boolean = xmlNode.Element("grace") != null || noteDivisions == 0 || isChord && lastNoteWasGrace;
-                    var musicTimestamp: Fraction = new Fraction(currentFraction);
-                    if (isChord)
-                        musicTimestamp = new Fraction(previousFraction);
-                    var newContainerCreated: boolean;
-                    this.currentStaffEntry = this.currentMeasure.findOrCreateStaffEntry(musicTimestamp,
-                        this.inSourceMeasureInstrumentIndex + noteStaff - 1, this.currentStaff, newContainerCreated);
-                    if (!this.currentVoiceGenerator.hasVoiceEntry() || !isChord && !isGraceNote && !lastNoteWasGrace || !lastNoteWasGrace && isGraceNote) {
-                        this.currentVoiceGenerator.createVoiceEntry(musicTimestamp, this.currentStaffEntry, !restNote);
-                    }
-                    if (!isGraceNote && !isChord) {
-                        previousFraction = new Fraction(currentFraction);
-                        currentFraction.Add(new Fraction(noteDuration));
-                    }
-                    if (isChord) {
-                        if (this.currentStaffEntry != null && this.currentStaffEntry.ParentStaff != this.currentStaff)
-                            this.currentStaffEntry = this.currentVoiceGenerator.checkForStaffEntryLink(this.inSourceMeasureInstrumentIndex + noteStaff - 1, this.currentStaff, this.currentStaffEntry, this.currentMeasure);
-                    }
-                    var beginOfMeasure: boolean = (this.currentStaffEntry != null && this.currentStaffEntry.Timestamp != null && this.currentStaffEntry.Timestamp == new Fraction(0, 1) && !this.currentStaffEntry.hasNotes());
-                    saveAbstractInstructionList(this.instrument.Staves.Count, beginOfMeasure);
-                    if (this.openChordSymbolContainer != null) {
-                        this.currentStaffEntry.ChordContainer = this.openChordSymbolContainer;
-                        this.openChordSymbolContainer = null;
-                    }
-                    if (this.activeRhythm != null)
-                        this.musicSheet.SheetPlaybackSetting.Rhythm = this.activeRhythm.Rhythm;
-                    if (isTuplet)
-                        this.currentVoiceGenerator.read(xmlNode, noteDuration.Numerator, noteDuration.Denominator,
-                            restNote, isGraceNote, this.currentStaffEntry, this.currentMeasure,
-                            measureStartAbsoluteTimestamp, this.maxTieNoteFraction, isChord, guitarPro);
-                    else this.currentVoiceGenerator.read(xmlNode, noteDivisions, 4 * this.divisions, restNote, isGraceNote,
-                        this.currentStaffEntry, this.currentMeasure, measureStartAbsoluteTimestamp,
-                        this.maxTieNoteFraction, isChord, guitarPro);
-                    var notationsNode: IXmlElement = xmlNode.Element("notations");
-                    if (notationsNode != null && notationsNode.Element("dynamics") != null) {
-                        var expressionReader: ExpressionReader = this.expressionReaders[this.readExpressionStaffNumber(xmlNode) - 1];
-                        if (expressionReader != null) {
-                            expressionReader.readExpressionParameters(xmlNode, this.instrument, this.divisions, currentFraction, previousFraction, this.currentMeasure.MeasureNumber, false);
-                            expressionReader.read(xmlNode, this.currentMeasure, previousFraction);
-                        }
-                    }
-                    lastNoteWasGrace = isGraceNote;
-                }
-                else if (xmlNode.Name == "attributes") {
-                    var divisionsNode: IXmlElement = xmlNode.Element("divisions");
-                    if (divisionsNode != null) {
-                        try {
-                            this.divisions = StringToNumberConverter.ToInteger(divisionsNode.Value);
-                        }
-                        catch (e) {
-                            var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/DivisionError", "Invalid divisions value at Instrument: ");
-                            Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readNextXmlMeasure", errorMsg, e);
-                            this.divisions = this.readDivisionsFromNotes();
-                            if (this.divisions > 0)
-                                this.musicSheet.SheetErrors.Errors.Add(errorMsg + this.instrument.Name);
-                            else {
-                                divisionsException = true;
-                                throw new MusicSheetReadingException(errorMsg + this.instrument.Name, 0);
-                            }
-                        }
+          }
+          let restNote: boolean = xmlNode.Element("rest") !== undefined;
+          let isGraceNote: boolean = xmlNode.Element("grace") !== undefined || noteDivisions === 0 || isChord && lastNoteWasGrace;
+          let musicTimestamp: Fraction = new Fraction(currentFraction);
+          if (isChord) {
+            musicTimestamp = new Fraction(previousFraction);
+          }
+          let newContainerCreated: boolean;
+          this.currentStaffEntry = this.currentMeasure.findOrCreateStaffEntry(
+            musicTimestamp,
+            this.inSourceMeasureInstrumentIndex + noteStaff - 1,
+            this.currentStaff,
+            newContainerCreated,
+          );
+          if (!this.currentVoiceGenerator.hasVoiceEntry() || !isChord && !isGraceNote && !lastNoteWasGrace || !lastNoteWasGrace && isGraceNote) {
+            this.currentVoiceGenerator.createVoiceEntry(musicTimestamp, this.currentStaffEntry, !restNote);
+          }
+          if (!isGraceNote && !isChord) {
+            previousFraction = new Fraction(currentFraction);
+            currentFraction.Add(new Fraction(noteDuration));
+          }
+          if (
+            isChord &&
+            this.currentStaffEntry !== undefined &&
+            this.currentStaffEntry.ParentStaff !== this.currentStaff
+          ) {
+            this.currentStaffEntry = this.currentVoiceGenerator.checkForStaffEntryLink(
+              this.inSourceMeasureInstrumentIndex + noteStaff - 1, this.currentStaff, this.currentStaffEntry, this.currentMeasure
+            );
+          }
+          let beginOfMeasure: boolean = (
+            this.currentStaffEntry !== undefined &&
+            this.currentStaffEntry.Timestamp !== undefined &&
+            this.currentStaffEntry.Timestamp === new Fraction(0, 1) &&
+            !this.currentStaffEntry.hasNotes()
+          );
+          saveAbstractInstructionList(this.instrument.Staves.Count, beginOfMeasure);
+          if (this.openChordSymbolContainer !== undefined) {
+            this.currentStaffEntry.ChordContainer = this.openChordSymbolContainer;
+            this.openChordSymbolContainer = undefined;
+          }
+          if (this.activeRhythm !== undefined) {
+            this.musicSheet.SheetPlaybackSetting.Rhythm = this.activeRhythm.Rhythm;
+          }
+          if (isTuplet) {
+            this.currentVoiceGenerator.read(
+              xmlNode, noteDuration.Numerator,
+              noteDuration.Denominator, restNote, isGraceNote,
+              this.currentStaffEntry, this.currentMeasure,
+              measureStartAbsoluteTimestamp,
+              this.maxTieNoteFraction, isChord, guitarPro
+            );
+          } else {
+            this.currentVoiceGenerator.read(
+            xmlNode, noteDivisions, 4 * this.divisions,
+            restNote, isGraceNote, this.currentStaffEntry,
+            this.currentMeasure, measureStartAbsoluteTimestamp,
+            this.maxTieNoteFraction, isChord, guitarPro
+            );
+          }
+          let notationsNode: IXmlElement = xmlNode.Element("notations");
+          if (notationsNode !== undefined && notationsNode.Element("dynamics") !== undefined) {
+            let expressionReader: ExpressionReader = this.expressionReaders[this.readExpressionStaffNumber(xmlNode) - 1];
+            if (expressionReader !== undefined) {
+              expressionReader.readExpressionParameters(
+                xmlNode, this.instrument, this.divisions, currentFraction, previousFraction, this.currentMeasure.MeasureNumber, false
+              );
+              expressionReader.read(
+                xmlNode, this.currentMeasure, previousFraction
+              );
+            }
+          }
+          lastNoteWasGrace = isGraceNote;
+        } else if (xmlNode.Name === "attributes") {
+          let divisionsNode: IXmlElement = xmlNode.Element("divisions");
+          if (divisionsNode !== undefined) {
+            try {
+              this.divisions = StringToNumberConverter.ToInteger(divisionsNode.Value);
+            } catch (e) {
+              let errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/DivisionError", "Invalid divisions value at Instrument: ");
+              Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readNextXmlMeasure", errorMsg, e);
+              this.divisions = this.readDivisionsFromNotes();
+              if (this.divisions > 0) {
+                this.musicSheet.SheetErrors.Errors.Add(errorMsg + this.instrument.Name);
+              } else {
+                divisionsException = true;
+                throw new MusicSheetReadingException(errorMsg + this.instrument.Name, 0);
+              }
+            }
 
-                    }
-                    if (xmlNode.Element("divisions") == null && this.divisions == 0 && this.currentXmlMeasureIndex == 0) {
-                        var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/DivisionError", "Invalid divisions value at Instrument: ");
-                        this.divisions = this.readDivisionsFromNotes();
-                        if (this.divisions > 0)
-                            this.musicSheet.SheetErrors.Errors.Add(errorMsg + this.instrument.Name);
-                        else {
-                            divisionsException = true;
-                            throw new MusicSheetReadingException(errorMsg + this.instrument.Name, 0);
-                        }
-                    }
-                    this.addAbstractInstruction(xmlNode, guitarPro);
-                    if (currentFraction == new Fraction(0, 1) && this.isAttributesNodeAtBeginOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex], xmlNode))
-                        saveAbstractInstructionList(this.instrument.Staves.Count, true);
-                    if (this.isAttributesNodeAtEndOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex], xmlNode))
-                        this.saveClefInstructionAtEndOfMeasure();
-                }
-                else if (xmlNode.Name == "forward") {
-                    var forFraction: number = StringToNumberConverter.ToInteger(xmlNode.Element("duration").Value);
-                    currentFraction.Add(new Fraction(forFraction, 4 * this.divisions));
-                }
-                else if (xmlNode.Name == "backup") {
-                    var backFraction: number = StringToNumberConverter.ToInteger(xmlNode.Element("duration").Value);
-                    currentFraction.Sub(new Fraction(backFraction, 4 * this.divisions));
-                    if (currentFraction.Numerator < 0)
-                        currentFraction = new Fraction(0, 1);
-                    previousFraction.Sub(new Fraction(backFraction, 4 * this.divisions));
-                    if (previousFraction.Numerator < 0)
-                        previousFraction = new Fraction(0, 1);
-                }
-                else if (xmlNode.Name == "direction") {
-                    var directionTypeNode: IXmlElement = xmlNode.Element("direction-type");
-                    MetronomeReader.readMetronomeInstructions(xmlNode, this.musicSheet, this.currentXmlMeasureIndex);
-                    var relativePositionInMeasure: number = Math.Min(1, currentFraction.RealValue);
-                    if (this.activeRhythm != null && this.activeRhythm.Rhythm != null)
-                        relativePositionInMeasure /= this.activeRhythm.Rhythm.RealValue;
-                    var handeled: boolean = false;
-                    if (this.repetitionInstructionReader != null)
-                        handeled = this.repetitionInstructionReader.handleRepetitionInstructionsFromWordsOrSymbols(directionTypeNode, relativePositionInMeasure);
-                    if (!handeled) {
-                        var expressionReader: ExpressionReader = this.expressionReaders[0];
-                        var staffIndex: number = this.readExpressionStaffNumber(xmlNode) - 1;
-                        if (staffIndex < this.expressionReaders.Count())
-                            expressionReader = this.expressionReaders[staffIndex];
-                        if (expressionReader != null) {
-                            if (directionTypeNode.Element("octave-shift") != null) {
-                                expressionReader.readExpressionParameters(xmlNode, this.instrument, this.divisions, currentFraction, previousFraction, this.currentMeasure.MeasureNumber, true);
-                                expressionReader.addOctaveShift(xmlNode, this.currentMeasure, new Fraction(previousFraction));
-                            }
-                            expressionReader.readExpressionParameters(xmlNode, this.instrument, this.divisions, currentFraction, previousFraction, this.currentMeasure.MeasureNumber, false);
-                            expressionReader.read(xmlNode, this.currentMeasure, currentFraction);
-                        }
-                    }
-                }
-                else if (xmlNode.Name == "barline") {
-                    if (this.repetitionInstructionReader != null) {
-                        var measureEndsSystem: boolean = false;
-                        this.repetitionInstructionReader.handleLineRepetitionInstructions(xmlNode, measureEndsSystem);
-                        if (measureEndsSystem) {
-                            this.currentMeasure.BreakSystemAfter = true;
-                            this.currentMeasure.EndsPiece = true;
-                        }
-                    }
-                }
-                else if (xmlNode.Name == "sound") {
-                    MetronomeReader.readTempoInstruction(xmlNode, this.musicSheet, this.currentXmlMeasureIndex);
-                }
-                else if (xmlNode.Name == "harmony") {
-                    this.openChordSymbolContainer = ChordSymbolReader.readChordSymbol(xmlNode, this.musicSheet, this.activeKey);
-                }
+          }
+          if (
+            xmlNode.Element("divisions") === undefined &&
+            this.divisions === 0 &&
+            this.currentXmlMeasureIndex === 0
+          ) {
+            let errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/DivisionError", "Invalid divisions value at Instrument: ");
+            this.divisions = this.readDivisionsFromNotes();
+            if (this.divisions > 0) {
+              this.musicSheet.SheetErrors.Errors.Add(errorMsg + this.instrument.Name);
+            } else {
+              divisionsException = true;
+              throw new MusicSheetReadingException(errorMsg + this.instrument.Name, 0);
             }
-            for (var j: number = 0; j < this.voiceGeneratorsDict.Count; j++) {
-                var keyValuePair: KeyValuePair<number, VoiceGenerator> = this.voiceGeneratorsDict.ElementAt(j);
-                var voiceGenerator: VoiceGenerator = keyValuePair.Value;
-                voiceGenerator.checkForOpenBeam();
-                voiceGenerator.checkForOpenGraceNotes();
+          }
+          this.addAbstractInstruction(xmlNode, guitarPro);
+          if (currentFraction === new Fraction(0, 1) && this.isAttributesNodeAtBeginOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex], xmlNode)) {
+            saveAbstractInstructionList(this.instrument.Staves.Count, true);
+          }
+          if (this.isAttributesNodeAtEndOfMeasure(this.xmlMeasureList[this.currentXmlMeasureIndex], xmlNode)) {
+            this.saveClefInstructionAtEndOfMeasure();
+          }
+        } else if (xmlNode.Name === "forward") {
+          let forFraction: number = StringToNumberConverter.ToInteger(xmlNode.Element("duration").Value);
+          currentFraction.Add(new Fraction(forFraction, 4 * this.divisions));
+        } else if (xmlNode.Name === "backup") {
+          let backFraction: number = StringToNumberConverter.ToInteger(xmlNode.Element("duration").Value);
+          currentFraction.Sub(new Fraction(backFraction, 4 * this.divisions));
+          if (currentFraction.Numerator < 0) {
+            currentFraction = new Fraction(0, 1);
+          }
+          previousFraction.Sub(new Fraction(backFraction, 4 * this.divisions));
+          if (previousFraction.Numerator < 0) {
+            previousFraction = new Fraction(0, 1);
+          }
+        } else if (xmlNode.Name === "direction") {
+          let directionTypeNode: IXmlElement = xmlNode.Element("direction-type");
+          MetronomeReader.readMetronomeInstructions(xmlNode, this.musicSheet, this.currentXmlMeasureIndex);
+          let relativePositionInMeasure: number = Math.Min(1, currentFraction.RealValue);
+          if (this.activeRhythm !== undefined && this.activeRhythm.Rhythm !== undefined) {
+            relativePositionInMeasure /= this.activeRhythm.Rhythm.RealValue;
+          }
+          let handeled: boolean = false;
+          if (this.repetitionInstructionReader !== undefined) {
+            handeled = this.repetitionInstructionReader.handleRepetitionInstructionsFromWordsOrSymbols(directionTypeNode, relativePositionInMeasure);
+          }
+          if (!handeled) {
+            let expressionReader: ExpressionReader = this.expressionReaders[0];
+            let staffIndex: number = this.readExpressionStaffNumber(xmlNode) - 1;
+            if (staffIndex < this.expressionReaders.Count()) {
+              expressionReader = this.expressionReaders[staffIndex];
             }
-            if (this.currentXmlMeasureIndex == this.xmlMeasureList.length - 1) {
-                for (var i: number = 0; i < this.instrument.Staves.Count; i++)
-                    if (!this.activeClefsHaveBeenInitialized[i])
-                        createDefaultClefInstruction(this.musicSheet.getGlobalStaffIndexOfFirstStaff(this.instrument) + i);
-                if (!this.activeKeyHasBeenInitialized)
-                    this.createDefaultKeyInstruction();
-                for (var i: number = 0; i < this.expressionReaders.length; i++) {
-                    var reader: ExpressionReader = this.expressionReaders[i];
-                    if (reader != null)
-                        reader.checkForOpenExpressions(this.currentMeasure, currentFraction);
-                }
+            if (expressionReader !== undefined) {
+              if (directionTypeNode.Element("octave-shift") !== undefined) {
+                expressionReader.readExpressionParameters(
+                  xmlNode, this.instrument, this.divisions, currentFraction, previousFraction, this.currentMeasure.MeasureNumber, true
+                );
+                expressionReader.addOctaveShift(xmlNode, this.currentMeasure, new Fraction(previousFraction));
+              }
+              expressionReader.readExpressionParameters(
+                xmlNode, this.instrument, this.divisions, currentFraction, previousFraction, this.currentMeasure.MeasureNumber, false
+              );
+              expressionReader.read(xmlNode, this.currentMeasure, currentFraction);
             }
-        }
-        catch (e) {
-            if (divisionsException) {
-                throw new MusicSheetReadingException(e.Message, e, 0);
+          }
+        } else if (xmlNode.Name === "barline") {
+          if (this.repetitionInstructionReader !== undefined) {
+            let measureEndsSystem: boolean = false;
+            this.repetitionInstructionReader.handleLineRepetitionInstructions(xmlNode, measureEndsSystem);
+            if (measureEndsSystem) {
+              this.currentMeasure.BreakSystemAfter = true;
+              this.currentMeasure.EndsPiece = true;
             }
-            var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/MeasureError", "Error while reading Measure.");
-            this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-            Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readNextXmlMeasure", errorMsg, e);
+          }
+        } else if (xmlNode.Name === "sound") {
+          MetronomeReader.readTempoInstruction(xmlNode, this.musicSheet, this.currentXmlMeasureIndex);
+        } else if (xmlNode.Name === "harmony") {
+          this.openChordSymbolContainer = ChordSymbolReader.readChordSymbol(xmlNode, this.musicSheet, this.activeKey);
         }
+      }
+      for (let j: number = 0; j < this.voiceGeneratorsDict.Count; j++) {
+        let keyValuePair: KeyValuePair<number, VoiceGenerator> = this.voiceGeneratorsDict.ElementAt(j);
+        let voiceGenerator: VoiceGenerator = keyValuePair.Value;
+        voiceGenerator.checkForOpenBeam();
+        voiceGenerator.checkForOpenGraceNotes();
+      }
+      if (this.currentXmlMeasureIndex === this.xmlMeasureList.length - 1) {
+        for (let i: number = 0; i < this.instrument.Staves.Count; i++) {
+          if (!this.activeClefsHaveBeenInitialized[i]) {
+            createDefaultClefInstruction(this.musicSheet.getGlobalStaffIndexOfFirstStaff(this.instrument) + i);
+        }}
+        if (!this.activeKeyHasBeenInitialized) {
+          this.createDefaultKeyInstruction();
+        }
+        for (let i: number = 0; i < this.expressionReaders.length; i++) {
+          let reader: ExpressionReader = this.expressionReaders[i];
+          if (reader !== undefined) {
+            reader.checkForOpenExpressions(this.currentMeasure, currentFraction);
+          }
+        }
+      }
+    } catch (e) {
+      if (divisionsException) {
+        throw new MusicSheetReadingException(e.Message, e, 0);
+      }
+      let errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/MeasureError", "Error while reading Measure.");
+      this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+      Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readNextXmlMeasure", errorMsg, e);
+    }
 
-        this.previousMeasure = this.currentMeasure;
-        this.currentXmlMeasureIndex++;
-        return true;
+    this.previousMeasure = this.currentMeasure;
+    this.currentXmlMeasureIndex++;
+    return true;
+  }
+  public doCalculationsAfterDurationHasBeenSet(): void {
+    for (let j: number = 0; j < this.voiceGeneratorsDict.Count; j++) {
+      let keyValuePair: KeyValuePair<number, VoiceGenerator> = this.voiceGeneratorsDict.ElementAt(j);
+      let voiceGenerator: VoiceGenerator = keyValuePair.Value;
+      voiceGenerator.checkOpenTies();
     }
-    public doCalculationsAfterDurationHasBeenSet(): void {
-        for (var j: number = 0; j < this.voiceGeneratorsDict.Count; j++) {
-            var keyValuePair: KeyValuePair<number, VoiceGenerator> = this.voiceGeneratorsDict.ElementAt(j);
-            var voiceGenerator: VoiceGenerator = keyValuePair.Value;
-            voiceGenerator.checkOpenTies();
-        }
+  }
+  private getOrCreateVoiceGenerator(voiceId: number, staffId: number): VoiceGenerator {
+    let voiceGenerator: VoiceGenerator;
+    let staff: Staff = this.instrument.Staves[staffId];
+    if (this.voiceGeneratorsDict.ContainsKey(voiceId)) {
+      voiceGenerator = this.voiceGeneratorsDict[voiceId];
+      if (!staff.Voices.Contains(voiceGenerator.GetVoice)) {
+        staff.Voices.Add(voiceGenerator.GetVoice);
+      }
+      return voiceGenerator;
+    } else {
+      if (this.staffMainVoiceGeneratorDict.ContainsKey(staff)) {
+        let mainVoiceGenerator: VoiceGenerator = this.staffMainVoiceGeneratorDict[staff];
+        voiceGenerator = new VoiceGenerator(this.instrument, voiceId, this.slurReader, mainVoiceGenerator.GetVoice);
+        staff.Voices.Add(voiceGenerator.GetVoice);
+        this.voiceGeneratorsDict.Add(voiceId, voiceGenerator);
+        return voiceGenerator;
+      }
+      voiceGenerator = new VoiceGenerator(this.instrument, voiceId, this.slurReader);
+      staff.Voices.Add(voiceGenerator.GetVoice);
+      this.voiceGeneratorsDict.Add(voiceId, voiceGenerator);
+      this.staffMainVoiceGeneratorDict.Add(staff, voiceGenerator);
+      return voiceGenerator;
     }
-    private getOrCreateVoiceGenerator(voiceId: number, staffId: number): VoiceGenerator {
-        var voiceGenerator: VoiceGenerator;
-        var staff: Staff = this.instrument.Staves[staffId];
-        if (this.voiceGeneratorsDict.ContainsKey(voiceId)) {
-            voiceGenerator = this.voiceGeneratorsDict[voiceId];
-            if (!staff.Voices.Contains(voiceGenerator.GetVoice))
-                staff.Voices.Add(voiceGenerator.GetVoice);
-            return voiceGenerator;
-        }
-        else {
-            if (this.staffMainVoiceGeneratorDict.ContainsKey(staff)) {
-                var mainVoiceGenerator: VoiceGenerator = this.staffMainVoiceGeneratorDict[staff];
-                voiceGenerator = new VoiceGenerator(this.instrument, voiceId, this.slurReader, mainVoiceGenerator.GetVoice);
-                staff.Voices.Add(voiceGenerator.GetVoice);
-                this.voiceGeneratorsDict.Add(voiceId, voiceGenerator);
-                return voiceGenerator;
-            }
-            voiceGenerator = new VoiceGenerator(this.instrument, voiceId, this.slurReader);
-            staff.Voices.Add(voiceGenerator.GetVoice);
-            this.voiceGeneratorsDict.Add(voiceId, voiceGenerator);
-            this.staffMainVoiceGeneratorDict.Add(staff, voiceGenerator);
-            return voiceGenerator;
-        }
+  }
+
+/*
+  private createExpressionGenerators(numberOfStaves: number): void {
+    this.expressionReaders = new Array(numberOfStaves);
+    for (let i: number = 0; i < numberOfStaves; i++)
+      this.expressionReaders[i] = MusicSymbolModuleFactory.createExpressionGenerator(this.musicSheet, this.instrument, i + 1);
+  }
+
+
+  private createDefaultClefInstruction(staffIndex: number): void {
+    let first: SourceMeasure;
+    if (this.musicSheet.SourceMeasures.Count > 0) {
+      first = this.musicSheet.SourceMeasures[0];
+    } else {
+      first = this.currentMeasure;
     }
-    private createExpressionGenerators(numberOfStaves: number): void {
-        this.expressionReaders = new Array(numberOfStaves);
-        for (var i: number = 0; i < numberOfStaves; i++)
-            this.expressionReaders[i] = MusicSymbolModuleFactory.createExpressionGenerator(this.musicSheet, this.instrument, i + 1);
+    let clefInstruction: ClefInstruction = new ClefInstruction(ClefEnum.G, 0, 2);
+    let firstStaffEntry: SourceStaffEntry;
+    if (first.FirstInstructionsStaffEntries[staffIndex] === undefined) {
+      firstStaffEntry = new SourceStaffEntry(undefined, undefined);
+      first.FirstInstructionsStaffEntries[staffIndex] = firstStaffEntry;
+    } else {
+      firstStaffEntry = first.FirstInstructionsStaffEntries[staffIndex];
+      firstStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
     }
-    private createDefaultClefInstruction(staffIndex: number): void {
-        var first: SourceMeasure;
-        if (this.musicSheet.SourceMeasures.Count > 0)
-            first = this.musicSheet.SourceMeasures[0];
-        else first = this.currentMeasure;
-        var clefInstruction: ClefInstruction = new ClefInstruction(ClefEnum.G, 0, 2);
-        var firstStaffEntry: SourceStaffEntry;
-        if (first.FirstInstructionsStaffEntries[staffIndex] == null) {
-            firstStaffEntry = new SourceStaffEntry(null, null);
-            first.FirstInstructionsStaffEntries[staffIndex] = firstStaffEntry;
-        }
-        else {
-            firstStaffEntry = first.FirstInstructionsStaffEntries[staffIndex];
-            firstStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
-        }
-        clefInstruction.Parent = firstStaffEntry;
-        firstStaffEntry.Instructions.Insert(0, clefInstruction);
+    clefInstruction.Parent = firstStaffEntry;
+    firstStaffEntry.Instructions.Insert(0, clefInstruction);
+  }
+*/
+  private createDefaultKeyInstruction(): void {
+    let first: SourceMeasure;
+    if (this.musicSheet.SourceMeasures.Count > 0) {
+      first = this.musicSheet.SourceMeasures[0];
+    } else {
+      first = this.currentMeasure;
     }
-    private createDefaultKeyInstruction(): void {
-        var first: SourceMeasure;
-        if (this.musicSheet.SourceMeasures.Count > 0)
-            first = this.musicSheet.SourceMeasures[0];
-        else first = this.currentMeasure;
-        var keyInstruction: KeyInstruction = new KeyInstruction(0, KeyEnum.major);
-        for (var j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + this.instrument.Staves.Count; j++) {
-            if (first.FirstInstructionsStaffEntries[j] == null) {
-                var firstStaffEntry: SourceStaffEntry = new SourceStaffEntry(null, null);
-                first.FirstInstructionsStaffEntries[j] = firstStaffEntry;
-                keyInstruction.Parent = firstStaffEntry;
-                firstStaffEntry.Instructions.Add(keyInstruction);
-            }
-            else {
-                var firstStaffEntry: SourceStaffEntry = first.FirstInstructionsStaffEntries[j];
-                keyInstruction.Parent = firstStaffEntry;
-                firstStaffEntry.removeFirstInstructionOfType<KeyInstruction>();
-                if (firstStaffEntry.Instructions[0] instanceof ClefInstruction)
-                    firstStaffEntry.Instructions.Insert(1, keyInstruction);
-                else firstStaffEntry.Instructions.Insert(0, keyInstruction);
-            }
+    let keyInstruction: KeyInstruction = new KeyInstruction(0, KeyEnum.major);
+    for (let j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + this.instrument.Staves.Count; j++) {
+      if (first.FirstInstructionsStaffEntries[j] === undefined) {
+        let firstStaffEntry: SourceStaffEntry = new SourceStaffEntry(undefined, undefined);
+        first.FirstInstructionsStaffEntries[j] = firstStaffEntry;
+        keyInstruction.Parent = firstStaffEntry;
+        firstStaffEntry.Instructions.Add(keyInstruction);
+      } else {
+        let firstStaffEntry: SourceStaffEntry = first.FirstInstructionsStaffEntries[j];
+        keyInstruction.Parent = firstStaffEntry;
+        firstStaffEntry.removeFirstInstructionOfType<KeyInstruction>();
+        if (firstStaffEntry.Instructions[0] instanceof ClefInstruction) {
+          firstStaffEntry.Instructions.Insert(1, keyInstruction);
+        } else {
+          firstStaffEntry.Instructions.Insert(0, keyInstruction);
         }
+      }
     }
-    private isAttributesNodeAtBeginOfMeasure(parentNode: IXmlElement, attributesNode: IXmlElement): boolean {
-        var childs: IXmlElement[] = parentNode.Elements().ToArray();
-        var attributesNodeIndex: number = 0;
-        for (var i: number = 0; i < childs.length; i++) {
-            if (childs[i] == attributesNode) {
-                attributesNodeIndex = i;
-                break;
-            }
-        }
-        if (attributesNodeIndex > 0 && childs[attributesNodeIndex - 1].Name == "backup")
-            return true;
-        var firstNoteNodeIndex: number = -1;
-        for (var i: number = 0; i < childs.length; i++) {
-            if (childs[i].Name == "note") {
-                firstNoteNodeIndex = i;
-                break;
-            }
-        }
-        if ((attributesNodeIndex < firstNoteNodeIndex && firstNoteNodeIndex > 0) || (firstNoteNodeIndex < 0))
-            return true;
-        return false;
+  }
+  private isAttributesNodeAtBeginOfMeasure(parentNode: IXmlElement, attributesNode: IXmlElement): boolean {
+    let childs: IXmlElement[] = parentNode.Elements().ToArray();
+    let attributesNodeIndex: number = 0;
+    for (let i: number = 0; i < childs.length; i++) {
+      if (childs[i] === attributesNode) {
+        attributesNodeIndex = i;
+        break;
+      }
     }
-    private isAttributesNodeAtEndOfMeasure(parentNode: IXmlElement, attributesNode: IXmlElement): boolean {
-        var childs: IXmlElement[] = parentNode.Elements().ToArray();
-        var attributesNodeIndex: number = 0;
-        for (var i: number = 0; i < childs.length; i++) {
-            if (childs[i] == attributesNode) {
-                attributesNodeIndex = i;
-                break;
-            }
-        }
-        var nextNoteNodeIndex: number = 0;
-        for (var i: number = attributesNodeIndex; i < childs.length; i++) {
-            if (childs[i].Name == "note") {
-                nextNoteNodeIndex = i;
-                break;
-            }
-        }
-        if (attributesNodeIndex > nextNoteNodeIndex)
-            return true;
-        return false;
+    if (attributesNodeIndex > 0 && childs[attributesNodeIndex - 1].Name === "backup") {
+      return true;
     }
-    private getNoteDurationFromTypeNode(xmlNode: IXmlElement): Fraction {
-        if (xmlNode.Element("type") != null) {
-            var typeNode: IXmlElement = xmlNode.Element("type");
-            if (typeNode != null) {
-                var type: string = typeNode.Value;
-                return this.currentVoiceGenerator.getNoteDurationFromType(type);
-            }
-        }
-        return new Fraction(0, 4 * this.divisions);
+    let firstNoteNodeIndex: number = -1;
+    for (let i: number = 0; i < childs.length; i++) {
+      if (childs[i].Name === "note") {
+        firstNoteNodeIndex = i;
+        break;
+      }
+    }
+    return (attributesNodeIndex < firstNoteNodeIndex && firstNoteNodeIndex > 0) || (firstNoteNodeIndex < 0);
+  }
+  private isAttributesNodeAtEndOfMeasure(parentNode: IXmlElement, attributesNode: IXmlElement): boolean {
+    let childs: IXmlElement[] = parentNode.Elements().ToArray();
+    let attributesNodeIndex: number = 0;
+    for (let i: number = 0; i < childs.length; i++) {
+      if (childs[i] === attributesNode) {
+        attributesNodeIndex = i;
+        break;
+      }
     }
-    private addAbstractInstruction(node: IXmlElement, guitarPro: boolean): void {
-        if (node.Element("divisions") != null) {
-            if (node.Elements().Count() == 1)
-                return
+    let nextNoteNodeIndex: number = 0;
+    for (let i: number = attributesNodeIndex; i < childs.length; i++) {
+      if (childs[i].Name === "note") {
+        nextNoteNodeIndex = i;
+        break;
+      }
+    }
+    return attributesNodeIndex > nextNoteNodeIndex;
+  }
+  private getNoteDurationFromTypeNode(xmlNode: IXmlElement): Fraction {
+    if (xmlNode.Element("type") !== undefined) {
+      let typeNode: IXmlElement = xmlNode.Element("type");
+      if (typeNode !== undefined) {
+        let type: string = typeNode.Value;
+        return this.currentVoiceGenerator.getNoteDurationFromType(type);
+      }
+    }
+    return new Fraction(0, 4 * this.divisions);
+  }
+  private addAbstractInstruction(node: IXmlElement, guitarPro: boolean): void {
+    if (node.Element("divisions") !== undefined) {
+      if (node.Elements().Count() === 1) { return; }
+    }
+    let transposeNode: IXmlElement = node.Element("transpose");
+    if (transposeNode !== undefined) {
+      let chromaticNode: IXmlElement = transposeNode.Element("chromatic");
+      if (chromaticNode !== undefined) {
+        this.instrument.PlaybackTranspose = StringToNumberConverter.ToInteger(chromaticNode.Value);
+      }
+    }
+    let clefList: IXmlElement[] = node.Elements("clef").ToArray();
+    if (clefList.length > 0) {
+      for (let idx: number = 0, len: number = clefList.Count(); idx < len; ++idx) {
+        let nodeList: IXmlElement = clefList[idx];
+        let clefEnum: ClefEnum = ClefEnum.G;
+        let line: number = 2;
+        let staffNumber: number = 1;
+        let clefOctaveOffset: number = 0;
+        let lineNode: IXmlElement = nodeList.Element("line");
+        let errorMsg: string;
+        if (lineNode !== undefined) {
+          try {
+            line = StringToNumberConverter.ToInteger(lineNode.Value);
+          } catch (ex) {
+            errorMsg = ITextTranslation.translateText(
+              "ReaderErrorMessages/ClefLineError",
+              "Invalid clef line given -> using default clef line."
+            );
+            this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+            line = 2;
+            Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, ex);
+          }
+
         }
-        var transposeNode: IXmlElement = node.Element("transpose");
-        if (transposeNode != null) {
-            var chromaticNode: IXmlElement = transposeNode.Element("chromatic");
-            if (chromaticNode != null)
-                this.instrument.PlaybackTranspose = StringToNumberConverter.ToInteger(chromaticNode.Value);
+        let signNode: IXmlElement = nodeList.Element("sign");
+        if (signNode !== undefined) {
+          try {
+            clefEnum = <ClefEnum>Enum.Parse(/*typeof*/ClefEnum, signNode.Value);
+            if (!ClefInstruction.isSupportedClef(clefEnum)) {
+              if (clefEnum === ClefEnum.TAB && guitarPro) {
+                clefOctaveOffset = -1;
+              }
+              errorMsg = ITextTranslation.translateText(
+                "ReaderErrorMessages/ClefError",
+                "Unsupported clef found -> using default clef."
+              );
+              this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+              clefEnum = ClefEnum.G;
+              line = 2;
+            }
+          } catch (e) {
+            errorMsg = ITextTranslation.translateText(
+              "ReaderErrorMessages/ClefError",
+              "Invalid clef found -> using default clef."
+            );
+            this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+            clefEnum = ClefEnum.G;
+            line = 2;
+            Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, e);
+          }
+
         }
-        var clefList: IXmlElement[] = node.Elements("clef").ToArray();
-        if (clefList.length > 0) {
-            for (var idx: number = 0, len = clefList.Count(); idx < len; ++idx) {
-                var nodeList: IXmlElement = clefList[idx];
-                var clefEnum: ClefEnum = ClefEnum.G;
-                var line: number = 2;
-                var staffNumber: number = 1;
-                var clefOctaveOffset: number = 0;
-                var lineNode: IXmlElement = nodeList.Element("line");
-                if (lineNode != null) {
-                    try {
-                        line = StringToNumberConverter.ToInteger(lineNode.Value);
-                    }
-                    catch (ex) {
-                        var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ClefLineError",
-                            "Invalid clef line given -> using default clef line.");
-                        this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                        line = 2;
-                        Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, ex);
-                    }
+        let clefOctaveNode: IXmlElement = nodeList.Element("clef-octave-change");
+        if (clefOctaveNode !== undefined) {
+          try {
+            clefOctaveOffset = StringToNumberConverter.ToInteger(clefOctaveNode.Value);
+          } catch (e) {
+            errorMsg = ITextTranslation.translateText(
+              "ReaderErrorMessages/ClefOctaveError",
+              "Invalid clef octave found -> using default clef octave."
+            );
+            this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+            clefOctaveOffset = 0;
+          }
 
-                }
-                var signNode: IXmlElement = nodeList.Element("sign");
-                if (signNode != null) {
-                    try {
-                        clefEnum = <ClefEnum>Enum.Parse(/*typeof*/ClefEnum, signNode.Value);
-                        if (!ClefInstruction.isSupportedClef(clefEnum)) {
-                            if (clefEnum == ClefEnum.TAB && guitarPro) {
-                                clefOctaveOffset = -1;
-                            }
-                            var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ClefError",
-                                "Unsupported clef found -> using default clef.");
-                            this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                            clefEnum = ClefEnum.G;
-                            line = 2;
-                        }
-                    }
-                    catch (e) {
-                        var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ClefError",
-                            "Invalid clef found -> using default clef.");
-                        this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                        clefEnum = ClefEnum.G;
-                        line = 2;
-                        Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, e);
-                    }
+        }
+        if (nodeList.HasAttributes && nodeList.Attributes().First().Name === "number") {
+          try {
+            staffNumber = StringToNumberConverter.ToInteger(nodeList.Attributes().First().Value);
+          } catch (err) {
+            errorMsg = ITextTranslation.translateText(
+              "ReaderErrorMessages/ClefError",
+              "Invalid clef found -> using default clef."
+            );
+            this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+            staffNumber = 1;
+          }
+        }
 
-                }
-                var clefOctaveNode: IXmlElement = nodeList.Element("clef-octave-change");
-                if (clefOctaveNode != null) {
-                    try {
-                        clefOctaveOffset = StringToNumberConverter.ToInteger(clefOctaveNode.Value);
-                    }
-                    catch (e) {
-                        var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ClefOctaveError",
-                            "Invalid clef octave found -> using default clef octave.");
-                        this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                        clefOctaveOffset = 0;
-                    }
+        let clefInstruction: ClefInstruction = new ClefInstruction(clefEnum, clefOctaveOffset, line);
+        this.abstractInstructions.Add(new KeyValuePairClass<number, AbstractNotationInstruction>(staffNumber, clefInstruction));
+      }
+    }
+    if (node.Element("key") !== undefined && this.instrument.MidiInstrumentId !== Common.Enums.MidiInstrument.Percussion) {
+      let key: number = 0;
+      let keyNode: IXmlElement = node.Element("key").Element("fifths");
+      if (keyNode !== undefined) {
+        try {
+          key = <number>StringToNumberConverter.ToInteger(keyNode.Value);
+        } catch (ex) {
+          let errorMsg: string = ITextTranslation.translateText(
+            "ReaderErrorMessages/KeyError",
+            "Invalid key found -> set to default."
+          );
+          this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+          key = 0;
+          Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, ex);
+        }
 
-                }
-                if (nodeList.HasAttributes)
-                    if (nodeList.Attributes().First().Name == "number") {
-                        try {
-                            staffNumber = StringToNumberConverter.ToInteger(nodeList.Attributes().First().Value);
-                        }
-                        catch (err) {
-                            var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ClefError",
-                                "Invalid clef found -> using default clef.");
-                            this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                            staffNumber = 1;
-                        }
+      }
+      let keyEnum: KeyEnum = KeyEnum.none;
+      let modeNode: IXmlElement = node.Element("key");
+      if (modeNode !== undefined) { modeNode = modeNode.Element("mode"); }
+      if (modeNode !== undefined) {
+        try {
+          keyEnum = <KeyEnum>Enum.Parse(/*typeof*/KeyEnum, modeNode.Value);
+        } catch (ex) {
+          errorMsg = ITextTranslation.translateText(
+            "ReaderErrorMessages/KeyError",
+            "Invalid key found -> set to default."
+          );
+          this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+          keyEnum = KeyEnum.major;
+          Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, ex);
+        }
 
-                    }
-                var clefInstruction: ClefInstruction = new ClefInstruction(clefEnum, clefOctaveOffset, line);
-                this.abstractInstructions.Add(new KeyValuePairClass<number, AbstractNotationInstruction>(staffNumber, clefInstruction));
-            }
+      }
+      let keyInstruction: KeyInstruction = new KeyInstruction(key, keyEnum);
+      this.abstractInstructions.Add(new KeyValuePairClass<number, AbstractNotationInstruction>(1, keyInstruction));
+    }
+    if (node.Element("time") !== undefined) {
+      let symbolEnum: RhythmSymbolEnum = RhythmSymbolEnum.NONE;
+      let timeNode: IXmlElement = node.Element("time");
+      if (
+        timeNode !== undefined &&
+        timeNode.HasAttributes &&
+        timeNode.Attributes().First() !== undefined
+      ) {
+        let firstAttr: IXmlAttribute = timeNode.Attributes().First();
+        if (firstAttr.Name === "symbol") {
+          if (firstAttr.Value === "common") {
+            symbolEnum = RhythmSymbolEnum.COMMON;
+          } else if (firstAttr.Value === "cut") {
+            symbolEnum = RhythmSymbolEnum.CUT;
+          }
         }
-        if (node.Element("key") != null && this.instrument.MidiInstrumentId != Common.Enums.MidiInstrument.Percussion) {
-            var key: number = 0;
-            var keyNode: IXmlElement = node.Element("key").Element("fifths");
-            if (keyNode != null) {
-                try {
-                    key = <number>StringToNumberConverter.ToInteger(keyNode.Value);
-                }
-                catch (ex) {
-                    var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/KeyError",
-                        "Invalid key found -> set to default.");
-                    this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                    key = 0;
-                    Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, ex);
+      }
+      let num: number = 0;
+      let denom: number = 0;
+      let senzaMisura: boolean = (timeNode !== undefined && timeNode.Element("senza-misura") !== undefined);
+      let timeList: IXmlElement[] = node.Elements("time").ToArray();
+      let beatsList: List<IXmlElement> = new List<IXmlElement>();
+      let typeList: List<IXmlElement> = new List<IXmlElement>();
+      for (let idx: number = 0, len: number = timeList.length; idx < len; ++idx) {
+        let xmlNode: IXmlElement = timeList[idx];
+        beatsList.AddRange(xmlNode.Elements("beats"));
+        typeList.AddRange(xmlNode.Elements("beat-type"));
+      }
+      if (!senzaMisura) {
+        try {
+          if (beatsList !== undefined && beatsList.Count > 0 && typeList !== undefined && beatsList.Count === typeList.Count) {
+            let length: number = beatsList.Count();
+            let fractions: Fraction[] = new Array(length);
+            let maxDenom: number = 0;
+            for (let i: number = 0; i < length; i++) {
+              let s: string = beatsList[i].Value;
+              let n: number = 0;
+              let d: number = 0;
+              if (s.IndexOf("+") !== -1) {
+                let numbers: string[] = s.Split("+");
+                for (let idx: number = 0, len: number = numbers.Count(); idx < len; ++idx) {
+                  n += StringToNumberConverter.ToInteger(numbers[idx]);
                 }
-
+              } else {
+                n = StringToNumberConverter.ToInteger(s);
+              }
+              d = StringToNumberConverter.ToInteger(typeList[i].Value);
+              maxDenom = Math.Max(maxDenom, d);
+              fractions[i] = new Fraction(n, d, false);
             }
-            var keyEnum: KeyEnum = KeyEnum.none;
-            var modeNode: IXmlElement = node.Element("key");
-            if (modeNode != null)
-                modeNode = modeNode.Element("mode");
-            if (modeNode != null) {
-                try {
-                    keyEnum = <KeyEnum>Enum.Parse(/*typeof*/KeyEnum, modeNode.Value);
-                }
-                catch (ex) {
-                    var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/KeyError",
-                        "Invalid key found -> set to default.");
-                    this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                    keyEnum = KeyEnum.major;
-                    Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, ex);
-                }
-
+            for (let i: number = 0; i < length; i++) {
+              if (fractions[i].Denominator === maxDenom) {
+                num += fractions[i].Numerator;
+              } else {
+                num += (maxDenom / fractions[i].Denominator) * fractions[i].Numerator;
+              }
             }
-            var keyInstruction: KeyInstruction = new KeyInstruction(key, keyEnum);
-            this.abstractInstructions.Add(new KeyValuePairClass<number, AbstractNotationInstruction>(1, keyInstruction));
+            denom = maxDenom;
+          } else {
+            num = StringToNumberConverter.ToInteger(node.Element("time").Element("beats").Value);
+            denom = StringToNumberConverter.ToInteger(node.Element("time").Element("beat-type").Value);
+          }
+        } catch (ex) {
+          errorMsg = ITextTranslation.translateText("ReaderErrorMessages/RhythmError", "Invalid rhythm found -> set to default.");
+          this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+          num = 4;
+          denom = 4;
+          Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, ex);
         }
-        if (node.Element("time") != null) {
-            var symbolEnum: RhythmSymbolEnum = RhythmSymbolEnum.NONE;
-            var timeNode: IXmlElement = node.Element("time");
-            if (timeNode != null)
-                if (timeNode.HasAttributes)
-                    if (timeNode.Attributes().First() != null) {
-                        var firstAttr: IXmlAttribute = timeNode.Attributes().First();
-                        if (firstAttr.Name == "symbol") {
-                            if (firstAttr.Value == "common")
-                                symbolEnum = RhythmSymbolEnum.COMMON;
-                            else if (firstAttr.Value == "cut")
-                                symbolEnum = RhythmSymbolEnum.CUT;
-                        }
-                    }
-            var num: number = 0;
-            var denom: number = 0;
-            var senzaMisura: boolean = (timeNode != null && timeNode.Element("senza-misura") != null);
-            var timeList: IXmlElement[] = node.Elements("time").ToArray();
-            var beatsList: List<IXmlElement> = new List<IXmlElement>();
-            var typeList: List<IXmlElement> = new List<IXmlElement>();
-            for (var idx: number = 0, len = timeList.length; idx < len; ++idx) {
-                var xmlNode: IXmlElement = timeList[idx];
-                beatsList.AddRange(xmlNode.Elements("beats"));
-                typeList.AddRange(xmlNode.Elements("beat-type"));
-            }
-            if (!senzaMisura) {
-                try {
-                    if (beatsList != null && beatsList.Count > 0 && typeList != null && beatsList.Count == typeList.Count) {
-                        var length: number = beatsList.Count();
-                        var fractions: Fraction[] = new Array(length);
-                        var maxDenom: number = 0;
-                        for (var i: number = 0; i < length; i++) {
-                            var s: string = beatsList[i].Value;
-                            var n: number = 0;
-                            var d: number = 0;
-                            if (s.IndexOf("+") != -1) {
-                                var numbers: string[] = s.Split('+');
-                                for (var idx: number = 0, len = numbers.Count(); idx < len; ++idx) {
-                                    var number: String = numbers[idx];
-                                    n += StringToNumberConverter.ToInteger(number);
-                                }
-                            }
-                            else n = StringToNumberConverter.ToInteger(s);
-                            d = StringToNumberConverter.ToInteger(typeList[i].Value);
-                            maxDenom = Math.Max(maxDenom, d);
-                            fractions[i] = new Fraction(n, d, false);
-                        }
-                        for (var i: number = 0; i < length; i++) {
-                            if (fractions[i].Denominator == maxDenom)
-                                num += fractions[i].Numerator;
-                            else num += (maxDenom / fractions[i].Denominator) * fractions[i].Numerator;
-                        }
-                        denom = maxDenom;
-                    }
-                    else {
-                        num = StringToNumberConverter.ToInteger(node.Element("time").Element("beats").Value);
-                        denom = StringToNumberConverter.ToInteger(node.Element("time").Element("beat-type").Value);
-                    }
-                }
-                catch (ex) {
-                    var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/RhythmError", "Invalid rhythm found -> set to default.");
-                    this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                    num = 4;
-                    denom = 4;
-                    Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.addAbstractInstruction", errorMsg, ex);
-                }
 
-                var measure: Fraction = new Fraction(num, denom, false);
-                if (symbolEnum != RhythmSymbolEnum.NONE && (measure != new Fraction(4, 4) || measure != new Fraction(2, 2)))
-                    symbolEnum = RhythmSymbolEnum.NONE;
-                var rhythmInstruction: RhythmInstruction = new RhythmInstruction(measure, num, denom, symbolEnum);
-                this.abstractInstructions.Add(new KeyValuePairClass<number, AbstractNotationInstruction>(1, rhythmInstruction));
-            }
-            else {
-                var rhythmInstruction: RhythmInstruction = new RhythmInstruction(new Fraction(4, 4, false), 4, 4, RhythmSymbolEnum.NONE);
-                this.abstractInstructions.Add(new KeyValuePairClass<number, AbstractNotationInstruction>(1, rhythmInstruction));
-            }
+        if ((num === denom === 4) || (num === denom === 2)) {
+          symbolEnum = RhythmSymbolEnum.NONE;
         }
+        let rhythmInstruction: RhythmInstruction = new RhythmInstruction(
+          new Fraction(num, denom, false), num, denom, symbolEnum
+        );
+        this.abstractInstructions.Add(new KeyValuePairClass<number, AbstractNotationInstruction>(1, rhythmInstruction));
+      } else {
+        let rhythmInstruction: RhythmInstruction = new RhythmInstruction(new Fraction(4, 4, false), 4, 4, RhythmSymbolEnum.NONE);
+        this.abstractInstructions.Add(new KeyValuePairClass<number, AbstractNotationInstruction>(1, rhythmInstruction));
+      }
     }
-    private saveAbstractInstructionList(numberOfStaves: number, beginOfMeasure: boolean): void {
-        for (var i: number = this.abstractInstructions.Count - 1; i >= 0; i--) {
-            var keyValuePair: KeyValuePairClass<number, AbstractNotationInstruction> = this.abstractInstructions[i];
-            if (keyValuePair.value instanceof ClefInstruction) {
-                var clefInstruction: ClefInstruction = <ClefInstruction>keyValuePair.value;
-                if (this.currentXmlMeasureIndex == 0 || (keyValuePair.key <= this.activeClefs.length && clefInstruction != this.activeClefs[keyValuePair.key - 1])) {
-                    if (!beginOfMeasure && this.currentStaffEntry != null && !this.currentStaffEntry.hasNotes() && keyValuePair.key - 1 == this.instrument.Staves.IndexOf(this.currentStaffEntry.ParentStaff)) {
-                        var newClefInstruction: ClefInstruction = clefInstruction;
-                        newClefInstruction.Parent = this.currentStaffEntry;
-                        this.currentStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
-                        this.currentStaffEntry.Instructions.Add(newClefInstruction);
-                        this.activeClefs[keyValuePair.key - 1] = clefInstruction;
-                        this.abstractInstructions.Remove(keyValuePair);
-                    }
-                    else if (beginOfMeasure) {
-                        if (this.currentMeasure != null) {
-                            var newClefInstruction: ClefInstruction = clefInstruction;
-                            if (this.currentXmlMeasureIndex == 0) {
-                                if (this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] == null) {
-                                    var firstStaffEntry: SourceStaffEntry = new SourceStaffEntry(null, null);
-                                    this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] = firstStaffEntry;
-                                    newClefInstruction.Parent = firstStaffEntry;
-                                    firstStaffEntry.Instructions.Add(newClefInstruction);
-                                    this.activeClefsHaveBeenInitialized[keyValuePair.key - 1] = true;
-                                }
-                                else if (this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] != null && !(this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1].Instructions[0] instanceof ClefInstruction)) {
-                                    var firstStaffEntry: SourceStaffEntry = this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1];
-                                    newClefInstruction.Parent = firstStaffEntry;
-                                    firstStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
-                                    firstStaffEntry.Instructions.Insert(0, newClefInstruction);
-                                    this.activeClefsHaveBeenInitialized[keyValuePair.key - 1] = true;
-                                }
-                                else {
-                                    var lastStaffEntry: SourceStaffEntry = new SourceStaffEntry(null, null);
-                                    this.currentMeasure.LastInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] = lastStaffEntry;
-                                    newClefInstruction.Parent = lastStaffEntry;
-                                    lastStaffEntry.Instructions.Add(newClefInstruction);
-                                }
-                            }
-                            else if (!this.activeClefsHaveBeenInitialized[keyValuePair.key - 1]) {
-                                var first: SourceMeasure = this.musicSheet.SourceMeasures[0];
-                                var firstStaffEntry: SourceStaffEntry;
-                                if (first.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] == null)
-                                    firstStaffEntry = new SourceStaffEntry(null, null);
-                                else {
-                                    firstStaffEntry = first.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1];
-                                    firstStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
-                                }
-                                newClefInstruction.Parent = firstStaffEntry;
-                                firstStaffEntry.Instructions.Insert(0, newClefInstruction);
-                                this.activeClefsHaveBeenInitialized[keyValuePair.key - 1] = true;
-                            }
-                            else {
-                                var lastStaffEntry: SourceStaffEntry = new SourceStaffEntry(null, null);
-                                this.previousMeasure.LastInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] = lastStaffEntry;
-                                newClefInstruction.Parent = lastStaffEntry;
-                                lastStaffEntry.Instructions.Add(newClefInstruction);
-                            }
-                            this.activeClefs[keyValuePair.key - 1] = clefInstruction;
-                            this.abstractInstructions.Remove(keyValuePair);
-                        }
-                    }
+  }
+  /*private saveAbstractInstructionList(numberOfStaves: number, beginOfMeasure: boolean): void {
+    for (let i: number = this.abstractInstructions.Count - 1; i >= 0; i--) {
+      let keyValuePair: KeyValuePairClass<number, AbstractNotationInstruction> = this.abstractInstructions[i];
+      if (keyValuePair.value instanceof ClefInstruction) {
+        let clefInstruction: ClefInstruction = <ClefInstruction>keyValuePair.value;
+        if (this.currentXmlMeasureIndex === 0 || (keyValuePair.key <= this.activeClefs.length && clefInstruction !== this.activeClefs[keyValuePair.key - 1])) {
+          if (!beginOfMeasure && this.currentStaffEntry !== undefined && !this.currentStaffEntry.hasNotes() && keyValuePair.key - 1
+          === this.instrument.Staves.IndexOf(this.currentStaffEntry.ParentStaff)) {
+            let newClefInstruction: ClefInstruction = clefInstruction;
+            newClefInstruction.Parent = this.currentStaffEntry;
+            this.currentStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
+            this.currentStaffEntry.Instructions.Add(newClefInstruction);
+            this.activeClefs[keyValuePair.key - 1] = clefInstruction;
+            this.abstractInstructions.Remove(keyValuePair);
+          } else if (beginOfMeasure) {
+            let firstStaffEntry: SourceStaffEntry;
+            if (this.currentMeasure !== undefined) {
+              let newClefInstruction: ClefInstruction = clefInstruction;
+              if (this.currentXmlMeasureIndex === 0) {
+                if (this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] === undefined) {
+                  firstStaffEntry = new SourceStaffEntry(undefined, undefined);
+                  this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] = firstStaffEntry;
+                  newClefInstruction.Parent = firstStaffEntry;
+                  firstStaffEntry.Instructions.Add(newClefInstruction);
+                  this.activeClefsHaveBeenInitialized[keyValuePair.key - 1] = true;
+                } else if (this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1]
+                !==
+                undefined && !(this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1].Instructions[0]
+                 instanceof ClefInstruction)) {
+                  firstStaffEntry = this.currentMeasure.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1];
+                  newClefInstruction.Parent = firstStaffEntry;
+                  firstStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
+                  firstStaffEntry.Instructions.Insert(0, newClefInstruction);
+                  this.activeClefsHaveBeenInitialized[keyValuePair.key - 1] = true;
+                } else {
+                  firstStaffEntry = new SourceStaffEntry(undefined, undefined);
+                  this.currentMeasure.LastInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] = lastStaffEntry;
+                  newClefInstruction.Parent = lastStaffEntry;
+                  lastStaffEntry.Instructions.Add(newClefInstruction);
                 }
-                if (keyValuePair.key <= this.activeClefs.length && clefInstruction == this.activeClefs[keyValuePair.key - 1])
-                    this.abstractInstructions.Remove(keyValuePair);
-            }
-            if (keyValuePair.value instanceof KeyInstruction) {
-                var keyInstruction: KeyInstruction = <KeyInstruction>keyValuePair.value;
-                if (this.activeKey == null || this.activeKey.Key != keyInstruction.Key) {
-                    this.activeKey = keyInstruction;
-                    this.abstractInstructions.Remove(keyValuePair);
-                    var sourceMeasure: SourceMeasure;
-                    if (!this.activeKeyHasBeenInitialized) {
-                        this.activeKeyHasBeenInitialized = true;
-                        if (this.currentXmlMeasureIndex > 0)
-                            sourceMeasure = this.musicSheet.SourceMeasures[0];
-                        else sourceMeasure = this.currentMeasure;
-                    }
-                    else sourceMeasure = this.currentMeasure;
-                    if (sourceMeasure != null) {
-                        for (var j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + numberOfStaves; j++) {
-                            var newKeyInstruction: KeyInstruction = keyInstruction;
-                            if (sourceMeasure.FirstInstructionsStaffEntries[j] == null) {
-                                var firstStaffEntry: SourceStaffEntry = new SourceStaffEntry(null, null);
-                                sourceMeasure.FirstInstructionsStaffEntries[j] = firstStaffEntry;
-                                newKeyInstruction.Parent = firstStaffEntry;
-                                firstStaffEntry.Instructions.Add(newKeyInstruction);
-                            }
-                            else {
-                                var firstStaffEntry: SourceStaffEntry = sourceMeasure.FirstInstructionsStaffEntries[j];
-                                newKeyInstruction.Parent = firstStaffEntry;
-                                firstStaffEntry.removeFirstInstructionOfType<KeyInstruction>();
-                                if (firstStaffEntry.Instructions.Count == 0) {
-                                    firstStaffEntry.Instructions.Add(newKeyInstruction);
-                                }
-                                else {
-                                    if (firstStaffEntry.Instructions[0] instanceof ClefInstruction)
-                                        firstStaffEntry.Instructions.Insert(1, newKeyInstruction);
-                                    else firstStaffEntry.Instructions.Insert(0, newKeyInstruction);
-                                }
-                            }
-                        }
-                    }
+              } else if (!this.activeClefsHaveBeenInitialized[keyValuePair.key - 1]) {
+                let first: SourceMeasure = this.musicSheet.SourceMeasures[0];
+                if (first.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] === undefined) {
+                  firstStaffEntry = new SourceStaffEntry(undefined, undefined);
+                } else {
+                  firstStaffEntry = first.FirstInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1];
+                  firstStaffEntry.removeFirstInstructionOfType<ClefInstruction>();
                 }
-                if (this.activeKey != null && this.activeKey == keyInstruction)
-                    this.abstractInstructions.Remove(keyValuePair);
+                newClefInstruction.Parent = firstStaffEntry;
+                firstStaffEntry.Instructions.Insert(0, newClefInstruction);
+                this.activeClefsHaveBeenInitialized[keyValuePair.key - 1] = true;
+              } else {
+                let lastStaffEntry: SourceStaffEntry = new SourceStaffEntry(undefined, undefined);
+                this.previousMeasure.LastInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] = lastStaffEntry;
+                newClefInstruction.Parent = lastStaffEntry;
+                lastStaffEntry.Instructions.Add(newClefInstruction);
+              }
+              this.activeClefs[keyValuePair.key - 1] = clefInstruction;
+              this.abstractInstructions.Remove(keyValuePair);
+            }
+          }
+        }
+        if (keyValuePair.key <= this.activeClefs.length && clefInstruction === this.activeClefs[keyValuePair.key - 1])
+          this.abstractInstructions.Remove(keyValuePair);
+      }
+      if (keyValuePair.value instanceof KeyInstruction) {
+        let keyInstruction: KeyInstruction = <KeyInstruction>keyValuePair.value;
+        if (this.activeKey === undefined || this.activeKey.Key !== keyInstruction.Key) {
+          this.activeKey = keyInstruction;
+          this.abstractInstructions.Remove(keyValuePair);
+          let sourceMeasure: SourceMeasure;
+          if (!this.activeKeyHasBeenInitialized) {
+            this.activeKeyHasBeenInitialized = true;
+            if (this.currentXmlMeasureIndex > 0) {
+              sourceMeasure = this.musicSheet.SourceMeasures[0];
+            } else {
+              sourceMeasure = this.currentMeasure;
             }
-            if (keyValuePair.value instanceof RhythmInstruction) {
-                var rhythmInstruction: RhythmInstruction = <RhythmInstruction>keyValuePair.value;
-                if (this.activeRhythm == null || this.activeRhythm != rhythmInstruction) {
-                    this.activeRhythm = rhythmInstruction;
-                    this.abstractInstructions.Remove(keyValuePair);
-                    if (this.currentMeasure != null) {
-                        for (var j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + numberOfStaves; j++) {
-                            var newRhythmInstruction: RhythmInstruction = rhythmInstruction;
-                            var firstStaffEntry: SourceStaffEntry;
-                            if (this.currentMeasure.FirstInstructionsStaffEntries[j] == null) {
-                                firstStaffEntry = new SourceStaffEntry(null, null);
-                                this.currentMeasure.FirstInstructionsStaffEntries[j] = firstStaffEntry;
-                            }
-                            else {
-                                firstStaffEntry = this.currentMeasure.FirstInstructionsStaffEntries[j];
-                                firstStaffEntry.removeFirstInstructionOfType<RhythmInstruction>();
-                            }
-                            newRhythmInstruction.Parent = firstStaffEntry;
-                            firstStaffEntry.Instructions.Add(newRhythmInstruction);
-                        }
-                    }
+          } else {
+            sourceMeasure = this.currentMeasure;
+          }
+          if (sourceMeasure !== undefined) {
+            for (let j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + numberOfStaves; j++) {
+              let newKeyInstruction: KeyInstruction = keyInstruction;
+              if (sourceMeasure.FirstInstructionsStaffEntries[j] === undefined) {
+                firstStaffEntry = new SourceStaffEntry(undefined, undefined);
+                sourceMeasure.FirstInstructionsStaffEntries[j] = firstStaffEntry;
+                newKeyInstruction.Parent = firstStaffEntry;
+                firstStaffEntry.Instructions.Add(newKeyInstruction);
+              } else {
+                firstStaffEntry = sourceMeasure.FirstInstructionsStaffEntries[j];
+                newKeyInstruction.Parent = firstStaffEntry;
+                firstStaffEntry.removeFirstInstructionOfType<KeyInstruction>();
+                if (firstStaffEntry.Instructions.Count === 0) {
+                  firstStaffEntry.Instructions.Add(newKeyInstruction);
+                } else {
+                  if (firstStaffEntry.Instructions[0] instanceof ClefInstruction) {
+                    firstStaffEntry.Instructions.Insert(1, newKeyInstruction);
+                  } else {
+                    firstStaffEntry.Instructions.Insert(0, newKeyInstruction);
+                  }
                 }
-                if (this.activeRhythm != null && this.activeRhythm == rhythmInstruction)
-                    this.abstractInstructions.Remove(keyValuePair);
+              }
             }
+          }
         }
-    }
-    private saveClefInstructionAtEndOfMeasure(): void {
-        for (var i: number = this.abstractInstructions.Count - 1; i >= 0; i--) {
-            var keyValuePair: KeyValuePairClass<number, AbstractNotationInstruction> = this.abstractInstructions[i];
-            if (keyValuePair.value instanceof ClefInstruction) {
-                var clefInstruction: ClefInstruction = __as__<ClefInstruction>(keyValuePair.value, ClefInstruction);
-                if ((this.activeClefs[keyValuePair.key - 1] == null) || (this.activeClefs[keyValuePair.key - 1] != null && (clefInstruction.ClefType != this.activeClefs[keyValuePair.key - 1].ClefType || (clefInstruction.ClefType == this.activeClefs[keyValuePair.key - 1].ClefType && clefInstruction.Line != this.activeClefs[keyValuePair.key - 1].Line)))) {
-                    var lastStaffEntry: SourceStaffEntry = new SourceStaffEntry(null, null);
-                    this.currentMeasure.LastInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] = lastStaffEntry;
-                    var newClefInstruction: ClefInstruction = clefInstruction;
-                    newClefInstruction.Parent = lastStaffEntry;
-                    lastStaffEntry.Instructions.Add(newClefInstruction);
-                    this.activeClefs[keyValuePair.key - 1] = clefInstruction;
-                    this.abstractInstructions.Remove(keyValuePair);
-                }
+        if (this.activeKey !== undefined && this.activeKey === keyInstruction)
+          this.abstractInstructions.Remove(keyValuePair);
+      }
+      if (keyValuePair.value instanceof RhythmInstruction) {
+        let rhythmInstruction: RhythmInstruction = <RhythmInstruction>keyValuePair.value;
+        if (this.activeRhythm === undefined || this.activeRhythm !== rhythmInstruction) {
+          this.activeRhythm = rhythmInstruction;
+          this.abstractInstructions.Remove(keyValuePair);
+          if (this.currentMeasure !== undefined) {
+            for (let j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + numberOfStaves; j++) {
+              let newRhythmInstruction: RhythmInstruction = rhythmInstruction;
+              if (this.currentMeasure.FirstInstructionsStaffEntries[j] === undefined) {
+                firstStaffEntry = new SourceStaffEntry(undefined, undefined);
+                this.currentMeasure.FirstInstructionsStaffEntries[j] = firstStaffEntry;
+              } else {
+                firstStaffEntry = this.currentMeasure.FirstInstructionsStaffEntries[j];
+                firstStaffEntry.removeFirstInstructionOfType<RhythmInstruction>();
+              }
+              newRhythmInstruction.Parent = firstStaffEntry;
+              firstStaffEntry.Instructions.Add(newRhythmInstruction);
             }
+          }
         }
+        if (this.activeRhythm !== undefined && this.activeRhythm === rhythmInstruction)
+          this.abstractInstructions.Remove(keyValuePair);
+      }
     }
-    private getNoteDurationForTuplet(xmlNode: IXmlElement): Fraction {
-        var duration: Fraction = new Fraction(0, 1);
-        var typeDuration: Fraction = this.getNoteDurationFromTypeNode(xmlNode);
-        if (xmlNode.Element("time-modification") != null) {
-            var time: IXmlElement = xmlNode.Element("time-modification");
-            if (time != null) {
-                if (time.Element("actual-notes") != null && time.Element("normal-notes") != null) {
-                    var actualNotes: IXmlElement = time.Element("actual-notes");
-                    var normalNotes: IXmlElement = time.Element("normal-notes");
-                    if (actualNotes != null && normalNotes != null) {
-                        var actual: number = StringToNumberConverter.ToInteger(actualNotes.Value);
-                        var normal: number = StringToNumberConverter.ToInteger(normalNotes.Value);
-                        duration = new Fraction(normal, actual) * typeDuration;
-                    }
-                }
-            }
+  }
+  */
+  private saveClefInstructionAtEndOfMeasure(): void {
+    for (let i: number = this.abstractInstructions.Count - 1; i >= 0; i--) {
+      let keyValuePair: KeyValuePairClass<number, AbstractNotationInstruction> = this.abstractInstructions[i];
+      if (keyValuePair.value instanceof ClefInstruction) {
+        let clefInstruction: ClefInstruction = __as__<ClefInstruction>(keyValuePair.value, ClefInstruction);
+        if (
+          (this.activeClefs[keyValuePair.key - 1] === undefined) ||
+          (clefInstruction.ClefType !== this.activeClefs[keyValuePair.key - 1].ClefType || (
+            clefInstruction.ClefType === this.activeClefs[keyValuePair.key - 1].ClefType &&
+            clefInstruction.Line !== this.activeClefs[keyValuePair.key - 1].Line
+          ))) {
+          let lastStaffEntry: SourceStaffEntry = new SourceStaffEntry(undefined, undefined);
+          this.currentMeasure.LastInstructionsStaffEntries[this.inSourceMeasureInstrumentIndex + keyValuePair.key - 1] = lastStaffEntry;
+          let newClefInstruction: ClefInstruction = clefInstruction;
+          newClefInstruction.Parent = lastStaffEntry;
+          lastStaffEntry.Instructions.Add(newClefInstruction);
+          this.activeClefs[keyValuePair.key - 1] = clefInstruction;
+          this.abstractInstructions.Remove(keyValuePair);
         }
-        return duration;
+      }
     }
-    private readExpressionStaffNumber(xmlNode: IXmlElement): number {
-        var directionStaffNumber: number = 1;
-        if (xmlNode.Element("staff") != null) {
-            var staffNode: IXmlElement = xmlNode.Element("staff");
-            if (staffNode != null) {
-                try {
-                    directionStaffNumber = StringToNumberConverter.ToInteger(staffNode.Value);
-                }
-                catch (ex) {
-                    var errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ExpressionStaffError", "Invalid Expression staff number -> set to default.");
-                    this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
-                    directionStaffNumber = 1;
-                    Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readExpressionStaffNumber", errorMsg, ex);
-                }
-
-            }
+  }
+  private getNoteDurationForTuplet(xmlNode: IXmlElement): Fraction {
+    let duration: Fraction = new Fraction(0, 1);
+    let typeDuration: Fraction = this.getNoteDurationFromTypeNode(xmlNode);
+    if (xmlNode.Element("time-modification") !== undefined) {
+      let time: IXmlElement = xmlNode.Element("time-modification");
+      if (time !== undefined) {
+        if (time.Element("actual-notes") !== undefined && time.Element("normal-notes") !== undefined) {
+          let actualNotes: IXmlElement = time.Element("actual-notes");
+          let normalNotes: IXmlElement = time.Element("normal-notes");
+          if (actualNotes !== undefined && normalNotes !== undefined) {
+            let actual: number = StringToNumberConverter.ToInteger(actualNotes.Value);
+            let normal: number = StringToNumberConverter.ToInteger(normalNotes.Value);
+            duration = new Fraction(normal, actual) * typeDuration;
+          }
+        }
+      }
+    }
+    return duration;
+  }
+  private readExpressionStaffNumber(xmlNode: IXmlElement): number {
+    let directionStaffNumber: number = 1;
+    if (xmlNode.Element("staff") !== undefined) {
+      let staffNode: IXmlElement = xmlNode.Element("staff");
+      if (staffNode !== undefined) {
+        try {
+          directionStaffNumber = StringToNumberConverter.ToInteger(staffNode.Value);
+        } catch (ex) {
+          let errorMsg: string = ITextTranslation.translateText(
+            "ReaderErrorMessages/ExpressionStaffError", "Invalid Expression staff number -> set to default."
+          );
+          this.musicSheet.SheetErrors.AddErrorMessageInTempList(errorMsg);
+          directionStaffNumber = 1;
+          Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readExpressionStaffNumber", errorMsg, ex);
         }
-        return directionStaffNumber;
+
+      }
     }
-    private readDivisionsFromNotes(): number {
-        var divisionsFromNote: number = 0;
-        var xmlMeasureIndex: number = this.currentXmlMeasureIndex;
-        var read: boolean = false;
-        while (!read) {
-            var xmlMeasureListArr: IXmlElement[] = this.xmlMeasureList[xmlMeasureIndex].Elements().ToArray();
-            for (var idx: number = 0, len = xmlMeasureListArr.length; idx < len; ++idx) {
-                var xmlNode: IXmlElement = xmlMeasureListArr[idx];
-                if (xmlNode.Name == "note" && xmlNode.Element("time-modification") == null) {
-                    if (xmlNode.Element("duration") != null && xmlNode.Element("type") != null) {
-                        var durationNode: IXmlElement = xmlNode.Element("duration");
-                        var typeNode: IXmlElement = xmlNode.Element("type");
-                        if (durationNode != null && typeNode != null) {
-                            var type: string = typeNode.Value;
-                            var noteDuration: number = 0;
-                            try {
-                                noteDuration = StringToNumberConverter.ToInteger(durationNode.Value);
-                            }
-                            catch (ex) {
-                                Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readDivisionsFromNotes", ex);
-                                continue;
-                            }
+    return directionStaffNumber;
+  }
+  private readDivisionsFromNotes(): number {
+    let divisionsFromNote: number = 0;
+    let xmlMeasureIndex: number = this.currentXmlMeasureIndex;
+    let read: boolean = false;
+    while (!read) {
+      let xmlMeasureListArr: IXmlElement[] = this.xmlMeasureList[xmlMeasureIndex].Elements().ToArray();
+      for (let idx: number = 0, len: number = xmlMeasureListArr.length; idx < len; ++idx) {
+        let xmlNode: IXmlElement = xmlMeasureListArr[idx];
+        if (xmlNode.Name === "note" && xmlNode.Element("time-modification") === undefined) {
+          if (xmlNode.Element("duration") !== undefined && xmlNode.Element("type") !== undefined) {
+            let durationNode: IXmlElement = xmlNode.Element("duration");
+            let typeNode: IXmlElement = xmlNode.Element("type");
+            if (durationNode !== undefined && typeNode !== undefined) {
+              let type: string = typeNode.Value;
+              let noteDuration: number = 0;
+              try {
+                noteDuration = StringToNumberConverter.ToInteger(durationNode.Value);
+              } catch (ex) {
+                Logger.DefaultLogger.LogError(LogLevel.DEBUG, "InstrumentReader.readDivisionsFromNotes", ex);
+                continue;
+              }
 
-                            switch (type) {
-                                case "1024th":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 1024;
-                                        break;
-                                    }
-                                case "512th":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 512;
-                                        break;
-                                    }
-                                case "256th":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 256;
-                                        break;
-                                    }
-                                case "128th":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 128;
-                                        break;
-                                    }
-                                case "64th":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 64;
-                                        break;
-                                    }
-                                case "32nd":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 32;
-                                        break;
-                                    }
-                                case "16th":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 16;
-                                        break;
-                                    }
-                                case "eighth":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 8;
-                                        break;
-                                    }
-                                case "quarter":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 4;
-                                        break;
-                                    }
-                                case "half":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) * 2;
-                                        break;
-                                    }
-                                case "whole":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4);
-                                        break;
-                                    }
-                                case "breve":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) / 2;
-                                        break;
-                                    }
-                                case "long":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) / 4;
-                                        break;
-                                    }
-                                case "maxima":
-                                    {
-                                        divisionsFromNote = (noteDuration / 4) / 8;
-                                        break;
-                                    }
-                                default:
-                                    {
-                                        break;
-                                    }
-                            }
-                        }
-                    }
-                }
-                if (divisionsFromNote > 0) {
-                    read = true;
+              switch (type) {
+                case "1024th":
+                    divisionsFromNote = (noteDuration / 4) * 1024;
                     break;
-                }
-            }
-            if (divisionsFromNote == 0) {
-                xmlMeasureIndex++;
-                if (xmlMeasureIndex == this.xmlMeasureList.length) {
-                    var errorMsg: string = ITextTranslation.translateText("ReaderErrorMEssages/DivisionsError", "Invalid divisions value at Instrument: ");
-                    throw new MusicSheetReadingException(errorMsg + this.instrument.Name, 0);
-                }
+                case "512th":
+                    divisionsFromNote = (noteDuration / 4) * 512;
+                    break;
+                case "256th":
+                    divisionsFromNote = (noteDuration / 4) * 256;
+                    break;
+                case "128th":
+                    divisionsFromNote = (noteDuration / 4) * 128;
+                    break;
+                case "64th":
+                    divisionsFromNote = (noteDuration / 4) * 64;
+                    break;
+                case "32nd":
+                    divisionsFromNote = (noteDuration / 4) * 32;
+                    break;
+                case "16th":
+                    divisionsFromNote = (noteDuration / 4) * 16;
+                    break;
+                case "eighth":
+                    divisionsFromNote = (noteDuration / 4) * 8;
+                    break;
+                case "quarter":
+                    divisionsFromNote = (noteDuration / 4) * 4;
+                    break;
+                case "half":
+                    divisionsFromNote = (noteDuration / 4) * 2;
+                    break;
+                case "whole":
+                    divisionsFromNote = (noteDuration / 4);
+                    break;
+                case "breve":
+                    divisionsFromNote = (noteDuration / 4) / 2;
+                    break;
+                case "long":
+                    divisionsFromNote = (noteDuration / 4) / 4;
+                    break;
+                case "maxima":
+                    divisionsFromNote = (noteDuration / 4) / 8;
+                    break;
+                default: break;
+              }
             }
+          }
         }
-        return divisionsFromNote;
-    }
-}
-export module InstrumentReader {
-    export class KeyValuePairClass<T, TU>
-    {
-        constructor(key: T, value: TU) {
-            this.key = key;
-            this.value = value;
+        if (divisionsFromNote > 0) {
+          read = true;
+          break;
+        }
+      }
+      if (divisionsFromNote === 0) {
+        xmlMeasureIndex++;
+        if (xmlMeasureIndex === this.xmlMeasureList.length) {
+          let errorMsg: string = ITextTranslation.translateText("ReaderErrorMEssages/DivisionsError", "Invalid divisions value at Instrument: ");
+          throw new MusicSheetReadingException(errorMsg + this.instrument.Name, 0);
         }
-        public key: T;
-        public value: TU;
+      }
     }
-}
+    return divisionsFromNote;
+  }
+
+  export class KeyValuePairClass<T, TU> {
+    constructor(key: T, value: TU) {
+      this.key = key;
+      this.value = value;
+    }
+    public key: T;
+    public value: TU;
+  }
+}

+ 101 - 97
src/MusicalScore/SubInstrument.ts

@@ -4,107 +4,111 @@ export class SubInstrument {
         this.FixedKey = -1;
         this.MidiInstrumentId = parseMidiInstrument(this.parentInstrument.Name);
         this.Name = this.MidiInstrumentId.ToString();
-        this.Volume = 1f;
+        this.Volume = 1.0;
     }
-    private static midiInstrument: Dictionary<string, MidiInstrument> = __init(new Dictionary<string, MidiInstrument>(), { { "cello",MidiInstrument.Cello },
-        { "violon-c",MidiInstrument.Cello },
-        { "contrabass",MidiInstrument.Contrabass },
-        { "kontrabass",MidiInstrument.Contrabass },
-        { "clarinet",MidiInstrument.Clarinet },
-        { "klarinette",MidiInstrument.Clarinet },
-        { "flute",MidiInstrument.Flute },
-        { "flöte",MidiInstrument.Flute },
-        { "frenchhorn",MidiInstrument.French_Horn },
-        { "guitar",MidiInstrument.Acoustic_Guitar_nylon },
-        { "gitarre",MidiInstrument.Acoustic_Guitar_nylon },
-        { "harp",MidiInstrument.Orchestral_Harp },
-        { "harfe",MidiInstrument.Orchestral_Harp },
-        { "oboe",MidiInstrument.Oboe },
-        { "organ",MidiInstrument.Church_Organ },
-        { "orgue",MidiInstrument.Church_Organ },
-        { "orgel",MidiInstrument.Church_Organ },
-        { "piano",MidiInstrument.Acoustic_Grand_Piano },
-        { "klavier",MidiInstrument.Acoustic_Grand_Piano },
-        { "piccolo",MidiInstrument.Piccolo },
-        { "strings",MidiInstrument.String_Ensemble_1 },
-        { "streicher",MidiInstrument.String_Ensemble_1 },
-        { "steeldrum",MidiInstrument.Steel_Drums },
-        { "trombone",MidiInstrument.Trombone },
-        { "posaune",MidiInstrument.Trombone },
-        { "brass",MidiInstrument.Trombone },
-        { "trumpet",MidiInstrument.Trumpet },
-        { "trompete",MidiInstrument.Trumpet },
-        { "tpt",MidiInstrument.Trumpet },
-        { "tuba",MidiInstrument.Tuba },
-        { "sax",MidiInstrument.Tenor_Sax },
-        { "viola",MidiInstrument.Viola },
-        { "bratsche",MidiInstrument.Viola },
-        { "violin",MidiInstrument.Violin },
-        { "violon.",MidiInstrument.Violin },
-        { "woodblock",MidiInstrument.Woodblock },
-        { "alt",MidiInstrument.Synth_Voice },
-        { "alto",MidiInstrument.Synth_Voice },
-        { "tenor",MidiInstrument.Synth_Voice },
-        { "bariton",MidiInstrument.Synth_Voice },
-        { "baritone",MidiInstrument.Synth_Voice },
-        { "bass",MidiInstrument.Synth_Voice },
-        { "sopran",MidiInstrument.Synth_Voice },
-        { "voice",MidiInstrument.Synth_Voice },
-        { "recorder",MidiInstrument.Recorder },
-        { "blockflöte",MidiInstrument.Recorder },
-        { "banjo",MidiInstrument.Banjo },
-        { "drums",MidiInstrument.Percussion },
-        { "percussion",MidiInstrument.Percussion },
-        { "schlagzeug",MidiInstrument.Percussion },
-        { "schlagwerk",MidiInstrument.Percussion },
-        { "unnamed",MidiInstrument.Acoustic_Grand_Piano } });
- public IdString: string;
- public MidiInstrumentId: MidiInstrument;
- public Volume: number;
- public Pan: number;
- public FixedKey: number;
- public Name: string;
-private parentInstrument: Instrument;
-public get ParentInstrument(): Instrument
-{
-    return this.parentInstrument;
-}
-public static isPianoInstrument(instrument:MidiInstrument): boolean
-{
-    if (instrument == MidiInstrument.Acoustic_Grand_Piano || instrument == MidiInstrument.Bright_Acoustic_Piano || instrument == MidiInstrument.Electric_Grand_Piano || instrument == MidiInstrument.Electric_Piano_1 || instrument == MidiInstrument.Electric_Piano_2)
-        return true;
-    return false;
-}
-public setMidiInstrument(instrumentType:string): void
-    {
+    /*private static midiInstrument: Dictionary<string, MidiInstrument> = __init(new Dictionary<string, MidiInstrument>(), {
+        { "cello", MidiInstrument.Cello },
+        { "violon-c", MidiInstrument.Cello },
+        { "contrabass", MidiInstrument.Contrabass },
+        { "kontrabass", MidiInstrument.Contrabass },
+        { "clarinet", MidiInstrument.Clarinet },
+        { "klarinette", MidiInstrument.Clarinet },
+        { "flute", MidiInstrument.Flute },
+        { "fl�te", MidiInstrument.Flute },
+        { "frenchhorn", MidiInstrument.French_Horn },
+        { "guitar", MidiInstrument.Acoustic_Guitar_nylon },
+        { "gitarre", MidiInstrument.Acoustic_Guitar_nylon },
+        { "harp", MidiInstrument.Orchestral_Harp },
+        { "harfe", MidiInstrument.Orchestral_Harp },
+        { "oboe", MidiInstrument.Oboe },
+        { "organ", MidiInstrument.Church_Organ },
+        { "orgue", MidiInstrument.Church_Organ },
+        { "orgel", MidiInstrument.Church_Organ },
+        { "piano", MidiInstrument.Acoustic_Grand_Piano },
+        { "klavier", MidiInstrument.Acoustic_Grand_Piano },
+        { "piccolo", MidiInstrument.Piccolo },
+        { "strings", MidiInstrument.String_Ensemble_1 },
+        { "streicher", MidiInstrument.String_Ensemble_1 },
+        { "steeldrum", MidiInstrument.Steel_Drums },
+        { "trombone", MidiInstrument.Trombone },
+        { "posaune", MidiInstrument.Trombone },
+        { "brass", MidiInstrument.Trombone },
+        { "trumpet", MidiInstrument.Trumpet },
+        { "trompete", MidiInstrument.Trumpet },
+        { "tpt", MidiInstrument.Trumpet },
+        { "tuba", MidiInstrument.Tuba },
+        { "sax", MidiInstrument.Tenor_Sax },
+        { "viola", MidiInstrument.Viola },
+        { "bratsche", MidiInstrument.Viola },
+        { "violin", MidiInstrument.Violin },
+        { "violon.", MidiInstrument.Violin },
+        { "woodblock", MidiInstrument.Woodblock },
+        { "alt", MidiInstrument.Synth_Voice },
+        { "alto", MidiInstrument.Synth_Voice },
+        { "tenor", MidiInstrument.Synth_Voice },
+        { "bariton", MidiInstrument.Synth_Voice },
+        { "baritone", MidiInstrument.Synth_Voice },
+        { "bass", MidiInstrument.Synth_Voice },
+        { "sopran", MidiInstrument.Synth_Voice },
+        { "voice", MidiInstrument.Synth_Voice },
+        { "recorder", MidiInstrument.Recorder },
+        { "blockfl�te", MidiInstrument.Recorder },
+        { "banjo", MidiInstrument.Banjo },
+        { "drums", MidiInstrument.Percussion },
+        { "percussion", MidiInstrument.Percussion },
+        { "schlagzeug", MidiInstrument.Percussion },
+        { "schlagwerk", MidiInstrument.Percussion },
+        { "unnamed", MidiInstrument.Acoustic_Grand_Piano },
+});*/
+
+    public IdString: string;
+    public MidiInstrumentId: MidiInstrument;
+    public Volume: number;
+    public Pan: number;
+    public FixedKey: number;
+    public Name: string;
+
+    private parentInstrument: Instrument;
+
+    public get ParentInstrument(): Instrument {
+        return this.parentInstrument;
+    }
+    public static isPianoInstrument(instrument: MidiInstrument): boolean {
+        return (instrument === MidiInstrument.Acoustic_Grand_Piano
+          || instrument === MidiInstrument.Bright_Acoustic_Piano
+          || instrument === MidiInstrument.Electric_Grand_Piano
+          || instrument === MidiInstrument.Electric_Piano_1
+          || instrument === MidiInstrument.Electric_Piano_2);
+    }
+    public setMidiInstrument(instrumentType: string): void {
         this.MidiInstrumentId = this.parseMidiInstrument(instrumentType);
     }
-private parseMidiInstrument(instrumentType:string): MidiInstrument
-{
-    try {
-        if (!string.IsNullOrEmpty(instrumentType)) {
-            var tmpName: string = instrumentType.ToLower().Trim();
-            var midiInstrumentArr: KeyValuePair<string, MidiInstrument>[] = SubInstrument.midiInstrument.ToArray();
-            for (var idx: number = 0, len = midiInstrumentArr.length; idx < len; ++idx) {
-                var keyValuePair: KeyValuePair<string, MidiInstrument> = midiInstrumentArr[idx];
-                if (tmpName.Contains(keyValuePair.Key))
-                    return keyValuePair.Value;
+    private parseMidiInstrument(instrumentType: string): MidiInstrument {
+        try {
+            if (!string.IsNullOrEmpty(instrumentType)) {
+                let tmpName: string = instrumentType.ToLower().Trim();
+                let midiInstrumentArr: KeyValuePair<string, MidiInstrument>[] = SubInstrument.midiInstrument.ToArray();
+                for (let idx: number = 0, len: number = midiInstrumentArr.length; idx < len; ++idx) {
+                    let keyValuePair: KeyValuePair<string, MidiInstrument> = midiInstrumentArr[idx];
+                    if (tmpName.Contains(keyValuePair.Key)) {
+                        return keyValuePair.Value;
+                    }
+                }
             }
-        }
-        if (!string.IsNullOrEmpty(this.parentInstrument.Name)) {
-            var tmpName: string = this.parentInstrument.Name.ToLower().Trim();
-            var midiInstrumentArr: KeyValuePair<string, MidiInstrument>[] = SubInstrument.midiInstrument.ToArray();
-            for (var idx: number = 0, len = midiInstrumentArr.length; idx < len; ++idx) {
-                var keyValuePair: KeyValuePair<string, MidiInstrument> = midiInstrumentArr[idx];
-                if (tmpName.Contains(keyValuePair.Key))
-                    return keyValuePair.Value;
+            if (!string.IsNullOrEmpty(this.parentInstrument.Name)) {
+                let tmpName: string = this.parentInstrument.Name.ToLower().Trim();
+                let midiInstrumentArr: KeyValuePair<string, MidiInstrument>[] = SubInstrument.midiInstrument.ToArray();
+                for (let idx: number = 0, len: number = midiInstrumentArr.length; idx < len; ++idx) {
+                    let keyValuePair: KeyValuePair<string, MidiInstrument> = midiInstrumentArr[idx];
+                    if (tmpName.Contains(keyValuePair.Key)) {
+                        return keyValuePair.Value;
+                    }
+                }
             }
+            return MidiInstrument.Acoustic_Grand_Piano;
+        } catch (e) {
+            return MidiInstrument.Acoustic_Grand_Piano;
         }
-        return MidiInstrument.Acoustic_Grand_Piano;
-    }
-    catch (e) {
-        return MidiInstrument.Acoustic_Grand_Piano;
-    }
 
-} 
-                }
+    }
+}