Fix lift zone random behavior

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