]> git.sesse.net Git - kdenlive/blob - src/docclipbase.cpp
Various fixes to improve general stability in Qt 4.5.2
[kdenlive] / src / docclipbase.cpp
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)        *
7  *                                                                         *
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.                                   *
12  *                                                                         *
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.                          *
17  *                                                                         *
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  ***************************************************************************/
23
24
25
26
27 #include "docclipbase.h"
28 #include "kdenlivesettings.h"
29 #include "kthumb.h"
30 #include "clipmanager.h"
31
32 #include <KIO/NetAccess>
33 #include <KDebug>
34
35 #include <QCryptographicHash>
36
37 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
38         QObject(),
39         m_audioFrameCache(),
40         m_refcount(0),
41         m_baseTrackProducers(),
42         m_audioTrackProducers(),
43         m_videoOnlyProducer(NULL),
44         m_snapMarkers(),
45         m_duration(),
46         m_audioTimer(NULL),
47         m_thumbProd(NULL),
48         m_audioThumbCreated(false),
49         m_id(id),
50         m_placeHolder(xml.hasAttribute("placeholder")),
51         m_properties()
52 {
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());
59     }
60
61     KUrl url = KUrl(xml.attribute("resource"));
62     if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
63
64     if (xml.hasAttribute("duration")) {
65         setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
66     } else {
67         int out = xml.attribute("out").toInt();
68         int in = xml.attribute("in").toInt();
69         setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
70     }
71
72     if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
73
74     //if (!url.isEmpty() && QFile::exists(url.path()))
75     {
76         m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
77         if (m_clipType == AV || m_clipType == AUDIO) slotCreateAudioTimer();
78     }
79     //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
80 }
81
82 /*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
83     DocClipBase::operator=(clip);
84     m_id = clip.getId();
85     m_clipType = clip.clipType();
86     m_name = clip.name();
87     m_duration = clip.duration();
88     m_audioThumbCreated = clip.audioThumbCreated();
89     m_properties = clip.properties();
90     return *this;
91 }*/
92
93 DocClipBase::~DocClipBase()
94 {
95     kDebug() << "CLIP " << m_id << " DELETED******************************";
96     delete m_thumbProd;
97     if (m_audioTimer) {
98         m_audioTimer->stop();
99         delete m_audioTimer;
100     }
101     /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
102     if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
103     qDeleteAll(m_baseTrackProducers);
104     m_baseTrackProducers.clear();
105     qDeleteAll(m_audioTrackProducers);
106     m_audioTrackProducers.clear();
107     delete m_videoOnlyProducer;
108     m_videoOnlyProducer = NULL;
109 }
110
111 void DocClipBase::setZone(QPoint zone)
112 {
113     m_properties.insert("zone_in", QString::number(zone.x()));
114     m_properties.insert("zone_out", QString::number(zone.y()));
115 }
116
117 QPoint DocClipBase::zone() const
118 {
119     QPoint zone;
120     zone.setX(m_properties.value("zone_in").toInt());
121     zone.setY(m_properties.value("zone_out", "50").toInt());
122     return zone;
123 }
124
125 void DocClipBase::slotCreateAudioTimer()
126 {
127     connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
128     connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
129     m_audioTimer = new QTimer(this);
130     connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
131 }
132
133 void DocClipBase::askForAudioThumbs()
134 {
135     if (m_thumbProd) m_thumbProd->askForAudioThumbs(getId());
136 }
137
138 void DocClipBase::slotClearAudioCache()
139 {
140     if (m_thumbProd) m_thumbProd->stopAudioThumbs();
141     if (m_audioTimer != NULL) m_audioTimer->stop();
142     m_audioFrameCache.clear();
143     m_audioThumbCreated = false;
144 }
145
146 /*void DocClipBase::getClipMainThumb() {
147     if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
148 }*/
149
150 KThumb *DocClipBase::thumbProducer()
151 {
152     return m_thumbProd;
153 }
154
155 bool DocClipBase::audioThumbCreated() const
156 {
157     return m_audioThumbCreated;
158 }
159
160 const QString DocClipBase::name() const
161 {
162
163     return m_properties.value("name");
164 }
165
166 const QString &DocClipBase::getId() const
167 {
168     return m_id;
169 }
170
171 void DocClipBase::setId(const QString &newId)
172 {
173     m_id = newId;
174 }
175
176 const CLIPTYPE & DocClipBase::clipType() const
177 {
178     return m_clipType;
179 }
180
181 void DocClipBase::setClipType(CLIPTYPE type)
182 {
183     m_clipType = type;
184
185     m_properties.insert("type", QString::number((int) type));
186     if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO))
187         slotCreateAudioTimer();
188 }
189
190 KUrl DocClipBase::fileURL() const
191 {
192     QString res = m_properties.value("resource");
193     if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
194     return KUrl();
195 }
196
197 void DocClipBase::setClipThumbFrame(const uint &ix)
198 {
199     m_properties.insert("thumbnail", QString::number((int) ix));
200 }
201
202 uint DocClipBase::getClipThumbFrame() const
203 {
204     return (uint) m_properties.value("thumbnail").toInt();
205 }
206
207 const QString DocClipBase::description() const
208 {
209     return m_properties.value("description");
210 }
211
212 bool DocClipBase::isTransparent() const
213 {
214     return (m_properties.value("transparency") == "1");
215 }
216
217 const QString DocClipBase::getProperty(const QString prop) const
218 {
219     return m_properties.value(prop);
220 }
221
222 void DocClipBase::setDuration(GenTime dur)
223 {
224     m_duration = dur;
225     m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
226 }
227
228 const GenTime &DocClipBase::duration() const
229 {
230     return m_duration;
231 }
232
233 const GenTime DocClipBase::maxDuration() const
234 {
235     if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW &&  m_properties.value("loop") == "1")) {
236         /*const GenTime dur(15000, KdenliveSettings::project_fps());
237         return dur;*/
238         return GenTime();
239     }
240     return m_duration;
241 }
242
243 bool DocClipBase::hasFileSize() const
244 {
245     return true;
246 }
247
248
249 // virtual
250 QDomElement DocClipBase::toXML() const
251 {
252     QDomDocument doc;
253     QDomElement clip = doc.createElement("producer");
254
255     QMapIterator<QString, QString> i(m_properties);
256     while (i.hasNext()) {
257         i.next();
258         if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
259     }
260     doc.appendChild(clip);
261     //kDebug() << "/// CLIP XML: " << doc.toString();
262     return doc.documentElement();
263 }
264
265
266 void DocClipBase::setAudioThumbCreated(bool isDone)
267 {
268     m_audioThumbCreated = isDone;
269 }
270
271
272 void DocClipBase::setThumbnail(const QPixmap & pixmap)
273 {
274     m_thumbnail = pixmap;
275 }
276
277 const QPixmap & DocClipBase::thumbnail() const
278 {
279     return m_thumbnail;
280 }
281
282 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
283 {
284     //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
285     m_audioFrameCache = data;
286     m_audioThumbCreated = true;
287     emit gotAudioData();
288 }
289
290 QList < GenTime > DocClipBase::snapMarkers() const
291 {
292     QList < GenTime > markers;
293
294     for (int count = 0; count < m_snapMarkers.count(); ++count) {
295         markers.append(m_snapMarkers[count].time());
296     }
297
298     return markers;
299 }
300
301 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
302 {
303     return m_snapMarkers;
304 }
305
306 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
307 {
308     m_snapMarkers = markers;
309 }
310
311 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
312 {
313     QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
314     for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
315         if ((*it).time() >= time)
316             break;
317     }
318
319     if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
320         (*it).setComment(comment);
321         //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
322     } else {
323         CommentedTime t(time, comment);
324         m_snapMarkers.insert(it, t);
325     }
326
327 }
328
329 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
330 {
331     QList < CommentedTime >::Iterator it;
332     for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
333         if ((*it).time() == time)
334             break;
335     }
336     if (it != m_snapMarkers.end()) {
337         (*it).setComment(comment);
338     } else {
339         kError() << "trying to edit Snap Marker that does not already exists";
340     }
341 }
342
343 QString DocClipBase::deleteSnapMarker(const GenTime & time)
344 {
345     QString result = i18n("Marker");
346     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
347
348     while (itt != m_snapMarkers.end()) {
349         if ((*itt).time() == time)
350             break;
351         ++itt;
352     }
353
354     if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
355         result = (*itt).comment();
356         m_snapMarkers.erase(itt);
357     }
358     return result;
359 }
360
361
362 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
363 {
364     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
365
366     while (itt != m_snapMarkers.end()) {
367         if ((*itt).time() == time)
368             return time;
369         ++itt;
370     }
371
372     return GenTime(0.0);
373 }
374
375 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
376 {
377     int it;
378     for (it = 0; it < m_snapMarkers.count(); it++) {
379         if (m_snapMarkers[it].time() >= currTime)
380             break;
381     }
382     if (it == 0) return GenTime();
383     else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
384         return m_snapMarkers[it].time();
385     else return m_snapMarkers[it-1].time();
386 }
387
388 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
389 {
390     int it;
391     for (it = 0; it < m_snapMarkers.count(); it++) {
392         if (m_snapMarkers[it].time() > currTime)
393             break;
394     }
395     if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
396     return duration();
397 }
398
399 QString DocClipBase::markerComment(GenTime t)
400 {
401     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
402
403     while (itt != m_snapMarkers.end()) {
404         if ((*itt).time() == t)
405             return (*itt).comment();
406         ++itt;
407     }
408     return QString();
409 }
410
411 void DocClipBase::clearProducers()
412 {
413     m_baseTrackProducers.clear();
414 }
415
416 void DocClipBase::deleteProducers()
417 {
418     kDebug() << "// CLIP KILL PRODS ct: " << m_baseTrackProducers.count();
419     if (m_thumbProd) m_thumbProd->clearProducer();
420     /*kDebug()<<"// CLIP KILL PRODS ct: "<<m_baseTrackProducers.count();
421     int max = m_baseTrackProducers.count();
422     for (int i = 0; i < max; i++) {
423         kDebug()<<"// CLIP KILL PROD "<<i;
424     Mlt::Producer *p = m_baseTrackProducers.takeAt(i);
425     if (p != NULL) {
426      delete p;
427      p = NULL;
428     }
429     m_baseTrackProducers.insert(i, NULL);
430     }*/
431
432     delete m_videoOnlyProducer;
433     m_videoOnlyProducer = NULL;
434
435     qDeleteAll(m_baseTrackProducers);
436     m_baseTrackProducers.clear();
437     qDeleteAll(m_audioTrackProducers);
438     m_audioTrackProducers.clear();
439 }
440
441 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
442 {
443     if (producer == NULL) return;
444     if (reset) {
445         // Clear all previous producers
446         kDebug() << "/+++++++++++++++   DELETE ALL PRODS " << producer->get("id");
447         deleteProducers();
448     }
449     QString id = producer->get("id");
450     kDebug() << "// set prod: " << id;
451     if (id.contains('_')) {
452         // this is a subtrack producer, insert it at correct place
453         id = id.section('_', 1);
454         if (id.endsWith("audio")) {
455             int pos = id.section('_', 0, 0).toInt();
456             if (pos >= m_audioTrackProducers.count()) {
457                 while (m_audioTrackProducers.count() - 1 < pos) {
458                     m_audioTrackProducers.append(NULL);
459                 }
460             }
461             if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
462             return;
463         } else if (id.endsWith("video")) {
464             m_videoOnlyProducer = producer;
465             return;
466         }
467         int pos = id.toInt();
468         if (pos >= m_baseTrackProducers.count()) {
469             while (m_baseTrackProducers.count() - 1 < pos) {
470                 m_baseTrackProducers.append(NULL);
471             }
472         }
473         if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
474     } else {
475         if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
476         else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
477     }
478     //m_clipProducer = producer;
479     //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
480     if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
481 }
482
483 Mlt::Producer *DocClipBase::audioProducer(int track)
484 {
485     if (m_audioTrackProducers.count() <= track) {
486         while (m_audioTrackProducers.count() - 1 < track) {
487             m_audioTrackProducers.append(NULL);
488         }
489     }
490     if (m_audioTrackProducers.at(track) == NULL) {
491         Mlt::Producer *base = producer();
492         m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
493         if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
494         if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
495         m_audioTrackProducers.at(track)->set("video_index", -1);
496         if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
497         char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
498         m_audioTrackProducers.at(track)->set("id", tmp);
499         delete[] tmp;
500     }
501     return m_audioTrackProducers.at(track);
502 }
503
504 Mlt::Producer *DocClipBase::videoProducer()
505 {
506     if (m_videoOnlyProducer == NULL) {
507         int i;
508         for (i = 0; i < m_baseTrackProducers.count(); i++)
509             if (m_baseTrackProducers.at(i) != NULL) break;
510         if (i >= m_baseTrackProducers.count()) return NULL;
511         m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
512         if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
513         if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
514         m_videoOnlyProducer->set("audio_index", -1);
515         if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
516         char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
517         m_videoOnlyProducer->set("id", tmp);
518         delete[] tmp;
519     }
520     return m_videoOnlyProducer;
521 }
522
523 Mlt::Producer *DocClipBase::producer(int track)
524 {
525     /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
526         if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
527     }*/
528     if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
529         if (m_baseTrackProducers.count() == 0) return NULL;
530         for (int i = 0; i < m_baseTrackProducers.count(); i++) {
531             if (m_baseTrackProducers.at(i) != NULL)
532                 return m_baseTrackProducers.at(i);
533         }
534         return NULL;
535     }
536     if (track >= m_baseTrackProducers.count()) {
537         while (m_baseTrackProducers.count() - 1 < track) {
538             m_baseTrackProducers.append(NULL);
539         }
540     }
541     if (m_baseTrackProducers.at(track) == NULL) {
542         int i;
543         for (i = 0; i < m_baseTrackProducers.count(); i++)
544             if (m_baseTrackProducers.at(i) != NULL) break;
545
546         if (i >= m_baseTrackProducers.count()) return NULL;
547
548         if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
549             m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
550         else { // special case for placeholder clips
551             m_baseTrackProducers[track] = NULL;
552             return NULL;
553         }
554
555         if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
556         if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
557         if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
558         if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
559         char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
560         m_baseTrackProducers[track]->set("id", tmp);
561         delete[] tmp;
562         if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
563             m_baseTrackProducers[track]->set("skip_loop_filter", "all");
564             m_baseTrackProducers[track]->set("skip_frame", "bidir");
565         }
566     }
567     return m_baseTrackProducers.at(track);
568 }
569
570 void DocClipBase::setProducerProperty(const char *name, int data)
571 {
572     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
573         if (m_baseTrackProducers.at(i) != NULL)
574             m_baseTrackProducers[i]->set(name, data);
575     }
576 }
577
578 void DocClipBase::setProducerProperty(const char *name, double data)
579 {
580     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
581         if (m_baseTrackProducers.at(i) != NULL)
582             m_baseTrackProducers[i]->set(name, data);
583     }
584 }
585
586 void DocClipBase::setProducerProperty(const char *name, const char *data)
587 {
588     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
589         if (m_baseTrackProducers.at(i) != NULL)
590             m_baseTrackProducers[i]->set(name, data);
591     }
592 }
593
594 const char *DocClipBase::producerProperty(const char *name) const
595 {
596     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
597         if (m_baseTrackProducers.at(i) != NULL) {
598             return m_baseTrackProducers.at(i)->get(name);
599         }
600     }
601     return NULL;
602 }
603
604
605 void DocClipBase::slotRefreshProducer()
606 {
607     if (m_baseTrackProducers.count() == 0) return;
608     kDebug() << "////////////   REFRESH CLIP !!!!!!!!!!!!!!!!";
609     if (m_clipType == SLIDESHOW) {
610         /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
611                Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
612                delete[] tmp;
613         delete m_clipProducer;
614         m_clipProducer = new Mlt::Producer(producer.get_producer());
615         if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
616         setProducerProperty("ttl", getProperty("ttl").toInt());
617         //m_clipProducer->set("id", getProperty("id"));
618         if (getProperty("fade") == "1") {
619             // we want a fade filter effect
620             kDebug() << "////////////   FADE WANTED";
621             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
622             int ct = 0;
623             Mlt::Filter *filter = clipService.filter(ct);
624             while (filter) {
625                 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
626                     break;
627                 }
628                 ct++;
629                 filter = clipService.filter(ct);
630             }
631
632             if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
633                 filter->set("period", getProperty("ttl").toInt() - 1);
634                 filter->set("luma.out", getProperty("luma_duration").toInt());
635                 QString resource = getProperty("luma_file");
636                 char *tmp = (char *) qstrdup(resource.toUtf8().data());
637                 filter->set("luma.resource", tmp);
638                 delete[] tmp;
639                 if (!getProperty("softness").isEmpty()) {
640                     int soft = getProperty("softness").toInt();
641                     filter->set("luma.softness", (double) soft / 100.0);
642                 }
643             } else {
644                 // filter does not exist, create it...
645                 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
646                 filter->set("period", getProperty("ttl").toInt() - 1);
647                 filter->set("luma.out", getProperty("luma_duration").toInt());
648                 QString resource = getProperty("luma_file");
649                 char *tmp = (char *) qstrdup(resource.toUtf8().data());
650                 filter->set("luma.resource", tmp);
651                 delete[] tmp;
652                 if (!getProperty("softness").isEmpty()) {
653                     int soft = getProperty("softness").toInt();
654                     filter->set("luma.softness", (double) soft / 100.0);
655                 }
656                 clipService.attach(*filter);
657             }
658         } else {
659             kDebug() << "////////////   FADE NOT WANTED!!!";
660             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
661             int ct = 0;
662             Mlt::Filter *filter = clipService.filter(0);
663             while (filter) {
664                 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
665                     clipService.detach(*filter);
666                 } else ct++;
667                 filter = clipService.filter(ct);
668             }
669         }
670     }
671 }
672
673 void DocClipBase::setProperties(QMap <QString, QString> properties)
674 {
675     // changing clip type is not allowed
676     properties.remove("type");
677     QMapIterator<QString, QString> i(properties);
678     bool refreshProducer = false;
679     QStringList keys;
680     keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
681     while (i.hasNext()) {
682         i.next();
683         setProperty(i.key(), i.value());
684         if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
685     }
686     if (refreshProducer) slotRefreshProducer();
687 }
688
689 void DocClipBase::setMetadata(QMap <QString, QString> properties)
690 {
691     m_metadata = properties;
692 }
693
694 QMap <QString, QString> DocClipBase::metadata() const
695 {
696     return m_metadata;
697 }
698
699 void DocClipBase::clearProperty(const QString &key)
700 {
701     m_properties.remove(key);
702 }
703
704 void DocClipBase::getFileHash(const QString url)
705 {
706     if (m_clipType == SLIDESHOW) return;
707     QFile file(url);
708     if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
709         QByteArray fileData;
710         QByteArray fileHash;
711         //kDebug() << "SETTING HASH of" << value;
712         m_properties.insert("file_size", QString::number(file.size()));
713         /*
714                * 1 MB = 1 second per 450 files (or faster)
715                * 10 MB = 9 seconds per 450 files (or faster)
716                */
717         if (file.size() > 1000000*2) {
718             fileData = file.read(1000000);
719             if (file.seek(file.size() - 1000000))
720                 fileData.append(file.readAll());
721         } else
722             fileData = file.readAll();
723         file.close();
724         fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
725         m_properties.insert("file_hash", QString(fileHash.toHex()));
726     }
727 }
728
729 QString DocClipBase::getClipHash() const
730 {
731     QString hash;
732     if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
733     else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
734     else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
735     else hash = m_properties.value("file_hash");
736     return hash;
737 }
738
739 // static
740 QString DocClipBase::getHash(const QString &path)
741 {
742     QFile file(path);
743     if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
744         QByteArray fileData;
745         QByteArray fileHash;
746         /*
747                * 1 MB = 1 second per 450 files (or faster)
748                * 10 MB = 9 seconds per 450 files (or faster)
749                */
750         if (file.size() > 1000000*2) {
751             fileData = file.read(1000000);
752             if (file.seek(file.size() - 1000000))
753                 fileData.append(file.readAll());
754         } else
755             fileData = file.readAll();
756         file.close();
757         return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
758     }
759     return QString();
760 }
761
762 void DocClipBase::refreshThumbUrl()
763 {
764     if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
765 }
766
767 void DocClipBase::setProperty(const QString &key, const QString &value)
768 {
769     m_properties.insert(key, value);
770     if (key == "resource") {
771         getFileHash(value);
772         if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
773     } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
774     //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
775     else if (key == "colour") {
776         char *tmp = (char *) qstrdup(value.toUtf8().data());
777         setProducerProperty("colour", tmp);
778         delete[] tmp;
779     } else if (key == "templatetext") {
780         char *tmp = (char *) qstrdup(value.toUtf8().data());
781         setProducerProperty("templatetext", tmp);
782         delete[] tmp;
783         setProducerProperty("force_reload", 1);
784     } else if (key == "xmldata") {
785         char *tmp = (char *) qstrdup(value.toUtf8().data());
786         setProducerProperty("xmldata", tmp);
787         delete[] tmp;
788         setProducerProperty("force_reload", 1);
789     } else if (key == "force_aspect_ratio") {
790         if (value.isEmpty()) {
791             m_properties.remove("force_aspect_ratio");
792             setProducerProperty("force_aspect_ratio", 0);
793         } else setProducerProperty("force_aspect_ratio", value.toDouble());
794     } else if (key == "threads") {
795         if (value.isEmpty()) {
796             m_properties.remove("threads");
797             setProducerProperty("threads", 1);
798         } else setProducerProperty("threads", value.toInt());
799     } else if (key == "video_index") {
800         if (value.isEmpty()) {
801             m_properties.remove("video_index");
802             setProducerProperty("video_index", m_properties.value("default_video").toInt());
803         } else setProducerProperty("video_index", value.toInt());
804     } else if (key == "audio_index") {
805         if (value.isEmpty()) {
806             m_properties.remove("audio_index");
807             setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
808         } else setProducerProperty("audio_index", value.toInt());
809     }
810 }
811
812 QMap <QString, QString> DocClipBase::properties() const
813 {
814     return m_properties;
815 }
816
817 bool DocClipBase::slotGetAudioThumbs()
818 {
819     if (m_thumbProd == NULL) return false;
820     if (!KdenliveSettings::audiothumbnails()) {
821         if (m_audioTimer != NULL) m_audioTimer->stop();
822         return false;
823     }
824     if (m_audioThumbCreated) {
825         if (m_audioTimer != NULL) m_audioTimer->stop();
826         return false;
827     }
828     if (m_audioTimer != NULL)
829         m_audioTimer->start(1500);
830     double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
831     m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
832     return true;
833 }
834
835 bool DocClipBase::isPlaceHolder() const
836 {
837     return m_placeHolder;
838 }
839