diff --git a/Source/PS_Source/globals.h b/Source/PS_Source/globals.h index 061ea09..55fc5ea 100644 --- a/Source/PS_Source/globals.h +++ b/Source/PS_Source/globals.h @@ -90,6 +90,11 @@ inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, juce::Ident dest.setProperty(varname+"_end", x.getEnd(), uman); } +inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, AudioParameterFloat* par) +{ + if (par) dest.setProperty(par->paramID, (float)*par, uman); +} + inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, AudioParameterBool* par) { if (par) dest.setProperty(par->paramID,(bool)*par,uman); @@ -128,7 +133,9 @@ inline void getFromTreeProperties(ValueTree src, juce::Identifier varname, Range template inline void getFromTreeProperties(ValueTree src, T par) { - if (par!=nullptr && src.hasProperty(par->paramID)) + static_assert(std::is_base_of::type>::value, + "T must inherit from AudioProcessorParameterWithID"); + if (par!=nullptr && src.hasProperty(par->paramID)) { *par = src.getProperty(par->paramID); } diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 6f95d0b..4560085 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -204,11 +204,7 @@ ValueTree PaulstretchpluginAudioProcessor::getStateTree(bool ignoreoptions, bool ValueTree paramtree("paulstretch3pluginstate"); for (int i = 0; iparamID, (double)*par, nullptr); - } + storeToTreeProperties(paramtree, nullptr, getFloatParameter(i)); } storeToTreeProperties(paramtree, nullptr, m_outchansparam); storeToTreeProperties(paramtree, nullptr, m_inchansparam); @@ -257,12 +253,7 @@ void PaulstretchpluginAudioProcessor::setStateFromTree(ValueTree tree) getFromTreeProperties(tree, "waveviewrange", m_wave_view_range); for (int i = 0; i < getNumParameters(); ++i) { - auto par = getFloatParameter(i); - if (par != nullptr) - { - double parval = tree.getProperty(par->paramID, (double)*par); - *par = parval; - } + getFromTreeProperties(tree,getFloatParameter(i)); } getFromTreeProperties(tree, m_outchansparam); getFromTreeProperties(tree, m_inchansparam);