Fix monitor audio thumb disappearing on proxy

parent b7ceb420
......@@ -1839,13 +1839,13 @@ void Bin::slotEditClipCommand(const QString &id, const QMap<QString, QString> &o
m_doc->commandStack()->push(command);
}
void Bin::reloadClip(const QString &id)
void Bin::reloadClip(const QString &id, bool reloadAudio)
{
std::shared_ptr<ProjectClip> clip = m_itemModel->getClipByBinID(id);
if (!clip) {
return;
}
clip->reloadProducer();
clip->reloadProducer(false, false, reloadAudio);
}
void Bin::reloadMonitorIfActive(const QString &id)
......
......@@ -207,7 +207,7 @@ public:
const QString getDocumentProperty(const QString &key);
/** @brief Ask MLT to reload this clip's producer */
void reloadClip(const QString &id);
void reloadClip(const QString &id, bool reloadAudio = true);
/** @brief refresh monitor (if clip changed) */
void reloadMonitorIfActive(const QString &id);
......
......@@ -295,7 +295,7 @@ size_t ProjectClip::frameDuration() const
return (size_t)d.frames(pCore->getCurrentFps());
}
void ProjectClip::reloadProducer(bool refreshOnly, bool audioStreamChanged)
void ProjectClip::reloadProducer(bool refreshOnly, bool audioStreamChanged, bool reloadAudio)
{
// we find if there are some loading job on that clip
int loadjobId = -1;
......@@ -305,7 +305,7 @@ void ProjectClip::reloadProducer(bool refreshOnly, bool audioStreamChanged)
// In that case, we only want a new thumbnail.
// We thus set up a thumb job. We must make sure that there is no pending LOADJOB
// Clear cache first
ThumbnailCache::get()->invalidateThumbsForClip(clipId());
ThumbnailCache::get()->invalidateThumbsForClip(clipId(), false);
pCore->jobManager()->discardJobs(clipId(), AbstractClipJob::THUMBJOB);
m_thumbsProducer.reset();
pCore->jobManager()->startJob<ThumbJob>({clipId()}, loadjobId, QString(), 150, -1, true, true);
......@@ -326,7 +326,7 @@ void ProjectClip::reloadProducer(bool refreshOnly, bool audioStreamChanged)
if (type != ClipType::Color && type != ClipType::Image && type != ClipType::SlideShow) {
xml.removeAttribute("out");
}
ThumbnailCache::get()->invalidateThumbsForClip(clipId());
ThumbnailCache::get()->invalidateThumbsForClip(clipId(), reloadAudio);
int loadJob = pCore->jobManager()->startJob<LoadJob>({clipId()}, loadjobId, QString(), xml);
pCore->jobManager()->startJob<ThumbJob>({clipId()}, loadJob, QString(), 150, -1, true, true);
if (audioStreamChanged) {
......@@ -1199,12 +1199,7 @@ void ProjectClip::discardAudioThumb()
const QString ProjectClip::getAudioThumbPath(bool miniThumb)
{
if (audioInfo() == nullptr) {
return QString();
}
int audioStream = audioInfo()->ffmpeg_audio_index();
QString clipHash = hash();
if (clipHash.isEmpty()) {
if (audioInfo() == nullptr && !miniThumb) {
return QString();
}
bool ok = false;
......@@ -1212,11 +1207,16 @@ const QString ProjectClip::getAudioThumbPath(bool miniThumb)
if (!ok) {
return QString();
}
const QString clipHash = hash();
if (clipHash.isEmpty()) {
return QString();
}
QString audioPath = thumbFolder.absoluteFilePath(clipHash);
if (miniThumb) {
audioPath.append(QStringLiteral(".png"));
return audioPath;
}
int audioStream = audioInfo()->ffmpeg_audio_index();
if (audioStream > 0) {
audioPath.append(QLatin1Char('_') + QString::number(audioInfo()->audio_index()));
}
......
......@@ -81,7 +81,7 @@ protected:
public:
~ProjectClip() override;
void reloadProducer(bool refreshOnly = false, bool audioStreamChanged = false);
void reloadProducer(bool refreshOnly = false, bool audioStreamChanged = false, bool reloadAudio = true);
/** @brief Returns a unique hash identifier used to store clip thumbnails. */
// virtual void hash() = 0;
......
......@@ -356,14 +356,14 @@ bool ProxyJob::commitResult(Fun &undo, Fun &redo)
binClip->setProducerProperty(QStringLiteral("_overwriteproxy"), QString());
const QString dest = binClip->getProducerProperty(QStringLiteral("kdenlive:proxy"));
binClip->setProducerProperty(QStringLiteral("resource"), dest);
pCore->bin()->reloadClip(clipId);
pCore->bin()->reloadClip(clipId, false);
return true;
};
auto reverse = [clipId = m_clipId]() {
auto binClip = pCore->projectItemModel()->getClipByBinID(clipId);
const QString dest = binClip->getProducerProperty(QStringLiteral("kdenlive:originalurl"));
binClip->setProducerProperty(QStringLiteral("resource"), dest);
pCore->bin()->reloadClip(clipId);
pCore->bin()->reloadClip(clipId, false);
return true;
};
bool ok = operation();
......
......@@ -212,7 +212,7 @@ void ThumbnailCache::saveCachedThumbs(QStringList keys)
}
}
void ThumbnailCache::invalidateThumbsForClip(const QString &binId)
void ThumbnailCache::invalidateThumbsForClip(const QString &binId, bool reloadAudio)
{
QMutexLocker locker(&m_mutex);
if (m_storedVolatile.find(binId) != m_storedVolatile.end()) {
......@@ -233,9 +233,11 @@ void ThumbnailCache::invalidateThumbsForClip(const QString &binId)
// Remove persistent cache
for (int pos : m_storedOnDisk.at(binId)) {
if (pos < 0) {
auto key = getAudioKey(binId, &ok);
if (ok) {
QFile::remove(audioThumbFolder.absoluteFilePath(key));
if (reloadAudio) {
auto key = getAudioKey(binId, &ok);
if (ok) {
QFile::remove(audioThumbFolder.absoluteFilePath(key));
}
}
} else {
auto key = getKey(binId, pos, &ok);
......
......@@ -71,7 +71,7 @@ public:
void storeThumbnail(const QString &binId, int pos, const QImage &img, bool persistent = false);
/* @brief Removes all the thumbnails for a given clip */
void invalidateThumbsForClip(const QString &binId);
void invalidateThumbsForClip(const QString &binId, bool reloadAudio);
/* @brief Save all cached thumbs to disk */
void saveCachedThumbs(QStringList keys);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment