But a numeric return value here is not meaningless!
Let’s take the same code structure and simplify, to illustrate:
p = Pfunc({ thisThread.beats.postln; 1 }).play;
81.178623736
82.178623736
83.178623736
84.178623736
p.stop;
Now, if you write 713 instead of 1, you would get 81.178623736, then 794.178623736… if you wait the 11min 53sec. Probably you aren’t waiting that long, so you might have assumed that it’s going to do the Pfunc only once. It doesn’t. If you return a number here, it will be rescheduled. If that’s not what you wanted, then don’t return a number. (nil
is OK for non-repeat.)
Then…
s.sendBundle(0.713, ["/s_new", "loopbz", 3713, 1, 0, \bufnum, d["riff"][4].bufnum, \startLoop, 0,\endLoop, 713713713, \gate, 0]);
~riff=Pfunc({ s.sendBundle(0.713, ...) });
If you’re trying to sync two different players, using “meaningless” latency values is guaranteed to de-synchronize!
If you want two things to happen at the same time, the simplest, easiest, most reliable way to do that is:
-
Choose a point on a language-side clock (which you’re already doing by quant
).
-
At that time point, send messages with the same latency.
~k
will be using s.latency
= 0.1 in your example.
To start the riff loop at exactly the same time as ~k, you need to run the ~riff pattern at the same clock time, with the same latency. If ~k’s latency is 0.1 and ~riff’s latency is 0.713, then the riff will be 0.613 seconds late.
This works… (the magic numbers here are taken from an example I wrote once for a help file – the tricky thing was that the rhythm makes sense with a half beat “upbeat” so the synth here offsets the playback start position – if your loop recording starts on the downbeat then you don’t have to do that – the important point is that the synth begins exactly on a downbeat):
(
b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
~start = 0.404561;
~end = 3.185917;
~beatsInLoop = 4;
~originalTempo = ~beatsInLoop / (~end - ~start);
TempoClock.tempo = ~originalTempo;
SynthDef(\loop, { |out, gate = 1, bufnum, start, startOffset, end, amp = 0.1, rate = 1|
var eg = EnvGen.kr(Env.asr(0.01, 1, 0.01), gate, doneAction: 2),
bufsr = BufSampleRate.kr(bufnum),
// sc3-plugins:
sig = LoopBuf.ar(1, bufnum, rate * BufRateScale.kr(bufnum), gate,
startPos: (start + startOffset) * bufsr,
startLoop: start * bufsr,
endLoop: end * bufsr
);
Out.ar(out, (sig * (amp * eg)).dup);
}).add;
)
(
~loop = Pfunc({
s.makeBundle(s.latency, {
~loopsynth = Synth(\loop, [bufnum: b,
start: ~start, end: ~end, startOffset: 0.5 / ~originalTempo
]);
});
nil
});
~notes = Pbind(
\degree, Pseq([-7, Pwhite(0, 7, 7)], inf),
\dur, 0.5
);
)
p = ~notes.play(quant: -1);
q = ~loop.play(quant: -1);
p.stop;
~loopsynth.release;
hjh