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); } }
// 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); } } }
void get_group_users_info( const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint ) { (void) remoteEndpoint; // suppress unused parameter warning // /groupserver/get_group_users_info group-name group-password osc::ReceivedMessageArgumentStream args = m.ArgumentStream(); const char *groupName, *groupPassword; args >> groupName >> groupPassword >> osc::EndMessage; Group *group = groupServer_.FindGroup( groupName ); if( group && group->password.compare( groupPassword ) == 0 ){ std::time_t currentTime = time(0); for( Group::const_user_iterator i = group->users_begin(); i != group->users_end(); ++i ) MakeUserInfoMessage( resultStream_, *i, currentTime ); } // we don't return a result to the client in the case where the group // doesn't exist, or the password is wrong because legitimate clients // will have already successfully joined the group, or they will have // received an error message when they tried to join. }
void Network::handleObjectPadMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message float x, y, radius; osc::Symbol uuid; m.ArgumentStream() >> uuid >> x >> y >> radius >> osc::EndMessage; std::cerr << uuid << ", " << x << ", " << y << ", " << radius << std::endl; // Check for known pad, add & broadcast if unknown WidgetMap* widgets = Widget::getAll(); WidgetMap::iterator wit = widgets->find(std::string(uuid)); if (wit == widgets->end()) { RoundPad* newPad = new RoundPad(Point2D(x, y), radius); newPad->setUuid(uuid); widgets->insert(WidgetData(std::string(uuid), newPad)); m_engine->addChild(newPad); // Tell the world newPad->toOutboundPacketStream(ps); broadcast(ps); } }
void Network::handlePeerTextMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message osc::Symbol text; osc::int64 address; osc::int32 port; m.ArgumentStream() >> address >> port >> text >> osc::EndMessage; if (address == 0) address = remoteEndpoint.address; char ipStr[INET_ADDRSTRLEN]; uint32_t endian = htonl(address); std::cerr << inet_ntop(AF_INET, &(endian), ipStr, INET_ADDRSTRLEN) << ": " << text << std::endl; // Check for known peer, add & broadcast if unknown IpEndpointName peerEndpoint((unsigned long)address, (int)port); PeerMap::iterator peer = m_peers.find(peerEndpoint); if (peer != m_peers.end()) peer->second->setDisplayName(std::string(text)); }
void Network::handlePeerDownMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message osc::int32 port; osc::int64 address; m.ArgumentStream() >> address >> port >> osc::EndMessage; if (address == 0) address = remoteEndpoint.address; char ipStr[INET_ADDRSTRLEN]; uint32_t endian = htonl(address); std::cerr << inet_ntop(AF_INET, &(endian), ipStr, INET_ADDRSTRLEN) << ", " << (int)port << std::endl; // Check for known peer, add & broadcast if unknown IpEndpointName peerEndpoint((unsigned long)address, (int)port); PeerMap::iterator peer = m_peers.find(peerEndpoint); if (peer != m_peers.end()) { m_peers.erase(peer); // Tell the world ps << osc::BeginMessage("/network/peer/down") << address << port << osc::EndMessage; broadcast(ps); } }
void ScServer::processServerStatusMessage(const osc::ReceivedMessage &message ) { if (!isRunning()) return; int unused; int ugenCount; int synthCount; int groupCount; int defCount; float avgCPU; float peakCPU; auto args = message.ArgumentStream(); try { args >> unused >> ugenCount >> synthCount >> groupCount >> defCount >> avgCPU >> peakCPU; } catch (osc::MissingArgumentException) { qCritical("Misformatted server status message."); return; } emit updateServerStatus(ugenCount, synthCount, groupCount, defCount, avgCPU, peakCPU); }
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; }
void Network::handleObjectStringMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message osc::Symbol uuid, padUuid; float startX, startY, endX, endY; m.ArgumentStream() >> uuid >> padUuid >> startX >> startY >> endX >> endY >> osc::EndMessage; std::cerr << uuid << ", " << padUuid << ", " << startX << ", " << startY << ", " << endX << ", " << endY << std::endl; // Check for known arc, add & broadcast if unknown bool unlocked = false; SoundSource::lockGlobals(); SoundSourceMap* soundSources = SoundSource::getAllForEngine(); WidgetMap* widgets = Widget::getAll(); if (soundSources->find(std::string(uuid)) == soundSources->end()) { WidgetMap::iterator wit = m_orphans.find(std::string(uuid)); if (wit == m_orphans.end()) { // Search for pad wit = widgets->find(std::string(padUuid)); if (wit != widgets->end()) { String* newString = new String(Point2D(startX, startY), Point2D(endX, endY), 1); newString->setUuid(uuid); // Add string to soundsource soundSources->insert(SoundSourceData(newString->getUuid(), newString)); wit->second->addChild(newString); newString->setPadRadius(((RoundPad*)wit->second)->getRadius()); // Tell the world newString->toOutboundPacketStream(ps); broadcast(ps); } else {// orphan if we don't know about its pad yet String* newString = new String(Point2D(startX, startY), Point2D(endX, endY), 1); newString->setUuid(uuid); m_orphans.insert(WidgetData(std::string(padUuid), newString)); } SoundSource::unlockGlobals(); unlocked = true; } } if (!unlocked) SoundSource::unlockGlobals(); }
void Network::handlePeerUpMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message osc::int32 port; osc::int64 address; m.ArgumentStream() >> address >> port >> osc::EndMessage; if ((long)address == 0) address = remoteEndpoint.address; char ipStr[INET_ADDRSTRLEN]; uint32_t endian = htonl(address); std::cerr << inet_ntop(AF_INET, &(endian), ipStr, INET_ADDRSTRLEN) << ", " << (int)port << std::endl; // Check for known peer, add & broadcast if unknown IpEndpointName peerEndpoint((unsigned long)address, (int)port); PeerMap::iterator peer = m_peers.find(peerEndpoint); if (peer == m_peers.end()) { PeerData peerData(peerEndpoint, new Peer(peerEndpoint)); // Tell the world for (PeerMap::iterator pit = m_peers.begin(); pit != m_peers.end(); pit++) { std::cerr << "sending " << (int)port << " to " << pit->first.port << std::endl; ps.Clear(); ps << osc::BeginMessage("/network/peer/up") << address << port << osc::EndMessage; pit->second->sendMessage(ps); ps.Clear(); ps << osc::BeginMessage("/network/peer/up") << (osc::int64)(pit->first.address) << (osc::int32)(pit->first.port) << osc::EndMessage; peerData.second->sendMessage(ps); } peer = m_peers.insert(peerData).first; sendPeerUpMessage(); // Tell our new friend everything we know /* * This doesn't work terribly well, so it's disabled for now * WidgetMap* widgets = Widget::getAll(); for (WidgetMap::iterator wit = widgets->begin(); wit != widgets->end(); wit++) { wit->second->toOutboundPacketStream(ps); peer->second->sendMessage(ps); } */ } }
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 Network::handleMousePositionMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Parse OSC message osc::int32 port; float x, y; bool down; m.ArgumentStream() >> port >> x >> y >> down >> osc::EndMessage; PeerMap::iterator pit = m_peers.find(IpEndpointName(remoteEndpoint.address, (int)port)); if (pit != m_peers.end()) { pit->second->setMousePosition(x, y); pit->second->setMouseDown(down); } }
void get_users_list(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint ) { (void) remoteEndpoint; // suppress unused parameter warning osc::ReceivedMessageArgumentStream args = m.ArgumentStream(); resultStream_ << osc::BeginMessage("/groupclient/user_list"); while( !args.Eos() ) { const char *groupName; const char *groupPassword; args >> groupName >> groupPassword; Group *group = groupServer_.FindGroup( groupName ); if(group && group->password.compare(groupPassword) == 0) { std::cout << "group found:" << groupName << std::endl; Group::const_user_iterator user_iter = group->users_begin(); for(; user_iter != group->users_end(); ++user_iter ) { User *user = *user_iter; resultStream_ << user->name.c_str() << ~((osc::int32)user->privateEndpoint.address) << (osc::int32)user->privateEndpoint.port << ~((osc::int32)user->publicEndpoint.address) << (osc::int32)user->publicEndpoint.port << groupName; std::cout << "Add userinfo:" << user->name.c_str() << ~((osc::int32)user->privateEndpoint.address) << (osc::int32)user->privateEndpoint.port << ~((osc::int32)user->publicEndpoint.address) << (osc::int32)user->publicEndpoint.port << groupName; } } else { std::cout << "group name or gourp password is not correct:" << groupName << std::endl; } } resultStream_ << osc::EndMessage; }
void Network::handleObjectPadTextMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message osc::Symbol uuid, text; m.ArgumentStream() >> uuid >> text >> osc::EndMessage; std::cerr << uuid << ", " << text << std::endl; WidgetMap* widgets = Widget::getAll(); WidgetMap::iterator wit = widgets->find(std::string(uuid)); if (wit != widgets->end() && dynamic_cast<RoundPad*>(wit->second)) ((RoundPad*)wit->second)->setCommentText(std::string(text)); }
void Network::handlePluckerMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message osc::Symbol uuid; m.ArgumentStream() >> uuid >> osc::EndMessage; std::cerr << uuid << std::endl; WidgetMap* widgets = Widget::getAll(); WidgetMap::iterator wit = widgets->find(std::string(uuid)); if (wit != widgets->end() && dynamic_cast<Track*>(wit->second)) ((Track*)wit->second)->addPlucker(); }
void Network::handleObjectDeleteMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Parse OSC message osc::Symbol uuid; m.ArgumentStream() >> uuid >> osc::EndMessage; std::cerr << uuid << std::endl; WidgetMap* widgets = Widget::getAll(); WidgetMap::iterator wit = widgets->find(std::string(uuid)); Widget* widget; if (wit != widgets->end() && (widget = wit->second->getParent()->removeChild(wit->second))) { sendObjectMessage(widget, true); delete widget; } }
void OSCListener::ProcessMessage(const osc::ReceivedMessage & m, const ::IpEndpointName & remoteEndpoint) { osc::ReceivedMessageArgumentStream as = m.ArgumentStream(); ReceiveCall(m.AddressPattern(),as); }
void Network::handleObjectSpiralMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message osc::Symbol uuid, padUuid; float startAngle, startRadius, endAngle, endRadius; m.ArgumentStream() >> uuid >> padUuid >> startAngle >> startRadius >> endAngle >> endRadius >> osc::EndMessage; std::cerr << uuid << ", " << padUuid << ", " << startAngle << ", " << startRadius << ", " << endAngle << ", " << endRadius << std::endl; // Check for known arc, add & broadcast if unknown WidgetMap* widgets = Widget::getAll(); WidgetMap::iterator wit = widgets->find(std::string(uuid)); if (wit == widgets->end()) { wit = m_orphans.find(std::string(uuid)); if (wit == m_orphans.end()) { SpiralTrack* newSpiral = NULL; // Search for pad wit = widgets->find(std::string(padUuid)); if (wit != widgets->end()) { Point2D center = ((RoundPad*)wit->second)->getCenter(); Point2D startPoint = Spiral::getPointFromRadius(center, startRadius, startAngle); Point2D endPoint = Spiral::getPointFromRadius(center, endRadius, endAngle); Joint *endJoint = NULL, *startJoint = NULL; std::vector<Widget*>* children = wit->second->getChildren(); for (int i = children->size() - 1; i >= 0; i --) { Track *track = dynamic_cast<Track *>(children->at(i)); if (track) { Joint *joint = track->getJoint1(); if (!startJoint && joint && joint->hitTest(startPoint.x, startPoint.y)) startJoint = joint; else if (!endJoint && joint && joint->hitTest(endPoint.x, endPoint.y)) endJoint = joint; joint = track->getJoint2(); if (!startJoint && joint && joint->hitTest(startPoint.x, startPoint.y)) startJoint = joint; else if (!endJoint && joint && joint->hitTest(endPoint.x, endPoint.y)) endJoint = joint; } } newSpiral = new SpiralTrack(center, startAngle, startRadius, endAngle, endRadius, startJoint, endJoint); newSpiral->setUuid(uuid); newSpiral->getSpiral()->setLineWidth(3); newSpiral->getJoint1()->setParentRoundPad(((RoundPad*)wit->second)); newSpiral->getJoint2()->setParentRoundPad(((RoundPad*)wit->second)); wit->second->addChild(newSpiral); widgets->insert(WidgetData(std::string(uuid), newSpiral)); // Tell the world newSpiral->toOutboundPacketStream(ps); broadcast(ps); } else {// orphan if we don't know about its pad yet newSpiral = new SpiralTrack(Point2D(0, 0), startAngle, startRadius, endAngle, endRadius, NULL, NULL); newSpiral->setUuid(uuid); m_orphans.insert(WidgetData(std::string(padUuid), newSpiral)); } } } }
void Network::handleObjectLineMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint) { // Utility data structures char buffer[1024]; osc::OutboundPacketStream ps(buffer, 1024); // Parse OSC message osc::Symbol uuid, padUuid; float startX, startY, endX, endY; m.ArgumentStream() >> uuid >> padUuid >> startX >> startY >> endX >> endY >> osc::EndMessage; std::cerr << uuid << ", " << padUuid << ", " << startX << ", " << startY << ", " << endX << ", " << endY << std::endl; // Check for known arc, add & broadcast if unknown WidgetMap* widgets = Widget::getAll(); WidgetMap::iterator wit = widgets->find(std::string(uuid)); if (wit == widgets->end()) { wit = m_orphans.find(std::string(uuid)); if (wit == m_orphans.end()) { LineTrack* newLine = NULL; // Search for pad wit = widgets->find(std::string(padUuid)); if (wit != widgets->end()) { Joint *endJoint = NULL, *startJoint = NULL; for (WidgetMap::iterator ptr = widgets->begin(); ptr != widgets->end(); ptr++) { Track *track = dynamic_cast<Track *>(ptr->second); if (track) { Joint *joint = track->getJoint1(); if (!startJoint && joint && joint->hitTest(startX, startY)) startJoint = joint; else if (!endJoint && joint && joint->hitTest(endX, endY)) endJoint = joint; joint = track->getJoint2(); if (!startJoint && joint && joint->hitTest(startX, startY)) startJoint = joint; else if (!endJoint && joint && joint->hitTest(endX, endY)) endJoint = joint; } } LineTrack* newLine = new LineTrack(Point2D(startX, startY), Point2D(endX, endY), startJoint, endJoint); newLine->setUuid(uuid); newLine->getLine()->setLineWidth(3); wit->second->addChild(newLine); widgets->insert(WidgetData(std::string(uuid), newLine)); // Tell the world newLine->toOutboundPacketStream(ps); broadcast(ps); } else {// orphan if we don't know about its pad yet newLine = new LineTrack(Point2D(startX, startY), Point2D(endX, endY), NULL, NULL); newLine->setUuid(uuid); m_orphans.insert(WidgetData(std::string(padUuid), newLine)); } } } }