]> git.sesse.net Git - kdenlive/blobdiff - src/clipitem.cpp
xml for frei0r saturat0r & lens correction
[kdenlive] / src / clipitem.cpp
index 9e43db237ceb0a440c4d18a4db410f224362fc97..75c5ca2290f3654c1376b79bdcbce553fa1cac4b 100644 (file)
@@ -26,6 +26,7 @@
 #include "transition.h"
 #include "kdenlivesettings.h"
 #include "kthumb.h"
+#include "profilesdialog.h"
 
 #include <KDebug>
 #include <KIcon>
@@ -39,7 +40,6 @@
 ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, double fps, double speed, bool generateThumbs) :
         AbstractClipItem(info, QRectF(), fps),
         m_clip(clip),
-        m_resizeMode(NONE),
         m_startFade(0),
         m_endFade(0),
         m_audioOnly(false),
@@ -147,6 +147,7 @@ void ClipItem::setEffectList(const EffectsList effectList)
 {
     m_effectList = effectList;
     m_effectNames = m_effectList.effectNames().join(" / ");
+    if (!m_effectList.isEmpty()) setSelectedEffect(0);
 }
 
 const EffectsList ClipItem::effectList()
@@ -170,11 +171,21 @@ 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
             if (e.attribute("keyframes").isEmpty()) {
-                e.setAttribute("keyframes", QString::number(m_cropStart.frames(m_fps)) + ':' + def + ';' + QString::number((m_cropStart + m_cropDuration).frames(m_fps)) + ':' + def);
+                e.setAttribute("keyframes", QString::number(cropStart().frames(m_fps)) + ':' + def + ';' + QString::number((cropStart() + cropDuration()).frames(m_fps)) + ':' + def);
                 //kDebug() << "///// EFFECT KEYFRAMES INITED: " << e.attribute("keyframes");
                 break;
             }
@@ -182,7 +193,7 @@ void ClipItem::initEffect(QDomElement effect)
     }
     if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") {
         if (effect.attribute("id") == "fadeout" || effect.attribute("id") == "fade_to_black") {
-            int end = (duration() + cropStart()).frames(m_fps);
+            int end = (cropDuration() + cropStart()).frames(m_fps);
             int start = end;
             if (effect.attribute("id") == "fadeout") {
                 if (m_effectList.hasEffect(QString(), "fade_to_black") == -1) {
@@ -704,9 +715,8 @@ void ClipItem::paint(QPainter *painter,
         QRectF mappedRect;
         if (m_clipType == AV && !isAudioOnly()) {
             QRectF re =  br;
-            re.setTop(re.y() + re.height() / 2);
             mappedRect = painter->matrix().mapRect(re);
-            //painter->fillRect(mappedRect, QBrush(QColor(200, 200, 200, 140)));
+            mappedRect.setTop(mappedRect.bottom() - re.height() / 2);
         } else mappedRect = mapped;
 
         int channels = baseClip()->getProperty("channels").toInt();
@@ -740,9 +750,9 @@ void ClipItem::paint(QPainter *painter,
     pen.setStyle(Qt::DotLine);
     painter->setPen(pen);
     for (; it != markers.end(); ++it) {
-        pos = (*it).time() - cropStart();
+        pos = (*it).time() / m_speed - cropStart();
         if (pos > GenTime()) {
-            if (pos > duration()) break;
+            if (pos > cropDuration()) break;
             QLineF l(br.x() + pos.frames(m_fps), br.y(), br.x() + pos.frames(m_fps), br.bottom());
             QLineF l2 = painter->matrix().map(l);
             //framepos = scale * pos.frames(m_fps);
@@ -849,7 +859,7 @@ void ClipItem::paint(QPainter *painter,
     }*/
 
     // draw effect or transition keyframes
-    if (itemWidth > 20) drawKeyFrames(painter, exposed);
+    if (mapped.width() > 20) drawKeyFrames(painter, exposed);
 
     painter->setMatrixEnabled(true);
 
@@ -908,7 +918,7 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos)
         else setToolTip(i18n("Audio fade duration: %1s", GenTime(m_endFade, m_fps).seconds()));
         return FADEOUT;
     } else if ((rect.right() - pos.x() < maximumOffset) && (rect.bottom() - pos.y() > addtransitionOffset)) {
-        setToolTip(i18n("Clip duration: %1s", duration().seconds()));
+        setToolTip(i18n("Clip duration: %1s", cropDuration().seconds()));
         return RESIZEEND;
     } else if ((pos.x() - rect.x() < 16 / scale) && (rect.bottom() - pos.y() <= addtransitionOffset)) {
         setToolTip(i18n("Add transition"));
@@ -928,9 +938,9 @@ QList <GenTime> ClipItem::snapMarkers() const
     GenTime pos;
 
     for (int i = 0; i < markers.size(); i++) {
-        pos = markers.at(i) - cropStart();
+        pos = markers.at(i) / m_speed - cropStart();
         if (pos > GenTime()) {
-            if (pos > duration()) break;
+            if (pos > cropDuration()) break;
             else snaps.append(pos + startPos());
         }
     }
@@ -944,9 +954,9 @@ QList <CommentedTime> ClipItem::commentedSnapMarkers() const
     GenTime pos;
 
     for (int i = 0; i < markers.size(); i++) {
-        pos = markers.at(i).time() - cropStart();
+        pos = markers.at(i).time() / m_speed - cropStart();
         if (pos > GenTime()) {
-            if (pos > duration()) break;
+            if (pos > cropDuration()) break;
             else snaps.append(CommentedTime(pos + startPos(), markers.at(i).comment()));
         }
     }
@@ -1072,24 +1082,6 @@ void ClipItem::setFadeOut(int pos)
 
 }
 
-// virtual
-void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event)
-{
-    /*m_resizeMode = operationMode(event->pos());
-    if (m_resizeMode == MOVE) {
-      m_maxTrack = scene()->sceneRect().height();
-      m_grabPoint = (int) (event->pos().x() - rect().x());
-    }*/
-    QGraphicsRectItem::mousePressEvent(event);
-}
-
-// virtual
-void ClipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
-{
-    m_resizeMode = NONE;
-    QGraphicsRectItem::mouseReleaseEvent(event);
-}
-
 /*
 //virtual
 void ClipItem::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
@@ -1142,10 +1134,10 @@ void ClipItem::resizeEnd(int posx, double /*speed*/, bool updateKeyFrames)
     if (posx > max && maxDuration() != GenTime()) posx = max;
     if (posx == endPos().frames(m_fps)) return;
     //kDebug() << "// NEW POS: " << posx << ", OLD END: " << endPos().frames(m_fps);
-    const int previous = (cropStart() + duration()).frames(m_fps);
+    const int previous = (cropStart() + cropDuration()).frames(m_fps);
     AbstractClipItem::resizeEnd(posx, m_speed);
-    if ((int)(cropStart() + duration()).frames(m_fps) != previous) {
-        if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + duration()).frames(m_fps), false);
+    if ((int)(cropStart() + cropDuration()).frames(m_fps) != previous) {
+        if (updateKeyFrames) checkEffectsKeyframesPos(previous, (cropStart() + cropDuration()).frames(m_fps), false);
         if (m_hasThumbs && KdenliveSettings::videothumbnails()) {
             /*connect(m_clip->thumbProducer(), SIGNAL(thumbReady(int, QPixmap)), this, SLOT(slotThumbReady(int, QPixmap)));*/
             m_endThumbTimer->start(150);
@@ -1294,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);
@@ -1346,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
@@ -1394,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));
             }
         }
     }
@@ -1454,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"));
             }