VexFlowMusicSystem.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {MusicSystem} from "../MusicSystem";
  2. import {GraphicalMusicPage} from "../GraphicalMusicPage";
  3. import {SystemLinesEnum} from "../SystemLinesEnum";
  4. import {SystemLinePosition} from "../SystemLinePosition";
  5. import {GraphicalMeasure} from "../GraphicalMeasure";
  6. import {SystemLine} from "../SystemLine";
  7. import {VexFlowStaffLine} from "./VexFlowStaffLine";
  8. import {VexFlowMeasure} from "./VexFlowMeasure";
  9. import {VexFlowConverter} from "./VexFlowConverter";
  10. import {StaffLine} from "../StaffLine";
  11. import {EngravingRules} from "../EngravingRules";
  12. import { VexFlowInstrumentBracket } from "./VexFlowInstrumentBracket";
  13. import { VexFlowInstrumentBrace } from "./VexFlowInstrumentBrace";
  14. import { SkyBottomLineCalculator } from "../SkyBottomLineCalculator";
  15. export class VexFlowMusicSystem extends MusicSystem {
  16. constructor(parent: GraphicalMusicPage, id: number) {
  17. super(parent, id);
  18. }
  19. public calculateBorders(rules: EngravingRules): void {
  20. if (this.staffLines.length === 0) {
  21. return;
  22. }
  23. const width: number = this.calcBracketsWidth();
  24. this.boundingBox.BorderLeft = -width;
  25. this.boundingBox.BorderMarginLeft = -width;
  26. this.boundingBox.XBordersHaveBeenSet = true;
  27. const topSkyBottomLineCalculator: SkyBottomLineCalculator = this.staffLines[0].SkyBottomLineCalculator;
  28. const top: number = topSkyBottomLineCalculator.getSkyLineMin();
  29. this.boundingBox.BorderTop = top;
  30. this.boundingBox.BorderMarginTop = top;
  31. const lastStaffLine: StaffLine = this.staffLines[this.staffLines.length - 1];
  32. const bottomSkyBottomLineCalculator: SkyBottomLineCalculator = lastStaffLine.SkyBottomLineCalculator;
  33. const bottom: number = bottomSkyBottomLineCalculator.getBottomLineMax()
  34. + lastStaffLine.PositionAndShape.RelativePosition.y;
  35. this.boundingBox.BorderBottom = bottom;
  36. this.boundingBox.BorderMarginBottom = bottom;
  37. this.boundingBox.XBordersHaveBeenSet = true;
  38. this.boundingBox.YBordersHaveBeenSet = true;
  39. }
  40. /**
  41. * This method creates all the graphical lines and dots needed to render a system line (e.g. bold-thin-dots..).
  42. * @param xPosition
  43. * @param lineWidth
  44. * @param lineType
  45. * @param linePosition indicates if the line belongs to start or end of measure
  46. * @param musicSystem
  47. * @param topMeasure
  48. * @param bottomMeasure
  49. */
  50. protected createSystemLine(xPosition: number, lineWidth: number, lineType: SystemLinesEnum, linePosition: SystemLinePosition,
  51. musicSystem: MusicSystem, topMeasure: GraphicalMeasure, bottomMeasure: GraphicalMeasure = undefined): SystemLine {
  52. const vfMeasure: VexFlowMeasure = topMeasure as VexFlowMeasure;
  53. vfMeasure.addMeasureLine(lineType, linePosition);
  54. if (bottomMeasure) {
  55. // ToDo: feature/Repetitions
  56. // create here the correct lines according to the given lineType.
  57. (bottomMeasure as VexFlowMeasure).lineTo(topMeasure as VexFlowMeasure, VexFlowConverter.line(lineType, linePosition));
  58. (bottomMeasure as VexFlowMeasure).addMeasureLine(lineType, linePosition);
  59. }
  60. return new SystemLine(lineType, linePosition, this, topMeasure, bottomMeasure);
  61. }
  62. /**
  63. * creates an instrument brace for the given dimension.
  64. * The height and positioning can be inferred from the given staff lines.
  65. * @param firstStaffLine the upper StaffLine (use a cast to get the VexFlowStaffLine) of the brace to create
  66. * @param lastStaffLine the lower StaffLine (use a cast to get the VexFlowStaffLine) of the brace to create
  67. */
  68. protected createInstrumentBracket(firstStaffLine: StaffLine, lastStaffLine: StaffLine): void {
  69. // You could write this in one line but the linter doesn't let me.
  70. const firstVexStaff: VexFlowStaffLine = (firstStaffLine as VexFlowStaffLine);
  71. const lastVexStaff: VexFlowStaffLine = (lastStaffLine as VexFlowStaffLine);
  72. const vexFlowBracket: VexFlowInstrumentBrace = new VexFlowInstrumentBrace(firstVexStaff, lastVexStaff);
  73. this.InstrumentBrackets.push(vexFlowBracket);
  74. return;
  75. }
  76. /**
  77. * creates an instrument group bracket for the given dimension.
  78. * There can be cascaded bracket (e.g. a group of 2 in a group of 4) -
  79. * The recursion depth informs about the current depth level (needed for positioning)
  80. * @param firstStaffLine the upper staff line of the bracket to create
  81. * @param lastStaffLine the lower staff line of the bracket to create
  82. * @param recursionDepth
  83. */
  84. protected createGroupBracket(firstStaffLine: StaffLine, lastStaffLine: StaffLine, recursionDepth: number): void {
  85. const firstVexStaff: VexFlowStaffLine = (firstStaffLine as VexFlowStaffLine);
  86. const lastVexStaff: VexFlowStaffLine = (lastStaffLine as VexFlowStaffLine);
  87. if (recursionDepth === 0) {
  88. const vexFlowBracket: VexFlowInstrumentBracket = new VexFlowInstrumentBracket(firstVexStaff, lastVexStaff, recursionDepth);
  89. this.GroupBrackets.push(vexFlowBracket);
  90. } else {
  91. const vexFlowBrace: VexFlowInstrumentBrace = new VexFlowInstrumentBrace(firstVexStaff, lastVexStaff, recursionDepth);
  92. this.GroupBrackets.push(vexFlowBrace);
  93. }
  94. return;
  95. }
  96. }