On Beams
Beams are interesting. Engraving rules for beams are extremely inconsistent. In essence, the ideal rendering involves striking a balance between the direction of the music, the angle of the beam, and the length of the stems. You don't want beams whose absolute slopes are too high, and you also don't want to compromise on the slopes too much by making the stems too long.
There is one well-known rule, however: Never shorten a stem.
The algorithm I currently use to render beams seems to work pretty well. I use an approach where I iteratively update the slope and y-shift of the beam, based on the height of each stem.
In retrospect, this algorithm seems pretty obvious, but I really had to experiment a fair bit to derive it. The first few beams were just all over the place.
My debugging code places colored dots at various control points to help me visualize the errors better. It took me a bit of effort before I got to the rendering below. The beams still aren't shifted far enough to both accommodate for the stem heights.
After ironing out the iterative algorithm, I got this:
Perfect! The stems are only extended where necessary, and the angles of the beams adequately reflect the direction of the music.
Thanks to the context-based architecture, note-modifiers such as accidentals don't disturb beam positioning.
That said, something about the above rendering does not look right to me. The group of eighth notes don't look like they're positioned very evenly. If anyone knows how to render beamed notes with accidentals correctly, please let me know.
Anyhow, I also got slides and ties working again. These were gone after the rewrite, and I had to work them in using the new framework.
These actually make use of annotation-contexts which help determine the position of the annotation text above the stave.
I'm still a bit unsure of how to render ties across different note steps, with accidentals. What I have now looks like this:
Although this is a really uncommon case, it would be nice if there were a generic way to deal with it. Thoughts? Ideas?
That's all for now folks, and thanks very much for the comments. Keep 'em coming!










10 comments (imported from blogger)
The tie method between chords is a difficult topic to find a definitive answer. I like the bent method, but not sure classical musicians will approve. It's very readable, but I'm not that strict on standards. The extension of that is dealing with tying notes of different durations to a chord that follows, lots of overlaps to deal with. Just some food for thought. Keep up the great work!
I haven't really thought about beams across staves, but I think it should be pretty straightforward to support for two staves. (I hope beams don't usually go across more than two staves, because that will be pretty tricky.)
Re: large ranges, I tend to prefer high slopes to lengthening stems. (I'll update this post with an example shortly.)
Thanks for the comments, much appreciated. :-)
Just for your reference:
http://img485.imageshack.us/img485/4071/beamsjh0.png
http://www.turandot.hu/Images/cross_staff1.gif
http://www.lilypond.org/doc/v2.12/input/regression/92/lily-b035726f.png
Can't seem to find an example of the tied chords I mentioned. I've seen it in the printed music I've used, but dont have any with me to scan.
This is very good and encouraging work and I'm really happy to see that you want to deal with complex details. Have you thought about how to handle beams on the staff and how they will be positioned relatively to the lines in the staff? Especially for shorter notes, the staff lines can make reading harder if the beams are not carefully positioned. This is a simple example: http://i.imgur.com/p732J.png
Hope this helps in some way, keep up the good work!
@raf: I haven't really thought about positioning relative to staff lines, but thanks for bringing it up. I'm going to experiment with some cases where the beams interfere with the staff, and see if I can come up with a general solution.
Anyway, If you have plans to open source this project I will be a ready contributor, and if you plan to sell it commercially I'll be your first payer. Great work!!!
@Tails: Screenshots? Is it the fact that the staves are _below_ the tabs that you find useful? If that's the case, the API allows you to position the staves where ever you like.
@Rein: Thanks... I'm crunching away...