// OSC\u9001\u4fe1
  public void sendOSC(ArrayList<dotObj> theList, OscMessage message, String prefix) {

    if (theList.size() > 0) {
      // \u901a\u4fe1\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u521d\u671f\u5316
      message.clear();
      // prefix\u306e\u6307\u5b9a
      message.setAddrPattern(prefix);
      // \u5024\u306e\u6307\u5b9a(\u4e0b\u8a18\u306e\u3088\u3046\u306b\u7d9a\u3051\u3066\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067PureData\u3067\u306flist\u3068\u3057\u3066\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u308b)
      // message.add(mouseX);
      // message.add(mouseY);

      float average = 0;
      for (int i = 0; i < theList.size(); i++) {
        average += theList.get(i).val;
      }
      average = average / theList.size();
      // println(average);

      for (int i = 0; i < theList.size(); i++) {
        float val = map(theList.get(i).val, -0.7f, 0.7f, 0, 127);
        // float zero_shift_val = theList.get(i).val - average;
        // float val = map(zero_shift_val, -0.02, 0.02, 0, 127);
        message.add(val);
      }

      // OSC\u306e\u9001\u4fe1
      oscP5.send(message, myRemoteLocation);
    }
  }
Example #2
0
  public void oscEvent(OscMessage theOscMessage) {
    // print the address pattern of the received OscMessage
    String addr = theOscMessage.addrPattern();

    print("### received an osc message.");
    println("tag type: " + theOscMessage.typetag());
    println("addr type: " + theOscMessage.addrPattern()); // it was lowercase in the documentation

    /// we have to check for init OSC values
    /// so the mouse doesn't override it on
    /// globe and cursor postion
    if (addr.indexOf("/EpsonPlanet/xy1") != -1) {
      hasOsc = true;
      println(hasOsc);
    }
    if (addr.indexOf("/EpsonPlanet/xy2") != -1) {
      hasOsc = true;
      println(hasOsc);
    }

    if (theOscMessage.checkTypetag("i")) {
      if (addr.equals("/EpsonPlanet/fader1")) {
        int valI = theOscMessage.get(0).intValue();
      }
    }

    /// check for 2 FLOATS
    if (theOscMessage.checkTypetag("ff")) {
      float val0 = theOscMessage.get(0).floatValue();
      float val1 = theOscMessage.get(1).floatValue();
      // hasOsc == true
      println("FF type: " + val0 + " " + val1);
      try {
        if (addr.equals("/EpsonPlanet/xy1")) {
          println("Do globe " + val0);
          oscX0 = new Float(val0);
          oscY0 = new Float(val1);
        } else if (addr.equals("/EpsonPlanet/xy2")) {
          float val2 = theOscMessage.get(0).floatValue();
          float val3 = theOscMessage.get(1).floatValue();
          doCursor = true;
          oscX1 = new Float(val2);
          oscY1 = new Float(val3);
        }
      } catch (Exception e) {
        println("can't run real floats");
      }
    }
    /// check for ONE FLOAT
    /// thanks stupid oscP5
    if (theOscMessage.checkTypetag("f")) {
      /// set up strings for the 2 values because stupid OSC
      String str0 = theOscMessage.toString();
      String str1 = theOscMessage.toString();

      try {

        // println(" VALUE 0: "+theOscMessage.get(0).floatValue());
        if (addr.equals("/EpsonPlanet/fader1")) {
          // targetZoom = max(targetZoom - 0.1f, 0.5f);
          // targetZoom = min(targetZoom + 0.1f, 1.9f);
          float val0 = theOscMessage.get(0).floatValue();
          println("DO ZOOM " + addr + " " + val0);
          targetZoom = map(val0, 0, 1, 0.5f, 1.9f);

        } else if (addr.equals("/1/fader2")) {
          println("v2 " + str0);
        } else if (addr.equals("/1/xy1")) {

        } else if (addr.equals("/EpsonPlanet/toggle1")) {
          println("toggle visibility");
          theDestroyer.toggleVisibility();

        } else if (addr.equals("/EpsonPlanet/resetGlobeButt")) {
          println("reset position");
          theCamX = defaultCamX;
          theCamY = defaultCamY;
          targetZoom = 1;

        } else if (addr.equals("/EpsonPlanet/playVidButt")) {
          println("play vid");
          thePopUp.startVideo();

        } else if (addr.equals("/EpsonPlanet/stopVidButt")) {
          println("pause vid");
          thePopUp.stopVideo();

        } else if (addr.equals("/EpsonPlanet/rotary1")) {
          int v = parseInt(theOscMessage.get(0).floatValue());
          println("R: " + v + " " + str0);
          bgColorR = v;
        } else if (addr.equals("/EpsonPlanet/rotary2")) {
          int v = parseInt(theOscMessage.get(0).floatValue());
          println("G: " + v + " " + str0);
          bgColorG = v;
        } else if (addr.equals("/EpsonPlanet/rotary3")) {
          int v = parseInt(theOscMessage.get(0).floatValue());
          println("B: " + v + " " + str0);
          bgColorB = v;
        }
      } catch (Exception e) {
        println(" osc error: " + e);
      }
    }

    /// control x and y globe

    /// control x and y destroyer
  }
