The code below will work, but I find it very messy and difficult to adjust or see exactly what will happen. It seems to just have several different ideas randomly added on top of each other, although they will work together in a somewhat haphazard manner.
I assume the sample you want is the piece you posted to soundcloud. I managed to download it with the aid of a helper program, and the first thing I did was to convert it from mp3 to flac format as this is one that Sonic Pi can handle. (I used audacity to do this). I then placed it in a folder music in my downloads folder and hence it is accessed by index 0 in that folder (your setting was 2, but maybe you have other samples there as well).
I altered your loop that was inside an in_thread block to a live loop named live_loop :test By adding a sync command inside the loop it can be synced to live_loop :three. I placed it before the other live loops, so that it was running and waiting for this sync BEFORE live_loop three starts for the first time. That way it starts the first time live_loop :three starts. Live_loop :three has a duration of several seconds (a+s+r) on each pass, but this is quite a bit shorter that the downloaded sample duration, even though it is played at a higher rate and only with a finish 0.75 or three quarters of the way through. You will therefore get the sample overlaying several times. I have set the loop to print each time it runs a new iteration so you can visually see when this happens.
With the present synth (:tri) you won’t hear played midi notes very well, but I don’t know what your aim is here. You can here the various percussion loops playing though.
I have added a line use_debug false so that the log window is not so cluttered up.
I think that I have taken this as far as it can go at present. I suggest that you need to do some planning as to what you are eventually aiming at. Just adding further bits seemingly rather at random is unlikely to achieve a good result.
#7 use_debug false set_volume! 1 ##| Link to the samples folder: samples_dir = '~/Downloads/music' #i've changed this to suit my setup with_fx :reverb, room: 1 do with_fx :rbpf, res: 0, mix: 0.7 do with_fx :gverb, mix: 0.2, room: 10 do live_loop :test do #your loop changed to a live loop. Synced bynext line sync :three#syncved by live loop three. puts "loop test run ",tick #printed each time toe live loop starts #sample lenght is quite long so will not finish before next overlay starts sample samples_dir,0 , amp: 1.35, rate: 1.4, compress: 1, finish: 0.75, release: 2 end end end end n,v = sync "/midi*:1/note_on"#first midi note starts things going use_synth :tri #synth for midi input notes set :flag, false define :check_sample do |ns,bs| in_thread do sample ns,beat_stretch: bs,amp: 0.7 set :flag,true sleep bs set :flag,false end end live_loop :midi_in do use_real_time #n,v = sync "/midi*/note_on" n,v = sync "/midi*:1/note_on" if v > 0 play n,amp: v/127.0,release: 0.2 if get(:flag)==false #tick chooses sample in sequence from a ring, 8 is the beat_stretch number check_sample (ring :loop_garzul,:loop_mika,:loop_safari).tick,8 end end end mn=; for j in 1..1023 mn[j]=hz_to_midi(11*j) end; use_synth :hoover m=[3,6,9] nl=[24,30,36,48] # Ryhtm live_loop :one do a=choose(m); s=choose(m); r=choose(m) nv=choose(nl) play mn[nv], attack: a, sustain: s, release: r, amp: 0.6 print mn[nv], attack: a, sustain: s, release: r sleep a+s+r; end with_fx :reverb, room: 1 do with_fx :echo do live_loop :two do #use_synth :dark_ambience use_synth (ring :blade, :hollow, :hoover).tick a=choose(m); s=choose(m); r=choose(m) nv=choose(nl) play mn[nv], attack: a, sustain: s, release: r, amp: 0.75 sleep a+s+r; end end end live_loop :three do a=choose(m); s=choose(m); r=choose(m) #use_synth :prophet use_synth (ring :hoover, :hollow, :blade).tick nv=choose(nl) play mn[nv], attack: a, sustain: s, release: r, amp: 0.8 sleep a+s+r; end