/
Tuplet.ts
69 lines (56 loc) · 1.85 KB
/
Tuplet.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {Note} from "./Note";
import {Fraction} from "../../Common/DataObjects/Fraction";
/**
* Tuplets create irregular rhythms; e.g. triplets, quadruplets, quintuplets, etc.
*/
export class Tuplet {
constructor(tupletLabelNumber: number, bracket: boolean = false) {
this.tupletLabelNumber = tupletLabelNumber;
this.bracket = bracket;
}
private tupletLabelNumber: number;
/** Notes contained in the tuplet, per VoiceEntry (list of VoiceEntries, which has a list of notes). */
private notes: Note[][] = []; // TODO should probably be VoiceEntry[], not Note[][].
private fractions: Fraction[] = [];
/** Whether this tuplet has a bracket. (e.g. showing |--3--| or just 3 for a triplet) */
private bracket: boolean;
public get TupletLabelNumber(): number {
return this.tupletLabelNumber;
}
public set TupletLabelNumber(value: number) {
this.tupletLabelNumber = value;
}
public get Notes(): Note[][] {
return this.notes;
}
public set Notes(value: Note[][]) {
this.notes = value;
}
public get Fractions(): Fraction[] {
return this.fractions;
}
public set Fractions(value: Fraction[]) {
this.fractions = value;
}
public get Bracket(): boolean {
return this.bracket;
}
public set Bracket(value: boolean) {
this.bracket = value;
}
/**
* Returns the index of the given Note in the Tuplet List (notes[0], notes[1],...).
* @param note
* @returns {number}
*/
public getNoteIndex(note: Note): number {
for (let i: number = this.notes.length - 1; i >= 0; i--) {
for (let j: number = 0; j < this.notes[i].length; j++) {
if (note === this.notes[i][j]) {
return i;
}
}
}
return 0;
}
}