VexFlowMusicSystem.ts 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {MusicSystem} from "../MusicSystem";
  2. import {GraphicalMusicPage} from "../GraphicalMusicPage";
  3. import {SystemLinesEnum} from "../SystemLinesEnum";
  4. import {SystemLinePosition} from "../SystemLinePosition";
  5. import {StaffMeasure} from "../StaffMeasure";
  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. export class VexFlowMusicSystem extends MusicSystem {
  14. constructor(parent: GraphicalMusicPage, id: number) {
  15. super(parent, id);
  16. }
  17. public calculateBorders(rules: EngravingRules): void {
  18. if (this.staffLines.length === 0) {
  19. return;
  20. }
  21. const width: number = this.calcBracketsWidth();
  22. this.boundingBox.BorderLeft = -width;
  23. this.boundingBox.BorderMarginLeft = -width;
  24. this.boundingBox.XBordersHaveBeenSet = true;
  25. }
  26. /**
  27. * This method creates all the graphical lines and dots needed to render a system line (e.g. bold-thin-dots..).
  28. * @param xPosition
  29. * @param lineWidth
  30. * @param lineType
  31. * @param linePosition indicates if the line belongs to start or end of measure
  32. * @param musicSystem
  33. * @param topMeasure
  34. * @param bottomMeasure
  35. */
  36. protected createSystemLine(xPosition: number, lineWidth: number, lineType: SystemLinesEnum, linePosition: SystemLinePosition,
  37. musicSystem: MusicSystem, topMeasure: StaffMeasure, bottomMeasure: StaffMeasure = undefined): SystemLine {
  38. const vfMeasure: VexFlowMeasure = topMeasure as VexFlowMeasure;
  39. vfMeasure.addMeasureLine(lineType, linePosition);
  40. if (bottomMeasure) {
  41. // ToDo: feature/Repetitions
  42. // create here the correct lines according to the given lineType.
  43. (bottomMeasure as VexFlowMeasure).lineTo(topMeasure as VexFlowMeasure, VexFlowConverter.line(lineType));
  44. (bottomMeasure as VexFlowMeasure).addMeasureLine(lineType, linePosition);
  45. }
  46. return new SystemLine(lineType, linePosition, this, topMeasure, bottomMeasure);
  47. }
  48. /**
  49. * creates an instrument brace for the given dimension.
  50. * The height and positioning can be inferred from the given staff lines.
  51. * @param firstStaffLine the upper StaffLine (use a cast to get the VexFlowStaffLine) of the brace to create
  52. * @param lastStaffLine the lower StaffLine (use a cast to get the VexFlowStaffLine) of the brace to create
  53. */
  54. protected createInstrumentBracket(firstStaffLine: StaffLine, lastStaffLine: StaffLine): void {
  55. // You could write this in one line but the linter doesn't let me.
  56. const firstVexStaff: VexFlowStaffLine = (firstStaffLine as VexFlowStaffLine);
  57. const lastVexStaff: VexFlowStaffLine = (lastStaffLine as VexFlowStaffLine);
  58. const vexFlowBracket: VexFlowInstrumentBracket = new VexFlowInstrumentBracket(firstVexStaff, lastVexStaff);
  59. this.InstrumentBrackets.push(vexFlowBracket);
  60. return;
  61. }
  62. /**
  63. * creates an instrument group bracket for the given dimension.
  64. * There can be cascaded bracket (e.g. a group of 2 in a group of 4) -
  65. * The recursion depth informs about the current depth level (needed for positioning)
  66. * @param firstStaffLine the upper staff line of the bracket to create
  67. * @param lastStaffLine the lower staff line of the bracket to create
  68. * @param staffHeight
  69. * @param recursionDepth
  70. */
  71. protected createGroupBracket(firstStaffLine: StaffLine, lastStaffLine: StaffLine, recursionDepth: number): void {
  72. return;
  73. }
  74. }