Commit c98552e4 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Move clip cut in separate file to clean up timelinemodel. Don't reset timeline...

Move clip cut in separate file to clean up timelinemodel. Don't reset timeline id on project opening
parent 208a433f
......@@ -5,6 +5,7 @@ set(kdenlive_SRCS
timeline2/model/groupsmodel.cpp
timeline2/model/timelineitemmodel.cpp
timeline2/model/timelinemodel.cpp
timeline2/model/timelinefunctions.cpp
timeline2/model/trackmodel.cpp
timeline2/model/snapmodel.cpp
timeline2/model/builders/meltBuilder.cpp
......
......@@ -43,7 +43,9 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
Fun redo = []() { return true; };
// First, we destruct the previous tracks
timeline->requestReset(undo, redo);
pCore->binController()->loadBinPlaylist(&tractor, timeline->tractor());
const QStringList ids = pCore->binController()->getClipIds();
for (const QString &id : ids) {
if (id == QLatin1String("black")) {
......
/*
Copyright (C) 2017 Jean-Baptiste Mardelle <jb@kdenlive.org>
This file is part of Kdenlive. See www.kdenlive.org.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "timelinefunctions.hpp"
#include "klocalizedstring.h"
#include <QDebug>
bool TimelineFunction::requestClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position)
{
int start = timeline->getClipPosition(clipId);
int duration = timeline->getClipPlaytime(clipId);
if (start > position || (start + duration) < position) {
return false;
}
std::unordered_set<int> siblings = timeline->getGroupElements(clipId);
if (siblings.size() > 0) {
// TODO
}
int clipIn = timeline->getClipIn(clipId);
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
int in = position - start - clipIn;
int out = start + duration - position;
bool res = timeline->requestItemResize(clipId, position - start, true, true, undo, redo);
int newId;
const QString binId = timeline->getClipBinId(clipId);
res = timeline->requestClipCreation(binId, in, out, newId, undo, redo);
res = timeline->requestClipMove(newId, timeline->getItemTrackId(clipId), position, true, undo, redo);
if (res) {
//TODO
//PUSH_UNDO(undo, redo, i18n("Move clip"));
}
return res;
}
/*
Copyright (C) 2017 Jean-Baptiste Mardelle <jb@kdenlive.org>
This file is part of Kdenlive. See www.kdenlive.org.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
by the membership of KDE e.V.), which shall act as a proxy
defined in Section 14 of version 3 of the license.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TIMELINEFUNCTIONS_H
#define TIMELINEFUNCTIONS_H
#include <memory>
#include "timelineitemmodel.hpp"
/**
* @namespace TimelineFunction
* @brief This namespace contains a list of static methods for advanced timeline editing features
* based on timelinemodel methods
*/
namespace TimelineFunction {
bool requestClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position);
}
#endif
......@@ -191,7 +191,7 @@ QVariant TimelineItemModel::data(const QModelIndex &index, int role) const
if (role == ItemIdRole) {
return id;
}
// qDebug() << "REQUESTING DATA "<<roleNames()[role]<<index;
//qDebug() << "REQUESTING DATA "<<roleNames()[role]<<index;
if (isClip(id)) {
std::shared_ptr<ClipModel> clip = m_allClips.at(id);
// Get data for a clip
......
......@@ -149,6 +149,24 @@ int TimelineModel::getClipPosition(int clipId) const
return pos;
}
int TimelineModel::getClipIn(int clipId) const
{
READ_LOCK();
Q_ASSERT(m_allClips.count(clipId) > 0);
const auto clip = m_allClips.at(clipId);
int pos = clip->getIn();
return pos;
}
const QString TimelineModel::getClipBinId(int clipId) const
{
READ_LOCK();
Q_ASSERT(m_allClips.count(clipId) > 0);
const auto clip = m_allClips.at(clipId);
QString id = clip->binId();
return id;
}
int TimelineModel::getClipPlaytime(int clipId) const
{
READ_LOCK();
......@@ -267,35 +285,6 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool
return res;
}
bool TimelineModel::requestClipCut(int clipId, int position)
{
//QWriteLocker locker(&m_lock);
Q_ASSERT(m_allClips.count(clipId) > 0);
if (m_allClips[clipId]->getPosition() > position || (m_allClips[clipId]->getPosition() + m_allClips[clipId]->getPlaytime() < position)) {
return false;
}
if (m_groups->isInGroup(clipId)) {
// TODO
/*int groupId = m_groups->getRootId(clipId);
int current_trackId = getClipTrackId(clipId);
int track_pos1 = getTrackPosition(trackId);
int track_pos2 = getTrackPosition(current_trackId);
int delta_track = track_pos1 - track_pos2;
int delta_pos = position - m_allClips[clipId]->getPosition();*/
}
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
int in = position - m_allClips[clipId]->getPosition() - m_allClips[clipId]->getIn();
int out = m_allClips[clipId]->getPosition() + m_allClips[clipId]->getPlaytime() - position;
bool res = requestItemResize(clipId, position - m_allClips[clipId]->getPosition(), true, true, undo, redo);
int newId;
res = requestClipCreation(m_allClips[clipId]->binId(), in, out, newId, undo, redo);
res = requestClipMove(newId, m_allClips[clipId]->getCurrentTrackId(), position, true, undo, redo);
if (res) {
PUSH_UNDO(undo, redo, i18n("Move clip"));
}
return res;
}
int TimelineModel::suggestClipMove(int clipId, int trackId, int position)
{
......@@ -1053,7 +1042,6 @@ bool TimelineModel::requestReset(Fun &undo, Fun &redo)
for (int trackId : all_ids) {
ok = ok && requestTrackDeletion(trackId, undo, redo);
}
TimelineModel::next_id = 0;
return ok;
}
......
......@@ -178,6 +178,16 @@ public:
*/
Q_INVOKABLE int getClipPosition(int clipId) const;
/* @brief Returns the in cut position of a clip
@param clipId Id of the clip to test
*/
int getClipIn(int clipId) const;
/* @brief Returns the bin id of the clip master
@param clipId Id of the clip to test
*/
const QString getClipBinId(int clipId) const;
/* @brief Returns the duration of a clip
@param clipId Id of the clip to test
*/
......@@ -418,9 +428,14 @@ public:
*/
void setTimelineEffectsEnabled(bool enabled);
Q_INVOKABLE bool requestClipCut(int clipId, int position);
/* @brief Get a timeline clip id by its position
*/
int getClipByPosition(int trackId, int position) const;
/* @brief Creates a new clip instance without inserting it
*/
bool requestClipCreation(const QString &binClipId, int in, int duration, int &id, Fun &undo, Fun &redo);
protected:
/* @brief Register a new track. This is a call-back meant to be called from TrackModel
@param pos indicates the number of the track we are adding. If this is -1, then we add at the end.
......@@ -485,8 +500,6 @@ protected:
void checkRefresh(int start, int end) const;
bool requestClipCreation(const QString &binClipId, int in, int duration, int &id, Fun &undo, Fun &redo);
protected:
std::unique_ptr<Mlt::Tractor> m_tractor;
......
......@@ -22,6 +22,7 @@
#include "timelinecontroller.h"
#include "bin/bin.h"
#include "bin/model/markerlistmodel.hpp"
#include "../model/timelinefunctions.hpp"
#include "bin/projectclip.h"
#include "core.h"
#include "dialogs/markerdialog.h"
......@@ -443,7 +444,7 @@ void TimelineController::cutClipUnderCursor(int position, int track)
}
bool foundClip = false;
for (int cid : m_selection.selectedClips) {
if (m_model->requestClipCut(cid, position)) {
if (TimelineFunction::requestClipCut(m_model, cid, position)) {
foundClip = true;
}
}
......@@ -457,7 +458,7 @@ void TimelineController::cutClipUnderCursor(int position, int track)
if (track >= 0) {
int cid = m_model->getClipByPosition(track, position);
if (cid >= 0) {
m_model->requestClipCut(cid, position);
TimelineFunction::requestClipCut(m_model, cid, position);
foundClip = true;
}
}
......
Supports Markdown
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