1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"824.42">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
; min-height: 17.0px}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #79331d}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
18 span
.s1
{color: #000000}
19 span
.s2
{color: #0022ac}
20 span
.s3
{color: #002de6}
21 span
.s4
{color: #606060}
22 span
.Apple-tab-span
{white-space:pre
}
26 <p class=
"p1"><b>Client versus Server Architecture and Operations
</b></p>
27 <p class=
"p2"><br></p>
28 <p class=
"p3">The name
"SuperCollider" is in fact used to indicate five different things (Figure
1):
</p>
29 <p class=
"p3"><span class=
"Apple-tab-span"> </span>1. an audio server
<span class=
"Apple-converted-space"> </span></p>
30 <p class=
"p3"><span class=
"Apple-tab-span"> </span>2. an audio programming language
</p>
31 <p class=
"p3"><span class=
"Apple-tab-span"> </span>3. an interpreter for the language, i.e. a program able to interpret it
</p>
32 <p class=
"p3"><span class=
"Apple-tab-span"> </span>4. the interpreter program as a client for the server
</p>
33 <p class=
"p3"><span class=
"Apple-tab-span"> </span>5. the application including the two programs and providing mentioned functionalities
</p>
34 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
35 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
36 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><img src=
"attachments/ClientVsServer/structureEn.png" alt=
"attachments/ClientVsServer/structureEn.png"></p>
37 <p class=
"p2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
38 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>Figure
1. Structure of the SuperCollider application
</b></p>
39 <p class=
"p2"><br></p>
40 <p class=
"p3">The SuperCollider application is thus made up of two distinct, autonomous, components, a
<i>server
</i> and a
<i>client
</i>. The first is named
<i>scsynth
</i> (SC-synthesizer), the second
<i>sclang
</i> (SC-language).
</p>
41 <p class=
"p2"><br></p>
42 <p class=
"p4"><b>Description
</b></p>
43 <p class=
"p5"><br></p>
44 <p class=
"p3">The SuperCollider application makes use of client/server architecture which separates two functions, respectively one providing and the other requesting services. The client and the server communicate through a network.
<span class=
"Apple-converted-space"> </span></p>
45 <p class=
"p2"><br></p>
46 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><img src=
"attachments/ClientVsServer/s8kfFC-clientServerEn.png" alt=
"attachments/ClientVsServer/s8kfFC-clientServerEn.png"></p>
47 <p class=
"p3"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Figure
2. Client/Server architecture
</b></p>
48 <p class=
"p2"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></p>
49 <p class=
"p2"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></p>
50 <p class=
"p3">In Figure
2 a generic network architecture is depicted: A number of clients communicating with a server by exchanging messages through a network. In SuperCollider the client and the server make use of a specific subset of CNMAT's Open Sound Control (OSC) protocol in order to communicate (over TCP or UDP). As a consequence, you will see many references to
"OSC messages" in the help files.
</p>
51 <p class=
"p2"><br></p>
52 <p class=
"p3">To avoid any possible confusion: The network is defined at an abstract level. This means that the client(s) and the server(s) can be in execution on the same physical machine. This is what normally happens when you use the SuperCollider application: two programs will run on your machine, scsynth and sclang.
</p>
53 <p class=
"p2"><br></p>
54 <p class=
"p3">The server app,
<i>scsynth
</i>, is a lean and efficient command line program dedicated to audio synthesis and processing. It knows nothing about SC code, objects, Object Oriented Programming, or anything else to do with the SC language.
</p>
55 <p class=
"p2"><br></p>
56 <p class=
"p3">The client of this server is
<i>sclang
</i>. Sclang performs two distinct tasks:
</p>
57 <p class=
"p3"><b>1.
</b> it is the
<i>client
</i> for the server, i.e. it sends OSC messages to the server.
</p>
58 <p class=
"p3">In order to write a letter to server, you need a paper sheet and a mailer: sclang is both.
</p>
59 <p class=
"p3"><b>2.
</b>it is the
<i>interpreter
</i> for the SuperCollider programming language, i.e. it allows to the user to write code in the aforementioned language and interactively execute the resulting commands, e.g. to control the audio server. In particular OSC messages can be cumbersome to write, as they share with the server its low-level perspective. The SuperCollider language is a high-level, fully featured object oriented language, allowing the user to gain a much more expressive power than OSC messages. Typically, the interpreter translates the code in SuperCollider language in OSC messages for the server. The user writes poetry (so to speak) in the SuperCollider language which is then paraphrased in OSC prose by the sclang interpreter, to be sent to the server.
<span class=
"Apple-converted-space"> </span></p>
60 <p class=
"p2"><br></p>
61 <p class=
"p3">From inside sclang, starting a server app can be accomplished by:
</p>
62 <p class=
"p6"><br></p>
63 <p class=
"p7"><span class=
"s1">s =
</span><span class=
"s2">Server
</span><span class=
"s1">.default;
<span class=
"Apple-tab-span"> </span></span>// create a new Server object and assign it to variable s
<span class=
"Apple-converted-space"> </span></p>
64 <p class=
"p7"><span class=
"s1">s.boot;
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// boot the server app, i.e. tell the server to be ready to work
</p>
65 <p class=
"p2"><br></p>
66 <p class=
"p3">The sclang interpreter can send OSC messages to scsynth in two fashions:
</p>
67 <p class=
"p2"><br></p>
68 <p class=
"p3"><b>- directly
</b>: in this case, sclang offers a thin syntax layer which allows one to deal with raw OSC messages. All the server's functionality is in this case available
"by hand" using the .sendMsg method of
<a href=
"../ServerArchitecture/Server.html"><span class=
"s3">Server
</span></a>, and other similar messages.
<span class=
"Apple-converted-space"> </span></p>
69 <p class=
"p6"><br></p>
70 <p class=
"p7"><span class=
"s1">n = s.nextNodeID;
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// get an available nodeID from the server and assign it to n
</p>
71 <p class=
"p7"><span class=
"s1">s.sendMsg(
</span><span class=
"s4">"/s_new"</span><span class=
"s1">,
</span><span class=
"s4">"default"</span><span class=
"s1">, n);
<span class=
"Apple-tab-span"> </span></span>// use the SynthDef
"default" to create a synth with ID n
<span class=
"Apple-converted-space"> </span></p>
72 <p class=
"p7"><span class=
"s1">s.sendMsg(
</span><span class=
"s4">"/n_free"</span><span class=
"s1">, n);
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// release the synth n
<span class=
"Apple-tab-span"> </span></p>
73 <p class=
"p2"><br></p>
74 <p class=
"p3"><b>- indirectly
</b>: the language app provides you with convienent OOP functionality to keep track of and manipulate things on the server. The high-level syntax is translated into low-level OSC messages by sclang and sent to the server (
<i>language wrapping
</i>).
</p>
75 <p class=
"p2"><br></p>
76 <p class=
"p7"><span class=
"s1">x =
</span><span class=
"s2">Synth
</span><span class=
"s1">(
</span><span class=
"s4">"default"</span><span class=
"s1">);
<span class=
"Apple-tab-span"> </span></span>// create a synth on the default server (s) and allocate an ID for it
</p>
77 <p class=
"p7"><span class=
"s1">x.free;
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// free the synth, its ID and resources
</p>
78 <p class=
"p6"><br></p>
79 <p class=
"p3">Working this way you have gained certain functionality. It provides a node ID for you automatically, it allows you to control the Synth in syntactically elegant and efficient ways (see the
<a href=
"../ServerArchitecture/Synth.html"><span class=
"s3">Synth
</span></a> and
<a href=
"../ServerArchitecture/Node.html"><span class=
"s3">Node
</span></a> helpfiles), and to access all the advantages of object oriented programming while doing so.
<span class=
"Apple-converted-space"> </span>Encapsulating the complexities and bookeeping greatly reduces the chance of bugs in your own code.
</p>
80 <p class=
"p2"><br></p>
81 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><img src=
"attachments/ClientVsServer/scEn.png" alt=
"attachments/ClientVsServer/scEn.png"></p>
82 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>Figure
3. Sclang as a high-level client.
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
83 <p class=
"p2"><span class=
"Apple-converted-space"> </span></p>
84 <p class=
"p2"><span class=
"Apple-converted-space"> </span></p>
85 <p class=
"p3">Language wrapping allows the user to access complex behaviours from very little code. Figure
3 (ignore for the moment that sclang is represented as a client among other possible ones, see later) schematically represents what happens when you evaluate an audio function like this:
</p>
86 <p class=
"p2"><br></p>
87 <p class=
"p7">// assuming the server is already booted
</p>
88 <p class=
"p8">{
<span class=
"s2">SinOsc
</span>.ar}.play ;
</p>
89 <p class=
"p2"><br></p>
90 <p class=
"p3">In this case many server operations are hidden. To understand the
<span class=
"Apple-converted-space"> </span>passages inolved in the evalutation of this code see
<a href=
"../Tutorials/Getting-Started/Functions and Other Functionality.html"><span class=
"s3">Functions and Other Functionality
</span></a><b> </b>and
<a href=
"../Tutorials/Getting-Started/SynthDefs and Synths.html"><span class=
"s3">SynthDefs and Synths
</span></a><span class=
"s3"> </span>(part of Scott Wilson's tutorial).
</p>
91 <p class=
"p2"><br></p>
92 <p class=
"p3">The OOP-style also has a small amount of overhead. It requires clientside CPU cycles and memory to create and manipulate an object. Normally this is not significant, but there may be times when you would prefer to use the less elegant, and less expensive first method, for instance when creating large numbers of grains which will simply play and then deallocate themselves.
</p>
93 <p class=
"p2"><br></p>
94 <p class=
"p3">Thus it is possible to create synth nodes on the server without actually creating Synth objects, providing you are willing to do the required housekeeping yourself. The same is true of group nodes, buffers, and buses. A more detailed discussion of these concepts can be found in the
<a href=
"../ServerArchitecture/NodeMessaging.html"><span class=
"s3">NodeMessaging
</span></a> helpfile.
</p>
95 <p class=
"p2"><br></p>
96 <p class=
"p3">In conclusion, the crucial thing to remember is the distinction between things like nodes, busses, buffers, and servers and the objects that represent them in the language app (i.e. instances of
<a href=
"../ServerArchitecture/Node.html"><span class=
"s3">Node
</span></a>,
<a href=
"../ServerArchitecture/Bus.html"><span class=
"s3">Bus
</span></a>,
<a href=
"../ServerArchitecture/Buffer.html"><span class=
"s3">Buffer
</span></a>, and
<a href=
"../ServerArchitecture/Server.html"><span class=
"s3">Server
</span></a>; these are referred to as 'Server Abstraction Objects'). Keeping these conceptually distinct will help avoid much confusion.
</p>
97 <p class=
"p2"><br></p>
98 <p class=
"p2"><br></p>
99 <p class=
"p4"><b>Pros/Cons
</b></p>
100 <p class=
"p2"><br></p>
101 <p class=
"p3">The client/server architecture provides three main advantages:
</p>
102 <p class=
"p2"><br></p>
103 <p class=
"p3"><b>stability
</b>: if the client crashes, the server keeps on working, i.e. the audio does not stop. This is intuitively relevant for a live situation. Vice versa, the server can crash letting you still manage the situation from the client.
</p>
104 <p class=
"p2"><br></p>
105 <p class=
"p3"><b>modularity
</b>: synthesis is one thing, control another. Separating the two aspects allows one to (for example) control scsynth from applications besides sclang. The only important thing is that they are able to send the right OSC messages to the server.
<span class=
"Apple-converted-space"> </span></p>
106 <p class=
"p2"><br></p>
107 <p class=
"p3"><b>remote control
</b>: the client/server network can be external to your computer, e.g. over the Internet. This allows one to control an audio server in Alaska from a client (sclang or other) in India, for example.
<span class=
"Apple-converted-space"> </span></p>
108 <p class=
"p2"><br></p>
109 <p class=
"p3">There are two notable drawbacks:
<span class=
"Apple-converted-space"> </span></p>
110 <p class=
"p2"><br></p>
111 <p class=
"p3"><b>latency:
</b>The messaging process introduces a small amount of latency. This should not be confused with audio latency which can be quite low. It only means that there is a small, usually insignificant delay between the one side sending a message and the other receiving it and acting upon it. (This can be minimized by using the 'internal' server. See
<a href=
"../ServerArchitecture/Server.html"><span class=
"s3">Server
</span></a> for more detail.)
</p>
112 <p class=
"p2"><br></p>
113 <p class=
"p3"><b>asynchronous execution:
</b> In some cases the client might need to know that a task on the server (for instance processing a large sound file) has been completed before continuing with another task. Since some tasks take an arbitrary length of time to complete, a reply mechanism is necessary. This can add some complexity to your code, but is in principle not an issue. (See
<a href=
"../Control/OSCresponder.html"><span class=
"s3">OSCresponder
</span></a> and
<a href=
"../Control/OSCresponderNode.html"><span class=
"s3">OSCresponderNode
</span></a>.) Some server abstraction objects such as
<a href=
"../ServerArchitecture/Buffer.html"><span class=
"s3">Buffer
</span></a> provide for this automatically through 'action' functions which wait for completion before executing.
</p>
114 <p class=
"p2"><br></p>
115 <p class=
"p2"><br></p>
116 <p class=
"p4"><b>A final remark for the advanced reader
</b></p>
117 <p class=
"p2"><br></p>
118 <p class=
"p3">Apart from sclang, it is possible to control scsynth from any other client which provides for OSC messaging (e.g. from Java, Python, Max/MSP, etc.). For networking, see
<a href=
"../ServerArchitecture/Server-Architecture.html"><span class=
"s3">Server-Architecture
</span></a>,
<a href=
"../Control/NetAddr.html"><span class=
"s3">NetAddr
</span></a>,
<a href=
"../Control/OSCresponder.html"><span class=
"s3">OSCresponder
</span></a>,
<a href=
"../Control/OSCresponderNode.html"><span class=
"s3">OSCresponderNode
</span></a>.
</p>
119 <p class=
"p2"><br></p>
120 <p class=
"p3">In general however, sclang is the preferable way to communicate with scsynth for three reasons:
<span class=
"Apple-converted-space"> </span></p>
121 <p class=
"p3">- it gives you the expressive power of the SuperCollider language;
</p>
122 <p class=
"p3">- the language is explicitly fitted to scsynth's needs (and, more importantly, to musician's ones)
<span class=
"Apple-converted-space"> </span></p>
123 <p class=
"p3">- it allows one to create and load SynthDefs onto scsynth (see
<a href=
"../ServerArchitecture/SynthDef.html"><span class=
"s3">SynthDef
</span></a>), which is a not such an easy task to accomplished in another client app.
</p>
124 <p class=
"p2"><br></p>