@@ -14,7 +14,7 @@ import { defined, RuntimeError } from './util';
14
14
15
15
export interface TimeSignatureInfo {
16
16
glyph : Glyph ;
17
- line ? : number ;
17
+ line : number ;
18
18
num : boolean ;
19
19
}
20
20
@@ -60,13 +60,21 @@ export class TimeSignature extends StaveModifier {
60
60
bottomLine : number ;
61
61
topLine : number ;
62
62
63
- protected info : TimeSignatureInfo ;
63
+ protected line : number = 0 ;
64
+ protected glyph : Glyph ;
65
+ protected is_numeric : boolean = true ;
64
66
protected validate_args : boolean ;
65
67
66
68
constructor ( timeSpec : string = '4/4' , customPadding = 15 , validate_args = true ) {
67
69
super ( ) ;
68
70
this . validate_args = validate_args ;
69
71
72
+ // violates DRY w/ setTimeSig(timeSpec) but needed to convince TypeScript that all is well.
73
+ const info = this . parseTimeSpec ( timeSpec ) ;
74
+ this . glyph = info . glyph ;
75
+ this . is_numeric = info . num ;
76
+ this . line = info . line ;
77
+
70
78
const padding = customPadding ;
71
79
72
80
const musicFont = Tables . currentMusicFont ( ) ;
@@ -75,8 +83,7 @@ export class TimeSignature extends StaveModifier {
75
83
this . topLine = 2 + fontLineShift ;
76
84
this . bottomLine = 4 + fontLineShift ;
77
85
this . setPosition ( StaveModifierPosition . BEGIN ) ;
78
- this . info = this . parseTimeSpec ( timeSpec ) ;
79
- this . setWidth ( defined ( this . info . glyph . getMetrics ( ) . width ) ) ;
86
+ this . setWidth ( defined ( this . glyph . getMetrics ( ) . width ) ) ;
80
87
this . setPadding ( padding ) ;
81
88
}
82
89
@@ -97,6 +104,7 @@ export class TimeSignature extends StaveModifier {
97
104
const parts = timeSpec . split ( '/' ) ;
98
105
99
106
return {
107
+ line : 0 ,
100
108
num : true ,
101
109
glyph : this . makeTimeSignatureGlyph ( parts [ 0 ] ?? '' , parts [ 1 ] ?? '' ) ,
102
110
} ;
@@ -106,26 +114,60 @@ export class TimeSignature extends StaveModifier {
106
114
return new TimeSignatureGlyph ( this , topDigits , botDigits , 'timeSig0' , this . point ) ;
107
115
}
108
116
117
+ /**
118
+ * Returns line, num, glyph -- but these can be accessed directly w/ getters and setters.
119
+ */
109
120
getInfo ( ) : TimeSignatureInfo {
110
- return this . info ;
121
+ const { line, is_numeric, glyph } = this ;
122
+ return { line, num : is_numeric , glyph } ;
111
123
}
112
124
125
+ /**
126
+ * Set a new time signature specification without changing customPadding, etc.
127
+ */
113
128
setTimeSig ( timeSpec : string ) : this {
114
- this . info = this . parseTimeSpec ( timeSpec ) ;
129
+ const info = this . parseTimeSpec ( timeSpec ) ;
130
+ this . glyph = info . glyph ;
131
+ this . is_numeric = info . num ;
132
+ this . line = info . line ;
115
133
return this ;
116
134
}
117
135
136
+ getLine ( ) : number {
137
+ return this . line ;
138
+ }
139
+
140
+ setLine ( line : number ) {
141
+ this . line = line ;
142
+ }
143
+
144
+ getGlyph ( ) : Glyph {
145
+ return this . glyph ;
146
+ }
147
+
148
+ setGlyph ( glyph : Glyph ) {
149
+ this . glyph = glyph ;
150
+ }
151
+
152
+ getIsNumeric ( ) : boolean {
153
+ return this . is_numeric ;
154
+ }
155
+
156
+ setIsNumeric ( isNumeric : boolean ) {
157
+ this . is_numeric = isNumeric ;
158
+ }
159
+
118
160
draw ( ) : void {
119
161
const stave = this . checkStave ( ) ;
120
162
const ctx = stave . checkContext ( ) ;
121
163
this . setRendered ( ) ;
122
164
123
165
this . applyStyle ( ctx ) ;
124
166
ctx . openGroup ( 'timesignature' , this . getAttribute ( 'id' ) ) ;
125
- this . info . glyph . setStave ( stave ) ;
126
- this . info . glyph . setContext ( ctx ) ;
127
- this . placeGlyphOnLine ( this . info . glyph , stave , this . info . line ) ;
128
- this . info . glyph . renderToStave ( this . x ) ;
167
+ this . glyph . setStave ( stave ) ;
168
+ this . glyph . setContext ( ctx ) ;
169
+ this . placeGlyphOnLine ( this . glyph , stave , this . line ) ;
170
+ this . glyph . renderToStave ( this . x ) ;
129
171
ctx . closeGroup ( ) ;
130
172
this . restoreStyle ( ctx ) ;
131
173
}
0 commit comments