]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Added "find next" feature
[kdenlive] / src / customtrackview.cpp
index 805be75ce43c406179782b696b107862d1f11abf..04eaba36cafbe9ce9e1d706b60f7305dfdb2b424 100644 (file)
@@ -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"
@@ -55,6 +56,8 @@
 #include "renderer.h"
 #include "markerdialog.h"
 #include "mainwindow.h"
+#include "ui_keyframedialog_ui.h"
+#include "clipdurationdialog.h"
 
 
 //TODO:
@@ -66,7 +69,7 @@
 // const int duration = animate ? 1500 : 1;
 
 CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
-        : QGraphicsView(projectscene, parent), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL) {
+        : QGraphicsView(projectscene, parent), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL), m_findIndex(0) {
     if (doc) m_commandStack = doc->commandStack();
     else m_commandStack == NULL;
     setMouseTracking(true);
@@ -176,10 +179,10 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
             if (m_operationMode == MOVE && (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance()) {
                 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint.x());
                 //kDebug() << "///////  MOVE CLIP, EVENT Y: "<<m_clickPoint.y();//<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
-                int moveTrack = (int)  mapToScene(event->pos() + QPoint(0, (m_dragItem->type() == TRANSITIONWIDGET ? - m_clickPoint.y() : 0))).y() / m_tracksHeight;
+                int moveTrack = (int)  mapToScene(event->pos() - QPoint(0, (m_dragItem->type() == TRANSITIONWIDGET ? m_dragItem->boundingRect().height() / 2 : 0))).y() / m_tracksHeight;
                 int currentTrack = m_dragItem->track();
 
-                if (moveTrack > 1000)moveTrack = 0;
+                if (moveTrack > 1000) moveTrack = 0;
                 else if (moveTrack > m_tracksList.count() - 1) moveTrack = m_tracksList.count() - 1;
                 else if (moveTrack < 0) moveTrack = 0;
 
@@ -200,7 +203,11 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
                 ((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - pos), m_scale);
             } else if (m_operationMode == KEYFRAME) {
                 GenTime keyFramePos = GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()) - m_dragItem->startPos() + m_dragItem->cropStart();
-                m_dragItem->updateKeyFramePos(keyFramePos, mapToScene(event->pos()).toPoint().y());
+                double pos = mapToScene(event->pos()).toPoint().y();
+                QRectF br = m_dragItem->rect();
+                double maxh = 100.0 / br.height();
+                pos = (br.bottom() - pos) * maxh;
+                m_dragItem->updateKeyFramePos(keyFramePos, pos);
             }
 
             if (m_animation) delete m_animation;
@@ -221,8 +228,8 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
 
     if (m_tool == RAZORTOOL) {
         setCursor(m_razorCursor);
-        QGraphicsView::mouseMoveEvent(event);
-        return;
+        //QGraphicsView::mouseMoveEvent(event);
+        //return;
     }
 
     QList<QGraphicsItem *> itemList = items(event->pos());
