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