import Vex from "vexflow" ; import { GraphicalObject } from "../GraphicalObject" ; import { VexFlowStaffLine } from "./VexFlowStaffLine" ; import { BoundingBox } from "../BoundingBox" ; import { VexFlowMeasure } from "./VexFlowMeasure" ; import { unitInPixels } from "./VexFlowMusicSheetDrawer" ; /**
 * Class that defines a instrument bracket at the beginning of a line.
 */ export class VexFlowInstrumentBracket extends GraphicalObject { public vexflowConnector : Vex . Flow . StaveConnector ; public Visible : boolean = true ; constructor ( firstVexFlowStaffLine , lastVexFlowStaffLine , depth = 0 ) { super ( ) ; this . PositionAndShape = new BoundingBox ( this , firstVexFlowStaffLine . ParentMusicSystem . PositionAndShape ) ; const firstVexMeasure = firstVexFlowStaffLine . Measures [ 0 ] as VexFlowMeasure ; const lastVexMeasure = lastVexFlowStaffLine . Measures [ 0 ] as VexFlowMeasure ; this . addConnector ( firstVexMeasure . getVFStave ( ) , lastVexMeasure . getVFStave ( ) , Vex . Flow . StaveConnector . type . BRACKET , depth ) ; } param ctx public draw ( ctx ) { if ( this . Visible ) { this . vexflowConnector . setContext ( ctx ) . draw ( ) ; } const con = this . vexflowConnector ; const topY = con . top_stave . getYForLine ( 0 ) ; const botY = con . bottom_stave . getYForLine ( con . bottom_stave . getNumLines ( ) - 1 ) + con . thickness ; this . PositionAndShape . AbsolutePosition . x = ( con . top_stave . getX ( ) - 2 + con . x_shift ) / unitInPixels ; this . PositionAndShape . AbsolutePosition . y = topY / unitInPixels ; this . PositionAndShape . Size . height = ( botY - topY ) / unitInPixels ; this . PositionAndShape . Size . width = 12 / unitInPixels ; } param { Stave } stave1 param { Stave } stave2 param { Flow . StaveConnector . type } type private addConnector ( stave1 , stave2 , type , depth ) { this . vexflowConnector = new Vex . Flow . StaveConnector ( stave1 , stave2 ) . setType ( type ) . setXShift ( depth * - 5 ) ; } }