From f718b68bc9b5d25fd864b0281d9406cdc92e88ca Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Fri, 27 Jun 2008 17:18:40 +0000 Subject: [PATCH] add / edit effect keyframe is now integrated in the undo framework svn path=/branches/KDE4/; revision=2280 --- src/CMakeLists.txt | 1 + src/clipitem.cpp | 46 +++++++++++++++++++++++++++++++++- src/clipitem.h | 4 ++- src/customtrackview.cpp | 26 +++++++++++++++++++- src/customtrackview.h | 1 + src/editeffectcommand.h | 4 +-- src/editkeyframecommand.cpp | 44 +++++++++++++++++++++++++++++++++ src/editkeyframecommand.h | 49 +++++++++++++++++++++++++++++++++++++ src/edittransitioncommand.h | 4 +-- src/moveclipcommand.h | 4 +-- 10 files changed, 174 insertions(+), 9 deletions(-) create mode 100644 src/editkeyframecommand.cpp create mode 100644 src/editkeyframecommand.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 468cc8ad..70a13dcd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -116,6 +116,7 @@ set(kdenlive_SRCS editguidecommand.cpp statusbarmessagelabel.cpp regiongrabber.cpp + editkeyframecommand.cpp ) kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc ) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 16a173e6..58590298 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -122,8 +122,37 @@ void ClipItem::initEffect(QDomElement effect) { } } +void ClipItem::setKeyframes(const int ix, const QString keyframes) { + QDomElement effect = effectAt(ix); + QDomNodeList params = effect.elementsByTagName("parameter"); + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + if (!e.isNull() && e.attribute("type") == "keyframe") { + e.setAttribute("keyframes", keyframes); + if (ix == m_selectedEffect) { + m_keyframes.clear(); + double max = e.attribute("max").toDouble(); + double min = e.attribute("min").toDouble(); + m_keyframeFactor = 100.0 / (max - min); + m_keyframeDefault = e.attribute("default").toDouble(); + // parse keyframes + QStringList keyframes = e.attribute("keyframes").split(";", QString::SkipEmptyParts); + foreach(QString str, keyframes) { + int pos = str.section(":", 0, 0).toInt(); + double val = str.section(":", 1, 1).toDouble(); + m_keyframes[pos] = val; + } + update(); + return; + } + break; + } + } + +} + -void ClipItem::setSelectedEffect(int ix) { +void ClipItem::setSelectedEffect(const int ix) { m_selectedEffect = ix; QDomElement effect = effectAt(m_selectedEffect); @@ -153,6 +182,21 @@ void ClipItem::setSelectedEffect(int ix) { } } +QString ClipItem::keyframes(const int index) { + QString result; + QDomElement effect = effectAt(index); + QDomNodeList params = effect.elementsByTagName("parameter"); + + for (int i = 0; i < params.count(); i++) { + QDomElement e = params.item(i).toElement(); + if (!e.isNull() && e.attribute("type") == "keyframe") { + result = e.attribute("keyframes"); + break; + } + } + return result; +} + void ClipItem::updateKeyframeEffect() { // regenerate xml parameter from the clip keyframes QDomElement effect = effectAt(m_selectedEffect); diff --git a/src/clipitem.h b/src/clipitem.h index e091916a..190c669b 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -81,11 +81,13 @@ public: QList snapMarkers() const; uint fadeIn() const; uint fadeOut() const; - void setSelectedEffect(int ix); + void setSelectedEffect(const int ix); void updateKeyframeEffect(); QDomElement selectedEffect(); int selectedEffectIndex() const; void initEffect(QDomElement effect); + QString keyframes(const int index); + void setKeyframes(const int ix, const QString keyframes); protected: //virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 8866ce5b..96f90487 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -45,6 +45,7 @@ #include "moveeffectcommand.h" #include "addtransitioncommand.h" #include "edittransitioncommand.h" +#include "editkeyframecommand.h" #include "addmarkercommand.h" #include "razorclipcommand.h" #include "kdenlivesettings.h" @@ -569,7 +570,11 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) { int pos = m_document->timecode().getFrameCount(view.kfr_position->text(), m_document->fps()); m_dragItem->updateKeyFramePos(GenTime(pos, m_document->fps()) + m_dragItem->cropStart(), (double) view.kfr_value->value() * m_dragItem->keyFrameFactor()); ClipItem *item = (ClipItem *)m_dragItem; - item->updateKeyframeEffect(); + QString previous = item->keyframes(item->selectedEffectIndex()); + item->updateKeyframeEffect(); + QString next = item->keyframes(item->selectedEffectIndex()); + EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false); + m_commandStack->push(command); updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect()); } @@ -578,12 +583,27 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) { GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart(); m_dragItem->addKeyFrame(keyFramePos, mapToScene(event->pos()).toPoint().y()); ClipItem * item = (ClipItem *) m_dragItem; + QString previous = item->keyframes(item->selectedEffectIndex()); item->updateKeyframeEffect(); + QString next = item->keyframes(item->selectedEffectIndex()); + EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false); + m_commandStack->push(command); updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect()); } } } + +void CustomTrackView::editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes) { + ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track); + if (clip) { + clip->setKeyframes(index, keyframes); + updateEffect(m_tracksList.count() - clip->track(), clip->startPos(), clip->effectAt(index)); + } + else emit displayMessage(i18n("Cannot find clip with keyframe"), ErrorMessage); +} + + void CustomTrackView::displayContextMenu(QPoint pos, AbstractClipItem *clip) { if (clip == NULL) m_timelineContextMenu->popup(pos); else if (clip->type() == AVWIDGET) m_timelineContextClipMenu->popup(pos); @@ -1064,7 +1084,11 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) { } else if (m_operationMode == KEYFRAME) { // update the MLT effect ClipItem * item = (ClipItem *) m_dragItem; + QString previous = item->keyframes(item->selectedEffectIndex()); item->updateKeyframeEffect(); + QString next = item->keyframes(item->selectedEffectIndex()); + EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false); + m_commandStack->push(command); updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect()); } diff --git a/src/customtrackview.h b/src/customtrackview.h index 76352ac6..f0869f1f 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -84,6 +84,7 @@ public: void slotSeekToNextSnap(); double getSnapPointForPos(double pos); QDomElement xmlInfo(); + void editKeyFrame(const GenTime pos, const int track, const int index, const QString keyframes); public slots: void setCursorPos(int pos, bool seek = true); diff --git a/src/editeffectcommand.h b/src/editeffectcommand.h index 36986834..c06fe931 100644 --- a/src/editeffectcommand.h +++ b/src/editeffectcommand.h @@ -39,10 +39,10 @@ public: private: CustomTrackView *m_view; - int m_track; + const int m_track; QDomElement m_effect; QDomElement m_oldeffect; - GenTime m_pos; + const GenTime m_pos; bool m_doIt; }; diff --git a/src/editkeyframecommand.cpp b/src/editkeyframecommand.cpp new file mode 100644 index 00000000..edc89816 --- /dev/null +++ b/src/editkeyframecommand.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + editkeyframecommand.cpp - description + ------------------- + begin : 2008 + copyright : (C) 2008 by Jean-Baptiste Mardelle + email : jb@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) any later version. * + * * + ***************************************************************************/ +#include + +#include "editkeyframecommand.h" +#include "customtrackview.h" + +EditKeyFrameCommand::EditKeyFrameCommand(CustomTrackView *view, const int track, GenTime pos, const int effectIndex, const QString& oldkeyframes, const QString& newkeyframes, bool doIt) : m_view(view), m_track(track), m_pos(pos), m_index(effectIndex), m_oldkfr(oldkeyframes), m_newkfr(newkeyframes), m_doIt(doIt) { + int prev = m_oldkfr.split(";", QString::SkipEmptyParts).count(); + int next = m_newkfr.split(";", QString::SkipEmptyParts).count(); + if (prev == next) setText(i18n("Edit keyframe")); + else if (prev > next) setText(i18n("Delete keyframe")); + else setText(i18n("Add keyframe")); + //kDebug() << "/// CREATE GUIDE COMMAND, TIMES: " << m_oldPos.frames(25) << "x" << m_pos.frames(25); +} + + +// virtual +void EditKeyFrameCommand::undo() { + m_view->editKeyFrame(m_pos, m_track, m_index, m_oldkfr); +} +// virtual +void EditKeyFrameCommand::redo() { + if (m_doIt) { + m_view->editKeyFrame(m_pos, m_track, m_index, m_newkfr); + } + m_doIt = true; +} + +#include "editkeyframecommand.moc" diff --git a/src/editkeyframecommand.h b/src/editkeyframecommand.h new file mode 100644 index 00000000..9c591e02 --- /dev/null +++ b/src/editkeyframecommand.h @@ -0,0 +1,49 @@ +/*************************************************************************** + editkeyframecommand.h - description + ------------------- + begin : 2008 + copyright : (C) 2008 by Jean-Baptiste Mardelle + email : jb@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) any later version. * + * * + ***************************************************************************/ + +#ifndef KEYFRAMECOMMAND_H +#define KEYFRAMECOMMAND_H + +#include +#include +#include +#include +#include + +#include "gentime.h" +#include "definitions.h" +class CustomTrackView; + + +class EditKeyFrameCommand : public QUndoCommand { +public: + EditKeyFrameCommand(CustomTrackView *view, const int track, GenTime pos, const int effectIndex, const QString& oldkeyframes, const QString& newkeyframes, bool doIt); + virtual void undo(); + virtual void redo(); + +private: + CustomTrackView *m_view; + const QString m_oldkfr; + const QString m_newkfr; + const int m_track; + const int m_index; + const GenTime m_pos; + bool m_doIt; +}; + +#endif + diff --git a/src/edittransitioncommand.h b/src/edittransitioncommand.h index 0a6c16d8..9a12d5b1 100644 --- a/src/edittransitioncommand.h +++ b/src/edittransitioncommand.h @@ -36,10 +36,10 @@ public: private: CustomTrackView *m_view; - int m_track; + const int m_track; QDomElement m_effect; QDomElement m_oldeffect; - GenTime m_pos; + const GenTime m_pos; bool m_doIt; }; diff --git a/src/moveclipcommand.h b/src/moveclipcommand.h index 54a4a721..7cf002ec 100644 --- a/src/moveclipcommand.h +++ b/src/moveclipcommand.h @@ -38,8 +38,8 @@ public: private: CustomTrackView *m_view; - ItemInfo m_startPos; - ItemInfo m_endPos; + const ItemInfo m_startPos; + const ItemInfo m_endPos; bool m_doIt; }; -- 2.39.2