Beispiel #1
0
XmlElementPtr XmlElement::getFirstChildByName(const string& name) const {
    XmlElementList&& vec = XmlElement::getChildren();
    for (auto iter = vec.begin(), end = vec.end(); iter != end; ++iter ) {
        if (iter->getName() == name) {
            return make_shared<XmlElement>(*iter);
        }
    }
    return XmlElementPtr();
}
Beispiel #2
0
void MLPluginProcessor::getStateAsXML (XmlElement& xml)
{
	if( !(mEngine.getCompileStatus() == MLProc::OK)) return;
	
#if DEMO	
	xml.setAttribute ("pluginVersion", JucePlugin_VersionCode);	
    xml.setAttribute ("presetName", String("----"));	
#else

  	const unsigned numParams = getNumParameters();

	// TODO use string properties of model instead of these JUCE strings.
	// also move to JSON.
	xml.setAttribute ("pluginVersion", JucePlugin_VersionCode);
	xml.setAttribute ("presetName", String(getStringProperty("preset").c_str()));
	xml.setAttribute ("scaleName", String(getStringProperty("key_scale").c_str()));

	// store parameter values to xml as a bunch of attributes.
	// not XML best practice in general but takes fewer characters.
	for(unsigned i=0; i<numParams; ++i)
	{
		const String paramName = symbolToXMLAttr(getParameterAlias(i));
		const float defaultVal = getParameterDefault(i);
		const float paramVal = getParameter(i);
		if (paramVal != defaultVal)
		{
			xml.setAttribute(paramName, paramVal);		
			//debug() << "setting XML param " << paramName << " to " << paramVal << "\n";
		}
	}

	// store patcher info to xml
	{			
		MLProcList patchers = getPatcherList();
		if (!patchers.empty())
		{
			MLProcPatcher& firstPatcher = static_cast<MLProcPatcher&>(**patchers.begin());
			const int inputs = firstPatcher.getParam("inputs");
			const int outputs = firstPatcher.getParam("outputs");
			String outStr;
			String patcherInput = "patcher_input_";
			
			for(unsigned i=1; i<=inputs; ++i)
			{
				bool differentFromDefault = false;
				outStr = "";
				for(unsigned j=1; j<=outputs; ++j)
				{
					if (firstPatcher.getConnection(i, j))
					{
						outStr += "1";
						differentFromDefault = true;
					}
					else
					{
						outStr += "0";
					}
				}
				if(differentFromDefault)
				{
					String outNum (i); 
					xml.setAttribute(patcherInput + outNum, outStr);	
				}				
			}
		}
	}	
	
	// store editor state to XML if one exists	
	MLPluginEditor* pEditor = static_cast<MLPluginEditor*>(getActiveEditor());
	if(pEditor)
	{
		MLRect r = pEditor->getWindowBounds();
		xml.setAttribute("editor_x", r.x());	
		xml.setAttribute("editor_y", r.y());	
		xml.setAttribute("editor_width", r.getWidth());	
		xml.setAttribute("editor_height", r.getHeight());
		xml.setAttribute("editor_num", getFloatProperty("patch_num"));	
		xml.setAttribute("editor_anim", getFloatProperty("patch_anim"));	
	}
	
	// save blob as most recently saved state
	mpLatestStateLoaded = XmlElementPtr(new XmlElement(xml));
	
#endif

}