1 /***************************************************************************
2 * DocClipBase.cpp - description *
3 * ------------------- *
4 * begin : Fri Apr 12 2002 *
5 * Copyright (C) 2002 by Jason Wood (jasonwood@blueyonder.co.uk) *
6 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
22 ***************************************************************************/
27 #include "docclipbase.h"
28 #include "kdenlivesettings.h"
30 #include "clipmanager.h"
32 #include <KIO/NetAccess>
35 #include <QCryptographicHash>
39 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
43 m_baseTrackProducers(),
44 m_audioTrackProducers(),
45 m_videoOnlyProducer(NULL),
46 m_snapMarkers(QList < CommentedTime >()),
50 m_audioThumbCreated(false),
52 m_placeHolder(xml.hasAttribute("placeholder")),
55 int type = xml.attribute("type").toInt();
56 m_clipType = (CLIPTYPE) type;
57 if (m_placeHolder) xml.removeAttribute("placeholder");
58 QDomNamedNodeMap attributes = xml.attributes();
59 for (int i = 0; i < attributes.count(); i++) {
60 m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
63 if (xml.hasAttribute("cutzones")) {
64 QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
65 for (int i = 0; i < cuts.count(); i++) {
66 QString z = cuts.at(i);
67 addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
71 KUrl url = KUrl(xml.attribute("resource"));
72 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
74 if (xml.hasAttribute("duration")) {
75 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
77 int out = xml.attribute("out").toInt();
78 int in = xml.attribute("in").toInt();
79 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
82 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
84 //if (!url.isEmpty() && QFile::exists(url.path()))
86 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
87 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer();
89 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
92 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
93 DocClipBase::operator=(clip);
95 m_clipType = clip.clipType();
97 m_duration = clip.duration();
98 m_audioThumbCreated = clip.audioThumbCreated();
99 m_properties = clip.properties();
103 DocClipBase::~DocClipBase()
105 kDebug() << "CLIP " << m_id << " DELETED******************************";
108 m_audioTimer->stop();
111 /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
112 if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
113 qDeleteAll(m_baseTrackProducers);
114 m_baseTrackProducers.clear();
115 qDeleteAll(m_audioTrackProducers);
116 m_audioTrackProducers.clear();
117 delete m_videoOnlyProducer;
118 m_videoOnlyProducer = NULL;
121 void DocClipBase::setZone(QPoint zone)
123 m_properties.insert("zone_in", QString::number(zone.x()));
124 m_properties.insert("zone_out", QString::number(zone.y()));
127 QPoint DocClipBase::zone() const
130 zone.setX(m_properties.value("zone_in").toInt());
131 zone.setY(m_properties.value("zone_out", "50").toInt());
135 void DocClipBase::slotCreateAudioTimer()
137 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
138 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
139 m_audioTimer = new QTimer(this);
140 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
143 void DocClipBase::askForAudioThumbs()
145 if (m_thumbProd && m_audioTimer) slotGetAudioThumbs();
148 void DocClipBase::slotClearAudioCache()
150 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
151 if (m_audioTimer != NULL) m_audioTimer->stop();
152 m_audioFrameCache.clear();
153 m_audioThumbCreated = false;
156 /*void DocClipBase::getClipMainThumb() {
157 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
160 KThumb *DocClipBase::thumbProducer()
165 bool DocClipBase::audioThumbCreated() const
167 return m_audioThumbCreated;
170 const QString DocClipBase::name() const
173 return m_properties.value("name");
176 const QString &DocClipBase::getId() const
181 void DocClipBase::setId(const QString &newId)
186 const CLIPTYPE & DocClipBase::clipType() const
191 void DocClipBase::setClipType(CLIPTYPE type)
195 m_properties.insert("type", QString::number((int) type));
196 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST))
197 slotCreateAudioTimer();
200 KUrl DocClipBase::fileURL() const
202 QString res = m_properties.value("resource");
203 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
207 void DocClipBase::setClipThumbFrame(const uint &ix)
209 m_properties.insert("thumbnail", QString::number((int) ix));
212 uint DocClipBase::getClipThumbFrame() const
214 return (uint) m_properties.value("thumbnail").toInt();
217 const QString DocClipBase::description() const
219 return m_properties.value("description");
222 bool DocClipBase::isTransparent() const
224 return (m_properties.value("transparency") == "1");
227 const QString DocClipBase::getProperty(const QString prop) const
229 return m_properties.value(prop);
232 void DocClipBase::setDuration(GenTime dur)
235 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
238 const GenTime &DocClipBase::duration() const
243 const GenTime DocClipBase::maxDuration() const
245 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
246 /*const GenTime dur(15000, KdenliveSettings::project_fps());
253 bool DocClipBase::hasFileSize() const
258 qulonglong DocClipBase::fileSize() const
260 return m_properties.value("file_size").toULongLong();
264 QDomElement DocClipBase::toXML() const
267 QDomElement clip = doc.createElement("producer");
269 QMapIterator<QString, QString> i(m_properties);
270 while (i.hasNext()) {
272 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
274 doc.appendChild(clip);
275 if (!m_cutZones.isEmpty()) {
277 for (int i = 0; i < m_cutZones.size(); i++) {
278 CutZoneInfo info = m_cutZones.at(i);
279 cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
281 clip.setAttribute("cutzones", cuts.join(";"));
283 //kDebug() << "/// CLIP XML: " << doc.toString();
284 return doc.documentElement();
288 void DocClipBase::setAudioThumbCreated(bool isDone)
290 m_audioThumbCreated = isDone;
294 void DocClipBase::setThumbnail(const QPixmap & pixmap)
296 m_thumbnail = pixmap;
299 const QPixmap & DocClipBase::thumbnail() const
304 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
306 //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
307 m_audioFrameCache = data;
308 m_audioThumbCreated = true;
312 QList < GenTime > DocClipBase::snapMarkers() const
314 QList < GenTime > markers;
316 for (int count = 0; count < m_snapMarkers.count(); ++count) {
317 markers.append(m_snapMarkers.at(count).time());
323 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
325 return m_snapMarkers;
329 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
331 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
332 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
333 if ((*it).time() >= time)
337 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
338 (*it).setComment(comment);
339 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
341 CommentedTime t(time, comment);
342 m_snapMarkers.insert(it, t);
347 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
349 QList < CommentedTime >::Iterator it;
350 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
351 if ((*it).time() == time)
354 if (it != m_snapMarkers.end()) {
355 (*it).setComment(comment);
357 kError() << "trying to edit Snap Marker that does not already exists";
361 QString DocClipBase::deleteSnapMarker(const GenTime & time)
363 QString result = i18n("Marker");
364 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
366 while (itt != m_snapMarkers.end()) {
367 if ((*itt).time() == time)
372 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
373 result = (*itt).comment();
374 m_snapMarkers.erase(itt);
380 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
382 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
384 while (itt != m_snapMarkers.end()) {
385 if ((*itt).time() == time)
393 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
396 for (it = 0; it < m_snapMarkers.count(); it++) {
397 if (m_snapMarkers.at(it).time() >= currTime)
400 if (it == 0) return GenTime();
401 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
402 return m_snapMarkers.at(it).time();
403 else return m_snapMarkers.at(it - 1).time();
406 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
409 for (it = 0; it < m_snapMarkers.count(); it++) {
410 if (m_snapMarkers.at(it).time() > currTime)
413 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
417 QString DocClipBase::markerComment(GenTime t)
419 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
421 while (itt != m_snapMarkers.end()) {
422 if ((*itt).time() == t)
423 return (*itt).comment();
429 void DocClipBase::clearProducers()
431 m_baseTrackProducers.clear();
434 void DocClipBase::deleteProducers()
436 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
437 if (m_thumbProd) m_thumbProd->clearProducer();
438 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
439 int max = m_baseTrackProducers.count();
440 for (int i = 0; i < max; i++) {
441 kDebug()<<"// CLIP KILL PROD "<<i;
442 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
447 m_baseTrackProducers.insert(i, NULL);
450 delete m_videoOnlyProducer;
451 m_videoOnlyProducer = NULL;
453 qDeleteAll(m_baseTrackProducers);
454 m_baseTrackProducers.clear();
455 qDeleteAll(m_audioTrackProducers);
456 m_audioTrackProducers.clear();
459 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
461 if (producer == NULL || m_placeHolder) return;
463 // Clear all previous producers
464 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
467 QString id = producer->get("id");
468 if (id.contains('_')) {
469 // this is a subtrack producer, insert it at correct place
470 id = id.section('_', 1);
471 if (id.endsWith("audio")) {
472 int pos = id.section('_', 0, 0).toInt();
473 if (pos >= m_audioTrackProducers.count()) {
474 while (m_audioTrackProducers.count() - 1 < pos) {
475 m_audioTrackProducers.append(NULL);
478 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
480 } else if (id.endsWith("video")) {
481 m_videoOnlyProducer = producer;
484 int pos = id.toInt();
485 if (pos >= m_baseTrackProducers.count()) {
486 while (m_baseTrackProducers.count() - 1 < pos) {
487 m_baseTrackProducers.append(NULL);
490 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
492 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
493 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
495 //m_clipProducer = producer;
496 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
497 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
500 Mlt::Producer *DocClipBase::audioProducer(int track)
502 if (m_audioTrackProducers.count() <= track) {
503 while (m_audioTrackProducers.count() - 1 < track) {
504 m_audioTrackProducers.append(NULL);
507 if (m_audioTrackProducers.at(track) == NULL) {
508 Mlt::Producer *base = producer();
509 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
510 if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
511 if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
512 if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
513 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
514 m_audioTrackProducers.at(track)->set("video_index", -1);
515 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
516 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
517 m_audioTrackProducers.at(track)->set("id", tmp);
520 return m_audioTrackProducers.at(track);
523 Mlt::Producer *DocClipBase::videoProducer()
525 if (m_videoOnlyProducer == NULL) {
527 for (i = 0; i < m_baseTrackProducers.count(); i++)
528 if (m_baseTrackProducers.at(i) != NULL) break;
529 if (i >= m_baseTrackProducers.count()) return NULL;
530 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
531 if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
532 if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
533 if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
534 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
535 m_videoOnlyProducer->set("audio_index", -1);
536 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
537 char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
538 m_videoOnlyProducer->set("id", tmp);
541 return m_videoOnlyProducer;
544 Mlt::Producer *DocClipBase::producer(int track)
546 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
547 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
549 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
550 if (m_baseTrackProducers.count() == 0) return NULL;
551 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
552 if (m_baseTrackProducers.at(i) != NULL)
553 return m_baseTrackProducers.at(i);
557 if (track >= m_baseTrackProducers.count()) {
558 while (m_baseTrackProducers.count() - 1 < track) {
559 m_baseTrackProducers.append(NULL);
562 if (m_baseTrackProducers.at(track) == NULL) {
564 for (i = 0; i < m_baseTrackProducers.count(); i++)
565 if (m_baseTrackProducers.at(i) != NULL) break;
567 if (i >= m_baseTrackProducers.count()) return NULL;
569 if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
570 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
571 else { // special case for placeholder clips
572 m_baseTrackProducers[track] = NULL;
576 if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
577 if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
578 if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
579 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
580 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
581 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
582 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
583 m_baseTrackProducers[track]->set("id", tmp);
585 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
586 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
587 m_baseTrackProducers[track]->set("skip_frame", "bidir");
590 return m_baseTrackProducers.at(track);
593 void DocClipBase::setProducerProperty(const char *name, int data)
595 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
596 if (m_baseTrackProducers.at(i) != NULL)
597 m_baseTrackProducers[i]->set(name, data);
601 void DocClipBase::setProducerProperty(const char *name, double data)
603 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
604 if (m_baseTrackProducers.at(i) != NULL)
605 m_baseTrackProducers[i]->set(name, data);
609 void DocClipBase::setProducerProperty(const char *name, const char *data)
611 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
612 if (m_baseTrackProducers.at(i) != NULL)
613 m_baseTrackProducers[i]->set(name, data);
617 void DocClipBase::resetProducerProperty(const char *name)
619 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
620 if (m_baseTrackProducers.at(i) != NULL)
621 m_baseTrackProducers[i]->set(name, (const char*) NULL);
625 const char *DocClipBase::producerProperty(const char *name) const
627 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
628 if (m_baseTrackProducers.at(i) != NULL) {
629 return m_baseTrackProducers.at(i)->get(name);
636 void DocClipBase::slotRefreshProducer()
638 if (m_baseTrackProducers.count() == 0) return;
639 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
640 if (m_clipType == SLIDESHOW) {
641 /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
642 Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
644 delete m_clipProducer;
645 m_clipProducer = new Mlt::Producer(producer.get_producer());
646 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
647 setProducerProperty("ttl", getProperty("ttl").toInt());
648 //m_clipProducer->set("id", getProperty("id"));
649 if (getProperty("fade") == "1") {
650 // we want a fade filter effect
651 kDebug() << "//////////// FADE WANTED";
652 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
654 Mlt::Filter *filter = clipService.filter(ct);
656 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
660 filter = clipService.filter(ct);
663 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
664 filter->set("period", getProperty("ttl").toInt() - 1);
665 filter->set("luma.out", getProperty("luma_duration").toInt());
666 QString resource = getProperty("luma_file");
667 char *tmp = (char *) qstrdup(resource.toUtf8().data());
668 filter->set("luma.resource", tmp);
670 if (!getProperty("softness").isEmpty()) {
671 int soft = getProperty("softness").toInt();
672 filter->set("luma.softness", (double) soft / 100.0);
675 // filter does not exist, create it...
676 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
677 filter->set("period", getProperty("ttl").toInt() - 1);
678 filter->set("luma.out", getProperty("luma_duration").toInt());
679 QString resource = getProperty("luma_file");
680 char *tmp = (char *) qstrdup(resource.toUtf8().data());
681 filter->set("luma.resource", tmp);
683 if (!getProperty("softness").isEmpty()) {
684 int soft = getProperty("softness").toInt();
685 filter->set("luma.softness", (double) soft / 100.0);
687 clipService.attach(*filter);
690 kDebug() << "//////////// FADE NOT WANTED!!!";
691 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
693 Mlt::Filter *filter = clipService.filter(0);
695 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
696 clipService.detach(*filter);
698 filter = clipService.filter(ct);
704 void DocClipBase::setProperties(QMap <QString, QString> properties)
706 // changing clip type is not allowed
707 properties.remove("type");
708 QMapIterator<QString, QString> i(properties);
709 bool refreshProducer = false;
711 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
712 while (i.hasNext()) {
714 setProperty(i.key(), i.value());
715 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
717 if (refreshProducer) slotRefreshProducer();
720 void DocClipBase::setMetadata(QMap <QString, QString> properties)
722 m_metadata = properties;
725 QMap <QString, QString> DocClipBase::metadata() const
730 void DocClipBase::clearProperty(const QString &key)
732 m_properties.remove(key);
735 void DocClipBase::getFileHash(const QString url)
737 if (m_clipType == SLIDESHOW) return;
739 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
742 //kDebug() << "SETTING HASH of" << value;
743 m_properties.insert("file_size", QString::number(file.size()));
745 * 1 MB = 1 second per 450 files (or faster)
746 * 10 MB = 9 seconds per 450 files (or faster)
748 if (file.size() > 1000000*2) {
749 fileData = file.read(1000000);
750 if (file.seek(file.size() - 1000000))
751 fileData.append(file.readAll());
753 fileData = file.readAll();
755 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
756 m_properties.insert("file_hash", QString(fileHash.toHex()));
760 QString DocClipBase::getClipHash() const
763 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
764 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
765 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
766 else hash = m_properties.value("file_hash");
771 QString DocClipBase::getHash(const QString &path)
774 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
778 * 1 MB = 1 second per 450 files (or faster)
779 * 10 MB = 9 seconds per 450 files (or faster)
781 if (file.size() > 1000000*2) {
782 fileData = file.read(1000000);
783 if (file.seek(file.size() - 1000000))
784 fileData.append(file.readAll());
786 fileData = file.readAll();
788 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
793 void DocClipBase::refreshThumbUrl()
795 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
798 void DocClipBase::setProperty(const QString &key, const QString &value)
800 m_properties.insert(key, value);
801 if (key == "resource") {
803 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
804 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
805 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
806 else if (key == "colour") {
807 char *tmp = (char *) qstrdup(value.toUtf8().data());
808 setProducerProperty("colour", tmp);
810 } else if (key == "templatetext") {
811 char *tmp = (char *) qstrdup(value.toUtf8().data());
812 setProducerProperty("templatetext", tmp);
814 setProducerProperty("force_reload", 1);
815 } else if (key == "xmldata") {
816 char *tmp = (char *) qstrdup(value.toUtf8().data());
817 setProducerProperty("xmldata", tmp);
819 setProducerProperty("force_reload", 1);
820 } else if (key == "force_aspect_ratio") {
821 if (value.isEmpty()) {
822 m_properties.remove("force_aspect_ratio");
823 resetProducerProperty("force_aspect_ratio");
824 } else setProducerProperty("force_aspect_ratio", value.toDouble());
825 } else if (key == "force_fps") {
826 if (value.isEmpty()) {
827 m_properties.remove("force_fps");
828 resetProducerProperty("force_fps");
829 } else setProducerProperty("force_fps", value.toDouble());
830 } else if (key == "force_progressive") {
831 if (value.isEmpty()) {
832 m_properties.remove("force_progressive");
833 resetProducerProperty("force_progressive");
834 } else setProducerProperty("force_progressive", value.toInt());
835 } else if (key == "threads") {
836 if (value.isEmpty()) {
837 m_properties.remove("threads");
838 setProducerProperty("threads", 1);
839 } else setProducerProperty("threads", value.toInt());
840 } else if (key == "video_index") {
841 if (value.isEmpty()) {
842 m_properties.remove("video_index");
843 setProducerProperty("video_index", m_properties.value("default_video").toInt());
844 } else setProducerProperty("video_index", value.toInt());
845 } else if (key == "audio_index") {
846 if (value.isEmpty()) {
847 m_properties.remove("audio_index");
848 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
849 } else setProducerProperty("audio_index", value.toInt());
853 QMap <QString, QString> DocClipBase::properties() const
858 bool DocClipBase::slotGetAudioThumbs()
860 if (m_thumbProd == NULL) return false;
861 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
862 if (m_audioTimer != NULL) m_audioTimer->stop();
865 if (m_audioThumbCreated) {
866 m_audioTimer->stop();
869 m_audioTimer->start(1500);
870 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
871 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
875 bool DocClipBase::isPlaceHolder() const
877 return m_placeHolder;
880 void DocClipBase::addCutZone(int in, int out, QString desc)
883 info.zone = QPoint(in, out);
884 info.description = desc;
885 for (int i = 0; i < m_cutZones.count(); i++)
886 if (m_cutZones.at(i).zone == info.zone) {
889 m_cutZones.append(info);
892 bool DocClipBase::hasCutZone(QPoint p) const
894 for (int i = 0; i < m_cutZones.count(); i++)
895 if (m_cutZones.at(i).zone == p) return true;
900 void DocClipBase::removeCutZone(int in, int out)
903 for (int i = 0; i < m_cutZones.count(); i++) {
904 if (m_cutZones.at(i).zone == p) {
905 m_cutZones.removeAt(i);
911 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
913 QPoint old(oldin, oldout);
914 for (int i = 0; i < m_cutZones.size(); ++i) {
915 if (m_cutZones.at(i).zone == old) {
917 info.zone = QPoint(in, out);
918 info.description = desc;
919 m_cutZones.replace(i, info);
925 QList <CutZoneInfo> DocClipBase::cutZones() const
930 bool DocClipBase::hasVideoCodec(const QString &codec) const
932 Mlt::Producer *prod = NULL;
933 if (m_baseTrackProducers.count() == 0) return false;
934 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
935 if (m_baseTrackProducers.at(i) != NULL) {
936 prod = m_baseTrackProducers.at(i);
941 if (!prod) return false;
942 int default_video = prod->get_int("video_index");
944 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
945 return prod->get(property) == codec;
948 bool DocClipBase::hasAudioCodec(const QString &codec) const
950 Mlt::Producer *prod = NULL;
951 if (m_baseTrackProducers.count() == 0) return false;
952 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
953 if (m_baseTrackProducers.at(i) != NULL) {
954 prod = m_baseTrackProducers.at(i);
958 if (!prod) return false;
959 int default_video = prod->get_int("audio_index");
961 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
962 return prod->get(property) == codec;