Esempio n. 1
0
void Client::send( const osc::Message &message )
{
	lo_message msg = lo_message_new();

	for ( size_t i = 0; i < message.getNumArgs(); i++ )
	{
		switch ( message.getArgType( i ) )
		{
			case 'i':
				lo_message_add_int32( msg, message.getArg< int32_t >( i ) );
				break;

			case 'f':
				lo_message_add_float( msg, message.getArg< float >( i ) );
				break;

			case 's':
				lo_message_add_string( msg, message.getArg< std::string >( i ).c_str() );
				break;

			default:
				break;
		}
	}

	lo_send_message( mAddress, message.getAddressPattern().c_str(), msg );
	lo_message_free( msg );
}
/**
 * Log incomming OSC msgs
 * Taken from OSCListener example provided with the Cinder OSC block
 */
void OSCController::__logMessage( osc::Message msg )
{
    if( displayMsgLog ){
        console() << "Incomming OSC msg: @ " << getId() << std::endl;
		console() << "Address: " << msg.getAddress() << std::endl;
		if( displayMsgExtended ){
			console() << "Num Arg: " << msg.getNumArgs() << std::endl;
			for (int i = 0; i < msg.getNumArgs(); i++) {
				console() << "-- Argument " << i << std::endl;
				console() << "---- type: " << msg.getArgTypeName(i) << std::endl;
				if (msg.getArgType(i) == osc::TYPE_INT32){
					try {
						console() << "------ value: "<< msg.getArgAsInt32(i) << std::endl;
					}
					catch (...) {
						console() << "Exception reading argument as int32" << std::endl;
					}
					
				}else if (msg.getArgType(i) == osc::TYPE_FLOAT){
					try {
						console() << "------ value: " << msg.getArgAsFloat(i) << std::endl;
					}
					catch (...) {
						console() << "Exception reading argument as float" << std::endl;
					}
					
				}else if (msg.getArgType(i) == osc::TYPE_STRING){
					try {
						console() << "------ value: " << msg.getArgAsString(i).c_str() << std::endl;
					}
					catch (...) {
						console() << "Exception reading argument as string" << std::endl;
					}
					
				}
			}
		}

        
    }
}
void PluginOSCController::processInteralMessage( const osc::Message& message, vector<string> tokens ){
    
    return;
    
    console() << "========= INTERNAL MESSAGE ==========" << std::endl;
    console() << "Num Arg: " << message.getNumArgs() << std::endl;
    for (int i = 0; i < message.getNumArgs(); i++) {
        console() << "-- Argument " << i << std::endl;
        console() << "---- type: " << message.getArgTypeName(i) << std::endl;
        if( message.getArgType(i) == osc::TYPE_INT32 ) {
            try {
                console() << "------ value: "<< message.getArgAsInt32(i) << std::endl;
            }
            catch (...) {
                console() << "Exception reading argument as int32" << std::endl;
            }
        }
        else if( message.getArgType(i) == osc::TYPE_FLOAT ) {
            try {
                console() << "------ value: " << message.getArgAsFloat(i) << std::endl;
            }
            catch (...) {
                console() << "Exception reading argument as float" << std::endl;
            }
        }
        else if( message.getArgType(i) == osc::TYPE_STRING) {
            try {
                console() << "------ value: " << message.getArgAsString(i).c_str() << std::endl;
            }
            catch (...) {
                console() << "Exception reading argument as string" << std::endl;
            }
        }
    }
    
}
void PluginOSCController::processPluginMessageDirect( const osc::Message& message, OSCElement* oscElement ){

    cinder::osc::ArgType typeOsc = message.getArgType(0);
    OSCElement::OSCElementTypes typeVar = oscElement->type;
    
    if( typeOsc == osc::TYPE_INT32 && typeVar == OSCElement::OSCElementTypes::INTEGER ) {
        try {
//            int val = message.getArgAsInt32(0);
            float val = cinder::math<float>::clamp( message.getArgAsFloat(0), 0.0f, 1.0f );
            val = lerp( oscElement->minValue, oscElement->maxValue, val );
            *static_cast<int*>(oscElement->pointer) = val;
        }
        catch (...) {
            console() << "Exception reading argument as int32" << std::endl;
        }
    }
    else if( typeOsc == osc::TYPE_FLOAT && typeVar == OSCElement::OSCElementTypes::FLOAT  ) {
        try {
            float val = cinder::math<float>::clamp( message.getArgAsFloat(0), 0.0f, 1.0f );
            val = lerp( oscElement->minValue, oscElement->maxValue, val );
            *(static_cast<float*>(oscElement->pointer)) = val;
        }
        catch (...) {
            console() << "Exception reading argument as float" << std::endl;
        }
    }
//    else if( message.getArgType(i) == osc::TYPE_STRING) {
//        try {
//            message.getArgAsString(i);
//        }
//        catch (...) {
//            console() << "Exception reading argument as string" << std::endl;
//        }
//    }
    
}