Processing and Max Msp - Send data from Processing to Max Msp

Hello everyone,

it’s been a few weeks since I’m trying to send the values of some variables from Processing to Max Msp through the Oscp5 library. Being a newcomer in programming with java and processing, and not being a computer scientist, but a composer, I hope the question below is not unpleasant.
I enclose the test sketch below:

//Davide Martiello sketch "trytopasssomedata"

import netP5.*;
import oscP5.*;

OscP5 oscP5;
NetAddress oscDestination;

OscMessage myMessage;

int numeri;
int a;
int b;
int value;

void setup() {
  size(10, 10);
  frameRate(30);
  oscP5 = new OscP5(this, 7374);
  oscDestination = new NetAddress("127.0.0.1", 7374);
  oscP5.plug(this, "a", "/a");
  oscP5.plug(this, "b", "/b"); 
}

//public void a(int value);
//public void b(int value);

void draw() {
  int[] numeri = new int[3];
  numeri[0] = 20; //assegno un valore al primo elemento dell'Array
  numeri[1] = 50; //assegno un valore al secondo elemento dell'Array
  numeri[2] = 1; //assegno un valore al terzo elemento dell'Array

  int a = numeri[0] + numeri[1]; <-----
  int b = numeri[1] + numeri[2]; <-----

  println(b);
  println(a);

  Ganzo();
}

void Ganzo() {
  OscMessage myMessage = new OscMessage ("/a");
  
  myMessage.add(a);
  
  OscMessage myMessage1 = new OscMessage ("/b");
  
  myMessage1.add(b);
  
  oscP5.send(myMessage, oscDestination);
  oscP5.send(myMessage1, oscDestination);
}

The two platforms communicate well and in real time without any latency.

I can see the values ​​within the processing console, but I cannot see the values of the variables “a” and “b” within Max Msp.

What appears on Max’s console is “received message:” to “0” b "0 , and I understand why:

I have to assign a value to the messages sent with the myMessage function, but I have already done it just above where I have indicated with this sign (<—).

Is it possible that Processing does not see the value already assigned to the function?

What I think I need to do is to tell the function myMessage.add (a) that a is the sum of two integers, and that it must take those values ​​and bring them as they are in Max Msp, but I have not yet succeeded to do it.

I hope someone can help me because I cannot find a solution.

Thank you and I hope you can help me.

Cordially,
Davide

a and b are not golbal variables in the lines you point out–they are declared inside draw(), so therefore can only be acessed inside draw().
Although you have put int a; and int b; at the beginning of your code, when you asign the values to it in draw later, you instead create new variables as you declare them as integers again.

A simple fix is just to remove the ints on the two lines you pointed out.
Another solution is to remove the int a; and int b; at the beginning and pass a and b into your Ganzo() function as arguments similar to this example.

Also, format your code using the </> button or by pressing ctrl+shift+C, please!

Hi Wizard Bear

thanks for your answer! Sorry for the code, next time I will format it for sure.

D.

1 Like

You can also edit existing posts. :wink:

1 Like

Hello Davide,

Would you please send the patch made with Max Msp?