osc_receiver_example.scd 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. s.boot;
  2. s.reboot;
  3. (
  4. // Define a custom function that listens on a given port
  5. ~startOSCListener = { |port, oscAddress|
  6. // Create a NetAddr for the server to bind to
  7. var udpIn, listener;
  8. // Start listening on the port
  9. udpIn = NetAddr.langPort(port); // binds to this port
  10. // Define the listener
  11. listener = OSCdef.new(
  12. key: "myOSCListener", // unique identifier
  13. func: { |msg, time, addr, recvPort|
  14. var val;
  15. val = msg[1]; // assuming single float argument
  16. // Print in the console (just for debugging)
  17. ["[OSC RECEIVED]", msg, "from", addr].postln;
  18. // Example: do something with `val`
  19. // You could control a Synth here
  20. },
  21. path: oscAddress,
  22. srcID: nil, // nil = accept from any IP
  23. recvPort: port
  24. );
  25. "Listening for OSC on port % at address '%'\n".format(port, oscAddress).postln;
  26. };
  27. )
  28. // Start the listener
  29. ~startOSCListener.(port: 8000, oscAddress: "/touchX"); // Change the oscAddress depending on what you want to receive