MIDI IN issues - Real time sync of CC values not working

#1

Hi there ,

Excuses if it is too simple an issue but I am a bit short in time and I would really like to use Sonic Pi in my next performance a few days from now.

The issue is with MDI IN settings . How do I get the MIDI CC value to keep constant?
If I use it within the loop like so :

in_thread(name: :key_0) do

live_loop :midi_piano do

chan, ampCC = sync "/midi/reloop_keypad/9/1/control_change"

with_fx :compressor, amp: 0.5  do

          use_real_time
          
          use_synth_defaults release: 2, cutoff: 1, attack: 1, amp: ampCC/127.0
          ##| use_synth :saw
          note, velocity = sync "/midi/reloop_keypad/9/1/note_on"
          synth :saw, note: note,
            amp: velocity / 127.0
          play note
          play note + 50
          sleep 0.125
          
       end

end
end

The amp value from my Midi controller updates only when I touch it and seems to reset to 0 if I don’t

If I place it outside the loop like so :

in_thread(name: :key_0) do

chan, ampCC = sync “/midi/reloop_keypad/9/1/control_change”

live_loop :midi_piano do

with_fx :compressor, amp: 0.5  do
  
  use_real_time
  
  use_synth_defaults release: 2, cutoff: 1, attack: 1, amp: ampCC/127.0
  ##| use_synth :saw
  note, velocity = sync "/midi/reloop_keypad/9/1/note_on"
  synth :saw, note: note,
    amp: velocity / 127.0
  play note
  play note + 50
  sleep 0.125
  
  
end

end
end

it updates only if I run the code again

Any alternatives to this ?
I should be able to control in real time the level of ampCC without having to rerun the code every time or touch the volume fader every note I strike.

Any suggestions welcome

Thanks in advance

Seb

0 Likes

#2

I think you can do it with two live loops, something like the following (untested):

use_real_time

set :ampcc, 0
live_loop :midi_cc do
  _, amp = sync "/midi/reloop_keypad/9/1/control_change"
  set :ampcc, amp
end

live_loop :midi_piano do
  with_fx :compressor, amp: 0.5  do
    note, velocity = sync "/midi/reloop_keypad/9/1/note_on"
    ampCC = get :ampcc
    use_synth_defaults release: 2, cutoff: 1, attack: 1, amp: ampCC/127.0
    synth :saw, note: note, amp: velocity / 127.0
    play note
    play note + 50
  end
end

This way only the first loop will block waiting for new CC messages, and the second loop will only wait for key presses, but still get the latest ampCC via set/get.

1 Like