# Working with Groups

## Creating Groups

Groups - or group nodes - can be a very useful concept for keeping track of the signal flow. Without any further actions, all nodes are placed in the default Group 1. Additional groups can be arranged regarding the order of execution. A new group can be added from sclang as follows:

~g1 = Group.new();


Synth nodes can be added to groups on creation or afterwards. Any existing node - in this case the ~osc node from the previous example <http://ringbuffer.org/computer_music_basics/SuperCollider/combining-nodes-in-supercollider/> - can be moved to a group using the following commands:

// make it the first node in the group

// make it the last node in the group
~osc.moveToTail(~g1)


## Relative Group Positions

As with nodes, further groups can be added in relation to existing groups. The following action makes sure that a new group will be placed after the previously defined group:

~g2 = Group.after(~g1);


## Nested Groups

Groups can contain other groups, allowing a hierarchical structure of nodes:

~g3 = Group.head(~g2);


## More on Groups

The group object allows many more actions. They are listed in the SC documentation on groups. After adding another group before the third one

~g4 = Group.before(~g3);


the server node structure looks as follows:

The server does not know the groups by their variable names in sclang. Hence they are numerated. Node indices - or IDs - of groups can be assessed from the language:

~g1.nodeID;
~g2.nodeID;
~g3.nodeID;
~g4.nodeID;


### Exercise

Exercise

Use groups to sort the nodes from the example in the section on Combining Nodes