diff options
| author | Comment <tim@gray.(none)> | 2013-01-28 12:42:36 +0000 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2013-01-28 12:42:36 +0000 |
| commit | f7667bd306b983f8f8daa0b40719aa665bf555b0 (patch) | |
| tree | 19ba166a2c1bd666471bf16f74e93228d8819f89 /src | |
| parent | 1f8525289c3533805fa235d25804f3413243743a (diff) | |
drag filenames into areas
Diffstat (limited to 'src')
| -rwxr-xr-x | src/boundary.cpp | 12 | ||||
| -rwxr-xr-x | src/boundary.h | 6 | ||||
| -rwxr-xr-x | src/main.cpp | 4 | ||||
| -rwxr-xr-x | src/testApp.cpp | 125 | ||||
| -rwxr-xr-x | src/testApp.h | 30 |
5 files changed, 112 insertions, 65 deletions
diff --git a/src/boundary.cpp b/src/boundary.cpp index c30f676..64957ed 100755 --- a/src/boundary.cpp +++ b/src/boundary.cpp @@ -2,12 +2,12 @@ boundary::boundary()
{
- note=40; //middle C
+ filename="";
}
-boundary::boundary(int _note)
+boundary::boundary(string file)
{
- note=_note;
+ filename=file;
}
boundary::~boundary()
@@ -20,7 +20,7 @@ void boundary::draw(){ for (int i=0;i<points.size();i++) {
ofLine(points[i],points[(i+1)%points.size()]);
}
- ofDrawBitmapString(ofToString(note),centroid);
+ ofDrawBitmapString(filename,centroid);
}
}
@@ -77,3 +77,7 @@ bool boundary::contains(ofPoint p) else
return true;
}
+
+void boundary::checkfile(ofPoint pos,string file) {
+ if (contains(pos)) filename=file;
+}
diff --git a/src/boundary.h b/src/boundary.h index a4ee28b..e28b278 100755 --- a/src/boundary.h +++ b/src/boundary.h @@ -9,17 +9,19 @@ class boundary {
public:
boundary();
- boundary(int _note);
+ boundary(string file);
virtual ~boundary();
bool contains(ofPoint p);
void draw();
void add(ofPoint p);
void undo();
- int note;
void getCentroid();
vector<ofPoint> points;
ofPoint centroid;
+
+ void checkfile(ofPoint pos,string file);
+ string filename;
};
diff --git a/src/main.cpp b/src/main.cpp index e922099..fca2408 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,11 +6,11 @@ int main( ){ ofAppGlutWindow window; - ofSetupOpenGL(&window, 720,576, OF_WINDOW); // <-------- setup the GL context + ofSetupOpenGL(ofxFensterManager::get(), 720,576, 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()); + ofRunFensterApp( new testApp()); } diff --git a/src/testApp.cpp b/src/testApp.cpp index d093497..1ca45e4 100755 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -1,69 +1,85 @@ #include "testApp.h" - //-------------------------------------------------------------- void testApp::setup(){ loadSettings("settings.xml"); //sender.setup(host.c_str(),port); - sender.setup("192.168.15.6",57117); - + sender.setup("169.254.113.20",57117); + bInvert=true; threshold = 80; // - + gw=720; gh=576; - + vidGrabber.setVerbose(true); - vidGrabber.initGrabber(gw,gh); //base grab size - + bool bGrab=false; + //vidGrabber.initGrabber(gw,gh); //base grab size + colorImg.allocate(gw,gh); grayImage.allocate(gw,gh); grayBg.allocate(gw,gh); grayDiff.allocate(gw,gh); - + mode=COLOUR; 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); + + //ofAddListener(win2->events.windowResized, this, &testApp::windowEvent); + + win2->setWindowTitle("config"); + win2->addListener(guiWin); + guiWin->setup(); + guiWin->setParent(this); + +*/ } //-------------------------------------------------------------- void testApp::update(){ - vidGrabber.grabFrame(); - bool bNewFrame = vidGrabber.isFrameNew(); - if (bNewFrame){ - colorImg.setFromPixels(vidGrabber.getPixels(), gw,gh); - if (bFlip) colorImg.mirror(false,true); - grayImage = colorImg; - if (bInvert) grayImage.invert(); - if (bLearnBakground == true){ - grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading) - bLearnBakground = false; - } - grayDiff.absDiff(grayBg, grayImage); - grayDiff.threshold(threshold); - contourFinder.findContours(grayDiff, 20, (gw*gh)/3, 10, true); // find holes - } - - //generate midi - - 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 (bGrab) { vidGrabber.grabFrame(); + bool bNewFrame = vidGrabber.isFrameNew(); + if (bNewFrame){ + colorImg.setFromPixels(vidGrabber.getPixels(), gw,gh); + if (bFlip) colorImg.mirror(false,true); + grayImage = colorImg; + if (bInvert) grayImage.invert(); + if (bLearnBakground == true){ + grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading) + bLearnBakground = false; + } + grayDiff.absDiff(grayBg, grayImage); + grayDiff.threshold(threshold); + contourFinder.findContours(grayDiff, 20, (gw*gh)/3, 10, true); // find holes + } + + //generate midi +/* + 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); + } + } + } + */ } - + } //-------------------------------------------------------------- @@ -80,11 +96,11 @@ void testApp::draw(){ grayDiff.draw(0,0,gw,gh); //(ofGetHeight()-gh)/2,gw,ofGetHeight()+((gh-ofGetHeight())/2)); break; } - + for (int i = 0; i < contourFinder.nBlobs; i++){ contourFinder.blobs[i].draw(0,0); //(ofGetHeight()-gh)/2); } - + for (int i=0;i<boundaries.size();i++) { if (selectedBoundary==i) ofSetColor(255,0,0); else ofSetColor(180,0,0); @@ -95,6 +111,12 @@ void testApp::draw(){ //-------------------------------------------------------------- void testApp::keyPressed(int key){ + //make in fenster, drag/drop support + //drag sound file onto a sound area, its name becomes name of area + //keys to play/stop (test) + //overall sound level control + //fine tune image detection + switch (key){ case ' ': bLearnBakground = true; @@ -134,18 +156,20 @@ void testApp::keyPressed(int key){ case OF_KEY_PAGE_DOWN: selectedBoundary=(selectedBoundary+1)%boundaries.size(); break; + /* case OF_KEY_LEFT: boundaries[selectedBoundary].note--; break; case OF_KEY_RIGHT: boundaries[selectedBoundary].note++; break; + */ case '1': case '2': case '3': mode=key-48; break; - + } } @@ -158,6 +182,7 @@ void testApp::sendNote(int note){ m.addIntArg(127); m.addIntArg(1); sender.sendMessage(m); + //printf("sent %i\n",note); } //-------------------------------------------------------------- @@ -197,8 +222,18 @@ void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- -void testApp::dragEvent(ofDragInfo dragInfo){ - +void testApp::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ + dragEvent(dragInfo); +} +void testApp::dragEvent(ofDragInfo dragInfo) { + printf("got draginfo: %f,%f,%f\n",dragInfo.position.x,dragInfo.position.y,dragInfo.position.z); + 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); + } } void testApp::loadSettings(string filename){ if( !XML.loadFile(filename) ){ @@ -211,7 +246,7 @@ void testApp::loadSettings(string filename){ threshold = XML.getAttribute("figgis","threshold",80,0); if(XML.pushTag("boundaries")) { for (int i=0;i<XML.getNumTags("boundary");i++){ - boundaries.push_back(boundary(XML.getAttribute("boundary","note",40,i))); + boundaries.push_back(boundary(XML.getAttribute("boundary","filename","",i))); selectedBoundary=boundaries.size()-1; XML.pushTag("boundary",i); for (int j=0;j<XML.getNumTags("point");j++){ @@ -232,7 +267,7 @@ void testApp::saveSettings(string filename){ if(XML.pushTag("boundaries")) { for (int i=0;i<boundaries.size();i++){ XML.addTag("boundary"); - XML.setAttribute("boundary","note",boundaries[i].note,i); + XML.setAttribute("boundary","filename",boundaries[i].filename,i); if(XML.pushTag("boundary",i)) { for (int j=0;j<boundaries[i].points.size();j++){ XML.addTag("point"); @@ -248,4 +283,4 @@ void testApp::saveSettings(string filename){ printf("saved %s\n",filename.c_str()); } void testApp::exit(){ -}
\ No newline at end of file +} diff --git a/src/testApp.h b/src/testApp.h index 9bcf15e..e154493 100755 --- a/src/testApp.h +++ b/src/testApp.h @@ -5,14 +5,18 @@ #include "boundary.h" #include "ofxXmlSettings.h" - +#include "ofxFensterManager.h" #include "ofxOsc.h" #define COLOUR 1 #define GREY 2 #define DIFF 3 -class testApp : public ofBaseApp{ +//12-10-12 +//each area will trigger once and once only + + +class testApp : public ofxFensterListener{ public: void setup(); @@ -28,23 +32,24 @@ class testApp : public ofBaseApp{ void mouseReleased(int x, int y, int button); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); + void dragEvent(ofDragInfo dragInfo, ofxFenster* win); void gotMessage(ofMessage msg); - + ofxXmlSettings XML; 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; - + ofxCvColorImage colorImg; ofxCvGrayscaleImage grayImage; @@ -52,16 +57,17 @@ class testApp : public ofBaseApp{ ofxCvGrayscaleImage grayDiff; ofxCvContourFinder contourFinder; - + int mode; int threshold; bool bLearnBakground; - + + bool bGrab; bool bFlip; bool bInvert; - + vector<boundary> boundaries; int selectedBoundary; - + }; |
