-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
144 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Glyph, GlyphMetrics } from './glyph'; | ||
import { TimeSignature } from './timesignature'; | ||
|
||
export class TimeSignatureGlyph extends Glyph { | ||
timeSignature: TimeSignature; | ||
topStartX: number; | ||
botStartX: number; | ||
width: number; | ||
xMin: number; | ||
|
||
constructor( | ||
timeSignature: TimeSignature, | ||
topDigits: string[], | ||
botDigits: string[], | ||
code: string, | ||
point: number, | ||
options?: { category: string } | ||
) { | ||
super(code, point, options); | ||
this.timeSignature = timeSignature; | ||
this.topGlyphs = []; | ||
this.botGlyphs = []; | ||
|
||
let topWidth = 0; | ||
for (let i = 0; i < topDigits.length; ++i) { | ||
const num = topDigits[i]; | ||
const topGlyph = new Glyph('timeSig' + num, this.timeSignature.point!); | ||
|
||
this.topGlyphs.push(topGlyph); | ||
topWidth += topGlyph.getMetrics().width!; | ||
} | ||
|
||
let botWidth = 0; | ||
for (let i = 0; i < botDigits.length; ++i) { | ||
const num = botDigits[i]; | ||
const botGlyph = new Glyph('timeSig' + num, this.timeSignature.point!); | ||
|
||
this.botGlyphs.push(botGlyph); | ||
botWidth += botGlyph.getMetrics().width!; | ||
} | ||
|
||
this.width = topWidth > botWidth ? topWidth : botWidth; | ||
this.xMin = this.getMetrics().x_min; | ||
this.topStartX = (this.width - topWidth) / 2.0; | ||
this.botStartX = (this.width - botWidth) / 2.0; | ||
this.reset(); | ||
} | ||
|
||
getMetrics(): GlyphMetrics { | ||
return { | ||
x_min: this.xMin, | ||
x_max: this.xMin + this.width, | ||
width: this.width, | ||
} as GlyphMetrics; | ||
} | ||
|
||
renderToStave(x: number): void { | ||
let start_x = x + this.topStartX; | ||
for (let i = 0; i < this.topGlyphs.length; ++i) { | ||
const glyph = this.topGlyphs[i]; | ||
Glyph.renderOutline( | ||
this.checkContext(), | ||
glyph.getMetrics().outline, | ||
this.scale, | ||
start_x + this.x_shift, | ||
this.stave!.getYForLine(this.timeSignature.topLine!) | ||
); | ||
start_x += glyph.getMetrics().width!; | ||
} | ||
|
||
start_x = x + this.botStartX; | ||
for (let i = 0; i < this.botGlyphs.length; ++i) { | ||
const glyph = this.botGlyphs[i]; | ||
this.timeSignature.placeGlyphOnLine(glyph, this.stave!, 0); | ||
Glyph.renderOutline( | ||
this.checkContext(), | ||
glyph.getMetrics().outline, | ||
this.scale, | ||
start_x + glyph.getMetrics().x_shift, | ||
this.stave!.getYForLine(this.timeSignature.bottomLine!) | ||
); | ||
start_x += glyph.getMetrics().width!; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,46 @@ | ||
// [VexFlow](http://vexflow.com) - Copyright (c) Mohit Muthanna 2010. | ||
// Author Taehoon Moon 2014 | ||
|
||
import { Vex } from './vex'; | ||
import { Note } from './note'; | ||
import { TimeSignature } from './timesignature'; | ||
import { TimeSignature, TimeSignatureInfo } from './timesignature'; | ||
|
||
export class TimeSigNote extends Note { | ||
constructor(timeSpec, customPadding) { | ||
protected timeSig: TimeSignatureInfo; | ||
|
||
constructor(timeSpec: string, customPadding?: number) { | ||
super({ duration: 'b' }); | ||
this.setAttribute('type', 'TimeSigNote'); | ||
|
||
const timeSignature = new TimeSignature(timeSpec, customPadding); | ||
this.timeSig = timeSignature.getTimeSig(); | ||
this.setWidth(this.timeSig.glyph.getMetrics().width); | ||
this.setWidth(this.timeSig.glyph.getMetrics().width!); | ||
|
||
// Note properties | ||
this.ignore_ticks = true; | ||
} | ||
|
||
getBoundingBox() { | ||
return super.getBoundingBox(); | ||
} | ||
|
||
addToModifierContext() { | ||
addToModifierContext(): this { | ||
/* overridden to ignore */ | ||
return this; | ||
} | ||
|
||
preFormat() { | ||
preFormat(): this { | ||
this.setPreFormatted(true); | ||
return this; | ||
} | ||
|
||
draw() { | ||
this.stave.checkContext(); | ||
draw(): void { | ||
if (!this.stave) throw new Vex.RERR('NoStave', 'No stave attached to this note.'); | ||
const ctx = this.checkContext(); | ||
this.setRendered(); | ||
|
||
if (!this.timeSig.glyph.getContext()) { | ||
this.timeSig.glyph.setContext(this.context); | ||
this.timeSig.glyph.setContext(ctx); | ||
} | ||
|
||
this.timeSig.glyph.setStave(this.stave); | ||
this.timeSig.glyph.setYShift(this.stave.getYForLine(this.timeSig.line) - this.stave.getYForGlyphs()); | ||
this.timeSig.glyph.setYShift(this.stave.getYForLine(this.timeSig.line!) - this.stave.getYForGlyphs()); | ||
this.timeSig.glyph.renderToStave(this.getAbsoluteX()); | ||
} | ||
} |