From 4620ba818edbf1df75d2ef3b1cf7882b50dcb9e8 Mon Sep 17 00:00:00 2001 From: xenakios Date: Wed, 15 Nov 2017 20:51:52 +0200 Subject: [PATCH] Save and restore plugin state. Port input file skipbuffer bug fix from standalone app. --- Source/PS_Source/Input/InputS.h | 8 +++--- Source/PluginProcessor.cpp | 47 ++++++++++++++++++++++++++++----- Source/PluginProcessor.h | 2 +- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Source/PS_Source/Input/InputS.h b/Source/PS_Source/Input/InputS.h index 6093e9c..5176d9c 100644 --- a/Source/PS_Source/Input/InputS.h +++ b/Source/PS_Source/Input/InputS.h @@ -28,7 +28,7 @@ public: InputS() { skipbufsize=1024; - skipbuf.setSize(4, skipbufsize); + skipbuf.setSize(1, skipbufsize); }; virtual ~InputS() @@ -45,8 +45,8 @@ public: { int readsize=(nsmps= info.nsamples*m_activerange.getEnd(); } + protected: int64_t m_currentsample = 0; int m_silenceoutputted = 0; bool m_loop_enabled = false; Range m_activerange{ 0.0,1.0 }; + private: int skipbufsize; AudioBuffer skipbuf; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 7ba073d..16e670f 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -127,7 +127,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl } if (m_ready_to_play == false) { - m_control->setFFTSize(0.2); + m_control->setFFTSize(0.7); m_control->update_player_stretch(); m_control->update_process_parameters(); @@ -242,15 +242,47 @@ AudioProcessorEditor* PaulstretchpluginAudioProcessor::createEditor() //============================================================================== void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData) { - // You should use this method to store your parameters in the memory block. - // You could do that either as raw data, or use the XML or ValueTree classes - // as intermediaries to make it easy to save and load complex data. + ValueTree paramtree("paulstretch3pluginstate"); + for (int i=0;iparamID, (double)*par, nullptr); + } + if (m_current_file != File()) + { + paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr); + } + MemoryOutputStream stream(destData,true); + paramtree.writeToStream(stream); } void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes) { - // You should use this method to restore your parameters from this memory block, - // whose contents will have been created by the getStateInformation() call. + ValueTree tree = ValueTree::readFromData(data, sizeInBytes); + if (tree.isValid()) + { + for (int i = 0; iparamID, (double)*par); + *par = parval; + } + String fn = tree.getProperty("importedfile"); + if (fn.isEmpty() == false) + { + m_using_memory_buffer = false; + File f(fn); + setAudioFile(f); + Timer::callAfterDelay(500, [this,f]() + { + callGUI([f](PaulstretchpluginAudioProcessorEditor* ed) + { + ed->setAudioFile(f); + }, false); + }); + + } + } } void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b) @@ -259,6 +291,8 @@ void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b) int lenbufframes = getSampleRate()*m_max_reclen; if (b == true) { + m_using_memory_buffer = true; + m_current_file = File(); m_recbuffer.setSize(2, m_max_reclen*getSampleRate()+4096); m_recbuffer.clear(); m_rec_pos = 0; @@ -292,6 +326,7 @@ String PaulstretchpluginAudioProcessor::setAudioFile(File f) }); m_current_file = f; + m_using_memory_buffer = false; return String(); } diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 605c221..e3cbb42 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -75,7 +75,7 @@ private: bool m_is_recording = false; int m_rec_pos = 0; void finishRecording(int lenrecorded); - bool m_using_memory_buffer = true; + bool m_using_memory_buffer = false; int m_cur_num_out_chans = 2; std::mutex m_mutex; File m_current_file;