1class:: Server
2summary:: Object representing a server application
3categories:: Server>Abstractions
4related:: Classes/ServerOptions, Reference/Server-Architecture, Reference/Server-Command-Reference, Classes/ServerStatusWatcher, Reference/AudioDeviceSelection
5
6description::
7
8A Server object is a representation of a server application. It is used to control scsynth (or supernova) from the SuperCollider language. (See link::Guides/Server-Guide::, as well as link::Guides/ClientVsServer:: for more details on the distinction.) It forwards OSC messages and has a number of allocators that keep track of IDs for nodes, buses, and buffers.
9
10The server application represented by a Server object might be running on the same machine as the sclang, or it may be running on a remote machine.
11
12Most of a Server's options are controlled through its instance of ServerOptions. See the link::Classes/ServerOptions:: helpfile for more detail.
13
14A server also holds an instance of a link::Classes/Recorder:: (for recording output into a file) and a link::Classes/Volume:: (master level).
15
16note::
17By default, there is always one default server, which is stored in the interpreter variable 's'. E.g. you can boot the default server by calling code::s.boot::
18::
19
20code::
21s.boot;
22{ SinOsc.ar * 0.1 }.play(s); // play a synth on the server
23::
24
25The server application may be in three different states: running, not running, or unresponsive (for example while loading large files from disk).
26
27code::
28s.serverRunning // returns true if it is true
29::
30
31
32ClassMethods::
33private:: initClass
34
35method:: new
36Create a new Server instance.
37
38argument:: name
39a symbol;  each Server object is stored in one global classvariable under its name.
40
41argument:: addr
42an optional instance of link::Classes/NetAddr::, providing host and port.
43The default is the localhost address using port 57110; the same as the local server.
44
45argument:: options
46an optional instance of link::Classes/ServerOptions::. If code::nil::, an instance of ServerOptions will be created, using the default values.
47
48argument:: clientID
49an integer. In multi-client situations, every client can be given separate ranges for link::Classes/Node##Nodes::, link::Classes/Buffer##Buffers::, or link::Classes/Bus##Busses::. In normal usage, the server will supply an ID automatically when a client registers for the link::#-notify#notifications:: so you should not need to supply one here. N.B. In multi-client situations, you will need to set the link::Classes/ServerOptions#-maxLogins:: to at least the number of clients you wish to allow. This must be the same in the Server instances on every client.
50
51method:: remote
52Create a new Server instance corresponding to a server app running on a separate machine. This method assumes the remote app has been booted and starts listening immediately. You should not call link::#-boot:: on an instance created using this method.
53
54argument:: name
55a symbol;  each Server object is stored in one global classvariable under its name.
56
57argument:: addr
58an optional instance of link::Classes/NetAddr::, providing IP address of the remote machine and port the app is listening on.
59
60argument:: options
61an optional instance of link::Classes/ServerOptions::. If code::nil::, an instance of ServerOptions will be created, using the default values.
62
63argument:: clientID
64an integer. In multi-client situations, every client can be given separate ranges for link::Classes/Node##Nodes::, link::Classes/Buffer##Buffers::, or link::Classes/Bus##Busses::. In normal usage, the server will supply an ID automatically when a client registers for the link::#-notify#notifications:: so you should not need to supply one here. N.B. In multi-client situations, you will need to set the link::Classes/ServerOptions#-maxLogins:: to at least the number of clients you wish to allow. This must be the same in the Server instances on every client.
65
66
67method:: local
68get/set the local server, stored in classvar code::local:: (created already on initClass)
69
70method:: internal
71get/set the internal server, stored in classvar code::internal:: (created already on initClass)
72See: link::Guides/Server-Guide::
73
74method:: default
75Get or set the default server. By default this is the local server (see above).
76discussion::
77Setting this will also assign it to the link::Classes/Interpreter:: variable 's'.
78code::
79// set the internal Server to be the default Server
80Server.default = Server.internal;
81s.postln; // internal
82::
83
84subsection::Accessing all servers
85
86method:: all
87returns:: a link::Classes/Set:: containing all servers.
88
89code::
90Server.all
91::
92
93method:: allRunningServers
94returns:: a Set containing all running servers, according to the definition of link::#-serverRunning::.
95
96code::
97Server.allRunningServers
98::
99
100method:: allBootedServers
101returns:: a Set containing all booted servers, according to the definition of link::#-hasBooted::.
102
103method:: named
104returns:: An link::Classes/IdentityDictionary:: of all servers listed by their name
105
106code::
107Server.named.at(\default)
108::
109
110
111method:: quitAll
112quit all registered servers
113
114method:: killAll
115query the system for any sc-server apps and hard quit them
116
117method:: freeAll
118free all nodes in all registered servers
119
120method:: hardFreeAll
121try to free all nodes in all registered servers, even if the server seems not to be running
122
123method::sync_s
124If kept true (default), when the default server is changed, also the interpreter variable s is changed.
125code::
126Server.default = Server(\alice, NetAddr("127.0.0.1", 57130));
127s.postln; // see: it is alice.
128::
129
130subsection::Switching the server application
131
132method:: supernova
133
134Switches the server program to supernova. Check link::Classes/ParGroup:: how to make use of multicore hardware with the supernova server.
135
136method:: scsynth
137
138Switches the server program to scsynth. This is the default server.
139
140
141InstanceMethods::
142
143private:: doSend, prHandleClientLoginInfoFromServer, prHandleNotifyFailString, prPingApp, prOnServerProcessExit, prWaitForPidRelease
144
145method:: sendMsg
146send an OSC-message to the server.
147discussion::
148code::
149s.sendMsg("/s_new", "default", s.nextNodeID, 0, 1);
150::
151
152method:: sendBundle
153send an OSC-bundle to the server.
154discussion::
155Since the network may have irregular performance, time allows for the bundle to be evaluated at a specified point in the future.
156Thus all messages are synchronous relative to each other, but delayed by a constant offset.
157If such a bundle arrives late, the server replies with a late message but still evaluates it.
158code::
159s.sendBundle(0.2, ["/s_new", "default", x = s.nextNodeID, 0, 1], ["/n_set", x, "freq", 500]);
160::
161
162method:: sendRaw
163
164method:: listSendMsg
165as sendMsg, but takes an array as argument.
166
167method:: listSendBundle
168as sendBundle, but takes an array as argument.
169discussion::
170This allows you to collect messages in an array and then send them.
171code::
172s.listSendBundle(0.2, [["/s_new", "default", x = s.nextNodeID, 0, 1],
173	["/n_set", x, "freq", 600]]);
174::
175
176method:: sendSynthDef
177send a synthDef to the server that was written in a local directory
178
179method:: loadSynthDef
180load a synthDef that resides in the remote directory
181
182method:: loadDirectory
183load all the SynthDefs in the directory dir.
184argument:: dir
185a link::Classes/String:: which is a valid path.
186argument:: completionMsg
187
188method:: nextNodeID
189get a unique nodeID.
190
191method:: nextPermNodeID
192get a permanent node ID. This node ID is in a reserved range and will be held until you explicitly free it.
193
194method:: freePermNodeID
195free a permanent node ID for later reuse.
196
197method:: wait
198this can be used within a link::Classes/Routine:: to wait for a server reply
199
200method:: waitForBoot
201Evaluate "onComplete" as soon as the server has booted. This method will boot the server for you if it is not already running or booting. If the server is already running, "onComplete" is executed immediately.
202argument:: onComplete
203A function to evaluate after the server has booted successfully.
204argument:: limit
205The number of times to check for a successful boot. (5 times/sec)
206argument:: onFailure
207A function to evaluate after the server fails to boot. If onFailure is not given, an error message is posted. Providing a function suppresses the error message. If you want to supply a function and print the normal error message, make sure that your function returns "false," e.g. code::s.waitForBoot(onFailure: { ... custom action...; false })::.
208
209method:: doWhenBooted
210Evaluate "onComplete" as soon as the server has booted. This method assumes the server is being booted explicitly through a separate code::boot:: call. If the server is already running, "onComplete" is executed immediately.
211argument:: onComplete
212A function to evaluate after the server has booted successfully.
213argument:: limit
214The number of times to check for a successful boot.
215argument:: onFailure
216A function to evaluate after the server fails to boot. If onFailure is not given, an error message is posted. Providing a function suppresses the error message. If you want to supply a function and print the normal error message, make sure that your function returns "false," e.g. code::s.doWhenBooted(onFailure: { ... custom action...; false })::.
217
218method:: boot
219boot the remote server, create new allocators.
220argument:: startAliveThread
221If true, start a Routine to send a /status message to the server every so often. The interval between the messages is set by code::theServer.aliveThreadPeriod = (seconds)::. The default period is 0.7. If false, /status will not be sent and the server's window will not update.
222argument:: recover
223If true, create a new node ID allocator for the server, but use the old buffer and bus allocators. This is useful if the server process did not actually stop. In normal use, the default value "false" should be used.
224argument:: onFailure
225In this method, the onFailure argument is for internal use only. If you wish to take specific actions when the server boots or fails to boot, it is recommended to use link::#-waitForBoot:: or link::#-doWhenBooted::.
226
227discussion::
228You cannot boot a server app on a remote machine, but you can initialize the allocators by calling this message.
229
230method:: quit
231quit the server application
232
233argument::onComplete
234A function that is called when quit has completed.
235
236argument::onFailure
237A function that is called when quit has failed.
238
239argument::watchShutDown
240a boolean to tell the server whether to watch status during shutdown.
241
242method:: reboot
243quit and restart the server application
244
245argument::func
246a function that is called between quit and (re-)boot.
247
248argument::onFailure
249A function that is called when quit has failed.
250
251method:: freeAll
252free all nodes in this server
253
254method:: status
255query the server status
256
257method:: notify
258The server sends notifications, for example, if a node was created, a 'tr' message from a link::Classes/SendTrig::, or a strong::/done:: action. If code::flag:: is set to false, these messages will not be sent to this client. The default is true. If true the server will respond with a clientID (scsynth only) which can be useful in multi-client situations. If this is different from any previously received ID new allocators will be created. See link::#Local vs. Remote Servers, Multi-client Configurations:: for more information.
259
260method:: ping
261measure the time between server and client, which may vary. the code::func:: is
262evaluated after code::n:: number of times and is passed the resulting maximum.
263
264method:: options
265Get or set this Server's link::Classes/ServerOptions:: object. Changes to options only take effect when the server is rebooted.
266
267method:: defaultGroup
268Return the default group on this Server for this client ID. This will be the
269same object as code::server.defaultGroups[server.clientID]::.
270
271method:: defaultGroups
272Return an array mapping client IDs to their associated default groups as
273link::Classes/Group:: objects.
274
275method:: volume
276Get an instance of Volume that runs after the default group, or sets the Volume of the Server's output to level. Level is in db.
277
278method:: mute
279mute the server's output. This can also be toggled from the Server window with the 'm' key.
280
281method:: unmute
282unmute the server. This can also be toggled from the Server window with the 'm' key.
283
284method:: reorder
285Move the nodes in code::nodeList:: to the location specified by code::target:: and code::addAction::, placing them there in the order indicated by nodeList.
286discussion::
287Any nodes which have already been freed will be skipped. Passing nil for target and addAction will result in the location being the head of the default group.
288code::
289g = Group.new;
290x = Array.fill(5, {Synth(\default)});
291s.queryAllNodes;
292s.reorder(x, g, \addToTail);
293s.queryAllNodes;
294::
295
296method:: inputBus
297Return a link::Classes/Bus:: object that represents the input audio bus.
298
299method:: outputBus
300Return a link::Classes/Bus:: object that represents the output audio bus.
301
302
303subsection:: Information and debugging
304
305method:: dumpOSC
306argument:: code
307table::
308## 0 || turn dumping OFF.
309## 1 || print the parsed contents of the message.
310## 2 || print the contents in hexadecimal.
311## 3 || print both the parsed and hexadecimal representations of the contents.
312::
313
314note:: teletype::/status:: messages won't be posted, when dumping is enabled::
315
316method:: queryAllNodes
317Post a representation of this Server's current node tree to the post window. See link::#-plotTree:: for a graphical variant.
318discussion::
319Very helpful for debugging. For local servers, this uses g_dumpTree and for remote g_queryTree. See link::Classes/Group:: and link::Reference/Server-Command-Reference:: for more info.
320code::
321s.boot;
322s.queryAllNodes; // note the root node (ID 0) and the default group (ID 1)
323s.quit;
324::
325
326method:: peakCPU, avgCPU
327Get peak and average CPU usage.
328
329method:: latency
330The current latency of the server. See link::Guides/ServerTiming:: for details.
331
332method:: sampleRate
333An integer representing the nominal sample rate of the server; in other words, the sample rate that was requested of the server when it was booted.
334
335method:: actualSampleRate
336A floating-point number representing the current hardware sample rate, which may drift.
337
338method:: numSynths
339Get number of running link::Classes/Synth::s.
340
341method:: numGroups
342Get the number of link::Classes/Group::s.
343
344method:: numUGens
345Get the number of running link::Classes/UGen::s.
346
347method:: numSynthDefs
348Get number of loaded link::Classes/SynthDef::initions.
349
350method:: pid
351Get process ID of the running server (if not internal).
352
353method:: addr
354The network address of the server as a link::Classes/NetAddr::.
355
356method:: maxNumClients
357If known, the maximum number of clients allowed on the server. Otherwise, the value of link::Classes/ServerOptions#-maxLogins::, which is what will be requested after the server boots. This number is not guaranteed to be correct until link::#-serverRunning:: is code::true::.
358
359method:: clientID
360The getter returns the client ID of this client on the remote process. code::nil:: until the server is running.
361
362The setter attempts to set the client ID of this client for the remote server process. Fails on invalid input or if the server is running. Valid inputs are in the range code::[0..(this.maxNumClients-1)]::.
363
364method:: hasShmInterface
365Returns true if a link::Classes/ServerShmInterface:: is available. See also link::Classes/Bus#Synchronous control bus methods::.
366The shared memory interface is initialized after first server boot.
367
368method:: serverBooting
369code::true:: if the server is booting, code::false:: otherwise.
370
371method:: hasBooted
372code::true:: if the server has booted. The server is not guaranteed to have a correct clientID, nor is it guaranteed that actions in link::Classes/ServerTree:: will have run yet.
373
374method:: serverRunning
375code::true:: only if the server is fully ready. A server is fully ready once it has booted, received a reply to a code::/notify:: command, been given a client ID, and after the link::Classes/ServerTree:: has run.
376
377method:: unresponsive
378code::true:: if the server is unresponsive (specifically, if it has failed to respond after link::Classes/ServerOptions#-pingsBeforeConsideredDead:: ping attempts); code::false:: otherwise.
379
380method:: isLocal
381code::true:: if the server is running on the same machine as sclang, code::false:: otherwise.
382
383method:: remoteControlled
384code::true:: if the server is not being controlled by the machine on which it is running, code::false:: otherwise. This value is the same as code::isLocal:: unless explicitly set.
385
386method:: userSpecifiedClientID
387Deprecated in 3.9. Returns code::false::. Server:clientID can now be set while a server is off, and is locked while the server is running. Thus, userSpecifiedClientID is no longer needed internally, and meaningless.
388
389subsection:: Message Bundling
390
391The server provides support for automatically bundling messages. This is quite convenient in object style and ensures synchronous execution. See also link::Guides/Bundled-Messages::
392
393method:: makeBundle
394The Function code::func:: is evaluated, and all OSC messages generated by it are deferred and added to a bundle.
395argument:: time
396If set to nil or a number the bundle will be automatically sent and executed after the corresponding delay in seconds. If code::time:: is set to false the bundle will not be sent.
397argument:: func
398The function to evaluate.
399argument:: bundle
400allows you to pass in a preexisting bundle and continue adding to it.
401returns:: The bundle so that it can be further used if needed.
402discussion::
403Calling code::sync:: inside func will split the bundle and wait for asynchronous actions to complete before continuing.
404
405If an error is encountered while evaluating code::func:: this method will throw an link::Classes/Error:: and stop message deferral.
406code::
407s.boot;
408(
409// send a synth def to server
410SynthDef("tpulse", { arg out=0,freq=700,sawFreq=440.0;
411	Out.ar(out, SyncSaw.ar(freq,  sawFreq,0.1) )
412}).add;
413)
414
415// all OSC-commands generated in the function contained below will be added to a bundle
416// and executed simultaneously after 2 seconds.
417(
418s.makeBundle(2.0, {
419	x = Synth.new("tpulse");
420	a = Bus.control.set(440);
421	x.map(\freq, a);
422});
423)
424x.free;
425
426// don't send
427(
428b = s.makeBundle(false, {
429	x = { PinkNoise.ar(0.1) * In.kr(0, 1); }.play;
430});
431)
432// now pass b as a pre-existing bundle, and start both synths synchronously
433(
434s.makeBundle(nil, { // nil executes ASAP
435	y = { SinOsc.kr(0.2).abs }.play(x, 0, 0, \addBefore); // sine envelope
436}, b);
437)
438x.free; y.free;
439
440// Throw an Error
441(
442try {
443	s.makeBundle(nil, {
444		s.farkermartin;
445	});
446} { |error|
447	("Look Ma, normal operations resume even though:\n" + error.errorString).postln;
448	x = { FSinOsc.ar(440, 0, 0.2) }.play; // This works fine
449}
450)
451x.free;
452
453// use sync
454(
455s.makeBundle(nil, {
456	b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
457	s.sync; // wait until load is done and then send the rest of the bundle
458	x = { PlayBuf.ar(1, b) * 0.5 }.play;
459});
460)
461x.free; b.free;
462::
463
464method:: bind
465Just as in code::makeBundle::, the Function code::func:: is evaluated, and all OSC messages generated by it are deferred and added to a bundle, which is sent to the server, using the server default latency.
466discussion::
467code::
468(
469s.bind {
470	a = { |freq=100| SinOsc.ar(freq, LFTri.ar(freq)) * 0.2 }.play;
471	s.sync;
472	a.set(\freq, 400);
473}
474)
475::
476
477subsection:: Shared Controls
478
479The internal server has a number of shared control buses. Their values can be set or polled using the methods below.
480
481method:: getSharedControl
482get the current value of a shared control bus. num is the index of the bus to poll. This command is synchronous and only works with the internal server.
483
484method:: setSharedControl
485set the current value of a shared control bus to value. num is the index of the bus to set. This command is synchronous and only works with the internal server.
486
487method:: allocSharedControls
488set the number of shared control buses. Must be done before the internal server is booted. The default is 1024.
489
490subsection:: Persistent Node Trees
491
492The class link::Classes/ServerTree:: can be used to store functions which will be evaluated after the server is booted, after all nodes are freed, and after cmd-. is pressed.
493This allows, for example, for one to create a persistent basic node structure. ServerTree is evaluated in the method initTree after the default group is created, so its existence can be relied upon.
494
495method:: initTree
496This method initializes the link::Reference/default_group:: and runs link::Classes/ServerTree::.
497discussion::
498This method is called automatically when you boot a Server from the language. N.B. If you started a server app from the command line you will have to call initTree manually if you need this functionality.
499code::
500s.quit;
501f = {Group.new(s.defaultGroup); "Other code can be evaluated too".postln;};
502ServerTree.add(f);
503s.boot;
504s.queryAllNodes; // note the group within the default group
505ServerTree.remove(f);
506::
507link::Classes/ServerBoot:: and link::Classes/ServerQuit:: provide similar functionality at boot and quit times.
508
509subsection:: GUI methods
510
511method:: makeGui
512Create and show the server window. The window responds to a number of keyboard shortcuts:
513table::
514## strong::key:: || strong::action::
515## teletype::n:: || Post a representation of this Server's current node tree to the post window. (See link::#-queryAllNodes::)
516## teletype::N:: || As 'n' above but include controls.
517## teletype::l:: || Show input/output level meters. (See link::#-meter::)
518## teletype::p:: || Show graphical view of the node tree. (See link::#-plotTree::)
519## (space) || Boot server if not already booted. (See link::#-boot::)
520## teletype::s:: || Show scope window. (See link::#-scope::)
521## teletype::f:: || Show frequency analyzer window. (See link::#-freqscope::)
522## teletype::d:: || Toggle dumping of OSC messages.
523## teletype::m:: || Toggle mute.
524## teletype::0:: || Reset volume to 0 db.
525::
526
527method:: makeWindow
528On most platforms, this is equivalent to code::makeGui::.
529If you are running SuperCollider on Emacs, it makes a server view composed of Emacs widgets.
530
531method:: scope
532Open a scope window showing the output of the Server.
533see link::Classes/Stethoscope:: for further details.
534
535argument:: numChannels
536the number of channels to be scoped out. The default is this server's options' numOutputBusChannels.
537argument:: index
538the first channel to be output. The default is 0.
539argument:: bufsize
540the size of the buffer for the ScopeView. The default is 4096.
541argument:: zoom
542a zoom value for the scope's X-axis. Larger values show more. The default is 1.
543argument:: rate
544whether to display audio or control rate buses (either \audio or \control)
545
546method:: freqscope
547Show frequency analyzer window.
548
549method:: meter
550Show input/output level meters.
551
552method:: plotTree
553Plot the node/group tree. As link::#-queryAllNodes:: but graphical.
554
555argument:: interval
556Polling interval.
557
558method:: plotTreeView
559Plot the node/group tree graphically on a given view.
560
561argument:: interval
562Polling interval.
563
564argument:: parent
565Parent view.
566
567argument:: actionIfFail
568Function to be evaluated in case communication with the server cannot be established.
569
570returns:: Function to be evaluated in order to clean up all actions performed inside the method. To be called for instance by the onClose method of the enclosing window.
571
572subsection:: Recording Support
573
574The following methods are for convenience use. For recording with sample-accurate start and stop times you should make your own nodes. See the link::Classes/DiskOut:: helpfile for more info. For non-realtime recording, see the link::Guides/Non-Realtime-Synthesis:: helpfile.
575
576This functionality is also available through the recording button on the server windows.
577Pressing it once calls record, and pressing it again calls stopRecording (see below). When doing so the file created will be in your recordings folder and be named for the current date and time.
578The default location of the recordings folder varies from platform to platform but is always stored in code::thisProcess.platform.recordingsDir::. Setting this variable allows you to change the default.
579
580NOTE::
581record creates the recording synth after the Server's default group and uses In.ar. Thus if you add nodes after the recording synth their output will not be captured.
582To avoid this, either use Node objects (which use the default node as their target) or (when using messaging style) use a target nodeID of 1.
583code::
584s.sendMsg("/s_new", "default", s.nextNodeID, 1,1);
585::
586::
587
588For more detail on this subject see link::Guides/Order-of-execution::, link::Reference/default_group::, and link::Guides/NodeMessaging::.
589
590See link::Classes/SoundFile:: for information on the various sample and header formats.
591Not all sample and header formats are compatible. Note that the sampling rate of the output file will be the same as that of the server app. This can be set using the Server's link::Classes/ServerOptions::.
592
593Example:
594code::
595s.boot; // start the server
596
597// something to record
598(
599SynthDef("bubbles", { |out|
600	var f, sound;
601	f = LFSaw.kr(0.4, 0, 24, LFSaw.kr([8,7.23], 0, 3, 80)).midicps; // glissando function
602	sound = CombN.ar(SinOsc.ar(f, 0, 0.04), 0.2, 0.2, 4); // echoing sine wave
603	Out.ar(out, sound);
604}).add;
605)
606
607x = Synth.new("bubbles");
608
609s.prepareForRecord; // if you want to start recording at a precise moment in time, you have to call this first.
610
611s.record;
612
613s.pauseRecording; // pausable
614
615s.record // start again
616
617s.stopRecording; // this closes the file and deallocates the buffer recording node, etc.
618
619x.free; // stop the synths
620
621// look in your recordings folder and you'll find a file named for this date and time
622::
623
624The recording is done via an of link::Classes/Recorder:: - a server holds one instance implicitly.
625
626method:: prepareForRecord
627Allocates the necessary buffer, etc. for recording the server's output. (See code::record:: below.)
628argument:: path
629a link::Classes/String:: representing the path and name of the output file. If the directory does not exist, it will be created for you. (Note, however, that if this fails for any reason, the recording will also fail.)
630argument:: numChannels
631a link::Classes/String:: the number of output channels to record.
632
633discussion::
634If you do not specify a path than a file will be created in your recordings folder (see the note above on this) called SC_thisDateAndTime. Changes to the header or sample format, or to the number of channels must be made strong::before:: calling this.
635
636method:: record
637Starts or resumes recording the output.
638argument:: path
639this is optional, and is passed to code::prepareForRecord:: (above).
640argument:: bus
641the bus to record - defaults to 0
642argument:: numChannels
643the number of channels to record - defaults to server numChannels
644argument:: node
645the node to record - defaults to server rootnode
646argument:: duration
647duration to record - defaults to inf
648
649discussion::
650If you have not called prepareForRecord first (see above) then it will be invoked for you (but that adds a slight delay before recording starts for real).
651
652method:: pauseRecording
653Pauses recording. Can be resumed by executing record again.
654
655method:: stopRecording
656Stops recording, closes the file, and frees the associated resources.
657discussion::
658You must call this when finished recording or the output file will be unusable. Cmd-. while recording has the same effect.
659
660
661method:: recChannels
662Get/set the number of channels (int) to record. Is automatically set to the value of link::Classes/ServerOptions#-numOutputBusChannels:: when booting the server. Must be called strong::before:: prepareForRecord.
663
664method:: recHeaderFormat
665Get/set the header format (string) of the output file. The default is "aiff". Must be called strong::before:: prepareForRecord.
666
667method:: recSampleFormat
668Get/set the sample format (string) of the output file. The default is "float". Must be called strong::before:: prepareForRecord.
669
670method::recBufSize
671Get/set the size of the link::Classes/Buffer:: to use with the link::Classes/DiskOut:: UGen. This must be a power of two. The default is the code::sampleRate.nextPowerOfTwo:: or the first power of two number of samples longer than one second. Must be called strong::before:: prepareForRecord.
672
673subsection:: Asynchronous Commands
674
675The server provides support for waiting on the completion of asynchronous OSC-commands such as reading or writing sound files. N.B. The following methods must be called from within a running link::Classes/Routine::. Explicitly passing in a link::Classes/Condition:: allows multiple elements to depend on different conditions. The examples below should make clear how all this works.
676
677method:: bootSync
678Boot the Server and wait until it has completed before resuming the thread.
679argument:: condition
680an optional instance of link::Classes/Condition:: used for evaluating this.
681
682method:: sendMsgSync
683Send the following message to the wait until it has completed before resuming the thread.
684argument:: condition
685an optional instance of link::Classes/Condition:: used for evaluating this.
686argument:: ... args
687one or more valid OSC messages.
688
689method:: sync
690Send a code::/sync:: message to the server, which will reply with the message code::/synced:: when all pending asynchronous commands have been completed.
691argument:: condition
692an optional instance of link::Classes/Condition:: used for evaluating this.
693argument:: bundles
694one or more OSC messages which will be bundled before the sync message (thus ensuring that they will arrive before the /sync message). argument:: latency
695allows for the message to be evaluated at a specific point in the future.
696
697discussion::
698This may be slightly less safe then sendMsgSync under UDP on a wide area network, as packets may arrive out of order, but on a local network should be okay. Under TCP this should always be safe.
699code::
700(
701Routine.run {
702	var c;
703
704	// create a condition variable to control execution of the Routine
705	c = Condition.new;
706
707	s.bootSync(c);
708	\BOOTED.postln;
709
710	s.sendMsgSync(c, "/b_alloc", 0, 44100, 2);
711	s.sendMsgSync(c, "/b_alloc", 1, 44100, 2);
712	s.sendMsgSync(c, "/b_alloc", 2, 44100, 2);
713	\b_alloc_DONE.postln;
714};
715)
716
717(
718Routine.run {
719	var c;
720
721	// create a condition variable to control execution of the Routine
722	c = Condition.new;
723
724	s.bootSync(c);
725	\BOOTED.postln;
726
727	s.sendMsg("/b_alloc", 0, 44100, 2);
728	s.sendMsg("/b_alloc", 1, 44100, 2);
729	s.sendMsg("/b_alloc", 2, 44100, 2);
730	s.sync(c);
731	\b_alloc_DONE.postln;
732};
733)
734::
735
736
737