]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
Add animation feature to Slideshow Clip.
[kdenlive] / src / docclipbase.cpp
index f14026b74a6fc71e303076e7bc9a735acb61ecef..87194e0f33ce4cc904329b78a17e44e50bfc5fac 100644 (file)
@@ -28,6 +28,7 @@
 #include "kdenlivesettings.h"
 #include "kthumb.h"
 #include "clipmanager.h"
+#include "slideshowclip.h"
 
 #include <KIO/NetAccess>
 #include <KDebug>
@@ -57,7 +58,10 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
     if (m_placeHolder) xml.removeAttribute("placeholder");
     QDomNamedNodeMap attributes = xml.attributes();
     for (int i = 0; i < attributes.count(); i++) {
-        m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
+        QString name = attributes.item(i).nodeName();
+        if (name.startsWith("meta.attr.")) {
+            m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
+        } else m_properties.insert(name, attributes.item(i).nodeValue());
     }
 
     if (xml.hasAttribute("cutzones")) {
@@ -126,23 +130,20 @@ void DocClipBase::setZone(QPoint zone)
 
 QPoint DocClipBase::zone() const
 {
-    QPoint zone;
-    zone.setX(m_properties.value("zone_in").toInt());
-    zone.setY(m_properties.value("zone_out", "50").toInt());
+    QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
     return zone;
 }
 
 void DocClipBase::slotCreateAudioTimer()
 {
     connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
-    connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
     m_audioTimer = new QTimer(this);
     connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
 }
 
 void DocClipBase::askForAudioThumbs()
 {
-    if (m_thumbProd && m_audioTimer) slotGetAudioThumbs();
+    if (m_thumbProd && m_audioTimer) m_thumbProd->askForAudioThumbs(getId());
 }
 
 void DocClipBase::slotClearAudioCache()
@@ -431,10 +432,10 @@ void DocClipBase::clearProducers()
     m_baseTrackProducers.clear();
 }
 
-void DocClipBase::deleteProducers()
+void DocClipBase::deleteProducers(bool clearThumbCreator)
 {
     kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
-    if (m_thumbProd) m_thumbProd->clearProducer();
+    if (clearThumbCreator && m_thumbProd) m_thumbProd->clearProducer();
     /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
     int max = m_baseTrackProducers.count();
     for (int i = 0; i < max; i++) {
@@ -463,11 +464,12 @@ void DocClipBase::setValid()
 
 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
 {
-    if (producer == NULL || m_placeHolder) return;
+    if (producer == NULL || (m_placeHolder && !reset)) return;
+    if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
     if (reset) {
         // Clear all previous producers
         kDebug() << "/+++++++++++++++   DELETE ALL PRODS " << producer->get("id");
-        deleteProducers();
+        deleteProducers(false);
     }
     QString id = producer->get("id");
     if (id.contains('_')) {
@@ -499,7 +501,6 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
     }
     //m_clipProducer = producer;
     //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
-    if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
 }
 
 Mlt::Producer *DocClipBase::audioProducer(int track)
@@ -577,7 +578,6 @@ Mlt::Producer *DocClipBase::producer(int track)
             m_baseTrackProducers[track] = NULL;
             return NULL;
         }
-
         if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
         if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
         if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
@@ -651,6 +651,49 @@ void DocClipBase::slotRefreshProducer()
         if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
         setProducerProperty("ttl", getProperty("ttl").toInt());
         //m_clipProducer->set("id", getProperty("id"));
+        if (!getProperty("animation").isEmpty()) {
+            Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
+            int ct = 0;
+            Mlt::Filter *filter = clipService.filter(ct);
+            while (filter) {
+                if (strcmp(filter->get("mlt_service"), "affine") == 0) {
+                    break;
+                }
+                else if (strcmp(filter->get("mlt_service"), "boxblur") == 0) {
+                    clipService.detach(*filter);
+                } else ct++;
+                filter = clipService.filter(ct);
+            }
+
+            if (!filter || strcmp(filter->get("mlt_service"), "affine")) {
+                // filter does not exist, create it.
+                Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "affine");
+                if (filter && filter->is_valid()) {
+                    int cycle = getProperty("ttl").toInt();
+                    QString geometry = SlideshowClip::animationToGeometry(getProperty("animation"), cycle);
+                    if (!geometry.isEmpty()) {
+                        if (getProperty("animation").contains("low-pass")) {
+                            Mlt::Filter *blur = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "boxblur");
+                            if (blur && blur->is_valid())
+                                clipService.attach(*blur);
+                        }
+                        filter->set("transition.geometry", geometry.toUtf8().data());
+                        filter->set("transition.cycle", cycle);
+                        clipService.attach(*filter);
+                    }
+                }
+            }
+        } else {
+            Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
+            int ct = 0;
+            Mlt::Filter *filter = clipService.filter(0);
+            while (filter) {
+                if (strcmp(filter->get("mlt_service"), "affine") == 0 || strcmp(filter->get("mlt_service"), "boxblur") == 0) {
+                    clipService.detach(*filter);
+                } else ct++;
+                filter = clipService.filter(ct);
+            }
+        }
         if (getProperty("fade") == "1") {
             // we want a fade filter effect
             kDebug() << "////////////   FADE WANTED";
@@ -666,8 +709,8 @@ void DocClipBase::slotRefreshProducer()
             }
 
             if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
