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);
  background(250);
  noStroke();
  smooth();
  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() {
  background(250);
}

Answers

  • 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 https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

    Kf

  • 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.

    
    ----------begin_max5_patcher----------
    364.3ocwT1jaCBCDEdMbJr7ZZJl+a21iPWVEU4.iRbDXSsMIDEk6dw1PUZKR
    MpQsYiQyyCyv27v9nuGdknGTXzinWPddG887rRFAuwXObCsurlproga.khtF
    vAt8zPu1peeYMPkSxrJqnX016xlz3cMhNcMnsEhLp5jzGZA2WAFiVNtkRen1
    phOqDL9TEhFEao5xML95WkPo1Ujnr3EgAHRZl4QRnYMJZQHZo4UN46aVBtVh
    qjz8O+VGUByfcxM.aRZwhzArIVfye3uC6mXxA+dFriuAXWDclYmStJp4v9AL
    9FzcUsJfWgpEkz5MBkFUDVDNC+j44O7xfj7SPFQRsrFmOKk1gItlw+5YZaAM
    5eFcknSVNYEiGVQgeXIUfRy3TMSvOKGhKmYGtWZeR9m5S7upOtwHsscGHUiI
    aawv+JaERSXdfMjwcgw1PIriMkehUgJG7Q8fI1Ic1del6hAbinBj7Nl018Mc
    9j+6Lk9Qk.
    -----------end_max5_patcher-----------
    
  • @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?

    http://www.conceptualinertia.net/aoakenfo/sketch-1

  • @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 */
    
    oscP5.plug(this,"result","/test");
    }
    
    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:

    
    ----------begin_max5_patcher----------
    754.3ocyV0zbaBCD8r8uBMboWbcQBjA5k9WHS6wlNcjAkXkHjXPhDmIS9uWw
    JHeTicvejw4h7n0Rru2aWs693zIAK0q4l.z2Q+FMYxiSmLAL0ZXR29IAkr04
    RlANVPttrjqrAy7+mku1B1uRpYVzcLYCu++TMkBkjagKh6LVwr4qDpq+aMO2
    5cLljNmNCgoQyCmgVD2tRBmGh9S2cDEfKzKu4q3jW800M19OeXmUi8AIGNcP
    qgmlNscY1QRN6JdMG4VQksvGcutt.cuvtBroM4WPqjMW2eOoPwy0MJ3xj8TM
    HKx.AftvKJKZ2EEMrbPBOGxwur0NL6C1yPf1HTNoYMRXPLoQixYRIu.Ydnbo
    VdZjkTZqPfiCgeno6RVvomCYQnNvG.TJDpIPlOc24+zyAy9YiBxzaSxQ70rx
    JIDxunVmyMl1jAlp.kKE42hVxTmlWB3DHHSI9Hd3Ni3Qej5xxFqUq12vJIBf
    bFr5CtsqCBe7vvGuI76r3Oj8gJt2YAfri9yAvtRWHjcMein9kt7Asz8lV8E6
    OtLXP5Sd2BY3D3gaBDEIjg4e1QS+SK0iliiwzr8kx3r3W0Iq6k7VnbxmLJmj
    r2rE+55Vjr1MaiszyDaU76cteCxVwtEIPWgLCx4n2slDAG+Roosw4nOYbtlW
    wcUo+lkarAGVsXxBfwo3cwaxmKd2TTYZ4sT6lJYk1XcYrgggGnBDgi7ygryG
    23CoaD7gfVl+2D4.ZZs+VxazM048RVeWDzK3ovEmEJlU3Zc8xgxdyYJEEUZ2
    fKl9VVY9BX9dVIoOu64a3F8kWCjYvPzIEqIiAqQQ9Alf.B9MCH7LVwe7XkNF
    rh8BJwOKa6tMwJ4nvZ1HfpqvDhrkmXi0OIizO3izOzQ5msJ8chMIzK8oIPap
    PP5OJjEMBjQ7m4n7CYD9Auge7ESXUU2wqMcGFbgql4MZHQKYFrUn7agtdA07
    6D8mOFrvpckBst5fM09ZVqWDG3up1kxpZDcuvbd9oo+CTPCuCA
    -----------end_max5_patcher-----------
    

    Hope this help!

  • Excellent -- thanks so much!

Sign In or Register to comment.