Initial work to make the AudioProcessor own the AudioThumbNail etc

This commit is contained in:
xenakios 2018-01-17 18:57:56 +02:00
parent 01ee930174
commit daf17f2ea3
4 changed files with 27 additions and 14 deletions

View File

@ -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<double>, 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<AudioThumbnail>(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<float>* 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<float>& buf, int samplerate, int pos)
{
/*
m_thumb->addBlock(pos, buf, 0, buf.getNumSamples());
*/
}
void WaveformComponent::timerCallback()

View File

@ -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<MyThumbCache> m_thumbcache;
std::unique_ptr<AudioThumbnail> m_thumb;
AudioThumbnail* m_thumbnail = nullptr;
Range<double> m_view_range{ 0.0,1.0 };
int m_time_sel_drag_target = 0;
double m_time_sel_start = -1.0;

View File

@ -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<AudioThumbnail>(512, *m_afm, *m_thumbcache);
//m_thumb->addChangeListener(this);
m_stretch_source = std::make_unique<StretchAudioSource>(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;

View File

@ -150,6 +150,7 @@ public:
ValueTree getStateTree(bool ignoreoptions, bool ignorefile);
void setStateFromTree(ValueTree tree);
bool m_state_dirty = false;
std::unique_ptr<AudioThumbnail> m_thumb;
private:
@ -188,6 +189,7 @@ private:
std::vector<float> m_reset_pars;
int m_cur_program = 0;
void setParameters(const std::vector<double>& pars);
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
};