ssb22 / jianpu-ly

Jianpu in Lilypond
http://ssb22.user.srcf.net/mwrhome/jianpu-ly.html
Apache License 2.0
70 stars 18 forks source link

beams with rests #52

Closed BertrandSim closed 8 months ago

BertrandSim commented 8 months ago

Hi Silas,

I noticed that when lyrics are given, beams joining a rest and pitched notes become disjointed.

1=C
4/4

NoBarNums

q0 q1 q2 q3 q4 q5 s6 s7 q0

L: 1. hello hello hello hello hello hello hello

image

When there are no lyrics, the beams between rest and notes are joined as per usual.

image

Is this behavior intended?

Bertrand

ssb22 commented 8 months ago

Unfortunately this is a Lilypond limitation, and it depends which version of Lilypond you have. The problem is:

So it was a "least bad option" / known limitation: rests in beams with lyrics result in the beams being broken.

If you run jianpu-ly with --noRestHack (or change the variable use_rest_hack) you can turn off all this "tell Lilypond the rests are notes" logic, and see if your particular version of Lilypond can beam them properly if it's told they are rests. The comment in the code currently says: "Implement short rests as notes (and if there are lyrics, creates temporary voices so the lyrics miss them); sometimes works better for beaming (at least in 2.15, 2.16 and 2.18)". We probably need to test more thoroughly on later versions of Lilypond (2.20, 2.22, 2.24) and perhaps add some kind of "check the actual Lilypond version on this system before deciding what the default should be": if recent versions are better anyway then we might be able to turn off this workaround.

Alternatively there might be some other way of telling Lilypond to avoid a note for the purpose of lyrics, other than putting that note into a different voice. Probably by keeping track of where we are in the lyric text itself and adding in null syllables like "" but we'd have to check what that does to hyphenation in the case of a rest breaking up a word. But I'd rather look at 'under what circumstances can we definitely turn off this workaround' because it doesn't really seem right telling Lilypond that rests are notes....

ssb22 commented 8 months ago

just tried in 2.24.3 and it's fine with --noRestHack, so I'll make that the default option if our Lilypond is 2.24 or above (will try to check 2.22 at some time)

ssb22 commented 8 months ago

ah hold on: that particular input with --noRestHack works even on the older versions of Lilypond that needed the rest hack for other input. I'd better try to find which input was actually causing a problem for those versions, so as to find out what was the earliest version (hopefully there is one) in which it's no longer a problem

ssb22 commented 8 months ago

OK, here's an example of input that definitely needs the rest hack to work properly on Lilypond 2.18.2:

4/4,8 q0 1 2 3 q0

Lilypond 2.20.0 and 2.22.2 are still affected, and so is, unfortunately, Lilypond 2.24.3. Which means it's not ready to be taken out yet. (We might be able to be more clever about exactly when we do and don't have to apply the rest hack, but it's still going to be in there in some cases; I'm not sure how easy it is to check if all the instances where rests are beamed to non-rests are instances where rest-hack is not needed in a particular Lilypond version.) So it looks like we'll need some other way of addressing this, like syllable skips (which could take a bit of tracking in the code and we'll need to check what it does to hyphenation)

ssb22 commented 8 months ago

oh I forgot to mention: another way to work around the problem is to add a WithStaff since that causes the lyrics to be attached to the 5-line staff instead of to the jianpu

BertrandSim commented 8 months ago
  • To work around this, we pretend the rest is a note that looks like a "0" and tell Lilypond to typeset that note (it doesn't matter that it's not really a note, as long as Lilypond puts ink on paper the way we want!)
  • but when we bring lyrics into the scene, we somehow have to tell Lilypond that "OK, although this '0' thing is, as far as you're concerned, a 'note', it's not a note that you should put a lyric underneath".

Thanks for the explanations, and that sounds tricky. I'll need to think more into this.

another way to work around the problem is to add a WithStaff since that causes the lyrics to be attached to the 5-line staff instead of to the jianpu

Thanks Silas, I'll use this workaround for now.