Commit b18469b8 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix timeline clip duration not updated after clip reload.

Related to #487
parent e61403cd
......@@ -398,7 +398,7 @@ bool ClipModel::isAudioOnly() const
return m_currentState == PlaylistState::AudioOnly;
}
void ClipModel::refreshProducerFromBin(PlaylistState::ClipState state, double speed)
void ClipModel::refreshProducerFromBin(int trackId, PlaylistState::ClipState state, double speed)
{
// We require that the producer is not in the track when we refresh the producer, because otherwise the modification will not be propagated. Remove the clip
// first, refresh, and then replant.
......@@ -414,7 +414,7 @@ void ClipModel::refreshProducerFromBin(PlaylistState::ClipState state, double sp
qDebug() << "changing speed" << in << out << m_speed;
}
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(m_binClipId);
std::shared_ptr<Mlt::Producer> binProducer = binClip->getTimelineProducer(m_currentTrackId, m_id, state, m_speed);
std::shared_ptr<Mlt::Producer> binProducer = binClip->getTimelineProducer(trackId, m_id, state, m_speed);
m_producer = std::move(binProducer);
m_producer->set_in_and_out(in, out);
// replant effect stack in updated service
......@@ -424,9 +424,12 @@ void ClipModel::refreshProducerFromBin(PlaylistState::ClipState state, double sp
m_endlessResize = !binClip->hasLimitedDuration();
}
void ClipModel::refreshProducerFromBin()
void ClipModel::refreshProducerFromBin(int trackId)
{
refreshProducerFromBin(m_currentState);
if (trackId == -1) {
trackId = m_currentTrackId;
}
refreshProducerFromBin(trackId, m_currentState);
}
bool ClipModel::useTimewarpProducer(double speed, bool changeDuration, Fun &undo, Fun &redo)
......@@ -508,7 +511,7 @@ Fun ClipModel::useTimewarpProducer_lambda(double speed)
QWriteLocker locker(&m_lock);
return [speed, this]() {
qDebug() << "timeWarp producer" << speed;
refreshProducerFromBin(m_currentState, speed);
refreshProducerFromBin(m_currentTrackId, m_currentState, speed);
if (auto ptr = m_parent.lock()) {
QModelIndex ix = ptr->makeClipIndexFromID(m_id);
ptr->notifyChange(ix, ix, TimelineModel::SpeedRole);
......@@ -597,7 +600,7 @@ void ClipModel::setCurrentTrackId(int tid, bool finalMove)
}
if (finalMove && tid != -1 && m_lastTrackId != m_currentTrackId) {
refreshProducerFromBin(m_currentState);
refreshProducerFromBin(m_currentTrackId, m_currentState);
m_lastTrackId = m_currentTrackId;
}
}
......@@ -611,7 +614,7 @@ Fun ClipModel::setClipState_lambda(PlaylistState::ClipState state)
// Enforce producer reload
m_lastTrackId = -1;
if (m_currentTrackId != -1 && ptr->isClip(m_id)) { // if this is false, the clip is being created. Don't update model in that case
refreshProducerFromBin(m_currentState);
refreshProducerFromBin(m_currentTrackId, m_currentState);
QModelIndex ix = ptr->makeClipIndexFromID(m_id);
ptr->dataChanged(ix, ix, {TimelineModel::StatusRole});
}
......
......@@ -173,8 +173,8 @@ protected:
* @param speed corresponds to the speed we need. Leave to 0 to keep current speed. Warning: this function doesn't notify the model. Unless you know what
* you are doing, better use useTimewarProducer to change the speed
*/
void refreshProducerFromBin(PlaylistState::ClipState state, double speed = 0);
void refreshProducerFromBin();
void refreshProducerFromBin(int trackId, PlaylistState::ClipState state, double speed = 0);
void refreshProducerFromBin(int trackId = -1);
/* @brief This functions replaces the current producer with a slowmotion one
It also resizes the producer so that set of frames contained in the clip is the same
......
......@@ -953,7 +953,7 @@ bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Playl
// We capture a shared_ptr to the clip, which means that as long as this undo object lives, the clip object is not deleted. To insert it back it is
// sufficient to register it.
registerClip(clip, true);
clip->refreshProducerFromBin(state);
clip->refreshProducerFromBin(-1, state);
return true;
};
......@@ -3336,7 +3336,7 @@ void TimelineModel::requestClipReload(int clipId)
int old_trackId = getClipTrackId(clipId);
int oldPos = getClipPosition(clipId);
int oldOut = getClipIn(clipId) + getClipPlaytime(clipId);
int maxDuration = m_allClips[clipId]->getMaxDuration();
// 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();
......@@ -3344,8 +3344,12 @@ void TimelineModel::requestClipReload(int clipId)
getTrackById(old_trackId)->requestClipDeletion(clipId, refreshView, true, local_undo, local_redo, false, false);
}
if (old_trackId != -1) {
m_allClips[clipId]->refreshProducerFromBin();
m_allClips[clipId]->refreshProducerFromBin(old_trackId);
getTrackById(old_trackId)->requestClipInsertion(clipId, oldPos, refreshView, true, local_undo, local_redo);
if (maxDuration != m_allClips[clipId]->getMaxDuration()) {
QModelIndex ix = makeClipIndexFromID(clipId);
emit dataChanged(ix, ix, {TimelineModel::MaxDurationRole});
}
}
}
......
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