-                filter->set("period", getProperty("ttl").toInt() - 1);
-                filter->set("luma.out", getProperty("luma_duration").toInt());
+                filter->set("cycle", getProperty("ttl").toInt());
+                filter->set("duration", getProperty("luma_duration").toInt());
                 QString resource = getProperty("luma_file");
                 char *tmp = (char *) qstrdup(resource.toUtf8().data());
                 filter->set("luma.resource", tmp);
@@ -679,8 +722,8 @@ void DocClipBase::slotRefreshProducer()
             } else {
                 // filter does not exist, create it...
                 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
-                filter->set("period", getProperty("ttl").toInt() - 1);
-                filter->set("luma.out", getProperty("luma_duration").toInt());
+                filter->set("cycle", getProperty("ttl").toInt());
+                filter->set("duration", getProperty("luma_duration").toInt());
                 QString resource = getProperty("luma_file");
                 char *tmp = (char *) qstrdup(resource.toUtf8().data());
                 filter->set("luma.resource", tmp);
@@ -703,6 +746,36 @@ void DocClipBase::slotRefreshProducer()
                 filter = clipService.filter(ct);
             }
         }
+        if (getProperty("crop") == "1") {
+            // we want a center crop filter effect
+            Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
+            int ct = 0;
+            Mlt::Filter *filter = clipService.filter(ct);
+            while (filter) {
+                if (strcmp(filter->get("mlt_service"), "crop") == 0) {
+                    break;
+                }
+                ct++;
+                filter = clipService.filter(ct);
+            }
+
+            if (!filter || strcmp(filter->get("mlt_service"), "crop")) {
+                // filter does not exist, create it...
+                Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "crop");
+                filter->set("center", 1);
+                clipService.attach(*filter);
+            }
+        } else {
+            Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
+            int ct = 0;
+            Mlt::Filter *filter = clipService.filter(0);
+            while (filter) {
+                if (strcmp(filter->get("mlt_service"), "crop") == 0) {
+                    clipService.detach(*filter);
+                } else ct++;
+                filter = clipService.filter(ct);
+            }
+        }
     }
 }
 
@@ -724,7 +797,15 @@ void DocClipBase::setProperties(QMap <QString, QString> properties)
 
 void DocClipBase::setMetadata(QMap <QString, QString> properties)
 {
-    m_metadata = properties;
+    QMapIterator<QString, QString> i(properties);
+    while (i.hasNext()) {
+        i.next();
+        if (i.value().isEmpty() && m_metadata.contains(i.key())) {
+            m_metadata.remove(i.key());
+        } else {
+            m_metadata.insert(i.key(), i.value());
+        }
+    }
 }
 
 QMap <QString, QString> DocClipBase::metadata() const
@@ -762,6 +843,13 @@ void DocClipBase::getFileHash(const QString url)
     }
 }
 
+bool DocClipBase::checkHash() const
+{
+    KUrl url = fileURL();
+    if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
+    return true;
+}
+
 QString DocClipBase::getClipHash() const
 {
     QString hash;
@@ -772,6 +860,11 @@ QString DocClipBase::getClipHash() const
     return hash;
 }
 
+void DocClipBase::setPlaceHolder(bool place)
+{
+    m_placeHolder = place;
+}
+
 // static
 QString DocClipBase::getHash(const QString &path)
 {
@@ -862,7 +955,7 @@ QMap <QString, QString> DocClipBase::properties() const
 
 bool DocClipBase::slotGetAudioThumbs()
 {
-    if (m_thumbProd == NULL) return false;
+    if (m_thumbProd == NULL || isPlaceHolder()) return false;
     if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
         if (m_audioTimer != NULL) m_audioTimer->stop();
         return false;