Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have annotations all at the same y level #770

Open
davidedelvento opened this issue Apr 12, 2020 · 1 comment
Open

Have annotations all at the same y level #770

davidedelvento opened this issue Apr 12, 2020 · 1 comment

Comments

@davidedelvento
Copy link

davidedelvento commented Apr 12, 2020

I am rendering something like

align

by simply having the following in a loop

var note = new VF.StaveNote({clef: "treble", keys: [upper_note], duration: "q", auto_stem: true });
note.addModifier(0, new VF.Annotation('O'));
note_list.push(note);

and then rendering it with

voice.addTickables(note_list);
var formatter = new VF.Formatter().joinVoices([voice]).format([voice], 600);
voice.draw(ctx, topStaff);

I would like to have all the Os aligned on the same vertical position, which I'd be fine to set manually e.g. by beforehand finding the highest note and set that. Looking at the source code

vexflow/src/annotation.js

Lines 193 to 202 in a2acedf

} else if (this.vert_justification === Annotation.VerticalJustify.TOP) {
y = Math.min(stave.getYForTopText(this.text_line), this.note.getYs()[0] - 10);
if (has_stem) {
y = Math.min(y, (stem_ext.topY - 5) - (spacing * this.text_line));
}
} else /* CENTER_STEM */ {
const extents = this.note.getStemExtents();
y = extents.topY + (extents.baseY - extents.topY) / 2 +
text_height / 2;
}

what I want does not seem possible, but perhaps it is (I am definitely not an expert in javascript and there may be some trick to force some of those variables to a "wrong" value so that I achieve all the Os at the same vertical level).

Alternatively, I could accomplish what I want in a different way, can you suggest options? I thought of:

  • Another voice of TextNotes
  • Another voice of StaveNotes with a constant high enough notes (made transparent) and with its own annotation
  • Another voice of StaveNotes with a constant high enough notes without (or transparent) ledger lines and stems

Unfortunately neither of those work as I'd want (perhaps it's just me but I will submit separate issues about the problems I am experiencing)

@davidedelvento
Copy link
Author

Since I have the various solutions described at the other issues, this one can be closed as far as I am concerned. I am not closing it myself in case you can see another use case where this can be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants