Hi there, still feeling pretty n00b, sorry if this is pretty arbitrary but I cant find the answer for the life of me.
I’m trying to control cutoff or lpf or something using a rising set of numbers defined by a function, once it gets to a top threshold the idea is for it to stay there rather than loop back down.
I’ve got this…
define :rise do |rise|
rise += 10
if rise > 120
rise = 120
else
rise = rise
end
end
live_loop :BD do
sample ate_08_BD, beat_stretch: 2, cutoff: rise 0
sleep 2
end
Hey @DeceptiveCake
There were a few problems getting this to run - firstly, due to the structure of Sonic Pi code, Sonic Pi did not understand that you were trying to pass 0 as the parameter to the rise function - it just saw a number stuck on the end of that line for some unknown reason. Here, in order to make it see 0 as the parameter to that function, you would need to write it as rise(0).
Having said that, after I replaced ate_08_BD with the name of one of the samples built in to Sonic Pi, the loop then runs for me. However, it will still not have the desired result. That’s because we’re passing 0 into the function when playing the sample, sleeping for 2, and then doing exactly the same thing the next time around the loop. (Every time around the loop, rise is passed 0.
Luckily, in this case Sonic Pi actually makes it quite easy to do exactly what you want, without having to worry about if conditions and adding values etc Enter: Rings, tick/look, and the ramp function
Behold:
live_loop :BD do
sample ate_08_BD, beat_stretch: 2, cutoff: (line 0, 120, steps: 16, inclusive: true).ramp.tick
sleep 2
end
I don’t know exactly what your sample is meant to sound like, but the mechanism of what you’re after is what follows cutoff above anyway In a nutshell: line creates a ring of values, ramp causes anything stepping through the ring to stay on the last item when it reaches there, and tick is what steps through each value.
I’m quite happy to explain it in detail if you want, or still have questions - otherwise, you can read about it in the app help (See line, tick, look and ramp under ‘Lang’). Rings (which the line function also creates) are also described in Chapter 8.4 of the Tutorial. (Or see https://sonic-pi.net/tutorial#section-8-4).
Think I obviously missed this bit when I read your message earlier
My solution above is one way of achieving a rising value that holds at the end - Robin’s does just as well also. It all depends on what you choose for your particular use case