]> git.sesse.net Git - kdenlive/commitdiff
Start implementing effects
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 17 Feb 2008 18:46:45 +0000 (18:46 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 17 Feb 2008 18:46:45 +0000 (18:46 +0000)
svn path=/branches/KDE4/; revision=1860

src/addeffectcommand.cpp [new file with mode: 0644]
src/addeffectcommand.h [new file with mode: 0644]
src/customtrackview.cpp
src/customtrackview.h
src/effectslist.cpp
src/effectslist.h
src/effectslistview.cpp
src/effectslistview.h
src/renderer.cpp
src/renderer.h

diff --git a/src/addeffectcommand.cpp b/src/addeffectcommand.cpp
new file mode 100644 (file)
index 0000000..b374e36
--- /dev/null
@@ -0,0 +1,46 @@
+/***************************************************************************
+ *   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 "addeffectcommand.h"
+
+AddEffectCommand::AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, const QString &tag, QMap <QString, QString> args, bool doIt)
+         : m_view(view), m_track(track), m_pos(pos), m_tag(tag), m_args(args), m_doIt(doIt) {
+           if (doIt) setText(i18n("Add effect"));
+           else setText(i18n("Delete effect"));
+        }
+
+
+// virtual 
+void AddEffectCommand::undo()
+{
+kDebug()<<"----  undoing action";
+  if (m_doIt) m_view->deleteEffect(m_track, m_pos, m_tag);
+  else m_view->addEffect(m_track, m_pos, m_tag, m_args);
+}
+// virtual 
+void AddEffectCommand::redo()
+{
+kDebug()<<"----  redoing action";
+  if (m_doIt) m_view->addEffect(m_track, m_pos, m_tag, m_args);
+  else m_view->deleteEffect(m_track, m_pos, m_tag);
+}
+
+#include "addeffectcommand.moc"
diff --git a/src/addeffectcommand.h b/src/addeffectcommand.h
new file mode 100644 (file)
index 0000000..917a43b
--- /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          *
+ ***************************************************************************/
+
+
+#ifndef ADDEFFECTCOMMAND_H
+#define ADDEFFECTCOMMAND_H
+
+#include <QUndoCommand>
+#include <KDebug>
+
+#include "customtrackview.h"
+
+class AddEffectCommand : public QUndoCommand
+ {
+ public:
+     AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, const QString &tag, QMap <QString, QString> args, bool doIt);
+
+    virtual void undo();
+    virtual void redo();
+
+ private:
+     CustomTrackView *m_view;
+     int m_track;
+     QString m_tag;
+     GenTime m_pos;
+     QMap <QString, QString> m_args;
+     bool m_doIt;
+ };
+
+#endif
+
index d03c248c1ff78a27d4ff8100f6557b5b4d7c1912..bab54b1cb04585f87c3a046e96156ecf3b83c226 100644 (file)
@@ -33,6 +33,7 @@
 #include "moveclipcommand.h"
 #include "resizeclipcommand.h"
 #include "addtimelineclipcommand.h"
+#include "addeffectcommand.h"
 
 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(0), m_document(doc)
@@ -297,7 +298,7 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event )
   }
   updateSnapPoints(m_dragItem);
   //kDebug()<<pos;
-  //QGraphicsView::mousePressEvent(event);
+  QGraphicsView::mousePressEvent(event);
 }
 
 void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
@@ -315,6 +316,29 @@ void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
   }
 }
 