@@ -240,6 +247,14 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
 
     if (item && event->buttons() == Qt::NoButton) {
         AbstractClipItem *clip = (AbstractClipItem*) item;
+        if (m_tool == RAZORTOOL) {
+            // razor tool over a clip, display current frame in monitor
+            if (item->type() == AVWIDGET) {
+                emit showClipFrame(((ClipItem *) item)->baseClip(), mapToScene(event->pos()).x() / m_scale - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
+            }
+            QGraphicsView::mouseMoveEvent(event);
+            return;
+        }
         opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
         double size = 8;
         if (opMode == m_moveOpMode) {
@@ -392,7 +407,10 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
             setCursor(Qt::PointingHandCursor);
         }
     } // no clip under mouse
-    else if (opMode == MOVEGUIDE) {
+    else if (m_tool == RAZORTOOL) {
+        QGraphicsView::mouseMoveEvent(event);
+        return;
+    } else if (opMode == MOVEGUIDE) {
         m_moveOpMode = opMode;
         setCursor(Qt::SplitHCursor);
     } else {
@@ -449,7 +467,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
                 QGraphicsItem *item = collisionList.at(i);
                 if (item->type() == AVWIDGET || item->type() == TRANSITIONWIDGET) {
                     if (m_tool == RAZORTOOL) {
-                        if (item->type() == TRANSITIONWIDGET) return;
+                        if (item->type() == TRANSITIONWIDGET) {
+                            emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage);
+                            return;
+                        }
                         AbstractClipItem *clip = (AbstractClipItem *) item;
                         ItemInfo info;
                         info.startPos = clip->startPos();
@@ -537,14 +558,87 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
 
 void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
     if (m_dragItem && m_dragItem->hasKeyFrames()) {
-        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;
-        item->updateKeyframeEffect();
-        updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect());
+        if (m_moveOpMode == KEYFRAME) {
+            // user double clicked on a keyframe, open edit dialog
+            QDialog d(parentWidget());
+            Ui::KeyFrameDialog_UI view;
+            view.setupUi(&d);
+            view.kfr_position->setText(m_document->timecode().getTimecode(GenTime(m_dragItem->selectedKeyFramePos(), m_document->fps()) - m_dragItem->cropStart(), m_document->fps()));
+            view.kfr_value->setValue(m_dragItem->selectedKeyFrameValue());
+            view.kfr_value->setFocus();
+            if (d.exec() == QDialog::Accepted) {
+                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;
+                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(), item->selectedEffectIndex());
+            }
+
+        } else  {
+            // add keyframe
+            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(), item->selectedEffectIndex());
+        }
+    } else {
+        ClipDurationDialog d(m_dragItem, m_document->timecode(), this);
+        if (d.exec() == QDialog::Accepted) {
+            if (d.startPos() != m_dragItem->startPos()) {
+                if (m_dragItem->type() == AVWIDGET) {
+                    ItemInfo startInfo;
+                    startInfo.startPos = m_dragItem->startPos();
+                    startInfo.endPos = m_dragItem->endPos();
+                    startInfo.track = m_dragItem->track();
+                    ItemInfo endInfo;
+                    endInfo.startPos = d.startPos();
+                    endInfo.endPos = m_dragItem->endPos() + (endInfo.startPos - startInfo.startPos);
+                    endInfo.track = m_dragItem->track();
+                    MoveClipCommand *command = new MoveClipCommand(this, startInfo, endInfo, true);
+                    m_commandStack->push(command);
+                } else {
+                    //TODO: move transition
+                }
+            }
+            if (d.duration() != m_dragItem->duration()) {
+                if (m_dragItem->type() == AVWIDGET) {
+                    ItemInfo startInfo;
+                    startInfo.startPos = m_dragItem->startPos();
+                    startInfo.endPos = m_dragItem->endPos();
+                    startInfo.track = m_dragItem->track();
+                    ItemInfo endInfo;
+                    endInfo.startPos = startInfo.startPos;
+                    endInfo.endPos = endInfo.startPos + d.duration();
+                    endInfo.track = m_dragItem->track();
+                    ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
+                    m_commandStack->push(command);
+                } else {
+                    //TODO: resize transition
+                }
+            }
+        }
     }
 }
 
+
+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), 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);
@@ -572,10 +666,15 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
 void CustomTrackView::slotRefreshEffects(ClipItem *clip) {
     int track = m_tracksList.count() - clip->track();
     GenTime pos = clip->startPos();
-    m_document->renderer()->mltRemoveEffect(track, pos, "-1", false);
+    if (!m_document->renderer()->mltRemoveEffect(track, pos, "-1", false)) {
+        emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
+        return;
+    }
+    bool success = true;
     for (int i = 0; i < clip->effectsCount(); i++) {
-        m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false);
+        if (!m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false)) success = false;
     }
+    if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
     m_document->renderer()->doRefresh();
 }
 
@@ -583,14 +682,18 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) {
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
     if (clip) {
         QMap <QString, QString> effectParams = clip->addEffect(effect);
-        m_document->renderer()->mltAddEffect(track, pos, effectParams);
+        if (!m_document->renderer()->mltAddEffect(track, pos, effectParams))
+            emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
         emit clipItemSelected(clip);
-    }
+    } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage);
 }
 
 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) {
     QString index = effect.attribute("kdenlive_ix");
-    m_document->renderer()->mltRemoveEffect(track, pos, index);
+    if (!m_document->renderer()->mltRemoveEffect(track, pos, index)) {
+        emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
+        return;
+    }
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
     if (clip) {
         clip->deleteEffect(index);
@@ -624,14 +727,19 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) {
     m_document->setModified(true);
 }
 
-void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect) {
+void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, int ix) {
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
     if (clip) {
         QMap <QString, QString> effectParams = clip->getEffectArgs(effect);
         if (effectParams.value("disabled") == "1") {
-            QString index = effectParams.value("kdenlive_ix");
-            m_document->renderer()->mltRemoveEffect(track, pos, index);
-        } else m_document->renderer()->mltEditEffect(m_tracksList.count() - clip->track(), clip->startPos(), effectParams);
+            if (m_document->renderer()->mltRemoveEffect(track, pos, effectParams.value("kdenlive_ix"))) {
+                kDebug() << "//////  DISABLING EFFECT: " << index << ", CURRENTLA: " << clip->selectedEffectIndex();
+            } else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
+        } else if (!m_document->renderer()->mltEditEffect(m_tracksList.count() - clip->track(), clip->startPos(), effectParams))
+            emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+        if (ix == clip->selectedEffectIndex()) {
+            clip->setSelectedEffect(clip->selectedEffectIndex());
+        }
     }
     m_document->setModified(true);
 }
