DrawingParameters.ts 9.0 KB

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