# Dynamic FX for live loop

**URL:** <https://in-thread.sonic-pi.net/t/dynamic-fx-for-live-loop/5046>\
**Category:** Support, Help & Resources\
**Created:** [January 25, 2021, 8:10pm UTC](https://in-thread.sonic-pi.net/t/dynamic-fx-for-live-loop/5046 "2021-01-25T20:10:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xorik](https://avatars.discourse-cdn.com/v4/letter/x/8dc957/32.png) [@xorik](https://in-thread.sonic-pi.net/u/xorik)\
**Post date:** [January 25, 2021, 8:10pm UTC](https://in-thread.sonic-pi.net/t/dynamic-fx-for-live-loop/5046/1 "2021-01-25T20:10:22Z")

</div>

Hi,  
I wonder if there is any way to dynamically add fx for playing `live_loop`. I know that I can add `with_fx` inside a `live_loop` but it have 2 problems:

- It creates a new fx on each cycle, so wasting of resources
- If my live\_loop is listening for midi events, it won’t work properly with some FX, like flanger, because it will create a new FX for each note.

So only way is to create a bunch of nested `with_fx` sections with `mix: 0`, and toggle them later with the `control` method. But I don’t like it, and I think it will consume resources even with `mix: 0` (not sure about that).

Is there any better solution? Basically I want dynamically enable/disable and chain effects without stopping live loops.

---

<div class="post-metadata">

**Author:** ![xorik](https://avatars.discourse-cdn.com/v4/letter/x/8dc957/32.png) [@xorik](https://in-thread.sonic-pi.net/u/xorik)\
**Post date:** [January 30, 2021, 9:26pm UTC](https://in-thread.sonic-pi.net/t/dynamic-fx-for-live-loop/5046/2 "2021-01-30T21:26:40Z")

</div>

If anyone is interested:  
I did some research and found, that I can save `live_loop` in a variable, and later kill it and immediately recreate, even if it’s waiting for sync or MIDI event.

Saving is a bit tricky, because I can’t use `set`, so I have to make something like that:

```ruby
if get[:init] == nil
  thread = nil
  
  define :save_thread do |t|
    thread = t
  end
  
  define :kill_thread do
    thread.kill if thread != nil
  end
  
  set :init, true
end

```

With these 2 methods I can save live loops like that:

```ruby
x = live_loop :test do
...
end

save_thread x

```

But another issue is that after killing, I need to change thread name, because sonic pi is thinking that it still alive for some reason.

Not a perfect solution, but will work for me.
