# Live loops inside of FX, with control capabilities

**URL:** <https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269>\
**Category:** Support, Help & Resources\
**Created:** [April 17, 2019, 6:04pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269 "2019-04-17T18:04:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwalchuk](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@lwalchuk](https://in-thread.sonic-pi.net/u/lwalchuk)\
**Post date:** [April 17, 2019, 6:04pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/1 "2019-04-17T18:04:25Z")

</div>

Hi all! I’m having some trouble with using effects and live loops. I want to be able to put live loops inside of effects and control them externally, but am running into some problems. I’ll try to articulate each of my specific issues as clearly as possible.

In my first example, when I run the code it starts with the default values for the reverb, as I have not specified any opts. When I make a change in the second thread using the control command, it will make the change the first time I re-run. However, if I try to change it again, it doesn’t work.

```ruby
use_bpm 100

in_thread do
  with_fx :reverb do |f|
    set :f, f
    live_loop :sample do
      sample :loop_amen, beat_stretch: 4
      sleep 4
    end
  end
end

in_thread do
  fx = get[:f]
  control fx, room: 0.4, mix: 0
end

```

I solved this problem by naming the thread with the effects:

```ruby
use_bpm 100

in_thread(name: :effect) do
  with_fx :reverb do |f|
    set :f, f
    live_loop :sample do
      sample :loop_amen, beat_stretch: 4
      sleep 4
    end
  end
end

in_thread do
  fx = get[:f]
  control fx, room: 0.4, mix: 0
end

```

I can now change the control values to my heart’s content. However, now that I’ve done this, I am unable to update the live loop inside the effect. Any change I make, for example, to the rate of the sample does not take effect when I re-run.

I want the live loop to be inside the effects for two reasons. First, I want to conserve as much processor power as I can. Second, and more importantly, if the effect is inside the live loop I can no longer use the external thread to control its parameters, because the effect resets to its initial parameters every loop.

Can someone offer some insight into why I lose the ability to update the live loop inside of a named thread? Possible solutions?

Thanks!

-Luke

---

<div class="post-metadata">

**Author:** ![Davids-Music-Lab](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/davids-music-lab/32/512_2.png) [@Davids-Music-Lab](https://in-thread.sonic-pi.net/u/Davids-Music-Lab)\
**Post date:** [April 18, 2019, 7:56pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/2 "2019-04-18T19:56:39Z")

</div>

This is a namespace problem. (Edit: it’s not, I didn’t look at the problem properly.)

Put the block that controls the effect inside the effect itself: (Edit: this works anyway.)

```
use_bpm 100

#cue 'up'

with_fx :reverb do |f|
  live_loop :sample do
    sample :loop_amen, beat_stretch: 4
    sleep 2
  end
  
  live_loop :control do
    sync 'up'
    control f, room: (line 0.1,0.8).choose
  end
end

```

You can run the control loop as a sort of LFO or on cues.

---

<div class="post-metadata">

**Author:** ![lwalchuk](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@lwalchuk](https://in-thread.sonic-pi.net/u/lwalchuk)\
**Post date:** [April 18, 2019, 8:01pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/3 "2019-04-18T20:01:20Z")

</div>

Shouldn’t using set and get circumvent the namespace problem?

---

<div class="post-metadata">

**Author:** ![Davids-Music-Lab](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/davids-music-lab/32/512_2.png) [@Davids-Music-Lab](https://in-thread.sonic-pi.net/u/Davids-Music-Lab)\
**Post date:** [April 18, 2019, 8:22pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/4 "2019-04-18T20:22:17Z")

</div>

You’re right, it should.

My first answer is just what I would do to fix it, I didn’t look at the problem.  
I did that now:

Having the first loop in an in\_thread block means every time you run the code, a new effect is made, and it’s pointer set to the timestate.  
When you look at the cues, you see that the set/f uses a different id every time.  
The sample loop however is not recreated, it still is inside the original effect block.

I usually avoid using in\_thread together with live\_loops.

---

<div class="post-metadata">

**Author:** ![lwalchuk](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@lwalchuk](https://in-thread.sonic-pi.net/u/lwalchuk)\
**Post date:** [April 18, 2019, 8:28pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/5 "2019-04-18T20:28:00Z")

</div>

Ok, that makes sense. This actually does solve my problem, as it allows me to put several dynamic things inside of a single effect (essentially using it as an effects rack) and still change the effects using control messages. Thanks!

In regards to the in\_thread block creating a new effect every time, I’m trying to wrap my head around the difference in behavior between a named in\_thread block and a non-named one. Why is it that when the block is not named, I am able to update the live loop inside of it, but when it is named I can’t?

---

<div class="post-metadata">

**Author:** ![lwalchuk](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@lwalchuk](https://in-thread.sonic-pi.net/u/lwalchuk)\
**Post date:** [April 18, 2019, 8:52pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/6 "2019-04-18T20:52:16Z")

</div>

Also, I’m not sure why, but I just tried out your example and it didn’t work for me.

---

<div class="post-metadata">

**Author:** ![Davids-Music-Lab](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/davids-music-lab/32/512_2.png) [@Davids-Music-Lab](https://in-thread.sonic-pi.net/u/Davids-Music-Lab)\
**Post date:** [April 19, 2019, 12:01pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/7 "2019-04-19T12:01:20Z")

</div>

> [@lwalchuk](#):
>
> Why is it that when the block is not named, I am able to update the live loop inside of it, but when it is named I can’t?

It would make sense if it was the other way round, with a named thread not being updated.

Did you uncomment the cue in my example?

---

<div class="post-metadata">

**Author:** ![mobius927](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@mobius927](https://in-thread.sonic-pi.net/u/mobius927)\
**Post date:** [November 11, 2021, 2:48pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/8 "2021-11-11T14:48:59Z")

</div>

Sorry to bump an old topic, but I am running into this same problem today, both on a mac, v3.3.1 and linux v4.0 beta. Using a fairly obvious effect like slicer:

```ruby
#cue 'up'

with_fx :slicer do |sc|
  live_loop :foo do
    play 50
    sleep 2
  end
  
  live_loop :control do
    sync 'up'
    control sc, phase: 0.1
  end
end

```

Uncommenting the cue the first time updates the slicer phase as expected – you’ll hear the slicing effect increase in speed. But then update the phase to something like 0.5 and run the code again, e.g.,

```ruby
cue 'up'

with_fx :slicer do |sc|
  live_loop :foo do
    play 50
    sleep 2
  end

  live_loop :control do
    sync 'up'
    control sc, phase: 0.5
  end
end

```

and nothing seems to happen to the slicer effect – it continues at the faster speed. I’ve tried both with cue commented first, and then uncommenting as well as just leaving cue uncommented. Any idea what’s going on, or is there a different way we need to be controlling FX?

---

<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 11, 2021, 3:10pm UTC](https://in-thread.sonic-pi.net/t/live-loops-inside-of-fx-with-control-capabilities/2269/9 "2021-11-11T15:10:59Z")

</div>

Hi Mobius 🙂

In fact, this is by design (as far as Sam originally way back when being unable to find a simple, quick and easy way to enable live updating fx that wrap around live\_loops). However, we are interested in changing this some time in the future (it’s [on our wishlist](https://github.com/orgs/sonic-pi-net/projects/1#card-41252705)) if our priorities and resources fit 🙂

See the following for a discussion around this behaviour:

> <https://github.com/sonic-pi-net/sonic-pi/issues/794>
>
> \*\*Affected version:\*\* Sonic Pi v2.8.0-dev-a3737, running on Arch Linux (x64)
> 
> I… can't tell if this is intended behaviour, but when i try to wrap some effects around a 
> \_live\_loop\_, change some parameters, and re-run the buffer (that is, without completely stopping in between), the effects aren't reacting to the change. 
> 
> Example:
> 
> \`\`\` ruby
> with\_fx :bitcrusher, bits: 12 do
> live\_loop :foo do
> play 70
> sleep 0.5
> end
> end
> \`\`\`
> 
> If i want to change the bitrate here, i have to stop the run first (using \_Stop\_ or \_Alt-R\_), then start it again. Otherwise, there'll be no change at all ... 
> 
> It works fine if the effect is specified \_within\_ the live loop. It also works using a "normal" \_loop\_, instead of a \_live\_loop\_.

As for how you can otherwise automate fx from outside, the usual solution involves moving the fx inside the live\_loop, and then using variables to give the fx their values. One way to do this is to use `set` and `get` to transfer your desired fx values via the Time-State memory store. @robin.newman shows an example here:

> [@FX Automation (reverb, echo etc)](https://in-thread.sonic-pi.net/t/fx-automation-reverb-echo-etc/1680):
>
> How to automate phase parameter ? live\_loop :foo do with\_fx :echo, phase: 0.2 do use\_synth :blade play 60, release: 0.1 sleep 1 end end

(See the Tutorial or the Lang section of the Help panel in the app for more details of `set` and `get` if you need 🙂)

> **[Sonic Pi - Tutorial](https://sonic-pi.net/tutorial.html#section-10-1)**
>
> Sonic Pi Tutorial - Learn how to code music.
