Skip to content

Instantly share code, notes, and snippets.

@indefinit
Last active August 29, 2015 14:16
Show Gist options
  • Save indefinit/132fc6084e734b490d6c to your computer and use it in GitHub Desktop.
Save indefinit/132fc6084e734b490d6c to your computer and use it in GitHub Desktop.
Test for Osc Blob Listener in Cinder
/*
Copyright (c) 2010, Hector Sanchez-Pajares
Aer Studio http://www.aerstudio.com
All rights reserved.
modified for Blobs by Indefinit, Kevin Siwoff, 2015
This is a block for OSC Integration for Cinder framework developed by The Barbarian Group, 2010
Redistribution and use in source and binary forms, with or without modification, are permitted provided that
the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and
the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include "cinder/app/AppNative.h"
using namespace ci;
using namespace ci::app;
#include "OscListener.h"
class OSCListenerBlobApp : public AppNative {
public:
void setup();
void update();
void draw();
osc::Listener listener;
float positionX;
};
void OSCListenerBlobApp::setup()
{
listener.setup( 3000 );
positionX = 0;
}
void OSCListenerBlobApp::update()
{
while( listener.hasWaitingMessages() ) {
osc::Message message;
listener.getNextMessage( &message );
console() << "New message received" << std::endl;
console() << "Address: " << message.getAddress() << std::endl;
console() << "Num Arg: " << message.getNumArgs() << std::endl;
for (int i = 0; i < message.getNumArgs(); i++) {
console() << "-- Argument " << i << std::endl;
console() << "---- type: " << message.getArgTypeName(i) << std::endl;
if( message.getArgType(i) == osc::TYPE_BLOB) {
try {
console() << "------ value: " << message.getArgAsBlob(i) << std::endl;
//create a new IStream ref from our Buffer
IStreamMemRef stream = IStreamMem::create( message.getArgAsBlob(i).getData(), message.getArgAsBlob(i).getDataSize() );
while( ! stream->isEof() ){
std::cout << stream << std::endl;
//unsigned char data[stream->size()];
//stream->readData((char*) &data[0], stream->size());
//for (unsigned char &component : data) {
//@TODO
//do something with each component here
//std::cout<< component << std::endl;
//}
}
}
catch (...) {
console() << "Exception reading argument as blob" << std::endl;
}
}
}
}
}
void OSCListenerBlobApp::draw()
{
gl::clear();
gl::color( Color::white() );
gl::drawSolidRect( Rectf(Vec2f(0, 0), Vec2f(0.5f * getWindowWidth(), 0.5f * getWindowHeight())) );
}
CINDER_APP_NATIVE( OSCListenerBlobApp, RendererGl )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment