scaramouche
scaramouche

Reputation: 471

Programmatically create a MIDI file from any LilyPond file

I want to create a MIDI file from any LilyPond file, without having to manually add a \midi { } block.

Can this be done from the command line? Ideally I am looking for an option like lilypond --midi. The final goal is to create a shell script, lilypond2midi.

Upvotes: 0

Views: 902

Answers (1)

jwvh
jwvh

Reputation: 51271

The documentation makes it pretty clear that there is no such command-line option, so this isn't really a LilyPond question.

What you could do, however, is insert the \midi command into the LilyPond code dynamically within your shell script.

For example, your script could do something like this. (I haven't done any AWK in a while, but I think this works. Perl could also tackle this problem.)

awk '/^\\score/ {inScore=1}
     /^}/ {if (inScore == 1) print "\midi {}"
                             inScore=0
          }
     {print}' ${filename}.ly | lilypond -o $filename -

This assumes that the input file has a \score block and that the first closing brace, }, at the beginning of a line, after the \score block begins, is the closing of the \score block.

This doesn't alter the original LilyPond file, of course, but LilyPond will compile it as if it did have a \midi command.

Upvotes: 3

Related Questions