From c3e1830357babefd36be9fb733e4196960a55126 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Wed, 20 Feb 2008 20:20:59 +0000 Subject: [PATCH] Effects are now stored in clip as xml, get ready for effectstack connection svn path=/branches/KDE4/; revision=1890 --- src/addeffectcommand.cpp | 12 ++++++------ src/addeffectcommand.h | 5 ++--- src/clipitem.cpp | 29 +++++++++++++++++++++++++---- src/clipitem.h | 6 ++++-- src/customtrackview.cpp | 30 ++++++++++++++++++------------ src/customtrackview.h | 6 +++--- src/effectslist.cpp | 9 ++++++++- src/effectslistview.cpp | 17 +++++++++++++++-- src/effectslistview.h | 2 +- src/effectstackview.cpp | 14 +++++++++++++- src/mainwindow.cpp | 12 ++++++------ src/mainwindow.h | 2 +- src/renderer.cpp | 36 ++++++++++++++---------------------- src/renderer.h | 4 ++-- 14 files changed, 118 insertions(+), 66 deletions(-) diff --git a/src/addeffectcommand.cpp b/src/addeffectcommand.cpp index b374e364..00bf663d 100644 --- a/src/addeffectcommand.cpp +++ b/src/addeffectcommand.cpp @@ -21,8 +21,8 @@ #include "addeffectcommand.h" -AddEffectCommand::AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, const QString &tag, QMap 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" diff --git a/src/addeffectcommand.h b/src/addeffectcommand.h index 917a43bd..942d9fe1 100644 --- a/src/addeffectcommand.h +++ b/src/addeffectcommand.h @@ -29,7 +29,7 @@ class AddEffectCommand : public QUndoCommand { public: - AddEffectCommand(CustomTrackView *view, const int track, GenTime pos, const QString &tag, QMap 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 m_args; bool m_doIt; }; diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 22f0c13e..969bf5ec 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -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: "< args) +QDomElement ClipItem::effectAt(int ix) { - m_effectList.append(args); + return m_effectList.at(ix); +} + +QMap ClipItem::addEffect(QDomElement effect) +{ + QMap 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; } diff --git a/src/clipitem.h b/src/clipitem.h index 3c930809..51bbb320 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -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 args); + QMap 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 > m_effectList; + QList< QDomElement > m_effectList; private slots: void slotThumbReady(int frame, QPixmap pix); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 83202edc..cc3878ba 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -301,6 +301,10 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event ) kDebug()<<"//////// NO ITEM FOUND ON CLICK"; m_dragItem = NULL; setCursor(Qt::ArrowCursor); + QList 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 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 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 filter) +void CustomTrackView::slotAddEffect(QDomElement effect) { QList 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); } } diff --git a/src/customtrackview.h b/src/customtrackview.h index 59d53650..8148636e 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -50,9 +50,9 @@ class CustomTrackView : public QGraphicsView void setDuration(int duration); void setScale(double scaleFactor); void deleteClip(int clipId); - void slotAddEffect(QMap filter); - void addEffect(int track, GenTime pos, QString tag, QMap 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); diff --git a/src/effectslist.cpp b/src/effectslist.cpp index 76cf6e3f..56521afc 100644 --- a/src/effectslist.cpp +++ b/src/effectslist.cpp @@ -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(); diff --git a/src/effectslistview.cpp b/src/effectslistview.cpp index dbd2ab46..7c374c5a 100644 --- a/src/effectslistview.cpp +++ b/src/effectslistview.cpp @@ -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); diff --git a/src/effectslistview.h b/src/effectslistview.h index 036ef78e..dacbbe9a 100644 --- a/src/effectslistview.h +++ b/src/effectslistview.h @@ -49,7 +49,7 @@ class EffectsListView : public QWidget public slots: signals: - void addEffect(int, QString); + void addEffect(QDomElement); }; diff --git a/src/effectstackview.cpp b/src/effectstackview.cpp index a981a69b..f82d72a1 100644 --- a/src/effectstackview.cpp +++ b/src/effectstackview.cpp @@ -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); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 546f0663..31bc3df8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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 filter; + /*QMap 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); diff --git a/src/mainwindow.h b/src/mainwindow.h index 5166acb6..cc6d1581 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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(); }; diff --git a/src/renderer.cpp b/src/renderer.cpp index 11367731..c651177e 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -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: "<get("mlt_service") == tag /*&& filter->get("kdenlive_id") == id*/) clipService.detach(*filter); - else { - kDebug()<<"WARINIG, FILTER "< args) +void Render::mltAddEffect(int track, GenTime position, QMap 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 get_service()); m_isBlocked = true; // create filter + QString tag = args.value("tag"); //kDebug()<<" / / INSERTING EFFECT: "<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::Iterator it; QString keyFrameNumber = "#0"; @@ -1112,8 +1104,8 @@ void Render::mltEditEffect(int track, GenTime position, int index, QString id, Q QMap::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; diff --git a/src/renderer.h b/src/renderer.h index a9503f24..a1f69ffa 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -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 args); + void mltRemoveEffect(int track, GenTime position, QString index); + void mltAddEffect(int track, GenTime position, QMap args); void mltEditEffect(int track, GenTime position, int index, QString id, QString tag, QMap 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); -- 2.39.2