Overview
The Server
The server is a Programm, that runs in the Background of your computer. Every sound of SuperCollider is made on the server. The server is the sound engine, so to speak. To create sounds you need to start / boot the server. After this you can send messages made up of the sclang from your IDE to the server.
Your localhost server has the reserved chracter s. The server is also an object and you can boot and quit your server with these methods:
s.boot;
s.quit;Change the SR and Blocksize
(
Server.local.options.sampleRate = 48000;
// sample rate can be checked in post window
Server.local.options.blockSize = 16;
// block size can be checked via
// s.options.blockSize; after boot
s.boot;
)
// check the blocksize
s.options.blockSize;
// end your test
s.quitChoose Input and Output Device
SuperCollider can show you the avaiable input and output devices without starting the server with these commands:
ServerOptions.devices; // all devices
ServerOptions.inDevices; // input devices
ServerOptions.outDevices; // output devicesAfter this you can choose the devices with these commands:
Server.default.options.inDevice_("Built-in Microph");
Server.default.options.outDevice_("Built-in Output");
// for in and ouput
Server.default.options.device_("MOTU 828");UGen Graphs
From time to time you can run into this error message: "exceeded number of interconnect buffers" . There is a default limit of allowed interconnections in a UGen Buffer of 64, you can rise this with s.options.numWireBufs_(NUM).
Server Hygiene
When working on bigger projects it is recommended to prepare a Setup section in your project, which is responsible for cleaning up the server and setup everything up for working.
The common way for this is to use the classes ServerBoot, ServerQuit, ServerTree and CmdPeriod.
These classes can be used, to add functions to a list of functions, that is executed when the Server is booted, quit, the Server Tree is build or when Cmd + . is used.
When ServerBoot and ServerQuit are executed is quit clear. ServerTree is part of the server boot process: when the server is booted, ServerTree is executed. But ServerTree is also executed after CmdPeriod is used.
Check this example:
(
~testTree = { "tree is build".postln };
~testPeriod = { "CmdPeriod is used".postln };
ServerTree.add(~testTree); // registers a function the the ServerTree list of functions
CmdPeriod.add(~testPeriod); // registers a function the the CmdPeriod list of functions
)
CmdPeriod.run; // runs CmdPeriodA setup section could be something like this:
~setup = {
s.plotTree; // show node tree
s.newBusAllocators; // resets the bus allocator counter
~fxBus = Bus.audio(s, 2);
~mstBus = Bus.audio(s, 2);
s.bind({ // everything inside s.bind is executed synchron on the server, the client has no time to interrupt
~srcGrp = Group.new;
~fxGrp = Group.after(~srcGrp);
});
};
ServerTree.removeAll;
ServerTree.add(~setup);
CmdPeriod.run;The cleanup could be something like this:
(
~cleanup = {
s.freeAll; // stop and delete all Synths, Groups and Routings, that are running on the server right now
Buffer.freeAll; // free all buffer on the server
Window.closeAll; // close all SC-GUI-Fenster
ServerBoot.removeAll; // clear list, which is execute when server is booted
ServerQuit.removeAll; // clear list, which is executed when server is quit
ServerTree.removeAll; // clear list, which is executed when the server tree is build (part of the server boot)
CmdPeriod.removeAll; // clear list, which is executed when Cmd + . is used
TempoClock.default.clear; // clear all processes, which are scheduled on the TempoClock
};
ServerQuit.add(~cleanup); // add the function to the list, which is executed when server is quit
~cleanup.(); // execute function
)