8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

送信したOSCメッセージの確認する受信処理を用意する

Posted at

OSCの受信を手早く確認するのにProcessingを使用する

Processingだと割と癖がなく、手早くOSCのメッセージを確認することが出来るので
、いつもProcessingのoscP5を利用して、送信したOSCメッセージを確認している

Processingが手元にないとき

  1. Processingのダウンロードページに移動する
  2. donation(寄付)の選択(払わないときはNo Dunationを選択)して、Downloadボタンをクリック
  3. 2.2.1のいずれかを選択(Version 3でも動くとは思うけど未確認) 20160520_Mocap_PR_001.png
  4. zipを解凍して、processing.exeを実行する

oscP5のサンプルソースを修正してOSCの受信を確認する

  1. ライブラリをコピーする。 場所:oscP5-0.9.8/oscP5/library/oscP5.jar
  2. サンプルソースにcodeフォルダを作成する 場所:oscP5/examples/oscP5sendReceive/code
  3. codeフォルダ配下にoscP5.jarをペーストする 場所:oscP5/examples/oscP5sendReceive/code/oscP5.jar
  4. oscP5sendReceive.pdeを開いて変更する 場所:oscP5/examples/oscP5sendReceive/oscP5sendReceive.pde
oscP5sendReceive.pde
/**
 * 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;

int receivePort = 12345;
String sendIP = "127.0.0.1";
int sendPort = 12001;

void setup() {
  size(400,400);
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this,receivePort);
  
  /* 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(sendIP,sendPort);
}


void draw() {
  background(0);  
}

void mousePressed() {
  /* in the following different ways of creating osc messages are shown by example */
  OscMessage myMessage = new OscMessage("/test");
  
  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());
  println(" typetag: "+theOscMessage.typetag());
  
  theOscMessage.print();
}

theOscMessage.print();

公式ドキュメント
http://www.sojamo.de/libraries/oscP5/reference/oscP5/OscMessage.html

image

値をとる時
theOscMessage.get(0).floatValue()

公式ドキュメント
http://www.sojamo.de/libraries/oscP5/reference/oscP5/OscArgument.html

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?