The classes listed below implement the method asTarget
. This is used widely in the Node classes ( Group and Synth ) to convert non-Node objects to an appropriate target. This allows nil and instances of Server to be used as targets. This can be useful when writing classes which create nodes internally, but in most cases there should be little need to call asTarget in normal use.
For an updated list of which classes that implements asTarget
, see asTarget in Methods: asTarget
s = Server.default;
g = s.asTarget; // the default group of s
h = s.defaultGroup; // and again
g == h; // true
g === h; // false
xxxxxxxxxx
s = Server.default;
g = nil.asTarget;
g == s.defaultGroup; // true
/////// Showing the problems
s = Server.default;
s.boot;
g = s.nextNodeID.asTarget;
x = Synth.head(g, "default"); // but g doesn't exist on the server
s.sendMsg(*g.addToHeadMsg); // now it's sent to the default server, in the default group
x = Synth.head(g, "default"); // now this works
x.free; g.free;
// if not using the default Server Integer-asTarget can be problematic
Server.default = Server.local;
Server.default.boot; // quit the default server
i = Server.internal; i.boot;
g = i.nextNodeID.asTarget;
i.sendMsg(*g.addToHeadMsg); // seems to work, but...
x = Synth.head(g, "default"); // oops, this goes to the default server, so Group not Found
g.server == Server.default; // true, so that's the problem
g.server = i;
x = Synth.head(g, "default"); // now to the right place
x.free; g.free;
xxxxxxxxxx
/////// A more practical example
s = Server.default;
s.boot;
s.sendMsg(\g_new, x = s.nextNodeID);
// ...
// now if we need to use Node objects for some reason
y = Synth.head(x.asTarget, "default");
// this is simpler than Group.basicNew(s, x);, providing you're using the default server:
z = Synth.head(Group.basicNew(s, x), "default");
y.free; z.free; x.asTarget.free;