Tuplet.ts 2.0 KB

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