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
live_loop :BD do
sample ate_08_BD, beat_stretch: 2, cutoff: (line 0, 120, steps: 16, inclusive: true).ramp.tick
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