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>
37 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
41 m_baseTrackProducers(),
42 m_audioTrackProducers(),
43 m_videoOnlyProducer(NULL),
48 m_audioThumbCreated(false),
50 m_placeHolder(xml.hasAttribute("placeholder")),
53 int type = xml.attribute("type").toInt();
54 m_clipType = (CLIPTYPE) type;
55 if (m_placeHolder) xml.removeAttribute("placeholder");
56 QDomNamedNodeMap attributes = xml.attributes();
57 for (int i = 0; i < attributes.count(); i++) {
58 m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
61 if (xml.hasAttribute("cutzones")) {
62 QStringList cuts = xml.attribute("cutzones").split(";", QString::SkipEmptyParts);
63 for (int i = 0; i < cuts.count(); i++) {
64 QString z = cuts.at(i);
65 addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
69 KUrl url = KUrl(xml.attribute("resource"));
70 if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
72 if (xml.hasAttribute("duration")) {
73 setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
75 int out = xml.attribute("out").toInt();
76 int in = xml.attribute("in").toInt();
77 setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
80 if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
82 //if (!url.isEmpty() && QFile::exists(url.path()))
84 m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
85 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == PLAYLIST) slotCreateAudioTimer();
87 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
90 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
91 DocClipBase::operator=(clip);
93 m_clipType = clip.clipType();
95 m_duration = clip.duration();
96 m_audioThumbCreated = clip.audioThumbCreated();
97 m_properties = clip.properties();
101 DocClipBase::~DocClipBase()
103 kDebug() << "CLIP " << m_id << " DELETED******************************";
106 m_audioTimer->stop();
109 /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
110 if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
111 qDeleteAll(m_baseTrackProducers);
112 m_baseTrackProducers.clear();
113 qDeleteAll(m_audioTrackProducers);
114 m_audioTrackProducers.clear();
115 delete m_videoOnlyProducer;
116 m_videoOnlyProducer = NULL;
119 void DocClipBase::setZone(QPoint zone)
121 m_properties.insert("zone_in", QString::number(zone.x()));
122 m_properties.insert("zone_out", QString::number(zone.y()));
125 QPoint DocClipBase::zone() const
128 zone.setX(m_properties.value("zone_in").toInt());
129 zone.setY(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) slotGetAudioThumbs();
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;
326 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
328 m_snapMarkers = markers;
331 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
333 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
334 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
335 if ((*it).time() >= time)
339 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
340 (*it).setComment(comment);
341 //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
343 CommentedTime t(time, comment);
344 m_snapMarkers.insert(it, t);
349 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
351 QList < CommentedTime >::Iterator it;
352 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
353 if ((*it).time() == time)
356 if (it != m_snapMarkers.end()) {
357 (*it).setComment(comment);
359 kError() << "trying to edit Snap Marker that does not already exists";
363 QString DocClipBase::deleteSnapMarker(const GenTime & time)
365 QString result = i18n("Marker");
366 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
368 while (itt != m_snapMarkers.end()) {
369 if ((*itt).time() == time)
374 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
375 result = (*itt).comment();
376 m_snapMarkers.erase(itt);
382 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
384 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
386 while (itt != m_snapMarkers.end()) {
387 if ((*itt).time() == time)
395 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
398 for (it = 0; it < m_snapMarkers.count(); it++) {
399 if (m_snapMarkers.at(it).time() >= currTime)
402 if (it == 0) return GenTime();
403 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
404 return m_snapMarkers.at(it).time();
405 else return m_snapMarkers.at(it - 1).time();
408 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
411 for (it = 0; it < m_snapMarkers.count(); it++) {
412 if (m_snapMarkers.at(it).time() > currTime)
415 if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
419 QString DocClipBase::markerComment(GenTime t)
421 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
423 while (itt != m_snapMarkers.end()) {
424 if ((*itt).time() == t)
425 return (*itt).comment();
431 void DocClipBase::clearProducers()
433 m_baseTrackProducers.clear();
436 void DocClipBase::deleteProducers()
438 kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
439 if (m_thumbProd) m_thumbProd->clearProducer();
440 /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
441 int max = m_baseTrackProducers.count();
442 for (int i = 0; i < max; i++) {
443 kDebug()<<"// CLIP KILL PROD "<<i;
444 Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
449 m_baseTrackProducers.insert(i, NULL);
452 delete m_videoOnlyProducer;
453 m_videoOnlyProducer = NULL;
455 qDeleteAll(m_baseTrackProducers);
456 m_baseTrackProducers.clear();
457 qDeleteAll(m_audioTrackProducers);
458 m_audioTrackProducers.clear();
461 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
463 if (producer == NULL) return;
465 // Clear all previous producers
466 kDebug() << "/+++++++++++++++ DELETE ALL PRODS " << producer->get("id");
469 QString id = producer->get("id");
470 if (id.contains('_')) {
471 // this is a subtrack producer, insert it at correct place
472 id = id.section('_', 1);
473 if (id.endsWith("audio")) {
474 int pos = id.section('_', 0, 0).toInt();
475 if (pos >= m_audioTrackProducers.count()) {
476 while (m_audioTrackProducers.count() - 1 < pos) {
477 m_audioTrackProducers.append(NULL);
480 if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
482 } else if (id.endsWith("video")) {
483 m_videoOnlyProducer = producer;
486 int pos = id.toInt();
487 if (pos >= m_baseTrackProducers.count()) {
488 while (m_baseTrackProducers.count() - 1 < pos) {
489 m_baseTrackProducers.append(NULL);
492 if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
494 if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
495 else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
497 //m_clipProducer = producer;
498 //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
499 if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
502 Mlt::Producer *DocClipBase::audioProducer(int track)
504 if (m_audioTrackProducers.count() <= track) {
505 while (m_audioTrackProducers.count() - 1 < track) {
506 m_audioTrackProducers.append(NULL);
509 if (m_audioTrackProducers.at(track) == NULL) {
510 Mlt::Producer *base = producer();
511 m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
512 if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
513 if (m_properties.contains("force_fps")) m_audioTrackProducers.at(track)->set("force_fps", m_properties.value("force_fps").toDouble());
514 if (m_properties.contains("force_progressive")) m_audioTrackProducers.at(track)->set("force_progressive", m_properties.value("force_progressive").toInt());
515 if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
516 m_audioTrackProducers.at(track)->set("video_index", -1);
517 if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
518 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
519 m_audioTrackProducers.at(track)->set("id", tmp);
522 return m_audioTrackProducers.at(track);
525 Mlt::Producer *DocClipBase::videoProducer()
527 if (m_videoOnlyProducer == NULL) {
529 for (i = 0; i < m_baseTrackProducers.count(); i++)
530 if (m_baseTrackProducers.at(i) != NULL) break;
531 if (i >= m_baseTrackProducers.count()) return NULL;
532 m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
533 if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
534 if (m_properties.contains("force_fps")) m_videoOnlyProducer->set("force_fps", m_properties.value("force_fps").toDouble());
535 if (m_properties.contains("force_progressive")) m_videoOnlyProducer->set("force_progressive", m_properties.value("force_progressive").toInt());
536 if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
537 m_videoOnlyProducer->set("audio_index", -1);
538 if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
539 char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
540 m_videoOnlyProducer->set("id", tmp);
543 return m_videoOnlyProducer;
546 Mlt::Producer *DocClipBase::producer(int track)
548 /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
549 if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
551 if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
552 if (m_baseTrackProducers.count() == 0) return NULL;
553 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
554 if (m_baseTrackProducers.at(i) != NULL)
555 return m_baseTrackProducers.at(i);
559 if (track >= m_baseTrackProducers.count()) {
560 while (m_baseTrackProducers.count() - 1 < track) {
561 m_baseTrackProducers.append(NULL);
564 if (m_baseTrackProducers.at(track) == NULL) {
566 for (i = 0; i < m_baseTrackProducers.count(); i++)
567 if (m_baseTrackProducers.at(i) != NULL) break;
569 if (i >= m_baseTrackProducers.count()) return NULL;
571 if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
572 m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
573 else { // special case for placeholder clips
574 m_baseTrackProducers[track] = NULL;
578 if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
579 if (m_properties.contains("force_fps")) m_baseTrackProducers[track]->set("force_fps", m_properties.value("force_fps").toDouble());
580 if (m_properties.contains("force_progressive")) m_baseTrackProducers[track]->set("force_progressive", m_properties.value("force_progressive").toInt());
581 if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
582 if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
583 if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
584 char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
585 m_baseTrackProducers[track]->set("id", tmp);
587 if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
588 m_baseTrackProducers[track]->set("skip_loop_filter", "all");
589 m_baseTrackProducers[track]->set("skip_frame", "bidir");
592 return m_baseTrackProducers.at(track);
595 void DocClipBase::setProducerProperty(const char *name, int data)
597 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
598 if (m_baseTrackProducers.at(i) != NULL)
599 m_baseTrackProducers[i]->set(name, data);
603 void DocClipBase::setProducerProperty(const char *name, double data)
605 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
606 if (m_baseTrackProducers.at(i) != NULL)
607 m_baseTrackProducers[i]->set(name, data);
611 void DocClipBase::setProducerProperty(const char *name, const char *data)
613 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
614 if (m_baseTrackProducers.at(i) != NULL)
615 m_baseTrackProducers[i]->set(name, data);
619 void DocClipBase::resetProducerProperty(const char *name)
621 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
622 if (m_baseTrackProducers.at(i) != NULL)
623 m_baseTrackProducers[i]->set(name, (const char*) NULL);
627 const char *DocClipBase::producerProperty(const char *name) const
629 for (int i = 0; i < m_baseTrackProducers.count(); i++) {
630 if (m_baseTrackProducers.at(i) != NULL) {
631 return m_baseTrackProducers.at(i)->get(name);
638 void DocClipBase::slotRefreshProducer()
640 if (m_baseTrackProducers.count() == 0) return;
641 kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!";
642 if (m_clipType == SLIDESHOW) {
643 /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
644 Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
646 delete m_clipProducer;
647 m_clipProducer = new Mlt::Producer(producer.get_producer());
648 if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
649 setProducerProperty("ttl", getProperty("ttl").toInt());
650 //m_clipProducer->set("id", getProperty("id"));
651 if (getProperty("fade") == "1") {
652 // we want a fade filter effect
653 kDebug() << "//////////// FADE WANTED";
654 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
656 Mlt::Filter *filter = clipService.filter(ct);
658 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
662 filter = clipService.filter(ct);
665 if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
666 filter->set("period", getProperty("ttl").toInt() - 1);
667 filter->set("luma.out", getProperty("luma_duration").toInt());
668 QString resource = getProperty("luma_file");
669 char *tmp = (char *) qstrdup(resource.toUtf8().data());
670 filter->set("luma.resource", tmp);
672 if (!getProperty("softness").isEmpty()) {
673 int soft = getProperty("softness").toInt();
674 filter->set("luma.softness", (double) soft / 100.0);
677 // filter does not exist, create it...
678 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
679 filter->set("period", getProperty("ttl").toInt() - 1);
680 filter->set("luma.out", getProperty("luma_duration").toInt());
681 QString resource = getProperty("luma_file");
682 char *tmp = (char *) qstrdup(resource.toUtf8().data());
683 filter->set("luma.resource", tmp);
685 if (!getProperty("softness").isEmpty()) {
686 int soft = getProperty("softness").toInt();
687 filter->set("luma.softness", (double) soft / 100.0);
689 clipService.attach(*filter);
692 kDebug() << "//////////// FADE NOT WANTED!!!";
693 Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
695 Mlt::Filter *filter = clipService.filter(0);
697 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
698 clipService.detach(*filter);
700 filter = clipService.filter(ct);
706 void DocClipBase::setProperties(QMap <QString, QString> properties)
708 // changing clip type is not allowed
709 properties.remove("type");
710 QMapIterator<QString, QString> i(properties);
711 bool refreshProducer = false;
713 keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
714 while (i.hasNext()) {
716 setProperty(i.key(), i.value());
717 if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
719 if (refreshProducer) slotRefreshProducer();
722 void DocClipBase::setMetadata(QMap <QString, QString> properties)
724 m_metadata = properties;
727 QMap <QString, QString> DocClipBase::metadata() const
732 void DocClipBase::clearProperty(const QString &key)
734 m_properties.remove(key);
737 void DocClipBase::getFileHash(const QString url)
739 if (m_clipType == SLIDESHOW) return;
741 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
744 //kDebug() << "SETTING HASH of" << value;
745 m_properties.insert("file_size", QString::number(file.size()));
747 * 1 MB = 1 second per 450 files (or faster)
748 * 10 MB = 9 seconds per 450 files (or faster)
750 if (file.size() > 1000000*2) {
751 fileData = file.read(1000000);
752 if (file.seek(file.size() - 1000000))
753 fileData.append(file.readAll());
755 fileData = file.readAll();
757 fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
758 m_properties.insert("file_hash", QString(fileHash.toHex()));
762 QString DocClipBase::getClipHash() const
765 if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
766 else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
767 else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
768 else hash = m_properties.value("file_hash");
773 QString DocClipBase::getHash(const QString &path)
776 if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
780 * 1 MB = 1 second per 450 files (or faster)
781 * 10 MB = 9 seconds per 450 files (or faster)
783 if (file.size() > 1000000*2) {
784 fileData = file.read(1000000);
785 if (file.seek(file.size() - 1000000))
786 fileData.append(file.readAll());
788 fileData = file.readAll();
790 return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
795 void DocClipBase::refreshThumbUrl()
797 if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
800 void DocClipBase::setProperty(const QString &key, const QString &value)
802 m_properties.insert(key, value);
803 if (key == "resource") {
805 if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
806 } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
807 //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
808 else if (key == "colour") {
809 char *tmp = (char *) qstrdup(value.toUtf8().data());
810 setProducerProperty("colour", tmp);
812 } else if (key == "templatetext") {
813 char *tmp = (char *) qstrdup(value.toUtf8().data());
814 setProducerProperty("templatetext", tmp);
816 setProducerProperty("force_reload", 1);
817 } else if (key == "xmldata") {
818 char *tmp = (char *) qstrdup(value.toUtf8().data());
819 setProducerProperty("xmldata", tmp);
821 setProducerProperty("force_reload", 1);
822 } else if (key == "force_aspect_ratio") {
823 if (value.isEmpty()) {
824 m_properties.remove("force_aspect_ratio");
825 resetProducerProperty("force_aspect_ratio");
826 } else setProducerProperty("force_aspect_ratio", value.toDouble());
827 } else if (key == "force_fps") {
828 if (value.isEmpty()) {
829 m_properties.remove("force_fps");
830 resetProducerProperty("force_fps");
831 } else setProducerProperty("force_fps", value.toDouble());
832 } else if (key == "force_progressive") {
833 if (value.isEmpty()) {
834 m_properties.remove("force_progressive");
835 resetProducerProperty("force_progressive");
836 } else setProducerProperty("force_progressive", value.toInt());
837 } else if (key == "threads") {
838 if (value.isEmpty()) {
839 m_properties.remove("threads");
840 setProducerProperty("threads", 1);
841 } else setProducerProperty("threads", value.toInt());
842 } else if (key == "video_index") {
843 if (value.isEmpty()) {
844 m_properties.remove("video_index");
845 setProducerProperty("video_index", m_properties.value("default_video").toInt());
846 } else setProducerProperty("video_index", value.toInt());
847 } else if (key == "audio_index") {
848 if (value.isEmpty()) {
849 m_properties.remove("audio_index");
850 setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
851 } else setProducerProperty("audio_index", value.toInt());
855 QMap <QString, QString> DocClipBase::properties() const
860 bool DocClipBase::slotGetAudioThumbs()
862 if (m_thumbProd == NULL) return false;
863 if (!KdenliveSettings::audiothumbnails() || m_audioTimer == NULL) {
864 if (m_audioTimer != NULL) m_audioTimer->stop();
867 if (m_audioThumbCreated) {
868 m_audioTimer->stop();
871 m_audioTimer->start(1500);
872 double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
873 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
877 bool DocClipBase::isPlaceHolder() const
879 return m_placeHolder;
882 void DocClipBase::addCutZone(int in, int out, QString desc)
885 info.zone = QPoint(in, out);
886 info.description = desc;
887 for (int i = 0; i < m_cutZones.count(); i++)
888 if (m_cutZones.at(i).zone == info.zone) {
891 m_cutZones.append(info);
894 bool DocClipBase::hasCutZone(QPoint p) const
896 for (int i = 0; i < m_cutZones.count(); i++)
897 if (m_cutZones.at(i).zone == p) return true;
902 void DocClipBase::removeCutZone(int in, int out)
905 for (int i = 0; i < m_cutZones.count(); i++) {
906 if (m_cutZones.at(i).zone == p) {
907 m_cutZones.removeAt(i);
913 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
915 QPoint old(oldin, oldout);
916 for (int i = 0; i < m_cutZones.size(); ++i) {
917 if (m_cutZones.at(i).zone == old) {
919 info.zone = QPoint(in, out);
920 info.description = desc;
921 m_cutZones.replace(i, info);
927 QList <CutZoneInfo> DocClipBase::cutZones() const