|
/* |
|
* Sending OSC Type Tag "T", "F", and "N" in Processing |
|
* written by cleemy desu wayo / Licensed under CC0 1.0 |
|
* 2025-09-29 |
|
* ---- |
|
* possibly the updated version is here: |
|
* https://gist.github.com/cleemy-desu-wayo/e966a18706530e3af61867b2b3808d24 |
|
* |
|
* ---- |
|
* require: oscP5, controlP5 |
|
* (this code has been confirmed to work with Processing 4.4.7 and oscP5 0.9.9) |
|
* |
|
*/ |
|
|
|
import oscP5.*; |
|
import netP5.*; |
|
import controlP5.*; |
|
|
|
OscP5 osc; |
|
NetAddress destHost; |
|
ControlP5 cp5; |
|
|
|
int listenPort = 9004; // change this line appropriately |
|
int destPort = 9003; // change this line appropriately |
|
String fontName = "Noto Sans Mono"; // change this line appropriately |
|
|
|
void setup() { |
|
osc = new OscP5(this, listenPort); |
|
destHost = new NetAddress("localhost", destPort); |
|
|
|
frameRate(60); |
|
size(290, 560); |
|
cp5 = new ControlP5(this); |
|
PFont pfont = createFont(fontName, 14, true); |
|
ControlFont font = new ControlFont(pfont); |
|
|
|
int btnWidth = 250; |
|
int btnHeight = 40; |
|
int btnMarginX = 20; |
|
int btnMarginY = 20; |
|
|
|
String[] btnName = new String[9]; |
|
btnName[0] = "button01"; btnName[1] = "button02"; btnName[2] = "button03"; |
|
btnName[3] = "button04"; btnName[4] = "button05"; btnName[5] = "button06"; |
|
btnName[6] = "button07"; btnName[7] = "button08"; btnName[8] = "button09"; |
|
|
|
String[] btnCaption = new String[9]; |
|
btnCaption[0] = "send /test T"; btnCaption[1] = "send /test F"; |
|
btnCaption[2] = "send /test N"; btnCaption[3] = "send /test TFN"; |
|
btnCaption[4] = "send /test sT aaa1"; btnCaption[5] = "send /test iiiT 1 2 3"; |
|
btnCaption[6] = "send /test Tiii 4 5 6"; btnCaption[7] = "send /test iiiN 7 8 9"; |
|
btnCaption[8] = "send /test Niii 10 11 12"; |
|
|
|
for(int i = 0; i < btnName.length; i++) { |
|
cp5.addButton(btnName[i]) |
|
.setPosition(btnMarginX, btnMarginY + (btnHeight + btnMarginY) * i) |
|
.setSize(btnWidth, btnHeight) |
|
.setCaptionLabel(btnCaption[i]) |
|
.setFont(font) |
|
; |
|
cp5.getController(btnName[i]).getCaptionLabel().toUpperCase(false); |
|
} |
|
} |
|
|
|
void draw() { } |
|
|
|
void button01() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add(true); |
|
osc.send(msg, destHost); |
|
} |
|
|
|
void button02() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add(false); |
|
osc.send(msg, destHost); |
|
} |
|
|
|
void button03() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add(); |
|
osc.send(msg, destHost); |
|
} |
|
|
|
void button04() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add(true).add(false).add(); |
|
osc.send(msg, destHost); |
|
} |
|
|
|
void button05() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add("aaa1").add(true); |
|
osc.send(msg, destHost); |
|
} |
|
|
|
void button06() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add(new int[] {1, 2, 3}).add(true); |
|
osc.send(msg, destHost); |
|
} |
|
|
|
void button07() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add(true).add(new int[] {4, 5, 6}); |
|
osc.send(msg, destHost); |
|
} |
|
|
|
void button08() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add(new int[] {7, 8, 9}).add(); |
|
osc.send(msg, destHost); |
|
} |
|
|
|
void button09() { |
|
OscMessage msg = new OscMessage("/test"); |
|
msg.add().add(new int[] {10, 11, 12}); |
|
osc.send(msg, destHost); |
|
} |