Problems with Buffer (EyeTracker)

I'm receiving data from Matlab (1000fps) of a subject looking a picture using EyeTracker Hardware. [both in different computers].

Connection is OK, UDP is fine, OSC is working thanks to oscP5.

With the data, I draw circles ( that are designed by X and Y axis from EyeTracker device ) in a canvas.

Now the problem is that I don't know how to build a proper buffer to receive all this massive information, and then, after few milliseconds erase it. Because I want to see in my canvas, the eyes moving on real time drawing circles, but i just want to see 1 circle, not all of them, eventhough i don't need to save all this information.

If you don't understand something, please ask me, and I'll try to explain you better:

I have this code, feel free to ask and say whatever you want :

 * oscP5parsing by andreas schlegel
 * example shows how to parse incoming osc messages "by hand".
 * it is recommended to take a look at oscP5plug for an
 * alternative and more convenient way to parse messages.
 * oscP5 website at
import java.util.*;

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

ArrayList <Posiciones> buffer  = new ArrayList<Posiciones>();

//Iterator <Posiciones> itr = new ArrayList<Posiciones>();

long tiempoX = 1000;
long tiempoActual = millis(); 

float x1, y1, x2, y2;
float diamt = 20;

float ancho = 400;
float alto = 400;

void setup() {
  size(400, 400); 
  /* start oscP5, listening for incoming messages at port 8002 */
  oscP5 = new OscP5(this, 8002); //Pasar este puerto al experimento de MatLab

  /* 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("", 4002);

void draw() {


void oscEvent(OscMessage theOscMessage) {
  /* check if theOscMessage has the address pattern we are looking for. */

  if (theOscMessage.checkAddrPattern("/test")==true) {
    /* check if the typetag is the right one. */
    if (theOscMessage.checkTypetag("s")) {
      /* parse theOscMessage and extract the values from the osc message arguments. */
      String stringValue = theOscMessage.get(0).stringValue();
      println(" values: " + stringValue);

      int[] datos = int(split(stringValue, "-")); //divide los datos y los guarda temporalmente //  divide data and save temporarily
      Posiciones crearPosiciones = new Posiciones(); //creo un objeto para guardar la data // creating an object to save the data
      crearPosiciones.x1 = datos[0]; //guardo la data // saving data
      crearPosiciones.y1 = datos[1];
      crearPosiciones.x2 = datos[2];
      crearPosiciones.y2 = datos[3];
      buffer.add(crearPosiciones); //agrego un elemento al arrayList/buffer // adding an element to arrayList/buffer


void escupirData() {

  long currentMillis = millis();

  if (millis() - tiempoActual >= tiempoX ) {
    //Pixel newPixel = pixeles.get(i); 

    if (buffer.size() > 0) { //fijarse si el buffer tiene elementos // look if the buffer has elements
      Posiciones posicionActual = buffer.get(0); //creo un objeto para guardar el primer objeto del buffer // creating an object to save the first object of the buffer

      x1 = posicionActual.x1; //guardo la data para usar // saving the data to use
      y1 = posicionActual.y1;
      x2 = posicionActual.x2;
      y2 = posicionActual.y2;

      posicionActual.borrar = true;//si ya lo dibujé levanto el flag para borrarlo // if it is drawn, clear

      println(" borrado: " + posicionActual.borrar);

      tiempoActual = millis();

  //crear un iterator, que si ya dibujó la posición lo borre por el flag // creating an iterator

  //creo un iterator para podes remover lugares del ArrayList // creating an iterator to remove spots of ArrayList
  Iterator itr = buffer.iterator();
  // itr = buffer.iterator();
  while (itr.hasNext ()) {
    Posiciones posicionActual = (Posiciones);
    if (posicionActual.borrar) {
      itr.remove(); //remuevo la frase que ya no se ve // removing the phrase that is not visible
      println("borré 1, quedan " + buffer.size() + " posiciones");

void dibujarCirculos() {

  x1 = map(x1, 0, ancho, 0, width); 
  y1 = map(y1, 0, ancho, 0, height);
  x2 = map(x2, 0, ancho, 0, width); 
  y2 = map(y2, 0, ancho, 0, height); 

  fill(255, 0, 0);
  ellipse(x1, y1, diamt, diamt);
  fill(0, 0, 255);
  ellipse(x2, y2, diamt, diamt);


class Posiciones {
  int x1, y1, x2, y2;
  boolean borrar = false;

  Posiciones() {

  void vacio() {



  • edit post, highlight code, press ctrl-o to format

  • edited February 2018

    Format your code.



  • So you are sending 1000fps data over OSC in real time? And you want to draw one circle at a time in realtime?

    I don't understand this. No display could draw at 1000fps, and even if it could the result would be imperceptabe compared to 100fps, so why would you do this?

  • duplicate deleted.

    if you post duplicates then you split all the possible answers and generally cause confusion.

  • @koogs thanks I'm a complete newbie on this. I highlighted the code now (I didn't know how to do it). And sorry for the post duplicated, I thought I could post in one section without the code just to see what people think about it without my code, and here work in this possible idea, but it's ok, i got the point.

    @jeremydouglass I could down the fps to 200fps from the EyeLink System and also changed to one eye instead of both of them. So I reduce a lot the quantity of information.

    That's the best I can improve, I'm doing this because EyeLink software don't allow less than that.

    Now any idea? Thanks to be patience

  • if you post duplicates then you split all the possible answers and generally cause confusion.

    this also goes for bumping old questions, like the one from 2014 that you just replied to.

  • How are you sending OSC from MatLab? Can you just sample at 60fps there before generating the OSC messages?

  • Thanks guys! I solved the problem.

  • @koogs Sorry, I'm trying to do my best. I'm new here. Thanks for all your help.....

Sign In or Register to comment.