瀏覽代碼

some cleanup

Matthias 9 年之前
父節點
當前提交
b3645385be

+ 0 - 2
src/MusicalScore/VoiceData/Note.ts

@@ -9,8 +9,6 @@ import {Staff} from "./Staff";
 import {Slur} from "./Expressions/ContinuousExpressions/Slur";
 import {Slur} from "./Expressions/ContinuousExpressions/Slur";
 import {NoteState} from "../Graphical/DrawingEnums";
 import {NoteState} from "../Graphical/DrawingEnums";
 
 
-// import Vex = require("vexflow");
-
 export class Note {
 export class Note {
 
 
     constructor(voiceEntry: VoiceEntry, parentStaffEntry: SourceStaffEntry, length: Fraction, pitch: Pitch) {
     constructor(voiceEntry: VoiceEntry, parentStaffEntry: SourceStaffEntry, length: Fraction, pitch: Pitch) {

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

@@ -30,7 +30,6 @@ export class SourceMeasure {
     public endsPiece: boolean;
     public endsPiece: boolean;
 
 
     private measureNumber: number;
     private measureNumber: number;
-    //private parentMusicPart: SourceMusicPart;
     private absoluteTimestamp: Fraction;
     private absoluteTimestamp: Fraction;
     private completeNumberOfStaves: number;
     private completeNumberOfStaves: number;
     private duration: Fraction;
     private duration: Fraction;
@@ -408,6 +407,6 @@ export class SourceMeasure {
                 return this.verticalSourceStaffEntryContainers[i][instrumentIndex];
                 return this.verticalSourceStaffEntryContainers[i][instrumentIndex];
             }
             }
         }
         }
-        //return undefined;
+        return undefined;
     }
     }
 }
 }

+ 221 - 185
src/MusicalScore/VoiceData/SourceStaffEntry.ts

