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=
"949.43">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Helvetica
; min-height: 23.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: 12.0px Helvetica
; min-height: 14.0px}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #812e25}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #9f2423}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
; color: #812e25}
20 p
.p11
{margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco
; min-height: 14.0px}
21 span
.s1
{color: #000000}
22 span
.s2
{color: #0030ae}
23 span
.s3
{color: #606060}
24 span
.s4
{color: #52691e}
25 span
.s5
{color: #812e25}
26 span
.s6
{color: #0020bb}
27 span
.s7
{color: #3c6d00}
28 span
.s8
{font: 12.0px Helvetica
}
29 span
.Apple-tab-span
{white-space:pre
}
33 <p class=
"p1"><b>Bundled Server Messages
</b></p>
34 <p class=
"p2"><br></p>
35 <p class=
"p3">When using the
<b>Synth
</b>/
<b>Node
</b>/
<b>Group
</b> sclang objects there is often a need to construct bundles to send messages together. For example when you want to start a synth that should be mapped instantly to certain buses, or need to ensure that two synths start with precise synchronisation.
</p>
36 <p class=
"p4"><br></p>
37 <p class=
"p3">The simplest way to deal with this is through Server's automated bundling support. This allows you to open a bundle into which all osc messages will be collected until it is sent. See
<b>Server
</b> for details of makeBundle's arguments.
</p>
38 <p class=
"p4"><br></p>
39 <p class=
"p5"><span class=
"Apple-tab-span"> </span>s.boot;
</p>
40 <p class=
"p5"><span class=
"Apple-tab-span"> </span>(
</p>
41 <p class=
"p6"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// send a synth def to server
</p>
42 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">SynthDef
</span>(
<span class=
"s3">"tpulse"</span>, {
<span class=
"s2">arg
</span> out=
0,freq=
700,sawFreq=
440.0;
</p>
43 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Out
</span>.ar(out,
<span class=
"s2">SyncSaw
</span>.ar(freq,
<span class=
"Apple-converted-space"> </span>sawFreq,
0.1) )
</p>
44 <p class=
"p5"><span class=
"Apple-tab-span"> </span>}).send(s);
</p>
45 <p class=
"p5"><span class=
"Apple-tab-span"> </span>)
</p>
46 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
47 <p class=
"p6"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// all OSC commands generated in the function contained below will be added to a bundle
</p>
48 <p class=
"p6"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// and executed simultaneously after
2 seconds.
</p>
49 <p class=
"p5"><span class=
"Apple-tab-span"> </span>(
</p>
50 <p class=
"p5"><span class=
"Apple-tab-span"> </span>s.makeBundle(
2.0, {
</p>
51 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x =
<span class=
"s2">Synth
</span>.new(
<span class=
"s3">"tpulse"</span>);
</p>
52 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a =
<span class=
"s2">Bus
</span>.control.set(
440);
</p>
53 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x.map(
<span class=
"s4">\freq
</span>, a);
</p>
54 <p class=
"p5"><span class=
"Apple-tab-span"> </span>});
</p>
55 <p class=
"p5"><span class=
"Apple-tab-span"> </span>)
</p>
56 <p class=
"p5"><span class=
"Apple-tab-span"> </span>x.free;
</p>
57 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
58 <p class=
"p6"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// don't send
</p>
59 <p class=
"p5"><span class=
"Apple-tab-span"> </span>(
</p>
60 <p class=
"p5"><span class=
"Apple-tab-span"> </span>b = s.makeBundle(
<span class=
"s2">false
</span>, {
<span class=
"Apple-converted-space"> <span class=
"Apple-tab-span"> </span></span></p>
61 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x = {
<span class=
"s2">PinkNoise
</span>.ar(
0.1) *
<span class=
"s2">In
</span>.kr(
0,
1); }.play;
</p>
62 <p class=
"p5"><span class=
"Apple-tab-span"> </span>});
</p>
63 <p class=
"p5"><span class=
"Apple-tab-span"> </span>)
</p>
64 <p class=
"p6"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// now pass b as a pre-existing bundle, and start both synths synchronously
</p>
65 <p class=
"p5"><span class=
"Apple-tab-span"> </span>(
</p>
66 <p class=
"p6"><span class=
"s1"><span class=
"Apple-tab-span"> </span>s.makeBundle(
</span><span class=
"s2">nil
</span><span class=
"s1">, {
</span>// nil executes ASAP
</p>
67 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>y = {
<span class=
"s2">SinOsc
</span>.kr(
0.2).abs }.play(x,
0,
0,
<span class=
"s4">\addBefore
</span>);
<span class=
"s5">// sine envelope
</span></p>
68 <p class=
"p5"><span class=
"Apple-tab-span"> </span>}, b);
</p>
69 <p class=
"p5"><span class=
"Apple-tab-span"> </span>)
</p>
70 <p class=
"p5"><span class=
"Apple-tab-span"> </span>x.free; y.free;
</p>
71 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
72 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
73 <p class=
"p3">To send a bundle with the default latency of the server, use the message
<b>bind
</b>:
</p>
74 <p class=
"p4"><br></p>
75 <p class=
"p5"><span class=
"Apple-tab-span"> </span>(
</p>
76 <p class=
"p5"><span class=
"Apple-tab-span"> </span>s.bind {
</p>
77 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s6">SynthDef
</span>(
<span class=
"s3">"tpulse2"</span>, {
<span class=
"s6">arg
</span> out=
0, freq=
700, sawFreq=
440.0;
</p>
78 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s6">Out
</span>.ar(out,
<span class=
"s6">Pan2
</span>.ar(
<span class=
"s6">SyncSaw
</span>.ar(freq,
<span class=
"Apple-converted-space"> </span>sawFreq,
0.1),
<span class=
"s6">SinOsc
</span>.kr(
8)) )
</p>
79 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}).send(s);
</p>
80 <p class=
"p8"><span class=
"s1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>s.sync;
</span>// wait until synthdef is loaded
</p>
81 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x =
<span class=
"s6">Synth
</span>.new(
<span class=
"s3">"tpulse2"</span>);
</p>
82 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a =
<span class=
"s6">Bus
</span>.control.set(
440);
</p>
83 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x.map(
<span class=
"s7">\freq
</span>, a);
</p>
84 <p class=
"p5"><span class=
"Apple-tab-span"> </span>};
</p>
85 <p class=
"p5"><span class=
"Apple-tab-span"> </span>)
</p>
86 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
87 <p class=
"p5"><span class=
"Apple-tab-span"> </span>a.free; x.free;
</p>
88 <p class=
"p7"><br></p>
89 <p class=
"p7"><span class=
"Apple-tab-span"> </span></p>
90 <p class=
"p3">In addition to this there are a number of methods which return OSC messages which can be added to a bundle. These are detailed in the helpfiles for
<b>Node
</b>,
<b>Synth
</b>, and
<b>Group
</b>.
</p>
91 <p class=
"p4"><br></p>
92 <p class=
"p9"><span class=
"s8"><span class=
"Apple-tab-span"> </span></span>s.boot;
</p>
93 <p class=
"p9"><span class=
"Apple-tab-span"> </span>b =
<span class=
"s2">List
</span>.new;
</p>
94 <p class=
"p9"><span class=
"Apple-tab-span"> </span>c =
<span class=
"s2">Bus
</span>.control(s,
1).set(
660);
</p>
95 <p class=
"p10"><span class=
"s1"><span class=
"Apple-tab-span"> </span>x =
</span><span class=
"s2">Synth
</span><span class=
"s1">.basicNew(
</span><span class=
"s3">"default"</span><span class=
"s1">, s);
</span>// Create without sending
</p>
96 <p class=
"p9"><span class=
"Apple-tab-span"> </span>b.add(x.newMsg);
</p>
97 <p class=
"p9"><span class=
"Apple-tab-span"> </span>b.add(x.mapMsg(
<span class=
"s4">\freq
</span>, c));
</p>
98 <p class=
"p10"><span class=
"s1"><span class=
"Apple-tab-span"> </span>b.postln;
</span>// here's what it looks like
</p>
99 <p class=
"p9"><span class=
"Apple-tab-span"> </span>s.listSendBundle(
1.0, b);
<span class=
"s5">// Execute after
1 second
</span></p>
100 <p class=
"p9"><span class=
"Apple-tab-span"> </span>c.set(
440);
</p>
101 <p class=
"p9"><span class=
"Apple-tab-span"> </span>s.queryAllNodes;
</p>
102 <p class=
"p9"><span class=
"Apple-tab-span"> </span>x.free;
</p>
103 <p class=
"p11"><br></p>
104 <p class=
"p11"><br></p>
105 <p class=
"p11"><br></p>