Greetings
i am trying to send messages from processing to max, but i am not being able to do so. you can find my code below. any feedback would be highly appreciated
import controlP5.*;
import oscP5.*;
import netP5.*;
ControlP5 cp5;
OscP5 oscP5;
NetAddress oscAddress;
int myColor = color(0, 0, 0);
int numSliders = 10;
int numColumns = 2;
int sliderTicks1 = 100;
int sliderTicks2 = 30;
void setup() {
size(700, 400);
noStroke();
cp5 = new ControlP5(this);
// Initialize the OSC objects
oscP5 = new OscP5(this, 12000); // Listen on port 12000
oscAddress = new NetAddress("127.0.0.1", 57120); // IP address and port of the OSC server
for (int col = 0; col < numColumns; col++) {
for (int row = 0; row < numSliders; row++) {
cp5.addSlider("Slider_" + col + "_" + row)
.setPosition(100 + col * (width / numColumns), 50 + (20 * row))
.setRange(0, 255)
.setValue(255/2) // Set the initial value
;
}
}
// Create a NumBox
cp5.addNumberbox("myNumBox")
.setPosition(width*0.4, height*0.75)
.setSize(100, 30)
.setRange(1, 10) // Set the allowable range for input values
.setValue(5) // Set the initial value
;
}
void draw() {
background(sliderTicks1);
fill(myColor);
rect(0, 280, width, 70);
fill(sliderTicks2);
rect(0, 350, width, 50);
}
void controlEvent(ControlEvent event) {
if (event.isController()) {
String controllerName = event.getController().getName();
float value = event.getController().getValue();
// Send OSC message based on the controller name
if (controllerName.startsWith("Slider")) {
sendSliderOSC(controllerName, value);
} else if (controllerName.equals("myNumBox")) {
sendNumBoxOSC(value);
}
}
}
void sendSliderOSC(String sliderName, float value) {
try {
// Extract slider index from the controller name
int sliderIndex = Integer.parseInt(sliderName.split("_")[1]);
// Send OSC message when a slider value changes
OscMessage msg = new OscMessage("/slider");
msg.add(sliderIndex); // Include slider index in the message
msg.add(value); // Include the new slider value
oscP5.send(msg, oscAddress);
// Debugging statement
println("Sent OSC: " + msg);
} catch (Exception e) {
println("Error sending OSC message for slider " + sliderName + ": " + e.getMessage());
e.printStackTrace();
}
}
void sendNumBoxOSC(float value) {
try {
// Send OSC message when the number box value changes
OscMessage msg = new OscMessage("/numbox");
msg.add(value); // Include the new number box value
oscP5.send(msg, oscAddress);
} catch (Exception e) {
println("Error sending OSC message for numbox: " + e.getMessage());
e.printStackTrace();
}
}
by the way, if this is relevant, here is my MaxMSP code…
cheers
----------begin_max5_patcher----------
461.3oc0U9zSBCCFF+7HguCM87D1VYCwaFS7lFO3MCwT1ZvhasKccHFhe2s+
YiPbC1zPH3ARy6Seae5OVee61gCbfK3aHEPvMfW.NNaUJNFMshSsfCLCuINE
WXRDxHevWrB5VMmjrQZzKSxEjXBcMA3G344At6wGt84c4QSLYoV5UAy1olik
wuQYKeUsTo8b36McjmKHHJPO3OYlIRE.lWuJVYFkkRjlCj+dp7RYCYql7ybh
c+gPvbyTeMbfdTM31a3yHEE3kjlzmyERK2sQrO5nDOKbTnlQeMpQQc.bvkEv
9sAbTe9BeIx6gtcmKnLYajhBOFpAHy0WDxfJJ3ucW16Lhyji9kaJ5eFNndbQ
7hCG9HgZ+IfwEozDh.LVYndqZqWZe3yy1J0h4uGPzgqzbs+tuLM8Ib76DYyZ
OqWvTJqwKMlirdhe7mTAuTDW6QU6DvdG5DRgjxvRJmsWR5mUzYc3OG81Oc+5
ypg0aUGFd57qO1gPmT+76zuImT+B5zuvV8q5BKNOeMQTTsDqUpx2UbgN9ZWa
LkYiCswBxZZ8RhrRXgprTppIKElSHbSTUOVXFWUcyJolZOkhFVs0lNDLr5s2
brEKSmjgCTI7M.ixgXJ
-----------end_max5_patcher-----------