import Vex from "vexflow" ; import { GraphicalNote } from "../GraphicalNote" ; import { Note } from "../../VoiceData/Note" ; import { ClefInstruction } from "../../VoiceData/Instructions/ClefInstruction" ; import { VexFlowConverter } from "./VexFlowConverter" ; import { Pitch } from "../../../Common/DataObjects/Pitch" ; import { Fraction } from "../../../Common/DataObjects/Fraction" ; import { OctaveEnum , OctaveShift } from "../../VoiceData/Expressions/ContinuousExpressions/OctaveShift" ; import { GraphicalVoiceEntry } from "../GraphicalVoiceEntry" ; import { KeyInstruction } from "../../VoiceData/Instructions/KeyInstruction" ; import { EngravingRules } from "../EngravingRules" ; /**
 * The VexFlow version of a [[GraphicalNote]].
 */ export class VexFlowGraphicalNote extends GraphicalNote { constructor ( note , parent , activeClef , octaveShift = OctaveEnum . NONE , rules , graphicalNoteLength = undefined ) { super ( note , parent , rules , graphicalNoteLength ) ; this . clef = activeClef ; this . octaveShift = octaveShift ; if ( note . Pitch ) { const drawPitch = note . isRest ( ) ? note . Pitch : OctaveShift . getPitchFromOctaveShift ( note . Pitch , octaveShift ) ; this . vfpitch = VexFlowConverter . pitch ( drawPitch , note . isRest ( ) , this . clef , this . sourceNote . Notehead ) ; this . vfpitch [ 1 ] = undefined ; } } public octaveShift : OctaveEnum ; public vfpitch : [ string , string , ClefInstruction ] ; public vfnote : [ Vex . Flow . StemmableNote , number ] ; public vfnoteIndex : number ; private clef : ClefInstruction ; param pitch public setAccidental ( pitch ) { const drawPitch = this . drawPitch ( pitch ) ; this . vfpitch = VexFlowConverter . pitch ( drawPitch , this . sourceNote . isRest ( ) , this . clef , this . sourceNote . Notehead ) ; this . DrawnAccidental = drawPitch . Accidental ; } public drawPitch ( pitch ) { return OctaveShift . getPitchFromOctaveShift ( pitch , this . octaveShift ) ; } public Transpose ( keyInstruction , activeClef , halfTones , octaveEnum ) { const tranposedPitch = super . Transpose ( keyInstruction , activeClef , halfTones , octaveEnum ) ; const drawPitch = OctaveShift . getPitchFromOctaveShift ( tranposedPitch , this . octaveShift ) ; this . vfpitch = VexFlowConverter . pitch ( drawPitch , this . sourceNote . isRest ( ) , this . clef , this . sourceNote . Notehead ) ; this . vfpitch [ 1 ] = undefined ; return drawPitch ; } param note param index public setIndex ( note , index ) { this . vfnote = [ note , index ] ; this . vfnoteIndex = index ; } public notehead ( vfNote = undefined ) { let vfnote = vfNote ; if ( ! vfnote ) { vfnote = ( this . vfnote [ 0 ] as any ) ; } const noteheads = vfnote . note_heads ; if ( noteheads && noteheads . length > this . vfnoteIndex && noteheads [ this . vfnoteIndex ] ) { return vfnote . note_heads [ this . vfnoteIndex ] ; } else { return { line : 0 } ; } } /**
     * Gets the clef for this note
     */ public Clef ( ) { return this . clef ; } /**
     * Gets the id of the SVGGElement containing this note, given the SVGRenderer is used.
     * This is for low-level rendering hacks and should be used with caution.
     */ public getSVGId ( ) { if ( ! this . vfnote ) { return undefined ; } return this . vfnote [ 0 ] . getAttribute ( "id" ) ; } /**
     * Gets the SVGGElement containing this note, given the SVGRenderer is used.
     * This is for low-level rendering hacks and should be used with caution.
     */ public getSVGGElement ( ) { if ( ! this . vfnote ) { return undefined ; } return this . vfnote [ 0 ] . getAttribute ( "el" ) ; } /** Gets the SVG path element of the note's stem. */ public getStemSVG ( ) { return document . getElementById ( "vf-" + this . getSVGId ( ) + "-stem" ) ; } /** Gets the SVG path elements of the beams starting on this note. */ public getBeamSVGs ( ) { const beamSVGs = [ ] ; for ( let i = 0 ; ; i ++ ) { const newSVG = document . getElementById ( `vf-${ this . getSVGId ( ) }-beam${ i }` ) ; if ( ! newSVG ) { break ; } beamSVGs . push ( newSVG ) ; } return beamSVGs ; } }