Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed May 12, 2021
1 parent 7cfcd83 commit c10d729
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/clefnote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ClefNote extends Note {
this.type = type;
this.clef_obj = new Clef(type, size, annotation);
this.clef = this.clef_obj.clef;
this.glyph = new Glyph(this.clef.code, this.clef.point ?? 0);
this.glyph = new Glyph(this.clef.code, this.clef.point);
this.setWidth(this.glyph.getMetrics().width);

// Note properties
Expand All @@ -39,7 +39,7 @@ export class ClefNote extends Note {
this.type = type;
this.clef_obj = new Clef(type, size, annotation);
this.clef = this.clef_obj.clef;
this.glyph = new Glyph(this.clef.code, this.clef.point ?? 0);
this.glyph = new Glyph(this.clef.code, this.clef.point);
this.setWidth(this.glyph.getMetrics().width);
return this;
}
Expand Down
9 changes: 9 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import { Vex } from './vex';

export function check<T>(x?: T): T {
if (x === undefined) {
throw new Vex.RERR('undefined');
}
return x;
}

//** TODO: Resolve duplication with Flow */
export const GLYPH_PROPS_VALID_TYPES: Record<string, Record<string, string>> = {
n: { name: 'note' },
Expand Down
4 changes: 2 additions & 2 deletions src/tabslide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class TabSlide extends TabTie {
this.setAttribute('type', 'TabSlide');

if (!direction) {
const first_fret = (notes.first_note as unknown as TabNote).getPositions()[0].fret;
const last_fret = (notes.last_note as unknown as TabNote).getPositions()[0].fret;
const first_fret = ((notes.first_note as unknown) as TabNote).getPositions()[0].fret;
const last_fret = ((notes.last_note as unknown) as TabNote).getPositions()[0].fret;

direction = parseInt(first_fret, 10) > parseInt(last_fret, 10) ? TabSlide.SLIDE_DOWN : TabSlide.SLIDE_UP;
}
Expand Down
7 changes: 4 additions & 3 deletions src/timesigglyph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Vex } from './vex';
import { Glyph, GlyphMetrics } from './glyph';
import { TimeSignature } from './timesignature';
import { check } from './common';

export class TimeSignatureGlyph extends Glyph {
timeSignature: TimeSignature;
Expand Down Expand Up @@ -37,7 +38,7 @@ export class TimeSignatureGlyph extends Glyph {
const botGlyph = new Glyph('timeSig' + num, this.timeSignature.point);

this.botGlyphs.push(botGlyph);
botWidth += botGlyph.getMetrics().width ?? 0;
botWidth += check<number>(botGlyph.getMetrics().width);
}

this.width = Math.max(topWidth, botWidth);
Expand Down Expand Up @@ -68,7 +69,7 @@ export class TimeSignatureGlyph extends Glyph {
start_x + this.x_shift,
this.stave.getYForLine(this.timeSignature.topLine)
);
start_x += glyph.getMetrics().width ?? 0;
start_x += check<number>(glyph.getMetrics().width);
}

start_x = x + this.botStartX;
Expand All @@ -82,7 +83,7 @@ export class TimeSignatureGlyph extends Glyph {
start_x + glyph.getMetrics().x_shift,
this.stave.getYForLine(this.timeSignature.bottomLine)
);
start_x += glyph.getMetrics().width ?? 0;
start_x += check<number>(glyph.getMetrics().width);
}
}
}
3 changes: 2 additions & 1 deletion src/timesignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Vex } from './vex';
import { Glyph } from './glyph';
import { StaveModifier } from './stavemodifier';
import { TimeSignatureGlyph } from './timesigglyph';
import { check } from './common';

export interface TimeSignatureInfo {
glyph: Glyph;
Expand Down Expand Up @@ -73,7 +74,7 @@ export class TimeSignature extends StaveModifier {
this.bottomLine = 4 + fontLineShift;
this.setPosition(StaveModifier.Position.BEGIN);
this.timeSig = this.parseTimeSpec(timeSpec);
this.setWidth(this.timeSig.glyph.getMetrics().width ?? 0);
this.setWidth(check<number>(this.timeSig.glyph.getMetrics().width));
this.setPadding(padding);
}

Expand Down
34 changes: 14 additions & 20 deletions src/vibratobracket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,20 @@ export class VibratoBracket extends Element {
draw(): void {
const ctx = this.checkContext();
this.setRendered();
let y = 0;
let start_x = 0;
let stop_x = 0;
if (this.start) {
y = this.start.checkStave().getYForTopText(this.line);
start_x = this.start.getAbsoluteX();
} else if (this.stop) {
y = this.stop.checkStave().getYForTopText(this.line);
// If start note is not set then vibrato will be drawn
// from the beginning of the stave
start_x = this.stop.checkStave().getTieStartX();
}

if (this.stop) {
stop_x = this.stop.getAbsoluteX() - this.stop.getWidth() - 5;
} else if (this.start) {
// If stop note is not set then vibrato will be drawn
// until the end of the stave
stop_x = this.start.checkStave().getTieEndX() - 10;
}
const y: number =
(this.start && this.start.checkStave().getYForTopText(this.line)) ||
(this.stop && this.stop.checkStave().getYForTopText(this.line)) ||
0;
// If start note is not set then vibrato will be drawn
// from the beginning of the stave
const start_x: number =
(this.start && this.start.getAbsoluteX()) || (this.stop && this.stop.checkStave().getTieStartX()) || 0;
// If stop note is not set then vibrato will be drawn
// until the end of the stave
const stop_x: number =
(this.stop && this.stop.getAbsoluteX() - this.stop.getWidth() - 5) ||
(this.start && this.start.checkStave().getTieEndX() - 10) ||
0;

this.render_options.vibrato_width = stop_x - start_x;

Expand Down

0 comments on commit c10d729

Please sign in to comment.