diff options
Diffstat (limited to '04_playobjects/src')
| -rw-r--r-- | 04_playobjects/src/main.cpp | 17 | ||||
| -rw-r--r-- | 04_playobjects/src/testApp.cpp | 183 | ||||
| -rw-r--r-- | 04_playobjects/src/testApp.h | 106 |
3 files changed, 306 insertions, 0 deletions
diff --git a/04_playobjects/src/main.cpp b/04_playobjects/src/main.cpp new file mode 100644 index 0000000..f0d25bb --- /dev/null +++ b/04_playobjects/src/main.cpp @@ -0,0 +1,17 @@ + +#include "testApp.h" +#include "ofMain.h" +#include "ofAppGlutWindow.h" + +//======================================================================== +int main( ){ + + ofAppGlutWindow window; + ofSetupOpenGL(&window, 1200,800, OF_WINDOW); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp( new testApp()); + +} diff --git a/04_playobjects/src/testApp.cpp b/04_playobjects/src/testApp.cpp new file mode 100644 index 0000000..5683e1f --- /dev/null +++ b/04_playobjects/src/testApp.cpp @@ -0,0 +1,183 @@ +#include "testApp.h" + +//-------------------------------------------------------------- +void testApp::setup() { + + ofSetLogLevel(OF_LOG_NOTICE); + + verdana.loadFont(ofToDataPath("verdana.ttf"), 10); + + playing=0; + numDevices=2; + + string filename="test.xml"; //"TRSS_nesbitt_recordings.xml"; + + if( !XML.loadFile(filename) ){ + 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++) { + /* + syncOniPlayer p; + p.addPlayer(XML.getAttribute("rec","left","",i)); + p.addPlayer(XML.getAttribute("rec","right","",i)); + p.audio=XML.getAttribute("rec","audio","",i); + players.push_back(p); + */ + players.push_back(syncOniPlayer()); + players[i].addPlayer(XML.getAttribute("rec","left","",i)); + players[i].addPlayer(XML.getAttribute("rec","right","",i)); + players[i].audio=XML.getAttribute("rec","audio","",i); + } + } + else printf("no recordings found!\n"); + } + } + /* + for (int deviceID = 0; deviceID < numDevices; deviceID++){ + + //openNIPlayers[deviceID].stop(); + openNIPlayers[deviceID].setup(true); + openNIPlayers[deviceID].start(); + //openNIPlayers[deviceID].startPlayer(ofToDataPath(recs[playing][deviceID])); + } + */ + soundplayer.setLoop(false); + startPlayers(0); + + //ofSetFrameRate(25.0f); + offset=0.0f; +} + +void testApp::startPlayers(int newplayer){ + players[playing].pause(); + playing=newplayer; + players[playing].play(); + //for (int deviceID = 0; deviceID < numDevices; deviceID++){ + //openNIPlayers[deviceID].stop(); + //openNIPlayers[deviceID].setup(true); + //openNIPlayers[deviceID].start(); + //openNIPlayers[deviceID].startPlayer(ofToDataPath(recs[playing].data[deviceID])); + + soundplayer.stop(); + + if (players[playing].audio!=""){ + soundplayer.loadSound(players[playing].audio); + soundplayer.play(); + //mmsoundplayer.setPositionMS(offset); + } + //} +} + +//-------------------------------------------------------------- +void testApp::update(){ + /* + for (int deviceID = 0; deviceID < numDevices; deviceID++){ + openNIPlayers[deviceID].update(); + } + */ + players[playing].update(); +} + +//-------------------------------------------------------------- +void testApp::draw(){ + ofBackground(0, 0, 0); + ofSetColor(255, 255, 255); + + ofPushMatrix(); + + players[playing].draw(); + + /* + for (int deviceID = 0; deviceID < numDevices; deviceID++){ + ofTranslate(0, deviceID * 400); + //openNIPlayers[deviceID].drawDebug(); + openNIPlayers[deviceID].drawDepth(50, 0,520,390); + openNIPlayers[deviceID].drawImage(600, 0,520,390); + } + */ + + ofPopMatrix(); + + ofSetColor(255, 255, 255); + string msg = "MILLIS: " + ofToString(ofGetElapsedTimeMillis()); + msg += "\nFPS: " + ofToString(ofGetFrameRate()); + msg += "\noffset: "+ofToString(offset); + verdana.drawString(msg, 10, 10); +} + +//-------------------------------------------------------------- +void testApp::exit(){ + +} + +//-------------------------------------------------------------- +void testApp::keyPressed(int key){ + int newplaying=playing; + switch (key) { + case ',': + newplaying=playing-1; + if (newplaying<0) newplaying=numDevices-1; + break; + case '.': + newplaying=(playing+1)%numDevices; + break; + case 'z': + offset-=1; + break; + case 'x': + offset+=1; + break; + } + if (newplaying!=playing) startPlayers(newplaying); + + /* why do this? + switch (key) { + case 't': + for (int deviceID = 0; deviceID < numDevices; deviceID++){ + openNIRecorders[deviceID].toggleRegister(); + } + break; + case 'x': + for (int deviceID = 0; deviceID < numDevices; deviceID++){ + openNIRecorders[deviceID].stop(); + } + break; + default: + break; + } + */ +} + +//-------------------------------------------------------------- +void testApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void testApp::mouseMoved(int x, int y ){ + +} + +//-------------------------------------------------------------- +void testApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::windowResized(int w, int h){ + +} + diff --git a/04_playobjects/src/testApp.h b/04_playobjects/src/testApp.h new file mode 100644 index 0000000..b541207 --- /dev/null +++ b/04_playobjects/src/testApp.h @@ -0,0 +1,106 @@ +#ifndef _TEST_APP +#define _TEST_APP + +#include "ofxOpenNI.h" +#include "ofMain.h" +#include "ofxXmlSettings.h" + +#define MAX_DEVICES 2 + +struct record{ + vector<string> data; + string audio; +}; + +//in order to play diffferent clips it seems necessary to have a player per clip +class syncOniPlayer{ + public: + ~syncOniPlayer(){ + for (int i=0;i<players.size();i++) { + players[i]->stop(); + delete players[i]; + } + } + void addPlayer(string name){ + //ofxOpenNI *o=new ofxOpenNI; + //o->setupFromONI(name,true); + //o->setPaused(true); + //players.push_back(o); + players.push_back(new ofxOpenNI); + players[players.size()-1]->setupFromONI(name,true); + players[players.size()-1]->setPaused(true); + //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 play(){ + for (int i=0;i<players.size();i++) { + players[i]->setPaused(false); + //players[players.size()-1]->setSpeed(1.0f); + } + } + void update(){ + for (int i=0;i<players.size();i++) { + players[i]->update(); + } + } + void pause(){ + for (int i=0;i<players.size();i++) { + //players[players.size()-1]->setSpeed(0.0f); + players[i]->setPaused(true); + } + } + void draw(){ + for (int i=0;i<players.size();i++) { + ofTranslate(0, i * 400); + players[i]->drawDepth(50, 0,520,390); + players[i]->drawImage(600, 0,520,390); + } + } + string audio; + private: + vector<ofxOpenNI*> players; + +}; + +//however creating losts of ofxOpenNI doesn't seem viable +//we know we want to play seperate clips +//however we know that when we stop and start a player it comes back single threaded + +class testApp : public ofBaseApp{ + +public: + void setup(); + void update(); + void draw(); + void exit(); + + void keyPressed (int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + + void startPlayers(int which); + + int numDevices; + ofxOpenNI openNIPlayers[MAX_DEVICES]; + + int playing; + + ofTrueTypeFont verdana; + + ofxXmlSettings XML; + + vector<syncOniPlayer> players; + + ofSoundPlayer soundplayer; + + int offset; + +}; + +#endif |
