Initial work to make the AudioProcessor own the AudioThumbNail etc
This commit is contained in:
		| @@ -27,7 +27,7 @@ extern String g_plugintitle; | |||||||
| //============================================================================== | //============================================================================== | ||||||
| PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(PaulstretchpluginAudioProcessor& p) | PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(PaulstretchpluginAudioProcessor& p) | ||||||
| 	: AudioProcessorEditor(&p), | 	: AudioProcessorEditor(&p), | ||||||
| 	m_wavecomponent(p.m_afm), | 	m_wavecomponent(p.m_afm,p.m_thumb.get()), | ||||||
| 	processor(p) | 	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) {}; | 	TimeSelectionChangedCallback = [](Range<double>, int) {}; | ||||||
| 	if (m_use_opengl == true) | 	if (m_use_opengl == true) | ||||||
| 		m_ogl.attachTo(*this); | 		m_ogl.attachTo(*this); | ||||||
| 	// The default priority of 2 is a bit too low in some cases, it seems... | 	// The default priority of 2 is a bit too low in some cases, it seems... | ||||||
| 	m_thumbcache->getTimeSliceThread().setPriority(3); | 	//m_thumbcache->getTimeSliceThread().setPriority(3); | ||||||
| 	m_thumb = std::make_unique<AudioThumbnail>(512, *afm, *m_thumbcache); | 	m_thumbnail = thumb; | ||||||
| 	m_thumb->addChangeListener(this); | 	m_thumbnail->addChangeListener(this); | ||||||
| 	setOpaque(true); | 	setOpaque(true); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -388,6 +388,7 @@ WaveformComponent::~WaveformComponent() | |||||||
| { | { | ||||||
| 	if (m_use_opengl == true) | 	if (m_use_opengl == true) | ||||||
| 		m_ogl.detach(); | 		m_ogl.detach(); | ||||||
|  | 	m_thumbnail->removeChangeListener(this); | ||||||
| } | } | ||||||
|  |  | ||||||
| void WaveformComponent::changeListenerCallback(ChangeBroadcaster * /*cb*/) | void WaveformComponent::changeListenerCallback(ChangeBroadcaster * /*cb*/) | ||||||
| @@ -402,14 +403,14 @@ void WaveformComponent::paint(Graphics & g) | |||||||
| 	g.fillAll(Colours::black); | 	g.fillAll(Colours::black); | ||||||
| 	g.setColour(Colours::darkgrey); | 	g.setColour(Colours::darkgrey); | ||||||
| 	g.fillRect(0, 0, getWidth(), m_topmargin); | 	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.setColour(Colours::aqua.darker()); | ||||||
| 		g.drawText("No file loaded", 2, m_topmargin + 2, getWidth(), 20, Justification::topLeft); | 		g.drawText("No file loaded", 2, m_topmargin + 2, getWidth(), 20, Justification::topLeft); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	g.setColour(Colours::lightslategrey); | 	g.setColour(Colours::lightslategrey); | ||||||
| 	double thumblen = m_thumb->getTotalLength(); | 	double thumblen = m_thumbnail->getTotalLength(); | ||||||
| 	double tick_interval = 1.0; | 	double tick_interval = 1.0; | ||||||
| 	if (thumblen > 60.0) | 	if (thumblen > 60.0) | ||||||
| 		tick_interval = 5.0; | 		tick_interval = 5.0; | ||||||
| @@ -430,7 +431,7 @@ void WaveformComponent::paint(Graphics & g) | |||||||
| 			Graphics tempg(m_waveimage); | 			Graphics tempg(m_waveimage); | ||||||
| 			tempg.fillAll(Colours::black); | 			tempg.fillAll(Colours::black); | ||||||
| 			tempg.setColour(Colours::darkgrey); | 			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); | 				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); | 		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.fillAll(Colours::black); | ||||||
| 		g.setColour(Colours::darkgrey); | 		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); | 			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) | void WaveformComponent::setAudioFile(File f) | ||||||
| { | { | ||||||
|  | 	/* | ||||||
| 	if (f.existsAsFile()) | 	if (f.existsAsFile()) | ||||||
| 	{ | 	{ | ||||||
| 		m_waveimage = Image(); | 		m_waveimage = Image(); | ||||||
| @@ -502,28 +504,35 @@ void WaveformComponent::setAudioFile(File f) | |||||||
| 		m_curfile = File(); | 		m_curfile = File(); | ||||||
| 	} | 	} | ||||||
| 	repaint(); | 	repaint(); | ||||||
|  | 	*/ | ||||||
| } | } | ||||||
|  |  | ||||||
| void WaveformComponent::setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len) | void WaveformComponent::setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len) | ||||||
| { | { | ||||||
|     jassert(buf!=nullptr); |     /* | ||||||
|  | 	jassert(buf!=nullptr); | ||||||
|     m_using_audio_buffer = true; |     m_using_audio_buffer = true; | ||||||
|     m_waveimage = Image(); |     m_waveimage = Image(); | ||||||
| 	m_curfile = File(); | 	m_curfile = File(); | ||||||
| 	m_thumb->reset(buf->getNumChannels(), samplerate, len); | 	m_thumb->reset(buf->getNumChannels(), samplerate, len); | ||||||
| 	m_thumb->addBlock(0, *buf, 0, len); | 	m_thumb->addBlock(0, *buf, 0, len); | ||||||
|  | 	*/ | ||||||
| } | } | ||||||
|  |  | ||||||
| void WaveformComponent::beginAddingAudioBlocks(int channels, int samplerate, int totalllen) | void WaveformComponent::beginAddingAudioBlocks(int channels, int samplerate, int totalllen) | ||||||
| { | { | ||||||
|  | 	/* | ||||||
| 	m_waveimage = Image(); | 	m_waveimage = Image(); | ||||||
| 	m_curfile = File(); | 	m_curfile = File(); | ||||||
| 	m_thumb->reset(channels, samplerate, totalllen); | 	m_thumb->reset(channels, samplerate, totalllen); | ||||||
|  | 	*/ | ||||||
| } | } | ||||||
|  |  | ||||||
| void WaveformComponent::addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos) | void WaveformComponent::addAudioBlock(AudioBuffer<float>& buf, int samplerate, int pos) | ||||||
| { | { | ||||||
|  | 	/* | ||||||
| 	m_thumb->addBlock(pos, buf, 0, buf.getNumSamples()); | 	m_thumb->addBlock(pos, buf, 0, buf.getNumSamples()); | ||||||
|  | 	*/ | ||||||
| } | } | ||||||
|  |  | ||||||
| void WaveformComponent::timerCallback() | void WaveformComponent::timerCallback() | ||||||
|   | |||||||
| @@ -82,7 +82,7 @@ public: | |||||||
| class WaveformComponent : public Component, public ChangeListener, public Timer | class WaveformComponent : public Component, public ChangeListener, public Timer | ||||||
| { | { | ||||||
| public: | public: | ||||||
| 	WaveformComponent(AudioFormatManager* afm); | 	WaveformComponent(AudioFormatManager* afm, AudioThumbnail* thumb); | ||||||
| 	~WaveformComponent(); | 	~WaveformComponent(); | ||||||
| 	void changeListenerCallback(ChangeBroadcaster* cb) override; | 	void changeListenerCallback(ChangeBroadcaster* cb) override; | ||||||
| 	void paint(Graphics& g) override; | 	void paint(Graphics& g) override; | ||||||
| @@ -108,9 +108,7 @@ public: | |||||||
| 	Value ShowFileCacheRange; | 	Value ShowFileCacheRange; | ||||||
| 	void setRecordingPosition(double pos) { m_rec_pos = pos; } | 	void setRecordingPosition(double pos) { m_rec_pos = pos; } | ||||||
| private: | private: | ||||||
| 	SharedResourcePointer<MyThumbCache> m_thumbcache; | 	AudioThumbnail* m_thumbnail = nullptr; | ||||||
|  |  | ||||||
| 	std::unique_ptr<AudioThumbnail> m_thumb; |  | ||||||
| 	Range<double> m_view_range{ 0.0,1.0 }; | 	Range<double> m_view_range{ 0.0,1.0 }; | ||||||
| 	int m_time_sel_drag_target = 0; | 	int m_time_sel_drag_target = 0; | ||||||
| 	double m_time_sel_start = -1.0; | 	double m_time_sel_start = -1.0; | ||||||
|   | |||||||
| @@ -90,10 +90,13 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() | |||||||
| { | { | ||||||
| 	 | 	 | ||||||
|     g_activeprocessors.insert(this); |     g_activeprocessors.insert(this); | ||||||
|  | 	 | ||||||
| 	m_recbuffer.setSize(2, 44100); | 	m_recbuffer.setSize(2, 44100); | ||||||
| 	m_recbuffer.clear(); | 	m_recbuffer.clear(); | ||||||
| 	if (m_afm->getNumKnownFormats()==0) | 	if (m_afm->getNumKnownFormats()==0) | ||||||
| 		m_afm->registerBasicFormats(); | 		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); | 	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()); }); | 			//MessageManager::callAsync([cb, file]() { cb("Too high bit depth in file " + file.getFullPathName()); }); | ||||||
| 			return "Too high bit depth in file " + f.getFullPathName(); | 			return "Too high bit depth in file " + f.getFullPathName(); | ||||||
| 		} | 		} | ||||||
|  | 		m_thumb->setSource(new FileInputSource(f)); | ||||||
| 		ScopedLock locker(m_cs); | 		ScopedLock locker(m_cs); | ||||||
| 		m_stretch_source->setAudioFile(f); | 		m_stretch_source->setAudioFile(f); | ||||||
| 		m_current_file = f; | 		m_current_file = f; | ||||||
|   | |||||||
| @@ -150,6 +150,7 @@ public: | |||||||
| 	ValueTree getStateTree(bool ignoreoptions, bool ignorefile); | 	ValueTree getStateTree(bool ignoreoptions, bool ignorefile); | ||||||
| 	void setStateFromTree(ValueTree tree); | 	void setStateFromTree(ValueTree tree); | ||||||
| 	bool m_state_dirty = false; | 	bool m_state_dirty = false; | ||||||
|  | 	std::unique_ptr<AudioThumbnail> m_thumb; | ||||||
| private: | private: | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| @@ -188,6 +189,7 @@ private: | |||||||
| 	std::vector<float> m_reset_pars; | 	std::vector<float> m_reset_pars; | ||||||
| 	int m_cur_program = 0; | 	int m_cur_program = 0; | ||||||
| 	void setParameters(const std::vector<double>& pars); | 	void setParameters(const std::vector<double>& pars); | ||||||
|  | 	 | ||||||
| 	//============================================================================== | 	//============================================================================== | ||||||
|     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) |     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 xenakios
					xenakios