Skip to content

Commit

Permalink
Merge pull request #1532 from rvilarl/fix/1527
Browse files Browse the repository at this point in the history
point fixed on time signatures and clefs
  • Loading branch information
rvilarl authored Mar 18, 2023
2 parents f5af0b9 + 16c7d8f commit 577939d
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/accidental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export class Accidental extends Modifier {

this.render_options = {
// Font size for glyphs
font_scale: 38,
font_scale: Tables.NOTATION_FONT_SCALE,

// Padding between accidental and parentheses on each side
parenLeftPadding: 2,
Expand Down
2 changes: 1 addition & 1 deletion src/articulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class Articulation extends Modifier {
this.type = type;
this.position = ABOVE;
this.render_options = {
font_scale: 38,
font_scale: Tables.NOTATION_FONT_SCALE,
};

this.reset();
Expand Down
28 changes: 10 additions & 18 deletions src/clef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import { Category } from './typeguard';
import { defined, log } from './util';

export interface ClefType {
point: number;
code: string;
line: number;
}

export interface ClefAnnotatiomType extends ClefType {
x_shift: number;
code: string;
line: number;
point: number;
}

export interface ClefMetrics {
Expand Down Expand Up @@ -70,62 +68,50 @@ export class Clef extends StaveModifier {
treble: {
code: 'gClef',
line: 3,
point: 0,
},
bass: {
code: 'fClef',
line: 1,
point: 0,
},
alto: {
code: 'cClef',
line: 2,
point: 0,
},
tenor: {
code: 'cClef',
line: 1,
point: 0,
},
percussion: {
code: 'unpitchedPercussionClef1',
line: 2,
point: 0,
},
soprano: {
code: 'cClef',
line: 4,
point: 0,
},
'mezzo-soprano': {
code: 'cClef',
line: 3,
point: 0,
},
'baritone-c': {
code: 'cClef',
line: 0,
point: 0,
},
'baritone-f': {
code: 'fClef',
line: 2,
point: 0,
},
subbass: {
code: 'fClef',
line: 0,
point: 0,
},
french: {
code: 'gClef',
line: 4,
point: 0,
},
tab: {
code: '6stringTabClef',
line: 3,
point: 0,
line: 2.5,
},
};
}
Expand All @@ -143,7 +129,7 @@ export class Clef extends StaveModifier {

this.setPosition(StaveModifierPosition.BEGIN);
this.setType(type, size, annotation);
this.setWidth(Glyph.getWidth(this.clef.code, this.clef.point, `clef_${this.size}`));
this.setWidth(Glyph.getWidth(this.clef.code, Clef.getPoint(this.size), `clef_${this.size}`));
L('Creating clef:', type);
}

Expand Down Expand Up @@ -186,6 +172,12 @@ export class Clef extends StaveModifier {
return this.width;
}

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

/** Set associated stave. */
setStave(stave: Stave): this {
this.stave = stave;
Expand All @@ -200,7 +192,7 @@ export class Clef extends StaveModifier {

this.applyStyle(ctx);
ctx.openGroup('clef', this.getAttribute('id'));
Glyph.renderGlyph(ctx, this.x, stave.getYForLine(this.clef.line), this.clef.point, this.clef.code, {
Glyph.renderGlyph(ctx, this.x, stave.getYForLine(this.clef.line), Clef.getPoint(this.size), this.clef.code, {
category: `clef_${this.size}`,
});
if (this.annotation !== undefined && this.attachment !== undefined) {
Expand Down
7 changes: 4 additions & 3 deletions src/clefnote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Clef, ClefAnnotatiomType, ClefType } from './clef';
import { Glyph } from './glyph';
import { Note } from './note';
import { Tables } from './tables';
import { Category } from './typeguard';

/** ClefNote implements clef annotations in measures. */
Expand All @@ -25,7 +26,7 @@ export class ClefNote extends Note {
this.clef = clef.clef;
this.annotation = clef.annotation;
this.size = size === undefined ? 'default' : size;
this.setWidth(Glyph.getWidth(this.clef.code, this.clef.point, `clefNote_${this.size}`));
this.setWidth(Glyph.getWidth(this.clef.code, Clef.getPoint(this.size), `clefNote_${this.size}`));

// Note properties
this.ignore_ticks = true;
Expand All @@ -38,7 +39,7 @@ export class ClefNote extends Note {
const clef = new Clef(type, size, annotation);
this.clef = clef.clef;
this.annotation = clef.annotation;
this.setWidth(Glyph.getWidth(this.clef.code, this.clef.point, `clefNote_${this.size}`));
this.setWidth(Glyph.getWidth(this.clef.code, Clef.getPoint(this.size), `clefNote_${this.size}`));
return this;
}

Expand All @@ -60,7 +61,7 @@ export class ClefNote extends Note {
this.setRendered();
const abs_x = this.getAbsoluteX();

Glyph.renderGlyph(ctx, abs_x, stave.getYForLine(this.clef.line), this.clef.point, this.clef.code, {
Glyph.renderGlyph(ctx, abs_x, stave.getYForLine(this.clef.line), Clef.getPoint(this.size), this.clef.code, {
category: `clefNote_${this.size}`,
});

Expand Down
32 changes: 7 additions & 25 deletions src/fonts/common_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ export const CommonMetrics = {
'8va': {
point: 18,
treble: {
line: -1.4,
line: -2,
shiftX: 12,
},
},
'8vb': {
point: 18,
treble: {
line: 6,
line: 6.5,
shiftX: 10,
},
bass: {
line: 3.5,
line: 4,
shiftX: 1,
},
},
Expand Down Expand Up @@ -239,7 +239,7 @@ export const CommonMetrics = {
digits: {
// used by TimeSignature objects
shiftLine: -1,
point: 34,
point: 39,

// used by tuplets
tupletPoint: 22,
Expand Down Expand Up @@ -374,32 +374,14 @@ export const CommonMetrics = {
shiftX: -1,
},
},
clef_default: {
point: 32,
gClef: {
scale: 1.1,
shiftY: 1,
},
fClef: {
shiftY: -0.5,
},
'6stringTabClef': {
point: 32,
shiftY: -5.5,
},
},
clef_default: {},
clef_small: {
point: 26,
gClef: {
shiftY: 1.5,
},
},
clefNote_default: {
point: 32,
},
clefNote_small: {
point: 26,
},
clefNote_default: {},
clefNote_small: {},
ornament: {
ornamentTurn: {
scale: 1.2,
Expand Down
1 change: 0 additions & 1 deletion src/fonts/gonville_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ export const GonvilleMetrics = {
point: 40,
'6stringTabClef': {
point: 40,
shiftY: -5.5,
},
},
clef_small: {
Expand Down
2 changes: 1 addition & 1 deletion src/keysignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class KeySignature extends StaveModifier {

this.setKeySig(keySpec, cancelKeySpec, alterKeySpec);
this.setPosition(StaveModifierPosition.BEGIN);
this.glyphFontScale = 38; // TODO(0xFE): Should this match StaveNote?
this.glyphFontScale = Tables.NOTATION_FONT_SCALE;
this.glyphs = [];
this.xPositions = []; // relative to this.x
this.paddingForced = false;
Expand Down
2 changes: 1 addition & 1 deletion src/ornament.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class Ornament extends Modifier {
this.delayed = false;

this.render_options = {
font_scale: 38,
font_scale: Tables.NOTATION_FONT_SCALE,
accidentalLowerPadding: 3,
accidentalUpperPadding: 3,
};
Expand Down
4 changes: 1 addition & 3 deletions src/stavetempo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ export class StaveTempo extends StaveModifier {
this.setRendered();

const options = this.render_options;
// FIXME: What does the '38' mean? Why 38? Is that supposed to
// be the default font size for standard notation?
const scale = options.glyph_font_scale / 38;
const scale = options.glyph_font_scale / Tables.NOTATION_FONT_SCALE;
const name = this.tempo.name;
const duration = this.tempo.duration;
const dots = this.tempo.dots || 0;
Expand Down
3 changes: 2 additions & 1 deletion src/strokes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Glyph } from './glyph';
import { Modifier } from './modifier';
import { ModifierContextState } from './modifiercontext';
import { Note } from './note';
import { Tables } from './tables';
import { Category, isNote, isStaveNote, isTabNote } from './typeguard';
import { RuntimeError } from './util';

Expand Down Expand Up @@ -92,7 +93,7 @@ export class Stroke extends Modifier {
this.position = Modifier.Position.LEFT;

this.render_options = {
font_scale: 38,
font_scale: Tables.NOTATION_FONT_SCALE,
};

this.resetFont();
Expand Down
2 changes: 1 addition & 1 deletion src/timesigglyph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class TimeSignatureGlyph extends Glyph {

// If the height of the digits is more than two staff spaces (20), shift to the next line
// in order to center the digits on lines 1 and 5 rather than 2 and 4.
this.lineShift = height > 20 ? 1 : 0;
this.lineShift = height > 22 ? 1 : 0;

this.width = Math.max(topWidth, botWidth);
this.xMin = this.getMetrics().x_min;
Expand Down
10 changes: 4 additions & 6 deletions src/timesignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ export class TimeSignature extends StaveModifier {
return Category.TimeSignature;
}

static get glyphs(): Record<string, { code: string; point: number; line: number }> {
static get glyphs(): Record<string, { code: string; line: number }> {
return {
C: {
code: 'timeSigCommon',
point: 40,
line: 2,
},
'C|': {
code: 'timeSigCutCommon',
point: 40,
line: 2,
},
};
Expand All @@ -79,7 +77,7 @@ export class TimeSignature extends StaveModifier {

// point must be defined before parsing spec.
const musicFont = Tables.currentMusicFont();
this.point = musicFont.lookupMetric('digits.point');
this.point = musicFont.lookupMetric('digits.point') || Tables.NOTATION_FONT_SCALE;

const fontLineShift = musicFont.lookupMetric('digits.shiftLine', 0);
this.topLine = 2 + fontLineShift;
Expand All @@ -96,11 +94,11 @@ export class TimeSignature extends StaveModifier {
*/
parseTimeSpec(timeSpec: string): TimeSignatureInfo {
if (timeSpec === 'C' || timeSpec === 'C|') {
const { line, code, point } = TimeSignature.glyphs[timeSpec];
const { line, code } = TimeSignature.glyphs[timeSpec];
return {
line,
num: false,
glyph: new Glyph(code, point),
glyph: new Glyph(code, Tables.NOTATION_FONT_SCALE),
};
}

Expand Down

0 comments on commit 577939d

Please sign in to comment.