Sfoglia il codice sorgente

adding some useful functions to be used later

Thomas GUFFROY 7 mesi fa
parent
commit
347c6accb3
1 ha cambiato i file con 42 aggiunte e 0 eliminazioni
  1. 42 0
      resources for sc and juce/osc_receiver_example.scd

+ 42 - 0
resources for sc and juce/osc_receiver_example.scd

@@ -0,0 +1,42 @@
+s.boot;
+s.reboot;
+
+
+(
+// Define a custom function that listens on a given port
+~startOSCListener = { |port, oscAddress|
+
+    // Create a NetAddr for the server to bind to
+    var udpIn, listener;
+
+    // Start listening on the port
+    udpIn = NetAddr.langPort(port); // binds to this port
+
+    // Define the listener
+    listener = OSCdef.new(
+        key: "myOSCListener",  // unique identifier
+        func: { |msg, time, addr, recvPort|
+            var val;
+
+            val = msg[1]; // assuming single float argument
+
+			// Print in the console (just for debugging)
+            ["[OSC RECEIVED]", msg, "from", addr].postln;
+
+
+            // Example: do something with `val`
+            // You could control a Synth here
+
+
+        },
+        path: oscAddress,
+        srcID: nil,  // nil = accept from any IP
+        recvPort: port
+    );
+
+    "Listening for OSC on port % at address '%'\n".format(port, oscAddress).postln;
+};
+)
+
+// Start the listener
+~startOSCListener.(port: 8000, oscAddress: "/touchX"); // Change the oscAddress depending on what you want to receive