From f2f5ab873931247a6325effba5bc978d4021f47c Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 27 Apr 2021 00:49:04 +1000 Subject: [PATCH] audiovisualwaveform: keep track of length Useful to determine how long the visual waveform is. --- app/audio/audiovisualwaveform.cpp | 7 +++++++ app/audio/audiovisualwaveform.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/app/audio/audiovisualwaveform.cpp b/app/audio/audiovisualwaveform.cpp index e6907936f..f0daec9df 100644 --- a/app/audio/audiovisualwaveform.cpp +++ b/app/audio/audiovisualwaveform.cpp @@ -121,6 +121,9 @@ void AudioVisualWaveform::OverwriteSamples(SampleBufferPtr samples, int sample_r input_start, input_length, start, current_mipmap->first.toDouble(), current_mipmap->second); } + + rational sample_length(samples->sample_count(), sample_rate); + length_ = qMax(length_, start + sample_length); } void AudioVisualWaveform::OverwriteSums(const AudioVisualWaveform &sums, const rational &dest, const rational& offset, const rational& length) @@ -155,6 +158,8 @@ void AudioVisualWaveform::OverwriteSums(const AudioVisualWaveform &sums, const r reinterpret_cast(their_arr.constData()) + their_start_index * sizeof(SamplePerChannel), copy_len * sizeof(SamplePerChannel)); } + + length_ = qMax(length_, dest + length); } void AudioVisualWaveform::Shift(const rational &from, const rational &to) @@ -201,6 +206,8 @@ void AudioVisualWaveform::Shift(const rational &from, const rational &to) memset(reinterpret_cast(&data[from_index]), 0, distance * sizeof(SamplePerChannel)); } } + + length_ += (to-from); } AudioVisualWaveform::Sample AudioVisualWaveform::GetSummaryFromTime(const rational &start, const rational &length) const diff --git a/app/audio/audiovisualwaveform.h b/app/audio/audiovisualwaveform.h index 917a645a1..6f4ffa731 100644 --- a/app/audio/audiovisualwaveform.h +++ b/app/audio/audiovisualwaveform.h @@ -55,6 +55,11 @@ public: channels_ = channels; } + const rational& length() const + { + return length_; + } + /** * @brief Writes samples into the visual waveform buffer * @@ -112,6 +117,8 @@ private: std::map mipmapped_data_; + rational length_; + }; }