Oscjs meets Sonic Pi - Incoming Port number

HI everybody,

After the questions @dewildequinten about ocsjs, i do some researches to test ocsjs library.

i struggle with osc ports number.

so if somebody want to test i made a repo : https://github.com/nlebellier/ocsjsMeetsSonicPi

1 - we have to launch node before sonic-pi
2 - then sonicpi

It appears that the incoming osc port can’t be 4560 as usual so a randomized number is set by sonic pi. Can someone confirm this ?

If @robin.newman has some brilliant comments to add, he is welcomed or anybody else of course.

Cheers,


Nicolas

You’ve got your ports mixed up.
If you alter your index.js file as below

var osc = require("osc");


/****************
 * OSC Over UDP *
 ****************/

var getIPAddresses = function () {
    var os = require("os"),
        interfaces = os.networkInterfaces(),
        ipAddresses = [];

    for (var deviceName in interfaces) {
        var addresses = interfaces[deviceName];
        for (var i = 0; i < addresses.length; i++) {
            var addressInfo = addresses[i];
            if (addressInfo.family === "IPv4" && !addressInfo.internal) {
                ipAddresses.push(addressInfo.address);
            }
        }
    }

    return ipAddresses;
};

var udpPort = new osc.UDPPort({
    localAddress: "0.0.0.0",
    localPort: 9000,

	// below is the destination target, ie SonicPi ip and port
    remoteAddress: "127.0.0.1",
    remotePort: 4560,
    metadata: true
	
});

udpPort.on("ready", function () {
    var ipAddresses = getIPAddresses();
    console.log("Listening for OSC over UDP.");
    ipAddresses.forEach(function (address) {
        console.log(" Host:", address + ", Port:", udpPort.options.localPort);
    });
});

udpPort.on("message", function (oscMessage) {
    console.log(oscMessage);
});

udpPort.on("error", function (err) {
    console.log(err);
});

udpPort.open();


/*********** send to sonic pi *****/
// Every second, send an OSC message to Sonic Pi - 1000 ms = 1s :-)
setInterval(function() {
    var msg = {
        address: "/play/note",
        args: [
            {
 		    // midi note value 
		        type: "i",
                value: 60+24
            },
            {   // amp value a float to send decimal numbers
                type: "f",
                value: 1.5
            },
	        {   // sustain value
		        type: "f",
		        value: 2
		    }
        ]
    };

    console.log("Sending message", msg.address, msg.args, "to", udpPort.options.remoteAddress + ":" + udpPort.options.remotePort);
    udpPort.send(msg);
}, 1000);

and then use this in Sonic Pi to receive it works fine.

live_loop :test do
  n = sync "/osc*/play/note"
  puts play n[0],amp: n[1],sustain: n[2]
end

ADDENDUM I chose 9000 arbitrarily as the port associated with the node sender. Could be anything . The important thing is that Sonic Pi receives on port 4560. You had allocated this to the node app and so it wasn’t available for Sonic Pi.

Thank you @robin.newman
it’s now clear in my head and i forgot the use of *

The repo is updated.
Cheers

@nlb @robin.newman

Guys! Thanks so much for clearing this out for me!! It works perfectly.

:clap: :raised_hands: :clap: :raised_hands:

Glad you got there in the end. Enjoy using Sonic Pi via OSC!