Csound, MIDI, Philip Glass’s “Two Pages”

I’ve been wanting a relatively convenient means of driving either a MIDI-capable keyboard or my analog synth from what are basically glorified source code files. At the moment, I’m trying the freely-available Csound application.

What follows below is a one-minute sample of Philip Glass’s 1968 composition Two Pages. This sample is monophonic and has a very low bit rate. Still sounds OK, but I didn’t want to infringe on his copyright. I believe this brief clip qualifies as “fair use,” since it is in part educational (mine).

 

The first step was to laboriously write the MIDI note values in a column in an Excel spreadsheet. Based on Glass’s Nonesuch recording, there are some 7,142 eighth notes played at roughly 176 beats per minute. This was the truly tedious part.

After some experimentation on a few notes at a time, I came up with timing parameters to supply to Csound, as well as some Csound shorthand to facilitate copying and pasting. The rest was a matter of  copy + fill down. Then to TextEdit to paste as raw text into the source file.

TwoPagesCsound       TwoPagesCsoundInstrument

Above  are a couple of screen shots of the source file running in the CsoundQt graphical front end on my iMac. As can be seen in the instrument definition, the original used the midiout opcode. I got better results switching to  noteondur2.

After a couple of false starts (like forgetting these are eighth notes, not quarter notes 😉 ), I finally arrived at a source file that plays my MIDI keyboard more or less successfully for the twenty minute duration of the piece. Simultaneously, the program writes the thousands of MIDI NOTEON and NOTEOFF events to a basic .MID file for further use.

Some more piddling around, and I decided to record the piece in stacked fifths (root, fifth, ninth, thirteenth. I needed only to add four additional noteondur2 opcodes to get the effect. This is, I admit, trivial stuff, and there’s so much more I need to figure out before I can even think to write my own compositions.

Next, I imported the MIDI file into Propellerhead Software’s Reason, assigned the note data to three virtual instruments, and tweaked the result with “reverb,” e.q., and compression.

Things I learned:

  • Csound is immensely flexible, but it struggles to send large volumes of data to a MIDI destination with perfect timing (i.e., there is some jitter). Part of this is due, no doubt, to my use of a USB interface, as well as to the fact that MIDI is a slower protocol. OTOH, the principal developer of Csound has acknowledged that MIDI was a somewhat late addition to the program’s architecture and that a complete rewrite would be required to get maximum precision on MIDI output.
  • For some reason I absolutely cannot figure out, I can’t run my .CSD files through Csound at the command line. The resulting MIDI file is fine, but all the notes (all 7,142 of ’em) sound nearly simultaneously. This is, to say the least, an interesting effect 😉 . Running the file from within CsoundQt works OK, though. That’s probably how I’ll drive my analog synth down the road.[4/29/15: found the solution to the simultaneous NOTEON‘s. I edited my bash .profile config file and defined an alias as follows:
    csMIDI = ‘csound -+rtaudio=auhal -iadc -odac -Q0’
    It seems that some of the arguments should be extraneous, as I’m not rendering audio, but it works. Good enough.]