summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/testApp.cpp102
-rw-r--r--src/testApp.h28
2 files changed, 123 insertions, 7 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp
index dff1f18..a7b90d1 100644
--- a/src/testApp.cpp
+++ b/src/testApp.cpp
@@ -66,6 +66,10 @@ void testApp::setup(){
ofAddListener(ard.EInitialized, this, &testApp::setupArduino);
bSetupArduino = false;
bSwitchArduino = false;
+
+ //----------------avahi stuff
+ avahiService.start("ofMrmr","_mrmrsrvr._udp",1337);
+ oscReceiver.setup(1337); //default mrmr port
}
@@ -93,6 +97,9 @@ void testApp::update(){
}
}
updateArduino();
+
+ //----------------avahi stuff
+ ProcessMessages();
}
//--------------------------------------------------------------
@@ -139,6 +146,81 @@ void testApp::updateArduino(){
}
}
+bool startswith(const char* _str1, const char* _start){
+ for(int i=0;_start[i]>0;i++){
+ if(_str1[i]!=_start[i])
+ return false;
+ }
+ return true;
+}
+
+void testApp::SendInterface(std::string targetIP, std::string interfaceString){
+
+ /* Example:
+ "/mrmrIB mrmr_clear_all\n"\
+ "/mrmrIB tactilezone nil .1 1 10 1 2 1 9 _ 2\n"\
+ "/mrmrIB textinputview nil .1 1 10 1 1 1 1 placeholder_text_for_textinput_field\n"*/
+
+ tcpClient.close(); //just open a fresh socket to do this one-time setup/send to the new client
+ tcpClient.setup(targetIP,31337);
+
+ printf("Sending interface...\n");
+
+ int count = interfaceString.length();
+ tcpClient.sendRawBytes(interfaceString.c_str(),count); //don't use send() as it appends [/TCP] tag, which screws up mrmr client
+}
+
+void testApp::ProcessMessages(){
+
+ while( oscReceiver.hasWaitingMessages() )
+
+
+ {
+
+ // get the next message
+ ofxOscMessage m;
+ oscReceiver.getNextMessage( &m );
+ std::string messageAddress = m.getAddress();
+
+ printf("Message: %s\n",messageAddress.c_str());
+
+ std::string rip = m.getRemoteIp();
+ int rp = m.getRemotePort();
+ std::string arg1;
+
+ if(messageAddress.compare("/mrmr connect")==0){
+ SendInterface(rip,
+ "/mrmrIB mrmr_clear_all\n"\
+ "/mrmrIB titleview nil .1 1 10 1 1 1 1 StrongbowDemo 3"\
+ "/mrmrIB pushbutton nil .1 2 10 1 6 1 1 < 11\n"\
+ "/mrmrIB pushbutton nil .1 2 10 1 6 1 1 < 11\n"\
+ "/mrmrIB pushbutton nil .1 2 10 2 6 1 1 > 11\n"
+ );
+ }
+ else
+ {
+ int ls = messageAddress.find_last_of("/");
+ int msg=-1;
+
+ if(m.getNumArgs()) msg=m.getArgAsInt32( 0 );
+
+ if(startswith(messageAddress.c_str(),"/mrmr/pushbutton/1"))
+ {
+ printf("previous movie %i\n",msg);
+ if (msg) prevMovie();
+ }
+ if(startswith(messageAddress.c_str(),"/mrmr/pushbutton/2"))
+ {
+ printf("next movie %i\n",msg);
+ if (msg) nextMovie();
+ }
+
+ }
+ }
+}
+
+
+
//--------------------------------------------------------------
void testApp::draw(){
for (int i=0;i<numViews;i++) {
@@ -237,16 +319,11 @@ void testApp::keyPressed(int key){
break;
case ',':
case '<':
- whichClip--;
- if (whichClip<1) whichClip=numClips-1;
- transTime=ofGetElapsedTimef()+1.0;
- transition=true;
+ prevMovie();
break;
case '.':
case '>':
- whichClip=max(1,(whichClip+1)%numClips);
- transTime=ofGetElapsedTimef()+1.0;
- transition=true;
+ nextMovie();
break;
case '/':
light=!light;
@@ -258,6 +335,17 @@ void testApp::keyPressed(int key){
break;
}
}
+void testApp::prevMovie(){
+ whichClip--;
+ if (whichClip<1) whichClip=numClips-1;
+ transTime=ofGetElapsedTimef()+1.0;
+ transition=true;
+}
+void testApp::nextMovie(){
+ whichClip=max(1,(whichClip+1)%numClips);
+ transTime=ofGetElapsedTimef()+1.0;
+ transition=true;
+}
void testApp::doTransition(){
if (transition) {
if (ofGetElapsedTimef()>transTime) {
diff --git a/src/testApp.h b/src/testApp.h
index 293b6fd..1bf2d7b 100644
--- a/src/testApp.h
+++ b/src/testApp.h
@@ -34,6 +34,14 @@ have to track how many frames each key has been pressed for
#include "mapUtils.h"
#include "viewpoint.h"
+#define OF_ADDON_USING_OFXAVAHI
+
+//#include "ofxAvahiCoreBrowser.h"
+#include "ofxAvahiClient.h"
+
+#include "ofxOsc.h"
+#include "ofxNetwork.h"
+
class testApp : public ofBaseApp{
public:
@@ -57,6 +65,9 @@ class testApp : public ofBaseApp{
void doTransition();
float transTime;
bool transition;
+
+ void prevMovie();
+ void nextMovie();
string model_name;
float model_x;
@@ -95,5 +106,22 @@ class testApp : public ofBaseApp{
ofArduino ard;
bool bSetupArduino; // flag variable for setting up arduino once
int bSwitchArduino;
+
+ //----------------avahi stuff
+
+ ofxAvahiClientService avahiService;
+
+ ofxTCPClient tcpClient;
+ ofxOscReceiver oscReceiver;
+
+ void SendInterface(std::string targetIP, std::string interfaceString);
+
+ bool hasWaitingMessages(){
+ return oscReceiver.hasWaitingMessages();
+ }
+ void getNextMessage(ofxOscMessage* m){
+ oscReceiver.getNextMessage(m);
+ }
+ void ProcessMessages();
};