Triggering changes with Run in the 3.3 Beta

Not sure if I should ask this on github considering I’m using Beta versions, but wanted to make sure I wasn’t missing something in how Sonic Pi operates in general.

I’m doing pretty basic stuff with a bunch of live_loop blocks. Playing external samples and synths etc. However, it seems that the only way some of the parameters take (including commenting out blocks in general) doesn’t actually update unless I fully stop and then run again, which of course breaks the timing.

I imagine that running threaded loops is still going on and takes time to clear out, but it seems like they just keep going regardless until I actually stop and restart. Seems mostly to happen using a with_fx block more than samples or synths, but again even commenting out huge parts of the files keep stuff running for seeming eternity.

The code:

sroot = "/home/hypostatic/music/samples/"
samples = sample_paths sroot + "_MM - Field Recordings/Andrei's Bell/"

load_samples sroot + "Cult of Montu/_Ideas/_MM - Field Recordings/Andrei's Bell/"

use_debug false

use_bpm 70

with_fx :echo,
  phase: rrand(0.1, 1),
  decay: [1, 5].tick,
  max_phase: 5,
  mix: (range 0, 1, step: 0.1).choose,
amp: 1 do
  live_loop :andrei do
    s = sample samples.tick,
      amp: [0, 1, 2, 3].choose,
      slice: 3, num_slices: rrand(1, 5),
      start: (range 0, 1, step: 0.1).tick,
      finish: (range 1, 0, step: 0.1).tick,
      lpf: (range 30, 100, step: 2).look,
      release: (range 0, 1, step: 0.1).choose,
      attack: (range 0, 1, step: 0.1).look,
      slide: 2,
      rate: rrand(0.1, 1)
    sleep [1,0.25,2].tick
    if one_in(1)
      kill s
  sleep 1

live_loop :ch do
  sync [:ah, :andrei].tick
  use_synth :fm
  play scale(:D2, :minor_pentatonic).choose
  sleep 0.25
  use_synth :dtri
  play scale(:D3, :minor).choose, attack: rrand(0.01, 1)
  sleep [0.125, 0.25, 0.5, 3].choose

live_loop :beat do
  if one_in(3)
    sync :andrei
  sample :ambi_soft_buzz, attack: rrand(0.01, 0.2)
  sleep 3

live_loop :beat2 do
  sync :ah
  sample :bd_808, amp: 1, beat_stretch: [0.5, 4].tick
  sleep [0.5, 0.25, 0.5].tick

live_loop :ah do
  sync :beat2
  use_synth :dull_bell
  5.times do
    play scale(:G3, :minor, num_octaves: 3).mirror.choose, sustain: rrand(0.1, 0.3)
    sleep [0.25, 0.5, 0.75].choose
  sleep 12

live_loop :kik do
  use_synth :fm
  play [:c2, :c3, scale(:c4, :egyptian).choose].tick
  sleep [0.5, 0.25, 0.25, 1, 0.5, 2].tick

Commenting everything out but the last block still plays all of the above for well beyond say the first blocks loop. I’ve let it go for several minutes and doesn’t stop after commenting it out.

Probably some misunderstanding on my part.

Hi Isaac,

just a general comment (which might already be enougth for you to figure this out):

  • If you comment a running live_loop, it will still be playing (it is still evaluated code running in the memory); this is expected behavior. To stop a live_loop write a stop in the second line and evaluate the code.
  • The live_loop has two functions: 1. it creates an independent unitiy (the same as to use in_thread) but also it registers new code after a reevaluation of the buffer without creating a new thread (and thus e. g. playing a sample or note again on top of what is already playing). On the other hand this means: You will not be able to update anything outside a live_loop without stopping/restarting SP completely. This e. g. applies to you with_fx :echo and also to your sample definition.

So I hope read your questions correctly and this is of some help.

1 Like

This is exactly what I needed. I know I’ve seen ‘stop’ but totally forgot about it. Most of what you said I sort of assumed was the case, but found it so unwieldy (with a way to stop) that I thought something else might be wrong. Thanks once again for great answers @Martin!

I’m still in the basics (obvioiusly) - I can’t imagine what will happen when I get further along…

1 Like