]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
cleanup and now every change of transitions tag updates the monitor
[kdenlive] / src / customtrackview.cpp
index 22b82c4c2edd71f2065b51a517026990746f2a49..be7920659d71ae1b3694d38d9156746bfb8a2b0f 100644 (file)
@@ -29,6 +29,7 @@
 #include <KCursor>
 
 #include "customtrackview.h"
+#include "docclipbase.h"
 #include "clipitem.h"
 #include "definitions.h"
 #include "moveclipcommand.h"
 #include "addeffectcommand.h"
 #include "editeffectcommand.h"
 #include "addtransitioncommand.h"
+#include "edittransitioncommand.h"
 #include "kdenlivesettings.h"
 #include "transition.h"
-
+#include "clipitem.h"
+#include "customtrackview.h"
+#include "clipmanager.h"
+#include "renderer.h"
 //TODO:
 // disable animation if user asked it in KDE's global settings
 // http://lists.kde.org/?l=kde-commits&m=120398724717624&w=2
@@ -49,7 +54,7 @@
 // const int duration = animate ? 1500 : 1;
 
 CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
-        : QGraphicsView(projectscene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()) {
+        : QGraphicsView(projectscene, parent), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()) {
     if (doc) m_commandStack = doc->commandStack();
     else m_commandStack == NULL;
     setMouseTracking(true);
@@ -64,7 +69,7 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene
     m_tipPen.setWidth(3);
     setContentsMargins(0, 0, 0, 0);
     if (projectscene) {
-        m_cursorLine = projectscene->addLine(0, 0, 0, 50);
+        m_cursorLine = projectscene->addLine(0, 0, 0, m_tracksHeight);
         m_cursorLine->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIgnoresTransformations);
         m_cursorLine->setZValue(1000);
     }
@@ -80,6 +85,33 @@ void CustomTrackView::checkAutoScroll() {
     m_autoScroll = KdenliveSettings::autoscroll();
 }
 
+QList <TrackInfo> CustomTrackView::tracksList() const {
+    return m_tracksList;
+}
+
+void CustomTrackView::checkTrackHeight() {
+    if (m_tracksHeight == KdenliveSettings::trackheight()) return;
+    m_tracksHeight = KdenliveSettings::trackheight();
+    emit trackHeightChanged();
+    QList<QGraphicsItem *> itemList = items();
+    ClipItem *item;
+    Transition *transitionitem;
+    for (int i = 0; i < itemList.count(); i++) {
+        if (itemList.at(i)->type() == AVWIDGET) {
+            item = (ClipItem*) itemList.at(i);
+            item->setRect(item->rect().x(), item->track() * m_tracksHeight, item->rect().width(), m_tracksHeight - 1);
+            item->resetThumbs();
+        } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
+            transitionitem = (Transition*) itemList.at(i);
+            transitionitem->setRect(transitionitem->rect().x(), transitionitem->track() * m_tracksHeight + m_tracksHeight / 2, transitionitem->rect().width(), m_tracksHeight - 1);
+        }
+    }
+    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
+    setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_tracksList.count());
+    verticalScrollBar()->setMaximum(m_tracksHeight * m_tracksList.count());
+    update();
+}
+
 // virtual
 void CustomTrackView::resizeEvent(QResizeEvent * event) {
     QGraphicsView::resizeEvent(event);
@@ -96,11 +128,20 @@ void CustomTrackView::wheelEvent(QWheelEvent * e) {
     }
 }
 
+int CustomTrackView::getPreviousVideoTrack(int track) {
+    track = m_tracksList.count() - track - 1;
+    int videoTracksCount = 0;
+    track --;
+    for (int i = track; i > -1; i--) {
+        if (m_tracksList.at(i).type == VIDEOTRACK) return i + 1;
+    }
+    return 0;
+}
 
 // virtual
 void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
     int pos = event->x();
