|
@@ -1,9 +1,17 @@
|
|
-export class MusicPartManager implements ISelectionListener {
|
|
|
|
|
|
+import { MusicSheet } from "../MusicSheet"
|
|
|
|
+import { PartListEntry } from "../MusicSource/PartListEntry"
|
|
|
|
+import { Repetition } from "../MusicSource/Repetition"
|
|
|
|
+import { Fraction } from "../../Common/DataObjects/fraction"
|
|
|
|
+import { MusicPartManagerIterator } from "./MusicPartManagerIterator"
|
|
|
|
+
|
|
|
|
+type TimestampTransform = any;
|
|
|
|
+
|
|
|
|
+export class MusicPartManager /*implements ISelectionListener*/ {
|
|
constructor(musicSheet: MusicSheet) {
|
|
constructor(musicSheet: MusicSheet) {
|
|
this.musicSheet = musicSheet;
|
|
this.musicSheet = musicSheet;
|
|
}
|
|
}
|
|
- private parts: List<PartListEntry>;
|
|
|
|
- private timestamps: List<TimestampTransform>;
|
|
|
|
|
|
+ private parts: PartListEntry[];
|
|
|
|
+ private timestamps: TimestampTransform[];
|
|
private musicSheet: MusicSheet;
|
|
private musicSheet: MusicSheet;
|
|
private sheetStart: Fraction;
|
|
private sheetStart: Fraction;
|
|
private sheetEnd: Fraction;
|
|
private sheetEnd: Fraction;
|
|
@@ -11,14 +19,14 @@ export class MusicPartManager implements ISelectionListener {
|
|
this.init();
|
|
this.init();
|
|
}
|
|
}
|
|
public init(): void {
|
|
public init(): void {
|
|
- this.parts = new List<PartListEntry>(this.musicSheet.Repetitions.ToArray());
|
|
|
|
|
|
+ this.parts = this.musicSheet.Repetitions.slice();
|
|
this.sheetStart = this.musicSheet.SelectionStart = new Fraction(0, 1);
|
|
this.sheetStart = this.musicSheet.SelectionStart = new Fraction(0, 1);
|
|
this.sheetEnd = this.musicSheet.SelectionEnd = this.musicSheet.SheetEndTimestamp;
|
|
this.sheetEnd = this.musicSheet.SelectionEnd = this.musicSheet.SheetEndTimestamp;
|
|
this.calcMapping();
|
|
this.calcMapping();
|
|
}
|
|
}
|
|
public getCurrentRepetitionTimestampTransform(curEnrolledTimestamp: Fraction): TimestampTransform {
|
|
public getCurrentRepetitionTimestampTransform(curEnrolledTimestamp: Fraction): TimestampTransform {
|
|
let curTransform: TimestampTransform = undefined;
|
|
let curTransform: TimestampTransform = undefined;
|
|
- for (let i: number = this.timestamps.Count - 1; i >= 0; i--) {
|
|
|
|
|
|
+ for (let i: number = this.timestamps.length - 1; i >= 0; i--) {
|
|
curTransform = this.timestamps[i];
|
|
curTransform = this.timestamps[i];
|
|
if (curEnrolledTimestamp >= curTransform.$from) {
|
|
if (curEnrolledTimestamp >= curTransform.$from) {
|
|
return curTransform;
|
|
return curTransform;
|
|
@@ -27,22 +35,22 @@ export class MusicPartManager implements ISelectionListener {
|
|
return this.timestamps[0];
|
|
return this.timestamps[0];
|
|
}
|
|
}
|
|
public absoluteEnrolledToSheetTimestamp(timestamp: Fraction): Fraction {
|
|
public absoluteEnrolledToSheetTimestamp(timestamp: Fraction): Fraction {
|
|
- if (this.timestamps.Count === 0) {
|
|
|
|
|
|
+ if (this.timestamps.length === 0) {
|
|
return timestamp;
|
|
return timestamp;
|
|
}
|
|
}
|
|
let transform: TimestampTransform = this.getCurrentRepetitionTimestampTransform(timestamp);
|
|
let transform: TimestampTransform = this.getCurrentRepetitionTimestampTransform(timestamp);
|
|
- return timestamp + (transform.to - transform.$from);
|
|
|
|
|
|
+ return Fraction.plus(timestamp, <any>(transform.to - transform.$from)); // FIXME
|
|
}
|
|
}
|
|
- public get Parts(): List<PartListEntry> {
|
|
|
|
|
|
+ public get Parts(): PartListEntry[] {
|
|
return this.parts;
|
|
return this.parts;
|
|
}
|
|
}
|
|
public get MusicSheet(): MusicSheet {
|
|
public get MusicSheet(): MusicSheet {
|
|
return this.musicSheet;
|
|
return this.musicSheet;
|
|
}
|
|
}
|
|
- public getIterator(): MusicPartManagerIterator {
|
|
|
|
- return new MusicPartManagerIterator(this, this.musicSheet.SelectionStart, this.musicSheet.SelectionEnd);
|
|
|
|
- }
|
|
|
|
- public getIterator(start: Fraction): MusicPartManagerIterator {
|
|
|
|
|
|
+ public getIterator(start?: Fraction): MusicPartManagerIterator {
|
|
|
|
+ if (start === undefined) {
|
|
|
|
+ return new MusicPartManagerIterator(this, this.musicSheet.SelectionStart, this.musicSheet.SelectionEnd);
|
|
|
|
+ }
|
|
return new MusicPartManagerIterator(this, start, undefined);
|
|
return new MusicPartManagerIterator(this, start, undefined);
|
|
}
|
|
}
|
|
public setSelectionStart(beginning: Fraction): void {
|
|
public setSelectionStart(beginning: Fraction): void {
|
|
@@ -54,7 +62,7 @@ export class MusicPartManager implements ISelectionListener {
|
|
this.musicSheet.SelectionEnd = end === undefined ? this.sheetEnd : end;
|
|
this.musicSheet.SelectionEnd = end === undefined ? this.sheetEnd : end;
|
|
}
|
|
}
|
|
private calcMapping(): void {
|
|
private calcMapping(): void {
|
|
- this.timestamps = new List<TimestampTransform>();
|
|
|
|
|
|
+ this.timestamps = new Array();
|
|
let iterator: MusicPartManagerIterator = this.getIterator();
|
|
let iterator: MusicPartManagerIterator = this.getIterator();
|
|
let currentRepetition: Repetition = iterator.CurrentRepetition;
|
|
let currentRepetition: Repetition = iterator.CurrentRepetition;
|
|
let curTimestampTransform: TimestampTransform = new TimestampTransform(
|
|
let curTimestampTransform: TimestampTransform = new TimestampTransform(
|
|
@@ -63,7 +71,7 @@ export class MusicPartManager implements ISelectionListener {
|
|
undefined,
|
|
undefined,
|
|
0,
|
|
0,
|
|
);
|
|
);
|
|
- this.timestamps.Add(curTimestampTransform);
|
|
|
|
|
|
+ this.timestamps.push(curTimestampTransform);
|
|
while (!iterator.EndReached) {
|
|
while (!iterator.EndReached) {
|
|
if (iterator.JumpOccurred || currentRepetition !== iterator.CurrentRepetition) {
|
|
if (iterator.JumpOccurred || currentRepetition !== iterator.CurrentRepetition) {
|
|
currentRepetition = iterator.CurrentRepetition;
|
|
currentRepetition = iterator.CurrentRepetition;
|
|
@@ -72,7 +80,7 @@ export class MusicPartManager implements ISelectionListener {
|
|
curTimestampTransform.nextBackJump = iterator.CurrentEnrolledTimestamp;
|
|
curTimestampTransform.nextBackJump = iterator.CurrentEnrolledTimestamp;
|
|
curTimestampTransform.curRepetition = jumpRep;
|
|
curTimestampTransform.curRepetition = jumpRep;
|
|
curTimestampTransform.curRepetitionIteration = iterator.CurrentJumpResponsibleRepetitionIterationBeforeJump;
|
|
curTimestampTransform.curRepetitionIteration = iterator.CurrentJumpResponsibleRepetitionIterationBeforeJump;
|
|
- for (let i: number = this.timestamps.Count - 2; i >= 0; i--) {
|
|
|
|
|
|
+ for (let i: number = this.timestamps.length - 2; i >= 0; i--) {
|
|
if (jumpRep.AbsoluteTimestamp > this.timestamps[i].to || this.timestamps[i].curRepetition !== undefined) {
|
|
if (jumpRep.AbsoluteTimestamp > this.timestamps[i].to || this.timestamps[i].curRepetition !== undefined) {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -87,7 +95,7 @@ export class MusicPartManager implements ISelectionListener {
|
|
undefined,
|
|
undefined,
|
|
0,
|
|
0,
|
|
);
|
|
);
|
|
- this.timestamps.Add(curTimestampTransform);
|
|
|
|
|
|
+ this.timestamps.push(curTimestampTransform);
|
|
}
|
|
}
|
|
iterator.moveToNext();
|
|
iterator.moveToNext();
|
|
}
|
|
}
|