@@ -644,10 +752,11 @@ void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
     m_document->setModified(true);
 }
 
-void CustomTrackView::slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable) {
+void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable) {
+    QDomElement effect = clip->effectAt(effectPos);
     QDomElement oldEffect = effect.cloneNode().toElement();
     effect.setAttribute("disabled", disable);
-    EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldEffect, effect, true);
+    EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
     m_commandStack->push(command);
     m_document->setModified(true);
 }
@@ -658,8 +767,8 @@ void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, i
     m_document->setModified(true);
 }
 
-void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect) {
-    EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldeffect, effect, true);
+void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix) {
+    EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
     m_commandStack->push(command);
 }
 
@@ -667,21 +776,32 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut) {
     if (cut) {
         // cut clip
         ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
+        if (!item) {
+            emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage);
+            return;
+        }
         int cutPos = (int) cutTime.frames(m_document->fps());
         ItemInfo newPos;
         newPos.startPos = cutTime;
         newPos.endPos = info.endPos;
         newPos.track = info.track;
-        ClipItem *dup = new ClipItem(item->baseClip(), newPos, item->cropStart(), m_scale, m_document->fps());
-        dup->setCropStart(dup->cropStart() + (cutTime - info.startPos));
         item->resizeEnd(cutPos, m_scale);
+        ClipItem *dup = new ClipItem(item->baseClip(), newPos, item->cropStart() + (cutTime - info.startPos), m_scale, m_document->fps());
         scene()->addItem(dup);
         m_document->renderer()->mltCutClip(m_tracksList.count() - info.track, cutTime);
+        item->baseClip()->addReference();
+        m_document->updateClip(item->baseClip()->getId());
     } else {
         // uncut clip
         ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
         ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()), info.track);
+        if (!item || !dup) {
+            emit displayMessage(i18n("Cannot find clip to uncut"), ErrorMessage);
+            return;
+        }
         delete dup;
+        item->baseClip()->removeReference();
+        m_document->updateClip(item->baseClip()->getId());
         item->resizeEnd((int) info.endPos.frames(m_document->fps()), m_scale);
         m_document->renderer()->mltRemoveClip(m_tracksList.count() - info.track, cutTime);
         m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - info.track, info.startPos, item->cropStart(), item->cropStart() + info.endPos - info.startPos);
@@ -887,11 +1007,15 @@ void CustomTrackView::moveCursorPos(int delta) {
 }
 
 void CustomTrackView::checkScrolling() {
-    QRect rectInView = viewport()->rect();
+    int vert = verticalScrollBar()->value();
+    int hor = cursorPos();
+    ensureVisible(hor, vert + 10, 2, 2, 50, 0);
+    //centerOn(QPointF(cursorPos(), m_tracksHeight));
+    /*QRect rectInView = viewport()->rect();
     int delta = rectInView.width() / 3;
     int max = rectInView.right() + horizontalScrollBar()->value() - delta;
     //kDebug() << "CURSOR POS: "<<m_cursorPos<< "Scale: "<<m_scale;
-    if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue((int)(horizontalScrollBar()->value() + 1 + m_scale));
+    if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue((int)(horizontalScrollBar()->value() + 1 + m_scale));*/
 }
 
 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
@@ -924,9 +1048,16 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
         setCursor(Qt::OpenHandCursor);
         // move clip
         if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
