Created
September 25, 2016 23:20
-
-
Save eighteight/979fcac277a6b429c42235ca17727ce7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cinder/app/App.h" | |
#include "cinder/app/RendererGl.h" | |
#include "cinder/gl/gl.h" | |
#include "cinder/Log.h" | |
#include "cinder/Timeline.h" | |
#include "cinder/osc/Osc.h" | |
using namespace ci; | |
using namespace ci::app; | |
using namespace std; | |
#define USE_UDP 1 | |
#if USE_UDP | |
using Receiver = osc::ReceiverUdp; | |
#else | |
using Receiver = osc::ReceiverTcp; | |
#endif | |
class SimpleReceiverApp : public App { | |
public: | |
SimpleReceiverApp(); | |
void setup() override; | |
void draw() override; | |
void keyDown(KeyEvent) override; | |
ivec2 mCurrentCirclePos; | |
vec2 mCurrentSquarePos; | |
bool mMouseDown = false; | |
std::unique_ptr<Receiver> mReceiver; | |
}; | |
SimpleReceiverApp::SimpleReceiverApp() | |
{ | |
} | |
void SimpleReceiverApp::keyDown(KeyEvent e) | |
{ | |
mReceiver.reset(); | |
setup(); | |
} | |
void SimpleReceiverApp::setup() | |
{ | |
mReceiver = std::make_unique<Receiver>(3000); | |
mReceiver->setListener( "/mousemove/1", | |
[&]( const osc::Message &msg ){ | |
mCurrentCirclePos.x = msg[0].int32(); | |
mCurrentCirclePos.y = msg[1].int32(); | |
}); | |
mReceiver->setListener( "/mouseclick/1", | |
[&]( const osc::Message &msg ){ | |
mCurrentSquarePos = vec2( msg[0].flt(), msg[1].flt() ) * vec2( getWindowSize() ); | |
}); | |
mReceiver->bind(); | |
mReceiver->listen(); | |
} | |
void SimpleReceiverApp::draw() | |
{ | |
gl::clear( GL_COLOR_BUFFER_BIT ); | |
gl::setMatricesWindow( getWindowSize() ); | |
gl::drawStrokedCircle( mCurrentCirclePos, 100 ); | |
gl::drawSolidRect( Rectf( mCurrentSquarePos - vec2( 50 ), mCurrentSquarePos + vec2( 50 ) ) ); | |
} | |
auto settingsFunc = []( App::Settings *settings ) { | |
#if defined( CINDER_MSW ) | |
settings->setConsoleWindowEnabled(); | |
#endif | |
settings->setMultiTouchEnabled( false ); | |
}; | |
CINDER_APP( SimpleReceiverApp, RendererGl, settingsFunc ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So the fix is a bit more involved and there's already an enormous update to the osc block waiting to be merged, which I will put this change into as well. For now, if you just poll the io_service after a close and before you reset the pointer everything seems to work fine. Replace the above keyDown function with this...
...and you should be good to go. I'll try and get everything merged in ASAP.