I’m trying to encapsulate the (working) code I have here in a Proto
. But I’m having a race condition on startup on trying to map the “perma sig gen” node to a bus (giving a FAILURE IN SERVER /n_mapn Node XXXX not found
. Can anyone suggest how to work around for this? (And I mean something that doesn’t break the encapsulation, i.e. abandon Pproto.)
(SynthDef(\beep, {
var out = \out.ir(0), amp = \amp.kr(0.5), freq = \freq.kr(440);
ReplaceOut.ar(out, amp * SinOsc.ar(freq).dup);
}).add;)
(SynthDef(\menv, {
var out = \out.ir(88), atk = \atk.kr(0.15), rls = \rls.kr(0.5), gate = \gate.kr(1), slvl = \slvl.kr(0.5);
var insig = In.kr(out), env = EnvGen.kr(Env.asr(atk, slvl, rls, 0), gate, doneAction:2);
var eSlopesDown = (HPZ1.kr(env) < 0), outsig = eSlopesDown.if(env, max(insig, env));
ReplaceOut.kr(out, outsig);
}).add;)
(p = Pproto({ var onres;
~ampBusNum = ((type: \controlBus, channels: 1).yield)[\out];
~ampBusNum.postln;
onres = (type: \on, instrument: \beep, amp: 0.1).yield; // non-zero amp so I can hear it get created
onres.postln;
Node.basicNew(s, onres[\id][0]).map(\amp, ~ampBusNum); // onres[\server] no diff
~egroup = (type: \group).yield; // not sure this works either without indexing id
~egroup.postln;
}, Pbind(
\instrument, \menv, \addAction, 1,
\group, Pkey(\egroup), \out, Pkey(\ampBusNum),
\dur, Pseq([0.2], inf),
\legato, Pseq([0.5, 0.7, 0.9, 0.975, 1, 1.1, 1.151])
)).trace.play);
I get something like (snipping the irrelevant output):
( 'channels': 1, 'type': controlBus )
1
( 'instrument': beep, 'amp': 0.1, 'type': on )
( 'instrument': beep, 'msgFunc': a Function, 'amp': 0.1, 'server': localhost,
'isPlaying': true, 'freq': 261.6255653006, 'hasGate': false, 'type': on, 'id': [ 1661 ] )
( 'type': group )
( 'type': group, 'id': 1662, 'server': localhost )
( 'instrument': menv, 'group': ( 'type': group, 'id': 1662, 'server': localhost ), 'out': 1, 'dur': 0.2,
'legato': 0.5, 'addToCleanup': [ a Function ], 'delta': 0.2, 'egroup': ( 'type': group, 'id': 1662, 'server': localhost ), 'addAction': 1,
'ampBusNum': 1 )
FAILURE IN SERVER /n_mapn Node 1661 not found
Looking through Event.sc
, there seems to an event of type \map
defined too, which might sequence everything correctly without me having to instantiate the Node.basicNew
, but I’m not sure how to use the \map
events. Actually, scratch that, map
seems to be intended to be called directly as a “NodeEvent”, not actually scheduled. Those NodeEvents don’t work terribly well, by the way…