Reverse rate at especif onset number

Hello there, i’m trying to apply a reverse rate of the sample when a especif onset number plays inside a knit sequence, like this:

live_loop :vapor do
  rev = 1
  pitch = 0
  slice = (knit, 6, 2, 3, 1, 2, 4, 4, 4, 5, 1).tick
  sample plunder, n, amp: 8, onset: slice, rpitch: pitch, rate: rev
  sleep sample_duration plunder, n, onset: slice, rpitch: pitch, rate: rev
end

Can someone help me with this ?

Hello @morte_conscio :slight_smile: Sure.
What is the specific challenge you are having? are you not sure of the correct commands to use? the correct sequence of commands/algorithm to use? both?
Have you got any initial thoughts about the rough procedure, if it were described in plain (not code) language? (This is a very useful technique when thinking about solving a programming challenge!)
You are already half way there, because you are already iterating through the ring of onsets :slight_smile:

The first question to answer is probably something like ‘how do we know when the right onset is ready to play so that we can reverse it?’.
Then, we can figure out a way to check it. As is common in many programming situations, there’s several ways we can do this - we could check the specific value of the current onset; we could check the position of the current onset in the slice ring; etc.
Given that, it’s just a matter of then using this to change the rate if the onset is the right one.

Maybe have a read through the tutorial chapter on Ticking: Sonic Pi - Tutorial, especially where it talks about look.

If none of this gives you any further clues, I’m happy to point you closer towards your goal :slight_smile:

Thank you. I’ve tried somethings, but still not exactly what i want:

live_loop :vapor do
  rev = -1 if bools(0, 0, 0, 1, 0, 0, 0, 0, 1, 0).look
  pitch = -6
  slice = (knit, 6, 2, 3, 1, 2, 4, 4, 4, 5, 1).tick
  sample plunder, n, amp: 8, rpitch: pitch, rate: rev, onset: slice
  sleep sample_duration plunder, n, rpitch: pitch, rate: rev, onset: slice
end

It does work, but not on specific onset values. For example, i want the rate as -1 if onset goes 6 or 4. I’m still kind of lost with this

Sure! So, it’s probably simpler if you just base the choice of rev directly on the slice, rather than tracking it with an entirely separate ring.

For that, it might be worth checking out Sonic Pi - Tutorial - Conditionals - that may clarify for you how you can say ‘if something something, do XYZ’. All you’d need to do is have that conditional statement change the rev based on the value of the slice :slight_smile:

Hi @morte_conscio

seems there is a typo near knit

Another point if you want others to help you, avoid giving code with undefined variables (plunder) :slight_smile:
So i propose

live_loop :vapor do
  rev = -1 if bools(0, 0, 0, 1, 0, 0, 0, 0, 1, 0).look
  pitch = -6
  slice = (knit 6, 2, 3, 1, 2, 4, 4, 4, 5, 1).tick
  sample :loop_amen_full, 4, amp: 8, rate: rev, onset: slice, rpitch: pitch
  sleep 1
end

and tell us what you want to get !
Cheers

Hi @morte_conscio

I think you can use case.
There is a rythm tune

##| r = (knit 8, 5)
r = (knit 6,4, 1,4, 4,3, 6,1, 0,4)
puts r


live_loop :vapor do
  foo = r.tick
  puts foo
  case foo
  when 6
    rev = -1
  when 4
    rev = 1.5
  else
    rev = 1
  end
  
  sample :loop_amen_full, amp: 2, rate: rev, onset: foo, lpf:80,
    sustain: 0.25
  
  sleep 0.25
  
end

Hey @nlb , thank you for advice. I didn’t know about this case and when function, also didn’t find them in the sonic pi tutorial. Just one more question, does it have some diference using the ring outside or inside the live_loop?

Actually you can use these others instructions

##| r = (knit 8, 5)
r = (knit 6,4, 1,4, 4,3, 6,1, 0,2)
puts r


live_loop :vapor do
  foo = r.tick
  
  puts foo
  if foo == 6
    rev = -1
  elsif foo ==4
    rev = 1.5
    
  else
    rev = 1
  end
  
  
  
  ##| case foo
  ##| when 6
  ##|   rev = -1
  ##| when 4
  ##|   rev = 1.5
  ##| else
  ##|   rev = 1
  ##| end
  
  sample :loop_amen_full, amp: 2, rate: rev, onset: foo, lpf:80,
    sustain: 0.25

  sleep 0.25
  
end

If you don’t need your ring in another live_loop you can put it inside the live_loop otherwise you need to set it into the main “scope” outside the live_loop.

Hmm, ok, thank you! Guess i understand now