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

line comments in `LP: ... :LP` blocks break MIDI STAFF #13

Closed BertrandSim closed 2 years ago

BertrandSim commented 2 years ago

Hi Silas,

I've found that using line comments inside an LP: ... :LP block affects the output in between BEGIN MIDI STAFF and END MIDI STAFF.

My guess is that jianpu-ly places the output in between BEGIN MIDI STAFF and END MIDI STAFF on a single line, thus the % comment marker causes subsequent lines to be commented out as well.

Here's an example:

% input file
4/4

LP: 
c' % comment1
d' % comment2
:LP

1  1 1 1 
% output .ly file
% ...
% === BEGIN MIDI STAFF ===
    \new Staff { \new Voice="midi" { \time 4/4 c' % comment1 d' % comment2 c'4 c'4 c'4 c'4 } }
% === END MIDI STAFF ===
% ...

Perhaps this can be fixed by having each line inside an LP: ... :LP block in the input file to have a line ending char in the .ly output.

Best, Bertrand

ssb22 commented 2 years ago

Thanks Bertrand, well spotted, it's due to the lines:

if midi or western: out = ' '.join(out)
else: out = '\n'.join(out)

i.e. join the output items with newlines by default, but with spaces if outputting a MIDI or Western staff. The original reason for this was that each "output item" is likely to be a note, and having only one note per line seemed excessive for MIDI or Western, but makes more sense for jianpu where there is rather a lot of Lilypond code for each note. But it wouldn't actually hurt to unconditionally use '\n'.join(out) here if you don't mind lots of extra newlines in the .ly file.

As a temporary workaround, you might like to use Lilypond's %{ ... %} comment syntax (which can be used within a line, like C's / ... / ) instead of just %. But I agree we really should preserve newlines within LP: blocks, and not just because of comments (there are other advanced Lilypond 'hacks' that may require newlines in some places). I'll see if I can fix this properly later (I'm still not finished tinkering with bug #12 ....)