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 m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
63 if (xml.hasAttribute("cutzones")) {
64 QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
65 for (int i = 0; i < cuts.count(); i++) {
66 QString z = cuts.at(i);
67 addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
71 KUrl url = KUrl(xml.attribute("resource"));
72 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
74 if (xml.hasAttribute("duration")) {
75 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
77 int out = xml.attribute("out").toInt();
78 int in = xml.attribute("in").toInt();
79 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
82 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
84 //if (!url.isEmpty() && QFile::exists(url.path()))
86 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
87 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer();
89 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
92 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
93 DocClipBase::operator=(clip);
95 m_clipType = clip.clipType();
97 m_duration = clip.duration();
98 m_audioThumbCreated = clip.audioThumbCreated();
99 m_properties = clip.properties();
103 DocClipBase::~DocClipBase()
105 kDebug() << "CLIP " << m_id << " DELETED******************************";
108 m_audioTimer->stop();
111 /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
112 if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
113 qDeleteAll(m_baseTrackProducers);
114 m_baseTrackProducers.clear();
115 qDeleteAll(m_audioTrackProducers);
116 m_audioTrackProducers.clear();
117 delete m_videoOnlyProducer;
118 m_videoOnlyProducer = NULL;
121 void DocClipBase::setZone(QPoint zone)
123 m_properties.insert("zone_in", QString::number(zone.x()));
124 m_properties.insert("zone_out", QString::number(zone.y()));
127 QPoint DocClipBase::zone() const
129 QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
133 void DocClipBase::slotCreateAudioTimer()
135 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
136 m_audioTimer = new QTimer(this);
137 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
140 void DocClipBase::askForAudioThumbs()
142 if (m_thumbProd && m_audioTimer) m_thumbProd->askForAudioThumbs(getId());
145 void DocClipBase::slotClearAudioCache()
147 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
148 if (m_audioTimer != NULL) m_audioTimer->stop();
149 m_audioFrameCache.clear();
150 m_audioThumbCreated = false;
153 /*void DocClipBase::getClipMainThumb() {
154 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
157 KThumb *DocClipBase::thumbProducer()
162 bool DocClipBase::audioThumbCreated() const
164 return m_audioThumbCreated;
167 const QString DocClipBase::name() const
170 return m_properties.value("name");
173 const QString &DocClipBase::getId() const
178 void DocClipBase::setId(const QString &newId)
183 const CLIPTYPE & DocClipBase::clipType() const
188 void DocClipBase::setClipType(CLIPTYPE type)
192 m_properties.insert("type", QString::number((int) type));
193 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST))
194 slotCreateAudioTimer();
197 KUrl DocClipBase::fileURL() const
199 QString res = m_properties.value("resource");
200 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
204 void DocClipBase::setClipThumbFrame(const uint &ix)
206 m_properties.insert("thumbnail", QString::number((int) ix));
209 uint DocClipBase::getClipThumbFrame() const
211 return (uint) m_properties.value("thumbnail").toInt();
214 const QString DocClipBase::description() const
216 return m_properties.value("description");
219 bool DocClipBase::isTransparent() const
221 return (m_properties.value("transparency") == "1");
224 const QString DocClipBase::getProperty(const QString prop) const
226 return m_properties.value(prop);
229 void DocClipBase::setDuration(GenTime dur)
232 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
235 const GenTime &DocClipBase::duration() const
240 const GenTime DocClipBase::maxDuration() const
242 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
243 /*const GenTime dur(15000, KdenliveSettings::project_fps());
250 bool DocClipBase::hasFileSize() const
255 qulonglong DocClipBase::fileSize() const
257 return m_properties.value("file_size").toULongLong();
261 QDomElement DocClipBase::toXML() const
264 QDomElement clip = doc.createElement("producer");
266 QMapIterator<QString, QString> i(m_properties);
267 while (i.hasNext()) {
269 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
271 doc.appendChild(clip);
272 if (!m_cutZones.isEmpty()) {
274 for (int i = 0; i < m_cutZones.size(); i++) {
275 CutZoneInfo info = m_cutZones.at(i);
276 cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
278 clip.setAttribute("cutzones", cuts.join(";"));
280 //kDebug() << "/// CLIP XML: " << doc.toString();
281 return doc.documentElement();
285 void DocClipBase::setAudioThumbCreated(bool isDone)
287 m_audioThumbCreated = isDone;
291 void DocClipBase::setThumbnail(const QPixmap & pixmap)
293 m_thumbnail = pixmap;
296 const QPixmap & DocClipBase::thumbnail() const
301 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
303 //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
304 m_audioFrameCache = data;
305 m_audioThumbCreated = true;
309 QList < GenTime > DocClipBase::snapMarkers() const
311 QList < GenTime > markers;
313 for (int count = 0; count < m_snapMarkers.count(); ++count) {
314 markers.append(m_snapMarkers.at(count).time());
320 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
322 return m_snapMarkers;
326 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
328 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
329 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
330 if ((*it).time() >= time)
334 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
335 (*it).setComment(comment);
336 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
338 CommentedTime t(time, comment);
339 m_snapMarkers.insert(it, t);
344 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
346 QList < CommentedTime >::Iterator it;
347 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
348 if ((*it).time() == time)
351 if (it != m_snapMarkers.end()) {
352 (*it).setComment(comment);
354 kError() << "trying to edit Snap Marker that does not already exists";
358 QString DocClipBase::deleteSnapMarker(const GenTime & time)
360 QString result = i18n("Marker");
361 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
363 while (itt != m_snapMarkers.end()) {
364 if ((*itt).time() == time)
369 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
370 result = (*itt).comment();
371 m_snapMarkers.erase(itt);
377 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
379 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
381 while (itt != m_snapMarkers.end()) {
382 if ((*itt).time() == time)
390 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
393 for (it = 0; it < m_snapMarkers.count(); it++) {
394 if (m_snapMarkers.at(it).time() >= currTime)
397 if (it == 0) return GenTime();
398 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
399 return m_snapMarkers.at(it).time();
400 else return m_snapMarkers.at(it - 1).time();
403 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
406 for (it = 0; it < m_snapMarkers.count(); it++) {
407 if (m_snapMarkers.at(it).time() > currTime)
410 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
414 QString DocClipBase::markerComment(GenTime t)
416 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
418 while (itt != m_snapMarkers.end()) {
419 if ((*itt).time() == t)
420 return (*itt).comment();
426 void DocClipBase::clearProducers()
428 m_baseTrackProducers.clear();
431 void DocClipBase::deleteProducers(bool clearThumbCreator)
433 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
434 if (clearThumbCreator && m_thumbProd) m_thumbProd->clearProducer();
435 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
436 int max = m_baseTrackProducers.count();
437 for (int i = 0; i < max; i++) {
438 kDebug()<<"// CLIP KILL PROD "<<i;
439 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
444 m_baseTrackProducers.insert(i, NULL);
447 delete m_videoOnlyProducer;
448 m_videoOnlyProducer = NULL;
450 qDeleteAll(m_baseTrackProducers);
451 m_baseTrackProducers.clear();
452 qDeleteAll(m_audioTrackProducers);
453 m_audioTrackProducers.clear();
456 void DocClipBase::setValid()
458 m_placeHolder = false;
461 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
463 if (producer == NULL || (m_placeHolder && !reset)) return;
464 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
466 // Clear all previous producers
467 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
468 deleteProducers(false);
470 QString id = producer->get("id");
471 if (id.contains('_')) {
472 // this is a subtrack producer, insert it at correct place
473 id = id.section('_', 1);
474 if (id.endsWith("audio")) {
475 int pos = id.section('_', 0, 0).toInt();
476 if (pos >= m_audioTrackProducers.count()) {
477 while (m_audioTrackProducers.count() - 1 < pos) {
478 m_audioTrackProducers.append(NULL);
481 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
483 } else if (id.endsWith("video")) {
484 m_videoOnlyProducer = producer;
487 int pos = id.toInt();
488 if (pos >= m_baseTrackProducers.count()) {
489 while (m_baseTrackProducers.count() - 1 < pos) {
490 m_baseTrackProducers.append(NULL);
493 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
495 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
496 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
498 //m_clipProducer = producer;
499 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
502 Mlt::Producer *DocClipBase::audioProducer(int track)
504 if (m_audioTrackProducers.count() <= track) {
505 while (m_audioTrackProducers.count() - 1 < track) {
506 m_audioTrackProducers.append(NULL);
509 if (m_audioTrackProducers.at(track) == NULL) {
510 Mlt::Producer *base = producer();
511 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
512 if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
513 if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
514 if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
515 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
516 m_audioTrackProducers.at(track)->set("video_index", -1);
517 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
518 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
519 m_audioTrackProducers.at(track)->set("id", tmp);
522 return m_audioTrackProducers.at(track);
525 Mlt::Producer *DocClipBase::videoProducer()
527 if (m_videoOnlyProducer == NULL) {
529 for (i = 0; i < m_baseTrackProducers.count(); i++)
530 if (m_baseTrackProducers.at(i) != NULL) break;
531 if (i >= m_baseTrackProducers.count()) return NULL;
532 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
533 if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
534 if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
535 if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
536 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
537 m_videoOnlyProducer->set("audio_index", -1);
538 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
539 char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
540 m_videoOnlyProducer->set("id", tmp);
543 return m_videoOnlyProducer;
546 Mlt::Producer *DocClipBase::producer(int track)
548 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
549 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
551 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
552 if (m_baseTrackProducers.count() == 0) return NULL;
553 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
554 if (m_baseTrackProducers.at(i) != NULL)
555 return m_baseTrackProducers.at(i);
559 if (track >= m_baseTrackProducers.count()) {
560 while (m_baseTrackProducers.count() - 1 < track) {
561 m_baseTrackProducers.append(NULL);
564 if (m_baseTrackProducers.at(track) == NULL) {
566 for (i = 0; i < m_baseTrackProducers.count(); i++)
567 if (m_baseTrackProducers.at(i) != NULL) break;
569 if (i >= m_baseTrackProducers.count()) return NULL;
571 if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
572 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
573 else { // special case for placeholder clips
574 m_baseTrackProducers[track] = NULL;
578 if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
579 if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
580 if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
581 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
582 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
583 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
584 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
585 m_baseTrackProducers[track]->set("id", tmp);
587 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
588 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
589 m_baseTrackProducers[track]->set("skip_frame", "bidir");
592 return m_baseTrackProducers.at(track);
595 void DocClipBase::setProducerProperty(const char *name, int data)
597 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
598 if (m_baseTrackProducers.at(i) != NULL)
599 m_baseTrackProducers[i]->set(name, data);
603 void DocClipBase::setProducerProperty(const char *name, double data)
605 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
606 if (m_baseTrackProducers.at(i) != NULL)
607 m_baseTrackProducers[i]->set(name, data);
611 void DocClipBase::setProducerProperty(const char *name, const char *data)
613 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
614 if (m_baseTrackProducers.at(i) != NULL)
615 m_baseTrackProducers[i]->set(name, data);
619 void DocClipBase::resetProducerProperty(const char *name)
621 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
622 if (m_baseTrackProducers.at(i) != NULL)
623 m_baseTrackProducers[i]->set(name, (const char*) NULL);
627 const char *DocClipBase::producerProperty(const char *name) const
629 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
630 if (m_baseTrackProducers.at(i) != NULL) {
631 return m_baseTrackProducers.at(i)->get(name);
638 void DocClipBase::slotRefreshProducer()
640 if (m_baseTrackProducers.count() == 0) return;
641 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
642 if (m_clipType == SLIDESHOW) {
643 /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
644 Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
646 delete m_clipProducer;
647 m_clipProducer = new Mlt::Producer(producer.get_producer());
648 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
649 setProducerProperty("ttl", getProperty("ttl").toInt());
650 //m_clipProducer->set("id", getProperty("id"));
651 if (getProperty("fade") == "1") {
652 // we want a fade filter effect
653 kDebug() << "//////////// FADE WANTED";
654 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
656 Mlt::Filter *filter = clipService.filter(ct);
658 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
662 filter = clipService.filter(ct);
665 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
666 filter->set("period", getProperty("ttl").toInt() - 1);
667 filter->set("luma.out", getProperty("luma_duration").toInt());
668 QString resource = getProperty("luma_file");
669 char *tmp = (char *) qstrdup(resource.toUtf8().data());
670 filter->set("luma.resource", tmp);
672 if (!getProperty("softness").isEmpty()) {
673 int soft = getProperty("softness").toInt();
674 filter->set("luma.softness", (double) soft / 100.0);
677 // filter does not exist, create it...
678 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
679 filter->set("period", getProperty("ttl").toInt() - 1);
680 filter->set("luma.out", getProperty("luma_duration").toInt());
681 QString resource = getProperty("luma_file");
682 char *tmp = (char *) qstrdup(resource.toUtf8().data());
683 filter->set("luma.resource", tmp);
685 if (!getProperty("softness").isEmpty()) {
686 int soft = getProperty("softness").toInt();
687 filter->set("luma.softness", (double) soft / 100.0);
689 clipService.attach(*filter);
692 kDebug() << "//////////// FADE NOT WANTED!!!";
693 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
695 Mlt::Filter *filter = clipService.filter(0);
697 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
698 clipService.detach(*filter);
700 filter = clipService.filter(ct);
706 void DocClipBase::setProperties(QMap <QString, QString> properties)
708 // changing clip type is not allowed
709 properties.remove("type");
710 QMapIterator<QString, QString> i(properties);
711 bool refreshProducer = false;
713 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
714 while (i.hasNext()) {
716 setProperty(i.key(), i.value());
717 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
719 if (refreshProducer) slotRefreshProducer();
722 void DocClipBase::setMetadata(QMap <QString, QString> properties)
724 m_metadata = properties;
727 QMap <QString, QString> DocClipBase::metadata() const
732 void DocClipBase::clearProperty(const QString &key)
734 m_properties.remove(key);
737 void DocClipBase::getFileHash(const QString url)
739 if (m_clipType == SLIDESHOW) return;
741 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
744 //kDebug() << "SETTING HASH of" << value;
745 m_properties.insert("file_size", QString::number(file.size()));
747 * 1 MB = 1 second per 450 files (or faster)
748 * 10 MB = 9 seconds per 450 files (or faster)
750 if (file.size() > 1000000*2) {
751 fileData = file.read(1000000);
752 if (file.seek(file.size() - 1000000))
753 fileData.append(file.readAll());
755 fileData = file.readAll();
757 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
758 m_properties.insert("file_hash", QString(fileHash.toHex()));
762 bool DocClipBase::checkHash() const
764 KUrl url = fileURL();
765 if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
769 QString DocClipBase::getClipHash() const
772 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
773 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
774 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
775 else hash = m_properties.value("file_hash");
779 void DocClipBase::setPlaceHolder(bool place)
781 m_placeHolder = place;
785 QString DocClipBase::getHash(const QString &path)
788 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
792 * 1 MB = 1 second per 450 files (or faster)
793 * 10 MB = 9 seconds per 450 files (or faster)
795 if (file.size() > 1000000*2) {
796 fileData = file.read(1000000);
797 if (file.seek(file.size() - 1000000))
798 fileData.append(file.readAll());
800 fileData = file.readAll();
802 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
807 void DocClipBase::refreshThumbUrl()
809 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
812 void DocClipBase::setProperty(const QString &key, const QString &value)
814 m_properties.insert(key, value);
815 if (key == "resource") {
817 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
818 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
819 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
820 else if (key == "colour") {
821 char *tmp = (char *) qstrdup(value.toUtf8().data());
822 setProducerProperty("colour", tmp);
824 } else if (key == "templatetext") {
825 char *tmp = (char *) qstrdup(value.toUtf8().data());
826 setProducerProperty("templatetext", tmp);
828 setProducerProperty("force_reload", 1);
829 } else if (key == "xmldata") {
830 char *tmp = (char *) qstrdup(value.toUtf8().data());
831 setProducerProperty("xmldata", tmp);
833 setProducerProperty("force_reload", 1);
834 } else if (key == "force_aspect_ratio") {
835 if (value.isEmpty()) {
836 m_properties.remove("force_aspect_ratio");
837 resetProducerProperty("force_aspect_ratio");
838 } else setProducerProperty("force_aspect_ratio", value.toDouble());
839 } else if (key == "force_fps") {
840 if (value.isEmpty()) {
841 m_properties.remove("force_fps");
842 resetProducerProperty("force_fps");
843 } else setProducerProperty("force_fps", value.toDouble());
844 } else if (key == "force_progressive") {
845 if (value.isEmpty()) {
846 m_properties.remove("force_progressive");
847 resetProducerProperty("force_progressive");
848 } else setProducerProperty("force_progressive", value.toInt());
849 } else if (key == "threads") {
850 if (value.isEmpty()) {
851 m_properties.remove("threads");
852 setProducerProperty("threads", 1);
853 } else setProducerProperty("threads", value.toInt());
854 } else if (key == "video_index") {
855 if (value.isEmpty()) {
856 m_properties.remove("video_index");
857 setProducerProperty("video_index", m_properties.value("default_video").toInt());
858 } else setProducerProperty("video_index", value.toInt());
859 } else if (key == "audio_index") {
860 if (value.isEmpty()) {
861 m_properties.remove("audio_index");
862 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
863 } else setProducerProperty("audio_index", value.toInt());
867 QMap <QString, QString> DocClipBase::properties() const
872 bool DocClipBase::slotGetAudioThumbs()
874 if (m_thumbProd == NULL) return false;
875 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
876 if (m_audioTimer != NULL) m_audioTimer->stop();
879 if (m_audioThumbCreated) {
880 m_audioTimer->stop();
883 m_audioTimer->start(1500);
884 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
885 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
889 bool DocClipBase::isPlaceHolder() const
891 return m_placeHolder;
894 void DocClipBase::addCutZone(int in, int out, QString desc)
897 info.zone = QPoint(in, out);
898 info.description = desc;
899 for (int i = 0; i < m_cutZones.count(); i++)
900 if (m_cutZones.at(i).zone == info.zone) {
903 m_cutZones.append(info);
906 bool DocClipBase::hasCutZone(QPoint p) const
908 for (int i = 0; i < m_cutZones.count(); i++)
909 if (m_cutZones.at(i).zone == p) return true;
914 void DocClipBase::removeCutZone(int in, int out)
917 for (int i = 0; i < m_cutZones.count(); i++) {
918 if (m_cutZones.at(i).zone == p) {
919 m_cutZones.removeAt(i);
925 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
927 QPoint old(oldin, oldout);
928 for (int i = 0; i < m_cutZones.size(); ++i) {
929 if (m_cutZones.at(i).zone == old) {
931 info.zone = QPoint(in, out);
932 info.description = desc;
933 m_cutZones.replace(i, info);
939 QList <CutZoneInfo> DocClipBase::cutZones() const
944 bool DocClipBase::hasVideoCodec(const QString &codec) const
946 Mlt::Producer *prod = NULL;
947 if (m_baseTrackProducers.count() == 0) return false;
948 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
949 if (m_baseTrackProducers.at(i) != NULL) {
950 prod = m_baseTrackProducers.at(i);
955 if (!prod) return false;
956 int default_video = prod->get_int("video_index");
958 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
959 return prod->get(property) == codec;
962 bool DocClipBase::hasAudioCodec(const QString &codec) const
964 Mlt::Producer *prod = NULL;
965 if (m_baseTrackProducers.count() == 0) return false;
966 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
967 if (m_baseTrackProducers.at(i) != NULL) {
968 prod = m_baseTrackProducers.at(i);
972 if (!prod) return false;
973 int default_video = prod->get_int("audio_index");
975 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
976 return prod->get(property) == codec;