diff options
| author | Comment <tim@gray.(none)> | 2013-01-29 01:52:00 +0000 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2013-01-29 01:52:00 +0000 |
| commit | ba37049c44ff64b3c6482a5e2f199f178351a69f (patch) | |
| tree | 2a585dc6a4a169e894b841b343d5763b94e3c1f5 /src/testApp.cpp | |
| parent | f7667bd306b983f8f8daa0b40719aa665bf555b0 (diff) | |
mostly working
Diffstat (limited to 'src/testApp.cpp')
| -rwxr-xr-x | src/testApp.cpp | 134 |
1 files changed, 79 insertions, 55 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp index 1ca45e4..0392c92 100755 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -1,19 +1,24 @@ #include "testApp.h" //-------------------------------------------------------------- +guiWindow::~guiWindow(){ + cout << "gui window destroyed" << endl; +} +void guiWindow::setup(){} +void guiWindow::setParent(testApp *p){ + parent=p; +} +void guiWindow::draw(){ + parent->gui.draw(); +} +//-------------------------------------------------------------- void testApp::setup(){ loadSettings("settings.xml"); - //sender.setup(host.c_str(),port); - sender.setup("169.254.113.20",57117); - - bInvert=true; - threshold = 80; - // gw=720; gh=576; vidGrabber.setVerbose(true); - bool bGrab=false; + bGrab=false; //vidGrabber.initGrabber(gw,gh); //base grab size colorImg.allocate(gw,gh); @@ -25,33 +30,35 @@ void testApp::setup(){ bLearnBakground = true; - - bFlip=true; - if (boundaries.size()==0) { boundaries.push_back(boundary()); } selectedBoundary=0; -// ofAddListener(ofEvents().fileDragEvent, this, &testApp::fileDragEvent); - /* guiWin=new guiWindow(); - //gui window stuff - ofxFenster* win2=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW); + ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 200, 200, OF_WINDOW); //ofAddListener(win2->events.windowResized, this, &testApp::windowEvent); - win2->setWindowTitle("config"); - win2->addListener(guiWin); + //volume is set in loadSettings + gui.setup("","panel.xml",0,0); + gui.add(vol.setup("volume",volume,0,1.0,255)); + vol.addListener(this,&testApp::volumeChanged); + gui.add(bFlip.setup("flip grab", flip)); + gui.add(bInvert.setup("invert grab", invert)); + gui.add(thresh.setup("threshold",threshold,0,255,255)); + win->setWindowTitle("config"); + win->addListener(guiWin); guiWin->setup(); guiWin->setParent(this); -*/ + } //-------------------------------------------------------------- void testApp::update(){ - if (bGrab) { vidGrabber.grabFrame(); + if (bGrab) { + vidGrabber.grabFrame(); bool bNewFrame = vidGrabber.isFrameNew(); if (bNewFrame){ colorImg.setFromPixels(vidGrabber.getPixels(), gw,gh); @@ -67,34 +74,35 @@ void testApp::update(){ contourFinder.findContours(grayDiff, 20, (gw*gh)/3, 10, true); // find holes } - //generate midi -/* + //generate events + for (int i = 0; i < contourFinder.nBlobs; i++){ for (int j=0;j<boundaries.size();j++) { - if (boundaries[j].contains(contourFinder.blobs[i].centroid)) { - sendNote(boundaries[j].note); - //printf("sending %i\n",boundaries[j].note); + if (boundaries[j].checkClick(contourFinder.blobs[i].centroid)) { + printf("playing %i: %s\n",boundaries[j].filename.c_str(),j); } } } - */ } } //-------------------------------------------------------------- void testApp::draw(){ + //ofBackground(0,0,0); ofSetColor(255,255,255); - switch(mode){ - case COLOUR: - colorImg.draw(0,0,gw,gh); //(ofGetHeight()-gh)/2,gw,ofGetHeight()+((gh-ofGetHeight())/2)); - break; - case GREY: - grayImage.draw(0,0,gw,gh); //(ofGetHeight()-gh)/2,gw,ofGetHeight()+((gh-ofGetHeight())/2)); - break; - case DIFF: - grayDiff.draw(0,0,gw,gh); //(ofGetHeight()-gh)/2,gw,ofGetHeight()+((gh-ofGetHeight())/2)); - break; + if (bGrab) { + switch(mode){ + case COLOUR: + colorImg.draw(0,0,gw,gh); //(ofGetHeight()-gh)/2,gw,ofGetHeight()+((gh-ofGetHeight())/2)); + break; + case GREY: + grayImage.draw(0,0,gw,gh); //(ofGetHeight()-gh)/2,gw,ofGetHeight()+((gh-ofGetHeight())/2)); + break; + case DIFF: + grayDiff.draw(0,0,gw,gh); //(ofGetHeight()-gh)/2,gw,ofGetHeight()+((gh-ofGetHeight())/2)); + break; + } } for (int i = 0; i < contourFinder.nBlobs; i++){ @@ -102,10 +110,21 @@ void testApp::draw(){ } for (int i=0;i<boundaries.size();i++) { - if (selectedBoundary==i) ofSetColor(255,0,0); - else ofSetColor(180,0,0); + int b=selectedBoundary==i?255:180; + if (boundaries[i].sound.getIsPlaying()) { + int r=b*boundaries[i].sound.getPosition(); + ofSetColor(r,0,b-r); + } + else ofSetColor(b,0,0); boundaries[i].draw(); } + /* + for (int i=0;i<clicks.size();i++) { + ofSetColor(0,0,255); + ofLine(clicks[i].x-2,clicks[i].y,clicks[i].x+2,clicks[i].y); + ofLine(clicks[i].x,clicks[i].y-2,clicks[i].x,clicks[i].y+2); + } + */ } //-------------------------------------------------------------- @@ -173,18 +192,9 @@ void testApp::keyPressed(int key){ } } -//-------------------------------------------------------------- -void testApp::sendNote(int note){ - ofxOscMessage m; - m.setAddress("/osc/midi/out/noteOn"); - m.addIntArg(channel); - m.addIntArg(note); - m.addIntArg(127); - m.addIntArg(1); - sender.sendMessage(m); - //printf("sent %i\n",note); +void testApp::volumeChanged(float &v){ + for (int i=0;i<boundaries.size();i++) boundaries[i].setVolume(v); } - //-------------------------------------------------------------- void testApp::keyReleased(int key){ @@ -202,8 +212,21 @@ void testApp::mouseDragged(int x, int y, int button){ //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ - boundaries[selectedBoundary].add(ofPoint(x,y,0)); - + switch (button) { + case 0: + boundaries[selectedBoundary].add(ofPoint(x,y,0)); + break; + case 1: + for (int i=0;i<boundaries.size();i++) { + if (boundaries[i].checkClick(ofPoint(x,y,0))) printf("playing %i: %s\n",i,boundaries[i].filename.c_str()); + } + break; + case 2: + for (int i=0;i<boundaries.size();i++) { + if (boundaries[i].contains(ofPoint(x,y,0))) selectedBoundary=i; + } + break; + } } //-------------------------------------------------------------- @@ -230,20 +253,19 @@ void testApp::dragEvent(ofDragInfo dragInfo) { int sta=dragInfo.files[0].find_last_of("\\/")+1; int len=(dragInfo.files[0].find_last_of(".")+4)-sta; string filename=dragInfo.files[0].substr(sta,len); - printf("loading %s\n",filename.c_str()); for (int i=0;i<boundaries.size();i++) { - boundaries[i].checkfile(dragInfo.position,filename); + if (boundaries[i].checkFile(dragInfo.position,filename)) printf("loaded %s into shape %i\n",filename.c_str(),i); } + //clicks.push_back(ofPoint(dragInfo.position.x,dragInfo.position.y,0)); } void testApp::loadSettings(string filename){ if( !XML.loadFile(filename) ){ printf("unable to load %s check data/ folder\n",filename.c_str()); }else{ - host=XML.getAttribute("figgis","host","127.0.0.1",0); - port=XML.getAttribute("figgis","port",5151,0); - channel=XML.getAttribute("figgis","channel",1,0); - bInvert=(XML.getAttribute("figgis","invert",0,0)==1); + flip=(XML.getAttribute("figgis","flip",0,0)==1); + invert=(XML.getAttribute("figgis","invert",0,0)==1); threshold = XML.getAttribute("figgis","threshold",80,0); + volume = XML.getAttribute("figgis","volume",1.0,0); if(XML.pushTag("boundaries")) { for (int i=0;i<XML.getNumTags("boundary");i++){ boundaries.push_back(boundary(XML.getAttribute("boundary","filename","",i))); @@ -261,7 +283,9 @@ void testApp::loadSettings(string filename){ } void testApp::saveSettings(string filename){ XML.setAttribute("figgis","invert",bInvert,0); + XML.setAttribute("figgis","flip",bFlip,0); XML.setAttribute("figgis","threshold",threshold,0); + XML.setAttribute("figgis","volume",volume,0); if (XML.tagExists("boundaries")) XML.removeTag("boundaries"); XML.addTag("boundaries"); if(XML.pushTag("boundaries")) { |
