UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

50 lines (49 loc) 1.72 kB
import { Fraction } from '../util'; export class Note { config; log; document; noteRender; constructor(config, log, document, noteRender) { this.config = config; this.log = log; this.document = document; this.noteRender = noteRender; } static create(config, log, document, noteRender) { return new Note(config, log, document, noteRender); } /** The name of the element, which can be used as a type discriminant. */ name = 'note'; /** Returns the bounding box of the element. */ rect() { return this.noteRender.rect; } getPitch() { const note = this.document.getNote(this.noteRender.key); return { step: note.pitch.step, octave: note.pitch.octave, accidentalCode: note.accidental?.code ?? null, }; } sharesACurveWith(note) { return this.noteRender.curveIds.some((curveId) => note.noteRender.curveIds.includes(curveId)); } /** Returns the measure beat that this note starts on. */ getStartMeasureBeat() { return Fraction.fromFractionLike(this.document.getVoiceEntry(this.noteRender.key).measureBeat); } /** Returns the number of beats that this note takes. */ getBeatCount() { return Fraction.fromFractionLike(this.document.getVoiceEntry(this.noteRender.key).duration); } /** Returns the system index that this note resides in. */ getSystemIndex() { return this.noteRender.key.systemIndex; } /** Returns the absolute measure index that this note resides in. */ getAbsoluteMeasureIndex() { return this.document.getAbsoluteMeasureIndex(this.noteRender.key); } }