Commit a12ba6df authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle

When switching project profile and there is only 1 clip in timeline, update...

When switching project profile and there is only 1 clip in timeline, update the timeline clip duration accordingly to profile change.
Fixes #819
parent 9b615fca
Pipeline #38372 passed with stage
in 19 minutes and 53 seconds
......@@ -3947,6 +3947,11 @@ void Bin::reloadAllProducers(bool reloadThumbs)
}
QList<std::shared_ptr<ProjectClip>> clipList = m_itemModel->getRootFolder()->childClips();
emit openClip(std::shared_ptr<ProjectClip>());
if (clipList.count() == 1) {
// We only have one clip in the project, so this was called on a reset profile event.
// Check if the clip is included in timeline to update it afterwards
clipList.first()->updateTimelineOnReload();
}
for (const std::shared_ptr<ProjectClip> &clip : qAsConst(clipList)) {
QDomDocument doc;
QDomElement xml = clip->toXml(doc, false, false);
......
......@@ -81,6 +81,7 @@ RTTR_REGISTRATION
ProjectClip::ProjectClip(const QString &id, const QIcon &thumb, const std::shared_ptr<ProjectItemModel> &model, std::shared_ptr<Mlt::Producer> producer)
: AbstractProjectItem(AbstractProjectItem::ClipItem, id, model)
, ClipController(id, std::move(producer))
, m_resetTimelineOccurences(false)
{
m_markerModel = std::make_shared<MarkerListModel>(id, pCore->projectManager()->undoStack());
if (producer->get_int("_placeholder") == 1) {
......@@ -136,6 +137,7 @@ void ProjectClip::importEffects(const std::shared_ptr<Mlt::Producer> &producer,
ProjectClip::ProjectClip(const QString &id, const QDomElement &description, const QIcon &thumb, const std::shared_ptr<ProjectItemModel> &model)
: AbstractProjectItem(AbstractProjectItem::ClipItem, id, model)
, ClipController(id)
, m_resetTimelineOccurences(false)
{
m_clipStatus = FileStatus::StatusWaiting;
m_thumbnail = thumb;
......@@ -1597,9 +1599,11 @@ bool ProjectClip::isIncludedInTimeline()
void ProjectClip::replaceInTimeline()
{
int updatedDuration = m_resetTimelineOccurences ? getFramePlaytime() : -1;
m_resetTimelineOccurences = false;
for (const auto &clip : m_registeredClips) {
if (auto timeline = clip.second.lock()) {
timeline->requestClipReload(clip.first);
timeline->requestClipReload(clip.first, updatedDuration);
} else {
qDebug() << "Error while reloading clip: timeline unavailable";
Q_ASSERT(false);
......@@ -1897,3 +1901,21 @@ QStringList ProjectClip::getAudioStreamEffect(int streamIndex) const
}
return effects;
}
void ProjectClip::updateTimelineOnReload()
{
if (m_registeredClips.size() > 0 && m_registeredClips.size() < 3) {
bool reloadProducer = true;
for (const auto &clip : m_registeredClips) {
if (auto timeline = clip.second.lock()) {
if (timeline->getClipPlaytime(clip.first) < static_cast<int>(frameDuration())) {
reloadProducer = false;
break;
}
}
if (reloadProducer) {
m_resetTimelineOccurences = true;
}
}
}
}
......@@ -245,6 +245,8 @@ public:
QStringList getAudioStreamEffect(int streamIndex) const override;
/** @brief Calculate the folder's hash (based on the files it contains). */
static const QByteArray getFolderHash(QDir dir);
/** @brief Check if the clip is included in timeline and reset its occurences on producer reload. */
void updateTimelineOnReload();
protected:
friend class ClipModel;
......@@ -290,6 +292,8 @@ private:
QList<int> m_requestedThumbs;
const QString geometryWithOffset(const QString &data, int offset);
QMap <QString, QByteArray> m_audioLevels;
/** @brief If true, all timeline occurences of this clip will be replaced from a fresh producer on reload. */
bool m_resetTimelineOccurences;
// This is a helper function that creates the disabled producer. This is a clone of the original one, with audio and video disabled
void createDisabledMasterProducer();
......
......@@ -1386,6 +1386,7 @@ void KdenliveDoc::slotSwitchProfile(const QString &profile_path, bool reloadThum
pCore->jobManager()->slotCancelJobs();
pCore->setCurrentProfile(profile_path);
updateProjectProfile(true, reloadThumbs);
// In case we only have one clip in timeline,
emit docModified(true);
}
......
......@@ -3700,7 +3700,7 @@ void TimelineModel::adjustAssetRange(int clipId, int in, int out)
// pCore->adjustAssetRange(clipId, in, out);
}
void TimelineModel::requestClipReload(int clipId)
void TimelineModel::requestClipReload(int clipId, int forceDuration)
{
std::function<bool(void)> local_undo = []() { return true; };
std::function<bool(void)> local_redo = []() { return true; };
......@@ -3719,12 +3719,15 @@ void TimelineModel::requestClipReload(int clipId)
int audioStream = m_allClips[clipId]->getIntProperty(QStringLiteral("audio_index"));
// Check if clip out is longer than actual producer duration (if user forced duration)
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(getClipBinId(clipId));
bool refreshView = oldOut > (int)binClip->frameDuration();
bool refreshView = oldOut > (int)binClip->frameDuration() || forceDuration > -1;
if (old_trackId != -1) {
getTrackById(old_trackId)->requestClipDeletion(clipId, refreshView, true, local_undo, local_redo, false, false);
}
if (old_trackId != -1) {
m_allClips[clipId]->refreshProducerFromBin(old_trackId, state, audioStream, 0, hasPitch);
if (forceDuration > -1) {
m_allClips[clipId]->requestResize(forceDuration, true, local_undo, local_redo);
}
getTrackById(old_trackId)->requestClipInsertion(clipId, oldPos, refreshView, true, local_undo, local_redo);
if (maxDuration != m_allClips[clipId]->getMaxDuration()) {
QModelIndex ix = makeClipIndexFromID(clipId);
......
......@@ -633,7 +633,7 @@ public:
*/
virtual void adjustAssetRange(int clipId, int in, int out);
void requestClipReload(int clipId);
void requestClipReload(int clipId, int forceDuration = -1);
void requestClipUpdate(int clipId, const QVector<int> &roles);
/** @brief define current edit mode (normal, insert, overwrite */
void setEditMode(TimelineMode::EditMode mode);
......
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