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