]> git.sesse.net Git - kdenlive/commitdiff
Effects are now stored in clip as xml, get ready for effectstack connection
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 20 Feb 2008 20:20:59 +0000 (20:20 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 20 Feb 2008 20:20:59 +0000 (20:20 +0000)
svn path=/branches/KDE4/; revision=1890

14 files changed:
src/addeffectcommand.cpp
src/addeffectcommand.h
src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp
src/customtrackview.h
src/effectslist.cpp
src/effectslistview.cpp
src/effectslistview.h
src/effectstackview.cpp
src/mainwindow.cpp
src/mainwindow.h
src/renderer.cpp
src/renderer.h

index b374e3646ac53f76f1bd927f7f0b26b053a26e5a..00bf663d4590e1810a7237e46966869b63861fa7 100644 (file)
@@ -21,8 +21,8 @@
 
 #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) {
+AddEffectCommand::AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, QDomElement effect, bool doIt)
+         : m_view(view), m_track(track), m_pos(pos), m_effect(effect), m_doIt(doIt) {
            if (doIt) setText(i18n("Add effect"));
            else setText(i18n("Delete effect"));
         }
@@ -32,15 +32,15 @@ AddEffectCommand::AddEffectCommand(CustomTrackView *view, const int track, GenTi
 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);
+  if (m_doIt) m_view->deleteEffect(m_track, m_pos, m_effect);
+  else m_view->addEffect(m_track, m_pos, m_effect);
 }
 // 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);
+  if (m_doIt) m_view->addEffect(m_track, m_pos, m_effect);
+  else m_view->deleteEffect(m_track, m_pos, m_effect);
 }
 
 #include "addeffectcommand.moc"
index 917a43bd7745f3254412a255d559eb3968fab541..942d9fe155df9dee6774a834debd2f4a6f9c65ff 100644 (file)
@@ -29,7 +29,7 @@
 class AddEffectCommand : public QUndoCommand
  {
  public:
-     AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, const QString &tag, QMap <QString, QString> args, bool doIt);
+     AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, QDomElement effect, bool doIt);
 
     virtual void undo();
     virtual void redo();
@@ -37,9 +37,8 @@ class AddEffectCommand : public QUndoCommand
  private:
      CustomTrackView *m_view;
      int m_track;
-     QString m_tag;
+     QDomElement m_effect;
      GenTime m_pos;
-     QMap <QString, QString> m_args;
      bool m_doIt;
  };
 
index 22f0c13e2149c64a587447eacbb9a84187098629..969bf5ec92848b5643c3bf37f3237835608b06cd 100644 (file)
@@ -470,26 +470,47 @@ void ClipItem::setTrack(int track)
   m_track = track;
 }
 
+int ClipItem::effectsCount()
+{
+  return m_effectList.size();
+}
+
 QStringList ClipItem::effectNames()
 {
   QStringList result;
   for (int i = 0; i < m_effectList.size(); ++i) {
-     result.append(m_effectList.at(i).value("name"));
+       QDomNode namenode = m_effectList.at(i).elementsByTagName("name").item(0);
+       if (!namenode.isNull()) result.append(namenode.toElement().text());
   }
   kDebug()<<"///  EFFECT LIST FOR CLIP IS: "<<result;
   return result;
 }
 
-void ClipItem::addEffect(QMap <QString, QString> args)
+QDomElement ClipItem::effectAt(int ix)
 {
-  m_effectList.append(args);
+  return m_effectList.at(ix);
+}
+
+QMap <QString, QString> ClipItem::addEffect(QDomElement effect)
+{
+  QMap <QString, QString> effectParams;
+  effectParams["kdenlive_ix"] = QString::number(m_effectList.size());
+  m_effectList.append(effect);
+  effectParams["tag"] = effect.attribute("tag");
+  QDomNodeList params = effect.elementsByTagName("parameter");
+  for (int i = 0; i < params.count(); i++) {
+    QDomElement e = params.item(i).toElement();
+    if (!e.isNull())
+      effectParams[e.attribute("name")] = e.attribute("value");
+  }
   update(boundingRect());
+  return effectParams;
 }
 
 void ClipItem::deleteEffect(QString tag)
 {
   for (int i = 0; i < m_effectList.size(); ++i) {
-    if (m_effectList.at(i).value("mlt_service") == tag) {
+    if (m_effectList.at(i).attribute("kdenlive_ix") == tag) {
       m_effectList.removeAt(i);
       break;
     }
index 3c9308090044638d6f5de36fe52838f86b978bfc..51bbb320fff4000b8a9fdd8b615d5794d6a74edc 100644 (file)
@@ -63,8 +63,10 @@ class ClipItem : public QObject, public QGraphicsRectItem
     void setFadeOut(int pos, double scale);
     void setFadeIn(int pos, double scale);
     QStringList effectNames();
-    void addEffect(QMap <QString, QString> args);
+    QMap <QString, QString> addEffect(QDomElement effect);
     void deleteEffect(QString tag);
+    int effectsCount();
+    QDomElement effectAt(int ix);
 
   protected:
     virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
@@ -94,7 +96,7 @@ class ClipItem : public QObject, public QGraphicsRectItem
     uint m_startFade;
     uint m_endFade;
     
-    QList< QMap<QString, QString> > m_effectList;
+    QList< QDomElement > m_effectList;
 
   private slots:
     void slotThumbReady(int frame, QPixmap pix);
index 83202edc58c7e951e3ca88652a900b77b65dbc87..cc3878ba3328a7b7c3a258a5b99ffbc0bfeb0735 100644 (file)
@@ -301,6 +301,10 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event )
       kDebug()<<"//////// NO ITEM FOUND ON CLICK";
       m_dragItem = NULL;
       setCursor(Qt::ArrowCursor);
+      QList<QGraphicsItem *> itemList = items();
+      for (int i = 0; i < itemList.count(); i++)
+       itemList.at(i)->setSelected(false);
+      emit clipItemSelected(NULL);
       setCursorPos((int) mapToScene(event->x(), 0).x());
       emit cursorMoved(cursorPos());
     }
@@ -325,34 +329,36 @@ void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
   }
 }
 
