MusicSheetDrawer.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. import {EngravingRules} from "./EngravingRules";
  2. import {ITextMeasurer} from "../Interfaces/ITextMeasurer";
  3. import {GraphicalMusicSheet} from "./GraphicalMusicSheet";
  4. import {BoundingBox} from "./BoundingBox";
  5. import {GraphicalLayers, OutlineAndFillStyleEnum} from "./DrawingEnums";
  6. import {DrawingParameters} from "./DrawingParameters";
  7. import {GraphicalLine} from "./GraphicalLine";
  8. import {RectangleF2D} from "../../Common/DataObjects/RectangleF2D";
  9. import {PointF2D} from "../../Common/DataObjects/PointF2D";
  10. import {GraphicalRectangle} from "./GraphicalRectangle";
  11. import {GraphicalLabel} from "./GraphicalLabel";
  12. import {Label} from "../Label";
  13. import {TextAlignmentEnum} from "../../Common/Enums/TextAlignment";
  14. import {ArgumentOutOfRangeException} from "../Exceptions";
  15. import {SelectionStartSymbol} from "./SelectionStartSymbol";
  16. import {SelectionEndSymbol} from "./SelectionEndSymbol";
  17. import {MusicSystem} from "./MusicSystem";
  18. import {GraphicalMeasure} from "./GraphicalMeasure";
  19. import {StaffLine} from "./StaffLine";
  20. import {SystemLine} from "./SystemLine";
  21. import {MusicSymbol} from "./MusicSymbol";
  22. import {GraphicalMusicPage} from "./GraphicalMusicPage";
  23. import {Instrument} from "../Instrument";
  24. import {MusicSymbolDrawingStyle, PhonicScoreModes} from "./DrawingMode";
  25. import {GraphicalObject} from "./GraphicalObject";
  26. import { GraphicalInstantaneousDynamicExpression } from "./GraphicalInstantaneousDynamicExpression";
  27. import { GraphicalContinuousDynamicExpression } from "./GraphicalContinuousDynamicExpression";
  28. /**
  29. * Draw a [[GraphicalMusicSheet]] (through the .drawSheet method)
  30. *
  31. * The drawing is implemented with a top-down approach, starting from a music sheet, going through pages, systems, staffs...
  32. * ... and ending in notes, beams, accidentals and other symbols.
  33. * It's worth to say, that this class just draws the symbols and graphical elements, using the positions that have been computed before.
  34. * But in any case, some of these previous positioning algorithms need the sizes of the concrete symbols (NoteHeads, sharps, flats, keys...).
  35. * Therefore, there are some static functions on the 'Bounding Boxes' section used to compute these symbol boxes at the
  36. * beginning for the later use in positioning algorithms.
  37. *
  38. * This class also includes the resizing and positioning of the symbols due to user interaction like zooming or panning.
  39. */
  40. export abstract class MusicSheetDrawer {
  41. public drawingParameters: DrawingParameters;
  42. public splitScreenLineColor: number;
  43. public midiPlaybackAvailable: boolean;
  44. public drawableBoundingBoxElement: string = process.env.DRAW_BOUNDING_BOX_ELEMENT;
  45. public skyLineVisible: boolean = false;
  46. public bottomLineVisible: boolean = false;
  47. protected rules: EngravingRules;
  48. protected graphicalMusicSheet: GraphicalMusicSheet;
  49. protected textMeasurer: ITextMeasurer;
  50. private phonicScoreMode: PhonicScoreModes = PhonicScoreModes.Manual;
  51. constructor(textMeasurer: ITextMeasurer,
  52. drawingParameters: DrawingParameters) {
  53. this.textMeasurer = textMeasurer;
  54. this.splitScreenLineColor = -1;
  55. this.drawingParameters = drawingParameters;
  56. }
  57. public set Mode(value: PhonicScoreModes) {
  58. this.phonicScoreMode = value;
  59. }
  60. public drawSheet(graphicalMusicSheet: GraphicalMusicSheet): void {
  61. this.graphicalMusicSheet = graphicalMusicSheet;
  62. this.rules = graphicalMusicSheet.ParentMusicSheet.Rules;
  63. this.drawSplitScreenLine();
  64. if (this.drawingParameters.drawCursors) {
  65. for (const line of graphicalMusicSheet.Cursors) {
  66. const psi: BoundingBox = new BoundingBox(line);
  67. psi.AbsolutePosition = line.Start;
  68. psi.BorderBottom = line.End.y - line.Start.y;
  69. psi.BorderRight = line.Width / 2.0;
  70. psi.BorderLeft = -line.Width / 2.0;
  71. if (this.isVisible(psi)) {
  72. this.drawLineAsVerticalRectangle(line, <number>GraphicalLayers.Cursor);
  73. }
  74. }
  75. }
  76. // Draw the vertical ScrollIndicator
  77. if (this.drawingParameters.drawScrollIndicator) {
  78. this.drawScrollIndicator();
  79. }
  80. // Draw all the pages
  81. for (const page of this.graphicalMusicSheet.MusicPages) {
  82. this.drawPage(page);
  83. }
  84. }
  85. public drawLineAsHorizontalRectangle(line: GraphicalLine, layer: number): void {
  86. let rectangle: RectangleF2D = new RectangleF2D(line.Start.x, line.End.y - line.Width / 2, line.End.x - line.Start.x, line.Width);
  87. rectangle = this.applyScreenTransformationForRect(rectangle);
  88. this.renderRectangle(rectangle, layer, line.styleId);
  89. }
  90. public drawLineAsVerticalRectangle(line: GraphicalLine, layer: number): void {
  91. const lineStart: PointF2D = line.Start;
  92. const lineWidth: number = line.Width;
  93. let rectangle: RectangleF2D = new RectangleF2D(lineStart.x - lineWidth / 2, lineStart.y, lineWidth, line.End.y - lineStart.y);
  94. rectangle = this.applyScreenTransformationForRect(rectangle);
  95. this.renderRectangle(rectangle, layer, line.styleId);
  96. }
  97. public drawLineAsHorizontalRectangleWithOffset(line: GraphicalLine, offset: PointF2D, layer: number): void {
  98. const start: PointF2D = new PointF2D(line.Start.x + offset.x, line.Start.y + offset.y);
  99. const end: PointF2D = new PointF2D(line.End.x + offset.x, line.End.y + offset.y);
  100. const width: number = line.Width;
  101. let rectangle: RectangleF2D = new RectangleF2D(start.x, end.y - width / 2, end.x - start.x, width);
  102. rectangle = this.applyScreenTransformationForRect(rectangle);
  103. this.renderRectangle(rectangle, layer, line.styleId);
  104. }
  105. public drawLineAsVerticalRectangleWithOffset(line: GraphicalLine, offset: PointF2D, layer: number): void {
  106. const start: PointF2D = new PointF2D(line.Start.x + offset.x, line.Start.y + offset.y);
  107. const end: PointF2D = new PointF2D(line.End.x + offset.x, line.End.y + offset.y);
  108. const width: number = line.Width;
  109. let rectangle: RectangleF2D = new RectangleF2D(start.x, start.y, width, end.y - start.y);
  110. rectangle = this.applyScreenTransformationForRect(rectangle);
  111. this.renderRectangle(rectangle, layer, line.styleId);
  112. }
  113. public drawRectangle(rect: GraphicalRectangle, layer: number): void {
  114. const psi: BoundingBox = rect.PositionAndShape;
  115. let rectangle: RectangleF2D = new RectangleF2D(psi.AbsolutePosition.x, psi.AbsolutePosition.y, psi.BorderRight, psi.BorderBottom);
  116. rectangle = this.applyScreenTransformationForRect(rectangle);
  117. this.renderRectangle(rectangle, layer, <number>rect.style);
  118. }
  119. public calculatePixelDistance(unitDistance: number): number {
  120. throw new Error("not implemented");
  121. }
  122. public drawLabel(graphicalLabel: GraphicalLabel, layer: number): void {
  123. if (!this.isVisible(graphicalLabel.PositionAndShape)) {
  124. return;
  125. }
  126. const label: Label = graphicalLabel.Label;
  127. if (label.text.trim() === "") {
  128. return;
  129. }
  130. const screenPosition: PointF2D = this.applyScreenTransformation(graphicalLabel.PositionAndShape.AbsolutePosition);
  131. const heightInPixel: number = this.calculatePixelDistance(label.fontHeight);
  132. const widthInPixel: number = heightInPixel * this.textMeasurer.computeTextWidthToHeightRatio(label.text, label.font, label.fontStyle);
  133. const bitmapWidth: number = Math.ceil(widthInPixel);
  134. const bitmapHeight: number = Math.ceil(heightInPixel * 1.2);
  135. switch (label.textAlignment) {
  136. // Adjust the OSMD-calculated positions to rendering coordinates
  137. // These have to match the Border settings in GraphicalLabel.setLabelPositionAndShapeBorders()
  138. // TODO isn't this a Vexflow-specific transformation that should be in VexflowMusicSheetDrawer?
  139. case TextAlignmentEnum.LeftTop:
  140. break;
  141. case TextAlignmentEnum.LeftCenter:
  142. screenPosition.y -= bitmapHeight / 2;
  143. break;
  144. case TextAlignmentEnum.LeftBottom:
  145. screenPosition.y -= bitmapHeight;
  146. break;
  147. case TextAlignmentEnum.CenterTop:
  148. screenPosition.x -= bitmapWidth / 2;
  149. break;
  150. case TextAlignmentEnum.CenterCenter:
  151. screenPosition.x -= bitmapWidth / 2;
  152. screenPosition.y -= bitmapHeight / 2;
  153. break;
  154. case TextAlignmentEnum.CenterBottom:
  155. screenPosition.x -= bitmapWidth / 2;
  156. screenPosition.y -= bitmapHeight;
  157. break;
  158. case TextAlignmentEnum.RightTop:
  159. screenPosition.x -= bitmapWidth;
  160. break;
  161. case TextAlignmentEnum.RightCenter:
  162. screenPosition.x -= bitmapWidth;
  163. screenPosition.y -= bitmapHeight / 2;
  164. break;
  165. case TextAlignmentEnum.RightBottom:
  166. screenPosition.x -= bitmapWidth;
  167. screenPosition.y -= bitmapHeight;
  168. break;
  169. default:
  170. throw new ArgumentOutOfRangeException("");
  171. }
  172. this.renderLabel(graphicalLabel, layer, bitmapWidth, bitmapHeight, heightInPixel, screenPosition);
  173. }
  174. protected applyScreenTransformation(point: PointF2D): PointF2D {
  175. throw new Error("not implemented");
  176. }
  177. protected applyScreenTransformations(points: PointF2D[]): PointF2D[] {
  178. const transformedPoints: PointF2D[] = [];
  179. for (const point of points) {
  180. transformedPoints.push(this.applyScreenTransformation(point));
  181. }
  182. return transformedPoints;
  183. }
  184. protected applyScreenTransformationForRect(rectangle: RectangleF2D): RectangleF2D {
  185. throw new Error("not implemented");
  186. }
  187. protected drawSplitScreenLine(): void {
  188. // empty
  189. }
  190. protected renderRectangle(rectangle: RectangleF2D, layer: number, styleId: number, alpha: number = 1): void {
  191. throw new Error("not implemented");
  192. }
  193. protected drawScrollIndicator(): void {
  194. // empty
  195. }
  196. protected drawSelectionStartSymbol(symbol: SelectionStartSymbol): void {
  197. // empty
  198. }
  199. protected drawSelectionEndSymbol(symbol: SelectionEndSymbol): void {
  200. // empty
  201. }
  202. protected renderLabel(graphicalLabel: GraphicalLabel, layer: number, bitmapWidth: number,
  203. bitmapHeight: number, heightInPixel: number, screenPosition: PointF2D): void {
  204. throw new Error("not implemented");
  205. }
  206. protected renderSystemToScreen(system: MusicSystem, systemBoundingBoxInPixels: RectangleF2D,
  207. absBoundingRectWithMargin: RectangleF2D): void {
  208. // empty
  209. }
  210. protected drawMeasure(measure: GraphicalMeasure): void {
  211. throw new Error("not implemented");
  212. }
  213. protected drawSkyLine(staffLine: StaffLine): void {
  214. // empty
  215. }
  216. protected drawBottomLine(staffLine: StaffLine): void {
  217. // empty
  218. }
  219. protected drawInstrumentBrace(brace: GraphicalObject, system: MusicSystem): void {
  220. // empty
  221. }
  222. protected drawGroupBracket(bracket: GraphicalObject, system: MusicSystem): void {
  223. // empty
  224. }
  225. protected isVisible(psi: BoundingBox): boolean {
  226. return true;
  227. }
  228. protected drawMusicSystem(system: MusicSystem): void {
  229. const absBoundingRectWithMargin: RectangleF2D = this.getSystemAbsBoundingRect(system);
  230. const systemBoundingBoxInPixels: RectangleF2D = this.getSytemBoundingBoxInPixels(absBoundingRectWithMargin);
  231. this.drawMusicSystemComponents(system, systemBoundingBoxInPixels, absBoundingRectWithMargin);
  232. }
  233. protected getSytemBoundingBoxInPixels(absBoundingRectWithMargin: RectangleF2D): RectangleF2D {
  234. const systemBoundingBoxInPixels: RectangleF2D = this.applyScreenTransformationForRect(absBoundingRectWithMargin);
  235. systemBoundingBoxInPixels.x = Math.round(systemBoundingBoxInPixels.x);
  236. systemBoundingBoxInPixels.y = Math.round(systemBoundingBoxInPixels.y);
  237. return systemBoundingBoxInPixels;
  238. }
  239. protected getSystemAbsBoundingRect(system: MusicSystem): RectangleF2D {
  240. const relBoundingRect: RectangleF2D = system.PositionAndShape.BoundingRectangle;
  241. const absBoundingRectWithMargin: RectangleF2D = new RectangleF2D(
  242. system.PositionAndShape.AbsolutePosition.x + system.PositionAndShape.BorderLeft - 1,
  243. system.PositionAndShape.AbsolutePosition.y + system.PositionAndShape.BorderTop - 1,
  244. (relBoundingRect.width + 6), (relBoundingRect.height + 2)
  245. );
  246. return absBoundingRectWithMargin;
  247. }
  248. protected drawMusicSystemComponents(musicSystem: MusicSystem, systemBoundingBoxInPixels: RectangleF2D,
  249. absBoundingRectWithMargin: RectangleF2D): void {
  250. const selectStartSymb: SelectionStartSymbol = this.graphicalMusicSheet.SelectionStartSymbol;
  251. const selectEndSymb: SelectionEndSymbol = this.graphicalMusicSheet.SelectionEndSymbol;
  252. if (this.drawingParameters.drawSelectionStartSymbol) {
  253. if (selectStartSymb !== undefined && this.isVisible(selectStartSymb.PositionAndShape)) {
  254. this.drawSelectionStartSymbol(selectStartSymb);
  255. }
  256. }
  257. if (this.drawingParameters.drawSelectionEndSymbol) {
  258. if (selectEndSymb !== undefined && this.isVisible(selectEndSymb.PositionAndShape)) {
  259. this.drawSelectionEndSymbol(selectEndSymb);
  260. }
  261. }
  262. for (const staffLine of musicSystem.StaffLines) {
  263. this.drawStaffLine(staffLine);
  264. // draw lyric dashes
  265. if (staffLine.LyricsDashes.length > 0) {
  266. this.drawDashes(staffLine.LyricsDashes);
  267. }
  268. // draw lyric lines (e.g. LyricExtends: "dich,___")
  269. if (staffLine.LyricLines.length > 0) {
  270. this.drawLyricLines(staffLine.LyricLines, staffLine);
  271. }
  272. }
  273. for (const systemLine of musicSystem.SystemLines) {
  274. this.drawSystemLineObject(systemLine);
  275. }
  276. if (musicSystem === musicSystem.Parent.MusicSystems[0] && musicSystem.Parent === musicSystem.Parent.Parent.MusicPages[0]) {
  277. for (const label of musicSystem.Labels) {
  278. this.drawLabel(label, <number>GraphicalLayers.Notes);
  279. }
  280. }
  281. for (const bracket of musicSystem.InstrumentBrackets) {
  282. this.drawInstrumentBrace(bracket, musicSystem);
  283. }
  284. for (const bracket of musicSystem.GroupBrackets) {
  285. this.drawGroupBracket(bracket, musicSystem);
  286. }
  287. if (!this.leadSheet) {
  288. for (const measureNumberLabel of musicSystem.MeasureNumberLabels) {
  289. this.drawLabel(measureNumberLabel, <number>GraphicalLayers.Notes);
  290. }
  291. }
  292. for (const staffLine of musicSystem.StaffLines) {
  293. this.drawStaffLineSymbols(staffLine);
  294. }
  295. if (this.drawingParameters.drawMarkedAreas) {
  296. this.drawMarkedAreas(musicSystem);
  297. }
  298. if (this.drawingParameters.drawComments) {
  299. this.drawComment(musicSystem);
  300. }
  301. }
  302. protected activateSystemRendering(systemId: number, absBoundingRect: RectangleF2D,
  303. systemBoundingBoxInPixels: RectangleF2D, createNewImage: boolean): boolean {
  304. return true;
  305. }
  306. protected drawSystemLineObject(systemLine: SystemLine): void {
  307. // empty
  308. }
  309. protected drawStaffLine(staffLine: StaffLine): void {
  310. for (const measure of staffLine.Measures) {
  311. this.drawMeasure(measure);
  312. }
  313. if (staffLine.LyricsDashes.length > 0) {
  314. this.drawDashes(staffLine.LyricsDashes);
  315. }
  316. this.drawOctaveShifts(staffLine);
  317. this.drawExpressions(staffLine);
  318. if (this.skyLineVisible) {
  319. this.drawSkyLine(staffLine);
  320. }
  321. if (this.bottomLineVisible) {
  322. this.drawBottomLine(staffLine);
  323. }
  324. }
  325. protected drawLyricLines(lyricLines: GraphicalLine[], staffLine: StaffLine): void {
  326. staffLine.LyricLines.forEach(lyricLine => {
  327. // TODO maybe we should put this in the calculation (MusicSheetCalculator.calculateLyricExtend)
  328. // then we can also remove staffLine argument
  329. // but same addition doesn't work in calculateLyricExtend, because y-spacing happens after lyrics positioning
  330. lyricLine.Start.y += staffLine.PositionAndShape.AbsolutePosition.y;
  331. lyricLine.End.y += staffLine.PositionAndShape.AbsolutePosition.y;
  332. lyricLine.Start.x += staffLine.PositionAndShape.AbsolutePosition.x;
  333. lyricLine.End.x += staffLine.PositionAndShape.AbsolutePosition.x;
  334. this.drawGraphicalLine(lyricLine, EngravingRules.Rules.LyricUnderscoreLineWidth);
  335. });
  336. }
  337. protected drawExpressions(staffline: StaffLine): void {
  338. // implemented by subclass (VexFlowMusicSheetDrawer)
  339. }
  340. protected drawGraphicalLine(graphicalLine: GraphicalLine, lineWidth: number, colorOrStyle: string = "black"): void {
  341. /* TODO similar checks as in drawLabel
  342. if (!this.isVisible(new BoundingBox(graphicalLine.Start,)) {
  343. return;
  344. }
  345. */
  346. this.drawLine(graphicalLine.Start, graphicalLine.End, colorOrStyle, lineWidth);
  347. }
  348. public drawLine(start: PointF2D, stop: PointF2D, color: string = "#FF0000FF", lineWidth: number): void {
  349. // implemented by subclass (VexFlowMusicSheetDrawer)
  350. }
  351. /**
  352. * Draw all dashes to the canvas
  353. * @param lyricsDashes Array of lyric dashes to be drawn
  354. * @param layer Number of the layer that the lyrics should be drawn in
  355. */
  356. protected drawDashes(lyricsDashes: GraphicalLabel[]): void {
  357. lyricsDashes.forEach(dash => this.drawLabel(dash, <number>GraphicalLayers.Notes));
  358. }
  359. // protected drawSlur(slur: GraphicalSlur, abs: PointF2D): void {
  360. //
  361. // }
  362. protected drawOctaveShifts(staffLine: StaffLine): void {
  363. return;
  364. }
  365. protected drawStaffLines(staffLine: StaffLine): void {
  366. if (staffLine.StaffLines !== undefined) {
  367. const position: PointF2D = staffLine.PositionAndShape.AbsolutePosition;
  368. for (let i: number = 0; i < 5; i++) {
  369. this.drawLineAsHorizontalRectangleWithOffset(staffLine.StaffLines[i], position, <number>GraphicalLayers.Notes);
  370. }
  371. }
  372. }
  373. // protected drawEnding(ending: GraphicalRepetitionEnding, absolutePosition: PointF2D): void {
  374. // if (undefined !== ending.Left)
  375. // drawLineAsVerticalRectangle(ending.Left, absolutePosition, <number>GraphicalLayers.Notes);
  376. // this.drawLineAsHorizontalRectangle(ending.Top, absolutePosition, <number>GraphicalLayers.Notes);
  377. // if (undefined !== ending.Right)
  378. // drawLineAsVerticalRectangle(ending.Right, absolutePosition, <number>GraphicalLayers.Notes);
  379. // this.drawLabel(ending.Label, <number>GraphicalLayers.Notes);
  380. // }
  381. /**
  382. * Draws an instantaneous dynamic expression (p, pp, f, ff, ...) to the canvas
  383. * @param instantaneousDynamic GraphicalInstantaneousDynamicExpression to be drawn
  384. */
  385. protected drawInstantaneousDynamic(instantaneousDynamic: GraphicalInstantaneousDynamicExpression): void {
  386. throw new Error("not implemented");
  387. }
  388. /**
  389. * Draws a continuous dynamic expression (wedges) to the canvas
  390. * @param expression GraphicalContinuousDynamicExpression to be drawn
  391. */
  392. protected drawContinuousDynamic(expression: GraphicalContinuousDynamicExpression): void {
  393. throw new Error("not implemented");
  394. }
  395. protected drawSymbol(symbol: MusicSymbol, symbolStyle: MusicSymbolDrawingStyle, position: PointF2D,
  396. scalingFactor: number = 1, layer: number = <number>GraphicalLayers.Notes): void {
  397. //empty
  398. }
  399. protected get leadSheet(): boolean {
  400. return this.graphicalMusicSheet.LeadSheet;
  401. }
  402. protected set leadSheet(value: boolean) {
  403. this.graphicalMusicSheet.LeadSheet = value;
  404. }
  405. private drawPage(page: GraphicalMusicPage): void {
  406. if (!this.isVisible(page.PositionAndShape)) {
  407. return;
  408. }
  409. for (const system of page.MusicSystems) {
  410. if (this.isVisible(system.PositionAndShape)) {
  411. this.drawMusicSystem(system);
  412. }
  413. }
  414. if (page === page.Parent.MusicPages[0]) {
  415. for (const label of page.Labels) {
  416. this.drawLabel(label, <number>GraphicalLayers.Notes);
  417. }
  418. }
  419. // Draw bounding boxes for debug purposes. This has to be at the end because only
  420. // then all the calculations and recalculations are done
  421. if (this.drawableBoundingBoxElement) {
  422. this.drawBoundingBoxes(page.PositionAndShape, 0, this.drawableBoundingBoxElement);
  423. }
  424. }
  425. /**
  426. * Draw bounding boxes aroung GraphicalObjects
  427. * @param startBox Bounding Box that is used as a staring point to recursively go through all child elements
  428. * @param layer Layer to draw to
  429. * @param type Type of element to show bounding boxes for as string.
  430. */
  431. private drawBoundingBoxes(startBox: BoundingBox, layer: number = 0, type: string = "all"): void {
  432. const dataObjectString: string = (startBox.DataObject.constructor as any).name;
  433. if (dataObjectString === type || type === "all") {
  434. let tmpRect: RectangleF2D = new RectangleF2D(startBox.AbsolutePosition.x + startBox.BorderMarginLeft,
  435. startBox.AbsolutePosition.y + startBox.BorderMarginTop,
  436. startBox.BorderMarginRight - startBox.BorderMarginLeft,
  437. startBox.BorderMarginBottom - startBox.BorderMarginTop);
  438. this.drawLineAsHorizontalRectangle(new GraphicalLine(
  439. new PointF2D(startBox.AbsolutePosition.x - 1, startBox.AbsolutePosition.y),
  440. new PointF2D(startBox.AbsolutePosition.x + 1, startBox.AbsolutePosition.y),
  441. 0.1,
  442. OutlineAndFillStyleEnum.BaseWritingColor),
  443. layer - 1);
  444. this.drawLineAsVerticalRectangle(new GraphicalLine(
  445. new PointF2D(startBox.AbsolutePosition.x, startBox.AbsolutePosition.y - 1),
  446. new PointF2D(startBox.AbsolutePosition.x, startBox.AbsolutePosition.y + 1),
  447. 0.1,
  448. OutlineAndFillStyleEnum.BaseWritingColor),
  449. layer - 1);
  450. tmpRect = this.applyScreenTransformationForRect(tmpRect);
  451. this.renderRectangle(tmpRect, <number>GraphicalLayers.Background, layer, 0.5);
  452. this.renderLabel(new GraphicalLabel(new Label(dataObjectString), 0.8, TextAlignmentEnum.CenterCenter),
  453. layer, tmpRect.width, tmpRect.height, tmpRect.height, new PointF2D(tmpRect.x, tmpRect.y + 12));
  454. }
  455. layer++;
  456. startBox.ChildElements.forEach(bb => this.drawBoundingBoxes(bb, layer, type));
  457. }
  458. private drawMarkedAreas(system: MusicSystem): void {
  459. for (const markedArea of system.GraphicalMarkedAreas) {
  460. if (markedArea !== undefined) {
  461. if (markedArea.systemRectangle !== undefined) {
  462. this.drawRectangle(markedArea.systemRectangle, <number>GraphicalLayers.Background);
  463. }
  464. if (markedArea.settings !== undefined) {
  465. this.drawLabel(markedArea.settings, <number>GraphicalLayers.Comment);
  466. }
  467. if (markedArea.labelRectangle !== undefined) {
  468. this.drawRectangle(markedArea.labelRectangle, <number>GraphicalLayers.Background);
  469. }
  470. if (markedArea.label !== undefined) {
  471. this.drawLabel(markedArea.label, <number>GraphicalLayers.Comment);
  472. }
  473. }
  474. }
  475. }
  476. private drawComment(system: MusicSystem): void {
  477. for (const comment of system.GraphicalComments) {
  478. if (comment !== undefined) {
  479. if (comment.settings !== undefined) {
  480. this.drawLabel(comment.settings, <number>GraphicalLayers.Comment);
  481. }
  482. if (comment.label !== undefined) {
  483. this.drawLabel(comment.label, <number>GraphicalLayers.Comment);
  484. }
  485. }
  486. }
  487. }
  488. private drawStaffLineSymbols(staffLine: StaffLine): void {
  489. const parentInst: Instrument = staffLine.ParentStaff.ParentInstrument;
  490. const absX: number = staffLine.PositionAndShape.AbsolutePosition.x;
  491. const absY: number = staffLine.PositionAndShape.AbsolutePosition.y + 2;
  492. const borderRight: number = staffLine.PositionAndShape.BorderRight;
  493. if (parentInst.highlight && this.drawingParameters.drawHighlights) {
  494. this.drawLineAsHorizontalRectangle(
  495. new GraphicalLine(
  496. new PointF2D(absX, absY),
  497. new PointF2D(absX + borderRight, absY),
  498. 4,
  499. OutlineAndFillStyleEnum.Highlighted
  500. ),
  501. <number>GraphicalLayers.Highlight
  502. );
  503. }
  504. let style: MusicSymbolDrawingStyle = MusicSymbolDrawingStyle.Disabled;
  505. let symbol: MusicSymbol = MusicSymbol.PLAY;
  506. let drawSymbols: boolean = this.drawingParameters.drawActivitySymbols;
  507. switch (this.phonicScoreMode) {
  508. case PhonicScoreModes.Midi:
  509. symbol = MusicSymbol.PLAY;
  510. if (this.midiPlaybackAvailable && staffLine.ParentStaff.audible) {
  511. style = MusicSymbolDrawingStyle.PlaybackSymbols;
  512. }
  513. break;
  514. case PhonicScoreModes.Following:
  515. symbol = MusicSymbol.MIC;
  516. if (staffLine.ParentStaff.following) {
  517. style = MusicSymbolDrawingStyle.FollowSymbols;
  518. }
  519. break;
  520. default:
  521. drawSymbols = false;
  522. break;
  523. }
  524. if (drawSymbols) {
  525. const p: PointF2D = new PointF2D(absX + borderRight + 2, absY);
  526. this.drawSymbol(symbol, style, p);
  527. }
  528. if (this.drawingParameters.drawErrors) {
  529. for (const measure of staffLine.Measures) {
  530. const measurePSI: BoundingBox = measure.PositionAndShape;
  531. const absXPSI: number = measurePSI.AbsolutePosition.x;
  532. const absYPSI: number = measurePSI.AbsolutePosition.y + 2;
  533. if (measure.hasError && this.graphicalMusicSheet.ParentMusicSheet.DrawErroneousMeasures) {
  534. this.drawLineAsHorizontalRectangle(
  535. new GraphicalLine(
  536. new PointF2D(absXPSI, absYPSI),
  537. new PointF2D(absXPSI + measurePSI.BorderRight, absYPSI),
  538. 4,
  539. OutlineAndFillStyleEnum.ErrorUnderlay
  540. ),
  541. <number>GraphicalLayers.MeasureError
  542. );
  543. }
  544. }
  545. }
  546. }
  547. }