void ofXml::serialize(const ofAbstractParameter & parameter){ if(!parameter.isSerializable()) return; string name = parameter.getEscapedName(); if(name=="") name="UnknownName"; if(parameter.type()==typeid(ofParameterGroup).name()){ const ofParameterGroup & group = static_cast<const ofParameterGroup&>(parameter); if(!exists(name)){ addChild(name); ofLogVerbose("ofXml") << "creating group " << name; } setTo(name); ofLogVerbose("ofXml") << "group " << name; for(int i=0;i<group.size();i++){ serialize(group.get(i)); } ofLogVerbose("ofXml") << "end group " << name; setToParent(); }else{ string value = parameter.toString(); if(!exists(name)){ addChild(name); ofLogVerbose("ofXml") << "creating tag " << name; } ofLogVerbose("ofXml") << "setting tag " << name << ": " << value; setValue(name,value); } }
void OscController::parameterChanged(ofAbstractParameter & parameter){ string paramName = getParameterName(parameter); string address = getAddressByParamName(paramName); if(address == ""){ return; } ofxOscMessage msg; msg.setAddress(address); // NOTE: all parameters are sent as float args if(parameter.type()==typeid(ofParameter<int>).name()){ //msg.addFloatArg(parameter.cast<int>()); ofParameter<int> & p = parameter.cast<int>(); msg.addFloatArg( ofMap(p.get(), p.getMin(), p.getMax(), 0.0, 1.0) ); }else if(parameter.type()==typeid(ofParameter<float>).name()){ //msg.addFloatArg(parameter.cast<float>()); ofParameter<float> & p = parameter.cast<float>(); msg.addFloatArg( ofMap(p.get(), p.getMin(), p.getMax(), 0.0, 1.0) ); }else if(parameter.type()==typeid(ofParameter<bool>).name()){ msg.addFloatArg(parameter.cast<bool>()); } // send message // for (int i = 0; i < oscOut.size(); i++) { // oscOut[i]->sendMessage(msg); // } //senderTouchOSC.sendMessage(msg); senderVezer.sendMessage(msg); }
void ofSerialize(ofXml & xml, const ofAbstractParameter & parameter){ if(!parameter.isSerializable()){ return; } string name = parameter.getEscapedName(); if(name == ""){ name = "UnknownName"; } ofXml child = xml.findFirst(name); if(!child){ child = xml.appendChild(name); ofLogVerbose("ofXml") << "creating group " << name; } if(parameter.type() == typeid(ofParameterGroup).name()){ const ofParameterGroup & group = static_cast <const ofParameterGroup &>(parameter); ofLogVerbose("ofXml") << "group " << name; for(auto & p: group){ ofSerialize(child, *p); } ofLogVerbose("ofXml") << "end group " << name; }else{ string value = parameter.toString(); child.set(value); } }
//------------------------------------------------ bool guiValue::addValue(ofAbstractParameter ¶m){ if( param.getParent() ){ paramGroup.setName( param.getParent()->getName() ); } paramGroup.add(param); return true; }
string OscController::getParameterName(ofAbstractParameter ¶meter){ string paramName = ""; const vector<string> hierarchy = parameter.getGroupHierarchyNames(); for(int i=0; i<(int)hierarchy.size()-1; i++){ paramName += hierarchy[i] + "."; } paramName += parameter.getEscapedName(); return paramName; }
void ofXml::deserialize(ofAbstractParameter & parameter){ if(!parameter.isSerializable()) return; string name = parameter.getEscapedName(); if(parameter.type()==typeid(ofParameterGroup).name()){ ofParameterGroup & group = static_cast<ofParameterGroup&>(parameter); if(setTo(name)){ for(int i=0;i<group.size();i++){ deserialize(group.get(i)); } setToParent(); } }else{ if(exists(name)){ if(parameter.type()==typeid(ofParameter<int>).name()){ parameter.cast<int>() = getIntValue(name); }else if(parameter.type()==typeid(ofParameter<float>).name()){ parameter.cast<float>() = getFloatValue(name); }else if(parameter.type()==typeid(ofParameter<bool>).name()){ parameter.cast<bool>() = getBoolValue(name); }else if(parameter.type()==typeid(ofParameter<int64_t>).name()){ parameter.cast<int64_t>() = getInt64Value(name); }else if(parameter.type()==typeid(ofParameter<string>).name()){ parameter.cast<string>() = getValue(name); }else{ parameter.fromString(getValue(name)); } } } }
bool OscController::isMappeable(ofAbstractParameter & p) { // at the moment, there's no way to control multivalue parameters (colors, vectors, etc) with midi // a workarround would be exposing the color components (r,g,b) as individual parameters // eg: color1_r, color1_g, color1_b and color2_r, color2_g, color2_b if(p.type() == typeid(ofParameter<float>).name() || p.type() == typeid(ofParameter<int>).name() || p.type() == typeid(ofParameter<bool>).name()){ return true; } return false; }
void ofParameterGroup::swapPositions(ofAbstractParameter & param1, ofAbstractParameter & param2){ auto iter = obj->parametersIndex.find(param1.getName()); if (iter != obj->parametersIndex.end()){ auto iter2 = obj->parametersIndex.find(param2.getName()); if(iter != obj->parametersIndex.end()) { swapPositions(obj->parametersIndex[param1.getName()], obj->parametersIndex[param2.getName()]); } } }
void ofxOscSender::appendParameter( ofxOscMessage & msg, const ofAbstractParameter & parameter, string address){ msg.setAddress(address+parameter.getEscapedName()); if(parameter.type()==typeid(ofParameter<int>).name()){ msg.addIntArg(parameter.cast<int>()); }else if(parameter.type()==typeid(ofParameter<float>).name()){ msg.addFloatArg(parameter.cast<float>()); }else if(parameter.type()==typeid(ofParameter<bool>).name()){ msg.addIntArg(parameter.cast<bool>()); }else{ msg.addStringArg(parameter.toString()); } }
void ofDeserialize(const ofXml & xml, ofAbstractParameter & parameter){ if(!parameter.isSerializable()){ return; } string name = parameter.getEscapedName(); ofXml child = xml.findFirst(name); if(child){ if(parameter.type() == typeid(ofParameterGroup).name()){ ofParameterGroup & group = static_cast <ofParameterGroup &>(parameter); for(auto & p: group){ ofDeserialize(child, *p); } }else{ if(parameter.type() == typeid(ofParameter <int> ).name()){ parameter.cast <int>() = child.getIntValue(); }else if(parameter.type() == typeid(ofParameter <float> ).name()){ parameter.cast <float>() = child.getFloatValue(); }else if(parameter.type() == typeid(ofParameter <bool> ).name()){ parameter.cast <bool>() = child.getBoolValue(); }else if(parameter.type() == typeid(ofParameter <string> ).name()){ parameter.cast <string>() = child.getValue(); }else{ parameter.fromString(child.getValue()); } } } }
void ofxXmlSettings::deserialize(ofAbstractParameter & parameter){ if(!parameter.isSerializable()) return; string name = parameter.getEscapedName(); if(parameter.type()==typeid(ofParameterGroup).name()){ ofParameterGroup & group = static_cast<ofParameterGroup&>(parameter); if(tagExists(name)){ pushTag(name); for(int i=0;i<group.size();i++){ deserialize(group.get(i)); } popTag(); } }else{ if(tagExists(name)){ if(parameter.type()==typeid(ofParameter<int>).name()){ parameter.cast<int>() = getValue(name,0); }else if(parameter.type()==typeid(ofParameter<float>).name()){ parameter.cast<float>() = getValue(name,0.0f); }else if(parameter.type()==typeid(ofParameter<bool>).name()){ parameter.cast<bool>() = getValue(name,false); }else if(parameter.type()==typeid(ofParameter<string>).name()){ parameter.cast<string>() = getValue(name,""); }else{ parameter.fromString(getValue(name,"")); } } } }
void ofParameterGroup::remove(ofAbstractParameter ¶m){ std::for_each(obj->parameters.begin(), obj->parameters.end(), [&](shared_ptr<ofAbstractParameter>& p){ if(p->isReferenceTo(param)){ remove(param.getName()); } }); }
void ofParameterGroup::remove(ofAbstractParameter ¶m){ for(auto & p: obj->parameters){ if(p->isReferenceTo(param)){ remove(param.getName()); return; } } }
void audioVisualApp::onSettingChanged(ofAbstractParameter &p) { string name = p.getName(); if(name == "Play!") { if(outputOn) { soundPlayer->play(); } } }
//-------------------------------------------------------------- void PartyCLApp::paramsChanged(ofAbstractParameter& param) { string paramName = param.getName(); if (paramName == clusterScale.getName() || paramName == velocityScale.getName()) { bReset = true; } }
void audioVisualApp::onClipChanged(ofAbstractParameter &p) { string clipName = soundClips[p.getName()]; if(soundPlayer->isPlaying()) { soundPlayer->stop(); } soundPlayer->load(clipName); if(outputOn) { soundPlayer->play(); } }
void ofxOscSender::appendParameter( ofxOscBundle & _bundle, const ofAbstractParameter & parameter, string address){ if(parameter.type()==typeid(ofParameterGroup).name()){ ofxOscBundle bundle; const ofParameterGroup & group = static_cast<const ofParameterGroup &>(parameter); for(std::size_t i=0;i<group.size();i++){ const ofAbstractParameter & p = group[i]; if(p.isSerializable()){ appendParameter(bundle,p,address+group.getEscapedName()+"/"); } } _bundle.addBundle(bundle); }else{ if(parameter.isSerializable()){ ofxOscMessage msg; appendParameter(msg,parameter,address); _bundle.addMessage(msg); } } }
void ofParameterGroup::add(ofAbstractParameter & parameter){ shared_ptr<ofAbstractParameter> param = parameter.newReference(); const std::string name = param->getEscapedName(); if(obj->parametersIndex.find(name) != obj->parametersIndex.end()){ ofLogWarning() << "Adding another parameter with same name '" << param->getName() << "' to group '" << getName() << "'"; } obj->parameters.push_back(param); obj->parametersIndex[name] = obj->parameters.size()-1; param->setParent(*this); }
void ofxXmlSettings::serialize(const ofAbstractParameter & parameter){ if(!parameter.isSerializable()) return; string name = parameter.getEscapedName(); if(name=="") name="UnknownName"; if(parameter.type()==typeid(ofParameterGroup).name()){ const ofParameterGroup & group = static_cast<const ofParameterGroup&>(parameter); if(!tagExists(name)) addTag(name); pushTag(name); for(int i=0;i<group.size();i++){ serialize(group.get(i)); } popTag(); }else{ string value = parameter.toString(); if(!tagExists(name)) addValue(name,value); else setValue(name,value); } }
//-------------------------------------------------------------- bool MidiController::isMappeable(ofAbstractParameter & p) { // ignore non-serializable parameters (eg: toggles from buttons) if(!p.isSerializable()){ return false; } // TODO: // at the moment, there's no way to control multivalue parameters (like color, vector, etc) with midi // a solution would be exposing the color components in the renderers as individual // values like: color1_r, color1_g, color1_b and color2_r, color2_g, color2_b if(p.type() == typeid(ofParameter<ofColor>).name() || p.type() == typeid(ofParameter<ofFloatColor>).name()){ return false; } if(p.type() == typeid(ofParameter<float>).name() || p.type() == typeid(ofParameter<int>).name() || p.type() == typeid(ofParameter<bool>).name()){ return true; } return false; }
void ofxOscSender::sendParameter( const ofAbstractParameter & parameter){ if(!parameter.isSerializable()) return; if(parameter.type()==typeid(ofParameterGroup).name()){ string address = "/"; const vector<string> hierarchy = parameter.getGroupHierarchyNames(); for(int i=0;i<(int)hierarchy.size()-1;i++){ address+=hierarchy[i] + "/"; } ofxOscBundle bundle; appendParameter(bundle,parameter,address); sendBundle(bundle); }else{ string address = ""; const vector<string> hierarchy = parameter.getGroupHierarchyNames(); for(int i=0;i<(int)hierarchy.size()-1;i++){ address+= "/" + hierarchy[i]; } if(address.length()) address += "/"; ofxOscMessage msg; appendParameter(msg,parameter,address); sendMessage(msg, false); } }
void ofParameterGroup::add(ofAbstractParameter & param) { obj->parameters.push_back(¶m); obj->parametersIndex[param.getEscapedName()] = obj->parameters.size()-1; param.setParent(this); }
bool ofAbstractParameter::isReferenceTo(const ofAbstractParameter &other) const{ return getInternalObject() == other.getInternalObject(); }
void ofParameterGroup::add(ofAbstractParameter & parameter){ shared_ptr<ofAbstractParameter> param = parameter.newReference(); obj->parameters.push_back(param); obj->parametersIndex[param->getEscapedName()] = obj->parameters.size()-1; param->setParent(*this); }
bool OscController::isGroup(ofAbstractParameter& p){ if(p.type() == typeid(ofParameterGroup).name()){ return true; } return false; }