]> git.sesse.net Git - kdenlive/commitdiff
Add track should work, delete track is still to do
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 2 Dec 2008 10:49:07 +0000 (10:49 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 2 Dec 2008 10:49:07 +0000 (10:49 +0000)
svn path=/branches/KDE4/; revision=2744

13 files changed:
src/CMakeLists.txt
src/addtrackcommand.cpp [new file with mode: 0644]
src/addtrackcommand.h [new file with mode: 0644]
src/customtrackview.cpp
src/customtrackview.h
src/moveclipcommand.cpp
src/moveclipcommand.h
src/moveeffectcommand.cpp
src/moveeffectcommand.h
src/projectlist.cpp
src/renderer.cpp
src/renderer.h
src/widgets/addtrack_ui.ui [new file with mode: 0644]

index eba7e5d8f3ebb013a52b388fa47cc8780151a57b..205d5f51096ec0a4a275d083bbb29c41ad939491 100644 (file)
@@ -60,6 +60,7 @@ kde4_add_ui_files(kdenlive_UI
   widgets/wizardstandard_ui.ui
   widgets/wizardextra_ui.ui
   widgets/spacerdialog_ui.ui
+  widgets/addtrack_ui.ui
 )
  
 set(kdenlive_SRCS 
@@ -135,6 +136,7 @@ set(kdenlive_SRCS
   editclipcommand.cpp
   insertspacecommand.cpp
   spacerdialog.cpp
+  addtrackcommand.cpp
 )
 
 if(NO_JOGSHUTTLE)
diff --git a/src/addtrackcommand.cpp b/src/addtrackcommand.cpp
new file mode 100644 (file)
index 0000000..184d066
--- /dev/null
@@ -0,0 +1,47 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#include <KLocale>
+
+#include "addtrackcommand.h"
+#include "customtrackview.h"
+
+AddTrackCommand::AddTrackCommand(CustomTrackView *view, int ix, TrackInfo info, bool addTrack, bool doIt, QUndoCommand * parent) : QUndoCommand(parent), m_view(view), m_ix(ix), m_info(info), m_addTrack(addTrack), m_doIt(doIt) {
+    if (addTrack) setText(i18n("Add track"));
+    else setText(i18n("Delete track"));
+}
+
+
+// virtual
+void AddTrackCommand::undo() {
+// kDebug()<<"----  undoing action";
+    m_doIt = true;
+    if (m_addTrack) m_view->deleteTimelineTrack(m_ix);
+    else m_view->addTimelineTrack(m_ix, m_info);
+}
+// virtual
+void AddTrackCommand::redo() {
+    kDebug() << "----  redoing action";
+    if (m_doIt) {
+        if (m_addTrack) m_view->addTimelineTrack(m_ix, m_info);
+        else m_view->deleteTimelineTrack(m_ix);
+    }
+    m_doIt = true;
+}
+
diff --git a/src/addtrackcommand.h b/src/addtrackcommand.h
new file mode 100644 (file)
index 0000000..787a03f
--- /dev/null
@@ -0,0 +1,48 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef ADDTRACKCOMMAND_H
+#define ADDTRACKCOMMAND_H
+
+#include <QUndoCommand>
+#include <QGraphicsView>
+#include <QPointF>
+
+#include <KDebug>
+#include "definitions.h"
+
+class CustomTrackView;
+
+class AddTrackCommand : public QUndoCommand {
+public:
+    AddTrackCommand(CustomTrackView *view, int ix, TrackInfo info, bool addTrack, bool doIt, QUndoCommand * parent = 0);
+    virtual void undo();
+    virtual void redo();
+
+private:
+    CustomTrackView *m_view;
+    int m_ix;
+    bool m_doIt;
+    bool m_addTrack;
+    TrackInfo m_info;
+};
+
+#endif
+
index 4d59c1efced379711d4fef13d77b840e94f78f44..f41af69e05ff6f2240b26f695fa9e6828ba6a641 100644 (file)
@@ -63,6 +63,8 @@
 #include "abstractgroupitem.h"
 #include "insertspacecommand.h"
 #include "spacerdialog.h"
+#include "addtrackcommand.h"
+#include "ui_addtrack_ui.h"
 
 //TODO:
 // disable animation if user asked it in KDE's global settings
@@ -794,7 +796,7 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
                     endInfo.startPos = d.startPos();
                     endInfo.endPos = m_dragItem->endPos() + (endInfo.startPos - startInfo.startPos);
                     endInfo.track = m_dragItem->track();
-                    MoveClipCommand *command = new MoveClipCommand(this, startInfo, endInfo, true);
+                    MoveClipCommand *command = new MoveClipCommand(this, startInfo, endInfo, false, true);
                     m_commandStack->push(command);
                 } else {
                     //TODO: move transition
@@ -1308,8 +1310,9 @@ int CustomTrackView::duration() const {
     return m_projectDuration;
 }
 
-void CustomTrackView::addTrack(TrackInfo type) {
-    m_scene->m_tracksList << type;
+void CustomTrackView::addTrack(TrackInfo type, int ix) {
+    if (ix == -1) m_scene->m_tracksList << type;
+    else m_scene->m_tracksList.insert(ix, type);
     m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_scene->m_tracksList.count());
     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_scene->m_tracksList.count());
     verticalScrollBar()->setMaximum(m_tracksHeight * m_scene->m_tracksList.count());
@@ -1513,7 +1516,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
                 ClipItem *item = static_cast <ClipItem *>(m_dragItem);
                 bool success = m_document->renderer()->mltMoveClip((int)(m_scene->m_tracksList.count() - m_dragItemInfo.track), (int)(m_scene->m_tracksList.count() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())), item->baseClip()->producer(info.track));
                 if (success) {
-                    MoveClipCommand *command = new MoveClipCommand(this, m_dragItemInfo, info, false);
+                    MoveClipCommand *command = new MoveClipCommand(this, m_dragItemInfo, info, false, false);
                     m_commandStack->push(command);
                     if (item->baseClip()->isTransparent()) {
                         // Also move automatic transition
@@ -1526,7 +1529,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
                     }
                 } else {
                     // undo last move and emit error message
-                    MoveClipCommand *command = new MoveClipCommand(this, info, m_dragItemInfo, true);
+                    MoveClipCommand *command = new MoveClipCommand(this, info, m_dragItemInfo, false, true);
                     m_commandStack->push(command);
                     emit displayMessage(i18n("Cannot move clip to position %1seconds", QString::number(m_dragItemInfo.startPos.seconds(), 'g', 2)), ErrorMessage);
                 }
@@ -1879,7 +1882,7 @@ Transition *CustomTrackView::getTransitionItemAt(GenTime pos, int track) {
     return getTransitionItemAt(framepos, track);
 }
 
-void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
+void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool forceProducer) {
     ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()) + 1, start.track);
     if (!item) {
         emit displayMessage(i18n("Cannot move clip at time: %1s on track %2", QString::number(start.startPos.seconds(), 'g', 2), start.track), ErrorMessage);
@@ -1888,7 +1891,7 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end) {
     }
     //kDebug() << "----------------  Move CLIP FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << startPos.y() << " TO " << endPos.y();
 
