//============================================================================== void getStateInformation (MemoryBlock& destData) { destData.setSize (sizeof (float) * getNumParameters()); destData.fillWith (0); float* const p = (float*) ((char*) destData.getData()); for (int i = 0; i < getNumParameters(); ++i) p[i] = getParameter(i); }
void calcDerivative(const Differentiator::DifferentiatorRep& diff, Differentiator::Method m, Real y0, const Real* fy0p, Real& dfdy) const override { if (getNumFunctions() != 1 || getNumParameters() != 1) SimTK_THROW5(Differentiator::OpNotAllowedForFunctionOfThisShape, "calcDerivative", "1x1", "JacobianFunction", getNumFunctions(), getNumParameters()); const Vector y0v(1, y0); Vector fy0v(1); if (fy0p) fy0v[0] = *fy0p; else {diff.nCallsToUserFunction++; call(y0v, fy0v);} Matrix dfdym(1,1, &dfdy); // refers to dfdy directly as data diff.calcJacobian(*this,m,y0v,fy0v,dfdym); }
void calcDerivative(const Differentiator::DifferentiatorRep& diff, Differentiator::Method m, Real y0, const Real* fy0p, Real& dfdy) const override { if (getNumParameters() != 1) SimTK_THROW5(Differentiator::OpNotAllowedForFunctionOfThisShape, "calcDerivative", "1x1", "GradientFunction", 1, getNumParameters()); const Vector y0v(1, y0); Real fy0; if (fy0p) fy0 = *fy0p; else {diff.nCallsToUserFunction++; call(y0v, fy0);} Vector dfdyv(1, &dfdy); // refers to dfdy data directly diff.calcGradient(*this,m,y0v,fy0,dfdyv); }
bool CParameterObject::operator == (CParameters ¶meterObject) { std::map<string, double>::iterator it = parameters->begin(); if (parameterObject.getNumParameters() != getNumParameters()) { return false; } for (int i = 0 ;it != parameters->end(); it++, i++) { if (parameterObject.getParameterIndex((*it).first) >= 0) { //if (adaptiveParameters->find((*it).first) == adaptiveParameters->end() && fabs((*it).second - parameterObject.getParameter((*it).first)) > 0.00001) if (fabs((*it).second - parameterObject.getParameter((*it).first)) > 0.00001) { //printf("Different Param Values for Parameter %s, %f %f\n", (*it).first.c_str(), (*it).second, parameterObject.getParameter((*it).first)); return false; } } else { return false; } } return true; }
bool DMPPolicy::computeControlCosts(const std::vector<Eigen::MatrixXd>& control_cost_matrices, const std::vector<std::vector<Eigen::VectorXd> >& parameters, const double weight, std::vector<Eigen::VectorXd>& control_costs) { int num_dimensions = control_cost_matrices.size(); int num_time_steps = parameters[0].size(); std::vector<int> num_parameters(num_dimensions); getNumParameters(num_parameters); // initialize output vector if necessary: if (int(control_costs.size()) != num_dimensions) { control_costs.clear(); for (int d = 0; d < num_dimensions; ++d) { control_costs.push_back(VectorXd::Zero(num_time_steps)); } } // compute the costs for (int d = 0; d < num_dimensions; ++d) { for (int t = 0; t < num_time_steps; ++t) { control_costs[d](t) = weight * parameters[d][t].dot(control_cost_matrices[d] * parameters[d][t]); } } return true; }
void MLPluginProcessor::setDefaultParameters() { if (mEngine.getCompileStatus() == MLProc::OK) { // set default for each parameter. const unsigned numParams = getNumParameters(); for(unsigned i=0; i<numParams; ++i) { MLPublishedParamPtr paramPtr = getParameterPtr(i); MLSymbol paramType = paramPtr->getType(); if(paramType == "float") { float defaultVal = getParameterDefaultValue(i); setPropertyImmediate(getParameterAlias(i), defaultVal); } else if (paramType == "string") { // unimplemented } else if (paramType == "signal") { const MLProperty& p = getProperty(getParameterAlias(i)); if (p.getType() == MLProperty::kSignalProperty) { // TODO set up defaults for signal params once we are loading from JSON // right now we clear to zero MLSignal defaultSignal(p.getSignalValue()); defaultSignal.clear(); setPropertyImmediate(getParameterAlias(i), defaultSignal); } } } } }
//============================================================================== void prepareToPlay (double newSampleRate, int samplesPerBlockExpected) { setPlayConfigDetails (inputs.size(), outputs.size(), newSampleRate, samplesPerBlockExpected); setLatencySamples (0); initialise(); if (initialised) { tempBuffer.setSize (jmax (1, outputs.size()), samplesPerBlockExpected); // dodgy hack to force some plugins to initialise the sample rate.. if (getNumParameters() > 0) { const float old = getParameter (0); setParameter (0, (old < 0.5f) ? 1.0f : 0.0f); setParameter (0, old); } if (plugin->activate != nullptr) plugin->activate (handle); } }
XmlElement BiasedDelay::getStateInformation(){ XmlElement state("BiasedDelayState"); for (int i=0; i<getNumParameters(); i++) state.setAttribute(String::formatted("parameter%d", i), getParameterValue(i)); // state.setAttribute(getParameterName(i), getParameterValue(i)); return state; }
void PitchedDelayAudioProcessor::setStateInformation (const void* data, int sizeInBytes) { ScopedPointer<XmlElement> xml(getXmlFromBinary(data, sizeInBytes)); if (xml != 0 && xml->getTagName() == "PitchedDelay") { const bool extendedsync = xml->hasAttribute("extended"); for (int i=0; i<getNumParameters(); ++i) { const String paramName(getParameterName(i)); float val = (float) xml->getDoubleAttribute(paramName, -1000); if (! extendedsync && paramName.contains("Sync")) val = val*7/9; if (! extendedsync && paramName.contains("PitchType")) val = val*5/8; if (val > -1000) setParameterNotifyingHost(i, val); } const int curTab = xml->getIntAttribute("currentTab", -1000); showTooltips = xml->getIntAttribute("showtooltips") == 1; currentTab = curTab > -1000 ? curTab : 0; } }
void AudioProcessor::endParameterChangeGesture (int parameterIndex) { jassert (isPositiveAndBelow (parameterIndex, getNumParameters())); #if JUCE_DEBUG // This means you've called endParameterChangeGesture without having previously called // endParameterChangeGesture. That might be fine in most hosts, but better to keep the // calls matched correctly. jassert (changingParams [parameterIndex]); changingParams.clearBit (parameterIndex); #endif for (int i = listeners.size(); --i >= 0;) { AudioProcessorListener* l; { const ScopedLock sl (listenerLock); l = listeners [i]; } if (l != nullptr) l->audioProcessorParameterChangeGestureEnd (this, parameterIndex); } }
void DemoJuceFilter::setStateInformation (const void* data, int sizeInBytes) { // use this helper function to get the XML from this binary blob.. XmlElement* const xmlState = getXmlFromBinary (data, sizeInBytes); if (xmlState != 0) { // check that it's the right type of xml.. if (xmlState->hasTagName (T("XSynthPatch"))) { // ok, now pull out our parameters.. gain = (float) xmlState->getDoubleAttribute (T("gainLevel"), gain); lastUIWidth = xmlState->getIntAttribute (T("uiWidth"), lastUIWidth); lastUIHeight = xmlState->getIntAttribute (T("uiHeight"), lastUIHeight); for (int i=0; i<getNumParameters(); i++) { DBG(String("Loading parameter ") + getParameterXMLName(i) + String(" to ") + String(xmlState->getDoubleAttribute(getParameterXMLName(i)))); setParameter(i, xmlState->getDoubleAttribute(getParameterXMLName(i))); } sendChangeMessage (this); } delete xmlState; } }
void setStateInformation (const void* data, int sizeInBytes) { const float* p = static_cast <const float*> (data); for (int i = 0; i < getNumParameters(); ++i) setParameter (i, p[i]); }
//============================================================================== void DemoJuceFilter::getStateInformation (MemoryBlock& destData) { // you can store your parameters as binary data if you want to or if you've got // a load of binary to put in there, but if you're not doing anything too heavy, // XML is a much cleaner way of doing it - here's an example of how to store your // params as XML.. // create an outer XML element.. XmlElement xmlState (T("XSynthPatch")); // add some attributes to it.. xmlState.setAttribute (T("pluginVersion"), 1); xmlState.setAttribute (T("gainLevel"), gain); xmlState.setAttribute (T("uiWidth"), lastUIWidth); xmlState.setAttribute (T("uiHeight"), lastUIHeight); // you could also add as many child elements as you need to here.. for (int i=0; i<getNumParameters(); i++) { xmlState.setAttribute (getParameterXMLName(i), getParameter(i)); DBG(String("Saved parameter ") + getParameterXMLName(i) + String(" as ") + String(getParameter(i))); } // then use this helper function to stuff it into the binary blob and return it.. copyXmlToBinary (xmlState, destData); }
/* declares constant = false for any L1 compartment/parameter * assigned by a rule */ void Model::addConstantAttribute() { unsigned int n; // parameters and compartments are declared to have constant=true // by default. Since in L1 the constant attribute didnt exist // parameters/compartments that are the subjcet of rules must have // the value changed for ( n = 0; n < getNumParameters(); n++) { if (getRule(getParameter(n)->getId()) != NULL) { getParameter(n)->setConstant(false); } } for ( n = 0; n < getNumCompartments(); n++) { if (getRule(getCompartment(n)->getId()) != NULL) { getCompartment(n)->setConstant(false); } } }
void BiasedDelay::setStateInformation(ScopedPointer<XmlElement> state){ if (state->hasTagName("BiasedDelayState")) { for (int i=0; i<getNumParameters(); i++) setParameterValue(i, (float)state->getDoubleAttribute(String::formatted("parameter%d", i), getParameterValue(i))); // setParameterValue(i, (float)state->getDoubleAttribute(getParameterName(i), getParameterValue(i))); } }
float DemoJuceFilter::getParameter (int index) { if(index>=0 && index<getNumParameters()) { return mpUI->getNormalizedParameter(index); } return 0.f; }
void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue) { jassert (isPositiveAndBelow (parameterIndex, getNumParameters())); for (int i = listeners.size(); --i >= 0;) if (AudioProcessorListener* l = getListenerLocked (i)) l->audioProcessorParameterChanged (this, parameterIndex, newValue); }
void DemoJuceFilter::setParameter (int index, float newValue) { if(index>=0 && index<getNumParameters()) { mpUI->setNormalizedParameter(index, newValue); sendChangeMessage (this); } }
const String DemoJuceFilter::getParameterText (int index) { if(index>=0 && index<getNumParameters()) { return mpUI->getParameterText(index); } return String::empty; }
//============================================================================== void SuperSpreadAudioProcessor::getStateInformation (MemoryBlock& destData) { XmlElement xml("STATE"); for (int i=0; i<getNumParameters(); ++i) xml.setAttribute(getParameterName(i), getParameter(i)); copyXmlToBinary(xml, destData); }
//============================================================================== void LuftikusAudioProcessor::getStateInformation (MemoryBlock& destData) { XmlElement xml("LUFTIKUSDATA"); for (int i=0; i<getNumParameters(); ++i) xml.setAttribute(getParameterName(i).replace(" ", "_", false).replace(".", "-", false), getParameter(i)); xml.setAttribute("tooltips", showTooltips ? 1 : 0); copyXmlToBinary(xml, destData); }
void SuperSpreadAudioProcessor::setStateInformation (const void* data, int sizeInBytes) { ScopedPointer<XmlElement> xml(getXmlFromBinary(data, sizeInBytes)); if (xml != nullptr) { for (int i=0; i<getNumParameters(); ++i) setParameterNotifyingHost(i, static_cast<float> (xml->getDoubleAttribute(getParameterName(i), getParameter(i)))); } }
void calcJacobian(const Differentiator::DifferentiatorRep& diff, Differentiator::Method m, const Vector& y0, const Vector* fy0p, Matrix& dfdy) const override { assert(!fy0p || (*fy0p).size()==1); dfdy.resize(1,getNumParameters()); Real fy0; if (fy0p) fy0 = (*fy0p)[0]; else {diff.nCallsToUserFunction++; call(y0, fy0);} diff.calcGradient(*this,m,y0,fy0,~dfdy[0]); }
void AudioProcessor::addParameter (AudioProcessorParameter* p) { p->processor = this; p->parameterIndex = managedParameters.size(); managedParameters.add (p); // if you're using parameter objects, then you must not override the // deprecated getNumParameters() method! jassert (getNumParameters() == AudioProcessor::getNumParameters()); }
void calcGradient(const Differentiator::DifferentiatorRep& diff, Differentiator::Method m, const Vector& y0, const Real* fy0p, Vector& gf) const override { if (getNumFunctions() != 1) SimTK_THROW5(Differentiator::OpNotAllowedForFunctionOfThisShape, "calcGradient", "1xn", "JacobianFunction", getNumFunctions(), getNumParameters()); Vector fy0v(1); if (fy0p) fy0v[0] = *fy0p; else {diff.nCallsToUserFunction++; call(y0, fy0v);} diff.calcJacobian(*this,m,y0,fy0v,gf); }
void LuftikusAudioProcessor::setStateInformation (const void* data, int sizeInBytes) { ScopedPointer<XmlElement> xml(getXmlFromBinary(data, sizeInBytes)); if (xml != nullptr) { for (int i=0; i<getNumParameters(); ++i) setParameterNotifyingHost(i, (float) xml->getDoubleAttribute(getParameterName(i).replace(" ", "_", false).replace(".", "-", false))); showTooltips = xml->getBoolAttribute("tooltips", true); } }
/* converting to l1 any metaid attributes should be removed */ void Model::removeMetaId() { unsigned int n, i; unsetMetaId(); for (n = 0; n < getNumUnitDefinitions(); n++) { getUnitDefinition(n)->unsetMetaId(); for (i = 0; i < getUnitDefinition(n)->getNumUnits(); i++) { getUnitDefinition(n)->getUnit(i)->unsetMetaId(); } } for (n = 0; n < getNumCompartments(); n++) { getCompartment(n)->unsetMetaId(); } for (n = 0; n < getNumSpecies(); n++) { getSpecies(n)->unsetMetaId(); } for (n = 0; n < getNumParameters(); n++) { getParameter(n)->unsetMetaId(); } for (n = 0; n < getNumRules(); n++) { getRule(n)->unsetMetaId(); } for (n = 0; n < getNumReactions(); n++) { getReaction(n)->unsetMetaId(); for (i = 0; i < getReaction(n)->getNumReactants(); i++) { getReaction(n)->getReactant(i)->unsetMetaId(); } for (i = 0; i < getReaction(n)->getNumProducts(); i++) { getReaction(n)->getProduct(i)->unsetMetaId(); } if (getReaction(n)->isSetKineticLaw()) { getReaction(n)->getKineticLaw()->unsetMetaId(); } } }
void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue) { if (isPositiveAndBelow (parameterIndex, getNumParameters())) { for (int i = listeners.size(); --i >= 0;) if (AudioProcessorListener* l = getListenerLocked (i)) l->audioProcessorParameterChanged (this, parameterIndex, newValue); } else { jassertfalse; // called with an out-of-range parameter index! } }
// set default value for each scalar parameter. needed before loading // patches, which are only required to store differences from these // default values. void MLPluginProcessor::setDefaultParameters() { if (mEngine.getCompileStatus() == MLProc::OK) { // set default for each parameter. const unsigned numParams = getNumParameters(); for(unsigned i=0; i<numParams; ++i) { float defaultVal = getParameterDefault(i); setPropertyImmediate(getParameterAlias(i), defaultVal); } } }
//============================================================================== void PitchedDelayAudioProcessor::getStateInformation (MemoryBlock& destData) { XmlElement xml("PitchedDelay"); for (int i=0; i<getNumParameters(); ++i) xml.setAttribute(getParameterName(i), getParameter(i)); xml.setAttribute("currenttab", jmax(0, currentTab)); xml.setAttribute("showtooltips", showTooltips ? 1 : 0); xml.setAttribute("extended", "1"); copyXmlToBinary(xml, destData); }