UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

54 lines (53 loc) 1.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Note = void 0; const util_1 = require("../util"); 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 util_1.Fraction.fromFractionLike(this.document.getVoiceEntry(this.noteRender.key).measureBeat); } /** Returns the number of beats that this note takes. */ getBeatCount() { return util_1.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); } } exports.Note = Note;