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.