The subtile difference between "range" and "line"

Hi there! @Hussein in two of his great videos speaks about “line” then “range”. In fact if you compare these two blocks, it’s the same thing, the same result:

myrange = (range 0, 1, step: 0.1, inclusive: true)

10.times  do
  play 60, release: 0.2, amp: myrange.tick
  sleep 0.25
end

myline = (line 0, 1, steps: 10, inclusive: true)

10.times  do
  play 60, release: 0.2, amp: myline.tick
  sleep 0.25
end

I’d like just like to know if you see code contexts where “range” and “line” could bring something different…or perhaps not since, just the word “step/steps” seems to make the only difference.
Thanks for attention

1 Like

Hi
as per the docs, both line and range create a ring, with start and end values, with the subtle difference that range asks you to specify (and therefore have ‘greater control’ over), the size of the step; line also has a start and end value, but the step size is calculated based on the number of divisions within that range.

Speaking strictly as a non-coder/mathematician, the difference can sometimes yield unexpected results, particularly when using either function for control of, for example, pitch.

myrange = (range 0, 1, step: 0.2, inclusive: true)

5.times  do
  tick
  val = myrange.look
  puts val
  play (val * 10) + 60, release: 0.2
  sleep 0.5
end

sleep 2
myline = (line 0, 1, steps: 5, inclusive: true)

5.times  do
  tick
  val = myline.look
  puts val
  play (val * 10) + 60, release: 0.2
  sleep 0.5
end

At least, that’s how I think of the difference between the two, and therefore prefer to use range :wink:

PD-Pi

1 Like

ok Brendan @brendanmac thanks for your interesting point of view…
In the help doc, Sam @samaaron writes that “line is similar to range” but without giving details so, in certain context it seems interesting to use and compare the two possibilities :grinning:

Hi
others may disagree, or have different approaches but, generally, I tend to use range for larger steps - pitch, cutoff etc - and line for finer resolution control of normalised values, say, amplitude.

PD-Pi

1 Like

Subtle difference indeed; but note that Sam uses the phrase “similar to” and not “the same as”:

ln1 = (range 0, 1, step: 0.1, inclusive: true)

ln2 = (line 0, 1, steps: 11, inclusive: true)

live_loop :stepsize do
  puts ln1.tick
  sleep 1
end

live_loop :divisions, delay: 0.1 do
  puts ln2.tick
  sleep 1
end

PD-Pi

1 Like