GraphicalStaffEntryLink.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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]) {
  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. const notes: GraphicalNote[] = [];
  40. for (let idx: number = 0, len: number = this.graphicalLinkedStaffEntries.length; idx < len; ++idx) {
  41. const graphicalLinkedStaffEntry: GraphicalStaffEntry = this.graphicalLinkedStaffEntries[idx];
  42. for (const gve of graphicalLinkedStaffEntry.graphicalVoiceEntries) {
  43. for (const graphicalNote of gve.notes) {
  44. if (graphicalNote.sourceNote.ParentStaffEntry.Link
  45. && graphicalNote.sourceNote.ParentVoiceEntry === this.staffEntryLink.GetVoiceEntry) {
  46. notes.push(graphicalNote);
  47. }
  48. }
  49. }
  50. }
  51. return notes;
  52. }
  53. return undefined;
  54. }
  55. private initialize(): void {
  56. for (let idx: number = 0, len: number = this.staffEntryLink.LinkStaffEntries.length; idx < len; ++idx) {
  57. this.graphicalLinkedStaffEntries.push(undefined);
  58. }
  59. }
  60. }