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();
435 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
436 int max = m_baseTrackProducers.count();
437 for (int i = 0; i < max; i++) {
438 kDebug()<<"// CLIP KILL PROD "<<i;
439 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
444 m_baseTrackProducers.insert(i, NULL);
447 delete m_videoOnlyProducer;
448 m_videoOnlyProducer = NULL;
450 qDeleteAll(m_baseTrackProducers);
451 m_baseTrackProducers.clear();
452 qDeleteAll(m_audioTrackProducers);
453 m_audioTrackProducers.clear();
456 void DocClipBase::setValid()
458 m_placeHolder = false;
461 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
463 if (producer == NULL || (m_placeHolder && !reset)) return;
464 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
466 // Clear all previous producers
467 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
468 deleteProducers(false);
470 QString id = producer->get("id");
471 if (id.contains('_')) {
472 // this is a subtrack producer, insert it at correct place
473 id = id.section('_', 1);
474 if (id.endsWith("audio")) {
475 int pos = id.section('_', 0, 0).toInt();
476 if (pos >= m_audioTrackProducers.count()) {
477 while (m_audioTrackProducers.count() - 1 < pos) {
478 m_audioTrackProducers.append(NULL);
481 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
483 } else if (id.endsWith("video")) {
484 m_videoOnlyProducer = producer;
487 int pos = id.toInt();
488 if (pos >= m_baseTrackProducers.count()) {
489 while (m_baseTrackProducers.count() - 1 < pos) {
490 m_baseTrackProducers.append(NULL);
493 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
495 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
496 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
498 //m_clipProducer = producer;
499 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
502 static double getPixelAspect(QMap<QString, QString>& props) {
503 int width = props.value("frame_size").section('x', 0, 0).toInt();
504 int height = props.value("frame_size").section('x', 1, 1).toInt();
505 int aspectNumerator = props.value("force_aspect_num").toInt();
506 int aspectDenominator = props.value("force_aspect_den").toInt();
507 if (aspectDenominator != 0 && width != 0)
508 return double(height) * aspectNumerator / aspectDenominator / width;
513 Mlt::Producer *DocClipBase::audioProducer(int track)
515 if (m_audioTrackProducers.count() <= track) {
516 while (m_audioTrackProducers.count() - 1 < track) {
517 m_audioTrackProducers.append(NULL);
520 if (m_audioTrackProducers.at(track) == NULL) {
521 Mlt::Producer *base = producer();
522 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
523 if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
524 m_audioTrackProducers.at(track)->set("force_aspect_ratio", getPixelAspect(m_properties));
525 if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
526 if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
527 if (m_properties.contains("force_tff")) m_audioTrackProducers.at(track)->set("force_tff", m_properties.value("force_tff").toInt());
528 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
529 m_audioTrackProducers.at(track)->set("video_index", -1);
530 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
531 m_audioTrackProducers.at(track)->set("id", QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
532 if (m_properties.contains("force_colorspace")) m_audioTrackProducers.at(track)->set("force_colorspace", m_properties.value("force_colorspace").toInt());
533 if (m_properties.contains("full_luma")) m_audioTrackProducers.at(track)->set("set.force_full_luma", m_properties.value("full_luma").toInt());
535 return m_audioTrackProducers.at(track);
538 Mlt::Producer *DocClipBase::videoProducer()
540 if (m_videoOnlyProducer == NULL) {
542 for (i = 0; i < m_baseTrackProducers.count(); i++)
543 if (m_baseTrackProducers.at(i) != NULL) break;
544 if (i >= m_baseTrackProducers.count()) return NULL;
545 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
546 if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
547 m_videoOnlyProducer->set("force_aspect_ratio", getPixelAspect(m_properties));
548 if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
549 if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
550 if (m_properties.contains("force_tff")) m_videoOnlyProducer->set("force_tff", m_properties.value("force_tff").toInt());
551 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
552 m_videoOnlyProducer->set("audio_index", -1);
553 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
554 m_videoOnlyProducer->set("id", QString(getId() + "_video").toUtf8().data());
555 if (m_properties.contains("force_colorspace")) m_videoOnlyProducer->set("force_colorspace", m_properties.value("force_colorspace").toInt());
556 if (m_properties.contains("full_luma")) m_videoOnlyProducer->set("set.force_full_luma", m_properties.value("full_luma").toInt());
558 return m_videoOnlyProducer;
561 Mlt::Producer *DocClipBase::producer(int track)
563 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
564 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
566 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
567 if (m_baseTrackProducers.count() == 0) return NULL;
568 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
569 if (m_baseTrackProducers.at(i) != NULL)
570 return m_baseTrackProducers.at(i);
574 if (track >= m_baseTrackProducers.count()) {
575 while (m_baseTrackProducers.count() - 1 < track) {
576 m_baseTrackProducers.append(NULL);
579 if (m_baseTrackProducers.at(track) == NULL) {
581 for (i = 0; i < m_baseTrackProducers.count(); i++)
582 if (m_baseTrackProducers.at(i) != NULL) break;
584 if (i >= m_baseTrackProducers.count()) return NULL;
586 if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
587 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
588 else { // special case for placeholder clips
589 m_baseTrackProducers[track] = NULL;
592 if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
593 m_baseTrackProducers[track]->set("force_aspect_ratio", getPixelAspect(m_properties));
594 if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
595 if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
596 if (m_properties.contains("force_tff")) m_baseTrackProducers[track]->set("force_tff", m_properties.value("force_tff").toInt());
597 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
598 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
599 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
600 m_baseTrackProducers[track]->set("id", QString(getId() + '_' + QString::number(track)).toUtf8().data());
602 if (m_properties.contains("force_colorspace")) m_baseTrackProducers[track]->set("force_colorspace", m_properties.value("force_colorspace").toInt());
603 if (m_properties.contains("full_luma")) m_baseTrackProducers[track]->set("set.force_full_luma", m_properties.value("full_luma").toInt());
605 return m_baseTrackProducers.at(track);
608 void DocClipBase::setProducerProperty(const char *name, int data)
610 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
611 if (m_baseTrackProducers.at(i) != NULL)
612 m_baseTrackProducers[i]->set(name, data);
616 void DocClipBase::setProducerProperty(const char *name, double data)
618 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
619 if (m_baseTrackProducers.at(i) != NULL)
620 m_baseTrackProducers[i]->set(name, data);
624 void DocClipBase::setProducerProperty(const char *name, const char *data)
626 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
627 if (m_baseTrackProducers.at(i) != NULL)
628 m_baseTrackProducers[i]->set(name, data);
632 void DocClipBase::resetProducerProperty(const char *name)
634 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
635 if (m_baseTrackProducers.at(i) != NULL)
636 m_baseTrackProducers[i]->set(name, (const char*) NULL);
640 const char *DocClipBase::producerProperty(const char *name) const
642 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
643 if (m_baseTrackProducers.at(i) != NULL) {
644 return m_baseTrackProducers.at(i)->get(name);
651 void DocClipBase::slotRefreshProducer()
653 if (m_baseTrackProducers.count() == 0) return;
654 if (m_clipType == SLIDESHOW) {
655 /*Mlt::Producer producer(*(m_clipProducer->profile()), getProperty("resource").toUtf8().data());
656 delete m_clipProducer;
657 m_clipProducer = new Mlt::Producer(producer.get_producer());
658 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
659 setProducerProperty("ttl", getProperty("ttl").toInt());
660 //m_clipProducer->set("id", getProperty("id"));
661 if (!getProperty("animation").isEmpty()) {
662 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
664 Mlt::Filter *filter = clipService.filter(ct);
666 if (strcmp(filter->get("mlt_service"), "affine") == 0) {
668 } else if (strcmp(filter->get("mlt_service"), "boxblur") == 0) {
669 clipService.detach(*filter);
671 filter = clipService.filter(ct);
674 if (!filter || strcmp(filter->get("mlt_service"), "affine")) {
675 // filter does not exist, create it.
676 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "affine");
677 if (filter && filter->is_valid()) {
678 int cycle = getProperty("ttl").toInt();
679 QString geometry = SlideshowClip::animationToGeometry(getProperty("animation"), cycle);
680 if (!geometry.isEmpty()) {
681 if (getProperty("animation").contains("low-pass")) {
682 Mlt::Filter *blur = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "boxblur");
683 if (blur && blur->is_valid())
684 clipService.attach(*blur);
686 filter->set("transition.geometry", geometry.toUtf8().data());
687 filter->set("transition.cycle", cycle);
688 clipService.attach(*filter);
693 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
695 Mlt::Filter *filter = clipService.filter(0);
697 if (strcmp(filter->get("mlt_service"), "affine") == 0 || strcmp(filter->get("mlt_service"), "boxblur") == 0) {
698 clipService.detach(*filter);
700 filter = clipService.filter(ct);
703 if (getProperty("fade") == "1") {
704 // we want a fade filter effect
705 kDebug() << "//////////// FADE WANTED";
706 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
708 Mlt::Filter *filter = clipService.filter(ct);
710 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
714 filter = clipService.filter(ct);
717 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
718 filter->set("cycle", getProperty("ttl").toInt());
719 filter->set("duration", getProperty("luma_duration").toInt());
720 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
721 if (!getProperty("softness").isEmpty()) {
722 int soft = getProperty("softness").toInt();
723 filter->set("luma.softness", (double) soft / 100.0);
726 // filter does not exist, create it...
727 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
728 filter->set("cycle", getProperty("ttl").toInt());
729 filter->set("duration", getProperty("luma_duration").toInt());
730 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
731 if (!getProperty("softness").isEmpty()) {
732 int soft = getProperty("softness").toInt();
733 filter->set("luma.softness", (double) soft / 100.0);
735 clipService.attach(*filter);
738 kDebug() << "//////////// FADE NOT WANTED!!!";
739 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
741 Mlt::Filter *filter = clipService.filter(0);
743 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
744 clipService.detach(*filter);
746 filter = clipService.filter(ct);
749 if (getProperty("crop") == "1") {
750 // we want a center crop filter effect
751 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
753 Mlt::Filter *filter = clipService.filter(ct);
755 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
759 filter = clipService.filter(ct);
762 if (!filter || strcmp(filter->get("mlt_service"), "crop")) {
763 // filter does not exist, create it...
764 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "crop");
765 filter->set("center", 1);
766 clipService.attach(*filter);
769 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
771 Mlt::Filter *filter = clipService.filter(0);
773 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
774 clipService.detach(*filter);
776 filter = clipService.filter(ct);
782 void DocClipBase::setProperties(QMap <QString, QString> properties)
784 // changing clip type is not allowed
785 properties.remove("type");
786 QMapIterator<QString, QString> i(properties);
787 bool refreshProducer = false;
789 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness" << "crop" << "animation";
790 while (i.hasNext()) {
792 setProperty(i.key(), i.value());
793 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
795 if (refreshProducer) slotRefreshProducer();
798 void DocClipBase::setMetadata(QMap <QString, QString> properties)
800 QMapIterator<QString, QString> i(properties);
801 while (i.hasNext()) {
803 if (i.value().isEmpty() && m_metadata.contains(i.key())) {
804 m_metadata.remove(i.key());
806 m_metadata.insert(i.key(), i.value());
811 QMap <QString, QString> DocClipBase::metadata() const
816 void DocClipBase::clearProperty(const QString &key)
818 m_properties.remove(key);
821 void DocClipBase::getFileHash(const QString url)
823 if (m_clipType == SLIDESHOW) return;
825 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
828 //kDebug() << "SETTING HASH of" << value;
829 m_properties.insert("file_size", QString::number(file.size()));
831 * 1 MB = 1 second per 450 files (or faster)
832 * 10 MB = 9 seconds per 450 files (or faster)
834 if (file.size() > 1000000*2) {
835 fileData = file.read(1000000);
836 if (file.seek(file.size() - 1000000))
837 fileData.append(file.readAll());
839 fileData = file.readAll();
841 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
842 m_properties.insert("file_hash", QString(fileHash.toHex()));
846 bool DocClipBase::checkHash() const
848 KUrl url = fileURL();
849 if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
853 QString DocClipBase::getClipHash() const
856 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
857 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
858 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
860 if (m_properties.contains("file_hash")) hash = m_properties.value("file_hash");
861 else hash = getHash(fileURL().path());
867 void DocClipBase::setPlaceHolder(bool place)
869 m_placeHolder = place;
873 QString DocClipBase::getHash(const QString &path)
876 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
880 * 1 MB = 1 second per 450 files (or faster)
881 * 10 MB = 9 seconds per 450 files (or faster)
883 if (file.size() > 1000000*2) {
884 fileData = file.read(1000000);
885 if (file.seek(file.size() - 1000000))
886 fileData.append(file.readAll());
888 fileData = file.readAll();
890 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
895 void DocClipBase::refreshThumbUrl()
897 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
900 void DocClipBase::setProperty(const QString &key, const QString &value)
902 m_properties.insert(key, value);
903 if (key == "resource") {
905 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
906 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
907 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
908 else if (key == "colour") {
909 setProducerProperty("colour", value.toUtf8().data());
910 } else if (key == "templatetext") {
911 setProducerProperty("templatetext", value.toUtf8().data());
912 setProducerProperty("force_reload", 1);
913 } else if (key == "xmldata") {
914 setProducerProperty("xmldata", value.toUtf8().data());
915 setProducerProperty("force_reload", 1);
916 } else if (key == "force_aspect_num") {
917 if (value.isEmpty()) {
918 m_properties.remove("force_aspect_num");
919 resetProducerProperty("force_aspect_ratio");
920 } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
921 } else if (key == "force_aspect_den") {
922 if (value.isEmpty()) {
923 m_properties.remove("force_aspect_den");
924 resetProducerProperty("force_aspect_ratio");
925 } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
926 } else if (key == "force_fps") {
927 if (value.isEmpty()) {
928 m_properties.remove("force_fps");
929 resetProducerProperty("force_fps");
930 } else setProducerProperty("force_fps", value.toDouble());
931 } else if (key == "force_progressive") {
932 if (value.isEmpty()) {
933 m_properties.remove("force_progressive");
934 resetProducerProperty("force_progressive");
935 } else setProducerProperty("force_progressive", value.toInt());
936 } else if (key == "force_tff") {
937 if (value.isEmpty()) {
938 m_properties.remove("force_tff");
939 resetProducerProperty("force_tff");
940 } else setProducerProperty("force_tff", value.toInt());
941 } else if (key == "threads") {
942 if (value.isEmpty()) {
943 m_properties.remove("threads");
944 setProducerProperty("threads", 1);
945 } else setProducerProperty("threads", value.toInt());
946 } else if (key == "video_index") {
947 if (value.isEmpty()) {
948 m_properties.remove("video_index");
949 setProducerProperty("video_index", m_properties.value("default_video").toInt());
950 } else setProducerProperty("video_index", value.toInt());
951 } else if (key == "audio_index") {
952 if (value.isEmpty()) {
953 m_properties.remove("audio_index");
954 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
955 } else setProducerProperty("audio_index", value.toInt());
956 } else if (key == "force_colorspace") {
957 if (value.isEmpty()) {
958 m_properties.remove("force_colorspace");
959 resetProducerProperty("force_colorspace");
960 } else setProducerProperty("force_colorspace", value.toInt());
961 } else if (key == "full_luma") {
962 if (value.isEmpty()) {
963 m_properties.remove("full_luma");
964 resetProducerProperty("set.force_full_luma");
965 } else setProducerProperty("set.force_full_luma", value.toInt());
967 else if (key == "proxy") {
968 // If value is "-", that means user manually disabled proxy on this clip
969 if (value.isEmpty() || value == "-") {
971 emit abortProxy(m_id);
974 emit createProxy(m_id);
979 QMap <QString, QString> DocClipBase::properties() const
984 bool DocClipBase::slotGetAudioThumbs()
986 if (m_thumbProd == NULL || isPlaceHolder()) return false;
987 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
988 if (m_audioTimer != NULL) m_audioTimer->stop();
991 if (m_audioThumbCreated) {
992 m_audioTimer->stop();
995 m_audioTimer->start(1500);
996 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
997 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
1001 bool DocClipBase::isPlaceHolder() const
1003 return m_placeHolder;
1006 void DocClipBase::addCutZone(int in, int out, QString desc)
1009 info.zone = QPoint(in, out);
1010 info.description = desc;
1011 for (int i = 0; i < m_cutZones.count(); i++)
1012 if (m_cutZones.at(i).zone == info.zone) {
1015 m_cutZones.append(info);
1018 bool DocClipBase::hasCutZone(QPoint p) const
1020 for (int i = 0; i < m_cutZones.count(); i++)
1021 if (m_cutZones.at(i).zone == p) return true;
1026 void DocClipBase::removeCutZone(int in, int out)
1029 for (int i = 0; i < m_cutZones.count(); i++) {
1030 if (m_cutZones.at(i).zone == p) {
1031 m_cutZones.removeAt(i);
1037 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
1039 QPoint old(oldin, oldout);
1040 for (int i = 0; i < m_cutZones.size(); ++i) {
1041 if (m_cutZones.at(i).zone == old) {
1043 info.zone = QPoint(in, out);
1044 info.description = desc;
1045 m_cutZones.replace(i, info);
1051 QList <CutZoneInfo> DocClipBase::cutZones() const
1056 bool DocClipBase::hasVideoCodec(const QString &codec) const
1058 Mlt::Producer *prod = NULL;
1059 if (m_baseTrackProducers.count() == 0) return false;
1060 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1061 if (m_baseTrackProducers.at(i) != NULL) {
1062 prod = m_baseTrackProducers.at(i);
1067 if (!prod) return false;
1068 int default_video = prod->get_int("video_index");
1070 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1071 return prod->get(property) == codec;
1074 bool DocClipBase::hasAudioCodec(const QString &codec) const
1076 Mlt::Producer *prod = NULL;
1077 if (m_baseTrackProducers.count() == 0) return false;
1078 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1079 if (m_baseTrackProducers.at(i) != NULL) {
1080 prod = m_baseTrackProducers.at(i);
1084 if (!prod) return false;
1085 int default_video = prod->get_int("audio_index");
1087 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1088 return prod->get(property) == codec;