]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Merge branch 'master' into feature/pkey
[kdenlive] / src / customtrackview.cpp
index 3865dd831c0cf1defa768f84103c381091b53a0f..166990f43d1800f24ed9f65835884050cce9308b 100644 (file)
 #include "docclipbase.h"
 #include "clipitem.h"
 #include "definitions.h"
-#include "moveclipcommand.h"
-#include "movetransitioncommand.h"
-#include "resizeclipcommand.h"
-#include "editguidecommand.h"
-#include "addtimelineclipcommand.h"
-#include "addeffectcommand.h"
-#include "editeffectcommand.h"
-#include "moveeffectcommand.h"
-#include "addtransitioncommand.h"
-#include "edittransitioncommand.h"
-#include "editkeyframecommand.h"
-#include "changespeedcommand.h"
-#include "addmarkercommand.h"
-#include "razorclipcommand.h"
+#include "commands/moveclipcommand.h"
+#include "commands/movetransitioncommand.h"
+#include "commands/resizeclipcommand.h"
+#include "commands/editguidecommand.h"
+#include "commands/addextradatacommand.h"
+#include "commands/addtimelineclipcommand.h"
+#include "commands/addeffectcommand.h"
+#include "commands/editeffectcommand.h"
+#include "commands/moveeffectcommand.h"
+#include "commands/addtransitioncommand.h"
+#include "commands/edittransitioncommand.h"
+#include "commands/editkeyframecommand.h"
+#include "commands/changespeedcommand.h"
+#include "commands/addmarkercommand.h"
+#include "commands/razorclipcommand.h"
 #include "kdenlivesettings.h"
 #include "transition.h"
 #include "clipmanager.h"
 #include "ui_keyframedialog_ui.h"
 #include "clipdurationdialog.h"
 #include "abstractgroupitem.h"
-#include "insertspacecommand.h"
+#include "commands/insertspacecommand.h"
 #include "spacerdialog.h"
-#include "addtrackcommand.h"
-#include "movegroupcommand.h"
+#include "commands/addtrackcommand.h"
+#include "commands/changeeffectstatecommand.h"
+#include "commands/movegroupcommand.h"
 #include "ui_addtrack_ui.h"
+#include "ui_importkeyframesdialog_ui.h"
 #include "initeffects.h"
-#include "locktrackcommand.h"
-#include "groupclipscommand.h"
-#include "splitaudiocommand.h"
-#include "changecliptypecommand.h"
+#include "commands/locktrackcommand.h"
+#include "commands/groupclipscommand.h"
+#include "commands/splitaudiocommand.h"
+#include "commands/changecliptypecommand.h"
 #include "trackdialog.h"
 #include "tracksconfigdialog.h"
-#include "configtrackscommand.h"
-#include "rebuildgroupcommand.h"
-#include "razorgroupcommand.h"
+#include "commands/configtrackscommand.h"
+#include "commands/rebuildgroupcommand.h"
+#include "commands/razorgroupcommand.h"
+#include "commands/refreshmonitorcommand.h"
 #include "profilesdialog.h"
 
+#include "lib/audio/audioEnvelope.h"
+#include "lib/audio/audioCorrelation.h"
+
 #include <KDebug>
 #include <KLocale>
 #include <KUrl>
@@ -69,6 +76,7 @@
 #include <KCursor>
 #include <KMessageBox>
 #include <KIO/NetAccess>
+#include <KFileDialog>
 
 #include <QMouseEvent>
 #include <QStylePainter>
 #include <QGraphicsDropShadowEffect>
 #endif
 
+#define SEEK_INACTIVE (-1)
+
+//#define DEBUG
+
 bool sortGuidesList(const Guide *g1 , const Guide *g2)
 {
     return (*g1).position() < (*g2).position();
@@ -98,39 +110,42 @@ bool sortGuidesList(const Guide *g1 , const Guide *g2)
 // const int duration = animate ? 1500 : 1;
 
 CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscene, QWidget *parent) :
-        QGraphicsView(projectscene, parent),
-        m_tracksHeight(KdenliveSettings::trackheight()),
-        m_projectDuration(0),
-        m_cursorPos(0),
-        m_document(doc),
-        m_scene(projectscene),
-        m_cursorLine(NULL),
-        m_operationMode(NONE),
-        m_moveOpMode(NONE),
-        m_dragItem(NULL),
-        m_dragGuide(NULL),
-        m_visualTip(NULL),
-        m_animation(NULL),
-        m_clickPoint(),
-        m_autoScroll(KdenliveSettings::autoscroll()),
-        m_pasteEffectsAction(NULL),
-        m_ungroupAction(NULL),
-        m_scrollOffset(0),
-        m_clipDrag(false),
-        m_findIndex(0),
-        m_tool(SELECTTOOL),
-        m_copiedItems(),
-        m_menuPosition(),
-        m_blockRefresh(false),
-        m_selectionGroup(NULL),
-        m_selectedTrack(0),
-        m_controlModifier(false)
-{
-    if (doc)
+    QGraphicsView(projectscene, parent),
+    m_tracksHeight(KdenliveSettings::trackheight()),
+    m_projectDuration(0),
+    m_cursorPos(0),
+    m_document(doc),
+    m_scene(projectscene),
+    m_cursorLine(NULL),
+    m_operationMode(NONE),
+    m_moveOpMode(NONE),
+    m_dragItem(NULL),
+    m_dragGuide(NULL),
+    m_visualTip(NULL),
+    m_animation(NULL),
+    m_clickPoint(),
+    m_autoScroll(KdenliveSettings::autoscroll()),
+    m_pasteEffectsAction(NULL),
+    m_ungroupAction(NULL),
+    m_scrollOffset(0),
+    m_clipDrag(false),
+    m_findIndex(0),
+    m_tool(SELECTTOOL),
+    m_copiedItems(),
+    m_menuPosition(),
+    m_blockRefresh(false),
+    m_selectionGroup(NULL),
+    m_selectedTrack(0),
+    m_audioCorrelator(NULL),
+    m_audioAlignmentReference(NULL),
+    m_controlModifier(false)
+{
+    if (doc) {
         m_commandStack = doc->commandStack();
-    else
+    } else {
         m_commandStack = NULL;
-
+    }
+    m_ct = 0;
     setMouseTracking(true);
     setAcceptDrops(true);
     setFrameShape(QFrame::NoFrame);
@@ -142,8 +157,6 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen
 
     m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
 
-    pixmapCache = new KPixmapCache("kdenlive-thumbs");
-
     m_animationTimer = new QTimeLine(800);
     m_animationTimer->setFrameRange(0, 5);
     m_animationTimer->setUpdateInterval(100);
@@ -188,6 +201,7 @@ CustomTrackView::~CustomTrackView()
     qDeleteAll(m_guides);
     m_guides.clear();
     m_waitingThumbs.clear();
+    delete m_animationTimer;
 }
 
 //virtual
@@ -263,14 +277,35 @@ void CustomTrackView::checkAutoScroll()
     return m_scene->m_tracksList;
 }*/
 
-void CustomTrackView::checkTrackHeight()
+
+int CustomTrackView::getFrameWidth()
+{
+    return (int) (m_tracksHeight * m_document->mltProfile().display_aspect_num / m_document->mltProfile().display_aspect_den + 0.5);
+}
+
+void CustomTrackView::updateSceneFrameWidth()
 {
-    if (m_tracksHeight == KdenliveSettings::trackheight()) return;
+    int frameWidth = getFrameWidth();
+    QList<QGraphicsItem *> itemList = items();
+    ClipItem *item;
+    for (int i = 0; i < itemList.count(); i++) {
+        if (itemList.at(i)->type() == AVWIDGET) {
+            item = (ClipItem*) itemList.at(i);
+            item->resetFrameWidth(frameWidth);
+            item->resetThumbs(true);
+        }
+    }
+}
+
+bool CustomTrackView::checkTrackHeight()
+{
+    if (m_tracksHeight == KdenliveSettings::trackheight()) return false;
     m_tracksHeight = KdenliveSettings::trackheight();
     emit trackHeightChanged();
     QList<QGraphicsItem *> itemList = items();
     ClipItem *item;
     Transition *transitionitem;
+    int frameWidth = getFrameWidth();
     bool snap = KdenliveSettings::snaptopoints();
     KdenliveSettings::setSnaptopoints(false);
     for (int i = 0; i < itemList.count(); i++) {
@@ -278,6 +313,7 @@ void CustomTrackView::checkTrackHeight()
             item = (ClipItem*) itemList.at(i);
             item->setRect(0, 0, item->rect().width(), m_tracksHeight - 1);
             item->setPos((qreal) item->startPos().frames(m_document->fps()), (qreal) item->track() * m_tracksHeight + 1);
+            item->resetFrameWidth(frameWidth);
             item->resetThumbs(true);
         } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
             transitionitem = (Transition*) itemList.at(i);
@@ -298,6 +334,7 @@ void CustomTrackView::checkTrackHeight()
 //     verticalScrollBar()->setMaximum(m_tracksHeight * m_document->tracksCount());
     KdenliveSettings::setSnaptopoints(snap);
     viewport()->update();
+    return true;
 }
 
 /** Zoom or move viewport on mousewheel
@@ -334,7 +371,7 @@ void CustomTrackView::slotFetchNextThumbs()
 {
     if (!m_waitingThumbs.isEmpty()) {
         ClipItem *item = m_waitingThumbs.takeFirst();
-        while ((item == NULL) && !m_waitingThumbs.isEmpty()) {
+        while (item == NULL && !m_waitingThumbs.isEmpty()) {
             item = m_waitingThumbs.takeFirst();
         }
         if (item) item->slotFetchThumbs();
@@ -357,16 +394,26 @@ void CustomTrackView::slotCheckPositionScrolling()
     // If mouse is at a border of the view, scroll
     if (m_moveOpMode != SEEK) return;
     if (mapFromScene(m_cursorPos, 0).x() < 3) {
+       if (horizontalScrollBar()->value() == 0) return;
         horizontalScrollBar()->setValue(horizontalScrollBar()->value() - 2);
         QTimer::singleShot(200, this, SLOT(slotCheckPositionScrolling()));
-        setCursorPos(mapToScene(QPoint(-2, 0)).x());
+        seekCursorPos(mapToScene(QPoint(-2, 0)).x());
     } else if (viewport()->width() - 3 < mapFromScene(m_cursorPos + 1, 0).x()) {
         horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 2);
-        setCursorPos(mapToScene(QPoint(viewport()->width(), 0)).x() + 1);
+        seekCursorPos(mapToScene(QPoint(viewport()->width(), 0)).x() + 1);
         QTimer::singleShot(200, this, SLOT(slotCheckPositionScrolling()));
     }
 }
 
+void CustomTrackView::slotAlignPlayheadToMousePos()
+{
+       /* get curser point ref in screen coord */
+       QPoint ps = QCursor::pos();
+       /* get xPos in scene coord */
+       int mappedXPos = qMax((int)(mapToScene(mapFromGlobal(ps)).x() + 0.5), 0);
+       /* move playhead to new xPos*/
+       seekCursorPos(mappedXPos);
+}
 
 // virtual
 void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
@@ -376,18 +423,24 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
     double snappedPos = getSnapPointForPos(mappedXPos);
     emit mousePosition(mappedXPos);
 
+    if (m_operationMode == SCROLLTIMELINE) {
+       QGraphicsView::mouseMoveEvent(event);
+       return;
+    }
+
     if (event->buttons() & Qt::MidButton) return;
     if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && m_operationMode != RESIZESTART && m_operationMode != RESIZEEND)) {
         event->setAccepted(true);
         m_moveOpMode = NONE;
-        QGraphicsView::mouseMoveEvent(event);
+        if (event->modifiers() != Qt::ControlModifier || dragMode() == QGraphicsView::RubberBandDrag) QGraphicsView::mouseMoveEvent(event);
         return;
     }
 
     if (event->buttons() != Qt::NoButton) {
         bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance();
+       if (m_dragItem && move) m_clipDrag = true;
         if (m_dragItem && m_tool == SELECTTOOL) {
-            if (m_operationMode == MOVE && move) {
+            if (m_operationMode == MOVE && m_clipDrag) {
                 QGraphicsView::mouseMoveEvent(event);
                 // If mouse is at a border of the view, scroll
                 if (pos < 5) {
@@ -553,11 +606,8 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
 
     if (m_tool == RAZORTOOL) {
         setCursor(m_razorCursor);
-        //QGraphicsView::mouseMoveEvent(event);
-        //return;
     } else if (m_tool == SPACERTOOL) {
         setCursor(m_spacerCursor);
-        return;
     }
 
     QList<QGraphicsItem *> itemList = items(event->pos());
@@ -566,12 +616,18 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
 
     if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) {
         opMode = MOVEGUIDE;
+       setCursor(Qt::SplitHCursor);
     } else for (int i = 0; i < itemList.count(); i++) {
-            if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
-                item = (QGraphicsRectItem*) itemList.at(i);
-                break;
-            }
-        }
+        if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
+            item = (QGraphicsRectItem*) itemList.at(i);
+           break;
+       }
+    }
+
+    if (m_tool == SPACERTOOL) {
+        event->accept();
+        return;
+    }
 
     if (item && event->buttons() == Qt::NoButton) {
         AbstractClipItem *clip = static_cast <AbstractClipItem*>(item);
@@ -579,12 +635,23 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
             // razor tool over a clip, display current frame in monitor
             if (false && !m_blockRefresh && item->type() == AVWIDGET) {
                 //TODO: solve crash when showing frame when moving razor over clip
-                emit showClipFrame(((ClipItem *) item)->baseClip(), QPoint(), mappedXPos - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
+                emit showClipFrame(((ClipItem *) item)->baseClip(), QPoint(), false, mappedXPos - (clip->startPos() - clip->cropStart()).frames(m_document->fps()));
             }
             event->accept();
             return;
         }
-        opMode = clip->operationMode(mapToScene(event->pos()));
+
+        if (m_selectionGroup && clip->parentItem() == m_selectionGroup) {
+            // all other modes break the selection, so the user probably wants to move it
+            opMode = MOVE;
+        } else {
+           if (clip->rect().width() * transform().m11() < 15) {
+               // If the item is very small, only allow move
+               opMode = MOVE;
+           }
+            else opMode = clip->operationMode(mapToScene(event->pos()));
+        }
+
         const double size = 5;
         if (opMode == m_moveOpMode) {
             QGraphicsView::mouseMoveEvent(event);
@@ -594,11 +661,14 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
         }
         m_moveOpMode = opMode;
         setTipAnimation(clip, opMode, size);
+        ClipItem *ci = NULL;
+        if (item->type() == AVWIDGET)
+            ci = static_cast <ClipItem *>(item);
+        QString message;
         if (opMode == MOVE) {
             setCursor(Qt::OpenHandCursor);
-            if (item->type() == AVWIDGET) {
-                ClipItem *ci = static_cast <ClipItem *>(item);
-                QString message = ci->clipName() + i18n(":");
+            if (ci) {
+                message = ci->clipName() + i18n(":");
                 message.append(i18n(" Position:") + m_document->timecode().getDisplayTimecode(ci->info().startPos, KdenliveSettings::frametimecode()));
                 message.append(i18n(" Duration:") + m_document->timecode().getDisplayTimecode(ci->cropDuration(),  KdenliveSettings::frametimecode()));
                 if (clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) {
@@ -613,40 +683,53 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                         message.append(i18n(" Selection duration:") + m_document->timecode().getDisplayTimecode(parent2->duration(), KdenliveSettings::frametimecode()));
                     }
                 }
-                emit displayMessage(message, InformationMessage);
             }
         } else if (opMode == RESIZESTART) {
             setCursor(KCursor("left_side", Qt::SizeHorCursor));
+            if (ci)
+                message = i18n("Crop from start: ") + m_document->timecode().getDisplayTimecode(ci->cropStart(), KdenliveSettings::frametimecode());
             if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup)
-                emit displayMessage(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."), InformationMessage);
+                message.append(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."));
         } else if (opMode == RESIZEEND) {
             setCursor(KCursor("right_side", Qt::SizeHorCursor));
+            if (ci)
+                message = i18n("Duration: ") + m_document->timecode().getDisplayTimecode(ci->cropDuration(), KdenliveSettings::frametimecode());
             if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup)
-                emit displayMessage(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."), InformationMessage);
+                message.append(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."));
         } else if (opMode == FADEIN || opMode == FADEOUT) {
             setCursor(Qt::PointingHandCursor);
-            emit displayMessage(i18n("Drag to add or resize a fade effect."), InformationMessage);
+            if (ci && opMode == FADEIN && ci->fadeIn()) {
+                message = i18n("Fade in duration: ");
+                message.append(m_document->timecode().getDisplayTimecodeFromFrames(ci->fadeIn(), KdenliveSettings::frametimecode()));
+            } else if (ci && opMode == FADEOUT && ci->fadeOut()) {
+                message = i18n("Fade out duration: ");
+                message.append(m_document->timecode().getDisplayTimecodeFromFrames(ci->fadeOut(), KdenliveSettings::frametimecode()));
+            } else {
+                message = i18n("Drag to add or resize a fade effect.");
+            }
         } else if (opMode == TRANSITIONSTART || opMode == TRANSITIONEND) {
             setCursor(Qt::PointingHandCursor);
-            emit displayMessage(i18n("Click to add a transition."), InformationMessage);
+            message = i18n("Click to add a transition.");
         } else if (opMode == KEYFRAME) {
             setCursor(Qt::PointingHandCursor);
             emit displayMessage(i18n("Move keyframe above or below clip to remove it, double click to add a new one."), InformationMessage);
         }
+
+        if (!message.isEmpty())
+            emit displayMessage(message, InformationMessage);
     } // no clip under mouse
     else if (m_tool == RAZORTOOL) {
         event->accept();
         return;
     } else if (opMode == MOVEGUIDE) {
         m_moveOpMode = opMode;
-        setCursor(Qt::SplitHCursor);
     } else {
         removeTipAnimation();
         setCursor(Qt::ArrowCursor);
         if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
             QGraphicsView::mouseMoveEvent(event);
             m_moveOpMode = SEEK;
-            setCursorPos(mappedXPos);
+            seekCursorPos(mappedXPos);
             slotCheckPositionScrolling();
             return;
         } else m_moveOpMode = NONE;
@@ -659,6 +742,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 {
     setFocus(Qt::MouseFocusReason);
     m_menuPosition = QPoint();
+    m_clipDrag = false;
 
     // special cases (middle click button or ctrl / shift click
     if (event->button() == Qt::MidButton) {
@@ -674,6 +758,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         setDragMode(QGraphicsView::RubberBandDrag);
         if (!(event->modifiers() & Qt::ControlModifier)) {
             resetSelectionGroup();
+           if (m_dragItem) {
+               emit clipItemSelected(NULL);
+               m_dragItem = NULL;
+           }
             scene()->clearSelection();
         }
         m_blockRefresh = false;
@@ -684,7 +772,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 
     m_blockRefresh = true;
     m_dragGuide = NULL;
-    bool collision = false;
 
     if (m_tool != RAZORTOOL) activateMonitor();
     else if (m_document->renderer()->playSpeed() != 0.0) {
@@ -695,13 +782,12 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
 
     // check item under mouse
     QList<QGraphicsItem *> collisionList = items(m_clickEvent);
-
     if (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && collisionList.count() == 0) {
         // Pressing Ctrl + left mouse button in an empty area scrolls the timeline
         setDragMode(QGraphicsView::ScrollHandDrag);
-        QGraphicsView::mousePressEvent(event);
         m_blockRefresh = false;
-        m_operationMode = NONE;
+        m_operationMode = SCROLLTIMELINE;
+       QGraphicsView::mousePressEvent(event);
         return;
     }
 
@@ -712,7 +798,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             m_dragGuide = (Guide *) collisionList.at(i);
             if (event->button() == Qt::LeftButton) { // move it
                 m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, true);
-                collision = true;
                 m_operationMode = MOVEGUIDE;
                 // deselect all clips so that only the guide will move
                 m_scene->clearSelection();
@@ -735,15 +820,19 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             collisionClip = static_cast <AbstractClipItem *>(collisionList.at(ct));
             if (collisionClip->isItemLocked())
                 break;
-            if (collisionClip == m_dragItem)
+            if (collisionClip == m_dragItem) {
                 collisionClip = NULL;
-            else
+           }
+            else {
                 m_dragItem = collisionClip;
+           }
             found = true;
+           m_dragItem->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
             m_dragItemInfo = m_dragItem->info();
+           if (m_selectionGroup) m_selectionGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
             if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET && m_dragItem->parentItem() != m_selectionGroup) {
-                // kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
                 dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
+               dragGroup->setProperty("y_absolute", mapToScene(m_clickEvent).y() - m_dragItem->scenePos().y());
             }
             break;
         }
@@ -753,13 +842,14 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         if (m_dragItem) emit clipItemSelected(NULL);
         m_dragItem = NULL;
     }
-#if QT_VERSION >= 0x040600
+#if QT_VERSION >= 0x040800
     // Add shadow to dragged item, currently disabled because of painting artifacts
-    //TODO: re-enable when fixed
-    /*QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect();
-    eff->setBlurRadius(5);
-    eff->setOffset(3, 3);
-    m_dragItem->setGraphicsEffect(eff);*/
+    /*if (m_dragItem) {
+       QGraphicsDropShadowEffect *eff = new QGraphicsDropShadowEffect();
+       eff->setBlurRadius(5);
+       eff->setOffset(3, 3);
+       m_dragItem->setGraphicsEffect(eff);
+    }*/
 #endif
     if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) {
         // update transition menu action
@@ -804,7 +894,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     // No item under click
     if (m_dragItem == NULL || m_tool == SPACERTOOL) {
         resetSelectionGroup(false);
-        setCursor(Qt::ArrowCursor);
         m_scene->clearSelection();
         //event->accept();
         updateClipTypeActions(NULL);
@@ -847,8 +936,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                     if (item->isItemLocked()) continue;
                     offsetList.append(item->startPos());
                     offsetList.append(item->endPos());
-                    m_selectionGroup->addToGroup(selection.at(i));
-                    selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(selection.at(i));
                 } else if (/*selection.at(i)->parentItem() == 0 && */selection.at(i)->type() == GROUPWIDGET) {
                     if (static_cast<AbstractGroupItem *>(selection.at(i))->isItemLocked()) continue;
                     QList<QGraphicsItem *> children = selection.at(i)->childItems();
@@ -857,13 +945,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                         offsetList.append(item->startPos());
                         offsetList.append(item->endPos());
                     }
-                    m_selectionGroup->addToGroup(selection.at(i));
-                    selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(selection.at(i));
                 } else if (selection.at(i)->parentItem() && !selection.contains(selection.at(i)->parentItem())) {
                     if (static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())->isItemLocked()) continue;
-                    //AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(selection.at(i)->parentItem());
-                    m_selectionGroup->addToGroup(selection.at(i)->parentItem());
-                    selection.at(i)->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(selection.at(i)->parentItem());
                 }
             }
             m_spacerOffset = m_selectionGroup->sceneBoundingRect().left() - (int)(mapToScene(m_clickEvent).x());
