MaxLink to oscP5 conversion (Comunicate from Max/MSP to Processing)

edited September 2017 in Library Questions

Hi to all,

i've put this topic also in cycling74 forum because i don't know if it is a properly max/msp or processing question, anyway:

I'm starting to learn how communicate with Max/MSP and Processing. I've discovered first MaxLink libraries to do it, i've tried it and i found that it is now outdated and still unsupported so i'll go out with OSC (udpsend object) and oscP5 library in Processing to do the same things. So i've tried to learn how use Processing replicating and converting some easy examples of MaxLink libraries to oscP5, in particular the "shape_sketch" one, which send from max/msp a "bang" from /drawCircle, /drawSquare, /clear message objects to generate randomly 2D shapes in Processing, but i'm still newbie and i can't understand what is not working with oscP5, because, after i click that message objects in max/msp, in Processing nothing happens.

I'm asking if Processing can see a "bang" from max (like a string?), or i have to declare it in an other way. Processing has a similar max/msp "bang" function? The idea anyway is to use something that hit an ON value to "bang" an action, without use a streams of int or float values, like max/MSP does after clicking in a message object.

I'll attached here the Processing code:

import netP5.*;
import oscP5.*;
OscP5 link;
void setup() {
  size(300, 300);
  OscP5 link = new OscP5(this, 8080);

 // declare the variable name and the setter function name
  link.plug(this, "drawCircle", "/drawCircle");
  link.plug(this, "drawSquare", "/drawSquare");
  link.plug(this, "clear", "/clear");
void draw() {
  // must define draw function to
  // allow accurate future drawing
// these methods must be public
public void drawCircle() {
  fill(0, 0, 240, 200);
  float r = random(50) + 5;
  ellipse(random(width), random(height), r, r);
public void drawSquare() {
  fill(50, 240, 50, 200);
  float w = random(50) + 5;
  rect(random(width), random(height), w, w);
public void clear() {


  • Answer ✓

    Please format your code. Edit your post (gear on top right side of any of your posts), select your code and hit ctrl+o. Leaves an empty line above and below your block of code.

    Is it possible to see your code from MAX or provide links to your resources/sample code? Ok... not familiar with MAX but I will be important to see if you are setting max as a client or server when using OSC. The concept is that when running osc, processing and max cannot be the same. You always need to set one to be a client and the other to be a server. Before you attempt to create figures or animations, I would check if I am transmitting the right data. Also, I will recommend using a different port as 8080 might be use by other services. You could use other ports like 12000 and try to avoid using reserved ports as listed in


  • Hi kfrajer,

    I've edited and formatted code of previous post, i didn't know how do it, thank you.

    About Max/MSP code i'll attach here the code to copy and paste at clipboard from Max/MSP - File --> "New from clipboard".

    Anyway, as i wrote in previous post, i'm asking how i have to set Processing to receive the "change" of a value to generate a "bang" that do something, in this case drawing a figure.

  • @Alaghast -- can't test this now, but should your plug methods take an argument, like a boolean (even if you don't use it)? I'm not familiar with oscP5.plug, but I wonder if the method signature needs to exactly match the message -- and I thought an osc bang had a Boolean true argument, or maybe an int. if plug dispatch is trying to call drawCircle(boolean) and no such method exists, it could be silently swallowing your messages -- just guessing.

    I believe the demo sketch for plug has an oscEvents function that lets you inspect all raw osc that the sketch receives. If it doesn't receive any then this is probably a max/map broadcast problem or a network config / firewall problem.

  • On the Max/MSP side, are you familiar with this tutorial?

  • @jeremydouglass thanks for your observation, i knew that Max tutorial.

    I have grasped the solution to comunicate with Max and Processing with oscP5 plug method, also in oscEvent, but i prefer plug that is more simple and fast to declare.

  • Glad you worked out a solution, @Alaghast!

    Would you be willing to share a code snippet with the forum to demonstrate how you got the plug method working? This might help future users.

  • Sure! Here how plug in processing works:

    import oscP5.*;
    OscP5 oscP5;
    void setup(){
    oscP5 = new OscP5(this,12000);
    /* You define here with "/test" the message that come from Max,
    like an object [prepend /test].
    With "result" you define a name to build a function inside Processing */
    void draw() {
    // The function must be public 
    public void result(int valueA, float valueB, String valueS) {
      /*The cool thing is that you can send from [prepend /test] three message,
    inside a pack object for example, that have three different "type" of values*/
      println("The three result will be: " + valueA + ", " + valueB +" ," + valueS);

    And here a max patch example to comunicate with it:


    Hope this help!

  • Excellent -- thanks so much!

Sign In or Register to comment.