Midi sync vs. control

This is probably an easy beginner error.

This code works fine:

note = 0
use_synth :dsaw

live_loop :midi_piano do
  use_real_time
  note, velocity = sync "/midi:mio:0:1/note_on"
end

live_loop :midi_cc do
  use_real_time
  controller, value = sync "/midi:mio:0:1/control_change"
  play note, amp: value / 127.0 if controller == 2
end

But, this code doesn’t and I don’t understand why. The only difference is that it creates the play on the synth at the top as s, then uses control s to change the note and amp:

note = 0
use_synth :dsaw
s = play note, attack: 10, attack_level: 0

live_loop :midi_piano do
  use_real_time
  note, velocity = sync "/midi:mio:0:1/note_on"
end

live_loop :midi_cc do
  use_real_time
  controller, value = sync "/midi:mio:0:1/control_change"
  control s, note: note, amp: value / 127.0 if controller == 2
end

it seems a play is missing play note

I would tackle it like this:

use_synth :dsaw


with_fx :level,amp: 0 do |v|
  set :v,v
  live_loop :midi_piano do
    use_real_time
    note, velocity = sync "/midi*/note_on"
    play note, amp: velocity/127.0 if velocity > 0
  end
end

live_loop :controlVol do #control level of fx envelope
  use_real_time
  controller, value = sync "/midi*/control_change"
  control get(:v), amp: value/127.0 if controller==2
end

I’ve placed the live loop midi_piano inside an fx :level wrapper. The individual notes played in that live loop have their volume affectd in two ways. First the velocity with which the note is played on the keyboard, but secondly this is attenduated by the fx wrapper. The amp: setting of this is intially set to 0 and a reference to the =effect v is then stored in the time line using the command set :v,v
A second live loop controlVol is then used to retrieve the value from the midi cc control number 2 and this is used to control the amplitude of the fx :level wrapper. It retrieves the pointer to the fx wrapper using get(:v) and controls the setting of the amp: for the wrapper, acting as an overall volume control.

When you start playing you will hear nothing until you adjust midi control 2 to raise the wrapper amplitude setting. If you prefer, you can set the inital value of the wrapper volume to 1 or 0.5 in the line
with_fx :level, amp: 0 do |v| changing it to say
with_fx :level, amp: 0.5 do |v|

1 Like