1 class:: OSCresponderNode
2 summary:: client side network responder
3 related:: Classes/OSCFunc, Classes/OSCdef, Guides/OSC_communication, Classes/OSCpathResponder, Classes/NetAddr
4 categories:: External Control>OSC
7 note:: As of SC 3.5 link::Classes/OSCFunc:: and link::Classes/OSCdef:: are the recommended way of registering for incoming OSC messages. They are faster, safer, and have more logical argument order than the old responder classes, and they support pattern matching and custom listening ports. Use of the older classes OSCresponder, OSCresponderNode, and OSCpathResponder can be unsafe, since responders in user and class code can override each other unintentionally. They are maintained for legacy code only.::
9 Register a function to be called upon receiving a specific command from a specific OSC address. Same interface like link::Classes/OSCresponder::, but allows strong::multiple responders to the same command::.
11 Note that OSCresponderNode evaluates its function in the system process.
12 In order to access the application process (e.g. for GUI access ) use { ... }.defer;
14 Other applications sending messages to SuperCollider should distinguish between sending messages to the server or the language. Server messages are documented in the link::Reference/Server-Command-Reference:: and should be sent to the server's port - code::s.addr.port:: - which is strong::57110:: by default. Messages sent to the server will not be processed by any OSCresponder in the language.
16 Messages from external clients that should be processed by OSCresponders must be sent to the language port, strong::57120:: by default. Use code::NetAddr.langPort:: to confirm which port the SuperCollider language is listening on.
18 See link::Guides/OSC_communication:: for more details.
22 subsection::Setting up OSCresponderNode for listening to a remote application
25 // example: two SuperCollider apps communicating
28 n = NetAddr("127.0.0.1", 57120); // the url should be the one of computer of app 2 (or nil)
30 o = OSCresponderNode(n, '/chat', { |t, r, msg| ("time:" + t).postln; msg[1].postln }).add;
33 m = NetAddr("127.0.0.1", 57120); // the url should be the one of computer of app 1
34 m.sendMsg("/chat", "Hello App 1");
36 // sending bundles (including timestamps)
38 m.sendBundle(2.0, ["/chat", "Hello App 1"], ["/chat", "Hallo Wurld"]);
39 m.sendBundle(0.0, ["/chat", "Hello App 1"], ["/chat", "Hallo Wurld"]);
46 n.disconnect; o.remove;
49 subsection::Listening to data from _any_ client
52 // same as above, but we set the address to nil so we can receive from anywhere
53 // no need for a NetAddr since we are just listening (and not sending)
55 o = OSCresponderNode(nil, '/test', { |t, r, msg| msg.postln }).add;
59 subsection::Listening to data from _any_ client, but from a specific host
62 // 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
64 n = NetAddr("127.0.0.1", nil); // the url should be the one of computer of app 2
65 o = OSCresponderNode(n, '/test', { |t, r, msg| msg.postln }).add;
69 subsection::Listening to data from the server
72 // example from SendTrig
81 SynthDef("help-SendTrig",{
82 SendTrig.kr(Dust.kr(1.0), 0, 0.9);
85 // register to receive this message
86 a = OSCresponderNode(s.addr, '/tr', { arg time, responder, msg;
87 [time, responder, msg].postln;
89 b = OSCresponderNode(s.addr, '/tr', { arg time, responder, msg;
90 "this is another call".postln;
94 x = Synth.new("help-SendTrig");
100 subsection::Watching for something specific
103 // end of group message
107 a = OSCresponderNode(s.addr,'/n_end',{ arg time,responder,msg;
108 [time, responder, msg].postln;
109 if(msg[1] == g.nodeID,{
110 "g is dead !".postln;
122 subsection::Watching for errors
125 // example from ServerErrorGui in crucial lib
127 f = OSCresponderNode(s.addr, '/fail', { arg time, responder, msg;
130 mins = (time/60).round(1);
131 secs = (time%60).round(0.1);
132 if(secs<10,{ secs = "0"++secs.asString; },{ secs=secs.asString;});
134 //errors.label = "% % (%:%)".format(msg[1], msg[2], mins, secs);
135 //errors.stringColor = Color.white;
136 "% % (%:%)".format(msg[1], msg[2], mins, secs).postln;
142 Synth("gthhhhppppppp!");