# \[solved\] Controlling parameters from inside another live\_loop

**URL:** <https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729>\
**Category:** Support, Help & Resources\
**Created:** [March 23, 2024, 8:05pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729 "2024-03-23T20:05:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![drmindflip](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/drmindflip/32/2627_2.png) [@drmindflip](https://in-thread.sonic-pi.net/u/drmindflip)\
**Post date:** [March 23, 2024, 8:05pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/1 "2024-03-23T20:05:49Z")

</div>

Let’s say I have one `live_loop` that is playing a sample continuously:

```ruby
live_loop :looper do
  sample :loop_amen
  sleep sample_duration :loop_amen
end

```

And I have another that is updating a variable via an LFO-like behaviour. In this case, a value between -1 and 1 for panning:

```ruby
live_loop :lfo do
  pan_value = (range -1, 1, 0.1).mirror.tick
  sleep 0.1
end

```

How can I use the pan\_value variable to change the `pan:` parameter of the `sample` in _real-time_? Like using the `control` command, for example.

I have tried using `set:` and `get:` to store and update the varible, but then the looper will only grab the current value whenever the live\_loop restarts.

It would be okay if the `:lfo` live\_loop lives inside the `:looper` live\_loop, as in:

```ruby
live_loop :looper do

  live_loop :lfo do
    pan = (range -1, 1, 0.1).mirror.tick
    # some way of updating the 'sample' parameters needs to go here!
    sleep 0.1
  end

  sample :loop_amen
  sleep sample_duration :loop_amen
end

```

How can I get that pan value updating the sample parameters in real-time? What I ultimately want to build several asynchronous lfos that are each mapped to different, real-time elements of the `sample` command.

---

<div class="post-metadata">

**Author:** ![drmindflip](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/drmindflip/32/2627_2.png) [@drmindflip](https://in-thread.sonic-pi.net/u/drmindflip)\
**Post date:** [March 23, 2024, 8:32pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/2 "2024-03-23T20:32:36Z")

</div>

I think I’ve got it! Thanks to the advice posted by @ethancrawford on [this thread](https://in-thread.sonic-pi.net/t/solved-by-now-ty-all/4628/10).

```ruby
live_loop :beat do
  s = sample :loop_amen_full
  set(:s, s)
  sleep sample_duration :loop_amen_full
end

live_loop :lfo do
  use_real_time
  control get[:s], pan: (range -1, 1, inclusive:true, step: 0.1).mirror.tick
  sleep 0.1
end

```

I had to stick in `use_real_time` on the lfo section or I was getting timing warnings. Think this looks okay - although I’d welcome any feedback if I’m doing it a goofy or inefficient way!

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [March 23, 2024, 8:39pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/3 "2024-03-23T20:39:19Z")

</div>

Was just about to post this

```ruby
LFO = line(0, 1, steps: 5).mirror

live_loop :test do
  play 60, pan: LFO.tick * 2 - 1
  sleep 0.5
end

```

But I may have missed what the core of your question was.

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [March 23, 2024, 8:50pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/4 "2024-03-23T20:50:54Z")

</div>

I did misunderstand, oops

```ruby
live_loop :depth do
  l = -1
  r = 0
  LFO = line(r, l, steps: 5).mirror
  sleep 0.1
end

live_loop :test do
  play 60, pan: LFO.tick
  sleep 0.5
end

```

---

<div class="post-metadata">

**Author:** ![drmindflip](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/drmindflip/32/2627_2.png) [@drmindflip](https://in-thread.sonic-pi.net/u/drmindflip)\
**Post date:** [March 23, 2024, 8:53pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/5 "2024-03-23T20:53:45Z")

</div>

Thanks Brendan - after going down the rabbit-hole a bit here, it’s actually very helpful to see both of your examples for a more straightforward use case. They’re very clean!

I want to be able to `tick` the LFO independantly of the synth that’s making sounds, for 2 reasons: so I can use different `sleep` rates in the LFO loop to change the speed, and so I can change the parameters of an already-running note/sample.

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [March 23, 2024, 9:09pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/6 "2024-03-23T21:09:21Z")

</div>

Ah ok, so the steps: and sleep values in the :depth loop will give you some opaque control over the LFO parameters. I’ll have a tinker in the morning to see if there’s a more transparent method, it’s the kind of thing I could make use of too - like patching independently controllable synth modules.

Brendan

---

<div class="post-metadata">

**Author:** ![drmindflip](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/drmindflip/32/2627_2.png) [@drmindflip](https://in-thread.sonic-pi.net/u/drmindflip)\
**Post date:** [March 23, 2024, 9:23pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/7 "2024-03-23T21:23:06Z")

</div>

Aha yes, that’s a nice analogy - a much cleaner way of describing it!

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [March 23, 2024, 10:23pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/8 "2024-03-23T22:23:12Z")

</div>

It takes a bit of head scratching on my part, because, raised as I was on AudioMulch, Max/PD and Supercollider, I often think of live loops as independent patchable unit generators. And they’re not, and I absolutely LOVE learning this different way of composing and performing music!

---

<div class="post-metadata">

**Author:** ![drmindflip](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/drmindflip/32/2627_2.png) [@drmindflip](https://in-thread.sonic-pi.net/u/drmindflip)\
**Post date:** [March 25, 2024, 2:53pm UTC](https://in-thread.sonic-pi.net/t/solved-controlling-parameters-from-inside-another-live-loop/8729/9 "2024-03-25T14:53:45Z")

</div>

Very much in the same boat here! But just learning that I can do something like this in one live loop:  
`s = sample :loop_amen`

and then do _this_ in a separate live loop:  
`control get[:s], amp: 0.5`

is a bit of a game changer, connectivity-wise!
