Apologies @Iannis_Zannos, @Geoffroy!
I think the problem was that ~global variable declarations (~hiThetaEnergy, ~timeThreshold
) used in the ~reward.play
routine were inside the t.playNextBar{
:
~forestDepth[0] = { |bps,bpb|
t.playNextBar {
//nf settings:
~hiThetaEnergy = 10;
~timeThreshold = 10;
//forest:
Ndef(\wind2).play;
Ndef(\wind2).fadeTime = 6;
Ndef(\wind2).xset(\amp, 0.1, \lpf, 2500);
//shaman:
Ndef(\0).stop;Ndef(\1).stop;Ndef(\2).stop;
~notes = Array.fill3D(3, bpb, 5, nil);
t.clear;
};
};
Moving them outside the t.playNextBar{
makes it work:
~forestDepth[0] = { |bps,bpb|
//nf settings:
~hiThetaEnergy = 10;
~timeThreshold = 10;
t.playNextBar {
//forest:
Ndef(\wind2).play;
Ndef(\wind2).fadeTime = 6;
Ndef(\wind2).xset(\amp, 0.1, \lpf, 2500);
//shaman:
Ndef(\0).stop;Ndef(\1).stop;Ndef(\2).stop;
~notes = Array.fill3D(3, bpb, 5, nil);
t.clear;
};
};
The routine to clarify it further:
~reward= Routine(
~timer = [0,0,0,0];
// 0: elapsed time since routine started
// 1: total time above ~threshold
// 2: current time spent above ~threshold
// 3: how often was ~timeThreshold met
{inf.do{ |i|
~timer[0] = ~timer[0]+1;
(~energyTheta >= ~hiThetaEnergy).if {
~timer[1] = ~timer[1]+1;
~timer[2] = ~timer[2]+1;
(~timer[2]%~timeThreshold == 0).if {
~timer[3] = ~timer[3]+1
}
} {
~timer[2] = 0; //restart
};
~timer.postln;
1.wait}});
Yes, entirely my fault! Very sorry 
If however it is just a function, then the thread will wait until the function finishes, and there is nothing you have to do.
Thanks - I think I understand now:
t.playNextBar {
is pointing to do something outside the function, hence it is later in the thread (or in another thread). Now, executing the following line works:
~forestDepth[0].value(4,16);~reward.play;
cheers! k