2 summary:: Client-side representation of a group node on the server
3 categories:: Server>Nodes, Server>Abstractions
6 A Group is the client-side representation of a group node on the server, which is a collection of other nodes organized as a linked list.
7 The Nodes within a Group may be controlled together, and may be both link::Classes/Synth::s and other Groups.
8 Groups are thus useful for controlling a number of nodes at once, and when used as targets can be very helpful in controlling order of execution. (See link::Guides/Order-of-execution:: for more details on this topic).
10 For more on the crucial distinction between client objects and server nodes, see link::Guides/ClientVsServer::. For information on creating nodes without using objects, see link::Guides/NodeMessaging::.
12 N.B. Group is a subclass of Node, and thus many of its most useful and important methods are documented in the link::Classes/Node:: help file. Please refer to it for more information.
14 subsection:: RootNode and the default group
16 When a Server is booted there is a top level group with an ID of zero that defines the root of the tree. This is represented by a subclass of Group: link::Classes/RootNode::.
17 If the Server was booted from within SCLang (as opposed to from the command line) then a default_group with an ID of 1 will be automatically created. This group is the default enclosing group for all Nodes, i.e. it's what you get if you don't specify.
18 In general you should create new Nodes within the default group of a Server rather than in its RootNode.
19 See link::Classes/Server::, link::Reference/default_group:: and link::Classes/RootNode:: for more detail.
23 Some of the methods below have two versions: a regular one which sends its corresponding message to the server immediately, and one which returns the message in an link::Classes/Array:: so that it can be added to a bundle.
24 It is also possible to capture the messages generated by the regular methods using Server's automated bundling capabilities. See link::Classes/Server:: and link::Guides/Bundled-Messages:: for more detail.
29 subsection:: Creation with Immediate Instantiation on the Server
32 Create and return a Group.
35 A target for this Group. If target is not a Group or Synth, it will be converted as follows: If it is a Server, it will be converted to the default_group of that server. If it is nil, to the default_group of the default Server.
37 one of the following Symbols:
39 ## \addToHead || (the default) add at the head of the group specified by target
40 ## \addToTail || add at the tail of the group specified by target
41 ## \addAfter || add immediately after target in its server's node order
42 ## \addBefore || add immediately before target in its server's node order
43 ## \addReplace || replace target and take its place in its server's node order
45 Note: A Synth is not a valid target for \addToHead and \addToTail.
49 g = Group.new; // add a Group at the head of the default Server's default group
50 h = Group.new(g, \addAfter);
51 s.queryAllNodes; // note the Group within the default group (ID 1)
55 subsection:: Convenience methods for add actions
56 The following convenience methods correspond to the add actions above:
59 Create and return a Group and add it immediately after aNode.
62 Create and return a Group and add it immediately before aNode.
65 Create and return a Group. If aGroup is a Group add it at the head of that group. If it is a Server, add it at the head of the default_group of that server. If it is nil, add it at the head of the default_group of the default Server.
68 Create and return a Group. If aGroup is a Group add it at the tail of that group. If it is a Server, add it at the tail of the default_group of that server. If it is nil, add it at the tail of the default_group of the default Server.
71 Create and return a Group and use it to replace nodeToReplace, taking its place in its server's node order.
73 subsection:: Creation without Instantiation on the Server
75 For use in message bundles it is also possible to create a Group object in the client app without immediately creating a group node on the server. Once done one can call methods which create messages to add to a bundle, which when sent to the server will instantiate the group or perform other operations. (See strong::Control::, below.)
78 Create and return a Group object without creating a group node on the server. (This method is inherited from Node and is documented here only for convenience.)
80 An optional instance of Server. If nil this will default to the default Server.
82 An optional node ID number. If not supplied one will be generated by the Server's NodeIDAllocator. Normally you should not need to supply an ID.
86 g = Group.basicNew(s); // Create without sending
87 s.sendBundle(nil, g.newMsg;); // Now send a message; create at the head of s' default group
92 After creation, use instance methods code::newMsg, addToHeadMsg, addToTailMsg, addBeforeMsg, addAfterMsg, addReplaceMsg:: to instantiate this synth on the server. See link::#instancemethods#Instance Methods:: below.
97 subsection:: Creation without Instantiation on the Server
98 Use class method code::basicNew:: to create a Synth without instantiating it on the server. Then use the following instance methods:
101 Returns a message of the type g_new which can be bundled. When sent to the server this message will instantiate this group. If target is nil, it will default to the default_group of the Server specified in *basicNew when this Group was created. The default addAction is \addToHead. (See *new above for details of addActions.
103 method:: addToHeadMsg
104 Returns a message of the type g_new which can be bundled. When sent to the server this message will instantiate this group. If aGroup is a Group it will be added at the head of that group. If it is nil, it will be added at the head of the default_group of this Group's server (as specified when *basicNew was called).
106 method:: addToTailMsg
107 Returns a message of the type g_new which can be bundled. When sent to the server this message will instantiate this group. If aGroup is a Group it will be added at the tail of that group. If it is nil, it will be added at the tail of the default_group of this Group's server (as specified when *basicNew was called).
109 method:: addBeforeMsg
110 Returns a message of the type g_new which can be bundled. When sent to the server this message will instantiate this group, immediately before aNode.
113 Returns a message of the type g_new which can be bundled. When sent to the server this message will instantiate this group, immediately after aNode.
115 method:: addReplaceMsg
116 Returns a message of the type g_new which can be bundled. When sent to the server this message will instantiate this group, replacing nodeToReplace in the server's node order.
118 subsection:: Control and Introspection
120 For further methods of controlling Groups (set, map, etc.), see the link::Classes/Node:: help file.
122 method:: moveNodeToHead, moveNodeToHeadMsg
123 Move aNode to the head of this group
125 method:: moveNodeToTail, moveNodeToTailMsg
126 Move aNode to the tail of this group
128 method:: freeAll, freeAllMsg
129 Free all the nodes in this group, but do not free this group itself.
131 method:: deepFree, deepFreeMsg
132 Free all Synths in the group, and all Synths in any enclosed groups, but do not free this group or any of its enclosed groups.
135 Post a representation of this group's node subtree. (Sends a message of the type g_dumpTree.) If code::postControls:: is true, then the current Control (arg) values for any synths contained in this group will be posted as well. The default is false.
138 note:: not working yet ::
139 Queries the server for a message describing this group's node subtree. (Sends a message of the type g_queryTree.) This reply is passed to the action function as an argument. See g_queryTree in Server-Command-Reference or the example below for information on how the reply is structured.
145 s = Server.default; // just to be sure
150 SynthDef("help-Group-moto-rev", { arg out=0,freq=100,ffreq=120;
152 x = RLPF.ar(LFPulse.ar(SinOsc.kr(0.2, 0, 10, freq), [0,0.1], 0.1),
153 ffreq, 0.1).clip2(0.4);
158 SynthDef("help-Group-wah", { arg out, rate = 1.5, cfreq = 1400, mfreq = 1200, rq=0.1;
162 cfreq = Lag3.kr(cfreq, 0.1);
163 mfreq = Lag3.kr(mfreq, 0.1);
164 q = Ramp.kr(rq, 0.1);
165 zout = RLPF.ar(zin, LFNoise1.kr(rate, mfreq, cfreq), q, 10).distort
168 // replace the incoming bus with the effected version
169 ReplaceOut.ar( out , zout );
178 // random freq for each synth, added to g at the head
179 Synth("help-Group-moto-rev",["out",0,"freq",rrand(10,120)],g,\addToHead);
183 // set all controls that match "ffreq" in all nodes in g to 90
188 // since we stored the Synths in an Array, we can also control them individually
193 node.set("freq",rrand(10,120));
202 // g is in a group too. Since we didn't specify it's the default group (ID 1) of the default Server
205 // asking a wah to go order-of-execution after g, in the same group as g.
206 x = Synth.after(g,"help-Group-wah",["out",0]);
208 // now dump my tree to confirm
213 // free all nodes in g, but not g itself
216 // don't forget the Routine is still running...
219 // oh, and set l to nil so the Synths and Array can be garbage collected
222 // and i'm still on the server, its just my children that were freed
225 // don't need the individual synth objects this time
228 // random freq for each synth, added to g at the head
229 Synth("help-Group-moto-rev",["out",0,"freq",rrand(10,1200)],g,\addToHead);
233 // now query my tree and post a graph of it (duplicates dumpTree)
234 // msg format is ['/g_querytree.reply', node1-ID, numChildren, defName, child1-ID, numChildren, ...]
237 // var i = 1, tabs = 0, dumpFunc;
238 // ("NODE TREE Group" + msg[1]).postln;
240 // dumpFunc = {|numChildren|
244 // tabs.do({ " ".post });
246 // (" " ++ msg[i + 2]).postln;
247 // if(msg[i + 1] > 0, { dumpFunc.value(msg[i + 1]) });
251 // dumpFunc.value(msg[2]);
256 // kill me and my children