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