3

When I work on my LilyPond scores, especially in the end when I just tweak on some graphical settings, it would be quite nice if it was possible to skip the Midi generation, even though it is not very time consuming. Is this possible from the command-line in a similar way then to skip the pdf generation?

Again I have not been able to find something in the LilyPond Documentary section about the Command-Line Options.


Update:

if I had the \midi {} block only in one line, I could simply comment it out by using sed from the command-line, with something like: sed -i 's/\\midi\ {}/%&/g' file.ly. While the option -i stands for inplace-editing. Without the option sed is going to print to stdout. You could also use wildcarts to batch process a bunch of files: *.ly would process all files ending with .ly in the current directory.

It would get more difficult, if the \midi block was bigger then a single line, like here with setting the tempo:

\version "2.18.2"

\score {
  <<
    \new Staff = "celloI" \with { midiInstrument = #"cello" }
    \relative c {
      \clef bass
      c4( d e f
      g1) \bar "|."
    }
    \new Staff = "celloII" \with { midiInstrument = #"cello" }
    \relative c, {
      \clef bass
      c4( d e f
      g1) \bar "|."
    }
  >>
  \layout {}
  \midi {
    \tempo 2 = 120
  } 
}
5
  • 2
    I fear there is indeed no command line option for this. The only way I can think of is to comment out the Midi block. Commented Dec 8, 2019 at 15:03
  • @JasperHabicht ok thanks. On a UNIX/LINUX system one could got for something with sed like sed -i 's/\\midi\ {}/%&/g' file.ly to comment out the \midi block. Though this would only work if the the block did not have multible lines.
    – nath
    Commented Dec 8, 2019 at 15:14
  • 1
    If the block has multiple lines, you could perhaps define a macro that contains these lines and put this macro into the midi block, which would then only have one line. Might not work in every case though ... Commented Dec 8, 2019 at 15:24
  • @JasperHabicht maybe this, with an example, is the appropriate answer :-)
    – nath
    Commented Dec 8, 2019 at 17:36
  • Do you have a snippet with a bit of your code, especially that from the midi block? Commented Dec 8, 2019 at 17:52

1 Answer 1

2

As far as I know, LilyPond does not provide a command line option for this. The only way I can think of is to comment out the midi block. However, your approach using sed is very promising!

To avoid the problem of your midi block containing several lines, you could write a macro that contains the whole midi block with all your settings and place this macro into your score block. You should then be able to use sed to replace this single line from your code.

I was not able to test this with sed, but if you change your code as follows, it should work with something like sed -i 's/\\mymidi/%&/g' file.ly:

\version "2.19.83"

mymidi = \midi {
    \tempo 2 = 120
  } 

\score {
  <<
    \new Staff = "celloI" \with { midiInstrument = #"cello" }
    \relative c {
      \clef bass
      c4( d e f
      g1) \bar "|."
    }
    \new Staff = "celloII" \with { midiInstrument = #"cello" }
    \relative c, {
      \clef bass
      c4( d e f
      g1) \bar "|."
    }
  >>
  \layout {}
  \mymidi 
}

If you have more than one score block, you would need to create several macros for the midi blocks and change the sed command accordingly.

The above code, however, seems to work only as from version 2.19.

4
  • 1
    This setup works pretty well for me. Sure I have quite a lot of \score blocks, but I could use something like \mymidifirst \mymidisecond etc. and then use sed to just comment the line out with an "add before pattern match" like: sed 's/\\mymidi/%&/g' *.ly
    – nath
    Commented Dec 9, 2019 at 7:12
  • for some reason I get 02.ly:23:3: Fehler: syntax error, unexpected OUTPUT_DEF_IDENTIFIER when truing to compile this.
    – nath
    Commented Jan 4, 2020 at 20:09
  • You are right. It seems that the code only works with the newest version of LilyPond. Commented Jan 8, 2020 at 9:55
  • this is kind of weird since it works like: macro = \relative { c d e f g } or macro = \markup { "some text" } it only does not work like: macro = \midi {}...
    – nath
    Commented Jan 8, 2020 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.