]> git.sesse.net Git - kdenlive/commitdiff
Allow effects to have parameters depending on the project's profile properties (width...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 19 Jul 2009 18:54:53 +0000 (18:54 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 19 Jul 2009 18:54:53 +0000 (18:54 +0000)
svn path=/trunk/kdenlive/; revision=3735

src/clipitem.cpp
src/customtrackscene.cpp
src/customtrackscene.h
src/effectstackedit.cpp
src/mainwindow.cpp
src/profilesdialog.cpp
src/profilesdialog.h
src/trackview.cpp

index 9a92cbd369cedc57aca2c947b23cfb674d76e302..75c5ca2290f3654c1376b79bdcbce553fa1cac4b 100644 (file)
@@ -26,6 +26,7 @@
 #include "transition.h"
 #include "kdenlivesettings.h"
 #include "kthumb.h"
+#include "profilesdialog.h"
 
 #include <KDebug>
 #include <KIcon>
@@ -170,6 +171,16 @@ void ClipItem::initEffect(QDomElement effect)
     for (int i = 0; i < params.count(); i++) {
         QDomElement e = params.item(i).toElement();
         kDebug() << "// init eff: " << e.attribute("name");
+
+        // Check if this effect has a variable parameter
+        if (e.attribute("default").startsWith('%')) {
+            double evaluatedValue = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("default"));
+            e.setAttribute("default", evaluatedValue);
+            if (e.hasAttribute("value") && e.attribute("value").startsWith('%')) {
+                e.setAttribute("value", evaluatedValue);
+            }
+        }
+
         if (!e.isNull() && e.attribute("type") == "keyframe") {
             QString def = e.attribute("default");
             // Effect has a keyframe type parameter, we need to set the values
@@ -1275,7 +1286,7 @@ void ClipItem::setEffectAt(int ix, QDomElement effect)
         kDebug() << "Invalid effect index: " << ix;
         return;
     }
-    kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
+    //kDebug() << "CHange EFFECT AT: " << ix << ", CURR: " << m_effectList.at(ix).attribute("tag") << ", NEW: " << effect.attribute("tag");
     effect.setAttribute("kdenlive_ix", ix + 1);
     m_effectList.insert(ix, effect);
     m_effectList.removeAt(ix + 1);
@@ -1327,9 +1338,7 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate)
                 parameters.addParam("endtag", e.attribute("endtag", "end"));
             }
 
-            double f = e.attribute("factor", "1").toDouble();
-
-            if (f == 1) {
+            if (e.attribute("factor", "1") == "1") {
                 parameters.addParam(e.attribute("name"), e.attribute("value"));
 
                 // check if it is a fade effect
@@ -1375,7 +1384,11 @@ EffectsParameterList ClipItem::addEffect(QDomElement effect, bool animate)
                     }
                 }
             } else {
-                parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / f));
+                double fact;
+                if (e.attribute("factor").startsWith('%')) {
+                    fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
+                } else fact = e.attribute("factor", "1").toDouble();
+                parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
             }
         }
     }
@@ -1435,7 +1448,11 @@ EffectsParameterList ClipItem::getEffectArgs(QDomElement effect)
             parameters.addParam("start", neu);
         } else {
             if (e.attribute("factor", "1") != "1") {
-                parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / e.attribute("factor").toDouble()));
+                double fact;
+                if (e.attribute("factor").startsWith('%')) {
+                    fact = ProfilesDialog::getStringEval(projectScene()->profile(), e.attribute("factor"));
+                } else fact = e.attribute("factor", "1").toDouble();
+                parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact));
             } else {
                 parameters.addParam(e.attribute("name"), e.attribute("value"));
             }
index 7a3209e42efe79ffbb8497a9807b80239f687a5f..eaacb63a6e76a6cf02092cd11d03acace126e3a7 100644 (file)
@@ -92,4 +92,9 @@ int CustomTrackScene::tracksCount() const
     return m_document->tracksCount();
 }
 
+MltVideoProfile CustomTrackScene::profile() const
+{
+    return m_document->mltProfile();
+}
+
 #include "customtrackscene.moc"
index eb22ec90c6e3e435f3c788ab3c657795069a880f..32224b20431215360d94ad31ecf26f53fb1442c0 100644 (file)
@@ -28,6 +28,7 @@
 #include "gentime.h"
 
 class KdenliveDoc;
+class MltVideoProfile;
 
 /** This class holds all properties that need to be used by clip items */
 