-void CustomTrackView::addEffect(int track, GenTime pos, QString tag, QMap <QString, QString> args)
+void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect)
 {
-  m_document->renderer()->mltAddEffect(track, pos, tag, args);
   ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track);
-       if (clip){ 
-               clip->addEffect(args);
-               emit clipItemSelected(clip);
-       }
+  if (clip){ 
+    QMap <QString, QString> effectParams = clip->addEffect(effect);
+    m_document->renderer()->mltAddEffect(track, pos, effectParams);
+    emit clipItemSelected(clip);
+  }
 }
 
-void CustomTrackView::deleteEffect(int track, GenTime pos, QString tag)
+void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
 {
-  m_document->renderer()->mltRemoveEffect(track, pos, tag, -1);  
+  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);
        if (clip){
-               clip->deleteEffect(tag);
+               clip->deleteEffect(index);
                emit clipItemSelected(clip);
        }
 }
 
-void CustomTrackView::slotAddEffect(QMap <QString, QString> filter)
+void CustomTrackView::slotAddEffect(QDomElement effect)
 {
   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(), m_document->fps()), tag, filter, true);
+      // the kdenlive_ix int is used to identify an effect in the stack and in mlt's playlist
+      effect.setAttribute("kdenlive_ix", QString::number(item->effectsCount()));
+      AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(),GenTime(item->startPos(), m_document->fps()), effect, true);
       m_commandStack->push(command);    
     }
   }
index 59d536508db7e5969aa3629ec6576f7e02350c78..8148636ebef4ae9c1496a9955888e6654ed82a3c 100644 (file)
@@ -50,9 +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);
+    void slotAddEffect(QDomElement effect);
+    void addEffect(int track, GenTime pos, QDomElement effect);
+    void deleteEffect(int track, GenTime pos, QDomElement effect);
 
   public slots:
     void setCursorPos(int pos, bool seek = true);
index 76cf6e3f558532e228fcd38cbfbf22f9256c3d6d..56521afc69d8ca672cfc2b7e7a04cc7b45246bc0 100644 (file)
@@ -55,7 +55,14 @@ QDomElement EffectsList::getEffectByName(const QString & name)
     QDomElement effect =  this->at(i);
     QDomNode namenode = effect.elementsByTagName("name").item(0);
     if (!namenode.isNull()) effectName = i18n(qstrdup(namenode.toElement().text().toUtf8()));
-    if (name == effectName) return effect;
+    if (name == effectName) {
+      QDomNodeList params = effect.elementsByTagName("parameter");
+      for (int i = 0; i < params.count(); i++) {
+       QDomElement e = params.item(i).toElement();
+       e.setAttribute("value", e.attribute("default"));
+      }
+      return effect;
+    }
   }
 
   return QDomElement();
index dbd2ab460c53450e2cbb5f2a0b37213d192d3f75..7c374c5a2df803fc57eb5d7714e1947aef16dbca 100644 (file)
@@ -72,7 +72,20 @@ void EffectsListView::showInfoPanel()
 
 void EffectsListView::slotEffectSelected()
 {
-  emit addEffect(ui.type_combo->currentIndex(), ui.effectlist->currentItem()->text());
+  QDomElement effect;
+  switch (ui.type_combo->currentIndex())
+  {
+    case 0:
+      effect = m_videoList->getEffectByName(ui.effectlist->currentItem()->text());
+      break;
+    case 1:
+      effect = m_audioList->getEffectByName(ui.effectlist->currentItem()->text());
+      break;
+    default:
+      effect = m_customList->getEffectByName(ui.effectlist->currentItem()->text());
+      break;
+  }
+  emit addEffect(effect);
 }
 
 void EffectsListView::slotUpdateInfo()
