]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Fix transition widget when tracks changed (count, name,...)
[kdenlive] / src / customtrackview.cpp
index e2a2a758ae06e42f783c5bbe15a7d9da829be1fc..decf2029a0c5cee06a23c3c9fce9b8d0a9827743 100644 (file)
@@ -324,6 +324,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
 {
     int pos = event->x();
     int mappedXPos = (int)(mapToScene(event->pos()).x() + 0.5);
+    double snappedPos = getSnapPointForPos(mappedXPos);
     emit mousePosition(mappedXPos);
 
     if (event->buttons() & Qt::MidButton) return;
@@ -349,11 +350,9 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
                 } else if (m_scrollTimer.isActive()) m_scrollTimer.stop();
 
             } else if (m_operationMode == RESIZESTART && move) {
-                double snappedPos = getSnapPointForPos(mappedXPos);
                 m_document->renderer()->pause();
                 m_dragItem->resizeStart((int)(snappedPos));
             } else if (m_operationMode == RESIZEEND && move) {
-                double snappedPos = getSnapPointForPos(mappedXPos);
                 m_document->renderer()->pause();
                 m_dragItem->resizeEnd((int)(snappedPos));
             } else if (m_operationMode == FADEIN && move) {
@@ -386,8 +385,41 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
             return;
         } else if (m_operationMode == SPACER && move && m_selectionGroup) {
             // spacer tool
-            int mappedClick = (int)(mapToScene(m_clickEvent).x() + 0.5);
-            m_selectionGroup->setPos(mappedXPos + (((int) m_selectionGroup->boundingRect().topLeft().x() + 0.5) - mappedClick) , m_selectionGroup->pos().y());
+            if (snappedPos < 0) snappedPos = 0;
+            // Make sure there is no collision
+            QList<QGraphicsItem *> children = m_selectionGroup->childItems();
+            QPainterPath shape = m_selectionGroup->clipGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
+            QList<QGraphicsItem*> collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
+            collidingItems.removeAll(m_selectionGroup);
+            for (int i = 0; i < children.count(); i++) {
+                collidingItems.removeAll(children.at(i));
+            }
+            bool collision = false;
+            for (int i = 0; i < collidingItems.count(); i++) {
+                if (collidingItems.at(i)->type() == AVWIDGET) {
+                    collision = true;
+                    break;
+                }
+            }
+            if (!collision) {
+                // Check transitions
+                shape = m_selectionGroup->transitionGroupShape(QPointF(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0));
+                collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
+                collidingItems.removeAll(m_selectionGroup);
+                for (int i = 0; i < children.count(); i++) {
+                    collidingItems.removeAll(children.at(i));
+                }
+                for (int i = 0; i < collidingItems.count(); i++) {
+                    if (collidingItems.at(i)->type() == TRANSITIONWIDGET) {
+                        collision = true;
+                        break;
+                    }
+                }
+            }
+
+            if (!collision)
+                m_selectionGroup->translate(snappedPos - m_selectionGroup->sceneBoundingRect().left(), 0);
+            //m_selectionGroup->setPos(mappedXPos + (((int) m_selectionGroup->boundingRect().topLeft().x() + 0.5) - mappedClick) , m_selectionGroup->pos().y());
         }
     }
 
@@ -757,7 +789,15 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
             if (event->modifiers() == Qt::ControlModifier) {
                 // Ctrl + click, select all items on track after click position
                 int track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight);
-                selection = items(m_clickEvent.x(), track * m_tracksHeight + m_tracksHeight / 2, mapFromScene(sceneRect().width(), 0).x() - m_clickEvent.x(), m_tracksHeight / 2 - 2);
+                QRectF rect(mapToScene(m_clickEvent).x(), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - mapToScene(m_clickEvent).x(), m_tracksHeight / 2 - 2);
+
+                bool isOk;
+                selection = checkForGroups(rect, isOk);
+                if (!isOk) {
+                    // groups found on track, do not allow the move
+                    emit displayMessage(i18n("Cannot use spacer in a track with a group"), ErrorMessage);
+                    return;
+                }
 
                 kDebug() << "SPACER TOOL + CTRL, SELECTING ALL CLIPS ON TRACK " << track << " WITH SELECTION RECT " << m_clickEvent.x() << "/" <<  track * m_tracksHeight + 1 << "; " << mapFromScene(sceneRect().width(), 0).x() - m_clickEvent.x() << "/" << m_tracksHeight - 2;
             } else {
@@ -766,22 +806,29 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                 kDebug() << "SELELCTING ELEMENTS WITHIN =" << event->pos().x() << "/" <<  1 << ", " << mapFromScene(sceneRect().width(), 0).x() - event->pos().x() << "/" << sceneRect().height();
             }
 
+            // create group to hold selected items
+            m_selectionGroup = new AbstractGroupItem(m_document->fps());
+            scene()->addItem(m_selectionGroup);
             QList <GenTime> offsetList;
             for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET) {
+                if (selection.at(i)->parentItem() == 0 && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) {
                     AbstractClipItem *item = static_cast<AbstractClipItem *>(selection.at(i));
                     offsetList.append(item->startPos());
                     offsetList.append(item->endPos());
-                    selection.at(i)->setSelected(true);
-                }
-                if (selection.at(i)->type() == GROUPWIDGET) {
+                    m_selectionGroup->addToGroup(selection.at(i));
+                    selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable);
+                } else if (selection.at(i)->parentItem() == 0 && selection.at(i)->type() == GROUPWIDGET) {
                     QList<QGraphicsItem *> children = selection.at(i)->childItems();
                     for (int j = 0; j < children.count(); j++) {
                         AbstractClipItem *item = static_cast<AbstractClipItem *>(children.at(j));
                         offsetList.append(item->startPos());
                         offsetList.append(item->endPos());
                     }
-                    selection.at(i)->setSelected(true);
+                    m_selectionGroup->addToGroup(selection.at(i));
+                    selection.at(i)->setFlags(QGraphicsItem::ItemIsSelectable);
+                } else if (selection.at(i)->parentItem()) {
+                    m_selectionGroup->addToGroup(selection.at(i)->parentItem());
+                    selection.at(i)->parentItem()->setFlags(QGraphicsItem::ItemIsSelectable);
                 }
             }
 
