Coding help and SonicPi experiences needed

How exactly do I install this version on RPi3 ?
I only found the update but that brought me to 3.1.0

have a look above :slight_smile:

Whoops missed that one! Successfully installed it but nothing happens.

Weird thing is that I can’t change anything about the arguments or the code breaks. If I change the f type it breaks if I change the value to whatever it also breaks.

Is there a better osc javascript package :stuck_out_tongue: ?? :smiley:

what about a sketch to understand your setup ? :slight_smile:
would you put your code into a public repo ? maybe someone can test it ?

Sure it is totally open for me :slight_smile:

The repo is Tools-for-Instagram. I installed the osc.js correctly because it shows up in my node-modules in the Tools-for-Instgram.

But at the moment I just ran the osc.js example from the osc.js repo the (supercollider example!))

And put those files in the tools-for-instagram folder.
I wanted to test the osc.js code first before trying to merge two scripts together.

I’ll upload the folder of mine to my GitHub if it’s necessary. I’ll have to figure that one out then to but let me know!

Did it anyways

Also, when you have installed 3.2.2 from my site, you want to send OSC messages to port 4560 which is now used by recent SonicPI version not 4559.

1 Like

@robin.newman Thanks! wonderful job again with the update!

I changed it but nothing changed…

OK I’ve not looked at your code in detail, but I’m not sure where your 4559 port is coming from, as you shouldnt be using that with Sonic Pi 3.2.2

If you are reffering to the code in the thread, that’s already adjust by the advice of @nlb.

The repo I posted shows the complete setup and code currently using.
It’s under bots/osc.js

Kind regards!

I’ve tried to send the osc message to my mac sonic pi 3.2

But I got this error again

Sending message /osc/trigger/prophet [
  { type: 'f', value: 0.27846073507523084 },
  { type: 'f', value: 0.027304372553160983 }
] to 192.168.1.8:4560
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: send EINVAL 192.168.1.8:4560
    at doSend (dgram.js:681:16)
    at defaultTriggerAsyncIdScope (internal/async_hooks.js:313:12)
    at afterDns (dgram.js:627:5)
    at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on  instance at:
    at /home/pi/Tools-for-Instagram/node_modules/osc/src/platforms/osc-node.js:126:22
    at processTicksAndRejections (internal/process/task_queues.js:83:21) {
  errno: -22,
  code: 'EINVAL',
  syscall: 'send',
  address: '192.168.1.8',
  port: 4560
}

I did lsof -i -P | grep 4560 on both machines and nothing came up.

Hi @dewildequinten,

So i test oscjs :slight_smile: from the github repo https://github.com/colinbdclark/osc.js-examples

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 :slight_smile:

and then it works.

Hope it helps you !

ah i gonna try to send too now :slight_smile:

it works :slight_smile:

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);
    });
});

Au plaisir !

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.

Hi,

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 

And the incoming cue

/osc:127.0.0.1:4600/osc/play/note [70.0, 70.0]

Doesn’t generate any sounds.

Did I overlook something again??

Hi @dewildequinten

try this

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! :smiley:

  • so change into ocs.js , address /play/note no need for osc since spi waits for /play/note
  • you send two parameters, so data[2] does not exist.

you can add a little play :c5 after puts data to see if the live_loop is triggered
Note that sometimes you may need restart sonic pi when using osc.

Bonne nuit les petits :slight_smile:

So I tried this and it doesn’t work.

I also really don’t get the code above, I don’t know what’s sending the message and what is the message. Well I don’t get it.

Than your last reply change into osc.js => what do I change exactly?

Following you say that I send 2 parameters, by that do you mean

args: [
            {
                type: "f",
                value: Math.random()
            },
            {
                type: "f",
                value: Math.random()
            }
        ]

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 :slight_smile:

Merci encore pour votre patience et bonne nuit sage seigneur

hi @dewildequinten,

ok may i have missed some part of code. so i create a new post concerning oscjs and sonic pi.

Hope it can help you in your project.

I have given some input in your separate thread and shown how to get that working.

1 Like