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.")) {
62 m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
63 } else m_properties.insert(name, attributes.item(i).nodeValue());
66 if (xml.hasAttribute("cutzones")) {
67 QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
68 for (int i = 0; i < cuts.count(); i++) {
69 QString z = cuts.at(i);
70 addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
74 KUrl url = KUrl(xml.attribute("resource"));
75 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
77 if (xml.hasAttribute("duration")) {
78 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
80 int out = xml.attribute("out").toInt();
81 int in = xml.attribute("in").toInt();
82 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
85 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
87 //if (!url.isEmpty() && QFile::exists(url.path()))
89 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
90 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer();
92 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
95 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
96 DocClipBase::operator=(clip);
98 m_clipType = clip.clipType();
100 m_duration = clip.duration();
101 m_audioThumbCreated = clip.audioThumbCreated();
102 m_properties = clip.properties();
106 DocClipBase::~DocClipBase()
108 kDebug() << "CLIP " << m_id << " DELETED******************************";
111 m_audioTimer->stop();
114 /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
115 if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
116 qDeleteAll(m_baseTrackProducers);
117 m_baseTrackProducers.clear();
118 qDeleteAll(m_audioTrackProducers);
119 m_audioTrackProducers.clear();
120 delete m_videoOnlyProducer;
121 m_videoOnlyProducer = NULL;
124 void DocClipBase::setZone(QPoint zone)
126 m_properties.insert("zone_in", QString::number(zone.x()));
127 m_properties.insert("zone_out", QString::number(zone.y()));
130 QPoint DocClipBase::zone() const
132 QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
136 void DocClipBase::slotCreateAudioTimer()
138 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
139 m_audioTimer = new QTimer(this);
140 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
143 void DocClipBase::askForAudioThumbs()
145 if (m_thumbProd && m_audioTimer) m_thumbProd->askForAudioThumbs(getId());
148 void DocClipBase::slotClearAudioCache()
150 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
151 if (m_audioTimer != NULL) m_audioTimer->stop();
152 m_audioFrameCache.clear();
153 m_audioThumbCreated = false;
156 /*void DocClipBase::getClipMainThumb() {
157 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
160 KThumb *DocClipBase::thumbProducer()
165 bool DocClipBase::audioThumbCreated() const
167 return m_audioThumbCreated;
170 const QString DocClipBase::name() const
173 return m_properties.value("name");
176 const QString &DocClipBase::getId() const
181 void DocClipBase::setId(const QString &newId)
186 const CLIPTYPE & DocClipBase::clipType() const
191 void DocClipBase::setClipType(CLIPTYPE type)
195 m_properties.insert("type", QString::number((int) type));
196 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST))
197 slotCreateAudioTimer();
200 KUrl DocClipBase::fileURL() const
202 QString res = m_properties.value("resource");
203 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
207 void DocClipBase::setClipThumbFrame(const uint &ix)
209 m_properties.insert("thumbnail", QString::number((int) ix));
212 uint DocClipBase::getClipThumbFrame() const
214 return (uint) m_properties.value("thumbnail").toInt();
217 const QString DocClipBase::description() const
219 return m_properties.value("description");
222 bool DocClipBase::isTransparent() const
224 return (m_properties.value("transparency") == "1");
227 const QString DocClipBase::getProperty(const QString prop) const
229 return m_properties.value(prop);
232 void DocClipBase::setDuration(GenTime dur)
235 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
238 const GenTime &DocClipBase::duration() const
243 const GenTime DocClipBase::maxDuration() const
245 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
246 /*const GenTime dur(15000, KdenliveSettings::project_fps());
253 bool DocClipBase::hasFileSize() const
258 qulonglong DocClipBase::fileSize() const
260 return m_properties.value("file_size").toULongLong();
264 QDomElement DocClipBase::toXML() const
267 QDomElement clip = doc.createElement("producer");
269 QMapIterator<QString, QString> i(m_properties);
270 while (i.hasNext()) {
272 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
274 doc.appendChild(clip);
275 if (!m_cutZones.isEmpty()) {
277 for (int i = 0; i < m_cutZones.size(); i++) {
278 CutZoneInfo info = m_cutZones.at(i);
279 cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
281 clip.setAttribute("cutzones", cuts.join(";"));
283 //kDebug() << "/// CLIP XML: " << doc.toString();
284 return doc.documentElement();
288 void DocClipBase::setAudioThumbCreated(bool isDone)
290 m_audioThumbCreated = isDone;
294 void DocClipBase::setThumbnail(const QPixmap & pixmap)
296 m_thumbnail = pixmap;
299 const QPixmap & DocClipBase::thumbnail() const
304 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
306 //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
307 m_audioFrameCache = data;
308 m_audioThumbCreated = true;
312 QList < GenTime > DocClipBase::snapMarkers() const
314 QList < GenTime > markers;
316 for (int count = 0; count < m_snapMarkers.count(); ++count) {
317 markers.append(m_snapMarkers.at(count).time());
323 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
325 return m_snapMarkers;
329 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
331 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
332 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
333 if ((*it).time() >= time)
337 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
338 (*it).setComment(comment);
339 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
341 CommentedTime t(time, comment);
342 m_snapMarkers.insert(it, t);
347 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
349 QList < CommentedTime >::Iterator it;
350 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
351 if ((*it).time() == time)
354 if (it != m_snapMarkers.end()) {
355 (*it).setComment(comment);
357 kError() << "trying to edit Snap Marker that does not already exists";
361 QString DocClipBase::deleteSnapMarker(const GenTime & time)
363 QString result = i18n("Marker");
364 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
366 while (itt != m_snapMarkers.end()) {
367 if ((*itt).time() == time)
372 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
373 result = (*itt).comment();
374 m_snapMarkers.erase(itt);
380 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
382 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
384 while (itt != m_snapMarkers.end()) {
385 if ((*itt).time() == time)
393 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
396 for (it = 0; it < m_snapMarkers.count(); it++) {
397 if (m_snapMarkers.at(it).time() >= currTime)
400 if (it == 0) return GenTime();
401 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
402 return m_snapMarkers.at(it).time();
403 else return m_snapMarkers.at(it - 1).time();
406 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
409 for (it = 0; it < m_snapMarkers.count(); it++) {
410 if (m_snapMarkers.at(it).time() > currTime)
413 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
417 QString DocClipBase::markerComment(GenTime t)
419 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
421 while (itt != m_snapMarkers.end()) {
422 if ((*itt).time() == t)
423 return (*itt).comment();
429 void DocClipBase::clearProducers()
431 m_baseTrackProducers.clear();
434 void DocClipBase::deleteProducers(bool clearThumbCreator)
436 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
437 if (clearThumbCreator && m_thumbProd) m_thumbProd->clearProducer();
438 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
439 int max = m_baseTrackProducers.count();
440 for (int i = 0; i < max; i++) {
441 kDebug()<<"// CLIP KILL PROD "<<i;
442 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
447 m_baseTrackProducers.insert(i, NULL);
450 delete m_videoOnlyProducer;
451 m_videoOnlyProducer = NULL;
453 qDeleteAll(m_baseTrackProducers);
454 m_baseTrackProducers.clear();
455 qDeleteAll(m_audioTrackProducers);
456 m_audioTrackProducers.clear();
459 void DocClipBase::setValid()
461 m_placeHolder = false;
464 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
466 if (producer == NULL || (m_placeHolder && !reset)) return;
467 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
469 // Clear all previous producers
470 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
471 deleteProducers(false);
473 QString id = producer->get("id");
474 if (id.contains('_')) {
475 // this is a subtrack producer, insert it at correct place
476 id = id.section('_', 1);
477 if (id.endsWith("audio")) {
478 int pos = id.section('_', 0, 0).toInt();
479 if (pos >= m_audioTrackProducers.count()) {
480 while (m_audioTrackProducers.count() - 1 < pos) {
481 m_audioTrackProducers.append(NULL);
484 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
486 } else if (id.endsWith("video")) {
487 m_videoOnlyProducer = producer;
490 int pos = id.toInt();
491 if (pos >= m_baseTrackProducers.count()) {
492 while (m_baseTrackProducers.count() - 1 < pos) {
493 m_baseTrackProducers.append(NULL);
496 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
498 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
499 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
501 //m_clipProducer = producer;
502 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
505 Mlt::Producer *DocClipBase::audioProducer(int track)
507 if (m_audioTrackProducers.count() <= track) {
508 while (m_audioTrackProducers.count() - 1 < track) {
509 m_audioTrackProducers.append(NULL);
512 if (m_audioTrackProducers.at(track) == NULL) {
513 Mlt::Producer *base = producer();
514 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
515 if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
516 if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
517 if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
518 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
519 m_audioTrackProducers.at(track)->set("video_index", -1);
520 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
521 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
522 m_audioTrackProducers.at(track)->set("id", tmp);
525 return m_audioTrackProducers.at(track);
528 Mlt::Producer *DocClipBase::videoProducer()
530 if (m_videoOnlyProducer == NULL) {
532 for (i = 0; i < m_baseTrackProducers.count(); i++)
533 if (m_baseTrackProducers.at(i) != NULL) break;
534 if (i >= m_baseTrackProducers.count()) return NULL;
535 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
536 if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
537 if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
538 if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
539 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
540 m_videoOnlyProducer->set("audio_index", -1);
541 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
542 char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
543 m_videoOnlyProducer->set("id", tmp);
546 return m_videoOnlyProducer;
549 Mlt::Producer *DocClipBase::producer(int track)
551 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
552 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
554 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
555 if (m_baseTrackProducers.count() == 0) return NULL;
556 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
557 if (m_baseTrackProducers.at(i) != NULL)
558 return m_baseTrackProducers.at(i);
562 if (track >= m_baseTrackProducers.count()) {
563 while (m_baseTrackProducers.count() - 1 < track) {
564 m_baseTrackProducers.append(NULL);
567 if (m_baseTrackProducers.at(track) == NULL) {
569 for (i = 0; i < m_baseTrackProducers.count(); i++)
570 if (m_baseTrackProducers.at(i) != NULL) break;
572 if (i >= m_baseTrackProducers.count()) return NULL;
574 if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
575 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
576 else { // special case for placeholder clips
577 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 if (i.value().isEmpty() && m_metadata.contains(i.key())) {
730 m_metadata.remove(i.key());
732 m_metadata.insert(i.key(), i.value());
737 QMap <QString, QString> DocClipBase::metadata() const
742 void DocClipBase::clearProperty(const QString &key)
744 m_properties.remove(key);
747 void DocClipBase::getFileHash(const QString url)
749 if (m_clipType == SLIDESHOW) return;
751 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
754 //kDebug() << "SETTING HASH of" << value;
755 m_properties.insert("file_size", QString::number(file.size()));
757 * 1 MB = 1 second per 450 files (or faster)
758 * 10 MB = 9 seconds per 450 files (or faster)
760 if (file.size() > 1000000*2) {
761 fileData = file.read(1000000);
762 if (file.seek(file.size() - 1000000))
763 fileData.append(file.readAll());
765 fileData = file.readAll();
767 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
768 m_properties.insert("file_hash", QString(fileHash.toHex()));
772 bool DocClipBase::checkHash() const
774 KUrl url = fileURL();
775 if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
779 QString DocClipBase::getClipHash() const
782 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
783 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
784 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
785 else hash = m_properties.value("file_hash");
789 void DocClipBase::setPlaceHolder(bool place)
791 m_placeHolder = place;
795 QString DocClipBase::getHash(const QString &path)
798 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
802 * 1 MB = 1 second per 450 files (or faster)
803 * 10 MB = 9 seconds per 450 files (or faster)
805 if (file.size() > 1000000*2) {
806 fileData = file.read(1000000);
807 if (file.seek(file.size() - 1000000))
808 fileData.append(file.readAll());
810 fileData = file.readAll();
812 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
817 void DocClipBase::refreshThumbUrl()
819 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
822 void DocClipBase::setProperty(const QString &key, const QString &value)
824 m_properties.insert(key, value);
825 if (key == "resource") {
827 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
828 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
829 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
830 else if (key == "colour") {
831 char *tmp = (char *) qstrdup(value.toUtf8().data());
832 setProducerProperty("colour", tmp);
834 } else if (key == "templatetext") {
835 char *tmp = (char *) qstrdup(value.toUtf8().data());
836 setProducerProperty("templatetext", tmp);
838 setProducerProperty("force_reload", 1);
839 } else if (key == "xmldata") {
840 char *tmp = (char *) qstrdup(value.toUtf8().data());
841 setProducerProperty("xmldata", tmp);
843 setProducerProperty("force_reload", 1);
844 } else if (key == "force_aspect_ratio") {
845 if (value.isEmpty()) {
846 m_properties.remove("force_aspect_ratio");
847 resetProducerProperty("force_aspect_ratio");
848 } else setProducerProperty("force_aspect_ratio", value.toDouble());
849 } else if (key == "force_fps") {
850 if (value.isEmpty()) {
851 m_properties.remove("force_fps");
852 resetProducerProperty("force_fps");
853 } else setProducerProperty("force_fps", value.toDouble());
854 } else if (key == "force_progressive") {
855 if (value.isEmpty()) {
856 m_properties.remove("force_progressive");
857 resetProducerProperty("force_progressive");
858 } else setProducerProperty("force_progressive", value.toInt());
859 } else if (key == "threads") {
860 if (value.isEmpty()) {
861 m_properties.remove("threads");
862 setProducerProperty("threads", 1);
863 } else setProducerProperty("threads", value.toInt());
864 } else if (key == "video_index") {
865 if (value.isEmpty()) {
866 m_properties.remove("video_index");
867 setProducerProperty("video_index", m_properties.value("default_video").toInt());
868 } else setProducerProperty("video_index", value.toInt());
869 } else if (key == "audio_index") {
870 if (value.isEmpty()) {
871 m_properties.remove("audio_index");
872 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
873 } else setProducerProperty("audio_index", value.toInt());
877 QMap <QString, QString> DocClipBase::properties() const
882 bool DocClipBase::slotGetAudioThumbs()
884 if (m_thumbProd == NULL) return false;
885 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
886 if (m_audioTimer != NULL) m_audioTimer->stop();
889 if (m_audioThumbCreated) {
890 m_audioTimer->stop();
893 m_audioTimer->start(1500);
894 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
895 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
899 bool DocClipBase::isPlaceHolder() const
901 return m_placeHolder;
904 void DocClipBase::addCutZone(int in, int out, QString desc)
907 info.zone = QPoint(in, out);
908 info.description = desc;
909 for (int i = 0; i < m_cutZones.count(); i++)
910 if (m_cutZones.at(i).zone == info.zone) {
913 m_cutZones.append(info);
916 bool DocClipBase::hasCutZone(QPoint p) const
918 for (int i = 0; i < m_cutZones.count(); i++)
919 if (m_cutZones.at(i).zone == p) return true;
924 void DocClipBase::removeCutZone(int in, int out)
927 for (int i = 0; i < m_cutZones.count(); i++) {
928 if (m_cutZones.at(i).zone == p) {
929 m_cutZones.removeAt(i);
935 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
937 QPoint old(oldin, oldout);
938 for (int i = 0; i < m_cutZones.size(); ++i) {
939 if (m_cutZones.at(i).zone == old) {
941 info.zone = QPoint(in, out);
942 info.description = desc;
943 m_cutZones.replace(i, info);
949 QList <CutZoneInfo> DocClipBase::cutZones() const
954 bool DocClipBase::hasVideoCodec(const QString &codec) const
956 Mlt::Producer *prod = NULL;
957 if (m_baseTrackProducers.count() == 0) return false;
958 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
959 if (m_baseTrackProducers.at(i) != NULL) {
960 prod = m_baseTrackProducers.at(i);
965 if (!prod) return false;
966 int default_video = prod->get_int("video_index");
968 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
969 return prod->get(property) == codec;
972 bool DocClipBase::hasAudioCodec(const QString &codec) const
974 Mlt::Producer *prod = NULL;
975 if (m_baseTrackProducers.count() == 0) return false;
976 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
977 if (m_baseTrackProducers.at(i) != NULL) {
978 prod = m_baseTrackProducers.at(i);
982 if (!prod) return false;
983 int default_video = prod->get_int("audio_index");
985 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
986 return prod->get(property) == codec;