SuperCollider CLASSES

OSCresponderNode

client side network responder
Inherits from: OSCresponder : Object

Description

NOTE: As of SC 3.5 OSCFunc and 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.

Register a function to be called upon receiving a specific command from a specific OSC address. Same interface like OSCresponder, but allows multiple responders to the same command.

Note that OSCresponderNode evaluates its function in the system process. In order to access the application process (e.g. for GUI access ) use { ... }.defer;

Other applications sending messages to SuperCollider should distinguish between sending messages to the server or the language. Server messages are documented in the Server Command Reference and should be sent to the server's port - s.addr.port - which is 57110 by default. Messages sent to the server will not be processed by any OSCresponder in the language.

Messages from external clients that should be processed by OSCresponders must be sent to the language port, 57120 by default. Use NetAddr.langPort to confirm which port the SuperCollider language is listening on.

See OSC Communication for more details.

Class Methods

Inherited class methods

Instance Methods

Inherited instance methods

Undocumented instance methods

-add

-added

-remove

-removeWhenDone

-value (time, msg, addr)

Examples

Setting up OSCresponderNode for listening to a remote application

// example: two SuperCollider apps communicating

// application 1:
n = NetAddr("127.0.0.1", 57120); // the url should be the one of computer of app 2 (or nil)

o = OSCresponderNode(n, '/chat', { |t, r, msg| ("time:" + t).postln; msg[1].postln }).add;

// application 2:
m = NetAddr("127.0.0.1", 57120); // the url should be the one of computer of app 1
m.sendMsg("/chat", "Hello App 1");

// sending bundles (including timestamps)
(
m.sendBundle(2.0, ["/chat", "Hello App 1"], ["/chat", "Hallo Wurld"]);
m.sendBundle(0.0, ["/chat", "Hello App 1"], ["/chat", "Hallo Wurld"]);
)

// end application 1:
o.remove;

Listening to data from _any_ client

// same as above, but we set the address to nil so we can receive from anywhere
// no need for a NetAddr since we are just listening (and not sending)

o = OSCresponderNode(nil, '/test', { |t, r, msg| msg.postln }).add;
o.remove;

Listening to data from _any_ client, but from a specific host

// 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

n = NetAddr("127.0.0.1", nil); // the url should be the one of computer of app 2
o = OSCresponderNode(n, '/test', { |t, r, msg| msg.postln }).add;
o.remove;

Listening to data from the server

// example from SendTrig

(
s.boot;
s.notify;
)

(
SynthDef("help-SendTrig",{
    SendTrig.kr(Dust.kr(1.0), 0, 0.9);
}).add;

// register to receive this message
a = OSCresponderNode(s.addr, '/tr', { arg time, responder, msg;
    [time, responder, msg].postln;
}).add;
b = OSCresponderNode(s.addr, '/tr', { arg time, responder, msg;
    "this is another call".postln;
}).add;
)

x = Synth.new("help-SendTrig");
a.remove;
b.remove;
x.free;

Watching for something specific

// end of group message

s.boot;

a = OSCresponderNode(s.addr,'/n_end',{ arg time,responder,msg;
    [time, responder, msg].postln;
    if(msg[1] == g.nodeID,{
        "g is dead !".postln;
        // g = Group.new;
    });
}).add;

g = Group.new;

g.free;

a.remove;

Watching for errors

// example from ServerErrorGui in crucial lib

f = OSCresponderNode(s.addr, '/fail', { arg time, responder, msg;
    {
        var mins,secs;
        mins = (time/60).round(1);
        secs = (time%60).round(0.1);
        if(secs<10,{ secs = "0"++secs.asString; },{ secs=secs.asString;});
        // put this on a gui
        //errors.label = "% % (%:%)".format(msg[1], msg[2], mins, secs);
        //errors.stringColor = Color.white;
        "% % (%:%)".format(msg[1], msg[2], mins, secs).postln;
    }.defer
});
f.add;

// cause a failure
Synth("gthhhhppppppp!");

f.remove