summaryrefslogtreecommitdiff
path: root/src/testApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/testApp.cpp')
-rwxr-xr-xsrc/testApp.cpp125
1 files changed, 80 insertions, 45 deletions
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
+}