Creating values for a fade

I have been trying to figure out the best and most effective way for generating values for a fade. I know there must be a good way but please advise if you have a suggestion for a good solution. If no such mechanism exists I guess I can create a function of some sort but I wanted to check if something exists before I do.

E.g I want to start the value from 30 and then go up to 40 but I then do not want the ring to loop. I want the ring to continue to deliver the value 40 when it is reached.

live_loop :test do
  tick
  value = (range 30, 40, step: 1).look
  puts value
  sleep 0.125
end

@keys - see the Lang documentation reference for the ramp function :slight_smile:
(You can also call it like this:)

(ring ...).ramp
1 Like

Thanks! I knew there had to be a solution for this :slight_smile: Hope it is ok that I post a follow up. Where can I find the lang documentation? Also do you know if there is a difference between range and line?

ri = (line 30, 40, steps: 10).ramp  #vs
ri = (range 30, 40, steps: 10).ramp

No problem, that’s fine :slight_smile:
It’s visible in the Help panel, which you can access via the main menu, or the buttons, or by hitting the Meta-i key combination:


As for a difference between range and line, yes, they are slightly different. range lets you set the distance between items (step size), line lets you set the number of steps. See the Lang reference again for both functions, and all the others :slight_smile:

1 Like

Thanks for the advise but I have to post one more follow up. I got it working fine now using range and ramp and I am able to change the value from e.g 40 to 60 in a way I want. However the challenge is if I want to go back again or continue to increase from 60 to 70. If I then change the values in the ring it just jumps straight to 80 instead of stepping. Is this a bug or am I doing somthing wrong.

  tick
  ri = (range 40, 60,step:1).ramp
  val = ri.look

  # Then later I change it to the code below and hit run

  tick
  ri = (range 60, 70,step:1).ramp
  val = ri.look

Also this does not work

  tick
  ri = (range 40, 60,step:1).ramp
  val = ri.look

  # Then later I change it to the code below and hit run

 tick
 ri = (range 60, 40,step:1).ramp
 val = ri.look

Hi @keys,

I think the key here is to see that tick and a given ring are very separate things. tick is a thread-local counter. Every time you call it, it will add 1 to the current counter value. If you call it 1000 times, the counter value will be 1000 (actually 999 as the counting starts at 0, but I’m just mentioning that here for technical completeness).

Calling .look on a ring will use the current counter value as an index on the ring and if the value is larger than the size of the ring (say the ring has only 15 elements within it) it will wrap the index round back to the beginning (using a mod of the ring’s size) so that it always returns a value within the ring. (That’s why rings are called rings - they act like ring buffers).

Therefore, if you call .look on a new ring, it will still use the counter value as it currently stands. Each ring does not have its own distinct counter.

If you want to reset a counter call tick_reset and then you’ll be back where you started :slight_smile:

Hope that this helps

2 Likes

Thank you so much for the advise. It was very clarifying. I have been testing a bit more here in light of the reply and I understand a bit more how rings work now. Just to clarify one final thing. When I define a ring in a live_loop will this be a global defined list in the thread or will it be redefined on every run?

However in light of the replies I think maybe rings are not the right tool for what I am trying to do after all. I have sketched a solution for how I can solve the fade using global variables.

live_loop :loop2 do
    new_vol = 10
    if get[:t1_volume] == nil
        set :t1_volume,0
    elsif new_vol < get[:t1_volume]
        set :t1_volume,get[:t1_volume]-1
    elsif new_vol > get[:t1_volume]
        set :t1_volume,get[:t1_volume]+1
    end
    
    sleep 0.5
end