@@ -797,7 +844,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
                 }
                 updateSnapPoints(NULL, cleandOffsetList, true);
             }
-            groupSelectedItems(true);
             m_operationMode = SPACER;
         } else {
             setCursorPos((int)(mapToScene(event->x(), 0).x()));
@@ -856,9 +902,24 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
     }
 
+    if (collisionClip != NULL || m_dragItem == NULL) {
+        if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) {
+            ClipItem *selected = static_cast <ClipItem*>(m_dragItem);
+            emit clipItemSelected(selected);
+        } else emit clipItemSelected(NULL);
+    }
+
+    // If clicked item is selected, allow move
+    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()));
+
     // Update snap points
-    if (m_selectionGroup == NULL) updateSnapPoints(m_dragItem);
-    else {
+    if (m_selectionGroup == NULL) {
+        if (m_operationMode == RESIZEEND || m_operationMode == RESIZESTART) updateSnapPoints(NULL);
+        else updateSnapPoints(m_dragItem);
+    } else {
         QList <GenTime> offsetList;
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
         for (int i = 0; i < children.count(); i++) {
@@ -882,19 +943,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         }
     }
 
-    if (collisionClip != NULL || m_dragItem == NULL) {
-        if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) {
-            ClipItem *selected = static_cast <ClipItem*>(m_dragItem);
-            emit clipItemSelected(selected);
-        } else emit clipItemSelected(NULL);
-    }
-
-    // If clicked item is selected, allow move
-    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_operationMode == KEYFRAME) {
         m_dragItem->updateSelectedKeyFrame();
         m_blockRefresh = false;
@@ -910,7 +958,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
         if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
             info.endPos = transitionClip->endPos();
-        } else info.endPos = info.startPos + GenTime(65, m_document->fps());
+        } else {
+            GenTime transitionDuration(65, m_document->fps());
+            if (m_dragItem->cropDuration() < transitionDuration) info.endPos = m_dragItem->endPos();
+            else info.endPos = info.startPos + transitionDuration;
+        }
         if (info.endPos == info.startPos) info.endPos = info.startPos + GenTime(65, m_document->fps());
         // Check there is no other transition at that place
         double startY = info.track * m_tracksHeight + 1 + m_tracksHeight / 2;
@@ -936,7 +988,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
         if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_document->tracksCount() - transitiontrack);
         if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
             info.startPos = transitionClip->startPos();
-        } else info.startPos = info.endPos - GenTime(65, m_document->fps());
+        } else {
+            GenTime transitionDuration(65, m_document->fps());
+            if (m_dragItem->cropDuration() < transitionDuration) info.startPos = m_dragItem->startPos();
+            else info.startPos = info.endPos - transitionDuration;
+        }
         if (info.endPos == info.startPos) info.startPos = info.endPos - GenTime(65, m_document->fps());
         QDomElement transition = MainWindow::transitions.getEffectByTag("luma", "dissolve").cloneNode().toElement();
         EffectsList::setParameter(transition, "reverse", "1");
@@ -977,7 +1033,7 @@ void CustomTrackView::resetSelectionGroup(bool selectItems)
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
         scene()->destroyItemGroup(m_selectionGroup);
         for (int i = 0; i < children.count(); i++) {
-            if (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET) {
+            if (children.at(i)->parentItem() == 0 && (children.at(i)->type() == AVWIDGET || children.at(i)->type() == TRANSITIONWIDGET)) {
                 if (!static_cast <AbstractClipItem *>(children.at(i))->isItemLocked()) {
                     children.at(i)->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
                     children.at(i)->setSelected(selectItems);
@@ -1003,8 +1059,10 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
     QRectF rectUnion;
     // Find top left position of selection
     for (int i = 0; i < selection.count(); i++) {
-        if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET) {
+        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());
         }
     }
 
@@ -1013,8 +1071,11 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
         KdenliveSettings::setSnaptopoints(false);
         if (createNewGroup) {
             AbstractGroupItem *newGroup = m_document->clipManager()->createGroup();
-            newGroup->translate(-rectUnion.left(), -rectUnion.top() + 1);
             newGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
+            QPointF diff = newGroup->pos();
+            newGroup->translate(-diff.x(), -diff.y());
+            //newGroup->translate((int) -rectUnion.left(), (int) -rectUnion.top() + 1);
+
             scene()->addItem(newGroup);
 
             // CHeck if we are trying to include a group in a group
@@ -1043,11 +1104,14 @@ void CustomTrackView::groupSelectedItems(bool force, bool createNewGroup)
             KdenliveSettings::setSnaptopoints(snap);
         } else {
             m_selectionGroup = new AbstractGroupItem(m_document->fps());
-            m_selectionGroup->translate(-rectUnion.left(), -rectUnion.top() + 1);
             m_selectionGroup->setPos(rectUnion.left(), rectUnion.top() - 1);
+            QPointF diff = m_selectionGroup->pos();
+            //m_selectionGroup->translate((int) - rectUnion.left(), (int) -rectUnion.top() + 1);
+            m_selectionGroup->translate(- diff.x(), -diff.y());
+
             scene()->addItem(m_selectionGroup);
             for (int i = 0; i < selection.count(); i++) {
-                if (selection.at(i)->parentItem() == NULL && (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET || selection.at(i)->type() == GROUPWIDGET)) {
+                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)->setFlags(QGraphicsItem::ItemIsSelectable);
                 }
@@ -1212,11 +1276,13 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
         info.startPos = GenTime();
         info.cropStart = GenTime(list.at(1).toInt(), m_document->fps());
         info.endPos = GenTime(list.at(2).toInt() - list.at(1).toInt(), m_document->fps());
+        info.cropDuration = info.endPos - info.startPos;
         info.track = 0;
 
         // Check if clip can be inserted at that position
         ItemInfo pasteInfo = info;
         pasteInfo.startPos = GenTime((int)(framePos.x() + 0.5), m_document->fps());
+        pasteInfo.endPos = pasteInfo.startPos + info.endPos;
         pasteInfo.track = (int)(framePos.y() / m_tracksHeight);
         if (!canBePastedTo(pasteInfo, AVWIDGET)) {
             return true;
@@ -1253,7 +1319,8 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
             }
             ItemInfo info;
             info.startPos = start;
-            info.endPos = info.startPos + clip->duration();
+            info.cropDuration = clip->duration();
+            info.endPos = info.startPos + info.cropDuration;
             info.track = track;
             infoList.append(info);
             start += clip->duration();
@@ -1267,9 +1334,10 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos)
             DocClipBase *clip = m_document->getBaseClip(ids.at(i));
             ItemInfo info;
             info.startPos = start;
-            info.endPos = info.startPos + clip->duration();
+            info.cropDuration = clip->duration();
+            info.endPos = info.startPos + info.cropDuration;
             info.track = 0;
-            start += clip->duration();
+            start += info.cropDuration;
             offsetList.append(start);
             ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, false);
             item->setFlags(QGraphicsItem::ItemIsSelectable);
@@ -1336,7 +1404,7 @@ void CustomTrackView::slotRefreshEffects(ClipItem *clip)
 
 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
 {
-    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
     if (clip) {
         // Special case: speed effect
         if (effect.attribute("id") == "speed") {
@@ -1344,17 +1412,21 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
                 emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
                 return;
             }
-            ItemInfo info = clip->info();
             double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
             int strobe = EffectsList::parameter(effect, "strobe").toInt();
             if (strobe == 0) strobe = 1;
-            doChangeClipSpeed(info, speed, 1.0, strobe, clip->baseClip()->getId());
-            clip->addEffect(effect);
+            doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, 1.0, strobe, clip->baseClip()->getId());
+            EffectsParameterList params = clip->addEffect(effect);
+            m_document->renderer()->mltAddEffect(track, pos, params);
             if (clip->isSelected()) emit clipItemSelected(clip);
             return;
         }
-
         EffectsParameterList params = clip->addEffect(effect);
+        if (effect.attribute("disabled") == "1") {
+            // Effect is disabled, don't add it to MLT playlist
+            if (clip->isSelected()) emit clipItemSelected(clip);
+            return;
+        }
         if (!m_document->renderer()->mltAddEffect(track, pos, params))
             emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage);
         if (clip->isSelected()) emit clipItemSelected(clip);
