Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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;
	}
}
Ejemplo n.º 3
0
//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";
    }
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
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);
        }
    }
Ejemplo n.º 6
0
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";
    }
}
Ejemplo n.º 7
0
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 );
    }    
}
Ejemplo n.º 8
0
//------------------------------------------------------------------------
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++;
        }
    }
}
Ejemplo n.º 9
0
// 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);
				}
			}
		}
Ejemplo n.º 10
0
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) );
}
Ejemplo n.º 11
0
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;
		}
Ejemplo n.º 12
0
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->IsFloat() )
			ofMessage->addFloatArg( arg->AsFloatUnchecked() );
		else if ( arg->IsString() )
			ofMessage->addStringArg( arg->AsStringUnchecked() );
		else if ( arg->IsBlob() )
		{
			osc::Blob blob;
			arg->AsBlobUnchecked( blob.data, blob.size );
			ofMessage->addBlobArg( blob );
		}
		else
		{
			assert( false && "message argument is not int, float, string, or blob" );
		}
	}

	// 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();
}
Ejemplo n.º 13
0
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;
    }
}
Ejemplo n.º 14
0
void MinuitGetAnswer::parseMinuitGetAnswer(const osc::ReceivedMessage&m)
{
	osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
	std::ostringstream ossWithAddress;
	std::ostringstream ossWithoutAddress;
	std::ostringstream floatCorrection;

	// get the address
	ossWithAddress << arg->AsString();
	++arg;
	
	while(arg != m.ArgumentsEnd()) {

		if (arg->IsChar()) {
			ossWithAddress  << arg->AsChar();
			ossWithoutAddress  << arg->AsChar();
		} else if (arg->IsInt32()) {
			ossWithAddress  << arg->AsInt32();
			ossWithoutAddress  << arg->AsInt32();
		} else if (arg->IsString()) {
			ossWithAddress  << arg->AsString();
			ossWithoutAddress  << arg->AsString();
		}else if (arg->IsFloat()) {
			floatCorrection.str("");

			floatCorrection << arg->AsFloat();

			std::string floatWithPoint = floatCorrection.str();

			if(floatWithPoint.find(".") == floatWithPoint.npos) {
				floatWithPoint = floatWithPoint + ".";
			}

			ossWithAddress  << floatWithPoint;
			ossWithoutAddress  << floatWithPoint;
		}

		++arg;
		if(arg != m.ArgumentsEnd()){
			ossWithAddress << " ";
			ossWithoutAddress << " ";
		}
	}

	m_getStringWithAddress = ossWithAddress.str();
	m_getStringWithoutAddress = ossWithoutAddress.str();
	
	m_state = ANSWER_RECEIVED;
}
Ejemplo n.º 15
0
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();
}
Ejemplo n.º 16
0
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";
    }
}
Ejemplo n.º 17
0
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);
  }
}
Ejemplo n.º 18
0
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));
}
Ejemplo n.º 19
0
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);
  }
}
Ejemplo n.º 20
0
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);
}
Ejemplo n.º 21
0
    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.
    }
Ejemplo n.º 22
0
void ScServer::processOscMessage( const osc::ReceivedMessage & message )
{
    if (strcmp(message.AddressPattern(), "/status.reply") == 0)
    {
        processServerStatusMessage(message);
    }
}
Ejemplo n.º 23
0
 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);
 }
Ejemplo n.º 24
0
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());
  }
}
Ejemplo n.º 25
0
void OscReceiver::processXFadeMessage(const std::string addr, const osc::ReceivedMessage& m){
	boost::regex position_re("^(/relative){0,1}/{0,1}$");
	//boost::regex leftmixer_re("^/mixer/left/{0,1}$");
	//boost::regex rightmixer_re("^/mixer/right/{0,1}$");
	boost::regex mixers_re("^/mixers/{0,1}$");
	boost::regex enable_re("^/enable/{0,1}$");
	boost::cmatch matches;
	osc::ReceivedMessage::const_iterator arg_it = m.ArgumentsBegin();

	if(boost::regex_match(addr.c_str(), matches, position_re)){
		if(arg_it == m.ArgumentsEnd())
			throw osc::MissingArgumentException();
		float arg = floatFromOscNumber(*arg_it);
		if(strcmp("", matches[1].str().c_str()) == 0)
			mModel->crossFade()->setPosition(arg);
		else
			mModel->crossFade()->setPosition(mModel->crossFade()->position() + arg);
	} else if(boost::regex_match(addr.c_str(), mixers_re)){
		if(arg_it == m.ArgumentsEnd())
			throw osc::MissingArgumentException();
		int left = intFromOsc(*arg_it);
		arg_it++;
		if(arg_it == m.ArgumentsEnd())
			throw osc::MissingArgumentException();
		int right = intFromOsc(*arg_it);
		mModel->crossFade()->setMixers(left, right);
		/*
	} else if(boost::regex_match(addr.c_str(), leftmixer_re)){
		if(arg_it == m.ArgumentsEnd())
			throw osc::MissingArgumentException();
		int arg = intFromOsc(*arg_it);
		mModel->crossFade()->setLeftMixer(arg);
	} else if(boost::regex_match(addr.c_str(), rightmixer_re)){
		if(arg_it == m.ArgumentsEnd())
			throw osc::MissingArgumentException();
		int arg = intFromOsc(*arg_it);
		mModel->crossFade()->setRightMixer(arg);
		*/
	} else if(boost::regex_match(addr.c_str(), enable_re)){
		if(arg_it == m.ArgumentsEnd())
			mModel->crossFade()->enable();
		else
			mModel->crossFade()->enable(boolFromBoolOrInt(*arg_it));
	}
}
Ejemplo n.º 26
0
    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";
        }
    }
Ejemplo n.º 27
0
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));
}
Ejemplo n.º 28
0
bool App::processOscMessage(const osc::ReceivedMessage& message,
								  const osc::MessageSource& source)
{
	LOG_DEBUG << "received " << message.path() << " " << message.types() << std::endl;
    
    if(message.path() == getOscRootAddress() + "/scene")
    {
        if(message.types() == "s")
        {
            string scene = message.asString(0);
            sceneManager.gotoScene(scene);
            return true;
        }
        else if(message.types() == "i")
        {
            int index = message.asInt32(0);
            sceneManager.gotoScene(index);
            return true;
        }
    }
    
    else if(message.path() == getOscRootAddress() + "/scene/prev")
    {
    	sceneManager.prevScene();
    	return true;
    }
    
    else if(message.path() == getOscRootAddress() + "/scene/next")
    {
    	sceneManager.nextScene();
    	return true;
    }

    else if(message.path() == getOscRootAddress() + "/quit")
    {
        exitMainLoop();
        return true;
    }

    return false;
}
Ejemplo n.º 29
0
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);
    }
    */
  }
}
Ejemplo n.º 30
0
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();
}