Solved by now, ty all

Hey guys,
i had some sleepless nights to learn sonic pi, but i kind of hit a wall here.
I am pretty sure its the last step for my idea to become reality.

I build a sample slicer, a bit different from the instructions but it works like a charm.
the only Problem i have is, i can´t control the with_fx because it would alter the sleep time.

That´s where i am actually stuck:

a = (ring  0.5,    0.5,    0.9,   0).tick  #sequencer
b = (ring   0.6,    0.2,    1,   0.2).tick


define :sampleslicer do
  live_loop :möp do
  
   sample "C:/xxx.wav" , start: a, finish: b, rate: 0.9, amp: 5 
    sleep sample_duration "C:/xxxwav", start: a, finish: b
   
  end
end


live_loop :lol1 do
  with_fx :slicer, phase: 0.125, pulse_width: 0.8 do |e|
    
   sampleslicer
    
    sleep 1
    control e, phase: 0.125, pulse_width: 0.8
    sleep 1
    control e, phase: 0.125, pulse_width: 0.1
    sleep 1
    control e, phase: 0.2, pulse_width: 0.5
    sleep 1
    
  end
end

So how do i use and control for example the with_fx :slicer on that?

and the fx should repeat itself.

i tried so much and nothing worked except defining the sample slicer and then using the defined function with_fx, but it doesnt repeat, its stuck at the last step, for example phase: 0.2, pulse_width: 0.5 in this case.

pleeeease help me i neeeed that to work

THANKS GUYS <3 and aaron if u solve that for me i will donate for ya^^#

1 Like

Hi @holz,

