Hi,
has anybody an idea, why the following code does not work? I have the expectation, that I
- get an initial volume of 2 for the sample playback
- can use the knob no. 16 to change the volume
This does work but in an odd way: I can change the volume dynamically but anytime I let go of the knob (no more midi data coming in) the volue switches back to some/the (??) default value. The puts
will reflect the correct value but not the actual audio. Am I making a silly mistake or is it my SP installation which plays tricks with me?
The code:
set :master_vol, 2
set :vol_track1, (1 * get(:master_vol))
# Calculate proper values for volume values
define :scale_vol do |v|
max = 1
a = max.to_f / 127 * v.to_f * get(:master_vol)
return a
end
live_loop :midi_knobs do
use_real_time
knob = sync "/midi/arturia_beatstep_midi_1/*/10/control_change" # insert your midi controller
# track VOLUME
if knob[0] == 16 # adjust the controller number to your setup
set :vol_track1, scale_vol(knob[1])
control get(:t1), amp: get(:vol_track1)
puts "===================================="
puts " Knob: #{get(:vol_track1)}"
puts "===================================="
end
end
live_loop :track1_playing do
s = sample :loop_amen, beat_stretch: 2, amp: get(:track1_vol)
puts "===================================="
puts "LL: #{get(:vol_track1)}"
puts "===================================="
set :t1, s
sleep 2
end