Created
October 30, 2023 08:19
-
-
Save supertask/31d564c645c4fc0a28bcfcd1e1e25595 to your computer and use it in GitHub Desktop.
OSC Receiver by Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import oscP5.*; | |
import netP5.*; | |
OscP5 oscP5; | |
void setup() { | |
size(400, 400); | |
frameRate(25); | |
int port = 7474; | |
oscP5 = new OscP5(this, port); | |
println("Started OSC server. Port: " + port); | |
} | |
void draw() { | |
background(0); | |
} | |
void oscEvent(OscMessage theOscMessage) { | |
//Filtering | |
if (theOscMessage.addrPattern().startsWith("/sound") == false) { | |
return; | |
} | |
NetAddress remote = theOscMessage.netAddress(); | |
print("Sender IP: " + remote.address() + ", "); | |
print("Sender Port: " + remote.port() + ", "); | |
print("OSC Address Pattern: " + theOscMessage.addrPattern() + ", "); | |
print("Type Tag: " + theOscMessage.typetag() + ", "); | |
for (int i = 0; i < theOscMessage.typetag().length(); i++) { | |
char type = theOscMessage.typetag().charAt(i); | |
switch (type) { | |
case 's': // String | |
print("String: " + theOscMessage.get(i).stringValue() + ", "); | |
break; | |
case 'i': // int | |
print("Int: " + theOscMessage.get(i).intValue() + ", "); | |
break; | |
case 'f': // float | |
print("Float: " + theOscMessage.get(i).floatValue() + ", "); | |
break; | |
case 'd': // double | |
print("Double: " + theOscMessage.get(i).doubleValue() + ", "); | |
break; | |
case 'c': // char | |
print("Char: " + theOscMessage.get(i).charValue() + ", "); | |
break; | |
case 'T': // True | |
print("True, "); | |
break; | |
case 'F': // False | |
print("False, "); | |
break; | |
case 'N': // Null | |
print("Null, "); | |
break; | |
case 'b': // Blob | |
byte[] blob = theOscMessage.get(i).blobValue(); | |
print("Blob: " + new String(blob) + ", "); | |
break; | |
case 'h': // int64 | |
print("Int64: " + theOscMessage.get(i).longValue() + ", "); | |
break; | |
default: | |
print("Unknown type: " + type + ", "); | |
} | |
} | |
println(); // Move to the next line after printing all details | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment