]> git.sesse.net Git - kdenlive/blob - src/docclipbase.cpp
Improve update of effect stack when resizing clip, start implementing merge of analys...
[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 #include "slideshowclip.h"
32
33 #include <KIO/NetAccess>
34 #include <KStandardDirs>
35 #include <KApplication>
36 #include <KDebug>
37
38 #include <QCryptographicHash>
39 #include <QtConcurrentRun>
40
41 #include <cstdio>
42 #include <kmessagebox.h>
43
44 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
45         QObject(),
46         lastSeekPosition(0),
47         audioFrameCache(),
48         m_refcount(0),
49         m_baseTrackProducers(),
50         m_videoTrackProducers(),
51         m_audioTrackProducers(),
52         m_snapMarkers(QList < CommentedTime >()),
53         m_duration(),
54         m_thumbProd(NULL),
55         m_audioThumbCreated(false),
56         m_id(id),
57         m_placeHolder(xml.hasAttribute("placeholder")),
58         m_properties()
59 {
60     int type = xml.attribute("type").toInt();
61     m_clipType = (CLIPTYPE) type;
62     if (m_placeHolder) xml.removeAttribute("placeholder");
63     QDomNamedNodeMap attributes = xml.attributes();
64     for (int i = 0; i < attributes.count(); i++) {
65         QString name = attributes.item(i).nodeName();
66         if (name.startsWith("meta.attr.")) {
67             m_metadata.insert(name.section('.', 2, 3), attributes.item(i).nodeValue());
68         } else m_properties.insert(name, attributes.item(i).nodeValue());
69     }
70
71     if (xml.hasAttribute("cutzones")) {
72         QStringList cuts = xml.attribute("cutzones").split(';', QString::SkipEmptyParts);
73         for (int i = 0; i < cuts.count(); i++) {
74             QString z = cuts.at(i);
75             addCutZone(z.section('-', 0, 0).toInt(), z.section('-', 1, 1).toInt(), z.section('-', 2, 2));
76         }
77     }
78
79     if (xml.hasAttribute("analysisdata")) {
80         QStringList adata = xml.attribute("analysisdata").split('#', QString::SkipEmptyParts);
81         for (int i = 0; i < adata.count(); i++)
82             m_analysisdata.insert(adata.at(i).section('?', 0, 0), adata.at(i).section('?', 1, 1));
83     }
84
85     KUrl url = KUrl(xml.attribute("resource"));
86     if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
87
88     if (xml.hasAttribute("duration")) {
89         setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
90     } else {
91         int out = xml.attribute("out").toInt();
92         int in = xml.attribute("in").toInt();
93         setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
94     }
95
96     if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
97
98     m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
99     
100     // Setup timer to trigger audio thumbs creation
101     m_audioTimer.setSingleShot(true);
102     m_audioTimer.setInterval(800);
103     connect(&m_audioTimer, SIGNAL(timeout()), m_thumbProd, SLOT(slotCreateAudioThumbs()));
104     
105 }
106
107 DocClipBase::~DocClipBase()
108 {
109     m_audioTimer.stop();
110     delete m_thumbProd;
111     m_thumbProd = NULL;
112     qDeleteAll(m_toDeleteProducers);
113     m_toDeleteProducers.clear();
114     qDeleteAll(m_baseTrackProducers);
115     m_baseTrackProducers.clear();
116     qDeleteAll(m_audioTrackProducers);
117     m_audioTrackProducers.clear();
118     qDeleteAll(m_videoTrackProducers);
119     m_videoTrackProducers.clear();
120 }
121
122 void DocClipBase::setZone(QPoint zone)
123 {
124     m_properties.insert("zone_in", QString::number(zone.x()));
125     m_properties.insert("zone_out", QString::number(zone.y()));
126 }
127
128 QPoint DocClipBase::zone() const
129 {
130     QPoint zone(m_properties.value("zone_in", "0").toInt(), m_properties.value("zone_out", "50").toInt());
131     return zone;
132 }
133
134
135 bool DocClipBase::hasAudioThumb() const
136 {
137     if (m_clipType == AUDIO || m_clipType == AV || m_clipType == PLAYLIST) return true;
138     return false;
139 }
140
141 void DocClipBase::slotClearAudioCache()
142 {
143     audioFrameCache.clear();
144     m_audioThumbCreated = false;
145 }
146
147 /*void DocClipBase::getClipMainThumb() {
148     if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
149 }*/
150
151 KThumb *DocClipBase::thumbProducer()
152 {
153     return m_thumbProd;
154 }
155
156 bool DocClipBase::audioThumbCreated() const
157 {
158     return m_audioThumbCreated;
159 }
160
161 const QString DocClipBase::name() const
162 {
163
164     return m_properties.value("name");
165 }
166
167 const QString &DocClipBase::getId() const
168 {
169     return m_id;
170 }
171
172 const CLIPTYPE & DocClipBase::clipType() const
173 {
174     return m_clipType;
175 }
176
177 void DocClipBase::setClipType(CLIPTYPE type)
178 {
179     m_clipType = type;
180     m_properties.insert("type", QString::number((int) type));
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         return GenTime();
232     }
233     return m_duration;
234 }
235
236 bool DocClipBase::hasFileSize() const
237 {
238     return true;
239 }
240
241 qulonglong DocClipBase::fileSize() const
242 {
243     return m_properties.value("file_size").toULongLong();
244 }
245
246 // virtual
247 QDomElement DocClipBase::toXML(bool hideTemporaryProperties) 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 (hideTemporaryProperties && i.key().startsWith('_')) continue;
256         if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
257     }
258     doc.appendChild(clip);
259     if (!m_cutZones.isEmpty()) {
260         QStringList cuts;
261         for (int i = 0; i < m_cutZones.size(); i++) {
262             CutZoneInfo info = m_cutZones.at(i);
263             cuts << QString::number(info.zone.x()) + "-" + QString::number(info.zone.y()) + "-" + info.description;
264         }
265         clip.setAttribute("cutzones", cuts.join(";"));
266     }
267     QString adata;
268     if (!m_analysisdata.isEmpty()) {
269         QMapIterator<QString, QString> i(m_analysisdata);
270         while (i.hasNext()) {
271             i.next();
272             //WARNING: a ? and # separator is not a good idea
273             adata.append(i.key() + "?" + i.value() + "#");
274         }
275     }
276     clip.setAttribute("analysisdata", adata);
277     //kDebug() << "/// CLIP XML: " << doc.toString();
278     return doc.documentElement();
279 }
280
281
282 void DocClipBase::setAudioThumbCreated(bool isDone)
283 {
284     m_audioThumbCreated = isDone;
285 }
286
287 void DocClipBase::updateAudioThumbnail(const audioByteArray& data)
288 {
289     //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
290     audioFrameCache = data;
291     m_audioThumbCreated = true;
292     emit gotAudioData();
293 }
294
295 QList < GenTime > DocClipBase::snapMarkers() const
296 {
297     QList < GenTime > markers;
298
299     for (int count = 0; count < m_snapMarkers.count(); ++count) {
300         markers.append(m_snapMarkers.at(count).time());
301     }
302
303     return markers;
304 }
305
306 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
307 {
308     return m_snapMarkers;
309 }
310
311
312 void DocClipBase::addSnapMarker(const CommentedTime marker)
313 {
314     QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
315     for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
316         if ((*it).time() >= marker.time())
317             break;
318     }
319
320     if ((it != m_snapMarkers.end()) && ((*it).time() == marker.time())) {
321         (*it).setComment(marker.comment());
322         (*it).setMarkerType(marker.markerType());
323         //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
324     } else {
325         m_snapMarkers.insert(it, marker);
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.at(it).time() >= currTime)
380             break;
381     }
382     if (it == 0) return GenTime();
383     else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
384         return m_snapMarkers.at(it).time();
385     else return m_snapMarkers.at(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.at(it).time() > currTime)
393             break;
394     }
395     if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
396     return duration();
397 }
398
399 QString DocClipBase::markerComment(GenTime t) const
400 {
401     QList < CommentedTime >::ConstIterator itt = m_snapMarkers.begin();
402     while (itt != m_snapMarkers.end()) {
403         if ((*itt).time() == t)
404             return (*itt).comment();
405         ++itt;
406     }
407     return QString();
408 }
409
410 CommentedTime DocClipBase::markerAt(GenTime t) const
411 {
412     QList < CommentedTime >::ConstIterator itt = m_snapMarkers.begin();
413     while (itt != m_snapMarkers.end()) {
414         if ((*itt).time() == t)
415             return (*itt);
416         ++itt;
417     }
418     return CommentedTime();
419 }
420
421 void DocClipBase::clearThumbProducer()
422 {
423     if (m_thumbProd) m_thumbProd->clearProducer();
424 }
425
426 void DocClipBase::reloadThumbProducer()
427 {
428     if (m_thumbProd && !m_thumbProd->hasProducer())
429         m_thumbProd->setProducer(getProducer());
430 }
431
432 void DocClipBase::deleteProducers()
433 {
434     if (m_thumbProd) m_thumbProd->clearProducer();
435     
436     if (numReferences() > 0 && (!m_baseTrackProducers.isEmpty() || !m_videoTrackProducers.isEmpty() || !m_audioTrackProducers.isEmpty())) {
437         // Clip is used in timeline, delay producers deletion
438         for (int i = 0; i < m_baseTrackProducers.count(); i++) {
439             m_toDeleteProducers.append(m_baseTrackProducers.at(i));
440         }
441         for (int i = 0; i < m_videoTrackProducers.count(); i++) {
442             m_toDeleteProducers.append(m_videoTrackProducers.at(i));
443         }
444         for (int i = 0; i < m_audioTrackProducers.count(); i++) {
445             m_toDeleteProducers.append(m_audioTrackProducers.at(i));
446         }
447     }
448     else {
449         qDeleteAll(m_baseTrackProducers);
450         qDeleteAll(m_videoTrackProducers);
451         qDeleteAll(m_audioTrackProducers);
452         m_replaceMutex.unlock();
453     }
454     m_baseTrackProducers.clear();
455     m_videoTrackProducers.clear();
456     m_audioTrackProducers.clear();
457 }
458
459 void DocClipBase::cleanupProducers()
460 {
461     /*
462     int ct = 0;
463     kDebug()<<"----------------------------------------------------------------------------------";
464     for (int i = 0; i < m_toDeleteProducers.count(); i++) {
465         if (m_toDeleteProducers.at(i) != NULL) {
466             Mlt::Properties props(m_toDeleteProducers.at(i)->get_properties());
467             if (props.ref_count() > 2) {
468                 kDebug()<<"PRODUCER: "<<i<<", COUNTS: "<<props.ref_count();
469                 //exit(1);
470             }
471             ct++;
472         }
473     }*/
474
475     if (!isClean()) {
476       qDeleteAll(m_toDeleteProducers);
477       m_toDeleteProducers.clear();
478       m_replaceMutex.unlock();
479     }
480 }
481
482 bool DocClipBase::isClean() const
483 {
484     return m_toDeleteProducers.isEmpty();
485 }
486
487 void DocClipBase::setValid()
488 {
489     m_placeHolder = false;
490 }
491
492 void DocClipBase::setProducer(Mlt::Producer *producer, bool reset, bool readPropertiesFromProducer)
493 {
494     if (producer == NULL) return;
495     if (reset) {
496         QMutexLocker locker(&m_producerMutex);
497         m_replaceMutex.lock();
498         deleteProducers();
499     }
500     QString id = producer->get("id");
501     if (m_placeHolder || !producer->is_valid()) {
502         char *tmp = qstrdup(i18n("Missing clip").toUtf8().constData());
503         producer->set("markup", tmp);
504         producer->set("bgcolour", "0xff0000ff");
505         producer->set("pad", "10");
506         delete[] tmp;
507     }
508     else if (m_thumbProd && !m_thumbProd->hasProducer()) {
509         if (m_clipType != AUDIO) {
510             if (!id.endsWith("_audio"))
511                 m_thumbProd->setProducer(producer);
512         }
513         else m_thumbProd->setProducer(producer);
514         getAudioThumbs();
515     }
516     bool updated = false;
517     if (id.contains('_')) {
518         // this is a subtrack producer, insert it at correct place
519         id = id.section('_', 1);
520         if (id.endsWith("audio")) {
521             int pos = id.section('_', 0, 0).toInt();
522             if (pos >= m_audioTrackProducers.count()) {
523                 while (m_audioTrackProducers.count() - 1 < pos) {
524                     m_audioTrackProducers.append(NULL);
525                 }
526             }
527             if (m_audioTrackProducers.at(pos) == NULL) {
528                 m_audioTrackProducers[pos] = producer;
529                 updated = true;
530             }
531             else delete producer;
532             return;
533         } else if (id.endsWith("video")) {
534             int pos = 0;
535             // Keep compatibility with older projects where video only producers were not track specific
536             if (id.contains('_')) pos = id.section('_', 0, 0).toInt();
537             if (pos >= m_videoTrackProducers.count()) {
538                 while (m_videoTrackProducers.count() - 1 < pos) {
539                     m_videoTrackProducers.append(NULL);
540                 }
541             }
542             if (m_videoTrackProducers.at(pos) == NULL) {
543                 m_videoTrackProducers[pos] = producer;
544                 updated = true;
545             }
546             else delete producer;
547             return;
548         }
549         int pos = id.toInt();
550         if (pos >= m_baseTrackProducers.count()) {
551             while (m_baseTrackProducers.count() - 1 < pos) {
552                 m_baseTrackProducers.append(NULL);
553             }
554         }
555         if (m_baseTrackProducers.at(pos) == NULL) {
556             m_baseTrackProducers[pos] = producer;
557             updated = true;
558         }
559         else delete producer;
560     } else {
561         if (m_baseTrackProducers.isEmpty()) {
562             m_baseTrackProducers.append(producer);
563             updated = true;
564         }
565         else if (m_baseTrackProducers.at(0) == NULL) {
566             m_baseTrackProducers[0] = producer;
567             updated = true;
568         }
569         else delete producer;
570     }
571     if (updated && readPropertiesFromProducer && (m_clipType != COLOR && m_clipType != IMAGE && m_clipType != TEXT))
572         setDuration(GenTime(producer->get_length(), KdenliveSettings::project_fps()));
573 }
574
575 static double getPixelAspect(QMap<QString, QString>& props) {
576     int width = props.value("frame_size").section('x', 0, 0).toInt();
577     int height = props.value("frame_size").section('x', 1, 1).toInt();
578     int aspectNumerator = props.value("force_aspect_num").toInt();
579     int aspectDenominator = props.value("force_aspect_den").toInt();
580     if (aspectDenominator != 0 && width != 0)
581         return double(height) * aspectNumerator / aspectDenominator / width;    
582     else
583         return 1.0;
584 }
585
586 Mlt::Producer *DocClipBase::audioProducer(int track)
587 {
588     QMutexLocker locker(&m_producerMutex);
589     if (m_audioTrackProducers.count() <= track) {
590         while (m_audioTrackProducers.count() - 1 < track) {
591             m_audioTrackProducers.append(NULL);
592         }
593     }
594     if (m_audioTrackProducers.at(track) == NULL) {
595         int i;
596         for (i = 0; i < m_audioTrackProducers.count(); i++)
597             if (m_audioTrackProducers.at(i) != NULL) break;
598         Mlt::Producer *base;
599         if (i >= m_audioTrackProducers.count()) {
600             // Could not find a valid producer for that clip
601             locker.unlock();
602             base = getProducer();
603             if (base == NULL) {
604                 return NULL;
605             }
606             locker.relock();
607         }
608         else base = m_audioTrackProducers.at(i);
609         m_audioTrackProducers[track] = cloneProducer(base);
610         adjustProducerProperties(m_audioTrackProducers.at(track), QString(getId() + '_' + QString::number(track) + "_audio"), false, true);
611     }
612     return m_audioTrackProducers.at(track);
613 }
614
615
616 void DocClipBase::adjustProducerProperties(Mlt::Producer *prod, const QString &id, bool mute, bool blind)
617 {
618         if (m_properties.contains("force_aspect_num") && m_properties.contains("force_aspect_den") && m_properties.contains("frame_size"))
619             prod->set("force_aspect_ratio", getPixelAspect(m_properties));
620         if (m_properties.contains("force_fps")) prod->set("force_fps", m_properties.value("force_fps").toDouble());
621         if (m_properties.contains("force_progressive")) prod->set("force_progressive", m_properties.value("force_progressive").toInt());
622         if (m_properties.contains("force_tff")) prod->set("force_tff", m_properties.value("force_tff").toInt());
623         if (m_properties.contains("threads")) prod->set("threads", m_properties.value("threads").toInt());
624         if (mute) prod->set("audio_index", -1);
625         else if (m_properties.contains("audio_index")) prod->set("audio_index", m_properties.value("audio_index").toInt());
626         if (blind) prod->set("video_index", -1);
627         else if (m_properties.contains("video_index")) prod->set("video_index", m_properties.value("video_index").toInt());
628         prod->set("id", id.toUtf8().constData());
629         if (m_properties.contains("force_colorspace")) prod->set("force_colorspace", m_properties.value("force_colorspace").toInt());
630         if (m_properties.contains("full_luma")) prod->set("set.force_full_luma", m_properties.value("full_luma").toInt());
631         if (m_properties.contains("proxy_out")) {
632             // We have a proxy clip, make sure the proxy has same duration as original
633             prod->set("length", m_properties.value("duration").toInt());
634             prod->set("out", m_properties.value("proxy_out").toInt());
635         }
636
637 }
638
639 Mlt::Producer *DocClipBase::videoProducer(int track)
640 {
641     QMutexLocker locker(&m_producerMutex);
642     if (m_videoTrackProducers.count() <= track) {
643         while (m_videoTrackProducers.count() - 1 < track) {
644             m_videoTrackProducers.append(NULL);
645         }
646     }
647     if (m_videoTrackProducers.at(track) == NULL) {
648         int i;
649         for (i = 0; i < m_videoTrackProducers.count(); i++)
650             if (m_videoTrackProducers.at(i) != NULL) break;
651         Mlt::Producer *base;
652         if (i >= m_videoTrackProducers.count()) {
653             // Could not find a valid producer for that clip
654             locker.unlock();
655             base = getProducer();
656             if (base == NULL) {
657                 return NULL;
658             }
659             locker.relock();
660         }
661         else base = m_videoTrackProducers.at(i);
662         m_videoTrackProducers[track] = cloneProducer(base);
663         adjustProducerProperties(m_videoTrackProducers.at(track), QString(getId() + '_' + QString::number(track) + "_video"), true, false);
664     }
665     return m_videoTrackProducers.at(track);
666 }
667
668 Mlt::Producer *DocClipBase::getCloneProducer()
669 {
670     Mlt::Producer *source = NULL;
671     Mlt::Producer *prod = NULL;
672     if (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST) {
673         source = getProducer();
674         if (!source) return NULL;
675     }
676     if (m_clipType == COLOR) {
677         prod = new Mlt::Producer(*(source->profile()), 0, QString("colour:" + QString(source->get("resource"))).toUtf8().constData());
678     } else if (m_clipType == TEXT) {
679         prod = new Mlt::Producer(*(source->profile()), 0, QString("kdenlivetitle:" + QString(source->get("resource"))).toUtf8().constData());
680         if (prod && prod->is_valid() && m_properties.contains("xmldata"))
681             prod->set("xmldata", m_properties.value("xmldata").toUtf8().constData());
682     }
683     if (!prod) {
684         if (!source) {
685             QMutexLocker locker(&m_producerMutex);
686             for (int i = 0; i < m_baseTrackProducers.count(); i++) {
687                 if (m_baseTrackProducers.at(i) != NULL) {
688                     source = m_baseTrackProducers.at(i);
689                     break;
690                 }
691             }
692             if (!source) return NULL;
693         }
694         prod = cloneProducer(source);
695     }
696     if (prod) {
697         adjustProducerProperties(prod, getId() + "_", false, false);
698         if (!m_properties.contains("proxy_out")) {
699             // Adjust length in case...
700             if (m_properties.contains("duration")) prod->set("length", m_properties.value("duration").toInt());
701             if (m_properties.contains("out"))prod->set("out", m_properties.value("out").toInt());
702         }
703         if (m_clipType == AUDIO) {
704             prod->set("_audioclip", 1);
705         }
706     }
707     return prod;
708 }
709
710
711 Mlt::Producer *DocClipBase::getProducer(int track)
712 {
713     QMutexLocker locker(&m_producerMutex);
714     if (track == -1 || (m_clipType != AUDIO && m_clipType != AV && m_clipType != PLAYLIST)) {
715         if (m_baseTrackProducers.count() == 0) {
716             return NULL;
717         }
718         for (int i = 0; i < m_baseTrackProducers.count(); i++) {
719             if (m_baseTrackProducers.at(i) != NULL) {
720                 return m_baseTrackProducers.at(i);
721             }
722         }
723         return NULL;
724     }
725     if (track >= m_baseTrackProducers.count()) {
726         while (m_baseTrackProducers.count() - 1 < track) {
727             m_baseTrackProducers.append(NULL);
728         }
729     }
730     if (m_baseTrackProducers.at(track) == NULL) {
731         int i;
732         for (i = 0; i < m_baseTrackProducers.count(); i++)
733             if (m_baseTrackProducers.at(i) != NULL) break;
734
735         if (i >= m_baseTrackProducers.count()) {
736             // Could not find a valid producer for that clip, check in 
737             return NULL;
738         }
739         Mlt::Producer *prod = cloneProducer(m_baseTrackProducers.at(i));
740         adjustProducerProperties(prod, QString(getId() + '_' + QString::number(track)), false, false);
741         m_baseTrackProducers[track] = prod;
742     }
743     return m_baseTrackProducers.at(track);
744 }
745
746
747 Mlt::Producer *DocClipBase::cloneProducer(Mlt::Producer *source)
748 {
749     Mlt::Producer *result = NULL;
750     QString url = QString::fromUtf8(source->get("resource"));
751     if (url == "<playlist>" || url == "<tractor>" || url == "<producer>") {
752         // Xml producer sometimes loses the correct url
753         url = m_properties.value("resource");
754     }
755     if (m_clipType == SLIDESHOW || KIO::NetAccess::exists(KUrl(url), KIO::NetAccess::SourceSide, 0)) {
756         result = new Mlt::Producer(*(source->profile()), url.toUtf8().constData());
757     }
758     if (result == NULL || !result->is_valid()) {
759         // placeholder clip
760         QString txt = "+" + i18n("Missing clip") + ".txt";
761         char *tmp = qstrdup(txt.toUtf8().constData());
762         result = new Mlt::Producer(*source->profile(), tmp);
763         delete[] tmp;
764         if (result == NULL || !result->is_valid())
765             result = new Mlt::Producer(*(source->profile()), "colour:red");
766         else {
767             result->set("bgcolour", "0xff0000ff");
768             result->set("pad", "10");
769         }
770         return result;
771     }
772     /*Mlt::Properties src_props(source->get_properties());
773     Mlt::Properties props(result->get_properties());
774     props.inherit(src_props);*/
775     return result;
776 }
777
778 void DocClipBase::setProducerProperty(const char *name, int data)
779 {
780     QMutexLocker locker(&m_producerMutex);
781     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
782         if (m_baseTrackProducers.at(i) != NULL)
783             m_baseTrackProducers[i]->set(name, data);
784     }
785 }
786
787 void DocClipBase::setProducerProperty(const char *name, double data)
788 {
789     QMutexLocker locker(&m_producerMutex);
790     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
791         if (m_baseTrackProducers.at(i) != NULL)
792             m_baseTrackProducers[i]->set(name, data);
793     }
794 }
795
796 void DocClipBase::setProducerProperty(const char *name, const char *data)
797 {
798     QMutexLocker locker(&m_producerMutex);
799     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
800         if (m_baseTrackProducers.at(i) != NULL)
801             m_baseTrackProducers[i]->set(name, data);
802     }
803 }
804
805 void DocClipBase::resetProducerProperty(const char *name)
806 {
807     QMutexLocker locker(&m_producerMutex);
808     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
809         if (m_baseTrackProducers.at(i) != NULL)
810             m_baseTrackProducers[i]->set(name, (const char*) NULL);
811     }
812 }
813
814 const char *DocClipBase::producerProperty(const char *name) const
815 {
816     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
817         if (m_baseTrackProducers.at(i) != NULL) {
818             return m_baseTrackProducers.at(i)->get(name);
819         }
820     }
821     return NULL;
822 }
823
824
825 void DocClipBase::slotRefreshProducer()
826 {
827     if (m_baseTrackProducers.count() == 0) return;
828     if (m_clipType == SLIDESHOW) {
829         setProducerProperty("ttl", getProperty("ttl").toInt());
830         //m_clipProducer->set("id", getProperty("id"));
831         if (!getProperty("animation").isEmpty()) {
832             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
833             int ct = 0;
834             Mlt::Filter *filter = clipService.filter(ct);
835             while (filter) {
836                 if (strcmp(filter->get("mlt_service"), "affine") == 0) {
837                     break;
838                 } else if (strcmp(filter->get("mlt_service"), "boxblur") == 0) {
839                     clipService.detach(*filter);
840                 } else ct++;
841                 filter = clipService.filter(ct);
842             }
843
844             if (!filter || strcmp(filter->get("mlt_service"), "affine")) {
845                 // filter does not exist, create it.
846                 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "affine");
847                 if (filter && filter->is_valid()) {
848                     int cycle = getProperty("ttl").toInt();
849                     QString geometry = SlideshowClip::animationToGeometry(getProperty("animation"), cycle);
850                     if (!geometry.isEmpty()) {
851                         if (getProperty("animation").contains("low-pass")) {
852                             Mlt::Filter *blur = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "boxblur");
853                             if (blur && blur->is_valid())
854                                 clipService.attach(*blur);
855                         }
856                         filter->set("transition.geometry", geometry.toUtf8().data());
857                         filter->set("transition.cycle", cycle);
858                         clipService.attach(*filter);
859                     }
860                 }
861             }
862         } else {
863             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
864             int ct = 0;
865             Mlt::Filter *filter = clipService.filter(0);
866             while (filter) {
867                 if (strcmp(filter->get("mlt_service"), "affine") == 0 || strcmp(filter->get("mlt_service"), "boxblur") == 0) {
868                     clipService.detach(*filter);
869                 } else ct++;
870                 filter = clipService.filter(ct);
871             }
872         }
873         if (getProperty("fade") == "1") {
874             // we want a fade filter effect
875             kDebug() << "////////////   FADE WANTED";
876             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
877             int ct = 0;
878             Mlt::Filter *filter = clipService.filter(ct);
879             while (filter) {
880                 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
881                     break;
882                 }
883                 ct++;
884                 filter = clipService.filter(ct);
885             }
886
887             if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
888                 filter->set("cycle", getProperty("ttl").toInt());
889                 filter->set("duration", getProperty("luma_duration").toInt());
890                 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
891                 if (!getProperty("softness").isEmpty()) {
892                     int soft = getProperty("softness").toInt();
893                     filter->set("luma.softness", (double) soft / 100.0);
894                 }
895             } else {
896                 // filter does not exist, create it...
897                 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
898                 filter->set("cycle", getProperty("ttl").toInt());
899                 filter->set("duration", getProperty("luma_duration").toInt());
900                 filter->set("luma.resource", getProperty("luma_file").toUtf8().data());
901                 if (!getProperty("softness").isEmpty()) {
902                     int soft = getProperty("softness").toInt();
903                     filter->set("luma.softness", (double) soft / 100.0);
904                 }
905                 clipService.attach(*filter);
906             }
907         } else {
908             kDebug() << "////////////   FADE NOT WANTED!!!";
909             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
910             int ct = 0;
911             Mlt::Filter *filter = clipService.filter(0);
912             while (filter) {
913                 if (strcmp(filter->get("mlt_service"), "luma") == 0) {
914                     clipService.detach(*filter);
915                 } else ct++;
916                 filter = clipService.filter(ct);
917             }
918         }
919         if (getProperty("crop") == "1") {
920             // we want a center crop filter effect
921             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
922             int ct = 0;
923             Mlt::Filter *filter = clipService.filter(ct);
924             while (filter) {
925                 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
926                     break;
927                 }
928                 ct++;
929                 filter = clipService.filter(ct);
930             }
931
932             if (!filter || strcmp(filter->get("mlt_service"), "crop")) {
933                 // filter does not exist, create it...
934                 Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "crop");
935                 filter->set("center", 1);
936                 clipService.attach(*filter);
937             }
938         } else {
939             Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
940             int ct = 0;
941             Mlt::Filter *filter = clipService.filter(0);
942             while (filter) {
943                 if (strcmp(filter->get("mlt_service"), "crop") == 0) {
944                     clipService.detach(*filter);
945                 } else ct++;
946                 filter = clipService.filter(ct);
947             }
948         }
949     }
950 }
951
952 void DocClipBase::setProperties(QMap <QString, QString> properties)
953 {
954     // changing clip type is not allowed
955     properties.remove("type");
956     QMapIterator<QString, QString> i(properties);
957     bool refreshProducer = false;
958     QStringList keys;
959     keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness" << "crop" << "animation";
960     QString oldProxy = m_properties.value("proxy");
961     while (i.hasNext()) {
962         i.next();
963         setProperty(i.key(), i.value());
964         if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
965     }
966     if (properties.contains("proxy")) {
967         QString value = properties.value("proxy");
968         // If value is "-", that means user manually disabled proxy on this clip
969         if (value.isEmpty() || value == "-") {
970             // reset proxy
971             emit abortProxy(m_id, oldProxy);
972         }
973         else {
974             emit createProxy(m_id);
975         }
976     }
977     if (refreshProducer) slotRefreshProducer();
978 }
979
980 void DocClipBase::setMetadata(QMap <QString, QString> properties)
981 {
982     QMapIterator<QString, QString> i(properties);
983     while (i.hasNext()) {
984         i.next();
985         if (i.value().isEmpty() && m_metadata.contains(i.key())) {
986             m_metadata.remove(i.key());
987         } else {
988             m_metadata.insert(i.key(), i.value());
989         }
990     }
991 }
992
993 QMap <QString, QString> DocClipBase::metadata() const
994 {
995     return m_metadata;
996 }
997
998 void DocClipBase::clearProperty(const QString &key)
999 {
1000     m_properties.remove(key);
1001 }
1002
1003 void DocClipBase::getFileHash(const QString &url)
1004 {
1005     if (m_clipType == SLIDESHOW) return;
1006     QFile file(url);
1007     if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
1008         QByteArray fileData;
1009         QByteArray fileHash;
1010         //kDebug() << "SETTING HASH of" << value;
1011         m_properties.insert("file_size", QString::number(file.size()));
1012         /*
1013                * 1 MB = 1 second per 450 files (or faster)
1014                * 10 MB = 9 seconds per 450 files (or faster)
1015                */
1016         if (file.size() > 1000000*2) {
1017             fileData = file.read(1000000);
1018             if (file.seek(file.size() - 1000000))
1019                 fileData.append(file.readAll());
1020         } else
1021             fileData = file.readAll();
1022         file.close();
1023         fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
1024         m_properties.insert("file_hash", QString(fileHash.toHex()));
1025     }
1026 }
1027
1028 bool DocClipBase::checkHash() const
1029 {
1030     KUrl url = fileURL();
1031     if (!url.isEmpty() && getClipHash() != getHash(url.path())) return false;
1032     return true;
1033 }
1034
1035 QString DocClipBase::getClipHash() const
1036 {
1037     QString hash;
1038     if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
1039     else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
1040     else if (m_clipType == TEXT) hash = QCryptographicHash::hash(QString("title" + getId() + m_properties.value("xmldata")).toUtf8().data(), QCryptographicHash::Md5).toHex();
1041     else {
1042         if (m_properties.contains("file_hash")) hash = m_properties.value("file_hash");
1043         if (hash.isEmpty()) hash = getHash(fileURL().path());
1044         
1045     }
1046     return hash;
1047 }
1048
1049 void DocClipBase::setPlaceHolder(bool place)
1050 {
1051     m_placeHolder = place;
1052 }
1053
1054 // static
1055 QString DocClipBase::getHash(const QString &path)
1056 {
1057     QFile file(path);
1058     if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
1059         QByteArray fileData;
1060         QByteArray fileHash;
1061         /*
1062                * 1 MB = 1 second per 450 files (or faster)
1063                * 10 MB = 9 seconds per 450 files (or faster)
1064                */
1065         if (file.size() > 1000000*2) {
1066             fileData = file.read(1000000);
1067             if (file.seek(file.size() - 1000000))
1068                 fileData.append(file.readAll());
1069         } else
1070             fileData = file.readAll();
1071         file.close();
1072         return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
1073     }
1074     return QString();
1075 }
1076
1077 void DocClipBase::refreshThumbUrl()
1078 {
1079     if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
1080 }
1081
1082 void DocClipBase::setProperty(const QString &key, const QString &value)
1083 {
1084     m_properties.insert(key, value);
1085     if (key == "resource") {
1086         getFileHash(value);
1087         if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
1088     } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
1089     //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
1090     else if (key == "colour") {
1091         setProducerProperty("colour", value.toUtf8().data());
1092     } else if (key == "templatetext") {
1093         setProducerProperty("templatetext", value.toUtf8().data());
1094         setProducerProperty("force_reload", 1);
1095     } else if (key == "xmldata") {
1096         setProducerProperty("xmldata", value.toUtf8().data());
1097         setProducerProperty("force_reload", 1);
1098     } else if (key == "force_aspect_num") {
1099         if (value.isEmpty()) {
1100             m_properties.remove("force_aspect_num");
1101             resetProducerProperty("force_aspect_ratio");
1102         } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
1103     } else if (key == "force_aspect_den") {
1104         if (value.isEmpty()) {
1105             m_properties.remove("force_aspect_den");
1106             resetProducerProperty("force_aspect_ratio");
1107         } else setProducerProperty("force_aspect_ratio", getPixelAspect(m_properties));
1108     } else if (key == "force_fps") {
1109         if (value.isEmpty()) {
1110             m_properties.remove("force_fps");
1111             resetProducerProperty("force_fps");
1112         } else setProducerProperty("force_fps", value.toDouble());
1113     } else if (key == "force_progressive") {
1114         if (value.isEmpty()) {
1115             m_properties.remove("force_progressive");
1116             resetProducerProperty("force_progressive");
1117         } else setProducerProperty("force_progressive", value.toInt());
1118     } else if (key == "force_tff") {
1119         if (value.isEmpty()) {
1120             m_properties.remove("force_tff");
1121             resetProducerProperty("force_tff");
1122         } else setProducerProperty("force_tff", value.toInt());
1123     } else if (key == "threads") {
1124         if (value.isEmpty()) {
1125             m_properties.remove("threads");
1126             setProducerProperty("threads", 1);
1127         } else setProducerProperty("threads", value.toInt());
1128     } else if (key == "video_index") {
1129         if (value.isEmpty()) {
1130             m_properties.remove("video_index");
1131             setProducerProperty("video_index", m_properties.value("default_video").toInt());
1132         } else setProducerProperty("video_index", value.toInt());
1133     } else if (key == "audio_index") {
1134         if (value.isEmpty()) {
1135             m_properties.remove("audio_index");
1136             setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
1137         } else setProducerProperty("audio_index", value.toInt());
1138     } else if (key == "force_colorspace") {
1139         if (value.isEmpty()) {
1140             m_properties.remove("force_colorspace");
1141             resetProducerProperty("force_colorspace");
1142         } else setProducerProperty("force_colorspace", value.toInt());
1143     } else if (key == "full_luma") {
1144         if (value.isEmpty()) {
1145             m_properties.remove("full_luma");
1146             resetProducerProperty("set.force_full_luma");
1147         } else setProducerProperty("set.force_full_luma", value.toInt());
1148     }
1149 }
1150
1151 QMap <QString, QString> DocClipBase::properties() const
1152 {
1153     return m_properties;
1154 }
1155
1156 QMap <QString, QString> DocClipBase::currentProperties(QMap <QString, QString> props)
1157 {
1158     QMap <QString, QString> currentProps;
1159     QMap<QString, QString>::const_iterator i = props.constBegin();
1160     while (i != props.constEnd()) {
1161         currentProps.insert(i.key(), m_properties.value(i.key()));
1162         ++i;
1163     }
1164     return currentProps;
1165 }
1166
1167 bool DocClipBase::getAudioThumbs()
1168 {
1169     if (m_thumbProd == NULL || isPlaceHolder() || !KdenliveSettings::audiothumbnails()) return false;
1170     if (m_audioThumbCreated) {
1171         return false;
1172     }
1173     m_audioTimer.start();
1174     return true;
1175 }
1176
1177 bool DocClipBase::isPlaceHolder() const
1178 {
1179     return m_placeHolder;
1180 }
1181
1182 void DocClipBase::addCutZone(int in, int out, QString desc)
1183 {
1184     CutZoneInfo info;
1185     info.zone = QPoint(in, out);
1186     info.description = desc;
1187     for (int i = 0; i < m_cutZones.count(); i++)
1188         if (m_cutZones.at(i).zone == info.zone) {
1189             return;
1190         }
1191     m_cutZones.append(info);
1192 }
1193
1194 bool DocClipBase::hasCutZone(QPoint p) const
1195 {
1196     for (int i = 0; i < m_cutZones.count(); i++)
1197         if (m_cutZones.at(i).zone == p) return true;
1198     return false;
1199 }
1200
1201
1202 void DocClipBase::removeCutZone(int in, int out)
1203 {
1204     QPoint p(in, out);
1205     for (int i = 0; i < m_cutZones.count(); i++) {
1206         if (m_cutZones.at(i).zone == p) {
1207             m_cutZones.removeAt(i);
1208             i--;
1209         }
1210     }
1211 }
1212
1213 void DocClipBase::updateCutZone(int oldin, int oldout, int in, int out, QString desc)
1214 {
1215     QPoint old(oldin, oldout);
1216     for (int i = 0; i < m_cutZones.size(); ++i) {
1217         if (m_cutZones.at(i).zone == old) {
1218             CutZoneInfo info;
1219             info.zone = QPoint(in, out);
1220             info.description = desc;
1221             m_cutZones.replace(i, info);
1222             break;
1223         }
1224     }
1225 }
1226
1227 QList <CutZoneInfo> DocClipBase::cutZones() const
1228 {
1229     return m_cutZones;
1230 }
1231
1232 bool DocClipBase::hasVideoCodec(const QString &codec) const
1233 {
1234     Mlt::Producer *prod = NULL;
1235     if (m_baseTrackProducers.count() == 0) return false;
1236     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1237         if (m_baseTrackProducers.at(i) != NULL) {
1238             prod = m_baseTrackProducers.at(i);
1239             break;
1240         }
1241     }
1242
1243     if (!prod) return false;
1244     int default_video = prod->get_int("video_index");
1245     char property[200];
1246     snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1247     return prod->get(property) == codec;
1248 }
1249
1250 bool DocClipBase::hasAudioCodec(const QString &codec) const
1251 {
1252     Mlt::Producer *prod = NULL;
1253     if (m_baseTrackProducers.count() == 0) return false;
1254     for (int i = 0; i < m_baseTrackProducers.count(); i++) {
1255         if (m_baseTrackProducers.at(i) != NULL) {
1256             prod = m_baseTrackProducers.at(i);
1257             break;
1258         }
1259     }
1260     if (!prod) return false;
1261     int default_video = prod->get_int("audio_index");
1262     char property[200];
1263     snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
1264     return prod->get(property) == codec;
1265 }
1266
1267
1268 void DocClipBase::slotExtractImage(QList <int> frames)
1269 {
1270     if (m_thumbProd == NULL) return;
1271     m_thumbProd->extractImage(frames);
1272 }
1273
1274 QImage DocClipBase::extractImage(int frame, int width, int height)
1275 {
1276     if (m_thumbProd == NULL) return QImage();
1277     QMutexLocker locker(&m_producerMutex);
1278     return m_thumbProd->extractImage(frame, width, height);
1279 }
1280
1281 void DocClipBase::setAnalysisData(const QString &name, const QString &data, int offset)
1282 {
1283     if (data.isEmpty()) m_analysisdata.remove(name);
1284     else {
1285         if (m_analysisdata.contains(name)) {
1286             if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip already contains analysis data %1", name), QString(), KGuiItem(i18n("Merge")), KGuiItem(i18n("Add"))) == KMessageBox::Yes) {
1287                 // Merge data
1288                 Mlt::Profile *profile = m_baseTrackProducers.at(0)->profile();
1289                 Mlt::Geometry geometry(m_analysisdata.value(name).toUtf8().data(), m_properties.value("duration").toInt(), profile->width(), profile->height());
1290                 Mlt::Geometry newGeometry(data.toUtf8().data(), m_properties.value("duration").toInt(), profile->width(), profile->height());
1291                 Mlt::GeometryItem item;
1292                 int pos = 0;
1293                 while (!newGeometry.next_key(&item, pos)) {
1294                     pos = item.frame();
1295                     item.frame(pos + offset);
1296                     pos++;
1297                     geometry.insert(item);
1298                 }
1299                 m_analysisdata.insert(name, geometry.serialise());
1300             }
1301             else {
1302                 // Add data with another name
1303                 int i = 1;
1304                 QString newname = name + " " + QString::number(i);
1305                 while (m_analysisdata.contains(newname)) {
1306                     i++;
1307                     newname = name + " " + QString::number(i);
1308                 }
1309                 m_analysisdata.insert(newname, geometryWithOffset(data, offset));
1310             }
1311         }
1312         else m_analysisdata.insert(name, geometryWithOffset(data, offset));
1313     }
1314 }
1315
1316 const QString DocClipBase::geometryWithOffset(QString data, int offset)
1317 {
1318     if (offset == 0) return data;
1319     Mlt::Profile *profile = m_baseTrackProducers.at(0)->profile();
1320     Mlt::Geometry geometry(data.toUtf8().data(), m_properties.value("duration").toInt(), profile->width(), profile->height());
1321     Mlt::Geometry newgeometry("", m_properties.value("duration").toInt(), profile->width(), profile->height());
1322     Mlt::GeometryItem item;
1323     int pos = 0;
1324     while (!geometry.next_key(&item, pos)) {
1325         pos = item.frame();
1326         item.frame(pos + offset);
1327         pos++;
1328         newgeometry.insert(item);
1329     }
1330     return newgeometry.serialise();
1331 }
1332
1333 QMap <QString, QString> DocClipBase::analysisData() const
1334 {
1335     return m_analysisdata;
1336 }
1337