@@ -1366,12 +1438,12 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
     QString index = effect.attribute("kdenlive_ix");
     // Special case: speed effect
     if (effect.attribute("id") == "speed") {
-        ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
+        ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
         if (clip) {
-            ItemInfo info = clip->info();
-            doChangeClipSpeed(info, 1.0, clip->speed(), 1, clip->baseClip()->getId());
+            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);
             return;
         }
     }
@@ -1380,7 +1452,7 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
         emit displayMessage(i18n("Problem deleting effect"), ErrorMessage);
         return;
     }
-    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
     if (clip) {
         clip->deleteEffect(index);
         emit clipItemSelected(clip);
@@ -1471,7 +1543,9 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
             if (item->isItemLocked()) {
                 continue;
             }
-            item->initEffect(effect);
+            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));
@@ -1496,19 +1570,22 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect)
 
 void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedEffect, int ix, bool triggeredByUser)
 {
-    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track);
     QDomElement effect = insertedEffect.cloneNode().toElement();
     if (clip) {
         // Special case: speed effect
         if (effect.attribute("id") == "speed") {
-            ItemInfo info = clip->info();
-            double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
-            int strobe = EffectsList::parameter(effect, "strobe").toInt();
-            if (strobe == 0) strobe = 1;
-            doChangeClipSpeed(info, speed, clip->speed(), strobe, clip->baseClip()->getId());
+            if (effect.attribute("disabled") == "1") doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId());
+            else {
+                double speed = EffectsList::parameter(effect, "speed").toDouble() / 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);
             }
             return;
         }
@@ -1552,13 +1629,18 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE
 
 void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
 {
-    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
+    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).cloneNode().toElement();
-        QDomElement before = clip->effectAt(oldPos - 1).cloneNode().toElement();
+        QDomElement act = clip->effectAt(newPos - 1);
+        QDomElement before = clip->effectAt(oldPos - 1);
         clip->setEffectAt(oldPos - 1, act);
         clip->setEffectAt(newPos - 1, before);
-        m_document->renderer()->mltMoveEffect(track, pos, oldPos, newPos);
+        // 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);
         setDocumentModified();
     } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage);
@@ -1566,22 +1648,9 @@ void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos)
 
 void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable)
 {
-    QDomElement effect = clip->effectAt(effectPos).cloneNode().toElement();
+    QDomElement effect = clip->effectAt(effectPos);
     QDomElement oldEffect = effect.cloneNode().toElement();
-    if (effect.attribute("id") == "speed") {
-        if (clip) {
-            ItemInfo info = clip->info();
-            effect.setAttribute("disabled", (int) disable);
-            if (disable) doChangeClipSpeed(info, 1.0, clip->speed(), 1, clip->baseClip()->getId());
-            else {
-                double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0;
-                int strobe = EffectsList::parameter(effect, "strobe").toInt();
-                if (strobe == 0) strobe = 1;
-                doChangeClipSpeed(info, speed, 1.0, strobe, clip->baseClip()->getId());
-            }
-            return;
-        }
-    }
+
     effect.setAttribute("disabled", (int) disable);
     EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true);
     m_commandStack->push(command);
@@ -1621,12 +1690,13 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut)
         m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime);
         int cutPos = (int) cutTime.frames(m_document->fps());
         ItemInfo newPos;
-        double speed = item->speed();
         newPos.startPos = cutTime;
         newPos.endPos = info.endPos;
-        if (speed == 1) newPos.cropStart = item->info().cropStart + (cutTime - info.startPos);
-        else newPos.cropStart = item->info().cropStart + (cutTime - info.startPos) * speed;
+        newPos.cropStart = item->info().cropStart + (cutTime - info.startPos);
         newPos.track = info.track;
