StaffLine.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {Staff} from "../VoiceData/Staff";
  2. import {BoundingBox} from "./BoundingBox";
  3. import {Instrument} from "../Instrument";
  4. import {GraphicalLine} from "./GraphicalLine";
  5. import {GraphicalStaffEntry} from "./GraphicalStaffEntry";
  6. import {GraphicalObject} from "./GraphicalObject";
  7. import {StaffMeasure} from "./StaffMeasure";
  8. import {MusicSystem} from "./MusicSystem";
  9. import {StaffLineActivitySymbol} from "./StaffLineActivitySymbol";
  10. import {PointF2D} from "../../Common/DataObjects/PointF2D";
  11. export abstract class StaffLine extends GraphicalObject {
  12. protected measures: StaffMeasure[] = [];
  13. protected staffLines: GraphicalLine[] = new Array(5);
  14. protected parentMusicSystem: MusicSystem;
  15. protected parentStaff: Staff;
  16. protected skyLine: number[];
  17. protected bottomLine: number[];
  18. constructor(parentSystem: MusicSystem, parentStaff: Staff) {
  19. super();
  20. this.parentMusicSystem = parentSystem;
  21. this.parentStaff = parentStaff;
  22. this.boundingBox = new BoundingBox(this, parentSystem.PositionAndShape);
  23. }
  24. public get Measures(): StaffMeasure[] {
  25. return this.measures;
  26. }
  27. public set Measures(value: StaffMeasure[]) {
  28. this.measures = value;
  29. }
  30. public get StaffLines(): GraphicalLine[] {
  31. return this.staffLines;
  32. }
  33. public set StaffLines(value: GraphicalLine[]) {
  34. this.staffLines = value;
  35. }
  36. public get ParentMusicSystem(): MusicSystem {
  37. return this.parentMusicSystem;
  38. }
  39. public set ParentMusicSystem(value: MusicSystem) {
  40. this.parentMusicSystem = value;
  41. }
  42. public get ParentStaff(): Staff {
  43. return this.parentStaff;
  44. }
  45. public set ParentStaff(value: Staff) {
  46. this.parentStaff = value;
  47. }
  48. public get SkyLine(): number[] {
  49. return this.skyLine;
  50. }
  51. public set SkyLine(value: number[]) {
  52. this.skyLine = value;
  53. }
  54. public get BottomLine(): number[] {
  55. return this.bottomLine;
  56. }
  57. public set BottomLine(value: number[]) {
  58. this.bottomLine = value;
  59. }
  60. public addActivitySymbolClickArea(): void {
  61. let activitySymbol: StaffLineActivitySymbol = new StaffLineActivitySymbol(this);
  62. let staffLinePsi: BoundingBox = this.PositionAndShape;
  63. activitySymbol.PositionAndShape.RelativePosition =
  64. new PointF2D(staffLinePsi.RelativePosition.x + staffLinePsi.BorderRight + 0.5, staffLinePsi.RelativePosition.y + 0.5);
  65. this.parentMusicSystem.PositionAndShape.ChildElements.push(activitySymbol.PositionAndShape);
  66. }
  67. public isPartOfMultiStaffInstrument(): boolean {
  68. let instrument: Instrument = this.parentStaff.ParentInstrument;
  69. if (instrument.Staves.length > 1) {
  70. return true;
  71. }
  72. return false;
  73. }
  74. public findClosestStaffEntry(xPosition: number): GraphicalStaffEntry {
  75. let closestStaffentry: GraphicalStaffEntry = undefined;
  76. let difference: number = Number.MAX_VALUE;
  77. for (let idx: number = 0, len: number = this.Measures.length; idx < len; ++idx) {
  78. let graphicalMeasure: StaffMeasure = this.Measures[idx];
  79. for (let idx2: number = 0, len2: number = graphicalMeasure.staffEntries.length; idx2 < len2; ++idx2) {
  80. let graphicalStaffEntry: GraphicalStaffEntry = graphicalMeasure.staffEntries[idx2];
  81. if (
  82. Math.abs(graphicalStaffEntry.PositionAndShape.RelativePosition.x - xPosition + graphicalMeasure.PositionAndShape.RelativePosition.x) < 5.0
  83. ) {
  84. difference = Math.abs(
  85. graphicalStaffEntry.PositionAndShape.RelativePosition.x - xPosition + graphicalMeasure.PositionAndShape.RelativePosition.x
  86. );
  87. closestStaffentry = graphicalStaffEntry;
  88. }
  89. }
  90. }
  91. return closestStaffentry;
  92. }
  93. }