I improved the parameter list for fadeControl to use start and finish, which makes it more logical when entering the data. So you get
fadeControl(1,0.5,2,:down)
for example, which fades down from 1 to 0.5 in 2 seconds
and fadeControl(0.3,0.8,4,:up)
which fades up from 0.3 to 0.8 in 4 seconds
The adjusted programs are below
define :fade do |min, max, len, type|
case type
when :up
b = (line min, max, steps: len, inclusive: true).stretch(2).drop(1).butlast.ramp
when :down
b = (line min, max, steps: len, inclusive: true).stretch(2).drop(1).butlast.reverse.ramp
when :wave
b = (line min, max, steps: len, inclusive: true).stretch(2).drop(1).butlast.mirror
end
end
define :fadeControl do |start,finish,duration,type|
if type==:down
min=finish
max=start
else
min=start
max=finish
end
l=fade min,max,11,type #11 ensures 20 steps for each up/down, 40 for wave
if type==:wave
dt=duration/40.0 #adjust step interval to give correct total time
else
dt=duration/20.0
end
#puts l.length,type #uncomment for debugging to check number of steps
puts "fadeControl #{start} #{finish} #{duration} #{type}"
in_thread do
t=vt
tick_reset
l.length.times do
control get(:lv),amp: l.tick,amp_slide: dt
sleep dt
end
end
end
with_fx :level,amp: 0 do |lv|
set :lv,lv
live_loop :test do
sample :loop_amen_full,beat_stretch: 8
fadeControl(0,1,2,:up) #fade up from 0 to 1 in 2 seconds
sleep 2
fadeControl(1,0.3,1,:down) #fade down from 1 to 0.3 in 1 second
sleep 2
fadeControl(0.3,1,1,:wave) #fade up and down from 0.3->1-> 0in 1 second
sleep 2
fadeControl(0.3,0,1,:down) #fade down from 0.3 to 0 in 1 second
sleep 2 #there will be 1 second of silence here
sample :loop_amen_full,beat_stretch: 8 #start another sample to give 16 second loop
fadeControl(0,0.4,8,:wave) #fade up and down from 0->0.4->0 in 8 seconds
sleep 8
end
end
ADDENDUM EDIT
Finally (!!)
here is a much more compact way of writing the live loop above, making use of the at command. It is shown below with the fx wrapper.
The remainder of the program in my previous post remains the same.
Here is a much more compact version of the live loop using the at command. This replaces the live_loop :test and fx wrapper above. The remainder remains as it is.
with_fx :level,amp: 0 do |lv|
set :lv,lv
live_loop :test do
at [0,2,4,6,8],[[0,1,2,:up],[1,0.3,1,:down],[0.3,1,1,:wave],[0.3,0,1,:down],[0,0.4,8,:wave]]do |param|
fadeControl param[0],param[1],param[2],param[3]
end
sample :loop_amen_full,beat_stretch: 8
sleep 8
sample :loop_amen_full,beat_stretch: 8
sleep 8
end
end