-            MoveClipCommand *command = new MoveClipCommand(this, m_dragItemInfo, info, false);
-            m_commandStack->push(command);
-            m_document->renderer()->mltMoveClip((int)(m_tracksList.count() - m_dragItemInfo.track), (int)(m_tracksList.count() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())));
+            bool success = m_document->renderer()->mltMoveClip((int)(m_tracksList.count() - m_dragItemInfo.track), (int)(m_tracksList.count() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())));
+            if (success) {
+                MoveClipCommand *command = new MoveClipCommand(this, m_dragItemInfo, info, false);
+                m_commandStack->push(command);
+            } else {
+                // undo last move and emit error message
+                MoveClipCommand *command = new MoveClipCommand(this, info, m_dragItemInfo, true);
+                m_commandStack->push(command);
+                emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(m_dragItemInfo.startPos.seconds(), 'g', 2)), ErrorMessage);
+            }
         }
         if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
             MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
@@ -969,7 +1100,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
         ClipItem * item = (ClipItem *) m_dragItem;
         QStringList clipeffects = item->effectNames();
         if (clipeffects.contains(i18n("Fade in"))) {
-            QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade in"));
+            int ix = clipeffects.indexOf(i18n("Fade in"));
+            QDomElement oldeffect = item->effectAt(ix);
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
@@ -979,7 +1111,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
                 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
                 EffectsList::setParameter(effect, "in", QString::number(start));
                 EffectsList::setParameter(effect, "out", QString::number(end));
-                slotUpdateClipEffect(item, oldeffect, effect);
+                slotUpdateClipEffect(item, oldeffect, effect, ix);
             }
         } else if (item->fadeIn() != 0) {
             QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade in");
@@ -994,7 +1126,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
         ClipItem * item = (ClipItem *) m_dragItem;
         QStringList clipeffects = item->effectNames();
         if (clipeffects.contains(i18n("Fade out"))) {
-            QDomElement oldeffect = item->effectAt(clipeffects.indexOf("Fade out"));
+            int ix = clipeffects.indexOf(i18n("Fade out"));
+            QDomElement oldeffect = item->effectAt(ix);
             int end = (item->duration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
@@ -1004,7 +1137,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
                 QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
                 EffectsList::setParameter(effect, "in", QString::number(start));
                 EffectsList::setParameter(effect, "out", QString::number(end));
-                slotUpdateClipEffect(item, oldeffect, effect);
+                slotUpdateClipEffect(item, oldeffect, effect, ix);
             }
         } else if (item->fadeOut() != 0) {
             QDomElement effect = MainWindow::audioEffects.getEffectByName("Fade out");
@@ -1017,8 +1150,12 @@ 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();
-        updateEffect(m_tracksList.count() - item->track(), item->startPos(), item->selectedEffect());
+        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(), item->selectedEffectIndex());
     }
 
     emit transitionItemSelected((m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) ? (Transition*) m_dragItem : NULL);
@@ -1143,13 +1280,19 @@ Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track) {
 void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
     ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()) + 1, start.track);
     if (!item) {
-        emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
+        emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", QString::number(start.startPos.seconds(), 'g', 2), start.track), ErrorMessage);
         kDebug() << "----------------  ERROR, CANNOT find clip to move at.. ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
         return;
     }
     //kDebug() << "----------------  Move CLIP FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << startPos.y() << " TO " << endPos.y();
-    item->moveTo((int) end.startPos.frames(m_document->fps()), m_scale, (int)((end.track - start.track) * m_tracksHeight), end.track);
-    m_document->renderer()->mltMoveClip((int)(m_tracksList.count() - start.track), (int)(m_tracksList.count() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()));
+
+    bool success = m_document->renderer()->mltMoveClip((int)(m_tracksList.count() - start.track), (int)(m_tracksList.count() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()));
+    if (success) {
+        item->moveTo((int) end.startPos.frames(m_document->fps()), m_scale, (int)((end.track - start.track) * m_tracksHeight), end.track);
+    } else {
+        // undo last move and emit error message
+        emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(end.startPos.seconds(), 'g', 2)), ErrorMessage);
+    }
 }
 
 void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end) {
@@ -1178,11 +1321,11 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end) {
 }
 
 void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end) {
-    int offset;
+    int offset = 0;
     bool resizeClipStart = true;
     if (start.startPos == end.startPos) resizeClipStart = false;
-    if (resizeClipStart) offset = 1;
-    else offset = -1;
+    /*if (resizeClipStart) offset = 1;
+    else offset = -1;*/
     ClipItem *item = getClipItemAt((int)(start.startPos.frames(m_document->fps()) + offset), start.track);
     if (!item) {
         emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", start.startPos.seconds(), start.track), ErrorMessage);
@@ -1194,8 +1337,8 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end) {
         item->resizeStart((int) end.startPos.frames(m_document->fps()), m_scale);
         updateClipFade(item);
     } else {
-        m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - item->track(), item->startPos(), item->cropStart(), item->cropStart() + end.startPos - item->startPos());
-        item->resizeEnd((int) end.startPos.frames(m_document->fps()), m_scale);
+        m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - item->track(), item->startPos(), item->cropStart(), item->cropStart() + end.endPos - item->startPos());
+        item->resizeEnd((int) end.endPos.frames(m_document->fps()), m_scale);
         updateClipFade(item, true);
     }
     m_document->renderer()->doRefresh();
