Quarks-help: use Quark-openHelpFile
[supercollider.git] / Help / ServerArchitecture / Synth.html
blob15207fc0f2fee91c80a2dc0c04e25183963dc632
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.54">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.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: 14.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica; min-height: 14.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica}
15 p.p6 {margin: 0.0px 0.0px 0.0px 56.0px; text-indent: -56.0px; font: 12.0px Helvetica}
16 p.p7 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica}
17 p.p8 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica; min-height: 14.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 9.0px Monaco; min-height: 12.0px}
19 p.p10 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco}
20 p.p11 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; color: #a31917}
21 p.p12 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; color: #0017b3}
22 p.p13 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
23 p.p14 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; min-height: 12.0px}
24 p.p15 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica}
25 p.p16 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; color: #606060}
26 p.p17 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
27 p.p18 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #a31917}
28 p.p19 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
29 span.s1 {font: 18.0px Helvetica}
30 span.s2 {color: #0017b3}
31 span.s3 {font: 9.0px Monaco}
32 span.s4 {font: 9.0px Monaco; color: #35701d}
33 span.s5 {color: #35701d}
34 span.s6 {font: 12.0px Helvetica}
35 span.s7 {color: #000000}
36 span.s8 {color: #606060}
37 span.s9 {color: #a31917}
38 span.Apple-tab-span {white-space:pre}
39 </style>
40 </head>
41 <body>
42 <p class="p1"><span class="s1"><b>Synth<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></span><b>client-side representation of a synth node on the server</b></p>
43 <p class="p2"><br></p>
44 <p class="p1"><b>superclass: </b><a href="Node.html"><span class="s2"><b>Node</b></span></a></p>
45 <p class="p2"><br></p>
46 <p class="p1">A Synth is the client-side representation of a synth node on the server. A Synth represents a single sound producing unit.<span class="Apple-converted-space">  </span>What it does is defined in a <b>SynthDef</b>, which specifies what UGens are used and how they are patched together.<span class="Apple-converted-space">  </span>It also specifies what inputs and outputs the Synth will have. A SynthDef is thus a kind of fixed pattern, upon which Synths are be based. (Despite this, a given SynthDef can provide a surprising amount of variation.) For more detail on SynthDefs, their construction, and how to send them to a server, see the <a href="SynthDef.html"><span class="s2"><b>SynthDef</b></span></a> help file.</p>
47 <p class="p2"><br></p>
48 <p class="p1">For more on the important distinction between client objects and server nodes, see <a href="ClientVsServer.html"><span class="s2"><b>ClientVsServer</b></span></a>. For information on creating nodes without using objects, see <a href="NodeMessaging.html"><span class="s2"><b>NodeMessaging</b></span></a>.</p>
49 <p class="p2"><br></p>
50 <p class="p1"><b>N.B. </b>Synth is a subclass of <b>Node</b>, and thus many of its most useful and important methods are documented in the <a href="Node.html"><span class="s2"><b>Node</b></span></a> help file.</p>
51 <p class="p2"><br></p>
52 <p class="p3"><b>Order of Execution</b></p>
53 <p class="p2"><br></p>
54 <p class="p1">Order of execution is a crucial issue when creating Synths which interact with each other.</p>
55 <p class="p2"><br></p>
56 <p class="p1"><b><span class="Apple-tab-span"> </span>sound -&gt;<span class="Apple-converted-space">  </span>filter</b></p>
57 <p class="p2"><span class="Apple-tab-span"> </span></p>
58 <p class="p1">If a sound is to be passed through a filter, the synth that does the filtering must be later in the order of execution than the synth which is its input.<span class="Apple-converted-space">  </span>The computer must calculate a buffer's worth of sound, and then the computer moves on to calculate a buffer's worth of the filtered version of that sound.</p>
59 <p class="p2"><br></p>
60 <p class="p1">The actual interconnection between synth nodes is accomplished with buses. See <a href="Bus.html"><span class="s2"><b>Bus</b></span></a> and <a href="Server-Architecture.html"><span class="s2"><b>Server-Architecture</b></span></a> for details.</p>
61 <p class="p2"><br></p>
62 <p class="p1">See the <a href="Order-of-execution.html"><span class="s2"><b>Order-of-execution</b></span></a> help file for a more detailed discussion of this important topic.</p>
63 <p class="p2"><br></p>
64 <p class="p3"><b>Bundling</b></p>
65 <p class="p2"><br></p>
66 <p class="p1">Some of the methods below have two versions: a regular one which sends its corresponding message to the server immediately, and one which returns the message in an <a href="../Collections/Array.html"><span class="s2"><b>Array</b></span></a> so that it can be added to a bundle. It is also possible to capture the messages generated by the regular methods using Server's automated bundling capabilities. See <a href="Server.html"><span class="s2"><b>Server</b></span></a> and <a href="bundledCommands.html"><span class="s2"><b>bundledCommands</b></span></a> for more details.</p>
67 <p class="p2"><br></p>
68 <p class="p3"><b>Accessing Instance Variables</b></p>
69 <p class="p4"><br></p>
70 <p class="p5"><b><span class="Apple-tab-span"> </span>defName </b>- Returns the name of this Synth's SynthDef.</p>
71 <p class="p4"><span class="Apple-tab-span"> </span></p>
72 <p class="p5">For other instance variables see <a href="Node.html"><span class="s2"><b>Node</b></span></a>.</p>
73 <p class="p2"><br></p>
74 <p class="p3"><b>Creation with Immediate Instantiation on the Server</b></p>
75 <p class="p2"><b><span class="Apple-tab-span"> </span></b></p>
76 <p class="p2"><br></p>
77 <p class="p5"><b><span class="Apple-tab-span"> </span>*new(defName, args: [ arg1, value1, ... argN, valueN<span class="Apple-converted-space">  </span>], target, addAction)</b></p>
78 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
79 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Create and return a new Synth object, and immediately start the corresponding synth node on the server.</p>
80 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
81 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>defName </b>- A <a href="../Collections/String.html"><span class="s2"><b>String</b></span></a> or <a href="../Core/Symbol.html"><span class="s2"><b>Symbol</b></span></a> specifying the name of the <b>SynthDef</b> to use in creating the Synth.</p>
82 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
83 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>args </b>- An optional array specifying initial values for the SynthDef's arguments (controls). These are specified in pairs of control name or index and value. If names are used they can be specified with either Strings or Symbols. e.g. <span class="s3">[</span><span class="s4">\frequency</span><span class="s3">, 440, </span><span class="s4">\amplitude</span><span class="s3">, 1, ...]</span></p>
84 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Values that are arrays are sent using<span class="Apple-converted-space">  </span>OSC array type-tags ($[ and $]).<span class="Apple-converted-space">  </span>These values will<span class="Apple-converted-space"> </span></p>
85 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>be assigned to subsequent controls.</p>
86 <p class="p9"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
87 <p class="p7"><span class="s3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><b>target </b>- A target for this Synth. If target is not a <a href="Group.html"><span class="s2"><b>Group</b></span></a> or Synth, it will be converted as follows: If it is a <b>Server</b>, it will be converted to the <b>default_group</b> of that server. If it is nil, to the <b>default_group</b> of the default Server. If it is an integer, it is created relative to a group with that id.<span class="Apple-converted-space"> </span></p>
88 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>Note: </b>A Synth is not a valid target for <span class="s4">\addToHead</span> and <span class="s4">\addToTail</span>.</p>
89 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
90 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>addAction</b> - one of the following Symbols:<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
91 <p class="p7"><span class="s3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">\addToHead</span><span class="s3"> <span class="Apple-tab-span"> </span></span>- (the default) add at the head of the group specified by <b>target</b></p>
92 <p class="p5"><span class="s3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">\addToTail</span><span class="s3"> <span class="Apple-tab-span"> </span></span>- add at the tail of the group specified by <b>target</b></p>
93 <p class="p5"><span class="s3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">\addAfter</span> <span class="Apple-tab-span"> </span>- add immediately after <b>target </b>in its server<span class="s5">'s </span>node order</p>
94 <p class="p5"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>\addBefore</span><span class="s5"> <span class="Apple-tab-span"> </span></span>- add immediately before <b>target </b>in its server's node order</p>
95 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">\addReplace</span> <span class="Apple-tab-span"> </span>- replace <b>target</b> and take its place in its server's node order</p>
96 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
97 <p class="p10"><span class="s6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
98 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// create a Synth at the head of the default Server's default group</p>
99 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// based on the SynthDef "default"</p>
100 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = <span class="s2">Synth</span>.new(<span class="s8">"default"</span>);<span class="Apple-converted-space"> </span></p>
101 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.queryAllNodes; </span>// note the default group (ID 1)</p>
102 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free;</p>
103 <p class="p2"><br></p>
104 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// Using an arrayed control</p>
105 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
106 <p class="p12"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = </span>SynthDef<span class="s7">(</span><span class="s8">"help-synth"</span><span class="s7">, {</span>| freq = #[440, 450, 460], out = 0 |</p>
107 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar(out, <span class="s2">Mix</span>(<span class="s2">SinOsc</span>.ar(freq, 0, 0.1)));</p>
108 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
109 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = x.play(s, [freq: [500,501,510] ]);</p>
110 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
111 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.set(<span class="s5">\freq</span>, [1,2,3] * 400 + [1,2,3], <span class="s5">\out</span>, 1); <span class="s9">// two pairs</span></p>
112 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.set(<span class="s5">\freq</span>, [3] * 400 + [1,2,3], <span class="s5">\out</span>, 1); <span class="s9">// two pairs</span></p>
113 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.set(0, [660, 680, 720], 1, 0); </span>// freq is the first argument, so it's index is 0. out is index 1.</p>
114 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free;</p>
115 <p class="p2"><br></p>
116 <p class="p1"><b><span class="Apple-tab-span"> </span>*newPaused(defName, args: [ arg1, value1,... argN, valueN<span class="Apple-converted-space">  </span>], target, addAction)</b></p>
117 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
118 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>As <b>*new</b> above, but creates a node which is paused. This can be started by calling run on it.</p>
119 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
120 <p class="p13"><span class="s6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
121 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = <span class="s2">Synth</span>.newPaused(<span class="s8">"default"</span>);<span class="Apple-converted-space"> </span></p>
122 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.queryAllNodes; <span class="s9">// see I'm here</span></p>
123 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.run; </span>// true is the default</p>
124 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.run(</span><span class="s2">false</span><span class="s7">); </span>// pause me again</p>
125 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free;</p>
126 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
127 <p class="p5"><span class="Apple-tab-span"> </span><b>*grain(defName, args: [ arg1, value1, ... argN, valueN<span class="Apple-converted-space">  </span>], target, addAction)</b></p>
128 <p class="p4"><b><span class="Apple-tab-span"> </span></b></p>
129 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>A convenience method which will create a synth node with an node ID of -1. Such a node cannot be messaged after creation. As such this method does not create an object, and returns nil. For details of its arguments see <b>*new</b> above.</p>
130 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
131 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
132 <p class="p5">The following convenience methods correspond to the add actions of <b>Synth.new</b>:</p>
133 <p class="p14"><br></p>
134 <p class="p5"><b><span class="Apple-tab-span"> </span>*after(aNode, defName, args)</b></p>
135 <p class="p4"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
136 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Create and return a Synth and add it immediately after <b>aNode.</b></p>
137 <p class="p4"><br></p>
138 <p class="p5"><b><span class="Apple-tab-span"> </span>*before(aNode, defName, args)</b></p>
139 <p class="p4"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
140 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Create and return a Synth and add it immediately before <b>aNode.</b></p>
141 <p class="p4"><br></p>
142 <p class="p5"><span class="s3"><span class="Apple-tab-span"> </span></span><b>*head(aGroup, defName, args)</b></p>
143 <p class="p4"><b><span class="Apple-tab-span"> </span></b></p>
144 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Create and return a Synth. If <b>aGroup</b> is a <b>Group</b> add it at the head of that group. If it is a <b>Server</b>, add it at the head of the <b>default_group</b> of that server. If it is nil, add it at the head of the <b>default_group</b> of the default server<b>. </b>If it is an integer, it is created relative to a group with that id.<span class="Apple-converted-space"> </span></p>
145 <p class="p4"><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>
146 <p class="p5"><span class="s3"><span class="Apple-tab-span"> </span></span><b>*tail(aGroup, defName, args)</b></p>
147 <p class="p4"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
148 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Create and return a Synth. If <b>aGroup</b> is a <b>Group</b> add it at the tail of that group. If it is a <b>Server</b>, add it at the tail of the <b>default_group</b> of that server. If it is nil, add it at the tail of the <b>default_group</b> of the the default server<b>. </b>If it is an integer, it is created relative to a group with that id.<span class="Apple-converted-space"> </span></p>
149 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
150 <p class="p5"><span class="Apple-tab-span"> </span><b>*replace(nodeToReplace, defName, args)</b></p>
151 <p class="p4"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
152 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Create and return a Synth and use it to replace <b>nodeToReplace</b>, taking its place in its server's node order.</p>
153 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
154 <p class="p3"><b>Creation without Instantiation on the Server</b></p>
155 <p class="p2"><br></p>
156 <p class="p1">For use in message bundles it is also possible to create a Synth object in the client app without immediately creating a synth node on the server. Once done one can call methods which create messages to add to a bundle, which when sent to the server will instantiate the synth.</p>
157 <p class="p4"><br></p>
158 <p class="p5"><span class="Apple-tab-span"> </span><b>*basicNew(defName, server, nodeID)</b></p>
159 <p class="p4"><b><span class="Apple-tab-span"> </span></b></p>
160 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Create and return a Synth object without creating a synth node on the server.<span class="Apple-converted-space"> </span></p>
161 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
162 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>defName </b>- A <b>String</b> or <b>Symbol</b> specifying the name of the <b>SynthDef</b> to use in creating the Synth.</p>
163 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
164 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>server</b> - An optional instance of <b>Server</b>. If nil this will default to the default <b>Server</b>.<span class="Apple-converted-space"> </span></p>
165 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
166 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>nodeID </b>- An optional node ID number. If not supplied one will be generated by the Server's NodeIDAllocator. Normally you should not need to supply an ID.</p>
167 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
168 <p class="p10"><span class="s6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
169 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = </span><span class="s2">Synth</span><span class="s7">.basicNew(</span><span class="s8">"default"</span><span class="s7">, s); </span>// Create without sending</p>
170 <p class="p11"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.sendBundle(</span><span class="s2">nil</span><span class="s7">, x.newMsg;); </span>// Now send a message; create at the head of s' default group</p>
171 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.queryAllNodes;</p>
172 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free;</p>
173 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
174 <p class="p5"><span class="Apple-tab-span"> </span><b>newMsg(target, args, addAction</b>)</p>
175 <p class="p4"><b><span class="Apple-tab-span"> </span></b></p>
176 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Returns a message of the type <b>s_new</b> which can be bundled. When sent to the server this message will instantiate this synth. If target is nil, it will default to the <b>default_group</b> of the Server specified in <b>*basicNew</b> when this Synth was created. The default addAction is <span class="s4">\addToHead</span>. (See <b>*new</b> above for details of addActions and args.)</p>
177 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
178 <p class="p5"><span class="Apple-tab-span"> </span><b>addToHeadMsg(aGroup, args)</b></p>
179 <p class="p4"><span class="Apple-tab-span"> </span></p>
180 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Returns a message of the type <b>s_new</b> which can be bundled. When sent to the server this message will instantiate this synth. If <b>aGroup</b> is a <b>Group</b> it will be added at the head of that group. If it is nil, it will be added at the head of the <b>default_group</b> of this Synth's server (as specified when *<b>basicNew</b> was called). See <b>*new</b> above for details on <b>args</b>.</p>
181 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
182 <p class="p5"><span class="Apple-tab-span"> </span><b>addToTailMsg(aGroup, args)</b></p>
183 <p class="p4"><span class="Apple-tab-span"> </span></p>
184 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Returns a message of the type <b>s_new</b> which can be bundled. When sent to the server this message will instantiate this synth. If <b>aGroup</b> is a <b>Group</b> it will be added at the tail of that group. If it is nil, it will be added at the tail of the <b>default_group</b> of this Synth's server (as specified when *<b>basicNew</b> was called). See <b>*new</b> above for details on <b>args</b>.</p>
185 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
186 <p class="p5"><span class="Apple-tab-span"> </span><b>addBeforeMsg(aNode, args</b>)</p>
187 <p class="p4"><b><span class="Apple-tab-span"> </span></b></p>
188 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Returns a message of the type <b>s_new</b> which can be bundled. When sent to the server this message will instantiate this synth, immediately before <b>aNode</b>. See <b>*new</b> above for details on <b>args</b>.</p>
189 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
190 <p class="p5"><span class="Apple-tab-span"> </span><b>addAfterMsg(aNode, args</b>)</p>
191 <p class="p4"><b><span class="Apple-tab-span"> </span></b></p>
192 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Returns a message of the type <b>s_new</b> which can be bundled. When sent to the server this message will instantiate this synth, immediately after <b>aNode</b>. See <b>*new</b> above for details on <b>args</b>.</p>
193 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
194 <p class="p5"><span class="Apple-tab-span"> </span><b>addReplaceMsg(nodeToReplace, args</b>)</p>
195 <p class="p4"><b><span class="Apple-tab-span"> </span></b></p>
196 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Returns a message of the type <b>s_new</b> which can be bundled. When sent to the server this message will instantiate this synth, replacing <b>nodeToReplace</b> in the server's node order. See <b>*new</b> above for details on <b>args</b>.</p>
197 <p class="p4"><br></p>
198 <p class="p15"><b>Control</b></p>
199 <p class="p4"><br></p>
200 <p class="p5">For further methods of controlling Synths (set, map, etc.), see the <a href="Node.html"><span class="s2"><b>Node</b></span></a> helpfile.</p>
201 <p class="p4"><br></p>
202 <p class="p5"><span class="Apple-tab-span"> </span><b>get(index, action)</b></p>
203 <p class="p5"><b><span class="Apple-tab-span"> </span>getMsg(index)</b></p>
204 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
205 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Query the server for the current value of a <b>Control</b> (argument). <b>index</b> is a control name or index. <b>action</b> is a <a href="../Core/Kernel/Function.html"><span class="s2"><b>Function</b></span></a> which will be evaluated with the value passed as an argument when the reply is received.</p>
206 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
207 <p class="p10"><span class="s6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>s.boot;</p>
208 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
209 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">SynthDef</span>(<span class="s8">"help-Synth-get"</span>, { <span class="s2">arg</span> freq = 440;<span class="Apple-converted-space"> </span></p>
210 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar(0, <span class="s2">SinOsc</span>.ar(freq, 0, 0.1));</p>
211 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}).add;</p>
212 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
213 <p class="p16"><span class="s7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x = </span><span class="s2">Synth</span><span class="s7">(</span>"help-Synth-get"<span class="s7">);</span></p>
214 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.set(<span class="s5">\freq</span>, 220 + 440.rand);</p>
215 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.get(<span class="s5">\freq</span>, { <span class="s2">arg</span> value; (<span class="s8">"freq is now:"</span> + value + <span class="s8">"Hz"</span>).postln; });</p>
216 <p class="p10"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x.free;</p>
217 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
218 <p class="p5"><span class="Apple-tab-span"> </span><b>getn(index, count, action)</b></p>
219 <p class="p5"><b><span class="Apple-tab-span"> </span>getnMsg(index, count)</b></p>
220 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
221 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Query the server for the current values of a sequential range of Controls (arguments). <b>index</b> is a control name or index. <b>count</b> is the number of sequential controls to query, starting at <b>index</b>. <b>action</b> is a <b>Function</b> which will be evaluated with an <b>Array</b> containing the values passed as an argument when the reply is received.<span class="Apple-tab-span"> </span></p>
222 <p class="p4"><br></p>
223 <p class="p2"><br></p>
224 <p class="p15"><b>Examples</b></p>
225 <p class="p2"><br></p>
226 <p class="p17"><br></p>
227 <p class="p18">// boot the default server</p>
228 <p class="p18"><span class="s7">s = </span><span class="s2">Server</span><span class="s7">.default; </span>// just to be sure</p>
229 <p class="p13">s.boot;</p>
230 <p class="p17"><br></p>
231 <p class="p17"><br></p>
232 <p class="p13">(</p>
233 <p class="p18">// send a synth def to server</p>
234 <p class="p13"><span class="s2">SynthDef</span>(<span class="s8">"tpulse"</span>, { <span class="s2">arg</span> out = 0,freq = 700, sawFreq = 440.0;<span class="Apple-converted-space"> </span></p>
235 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar(out, <span class="s2">SyncSaw</span>.ar(freq, sawFreq, 0.1));</p>
236 <p class="p13">}).add;</p>
237 <p class="p13">)</p>
238 <p class="p17"><br></p>
239 <p class="p18">// Here the defaults for *new will result in a Synth at the head of the default group</p>
240 <p class="p18">// of the default Server. This will use the SynthDef's default arguments;</p>
241 <p class="p13">y = <span class="s2">Synth</span>.new(<span class="s8">"tpulse"</span>);<span class="Apple-converted-space"> </span></p>
242 <p class="p13">y.free;</p>
243 <p class="p17"><br></p>
244 <p class="p18">// The same done explicitly</p>
245 <p class="p13">y = <span class="s2">Synth</span>.new(<span class="s8">"tpulse"</span>, <span class="s2">nil</span>, s, <span class="s5">\addToHead</span>);<span class="Apple-converted-space"> </span></p>
246 <p class="p13">y.free;</p>
247 <p class="p17"><br></p>
248 <p class="p18">// With some arguments</p>
249 <p class="p13">y = <span class="s2">Synth</span>.new(<span class="s8">"tpulse"</span>, [<span class="s5">\freq</span>, 350, <span class="s5">\sawFreq</span>, 220]);</p>
250 <p class="p13">y.free;</p>
251 <p class="p17"><br></p>
252 <p class="p18">// make a new synth</p>
253 <p class="p19"><span class="s7">y = </span><span class="s2">Synth</span><span class="s7">(</span>"tpulse"<span class="s7">);</span></p>
254 <p class="p17"><br></p>
255 <p class="p18">// pause</p>
256 <p class="p13">y.run(<span class="s2">false</span>);</p>
257 <p class="p17"><br></p>
258 <p class="p13">y.run(<span class="s2">true</span>);</p>
259 <p class="p17"><br></p>
260 <p class="p18">// set a control by argument name</p>
261 <p class="p13">y.set(<span class="s8">"freq"</span>, 200);</p>
262 <p class="p17"><br></p>
263 <p class="p18">// or by index</p>
264 <p class="p13">y.set(2, 100.0);</p>
265 <p class="p17"><br></p>
266 <p class="p18">// modulate out to bus number 1 (the right speaker)</p>
267 <p class="p13">y.set(0, 1);</p>
268 <p class="p17"><br></p>
269 <p class="p18">//<span class="Apple-converted-space">  </span>multiple set commands in one message</p>
270 <p class="p13">y.set(<span class="s8">"out"</span>, 0, <span class="s8">"freq"</span>,300);</p>
271 <p class="p17"><br></p>
272 <p class="p18">// free the synth from the server</p>
273 <p class="p13">y.free;</p>
274 <p class="p17"><br></p>
275 <p class="p17"><br></p>
276 <p class="p17"><br></p>
277 <p class="p18">//////////// Filtering</p>
278 <p class="p17"><br></p>
279 <p class="p13">(</p>
280 <p class="p18">// first collect some things to play with</p>
281 <p class="p13"><span class="s2">SynthDef</span>(<span class="s8">"moto-rev"</span>, { <span class="s2">arg</span> out=0;</p>
282 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">var</span> x;</p>
283 <p class="p13"><span class="Apple-tab-span"> </span>x = <span class="s2">RLPF</span>.ar(<span class="s2">LFPulse</span>.ar(<span class="s2">SinOsc</span>.kr(0.2, 0, 10, 21), [0,0.1], 0.1),<span class="Apple-converted-space"> </span></p>
284 <p class="p13"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>100, 0.1).clip2(0.4);</p>
285 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar(out, x);</p>
286 <p class="p13">}).add;</p>
287 <p class="p17"><br></p>
288 <p class="p13"><span class="s2">SynthDef</span>(<span class="s8">"bubbles"</span>, { <span class="s2">arg</span> out=0;</p>
289 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">var</span> f, zout;</p>
290 <p class="p13"><span class="Apple-tab-span"> </span>f = <span class="s2">LFSaw</span>.kr(0.4, 0, 24, <span class="s2">LFSaw</span>.kr([8,7.23], 0, 3, 80)).midicps;<span class="Apple-converted-space"> </span></p>
291 <p class="p13"><span class="Apple-tab-span"> </span>zout = <span class="s2">CombN</span>.ar(<span class="s2">SinOsc</span>.ar(f, 0, 0.04), 0.2, 0.2, 4); <span class="s9">// echoing sine wave</span></p>
292 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">Out</span>.ar(out, zout);</p>
293 <p class="p13">}).add;</p>
294 <p class="p17"><br></p>
295 <p class="p17"><br></p>
296 <p class="p13"><span class="s2">SynthDef</span>(<span class="s8">"rlpf"</span>,{ <span class="s2">arg</span> out=0,ffreq=600,rq=0.1;</p>
297 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">ReplaceOut</span>.ar( out, <span class="s2">RLPF</span>.ar( <span class="s2">In</span>.ar(out), ffreq,rq) )</p>
298 <p class="p13">}).add;</p>
299 <p class="p17"><br></p>
300 <p class="p17"><br></p>
301 <p class="p13"><span class="s2">SynthDef</span>(<span class="s8">"wah"</span>, { <span class="s2">arg</span> out, rate = 1.5, cfreq = 1400, mfreq = 1200, rq=0.1;</p>
302 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">var</span> zin, zout;</p>
303 <p class="p17"><br></p>
304 <p class="p13"><span class="Apple-tab-span"> </span>zin = <span class="s2">In</span>.ar(out, 2);</p>
305 <p class="p13"><span class="Apple-tab-span"> </span>cfreq = <span class="s2">Lag3</span>.kr(cfreq, 0.1);</p>
306 <p class="p13"><span class="Apple-tab-span"> </span>mfreq = <span class="s2">Lag3</span>.kr(mfreq, 0.1);</p>
307 <p class="p13"><span class="Apple-tab-span"> </span>rq <span class="Apple-converted-space">  </span>= <span class="s2">Ramp</span>.kr(rq, 0.1);</p>
308 <p class="p13"><span class="Apple-tab-span"> </span>zout = <span class="s2">RLPF</span>.ar(zin, <span class="s2">LFNoise1</span>.kr(rate, mfreq, cfreq), rq, 10).distort<span class="Apple-converted-space"> </span></p>
309 <p class="p13"><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>* 0.15;</p>
310 <p class="p17"><br></p>
311 <p class="p18"><span class="s7"><span class="Apple-tab-span"> </span></span>// replace the incoming bus with the effected version</p>
312 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">ReplaceOut</span>.ar( out , zout );<span class="Apple-converted-space"> </span></p>
313 <p class="p17"><span class="Apple-tab-span"> </span></p>
314 <p class="p13">}).add;</p>
315 <p class="p17"><br></p>
316 <p class="p13"><span class="s2">SynthDef</span>(<span class="s8">"modulate"</span>,{ <span class="s2">arg</span> out = 0, freq = 1, center = 440, plusMinus = 110;</p>
317 <p class="p13"><span class="Apple-tab-span"> </span><span class="s2">Out</span>.kr(out, <span class="s2">SinOsc</span>.kr(freq, 0, plusMinus, center));</p>
318 <p class="p13">}).add;</p>
319 <p class="p13">)</p>
320 <p class="p17"><br></p>
321 <p class="p18">// execute these one at a time</p>
322 <p class="p17"><br></p>
323 <p class="p18">// y is playing on bus 0</p>
324 <p class="p19"><span class="s7">y = </span><span class="s2">Synth</span><span class="s7">(</span>"moto-rev"<span class="s7">,[</span>"out"<span class="s7">,0]);</span></p>
325 <p class="p17"><br></p>
326 <p class="p18">// z is reading from bus 0 and replacing that; It must be *after* y</p>
327 <p class="p13">z = <span class="s2">Synth</span>.after(y,<span class="s8">"wah"</span>,[<span class="s8">"out"</span>,0]);</p>
328 <p class="p17"><br></p>
329 <p class="p18">// stop the wah-ing</p>
330 <p class="p13">z.run(<span class="s2">false</span>);</p>
331 <p class="p17"><br></p>
332 <p class="p18">// resume the wah-ing</p>
333 <p class="p13">z.run(<span class="s2">true</span>);</p>
334 <p class="p17"><br></p>
335 <p class="p18">// add a rlpf after that, reading and writing to the same buss</p>
336 <p class="p13">x = <span class="s2">Synth</span>.after(z,<span class="s8">"rlpf"</span>,[<span class="s8">"out"</span>,0]);</p>
337 <p class="p17"><br></p>
338 <p class="p18">// create another rlpf after x</p>
339 <p class="p13">t = <span class="s2">Synth</span>.after(x,<span class="s8">"rlpf"</span>,[<span class="s8">"out"</span>,0]);</p>
340 <p class="p17"><br></p>
341 <p class="p13">x.set(<span class="s8">"ffreq"</span>, 400);</p>
342 <p class="p17"><br></p>
343 <p class="p18"><span class="s7">x.set(</span><span class="s5">\ffreq</span><span class="s7">, 800); </span>// Symbols work for control names too</p>
344 <p class="p17"><br></p>
345 <p class="p18">// Now let's modulate x's ffreq arg</p>
346 <p class="p18">// First get a control Bus</p>
347 <p class="p13">b = <span class="s2">Bus</span>.control(s, 1);</p>
348 <p class="p17"><br></p>
349 <p class="p18">// now the modulator, *before* x</p>
350 <p class="p13">m = <span class="s2">Synth</span>.before(x, <span class="s8">"modulate"</span>, [<span class="s5">\out</span>, b]);</p>
351 <p class="p17"><br></p>
352 <p class="p18">// now map x's ffreq to b</p>
353 <p class="p13">x.map(<span class="s8">"ffreq"</span>, b);</p>
354 <p class="p17"><br></p>
355 <p class="p13">m.set(<span class="s8">"freq"</span>, 4, <span class="s8">"plusMinus"</span>, 20);</p>
356 <p class="p17"><br></p>
357 <p class="p13">x.free;</p>
358 <p class="p13">z.free;</p>
359 <p class="p13">m.free;</p>
360 <p class="p17"><br></p>
361 <p class="p18">// now place another synth after y, on the same bus</p>
362 <p class="p18">// they both write to the buss, adding their outputs</p>
363 <p class="p13">r = <span class="s2">Synth</span>.after(y,<span class="s8">"bubbles"</span>,[<span class="s8">"out"</span>,0]);</p>
364 <p class="p17"><br></p>
365 <p class="p13">y.free;</p>
366 <p class="p17"><br></p>
367 <p class="p13">r.free;</p>
368 <p class="p17"><br></p>
369 <p class="p18">// look at the Server window</p>
370 <p class="p18">// still see 4 Ugens and 1 synth?</p>
371 <p class="p18">// you can't hear me, but don't forget to free me</p>
372 <p class="p13">t.free;</p>
373 <p class="p17"><br></p>
374 <p class="p17"><br></p>
375 <p class="p17"><br></p>
376 <p class="p17"><br></p>
377 <p class="p17"><br></p>
378 <p class="p17"><br></p>
379 <p class="p17"><br></p>
380 <p class="p17"><br></p>
381 </body>
382 </html>