Another attempt at getting the play cursor to update more often. Looks like getting somewhere with that but needs more work.

This commit is contained in:
xenakios 2018-09-13 13:47:19 +03:00
parent 9c5141a16b
commit cabf6de7c3
4 changed files with 27 additions and 6 deletions

View File

@ -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
}
}
}
};

View File

@ -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<float> m_stretchoutringbuf{ 1024 * 1024 };
AudioBuffer<float> m_file_inbuf;
@ -165,5 +170,6 @@ private:
bool m_preview_dry = false;
double m_dryplayrate = 1.0;
AudioBuffer<float> m_drypreviewbuf;
int64_t m_last_filepos = 0;
void playDrySound(const AudioSourceChannelInfo & bufferToFill);
};

View File

@ -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<double>, 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<int>(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<int>(curpos), m_topmargin, 1, getHeight() - m_topmargin);
g.drawText(String(curpos), 1, 30, 200,30, Justification::left);
//g.fillRect(normalizedToViewX<int>(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();
}

View File

@ -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;