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
129 QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
133 void DocClipBase::slotCreateAudioTimer()
135 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
136 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
137 m_audioTimer = new QTimer(this);
138 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
141 void DocClipBase::askForAudioThumbs()
143 if (m_thumbProd && m_audioTimer) m_thumbProd->askForAudioThumbs(getId());
146 void DocClipBase::slotClearAudioCache()
148 if (m_thumbProd) m_thumbProd->stopAudioThumbs();
149 if (m_audioTimer != NULL) m_audioTimer->stop();
150 m_audioFrameCache.clear();
151 m_audioThumbCreated = false;
154 /*void DocClipBase::getClipMainThumb() {
155 if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
158 KThumb *DocClipBase::thumbProducer()
163 bool DocClipBase::audioThumbCreated() const
165 return m_audioThumbCreated;
168 const QString DocClipBase::name() const
171 return m_properties.value("name");
174 const QString &DocClipBase::getId() const
179 void DocClipBase::setId(const QString &newId)
184 const CLIPTYPE & DocClipBase::clipType() const
189 void DocClipBase::setClipType(CLIPTYPE type)
193 m_properties.insert("type", QString::number((int) type));
194 if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST))
195 slotCreateAudioTimer();
198 KUrl DocClipBase::fileURL() const
200 QString res = m_properties.value("resource");
201 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
205 void DocClipBase::setClipThumbFrame(const uint &ix)
207 m_properties.insert("thumbnail", QString::number((int) ix));
210 uint DocClipBase::getClipThumbFrame() const
212 return (uint) m_properties.value("thumbnail").toInt();
215 const QString DocClipBase::description() const
217 return m_properties.value("description");
220 bool DocClipBase::isTransparent() const
222 return (m_properties.value("transparency") == "1");
225 const QString DocClipBase::getProperty(const QString prop) const
227 return m_properties.value(prop);
230 void DocClipBase::setDuration(GenTime dur)
233 m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
236 const GenTime &DocClipBase::duration() const
241 const GenTime DocClipBase::maxDuration() const
243 if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) {
244 /*const GenTime dur(15000, KdenliveSettings::project_fps());
251 bool DocClipBase::hasFileSize() const
256 qulonglong DocClipBase::fileSize() const
258 return m_properties.value("file_size").toULongLong();
262 QDomElement DocClipBase::toXML() const
265 QDomElement clip = doc.createElement("producer");
267 QMapIterator<QString, QString> i(m_properties);
268 while (i.hasNext()) {
270 if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
272 doc.appendChild(clip);
273 if (!m_cutZones.isEmpty()) {
275 for (int i = 0; i < m_cutZones.size(); i++) {
276 CutZoneInfo info = m_cutZones.at(i);
277 cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
279 clip.setAttribute("cutzones", cuts.join(";"));
281 //kDebug() << "/// CLIP XML: " << doc.toString();
282 return doc.documentElement();
286 void DocClipBase::setAudioThumbCreated(bool isDone)
288 m_audioThumbCreated = isDone;
292 void DocClipBase::setThumbnail(const QPixmap & pixmap)
294 m_thumbnail = pixmap;
297 const QPixmap & DocClipBase::thumbnail() const
302 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
304 //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
305 m_audioFrameCache = data;
306 m_audioThumbCreated = true;
310 QList < GenTime > DocClipBase::snapMarkers() const
312 QList < GenTime > markers;
314 for (int count = 0; count < m_snapMarkers.count(); ++count) {
315 markers.append(m_snapMarkers.at(count).time());
321 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
323 return m_snapMarkers;
327 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
329 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
330 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
331 if ((*it).time() >= time)
335 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
336 (*it).setComment(comment);
337 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
339 CommentedTime t(time, comment);
340 m_snapMarkers.insert(it, t);
345 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
347 QList < CommentedTime >::Iterator it;
348 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
349 if ((*it).time() == time)
352 if (it != m_snapMarkers.end()) {
353 (*it).setComment(comment);
355 kError() << "trying to edit Snap Marker that does not already exists";
359 QString DocClipBase::deleteSnapMarker(const GenTime & time)
361 QString result = i18n("Marker");
362 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
364 while (itt != m_snapMarkers.end()) {
365 if ((*itt).time() == time)
370 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
371 result = (*itt).comment();
372 m_snapMarkers.erase(itt);
378 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
380 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
382 while (itt != m_snapMarkers.end()) {
383 if ((*itt).time() == time)
391 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
394 for (it = 0; it < m_snapMarkers.count(); it++) {
395 if (m_snapMarkers.at(it).time() >= currTime)
398 if (it == 0) return GenTime();
399 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
400 return m_snapMarkers.at(it).time();
401 else return m_snapMarkers.at(it - 1).time();
404 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
407 for (it = 0; it < m_snapMarkers.count(); it++) {
408 if (m_snapMarkers.at(it).time() > currTime)
411 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
415 QString DocClipBase::markerComment(GenTime t)
417 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
419 while (itt != m_snapMarkers.end()) {
420 if ((*itt).time() == t)
421 return (*itt).comment();
427 void DocClipBase::clearProducers()
429 m_baseTrackProducers.clear();
432 void DocClipBase::deleteProducers(bool clearThumbCreator)
434 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
435 if (clearThumbCreator && m_thumbProd) m_thumbProd->clearProducer();
436 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
437 int max = m_baseTrackProducers.count();
438 for (int i = 0; i < max; i++) {
439 kDebug()<<"// CLIP KILL PROD "<<i;
440 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
445 m_baseTrackProducers.insert(i, NULL);
448 delete m_videoOnlyProducer;
449 m_videoOnlyProducer = NULL;
451 qDeleteAll(m_baseTrackProducers);
452 m_baseTrackProducers.clear();
453 qDeleteAll(m_audioTrackProducers);
454 m_audioTrackProducers.clear();
457 void DocClipBase::setValid()
459 m_placeHolder = false;
462 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
464 if (producer == NULL || (m_placeHolder && !reset)) return;
465 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
467 // Clear all previous producers
468 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
469 deleteProducers(false);
471 QString id = producer->get("id");
472 if (id.contains('_')) {
473 // this is a subtrack producer, insert it at correct place
474 id = id.section('_', 1);
475 if (id.endsWith("audio")) {
476 int pos = id.section('_', 0, 0).toInt();
477 if (pos >= m_audioTrackProducers.count()) {
478 while (m_audioTrackProducers.count() - 1 < pos) {
479 m_audioTrackProducers.append(NULL);
482 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
484 } else if (id.endsWith("video")) {
485 m_videoOnlyProducer = producer;
488 int pos = id.toInt();
489 if (pos >= m_baseTrackProducers.count()) {
490 while (m_baseTrackProducers.count() - 1 < pos) {
491 m_baseTrackProducers.append(NULL);
494 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
496 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
497 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
499 //m_clipProducer = producer;
500 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
503 Mlt::Producer *DocClipBase::audioProducer(int track)
505 if (m_audioTrackProducers.count() <= track) {
506 while (m_audioTrackProducers.count() - 1 < track) {
507 m_audioTrackProducers.append(NULL);
510 if (m_audioTrackProducers.at(track) == NULL) {
511 Mlt::Producer *base = producer();
512 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
513 if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
514 if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
515 if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
516 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
517 m_audioTrackProducers.at(track)->set("video_index", -1);
518 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
519 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
520 m_audioTrackProducers.at(track)->set("id", tmp);
523 return m_audioTrackProducers.at(track);
526 Mlt::Producer *DocClipBase::videoProducer()
528 if (m_videoOnlyProducer == NULL) {
530 for (i = 0; i < m_baseTrackProducers.count(); i++)
531 if (m_baseTrackProducers.at(i) != NULL) break;
532 if (i >= m_baseTrackProducers.count()) return NULL;
533 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
534 if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
535 if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
536 if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
537 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
538 m_videoOnlyProducer->set("audio_index", -1);
539 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
540 char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
541 m_videoOnlyProducer->set("id", tmp);
544 return m_videoOnlyProducer;
547 Mlt::Producer *DocClipBase::producer(int track)
549 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
550 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
552 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
553 if (m_baseTrackProducers.count() == 0) return NULL;
554 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
555 if (m_baseTrackProducers.at(i) != NULL)
556 return m_baseTrackProducers.at(i);
560 if (track >= m_baseTrackProducers.count()) {
561 while (m_baseTrackProducers.count() - 1 < track) {
562 m_baseTrackProducers.append(NULL);
565 if (m_baseTrackProducers.at(track) == NULL) {
567 for (i = 0; i < m_baseTrackProducers.count(); i++)
568 if (m_baseTrackProducers.at(i) != NULL) break;
570 if (i >= m_baseTrackProducers.count()) return NULL;
572 if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
573 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
574 else { // special case for placeholder clips
575 m_baseTrackProducers[track] = NULL;
579 if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
580 if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
581 if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
582 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
583 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
584 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
585 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
586 m_baseTrackProducers[track]->set("id", tmp);
588 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
589 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
590 m_baseTrackProducers[track]->set("skip_frame", "bidir");
593 return m_baseTrackProducers.at(track);
596 void DocClipBase::setProducerProperty(const char *name, int data)
598 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
599 if (m_baseTrackProducers.at(i) != NULL)
600 m_baseTrackProducers[i]->set(name, data);
604 void DocClipBase::setProducerProperty(const char *name, double data)
606 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
607 if (m_baseTrackProducers.at(i) != NULL)
608 m_baseTrackProducers[i]->set(name, data);
612 void DocClipBase::setProducerProperty(const char *name, const char *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::resetProducerProperty(const char *name)
622 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
623 if (m_baseTrackProducers.at(i) != NULL)
624 m_baseTrackProducers[i]->set(name, (const char*) NULL);
628 const char *DocClipBase::producerProperty(const char *name) const
630 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
631 if (m_baseTrackProducers.at(i) != NULL) {
632 return m_baseTrackProducers.at(i)->get(name);
639 void DocClipBase::slotRefreshProducer()
641 if (m_baseTrackProducers.count() == 0) return;
642 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
643 if (m_clipType == SLIDESHOW) {
644 /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
645 Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
647 delete m_clipProducer;
648 m_clipProducer = new Mlt::Producer(producer.get_producer());
649 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
650 setProducerProperty("ttl", getProperty("ttl").toInt());
651 //m_clipProducer->set("id", getProperty("id"));
652 if (getProperty("fade") == "1") {
653 // we want a fade filter effect
654 kDebug() << "//////////// FADE WANTED";
655 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
657 Mlt::Filter *filter = clipService.filter(ct);
659 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
663 filter = clipService.filter(ct);
666 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
667 filter->set("period", getProperty("ttl").toInt() - 1);
668 filter->set("luma.out", getProperty("luma_duration").toInt());
669 QString resource = getProperty("luma_file");
670 char *tmp = (char *) qstrdup(resource.toUtf8().data());
671 filter->set("luma.resource", tmp);
673 if (!getProperty("softness").isEmpty()) {
674 int soft = getProperty("softness").toInt();
675 filter->set("luma.softness", (double) soft / 100.0);
678 // filter does not exist, create it...
679 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
680 filter->set("period", getProperty("ttl").toInt() - 1);
681 filter->set("luma.out", getProperty("luma_duration").toInt());
682 QString resource = getProperty("luma_file");
683 char *tmp = (char *) qstrdup(resource.toUtf8().data());
684 filter->set("luma.resource", tmp);
686 if (!getProperty("softness").isEmpty()) {
687 int soft = getProperty("softness").toInt();
688 filter->set("luma.softness", (double) soft / 100.0);
690 clipService.attach(*filter);
693 kDebug() << "//////////// FADE NOT WANTED!!!";
694 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
696 Mlt::Filter *filter = clipService.filter(0);
698 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
699 clipService.detach(*filter);
701 filter = clipService.filter(ct);
707 void DocClipBase::setProperties(QMap <QString, QString> properties)
709 // changing clip type is not allowed
710 properties.remove("type");
711 QMapIterator<QString, QString> i(properties);
712 bool refreshProducer = false;
714 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
715 while (i.hasNext()) {
717 setProperty(i.key(), i.value());
718 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
720 if (refreshProducer) slotRefreshProducer();
723 void DocClipBase::setMetadata(QMap <QString, QString> properties)
725 m_metadata = properties;
728 QMap <QString, QString> DocClipBase::metadata() const
733 void DocClipBase::clearProperty(const QString &key)
735 m_properties.remove(key);
738 void DocClipBase::getFileHash(const QString url)
740 if (m_clipType == SLIDESHOW) return;
742 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
745 //kDebug() << "SETTING HASH of" << value;
746 m_properties.insert("file_size", QString::number(file.size()));
748 * 1 MB = 1 second per 450 files (or faster)
749 * 10 MB = 9 seconds per 450 files (or faster)
751 if (file.size() > 1000000*2) {
752 fileData = file.read(1000000);
753 if (file.seek(file.size() - 1000000))
754 fileData.append(file.readAll());
756 fileData = file.readAll();
758 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
759 m_properties.insert("file_hash", QString(fileHash.toHex()));
763 bool DocClipBase::checkHash() const
765 KUrl url = fileURL();
766 if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
770 QString DocClipBase::getClipHash() const
773 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
774 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
775 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
776 else hash = m_properties.value("file_hash");
780 void DocClipBase::setPlaceHolder(bool place)
782 m_placeHolder = place;
786 QString DocClipBase::getHash(const QString &path)
789 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
793 * 1 MB = 1 second per 450 files (or faster)
794 * 10 MB = 9 seconds per 450 files (or faster)
796 if (file.size() > 1000000*2) {
797 fileData = file.read(1000000);
798 if (file.seek(file.size() - 1000000))
799 fileData.append(file.readAll());
801 fileData = file.readAll();
803 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
808 void DocClipBase::refreshThumbUrl()
810 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
813 void DocClipBase::setProperty(const QString &key, const QString &value)
815 m_properties.insert(key, value);
816 if (key == "resource") {
818 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
819 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
820 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
821 else if (key == "colour") {
822 char *tmp = (char *) qstrdup(value.toUtf8().data());
823 setProducerProperty("colour", tmp);
825 } else if (key == "templatetext") {
826 char *tmp = (char *) qstrdup(value.toUtf8().data());
827 setProducerProperty("templatetext", tmp);
829 setProducerProperty("force_reload", 1);
830 } else if (key == "xmldata") {
831 char *tmp = (char *) qstrdup(value.toUtf8().data());
832 setProducerProperty("xmldata", tmp);
834 setProducerProperty("force_reload", 1);
835 } else if (key == "force_aspect_ratio") {
836 if (value.isEmpty()) {
837 m_properties.remove("force_aspect_ratio");
838 resetProducerProperty("force_aspect_ratio");
839 } else setProducerProperty("force_aspect_ratio", value.toDouble());
840 } else if (key == "force_fps") {
841 if (value.isEmpty()) {
842 m_properties.remove("force_fps");
843 resetProducerProperty("force_fps");
844 } else setProducerProperty("force_fps", value.toDouble());
845 } else if (key == "force_progressive") {
846 if (value.isEmpty()) {
847 m_properties.remove("force_progressive");
848 resetProducerProperty("force_progressive");
849 } else setProducerProperty("force_progressive", value.toInt());
850 } else if (key == "threads") {
851 if (value.isEmpty()) {
852 m_properties.remove("threads");
853 setProducerProperty("threads", 1);
854 } else setProducerProperty("threads", value.toInt());
855 } else if (key == "video_index") {
856 if (value.isEmpty()) {
857 m_properties.remove("video_index");
858 setProducerProperty("video_index", m_properties.value("default_video").toInt());
859 } else setProducerProperty("video_index", value.toInt());
860 } else if (key == "audio_index") {
861 if (value.isEmpty()) {
862 m_properties.remove("audio_index");
863 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
864 } else setProducerProperty("audio_index", value.toInt());
868 QMap <QString, QString> DocClipBase::properties() const
873 bool DocClipBase::slotGetAudioThumbs()
875 if (m_thumbProd == NULL) return false;
876 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
877 if (m_audioTimer != NULL) m_audioTimer->stop();
880 if (m_audioThumbCreated) {
881 m_audioTimer->stop();
884 m_audioTimer->start(1500);
885 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
886 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
890 bool DocClipBase::isPlaceHolder() const
892 return m_placeHolder;
895 void DocClipBase::addCutZone(int in, int out, QString desc)
898 info.zone = QPoint(in, out);
899 info.description = desc;
900 for (int i = 0; i < m_cutZones.count(); i++)
901 if (m_cutZones.at(i).zone == info.zone) {
904 m_cutZones.append(info);
907 bool DocClipBase::hasCutZone(QPoint p) const
909 for (int i = 0; i < m_cutZones.count(); i++)
910 if (m_cutZones.at(i).zone == p) return true;
915 void DocClipBase::removeCutZone(int in, int out)
918 for (int i = 0; i < m_cutZones.count(); i++) {
919 if (m_cutZones.at(i).zone == p) {
920 m_cutZones.removeAt(i);
926 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
928 QPoint old(oldin, oldout);
929 for (int i = 0; i < m_cutZones.size(); ++i) {
930 if (m_cutZones.at(i).zone == old) {
932 info.zone = QPoint(in, out);
933 info.description = desc;
934 m_cutZones.replace(i, info);
940 QList <CutZoneInfo> DocClipBase::cutZones() const
945 bool DocClipBase::hasVideoCodec(const QString &codec) const
947 Mlt::Producer *prod = NULL;
948 if (m_baseTrackProducers.count() == 0) return false;
949 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
950 if (m_baseTrackProducers.at(i) != NULL) {
951 prod = m_baseTrackProducers.at(i);
956 if (!prod) return false;
957 int default_video = prod->get_int("video_index");
959 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
960 return prod->get(property) == codec;
963 bool DocClipBase::hasAudioCodec(const QString &codec) const
965 Mlt::Producer *prod = NULL;
966 if (m_baseTrackProducers.count() == 0) return false;
967 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
968 if (m_baseTrackProducers.at(i) != NULL) {
969 prod = m_baseTrackProducers.at(i);
973 if (!prod) return false;
974 int default_video = prod->get_int("audio_index");
976 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
977 return prod->get(property) == codec;