+        newPos.cropDuration = newPos.endPos - newPos.startPos;
+
+
         ClipItem *dup = item->clone(newPos);
         // remove unwanted effects (fade in) from 2nd part of cutted clip
         int ix = dup->hasEffect(QString(), "fadein");
@@ -1639,7 +1709,7 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut)
             QDomElement oldeffect = item->effectAt(ix);
             dup->deleteEffect(oldeffect.attribute("kdenlive_ix"));
         }
-        item->resizeEnd(cutPos, false);
+        item->resizeEnd(cutPos);
         scene()->addItem(dup);
         if (item->checkKeyFrames()) slotRefreshEffects(item);
         if (dup->checkKeyFrames()) slotRefreshEffects(dup);
@@ -1651,7 +1721,7 @@ void CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut)
         // uncut clip
 
         ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
-        ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()) + 1, info.track);
+        ClipItem *dup = getClipItemAt((int) cutTime.frames(m_document->fps()), info.track);
         if (!item || !dup || item == dup) {
             emit displayMessage(i18n("Cannot find clip to uncut"), ErrorMessage);
             m_blockRefresh = false;
@@ -2009,7 +2079,10 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
                     if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
                     else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
                     else prod = clip->baseClip()->producer(clipinfo.track);
-                    m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod);
+                    if (m_document->renderer()->mltUpdateClipProducer((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) {
                 Transition *tr = static_cast <Transition *>(item);
@@ -2031,7 +2104,7 @@ void CustomTrackView::addTrack(TrackInfo type, int ix)
     m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight);
     setSceneRect(0, 0, sceneRect().width(), maxHeight);
     viewport()->update();
-    emit trackHeightChanged();
+    emit tracksChanged();
     //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
     //setFixedHeight(50 * m_tracksCount);
 }
@@ -2079,7 +2152,9 @@ void CustomTrackView::removeTrack(int ix)
                 if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track);
                 else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer();
                 else prod = clip->baseClip()->producer(clipinfo.track);
-                m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod);
+                if (!m_document->renderer()->mltUpdateClipProducer((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);
+                }
             }
         } else if (children.at(i)->type() == TRANSITIONWIDGET) {
             Transition *tr = static_cast <Transition *>(children.at(i));
@@ -2102,7 +2177,7 @@ void CustomTrackView::removeTrack(int ix)
     m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight);
     setSceneRect(0, 0, sceneRect().width(), maxHeight);
     viewport()->update();
-    emit trackHeightChanged();
+    emit tracksChanged();
     //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged()));
 }
 
@@ -2163,6 +2238,24 @@ void CustomTrackView::slotSwitchTrackVideo(int ix)
     setDocumentModified();
 }
 
+QList<QGraphicsItem *> CustomTrackView::checkForGroups(const QRectF &rect, bool &ok)
+{
+    // Check there is no group going over several tracks there, or that would result in timeline corruption
+    QList<QGraphicsItem *> selection = scene()->items(rect);
+    int maxHeight = m_tracksHeight * 1.5;
+    for (int i = 0; i < selection.count(); i++) {
+        // Check that we don't try to move a group with clips on other tracks
+        if (selection.at(i)->type() == GROUPWIDGET && (selection.at(i)->boundingRect().height() >= maxHeight)) {
+            ok = false;
+            break;
+        } else if (selection.at(i)->parentItem() && (selection.at(i)->parentItem()->boundingRect().height() >= maxHeight)) {
+            ok = false;
+            break;
+        }
+    }
+    return selection;
+}
+
 void CustomTrackView::slotRemoveSpace()
 {
     GenTime pos;
@@ -2176,6 +2269,7 @@ void CustomTrackView::slotRemoveSpace()
         pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps());
         track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight);
     }
+
     ClipItem *item = getClipItemAt(pos, track);
     if (item) {
         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);
@@ -2184,12 +2278,20 @@ void CustomTrackView::slotRemoveSpace()
     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);
+        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;
     }
 
-    QRectF r(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 1);
-    QList<QGraphicsItem *> items = m_scene->items(r);
+    // Make sure there is no group in the way
+    QRectF rect(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 2);
+
+    bool isOk;
+    QList<QGraphicsItem *> items = checkForGroups(rect, isOk);
+    if (!isOk) {
+        // groups found on track, do not allow the move
+        emit displayMessage(i18n("Cannot remove space in a track with a group"), ErrorMessage);
+        return;
+    }
 
     QList<ItemInfo> clipsToMove;
     QList<ItemInfo> transitionsToMove;
@@ -2224,19 +2326,20 @@ void CustomTrackView::slotInsertSpace()
     if (d.exec() != QDialog::Accepted) return;
     GenTime spaceDuration = d.selectedDuration();
     track = d.selectedTrack();
+
     ClipItem *item = getClipItemAt(pos, track);
     if (item) pos = item->startPos();
 
-    int minh = 0;
-    int maxh = sceneRect().height();
-    if (track != -1) {
-        minh = track * m_tracksHeight + m_tracksHeight / 2;
-        maxh = m_tracksHeight / 2 - 1;
+    // Make sure there is no group in the way
+    QRectF rect(pos.frames(m_document->fps()), track * m_tracksHeight + m_tracksHeight / 2, sceneRect().width() - pos.frames(m_document->fps()), m_tracksHeight / 2 - 2);
+    bool isOk;
+    QList<QGraphicsItem *> items = checkForGroups(rect, isOk);
+    if (!isOk) {
+        // groups found on track, do not allow the move
+        emit displayMessage(i18n("Cannot insert space in a track with a group"), ErrorMessage);
+        return;
     }
 
-    QRectF r(pos.frames(m_document->fps()), minh, sceneRect().width() - pos.frames(m_document->fps()), maxh);
-    QList<QGraphicsItem *> items = m_scene->items(r);
-
     QList<ItemInfo> clipsToMove;
     QList<ItemInfo> transitionsToMove;
 
@@ -2286,29 +2389,37 @@ void CustomTrackView::insertSpace(QList<ItemInfo> clipsToMove, QList<ItemInfo> t
                 }
                 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());
