# Modifying FX outside live\_loop

**URL:** https://in-thread.sonic-pi.net/t/modifying-fx-outside-live-loop/6511
**Category:** Creations & Ideas
**Created:** [February 8, 2022, 4:30am UTC](https://in-thread.sonic-pi.net/t/modifying-fx-outside-live-loop/6511 "2022-02-08T04:30:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![thatkidnamedrox](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@thatkidnamedrox](https://in-thread.sonic-pi.net/u/thatkidnamedrox)
#### Post date: [February 8, 2022, 4:30am UTC](https://in-thread.sonic-pi.net/t/modifying-fx-outside-live-loop/6511/1 "2022-02-08T04:30:24Z")

</div>

Hey everyone! Wanted to share my workaround for dealing with FX defined outside live\_loops. Let me know what you think of this approach, would love to hear feedback!

Tackled this situation to save resources (e.g. not calling FX within live\_loop). What’s neat is that the loop will remain in time!

Ran into some issues with faster loops so made another modification.

```ruby
def live_fx (name, *args, &block)
  params, opts = split_params_and_merge_opts_array(*args)
  reset = opts.fetch(:reset, false)
  if !truthy?(reset)
    live_loop name, opts do
      block.()
    end
    return
  end
  in_thread sync: name do
    dur = block_duration do
      block.()
    end
    # allow time for loop register stop and start
    while dur < 2
      dur += block_duration do
        block.()
      end
    end
    live_loop name, opts do
      block.()
    end
  end
  live_loop name, opts do
    cue name
    stop
  end
end

##| Try this example code out by changing the mix parameter
##| Will reflect change in live loop if reset is set to true (false by default)
with_fx :distortion, distort: 0.9, mix: 0 do
  live_fx :foo, reset: true do
    sample :bd_haus, amp: 5
    sleep 1
  end
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: [February 14, 2022, 3:33am UTC](https://in-thread.sonic-pi.net/t/modifying-fx-outside-live-loop/6511/2 "2022-02-14T03:33:50Z")

</div>

@thatkidnamedrox this _is_ actually a pretty neat idea I think! even if it’s just a workaround 🙂@samaaron any thoughts?
