Fix group of clips with mix broken after reloading project

parent 378c4c72
......@@ -766,7 +766,7 @@ int GroupsModel::fromJson(const QJsonObject &o, Fun &undo, Fun &redo)
int pos = data.section(":", 1, 1).toInt();
int id = -1;
if (leaf == QLatin1String("clip")) {
id = ptr->getClipByPosition(trackId, pos);
id = ptr->getClipByStartPosition(trackId, pos);
} else if (leaf == QLatin1String("composition")) {
id = ptr->getCompositionByPosition(trackId, pos);
} else {
......
......@@ -328,6 +328,13 @@ int TimelineModel::getTrackClipsCount(int trackId) const
return count;
}
int TimelineModel::getClipByStartPosition(int trackId, int position) const
{
READ_LOCK();
Q_ASSERT(isTrack(trackId));
return getTrackById_const(trackId)->getClipByStartPosition(position);
}
int TimelineModel::getClipByPosition(int trackId, int position) const
{
READ_LOCK();
......
......@@ -620,6 +620,7 @@ public:
/* @brief Get a timeline clip id by its position or -1 if not found
*/
int getClipByPosition(int trackId, int position) const;
int getClipByStartPosition(int trackId, int position) const;
/* @brief Get a timeline composition id by its starting position or -1 if not found
*/
......
......@@ -707,6 +707,17 @@ int TrackModel::getId() const
return m_id;
}
int TrackModel::getClipByStartPosition(int position) const
{
READ_LOCK();
for (auto &clip : m_allClips) {
if (clip.second->getPosition() == position) {
return clip.second->getId();
}
}
return -1;
}
int TrackModel::getClipByPosition(int position, int playlist)
{
READ_LOCK();
......@@ -1748,7 +1759,7 @@ bool TrackModel::requestClipMix(std::pair<int, int> clipIds, int mixDuration, bo
return true;
};
// lock MLT playlist so that we don't end up with invalid frames in monitor
auto operation = requestClipDeletion_lambda(clipIds.second, updateView, finalMove, groupMove, finalMove);
auto operation = requestClipDeletion_lambda(clipIds.second, updateView, finalMove, groupMove, false);
bool res = operation();
if (res) {
Fun replay = [this, clipIds, dest_track, firstClipPos, secondClipDuration, mixPosition, mixDuration, build_mix, secondClipPos, clipHasEndMix, updateView, finalMove, groupMove, rearrange_playlists]() {
......@@ -2035,6 +2046,9 @@ bool TrackModel::loadMix(Mlt::Transition &t)
bool reverse = t.get_int("reverse") == 1;
int cid1 = getClipByPosition(in, reverse ? 1 : 0);
int cid2 = getClipByPosition(out, reverse ? 0 : 1);
if (cid1 < 0 || cid2 < 0) {
return false;
}
std::shared_ptr<Mlt::Transition>tr(&t);
m_sameCompositions[cid2] = tr;
m_mixList.insert(cid1, cid2);
......
......@@ -267,6 +267,8 @@ protected:
/* @brief Returns the clip id on this track at position requested, or -1 if no clip */
int getClipByPosition(int position, int playlist = -1);
/* @brief Returns the clip id on this track that starts at position requested, or -1 if no clip */
int getClipByStartPosition(int position) const;
/* @brief Returns the composition id on this track starting position requested, or -1 if not found */
int getCompositionByPosition(int position);
......
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