OSC in Processing: Unterschied zwischen den Versionen

Aus hyperdramatik
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
//
<source lang="js" line start="2" highlight="4-6">
// oscP5sendreceive by andreas schlegel
 
// example shows how to send and receive osc messages.
/**
// oscP5 website at http://www.sojamo.de/oscP5
* oscP5sendreceive by andreas schlegel
//
* example shows how to send and receive osc messages.
 
* oscP5 website at http://www.sojamo.de/oscP5
*/
import oscP5.*;
import oscP5.*;
import netP5.*;
import netP5.*;
 
 
OscP5 oscP5;
OscP5 oscP5;
NetAddress myRemoteLocation;
NetAddress myRemoteLocation;
 
void setup() {
void setup() {
   size(400,400);
   size(400,400);
   frameRate(25);
   frameRate(25);
   // start oscP5, listening for incoming messages at port 12000 */
   /* start oscP5, listening for incoming messages at port 12000 */
   oscP5 = new OscP5(this,6448);
   oscP5 = new OscP5(this,6448);
 
 
   /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
   /* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
   * an ip address and a port number. myRemoteLocation is used as parameter in
   * an ip address and a port number. myRemoteLocation is used as parameter in
Zeile 26: Zeile 28:
   myRemoteLocation = new NetAddress("127.0.0.1",12000);
   myRemoteLocation = new NetAddress("127.0.0.1",12000);
}
}
 
 
void draw() {
void draw() {
   background(0);   
   background(0);   
}
}
 
void mousePressed() {
void mousePressed() {
   // in the following different ways of creating osc messages are shown by example */
   /* in the following different ways of creating osc messages are shown by example */
   OscMessage myMessage = new OscMessage("/spaghetti/1");
   OscMessage myMessage = new OscMessage("/spaghetti/1");
 
 
   myMessage.add(123); /* add an int to the osc message */
   myMessage.add(123); /* add an int to the osc message */
 
   // send the message */
   /* send the message */
   oscP5.send(myMessage, myRemoteLocation);  
   oscP5.send(myMessage, myRemoteLocation);  
}
}
 
 
// incoming osc message are forwarded to the oscEvent method. */
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
void oscEvent(OscMessage theOscMessage) {
   // print the address pattern and the typetag of the received OscMessage */
   /* print the address pattern and the typetag of the received OscMessage */
   print("### received an osc message.");
   print("### received an osc message.");
   print(" addrpattern: "+theOscMessage.addrPattern());
   print(" addrpattern: "+theOscMessage.addrPattern());
   print(" typetag: "+theOscMessage.typetag());
   print(" typetag: "+theOscMessage.typetag());
 
 
   // read the contents of the OSCmessage as float and print it */
   /* read the contents of the OSCmessage as float and print it */
   float messageValue = theOscMessage.get(0).floatValue();
   float messageValue = theOscMessage.get(0).floatValue();
   println(" message: "+messageValue);
   println(" message: "+messageValue);
}
}
</source>

Version vom 3. Mai 2022, 17:06 Uhr

/**
 * 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;

void setup() {
  size(400,400);
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this,6448);
  
  /* 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() {
  /* in the following different ways of creating osc messages are shown by example */
  OscMessage myMessage = new OscMessage("/spaghetti/1");
  
  myMessage.add(123); /* add an int to the osc message */

  /* 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());
  print(" typetag: "+theOscMessage.typetag());
  
  /* read the contents of the OSCmessage as float and print it */
  float messageValue = theOscMessage.get(0).floatValue();
  println(" message: "+messageValue);
}