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

Fix track effects not working when a clip is added at end of track or if last clip is resized.

Fixes #356
parent 21382f01
Pipeline #8119 passed with stage
in 22 minutes and 3 seconds
......@@ -620,7 +620,7 @@ void Core::invalidateRange(QSize range)
void Core::invalidateItem(ObjectId itemId)
{
if (!m_mainWindow || m_mainWindow->getCurrentTimeline()->loading) return;
if (!m_mainWindow || !m_mainWindow->getCurrentTimeline() || m_mainWindow->getCurrentTimeline()->loading) return;
switch (itemId.first) {
case ObjectType::TimelineClip:
case ObjectType::TimelineComposition:
......@@ -652,7 +652,7 @@ void Core::updateItemKeyframes(ObjectId id)
void Core::updateItemModel(ObjectId id, const QString &service)
{
if (m_mainWindow && !m_mainWindow->getCurrentTimeline()->loading && service.startsWith(QLatin1String("fade")) && id.first == ObjectType::TimelineClip) {
if (m_mainWindow && id.first == ObjectType::TimelineClip && !m_mainWindow->getCurrentTimeline()->loading && service.startsWith(QLatin1String("fade"))) {
bool startFade = service == QLatin1String("fadein") || service == QLatin1String("fade_from_black");
m_mainWindow->getCurrentTimeline()->controller()->updateClip(id.second, {startFade ? TimelineModel::FadeInRole : TimelineModel::FadeOutRole});
}
......
......@@ -591,7 +591,27 @@ bool EffectStackModel::adjustStackLength(bool adjustFromEnd, int oldIn, int oldD
PUSH_LAMBDA(refresh, redo);
PUSH_LAMBDA(refresh, undo);
} else {
qDebug() << "// NULL Keyframes---------";
if (m_ownerId.first == ObjectType::TimelineTrack) {
int oldEffectOut = effect->filter().get_out();
Fun operation = [effect, out, logUndo]() {
effect->setParameter(QStringLiteral("out"), out, logUndo);
return true;
};
bool res = operation();
if (!res) {
return false;
}
if (logUndo) {
Fun reverse = [effect, oldEffectOut]() {
effect->setParameter(QStringLiteral("out"), oldEffectOut, true);
return true;
};
PUSH_LAMBDA(operation, redo);
PUSH_LAMBDA(reverse, undo);
}
} else {
qDebug() << "// NULL Keyframes---------";
}
}
}
}
......
......@@ -171,6 +171,7 @@ bool ClipModel::requestResize(int size, bool right, Fun &undo, Fun &redo, bool l
int outPoint = out;
int inPoint = in;
int offset = 0;
int trackDuration = 0;
if (m_endlessResize) {
offset = inPoint;
outPoint = out - in;
......@@ -181,6 +182,9 @@ bool ClipModel::requestResize(int size, bool right, Fun &undo, Fun &redo, bool l
if (ptr->getTrackById(m_currentTrackId)->isLocked()) {
return false;
}
if (right && ptr->getTrackById_const(m_currentTrackId)->isLastClip(getPosition())) {
trackDuration = ptr->getTrackById_const(m_currentTrackId)->trackDuration();
}
track_operation = ptr->getTrackById(m_currentTrackId)->requestClipResize_lambda(m_id, inPoint, outPoint, right);
} else {
qDebug() << "Error : Moving clip failed because parent timeline is not available anymore";
......@@ -219,6 +223,14 @@ bool ClipModel::requestResize(int size, bool right, Fun &undo, Fun &redo, bool l
// Now, we are in the state in which the timeline should be when we try to revert current action. So we can build the reverse action from here
if (m_currentTrackId != -1) {
if (auto ptr = m_parent.lock()) {
if (trackDuration > 0) {
// Operation changed parent track duration, update effect stack
int newDuration = ptr->getTrackById_const(m_currentTrackId)->trackDuration();
if (logUndo || trackDuration != newDuration) {
// A clip move changed the track duration, update track effects
ptr->getTrackById(m_currentTrackId)->m_effectStack->adjustStackLength(true, 0, trackDuration, 0, newDuration, 0, undo, redo, logUndo);
}
}
track_reverse = ptr->getTrackById(m_currentTrackId)->requestClipResize_lambda(m_id, old_in, old_out, right);
}
}
......
......@@ -177,6 +177,7 @@ Fun TrackModel::requestClipInsertion_lambda(int clipId, int position, bool updat
m_playlists[0].unlock();
if (finalMove && !groupMove) {
ptr->updateDuration();
}
return index != -1 && end_function(0);
}
......@@ -236,9 +237,14 @@ bool TrackModel::requestClipInsertion(int clipId, int position, bool updateView,
if (ptr->getClipPtr(clipId)->clipState() != PlaylistState::Disabled) {
res = res && ptr->getClipPtr(clipId)->setClipState(isAudioTrack() ? PlaylistState::AudioOnly : PlaylistState::VideoOnly, local_undo, local_redo);
}
int duration = trackDuration();
auto operation = requestClipInsertion_lambda(clipId, position, updateView, finalMove, groupMove);
res = res && operation();
if (res) {
if (finalMove && duration != trackDuration()) {
// A clip move changed the track duration, update track effects
m_effectStack->adjustStackLength(true, 0, duration, 0, trackDuration(), 0, undo, redo, true);
}
auto reverse = requestClipDeletion_lambda(clipId, updateView, finalMove, groupMove);
UPDATE_UNDO_REDO(operation, reverse, local_undo, local_redo);
UPDATE_UNDO_REDO(local_redo, local_undo, undo, redo);
......@@ -346,8 +352,13 @@ bool TrackModel::requestClipDeletion(int clipId, bool updateView, bool finalMove
if (finalDeletion) {
m_allClips[clipId]->selected = false;
}
int duration = trackDuration();
auto operation = requestClipDeletion_lambda(clipId, updateView, finalMove, groupMove);
if (operation()) {
if (finalMove && duration != trackDuration()) {
// A clip move changed the track duration, update track effects
m_effectStack->adjustStackLength(true, 0, duration, 0, trackDuration(), 0, undo, redo, true);
}
auto reverse = requestClipInsertion_lambda(clipId, old_position, updateView, finalMove, groupMove);
UPDATE_UNDO_REDO(operation, reverse, undo, redo);
return true;
......@@ -921,6 +932,17 @@ std::pair<int, int> TrackModel::getClipIndexAt(int position)
return {-1, -1};
}
bool TrackModel::isLastClip(int position)
{
READ_LOCK();
for (int j = 0; j < 2; j++) {
if (!m_playlists[j].is_blank_at(position)) {
return m_playlists[j].get_clip_index_at(position) == m_playlists[j].count() - 1;
}
}
return false;
}
bool TrackModel::isBlankAt(int position)
{
READ_LOCK();
......@@ -1205,7 +1227,7 @@ void TrackModel::setEffectStackEnabled(bool enable)
m_effectStack->setEffectStackEnabled(enable);
}
int TrackModel::trackDuration()
int TrackModel::trackDuration() const
{
return m_track->get_length();
}
......
......@@ -182,6 +182,10 @@ protected:
int getBlankSizeNearComposition(int compoId, bool after);
int getBlankStart(int position);
int getBlankSizeAtPos(int frame);
/* @brief Returns true if clip at position is the last on playlist
* @param position the position in playlist
*/
bool isLastClip(int position);
/*@brief Returns the best composition duration depending on clips on the track */
int suggestCompositionLength(int position);
......@@ -248,7 +252,7 @@ protected:
* This is used when some properties of the clip have changed, and we need this to refresh it */
void replugClip(int clipId);
int trackDuration();
int trackDuration() const;
/* @brief Returns the list of the ids of the clips that intersect the given range */
std::unordered_set<int> getClipsInRange(int position, int end = -1);
......
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