waveform: shift track waveform alongside cache
This commit is contained in:
@@ -131,10 +131,19 @@ void AudioPlaybackCache::WriteSilence(const TimeRange &range)
|
||||
|
||||
void AudioPlaybackCache::ShiftEvent(const rational &from, const rational &to)
|
||||
{
|
||||
qint64 from_offset = params_.time_to_bytes(from);
|
||||
qint64 to_offset = params_.time_to_bytes(to);
|
||||
|
||||
if (from_offset == to_offset) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile f(filename_);
|
||||
if (f.open(QFile::ReadWrite)) {
|
||||
qint64 from_offset = params_.time_to_bytes(from);
|
||||
qint64 to_offset = params_.time_to_bytes(to);
|
||||
if (!f.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
qint64 chunk = qAbs(to_offset - from_offset);
|
||||
|
||||
QByteArray buf(chunk, Qt::Uninitialized);
|
||||
@@ -150,7 +159,7 @@ void AudioPlaybackCache::ShiftEvent(const rational &from, const rational &to)
|
||||
|
||||
qint64 write_offset = f.size();
|
||||
|
||||
do {
|
||||
while (read_offset != from_offset) {
|
||||
|
||||
// Calculate how much will be read this time
|
||||
qint64 chunk_sz = qMin(chunk, read_offset - from_offset);
|
||||
@@ -165,7 +174,7 @@ void AudioPlaybackCache::ShiftEvent(const rational &from, const rational &to)
|
||||
f.seek(write_offset);
|
||||
f.write(buf.data(), chunk_sz);
|
||||
|
||||
} while (read_offset != from_offset);
|
||||
}
|
||||
|
||||
// Replace remainder with silence
|
||||
f.seek(from_offset);
|
||||
@@ -175,7 +184,7 @@ void AudioPlaybackCache::ShiftEvent(const rational &from, const rational &to)
|
||||
} else {
|
||||
// Shifting backwards, we will shift bytes and truncate
|
||||
|
||||
do {
|
||||
while (from_offset != f.size()) {
|
||||
// Read region to be shifted
|
||||
f.seek(from_offset);
|
||||
qint64 read_sz = f.read(buf.data(), buf.size());
|
||||
@@ -184,7 +193,7 @@ void AudioPlaybackCache::ShiftEvent(const rational &from, const rational &to)
|
||||
// Write it at the destination
|
||||
f.seek(to_offset);
|
||||
to_offset += f.write(buf, read_sz);
|
||||
} while (from_offset != f.size());
|
||||
}
|
||||
|
||||
// Truncate
|
||||
f.resize(f.size() - chunk);
|
||||
|
||||
@@ -353,6 +353,10 @@ void RenderBackend::WorkerFinished()
|
||||
|
||||
void RenderBackend::WorkerGeneratedWaveform(const TrackOutput *copied_track, const AudioVisualWaveform& samples, const rational &r)
|
||||
{
|
||||
if (!viewer_node_) {
|
||||
return;
|
||||
}
|
||||
|
||||
TrackOutput* track = nullptr;
|
||||
|
||||
/*
|
||||
@@ -372,7 +376,6 @@ void RenderBackend::WorkerGeneratedWaveform(const TrackOutput *copied_track, con
|
||||
if (track) {
|
||||
track->waveform().set_channel_count(audio_params_.channel_count());
|
||||
track->waveform().OverwriteSums(samples, r);
|
||||
qDebug() << "Preview changed";
|
||||
emit track->PreviewChanged();
|
||||
} else {
|
||||
qDebug() << "Failed to find track";
|
||||
|
||||
@@ -57,6 +57,10 @@ void PlaybackCache::SetLength(const rational &r)
|
||||
|
||||
void PlaybackCache::Shift(const rational &from, const rational &to)
|
||||
{
|
||||
if (from == to) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMutexLocker locker(&lock_);
|
||||
|
||||
// An region between `from` and `to` will be inserted or spliced out
|
||||
@@ -75,6 +79,8 @@ void PlaybackCache::Shift(const rational &from, const rational &to)
|
||||
|
||||
ShiftEvent(from, to);
|
||||
|
||||
length_ += diff;
|
||||
|
||||
if (diff > rational()) {
|
||||
// If shifting forward, add this section to the invalidated region
|
||||
TimeRange invalidate_range(from, to);
|
||||
@@ -113,12 +119,15 @@ void PlaybackCache::NoLockSetLength(const rational &r)
|
||||
return;
|
||||
}
|
||||
|
||||
TimeRange range_diff(length_, r);
|
||||
|
||||
if (r > length_) {
|
||||
// If new length is greater, simply extend the invalidated range for now
|
||||
invalidated_.InsertTimeRange(TimeRange(length_, r));
|
||||
invalidated_.InsertTimeRange(range_diff);
|
||||
} else {
|
||||
// If new length is smaller, removed hashes
|
||||
invalidated_.RemoveTimeRange(TimeRange(r, length_));
|
||||
invalidated_.RemoveTimeRange(range_diff);
|
||||
RemoveRangeFromJobs(range_diff);
|
||||
}
|
||||
|
||||
LengthChangedEvent(length_, r);
|
||||
|
||||
Reference in New Issue
Block a user