Fix lift zone random behavior

parent 5cd743b0
...@@ -2528,7 +2528,7 @@ void MainWindow::slotExtractZone() ...@@ -2528,7 +2528,7 @@ void MainWindow::slotExtractZone()
void MainWindow::slotLiftZone() void MainWindow::slotLiftZone()
{ {
getMainTimeline()->controller()->liftZone(m_clipMonitor->getZoneInfo()); getMainTimeline()->controller()->extractZone(m_clipMonitor->getZoneInfo(), true);
} }
void MainWindow::slotPreviewRender() void MainWindow::slotPreviewRender()
......
...@@ -69,7 +69,6 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt ...@@ -69,7 +69,6 @@ int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QSt
state = stateFromBool(videoAudio); state = stateFromBool(videoAudio);
std::shared_ptr<Mlt::Producer> cutProducer = binClip->getTimelineProducer(id, state, 1.); std::shared_ptr<Mlt::Producer> cutProducer = binClip->getTimelineProducer(id, state, 1.);
std::shared_ptr<ClipModel> clip(new ClipModel(parent, cutProducer, binClipId, id, state)); std::shared_ptr<ClipModel> clip(new ClipModel(parent, cutProducer, binClipId, id, state));
clip->setClipState_lambda(state)(); clip->setClipState_lambda(state)();
parent->registerClip(clip); parent->registerClip(clip);
...@@ -483,6 +482,9 @@ bool ClipModel::setClipState(PlaylistState::ClipState state, Fun &undo, Fun &red ...@@ -483,6 +482,9 @@ bool ClipModel::setClipState(PlaylistState::ClipState state, Fun &undo, Fun &red
if (state == PlaylistState::AudioOnly && !canBeAudio()) { if (state == PlaylistState::AudioOnly && !canBeAudio()) {
return false; return false;
} }
if (state == m_currentState) {
return true;
}
auto old_state = m_currentState; auto old_state = m_currentState;
auto operation = setClipState_lambda(state); auto operation = setClipState_lambda(state);
if (operation()) { if (operation()) {
......
...@@ -222,12 +222,12 @@ bool TimelineFunctions::extractZone(std::shared_ptr<TimelineItemModel> timeline, ...@@ -222,12 +222,12 @@ bool TimelineFunctions::extractZone(std::shared_ptr<TimelineItemModel> timeline,
// Start undoable command // Start undoable command
std::function<bool(void)> undo = []() { return true; }; std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; }; std::function<bool(void)> redo = []() { return true; };
bool result = false; bool result = true;
for (int trackId : tracks) { for (int trackId : tracks) {
result = TimelineFunctions::liftZone(timeline, trackId, zone, undo, redo); result = result && TimelineFunctions::liftZone(timeline, trackId, zone, undo, redo);
if (result && !liftOnly) { }
result = TimelineFunctions::removeSpace(timeline, trackId, zone, undo, redo); if (result && !liftOnly) {
} result = TimelineFunctions::removeSpace(timeline, -1, zone, undo, redo);
} }
pCore->pushUndo(undo, redo, liftOnly ? i18n("Lift zone") : i18n("Extract zone")); pCore->pushUndo(undo, redo, liftOnly ? i18n("Lift zone") : i18n("Extract zone"));
return result; return result;
...@@ -305,6 +305,9 @@ bool TimelineFunctions::removeSpace(std::shared_ptr<TimelineItemModel> timeline, ...@@ -305,6 +305,9 @@ bool TimelineFunctions::removeSpace(std::shared_ptr<TimelineItemModel> timeline,
if (result) { if (result) {
result = timeline->requestClipUngroup(clipId, undo, redo); result = timeline->requestClipUngroup(clipId, undo, redo);
} }
if (!result) {
undo();
}
} }
} else { } else {
// only 1 clip to be moved // only 1 clip to be moved
......
...@@ -594,24 +594,15 @@ int TrackModel::getClipByRow(int row) const ...@@ -594,24 +594,15 @@ int TrackModel::getClipByRow(int row) const
std::unordered_set<int> TrackModel::getClipsAfterPosition(int position, int end) std::unordered_set<int> TrackModel::getClipsAfterPosition(int position, int end)
{ {
READ_LOCK(); READ_LOCK();
// TODO: this function doesn't take into accounts the fact that there are two tracks
std::unordered_set<int> ids; std::unordered_set<int> ids;
int ix = m_playlists[0].get_clip_index_at(position); for (auto clp : m_allClips) {
if (end > -1) { int pos = clp.second->getPosition();
end = m_playlists[0].get_clip_index_at(end); if (end > -1 && pos >= end) {
if (end < m_playlists[0].count()) {
end++;
}
} else {
end = m_playlists[0].count();
}
while (ix < end) {
QSharedPointer<Mlt::Producer> prod(m_playlists[0].get_clip(ix));
ix++;
if (prod->is_blank()) {
continue; continue;
} }
ids.insert(prod->get_int("_kdenlive_cid")); if (pos >= position) {
ids.insert(clp.first);
}
} }
return ids; return ids;
} }
......
...@@ -1384,7 +1384,7 @@ void TimelineController::switchCompositing(int mode) ...@@ -1384,7 +1384,7 @@ void TimelineController::switchCompositing(int mode)
pCore->requestMonitorRefresh(); pCore->requestMonitorRefresh();
} }
void TimelineController::extractZone(QPoint zone) void TimelineController::extractZone(QPoint zone, bool liftOnly)
{ {
QVector<int> tracks; QVector<int> tracks;
if (audioTarget() >= 0) { if (audioTarget() >= 0) {
...@@ -1401,7 +1401,7 @@ void TimelineController::extractZone(QPoint zone) ...@@ -1401,7 +1401,7 @@ void TimelineController::extractZone(QPoint zone)
zone.setY(timelinePosition() + zone.y() - zone.x()); zone.setY(timelinePosition() + zone.y() - zone.x());
zone.setX(timelinePosition()); zone.setX(timelinePosition());
} }
TimelineFunctions::extractZone(m_model, tracks, m_zone == QPoint() ? zone : m_zone, false); TimelineFunctions::extractZone(m_model, tracks, m_zone == QPoint() ? zone : m_zone, liftOnly);
} }
void TimelineController::extract(int clipId) void TimelineController::extract(int clipId)
...@@ -1413,26 +1413,6 @@ void TimelineController::extract(int clipId) ...@@ -1413,26 +1413,6 @@ void TimelineController::extract(int clipId)
TimelineFunctions::extractZone(m_model, QVector<int>() << track, zone, false); TimelineFunctions::extractZone(m_model, QVector<int>() << track, zone, false);
} }
void TimelineController::liftZone(QPoint zone)
{
QVector<int> tracks;
if (audioTarget() >= 0) {
tracks << audioTarget();
}
if (videoTarget() >= 0) {
tracks << videoTarget();
}
if (tracks.isEmpty()) {
tracks << m_activeTrack;
}
if (m_zone == QPoint()) {
// Use current timeline position and clip zone length
zone.setY(timelinePosition() + zone.y() - zone.x());
zone.setX(timelinePosition());
}
TimelineFunctions::extractZone(m_model, tracks, m_zone == QPoint() ? zone : m_zone, true);
}
int TimelineController::insertZone(const QString &binId, QPoint zone, bool overwrite) int TimelineController::insertZone(const QString &binId, QPoint zone, bool overwrite)
{ {
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(binId); std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(binId);
......
...@@ -343,10 +343,10 @@ public: ...@@ -343,10 +343,10 @@ public:
/** @brief Change a clip item's speed in timeline */ /** @brief Change a clip item's speed in timeline */
Q_INVOKABLE void changeItemSpeed(int clipId, int speed); Q_INVOKABLE void changeItemSpeed(int clipId, int speed);
/** @brief Delete selected zone and fill gap by moving following clips*/ /** @brief Delete selected zone and fill gap by moving following clips
void extractZone(QPoint zone); * @param lift if true, the zone will simply be deleted but clips won't be moved
/** @brief Delete selected zone */ */
void liftZone(QPoint zone); void extractZone(QPoint zone, bool liftOnly = false);
/** @brief Insert clip monitor into timeline /** @brief Insert clip monitor into timeline
* @returns the zone end position or -1 on fail * @returns the zone end position or -1 on fail
*/ */
......
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