First things first - It would be super helpful to format the code blocks so that they are more readable :smile:
Can you place an extra line before and after each code block, and insert three backticks ` on these lines?
It’d be much easier to understand what’s going on in your code once that’s done :slight_smile:

thanks for your reply!
I made a screenshot, i hope that helps, if not let me know.

That’s one way - what I was referring to was editing your post above, and inserting the three backticks on lines before and after each code block. See ‘Code blocks’ in Read First - Welcome To The Sonic Pi Community if you need further clarification :slight_smile:

This is the kind of thing I’ve been using to control fx. If I understand you correctly, you want bits of the sample to play linked end-to-end in a continuous loop (not in any particular time, as the durations vary not to a regular pattern). Then control the slicer on a sequenced basis.

The idea is to put the fx outside the loop, so only one is ever created. Then first time through, save a reference to the fx, using set. Then the control loop can pick up the reference with a get.

At the moment the sample loop is free running, but you could equally sync it to the control loop for a more regular sound if you wanted.

See what you think.

with_fx :slicer, phase: 0.125, pulse_width: 0.8 do |e|
  
  #Loop playing different bits of the sample, end to end.
  live_loop :play do
    
    #First time through, save a ref to the slicer fx
    if tick(:firsttime) == 0 then
      set :e, e
    end
    
    a = (ring  0.5,    0.5,    0.9,   0).tick  #sequencer
    b = (ring   0.6,    0.2,    1,   0.2).look
    
    s="C:/Users/guy/Music/Samples/Frank Bridge/Frank Bridge 1.wav"
    sample s, start: a, finish: b, rate: 0.9, amp: 1
    sleep sample_duration s, start: a, finish: b, rate: 0.9
    
  end
end

#Control the slicer.
live_loop :control do
  n = 1
  
  #Get the fx to control
  e = get[:e]
  p = (ring 0.125, 0.5, 0.2)
  w = (ring 0.8,   0.1, 0.5)
  
  3.times do
    #sample :perc_bell, amp: 0.5
    control e, phase: p.tick, pulse_width: w.look
    sleep n
  end
end

Hi thanks dude u just solved my problem, i tweaked it till i got the result i wanted, like that i can control the fx independently from the sample slices.
HUGE kiss xD

with_fx :slicer, phase_slide: 0.5, phase: 0.125, pulse_width: 0.8 do |e|
  
  live_loop :löl do
    
    if tick(:firsttime) == 0 then
      set :e, e
    end
    
    
    a = (ring  0.5,    0.5,    0.9,   0).tick  #sequencer
    b = (ring   0.6,    0.2,    1,   0.2).look
    
    s="C:/Users/marce/Desktop/samps1/dum1.wav"
    sample s, start: a, finish: b, rate: 0.9, amp: 1
    sleep sample_duration s, start: a, finish: b, rate: 0.9
    
  end
end



live_loop :klo do
  e = get[:e]
  sleep 1
  control e, phase: 0.5, pulse_width: 0.8
  sleep 5
  control e, phase: 0.5, pulse_width: 0.8
  sleep 1
  control e, phase: 0.125, pulse_width: 0.125
  sleep 5
end

Here comes the next Problem :stuck_out_tongue_winking_eye:

I want to control the sample so i can slide parameters of the sample.
with amp = sync :ampi
and set :ampi, 0
but like that i can´t slide :frowning:

with_fx :slicer, phase_slide: 0.5, phase: 0.125, pulse_width: 0.8, pulse_width_slide: 0.125 do |e|
  
  if tick(:firsttime) == 0 then
    set :e, e
  end
  
  live_loop :löl do
    
    a = (ring  0.5,    0.5,    0.9,   0).tick  #sequencer
    b = (ring   0.6,    0.2,    1,   0.2).look
    
      amp = sync :ampi
    
       s = sample :loop_amen, start: a, finish: b, rate: 0.9, amp: amp
    sleep sample_duration :loop_amen, start: a, finish: b, rate: 0.9
    
     if tick(:firsttime) == 0 then
      set :a, a
    end
   
  end
end


# sample control ?? slide ??

live_loop :wut do
  a = get[:a]
  set :ampi, 1
  sleep 0.5
  set :ampi, 0
  sleep 0.5
end


#fx control

live_loop :klo do
  e = get[:e]
  sleep 1
  control e, phase: 0.5, pulse_width: 0.8
  sleep 5
  control e, phase: 0.5, pulse_width: 0.8
  sleep 1
  control e, phase: 0.125, pulse_width: 0.125
  sleep 5
end

@holz - are you aware of the _slide opts available to the sample command? you can use these to introduce sliding while using control.
See the Samples help category for details of all slidable sample opts - each is marked with a label indicating it has sliding ability if it is capable.

Well i am not sure i know what u mean.

i know this for example: (but it doesn´t work with the code above beacuse it would add sleep time and break the purpose of the thread)

live_loop :möp do
s = play 50, amp_slide 1, amp: 1
sleep 1
control s , amp: 0
end

in other words,
how do i control the sample with timed slide options without changing the time of the thread

Sure. Actually, looking at your other post about this, it is pretty close.
Here’s what you had there (basically - with a few syntax corrections:)

live_loop :möp do
s = sample :loop_amen, amp_slide: 1
sleep 3
end

sleep 1
control s, amp: 0

This does not work because the reference to s is local to the live_loop - so code outside does not know about it.

You can modify it to work by storing/accessing this reference in the global time-state store using set and get, so that it is visible outside the live_loop:

live_loop :möp do
  s = sample :loop_amen, amp_slide: 1
  set(:s, s)
  sleep 3
end

sleep 1
control get(:s), amp: 0

This slides as expected.

1 Like

That’s great. It’s a good sound I like it.

BTW that pattern is easier on your CPU too, as it’s not creating a new effect each time through the loop. (sorry, referring to the OP bit)

yeah thanks,
i am really pleased with sonic pi, nothing seems to be like what i need for my musical vision except sonic pi.
there is only one step left for my sample machine to me perfect, wich is the option to randomise start and finish points, but they need to stay in relation to each other.

Just adding that you don’t need to move the control out of the live_loop if you prefer to keep them together. You can use a time_warp instead of a sleep to temporarily jump into the future and do the control without affecting the timing, like this:

live_loop :möp do
  s = sample :loop_amen, amp_slide: 1
  time_warp 1 do
    control s, amp: 0
  end
  sleep 3
end
2 Likes

WOW this is siiiiiick, thanks to all of u!!!
Only thing i need to add is a randomizer for the start and finish points. but the finish needs to make sense in relation to the start.

#define :klop do

with_fx :slicer, phase_slide: 0.5, phase: 0.125, pulse_width: 0.8, pulse_width_slide: 0.125 do |slice|
  
  set :slice, slice
  
 
  live_loop :löl do
    
    a = (ring  0.5,    0.5,    0.9,   0).tick  #sequencer
    b = (ring   0.6,    0.2,    1,   0.2).tick
    
    samp2 = sample :loop_amen, start: a, finish: b, rate: 0.9, amp: 1, amp_slide: 2
    
set :samp2, samp2
    
    sleep sample_duration :loop_amen, start: a, finish: b, rate: 0.9
     
    end
end


live_loop :samp1 do
  
  sleep 2
  control get[:samp2], pitch: 23
  sleep 2
  control get[:samp2], pitch: -23
  
end


live_loop :slice1 do
  slice = get[:slice]
  sleep 1
  control slice, phase: 0.125, pulse_width: 0.125
  sleep 5
  control slice, phase: 0.125, pulse_width: 0.125
  sleep 1
  control slice, phase: 0.125, pulse_width: 0.125
  sleep 5

end

#end
´´´
1 Like

I think you can do that a different way too, with in_thread. I’ve been using that a lot to kick off free-running segments within in a loop, without affecting the overall timing of the loop

live_loop :möp do
  s = sample :loop_amen, amp_slide: 1
  in_thread do
    sleep 1
    control s, amp: 0
  end
  sleep 3
end
``

This is a great effect @holz definitely going to use this idea

You can also do:

live_loop :möp do
  s = sample :loop_amen, amp_slide: 1
  at 1 do
    control s, amp: 0
  end
  sleep 3
end

which is like in_thread with the sleep built in.

Both in_thread and at run the code in a separate thread, so you can do things like use_bpm or use_synth in there as well as adding sleeps and it won’t affect the surrounding code.

1 Like

Oops ignore this , i already figured it out and forgot about it lol

Nice one @emlyn, I like that. I’d passed over at but that looks super useful. Thanks!

…esp called with a list of times, that’s good

1 Like

Hi, i discovered a little “bug” if u will.
Everytime the
control get(:s), amp: 0
sleeps, it jumps back to the sample amp which is 1.
how can i avoid this so only the values in the live loop which controls the amp is put out?

live_loop :lol do
  
  a = (ring  0.5,    0.5,    0.9,   0).tick  #sequencer
  b = (ring   0.6,    0.2,    1,   0.2).tick
  
 s = sample :loop_amen, start: a, finish: b, rate: 0.9, amp: 1, amp_slide: 0.3, pitch_slide: 1
  
 set(:s, s)
  
sleep sample_duration :loop_amen, start: a, finish: b, rate: 0.9
 
  end


live_loop :sampiii do
  sleep 1
  control get(:s), amp: 0
  sleep 1
  control get(:s), amp: 0
  sleep 1
  control get(:s), amp:  
  sleep 1
  
end