Coding help and SonicPi experiences needed

Hi,

I know this is not actually for this board. But I’m hoping one of you had already tried a similar thing and maybe want to share how they achieved it.

I’m not at all a very good programmer a more technical guy. But I’m still trying this because I want to finish something that at least works.
Soo any help is very appreciated.

Info: I have got a working tool to find data (numbers) and pull it to my terminal in node.js. The program checks every 10 min for a new pull.
I want to use the pulled numbers and divide them with 540. So for example the pull gave me x / 540 = y.
The following last step is to send an osc message a simple (bang in maxmsp terms) alert to sonic pi for every second y is.

But I’m unable to first get it wrapped up in my head how to exactly do that. I know I should use setinterval.

Secondly and most important. I can’t seem to install npm i osc in to raspberry pi.

Any body who got this to work?? Because this is needed to communicate with Sonic Pi which is my eandgoal in this project.

All help is really welcome!!!

Kind regards,

hi

well what’s your problem ? :slight_smile:

how to use osc with npm via the osc npm package ? which version of raspberry pi ? which os on it ?
could you draw a scheme of your installation ? Which machine ? wich role ? which softwares ? what do you want ? Max send to ***** ? sonic pi receives from ???

maybe then we could help you… not sure :wink:

@nlb ok I’ll try to explain it as good as possible bear with me :smiley:

Version Raspberry Pi :

Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux

Buster latest

I can’t install the node js osc package on this raspberry pi without getting loads of errors.

I want to send a message from a js script to sonic pi. The message should just be a “signal” (I’ve compared it with a bang like in max msp) when this osc message is received in Sonic Pi I would translate it to run a sound in an array to a speaker.
The last part is no problem. But I can’t get the signal to be send to sonic pi from the js script.

The whole process would run from one single pi. The osc message would be send internally thus.

I hope it’s a bit clearder :smiley:

@dewildequinten what version of Sonic Pi are you using?

latest 3.1.0 it is. Do you think is a version issue?

In that case, yes, quite likely. (At least as far as Sonic Pi itself is concerned). The version that came with the Pi is incomplete, as it was a build created externally, outside of Sam’s control. (OSC and MIDI do not work).
The latest official version of Sonic Pi is 3.2.2 - @robin.newman has kindly created a Raspberry Pi package for this: http://r.newman.ch/rpi/sonic-pi-3.2.2/ (it will only work on Raspbian Buster).
Give that a go, and hopefully it works for you :slight_smile:

Once that’s working, it’s just a matter of getting the javascript set up.

1 Like

well first find a solution for this no ? osc - npm
and ask Issues · colinbdclark/osc.js · GitHub

Edit : oups you did it :slight_smile: Sorry

Yes I did,

But I reinstalled everything and know the package is in my node-modules.

So I thought just try the example and see if that works. When importing the library with node and running it, it gave me no errors. But then I tried the example code and got following error:

code:

var osc = require("osc");

var udpPort = new osc.UDPPort({
    // This is the port we're listening on.
    localAddress: "127.0.0.1",
    localPort: 57121,

    // This is where sclang is listening for OSC messages.
    remoteAddress: "127.0.0.1",
    remotePort: 57120,
    metadata: true
});

// Open the socket.
udpPort.open();

// Every second, send an OSC message to SuperCollider
setInterval(function() {
    var msg = {
        address: "/hello/from/oscjs",
        args: [
            {
                type: "f",
                value: Math.random()
            },
            {
                type: "f",
                value: Math.random()
            }
        ]
    };

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

error:

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: bind EADDRINUSE 192.168.1.23:4559
    at dgram.js:337:20
    at processTicksAndRejections (internal/process/task_queues.js:85:21)
Emitted 'error' event on  instance at:
    at Socket.<anonymous> (/home/pi/Tools-for-Instagram/node_modules/osc/src/platforms/osc-node.js:79:18)
    at Socket.emit (events.js:327:22)
    at dgram.js:339:14
    at processTicksAndRejections (internal/process/task_queues.js:85:21) {
  errno: -98,
  code: 'EADDRINUSE',
  syscall: 'bind',
  address: '192.168.1.23',
  port: 4559

Not sure what you are trying to do here, but I can definitely help with the error - it says that it cannot listen on port 4559 because there is something else attached to it.
If you want to know what that is, just run a lsof -i -P | grep 4559 as root.

this is the response

ruby 3341 pi 18u IPv4 83410 0t0 UDP *:4559

But no idea wha this could be. Something from ruby??

UPDATE:

I restarted the whole machine and run it again.

Sending message /osc/trigger/prophet [
{ type: ‘f’, value: 0.8651540092898522 },
{ type: ‘f’, value: 0.5801701552646872 }
] to 127.0.0.1:4559
Sending message /osc/trigger/prophet [
{ type: ‘f’, value: 0.16566471922413717 },
{ type: ‘f’, value: 0.7892016716765036 }
] to 127.0.0.1:4559
Sending message /osc/trigger/prophet [
{ type: ‘f’, value: 0.8855032933937974 },
{ type: ‘f’, value: 0.3654368469507743 }
] to 127.0.0.1:4559

Is the output so that works

But there’s nothing coming in on the sonic pi on the same device…

I’ve changed the ip adress to the rpi ip but no difference.

well imo it’s sonic pi :slight_smile:

we want a scheme of your set up to help you ! we want a scheme of your set up to help you
:slight_smile:

Have you installed the 3.2.2 version of sonic pi ?

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!