Tuplet.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {Note} from "./Note";
  2. import {Fraction} from "../../Common/DataObjects/Fraction";
  3. /**
  4. * Tuplets create irregular rhythms; e.g. triplets, quadruplets, quintuplets, etc.
  5. */
  6. export class Tuplet {
  7. constructor(tupletLabelNumber: number) {
  8. this.tupletLabelNumber = tupletLabelNumber;
  9. }
  10. private tupletLabelNumber: number;
  11. private notes: Note[][] = [];
  12. private fractions: Fraction[] = [];
  13. public get TupletLabelNumber(): number {
  14. return this.tupletLabelNumber;
  15. }
  16. public set TupletLabelNumber(value: number) {
  17. this.tupletLabelNumber = value;
  18. }
  19. public get Notes(): Note[][] {
  20. return this.notes;
  21. }
  22. public set Notes(value: Note[][]) {
  23. this.notes = value;
  24. }
  25. public get Fractions(): Fraction[] {
  26. return this.fractions;
  27. }
  28. public set Fractions(value: Fraction[]) {
  29. this.fractions = value;
  30. }
  31. /**
  32. * Returns the index of the given Note in the Tuplet List (notes[0], notes[1],...).
  33. * @param note
  34. * @returns {number}
  35. */
  36. public getNoteIndex(note: Note): number {
  37. for (let i: number = this.notes.length - 1; i >= 0; i--) {
  38. for (let j: number = 0; j < this.notes[i].length; j++) {
  39. if (note === this.notes[i][j]) {
  40. return i;
  41. }
  42. }
  43. }
  44. return 0;
  45. }
  46. }