GraphicalStaffEntryLink.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {StaffEntryLink} from "../VoiceData/StaffEntryLink";
  2. import {GraphicalStaffEntry} from "./GraphicalStaffEntry";
  3. import {GraphicalNote} from "./GraphicalNote";
  4. /**
  5. * The graphical counterpart of a [[StaffEntryLink]].
  6. * Used for linked voices.
  7. */
  8. export class GraphicalStaffEntryLink {
  9. private staffEntryLink: StaffEntryLink;
  10. private graphicalLinkedStaffEntries: GraphicalStaffEntry[] = [];
  11. constructor(staffEntryLink: StaffEntryLink) {
  12. this.staffEntryLink = staffEntryLink;
  13. this.initialize();
  14. }
  15. public get GetStaffEntryLink(): StaffEntryLink {
  16. return this.staffEntryLink;
  17. }
  18. public get GraphicalLinkedStaffEntries(): GraphicalStaffEntry[] {
  19. return this.graphicalLinkedStaffEntries;
  20. }
  21. public set GraphicalLinkedStaffEntries(value: GraphicalStaffEntry[]) {
  22. this.graphicalLinkedStaffEntries = value;
  23. }
  24. public isFilled(): boolean {
  25. for (let i: number = 0; i < this.graphicalLinkedStaffEntries.length; i++) {
  26. if (this.graphicalLinkedStaffEntries[i] === undefined) {
  27. return false;
  28. }
  29. }
  30. return true;
  31. }
  32. /**
  33. * Return all the [[GraphicalNote]]s that correspond to the [[LinkedVoiceEntry]] (the one saved in [[StaffEntryLink]]).
  34. * @param graphicalStaffEntry
  35. * @returns {any}
  36. */
  37. public getLinkedStaffEntriesGraphicalNotes(graphicalStaffEntry: GraphicalStaffEntry): GraphicalNote[] {
  38. if (this.graphicalLinkedStaffEntries.indexOf(graphicalStaffEntry) !== -1) {
  39. let notes: GraphicalNote[] = [];
  40. for (let idx: number = 0, len: number = this.graphicalLinkedStaffEntries.length; idx < len; ++idx) {
  41. let graphicalLinkedStaffEntry: GraphicalStaffEntry = this.graphicalLinkedStaffEntries[idx];
  42. for (let idx2: number = 0, len2: number = graphicalLinkedStaffEntry.notes.length; idx2 < len2; ++idx2) {
  43. let graphicalNotes: GraphicalNote[] = graphicalLinkedStaffEntry.notes[idx2];
  44. for (let idx3: number = 0, len3: number = graphicalNotes.length; idx3 < len3; ++idx3) {
  45. let graphicalNote: GraphicalNote = graphicalNotes[idx3];
  46. if (graphicalNote.sourceNote.ParentStaffEntry.Link !== undefined
  47. && graphicalNote.sourceNote.ParentVoiceEntry === this.staffEntryLink.GetVoiceEntry) {
  48. notes.push(graphicalNote);
  49. }
  50. }
  51. }
  52. }
  53. return notes;
  54. }
  55. return undefined;
  56. }
  57. private initialize(): void {
  58. for (let idx: number = 0, len: number = this.staffEntryLink.LinkStaffEntries.length; idx < len; ++idx) {
  59. this.graphicalLinkedStaffEntries.push(undefined);
  60. }
  61. }
  62. }