bool SmugMug::getSubCategoryList(OwnedArray<SubCategory>& subCategories) { StringPairArray params; XmlElement* n = smugMugRequest(("smugmug.subcategories.getAll"), params); if (n) { XmlElement* c = n->getChildByName(("SubCategories")); if (c) { XmlElement* subCat = c->getChildByName(("SubCategory")); while (subCat) { SubCategory* subCategory = new SubCategory(); subCategory->id = subCat->getIntAttribute(("id")); subCategory->title = subCat->getStringAttribute(("Name")); XmlElement* cat = subCat->getChildByName(("Category")); if (cat) subCategory->parentId = cat->getIntAttribute(("id")); subCategories.add(subCategory); subCat = subCat->getNextElementWithTagName(("SubCategory")); } } delete n; return true; } return false; }
bool SmugMug::getAlbumList(OwnedArray<Album>& albums) { StringPairArray params; XmlElement* n = smugMugRequest(("smugmug.albums.get"), params); if (n) { XmlElement* a = n->getChildByName(("Albums")); if (a) { XmlElement* alb = a->getChildByName(("Album")); while (alb) { Album* album = new Album(); album->id.id = alb->getIntAttribute(("id")); album->id.key = alb->getStringAttribute(("Key")); album->title = alb->getStringAttribute(("Title")); XmlElement* cat = alb->getChildByName(("Category")); if (cat) { album->category = cat->getStringAttribute(("Name")); album->categoryId = cat->getIntAttribute(("id")); } else { album->category = String::empty; album->categoryId = -1; } XmlElement* subcat = alb->getChildByName(("SubCategory")); if (subcat) { album->subCategory = subcat->getStringAttribute(("Name")); album->subCategoryId = subcat->getIntAttribute(("id")); } else { album->subCategory = String::empty; album->subCategoryId = -1; } albums.add(album); alb = alb->getNextElementWithTagName(("Album")); } } delete n; return true; } return false; }
SmugID SmugMug::createAlbum(const String& title, const int categoryId, const StringPairArray& albumFlags) { SmugID newAlbum; newAlbum.id = -1; StringPairArray params(albumFlags); params.set(("Title"), title); params.set(("CategoryID"), String(categoryId)); XmlElement* n = smugMugRequest(("smugmug.albums.create"), params); if (n) { XmlElement* a = n->getChildByName(("Album")); if (a) { newAlbum.id = a->getIntAttribute(("id"), -1); newAlbum.key = a->getStringAttribute(("Key")); } if (newAlbum.id != -1) addLogEntry(("Info: album created: ") + title); delete n; } return newAlbum; }
bool SmugMug::getCategoryList(OwnedArray<Category>& categories) { StringPairArray params; XmlElement* n = smugMugRequest(("smugmug.categories.get"), params); if (n) { XmlElement* c = n->getChildByName(("Categories")); if (c) { XmlElement* cat = c->getChildByName(("Category")); while (cat) { Category* category = new Category(); category->id = cat->getIntAttribute(("id")); category->title = cat->getStringAttribute(("Name")); categories.add(category); cat = cat->getNextElementWithTagName(("Category")); } } delete n; return true; } return false; }
void TreeView::restoreOpennessState (const XmlElement& newState) { if (rootItem != 0) { rootItem->restoreOpennessState (newState); if (newState.hasAttribute ("scrollPos")) viewport->setViewPosition (viewport->getViewPositionX(), newState.getIntAttribute ("scrollPos")); } }
bool PluginDescription::loadFromXml (const XmlElement& xml) { if (xml.hasTagName ("PLUGIN")) { name = xml.getStringAttribute ("name"); descriptiveName = xml.getStringAttribute ("descriptiveName", name); pluginFormatName = xml.getStringAttribute ("format"); category = xml.getStringAttribute ("category"); manufacturerName = xml.getStringAttribute ("manufacturer"); version = xml.getStringAttribute ("version"); fileOrIdentifier = xml.getStringAttribute ("file"); uid = xml.getStringAttribute ("uid").getHexValue32(); isInstrument = xml.getBoolAttribute ("isInstrument", false); lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64()); numInputChannels = xml.getIntAttribute ("numInputs"); numOutputChannels = xml.getIntAttribute ("numOutputs"); return true; } return false; }
bool JucerDocument::loadFromXml (const XmlElement& xml) { if (xml.hasTagName (jucerCompXmlTag) && getTypeName().equalsIgnoreCase (xml.getStringAttribute ("documentType"))) { className = xml.getStringAttribute ("className", defaultClassName); templateFile = xml.getStringAttribute ("template", String::empty); componentName = xml.getStringAttribute ("componentName", String::empty); parentClasses = xml.getStringAttribute ("parentClasses", defaultParentClasses); constructorParams = xml.getStringAttribute ("constructorParams", String::empty); variableInitialisers = xml.getStringAttribute ("variableInitialisers", String::empty); fixedSize = xml.getBoolAttribute ("fixedSize", false); initialWidth = xml.getIntAttribute ("initialWidth", 300); initialHeight = xml.getIntAttribute ("initialHeight", 200); snapGridPixels = xml.getIntAttribute ("snapPixels", snapGridPixels); snapActive = xml.getBoolAttribute ("snapActive", snapActive); snapShown = xml.getBoolAttribute ("snapShown", snapShown); componentOverlayOpacity = (float) xml.getDoubleAttribute ("overlayOpacity", 0.0); activeExtraMethods.clear(); if (XmlElement* const methods = xml.getChildByName ("METHODS")) forEachXmlChildElementWithTagName (*methods, e, "METHOD") activeExtraMethods.addIfNotAlreadyThere (e->getStringAttribute ("name")); activeExtraMethods.trim(); activeExtraMethods.removeEmptyStrings(); changed(); getUndoManager().clearUndoHistory(); return true; } return false; }
bool SmugMug::getImages(OwnedArray<ImageItem>& images, SmugID albumId) { StringPairArray params; params.set(("AlbumID"), String(albumId.id)); params.set(("AlbumKey"), albumId.key); params.set(("Heavy"), ("1")); XmlElement* n = smugMugRequest(("smugmug.images.get"), params); if (n) { XmlElement* a = n->getChildByName(("Album")); if (a) { XmlElement* i = a->getChildByName(("Images")); if (i) { XmlElement* img = i->getChildByName(("Image")); while (img) { ImageItem* itm = new ImageItem(); itm->id.id = img->getIntAttribute(("id")); itm->id.key = img->getStringAttribute(("Key")); itm->filename = img->getStringAttribute(("FileName")); itm->caption = img->getStringAttribute(("")); itm->keywords = img->getStringAttribute(("")); itm->position = img->getIntAttribute(("Position")); itm->date = img->getStringAttribute(("Date")); itm->format = img->getStringAttribute(("Format")); itm->serial = img->getIntAttribute(("Serial")); itm->watermark = img->getBoolAttribute(("Watermark")); itm->size = img->getIntAttribute(("Size")); itm->width = img->getIntAttribute(("Width")); itm->height = img->getIntAttribute(("Height")); itm->md5sum = img->getStringAttribute(("MD5Sum")); itm->lastUpdated = img->getStringAttribute(("LastUpdated")); itm->originalURL = img->getStringAttribute(("OriginalURL")); itm->largeURL = img->getStringAttribute(("LargeURL")); itm->mediumURL = img->getStringAttribute(("MediumURL")); itm->smallURL = img->getStringAttribute(("SmallURL")); itm->tinyURL = img->getStringAttribute(("TinyURL")); itm->thumbURL = img->getStringAttribute(("ThumbURL")); itm->albumURL = img->getStringAttribute(("AlbumURL")); images.add(itm); img = img->getNextElementWithTagName(("Image")); } } } delete n; return images.size() > 0; } return false; }
void CommandTableModel::buildFromXml(XmlElement *root) { if (root->getTagName().compare("settings") != 0) return; removeAllRows(); XmlElement* setting = root->getFirstChildElement(); while ((setting) && (m_commandMap)) { if (setting->hasAttribute("controller")) { MIDI_Message cc(setting->getIntAttribute("channel"), setting->getIntAttribute("controller"), true); addRow(cc.channel, cc.controller, true); // older versions of MIDI2LR stored the index of the string, so we should attempt to parse this as well if (setting->getIntAttribute("command", -1) != -1) { m_commandMap->addCommandforMessage(setting->getIntAttribute("command"), cc); } else { m_commandMap->addCommandforMessage(setting->getStringAttribute("command_string"), cc); } } else if (setting->hasAttribute("note")) { MIDI_Message note(setting->getIntAttribute("channel"), setting->getIntAttribute("note"), false); addRow(note.channel, note.pitch, false); // older versions of MIDI2LR stored the index of the string, so we should attempt to parse this as well if (setting->getIntAttribute("command", -1) != -1) { m_commandMap->addCommandforMessage(setting->getIntAttribute("command"), note); } else { m_commandMap->addCommandforMessage(setting->getStringAttribute("command_string"), note); } } setting = setting->getNextElement(); } }
int SmugMug::createCategory(const String& title) { int catId = -1; StringPairArray params; params.set(("Name"), title); XmlElement* n = smugMugRequest(("smugmug.categories.create"), params); if (n) { XmlElement* a = n->getChildByName(("Category")); if (a) catId = a->getIntAttribute(("id"), -1); delete n; } return catId; }
void Equalizer::updateFromXML (XmlElement *xml) { Ppreset = xml->getIntAttribute (T("prst"), Ppreset); XmlElement* e = xml->getChildByName (T("fxpar")); if (e) { for (int n = 0; n < 128; n++) { setParameter (n, 0); XmlElement* pe = e->getChildByName (T("p") + String (n)); if (pe) setParameter (n, pe->getIntAttribute (T("v"), getParameter (n))); } } clean(); }
void pspRandomSystem::loadXml(juce::File xmlFile){ XmlDocument myDocument (xmlFile); XmlElement* mainElement = myDocument.getDocumentElement(); if (mainElement == nullptr) { AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "error loading randomTrajectory xml file !", "", "OK"); delete mainElement; return; } else{ if(!mainElement->hasTagName("RandomTrajectory")){ AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "xml file doesn't randomTrajectory data", "", "OK"); delete mainElement; return; } else{ XmlElement* params = mainElement->getChildByName("parameterValues"); if(params){ int np = params->getIntAttribute("numParticles"); changeNumParticles(np); static_cast<pspParticleSystemGUIGenericComponent*>(myGui->getGenericComponent())->getNumParticleSlider()->setValue(np); setBounds(1, params->getDoubleAttribute("lxMin")); setBounds(2, params->getDoubleAttribute("lxMax")); setBounds(3, params->getDoubleAttribute("lyMin")); setBounds(4, params->getDoubleAttribute("lyMax")); setBounds(5, params->getDoubleAttribute("lzMin")); setBounds(6, params->getDoubleAttribute("lzMax")); static_cast<pspRandomSystemSpecificGUI*>(mySpecificGui)->setSliderValues(params->getDoubleAttribute("lxMin"), params->getDoubleAttribute("lxMax"), params->getDoubleAttribute("lyMin"), params->getDoubleAttribute("lxMax"), params->getDoubleAttribute("lzMin"), params->getDoubleAttribute("lzMax")); } } } delete mainElement; }
bool SmugMug::getNumberOfViews(int month, int year, OwnedArray<Views>& albums, OwnedArray<Views>& images) { StringPairArray params; params.set(("Month"), String(month)); params.set(("Year"), String(year)); XmlElement* n = smugMugRequest(("smugmug.users.getTransferStats"), params); if (n) { XmlElement* albs = n->getChildByName(("Albums")); if (albs) { XmlElement* alb = albs->getChildByName(("Album")); while (alb) { Views* v = new Views(); v->id = alb->getIntAttribute(("id")); v->views = alb->getIntAttribute(("Tiny")) + alb->getIntAttribute(("Small")) + alb->getIntAttribute(("Medium")) + alb->getIntAttribute(("Large")) + roundDoubleToInt(alb->getDoubleAttribute(("Original"))); albums.add(v); XmlElement* img = n->getChildByName(("Image")); while (img) { Views* v = new Views(); v->id = img->getIntAttribute(("id")); v->views = img->getIntAttribute(("Tiny")) + img->getIntAttribute(("Small")) + img->getIntAttribute(("Medium")) + img->getIntAttribute(("Large")) + roundDoubleToInt(img->getDoubleAttribute(("Original"))); img = img->getNextElementWithTagName(("Image")); } alb = alb->getNextElementWithTagName(("Album")); } } delete n; return true; } return false; }
bool ComponentTypeHandler::restoreFromXml (const XmlElement& xml, Component* comp, const ComponentLayout* layout) { jassert (xml.hasTagName (getXmlTagName())); if (! xml.hasTagName (getXmlTagName())) return false; comp->setName (xml.getStringAttribute ("name", comp->getName())); setComponentId (comp, xml.getStringAttribute ("id").getHexValue64()); comp->getProperties().set ("memberName", xml.getStringAttribute ("memberName")); comp->getProperties().set ("virtualName", xml.getStringAttribute ("virtualName")); comp->setExplicitFocusOrder (xml.getIntAttribute ("explicitFocusOrder")); RelativePositionedRectangle currentPos (getComponentPosition (comp)); currentPos.updateFromComponent (*comp, layout); RelativePositionedRectangle rpr; rpr.restoreFromXml (xml, currentPos); jassert (layout != 0); setComponentPosition (comp, rpr, layout); SettableTooltipClient* const ttc = dynamic_cast <SettableTooltipClient*> (comp); if (ttc != 0) ttc->setTooltip (xml.getStringAttribute ("tooltip")); for (int i = 0; i < colours.size(); ++i) { const String col (xml.getStringAttribute (colours[i]->xmlTagName, String::empty)); if (col.isNotEmpty()) { comp->setColour (colours[i]->colourId, Colour (col.getHexValue32())); } } return true; }
SmugID SmugMug::uploadFile(int queue, int index) { SmugID retval; lock.enter(); UploadFile& uf = uploadQueue[queue]->getImageFileInfo(index); lock.exit(); int64 bytesDone = 0; MD5 md5(uf.file); Time start = Time::getCurrentTime(); startTimer(LOGOUT_TIMER); String headers; String filename = uf.file.getFileName(); headers = "PUT http://upload.smugmug.com/" + URL::addEscapeChars(filename, false) + " HTTP/1.1\r\n" + "Host: upload.smugmug.com\r\n" + "Content-Length: " + String(uf.file.getSize()) + "\r\n" + "Content-MD5: " + md5.toHexString() + "\r\n" + "X-Smug-SessionID: " + sessionId + "\r\n" + "X-Smug-Version: 1.2.2\r\n" + "X-Smug-ResponseType: REST\r\n" + "X-Smug-AlbumID: " + String(uploadQueue[queue]->getAlbumId().id) + "\r\n" + "X-Smug-FileName: " + filename + "\r\n\r\n"; #ifdef JUCE_DEBUG Logger::outputDebugString(headers); #endif const char* headerUtf8 = headers.toUTF8(); StreamingSocket soc; if (soc.connect("upload.smugmug.com", 80)) { int bytesWritten = soc.write(headerUtf8, (int)strlen(headerUtf8)); if (bytesWritten == -1) { uf.status = UploadFile::Failed; return retval; } FileInputStream* fos = uf.file.createInputStream(); if (fos) { char buffer[1024 * 8]; while (!fos->isExhausted()) { int in = fos->read(buffer, sizeof(buffer)); int out = soc.write(buffer, in); startTimer(LOGOUT_TIMER); if (in != out) { delete fos; uf.status = UploadFile::Failed; return retval; } else { bytesDone += in; uf.complete = float(bytesDone)/float(uf.file.getSize()); } if (uf.status == UploadFile::Cancelled) { delete fos; return retval; } } delete fos; } else { uf.status = UploadFile::Failed; return retval; } String response; response.preallocateBytes(1024); while (1) { char buffer; int read = soc.read(&buffer, 1, true); if (read == -1) break; response += buffer; if (response.endsWith(("\r\n\r\n")) || response.endsWith(("\n\n"))) { String len = response.fromFirstOccurrenceOf(("Content-Length: "), false, true); if (len.isNotEmpty()) { // normal mode String num; int i = 0; while (CharacterFunctions::isDigit(len[i])) num += len[i++]; int bytes = num.getIntValue(); char* buffer = new char[bytes + 1]; soc.read(buffer, bytes, true); buffer[bytes] = 0; response += buffer; delete[] buffer; } else { // chunked while (1) { String line; char ch; while (!line.endsWith("\r\n")) { soc.read(&ch, 1, true); line += ch; } int sz = line.getHexValue32(); if (sz == 0) break; char* buf = new char[sz + 1]; soc.read(buf, sz, true); buf[sz] = 0; response += buf; delete buf; soc.read(&ch, 1, true); soc.read(&ch, 1, true); } } #ifdef JUCE_DEBUG Logger::outputDebugString(response); #endif soc.close(); String xml = response.fromFirstOccurrenceOf(("<?xml"), true, true); XmlDocument doc(xml); XmlElement* e = doc.getDocumentElement(); if (e) { XmlElement* image = e->getChildByName(("Image")); if (image) { int val = image->getIntAttribute(("id")); if (val >= 0) { uf.status = UploadFile::Finished; uf.complete = 1.0f; uf.url = image->getStringAttribute("URL"); Time end = Time::getCurrentTime(); RelativeTime diff = end - start; addLogEntry(("Info: ") + uf.file.getFileName() + (" uploaded in ") + String(int(diff.inSeconds())) + (" seconds [") + String(uf.file.getSize() / 1024 / diff.inSeconds(), 1) + ("KB/s]")); retval.id = val; retval.key = image->getStringAttribute(("Key")); delete e; return retval; } } delete e; } } } } uf.status = UploadFile::Failed; return retval; }
void ZenTime::setFromXML(const XmlElement& inXML) { //DBG("In ZenParameter::setFromXML(inXML) "); XmlElement* thisXML = inXML.getChildByName(paramID); setValueFromMS(thisXML->getIntAttribute("valueInMS", -987654321)); }
String AudioDeviceManager::initialiseFromXML (const XmlElement& xml, const bool selectDefaultDeviceOnFailure, const String& preferredDefaultDeviceName, const AudioDeviceSetup* preferredSetupOptions) { lastExplicitSettings = new XmlElement (xml); String error; AudioDeviceSetup setup; if (preferredSetupOptions != nullptr) setup = *preferredSetupOptions; if (xml.getStringAttribute ("audioDeviceName").isNotEmpty()) { setup.inputDeviceName = setup.outputDeviceName = xml.getStringAttribute ("audioDeviceName"); } else { setup.inputDeviceName = xml.getStringAttribute ("audioInputDeviceName"); setup.outputDeviceName = xml.getStringAttribute ("audioOutputDeviceName"); } currentDeviceType = xml.getStringAttribute ("deviceType"); if (findType (currentDeviceType) == nullptr) { if (AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName)) currentDeviceType = type->getTypeName(); else if (availableDeviceTypes.size() > 0) currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName(); } setup.bufferSize = xml.getIntAttribute ("audioDeviceBufferSize", setup.bufferSize); setup.sampleRate = xml.getDoubleAttribute ("audioDeviceRate", setup.sampleRate); setup.inputChannels .parseString (xml.getStringAttribute ("audioDeviceInChans", "11"), 2); setup.outputChannels.parseString (xml.getStringAttribute ("audioDeviceOutChans", "11"), 2); setup.useDefaultInputChannels = ! xml.hasAttribute ("audioDeviceInChans"); setup.useDefaultOutputChannels = ! xml.hasAttribute ("audioDeviceOutChans"); error = setAudioDeviceSetup (setup, true); midiInsFromXml.clear(); forEachXmlChildElementWithTagName (xml, c, "MIDIINPUT") midiInsFromXml.add (c->getStringAttribute ("name")); const StringArray allMidiIns (MidiInput::getDevices()); for (int i = allMidiIns.size(); --i >= 0;) setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i])); if (error.isNotEmpty() && selectDefaultDeviceOnFailure) error = initialise (numInputChansNeeded, numOutputChansNeeded, nullptr, false, preferredDefaultDeviceName); setDefaultMidiOutput (xml.getStringAttribute ("defaultMidiOutput")); return error; }
void Track::LoadXml(XmlElement* e, StringArray& errors, int formatVersion) { if (e->hasTagName(tag::kTrack)) { this->SetName(e->getStringAttribute(tag::kName, "")); this->Mute(e->getBoolAttribute(tag::kMuted)); this->SetActive(e->getBoolAttribute(tag::kActive, false)); this->SetInputGain(e->getDoubleAttribute(tag::kInputGain, 0)); this->SetInputPan(e->getDoubleAttribute(tag::kPan, 0.5)); this->SetOutputVolume(e->getDoubleAttribute("outputVolume", 0)); bool isSoloed = e->getBoolAttribute(tag::kSoloed, false); if (isSoloed) { fScumbler->SoloTrack(this); } int channels = e->getIntAttribute(tag::kChannels, tk::kStereo); // handle the pre-effect block. XmlElement* pre = e->getChildByName(tag::kPreBlock); if (pre) { fPreEffects->LoadXml(pre, errors, formatVersion); } else { errors.add("File format error -- missing <pre> effects block."); } // restore the loop parameters XmlElement* loop = e->getChildByName(tag::kLoop); if (loop) { fLoop->SetLoopDuration(loop->getIntAttribute(tag::kLoopDuration, 4000)); fLoop->SetFeedback(loop->getDoubleAttribute(tag::kLoopFeedback, 0.9)); //fLoop->SeekAbsolute(loop->getIntAttribute(tag::kLoopPosition, 0)); } else { errors.add("File format error -- missing <loop> information"); } // handle the post-effect block XmlElement* post = e->getChildByName(tag::kPostBlock); if (post) { fPostEffects->LoadXml(post, errors, formatVersion); } else { errors.add("File format error -- missing <post> effects block"); } } else { errors.add("File format error -- missing <track> data"); } }
void MLPluginProcessor::setStateFromXML(const XmlElement& xmlState, bool setViewAttributes) { if (!(xmlState.hasTagName (JucePlugin_Name))) return; if (!(mEngine.getCompileStatus() == MLProc::OK)) return; // TODO revisit need to compile first // getCallbackLock() is in juce_AudioProcessor // process lock is a quick fix. it is here to prevent doParams() from getting called in // process() methods and thereby setting mParamsChanged to false before the real changes take place. // A better alternative would be a lock-free queue of parameter changes. const ScopedLock sl (getCallbackLock()); // only the differences between default parameters and the program state are saved in a program, // so the first step is to set the default parameters. setDefaultParameters(); // get program version of saved state unsigned blobVersion = xmlState.getIntAttribute ("pluginVersion"); unsigned pluginVersion = JucePlugin_VersionCode; if (blobVersion > pluginVersion) { // TODO show error to user MLError() << "MLPluginProcessor::setStateFromXML: saved program version is newer than plugin version!\n"; return; } // try to load scale if a scale attribute exists // TODO auto save all state including this const String scaleDir = xmlState.getStringAttribute ("scaleDir"); // look for old-style dir attribute const String scaleName = xmlState.getStringAttribute ("scaleName"); String fullName; if(scaleName != String::empty) { fullName = scaleName; if(scaleDir != String::empty) { fullName = scaleDir + String("/") + fullName + ".scl"; } } else { fullName = "12-equal"; } std::string fullScaleName(fullName.toUTF8()); setProperty("key_scale", fullScaleName); bool loaded = false; // look for scale under full name with path if(fullScaleName != std::string()) { const MLFilePtr f = mScaleFiles->getFileByName(fullScaleName); if(f != MLFilePtr()) { loadScale(f->mFile); loaded = true; } } if(!loaded) { loadDefaultScale(); } // get preset name saved in blob. when saving from AU host, name will also be set from RestoreState(). const String presetName = xmlState.getStringAttribute ("presetName"); setProperty("preset", std::string(presetName.toUTF8())); /* debug() << "MLPluginProcessor: setStateFromXML: loading program " << presetName << ", version " << std::hex << blobVersion << std::dec << "\n"; MemoryOutputStream myStream; xmlState->writeToStream (myStream, ""); debug() << myStream.toString(); */ /* setCurrentPresetName(presetName.toUTF8()); setCurrentPresetDir(presetDir.toUTF8()); */ // get plugin-specific translation table for updating older versions of data std::map<MLSymbol, MLSymbol> translationTable; // TODO move this into Aalto! // make translation tables based on program version. // if (blobVersion <= 0x00010120) { // translate seq parameters for(unsigned n=0; n<16; ++n) { std::stringstream pName; std::stringstream pName2; pName << "seq_value" << n; pName2 << "seq_pulse" << n; MLSymbol oldSym(pName.str()); MLSymbol newSym = MLSymbol("seq_value#").withFinalNumber(n); MLSymbol oldSym2(pName2.str()); MLSymbol newSym2 = MLSymbol("seq_pulse#").withFinalNumber(n); translationTable[oldSym] = newSym; translationTable[oldSym2] = newSym2; } } if (blobVersion <= 0x00010200) { MLSymbol oldSym = MLSymbol("seq_value"); MLSymbol newSym = MLSymbol("seq_value").withFinalNumber(0); MLSymbol oldSym2 = MLSymbol("seq_pulse"); MLSymbol newSym2 = MLSymbol("seq_pulse").withFinalNumber(0); translationTable[oldSym] = newSym; translationTable[oldSym2] = newSym2; // translate seq parameters for(unsigned n=1; n<16; ++n) { oldSym = MLSymbol("seq_value#").withFinalNumber(n); newSym = MLSymbol("seq_value").withFinalNumber(n); oldSym2 = MLSymbol("seq_pulse#").withFinalNumber(n); newSym2 = MLSymbol("seq_pulse").withFinalNumber(n); translationTable[oldSym] = newSym; translationTable[oldSym2] = newSym2; } } // get params from xml const unsigned numAttrs = xmlState.getNumAttributes(); String patcherInputStr ("patcher_input_"); for(unsigned i=0; i<numAttrs; ++i) { // get name / value pair. const String& attrName = xmlState.getAttributeName(i); const MLParamValue paramVal = xmlState.getDoubleAttribute(attrName); // if not a patcher input setting, if (!attrName.contains(patcherInputStr)) { // see if we have this named parameter in our engine. MLSymbol paramSym = XMLAttrToSymbol(attrName); const int pIdx = getParameterIndex(paramSym); if (pIdx >= 0) { // debug() << "setStateFromXML: <" << paramSym << " = " << paramVal << ">\n"; setPropertyImmediate(paramSym, paramVal); } else // try finding a match through translation table. { //debug() << "Looking for parameter " << paramSym << " in table...\n"; std::map<MLSymbol, MLSymbol>::iterator it; it = translationTable.find(paramSym); if (it != translationTable.end()) { const MLSymbol newSym = translationTable[paramSym]; const int pNewIdx = getParameterIndex(newSym); if (pNewIdx >= 0) { //debug() << "translated parameter to " << newSym << " .\n"; setPropertyImmediate(newSym, paramVal); } else { MLError() << "MLPluginProcessor::setStateFromXML: no such parameter! \n"; } } else { // fail silently on unfound params, because we have deprecated some but they may still // be around in old presets. //debug() << "MLPluginProcessor::setStateFromXML: parameter " << paramSym << " not found!\n"; } } } } // get editor state from XML if(setViewAttributes) { int x = xmlState.getIntAttribute("editor_x"); int y = xmlState.getIntAttribute("editor_y"); int width = xmlState.getIntAttribute("editor_width"); int height = xmlState.getIntAttribute("editor_height"); mEditorRect = MLRect(x, y, width, height); mEditorNumbersOn = xmlState.getIntAttribute("editor_num", 1); mEditorAnimationsOn = xmlState.getIntAttribute("editor_anim", 1); } }
void PMixDocument::createNodeFromXml (XmlElement& xml, const String& newSourceCode) { PluginDescription pd; forEachXmlChildElement (xml, e) { if (pd.loadFromXml (*e)) break; } String errorMessage; AudioPluginInstance* instance = audioEngine.createPluginInstance(pd, errorMessage); jassert(instance != nullptr); if (pd.pluginFormatName == "FAUST") { FaustAudioPluginInstance* faustProc = dynamic_cast<FaustAudioPluginInstance*>(instance); faustProc->initialize(getLibraryPath(), drawPath); if (newSourceCode.length()) faustProc->setSourceCode(newSourceCode, true); // TODO: this is a bit wrong! faustProc->prepareToPlay(44100., 8192); // xml.setAttribute("numInputs", faustProc->getNumInputChannels()); // xml.setAttribute("numOutputs", faustProc->getNumOutputChannels()); ??? } AudioProcessorGraph::Node::Ptr node (audioEngine.getGraph().addNode (instance, xml.getIntAttribute ("uid"))); if (!newSourceCode.length()) { if (const XmlElement* const state = xml.getChildByName ("STATE")) { MemoryBlock m; m.fromBase64Encoding (state->getAllSubText()); node->getProcessor()->setStateInformation (m.getData(), (int) m.getSize()); } } node->properties.set ("x", xml.getDoubleAttribute ("x")); node->properties.set ("y", xml.getDoubleAttribute ("y")); node->properties.set ("uiLastX", xml.getIntAttribute ("uiLastX")); node->properties.set ("uiLastY", xml.getIntAttribute ("uiLastY")); node->properties.set ("uiStatus", xml.getIntAttribute ("uiStatus")); // presets etc for faust & plugin nodes if(!InternalPluginFormat::isInternalFormat(pd.name)) { node->properties.set ("colour", xml.getStringAttribute ("colour")); node->properties.set ("iposx", xml.getDoubleAttribute ("iposx")); node->properties.set ("iposy", xml.getDoubleAttribute ("iposy")); if (const XmlElement* const params = xml.getChildByName ("PARAMS")) { var vparams = JSON::parse(params->getAllSubText()); node->properties.set ("params", vparams); } Array<var> presetsArr; forEachXmlChildElement (xml, e) { if (e->hasTagName ("PRESET")) { DynamicObject* obj = new DynamicObject(); obj->setProperty("name", e->getStringAttribute("name")); obj->setProperty("x", e->getDoubleAttribute("x")); obj->setProperty("y", e->getDoubleAttribute("y")); obj->setProperty("radius", e->getDoubleAttribute("radius")); obj->setProperty("hidden", e->getBoolAttribute("hidden")); // obj->setProperty("distance", e->getDoubleAttribute("distance")); obj->setProperty("coeff", e->getDoubleAttribute("coeff")); var vparams = JSON::parse(e->getAllSubText()); obj->setProperty("state", vparams); obj->setProperty("uid", e->getIntAttribute("uid")); var preset = var(obj); presetsArr.add(preset); } } node->properties.set("presets", presetsArr); }