]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
Add subclips (dragging a zone from clip monitor to project tree)
[kdenlive] / src / docclipbase.cpp
index 6c3addf01ce4798a3715347fadf49a5673b5d4d4..6a72de10498b2e7273fc650b4bfa1c89b417d4b2 100644 (file)
@@ -58,6 +58,14 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
         m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
     }
 
+    if (xml.hasAttribute("cutzones")) {
+        QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
+        for (int i = 0; i < cuts.count(); i++) {
+            QString z = cuts.at(i);
+            addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt());
+        }
+    }
+
     KUrl url = KUrl(xml.attribute("resource"));
     if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
 
@@ -245,6 +253,10 @@ bool DocClipBase::hasFileSize() const
     return true;
 }
 
+qulonglong DocClipBase::fileSize() const
+{
+    return m_properties.value("file_size").toULongLong();
+}
 
 // virtual
 QDomElement DocClipBase::toXML() const
@@ -258,6 +270,13 @@ QDomElement DocClipBase::toXML() const
         if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
     }
     doc.appendChild(clip);
+    if (!m_cutZones.isEmpty()) {
+        QStringList cuts;
+        for (int i = 0; i < m_cutZones.size(); i++) {
+            cuts << QString::number(m_cutZones.at(i).x()) + "-" + QString::number(m_cutZones.at(i).y());
+        }
+        clip.setAttribute("cutzones", cuts.join(";"));
+    }
     //kDebug() << "/// CLIP XML: " << doc.toString();
     return doc.documentElement();
 }
@@ -292,7 +311,7 @@ QList < GenTime > DocClipBase::snapMarkers() const
     QList < GenTime > markers;
 
     for (int count = 0; count < m_snapMarkers.count(); ++count) {
-        markers.append(m_snapMarkers[count].time());
+        markers.append(m_snapMarkers.at(count).time());
     }
 
     return markers;
@@ -376,23 +395,23 @@ GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
 {
     int it;
     for (it = 0; it < m_snapMarkers.count(); it++) {
-        if (m_snapMarkers[it].time() >= currTime)
+        if (m_snapMarkers.at(it).time() >= currTime)
             break;
     }
     if (it == 0) return GenTime();
-    else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
-        return m_snapMarkers[it].time();
-    else return m_snapMarkers[it-1].time();
+    else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
+        return m_snapMarkers.at(it).time();
+    else return m_snapMarkers.at(it -1).time();
 }
 
 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
 {
     int it;
     for (it = 0; it < m_snapMarkers.count(); it++) {
-        if (m_snapMarkers[it].time() > currTime)
+        if (m_snapMarkers.at(it).time() > currTime)
             break;
     }
-    if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
+    if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
     return duration();
 }
 
@@ -408,15 +427,34 @@ QString DocClipBase::markerComment(GenTime t)
     return QString();
 }
 
+void DocClipBase::clearProducers()
+{
+    m_baseTrackProducers.clear();
+}
+
 void DocClipBase::deleteProducers()
 {
+    kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
+    if (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++) {
+        kDebug()<<"// CLIP KILL PROD "<<i;
+    Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
+    if (p != NULL) {
+     delete p;
+     p = NULL;
+    }
+    m_baseTrackProducers.insert(i, NULL);
+    }*/
+
+    delete m_videoOnlyProducer;
+    m_videoOnlyProducer = NULL;
+
     qDeleteAll(m_baseTrackProducers);
     m_baseTrackProducers.clear();
-    if (m_thumbProd) m_thumbProd->clearProducer();
     qDeleteAll(m_audioTrackProducers);
     m_audioTrackProducers.clear();
-    delete m_videoOnlyProducer;
-    m_videoOnlyProducer = NULL;
 }
 
 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
@@ -424,6 +462,7 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
     if (producer == NULL) return;
     if (reset) {
         // Clear all previous producers
+        kDebug() << "/+++++++++++++++   DELETE ALL PRODS " << producer->get("id");
         deleteProducers();
     }
     QString id = producer->get("id");
@@ -439,8 +478,7 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
             }
             if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
             return;
-        }
-        if (id.endsWith("video")) {
+        } else if (id.endsWith("video")) {
             m_videoOnlyProducer = producer;
             return;
         }
@@ -769,6 +807,7 @@ void DocClipBase::setProperty(const QString &key, const QString &value)
     } else if (key == "force_aspect_ratio") {
         if (value.isEmpty()) {
             m_properties.remove("force_aspect_ratio");
+            //TODO: find a was to remove the "force_aspect_ratio" property from producer, currently does not work
             setProducerProperty("force_aspect_ratio", 0);
         } else setProducerProperty("force_aspect_ratio", value.toDouble());
     } else if (key == "threads") {
@@ -817,3 +856,37 @@ bool DocClipBase::isPlaceHolder() const
     return m_placeHolder;
 }
 
+void DocClipBase::addCutZone(int in, int out)
+{
+    if (!m_cutZones.contains(QPoint(in, out))) {
+        m_cutZones.append(QPoint(in, out));
+    }
+}
+
+bool DocClipBase::hasCutZone(QPoint p) const
+{
+    return m_cutZones.contains(p);
+}
+
+
+void DocClipBase::removeCutZone(int in, int out)
+{
+    m_cutZones.removeAll(QPoint(in, out));
+}
+
+void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out)
+{
+    QPoint old(oldin, oldout);
+    for (int i = 0; i < m_cutZones.size(); ++i) {
+        if (m_cutZones.at(i) == old) {
+            m_cutZones.replace(i, QPoint(in, out));
+            break;
+        }
+    }
+}
+
+QList <QPoint> DocClipBase::cutZones() const
+{
+    return m_cutZones;
+}
+