VexFlowInstantaniousDynamicExpression.ts 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { GraphicalInstantaniousDynamicExpression } from "../GraphicalInstantaniousDynamicExpression";
  2. import { InstantaniousDynamicExpression, DynamicEnum } from "../../VoiceData/Expressions/InstantaniousDynamicExpression";
  3. import { GraphicalStaffEntry } from "../GraphicalStaffEntry";
  4. import { GraphicalLabel } from "../GraphicalLabel";
  5. import { Label } from "../../Label";
  6. import { TextAlignment } from "../../../Common/Enums/TextAlignment";
  7. import { EngravingRules } from "../EngravingRules";
  8. import { FontStyles } from "../../../Common/Enums/FontStyles";
  9. import { SkyBottomLineCalculator } from "../SkyBottomLineCalculator";
  10. import { StaffLine } from "../StaffLine";
  11. import { GraphicalMeasure } from "../GraphicalMeasure";
  12. import { MusicSystem } from "../MusicSystem";
  13. export class VexFlowInstantaniousDynamicExpression extends GraphicalInstantaniousDynamicExpression {
  14. private mInstantaniousDynamicExpression: InstantaniousDynamicExpression;
  15. private mLabel: GraphicalLabel;
  16. constructor(instantaniousDynamicExpression: InstantaniousDynamicExpression, staffEntry: GraphicalStaffEntry) {
  17. super();
  18. this.mInstantaniousDynamicExpression = instantaniousDynamicExpression;
  19. this.mLabel = new GraphicalLabel(new Label(this.Expression),
  20. EngravingRules.Rules.ContinuousDynamicTextHeight,
  21. TextAlignment.LeftTop,
  22. staffEntry ? staffEntry.PositionAndShape : undefined);
  23. let offset: number = staffEntry ? staffEntry.parentMeasure.ParentStaffLine
  24. .SkyBottomLineCalculator.getBottomLineMaxInBoundingBox(staffEntry.parentMeasure.PositionAndShape) : 0;
  25. // TODO: this should not happen: Bug in sbc?
  26. offset = offset < 0 ? 0 : offset;
  27. this.mLabel.PositionAndShape.RelativePosition.y += offset;
  28. this.mLabel.Label.fontStyle = FontStyles.BoldItalic;
  29. this.mLabel.setLabelPositionAndShapeBorders();
  30. }
  31. public calculcateBottomLine(measure: GraphicalMeasure): void {
  32. const skyBottomLineCalculator: SkyBottomLineCalculator = measure.ParentStaffLine.SkyBottomLineCalculator;
  33. const staffLine: StaffLine = measure.ParentStaffLine;
  34. const musicSystem: MusicSystem = measure.parentMusicSystem;
  35. // calculate LabelBoundingBox and set PSI parent
  36. this.mLabel.setLabelPositionAndShapeBorders();
  37. this.mLabel.PositionAndShape.Parent = musicSystem.PositionAndShape;
  38. // calculate relative Position
  39. const relativeX: number = staffLine.PositionAndShape.RelativePosition.x +
  40. measure.PositionAndShape.RelativePosition.x - this.mLabel.PositionAndShape.BorderMarginLeft;
  41. let relativeY: number;
  42. // and the corresponding SkyLine indeces
  43. let start: number = relativeX;
  44. let end: number = relativeX - this.mLabel.PositionAndShape.BorderLeft + this.mLabel.PositionAndShape.BorderMarginRight;
  45. // take into account the InstrumentNameLabel's at the beginning of the first MusicSystem
  46. if (staffLine === musicSystem.StaffLines[0] && musicSystem === musicSystem.Parent.MusicSystems[0]) {
  47. start -= staffLine.PositionAndShape.RelativePosition.x;
  48. end -= staffLine.PositionAndShape.RelativePosition.x;
  49. }
  50. // get the minimum corresponding SkyLine value
  51. const bottomLineMaxValue: number = skyBottomLineCalculator.getBottomLineMaxInRange(start, end);
  52. relativeY = bottomLineMaxValue;
  53. // console.log(start, end, relativeY, this.mLabel.PositionAndShape.BorderMarginBottom)
  54. skyBottomLineCalculator.updateBottomLineInRange(start, end, relativeY + this.mLabel.PositionAndShape.BorderMarginBottom);
  55. }
  56. get Expression(): string {
  57. return DynamicEnum[this.mInstantaniousDynamicExpression.DynEnum];
  58. }
  59. get Label(): GraphicalLabel {
  60. return this.mLabel;
  61. }
  62. }