Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • How to reconnect/stop OscP5 TCPIP ?

    Hello, i want to stop and start new connection, but oscP5tcpClient.stop(); not working...

    CLIENT

     import oscP5.*;
     OscP5 oscP5tcpClient;
     OscMessage m;
    
     String input;
    
     void setup() {
       size(500, 500);
       oscP5tcpClient = new OscP5(this, "localhost", 29922, OscP5.TCP);
       send("HELLO");
       reconnect();
     }
    
     void draw() {
     }
    
     void mouseReleased() {
       reconnect();
     }
    
     void reconnect() {
       oscP5tcpClient.stop();
       println("STOPPED");
       oscP5tcpClient = new OscP5(this, "localhost", 29922, OscP5.TCP);
       send("HELLO");
     }
    
     void oscEvent(OscMessage theMessage) {
       input = theMessage.addrPattern();
     }
    
     void send(String message) {
       oscP5tcpClient.send(message, new Object[] {new Integer(1)});
     }
    

    SERVER

     import oscP5.*;
     import netP5.*;
     OscP5 oscP5tcpServer;
     NetAddress myServerAddress;
    
     String input;
    
     void setup() {
       oscP5tcpServer = new OscP5(this, 29922, OscP5.TCP);
     }
    
     void oscEvent(OscMessage theMessage) {
       input = theMessage.addrPattern();
       println(input);
     }
    
  • real time data program

    hey guys. in this time i need some help to optimize a system to pick shaders in real time (fragment shaders, and vertex shaders). This code is a mix that i recoleted in internet with code writing by myself.

    Theres a lot of problem and i need help:

    the idea of the program is that user can pick the shader in real time. there are two problems, first, i dont know how uploading the vertexShader, when i save it and reload it i need to click in another frag and then vertex upload.

    second, it seems very inestable.the window of shaders crash very often, specially when frame rate is lowest. I wondering how to fix that. maybe with thread(), but it dont know exactly how apply this method..

    If someone have time and wants to help, im sure that this code needs to be re writing. Thanks!

    ShaderWindow shaderWin;
    
    boolean recording = false;
    
    
    import netP5.*;
    import oscP5.*;
    
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    import themidibus.*;
    MidiBus bus;
    MidiBus apc;
    float cc [] =new float [256];
    
    
    boolean record, load;
    double folderTime;
    File folderShader;
    float desmouse = 0.5;
    
    // BUFFERS-SHADERS
    
    String dirFolderShaders;
    String dirFolderShaders2;
    String dirFolderShadersvertex;
    
    PGraphics [] buffers = new PGraphics [4];
    PGraphics buffer;
    
    LoadShader loadshader;
    
    LoadShader loadshader2;
    LoadShader loadshaderVertex;
    
    ArrayList<ViewShader>vs = new ArrayList<ViewShader>();
    ViewShaderVertex ss;
    
    PShader sh, buffer1;
    float count;
    float angle = random(0, 0.005);
    
    int choiceSize =1;
    //int ww =  1920;
    //int h = 1080;
    
    void settings() {
      if (choiceSize==0) fullScreen(P3D, 2);
      if (choiceSize==1) size(1000, 1000, P3D);
      if (choiceSize==2) size(720, 1280, P3D);
    }
    
    void setup() {
    
      // BUFFERS-SHADERS
    
      dirFolderShaders = sketchPath("frag/");  //PUT SOME FRAGMENT IN THIS FOLDER
    
      dirFolderShadersvertex = sketchPath("vertex/"); PUT SOME VERTEX IN THIS FOLDER
    
      loadshader = new LoadShader(dirFolderShaders);
    
      loadshaderVertex = new LoadShader(dirFolderShadersvertex);
    
    
      for (int i = 0; i < buffers.length; i++) {
        buffers[i] = createGraphics(width, height, P3D);
      }
    
    
      ss = new ViewShaderVertex(loadshaderVertex.shadersPaths[1], loadshaderVertex, buffer);
      vs.add(new ViewShader(loadshader.shadersPaths[0], loadshader, buffer, ss));
    
      shaderWin = new ShaderWindow();
    }
    
    void draw() {
    
      background(0);
    
    
      for (ViewShader s : vs) {
        s.update();
      }
    
    
      if (folderShader.listFiles().length != loadshader.shadersNames.length) {
        loadshaderVertex.loadFolderShader();
      }
    
      if (folderShader.listFiles().length != loadshader.shadersNames.length) {
        loadshader.loadFolderShader();
      }
    
    
    
    
      buffers[0].beginDraw();
      buffers[0].background(0);
      buffers[0].translate(width/2, height/2);
    
    
      buffers[0].sphere(100);
      buffers[0].endDraw();
    
      image(buffers[0],0,0);
    }
    
    
    
    // LOAD SHADER CLASS
    
    class LoadShader {
    
      String dirFolderShaders;
    
      String[] shadersNames;
      String[] shadersPaths;
    
      LoadShader(String _dirFolderShaders) {
        dirFolderShaders= _dirFolderShaders;
        loadFolderShader();
      }
    
      void loadFolderShader() {
        load = true;
        folderShader = new File(dirFolderShaders);
        File files[] = folderShader.listFiles();
        shadersNames = new String[files.length];
        shadersPaths = new String[files.length];
        for (int i = 0; i < files.length; i++) {
          shadersNames[i] = split(files[i].getName(), ".")[0];
          shadersPaths[i] = files[i].getAbsolutePath();
          //println(shadersNames[i]);
        }
        load = false;
      }
    }
    
    class ViewShader {
    
      boolean reload, error, loaded;
      File fileShader;
    
      long timeModi;
      long timeModis;
      String src;
    
      PShader shader;
      PShader shader1;
      PShader shader2;
      float a;
      LoadShader loadshader;
      ViewShaderVertex ss;
      PGraphics b;
    
      ViewShader(String _src, LoadShader _loadshader, PGraphics _b) {
        src = _src;
        fileShader = new File(src);
        openShader(fileShader);
        //shader1 = loadShader("blur.glsl", "bloomVert.glsl");
        //shader2 = loadShader("blur_vertical.glsl", "bloomVert.glsl");
        loadshader = _loadshader;
        b = _b;
      }
    
      ViewShader(String _src, LoadShader _loadshader, PGraphics _b, ViewShaderVertex _s) {
        ss = _s;
    
        //shader = loadShader("test2.glsl", "defaultVertex2.glsl");
        //shader1 = loadShader("blur.glsl", "bloomVert.glsl");
        //shader2 = loadShader("blur_vertical.glsl", "bloomVert.glsl");
    
        src = _src;
        fileShader = new File(src);
        openShader(fileShader);
        loadshader = _loadshader;
        b = _b;
      }
    
    
      void update() {
        if (reload) {      
          openShader(fileShader);
          reload = false;
        }
        if (shader != null) {
    
          //float p = map(cc[15], 0, 1, 0, 1);
          //float amt = map(cc[16], 0, 1, 1, 50);
          //float  h = map(cc[48], 0, 1, 0, 0.1);
          // //float  h = map(cc[14], 0, 1, 0, 0.5);
    
    
          shader.set("u_time", random(10));
    
          //shader1.set("u_time", angle);
          //shader2.set("u_time", angle);
    
          //shader.set("var2", p);
          //shader.set("amt", amt);
    
          //shader1.set("var2", p);
          //shader2.set("var2", p);
    
    
          if (fileShader.lastModified() != timeModi) {
            openShader(fileShader);
          }
        }
      }
    
    
      void newShader(String _srcc) {
        src = _srcc;
        fileShader = new File(src);
        reload = true;
        openShader(fileShader);
      }
    
      void openShader(File file) {
        if (file != null) {
          fileShader = file;
          timeModi = fileShader.lastModified();  
          try {
            shader = loadShader(file.getAbsolutePath(), ss.fileShader.getAbsolutePath());
    
            buffers[0].shader(shader);
    
    
            println(file.getAbsolutePath());
            error = false;
            loaded = true;
          }
          catch (RuntimeException e) {
            if (error == false) {
              error = true;
              // String time = nf(str(hour()),2) + ":" + nf(str(minute()),2) + ":" + nf(str(second()),2);
              println("\n");
              // println("At", time, "loadShader() returned the following error: \n");
              println("loadShader() returned the following error: \n");
              e.printStackTrace();
            }
            loaded = false;
          }
        }
      }
    }
    
    public class ShaderWindow extends PApplet {
    
      ShaderWindow() {
        super();
        PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
      }
    
      boolean mover;
    
      void settings() {
        size(600, 800, P2D);
      }
    
      void setup() {
        this.frameRate(30);
      }
    
    
      void draw() {
    
        background(25);
    
    
        for (int i = 0; i < vs.size(); i++) {
          ViewShader sss = vs.get(i);
          selector(i*100, 16, 100, width-16, sss, sss.loadshader, this);
        }
    
        ViewShaderVertex s = ss;  
        selector2(400, 16, 100, width-16, s, ss.loadshader, this);
    
      }
    
      void selector(float xx, float yy, float ww, float hh, ViewShader vs, LoadShader loadshader, PApplet p) {
        p.fill(150);
        p.noStroke();
        p.rectMode(CORNER);
    
        int cant = loadshader.shadersNames.length;
        p.rect(xx, yy+cant*16, ww, hh-cant*16);
        for (int i = 0; i < cant; i++) {
          boolean sobre = false;
          if (p.mouseX >= xx && p.mouseX < xx+ww && p.mouseY >= yy+i*16 && p.mouseY < yy+(i+1)*16) {
            sobre = true;
          }
          if (sobre) {
            p.fill(125);
          } else {
            p.fill(100, 50);
          }
          boolean selec = vs.src.equals(loadshader.shadersPaths[i]);
          if (p.mousePressed && sobre && !selec) {
            vs.newShader(loadshader.shadersPaths[i]);
          }
    
          if (selec) {
            p.fill(100);
            if (vs.error) {
              p.fill(200, 10, 10);
            }
          }
    
          p.rect(xx, yy+i*16, ww, 16);
          p.textAlign(LEFT, TOP);
          p.fill(250);
          if (i < loadshader.shadersNames.length && !load)
            text(loadshader.shadersNames[i], xx+5, yy+i*16);
        }
      }
    
      void selector2(float xx, float yy, float ww, float hh, ViewShaderVertex vs, LoadShader loadshader, PApplet p) {
        p.fill(150);
        p.noStroke();
        p.rectMode(CORNER);
    
        int cant = loadshader.shadersNames.length;
        p.rect(xx, yy+cant*16, ww, hh-cant*16);
        for (int i = 0; i < cant; i++) {
          boolean sobre = false;
          if (p.mouseX >= xx && p.mouseX < xx+ww && p.mouseY >= yy+i*16 && p.mouseY < yy+(i+1)*16) {
            sobre = true;
          }
          if (sobre) {
            p.fill(125);
          } else {
            p.fill(100, 50);
          }
          boolean selec = ss.src.equals(loadshader.shadersPaths[i]);
          if (p.mousePressed && sobre && !selec) {
            vs.newShader(loadshader.shadersPaths[i]);
          }
    
          if (selec) {
            p.fill(100);
            if (vs.error) {
              p.fill(200, 10, 10);
            }
          }
    
          p.rect(xx, yy+i*16, ww, 16);
          p.textAlign(LEFT, TOP);
          p.fill(250);
          if (i < loadshader.shadersNames.length && !load)
            p.text(loadshader.shadersNames[i], xx+5, yy+i*16);
        }
      }
    }
    
    class ViewShaderVertex {
    
      boolean reload, error, loaded;
      File fileShader;
      long timeModi;
      String src;
      String src2;
    
      PShader shader;
    
      float a;
      LoadShader loadshader;
      ViewShader ss;
    
      ViewShaderVertex(String _src, LoadShader _loadshader, PGraphics b) {
    
        src = _src;
        fileShader = new File(src);
        openShader(fileShader);
    
        loadshader = _loadshader;
      }
    
    
    
      void update() {
        if (reload) {      
          openShader(fileShader);
          reload = false;
        }
        if (shader != null) {
    
          if (fileShader.lastModified() != timeModi) {
            openShader(fileShader);
    
          }
        }
      }
    
    
      void newShader(String src) {
        this.src = src;
        fileShader = new File(src);
        reload = true;
        openShader(fileShader);
      }
    
      void openShader(File file) {
    
        if (file != null) {
          fileShader = file;
          timeModi = fileShader.lastModified();
    
          try {
                    for (ViewShader s : vs) {
              s.update();
            }
            //shader = loadShader("test.glsl", file.getAbsolutePath());
            shader.setVertexShader(file.getAbsolutePath());
            buffers[0].shader(shader);
    
            println(file.getAbsolutePath());
            error = false;
            loaded = true;
          }
          catch (RuntimeException e) {
            if (error == false) {
              error = true;
              // String time = nf(str(hour()),2) + ":" + nf(str(minute()),2) + ":" + nf(str(second()),2);
              println("\n");
              // println("At", time, "loadShader() returned the following error: \n");
              println("loadShader() returned the following error: \n");
              e.printStackTrace();
            }
            loaded = false;
          }
        }
      }
    }
    
  • How to connect processing with gh using UDP or OSC?

    looking at this: http://www.sojamo.com/libraries/oscP5/examples/oscP5parsing/oscP5parsing.pde

    that adds an int, a float and a string to the message. the message typetag ends up as "ifs", which suggests "s" is for string. you're getting "Typetag: ssss", four strings, but you appear to be trying to read that as a double.

  • How to connect processing with gh using UDP or OSC?

    @kfrajer The message shows up as a red background banner above the console. And the line is

    udps = new UDP( this, 6005 ); //sending from this port

    which is the third line in the setup{}

    Sorry I deleted the UDP section in the question cos I figured out how to receive my message via oscP5, don't want to make confusion.

    Also may I ask how to translate the java object I received into a string or string array..? cos I received

    oscEvent/GH/none[Ljava.lang.Object;@54f912f5

    this kind of thing in my console...

  • How to connect processing with gh using UDP or OSC?

    Hi there, I am trying to receive some data from grasshopper, and I firstly use OCSP5 library, which allows sending message to gh but cannot receive. And I tried UDP class, but the processing keeps saying the library cannot be used... I was wondering is there a way to get the newer version of the UDP library, or is there a way to receiving data from grasshopper?

    Thanks!

    I am really try with a simple sketch.

    import netP5.*;
    import oscP5.*;
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    float mySum;
    
    void setup()
    {
      frameRate(25);
      oscP5 = new OscP5(this,12000);
      myRemoteLocation = new NetAddress("10.10.15.157",12000);
      oscP5.addListener(myListener);
      mySum = 0;
    }
    
    void draw()
    {
      background(0);
    }
    
    /* incoming osc message are forwarded to the oscEvent method. */
    void oscEvent(OscMessage theOscMessage) {
      print ("oscEvent"+theOscMessage.addrPattern()+theOscMessage.arguments());
    }
    

    and when I send data from grasshopper, the console says NullPointerException, and print something in console like

    java.lang.NullPointerException
        at oscP5.OscP5.callMethod(Unknown Source)
        at oscP5.OscP5.process(Unknown Source)
        at oscP5.OscNetManager.process(Unknown Source)
        at netP5.AbstractUdpServer.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:748)
    

    I commented the initiation for Add listener, and it worked...sorry I've got this in console

    oscEvent/GH/none[Ljava.lang.Object;@54f912f5

    Thanks for your time!

    ==============================

    update Now my new sketch, what troubles me now is that I don't want the java object, but a list of doubles. But I got Error in console

    code:

    import netP5.*;
    import oscP5.*;
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    OscMessage arrayMsg = new OscMessage("/array");
    
    void setup()
    {
      frameRate(25);
      oscP5 = new OscP5(this,12000);
      myRemoteLocation = new NetAddress("10.10.15.157",12000);
    }
    
    void draw()
    {
      background(0);
    }
    
    void oscEvent(OscMessage theOscMessage) {
      println("Address pattern: "+theOscMessage.addrPattern());
      println ("Typetag: "+theOscMessage.typetag());
      println ("Arguments: "+theOscMessage.get(0).doubleValue());
    }
    

    and the console prints

    Address pattern: /test01
    Typetag: ssss
    ### [2018/5/31 15:22:4] ERROR @ OscP5 ERROR. an error occured while forwarding an OscMessage
     to a method in your program. please check your code for any 
    possible errors that might occur in the method where incoming
     OscMessages are parsed e.g. check for casting errors, possible
     nullpointers, array overflows ... .
    method in charge : oscEvent  java.lang.reflect.InvocationTargetException
    
  • Send/Recieve files

    i want to send the OktoberfestVSGermanElections.csv file, when i push the button(Message).This is my code bellow:

        import ketai.net.*;
        import ketai.net.bluetooth.*;
        import ketai.net.nfc.*;
        import ketai.net.nfc.record.*;
        import ketai.net.wifidirect.*;
        import ketai.sensors.*;
        import ketai.ui.*;
    
        import oscP5.*;
        import netP5.*;
        import grafica.*;
    
    
        OscP5 oscP5;
        NetAddress remoteLocation;
    
        double longitude, latitude, altitude;
        KetaiLocation location;
    
        Button on_button;  // the button
        int clk = 1;  
    
    
        String[] monthNames = new String[] {"January", "February", "March", "April", "May", "June", "July", 
                                             "August", "September", "October", "November", "December"};
        int[] daysPerMonth = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[] daysPerMonthLeapYear = new int[] {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
        GPlot plot;
    
        void setup() {
          fullScreen();
          //size(800, 410);
          orientation(LANDSCAPE);
          textAlign(CENTER, CENTER);
        textSize(22);
    
         location = new KetaiLocation(this);
    
        oscP5 = new OscP5(this,19000);
           on_button = new Button("Message", 850, 360, 150, 100);
        remoteLocation = new NetAddress("192.168.1.2",19000);
    
          // Load the Oktoberfest vs. Bundestagswahl (German elections day) Google 
          // search history file (obtained from the Google trends page). 
          // The csv file has the following format: 
          // year,month,day,oktoberfest,bundestagswahl
          // 2004,0,1,5,1
          // ...
          Table table = loadTable("OktoberfestVSGermanElections.csv", "header");
          table.setColumnType("year", Table.INT);
          table.setColumnType("month", Table.INT);
          table.setColumnType("day", Table.INT);
          table.setColumnType("oktoberfest", Table.INT);
          table.setColumnType("bundestagswahl", Table.INT);
    
          // Save the data in two GPointsArrays
          GPointsArray pointsOktoberfest = new GPointsArray();
          GPointsArray pointsElections = new GPointsArray();
    
          for (int row = 0; row < table.getRowCount(); row++) {
            int year = table.getInt(row, "year");
            int month = table.getInt(row, "month");
            int day = table.getInt(row, "day");
            float date = getExactDate(year, month, day);
            int oktoberfestCount = table.getInt(row, "oktoberfest");
            int electionsCount = table.getInt(row, "bundestagswahl");
    
            pointsOktoberfest.add(date, oktoberfestCount, monthNames[month]);
            pointsElections.add(date, electionsCount, monthNames[month]);
          }
    
          // Create the plot
          plot = new GPlot(this);
          plot.setDim(700, 300);
          plot.setTitleText("Oktoberfest vs. Bundestagwahl Google search history");
          plot.getXAxis().setAxisLabelText("Year");
          plot.getYAxis().setAxisLabelText("Google normalized searches");
          plot.getXAxis().setNTicks(10);
          plot.setPoints(pointsOktoberfest);
          plot.setLineColor(color(100, 100, 100));
          plot.addLayer("German elections day", pointsElections);
          plot.getLayer("German elections day").setLineColor(color(255, 100, 255));
          plot.activatePointLabels();
        }
    
        void draw() {
          background(255);
          on_button.Draw();
          if (location.getProvider() == "none")
            text("Location data is unavailable. \n" +
              "Please check your location settings.", -100,100, width, height);
          else
            text("Latitude: " + latitude + "\n" + 
              "Longitude: " + longitude + "\n" + 
              "Altitude: " + altitude + "\n" + 
              "Provider: " + location.getProvider(),  -100, 100, width, height);  
    
          // Draw the plot  
          plot.beginDraw();
          plot.drawBox();
          plot.drawXAxis();
          plot.drawYAxis();
          plot.drawTitle();
          plot.drawGridLines(GPlot.VERTICAL);
          plot.drawFilledContours(GPlot.HORIZONTAL, 0);
          plot.drawLegend(new String[] {"Oktoberfest", "Bundestagswahl"}, new float[] {0.07, 0.22}, 
                          new float[] {0.92, 0.92});
          plot.drawLabels();
          plot.endDraw();
        }  
    
    
        // Not really the exact date, but it's ok for this example
        float getExactDate(int year, int month, int day) {
          boolean leapYear = false;
    
          if (year % 400 == 0) {
            leapYear = true;
          }
          else if (year % 100 == 0) {
            leapYear = false;
          }
          else if (year % 4 == 0) {
            leapYear = true;
          }
    
          if (leapYear) {
            return year + (month + (day - 1f)/daysPerMonthLeapYear[month])/12f;
          }
          else {
            return year + (month + (day - 1f)/daysPerMonth[month])/12f;
          }
        }
    
        void mousePressed() {
          if (on_button.MouseIsOver()) {
          /* in the following different ways of creating osc messages are shown by example */
          OscMessage myMessage = new OscMessage("The Data are bellow:" +"\n" +
                       "Latitude: " + latitude + "\n" + 
              "Longitude: " + longitude + "\n" + 
              "Altitude: " + altitude);
    
          //myMessage.add(123); /* add an int to the osc message */
    
          /* send the message */
          oscP5.send(myMessage, remoteLocation); 
          }
        }
    
    
        void oscEvent(OscMessage theOscMessage) {
          /* print the address pattern and the typetag of the received OscMessage */
          print("### received an osc message.");
          print("Hello: "+theOscMessage.addrPattern());
         // println(" typetag: "+theOscMessage.typetag());
    
        }
        void onLocationEvent(double _latitude, double _longitude, double _altitude)
        {
          longitude = _longitude;
          latitude = _latitude;
          altitude = _altitude;
          println("lat/lon/alt: " + latitude + "/" + longitude + "/" + altitude);
        }
    
        class Button {
          String label; // button label
          float x;      // top left corner x position
          float y;      // top left corner y position
          float w;      // width of button
          float h;      // height of button
    
          // constructor
          Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
            label = labelB;
            x = xpos;
            y = ypos;
            w = widthB;
            h = heightB;
          }
    
          void Draw() {
            fill(150);
            stroke(141);
            rect(x, y, w, h, 10);
            textAlign(CENTER, CENTER);
            fill(0);
            text(label, x + (w / 2), y + (h / 2));
          }
    
          boolean MouseIsOver() {
            if (mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) {
              return true;
            }
            return false;
          }
        }
    
  • Send/Recieve files

    Hello, i would like to know if there is a way in processing i3 to send and recieve data files. as csv files between android phone and pc through Wi-Fi..Actually i tried to communicate them with oscP5 library and i can send/recieve messages..But what about csv files???

  • Unable to use substring() function within an array. (Parsing irishrail)

    Thanks kfrajer :) I'm sending OSC to Max.

    I have used OSC with processing and max in the past. In case there were any crossed wires, my OSC setup was working fine, until I tried to set it up within it's own function, as you suggested.

    I think I have an idea why only the first index of 'onTimeStatus' could be accessed outside of the requestData() function. I think the index values of 'onTimeStatus' needed to be stored in an array to enable them to be used outside of that function?

    I am pretty sure this is not elegant coding, and you are probably going to vomit when you see this :-& .... but, after some hours this the only method that has allowed me to both draw those rectangles and send OSC messages using a discrete OSC function (line 95) that is called each time the timer counts down from within requestData() (line 82).

    I am using a intArray list on line 17 to store the myTrainStatus values. Even though I'm inexperienced, I can tell that this is not the best way. But it works, for now. It is messy that I am having to use myStatuses = statuses.get(i); in two places; line 55 and 98.

    import de.fhpotsdam.unfolding.*;
    import de.fhpotsdam.unfolding.geo.*;
    import de.fhpotsdam.unfolding.utils.*;
    import de.fhpotsdam.unfolding.marker.*;
    UnfoldingMap map;
    SimplePointMarker trainMarker;
    Location irelandLoc;
    
    import oscP5.*;
    import netP5.*;
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    //String url = "http://" + "api.irishrail.ie/realtime/realtime.asmx/getCurrentTrainsXML";
    XML xml; 
    XML[] children;
    
    IntList statuses;
    int onTimeStatus;
    int myStatuses;
    
    Timer timer = new Timer(5000);
    
    
    //________________________________________________________________________________________________________________________________ 
    void setup() {
      size(800, 800, P2D);
      map = new UnfoldingMap(this);
      MapUtils.createDefaultEventDispatcher(this, map);
      irelandLoc = new Location(53.098, -7.910);   
      map.zoomAndPanTo(irelandLoc, 7);
    
      oscP5 = new OscP5(this, 236);
      myRemoteLocation = new NetAddress("127.0.0.1", 10000);
    
      requestData();
      timer.start();
    } 
    
    
    //________________________________________________________________________________________________________________________________ 
    void draw() {
      map.draw();
    
      if (timer.isFinished()) {   // Every one second, make a new request.
        println("Timer is finished: Requesting values and restarting");   
        requestData();
        timer.start();  // And restart the timer. 
      }
    
      for (int i = 0; i < children.length; i++) {   
        myStatuses = statuses.get(i);
        drawRects(i);
      }
    
    }
    
    
    //________________________________________________________________________________________________________________________________ 
    void requestData() {   
      xml = loadXML("xml.xml");   
      children = xml.getChildren("objTrainPositions");   
      statuses = new IntList();
    
    
      for (int i = 0; i < children.length; i++) {    
        XML announcementElement = children[i].getChild("PublicMessage");
        String announcement = announcementElement.getContent();
        int start = announcement.indexOf("(" ) + 1; // STEP 1 
        int end = announcement.indexOf(" mins", start); // STEP 2
        if(start >= 0 && end >= start){ 
          String status = announcement.substring(start, end); // STEP 3 error thrown at this point 
          onTimeStatus = int(status);
        } else {
          onTimeStatus = 999;  // My personal Error Code
        }
        statuses.append(onTimeStatus);                         
      }   
      sendOSC();
    } 
    
    
    //________________________________________________________________________________________________________________________________
    void drawRects(float i) {  
      stroke(0);
      fill(0,255,0);
      rect(0+(i*width/children.length), height/2+children.length, width/children.length, myStatuses*50);
    }
    
    
    //________________________________________________________________________________________________________________________________
    void sendOSC(){  
      OscMessage myMessage = new OscMessage("/status");  
      for (int i=0; i< children.length; i++) {
        myStatuses = statuses.get(i);
        myMessage.add(myStatuses);
        println(myStatuses);
      }
      oscP5.send(myMessage, myRemoteLocation);     
    }
    
    
    
    //________________________________________________________________________________________________________________________________
    class Timer {
      int savedTime;
      boolean running = false;
      int totalTime;
    
      Timer(int tempTotalTime) {
        totalTime = tempTotalTime;
      }
    
      void start() {
        running = true;
        savedTime = millis();
      }
    
      boolean isFinished() {
        int passedTime = millis() - savedTime;
        if (running && passedTime > totalTime) {
          running = false;
          return true;
        } else {
          return false;
        }
      }
    }
    
  • Unable to use substring() function within an array. (Parsing irishrail)

    Ok, so I think my code above needs to be changed. IsFinished() should be:

    boolean isFinished() {
        if (running) {
          int passedTime = millis() - savedTime;
          running=(passedTime < totalTime);
          return !running;
        } else
          return true;
      }
    

    Right now your code doesn't work as the bus system must be down. This is not going to solve your problem: You need to choose another port number. Usually lower numbers are ports reserved for the system. You should use instead numbers above 5000 or 10000 as the chances they are taken is very low.

    To test the oscP5, I use this modified version of the example provided here: http://www.sojamo.de/libraries/oscP5/examples/oscP5sendReceive/oscP5sendReceive.pde

    You will see that I have attached 10 numbers and I can retrieve them in the other end. See the documentation for proper function calls. In your case:

    1. You need to make sure you are attaching all the values. As I said, ensure you have attached those values. at least during debugging sessions.
    2. What code is reading your osc message? Is this also another Processing program?

    Kf

    /**
     * oscP5sendreceive by andreas schlegel
     * example shows how to send and receive osc messages.
     * oscP5 website at http://www.sojamo.de/oscP5
     */
    
    import oscP5.*;
    import netP5.*;
    
    
    final int N=10;
    
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    void setup() {
      size(400, 400);
      frameRate(25);
      /** start oscP5, listening for incoming messages at port 12000 */
      oscP5 = new OscP5(this, 12000);
    
      /** myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
       * an ip address and a port number. myRemoteLocation is used as parameter in
       * oscP5.send() when sending osc packets to another computer, device, 
       * application. usage see below. for testing purposes the listening port
       * and the port of the remote location address are the same, hence you will
       * send messages back to this sketch.
       */
      myRemoteLocation = new NetAddress("127.0.0.1", 12000);
    }
    
    
    void draw() {
      background(0);
    }
    
    
    void mousePressed() {
      /** in the following different ways of creating osc messages are shown by example */
      OscMessage myMessage = new OscMessage("/test");
    
      for (int i=0; i<N; i++)
        myMessage.add(123+i); /* add an int to the osc message */
    
    
      /** send the message */
      oscP5.send(myMessage, myRemoteLocation);
    }
    
    
    /* incoming osc message are forwarded to the oscEvent method. */
    void oscEvent(OscMessage theOscMessage) {
      /* print the address pattern and the typetag of the received OscMessage */
      print("### received an osc message.");
      print(" addrpattern: "+theOscMessage.addrPattern());
      println(" typetag: "+theOscMessage.typetag());
    
      println(theOscMessage);
      println("____________________");
      println(theOscMessage.getBytes());
    }
    
  • Unable to use substring() function within an array. (Parsing irishrail)

    Regarding the bad explanation of OSC messages iteration, Sorry. To simplify, what I meant by:

    Also, with the OSC as a separate function (void sendOSC(){ on line 105) and call it within the timer finished condition in draw(). It does not seem to iterate through the OSC messages.

    I will just take 'latitude' as an example..

    I rewrote some code to simplify. I don't understand why only the value of the first index of 'latitude' is being sent for all indices (line 19), when all discrete indices print out fine in the line before it. I hope this made sense.

    void requestData() {   
      xml = loadXML(url);   
      children = xml.getChildren("objTrainPositions");   
    
      for (int i = 0; i < children.length; i++) {    
        XML latitudeElement = children[i].getChild("TrainLatitude");
        latitude = latitudeElement.getFloatContent();       
        sendOSC(latitude);                                 
      } 
    } 
    
    
    void sendOSC(float messageToBeSent){
      OscMessage myMessage = new OscMessage("/latitude");  
      for (int i=0; i< children.length; i++) {  
        myMessage.add(messageToBeSent);
      }
      println(messageToBeSent);                    //*** if latitude prints for all indexes correctly at this point...
      oscP5.send(myMessage, myRemoteLocation);     //.. why does it not transmit OSC messages the same way here? ***
    }
    
  • Unable to use substring() function within an array. (Parsing irishrail)

    This does not address all the questions. Check the code below where I have made some subtle changes all over the place.

    Also, with the OSC as a separate function (void sendOSC(){ on line 105) and call it within the timer finished condition in draw(). It does not seem to iterate through the OSC messages.

    Not clear what you mean. Where is this iteration taking place?

    One additional note. When managing your data, you need to make sure you have valid data. Just because you call a function and you are expecting certain result doesn't mean your returned value has those values. The proper way to do this is to manage your returns. If your return has data, process it. Otherwise, skip or even better, provide an error or warning msg.

    Kf

    import de.fhpotsdam.unfolding.*;
    import de.fhpotsdam.unfolding.geo.*;
    import de.fhpotsdam.unfolding.utils.*;
    import de.fhpotsdam.unfolding.marker.*;
    UnfoldingMap map;
    SimplePointMarker trainMarker;
    
    import oscP5.*;
    import netP5.*;
    
    final int ERROR_REQ=-1;
    
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    String url = "http://" + "api.irishrail.ie/realtime/realtime.asmx/getCurrentTrainsXML";
    XML xml; 
    XML[] children;
    
    Location irelandLoc;
    
    Timer timer = new Timer(5000);
    int onTimeStatus;
    
    
    //________________________________________________________________________________________________________________________________ 
    void setup() {
      size(800, 800, P2D);
      map = new UnfoldingMap(this);
      MapUtils.createDefaultEventDispatcher(this, map);
      irelandLoc = new Location(53.098, -7.910);   
      map.zoomAndPanTo(irelandLoc, 7);
    
      oscP5 = new OscP5(this, 236);
      myRemoteLocation = new NetAddress("127.0.0.1", 12345);
    
      requestData();
      timer.start();
    } 
    
    
    //________________________________________________________________________________________________________________________________ 
    void draw() {
      map.draw();
    
      if (timer.isFinished()) {   // Every one second, make a new request.
        println("Timer is finished: Requesting values and restarting");
    
        if (requestData() != ERROR_REQ)
          sendOSC();
    
        timer.start();  // And restart the timer.
      }
      drawRects();
    }
    
    //________________________________________________________________________________________________________________________________ 
    void drawRects() {
    
      if (children==null)
        return;
    
      for (int i = 0; i < children.length; i++) {     
        stroke(0);
        fill(0, 255, 0);
        rect(0+(i*width/children.length), height/2+children.length, width/children.length, onTimeStatus);
      }
    }
    
    //________________________________________________________________________________________________________________________________
    int requestData() {   
      xml = loadXML(url);    // Load the XML feed from URL
      children = xml.getChildren("objTrainPositions");    // Get all the child nodes named "objTrainPositions" 
    
      if (children==null)
        return ERROR_REQ;
    
      for (int i = 0; i < children.length; i++) {   
        XML announcementElement = children[i].getChild("PublicMessage");
        String announcement = announcementElement.getContent();
        int start = announcement.indexOf("(" ) + 1; // STEP 1 
        int end = announcement.indexOf(" mins", start); // STEP 2
        if (start >= 0 && end >= start) { 
          String status = announcement.substring(start, end); // STEP 3 error thrown at this point 
          onTimeStatus = int(status);
        } else {
          onTimeStatus = 0;  // My personal Error Code
        }
    
        XML trainCodeElement = children[i].getChild("TrainCode");
        String trainCode = trainCodeElement.getContent(); 
    
        XML latitudeElement = children[i].getChild("TrainLatitude");
        float latitude = latitudeElement.getFloatContent();   
    
        XML longitudeElement = children[i].getChild("TrainLongitude");
        float longitude = longitudeElement.getFloatContent();  
    
        Location location = new Location(latitude, longitude); 
    
        trainMarker = new SimplePointMarker(location);
        trainMarker.setStrokeWeight(3);
        trainMarker.setStrokeColor(0);
        trainMarker.setRadius(5 + onTimeStatus);
        trainMarker.setColor(color(255, 0, 0));
    
        map.addMarker(trainMarker);    
    
        println("Train Code: " + trainCode + ", Latitude: " + latitude + ", Longitude: " + longitude + ", Status: " + onTimeStatus);
      } 
      return onTimeStatus;  //
    } 
    
    
    //________________________________________________________________________________________________________________________________
    void sendOSC() {
      OscMessage myMessage = new OscMessage("/onTimeStatus");   
      for (int i=0; i< children.length; i++) {  
        //myMessage.add(children[i].onTimeStatus);  // Does not work
        myMessage.add(onTimeStatus);
      }
      oscP5.send(myMessage, myRemoteLocation);   /* send the message */
    }
    
    
    //________________________________________________________________________________________________________________________________
    
    class Timer {
      int savedTime;
      boolean running;
      int totalTime;
    
      Timer(int tempTotalTime) {
        totalTime = tempTotalTime;
        running = false;  
      }
    
      void start() {
        running = true;
        savedTime = millis();
      }
    
      boolean isFinished() {  //  *** This functions needs to be revised. See post below
        if(running){
          int passedTime = millis() - savedTime;
          return running=passedTime > totalTime;
        }
        else
        return false;    
      }
    }
    
  • Unable to use substring() function within an array. (Parsing irishrail)

    Really, no need to thank me :-/ You're the one helping me out ;)

    I wasn't sure where to put if(trainMarker!=null){ ... }, so I put it in line 26 before it requests data. The train positions still don't seem to print until the timer counts down.

    Also, with the OSC as a separate function (void sendOSC(){ on line 105) and call it within the timer finished condition in draw(). It does not seem to iterate through the OSC messages.

    Basically, the overall visual end goal is to draw various vertical rectangles to the screen based on the late/early status of each train. For this I need to access the global variable 'onTimeStatus' (line 21). I cannot seem to access it in draw. I have also tried getting the requestData() (line 61) function to return an integer and retrieve it this way to no avail. Is there something basic I'm missing here?

    I have left everything visible in the code below. It runs but behaves according to the above info. Thanks again.

    import de.fhpotsdam.unfolding.*;
    import de.fhpotsdam.unfolding.geo.*;
    import de.fhpotsdam.unfolding.utils.*;
    import de.fhpotsdam.unfolding.marker.*;
    UnfoldingMap map;
    SimplePointMarker trainMarker;
    
    import oscP5.*;
    import netP5.*;
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    String url = "http://" + "api.irishrail.ie/realtime/realtime.asmx/getCurrentTrainsXML";
    XML xml; 
    XML[] children;
    
    Location irelandLoc;
    
    Timer timer = new Timer(5000);
    
    int onTimeStatus;
    
    
    //________________________________________________________________________________________________________________________________ 
    void setup() {
      if(trainMarker!=null){  
        requestData();
      }
      timer.start();
      size(800, 800, P2D);
      map = new UnfoldingMap(this);
      MapUtils.createDefaultEventDispatcher(this, map);
      irelandLoc = new Location(53.098, -7.910);   
      map.zoomAndPanTo(irelandLoc, 7);
    
      oscP5 = new OscP5(this, 236);
      myRemoteLocation = new NetAddress("127.0.0.1", 12345);    
    } 
    
    
    //________________________________________________________________________________________________________________________________ 
    void draw() {
      map.draw();
    
      if (timer.isFinished()) {   // Every one second, make a new request.
        println("Timer is finished: Requesting values and restarting");
        requestData();
        sendOSC();
        timer.start();  // And restart the timer. 
      }
    
      //for (int i = 0; i < children.length; i++) {     
      //  stroke(0);
      //  fill(0,255,0);
      //  rect(0+(i*width/children.length), height/2+children.length, width/children.length, onTimeStatus);
      //}  
    }
    
    
    //________________________________________________________________________________________________________________________________
    int requestData() {   
      xml = loadXML(url);    // Load the XML feed from URL
      children = xml.getChildren("objTrainPositions");    // Get all the child nodes named "objTrainPositions" 
    
      for (int i = 0; i < children.length; i++) {   
        XML announcementElement = children[i].getChild("PublicMessage");
        String announcement = announcementElement.getContent();
        int start = announcement.indexOf("(" ) + 1; // STEP 1 
        int end = announcement.indexOf(" mins", start); // STEP 2
        if(start >= 0 && end >= start){ 
          String status = announcement.substring(start, end); // STEP 3 error thrown at this point 
          onTimeStatus = int(status);
        } else {
          onTimeStatus = 0;  // My personal Error Code
        }
    
        XML trainCodeElement = children[i].getChild("TrainCode");
        String trainCode = trainCodeElement.getContent(); 
    
        XML latitudeElement = children[i].getChild("TrainLatitude");
        float latitude = latitudeElement.getFloatContent();   
    
        XML longitudeElement = children[i].getChild("TrainLongitude");
        float longitude = longitudeElement.getFloatContent();  
    
        Location location = new Location(latitude, longitude); 
    
        trainMarker = new SimplePointMarker(location);
        trainMarker.setStrokeWeight(3);
        trainMarker.setStrokeColor(0);
        trainMarker.setRadius(5 + onTimeStatus);
        trainMarker.setColor(color(255,0,0));
    
        map.addMarker(trainMarker);    
    
        println("Train Code: " + trainCode + ", Latitude: " + latitude + ", Longitude: " + longitude + ", Status: " + onTimeStatus);  
      } 
      return onTimeStatus;  //
    } 
    
    
    //________________________________________________________________________________________________________________________________
    void sendOSC(){
      OscMessage myMessage = new OscMessage("/onTimeStatus");   
      for (int i=0; i< children.length; i++) {  
        //myMessage.add(children[i].onTimeStatus);  // Does not work
        myMessage.add(onTimeStatus);
      }
      oscP5.send(myMessage, myRemoteLocation);   /* send the message */ 
    }
    
    
    //________________________________________________________________________________________________________________________________
    
    class Timer {
      int savedTime;
      boolean running = false;
      int totalTime;
    
      Timer(int tempTotalTime) {
        totalTime = tempTotalTime;
      }
    
      void start() {
        running = true;
        savedTime = millis();
      }
    
      boolean isFinished() {
        int passedTime = millis() - savedTime;
        if (running && passedTime > totalTime) {
          running = false;
          return true;
        } else {
          return false;
        }
      }
    }
    
  • Unable to use substring() function within an array. (Parsing irishrail)

    Yup, already dong things. Drawn the train positions to a map to update when the XML feed updates and sending some messages over OSC to max for some complimentary sonification :)

    import de.fhpotsdam.unfolding.*;
    import de.fhpotsdam.unfolding.geo.*;
    import de.fhpotsdam.unfolding.utils.*;
    import de.fhpotsdam.unfolding.marker.*;
    
    import oscP5.*;
    import netP5.*;
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    UnfoldingMap map;
    XML xml;   
    Location irelandLoc;
    
    Timer timer = new Timer(1000);
    
    int onTimeStatus;
    
    
    
    void setup() {
      xml = loadXML("http://" + "api.irishrail.ie/realtime/realtime.asmx/getCurrentTrainsXML");    // Load the XML feed from URL  
      size(800, 600, P2D);
      map = new UnfoldingMap(this);
      MapUtils.createDefaultEventDispatcher(this, map);
      irelandLoc = new Location(53.098, -7.910);   
      map.zoomAndPanTo(irelandLoc, 7);
    
      oscP5 = new OscP5(this, 236);
      myRemoteLocation = new NetAddress("127.0.0.1", 12345);   
    } 
    
    
    
    void requestData() {   
      OscMessage myMessage = new OscMessage("/onTimeStatus");  
      XML[]   children = xml.getChildren("objTrainPositions");    // Get all the child nodes named "objTrainPositions" 
      for (int i = 0; i < children.length; i++) {     
        XML announcementElement = children[i].getChild("PublicMessage");
        String announcement = announcementElement.getContent();
        int start = announcement.indexOf("(" ) + 1; // STEP 1 
        int end = announcement.indexOf(" mins", start); // STEP 2
        if(start >= 0 && end >= start){ 
          String status = announcement.substring(start, end); // STEP 3 error thrown at this point 
          onTimeStatus = int(status);
        } else {
          onTimeStatus = 666;  // My personal Error Code
        }
        myMessage.add(onTimeStatus);  
    
    
        XML trainCodeElement = children[i].getChild("TrainCode");
        String trainCode = trainCodeElement.getContent(); 
    
        XML latitudeElement = children[i].getChild("TrainLatitude");
        float latitude = latitudeElement.getFloatContent();   
    
        XML longitudeElement = children[i].getChild("TrainLongitude");
        float longitude = longitudeElement.getFloatContent();  
    
        Location location = new Location(latitude, longitude);
        map.addMarker(new SimplePointMarker(location));  // Create Unfolding Marker here
    
        println("Train Code: " + trainCode + ", Latitude: " + latitude + ", Longitude: " + longitude + ", Status: " + onTimeStatus);       
      }
      oscP5.send(myMessage, myRemoteLocation);   /* send the message */  
    } 
    
    
    void draw() {
      map.draw();
    
      if (timer.isFinished()) {   // Every one second, make a new request.
        requestData();
        timer.start();  // And restart the timer.
      }
      thread("requestData");  
    }
    
    
    class Timer {
      int savedTime;
      boolean running = false;
      int totalTime;
    
      Timer(int tempTotalTime) {
        totalTime = tempTotalTime;
      }
    
      void start() {
        running = true;
        savedTime = millis();
      }
    
      boolean isFinished() {
        int passedTime = millis() - savedTime;
        if (running && passedTime > totalTime) {
          running = false;
          return true;
        } else {
          return false;
        }
      }
    }
    
  • Pitch, Roll, Yaw using rotateX/Y/Z query

    I am trying to represent the orientation of my phone being held upright. I'm using a simple rectangle for starters. I am sending messages over OSC. Each of my 3 values; pitch, roll and yaw (Azimuth) goes from -180degrees to +180degrees.

    I am going by the example in the picture below my code, where X is pitch and Y is roll:

    When I use just two values, (eg just pitch and roll) the orientation seems to be represented normally. But when I throw the third into the mix, it gets a little wild.

    I don't have another device right now to check if it's the phone sensors that are faulty. Looking at the rotateX(and Y and Z) examples, this should work as is. I guess there's something a bit deeper I'm missing?

    Thanks

    import oscP5.*;
    import netP5.*;
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    float ZyawValue, XpitchValue, YrollValue;
    
    
    void setup() {
      size(360, 360, P3D);
      lights();
      noStroke();
      colorMode(RGB, 256); 
    
      oscP5 = new OscP5(this,34567);
      myRemoteLocation = new NetAddress("192.168.1.7",34567);
    }
    
    
    void draw() {
      background(100);
      rectMode(CENTER);
      fill(51);
      stroke(255);
    
      pushMatrix();
      translate(width/2, height/2, 0);
    
        rotateX(radians(XpitchValue));
        rotateY(radians(-YrollValue));
        rotateZ(radians(ZyawValue));     // **Issues**
    
      rect(0, 0, 50, 100);
      popMatrix();
    
      textSize(24);
      String gyrStr1 = "X=Roll: " + (int) YrollValue; 
      String gyrStr2 = "Y=Pitch: " + (int) XpitchValue; 
      String gyrStr3 = "Z=Yaw: " + (int) ZyawValue; 
      fill(249, 250, 50);
      text(gyrStr1, (int) (width/6.0) - 40, 50); 
      text(gyrStr2, (int) (width/6.0) - 40, 100); 
      text(gyrStr3, (int) (width/6.0) - 40, 150);   
    }
    
    
    
    void oscEvent(OscMessage theOscMessage) {
    
      if(theOscMessage.checkAddrPattern("/orientation/azimuth")==true) { 
        if(theOscMessage.checkTypetag("f")) {
          ZyawValue = theOscMessage.get(0).floatValue();  
          return;
        }  
      }
    
      if(theOscMessage.checkAddrPattern("/orientation/pitch")==true) { 
        if(theOscMessage.checkTypetag("f")) 
        {
          XpitchValue = theOscMessage.get(0).floatValue();  
          return;
        }  
      } 
    
      if(theOscMessage.checkAddrPattern("/orientation/roll")==true) { 
        if(theOscMessage.checkTypetag("f")) {
          YrollValue = theOscMessage.get(0).floatValue();
          return;
        }  
      }   
      println("Azimuth: "+ZyawValue+", Pitch: "+XpitchValue+", Roll: "+YrollValue);
    }
    

    Screen Shot 2018-03-30 at 21.45.50

  • My sketch runs slow when outputting the OSC to Max, im using kinect RGB and Depth cam

    Im attempting to build a system for hand tracking using the depth camera and color tracking, and output the values to MaxMsp where I can use them for audio mappings for a college project. The sketch runs fine when I comment out my OSC send code but when sending the OSC, the rgb and depth stop, changing frame every thirty seconds or so.

    //kinect
    import org.openkinect.freenect.*;
    import org.openkinect.freenect2.*;
    import org.openkinect.processing.*;
    import org.openkinect.tests.*;
    //osc
    import oscP5.*;
    import netP5.*;
    
    
    Kinect kinect;
    OscP5 oscP5;
    NetAddress myRemoteLocation;
    
    PImage cam; 
    
    //Color
    color trackColor;
    color trackColor2;
    float threshold = 150;
    
    void setup() {
      size(640, 480, P2D);
      kinect = new Kinect(this);
      kinect.initVideo();
      kinect.initDepth();
      background(255);
    
      //Color
      trackColor = color(255, 0, 0);
      trackColor2 = color(0, 255, 0);
    
      //osc
      myRemoteLocation = new NetAddress("127.0.0.1", 8000);
      oscP5 = new OscP5(this, 8000);
    }
    
    
    
    void draw() {
      image(kinect.getVideoImage(), 0, 0);
      PImage cam = kinect.getVideoImage();
      int[] depth = kinect.getRawDepth();
    
    
    
    
      float avgX1 = 0;
      float avgY1 = 0;
      float avgX2 = 0;
      float avgY2 = 0;
    
      int count1 = 0;
      int count2 = 0;
    
    
      for (int x = 0; x < kinect.width; x++ ) {
        for (int y = 0; y < kinect.height; y++ ) {
          int loc = x + y * kinect.width;
          // What is current color
          color currentColor = cam.pixels[loc];
          float rc = red(currentColor);
          float gc = green(currentColor);
          float bc = blue(currentColor);
    
          float r2 = red(trackColor);
          float g2 = green(trackColor);
          float b2 = blue(trackColor);
    
          float r3 = red(trackColor2);
          float g3 = green(trackColor2);
          float b3 = blue(trackColor2);
    
          float d = distSq(rc, gc, bc, r2, g2, b2);
          float e = distSq(rc, gc, bc, r3, g3, b3);
    
          if (d < threshold*threshold) {
            stroke(255);
            strokeWeight(1);
            point(x, y);
            avgX1 += x;
            avgY1 += y;
            count1++;
          }
          else if (e < threshold*threshold) {
            stroke(255);
            strokeWeight(1);
            point(x, y);
            avgX2 += x;
            avgY2 += y;
            count2++;
          }
    
        }
      }
    
    
    
    
      if (count1 > 0) { 
        avgX1 = avgX1 / count1;
        avgY1 = avgY1 / count1;
    
        fill(255, 0, 0);
        strokeWeight(4.0);
        stroke(0);
        ellipse(avgX1, avgY1, 24, 24);
      }
       if (count2 > 0) { 
        avgX2 = avgX2 / count2;
        avgY2 = avgY2 / count2;
    
        //green
        fill(0, 255, 0);
        strokeWeight(4.0);
        stroke(0);
        ellipse(avgX2, avgY2, 24, 24);
      }
    
    
      //DEPTH
        for (int x = 0; x < 640; x++) {
        for (int y = 0; y < 480; y++) {
          int offset = x + y * kinect.width;
          int dpth = depth[offset];
    
          if (!(dpth > 300 && dpth < 700)) {        
            cam.pixels[offset] = color(0);
          } else if (dpth > 300 && dpth < 700) {
          /*
            //OSC LEFT
            OscMessage leftXpos = new OscMessage("/leftXpos");
            OscMessage leftYpos = new OscMessage("/leftYpos");
    
            leftXpos.add(avgX1);
            leftYpos.add(avgY1);
    
            //OSC RIGHT
            OscMessage rightXpos = new OscMessage("/rightXpos");
            OscMessage rightYpos = new OscMessage("/rightYpos");
    
            rightXpos.add(avgX2);
            rightYpos.add(avgY2);
    
            oscP5.send(leftXpos, myRemoteLocation);
            oscP5.send(leftYpos, myRemoteLocation);
    
            oscP5.send(rightXpos, myRemoteLocation);
            oscP5.send(rightYpos, myRemoteLocation);
           */
          }
    
        }
      }
    
    
    
    }
    
    float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
      float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
      return d;
    }  
    
  • receiving OSC stems

    hello Everybody, I have been using Processing for just 3 months but I am loving it. I have a question about the OSCP5 library. so I am using Processing to create graphics for sounds generated in Kyma. Receiving single messages is smooth and work properly. But I dont understand if there is an efficient way to handle stems of messages coming from Kyma. so, for example if Kyma is sending: /position1 /position2 /position3 ..../position20 messages, is there a way to deal with them in Processing without creating 20 variables and 20 OSC functions? it would be great to put them all directly in an array. thanks for help. peace. d

  • Android and PC communication

    Hello, i am making an app and i would like to add a button whose function will be sending a message from the app of an android device to a PC. I tried to use oscP5 and netP5 libraries and examples but the messages was only in the Processing's i3 plattform..Is there a way to send a message to PC through WiFi and IP adresses without the programm( processing i3) after programming?

  • oscP5 without wifi between PC and Phone

    Hi, The title says more or less all : is there a way to use oscP5 to send data from an android phone (no sim card inside...) and a pc without internet connection/wifi/wire? Thanks for your help! A.

  • Ketai bluetooth to PC

    Hi, thanks for your answer. The thing is oscP5 is...osc...I really would prefer use bluetooth (actually I heard you can send osc over BT, do you know more about this?) : I'm devellopping a device for a place where there is not wifi everywhere, and, I know you can make a hotspot with your phone, but the final device will have to be super easy and kind of "plug and play" to be use by non-technological and really busy people (nurse and patients in an hospital). I'll perhaps use OSC if I can't find solution with bluetooth, but ideally users will just have to clic on a icon on the phone and that's it, don't want them to have to do multiple actions to connect the phone and the sketch.

  • I want to send Live AudioInput of one PC to Another through Java Socket.How can I achieve that?

    Check previous code on UDP or oscP5 here in the forum or in provided examples on each library. Create a small sketch for testing across your network. You can explore previous code in the forum. Check also

    https://processing.org/reference/libraries/

    Kf