Wulf's Webden

The Webden on WordPress

AwkSed TubaBass

| 0 comments

A couple of months ago I was experimenting with ways to produce tuba and electric bass editions of the pieces I have worked up in Lilypond. Lilypond’s conditionals got me a certain way but it did mean adding an extra layer of complexity to the files and there were still things (like the instrument name) which I still had to manage via commented lines. At the time, I pondered if a Command Line Interface (CLI) tool like awk could help and, today, I have worked out a functional implementation to explore that more.

I am starting with base files that I am labelling .lyb (lilypond base). These are regular Lilypond files but some lines start either BASS: or TUBA:, as the signifier. Ending them with a colon means I can then run a short awk script – the tuba version presently looks like this:

#!/bin/awk -f

BEGIN { FS = “:” };

{
if ($1 == “TUBA”)
print $2
else
if ($1 == “BASS”)
pass
else
print $0
}

It is very basic – if breaking the line down by colon delimiters yields the string “TUBA”, print the rest of the line. Otherwise, either ignore the line if the first part is “BASS” or print the whole thing. My awk scripting skills are somewhat rusty; I am sure there are better ways of doing this, there is a glitch if any line starting “TUBA:” contains a further colon (anything after that will be dropped) and perhaps it would be better to do the whole thing in Python. It works for now though. I pipe the result through sed, where I can replace a piece of text saying RENDERDATE with a short date string and then I redirect the output not to the screen but to a file… which is pure lilypond and can be viewed and rendered with Frescobaldi.

What I can’t do is edit the base files directly in Frescobaldi but I can generate one I can work on and paste any changes back in to my master. There is still a certain clunkiness to the solution but I think it may suffice for the volume of files I am working on. If nothing else, it has generated the file I need for tomorrow’s rehearsal smoothly (albeit more slowly because of the time to develop the scripts) and should be a lot quicker as more pieces come along needing attention later in the term.

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.