Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Allow setting clip state (original/video only/audio only) at build time

parent df7afaae
......@@ -51,12 +51,12 @@ ClipModel::ClipModel(std::shared_ptr<TimelineModel> parent, std::shared_ptr<Mlt:
}
}
int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, int id)
int ClipModel::construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, int id, PlaylistState::ClipState state)
{
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(binClipId);
//std::shared_ptr<Mlt::Producer> originalProducer = binClip->originalProducer();
//std::shared_ptr<Mlt::Producer> cutProducer(originalProducer->cut());
std::shared_ptr<Mlt::Producer> cutProducer = binClip->timelineProducer();
std::shared_ptr<Mlt::Producer> cutProducer = binClip->timelineProducer(state);
return construct(parent, binClipId, cutProducer, id);
}
......
......@@ -57,7 +57,7 @@ public:
@param binClip is the id of the bin clip associated
@param id Requested id of the clip. Automatic if -1
*/
static int construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, int id = -1);
static int construct(const std::shared_ptr<TimelineModel> &parent, const QString &binClipId, int id = -1, PlaylistState::ClipState state = PlaylistState::Original);
/* @brief Creates a clip from an instance in MLT's playlist,
Returns the (unique) id of the created clip
@param parent is a pointer to the timeline
......
......@@ -31,9 +31,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QDebug>
#include <klocalizedstring.h>
bool TimelineFunctions::copyClip(std::shared_ptr<TimelineItemModel> timeline, int clipId, int &newId, Fun &undo, Fun &redo)
bool TimelineFunctions::copyClip(std::shared_ptr<TimelineItemModel> timeline, int clipId, int &newId, PlaylistState::ClipState state, Fun &undo, Fun &redo)
{
bool res = timeline->requestClipCreation(timeline->getClipBinId(clipId), newId, undo, redo);
bool res = timeline->requestClipCreation(timeline->getClipBinId(clipId), newId, state, undo, redo);
timeline->m_allClips[newId]->m_endlessResize = timeline->m_allClips[clipId]->m_endlessResize;
int duration = timeline->getClipPlaytime(clipId);
int init_duration = timeline->getClipPlaytime(newId);
......@@ -58,7 +58,8 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
if (start > position || (start + duration) < position) {
return false;
}
bool res = copyClip(timeline, clipId, newId, undo, redo);
PlaylistState::ClipState state = timeline->m_allClips[clipId]->clipState();
bool res = copyClip(timeline, clipId, newId, state, undo, redo);
res = res && timeline->requestItemResize(clipId, position - start, true, true, undo, redo);
int newDuration = timeline->getClipPlaytime(clipId);
res = res && timeline->requestItemResize(newId, duration - newDuration, false, true, undo, redo);
......@@ -263,7 +264,8 @@ bool TimelineFunctions::requestClipCopy(std::shared_ptr<TimelineItemModel> timel
std::unordered_map<int, int> mapping; //keys are ids of the source clips, values are ids of the copied clips
for (int id : allIds) {
int newId = -1;
bool res = copyClip(timeline, id, newId, undo, redo);
PlaylistState::ClipState state = timeline->m_allClips[id]->clipState();
bool res = copyClip(timeline, id, newId, state, undo, redo);
res = res && (newId != -1);
int target_position = timeline->getClipPosition(id) + deltaPos;
int target_track_position = timeline->getTrackPosition(timeline->getClipTrackId(id)) + deltaTrack;
......@@ -366,10 +368,10 @@ bool TimelineFunctions::requestSplitAudio(std::shared_ptr<TimelineItemModel> tim
int track = timeline->getClipTrackId(cid);
int newTrack = timeline->getNextTrackId(track);
int newId;
bool res = copyClip(timeline, cid, newId, undo, redo);
bool res = copyClip(timeline, cid, newId, PlaylistState::AudioOnly, undo, redo);
TimelineFunctions::changeClipState(timeline, clipId, PlaylistState::VideoOnly);
res = res && timeline->requestClipMove(newId, newTrack, position, true, false, undo, redo);
TimelineFunctions::changeClipState(timeline, newId, PlaylistState::AudioOnly);
//TimelineFunctions::changeClipState(timeline, newId, PlaylistState::AudioOnly);
std::unordered_set<int> clips;
clips.insert(clipId);
clips.insert(newId);
......
......@@ -47,7 +47,7 @@ struct TimelineFunctions {
static bool requestClipCut(std::shared_ptr<TimelineItemModel> timeline, int clipId, int position, int &newId, Fun &undo, Fun &redo);
/* @brief Makes a perfect copy of a given clip, but do not insert it */
static bool copyClip(std::shared_ptr<TimelineItemModel> timeline, int clipId, int &newId, Fun &undo, Fun &redo);
static bool copyClip(std::shared_ptr<TimelineItemModel> timeline, int clipId, int &newId, PlaylistState::ClipState state, Fun &undo, Fun &redo);
static int requestSpacerStartOperation(std::shared_ptr<TimelineItemModel> timeline, int trackId, int position);
static bool requestSpacerEndOperation(std::shared_ptr<TimelineItemModel> timeline, int clipId, int startPosition, int endPosition);
......
......@@ -29,7 +29,7 @@
#include "groupsmodel.hpp"
#include "snapmodel.hpp"
#include "trackmodel.hpp"
#include "kdenlivesettings.h"
#include "doc/docundostack.hpp"
#include <QDebug>
......@@ -466,7 +466,7 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
return result;
}
bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Fun &undo, Fun &redo)
bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo)
{
int clipId = TimelineModel::getNextId();
id = clipId;
......@@ -475,7 +475,7 @@ bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Fun &
if (binClipId.contains(QLatin1Char('#'))) {
bid = binClipId.section(QLatin1Char('#'), 0, 0);
}
ClipModel::construct(shared_from_this(), bid, clipId);
ClipModel::construct(shared_from_this(), bid, clipId, state);
auto clip = m_allClips[clipId];
Fun local_redo = [clip, this]() {
// We capture a shared_ptr to the clip, which means that as long as this undo object lives, the clip object is not deleted. To insert it back it is
......@@ -505,8 +505,14 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
{
std::function<bool(void)> local_undo = []() { return true; };
std::function<bool(void)> local_redo = []() { return true; };
bool res = requestClipCreation(binClipId, id, local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
bool res = false;
if (KdenliveSettings::splitaudio()) {
res = requestClipCreation(binClipId, id, PlaylistState::VideoOnly, local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
} else {
res = requestClipCreation(binClipId, id, PlaylistState::Original, local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
}
if (!res) {
bool undone = local_undo();
Q_ASSERT(undone);
......
......@@ -311,8 +311,9 @@ public:
This action is undoable, returns true on success
@param binClipId: Bin id of the clip to insert
@param id: return parameter for the id of the newly created clip.
@param state: The desired clip state (original, audio/video only).
*/
bool requestClipCreation(const QString &binClipId, int &id, Fun &undo, Fun &redo);
bool requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo);
/* @brief Deletes the given clip or composition from the timeline This
action is undoable Returns true on success. If it fails, nothing is
......
......@@ -785,7 +785,7 @@ TEST_CASE("Clip manipulation", "[ClipModel]")
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
REQUIRE(TimelineFunctions::copyClip(timeline, cid6, newId, undo, redo));
REQUIRE(TimelineFunctions::copyClip(timeline, cid6, newId, PlaylistState::Original, undo, redo));
REQUIRE(timeline->m_allClips[cid6]->binId() == timeline->m_allClips[newId]->binId());
// TODO check effects
}
......@@ -897,7 +897,7 @@ TEST_CASE("Undo and Redo", "[ClipModel]")
{
Fun undo = [](){return true;};
Fun redo = [](){return true;};
REQUIRE(timeline->requestClipCreation(binId3, cid3, undo, redo));
REQUIRE(timeline->requestClipCreation(binId3, cid3, PlaylistState::Original, undo, redo));
pCore->pushUndo(undo, redo, QString());
}
......@@ -914,7 +914,7 @@ TEST_CASE("Undo and Redo", "[ClipModel]")
{
Fun undo = [](){return true;};
Fun redo = [](){return true;};
REQUIRE(timeline->requestClipCreation(binId4, cid4, undo, redo));
REQUIRE(timeline->requestClipCreation(binId4, cid4,PlaylistState::Original, undo, redo));
pCore->pushUndo(undo, redo, QString());
}
......@@ -1326,7 +1326,7 @@ TEST_CASE("Undo and Redo", "[ClipModel]")
{
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
REQUIRE(timeline->requestClipCreation(binId, cid6,undo,redo));
REQUIRE(timeline->requestClipCreation(binId, cid6,PlaylistState::Original,undo,redo));
pCore->pushUndo(undo, redo, QString());
}
int l = timeline->getClipPlaytime(cid6);
......
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