浏览代码

refactor: handle all remaining undefined checks (#783)

close #783
sschmid 5 年之前
父节点
当前提交
341341be81
共有 33 个文件被更改,包括 128 次插入128 次删除
  1. 7 7
      src/MusicalScore/Graphical/MusicSheetCalculator.ts
  2. 1 1
      src/MusicalScore/Graphical/MusicSystem.ts
  3. 6 6
      src/MusicalScore/Graphical/MusicSystemBuilder.ts
  4. 2 2
      src/MusicalScore/Graphical/SkyBottomLineCalculator.ts
  5. 2 2
      src/MusicalScore/Graphical/VexFlow/VexFlowConverter.ts
  6. 12 12
      src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts
  7. 8 8
      src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts
  8. 1 1
      src/MusicalScore/Graphical/VexFlow/VexFlowTabMeasure.ts
  9. 1 1
      src/MusicalScore/Interfaces/ITextTranslation.ts
  10. 3 3
      src/MusicalScore/MusicParts/MusicPartManager.ts
  11. 8 8
      src/MusicalScore/MusicParts/MusicPartManagerIterator.ts
  12. 14 14
      src/MusicalScore/ScoreIO/InstrumentReader.ts
  13. 19 19
      src/MusicalScore/ScoreIO/MusicSheetReader.ts
  14. 3 3
      src/MusicalScore/ScoreIO/MusicSymbolModules/ChordSymbolReader.ts
  15. 10 10
      src/MusicalScore/ScoreIO/MusicSymbolModules/ExpressionReader.ts
  16. 1 1
      src/MusicalScore/ScoreIO/MusicSymbolModules/SlurReader.ts
  17. 4 4
      src/MusicalScore/ScoreIO/VoiceGenerator.ts
  18. 2 2
      src/MusicalScore/VoiceData/Expressions/ContinuousExpressions/ContinuousDynamicExpression.ts
  19. 1 1
      src/MusicalScore/VoiceData/Expressions/ContinuousExpressions/ContinuousTempoExpression.ts
  20. 3 3
      src/MusicalScore/VoiceData/Expressions/ContinuousExpressions/Slur.ts
  21. 1 1
      src/MusicalScore/VoiceData/Expressions/InstantaneousDynamicExpression.ts
  22. 1 1
      src/MusicalScore/VoiceData/Expressions/InstantaneousTempoExpression.ts
  23. 1 1
      src/MusicalScore/VoiceData/Expressions/MoodExpression.ts
  24. 1 1
      src/MusicalScore/VoiceData/Expressions/UnknownExpression.ts
  25. 1 1
      src/MusicalScore/VoiceData/Instructions/ClefInstruction.ts
  26. 1 1
      src/MusicalScore/VoiceData/Instructions/KeyInstruction.ts
  27. 1 1
      src/MusicalScore/VoiceData/Instructions/RepetitionInstruction.ts
  28. 1 1
      src/MusicalScore/VoiceData/Instructions/RhythmInstruction.ts
  29. 1 1
      src/MusicalScore/VoiceData/Note.ts
  30. 2 2
      src/MusicalScore/VoiceData/Notehead.ts
  31. 4 4
      src/MusicalScore/VoiceData/SourceMeasure.ts
  32. 2 2
      src/MusicalScore/VoiceData/VoiceEntry.ts
  33. 3 3
      src/OpenSheetMusicDisplay/Cursor.ts

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

@@ -1536,7 +1536,7 @@ export abstract class MusicSheetCalculator {
 
         for (let idx: number = 0, len: number = voiceEntry.Notes.length; idx < len; ++idx) {
             const note: Note = voiceEntry.Notes[idx];
-            if (note === undefined) {
+            if (!note) {
                 continue;
             }
             if (sourceStaffEntry !== undefined && sourceStaffEntry.Link !== undefined && linkedNotes !== undefined && linkedNotes.indexOf(note) > -1) {
@@ -1690,7 +1690,7 @@ export abstract class MusicSheetCalculator {
                         const gse: GraphicalStaffEntry = measure.staffEntries[0];
                         if (gse.graphicalVoiceEntries.length > 0 && gse.graphicalVoiceEntries[0].notes.length === 1) {
                             const graphicalNote: GraphicalNote = gse.graphicalVoiceEntries[0].notes[0];
-                            if (graphicalNote.sourceNote.Pitch === undefined && (new Fraction(1, 2)).lt(graphicalNote.sourceNote.Length)) {
+                            if (!graphicalNote.sourceNote.Pitch && (new Fraction(1, 2)).lt(graphicalNote.sourceNote.Length)) {
                                 this.layoutMeasureWithWholeRest(graphicalNote, gse, measure);
                             }
                         }
@@ -1709,13 +1709,13 @@ export abstract class MusicSheetCalculator {
             return;
         }
         const voice1Note1: GraphicalNote = voice1Notes[0];
-        const voice1Note1IsRest: boolean = voice1Note1.sourceNote.Pitch === undefined;
+        const voice1Note1IsRest: boolean = voice1Note1.sourceNote.isRest();
         if (graphicalStaffEntry.graphicalVoiceEntries.length === 2) {
             let voice2Note1IsRest: boolean = false;
             const voice2Notes: GraphicalNote[] = graphicalStaffEntry.graphicalVoiceEntries[1].notes;
             if (voice2Notes.length > 0) {
                 const voice2Note1: GraphicalNote = voice2Notes[0];
-                voice2Note1IsRest = voice2Note1.sourceNote.Pitch === undefined;
+                voice2Note1IsRest = voice2Note1.sourceNote.isRest();
             }
             if (voice1Note1IsRest && voice2Note1IsRest) {
                 this.calculateTwoRestNotesPlacementWithCollisionDetection(graphicalStaffEntry);
@@ -2561,7 +2561,7 @@ export abstract class MusicSheetCalculator {
             index < this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers.length;
             ++index) {
             const gse: GraphicalStaffEntry = this.graphicalMusicSheet.VerticalGraphicalStaffEntryContainers[index].StaffEntries[staffIndex];
-            if (gse === undefined) {
+            if (!gse) {
                 continue;
             }
             if (gse.hasOnlyRests()) {
@@ -2573,7 +2573,7 @@ export abstract class MusicSheetCalculator {
             endStaffEntry = gse;
             endStaffLine = <StaffLine>endStaffEntry.parentMeasure.ParentStaffLine;
         }
-        if (endStaffEntry === undefined) {
+        if (!endStaffEntry) {
             return;
         }
         // if on the same StaffLine
@@ -2606,7 +2606,7 @@ export abstract class MusicSheetCalculator {
             startY -= lyricEntry.GraphicalLabel.PositionAndShape.Size.height / 4;
             // first Underscore until the StaffLine's End
             this.calculateSingleLyricWordWithUnderscore(startStaffLine, startX, endX, startY);
-            if (endStaffEntry === undefined) {
+            if (!endStaffEntry) {
                 return;
             }
             // second Underscore in the endStaffLine until endStaffEntry (if endStaffEntry isn't the first StaffEntry of the StaffLine))

+ 1 - 1
src/MusicalScore/Graphical/MusicSystem.ts

@@ -257,7 +257,7 @@ export abstract class MusicSystem extends GraphicalObject {
             }
             const instrument1: Instrument = this.findFirstVisibleInstrumentInInstrumentalGroup(instrumentGroup);
             const instrument2: Instrument = this.findLastVisibleInstrumentInInstrumentalGroup(instrumentGroup);
-            if (instrument1 === undefined || instrument2 === undefined) {
+            if (!instrument1 || !instrument2) {
                 continue;
             }
             let firstStaffLine: StaffLine = undefined;

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

@@ -464,13 +464,13 @@ export class MusicSystemBuilder {
             }
         }
         if (isSystemStartMeasure) {
-            if (currentClef === undefined) {
+            if (!currentClef) {
                 currentClef = this.activeClefs[visibleStaffIdx];
             }
-            if (currentKey === undefined) {
+            if (!currentKey) {
                 currentKey = this.activeKeys[visibleStaffIdx];
             }
-            if (isFirstSourceMeasure && currentRhythm === undefined) {
+            if (isFirstSourceMeasure && !currentRhythm) {
                 currentRhythm = this.activeRhythm[visibleStaffIdx];
             }
         }
@@ -503,7 +503,7 @@ export class MusicSystemBuilder {
     }
 
     protected addInstructionsAtMeasureEnd(lastEntry: SourceStaffEntry, measure: GraphicalMeasure): number {
-        if (lastEntry === undefined || lastEntry.Instructions === undefined || lastEntry.Instructions.length === 0) {
+        if (!lastEntry || !lastEntry.Instructions || lastEntry.Instructions.length === 0) {
             return 0;
         }
         for (let idx: number = 0, len: number = lastEntry.Instructions.length; idx < len; ++idx) {
@@ -578,7 +578,7 @@ export class MusicSystemBuilder {
         let maxMeasureWidth: number = 0;
         for (let visStaffIdx: number = 0, len: number = visibleInstructionEntries.length; visStaffIdx < len; ++visStaffIdx) {
             const sse: SourceStaffEntry = visibleInstructionEntries[visStaffIdx];
-            if (sse === undefined) {
+            if (!sse) {
                 continue;
             }
             const instructions: AbstractNotationInstruction[] = sse.Instructions;
@@ -823,7 +823,7 @@ export class MusicSystemBuilder {
         if (this.measureListIndex < this.measureList.length - 1) {
             for (let visIndex: number = 0; visIndex < this.measureList[this.measureListIndex].length; visIndex++) {
                 const sourceMeasure: SourceMeasure = this.measureList[this.measureListIndex + 1][visIndex].parentSourceMeasure;
-                if (sourceMeasure === undefined) {
+                if (!sourceMeasure) {
                     return undefined;
                 }
                 return sourceMeasure.getKeyInstruction(this.visibleStaffIndices[visIndex]);

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

@@ -488,7 +488,7 @@ export class SkyBottomLineCalculator {
         startIndex = Math.floor(startIndex * this.SamplingUnit);
         endIndex = Math.ceil(endIndex * this.SamplingUnit);
 
-        if (skyBottomArray === undefined) {
+        if (!skyBottomArray) {
             // Highly questionable
             return Number.MAX_VALUE;
         }
@@ -521,7 +521,7 @@ export class SkyBottomLineCalculator {
         startIndex = Math.floor(startIndex * this.SamplingUnit);
         endIndex = Math.ceil(endIndex * this.SamplingUnit);
 
-        if (skyBottomArray === undefined) {
+        if (!skyBottomArray) {
             // Highly questionable
             return Number.MIN_VALUE;
         }

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

@@ -369,7 +369,7 @@ export class VexFlowConverter {
     }
 
     public static generateArticulations(vfnote: Vex.Flow.StemmableNote, articulations: ArticulationEnum[]): void {
-        if (vfnote === undefined || vfnote.getAttribute("type") === "GhostNote") {
+        if (!vfnote || vfnote.getAttribute("type") === "GhostNote") {
             return;
         }
         // Articulations:
@@ -683,7 +683,7 @@ export class VexFlowConverter {
      * @returns {string}
      */
     public static keySignature(key: KeyInstruction): string {
-        if (key === undefined) {
+        if (!key) {
             return undefined;
         }
         let ret: string;

+ 12 - 12
src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts

@@ -623,7 +623,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
             }
 
             // check if this voice has just been found the first time:
-            if (latestVoiceTimestamp === undefined) {
+            if (!latestVoiceTimestamp) {
                 // if this voice is new, check for a gap from measure start to the start of the current voice entry:
                 const gapFromMeasureStart: Fraction = Fraction.minus(gNotesStartTimestamp, this.parentSourceMeasure.AbsoluteTimestamp);
                 if (gapFromMeasureStart.RealValue > 0) {
@@ -677,7 +677,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
     public handleBeam(graphicalNote: GraphicalNote, beam: Beam): void {
         const voiceID: number = graphicalNote.sourceNote.ParentVoiceEntry.ParentVoice.VoiceId;
         let beams: [Beam, VexFlowVoiceEntry[]][] = this.beams[voiceID];
-        if (beams === undefined) {
+        if (!beams) {
             beams = this.beams[voiceID] = [];
         }
         let data: [Beam, VexFlowVoiceEntry[]];
@@ -686,7 +686,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
                 data = mybeam;
             }
         }
-        if (data === undefined) {
+        if (!data) {
             data = [beam, []];
             beams.push(data);
         }
@@ -700,7 +700,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
         const voiceID: number = graphicalNote.sourceNote.ParentVoiceEntry.ParentVoice.VoiceId;
         tuplet = graphicalNote.sourceNote.NoteTuplet;
         let tuplets: [Tuplet, VexFlowVoiceEntry[]][] = this.tuplets[voiceID];
-        if (tuplets === undefined) {
+        if (!tuplets) {
             tuplets = this.tuplets[voiceID] = [];
         }
         let currentTupletBuilder: [Tuplet, VexFlowVoiceEntry[]];
@@ -709,7 +709,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
                 currentTupletBuilder = t;
             }
         }
-        if (currentTupletBuilder === undefined) {
+        if (!currentTupletBuilder) {
             currentTupletBuilder = [tuplet, []];
             tuplets.push(currentTupletBuilder);
         }
@@ -731,7 +731,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
         for (const voiceID in this.beams) {
             if (this.beams.hasOwnProperty(voiceID)) {
                 let vfbeams: Vex.Flow.Beam[] = this.vfbeams[voiceID];
-                if (vfbeams === undefined) {
+                if (!vfbeams) {
                     vfbeams = this.vfbeams[voiceID] = [];
                 }
                 for (const beam of this.beams[voiceID]) {
@@ -739,7 +739,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
                     for (const note of beam[0].Notes) {
                         if (note.Length.RealValue >= new Fraction(1, 4).RealValue
                             // check whether the note has a TypeLength that's also not suitable for a beam (bigger than an eigth)
-                            && (note.TypeLength === undefined || note.TypeLength.RealValue > 0.125)) {
+                            && (!note.TypeLength || note.TypeLength.RealValue > 0.125)) {
                             beamHasQuarterNoteOrLonger = true;
                             break;
                         }
@@ -818,7 +818,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
         const separateAutoBeams: StemmableNote[][] = []; // a set of separate beams, each having a set of notes (StemmableNote[]).
         this.autoVfBeams = []; // final Vex.Flow.Beams will be pushed/collected into this
         let timeSignature: Fraction = this.parentSourceMeasure.ActiveTimeSignature;
-        if (timeSignature === undefined) { // this doesn't happen in OSMD, but maybe in a SourceGenerator
+        if (!timeSignature) { // this doesn't happen in OSMD, but maybe in a SourceGenerator
             timeSignature = this.parentSourceMeasure.Duration; // suboptimal, can be 1/1 in a 4/4 time signature
         }
         /*if (this.parentSourceMeasure.FirstInstructionsStaffEntries[0]) {
@@ -885,7 +885,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
                         }
                     }
 
-                    if (currentTuplet === undefined) {
+                    if (!currentTuplet) {
                         currentTuplet = noteTuplet;
                     } else {
                         if (currentTuplet !== noteTuplet) { // new tuplet, finish old one
@@ -951,7 +951,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
         for (const voiceID in this.tuplets) {
             if (this.tuplets.hasOwnProperty(voiceID)) {
                 let vftuplets: Vex.Flow.Tuplet[] = this.vftuplets[voiceID];
-                if (vftuplets === undefined) {
+                if (!vftuplets) {
                     vftuplets = this.vftuplets[voiceID] = [];
                 }
                 for (const tupletBuilder of this.tuplets[voiceID]) {
@@ -1049,7 +1049,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
         const voices: Voice[] = this.getVoicesWithinMeasure();
 
         for (const voice of voices) {
-            if (voice === undefined) {
+            if (!voice) {
                 continue;
             }
             const isMainVoice: boolean = !(voice instanceof LinkedVoice);
@@ -1137,7 +1137,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
             for ( const gVoiceEntry of vfStaffEntry.graphicalVoiceEntries) {
                 for ( const gnote of gVoiceEntry.notes) {
                     const vfnote: [StaveNote, number] = (gnote as VexFlowGraphicalNote).vfnote;
-                    if (vfnote === undefined || vfnote[0] === undefined) {
+                    if (!vfnote || !vfnote[0]) {
                         continue;
                     }
 

+ 8 - 8
src/MusicalScore/Graphical/VexFlow/VexFlowMusicSheetCalculator.ts

@@ -281,7 +281,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
             if (syllables.length > 1) {
               if (lyricsEntry.LyricsEntry.SyllableIndex < syllables.length - 1) {
                 // if a middle syllable of a word, give less measure overlap into next measure, to give room for dash
-                if (this.dashSpace === undefined) {
+                if (this.dashSpace === undefined) { // don't replace undefined check
                   this.dashSpace = 1.5;
                   // better method, doesn't work:
                   // this.dashLength = new GraphicalLabel(new Label("-"), this.rules.LyricsHeight, TextAlignmentEnum.CenterBottom)
@@ -624,21 +624,21 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
     if (endMeasure && startStaffLine && endStaffLine) {
       // calculate GraphicalOctaveShift and RelativePositions
       const graphicalOctaveShift: VexFlowOctaveShift = new VexFlowOctaveShift(octaveShift, startStaffLine.PositionAndShape);
-      if (graphicalOctaveShift.getStartNote() === undefined) { // fix for rendering range set
+      if (!graphicalOctaveShift.getStartNote()) { // fix for rendering range set
         graphicalOctaveShift.setStartNote(startMeasure.staffEntries[0]);
       }
-      if (graphicalOctaveShift.getStartNote() === undefined) { // fix for rendering range set
+      if (!graphicalOctaveShift.getStartNote()) { // fix for rendering range set
         graphicalOctaveShift.setEndNote(endMeasure.staffEntries.last());
       }
       startStaffLine.OctaveShifts.push(graphicalOctaveShift);
 
       // calculate RelativePosition and Dashes
       let startStaffEntry: GraphicalStaffEntry = startMeasure.findGraphicalStaffEntryFromTimestamp(startTimeStamp);
-      if (startStaffEntry === undefined) { // fix for rendering range set
+      if (!startStaffEntry) { // fix for rendering range set
         startStaffEntry = startMeasure.staffEntries[0];
       }
       let endStaffEntry: GraphicalStaffEntry = endMeasure.findGraphicalStaffEntryFromTimestamp(endTimeStamp);
-      if (endStaffEntry === undefined) { // fix for rendering range set
+      if (!endStaffEntry) { // fix for rendering range set
         endStaffEntry = endMeasure.staffEntries[endMeasure.staffEntries.length - 1];
       }
 
@@ -647,7 +647,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
       if (endStaffLine !== startStaffLine) {
         graphicalOctaveShift.endsOnDifferentStaffLine = true;
         let lastMeasure: GraphicalMeasure = startStaffLine.Measures[startStaffLine.Measures.length - 1];
-        if (lastMeasure === undefined) { // TODO handle this case correctly (when drawUpToMeasureNumber etc set)
+        if (!lastMeasure) { // TODO handle this case correctly (when drawUpToMeasureNumber etc set)
           lastMeasure = endMeasure;
         }
         const lastNote: GraphicalStaffEntry = lastMeasure.staffEntries[lastMeasure.staffEntries.length - 1];
@@ -657,7 +657,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
         const remainingOctaveShift: VexFlowOctaveShift = new VexFlowOctaveShift(octaveShift, endMeasure.PositionAndShape);
         endStaffLine.OctaveShifts.push(remainingOctaveShift);
         let firstMeasure: GraphicalMeasure = endStaffLine.Measures[0];
-        if (firstMeasure === undefined) { // TODO handle this case correctly (when drawUpToMeasureNumber etc set)
+        if (!firstMeasure) { // TODO handle this case correctly (when drawUpToMeasureNumber etc set)
           firstMeasure = startMeasure;
         }
         const firstNote: GraphicalStaffEntry = firstMeasure.staffEntries[0];
@@ -928,7 +928,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
                 for (const graphicalNote of graphicalVoiceEntry.notes) {
                   for (const slur of graphicalNote.sourceNote.NoteSlurs) {
                     // extra check for some MusicSheets that have openSlurs (because only the first Page is available -> Recordare files)
-                    if (slur.EndNote === undefined || slur.StartNote === undefined) {
+                    if (!slur.EndNote || !slur.StartNote) {
                       continue;
                     }
                     // add new VexFlowSlur to List

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

@@ -51,7 +51,7 @@ export class VexFlowTabMeasure extends VexFlowMeasure {
         const voices: Voice[] = this.getVoicesWithinMeasure();
 
         for (const voice of voices) {
-            if (voice === undefined) {
+            if (!voice) {
                 continue;
             }
 

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

@@ -2,7 +2,7 @@ export class ITextTranslation {
     public static defaultTextTranslation: ITextTranslation;
 
     public static translateText(tag: string, text: string): string {
-        if (this.defaultTextTranslation === undefined) {
+        if (!this.defaultTextTranslation) {
             return text;
         }
 

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

@@ -54,7 +54,7 @@ export class MusicPartManager /*implements ISelectionListener*/ {
         return this.musicSheet;
     }
     public getIterator(start?: Fraction): MusicPartManagerIterator {
-        if (start === undefined) {
+        if (!start) {
           return new MusicPartManagerIterator(this, this.musicSheet.SelectionStart, this.musicSheet.SelectionEnd);
         }
         return new MusicPartManagerIterator(this, start, undefined);
@@ -64,8 +64,8 @@ export class MusicPartManager /*implements ISelectionListener*/ {
         this.musicSheet.SelectionEnd = undefined;
     }
     public setSelectionRange(start: Fraction, end: Fraction): void {
-        this.musicSheet.SelectionStart = start === undefined ? this.sheetStart : start;
-        this.musicSheet.SelectionEnd = end === undefined ? this.sheetEnd : end;
+        this.musicSheet.SelectionStart = start ?? this.sheetStart;
+        this.musicSheet.SelectionEnd = end ?? this.sheetEnd;
     }
     private calcMapping(): void {
         const timestamps: TimestampTransform[] = [];

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

@@ -31,7 +31,7 @@ export class MusicPartManagerIterator {
             if (!startTimestamp) { return; }
             do {
                 this.moveToNext();
-            } while ((this.currentVoiceEntries === undefined || this.currentTimeStamp.lt(startTimestamp)) && !this.endReached);
+            } while ((!this.currentVoiceEntries || this.currentTimeStamp.lt(startTimestamp)) && !this.endReached);
             for (let staffIndex: number = 0; staffIndex < this.activeDynamicExpressions.length; staffIndex++) {
                 if (this.activeDynamicExpressions[staffIndex]) {
                     if (this.activeDynamicExpressions[staffIndex] instanceof ContinuousDynamicExpression) {
@@ -153,7 +153,7 @@ export class MusicPartManagerIterator {
      */
     public CurrentVisibleVoiceEntries(instrument?: Instrument): VoiceEntry[] {
         const voiceEntries: VoiceEntry[] = [];
-        if (this.currentVoiceEntries === undefined) {
+        if (!this.currentVoiceEntries) {
             return voiceEntries;
         }
         if (instrument) {
@@ -178,7 +178,7 @@ export class MusicPartManagerIterator {
      */
     public CurrentAudibleVoiceEntries(instrument?: Instrument): VoiceEntry[] {
         const voiceEntries: VoiceEntry[] = [];
-        if (this.currentVoiceEntries === undefined) {
+        if (!this.currentVoiceEntries) {
             return voiceEntries;
         }
         if (instrument) {
@@ -212,7 +212,7 @@ export class MusicPartManagerIterator {
      */
     public CurrentScoreFollowingVoiceEntries(instrument?: Instrument): VoiceEntry[] {
         const voiceEntries: VoiceEntry[] = [];
-        if (this.currentVoiceEntries === undefined) {
+        if (!this.currentVoiceEntries) {
             return voiceEntries;
         }
         if (instrument) {
@@ -240,7 +240,7 @@ export class MusicPartManagerIterator {
             this.currentVoiceEntries = [];
         }
         this.recursiveMove();
-        if (this.currentMeasure === undefined) {
+        if (!this.currentMeasure) {
             this.currentTimeStamp = new Fraction(99999, 1);
         }
     }
@@ -324,7 +324,7 @@ export class MusicPartManagerIterator {
     private handleRepetitionsAtMeasureBegin(): void {
         for (let idx: number = 0, len: number = this.currentMeasure.FirstRepetitionInstructions.length; idx < len; ++idx) {
             const repetitionInstruction: RepetitionInstruction = this.currentMeasure.FirstRepetitionInstructions[idx];
-            if (repetitionInstruction.parentRepetition === undefined) { continue; }
+            if (!repetitionInstruction.parentRepetition) { continue; }
             const currentRepetition: Repetition = repetitionInstruction.parentRepetition;
             this.currentRepetition = currentRepetition;
             if (currentRepetition.StartIndex === this.currentMeasureIndex) {
@@ -344,7 +344,7 @@ export class MusicPartManagerIterator {
         for (let idx: number = 0, len: number = this.currentMeasure.LastRepetitionInstructions.length; idx < len; ++idx) {
             const repetitionInstruction: RepetitionInstruction = this.currentMeasure.LastRepetitionInstructions[idx];
             const currentRepetition: Repetition = repetitionInstruction.parentRepetition;
-            if (currentRepetition === undefined) { continue; }
+            if (!currentRepetition) { continue; }
             if (currentRepetition.BackwardJumpInstructions.indexOf(repetitionInstruction) > -1) {
                 if (this.getRepetitionIterationCount(currentRepetition) < currentRepetition.UserNumberOfRepetitions) {
                     this.doBackJump(currentRepetition);
@@ -562,7 +562,7 @@ export class MusicPartManagerIterator {
     private getVoiceEntries(container: VerticalSourceStaffEntryContainer): VoiceEntry[] {
         const entries: VoiceEntry[] = [];
         for (const sourceStaffEntry of container.StaffEntries) {
-            if (sourceStaffEntry === undefined) { continue; }
+            if (!sourceStaffEntry) { continue; }
             for (const voiceEntry of sourceStaffEntry.VoiceEntries) {
                 entries.push(voiceEntry);
             }

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

@@ -170,7 +170,7 @@ export class InstrumentReader {
             const noteVoice: number = parseInt(xmlNode.element("voice").value, 10);
             this.currentVoiceGenerator = this.getOrCreateVoiceGenerator(noteVoice, noteStaff - 1);
           } else {
-            if (!isChord || this.currentVoiceGenerator === undefined) {
+            if (!isChord || !this.currentVoiceGenerator) {
               this.currentVoiceGenerator = this.getOrCreateVoiceGenerator(1, noteStaff - 1);
             }
           }
@@ -316,10 +316,10 @@ export class InstrumentReader {
           const noteColorAttr: Attr = xmlNode.attribute("color");
           if (noteColorAttr) { // can be undefined
             noteColorXml = this.parseXmlColor(noteColorAttr.value);
-            if (noteheadColorXml === undefined) {
+            if (!noteheadColorXml) {
               noteheadColorXml = noteColorXml;
             }
-            if (stemColorXml === undefined) {
+            if (!stemColorXml) {
               stemColorXml = noteColorXml;
             }
           }
@@ -414,7 +414,7 @@ export class InstrumentReader {
 
           }
           if (
-            xmlNode.element("divisions") === undefined &&
+            !xmlNode.element("divisions") &&
             this.divisions === 0 &&
             this.currentXmlMeasureIndex === 0
           ) {
@@ -635,7 +635,7 @@ export class InstrumentReader {
     }
     const clefInstruction: ClefInstruction = new ClefInstruction(ClefEnum.G, 0, 2);
     let firstStaffEntry: SourceStaffEntry;
-    if (first.FirstInstructionsStaffEntries[staffIndex] === undefined) {
+    if (!first.FirstInstructionsStaffEntries[staffIndex]) {
       firstStaffEntry = new SourceStaffEntry(undefined, undefined);
       first.FirstInstructionsStaffEntries[staffIndex] = firstStaffEntry;
     } else {
@@ -658,7 +658,7 @@ export class InstrumentReader {
     }
     const keyInstruction: KeyInstruction = new KeyInstruction(undefined, 0, KeyEnum.major);
     for (let j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + this.instrument.Staves.length; j++) {
-      if (first.FirstInstructionsStaffEntries[j] === undefined) {
+      if (!first.FirstInstructionsStaffEntries[j]) {
         const firstStaffEntry: SourceStaffEntry = new SourceStaffEntry(undefined, undefined);
         first.FirstInstructionsStaffEntries[j] = firstStaffEntry;
         keyInstruction.Parent = firstStaffEntry;
@@ -995,7 +995,7 @@ export class InstrumentReader {
               const sseIndex: number = this.inSourceMeasureInstrumentIndex + key - 1;
               const firstSse: SourceStaffEntry = this.currentMeasure.FirstInstructionsStaffEntries[sseIndex];
               if (this.currentXmlMeasureIndex === 0) {
-                if (firstSse === undefined) {
+                if (!firstSse) {
                   firstStaffEntry = new SourceStaffEntry(undefined, undefined);
                   this.currentMeasure.FirstInstructionsStaffEntries[sseIndex] = firstStaffEntry;
                   newClefInstruction.Parent = firstStaffEntry;
@@ -1017,7 +1017,7 @@ export class InstrumentReader {
                 }
               } else if (!this.activeClefsHaveBeenInitialized[key - 1]) {
                 const first: SourceMeasure = this.musicSheet.SourceMeasures[0];
-                if (first.FirstInstructionsStaffEntries[sseIndex] === undefined) {
+                if (!first.FirstInstructionsStaffEntries[sseIndex]) {
                   firstStaffEntry = new SourceStaffEntry(undefined, undefined);
                 } else {
                   firstStaffEntry = first.FirstInstructionsStaffEntries[sseIndex];
@@ -1042,7 +1042,7 @@ export class InstrumentReader {
       }
       if (value instanceof KeyInstruction) {
         const keyInstruction: KeyInstruction = <KeyInstruction>value;
-        if (this.activeKey === undefined || this.activeKey.Key !== keyInstruction.Key) {
+        if (!this.activeKey || this.activeKey.Key !== keyInstruction.Key) {
           this.activeKey = keyInstruction;
           this.abstractInstructions.splice(i, 1);
           let sourceMeasure: SourceMeasure;
@@ -1059,7 +1059,7 @@ export class InstrumentReader {
           if (sourceMeasure) {
             for (let j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + numberOfStaves; j++) {
               const newKeyInstruction: KeyInstruction = keyInstruction;
-              if (sourceMeasure.FirstInstructionsStaffEntries[j] === undefined) {
+              if (!sourceMeasure.FirstInstructionsStaffEntries[j]) {
                 const firstStaffEntry: SourceStaffEntry = new SourceStaffEntry(undefined, undefined);
                 sourceMeasure.FirstInstructionsStaffEntries[j] = firstStaffEntry;
                 newKeyInstruction.Parent = firstStaffEntry;
@@ -1086,14 +1086,14 @@ export class InstrumentReader {
       }
       if (value instanceof RhythmInstruction) {
         const rhythmInstruction: RhythmInstruction = <RhythmInstruction>value;
-        if (this.activeRhythm === undefined || this.activeRhythm !== rhythmInstruction) {
+        if (!this.activeRhythm || this.activeRhythm !== rhythmInstruction) {
           this.activeRhythm = rhythmInstruction;
           this.abstractInstructions.splice(i, 1);
           if (this.currentMeasure) {
             for (let j: number = this.inSourceMeasureInstrumentIndex; j < this.inSourceMeasureInstrumentIndex + numberOfStaves; j++) {
               const newRhythmInstruction: RhythmInstruction = rhythmInstruction;
               let firstStaffEntry: SourceStaffEntry;
-              if (this.currentMeasure.FirstInstructionsStaffEntries[j] === undefined) {
+              if (!this.currentMeasure.FirstInstructionsStaffEntries[j]) {
                 firstStaffEntry = new SourceStaffEntry(undefined, undefined);
                 this.currentMeasure.FirstInstructionsStaffEntries[j] = firstStaffEntry;
               } else {
@@ -1121,7 +1121,7 @@ export class InstrumentReader {
       if (value instanceof ClefInstruction) {
         const clefInstruction: ClefInstruction = <ClefInstruction>value;
         if (
-          (this.activeClefs[key - 1] === undefined) ||
+          (!this.activeClefs[key - 1]) ||
           (clefInstruction.ClefType !== this.activeClefs[key - 1].ClefType || (
             clefInstruction.ClefType === this.activeClefs[key - 1].ClefType &&
             clefInstruction.Line !== this.activeClefs[key - 1].Line
@@ -1200,7 +1200,7 @@ export class InstrumentReader {
       const xmlMeasureListArr: IXmlElement[] = this.xmlMeasureList[xmlMeasureIndex].elements();
       for (let idx: number = 0, len: number = xmlMeasureListArr.length; idx < len; ++idx) {
         const xmlNode: IXmlElement = xmlMeasureListArr[idx];
-        if (xmlNode.name === "note" && xmlNode.element("time-modification") === undefined) {
+        if (xmlNode.name === "note" && !xmlNode.element("time-modification")) {
           const durationNode: IXmlElement = xmlNode.element("duration");
           const typeNode: IXmlElement = xmlNode.element("type");
           if (durationNode !== undefined && typeNode) {

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

@@ -26,7 +26,7 @@ import {EngravingRules} from "../Graphical";
 export class MusicSheetReader /*implements IMusicSheetReader*/ {
 
     constructor(afterSheetReadingModules: IAfterSheetReadingModule[] = undefined, rules: EngravingRules = new EngravingRules()) {
-     if (afterSheetReadingModules === undefined) {
+     if (!afterSheetReadingModules) {
        this.afterSheetReadingModules = [];
      } else {
        this.afterSheetReadingModules = afterSheetReadingModules;
@@ -120,12 +120,12 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         this.musicSheet = new MusicSheet();
         this.musicSheet.Path = path;
         this.musicSheet.Rules = this.rules;
-        if (root === undefined) {
+        if (!root) {
             throw new MusicSheetReadingException("Undefined root element");
         }
         this.pushSheetLabels(root, path);
         const partlistNode: IXmlElement = root.element("part-list");
-        if (partlistNode === undefined) {
+        if (!partlistNode) {
             throw new MusicSheetReadingException("Undefined partListNode");
         }
 
@@ -271,7 +271,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                     this.currentMeasure.FirstInstructionsStaffEntries[i].removeAllInstructionsOfTypeRhythmInstruction();
                     this.currentMeasure.FirstInstructionsStaffEntries[i].Instructions.push(rhythmInstruction.clone());
                 }
-                if (this.currentMeasure.FirstInstructionsStaffEntries[i] === undefined) {
+                if (!this.currentMeasure.FirstInstructionsStaffEntries[i]) {
                     this.currentMeasure.FirstInstructionsStaffEntries[i] = new SourceStaffEntry(undefined, undefined);
                     this.currentMeasure.FirstInstructionsStaffEntries[i].Instructions.push(rhythmInstruction.clone());
                 }
@@ -284,7 +284,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         if (rhythmInstructions.length === 0 && this.currentMeasure === this.musicSheet.SourceMeasures[0]) {
             const rhythmInstruction: RhythmInstruction = new RhythmInstruction(new Fraction(4, 4, 0, false), RhythmSymbolEnum.NONE);
             for (let i: number = 0; i < this.completeNumberOfStaves; i++) {
-                if (this.currentMeasure.FirstInstructionsStaffEntries[i] === undefined) {
+                if (!this.currentMeasure.FirstInstructionsStaffEntries[i]) {
                     this.currentMeasure.FirstInstructionsStaffEntries[i] = new SourceStaffEntry(undefined, undefined);
                 } else {
                     this.currentMeasure.FirstInstructionsStaffEntries[i].removeAllInstructionsOfTypeRhythmInstruction();
@@ -415,7 +415,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
      * @returns {boolean}
      */
     private checkIfMeasureIsImplicit(maxInstrumentDuration: Fraction, activeRhythm: Fraction): boolean {
-        if (this.previousMeasure === undefined && maxInstrumentDuration.lt(activeRhythm)) {
+        if (!this.previousMeasure && maxInstrumentDuration.lt(activeRhythm)) {
             return true;
         }
         if (this.previousMeasure) {
@@ -444,7 +444,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
     private graphicalMeasureIsEmpty(index: number): boolean {
         let counter: number = 0;
         for (let i: number = 0; i < this.currentMeasure.VerticalSourceStaffEntryContainers.length; i++) {
-            if (this.currentMeasure.VerticalSourceStaffEntryContainers[i].StaffEntries[index] === undefined) {
+            if (!this.currentMeasure.VerticalSourceStaffEntryContainers[i].StaffEntries[index]) {
                 counter++;
             }
         }
@@ -477,7 +477,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
             let counter: number = 0;
             for (let idx: number = 0, len: number = this.currentMeasure.VerticalSourceStaffEntryContainers[i].StaffEntries.length; idx < len; ++idx) {
                 const sourceStaffEntry: SourceStaffEntry = this.currentMeasure.VerticalSourceStaffEntryContainers[i].StaffEntries[idx];
-                if (sourceStaffEntry === undefined) {
+                if (!sourceStaffEntry) {
                     counter++;
                 }
             }
@@ -496,14 +496,14 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         this.readComposer(root);
         this.readTitle(root);
         try {
-            if (this.musicSheet.Title === undefined || this.musicSheet.Composer === undefined) {
+            if (!this.musicSheet.Title || !this.musicSheet.Composer) {
                 this.readTitleAndComposerFromCredits(root); // this can also throw an error
             }
         } catch (ex) {
             log.info("MusicSheetReader.pushSheetLabels", "readTitleAndComposerFromCredits", ex);
         }
         try {
-            if (this.musicSheet.Title === undefined) {
+            if (!this.musicSheet.Title) {
                 const barI: number = Math.max(
                     0, filePath.lastIndexOf("/"), filePath.lastIndexOf("\\")
                 );
@@ -572,7 +572,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                     const creditY: string = creditChild.attribute("default-y").value;
                     const creditYInfo: number = parseFloat(creditY);
                     if (creditYInfo > systemYCoordinates) {
-                        if (this.musicSheet.Title === undefined) {
+                        if (!this.musicSheet.Title) {
                             const creditSize: string = creditChild.attribute("font-size").value;
                             const titleCreditSizeInt: number = parseFloat(creditSize);
                             if (largestTitleCreditSize < titleCreditSizeInt) {
@@ -580,7 +580,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                                 finalTitle = creditChild.value;
                             }
                         }
-                        if (this.musicSheet.Subtitle === undefined) {
+                        if (!this.musicSheet.Subtitle) {
                             if (creditJustify !== "right" && creditJustify !== "left") {
                                 if (largestCreditYInfo < creditYInfo) {
                                     largestCreditYInfo = creditYInfo;
@@ -609,16 +609,16 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                 }
             }
         }
-        if (this.musicSheet.Title === undefined && finalTitle) {
+        if (!this.musicSheet.Title && finalTitle) {
             this.musicSheet.Title = new Label(this.trimString(finalTitle));
         }
-        if (this.musicSheet.Subtitle === undefined && finalSubtitle) {
+        if (!this.musicSheet.Subtitle && finalSubtitle) {
             this.musicSheet.Subtitle = new Label(this.trimString(finalSubtitle));
         }
     }
 
     private computeSystemYCoordinates(root: IXmlElement): number {
-        if (root.element("defaults") === undefined) {
+        if (!root.element("defaults")) {
             return 0;
         }
         let paperHeight: number = 0;
@@ -672,14 +672,14 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
         let titleNodeChild: IXmlElement = undefined;
         if (titleNode) {
             titleNodeChild = titleNode.element("work-title");
-            if (titleNodeChild !== undefined && titleNodeChild.value) {
+            if (titleNodeChild && titleNodeChild.value) {
                 this.musicSheet.Title = new Label(this.trimString(titleNodeChild.value));
             }
         }
         const movementNode: IXmlElement = root.element("movement-title");
         let finalSubTitle: string = "";
         if (movementNode) {
-            if (this.musicSheet.Title === undefined) {
+            if (!this.musicSheet.Title) {
                 this.musicSheet.Title = new Label(this.trimString(movementNode.value));
             } else {
                 finalSubTitle = this.trimString(movementNode.value);
@@ -861,7 +861,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
                     if (stavesNode) {
                         stavesNode = stavesNode.element("staves");
                     }
-                    if (stavesNode === undefined) {
+                    if (!stavesNode) {
                         num++;
                     } else {
                         num += parseInt(stavesNode.value, 10);
@@ -892,7 +892,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
             if (attributes) {
                 staves = attributes.element("staves");
             }
-            if (attributes === undefined || staves === undefined) {
+            if (!attributes || !staves) {
                 num = 1;
             } else {
                 num = parseInt(staves.value, 10);

+ 3 - 3
src/MusicalScore/ScoreIO/MusicSymbolModules/ChordSymbolReader.ts

@@ -13,7 +13,7 @@ export class ChordSymbolReader {
         const kindText: IXmlAttribute = kind.attribute("text");
 
         // must be always present
-        if (root === undefined || kind === undefined) {
+        if (!root || !kind) {
           return undefined;
         }
 
@@ -21,7 +21,7 @@ export class ChordSymbolReader {
         const rootAlter: IXmlElement = root.element("root-alter");
 
         // a valid NoteEnum value should be present
-        if (rootStep === undefined) {
+        if (!rootStep) {
             return undefined;
         }
         let rootNote: NoteEnum;
@@ -112,7 +112,7 @@ export class ChordSymbolReader {
             const degreeValue: IXmlElement = degreeNode.element("degree-value");
             const degreeAlter: IXmlElement = degreeNode.element("degree-alter");
             const degreeType: IXmlElement = degreeNode.element("degree-type");
-            if (degreeValue === undefined || degreeAlter === undefined || degreeType === undefined) {
+            if (!degreeValue || !degreeAlter || !degreeType) {
               return undefined;
             }
 

+ 10 - 10
src/MusicalScore/ScoreIO/MusicSymbolModules/ExpressionReader.ts

@@ -152,7 +152,7 @@ export class ExpressionReader {
             }
         }
         const dirNode: IXmlElement = directionNode.element("direction-type");
-        if (dirNode === undefined) {
+        if (!dirNode) {
             return;
         }
         let dirContentNode: IXmlElement = dirNode.element("metronome");
@@ -320,8 +320,8 @@ export class ExpressionReader {
                 //     this.musicSheet.SheetErrors.pushMeasureError(errorMsg);
                 //     return;
                 // }
-                // if (this.activeInstantaneousDynamic === undefined ||
-                //     (this.activeInstantaneousDynamic !== undefined && this.activeInstantaneousDynamic.DynEnum !== dynamicEnum)) {
+                // if (!this.activeInstantaneousDynamic ||
+                //     (this.activeInstantaneousDynamic && this.activeInstantaneousDynamic.DynEnum !== dynamicEnum)) {
                 if (!fromNotation) {
                     this.createNewMultiExpressionIfNeeded(currentMeasure);
                 } else { this.createNewMultiExpressionIfNeeded(currentMeasure, Fraction.createFromFraction(inSourceMeasureCurrentFraction)); }
@@ -369,11 +369,11 @@ export class ExpressionReader {
         this.initialize();
     }
     private createNewMultiExpressionIfNeeded(currentMeasure: SourceMeasure, timestamp: Fraction = undefined): void {
-        if (timestamp === undefined) {
+        if (!timestamp) {
             timestamp = this.directionTimestamp;
         }
-        if (this.getMultiExpression === undefined ||
-            this.getMultiExpression !== undefined &&
+        if (!this.getMultiExpression ||
+            this.getMultiExpression &&
             (this.getMultiExpression.SourceMeasureParent !== currentMeasure ||
                 (this.getMultiExpression.SourceMeasureParent === currentMeasure && this.getMultiExpression.Timestamp !== timestamp))) {
             this.getMultiExpression = new MultiExpression(currentMeasure, Fraction.createFromFraction(timestamp));
@@ -382,7 +382,7 @@ export class ExpressionReader {
     }
 
     private createNewTempoExpressionIfNeeded(currentMeasure: SourceMeasure): void {
-        if (this.currentMultiTempoExpression === undefined ||
+        if (!this.currentMultiTempoExpression ||
             this.currentMultiTempoExpression.SourceMeasureParent !== currentMeasure ||
             this.currentMultiTempoExpression.Timestamp !== this.directionTimestamp) {
             this.currentMultiTempoExpression = new MultiTempoExpression(currentMeasure, Fraction.createFromFraction(this.directionTimestamp));
@@ -423,7 +423,7 @@ export class ExpressionReader {
         }
     }
     private fillMultiOrTempoExpression(inputString: string, currentMeasure: SourceMeasure): void {
-        if (inputString === undefined) {
+        if (!inputString) {
             return;
         }
         const tmpInputString: string = inputString.trim();
@@ -501,7 +501,7 @@ export class ExpressionReader {
             ContinuousDynamicExpression.isInputStringContinuousDynamic(stringTrimmed)) {
             this.createNewMultiExpressionIfNeeded(currentMeasure);
             if (InstantaneousDynamicExpression.isInputStringInstantaneousDynamic(stringTrimmed)) {
-                if (this.openContinuousDynamicExpression !== undefined && this.openContinuousDynamicExpression.EndMultiExpression === undefined) {
+                if (this.openContinuousDynamicExpression !== undefined && !this.openContinuousDynamicExpression.EndMultiExpression) {
                     this.closeOpenContinuousDynamic();
                 }
                 const instantaneousDynamicExpression: InstantaneousDynamicExpression =
@@ -522,7 +522,7 @@ export class ExpressionReader {
                         this.staffNumber,
                         currentMeasure,
                         stringTrimmed);
-                if (this.openContinuousDynamicExpression !== undefined && this.openContinuousDynamicExpression.EndMultiExpression === undefined) {
+                if (this.openContinuousDynamicExpression !== undefined && !this.openContinuousDynamicExpression.EndMultiExpression) {
                     this.closeOpenContinuousDynamic();
                 }
                 if (this.activeInstantaneousDynamic !== undefined && this.activeInstantaneousDynamic.StaffNumber === continuousDynamicExpression.StaffNumber) {

+ 1 - 1
src/MusicalScore/ScoreIO/MusicSymbolModules/SlurReader.ts

@@ -29,7 +29,7 @@ export class SlurReader {
 
                         if (type === "start") {
                             let slur: Slur = this.openSlurDict[slurNumber];
-                            if (slur === undefined) {
+                            if (!slur) {
                                 slur = new Slur();
                                 this.openSlurDict[slurNumber] = slur;
                             }

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

@@ -234,7 +234,7 @@ export class VoiceGenerator {
     const linkMusicTimestamp: Fraction = this.currentVoiceEntry.Timestamp.clone();
     const verticalSourceStaffEntryContainer: VerticalSourceStaffEntryContainer = currentMeasure.getVerticalContainerByTimestamp(linkMusicTimestamp);
     currentStaffEntry = verticalSourceStaffEntryContainer.StaffEntries[index];
-    if (currentStaffEntry === undefined) {
+    if (!currentStaffEntry) {
       currentStaffEntry = new SourceStaffEntry(verticalSourceStaffEntryContainer, currentStaff);
       verticalSourceStaffEntryContainer.StaffEntries[index] = currentStaffEntry;
     }
@@ -369,7 +369,7 @@ export class VoiceGenerator {
             try {
               if (pitchElement.name === "step") {
                 noteStep = NoteEnum[pitchElement.value];
-                if (noteStep === undefined) {
+                if (noteStep === undefined) { // don't replace undefined check
                   const errorMsg: string = ITextTranslation.translateText(
                     "ReaderErrorMessages/NotePitchError",
                     "Invalid pitch while reading note."
@@ -537,7 +537,7 @@ export class VoiceGenerator {
           this.lastBeamTag = currentBeamTag;
         }
         let sameVoiceEntry: boolean = false;
-        if (this.openBeam === undefined) {
+        if (!this.openBeam) {
             return;
           }
         for (let idx: number = 0, len: number = this.openBeam.Notes.length; idx < len; ++idx) {
@@ -718,7 +718,7 @@ export class VoiceGenerator {
             tupletnumber = this.openTupletNumber;
           }
           let tuplet: Tuplet = this.tupletDict[tupletnumber];
-          if (tuplet === undefined) {
+          if (!tuplet) {
             tuplet = this.tupletDict[tupletnumber] = new Tuplet(tupletLabelNumber, bracketed);
           }
           const subnotelist: Note[] = [];

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

@@ -79,7 +79,7 @@ export class ContinuousDynamicExpression extends AbstractExpression {
         this.setType();
     }
     public static isInputStringContinuousDynamic(inputString: string): boolean {
-        if (inputString === undefined) { return false; }
+        if (!inputString) { return false; }
         return (
             ContinuousDynamicExpression.isStringInStringList(ContinuousDynamicExpression.listContinuousDynamicIncreasing, inputString)
             || ContinuousDynamicExpression.isStringInStringList(ContinuousDynamicExpression.listContinuousDynamicDecreasing, inputString)
@@ -104,7 +104,7 @@ export class ContinuousDynamicExpression extends AbstractExpression {
         return interpolatedVolume;
     }
     public isWedge(): boolean {
-        return this.label === undefined;
+        return !this.label;
     }
     private setType(): void {
         if (ContinuousDynamicExpression.isStringInStringList(ContinuousDynamicExpression.listContinuousDynamicIncreasing, this.label)) {

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

@@ -24,7 +24,7 @@ export class ContinuousTempoExpression extends AbstractTempoExpression {
     private endTempo: number;
 
     public static isInputStringContinuousTempo(inputString: string): boolean {
-        if (inputString === undefined) { return false; }
+        if (!inputString) { return false; }
         return (
             ContinuousTempoExpression.isStringInStringList(ContinuousTempoExpression.listContinuousTempoFaster, inputString)
             || ContinuousTempoExpression.isStringInStringList(ContinuousTempoExpression.listContinuousTempoSlower, inputString)

+ 3 - 3
src/MusicalScore/VoiceData/Expressions/ContinuousExpressions/Slur.ts

@@ -22,7 +22,7 @@ export class Slur {
         this.endNote = value;
     }
     public startNoteHasMoreStartingSlurs(): boolean {
-        if (this.startNote === undefined) { return false; }
+        if (!this.startNote) { return false; }
         for (let idx: number = 0, len: number = this.startNote.NoteSlurs.length; idx < len; ++idx) {
             const slur: Slur = this.startNote.NoteSlurs[idx];
             if (slur !== this && slur.StartNote === this.startNote) {
@@ -32,7 +32,7 @@ export class Slur {
         return false;
     }
     public endNoteHasMoreEndingSlurs(): boolean {
-        if (this.endNote === undefined) { return false; }
+        if (!this.endNote) { return false; }
         for (let idx: number = 0, len: number = this.endNote.NoteSlurs.length; idx < len; ++idx) {
             const slur: Slur = this.endNote.NoteSlurs[idx];
             if (slur !== this && slur.EndNote === this.endNote) {
@@ -45,7 +45,7 @@ export class Slur {
         return (this.startNote.ParentStaffEntry.ParentStaff !== this.endNote.ParentStaffEntry.ParentStaff);
     }
     public isSlurLonger(): boolean {
-        if (this.endNote === undefined || this.startNote === undefined) {
+        if (!this.endNote || !this.startNote) {
             return false;
         }
         const length: Fraction = Fraction.minus(this.endNote.getAbsoluteTimestamp(), this.startNote.getAbsoluteTimestamp());

+ 1 - 1
src/MusicalScore/VoiceData/Expressions/InstantaneousDynamicExpression.ts

@@ -95,7 +95,7 @@ export class InstantaneousDynamicExpression extends AbstractExpression {
         return InstantaneousDynamicExpression.dynamicToRelativeVolumeDict[this.dynamicEnum] * 127;
     }
     public static isInputStringInstantaneousDynamic(inputString: string): boolean {
-        if (inputString === undefined) { return false; }
+        if (!inputString) { return false; }
         return InstantaneousDynamicExpression.isStringInStringList(InstantaneousDynamicExpression.listInstantaneousDynamics, inputString);
     }
 

+ 1 - 1
src/MusicalScore/VoiceData/Expressions/InstantaneousTempoExpression.ts

@@ -205,7 +205,7 @@ export class InstantaneousTempoExpression extends AbstractTempoExpression {
         }
     }
     public static isInputStringInstantaneousTempo(inputString: string): boolean {
-        if (inputString === undefined) { return false; }
+        if (!inputString) { return false; }
         return (
             (InstantaneousTempoExpression.isStringInStringList(InstantaneousTempoExpression.listInstantaneousTempoLarghissimo, inputString))
             || (InstantaneousTempoExpression.isStringInStringList(InstantaneousTempoExpression.listInstantaneousTempoGrave, inputString))

+ 1 - 1
src/MusicalScore/VoiceData/Expressions/MoodExpression.ts

@@ -48,7 +48,7 @@ export class MoodExpression extends AbstractExpression {
     private staffNumber: number;
 
     public static isInputStringMood(inputString: string): boolean {
-        if (inputString === undefined) {
+        if (!inputString) {
             return false;
         }
         return (

+ 1 - 1
src/MusicalScore/VoiceData/Expressions/UnknownExpression.ts

@@ -6,7 +6,7 @@ export class UnknownExpression extends AbstractExpression {
         super(placement);
         this.label = label;
         this.staffNumber = staffNumber;
-        if (textAlignment === undefined) {
+        if (textAlignment === undefined) { // don't replace undefined check
             textAlignment = TextAlignmentEnum.LeftBottom;
         }
         this.textAlignment = textAlignment;

+ 1 - 1
src/MusicalScore/VoiceData/Instructions/ClefInstruction.ts

@@ -117,7 +117,7 @@ export class ClefInstruction extends AbstractNotationInstruction {
         if (this === other) {
             return true;
         }
-        if (this === undefined || other === undefined) {
+        if (!this || !other) {
             return false;
         }
         return (this.clefPitch === other.clefPitch && this.Line === other.Line);

+ 1 - 1
src/MusicalScore/VoiceData/Instructions/KeyInstruction.ts

@@ -96,7 +96,7 @@ export class KeyInstruction extends AbstractNotationInstruction {
         if (key1 === key2) {
             return true;
         }
-        if ((key1 === undefined) || (key2 === undefined)) {
+        if (!key1 || !key2) {
             return false;
         }
         return (key1.Key === key2.Key && key1.Mode === key2.Mode);

+ 1 - 1
src/MusicalScore/VoiceData/Instructions/RepetitionInstruction.ts

@@ -132,7 +132,7 @@ export class RepetitionInstruction /*implements IComparable*/ {
         if (this.endingIndices === other.endingIndices) {
             return true;
         }
-        if (this.endingIndices === undefined || other.endingIndices === undefined ||
+        if (!this.endingIndices || !other.endingIndices ||
             this.endingIndices.length !== other.endingIndices.length) {
             return false;
         }

+ 1 - 1
src/MusicalScore/VoiceData/Instructions/RhythmInstruction.ts

@@ -43,7 +43,7 @@ export class RhythmInstruction extends AbstractNotationInstruction {
         if (rhythm1 === rhythm2) {
             return true;
         }
-        if ((<Object>rhythm1 === undefined) || (<Object>rhythm2 === undefined)) {
+        if (!rhythm1 || !rhythm2) {
             return false;
         }
         return (rhythm1.numerator === rhythm2.numerator && rhythm1.denominator === rhythm2.denominator);

+ 1 - 1
src/MusicalScore/VoiceData/Note.ts

@@ -216,7 +216,7 @@ export class Note {
     }
 
     public isRest(): boolean {
-        return this.Pitch === undefined;
+        return this.Pitch === undefined || this.Pitch === null;
     }
 
     /** Note: May be dangerous to use if ParentStaffEntry.VerticalContainerParent etc is not set.

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

@@ -34,8 +34,8 @@ export class Notehead {
         this.shape = Notehead.ShapeTypeXmlToShape(shapeTypeXml);
 
         let filled: boolean = filledXmlAttribute;
-        if (filled === undefined) {
-            if (this.sourceNote === undefined) {
+        if (filled === undefined) { // don't replace undefined check
+            if (!this.sourceNote) {
                 // this should not happen. Either filledXmlAttribute or sourceNote should be defined.
                 log.warn("notehead: sourceNote and filledXmlAttribute undefined.");
                 filled = true;

+ 4 - 4
src/MusicalScore/VoiceData/SourceMeasure.ts

@@ -272,7 +272,7 @@ export class SourceMeasure {
                 break;
             }
         }
-        if (ve === undefined) {
+        if (!ve) {
             ve = new VoiceEntry(sse.Timestamp, voice, sse);
             sse.VoiceEntries.push(ve);
             createdNewVoiceEntry = true;
@@ -333,7 +333,7 @@ export class SourceMeasure {
     public checkForEmptyVerticalContainer(index: number): void {
         let undefinedCounter: number = 0;
         for (let i: number = 0; i < this.completeNumberOfStaves; i++) {
-            if (this.verticalSourceStaffEntryContainers[index][i] === undefined) {
+            if (!this.verticalSourceStaffEntryContainers[index][i]) {
                 undefinedCounter++;
             }
         }
@@ -460,7 +460,7 @@ export class SourceMeasure {
             }
 
             const rep: Repetition = instruction.parentRepetition;
-            if (rep === undefined) {
+            if (!rep) {
                 continue;
             }
             if (rep.FromWords) {
@@ -499,7 +499,7 @@ export class SourceMeasure {
         for (let idx: number = 0, len: number = this.LastRepetitionInstructions.length; idx < len; ++idx) {
             const instruction: RepetitionInstruction = this.LastRepetitionInstructions[idx];
             const rep: Repetition = instruction.parentRepetition;
-            if (rep === undefined) {
+            if (!rep) {
                 continue;
             }
             if (!rep.FromWords) {

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

@@ -220,11 +220,11 @@ export class VoiceEntry {
     //    return this.createVoiceEntriesForOrnament(this, activeKey);
     //}
     public createVoiceEntriesForOrnament(voiceEntryWithOrnament: VoiceEntry, activeKey: KeyInstruction): VoiceEntry[] {
-        if (voiceEntryWithOrnament === undefined) {
+        if (!voiceEntryWithOrnament) {
             voiceEntryWithOrnament = this;
         }
         const voiceEntries: VoiceEntry[] = [];
-        if (voiceEntryWithOrnament.ornamentContainer === undefined) {
+        if (!voiceEntryWithOrnament.ornamentContainer) {
             return;
         }
         const baseNote: Note = this.notes[0];

+ 3 - 3
src/OpenSheetMusicDisplay/Cursor.ts

@@ -101,7 +101,7 @@ export class Cursor {
 
   public update(): void {
     // Warning! This should NEVER call this.openSheetMusicDisplay.render()
-    if (this.hidden || this.hidden === undefined) {
+    if (this.hidden || this.hidden === undefined || this.hidden === null) {
       return;
     }
     // this.graphic?.Cursors?.length = 0;
@@ -109,7 +109,7 @@ export class Cursor {
     // TODO when measure draw range (drawUpToMeasureNumber) was changed, next/update can fail to move cursor. but of course it can be reset before.
 
     const voiceEntries: VoiceEntry[] = iterator.CurrentVisibleVoiceEntries();
-    if (iterator.EndReached || iterator.CurrentVoiceEntries === undefined || voiceEntries.length === 0) {
+    if (iterator.EndReached || !iterator.CurrentVoiceEntries || voiceEntries.length === 0) {
       return;
     }
     let x: number = 0, y: number = 0, height: number = 0;
@@ -121,7 +121,7 @@ export class Cursor {
           gseArr.sort((a, b) => a?.PositionAndShape?.AbsolutePosition?.x <= b?.PositionAndShape?.AbsolutePosition?.x ? -1 : 1 )[0];
     x = gse.PositionAndShape.AbsolutePosition.x;
     const musicSystem: MusicSystem = gse.parentMeasure.ParentMusicSystem;
-    if (musicSystem === undefined) {
+    if (!musicSystem) {
       return;
     }
     y = musicSystem.PositionAndShape.AbsolutePosition.y + musicSystem.StaffLines[0].PositionAndShape.RelativePosition.y;