December 09, 2004

Music/MIDI & Mac

The idea of using my Mac for creating music has been a thought in the back of my head for a long time. Finally, I put enough time into coding to make a real set of tools. This post describes my last month of progress in the hopes that this will be helpful to others.

The basic idea was to create music using UNIX basics, my own algorithms, MIDI and a synth. A year and a half ago, I used the echo.cpp example code to create a set of code that uses stdio via a text format to send/receive midi events. I called them mid2txt and txt2mid. However, synthesis at that time for me was just not that interesting--I had no synth! So, those tools went up onto the virtual shelf and were ignored after a bit of noodling.

Apple helped the situation out in a huge way with the introduction of GarageBand earlier this year. Finally, a synth and sequencer. I loved it, but when it was introduced, I had no time. And when I did try my txt2mid program, it didn't work with it and I couldn't figure out why.

Fast-forward to November. I had just received an Oxygen-8 keyboard and was having a bit of fun playing with it & GarageBand. Soon enough, I started thinking more about writing programs...

Looking around the net, I finally read that I needed to create/use a virtual midi source in my code. After finding the code here, it was simple enough to get txt2vmid working. For a moment, I thought all the pieces were in place...

But, the next problem came from timing the midi events. The problem was, no matter what I tried, I just could not get my code to get a proper timing loop in order to send the midi events when they should be sent. Basically, I got within 0.01s most of the time, but every once-in-a while a delay of 0.2s would pop in and destroy the sequence. It got even worse when I actually turned GarageBand recording on. Grrrr, I was pulling my hair out.

Googling & searching the coreaudio email list took a night or two before I found this post. Ah, what a brilliant idea--use a round-trip through the OS midi server to get the timing right. I modified txt2vmid in a couple hours and it worked like a charm. Woo-hoo! The timing was dead-on and recording in GarageBand is only a little annoying because I need to trim/align my input sequences after each recording.

I'm on my way now, having fun creating music with Python. Soon, I'll try to have something to put out there, but in the meantime, as kharmic payback for the virtual help I've received, I'm releasing my code for others to use. Grab it from UPDATED! http://rogerandwendy.com/roger/mac/mtl-2008.05.24.tar.gz if you'd like.

Please send me email (my_first_name-at-rogerandwendy.com) if you use it, though. I'd appreciate knowing.

3 comments:

Unknown said...

Years later, someone wants to take a look but no files :(

Can you repost?

Thanks,

Chris

Roger Allen said...

I'll find the code & repost, sure. Will followup when I do this. Send email if you want it directly.

Roger Allen said...

Updated code is in http://www.rogerandwendy.com/roger/code/mtl-2008.05.24.tar.gz