@@ -84,7 +97,7 @@ void EffectsListView::slotUpdateInfo()
   else if (ui.type_combo->currentIndex() == 1) {
     info = m_audioList->getInfo(ui.effectlist->currentItem()->text());
   }
-  if (ui.type_combo->currentIndex() == 2) {
+  else if (ui.type_combo->currentIndex() == 2) {
     info = m_customList->getInfo(ui.effectlist->currentItem()->text());
   }
   ui.infopanel->setText(info);
index 036ef78efb43a039a7553c1f3baf741de5a8e255..dacbbe9a623dba5ce644a654c29cebbbf8b1d42f 100644 (file)
@@ -49,7 +49,7 @@ class EffectsListView : public QWidget
   public slots:
 
   signals:
-    void addEffect(int, QString);
+    void addEffect(QDomElement);
  
 };
 
index a981a69b81f870de73cdcc113eb07d74617c2ff5..f82d72a12d878e7bd1a4e0f03a8e97ad1e9c7c6f 100644 (file)
@@ -34,15 +34,24 @@ EffectStackView::EffectStackView(EffectsList *audioEffectList, EffectsList *vide
        clipref=NULL;
        
        ui.buttonNew->setIcon(KIcon("document-new"));
+       ui.buttonNew->setToolTip(i18n("Add new effect"));
        ui.buttonUp->setIcon(KIcon("go-up"));
+       ui.buttonUp->setToolTip(i18n("Move effect up"));
        ui.buttonDown->setIcon(KIcon("go-down"));
+       ui.buttonDown->setToolTip(i18n("Move effect down"));
        ui.buttonDel->setIcon(KIcon("trash-empty"));
+       ui.buttonDel->setToolTip(i18n("Delete effect"));
        
        ui.buttonLeftRight->setIcon(KIcon("go-next"));//better icons needed
+       ui.buttonLeftRight->setToolTip(i18n("Allow horizontal moves"));
        ui.buttonUpDown->setIcon(KIcon("go-up"));
+       ui.buttonUpDown->setToolTip(i18n("Allow vertical moves"));
        ui.buttonShowInTimeline->setIcon(KIcon("kmplayer"));
+       ui.buttonShowInTimeline->setToolTip(i18n("Show keyframes in timeline"));
        ui.buttonHelp->setIcon(KIcon("help-about"));
+       ui.buttonHelp->setToolTip(i18n("Parameter info"));
        ui.buttonNewPoints->setIcon(KIcon("xedit"));
+       ui.buttonNewPoints->setToolTip(i18n("Add keyframe"));
        
        ui.effectlist->setDragDropMode(QAbstractItemView::NoDragDrop);//use internal if drop is recognised right
        
@@ -94,8 +103,11 @@ EffectStackView::EffectStackView(EffectsList *audioEffectList, EffectsList *vide
 void EffectStackView::slotClipItemSelected(ClipItem* c)
 {
        clipref=c;
-       if (clipref==NULL)
+       if (clipref==NULL) {
+               setEnabled(false);
                return;
+       }
+       setEnabled(true);
        effects=clipref->effectNames();
        setupListView(effects);
        
index 546f0663eb4a20d6174540508a6235f9c2c7bd97..31bc3df8c0ce6d7b746797d5f1b30d589dd7edfc 100644 (file)
@@ -145,7 +145,7 @@ MainWindow::MainWindow(QWidget *parent)
   connect(clipMonitorDock, SIGNAL(visibilityChanged (bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
   connect(m_monitorManager, SIGNAL(connectMonitors ()), this, SLOT(slotConnectMonitors()));
   connect(m_monitorManager, SIGNAL(raiseClipMonitor (bool)), this, SLOT(slotRaiseMonitor(bool)));
-  connect(m_effectList, SIGNAL(addEffect(int, const QString&)), this, SLOT(slotAddEffect(int, const QString &)));
+  connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
   m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
        
   setAutoSaveSettings();
@@ -167,18 +167,18 @@ bool MainWindow::queryClose()
   }
 }
 
-void MainWindow::slotAddEffect(int effectType, const QString &effectName)
+void MainWindow::slotAddEffect(QDomElement effect)
 {
   if (!m_activeDocument) return;
-  QMap <QString, QString> filter;
+  /*QMap <QString, QString> filter;
   if (effectType == 0)
     filter = m_videoEffects.effect(effectName);
   else if (effectType == 1)
     filter = m_audioEffects.effect(effectName);
   else 
-    filter = m_customEffects.effect(effectName);
+    filter = m_customEffects.effect(effectName);*/
   TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
-  currentTimeLine->projectView()->slotAddEffect(filter);
+  currentTimeLine->projectView()->slotAddEffect(effect);
 }
 
 void MainWindow::slotRaiseMonitor(bool clipMonitor)
@@ -441,7 +441,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //chang
   connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
   connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
   connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
-       connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
+  connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
   m_projectList->setDocument(doc);
   m_monitorManager->setTimecode(doc->timecode());
   doc->setRenderer(m_projectMonitor->render);
index 5166acb69bf4445cf68b0f69c507057a2404cb62..cc6d1581671cf13930ecb4c82295c89b881ba6e5 100644 (file)
@@ -116,7 +116,7 @@ class MainWindow : public KXmlGuiWindow
     void slotRaiseMonitor(bool clipMonitor);
     void slotSetClipDuration(int id, int duration);
     void slotUpdateMousePosition(int pos);
-    void slotAddEffect(int effectType, const QString &effectName);
+    void slotAddEffect(QDomElement effect);
     void slotEditProfiles();
     void slotEditProjectSettings();
 };
index 11367731fd1d32a9afe6d29e15dd168a61d5a9eb..c651177eb8696e02a4f38caab8cb4f062f2eca4b 100644 (file)
@@ -1004,7 +1004,7 @@ void Render::mltRemoveClip(int track, GenTime position)
     m_isBlocked = false;
 }
 
-void Render::mltRemoveEffect(int track, GenTime position, QString tag, int index)
+void Render::mltRemoveEffect(int track, GenTime position, QString index)
 {
 
     Mlt::Service service(m_mltProducer->parent().get_service());
@@ -1021,33 +1021,24 @@ void Render::mltRemoveEffect(int track, GenTime position, QString tag, int index
     m_isBlocked = true;
     Mlt::Service clipService(clip->get_service());
 
-    if (tag.startsWith("ladspa")) tag = "ladspa";
+//    if (tag.startsWith("ladspa")) tag = "ladspa";
 
-    if (index == -1) {
-       int ct = 0;
+    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("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
                clipService.detach(*filter);
                kDebug()<<" / / / DLEETED EFFECT: "<<ct;
            }
            else ct++;
            filter = clipService.filter( ct );
        }
-    }
-    else {
-        Mlt::Filter *filter = clipService.filter( index );
-        if (filter && filter->get("mlt_service") == tag /*&& filter->get("kdenlive_id") == id*/) clipService.detach(*filter);
-        else {
-           kDebug()<<"WARINIG, FILTER "<<tag<<" NOT FOUND!!!!!";
-        }
-    }
     m_isBlocked = false;
     refresh();
 }
 
 
-void Render::mltAddEffect(int track, GenTime position, QString tag, QMap <QString, QString> args)
+void Render::mltAddEffect(int track, GenTime position, QMap <QString, QString> args)
 {
     Mlt::Service service(m_mltProducer->parent().get_service());
     Mlt::Tractor tractor(service);
@@ -1063,16 +1054,17 @@ void Render::mltAddEffect(int track, GenTime position, QString tag, QMap <QStrin
     Mlt::Service clipService(clip->get_service());
     m_isBlocked = true;
     // create filter
+    QString tag = args.value("tag");
     //kDebug()<<" / / INSERTING EFFECT: "<<id;
     if (tag.startsWith("ladspa")) tag = "ladspa";
     char *filterId = decodedString(tag);
     Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterId);
-   if (filter && filter->is_valid())
-    filter->set("kdenlive_id", filterId);
-   else {
-     kDebug() << "filter is NULL";
-     return;
-   }
+    if (filter && filter->is_valid())
+      filter->set("kdenlive_id", filterId);
+    else {
+      kDebug() << "filter is NULL";
+      return;
+    }
 
     QMap<QString, QString>::Iterator it;
     QString keyFrameNumber = "#0";
@@ -1112,8 +1104,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, tag, -1);
-       mltAddEffect(track, position, tag, args);
+       //mltRemoveEffect(track, position, tag, -1);
+       //mltAddEffect(track, position, tag, args);
        return;
     }
     m_isBlocked = true;
index a9503f2407e452a9b1ff40e6bc06e2b223f9f16d..a1f69ffaadc1b3231acb2d014c6f1855353f20f3 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 tag, int index);
-    void mltAddEffect(int track, GenTime position, QString tag, QMap <QString, QString> args);
+    void mltRemoveEffect(int track, GenTime position, QString index);
+    void mltAddEffect(int track, GenTime position, 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);