@@ -881,9 +966,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             }
             m_operationMode = SPACER;
         } else {
-            setCursorPos((int)(mapToScene(event->x(), 0).x()));
+           setCursor(Qt::ArrowCursor);
+            seekCursorPos((int)(mapToScene(event->x(), 0).x()));
         }
         QGraphicsView::mousePressEvent(event);
+        event->ignore();
         return;
     }
 
@@ -909,35 +996,64 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     bool itemSelected = false;
-    if (m_dragItem->isSelected())
+    if (m_dragItem->isSelected()) {
         itemSelected = true;
-    else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected())
+    }
+    else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) {
         itemSelected = true;
-    else if (dragGroup && dragGroup->isSelected())
+    }
+    else if (dragGroup && dragGroup->isSelected()) {
         itemSelected = true;
+    }
 
-    if (event->modifiers() == Qt::ControlModifier || itemSelected == false) {
+    if ((event->modifiers() == Qt::ControlModifier) || itemSelected == false) {
         if (event->modifiers() != Qt::ControlModifier) {
             resetSelectionGroup(false);
             m_scene->clearSelection();
             // A refresh seems necessary otherwise in zoomed mode, some clips disappear
             viewport()->update();
-        } else resetSelectionGroup();
+        } else {
+           resetSelectionGroup();
+       }
         dragGroup = NULL;
         if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
-            //kDebug()<<"// KLIK FOUND GRP: "<<m_dragItem->sceneBoundingRect();
             dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
         }
+
         bool selected = !m_dragItem->isSelected();
-        if (dragGroup)
+       QGraphicsView::mousePressEvent(event);
+         
+        if (dragGroup) {
             dragGroup->setSelected(selected);
+           if (dragGroup->parentItem())
+               dragGroup->parentItem()->setSelected(selected);
+       }
         else
             m_dragItem->setSelected(selected);
-
-        groupSelectedItems();
-        ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
-        updateClipTypeActions(dragGroup == NULL ? clip : NULL);
-        m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
+       if (selected == false) {
+           m_dragItem = NULL;
+       }
+        groupSelectedItems(QList <QGraphicsItem*>(), false, false, true);
+       if (m_dragItem) { 
+           ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
+           updateClipTypeActions(dragGroup == NULL ? clip : NULL);
+           m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
+       }
+       else updateClipTypeActions(NULL);
+    }
+    else {
+       QGraphicsView::mousePressEvent(event);
+       if (m_selectionGroup) {
+           QList<QGraphicsItem *> children = m_selectionGroup->childItems();
+           for (int i = 0; i < children.count(); i++) {
+               children.at(i)->setSelected(itemSelected);
+           }
+            m_selectionGroup->setSelected(itemSelected);
+           
+       }
+       if (dragGroup)
+            dragGroup->setSelected(itemSelected);
+       m_dragItem->setSelected(itemSelected);
     }
 
     if (collisionClip != NULL || m_dragItem == NULL) {
@@ -950,10 +1066,22 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     // If clicked item is selected, allow move
-    if (event->modifiers() != Qt::ControlModifier && m_operationMode == NONE) QGraphicsView::mousePressEvent(event);
+    //if (!(event->modifiers() | Qt::ControlModifier) && m_operationMode == NONE)
+    //QGraphicsView::mousePressEvent(event);
 
-    m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
-    m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
+    if (m_dragItem) {
+       m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
+    if (m_selectionGroup && m_dragItem->parentItem() == m_selectionGroup) {
+        // all other modes break the selection, so the user probably wants to move it
+        m_operationMode = MOVE;
+    } else {
+       if (m_dragItem->rect().width() * transform().m11() < 15) {
+           // If the item is very small, only allow move
+           m_operationMode = MOVE;
+       }
+        else m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
+    }
+    } else m_operationMode = NONE;
     m_controlModifier = (event->modifiers() == Qt::ControlModifier);
 
     // Update snap points
@@ -1064,8 +1192,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     m_blockRefresh = false;
-    //kDebug()<<pos;
-    QGraphicsView::mousePressEvent(event);
 }
 
 void CustomTrackView::rebuildGroup(int childTrack, GenTime childPos)
@@ -1086,15 +1212,13 @@ void CustomTrackView::rebuildGroup(int childTrack, GenTime childPos)
 void CustomTrackView::rebuildGroup(AbstractGroupItem *group)
 {
     if (group) {
-        resetSelectionGroup(false);
-        m_scene->clearSelection();
-
         QList <QGraphicsItem *> children = group->childItems();
         m_document->clipManager()->removeGroup(group);
-        scene()->destroyItemGroup(group);
-        for (int i = 0; i < children.count(); i++)
-            children.at(i)->setSelected(true);
-        groupSelectedItems(false, true);
+       /*for (int i = 0; i < children.count(); i++) {
+           group->removeFromGroup(children.at(i));
+       }*/
+       scene()->destroyItemGroup(group);
+        groupSelectedItems(children, false, true, true);
     }
 }
 
@@ -1107,6 +1231,7 @@ void CustomTrackView::resetSelectionGroup(bool selectItems)
 
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
         scene()->destroyItemGroup(m_selectionGroup);
+       m_selectionGroup = NULL;
         for (int i = 0; i < children.count(); i++) {
             if (children.at(i)->parentItem() == 0 && (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) {
                 if (!static_cast <AbstractClipItem *>(children.at(i))->isItemLocked()) {
@@ -1118,29 +1243,46 @@ void CustomTrackView::resetSelectionGroup(bool selectItems)
                 children.at(i)->setSelected(selectItems);
             }
         }
-        m_selectionGroup = NULL;
         KdenliveSettings::setSnaptopoints(snap);
     }
 }
 
-void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
+void CustomTrackView::groupSelectedItems(QList <QGraphicsItem *> selection, bool force, bool createNewGroup, bool selectNewGroup)
 {
     if (m_selectionGroup) {
         kDebug() << "///// ERROR, TRYING TO OVERRIDE EXISTING GROUP";
         return;
     }
-    QList<QGraphicsItem *> selection = m_scene->selectedItems();
-    if (selection.isEmpty()) return;
+    if (selection.isEmpty()) selection = m_scene->selectedItems();
+    // Split groups and items
+    QSet <QGraphicsItemGroup *> groupsList;
+    QSet <QGraphicsItem *> itemsList;
+
+    for (int i = 0; i < selection.count(); i++) {
+       if (selection.at(i)->type() == GROUPWIDGET) {
+           groupsList.insert(static_cast<AbstractGroupItem*> (selection.at(i)));
+       }
+    }
+    for (int i = 0; i < selection.count(); i++) {
+       if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
+           if (selection.at(i)->parentItem() && selection.at(i)->parentItem()->type() == GROUPWIDGET) {
+               groupsList.insert(static_cast <QGraphicsItemGroup *> (selection.at(i)->parentItem()));
+           }
+           else {
+               itemsList.insert(selection.at(i));
+           }
+       }
+    }
+    if (itemsList.isEmpty() && groupsList.isEmpty()) return;
+    
     QRectF rectUnion;
     // Find top left position of selection
-    for (int i = 0; i < selection.count(); i++) {
-        if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-            rectUnion = rectUnion.united(selection.at(i)->sceneBoundingRect());
-        } else if (selection.at(i)->parentItem()) {
-            rectUnion = rectUnion.united(selection.at(i)->parentItem()->sceneBoundingRect());
-        }
+    foreach (const QGraphicsItemGroup *value, groupsList) {
+        rectUnion = rectUnion.united(value->sceneBoundingRect());
+    }
+    foreach (const QGraphicsItem *value, itemsList) {
+        rectUnion = rectUnion.united(value->sceneBoundingRect());
     }
-
     if (force || selection.count() > 1) {
         bool snap = KdenliveSettings::snaptopoints();
         KdenliveSettings::setSnaptopoints(false);
@@ -1152,32 +1294,23 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
             //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
 
             scene()->addItem(newGroup);
-
             // Check if we are trying to include a group in a group
-            QList <AbstractGroupItem *> groups;
-            for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->type() == GROUPWIDGET && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i))))
-                    groups.append(static_cast<AbstractGroupItem *>(selection.at(i)));
-                else if (selection.at(i)->parentItem() && !groups.contains(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem())))
-                    groups.append(static_cast<AbstractGroupItem *>(selection.at(i)->parentItem()));
-            }
-            if (!groups.isEmpty()) {
-                // ungroup previous groups
-                while (!groups.isEmpty()) {
-                    AbstractGroupItem *grp = groups.takeFirst();
-                    m_document->clipManager()->removeGroup(grp);
-                    scene()->destroyItemGroup(grp);
-                }
-                selection = m_scene->selectedItems();
-            }
+           foreach (QGraphicsItemGroup *value, groupsList) {
+               QList<QGraphicsItem *> children = value->childItems();
+               for (int i = 0; i < children.count(); i++) {
+                   if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)
+                       itemsList.insert(children.at(i));
+               }
+               AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(value);
+               m_document->clipManager()->removeGroup(grp);
+               scene()->destroyItemGroup(grp);
+           }
 
-            for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
-                    newGroup->addToGroup(selection.at(i));
-                    selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
-                }
+           foreach (QGraphicsItem *value, itemsList) {
+                newGroup->addItem(value);
             }
             KdenliveSettings::setSnaptopoints(snap);
+           if (selectNewGroup) newGroup->setSelected(true);
         } else {
             m_selectionGroup = new AbstractGroupItem(m_document->fps());
             m_selectionGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
@@ -1186,16 +1319,17 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
             m_selectionGroup->translate(- diff.x(), -diff.y());
 
             scene()->addItem(m_selectionGroup);
-            for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-                    m_selectionGroup->addToGroup(selection.at(i));
-                    selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
-                }
+            foreach (QGraphicsItemGroup *value, groupsList) {
+                m_selectionGroup->addItem(value);
+            }
+            foreach (QGraphicsItem *value, itemsList) {
+                m_selectionGroup->addItem(value);
             }
             KdenliveSettings::setSnaptopoints(snap);
             if (m_selectionGroup) {
                 m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
                 m_selectionGroupInfo.track = m_selectionGroup->track();
+               if (selectNewGroup) m_selectionGroup->setSelected(true);
             }
         }
     } else resetSelectionGroup();
@@ -1233,14 +1367,14 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event)
             ClipItem * item = static_cast <ClipItem *>(m_dragItem);
             //QString previous = item->keyframes(item->selectedEffectIndex());
             QDomElement oldEffect = item->selectedEffect().cloneNode().toElement();
-            item->insertKeyframe(item->getEffectAt(item->selectedEffectIndex()), keyFramePos.frames(m_document->fps()), val);
+            item->insertKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), keyFramePos.frames(m_document->fps()), val);
             //item->updateKeyframeEffect();
             //QString next = item->keyframes(item->selectedEffectIndex());
             QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
-            EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false);
+            EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false, false);
             //EditKeyFrameCommand *command = new EditKeyFrameCommand(this, m_dragItem->track(), m_dragItem->startPos(), item->selectedEffectIndex(), previous, next, false);
             m_commandStack->push(command);
-            updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
+            updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect());
             emit clipItemSelected(item, item->selectedEffectIndex());
         }
     } else if (m_dragItem && !m_dragItem->isItemLocked()) {
@@ -1289,51 +1423,64 @@ void CustomTrackView::editItemDuration()
         else
             getClipAvailableSpace(item, minimum, maximum);
 
-        ClipDurationDialog d(item, m_document->timecode(), minimum, maximum, this);
-        if (d.exec() == QDialog::Accepted) {
+        QPointer<ClipDurationDialog> d = new ClipDurationDialog(item,
+                               m_document->timecode(), minimum, maximum, this);
+        if (d->exec() == QDialog::Accepted) {
             ItemInfo clipInfo = item->info();
             ItemInfo startInfo = clipInfo;
             if (item->type() == TRANSITIONWIDGET) {
                 // move & resize transition
-                clipInfo.startPos = d.startPos();
-                clipInfo.endPos = clipInfo.startPos + d.duration();
+                clipInfo.startPos = d->startPos();
+                clipInfo.endPos = clipInfo.startPos + d->duration();
                 clipInfo.track = item->track();
                 MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, clipInfo, true);
                 updateTrackDuration(clipInfo.track, command);
                 m_commandStack->push(command);
             } else {
                 // move and resize clip
+                ClipItem *clip = static_cast<ClipItem *>(item);
                 QUndoCommand *moveCommand = new QUndoCommand();
                 moveCommand->setText(i18n("Edit clip"));
-                if (d.duration() < item->cropDuration() || d.cropStart() != clipInfo.cropStart) {
+                if (d->duration() < item->cropDuration() || d->cropStart() != clipInfo.cropStart) {
                     // duration was reduced, so process it first
-                    clipInfo.endPos = clipInfo.startPos + d.duration();
-                    clipInfo.cropStart = d.cropStart();
-                    new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
+                    clipInfo.endPos = clipInfo.startPos + d->duration();
+                    clipInfo.cropStart = d->cropStart();
+
+                    resizeClip(startInfo, clipInfo);
+                    new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand);
+                    adjustEffects(clip, startInfo, moveCommand);
+                    new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand);
                 }
-                if (d.startPos() != clipInfo.startPos) {
+
+                if (d->startPos() != clipInfo.startPos) {
                     startInfo = clipInfo;
-                    clipInfo.startPos = d.startPos();
+                    clipInfo.startPos = d->startPos();
                     clipInfo.endPos = item->endPos() + (clipInfo.startPos - startInfo.startPos);
                     new MoveClipCommand(this, startInfo, clipInfo, true, moveCommand);
                 }
-                if (d.duration() > item->cropDuration()) {
+
+                if (d->duration() > item->cropDuration()) {
                     // duration was increased, so process it after move
                     startInfo = clipInfo;
-                    clipInfo.endPos = clipInfo.startPos + d.duration();
-                    clipInfo.cropStart = d.cropStart();
-                    new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand);
+                    clipInfo.endPos = clipInfo.startPos + d->duration();
+                    clipInfo.cropStart = d->cropStart();
+
+                    resizeClip(startInfo, clipInfo);
+                    new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand);
+                    adjustEffects(clip, startInfo, moveCommand);
+                    new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand);
                 }
                 updateTrackDuration(clipInfo.track, moveCommand);
                 m_commandStack->push(moveCommand);
             }
         }
+        delete d;
     } else {
         emit displayMessage(i18n("Item is locked"), ErrorMessage);
     }
 }
 
-void CustomTrackView::editKeyFrame(const GenTime /*pos*/, const int /*track*/, const int /*index*/, const QString /*keyframes*/)
+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) {
@@ -1403,7 +1550,15 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out)
     pasteInfo.startPos = GenTime(m_cursorPos, m_document->fps());
     pasteInfo.endPos = pasteInfo.startPos + info.endPos;
     pasteInfo.track = selectedTrack();
-    if (!canBePastedTo(pasteInfo, AVWIDGET)) {
+    bool ok = canBePastedTo(pasteInfo, AVWIDGET);
+    if (!ok) {
+       // Cannot be inserted at cursor pos, insert at end of track
+       int duration = m_document->renderer()->mltTrackDuration(m_document->tracksCount() - pasteInfo.track) + 1;
+       pasteInfo.startPos = GenTime(duration, m_document->fps());
+       pasteInfo.endPos = pasteInfo.startPos + info.endPos;
+       ok = canBePastedTo(pasteInfo, AVWIDGET);
+    }
+    if (!ok) {
         emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage);
         return;
     }
@@ -1418,7 +1573,7 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out)
         splitAudio();
 }
 
-bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
+bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
 {
     if (data->hasFormat("kdenlive/clip")) {
         m_clipDrag = true;
@@ -1430,6 +1585,10 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
             kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
             return false;
         }
+        if (clip->getProducer() == NULL) {
+            emit displayMessage(i18n("Clip not ready"), ErrorMessage);
+            return false;
+        }
         QPointF framePos = mapToScene(pos);
         ItemInfo info;
         info.startPos = GenTime();
@@ -1449,9 +1608,8 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
             return true;
         }
         m_selectionGroup = new AbstractGroupItem(m_document->fps());
-        ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1);
-        m_selectionGroup->addToGroup(item);
-        item->setFlag(QGraphicsItem::ItemIsMovable, false);
+        ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth());
+        m_selectionGroup->addItem(item);
 
         QList <GenTime> offsetList;
         offsetList.append(info.endPos);
@@ -1476,18 +1634,32 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
 
         // Check if clips can be inserted at that position
         for (int i = 0; i < ids.size(); ++i) {
-            DocClipBase *clip = m_document->getBaseClip(ids.at(i));
+           QString clipData = ids.at(i);
+            DocClipBase *clip = m_document->getBaseClip(clipData.section('/', 0, 0));
             if (clip == NULL) {
                 kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(i);
                 return false;
             }
+            if (clip->getProducer() == NULL) {
+                emit displayMessage(i18n("Clip not ready"), ErrorMessage);
+                return false;
+            }
             ItemInfo info;
             info.startPos = start;
-            info.cropDuration = clip->duration();
-            info.endPos = info.startPos + info.cropDuration;
+           if (clipData.contains('/')) {
+               // this is a clip zone, set in / out
+               int in = clipData.section('/', 1, 1).toInt();
+               int out = clipData.section('/', 2, 2).toInt();
+               info.cropStart = GenTime(in, m_document->fps());
+               info.cropDuration = GenTime(out - in, m_document->fps());
+           }
+            else {
+               info.cropDuration = clip->duration();
+           }
+           info.endPos = info.startPos + info.cropDuration;
             info.track = track;
             infoList.append(info);
-            start += clip->duration();
+            start += info.cropDuration;
         }
         if (!canBePastedTo(infoList, AVWIDGET)) {
             return true;
@@ -1495,17 +1667,26 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
         m_selectionGroup = new AbstractGroupItem(m_document->fps());
         start = GenTime();
         for (int i = 0; i < ids.size(); ++i) {
-            DocClipBase *clip = m_document->getBaseClip(ids.at(i));
+            QString clipData = ids.at(i);
+            DocClipBase *clip = m_document->getBaseClip(clipData.section('/', 0, 0));
             ItemInfo info;
             info.startPos = start;
-            info.cropDuration = clip->duration();
-            info.endPos = info.startPos + info.cropDuration;
+           if (clipData.contains('/')) {
+               // this is a clip zone, set in / out
+               int in = clipData.section('/', 1, 1).toInt();
+               int out = clipData.section('/', 2, 2).toInt();
+               info.cropStart = GenTime(in, m_document->fps());
+               info.cropDuration = GenTime(out - in, m_document->fps());
+           }
+            else {
+               info.cropDuration = clip->duration();
+           }
+           info.endPos = info.startPos + info.cropDuration;
             info.track = 0;
             start += info.cropDuration;
             offsetList.append(start);
-            ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, false);
-            item->setFlag(QGraphicsItem::ItemIsMovable, false);
-            m_selectionGroup->addToGroup(item);
+            ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth(), false);
+            m_selectionGroup->addItem(item);
             if (!clip->isPlaceHolder()) m_waitingThumbs.append(item);
         }
 
@@ -1528,7 +1709,13 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
 void CustomTrackView::dragEnterEvent(QDragEnterEvent * event)
 {
     if (insertDropClips(event->mimeData(), event->pos())) {
-        event->acceptProposedAction();
+      if (event->source() == this) {
+             event->setDropAction(Qt::MoveAction);
+             event->accept();
+         } else {
+            event->setDropAction(Qt::MoveAction);
+             event->acceptProposedAction();
+        }
     } else QGraphicsView::dragEnterEvent(event);
 }
 
@@ -1555,13 +1742,13 @@ void CustomTrackView::slotRefreshEffects(ClipItem *clip)
 {
     int track = m_document->tracksCount() - clip->track();
     GenTime pos = clip->startPos();
-    if (!m_document->renderer()->mltRemoveEffect(track, pos, "-1", false, false)) {
+    if (!m_document->renderer()->mltRemoveEffect(track, pos, -1, false, false)) {
         emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
         return;
     }
     bool success = true;
     for (int i = 0; i < clip->effectsCount(); i++) {
-        if (!m_document->renderer()->mltAddEffect(track, pos, getEffectArgs(clip->effectAt(i)), false)) success = false;
+        if (!m_document->renderer()->mltAddEffect(track, pos, getEffectArgs(clip->effect(i)), false)) success = false;
     }
     if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
     m_document->renderer()->doRefresh();
@@ -1571,6 +1758,10 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
 {
     if (pos < GenTime()) {
         // Add track effect
+        if (effect.attribute("id") == "speed") {
+            emit displayMessage(i18n("Cannot add speed effect to track"), ErrorMessage);
+            return;
+        }
         clearSelection();
         m_document->addTrackEffect(track - 1, effect);
         m_document->renderer()->mltAddTrackEffect(track, getEffectArgs(effect));
@@ -1586,7 +1777,8 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
                 emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
                 return;
             }
-            double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
+            QLocale locale;
+            double speed = locale.toDouble(EffectsList::parameter(effect, "speed")) / 100.0;
             int strobe = EffectsList::parameter(effect, "strobe").toInt();
             if (strobe == 0) strobe = 1;
             doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, 1.0, strobe, clip->baseClip()->getId());
@@ -1598,6 +1790,7 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
         EffectsParameterList params = clip->addEffect(effect);
         if (!m_document->renderer()->mltAddEffect(track, pos, params))
             emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
+       clip->setSelectedEffect(params.paramValue("kdenlive_ix").toInt());
         if (clip->isSelected()) emit clipItemSelected(clip);
     } else emit displayMessage(i18n("Cannot find clip to add effect"), ErrorMessage);
 }
@@ -1607,7 +1800,7 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
     QString index = effect.attribute("kdenlive_ix");
     if (pos < GenTime()) {
         // Delete track effect
-        if (m_document->renderer()->mltRemoveTrackEffect(track, index, true)) {
+        if (m_document->renderer()->mltRemoveTrackEffect(track, index.toInt(), true)) {
            m_document->removeTrackEffect(track - 1, effect);
        }
        else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
@@ -1622,11 +1815,11 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
             doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId());
             clip->deleteEffect(index);
             emit clipItemSelected(clip);
-            m_document->renderer()->mltRemoveEffect(track, pos, index, true);
+            m_document->renderer()->mltRemoveEffect(track, pos, index.toInt(), true);
             return;
         }
     }
-    if (!m_document->renderer()->mltRemoveEffect(track, pos, index, true)) {
+    if (!m_document->renderer()->mltRemoveEffect(track, pos, index.toInt(), true)) {
         kDebug() << "// ERROR REMOV EFFECT: " << index << ", DISABLE: " << effect.attribute("disable");
         emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
         return;
@@ -1638,48 +1831,56 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
     }
 }
 
