ofxTuioClient - having trouble with events

Hello,

I am trying to write a very simple application that uses ofxTuioWrapper to capture touch events. It seems that the events are being fired from within ofxTuioClient, but I cannot capture them via ofEvents.touchDown in my testApp.cpp. I cannot get the eventhandlers in testApp.cpp to fire when an cursor is added or removed.

I understand the the touch events are being forwarded to a main application delegate via ofNotifyEvent() from with ofxTuioClient, but there seems to be some disconnect as the events are never received by the handlers in testApp.cpp.

Anyone know what I might be missing? Thanks in advance!

Here’s my code:

testApp.h

  
#ifndef _TEST_APP  
#define _TEST_APP  
  
#include "ofMain.h"  
#include "ofxTuioClient.h"  
#include "ofxVectorGraphics.h"  
  
class testApp : public ofBaseApp{  
	  
public:  
	void setup();  
	void update();  
	void draw();  
	  
	void keyPressed  (int key);  
	void keyReleased(int key);  
	void mouseMoved(int x, int y );  
	void mouseDragged(int x, int y, int button);  
	void mousePressed(int x, int y, int button);  
	void mouseReleased(int x, int y, int button);  
	void windowResized(int w, int h);  
	  
	ofxTuioClient myTuio;  
	  
	ofxVectorGraphics output;  
	bool capture;  
	bool bFill;  
	  
	vector <ofPoint> pts;  
	  
	void touchDown(ofTouchEventArgs & touch);  
	void touchUp(ofTouchEventArgs & touch);  
	void touchMoved(ofTouchEventArgs & touch);  
	void touchDoubleTap(ofTouchEventArgs & touch);  
	  
};  
  
#endif  

testApp.cpp - code is truncated for brevity

  
#include "testApp.h"  
  
void testApp::setup(){  
	  
	ofBackground(0, 0, 0);  
	  
	myTuio.setVerbose(false);  
	  
	//Connect to Port  
	myTuio.connect(3333);  
	  
	ofRegisterTouchEvents(this);  
	  
	//Assign Global TUIO Callback Functions  
	ofAddListener(ofEvents.touchDown,this,&testApp::touchDown);  
	ofAddListener(ofEvents.touchUp,this,&testApp::touchUp);  
	ofAddListener(ofEvents.touchMoved,this,&testApp::touchMoved);  
	ofAddListener(ofEvents.touchDoubleTap,this,&testApp::touchDoubleTap);  
}  
  
void testApp::touchDown(ofTouchEventArgs & touch){  
	  
	pts.clear();  
	  
	//lets store the first point of the line  
	pts.push_back(ofPoint());  
	pts[0].x = touch.x;  
	pts[0].y = touch.y;  
	  
	cout << " cursor added: " + ofToString(touch.id)+  
	" X: "+ofToString(touch.x)+  
	" Y: "+ofToString(touch.y)  
	<< endl;  
	  
	  
}  
  
void testApp::touchUp(ofTouchEventArgs & touch){  
	cout << " cursor removed: " + ofToString(touch.id)+  
	" X: "+ofToString(touch.x)+  
	" Y: "+ofToString(touch.y)  
	<< endl;  
	  
}  
  
void testApp::touchMoved(ofTouchEventArgs & touch){  
	  
	//we add a new point to our line  
	pts.push_back(ofPoint());  
	int last = pts.size()-1;  
	  
	pts[last].x = touch.x;  
	pts[last].y = touch.y;  
	  
	cout << " cursor updated: " + ofToString(touch.id)+  
	" X: "+ofToString(touch.x)+  
	" Y: "+ofToString(touch.y)  
	<< endl;  
}  
  
void testApp::touchDoubleTap(ofTouchEventArgs & touch){  
	cout << " Double Tap!: " + ofToString(touch.id)+  
	" X: "+ofToString(touch.x)+  
	" Y: "+ofToString(touch.y)  
	<< endl;  
	  
}  
  

Ok, so after messing around with this I discovered that I could get it to work by adding eventlisteners directly to the ofxTuioClient instance rather than the main app. Maybe this is the way it’s supposed to be done… At a certain point, things start to get real confusing.

