From 109d973f6ec9f999c3b8a589a053bec552964356 Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sat, 9 Oct 2021 14:09:35 -0700 Subject: [PATCH] audiovisualwaveform: improved shift code --- app/audio/audiovisualwaveform.cpp | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/app/audio/audiovisualwaveform.cpp b/app/audio/audiovisualwaveform.cpp index 1ee61425b..5d1e86dfd 100644 --- a/app/audio/audiovisualwaveform.cpp +++ b/app/audio/audiovisualwaveform.cpp @@ -202,33 +202,16 @@ void AudioVisualWaveform::Shift(const rational &from, const rational &to) continue; } - if (from_index > data.size()) { + if (from_index >= data.size()) { continue; } if (from_index > to_index) { // Shifting backwards <- - int copy_sz = data.size() - from_index; - - memcpy(&data.data()[to_index], &data.data()[from_index], copy_sz * sizeof(SamplePerChannel)); - - data.resize(data.size() - (from_index - to_index)); + data.remove(to_index, from_index - to_index); } else { // Shifting forwards -> - int old_sz = data.size(); - - int distance = (to_index - from_index); - - data.resize(data.size() + distance); - - int copy_sz = old_sz - from_index; - - // Copy to a temporary buffer first to prevent overwriting bytes we need to copy - QByteArray temp(copy_sz * sizeof(SamplePerChannel), Qt::Uninitialized); - memcpy(temp.data(), &data.data()[from_index], temp.size()); - memcpy(&data.data()[to_index], temp.data(), temp.size()); - - memset(&data.data()[from_index], 0, distance * sizeof(SamplePerChannel)); + data.insert(from_index, to_index - from_index, {0, 0}); } }