M_scquantizer::M_scquantizer(QWidget* parent, QString *p_sclname) : Module(M_type_scquantizer, 2, parent, tr("Scala Quantizer")) { QString qs; int l1; setGeometry(MODULE_NEW_X, MODULE_NEW_Y, MODULE_DEFAULT_WIDTH, MODULE_SCQUANTIZER_HEIGHT); port_M_in = new Port(tr("In"), PORT_IN, 0, this); port_M_trigger = new Port(tr("Trigger"), PORT_IN, 1, this); port_M_transpose = new Port(tr("Transpose"), PORT_IN, 2, this); cv.out_off = 95; port_out = new Port(tr("Out"), PORT_OUT, 0, this); port_trigger_out = new Port(tr("Trigger Out"), PORT_OUT, 1, this); base = 0; lastbase = 12; configDialog->addIntSlider(tr("&Note Offset"), base, -36, 36); sclname = "No_Scale_loaded"; configDialog->addLabel(tr(" Scale: ") + sclname); configDialog->addLabel(" "); //!! configDialog->addPushButton("Load Scale"); // QObject::connect(configDialog->midiPushButtonList.at(0), SIGNAL(clicked()), // this, SLOT(openBrowser())); fileDialog = NULL; for (l1 = 0; l1 < 12; l1++) { scale_lut_isRatio[l1] = false; scale_lut[l1] = 100.0 + (float)l1 * 100.0; } scale_lut_isRatio[12] = true; scale_lut[12] = 2.0; scale_lut_length = 12; dirpath.sprintf("%s", getenv("SCALA_PATH")); if (dirpath.length() < 1) { qWarning("\nSCALA_PATH not set, assuming SCALA_PATH=/usr/share/scala"); dirpath = "/usr/share/scala"; } else StdErr << "SCALA_PATH: " << dirpath << endl; if (p_sclname && !p_sclname->contains("No_Scale_loaded")) { loadScale(dirpath + "/" + *p_sclname); } }
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); } }