Przeglądaj źródła

Fixed the last errors!

Matthias 9 lat temu
rodzic
commit
4d56d5d191

+ 5 - 16
src/MusicalScore/Graphical/GraphicalMusicSheet.ts

@@ -303,23 +303,12 @@ export class GraphicalMusicSheet {
         return undefined;
     }
 
-    public GetVerticalContainerFromTimestamp(timestamp: Fraction, startIndex: number): VerticalGraphicalStaffEntryContainer {
-        let index: number = this.verticalGraphicalStaffEntryContainers.BinarySearch(
-            startIndex,
-            this.verticalGraphicalStaffEntryContainers.length - startIndex,
-            new VerticalGraphicalStaffEntryContainer(0, timestamp),
-            new VerticalGraphicalStaffEntryContainer.VgseContainerTimestampComparer()
-        );
-        if (index >= 0) {
-            return this.verticalGraphicalStaffEntryContainers[index];
-        }
-        return undefined;
-    }
-
-    public GetVerticalContainerFromTimestamp(timestamp: Fraction): VerticalGraphicalStaffEntryContainer {
-        let index: number = this.verticalGraphicalStaffEntryContainers.BinarySearch(
+    public GetVerticalContainerFromTimestamp(timestamp: Fraction, startIndex: number = 0): VerticalGraphicalStaffEntryContainer {
+        let index: number = CollectionUtil.binarySearch(this.verticalGraphicalStaffEntryContainers,
             new VerticalGraphicalStaffEntryContainer(0, timestamp),
-            new VerticalGraphicalStaffEntryContainer.VgseContainerTimestampComparer()
+            VerticalGraphicalStaffEntryContainer.compareByTimestamp,
+            startIndex,
+            this.verticalGraphicalStaffEntryContainers.length - startIndex
         );
         if (index >= 0) {
             return this.verticalGraphicalStaffEntryContainers[index];

+ 0 - 5
src/MusicalScore/Graphical/MusicSheetCalculator.ts

@@ -452,11 +452,6 @@ export class MusicSheetCalculator {
         return;
     }
 
-    protected layoutFingering(staffLine: StaffLine, skyBottomLineCalculator: SkyBottomLineCalculator,
-                              staffEntry: GraphicalStaffEntry, measureRelativePosition: PointF2D): void {
-        return;
-    }
-
     protected calculateDynamicExpressionsForSingleMultiExpression(multiExpression: MultiExpression, measureIndex: number, staffIndex: number): void {
         return;
     }

+ 14 - 5
src/MusicalScore/Graphical/VerticalGraphicalStaffEntryContainer.ts

@@ -38,6 +38,19 @@ export class VerticalGraphicalStaffEntryContainer {
         this.staffEntries = value;
     }
 
+    public static compareByTimestamp(x: VerticalGraphicalStaffEntryContainer, y: VerticalGraphicalStaffEntryContainer): number
+    {
+        let xValue = x.absoluteTimestamp.RealValue;
+        let yValue = y.absoluteTimestamp.RealValue;
+
+        if (xValue < yValue)
+            return -1;
+        else if (xValue > yValue)
+            return 1;
+        else
+            return 0;
+    }
+    
     public getFirstNonNullStaffEntry(): GraphicalStaffEntry {
         for (let idx: number = 0, len: number = this.staffEntries.length; idx < len; ++idx) {
             let graphicalStaffEntry: GraphicalStaffEntry = this.staffEntries[idx];
@@ -49,8 +62,4 @@ export class VerticalGraphicalStaffEntryContainer {
     }
 }
 
-export class VgseContainerTimestampComparer implements IComparer<VerticalGraphicalStaffEntryContainer> {
-    public Compare(x: VerticalGraphicalStaffEntryContainer, y: VerticalGraphicalStaffEntryContainer): number {
-        return Comparer.Default.Compare(x.AbsoluteTimestamp.RealValue, y.AbsoluteTimestamp.RealValue);
-    }
-}
+

+ 14 - 0
src/Util/collectionUtil.ts

@@ -40,4 +40,18 @@ export class CollectionUtil {
     public static getLastElement<T>(array: T[]): T{
         return array[array.length-1];
     }
+
+    public static binarySearch<T>(array: T[], element: T, cmp: (elem1: T, elem2: T) => number, startIndex: number = 0, endIndex: number = array.length): number 
+    {
+        var mid = 1;
+        while (startIndex < endIndex) {
+            mid = Math.floor((startIndex + endIndex) / 2);
+            var c = cmp(array[mid], element);
+            if (c === 0) return mid;
+            if (c < 0) startIndex = mid + 1;
+            if (0 < c) endIndex = mid;
+        }
+        
+        return -mid;
+    }
 }