calculateFlatSlope() {
    const {
      notes, stem_direction,
      render_options: { beam_width, min_flat_beam_offset, flat_beam_offset },
    } = this;

    // If a flat beam offset has not yet been supplied or calculated,
    // generate one based on the notes in this particular note group
    let total = 0;
    let extremeY = 0;  // Store the highest or lowest note here
    let extremeBeamCount = 0;  // The beam count of the extreme note
    let currentExtreme = 0;
    for (let i = 0; i < notes.length; i++) {
      // Total up all of the offsets so we can average them out later
      const note = notes[i];
      const stemTipY = note.getStemExtents().topY;
      total += stemTipY;

      // Store the highest (stems-up) or lowest (stems-down) note so the
      //  offset can be adjusted in case the average isn't enough
      if (stem_direction === Stem.DOWN && currentExtreme < stemTipY) {
        currentExtreme = stemTipY;
        extremeY = Math.max(...note.getYs());
        extremeBeamCount = note.getBeamCount();
      } else if (
        stem_direction === Stem.UP && (currentExtreme === 0 || currentExtreme > stemTipY)
      ) {
        currentExtreme = stemTipY;
        extremeY = Math.min(...note.getYs());
        extremeBeamCount = note.getBeamCount();
      }
    }

    // Average the offsets to try and come up with a reasonable one that
    //  works for all of the notes in the beam group.
    let offset = total / notes.length;

    // In case the average isn't long enough, add or subtract some more
    //  based on the highest or lowest note (again, based on the stem
    //  direction). This also takes into account the added height due to
    //  the width of the beams.
    const beamWidth = beam_width * 1.5;
    const extremeTest = min_flat_beam_offset + (extremeBeamCount * beamWidth);
    const newOffset = extremeY + (extremeTest * -stem_direction);
    if (stem_direction === Stem.DOWN && offset < newOffset) {
      offset = extremeY + extremeTest;
    } else if (stem_direction === Stem.UP && offset > newOffset) {
      offset = extremeY - extremeTest;
    }

    if (!(flat_beam_offset + this.render_options.flat_beam_offset_per_beam > 0)) {
      // Set the offset for the group based on the calculations above.
      this.render_options.flat_beam_offset = offset;
    } else if (stem_direction === Stem.DOWN && offset > flat_beam_offset && !this.render_options.flat_beams) {
       this.render_options.flat_beam_offset = offset;
    } else if (stem_direction === Stem.UP && offset < flat_beam_offset && !this.render_options.flat_beams) {
       this.render_options.flat_beam_offset = offset;
    }

    // for flat beams, the slope and y_shift are simply 0
    this.slope = 0;
    this.y_shift = 0;
  }
// Calculate a slope and y-shift for flat beams
Calculate a slope and y-shift for flat beams
Calculate a slope and y - shift for flat beams
calculateFlatSlope() {
    const {
      notes, stem_direction,
      render_options: { beam_width, min_flat_beam_offset, flat_beam_offset },
    } = this;
    let total = 0;
    let extremeY = 0;  
    let extremeBeamCount = 0;  
    let currentExtreme = 0;
    for (let i = 0; i < notes.length; i++) {
      const note = notes[i];
      const stemTipY = note.getStemExtents().topY;
      total += stemTipY;
      if (stem_direction === Stem.DOWN && currentExtreme < stemTipY) {
        currentExtreme = stemTipY;
        extremeY = Math.max(...note.getYs());
        extremeBeamCount = note.getBeamCount();
      } else if (
        stem_direction === Stem.UP && (currentExtreme === 0 || currentExtreme > stemTipY)
      ) {
        currentExtreme = stemTipY;
        extremeY = Math.min(...note.getYs());
        extremeBeamCount = note.getBeamCount();
      }
    }
    let offset = total / notes.length;
    const beamWidth = beam_width * 1.5;
    const extremeTest = min_flat_beam_offset + (extremeBeamCount * beamWidth);
    const newOffset = extremeY + (extremeTest * -stem_direction);
    if (stem_direction === Stem.DOWN && offset < newOffset) {
      offset = extremeY + extremeTest;
    } else if (stem_direction === Stem.UP && offset > newOffset) {
      offset = extremeY - extremeTest;
    }
    if (!(flat_beam_offset + this.render_options.flat_beam_offset_per_beam > 0)) {
      this.render_options.flat_beam_offset = offset;
    } else if (stem_direction === Stem.DOWN && offset > flat_beam_offset && !this.render_options.flat_beams) {
       this.render_options.flat_beam_offset = offset;
    } else if (stem_direction === Stem.UP && offset < flat_beam_offset && !this.render_options.flat_beams) {
       this.render_options.flat_beam_offset = offset;
    }
    this.slope = 0;
    this.y_shift = 0;
  }
calculateFlatSlope ( ) { const { notes , stem_direction , render_options : { beam_width , min_flat_beam_offset , flat_beam_offset } , } = this ; let total = 0 ; let extremeY = 0 ; let extremeBeamCount = 0 ; let currentExtreme = 0 ; for ( let i = 0 ; i < notes . length ; i ++ ) { const note = notes [ i ] ; const stemTipY = note . getStemExtents ( ) . topY ; total += stemTipY ; if ( stem_direction === Stem . DOWN && currentExtreme < stemTipY ) { currentExtreme = stemTipY ; extremeY = Math . max ( ... note . getYs ( ) ) ; extremeBeamCount = note . getBeamCount ( ) ; } else if ( stem_direction === Stem . UP && ( currentExtreme === 0 || currentExtreme > stemTipY ) ) { currentExtreme = stemTipY ; extremeY = Math . min ( ... note . getYs ( ) ) ; extremeBeamCount = note . getBeamCount ( ) ; } } let offset = total / notes . length ; const beamWidth = beam_width * 1.5 ; const extremeTest = min_flat_beam_offset + ( extremeBeamCount * beamWidth ) ; const newOffset = extremeY + ( extremeTest * - stem_direction ) ; if ( stem_direction === Stem . DOWN && offset < newOffset ) { offset = extremeY + extremeTest ; } else if ( stem_direction === Stem . UP && offset > newOffset ) { offset = extremeY - extremeTest ; } if ( ! ( flat_beam_offset + this . render_options . flat_beam_offset_per_beam > 0 ) ) { this . render_options . flat_beam_offset = offset ; } else if ( stem_direction === Stem . DOWN && offset > flat_beam_offset && ! this . render_options . flat_beams ) { this . render_options . flat_beam_offset = offset ; } else if ( stem_direction === Stem . UP && offset < flat_beam_offset && ! this . render_options . flat_beams ) { this . render_options . flat_beam_offset = offset ; } this . slope = 0 ; this . y_shift = 0 ; }
Calculate a slope and y-shift for flat beams
Calculate a slope and y - shift for flat beams
// If a flat beam offset has not yet been supplied or calculated, // generate one based on the notes in this particular note group // Store the highest or lowest note here // The beam count of the extreme note // Total up all of the offsets so we can average them out later // Store the highest (stems-up) or lowest (stems-down) note so the //  offset can be adjusted in case the average isn't enough // Average the offsets to try and come up with a reasonable one that //  works for all of the notes in the beam group. // In case the average isn't long enough, add or subtract some more //  based on the highest or lowest note (again, based on the stem //  direction). This also takes into account the added height due to //  the width of the beams. // Set the offset for the group based on the calculations above. // for flat beams, the slope and y_shift are simply 0