#include "testApp.h" //-------------------------------------------------------------- void testApp::setup(){ loadSettings("settings.xml"); //sender.setup(host.c_str(),port); sender.setup("192.168.15.6",57117); bInvert=true; threshold = 80; // gw=720; gh=576; vidGrabber.setVerbose(true); 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; } //-------------------------------------------------------------- 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 255) threshold = 255; break; case '-': threshold --; if (threshold < 0) threshold = 0; break; case 'i': bInvert=!bInvert; break; case 'f': bFlip=!bFlip; break; case 's': saveSettings("settings.xml"); break; case 'a': boundaries.push_back(boundary()); selectedBoundary=boundaries.size()-1; break; case 'z': boundaries[selectedBoundary].undo(); break; case 'q': boundaries.erase(boundaries.begin()+selectedBoundary); if (selectedBoundary==boundaries.size()) selectedBoundary=0; break; case OF_KEY_PAGE_UP: selectedBoundary--; if (selectedBoundary<0) selectedBoundary=boundaries.size()-1; break; 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; } } //-------------------------------------------------------------- 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); } //-------------------------------------------------------------- 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){ boundaries[selectedBoundary].add(ofPoint(x,y,0)); } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ } 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); threshold = XML.getAttribute("figgis","threshold",80,0); if(XML.pushTag("boundaries")) { for (int i=0;i