Skip to content

Commit adf7520

Browse files
authored
Merge pull request #1540 from rvilarl/point/tremoloParenthesis
point fixed on tremolo and parenthesis
2 parents c7d7803 + dd9a7d9 commit adf7520

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

src/fonts/common_metrics.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,9 @@ export const CommonMetrics = {
217217

218218
parenthesis: {
219219
default: {
220-
point: 39,
221220
width: 7,
222221
},
223222
gracenote: {
224-
point: (39 * 3) / 5,
225223
width: 3,
226224
},
227225
},
@@ -249,18 +247,16 @@ export const CommonMetrics = {
249247

250248
tremolo: {
251249
default: {
252-
point: 25,
253-
spacing: 5,
254-
offsetYStemUp: -5,
255-
offsetYStemDown: 5,
250+
spacing: 7,
251+
offsetYStemUp: -8,
252+
offsetYStemDown: 8,
256253
offsetXStemUp: 11,
257254
offsetXStemDown: 1,
258255
},
259256
grace: {
260-
point: 18,
261-
spacing: 4,
262-
offsetYStemUp: -5,
263-
offsetYStemDown: 5,
257+
spacing: (7 * 3) / 5,
258+
offsetYStemUp: -(8 * 3) / 5,
259+
offsetYStemDown: (8 * 3) / 5,
264260
offsetXStemUp: 7,
265261
offsetXStemDown: 1,
266262
},

src/note.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,12 @@ export abstract class Note extends Tickable {
636636
return x;
637637
}
638638

639+
/** Get point for notes. */
640+
static getPoint(size?: string): number {
641+
// for sizes other than 'default', note is 2/3 of the default value
642+
return size == 'default' ? Tables.NOTATION_FONT_SCALE : (Tables.NOTATION_FONT_SCALE / 5) * 3;
643+
}
644+
639645
/** Get the direction of the stem. */
640646
getStemDirection(): number {
641647
throw new RuntimeError('NoStem', 'No stem attached to this note.');

src/parenthesis.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ export class Parenthesis extends Modifier {
6868

6969
this.position = position ?? Modifier.Position.LEFT;
7070

71-
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.default.point');
71+
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.default.point') ?? Note.getPoint('default');
7272
this.setWidth(Tables.currentMusicFont().lookupMetric('parenthesis.default.width'));
7373
}
7474

7575
/** Set the associated note. */
7676
setNote(note: Note): this {
7777
this.note = note;
78-
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.default.point');
78+
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.default.point') ?? Note.getPoint('default');
7979
this.setWidth(Tables.currentMusicFont().lookupMetric('parenthesis.default.width'));
8080
if (isGraceNote(note)) {
81-
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.gracenote.point');
81+
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.gracenote.point') ?? Note.getPoint('gracenote');
8282
this.setWidth(Tables.currentMusicFont().lookupMetric('parenthesis.gracenote.width'));
8383
}
8484
return this;

src/tremolo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { Glyph } from './glyph';
66
import { GraceNote } from './gracenote';
77
import { Modifier } from './modifier';
8+
import { Note } from './note';
89
import { Stem } from './stem';
910
import { Tables } from './tables';
1011
import { Category, isGraceNote } from './typeguard';
@@ -64,7 +65,7 @@ export class Tremolo extends Modifier {
6465
y += musicFont.lookupMetric(`${category}.offsetYStemUp`) * scale;
6566
}
6667

67-
const fontScale = musicFont.lookupMetric(`${category}.point`);
68+
const fontScale = musicFont.lookupMetric(`${category}.point`) ?? Note.getPoint(gn ? 'grace' : 'default');
6869

6970
x += musicFont.lookupMetric(`${category}.offsetXStem${stemDirection === Stem.UP ? 'Up' : 'Down'}`);
7071
for (let i = 0; i < this.num; ++i) {

tests/percussion_tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ const snare2 = createSingleMeasureTest((f) => {
218218
f.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(1), 0),
219219
f.GraceNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(1), 0),
220220
f.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(3), 0),
221-
f.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(5), 0),
221+
f.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(4), 0),
222222
]);
223223
});
224224

@@ -229,7 +229,7 @@ const snare3 = createSingleMeasureTest((factory) => {
229229
factory.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: 1 }).addModifier(new Tremolo(2), 0),
230230
factory.GraceNote({ keys: ['c/5'], duration: '4', stem_direction: 1 }).addModifier(new Tremolo(2), 0),
231231
factory.GraceNote({ keys: ['c/5'], duration: '4', stem_direction: 1 }).addModifier(new Tremolo(3), 0),
232-
factory.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: 1 }).addModifier(new Tremolo(5), 0),
232+
factory.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: 1 }).addModifier(new Tremolo(4), 0),
233233
]);
234234
});
235235

0 commit comments

Comments
 (0)