-void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group)
+void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group, AbstractClipItem *dropTarget)
 {
     QList<QGraphicsItem *> itemList = group->childItems();
     QUndoCommand *effectCommand = new QUndoCommand();
     QString effectName;
-    QDomNode namenode = effect.elementsByTagName("name").item(0);
-    if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
+    int offset = effect.attribute("clipstart").toInt();
+    QDomElement namenode = effect.firstChildElement("name");
+    if (!namenode.isNull()) effectName = i18n(namenode.text().toUtf8().data());
     else effectName = i18n("effect");
     effectCommand->setText(i18n("Add %1", effectName));
-    int count = 0;
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
-            if (effect.attribute("type") == "audio") {
-                // Don't add audio effects on video clips
-                if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) continue;
-            } else if (effect.hasAttribute("type") == false) {
-                // Don't add video effect on audio clips
-                if (item->isAudioOnly() || item->clipType() == AUDIO) continue;
-            }
-
-            if (effect.attribute("unique", "0") != "0" && item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1) {
-                emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
-                continue;
-            }
-            if (item->isItemLocked()) {
-                continue;
-            }
-            item->initEffect(effect);
-            if (effect.attribute("tag") == "ladspa") {
-                QString ladpsaFile = m_document->getLadspaFile();
-                initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
-                effect.setAttribute("src", ladpsaFile);
-            }
-            new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand);
-            count++;
+            if (effect.tagName() == "effectgroup") {
+               QDomNodeList effectlist = effect.elementsByTagName("effect");
+               for (int j = 0; j < effectlist.count(); j++) {
+                   QDomElement subeffect = effectlist.at(j).toElement();
+                   if (subeffect.hasAttribute("kdenlive_info")) {
+                       // effect is in a group
+                       EffectInfo effectInfo;
+                       effectInfo.fromString(subeffect.attribute("kdenlive_info"));
+                       if (effectInfo.groupIndex < 0) {
+                           // group needs to be appended
+                           effectInfo.groupIndex = item->nextFreeEffectGroupIndex();
+                           subeffect.setAttribute("kdenlive_info", effectInfo.toString());
+                       }
+                   }
+                   processEffect(item, subeffect, offset, effectCommand);
+               }
+           }
+            else {
+               processEffect(item, effect, offset, effectCommand);
+           }
         }
     }
-    if (count > 0) {
+    if (effectCommand->childCount() > 0) {
         m_commandStack->push(effectCommand);
         setDocumentModified();
     } else delete effectCommand;
+    if (dropTarget) {
+       clearSelection(false);
+       m_dragItem = dropTarget;
+       m_dragItem->setSelected(true);
+       emit clipItemSelected(static_cast<ClipItem *>(dropTarget));
+    }
+}
+
+void CustomTrackView::slotAddEffect(ClipItem *clip, QDomElement effect)
+{
+    if (clip) slotAddEffect(effect, clip->startPos(), clip->track());
 }
 
 void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
@@ -1687,9 +1888,15 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
     QList<QGraphicsItem *> itemList;
     QUndoCommand *effectCommand = new QUndoCommand();
     QString effectName;
-    QDomNode namenode = effect.elementsByTagName("name").item(0);
-    if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
-    else effectName = i18n("effect");
+    
+    int offset = effect.attribute("clipstart").toInt();
+    if (effect.tagName() == "effectgroup") {
+       effectName = effect.attribute("name");
+    } else {
+       QDomElement namenode = effect.firstChildElement("name");
+       if (!namenode.isNull()) effectName = i18n(namenode.text().toUtf8().data());
+       else effectName = i18n("effect");
+    }
     effectCommand->setText(i18n("Add %1", effectName));
 
     if (track == -1) itemList = scene()->selectedItems();
@@ -1712,45 +1919,24 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
-            if (effect.attribute("type") == "audio") {
-                // Don't add audio effects on video clips
-                if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
-                    /* do not show error message when item is part of a group as the user probably knows what he does then
-                     * and the message is annoying when working with the split audio feature */
-                    if (!item->parentItem() || item->parentItem() == m_selectionGroup)
-                        emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage);
-                    continue;
-                }
-            } else if (effect.attribute("type") == "video" || !effect.hasAttribute("type")) {
-                // Don't add video effect on audio clips
-                if (item->isAudioOnly() || item->clipType() == AUDIO) {
-                    /* do not show error message when item is part of a group as the user probably knows what he does then
-                     * and the message is annoying when working with the split audio feature */
-                    if (!item->parentItem() || item->parentItem() == m_selectionGroup)
-                        emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage);
-                    continue;
-                }
-            }
-            if (item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1 && effect.attribute("unique", "0") != "0") {
-                emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
-                continue;
-            }
-            if (item->isItemLocked()) {
-                continue;
-            }
-
-            if (effect.attribute("id") == "freeze" && m_cursorPos > item->startPos().frames(m_document->fps()) && m_cursorPos < item->endPos().frames(m_document->fps())) {
-                item->initEffect(effect, m_cursorPos - item->startPos().frames(m_document->fps()));
-            } else {
-                item->initEffect(effect);
-            }
-
-            if (effect.attribute("tag") == "ladspa") {
-                QString ladpsaFile = m_document->getLadspaFile();
-                initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
-                effect.setAttribute("src", ladpsaFile);
-            }
-            new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand);
+           if (effect.tagName() == "effectgroup") {
+               QDomNodeList effectlist = effect.elementsByTagName("effect");
+               for (int j = 0; j < effectlist.count(); j++) {
+                   QDomElement subeffect = effectlist.at(j).toElement();
+                   if (subeffect.hasAttribute("kdenlive_info")) {
+                       // effect is in a group
+                       EffectInfo effectInfo;
+                       effectInfo.fromString(subeffect.attribute("kdenlive_info"));
+                       if (effectInfo.groupIndex < 0) {
+                           // group needs to be appended
+                           effectInfo.groupIndex = item->nextFreeEffectGroupIndex();
+                           subeffect.setAttribute("kdenlive_info", effectInfo.toString());
+                       }
+                   }
+                   processEffect(item, subeffect, offset, effectCommand);
+               }
+           }
+            else processEffect(item, effect, offset, effectCommand);
         }
     }
     if (effectCommand->childCount() > 0) {
@@ -1761,19 +1947,68 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
            for (int i = 0; i < itemList.count(); i++) {
                if (itemList.at(i)->type() == AVWIDGET) {
                    ClipItem *clip = static_cast<ClipItem *>(itemList.at(i));
+                   clip->setSelectedEffect(clip->effectsCount());
                    if (!clip->isSelected()) {
-                       clearSelection();
+                       clearSelection(false);
                        clip->setSelected(true);
+                       m_dragItem = clip;
                    }
-                   clip->setSelectedEffect(clip->effectsCount() - 1);
-                   emit clipItemSelected(clip, clip->effectsCount() - 1);
+                   emit clipItemSelected(clip);
                    break;
                }
            }
        }
+       else {
+           for (int i = 0; i < itemList.count(); i++) {
+               if (itemList.at(i)->type() == AVWIDGET) {
+                   ClipItem *clip = static_cast<ClipItem *>(itemList.at(i));
+                   if (clip->isMainSelectedClip()) {
+                       emit clipItemSelected(clip);
+                       break;
+                   }
+               }
+           }
+       }
     } else delete effectCommand;
 }
 
+void CustomTrackView::processEffect(ClipItem *item, QDomElement effect, int offset, QUndoCommand *effectCommand)
+{
+    if (effect.attribute("type") == "audio") {
+       // Don't add audio effects on video clips
+        if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) {
+           /* do not show error message when item is part of a group as the user probably knows what he does then
+            * and the message is annoying when working with the split audio feature */
+            if (!item->parentItem() || item->parentItem() == m_selectionGroup)
+               emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage);
+            return;
+        }
+    } else if (effect.attribute("type") == "video" || !effect.hasAttribute("type")) {
+       // Don't add video effect on audio clips
+        if (item->isAudioOnly() || item->clipType() == AUDIO) {
+           /* do not show error message when item is part of a group as the user probably knows what he does then
+            * and the message is annoying when working with the split audio feature */
+            if (!item->parentItem() || item->parentItem() == m_selectionGroup)
+               emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage);
+            return;
+        }
+    }
+    if (effect.attribute("unique", "0") != "0" && item->hasEffect(effect.attribute("tag"), effect.attribute("id")) != -1) {
+       emit displayMessage(i18n("Effect already present in clip"), ErrorMessage);
+        return;
+    }
+    if (item->isItemLocked()) {
+       return;
+    }
+
+    if (effect.attribute("id") == "freeze" && m_cursorPos > item->startPos().frames(m_document->fps()) && m_cursorPos < item->endPos().frames(m_document->fps())) {
+       item->initEffect(effect, m_cursorPos - item->startPos().frames(m_document->fps()), offset);
+    } else {
+       item->initEffect(effect, 0, offset);
+    }
+    new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand);
+}
+
 void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement effect, bool affectGroup)
 {
     if (clip == NULL) {
@@ -1788,8 +2023,8 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement ef
         QList<QGraphicsItem *> items = m_selectionGroup->childItems();
         QUndoCommand *delCommand = new QUndoCommand();
         QString effectName;
-        QDomNode namenode = effect.elementsByTagName("name").item(0);
-        if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
+        QDomElement namenode = effect.firstChildElement("name");
+        if (!namenode.isNull()) effectName = i18n(namenode.text().toUtf8().data());
         else effectName = i18n("effect");
         delCommand->setText(i18n("Delete %1", effectName));
 
@@ -1808,13 +2043,16 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement ef
                 ClipItem *item = static_cast <ClipItem *>(items.at(i));
                 int ix = item->hasEffect(effect.attribute("tag"), effect.attribute("id"));
                 if (ix != -1) {
-                    QDomElement eff = item->effectAt(ix);
+                    QDomElement eff = item->effectAtIndex(ix);
                     new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), eff, false, delCommand);
                 }
             }
         }
-        if (delCommand->childCount() > 0) m_commandStack->push(delCommand);
-        else delete delCommand;
+        if (delCommand->childCount() > 0)
+            m_commandStack->push(delCommand);
+        else
+            delete delCommand;
+        setDocumentModified();
         return;
     }
     AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, false);
@@ -1822,28 +2060,27 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement ef
     setDocumentModified();
 }
 
-void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser)
+void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedEffect, bool updateEffectStack)
 {
     if (insertedEffect.isNull()) {
+       kDebug()<<"// Trying to add null effect";
         emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
         return;
     }
+    int ix = insertedEffect.attribute("kdenlive_ix").toInt();
     QDomElement effect = insertedEffect.cloneNode().toElement();
-    //kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix")<<", TRACK: "<<track;
+    //kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix")<<", GAIN: "<<EffectsList::parameter(effect, "gain");
     if (pos < GenTime()) {
         // editing a track effect
         EffectsParameterList effectParams = getEffectArgs(effect);
-        if (effect.attribute("tag") == "ladspa") {
-            // Update the ladspa affect file
-            initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
-        }
         // check if we are trying to reset a keyframe effect
-        if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
-            //clip->initEffect(effect);
+        /*if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
+            clip->initEffect(effect);
             effectParams = getEffectArgs(effect);
-        }
-        if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - track, pos, effectParams))
+        }*/
+        if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - track, pos, effectParams)) {
             emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+       }
         m_document->setTrackEffect(m_document->tracksCount() - track - 1, ix, effect);
         emit updateTrackEffectState(track);
         setDocumentModified();
@@ -1854,107 +2091,183 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
     if (clip) {
         // Special case: speed effect
         if (effect.attribute("id") == "speed") {
-            if (effect.attribute("disable") == "1") doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId());
-            else {
-                double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
+            if (effect.attribute("disable") == "1") {
+                doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId());
+            } else {
+                QLocale locale;
+                double speed = locale.toDouble(EffectsList::parameter(effect, "speed")) / 100.0;
                 int strobe = EffectsList::parameter(effect, "strobe").toInt();
                 if (strobe == 0) strobe = 1;
                 doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, clip->speed(), strobe, clip->baseClip()->getId());
             }
-            clip->setEffectAt(ix, effect);
-            if (ix == clip->selectedEffectIndex()) {
-                clip->setSelectedEffect(ix);
-                if (!triggeredByUser) emit clipItemSelected(clip, ix);
-            }
+            clip->updateEffect(effect);
+           if (updateEffectStack && clip->isSelected())
+               emit clipItemSelected(clip);
+           if (ix == clip->selectedEffectIndex()) {
+               // make sure to update display of clip keyframes
+               clip->setSelectedEffect(ix);
+           }
             return;
         }
 
         EffectsParameterList effectParams = getEffectArgs(effect);
-        if (effect.attribute("tag") == "ladspa") {
-            // Update the ladspa affect file
-            initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
-        }
         // check if we are trying to reset a keyframe effect
         if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
             clip->initEffect(effect);
             effectParams = getEffectArgs(effect);
         }
-        if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams))
-            emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
 
-        clip->setEffectAt(ix, effect);
-        if (ix == clip->selectedEffectIndex()) {
-            clip->setSelectedEffect(ix);
-            if (!triggeredByUser) emit clipItemSelected(clip, ix);
-        }
         if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
             // A fade effect was modified, update the clip
             if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") {
-                int pos = effectParams.paramValue("out").toInt() - effectParams.paramValue("in").toInt();
+                int pos = EffectsList::parameter(effect, "out").toInt() - EffectsList::parameter(effect, "in").toInt();
                 clip->setFadeIn(pos);
             }
             if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
-                int pos = effectParams.paramValue("out").toInt() - effectParams.paramValue("in").toInt();
+                int pos = EffectsList::parameter(effect, "out").toInt() - EffectsList::parameter(effect, "in").toInt();
                 clip->setFadeOut(pos);
             }
         }
+       bool success = m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams);
+
+        if (success) {
+           clip->updateEffect(effect);
+           if (updateEffectStack && clip->isSelected()) {
+               emit clipItemSelected(clip);
+           }
+           if (ix == clip->selectedEffectIndex()) {
+               // make sure to update display of clip keyframes
+               clip->setSelectedEffect(ix);
+           }
+       }
+       else emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
     }
+    else emit displayMessage(i18n("Cannot find clip to update effect"), ErrorMessage);
     setDocumentModified();
 }
 
-void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
+void CustomTrackView::updateEffectState(int track, GenTime pos, QList <int> effectIndexes, bool disable, bool updateEffectStack)
+{
+    if (pos < GenTime()) {
+        // editing a track effect
+        if (!m_document->renderer()->mltEnableEffects(m_document->tracksCount() - track, pos, effectIndexes, disable)) {
+            emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+           return;
+       }
+        m_document->enableTrackEffects(m_document->tracksCount() - track - 1, effectIndexes, disable);
+        emit updateTrackEffectState(track);
+        setDocumentModified();
+        return;
+    }
+    // editing a clip effect
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
+    if (clip) {
+       bool success = m_document->renderer()->mltEnableEffects(m_document->tracksCount() - clip->track(), clip->startPos(), effectIndexes, disable);
+       if (success) {
+           clip->enableEffects(effectIndexes, disable);
+           if (updateEffectStack && clip->isSelected()) {
+               emit clipItemSelected(clip);
+           }
+           if (effectIndexes.contains(clip->selectedEffectIndex())) {
+               // make sure to update display of clip keyframes
+               clip->setSelectedEffect(clip->selectedEffectIndex());
+           }
+       }
+       else emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+    }
+    else emit displayMessage(i18n("Cannot find clip to update effect"), ErrorMessage);
+}
+
+void CustomTrackView::moveEffect(int track, GenTime pos, QList <int> oldPos, QList <int> newPos)
 {
     if (pos < GenTime()) {
         // Moving track effect
-        QDomElement act = m_document->getTrackEffect(m_document->tracksCount() - track - 1, newPos - 1);
-        QDomElement before = m_document->getTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1);
-
-        if (!act.isNull() && !before.isNull()) {
-            m_document->setTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1, act);
-            m_document->setTrackEffect(m_document->tracksCount() - track - 1, newPos - 1, before);
-            m_document->renderer()->mltMoveEffect(m_document->tracksCount() - track, pos, oldPos, newPos);
-            emit showTrackEffects(m_document->tracksCount() - track, m_document->trackInfoAt(m_document->tracksCount() - track - 1));
-        } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
+        int documentTrack = m_document->tracksCount() - track - 1;
+        int max = m_document->getTrackEffects(documentTrack).count();
+       int new_position = newPos.at(0);
+       if (new_position > max) {
+           new_position = max;
+       }
+       int old_position = oldPos.at(0);
+       for (int i = 0; i < newPos.count(); i++) {
+           QDomElement act = m_document->getTrackEffect(documentTrack, new_position);
+           if (old_position > new_position) {
+               // Moving up, we need to adjust index
+               old_position = oldPos.at(i);
+               new_position = newPos.at(i);
+           }
+           QDomElement before = m_document->getTrackEffect(documentTrack, old_position);
+           if (!act.isNull() && !before.isNull()) {
+               m_document->setTrackEffect(documentTrack, new_position, before);
+               m_document->renderer()->mltMoveEffect(m_document->tracksCount() - track, pos, old_position, new_position);
+           } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
+       }
+       emit showTrackEffects(m_document->tracksCount() - track, m_document->trackInfoAt(documentTrack));
         return;
     }
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
-    if (clip && !clip->effectAt(newPos - 1).isNull() && !clip->effectAt(oldPos - 1).isNull()) {
-        QDomElement act = clip->effectAt(newPos - 1);
-        QDomElement before = clip->effectAt(oldPos - 1);
-        clip->setEffectAt(oldPos - 1, act);
-        clip->setEffectAt(newPos - 1, before);
-        // special case: speed effect, which is a pseudo-effect, not appearing in MLT's effects
-        if (act.attribute("id") == "speed") {
-            m_document->renderer()->mltUpdateEffectPosition(track, pos, oldPos, newPos);
-        } else if (before.attribute("id") == "speed") {
-            m_document->renderer()->mltUpdateEffectPosition(track, pos, newPos, oldPos);
-        } else m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
-        emit clipItemSelected(clip, newPos - 1);
+    if (clip) {
+       int new_position = newPos.at(0);
+       if (new_position > clip->effectsCount()) {
+           new_position = clip->effectsCount();
+       }
+       int old_position = oldPos.at(0);
+       for (int i = 0; i < newPos.count(); i++) {
+           QDomElement act = clip->effectAtIndex(new_position);
+           if (old_position > new_position) {
+               // Moving up, we need to adjust index
+               old_position = oldPos.at(i);
+               new_position = newPos.at(i);
+           }
+           QDomElement before = clip->effectAtIndex(old_position);
+           if (act.isNull() || before.isNull()) {
+               emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
+               return;
+           }
+           clip->moveEffect(before, new_position);
+           // special case: speed effect, which is a pseudo-effect, not appearing in MLT's effects
+           if (act.attribute("id") == "speed") {
+               m_document->renderer()->mltUpdateEffectPosition(track, pos, old_position, new_position);
+           } else if (before.attribute("id") == "speed") {
+               m_document->renderer()->mltUpdateEffectPosition(track, pos, new_position, old_position);
+           } else m_document->renderer()->mltMoveEffect(track, pos, old_position, new_position);
+       }
+       clip->setSelectedEffect(newPos.at(0));
+       emit clipItemSelected(clip);
         setDocumentModified();
     } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
 }
 
-void CustomTrackView::slotChangeEffectState(ClipItem *clip, int track, int effectPos, bool disable)
+void CustomTrackView::slotChangeEffectState(ClipItem *clip, int track, QList <int> effectIndexes, bool disable)
 {
-    EditEffectCommand *command;
-    QDomElement effect;
-    if (clip == NULL) effect = m_document->getTrackEffect(track - 1, effectPos);
-    else effect = clip->effectAt(effectPos);
-    QDomElement oldEffect = effect.cloneNode().toElement();
-    effect.setAttribute("disable", (int) disable);
-
-
+    ChangeEffectStateCommand *command;
     if (clip == NULL) {
         // editing track effect
-        command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldEffect, effect, effectPos, true);
+        command = new ChangeEffectStateCommand(this, m_document->tracksCount() - track, GenTime(-1), effectIndexes, disable, false, true);
     } else {
-        command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
+       // Check if we have a speed effect, disabling / enabling it needs a special procedure since it is a pseudoo effect
+       QList <int> speedEffectIndexes;
+       for (int i = 0; i < effectIndexes.count(); i++) {
+           QDomElement effect = clip->effectAtIndex(effectIndexes.at(i));
+           if (effect.attribute("id") == "speed") {
+               // speed effect
+               speedEffectIndexes << effectIndexes.at(i);
+               QDomElement newEffect = effect.cloneNode().toElement();
+               newEffect.setAttribute("disable", (int) disable);
+               EditEffectCommand *editcommand = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, newEffect, effectIndexes.at(i), false, true);
+               m_commandStack->push(editcommand);
+           }
+       }
+       for (int j = 0; j < speedEffectIndexes.count(); j++) {
+           effectIndexes.removeAll(speedEffectIndexes.at(j));
+       }
+        command = new ChangeEffectStateCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effectIndexes, disable, false, true);
     }
     m_commandStack->push(command);
-    setDocumentModified();;
+    setDocumentModified();
 }
 
-void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int track, int currentPos, int newPos)
+void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int track, QList <int> currentPos, int newPos)
 {
     MoveEffectCommand *command;
     if (clip == NULL) {
@@ -1965,20 +2278,20 @@ void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int track, int cu
     setDocumentModified();
 }
 
-void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, int track, QDomElement oldeffect, QDomElement effect, int ix)
+void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, int track, QDomElement oldeffect, QDomElement effect, int ix, bool refreshEffectStack)
 {
     EditEffectCommand *command;
-    if (clip) command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
-    else command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldeffect, effect, ix, true);
+    if (clip) command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, refreshEffectStack, true);
+    else command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldeffect, effect, ix, refreshEffectStack, true);
     m_commandStack->push(command);
 }
 
 void CustomTrackView::slotUpdateClipRegion(ClipItem *clip, int ix, QString region)
 {
-    QDomElement effect = clip->getEffectAt(ix);
+    QDomElement effect = clip->getEffectAtIndex(ix);
     QDomElement oldeffect = effect.cloneNode().toElement();
     effect.setAttribute("region", region);
-    EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true);
+    EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true, true);
     m_commandStack->push(command);
 }
 
@@ -1997,9 +2310,13 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
             return NULL;
         }
 
-        kDebug() << "/////////  CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25);
-
-        if (execute) m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime);
+        if (execute) {
+           if (!m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime)) {
+               // Error cuting clip in playlist
+               m_blockRefresh = false;
+               return NULL;
+           }
+       }
         int cutPos = (int) cutTime.frames(m_document->fps());
         ItemInfo newPos;
         newPos.startPos = cutTime;
@@ -2011,17 +2328,32 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
         bool snap = KdenliveSettings::snaptopoints();
         KdenliveSettings::setSnaptopoints(false);
         ClipItem *dup = item->clone(newPos);
-        // remove unwanted effects (fade in) from 2nd part of cutted clip
+
+        // remove unwanted effects
+        // fade in from 2nd part of the clip
         int ix = dup->hasEffect(QString(), "fadein");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = dup->effectAtIndex(ix);
             dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
         }
         ix = dup->hasEffect(QString(), "fade_from_black");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = dup->effectAtIndex(ix);
             dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
         }
