1 /***************************************************************************
2 * DocClipBase.cpp - description *
3 * ------------------- *
4 * begin : Fri Apr 12 2002 *
5 * Copyright (C) 2002 by Jason Wood (jasonwood@blueyonder.co.uk) *
6 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
22 ***************************************************************************/
27 #include "docclipbase.h"
28 #include "kdenlivesettings.h"
30 #include "clipmanager.h"
32 #include <KIO/NetAccess>
35 #include <QCryptographicHash>
39 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
43 m_baseTrackProducers(),
44 m_audioTrackProducers(),
45 m_videoOnlyProducer(NULL),
46 m_snapMarkers(QList < CommentedTime >()),
50 m_audioThumbCreated(false),
52 m_placeHolder(xml.hasAttribute("placeholder")),
55 int type = xml.attribute("type").toInt();
56 m_clipType = (CLIPTYPE) type;
57 if (m_placeHolder) xml.removeAttribute("placeholder");
58 QDomNamedNodeMap attributes = xml.attributes();
59 for (int i = 0; i < attributes.count(); i++) {
60 QString name = attributes.item(i).nodeName();
61 if (name.startsWith("meta.attr.")) m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
62 else m_properties.insert(name, attributes.item(i).nodeValue());
65 if (xml.hasAttribute("cutzones")) {
66 QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
67 for (int i = 0; i < cuts.count(); i++) {
68 QString z = cuts.at(i);
69 addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
73 KUrl url = KUrl(xml.attribute("resource"));
74 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
76 if (xml.hasAttribute("duration")) {
77 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
79 int out = xml.attribute("out").toInt();
80 int in = xml.attribute("in").toInt();
81 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
84 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
86 //if (!url.isEmpty() && QFile::exists(url.path()))
88 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
89 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer();
91 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
94 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
95 DocClipBase::operator=(clip);
97 m_clipType = clip.clipType();
99 m_duration = clip.duration();
100 m_audioThumbCreated = clip.audioThumbCreated();
101 m_properties = clip.properties();
105 DocClipBase::~DocClipBase()
107 kDebug() << "CLIP " << m_id << " DELETED******************************";
110 m_audioTimer->stop();
113 /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
114 if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
115 qDeleteAll(m_baseTrackProducers);
116 m_baseTrackProducers.clear();
117 qDeleteAll(m_audioTrackProducers);
118 m_audioTrackProducers.clear();
119 delete m_videoOnlyProducer;
120 m_videoOnlyProducer = NULL;
123 void DocClipBase::setZone(QPoint zone)
125 m_properties.insert("zone_in", QString::number(zone.x()));
126 m_properties.insert("zone_out", QString::number(zone.y()));
129 QPoint DocClipBase::zone() const
131 QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
135 void DocClipBase::slotCreateAudioTimer()
137 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
138 m_audioTimer = new QTimer(this);
139 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
142 void DocClipBase::askForAudioThumbs()
144 if (m_thumbProd && m_audioTimer) m_thumbProd->askForAudioThumbs(getId());
147 void DocClipBase::slotClearAudioCache()
149 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
150 if (m_audioTimer != NULL) m_audioTimer->stop();
151 m_audioFrameCache.clear();
152 m_audioThumbCreated = false;
155 /*void DocClipBase::getClipMainThumb() {
156 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
159 KThumb *DocClipBase::thumbProducer()
164 bool DocClipBase::audioThumbCreated() const
166 return m_audioThumbCreated;
169 const QString DocClipBase::name() const
172 return m_properties.value("name");
175 const QString &DocClipBase::getId() const
180 void DocClipBase::setId(const QString &newId)
185 const CLIPTYPE & DocClipBase::clipType() const
190 void DocClipBase::setClipType(CLIPTYPE type)
194 m_properties.insert("type", QString::number((int) type));
195 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST))
196 slotCreateAudioTimer();
199 KUrl DocClipBase::fileURL() const
201 QString res = m_properties.value("resource");
202 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
206 void DocClipBase::setClipThumbFrame(const uint &ix)
208 m_properties.insert("thumbnail", QString::number((int) ix));
211 uint DocClipBase::getClipThumbFrame() const
213 return (uint) m_properties.value("thumbnail").toInt();
216 const QString DocClipBase::description() const
218 return m_properties.value("description");
221 bool DocClipBase::isTransparent() const
223 return (m_properties.value("transparency") == "1");
226 const QString DocClipBase::getProperty(const QString prop) const
228 return m_properties.value(prop);
231 void DocClipBase::setDuration(GenTime dur)
234 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
237 const GenTime &DocClipBase::duration() const
242 const GenTime DocClipBase::maxDuration() const
244 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
245 /*const GenTime dur(15000, KdenliveSettings::project_fps());
252 bool DocClipBase::hasFileSize() const
257 qulonglong DocClipBase::fileSize() const
259 return m_properties.value("file_size").toULongLong();
263 QDomElement DocClipBase::toXML() const
266 QDomElement clip = doc.createElement("producer");
268 QMapIterator<QString, QString> i(m_properties);
269 while (i.hasNext()) {
271 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
273 doc.appendChild(clip);
274 if (!m_cutZones.isEmpty()) {
276 for (int i = 0; i < m_cutZones.size(); i++) {
277 CutZoneInfo info = m_cutZones.at(i);
278 cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
280 clip.setAttribute("cutzones", cuts.join(";"));
282 //kDebug() << "/// CLIP XML: " << doc.toString();
283 return doc.documentElement();
287 void DocClipBase::setAudioThumbCreated(bool isDone)
289 m_audioThumbCreated = isDone;
293 void DocClipBase::setThumbnail(const QPixmap & pixmap)
295 m_thumbnail = pixmap;
298 const QPixmap & DocClipBase::thumbnail() const
303 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
305 //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
306 m_audioFrameCache = data;
307 m_audioThumbCreated = true;
311 QList < GenTime > DocClipBase::snapMarkers() const
313 QList < GenTime > markers;
315 for (int count = 0; count < m_snapMarkers.count(); ++count) {
316 markers.append(m_snapMarkers.at(count).time());
322 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
324 return m_snapMarkers;
328 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
330 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
331 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
332 if ((*it).time() >= time)
336 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
337 (*it).setComment(comment);
338 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
340 CommentedTime t(time, comment);
341 m_snapMarkers.insert(it, t);
346 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
348 QList < CommentedTime >::Iterator it;
349 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
350 if ((*it).time() == time)
353 if (it != m_snapMarkers.end()) {
354 (*it).setComment(comment);
356 kError() << "trying to edit Snap Marker that does not already exists";
360 QString DocClipBase::deleteSnapMarker(const GenTime & time)
362 QString result = i18n("Marker");
363 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
365 while (itt != m_snapMarkers.end()) {
366 if ((*itt).time() == time)
371 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
372 result = (*itt).comment();
373 m_snapMarkers.erase(itt);
379 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
381 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
383 while (itt != m_snapMarkers.end()) {
384 if ((*itt).time() == time)
392 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
395 for (it = 0; it < m_snapMarkers.count(); it++) {
396 if (m_snapMarkers.at(it).time() >= currTime)
399 if (it == 0) return GenTime();
400 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
401 return m_snapMarkers.at(it).time();
402 else return m_snapMarkers.at(it - 1).time();
405 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
408 for (it = 0; it < m_snapMarkers.count(); it++) {
409 if (m_snapMarkers.at(it).time() > currTime)
412 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
416 QString DocClipBase::markerComment(GenTime t)
418 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
420 while (itt != m_snapMarkers.end()) {
421 if ((*itt).time() == t)
422 return (*itt).comment();
428 void DocClipBase::clearProducers()
430 m_baseTrackProducers.clear();
433 void DocClipBase::deleteProducers(bool clearThumbCreator)
435 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
436 if (clearThumbCreator && m_thumbProd) m_thumbProd->clearProducer();
437 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
438 int max = m_baseTrackProducers.count();
439 for (int i = 0; i < max; i++) {
440 kDebug()<<"// CLIP KILL PROD "<<i;
441 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
446 m_baseTrackProducers.insert(i, NULL);
449 delete m_videoOnlyProducer;
450 m_videoOnlyProducer = NULL;
452 qDeleteAll(m_baseTrackProducers);
453 m_baseTrackProducers.clear();
454 qDeleteAll(m_audioTrackProducers);
455 m_audioTrackProducers.clear();
458 void DocClipBase::setValid()
460 m_placeHolder = false;
463 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
465 if (producer == NULL || (m_placeHolder && !reset)) return;
466 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
468 // Clear all previous producers
469 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
470 deleteProducers(false);
472 QString id = producer->get("id");
473 if (id.contains('_')) {
474 // this is a subtrack producer, insert it at correct place
475 id = id.section('_', 1);
476 if (id.endsWith("audio")) {
477 int pos = id.section('_', 0, 0).toInt();
478 if (pos >= m_audioTrackProducers.count()) {
479 while (m_audioTrackProducers.count() - 1 < pos) {
480 m_audioTrackProducers.append(NULL);
483 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
485 } else if (id.endsWith("video")) {
486 m_videoOnlyProducer = producer;
489 int pos = id.toInt();
490 if (pos >= m_baseTrackProducers.count()) {
491 while (m_baseTrackProducers.count() - 1 < pos) {
492 m_baseTrackProducers.append(NULL);
495 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
497 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
498 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
500 //m_clipProducer = producer;
501 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
504 Mlt::Producer *DocClipBase::audioProducer(int track)
506 if (m_audioTrackProducers.count() <= track) {
507 while (m_audioTrackProducers.count() - 1 < track) {
508 m_audioTrackProducers.append(NULL);
511 if (m_audioTrackProducers.at(track) == NULL) {
512 Mlt::Producer *base = producer();
513 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
514 if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
515 if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
516 if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
517 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
518 m_audioTrackProducers.at(track)->set("video_index", -1);
519 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
520 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
521 m_audioTrackProducers.at(track)->set("id", tmp);
524 return m_audioTrackProducers.at(track);
527 Mlt::Producer *DocClipBase::videoProducer()
529 if (m_videoOnlyProducer == NULL) {
531 for (i = 0; i < m_baseTrackProducers.count(); i++)
532 if (m_baseTrackProducers.at(i) != NULL) break;
533 if (i >= m_baseTrackProducers.count()) return NULL;
534 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
535 if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
536 if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
537 if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
538 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
539 m_videoOnlyProducer->set("audio_index", -1);
540 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
541 char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
542 m_videoOnlyProducer->set("id", tmp);
545 return m_videoOnlyProducer;
548 Mlt::Producer *DocClipBase::producer(int track)
550 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
551 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
553 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
554 if (m_baseTrackProducers.count() == 0) return NULL;
555 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
556 if (m_baseTrackProducers.at(i) != NULL)
557 return m_baseTrackProducers.at(i);
561 if (track >= m_baseTrackProducers.count()) {
562 while (m_baseTrackProducers.count() - 1 < track) {
563 m_baseTrackProducers.append(NULL);
566 if (m_baseTrackProducers.at(track) == NULL) {
568 for (i = 0; i < m_baseTrackProducers.count(); i++)
569 if (m_baseTrackProducers.at(i) != NULL) break;
571 if (i >= m_baseTrackProducers.count()) return NULL;
573 if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
574 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
575 else { // special case for placeholder clips
576 m_baseTrackProducers[track] = NULL;
580 if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
581 if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
582 if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
583 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
584 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
585 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
586 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
587 m_baseTrackProducers[track]->set("id", tmp);
589 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
590 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
591 m_baseTrackProducers[track]->set("skip_frame", "bidir");
594 return m_baseTrackProducers.at(track);
597 void DocClipBase::setProducerProperty(const char *name, int data)
599 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
600 if (m_baseTrackProducers.at(i) != NULL)
601 m_baseTrackProducers[i]->set(name, data);
605 void DocClipBase::setProducerProperty(const char *name, double data)
607 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
608 if (m_baseTrackProducers.at(i) != NULL)
609 m_baseTrackProducers[i]->set(name, data);
613 void DocClipBase::setProducerProperty(const char *name, const char *data)
615 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
616 if (m_baseTrackProducers.at(i) != NULL)
617 m_baseTrackProducers[i]->set(name, data);
621 void DocClipBase::resetProducerProperty(const char *name)
623 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
624 if (m_baseTrackProducers.at(i) != NULL)
625 m_baseTrackProducers[i]->set(name, (const char*) NULL);
629 const char *DocClipBase::producerProperty(const char *name) const
631 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
632 if (m_baseTrackProducers.at(i) != NULL) {
633 return m_baseTrackProducers.at(i)->get(name);
640 void DocClipBase::slotRefreshProducer()
642 if (m_baseTrackProducers.count() == 0) return;
643 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
644 if (m_clipType == SLIDESHOW) {
645 /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
646 Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
648 delete m_clipProducer;
649 m_clipProducer = new Mlt::Producer(producer.get_producer());
650 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
651 setProducerProperty("ttl", getProperty("ttl").toInt());
652 //m_clipProducer->set("id", getProperty("id"));
653 if (getProperty("fade") == "1") {
654 // we want a fade filter effect
655 kDebug() << "//////////// FADE WANTED";
656 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
658 Mlt::Filter *filter = clipService.filter(ct);
660 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
664 filter = clipService.filter(ct);
667 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
668 filter->set("period", getProperty("ttl").toInt() - 1);
669 filter->set("luma.out", getProperty("luma_duration").toInt());
670 QString resource = getProperty("luma_file");
671 char *tmp = (char *) qstrdup(resource.toUtf8().data());
672 filter->set("luma.resource", tmp);
674 if (!getProperty("softness").isEmpty()) {
675 int soft = getProperty("softness").toInt();
676 filter->set("luma.softness", (double) soft / 100.0);
679 // filter does not exist, create it...
680 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
681 filter->set("period", getProperty("ttl").toInt() - 1);
682 filter->set("luma.out", getProperty("luma_duration").toInt());
683 QString resource = getProperty("luma_file");
684 char *tmp = (char *) qstrdup(resource.toUtf8().data());
685 filter->set("luma.resource", tmp);
687 if (!getProperty("softness").isEmpty()) {
688 int soft = getProperty("softness").toInt();
689 filter->set("luma.softness", (double) soft / 100.0);
691 clipService.attach(*filter);
694 kDebug() << "//////////// FADE NOT WANTED!!!";
695 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
697 Mlt::Filter *filter = clipService.filter(0);
699 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
700 clipService.detach(*filter);
702 filter = clipService.filter(ct);
708 void DocClipBase::setProperties(QMap <QString, QString> properties)
710 // changing clip type is not allowed
711 properties.remove("type");
712 QMapIterator<QString, QString> i(properties);
713 bool refreshProducer = false;
715 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
716 while (i.hasNext()) {
718 setProperty(i.key(), i.value());
719 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
721 if (refreshProducer) slotRefreshProducer();
724 void DocClipBase::setMetadata(QMap <QString, QString> properties)
726 QMapIterator<QString, QString> i(properties);
727 while (i.hasNext()) {
729 m_metadata.insert(i.key(), i.value());
733 QMap <QString, QString> DocClipBase::metadata() const
738 void DocClipBase::clearProperty(const QString &key)
740 m_properties.remove(key);
743 void DocClipBase::getFileHash(const QString url)
745 if (m_clipType == SLIDESHOW) return;
747 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
750 //kDebug() << "SETTING HASH of" << value;
751 m_properties.insert("file_size", QString::number(file.size()));
753 * 1 MB = 1 second per 450 files (or faster)
754 * 10 MB = 9 seconds per 450 files (or faster)
756 if (file.size() > 1000000*2) {
757 fileData = file.read(1000000);
758 if (file.seek(file.size() - 1000000))
759 fileData.append(file.readAll());
761 fileData = file.readAll();
763 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
764 m_properties.insert("file_hash", QString(fileHash.toHex()));
768 bool DocClipBase::checkHash() const
770 KUrl url = fileURL();
771 if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
775 QString DocClipBase::getClipHash() const
778 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
779 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
780 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
781 else hash = m_properties.value("file_hash");
785 void DocClipBase::setPlaceHolder(bool place)
787 m_placeHolder = place;
791 QString DocClipBase::getHash(const QString &path)
794 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
798 * 1 MB = 1 second per 450 files (or faster)
799 * 10 MB = 9 seconds per 450 files (or faster)
801 if (file.size() > 1000000*2) {
802 fileData = file.read(1000000);
803 if (file.seek(file.size() - 1000000))
804 fileData.append(file.readAll());
806 fileData = file.readAll();
808 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
813 void DocClipBase::refreshThumbUrl()
815 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
818 void DocClipBase::setProperty(const QString &key, const QString &value)
820 m_properties.insert(key, value);
821 if (key == "resource") {
823 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
824 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
825 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
826 else if (key == "colour") {
827 char *tmp = (char *) qstrdup(value.toUtf8().data());
828 setProducerProperty("colour", tmp);
830 } else if (key == "templatetext") {
831 char *tmp = (char *) qstrdup(value.toUtf8().data());
832 setProducerProperty("templatetext", tmp);
834 setProducerProperty("force_reload", 1);
835 } else if (key == "xmldata") {
836 char *tmp = (char *) qstrdup(value.toUtf8().data());
837 setProducerProperty("xmldata", tmp);
839 setProducerProperty("force_reload", 1);
840 } else if (key == "force_aspect_ratio") {
841 if (value.isEmpty()) {
842 m_properties.remove("force_aspect_ratio");
843 resetProducerProperty("force_aspect_ratio");
844 } else setProducerProperty("force_aspect_ratio", value.toDouble());
845 } else if (key == "force_fps") {
846 if (value.isEmpty()) {
847 m_properties.remove("force_fps");
848 resetProducerProperty("force_fps");
849 } else setProducerProperty("force_fps", value.toDouble());
850 } else if (key == "force_progressive") {
851 if (value.isEmpty()) {
852 m_properties.remove("force_progressive");
853 resetProducerProperty("force_progressive");
854 } else setProducerProperty("force_progressive", value.toInt());
855 } else if (key == "threads") {
856 if (value.isEmpty()) {
857 m_properties.remove("threads");
858 setProducerProperty("threads", 1);
859 } else setProducerProperty("threads", value.toInt());
860 } else if (key == "video_index") {
861 if (value.isEmpty()) {
862 m_properties.remove("video_index");
863 setProducerProperty("video_index", m_properties.value("default_video").toInt());
864 } else setProducerProperty("video_index", value.toInt());
865 } else if (key == "audio_index") {
866 if (value.isEmpty()) {
867 m_properties.remove("audio_index");
868 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
869 } else setProducerProperty("audio_index", value.toInt());
873 QMap <QString, QString> DocClipBase::properties() const
878 bool DocClipBase::slotGetAudioThumbs()
880 if (m_thumbProd == NULL) return false;
881 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
882 if (m_audioTimer != NULL) m_audioTimer->stop();
885 if (m_audioThumbCreated) {
886 m_audioTimer->stop();
889 m_audioTimer->start(1500);
890 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
891 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
895 bool DocClipBase::isPlaceHolder() const
897 return m_placeHolder;
900 void DocClipBase::addCutZone(int in, int out, QString desc)
903 info.zone = QPoint(in, out);
904 info.description = desc;
905 for (int i = 0; i < m_cutZones.count(); i++)
906 if (m_cutZones.at(i).zone == info.zone) {
909 m_cutZones.append(info);
912 bool DocClipBase::hasCutZone(QPoint p) const
914 for (int i = 0; i < m_cutZones.count(); i++)
915 if (m_cutZones.at(i).zone == p) return true;
920 void DocClipBase::removeCutZone(int in, int out)
923 for (int i = 0; i < m_cutZones.count(); i++) {
924 if (m_cutZones.at(i).zone == p) {
925 m_cutZones.removeAt(i);
931 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
933 QPoint old(oldin, oldout);
934 for (int i = 0; i < m_cutZones.size(); ++i) {
935 if (m_cutZones.at(i).zone == old) {
937 info.zone = QPoint(in, out);
938 info.description = desc;
939 m_cutZones.replace(i, info);
945 QList <CutZoneInfo> DocClipBase::cutZones() const
950 bool DocClipBase::hasVideoCodec(const QString &codec) const
952 Mlt::Producer *prod = NULL;
953 if (m_baseTrackProducers.count() == 0) return false;
954 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
955 if (m_baseTrackProducers.at(i) != NULL) {
956 prod = m_baseTrackProducers.at(i);
961 if (!prod) return false;
962 int default_video = prod->get_int("video_index");
964 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
965 return prod->get(property) == codec;
968 bool DocClipBase::hasAudioCodec(const QString &codec) const
970 Mlt::Producer *prod = NULL;
971 if (m_baseTrackProducers.count() == 0) return false;
972 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
973 if (m_baseTrackProducers.at(i) != NULL) {
974 prod = m_baseTrackProducers.at(i);
978 if (!prod) return false;
979 int default_video = prod->get_int("audio_index");
981 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
982 return prod->get(property) == codec;