summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons.make2
-rwxr-xr-xbin/data/settings.xml61
-rw-r--r--figgis_detect.layout26
-rwxr-xr-xsrc/boundary.cpp32
-rwxr-xr-xsrc/boundary.h27
-rwxr-xr-xsrc/testApp.cpp134
-rwxr-xr-xsrc/testApp.h55
7 files changed, 227 insertions, 110 deletions
diff --git a/addons.make b/addons.make
index 4ad9634..68f9186 100644
--- a/addons.make
+++ b/addons.make
@@ -1,4 +1,4 @@
ofxOpenCv
ofxXmlSettings
-ofxOsc
ofxFenster
+ofxGui
diff --git a/bin/data/settings.xml b/bin/data/settings.xml
index cc22eb8..b18ba0c 100755
--- a/bin/data/settings.xml
+++ b/bin/data/settings.xml
@@ -1,14 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<figgis host="169.254.113.20" port="57117" channel="1" threshold="80" invert="1" />
+<figgis volume="0.368627" threshold="175" invert="0" flip="1" />
<boundaries>
- <boundary filename="five.wav">
- <point x="224.000000" y="79.000000"></point>
- <point x="281.000000" y="253.000000"></point>
- <point x="286.000000" y="421.000000"></point>
- <point x="86.000000" y="395.000000"></point>
- <point x="49.000000" y="94.000000"></point>
- </boundary>
- <boundary filename="four.wav">
+ <boundary filename="hook.wav">
<point x="645.000000" y="40.000000"></point>
<point x="414.000000" y="53.000000"></point>
<point x="374.000000" y="150.000000"></point>
@@ -16,11 +9,59 @@
<point x="637.000000" y="224.000000"></point>
<point x="676.000000" y="157.000000"></point>
</boundary>
- <boundary filename="one.wav">
+ <boundary filename="pus.wav">
<point x="651.000000" y="343.000000"></point>
<point x="447.000000" y="361.000000"></point>
<point x="318.000000" y="536.000000"></point>
<point x="681.000000" y="536.000000"></point>
<point x="678.000000" y="401.000000"></point>
</boundary>
+ <boundary filename="bigs.wav">
+ <point x="47.000000" y="38.000000"></point>
+ <point x="91.000000" y="38.000000"></point>
+ <point x="97.000000" y="95.000000"></point>
+ <point x="47.000000" y="97.000000"></point>
+ <point x="42.000000" y="55.000000"></point>
+ </boundary>
+ <boundary filename="cloaks.wav">
+ <point x="95.000000" y="122.000000"></point>
+ <point x="42.000000" y="125.000000"></point>
+ <point x="39.000000" y="239.000000"></point>
+ <point x="115.000000" y="239.000000"></point>
+ <point x="111.000000" y="153.000000"></point>
+ </boundary>
+ <boundary filename="pins.wav">
+ <point x="153.000000" y="266.000000"></point>
+ <point x="41.000000" y="264.000000"></point>
+ <point x="35.000000" y="537.000000"></point>
+ <point x="273.000000" y="546.000000"></point>
+ <point x="259.000000" y="391.000000"></point>
+ </boundary>
+ <boundary filename="bosie.wav">
+ <point x="171.000000" y="33.000000"></point>
+ <point x="134.000000" y="33.000000"></point>
+ <point x="136.000000" y="81.000000"></point>
+ <point x="175.000000" y="81.000000"></point>
+ <point x="178.000000" y="62.000000"></point>
+ </boundary>
+ <boundary filename="loop.wav">
+ <point x="182.000000" y="110.000000"></point>
+ <point x="153.000000" y="111.000000"></point>
+ <point x="151.000000" y="132.000000"></point>
+ <point x="180.000000" y="139.000000"></point>
+ </boundary>
+ <boundary filename="six.wav">
+ <point x="190.000000" y="164.000000"></point>
+ <point x="136.000000" y="152.000000"></point>
+ <point x="136.000000" y="206.000000"></point>
+ <point x="193.000000" y="233.000000"></point>
+ <point x="209.000000" y="202.000000"></point>
+ </boundary>
+ <boundary filename="friends.wav">
+ <point x="184.000000" y="257.000000"></point>
+ <point x="275.000000" y="369.000000"></point>
+ <point x="269.000000" y="240.000000"></point>
+ <point x="224.000000" y="222.000000"></point>
+ <point x="212.000000" y="246.000000"></point>
+ </boundary>
</boundaries>
diff --git a/figgis_detect.layout b/figgis_detect.layout
index 0e77965..ec2556a 100644
--- a/figgis_detect.layout
+++ b/figgis_detect.layout
@@ -2,27 +2,27 @@
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
<File name="addons.make" open="0" top="0" tabpos="3">
- <Cursor position="42" topLine="0" />
+ <Cursor position="24" topLine="0" />
</File>
- <File name="bin/data/settings.xml" open="1" top="0" tabpos="2">
- <Cursor position="163" topLine="0" />
+ <File name="bin/data/settings.xml" open="1" top="0" tabpos="5">
+ <Cursor position="506" topLine="0" />
</File>
<File name="config.make" open="0" top="0" tabpos="1">
<Cursor position="376" topLine="18" />
</File>
- <File name="src/boundary.cpp" open="1" top="0" tabpos="3">
- <Cursor position="1538" topLine="47" />
+ <File name="src/boundary.cpp" open="1" top="0" tabpos="4">
+ <Cursor position="1826" topLine="71" />
</File>
- <File name="src/boundary.h" open="0" top="0" tabpos="1">
- <Cursor position="267" topLine="0" />
+ <File name="src/boundary.h" open="1" top="0" tabpos="6">
+ <Cursor position="484" topLine="0" />
</File>
- <File name="src/main.cpp" open="0" top="0" tabpos="0">
- <Cursor position="430" topLine="0" />
+ <File name="src/main.cpp" open="1" top="0" tabpos="1">
+ <Cursor position="437" topLine="0" />
</File>
- <File name="src/testApp.cpp" open="1" top="1" tabpos="1">
- <Cursor position="6071" topLine="201" />
+ <File name="src/testApp.cpp" open="1" top="1" tabpos="3">
+ <Cursor position="3433" topLine="98" />
</File>
- <File name="src/testApp.h" open="0" top="0" tabpos="4">
- <Cursor position="1313" topLine="0" />
+ <File name="src/testApp.h" open="1" top="0" tabpos="2">
+ <Cursor position="1904" topLine="0" />
</File>
</CodeBlocks_layout_file>
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();
};
+