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

better view for txt code #1

Closed HowcanoeWang closed 6 years ago

HowcanoeWang commented 6 years ago

when writing a jianpu text file, it will become a chaos if it does not have separation to assist.

for example, when I write the following music: image

the txt file is like this:

3' 6 1' 3' 3' - 2' - 2' - - 2'

It may become much better to write like this:

3' 6 1' 3' | 3' - 2' - | 2' - - 2' |

however, the symbol '|' is used in Repeat (with alternate endings): A{ 2 | 3 }

May you add an if-else judgement that only in A{} paired '|' can be converted, otherwise just ignore it?

Thanks a lot!

ssb22 commented 6 years ago

Sorry I have only just seen this: I didn't realise Github doesn't automatically give us email notifications on new issues. When writing a complex jianpu file I normally just start a new line every bar, but I guess | is a more natural choice because it is the bar-check indicator in Lilypond (and Lilypond does not just ignore them, it also checks that the bar is correct length and warns you if not). But I'm not sure it's a good idea to "overload" | so it means a different thing depending on whether or not you are in a repeat: doing that could cause less error-checking, e.g. if someone forgets the A{ at the start of their alternatives, they need an error to tell them something is wrong. I could add an "ignore errors like this" option but it's probably not a good idea: people would switch it on and fail to realise if their input really does have an error.

I am now tempted to change the existing use of | into || and make | the standard bar-check character. But changing an existing part of the syntax would break some people's existing input, so I don't want to do it without some thought first. But perhaps I should not worry quite so much because (1) Lilypond itself has changed its syntax many times and (2) I can easily add code to check that there is a || inside each A{ block and error if not, so existing input files that use | within A{ will get an error and an explanation after they upgrade jianpu-ly (and I expect this is not a common use-case anyway).

ssb22 commented 6 years ago

... or perhaps }{ would be better than || as the alternate-separator syntax, as || could be confused with a section separator ...

HowcanoeWang commented 6 years ago

Okay, I have read the source code and modify it as what I want.

...
def getLY(score):
...
            elif word=="|":
                pass
            elif word=="A{":
                repeatStack.append((2,0,0))
                out.append(r'\alternative { {')
            elif word=="||":
                #if not repeatStack[-1][0]==2:
                #    sys.stderr.write("| should be in an A{ .. } block (scoreNo=%d barNo=%d)" % (scoreNo,notehead_markup.barNo))
                #out.append("} {")
                try:
                    if not repeatStack[-1][0]==2:
                        sys.stderr.write("| should be in an A{ .. } block (scoreNo=%d barNo=%d)" % (scoreNo,notehead_markup.barNo))
                    out.append("} {")
                except IndexError:
                    pass

Also I strongly support your opinion

But changing an existing part of the syntax would break some people's existing input

So I will just use it as a personal version ^_^, thank you very much

ssb22 commented 6 years ago

Instead of "pass", try "out.append(' | ')" which will copy the | characters to Lilypond. That way Lilypond will warn you if you make a bar the wrong length.

HowcanoeWang commented 6 years ago

Great, thanks a lot!