+void CustomTrackView::addEffect(int track, GenTime pos, QString tag, QMap <QString, QString> args)
+{
+  m_document->renderer()->mltAddEffect(track, pos, tag, args);  
+}
+
+void CustomTrackView::deleteEffect(int track, GenTime pos, QString tag)
+{
+  m_document->renderer()->mltRemoveEffect(track, pos, tag, -1);  
+}
+
+void CustomTrackView::slotAddEffect(QMap <QString, QString> filter)
+{
+  QList<QGraphicsItem *> itemList = items();
+  for (int i = 0; i < itemList.count(); i++) {
+    if (itemList.at(i)->type() == 70000 && itemList.at(i)->isSelected()) {
+      ClipItem *item = (ClipItem *)itemList.at(i);
+      QString tag = filter.value("mlt_service");
+      AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(),GenTime(item->startPos(), 25), tag, filter, true);
+      m_commandStack->push(command);    
+    }
+  }
+}
+
 void CustomTrackView::addItem(DocClipBase *clip, QPoint pos)
 {
   int in =0;
index 16e6ae796f9c73b903d807721a96988a66dcc0d8..b422cb7a78d14612e3d7620d2ca9d8b5a7aab5e8 100644 (file)
@@ -50,6 +50,9 @@ class CustomTrackView : public QGraphicsView
     void setDuration(int duration);
     void setScale(double scaleFactor);
     void deleteClip(int clipId);
+    void slotAddEffect(QMap <QString, QString> filter);
+    void addEffect(int track, GenTime pos, QString tag, QMap <QString, QString> args);
+    void deleteEffect(int track, GenTime pos, QString tag);
 
   public slots:
     void setCursorPos(int pos, bool seek = true);
index fbbc84616159fb95c4b5f4781a34951dfeb5ca66..76cf6e3f558532e228fcd38cbfbf22f9256c3d6d 100644 (file)
@@ -30,6 +30,24 @@ EffectsList::~EffectsList()
 {
 }
 
+QMap <QString, QString> EffectsList::effect(const QString & name)
+{
+  QMap <QString, QString> filter;
+  QString effectName;
+  QDomElement effect;
+  for (int i = 0; i < this->size(); ++i) {
+    effect =  this->at(i);
+    QDomNode namenode = effect.elementsByTagName("name").item(0);
+    if (!namenode.isNull()) {
+      effectName = i18n(qstrdup(namenode.toElement().text().toUtf8()));
+      if (name == effectName) break;
+    }
+  }
+  filter.insert("mlt_service", effect.attribute("tag"));
+  filter.insert("name", name);
+  return filter;
+}
+
 QDomElement EffectsList::getEffectByName(const QString & name)
 {
   QString effectName;
index d2c10dcb191f3f04be1894eeec77f9e9283d75ff..affb686918ef3d903542d75e7f130f1e3a3707f2 100644 (file)
@@ -36,7 +36,7 @@ class EffectsList:public QList < QDomElement > {
   QDomElement getEffectByName(const QString & name);
   QStringList effectNames();
   QString getInfo(QString effectName);
-
+  QMap <QString, QString> effect(const QString & name);
 };
 
 #endif
index e9d9876a1d1700fc9343d68503e7da38d1c461d0..683aeac4f76670a4824e6edda0cba7202e0d5756 100644 (file)
@@ -31,6 +31,9 @@ EffectsListView::EffectsListView(EffectsList *audioEffectList, EffectsList *vide
   connect(ui.type_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(initList(int)));
   connect(ui.button_info, SIGNAL(stateChanged(int)), this, SLOT(showInfoPanel(int)));
   connect(ui.effectlist, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateInfo()));
+  connect(ui.effectlist, SIGNAL(doubleClicked(QListWidgetItem *,const QPoint &)), this, SLOT(slotEffectSelected()));
+
+
 }
 
 void EffectsListView::initList(int pos)
@@ -58,6 +61,11 @@ void EffectsListView::showInfoPanel(int state)
   else ui.infopanel->show();
 }
 
+void EffectsListView::slotEffectSelected()
+{
+  emit addEffect(ui.type_combo->currentIndex(), ui.effectlist->currentItem()->text());
+}
+
 void EffectsListView::slotUpdateInfo()
 {
   QString info; 
index 51ded6554247954760c73f58f970c44c2b0aa247..9ec9c8e70df79025135c07e5ac55a2d4095c5111 100644 (file)
@@ -44,8 +44,12 @@ class EffectsListView : public QWidget
     void initList(int pos);
     void slotUpdateInfo();
     void showInfoPanel(int state);
+    void slotEffectSelected();
 
   public slots:
+
+  signals:
+    void addEffect(int, QString);
  
 };
 
