Skip to content

Instantly share code, notes, and snippets.

@jjaffeux
Created February 14, 2013 23:53
Show Gist options
  • Save jjaffeux/4957496 to your computer and use it in GitHub Desktop.
Save jjaffeux/4957496 to your computer and use it in GitHub Desktop.
core_midi_sample_rubymotion
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
notificationProc = proc {|message, refCon|
p "MIDI Notify, messageId=#{message[0].messageID},"
}
midiNotification = Pointer.new(MIDINotification.type)
midiClient = Pointer.new(MIDIClientRef.type)
MIDIClientCreate("testcore", notificationProc, nil, midiClient)
#packetList = Pointer.new(MIDIPacketList.type)
readProc = proc {|packetList, refCon, connRefCon|
packet = pktlist.packet
midiCommand = packet.data[0] >> 4
if midiCommand == 0x09
note = packet.data[1] & 0x7F
velocity = packet.data[2] & 0x7F
p "Note ON. Note=#{note}, Velocity=#{velocity}"
end
}
inputPort = Pointer.new(MIDIPortRef.type)
MIDIInputPortCreate(midiClient[0], "inputport", readProc, nil, inputPort)
session = MIDINetworkSession.defaultSession
session.enabled = true
session.connectionPolicy = MIDINetworkConnectionPolicy_Anyone
sourceCount = MIDIGetNumberOfSources()
p "#{sourceCount} sources"
sourceCount.times do |i|
MIDIPortConnectSource(inputPort[0], MIDIGetSource(i), nil)
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment