X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdocclipbase.cpp;h=ae8a07a03f5fd9b58f5cbc8679e29cd1f3ba1ac3;hb=8bcc799b522e6e5ae0299973b4d296bef831a17f;hp=81c55ad25552aa8d2104e24b2967b83f60020706;hpb=4664de14c0240086ced95c4ff9e4c1101a60051d;p=kdenlive diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 81c55ad2..ae8a07a0 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -1,56 +1,88 @@ -/**************************1************************************************* - DocClipBase.cpp - description - ------------------- - begin : Fri Apr 12 2002 - copyright : (C) 2002 by Jason Wood - copyright : (C) 2009 by Jean-Baptiste Mardelle - - ***************************************************************************/ - /*************************************************************************** + * DocClipBase.cpp - description * + * ------------------- * + * begin : Fri Apr 12 2002 * + * Copyright (C) 2002 by Jason Wood (jasonwood@blueyonder.co.uk) * + * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ + + #include "docclipbase.h" #include "kdenlivesettings.h" #include "kthumb.h" #include "clipmanager.h" +#include #include #include -DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id): - m_id(id), m_description(QString()), m_refcount(0), m_audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL), m_properties(QMap ()), audioFrameChache(QMap > ()), m_baseTrackProducers(QList ()), m_snapMarkers(QList < CommentedTime > ()) { +DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) : + QObject(), + m_audioFrameCache(), + m_refcount(0), + m_baseTrackProducers(), + m_audioTrackProducers(), + m_videoOnlyProducer(NULL), + m_snapMarkers(), + m_duration(), + m_audioTimer(NULL), + m_thumbProd(NULL), + m_audioThumbCreated(false), + m_id(id), + 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 (unsigned int i = 0; i < attributes.count(); i++) { + 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(), z.section('-', 2, 2)); + } + } + KUrl url = KUrl(xml.attribute("resource")); if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path()); - int out = xml.attribute("out").toInt(); - if (out != 0) { - setDuration(GenTime(out, KdenliveSettings::project_fps())); + + if (xml.hasAttribute("duration")) { + setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps())); } else { - out = xml.attribute("duration").toInt(); - if (out != 0) setDuration(GenTime(out, KdenliveSettings::project_fps())); + int out = xml.attribute("out").toInt(); + int in = xml.attribute("in").toInt(); + setDuration(GenTime(out - in, KdenliveSettings::project_fps())); } + if (!m_properties.contains("name")) m_properties.insert("name", url.fileName()); //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; } @@ -66,45 +98,56 @@ DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QStrin return *this; }*/ -DocClipBase::~DocClipBase() { - if (m_thumbProd) { - delete m_thumbProd; - } +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); + m_audioTrackProducers.clear(); + delete m_videoOnlyProducer; + m_videoOnlyProducer = NULL; } -void DocClipBase::setZone(QPoint zone) { +void DocClipBase::setZone(QPoint zone) +{ m_properties.insert("zone_in", QString::number(zone.x())); m_properties.insert("zone_out", QString::number(zone.y())); } -QPoint DocClipBase::zone() const { +QPoint DocClipBase::zone() const +{ QPoint zone; zone.setX(m_properties.value("zone_in").toInt()); zone.setY(m_properties.value("zone_out", "50").toInt()); return zone; } -void DocClipBase::slotCreateAudioTimer() { +void DocClipBase::slotCreateAudioTimer() +{ connect(m_thumbProd, SIGNAL(audioThumbReady(QMap >)), this , SLOT(updateAudioThumbnail(QMap >))); 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_thumbProd->askForAudioThumbs(getId()); +void DocClipBase::askForAudioThumbs() +{ + if (m_thumbProd && m_audioTimer) slotGetAudioThumbs(); } -void DocClipBase::slotClearAudioCache() { +void DocClipBase::slotClearAudioCache() +{ if (m_thumbProd) m_thumbProd->stopAudioThumbs(); if (m_audioTimer != NULL) m_audioTimer->stop(); - audioFrameChache.clear(); + m_audioFrameCache.clear(); m_audioThumbCreated = false; } @@ -112,89 +155,112 @@ void DocClipBase::slotClearAudioCache() { if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt()); }*/ -KThumb *DocClipBase::thumbProducer() { +KThumb *DocClipBase::thumbProducer() +{ return m_thumbProd; } -bool DocClipBase::audioThumbCreated() const { +bool DocClipBase::audioThumbCreated() const +{ return m_audioThumbCreated; } -const QString DocClipBase::name() const { +const QString DocClipBase::name() const +{ return m_properties.value("name"); } -const QString &DocClipBase::getId() const { +const QString &DocClipBase::getId() const +{ return m_id; } -void DocClipBase::setId(const QString &newId) { +void DocClipBase::setId(const QString &newId) +{ m_id = newId; } -const CLIPTYPE & DocClipBase::clipType() const { +const CLIPTYPE & DocClipBase::clipType() const +{ return m_clipType; } -void DocClipBase::setClipType(CLIPTYPE type) { +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(); } -KUrl DocClipBase::fileURL() const { +KUrl DocClipBase::fileURL() const +{ QString res = m_properties.value("resource"); if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res); return KUrl(); } -void DocClipBase::setClipThumbFrame(const uint &ix) { +void DocClipBase::setClipThumbFrame(const uint &ix) +{ m_properties.insert("thumbnail", QString::number((int) ix)); } -uint DocClipBase::getClipThumbFrame() const { +uint DocClipBase::getClipThumbFrame() const +{ return (uint) m_properties.value("thumbnail").toInt(); } -const QString DocClipBase::description() const { +const QString DocClipBase::description() const +{ return m_properties.value("description"); } -bool DocClipBase::isTransparent() const { +bool DocClipBase::isTransparent() const +{ return (m_properties.value("transparency") == "1"); } -const QString DocClipBase::getProperty(const QString prop) const { +const QString DocClipBase::getProperty(const QString prop) const +{ return m_properties.value(prop); } -void DocClipBase::setDuration(GenTime dur) { +void DocClipBase::setDuration(GenTime dur) +{ m_duration = dur; m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps()))); } -const GenTime &DocClipBase::duration() const { +const GenTime &DocClipBase::duration() const +{ return m_duration; } -const GenTime DocClipBase::maxDuration() 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; } -bool DocClipBase::hasFileSize() const { +bool DocClipBase::hasFileSize() const +{ return true; } +qulonglong DocClipBase::fileSize() const +{ + return m_properties.value("file_size").toULongLong(); +} // virtual -QDomElement DocClipBase::toXML() const { +QDomElement DocClipBase::toXML() const +{ QDomDocument doc; QDomElement clip = doc.createElement("producer"); @@ -204,93 +270,66 @@ QDomElement DocClipBase::toXML() const { if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value()); } doc.appendChild(clip); - //kDebug()<<"/// CLIP XML: "< props; - props.insert("description", description); - clip->setProperties(props); - clip->setAudioThumbCreated(false); + clip.setAttribute("cutzones", cuts.join(";")); } - return clip; + //kDebug() << "/// CLIP XML: " << doc.toString(); + return doc.documentElement(); } -void DocClipBase::setAudioThumbCreated(bool isDone) { + +void DocClipBase::setAudioThumbCreated(bool isDone) +{ m_audioThumbCreated = isDone; } -void DocClipBase::setThumbnail(const QPixmap & pixmap) { +void DocClipBase::setThumbnail(const QPixmap & pixmap) +{ m_thumbnail = pixmap; } -const QPixmap & DocClipBase::thumbnail() const { +const QPixmap & DocClipBase::thumbnail() const +{ return m_thumbnail; } -void DocClipBase::updateAudioThumbnail(QMap > data) { +void DocClipBase::updateAudioThumbnail(QMap > data) +{ //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************"; - audioFrameChache = data; + m_audioFrameCache = data; m_audioThumbCreated = true; emit gotAudioData(); } -QList < GenTime > DocClipBase::snapMarkers() const { +QList < GenTime > DocClipBase::snapMarkers() const +{ QList < GenTime > markers; - for (uint count = 0; count < m_snapMarkers.count(); ++count) { - markers.append(m_snapMarkers[count].time()); + for (int count = 0; count < m_snapMarkers.count(); ++count) { + markers.append(m_snapMarkers.at(count).time()); } return markers; } -QList < CommentedTime > DocClipBase::commentedSnapMarkers() const { +QList < CommentedTime > DocClipBase::commentedSnapMarkers() const +{ return m_snapMarkers; } -void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) { +void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) +{ m_snapMarkers = markers; } -void DocClipBase::addSnapMarker(const GenTime & time, QString comment) { +void DocClipBase::addSnapMarker(const GenTime & time, QString comment) +{ QList < CommentedTime >::Iterator it = m_snapMarkers.begin(); for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) { if ((*it).time() >= time) @@ -307,7 +346,8 @@ void DocClipBase::addSnapMarker(const GenTime & time, QString comment) { } -void DocClipBase::editSnapMarker(const GenTime & time, QString comment) { +void DocClipBase::editSnapMarker(const GenTime & time, QString comment) +{ QList < CommentedTime >::Iterator it; for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) { if ((*it).time() == time) @@ -320,7 +360,8 @@ void DocClipBase::editSnapMarker(const GenTime & time, QString comment) { } } -QString DocClipBase::deleteSnapMarker(const GenTime & time) { +QString DocClipBase::deleteSnapMarker(const GenTime & time) +{ QString result = i18n("Marker"); QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); @@ -338,7 +379,8 @@ QString DocClipBase::deleteSnapMarker(const GenTime & time) { } -GenTime DocClipBase::hasSnapMarkers(const GenTime & time) { +GenTime DocClipBase::hasSnapMarkers(const GenTime & time) +{ QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); while (itt != m_snapMarkers.end()) { @@ -350,29 +392,32 @@ GenTime DocClipBase::hasSnapMarkers(const GenTime & time) { return GenTime(0.0); } -GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) { +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) { +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(); } -QString DocClipBase::markerComment(GenTime t) { +QString DocClipBase::markerComment(GenTime t) +{ QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); while (itt != m_snapMarkers.end()) { @@ -383,18 +428,62 @@ QString DocClipBase::markerComment(GenTime t) { return QString(); } -void DocClipBase::deleteProducers() { - qDeleteAll(m_baseTrackProducers); +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: "<get("id"); + deleteProducers(); + } QString id = producer->get("id"); if (id.contains('_')) { // this is a subtrack producer, insert it at correct place - int pos = id.section('_', 1, 1).toInt(); + id = id.section('_', 1); + if (id.endsWith("audio")) { + int pos = id.section('_', 0, 0).toInt(); + if (pos >= m_audioTrackProducers.count()) { + while (m_audioTrackProducers.count() - 1 < pos) { + m_audioTrackProducers.append(NULL); + } + } + if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer; + return; + } else if (id.endsWith("video")) { + m_videoOnlyProducer = producer; + return; + } + int pos = id.toInt(); if (pos >= m_baseTrackProducers.count()) { while (m_baseTrackProducers.count() - 1 < pos) { m_baseTrackProducers.append(NULL); @@ -407,16 +496,56 @@ 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) +{ + if (m_audioTrackProducers.count() <= track) { + while (m_audioTrackProducers.count() - 1 < track) { + m_audioTrackProducers.append(NULL); + } + } + if (m_audioTrackProducers.at(track) == NULL) { + Mlt::Producer *base = producer(); + m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource")); + if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble()); + if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt()); + m_audioTrackProducers.at(track)->set("video_index", -1); + if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt()); + char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data()); + m_audioTrackProducers.at(track)->set("id", tmp); + delete[] tmp; + } + return m_audioTrackProducers.at(track); } -Mlt::Producer *DocClipBase::producer(int track) { +Mlt::Producer *DocClipBase::videoProducer() +{ + if (m_videoOnlyProducer == NULL) { + int i; + for (i = 0; i < m_baseTrackProducers.count(); i++) + if (m_baseTrackProducers.at(i) != NULL) break; + if (i >= m_baseTrackProducers.count()) return NULL; + m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource")); + if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble()); + if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt()); + m_videoOnlyProducer->set("audio_index", -1); + if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt()); + char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data()); + m_videoOnlyProducer->set("id", tmp); + delete[] tmp; + } + return m_videoOnlyProducer; +} + +Mlt::Producer *DocClipBase::producer(int track) +{ /*for (int i = 0; i < m_baseTrackProducers.count(); i++) { if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id"); }*/ if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) { if (m_baseTrackProducers.count() == 0) return NULL; - int i; for (int i = 0; i < m_baseTrackProducers.count(); i++) { if (m_baseTrackProducers.at(i) != NULL) return m_baseTrackProducers.at(i); @@ -432,8 +561,16 @@ Mlt::Producer *DocClipBase::producer(int track) { int i; for (i = 0; i < m_baseTrackProducers.count(); i++) 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")); + + 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()); if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt()); @@ -449,21 +586,32 @@ Mlt::Producer *DocClipBase::producer(int track) { return m_baseTrackProducers.at(track); } -void DocClipBase::setProducerProperty(const char *name, int data) { +void DocClipBase::setProducerProperty(const char *name, int 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) { +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); } } -const char *DocClipBase::producerProperty(const char *name) const { +void DocClipBase::setProducerProperty(const char *name, const char *data) +{ + for (int i = 0; i < m_baseTrackProducers.count(); i++) { + if (m_baseTrackProducers.at(i) != NULL) + m_baseTrackProducers[i]->set(name, data); + } +} + +const char *DocClipBase::producerProperty(const char *name) const +{ for (int i = 0; i < m_baseTrackProducers.count(); i++) { if (m_baseTrackProducers.at(i) != NULL) { return m_baseTrackProducers.at(i)->get(name); @@ -473,7 +621,8 @@ const char *DocClipBase::producerProperty(const char *name) const { } -void DocClipBase::slotRefreshProducer() { +void DocClipBase::slotRefreshProducer() +{ if (m_baseTrackProducers.count() == 0) return; kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!"; if (m_clipType == SLIDESHOW) { @@ -492,14 +641,14 @@ void DocClipBase::slotRefreshProducer() { int ct = 0; Mlt::Filter *filter = clipService.filter(ct); while (filter) { - if (filter->get("mlt_service") == "luma") { + if (strcmp(filter->get("mlt_service"), "luma") == 0) { break; } ct++; filter = clipService.filter(ct); } - if (filter && filter->get("mlt_service") == "luma") { + if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) { filter->set("period", getProperty("ttl").toInt() - 1); filter->set("luma.out", getProperty("luma_duration").toInt()); QString resource = getProperty("luma_file"); @@ -531,7 +680,7 @@ void DocClipBase::slotRefreshProducer() { int ct = 0; Mlt::Filter *filter = clipService.filter(0); while (filter) { - if (filter->get("mlt_service") == "luma") { + if (strcmp(filter->get("mlt_service"), "luma") == 0) { clipService.detach(*filter); } else ct++; filter = clipService.filter(ct); @@ -540,7 +689,8 @@ void DocClipBase::slotRefreshProducer() { } } -void DocClipBase::setProperties(QMap properties) { +void DocClipBase::setProperties(QMap properties) +{ // changing clip type is not allowed properties.remove("type"); QMapIterator i(properties); @@ -555,19 +705,23 @@ void DocClipBase::setProperties(QMap properties) { if (refreshProducer) slotRefreshProducer(); } -void DocClipBase::setMetadata(QMap properties) { +void DocClipBase::setMetadata(QMap properties) +{ m_metadata = properties; } -QMap DocClipBase::metadata() const { +QMap DocClipBase::metadata() const +{ return m_metadata; } -void DocClipBase::clearProperty(const QString &key) { +void DocClipBase::clearProperty(const QString &key) +{ m_properties.remove(key); } -void DocClipBase::getFileHash(const QString &url) { +void DocClipBase::getFileHash(const QString url) +{ if (m_clipType == SLIDESHOW) return; QFile file(url); if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file @@ -588,23 +742,49 @@ 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(); } } -QString DocClipBase::getClipHash() const { +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; } -void DocClipBase::refreshThumbUrl() { +// 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")); } -void DocClipBase::setProperty(const QString &key, const QString &value) { +void DocClipBase::setProperty(const QString &key, const QString &value) +{ m_properties.insert(key, value); if (key == "resource") { getFileHash(value); @@ -615,11 +795,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") { @@ -640,26 +829,80 @@ void DocClipBase::setProperty(const QString &key, const QString &value) { } } -QMap DocClipBase::properties() const { +QMap DocClipBase::properties() const +{ return m_properties; } -bool DocClipBase::slotGetAudioThumbs() { +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; } +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 DocClipBase::cutZones() const +{ + return m_cutZones; +}