DrawingParameters.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import { EngravingRules } from "./EngravingRules";
  2. import { PlacementEnum } from "../VoiceData/Expressions/AbstractExpression";
  3. export enum ColoringModes {
  4. XML = 0,
  5. AutoColoring = 1,
  6. CustomColorSet = 2
  7. }
  8. export enum DrawingParametersEnum {
  9. allon = "allon",
  10. compact = "compact",
  11. compacttight = "compacttight",
  12. default = "default",
  13. leadsheet = "leadsheet",
  14. preview = "preview",
  15. thumbnail = "thumbnail",
  16. }
  17. /** Internal drawing/rendering parameters and broad modes like compact and thumbnail. Overlap with EngravingRules. */
  18. export class DrawingParameters {
  19. /** will set other settings if changed with set method */
  20. private drawingParametersEnum: DrawingParametersEnum;
  21. private rules: EngravingRules;
  22. public drawHighlights: boolean;
  23. public drawErrors: boolean;
  24. public drawSelectionStartSymbol: boolean;
  25. public drawSelectionEndSymbol: boolean;
  26. public drawCursors: boolean = true;
  27. public drawActivitySymbols: boolean;
  28. public drawScrollIndicator: boolean;
  29. public drawAnnotations: boolean;
  30. public drawComments: boolean;
  31. public drawMarkedAreas: boolean;
  32. public drawTitle: boolean = true;
  33. public drawSubtitle: boolean = true;
  34. public drawLyricist: boolean = true;
  35. public drawComposer: boolean = true;
  36. public drawCopyright: boolean = false;
  37. public drawCredits: boolean = true;
  38. public drawPartNames: boolean = true;
  39. public coloringMode: ColoringModes;
  40. public fingeringPosition: PlacementEnum = PlacementEnum.Left;
  41. /** Draw notes set to be invisible (print-object="no" in XML). */
  42. public drawHiddenNotes: boolean = false;
  43. constructor(drawingParameters: DrawingParametersEnum = DrawingParametersEnum.default, rules?: EngravingRules) {
  44. this.rules = rules;
  45. if (!this.rules) {
  46. this.rules = new EngravingRules();
  47. }
  48. this.DrawingParametersEnum = drawingParameters;
  49. }
  50. /** Sets drawing parameters enum and changes settings flags accordingly. */
  51. public set DrawingParametersEnum(drawingParametersEnum: DrawingParametersEnum) {
  52. this.drawingParametersEnum = drawingParametersEnum;
  53. switch (drawingParametersEnum) {
  54. case DrawingParametersEnum.allon:
  55. this.setForAllOn();
  56. break;
  57. case DrawingParametersEnum.thumbnail:
  58. this.setForThumbnail();
  59. break;
  60. case DrawingParametersEnum.leadsheet:
  61. this.setForLeadsheet();
  62. break;
  63. case DrawingParametersEnum.compact:
  64. this.setForCompactMode();
  65. break;
  66. case DrawingParametersEnum.compacttight:
  67. this.setForCompactTightMode();
  68. break;
  69. case DrawingParametersEnum.default:
  70. default:
  71. this.setForDefault();
  72. }
  73. }
  74. public get DrawingParametersEnum(): DrawingParametersEnum {
  75. return this.drawingParametersEnum;
  76. }
  77. public setForAllOn(): void {
  78. this.drawHighlights = true;
  79. this.drawErrors = true;
  80. this.drawSelectionStartSymbol = true;
  81. this.drawSelectionEndSymbol = true;
  82. this.drawCursors = true;
  83. this.drawActivitySymbols = true;
  84. this.drawScrollIndicator = true;
  85. this.drawAnnotations = true;
  86. this.drawComments = true;
  87. this.drawMarkedAreas = true;
  88. this.DrawTitle = true;
  89. this.DrawSubtitle = true;
  90. this.DrawComposer = true;
  91. this.DrawLyricist = true;
  92. this.drawCredits = true;
  93. this.DrawPartNames = true;
  94. this.drawHiddenNotes = true;
  95. this.rules.CompactMode = false;
  96. }
  97. public setForDefault(): void {
  98. this.rules.loadDefaultValues(); // this is not ideal, but it's hard to reset compactTight mode properly
  99. this.setForAllOn();
  100. this.drawHiddenNotes = false;
  101. }
  102. public setForThumbnail(): void {
  103. this.drawHighlights = false;
  104. this.drawErrors = false;
  105. this.drawSelectionStartSymbol = false;
  106. this.drawSelectionStartSymbol = false;
  107. this.drawCursors = false;
  108. this.drawActivitySymbols = false;
  109. this.drawScrollIndicator = false;
  110. this.drawAnnotations = true;
  111. this.drawComments = true;
  112. this.drawMarkedAreas = true;
  113. this.drawHiddenNotes = false;
  114. }
  115. public setForCompactMode(): void {
  116. // this.setForDefault(); // this would reset all EngravingRules to default values.
  117. this.rules.CompactMode = true;
  118. this.DrawCredits = false; // sets DrawComposer, DrawTitle, DrawLyricist to false
  119. // this.DrawPartNames = true; // unnecessary
  120. this.drawHiddenNotes = false;
  121. }
  122. public setForCompactTightMode(): void {
  123. this.setForCompactMode(); // also sets CompactMode = true
  124. this.DrawPartNames = false;
  125. this.rules.VoiceSpacingMultiplierVexflow = 0.65;
  126. this.rules.VoiceSpacingAddendVexflow = 2.0;
  127. // tight rendering mode, lower margins and safety distances between systems, staffs etc. may cause overlap.
  128. // these options can afterwards be finetuned by setting osmd.rules.BetweenStaffDistance for example
  129. this.rules.MinSkyBottomDistBetweenStaves = 1.0; // default 1.0. this can cause collisions with slurs and dynamics sometimes
  130. this.rules.MinSkyBottomDistBetweenSystems = 1.0; // default 5.0
  131. // note that this.rules === osmd.rules, since it's passed as a reference
  132. this.rules.BetweenStaffDistance = 2.5;
  133. this.rules.StaffDistance = 3.5;
  134. this.rules.MinimumDistanceBetweenSystems = 1;
  135. // this.rules.PageTopMargin = 0.0; // see this.rules.PageTopMarginNarrow used in compact mode
  136. this.rules.PageBottomMargin = 0.0;
  137. this.rules.PageLeftMargin = 2.0;
  138. this.rules.PageRightMargin = 2.0;
  139. // this.BetweenStaffDistance = 2.5 // etc needs to be set in OSMD.rules
  140. // this.StaffDistance = 3.5
  141. // this.MinimumDistanceBetweenSystems = 1
  142. }
  143. public setForLeadsheet(): void {
  144. this.drawHighlights = false;
  145. this.drawErrors = false;
  146. this.drawSelectionStartSymbol = true;
  147. this.drawSelectionEndSymbol = true;
  148. this.drawCursors = true;
  149. this.drawActivitySymbols = false;
  150. this.drawScrollIndicator = true;
  151. this.drawAnnotations = true;
  152. this.drawComments = true;
  153. this.drawMarkedAreas = true;
  154. }
  155. //#region GETTER / SETTER
  156. public get DrawCredits(): boolean {
  157. return this.drawCredits;
  158. }
  159. public set DrawCredits(value: boolean) {
  160. this.drawCredits = value;
  161. this.DrawComposer = value;
  162. this.DrawTitle = value;
  163. this.DrawSubtitle = value;
  164. this.DrawLyricist = value;
  165. this.DrawCopyright = value;
  166. }
  167. // TODO these drawCredits settings are duplicate in drawingParameters and EngravingRules. Maybe we only need them in EngravingRules.
  168. // this sets the parameter in DrawingParameters, which in turn sets the parameter in EngravingRules.
  169. // see settings below that don't call drawingParameters for the immediate approach.
  170. // on the other hand, DrawingParameters has the added option of setting broad modes (e.g. compact), though they aren't that useful
  171. public get DrawTitle(): boolean {
  172. return this.drawTitle;
  173. }
  174. /** Enable or disable drawing the Title of the piece. If disabled, will disable drawing Subtitle as well. */
  175. public set DrawTitle(value: boolean) {
  176. this.drawTitle = value;
  177. this.rules.RenderTitle = value;
  178. if (!value) { // don't draw subtitle if title isn't drawn
  179. this.DrawSubtitle = false;
  180. }
  181. }
  182. public get DrawSubtitle(): boolean {
  183. return this.drawSubtitle;
  184. }
  185. /** Enable or disable drawing the Subtitle of the piece. If enabled, will enable drawing Title as well. */
  186. public set DrawSubtitle(value: boolean) {
  187. this.drawSubtitle = value;
  188. this.rules.RenderSubtitle = value;
  189. if (value) {
  190. this.DrawTitle = true; // if subtitle is drawn, title needs to be drawn as well
  191. }
  192. }
  193. public get DrawComposer(): boolean {
  194. return this.drawComposer;
  195. }
  196. /** Enable or disable drawing a label for the Composer of the piece. */
  197. public set DrawComposer(value: boolean) {
  198. this.drawComposer = value;
  199. this.rules.RenderComposer = value;
  200. }
  201. public get DrawLyricist(): boolean {
  202. return this.drawLyricist;
  203. }
  204. public set DrawLyricist(value: boolean) {
  205. this.drawLyricist = value;
  206. this.rules.RenderLyricist = value;
  207. }
  208. public get DrawCopyright(): boolean {
  209. return this.drawCopyright;
  210. }
  211. public set DrawCopyright(value: boolean) {
  212. this.drawCopyright = value;
  213. this.rules.RenderCopyright = value;
  214. }
  215. public get DrawPartNames(): boolean {
  216. return this.drawPartNames;
  217. }
  218. public set DrawPartNames(value: boolean) {
  219. this.drawPartNames = value;
  220. this.rules.RenderPartNames = value;
  221. if (!this.rules.RenderPartNames) {
  222. this.rules.RenderPartAbbreviations = false;
  223. }
  224. }
  225. public get FingeringPosition(): PlacementEnum {
  226. return this.fingeringPosition;
  227. }
  228. public set FingeringPosition(value: PlacementEnum) {
  229. this.fingeringPosition = value;
  230. this.rules.FingeringPosition = value;
  231. }
  232. public get Rules(): EngravingRules {
  233. return this.rules;
  234. }
  235. public set Rules(value: EngravingRules) {
  236. this.rules = value;
  237. }
  238. }