Skip to content

Commit

Permalink
fix bugs in FutureAudioSource
Browse files Browse the repository at this point in the history
  • Loading branch information
CrSjimo committed Oct 18, 2024
1 parent 38806e3 commit cf7826a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/core/source/FutureAudioSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ namespace talcs {

qint64 FutureAudioSource::length() const {
Q_D(const FutureAudioSource);
if (d->src)
return d->src->length();
return d->futureWatcher->progressMaximum();
}

Expand Down
32 changes: 17 additions & 15 deletions src/core/source/FutureAudioSourceClipSeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace talcs {
cachedLengthAvailable += clip.length();
clipLengthCachedDict[clip.position()] = true;
emitProgressChanged();
checkAndNotify();
checkAndNotify(Resume);
}
});
}
Expand Down Expand Up @@ -83,19 +83,21 @@ namespace talcs {
isPauseRequiredEmitted = false;
}
}
void FutureAudioSourceClipSeriesPrivate::checkAndNotify(qint64 position, qint64 length) {
void FutureAudioSourceClipSeriesPrivate::checkAndNotify(qint64 position, qint64 length, NotifyPurpose purpose) {
Q_Q(FutureAudioSourceClipSeries);
if (readMode == FutureAudioSourceClipSeries::Notify) {
if (!q->canRead(position + length, length)) {
if (readMode != FutureAudioSourceClipSeries::Notify)
return;
if (!q->canRead(position + length, length)) {
if (purpose == Pause)
notifyPause();
} else {
} else {
if (purpose == Resume)
notifyResume();
}
}
}
void FutureAudioSourceClipSeriesPrivate::checkAndNotify() {
void FutureAudioSourceClipSeriesPrivate::checkAndNotify(NotifyPurpose purpose) {
Q_Q(FutureAudioSourceClipSeries);
checkAndNotify(position, q->bufferSize());
checkAndNotify(position, q->bufferSize(), purpose);
}

/**
Expand All @@ -120,8 +122,8 @@ namespace talcs {
qint64 FutureAudioSourceClipSeries::processReading(const AudioSourceReadData &readData) {
Q_D(FutureAudioSourceClipSeries);
QMutexLocker locker(&d->mutex);
d->checkAndNotify(d->position + readData.length, readData.length);
FutureAudioSourceClipSeriesPrivate::ClipInterval readDataInterval(nullptr, d->position, readData.length);
d->checkAndNotify(d->position + readData.length, readData.length, FutureAudioSourceClipSeriesPrivate::Pause);
for (int ch = 0; ch < readData.buffer->channelCount(); ch++) {
readData.buffer->clear(ch, readData.startPos, readData.length);
}
Expand Down Expand Up @@ -155,7 +157,7 @@ namespace talcs {
QMutexLocker locker(&d->mutex);
if (d->position != pos) {
d->position = pos;
d->checkAndNotify();
d->checkAndNotify(FutureAudioSourceClipSeriesPrivate::Resume);
}
}

Expand Down Expand Up @@ -184,7 +186,7 @@ namespace talcs {
auto ret = d->insertClip(content, position, startPos, length);
if (!ret.isNull()) {
d->postAddClip(d->intervalLookup(ret.position(), ret.content()));
d->checkAndNotify();
d->checkAndNotify(FutureAudioSourceClipSeriesPrivate::Resume);
}
return ret;
}
Expand Down Expand Up @@ -221,9 +223,9 @@ namespace talcs {
auto oldContent = clip.content();
auto ret = d->setClipContent(clip, content);
if (!ret.isNull()) {
d->checkAndNotify();
d->postRemoveClip({oldContent, ret.position(), ret.length()}, false);
d->postAddClip({content, ret.position(), ret.length()});
d->checkAndNotify(FutureAudioSourceClipSeriesPrivate::Resume);
}
return ret;
}
Expand All @@ -249,15 +251,15 @@ namespace talcs {
auto clipInterval = d->intervalLookup(clip.position(), clip.content());
d->removeClip(clip);
d->postRemoveClip(clipInterval);
d->checkAndNotify();
d->checkAndNotify(FutureAudioSourceClipSeriesPrivate::Resume);
}

void FutureAudioSourceClipSeries::removeAllClips() {
Q_D(FutureAudioSourceClipSeries);
QMutexLocker locker(&d->mutex);
d->removeAllClips();
d->preRemoveAllClips();
d->checkAndNotify();
d->checkAndNotify(FutureAudioSourceClipSeriesPrivate::Resume);
}

QList<FutureAudioSourceClipSeries::ClipView> FutureAudioSourceClipSeries::clips() const {
Expand Down Expand Up @@ -342,8 +344,8 @@ namespace talcs {
void FutureAudioSourceClipSeries::setReadMode(FutureAudioSourceClipSeries::ReadMode readMode) {
Q_D(FutureAudioSourceClipSeries);
QMutexLocker locker(&d->mutex);
d->checkAndNotify(FutureAudioSourceClipSeriesPrivate::Resume);
d->readMode = readMode;
d->checkAndNotify();
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/core/source/FutureAudioSourceClipSeries_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ namespace talcs {

void notifyPause();
void notifyResume();
void checkAndNotify(qint64 position, qint64 length);
void checkAndNotify();
enum NotifyPurpose {
Pause,
Resume,
};
void checkAndNotify(qint64 position, qint64 length, NotifyPurpose purpose);
void checkAndNotify(NotifyPurpose purpose);
};

}
Expand Down

0 comments on commit cf7826a

Please sign in to comment.