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>
36 #include <QCryptographicHash>
40 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
44 m_baseTrackProducers(),
45 m_audioTrackProducers(),
46 m_videoOnlyProducer(NULL),
47 m_snapMarkers(QList < CommentedTime >()),
51 m_audioThumbCreated(false),
53 m_placeHolder(xml.hasAttribute("placeholder")),
56 int type = xml.attribute("type").toInt();
57 m_clipType = (CLIPTYPE) type;
58 if (m_placeHolder) xml.removeAttribute("placeholder");
59 QDomNamedNodeMap attributes = xml.attributes();
60 for (int i = 0; i < attributes.count(); i++) {
61 QString name = attributes.item(i).nodeName();
62 if (name.startsWith("meta.attr.")) {
63 m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
64 } else m_properties.insert(name, attributes.item(i).nodeValue());
67 if (xml.hasAttribute("cutzones")) {
68 QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
69 for (int i = 0; i < cuts.count(); i++) {
70 QString z = cuts.at(i);
71 addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
75 KUrl url = KUrl(xml.attribute("resource"));
76 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
78 if (xml.hasAttribute("duration")) {
79 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
81 int out = xml.attribute("out").toInt();
82 int in = xml.attribute("in").toInt();
83 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
86 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
88 //if (!url.isEmpty() && QFile::exists(url.path()))
90 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
91 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer();
93 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
96 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
97 DocClipBase::operator=(clip);
99 m_clipType = clip.clipType();
100 m_name = clip.name();
101 m_duration = clip.duration();
102 m_audioThumbCreated = clip.audioThumbCreated();
103 m_properties = clip.properties();
107 DocClipBase::~DocClipBase()
109 kDebug() << "CLIP " << m_id << " DELETED******************************";
112 m_audioTimer->stop();
115 /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
116 if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
117 qDeleteAll(m_baseTrackProducers);
118 m_baseTrackProducers.clear();
119 qDeleteAll(m_audioTrackProducers);
120 m_audioTrackProducers.clear();
121 delete m_videoOnlyProducer;
122 m_videoOnlyProducer = NULL;
125 void DocClipBase::setZone(QPoint zone)
127 m_properties.insert("zone_in", QString::number(zone.x()));
128 m_properties.insert("zone_out", QString::number(zone.y()));
131 QPoint DocClipBase::zone() const
133 QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
137 void DocClipBase::slotCreateAudioTimer()
139 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
140 m_audioTimer = new QTimer(this);
141 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
144 void DocClipBase::askForAudioThumbs()
146 if (m_thumbProd && m_audioTimer) m_thumbProd->askForAudioThumbs(getId());
149 void DocClipBase::slotClearAudioCache()
151 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
152 if (m_audioTimer != NULL) m_audioTimer->stop();
153 m_audioFrameCache.clear();
154 m_audioThumbCreated = false;
157 /*void DocClipBase::getClipMainThumb() {
158 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
161 KThumb *DocClipBase::thumbProducer()
166 bool DocClipBase::audioThumbCreated() const
168 return m_audioThumbCreated;
171 const QString DocClipBase::name() const
174 return m_properties.value("name");
177 const QString &DocClipBase::getId() const
182 void DocClipBase::setId(const QString &newId)
187 const CLIPTYPE & DocClipBase::clipType() const
192 void DocClipBase::setClipType(CLIPTYPE type)
196 m_properties.insert("type", QString::number((int) type));
197 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST))
198 slotCreateAudioTimer();
201 KUrl DocClipBase::fileURL() const
203 QString res = m_properties.value("resource");
204 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
208 void DocClipBase::setClipThumbFrame(const uint &ix)
210 m_properties.insert("thumbnail", QString::number((int) ix));
213 uint DocClipBase::getClipThumbFrame() const
215 return (uint) m_properties.value("thumbnail").toInt();
218 const QString DocClipBase::description() const
220 return m_properties.value("description");
223 bool DocClipBase::isTransparent() const
225 return (m_properties.value("transparency") == "1");
228 const QString DocClipBase::getProperty(const QString prop) const
230 return m_properties.value(prop);
233 void DocClipBase::setDuration(GenTime dur)
236 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
239 const GenTime &DocClipBase::duration() const
244 const GenTime DocClipBase::maxDuration() const
246 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
247 /*const GenTime dur(15000, KdenliveSettings::project_fps());
254 bool DocClipBase::hasFileSize() const
259 qulonglong DocClipBase::fileSize() const
261 return m_properties.value("file_size").toULongLong();
265 QDomElement DocClipBase::toXML() const
268 QDomElement clip = doc.createElement("producer");
270 QMapIterator<QString, QString> i(m_properties);
271 while (i.hasNext()) {
273 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
275 doc.appendChild(clip);
276 if (!m_cutZones.isEmpty()) {
278 for (int i = 0; i < m_cutZones.size(); i++) {
279 CutZoneInfo info = m_cutZones.at(i);
280 cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
282 clip.setAttribute("cutzones", cuts.join(";"));
284 //kDebug() << "/// CLIP XML: " << doc.toString();
285 return doc.documentElement();
289 void DocClipBase::setAudioThumbCreated(bool isDone)
291 m_audioThumbCreated = isDone;
295 void DocClipBase::setThumbnail(const QPixmap & pixmap)
297 m_thumbnail = pixmap;
300 const QPixmap & DocClipBase::thumbnail() const
305 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
307 //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
308 m_audioFrameCache = data;
309 m_audioThumbCreated = true;
313 QList < GenTime > DocClipBase::snapMarkers() const
315 QList < GenTime > markers;
317 for (int count = 0; count < m_snapMarkers.count(); ++count) {
318 markers.append(m_snapMarkers.at(count).time());
324 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
326 return m_snapMarkers;
330 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
332 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
333 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
334 if ((*it).time() >= time)
338 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
339 (*it).setComment(comment);
340 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
342 CommentedTime t(time, comment);
343 m_snapMarkers.insert(it, t);
348 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
350 QList < CommentedTime >::Iterator it;
351 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
352 if ((*it).time() == time)
355 if (it != m_snapMarkers.end()) {
356 (*it).setComment(comment);
358 kError() << "trying to edit Snap Marker that does not already exists";
362 QString DocClipBase::deleteSnapMarker(const GenTime & time)
364 QString result = i18n("Marker");
365 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
367 while (itt != m_snapMarkers.end()) {
368 if ((*itt).time() == time)
373 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
374 result = (*itt).comment();
375 m_snapMarkers.erase(itt);
381 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
383 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
385 while (itt != m_snapMarkers.end()) {
386 if ((*itt).time() == time)
394 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
397 for (it = 0; it < m_snapMarkers.count(); it++) {
398 if (m_snapMarkers.at(it).time() >= currTime)
401 if (it == 0) return GenTime();
402 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
403 return m_snapMarkers.at(it).time();
404 else return m_snapMarkers.at(it - 1).time();
407 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
410 for (it = 0; it < m_snapMarkers.count(); it++) {
411 if (m_snapMarkers.at(it).time() > currTime)
414 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
418 QString DocClipBase::markerComment(GenTime t)
420 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
422 while (itt != m_snapMarkers.end()) {
423 if ((*itt).time() == t)
424 return (*itt).comment();
430 void DocClipBase::clearProducers()
432 m_baseTrackProducers.clear();
435 void DocClipBase::deleteProducers(bool clearThumbCreator)
437 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
438 if (clearThumbCreator && m_thumbProd) m_thumbProd->clearProducer();
439 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
440 int max = m_baseTrackProducers.count();
441 for (int i = 0; i < max; i++) {
442 kDebug()<<"// CLIP KILL PROD "<<i;
443 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
448 m_baseTrackProducers.insert(i, NULL);
451 delete m_videoOnlyProducer;
452 m_videoOnlyProducer = NULL;
454 qDeleteAll(m_baseTrackProducers);
455 m_baseTrackProducers.clear();
456 qDeleteAll(m_audioTrackProducers);
457 m_audioTrackProducers.clear();
460 void DocClipBase::setValid()
462 m_placeHolder = false;
465 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
467 if (producer == NULL || (m_placeHolder && !reset)) return;
468 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
470 // Clear all previous producers
471 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
472 deleteProducers(false);
474 QString id = producer->get("id");
475 if (id.contains('_')) {
476 // this is a subtrack producer, insert it at correct place
477 id = id.section('_', 1);
478 if (id.endsWith("audio")) {
479 int pos = id.section('_', 0, 0).toInt();
480 if (pos >= m_audioTrackProducers.count()) {
481 while (m_audioTrackProducers.count() - 1 < pos) {
482 m_audioTrackProducers.append(NULL);
485 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
487 } else if (id.endsWith("video")) {
488 m_videoOnlyProducer = producer;
491 int pos = id.toInt();
492 if (pos >= m_baseTrackProducers.count()) {
493 while (m_baseTrackProducers.count() - 1 < pos) {
494 m_baseTrackProducers.append(NULL);
497 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
499 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
500 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
502 //m_clipProducer = producer;
503 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
506 static double getPixelAspect(QMap<QString, QString>& props) {
507 int width = props.value("frame_size").section('x', 0, 0).toInt();
508 int height = props.value("frame_size").section('x', 1, 1).toInt();
509 int aspectNumerator = props.value("force_aspect_num").toInt();
510 int aspectDenominator = props.value("force_aspect_den").toInt();
511 if (aspectDenominator != 0 && width != 0)
512 return double(height) * aspectNumerator / aspectDenominator / width;
517 Mlt::Producer *DocClipBase::audioProducer(int track)
519 if (m_audioTrackProducers.count() <= track) {
520 while (m_audioTrackProducers.count() - 1 < track) {
521 m_audioTrackProducers.append(NULL);
524 if (m_audioTrackProducers.at(track) == NULL) {
525 Mlt::Producer *base = producer();
526 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
527 if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
528 m_audioTrackProducers.at(track)->set("force_aspect_ratio", getPixelAspect(m_properties));
529 if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
530 if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
531 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
532 m_audioTrackProducers.at(track)->set("video_index", -1);
533 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
534 m_audioTrackProducers.at(track)->set("id", QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
535 if (m_properties.contains("force_colorspace")) m_audioTrackProducers.at(track)->set("force_colorspace", m_properties.value("force_colorspace").toInt());
536 if (m_properties.contains("full_luma")) m_audioTrackProducers.at(track)->set("set.force_full_luma", m_properties.value("full_luma").toInt());
538 return m_audioTrackProducers.at(track);
541 Mlt::Producer *DocClipBase::videoProducer()
543 if (m_videoOnlyProducer == NULL) {
545 for (i = 0; i < m_baseTrackProducers.count(); i++)
546 if (m_baseTrackProducers.at(i) != NULL) break;
547 if (i >= m_baseTrackProducers.count()) return NULL;
548 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
549 if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
550 m_videoOnlyProducer->set("force_aspect_ratio", getPixelAspect(m_properties));
551 if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
552 if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
553 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
554 m_videoOnlyProducer->set("audio_index", -1);
555 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
556 m_videoOnlyProducer->set("id", QString(getId() + "_video").toUtf8().data());
557 if (m_properties.contains("force_colorspace")) m_videoOnlyProducer->set("force_colorspace", m_properties.value("force_colorspace").toInt());
558 if (m_properties.contains("full_luma")) m_videoOnlyProducer->set("set.force_full_luma", m_properties.value("full_luma").toInt());
560 return m_videoOnlyProducer;
563 Mlt::Producer *DocClipBase::producer(int track)
565 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
566 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
568 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
569 if (m_baseTrackProducers.count() == 0) return NULL;
570 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
571 if (m_baseTrackProducers.at(i) != NULL)
572 return m_baseTrackProducers.at(i);
576 if (track >= m_baseTrackProducers.count()) {
577 while (m_baseTrackProducers.count() - 1 < track) {
578 m_baseTrackProducers.append(NULL);
581 if (m_baseTrackProducers.at(track) == NULL) {
583 for (i = 0; i < m_baseTrackProducers.count(); i++)
584 if (m_baseTrackProducers.at(i) != NULL) break;
586 if (i >= m_baseTrackProducers.count()) return NULL;
588 if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
589 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
590 else { // special case for placeholder clips
591 m_baseTrackProducers[track] = NULL;
594 if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
595 m_baseTrackProducers[track]->set("force_aspect_raio", getPixelAspect(m_properties));
596 if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
597 if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
598 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
599 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
600 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
601 m_baseTrackProducers[track]->set("id", QString(getId() + '_' + QString::number(track)).toUtf8().data());
602 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
603 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
604 m_baseTrackProducers[track]->set("skip_frame", "bidir");
606 if (m_properties.contains("force_colorspace")) m_baseTrackProducers[track]->set("force_colorspace", m_properties.value("force_colorspace").toInt());
607 if (m_properties.contains("full_luma")) m_baseTrackProducers[track]->set("set.force_full_luma", m_properties.value("full_luma").toInt());
609 return m_baseTrackProducers.at(track);
612 void DocClipBase::setProducerProperty(const char *name, int data)
614 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
615 if (m_baseTrackProducers.at(i) != NULL)
616 m_baseTrackProducers[i]->set(name, data);
620 void DocClipBase::setProducerProperty(const char *name, double data)
622 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
623 if (m_baseTrackProducers.at(i) != NULL)
624 m_baseTrackProducers[i]->set(name, data);
628 void DocClipBase::setProducerProperty(const char *name, const char *data)
630 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
631 if (m_baseTrackProducers.at(i) != NULL)
632 m_baseTrackProducers[i]->set(name, data);
636 void DocClipBase::resetProducerProperty(const char *name)
638 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
639 if (m_baseTrackProducers.at(i) != NULL)
640 m_baseTrackProducers[i]->set(name, (const char*) NULL);
644 const char *DocClipBase::producerProperty(const char *name) const
646 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
647 if (m_baseTrackProducers.at(i) != NULL) {
648 return m_baseTrackProducers.at(i)->get(name);
655 void DocClipBase::slotRefreshProducer()
657 if (m_baseTrackProducers.count() == 0) return;
658 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
659 if (m_clipType == SLIDESHOW) {
660 /*Mlt::Producer producer(*(m_clipProducer->profile()), getProperty("resource").toUtf8().data());
661 delete m_clipProducer;
662 m_clipProducer = new Mlt::Producer(producer.get_producer());
663 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
664 setProducerProperty("ttl", getProperty("ttl").toInt());
665 //m_clipProducer->set("id", getProperty("id"));
666 if (!getProperty("animation").isEmpty()) {
667 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
669 Mlt::Filter *filter = clipService.filter(ct);
671 if (strcmp(filter->get("mlt_service"), "affine") == 0) {
673 } else if (strcmp(filter->get("mlt_service"), "boxblur") == 0) {
674 clipService.detach(*filter);
676 filter = clipService.filter(ct);
679 if (!filter || strcmp(filter->get("mlt_service"), "affine")) {
680 // filter does not exist, create it.
681 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "affine");
682 if (filter && filter->is_valid()) {
683 int cycle = getProperty("ttl").toInt();
684 QString geometry = SlideshowClip::animationToGeometry(getProperty("animation"), cycle);
685 if (!geometry.isEmpty()) {
686 if (getProperty("animation").contains("low-pass")) {
687 Mlt::Filter *blur = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "boxblur");
688 if (blur && blur->is_valid())
689 clipService.attach(*blur);
691 filter->set("transition.geometry", geometry.toUtf8().data());
692 filter->set("transition.cycle", cycle);
693 clipService.attach(*filter);
698 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
700 Mlt::Filter *filter = clipService.filter(0);
702 if (strcmp(filter->get("mlt_service"), "affine") == 0 || strcmp(filter->get("mlt_service"), "boxblur") == 0) {
703 clipService.detach(*filter);
705 filter = clipService.filter(ct);
708 if (getProperty("fade") == "1") {
709 // we want a fade filter effect
710 kDebug() << "//////////// FADE WANTED";
711 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
713 Mlt::Filter *filter = clipService.filter(ct);
715 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
719 filter = clipService.filter(ct);
722 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
723 filter->set("cycle", getProperty("ttl").toInt());
724 filter->set("duration", getProperty("luma_duration").toInt());
725 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
726 if (!getProperty("softness").isEmpty()) {
727 int soft = getProperty("softness").toInt();
728 filter->set("luma.softness", (double) soft / 100.0);
731 // filter does not exist, create it...
732 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
733 filter->set("cycle", getProperty("ttl").toInt());
734 filter->set("duration", getProperty("luma_duration").toInt());
735 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
736 if (!getProperty("softness").isEmpty()) {
737 int soft = getProperty("softness").toInt();
738 filter->set("luma.softness", (double) soft / 100.0);
740 clipService.attach(*filter);
743 kDebug() << "//////////// FADE NOT WANTED!!!";
744 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
746 Mlt::Filter *filter = clipService.filter(0);
748 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
749 clipService.detach(*filter);
751 filter = clipService.filter(ct);
754 if (getProperty("crop") == "1") {
755 // we want a center crop filter effect
756 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
758 Mlt::Filter *filter = clipService.filter(ct);
760 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
764 filter = clipService.filter(ct);
767 if (!filter || strcmp(filter->get("mlt_service"), "crop")) {
768 // filter does not exist, create it...
769 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "crop");
770 filter->set("center", 1);
771 clipService.attach(*filter);
774 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
776 Mlt::Filter *filter = clipService.filter(0);
778 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
779 clipService.detach(*filter);
781 filter = clipService.filter(ct);
787 void DocClipBase::setProperties(QMap <QString, QString> properties)
789 // changing clip type is not allowed
790 properties.remove("type");
791 QMapIterator<QString, QString> i(properties);
792 bool refreshProducer = false;
794 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness" << "crop" << "animation";
795 while (i.hasNext()) {
797 setProperty(i.key(), i.value());
798 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
800 if (refreshProducer) slotRefreshProducer();
803 void DocClipBase::setMetadata(QMap <QString, QString> properties)
805 QMapIterator<QString, QString> i(properties);
806 while (i.hasNext()) {
808 if (i.value().isEmpty() && m_metadata.contains(i.key())) {
809 m_metadata.remove(i.key());
811 m_metadata.insert(i.key(), i.value());
816 QMap <QString, QString> DocClipBase::metadata() const
821 void DocClipBase::clearProperty(const QString &key)
823 m_properties.remove(key);
826 void DocClipBase::getFileHash(const QString url)
828 if (m_clipType == SLIDESHOW) return;
830 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
833 //kDebug() << "SETTING HASH of" << value;
834 m_properties.insert("file_size", QString::number(file.size()));
836 * 1 MB = 1 second per 450 files (or faster)
837 * 10 MB = 9 seconds per 450 files (or faster)
839 if (file.size() > 1000000*2) {
840 fileData = file.read(1000000);
841 if (file.seek(file.size() - 1000000))
842 fileData.append(file.readAll());
844 fileData = file.readAll();
846 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
847 m_properties.insert("file_hash", QString(fileHash.toHex()));
851 bool DocClipBase::checkHash() const
853 KUrl url = fileURL();
854 if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
858 QString DocClipBase::getClipHash() const
861 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
862 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
863 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
864 else hash = m_properties.value("file_hash");
868 void DocClipBase::setPlaceHolder(bool place)
870 m_placeHolder = place;
874 QString DocClipBase::getHash(const QString &path)
877 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
881 * 1 MB = 1 second per 450 files (or faster)
882 * 10 MB = 9 seconds per 450 files (or faster)
884 if (file.size() > 1000000*2) {
885 fileData = file.read(1000000);
886 if (file.seek(file.size() - 1000000))
887 fileData.append(file.readAll());
889 fileData = file.readAll();
891 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
896 void DocClipBase::refreshThumbUrl()
898 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
901 void DocClipBase::setProperty(const QString &key, const QString &value)
903 m_properties.insert(key, value);
904 if (key == "resource") {
906 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
907 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
908 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
909 else if (key == "colour") {
910 setProducerProperty("colour", value.toUtf8().data());
911 } else if (key == "templatetext") {
912 setProducerProperty("templatetext", value.toUtf8().data());
913 setProducerProperty("force_reload", 1);
914 } else if (key == "xmldata") {
915 setProducerProperty("xmldata", value.toUtf8().data());
916 setProducerProperty("force_reload", 1);
917 } else if (key == "force_aspect_num") {
918 if (value.isEmpty()) {
919 m_properties.remove("force_aspect_num");
920 resetProducerProperty("force_aspect_ratio");
921 } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
922 } else if (key == "force_aspect_den") {
923 if (value.isEmpty()) {
924 m_properties.remove("force_aspect_den");
925 resetProducerProperty("force_aspect_ratio");
926 } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
927 } else if (key == "force_fps") {
928 if (value.isEmpty()) {
929 m_properties.remove("force_fps");
930 resetProducerProperty("force_fps");
931 } else setProducerProperty("force_fps", value.toDouble());
932 } else if (key == "force_progressive") {
933 if (value.isEmpty()) {
934 m_properties.remove("force_progressive");
935 resetProducerProperty("force_progressive");
936 } else setProducerProperty("force_progressive", value.toInt());
937 } else if (key == "threads") {
938 if (value.isEmpty()) {
939 m_properties.remove("threads");
940 setProducerProperty("threads", 1);
941 } else setProducerProperty("threads", value.toInt());
942 } else if (key == "video_index") {
943 if (value.isEmpty()) {
944 m_properties.remove("video_index");
945 setProducerProperty("video_index", m_properties.value("default_video").toInt());
946 } else setProducerProperty("video_index", value.toInt());
947 } else if (key == "audio_index") {
948 if (value.isEmpty()) {
949 m_properties.remove("audio_index");
950 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
951 } else setProducerProperty("audio_index", value.toInt());
952 } else if (key == "force_colorspace") {
953 if (value.isEmpty()) {
954 m_properties.remove("force_colorspace");
955 resetProducerProperty("force_colorspace");
956 } else setProducerProperty("force_colorspace", value.toInt());
957 } else if (key == "full_luma") {
958 if (value.isEmpty()) {
959 m_properties.remove("full_luma");
960 resetProducerProperty("set.force_full_luma");
961 } else setProducerProperty("set.force_full_luma", value.toInt());
965 QMap <QString, QString> DocClipBase::properties() const
970 bool DocClipBase::slotGetAudioThumbs()
972 if (m_thumbProd == NULL || isPlaceHolder()) return false;
973 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
974 if (m_audioTimer != NULL) m_audioTimer->stop();
977 if (m_audioThumbCreated) {
978 m_audioTimer->stop();
981 m_audioTimer->start(1500);
982 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
983 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
987 bool DocClipBase::isPlaceHolder() const
989 return m_placeHolder;
992 void DocClipBase::addCutZone(int in, int out, QString desc)
995 info.zone = QPoint(in, out);
996 info.description = desc;
997 for (int i = 0; i < m_cutZones.count(); i++)
998 if (m_cutZones.at(i).zone == info.zone) {
1001 m_cutZones.append(info);
1004 bool DocClipBase::hasCutZone(QPoint p) const
1006 for (int i = 0; i < m_cutZones.count(); i++)
1007 if (m_cutZones.at(i).zone == p) return true;
1012 void DocClipBase::removeCutZone(int in, int out)
1015 for (int i = 0; i < m_cutZones.count(); i++) {
1016 if (m_cutZones.at(i).zone == p) {
1017 m_cutZones.removeAt(i);
1023 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
1025 QPoint old(oldin, oldout);
1026 for (int i = 0; i < m_cutZones.size(); ++i) {
1027 if (m_cutZones.at(i).zone == old) {
1029 info.zone = QPoint(in, out);
1030 info.description = desc;
1031 m_cutZones.replace(i, info);
1037 QList <CutZoneInfo> DocClipBase::cutZones() const
1042 bool DocClipBase::hasVideoCodec(const QString &codec) const
1044 Mlt::Producer *prod = NULL;
1045 if (m_baseTrackProducers.count() == 0) return false;
1046 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1047 if (m_baseTrackProducers.at(i) != NULL) {
1048 prod = m_baseTrackProducers.at(i);
1053 if (!prod) return false;
1054 int default_video = prod->get_int("video_index");
1056 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1057 return prod->get(property) == codec;
1060 bool DocClipBase::hasAudioCodec(const QString &codec) const
1062 Mlt::Producer *prod = NULL;
1063 if (m_baseTrackProducers.count() == 0) return false;
1064 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1065 if (m_baseTrackProducers.at(i) != NULL) {
1066 prod = m_baseTrackProducers.at(i);
1070 if (!prod) return false;
1071 int default_video = prod->get_int("audio_index");
1073 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1074 return prod->get(property) == codec;