Skip to content

Commit d8f9ce9

Browse files
committed
fix tests
1 parent e8ecc06 commit d8f9ce9

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/timesignature.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class TimeSignature extends StaveModifier {
6060
bottomLine: number;
6161
topLine: number;
6262

63+
protected timeSpec: string = '4/4';
6364
protected line: number = 0;
6465
protected glyph: Glyph;
6566
protected is_numeric: boolean = true;
@@ -68,21 +69,25 @@ export class TimeSignature extends StaveModifier {
6869
constructor(timeSpec: string = '4/4', customPadding = 15, validate_args = true) {
6970
super();
7071
this.validate_args = validate_args;
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;
72+
this.timeSpec = timeSpec;
7773

7874
const padding = customPadding;
7975

76+
// point must be defined before parsing spec.
8077
const musicFont = Tables.currentMusicFont();
8178
this.point = musicFont.lookupMetric('digits.point');
79+
8280
const fontLineShift = musicFont.lookupMetric('digits.shiftLine', 0);
8381
this.topLine = 2 + fontLineShift;
8482
this.bottomLine = 4 + fontLineShift;
8583
this.setPosition(StaveModifierPosition.BEGIN);
84+
85+
// violates DRY w/ setTimeSig(timeSpec) but needed to convince TypeScript that all is well.
86+
const info = this.parseTimeSpec(timeSpec);
87+
this.glyph = info.glyph;
88+
this.is_numeric = info.num;
89+
this.line = info.line;
90+
8691
this.setWidth(defined(this.glyph.getMetrics().width));
8792
this.setPadding(padding);
8893
}
@@ -124,15 +129,22 @@ export class TimeSignature extends StaveModifier {
124129

125130
/**
126131
* Set a new time signature specification without changing customPadding, etc.
132+
*
133+
* The getter for this is `getTimeSpec` not `getTimeSig`.
127134
*/
128135
setTimeSig(timeSpec: string): this {
136+
this.timeSpec = timeSpec;
129137
const info = this.parseTimeSpec(timeSpec);
130138
this.glyph = info.glyph;
131139
this.is_numeric = info.num;
132140
this.line = info.line;
133141
return this;
134142
}
135143

144+
getTimeSpec(): string {
145+
return this.timeSpec;
146+
}
147+
136148
getLine(): number {
137149
return this.line;
138150
}

tests/timesignature_tests.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const TimeSignatureTests = {
2929

3030
function parser(): void {
3131
const timeSig = new TimeSignature();
32+
equal(timeSig.getTimeSpec(), '4/4', 'default time signature is 4/4');
3233

3334
const mustFail = ['asdf', '123/', '/10', '/', '4567', 'C+', '1+', '+1', '(3+', '+3)', '()', '(+)'];
3435
mustFail.forEach((invalidString) => {
@@ -38,10 +39,11 @@ function parser(): void {
3839
const mustPass = ['4/4', '10/12', '1/8', '1234567890/1234567890', 'C', 'C|', '+'];
3940
mustPass.forEach((validString) => timeSig.parseTimeSpec(validString));
4041

41-
timeSig.parseTimeSpec('4/4');
42+
timeSig.setTimeSig('4/4');
4243
equal(timeSig.getIsNumeric(), true, '4/4 is numeric');
4344
equal(timeSig.getLine(), 0, 'digits are on line 0');
44-
timeSig.parseTimeSpec('C|');
45+
timeSig.setTimeSig('C|');
46+
equal(timeSig.getTimeSpec(), 'C|', 'timeSpec changed to C|');
4547
equal(timeSig.getIsNumeric(), false, 'cut time is not numeric');
4648
equal(timeSig.getLine(), 2, 'cut/common are on line 2');
4749

0 commit comments

Comments
 (0)