Managing midi control messages



basically, there are two functions to get control messages from external midi hardware: sync and get. sync waits for an event, get will give the last message received.

Let’s say you’d like to get the current value of controller number one, the code could look like this:

live_loop :player do
  controller, value =  get "/midi/photon_25_midi_1/1/1/control_change"
  puts value if controller == 1
  sleep 1

This is not very elegant, is it?

I found another solution, which is a nice hack perhaps, but still awkward:

values = [0,0,0,0,0,0,0,0,0,0,0,0,0]

live_loop :updater do
  controller, values[controller] =  get "/midi/photon_25_midi_1/1/1/control_change"
  puts values[1]
  sleep 1

Any better idea? Something like

get "....", 1

would be awesome!


Completely agreed. Pattern matching on event paths is something I’ve been planning for a while :slight_smile:


Thank you Sam, so this means, the given code examples are best practice for current sonic pi versions?