Trying to get a ping at random that plays 1.0 or 0.5, 0,5. subdivisions. Im guessing several ways to handle it. But interested in how to with the least amount of code. Im super new and this ugly mess I was trying is not working…
(
SynthDef(\ping,{
var sig;
sig = SinOsc.ar() * Env.perc(0.01, 0.1).ar(2) !2 * 0.2;
Out.ar(0, sig) ;
}).add
)
/// guessing something like this plugged in but have to get synth to play aswell..
(
|n = 1.0|
[n, [n/2, n/2]].choose;
)
/// i know this won't work
(
Routine { |n|
[n, [n/2, n/2]].choose;
Synth(\ping);
loop({
Synth(\ping)
wait(n);
});
}.play
)
///// or this
(
Routine
loop({
Synth(\ping)
wait(1.0, [0.5, 0.5]).rrand;
});
}.play
)
(
Routine {
var dur = Prand([
1.0, // one of the 2 random choices
Pn(0.5, 2) // the other (must play both 0.5 values consecutively)
], inf).asStream;
loop({
s.bind { Synth(\ping) }; // see "Server Timing" help
dur.next.wait;
});
}.play;
)
… but, you have also asked for shorter code, and I think it isn’t going to get any shorter than the pattern way. (Also, patterns aren’t all or nothing – using Prand for the duration doesn’t require using Pbind to run the sequence.)
In sequencing contexts, it’s generally recommended to send messages with timestamps. Synth() by itself omits the timestamp; as a result, synths’ onset times will be quantized to hardware buffer boundaries, which generally you don’t want (except for live triggering, where “as soon as possible” is the desired behavior).