Opensheetmusicdisplay: Accessing <text/> SVG elements for tablature notes

Created on 2 Aug 2020  路  3Comments  路  Source: opensheetmusicdisplay/opensheetmusicdisplay

In the SVG there is no distinction between elements that are tab notes, and elements that are measure numbers or other text labels. This makes note highlighting for guitar tablature pretty complex.

If the elements in the SVG had classnames like other types of notes (.vf-stavenote), it could be achieved easily. Could OSMD please add a classnames to tab notes like ".osmd-tabnote" or ".vf-tabstavenote" for example?

Or perhaps there is another way to reliably access the list of tab note svg elements that I missed?

Tabs

Most helpful comment

This is now built in to the new OSMD 0.8.4.
This still needs to be patched in manually by the one building OSMD (for now), if using Vexflow 1.2.93, but at least i added the patch files to the repository in src/VexFlowPatch/.

All 3 comments

This needs to be adjusted in Vexflow.
I patched it in manually:
image

this is tabnotejs:draw() (i added the two lines with comments):

  draw() {
    this.checkContext();

    if (!this.stave) {
      throw new Vex.RERR('NoStave', "Can't draw without a stave.");
    }

    if (this.ys.length === 0) {
      throw new Vex.RERR('NoYValues', "Can't draw note without Y values.");
    }

    this.setRendered();
    const render_stem = this.beam == null && this.render_options.draw_stem;

    this.context.openGroup('tabnote', null, { pointerBBox: true }); // added for osmd#850
    this.drawPositions();
    this.drawStemThrough();

    const stem_x = this.getStemX();

    this.stem.setNoteHeadXBounds(stem_x, stem_x);

    if (render_stem) {
      this.context.openGroup('stem', null, { pointerBBox: true });
      this.stem.setContext(this.context).draw();
      this.context.closeGroup();
    }

    this.drawFlag();
    this.drawModifiers();
    this.context.closeGroup(); // added for osmd#850
  }

I can patch this in manually for the next release.
I added a pull request to Vexflow so it's in their next version (though we can't yet use vexflow 3.x because of formatting).

This is now built in to the new OSMD 0.8.4.
This still needs to be patched in manually by the one building OSMD (for now), if using Vexflow 1.2.93, but at least i added the patch files to the repository in src/VexFlowPatch/.

Thank you so much! You're the best!!

Was this page helpful?
0 / 5 - 0 ratings