Переглянути джерело

Fixing types & imports pt.1

Andrea Condoluci 9 роки тому
батько
коміт
76c8117f86

+ 3 - 8
src/Common/DataObjects/fraction.ts

@@ -1,11 +1,7 @@
 // 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;
 
@@ -20,8 +16,7 @@ export class Fraction /*implements IComparable, IComparer<Fraction> */{
 
     public static Equal(f1: Fraction, f2: Fraction): boolean {
       // FIXME
-      return f1.Denominator() === f2.Denominator() &&
-      f1.Numerator() === f2.Numerator();
+      return f1.Denominator === f2.Denominator && f1.Numerator === f2.Numerator;
     }
 
     public static CreateFractionFromFraction(fraction: Fraction): Fraction {

+ 50 - 42
src/MusicalScore/Instrument.ts

@@ -1,4 +1,18 @@
-export class Instrument extends InstrumentalGroup implements ISettableInstrument, IInstrument {
+import { InstrumentalGroup } from "./InstrumentalGroup";
+import { Label } from "./Label";
+import { MusicSheet } from "./MusicSheet"
+import { Voice } from "./VoiceData/Voice"
+import { Staff } from "./VoiceData/Staff"
+import { SubInstrument } from "./SubInstrument"
+
+// FIXME
+type IPhonicScoreInterface = any;
+type MidiInstrument = any;
+type InstrumentParameters = any;
+type InstrumentParameterChangedDelegate = any;
+
+
+export class Instrument extends InstrumentalGroup /*implements ISettableInstrument, IInstrument*/ {
     constructor(id: number, idString: string, phonicScoreInterface: IPhonicScoreInterface, musicSheet: MusicSheet, parent: InstrumentalGroup) {
         super(musicSheet, parent);
         this.phonicScoreInterface = phonicScoreInterface;
@@ -12,22 +26,22 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
     public InstrumentParameterChanged: InstrumentParameterChangedDelegate;
 
     private phonicScoreInterface: IPhonicScoreInterface;
-    private voices: List<Voice> = new List<Voice>();
-    private staves: List<Staff> = new List<Staff>();
+    private voices: Voice[] = new Array();
+    private staves: Staff[] = new Array();
     private nameLabel: Label;
     // private range: ToneRange;
     private idString: string;
     private id: number;
     private hasLyrics: boolean = false;
     private hasChordSymbols: boolean = false;
-    // private playback
+    private playbackTranspose: number;
 
-    private lyricVersesNumbers: List<number> = new List<number>();
-    private subInstruments: List<SubInstrument> = new List<SubInstrument>();
-    public get Voices(): List<Voice> {
+    private lyricVersesNumbers: number[] = new Array();
+    private subInstruments: SubInstrument[] = new Array();
+    public get Voices(): Voice[] {
         return this.voices;
     }
-    public get Staves(): List<Staff> {
+    public get Staves(): Staff[] {
         return this.staves;
     }
     public get NameLabel(): Label {
@@ -45,10 +59,10 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
     public set HasChordSymbols(value: boolean) {
         this.hasChordSymbols = value;
     }
-    public get LyricVersesNumbers(): List<number> {
+    public get LyricVersesNumbers(): number[] {
         return this.lyricVersesNumbers;
     }
-    public set LyricVersesNumbers(value: List<number>) {
+    public set LyricVersesNumbers(value: number[]) {
         this.lyricVersesNumbers = value;
     }
     public get Name(): string {
@@ -76,7 +90,7 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         return this.subInstruments[0].Volume;
     }
     public set Volume(value: number) {
-        for (let idx: number = 0, len: number = this.subInstruments.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.subInstruments.length; idx < len; ++idx) {
             let subInstrument: SubInstrument = this.subInstruments[idx];
             subInstrument.Volume = value;
         }
@@ -88,11 +102,11 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         this.playbackTranspose = value;
     }
 
-    public get SubInstruments(): List<SubInstrument> {
+    public get SubInstruments(): SubInstrument[] {
         return this.subInstruments;
     }
     public getSubInstrument(subInstrumentIdString: string): SubInstrument {
-        for (let idx: number = 0, len: number = this.subInstruments.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.subInstruments.length; idx < len; ++idx) {
             let subInstrument: SubInstrument = this.subInstruments[idx];
             if (subInstrument.IdString === subInstrumentIdString) {
                 return subInstrument;
@@ -101,56 +115,56 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         return undefined;
     }
     public get Visible(): boolean {
-        if (this.voices.Count > 0) {
+        if (this.voices.length > 0) {
             return this.Voices[0].Visible;
         } else {
             return false;
         }
     }
     public set Visible(value: boolean) {
-        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.Voices.length; idx < len; ++idx) {
             let v: Voice = this.Voices[idx];
             v.Visible = value;
         }
     }
     public get Audible(): boolean {
         let result: boolean = false;
-        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.Voices.length; idx < len; ++idx) {
             let v: Voice = this.Voices[idx];
             result = result || v.Audible;
         }
         return result;
     }
     public set Audible(value: boolean) {
-        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.Voices.length; idx < len; ++idx) {
             let v: Voice = this.Voices[idx];
             v.Audible = value;
         }
-        for (let idx: number = 0, len: number = this.staves.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.staves.length; idx < len; ++idx) {
             let staff: Staff = this.staves[idx];
             staff.Audible = value;
         }
     }
     public get Following(): boolean {
         let result: boolean = false;
-        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.Voices.length; idx < len; ++idx) {
             let v: Voice = this.Voices[idx];
             result = result || v.Following;
         }
         return result;
     }
     public set Following(value: boolean) {
-        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.Voices.length; idx < len; ++idx) {
             let v: Voice = this.Voices[idx];
             v.Following = value;
         }
-        for (let idx: number = 0, len: number = this.staves.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.staves.length; idx < len; ++idx) {
             let staff: Staff = this.staves[idx];
             staff.Following = value;
         }
     }
     public SetVoiceAudible(voiceId: number, audible: boolean): void {
-        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.Voices.length; idx < len; ++idx) {
             let v: Voice = this.Voices[idx];
             if (v.VoiceId === voiceId) {
                 v.Audible = audible;
@@ -159,7 +173,7 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         }
     }
     public SetVoiceFollowing(voiceId: number, following: boolean): void {
-        for (let idx: number = 0, len: number = this.Voices.Count; idx < len; ++idx) {
+        for (let idx: number = 0, len: number = this.Voices.length; idx < len; ++idx) {
             let v: Voice = this.Voices[idx];
             if (v.VoiceId === voiceId) {
                 v.Following = following;
@@ -171,18 +185,18 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         let staff: Staff = this.staves[staffId - 1];
         staff.Audible = audible;
         if (audible) {
-            for (let idx: number = 0, len: number = staff.Voices.Count; idx < len; ++idx) {
+            for (let idx: number = 0, len: number = staff.Voices.length; idx < len; ++idx) {
                 let v: Voice = staff.Voices[idx];
                 v.Audible = true;
             }
         } else {
-            for (let idx: number = 0, len: number = staff.Voices.Count; idx < len; ++idx) {
+            for (let idx: number = 0, len: number = staff.Voices.length; 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) {
+                for (let idx2: number = 0, len2: number = this.Staves.length; 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) {
+                    for (let idx3: number = 0, len3: number = st.Voices.length; idx3 < len3; ++idx3) {
                         let v: Voice = st.Voices[idx3];
                         if (v === voice) {
                             isAudibleInOtherStaves = true;
@@ -199,18 +213,18 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         let staff: Staff = this.staves[staffId - 1];
         staff.Following = follow;
         if (follow) {
-            for (let idx: number = 0, len: number = staff.Voices.Count; idx < len; ++idx) {
+            for (let idx: number = 0, len: number = staff.Voices.length; idx < len; ++idx) {
                 let v: Voice = staff.Voices[idx];
                 v.Following = true;
             }
         } else {
-            for (let idx: number = 0, len: number = staff.Voices.Count; idx < len; ++idx) {
+            for (let idx: number = 0, len: number = staff.Voices.length; 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) {
+                for (let idx2: number = 0, len2: number = this.Staves.length; 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) {
+                    for (let idx3: number = 0, len3: number = st.Voices.length; idx3 < len3; ++idx3) {
                         let v: Voice = st.Voices[idx3];
                         if (v === voice) {
                             isFollowingInOtherStaves = true;
@@ -224,22 +238,16 @@ export class Instrument extends InstrumentalGroup implements ISettableInstrument
         }
     }
     public areAllVoiceVisible(): boolean {
-        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++;
+        for (let voice of this.Voices) {
+            if (!voice.Visible) {
+                return false;
             }
         }
-        if (counter === this.voices.Count) {
-            return true;
-        }
-        return false;
+        return true;
     }
     public createStaves(numberOfStaves: number): void {
         for (let i: number = 0; i < numberOfStaves; i++) {
-            let staff: Staff = new Staff(this, i + 1);
-            this.staves.Add(staff);
+            this.staves.push(new Staff(this, i + 1));
         }
     }
     public SetInstrumentParameter(parameter: InstrumentParameters, value: Object): void {

+ 1 - 1
src/MusicalScore/Label.ts

@@ -1,5 +1,5 @@
 export class Label {
-  constructor(arg1: any, alignment: PSTextAlignment) {
+  constructor(arg1: any, alignment?: PSTextAlignment) {
       if (arg1 instanceof string) {
           this.text = <string>arg1;
       } else if (arg1 instanceof FontInfo.MusicFontSymbol) {

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

@@ -92,8 +92,10 @@ export class MusicPartManager implements ISelectionListener {
             iterator.moveToNext();
         }
     }
+}
 
-    export class TimestampTransform {
+export module MusicPartManager {
+    class TimestampTransform {
         constructor(sourceTimestamp: Fraction, enrolledTimestamp: Fraction, repetition: Repetition, curRepetitionIteration: number) {
             this.$from = sourceTimestamp;
             this.to = enrolledTimestamp;

+ 4 - 9
src/MusicalScore/MusicSource/Repetition.ts

@@ -150,22 +150,17 @@ export class Repetition extends PartListEntry implements IRepetition {
         return getLastSourceMeasure().MeasureNumber;
     }
 
+}
 
+export module Repetition {
     export class RepetitionEndingPart {
         constructor(endingPart: SourceMusicPart) {
             this.part = endingPart;
         }
         public part: SourceMusicPart;
-        public endingIndices: List<number> = new List<number>();
+        public endingIndices: number[] = new Array();
         public ToString(): string {
-            let result: string = "";
-            if (this.endingIndices.Count > 0) {
-                result += this.endingIndices[0];
-            }
-            for (let i: number = 1; i < this.endingIndices.Count; i++) {
-                result += ", " + this.endingIndices[i];
-            }
-            return result;
+          return this.endingIndices.join(", ");
         }
     }
 }

+ 2 - 0
src/MusicalScore/ScoreIO/InstrumentReader.ts

@@ -949,7 +949,9 @@ export class InstrumentReader {
     }
     return divisionsFromNote;
   }
+}
 
+export module InstrumentReader {
   export class KeyValuePairClass<T, TU> {
     constructor(key: T, value: TU) {
       this.key = key;

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

@@ -250,7 +250,7 @@ export class MusicSheetReader implements IMusicSheetReader {
         if (this.currentMeasure.FirstInstructionsStaffEntries[rhythmInstructions.IndexOf(rhythmInstruction)].Instructions.Last() instanceof RhythmInstruction) {
           // TODO Test correctness
           let instrs: any = this.currentMeasure.FirstInstructionsStaffEntries[rhythmInstructions.IndexOf(rhythmInstruction)].Instructions;
-          instrs[instr.length - 1] = new RhythmInstruction(rhythmInstructions[index];
+          instrs[instr.length - 1] = new RhythmInstruction(rhythmInstructions[index]);
         }
       }
       if (

+ 3 - 0
src/MusicalScore/VoiceData/Instructions/KeyInstruction.ts

@@ -95,7 +95,9 @@ export class KeyInstruction extends AbstractNotationInstruction {
     let key1: KeyInstruction = this;
     return !(key1 === key2);
   }
+}
 
+export module KeyInstruction {
   export class NoteEnumToHalfToneLink {
     constructor(note: NoteEnum, halftone: number) {
       this.note = note;
@@ -106,6 +108,7 @@ export class KeyInstruction extends AbstractNotationInstruction {
   }
 
 }
+
 export enum KeyEnum {
   major = 0,
   minor = 1,

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

@@ -154,7 +154,9 @@ export class Note {
         }
         return false;
     }
+}
 
+export module Note {
     export enum Appearance {
         Normal,
         Grace,