My question is:
if I do a tempo and/or signature changes inside a task playing on the clock (t in this case) do I still need the t.schedAbs ?
Example:
var myTask, globalQuant = 7;
t = TempoClock.new(2);
myTask = {
var cond = Condition.new;
t.schedAbs(t.nextTimeOnGrid,{ // Do I need this in my case ?
t.tempo = 44 / 60;
t.beatsPerBar = 7;
cond.unhang;
});
cond.hang;
"tempo and signature changed".postln;
4.0.wait;
"you are 4 beats after tempo and signature changes".postln;
// write your task here
};
Tdef(\song, myTask).play(t, true, globalQuant);
If I simply do this:
var myTask, globalQuant = 7;
t = TempoClock.new(2);
myTask = {
t.tempo = 44 / 60;
t.beatsPerBar = 7;
"tempo and signature changed".postln;
4.0.wait;
"you are 4 beats after tempo and signature changes".postln;
// write your task here
};
Tdef(\song, myTask).play(t, true, globalQuant);
I’d like to know if the last block of code will be reliable.
Thank you in advance.
The help file says, “Setting must be done from within the scheduling thread” – which of course human beings couldn’t be expected to understand
It should really say “A code block setting beatsPerBar should be scheduled on the same clock whose meter is being set.”
How is a code block scheduled on a clock?
“Code block” is a function – and functions may be wrapped in a Routine or Task (or Pfunc, Prout, Pspawner etc) as well.
“Scheduling” refers to sched or schedAbs, or any method that uses those methods (such as play).
So: If you are setting beatsPerBar in a Routine and the Routine is playing on the clock being set, then… that’s completely fine. Playing the Routine on the clock is already scheduling, so there’s no need to schedule a separate function.
Also the beatsPerBar_ method will throw an error if it’s not running on the clock. So if you’re not getting an error, then… you’re fine.
It just occurred to me – I’ll change this later – the help should recommend always writing thisThread.clock.beatsPerBar = ... because then the only way to address the right clock is to schedule a function or routine on it.