More work on the AudioFilePreviewComponent, need to add samplerate conversions, volume control etc...
This commit is contained in:
		@@ -21,31 +21,6 @@ www.gnu.org/licenses
 | 
				
			|||||||
#include <array>
 | 
					#include <array>
 | 
				
			||||||
#include "RenderSettingsComponent.h"
 | 
					#include "RenderSettingsComponent.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AudioFilePreviewComponent : public FilePreviewComponent
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
public:
 | 
					 | 
				
			||||||
	AudioFilePreviewComponent(PaulstretchpluginAudioProcessor* p) : m_proc(p) 
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		addAndMakeVisible(m_playbut);
 | 
					 | 
				
			||||||
		m_playbut.setButtonText("Play");
 | 
					 | 
				
			||||||
		m_playbut.onClick = [this]()
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
		setSize(100, 30);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	void selectedFileChanged(const File &newSelectedFile) override
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	void resized() override
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		m_playbut.setBounds(0, 0, getWidth(), getHeight());
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
private:
 | 
					 | 
				
			||||||
	TextButton m_playbut;
 | 
					 | 
				
			||||||
	PaulstretchpluginAudioProcessor* m_proc = nullptr;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
//==============================================================================
 | 
					//==============================================================================
 | 
				
			||||||
PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(PaulstretchpluginAudioProcessor& p)
 | 
					PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(PaulstretchpluginAudioProcessor& p)
 | 
				
			||||||
	: AudioProcessorEditor(&p),
 | 
						: AudioProcessorEditor(&p),
 | 
				
			||||||
@@ -491,10 +466,12 @@ void PaulstretchpluginAudioProcessorEditor::chooseFile()
 | 
				
			|||||||
                                                File::getSpecialLocation(File::userHomeDirectory).getFullPathName());
 | 
					                                                File::getSpecialLocation(File::userHomeDirectory).getFullPathName());
 | 
				
			||||||
    File initialloc(initiallocfn);
 | 
					    File initialloc(initiallocfn);
 | 
				
			||||||
	String filterstring = processor.m_afm->getWildcardForAllFormats();
 | 
						String filterstring = processor.m_afm->getWildcardForAllFormats();
 | 
				
			||||||
 | 
						auto prevcomp = std::make_unique<AudioFilePreviewComponent>(&processor);
 | 
				
			||||||
 | 
						processor.setAudioPreview(prevcomp.get());
 | 
				
			||||||
	FileChooser myChooser("Please select audio file...",
 | 
						FileChooser myChooser("Please select audio file...",
 | 
				
			||||||
		initialloc,
 | 
							initialloc,
 | 
				
			||||||
		filterstring,true);
 | 
							filterstring,false);
 | 
				
			||||||
	if (myChooser.browseForFileToOpen())
 | 
						if (myChooser.browseForFileToOpen(prevcomp.get()))
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
        File resu = myChooser.getResult();
 | 
					        File resu = myChooser.getResult();
 | 
				
			||||||
        String pathname = resu.getFullPathName();
 | 
					        String pathname = resu.getFullPathName();
 | 
				
			||||||
@@ -506,7 +483,7 @@ void PaulstretchpluginAudioProcessorEditor::chooseFile()
 | 
				
			|||||||
        processor.m_propsfile->m_props_file->setValue("importfilefolder", resu.getParentDirectory().getFullPathName());
 | 
					        processor.m_propsfile->m_props_file->setValue("importfilefolder", resu.getParentDirectory().getFullPathName());
 | 
				
			||||||
        m_last_err = processor.setAudioFile(resu);
 | 
					        m_last_err = processor.setAudioFile(resu);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						processor.setAudioPreview(nullptr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void PaulstretchpluginAudioProcessorEditor::showSettingsMenu()
 | 
					void PaulstretchpluginAudioProcessorEditor::showSettingsMenu()
 | 
				
			||||||
@@ -1567,3 +1544,14 @@ void FreeFilterComponent::updateParameterComponents()
 | 
				
			|||||||
	for (auto& e : m_parcomps)
 | 
						for (auto& e : m_parcomps)
 | 
				
			||||||
		e->updateComponent();
 | 
							e->updateComponent();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AudioFilePreviewComponent::processBlock(double sr, AudioBuffer<float>& buf)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (m_reader != nullptr)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							m_reader->read(&buf, 0, buf.getNumSamples(), m_playpos, true, true);
 | 
				
			||||||
 | 
							m_playpos += buf.getNumSamples();
 | 
				
			||||||
 | 
							if (m_playpos >= m_reader->lengthInSamples)
 | 
				
			||||||
 | 
								m_playpos = 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -264,6 +264,41 @@ private:
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class AudioFilePreviewComponent : public FilePreviewComponent
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
						AudioFilePreviewComponent(PaulstretchpluginAudioProcessor* p) : m_proc(p)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							addAndMakeVisible(m_playbut);
 | 
				
			||||||
 | 
							m_playbut.setButtonText("Play");
 | 
				
			||||||
 | 
							m_playbut.onClick = [this]()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							};
 | 
				
			||||||
 | 
							setSize(100, 30);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						void selectedFileChanged(const File &newSelectedFile) override
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							ScopedLock locker(m_proc->getCriticalSection());
 | 
				
			||||||
 | 
							m_reader = unique_from_raw(m_proc->m_afm->createReaderFor(newSelectedFile));
 | 
				
			||||||
 | 
							m_playpos = 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						void resized() override
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							m_playbut.setBounds(0, 0, getWidth(), getHeight());
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						void togglePlay()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						void processBlock(double sr, AudioBuffer<float>& buf);
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						TextButton m_playbut;
 | 
				
			||||||
 | 
						PaulstretchpluginAudioProcessor* m_proc = nullptr;
 | 
				
			||||||
 | 
						std::unique_ptr<AudioFormatReader> m_reader;
 | 
				
			||||||
 | 
						int64 m_playpos = 0;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PaulstretchpluginAudioProcessorEditor  : public AudioProcessorEditor, 
 | 
					class PaulstretchpluginAudioProcessorEditor  : public AudioProcessorEditor, 
 | 
				
			||||||
	public MultiTimer, public FileDragAndDropTarget, public DragAndDropContainer
 | 
						public MultiTimer, public FileDragAndDropTarget, public DragAndDropContainer
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -652,6 +652,11 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M
 | 
				
			|||||||
		m_input_buffer.copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples());
 | 
							m_input_buffer.copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples());
 | 
				
			||||||
    for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
 | 
					    for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
 | 
				
			||||||
        buffer.clear (i, 0, buffer.getNumSamples());
 | 
					        buffer.clear (i, 0, buffer.getNumSamples());
 | 
				
			||||||
 | 
						if (m_previewcomponent != nullptr)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							m_previewcomponent->processBlock(getSampleRate(), buffer);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if (m_prebuffering_inited == false)
 | 
						if (m_prebuffering_inited == false)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	if (m_is_recording == true)
 | 
						if (m_is_recording == true)
 | 
				
			||||||