+        // fade out from 1st part of the clip
+        ix = item->hasEffect(QString(), "fadeout");
+        if (ix != -1) {
+            QDomElement oldeffect = item->effectAtIndex(ix);
+            item->deleteEffect(oldeffect.attribute("kdenlive_ix"));
+        }
+        ix = item->hasEffect(QString(), "fade_to_black");
+        if (ix != -1) {
+            QDomElement oldeffect = item->effectAtIndex(ix);
+            item->deleteEffect(oldeffect.attribute("kdenlive_ix"));
+        }
+
+
         item->resizeEnd(cutPos);
         scene()->addItem(dup);
         if (item->checkKeyFrames())
@@ -2029,15 +2361,13 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
         if (dup->checkKeyFrames())
             slotRefreshEffects(dup);
 
-        updatePanZoom(item);
-        updatePanZoom(dup, cutTime - item->startPos());
-
         item->baseClip()->addReference();
         m_document->updateClip(item->baseClip()->getId());
         setDocumentModified();
         KdenliveSettings::setSnaptopoints(snap);
+        if (execute && item->isSelected())
+            emit clipItemSelected(item);
         return dup;
-        //kDebug() << "/////////  CUTTING CLIP RESULT: (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), DUP: (" << dup->startPos().frames(25) << "-" << dup->endPos().frames(25) << ")" << ", CUT: " << cutTime.frames(25);
     } else {
         // uncut clip
 
@@ -2054,33 +2384,46 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo
             return NULL;
         }
 
-        /*kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")";
-        kDebug() << "// UNCUTTING CLIPS: ITEM 2 (" << dup->startPos().frames(25) << "x" << dup->endPos().frames(25) << ")";
-        kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;*/
-        //deleteClip(dup->info());
-
         bool snap = KdenliveSettings::snaptopoints();
         KdenliveSettings::setSnaptopoints(false);
 
-        if (dup->isSelected()) emit clipItemSelected(NULL);
+        // join fade effects again
+        int ix = dup->hasEffect(QString(), "fadeout");
+        if (ix != -1) {
+            QDomElement effect = dup->effectAtIndex(ix);
+            item->addEffect(effect);
+        }
+        ix = dup->hasEffect(QString(), "fade_to_black");
+        if (ix != -1) {
+            QDomElement effect = dup->effectAtIndex(ix);
+            item->addEffect(effect);
+        }
+
+        m_waitingThumbs.removeAll(dup);
+        bool selected = item->isSelected();
+        if (dup->isSelected()) {
+            selected = true;
+            item->setSelected(true);
+            emit clipItemSelected(NULL);
+        }
         dup->baseClip()->removeReference();
         m_document->updateClip(dup->baseClip()->getId());
         scene()->removeItem(dup);
         delete dup;
+        dup = NULL;
 
         ItemInfo clipinfo = item->info();
         clipinfo.track = m_document->tracksCount() - clipinfo.track;
         bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos);
         if (success) {
             item->resizeEnd((int) info.endPos.frames(m_document->fps()));
-
-            updatePanZoom(item);
-
             setDocumentModified();
         } else {
             emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
         }
         KdenliveSettings::setSnaptopoints(snap);
+        if (execute && selected)
+            emit clipItemSelected(item);
         return item;
     }
     //QTimer::singleShot(3000, this, SLOT(slotEnableRefresh()));
@@ -2245,6 +2588,7 @@ void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTr
         kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track;
         return;
     }
+    
     bool force = false;
     if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack"))
         force = true;
@@ -2302,6 +2646,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
     if (m_selectionGroup && m_clipDrag) {
         QList<QGraphicsItem *> items = m_selectionGroup->childItems();
         resetSelectionGroup();
+       m_dragItem = NULL;
         m_scene->clearSelection();
         bool hasVideoClip = false;
         QUndoCommand *addCommand = new QUndoCommand();
@@ -2329,7 +2674,7 @@ void CustomTrackView::dropEvent(QDropEvent * event)
             ItemInfo clipInfo = info;
             clipInfo.track = m_document->tracksCount() - item->track();
 
-            int worked = m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->producer(item->track()), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
+            int worked = m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->getProducer(item->track()), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
             if (worked == -1) {
                 emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage);
                 brokenClips.append(item);
@@ -2377,13 +2722,18 @@ void CustomTrackView::dropEvent(QDropEvent * event)
 
         m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
         if (items.count() > 1) {
-            groupSelectedItems(true);
+            groupSelectedItems(items, true);
         } else if (items.count() == 1) {
             m_dragItem = static_cast <AbstractClipItem *>(items.at(0));
-            emit clipItemSelected((ClipItem*)m_dragItem);
+            emit clipItemSelected((ClipItem*) m_dragItem, false);
         }
+        m_document->renderer()->refreshIfActive();
         event->setDropAction(Qt::MoveAction);
         event->accept();
+
+        /// \todo enable when really working
+//        alignAudio();
+
     } else QGraphicsView::dropEvent(event);
     setFocus();
 }
@@ -2429,6 +2779,7 @@ void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInf
                     }
                 } else if (clip->endPos() <= info.endPos) {
                     new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), clip->info(), clip->effectList(), false, false, false, true, command);
+                    m_waitingThumbs.removeAll(clip);
                     scene()->removeItem(clip);
                     delete clip;
                     clip = NULL;
@@ -2546,13 +2897,14 @@ int CustomTrackView::duration() const
 
 void CustomTrackView::addTrack(TrackInfo type, int ix)
 {
+    QList <TransitionInfo> transitionInfos;
     if (ix == -1 || ix == m_document->tracksCount()) {
         m_document->insertTrack(0, type);
-        m_document->renderer()->mltInsertTrack(1, type.type == VIDEOTRACK);
+        transitionInfos = m_document->renderer()->mltInsertTrack(1, type.type == VIDEOTRACK);
     } else {
         m_document->insertTrack(m_document->tracksCount() - ix, type);
         // insert track in MLT playlist
-        m_document->renderer()->mltInsertTrack(m_document->tracksCount() - ix, type.type == VIDEOTRACK);
+        transitionInfos = m_document->renderer()->mltInsertTrack(m_document->tracksCount() - ix, type.type == VIDEOTRACK);
 
         double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2;
         QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY);
@@ -2563,14 +2915,14 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
         scene()->addItem(m_selectionGroup);
         for (int i = 0; i < selection.count(); i++) {
             if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-                m_selectionGroup->addToGroup(selection.at(i));
-                selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(selection.at(i));
             }
         }
         // Move graphic items
         m_selectionGroup->translate(0, m_tracksHeight);
 
         // adjust track number
+        Mlt::Tractor *tractor = m_document->renderer()->lockService();
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
         for (int i = 0; i < children.count(); i++) {
             if (children.at(i)->type() == GROUPWIDGET) {
@@ -2588,20 +2940,31 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
                 // We add a move clip command so that we get the correct producer for new track number
                 if (clip->clipType() == AV || clip->clipType() == AUDIO) {
                     Mlt::Producer *prod = clip->getProducer(clipinfo.track);
-                    if (m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) {
+                    if (m_document->renderer()->mltUpdateClipProducer(tractor, (int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) {
                         // problem updating clip
                         emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
                     }
                 }
-            } else if (item->type() == TRANSITIONWIDGET) {
+            } /*else if (item->type() == TRANSITIONWIDGET) {
                 Transition *tr = static_cast <Transition *>(item);
                 int track = tr->transitionEndTrack();
                 if (track >= ix) {
                     tr->updateTransitionEndTrack(getPreviousVideoTrack(clipinfo.track));
                 }
-            }
-        }
+            }*/
+        }
+        // Sync transition tracks with MLT playlist
+        Transition *tr;        
+       TransitionInfo info;
+       for (int i = 0; i < transitionInfos.count(); i++) {
+           info = transitionInfos.at(i);
+           tr = getTransitionItem(info);
+           if (tr) tr->setForcedTrack(info.forceTrack, info.a_track);
+           else kDebug()<<"// Cannot update TRANSITION AT: "<<info.b_track<<" / "<<info.startPos.frames(m_document->fps()); 
+       }
+       
         resetSelectionGroup(false);
+        m_document->renderer()->unlockService(tractor);
     }
 
     int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
@@ -2636,13 +2999,13 @@ void CustomTrackView::removeTrack(int ix)
     scene()->addItem(m_selectionGroup);
     for (int i = 0; i < selection.count(); i++) {
         if ((!selection.at(i)->parentItem()) && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
-            m_selectionGroup->addToGroup(selection.at(i));
-            selection.at(i)->setFlag(QGraphicsItem::ItemIsMovable, false);
+            m_selectionGroup->addItem(selection.at(i));
         }
     }
     // Move graphic items
     qreal ydiff = 0 - (int) m_tracksHeight;
     m_selectionGroup->translate(0, ydiff);
+    Mlt::Tractor *tractor = m_document->renderer()->lockService();
 
     // adjust track number
     QList<QGraphicsItem *> children = m_selectionGroup->childItems();
@@ -2658,9 +3021,9 @@ void CustomTrackView::removeTrack(int ix)
             clip->updateItem();
             ItemInfo clipinfo = clip->info();
             // We add a move clip command so that we get the correct producer for new track number
-            if (clip->clipType() == AV || clip->clipType() == AUDIO) {
+            if (clip->clipType() == AV || clip->clipType() == AUDIO || clip->clipType() == PLAYLIST) {
                 Mlt::Producer *prod = clip->getProducer(clipinfo.track);
-                if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) {
+                if (prod == NULL || !m_document->renderer()->mltUpdateClipProducer(tractor, (int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) {
                     emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage);
                 }
             }
@@ -2675,6 +3038,7 @@ void CustomTrackView::removeTrack(int ix)
         }
     }
     resetSelectionGroup(false);
+    m_document->renderer()->unlockService(tractor);
 
     int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22();
     for (int i = 0; i < m_guides.count(); i++) {
@@ -2827,9 +3191,20 @@ void CustomTrackView::slotRemoveSpace()
     int track = 0;
     if (m_menuPosition.isNull()) {
         pos = GenTime(cursorPos(), m_document->fps());
-        bool ok;
-        track = QInputDialog::getInteger(this, i18n("Remove Space"), i18n("Track"), 0, 0, m_document->tracksCount() - 1, 1, &ok);
-        if (!ok) return;
+
+        QPointer<TrackDialog> d = new TrackDialog(m_document, parentWidget());
+        d->comboTracks->setCurrentIndex(m_selectedTrack);
+        d->label->setText(i18n("Track"));
+        d->before_select->setHidden(true);
+        d->setWindowTitle(i18n("Remove Space"));
+        d->video_track->setHidden(true);
+        d->audio_track->setHidden(true);
+        if (d->exec() != QDialog::Accepted) {
+            delete d;
+            return;
+        }
+        track = d->comboTracks->currentIndex();
+        delete d;
     } else {
         pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
         track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight);
@@ -2846,7 +3221,6 @@ void CustomTrackView::slotRemoveSpace()
         return;
     }
     int length = m_document->renderer()->mltGetSpaceLength(pos, m_document->tracksCount() - track, true);
-    //kDebug() << "// GOT LENGT; " << length;
     if (length <= 0) {
         emit displayMessage(i18n("You must be in an empty space to remove space (time: %1, track: %2)", m_document->timecode().getTimecodeFromFrames(mapToScene(m_menuPosition).x()), track), ErrorMessage);
         return;
@@ -2878,6 +3252,38 @@ void CustomTrackView::slotRemoveSpace()
         }
     }
 
+    if (!transitionsToMove.isEmpty()) {
+        // Make sure that by moving the items, we don't get a transition collision
+        // Find first transition
+        ItemInfo info = transitionsToMove.at(0);
+        for (int i = 1; i < transitionsToMove.count(); i++)
+            if (transitionsToMove.at(i).startPos < info.startPos) info = transitionsToMove.at(i);
+
+        // make sure there are no transitions on the way
+        QRectF rect(info.startPos.frames(m_document->fps()) - length, track * m_tracksHeight + m_tracksHeight / 2, length - 1, m_tracksHeight / 2 - 2);
+        items = scene()->items(rect);
+        int transitionCorrection = -1;
+        for (int i = 0; i < items.count(); i++) {
+            if (items.at(i)->type() == TRANSITIONWIDGET) {
+                // There is a transition on the way
+                AbstractClipItem *item = static_cast <AbstractClipItem *>(items.at(i));
+                int transitionEnd = item->endPos().frames(m_document->fps());
+                if (transitionEnd > transitionCorrection) transitionCorrection = transitionEnd;
+            }
+        }
+
+        if (transitionCorrection > 0) {
+            // We need to fix the move length
+            length = info.startPos.frames(m_document->fps()) - transitionCorrection;
+        }
+            
+        // Make sure we don't send transition before 0
+        if (info.startPos.frames(m_document->fps()) < length) {
+            // reduce length to maximum possible
+            length = info.startPos.frames(m_document->fps());
+        }           
+    }
+
     InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, GenTime(-length, m_document->fps()), true);
     updateTrackDuration(track, command);
     m_commandStack->push(command);
@@ -2893,13 +3299,18 @@ void CustomTrackView::slotInsertSpace()
         pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
         track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight) + 1;
     }
-    SpacerDialog d(GenTime(65, m_document->fps()), m_document->timecode(), track, m_document->tracksList(), this);
-    if (d.exec() != QDialog::Accepted) return;
-    GenTime spaceDuration = d.selectedDuration();
-    track = d.selectedTrack();
+    QPointer<SpacerDialog> d = new SpacerDialog(GenTime(65, m_document->fps()),
+                m_document->timecode(), track, m_document->tracksList(), this);
+    if (d->exec() != QDialog::Accepted) {
+        delete d;
+        return;
+    }
+    GenTime spaceDuration = d->selectedDuration();
+    track = d->selectedTrack();
+    delete d;
 
     QList<QGraphicsItem *> items;
-    if (track > 0) {
+    if (track >= 0) {
         if (m_document->isTrackLocked(m_document->tracksCount() - track - 1)) {
             emit displayMessage(i18n("Cannot insert space in a locked track"), ErrorMessage);
             return;
@@ -2943,7 +3354,7 @@ void CustomTrackView::slotInsertSpace()
     }
 }
 
-void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime duration, const GenTime offset)
+void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> transToMove, int track, const GenTime &duration, const GenTime &offset)
 {
     int diff = duration.frames(m_document->fps());
     resetSelectionGroup();
@@ -2965,11 +3376,9 @@ void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> t
             clip = getClipItemAtStart(clipsToMove.at(i).startPos + offset, clipsToMove.at(i).track);
             if (clip) {
                 if (clip->parentItem()) {
-                    m_selectionGroup->addToGroup(clip->parentItem());
-                    clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(clip->parentItem());
                 } else {
-                    m_selectionGroup->addToGroup(clip);
-                    clip->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(clip);
                 }
                 if (trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track) == -1 || clipsToMove.at(i).startPos.frames(m_document->fps()) < trackClipStartList.value(m_document->tracksCount() - clipsToMove.at(i).track))
                     trackClipStartList[m_document->tracksCount() - clipsToMove.at(i).track] = clipsToMove.at(i).startPos.frames(m_document->fps());
@@ -2981,11 +3390,9 @@ void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> t
             transition = getTransitionItemAtStart(transToMove.at(i).startPos + offset, transToMove.at(i).track);
             if (transition) {
                 if (transition->parentItem()) {
-                    m_selectionGroup->addToGroup(transition->parentItem());
-                    transition->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(transition->parentItem());
                 } else {
-                    m_selectionGroup->addToGroup(transition);
-                    transition->setFlag(QGraphicsItem::ItemIsMovable, false);
+                    m_selectionGroup->addItem(transition);
                 }
                 if (trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track) == -1 || transToMove.at(i).startPos.frames(m_document->fps()) < trackTransitionStartList.value(m_document->tracksCount() - transToMove.at(i).track))
                     trackTransitionStartList[m_document->tracksCount() - transToMove.at(i).track] = transToMove.at(i).startPos.frames(m_document->fps());
@@ -3037,18 +3444,33 @@ void CustomTrackView::deleteClip(const QString &clipId)
         delete deleteCommand;
     } else {
         updateTrackDuration(-1, deleteCommand);
+       new RefreshMonitorCommand(this, false, deleteCommand);
         m_commandStack->push(deleteCommand);
     }
+    m_document->renderer()->doRefresh();    
 }
 
-void CustomTrackView::setCursorPos(int pos, bool seek)
+void CustomTrackView::seekCursorPos(int pos)
 {
-    if (pos == m_cursorPos) return;
-    emit cursorMoved((int)(m_cursorPos), (int)(pos));
-    m_cursorPos = pos;
-    if (seek) m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
-    else if (m_autoScroll) checkScrolling();
-    m_cursorLine->setPos(m_cursorPos, 0);
+    m_document->renderer()->seek(qMax(pos, 0));
+    emit updateRuler();
+}
+
+int CustomTrackView::seekPosition() const
+{
+    return m_document->renderer()->requestedSeekPosition;
+}
+
+
+void CustomTrackView::setCursorPos(int pos)
+{
+    if (pos != m_cursorPos) {
+       emit cursorMoved((int)(m_cursorPos), (int)(pos));
+       m_cursorPos = pos;
+       m_cursorLine->setPos(m_cursorPos, 0);
+       if (m_autoScroll) checkScrolling();
+    }
+    else emit updateRuler();
 }
 
 void CustomTrackView::updateCursorPos()
@@ -3063,11 +3485,15 @@ int CustomTrackView::cursorPos()
 
 void CustomTrackView::moveCursorPos(int delta)
 {
-    if (m_cursorPos + delta < 0) delta = 0 - m_cursorPos;
-    emit cursorMoved((int)(m_cursorPos), (int)((m_cursorPos + delta)));
-    m_cursorPos += delta;
-    m_cursorLine->setPos(m_cursorPos, 0);
-    m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps()));
+    int currentPos = m_document->renderer()->requestedSeekPosition;
+    if (currentPos == SEEK_INACTIVE) {
+       currentPos = m_document->renderer()->seekPosition().frames(m_document->fps()) + delta;
+    }
+    else {
+       currentPos += delta;
+    }
+    m_document->renderer()->seek(qMax(0, currentPos));
+    emit updateRuler();
 }
 
 void CustomTrackView::initCursorPos(int pos)
@@ -3086,16 +3512,29 @@ void CustomTrackView::checkScrolling()
 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
 {
     if (m_moveOpMode == SEEK) m_moveOpMode = NONE;
-    QGraphicsView::mouseReleaseEvent(event);
-    setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
-#if QT_VERSION >= 0x040600
-    if (m_dragItem) m_dragItem->setGraphicsEffect(NULL);
+    if (m_operationMode == SCROLLTIMELINE) {
+       m_operationMode = NONE;
+       setDragMode(QGraphicsView::NoDrag);
+       QGraphicsView::mouseReleaseEvent(event);
+       return;
+    }
+    if (!m_controlModifier && m_operationMode != RUBBERSELECTION) {
+       //event->accept();
+       setDragMode(QGraphicsView::NoDrag);
+       if (m_clipDrag) QGraphicsView::mouseReleaseEvent(event);
+    }
+    m_clipDrag = false;
+    //setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
+#if QT_VERSION >= 0x040800
+    if (m_dragItem) {
+       m_dragItem->setGraphicsEffect(NULL);
+    }
 #endif
     if (m_scrollTimer.isActive()) m_scrollTimer.stop();
     if (event->button() == Qt::MidButton) {
         return;
     }
-    setDragMode(QGraphicsView::NoDrag);
+
     if (m_operationMode == MOVEGUIDE) {
         setCursor(Qt::ArrowCursor);
         m_operationMode = NONE;
@@ -3118,6 +3557,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             track = -1;
         } else track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight);
         GenTime timeOffset = GenTime((int)(m_selectionGroup->scenePos().x()), m_document->fps()) - m_selectionGroupInfo.startPos;
+       QList <AbstractGroupItem*> groups;
 
         if (timeOffset != GenTime()) {
             QList<QGraphicsItem *> items = m_selectionGroup->childItems();
@@ -3135,8 +3575,11 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             }
 
             for (int i = 0; i < items.count(); i++) {
-                if (items.at(i)->type() == GROUPWIDGET)
-                    items += items.at(i)->childItems();
+                if (items.at(i)->type() == GROUPWIDGET) {
+                   AbstractGroupItem* group = (AbstractGroupItem*)items.at(i);
+                   if (!groups.contains(group)) groups.append(group);
+                   items += items.at(i)->childItems();
+               }
             }
 
             for (int i = 0; i < items.count(); i++) {
@@ -3161,15 +3604,25 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 updateTrackDuration(track, command);
                 m_commandStack->push(command);
                 if (track != -1) track = m_document->tracksCount() - track;
-                kDebug() << "SPACER TRACK:" << track;
                 m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, timeOffset, GenTime());
                 setDocumentModified();
             }
         }
-        resetSelectionGroup(false);
+        resetSelectionGroup();
+        for (int i = 0; i < groups.count(); i++) {
+           rebuildGroup(groups.at(i));
+       }
+
+       
+        clearSelection();
+       
         m_operationMode = NONE;
     } else if (m_operationMode == RUBBERSELECTION) {
-        //kDebug() << "// END RUBBER SELECT";
+       //event->accept();
+       QGraphicsView::mouseReleaseEvent(event);
+       setDragMode(QGraphicsView::NoDrag);
+       setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
+       if (event->modifiers() != Qt::ControlModifier) m_dragItem = NULL;
         resetSelectionGroup();
         groupSelectedItems();
         m_operationMode = NONE;
@@ -3310,7 +3763,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     KdenliveSettings::setSnaptopoints(false);
                     item->setPos((int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItemInfo.track * m_tracksHeight + 1));
                     KdenliveSettings::setSnaptopoints(snap);
-                    emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(m_dragItemInfo.startPos.frames(m_document->fps()))), ErrorMessage);
+                    emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(info.startPos.frames(m_document->fps()))), ErrorMessage);
                 }
                 setDocumentModified();
             } else if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
@@ -3336,12 +3789,13 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             // Moving several clips. We need to delete them and readd them to new position,
             // or they might overlap each other during the move
             QGraphicsItemGroup *group;
-            if (m_selectionGroup)
+            if (m_selectionGroup) {
                 group = static_cast <QGraphicsItemGroup *>(m_selectionGroup);
-            else
+           }
+            else {
                 group = static_cast <QGraphicsItemGroup *>(m_dragItem->parentItem());
+           }
             QList<QGraphicsItem *> items = group->childItems();
-
             QList<ItemInfo> clipsToMove;
             QList<ItemInfo> transitionsToMove;
 
@@ -3394,11 +3848,12 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
 
                     if (item->type() == AVWIDGET) {
                         ClipItem *clip = static_cast <ClipItem*>(item);
+                        int trackProducer = info.track;
                         info.track = m_document->tracksCount() - info.track;
                         adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup);