-    bool success = m_document->renderer()->mltMoveClip((int)(m_scene->m_tracksList.count() - start.track), (int)(m_scene->m_tracksList.count() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), item->baseClip()->producer(end.track));
+    bool success = m_document->renderer()->mltMoveClip((int)(m_scene->m_tracksList.count() - start.track), (int)(m_scene->m_tracksList.count() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), item->baseClip()->producer(end.track), forceProducer);
     if (success) {
         item->setPos((int) end.startPos.frames(m_document->fps()), (int)(end.track * m_tracksHeight + 1));
         if (item->baseClip()->isTransparent()) {
@@ -2592,10 +2595,79 @@ void CustomTrackView::slotUpdateAllThumbs() {
     }
 }
 
-void CustomTrackView::slotInsertTrack() {
+void CustomTrackView::slotInsertTrack(int ix) {
+    kDebug() << "// INSERTING TRK: " << ix;
+
+    QDialog d(parentWidget());
+    Ui::AddTrack_UI view;
+    view.setupUi(&d);
+    view.track_nb->setMaximum(m_scene->m_tracksList.count() - 1);
+    view.track_nb->setValue(ix);
+
+    if (d.exec() == QDialog::Accepted) {
+        if (view.before_select->currentIndex() == 2) {
+            kDebug() << "// AFTER";
+            ix++;
+        }
+        TrackInfo info;
+        if (view.video_track->isChecked()) {
+            info.type = VIDEOTRACK;
+            info.isMute = false;
+            info.isBlind = false;
+        } else {
+            info.type = AUDIOTRACK;
+            info.isMute = false;
+            info.isBlind = false;
+        }
+        AddTrackCommand* command = new AddTrackCommand(this, ix, info, true, true);
+        m_commandStack->push(command);
+    }
+}
+
+void CustomTrackView::slotDeleteTrack(int ix) {
+}
+
+void CustomTrackView::addTimelineTrack(int ix, TrackInfo info) {
+    double startY = ix * m_tracksHeight + 1 + m_tracksHeight / 2;
+    QRectF r(0, startY, sceneRect().width(), sceneRect().height() - startY);
+    QList<QGraphicsItem *> selection = m_scene->items(r);
+    kDebug() << "// TRK RECT: " << r << ", ITEMS: " << selection.count();
+    addTrack(info, m_scene->m_tracksList.count() - ix);
+    QUndoCommand *addTrack = new QUndoCommand();
+    addTrack->setText("Add track");
+
+    resetSelectionGroup();
+
+    m_selectionGroup = new AbstractGroupItem(m_document->fps());
+    scene()->addItem(m_selectionGroup);
+    for (int i = 0; i < selection.count(); i++) {
+        if (selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)
+            m_selectionGroup->addToGroup(selection.at(i));
+    }
+    // insert track in MLT playlist
+    m_document->renderer()->mltInsertTrack(m_scene->m_tracksList.count() - ix);
+
+    // Move graphic items
+    m_selectionGroup->setPos(m_selectionGroup->pos().x(), m_selectionGroup->pos().y() + m_tracksHeight);
+
+    // adjust track number
+    QList<QGraphicsItem *> children = m_selectionGroup->childItems();
+    for (int i = 0; i < children.count(); i++) {
+        AbstractClipItem *item = static_cast <AbstractClipItem *>(children.at(i));
+        item->updateItem();
+        if (item->type() == AV || item->type() == AUDIO) {
+            // We add a move clip command so that we get the correct producer for new track number
+            ItemInfo clipinfo = item->info();
+            MoveClipCommand(this, clipinfo, clipinfo, true, true, addTrack);
+        }
+    }
+    resetSelectionGroup();
+    m_commandStack->push(addTrack);
+    update();
+    emit trackHeightChanged();
 }
 
-void CustomTrackView::slotDeleteTrack() {
+void CustomTrackView::deleteTimelineTrack(int ix) {
 }
 
 #include "customtrackview.moc"
index 67f0dc3f6b3e1bfb038c0a4515983c341f801587..742c7e871f4cffb9192fc0c4ee56356b1d54878f 100644 (file)
@@ -48,11 +48,11 @@ public:
     virtual void mouseReleaseEvent(QMouseEvent * event);
     virtual void mouseMoveEvent(QMouseEvent * event);
     virtual void mouseDoubleClickEvent(QMouseEvent *event);
-    void addTrack(TrackInfo type);
+    void addTrack(TrackInfo type, int ix = -1);
     void removeTrack();
     int cursorPos();
     void checkAutoScroll();
-    void moveClip(const ItemInfo start, const ItemInfo end);
+    void moveClip(const ItemInfo start, const ItemInfo end, bool forceProducer);
     /** move transition, startPos = (old start, old end), endPos = (new start, new end) */
     void moveTransition(const ItemInfo start, const ItemInfo end);
     void resizeClip(const ItemInfo start, const ItemInfo end);
@@ -100,6 +100,8 @@ public:
     void slotRemoveSpace();
     void insertSpace(const GenTime &pos, int track, const GenTime duration, bool add);
     ClipItem *getActiveClipUnderCursor(bool allowOutsideCursor = false) const;
+    void addTimelineTrack(int ix, TrackInfo info);
+    void deleteTimelineTrack(int ix);
 
 public slots:
     void setCursorPos(int pos, bool seek = true);
@@ -131,8 +133,8 @@ public slots:
     void pasteClipEffects();
     void slotUpdateAllThumbs();
     void slotCheckPositionScrolling();
-    void slotInsertTrack();
-    void slotDeleteTrack();
+    void slotInsertTrack(int ix);
+    void slotDeleteTrack(int ix);
 
 protected:
     virtual void drawBackground(QPainter * painter, const QRectF & rect);
index 6767f673dd1d284d0fae7b8d6bfc16c8b49d38d1..1cc459bb6384df1ec5039a3365fcd2de5b46f93d 100644 (file)
@@ -21,8 +21,7 @@
 
 #include "moveclipcommand.h"
 #include "customtrackview.h"
-MoveClipCommand::MoveClipCommand(CustomTrackView *view, const ItemInfo start, const ItemInfo end, bool doIt)
-        : m_view(view), m_startPos(start), m_endPos(end), m_doIt(doIt) {
+MoveClipCommand::MoveClipCommand(CustomTrackView *view, const ItemInfo start, const ItemInfo end, bool forceProducer, bool doIt, QUndoCommand * parent) : QUndoCommand(parent), m_view(view), m_startPos(start), m_endPos(end), m_forceProducer(forceProducer), m_doIt(doIt) {
     setText(i18n("Move clip"));
 }
 
@@ -31,13 +30,13 @@ MoveClipCommand::MoveClipCommand(CustomTrackView *view, const ItemInfo start, co
 void MoveClipCommand::undo() {
 // kDebug()<<"----  undoing action";
     m_doIt = true;
-    m_view->moveClip(m_endPos, m_startPos);
+    m_view->moveClip(m_endPos, m_startPos, m_forceProducer);
 }
 // virtual
 void MoveClipCommand::redo() {
     kDebug() << "----  redoing action";
     if (m_doIt)
-        m_view->moveClip(m_startPos, m_endPos);
+        m_view->moveClip(m_startPos, m_endPos, m_forceProducer);
     m_doIt = true;
 }
 
index 7cf002ec6a5dd6b3b0188a4994796f131538928d..6c785a8c2dedd965e3d3469bd0b217292361ee7b 100644 (file)
@@ -32,7 +32,7 @@ class CustomTrackView;
 
 class MoveClipCommand : public QUndoCommand {
 public:
-    MoveClipCommand(CustomTrackView *view, const ItemInfo start, const ItemInfo end, bool doIt);
+    MoveClipCommand(CustomTrackView *view, const ItemInfo start, const ItemInfo end, bool forceProducer, bool doIt, QUndoCommand * parent = 0);
     virtual void undo();
     virtual void redo();
 
@@ -41,6 +41,7 @@ private:
     const ItemInfo m_startPos;
     const ItemInfo m_endPos;
     bool m_doIt;
+    bool m_forceProducer;
 };
 
 #endif
index 88df05ac8bb9c8932ad379ff874dfc95894af4a7..cc0e90ae16a898147340a6a100f74261f9175322 100644 (file)
@@ -22,8 +22,7 @@
 #include "moveeffectcommand.h"
 #include "customtrackview.h"
 
-MoveEffectCommand::MoveEffectCommand(CustomTrackView *view, const int track, GenTime pos, int oldPos, int newPos, bool doIt)
-        : m_view(view), m_track(track), m_pos(pos), m_oldindex(oldPos), m_newindex(newPos), m_doIt(doIt) {
+MoveEffectCommand::MoveEffectCommand(CustomTrackView *view, const int track, GenTime pos, int oldPos, int newPos, bool doIt, QUndoCommand * parent) : QUndoCommand(parent), m_view(view), m_track(track), m_pos(pos), m_oldindex(oldPos), m_newindex(newPos), m_doIt(doIt) {
     /*    QString effectName;
         QDomNode namenode = effect.elementsByTagName("name").item(0);
         if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data());
index e6f1802044550440764939aae8df632fb8f26b59..1ac6946b6006bc7d0539b4fe9d0215f98ceced7e 100644 (file)
@@ -30,7 +30,7 @@ class CustomTrackView;
 
 class MoveEffectCommand : public QUndoCommand {
 public:
-    MoveEffectCommand(CustomTrackView *view, const int track, GenTime pos, int oldPos, int newPos, bool doIt);
+    MoveEffectCommand(CustomTrackView *view, const int track, GenTime pos, int oldPos, int newPos, bool doIt, QUndoCommand * parent = 0);
 
     virtual int id() const;
     virtual bool mergeWith(const QUndoCommand * command);
index cf5fb0431d782f15873a54a61c4cb7e5df86e762..17b247dae712ad9e0e05af37e2153f144670a1f6 100644 (file)
@@ -58,6 +58,7 @@ ProjectList::ProjectList(QWidget *parent)
     QWidget *vbox = new QWidget;
     listView = new ProjectListView(this);;
     QVBoxLayout *layout = new QVBoxLayout;
+    layout->setContentsMargins(0, 0, 0, 0);
     m_clipIdCounter = 0;
     // setup toolbar
     searchView = new KTreeWidgetSearchLine(this);
index 13b13725541dfb24377ed5351cd6149fb5a4bbcd..c85c8ab7f8f80e37d4b15dfc2ea2c547bee6f9cd 100644 (file)
@@ -2095,12 +2095,12 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
     return true;
 }
 
-bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
-    return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
+bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool forceProducer) {
+    return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, forceProducer);
 }
 
 
-bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
+bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool forceProducer) {
     m_isBlocked = true;
 
     m_mltConsumer->set("refresh", 0);
@@ -2116,22 +2116,27 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn
     bool checkLength = false;
     if (endTrack == startTrack) {
         //mlt_service_lock(service.get_service());
-        Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
-
-        if (!trackPlaylist.is_blank_at(moveEnd)) {
-            // error, destination is not empty
-            //int ix = trackPlaylist.get_clip_index_at(moveEnd);
-            kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
-            mlt_service_unlock(m_mltConsumer->get_service());
-            m_isBlocked = false;
-            return false;
+        if (forceProducer) {
+            Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
+            trackPlaylist.insert(clipProducer, moveEnd, clipProducer.get_in(), clipProducer.get_out());
         } else {
-            trackPlaylist.consolidate_blanks(0);
-            int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
-            /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
-                mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
-            }*/
-            if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
+            Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
+
+            if (!trackPlaylist.is_blank_at(moveEnd)) {
+                // error, destination is not empty
+                //int ix = trackPlaylist.get_clip_index_at(moveEnd);
+                kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
+                mlt_service_unlock(m_mltConsumer->get_service());
+                m_isBlocked = false;
+                return false;
+            } else {
+                trackPlaylist.consolidate_blanks(0);
+                int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
+                /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
+                              mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
+                }*/
+                if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
+            }
         }
         //mlt_service_unlock(service.get_service());
     } else {
@@ -2577,5 +2582,73 @@ QList <Mlt::Producer *> Render::producersList() {
     return prods;
 }
 
+void Render::mltInsertTrack(int ix) {
+    blockSignals(true);
+    m_isBlocked = true;
+
+    m_mltConsumer->set("refresh", 0);
+    mlt_service_lock(m_mltConsumer->get_service());
+    Mlt::Service service(m_mltProducer->parent().get_service());
+    if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
+
+    Mlt::Tractor tractor(service);
+    Mlt::Playlist *playlist = new Mlt::Playlist();
+    int ct = tractor.count();
+    kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
+    int pos = ix;
+    if (pos < ct) {
+        Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
+        tractor.set_track(*playlist, pos);
+        pos++;
+        for (; pos <= ct; pos++) {
+            Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
+            tractor.set_track(*prodToMove, pos);
+            prodToMove = prodToMove2;
+        }
+    } else tractor.set_track(*playlist, ix);
+
+    // Move transitions
+    mlt_service serv = m_mltProducer->parent().get_service();
+    mlt_service nextservice = mlt_service_get_producer(serv);
+    mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
+    QString mlt_type = mlt_properties_get(properties, "mlt_type");
+    QString resource = mlt_properties_get(properties, "mlt_service");
+
+    while (mlt_type == "transition") {
+        if (resource != "mix") {
+            mlt_transition tr = (mlt_transition) nextservice;
+            int currentTrack = mlt_transition_get_b_track(tr);
+            int currentaTrack = mlt_transition_get_a_track(tr);
+            mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
+
+            if (currentTrack >= ix) {
+                mlt_properties_set_int(properties, "b_track", currentTrack + 1);
+                mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
+            }
+        }
+        nextservice = mlt_service_producer(nextservice);
+        if (nextservice == NULL) break;
+        properties = MLT_SERVICE_PROPERTIES(nextservice);
+        mlt_type = mlt_properties_get(properties, "mlt_type");
+        resource = mlt_properties_get(properties, "mlt_service");
+    }
+
+    // Add audio mix transition to last track
+    Mlt::Field *field = tractor.field();
+    Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
+    //transition->set("mlt_service", "mix");
+    transition->set("a_track", 1);
+    transition->set("b_track", ct);
+    transition->set("always_active", 1);
+    transition->set("internal_added", 237);
+    transition->set("combine", 1);
+    field->plant_transition(*transition, 1, ct);
+
+    mlt_service_unlock(m_mltConsumer->get_service());
+    m_isBlocked = false;
+    blockSignals(false);
+    //Mlt::Producer trackProducer(tractor.track(startTrack));
+}
+
 #include "renderer.moc"
 
index 20800cbef8b7dca474f9d2a9205d9758c1916a2c..5737f2030b7c603047f04803ee08bcc08002ce0a 100644 (file)
@@ -154,8 +154,8 @@ Q_OBJECT public:
     int mltGetSpaceLength(const GenTime pos, int track);
     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
     bool mltResizeClipStart(ItemInfo info, GenTime diff);
-    bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod);
-    bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod);
+    bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod, bool forceProducer = false);
+    bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod, bool forceProducer = false);
     bool mltRemoveClip(int track, GenTime position);
     bool mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh = true);
     bool mltAddEffect(int track, GenTime position, QHash <QString, QString> args, bool doRefresh = true);
