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
130 zone.setX(m_properties.value("zone_in", "0").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;
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()
436 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
437 if (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) return;
468 // Clear all previous producers
469 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
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());
502 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
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;
581 if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
582 if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
583 if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
584 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
585 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
586 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
587 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
588 m_baseTrackProducers[track]->set("id", tmp);
590 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
591 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
592 m_baseTrackProducers[track]->set("skip_frame", "bidir");
595 return m_baseTrackProducers.at(track);
598 void DocClipBase::setProducerProperty(const char *name, int data)
600 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
601 if (m_baseTrackProducers.at(i) != NULL)
602 m_baseTrackProducers[i]->set(name, data);
606 void DocClipBase::setProducerProperty(const char *name, double data)
608 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
609 if (m_baseTrackProducers.at(i) != NULL)
610 m_baseTrackProducers[i]->set(name, data);
614 void DocClipBase::setProducerProperty(const char *name, const char *data)
616 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
617 if (m_baseTrackProducers.at(i) != NULL)
618 m_baseTrackProducers[i]->set(name, data);
622 void DocClipBase::resetProducerProperty(const char *name)
624 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
625 if (m_baseTrackProducers.at(i) != NULL)
626 m_baseTrackProducers[i]->set(name, (const char*) NULL);
630 const char *DocClipBase::producerProperty(const char *name) const
632 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
633 if (m_baseTrackProducers.at(i) != NULL) {
634 return m_baseTrackProducers.at(i)->get(name);
641 void DocClipBase::slotRefreshProducer()
643 if (m_baseTrackProducers.count() == 0) return;
644 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
645 if (m_clipType == SLIDESHOW) {
646 /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
647 Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
649 delete m_clipProducer;
650 m_clipProducer = new Mlt::Producer(producer.get_producer());
651 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
652 setProducerProperty("ttl", getProperty("ttl").toInt());
653 //m_clipProducer->set("id", getProperty("id"));
654 if (getProperty("fade") == "1") {
655 // we want a fade filter effect
656 kDebug() << "//////////// FADE WANTED";
657 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
659 Mlt::Filter *filter = clipService.filter(ct);
661 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
665 filter = clipService.filter(ct);
668 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
669 filter->set("period", getProperty("ttl").toInt() - 1);
670 filter->set("luma.out", getProperty("luma_duration").toInt());
671 QString resource = getProperty("luma_file");
672 char *tmp = (char *) qstrdup(resource.toUtf8().data());
673 filter->set("luma.resource", tmp);
675 if (!getProperty("softness").isEmpty()) {
676 int soft = getProperty("softness").toInt();
677 filter->set("luma.softness", (double) soft / 100.0);
680 // filter does not exist, create it...
681 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
682 filter->set("period", getProperty("ttl").toInt() - 1);
683 filter->set("luma.out", getProperty("luma_duration").toInt());
684 QString resource = getProperty("luma_file");
685 char *tmp = (char *) qstrdup(resource.toUtf8().data());
686 filter->set("luma.resource", tmp);
688 if (!getProperty("softness").isEmpty()) {
689 int soft = getProperty("softness").toInt();
690 filter->set("luma.softness", (double) soft / 100.0);
692 clipService.attach(*filter);
695 kDebug() << "//////////// FADE NOT WANTED!!!";
696 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
698 Mlt::Filter *filter = clipService.filter(0);
700 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
701 clipService.detach(*filter);
703 filter = clipService.filter(ct);
709 void DocClipBase::setProperties(QMap <QString, QString> properties)
711 // changing clip type is not allowed
712 properties.remove("type");
713 QMapIterator<QString, QString> i(properties);
714 bool refreshProducer = false;
716 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
717 while (i.hasNext()) {
719 setProperty(i.key(), i.value());
720 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
722 if (refreshProducer) slotRefreshProducer();
725 void DocClipBase::setMetadata(QMap <QString, QString> properties)
727 m_metadata = properties;
730 QMap <QString, QString> DocClipBase::metadata() const
735 void DocClipBase::clearProperty(const QString &key)
737 m_properties.remove(key);
740 void DocClipBase::getFileHash(const QString url)
742 if (m_clipType == SLIDESHOW) return;
744 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
747 //kDebug() << "SETTING HASH of" << value;
748 m_properties.insert("file_size", QString::number(file.size()));
750 * 1 MB = 1 second per 450 files (or faster)
751 * 10 MB = 9 seconds per 450 files (or faster)
753 if (file.size() > 1000000*2) {
754 fileData = file.read(1000000);
755 if (file.seek(file.size() - 1000000))
756 fileData.append(file.readAll());
758 fileData = file.readAll();
760 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
761 m_properties.insert("file_hash", QString(fileHash.toHex()));
765 QString DocClipBase::getClipHash() const
768 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
769 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
770 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
771 else hash = m_properties.value("file_hash");
776 QString DocClipBase::getHash(const QString &path)
779 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
783 * 1 MB = 1 second per 450 files (or faster)
784 * 10 MB = 9 seconds per 450 files (or faster)
786 if (file.size() > 1000000*2) {
787 fileData = file.read(1000000);
788 if (file.seek(file.size() - 1000000))
789 fileData.append(file.readAll());
791 fileData = file.readAll();
793 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
798 void DocClipBase::refreshThumbUrl()
800 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
803 void DocClipBase::setProperty(const QString &key, const QString &value)
805 m_properties.insert(key, value);
806 if (key == "resource") {
808 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
809 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
810 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
811 else if (key == "colour") {
812 char *tmp = (char *) qstrdup(value.toUtf8().data());
813 setProducerProperty("colour", tmp);
815 } else if (key == "templatetext") {
816 char *tmp = (char *) qstrdup(value.toUtf8().data());
817 setProducerProperty("templatetext", tmp);
819 setProducerProperty("force_reload", 1);
820 } else if (key == "xmldata") {
821 char *tmp = (char *) qstrdup(value.toUtf8().data());
822 setProducerProperty("xmldata", tmp);
824 setProducerProperty("force_reload", 1);
825 } else if (key == "force_aspect_ratio") {
826 if (value.isEmpty()) {
827 m_properties.remove("force_aspect_ratio");
828 resetProducerProperty("force_aspect_ratio");
829 } else setProducerProperty("force_aspect_ratio", value.toDouble());
830 } else if (key == "force_fps") {
831 if (value.isEmpty()) {
832 m_properties.remove("force_fps");
833 resetProducerProperty("force_fps");
834 } else setProducerProperty("force_fps", value.toDouble());
835 } else if (key == "force_progressive") {
836 if (value.isEmpty()) {
837 m_properties.remove("force_progressive");
838 resetProducerProperty("force_progressive");
839 } else setProducerProperty("force_progressive", value.toInt());
840 } else if (key == "threads") {
841 if (value.isEmpty()) {
842 m_properties.remove("threads");
843 setProducerProperty("threads", 1);
844 } else setProducerProperty("threads", value.toInt());
845 } else if (key == "video_index") {
846 if (value.isEmpty()) {
847 m_properties.remove("video_index");
848 setProducerProperty("video_index", m_properties.value("default_video").toInt());
849 } else setProducerProperty("video_index", value.toInt());
850 } else if (key == "audio_index") {
851 if (value.isEmpty()) {
852 m_properties.remove("audio_index");
853 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
854 } else setProducerProperty("audio_index", value.toInt());
858 QMap <QString, QString> DocClipBase::properties() const
863 bool DocClipBase::slotGetAudioThumbs()
865 if (m_thumbProd == NULL) return false;
866 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
867 if (m_audioTimer != NULL) m_audioTimer->stop();
870 if (m_audioThumbCreated) {
871 m_audioTimer->stop();
874 m_audioTimer->start(1500);
875 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
876 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
880 bool DocClipBase::isPlaceHolder() const
882 return m_placeHolder;
885 void DocClipBase::addCutZone(int in, int out, QString desc)
888 info.zone = QPoint(in, out);
889 info.description = desc;
890 for (int i = 0; i < m_cutZones.count(); i++)
891 if (m_cutZones.at(i).zone == info.zone) {
894 m_cutZones.append(info);
897 bool DocClipBase::hasCutZone(QPoint p) const
899 for (int i = 0; i < m_cutZones.count(); i++)
900 if (m_cutZones.at(i).zone == p) return true;
905 void DocClipBase::removeCutZone(int in, int out)
908 for (int i = 0; i < m_cutZones.count(); i++) {
909 if (m_cutZones.at(i).zone == p) {
910 m_cutZones.removeAt(i);
916 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
918 QPoint old(oldin, oldout);
919 for (int i = 0; i < m_cutZones.size(); ++i) {
920 if (m_cutZones.at(i).zone == old) {
922 info.zone = QPoint(in, out);
923 info.description = desc;
924 m_cutZones.replace(i, info);
930 QList <CutZoneInfo> DocClipBase::cutZones() const
935 bool DocClipBase::hasVideoCodec(const QString &codec) const
937 Mlt::Producer *prod = NULL;
938 if (m_baseTrackProducers.count() == 0) return false;
939 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
940 if (m_baseTrackProducers.at(i) != NULL) {
941 prod = m_baseTrackProducers.at(i);
946 if (!prod) return false;
947 int default_video = prod->get_int("video_index");
949 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
950 return prod->get(property) == codec;
953 bool DocClipBase::hasAudioCodec(const QString &codec) const
955 Mlt::Producer *prod = NULL;
956 if (m_baseTrackProducers.count() == 0) return false;
957 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
958 if (m_baseTrackProducers.at(i) != NULL) {
959 prod = m_baseTrackProducers.at(i);
963 if (!prod) return false;
964 int default_video = prod->get_int("audio_index");
966 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
967 return prod->get(property) == codec;