# Solved by now, ty all

**URL:** <https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628>\
**Category:** Support, Help & Resources\
**Created:** [November 17, 2020, 12:45am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628 "2020-11-17T00:45:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 17, 2020, 12:45am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/1 "2020-11-17T00:45:19Z")

</div>

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:

```ruby
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^^#

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [November 17, 2020, 1:51am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/2 "2020-11-17T01:51:21Z")

</div>

Hi @holz,

First things first - It would be super helpful to format the code blocks so that they are more readable 😄  
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 🙂

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 17, 2020, 2:11am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/3 "2020-11-17T02:11:11Z")

</div>

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

 ![Unbenannt](https://europe1.discourse-cdn.com/flex017/uploads/sonic_pi/original/2X/9/9a80122abe861cabf0b3b1ebf22788ec84ed47b6.png)

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [November 17, 2020, 2:20am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/4 "2020-11-17T02:20:48Z")

</div>

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](https://in-thread.sonic-pi.net/t/read-first-welcome-to-the-sonic-pi-community/8) if you need further clarification 🙂

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [November 17, 2020, 8:16am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/6 "2020-11-17T08:16:19Z")

</div>

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.

```ruby
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

```

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 17, 2020, 9:20am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/7 "2020-11-17T09:20:39Z")

</div>

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

```ruby
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

```

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 17, 2020, 10:01am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/8 "2020-11-17T10:01:01Z")

</div>

Here comes the next Problem 😜

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 ☹

```ruby
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
```

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [November 17, 2020, 10:18am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/9 "2020-11-17T10:18:37Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 17, 2020, 10:34am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/10 "2020-11-17T10:34:13Z")

</div>

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)

```ruby
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

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [November 17, 2020, 10:40am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/11 "2020-11-17T10:40:58Z")

</div>

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:)

```ruby
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:

```ruby
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.

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [November 17, 2020, 11:02am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/12 "2020-11-17T11:02:59Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 17, 2020, 11:40am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/13 "2020-11-17T11:40:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [November 17, 2020, 12:01pm UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/14 "2020-11-17T12:01:13Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 17, 2020, 12:56pm UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/15 "2020-11-17T12:56:02Z")

</div>

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.

```ruby
#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
´´´
```

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [November 17, 2020, 1:32pm UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/16 "2020-11-17T13:32:11Z")

</div>

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

```ruby
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
``
```

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [November 17, 2020, 1:36pm UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/17 "2020-11-17T13:36:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![emlyn](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/emlyn/32/1460_2.png) [@emlyn](https://in-thread.sonic-pi.net/u/emlyn)\
**Post date:** [November 17, 2020, 4:06pm UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/18 "2020-11-17T16:06:45Z")

</div>

You can also do:

```ruby
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.

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 17, 2020, 6:02pm UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/19 "2020-11-17T18:02:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![soxsa](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/soxsa/32/1669_2.png) [@soxsa](https://in-thread.sonic-pi.net/u/soxsa)\
**Post date:** [November 17, 2020, 6:32pm UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/21 "2020-11-17T18:32:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![holz](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/holz/32/1664_2.png) [@holz](https://in-thread.sonic-pi.net/u/holz)\
**Post date:** [November 18, 2020, 7:35am UTC](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/22 "2020-11-18T07:35:09Z")

</div>

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?

```ruby
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

```

[Next page](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628.md?page=2)
