Day 25: No time.

There just wasn’t time
for güiros today. I wrote
this haiku instead.


Day 24: Fun-a-Day DC Style

I started this whole Fun-a-Day thing on account of my friends up in NYC, but apparently, there is a DC chapter as well. I’m told they had an event at Qualia Coffee today, which I sadly missed.

That’s fine because I stayed up really late last night working on my güiro patch, and I feel like things are finally coming together. I cleaned up my Csound code, and then set it up so I could trigger the güiro sound with the drum pads on my Electribe ER-1. I bought this drum machine over a decade ago, and it is so satisfying to breath new life into an old machine. What’s interesting is that the drum machine appears to only send information about velocity when you play the pads manually. I guess that makes sense, but it means that I need to read the MIDI in a different way in order to be able to program the güiro beats with the drum machine.

That’s fine because my real interest in using the drum machine was for its knobs, which would control the parameters of my drum sound. I can always program the actual beats in Csound, but I want live control over those parameters via physical knobs. I tried setting this up, but it turns out that the ER-1 uses NRPN MIDI signals, and while Csound has an opcode for producing NRPN’s, it doesn’t have one for receiving them.  I spent a good portion of yesterday evening mining the web for info on this and trying to get ctrl14 to read the NRPN as a 14-bit MIDI signal, which is apparently something entirely different.

Finally, at the end of the night, I discovered the midiin opcode, which reads MIDI events as raw data and lets the user decide how to interpret that data. I haven’t had a chance yet to implement this, but it will allow me to finally set up those knobs. If I get this working correctly, I could turn my ER-1 into a Latin drum machine with up to eight different drum sounds, each with completely unique parameters. I might just do this because I already have an FM conga patch that I wrote in Csound a while ago. If I do go that route, I’m going to make covers for the ER-1 that can be printed out and placed over the drum machine so that each knob is labelled appropriately. A pretty cool hack.

If nothing else, I’m learning a lot about MIDI from this project.

Day 23: Success.

I had a fun, productive meeting with the Maracuyistas today. There’s exciting things in the pipeline so stay tuned for more info on that!

In the meantime, I have solved my MIDI woes! This article was *very* helpful for straightening out the different MIDI systems in Linux. Basically, ALSA and JACK each have their own MIDI system, but the JACK one cannot communicate with hardware (only software.) There are two ways to combine the systems (raw and seq.) My USB Audio Interface wants me to use seq, which is fine because that’s the more sophisticated method of the two.

If you open the “Connect” window in qjackctl, it has three tabs: Audio, MIDI, and ALSA. The first one connects the actual digital audio signals so that you can pipe the audio from one program into another and so on. The other two tabs are actually both MIDI connections. The MIDI tab connects MIDI within the JACK system, and the ALSA tab connects MIDI within the ALSA system.

The program Patchage provides an alternative way of visualizing these connections. In that system, digital connections are represented in blue, ALSA MIDI connections in red, and JACK MIDI connections in green. The program a2jmidid can port between ALSA and JACK MIDI connections, but this can also be done through JACK’s midi-through, something not mentioned in the above article. I found this patchage tutorial very helpful.

After reading through these two threads:


I discovered that the real-time MIDI support via JACK was not configured correctly on my computer (since I upgraded to Ubuntu Studio through the general Ubuntu distribution.) To fix that, I followed the instructions here, adding myself the the audio group and giving the audio group permissions to access the rtprio, nice, and memlock limits (whatever those are.)

That eliminated the errors I was getting before only to introduce new ones. It turns out that MIDI is even more complicated. There is also some sort of kernel-level virtual MIDI, and Csound can only communite with virtual MIDI ports. As this article suggests, you can enable these by runnings

sudo modprobe snd-virmidi

On my system, this adds four new “virtual” midi ports, which appear in the output of “amidi -l” as

IO hw:2,0 Virtual Raw MIDI (16 subdevices)
IO hw:2,1 Virtual Raw MIDI (16 subdevices)
IO hw:2,2 Virtual Raw MIDI (16 subdevices)
IO hw:2,3 Virtual Raw MIDI (16 subdevices)

Awesome. So now I run csound with the following options

-d --sched -+rtaudio=jack -o dac:system:playback_ -+rtmidi=alsa -Ma -b 256 -B 2048

and everything starts up as its supposed to without any errors. Finally, I go into Patchage and connect the MIDI from my USB Audio Interface (AudioBox 1818 VSL) to the first virtual raw midi port (Virtual Raw MIDI 2-3) and ¡wepa! I have working MIDI.

