]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
Clip cuts in project tree can now have a description
[kdenlive] / src / docclipbase.cpp
index b1d5d1c9efbbdca29bcfefdafe74967a4d9db7d4..ae8a07a03f5fd9b58f5cbc8679e29cd1f3ba1ac3 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(), z.section('-', 2, 2));
+        }
+    }
+
     KUrl url = KUrl(xml.attribute("resource"));
     if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
 
@@ -74,7 +82,7 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin
     //if (!url.isEmpty() && QFile::exists(url.path()))
     {
         m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
-        if (m_clipType == AV || m_clipType == AUDIO) slotCreateAudioTimer();
+        if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer();
     }
     //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
 }
@@ -132,7 +140,7 @@ void DocClipBase::slotCreateAudioTimer()
 
 void DocClipBase::askForAudioThumbs()
 {
-    if (m_thumbProd) m_thumbProd->askForAudioThumbs(getId());
+    if (m_thumbProd && m_audioTimer) slotGetAudioThumbs();
 }
 
 void DocClipBase::slotClearAudioCache()
@@ -183,7 +191,7 @@ void DocClipBase::setClipType(CLIPTYPE type)
     m_clipType = type;
 
     m_properties.insert("type", QString::number((int) type));
-    if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO))
+    if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST))
         slotCreateAudioTimer();
 }
 
@@ -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,14 @@ 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++) {
+            CutZoneInfo info = m_cutZones.at(i);
+            cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
+        }
+        clip.setAttribute("cutzones", cuts.join(";"));
+    }
     //kDebug() << "/// CLIP XML: " << doc.toString();
     return doc.documentElement();
 }
@@ -292,7 +312,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 +396,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();
 }
 
@@ -447,7 +467,6 @@ void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
         deleteProducers();
     }
     QString id = producer->get("id");
-    kDebug() << "// set prod: " << id;
     if (id.contains('_')) {
         // this is a subtrack producer, insert it at correct place
         id = id.section('_', 1);
@@ -789,6 +808,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,16 +837,15 @@ QMap <QString, QString> DocClipBase::properties() const
 bool DocClipBase::slotGetAudioThumbs()
 {
     if (m_thumbProd == NULL) return false;
-    if (!KdenliveSettings::audiothumbnails()) {
+    if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
         if (m_audioTimer != NULL) m_audioTimer->stop();
         return false;
     }
     if (m_audioThumbCreated) {
-        if (m_audioTimer != NULL) m_audioTimer->stop();
+        m_audioTimer->stop();
         return false;
     }
-    if (m_audioTimer != NULL)
-        m_audioTimer->start(1500);
+    m_audioTimer->start(1500);
     double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
     m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
     return true;
@@ -837,3 +856,53 @@ bool DocClipBase::isPlaceHolder() const
     return m_placeHolder;
 }
 
+void DocClipBase::addCutZone(int in, int out, QString desc)
+{
+    CutZoneInfo info;
+    info.zone = QPoint(in, out);
+    info.description = desc;
+    for (int i = 0; i < m_cutZones.count(); i++)
+        if (m_cutZones.at(i).zone == info.zone) {
+            return;
+        }
+    m_cutZones.append(info);
+}
+
+bool DocClipBase::hasCutZone(QPoint p) const
+{
+    for (int i = 0; i < m_cutZones.count(); i++)
+        if (m_cutZones.at(i).zone == p) return true;
+    return false;
+}
+
+
+void DocClipBase::removeCutZone(int in, int out)
+{
+    QPoint p(in, out);
+    for (int i = 0; i < m_cutZones.count(); i++) {
+        if (m_cutZones.at(i).zone == p) {
+            m_cutZones.removeAt(i);
+            i--;
+        }
+    }
+}
+
+void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
+{
+    QPoint old(oldin, oldout);
+    for (int i = 0; i < m_cutZones.size(); ++i) {
+        if (m_cutZones.at(i).zone == old) {
+            CutZoneInfo info;
+            info.zone = QPoint(in, out);
+            info.description = desc;
+            m_cutZones.replace(i, info);
+            break;
+        }
+    }
+}
+
+QList <CutZoneInfo> DocClipBase::cutZones() const
+{
+    return m_cutZones;
+}
+