Added convenience functions to deal with storing and getting audio parameters and use them

This commit is contained in:
xenakios 2018-02-22 01:09:36 +02:00
parent 73c58f6067
commit 1a8bddeb9b
2 changed files with 27 additions and 11 deletions

View File

@ -90,6 +90,16 @@ inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, juce::Ident
dest.setProperty(varname+"_end", x.getEnd(), uman); dest.setProperty(varname+"_end", x.getEnd(), uman);
} }
inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, AudioParameterBool* par)
{
if (par) dest.setProperty(par->paramID,(bool)*par,uman);
}
inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, AudioParameterInt* par)
{
if (par) dest.setProperty(par->paramID,(int)*par,uman);
}
template<typename T> template<typename T>
inline void getFromTreeProperties(ValueTree src, juce::Identifier varname, T& val) inline void getFromTreeProperties(ValueTree src, juce::Identifier varname, T& val)
{ {
@ -115,6 +125,15 @@ inline void getFromTreeProperties(ValueTree src, juce::Identifier varname, Range
} }
} }
template<typename T>
inline void getFromTreeProperties(ValueTree src, T par)
{
if (par!=nullptr && src.hasProperty(par->paramID))
{
*par = src.getProperty(par->paramID);
}
}
template<typename F> template<typename F>
inline void timeCall(String msgprefix,F&& f) inline void timeCall(String msgprefix,F&& f)
{ {

View File

@ -210,10 +210,10 @@ ValueTree PaulstretchpluginAudioProcessor::getStateTree(bool ignoreoptions, bool
paramtree.setProperty(par->paramID, (double)*par, nullptr); paramtree.setProperty(par->paramID, (double)*par, nullptr);
} }
} }
paramtree.setProperty(m_outchansparam->paramID, (int)*m_outchansparam, nullptr); storeToTreeProperties(paramtree, nullptr, m_outchansparam);
paramtree.setProperty(m_inchansparam->paramID, (int)*m_inchansparam, nullptr); storeToTreeProperties(paramtree, nullptr, m_inchansparam);
paramtree.setProperty(getBoolParameter(cpi_bypass_stretch)->paramID, (bool)*getBoolParameter(cpi_bypass_stretch), nullptr); storeToTreeProperties(paramtree, nullptr, getBoolParameter(cpi_bypass_stretch));
if (m_current_file != File() && ignorefile == false) if (m_current_file != File() && ignorefile == false)
{ {
paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr); paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr);
} }
@ -264,13 +264,10 @@ void PaulstretchpluginAudioProcessor::setStateFromTree(ValueTree tree)
*par = parval; *par = parval;
} }
} }
if (tree.hasProperty(m_outchansparam->paramID)) getFromTreeProperties(tree, m_outchansparam);
*m_outchansparam = tree.getProperty(m_outchansparam->paramID, 2); getFromTreeProperties(tree, m_inchansparam);
if (tree.hasProperty(m_inchansparam->paramID)) getFromTreeProperties(tree, getBoolParameter(cpi_bypass_stretch));
*m_inchansparam = tree.getProperty(m_inchansparam->paramID, 2); }
if (tree.hasProperty(getBoolParameter(cpi_bypass_stretch)->paramID))
*getBoolParameter(cpi_bypass_stretch) = tree.getProperty(getBoolParameter(cpi_bypass_stretch)->paramID, false);
}
int prebufamt = tree.getProperty("prebufamount", 2); int prebufamt = tree.getProperty("prebufamount", 2);
if (prebufamt == -1) if (prebufamt == -1)
m_use_backgroundbuffering = false; m_use_backgroundbuffering = false;