Synth nodes in the Node Tree window run from top to bottom. The most recent synths get added to the top by default. In figure \ref{fig:node-tree}, you can see that noise is on top, so it’s the first to be calculated. Then filter comes second, and masterOut comes last. This is the right order we want. If you now try running the example again, but evaluating the lines m, f, and n in reverse order, you will hear nothing, because the signals are being calculated in the wrong order.

Evaluating the right lines in the right order is fine, but it might get tricky as your code becomes more complex. In order to make this job easier, SuperCollider allows you to explicitly define where to place synth in the Node Tree. For this we use the addAction argument.

n = Synth("noise", addAction: 'addToHead');
m = Synth("masterOut", addAction: 'addToTail');
f = Synth("filter", target: n, addAction: 'addAfter');

Now, no matter in what order you execute the lines above, you can be sure that nodes will fall in the right places. The noise synth is explicitly told to be added to the head of the Node Tree; masterOut is added to the tail; and filter is explicitly added right after target n (the noise synth).

Groups

When you start to have lots of synths—some of them for source sounds, other for effects, or whatever you need—it may be a good idea to organize them into groups. Here’s a basic example:

// Keep watching everything in the NodeTree
s.plotTree;
// Create some buses
~reverbBus = Bus.audio(s, 2);
~masterBus = Bus.audio(s, 2);
// Define groups in proper order
~sources = Group.new
~effects = Group.new(~sources, \addAfter);
~master = Group.new(~effects, \addAfter);
// This is the source sound
{Out.ar(~reverbBus, SinOsc.ar([800, 890])*LFPulse.ar(2)*0.1)}.play(target: ~sources);
// This is some reverb
{Out.ar(~masterBus, FreeVerb.ar(In.ar(~reverbBus, 2), mix: 0.5, room: 0.9))}.play(target: ~effects);
// Some silly master volume control with mouse
{Out.ar(0, In.ar(~masterBus, 2) * MouseY.kr(0, 1))}.play(target: ~master);

For more information about order of execution, look up the Help files “Synth,” “Order of Execution,” and “Group.”