Here’s a useful class I thought I’d share. It’s pretty beta, but I find that it works fine for the cases I’ve tested. Happy to take feedback!
It’s a replacement for Pmono
that provides several additional things:
- It has the same syntax as Pbind - you no longer need the SynthDef name as the first argument, so you can easily switch in your code between mono and poly Pbinds.
- It provides a more convenient constructor,
Pbind.mono
. - It has several ways to restart your mono voice…
- If it detects that the target SynthDef has changed since it started, it restarts the voice.
- If you have a
\monoId
key, the voice is restarted every time this changes - If the
\restart
key contains or returnstrue
.
- It is SOMEWHAT resilient to node order changes. So, for example, if you specify a target
\group
or\addAction
and this CHANGES while you’re playing, the node is re-ordered on the server. - Normally Pmono uses the
\off
event type to end a voice - so do I. But, you can override this using the\offEventType
key. So, if you desire some special behavior when your voice is ending, you can make a custom event type and point to it here. - It’s composable: you can make any pattern monophonic by doing:
Pmonophonic() <> Pdef(\someOtherPattern)
Example:
(
SynthDef(\saw, {
Out.ar(
\out.ir(0),
RLPF.ar(
Saw.ar(
(
\freq.ar
* [0, \foffset.kr(0.01)].poll
.resamp1(4)
.midiratio
).lag(\freqLag.kr(0.05))
).sum,
\lpf.ar(300),
0.3
)
* Env.asr(
attackTime: \attack.kr(0.1),
releaseTime: \release.kr(1)
).ar(gate:\gate.kr(1))
* \amp.ar(1)
! 2
)
}).add;
)
(
Pdef(\monoVoice, Pbind.mono(
\instrument, \saw,
\dur, 1/8,
\amp, -24.dbamp,
\lpf, Pseg([
Pwhite(50, 120, 1),
Pwhite(550, 6320, 1)
], [Pwhite(1, 8, 1)]).repeat,
\foffset, Pseg(
[
0.01,
Pwhite(0.01, 1, 1),
0.01,
],
[Pwhite(1, 8, 1), Pwhite(1, 8, 1)],
6 * [1, -1]
).repeat,
\scale, Scale.augmented,
\release, 6,
\restart, Prand([false, false, true], inf),
\degree, Pxrand([-4, 2, 1, 5, 3], inf)
+ Pseq([0, -2, -3, 2, 1], inf).durStep(
Pseq([2, 2, 1.5, 3.5], inf)
)
)).play
)
You can see that if you change the SynthDef, the mono voice is restarted. Another interesting example - point the \monoId
key to \octave
, which starts a new voice each time the octave changes. This is useful for e.g. sample based synths, where you don’t want an abrupt click or transition when you switch samples.
(
Pdef(\monoVoice, Pbind.mono(
\instrument, \saw,
\dur, 1/8,
\amp, -24.dbamp,
\lpf, Pseg([
Pwhite(50, 120, 1),
Pwhite(550, 6320, 1)
], [Pwhite(1, 8, 1)]).repeat,
\scale, Scale.augmented,
\release, 6,
\octave, Pxrand([2, 3, 4], inf).durStep(4),
\monoId, { ~octave },
\degree, Pxrand([-4, 2, 1, 5, 3], inf)
+ Pseq([0, -2, -3, 2, 1], inf).durStep(
Pseq([2, 2, 1.5, 3.5], inf)
)
)).play
)