# Rising number function?

**URL:** <https://in-thread.sonic-pi.net/t/rising-number-function/4187>\
**Category:** Support, Help & Resources\
**Created:** [July 10, 2020, 11:33am UTC](https://in-thread.sonic-pi.net/t/rising-number-function/4187 "2020-07-10T11:33:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeceptiveCake](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/deceptivecake/32/1482_2.png) [@DeceptiveCake](https://in-thread.sonic-pi.net/u/DeceptiveCake)\
**Post date:** [July 10, 2020, 11:33am UTC](https://in-thread.sonic-pi.net/t/rising-number-function/4187/1 "2020-07-10T11:33:35Z")

</div>

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

what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [July 10, 2020, 12:09pm UTC](https://in-thread.sonic-pi.net/t/rising-number-function/4187/2 "2020-07-10T12:09:36Z")

</div>

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:

```ruby
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](https://sonic-pi.net/tutorial#section-8-4)).

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [July 10, 2020, 12:10pm UTC](https://in-thread.sonic-pi.net/t/rising-number-function/4187/3 "2020-07-10T12:10:30Z")

</div>

You set rise to 0 every time you start the loop.  
I would try something like this (I used a different sample) and used Ruby’s min method

```ruby
define :rise do |x|
  return [60+10*x,120].min
end

live_loop :BD do
  sample :loop_amen, beat_stretch: 2, cutoff: rise(tick)
  sleep 2
end

```

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [July 10, 2020, 12:17pm UTC](https://in-thread.sonic-pi.net/t/rising-number-function/4187/4 "2020-07-10T12:17:57Z")

</div>

> [@DeceptiveCake](#):
>
> defined by a function

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 🙂

---

<div class="post-metadata">

**Author:** ![DeceptiveCake](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/deceptivecake/32/1482_2.png) [@DeceptiveCake](https://in-thread.sonic-pi.net/u/DeceptiveCake)\
**Post date:** [July 10, 2020, 12:21pm UTC](https://in-thread.sonic-pi.net/t/rising-number-function/4187/5 "2020-07-10T12:21:41Z")

</div>

Thank you!  
defined as a function or built in, s’all good either way right now 😄

You’re both stars!
