From cabf6de7c3ccaf65a40e894ac864645b12a7f019 Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 13 Sep 2018 13:47:19 +0300 Subject: [PATCH] Another attempt at getting the play cursor to update more often. Looks like getting somewhere with that but needs more work. --- Source/PS_Source/StretchSource.cpp | 3 ++- Source/PS_Source/StretchSource.h | 8 +++++++- Source/PluginEditor.cpp | 17 ++++++++++++++--- Source/PluginEditor.h | 5 ++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index 73a2280..ea87a9b 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -321,6 +321,7 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer int readed = 0; if (readsize != 0) { + m_last_filepos = m_inputfile->getCurrentPosition(); readed = m_inputfile->readNextBlock(m_file_inbuf, readsize, m_num_outchans); } if (m_rand_count % (int)m_free_filter_envelope->m_transform_y_random_rate == 0) @@ -362,7 +363,7 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer } } - + } }; diff --git a/Source/PS_Source/StretchSource.h b/Source/PS_Source/StretchSource.h index ae01e16..352b1db 100644 --- a/Source/PS_Source/StretchSource.h +++ b/Source/PS_Source/StretchSource.h @@ -57,7 +57,11 @@ public: double getInfilePositionSeconds(); double getInfileLengthSeconds(); void setRate(double rate); - double getRate() { return m_playrate; } + double getRate() + { + return m_playrate; + } + double getOutputSamplerate() const { return m_outsr; } void setProcessParameters(ProcessParameters* pars); const ProcessParameters& getProcessParameters(); void setFFTSize(int size); @@ -107,6 +111,7 @@ public: int m_param_change_count = 0; double getLastSeekPos() const { return m_seekpos; } CriticalSection* getMutex() { return &m_cs; } + int64_t getLastSourcePosition() const { return m_last_filepos; } private: CircularBuffer m_stretchoutringbuf{ 1024 * 1024 }; AudioBuffer m_file_inbuf; @@ -165,5 +170,6 @@ private: bool m_preview_dry = false; double m_dryplayrate = 1.0; AudioBuffer m_drypreviewbuf; + int64_t m_last_filepos = 0; void playDrySound(const AudioSourceChannelInfo & bufferToFill); }; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index c414fe7..24e7066 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -24,7 +24,7 @@ www.gnu.org/licenses //============================================================================== PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(PaulstretchpluginAudioProcessor& p) : AudioProcessorEditor(&p), - m_wavecomponent(p.m_afm,p.m_thumb.get()), + m_wavecomponent(p.m_afm,p.m_thumb.get(), p.getStretchSource()), processor(p), m_perfmeter(&p), m_wavefilter_tab(p.m_cur_tab_index), m_free_filter_component(&p) @@ -568,7 +568,8 @@ void PaulstretchpluginAudioProcessorEditor::showSettingsMenu() } -WaveformComponent::WaveformComponent(AudioFormatManager* afm, AudioThumbnail* thumb) +WaveformComponent::WaveformComponent(AudioFormatManager* afm, AudioThumbnail* thumb, StretchAudioSource* sas) + : m_sas(sas) { TimeSelectionChangedCallback = [](Range, int) {}; #ifdef JUCE_MODULE_AVAILABLE_juce_opengl @@ -700,7 +701,12 @@ void WaveformComponent::paint(Graphics & g) g.setColour(Colours::white); if (CursorPosCallback) { - g.fillRect(normalizedToViewX(CursorPosCallback()), m_topmargin, 1, getHeight() - m_topmargin); + double timediff = (Time::getMillisecondCounterHiRes() - m_last_source_pos_update_time)*(1.0/m_sas->getRate()); + double curpos = ((double)m_last_source_pos / m_sas->getOutputSamplerate()) + (timediff/1000.0); + curpos = 1.0 / m_sas->getInfileLengthSeconds()*curpos; + g.fillRect(normalizedToViewX(curpos), m_topmargin, 1, getHeight() - m_topmargin); + g.drawText(String(curpos), 1, 30, 200,30, Justification::left); + //g.fillRect(normalizedToViewX(CursorPosCallback()), m_topmargin, 1, getHeight() - m_topmargin); } if (m_rec_pos >= 0.0) { @@ -714,6 +720,11 @@ void WaveformComponent::paint(Graphics & g) void WaveformComponent::timerCallback() { + if (m_sas->getLastSourcePosition() != m_last_source_pos) + { + m_last_source_pos = m_sas->getLastSourcePosition(); + m_last_source_pos_update_time = Time::getMillisecondCounterHiRes(); + } repaint(); } diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 20a0b0e..bf6185e 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -128,7 +128,7 @@ public: class WaveformComponent : public Component, public ChangeListener, public Timer { public: - WaveformComponent(AudioFormatManager* afm, AudioThumbnail* thumb); + WaveformComponent(AudioFormatManager* afm, AudioThumbnail* thumb, StretchAudioSource* sas); ~WaveformComponent(); void changeListenerCallback(ChangeBroadcaster* cb) override; void paint(Graphics& g) override; @@ -171,7 +171,10 @@ private: double m_sr = 0.0; int m_fft_size = 0; double m_last_startpos = 0.0; + int64_t m_last_source_pos = -1; + double m_last_source_pos_update_time = 0.0; Image m_waveimage; + StretchAudioSource* m_sas = nullptr; #ifdef JUCE_MODULE_AVAILABLE_juce_opengl OpenGLContext m_ogl; bool m_use_opengl = false;