@@ -171,6 +171,7 @@ Q_OBJECT public:
     void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
     void mltDeleteTransparency(int pos, int track, int id);
     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
+    void mltInsertTrack(int ix);
 
     /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
     This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path
diff --git a/src/widgets/addtrack_ui.ui b/src/widgets/addtrack_ui.ui
new file mode 100644 (file)
index 0000000..453b68d
--- /dev/null
@@ -0,0 +1,128 @@
+<ui version="4.0" >
+ <class>AddTrack_UI</class>
+ <widget class="QDialog" name="AddTrack_UI" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>249</width>
+    <height>97</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Dialog</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="0" column="0" >
+    <widget class="QLabel" name="label" >
+     <property name="text" >
+      <string>Insert track</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1" colspan="2" >
+    <widget class="QComboBox" name="before_select" >
+     <item>
+      <property name="text" >
+       <string>before</string>
+      </property>
+     </item>
+     <item>
+      <property name="text" >
+       <string>after</string>
+      </property>
+     </item>
+    </widget>
+   </item>
+   <item row="0" column="3" >
+    <widget class="KIntNumInput" name="track_nb" >
+     <property name="minimum" >
+      <number>0</number>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" colspan="2" >
+    <widget class="QRadioButton" name="video_track" >
+     <property name="text" >
+      <string>Video track</string>
+     </property>
+     <property name="checked" >
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="2" colspan="2" >
+    <widget class="QRadioButton" name="radioButton_2" >
+     <property name="text" >
+      <string>Audio track</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="2" >
+    <spacer name="verticalSpacer" >
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0" >
+      <size>
+       <width>20</width>
+       <height>10</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="3" column="0" colspan="4" >
+    <widget class="QDialogButtonBox" name="buttonBox" >
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons" >
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>KIntNumInput</class>
+   <extends>QWidget</extends>
+   <header>knuminput.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>AddTrack_UI</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>AddTrack_UI</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>