home/ atoms/ sc-osc-oscdef

OSCdef registers a named function to respond to incoming OSC messages by address

SuperCollider’s scsynth is the process that handles OSC communication. OSCdef.new(name, function, address) registers a function invoked whenever an OSC message with the matching URL-style address arrives. The function receives arguments: msg (the full message array, msg[0] is address, msg[1..] are values), time, addr (source NetAddr), and recvPort. The default SC listening port is 57120 (check with NetAddr.langPort). Unlike MIDIdef, OSCdef addresses use single-quote Symbol syntax '/my/path' rather than backslash syntax. OSCdef can be disabled, re-enabled, freed, or made permanent (surviving command-period).

Examples

OSCdef.new(\toggle, { arg msg; msg[1].postln; }, '/main/toggle1');

Assessment

You receive an OSC message at address /sensor/x and want to use the first numeric value to set the frequency of a running Synth. Write the OSCdef, assuming the Synth is stored in ~x.

“OSCdef.new( oggle, { arg msg, time, addr, port; [msg, time, addr, port].postln; } )”
corpus · supercollider-tutorials-full-transcripts-and-code-eli-fields · chunk 30