-    emit mousePosition(mapToScene(event->pos()).x() / m_scale);
+    emit mousePosition((int)(mapToScene(event->pos()).x() / m_scale));
     /*if (event->modifiers() == Qt::ControlModifier)
       setDragMode(QGraphicsView::ScrollHandDrag);
     else if (event->modifiers() == Qt::ShiftModifier)
@@ -113,27 +154,27 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
             if (m_operationMode == MOVE) {
                 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x() - m_clickPoint.x());
                 //kDebug() << "///////  MOVE CLIP, EVENT Y: "<<m_clickPoint.y();//<<event->scenePos().y()<<", SCENE HEIGHT: "<<scene()->sceneRect().height();
-                int moveTrack = (int)  mapToScene(event->pos() + QPoint(0, (m_dragItem->type() == TRANSITIONWIDGET ? 50 - m_clickPoint.y() : 0))).y() / 50;
+                int moveTrack = (int)  mapToScene(event->pos() + QPoint(0, (m_dragItem->type() == TRANSITIONWIDGET ? m_tracksHeight - m_clickPoint.y() : 0))).y() / m_tracksHeight;
                 int currentTrack = m_dragItem->track();
 
-                if (moveTrack > m_tracksCount - 1) moveTrack = m_tracksCount - 1;
+                if (moveTrack > m_tracksList.count() - 1) moveTrack = m_tracksList.count() - 1;
                 else if (moveTrack < 0) moveTrack = 0;
 
                 int offset = moveTrack - currentTrack;
-                if (offset != 0) offset = 50 * offset;
-                m_dragItem->moveTo(snappedPos / m_scale, m_scale, offset, moveTrack);
+                if (offset != 0) offset = m_tracksHeight * offset;
+                m_dragItem->moveTo((int)(snappedPos / m_scale), m_scale, offset, moveTrack);
             } else if (m_operationMode == RESIZESTART) {
                 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
-                m_dragItem->resizeStart(snappedPos / m_scale, m_scale);
+                m_dragItem->resizeStart((int)(snappedPos / m_scale), m_scale);
             } else if (m_operationMode == RESIZEEND) {
                 double snappedPos = getSnapPointForPos(mapToScene(event->pos()).x());
-                m_dragItem->resizeEnd(snappedPos / m_scale, m_scale);
+                m_dragItem->resizeEnd((int)(snappedPos / m_scale), m_scale);
             } else if (m_operationMode == FADEIN) {
-                int pos = mapToScene(event->pos()).x() / m_scale;
-                m_dragItem->setFadeIn(pos - m_dragItem->startPos().frames(m_document->fps()), m_scale);
+                int pos = (int)(mapToScene(event->pos()).x() / m_scale);
+                m_dragItem->setFadeIn((int)(pos - m_dragItem->startPos().frames(m_document->fps())), m_scale);
             } else if (m_operationMode == FADEOUT) {
-                int pos = mapToScene(event->pos()).x() / m_scale;
-                m_dragItem->setFadeOut(m_dragItem->endPos().frames(m_document->fps()) - pos, m_scale);
+                int pos = (int)(mapToScene(event->pos()).x() / m_scale);
+                m_dragItem->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - pos), m_scale);
             }
 
             if (m_animation) delete m_animation;
@@ -177,10 +218,10 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
                 kDebug() << "********  RESIZE CLIP START; WIDTH: " << size;
                 if (m_visualTip == NULL) {
                     QPolygon polygon;
-                    polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
-                    polygon << QPoint(clip->rect().x() + size * 2, clip->rect().y() + clip->rect().height() / 2);
-                    polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 + size * 2);
-                    polygon << QPoint(clip->rect().x(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
+                    polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
+                    polygon << QPoint((int)(clip->rect().x() + size * 2), (int)(clip->rect().y() + clip->rect().height() / 2));
+                    polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 + size * 2));
+                    polygon << QPoint((int)clip->rect().x(), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
 
                     m_visualTip = new QGraphicsPolygonItem(polygon);
                     ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
@@ -203,10 +244,10 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
                 setCursor(KCursor("right_side", Qt::SizeHorCursor));
                 if (m_visualTip == NULL) {
                     QPolygon polygon;
-                    polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
-                    polygon << QPoint(clip->rect().x() + clip->rect().width() - size * 2, clip->rect().y() + clip->rect().height() / 2);
-                    polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 + size * 2);
-                    polygon << QPoint(clip->rect().x() + clip->rect().width(), clip->rect().y() + clip->rect().height() / 2 - size * 2);
+                    polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
+                    polygon << QPoint((int)(clip->rect().x() + clip->rect().width() - size * 2), (int)(clip->rect().y() + clip->rect().height() / 2));
+                    polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 + size * 2));
+                    polygon << QPoint((int)(clip->rect().x() + clip->rect().width()), (int)(clip->rect().y() + clip->rect().height() / 2 - size * 2));
 
                     m_visualTip = new QGraphicsPolygonItem(polygon);
                     ((QGraphicsPolygonItem*) m_visualTip)->setBrush(m_tipColor);
@@ -306,7 +347,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
         } else {
             m_moveOpMode = NONE;
             if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
-                setCursorPos((int) mapToScene(event->pos().x(), 0).x() / m_scale);
+                setCursorPos((int)(mapToScene(event->pos().x(), 0).x() / m_scale));
             }
             if (m_visualTip) {
                 if (m_animation) delete m_animation;
@@ -343,9 +384,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
             if (item->type() == AVWIDGET || item->type() == TRANSITIONWIDGET) {
                 // select item
                 if (!item->isSelected()) {
-                    QList<QGraphicsItem *> itemList = items();
-                    for (int i = 0; i < itemList.count(); i++)
-                        itemList.at(i)->setSelected(false);
+
                     item->setSelected(true);
                     update();
                 }
@@ -356,7 +395,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
                 } else if (item->type() == TRANSITIONWIDGET) {
                     transitionItem = m_dragItem;
                 }
-                m_clickPoint = QPoint(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps()) * m_scale, event->pos().y() - m_dragItem->rect().top());
+                m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps()) * m_scale), (int)(event->pos().y() - m_dragItem->rect().top()));
                 m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
                 if (m_operationMode == MOVE) setCursor(Qt::ClosedHandCursor);
                 if (m_operationMode == MOVE || m_operationMode == RESIZESTART)
@@ -365,8 +404,8 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
                     m_startPos = QPointF(m_dragItem->endPos().frames(m_document->fps()), m_dragItem->track());
                 else if (m_operationMode == TRANSITIONSTART) {
                     Transition *tr = new Transition(
-                        QRect(m_dragItem->startPos().frames(m_document->fps()) *m_scale , m_dragItem->rect().y() + m_dragItem->rect().height() / 2,
-                              GenTime(2.5).frames(m_document->fps()) *m_scale ,  m_dragItem->rect().height()
+                        QRect((int)(m_dragItem->startPos().frames(m_document->fps()) *m_scale) , (int)(m_dragItem->rect().y() + m_dragItem->rect().height() / 2),
+                              (int)(GenTime(2.5).frames(m_document->fps()) *m_scale) , (int)(m_dragItem->rect().height())
                              ),
                         (ClipItem*)m_dragItem, "luma" , m_dragItem->startPos(), m_dragItem->startPos() + GenTime(2.5), m_document->fps());
                     tr->setTrack(m_dragItem->track());
@@ -391,7 +430,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
             //emit clipItemSelected(NULL);
             if (event->button() == Qt::RightButton) {
                 displayContextMenu(event->globalPos());
-            } else setCursorPos((int) mapToScene(event->x(), 0).x() / m_scale);
+            } else setCursorPos((int)(mapToScene(event->x(), 0).x() / m_scale));
         } else if (event->button() == Qt::RightButton) {
             m_operationMode = NONE;
             displayContextMenu(event->globalPos(), (ClipItem *) m_dragItem);
@@ -425,7 +464,7 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
 }
 
 void CustomTrackView::slotRefreshEffects(ClipItem *clip) {
-    int track = m_tracksCount - clip->track();
+    int track = m_tracksList.count() - clip->track();
     GenTime pos = clip->startPos();
     m_document->renderer()->mltRemoveEffect(track, pos, "-1", false);
     for (int i = 0; i < clip->effectsCount(); i++) {
@@ -435,7 +474,7 @@ void CustomTrackView::slotRefreshEffects(ClipItem *clip) {
 }
 
 void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) {
-    ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track);
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
     if (clip) {
         QMap <QString, QString> effectParams = clip->addEffect(effect);
         m_document->renderer()->mltAddEffect(track, pos, effectParams);
@@ -446,7 +485,7 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) {
 void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) {
     QString index = effect.attribute("kdenlive_ix");
     m_document->renderer()->mltRemoveEffect(track, pos, index);
-    ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track);
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
     if (clip) {
         clip->deleteEffect(index);
         emit clipItemSelected(clip);
@@ -458,7 +497,7 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
     if (track == -1)
         itemList = items();
     else {
-        ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, track);
+        ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, track);
         if (clip) itemList.append(clip);
         else kDebug() << "------   wrning, clip eff not found";
     }
@@ -470,7 +509,7 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
             // not be changed
             if (effect.attribute("kdenlive_ix").toInt() == 0)
                 effect.setAttribute("kdenlive_ix", QString::number(item->effectsCounter()));
-            AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(), item->startPos(), effect, true);
+            AddEffectCommand *command = new AddEffectCommand(this, m_tracksList.count() - item->track(), item->startPos(), effect, true);
             m_commandStack->push(command);
         }
     }
@@ -478,19 +517,19 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
 }
 
 void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect) {
-    AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - clip->track(), clip->startPos(), effect, false);
+    AddEffectCommand *command = new AddEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), effect, false);
     m_commandStack->push(command);
     m_document->setModified(true);
 }
 
 void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect) {
-    ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track);
+    ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_tracksList.count() - track);
     if (clip) {
         QMap <QString, QString> effectParams = clip->getEffectArgs(effect);
         if (effectParams["disabled"] == "1") {
             QString index = effectParams["kdenlive_ix"];
             m_document->renderer()->mltRemoveEffect(track, pos, index);
-        } else m_document->renderer()->mltEditEffect(m_tracksCount - clip->track(), clip->startPos(), effectParams);
+        } else m_document->renderer()->mltEditEffect(m_tracksList.count() - clip->track(), clip->startPos(), effectParams);
     }
     m_document->setModified(true);
 }
@@ -498,33 +537,42 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect) {
 void CustomTrackView::slotChangeEffectState(ClipItem *clip, QDomElement effect, bool disable) {
     QDomElement oldEffect = effect.cloneNode().toElement();
     effect.setAttribute("disabled", disable);
-    EditEffectCommand *command = new EditEffectCommand(this, m_tracksCount - clip->track(), clip->startPos(), oldEffect, effect, true);
+    EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldEffect, effect, true);
     m_commandStack->push(command);
     m_document->setModified(true);
 }
 
 void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect) {
-    EditEffectCommand *command = new EditEffectCommand(this, m_tracksCount - clip->track(), clip->startPos(), oldeffect, effect, true);
+    EditEffectCommand *command = new EditEffectCommand(this, m_tracksList.count() - clip->track(), clip->startPos(), oldeffect, effect, true);
     m_commandStack->push(command);
 }
 
 void CustomTrackView::slotAddTransition(ClipItem* clip , QDomElement transition, GenTime startTime , int startTrack) {
     AddTransitionCommand* command = new AddTransitionCommand(this, startTrack, transition, startTime, true);
     m_commandStack->push(command);
+    m_document->setModified(true);
 }
 
 void CustomTrackView::addTransition(int startTrack, GenTime startPos , QDomElement e) {
     QMap < QString, QString> map;
+    QString s;
+    QTextStream tx(&s);
+    e.save(tx, 2);
+    kDebug() << "in" << s;
 
-    QDomNamedNodeMap attribs = e.attributes();
+    QDomNodeList attribs = e.elementsByTagName("parameter");
     for (int i = 0;i < attribs.count();i++) {
-        if (attribs.item(i).nodeName() != "type" &&
-                attribs.item(i).nodeName() != "start" &&
-                attribs.item(i).nodeName() != "end"
-           )
-            map[attribs.item(i).nodeName()] = attribs.item(i).nodeValue();
+        QDomNamedNodeMap atts = attribs.item(i).attributes();
+        if (!atts.namedItem("value").nodeValue().isEmpty()) {
+            map[atts.namedItem("name").nodeValue()] = atts.namedItem("value").nodeValue();
+        } else {
+            map[atts.namedItem("name").nodeValue()] = atts.namedItem("default").nodeValue();
+        }
+
     }
-    m_document->renderer()->mltAddTransition(e.attribute("type"), 4 - e.attribute("transition_track").toInt(), 5 - e.attribute("transition_track").toInt() ,
+    //map["resource"] = "%luma12.pgm";
+    kDebug() << "---- ADDING transition " << e.attribute("tag") << ", on tracks " << m_tracksList.count() - e.attribute("transition_track").toInt() << " / " << getPreviousVideoTrack(e.attribute("transition_track").toInt());
+    m_document->renderer()->mltAddTransition(e.attribute("tag"), getPreviousVideoTrack(e.attribute("transition_track").toInt()), m_tracksList.count() - e.attribute("transition_track").toInt() ,
             GenTime(e.attribute("start").toInt(), m_document->renderer()->fps()),
             GenTime(e.attribute("end").toInt(), m_document->renderer()->fps()),
             map);
@@ -535,19 +583,50 @@ void CustomTrackView::addTransition(int startTrack, GenTime startPos , QDomEleme
 void CustomTrackView::deleteTransition(int, GenTime, QDomElement e) {
     QMap < QString, QString> map;
     QDomNamedNodeMap attribs = e.attributes();
-    m_document->renderer()->mltDeleteTransition(e.attribute("type"), 4 - e.attribute("transition_track").toInt(), 5 - e.attribute("transition_track").toInt() ,
+    m_document->renderer()->mltDeleteTransition(e.attribute("tag"), getPreviousVideoTrack(e.attribute("transition_track").toInt()), m_tracksList.count() - e.attribute("transition_track").toInt() ,
             GenTime(e.attribute("start").toInt(), m_document->renderer()->fps()),
             GenTime(e.attribute("end").toInt(), m_document->renderer()->fps()),
             map);
     m_document->setModified(true);
 }
 
+void CustomTrackView::slotTransitionUpdated(QDomElement old, QDomElement newEffect) {
+    EditTransitionCommand *command = new EditTransitionCommand(this, newEffect.attribute("a_track").toInt(), GenTime(newEffect.attribute("start").toInt(), m_document->renderer()->fps()) , old, newEffect , true);
+    m_commandStack->push(command);
+    m_document->setModified(true);
+}
+
+void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTransition, QDomElement transition) {
+    QString s;
+    QTextStream tx(&s);
+    transition.save(tx, 2);
+    kDebug() << "in" << s;
+    QMap < QString, QString> map;
+
+    QDomNodeList attribs = transition.elementsByTagName("parameter");
+    for (int i = 0;i < attribs.count();i++) {
+        QDomNamedNodeMap atts = attribs.item(i).attributes();
+        if (!atts.namedItem("value").nodeValue().isEmpty()) {
+            map[atts.namedItem("name").nodeValue()] = atts.namedItem("value").nodeValue();
+        } else {
+            map[atts.namedItem("name").nodeValue()] = atts.namedItem("default").nodeValue();
+        }
+
+    }
+    m_document->renderer()->mltUpdateTransition(oldTransition.attribute("tag"), transition.attribute("tag"), m_tracksList.count() - 1  - transition.attribute("transition_track").toInt(), m_tracksList.count() - transition.attribute("transition_track").toInt() ,
+            GenTime(transition.attribute("start").toInt(), m_document->renderer()->fps()),
+            GenTime(transition.attribute("end").toInt(), m_document->renderer()->fps()),
+            map);
+    repaint();
+    m_document->setModified(true);
+}
+
 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) {
     int in = 0;
     GenTime out = clip->duration();
     //kdDebug()<<"- - - -CREATING CLIP, duration = "<<out<<", URL: "<<clip->fileURL();
-    int trackTop = ((int) mapToScene(pos).y() / 50) * 50 + 1;
-    m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y() / 50), GenTime(), QRectF(mapToScene(pos).x() * m_scale, trackTop, out.frames(m_document->fps()) * m_scale, 49), out, m_document->fps());
+    int trackTop = ((int) mapToScene(pos).y() / m_tracksHeight) * m_tracksHeight + 1;
+    m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y() / m_tracksHeight), GenTime(), QRectF(mapToScene(pos).x() * m_scale, trackTop, out.frames(m_document->fps()) * m_scale, m_tracksHeight - 1), out, m_document->fps());
     scene()->addItem(m_dropItem);
 }
 
@@ -556,8 +635,8 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
     event->setDropAction(Qt::IgnoreAction);
     //kDebug()<<"+++++++++++++   DRAG MOVE, : "<<mapToScene(event->pos()).x()<<", SCAL: "<<m_scale;
     if (m_dropItem) {
-        int track = (int) mapToScene(event->pos()).y() / 50; //) * (m_scale * 50) + m_scale;
-        m_dropItem->moveTo(mapToScene(event->pos()).x() / m_scale, m_scale, (track - m_dropItem->track()) * 50, track);
+        int track = (int)(event->pos().y() / m_tracksHeight);  //) * (m_scale * 50) + m_scale;
+        m_dropItem->moveTo((int)(mapToScene(event->pos()).x() / m_scale), m_scale, (double)(track - m_dropItem->track()) * m_tracksHeight, track);
         event->setDropAction(Qt::MoveAction);
         if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
             event->acceptProposedAction();
@@ -580,8 +659,8 @@ void CustomTrackView::dropEvent(QDropEvent * event) {
         m_commandStack->push(command);
         m_dropItem->baseClip()->addReference();
         m_document->updateClip(m_dropItem->baseClip()->getId());
-        // kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_tracksCount<<", DROP: "<<m_dropItem->track();
-        m_document->renderer()->mltInsertClip(m_tracksCount - m_dropItem->track(), m_dropItem->startPos(), m_dropItem->xml());
+        // kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_tracksList.count()<<", DROP: "<<m_dropItem->track();
+        m_document->renderer()->mltInsertClip(m_tracksList.count() - m_dropItem->track(), m_dropItem->startPos(), m_dropItem->xml());
         m_document->setModified(true);
     } else QGraphicsView::dropEvent(event);
     m_dropItem = NULL;
@@ -602,26 +681,41 @@ Qt::DropActions CustomTrackView::supportedDropActions() const {
 }
 
 void CustomTrackView::setDuration(int duration) {
-    kDebug() << "/////////////  PRO DUR: " << duration << ", height: " << 50 * m_tracksCount;
+    kDebug() << "/////////////  PRO DUR: " << duration << ", SCALE. " << (m_projectDuration + 500) * m_scale << ", height: " << 50 * m_tracksList.count();
     m_projectDuration = duration;
-    scene()->setSceneRect(0, 0, (m_projectDuration + 500) * m_scale, scene()->sceneRect().height()); //50 * m_tracksCount);
+    setSceneRect(0, 0, (m_projectDuration + 100) * m_scale, sceneRect().height());
 }
 
 int CustomTrackView::duration() const {
     return m_projectDuration;
 }
 
-void CustomTrackView::addTrack() {
-    m_tracksCount++;
-    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
-    //setSceneRect(0, 0, sceneRect().width(), 50 * m_tracksCount);
-    //verticalScrollBar()->setMaximum(50 * m_tracksCount);
+void CustomTrackView::addTrack(TrackInfo type) {
+    m_tracksList << type;
+    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
+    setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_tracksList.count());
+    verticalScrollBar()->setMaximum(m_tracksHeight * m_tracksList.count());
     //setFixedHeight(50 * m_tracksCount);
 }
 
 void CustomTrackView::removeTrack() {
-    m_tracksCount--;
-    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
+    // TODO: implement track deletion
+    //m_tracksCount--;
+    m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
+}
+
+
+void CustomTrackView::slotSwitchTrackAudio(int ix) {
+    int tracknumber = m_tracksList.count() - ix;
+    kDebug() << "/////  MUTING TRK: " << ix << "; PL NUM: " << tracknumber;
+    m_tracksList[tracknumber - 1].isMute = !m_tracksList.at(tracknumber - 1).isMute;
+    m_document->renderer()->mltChangeTrackState(tracknumber, m_tracksList.at(tracknumber - 1).isMute, m_tracksList.at(tracknumber - 1).isBlind);
+}
+
+void CustomTrackView::slotSwitchTrackVideo(int ix) {
+    int tracknumber = m_tracksList.count() - ix;
+    m_tracksList[tracknumber - 1].isBlind = !m_tracksList.at(tracknumber - 1).isBlind;
+    m_document->renderer()->mltChangeTrackState(tracknumber, m_tracksList.at(tracknumber - 1).isMute, m_tracksList.at(tracknumber - 1).isBlind);
 }
 
 void CustomTrackView::deleteClip(int clipId) {
@@ -639,7 +733,7 @@ void CustomTrackView::deleteClip(int clipId) {
 }
 
 void CustomTrackView::setCursorPos(int pos, bool seek) {
-    emit cursorMoved(m_cursorPos * m_scale, pos * m_scale);
+    emit cursorMoved((int)(m_cursorPos * m_scale), (int)(pos * m_scale));
     m_cursorPos = pos;
     m_cursorLine->setPos(pos * m_scale, 0);
     if (seek) m_document->renderer()->seek(GenTime(pos, m_document->fps()));
@@ -651,7 +745,7 @@ void CustomTrackView::updateCursorPos() {
 }
 
 int CustomTrackView::cursorPos() {
-    return m_cursorPos * m_scale;
+    return (int)(m_cursorPos * m_scale);
 }
 
 void CustomTrackView::checkScrolling() {
@@ -659,7 +753,7 @@ void CustomTrackView::checkScrolling() {
     int delta = rectInView.width() / 3;
     int max = rectInView.right() + horizontalScrollBar()->value() - delta;
     //kDebug() << "CURSOR POS: "<<m_cursorPos<< "Scale: "<<m_scale;
-    if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 1 + m_scale);
+    if (m_cursorPos * m_scale >= max) horizontalScrollBar()->setValue((int)(horizontalScrollBar()->value() + 1 + m_scale));
 }
 
 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
@@ -671,19 +765,19 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
         // move clip
         MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos().frames(m_document->fps()), m_dragItem->track()), false);
         m_commandStack->push(command);
-        if (m_dragItem->type() == AVWIDGET) m_document->renderer()->mltMoveClip(m_tracksCount - m_startPos.y(), m_tracksCount - m_dragItem->track(), m_startPos.x(), m_dragItem->startPos().frames(m_document->fps()));
+        if (m_dragItem->type() == AVWIDGET) m_document->renderer()->mltMoveClip((int)(m_tracksList.count() - m_startPos.y()), (int)(m_tracksList.count() - m_dragItem->track()), (int) m_startPos.x(), (int)(m_dragItem->startPos().frames(m_document->fps())));
     } else if (m_operationMode == RESIZESTART) {
         // resize start
         ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos().frames(m_document->fps()), m_dragItem->track()), true, false);
 
-        if (m_dragItem->type() == AVWIDGET) m_document->renderer()->mltResizeClipStart(m_tracksCount - m_dragItem->track(), m_dragItem->endPos(), m_dragItem->startPos(), GenTime(m_startPos.x(), m_document->fps()), m_dragItem->cropStart(), m_dragItem->cropStart() + m_dragItem->endPos() - m_dragItem->startPos());
+        if (m_dragItem->type() == AVWIDGET) m_document->renderer()->mltResizeClipStart(m_tracksList.count() - m_dragItem->track(), m_dragItem->endPos(), m_dragItem->startPos(), GenTime((int)m_startPos.x(), m_document->fps()), m_dragItem->cropStart(), m_dragItem->cropStart() + m_dragItem->endPos() - m_dragItem->startPos());
         m_commandStack->push(command);
         m_document->renderer()->doRefresh();
     } else if (m_operationMode == RESIZEEND) {
         // resize end
         ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos().frames(m_document->fps()), m_dragItem->track()), false, false);
 
-        if (m_dragItem->type() == AVWIDGET) m_document->renderer()->mltResizeClipEnd(m_tracksCount - m_dragItem->track(), m_dragItem->startPos(), m_dragItem->cropStart(), m_dragItem->cropStart() + m_dragItem->endPos() - m_dragItem->startPos());
+        if (m_dragItem->type() == AVWIDGET) m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - m_dragItem->track(), m_dragItem->startPos(), m_dragItem->cropStart(), m_dragItem->cropStart() + m_dragItem->endPos() - m_dragItem->startPos());
         m_commandStack->push(command);
         m_document->renderer()->doRefresh();
     }
@@ -701,7 +795,7 @@ void CustomTrackView::deleteClip(int track, GenTime startpos, const QRectF &rect
     item->baseClip()->removeReference();
     m_document->updateClip(item->baseClip()->getId());
     delete item;
-    m_document->renderer()->mltRemoveClip(m_tracksCount - track, startpos);
+    m_document->renderer()->mltRemoveClip(m_tracksList.count() - track, startpos);
     m_document->renderer()->doRefresh();
 }
 
@@ -717,58 +811,58 @@ void CustomTrackView::deleteSelectedClips() {
 }
 
 void CustomTrackView::addClip(QDomElement xml, int clipId, int track, GenTime startpos, const QRectF &rect, GenTime duration) {
-    QRect r(startpos.frames(m_document->fps()) * m_scale, 50 * track, duration.frames(m_document->fps()) * m_scale, 49);
+    QRect r((int)(startpos.frames(m_document->fps()) * m_scale), m_tracksHeight * track, (int)(duration.frames(m_document->fps()) * m_scale), m_tracksHeight - 1);
     DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
     ClipItem *item = new ClipItem(baseclip, track, startpos, r, duration, m_document->fps());
     scene()->addItem(item);
     baseclip->addReference();
     m_document->updateClip(baseclip->getId());
-    m_document->renderer()->mltInsertClip(m_tracksCount - track, startpos, xml);
+    m_document->renderer()->mltInsertClip(m_tracksList.count() - track, startpos, xml);
     m_document->renderer()->doRefresh();
 }
 
 ClipItem *CustomTrackView::getClipItemAt(int pos, int track) {
-    return (ClipItem *) scene()->itemAt(pos * m_scale, track * 50 + 25);
+    return (ClipItem *) scene()->itemAt(pos * m_scale, track * m_tracksHeight + m_tracksHeight / 2);
 }
 
 ClipItem *CustomTrackView::getClipItemAt(GenTime pos, int track) {
-    return (ClipItem *) scene()->itemAt(pos.frames(m_document->fps()) * m_scale, track * 50 + 25);
+    return (ClipItem *) scene()->itemAt(pos.frames(m_document->fps()) * m_scale, track * m_tracksHeight + m_tracksHeight / 2);
 }
 
 void CustomTrackView::moveClip(const QPointF &startPos, const QPointF &endPos) {
-    ClipItem *item = getClipItemAt(startPos.x() + 1, startPos.y());
+    ClipItem *item = getClipItemAt((int)startPos.x() + 1, (int)startPos.y());
     if (!item) {
-        kDebug() << "----------------  ERROR, CANNOT find clip to move at: " << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * 50 + 25;
+        kDebug() << "----------------  ERROR, CANNOT find clip to move at: " << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2;
         return;
     }
     kDebug() << "----------------  Move CLIP FROM: " << startPos.x() << ", END:" << endPos.x();
-    item->moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y());
-    m_document->renderer()->mltMoveClip(m_tracksCount - startPos.y(), m_tracksCount - endPos.y(), startPos.x(), endPos.x());
+    item->moveTo((int)endPos.x(), m_scale, (endPos.y() - startPos.y()) * m_tracksHeight, (int)endPos.y());
+    m_document->renderer()->mltMoveClip((int)(m_tracksList.count() - startPos.y()), (int)(m_tracksList.count() - endPos.y()), (int) startPos.x(), (int)endPos.x());
 }
 
 void CustomTrackView::resizeClip(const QPointF &startPos, const QPointF &endPos, bool resizeClipStart) {
     int offset;
     if (resizeClipStart) offset = 1;
     else offset = -1;
-    ClipItem *item = getClipItemAt(startPos.x() + offset, startPos.y());
+    ClipItem *item = getClipItemAt((int)(startPos.x() + offset), (int) startPos.y());
     if (!item) {
         kDebug() << "----------------  ERROR, CANNOT find clip to resize at: " << startPos;
         return;
     }
     qreal diff = endPos.x() - startPos.x();
     if (resizeClipStart) {
-        m_document->renderer()->mltResizeClipStart(m_tracksCount - item->track(), item->endPos(), GenTime(endPos.x(), m_document->fps()), item->startPos(), item->cropStart() + GenTime(diff, m_document->fps()), item->cropStart() + GenTime(diff, m_document->fps()) + item->endPos() - GenTime(endPos.x(), m_document->fps()));
-        item->resizeStart(endPos.x(), m_scale);
+        m_document->renderer()->mltResizeClipStart(m_tracksList.count() - item->track(), item->endPos(), GenTime((int)endPos.x(), m_document->fps()), item->startPos(), item->cropStart() + GenTime((int)diff, m_document->fps()), item->cropStart() + GenTime((int)diff, m_document->fps()) + item->endPos() - GenTime((int)endPos.x(), m_document->fps()));
+        item->resizeStart((int)endPos.x(), m_scale);
     } else {
-        m_document->renderer()->mltResizeClipEnd(m_tracksCount - item->track(), item->startPos(), item->cropStart(), item->cropStart() + GenTime(endPos.x(), m_document->fps()) - item->startPos());
-        item->resizeEnd(endPos.x(), m_scale);
+        m_document->renderer()->mltResizeClipEnd(m_tracksList.count() - item->track(), item->startPos(), item->cropStart(), item->cropStart() + GenTime((int)endPos.x(), m_document->fps()) - item->startPos());
+        item->resizeEnd((int)endPos.x(), m_scale);
     }
     m_document->renderer()->doRefresh();
 }
 
 double CustomTrackView::getSnapPointForPos(double pos) {
     for (int i = 0; i < m_snapPoints.size(); ++i) {
-        if (abs(pos - m_snapPoints.at(i).frames(m_document->fps()) * m_scale) < 10) {
+        if (abs((int)(pos - m_snapPoints.at(i).frames(m_document->fps()) * m_scale)) < 10) {
             //kDebug()<<" FOUND SNAP POINT AT: "<<m_snapPoints.at(i)<<", current pos: "<<pos / m_scale;
             return m_snapPoints.at(i).frames(m_document->fps()) * m_scale + 0.5;
         }
@@ -815,8 +909,8 @@ void CustomTrackView::setScale(double scaleFactor) {
         }
     }
     updateCursorPos();
-    centerOn(QPointF(cursorPos(), 50));
-    scene()->setSceneRect(0, 0, (m_projectDuration + 500) * m_scale, scene()->sceneRect().height());
+    centerOn(QPointF(cursorPos(), m_tracksHeight));
+    setSceneRect(0, 0, (m_projectDuration + 100) * m_scale, sceneRect().height());
 }
 
 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
@@ -826,11 +920,13 @@ void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
     QColor base = palette().button().color();
     painter->setClipRect(rect);
     painter->drawLine(rectInView.left(), 0, rectInView.right(), 0);
-    for (uint i = 0; i < m_tracksCount;i++) {
-        painter->drawLine(rectInView.left(), 50 * (i + 1), rectInView.right(), 50 * (i + 1));
+    uint max = m_tracksList.count();
+    for (uint i = 0; i < max;i++) {
+        if (m_tracksList.at(max - i - 1).type == AUDIOTRACK) painter->fillRect(rectInView.left(), m_tracksHeight * i + 1, rectInView.right() - rectInView.left() + 1, m_tracksHeight - 1, QBrush(QColor(240, 240, 255)));
+        painter->drawLine(rectInView.left(), m_tracksHeight * (i + 1), rectInView.right(), m_tracksHeight * (i + 1));
         //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i + 1));
     }
-    int lowerLimit = 50 * m_tracksCount + 1;
+    int lowerLimit = m_tracksHeight * m_tracksList.count() + 1;
     if (height() > lowerLimit)
         painter->fillRect(QRectF(rectInView.left(), lowerLimit, rectInView.width(), height() - lowerLimit), QBrush(base));
 }