-            } else emit displayMessage(i18n("Cannot move clip at position %1, track %2", m_document->timecode().getTimecodeFromFrames(clipsToMove.at(i).startPos.frames(m_document->fps())), clipsToMove.at(i).track), ErrorMessage);
-        }
+            } else emit {
+                    displayMessage(i18n("Cannot move clip at position %1, track %2", m_document->timecode().getTimecodeFromFrames((clipsToMove.at(i).startPos + offset).frames(m_document->fps())), clipsToMove.at(i).track), ErrorMessage);
+                }
+            }
     if (!transToMove.isEmpty()) for (int i = 0; i < transToMove.count(); i++) {
             transition = getTransitionItemAtStart(transToMove.at(i).startPos + offset, transToMove.at(i).track);
             if (transition) {
-                if (transition->parentItem()) m_selectionGroup->addToGroup(transition->parentItem());
-                m_selectionGroup->addToGroup(transition);
+                if (transition->parentItem()) {
+                    m_selectionGroup->addToGroup(transition->parentItem());
+                    transition->parentItem()->setFlags(QGraphicsItem::ItemIsSelectable);
+                } else {
+                    m_selectionGroup->addToGroup(transition);
+                    transition->setFlags(QGraphicsItem::ItemIsSelectable);
+                }
                 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());
-                transition->setFlags(QGraphicsItem::ItemIsSelectable);
             } else emit displayMessage(i18n("Cannot move transition at position %1, track %2", m_document->timecode().getTimecodeFromFrames(transToMove.at(i).startPos.frames(m_document->fps())), transToMove.at(i).track), ErrorMessage);
         }
     m_selectionGroup->translate(diff, 0);
 
     // update items coordinates
-    QList<QGraphicsItem *> itemList = scene()->selectedItems();
+    QList<QGraphicsItem *> itemList = m_selectionGroup->childItems();
+
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
             static_cast < AbstractClipItem *>(itemList.at(i))->updateItem();
         } else if (itemList.at(i)->type() == GROUPWIDGET) {
             QList<QGraphicsItem *> children = itemList.at(i)->childItems();
             for (int j = 0; j < children.count(); j++) {
-                static_cast < AbstractClipItem *>(children.at(j))->updateItem();
+                AbstractClipItem * clp = static_cast < AbstractClipItem *>(children.at(j));
+                clp->updateItem();
             }
         }
     }
@@ -2322,7 +2433,6 @@ void CustomTrackView::deleteClip(const QString &clipId)
     resetSelectionGroup();
     QList<QGraphicsItem *> itemList = items();
     QUndoCommand *deleteCommand = new QUndoCommand();
-    deleteCommand->setText(i18n("Delete timeline clips"));
     int count = 0;
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == AVWIDGET) {
@@ -2337,6 +2447,7 @@ void CustomTrackView::deleteClip(const QString &clipId)
             }
         }
     }
+    deleteCommand->setText(i18np("Delete timeline clip", "Delete timeline clips", count));
     if (count == 0) delete deleteCommand;
     else m_commandStack->push(deleteCommand);
 }
@@ -2414,7 +2525,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             // We are moving all tracks
             track = -1;
         } else track = (int)(mapToScene(m_clickEvent).y() / m_tracksHeight);
-        GenTime timeOffset = GenTime(m_selectionGroup->scenePos().x(), m_document->fps()) - m_selectionGroupInfo.startPos;
+        GenTime timeOffset = GenTime((int)(m_selectionGroup->scenePos().x()), m_document->fps()) - m_selectionGroupInfo.startPos;
+
         if (timeOffset != GenTime()) {
             QList<QGraphicsItem *> items = m_selectionGroup->childItems();
 
@@ -2430,10 +2542,9 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 trackTransitionStartList[i] = -1;
             }
 
-            int max = items.count();
-            for (int i = 0; i < max; i++) {
+            for (int i = 0; i < items.count(); i++) {
                 if (items.at(i)->type() == GROUPWIDGET)
-                    items += static_cast <QGraphicsItemGroup *>(items.at(i))->childItems();
+                    items += items.at(i)->childItems();
             }
 
             for (int i = 0; i < items.count(); i++) {
@@ -2493,7 +2604,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                     int tracknumber = m_document->tracksCount() - item->track() - 1;
                     bool isLocked = m_document->trackInfoAt(tracknumber).isLocked;
                     if (isLocked) item->setItemLocked(true);
-
                     QUndoCommand *moveCommand = new QUndoCommand();
                     moveCommand->setText(i18n("Move clip"));
                     new MoveClipCommand(this, m_dragItemInfo, info, false, moveCommand);
@@ -2552,6 +2662,8 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                             ItemInfo trInfo = tr->info();
                             ItemInfo newTrInfo = trInfo;
                             newTrInfo.endPos = m_dragItem->endPos();
+                            kDebug() << "CLIP ENDS AT: " << newTrInfo.endPos.frames(25);
+                            kDebug() << "CLIP STARTS AT: " << newTrInfo.startPos.frames(25);
                             ClipItem * upperClip = getClipItemAt(m_dragItemInfo.startPos, m_dragItemInfo.track - 1);
                             if (!upperClip || !upperClip->baseClip()->isTransparent()) {
                                 if (!getClipItemAtStart(trInfo.startPos, tr->track())) {
@@ -2575,14 +2687,17 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
             }
             if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) {
                 Transition *transition = static_cast <Transition *>(m_dragItem);
-                if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), transition->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos)) {
+                int transitionTrack;
+                if (!transition->forcedTrack()) transitionTrack = getPreviousVideoTrack(m_dragItem->track());
+                else transitionTrack = transition->transitionEndTrack();
+                if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), transitionTrack, m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos)) {
                     // Moving transition failed, revert to previous position
                     emit displayMessage(i18n("Cannot move transition"), ErrorMessage);
                     transition->setPos((int) m_dragItemInfo.startPos.frames(m_document->fps()), (m_dragItemInfo.track) * m_tracksHeight + 1);
                 } else {
                     MoveTransitionCommand *command = new MoveTransitionCommand(this, m_dragItemInfo, info, false);
                     m_commandStack->push(command);
-                    transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track()));
+                    transition->updateTransitionEndTrack(transitionTrack);
                 }
             }
         } else {
@@ -2709,7 +2824,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 }
 
                 ClipItem *clip = static_cast < ClipItem * >(m_dragItem);
