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"
31 #include "slideshowclip.h"
33 #include <KIO/NetAccess>
34 #include <KStandardDirs>
37 #include <QCryptographicHash>
38 #include <QtConcurrentRun>
42 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
46 m_baseTrackProducers(),
47 m_audioTrackProducers(),
48 m_videoOnlyProducer(NULL),
49 m_snapMarkers(QList < CommentedTime >()),
53 m_audioThumbCreated(false),
55 m_placeHolder(xml.hasAttribute("placeholder")),
58 int type = xml.attribute("type").toInt();
59 m_clipType = (CLIPTYPE) type;
60 if (m_placeHolder) xml.removeAttribute("placeholder");
61 QDomNamedNodeMap attributes = xml.attributes();
62 for (int i = 0; i < attributes.count(); i++) {
63 QString name = attributes.item(i).nodeName();
64 if (name.startsWith("meta.attr.")) {
65 m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
66 } else m_properties.insert(name, attributes.item(i).nodeValue());
69 if (xml.hasAttribute("cutzones")) {
70 QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
71 for (int i = 0; i < cuts.count(); i++) {
72 QString z = cuts.at(i);
73 addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
77 KUrl url = KUrl(xml.attribute("resource"));
78 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
80 if (xml.hasAttribute("duration")) {
81 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
83 int out = xml.attribute("out").toInt();
84 int in = xml.attribute("in").toInt();
85 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
88 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
90 //if (!url.isEmpty() && QFile::exists(url.path()))
92 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
93 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer();
95 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
98 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
99 DocClipBase::operator=(clip);
101 m_clipType = clip.clipType();
102 m_name = clip.name();
103 m_duration = clip.duration();
104 m_audioThumbCreated = clip.audioThumbCreated();
105 m_properties = clip.properties();
109 DocClipBase::~DocClipBase()
111 kDebug() << "CLIP " << m_id << " DELETED******************************";
114 m_audioTimer->stop();
117 /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
118 if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
119 qDeleteAll(m_baseTrackProducers);
120 m_baseTrackProducers.clear();
121 qDeleteAll(m_audioTrackProducers);
122 m_audioTrackProducers.clear();
123 delete m_videoOnlyProducer;
124 m_videoOnlyProducer = NULL;
127 void DocClipBase::setZone(QPoint zone)
129 m_properties.insert("zone_in", QString::number(zone.x()));
130 m_properties.insert("zone_out", QString::number(zone.y()));
133 QPoint DocClipBase::zone() const
135 QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
139 void DocClipBase::slotCreateAudioTimer()
141 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
142 m_audioTimer = new QTimer(this);
143 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
146 void DocClipBase::askForAudioThumbs()
148 if (m_thumbProd && m_audioTimer) m_thumbProd->askForAudioThumbs(getId());
151 void DocClipBase::slotClearAudioCache()
153 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
154 if (m_audioTimer != NULL) m_audioTimer->stop();
155 m_audioFrameCache.clear();
156 m_audioThumbCreated = false;
159 /*void DocClipBase::getClipMainThumb() {
160 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
163 KThumb *DocClipBase::thumbProducer()
168 bool DocClipBase::audioThumbCreated() const
170 return m_audioThumbCreated;
173 const QString DocClipBase::name() const
176 return m_properties.value("name");
179 const QString &DocClipBase::getId() const
184 void DocClipBase::setId(const QString &newId)
189 const CLIPTYPE & DocClipBase::clipType() const
194 void DocClipBase::setClipType(CLIPTYPE type)
198 m_properties.insert("type", QString::number((int) type));
199 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST))
200 slotCreateAudioTimer();
203 KUrl DocClipBase::fileURL() const
205 QString res = m_properties.value("resource");
206 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
210 void DocClipBase::setClipThumbFrame(const uint &ix)
212 m_properties.insert("thumbnail", QString::number((int) ix));
215 uint DocClipBase::getClipThumbFrame() const
217 return (uint) m_properties.value("thumbnail").toInt();
220 const QString DocClipBase::description() const
222 return m_properties.value("description");
225 bool DocClipBase::isTransparent() const
227 return (m_properties.value("transparency") == "1");
230 const QString DocClipBase::getProperty(const QString prop) const
232 return m_properties.value(prop);
235 void DocClipBase::setDuration(GenTime dur)
238 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
241 const GenTime &DocClipBase::duration() const
246 const GenTime DocClipBase::maxDuration() const
248 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
249 /*const GenTime dur(15000, KdenliveSettings::project_fps());
256 bool DocClipBase::hasFileSize() const
261 qulonglong DocClipBase::fileSize() const
263 return m_properties.value("file_size").toULongLong();
267 QDomElement DocClipBase::toXML() const
270 QDomElement clip = doc.createElement("producer");
272 QMapIterator<QString, QString> i(m_properties);
273 while (i.hasNext()) {
275 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
277 doc.appendChild(clip);
278 if (!m_cutZones.isEmpty()) {
280 for (int i = 0; i < m_cutZones.size(); i++) {
281 CutZoneInfo info = m_cutZones.at(i);
282 cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
284 clip.setAttribute("cutzones", cuts.join(";"));
286 //kDebug() << "/// CLIP XML: " << doc.toString();
287 return doc.documentElement();
291 void DocClipBase::setAudioThumbCreated(bool isDone)
293 m_audioThumbCreated = isDone;
297 void DocClipBase::setThumbnail(const QPixmap & pixmap)
299 m_thumbnail = pixmap;
302 const QPixmap & DocClipBase::thumbnail() const
307 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
309 //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
310 m_audioFrameCache = data;
311 m_audioThumbCreated = true;
315 QList < GenTime > DocClipBase::snapMarkers() const
317 QList < GenTime > markers;
319 for (int count = 0; count < m_snapMarkers.count(); ++count) {
320 markers.append(m_snapMarkers.at(count).time());
326 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
328 return m_snapMarkers;
332 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
334 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
335 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
336 if ((*it).time() >= time)
340 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
341 (*it).setComment(comment);
342 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
344 CommentedTime t(time, comment);
345 m_snapMarkers.insert(it, t);
350 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
352 QList < CommentedTime >::Iterator it;
353 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
354 if ((*it).time() == time)
357 if (it != m_snapMarkers.end()) {
358 (*it).setComment(comment);
360 kError() << "trying to edit Snap Marker that does not already exists";
364 QString DocClipBase::deleteSnapMarker(const GenTime & time)
366 QString result = i18n("Marker");
367 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
369 while (itt != m_snapMarkers.end()) {
370 if ((*itt).time() == time)
375 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
376 result = (*itt).comment();
377 m_snapMarkers.erase(itt);
383 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
385 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
387 while (itt != m_snapMarkers.end()) {
388 if ((*itt).time() == time)
396 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
399 for (it = 0; it < m_snapMarkers.count(); it++) {
400 if (m_snapMarkers.at(it).time() >= currTime)
403 if (it == 0) return GenTime();
404 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
405 return m_snapMarkers.at(it).time();
406 else return m_snapMarkers.at(it - 1).time();
409 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
412 for (it = 0; it < m_snapMarkers.count(); it++) {
413 if (m_snapMarkers.at(it).time() > currTime)
416 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
420 QString DocClipBase::markerComment(GenTime t)
422 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
424 while (itt != m_snapMarkers.end()) {
425 if ((*itt).time() == t)
426 return (*itt).comment();
432 void DocClipBase::deleteProducers(bool clearThumbCreator)
434 if (clearThumbCreator && m_thumbProd) m_thumbProd->clearProducer();
436 delete m_videoOnlyProducer;
437 m_videoOnlyProducer = NULL;
439 qDeleteAll(m_baseTrackProducers);
440 m_baseTrackProducers.clear();
441 qDeleteAll(m_audioTrackProducers);
442 m_audioTrackProducers.clear();
445 void DocClipBase::setValid()
447 m_placeHolder = false;
450 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset, bool readPropertiesFromProducer)
452 if (producer == NULL || !producer->is_valid()) return;
453 if (reset) m_producerMutex.lock();
455 char *tmp = qstrdup(i18n("Missing clip").toUtf8().constData());
456 producer->set("markup", tmp);
457 producer->set("bgcolour", "0xff0000ff");
458 producer->set("pad", "10");
461 QString id = producer->get("id");
463 if (reset) m_thumbProd->setProducer(NULL);
464 if (!m_thumbProd->hasProducer()) {
465 if (m_clipType != AUDIO) {
466 if (!id.endsWith("_audio"))
467 m_thumbProd->setProducer(producer);
469 else m_thumbProd->setProducer(producer);
473 // Clear all previous producers
474 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
475 deleteProducers(false);
477 bool updated = false;
478 if (id.contains('_')) {
479 // this is a subtrack producer, insert it at correct place
480 id = id.section('_', 1);
481 if (id.endsWith("audio")) {
482 int pos = id.section('_', 0, 0).toInt();
483 if (pos >= m_audioTrackProducers.count()) {
484 while (m_audioTrackProducers.count() - 1 < pos) {
485 m_audioTrackProducers.append(NULL);
488 if (m_audioTrackProducers.at(pos) == NULL) {
489 m_audioTrackProducers[pos] = producer;
492 if (reset) m_producerMutex.unlock();
494 } else if (id.endsWith("video")) {
495 if (m_videoOnlyProducer == NULL) {
496 m_videoOnlyProducer = producer;
499 if (reset) m_producerMutex.unlock();
502 int pos = id.toInt();
503 if (pos >= m_baseTrackProducers.count()) {
504 while (m_baseTrackProducers.count() - 1 < pos) {
505 m_baseTrackProducers.append(NULL);
508 if (m_baseTrackProducers.at(pos) == NULL) {
509 m_baseTrackProducers[pos] = producer;
513 if (m_baseTrackProducers.isEmpty()) {
514 m_baseTrackProducers.append(producer);
517 else if (m_baseTrackProducers.at(0) == NULL) {
518 m_baseTrackProducers[0] = producer;
522 if (updated && readPropertiesFromProducer && (m_clipType != COLOR && m_clipType != IMAGE && m_clipType != TEXT))
523 setDuration(GenTime(producer->get_length(), KdenliveSettings::project_fps()));
524 if (reset) m_producerMutex.unlock();
527 static double getPixelAspect(QMap<QString, QString>& props) {
528 int width = props.value("frame_size").section('x', 0, 0).toInt();
529 int height = props.value("frame_size").section('x', 1, 1).toInt();
530 int aspectNumerator = props.value("force_aspect_num").toInt();
531 int aspectDenominator = props.value("force_aspect_den").toInt();
532 if (aspectDenominator != 0 && width != 0)
533 return double(height) * aspectNumerator / aspectDenominator / width;
538 Mlt::Producer *DocClipBase::audioProducer(int track)
540 m_producerMutex.lock();
541 if (m_audioTrackProducers.count() <= track) {
542 while (m_audioTrackProducers.count() - 1 < track) {
543 m_audioTrackProducers.append(NULL);
546 if (m_audioTrackProducers.at(track) == NULL) {
548 for (i = 0; i < m_audioTrackProducers.count(); i++)
549 if (m_audioTrackProducers.at(i) != NULL) break;
551 if (i >= m_audioTrackProducers.count()) {
552 // Could not find a valid producer for that clip
553 m_producerMutex.unlock();
558 m_producerMutex.lock();
560 else base = m_audioTrackProducers.at(i);
561 m_audioTrackProducers[track] = cloneProducer(base);
562 adjustProducerProperties(m_audioTrackProducers.at(track), QString(getId() + '_' + QString::number(track) + "_audio"), false, true);
564 m_producerMutex.unlock();
565 return m_audioTrackProducers.at(track);
569 void DocClipBase::adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind)
571 if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
572 prod->set("force_aspect_ratio", getPixelAspect(m_properties));
573 if (m_properties.contains("force_fps")) prod->set("force_fps", m_properties.value("force_fps").toDouble());
574 if (m_properties.contains("force_progressive")) prod->set("force_progressive", m_properties.value("force_progressive").toInt());
575 if (m_properties.contains("force_tff")) prod->set("force_tff", m_properties.value("force_tff").toInt());
576 if (m_properties.contains("threads")) prod->set("threads", m_properties.value("threads").toInt());
577 if (mute) prod->set("audio_index", -1);
578 else if (m_properties.contains("audio_index")) prod->set("audio_index", m_properties.value("audio_index").toInt());
579 if (blind) prod->set("video_index", -1);
580 else if (m_properties.contains("video_index")) prod->set("video_index", m_properties.value("video_index").toInt());
581 prod->set("id", id.toUtf8().data());
582 if (m_properties.contains("force_colorspace")) prod->set("force_colorspace", m_properties.value("force_colorspace").toInt());
583 if (m_properties.contains("full_luma")) prod->set("set.force_full_luma", m_properties.value("full_luma").toInt());
584 if (m_properties.contains("proxy_out")) {
585 // We have a proxy clip, make sure the proxy has same duration as original
586 prod->set("length", m_properties.value("duration").toInt());
587 prod->set("out", m_properties.value("proxy_out").toInt());
592 Mlt::Producer *DocClipBase::videoProducer()
594 m_producerMutex.lock();
595 if (m_videoOnlyProducer == NULL) {
597 for (i = 0; i < m_baseTrackProducers.count(); i++)
598 if (m_baseTrackProducers.at(i) != NULL) break;
599 if (i >= m_baseTrackProducers.count()) return NULL;
600 m_videoOnlyProducer = cloneProducer(m_baseTrackProducers.at(i));
601 adjustProducerProperties(m_videoOnlyProducer, QString(getId() + "_video"), true, false);
603 m_producerMutex.unlock();
604 return m_videoOnlyProducer;
607 Mlt::Producer *DocClipBase::producer(int track)
609 m_producerMutex.lock();
610 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST)) {
611 if (m_baseTrackProducers.count() == 0) {
612 m_producerMutex.unlock();
615 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
616 if (m_baseTrackProducers.at(i) != NULL) {
617 m_producerMutex.unlock();
618 return m_baseTrackProducers.at(i);
621 m_producerMutex.unlock();
624 if (track >= m_baseTrackProducers.count()) {
625 while (m_baseTrackProducers.count() - 1 < track) {
626 m_baseTrackProducers.append(NULL);
629 if (m_baseTrackProducers.at(track) == NULL) {
631 for (i = 0; i < m_baseTrackProducers.count(); i++)
632 if (m_baseTrackProducers.at(i) != NULL) break;
634 if (i >= m_baseTrackProducers.count()) {
635 // Could not find a valid producer for that clip, check in
636 m_producerMutex.unlock();
639 m_baseTrackProducers[track] = cloneProducer(m_baseTrackProducers.at(i));
640 adjustProducerProperties(m_baseTrackProducers.at(track), QString(getId() + '_' + QString::number(track)), false, false);
642 m_producerMutex.unlock();
643 return m_baseTrackProducers.at(track);
647 Mlt::Producer *DocClipBase::cloneProducer(Mlt::Producer *source)
649 Mlt::Producer *result = NULL;
650 QString url = source->get("resource");
651 if (KIO::NetAccess::exists(KUrl(url), KIO::NetAccess::SourceSide, 0)) {
652 char *tmp = qstrdup(url.toUtf8().constData());
653 result = new Mlt::Producer(*source->profile(), tmp);
656 if (result == NULL || !result->is_valid()) {
658 QString txt = "+" + i18n("Missing clip") + ".txt";
659 char *tmp = qstrdup(txt.toUtf8().constData());
660 result = new Mlt::Producer(*source->profile(), tmp);
662 if (result == NULL || !result->is_valid())
663 result = new Mlt::Producer(*source->profile(), "colour:red");
665 result->set("bgcolour", "0xff0000ff");
666 result->set("pad", "10");
669 Mlt::Properties props(result->get_properties());
670 Mlt::Properties src_props(source->get_properties());
671 props.inherit(src_props);
675 void DocClipBase::setProducerProperty(const char *name, int data)
677 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
678 if (m_baseTrackProducers.at(i) != NULL)
679 m_baseTrackProducers[i]->set(name, data);
683 void DocClipBase::setProducerProperty(const char *name, double data)
685 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
686 if (m_baseTrackProducers.at(i) != NULL)
687 m_baseTrackProducers[i]->set(name, data);
691 void DocClipBase::setProducerProperty(const char *name, const char *data)
693 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
694 if (m_baseTrackProducers.at(i) != NULL)
695 m_baseTrackProducers[i]->set(name, data);
699 void DocClipBase::resetProducerProperty(const char *name)
701 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
702 if (m_baseTrackProducers.at(i) != NULL)
703 m_baseTrackProducers[i]->set(name, (const char*) NULL);
707 const char *DocClipBase::producerProperty(const char *name) const
709 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
710 if (m_baseTrackProducers.at(i) != NULL) {
711 return m_baseTrackProducers.at(i)->get(name);
718 void DocClipBase::slotRefreshProducer()
720 if (m_baseTrackProducers.count() == 0) return;
721 if (m_clipType == SLIDESHOW) {
722 /*Mlt::Producer producer(*(m_clipProducer->profile()), getProperty("resource").toUtf8().data());
723 delete m_clipProducer;
724 m_clipProducer = new Mlt::Producer(producer.get_producer());
725 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
726 setProducerProperty("ttl", getProperty("ttl").toInt());
727 //m_clipProducer->set("id", getProperty("id"));
728 if (!getProperty("animation").isEmpty()) {
729 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
731 Mlt::Filter *filter = clipService.filter(ct);
733 if (strcmp(filter->get("mlt_service"), "affine") == 0) {
735 } else if (strcmp(filter->get("mlt_service"), "boxblur") == 0) {
736 clipService.detach(*filter);
738 filter = clipService.filter(ct);
741 if (!filter || strcmp(filter->get("mlt_service"), "affine")) {
742 // filter does not exist, create it.
743 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "affine");
744 if (filter && filter->is_valid()) {
745 int cycle = getProperty("ttl").toInt();
746 QString geometry = SlideshowClip::animationToGeometry(getProperty("animation"), cycle);
747 if (!geometry.isEmpty()) {
748 if (getProperty("animation").contains("low-pass")) {
749 Mlt::Filter *blur = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "boxblur");
750 if (blur && blur->is_valid())
751 clipService.attach(*blur);
753 filter->set("transition.geometry", geometry.toUtf8().data());
754 filter->set("transition.cycle", cycle);
755 clipService.attach(*filter);
760 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
762 Mlt::Filter *filter = clipService.filter(0);
764 if (strcmp(filter->get("mlt_service"), "affine") == 0 || strcmp(filter->get("mlt_service"), "boxblur") == 0) {
765 clipService.detach(*filter);
767 filter = clipService.filter(ct);
770 if (getProperty("fade") == "1") {
771 // we want a fade filter effect
772 kDebug() << "//////////// FADE WANTED";
773 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
775 Mlt::Filter *filter = clipService.filter(ct);
777 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
781 filter = clipService.filter(ct);
784 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
785 filter->set("cycle", getProperty("ttl").toInt());
786 filter->set("duration", getProperty("luma_duration").toInt());
787 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
788 if (!getProperty("softness").isEmpty()) {
789 int soft = getProperty("softness").toInt();
790 filter->set("luma.softness", (double) soft / 100.0);
793 // filter does not exist, create it...
794 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
795 filter->set("cycle", getProperty("ttl").toInt());
796 filter->set("duration", getProperty("luma_duration").toInt());
797 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
798 if (!getProperty("softness").isEmpty()) {
799 int soft = getProperty("softness").toInt();
800 filter->set("luma.softness", (double) soft / 100.0);
802 clipService.attach(*filter);
805 kDebug() << "//////////// FADE NOT WANTED!!!";
806 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
808 Mlt::Filter *filter = clipService.filter(0);
810 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
811 clipService.detach(*filter);
813 filter = clipService.filter(ct);
816 if (getProperty("crop") == "1") {
817 // we want a center crop filter effect
818 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
820 Mlt::Filter *filter = clipService.filter(ct);
822 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
826 filter = clipService.filter(ct);
829 if (!filter || strcmp(filter->get("mlt_service"), "crop")) {
830 // filter does not exist, create it...
831 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "crop");
832 filter->set("center", 1);
833 clipService.attach(*filter);
836 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
838 Mlt::Filter *filter = clipService.filter(0);
840 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
841 clipService.detach(*filter);
843 filter = clipService.filter(ct);
849 void DocClipBase::setProperties(QMap <QString, QString> properties)
851 // changing clip type is not allowed
852 properties.remove("type");
853 QMapIterator<QString, QString> i(properties);
854 bool refreshProducer = false;
856 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness" << "crop" << "animation";
857 QString oldProxy = m_properties.value("proxy");
858 while (i.hasNext()) {
860 setProperty(i.key(), i.value());
861 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
863 if (properties.contains("proxy")) {
864 QString value = properties.value("proxy");
865 // If value is "-", that means user manually disabled proxy on this clip
866 if (value.isEmpty() || value == "-") {
868 emit abortProxy(m_id, oldProxy);
871 emit createProxy(m_id);
874 if (refreshProducer) slotRefreshProducer();
877 void DocClipBase::setMetadata(QMap <QString, QString> properties)
879 QMapIterator<QString, QString> i(properties);
880 while (i.hasNext()) {
882 if (i.value().isEmpty() && m_metadata.contains(i.key())) {
883 m_metadata.remove(i.key());
885 m_metadata.insert(i.key(), i.value());
890 QMap <QString, QString> DocClipBase::metadata() const
895 void DocClipBase::clearProperty(const QString &key)
897 m_properties.remove(key);
900 void DocClipBase::getFileHash(const QString url)
902 if (m_clipType == SLIDESHOW) return;
904 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
907 //kDebug() << "SETTING HASH of" << value;
908 m_properties.insert("file_size", QString::number(file.size()));
910 * 1 MB = 1 second per 450 files (or faster)
911 * 10 MB = 9 seconds per 450 files (or faster)
913 if (file.size() > 1000000*2) {
914 fileData = file.read(1000000);
915 if (file.seek(file.size() - 1000000))
916 fileData.append(file.readAll());
918 fileData = file.readAll();
920 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
921 m_properties.insert("file_hash", QString(fileHash.toHex()));
925 bool DocClipBase::checkHash() const
927 KUrl url = fileURL();
928 if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
932 QString DocClipBase::getClipHash() const
935 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
936 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
937 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
939 if (m_properties.contains("file_hash")) hash = m_properties.value("file_hash");
940 if (hash.isEmpty()) hash = getHash(fileURL().path());
946 void DocClipBase::setPlaceHolder(bool place)
948 m_placeHolder = place;
952 QString DocClipBase::getHash(const QString &path)
955 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
959 * 1 MB = 1 second per 450 files (or faster)
960 * 10 MB = 9 seconds per 450 files (or faster)
962 if (file.size() > 1000000*2) {
963 fileData = file.read(1000000);
964 if (file.seek(file.size() - 1000000))
965 fileData.append(file.readAll());
967 fileData = file.readAll();
969 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
974 void DocClipBase::refreshThumbUrl()
976 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
979 void DocClipBase::setProperty(const QString &key, const QString &value)
981 m_properties.insert(key, value);
982 if (key == "resource") {
984 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
985 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
986 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
987 else if (key == "colour") {
988 setProducerProperty("colour", value.toUtf8().data());
989 } else if (key == "templatetext") {
990 setProducerProperty("templatetext", value.toUtf8().data());
991 setProducerProperty("force_reload", 1);
992 } else if (key == "xmldata") {
993 setProducerProperty("xmldata", value.toUtf8().data());
994 setProducerProperty("force_reload", 1);
995 } else if (key == "force_aspect_num") {
996 if (value.isEmpty()) {
997 m_properties.remove("force_aspect_num");
998 resetProducerProperty("force_aspect_ratio");
999 } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
1000 } else if (key == "force_aspect_den") {
1001 if (value.isEmpty()) {
1002 m_properties.remove("force_aspect_den");
1003 resetProducerProperty("force_aspect_ratio");
1004 } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
1005 } else if (key == "force_fps") {
1006 if (value.isEmpty()) {
1007 m_properties.remove("force_fps");
1008 resetProducerProperty("force_fps");
1009 } else setProducerProperty("force_fps", value.toDouble());
1010 } else if (key == "force_progressive") {
1011 if (value.isEmpty()) {
1012 m_properties.remove("force_progressive");
1013 resetProducerProperty("force_progressive");
1014 } else setProducerProperty("force_progressive", value.toInt());
1015 } else if (key == "force_tff") {
1016 if (value.isEmpty()) {
1017 m_properties.remove("force_tff");
1018 resetProducerProperty("force_tff");
1019 } else setProducerProperty("force_tff", value.toInt());
1020 } else if (key == "threads") {
1021 if (value.isEmpty()) {
1022 m_properties.remove("threads");
1023 setProducerProperty("threads", 1);
1024 } else setProducerProperty("threads", value.toInt());
1025 } else if (key == "video_index") {
1026 if (value.isEmpty()) {
1027 m_properties.remove("video_index");
1028 setProducerProperty("video_index", m_properties.value("default_video").toInt());
1029 } else setProducerProperty("video_index", value.toInt());
1030 } else if (key == "audio_index") {
1031 if (value.isEmpty()) {
1032 m_properties.remove("audio_index");
1033 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
1034 } else setProducerProperty("audio_index", value.toInt());
1035 } else if (key == "force_colorspace") {
1036 if (value.isEmpty()) {
1037 m_properties.remove("force_colorspace");
1038 resetProducerProperty("force_colorspace");
1039 } else setProducerProperty("force_colorspace", value.toInt());
1040 } else if (key == "full_luma") {
1041 if (value.isEmpty()) {
1042 m_properties.remove("full_luma");
1043 resetProducerProperty("set.force_full_luma");
1044 } else setProducerProperty("set.force_full_luma", value.toInt());
1048 QMap <QString, QString> DocClipBase::properties() const
1050 return m_properties;
1053 bool DocClipBase::slotGetAudioThumbs()
1055 if (m_thumbProd == NULL || isPlaceHolder()) return false;
1056 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
1057 if (m_audioTimer != NULL) m_audioTimer->stop();
1060 if (m_audioThumbCreated) {
1061 m_audioTimer->stop();
1064 m_audioTimer->start(1500);
1065 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
1066 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
1070 bool DocClipBase::isPlaceHolder() const
1072 return m_placeHolder;
1075 void DocClipBase::addCutZone(int in, int out, QString desc)
1078 info.zone = QPoint(in, out);
1079 info.description = desc;
1080 for (int i = 0; i < m_cutZones.count(); i++)
1081 if (m_cutZones.at(i).zone == info.zone) {
1084 m_cutZones.append(info);
1087 bool DocClipBase::hasCutZone(QPoint p) const
1089 for (int i = 0; i < m_cutZones.count(); i++)
1090 if (m_cutZones.at(i).zone == p) return true;
1095 void DocClipBase::removeCutZone(int in, int out)
1098 for (int i = 0; i < m_cutZones.count(); i++) {
1099 if (m_cutZones.at(i).zone == p) {
1100 m_cutZones.removeAt(i);
1106 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
1108 QPoint old(oldin, oldout);
1109 for (int i = 0; i < m_cutZones.size(); ++i) {
1110 if (m_cutZones.at(i).zone == old) {
1112 info.zone = QPoint(in, out);
1113 info.description = desc;
1114 m_cutZones.replace(i, info);
1120 QList <CutZoneInfo> DocClipBase::cutZones() const
1125 bool DocClipBase::hasVideoCodec(const QString &codec) const
1127 Mlt::Producer *prod = NULL;
1128 if (m_baseTrackProducers.count() == 0) return false;
1129 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1130 if (m_baseTrackProducers.at(i) != NULL) {
1131 prod = m_baseTrackProducers.at(i);
1136 if (!prod) return false;
1137 int default_video = prod->get_int("video_index");
1139 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1140 return prod->get(property) == codec;
1143 bool DocClipBase::hasAudioCodec(const QString &codec) const
1145 Mlt::Producer *prod = NULL;
1146 if (m_baseTrackProducers.count() == 0) return false;
1147 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1148 if (m_baseTrackProducers.at(i) != NULL) {
1149 prod = m_baseTrackProducers.at(i);
1153 if (!prod) return false;
1154 int default_video = prod->get_int("audio_index");
1156 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1157 return prod->get(property) == codec;
1161 void DocClipBase::slotExtractImage(int frame, int frame2)
1163 if (m_thumbProd == NULL) return;
1164 m_thumbProd->extractImage(frame, frame2);
1167 void DocClipBase::slotBlock()
1169 m_producerMutex.lock();
1172 void DocClipBase::slotRelease()
1174 m_producerMutex.unlock();
1177 QPixmap DocClipBase::extractImage(int frame, int width, int height)
1179 if (m_thumbProd == NULL) return QPixmap(width, height);
1180 m_producerMutex.lock();
1181 QPixmap p = m_thumbProd->extractImage(frame, width, height);
1182 m_producerMutex.unlock();