# Snake Jazz - also is there an fx stack?

**URL:** <https://in-thread.sonic-pi.net/t/snake-jazz-also-is-there-an-fx-stack/5932>\
**Category:** Creations & Ideas\
**Created:** [September 7, 2021, 1:00pm UTC](https://in-thread.sonic-pi.net/t/snake-jazz-also-is-there-an-fx-stack/5932 "2021-09-07T13:00:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![datashaman](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/datashaman/32/2091_2.png) [@datashaman](https://in-thread.sonic-pi.net/u/datashaman)\
**Post date:** [September 7, 2021, 1:00pm UTC](https://in-thread.sonic-pi.net/t/snake-jazz-also-is-there-an-fx-stack/5932/1 "2021-09-07T13:00:16Z")

</div>

My first creation. 🏆

As in title: is there an FX stack so I don’t have to have this nested structure?

```ruby
live_loop :snake_jazz do
  with_fx :compressor do
    with_fx :flanger, mix: rrand(0, 0.2) do
      with_fx :reverb, amp: rrand(0, 0.6) do
        with_fx :tanh, krunch: 2, mix: rrand(0, 0.2) do
          with_fx :hpf, cutoff: 130 - rrand(0, 20), mix: rrand(0.9, 1) do
            sample :drum_cymbal_open
            sleep 0.75
            sample :drum_cymbal_pedal
            sleep 0.5
            sample :drum_cymbal_pedal, sustain: 0.1
            sleep 0.25
          end
        end
      end
    end
  end
end

```

I picture something like this. Apologies for the syntax errors, I’m a bit rusty with Ruby. I’m not even sure if this is Ruby. 🙂

```ruby
chain = [
  { fx: :compressor },
  { fx: :flanger, mix: rrand(0, 0.2) },
  { fx: :reverb, amp: rrand(0, 0.6) },
  { fx: :tanh, krunch: 2, mix: rrand(0, 0.2) },
  { fx: :hpf, cutoff: 130 - rrand(0, 20), mix: rrand(0.9, 1) }
]

with_fx :chain, chain: chain do
    play :c
end

```

The fx variable could be reversed, not sure which is more intuitive.

Above code is in a gist here [https://gist.github.com/datashaman/e4cc432516dbe6c923c3390af2d6a52a](https://gist.github.com/datashaman/e4cc432516dbe6c923c3390af2d6a52a)

---

<div class="post-metadata">

**Author:** ![datashaman](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/datashaman/32/2091_2.png) [@datashaman](https://in-thread.sonic-pi.net/u/datashaman)\
**Post date:** [September 7, 2021, 4:55pm UTC](https://in-thread.sonic-pi.net/t/snake-jazz-also-is-there-an-fx-stack/5932/2 "2021-09-07T16:55:48Z")

</div>

Short answer: Not possible or easy.

Long answer: I tried a recursive call passing a diminishing array of fx definitions, but then ran into an issue with random number generators creating the same results on every run (even when using lambda calls). it gets messy quickly, messier than nested definitions.

---

<div class="post-metadata">

**Author:** ![amiika](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/amiika/32/2401_2.png) [@amiika](https://in-thread.sonic-pi.net/u/amiika)\
**Post date:** [September 13, 2021, 3:16pm UTC](https://in-thread.sonic-pi.net/t/snake-jazz-also-is-there-an-fx-stack/5932/3 "2021-09-13T15:16:10Z")

</div>

I’v used this sort of block function for randomizing the effects. Works with randomized parameters as well when using lambda:

```ruby
def with_effects(x,&block)
  x = x.dup
  if x.length>0 then
    n = x.shift
    if n[:with_fx] then
      with_fx n[:with_fx], n do
        with_effects(x,&block)
      end
    end
  else
    yield
  end
end

live_loop :random_effects do
  
  chain = lambda do
    [ #<- Remove ":" to see parameter autosuggestion for fx
      {with_fx: :echo, phase: rrand(0,0.5) },
      {with_fx: :whammy, grainsize: rrand(0,2.0)},
      {with_fx: :flanger, feedback: rrand(0,0.5)},
      {with_fx: :tremolo, phase: rrand(0,0.5)},
      {with_fx: :bitcrusher, bits: rand_i(3..5)}
    ].pick(3) # Use all or pick some randomly
  end
  
  with_effects chain.call do # lambda call here randomizes the params and effects
    play (scale :C, :ahirbhairav).pick
  end
  
  sleep 1
end

```

---

<div class="post-metadata">

**Author:** ![datashaman](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/datashaman/32/2091_2.png) [@datashaman](https://in-thread.sonic-pi.net/u/datashaman)\
**Post date:** [October 4, 2021, 4:51pm UTC](https://in-thread.sonic-pi.net/t/snake-jazz-also-is-there-an-fx-stack/5932/4 "2021-10-04T16:51:05Z")

</div>

Neat - i think it’s the calling of the rrand within a live\_loop that is the trick.
