DrawingParameters.ts 8.7 KB

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