// Process incoming OSC. Used for Kyma communication. // void SoundplaneModel::ProcessMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { osc::ReceivedMessageArgumentStream args = m.ArgumentStream(); osc::int32 a1; try { if( std::strcmp( m.AddressPattern(), "/osc/response_from" ) == 0 ) { args >> a1 >> osc::EndMessage; // set Kyma mode if (mOSCOutput.getKymaMode()) { mKymaIsConnected = true; } } else if (std::strcmp( m.AddressPattern(), "/osc/notify/midi/Soundplane" ) == 0 ) { args >> a1 >> osc::EndMessage; // set voice count to a1 int newTouches = clamp((int)a1, 0, kSoundplaneMaxTouches); if(mKymaIsConnected) { // Kyma is sending 0 sometimes, which there is probably // no reason to respond to if(newTouches > 0) { setProperty("max_touches", newTouches); } } }
//get OSC message void OscInput::ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint ) { try { if( strcmp( m.AddressPattern(), "/alpha" ) == 0 ) { osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); int recievedPad = (arg++)->AsInt32(); int recievedValue = (arg++)->AsInt32(); if( arg != m.ArgumentsEnd() ) throw osc::ExcessArgumentException(); recievedPad = Layouts::padArrangementLayout[recievedPad]; //call callback function oscCallBack(recievedPad, recievedValue); } } catch( osc::Exception& e ) { // any parsing errors such as unexpected argument types, or // missing arguments get thrown as exceptions. std::cout << "error while parsing message: " << m.AddressPattern() << ": " << e.what() << "\n"; } }
void BitalinoPacketListener::ProcessMessage( const osc::ReceivedMessage& m ) { try{ if( std::strcmp( m.AddressPattern(), "/wek/inputs" ) == 0 ){ osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); float emg = (arg++)->AsFloat(); float emgFilt = (arg++)->AsFloat(); float eda = (arg++)->AsFloat(); this->emgBuffer[this->curEmgBuffIdx++] = emgFilt; if (this->curEmgBuffIdx >= BUFFER_SIZE) { this->curEmgBuffIdx = 0; } this->emgStd = minMax(this->emgBuffer, BUFFER_SIZE); float ecg = (arg++)->AsFloat(); this->accelMean =(arg++)->AsFloat(); this->lux = (arg++)->AsFloat(); //std::cout << "emg: " << emg << " emgfilt: " << emgFilt << " eda: " << eda << " ecg: " << ecg << " accel: " << accel << " lux: " << lux << '\n'; } }catch( osc::Exception& e ){ // any parsing errors such as unexpected argument types, or // missing arguments get thrown as exceptions. std::cout << "error while parsing message: " << m.AddressPattern() << ": " << e.what() << "\n"; } }
void ofxOscReceiver::ProcessMessage( const osc::ReceivedMessage &m, const osc::IpEndpointName& remoteEndpoint ) { // convert the message to an ofxOscMessage ofxOscMessage msg; // set the address msg.setAddress( m.AddressPattern() ); // set the sender ip/host char endpoint_host[ osc::IpEndpointName::ADDRESS_STRING_LENGTH ]; remoteEndpoint.AddressAsString( endpoint_host ); msg.setRemoteEndpoint( endpoint_host, remoteEndpoint.port ); // transfer the arguments for ( osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); arg != m.ArgumentsEnd(); ++arg ) { if ( arg->IsInt32() ) msg.addIntArg( arg->AsInt32Unchecked() ); else if ( arg->IsInt64() ) msg.addInt64Arg( arg->AsInt64Unchecked() ); else if ( arg->IsFloat() ) msg.addFloatArg( arg->AsFloatUnchecked() ); else if ( arg->IsDouble() ) msg.addDoubleArg( arg->AsDoubleUnchecked() ); else if ( arg->IsString() ) msg.addStringArg( arg->AsStringUnchecked() ); else if ( arg->IsSymbol() ) msg.addSymbolArg( arg->AsSymbolUnchecked() ); else if ( arg->IsChar() ) msg.addCharArg( arg->AsCharUnchecked() ); else if ( arg->IsMidiMessage() ) msg.addMidiMessageArg( arg->AsMidiMessageUnchecked() ); else if ( arg->IsBool()) msg.addBoolArg( arg->AsBoolUnchecked() ); else if ( arg->IsInfinitum() ) msg.addTriggerArg(); else if ( arg->IsTimeTag() ) msg.addTimetagArg( arg->AsTimeTagUnchecked() ); else if ( arg->IsRgbaColor() ) msg.addRgbaColorArg( arg->AsRgbaColorUnchecked() ); else if ( arg->IsBlob() ){ const char * dataPtr; osc::osc_bundle_element_size_t len = 0; arg->AsBlobUnchecked((const void*&)dataPtr, len); ofBuffer buffer(dataPtr, len); msg.addBlobArg( buffer ); } else { ofLogError("ofxOscReceiver") << "ProcessMessage: argument in message " << m.AddressPattern() << " is not an int, float, or string"; } } // send msg to main thread messagesChannel.send( std::move(msg) ); }
void MyPacketListener::ProcessMessage(const osc::ReceivedMessage &m, const IpEndpointName &remoteEndpoint) { (void) remoteEndpoint; try { auto args = m.ArgumentStream(); const char* msg; args >> msg >> osc::EndMessage; emit parent_->message(m.AddressPattern(), msg); } catch (const osc::Exception& e) { std::cerr << "[OSCReceiver] Error while parsing process message." << std::endl; std::cerr << m.AddressPattern() << ": " << e.what() << std::endl; } }
void ReceiveOSCThread::ProcessMessage(const osc::ReceivedMessage&m, const IpEndpointName& remoteEndPoint) { std::ostringstream oss; if ((m.AddressPattern())[0] == '/') { m_minuitMethods->receiveNetworkMessage(m.AddressPattern()); } else { std::string currentString(m.AddressPattern()); if (currentString.find(":namespace") != currentString.npos) { osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); if (arg->IsChar()) { oss << arg->AsChar(); } else if (arg->IsInt32()) { oss << arg->AsInt32(); } else if (arg->IsString()) { oss << arg->AsString(); } m_minuitMethods->minuitParseNamespaceRequest(oss.str(), m); } else if (currentString.find(":get") != currentString.npos) { osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); if (arg->IsChar()) { oss << arg->AsChar(); } else if (arg->IsInt32()) { oss << arg->AsInt32(); } else if (arg->IsString()) { oss << arg->AsString(); } m_minuitMethods->minuitParseGetRequest(oss.str(), m); } else if (currentString.find("?namespace") != currentString.npos || currentString.find("?get") != currentString.npos) { osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); if (arg->IsChar()) { oss << arg->AsChar(); } else if (arg->IsInt32()) { oss << arg->AsInt32(); } else if (arg->IsString()) { oss << arg->AsString(); } m_minuitMethods->receiveNetworkRequest(oss.str(), currentString); } } };
void ofxOscReceiver::ProcessMessage( const osc::ReceivedMessage &m, const IpEndpointName& remoteEndpoint ) { // convert the message to an ofxOscMessage ofxOscMessage* ofMessage = new ofxOscMessage(); // set the address ofMessage->setAddress( m.AddressPattern() ); // set the sender ip/host char endpoint_host[ IpEndpointName::ADDRESS_STRING_LENGTH ]; remoteEndpoint.AddressAsString( endpoint_host ); ofMessage->setRemoteEndpoint( endpoint_host, remoteEndpoint.port ); // transfer the arguments for ( osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); arg != m.ArgumentsEnd(); ++arg ) { if ( arg->IsInt32() ) ofMessage->addIntArg( arg->AsInt32Unchecked() ); else if ( arg->IsInt64() ) ofMessage->addInt64Arg( arg->AsInt64Unchecked() ); else if ( arg->IsFloat() ) ofMessage->addFloatArg( arg->AsFloatUnchecked() ); else if ( arg->IsString() ) ofMessage->addStringArg( arg->AsStringUnchecked() ); else { ofLogError("ofxOscReceiver") << "ProcessMessage: argument in message " << m.AddressPattern() << " is not an int, float, or string"; } } // now add to the queue // at this point we are running inside the thread created by startThread, // so anyone who calls hasWaitingMessages() or getNextMessage() is coming // from a different thread // so we have to practise shared memory management // grab a lock on the queue grabMutex(); // add incoming message on to the queue messages.push_back( ofMessage ); // release the lock releaseMutex(); }
void Network::ProcessMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { try { std::string address = m.AddressPattern(); if (address != "/mouse/position") // too noisy! std::cerr << "Port " << m_port << " >>> Received '" << address << "' message with arguments: "; (this->*(m_handlers[address]))(m, remoteEndpoint); } catch(osc::Exception& e) { std::cerr << "error while parsing message: " << m.AddressPattern() << ": " << e.what() << std::endl; } rescueOrphans(); }
void OscListener::ProcessMessage( const ::osc::ReceivedMessage &m, const IpEndpointName& remoteEndpoint ) { Message* message = new Message(); message->setAddress(m.AddressPattern()); char endpoint_host[IpEndpointName::ADDRESS_STRING_LENGTH]; remoteEndpoint.AddressAsString(endpoint_host); message->setRemoteEndpoint(endpoint_host, remoteEndpoint.port); for (::osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); arg != m.ArgumentsEnd(); ++arg){ if (arg->IsInt32()) message->addIntArg( arg->AsInt32Unchecked()); else if (arg->IsFloat()) message->addFloatArg(arg->AsFloatUnchecked()); else if (arg->IsString()) message->addStringArg(arg->AsStringUnchecked()); else { assert(false && "message argument type unknown"); } } lock_guard<mutex> lock(mMutex); if( mMessageReceivedCbs.empty() ){ mMessages.push_back( message ); }else{ mMessageReceivedCbs.call( message ); delete message; } }
void oscReceiver::ProcessMessage(const osc::ReceivedMessage &_m, const IpEndpointName &remoteEndpoint) { boost::mutex::scoped_lock lock(listenerMutex); if (retrievalMode == SIGNAL_PARSER_ONLY_AFTER_RELEASE) { if (currentMessage != 0) return; } osc::ReceivedMessage::const_iterator arg = _m.ArgumentsBegin(); currentMessage = new oscMessage(_m.AddressPattern(), oscMessage::NO_BUFFER); // set source IP char sourceString[ IpEndpointName::ADDRESS_STRING_LENGTH ]; remoteEndpoint.AddressAsString( sourceString ); currentMessage->sourceIP = sourceString; while ( arg != _m.ArgumentsEnd() ) { if ( arg->IsBool() ) { currentMessage->AppendBoolean (arg->AsBool());} else if ( arg->IsInt32() ) { currentMessage->AppendInteger (arg->AsInt32());} else if ( arg->IsFloat() ) { currentMessage->AppendFloat (arg->AsFloat());} else if ( arg->IsString() ) { currentMessage->AppendString (arg->AsString());} else { std::cout << "Unrecognized osc argument type\n"; } arg++; } signalNewOscMessageReceived(currentMessage); }
void OSCHandler::ProcessMessage(const osc::ReceivedMessage& m, const IpEndpointName& /*remoteEndpoint*/) { const String stripWildcard = OSCPrefix + "strip/*"; try { String msgPattern = m.AddressPattern(); if (msgPattern.equalsIgnoreCase(OSCPrefix + "press")) { // we need three arguments for button presses const int numArgs = m.ArgumentCount(); if (numArgs != 3) throw osc::Exception(); osc::ReceivedMessageArgumentStream args = m.ArgumentStream(); // unpack the monome button, row and state (button up or down) osc::int32 row, col, state; args >> row >> col >> state >> osc::EndMessage; buttonPressCallback(row, col, state == 1); } else if (msgPattern.matchesWildcard(stripWildcard, false)) { // strip off the /mlrvst/strip/ part of the message msgPattern = msgPattern.substring(stripWildcard.length() - 1); // and extract the SampleStrip rowID from the message const String rowIDStr = msgPattern.upToFirstOccurrenceOf("/", false, false); const int stripID = rowIDStr.getIntValue(); handleStripMessage(stripID, m); } }
void ScServer::processOscMessage( const osc::ReceivedMessage & message ) { if (strcmp(message.AddressPattern(), "/status.reply") == 0) { processServerStatusMessage(message); } }
void Receiver::ProcessMessage( const osc::ReceivedMessage &m, const osc::IpEndpointName& remoteEndpoint ) { // convert the m to a Message, return at the end to other main thread Message message; // set the address message.setAddress( m.AddressPattern() ); // set the sender ip/host char endpoint_host[ osc::IpEndpointName::ADDRESS_STRING_LENGTH ]; remoteEndpoint.AddressAsString( endpoint_host ); message.setRemoteEndpoint( endpoint_host, remoteEndpoint.port ); // transfer the arguments for ( osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); arg != m.ArgumentsEnd(); ++arg ) { if ( arg->IsInt32() ) { message.addIntArg( arg->AsInt32Unchecked() ); } else if ( arg->IsFloat() ) { message.addFloatArg( arg->AsFloatUnchecked() ); } else if ( arg->IsString() ) { message.addStringArg( arg->AsStringUnchecked() ); } else { assert( false && "message argument is not int, float, or string" ); } } // at this point we are running inside the thread created by start() // since we are returning a copy no shared memory management for(unsigned int i=0; i<_oscHandlers.size(); ++i) { _oscHandlers[i]->oscReceive( message ); } }
//------------------------------------------------------------------------ void OSCListener::ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& src ) { string address(m.AddressPattern()); if (address == kGreensoundsAddr) { ReceivedMessageArgumentIterator i = m.ArgumentsBegin(); while (i != m.ArgumentsEnd()) { if (i->IsString()) { string msg(i->AsStringUnchecked()); if (msg == "hello") { char buff[120]; src.AddressAsString(buff); fSensors->connect(buff); } else if (msg == "version") { fSensors->send (kGreensoundsAddr, "version", kVersion); } } else if (i->IsInt32()) { } else if (i->IsFloat()) { } i++; } } }
void PortVideoSDL::ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint ) { //For now print the messages we recieve. std::cout << "Recieved a message: '" << m.AddressPattern() << "'" << std::endl; SDL_Event e={0}; e.type=SDL_USEREVENT; std::string pattern(m.AddressPattern()); if(pattern == "camera_off"){ e.user.code=CAMERA_OFF; } if(pattern == "camera_on"){ e.user.code=CAMERA_ON; } //Push the camera event onto the queue SDL_PushEvent(&e); }
void OscListener::ProcessMessage(const osc::ReceivedMessage& message, const IpEndpointName& endpoint) { char addressBuffer[256]; endpoint.AddressAsString(addressBuffer); QList<QVariant> arguments; for (osc::ReceivedMessage::const_iterator iterator = message.ArgumentsBegin(); iterator != message.ArgumentsEnd(); ++iterator) { const osc::ReceivedMessageArgument& argument = *iterator; if (argument.IsBool()) arguments.push_back(argument.AsBool()); else if (argument.IsInt32()) arguments.push_back(QVariant::fromValue<qint32>(argument.AsInt32())); else if (argument.IsInt64()) arguments.push_back(QVariant::fromValue<qint64>(argument.AsInt64())); else if (argument.IsFloat()) arguments.push_back(argument.AsFloat()); else if (argument.IsDouble()) arguments.push_back(argument.AsDouble()); else if (argument.IsString()) arguments.push_back(argument.AsString()); } QString eventPath = QString("%1%2").arg(addressBuffer).arg(message.AddressPattern()); QMutexLocker locker(&eventsMutex); this->events[eventPath] = arguments; }
void MLT3DHub::ProcessMessage(const osc::ReceivedMessage& msg, const IpEndpointName&) { osc::TimeTag frameTime; osc::int32 frameID, touchID, deviceID; float x, y, z, note; // todo keep track of alive touches again to fix deadbeats // int alive[MLProcInputToSignals::kFrameHeight] = {0}; try { osc::ReceivedMessageArgumentStream args = msg.ArgumentStream(); const char * addy = msg.AddressPattern(); //debug() << "t3d: " << addy << "\n"; // frame message. // /t3d/frm (int)frameID int)deviceID if (strcmp(addy, "/t3d/frm") == 0) { args >> frameID >> deviceID; mT3DWaitTime = 0; if(!mConnected) { mConnected = true; notifyListeners("connected", 1); } //debug() << "FRM " << frameID << "\n"; } // match tch[n] message else if (strncmp(addy, "/t3d/tch", 8) == 0) { // get trailing number touchID = 1; int len = strlen(addy); if(len == 9) { touchID = addy[8] - 48; } else if(len == 10) { touchID = 10*(addy[8] - 48) + (addy[9] - 48); } touchID = clamp(touchID - 1, (osc::int32)0, (osc::int32)16); // t3d/tch[ID], (float)x, (float)y, (float)z, (float)note args >> x >> y >> z >> note; //debug() << "TCH " << touchID << " " << x << " " << y << " " << z << " " << note << "\n"; mOutputFrame(0, touchID) = x; mOutputFrame(1, touchID) = y; mOutputFrame(2, touchID) = z; mOutputFrame(3, touchID) = note; }
virtual void ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint ) { try{ if( std::strcmp( m.AddressPattern(), "/groupclient/user_info" ) == 0 ){ user_info( m, remoteEndpoint ); }else if( std::strcmp( m.AddressPattern(), "/groupclient/ping" ) == 0 ){ ping( m, remoteEndpoint ); }else if( std::strcmp( m.AddressPattern(), "/groupclient/user_alive_status" ) == 0 ){ user_alive_status( m, remoteEndpoint ); }else if( std::strcmp( m.AddressPattern(), "/groupclient/user_group_status" ) == 0 ){ user_group_status( m, remoteEndpoint ); } }catch( osc::Exception& e ){ std::cout << "error while parsing message: " << e.what() << "\n"; } }
void ExamplePacketListener::ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint ) { try{ // example of parsing single messages. osc::OsckPacketListener // handles the bundle traversal. OSCData *d = new OSCData; //new OSCData; d->header = oscNothing; osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); if( strcmp( m.AddressPattern(), "/obs") == 0 ) // this is a packet of feature data: /obs len x x x x { d = new OSCData; int len = (arg++)->AsInt32(); for (int i = 0; i < len; i++) d->data.push_back((arg++)->AsFloat()); // the observed state d->header = oscUpdate; } else if( strcmp( m.AddressPattern(), "/spo") == 0 ) // set the RL's willingness to jump to new categories { d = new OSCData; d->data.push_back((arg++)->AsFloat()); // the observed state d->header = oscSponteneity; } else if( strcmp( m.AddressPattern(), "/reset") == 0 ) // start over! { d = new OSCData; d->header = oscReset; } else if( strcmp( m.AddressPattern(), "/analyze") == 0 ) // toggle between purely analyzing and predicting states { d = new OSCData; d->header = oscAnalyze; } else if( strcmp( m.AddressPattern(), "/learnRate") == 0 ) // toggle between purely analyzing and predicting states { d = new OSCData; d->header = oscLearnRates; for (int i = 0; i < 4; i++) d->data.push_back((arg++)->AsFloat()); // the observed state } else if( strcmp( m.AddressPattern(), "/rewardWeight") == 0 ) // toggle between purely analyzing and predicting states { d = new OSCData; d->header = oscRewardWeights; for (int i = 0; i < 4; i++) d->data.push_back((arg++)->AsFloat()); // the observed state } if (d->header != oscNothing) { pthread_mutex_lock(MusiVerse::oscmutex); //wait for the lock MusiVerse::rxCommands.push_back(d); pthread_mutex_unlock(MusiVerse::oscmutex); } else delete d; }catch( osc::Exception& e ) { // any parsing errors such as unexpected argument types, or // missing arguments get thrown as exceptions. std::cout << "error while parsing message: " << m.AddressPattern() << ": " << e.what() << "\n"; } }
void GesturePacketListener::ProcessMessage( const osc::ReceivedMessage& m) { try{ if( std::strcmp( m.AddressPattern(), "/0/raw" ) == 0 ){ osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); int battery = (arg++)->AsInt32(); this->switchState = (arg++)->AsInt32(); int accX = (arg++)->AsInt32(); this->accX = (arg++)->AsInt32(); int accZ =(arg++)->AsInt32(); accelMag = sqrt(pow(accX,2) + pow(this->accX, 2) + pow(accZ, 2)); int gyroY = (arg++)->AsInt32(); int gyroP = (arg++)->AsInt32(); int gyroR =(arg++)->AsInt32(); int magnetX = (arg++)->AsInt32(); int magnetY = (arg++)->AsInt32(); int magnetZ =(arg++)->AsInt32(); } if( std::strcmp( m.AddressPattern(), "/0/euler" ) == 0 ){ osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); this->yaw = (arg++)->AsFloat(); this->pitch = (arg++)->AsFloat(); this->roll = (arg++)->AsFloat(); } if( std::strcmp( m.AddressPattern(), "/0/quat" ) == 0 ){ osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); this->q1 = (arg++)->AsFloat(); this->q2 = (arg++)->AsFloat(); this->q3 = (arg++)->AsFloat(); this->q3 = (arg++)->AsFloat(); } }catch( osc::Exception& e ){ std::cout << "error while parsing message: " << m.AddressPattern() << ": " << e.what() << "\n"; } }
void process_message( MarSystem * root_system, const osc::ReceivedMessage& message ) { const char * path = message.AddressPattern(); if (path[0] == '/') ++path; // FIXME: Constructing std::string is not real-time-safe. MarControlPtr control = find_control(root_system, path); if (control.isInvalid()) { MRSWARN("OSC receiver: no control for path: " << path); return; } try { osc::ReceivedMessage::const_iterator it = message.ArgumentsBegin(); if (it == message.ArgumentsEnd()) throw std::runtime_error("OSC receiver: Message has no arguments."); char tag = it->TypeTag(); switch(tag) { case osc::TRUE_TYPE_TAG: case osc::FALSE_TYPE_TAG: control->setValue(it->AsBoolUnchecked()); break; case osc::INT32_TYPE_TAG: control->setValue(it->AsInt32Unchecked()); break; case osc::FLOAT_TYPE_TAG: control->setValue((mrs_real) it->AsFloatUnchecked()); break; case osc::DOUBLE_TYPE_TAG: control->setValue((mrs_real) it->AsDoubleUnchecked()); break; case osc::STRING_TYPE_TAG: control->setValue(it->AsStringUnchecked()); break; default: throw std::runtime_error("OSC receiver: Unsupported message argument type."); } } catch ( std::exception & e ) { MRSWARN("OSC receiver: error while parsing message: " << e.what()); } }
static void SendMessage(TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> & _pendingMessages, const osc::ReceivedMessage & message) { const FName address(message.AddressPattern()); TArray<FOscDataElemStruct> data; const auto argBegin = message.ArgumentsBegin(); const auto argEnd = message.ArgumentsEnd(); for(auto it = argBegin; it != argEnd; ++it) { FOscDataElemStruct elem; if(it->IsFloat()) { elem.SetFloat(it->AsFloatUnchecked()); } else if(it->IsDouble()) { elem.SetFloat(it->AsDoubleUnchecked()); } else if(it->IsInt32()) { elem.SetInt(it->AsInt32Unchecked()); } else if(it->IsInt64()) { elem.SetInt(it->AsInt64Unchecked()); } else if(it->IsBool()) { elem.SetBool(it->AsBoolUnchecked()); } else if(it->IsString()) { elem.SetString(FName(it->AsStringUnchecked())); } data.Add(elem); } // save it in pending messages _pendingMessages.Enqueue(std::make_pair(address, data)); }
void OscReceiver::ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& ){ boost::regex top_re("^/datajockey/(\\w*)(.*)$"); boost::regex mixer_re("^mixer$"); boost::regex xfade_re("^crossfade$"); boost::regex master_re("^master$"); boost::cmatch matches; std::string addr; try { if(boost::regex_match(m.AddressPattern(), matches, top_re)){ std::string sub_match(matches[1]); if(boost::regex_match(sub_match, mixer_re)){ processMixerMessage(matches[2], m); } else if(boost::regex_match(sub_match, master_re)){ processMasterMessage(matches[2], m); } else if(boost::regex_match(sub_match, xfade_re)){ processXFadeMessage(matches[2], m); } } } catch( osc::Exception& e ){ std::cerr << "An Exception occured while processing incoming OSC packets." << std::endl; std::cerr << e.what() << std::endl; } }
void SerialOscController::ProcessMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { (void)remoteEndpoint; String address = m.AddressPattern(); auto iter = m.ArgumentsBegin(); try { if (address == "/serialosc/device" || address == "/serialosc/add") { String id = (iter++)->AsString(); String type = (iter++)->AsString(); int port = (iter++)->AsInt32(); MonomeDevice *device = nullptr; if (devices.contains(id)) { device = devices[id]; } else { device = new MonomeDevice; devices.set(id, device); if (address == "/serialosc/add") { sendDeviceNotifyMessage(); } } device->id = id; device->type = type; device->port = port; device->prefix = devicePrefix; if (!device->prefix.startsWith("/")) { device->prefix = "/" + device->prefix; } sendDeviceInfoMessage(device->port); sendDevicePrefixMessage(port); sendDevicePortMessage(port); } else if (address == "/serialosc/remove") { String id = (iter++)->AsString(); if (devices.contains(id)) { delete devices[id]; devices.remove(id); sendDeviceNotifyMessage(); } } else if (address == "/sys/id") { currentDeviceID = (iter++)->AsString(); } else if (address == "/sys/size") { if (devices.contains(currentDeviceID)) { auto device = devices[currentDeviceID]; device->width = (iter++)->AsInt32(); device->height = (iter++)->AsInt32(); } } else if (address == "/sys/rotation") { if (devices.contains(currentDeviceID)) { auto device = devices[currentDeviceID]; device->rotation = (iter++)->AsInt32(); } } else if (address == ("/" + devicePrefix + "/grid/key")) { int x = (iter++)->AsInt32(); int y = (iter++)->AsInt32(); bool state = (iter++)->AsInt32() > 0; listener->buttonPressMessageReceived(x, y, state); } } catch(osc::WrongArgumentTypeException &exc) { printf("WrongArgumentTypeException: %s", exc.what()); } }
void OSCListener::ProcessMessage(const osc::ReceivedMessage & m, const ::IpEndpointName & remoteEndpoint) { osc::ReceivedMessageArgumentStream as = m.ArgumentStream(); ReceiveCall(m.AddressPattern(),as); }
void TUIOMsgListener::ProcessMessage(const osc::ReceivedMessage &m, const IpEndpointName &remoteEndpoint) { try { const char *addr = m.AddressPattern(); std::cout << "TUIOMsgListener: Received message " << addr << std::endl; const int prefixLen = strlen(tuioAddressPrefix); if (strncmp(addr, tuioAddressPrefix, prefixLen) == 0 && strlen(addr) > prefixLen + 1) { TUIOMsg *msg = new TUIOMsg; const char *type = (addr + prefixLen + 1); osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); const unsigned long numArgs = m.ArgumentCount(); if (strcmp(type, "2Dobj") == 0) { msg->type = kTUIOMsgTypeObj; } else if (strcmp(type, "2Dcur") == 0) { msg->type = kTUIOMsgTypeCur; } else if (strcmp(type, "2Dblb") == 0) { msg->type = kTUIOMsgTypeBlb; } else { std::cerr << "TUIOMsgListener: unknown TUIO message type " << type << std::endl; return; } const char *cmd = (arg++)->AsString(); if (strcmp(cmd, "source") == 0) { msg->cmd = kTUIOMsgCmdSrc; } else if (strcmp(cmd, "alive") == 0) { msg->cmd = kTUIOMsgCmdAlive; } else if (strcmp(cmd, "set") == 0) { msg->cmd = kTUIOMsgCmdSet; } else if (strcmp(cmd, "fseq") == 0) { msg->cmd = kTUIOMsgCmdFSeq; } else { std::cerr << "TUIOMsgListener: unknown TUIO message command " << cmd << std::endl; return; } switch (msg->cmd) { case kTUIOMsgCmdSrc: { const char *srcAddr = (arg++)->AsString(); const int addrLen = strlen(srcAddr + 1); msg->data.source.addr = new char[addrLen]; strncpy(msg->data.source.addr, srcAddr, addrLen); } break; case kTUIOMsgCmdAlive: { msg->data.alive.numSessIds = numArgs - 1; if (msg->data.alive.numSessIds > 0) { msg->data.alive.sessIds = new int[msg->data.alive.numSessIds]; for (int i = 0; i < msg->data.alive.numSessIds; i++) { msg->data.alive.sessIds[i] = (arg++)->AsInt32(); } } else { msg->data.alive.sessIds = NULL; } } break; case kTUIOMsgCmdSet: { msg->data.set.sessId = (arg++)->AsInt32(); switch (msg->type) { case kTUIOMsgTypeObj: msg->data.set.classId = (arg++)->AsInt32(); msg->data.set.pos.x = (arg++)->AsFloat(); msg->data.set.pos.y = (arg++)->AsFloat(); msg->data.set.angle = (arg++)->AsFloat(); msg->data.set.size.x = 0.0f; msg->data.set.size.y = 0.0f; msg->data.set.area = 0.0f; msg->data.set.vel.x = (arg++)->AsFloat(); msg->data.set.vel.y = (arg++)->AsFloat(); msg->data.set.angleVel = (arg++)->AsFloat(); msg->data.set.motAccel = (arg++)->AsFloat(); msg->data.set.rotAccel = (arg++)->AsFloat(); break; case kTUIOMsgTypeCur: msg->data.set.classId = 0; msg->data.set.pos.x = (arg++)->AsFloat(); msg->data.set.pos.y = (arg++)->AsFloat(); msg->data.set.angle = 0.0f; msg->data.set.size.x = 0.0f; msg->data.set.size.y = 0.0f; msg->data.set.area = 0.0f; msg->data.set.vel.x = (arg++)->AsFloat(); msg->data.set.vel.y = (arg++)->AsFloat(); msg->data.set.angleVel = 0.0f; msg->data.set.motAccel = (arg++)->AsFloat(); msg->data.set.rotAccel = 0.0f; break; case kTUIOMsgTypeBlb: msg->data.set.classId = 0; msg->data.set.pos.x = (arg++)->AsFloat(); msg->data.set.pos.y = (arg++)->AsFloat(); msg->data.set.angle = (arg++)->AsFloat(); msg->data.set.size.x = (arg++)->AsFloat(); msg->data.set.size.y = (arg++)->AsFloat(); msg->data.set.area = 0.0f; msg->data.set.vel.x = (arg++)->AsFloat(); msg->data.set.vel.y = (arg++)->AsFloat(); msg->data.set.angleVel = (arg++)->AsFloat(); msg->data.set.motAccel = (arg++)->AsFloat(); msg->data.set.rotAccel = (arg++)->AsFloat(); break; } } break; case kTUIOMsgCmdFSeq: { msg->data.fseq.frameId = (arg++)->AsInt32(); } break; } if (msgCallback) { msgCallback(msg); } } else { std::cerr << "TUIOMsgListener: Address prefix " << addr << " did not match to " << tuioAddressPrefix << std::endl; } } catch( osc::Exception& e ){ // any parsing errors such as unexpected argument types, or // missing arguments get thrown as exceptions. std::cerr << "TUIOMsgListener: error while parsing message " << m.AddressPattern() << ": " << e.what() << "\n"; } }
void OscThread::ProcessMessage( const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint ) { (void) remoteEndpoint; // suppress unused parameter warning try{ string keyword = m.AddressPattern(); if( keyword == "/object") { cout<<"Received virtual object from osc"<<endl; //if (H2ICUB != NULL) osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); const char *type = (arg++)->AsString(); const char *name = (arg++)->AsString(); string typeword = type; if (typeword == "add") { float x = (arg++)->AsFloat(); float y = (arg++)->AsFloat(); float dimx = (arg++)->AsFloat(); float dimy = (arg++)->AsFloat(); int r = (arg++)->AsInt32(); int g = (arg++)->AsInt32(); int b = (arg++)->AsInt32(); cout<<"Adding object "<<name<<endl; if (!opc->isConnected()) { cout<<"Not connected to OPC"<<endl; return; } if (!isCalibrated) { cout<<"Not calibrated"<<endl; return; } RTObject* o = opc->addRTObject(name); opc->update(o); Vector rtPosition(4); rtPosition(0) = XaxisFactor * x; rtPosition(1) = YaxisFactor * y; rtPosition(2) = 0; rtPosition(3) = 1; o->m_rt_position[0] = rtPosition[0]; o->m_rt_position[1] = rtPosition[1]; o->m_rt_position[2] = rtPosition[2]; cout<<o->toString()<<endl; Vector icubPos(4); icubPos = H2ICUB * rtPosition; o->m_ego_position[0] = icubPos[0];//+ idOffsets[tobj->getSymbolID()][0]; o->m_ego_position[1] = icubPos[1];//+ idOffsets[tobj->getSymbolID()][1]; o->m_ego_position[2] = icubPos[2];//+ idOffsets[tobj->getSymbolID()][2]; o->m_dimensions[0] = dimx; o->m_dimensions[1] = dimy; o->m_dimensions[2] = 0.01; o->m_present = true; o->m_ego_orientation[0] = 0.0; o->m_ego_orientation[1] = 0.0; o->m_ego_orientation[2] = 0.0;//tobj->getAngle(); o->m_color[0] = r; o->m_color[1] = g; o->m_color[2] = b;//tobj->getAngle(); //opc->isVerbose = true; opc->commit(o); //opc->isVerbose = false; cout<<"Added"<<endl; } if (typeword == "remove") { if (!opc->isConnected()) { cout<<"Not connected to OPC"<<endl; return; } cout<<"Removing object"<<endl; RTObject* o = opc->addRTObject(name); o->m_present = false; //opc->isVerbose = true; opc->commit(o); //opc->isVerbose = false; cout<<"Removed"<<endl; } } else if( keyword == "/event") { osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); const char *subject = (arg++)->AsString(); const char *verb = (arg++)->AsString(); const char *cobj = "none"; const char *cplace = "none"; const char *ctime = "none"; const char *cmanner = "none"; double timeLife = 5.0; if (arg != m.ArgumentsEnd()) cobj = (arg++)->AsString(); if (arg != m.ArgumentsEnd()) cplace = (arg++)->AsString(); if (arg != m.ArgumentsEnd()) ctime = (arg++)->AsString(); if (arg != m.ArgumentsEnd()) cmanner = (arg++)->AsString(); if (arg != m.ArgumentsEnd()) timeLife = (arg++)->AsFloat(); Relation r(subject,verb,cobj,cplace,ctime,cmanner); cout<<"Received relation (/Event) from OSC "<<r.toString()<< "with a lifetime of "<<timeLife<< "Trying to add : "; opc->addRelation(r, timeLife); cout<<endl; } else if( keyword == "/revent") { osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); const char *subject = (arg++)->AsString(); const char *verb = (arg++)->AsString(); const char *cobj = "none"; const char *cplace = "none"; const char *ctime = "none"; const char *cmanner = "none"; double timeLife = 5.0; if (arg != m.ArgumentsEnd()) cobj = (arg++)->AsString(); if (arg != m.ArgumentsEnd()) cplace = (arg++)->AsString(); if (arg != m.ArgumentsEnd()) ctime = (arg++)->AsString(); if (arg != m.ArgumentsEnd()) cmanner = (arg++)->AsString(); if (arg != m.ArgumentsEnd()) timeLife = (arg++)->AsFloat(); Relation r(subject,verb,cobj,cplace,ctime,cmanner); cout<<"Received relation remove request (/revent) from OSC "<<r.toString()<< "Trying to remove : "; opc->removeRelation(r); cout<<endl; } else if ( keyword == "/bottle") { Bottle bFwd; osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin(); const char *fwdMsg = (arg++)->AsString(); cout<<"OSC input (bottle forwarding) : "<<fwdMsg<<endl; bFwd.addString(fwdMsg); oscFwding.write(bFwd); } else { cout<<"OSC input : Unknown format"<<endl; } }catch( osc::Exception& e ){ std::cout << "error while parsing message: " << m.AddressPattern() << ": " << e.what() << "\n"; } }