Sonic-pi: ticks increasing more than once in a thread?

Created on 14 Mar 2016  Â·  7Comments  Â·  Source: sonic-pi-net/sonic-pi

Is this the normal behavior of the ticks command?
The following code is outputting the ticks to be 1,3,5,7... as if just calling the puts command is adding to the ticks...

live_loop :piano do
  use_synth :piano
  play (ring 60,80)[tick]
  puts tick
  sleep 1
end

And this code outputs 2, 3, 8, like every call to the ticks is adding to its value.

live_loop :piano do
  use_synth :piano
  play (ring 60,80)[tick]
  sleep 1
  play (ring 90,100)[tick]
  puts tick
  sleep 1
end

Most helpful comment

Alex
If you use puts tick it will increment it before displaying the value
You can use puts look which will print the current valueof tick without changing it.
One thing I find useful is to put a single line tick at the start of a loop and to use look instead of tick wherever you need it in the loop. that way you avoid double ticks.
so below you would have

live_loop :piano do
use_synth :piano
play (ring 60,80)[tick]
puts look
sleep 1
end

One thing I find useful is to put a single line tick at the start of a loop and to use look instead of tick wherever you need it in the loop. that way you avoid double ticks.
so for the second example you would have

live_loop :piano do
use_synth :piano
tick
play (ring 60,80)[look]
sleep 1
play (ring 90,100)[look]
puts look
sleep 1
end

On 14 Mar 2016, at 12:14, Alexandre Rangel [email protected] wrote:

Is this the normal behavior of the ticks command?
The following code is outputting the ticks to be 1,3,5,7... as if just calling the puts command is adding to the ticks...

live_loop :piano do
use_synth :piano
play (ring 60,80)[tick]
puts tick
sleep 1
end

And this code outputs 2, 3, 8, like every call to the ticks is adding to its value.

live_loop :piano do
use_synth :piano
play (ring 60,80)[tick]
sleep 1
play (ring 90,100)[tick]
puts tick
sleep 1
end

—
Reply to this email directly or view it on GitHub.

All 7 comments

Hi Alexandre,

yes, if you want 'independent' ticks in one thread you have to pass an
argument

live_loop :example do
  play (ring 60, 61).tick(:a)  # `:a` is optional here, you can also keep
one call to tick with no argument
  play (ring 67, 68).tick(:b)
  sleep 1
end

the documentation of the function explains it:

'Increment the default tick by 1 and return value. Successive calls to tick
will continue to increment the default tick. If a key is specified,
increment that specific tick.'

and there's a whole chapter in the tutorial : '9.4 Ticking'

nico

On Mon, Mar 14, 2016 at 1:14 PM, Alexandre Rangel [email protected]
wrote:

Is this the normal behavior of the ticks command?
The following code is outputting the ticks to be 1,3,5,7... as if just
calling the puts command is adding to the ticks...

live_loop :piano do
use_synth :piano
play (ring 60,80)[tick]
puts tick
sleep 1
end

And this code outputs 2, 3, 8, like every call to the ticks is adding to
its value.

live_loop :piano do
use_synth :piano
play (ring 60,80)[tick]
sleep 1
play (ring 90,100)[tick]
puts tick
sleep 1
end

—
Reply to this email directly or view it on GitHub
https://github.com/samaaron/sonic-pi/issues/1057.

Hi Nicolas,

I get it now. Thank you very much!

Alex
If you use puts tick it will increment it before displaying the value
You can use puts look which will print the current valueof tick without changing it.
One thing I find useful is to put a single line tick at the start of a loop and to use look instead of tick wherever you need it in the loop. that way you avoid double ticks.
so below you would have

live_loop :piano do
use_synth :piano
play (ring 60,80)[tick]
puts look
sleep 1
end

One thing I find useful is to put a single line tick at the start of a loop and to use look instead of tick wherever you need it in the loop. that way you avoid double ticks.
so for the second example you would have

live_loop :piano do
use_synth :piano
tick
play (ring 60,80)[look]
sleep 1
play (ring 90,100)[look]
puts look
sleep 1
end

On 14 Mar 2016, at 12:14, Alexandre Rangel [email protected] wrote:

Is this the normal behavior of the ticks command?
The following code is outputting the ticks to be 1,3,5,7... as if just calling the puts command is adding to the ticks...

live_loop :piano do
use_synth :piano
play (ring 60,80)[tick]
puts tick
sleep 1
end

And this code outputs 2, 3, 8, like every call to the ticks is adding to its value.

live_loop :piano do
use_synth :piano
play (ring 60,80)[tick]
sleep 1
play (ring 90,100)[tick]
puts tick
sleep 1
end

—
Reply to this email directly or view it on GitHub.

Can we close this now?

probably :) @AlexandreRangel ?

Closing for now - feel free to re-open if there's still an issue :-)

Oh, thanks!
Sure, issue closed ok ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MoiRouhs picture MoiRouhs  Â·  3Comments

kivancguckiran picture kivancguckiran  Â·  4Comments

sbeaumont picture sbeaumont  Â·  3Comments

reiner-dolp picture reiner-dolp  Â·  6Comments

tomekr picture tomekr  Â·  4Comments