How can I connect OSCP5 in Processing python

Hi dears, I try to connect Processing.py with supercollider but I have problems with import OSCP5. Can you help me :c How can I instance OSCP5, I imported with add_library(‘oscP5’).

thanks :smiley:

2 Likes

I hope this is enough to get you started?

add_library('oscP5')
from netP5 import *

def setup():
    global oscp5, addr
    oscp5 = OscP5(this, 12000)
    addr = NetAddress('127.0.0.1', 12000)
    
def draw():
    background(0)
    
def mousePressed():
    msg = OscMessage('/test')
    print(msg)
    oscp5.send(msg, addr)

It’s a partial port of this sketch.

3 Likes

it’s perfect! Thanks dude!

1 Like

I have once received data from a friend using supercollider. I don’t know the setup he used there to send things…

# data = dict()
# instruments = ['instrumentA',  'instrumentB', ... ]

def oscEvent(theOscMessage):
    # print theOscMessage
    for instrument in instruments:   
            if theOscMessage and theOscMessage.addrPattern() == "/"+ instrument:
                ins = theOscMessage.get(0).intValue() if theOscMessage.get(0) else 0
                tom = theOscMessage.get(1).intValue() if theOscMessage.get(1) else 0
                amp = theOscMessage.get(2).intValue() if theOscMessage.get(2) else 0
                cor = theOscMessage.get(3).intValue() if theOscMessage.get(3) else 0               
                data[instrument] = (ins, tom, amp, cor)
                # print(instrument, data[instrument])

I guess the main point is to define def oscEvent(theOscMessage): and read from theOscMEssage inside.