Setting playback parameters via Midi


#1

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


Smooth Parameter Automation
#2

Hi Martin
Problem is you used :vol_track1 in midi_knobs loop but get(:track1_vol) in the second loop. Make them the same and it works fine!


#3

Oh, no!! (That’s embarrasing.). Checked several times but obviously didn’t see it. Thanks!

Martin


#4

Easily done. I can remember several occasions when I’ve stared at some code for ages and missed something like this! Then you kick yourself when you realise what’s wrong. Doing what you did helps. A fresh pair of eyes can spot it.


#5

Yes, definitely. I did some ‘refactoring’ involving the renaming of variables. Always an adventure if you miss some because not using find and replace… :wink: