Hi to all,
this is a more conceptual question concerning good (or at least decent) coding qualitites once you leave the mere area of spaghetti code (albeit within Sonic Pi). I do have a code example but nothing to really try out because the whole script is much bigger and I do not expect anyone to test my home-made software (as long as its not really running).
As I am trying to adapt my Live Looper to the Arturia Beatstep I also planed to go over it to make slimmer and better maintainable. I have e. g. several midi pads and knobs to watch, which I already managed to do in more efficient way.
Also I have to create several live_loop
s on the fly. The following example shows the playback live_loop
for track1 (and I have 4 tracks to cover):
live_loop :play1 do
on get(:arm_track1) do
cue :rec
end
on get(:play_track1) do
time_warp get(:time_fix_play) do
s = sample t1, amp: get(:vol_track1), hpf: get(:hpf_track1), lpf: get(:lpf_track1)
set :t1, s
#end
end # time_warp
end
sleep get(:len_track1)
end
So I thought I could create a function, which I can be called in 4.times
to create 4 playback live_loops
.
# get symbol pointers consisting of keyword and track index
define :get_pointer do | prefix, index |
s = (prefix + index.to_s).to_sym
end
t1 = buffer[:track1, get(:len_track1)]
t2 = buffer[:track2, get(:len_track2)]
define :create_playback_loop do | buffer, index |
live_loop get_pointer("play", index) do
on get(get_pointer("arm_track", index)) do
cue :rec
end
on get(get_pointer("play_track", index)) do
time_warp get(:time_fix_play) do
#with_fx :sound_out_stereo, output: 3 do
s = sample buffer, amp: get(get_pointer("vol_track", index)), hpf: get(get_pointer("hpf_track", index)), lpf: get(get_pointer("lpf_track", index))
set get_pointer("t", index), s
#end
end # time_warp
end
sleep get(get_pointer("len_track", index))
end
end
# Create the play back live_loops
# Could later be done with a loop
create_playback_loop(t1, 1)
create_playback_loop(t2, 2)
The code runs (no syntax or run_time error) but it does not work as expected. I do have not the slightest idea what’s going wrong but I suspect there might be a very basic design flaw in it. So my hope is that someone more proficient as me could be able to hint me into the right direction or confirm that this basically is a valid approach (and I have to look for the reason it does not work as expected elsewhere).
Cheers,
Martin