void VampPlugin::applyParameters(MarSystem *system) { map<string, float>::const_iterator it; for (it = m_params.begin(); it != m_params.end(); ++it) { const string & id = it->first; float value = it->second; MarControlPtr control = system->control(id); if (control.isInvalid()) { cerr << "Invalid parameter id: " << id << endl; continue; } if (control->hasType<mrs_real>()) { control->setValue((mrs_real) value); } else if (control->hasType<mrs_natural>()) { control->setValue((mrs_natural) value); } else { cerr << "Invalid type for parameter id: " << id << endl; } } }
int set_control(MarControlPtr & control, const string & text) { string type = control->getType(); if (type == "mrs_bool") { if (text == "true") control->setValue(true); else if (text == "false") control->setValue(false); else return 1; } else if (type == "mrs_natural") { mrs_natural i; size_t count = 0; try { i = std::stol(text, &count); } catch (invalid_argument) {} if (count == text.size()) { control->setValue(i); } else return 1; } else if (type == "mrs_real") { mrs_real r; size_t count = 0; try { r = std::stod(text, &count); } catch (invalid_argument) {} if (count == text.size()) { control->setValue(r); } else return 1; } else if (type == "mrs_string") { control->setValue(text); } else return 1; return 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()); } }
static void set_control_value( MarControlPtr & control, const any & value, bool update = true ) { // FIXME: real-time-safe setting of string and realvec! try { const T & typed_value = any_cast<T>( value ); control->setValue(typed_value, update); } catch ( bad_any_cast ) { return; }; }