1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
title:: 15_Groups
summary:: Mark Polishook tutorial
categories:: Tutorials>Mark_Polishook_tutorial
related:: Tutorials/Mark_Polishook_tutorial/00_Introductory_tutorial
The simplest synthesis processes use a single ugen.
code::
{ Saw.ar(500, 0.1) }.scope;
::
or
code::
{ Formlet.ar(Saw.ar(22), 400, 0.01, 0.11, 0.022) }.scope
::
Most of the SuperCollider help documents for the UGens show other such examples.
link::Browse#UGens::
////////////////////////////////////////////////////////////////////////////////////////////////////
Many synthesis processes, because they use more than a few ugens, are often best divided into component parts. This can make code modular, reusable, and easier to read.
The link::Classes/Group:: class, which is the means to specify a collection of nodes, provides a mechanism through which to control several synths at once.
section::Groups are linked lists
The important technical feature of groups is that the nodes they contain are items in a linked list. A linked list is a data structure that makes it easy to order and reorder nodes. The first item in a linked list is the "head" and the last item is the "tail."
Groups, through their head and tail mechanisms, allow synths to be placed in order so one synth verifiably executes before another, eg, the head synth runs before the tail synth. The ability to order synths is essential when sending source audio through an effect, such as a reverb or a filter.
Another feature of groups is they allow synths to receive messages from a single point of control, eg, one message to the group goes to all of nodes that belong to the group.
section::Nodes, linked lists, trees
See the link::Reference/Server-Architecture:: document for a definition of a node in SuperCollider or look to the Wikipedia for a general discussion of nodes, linked lists, and trees.
list::
## http://en.wikipedia.org/wiki/Node
## http://en.wikipedia.org/wiki/Linked_list
## http://en.wikipedia.org/wiki/Tree_data_structure
::
section::RootNode and default_group
By default, the localhost and internal servers each boot with two predefined groups: the link::Classes/RootNode:: and the link::Reference/default_group:: (see their help files). To see this, start the localhost server and then evaluate
code::
s.queryAllNodes;
::
The next two lines
code::
Group(0)
Group(1)
::
will appear in the transcript window.
Group(0) is the rootnode group and Group(1) is the default_group. Group(1) is indented to show that it branches from Group(0).
////////////////////////////////////////////////////////////////////////////////////////////////////
New synths are attached by default to the head of the default_group.
code::
// 1st, evaluate a synthdef
(
SynthDef("ringModulation", {
Out.ar(
0,
Mix.ar(
SinOsc.ar([440.067, 441.013], 0, 1)
*
SinOsc.ar([111, 109], 0, 0.2)
)
)
}).add;
)
// 2nd, make a synth
(
Synth("ringModulation");
)
// 3rd, tell the server to list its nodes
(
s.queryAllNodes;
)
::
code::
Group(0)
Group(1)
Synth 1003
::
will appear in the transcript window. It shows Group(0) as the rootnode, Group(1) as the branching default_node and Synth 1003 (or some such number) as a leaf attached to the default_node.
code::
Rootnode - Group(0)
|
|
default_node - Group(1)
/
/
Synth 1003
::
////////////////////////////////////////////////////////////////////////////////////////////////////
An example with two synths.
code::
// 1st, evaluate a synthdef
(
SynthDef("pitchFromNoise", { arg out = 0;
Out.ar(
out,
Resonz.ar(
WhiteNoise.ar(15),
LFNoise0.kr(2, 110, 660),
0.005
)
)
}).add;
)
// 2nd, make 2 synths
(
Synth("ringModulation");
Synth("pitchFromNoise", [\out, 1]);
)
// 3rd, tell the server to list its nodes
(
s.queryAllNodes;
)
::
The printout in the transcript window
code::
Group(0)
Group(1)
Synth 1005
Synth 1004
::
shows that Group(0) is the rootnode and Group(1) is the default_node.
Synth 1005 and 1004 (or similar such numbers) are leaves attached to the default_node. Synth 1005 is first in the list because of the way nodes are attached, by default, to the head of a list: Synth 1004, the "ringModulation" synth, was evaluated first and attached to the head of Group(1). Then Synth 1005, the "pitchFromNoise"s synth, was evaluated and placed at the head of the list (in front of Synth 1004).
code::
Rootnode - Group(0)
|
|
default_node - Group(1)
/ \
/ \
Synth 1005 Synth 1004
(head) (tail)
::
////////////////////////////////////////////////////////////////////////////////////////////////////
It's the responsibility of the user to make sure that nodes on the server are ordered properly. For this reason, the two synths below must be evaluated in the order in which they're given - because the first synth is source material for the second synth, a filter that processes its input.
code::
(
SynthDef("firstNode-source", {
Out.ar(
0,
Saw.ar([200, 201], 0.05)
)
}).add;
SynthDef("secondNode-filter", {
ReplaceOut.ar(
0,
LPF.ar(
In.ar(0, 2),
Lag.kr(
LFNoise0.kr([4, 4.001], 500, 1000),
0.1
)
)
)
}).add;
)
// evaluate "secondNode-filter" first
// "firstNode-source" will go at the head of default_node
(
Synth("secondNode-filter");
Synth("firstNode-source");
)
(
s.queryAllNodes;
)
::
////////////////////////////////////////////////////////////////////////////////////////////////////
Or, use .head and .tail messages to attach the nodes to the default_group).
code::
(
Synth.head(s, "firstNode-source");
Synth.tail(s, "secondNode-filter");
)
(
s.queryAllNodes;
)
::
////////////////////////////////////////////////////////////////////////////////////////////////////
Or, assign the synths to groups.
code::
(
~source = Group.head(s); // attach the group to the head of the default_node
~effect = Group.tail(s); // attach the group to the tail of the default_node
)
(
// add the synths to the appropriate groups
Synth.head(~effect, "secondNode-filter");
Synth.head(~source, "firstNode-source");
)
::
The idea is that the groups are attached first to the default_group in the desired order. The synths can then be evaluated in any order as long as they're attached to the appropriate group.
code::
// run the code to see a diagram of the nodes
(
s.queryAllNodes;
)
::
code::
Rootnode
|
|
default_node
/\
/ \
Group Group
| |
| |
Synth Synth
::
////////////////////////////////////////////////////////////////////////////////////////////////////
Set a control for all of the synths in a group.
code::
// each of the synthdefs below has a control for amplitude (mul)
(
// build 3 synthdefs and a group
SynthDef("synthNumber1", { arg mul = 0.2;
Out.ar(
0,
BrownNoise.ar(mul) * LFNoise0.kr([1, 1.01])
)
}, [0.1]).add;
SynthDef("synthNumber2", { arg mul = 0.2;
Out.ar(
0,
WhiteNoise.ar(mul) * LFNoise1.kr([2.99, 3])
)
}, [0.1]).add;
SynthDef("synthNumber3", { arg mul = 0.2;
Out.ar(
0,
PinkNoise.ar(mul) * LFNoise2.kr([0.79, 0.67])
)
}, [0.1]).add;
)
(
// make a group
~myGroup = Group.new;
)
(
// attach 3 synths
Synth.head(~myGroup, "synthNumber1");
Synth.head(~myGroup, "synthNumber2");
Synth.head(~myGroup, "synthNumber3");
)
// set the \mul control of each of the 3 synths in the group
~myGroup.set(\mul, 0.01.rrand(0.2))
// execute to see a diagram of the nodes
(
s.queryAllNodes;
)
::
////////////////////////////////////////////////////////////////////////////////////////////////////
go to link::Tutorials/Mark_Polishook_tutorial/16_Playbuf::
|