Example #3
0
  /*
   * Method used to receive messages from Kinnect or MSB in the future
   */
  public void oscEvent(OscMessage theOscMessage) {

    // Friedrich added this select camera event
    if (theOscMessage != null && theOscMessage.checkAddrPattern("/selectActorByName")) {
      println("select Actor!");
      String myNewCamera = theOscMessage.get(0).stringValue();

      println(myNewCamera);

      // RAFACTOR THIS PART; MAYBE MAKE A DYNAMIC ENUM IN THE CAM DATA STRUCTURE?
      if (myNewCamera.compareTo("Camera1") == 0) selectedCamera = 0;
      if (myNewCamera.compareTo("Camera2") == 0) selectedCamera = 1;
      if (myNewCamera.compareTo("Camera3") == 0) selectedCamera = 2;
      if (myNewCamera.compareTo("Camera4") == 0) selectedCamera = 3;

      // Friedrich changed the coloring code here
      for (int i = 0; i < cameras.size(); i++) {
        cameras.get(i).changeToDefaultColor();
        cameras.get(i).isSelected = false;
      }

      cameras.get(selectedCamera).isSelected = true;
      cameras.get(selectedCamera).changeToSelectedColor();
      //    println(""  + timeline.getTickArr());
      timeline.getActiveTick().setCam(cameras.get(selectedCamera));
    }

    // Friedrich changed the AddressPattern for the submitted package - we can ignore the first
    // string part of the message
    if (theOscMessage != null
        && theOscMessage.checkAddrPattern("/setPropertyForSelected/string/matrix4f")) {
      float[] matrix = new float[16];

      // we do not need to use this in Processing, but let's pop it off the stack anyway
      String propertyName = theOscMessage.get(0).stringValue();

      for (int i = 1; i <= 16; i++) {
        if (i > 12 && i <= 15) {
          matrix[i - 1] = theOscMessage.get(i).floatValue() * 10;
        } else {
          matrix[i - 1] = theOscMessage.get(i).floatValue();
        }
      }

      matrix[2] = -matrix[2];
      matrix[8] = -matrix[8];

      // Friedrich - manual scaling adjustments
      matrix[12] = (700 - matrix[12]) * 2.0f;
      matrix[14] = matrix[14] * 1.5f;
      // println (matrix[12]);

      FloatBuffer fb = FloatBuffer.allocate(16);
      fb = FloatBuffer.wrap(matrix);
      // TODO(sanjeet): Currently using only camera 5
      // Change this variable based on the data received from OSC
      //    int selectedCamera = 5;
      cameras.get(selectedCamera).modelViewMatrix = fb;
    }

    // receive the currentFrame from kinect
    // this is where the playhead is on the timeline
    // currentFrame is global
    if (theOscMessage != null && theOscMessage.checkAddrPattern("/setPlayheadFrame/int")) {
      currentFrame = theOscMessage.get(0).intValue();
      println("Current Frame: " + currentFrame);
    }
  }