gregorami
YaBB Newbies
Offline
Posts: 8
receiving an array from maxlink
Jan 21st , 2007, 1:26am
Hi all, I am playing with connection between max msp and processing. So far I can send single numbers from max and assign them to variables in processing, but how do I send an array of numbers from max into processing? Here's what I tried to do: import maxlink.*; MaxLink link = new MaxLink(this, "message_board"); // get all messages from max link object - refer to object name public float num1, num2, num3, num4, num5; public int out1, out2, out3; int posX, posY; String oldMessage = ""; String message = ""; int messageCount = 0; // array to contain numbers an array sent from max float [] numbers = new float[3]; void setup() { size(300,300); background(20); // inlets from max to processing link.declareInlet("num1"); link.declareInlet("num2"); link.declareInlet("num3"); link.declareInlet("num4"); link.declareInlet("num5"); // array from max num3 = numbers[]; // Here I would like the input from mac - inlet 3 is an array to be written into an array in processing } void draw() { drawMessage(); stroke(250); line(20, 300, 20, num1); stroke(250); line(30, 300, 30, num2); stroke(250); line(40, 300, 40, num3); ellipseColor(); mouseAction(); arrayFromMax(); } // this method must be public - if a message number is different than previous, then notice it! public void setMessage(String newMessage) { messageCount++; link.output(messageCount); oldMessage = message; message = newMessage; } void drawMessage() { background(20); if (oldMessage != "") text("previous message: " + oldMessage, 37, 80); } // these two circles will be white if box is checked in max and grey otherwise void ellipseColor() { if(num4==1) { fill(255); noStroke(); ellipse(200, 30, 20, 20); } else { fill(100); noStroke(); ellipse(200, 30, 20, 20); } if(num5==1) { fill(255); noStroke(); ellipse(200, 57, 20, 20); } else { fill(100); noStroke(); ellipse(200, 57, 20, 20); } } // mouseClick and x/y coordinates will be sent to maxlink object in max void mouseAction() { posX=mouseX; posY=mouseY; if(mousePressed) { out1=1; } else { out1=0; } link.output(1,out1); noStroke(); fill(255); rect(posX, posY, 20, 20); //println("posX"); out2=posX; out3=posY; link.output(2,out2); link.output(3,out3); } void arrayFromMax() { fill(255); line(numbers[0], 50, numbers[1], 50); }