@@ -1213,7 +1356,8 @@ void CustomTrackView::updateClipFade(ClipItem * item, bool updateFadeOut) {
             EffectsList::setParameter(oldeffect, "in", QString::number(start));
             EffectsList::setParameter(oldeffect, "out", QString::number(end));
             QMap <QString, QString> effectParams = item->getEffectArgs(oldeffect);
-            m_document->renderer()->mltEditEffect(m_tracksList.count() - item->track(), item->startPos(), effectParams);
+            if (!m_document->renderer()->mltEditEffect(m_tracksList.count() - item->track(), item->startPos(), effectParams))
+                emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
         }
     } else {
         int start = item->fadeOut();
@@ -1226,7 +1370,8 @@ void CustomTrackView::updateClipFade(ClipItem * item, bool updateFadeOut) {
             EffectsList::setParameter(oldeffect, "in", QString::number(start));
             EffectsList::setParameter(oldeffect, "out", QString::number(end));
             QMap <QString, QString> effectParams = item->getEffectArgs(oldeffect);
-            m_document->renderer()->mltEditEffect(m_tracksList.count() - item->track(), item->startPos(), effectParams);
+            if (m_document->renderer()->mltEditEffect(m_tracksList.count() - item->track(), item->startPos(), effectParams))
+                emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
         }
     }
 }
@@ -1244,6 +1389,7 @@ double CustomTrackView::getSnapPointForPos(double pos) {
 
 void CustomTrackView::updateSnapPoints(AbstractClipItem *selected) {
     m_snapPoints.clear();
+    if (!KdenliveSettings::snaptopoints()) return;
     GenTime offset;
     if (selected) offset = selected->duration();
     QList<QGraphicsItem *> itemList = items();
@@ -1355,14 +1501,23 @@ void CustomTrackView::slotDeleteClipMarker() {
         return;
     }
     AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
-    if (item->type() != AVWIDGET) return;
+    if (item->type() != AVWIDGET) {
+        emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
+        return;
+    }
     GenTime pos = GenTime(m_cursorPos, m_document->fps());
-    if (item->startPos() > pos || item->endPos() < pos) return;
+    if (item->startPos() > pos || item->endPos() < pos) {
+        emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
+        return;
+    }
     ClipItem *clip = (ClipItem *) item;
     int id = clip->baseClip()->getId();
     GenTime position = pos - item->startPos() + item->cropStart();
     QString comment = clip->baseClip()->markerComment(position);
-    if (comment.isEmpty()) return;
+    if (comment.isEmpty()) {
+        emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
+        return;
+    }
     AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position, true);
     m_commandStack->push(command);
 }
@@ -1375,14 +1530,23 @@ void CustomTrackView::slotEditClipMarker() {
         return;
     }
     AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
-    if (item->type() != AVWIDGET) return;
+    if (item->type() != AVWIDGET) {
+        emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
+        return;
+    }
     GenTime pos = GenTime(m_cursorPos, m_document->fps());
-    if (item->startPos() > pos || item->endPos() < pos) return;
+    if (item->startPos() > pos || item->endPos() < pos) {
+        emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
+        return;
+    }
     ClipItem *clip = (ClipItem *) item;
     int id = clip->baseClip()->getId();
     GenTime position = pos - item->startPos() + item->cropStart();
     QString oldcomment = clip->baseClip()->markerComment(position);
-    if (oldcomment.isEmpty()) return;
+    if (oldcomment.isEmpty()) {
+        emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
+        return;
+    }
 
     CommentedTime marker(position, oldcomment);
     MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
