StaffLine.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 {GraphicalMeasure} from "./GraphicalMeasure";
  8. import {MusicSystem} from "./MusicSystem";
  9. import {StaffLineActivitySymbol} from "./StaffLineActivitySymbol";
  10. import {PointF2D} from "../../Common/DataObjects/PointF2D";
  11. import {GraphicalLabel} from "./GraphicalLabel";
  12. import { SkyBottomLineCalculator } from "./SkyBottomLineCalculator";
  13. import { GraphicalOctaveShift } from "./GraphicalOctaveShift";
  14. import { GraphicalSlur } from "./GraphicalSlur";
  15. import { AlignmentManager } from "./AlignmentManager";
  16. import { AbstractGraphicalExpression } from "./AbstractGraphicalExpression";
  17. /**
  18. * A StaffLine contains the [[Measure]]s in one line of the music sheet
  19. * (one instrument, one line, until a line break)
  20. */
  21. export abstract class StaffLine extends GraphicalObject {
  22. protected measures: GraphicalMeasure[] = [];
  23. protected staffLines: GraphicalLine[] = new Array(5);
  24. protected parentMusicSystem: MusicSystem;
  25. protected parentStaff: Staff;
  26. protected octaveShifts: GraphicalOctaveShift[] = [];
  27. protected skyBottomLine: SkyBottomLineCalculator;
  28. protected alignmentManager: AlignmentManager;
  29. protected lyricLines: GraphicalLine[] = [];
  30. protected lyricsDashes: GraphicalLabel[] = [];
  31. protected abstractExpressions: AbstractGraphicalExpression[] = [];
  32. // For displaying Slurs
  33. protected graphicalSlurs: GraphicalSlur[] = [];
  34. constructor(parentSystem: MusicSystem, parentStaff: Staff) {
  35. super();
  36. this.parentMusicSystem = parentSystem;
  37. this.parentStaff = parentStaff;
  38. this.boundingBox = new BoundingBox(this, parentSystem.PositionAndShape);
  39. this.skyBottomLine = new SkyBottomLineCalculator(this);
  40. this.alignmentManager = new AlignmentManager(this);
  41. }
  42. public get Measures(): GraphicalMeasure[] {
  43. return this.measures;
  44. }
  45. public set Measures(value: GraphicalMeasure[]) {
  46. this.measures = value;
  47. }
  48. public get StaffLines(): GraphicalLine[] {
  49. return this.staffLines;
  50. }
  51. public set StaffLines(value: GraphicalLine[]) {
  52. this.staffLines = value;
  53. }
  54. public get NextStaffLine(): StaffLine {
  55. const idxInParent: number = this.parentMusicSystem.StaffLines.indexOf(this);
  56. return idxInParent !== this.parentMusicSystem.StaffLines.length ? this.parentMusicSystem.StaffLines[idxInParent + 1] : undefined;
  57. }
  58. public get LyricLines(): GraphicalLine[] {
  59. return this.lyricLines;
  60. }
  61. public get AbstractExpressions(): AbstractGraphicalExpression[] {
  62. return this.abstractExpressions;
  63. }
  64. public set AbstractExpressions(value: AbstractGraphicalExpression[]) {
  65. this.abstractExpressions = value;
  66. }
  67. public set LyricLines(value: GraphicalLine[]) {
  68. this.lyricLines = value;
  69. }
  70. public get LyricsDashes(): GraphicalLabel[] {
  71. return this.lyricsDashes;
  72. }
  73. public set LyricsDashes(value: GraphicalLabel[]) {
  74. this.lyricsDashes = value;
  75. }
  76. public get ParentMusicSystem(): MusicSystem {
  77. return this.parentMusicSystem;
  78. }
  79. public set ParentMusicSystem(value: MusicSystem) {
  80. this.parentMusicSystem = value;
  81. }
  82. public get ParentStaff(): Staff {
  83. return this.parentStaff;
  84. }
  85. public set ParentStaff(value: Staff) {
  86. this.parentStaff = value;
  87. }
  88. public get AlignmentManager(): AlignmentManager {
  89. return this.alignmentManager;
  90. }
  91. public get SkyBottomLineCalculator(): SkyBottomLineCalculator {
  92. return this.skyBottomLine;
  93. }
  94. public get SkyLine(): number[] {
  95. return this.skyBottomLine.SkyLine;
  96. }
  97. public get BottomLine(): number[] {
  98. return this.skyBottomLine.BottomLine;
  99. }
  100. public get OctaveShifts(): GraphicalOctaveShift[] {
  101. return this.octaveShifts;
  102. }
  103. public set OctaveShifts(value: GraphicalOctaveShift[]) {
  104. this.octaveShifts = value;
  105. }
  106. // get all Graphical Slurs of a staffline
  107. public get GraphicalSlurs(): GraphicalSlur[] {
  108. return this.graphicalSlurs;
  109. }
  110. /**
  111. * Add a given Graphical Slur to the staffline
  112. * @param gSlur
  113. */
  114. public addSlurToStaffline(gSlur: GraphicalSlur): void {
  115. this.graphicalSlurs.push(gSlur);
  116. }
  117. public addActivitySymbolClickArea(): void {
  118. const activitySymbol: StaffLineActivitySymbol = new StaffLineActivitySymbol(this);
  119. const staffLinePsi: BoundingBox = this.PositionAndShape;
  120. activitySymbol.PositionAndShape.RelativePosition =
  121. new PointF2D(staffLinePsi.RelativePosition.x + staffLinePsi.BorderRight + 0.5, staffLinePsi.RelativePosition.y + 0.5);
  122. activitySymbol.PositionAndShape.Parent = this.parentMusicSystem.PositionAndShape;
  123. }
  124. /**
  125. * True iff [[StaffLine]] belongs to an [[Instrument]] with more than one [[Staff]].
  126. * @returns {boolean}
  127. */
  128. public isPartOfMultiStaffInstrument(): boolean {
  129. const instrument: Instrument = this.parentStaff.ParentInstrument;
  130. if (instrument.Staves.length > 1) {
  131. return true;
  132. }
  133. return false;
  134. }
  135. /**
  136. * Find the [[GraphicalStaffEntry]] closest to the given xPosition.
  137. * @param xPosition
  138. * @returns {GraphicalStaffEntry}
  139. */
  140. public findClosestStaffEntry(xPosition: number): GraphicalStaffEntry {
  141. let closestStaffentry: GraphicalStaffEntry = undefined;
  142. for (let idx: number = 0, len: number = this.Measures.length; idx < len; ++idx) {
  143. const graphicalMeasure: GraphicalMeasure = this.Measures[idx];
  144. for (let idx2: number = 0, len2: number = graphicalMeasure.staffEntries.length; idx2 < len2; ++idx2) {
  145. const graphicalStaffEntry: GraphicalStaffEntry = graphicalMeasure.staffEntries[idx2];
  146. if (
  147. Math.abs(graphicalStaffEntry.PositionAndShape.RelativePosition.x - xPosition + graphicalMeasure.PositionAndShape.RelativePosition.x) < 5.0
  148. ) {
  149. closestStaffentry = graphicalStaffEntry;
  150. }
  151. }
  152. }
  153. return closestStaffentry;
  154. }
  155. }