-                        m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
+                        m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(trackProducer), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT);
                         for (int i = 0; i < clip->effectsCount(); i++) {
-                            m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
+                            m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effect(i)), false);
                         }
                     } else {
                         Transition *tr = static_cast <Transition*>(item);
@@ -3423,24 +3878,43 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 if (m_selectionGroup) {
                     m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps());
                     m_selectionGroupInfo.track = m_selectionGroup->track();
-
-                    for (int i = 0; i < items.count(); ++i) {
-                        if (items.at(i)->type() == GROUPWIDGET) {
-                            rebuildGroup((AbstractGroupItem*)items.at(i));
-                            items.removeAt(i);
-                            --i;
-                        }
-                    }
-                    for (int i = 0; i < items.count(); ++i) {
-                        if (items.at(i)) {
-                            items.at(i)->setSelected(true);
-                            if (items.at(i)->parentItem())
-                                items.at(i)->parentItem()->setSelected(true);
+                   items = m_selectionGroup->childItems();
+                   resetSelectionGroup(false);
+
+                   QSet <QGraphicsItem*> groupList;
+                   QSet <QGraphicsItem*> itemList;
+                   while (!items.isEmpty()) {
+                       QGraphicsItem *first = items.takeFirst();
+                       if (first->type() == GROUPWIDGET) {
+                           if (first != m_selectionGroup) {
+                               groupList.insert(first);
+                           }
                         }
+                        else if (first->type() == AVWIDGET || first->type() == TRANSITIONWIDGET) {
+                           if (first->parentItem() && first->parentItem()->type() == GROUPWIDGET) {
+                               if (first->parentItem() != m_selectionGroup) {
+                                   groupList.insert(first->parentItem());
+                               }
+                               else itemList.insert(first);
+                           }
+                           else itemList.insert(first);
+                       }
+                   }
+                   foreach(QGraphicsItem *item, groupList) {
+                       itemList.unite(item->childItems().toSet());
+                       rebuildGroup(static_cast <AbstractGroupItem*>(item));
+                   }
+
+                    foreach(QGraphicsItem *item, itemList) {
+                       item->setSelected(true);
+                        if (item->parentItem())
+                            item->parentItem()->setSelected(true);
                     }
-                    groupSelectedItems();
+                    resetSelectionGroup();
+                    groupSelectedItems(itemList.toList());
                 } else {
-                    rebuildGroup((AbstractGroupItem *)group);
+                   AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(group);
+                    rebuildGroup(grp);
                 }
                 setDocumentModified();
             }
@@ -3501,7 +3975,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         int ix = item->hasEffect("volume", "fadein");
         int ix2 = item->hasEffect("", "fade_from_black");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = item->effectAtIndex(ix);
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
@@ -3512,7 +3986,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 EffectsList::setParameter(oldeffect, "in", QString::number(start));
                 EffectsList::setParameter(oldeffect, "out", QString::number(end));
                 slotUpdateClipEffect(item, -1, effect, oldeffect, ix);
-                emit clipItemSelected(item, ix);
+                emit clipItemSelected(item);
             }
         } else if (item->fadeIn() != 0 && ix2 == -1) {
             QDomElement effect;
@@ -3524,7 +3998,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
         }
         if (ix2 != -1) {
-            QDomElement oldeffect = item->effectAt(ix2);
+            QDomElement oldeffect = item->effectAtIndex(ix2);
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
@@ -3535,16 +4009,16 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 EffectsList::setParameter(oldeffect, "in", QString::number(start));
                 EffectsList::setParameter(oldeffect, "out", QString::number(end));
                 slotUpdateClipEffect(item, -1, effect, oldeffect, ix2);
-                emit clipItemSelected(item, ix2);
+                emit clipItemSelected(item);
             }
         }
     } else if (m_operationMode == FADEOUT) {
-        // resize fade in effect
+        // resize fade out effect
         ClipItem * item = static_cast <ClipItem *>(m_dragItem);
         int ix = item->hasEffect("volume", "fadeout");
         int ix2 = item->hasEffect("", "fade_to_black");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix);
+            QDomElement oldeffect = item->effectAtIndex(ix);
             int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
@@ -3556,7 +4030,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 EffectsList::setParameter(oldeffect, "out", QString::number(end));
                 // kDebug()<<"EDIT FADE OUT : "<<start<<"x"<<end;
                 slotUpdateClipEffect(item, -1, effect, oldeffect, ix);
-                emit clipItemSelected(item, ix);
+                emit clipItemSelected(item);
             }
         } else if (item->fadeOut() != 0 && ix2 == -1) {
             QDomElement effect;
@@ -3564,12 +4038,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 // add video fade
                 effect = MainWindow::videoEffects.getEffectByTag("", "fade_to_black").cloneNode().toElement();
             } else effect = MainWindow::audioEffects.getEffectByTag("volume", "fadeout").cloneNode().toElement();
-            EffectsList::setParameter(effect, "in", QString::number(item->fadeOut()));
-            EffectsList::setParameter(effect, "out", QString::number(0));
+            int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
+            int start = end-item->fadeOut();
+            EffectsList::setParameter(effect, "in", QString::number(start));
+            EffectsList::setParameter(effect, "out", QString::number(end));
             slotAddEffect(effect, m_dragItem->startPos(), m_dragItem->track());
         }
         if (ix2 != -1) {
-            QDomElement oldeffect = item->effectAt(ix2);
+            QDomElement oldeffect = item->effectAtIndex(ix2);
             int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
@@ -3581,7 +4057,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 EffectsList::setParameter(oldeffect, "out", QString::number(end));
                 // kDebug()<<"EDIT FADE OUT : "<<start<<"x"<<end;
                 slotUpdateClipEffect(item, -1, effect, oldeffect, ix2);
-                emit clipItemSelected(item, ix2);
+                emit clipItemSelected(item);
             }
         }
     } else if (m_operationMode == KEYFRAME) {
@@ -3599,20 +4075,20 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
 
         if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end && item->keyFrameNumber() > 1) {
             //delete keyframe
-            item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), -1, 0);
+            item->movedKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), item->selectedKeyFramePos(), -1, 0);
         } else {
-            item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), item->editedKeyFramePos(), item->editedKeyFrameValue());
+            item->movedKeyframe(item->getEffectAtIndex(item->selectedEffectIndex()), item->selectedKeyFramePos(), item->editedKeyFramePos(), item->editedKeyFrameValue());
         }
 
         QDomElement newEffect = item->selectedEffect().cloneNode().toElement();
         //item->updateKeyframeEffect();
         //QString next = item->keyframes(item->selectedEffectIndex());
         //EditKeyFrameCommand *command = new EditKeyFrameCommand(this, item->track(), item->startPos(), item->selectedEffectIndex(), previous, next, false);
-        EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false);
+        EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), oldEffect, newEffect, item->selectedEffectIndex(), false, false);
 
         m_commandStack->push(command);
-        updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect(), item->selectedEffectIndex());
-        emit clipItemSelected(item, item->selectedEffectIndex());
+        updateEffect(m_document->tracksCount() - item->track(), item->startPos(), item->selectedEffect());
+        emit clipItemSelected(item);
     }
     if (m_dragItem && m_dragItem->type() == TRANSITIONWIDGET && m_dragItem->isSelected()) {
         // A transition is selected
@@ -3634,11 +4110,18 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
 void CustomTrackView::deleteClip(ItemInfo info, bool refresh)
 {
     ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
-
+    m_ct++;
+    if (!item) kDebug()<<"// PROBLEM FINDING CLIP ITEM TO REMOVVE!!!!!!!!!";
+    else kDebug()<<"// deleting CLIP: "<<info.startPos.frames(m_document->fps())<<", "<<item->baseClip()->fileURL();
+    //m_document->renderer()->saveSceneList(QString("/tmp/error%1.mlt").arg(m_ct), QDomElement());
     if (!item || m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, info.startPos) == false) {
         emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(info.startPos.frames(m_document->fps())), info.track), ErrorMessage);
+        kDebug()<<"CANNOT REMOVE: "<<info.startPos.frames(m_document->fps())<<", TK: "<<info.track;
+        //m_document->renderer()->saveSceneList(QString("/tmp/error%1.mlt").arg(m_ct), QDomElement());
         return;
     }
+    m_waitingThumbs.removeAll(item);
+    item->stopThumbs();
     if (item->isSelected()) emit clipItemSelected(NULL);
     item->baseClip()->removeReference();
     m_document->updateClip(item->baseClip()->getId());
@@ -3652,8 +4135,9 @@ void CustomTrackView::deleteClip(ItemInfo info, bool refresh)
             delete tr;
         }
     }*/
-    m_waitingThumbs.removeAll(item);
+
     if (m_dragItem == item) m_dragItem = NULL;
+
 #if QT_VERSION >= 0x040600
     // animate item deletion
     item->closeAnimation();
@@ -3684,7 +4168,6 @@ void CustomTrackView::deleteSelectedClips()
     scene()->clearSelection();
     QUndoCommand *deleteSelected = new QUndoCommand();
 
-    bool resetGroup = false;
     int groupCount = 0;
     int clipCount = 0;
     int transitionCount = 0;
@@ -3695,7 +4178,6 @@ void CustomTrackView::deleteSelectedClips()
             QList<QGraphicsItem *> children = itemList.at(i)->childItems();
             QList <ItemInfo> clipInfos;
             QList <ItemInfo> transitionInfos;
-            GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
             for (int j = 0; j < children.count(); j++) {
                 if (children.at(j)->type() == AVWIDGET) {
                     AbstractClipItem *clip = static_cast <AbstractClipItem *>(children.at(j));
@@ -3721,7 +4203,6 @@ void CustomTrackView::deleteSelectedClips()
         if (itemList.at(i)->type() == AVWIDGET) {
             clipCount++;
             ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
-            if (item->parentItem()) resetGroup = true;
             //kDebug()<<"// DELETE CLP AT: "<<item->info().startPos.frames(25);
             new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteSelected);
             emit clipItemSelected(NULL);
@@ -3729,7 +4210,6 @@ void CustomTrackView::deleteSelectedClips()
             transitionCount++;
             Transition *item = static_cast <Transition *>(itemList.at(i));
             //kDebug()<<"// DELETE TRANS AT: "<<item->info().startPos.frames(25);
-            if (item->parentItem()) resetGroup = true;
             new AddTransitionCommand(this, item->info(), item->transitionEndTrack(), item->toXML(), true, true, deleteSelected);
             emit transitionItemSelected(NULL);
         }
@@ -3742,41 +4222,15 @@ void CustomTrackView::deleteSelectedClips()
         deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount));
     else deleteSelected->setText(i18n("Delete selected items"));
     updateTrackDuration(-1, deleteSelected);
+    new RefreshMonitorCommand(this, false, deleteSelected);
     m_commandStack->push(deleteSelected);
+    m_document->renderer()->doRefresh();
 }
 
-void CustomTrackView::changeClipSpeed()
-{
-    QList<QGraphicsItem *> itemList = scene()->selectedItems();
-    if (itemList.count() == 0) {
-        emit displayMessage(i18n("Select clip to change speed"), ErrorMessage);
-        return;
-    }
-    QUndoCommand *changeSelected = new QUndoCommand();
-    changeSelected->setText("Edit clip speed");
-    int count = 0;
-    int percent = -1;
-    bool ok;
-    for (int i = 0; i < itemList.count(); i++) {
-        if (itemList.at(i)->type() == AVWIDGET) {
-            ClipItem *item = static_cast <ClipItem *>(itemList.at(i));
-            ItemInfo info = item->info();
-            if (percent == -1) percent = QInputDialog::getInteger(this, i18n("Edit Clip Speed"), i18n("New speed (percents)"), item->speed() * 100, 1, 10000, 1, &ok);
-            if (!ok) break;
-            double speed = (double) percent / 100.0;
-            if (item->speed() != speed && (item->clipType() == VIDEO || item->clipType() == AV)) {
-                count++;
-                //new ChangeSpeedCommand(this, info, item->speed(), speed, item->clipProducer(), changeSelected);
-            }
-        }
-    }
-    if (count > 0) m_commandStack->push(changeSelected);
-    else delete changeSelected;
-}
 
 void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id)
 {
-    Q_UNUSED(id);
+    Q_UNUSED(id)
     //DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
 
     ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
@@ -3910,7 +4364,6 @@ void CustomTrackView::groupClips(bool group)
     QList<QGraphicsItem *> itemList = scene()->selectedItems();
     QList <ItemInfo> clipInfos;
     QList <ItemInfo> transitionInfos;
-    GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
 
     // Expand groups
     int max = itemList.count();
@@ -3963,22 +4416,22 @@ void CustomTrackView::doGroupClips(QList <ItemInfo> clipInfos, QList <ItemInfo>
         setDocumentModified();
         return;
     }
-
-    QList <QGraphicsItemGroup *> groups;
+    QList <QGraphicsItem *>list;
     for (int i = 0; i < clipInfos.count(); i++) {
         ClipItem *clip = getClipItemAt(clipInfos.at(i).startPos, clipInfos.at(i).track);
         if (clip) {
-            clip->setSelected(true);
+           list.append(clip);
+            //clip->setSelected(true);
         }
     }
     for (int i = 0; i < transitionInfos.count(); i++) {
         Transition *clip = getTransitionItemAt(transitionInfos.at(i).startPos, transitionInfos.at(i).track);
         if (clip) {
-            clip->setSelected(true);
+           list.append(clip);
+            //clip->setSelected(true);
         }
     }
-
-    groupSelectedItems(false, true);
+    groupSelectedItems(list, false, true, true);
     setDocumentModified();
 }
 
@@ -3990,18 +4443,19 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
         return;
     }
 
-    if (baseclip->producer() == NULL) {
+    if (baseclip->getProducer() == NULL) {
         // If the clip has no producer, we must wait until it is created...
         m_mutex.lock();
         emit displayMessage(i18n("Waiting for clip..."), InformationMessage);
         emit forceClipProcessing(clipId);
         qApp->processEvents();
-        for (int i = 0; i < 3; i++) {
-            if (baseclip->producer() == NULL) {
-                m_producerNotReady.wait(&m_mutex, 500 + 500 * i);
+        for (int i = 0; i < 10; i++) {
+            if (baseclip->getProducer() == NULL) {
+                qApp->processEvents();
+                m_producerNotReady.wait(&m_mutex, 200);
             } else break;
         }
-        if (baseclip->producer() == NULL) {
+        if (baseclip->getProducer() == NULL) {
             emit displayMessage(i18n("Cannot insert clip..."), ErrorMessage);
             m_mutex.unlock();
             return;
@@ -4010,12 +4464,13 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
         m_mutex.unlock();
     }
 
-    ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble(), xml.attribute("strobe", "1").toInt());
+    ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble(), xml.attribute("strobe", "1").toInt(), getFrameWidth());
     item->setEffectList(effects);
     if (xml.hasAttribute("audio_only")) item->setAudioOnly(true);
     else if (xml.hasAttribute("video_only")) item->setVideoOnly(true);
     scene()->addItem(item);
 
+    int producerTrack = info.track;
     int tracknumber = m_document->tracksCount() - info.track - 1;
     bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
     if (isLocked) item->setItemLocked(true);
@@ -4023,9 +4478,9 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
     baseclip->addReference();
     m_document->updateClip(baseclip->getId());
     info.track = m_document->tracksCount() - info.track;
-    m_document->renderer()->mltInsertClip(info, xml, item->getProducer(info.track), overwrite, push);
+    m_document->renderer()->mltInsertClip(info, xml, item->getProducer(producerTrack), overwrite, push);
     for (int i = 0; i < item->effectsCount(); i++) {
-        m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effectAt(i)), false);
+        m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effect(i)), false);
     }
     setDocumentModified();
     if (refresh)
@@ -4037,22 +4492,34 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
 
 void CustomTrackView::slotUpdateClip(const QString &clipId, bool reload)
 {
+    QMutexLocker locker(&m_mutex);
     QList<QGraphicsItem *> list = scene()->items();
+    QList <ClipItem *>clipList;
     ClipItem *clip = NULL;
+    DocClipBase *baseClip = NULL;
+    Mlt::Tractor *tractor = m_document->renderer()->lockService();
     for (int i = 0; i < list.size(); ++i) {
         if (list.at(i)->type() == AVWIDGET) {
             clip = static_cast <ClipItem *>(list.at(i));
             if (clip->clipProducer() == clipId) {
+                if (baseClip == NULL) {
+                    baseClip = clip->baseClip();
+                }
                 ItemInfo info = clip->info();
-                info.track = m_document->tracksCount() - clip->track();
-                if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer())) {
+                Mlt::Producer *prod = NULL;
+                if (clip->isAudioOnly()) prod = baseClip->audioProducer(info.track);
+                else if (clip->isVideoOnly()) prod = baseClip->videoProducer(info.track);
+                else prod = baseClip->getProducer(info.track);
+                if (reload && !m_document->renderer()->mltUpdateClip(tractor, info, clip->xml(), prod)) {
                     emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
                 }
-                clip->refreshClip(true);
-                clip->update();
+                else clipList.append(clip);
             }
         }
     }
+    for (int i = 0; i < clipList.count(); i++)
+        clipList.at(i)->refreshClip(true, true);
+    m_document->renderer()->unlockService(tractor);
 }
 
 ClipItem *CustomTrackView::getClipItemAtEnd(GenTime pos, int track)
@@ -4106,9 +4573,17 @@ ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track)
     return getClipItemAt((int) pos.frames(m_document->fps()), track);
 }
 
+
+Transition *CustomTrackView::getTransitionItem(TransitionInfo info)
+{
+    int pos = info.startPos.frames(m_document->fps());
+    int track = m_document->tracksCount() - info.b_track;
+    return getTransitionItemAt(pos, track);
+}
+
 Transition *CustomTrackView::getTransitionItemAt(int pos, int track)
 {
-    const QPointF p(pos, (track + 1) * m_tracksHeight);
+    const QPointF p(pos, track * m_tracksHeight + Transition::itemOffset() + 1);
     QList<QGraphicsItem *> list = scene()->items(p);
     Transition *clip = NULL;
     for (int i = 0; i < list.size(); i++) {
@@ -4129,7 +4604,7 @@ Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track)
 Transition *CustomTrackView::getTransitionItemAtEnd(GenTime pos, int track)
 {
     int framepos = (int)(pos.frames(m_document->fps()));
-    const QPointF p(framepos - 1, (track + 1) * m_tracksHeight);
+    const QPointF p(framepos - 1, track * m_tracksHeight + Transition::itemOffset() + 1);
     QList<QGraphicsItem *> list = scene()->items(p);
     Transition *clip = NULL;
     for (int i = 0; i < list.size(); i++) {
@@ -4145,7 +4620,7 @@ Transition *CustomTrackView::getTransitionItemAtEnd(GenTime pos, int track)
 
 Transition *CustomTrackView::getTransitionItemAtStart(GenTime pos, int track)
 {
-    const QPointF p(pos.frames(m_document->fps()), (track + 1) * m_tracksHeight);
+    const QPointF p(pos.frames(m_document->fps()), track * m_tracksHeight + Transition::itemOffset() + 1);
     QList<QGraphicsItem *> list = scene()->items(p);
     Transition *clip = NULL;
     for (int i = 0; i < list.size(); ++i) {
@@ -4159,18 +4634,26 @@ 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);
+#ifdef DEBUG
+    qDebug() << "Moving item " << (long)item << " from .. to:";
+    qDebug() << item->info();
+    qDebug() << start;
+    qDebug() << end;
+#endif
+    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);
@@ -4200,9 +4683,19 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool re
         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();
+#ifdef DEBUG
+        qDebug() << "Actual end position updated:" << *out_actualEnd;
+#endif
+    }
+#ifdef DEBUG
+    qDebug() << item->info();
+#endif
+    return success;
 }
 
-void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime offset, const int trackOffset, bool reverseMove)
+void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> startTransition, const GenTime &offset, const int trackOffset, bool reverseMove)
 {
     // Group Items
     resetSelectionGroup();
@@ -4221,11 +4714,9 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         if (clip) {
             clip->setItemLocked(false);
             if (clip->parentItem()) {
-                m_selectionGroup->addToGroup(clip->parentItem());
-                clip->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(clip->parentItem());
             } else {
-                m_selectionGroup->addToGroup(clip);
-                clip->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(clip);
             }
             m_document->renderer()->mltRemoveClip(m_document->tracksCount() - startClip.at(i).track, startClip.at(i).startPos);
         } else kDebug() << "//MISSING CLIP AT: " << startClip.at(i).startPos.frames(25);
@@ -4239,11 +4730,9 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         if (tr) {
             tr->setItemLocked(false);
             if (tr->parentItem()) {
-                m_selectionGroup->addToGroup(tr->parentItem());
-                tr->parentItem()->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(tr->parentItem());
             } else {
-                m_selectionGroup->addToGroup(tr);
-                tr->setFlag(QGraphicsItem::ItemIsMovable, false);
+                m_selectionGroup->addItem(tr);
             }
             m_document->renderer()->mltDeleteTransition(tr->transitionTag(), tr->transitionEndTrack(), m_document->tracksCount() - startTransition.at(i).track, startTransition.at(i).startPos, startTransition.at(i).endPos, tr->toXML());
         } else kDebug() << "//MISSING TRANSITION AT: " << startTransition.at(i).startPos.frames(25);
@@ -4258,6 +4747,7 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         //m_selectionGroup->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
 
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
+       QList <AbstractGroupItem*> groupList;
         // Expand groups
         int max = children.count();
         for (int i = 0; i < max; i++) {
@@ -4267,6 +4757,8 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
                 //grp->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
                 /*m_document->clipManager()->removeGroup(grp);
                 m_scene->destroyItemGroup(grp);*/
+               AbstractGroupItem *group = (AbstractGroupItem*) children.at(i);
+               if (!groupList.contains(group)) groupList.append(group);
                 children.removeAll(children.at(i));
                 i--;
             }
@@ -4287,10 +4779,11 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
 
             if (item->type() == AVWIDGET) {
                 ClipItem *clip = static_cast <ClipItem*>(item);
+                int trackProducer = info.track;
                 info.track = m_document->tracksCount() - info.track;
-                m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track));
+                m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(trackProducer));
                 for (int i = 0; i < clip->effectsCount(); i++) {
-                    m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false);
+                    m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effect(i)), false);
                 }
             } else if (item->type() == TRANSITIONWIDGET) {
                 Transition *tr = static_cast <Transition*>(item);
@@ -4307,11 +4800,10 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         }
 
         resetSelectionGroup(false);
+       for (int i = 0; i < groupList.count(); i++) {
+           rebuildGroup(groupList.at(i));
+       }
 
-        for (int i = 0; i < children.count(); i++) {
-            if (children.at(i)->parentItem())
-                rebuildGroup((AbstractGroupItem*)children.at(i)->parentItem());
-        }
         clearSelection();
 
         KdenliveSettings::setSnaptopoints(snap);
@@ -4319,7 +4811,7 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
     } else kDebug() << "///////// WARNING; NO GROUP TO MOVE";
 }
 
-void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, bool m_refresh)
+void CustomTrackView::moveTransition(const ItemInfo &start, const ItemInfo &end, bool refresh)
 {
     Transition *item = getTransitionItemAt(start.startPos, start.track);
     if (!item) {
@@ -4363,11 +4855,11 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, b
         }
         emit transitionItemSelected(item, getPreviousVideoTrack(item->track()), p);
     }
-    if (m_refresh) m_document->renderer()->doRefresh();
+    if (refresh) m_document->renderer()->doRefresh();
     setDocumentModified();
 }
 
