DrawingParameters.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.rules.CompactMode = true;
  115. this.DrawCredits = false;
  116. this.DrawPartNames = false;
  117. this.drawHiddenNotes = false;
  118. // this.BetweenStaffDistance = 2.5 // etc needs to be set in OSMD.rules
  119. // this.StaffDistance = 3.5
  120. // this.MinimumDistanceBetweenSystems = 1
  121. }
  122. public setForLeadsheet(): void {
  123. this.drawHighlights = false;
  124. this.drawErrors = false;
  125. this.drawSelectionStartSymbol = true;
  126. this.drawSelectionEndSymbol = true;
  127. this.drawCursors = true;
  128. this.drawActivitySymbols = false;
  129. this.drawScrollIndicator = true;
  130. this.drawComments = true;
  131. this.drawMarkedAreas = true;
  132. }
  133. //#region GETTER / SETTER
  134. public get DrawCredits(): boolean {
  135. return this.drawCredits;
  136. }
  137. public set DrawCredits(value: boolean) {
  138. this.drawCredits = value;
  139. this.DrawComposer = value;
  140. this.DrawTitle = value;
  141. this.DrawSubtitle = value;
  142. this.DrawLyricist = value;
  143. }
  144. // TODO these drawCredits settings are duplicate in drawingParameters and EngravingRules. Maybe we only need them in EngravingRules.
  145. // this sets the parameter in DrawingParameters, which in turn sets the parameter in EngravingRules.
  146. // see settings below that don't call drawingParameters for the immediate approach.
  147. // on the other hand, DrawingParameters has the added option of setting broad modes (e.g. compact), though they aren't that useful
  148. public get DrawTitle(): boolean {
  149. return this.drawTitle;
  150. }
  151. /** Enable or disable drawing the Title of the piece. If disabled, will disable drawing Subtitle as well. */
  152. public set DrawTitle(value: boolean) {
  153. this.drawTitle = value;
  154. this.rules.RenderTitle = value;
  155. if (!value) { // don't draw subtitle if title isn't drawn
  156. this.DrawSubtitle = false;
  157. }
  158. }
  159. public get DrawSubtitle(): boolean {
  160. return this.drawSubtitle;
  161. }
  162. /** Enable or disable drawing the Subtitle of the piece. If enabled, will enable drawing Title as well. */
  163. public set DrawSubtitle(value: boolean) {
  164. this.drawSubtitle = value;
  165. this.rules.RenderSubtitle = value;
  166. if (value) {
  167. this.DrawTitle = true; // if subtitle is drawn, title needs to be drawn as well
  168. }
  169. }
  170. public get DrawComposer(): boolean {
  171. return this.drawComposer;
  172. }
  173. /** Enable or disable drawing a label for the Composer of the piece. */
  174. public set DrawComposer(value: boolean) {
  175. this.drawComposer = value;
  176. this.rules.RenderComposer = value;
  177. }
  178. public get DrawLyricist(): boolean {
  179. return this.drawLyricist;
  180. }
  181. public set DrawLyricist(value: boolean) {
  182. this.drawLyricist = value;
  183. this.rules.RenderLyricist = value;
  184. }
  185. public get DrawPartNames(): boolean {
  186. return this.drawPartNames;
  187. }
  188. public set DrawPartNames(value: boolean) {
  189. this.drawPartNames = value;
  190. this.rules.RenderPartNames = value;
  191. }
  192. public get FingeringPosition(): PlacementEnum {
  193. return this.fingeringPosition;
  194. }
  195. public set FingeringPosition(value: PlacementEnum) {
  196. this.fingeringPosition = value;
  197. this.rules.FingeringPosition = value;
  198. }
  199. public get Rules(): EngravingRules {
  200. return this.rules;
  201. }
  202. public set Rules(value: EngravingRules) {
  203. this.rules = value;
  204. }
  205. }