@@ -11,193 +11,229 @@ import {KeyInstruction} from "./Instructions/KeyInstruction";
 import {RhythmInstruction} from "./Instructions/RhythmInstruction";
 import {RhythmInstruction} from "./Instructions/RhythmInstruction";
 
 
 export class SourceStaffEntry {
 export class SourceStaffEntry {
-  constructor(verticalContainerParent: VerticalSourceStaffEntryContainer, parentStaff: Staff) {
-    this.verticalContainerParent = verticalContainerParent;
-    this.parentStaff = parentStaff;
-  }
-  private parentStaff: Staff;
-  private verticalContainerParent: VerticalSourceStaffEntryContainer;
-  private voiceEntries: VoiceEntry[] = [];
-  private staffEntryLink: StaffEntryLink;
-  private instructions: AbstractNotationInstruction[] = [];
-  private chordSymbolContainer: ChordSymbolContainer;
-  public get ParentStaff(): Staff {
-    return this.parentStaff;
-  }
-  public get VerticalContainerParent(): VerticalSourceStaffEntryContainer {
-    return this.verticalContainerParent;
-  }
-  public get Timestamp(): Fraction {
-    if (this.VerticalContainerParent !== undefined) {
-      return this.VerticalContainerParent.Timestamp;
-    }
-    return undefined;
-  }
-  public get AbsoluteTimestamp(): Fraction {
-    if (this.VerticalContainerParent !== undefined) {
-      return Fraction.plus(this.VerticalContainerParent.ParentMeasure.AbsoluteTimestamp, this.VerticalContainerParent.Timestamp);
-    }
-    return undefined;
-  }
-  public get VoiceEntries(): VoiceEntry[] {
-    return this.voiceEntries;
-  }
-  public set VoiceEntries(value: VoiceEntry[]) {
-    this.voiceEntries = value;
-  }
-  public get Link(): StaffEntryLink {
-    return this.staffEntryLink;
-  }
-  public set Link(value: StaffEntryLink) {
-    this.staffEntryLink = value;
-  }
-  public get Instructions(): AbstractNotationInstruction[] {
-    return this.instructions;
-  }
-  public set Instructions(value: AbstractNotationInstruction[]) {
-    this.instructions = value;
-  }
-  public get ChordContainer(): ChordSymbolContainer {
-    return this.chordSymbolContainer;
-  }
-  public set ChordContainer(value: ChordSymbolContainer) {
-    this.chordSymbolContainer = value;
-  }
-  public removeAllInstructionsOfType<T>(): number {
-   let i: number = 0;
-   let ret: number = 0;
-   while (i < this.instructions.length) {
-       let instruction: Object = this.instructions[i];
-       if (<T>instruction !== undefined) {
-           this.instructions.splice(i, 1);
-           ret++;
-       }  else { i++; }
-   }
-   return ret;
-  }
-  public removeFirstInstructionOfType<T>(): boolean {
-   for (let i: number = 0; i < this.instructions.length; i++) {
-       let instruction: Object = this.instructions[i];
-       if (<T>instruction !== undefined) {
-          this.instructions.splice(i, 1);
-          return true;
-       }
-   }
-   return false;
-  }
-  public removeAllInstructionsOfTypeClefInstruction(): number {
-    let i: number = 0;
-    let ret: number = 0;
-    while (i < this.instructions.length) {
-      if (this.instructions[i] instanceof ClefInstruction) {
-        this.instructions.splice(i, 1);
-        ret++;
-      } else { i++; }
-    }
-    return ret;
-  }
-  public removeFirstInstructionOfTypeClefInstruction(): boolean {
-    for (let i: number = 0; i < this.instructions.length; i++) {
-      if (this.instructions[i] instanceof ClefInstruction) {
-        this.instructions.splice(i, 1);
-        return true;
-      }
-    }
-    return false;
-  }
-  public removeAllInstructionsOfTypeKeyInstruction(): number {
-    let i: number = 0;
-    let ret: number = 0;
-    while (i < this.instructions.length) {
-      if (this.instructions[i] instanceof KeyInstruction) {
-        this.instructions.splice(i, 1);
-        ret++;
-      } else { i++; }
-    }
-    return ret;
-  }
-  public removeFirstInstructionOfTypeKeyInstruction(): boolean {
-    for (let i: number = 0; i < this.instructions.length; i++) {
-      if (this.instructions[i] instanceof KeyInstruction) {
-        this.instructions.splice(i, 1);
-        return true;
-      }
-    }
-    return false;
-  }
-  public removeAllInstructionsOfTypeRhythmInstruction(): number {
-    let i: number = 0;
-    let ret: number = 0;
-    while (i < this.instructions.length) {
-      if (this.instructions[i] instanceof RhythmInstruction) {
-        this.instructions.splice(i, 1);
-        ret++;
-      } else { i++; }
-    }
-    return ret;
-  }
-
-  public calculateMinNoteLength(): Fraction {
-    let duration: Fraction = new Fraction(Number.MAX_VALUE, 1);
-    for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {
-      let voiceEntry: VoiceEntry = this.VoiceEntries[idx];
-      for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
-        let note: Note = voiceEntry.Notes[idx2];
-        if (note.NoteTie !== undefined) {
-          if (duration > note.calculateNoteLengthWithoutTie()) {
-            duration = note.calculateNoteLengthWithoutTie();
-          }
-        } else if (duration > note.Length) {
-            duration = note.Length;
+    constructor(verticalContainerParent: VerticalSourceStaffEntryContainer, parentStaff: Staff) {
+        this.verticalContainerParent = verticalContainerParent;
+        this.parentStaff = parentStaff;
+    }
+
+    private parentStaff: Staff;
+    private verticalContainerParent: VerticalSourceStaffEntryContainer;
+    private voiceEntries: VoiceEntry[] = [];
+    private staffEntryLink: StaffEntryLink;
+    private instructions: AbstractNotationInstruction[] = [];
+    private chordSymbolContainer: ChordSymbolContainer;
+
+    public get ParentStaff(): Staff {
+        return this.parentStaff;
+    }
+
+    public get VerticalContainerParent(): VerticalSourceStaffEntryContainer {
+        return this.verticalContainerParent;
+    }
+
+    public get Timestamp(): Fraction {
+        if (this.VerticalContainerParent !== undefined) {
+            return this.VerticalContainerParent.Timestamp;
+        }
+        return undefined;
+    }
+
+    public get AbsoluteTimestamp(): Fraction {
+        if (this.VerticalContainerParent !== undefined) {
+            return Fraction.plus(this.VerticalContainerParent.ParentMeasure.AbsoluteTimestamp, this.VerticalContainerParent.Timestamp);
+        }
+        return undefined;
+    }
+
+    public get VoiceEntries(): VoiceEntry[] {
+        return this.voiceEntries;
+    }
+
+    public set VoiceEntries(value: VoiceEntry[]) {
+        this.voiceEntries = value;
+    }
+
+    public get Link(): StaffEntryLink {
+        return this.staffEntryLink;
+    }
+
+    public set Link(value: StaffEntryLink) {
+        this.staffEntryLink = value;
+    }
+
+    public get Instructions(): AbstractNotationInstruction[] {
+        return this.instructions;
+    }
+
+    public set Instructions(value: AbstractNotationInstruction[]) {
+        this.instructions = value;
+    }
+
+    public get ChordContainer(): ChordSymbolContainer {
+        return this.chordSymbolContainer;
+    }
+
+    public set ChordContainer(value: ChordSymbolContainer) {
+        this.chordSymbolContainer = value;
+    }
+
+    public removeAllInstructionsOfType<T>(): number {
+        let i: number = 0;
+        let ret: number = 0;
+        while (i < this.instructions.length) {
+            let instruction: Object = this.instructions[i];
+            if (<T>instruction !== undefined) {
+                this.instructions.splice(i, 1);
+                ret++;
+            } else {
+                i++;
+            }
+        }
+        return ret;
+    }
+
+    public removeFirstInstructionOfType<T>(): boolean {
+        for (let i: number = 0; i < this.instructions.length; i++) {
+            let instruction: Object = this.instructions[i];
+            if (<T>instruction !== undefined) {
+                this.instructions.splice(i, 1);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public removeAllInstructionsOfTypeClefInstruction(): number {
+        let i: number = 0;
+        let ret: number = 0;
+        while (i < this.instructions.length) {
+            if (this.instructions[i] instanceof ClefInstruction) {
+                this.instructions.splice(i, 1);
+                ret++;
+            } else {
+                i++;
+            }
+        }
+        return ret;
+    }
+
+    public removeFirstInstructionOfTypeClefInstruction(): boolean {
+        for (let i: number = 0; i < this.instructions.length; i++) {
+            if (this.instructions[i] instanceof ClefInstruction) {
+                this.instructions.splice(i, 1);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public removeAllInstructionsOfTypeKeyInstruction(): number {
+        let i: number = 0;
+        let ret: number = 0;
+        while (i < this.instructions.length) {
+            if (this.instructions[i] instanceof KeyInstruction) {
+                this.instructions.splice(i, 1);
+                ret++;
+            } else {
+                i++;
+            }
+        }
+        return ret;
+    }
+
+    public removeFirstInstructionOfTypeKeyInstruction(): boolean {
+        for (let i: number = 0; i < this.instructions.length; i++) {
+            if (this.instructions[i] instanceof KeyInstruction) {
+                this.instructions.splice(i, 1);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public removeAllInstructionsOfTypeRhythmInstruction(): number {
+        let i: number = 0;
+        let ret: number = 0;
+        while (i < this.instructions.length) {
+            if (this.instructions[i] instanceof RhythmInstruction) {
+                this.instructions.splice(i, 1);
+                ret++;
+            } else {
+                i++;
+            }
         }
         }
-      }
-    }
-    return duration;
-  }
-  public calculateMaxNoteLength(): Fraction {
-    let duration: Fraction = new Fraction(0, 1);
-    for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {
-      let voiceEntry: VoiceEntry = this.VoiceEntries[idx];
-      for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
-        let note: Note = voiceEntry.Notes[idx2];
-        if (note.NoteTie !== undefined) {
-          if (duration < note.calculateNoteLengthWithoutTie()) {
-            duration = note.calculateNoteLengthWithoutTie();
-            for (let idx3: number = 0, len3: number = note.NoteTie.Fractions.length; idx3 < len3; ++idx3) {
-              let fraction: Fraction = note.NoteTie.Fractions[idx3];
-              duration.Add(fraction);
+        return ret;
+    }
+
+    public calculateMinNoteLength(): Fraction {
+        let duration: Fraction = new Fraction(Number.MAX_VALUE, 1);
+        for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {
+            let voiceEntry: VoiceEntry = this.VoiceEntries[idx];
+            for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
+                let note: Note = voiceEntry.Notes[idx2];
+                if (note.NoteTie !== undefined) {
+                    if (duration > note.calculateNoteLengthWithoutTie()) {
+                        duration = note.calculateNoteLengthWithoutTie();
+                    }
+                } else if (duration > note.Length) {
+                    duration = note.Length;
+                }
+            }
+        }
+        return duration;
+    }
+
+    public calculateMaxNoteLength(): Fraction {
+        let duration: Fraction = new Fraction(0, 1);
+        for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {
+            let voiceEntry: VoiceEntry = this.VoiceEntries[idx];
+            for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
+                let note: Note = voiceEntry.Notes[idx2];
+                if (note.NoteTie !== undefined) {
+                    if (duration < note.calculateNoteLengthWithoutTie()) {
+                        duration = note.calculateNoteLengthWithoutTie();
+                        for (let idx3: number = 0, len3: number = note.NoteTie.Fractions.length; idx3 < len3; ++idx3) {
+                            let fraction: Fraction = note.NoteTie.Fractions[idx3];
+                            duration.Add(fraction);
+                        }
+                    }
+                } else if (duration < note.Length) {
+                    duration = note.Length;
+                }
+            }
+        }
+        return duration;
+    }
+
+    public hasNotes(): boolean {
+        for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {
+            let voiceEntry: VoiceEntry = this.VoiceEntries[idx];
+            if (voiceEntry.Notes.length > 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public hasTie(): boolean {
+        for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {
+            let voiceEntry: VoiceEntry = this.VoiceEntries[idx];
+            if (voiceEntry.hasTie()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public findLinkedNotes(linkedNotes: Note[]): void {
+        for (let idx: number = 0, len: number = this.voiceEntries.length; idx < len; ++idx) {
+            let voiceEntry: VoiceEntry = this.voiceEntries[idx];
+            for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
+                let note: Note = voiceEntry.Notes[idx2];
+                if (note.ParentStaffEntry === this) {
+                    linkedNotes.push(note);
+                }
             }
             }
-          }
-        } else if (duration < note.Length) { duration = note.Length; }
-      }
-    }
-    return duration;
-  }
-  public hasNotes(): boolean {
-    for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {
-      let voiceEntry: VoiceEntry = this.VoiceEntries[idx];
-      if (voiceEntry.Notes.length > 0) { return true; }
-    }
-    return false;
-  }
-  public hasTie(): boolean {
-    for (let idx: number = 0, len: number = this.VoiceEntries.length; idx < len; ++idx) {
-      let voiceEntry: VoiceEntry = this.VoiceEntries[idx];
-      if (voiceEntry.hasTie()) {
-        return true;
-      }
-    }
-    return false;
-  }
-  public findLinkedNotes(linkedNotes: Note[]): void {
-    for (let idx: number = 0, len: number = this.voiceEntries.length; idx < len; ++idx) {
-      let voiceEntry: VoiceEntry = this.voiceEntries[idx];
-      for (let idx2: number = 0, len2: number = voiceEntry.Notes.length; idx2 < len2; ++idx2) {
-        let note: Note = voiceEntry.Notes[idx2];
-        if (note.ParentStaffEntry === this) {
-          linkedNotes.push(note);
         }
         }
-      }
     }
     }
-  }
 }
 }

+ 40 - 32
src/MusicalScore/VoiceData/Tuplet.ts

@@ -2,38 +2,46 @@ import {Note} from "./Note";
 import {Fraction} from "../../Common/DataObjects/fraction";
 import {Fraction} from "../../Common/DataObjects/fraction";
 
 
 export class Tuplet {
 export class Tuplet {
-  constructor(tupletLabelNumber: number) {
-    this.tupletLabelNumber = tupletLabelNumber;
-  }
-  private tupletLabelNumber: number;
-  private notes: Note[][] = [];
-  private fractions: Fraction[] = [];
-  public get TupletLabelNumber(): number {
-    return this.tupletLabelNumber;
-  }
-  public set TupletLabelNumber(value: number) {
-    this.tupletLabelNumber = value;
-  }
-  public get Notes(): Note[][] {
-    return this.notes;
-  }
-  public set Notes(value: Note[][]) {
-    this.notes = value;
-  }
-  public get Fractions(): Fraction[] {
-    return this.fractions;
-  }
-  public set Fractions(value: Fraction[]) {
-    this.fractions = value;
-  }
-  public getNoteIndex(note: Note): number {
-    for (let i: number = this.notes.length - 1; i >= 0; i--) {
-      for (let j: number = 0; j < this.notes[i].length; j++) {
-        if (note === this.notes[i][j]) {
-          return i;
+    constructor(tupletLabelNumber: number) {
+        this.tupletLabelNumber = tupletLabelNumber;
+    }
+
+    private tupletLabelNumber: number;
+    private notes: Note[][] = [];
+    private fractions: Fraction[] = [];
+
+    public get TupletLabelNumber(): number {
+        return this.tupletLabelNumber;
+    }
+
+    public set TupletLabelNumber(value: number) {
+        this.tupletLabelNumber = value;
+    }
+
+    public get Notes(): Note[][] {
+        return this.notes;
+    }
+
+    public set Notes(value: Note[][]) {
+        this.notes = value;
+    }
+
+    public get Fractions(): Fraction[] {
+        return this.fractions;
+    }
+
+    public set Fractions(value: Fraction[]) {
+        this.fractions = value;
+    }
+
+    public getNoteIndex(note: Note): number {
+        for (let i: number = this.notes.length - 1; i >= 0; i--) {
+            for (let j: number = 0; j < this.notes[i].length; j++) {
+                if (note === this.notes[i][j]) {
+                    return i;
+                }
+            }
         }
         }
-      }
+        return 0;
     }
     }
-    return 0;
-  }
 }
 }

+ 0 - 5
src/MusicalScore/VoiceData/VerticalSourceStaffEntryContainer.ts

@@ -48,9 +48,4 @@ export class VerticalSourceStaffEntryContainer {
     public getAbsoluteTimestamp(): Fraction {
     public getAbsoluteTimestamp(): Fraction {
         return Fraction.plus(this.timestamp, this.parentMeasure.AbsoluteTimestamp);
         return Fraction.plus(this.timestamp, this.parentMeasure.AbsoluteTimestamp);
     }
     }
-    //private initialize(): void {
-    //    for (let i: number = 0; i < this.size; i++) {
-    //        this.staffEntries.push(undefined);
-    //    }
-    //}
 }
 }