From 1a8bddeb9b1b9c76611a346578d7e9cded6dcaca Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 22 Feb 2018 01:09:36 +0200 Subject: [PATCH] Added convenience functions to deal with storing and getting audio parameters and use them --- Source/PS_Source/globals.h | 19 +++++++++++++++++++ Source/PluginProcessor.cpp | 19 ++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Source/PS_Source/globals.h b/Source/PS_Source/globals.h index d31d53c..061ea09 100644 --- a/Source/PS_Source/globals.h +++ b/Source/PS_Source/globals.h @@ -90,6 +90,16 @@ inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, juce::Ident 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 inline void getFromTreeProperties(ValueTree src, juce::Identifier varname, T& val) { @@ -115,6 +125,15 @@ inline void getFromTreeProperties(ValueTree src, juce::Identifier varname, Range } } +template +inline void getFromTreeProperties(ValueTree src, T par) +{ + if (par!=nullptr && src.hasProperty(par->paramID)) + { + *par = src.getProperty(par->paramID); + } +} + template inline void timeCall(String msgprefix,F&& f) { diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index b1c01e5..38bbe21 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -210,10 +210,10 @@ ValueTree PaulstretchpluginAudioProcessor::getStateTree(bool ignoreoptions, bool paramtree.setProperty(par->paramID, (double)*par, nullptr); } } - paramtree.setProperty(m_outchansparam->paramID, (int)*m_outchansparam, nullptr); - paramtree.setProperty(m_inchansparam->paramID, (int)*m_inchansparam, nullptr); - paramtree.setProperty(getBoolParameter(cpi_bypass_stretch)->paramID, (bool)*getBoolParameter(cpi_bypass_stretch), nullptr); - if (m_current_file != File() && ignorefile == false) + storeToTreeProperties(paramtree, nullptr, m_outchansparam); + storeToTreeProperties(paramtree, nullptr, m_inchansparam); + storeToTreeProperties(paramtree, nullptr, getBoolParameter(cpi_bypass_stretch)); + if (m_current_file != File() && ignorefile == false) { paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr); } @@ -264,13 +264,10 @@ void PaulstretchpluginAudioProcessor::setStateFromTree(ValueTree tree) *par = parval; } } - if (tree.hasProperty(m_outchansparam->paramID)) - *m_outchansparam = tree.getProperty(m_outchansparam->paramID, 2); - if (tree.hasProperty(m_inchansparam->paramID)) - *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); - } + getFromTreeProperties(tree, m_outchansparam); + getFromTreeProperties(tree, m_inchansparam); + getFromTreeProperties(tree, getBoolParameter(cpi_bypass_stretch)); + } int prebufamt = tree.getProperty("prebufamount", 2); if (prebufamt == -1) m_use_backgroundbuffering = false;