|
@@ -11,6 +11,7 @@ import {MultiTempoExpression} from "./Expressions/multiTempoExpression";
|
|
|
import {KeyInstruction} from "./Instructions/KeyInstruction";
|
|
|
import {AbstractNotationInstruction} from "./Instructions/AbstractNotationInstruction";
|
|
|
import {Repetition} from "../MusicSource/Repetition";
|
|
|
+
|
|
|
export class SourceMeasure {
|
|
|
constructor(completeNumberOfStaves: number) {
|
|
|
this.completeNumberOfStaves = completeNumberOfStaves;
|
|
@@ -47,75 +48,96 @@ export class SourceMeasure {
|
|
|
public get MeasureNumber(): number {
|
|
|
return this.measureNumber;
|
|
|
}
|
|
|
+
|
|
|
public set MeasureNumber(value: number) {
|
|
|
this.measureNumber = value;
|
|
|
}
|
|
|
+
|
|
|
public get AbsoluteTimestamp(): Fraction {
|
|
|
return this.absoluteTimestamp;
|
|
|
}
|
|
|
+
|
|
|
public set AbsoluteTimestamp(value: Fraction) {
|
|
|
this.absoluteTimestamp = value;
|
|
|
}
|
|
|
+
|
|
|
public get CompleteNumberOfStaves(): number {
|
|
|
return this.completeNumberOfStaves;
|
|
|
}
|
|
|
+
|
|
|
public get Duration(): Fraction {
|
|
|
return this.duration;
|
|
|
}
|
|
|
+
|
|
|
public set Duration(value: Fraction) {
|
|
|
this.duration = value;
|
|
|
}
|
|
|
+
|
|
|
public get ImplicitMeasure(): boolean {
|
|
|
return this.implicitMeasure;
|
|
|
}
|
|
|
+
|
|
|
public set ImplicitMeasure(value: boolean) {
|
|
|
this.implicitMeasure = value;
|
|
|
}
|
|
|
+
|
|
|
public get BreakSystemAfter(): boolean {
|
|
|
return this.breakSystemAfter;
|
|
|
}
|
|
|
+
|
|
|
public set BreakSystemAfter(value: boolean) {
|
|
|
this.breakSystemAfter = value;
|
|
|
}
|
|
|
+
|
|
|
public get StaffLinkedExpressions(): MultiExpression[][] {
|
|
|
return this.staffLinkedExpressions;
|
|
|
}
|
|
|
+
|
|
|
public get TempoExpressions(): MultiTempoExpression[] {
|
|
|
return this.tempoExpressions;
|
|
|
}
|
|
|
+
|
|
|
public get VerticalSourceStaffEntryContainers(): VerticalSourceStaffEntryContainer[] {
|
|
|
return this.verticalSourceStaffEntryContainers;
|
|
|
}
|
|
|
+
|
|
|
public get FirstInstructionsStaffEntries(): SourceStaffEntry[] {
|
|
|
return this.firstInstructionsStaffEntries;
|
|
|
}
|
|
|
+
|
|
|
public get LastInstructionsStaffEntries(): SourceStaffEntry[] {
|
|
|
return this.lastInstructionsStaffEntries;
|
|
|
}
|
|
|
+
|
|
|
public get FirstRepetitionInstructions(): RepetitionInstruction[] {
|
|
|
return this.firstRepetitionInstructions;
|
|
|
}
|
|
|
+
|
|
|
public get LastRepetitionInstructions(): RepetitionInstruction[] {
|
|
|
return this.lastRepetitionInstructions;
|
|
|
}
|
|
|
+
|
|
|
public getErrorInMeasure(staffIndex: number): boolean {
|
|
|
return this.staffMeasureErrors[staffIndex];
|
|
|
}
|
|
|
+
|
|
|
public setErrorInStaffMeasure(staffIndex: number, hasError: boolean): void {
|
|
|
this.staffMeasureErrors[staffIndex] = hasError;
|
|
|
}
|
|
|
+
|
|
|
public getNextMeasure(measures: SourceMeasure[]): SourceMeasure {
|
|
|
return measures[this.measureListIndex + 1];
|
|
|
}
|
|
|
+
|
|
|
public getPreviousMeasure(measures: SourceMeasure[]): SourceMeasure {
|
|
|
if (this.measureListIndex > 1) {
|
|
|
return measures[this.measureListIndex - 1];
|
|
|
}
|
|
|
return undefined;
|
|
|
}
|
|
|
- public findOrCreateStaffEntry(
|
|
|
- inMeasureTimestamp: Fraction, inSourceMeasureStaffIndex: number, staff: Staff
|
|
|
- ): {createdNewContainer: boolean, staffEntry: SourceStaffEntry} {
|
|
|
+
|
|
|
+ public findOrCreateStaffEntry(inMeasureTimestamp: Fraction, inSourceMeasureStaffIndex: number,
|
|
|
+ staff: Staff): {createdNewContainer: boolean, staffEntry: SourceStaffEntry} {
|
|
|
// FIXME Andrea: debug & Test
|
|
|
let staffEntry: SourceStaffEntry = undefined;
|
|
|
// Find:
|
|
@@ -171,6 +193,7 @@ export class SourceMeasure {
|
|
|
//Logging.debug("created new container: ", staffEntry, this.verticalSourceStaffEntryContainers);
|
|
|
return {createdNewContainer: true, staffEntry: staffEntry};
|
|
|
}
|
|
|
+
|
|
|
public findOrCreateVoiceEntry(sse: SourceStaffEntry, voice: Voice): { createdVoiceEntry: boolean, voiceEntry: VoiceEntry } {
|
|
|
let ve: VoiceEntry = undefined;
|
|
|
let createdNewVoiceEntry: boolean = false;
|
|
@@ -185,11 +208,10 @@ export class SourceMeasure {
|
|
|
sse.VoiceEntries.push(ve);
|
|
|
createdNewVoiceEntry = true;
|
|
|
}
|
|
|
- return { createdVoiceEntry: createdNewVoiceEntry, voiceEntry: ve };
|
|
|
+ return {createdVoiceEntry: createdNewVoiceEntry, voiceEntry: ve};
|
|
|
}
|
|
|
- public getPreviousSourceStaffEntryFromIndex(
|
|
|
- verticalIndex: number, horizontalIndex: number
|
|
|
- ): SourceStaffEntry {
|
|
|
+
|
|
|
+ public getPreviousSourceStaffEntryFromIndex(verticalIndex: number, horizontalIndex: number): SourceStaffEntry {
|
|
|
for (let i: number = horizontalIndex - 1; i >= 0; i--) {
|
|
|
if (this.verticalSourceStaffEntryContainers[i][verticalIndex] !== undefined) {
|
|
|
return this.verticalSourceStaffEntryContainers[i][verticalIndex];
|
|
@@ -197,6 +219,7 @@ export class SourceMeasure {
|
|
|
}
|
|
|
return undefined;
|
|
|
}
|
|
|
+
|
|
|
public getVerticalContainerIndexByTimestamp(musicTimestamp: Fraction): number {
|
|
|
for (let idx: number = 0, len: number = this.VerticalSourceStaffEntryContainers.length; idx < len; ++idx) {
|
|
|
if (this.VerticalSourceStaffEntryContainers[idx].Timestamp.Equals(musicTimestamp)) {
|
|
@@ -205,6 +228,7 @@ export class SourceMeasure {
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
+
|
|
|
public getVerticalContainerByTimestamp(musicTimestamp: Fraction): VerticalSourceStaffEntryContainer {
|
|
|
for (let idx: number = 0, len: number = this.VerticalSourceStaffEntryContainers.length; idx < len; ++idx) {
|
|
|
let verticalSourceStaffEntryContainer: VerticalSourceStaffEntryContainer = this.VerticalSourceStaffEntryContainers[idx];
|
|
@@ -214,6 +238,7 @@ export class SourceMeasure {
|
|
|
}
|
|
|
return undefined;
|
|
|
}
|
|
|
+
|
|
|
public checkForEmptyVerticalContainer(index: number): void {
|
|
|
let undefinedCounter: number = 0;
|
|
|
for (let i: number = 0; i < this.completeNumberOfStaves; i++) {
|
|
@@ -225,6 +250,7 @@ export class SourceMeasure {
|
|
|
this.verticalSourceStaffEntryContainers.splice(index, 1);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public reverseCheck(musicSheet: MusicSheet, maxInstDuration: Fraction): Fraction {
|
|
|
let maxDuration: Fraction = new Fraction(0, 1);
|
|
|
let instrumentsDurations: Fraction[] = [];
|
|
@@ -256,6 +282,7 @@ export class SourceMeasure {
|
|
|
}
|
|
|
return Fraction.max(maxDuration, maxInstDuration);
|
|
|
}
|
|
|
+
|
|
|
public calculateInstrumentsDuration(musicSheet: MusicSheet, instrumentMaxTieNoteFractions: Fraction[]): Fraction[] {
|
|
|
let instrumentsDurations: Fraction[] = [];
|
|
|
for (let i: number = 0; i < musicSheet.Instruments.length; i++) {
|
|
@@ -276,83 +303,105 @@ export class SourceMeasure {
|
|
|
}
|
|
|
return instrumentsDurations;
|
|
|
}
|
|
|
+
|
|
|
public getEntriesPerStaff(staffIndex: number): SourceStaffEntry[] {
|
|
|
let sourceStaffEntries: SourceStaffEntry[] = [];
|
|
|
for (let container of this.VerticalSourceStaffEntryContainers) {
|
|
|
let sse: SourceStaffEntry = container.StaffEntries[staffIndex];
|
|
|
- if (sse !== undefined) { sourceStaffEntries.push(sse); }
|
|
|
+ if (sse !== undefined) {
|
|
|
+ sourceStaffEntries.push(sse);
|
|
|
+ }
|
|
|
}
|
|
|
return sourceStaffEntries;
|
|
|
}
|
|
|
+
|
|
|
public hasBeginInstructions(): boolean {
|
|
|
- for (var staffIndex: number = 0, len = this.FirstInstructionsStaffEntries.length; staffIndex < len; staffIndex++) {
|
|
|
- var beginInstructionsStaffEntry: SourceStaffEntry = this.FirstInstructionsStaffEntries[staffIndex];
|
|
|
- if (beginInstructionsStaffEntry != null && beginInstructionsStaffEntry.Instructions.length > 0)
|
|
|
+ for (let staffIndex: number = 0, len: number = this.FirstInstructionsStaffEntries.length; staffIndex < len; staffIndex++) {
|
|
|
+ let beginInstructionsStaffEntry: SourceStaffEntry = this.FirstInstructionsStaffEntries[staffIndex];
|
|
|
+ if (beginInstructionsStaffEntry !== undefined && beginInstructionsStaffEntry.Instructions.length > 0) {
|
|
|
return true;
|
|
|
+ }
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
public beginsWithLineRepetition(): boolean {
|
|
|
- for (var idx: number = 0, len = this.FirstRepetitionInstructions.length; idx < len; ++idx) {
|
|
|
- var instr: RepetitionInstruction = this.FirstRepetitionInstructions[idx];
|
|
|
- if (instr.parentRepetition != null && instr == instr.parentRepetition.startMarker && !instr.parentRepetition.FromWords)
|
|
|
+ for (let idx: number = 0, len: number = this.FirstRepetitionInstructions.length; idx < len; ++idx) {
|
|
|
+ let instr: RepetitionInstruction = this.FirstRepetitionInstructions[idx];
|
|
|
+ if (instr.parentRepetition !== undefined && instr === instr.parentRepetition.startMarker && !instr.parentRepetition.FromWords) {
|
|
|
return true;
|
|
|
+ }
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
public endsWithLineRepetition(): boolean {
|
|
|
- for (var idx: number = 0, len = this.LastRepetitionInstructions.length; idx < len; ++idx) {
|
|
|
- var instruction: RepetitionInstruction = this.LastRepetitionInstructions[idx];
|
|
|
- var rep: Repetition = instruction.parentRepetition;
|
|
|
- if (rep == null)
|
|
|
+ for (let idx: number = 0, len: number = this.LastRepetitionInstructions.length; idx < len; ++idx) {
|
|
|
+ let instruction: RepetitionInstruction = this.LastRepetitionInstructions[idx];
|
|
|
+ let rep: Repetition = instruction.parentRepetition;
|
|
|
+ if (rep === undefined) {
|
|
|
continue;
|
|
|
- if (rep.FromWords)
|
|
|
+ }
|
|
|
+ if (rep.FromWords) {
|
|
|
continue;
|
|
|
- for (var idx2: number = 0, len2 = rep.BackwardJumpInstructions.length; idx2 < len2; ++idx2) {
|
|
|
- var backJumpInstruction: RepetitionInstruction = rep.BackwardJumpInstructions[idx2];
|
|
|
- if (instruction == backJumpInstruction)
|
|
|
+ }
|
|
|
+ for (let idx2: number = 0, len2: number = rep.BackwardJumpInstructions.length; idx2 < len2; ++idx2) {
|
|
|
+ let backJumpInstruction: RepetitionInstruction = rep.BackwardJumpInstructions[idx2];
|
|
|
+ if (instruction === backJumpInstruction) {
|
|
|
return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
public beginsWithWordRepetition(): boolean {
|
|
|
- for (var idx: number = 0, len = this.FirstRepetitionInstructions.length; idx < len; ++idx) {
|
|
|
- var instruction: RepetitionInstruction = this.FirstRepetitionInstructions[idx];
|
|
|
- if (instruction.parentRepetition != null && instruction == instruction.parentRepetition.startMarker && instruction.parentRepetition.FromWords)
|
|
|
+ for (let idx: number = 0, len: number = this.FirstRepetitionInstructions.length; idx < len; ++idx) {
|
|
|
+ let instruction: RepetitionInstruction = this.FirstRepetitionInstructions[idx];
|
|
|
+ if (instruction.parentRepetition !== undefined &&
|
|
|
+ instruction === instruction.parentRepetition.startMarker && instruction.parentRepetition.FromWords) {
|
|
|
return true;
|
|
|
+ }
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
public endsWithWordRepetition(): boolean {
|
|
|
- for (var idx: number = 0, len = this.LastRepetitionInstructions.length; idx < len; ++idx) {
|
|
|
- var instruction: RepetitionInstruction = this.LastRepetitionInstructions[idx];
|
|
|
- var rep: Repetition = instruction.parentRepetition;
|
|
|
- if (rep == null)
|
|
|
+ for (let idx: number = 0, len: number = this.LastRepetitionInstructions.length; idx < len; ++idx) {
|
|
|
+ let instruction: RepetitionInstruction = this.LastRepetitionInstructions[idx];
|
|
|
+ let rep: Repetition = instruction.parentRepetition;
|
|
|
+ if (rep === undefined) {
|
|
|
continue;
|
|
|
- if (!rep.FromWords)
|
|
|
+ }
|
|
|
+ if (!rep.FromWords) {
|
|
|
continue;
|
|
|
- for (var idx2: number = 0, len2 = rep.BackwardJumpInstructions.length; idx2 < len2; ++idx2) {
|
|
|
- var backJumpInstruction: RepetitionInstruction = rep.BackwardJumpInstructions[idx2];
|
|
|
- if (instruction == backJumpInstruction)
|
|
|
+ }
|
|
|
+ for (let idx2: number = 0, len2: number = rep.BackwardJumpInstructions.length; idx2 < len2; ++idx2) {
|
|
|
+ let backJumpInstruction: RepetitionInstruction = rep.BackwardJumpInstructions[idx2];
|
|
|
+ if (instruction === backJumpInstruction) {
|
|
|
return true;
|
|
|
+ }
|
|
|
}
|
|
|
- if (instruction == rep.forwardJumpInstruction)
|
|
|
+ if (instruction === rep.forwardJumpInstruction) {
|
|
|
return true;
|
|
|
+ }
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
public getKeyInstruction(staffIndex: number): KeyInstruction {
|
|
|
- if (this.FirstInstructionsStaffEntries[staffIndex] != null) {
|
|
|
- var sourceStaffEntry: SourceStaffEntry = this.FirstInstructionsStaffEntries[staffIndex];
|
|
|
- for (var idx: number = 0, len = sourceStaffEntry.Instructions.length; idx < len; ++idx) {
|
|
|
- var abstractNotationInstruction: AbstractNotationInstruction = sourceStaffEntry.Instructions[idx];
|
|
|
- if (abstractNotationInstruction instanceof KeyInstruction)
|
|
|
+ if (this.FirstInstructionsStaffEntries[staffIndex] !== undefined) {
|
|
|
+ let sourceStaffEntry: SourceStaffEntry = this.FirstInstructionsStaffEntries[staffIndex];
|
|
|
+ for (let idx: number = 0, len: number = sourceStaffEntry.Instructions.length; idx < len; ++idx) {
|
|
|
+ let abstractNotationInstruction: AbstractNotationInstruction = sourceStaffEntry.Instructions[idx];
|
|
|
+ if (abstractNotationInstruction instanceof KeyInstruction) {
|
|
|
return <KeyInstruction>abstractNotationInstruction;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
+ return undefined;
|
|
|
}
|
|
|
+
|
|
|
private getLastSourceStaffEntryForInstrument(instrumentIndex: number): SourceStaffEntry {
|
|
|
for (let i: number = this.verticalSourceStaffEntryContainers.length - 1; i >= 0; i--) {
|
|
|
if (this.verticalSourceStaffEntryContainers[i][instrumentIndex] !== undefined) {
|