Skip to content

Commit

Permalink
Merge pull request 0xfe#1540 from rvilarl/point/tremoloParenthesis
Browse files Browse the repository at this point in the history
point fixed on tremolo and parenthesis
  • Loading branch information
rvilarl authored Apr 5, 2023
2 parents c7d7803 + dd9a7d9 commit adf7520
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
16 changes: 6 additions & 10 deletions src/fonts/common_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,9 @@ export const CommonMetrics = {

parenthesis: {
default: {
point: 39,
width: 7,
},
gracenote: {
point: (39 * 3) / 5,
width: 3,
},
},
Expand Down Expand Up @@ -249,18 +247,16 @@ export const CommonMetrics = {

tremolo: {
default: {
point: 25,
spacing: 5,
offsetYStemUp: -5,
offsetYStemDown: 5,
spacing: 7,
offsetYStemUp: -8,
offsetYStemDown: 8,
offsetXStemUp: 11,
offsetXStemDown: 1,
},
grace: {
point: 18,
spacing: 4,
offsetYStemUp: -5,
offsetYStemDown: 5,
spacing: (7 * 3) / 5,
offsetYStemUp: -(8 * 3) / 5,
offsetYStemDown: (8 * 3) / 5,
offsetXStemUp: 7,
offsetXStemDown: 1,
},
Expand Down
6 changes: 6 additions & 0 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ export abstract class Note extends Tickable {
return x;
}

/** Get point for notes. */
static getPoint(size?: string): number {
// for sizes other than 'default', note is 2/3 of the default value
return size == 'default' ? Tables.NOTATION_FONT_SCALE : (Tables.NOTATION_FONT_SCALE / 5) * 3;
}

/** Get the direction of the stem. */
getStemDirection(): number {
throw new RuntimeError('NoStem', 'No stem attached to this note.');
Expand Down
6 changes: 3 additions & 3 deletions src/parenthesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ export class Parenthesis extends Modifier {

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

this.point = Tables.currentMusicFont().lookupMetric('parenthesis.default.point');
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.default.point') ?? Note.getPoint('default');
this.setWidth(Tables.currentMusicFont().lookupMetric('parenthesis.default.width'));
}

/** Set the associated note. */
setNote(note: Note): this {
this.note = note;
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.default.point');
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.default.point') ?? Note.getPoint('default');
this.setWidth(Tables.currentMusicFont().lookupMetric('parenthesis.default.width'));
if (isGraceNote(note)) {
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.gracenote.point');
this.point = Tables.currentMusicFont().lookupMetric('parenthesis.gracenote.point') ?? Note.getPoint('gracenote');
this.setWidth(Tables.currentMusicFont().lookupMetric('parenthesis.gracenote.width'));
}
return this;
Expand Down
3 changes: 2 additions & 1 deletion src/tremolo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Glyph } from './glyph';
import { GraceNote } from './gracenote';
import { Modifier } from './modifier';
import { Note } from './note';
import { Stem } from './stem';
import { Tables } from './tables';
import { Category, isGraceNote } from './typeguard';
Expand Down Expand Up @@ -64,7 +65,7 @@ export class Tremolo extends Modifier {
y += musicFont.lookupMetric(`${category}.offsetYStemUp`) * scale;
}

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

x += musicFont.lookupMetric(`${category}.offsetXStem${stemDirection === Stem.UP ? 'Up' : 'Down'}`);
for (let i = 0; i < this.num; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions tests/percussion_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ const snare2 = createSingleMeasureTest((f) => {
f.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(1), 0),
f.GraceNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(1), 0),
f.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(3), 0),
f.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(5), 0),
f.StaveNote({ keys: ['c/5'], duration: '4', stem_direction: -1 }).addModifier(new Tremolo(4), 0),
]);
});

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

Expand Down

0 comments on commit adf7520

Please sign in to comment.