Slur.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {Note} from "../../Note";
  2. import {Fraction} from "../../../../Common/DataObjects/Fraction";
  3. export class Slur {
  4. constructor() {
  5. // ?
  6. }
  7. private startNote: Note;
  8. private endNote: Note;
  9. public get StartNote(): Note {
  10. return this.startNote;
  11. }
  12. public set StartNote(value: Note) {
  13. this.startNote = value;
  14. }
  15. public get EndNote(): Note {
  16. return this.endNote;
  17. }
  18. public set EndNote(value: Note) {
  19. this.endNote = value;
  20. }
  21. public startNoteHasMoreStartingSlurs(): boolean {
  22. if (this.startNote === undefined) { return false; }
  23. for (let idx: number = 0, len: number = this.startNote.NoteSlurs.length; idx < len; ++idx) {
  24. const slur: Slur = this.startNote.NoteSlurs[idx];
  25. if (slur !== this && slur.StartNote === this.startNote) {
  26. return true;
  27. }
  28. }
  29. return false;
  30. }
  31. public endNoteHasMoreEndingSlurs(): boolean {
  32. if (this.endNote === undefined) { return false; }
  33. for (let idx: number = 0, len: number = this.endNote.NoteSlurs.length; idx < len; ++idx) {
  34. const slur: Slur = this.endNote.NoteSlurs[idx];
  35. if (slur !== this && slur.EndNote === this.endNote) {
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. public isCrossed(): boolean {
  42. return (this.startNote.ParentStaffEntry.ParentStaff !== this.endNote.ParentStaffEntry.ParentStaff);
  43. }
  44. public isSlurLonger(): boolean {
  45. if (this.endNote === undefined || this.startNote === undefined) {
  46. return false;
  47. }
  48. const length: Fraction = Fraction.minus(this.endNote.getAbsoluteTimestamp(), this.startNote.getAbsoluteTimestamp());
  49. for (let idx: number = 0, len: number = this.startNote.NoteSlurs.length; idx < len; ++idx) {
  50. const slur: Slur = this.startNote.NoteSlurs[idx];
  51. if (
  52. slur !== this
  53. && slur.EndNote !== undefined
  54. && slur.StartNote !== undefined
  55. && Fraction.minus(slur.EndNote.getAbsoluteTimestamp(), slur.StartNote.getAbsoluteTimestamp()).CompareTo(length) === -1
  56. ) {
  57. return true;
  58. }
  59. }
  60. for (let idx: number = 0, len: number = this.endNote.NoteSlurs.length; idx < len; ++idx) {
  61. const slur: Slur = this.endNote.NoteSlurs[idx];
  62. if (
  63. slur !== this
  64. && slur.EndNote !== undefined
  65. && slur.StartNote !== undefined
  66. && Fraction.minus(slur.EndNote.getAbsoluteTimestamp(), slur.StartNote.getAbsoluteTimestamp()).CompareTo(length)
  67. ) {
  68. return true;
  69. }
  70. }
  71. return false;
  72. }
  73. }