@@ -36,6 +36,11 @@ const assertIsValidTimeSig = (timeSpec: string) => {
36
36
} ) ;
37
37
} ;
38
38
39
+ /**
40
+ * A TimeSignature is a StaveModifier that can make its appropriate Glyphs directly from
41
+ * a provided "timeSpec" such as "4/4", "C|" (cut time), or even something more advanced
42
+ * such as "3/4(6/8)" or "2/4+5/8".
43
+ */
39
44
export class TimeSignature extends StaveModifier {
40
45
static get CATEGORY ( ) : string {
41
46
return Category . TimeSignature ;
@@ -57,8 +62,8 @@ export class TimeSignature extends StaveModifier {
57
62
}
58
63
59
64
point : number ;
60
- bottomLine : number ;
61
- topLine : number ;
65
+ bottomLine : number ; // bottomLine and topLine are used to calculate the position of the
66
+ topLine : number ; // top row of digits in a numeric TimeSignature.
62
67
63
68
protected timeSpec : string = '4/4' ;
64
69
protected line : number = 0 ;
@@ -81,10 +86,14 @@ export class TimeSignature extends StaveModifier {
81
86
this . bottomLine = 4 + fontLineShift ;
82
87
this . setPosition ( StaveModifierPosition . BEGIN ) ;
83
88
this . setTimeSig ( timeSpec ) ;
84
- this . setWidth ( defined ( this . glyph . getMetrics ( ) . width ) ) ;
85
89
this . setPadding ( padding ) ;
86
90
}
87
91
92
+ /**
93
+ * Return TimeSignatureInfo given a string, consisting of line (number),
94
+ * num (boolean: same as TimeSignature.getIsNumeric()), and glyph (a Glyph or
95
+ * TimeSignatureGlyph object).
96
+ */
88
97
parseTimeSpec ( timeSpec : string ) : TimeSignatureInfo {
89
98
if ( timeSpec === 'C' || timeSpec === 'C|' ) {
90
99
const { line, code, point } = TimeSignature . glyphs [ timeSpec ] ;
@@ -108,12 +117,18 @@ export class TimeSignature extends StaveModifier {
108
117
} ;
109
118
}
110
119
111
- makeTimeSignatureGlyph ( topDigits : string , botDigits : string ) : Glyph {
120
+ /**
121
+ * Returns a new TimeSignatureGlyph (a Glyph subclass that knows how to draw both
122
+ * top and bottom digits along with plus signs etc.)
123
+ */
124
+ makeTimeSignatureGlyph ( topDigits : string , botDigits : string ) : TimeSignatureGlyph {
125
+ // note that 'code' is ignored by TimeSignatureGlyph when rendering.
112
126
return new TimeSignatureGlyph ( this , topDigits , botDigits , 'timeSig0' , this . point ) ;
113
127
}
114
128
115
129
/**
116
- * Returns line, num, glyph -- but these can be accessed directly w/ getters and setters.
130
+ * Returns {line, num (=getIsNumeric), glyph} --
131
+ * but these can also be accessed directly w/ getters and setters.
117
132
*/
118
133
getInfo ( ) : TimeSignatureInfo {
119
134
const { line, is_numeric, glyph } = this ;
@@ -128,40 +143,72 @@ export class TimeSignature extends StaveModifier {
128
143
setTimeSig ( timeSpec : string ) : this {
129
144
this . timeSpec = timeSpec ;
130
145
const info = this . parseTimeSpec ( timeSpec ) ;
131
- this . glyph = info . glyph ;
146
+ this . setGlyph ( info . glyph ) ;
132
147
this . is_numeric = info . num ;
133
148
this . line = info . line ;
134
149
return this ;
135
150
}
136
151
152
+ /**
153
+ * Return the timeSpec (such as '4/4' or 'C|' or even '2/4+3/8') of the TimeSignature
154
+ */
137
155
getTimeSpec ( ) : string {
138
156
return this . timeSpec ;
139
157
}
140
158
159
+ /**
160
+ * Return the staff line that the TimeSignature sits on. Generally 0 for numerator/
161
+ * denominator time signatures such as 3/4 and 2 for cut/common.
162
+ */
141
163
getLine ( ) : number {
142
164
return this . line ;
143
165
}
144
166
167
+ /**
168
+ * Set the line number that the TimeSignature sits on. Half-values are acceptable
169
+ * for spaces, etc. Can be altered, for instance, for signatures that sit above the
170
+ * staff in large orchestral scores.
171
+ */
145
172
setLine ( line : number ) {
146
173
this . line = line ;
147
174
}
148
175
176
+ /**
177
+ * Get the Glyph object used to create the time signature. Numeric time signatures
178
+ * such as 3/8 have a composite Glyph stored as a single Glyph object.
179
+ */
149
180
getGlyph ( ) : Glyph {
150
181
return this . glyph ;
151
182
}
152
183
184
+ /**
185
+ * Set the Glyph object used to draw the time signature, and update the width of the
186
+ * TimeSignature to match. The Glyph must define width in its metrics.
187
+ */
153
188
setGlyph ( glyph : Glyph ) {
154
189
this . glyph = glyph ;
190
+ this . setWidth ( defined ( this . glyph . getMetrics ( ) . width ) ) ;
155
191
}
156
192
193
+ /**
194
+ * Return a boolean on whether this TimeSignature is drawn with one or more numbers
195
+ * (such as 4/4) or not (as in cut time).
196
+ */
157
197
getIsNumeric ( ) : boolean {
158
198
return this . is_numeric ;
159
199
}
160
200
201
+ /**
202
+ * Set whether this TimeSignature is drawn with one or more numbers.
203
+ */
161
204
setIsNumeric ( isNumeric : boolean ) {
162
205
this . is_numeric = isNumeric ;
163
206
}
164
207
208
+ /**
209
+ * Draw the time signature on a Stave using its RenderContext. Both setStave
210
+ * and setContext must already be run.
211
+ */
165
212
draw ( ) : void {
166
213
const stave = this . checkStave ( ) ;
167
214
const ctx = stave . checkContext ( ) ;
0 commit comments