-                updateClipFade(clip);
+                updatePositionEffects(clip, m_dragItemInfo);
 
                 // check keyframes
                 QDomDocument doc;
@@ -2833,7 +2948,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
                 } else new ResizeClipCommand(this, m_dragItemInfo, info, false, false, resizeCommand);
 
                 m_commandStack->push(resizeCommand);
-                updateClipFade(clip);
+                updatePositionEffects(clip, m_dragItemInfo);
             } else {
                 m_dragItem->resizeEnd((int) m_dragItemInfo.endPos.frames(m_document->fps()));
                 emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
@@ -2866,7 +2981,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         ClipItem * item = static_cast <ClipItem *>(m_dragItem);
         int ix = item->hasEffect("volume", "fadein");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix).cloneNode().toElement();
+            QDomElement oldeffect = item->effectAt(ix);
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
@@ -2886,7 +3001,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
         ix = item->hasEffect("volume", "fade_from_black");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix).cloneNode().toElement();
+            QDomElement oldeffect = item->effectAt(ix);
             int start = item->cropStart().frames(m_document->fps());
             int end = item->fadeIn();
             if (end == 0) {
@@ -2905,7 +3020,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         ClipItem * item = static_cast <ClipItem *>(m_dragItem);
         int ix = item->hasEffect("volume", "fadeout");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix).cloneNode().toElement();
+            QDomElement oldeffect = item->effectAt(ix);
             int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
@@ -2927,7 +3042,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
         }
         ix = item->hasEffect("brightness", "fade_to_black");
         if (ix != -1) {
-            QDomElement oldeffect = item->effectAt(ix).cloneNode().toElement();
+            QDomElement oldeffect = item->effectAt(ix);
             int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps());
             int start = item->fadeOut();
             if (start == 0) {
@@ -3009,12 +3124,15 @@ void CustomTrackView::deleteSelectedClips()
     }
     scene()->clearSelection();
     QUndoCommand *deleteSelected = new QUndoCommand();
-    deleteSelected->setText(i18n("Delete selected items"));
-    bool resetGroup = false;
 
+    bool resetGroup = false;
+    int groupCount = 0;
+    int clipCount = 0;
+    int transitionCount = 0;
     // expand & destroy groups
     for (int i = 0; i < itemList.count(); i++) {
         if (itemList.at(i)->type() == GROUPWIDGET) {
+            groupCount++;
             QList<QGraphicsItem *> children = itemList.at(i)->childItems();
             itemList += children;
             QList <ItemInfo> clipInfos;
@@ -3037,12 +3155,14 @@ void CustomTrackView::deleteSelectedClips()
 
     for (int i = 0; i < itemList.count(); i++) {
         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(), true, true, deleteSelected);
             emit clipItemSelected(NULL);
         } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
+            transitionCount++;
             Transition *item = static_cast <Transition *>(itemList.at(i));
             //kDebug()<<"// DELETE TRANS AT: "<<item->info().startPos.frames(25);
             if (item->parentItem()) resetGroup = true;
@@ -3050,7 +3170,13 @@ void CustomTrackView::deleteSelectedClips()
             emit transitionItemSelected(NULL);
         }
     }
-
+    if (groupCount > 0 && clipCount == 0 && transitionCount == 0)
+        deleteSelected->setText(i18np("Delete selected group", "Delete selected groups", groupCount));
+    else if (clipCount > 0 && groupCount == 0 && transitionCount == 0)
+        deleteSelected->setText(i18np("Delete selected clip", "Delete selected clips", clipCount));
+    else if (transitionCount > 0 && groupCount == 0 && clipCount == 0)
+        deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount));
+    else deleteSelected->setText(i18n("Delete selected items"));
     m_commandStack->push(deleteSelected);
 }
 
@@ -3083,7 +3209,7 @@ void CustomTrackView::changeClipSpeed()
     else delete changeSelected;
 }
 
-void CustomTrackView::doChangeClipSpeed(ItemInfo info, const double speed, const double oldspeed, int strobe, const QString &id)
+void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id)
 {
     DocClipBase *baseclip = m_document->clipManager()->getClipById(id);
     ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track);
@@ -3093,12 +3219,14 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, const double speed, const
         return;
     }
     info.track = m_document->tracksCount() - item->track();
-    int endPos = m_document->renderer()->mltChangeClipSpeed(info, speed, oldspeed, strobe, baseclip->producer());
+    int endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer());
     if (endPos >= 0) {
         item->setSpeed(speed, strobe);
         item->updateRectGeometry();
-        if (item->cropDuration().frames(m_document->fps()) > endPos)
-            item->AbstractClipItem::resizeEnd(info.startPos.frames(m_document->fps()) + endPos, speed);
+        if (item->cropDuration().frames(m_document->fps()) != endPos) {
+            item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1);
+        }
+        updatePositionEffects(item, info);
         setDocumentModified();
     } else emit displayMessage(i18n("Invalid clip"), ErrorMessage);
 }
@@ -3231,7 +3359,7 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i
     m_thumbsTimer.start();
 }
 
-void CustomTrackView::slotUpdateClip(const QString &clipId)
+void CustomTrackView::slotUpdateClip(const QString &clipId, bool reload)
 {
     QList<QGraphicsItem *> list = scene()->items();
     ClipItem *clip = NULL;
@@ -3241,7 +3369,9 @@ void CustomTrackView::slotUpdateClip(const QString &clipId)
             if (clip->clipProducer() == clipId) {
                 ItemInfo info = clip->info();
                 info.track = m_document->tracksCount() - clip->track();
-                m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer());
+                if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer())) {
+                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
+                }
                 clip->refreshClip(true);
                 clip->update();
             }
@@ -3401,6 +3531,10 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
     kDebug() << "// GROUP MOV; OFFSET: " << offset.frames(25) << ", TK OFF: " << trackOffset;*/
     resetSelectionGroup();
     m_scene->clearSelection();
