The method that you are using works well for a piece that I am doing for generative music, but I wanted to note that because of the way the Ruby notate def, it errors on any \ that are in the lilypond syntax. For example:
\relative c' {
c d e f
g a b c
}
Doesn't compile correctly. if you add another backslash:
\\relative c' {
c d e f
g a b c
}
it then works. I don't know Ruby well at all, so I don't know the proper way to Regex the string for the slashes, or I would provide code to fix the bug.
As a side note, it would seem like you could do this with simple scripting executing terminal commands to lilypond, but I won't argue with something that works.
escaping backslashes
The method that you are using works well for a piece that I am doing for generative music, but I wanted to note that because of the way the Ruby notate def, it errors on any \ that are in the lilypond syntax. For example:
\relative c' {
c d e f
g a b c
}
Doesn't compile correctly. if you add another backslash:
\\relative c' {
c d e f
g a b c
}
it then works. I don't know Ruby well at all, so I don't know the proper way to Regex the string for the slashes, or I would provide code to fix the bug.
As a side note, it would seem like you could do this with simple scripting executing terminal commands to lilypond, but I won't argue with something that works.