draw() {
    this.checkContext();
    this.setRendered();

    if (!this.formatted) this.format();

    const num_lines = this.options.num_lines;
    const width = this.width;
    const x = this.x;
    let y;

    // Render lines
    for (let line = 0; line < num_lines; line++) {
      y = this.getYForLine(line);

      this.applyStyle();
      if (this.options.line_config[line].visible) {
        this.context.beginPath();
        this.context.moveTo(x, y);
        this.context.lineTo(x + width, y);
        this.context.stroke();
      }
      this.restoreStyle();
    }

    // Draw the modifiers (bar lines, coda, segno, repeat brackets, etc.)
    for (let i = 0; i < this.modifiers.length; i++) {
      // Only draw modifier if it has a draw function
      if (typeof this.modifiers[i].draw === 'function') {
        this.modifiers[i].applyStyle(this.context);
        this.modifiers[i].draw(this, this.getModifierXShift(i));
        this.modifiers[i].restoreStyle(this.context);
      }
    }

    // Render measure numbers
    if (this.measure > 0) {
      this.context.save();
      this.context.setFont(this.font.family, this.font.size, this.font.weight);
      const text_width = this.context.measureText('' + this.measure).width;
      y = this.getYForTopText(0) + 3;
      this.context.fillText('' + this.measure, this.x - text_width / 2, y);
      this.context.restore();
    }

    return this;
  }
/**
   * All drawing functions below need the context to be set.
   */
All drawing functions below need the context to be set.
All drawing functions below need the context to be set .
draw() {
    this.checkContext();
    this.setRendered();
    if (!this.formatted) this.format();
    const num_lines = this.options.num_lines;
    const width = this.width;
    const x = this.x;
    let y;
    for (let line = 0; line < num_lines; line++) {
      y = this.getYForLine(line);
      this.applyStyle();
      if (this.options.line_config[line].visible) {
        this.context.beginPath();
        this.context.moveTo(x, y);
        this.context.lineTo(x + width, y);
        this.context.stroke();
      }
      this.restoreStyle();
    }
    for (let i = 0; i < this.modifiers.length; i++) {
      if (typeof this.modifiers[i].draw === 'function') {
        this.modifiers[i].applyStyle(this.context);
        this.modifiers[i].draw(this, this.getModifierXShift(i));
        this.modifiers[i].restoreStyle(this.context);
      }
    }
    if (this.measure > 0) {
      this.context.save();
      this.context.setFont(this.font.family, this.font.size, this.font.weight);
      const text_width = this.context.measureText('' + this.measure).width;
      y = this.getYForTopText(0) + 3;
      this.context.fillText('' + this.measure, this.x - text_width / 2, y);
      this.context.restore();
    }
    return this;
  }
draw ( ) { this . checkContext ( ) ; this . setRendered ( ) ; if ( ! this . formatted ) this . format ( ) ; const num_lines = this . options . num_lines ; const width = this . width ; const x = this . x ; let y ; for ( let line = 0 ; line < num_lines ; line ++ ) { y = this . getYForLine ( line ) ; this . applyStyle ( ) ; if ( this . options . line_config [ line ] . visible ) { this . context . beginPath ( ) ; this . context . moveTo ( x , y ) ; this . context . lineTo ( x + width , y ) ; this . context . stroke ( ) ; } this . restoreStyle ( ) ; } for ( let i = 0 ; i < this . modifiers . length ; i ++ ) { if ( typeof this . modifiers [ i ] . draw === 'function' ) { this . modifiers [ i ] . applyStyle ( this . context ) ; this . modifiers [ i ] . draw ( this , this . getModifierXShift ( i ) ) ; this . modifiers [ i ] . restoreStyle ( this . context ) ; } } if ( this . measure > 0 ) { this . context . save ( ) ; this . context . setFont ( this . font . family , this . font . size , this . font . weight ) ; const text_width = this . context . measureText ( '' + this . measure ) . width ; y = this . getYForTopText ( 0 ) + 3 ; this . context . fillText ( '' + this . measure , this . x - text_width / 2 , y ) ; this . context . restore ( ) ; } return this ; }
All drawing functions below need the context to be set.
All drawing functions below need the context to be set .
// Render lines // Draw the modifiers (bar lines, coda, segno, repeat brackets, etc.) // Only draw modifier if it has a draw function // Render measure numbers