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