As you can see, it was no small feat getting this working, and gives me a better appreciation for why so few musicians use Linux. Why does everything have to be so goddamn complicated?!

Now that I know my way around MIDI, I’m going to spend the rest of my evening plugging everything the güiro patch I wrote. It will be run from drum machine as though it were a built-in drum sound, and I will be able to modify all the parameters of its sound live just by twisting knobs. A complete and total success.

Day 22: Baby steps for MIDI

I bought a MIDI cable today after I realized I could connect MIDI devices through my USB audio interface. I plugged by Korg Electribe ER-1 into the Audio Interface, fired up QMidiArp, enabled logging of MIDI events, and started turning knobs. I’m getting real-time feedback. The MIDI is definitely working! This is exciting because it means I can just program a rhythm in on my drum machine (a pleasant, tangible interface,) but have it modify the patch in Csound. Basically, my ER-1 will be able to control the güiro patch as though it were one of the built-in drum sounds.

That’s the good news; the bad news is that I cannot get Csound to recognize any alsa midi device and I spent a good long time messing with this. I’m feeling very frustrated so I’m giving up for today. Baby steps…

Day 20? Something like that…

I kinda fell off the Fun-a-Day bandwagon for the last 5 days, but I’m getting back into the swing of things. I had an idea today to use my DX7 or my Electribe ER-1 as an external MIDI controller for my güiro patch. Turns out that this is very commonplace, using a non-MIDI controller keyboard as a MIDI controller keyboard. I need to get a MIDI-to-USB cable though.

I also started cleaning up the güiro patch code. I commented what each thing does, and tomorrow I’m going to map it all out on paper and come up with appropriate names for the variables. Right now, it’s a mess. For example, I have two triangle waves that play analogous roles but one is called atri while the other is amod. These should be atri1 and atri2.

Also, I looked into setting a default value for a slider with ctrl7. I didn’t realize that the 7 refers to a 7-bit MIDI message (and not the 7th of several ctrl opcodes.) It turns out that you can set default values, but you have to use a different opcode: initc7.

Tomorrow, I’ll finish cleaning the code up, and set up the MIDI sliders.

Day 14: The Day of Looove

I’m running out the door to see Los Rakas so we’ll keep this short. Today, I took that Csound program I wrote yesterday and turned one of the sliders in the virtual MIDI keyboard into a pitch-bender. The code was simple:

knote ctrl7 1, 1, inote, inote*4

knote is a control variable that uses the ctrl7 opcode to get its value. The first 1 after ctrl7 indicates to use MIDI channel 1, and the second 1 indicates to use control knob/slider/etc number 1. The last two values indicate the minimum and maximum values in the range of the slider. So you can basically bend the note from its initial value of inote up to four times its original pitch (i.e. 2 octaves.) Here’s the full instrument code:

sr = 44100
kr = 4410
ksmps = 10
nchnls = 2

instr 1
iamp = p4
inote = p5
knote ctrl7 1, 1, inote, inote*4
a1 oscil iamp, knote, 1
outs a1, a1

and the score looks like this

f0 20000
f1 0 4096 10 1 ; sine wave

i1 0 20 15000 440

Now, all the pieces are in place. I just need to set aside some time to clean up the güiro code, add the sliders, and figure out good min/max values for each of the sliders. I should also find a way to set the default slider value. I bet that’s an option with ctrl7.

Day 13: I can’t believe it’s already been 13 days!

If there’s one thing Fun-a-day gives me a good appreciation for it’s how quickly time passes. Can’t believe we’re almost halfway through the month and it just feels like last week that I was writing up that first post.

Today was a success. After reading these Realtime Csound on Linux: Tips and Tricks, and playing around with different settings, I was able to get an instrument working that played a very simple sine wave via the Virtual Midi Keyboard. In the end, I used these options in my csd file.

-d -+rtaudio=jack -o dac:system:playback_ -M0 -+rtmidi=virtual -b 256 -B 2048

The coolest part about MIDI in Csound is that you still have a score and as the score progresses, csound records your MIDI input and applies it to the the instrument. This means that I can have a musical score with the güiro beats programmed in already, and then use MIDI to control the timbre of the güiro in real-time by adjusting knobs. Since everything runs through JACK, I can direct the output of this “performance” to Ardour and record it.