Processing Max Msp. Sending data to Max

Hello guys!

I would like to send data to max (float and int).
I made a small sketch based on the example of the library oscP5, but I don’t know at all, if we can send several int like that. There is a problem with floats.

I read this in the monitor, I’m not sure it a good sign.

[2020/3/24 17:31:17] PROCESS @ OscP5 stopped.
[2020/3/24 17:31:17] PROCESS @ UdpClient.openSocket udp socket initialized.
[2020/3/24 17:31:18] ERROR @ UdpServer.start() IOException, couldnt create new DatagramSocket @ port 12000 java.net.BindException: Address already in use (Bind failed)
[2020/3/24 17:31:23] INFO @ OscP5 is running. you (192.168.1.105) are listening @ port 12000

I will put the patch of Max Msp later.

Thank you to all !

/**
 * oscP5sendreceive by andreas schlegel
 * example shows how to send and receive osc messages.
 * oscP5 website at http://www.sojamo.de/oscP5
 */
 
import oscP5.*;
import netP5.*;
  
OscP5 oscP5;
NetAddress myRemoteLocation;

float speedA, speedB, speedC, speedD, speedE;
int numberofrevolutionA, numberofrevolutionB, numberofrevolutionC, numberofrevolutionD, numberofrevolutionE;


void setup() {
  size(400,400);
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this,12000);
      speedA=0.01;
      speedB=0.02;
      speedC=0.03;
      speedD=0.04;
      speedE=0.05;
  
      numberofrevolutionA =0;
     numberofrevolutionB =1;
     numberofrevolutionC =2;
     numberofrevolutionD =3;
     numberofrevolutionE =4;
    
  
  /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
   * an ip address and a port number. myRemoteLocation is used as parameter in
   * oscP5.send() when sending osc packets to another computer, device, 
   * application. usage see below. for testing purposes the listening port
   * and the port of the remote location address are the same, hence you will
   * send messages back to this sketch.
   */
 // myRemoteLocation = new NetAddress("127.0.0.1",12000);
}


void draw() {
  background(0);  
}

void mousePressed() {
  
 
  
  numberofrevolutionA = numberofrevolutionA+1; numberofrevolutionB = numberofrevolutionB+1; numberofrevolutionC = numberofrevolutionC+1;
  speedA=speedA+0.01; speedB=speedB+0.01; speedC=speedC+0.01;
   
  /* in the following different ways of creating osc messages are shown by example */
  OscMessage myMessage = new OscMessage("/test");
  
  println (numberofrevolutionA, numberofrevolutionB, numberofrevolutionC );
  println (speedA, speedB, speedC);
  
  myMessage.add(numberofrevolutionA, numberofrevolutionA, numberofrevolutionB, numberofrevolutionC ); /* add an int to the osc message */
 // myMessage.add(speedA, speedB, speedC);
  
  

  /* send the message */
 // oscP5.send(myMessage, myRemoteLocation); 
}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  /* print the address pattern and the typetag of the received OscMessage */
  print("### received an osc message.");
  print(" addrpattern: "+theOscMessage.addrPattern());
  println(" typetag: "+theOscMessage.typetag());
}
/**
 * oscP5sendreceive by andreas schlegel
 * example shows how to send and receive osc messages.
 * oscP5 website at http://www.sojamo.de/oscP5
 */
 
import oscP5.*;
import netP5.*;
  
OscP5 oscP5;
NetAddress myRemoteLocation;

float speedA, speedB, speedC, speedD, speedE;
int numberofrevolutionA, numberofrevolutionB, numberofrevolutionC, numberofrevolutionD, numberofrevolutionE;


void setup() {
  size(400,400);
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this,12000);
      speedA=0.01;
      speedB=0.02;
      speedC=0.03;
      speedD=0.04;
      speedE=0.05;
  
      numberofrevolutionA =0;
     numberofrevolutionB =1;
     numberofrevolutionC =2;
     numberofrevolutionD =3;
     numberofrevolutionE =4;
    
  
  /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
   * an ip address and a port number. myRemoteLocation is used as parameter in
   * oscP5.send() when sending osc packets to another computer, device, 
   * application. usage see below. for testing purposes the listening port
   * and the port of the remote location address are the same, hence you will
   * send messages back to this sketch.
   */
 // myRemoteLocation = new NetAddress("127.0.0.1",12000);
}


void draw() {
  background(0);  
}

void mousePressed() {
  
 
  
  numberofrevolutionA = numberofrevolutionA+1; numberofrevolutionB = numberofrevolutionB+1; numberofrevolutionC = numberofrevolutionC+1;
  speedA=speedA+0.01; speedB=speedB+0.01; speedC=speedC+0.01;
   
  /* in the following different ways of creating osc messages are shown by example */
  OscMessage myMessage = new OscMessage("/test");
  
  println (numberofrevolutionA, numberofrevolutionB, numberofrevolutionC );
  println (speedA, speedB, speedC);
  
  myMessage.add(numberofrevolutionA, numberofrevolutionA, numberofrevolutionB, numberofrevolutionC ); /* add an int to the osc message */
 // myMessage.add(speedA, speedB, speedC);
  
  

  /* send the message */
 // oscP5.send(myMessage, myRemoteLocation); 
}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  /* print the address pattern and the typetag of the received OscMessage */
  print("### received an osc message.");
  print(" addrpattern: "+theOscMessage.addrPattern());
  println(" typetag: "+theOscMessage.typetag());
}
1 Like

@bking Were you able to resolve this issue?

Yes and no.

I haven’t really tried to send data directly from Processing to Max.
But, as I succeeded in sending data from Processing to Arduino and Arduino to Max, I tried to send data this way. I had a small bug, but it seems easily doable. :grinning: :blush: :innocent:
But since my lovely and charming daughter spilled sweet milk on my MacBookPro , I can’t show you the solution right now. I will do it ASAP.
But the direct solution, Processing to Max, interests me just to compare the fluidity of sending and receiving data between Processing and Max.
In fact, I don’t know if it’s useful to think about this direct solution.
In the end, I should send to Max Msp, 10 speed data, 10 position data (between 0 and 2PI) and 10 data informing of the number of revolutions that my virtual engines make, then send this data from Max4live to Abelton Live. (a patch max/msp transformed to be red directly in Ableton Live).
I already managed to do this with 5 information of speeds and number of laps, but I had small bugs in Live because I had sent too much MIDI information coming from Max Msp, or sent too quickly. :thinking:

To settle this, I bought a 15 inch quad core i7, 16 GB macbook from Ram, hoping that Ableton Live will work better. I had a macBook 13.3 from 2014.

Thank you for all your advice and all the solutions you have already given me;) :smiling_face_with_three_hearts:

1 Like

Some past Max-Processing libraries that might be of interest. They generally build on using oscP5 / OSC. I’d suggest looking at the most recent ones first (newest first, oldest is last)

1 Like