From bef35e209da18fd3c5c8cfc4ccc325081e7b24be Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Wed, 15 Feb 2012 21:29:13 +0100 Subject: [PATCH] Trying to fix a bug with the clip move undo command. No success. --- src/CMakeLists.txt | 1 + src/commands/moveclipcommand.cpp | 29 +++++++++++++++++------------ src/commands/moveclipcommand.h | 4 +++- src/customtrackview.cpp | 20 ++++++++++++++++---- src/customtrackview.h | 8 +++++++- src/definitions.cpp | 12 ++++++++++++ src/definitions.h | 3 +++ src/gentime.cpp | 5 +++++ src/gentime.h | 3 +++ src/renderer.cpp | 1 + 10 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 src/definitions.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f69796e3..d26352fc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -133,6 +133,7 @@ list(APPEND kdenlive_SRCS customruler.cpp customtrackscene.cpp customtrackview.cpp + definitions.cpp docclipbase.cpp documentchecker.cpp documentvalidator.cpp diff --git a/src/commands/moveclipcommand.cpp b/src/commands/moveclipcommand.cpp index 659c09fa..b590b97d 100644 --- a/src/commands/moveclipcommand.cpp +++ b/src/commands/moveclipcommand.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * 2012 Simon A. Eugster * * * * 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 * @@ -24,11 +25,12 @@ #include MoveClipCommand::MoveClipCommand(CustomTrackView *view, const ItemInfo start, const ItemInfo end, bool doIt, QUndoCommand * parent) : - QUndoCommand(parent), - m_view(view), - m_startPos(start), - m_endPos(end), - m_doIt(doIt) + QUndoCommand(parent), + m_view(view), + m_startPos(start), + m_endPos(end), + m_doIt(doIt), + m_success(true) { setText(i18n("Move clip")); if (parent) { @@ -38,19 +40,22 @@ MoveClipCommand::MoveClipCommand(CustomTrackView *view, const ItemInfo start, co } -// virtual void MoveClipCommand::undo() { -// kDebug()<<"---- undoing action"; m_doIt = true; - m_view->moveClip(m_endPos, m_startPos, m_refresh); + // We can only undo what was done; + // if moveClip() failed in redo() the document does (or should) not change. + if (m_success) { + m_view->moveClip(m_endPos, m_startPos, m_refresh); + } } -// virtual void MoveClipCommand::redo() { - //kDebug() << "---- redoing action"; - if (m_doIt) - m_view->moveClip(m_startPos, m_endPos, m_refresh); + if (m_doIt) { + qDebug() << "Executing move clip command. End now:" << m_endPos; + m_success = m_view->moveClip(m_startPos, m_endPos, m_refresh, &m_endPos); + qDebug() << "Move clip command executed. End now: " << m_endPos; + } m_doIt = true; } diff --git a/src/commands/moveclipcommand.h b/src/commands/moveclipcommand.h index 5b7d99ff..3ab20cb2 100644 --- a/src/commands/moveclipcommand.h +++ b/src/commands/moveclipcommand.h @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * 2012 Simon A. Eugster * * * * 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 * @@ -37,9 +38,10 @@ public: private: CustomTrackView *m_view; const ItemInfo m_startPos; - const ItemInfo m_endPos; + ItemInfo m_endPos; bool m_doIt; bool m_refresh; + bool m_success; }; #endif diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 7f30a686..1a0a8ebb 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -4292,18 +4292,24 @@ Transition *CustomTrackView::getTransitionItemAtStart(GenTime pos, int track) return clip; } -void CustomTrackView::moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh) +bool CustomTrackView::moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh, ItemInfo *out_actualEnd) { if (m_selectionGroup) resetSelectionGroup(false); ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()), start.track); if (!item) { emit displayMessage(i18n("Cannot move clip at time: %1 on track %2", m_document->timecode().getTimecodeFromFrames(start.startPos.frames(m_document->fps())), start.track), ErrorMessage); kDebug() << "---------------- ERROR, CANNOT find clip to move at.. "; - return; + return false; } Mlt::Producer *prod = item->getProducer(end.track); - bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), prod); + qDebug() << "Moving item " << (long)item << " from .. to:"; + qDebug().maybeSpace() << item->info(); + qDebug() << start; + qDebug() << end; + bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), + (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), + prod); if (success) { bool snap = KdenliveSettings::snaptopoints(); KdenliveSettings::setSnaptopoints(false); @@ -4333,6 +4339,12 @@ void CustomTrackView::moveClip(const ItemInfo &start, const ItemInfo &end, bool emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(end.startPos.frames(m_document->fps()))), ErrorMessage); } if (refresh) m_document->renderer()->doRefresh(); + if (out_actualEnd != NULL) { + *out_actualEnd = item->info(); + qDebug() << "Actual end position updated:" << *out_actualEnd; + } + qDebug() << item->info(); + return success; } void CustomTrackView::moveGroup(QList startClip, QList startTransition, const GenTime &offset, const int trackOffset, bool reverseMove) @@ -6029,7 +6041,7 @@ void CustomTrackView::alignAudio() QUndoCommand *moveCommand = new QUndoCommand(); moveCommand->setText(i18n("Auto-align clip")); new MoveClipCommand(this, start, end, true, moveCommand); - moveClip(start, end, true); +// moveClip(start, end, true); updateTrackDuration(clip->track(), moveCommand); m_commandStack->push(moveCommand); diff --git a/src/customtrackview.h b/src/customtrackview.h index 5d932b5d..66ee744b 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -61,7 +61,13 @@ public: void configTracks(QList trackInfos); int cursorPos(); void checkAutoScroll(); - void moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh); + /** + Move the clip at \c start to \c end. + + If \c out_actualEnd is not NULL, it will be set to the position the clip really ended up at. + For example, attempting to move a clip to t = -1 s will actually move it to t = 0 s. + */ + bool moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh, ItemInfo *out_actualEnd = NULL); void moveGroup(QList startClip, QList startTransition, const GenTime &offset, const int trackOffset, bool reverseMove = false); /** move transition, startPos = (old start, old end), endPos = (new start, new end) */ void moveTransition(const ItemInfo &start, const ItemInfo &end, bool refresh); diff --git a/src/definitions.cpp b/src/definitions.cpp new file mode 100644 index 00000000..2112faf9 --- /dev/null +++ b/src/definitions.cpp @@ -0,0 +1,12 @@ +#include "definitions.h" + +QDebug operator << (QDebug qd, const ItemInfo &info) +{ + qd << "ItemInfo " << &info; + qd << "\tTrack" << info.track; + qd << "\tStart pos: " << info.startPos.toString(); + qd << "\tEnd pos: " << info.endPos.toString(); + qd << "\tCrop start: " << info.cropStart.toString(); + qd << "\tCrop duration: " << info.cropDuration.toString(); + return qd.maybeSpace(); +} diff --git a/src/definitions.h b/src/definitions.h index 9c69a485..a9c55c85 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -26,6 +26,7 @@ #include #include +#include const int MAXCLIPDURATION = 15000; @@ -215,5 +216,7 @@ private: }; +QDebug operator << (QDebug qd, const ItemInfo &info); + #endif diff --git a/src/gentime.cpp b/src/gentime.cpp index 21eb7b70..82e0d9c7 100644 --- a/src/gentime.cpp +++ b/src/gentime.cpp @@ -54,3 +54,8 @@ GenTime& GenTime::roundNearestFrame(double framesPerSecond) m_time = floor((m_time * framesPerSecond) + 0.5) / framesPerSecond; return *this; } + +QString GenTime::toString() const +{ + return QString("%1 s").arg(m_time, 0, 'f', 2); +} diff --git a/src/gentime.h b/src/gentime.h index 34f7bc59..e927eabb 100644 --- a/src/gentime.h +++ b/src/gentime.h @@ -18,6 +18,7 @@ #ifndef GENTIME_H #define GENTIME_H +#include #include /** @@ -52,6 +53,8 @@ public: * @param framesPerSecond Number of frames per second */ GenTime & roundNearestFrame(double framesPerSecond); + QString toString() const; + /* * Operators. diff --git a/src/renderer.cpp b/src/renderer.cpp index 3dd02443..9bb3c8a8 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -3344,6 +3344,7 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service()); if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) { // error, destination is not empty + kDebug() << "Cannot move: Destination is not empty"; service.unlock(); return false; } else { -- 2.39.2