123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import {Repetition} from "../../MusicSource/Repetition";
- export class RepetitionInstructionComparer /*implements IComparer<RepetitionInstruction>*/ {
- public static Compare(x: RepetitionInstruction, y: RepetitionInstruction): number {
- if (x.parentRepetition !== undefined && y.parentRepetition !== undefined) {
- if (x.alignment === AlignmentType.End && y.alignment === AlignmentType.End) {
- if (x.parentRepetition.StartIndex < y.parentRepetition.StartIndex) {
- return 1;
- }
- if (x.parentRepetition.StartIndex > y.parentRepetition.StartIndex) {
- return -1;
- }
- }
- if (x.alignment === AlignmentType.Begin && y.alignment === AlignmentType.Begin) {
- if (x.parentRepetition.EndIndex < y.parentRepetition.EndIndex) {
- return 1;
- }
- if (x.parentRepetition.EndIndex > y.parentRepetition.EndIndex) {
- return -1;
- }
- }
- }
- return 0;
- }
- }
- export class RepetitionInstruction /*implements IComparable*/ {
- /* FIXME: Check constructor calling from other classes
- constructor(measureIndex: number, type: RepetitionInstructionEnum) {
- this(measureIndex, [], type, AlignmentType.End, undefined);
- if (type === RepetitionInstructionEnum.StartLine || type === RepetitionInstructionEnum.Segno || type === RepetitionInstructionEnum.Coda) {
- this.alignment = AlignmentType.Begin;
- }
- }
- constructor(measureIndex: number, type: RepetitionInstructionEnum, alignment: AlignmentType, parentRepetition: Repetition) {
- this(measureIndex, [], type, alignment, parentRepetition);
- }
- constructor(measureIndex: number, endingIndex: number, type: RepetitionInstructionEnum, alignment: AlignmentType, parentRepetition: Repetition) {
- this(measureIndex, [endingIndex], type, alignment, parentRepetition);
- }
- */
- constructor(measureIndex: number, type: RepetitionInstructionEnum, alignment: AlignmentType = AlignmentType.End,
- parentRepetition: Repetition = undefined, endingIndices: number[] = undefined) {
- this.measureIndex = measureIndex;
- this.endingIndices = endingIndices.slice();
- this.type = type;
- this.alignment = alignment;
- this.parentRepetition = parentRepetition;
- }
- public measureIndex: number;
- public endingIndices: number[];
- public type: RepetitionInstructionEnum;
- public alignment: AlignmentType;
- public parentRepetition: Repetition;
- public CompareTo(obj: Object): number {
- const other: RepetitionInstruction = <RepetitionInstruction>obj;
- if (this.measureIndex > other.measureIndex) {
- return 1;
- } else if (one.measureIndex < other.measureIndex) {
- return -1;
- }
- if (one.alignment === AlignmentType.Begin) {
- if (other.alignment === AlignmentType.End) {
- return -1;
- }
- switch (one.type) {
- case RepetitionInstructionEnum.Ending:
- return 1;
- case RepetitionInstructionEnum.StartLine:
- if (other.type === RepetitionInstructionEnum.Ending) {
- return -1;
- }
- return 1;
- case RepetitionInstructionEnum.Coda:
- case RepetitionInstructionEnum.Segno:
- if (other.type === RepetitionInstructionEnum.Coda) {
- return 1;
- }
- return -1;
- default:
- }
- } else {
- if (other.alignment === AlignmentType.Begin) {
- return 1;
- }
- switch (one.type) {
- case RepetitionInstructionEnum.Ending:
- return -1;
- case RepetitionInstructionEnum.Fine:
- case RepetitionInstructionEnum.ToCoda:
- if (other.type === RepetitionInstructionEnum.Ending) {
- return 1;
- }
- return -1;
- case RepetitionInstructionEnum.ForwardJump:
- switch (other.type) {
- case RepetitionInstructionEnum.Ending:
- case RepetitionInstructionEnum.Fine:
- case RepetitionInstructionEnum.ToCoda:
- return 1;
- default:
- }
- return -1;
- case RepetitionInstructionEnum.DalSegnoAlFine:
- case RepetitionInstructionEnum.DaCapoAlFine:
- case RepetitionInstructionEnum.DalSegnoAlCoda:
- case RepetitionInstructionEnum.DaCapoAlCoda:
- case RepetitionInstructionEnum.DaCapo:
- case RepetitionInstructionEnum.DalSegno:
- case RepetitionInstructionEnum.BackJumpLine:
- return 1;
- default:
- }
- }
- return 0;
- }
- public equals(other: RepetitionInstruction): boolean {
- if (
- this.measureIndex !== other.measureIndex
- || this.type !== other.type
- || this.alignment !== other.alignment
- || this.endingIndices.length !== other.endingIndices.length
- ) {
- return false;
- }
- for (let i: number = 0; i < this.endingIndices.length; i++) {
- if (this.endingIndices[i] !== other.endingIndices[i]) {
- return false;
- }
- }
- return true;
- }
- }
- export enum RepetitionInstructionEnum {
- StartLine,
- ForwardJump,
- BackJumpLine,
- Ending,
- DaCapo,
- DalSegno,
- Fine,
- ToCoda,
- DalSegnoAlFine,
- DaCapoAlFine,
- DalSegnoAlCoda,
- DaCapoAlCoda,
- Coda,
- Segno,
- None,
- }
- export enum AlignmentType {
- Begin,
- End,
- }
|