Hi there,
I've written a little OSC controller for millumin.
All my GUI & Osc sending works as expected. All calls made directly to the button Handler work fine, and I can display Text, shapes, etc...
I'm also wanting to listen to touch OSC on port 5001, and once the osc message correspond to specific parametre it trigger a series of action.
-> Trigger a button event (so i can reuse the same code as if i had clicked on the UI).
-> Send an OSC message.
Now both ways of doing that , works, as far as getting a feedback on the console or sending an OSC message to the app.
My Problem is:
None of these method allow me to draw anything in the processing app. I wanting to display some Text saying what is the last button press.
Calling the same button function / event handlers from the Osc event handlers, It Prints to console, send OSC, but won't draw anything.
Just wondering what am I doing wrong ? As i can verify that the whole If Statement gets executed, but none of the draw related commands works ( fill(); rect(); text(); background(); )
See Code Below:
` // Millumin OSC Controller
// June 2016 - Olivier Jean.
// Manual Trigger via Processing UI & also listen to port 5001 for OSC trigger ( Here Touch Osc )
// GUI LIBRARY's
import controlP5.*;
// OSC LIBRARY's
import netP5.*;
import oscP5.*;
// Instantiate P5
ControlP5 cp5;
// Instantiate OSC
OscP5 oscP5;
NetAddress myBroadcastLocation; // Used in the Millumin SDK example
// we're counting since when we been running. (Disable Premature Button Press :/ I think there's setBroadcast(false) ?
//long timeElapsed;
boolean activate = false;
// Background color variable.
public int myColor = color(25);
public int myBkg = color(25);
// GUI Variables
int spacerTop = 250;
// floats to receive OSC values.
float v_toggle1 = 0.0f;
float v_toggle2 = 0.0f;
float v_toggle3 = 0.0f;
float v_toggle4 = 0.0f;
float v_toggle5 = 0.0f;
float v_toggle6 = 0.0f;
String s = "heyman";
//////////// SETUP ////////////
void setup() {
size(240, 700);
noStroke();
background(myBkg);
int spacefromtop = 60;
cp5 = new ControlP5(this);
// create a new button with name 'buttonA'
cp5.addButton("Button_A")
.setValue(1)
.setPosition(20,20)
.setSize(200,39)
.setColorBackground(45)
.setColorForeground(color(100,100,100))
.setColorActive(color(255, 0, 0))
.setColorValue(color(255, 255, 0))
.setColorLabel(color(255, 255, 255))
.setCaptionLabel("FADE TO BACK")
;
cp5.addButton("Button_B")
.setValue(1)
.setPosition(20,spacefromtop*1+20)
.setSize(200,39)
.setCaptionLabel("PLAY COLUMN 2")
;
cp5.addButton("Button_C")
.setValue(0)
.setPosition(20,spacefromtop*2+20)
.setSize(200,39)
.setCaptionLabel("PLAY COLUMN 3")
;
cp5.addButton("Button_D")
.setValue(0)
.setPosition(20,spacefromtop*3+20)
.setSize(200,39)
.setCaptionLabel("PLAY COLUMN 4")
;
cp5.addButton("Button_E")
.setValue(0)
.setPosition(20,spacefromtop*4+20)
.setSize(200,39)
.setCaptionLabel("PLAY COLUMN 5")
;
cp5.addButton("Button_F")
.setValue(0)
.setPosition(20,spacefromtop*5+20)
.setSize(200,39)
.setCaptionLabel("PLAY COLUMN 6")
;
// Based on the Millumin SDK example @ GitHub
oscP5 = new OscP5(this, 5001); //
myBroadcastLocation = new NetAddress("255.255.255.255", 5000); // change local host to multicast address
DisplayStatusText("Tx [5000] & Rx [5001]");
}
//////////// XXXXX ////////////
//////////// DRAW MAIN LOOP ////////////
void draw() {
if (millis() > 5000) activate = true ; // we disable OSC for 5sec ( prevents P5 setup event from sending OSC messages )
// println(millis());
}
//////////// XXXXXXXXXXXX ////////////
//////////// BUTTON EVENT HANDLERS ////////////
// for version of the code we built in the osc sending function into the button A handlers.
// for later version we would call the OSC Send function.
// function Button_A will receive changes from
// controller with name Button_A
public void Button_A(int theValue) {
println("a button event from Button_A: "+theValue);
println("Sending you some OSC Juice");
if ( activate == true ) {
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(1);
oscP5.send(myOscMessage, myBroadcastLocation);
DisplayStatusText("OSC Message ' FADE TO BLACK '");
myColor = color(30, 30, 30);
println ("Did you get that sweet OSC Juice ?");
}
}
public void Button_B(int theValue) {
println("a button event from Button_B: "+theValue);
if (activate == true) {
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(2);
oscP5.send(myOscMessage, myBroadcastLocation);
DisplayStatusText("OSC Message ' COLUMM 02 '");
myColor = color(255, 0, 0);
}
}
public void Button_C(int theValue) {
println("a button event from Button_C: "+theValue);
if (activate == true) {
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(3);
oscP5.send(myOscMessage, myBroadcastLocation);
DisplayStatusText("OSC Message ' COLUMM 03 '");
myColor= color(255, 255, 0);
}
}
public void Button_D(int theValue) {
println("a button event from Button_D: "+theValue);
if (activate == true) {
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(4);
oscP5.send(myOscMessage, myBroadcastLocation);
DisplayStatusText("OSC Message ' COLUMM 04 '");
myColor= color(255, 255, 0);
}
}
public void Button_E(int theValue) {
println("a button event from Button_E: "+theValue);
if (activate == true) {
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(5);
oscP5.send(myOscMessage, myBroadcastLocation);
DisplayStatusText("OSC Message ' COLUMM 05 '");
myColor= color(255, 255, 0);
}
}
public void Button_F(int theValue) {
println("a button event from Button_F: "+theValue);
if (activate == true) {
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(6);
oscP5.send(myOscMessage, myBroadcastLocation);
DisplayStatusText("OSC Message ' COLUMM 06 '");
myColor= color(255, 255, 0);
}
}
/////////// XXXXXXXXXXXXXXXX ////////////
/////////// OSC MESSAGE * IN * HANDLERS ////////////
public void oscEvent(OscMessage theOscMessage) {
String addr = theOscMessage.addrPattern();
float val = theOscMessage.get(0).floatValue();
if ((addr.equals("/1/black")) && (val == 1.0f)) {
Button_A(1);
}
if ((addr.equals("/1/playb")) && (val == 1.0f)) {
v_toggle2 = val;
Button_B(1);
}
if ((addr.equals("/1/playc")) && (val == 1.0f)) {
v_toggle3 = val;
DisplayStatusText("OSC Message ' COLUMM 03 '");
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(3);
oscP5.send(myOscMessage, myBroadcastLocation);
}
if ((addr.equals("/1/playd")) && (val == 1.0f)) {
DisplayStatusText("OSC Message ' COLUMM 04 '");
v_toggle4 = val;
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(4);
oscP5.send(myOscMessage, myBroadcastLocation);
}
if ((addr.equals("/1/playe")) && (val == 1.0f)) {
v_toggle5 = val;
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(5);
oscP5.send(myOscMessage, myBroadcastLocation);
fill(myBkg);
rect(10, spacerTop + 220, 220, 50);
fill(255, 255, 255);
text(" COLUMN 5 ", 20, spacerTop + 232);
fill(myColor);
}
if ((addr.equals("/1/playf")) && (val == 1.0f)) {
OscMessage myOscMessage = new OscMessage("/millumin/action/launchColumn");
myOscMessage.add(6);
oscP5.send(myOscMessage, myBroadcastLocation);
background(123,123,157);
fill(128);
rect(10, 20, 220, 500);
fill(255, 255, 255);
text(" COLUMN 6 ", 0, 0);
fill(25);
println("testing handler - got it");
}
}
//////////// XXXXXXXXXXXXXXXX ////////////
//////////// DISPLAY STATUS MESSAGE ////////////
public void DisplayStatusText(String theTextMessage) {
fill(myBkg);
rect(10, 470, 220, 50);
fill(255, 255, 255);
text(": " + theTextMessage, 20, 482);
fill(myColor);
}
//////////// XXXXXXXXXXXXXXXX //////////// `
Thanks a lot ;)