X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdocclipbase.cpp;h=6a72de10498b2e7273fc650b4bfa1c89b417d4b2;hb=880efc8572a7df65453dfb5736de6455fe129a86;hp=1ecb29c7f7f012e1568122d2a1865635364f25a2;hpb=040425e542c9d3bfdeeb57a4bd59040a14b55dad;p=kdenlive diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 1ecb29c7..6a72de10 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -29,14 +29,14 @@ #include "kthumb.h" #include "clipmanager.h" +#include #include #include -DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id, bool placeHolder) : +DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) : QObject(), - audioFrameChache(), - m_description(), + m_audioFrameCache(), m_refcount(0), m_baseTrackProducers(), m_audioTrackProducers(), @@ -47,17 +47,25 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin m_thumbProd(NULL), m_audioThumbCreated(false), m_id(id), - m_placeHolder(placeHolder), + m_placeHolder(xml.hasAttribute("placeholder")), m_properties() { int type = xml.attribute("type").toInt(); m_clipType = (CLIPTYPE) type; - + 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()); } + 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()); @@ -92,11 +100,14 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin DocClipBase::~DocClipBase() { + kDebug() << "CLIP " << m_id << " DELETED******************************"; delete m_thumbProd; if (m_audioTimer) { m_audioTimer->stop(); delete m_audioTimer; } + /*kDebug() <<" * * *CNT "< 0) kDebug()<<"YOYO: "<get_out()<<", CUT: "<is_cut();*/ qDeleteAll(m_baseTrackProducers); m_baseTrackProducers.clear(); qDeleteAll(m_audioTrackProducers); @@ -136,7 +147,7 @@ void DocClipBase::slotClearAudioCache() { if (m_thumbProd) m_thumbProd->stopAudioThumbs(); if (m_audioTimer != NULL) m_audioTimer->stop(); - audioFrameChache.clear(); + m_audioFrameCache.clear(); m_audioThumbCreated = false; } @@ -230,8 +241,9 @@ const GenTime &DocClipBase::duration() const const GenTime DocClipBase::maxDuration() const { if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) { - const GenTime dur(15000, KdenliveSettings::project_fps()); - return dur; + /*const GenTime dur(15000, KdenliveSettings::project_fps()); + return dur;*/ + return GenTime(); } return m_duration; } @@ -241,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 @@ -254,7 +270,14 @@ QDomElement DocClipBase::toXML() const if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value()); } doc.appendChild(clip); - //kDebug()<<"/// CLIP XML: "< > data) { //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************"; - audioFrameChache = data; + m_audioFrameCache = data; m_audioThumbCreated = true; emit gotAudioData(); } @@ -288,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; @@ -372,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(); } @@ -404,20 +427,44 @@ 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: "<clearProducer(); qDeleteAll(m_audioTrackProducers); m_audioTrackProducers.clear(); - delete m_videoOnlyProducer; - m_videoOnlyProducer = NULL; } -void DocClipBase::setProducer(Mlt::Producer *producer) +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"); if (id.contains('_')) { // this is a subtrack producer, insert it at correct place @@ -431,8 +478,7 @@ void DocClipBase::setProducer(Mlt::Producer *producer) } if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer; return; - } - if (id.endsWith("video")) { + } else if (id.endsWith("video")) { m_videoOnlyProducer = producer; return; } @@ -449,7 +495,7 @@ void DocClipBase::setProducer(Mlt::Producer *producer) } //m_clipProducer = producer; //m_clipProducer->set("transparency", m_properties.value("transparency").toInt()); - if (m_thumbProd && !m_thumbProd->hasProducer()) m_thumbProd->setProducer(producer); + if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer); } Mlt::Producer *DocClipBase::audioProducer(int track) @@ -516,10 +562,13 @@ Mlt::Producer *DocClipBase::producer(int track) if (m_baseTrackProducers.at(i) != NULL) break; if (i >= m_baseTrackProducers.count()) return NULL; - m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource")); - // special case for placeholder clips - if (m_baseTrackProducers[track] == NULL) return NULL; + if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0)) + m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource")); + else { // special case for placeholder clips + 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("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt()); @@ -544,6 +593,14 @@ void DocClipBase::setProducerProperty(const char *name, int data) } } +void DocClipBase::setProducerProperty(const char *name, double data) +{ + for (int i = 0; i < m_baseTrackProducers.count(); i++) { + if (m_baseTrackProducers.at(i) != NULL) + m_baseTrackProducers[i]->set(name, data); + } +} + void DocClipBase::setProducerProperty(const char *name, const char *data) { for (int i = 0; i < m_baseTrackProducers.count(); i++) { @@ -684,7 +741,6 @@ void DocClipBase::getFileHash(const QString url) file.close(); fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5); m_properties.insert("file_hash", QString(fileHash.toHex())); - //kDebug() << file.fileName() << file.size() << fileHash.toHex(); } } @@ -693,10 +749,34 @@ QString DocClipBase::getClipHash() const QString hash; if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex(); else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex(); + else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex(); else hash = m_properties.value("file_hash"); return hash; } +// static +QString DocClipBase::getHash(const QString &path) +{ + QFile file(path); + if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file + QByteArray fileData; + QByteArray fileHash; + /* + * 1 MB = 1 second per 450 files (or faster) + * 10 MB = 9 seconds per 450 files (or faster) + */ + if (file.size() > 1000000*2) { + fileData = file.read(1000000); + if (file.seek(file.size() - 1000000)) + fileData.append(file.readAll()); + } else + fileData = file.readAll(); + file.close(); + return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex(); + } + return QString(); +} + void DocClipBase::refreshThumbUrl() { if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash")); @@ -714,11 +794,20 @@ void DocClipBase::setProperty(const QString &key, const QString &value) char *tmp = (char *) qstrdup(value.toUtf8().data()); setProducerProperty("colour", tmp); delete[] tmp; + } else if (key == "templatetext") { + char *tmp = (char *) qstrdup(value.toUtf8().data()); + setProducerProperty("templatetext", tmp); + delete[] tmp; + setProducerProperty("force_reload", 1); } else if (key == "xmldata") { + char *tmp = (char *) qstrdup(value.toUtf8().data()); + setProducerProperty("xmldata", tmp); + delete[] tmp; setProducerProperty("force_reload", 1); } 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") { @@ -767,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 DocClipBase::cutZones() const +{ + return m_cutZones; +} +