2 summary:: Mark Polishook tutorial
3 categories:: Tutorials>Mark_Polishook_tutorial
4 related:: Tutorials/Mark_Polishook_tutorial/00_Introductory_tutorial
6 The simplest synthesis processes use a single ugen.
9 { Saw.ar(500, 0.1) }.scope;
15 { Formlet.ar(Saw.ar(22), 400, 0.01, 0.11, 0.022) }.scope
18 Most of the SuperCollider help documents for the UGens show other such examples.
22 ////////////////////////////////////////////////////////////////////////////////////////////////////
24 Many synthesis processes, because they use more than a few ugens, are often best divided into component parts. This can make code modular, resusable, and easier to read.
26 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.
28 section::Groups are linked lists
30 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."
32 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.
34 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.
36 section::Nodes, linked lists, trees
38 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.
41 ## http://en.wikipedia.org/wiki/Node
42 ## http://en.wikipedia.org/wiki/Linked_list
43 ## http://en.wikipedia.org/wiki/Tree_data_structure
46 section::RootNode and default_group
48 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
61 will appear in the transcript window.
63 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).
65 ////////////////////////////////////////////////////////////////////////////////////////////////////
67 New synths are attached by default to the head of the default_group.
70 // 1st, evaluate a synthdef
72 SynthDef("ringModulation", {
76 SinOsc.ar([440.067, 441.013], 0, 1)
78 SinOsc.ar([111, 109], 0, 0.2)
86 Synth("ringModulation");
89 // 3rd, tell the server to list its nodes
101 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.
107 default_node - Group(1)
113 ////////////////////////////////////////////////////////////////////////////////////////////////////
115 An example with two synths.
118 // 1st, evaluate a synthdef
120 SynthDef("pitchFromNoise", { arg out = 0;
125 LFNoise0.kr(2, 110, 660),
132 // 2nd, make 2 synths
134 Synth("ringModulation");
135 Synth("pitchFromNoise", [\out, 1]);
138 // 3rd, tell the server to list its nodes
144 The printout in the transcript window
153 shows that Group(0) is the rootnode and Group(1) is the default_node.
155 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).
161 default_node - Group(1)
164 Synth 1005 Synth 1004
168 ////////////////////////////////////////////////////////////////////////////////////////////////////
170 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.
174 SynthDef("firstNode-source", {
177 Saw.ar([200, 201], 0.05)
181 SynthDef("secondNode-filter", {
187 LFNoise0.kr([4, 4.001], 500, 1000),
195 // evaluate "secondNode-filter" first
196 // "firstNode-source" will go at the head of default_node
198 Synth("secondNode-filter");
199 Synth("firstNode-source");
207 ////////////////////////////////////////////////////////////////////////////////////////////////////
209 Or, use .head and .tail messages to attach the the nodes to the default_group).
213 Synth.head(s, "firstNode-source");
214 Synth.tail(s, "secondNode-filter");
222 ////////////////////////////////////////////////////////////////////////////////////////////////////
224 Or, assign the synths to groups.
228 ~source = Group.head(s); // attach the group to the head of the default_node
229 ~effect = Group.tail(s); // attach the group to the tail of the default_node
233 // add the synths to the appropriate groups
234 Synth.head(~effect, "secondNode-filter");
235 Synth.head(~source, "firstNode-source");
239 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.
242 // run the code to see a diagram of the nodes
261 ////////////////////////////////////////////////////////////////////////////////////////////////////
263 Set a control for all of the synths in a group.
266 // each of the synthdefs below has a control for amplitude (mul)
268 // build 3 synthdefs and a group
269 SynthDef("synthNumber1", { arg mul = 0.2;
272 BrownNoise.ar(mul) * LFNoise0.kr([1, 1.01])
275 SynthDef("synthNumber2", { arg mul = 0.2;
278 WhiteNoise.ar(mul) * LFNoise1.kr([2.99, 3])
281 SynthDef("synthNumber3", { arg mul = 0.2;
284 PinkNoise.ar(mul) * LFNoise2.kr([0.79, 0.67])
291 ~myGroup = Group.new;
296 Synth.head(~myGroup, "synthNumber1");
297 Synth.head(~myGroup, "synthNumber2");
298 Synth.head(~myGroup, "synthNumber3");
301 // set the \mul control of each of the 3 synths in the group
302 ~myGroup.set(\mul, 0.01.rrand(0.2))
304 // execute to see a diagram of the nodes
310 ////////////////////////////////////////////////////////////////////////////////////////////////////
312 go to link::Tutorials/Mark_Polishook_tutorial/16_Playbuf::