11 error("Cannot convert this object to a SynthDef:" + this);
27 asDefName { ^this.asString }
32 this is mainly for {}.play and Synth({ })
42 it inserts an Out only if it needs it
45 asDefName { // won't work immediately for Synth.new
47 def = this.asSynthDef;
48 def.send(Server.default);
52 asSynthDef { arg rates, prependArgs, outClass=\Out, fadeTime, name;
53 ^GraphBuilder.wrapOut(name ?? { this.identityHash.abs.asString },
54 this, rates, prependArgs, outClass, fadeTime
58 play { arg target, outbus = 0, fadeTime = 0.02, addAction=\addToHead, args;
59 var def, synth, server, bytes, synthMsg;
60 target = target.asTarget;
61 server = target.server;
62 if(server.serverRunning.not) {
63 ("server '" ++ server.name ++ "' not running.").warn; ^nil
65 def = this.asSynthDef(
67 name: SystemSynthDefs.generateTempName
69 synth = Synth.basicNew(def.name, server);
70 // if notifications are enabled on the server,
71 // use the n_end signal to remove the temp synthdef
73 OSCpathResponder(server.addr, ['/n_end', synth.nodeID], { |time, resp, msg|
74 server.sendMsg(\d_free, def.name);
78 synthMsg = synth.newMsg(target, [\i_out, outbus, \out, outbus] ++ args, addAction);
79 def.doSend(server, synthMsg);