-void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry)
+void CustomTrackView::resizeClip(const ItemInfo &start, const ItemInfo &end, bool dontWorry)
 {
     bool resizeClipStart = (start.startPos != end.startPos);
     ClipItem *item = getClipItemAtStart(start.startPos, start.track);
@@ -4389,25 +4881,24 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool
         ItemInfo clipinfo = item->info();
         clipinfo.track = m_document->tracksCount() - clipinfo.track;
         bool success = m_document->renderer()->mltResizeClipStart(clipinfo, end.startPos - clipinfo.startPos);
-        if (success) {
-            kDebug() << "RESIZE CLP STRAT TO:" << end.startPos.frames(m_document->fps()) << ", OLD ST: " << start.startPos.frames(25);
+        if (success)
             item->resizeStart((int) end.startPos.frames(m_document->fps()));
-            updatePositionEffects(item, clipinfo);
-        } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
+        else
+            emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
     } else {
         ItemInfo clipinfo = item->info();
         clipinfo.track = m_document->tracksCount() - clipinfo.track;
         bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, end.endPos - clipinfo.startPos);
-        if (success) {
+        if (success)
             item->resizeEnd((int) end.endPos.frames(m_document->fps()));
-            updatePositionEffects(item, clipinfo);
-        } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
+        else
+            emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
     }
     if (!resizeClipStart && end.cropStart != start.cropStart) {
         kDebug() << "// RESIZE CROP, DIFF: " << (end.cropStart - start.cropStart).frames(25);
         ItemInfo clipinfo = end;
         clipinfo.track = m_document->tracksCount() - end.track;
-        bool success = m_document->renderer()->mltResizeClipCrop(clipinfo, end.cropStart - start.cropStart);
+        bool success = m_document->renderer()->mltResizeClipCrop(clipinfo, end.cropStart);
         if (success) {
             item->setCropStart(end.cropStart);
             item->resetThumbs(true);
@@ -4473,44 +4964,15 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol
                     new MoveTransitionCommand(this, trInfo, newTrInfo, true, command);
             }
 
-            /*
-                TODO: cleanup the effect update process
-             */
-            ClipItem *clip = static_cast < ClipItem * >(item);
-
-            updatePositionEffects(clip, oldInfo);
-
-            // check keyframes
-            QDomDocument doc;
-            QDomElement root = doc.createElement("list");
-            doc.appendChild(root);
-            QList <int> indexes;
-            for (int i = 0; i < clip->effectsCount(); i++) {
-                QDomElement effect = clip->effectAt(i);
-                if (EffectsList::hasKeyFrames(effect)) {
-                    doc.appendChild(doc.importNode(effect, true));
-                    indexes.append(i);
-                }
-            }
-
-            if (clip->checkEffectsKeyframesPos(oldInfo.cropStart.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), true)) {
-                // Keyframes were modified, updateClip
-                QDomNodeList effs = doc.elementsByTagName("effect");
-                // Hack:
-                // Since we must always resize clip before updating the keyframes, we
-                // put a resize command before & after checking keyframes so that
-                // we are sure the resize is performed before whenever we do or undo the action
-
-                new ResizeClipCommand(this, oldInfo, info, false, true, command);
-                for (int i = 0; i < indexes.count(); i++) {
-                    new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, command);
-                    updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i));
-                }
-                new ResizeClipCommand(this, oldInfo, info, false, true, command);
-                emit clipItemSelected(clip);
-            } else {
-                new ResizeClipCommand(this, oldInfo, info, false, false, command);
-            }
+            ClipItem *clip = static_cast < ClipItem * >(item);
+
+            // Hack:
+            // Since we must always resize clip before updating the keyframes, we
+            // put a resize command before & after checking keyframes so that
+            // we are sure the resize is performed before whenever we do or undo the action
+            new ResizeClipCommand(this, oldInfo, info, false, true, command);
+            adjustEffects(clip, oldInfo, command);
+            new ResizeClipCommand(this, oldInfo, info, false, true, command);
         } else {
             KdenliveSettings::setSnaptopoints(false);
             item->resizeStart((int) oldInfo.startPos.frames(m_document->fps()));
@@ -4561,7 +5023,6 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
         hasParentCommand = true;
     } else {
         command = new QUndoCommand();
-        command->setText(i18n("Resize clip end"));
     }
 
     // do this here, too, because otherwise undo won't update the group
@@ -4570,6 +5031,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
 
     ItemInfo info = item->info();
     if (item->type() == AVWIDGET) {
+        if (!hasParentCommand) command->setText(i18n("Resize clip end"));
         ItemInfo resizeinfo = info;
         resizeinfo.track = m_document->tracksCount() - resizeinfo.track;
         bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.cropDuration);
@@ -4598,39 +5060,13 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
 
             ClipItem *clip = static_cast < ClipItem * >(item);
 
-            updatePositionEffects(clip, oldInfo);
-
-            // check keyframes
-            QDomDocument doc;
-            QDomElement root = doc.createElement("list");
-            doc.appendChild(root);
-            QList <int> indexes;
-            for (int i = 0; i < clip->effectsCount(); i++) {
-                QDomElement effect = clip->effectAt(i);
-                if (EffectsList::hasKeyFrames(effect)) {
-                    doc.appendChild(doc.importNode(effect, true));
-                    indexes.append(i);
-                }
-            }
-
-            if (clip->checkEffectsKeyframesPos((oldInfo.cropStart + oldInfo.endPos - oldInfo.startPos).frames(m_document->fps()) - 1, (clip->cropStart() + clip->cropDuration()).frames(m_document->fps()) - 1, false)) {
-                // Keyframes were modified, updateClip
-                QDomNodeList effs = doc.elementsByTagName("effect");
-                // Hack:
-                // Since we must always resize clip before updating the keyframes, we
-                // put a resize command before & after checking keyframes so that
-                // we are sure the resize is performed before whenever we do or undo the action
-
-                new ResizeClipCommand(this, oldInfo, info, false, true, command);
-                for (int i = 0; i < indexes.count(); i++) {
-                    new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, command);
-                    updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i));
-                }
-                new ResizeClipCommand(this, oldInfo, info, false, true, command);
-                emit clipItemSelected(clip);
-            } else {
-                new ResizeClipCommand(this, oldInfo, info, false, false, command);
-            }
+            // Hack:
+            // Since we must always resize clip before updating the keyframes, we
+            // put a resize command before & after checking keyframes so that
+            // we are sure the resize is performed before whenever we do or undo the action
+            new ResizeClipCommand(this, oldInfo, info, false, true, command);
+            adjustEffects(clip, oldInfo, command);
+            new ResizeClipCommand(this, oldInfo, info, false, true, command);
         } else {
             KdenliveSettings::setSnaptopoints(false);
             item->resizeEnd((int) oldInfo.endPos.frames(m_document->fps()));
@@ -4638,6 +5074,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
             emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
         }
     } else if (item->type() == TRANSITIONWIDGET) {
+        if (!hasParentCommand) command->setText(i18n("Resize transition end"));
         Transition *transition = static_cast <Transition *>(item);
         if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - oldInfo.track), (int)(m_document->tracksCount() - oldInfo.track), transition->transitionEndTrack(), oldInfo.startPos, oldInfo.endPos, info.startPos, info.endPos)) {
             // Cannot resize transition
@@ -4646,9 +5083,14 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
             KdenliveSettings::setSnaptopoints(true);
             emit displayMessage(i18n("Cannot resize transition"), ErrorMessage);
         } else {
-            MoveTransitionCommand *moveCommand = new MoveTransitionCommand(this, oldInfo, info, false, command);
-            if (command == NULL)
-                m_commandStack->push(moveCommand);
+            // Check transition keyframes
+            QDomElement old = transition->toXML();
+            if (transition->updateKeyframes()) {
+                QDomElement xml = transition->toXML();
+                m_document->renderer()->mltUpdateTransition(xml.attribute("tag"), xml.attribute("tag"), xml.attribute("transition_btrack").toInt(), m_document->tracksCount() - xml.attribute("transition_atrack").toInt(), transition->startPos(), transition->endPos(), xml);
+                new EditTransitionCommand(this, transition->track(), transition->startPos(), old, xml, false, command);
+            }
+            new MoveTransitionCommand(this, oldInfo, info, false, command);
         }
     }
     if (item->parentItem() && item->parentItem() != m_selectionGroup)
@@ -4660,14 +5102,14 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI
     }
 }
 
-void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
+void CustomTrackView::updatePositionEffects(ClipItem* item, ItemInfo info, bool standalone)
 {
     int end = item->fadeIn();
     if (end != 0) {
         // there is a fade in effect
         int effectPos = item->hasEffect("volume", "fadein");
         if (effectPos != -1) {
-            QDomElement oldeffect = item->effectAt(effectPos);
+            QDomElement effect = item->getEffectAtIndex(effectPos);
             int start = item->cropStart().frames(m_document->fps());
             int max = item->cropDuration().frames(m_document->fps());
             if (end > max) {
@@ -4676,16 +5118,19 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
                 end = item->fadeIn();
             }
             end += start;
-            EffectsList::setParameter(oldeffect, "in", QString::number(start));
-            EffectsList::setParameter(oldeffect, "out", QString::number(end));
-            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
-                emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
-            // if fade effect is displayed, update the effect edit widget with new clip duration
-            if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
+            EffectsList::setParameter(effect, "in", QString::number(start));
+            EffectsList::setParameter(effect, "out", QString::number(end));
+            if (standalone) {
+                if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(effect)))
+                    emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+                // if fade effect is displayed, update the effect edit widget with new clip duration
+                if (item->isSelected() && effectPos == item->selectedEffectIndex())
+                    emit clipItemSelected(item);
+            }
         }
         effectPos = item->hasEffect("brightness", "fade_from_black");
         if (effectPos != -1) {
-            QDomElement oldeffect = item->effectAt(effectPos);
+            QDomElement effect = item->getEffectAtIndex(effectPos);
             int start = item->cropStart().frames(m_document->fps());
             int max = item->cropDuration().frames(m_document->fps());
             if (end > max) {
@@ -4694,20 +5139,24 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
                 end = item->fadeIn();
             }
             end += start;
-            EffectsList::setParameter(oldeffect, "in", QString::number(start));
-            EffectsList::setParameter(oldeffect, "out", QString::number(end));
-            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
-                emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
-            // if fade effect is displayed, update the effect edit widget with new clip duration
-            if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
+            EffectsList::setParameter(effect, "in", QString::number(start));
+            EffectsList::setParameter(effect, "out", QString::number(end));
+            if (standalone) {
+                if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(effect)))
+                    emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+                // if fade effect is displayed, update the effect edit widget with new clip duration
+                if (item->isSelected() && effectPos == item->selectedEffectIndex())
+                    emit clipItemSelected(item);
+            }
         }
     }
+
     int start = item->fadeOut();
     if (start != 0) {
         // there is a fade out effect
         int effectPos = item->hasEffect("volume", "fadeout");
         if (effectPos != -1) {
-            QDomElement oldeffect = item->effectAt(effectPos);
+            QDomElement effect = item->getEffectAtIndex(effectPos);
             int max = item->cropDuration().frames(m_document->fps());
             int end = max + item->cropStart().frames(m_document->fps());
             if (start > max) {
@@ -4716,16 +5165,19 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
                 start = item->fadeOut();
             }
             start = end - start;
-            EffectsList::setParameter(oldeffect, "in", QString::number(start));
-            EffectsList::setParameter(oldeffect, "out", QString::number(end));
-            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
-                emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
-            // if fade effect is displayed, update the effect edit widget with new clip duration
-            if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
+            EffectsList::setParameter(effect, "in", QString::number(start));
+            EffectsList::setParameter(effect, "out", QString::number(end));
+            if (standalone) {
+                if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(effect)))
+                    emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+                // if fade effect is displayed, update the effect edit widget with new clip duration
+                if (item->isSelected() && effectPos == item->selectedEffectIndex())
+                    emit clipItemSelected(item);
+            }
         }
         effectPos = item->hasEffect("brightness", "fade_to_black");
         if (effectPos != -1) {
-            QDomElement oldeffect = item->effectAt(effectPos);
+            QDomElement effect = item->getEffectAtIndex(effectPos);
             int max = item->cropDuration().frames(m_document->fps());
             int end = max + item->cropStart().frames(m_document->fps());
             if (start > max) {
@@ -4734,12 +5186,15 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
                 start = item->fadeOut();
             }
             start = end - start;
-            EffectsList::setParameter(oldeffect, "in", QString::number(start));
-            EffectsList::setParameter(oldeffect, "out", QString::number(end));
-            if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect)))
-                emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
-            // if fade effect is displayed, update the effect edit widget with new clip duration
-            if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
+            EffectsList::setParameter(effect, "in", QString::number(start));
+            EffectsList::setParameter(effect, "out", QString::number(end));
+            if (standalone) {
+                if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(effect)))
+                    emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
+                // if fade effect is displayed, update the effect edit widget with new clip duration
+                if (item->isSelected() && effectPos == item->selectedEffectIndex())
+                    emit clipItemSelected(item);
+            }
         }
     }
 
@@ -4747,17 +5202,17 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
     if (effectPos != -1) {
         // Freeze effect needs to be adjusted with clip resize
         int diff = (info.startPos - item->startPos()).frames(m_document->fps());
-        QDomElement eff = item->getEffectAt(effectPos);
+        QDomElement eff = item->getEffectAtIndex(effectPos);
         if (!eff.isNull() && diff != 0) {
             int freeze_pos = EffectsList::parameter(eff, "frame").toInt() + diff;
             EffectsList::setParameter(eff, "frame", QString::number(freeze_pos));
-            if (item->isSelected() && item->selectedEffect().attribute("id") == "freeze") {
-                emit clipItemSelected(item, item->selectedEffectIndex());
+            if (standalone) {
+                if (item->isSelected() && item->selectedEffect().attribute("id") == "freeze") {
+                    emit clipItemSelected(item);
+                }
             }
         }
     }
-
-    updatePanZoom(item);
 }
 
 double CustomTrackView::getSnapPointForPos(double pos)
@@ -4845,7 +5300,7 @@ void CustomTrackView::slotSeekToPreviousSnap()
 {
     updateSnapPoints(NULL);
     GenTime res = m_scene->previousSnapPoint(GenTime(m_cursorPos, m_document->fps()));
-    setCursorPos((int) res.frames(m_document->fps()));
+    seekCursorPos((int) res.frames(m_document->fps()));
     checkScrolling();
 }
 
@@ -4853,7 +5308,7 @@ void CustomTrackView::slotSeekToNextSnap()
 {
     updateSnapPoints(NULL);
     GenTime res = m_scene->nextSnapPoint(GenTime(m_cursorPos, m_document->fps()));
-    setCursorPos((int) res.frames(m_document->fps()));
+    seekCursorPos((int) res.frames(m_document->fps()));
     checkScrolling();
 }
 
@@ -4861,7 +5316,7 @@ void CustomTrackView::clipStart()
 {
     AbstractClipItem *item = getMainActiveClip();
     if (item != NULL) {
-        setCursorPos((int) item->startPos().frames(m_document->fps()));
+        seekCursorPos((int) item->startPos().frames(m_document->fps()));
         checkScrolling();
     }
 }
@@ -4870,21 +5325,54 @@ void CustomTrackView::clipEnd()
 {
     AbstractClipItem *item = getMainActiveClip();
     if (item != NULL) {
-        setCursorPos((int) item->endPos().frames(m_document->fps()) - 1);
+        seekCursorPos((int) item->endPos().frames(m_document->fps()) - 1);
         checkScrolling();
     }
 }
 
-void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c)
+void CustomTrackView::slotAddClipExtraData(const QString &id, const QString &key, const QString &data, QUndoCommand *groupCommand)
 {
-    QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
-    AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t);
-    m_commandStack->push(command);
+    DocClipBase *base = m_document->clipManager()->getClipById(id);
+    if (!base) return;
+    QMap <QString, QString> extraData = base->analysisData();
+    QString oldData = extraData.value(key);
+    AddExtraDataCommand *command = new AddExtraDataCommand(this, id, key, oldData, data, groupCommand);
+    if (!groupCommand) m_commandStack->push(command);
+}
+
+void CustomTrackView::slotAddClipMarker(const QString &id, QList <CommentedTime> newMarkers, QUndoCommand *groupCommand)
+{
+    QUndoCommand *subCommand = NULL;
+    if (newMarkers.count() > 1 && groupCommand == NULL) {
+       subCommand = new QUndoCommand;
+       subCommand->setText("Add markers");
+    }
+    for (int i = 0; i < newMarkers.count(); i++) {
+       CommentedTime oldMarker = m_document->clipManager()->getClipById(id)->markerAt(newMarkers.at(i).time());
+       if (oldMarker == CommentedTime()) {
+           oldMarker = newMarkers.at(i);
+           oldMarker.setMarkerType(-1);
+       }
+       if (newMarkers.count() == 1 && !groupCommand) {
+           AddMarkerCommand *command = new AddMarkerCommand(this, oldMarker, newMarkers.at(i), id, groupCommand);
+           m_commandStack->push(command);
+       }
+       else if (groupCommand) {
+           (void) new AddMarkerCommand(this, oldMarker, newMarkers.at(i), id, groupCommand);
+       }
+       else {
+           (void) new AddMarkerCommand(this, oldMarker, newMarkers.at(i), id, subCommand);
+       }
+    }
+    if (subCommand) m_commandStack->push(subCommand);
 }
 
 void CustomTrackView::slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position)
 {
-    AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position);
+    CommentedTime oldmarker(position, comment);
+    CommentedTime marker = oldmarker;
+    marker.setMarkerType(-1);
+    AddMarkerCommand *command = new AddMarkerCommand(this, oldmarker, marker, id);
     m_commandStack->push(command);
 }
 
@@ -4901,21 +5389,156 @@ void CustomTrackView::slotDeleteAllClipMarkers(const QString &id)
     deleteMarkers->setText("Delete clip markers");
 
     for (int i = 0; i < markers.size(); i++) {
-        new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), deleteMarkers);
+       CommentedTime oldMarker = markers.at(i);
+       CommentedTime marker = oldMarker;
+       marker.setMarkerType(-1);
+        new AddMarkerCommand(this, oldMarker, marker, id, deleteMarkers);
     }
     m_commandStack->push(deleteMarkers);
 }
 
-void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString comment)
+void CustomTrackView::slotSaveClipMarkers(const QString &id)
 {
     DocClipBase *base = m_document->clipManager()->getClipById(id);
-    if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
-    else base->deleteSnapMarker(pos);
+    QList < CommentedTime > markers = base->commentedSnapMarkers();
+    if (!markers.isEmpty()) {
+       // Set  up categories
+       QComboBox *cbox = new QComboBox;
+       cbox->insertItem(0, i18n("All categories"));
+       for (int i = 0; i < 5; ++i) {
+           cbox->insertItem(i + 1, i18n("Category %1", i));
+           cbox->setItemData(i + 1, CommentedTime::markerColor(i), Qt::DecorationRole);
+       }
+       cbox->setCurrentIndex(0);
+       KFileDialog fd(KUrl("kfiledialog:///projectfolder"), "text/plain", this, cbox);
+       fd.setMode(KFile::File);
+       fd.setOperationMode(KFileDialog::Saving);
+       fd.exec();
+       QString url = fd.selectedFile();
+       //QString url = KFileDialog::getSaveFileName(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Save markers"));
+       if (url.isEmpty()) return;
+
+       QString data;
+       int category = cbox->currentIndex() - 1;
+       for (int i = 0; i < markers.count(); i++) {
+           if (category >= 0) {
+               // Save only the markers in selected category
+               if (markers.at(i).markerType() != category) continue;
+           }
+           data.append(QString::number(markers.at(i).time().seconds()));
+           data.append("\t");
+           data.append(QString::number(markers.at(i).time().seconds()));
+           data.append("\t");
+           data.append(markers.at(i).comment());
+           data.append("\n");
+       }
+       delete cbox;
+       
+       QFile file(url);
+       if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+           emit displayMessage(i18n("Cannot open file %1", url), ErrorMessage);
+           return;
+       }
+       file.write(data.toUtf8());
+       file.close();
+    }
+}
+
+void CustomTrackView::slotLoadClipMarkers(const QString &id)
+{
+    QComboBox *cbox = new QComboBox;
+    for (int i = 0; i < 5; ++i) {
+       cbox->insertItem(i, i18n("Category %1", i));
+       cbox->setItemData(i, CommentedTime::markerColor(i), Qt::DecorationRole);
+    }
+    cbox->setCurrentIndex(KdenliveSettings::default_marker_type());
+    KFileDialog fd(KUrl("kfiledialog:///projectfolder"), "text/plain", this, cbox);
+    fd.setMode(KFile::File);
+    fd.setOperationMode(KFileDialog::Opening);
+    fd.exec();
+    QString url = fd.selectedFile();
+       
+    //KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Load marker file"));
+    if (url.isEmpty()) return;
+    int category = cbox->currentIndex();
+    delete cbox;
+    QFile file(url);
+    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+       emit displayMessage(i18n("Cannot open file %1", KUrl(url).fileName()), ErrorMessage);
+       return;
+    }
+    QString data = QString::fromUtf8(file.readAll());
+    file.close();
+    QStringList lines = data.split("\n", QString::SkipEmptyParts);
+    QStringList values;
+    bool ok;
+    QUndoCommand *command = new QUndoCommand();
+    command->setText("Load markers");
+    QString markerText;
+    QList <CommentedTime> markersList;
+    foreach(QString line, lines) {
+       markerText.clear();
+       values = line.split("\t", QString::SkipEmptyParts);
+       double time1 = values.at(0).toDouble(&ok);
+       double time2 = -1;
+       if (!ok) continue;
+       if (values.count() >1) {
+           time2 = values.at(1).toDouble(&ok);
+           if (values.count() == 2) {
+               // Check if second value is a number or text
+               if (!ok) {
+                   time2 = -1;
+                   markerText = values.at(1);
+               }
+               else markerText = i18n("Marker");
+           }
+           else {
+               // We assume 3 values per line: in out name
+               if (!ok) {
+                   // 2nd value is not a number, drop
+               }
+               else {
+                   markerText = values.at(2);
+               }
+           }
+       }
+       if (!markerText.isEmpty()) {
+           // Marker found, add it
+           //TODO: allow user to set a marker category
+           CommentedTime marker1(GenTime(time1), markerText, category);
+           markersList << marker1;
+           if (time2 > 0 && time2 != time1) {
+               CommentedTime marker2(GenTime(time2), markerText, category);
+               markersList << marker2;
+           }
+       }
+    }
+    if (!markersList.isEmpty()) slotAddClipMarker(id, markersList, command);
+    if (command->childCount() > 0) m_commandStack->push(command);
+    else delete command;
+}
+
+void CustomTrackView::addMarker(const QString &id, const CommentedTime marker)
+{
+    DocClipBase *base = m_document->clipManager()->getClipById(id);
+    if (base == NULL) return;
+    if (marker.markerType() < 0) base->deleteSnapMarker(marker.time());
+    else base->addSnapMarker(marker);
     emit updateClipMarkers(base);
     setDocumentModified();
     viewport()->update();
 }
 
