# How can I connect OSCP5 in Processing python

**URL:** <https://discourse.processing.org/t/how-can-i-connect-oscp5-in-processing-python/20688>\
**Category:** Processing.py\
**Created:** [May 9, 2020, 7:48pm UTC](https://discourse.processing.org/t/how-can-i-connect-oscp5-in-processing-python/20688 "2020-05-09T19:48:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lasc95](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lasc95/32/9140_2.png) [@lasc95](https://discourse.processing.org/u/lasc95)\
**Post date:** [May 9, 2020, 7:48pm UTC](https://discourse.processing.org/t/how-can-i-connect-oscp5-in-processing-python/20688/1 "2020-05-09T19:48:38Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 9, 2020, 9:09pm UTC](https://discourse.processing.org/t/how-can-i-connect-oscp5-in-processing-python/20688/2 "2020-05-09T21:09:03Z")

</div>

I hope this is enough to get you started?

```auto
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](http://www.sojamo.de/libraries/oscP5/examples/oscP5plug/oscP5plug.pde).

---

<div class="post-metadata">

**Author:** ![lasc95](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lasc95/32/9140_2.png) [@lasc95](https://discourse.processing.org/u/lasc95)\
**Post date:** [May 10, 2020, 4:02am UTC](https://discourse.processing.org/t/how-can-i-connect-oscp5-in-processing-python/20688/3 "2020-05-10T04:02:44Z")

</div>

it’s perfect! Thanks dude!

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [May 10, 2020, 7:13pm UTC](https://discourse.processing.org/t/how-can-i-connect-oscp5-in-processing-python/20688/4 "2020-05-10T19:13:38Z")

</div>

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

```auto
# 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.