@@ -46,6 +47,7 @@ public:
     QPointF scale() const;
     int tracksCount() const;
     QPixmap m_transitionPixmap;
+    MltVideoProfile profile() const;
 
 private:
     KdenliveDoc *m_document;
index 6edc614506795811345b171cbc3c1ba1f2be491d..d8db66108f5d29258de509b47694ea6d9c140210 100644 (file)
@@ -28,6 +28,7 @@
 #include "keyframeedit.h"
 #include "effectslist.h"
 #include "kdenlivesettings.h"
+#include "profilesdialog.h"
 
 #include <KDebug>
 #include <KLocale>
@@ -158,6 +159,7 @@ void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out)
         QWidget * toFillin = new QWidget;
         QString value = pa.attribute("value").isNull() ?
                         pa.attribute("default") : pa.attribute("value");
+
         if (type == "geometry") {
             /*pa.setAttribute("namedesc", "X;Y;Width;Height;Transparency");
             pa.setAttribute("format", "%d%,%d%:%d%x%d%:%d");
@@ -171,7 +173,17 @@ void EffectStackEdit::transferParamDesc(const QDomElement& d, int in, int out)
 
         //TODO constant, list, bool, complex , color, geometry, position
         if (type == "double" || type == "constant") {
-            createSliderItem(paramName, value.toInt(), pa.attribute("min").toInt(), pa.attribute("max").toInt());
+            int min;
+            int max;
+            if (pa.attribute("min").startsWith('%')) {
+                min = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("min"));
+            }
+           else min = pa.attribute("min").toInt();
+            if (pa.attribute("max").startsWith('%')) {
+                max = (int) ProfilesDialog::getStringEval(m_profile, pa.attribute("max"));
+            }
+           else max = pa.attribute("max").toInt();
+            createSliderItem(paramName, (int)(value.toDouble() + 0.5) , min, max);
             delete toFillin;
             toFillin = NULL;
         } else if (type == "list") {
@@ -501,7 +513,6 @@ void EffectStackEdit::createSliderItem(const QString& name, int val , int min, i
     QWidget* toFillin = new QWidget;
     Constval *ctval = new Constval;
     ctval->setupUi(toFillin);
-
     ctval->horizontalSlider->setMinimum(min);
     ctval->horizontalSlider->setMaximum(max);
     ctval->spinBox->setMinimum(min);
index 8f940fffa1e936ba0ec456ad5ae432f78f27a75f..106851e4df0d7faf0604ac1040d5f57b081cd1e2 100644 (file)
@@ -1612,11 +1612,18 @@ void MainWindow::slotEditProjectSettings()
         if (m_activeDocument->profilePath() != profile) {
             // Profile was changed
             double dar = m_activeDocument->dar();
+           
+           // Deselect current effect / transition
+           m_effectStack->slotClipItemSelected(NULL, 0);
+           m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
+           
             m_activeDocument->setProfilePath(profile);
             KdenliveSettings::setCurrent_profile(profile);
             KdenliveSettings::setProject_fps(m_activeDocument->fps());
             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
             m_monitorManager->resetProfiles(m_activeDocument->timecode());
+           m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeTimeline->tracksNumber());
+           m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
             m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
index d86ee605db75aad7ac27b99adf43608269d8cb20..fc2a6421e6f6ece490d3fc272f998b7335ca193a 100644 (file)
@@ -228,6 +228,20 @@ MltVideoProfile ProfilesDialog::getVideoProfile(QString name)
     return result;
 }
 
+// static
+double ProfilesDialog::getStringEval(const MltVideoProfile &profile, QString eval)
+{
+    double result;
+    eval.replace("%width", QString::number(profile.width));
+    eval.replace("%height", QString::number(profile.height));
+    if (eval.contains('/')) result = (double) eval.section('/', 0, 0).toInt() / eval.section('/', 1, 1).toInt();
+    else if (eval.contains('*')) result = (double) eval.section('*', 0, 0).toInt() * eval.section('*', 1, 1).toInt();
+    else if (eval.contains('+')) result = (double) eval.section('+', 0, 0).toInt() + eval.section('+', 1, 1).toInt();
+    else if (eval.contains('-')) result = (double) eval.section('-', 0, 0).toInt() - eval.section('-', 1, 1).toInt();
+    else result = eval.toDouble();
+    return result;
+}
+
 
 // static
 bool ProfilesDialog::existingProfileDescription(const QString &desc)
index 9f5e78f673bc124b34faf33850da9b79dfb9d877..1bac83d3a6cd3de178dbc005f65b5968824469cd 100644 (file)
@@ -41,6 +41,7 @@ public:
     static void saveProfile(MltVideoProfile &profile);
     static QString existingProfile(MltVideoProfile profile);
     static bool existingProfileDescription(const QString &desc);
+    static double getStringEval(const MltVideoProfile &profile, QString eval);
 
 protected:
     virtual void closeEvent(QCloseEvent *event);
index a78c7bf1ae2a9c87c4afbc03cbe14549c4c016b9..d8a45938e85d27efd2c187c62dc4cd197365a673 100644 (file)
@@ -30,6 +30,7 @@
 #include "mainwindow.h"
 #include "customtrackview.h"
 #include "initeffects.h"
+#include "profilesdialog.h"
 
 #include <KDebug>
 #include <KMessageBox>
@@ -323,9 +324,14 @@ void TrackView::parseDocument(QDomDocument doc)
                             QDomElement e = params.item(i).toElement();
                             if (!e.isNull() && e.attribute("tag") == paramName) {
                                 if (e.attribute("type") == "double") {
-                                    QString factor = e.attribute("factor", "1");
+                                   QString factor = e.attribute("factor", "1");
                                     if (factor != "1") {
-                                        double val = paramValue.toDouble() * factor.toDouble();
+                                       double fact;
+                                       if (factor.startsWith('%')) {
+                                           fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
+                                       }
+                                       else fact = factor.toDouble();
+                                        double val = paramValue.toDouble() * fact;
                                         paramValue = QString::number(val);
                                     }
                                 }
@@ -597,7 +603,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
                             if (MainWindow::videoEffects.hasKeyFrames(currenteffect)) {
                                 //kDebug() << " * * * * * * * * * * ** CLIP EFF WITH KFR FND  * * * * * * * * * * *";
                                 // effect is key-framable, read all effects to retrieve keyframes
-                                double factor = 0;
+                                QString factor;
                                 QString starttag;
                                 QString endtag;
                                 QDomNodeList params = currenteffect.elementsByTagName("parameter");
@@ -606,7 +612,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
                                     if (e.attribute("type") == "keyframe") {
                                         starttag = e.attribute("starttag", "start");
                                         endtag = e.attribute("endtag", "end");
-                                        factor = e.attribute("factor", "1").toDouble();
+                                        factor = e.attribute("factor", "1");
                                         break;
                                     }
                                 }
@@ -615,13 +621,18 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
                                 int effectout = effect.attribute("out").toInt();
                                 double startvalue = 0;
                                 double endvalue = 0;
+                                double fact;
+                                if (factor.isEmpty()) fact = 1;
+                                else if (factor.startsWith('%')) {
+                                   fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
+                                } else fact = factor.toDouble();
                                 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
                                     // parse effect parameters
                                     QDomElement effectparam = n3.toElement();
                                     if (effectparam.attribute("name") == starttag)
-                                        startvalue = effectparam.text().toDouble() * factor;
+                                        startvalue = effectparam.text().toDouble() * fact;
                                     if (effectparam.attribute("name") == endtag)
-                                        endvalue = effectparam.text().toDouble() * factor;
+                                        endvalue = effectparam.text().toDouble() * fact;
                                 }
                                 // add first keyframe
                                 keyframes.append(QString::number(effectin) + ':' + QString::number(startvalue) + ';' + QString::number(effectout) + ':' + QString::number(endvalue) + ';');
@@ -644,7 +655,7 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
                                             continueParsing = false;
                                             break;
                                         } else if (subeffectparam.attribute("name") == endtag) {
-                                            endvalue = subeffectparam.text().toDouble() * factor;
+                                            endvalue = subeffectparam.text().toDouble() * fact;
                                             break;
                                         }
                                     }
@@ -685,9 +696,13 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
                                 for (int k = 0; k < clipeffectparams.count(); k++) {
                                     e = clipeffectparams.item(k).toElement();
                                     if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
-                                        double factor = e.attribute("factor", "1").toDouble();
-                                        if (factor != 1) {
-                                            e.setAttribute("value", paramvalue.toDouble() * factor);
+                                        if (e.attribute("factor", "1") != "1") {
+                                            QString factor = e.attribute("factor", "1");
+                                            double fact;
+                                            if (factor.startsWith('%')) {
+                                               fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
+                                            } else fact = factor.toDouble();
+                                            e.setAttribute("value", paramvalue.toDouble() * fact);
                                         } else e.setAttribute("value", paramvalue);
                                         break;
                                     }