Tie.ts 924 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {Note} from "./Note";
  2. import { Fraction } from "../../Common/DataObjects/Fraction";
  3. import { Pitch } from "../../Common/DataObjects/Pitch";
  4. /**
  5. * A [[Tie]] connects two notes of the same pitch and name, indicating that they have to be played as a single note.
  6. */
  7. export class Tie {
  8. constructor(note: Note) {
  9. this.AddNote(note);
  10. }
  11. private notes: Note[] = [];
  12. public get Notes(): Note[] {
  13. return this.notes;
  14. }
  15. public get StartNote(): Note {
  16. return this.notes[0];
  17. }
  18. public get Duration(): Fraction {
  19. const duration: Fraction = new Fraction();
  20. for (const note of this.notes) {
  21. duration.Add(note.Length);
  22. }
  23. return duration;
  24. }
  25. public get Pitch(): Pitch {
  26. return this.StartNote.Pitch;
  27. }
  28. public AddNote(note: Note): void {
  29. this.notes.push(note);
  30. note.NoteTie = this;
  31. }
  32. }