diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/boundary.cpp | 32 | ||||
| -rwxr-xr-x | src/boundary.h | 27 | ||||
| -rwxr-xr-x | src/testApp.cpp | 134 | ||||
| -rwxr-xr-x | src/testApp.h | 55 |
4 files changed, 162 insertions, 86 deletions
diff --git a/src/boundary.cpp b/src/boundary.cpp index 64957ed..2425c4a 100755 --- a/src/boundary.cpp +++ b/src/boundary.cpp @@ -5,9 +5,10 @@ boundary::boundary() filename="";
}
-boundary::boundary(string file)
+boundary::boundary(string file,float vol)
{
- filename=file;
+ openFile(file);
+ sound.setVolume(vol);
}
boundary::~boundary()
@@ -77,7 +78,28 @@ bool boundary::contains(ofPoint p) else
return true;
}
-
-void boundary::checkfile(ofPoint pos,string file) {
- if (contains(pos)) filename=file;
+void boundary::openFile(string file) {
+ filename=file;
+ if (filename.length()>0) {
+ if (sound.loadSound(filename)) sound.setLoop(false);
+ else printf("failed to load %s\n",filename.c_str());
+ }
+}
+bool boundary::checkFile(ofPoint pos,string file) {
+ if (contains(pos)) { + sound.stop(); + openFile(file); + return true; + } + else return false;
+}
+bool boundary::checkClick(ofPoint pos){
+ if (contains(pos)&&sound.isLoaded()&&!sound.getIsPlaying()) { + sound.play(); + return true; + } + else return false;
}
+void boundary::setVolume(float vol){
+ sound.setVolume(vol);
+} diff --git a/src/boundary.h b/src/boundary.h index e28b278..bf0b780 100755 --- a/src/boundary.h +++ b/src/boundary.h @@ -9,19 +9,22 @@ class boundary {
public:
boundary();
- boundary(string file);
+ boundary(string file,float vol=1.0f);
virtual ~boundary();
- bool contains(ofPoint p);
- void draw();
- void add(ofPoint p);
- void undo();
- void getCentroid();
- vector<ofPoint> points;
- ofPoint centroid;
-
- void checkfile(ofPoint pos,string file);
-
- string filename;
+ bool contains(ofPoint p);
+ void draw();
+ void add(ofPoint p);
+ void undo();
+ void getCentroid();
+ vector<ofPoint> points;
+ ofPoint centroid;
+ bool checkClick(ofPoint pos);
+ bool checkFile(ofPoint pos,string file);
+ void openFile(string file);
+ void setVolume(float vol);
+
+ string filename;
+ ofSoundPlayer sound;
};
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")) { diff --git a/src/testApp.h b/src/testApp.h index e154493..bea746c 100755 --- a/src/testApp.h +++ b/src/testApp.h @@ -6,15 +6,22 @@ #include "boundary.h" #include "ofxXmlSettings.h" #include "ofxFensterManager.h" -#include "ofxOsc.h" +#include "ofxGui.h" #define COLOUR 1 #define GREY 2 #define DIFF 3 //12-10-12 -//each area will trigger once and once only +//each area will trigger 'once and once only' ? +//overall: +// +//tweak opencv stuff +//test performance + + +class guiWindow; class testApp : public ofxFensterListener{ @@ -39,13 +46,6 @@ class testApp : public ofxFensterListener{ void loadSettings(string filename); void saveSettings(string filename); - //destination for OSC - std::string host; - int port,channel; - ofxOscSender sender; - - void sendNote(int note); - ofVideoGrabber vidGrabber; int gw,gh; @@ -60,14 +60,41 @@ class testApp : public ofxFensterListener{ int mode; - int threshold; bool bLearnBakground; - - bool bGrab; - bool bFlip; - bool bInvert; + bool flip,invert; + + guiWindow *guiWin; + ofxPanel gui; + ofxFloatSlider vol; + ofxParameter<float> volume; + ofxToggle bFlip; + ofxToggle bInvert; + ofxIntSlider thresh; + ofxParameter<int> threshold; + + // register any method of any class to an event. + // the method must provide one of the following + // signatures: + // void method(ArgumentsType & args) + // void method(const void * sender, ArgumentsType &args) + // ie: + // ofAddListener(addon.newIntEvent, this, &Class::method) + void volumeChanged(float &v); + + bool bGrab; vector<boundary> boundaries; int selectedBoundary; + vector<ofPoint> clicks; +}; + +class guiWindow: public ofxFensterListener{ +public: + ~guiWindow(); + testApp *parent; + void setup(); + void setParent(testApp *p); + void draw(); }; + |