+
+    m_selectionGroup = new AbstractGroupItem(m_document->fps());
+    scene()->addItem(m_selectionGroup);
+
     m_document->renderer()->blockSignals(true);
     for (int i = 0; i < startClip.count(); i++) {
         if (reverseMove) {
@@ -3412,9 +3546,12 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         if (clip) {
             clip->setItemLocked(false);
             if (clip->parentItem()) {
-                clip->parentItem()->setSelected(true);
+                m_selectionGroup->addToGroup(clip->parentItem());
+                clip->parentItem()->setFlags(QGraphicsItem::ItemIsSelectable);
+            } else {
+                m_selectionGroup->addToGroup(clip);
+                clip->setFlags(QGraphicsItem::ItemIsSelectable);
             }
-            clip->setSelected(true);
             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);
     }
@@ -3427,18 +3564,23 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         if (tr) {
             tr->setItemLocked(false);
             if (tr->parentItem()) {
-                tr->parentItem()->setSelected(true);
-            } else tr->setSelected(true);
+                m_selectionGroup->addToGroup(tr->parentItem());
+                tr->parentItem()->setFlags(QGraphicsItem::ItemIsSelectable);
+            } else {
+                m_selectionGroup->addToGroup(tr);
+                tr->setFlags(QGraphicsItem::ItemIsSelectable);
+            }
             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);
     }
     m_document->renderer()->blockSignals(false);
-    groupSelectedItems(true);
+
     if (m_selectionGroup) {
         bool snap = KdenliveSettings::snaptopoints();
         KdenliveSettings::setSnaptopoints(false);
 
-        m_selectionGroup->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
+        m_selectionGroup->translate(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
+        //m_selectionGroup->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
 
         QList<QGraphicsItem *> children = m_selectionGroup->childItems();
         // Expand groups
@@ -3446,7 +3588,7 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
         for (int i = 0; i < max; i++) {
             if (children.at(i)->type() == GROUPWIDGET) {
                 children += children.at(i)->childItems();
-                AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(children.at(i));
+                //AbstractGroupItem *grp = static_cast<AbstractGroupItem *>(children.at(i));
                 //grp->moveBy(offset.frames(m_document->fps()), trackOffset *(qreal) m_tracksHeight);
                 /*m_document->clipManager()->removeGroup(grp);
                 m_scene->destroyItemGroup(grp);*/
@@ -3477,10 +3619,11 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
                 kDebug() << "// inserting new clp: " << info.startPos.frames(25);
             } else if (item->type() == TRANSITIONWIDGET) {
                 Transition *tr = static_cast <Transition*>(item);
-                int newTrack = tr->transitionEndTrack();
+                int newTrack;
                 kDebug() << "/// TRANSITION CURR TRK: " << newTrack;
-                if (!tr->forcedTrack()) {
-                    newTrack += trackOffset;
+                if (!tr->forcedTrack()) newTrack = getPreviousVideoTrack(info.track);
+                else {
+                    newTrack = tr->transitionEndTrack() + trackOffset;
                     if (newTrack < 0 || newTrack > m_document->tracksCount()) newTrack = getPreviousVideoTrack(info.track);
                 }
                 tr->updateTransitionEndTrack(newTrack);
@@ -3488,6 +3631,7 @@ void CustomTrackView::moveGroup(QList <ItemInfo> startClip, QList <ItemInfo> sta
                 m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML());
             }
         }
+        resetSelectionGroup(false);
         KdenliveSettings::setSnaptopoints(snap);
         m_document->renderer()->doRefresh();
     } else kDebug() << "///////// WARNING; NO GROUP TO MOVE";
@@ -3513,6 +3657,7 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, b
         item->resizeStart((int) end.startPos.frames(m_document->fps()));
     } else if (end.startPos == start.startPos) {
         // Transition end resize;
+        kDebug() << "// resize END: " << end.endPos.frames(m_document->fps());
         item->resizeEnd((int) end.endPos.frames(m_document->fps()));
     } else {
         // Move & resize
@@ -3536,6 +3681,7 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, b
         emit transitionItemSelected(item, getPreviousVideoTrack(item->track()), p);
     }
     if (m_refresh) m_document->renderer()->doRefresh();
+    setDocumentModified();
 }
 
 void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry)
@@ -3562,7 +3708,7 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool
         if (success) {
             kDebug() << "RESIZE CLP STRAT TO:" << end.startPos.frames(m_document->fps()) << ", OLD ST: " << start.startPos.frames(25);
             item->resizeStart((int) end.startPos.frames(m_document->fps()));
-            updateClipFade(item);
+            updatePositionEffects(item, clipinfo);
         } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
     } else {
         ItemInfo clipinfo = item->info();
@@ -3570,7 +3716,7 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool
         bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, end.endPos - clipinfo.startPos);
         if (success) {
             item->resizeEnd((int) end.endPos.frames(m_document->fps()));
-            updateClipFade(item);
+            updatePositionEffects(item, clipinfo);
         } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage);
     }
     if (!resizeClipStart && end.cropStart != start.cropStart) {
@@ -3585,9 +3731,10 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool
     }
     m_document->renderer()->doRefresh();
     KdenliveSettings::setSnaptopoints(snap);
+    setDocumentModified();
 }
 
-void CustomTrackView::updateClipFade(ClipItem * item)
+void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info)
 {
     int end = item->fadeIn();
     if (end != 0) {
@@ -3669,6 +3816,20 @@ void CustomTrackView::updateClipFade(ClipItem * item)
             if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos);
         }
     }
+
+    int effectPos = item->hasEffect("freeze", "freeze");
+    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);
+        if (!eff.isNull()) {
+            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());
+            }
+        }
+    }
 }
 
 double CustomTrackView::getSnapPointForPos(double pos)
@@ -3817,6 +3978,7 @@ void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QSt
     DocClipBase *base = m_document->clipManager()->getClipById(id);
     if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
     else base->deleteSnapMarker(pos);