index 19ff220d2528a473cc063cc9ea35ae13ec1e5caf..721a3b1d8f7e9180f204acaa64431497d8f68b81 100644 (file)
@@ -1002,7 +1002,7 @@ void Render::mltRemoveClip(int track, GenTime position)
     m_isBlocked = false;
 }
 
-void Render::mltRemoveEffect(int track, GenTime position, QString id, QString tag, int index)
+void Render::mltRemoveEffect(int track, GenTime position, QString tag, int index)
 {
 
     Mlt::Service service(m_mltProducer->parent().get_service());
@@ -1025,7 +1025,7 @@ void Render::mltRemoveEffect(int track, GenTime position, QString id, QString ta
        int ct = 0;
        Mlt::Filter *filter = clipService.filter( ct );
        while (filter) {
-           if (filter->get("mlt_service") == tag && filter->get("kdenlive_id") == id) {
+           if (filter->get("mlt_service") == tag) {// && filter->get("kdenlive_id") == id) {
                clipService.detach(*filter);
                kDebug()<<" / / / DLEETED EFFECT: "<<ct;
            }
@@ -1035,9 +1035,9 @@ void Render::mltRemoveEffect(int track, GenTime position, QString id, QString ta
     }
     else {
         Mlt::Filter *filter = clipService.filter( index );
-        if (filter && filter->get("mlt_service") == tag && filter->get("kdenlive_id") == id) clipService.detach(*filter);
+        if (filter && filter->get("mlt_service") == tag /*&& filter->get("kdenlive_id") == id*/) clipService.detach(*filter);
         else {
-           kDebug()<<"WARINIG, FILTER "<<id<<" NOT FOUND!!!!!";
+           kDebug()<<"WARINIG, FILTER "<<tag<<" NOT FOUND!!!!!";
         }
     }
     m_isBlocked = false;
@@ -1045,7 +1045,7 @@ void Render::mltRemoveEffect(int track, GenTime position, QString id, QString ta
 }
 
 
-void Render::mltAddEffect(int track, GenTime position, QString id, QString tag, QMap <QString, QString> args)
+void Render::mltAddEffect(int track, GenTime position, QString tag, QMap <QString, QString> args)
 {
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
@@ -1061,7 +1061,7 @@ void Render::mltAddEffect(int track, GenTime position, QString id, QString tag,
     Mlt::Service clipService(clip->get_service());
     m_isBlocked = true;
     // create filter
-    kDebug()<<" / / INSERTING EFFECT: "<<id;
+    //kDebug()<<" / / INSERTING EFFECT: "<<id;
     if (tag.startsWith("ladspa")) tag = "ladspa";
     char *filterId = decodedString(tag);
     Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterId);
@@ -1105,8 +1105,8 @@ void Render::mltEditEffect(int track, GenTime position, int index, QString id, Q
     QMap<QString, QString>::Iterator it = args.begin();
     if (it.key().startsWith("#") || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
        // This is a keyframe effect, to edit it, we remove it and re-add it.
-       mltRemoveEffect(track, position, id, tag, -1);
-       mltAddEffect(track, position, id, tag, args);
+       mltRemoveEffect(track, position, tag, -1);
+       mltAddEffect(track, position, tag, args);
        return;
     }
     m_isBlocked = true;
index a7087313d7e6f64cae4da6c0451d05fa9d03276e..a9503f2407e452a9b1ff40e6bc06e2b223f9f16d 100644 (file)
@@ -156,8 +156,8 @@ class Render:public QObject {
     void mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart);
     void mltMoveClip(int startTrack, int endTrack, int pos, int moveStart);
     void mltRemoveClip(int track, GenTime position);
-    void mltRemoveEffect(int track, GenTime position, QString id, QString tag, int index);
-    void mltAddEffect(int track, GenTime position, QString id, QString tag, QMap <QString, QString> args);
+    void mltRemoveEffect(int track, GenTime position, QString tag, int index);
+    void mltAddEffect(int track, GenTime position, QString tag, QMap <QString, QString> args);
     void mltEditEffect(int track, GenTime position, int index, QString id, QString tag, QMap <QString, QString> args);
     void mltChangeTrackState(int track, bool mute, bool blind);
     void mltMoveTransition(QString type, int startTrack, int trackOffset, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);