]> git.sesse.net Git - kdenlive/commitdiff
Fix LADSPA effects, should work now:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 28 Dec 2008 17:47:26 +0000 (17:47 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 28 Dec 2008 17:47:26 +0000 (17:47 +0000)
http://www.kdenlive.org:80/mantis/view.php?id=499

svn path=/branches/KDE4/; revision=2838

src/clipitem.cpp
src/customtrackview.cpp
src/customtrackview.h
src/initeffects.cpp
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/renderer.cpp
src/trackview.cpp

index f78324034786bf6808584cde1af8768d268ec2d7..1b493385ae4661d36d449d56581480c230129950 100644 (file)
@@ -1126,6 +1126,7 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate) {
     EffectsParameterList parameters;
     parameters.addParam("tag", effect.attribute("tag"));
     parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
+    if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
 
     QString state = effect.attribute("disabled");
     if (!state.isEmpty()) {
@@ -1193,7 +1194,7 @@ EffectsParameterList ClipItem::getEffectArgs(QDomElement effect) {
     parameters.addParam("tag", effect.attribute("tag"));
     parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix"));
     parameters.addParam("id", effect.attribute("id"));
-
+    if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src"));
     QString state = effect.attribute("disabled");
     if (!state.isEmpty()) {
         parameters.addParam("disabled", state);
index 651dd3f73cf7bc177e335d699f2056a15a749865..c58d32b03e2100cefe486bf252c00c41cc7efcdb 100644 (file)
@@ -67,6 +67,7 @@
 #include "changetrackcommand.h"
 #include "movegroupcommand.h"
 #include "ui_addtrack_ui.h"
+#include "initeffects.h"
 
 //TODO:
 // disable animation if user asked it in KDE's global settings
@@ -1007,6 +1008,11 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
         if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = (ClipItem *)itemList.at(i);
             item->initEffect(effect);
+            if (effect.attribute("tag") == "ladspa") {
+                QString ladpsaFile = m_document->getLadspaFile();
+                initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
+                effect.setAttribute("src", ladpsaFile);
+            }
             AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true);
             m_commandStack->push(command);
         }
@@ -1024,6 +1030,10 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement effect, i
     ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()) + 1, m_document->tracksCount() - track);
     if (clip) {
         EffectsParameterList effectParams = clip->getEffectArgs(effect);
+        if (effect.attribute("tag") == "ladspa") {
+            // Update the ladspa affect file
+            initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect));
+        }
         // check if we are trying to reset a keyframe effect
         if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) {
             clip->initEffect(effect);
@@ -3286,4 +3296,22 @@ void CustomTrackView::autoTransition() {
     m_document->renderer()->mltUpdateTransition(transition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_document->tracksCount() - transition.attribute("transition_atrack").toInt(), tr->startPos(), tr->endPos(), transition);
 }
 
+
+QStringList CustomTrackView::getLadspaParams(QDomElement effect) const {
+    QStringList result;
+    QDomNodeList params = effect.elementsByTagName("parameter");
+    for (int i = 0; i < params.count(); i++) {
+        QDomElement e = params.item(i).toElement();
+        if (!e.isNull() && e.attribute("type") == "constant") {
+            if (e.hasAttribute("factor")) {
+                double factor = e.attribute("factor").toDouble();
+                double value = e.attribute("value").toDouble();
+                value = value / factor;
+                result.append(QString::number(value));
+            } else result.append(e.attribute("value"));
+        }
+    }
+    return result;
+}
+
 #include "customtrackview.moc"
index ae6b23b9751fcac7b82f44ce902594dfc8511af5..5129b56370de641ac4ea4e4ac197fb44566a7eca 100644 (file)
@@ -106,6 +106,7 @@ public:
     void changeTimelineTrack(int ix, TrackInfo trackinfo);
     void saveThumbnails();
     void autoTransition();
+    QStringList getLadspaParams(QDomElement effect) const;
 
 public slots:
     void setCursorPos(int pos, bool seek = true);
index 1470cc48f7e91049c79bc15743e038f65b4fffc4..5d6ee274ce571e0ac03e4a0478f6d5ef69efaaa0 100644 (file)
@@ -417,7 +417,7 @@ void initEffects::ladspaEffectFile(const QString & fname, int ladspaId, QStringL
     delete filterString;
 }
 
-QString jackString = "<?xml version=\"1.0\"?><!DOCTYPE jackrack SYSTEM \"http://purge.bash.sh/~rah/jack_rack_1.2.dtd\"><jackrack><channels>2</channels><samplerate>48000</samplerate><plugin><id>";
+const QString jackString = "<?xml version=\"1.0\"?><!DOCTYPE jackrack SYSTEM \"http://purge.bash.sh/~rah/jack_rack_1.2.dtd\"><jackrack><channels>2</channels><samplerate>48000</samplerate><plugin><id>";
 
 
 char* initEffects::ladspaDeclipEffectString(QStringList) {
index 01b282a5d672789182c22c93bb60d06cadbd9068..61351c3aa117809b031ceb1475be4917961801e2 100644 (file)
@@ -179,6 +179,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup
     // make sure that the necessary folders exist
     KStandardDirs::makeDir(m_projectFolder.path() + "/titles/");
     KStandardDirs::makeDir(m_projectFolder.path() + "/thumbs/");
+    KStandardDirs::makeDir(m_projectFolder.path() + "/ladspa/");
 
     m_scenelist = m_document.toString();
     kDebug() << "KDEnnlive document, init timecode: " << m_fps;
@@ -336,8 +337,10 @@ int KdenliveDoc::zoom() const {
 bool KdenliveDoc::convertDocument(double version) {
     kDebug() << "Opening a document with version " << version;
 
+    if (version == 0.81) return true;
+
     // Opening a old Kdenlive document
-    if (version == 0.5 || version == 0.7) {
+    if (version == 0.5 || version == 0.7 || version > 0.81) {
         kDebug() << "Unable to open document with version " << version;
         // TODO: convert 0.7 (0.5?) files to the new document format.
         return FALSE;
@@ -901,6 +904,7 @@ void KdenliveDoc::setProjectFolder(KUrl url) {
 
 void KdenliveDoc::moveProjectData(KUrl url) {
     QList <DocClipBase*> list = m_clipManager->documentClipList();
+    //TODO: Also move ladspa effects files
     for (int i = 0; i < list.count(); i++) {
         DocClipBase *clip = list.at(i);
         if (clip->clipType() == TEXT) {
@@ -1078,7 +1082,7 @@ QDomDocument KdenliveDoc::generateSceneList() {
     QDomElement prod = doc.createElement("producer");
 }
 
-QDomDocument KdenliveDoc::toXml() const {
+QDomDocument KdenliveDoc::toXml() {
     return m_document;
 }
 
@@ -1412,5 +1416,15 @@ void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const {
     pix.save(m_projectFolder.path() + "/thumbs/" + fileId + ".png");
 }
 
+QString KdenliveDoc::getLadspaFile() const {
+    int ct = 0;
+    QString counter = QString::number(ct).rightJustified(5, '0', false);
+    while (QFile::exists(m_projectFolder.path() + "/ladspa/" + counter + ".ladspa")) {
+        ct++;
+        counter = QString::number(ct).rightJustified(5, '0', false);
+    }
+    return m_projectFolder.path() + "/ladspa/" + counter + ".ladspa";
+}
+
 #include "kdenlivedoc.moc"
 
index 188fcb4e128f425a6378ff306aa56ce6ba5fa0c3..92245fd1d186dfb30c8929c7577199815f4cf76e 100644 (file)
@@ -58,7 +58,7 @@ Q_OBJECT public:
     KAutoSaveFile *m_autosave;
     void backupMltPlaylist();
     Timecode timecode() const;
-    QDomDocument toXml() const;
+    QDomDocument toXml();
     void setRenderer(Render *render);
     QUndoStack *commandStack();
     QString producerName(const QString &id);
@@ -117,6 +117,7 @@ Q_OBJECT public:
     void switchTrackAudio(int ix, bool hide);
     void cachePixmap(const QString &fileId, const QPixmap &pix) const;
     void setProjectFolder(KUrl url);
+    QString getLadspaFile() const;
 
 private:
     KUrl m_url;
index db3e7ac1e57fc0a3d35128b4d856821a2e08b76e..40354c538c6af730d2e401d9f6d84b85c89af2bd 100644 (file)
@@ -1711,7 +1711,10 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool do
         if ((index == "-1" && filter->get("kdenlive_id") != "")  || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
             if (clipService.detach(*filter) == 0) success = true;
             kDebug() << " / / / DLEETED EFFECT: " << ct;
-        } else ct++;
+        } else {
+            if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
+            ct++;
+        }
         filter = clipService.filter(ct);
     }
     m_isBlocked = false;
@@ -1834,7 +1837,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para
             for (int j = 0; j < params.count(); j++) {
                 effectArgs.append(' ' + params.at(j).value());
             }
-            kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
+            //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
             char *value = decodedString(effectArgs.simplified());
             filter->set("effect", value);
             delete[] value;
index e5e920d5880c4eaa5fc02dc2ea18854df41b6e2e..7535509648aa32002bc37f99b9964ed604d2b85f 100644 (file)
@@ -34,7 +34,7 @@
 #include "kdenlivedoc.h"
 #include "mainwindow.h"
 #include "customtrackview.h"
-
+#include "initeffects.h"
 
 TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
         : QWidget(parent), m_doc(doc), m_scale(1.0), m_projectTracks(0) {
@@ -401,6 +401,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml) {
                         QString effecttag;
                         QString effectid;
                         QString effectindex;
+                        QString ladspaEffectFile;
                         // Get effect tag & index
                         for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
                             // parse effect parameters
@@ -411,6 +412,15 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml) {
                                 effectid = effectparam.text();
                             } else if (effectparam.attribute("name") == "kdenlive_ix") {
                                 effectindex = effectparam.text();
+                            } else if (effectparam.attribute("name") == "src") {
+                                ladspaEffectFile = effectparam.text();
+                                if (!QFile::exists(ladspaEffectFile)) {
+                                    // If the ladspa effect file is missing, recreate it
+                                    kDebug() << "// MISSING LADSPA FILE: " << ladspaEffectFile;
+                                    ladspaEffectFile = m_doc->getLadspaFile();
+                                    effectparam.firstChild().setNodeValue(ladspaEffectFile);
+                                    kDebug() << "// ... REPLACED WITH: " << ladspaEffectFile;
+                                }
                             }
                         }
                         //kDebug() << "+ + CLIP EFF FND: " << effecttag << ", " << effectid << ", " << effectindex;
@@ -527,6 +537,15 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml) {
                                     }
                                 }
                             }
+                            if (effecttag == "ladspa") {
+                                //QString ladspaEffectFile = EffectsList::parameter(effect, "src", "property");
+
+                                if (!QFile::exists(ladspaEffectFile)) {
+                                    // If the ladspa effect file is missing, recreate it
+                                    initEffects::ladspaEffectFile(ladspaEffectFile, currenteffect.attribute("ladspaid").toInt(), m_trackview->getLadspaParams(currenteffect));
+                                }
+                                currenteffect.setAttribute("src", ladspaEffectFile);
+                            }
                             item->addEffect(currenteffect, false);
                             item->effectsCounter();
                         }