Controlling Master volume throught MIDI


Hi! I was thinking if it is possible to control the master volume with a knob of my MIDI controller. I’ve found out that I can use set_volume! to choose the initial master volume, but I don’t know how to control it with the knob. Thank you!


Here you are. I used a controller knob which sent midi cc messages to control 17 on my keyboard

live_loop :vcontrol do
  control_num,val = sync "/midi/*/*/*/control_change"
  if control_num==17
    puts "controller number 17 detected: setting volume to #{val.to_f/127} "
    set_volume! (val.to_f/127)

live_loop :pl do #to play some notes so you can hear the volume change
  play scale(:c4,:major,num_octaves: 2).choose, release: 0.2
  sleep 0.2

Remember to reset the volume back to 1 at the end as the last value will persist.
I used wild cards for the sync stgring so it will work with any connected controller on the specified ccontroll 17