TAD2011.02 Emotiv EPOC Video Recorder

Second TAD project (with video). [2013.12.09: the TAD website has been offline for a while now]

Emotiv EPOC Video Recorder

Here is the source code:

/**
 * EPOC Recorder 1
 * by Joshua Madara, hyperRitual.com
 * This sketch records graphical data from the Emotiv 
 * EPOC via OSC messages, as a .mov video file.
 */

import oscP5.*;
import processing.video.*;

// declare objects
OscP5 oscP5;
MovieMaker mm;
Format formatter;
PFont miniMono;
Date time;

int barColor = (color(255,0,0));

void setup() {
  size(320, 240);
  background(0);
  rectMode(CORNERS);
  
  // listen for OSC messages on port 7400
  oscP5 = new OscP5(this, 7400);
  
  // plug the messages from COG/PUSH to function makeFrame()
  oscP5.plug(this,"makeFrame","/COG/PUSH");
  
  // load MiniMono font
  miniMono = loadFont("MiniMono.vlw");
  textFont(miniMono);
  
  // format timestamp
  formatter = new SimpleDateFormat("HH:mm:ss:SSS");
  
  // Create MovieMaker object with size, filename,
  // framerate, compression codec and quality
  mm = new MovieMaker(this, width, height, "epoc_record.mov",
                       30, MovieMaker.H263, MovieMaker.LOSSLESS);
}

void draw() {
  // not used
}

// for each new event, add a frame to the video
void makeFrame(float pushValue) {
  background(0); // clear screen
  
  // update and draw timestamp and COG/PUSH value
  /* note that the time here is the local time when the 
  event is recorded, not a count-up timer that initiates 
  when recording begins, although that could be implemented */
  time = new Date();
  String timestamp = formatter.format(time);
  fill(255);
  text("Time: "+timestamp+"  Value: "+pushValue, 5, 10);
  
  // draw horizontal lines
  for (int i = 0; i <= 10; i++) {
    stroke(map(i, 0, 10, 255, 0));
    float yPos = map(i, 0, 10, 20, 220);
    line(100, yPos, 220, yPos);
  }
  
  // draw bar
  float barHeight = map(pushValue, 0, 1, 220, 20);
  noStroke();
  fill(barColor, 100);
  rect(width/2 - 20, 220, width/2 + 20, barHeight);
  
  // write pixels to video frame
  mm.addFrame();
}

// press space bar to finish the video
void keyPressed() {
  if (key == ' ') {
    mm.finish();
  }
}

Leave a Reply