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;
}
示例#2
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);
}
示例#3
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;
	}
}
示例#4
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 );
    }    
}
示例#5
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";
    }
}
示例#6
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++;
        }
    }
}
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) );
}
示例#8
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));
	}
}
示例#9
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();
}
示例#10
0
void OscReceiver::processMasterMessage(const std::string addr, const osc::ReceivedMessage& m){
	boost::regex volume_re("^/volume(/relative){0,1}/{0,1}$");
	boost::regex tempo_re("^/tempo(/relative){0,1}/{0,1}$");
	boost::regex sync_re("^/syncsource/{0,1}$");
	boost::cmatch matches;
	osc::ReceivedMessage::const_iterator arg_it = m.ArgumentsBegin();
	if(boost::regex_match(addr.c_str(), matches, volume_re)){
		//make sure our matches list is long enough and that we have an argument
		if(matches.size() == 2 && arg_it != m.ArgumentsEnd()){
			float num = floatFromOscNumber(*arg_it);
			//"" == absolute, otherwise, relative
			if(strcmp("", matches[1].str().c_str()) == 0)
				mModel->master()->setVolume(num);
			else 
				mModel->master()->setVolume(mModel->master()->volume() + num);
		} else
			throw osc::MissingArgumentException();
	} else if(boost::regex_match(addr.c_str(), matches, tempo_re)){
		//make sure our matches list is long enough and that we have an argument
		if(matches.size() == 2 && arg_it != m.ArgumentsEnd()){
			float num = floatFromOscNumber(*arg_it);
			//"" == absolute, otherwise, relative
			if(strcmp("", matches[1].str().c_str()) == 0)
				mModel->master()->setTempo(num);
			else 
				mModel->master()->setTempo(mModel->master()->tempo() + num);
		} else
			throw osc::MissingArgumentException();
	} else if(boost::regex_match(addr.c_str(), sync_re)){
		//make sure our matches list is long enough and that we have an argument
		if(matches.size() == 2 && arg_it != m.ArgumentsEnd()){
			int src = intFromOsc(*arg_it);
			mModel->master()->setSyncSource(src);
		} else
			throw osc::MissingArgumentException();
	} else {
		//XXX throw an error?
	}
}
示例#11
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());
  }
}
示例#12
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));
}
	void ExternalVisualScrollMenu::ProcessMessage(const osc::ReceivedMessage& m, const IpEndpointName& remoteEndpoint)
	{

		printf("\nTesting process listening "); //Works

		//Take in package and break down into arguments


		std::vector<std::string> vals;
		/*Go through arguements. 
		0 = /Reply
		1 = Name
		2 = All arguments

		*/

		string name = "";
		bool aBreak = true;
		int i = 0;
		m;
		//EDITED
		vals.clear();
		for(osc::ReceivedMessageArgumentIterator it = m.ArgumentsBegin(); it != m.ArgumentsEnd(); it++, i++)
		{
			if (it->IsString())
			{
				//Convert the message into a usable string format
				std::string wub = ""; 
				wub = std::string (it->AsString());
				//If it is the first element
				if (i == 0)
				{
					//Check Break
					if (wub == "break")
					{
							printf("\nAccessed");
							s->AsynchronousBreak();
							aBreak = false;
					//Otherwise set the name
					}else
					{
						//Assign the string as the EV name
						name = wub;
					}
				//If not frst element
				}else
				{
					//Push into the parameters array
					vals.push_back(wub);
				}

				printf("THIS IS ONE STATEMENT");


			}else
			{
				printf("THIS IS ANOTHER STATMENT");

			}
			i++;

		}

		//Call External Visual Constructor
		//if( i >= 0)
		if( aBreak)
		{
			ExternalVisual* newVisual = new ExternalVisual (name,vals);
			//Add to the visuals list
			visuals.push_back(newVisual);
		}
	}
