vexflow icon indicating copy to clipboard operation
vexflow copied to clipboard

Can't obtain Notehead Bounding Box

Open andiejs opened this issue 7 years ago • 1 comments

After everything is formatted, my_notehead.getBoundingBox() gives the error "Can't call getBoundingBox on an unformatted note.", because my_notehead.preFormatted is set to false. However, there are four variables needed for the calculation, all of which are returning good values -- therefore the bounding box should be obtainable!

The variables are: my_notehead.stave.getSpacingBetweenLines() my_notehead.getAbsoluteX() my_notehead.width my_notehead.y

oriented (The attached picture shows why this is needed -- this illustration has to do with melodic pitch-shape: lines between notes should be oriented down or up, according to melodic direction, but this would only work with the bounding box on the notehead, not on the stavenote!)

andiejs avatar Jun 24 '17 18:06 andiejs

Sorry for the late response to this -- the NoteHead is unformatted because of the way StaveNote draws notes. I would suggest obtaining your X position (as you are) from StaveNote.getBoundingBox(), and obtaining the Y position from Stave.getYForLine(line). (At least, that's why I do when I need to do something similar.)

One caution: lines in VexFlow are counted from the top and are zero-based. So: the top line of the staff is line 0, the bottom line is line 4. Spaces are .5's.

In any case, yes, it should be easy to enable NoteHead.getBoundingBox once a StaveNote is formatted, so I'm flagging this as a feature request.

gristow avatar Jul 17 '17 13:07 gristow