Fix timeline operations (insert/overwrite/lift)

parent ad3f67d6
...@@ -2426,10 +2426,11 @@ void MainWindow::slotInsertClipOverwrite() ...@@ -2426,10 +2426,11 @@ void MainWindow::slotInsertClipOverwrite()
} }
int pos = getMainTimeline()->controller()->insertZone(binId, m_clipMonitor->getZoneInfo(), true); int pos = getMainTimeline()->controller()->insertZone(binId, m_clipMonitor->getZoneInfo(), true);
if (pos > 0) { if (pos > 0) {
Kdenlive::MonitorId activeMonitor = pCore->monitorManager()->activeMonitor()->id();
pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor); pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor);
m_projectMonitor->refreshMonitorIfActive(true); m_projectMonitor->refreshMonitorIfActive(true);
getCurrentTimeline()->controller()->setPosition(pos); getCurrentTimeline()->controller()->setPosition(pos);
pCore->monitorManager()->activateMonitor(Kdenlive::ClipMonitor); pCore->monitorManager()->activateMonitor(activeMonitor);
} }
} }
...@@ -2442,10 +2443,11 @@ void MainWindow::slotInsertClipInsert() ...@@ -2442,10 +2443,11 @@ void MainWindow::slotInsertClipInsert()
} }
int pos = getMainTimeline()->controller()->insertZone(binId, m_clipMonitor->getZoneInfo(), false); int pos = getMainTimeline()->controller()->insertZone(binId, m_clipMonitor->getZoneInfo(), false);
if (pos > 0) { if (pos > 0) {
Kdenlive::MonitorId activeMonitor = pCore->monitorManager()->activeMonitor()->id();
pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor); pCore->monitorManager()->activateMonitor(Kdenlive::ProjectMonitor);
m_projectMonitor->refreshMonitorIfActive(true); m_projectMonitor->refreshMonitorIfActive(true);
getCurrentTimeline()->controller()->setPosition(pos); getCurrentTimeline()->controller()->setPosition(pos);
pCore->monitorManager()->activateMonitor(Kdenlive::ClipMonitor); pCore->monitorManager()->activateMonitor(activeMonitor);
} }
} }
......
...@@ -295,7 +295,6 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim ...@@ -295,7 +295,6 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
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 = true; bool result = true;
int trackId = trackIds.first();
if (overwrite) { if (overwrite) {
// Cut all tracks // Cut all tracks
auto it = timeline->m_allTracks.cbegin(); auto it = timeline->m_allTracks.cbegin();
...@@ -331,9 +330,11 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim ...@@ -331,9 +330,11 @@ bool TimelineFunctions::insertZone(const std::shared_ptr<TimelineItemModel> &tim
result = result && TimelineFunctions::requestInsertSpace(timeline, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo); result = result && TimelineFunctions::requestInsertSpace(timeline, QPoint(insertFrame, insertFrame + (zone.y() - zone.x())), undo, redo);
} }
if (result) { if (result) {
int newId = -1; if (!trackIds.isEmpty()) {
QString binClipId = QString("%1/%2/%3").arg(binId).arg(zone.x()).arg(zone.y() - 1); int newId = -1;
result = timeline->requestClipInsertion(binClipId, trackId, insertFrame, newId, true, true, true, undo, redo); QString binClipId = QString("%1/%2/%3").arg(binId).arg(zone.x()).arg(zone.y() - 1);
result = timeline->requestClipInsertion(binClipId, trackIds.first(), insertFrame, newId, true, true, true, undo, redo);
}
if (result) { if (result) {
pCore->pushUndo(undo, redo, overwrite ? i18n("Overwrite zone") : i18n("Insert zone")); pCore->pushUndo(undo, redo, overwrite ? i18n("Overwrite zone") : i18n("Insert zone"));
} }
...@@ -376,8 +377,18 @@ bool TimelineFunctions::liftZone(const std::shared_ptr<TimelineItemModel> &timel ...@@ -376,8 +377,18 @@ bool TimelineFunctions::liftZone(const std::shared_ptr<TimelineItemModel> &timel
bool TimelineFunctions::removeSpace(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, QPoint zone, Fun &undo, Fun &redo) bool TimelineFunctions::removeSpace(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, QPoint zone, Fun &undo, Fun &redo)
{ {
Q_UNUSED(trackId) Q_UNUSED(trackId)
std::unordered_set<int> clips = timeline->getItemsInRange(-1, zone.y() - 1, -1, true); std::unordered_set<int> clips;
auto it = timeline->m_allTracks.cbegin();
while (it != timeline->m_allTracks.cend()) {
int target_track = (*it)->getId();
if (timeline->m_videoTarget == target_track || timeline->m_audioTarget == target_track || timeline->getTrackById_const(target_track)->shouldReceiveTimelineOp()) {
std::unordered_set<int> subs = timeline->getItemsInRange(target_track, zone.y() - 1, -1, true);
clips.insert(subs.begin(), subs.end());
}
++it;
}
bool result = false; bool result = false;
if (!clips.empty()) { if (!clips.empty()) {
int clipId = *clips.begin(); int clipId = *clips.begin();
...@@ -401,12 +412,27 @@ bool TimelineFunctions::removeSpace(const std::shared_ptr<TimelineItemModel> &ti ...@@ -401,12 +412,27 @@ bool TimelineFunctions::removeSpace(const std::shared_ptr<TimelineItemModel> &ti
return result; return result;
} }
bool TimelineFunctions::requestInsertSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo) bool TimelineFunctions::requestInsertSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo, bool followTargets)
{ {
timeline->requestClearSelection(); timeline->requestClearSelection();
Fun local_undo = []() { return true; }; Fun local_undo = []() { return true; };
Fun local_redo = []() { return true; }; Fun local_redo = []() { return true; };
std::unordered_set<int> items = timeline->getItemsInRange(-1, zone.x(), -1, true); std::unordered_set<int> items;
if (!followTargets) {
// Select clips in all tracks
items = timeline->getItemsInRange(-1, zone.x(), -1, true);
} else {
// Select clips in target and active tracks only
auto it = timeline->m_allTracks.cbegin();
while (it != timeline->m_allTracks.cend()) {
int target_track = (*it)->getId();
if (timeline->m_videoTarget == target_track || timeline->m_audioTarget == target_track || timeline->getTrackById_const(target_track)->shouldReceiveTimelineOp()) {
std::unordered_set<int> subs = timeline->getItemsInRange(target_track, zone.x(), -1, true);
items.insert(subs.begin(), subs.end());
}
++it;
}
}
if (items.empty()) { if (items.empty()) {
return true; return true;
} }
......
...@@ -88,7 +88,7 @@ struct TimelineFunctions ...@@ -88,7 +88,7 @@ struct TimelineFunctions
/** @brief This function will insert a blank space starting at zone.x, and ending at zone.y. This will affect all the tracks /** @brief This function will insert a blank space starting at zone.x, and ending at zone.y. This will affect all the tracks
@returns true on success, false otherwise @returns true on success, false otherwise
*/ */
static bool requestInsertSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo); static bool requestInsertSpace(const std::shared_ptr<TimelineItemModel> &timeline, QPoint zone, Fun &undo, Fun &redo, bool followTargets = true);
static bool insertZone(const std::shared_ptr<TimelineItemModel> &timeline, QList<int> trackIds, const QString &binId, int insertFrame, QPoint zone, static bool insertZone(const std::shared_ptr<TimelineItemModel> &timeline, QList<int> trackIds, const QString &binId, int insertFrame, QPoint zone,
bool overwrite); bool overwrite);
......
...@@ -1526,7 +1526,7 @@ int TimelineController::insertZone(const QString &binId, QPoint zone, bool overw ...@@ -1526,7 +1526,7 @@ int TimelineController::insertZone(const QString &binId, QPoint zone, bool overw
if (clip->hasVideo()) { if (clip->hasVideo()) {
vTrack = videoTarget(); vTrack = videoTarget();
} }
if (aTrack == -1 && vTrack == -1) { /*if (aTrack == -1 && vTrack == -1) {
// No target tracks defined, use active track // No target tracks defined, use active track
if (m_model->getTrackById_const(m_activeTrack)->isAudioTrack()) { if (m_model->getTrackById_const(m_activeTrack)->isAudioTrack()) {
aTrack = m_activeTrack; aTrack = m_activeTrack;
...@@ -1535,7 +1535,7 @@ int TimelineController::insertZone(const QString &binId, QPoint zone, bool overw ...@@ -1535,7 +1535,7 @@ int TimelineController::insertZone(const QString &binId, QPoint zone, bool overw
vTrack = m_activeTrack; vTrack = m_activeTrack;
aTrack = m_model->getMirrorAudioTrackId(vTrack); aTrack = m_model->getMirrorAudioTrackId(vTrack);
} }
} }*/
int insertPoint; int insertPoint;
QPoint sourceZone; QPoint sourceZone;
if (useRuler() && m_zone != QPoint()) { if (useRuler() && m_zone != QPoint()) {
...@@ -2070,7 +2070,7 @@ bool TimelineController::endFakeMove(int clipId, int position, bool updateView, ...@@ -2070,7 +2070,7 @@ bool TimelineController::endFakeMove(int clipId, int position, bool updateView,
// There is a clip, cut // There is a clip, cut
res = res && TimelineFunctions::requestClipCut(m_model, startClipId, position, undo, redo); res = res && TimelineFunctions::requestClipCut(m_model, startClipId, position, undo, redo);
} }
res = res && TimelineFunctions::requestInsertSpace(m_model, QPoint(position, position + duration), undo, redo); res = res && TimelineFunctions::requestInsertSpace(m_model, QPoint(position, position + duration), undo, redo, false);
} }
res = res && m_model->getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, undo, redo); res = res && m_model->getTrackById(trackId)->requestClipInsertion(clipId, position, updateView, invalidateTimeline, undo, redo);
if (res) { if (res) {
...@@ -2184,7 +2184,7 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra ...@@ -2184,7 +2184,7 @@ bool TimelineController::endFakeGroupMove(int clipId, int groupId, int delta_tra
res = res && TimelineFunctions::requestClipCut(m_model, startClipId, target_position, undo, redo); res = res && TimelineFunctions::requestClipCut(m_model, startClipId, target_position, undo, redo);
} }
} }
res = res && TimelineFunctions::requestInsertSpace(m_model, QPoint(min, max), undo, redo); res = res && TimelineFunctions::requestInsertSpace(m_model, QPoint(min, max), undo, redo, false);
} }
for (int item : sorted_clips) { for (int item : sorted_clips) {
if (m_model->isClip(item)) { if (m_model->isClip(item)) {
......
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