From daf17f2ea36d9433f74087622b0dc56787a4d6ca Mon Sep 17 00:00:00 2001 From: xenakios Date: Wed, 17 Jan 2018 18:57:56 +0200 Subject: [PATCH] Initial work to make the AudioProcessor own the AudioThumbNail etc --- Source/PluginEditor.cpp | 29 +++++++++++++++++++---------- Source/PluginEditor.h | 6 ++---- Source/PluginProcessor.cpp | 4 ++++ Source/PluginProcessor.h | 2 ++ 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 7f28e85..0a989c8 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -27,7 +27,7 @@ extern String g_plugintitle; //============================================================================== PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(PaulstretchpluginAudioProcessor& p) : AudioProcessorEditor(&p), - m_wavecomponent(p.m_afm), + m_wavecomponent(p.m_afm,p.m_thumb.get()), processor(p) { @@ -372,15 +372,15 @@ String juceversiontxt = String("JUCE ") + String(JUCE_MAJOR_VERSION) + "." + Str } } -WaveformComponent::WaveformComponent(AudioFormatManager* afm) +WaveformComponent::WaveformComponent(AudioFormatManager* afm, AudioThumbnail* thumb) { TimeSelectionChangedCallback = [](Range, int) {}; if (m_use_opengl == true) m_ogl.attachTo(*this); // The default priority of 2 is a bit too low in some cases, it seems... - m_thumbcache->getTimeSliceThread().setPriority(3); - m_thumb = std::make_unique(512, *afm, *m_thumbcache); - m_thumb->addChangeListener(this); + //m_thumbcache->getTimeSliceThread().setPriority(3); + m_thumbnail = thumb; + m_thumbnail->addChangeListener(this); setOpaque(true); } @@ -388,6 +388,7 @@ WaveformComponent::~WaveformComponent() { if (m_use_opengl == true) m_ogl.detach(); + m_thumbnail->removeChangeListener(this); } void WaveformComponent::changeListenerCallback(ChangeBroadcaster * /*cb*/) @@ -402,14 +403,14 @@ void WaveformComponent::paint(Graphics & g) g.fillAll(Colours::black); g.setColour(Colours::darkgrey); g.fillRect(0, 0, getWidth(), m_topmargin); - if (m_thumb == nullptr || m_thumb->getTotalLength() < 0.1) + if (m_thumbnail == nullptr || m_thumbnail->getTotalLength() < 0.01) { g.setColour(Colours::aqua.darker()); g.drawText("No file loaded", 2, m_topmargin + 2, getWidth(), 20, Justification::topLeft); return; } g.setColour(Colours::lightslategrey); - double thumblen = m_thumb->getTotalLength(); + double thumblen = m_thumbnail->getTotalLength(); double tick_interval = 1.0; if (thumblen > 60.0) tick_interval = 5.0; @@ -430,7 +431,7 @@ void WaveformComponent::paint(Graphics & g) Graphics tempg(m_waveimage); tempg.fillAll(Colours::black); tempg.setColour(Colours::darkgrey); - m_thumb->drawChannels(tempg, { 0,0,getWidth(),getHeight() - m_topmargin }, + m_thumbnail->drawChannels(tempg, { 0,0,getWidth(),getHeight() - m_topmargin }, thumblen*m_view_range.getStart(), thumblen*m_view_range.getEnd(), 1.0f); } g.drawImage(m_waveimage, 0, m_topmargin, getWidth(), getHeight() - m_topmargin, 0, 0, getWidth(), getHeight() - m_topmargin); @@ -440,7 +441,7 @@ void WaveformComponent::paint(Graphics & g) { //g.fillAll(Colours::black); g.setColour(Colours::darkgrey); - m_thumb->drawChannels(g, { 0,m_topmargin,getWidth(),getHeight() - m_topmargin }, + m_thumbnail->drawChannels(g, { 0,m_topmargin,getWidth(),getHeight() - m_topmargin }, thumblen*m_view_range.getStart(), thumblen*m_view_range.getEnd(), 1.0f); } @@ -485,6 +486,7 @@ void WaveformComponent::paint(Graphics & g) void WaveformComponent::setAudioFile(File f) { + /* if (f.existsAsFile()) { m_waveimage = Image(); @@ -502,28 +504,35 @@ void WaveformComponent::setAudioFile(File f) m_curfile = File(); } repaint(); + */ } void WaveformComponent::setAudioBuffer(AudioBuffer* buf, int samplerate, int len) { - jassert(buf!=nullptr); + /* + jassert(buf!=nullptr); m_using_audio_buffer = true; m_waveimage = Image(); m_curfile = File(); m_thumb->reset(buf->getNumChannels(), samplerate, len); m_thumb->addBlock(0, *buf, 0, len); + */ } void WaveformComponent::beginAddingAudioBlocks(int channels, int samplerate, int totalllen) { + /* m_waveimage = Image(); m_curfile = File(); m_thumb->reset(channels, samplerate, totalllen); + */ } void WaveformComponent::addAudioBlock(AudioBuffer& buf, int samplerate, int pos) { + /* m_thumb->addBlock(pos, buf, 0, buf.getNumSamples()); + */ } void WaveformComponent::timerCallback() diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 3545d02..795a47d 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -82,7 +82,7 @@ public: class WaveformComponent : public Component, public ChangeListener, public Timer { public: - WaveformComponent(AudioFormatManager* afm); + WaveformComponent(AudioFormatManager* afm, AudioThumbnail* thumb); ~WaveformComponent(); void changeListenerCallback(ChangeBroadcaster* cb) override; void paint(Graphics& g) override; @@ -108,9 +108,7 @@ public: Value ShowFileCacheRange; void setRecordingPosition(double pos) { m_rec_pos = pos; } private: - SharedResourcePointer m_thumbcache; - - std::unique_ptr m_thumb; + AudioThumbnail* m_thumbnail = nullptr; Range m_view_range{ 0.0,1.0 }; int m_time_sel_drag_target = 0; double m_time_sel_start = -1.0; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index aea4775..aef1787 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -90,10 +90,13 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() { g_activeprocessors.insert(this); + m_recbuffer.setSize(2, 44100); m_recbuffer.clear(); if (m_afm->getNumKnownFormats()==0) m_afm->registerBasicFormats(); + m_thumb = std::make_unique(512, *m_afm, *m_thumbcache); + //m_thumb->addChangeListener(this); m_stretch_source = std::make_unique(2, m_afm); @@ -695,6 +698,7 @@ String PaulstretchpluginAudioProcessor::setAudioFile(File f) //MessageManager::callAsync([cb, file]() { cb("Too high bit depth in file " + file.getFullPathName()); }); return "Too high bit depth in file " + f.getFullPathName(); } + m_thumb->setSource(new FileInputSource(f)); ScopedLock locker(m_cs); m_stretch_source->setAudioFile(f); m_current_file = f; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 3df21ef..7789a66 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -150,6 +150,7 @@ public: ValueTree getStateTree(bool ignoreoptions, bool ignorefile); void setStateFromTree(ValueTree tree); bool m_state_dirty = false; + std::unique_ptr m_thumb; private: @@ -188,6 +189,7 @@ private: std::vector m_reset_pars; int m_cur_program = 0; void setParameters(const std::vector& pars); + //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) };