From 6747d20aa82691c25233608df282e5ce99bbe1c1 Mon Sep 17 00:00:00 2001 From: xenakios Date: Wed, 21 Mar 2018 13:15:48 +0200 Subject: [PATCH] Consolidate and clean up storing and recalling parameters. Enable storing and recalling of spectral module order again, using different state IDs. So old states will be discarded, but oh well... --- Source/PS_Source/ProcessedStretch.h | 3 +- Source/PS_Source/globals.h | 32 ++++++++++++++++++ Source/PluginProcessor.cpp | 51 +++++++++-------------------- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/Source/PS_Source/ProcessedStretch.h b/Source/PS_Source/ProcessedStretch.h index 7e20d9f..8241f0c 100644 --- a/Source/PS_Source/ProcessedStretch.h +++ b/Source/PS_Source/ProcessedStretch.h @@ -172,7 +172,8 @@ inline void spectrum_copy(int nfreq, REALTYPE* freq1, REALTYPE* freq2) inline void spectrum_spread(int nfreq, double samplerate, std::vector& tmpfreq1, - REALTYPE *freq1, REALTYPE *freq2, REALTYPE spread_bandwidth) { + REALTYPE *freq1, REALTYPE *freq2, REALTYPE spread_bandwidth) +{ //convert to log spectrum REALTYPE minfreq = 20.0f; REALTYPE maxfreq = 0.5f*samplerate; diff --git a/Source/PS_Source/globals.h b/Source/PS_Source/globals.h index 2ec831e..f696d20 100644 --- a/Source/PS_Source/globals.h +++ b/Source/PS_Source/globals.h @@ -113,6 +113,22 @@ inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, AudioParame if (par) dest.setProperty(par->paramID,(int)*par,uman); } +inline void storeToTreeProperties(ValueTree dest, UndoManager* uman, const OwnedArray& pars) +{ + for (auto& e : pars) + { + auto parf = dynamic_cast(e); + if (parf != nullptr) + storeToTreeProperties(dest, nullptr, parf); + auto pari = dynamic_cast(e); + if (pari != nullptr) + storeToTreeProperties(dest, nullptr, pari); + auto parb = dynamic_cast(e); + if (parb != nullptr) + storeToTreeProperties(dest, nullptr, parb); + } +} + template inline void getFromTreeProperties(ValueTree src, juce::Identifier varname, T& val) { @@ -152,6 +168,22 @@ inline void getFromTreeProperties(ValueTree src, T par) } } +inline void getFromTreeProperties(ValueTree src, const OwnedArray& pars) +{ + for (auto& e : pars) + { + auto parf = dynamic_cast(e); + if (parf != nullptr && src.hasProperty(parf->paramID)) + *parf = src.getProperty(parf->paramID); + auto pari = dynamic_cast(e); + if (pari != nullptr && src.hasProperty(pari->paramID)) + *pari = src.getProperty(pari->paramID); + auto parb = dynamic_cast(e); + if (parb != nullptr && src.hasProperty(parb->paramID)) + *parb = src.getProperty(parb->paramID); + } +} + template inline void timeCall(String msgprefix,F&& f) { diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index cca0a7f..3d2b530 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -88,7 +88,7 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() m_sm_enab_pars[2] = new AudioParameterBool("enab_specmodule2", "Enable spectral module 3", true); m_sm_enab_pars[3] = new AudioParameterBool("enab_specmodule3", "Enable spectral module 4", true); m_sm_enab_pars[4] = new AudioParameterBool("enab_specmodule4", "Enable spectral module 5", false); - m_sm_enab_pars[5] = new AudioParameterBool("enab_specmodule5", "Enable spectral module 6", true); + m_sm_enab_pars[5] = new AudioParameterBool("enab_specmodule5", "Enable spectral module 6", false); m_sm_enab_pars[6] = new AudioParameterBool("enab_specmodule6", "Enable spectral module 7", true); m_sm_enab_pars[7] = new AudioParameterBool("enab_specmodule7", "Enable spectral module 8", true); m_sm_enab_pars[8] = new AudioParameterBool("enab_specmodule8", "Enable spectral module 9", false); @@ -217,26 +217,16 @@ int PaulstretchpluginAudioProcessor::getPreBufferAmount() ValueTree PaulstretchpluginAudioProcessor::getStateTree(bool ignoreoptions, bool ignorefile) { ValueTree paramtree("paulstretch3pluginstate"); - for (int i = 0; igetSpectrumProcessOrder(); - paramtree.setProperty("numspectralstages", (int)specorder.size(), nullptr); + paramtree.setProperty("numspectralstagesb", (int)specorder.size(), nullptr); for (int i = 0; i < specorder.size(); ++i) { - paramtree.setProperty("specorder" + String(i), specorder[i].m_index, nullptr); - //paramtree.setProperty("specstepenabled" + String(i), specorder[i].m_enabled, nullptr); + paramtree.setProperty("specorderb" + String(i), specorder[i].m_index, nullptr); } if (ignoreoptions == false) { @@ -261,32 +251,23 @@ void PaulstretchpluginAudioProcessor::setStateFromTree(ValueTree tree) ValueTree freefilterstate = tree.getChildWithName("freefilter_envelope"); m_free_filter_envelope->restoreState(freefilterstate); m_load_file_with_state = tree.getProperty("loadfilewithstate", true); - if (tree.hasProperty("numspectralstages")) + if (tree.hasProperty("numspectralstagesb")) { - /* - std::vector order; - int ordersize = tree.getProperty("numspectralstages"); - for (int i = 0; i < ordersize; ++i) + std::vector old_order = m_stretch_source->getSpectrumProcessOrder(); + std::vector new_order; + int ordersize = tree.getProperty("numspectralstagesb"); + if (ordersize == old_order.size()) { - bool step_enabled = tree.getProperty("specstepenabled" + String(i)); - //order.push_back({ (int)tree.getProperty("specorder" + String(i)), step_enabled }); + for (int i = 0; i < ordersize; ++i) + { + new_order.push_back({ (int)tree.getProperty("specorderb" + String(i)), old_order[i].m_enabled }); + } + m_stretch_source->setSpectrumProcessOrder(new_order); } - if (ordersizegetSpectrumProcessOrder().size()) - order.emplace_back(8,m_sm_enab_pars[8]); - m_stretch_source->setSpectrumProcessOrder(order); - */ } getFromTreeProperties(tree, "waveviewrange", m_wave_view_range); - for (int i = 0; i < getNumParameters(); ++i) - { - getFromTreeProperties(tree,getFloatParameter(i)); - } - getFromTreeProperties(tree, getIntParameter(cpi_numharmonics)); - getFromTreeProperties(tree, m_outchansparam); - getFromTreeProperties(tree, m_inchansparam); - getFromTreeProperties(tree, getBoolParameter(cpi_bypass_stretch)); - getFromTreeProperties(tree, getIntParameter(cpi_freefilter_randomy_numbands)); - getFromTreeProperties(tree, getIntParameter(cpi_freefilter_randomy_rate)); + getFromTreeProperties(tree, getParameters()); + } int prebufamt = tree.getProperty("prebufamount", 2); if (prebufamt == -1)