How can I "Kill" external sample?


#1

I am trying to use the “kill” command cut am not sure how to apply it to an external sample as the documentation only shows how to do it for built-in samples. Here’s what I wrote but it’s not working:

live_loop :plop do
  with_fx :level, amp: choose([0,1])  do
    samp1 = sample slomo, 8, rate: 2, onset: pick
  end
  sleep 0.125
  kill samp1
end

#2

Hi there,

there’s no difference between internal and external samples with respect to using kill. You’ll find that you’ll see the same error if you replace slomo with an internal sample.

It would have been useful if you could have included the error that you observed, which I assume is something along the following:

undefined local variable or method 'samp1' for Runtime :SonicPiLang

This issue here is that you have defined samp1 within the context of the FX block and it isn’t available outside. This is a limitation/behaviour of the underlying Ruby language.

The way round this currently is to use set and get:

live_loop :plop do
  with_fx :level, amp: choose([0,1])  do
    samp1 = sample slomo, 8, rate: 2, onset: pick
    set :s, samp1
  end
  sleep 0.125
  kill get(:s)
end

Alternatively if you put the kill within the do/end block of the FX, that will also work:

live_loop :plop do
  with_fx :level, amp: choose([0,1])  do
    samp1 = sample slomo, 8, rate: 2, onset: pick
    at do
      sleep 0.125
      kill samp1
    end
  end
  sleep 0.125
end

I hope that this helps :slight_smile:


#3

Yeah that helps, I understand more now thanks!