Include a header file required for build on mac 10.4
[supercollider.git] / Help / Control / OSCresponderNode.html
blob9bd37e6cd90d531aa60ec21f606dcf15504dec3f
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="824.44">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #ad140d}
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}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
18 span.s1 {font: 18.0px Helvetica}
19 span.s2 {color: #0043f0}
20 span.s3 {color: #002bf8}
21 span.s4 {color: #0024f8}
22 span.s5 {color: #000000}
23 span.s6 {color: #001bb9}
24 span.s7 {color: #606060}
25 span.s8 {color: #2c7014}
26 span.Apple-tab-span {white-space:pre}
27 </style>
28 </head>
29 <body>
30 <p class="p1"><span class="s1"><b>OSCresponderNode<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>client side network responder</b></p>
31 <p class="p2"><br></p>
32 <p class="p3"><br></p>
33 <p class="p4">Register a function to be called upon receiving a specific command from a specific OSC address.</p>
34 <p class="p4">same interface like <a href="OSCresponder.html"><span class="s2">OSCresponder</span></a><b>, </b>but allows<b><i> multiple responders to the same command</i></b>.</p>
35 <p class="p3"><br></p>
36 <p class="p4">Note that OSCresponderNode evaluates its function in the system process.</p>
37 <p class="p4">In order to access the application process (e.g. for GUI access ) use <b>{ ... }.defer</b>;</p>
38 <p class="p3"><br></p>
39 <p class="p4">Other applications sending messages to SuperCollider should distinguish between sending messages to the server or the language. Server messages are documented in the <a href="../ServerArchitecture/Server-Command-Reference.html"><span class="s3">Server-Command-Reference</span></a> and should be sent to the server's port - <b>s.addr.port</b> - which is 57110 by default. Messages sent to the server will not be processed by any OSCresponder in the language.</p>
40 <p class="p3"><br></p>
41 <p class="p4">Messages from external clients that should be processed by OSCresponders must be sent to the language port, <b>57120</b> by default. Use <b>NetAddr.langPort</b> to confirm which port the SuperCollider language is listening on.</p>
42 <p class="p3"><br></p>
43 <p class="p4">See <a href="OSC_communication.html"><span class="s4">OSC_communication</span></a> for more details.</p>
44 <p class="p3"><br></p>
45 <p class="p3"><br></p>
46 <p class="p4"><b>Setting up OSCresponderNode for listening to a remote application</b></p>
47 <p class="p3"><br></p>
48 <p class="p5">// example: two SuperCollider apps communicating</p>
49 <p class="p6"><br></p>
50 <p class="p5">// application 1:</p>
51 <p class="p5"><span class="s5">n = </span><span class="s6">NetAddr</span><span class="s5">(</span><span class="s7">"127.0.0.1"</span><span class="s5">, 57120); </span>// the url should be the one of computer of app 2 (or nil)</p>
52 <p class="p6"><br></p>
53 <p class="p7">o = <span class="s6">OSCresponderNode</span>(n, <span class="s8">'/chat'</span>, { <span class="s6">|t, r, msg|</span> (<span class="s7">"time:"</span> + t).postln; msg[1].postln }).add;</p>
54 <p class="p6"><br></p>
55 <p class="p5">// application 2:</p>
56 <p class="p5"><span class="s5">m = </span><span class="s6">NetAddr</span><span class="s5">(</span><span class="s7">"127.0.0.1"</span><span class="s5">, 57120); </span>// the url should be the one of computer of app 1</p>
57 <p class="p8"><span class="s5">m.sendMsg(</span>"/chat"<span class="s5">, </span>"Hello App 1"<span class="s5">);</span></p>
58 <p class="p6"><br></p>
59 <p class="p5">// sending bundles (including timestamps)</p>
60 <p class="p7">(</p>
61 <p class="p8"><span class="s5">m.sendBundle(2.0, [</span>"/chat"<span class="s5">, </span>"Hello App 1"<span class="s5">], [</span>"/chat"<span class="s5">, </span>"Hallo Wurld"<span class="s5">]);</span></p>
62 <p class="p8"><span class="s5">m.sendBundle(0.0, [</span>"/chat"<span class="s5">, </span>"Hello App 1"<span class="s5">], [</span>"/chat"<span class="s5">, </span>"Hallo Wurld"<span class="s5">]);</span></p>
63 <p class="p7">)</p>
64 <p class="p6"><br></p>
65 <p class="p5">// end application 2:</p>
66 <p class="p7">m.disconnect;</p>
67 <p class="p6"><br></p>
68 <p class="p5">// end application 1:</p>
69 <p class="p7">n.disconnect; o.remove;</p>
70 <p class="p3"><br></p>
71 <p class="p3"><br></p>
72 <p class="p4"><b>Listening to data from _any_ client</b></p>
73 <p class="p3"><br></p>
74 <p class="p5">// same as above, but we set the address to nil so we can receive from anywhere</p>
75 <p class="p5">// no need for a NetAddr since we are just listening (and not sending)</p>
76 <p class="p3"><br></p>
77 <p class="p7">o = <span class="s6">OSCresponderNode</span>(nil, <span class="s8">'/test'</span>, { <span class="s6">|t, r, msg|</span> msg.postln }).add;</p>
78 <p class="p7">o.remove;</p>
79 <p class="p3"><br></p>
80 <p class="p3"><br></p>
81 <p class="p4"><b>Listening to data from _any_ client, but from a specific host</b></p>
82 <p class="p3"><br></p>
83 <p class="p5">// same as above, but we use a NetAddr with a port of nil, so we can receive from a specific host, but from any port</p>
84 <p class="p3"><br></p>
85 <p class="p5"><span class="s5">n = </span><span class="s6">NetAddr</span><span class="s5">(</span><span class="s7">"127.0.0.1"</span><span class="s5">, nil); </span>// the url should be the one of computer of app 2</p>
86 <p class="p7">o = <span class="s6">OSCresponderNode</span>(n, <span class="s8">'/test'</span>, { <span class="s6">|t, r, msg|</span> msg.postln }).add;</p>
87 <p class="p7">o.remove;</p>
88 <p class="p3"><br></p>
89 <p class="p3"><br></p>
90 <p class="p4"><b>Listening to data from the server</b></p>
91 <p class="p3"><br></p>
92 <p class="p5">// example from SendTrig</p>
93 <p class="p6"><br></p>
94 <p class="p7">(</p>
95 <p class="p7">s = <span class="s6">Server</span>.local;</p>
96 <p class="p7">s.boot;</p>
97 <p class="p7">s.notify;</p>
98 <p class="p7">)</p>
99 <p class="p6"><br></p>
100 <p class="p7">(</p>
101 <p class="p8"><span class="s6">SynthDef</span><span class="s5">(</span>"help-SendTrig"<span class="s5">,{</span></p>
102 <p class="p7"><span class="Apple-tab-span"> </span><span class="s6">SendTrig</span>.kr(<span class="s6">Dust</span>.kr(1.0), 0, 0.9);</p>
103 <p class="p7">}).send(s);</p>
104 <p class="p6"><br></p>
105 <p class="p5">// register to receive this message</p>
106 <p class="p7">a = <span class="s6">OSCresponderNode</span>(s.addr, <span class="s8">'/tr'</span>, { <span class="s6">arg</span> time, responder, msg;</p>
107 <p class="p7"><span class="Apple-tab-span"> </span>[time, responder, msg].postln;</p>
108 <p class="p7">}).add;</p>
109 <p class="p7">b = <span class="s6">OSCresponderNode</span>(s.addr, <span class="s8">'/tr'</span>, { <span class="s6">arg</span> time, responder, msg;</p>
110 <p class="p8"><span class="s5"><span class="Apple-tab-span"> </span></span>"this is another call"<span class="s5">.postln;</span></p>
111 <p class="p7">}).add;</p>
112 <p class="p7">)</p>
113 <p class="p6"><br></p>
114 <p class="p6"><br></p>
115 <p class="p8"><span class="s5">x = </span><span class="s6">Synth</span><span class="s5">.new(</span>"help-SendTrig"<span class="s5">);</span></p>
116 <p class="p7">a.remove;</p>
117 <p class="p7">b.remove;</p>
118 <p class="p7">x.free;</p>
119 <p class="p6"><br></p>
120 <p class="p6"><br></p>
121 <p class="p4"><b>Watching for something specific</b></p>
122 <p class="p6"><br></p>
123 <p class="p5">// end of group message</p>
124 <p class="p6"><br></p>
125 <p class="p7">s.boot;</p>
126 <p class="p6"><br></p>
127 <p class="p7">a = <span class="s6">OSCresponderNode</span>(s.addr,<span class="s8">'/n_end'</span>,{ <span class="s6">arg</span> time,responder,msg;</p>
128 <p class="p7"><span class="Apple-tab-span"> </span>[time, responder, msg].postln;</p>
129 <p class="p7"><span class="Apple-tab-span"> </span>if(msg[1] == g.nodeID,{</p>
130 <p class="p8"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>"g is dead !"<span class="s5">.postln;</span></p>
131 <p class="p5"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// g = Group.new;</p>
132 <p class="p7"><span class="Apple-tab-span"> </span>});</p>
133 <p class="p7">}).add;</p>
134 <p class="p6"><br></p>
135 <p class="p7">g = <span class="s6">Group</span>.new;</p>
136 <p class="p6"><br></p>
137 <p class="p7">g.free;</p>
138 <p class="p6"><br></p>
139 <p class="p7">a.remove;</p>
140 <p class="p6"><br></p>
141 <p class="p6"><br></p>
142 <p class="p4"><b>Watching for errors</b></p>
143 <p class="p6"><br></p>
144 <p class="p5">// example from ServerErrorGui in crucial lib</p>
145 <p class="p6"><br></p>
146 <p class="p7">f = <span class="s6">OSCresponderNode</span>(s.addr, <span class="s8">'/fail'</span>, { <span class="s6">arg</span> time, responder, msg;</p>
147 <p class="p7"><span class="Apple-tab-span"> </span>{</p>
148 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s6">var</span> mins,secs;</p>
149 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>mins = (time/60).round(1);</p>
150 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>secs = (time%60).round(0.1);</p>
151 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>if(secs&lt;10,{ secs = <span class="s7">"0"</span>++secs.asString; },{ secs=secs.asString;});</p>
152 <p class="p5"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// put this on a gui</p>
153 <p class="p5"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>//errors.label = "% % (%:%)".format(msg[1], msg[2], mins, secs);</p>
154 <p class="p5"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>//errors.stringColor = Color.white;</p>
155 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s7">"% % (%:%)"</span>.format(msg[1], msg[2], mins, secs).postln;</p>
156 <p class="p7"><span class="Apple-tab-span"> </span>}.defer</p>
157 <p class="p7">});</p>
158 <p class="p7">f.add;</p>
159 <p class="p6"><br></p>
160 <p class="p5">// cause a failure</p>
161 <p class="p8"><span class="s6">Synth</span><span class="s5">(</span>"gthhhhppppppp!"<span class="s5">);</span></p>
162 <p class="p6"><br></p>
163 <p class="p7">f.remove</p>
164 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
165 <p class="p6"><br></p>
166 <p class="p6"><br></p>
167 </body>
168 </html>