We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › osc between processing and max msp ...
Page Index Toggle Pages: 1
osc between processing and max msp ... (Read 513 times)
osc between processing and max msp ...
Jan 2nd, 2007, 9:16am
 
Hi,

I cannot get any osc communication between processing and max msp to work, when I use the processing code posted below. Anyone, who have osc working between processing and max?



import oscP5.*;
import netP5.*;

import processing.opengl.*;

// receive information from netsend in max msp from 8 controllers and 6 buttons
float ctr1,  ctr2,  ctr3,  ctr4, ctr5,  ctr6,  ctr7,  ctr8, but1, but2, but3,  but4, but5,  but6;

// oscP5 instance for the osc communication
OscP5 oscP5;
int receiveAtPort;
int sendToPort;
String host;
String oscP5event;

void initOsc() {
       receiveAtPort = 7005;
       sendToPort = 7006;
       host = "127.0.0.1"; // 127.0.0.1 local host
       oscP5event = "oscEvent";
       oscP5 = new OscP5(
               this,
               host,
               sendToPort,
               receiveAtPort,
               oscP5event
               );
}


void oscEvent(OscIn oscIn) {
       println("received a message ... forwarding to analyseMessage(OscIn)");
       ctr1 = oscIn.getFloat(0);
       ctr2 = oscIn.getFloat(1);
       ctr3 = oscIn.getFloat(2);
       ctr4 = oscIn.getFloat(3);
       ctr5 = oscIn.getFloat(4);
       ctr6 = oscIn.getFloat(5);
       ctr7 = oscIn.getFloat(6);
       ctr8 = oscIn.getFloat(7);
       but1 = oscIn.getFloat(8);
       but2 = oscIn.getFloat(9);
       but3 = oscIn.getFloat(10);
       but4 = oscIn.getFloat(11);
       but5 = oscIn.getFloat(12);
       but6 = oscIn.getFloat(13);

 if (but1 == 1.0) {
   println("got button1");
   }

 if (but2 == 1.0) {
   println("got button2");
   }
   
 if (but3 == 1.0) {
   println("got button3");
   }

 if (but4 == 1.0) {
   println("got button4");
   }
   
 if (but5 == 1.0) {
   println("got button5");
   }
   
 if (but6 == 1.0) {
   println("got button6");
   }
   
 
}
void button1() {
/*
       OscMessage oscMsg = oscP5.newMsg("button1");
       
       // add an int to the osc message        
       oscMsg.add(100);
       
       // send the osc message
       // via the oscP5 bundle
       oscP5.sendMsg(oscMsg);  */
}



////////////////////////////////////////////////////////////////////////////////
///////////////////////
void setup(){
  size(320, 240, OPENGL);
  background(255);
  fill(200, 200, 200);
  initOsc();
 
 
 

}

void draw() {
 background(0);
 stroke(234);  
 line(20, ctr1, 20, 320);
 line(40, ctr2, 40, 320);
 line(60, ctr3, 60, 320);
 line(80, ctr4, 80, 320);
 line(100, ctr5, 100, 320);
 line(120, ctr6, 120, 320);
 line(140, ctr7, 140, 320);

 noStroke();
 
  // all the circles switch into a new color when the buttons are pushed//////////////////
 int[] circle1 = new int[] { 50, 50, 50 };
 int[] circle2 = new int[] { 50, 50, 50 };
 int[] circle3 = new int[] { 50, 50, 50 };
 int[] circle4 = new int[] { 50, 50, 50 };
 int[] circle5 = new int[] { 50, 50, 50 };
 int[] circle6 = new int[] { 50, 50, 50 };
 
  if(but1 == 1) {
     circle1[0] = 230;
     circle1[1] = 0;
     circle1[2] = 110;
     //button1();//OSC message is sent back to max when button is pushed
   } else if (but1 == 1) {
     circle1[0] = 50;
     circle1[1] = 50;
     circle1[2] = 50;
   }    

   if(but2 == 1) {
     circle2[0] = 230;
     circle2[1] = 0;
     circle2[2] = 110;
     //button2();//OSC message is sent back to max when button is pushed
   } else if (but2 == 1) {
     circle2[0] = 50;
     circle2[1] = 50;
     circle2[2] = 50;
   }
   
   if(but3 == 1) {
     circle3[0] = 230;
     circle3[1] = 0;
     circle3[2] = 110;
     //button3();//OSC message is sent back to max when button is pushed
   } else if (but3 == 1) {
     circle3[0] = 50;
     circle3[1] = 50;
     circle3[2] = 50;
   }
   
   if(but4 == 1) {
     circle4[0] = 230;
     circle4[1] = 0;
     circle4[2] = 110;
     //button4();//OSC message is sent back to max when button is pushed
   } else if (but4 == 1) {
     circle4[0] = 50;
     circle4[1] = 50;
     circle4[2] = 50;
   }
   
   if(but5 == 1) {
     circle5[0] = 230;
     circle5[1] = 0;
     circle5[2] = 110;
     //button5();
   } else if (but5 == 1) {
     circle5[0] = 50;
     circle5[1] = 50;
     circle5[2] = 50;
   }                            
   
   if(but6 == 1) {
     circle6[0] = 230;
     circle6[1] = 0;
     circle6[2] = 110;
     //button6();//OSC message is sent back to max when button is pushed
   } else if (but6 == 1) {
     circle6[0] = 50;
     circle6[1] = 50;
     circle6[2] = 50;
   }
   fill(circle1[0], circle1[1], circle1[2]);
   ellipse(20, 20, 20, 20);    
   fill(circle2[0], circle2[1], circle2[2]);
   ellipse(40, 20, 20, 20);
   fill(circle3[0], circle3[1], circle3[2]);
   ellipse(60, 20, 20, 20);    
   fill(circle4[0], circle4[1], circle4[2]);
   ellipse(80, 20, 20, 20);
   fill(circle5[0], circle5[1], circle5[2]);
   ellipse(80, 20, 20, 20);    
   fill(circle6[0], circle6[1], circle6[2]);
   ellipse(100, 20, 20, 20);

}


Page Index Toggle Pages: 1