{else}

Practical Ruby Projects Chapter 2 - Making Music with Ruby Making it work on Snow Leopard

Written by Matthew Forr View Comments

This book promised a plethora of projects I was disappointed when I got hung up early in the book because I couldn’t get sound to come out of my computer. For a bit I thought I had jacked my MIDI settings because I’m always hooking things up to my computer and playing with with various MIDI routing programs but I was wrong.

After taking some time off I came back and found this Stackoverflow question which seemed to solve the problem but Pastie didn’t contain the code.

Following the github link took me to a livecoding environment tool (something to play with later!) with updates for SnowLeopard.

I ported them into my LiveMIDI.rb file and things are working now so thanks to you Zackola for pointing me in the right direction.

I’m guessing other people might be looking for this so I submitted it to the books errata page and am posting it here for reference.

# Figure out if we have SnowLeopard
SnowLeopard = `uname -r` =~ /10\.\d\.\d/

# MIDIPacketListAdd takes different arguments in Snow Leopard so we'll update both the extern and further down when we call it.
if SnowLeopard
  extern "void * MIDIPacketListAdd(void *, int, void *, int, int, void*)"
else  
  extern "void * MIDIPacketListAdd(void *, int, void *, int, int, int, void *)"
end

# And give it what it wants.
if SnowLeopard
  packet_ptr = C.mIDIPacketListAdd(packet_list, 256, packet_ptr, 0, args.size, bytes)
else
  packet_ptr = C.mIDIPacketListAdd(packet_list, 256, packet_ptr, 0, 0, args.size, bytes)
end