Monday, July 05, 2010

Amazing Grace - now with a macro inside a macro

Today's post was made using a new function in my pre-processor, which reads a text file and generates Csound source code. The new function makes it possible to change the name of a macro each time it is called. For example, I've always been able to make a different macros, and call them explicitly by name:

.pian c1v67
.any01-1-a1 d12t42

This snippet would produce a line like this:


Which would in turn produce a Csound score line like this:

i1 0 42 67 42

Csound would interpret each parameter as time to start, duration, loudness, pitch, etc. There are parameters for many other note characteristics, but that's enough for this example.

I can call a macro by name, or I can let the preprocessor pick one that meets a "wild card" match. For example:

.pian c1v67
.any01-1-a1 d12t42
.any01-1-a2 d12t3

This would either call any01-1-a1 or any01-1-a2, chosen by one randomization method or another. That was the limit to the preprocessor up until today. This meant that I would have to generate choices for all the measures in a hymn transformation. In one case, that was over 60 different sets of possible chords to choose from. The transformation of Now Thank We All Our God had over 8000 lines of source code, all done my hand. It was very tedious, and prone to error if I missed a letter or two. And if I discovered one particularly useful way to manipulate a chord near the end of my composition process, I couldn't retrofit it to all the other measures.

The new method allows me to call a macro and change which one I call using simple indirection. For example:

.pian c1v67
.any01-1-a1 d12t42
.any02-1-a1 d12t3
.num 01
.num 02

The macro name is resolved inside out: first &num. is resolved to 01, then &any01-1-a* is resolved to d12t42 or d12t3. With recursion, any number of indirections are possible. Gotta love that 1980's Turbo Pascal compiler.

This allows me to chose a different macro for each chord at execution time, but set up a massive number of variations for all chords, without coding each measure individually. That's a 60:1 savings on code size and tedium. All good.

Today's example is the first five chords of Amazing Grace, repeated seven times. The variation is set to maximum, so there are some strange slips and slides, and trills that your ordinary piano can't do. Mine can. It still sounds like a piano, just one that has some extra mechanical do-dads inside.

Play it here: or download this linkSubscribe here: to this RSS feed

No comments: