* Fix model insert/delete track, so we don'tneed to reset view, makes these operation much faster

* Fix track compositing incorrect after undoing track deletion
parent f247b1a4
Pipeline #11521 passed with stage
in 13 minutes and 56 seconds
......@@ -90,7 +90,7 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
if (!audioTrack) {
videoTracksIndexes << i;
}
ok = timeline->requestTrackInsertion(-1, tid, QString(), audioTrack, undo, redo, false);
ok = timeline->requestTrackInsertion(-1, tid, QString(), audioTrack, undo, redo);
if (track->get_int("kdenlive:locked_track") > 0) {
lockedTracksIndexes << tid;
}
......@@ -111,7 +111,7 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
if (!audioTrack) {
videoTracksIndexes << i;
}
ok = timeline->requestTrackInsertion(-1, tid, trackName, audioTrack, undo, redo, false);
ok = timeline->requestTrackInsertion(-1, tid, trackName, audioTrack, undo, redo);
int muteState = track->get_int("hide");
if (muteState > 0 && (!audioTrack || (audioTrack && muteState != 1))) {
timeline->setTrackProperty(tid, QStringLiteral("hide"), QString::number(muteState));
......
......@@ -92,15 +92,14 @@ public:
void notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, const QVector<int> &roles) override;
void notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, int role) override;
/** @brief Rebuild track compositing */
void buildTrackCompositing(bool rebuild = false);
/** @brief Import track effects */
void importTrackEffects(int tid, std::weak_ptr<Mlt::Service> service);
const QString groupsData();
bool loadGroups(const QString &groupsData);
/** @brief Rebuild track compositing */
void buildTrackCompositing(bool rebuild = false) override;
void _beginRemoveRows(const QModelIndex & /*unused*/, int /*unused*/, int /*unused*/) override;
void _beginInsertRows(const QModelIndex & /*unused*/, int /*unused*/, int /*unused*/) override;
void _endRemoveRows() override;
......
......@@ -154,7 +154,7 @@ TimelineModel::~TimelineModel()
all_ids.push_back(tracks.first);
}
for (auto tracks : all_ids) {
deregisterTrack_lambda(tracks, false)();
deregisterTrack_lambda(tracks)();
}
for (const auto &clip : m_allClips) {
clip.second->deregisterClipToBin();
......@@ -2157,7 +2157,7 @@ bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &
TRACE(position, id, trackName, audioTrack);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool result = requestTrackInsertion(position, id, trackName, audioTrack, undo, redo, true);
bool result = requestTrackInsertion(position, id, trackName, audioTrack, undo, redo);
if (result) {
PUSH_UNDO(undo, redo, i18n("Insert Track"));
}
......@@ -2165,7 +2165,7 @@ bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &
return result;
}
bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &trackName, bool audioTrack, Fun &undo, Fun &redo, bool updateView)
bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &trackName, bool audioTrack, Fun &undo, Fun &redo)
{
// TODO: make sure we disable overlayTrack before inserting a track
if (position == -1) {
......@@ -2180,7 +2180,7 @@ bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &
}
int trackId = TimelineModel::getNextId();
id = trackId;
Fun local_undo = deregisterTrack_lambda(trackId, true);
Fun local_undo = deregisterTrack_lambda(trackId);
TrackModel::construct(shared_from_this(), trackId, position, trackName, audioTrack);
// Adjust compositions that were affecting track at previous pos
Fun local_update = [previousId, position, this]() {
......@@ -2194,21 +2194,22 @@ bool TimelineModel::requestTrackInsertion(int position, int &id, const QString &
return true;
};
local_update();
Fun rebuild_compositing = [this]() {
buildTrackCompositing(true);
return true;
};
buildTrackCompositing(true);
auto track = getTrackById(trackId);
Fun local_redo = [track, position, updateView, local_update, this]() {
Fun local_redo = [track, position, local_update, this]() {
// We capture a shared_ptr to the track, which means that as long as this undo object lives, the track object is not deleted. To insert it back it is
// sufficient to register it.
registerTrack(track, position, true);
local_update();
if (updateView) {
_resetView();
}
buildTrackCompositing(true);
return true;
};
PUSH_LAMBDA(rebuild_compositing, local_undo);
UPDATE_UNDO_REDO(local_redo, local_undo, undo, redo);
if (updateView) {
_resetView();
}
return true;
}
......@@ -2261,18 +2262,24 @@ bool TimelineModel::requestTrackDeletion(int trackId, Fun &undo, Fun &redo)
}
}
int old_position = getTrackPosition(trackId);
auto operation = deregisterTrack_lambda(trackId, true);
auto operation = deregisterTrack_lambda(trackId);
std::shared_ptr<TrackModel> track = getTrackById(trackId);
Fun reverse = [this, track, old_position]() {
// We capture a shared_ptr to the track, which means that as long as this undo object lives, the track object is not deleted. To insert it back it is
// sufficient to register it.
registerTrack(track, old_position);
_resetView();
return true;
};
Fun rebuild_compositing = [this]() {
buildTrackCompositing(true);
return true;
};
if (operation()) {
rebuild_compositing();
PUSH_LAMBDA(rebuild_compositing, local_undo);
UPDATE_UNDO_REDO(operation, reverse, local_undo, local_redo);
UPDATE_UNDO_REDO(local_redo, local_undo, undo, redo);
PUSH_LAMBDA(rebuild_compositing, redo);
return true;
}
local_undo();
......@@ -2325,9 +2332,9 @@ void TimelineModel::registerGroup(int groupId)
m_allGroups.insert(groupId);
}
Fun TimelineModel::deregisterTrack_lambda(int id, bool updateView)
Fun TimelineModel::deregisterTrack_lambda(int id)
{
return [this, id, updateView]() {
return [this, id]() {
// qDebug() << "DEREGISTER TRACK" << id;
emit checkTrackDeletion(id);
auto it = m_iteratorTable[id]; // iterator to the element
......@@ -2337,10 +2344,7 @@ Fun TimelineModel::deregisterTrack_lambda(int id, bool updateView)
m_allTracks.erase(it); // actual deletion of object
m_iteratorTable.erase(id); // clean table
beginRemoveRows(QModelIndex(), index, index);
endInsertRows();
if (updateView) {
_resetView();
}
endRemoveRows();
int cache = (int)QThread::idealThreadCount() + ((int)m_allTracks.size() + 1) * 2;
mlt_service_cache_set_size(NULL, "producer_avformat", qMax(4, cache));
return true;
......
......@@ -505,7 +505,7 @@ public:
*/
bool requestTrackInsertion(int pos, int &id, const QString &trackName = QString(), bool audioTrack = false);
/* Same function, but accumulates undo and redo*/
bool requestTrackInsertion(int pos, int &id, const QString &trackName, bool audioTrack, Fun &undo, Fun &redo, bool updateView = true);
bool requestTrackInsertion(int pos, int &id, const QString &trackName, bool audioTrack, Fun &undo, Fun &redo);
/* @brief Delete track with given id
This also deletes all the clips contained in the track.
......@@ -696,7 +696,7 @@ protected:
/* @brief Deregister and destruct the track with given id.
@parame updateView Whether to send updates to the model. Must be false when called from a constructor/destructor
*/
Fun deregisterTrack_lambda(int id, bool updateView = false);
Fun deregisterTrack_lambda(int id);
/* @brief Return a lambda that deregisters and destructs the clip with given id.
Note that the clip must already be deleted from its track and groups.
......@@ -825,6 +825,8 @@ protected:
// what follows are some virtual function that corresponds to the QML. They are implemented in TimelineItemModel
protected:
/** @brief Rebuild track compositing */
virtual void buildTrackCompositing(bool rebuild = false) = 0;
virtual void _beginRemoveRows(const QModelIndex &, int, int) = 0;
virtual void _beginInsertRows(const QModelIndex &, int, int) = 0;
virtual void _endRemoveRows() = 0;
......
......@@ -120,8 +120,8 @@ Rectangle {
}
onKeyframeModelChanged: {
console.log('keyframe model changed............')
if (effectRow.keyframecanvas) {
console.log('keyframe model changed............')
effectRow.keyframecanvas.requestPaint()
}
}
......
......@@ -566,7 +566,6 @@ void TimelineController::addTrack(int tid)
}
m_model->requestTrackInsertion(mirrorPos, newTid2, d->trackName(), true);
}
m_model->buildTrackCompositing(true);
if (audioRecTrack) {
m_model->setTrackProperty(newTid, "kdenlive:audio_rec", QStringLiteral("1"));
}
......@@ -582,7 +581,6 @@ void TimelineController::deleteTrack(int tid)
if (d->exec() == QDialog::Accepted) {
int selectedTrackIx = d->selectedTrackId();
m_model->requestTrackDeletion(selectedTrackIx);
m_model->buildTrackCompositing(true);
if (m_activeTrack == -1) {
setActiveTrack(m_model->getTrackIndexFromPosition(m_model->getTracksCount() - 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