bool StandardRequestHandler::operator()(const std::string& request_path, const std::string& full_request_path, const osc::ReceivedMessage& m)
{
    try
    {
        std::string path = osgDB::getFilePath(full_request_path);
        std::string last_elem = osgDB::getSimpleFileName(full_request_path);

        osg::ref_ptr<osgGA::GUIEventAdapter> ea = getDevice()->getOrCreateUserDataEvent();
        osg::UserDataContainer* udc = ea->getOrCreateUserDataContainer();


        ea->setName(_treatFirstArgumentAsValueName ? full_request_path : path);
        udc->setName(ea->getName());

        if (m.ArgumentCount() == 0) {
            return true;
        }

        // if we have only one argument, get it and save it to the udc
        else if (m.ArgumentCount() == 1)
        {
            addArgumentToUdc(udc, last_elem, m.ArgumentsBegin());
            return true;
        }
        else
        {
            unsigned int i(0);
            osc::ReceivedMessageArgumentIterator start = m.ArgumentsBegin();
            if ((_treatFirstArgumentAsValueName) && (start->TypeTag() == osc::STRING_TYPE_TAG))
            {
                last_elem = start->AsString();
                ++start;
                // if we hav only 2 arguments, then save the value and return
                if (m.ArgumentCount() == 2)
                {
                    addArgumentToUdc(udc, last_elem, start);
                    return true;
                }
            }
            std::vector<float> float_vec;
            std::vector<double> double_vec;
            bool mixed_arguments(false);
            for(osc::ReceivedMessageArgumentIterator itr = start; itr != m.ArgumentsEnd(); ++itr, ++i)
            {
                if(itr->TypeTag() == osc::FLOAT_TYPE_TAG)
                {
                    float_vec.push_back(itr->AsFloat());
                }
                else if(itr->TypeTag() == osc::DOUBLE_TYPE_TAG)
                {
                    double_vec.push_back(itr->AsDouble());
                }
                else if(itr->TypeTag() == osc::INT32_TYPE_TAG)
                {
                    float_vec.push_back(itr->AsInt32());
                }
                else {
                    mixed_arguments = true;
                    break;
                }
            }
            if (!mixed_arguments)
            {
                unsigned int sum = float_vec.size() + double_vec.size();
                if (sum == float_vec.size())
                {
                    if (addNativeTypeFromVector(udc, last_elem, float_vec))
                        return true;
                }
                else if (sum == double_vec.size())
                {
                    if (addNativeTypeFromVector(udc, last_elem, double_vec))
                        return true;
                }
            }

            for(osc::ReceivedMessageArgumentIterator itr = start; itr != m.ArgumentsEnd(); ++itr, ++i)
            {
                std::ostringstream ss;
                ss << last_elem << "_" << i;
                addArgumentToUdc(udc, ss.str(), itr);
            }
        }
        return true;

    }
    catch(osc::Exception& e)
    {
        handleException(e);
        return false;
    }
    return false;
}
示例#15
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;
}
void MinuitNamespaceAnswer::parseMinuitNamespaceAnswer(const osc::ReceivedMessage&m)
{
	std::ostringstream oss;
	osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();

	while (arg != m.ArgumentsEnd()) {
		std::string currentString = arg->AsString();

		if (currentString.find("nodes") != currentString.npos) {

			++arg;
			
			if (arg->IsString()) {
				currentString = arg->AsString();
			} else if (arg->IsInt32()) {
				oss.str("");
				oss << arg->AsInt32();
				currentString = oss.str();
			} else if (arg->IsFloat()) {
				oss.str("");
				oss << arg->AsFloat();
				currentString = oss.str();
			}

			while (currentString.find("}") == currentString.npos) {
				m_nodes.push_back(currentString);
				++arg;
				
				
				if (arg->IsString()) {
					currentString = arg->AsString();
				} else if (arg->IsInt32()) {
					oss.str("");
					oss << arg->AsInt32();
					currentString = oss.str();
				} else if (arg->IsFloat()) {
					oss.str("");
					oss << arg->AsFloat();
					currentString = oss.str();
				}

				//std::cout << "nodes : " << currentString << std::endl;
			}
		} else if  (currentString.find("leaves") != currentString.npos){

			++arg;
		
			if (arg->IsString()) {
				currentString = arg->AsString();
			} else if (arg->IsInt32()) {
				oss.str("");
				oss << arg->AsInt32();
				currentString = oss.str();
			} else if (arg->IsFloat()) {
				oss.str("");
				oss << arg->AsFloat();
				currentString = oss.str();
			}

			while (currentString.find("}") == currentString.npos) {
				m_leaves.push_back(currentString);
				++arg;
				
				if (arg->IsString()) {
					currentString = arg->AsString();
				} else if (arg->IsInt32()) {
					oss.str("");
					oss << arg->AsInt32();
					currentString = oss.str();
				} else if (arg->IsFloat()) {
					oss.str("");
					oss << arg->AsFloat();
					currentString = oss.str();
				}
			}

		} else if  ((currentString.find("attributes") != currentString.npos) || (currentString.find("attributs") != currentString.npos)){

			++arg;
			
			if (arg->IsString()) {
				currentString = arg->AsString();
			} else if (arg->IsInt32()) {
				oss.str("");
				oss << arg->AsInt32();
				currentString = oss.str();
			} else if (arg->IsFloat()) {
				oss.str("");
				oss << arg->AsFloat();
				currentString = oss.str();
			}

			while (currentString.find("}") == currentString.npos) {
				m_attributs.push_back(currentString);
				++arg;
				
				if (arg->IsString()) {
					currentString = arg->AsString();
				} else if (arg->IsInt32()) {
					oss.str("");
					oss << arg->AsInt32();
					currentString = oss.str();
				} else if (arg->IsFloat()) {
					oss.str("");
					oss << arg->AsFloat();
					currentString = oss.str();
				}
			}
		}

		++arg;
	}

//	std::cout << "NODES" << std::endl;
//
//	for (unsigned int i = 0; i < m_nodes.size(); ++i) {
//		std::cout << m_nodes[i] << std::endl;
//	}
//
//	std::cout << "LEAVES" << std::endl;
//
//	for (unsigned int i = 0; i < m_leaves.size(); ++i) {
//		std::cout << m_leaves[i] << std::endl;
//	}
//
//	std::cout << "ATTRIBUTES" << std::endl;
//
//	for (unsigned int i = 0; i < m_attributes.size(); ++i) {
//		std::cout << m_attributes[i] << std::endl;
//	}
	//
	m_state = ANSWER_RECEIVED;
}
示例#17
0
void OscReceiver::processMixerMessage(const std::string addr, const osc::ReceivedMessage& m){
	boost::regex mixer_re("^/(\\d+)/(.+)");
	boost::regex volume_re("^volume(/relative){0,1}/{0,1}$");
	boost::regex mute_re("^mute(/toggle){0,1}/{0,1}$");
	boost::regex eq_re("^eq/(high|mid|low)(/relative|/cut|/cut/toggle){0,1}/{0,1}$");
	boost::regex load_re("^load/{0,1}$");
	boost::cmatch matches;
	osc::ReceivedMessage::const_iterator arg_it = m.ArgumentsBegin();

	if(boost::regex_match(addr.c_str(), matches, mixer_re)){
		unsigned int mixer = (unsigned int)atoi(matches[1].str().c_str());
		std::string remain(matches[2].str());
		//make sure we're in range
		if(mixer >= mModel->numMixerChannels())
			return;
		if(boost::regex_match(remain.c_str(), matches, volume_re)){
			//make sure our matches list is long enough and that we have an argument
			if(matches.size() == 2 && arg_it != m.ArgumentsEnd()){
				float num = floatFromOscNumber(*arg_it);
				//"" == absolute, otherwise, relative
				if(strcmp("", matches[1].str().c_str()) == 0)
					mModel->mixerChannels()->at(mixer)->setVolume(num);
				else {
					mModel->mixerChannels()->at(mixer)->setVolume(
							mModel->mixerChannels()->at(mixer)->volume() + num);
				}
			} else
				throw osc::MissingArgumentException();
		} else if(boost::regex_match(remain.c_str(), matches, mute_re)){
			//make sure our matches list is long enough to test
			if(matches.size() == 2){
				//if we have no argument then we're just setting the mute
				//otherwise toggle mute
				if(strcmp("", matches[1].str().c_str()) == 0) {
					if(arg_it != m.ArgumentsEnd())
						mModel->mixerChannels()->at(mixer)->setMuted(boolFromBoolOrInt(*arg_it));
					else 
						throw osc::MissingArgumentException();
				} else {
					mModel->mixerChannels()->at(mixer)->setMuted(
							!mModel->mixerChannels()->at(mixer)->muted());
				}
			}
		} else if(boost::regex_match(remain.c_str(), matches, eq_re)){
			if(matches.size() == 3){
				EQModel * eqModel = mModel->mixerChannels()->at(mixer)->eq();
				//figure out the band
				EQModel::band band;
				if(strcmp(matches[1].str().c_str(), "low") == 0)
					band = EQModel::LOW;
				else if(strcmp(matches[1].str().c_str(), "mid") == 0)
					band = EQModel::MID;
				else
					band = EQModel::HIGH;

				if(strcmp(matches[2].str().c_str(), "") == 0){
					//absolute
					if(arg_it == m.ArgumentsEnd())
						throw osc::MissingArgumentException();
					else
						eqModel->set(band, floatFromOscNumber(*arg_it));
				} else if(strcmp(matches[2].str().c_str(), "/cut") == 0){
					//cut
					if(arg_it == m.ArgumentsEnd())
						throw osc::MissingArgumentException();
					else
						eqModel->cut(band, boolFromBoolOrInt(*arg_it));
				} else if(strcmp(matches[2].str().c_str(), "/cut/toggle") == 0){
					//toggle cut
					eqModel->toggleCut(band);
				} else {
					//otherwise it is relative
					if(arg_it == m.ArgumentsEnd())
						throw osc::MissingArgumentException();
					else {
						eqModel->set(band, 
								eqModel->value(band) + floatFromOscNumber(*arg_it));
					}
				}
			}
		} else if(boost::regex_match(remain.c_str(), load_re)){
			if(arg_it == m.ArgumentsEnd())
				throw osc::MissingArgumentException();
			int work = intFromOsc(*arg_it);
			mModel->mixerChannels()->at(mixer)->loadWork(work);
			//otherwise it is a djmixer control message [or not valid]
		} else {
			processDJControlMessage(remain.c_str(), mModel->mixerChannels()->at(mixer)->control(), m);
		}
	}
}
示例#18
0
void OscReceiver::processDJControlMessage(const std::string addr, 
		DJMixerControlModel * control, 
		const osc::ReceivedMessage& m){
	boost::regex play_re("^play(/toggle){0,1}/{0,1}$");
	boost::regex cue_re("^cue(/toggle){0,1}/{0,1}$");
	boost::regex sync_re("^sync(/toggle){0,1}/{0,1}$");
	boost::regex seek_re("^seek(/relative){0,1}/{0,1}$");
	boost::regex reset_re("^reset$");
	boost::regex beatoffset_re("^beatoffset(/relative){0,1}/{0,1}$");
	boost::regex tempomul_re("^tempomul/{0,1}$");
	boost::cmatch matches;
	osc::ReceivedMessage::const_iterator arg_it = m.ArgumentsBegin();

	if(boost::regex_match(addr.c_str(), matches, play_re)){
		//"" == set else toggle
		if(strcmp(matches[1].str().c_str(), "") == 0){
			if(arg_it == m.ArgumentsEnd())
				throw osc::MissingArgumentException();
			else
				control->setPlay(boolFromBoolOrInt(*arg_it));
		} else 
			control->setPlay(!control->playing());
	} else if(boost::regex_match(addr.c_str(), matches, reset_re)){
			control->resetWorkPosition();
	} else if(boost::regex_match(addr.c_str(), matches, cue_re)){
		if(strcmp(matches[1].str().c_str(), "") == 0){
			//set
			if(arg_it == m.ArgumentsEnd())
				throw osc::MissingArgumentException();
			else
				control->setCueing(boolFromBoolOrInt(*arg_it));
		} else 
			control->setCueing(!control->cueing());
	} else if(boost::regex_match(addr.c_str(), matches, sync_re)){
		if(strcmp(matches[1].str().c_str(), "") == 0){
			//set
			if(arg_it == m.ArgumentsEnd())
				throw osc::MissingArgumentException();
			else
				control->setSync(boolFromBoolOrInt(*arg_it));
		} else 
			control->setSync(!control->synced());
	} else if(boost::regex_match(addr.c_str(), matches, seek_re)){
		if(arg_it == m.ArgumentsEnd())
			throw osc::MissingArgumentException();
		int arg = intFromOsc(*arg_it);
		if(strcmp(matches[1].str().c_str(), "") == 0){
			control->setPlaybackPosition(arg);
		} else 
			control->seek(arg);
	} else if(boost::regex_match(addr.c_str(), matches, beatoffset_re)){
		if(arg_it == m.ArgumentsEnd())
			throw osc::MissingArgumentException();
		int arg = intFromOsc(*arg_it);
		if(strcmp(matches[1].str().c_str(), "") == 0){
			control->setBeatOffset(arg);
		} else 
			control->setBeatOffset(control->beatOffset() + arg);
	} else if(boost::regex_match(addr.c_str(), tempomul_re)){
		if(arg_it == m.ArgumentsEnd())
			throw osc::MissingArgumentException();
		float mul = floatFromOscNumber(*arg_it);
		control->setTempoMul(mul);
	} else {
		//XXX throw an error?
	}
}
示例#19
0
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";
    }
}