+void CustomTrackView::addData(const QString &id, const QString &key, const QString &data)
+{
+    DocClipBase *base = m_document->clipManager()->getClipById(id);
+    if (base == NULL) return;
+    base->setAnalysisData(key, data);
+    emit updateClipExtraData(base);
+    setDocumentModified();
+    viewport()->update();
+}
+
 int CustomTrackView::hasGuide(int pos, int offset)
 {
     for (int i = 0; i < m_guides.count(); i++) {
@@ -4932,13 +5555,13 @@ void CustomTrackView::buildGuidesMenu(QMenu *goMenu) const
     goMenu->clear();
     double fps = m_document->fps();
     for (int i = 0; i < m_guides.count(); i++) {
-        act = goMenu->addAction(m_guides.at(i)->label() + "/" + Timecode::getStringTimecode(m_guides.at(i)->position().frames(fps), fps));
+        act = goMenu->addAction(m_guides.at(i)->label() + '/' + Timecode::getStringTimecode(m_guides.at(i)->position().frames(fps), fps));
         act->setData(m_guides.at(i)->position().frames(m_document->fps()));
     }
     goMenu->setEnabled(!m_guides.isEmpty());
 }
 
-void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment)
+void CustomTrackView::editGuide(const GenTime &oldPos, const GenTime &pos, const QString &comment)
 {
     if (oldPos > GenTime() && pos > GenTime()) {
         // move guide
@@ -4966,7 +5589,7 @@ void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const Q
     m_document->syncGuides(m_guides);
 }
 
-bool 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) {
@@ -4986,9 +5609,14 @@ void CustomTrackView::slotAddGuide(bool dialog)
 {
     CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide"));
     if (dialog) {
-        MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this);
-        if (d.exec() != QDialog::Accepted) return;
-        marker.setComment(d.newMarker().comment());
+        QPointer<MarkerDialog> d = new MarkerDialog(NULL, marker,
+                             m_document->timecode(), i18n("Add Guide"), this);
+        if (d->exec() != QDialog::Accepted) {
+            delete d;
+            return;
+        }
+        marker = d->newMarker();
+        delete d;
     } else {
         marker.setComment(m_document->timecode().getDisplayTimecodeFromFrames(m_cursorPos, false));
     }
@@ -5016,11 +5644,12 @@ void CustomTrackView::slotEditGuide(int guidePos)
 
 void CustomTrackView::slotEditGuide(CommentedTime guide)
 {
-    MarkerDialog d(NULL, guide, m_document->timecode(), i18n("Edit Guide"), this);
-    if (d.exec() == QDialog::Accepted) {
-        EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
+    QPointer<MarkerDialog> d = new MarkerDialog(NULL, guide, m_document->timecode(), i18n("Edit Guide"), this);
+    if (d->exec() == QDialog::Accepted) {
+        EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d->newMarker().time(), d->newMarker().comment(), true);
         m_commandStack->push(command);
     }
+    delete d;
 }
 
 
@@ -5028,11 +5657,13 @@ void CustomTrackView::slotEditTimeLineGuide()
 {
     if (m_dragGuide == NULL) return;
     CommentedTime guide = m_dragGuide->info();
-    MarkerDialog d(NULL, guide, m_document->timecode(), i18n("Edit Guide"), this);
-    if (d.exec() == QDialog::Accepted) {
-        EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d.newMarker().time(), d.newMarker().comment(), true);
+    QPointer<MarkerDialog> d = new MarkerDialog(NULL, guide,
+                     m_document->timecode(), i18n("Edit Guide"), this);
+    if (d->exec() == QDialog::Accepted) {
+        EditGuideCommand *command = new EditGuideCommand(this, guide.time(), guide.comment(), d->newMarker().time(), d->newMarker().comment(), true);
         m_commandStack->push(command);
     }
+    delete d;
 }
 
 void CustomTrackView::slotDeleteGuide(int guidePos)
@@ -5074,6 +5705,16 @@ void CustomTrackView::slotDeleteAllGuides()
 void CustomTrackView::setTool(PROJECTTOOL tool)
 {
     m_tool = tool;
+    switch (m_tool) {
+      case RAZORTOOL:
+         setCursor(m_razorCursor);
+         break;
+      case SPACERTOOL:
+         setCursor(m_spacerCursor);
+         break;
+      default:
+         unsetCursor();
+    }
 }
 
 void CustomTrackView::setScale(double scaleFactor, double verticalScale)
@@ -5119,7 +5760,9 @@ void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect)
 {
     painter->setClipRect(rect);
     QPen pen1 = painter->pen();
-    pen1.setColor(palette().dark().color());
+    QColor lineColor = palette().dark().color();
+    lineColor.setAlpha(100);
+    pen1.setColor(lineColor);
     painter->setPen(pen1);
     double min = rect.left();
     double max = rect.right();
@@ -5146,7 +5789,7 @@ bool CustomTrackView::findString(const QString &text)
     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);
+            seekCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()));
             int vert = verticalScrollBar()->value();
             int hor = cursorPos();
             ensureVisible(hor, vert + 10, 2, 2, 50, 0);
@@ -5159,7 +5802,7 @@ bool CustomTrackView::findString(const QString &text)
 
 void CustomTrackView::selectFound(QString track, QString pos)
 {
-    setCursorPos(m_document->timecode().getFrameCount(pos), true);
+    seekCursorPos(m_document->timecode().getFrameCount(pos));
     slotSelectTrack(track.toInt());
     selectClip(true);
     int vert = verticalScrollBar()->value();
@@ -5173,7 +5816,7 @@ bool CustomTrackView::findNextString(const QString &text)
     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);
+            seekCursorPos(m_searchPoints.at(i).time().frames(m_document->fps()));
             int vert = verticalScrollBar()->value();
             int hor = cursorPos();
             ensureVisible(hor, vert + 10, 2, 2, 50, 0);
@@ -5256,10 +5899,22 @@ bool CustomTrackView::canBePastedTo(ItemInfo info, int type) const
         // If we are in overwrite mode, always allow the move
         return true;
     }
-    QRectF rect((double) info.startPos.frames(m_document->fps()), (double)(info.track * m_tracksHeight + 1), (double)(info.endPos - info.startPos).frames(m_document->fps()), (double)(m_tracksHeight - 1));
+    int height = m_tracksHeight - 2;
+    int offset = 0;
+    if (type == TRANSITIONWIDGET) {
+        height = Transition::itemHeight();
+        offset = Transition::itemOffset();
+    }
+    else if (type == AVWIDGET) {
+        height = ClipItem::itemHeight();
+        offset = ClipItem::itemOffset();
+    }
+    QRectF rect((double) info.startPos.frames(m_document->fps()), (double)(info.track * m_tracksHeight + 1 + offset), (double)(info.endPos - info.startPos).frames(m_document->fps()), (double) height);
     QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
     for (int i = 0; i < collisions.count(); i++) {
-        if (collisions.at(i)->type() == type) return false;
+        if (collisions.at(i)->type() == type) {
+            return false;
+        }
     }
     return true;
 }
@@ -5393,6 +6048,7 @@ void CustomTrackView::pasteClip()
         }
     }
     updateTrackDuration(-1, pasteClips);
+    new RefreshMonitorCommand(this, false, pasteClips);
     m_commandStack->push(pasteClips);
 }
 
@@ -5425,7 +6081,7 @@ void CustomTrackView::pasteClipEffects()
         if (clips.at(i)->type() == AVWIDGET) {
             ClipItem *item = static_cast < ClipItem *>(clips.at(i));
             for (int j = 0; j < clip->effectsCount(); j++) {
-                QDomElement eff = clip->effectAt(j);
+                QDomElement eff = clip->effect(j);
                 if (eff.attribute("unique", "0") == "0" || item->hasEffect(eff.attribute("tag"), eff.attribute("id")) == -1) {
                     adjustKeyfames(clip->cropStart(), item->cropStart(), item->cropDuration(), eff);
                     new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), eff, true, paste);
@@ -5451,22 +6107,23 @@ void CustomTrackView::adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime
     // parse parameters to check if we need to adjust to the new crop start
     int diff = (newstart - oldstart).frames(m_document->fps());
     int max = (newstart + duration).frames(m_document->fps());
+    QLocale locale;
     QDomNodeList params = xml.elementsByTagName("parameter");
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
         if (!e.isNull() && (e.attribute("type") == "keyframe" || e.attribute("type") == "simplekeyframe")) {
             QString def = e.attribute("default");
             // Effect has a keyframe type parameter, we need to adjust the values
-            QStringList keys = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
+            QStringList keys = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
             QStringList newKeyFrames;
             foreach(const QString &str, keys) {
                 int pos = str.section(':', 0, 0).toInt();
                 double val = str.section(':', 1, 1).toDouble();
                 pos += diff;
                 if (pos > max) {
-                    newKeyFrames.append(QString::number(max) + ':' + QString::number(val));
+                    newKeyFrames.append(QString::number(max) + ':' + locale.toString(val));
                     break;
-                } else newKeyFrames.append(QString::number(pos) + ':' + QString::number(val));
+                } else newKeyFrames.append(QString::number(pos) + ':' + locale.toString(val));
             }
             //kDebug()<<"ORIGIN: "<<keys<<", FIXED: "<<newKeyFrames;
             e.setAttribute("keyframes", newKeyFrames.join(";"));
@@ -5480,7 +6137,8 @@ ClipItem *CustomTrackView::getClipUnderCursor() const
     QList<QGraphicsItem *> collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect);
     for (int i = 0; i < collisions.count(); i++) {
         if (collisions.at(i)->type() == AVWIDGET) {
-            return static_cast < ClipItem *>(collisions.at(i));
+           ClipItem *clip = static_cast < ClipItem *>(collisions.at(i));
+           if (!clip->isItemLocked()) return clip;
         }
     }
     return NULL;
@@ -5539,7 +6197,26 @@ void CustomTrackView::setInPoint()
             return;
         }
     }
-    prepareResizeClipStart(clip, clip->info(), m_cursorPos, true);
+
+    AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(clip->parentItem());
+    if (parent) {
+       // Resizing a group
+       QUndoCommand *resizeCommand = new QUndoCommand();
+        resizeCommand->setText(i18n("Resize group"));
+        QList <QGraphicsItem *> items = parent->childItems();
+        for (int i = 0; i < items.count(); ++i) {
+           AbstractClipItem *item = static_cast<AbstractClipItem *>(items.at(i));
+            if (item && item->type() == AVWIDGET) {
+                prepareResizeClipStart(item, item->info(), m_cursorPos, true, resizeCommand);
+            }
+        }
+        if (resizeCommand->childCount() > 0) m_commandStack->push(resizeCommand);
+       else {
+           //TODO warn user of failed resize
+           delete resizeCommand;
+       }
+    }
+    else prepareResizeClipStart(clip, clip->info(), m_cursorPos, true);
 }
 
 void CustomTrackView::setOutPoint()
@@ -5553,7 +6230,25 @@ void CustomTrackView::setOutPoint()
             return;
         }
     }
-    prepareResizeClipEnd(clip, clip->info(), m_cursorPos, true);
+    AbstractGroupItem *parent = static_cast <AbstractGroupItem *>(clip->parentItem());
+    if (parent) {
+       // Resizing a group
+       QUndoCommand *resizeCommand = new QUndoCommand();
+        resizeCommand->setText(i18n("Resize group"));
+        QList <QGraphicsItem *> items = parent->childItems();
+        for (int i = 0; i < items.count(); ++i) {
+           AbstractClipItem *item = static_cast<AbstractClipItem *>(items.at(i));
+            if (item && item->type() == AVWIDGET) {
+                prepareResizeClipEnd(item, item->info(), m_cursorPos, true, resizeCommand);
+            }
+        }
+        if (resizeCommand->childCount() > 0) m_commandStack->push(resizeCommand);
+       else {
+           //TODO warn user of failed resize
+           delete resizeCommand;
+       }
+    }
+    else prepareResizeClipEnd(clip, clip->info(), m_cursorPos, true);
 }
 
 void CustomTrackView::slotUpdateAllThumbs()
@@ -5578,8 +6273,8 @@ void CustomTrackView::slotUpdateAllThumbs()
                 } else {
                     QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_';
                     QString endThumb = startThumb;
-                    startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png");
-                    endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png");
+                    startThumb.append(QString::number((int) item->speedIndependantCropStart().frames(m_document->fps())) + ".png");
+                    endThumb.append(QString::number((int) (item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png");
                     if (QFile::exists(startThumb)) {
                         QPixmap pix(startThumb);
                         if (pix.isNull()) KIO::NetAccess::del(KUrl(startThumb), this);
@@ -5591,7 +6286,7 @@ void CustomTrackView::slotUpdateAllThumbs()
                         item->slotSetEndThumb(pix);
                     }
                 }
-                item->refreshClip(false);
+                item->refreshClip(false, false);
             }
         }
     }
@@ -5617,8 +6312,8 @@ void CustomTrackView::saveThumbnails()
                 } else {
                     QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_';
                     QString endThumb = startThumb;
-                    startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png");
-                    endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png");
+                    startThumb.append(QString::number((int) item->speedIndependantCropStart().frames(m_document->fps())) + ".png");
+                    endThumb.append(QString::number((int) (item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png");
                     if (!QFile::exists(startThumb)) {
                         QPixmap pix(item->startThumb());
                         pix.save(startThumb);
@@ -5636,20 +6331,21 @@ void CustomTrackView::saveThumbnails()
 
 void CustomTrackView::slotInsertTrack(int ix)
 {
-    TrackDialog d(m_document, parentWidget());
-    d.comboTracks->setCurrentIndex(ix);
-    d.label->setText(i18n("Insert track"));
-    d.setWindowTitle(i18n("Insert New Track"));
+    QPointer<TrackDialog> d = new TrackDialog(m_document, parentWidget());
+    d->comboTracks->setCurrentIndex(ix);
+    d->label->setText(i18n("Insert track"));
+    d->setWindowTitle(i18n("Insert New Track"));
 
-    if (d.exec() == QDialog::Accepted) {
-        ix = d.comboTracks->currentIndex();
-        if (d.before_select->currentIndex() == 1)
+    if (d->exec() == QDialog::Accepted) {
+        ix = d->comboTracks->currentIndex();
+        if (d->before_select->currentIndex() == 1)
             ix++;
         TrackInfo info;
         info.duration = 0;
         info.isMute = false;
         info.isLocked = false;
-        if (d.video_track->isChecked()) {
+       info.effectsList = EffectsList(true);
+        if (d->video_track->isChecked()) {
             info.type = VIDEOTRACK;
             info.isBlind = false;
         } else {
@@ -5660,41 +6356,45 @@ void CustomTrackView::slotInsertTrack(int ix)
         m_commandStack->push(addTrack);
         setDocumentModified();
     }
+    delete d;
 }
 
 void CustomTrackView::slotDeleteTrack(int ix)
 {
     if (m_document->tracksCount() < 2) return;
-    TrackDialog d(m_document, parentWidget());
-    d.comboTracks->setCurrentIndex(ix);
-    d.label->setText(i18n("Delete track"));
-    d.before_select->setHidden(true);
-    d.setWindowTitle(i18n("Delete Track"));
-    d.video_track->setHidden(true);
-    d.audio_track->setHidden(true);
-    if (d.exec() == QDialog::Accepted) {
-        ix = d.comboTracks->currentIndex();
+    QPointer<TrackDialog> d = new TrackDialog(m_document, parentWidget());
+    d->comboTracks->setCurrentIndex(ix);
+    d->label->setText(i18n("Delete track"));
+    d->before_select->setHidden(true);
+    d->setWindowTitle(i18n("Delete Track"));
+    d->video_track->setHidden(true);
+    d->audio_track->setHidden(true);
+    if (d->exec() == QDialog::Accepted) {
+        ix = d->comboTracks->currentIndex();
         TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - ix - 1);
         deleteTimelineTrack(ix, info);
         setDocumentModified();
         /*AddTrackCommand* command = new AddTrackCommand(this, ix, info, false);
         m_commandStack->push(command);*/
     }
+    delete d;
 }
 
 void CustomTrackView::slotConfigTracks(int ix)
 {
-    TracksConfigDialog d(m_document, ix, parentWidget());
-    if (d.exec() == QDialog::Accepted) {
-        ConfigTracksCommand *configTracks = new ConfigTracksCommand(this, m_document->tracksList(), d.tracksList());
+    QPointer<TracksConfigDialog> d = new TracksConfigDialog(m_document,
+                                                        ix, parentWidget());
+    if (d->exec() == QDialog::Accepted) {
+        ConfigTracksCommand *configTracks = new ConfigTracksCommand(this, m_document->tracksList(), d->tracksList());
         m_commandStack->push(configTracks);
-        QList <int> toDelete = d.deletedTracks();
+        QList <int> toDelete = d->deletedTracks();
         for (int i = 0; i < toDelete.count(); ++i) {
             TrackInfo info = m_document->trackInfoAt(m_document->tracksCount() - toDelete.at(i) + i - 1);
             deleteTimelineTrack(toDelete.at(i) - i, info);
         }
         setDocumentModified();
     }
+    delete d;
 }
 
 void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
@@ -5711,6 +6411,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo)
         if (selection.at(i)->type() == AVWIDGET) {
             ClipItem *item =  static_cast <ClipItem *>(selection.at(i));
             new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, false, true, deleteTrack);
+            m_waitingThumbs.removeAll(item);
             m_scene->removeItem(item);
             delete item;
             item = NULL;
@@ -5741,26 +6442,7 @@ void CustomTrackView::autoTransition()
     setDocumentModified();
 }
 
-
-QStringList CustomTrackView::getLadspaParams(QDomElement effect) const
-{
-    QStringList result;
-    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") == "constant") {
-            if (e.hasAttribute("factor")) {
-                double factor = e.attribute("factor").toDouble();
-                double value = e.attribute("value").toDouble();
-                value = value / factor;
-                result.append(QString::number(value));
-            } else result.append(e.attribute("value"));
-        }
-    }
-    return result;
-}
-
-void CustomTrackView::clipNameChanged(const QString id, const QString name)
+void CustomTrackView::clipNameChanged(const QString &id, const QString &name)
 {
     QList<QGraphicsItem *> list = scene()->items();
     ClipItem *clip = NULL;
@@ -5807,25 +6489,25 @@ void CustomTrackView::getTransitionAvailableSpace(AbstractClipItem *item, GenTim
     }
 }
 
-void CustomTrackView::loadGroups(const QDomNodeList groups)
+void CustomTrackView::loadGroups(const QDomNodeList &groups)
 {
     for (int i = 0; i < groups.count(); i++) {
         QDomNodeList children = groups.at(i).childNodes();
         scene()->clearSelection();
+       QList <QGraphicsItem*>list;
         for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) {
-            QDomNode n = children.item(nodeindex);
-            QDomElement elem = n.toElement();
+            QDomElement elem = children.item(nodeindex).toElement();
             int pos = elem.attribute("position").toInt();
             int track = elem.attribute("track").toInt();
             if (elem.tagName() == "clipitem") {
                 ClipItem *clip = getClipItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
-                if (clip) clip->setSelected(true);
+                if (clip) list.append(clip);//clip->setSelected(true);
             } else {
                 Transition *clip = getTransitionItemAt(pos, track); //m_document->tracksCount() - transitiontrack);
-                if (clip) clip->setSelected(true);
+                if (clip) list.append(clip);//clip->setSelected(true);
             }
         }
-        groupSelectedItems(false, true);
+        groupSelectedItems(list, false, true);
     }
 }
 
@@ -5846,7 +6528,9 @@ void CustomTrackView::splitAudio()
                 if (clip->parentItem()) {
                     emit displayMessage(i18n("Cannot split audio of grouped clips"), ErrorMessage);
                 } else {
-                    new SplitAudioCommand(this, clip->track(), clip->startPos(), splitCommand);
+                    EffectsList effects;
+                    effects.clone(clip->effectList());
+                    new SplitAudioCommand(this, clip->track(), clip->startPos(), effects, splitCommand);
                 }
             }
         }
@@ -5857,7 +6541,145 @@ void CustomTrackView::splitAudio()
     }
 }
 
-void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
+void CustomTrackView::setAudioAlignReference()
+{
+    QList<QGraphicsItem *> selection = scene()->selectedItems();
+    if (selection.isEmpty() || selection.size() > 1) {
+        emit displayMessage(i18n("You must select exactly one clip for the audio reference."), ErrorMessage);
+        return;
+    }
+    if (m_audioCorrelator != NULL) {
+        delete m_audioCorrelator;
+    }
+    if (selection.at(0)->type() == AVWIDGET) {
+        ClipItem *clip = static_cast<ClipItem*>(selection.at(0));
+        if (clip->clipType() == AV || clip->clipType() == AUDIO) {
+            m_audioAlignmentReference = clip;
+
+            AudioEnvelope *envelope = new AudioEnvelope(clip->baseClip()->fileURL().path(), clip->getProducer(clip->track()));
+            m_audioCorrelator = new AudioCorrelation(envelope);
+
+
+#ifdef DEBUG
+            envelope->drawEnvelope().save("kdenlive-audio-reference-envelope.png");
+            envelope->dumpInfo();
+#endif
+
+
+            emit displayMessage(i18n("Audio align reference set."), InformationMessage);
+        }
+        return;
+    }
+    emit displayMessage(i18n("Reference for audio alignment must contain audio data."), ErrorMessage);
+}
+
+void CustomTrackView::alignAudio()
+{
+    bool referenceOK = true;
+    if (m_audioCorrelator == NULL) {
+        referenceOK = false;
+    }
+    if (referenceOK) {
+        if (!scene()->items().contains(m_audioAlignmentReference)) {
+            // The reference item has been deleted from the timeline (or so)
+            referenceOK = false;
+        }
+    }
+    if (!referenceOK) {
+        emit displayMessage(i18n("Audio alignment reference not yet set."), InformationMessage);
+        return;
+    }
+
+    int counter = 0;
+    QList<QGraphicsItem *> selection = scene()->selectedItems();
+    foreach (QGraphicsItem *item, selection) {
+        if (item->type() == AVWIDGET) {
+
+            ClipItem *clip = static_cast<ClipItem*>(item);
+            if (clip == m_audioAlignmentReference) {
+                continue;
+            }
+
+            if (clip->clipType() == AV || clip->clipType() == AUDIO) {
+                AudioEnvelope *envelope = new AudioEnvelope(clip->baseClip()->fileURL().path(), clip->getProducer(clip->track()), clip->info().cropStart.frames(m_document->fps()), clip->info().cropDuration.frames(m_document->fps()));
+
+                // FFT only for larger vectors. We could use it all time, but for small vectors
+                // the (anyway not noticeable) overhead is smaller with a nested for loop correlation.
+                int index = m_audioCorrelator->addChild(envelope, envelope->envelopeSize() > 200);
+                int shift = m_audioCorrelator->getShift(index);
+                counter++;
+
+
+#ifdef DEBUG
+                m_audioCorrelator->info(index)->toImage().save("kdenlive-audio-align-cross-correlation.png");
+                envelope->drawEnvelope().save("kdenlive-audio-align-envelope.png");
+                envelope->dumpInfo();
+
+                int targetPos = m_audioAlignmentReference->startPos().frames(m_document->fps()) + shift;
+                qDebug() << "Reference starts at " << m_audioAlignmentReference->startPos().frames(m_document->fps());
+                qDebug() << "We will start at " << targetPos;
+                qDebug() << "to shift by " << shift;
+                qDebug() << "(eventually)";
+                qDebug() << "(maybe)";
+#endif
+
+
+                QUndoCommand *moveCommand = new QUndoCommand();
+
+                GenTime add(shift, m_document->fps());
+                ItemInfo start = clip->info();
+
+                ItemInfo end = start;
+                end.startPos = m_audioAlignmentReference->startPos() + add - m_audioAlignmentReference->cropStart();
+                end.endPos = end.startPos + start.cropDuration;
+
+                if ( end.startPos.seconds() < 0 ) {
+                    // Clip would start before 0, so crop it first
+                    GenTime cropBy = -end.startPos;
+
+#ifdef DEBUG
+                    qDebug() << "Need to crop clip. " << start;
+                    qDebug() << "end.startPos: " << end.startPos.toString() << ", cropBy: " << cropBy.toString();
+#endif
+
+                    ItemInfo resized = start;
+                    resized.startPos += cropBy;
+
+                    resizeClip(start, resized);
+                    new ResizeClipCommand(this, start, resized, false, false, moveCommand);
+
+                    start = clip->info();
+                    end.startPos += cropBy;
+
+#ifdef DEBUG
+                    qDebug() << "Clip cropped. " << start;
+                    qDebug() << "Moving to: " << end;
+#endif
+                }
+
+                if (itemCollision(clip, end)) {
+                    delete moveCommand;
+                    emit displayMessage(i18n("Unable to move clip due to collision."), ErrorMessage);
+                    return;
+                }
+
+                moveCommand->setText(i18n("Auto-align clip"));
+                new MoveClipCommand(this, start, end, true, moveCommand);
+                updateTrackDuration(clip->track(), moveCommand);
+                m_commandStack->push(moveCommand);
+
+            }
+        }
+    }
+
+    if (counter == 0) {
+        emit displayMessage(i18n("No audio clips selected."), ErrorMessage);
+    } else {
+        emit displayMessage(i18n("Auto-aligned %1 clips.", counter), InformationMessage);
+    }
+}
+
+void CustomTrackView::doSplitAudio(const GenTime &pos, int track, EffectsList effects, bool split)
 {
     ClipItem *clip = getClipItemAt(pos, track);
     if (clip == NULL) {
@@ -5882,27 +6704,39 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
                 }
             }
         }