@@ -1412,7 +1576,7 @@ void CustomTrackView::addMarker(const int id, const GenTime &pos, const QString
 
 
 void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment) {
-    if (oldPos != GenTime() && pos != GenTime()) {
+    if (oldPos > GenTime() && pos > GenTime()) {
         // move guide
         for (int i = 0; i < m_guides.count(); i++) {
             kDebug() << "// LOOKING FOR GUIDE (" << i << "): " << m_guides.at(i)->position().frames(25) << ", LOOK: " << oldPos.frames(25) << "x" << pos.frames(25);
@@ -1423,42 +1587,54 @@ void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const Q
                 break;
             }
         }
-    } else if (pos != GenTime()) addGuide(pos, comment);
+    } else if (pos > GenTime()) addGuide(pos, comment);
     else {
         // remove guide
+        bool found = false;
         for (int i = 0; i < m_guides.count(); i++) {
             if (m_guides.at(i)->position() == oldPos) {
                 Guide *item = m_guides.takeAt(i);
                 delete item;
+                found = true;
                 break;
             }
         }
-
+        if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
     }
 }
 
-void CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
+bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
+    for (int i = 0; i < m_guides.count(); i++) {
+        if (m_guides.at(i)->position() == pos) {
+            emit displayMessage(i18n("A guide already exists at that position"), ErrorMessage);
+            return false;
+        }
+    }
     Guide *g = new Guide(this, pos, comment, m_scale, m_document->fps(), m_tracksHeight * m_tracksList.count());
     scene()->addItem(g);
     m_guides.append(g);
+    return true;
 }
 
 void CustomTrackView::slotAddGuide() {
-    addGuide(GenTime(m_cursorPos, m_document->fps()), i18n("guide"));
-    EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), GenTime(m_cursorPos, m_document->fps()), i18n("guide"), false);
-    m_commandStack->push(command);
-
+    if (addGuide(GenTime(m_cursorPos, m_document->fps()), i18n("guide"))) {
+        EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), GenTime(m_cursorPos, m_document->fps()), i18n("guide"), false);
+        m_commandStack->push(command);
+    }
 }
 
 void CustomTrackView::slotDeleteGuide() {
     GenTime pos = GenTime(m_cursorPos, m_document->fps());
+    bool found = false;
     for (int i = 0; i < m_guides.count(); i++) {
         if (m_guides.at(i)->position() == pos) {
             EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
             m_commandStack->push(command);
+            found = true;
             break;
         }
     }
+    if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
 }
 
 void CustomTrackView::setTool(PROJECTTOOL tool) {
@@ -1529,6 +1705,61 @@ QDomElement CustomTrackView::xmlInfo() {
     return guides;
 }
 
+bool CustomTrackView::findString(const QString &text) {
+    QString marker;
+    for (int i = 0; i < m_searchPoints.size(); ++i) {
+        marker = m_searchPoints.at(i).comment();
+        if (marker.contains(text, Qt::CaseInsensitive)) {
+            setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
+            int vert = verticalScrollBar()->value();
+            int hor = cursorPos();
+            ensureVisible(hor, vert + 10, 2, 2, 50, 0);
+            m_findIndex = i;
+            return true;
+        }
+    }
+    return false;
+}
+
+bool CustomTrackView::findNextString(const QString &text) {
+    QString marker;
+    for (int i = m_findIndex + 1; i < m_searchPoints.size(); ++i) {
+        marker = m_searchPoints.at(i).comment();
+        if (marker.contains(text, Qt::CaseInsensitive)) {
+            setCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()), true);
+            int vert = verticalScrollBar()->value();
+            int hor = cursorPos();
+            ensureVisible(hor, vert + 10, 2, 2, 50, 0);
+            m_findIndex = i;
+            return true;
+        }
+    }
+    m_findIndex = -1;
+    return false;
+}
+
+void CustomTrackView::initSearchStrings() {
+    m_searchPoints.clear();
+
+    QList<QGraphicsItem *> itemList = items();
+    for (int i = 0; i < itemList.count(); i++) {
+        if (itemList.at(i)->type() == AVWIDGET) {
+            ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
+            GenTime start = item->startPos();
+            CommentedTime t(start, item->clipName());
+            m_searchPoints.append(t);
+
+            QList < CommentedTime > markers = item->commentedSnapMarkers();
+            m_searchPoints += markers;
+        }
+    }
+}
+
+void CustomTrackView::clearSearchStrings() {
+    m_searchPoints.clear();
+    m_findIndex = 0;
+}
+
 /*
 void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )
 {