Save and restore plugin state. Port input file skipbuffer bug fix from standalone app.
This commit is contained in:
		| @@ -28,7 +28,7 @@ public: | |||||||
| 		InputS() | 		InputS() | ||||||
|         { |         { | ||||||
| 			skipbufsize=1024; | 			skipbufsize=1024; | ||||||
| 			skipbuf.setSize(4, skipbufsize); | 			skipbuf.setSize(1, skipbufsize); | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
| 		virtual ~InputS() | 		virtual ~InputS() | ||||||
| @@ -45,8 +45,8 @@ public: | |||||||
| 			{ | 			{ | ||||||
| 				int readsize=(nsmps<skipbufsize)?nsmps:skipbufsize; | 				int readsize=(nsmps<skipbufsize)?nsmps:skipbufsize; | ||||||
| 				if (skipbuf.getNumSamples() < readsize) | 				if (skipbuf.getNumSamples() < readsize) | ||||||
| 					skipbuf.setSize(info.nchannels, readsize); | 					skipbuf.setSize(1, readsize); | ||||||
| 				readNextBlock(skipbuf,readsize,info.nchannels); | 				readNextBlock(skipbuf,readsize,1); | ||||||
| 				nsmps-=readsize; | 				nsmps-=readsize; | ||||||
| 			}; | 			}; | ||||||
| 		}; | 		}; | ||||||
| @@ -79,11 +79,13 @@ public: | |||||||
| 	{ | 	{ | ||||||
| 		return m_currentsample >= info.nsamples*m_activerange.getEnd(); | 		return m_currentsample >= info.nsamples*m_activerange.getEnd(); | ||||||
| 	} | 	} | ||||||
|  | 	 | ||||||
| protected: | protected: | ||||||
| 	int64_t m_currentsample = 0; | 	int64_t m_currentsample = 0; | ||||||
| 	int m_silenceoutputted = 0; | 	int m_silenceoutputted = 0; | ||||||
| 	bool m_loop_enabled = false; | 	bool m_loop_enabled = false; | ||||||
| 	Range<double> m_activerange{ 0.0,1.0 }; | 	Range<double> m_activerange{ 0.0,1.0 }; | ||||||
|  | 	 | ||||||
| private: | private: | ||||||
| 	int skipbufsize; | 	int skipbufsize; | ||||||
| 	AudioBuffer<float> skipbuf; | 	AudioBuffer<float> skipbuf; | ||||||
|   | |||||||
| @@ -127,7 +127,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl | |||||||
| 	} | 	} | ||||||
| 	if (m_ready_to_play == false) | 	if (m_ready_to_play == false) | ||||||
| 	{ | 	{ | ||||||
| 		m_control->setFFTSize(0.2); | 		m_control->setFFTSize(0.7); | ||||||
| 		m_control->update_player_stretch(); | 		m_control->update_player_stretch(); | ||||||
| 		m_control->update_process_parameters(); | 		m_control->update_process_parameters(); | ||||||
| 		 | 		 | ||||||
| @@ -242,15 +242,47 @@ AudioProcessorEditor* PaulstretchpluginAudioProcessor::createEditor() | |||||||
| //============================================================================== | //============================================================================== | ||||||
| void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData) | void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData) | ||||||
| { | { | ||||||
|     // You should use this method to store your parameters in the memory block. | 	ValueTree paramtree("paulstretch3pluginstate"); | ||||||
|     // You could do that either as raw data, or use the XML or ValueTree classes | 	for (int i=0;i<getNumParameters();++i) | ||||||
|     // as intermediaries to make it easy to save and load complex data. | 	{ | ||||||
|  | 		auto par = getFloatParameter(i); | ||||||
|  | 		paramtree.setProperty(par->paramID, (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) | void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes) | ||||||
| { | { | ||||||
|     // You should use this method to restore your parameters from this memory block, | 	ValueTree tree = ValueTree::readFromData(data, sizeInBytes); | ||||||
|     // whose contents will have been created by the getStateInformation() call. | 	if (tree.isValid()) | ||||||
|  | 	{ | ||||||
|  | 		for (int i = 0; i<getNumParameters(); ++i) | ||||||
|  | 		{ | ||||||
|  | 			auto par = getFloatParameter(i); | ||||||
|  | 			double parval = tree.getProperty(par->paramID, (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) | void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b) | ||||||
| @@ -259,6 +291,8 @@ void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b) | |||||||
| 	int lenbufframes = getSampleRate()*m_max_reclen; | 	int lenbufframes = getSampleRate()*m_max_reclen; | ||||||
| 	if (b == true) | 	if (b == true) | ||||||
| 	{ | 	{ | ||||||
|  | 		m_using_memory_buffer = true; | ||||||
|  | 		m_current_file = File(); | ||||||
| 		m_recbuffer.setSize(2, m_max_reclen*getSampleRate()+4096); | 		m_recbuffer.setSize(2, m_max_reclen*getSampleRate()+4096); | ||||||
| 		m_recbuffer.clear(); | 		m_recbuffer.clear(); | ||||||
| 		m_rec_pos = 0; | 		m_rec_pos = 0; | ||||||
| @@ -292,6 +326,7 @@ String PaulstretchpluginAudioProcessor::setAudioFile(File f) | |||||||
| 		 | 		 | ||||||
| 	}); | 	}); | ||||||
| 	m_current_file = f; | 	m_current_file = f; | ||||||
|  | 	m_using_memory_buffer = false; | ||||||
| 	return String(); | 	return String(); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -75,7 +75,7 @@ private: | |||||||
| 	bool m_is_recording = false; | 	bool m_is_recording = false; | ||||||
| 	int m_rec_pos = 0; | 	int m_rec_pos = 0; | ||||||
| 	void finishRecording(int lenrecorded); | 	void finishRecording(int lenrecorded); | ||||||
| 	bool m_using_memory_buffer = true; | 	bool m_using_memory_buffer = false; | ||||||
| 	int m_cur_num_out_chans = 2; | 	int m_cur_num_out_chans = 2; | ||||||
| 	std::mutex m_mutex; | 	std::mutex m_mutex; | ||||||
| 	File m_current_file; | 	File m_current_file; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 xenakios
					xenakios