-        kDebug() << "GOT TRK: " << track;
         if (freetrack == 0) {
             emit displayMessage(i18n("No empty space to put clip audio"), ErrorMessage);
         } else {
             ItemInfo info = clip->info();
             info.track = m_document->tracksCount() - freetrack;
-            addClip(clip->xml(), clip->clipProducer(), info, clip->effectList());
-            scene()->clearSelection();
+           QDomElement xml = clip->xml();
+           xml.setAttribute("audio_only", 1);
+           scene()->clearSelection();
+            addClip(xml, clip->clipProducer(), info, clip->effectList(), false, false, false);
             clip->setSelected(true);
             ClipItem *audioClip = getClipItemAt(start, info.track);
             if (audioClip) {
-                clip->setVideoOnly(true);
-                if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
+               clip->setVideoOnly(true);
+                Mlt::Tractor *tractor = m_document->renderer()->lockService();
+                if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->videoProducer(info.track)) == false) {
                     emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
                 }
-                if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) {
-                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage);
-                }
+                m_document->renderer()->unlockService(tractor);
                 audioClip->setSelected(true);
-                audioClip->setAudioOnly(true);
-                groupSelectedItems(false, true);
+
+                // keep video effects, move audio effects to audio clip
+                int videoIx = 0;
+                int audioIx = 0;
+                for (int i = 0; i < effects.count(); ++i) {
+                    if (effects.at(i).attribute("type") == "audio") {
+                        deleteEffect(m_document->tracksCount() - track, pos, clip->effect(videoIx));
+                        audioIx++;
+                    } else {
+                        deleteEffect(freetrack, pos, audioClip->effect(audioIx));
+                        videoIx++;
+                    }
+                }
+                groupSelectedItems(QList <QGraphicsItem*>()<<clip<<audioClip, false, true);
             }
         }
     } else {
@@ -5923,9 +6757,26 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
                 ItemInfo info = clip->info();
                 deleteClip(clp->info());
                 clip->setVideoOnly(false);
-                if (!m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->producer(info.track))) {
-                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
+                Mlt::Tractor *tractor = m_document->renderer()->lockService();
+                if (!m_document->renderer()->mltUpdateClipProducer(
+                            tractor,
+                            m_document->tracksCount() - info.track,
+                            info.startPos.frames(m_document->fps()),
+                            clip->baseClip()->getProducer(info.track))) {
+
+                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)",
+                                             info.startPos.frames(m_document->fps()), info.track),
+                                        ErrorMessage);
                 }
+                m_document->renderer()->unlockService(tractor);
+
+                // re-add audio effects
+                for (int i = 0; i < effects.count(); ++i) {
+                    if (effects.at(i).attribute("type") == "audio") {
+                        addEffect(m_document->tracksCount() - track, pos, effects.at(i));
+                    }
+                }
+
                 break;
             }
         }
@@ -6010,6 +6861,11 @@ void CustomTrackView::setAudioAndVideo()
     m_commandStack->push(videoCommand);
 }
 
+void CustomTrackView::monitorRefresh()
+{
+    m_document->renderer()->doRefresh();
+}
+
 void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool videoOnly, bool audioOnly)
 {
     ClipItem *clip = getClipItemAt(pos, track);
@@ -6017,28 +6873,30 @@ void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool video
         kDebug() << "// Cannot find clip to split!!!";
         return;
     }
+    Mlt::Tractor *tractor = m_document->renderer()->lockService();
     if (videoOnly) {
         int start = pos.frames(m_document->fps());
         clip->setVideoOnly(true);
         clip->setAudioOnly(false);
-        if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
+        if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->videoProducer(track)) == false) {
             emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
         }
     } else if (audioOnly) {
         int start = pos.frames(m_document->fps());
         clip->setAudioOnly(true);
         clip->setVideoOnly(false);
-        if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track)) == false) {
+        if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track)) == false) {
             emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
         }
     } else {
         int start = pos.frames(m_document->fps());
         clip->setAudioOnly(false);
         clip->setVideoOnly(false);
-        if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->producer(track)) == false) {
+        if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->getProducer(track)) == false) {
             emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
         }
     }
+    m_document->renderer()->unlockService(tractor);
     clip->update();
     setDocumentModified();
 }
@@ -6066,7 +6924,7 @@ void CustomTrackView::updateClipTypeActions(ClipItem *clip)
 void CustomTrackView::slotGoToMarker(QAction *action)
 {
     int pos = action->data().toInt();
-    setCursorPos(pos, true);
+    seekCursorPos(pos);
 }
 
 void CustomTrackView::reloadTransitionLumas()
@@ -6152,13 +7010,14 @@ void CustomTrackView::updateProjectFps()
             m_document->clipManager()->removeGroup(grp);
             m_scene->addItem(grp);
             scene()->destroyItemGroup(grp);
-            for (int j = 0; j < children.count(); j++) {
+            scene()->clearSelection();
+            /*for (int j = 0; j < children.count(); j++) {
                 if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) {
                     //children.at(j)->setParentItem(0);
                     children.at(j)->setSelected(true);
                 }
-            }
-            groupSelectedItems(true, true);
+            }*/
+            groupSelectedItems(children, true, true);
         } else if (itemList.at(i)->type() == GUIDEITEM) {
             Guide *g = static_cast<Guide *>(itemList.at(i));
             g->updatePos();
@@ -6228,6 +7087,28 @@ void CustomTrackView::slotSelectTrack(int ix)
     viewport()->update();
 }
 
+void CustomTrackView::slotSelectClipsInTrack()
+{
+    QRectF rect(0, m_selectedTrack * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 1);
+    resetSelectionGroup();
+    QList<QGraphicsItem *> selection = m_scene->items(rect);
+    m_scene->clearSelection();
+    QList<QGraphicsItem *> list;
+    for (int i = 0; i < selection.count(); i++) {
+        if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET) {
+           list.append(selection.at(i));
+        }
+    }    
+    groupSelectedItems(list, false, false, true);
+}
+
+void CustomTrackView::slotSelectAllClips()
+{
+    m_scene->clearSelection();
+    resetSelectionGroup();
+    groupSelectedItems(m_scene->items(), false, false, true);
+}
+
 void CustomTrackView::selectClip(bool add, bool group, int track, int pos)
 {
     QRectF rect;
@@ -6272,10 +7153,13 @@ QStringList CustomTrackView::extractTransitionsLumas()
         if (itemList.at(i)->type() == TRANSITIONWIDGET) {
             transitionitem = static_cast <Transition*>(itemList.at(i));
             transitionXml = transitionitem->toXML();
+            // luma files in transitions can be in "resource" or "luma" property
             QString luma = EffectsList::parameter(transitionXml, "luma");
-            if (!luma.isEmpty()) urls << luma;
+            if (luma.isEmpty()) luma = EffectsList::parameter(transitionXml, "resource");
+            if (!luma.isEmpty()) urls << KUrl(luma).path();
         }
     }
+    urls.removeDuplicates();
     return urls;
 }
 
@@ -6329,12 +7213,12 @@ void CustomTrackView::insertZoneOverwrite(QStringList data, int in)
         splitAudio();
 }
 
-void CustomTrackView::clearSelection()
+void CustomTrackView::clearSelection(bool emitInfo)
 {
     resetSelectionGroup();
     scene()->clearSelection();
     m_dragItem = NULL;
-    emit clipItemSelected(NULL);
+    if (emitInfo) emit clipItemSelected(NULL);
 }
 
 void CustomTrackView::updatePalette()
@@ -6346,7 +7230,6 @@ void CustomTrackView::updatePalette()
         pen1.setColor(palette().text().color());
         m_cursorLine->setPen(pen1);
     }
-    emit tracksChanged();
 }
 
 void CustomTrackView::removeTipAnimation()
@@ -6451,41 +7334,101 @@ bool CustomTrackView::hasAudio(int track) const
     return false;
 }
 
-void CustomTrackView::slotAddTrackEffect(const QDomElement effect, int ix)
+void CustomTrackView::slotAddTrackEffect(const QDomElement &effect, int ix)
 {
-    AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - ix, GenTime(-1), effect, true);
-    m_commandStack->push(command);
-    setDocumentModified();
+    
+    QUndoCommand *effectCommand = new QUndoCommand();
+    QString effectName;
+    if (effect.tagName() == "effectgroup") {
+        effectName = effect.attribute("name");
+    } else {
+        QDomElement namenode = effect.firstChildElement("name");
+        if (!namenode.isNull()) effectName = i18n(namenode.text().toUtf8().data());
+        else effectName = i18n("effect");
+    }
+    effectCommand->setText(i18n("Add %1", effectName));
+    if (effect.tagName() == "effectgroup") {
+        QDomNodeList effectlist = effect.elementsByTagName("effect");
+        for (int j = 0; j < effectlist.count(); j++) {
+            QDomElement trackeffect = effectlist.at(j).toElement();
+            if (trackeffect.attribute("unique", "0") != "0" && m_document->hasTrackEffect(m_document->tracksCount() - ix - 1, trackeffect.attribute("tag"), trackeffect.attribute("id")) != -1) {
+                emit displayMessage(i18n("Effect already present in track"), ErrorMessage);
+                continue;
+            }
+            new AddEffectCommand(this, m_document->tracksCount() - ix, GenTime(-1), trackeffect, true, effectCommand);
+        }
+    }
+    else {
+        if (effect.attribute("unique", "0") != "0" && m_document->hasTrackEffect(m_document->tracksCount() - ix - 1, effect.attribute("tag"), effect.attribute("id")) != -1) {
+            emit displayMessage(i18n("Effect already present in track"), ErrorMessage);
+            delete effectCommand;
+            return;
+        }
+        new AddEffectCommand(this, m_document->tracksCount() - ix, GenTime(-1), effect, true, effectCommand);
+    }
+
+    if (effectCommand->childCount() > 0) {
+        m_commandStack->push(effectCommand);
+        setDocumentModified();
+    }
+    else delete effectCommand;
 }
 
 
-EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect)
+EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement &effect)
 {
     EffectsParameterList parameters;
+    QLocale locale;
     parameters.addParam("tag", effect.attribute("tag"));
-    if (effect.hasAttribute("region")) parameters.addParam("region", effect.attribute("region"));
+    //if (effect.hasAttribute("region")) parameters.addParam("region", effect.attribute("region"));
     parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
+    parameters.addParam("kdenlive_info", effect.attribute("kdenlive_info"));
     parameters.addParam("id", effect.attribute("id"));
     if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
     if (effect.hasAttribute("disable")) parameters.addParam("disable", effect.attribute("disable"));
     if (effect.hasAttribute("in")) parameters.addParam("in", effect.attribute("in"));
     if (effect.hasAttribute("out")) parameters.addParam("out", effect.attribute("out"));
+    if (effect.attribute("id") == "region") {
+       QDomNodeList subeffects = effect.elementsByTagName("effect");
+       for (int i = 0; i < subeffects.count(); i++) {
+           QDomElement subeffect = subeffects.at(i).toElement();
+           int subeffectix = subeffect.attribute("region_ix").toInt();
+           parameters.addParam(QString("filter%1").arg(subeffectix), subeffect.attribute("id"));
+           parameters.addParam(QString("filter%1.tag").arg(subeffectix), subeffect.attribute("tag"));
+           parameters.addParam(QString("filter%1.kdenlive_info").arg(subeffectix), subeffect.attribute("kdenlive_info"));
+           QDomNodeList subparams = subeffect.elementsByTagName("parameter");
+           adjustEffectParameters(parameters, subparams, m_document->mltProfile(), QString("filter%1.").arg(subeffectix));
+       }
+    }
 
     QDomNodeList params = effect.elementsByTagName("parameter");
-    for (int i = 0; i < params.count(); i++) {
+    adjustEffectParameters(parameters, params, m_document->mltProfile());
+    
+    return parameters;
+}
+
+
+void CustomTrackView::adjustEffectParameters(EffectsParameterList &parameters, QDomNodeList params, MltVideoProfile profile, const QString &prefix)
+{
+  QLocale locale;
+  for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
-        //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag");
+       QString paramname = prefix + e.attribute("name");
+        if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) {
+            // effects with geometry param need in / out synced with the clip, request it...
+            parameters.addParam("_sync_in_out", "1");
+        }
         if (e.attribute("type") == "simplekeyframe") {
-
-            QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts);
+            QStringList values = e.attribute("keyframes").split(';', QString::SkipEmptyParts);
             double factor = e.attribute("factor", "1").toDouble();
+            double offset = e.attribute("offset", "0").toDouble();
             for (int j = 0; j < values.count(); j++) {
                 QString pos = values.at(j).section(':', 0, 0);
-                double val = values.at(j).section(':', 1, 1).toDouble() / factor;
-                values[j] = pos + "=" + QString::number(val);
+                double val = (values.at(j).section(':', 1, 1).toDouble() - offset) / factor;
+                values[j] = pos + '=' + locale.toString(val);
             }
             // kDebug() << "/ / / /SENDING KEYFR:" << values;
-            parameters.addParam(e.attribute("name"), values.join(";"));
+            parameters.addParam(paramname, values.join(";"));
             /*parameters.addParam(e.attribute("name"), e.attribute("keyframes").replace(":", "="));
             parameters.addParam("max", e.attribute("max"));
             parameters.addParam("min", e.attribute("min"));
@@ -6496,6 +7439,7 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect)
             parameters.addParam("max", e.attribute("max"));
             parameters.addParam("min", e.attribute("min"));
             parameters.addParam("factor", e.attribute("factor", "1"));
+            parameters.addParam("offset", e.attribute("offset", "0"));
             parameters.addParam("starttag", e.attribute("starttag", "start"));
             parameters.addParam("endtag", e.attribute("endtag", "end"));
         } else if (e.attribute("namedesc").contains(';')) {
@@ -6512,35 +7456,22 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect)
             }
             parameters.addParam("start", neu);
         } else {
-            if (e.attribute("factor", "1") != "1") {
+            if (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0") {
                 double fact;
-                if (e.attribute("factor").startsWith('%')) {
-                    fact = ProfilesDialog::getStringEval(m_document->mltProfile(), e.attribute("factor"));
-                } else fact = e.attribute("factor", "1").toDouble();
-                parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
+                if (e.attribute("factor").contains('%')) {
+                    fact = ProfilesDialog::getStringEval(profile, e.attribute("factor"));
+                } else {
+                    fact = e.attribute("factor", "1").toDouble();
+                }
+                double offset = e.attribute("offset", "0").toDouble();
+                parameters.addParam(paramname, locale.toString((e.attribute("value").toDouble() - offset) / fact));
             } else {
-                parameters.addParam(e.attribute("name"), e.attribute("value"));
+                parameters.addParam(paramname, e.attribute("value"));
             }
         }
     }
-    return parameters;
 }
 
-void CustomTrackView::updatePanZoom(ClipItem* item, GenTime cutPos)
-{
-    QList <int> effects = item->updatePanZoom(m_document->width(), m_document->height(), cutPos.frames(m_document->fps()));
-    for (int i = 0; i < effects.count(); ++i) {
-        if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(item->effectAt(effects.at(i)))))
-            emit displayMessage(i18n("Problem editing effect"), ErrorMessage);
-
-        // if effect is displayed, update the effect edit widget with new clip duration
-        /*if (item->isSelected() && effects.at(i) == item->selectedEffectIndex())
-            emit clipItemSelected(item, effects.at(i));*/
-    }
-    // update always, otherwise there might problems when resizing groups
-    if (effects.count() > 0)
-        emit clipItemSelected(item, item->selectedEffectIndex());
-}
 
 void CustomTrackView::updateTrackNames(int track, bool added)
 {
@@ -6580,7 +7511,7 @@ void CustomTrackView::updateTrackNames(int track, bool added)
 
 void CustomTrackView::updateTrackDuration(int track, QUndoCommand *command)
 {
-    Q_UNUSED(command);
+    Q_UNUSED(command)
 
     QList<int> tracks;
     if (track >= 0) {
@@ -6610,4 +7541,125 @@ void CustomTrackView::updateTrackDuration(int track, QUndoCommand *command)
     }
 }
 
+void CustomTrackView::slotRefreshThumbs(const QString &id, bool resetThumbs)
+{
+    QList<QGraphicsItem *> list = scene()->items();
+    ClipItem *clip = NULL;
+    for (int i = 0; i < list.size(); ++i) {
+        if (list.at(i)->type() == AVWIDGET) {
+            clip = static_cast <ClipItem *>(list.at(i));
+            if (clip->clipProducer() == id) {
+                clip->refreshClip(true, resetThumbs);
+            }
+        }
+    }
+}
+
+void CustomTrackView::adjustEffects(ClipItem* item, ItemInfo oldInfo, QUndoCommand* command)
+{
+    QMap<int, QDomElement> effects = item->adjustEffectsToDuration(m_document->width(), m_document->height(), oldInfo);
+
+    if (effects.count()) {
+        QMap<int, QDomElement>::const_iterator i = effects.constBegin();
+        while (i != effects.constEnd()) {
+            new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), i.value(), item->effect(i.key()), i.value().attribute("kdenlive_ix").toInt(), true, true, command);
+            ++i;
+        }
+    }
+}
+
+
+void CustomTrackView::slotGotFilterJobResults(const QString &/*id*/, int startPos, int track, stringMap filterParams, stringMap extra)
+{
+    ClipItem *clip = getClipItemAt(GenTime(startPos, m_document->fps()), track);
+    if (clip == NULL) {
+        emit displayMessage(i18n("Cannot find clip for effect update %1.", extra.value("finalfilter")), ErrorMessage);
+        return;
+    }
+    QDomElement newEffect;
+    QDomElement effect = clip->getEffectAtIndex(clip->selectedEffectIndex());
+    if (effect.attribute("id") == extra.value("finalfilter")) {
+        newEffect = effect.cloneNode().toElement();
+        QMap<QString, QString>::const_iterator i = filterParams.constBegin();
+        while (i != filterParams.constEnd()) {
+            EffectsList::setParameter(newEffect, i.key(), i.value());
+            kDebug()<<"// RESULT FILTER: "<<i.key()<<"="<< i.value();
+            ++i;
+        }
+        EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, newEffect, clip->selectedEffectIndex(), true, true);
+        m_commandStack->push(command);
+        emit clipItemSelected(clip);
+    }    
+}
+
+
+void CustomTrackView::slotImportClipKeyframes(GRAPHICSRECTITEM type)
+{
+    if (!m_selectionGroup) {
+       emit displayMessage(i18n("You need to select one clip and one transition"), ErrorMessage);
+       return;
+    }
+    // Make sure there is no collision
+    QList<QGraphicsItem *> children = m_selectionGroup->childItems();
+    ClipItem *item = NULL;
+    for (int i = 0; i < children.count(); i++) {
+       if (children.at(i)->type() == AVWIDGET) {
+            item = (ClipItem*) children.at(i);
+            break;
+        }
+    }
+    if (!item) {
+       emit displayMessage(i18n("No clip found"), ErrorMessage);
+       return;
+    }
+    QMap <QString, QString> data = item->baseClip()->analysisData();
+    if (data.isEmpty()) {
+       emit displayMessage(i18n("No keyframe data found in clip"), ErrorMessage);
+       return;
+    }
+    QPointer<QDialog> d = new QDialog(this);
+    Ui::ImportKeyframesDialog_UI ui;
+    ui.setupUi(d);
+
+    // Set  up data
+    int ix = 0;
+    QMap<QString, QString>::const_iterator i = data.constBegin();
+    while (i != data.constEnd()) {
+       ui.data_list->insertItem(ix, i.key());
+       ui.data_list->setItemData(ix, i.value(), Qt::UserRole);
+       ++i;
+       ix++;
+    }
+
+    if (d->exec() != QDialog::Accepted) {
+       delete d;
+       return;
+    }
+    QString keyframeData = ui.data_list->itemData(ui.data_list->currentIndex()).toString();
+    QStringList keyframeList = keyframeData.split(';', QString::SkipEmptyParts);
+    QString result;
+    if (ui.import_position->isChecked()) {
+       if (ui.import_size->isChecked()) {
+           foreach(QString key, keyframeList) {
+               if (key.count(':') > 1) result.append(key.section(':', 0, 1));
+               else result.append(key);
+               result.append(';');
+           }
+       }
+       else {
+           foreach(QString key, keyframeList) {
+               result.append(key.section(':', 0, 0));
+               result.append(';');
+           }
+       }
+    }
+    else if (ui.import_size->isChecked()) {
+       foreach(QString key, keyframeList) {
+           result.append(key.section(':', 1, 1));
+           result.append(';');
+       }
+    }
+    emit importKeyframes(type, result, ui.limit_keyframes->isChecked() ? ui.max_keyframes->value() : -1);
+    delete d;
+}