But change the index.js line, cause no serial bus test.
var osc = require("osc");
/*******************
* OSC Over Serial *
*******************/
// Instantiate a new OSC Serial Port.
/*
* var serialPort = new osc.SerialPort({
devicePath: process.argv[2] || "/dev/tty.usbmodem221361"
});
//serialPort.on("message", function (oscMessage) {
console.log(oscMessage);
});
// Open the port.
// serialPort.open();
*/
/****************
* 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: 4560
});
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();
Important point : you have to first launch node . before launching sonicpi otherwise the port will be used
The tip : notice the incoming port into sonic pi and indicate it into index.js
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: 4560,
// Important : indicates the incoming port displayed into sonic pi ! here 51240
remoteAddress: "127.0.0.1",
remotePort: 51240,
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);
});
});
One point, I have found when using python OSC server to talk to Sonic Pi that it doesn’t like mixing localhost 127.0.0.1 with external ip address. If you are using everything on one machine localhost is fine, but if you have an external address involved you need to use the actual IP address of your local machine. Try and see if that helps.
Nice! Ok the code is drastically different from the example I used. Could you for info explain me why??
Because the math.random doesn’t shown where the message is ( the type and value part that does show in my code) And I don’t get where that’s coming from?
Also the code I shared with the repo is suddenly working and I think it is indeed because I need to node . first before doing anything else (that’s why the rebooting helped every time)
But I’m testing your code just to see if it’s works stable.
What I don’t get with the osc example I use
#test program
use_osc "localhost",4560
#send an osc message locally to trigger the live_loop
osc "/osc/play/note",72,100,2
live_loop :foo do
use_real_time
data = sync "/osc/play/note"
puts data
puts data[0],data[1],data[2]
synth :prophet, note: data[0], cutoff: data[1], sustain: data[2]
end
use_osc "localhost",4560
#send an osc message locally to trigger the live_loop
live_loop :sendMsg do
osc "/play/note",72,100,2
sleep 2
end
live_loop :foo do
use_real_time
data = sync "/osc:127.0.0.1:4560/play/note"
puts data
puts data[0],data[1],data[2]
synth :prophet, note: data[0], cutoff: data[1], sustain: data[2]
end
Eumh I tried both /osc/play/note and /play/note but nothing happens?
Though the internal example did work it does not work when it comes from the node script. @nlb thanks for your patience!
And how can I send just one message. Because my code I first showed, shows the data but it doesn’t trigger anything. And without that I don’t know if it actually works.
And for the moment I do not get how the code you showed above works (or what it actually sends as a message)
I want to use the first code (in my example) with the set interval because I can use the number I need from post.length (other code that I want to add later on) to set the interval timer of the osc.js I showed initially. (I will divide the post.length with 540 (=9min) to get an interval between 6 seconds give or take the post length.
But I only want to send a number between 1 / 8 (random) to trigger samples in an array.
I’m only telling this because this might make it easier to understand what I’m doing and might tell me that I’m doing it wrong. So as a sanity check
Merci encore pour votre patience et bonne nuit sage seigneur