Trigger over OSC
in
Contributed Library Questions
•
1 year ago
Hello there.
So, I wanted to do a very simple thing, which turned out to be a disaster. I wanted to use two different sketches that communicate over OSC, and from the first to press a button, and wait on the second sketch to trigger one item in the Arraylist to appear on screen. Following I have the two sketches so that you can follow my idea.
The Arralist is triggered perfectly when is on the same sketch, but it does not work on two different sketches. The difference is that in the first case I evaluate a boolean - when true add a new item to the Arraylist - but in the second case I send a variable (1 or 0) to evaluate on the second sketch. This does not seem to work.
Any ideas???
- int b = 0;
- boolean captured;
- boolean isOverSomething;
- ArrayList shapeMove = new ArrayList();
- Button button;
- import oscP5.*;
- import netP5.*;
- OscP5 incomingOSC;
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- int intButtonEnter = 0;
- void setup(){
- size(800, 500);
- button = new Button(200, 300);
- oscP5 = new OscP5(this,12000);
- myRemoteLocation = new NetAddress("127.0.0.1", 12000);
- }
- void draw(){
- background(255);
- button.display();
- }
- void mousePressed(){
- if( button.pressed() ){
- intButtonEnter = 1;
- } else {
- intButtonEnter = 0;
- }
- OscMessage setNewCapsule = new OscMessage("/output");
- setNewCapsule.add(intButtonEnter);
- oscP5.send(setNewCapsule, myRemoteLocation);
- //println(intButtonEnter);
- }
- class ShapeMove{
- int x;
- int y;
- int h;
- int w;
- int origx;
- int origy;
- int deltax;
- int deltay;
- int posXdiff;
- int posYdiff;
- int xdragdelta;
- int ydragdelta;
- boolean over;
- boolean locked = false;
- boolean imCaptured = false;
- boolean overMe = false;
- ShapeMove(int _x, int _y, int _h, int _w) {
- x = _x;
- y = _y;
- h = _h;
- w = _w;
- }
- void isover() {
- if (mouseX >= x && mouseX <=x+w &&
- mouseY >= y && mouseY <= y+h) {
- over = true;
- isOverSomething = true;
- } else {
- over = false;
- isOverSomething = false;
- }
- }
- void overme() {
- if (isOverSomething) {
- if (overMe) {
- if (!over) {
- overMe = false;
- isOverSomething = false;
- }
- }
- } else {
- if (over) {
- overMe = true;
- isOverSomething = true;
- }
- }
- }
- void update() {
- if (over && mousePressed && !imCaptured && !captured) {
- deltax = x - mouseX;
- deltay = y - mouseY;
- origx = x;
- origy = y;
- captured = true;
- imCaptured = true;
- }
- if (!mousePressed && imCaptured) {
- captured = false;
- imCaptured = false;
- }
- if (imCaptured) {
- xdragdelta = x - (mouseX + posXdiff);
- ydragdelta = y - (mouseY + posYdiff);
- x = mouseX + deltax;
- y = mouseY + deltay;
- }
- }
- }
- class Button{
- int rectX, rectY; // Position of square button
- int rectSize = 50; // Diameter of rect
- color rectColor;
- color rectHighlight;
- boolean rectOver = false;
- Button(int _rectX, int _rectY) {
- smooth();
- rectColor = color(0);
- rectHighlight = color(51);
- rectX = _rectX;
- rectY = _rectY;
- }
- void display() {
- update(mouseX, mouseY);
- if (rectOver) {
- fill(rectHighlight);
- } else {
- fill(rectColor);
- }
- stroke(255);
- rect(rectX, rectY, rectSize, rectSize);
- }
- void update(int x, int y) {
- if ( overRect(rectX, rectY, rectSize, rectSize) ) {
- rectOver = true;
- } else {
- rectOver = false;
- }
- }
- boolean overRect(int x, int y, int width, int height) {
- if (mouseX >= x && mouseX <= x+width &&
- mouseY >= y && mouseY <= y+height) {
- return true;
- } else {
- return false;
- }
- }
- boolean pressed(){
- if( rectOver ) {
- return true;
- } else {
- return false;
- }
- }
- }
- int x; int y; int h; int w; int b = 0;
- boolean captured;
- boolean isOverSomething;
- ArrayList shapeMove = new ArrayList();
- int incomingButton;
- import oscP5.*;
- import netP5.*;
- OscP5 incomingOSC;
- OscP5 oscP5;
- void setup(){
- size(800, 500);
- oscP5 = new OscP5(this,12000);
- incomingOSC = new OscP5(this, 12000);
- }
- void draw(){
- background(255);
- for( int i = 0; i < shapeMove.size(); i++ ){
- ((ShapeMove)shapeMove.get(i)).update();
- ((ShapeMove)shapeMove.get(i)).display();
- }
- }
- void mousePressed(){
- if( incomingButton == 1){
- shapeMove.add( new ShapeMove((int)random(0,width),(int)random(0,height), (int)random(10,20), (int)random(10,20)) );
- }
- }
- class ShapeMove{
- int x; int y; int h; int w; int origx; int origy; int deltax; int deltay;
- int posXdiff; int posYdiff; int xdragdelta; int ydragdelta;
- boolean over;
- boolean locked = false;
- boolean imCaptured = false;
- boolean overMe = false;
- ShapeMove(int _x, int _y, int _h, int _w) {
- x = _x; y = _y; h = _h; w = _w;
- }
- void isover(){
- if (mouseX >= x && mouseX <=x+w &&
- mouseY >= y && mouseY <= y+h) {
- over = true;
- isOverSomething = true;
- } else {
- over = false;
- isOverSomething = false;
- }
- }
- void overme()
- {
- if (isOverSomething) {
- if (overMe) {
- if (!over) {
- overMe = false;
- isOverSomething = false;
- }
- }
- } else {
- if (over) {
- overMe = true;
- isOverSomething = true;
- }
- }
- }
- void update() {
- if (over && mousePressed && !imCaptured && !captured) {
- deltax = x - mouseX;
- deltay = y - mouseY;
- origx = x;
- origy = y;
- captured = true;
- imCaptured = true;
- }
- if (!mousePressed && imCaptured) {
- captured = false;
- imCaptured = false;
- }
- if (imCaptured) {
- xdragdelta = x - (mouseX + posXdiff);
- ydragdelta = y - (mouseY + posYdiff);
- x = mouseX + deltax;
- y = mouseY + deltay;
- }
- }
- void display() {
- rect(x, y, h, w);
- }
- }
- public void oscEvent(OscMessage msg) {
- if (msg.checkAddrPattern("/output") && msg.checkTypetag("i")) {
- incomingButton = msg.get(0).intValue();
- println("Button = " + incomingButton);
- }
- }
1