Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

point fixed on pedals #1537

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/fonts/common_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,7 @@ export const CommonMetrics = {
},
},

pedalMarking: {
up: {
point: 40,
},
down: {
point: 34,
},
},
pedalMarking: {},

// These are for numeric digits, such as in time signatures
digits: {
Expand Down
17 changes: 9 additions & 8 deletions src/pedalmarking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function L(...args: any[]) {
function drawPedalGlyph(name: string, context: RenderContext, x: number, y: number, point: number): void {
const glyph_data = PedalMarking.GLYPHS[name];
const glyph = new Glyph(glyph_data.code, point, { category: 'pedalMarking' });
glyph.render(context, x + glyph_data.x_shift, y + glyph_data.y_shift);
// Center the middle of the glyph with the middle of the note head (Tables.STAVE_LINE_DISTANCE / 2)
glyph.render(context, x - (glyph.getMetrics().width - Tables.STAVE_LINE_DISTANCE) / 2, y);
}

/**
Expand Down Expand Up @@ -61,16 +62,12 @@ export class PedalMarking extends Element {
protected notes: StaveNote[];

/** Glyph data */
static readonly GLYPHS: Record<string, { code: string; y_shift: number; x_shift: number }> = {
static readonly GLYPHS: Record<string, { code: string }> = {
pedal_depress: {
code: 'keyboardPedalPed',
x_shift: -10,
y_shift: 0,
},
pedal_release: {
code: 'keyboardPedalUp',
x_shift: -2,
y_shift: 3,
},
};

Expand Down Expand Up @@ -188,7 +185,9 @@ export class PedalMarking extends Element {
const prev_is_same = notes[index - 1] === note;

let x_shift = 0;
const point = Tables.currentMusicFont().lookupMetric(`pedalMarking.${is_pedal_depressed ? 'down' : 'up'}.point`);
const point =
Tables.currentMusicFont().lookupMetric(`pedalMarking.${is_pedal_depressed ? 'down' : 'up'}.point`) ??
Tables.NOTATION_FONT_SCALE;

if (is_pedal_depressed) {
// Adjustment for release+depress
Expand Down Expand Up @@ -248,7 +247,9 @@ export class PedalMarking extends Element {
const x = note.getAbsoluteX();
const y = stave.getYForBottomText(this.line + 3);

const point = Tables.currentMusicFont().lookupMetric(`pedalMarking.${is_pedal_depressed ? 'down' : 'up'}.point`);
const point =
Tables.currentMusicFont().lookupMetric(`pedalMarking.${is_pedal_depressed ? 'down' : 'up'}.point`) ??
Tables.NOTATION_FONT_SCALE;

let text_width = 0;
if (is_pedal_depressed) {
Expand Down