testApp.cpp

  
void testApp::setup(){  
	  
	ofBackground(0, 0, 0);  
	//ofSetVerticalSync(true);  
	  
	myTuio.setVerbose(true);  
	  
	//Connect to Port  
	myTuio.connect(3333);  
	  
	//Assign Global TUIO Callback Functions  
	ofAddListener(myTuio.objectAdded,this,&testApp::tuioObjectAdded);  
	ofAddListener(myTuio.objectRemoved,this,&testApp::tuioObjectRemoved);  
	ofAddListener(myTuio.objectUpdated,this,&testApp::tuioObjectUpdated);  
	ofAddListener(myTuio.cursorAdded,this,&testApp::tuioCursorAdded);  
	ofAddListener(myTuio.cursorRemoved,this,&testApp::tuioCursorRemoved);  
	ofAddListener(myTuio.cursorUpdated,this,&testApp::tuioCursorUpdated);  
}  

the last way is the way I got it to work as well

I’m amazed that you’re getting this to work. Right now, I’ve got to the point where either I do:

  
ofAddListener(ofEvents.touchDown,this,&testApp::touchDown);  
ofAddListener(ofEvents.touchUp,this,&testApp::touchUp);  
ofAddListener(ofEvents.touchMoved,this,&testApp::touchMoved);  
ofAddListener(ofEvents.touchCancelled,this,&testApp::touchCancelled);  
ofAddListener(ofEvents.touchDoubleTap,this,&testApp::touchDoubleTap);  

…and get no compiler errors (but also no action from the listener methods) or I do:

  
ofAddListener(ofEvents.touchDown,this,&testApp::touchDown);  
ofAddListener(myTuio.touchUp,this,&testApp::touchUp);  
ofAddListener(myTuio.touchMoved,this,&testApp::touchMoved);  
ofAddListener(myTuio.touchCancelled,this,&testApp::touchCancelled);  
ofAddListener(myTuio.touchDoubleTap,this,&testApp::touchDoubleTap);  

Which produces the bizarre compiler error:

…/…/…/libs/openFrameworks/events/ofEventUtils.h:39:0 …/…/…/libs/openFrameworks/events/ofEventUtils.h:39: error: no match for ‘operator+=’ in ‘event += Poco::delegate(TObj*, void (TObj::*)(TArgs&)) with-TObj-=-testApp,-TArgs-=-ofTouchEventArgs

How to win?

take a look at the events in your version of the tuio wrapper, they are probably something like:

  
ofEvent<ofxTuioCursor>...  

so your functions need to be:

  
void touchDown(ofxTuioCursor & cursor)  

instead of:

  
void touchDown(ofTouchEventArgs & cursor)  

Hmm that seems reasonable. Except that when I declare function like that, I simply get an error message “ofxTuioCursor has not been declared”. Am I missing a library here?

OK, I’ve found the ofxTuio addon and put that in, so getting closer now…

Now I have the following error:

…/…/…/libs/openFrameworks/events/ofEventUtils.h:39:0 …/…/…/libs/openFrameworks/events/ofEventUtils.h:39: error: no match for ‘operator+=’ in ‘event += Poco::delegate(TObj*, void (TObj::*)(TArgs&)) with-TObj-=-testApp,-TArgs-=-ofxTuioCursor

So something going wrong with a declaration in Poco? Huh?

Sorry to keep piling up the messages here… Perhaps I am missing something crucial. The version of ofxTuioWrapper that I have includes a bunch of source files under “core”, named for example “TuioCursor.h”, “TuioClient.h”, etc. And yet there are also the ones starting with ofX, e.g. “ofxTuioClient.h”. But there are ALSO similar source files in the ofxTuio addon…

Am I getting all these mixed up?

I feel like I’m so close now…

In testapp.cpp, I’ve got:

  
  
ofAddListener(myTuio.touchDown,this,&testApp::touchDown);    
ofAddListener(myTuio.touchUp,this,&testApp::touchUp);    
ofAddListener(myTuio.touchMoved,this,&testApp::touchMoved);    
  

With functions such as:

  
  
void testApp::touchDown(ofxTuioCursor & touch) {}  
void testApp::touchUp(ofxTuioCursor & touch){}  
void testApp::touchMoved(ofxTuioCursor & touch){}  
  

And then in ofxTuioClient.h, I’ve got the following:

  
  
	ofEvent<ofxTuioCursor> touchUp;  
	ofEvent<ofxTuioCursor> touchDown;  
	ofEvent<ofxTuioCursor> touchMoved;  
  

So should be all good, right?

But I get the following compiler error:

…/…/…/libs/openFrameworks/events/ofEventUtils.h:73:0 …/…/…/libs/openFrameworks/events/ofEventUtils.h:73: error: no matching function for call to ‘ofEvent::notify(ofxTuioClient*&, TUIO::TuioCursor&)’

So something’s still not right…

that seems like a problem in the addon, cannot do it right now, but will take a look at my version and update it with an example working properly