+    emit updateClipMarkers(base);
     setDocumentModified();
     viewport()->update();
 }
@@ -4207,11 +4369,10 @@ void CustomTrackView::pasteClip()
         // parse all clip names
         if (m_copiedItems.at(i) && m_copiedItems.at(i)->type() == AVWIDGET) {
             ClipItem *clip = static_cast <ClipItem *>(m_copiedItems.at(i));
-            ItemInfo info;
-            info.startPos = clip->startPos() + offset;
-            info.endPos = clip->endPos() + offset;
-            info.cropStart = clip->cropStart();
-            info.track = clip->track() + trackOffset;
+            ItemInfo info = clip->info();
+            info.startPos += offset;
+            info.endPos += offset;
+            info.track += trackOffset;
             if (canBePastedTo(info, AVWIDGET)) {
                 new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), info, clip->effectList(), true, false, pasteClips);
             } else emit displayMessage(i18n("Cannot paste clip to selected place"), ErrorMessage);
@@ -4221,10 +4382,13 @@ void CustomTrackView::pasteClip()
             info.startPos = tr->startPos() + offset;
             info.endPos = tr->endPos() + offset;
             info.track = tr->track() + trackOffset;
+            int transitionEndTrack;
+            if (!tr->forcedTrack()) transitionEndTrack = getPreviousVideoTrack(info.track);
+            else transitionEndTrack = tr->transitionEndTrack();
             if (canBePastedTo(info, TRANSITIONWIDGET)) {
                 if (info.startPos >= info.endPos) {
                     emit displayMessage(i18n("Invalid transition"), ErrorMessage);
-                } else new AddTransitionCommand(this, info, tr->transitionEndTrack() + trackOffset, tr->toXML(), false, true, pasteClips);
+                } else new AddTransitionCommand(this, info, transitionEndTrack, tr->toXML(), false, true, pasteClips);
             } else emit displayMessage(i18n("Cannot paste transition to selected place"), ErrorMessage);
         }
     }
@@ -4323,7 +4487,7 @@ void CustomTrackView::setInPoint()
     ItemInfo startInfo = clip->info();
     ItemInfo endInfo = startInfo;
     endInfo.startPos = GenTime(m_cursorPos, m_document->fps());
-    if (endInfo.startPos >= startInfo.endPos) {
+    if (endInfo.startPos >= startInfo.endPos || endInfo.startPos < startInfo.startPos - startInfo.cropStart) {
         // Check for invalid resize
         emit displayMessage(i18n("Invalid action"), ErrorMessage);
         return;
@@ -4354,13 +4518,15 @@ void CustomTrackView::setOutPoint()
     ItemInfo startInfo = clip->info();
     ItemInfo endInfo = clip->info();
     endInfo.endPos = GenTime(m_cursorPos, m_document->fps());
-    if (endInfo.endPos <= startInfo.startPos) {
+    CLIPTYPE type = (CLIPTYPE) static_cast <ClipItem *>(clip)->clipType();
+    if (endInfo.endPos <= startInfo.startPos || (type != IMAGE && type != COLOR && type != TEXT && endInfo.endPos > startInfo.startPos + clip->maxDuration() - startInfo.cropStart)) {
         // Check for invalid resize
         emit displayMessage(i18n("Invalid action"), ErrorMessage);
         return;
     } else if (endInfo.endPos > startInfo.endPos) {
-        int length = m_document->renderer()->mltGetSpaceLength(endInfo.endPos, m_document->tracksCount() - startInfo.track, false);
-        if ((clip->type() == TRANSITIONWIDGET && itemCollision(clip, endInfo) == true) || (clip->type() == AVWIDGET && length < (endInfo.endPos - startInfo.endPos).frames(m_document->fps()))) {
+        int length = m_document->renderer()->mltGetSpaceLength(startInfo.endPos, m_document->tracksCount() - startInfo.track, false);
+        if ((clip->type() == TRANSITIONWIDGET && itemCollision(clip, endInfo) == true) || (clip->type() == AVWIDGET && length != -1 && length < (endInfo.endPos - startInfo.endPos).frames(m_document->fps()))) {
+            kDebug() << " RESIZE ERROR, BLNK: " << length << ", RESIZE: " << (endInfo.endPos - startInfo.endPos).frames(m_document->fps());
             emit displayMessage(i18n("Invalid action"), ErrorMessage);
             return;
         }
@@ -4721,10 +4887,7 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
         if (freetrack == 0) {
             emit displayMessage(i18n("No empty space to put clip audio"), ErrorMessage);
         } else {
-            ItemInfo info;
-            info.startPos = clip->startPos();
-            info.endPos = clip->endPos();
-            info.cropStart = clip->cropStart();
+            ItemInfo info = clip->info();
             info.track = m_document->tracksCount() - freetrack;
             addClip(clip->xml(), clip->clipProducer(), info, clip->effectList());
             scene()->clearSelection();
@@ -4732,8 +4895,12 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
             ClipItem *audioClip = getClipItemAt(start, info.track);
             if (audioClip) {
                 clip->setVideoOnly(true);
-                m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer());
-                m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track));
+                if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == 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);
+                }
                 audioClip->setSelected(true);
                 audioClip->setAudioOnly(true);
                 groupSelectedItems(false, true);
@@ -4757,7 +4924,9 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split)
                 ItemInfo info = clip->info();
                 deleteClip(clp->info());
                 clip->setVideoOnly(false);
-                m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->producer(info.track));
+                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);
+                }
                 break;
             }
         }
@@ -4853,17 +5022,23 @@ void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool video
         int start = pos.frames(m_document->fps());
         clip->setVideoOnly(true);
         clip->setAudioOnly(false);
-        m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer());
+        if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == 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);
-        m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track));
+        if (m_document->renderer()->mltUpdateClipProducer(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);
-        m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->producer(track));
+        if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->producer(track)) == false) {
+            emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
+        }
     }
     clip->update();
     setDocumentModified();
@@ -4987,5 +5162,3 @@ void CustomTrackView::updateProjectFps()
     }
     viewport()->update();
 }
-
-#include "customtrackview.moc"
\ No newline at end of file