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

Davide Martiello's icon

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. I am aware of being in a forum not really dedicated to programming in Java language and with Processing, but I found a lot of very useful advice in these years of study, and I hope therefore that my question is not out of place.

I enclose the test sketch of Processing 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. I have used the udpreceive object and it works well, I have already install the CNMAT library and the Osc-route object works well, but the data that Max receives is always 0.
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 in Processing, 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) (or b whatever) 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

yaniki's icon

You created global variable a and b... and local variables a and b inside draw() function which is wrong strategy. Use global variables:

change this

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

to this

a = numeri[0] + numeri[1];
b = numeri[1] + numeri[2];