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),
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
130 zone.setX(m_properties.value("zone_in").toInt());
131 zone.setY(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 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
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) slotGetAudioThumbs();
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;
328 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
330 m_snapMarkers = markers;
333 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
335 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
336 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
337 if ((*it).time() >= time)
341 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
342 (*it).setComment(comment);
343 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
345 CommentedTime t(time, comment);
346 m_snapMarkers.insert(it, t);
351 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
353 QList < CommentedTime >::Iterator it;
354 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
355 if ((*it).time() == time)
358 if (it != m_snapMarkers.end()) {
359 (*it).setComment(comment);
361 kError() << "trying to edit Snap Marker that does not already exists";
365 QString DocClipBase::deleteSnapMarker(const GenTime & time)
367 QString result = i18n("Marker");
368 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
370 while (itt != m_snapMarkers.end()) {
371 if ((*itt).time() == time)
376 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
377 result = (*itt).comment();
378 m_snapMarkers.erase(itt);
384 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
386 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
388 while (itt != m_snapMarkers.end()) {
389 if ((*itt).time() == time)
397 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
400 for (it = 0; it < m_snapMarkers.count(); it++) {
401 if (m_snapMarkers.at(it).time() >= currTime)
404 if (it == 0) return GenTime();
405 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
406 return m_snapMarkers.at(it).time();
407 else return m_snapMarkers.at(it - 1).time();
410 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
413 for (it = 0; it < m_snapMarkers.count(); it++) {
414 if (m_snapMarkers.at(it).time() > currTime)
417 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
421 QString DocClipBase::markerComment(GenTime t)
423 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
425 while (itt != m_snapMarkers.end()) {
426 if ((*itt).time() == t)
427 return (*itt).comment();
433 void DocClipBase::clearProducers()
435 m_baseTrackProducers.clear();
438 void DocClipBase::deleteProducers()
440 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
441 if (m_thumbProd) m_thumbProd->clearProducer();
442 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
443 int max = m_baseTrackProducers.count();
444 for (int i = 0; i < max; i++) {
445 kDebug()<<"// CLIP KILL PROD "<<i;
446 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
451 m_baseTrackProducers.insert(i, NULL);
454 delete m_videoOnlyProducer;
455 m_videoOnlyProducer = NULL;
457 qDeleteAll(m_baseTrackProducers);
458 m_baseTrackProducers.clear();
459 qDeleteAll(m_audioTrackProducers);
460 m_audioTrackProducers.clear();
463 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
465 if (producer == NULL) return;
467 // Clear all previous producers
468 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
471 QString id = producer->get("id");
472 if (id.contains('_')) {
473 // this is a subtrack producer, insert it at correct place
474 id = id.section('_', 1);
475 if (id.endsWith("audio")) {
476 int pos = id.section('_', 0, 0).toInt();
477 if (pos >= m_audioTrackProducers.count()) {
478 while (m_audioTrackProducers.count() - 1 < pos) {
479 m_audioTrackProducers.append(NULL);
482 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
484 } else if (id.endsWith("video")) {
485 m_videoOnlyProducer = producer;
488 int pos = id.toInt();
489 if (pos >= m_baseTrackProducers.count()) {
490 while (m_baseTrackProducers.count() - 1 < pos) {
491 m_baseTrackProducers.append(NULL);
494 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
496 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
497 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
499 //m_clipProducer = producer;
500 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
501 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
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 m_metadata = properties;
729 QMap <QString, QString> DocClipBase::metadata() const
734 void DocClipBase::clearProperty(const QString &key)
736 m_properties.remove(key);
739 void DocClipBase::getFileHash(const QString url)
741 if (m_clipType == SLIDESHOW) return;
743 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
746 //kDebug() << "SETTING HASH of" << value;
747 m_properties.insert("file_size", QString::number(file.size()));
749 * 1 MB = 1 second per 450 files (or faster)
750 * 10 MB = 9 seconds per 450 files (or faster)
752 if (file.size() > 1000000*2) {
753 fileData = file.read(1000000);
754 if (file.seek(file.size() - 1000000))
755 fileData.append(file.readAll());
757 fileData = file.readAll();
759 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
760 m_properties.insert("file_hash", QString(fileHash.toHex()));
764 QString DocClipBase::getClipHash() const
767 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
768 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
769 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
770 else hash = m_properties.value("file_hash");
775 QString DocClipBase::getHash(const QString &path)
778 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
782 * 1 MB = 1 second per 450 files (or faster)
783 * 10 MB = 9 seconds per 450 files (or faster)
785 if (file.size() > 1000000*2) {
786 fileData = file.read(1000000);
787 if (file.seek(file.size() - 1000000))
788 fileData.append(file.readAll());
790 fileData = file.readAll();
792 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
797 void DocClipBase::refreshThumbUrl()
799 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
802 void DocClipBase::setProperty(const QString &key, const QString &value)
804 m_properties.insert(key, value);
805 if (key == "resource") {
807 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
808 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
809 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
810 else if (key == "colour") {
811 char *tmp = (char *) qstrdup(value.toUtf8().data());
812 setProducerProperty("colour", tmp);
814 } else if (key == "templatetext") {
815 char *tmp = (char *) qstrdup(value.toUtf8().data());
816 setProducerProperty("templatetext", tmp);
818 setProducerProperty("force_reload", 1);
819 } else if (key == "xmldata") {
820 char *tmp = (char *) qstrdup(value.toUtf8().data());
821 setProducerProperty("xmldata", tmp);
823 setProducerProperty("force_reload", 1);
824 } else if (key == "force_aspect_ratio") {
825 if (value.isEmpty()) {
826 m_properties.remove("force_aspect_ratio");
827 resetProducerProperty("force_aspect_ratio");
828 } else setProducerProperty("force_aspect_ratio", value.toDouble());
829 } else if (key == "force_fps") {
830 if (value.isEmpty()) {
831 m_properties.remove("force_fps");
832 resetProducerProperty("force_fps");
833 } else setProducerProperty("force_fps", value.toDouble());
834 } else if (key == "force_progressive") {
835 if (value.isEmpty()) {
836 m_properties.remove("force_progressive");
837 resetProducerProperty("force_progressive");
838 } else setProducerProperty("force_progressive", value.toInt());
839 } else if (key == "threads") {
840 if (value.isEmpty()) {
841 m_properties.remove("threads");
842 setProducerProperty("threads", 1);
843 } else setProducerProperty("threads", value.toInt());
844 } else if (key == "video_index") {
845 if (value.isEmpty()) {
846 m_properties.remove("video_index");
847 setProducerProperty("video_index", m_properties.value("default_video").toInt());
848 } else setProducerProperty("video_index", value.toInt());
849 } else if (key == "audio_index") {
850 if (value.isEmpty()) {
851 m_properties.remove("audio_index");
852 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
853 } else setProducerProperty("audio_index", value.toInt());
857 QMap <QString, QString> DocClipBase::properties() const
862 bool DocClipBase::slotGetAudioThumbs()
864 if (m_thumbProd == NULL) return false;
865 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
866 if (m_audioTimer != NULL) m_audioTimer->stop();
869 if (m_audioThumbCreated) {
870 m_audioTimer->stop();
873 m_audioTimer->start(1500);
874 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
875 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
879 bool DocClipBase::isPlaceHolder() const
881 return m_placeHolder;
884 void DocClipBase::addCutZone(int in, int out, QString desc)
887 info.zone = QPoint(in, out);
888 info.description = desc;
889 for (int i = 0; i < m_cutZones.count(); i++)
890 if (m_cutZones.at(i).zone == info.zone) {
893 m_cutZones.append(info);
896 bool DocClipBase::hasCutZone(QPoint p) const
898 for (int i = 0; i < m_cutZones.count(); i++)
899 if (m_cutZones.at(i).zone == p) return true;
904 void DocClipBase::removeCutZone(int in, int out)
907 for (int i = 0; i < m_cutZones.count(); i++) {
908 if (m_cutZones.at(i).zone == p) {
909 m_cutZones.removeAt(i);
915 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
917 QPoint old(oldin, oldout);
918 for (int i = 0; i < m_cutZones.size(); ++i) {
919 if (m_cutZones.at(i).zone == old) {
921 info.zone = QPoint(in, out);
922 info.description = desc;
923 m_cutZones.replace(i, info);
929 QList <CutZoneInfo> DocClipBase::cutZones() const
934 bool DocClipBase::hasVideoCodec(const QString &codec) const
936 Mlt::Producer *prod = NULL;
937 if (m_baseTrackProducers.count() == 0) return false;
938 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
939 if (m_baseTrackProducers.at(i) != NULL) {
940 prod = m_baseTrackProducers.at(i);
945 if (!prod) return false;
946 int default_video = prod->get_int("video_index");
948 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
949 return prod->get(property) == codec;
952 bool DocClipBase::hasAudioCodec(const QString &codec) const
954 Mlt::Producer *prod = NULL;
955 if (m_baseTrackProducers.count() == 0) return false;
956 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
957 if (m_baseTrackProducers.at(i) != NULL) {
958 prod = m_baseTrackProducers.at(i);
962 if (!prod) return false;
963 int default_video = prod->get_int("audio_index");
965 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
966 return prod->get(property) == codec;