summaryrefslogtreecommitdiff
path: root/06_performance/src
diff options
context:
space:
mode:
authorComment <tim@gray.(none)>2013-06-20 09:06:40 +0100
committerComment <tim@gray.(none)>2013-06-20 09:06:40 +0100
commit39bcb5346b1f746399192391b6699e81d0d8ad3a (patch)
tree36445cbd0d270f5181fb04eaf875a7b6f3422ff2 /06_performance/src
parentcdd0e0b630bd3a5a8ba15dbce7f5e03221b72f92 (diff)
spooky bug fixed, integration nearly right
Diffstat (limited to '06_performance/src')
-rw-r--r--06_performance/src/main.cpp3
-rw-r--r--06_performance/src/oni.cpp159
-rw-r--r--06_performance/src/oni.h47
-rw-r--r--06_performance/src/testApp.cpp184
-rw-r--r--06_performance/src/testApp.h6
5 files changed, 316 insertions, 83 deletions
diff --git a/06_performance/src/main.cpp b/06_performance/src/main.cpp
index 58263a2..20767a2 100644
--- a/06_performance/src/main.cpp
+++ b/06_performance/src/main.cpp
@@ -4,7 +4,8 @@
//========================================================================
int main( ){
- ofSetupOpenGL(4080,768, OF_WINDOW); // <-------- setup the GL context
+ //ofSetupOpenGL(4080,768, OF_WINDOW); // <-------- setup the GL context
+ ofSetupOpenGL(1224,232, OF_WINDOW); // <-------- setup the GL context
diff --git a/06_performance/src/oni.cpp b/06_performance/src/oni.cpp
index a202f41..550d56e 100644
--- a/06_performance/src/oni.cpp
+++ b/06_performance/src/oni.cpp
@@ -1 +1,158 @@
-#include "oni.h" \ No newline at end of file
+#include "oni.h"
+
+void syncOniPlayer::addPlayer(string name){
+ //ofxOpenNI *o=new ofxOpenNI;
+ //o->setupFromONI(name,true);
+ //o->setPaused(true);
+ //players.push_back(o);
+ players.push_back(NULL);
+ filenames.push_back(name);
+ soundplayer.setLoop(false);
+ //players[players.size()-1]->setSpeed(0.0f);
+ //players[players.size()-1]->setup(true);
+ //players[players.size()-1]->start();
+ //players[players.size()-1]->startPlayer(name);
+}
+void syncOniPlayer::play(){
+ for (int i=0;i<players.size();i++) {
+ players[i]=new ofxOpenNI();
+ //players[i]->setSafeThreading(true);
+ players[i]->setupFromONI(filenames[i],true);
+ //players[i]->addDepthGenerator();
+ //players[i]->addImageGenerator();
+ //players[i]->setRegister(true);
+ players[i]->setLooped(false);
+ //players[i]->setBaseUserClass(user);
+ players[i]->start();
+ //players[players.size()-1]->setSpeed(1.0f);
+ if (audio!="") {
+ soundplayer.loadSound(audio);
+ soundplayer.play();
+ };
+ //sleep(2);
+ drawable=true;
+ }
+}
+void syncOniPlayer::update(){
+ for (int i=0;i<players.size();i++) {
+ players[i]->update();
+ }
+}
+void syncOniPlayer::pause(){
+ for (int i=0;i<players.size();i++) {
+ //players[players.size()-1]->setSpeed(0.0f);
+ players[i]->setPaused(true);
+ }
+}
+int syncOniPlayer::getCurrentFrame(){
+ if (players.size()) return players[0]->getCurrentFrame();
+ else return -1;
+}
+void syncOniPlayer::drawWindows(){
+ if (!drawable) return;
+ for (int i=0;i<players.size();i++) {
+ if (players[i]==NULL) break;
+ ofTranslate(0, i * 400);
+ players[i]->drawDepth(50, 0,520,390);
+ players[i]->drawImage(600, 0,520,390);
+
+
+ }
+}
+void syncOniPlayer::drawCloud(int step){
+ int count;
+ for (int n=0;n<players.size();n++) {
+
+
+ const XnDepthPixel* depthmap=players[n]->getDepthGenerator().GetDepthMap();
+ //uint16_t* depthpixels=depthmap.getPixels();
+ int range=1700;
+
+ int depthW=players[n]->getWidth();
+ int depthH=players[n]->getHeight();
+
+ for (int i=0;i<depthW;i+=step) {
+
+ glBegin(GL_LINES);
+
+ for (int j=0;j<depthH;j+=step) {
+
+
+ ofPoint p= players[n]->projectiveToWorld(ofPoint(i,j,(float)(depthmap[j*depthW+i])));
+ //ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
+
+ if (p.z == 0 || p.z>range) continue; // gets rid of background
+
+
+ glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255);
+ glVertex3f(p.x, p.y, p.z);
+ //if (i==320&&j==160) cerr<<"world point: "<<p.x<<","<<p.y<<","<<p.z<<endl;
+ }
+
+ glEnd();
+ }
+
+ }
+
+ return;
+}
+void syncOniPlayer::stop(){
+ soundplayer.stop();
+ for (int i=0;i<players.size();i++) {
+ if (players[i]!=NULL) {
+ players[i]->stop();
+ delete players[i];
+ players[i]=NULL;
+ }
+ }
+ drawable=false;
+}
+//=================
+void oniManager::init(const char* filename){
+ playing=-1;
+ int numDevices=1;
+ string f=string(filename);
+ if( !XML.loadFile(f) ){
+ printf("unable to load recordings, check data/ folder\n");
+ }else{
+ if(XML.pushTag("TRSS")) {
+ int num=XML.getNumTags("rec");
+ if(num) {
+ for (int i=0;i<num;i++) {
+ players.push_back(syncOniPlayer());
+ players[i].addPlayer(XML.getAttribute("rec","left","",i));
+ if (numDevices==2) {
+ players[i].addPlayer(XML.getAttribute("rec","right","",i));
+ }
+ players[i].audio=XML.getAttribute("rec","audio","",i);
+ }
+ }
+ else printf("no recordings found!\n");
+ }
+ }
+}
+void oniManager::startPlayer(int newplayer){
+ if (players.size()>newplayer){
+ if (playing>-1) players[playing].stop();
+ usleep(100000);
+ playing=newplayer;
+ players[playing].play();
+ }
+}
+void oniManager::update(){
+ if (players.size()>playing&&playing>-1) players[playing].update();
+}
+void oniManager::drawWindows(){
+ if (players.size()>playing&&playing>-1) players[playing].drawWindows();
+}
+void oniManager::drawCloud(int step){
+ if (players.size()>playing&&playing>-1) players[playing].drawCloud(step);
+}
+void oniManager::previous(){
+ int newp=(playing+1)%players.size();
+ startPlayer(newp);
+}
+void oniManager::next(){
+ int newp=playing-1<0?players.size()-1:playing-1;
+ startPlayer(newp);
+} \ No newline at end of file
diff --git a/06_performance/src/oni.h b/06_performance/src/oni.h
index ccb1417..158d513 100644
--- a/06_performance/src/oni.h
+++ b/06_performance/src/oni.h
@@ -1 +1,46 @@
-#include "ofxOpenNI.h" \ No newline at end of file
+#include "ofMain.h"
+#include "ofxXmlSettings.h"
+#include "ofxOpenNI.h"
+
+
+
+//in order to play different clips it seems necessary to have a player per clip
+class syncOniPlayer{
+ public:
+ syncOniPlayer() {
+ drawable=false;
+ }
+ ~syncOniPlayer(){
+ stop();
+ }
+ void addPlayer(string name);
+ void play();
+ void update();
+ void pause();
+ int getCurrentFrame();
+ void drawWindows();
+ void drawCloud(int step);
+ void stop();
+ string audio;
+
+ private:
+ vector<ofxOpenNI*> players;
+ vector<string> filenames;
+ ofSoundPlayer soundplayer;
+ bool drawable;
+
+};
+//========================================
+class oniManager{
+ public:
+ void init(const char* filename);
+ void startPlayer(int num);
+ void update();
+ void drawWindows();
+ void drawCloud(int step);
+ void previous();
+ void next();
+ int playing;
+ ofxXmlSettings XML;
+ vector<syncOniPlayer> players;
+}; \ No newline at end of file
diff --git a/06_performance/src/testApp.cpp b/06_performance/src/testApp.cpp
index d41071a..ac1391b 100644
--- a/06_performance/src/testApp.cpp
+++ b/06_performance/src/testApp.cpp
@@ -17,11 +17,11 @@ void testApp::setup(){
midiIn.listPorts();
- midiIn.openPort(0); //this was 1 on linux
+ midiIn.openPort(1); //this was 1 on linux
midiIn.addListener(this);
midiOut.listPorts();
- midiOut.openPort(0); //this was 1 on linux
+ midiOut.openPort(1); //this was 1 on linux
// 0 output channeLs,
// 2 input channels
@@ -60,7 +60,7 @@ void testApp::setup(){
F_movieSpeed=0.0;
//blendImage.loadImage("blend01.png");
- blendImage.loadMovie("blend01.mov");
+ blendImage.loadMovie("blend.mp4");
blendImage.play();
blendImage.setLoopState(OF_LOOP_NORMAL);
blendImage.setSpeed(F_movieSpeed);
@@ -95,8 +95,8 @@ void testApp::setup(){
F_yRotate=0;
F_zRotate=0;
- F_xRotation=0;
- F_yRotation=180;
+ F_xRotation=180;
+ F_yRotation=180; //was 180
F_zRotation=0;
F_particleAmount=100;
@@ -141,6 +141,11 @@ void testApp::setup(){
fullScreen=false;
setMidiState();
+
+ target.setPosition(0,0,0);
+ camera.setPosition(0,0,-700);
+ camera.lookAt(target,ofVec3f(0,1,0));
+ narrator.init("TRSS_nesbitt_recordings.xml");
}
@@ -171,7 +176,9 @@ void testApp::update(){
I_moviePlaying=I_movieSource;
}
blendImage.setSpeed(F_movieSpeed);
- blendImage.idleMovie();
+ //blendImage.idleMovie();
+
+ narrator.update();
}
//--------------------------------------------------------------
@@ -247,86 +254,95 @@ void testApp::draw(){
F_drawFrames=max(1.99f,min(F_drawFrames+(F_drawStep*interval),(float)BUFFER_FRAMES));
ofPushMatrix();
- ofTranslate(hw,hh);
- ofRotateX(F_xRotation);
- ofRotateY(F_yRotation);
- ofRotateZ(F_zRotation);
-
-
- if (inputMode==GRABBER) {
- ofSetColor(I_fade2,I_fade2,I_fade2);
- ofPushMatrix();
- ofRotateX(90);
- ofRotateZ(-90);
- outTexture.draw(hw,-hh,-ofGetWidth(),ofGetHeight());
- ofPopMatrix();
- }
+ //ofTranslate(hw,hh);
+ camera.begin();
+ ofRotateX(F_xRotation);
+ ofRotateY(F_yRotation);
+ ofRotateZ(F_zRotation);
- GLfloat fogColor[4] = {0,0,0, 1.0};
- glFogi(GL_FOG_MODE, GL_LINEAR);
- glFogfv(GL_FOG_COLOR, fogColor);
- glFogf(GL_FOG_DENSITY,1.0 );
- glHint(GL_FOG_HINT, GL_DONT_CARE);
- glFogf(GL_FOG_START, ofGetWidth()*(0.25+F_drawDecay));
- glFogf(GL_FOG_END, ofGetWidth()*(0.75+F_drawDecay));
- glEnable(GL_FOG);
-
- //reverse draw order when looking from back
- int jStart=0;
- int jEnd=F_drawFrames-1;
- int jStep=1;
- float F_yseg=F_yRotation;
- while (F_yseg<-90) F_yseg+=360;
- while (F_yseg>270) F_yseg-=360;
- if (F_yseg>90) {
- jStart=jEnd;
- jEnd=0;
- jStep=-1;
- if (draworder) {
- draworder=false;
- //printf("switched to reverse order\n");
+ /*
+ if (inputMode==GRABBER) {
+ ofSetColor(I_fade2,I_fade2,I_fade2);
+ ofPushMatrix();
+ ofRotateX(90);
+ ofRotateZ(-90);
+ outTexture.draw(hw,-hh,-ofGetWidth(),ofGetHeight());
+ ofPopMatrix();
+ }
+ */
+ GLfloat fogColor[4] = {0,0,0, 1.0};
+ glFogi(GL_FOG_MODE, GL_LINEAR);
+ glFogfv(GL_FOG_COLOR, fogColor);
+ glFogf(GL_FOG_DENSITY,1.0 );
+ glHint(GL_FOG_HINT, GL_DONT_CARE);
+ glFogf(GL_FOG_START, ofGetWidth()*(0.25+F_drawDecay));
+ glFogf(GL_FOG_END, ofGetWidth()*(0.75+F_drawDecay));
+ glEnable(GL_FOG);
+
+ //reverse draw order when looking from back
+ int jStart=0;
+ int jEnd=F_drawFrames-1;
+ int jStep=1;
+ float F_yseg=F_yRotation;
+ while (F_yseg<-90) F_yseg+=360;
+ while (F_yseg>270) F_yseg-=360;
+ if (F_yseg>90) {
+ jStart=jEnd;
+ jEnd=0;
+ jStep=-1;
+ if (draworder) {
+ draworder=false;
+ //printf("switched to reverse order\n");
+ }
+ }
+ else if (!draworder) {
+ draworder=true;
+ //printf("switched to normal order\n");
}
- }
- else if (!draworder) {
- draworder=true;
- //printf("switched to normal order\n");
- }
- for (int j=jStart;j!=jEnd;j+=jStep) {
- int fB=(thisFFTbuffer+j)%BUFFER_FRAMES;
+ for (int j=jStart;j!=jEnd;j+=jStep) {
+ int fB=(thisFFTbuffer+j)%BUFFER_FRAMES;
+
+ ofPushMatrix(); //coordinate transform for FFT draw direction
+ ofTranslate(0,0,(j*zStep)-hw);
+ ofRotateX(F_drawAxis);
+
+ ofFill();
+ ofSetColor(0,0,0);
+ if (B_fill) {
+ glBegin(GL_QUAD_STRIP);
+ for (int i = 0; i < lFFTanalyzer.nAverages-1; i++){
+ glVertex3f((i*xStep)-hw,-(FFTbuffer[0][i][fB] * F_scale),0);
+ glVertex3f((i*xStep)-hw,0,0);
+ }
+ for (int i =lFFTanalyzer.nAverages, k=lFFTanalyzer.nAverages-1; i < lFFTanalyzer.nAverages+rFFTanalyzer.nAverages; i++, k--){
+ glVertex3f((i*xStep)-hw,-(FFTbuffer[1][(lFFTanalyzer.nAverages+rFFTanalyzer.nAverages)-(i+1)][fB] * F_scale),0);
+ glVertex3f((i*xStep)-hw,0,0);
+ }
+ glEnd();
+ }
+
+ ofNoFill();
+ ofSetLineWidth(F_lineWidth);
+ ofSetColor(I_fade1,I_fade1,I_fade1);
+ glBegin(GL_LINE_STRIP);
+ for (int i = 0; i < lFFTanalyzer.nAverages; i++){
+ glVertex3f((i*xStep)-hw,-(FFTbuffer[0][i][fB] * F_scale),0);
+ }
+ for (int i =lFFTanalyzer.nAverages, k=lFFTanalyzer.nAverages-1; i < lFFTanalyzer.nAverages+rFFTanalyzer.nAverages; i++, k--){
+ glVertex3f((i*xStep)-hw,-(FFTbuffer[1][(lFFTanalyzer.nAverages+rFFTanalyzer.nAverages)-(i+1)][fB] * F_scale),0);
+ }
+ glEnd();
+ ofPopMatrix();
+ }
- ofPushMatrix(); //coordinate transform for FFT draw direction
- ofTranslate(0,0,(j*zStep)-hw);
- ofRotateX(F_drawAxis);
+ ofPushMatrix();
+ ofTranslate(0,150,-1050);
+ narrator.drawCloud(2);
+ ofPopMatrix();
- ofFill();
- ofSetColor(0,0,0);
- if (B_fill) {
- glBegin(GL_QUAD_STRIP);
- for (int i = 0; i < lFFTanalyzer.nAverages-1; i++){
- glVertex3f((i*xStep)-hw,-(FFTbuffer[0][i][fB] * F_scale),0);
- glVertex3f((i*xStep)-hw,0,0);
- }
- for (int i =lFFTanalyzer.nAverages, k=lFFTanalyzer.nAverages-1; i < lFFTanalyzer.nAverages+rFFTanalyzer.nAverages; i++, k--){
- glVertex3f((i*xStep)-hw,-(FFTbuffer[1][(lFFTanalyzer.nAverages+rFFTanalyzer.nAverages)-(i+1)][fB] * F_scale),0);
- glVertex3f((i*xStep)-hw,0,0);
- }
- glEnd();
- }
+ camera.end();
- ofNoFill();
- ofSetLineWidth(F_lineWidth);
- ofSetColor(I_fade1,I_fade1,I_fade1);
- glBegin(GL_LINE_STRIP);
- for (int i = 0; i < lFFTanalyzer.nAverages; i++){
- glVertex3f((i*xStep)-hw,-(FFTbuffer[0][i][fB] * F_scale),0);
- }
- for (int i =lFFTanalyzer.nAverages, k=lFFTanalyzer.nAverages-1; i < lFFTanalyzer.nAverages+rFFTanalyzer.nAverages; i++, k--){
- glVertex3f((i*xStep)-hw,-(FFTbuffer[1][(lFFTanalyzer.nAverages+rFFTanalyzer.nAverages)-(i+1)][fB] * F_scale),0);
- }
- glEnd();
- ofPopMatrix();
- }
ofPopMatrix();
renderImage.end();
@@ -447,6 +463,8 @@ void testApp::draw(){
glPopMatrix();
*/
+
+
if (showFPS) {
ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20);
ofDrawBitmapString(ofToString(F_xRotation, 4)+" "+ofToString(F_yRotation, 4)+" "+ofToString(F_zRotation, 4),20,30);
@@ -464,6 +482,12 @@ void testApp::keyPressed (int key){
fullScreen=!fullScreen;
ofSetFullscreen(fullScreen);
}
+ if(key == ','){
+ narrator.previous();
+ }
+ if(key == '.'){
+ narrator.next();
+ }
}
//--------------------------------------------------------------
diff --git a/06_performance/src/testApp.h b/06_performance/src/testApp.h
index cca9e20..b1c086c 100644
--- a/06_performance/src/testApp.h
+++ b/06_performance/src/testApp.h
@@ -5,6 +5,8 @@
#include "fft.h"
#include "FFTOctaveAnalyzer.h"
+#include "oni.h"
+
#define BUFFER_SIZE 1024
#define BUFFER_FRAMES 512
@@ -157,6 +159,10 @@ class testApp : public ofBaseApp, public ofxMidiListener{
ofImage blanker;
+
+ ofCamera camera;
+ ofNode target;
+ oniManager narrator;
};
#endif