Hi Petr
I have done further work on improving things.
1 You get better response by using separate loops to detect push on and push off OSC messages
2 I had forgotten to add a use_real_time command. I have done so globally at the beginning
3 having used a copy and paste to set up the loops initially, I have now altered the timings in some of the loops to eliminate timing can’t keep up errors.
4 :kill6 and :kill7 are not required for the single sample play loops as no live loop to kill!
4 You can preload samples if you wish, but otherwise you may notice a slight delay the first time a new one is used. However now it shouldn’t affect the correct operation by doubling up the playing of samples.
The new updated program is below
use_real_time
use_bpm 120
path="~/Desktop/samples/"
#initialise c variables
set:c1,0;set:c2,0;set:c3,0;set:c4,0;set:c5,0;set:c6,0;set:c7,0;
#input on and off live_loops to detect inputs
live_loop :p1on do
b = sync "/osc/1/push1"
if b[0]==1
set :c1,1
doLoopAmen
end
end
live_loop :p1off do
b = sync "/osc/1/push1"
set :c1,0 if b[0]==0
end
live_loop :p2on do
b = sync "/osc/1/push2"
if b[0]==1
set :c2,1
doLoopGarzul
end
end
live_loop :p2off do
b = sync "/osc/1/push2"
set :c2,0 if b[0]==0
end
live_loop :p3 do
b = sync "/osc/1/push3"
if b[0]==1
set :c3,1
doLoopCompus
end
end
live_loop :p3off do
b = sync "/osc/1/push3"
set :c3,0 if b[0]==0
end
live_loop :p4on do
b = sync "/osc/1/push4"
if b[0]==1
set :c4,1
doLoopLongNote
end
end
live_loop :p4off do
b = sync "/osc/1/push4"
set :c4,0 if b[0]==0
end
live_loop :p5on do
b = sync "/osc/1/push5"
if b[0]==1
set :c5,b[0]
doLoopSequence
end
end
live_loop :p5off do
b = sync "/osc/1/push5"
set :c5,0 if b[0]==0
end
live_loop :p6on do
b = sync "/osc/1/push6"
if b[0]==1
set :c6,1
doSingleSample
end
end
live_loop :p6off do
b = sync "/osc/1/push6"
set :c6,0 if b[0]==0
end
live_loop :p7on do
b = sync "/osc/1/push7"
if b[0]==1
set :c7,1
doVoiceSample
end
end
live_loop :p7off do
b = sync "/osc/1/push7"
set :c7,0 if b[0]==0
end
live_loop :metro do #metronome to sync stuff together
sleep 1
end
define :doLoopAmen do
set :kill1,false
live_loop :controlLoopAmen,sync: :metro do
s1=sample :loop_amen,beat_stretch: 4,amp: 2
in_thread do #in a thread poll for button up cue (:C1=>0)
loop do
if get(:c1)==0 #if button up cue then
kill s1 #kill the sample
set :kill1,true #set kill1 flag true
stop # quit loop
end
sleep 0.1 #time between checks for button up cue
end
end
40.times do # split sleep time to insert poll for kill1
sleep 4/ 40.0
stop if get(:kill1)
end
end #of live loop
end #of function
define :doLoopGarzul do
set :kill2,false
live_loop :controlLoopGarzul,sync: :metro do
s2=sample :loop_garzul
in_thread do
loop do
if get(:c2)==0
kill s2
set :kill2,true
stop
end
sleep 0.1
end
end
40.times do #do this to get a quicker response time
sleep (sample_duration :loop_garzul) / 40.0
stop if get(:kill2)
end
end
end
define :doLoopCompus do
set :kill3,false
live_loop :controlLoopCompus,sync: :metro do
s3=sample :loop_compus,beat_stretch: 8,amp: 2
in_thread do
loop do
if get(:c3)==0
kill s3
set :kill3,true
stop
end
sleep 0.1
end
end
40.times do #do this to get a quicker response time
sleep 8 / 40.0
stop if get(:kill3)
end
end
end
define :doLoopLongNote do #repeats a long note wile the button is pushed
set :kill4,false
live_loop :controlLongNote,sync: :metro do
s4=play :c4,sustain: 3,release: 1
in_thread do
loop do
if get(:c4)==0
kill s4
set :kill4,true
stop
end
sleep 0.1
end
end
40.times do #do this to get a quicker response time
sleep 4 / 40.0
stop if get(:kill4)
end
end
end
define :doLoopSequence do #plays a sequence of notes while the button is pushed
set :kill5,false
live_loop :controlSequence,sync: :metro do
use_synth :tb303
in_thread do
loop do
if get(:c5)==0
set :kill5,true
stop
end
sleep 0.1
end
end
12.times do
play scale(:c3,:minor_pentatonic,num_octaves: 2).choose,release: 0.25,amp: 0.5,cutoff: rrand_i(60,120)
10.times do #do this to get a quicker response time
sleep 0.25 / 10
stop if get(:kill5)
end
end
end
end
define :doSingleSample do #plays a single sample once when button pushed
sync :metro
s6=sample :loop_amen_full,beat_stretch: 16
in_thread do
loop do
if get(:c6)==0
kill s6
stop
end
sleep 0.1
end
end
end
define :doVoiceSample do #plays a voice sample once when button is pushed
sync :metro
s7=sample path,"testsample.flac",amp: 2 #use your own voice sample here
in_thread do
loop do
if get(:c7)==0
kill s7
stop
end
sleep 0.1
end
end
end
live_loop :alwaysplaying,sync: :metro do #runs continuously playing
use_synth :fm
play :c2,release: 1,amp: 4
play :c3,release: 2,amp: 0.2
sleep 2
play :c2,release: 2,amp: 4
sleep 2
end