supernova: c++11 compile fix
[supercollider.git] / Help / ServerArchitecture / default_group.html
blob143ffcc81fa44463f74c63b4a5650b8d02c2c4fc
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.42">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #a71e12}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #a71e12; min-height: 12.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0019b7; min-height: 12.0px}
19 span.s1 {font: 13.0px Helvetica}
20 span.s2 {color: #0019b7}
21 span.s3 {color: #000000}
22 span.s4 {color: #326f17}
23 span.s5 {text-decoration: underline}
24 span.s6 {color: #606060}
25 span.s7 {color: #a71e12}
26 span.Apple-tab-span {white-space:pre}
27 </style>
28 </head>
29 <body>
30 <p class="p1"><b>The default Group<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b><span class="s1"><b>id:1</b></span></p>
31 <p class="p2"><br></p>
32 <p class="p2"><br></p>
33 <p class="p3"><b>root node (id:0) [</b></p>
34 <p class="p3"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>default group (id:1)</b></p>
35 <p class="p3"><b>]</b></p>
36 <p class="p2"><br></p>
37 <p class="p4">When a <b>Server</b> is booted there is a top level group with an ID of 0 that defines the root of the node tree. (This is represented by a subclass of Group: <b>RootNode</b>.) If the Server was booted from within SCLang (as opposed to from the command line) a default group with an ID of 1 will be automatically created. This is the default target for all Nodes when using object style and is what you will get if you supply a Server as a target. If you don't specify a target or pass in nil, you will get the default group of the default Server. <span class="Apple-converted-space"> </span></p>
38 <p class="p2"><br></p>
39 <p class="p5"><span class="s2">Server</span>.default.boot;</p>
40 <p class="p6"><span class="s3">a = </span><span class="s2">Synth</span><span class="s3">.new(</span><span class="s4">\default</span><span class="s3">); </span>// creates a synth in the default group of the default Server</p>
41 <p class="p6"><span class="s3">a.group; </span>// note the Group ID</p>
42 <p class="p2"><br></p>
43 <p class="p4">The default group serves an important purpose: It provides a predictable basic Node tree so that methods such as Server-scope, Server-record, etc. can function without running into order of execution problems. In the example below the scoping node will come after the default group.</p>
44 <p class="p2"><br></p>
45 <p class="p5"><span class="s2">Server</span>.internal.boot;</p>
46 <p class="p7"><br></p>
47 <p class="p5">{ <span class="s2">SinOsc</span>.ar(mul: 0.2) }.scope(1);</p>
48 <p class="p8"><br></p>
49 <p class="p6">// watch the post window;</p>
50 <p class="p5"><span class="s2">Server</span>.internal.queryAllNodes;<span class="Apple-converted-space"> </span></p>
51 <p class="p7"><br></p>
52 <p class="p6">// our SinOsc synth is within the default group (ID 1)</p>
53 <p class="p6">// the scope node comes after the default group, so no problems</p>
54 <p class="p9"><br></p>
55 <p class="p5"><span class="s2">Server</span>.internal.quit;</p>
56 <p class="p2"><br></p>
57 <p class="p4">Note that the default group is persistent: It is created in Server's initTree method (executed along with any code stored in its tree instance variable; see <b>Server </b>for more detail) and is recreated upon reboot, after pressing Cmd-., and after all nodes are freed. When using osc messages this means <span class="s5">that a target node of id 1 can always be used</span>:</p>
58 <p class="p7"><br></p>
59 <p class="p5">s.sendMsg(<span class="s6">"/s_new"</span>, <span class="s6">"snd"</span>, 1832,0,1); <span class="s7">// add to head of group 1</span></p>
60 <p class="p2"><br></p>
61 <p class="p4">The default group can be specifically freed, but there is generally no reason that one would want to do so.</p>
62 <p class="p2"><br></p>
63 <p class="p4">In general one should add nodes to the default group rather than the RootNode unless one has a specific reason to do so (i.e. adding some new functionality such as recording and scoping which is dependent upon a predictable basic node order). When using object style the default group is the default target for all new nodes, so nodes will normally not be added to the RootNode unless that is explicitly specified. It is of course possible to do so, but it should only be done with a proper understanding of the issues involved.<span class="Apple-converted-space"> </span></p>
64 <p class="p2"><br></p>
65 <p class="p4">For instance, if one were to place an 'effects' synth after the default group and call Server-record or Server-scope, the resulting recording or scope synths may not be correctly ordered:</p>
66 <p class="p2"><br></p>
67 <p class="p4"><b>default group [</b></p>
68 <p class="p4"><b><span class="Apple-tab-span"> </span>source synth1</b></p>
69 <p class="p4"><b><span class="Apple-tab-span"> </span>source synth2</b></p>
70 <p class="p4"><b>]</b></p>
71 <p class="p4"><b>recording synth</b></p>
72 <p class="p4"><b>effects synth</b></p>
73 <p class="p2"><br></p>
74 <p class="p4">In the above example the recording synth might not capture the output of the effects synth since it comes later in the node order.</p>
75 <p class="p2"><br></p>
76 <p class="p4">A better method in this case is to create a group within the default group and place the effects synth after that.</p>
77 <p class="p2"><br></p>
78 <p class="p4"><b>default group [</b></p>
79 <p class="p4"><b><span class="Apple-tab-span"> </span>source group [</b></p>
80 <p class="p4"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>source synth1</b></p>
81 <p class="p4"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>source synth2</b></p>
82 <p class="p4"><b><span class="Apple-tab-span"> </span>]</b></p>
83 <p class="p4"><b><span class="Apple-tab-span"> </span>effects synth</b></p>
84 <p class="p4"><b>]</b></p>
85 <p class="p4"><b>recording synth</b></p>
86 <p class="p2"><br></p>
87 <p class="p4">See also: <b>RootNode, NodeMessaging </b>and <b>Order-of-execution</b></p>
88 <p class="p2"><br></p>
89 </body>
90 </html>