@@ -898,6 +903,12 @@ void PaulstretchpluginAudioProcessor::timerCallback(int id)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void PaulstretchpluginAudioProcessor::setAudioPreview(AudioFilePreviewComponent * afpc)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						ScopedLock locker(m_cs);
 | 
				
			||||||
 | 
						m_previewcomponent = afpc;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pointer_sized_int PaulstretchpluginAudioProcessor::handleVstPluginCanDo(int32 index, pointer_sized_int value, void * ptr, float opt)
 | 
					pointer_sized_int PaulstretchpluginAudioProcessor::handleVstPluginCanDo(int32 index, pointer_sized_int value, void * ptr, float opt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (strcmp((char*)ptr, "xenakios") == 0)
 | 
						if (strcmp((char*)ptr, "xenakios") == 0)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,6 +23,7 @@ www.gnu.org/licenses
 | 
				
			|||||||
#include <array>
 | 
					#include <array>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MyThumbCache;
 | 
					class MyThumbCache;
 | 
				
			||||||
 | 
					class AudioFilePreviewComponent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const int cpi_main_volume = 0;
 | 
					const int cpi_main_volume = 0;
 | 
				
			||||||
const int cpi_stretchamount = 1;
 | 
					const int cpi_stretchamount = 1;
 | 
				
			||||||
@@ -204,7 +205,8 @@ public:
 | 
				
			|||||||
    int m_prepare_count = 0;
 | 
					    int m_prepare_count = 0;
 | 
				
			||||||
    shared_envelope m_free_filter_envelope;
 | 
					    shared_envelope m_free_filter_envelope;
 | 
				
			||||||
	bool m_import_dlg_open = false;
 | 
						bool m_import_dlg_open = false;
 | 
				
			||||||
	
 | 
						void setAudioPreview(AudioFilePreviewComponent* afpc);
 | 
				
			||||||
 | 
						CriticalSection& getCriticalSection() { return m_cs; }
 | 
				
			||||||
	pointer_sized_int handleVstPluginCanDo(int32 index,
 | 
						pointer_sized_int handleVstPluginCanDo(int32 index,
 | 
				
			||||||
		pointer_sized_int value,
 | 
							pointer_sized_int value,
 | 
				
			||||||
		void* ptr,
 | 
							void* ptr,
 | 
				
			||||||
@@ -261,6 +263,7 @@ private:
 | 
				
			|||||||
	void updateStretchParametersFromPluginParameters(ProcessParameters& pars);
 | 
						void updateStretchParametersFromPluginParameters(ProcessParameters& pars);
 | 
				
			||||||
	std::array<AudioParameterBool*, 9> m_sm_enab_pars;
 | 
						std::array<AudioParameterBool*, 9> m_sm_enab_pars;
 | 
				
			||||||
	bool m_lastrewind = false;
 | 
						bool m_lastrewind = false;
 | 
				
			||||||
 | 
						AudioFilePreviewComponent* m_previewcomponent = nullptr;
 | 
				
			||||||
	//==============================================================================
 | 
						//==============================================================================
 | 
				
			||||||
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
 | 
					    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user