Tie.ts 1.1 KB

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