]> git.sesse.net Git - kdenlive/blobdiff - src/docclipbase.cpp
Clean up timecode handling, improves:
[kdenlive] / src / docclipbase.cpp
index a1cf7b20569b4b4a0dc191500f8d1e46a3f1dd57..f22410f1d237f091fea6640e1f10407919507f5d 100644 (file)
-/**************************1*************************************************
-                          DocClipBase.cpp  -  description
-                             -------------------
-    begin                : Fri Apr 12 2002
-    copyright            : (C) 2002 by Jason Wood
-    email                : jasonwood@blueyonder.co.uk
- ***************************************************************************/
-
 /***************************************************************************
+ *                         DocClipBase.cpp  -  description                 *
+ *                           -------------------                           *
+ *   begin                : Fri Apr 12 2002                                *
+ *   Copyright (C) 2002 by Jason Wood (jasonwood@blueyonder.co.uk)         *
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
  ***************************************************************************/
 
-#include <KDebug>
 
-#include "kdenlivesettings.h"
+
+
 #include "docclipbase.h"
+#include "kdenlivesettings.h"
+#include "kthumb.h"
+#include "clipmanager.h"
 
-DocClipBase::DocClipBase(QDomElement xml, uint id):
-m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0), audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL)
-{
-  int type = xml.attribute("type").toInt();
-  m_clipType = (CLIPTYPE) type;
-  m_name = xml.attribute("name");
-  m_xml.setAttribute("id", QString::number(id));
-  KUrl url = KUrl(xml.attribute("resource"));
-  int out = xml.attribute("out").toInt();
-  if (out != 0) setDuration(GenTime(out, 25));
-  if (m_name.isEmpty()) m_name = url.fileName();
-       if (!url.isEmpty()){
-    m_thumbProd = new KThumb(url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height());
-               connect (m_thumbProd, SIGNAL (audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> > )));
-               connect (this, SIGNAL (getAudioThumbs()), this , SLOT( slotGetAudioThumbs() ) );
-               
-       }
-       kDebug() << "type is video" << (m_clipType==AV) << " " << m_clipType;
-       
-       if (m_clipType == AV || m_clipType==AUDIO ||m_clipType==UNKNOWN){
-               m_audioTimer = new QTimer( this );
-               connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
-               //TODO disabled until the crash cause is found 
-               //emit getAudioThumbs();
-       }
-}
-
-DocClipBase::DocClipBase(const DocClipBase& clip)
-{
-    m_xml = clip.toXML();
-    m_id = clip.getId();
-    m_clipType = clip.clipType();
-    m_name = clip.name();
-    m_duration = clip.duration();
+#include <KIO/NetAccess>
+#include <KDebug>
+
+#include <QCryptographicHash>
+
+DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &id) :
+        QObject(),
+        m_audioFrameCache(),
+        m_refcount(0),
+        m_baseTrackProducers(),
+        m_audioTrackProducers(),
+        m_videoOnlyProducer(NULL),
+        m_snapMarkers(),
+        m_duration(),
+        m_audioTimer(NULL),
+        m_thumbProd(NULL),
+        m_audioThumbCreated(false),
+        m_id(id),
+        m_placeHolder(xml.hasAttribute("placeholder")),
+        m_properties()
+{
+    int type = xml.attribute("type").toInt();
+    m_clipType = (CLIPTYPE) type;
+    if (m_placeHolder) xml.removeAttribute("placeholder");
+    QDomNamedNodeMap attributes = xml.attributes();
+    for (int i = 0; i < attributes.count(); i++) {
+        m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue());
+    }
+
+    KUrl url = KUrl(xml.attribute("resource"));
+    if (!m_properties.contains("file_hash") && !url.isEmpty()) getFileHash(url.path());
+
+    if (xml.hasAttribute("duration")) {
+        setDuration(GenTime(xml.attribute("duration").toInt(), KdenliveSettings::project_fps()));
+    } else {
+        int out = xml.attribute("out").toInt();
+        int in = xml.attribute("in").toInt();
+        setDuration(GenTime(out - in, KdenliveSettings::project_fps()));
+    }
+
+    if (!m_properties.contains("name")) m_properties.insert("name", url.fileName());
+
+    //if (!url.isEmpty() && QFile::exists(url.path()))
+    {
+        m_thumbProd = new KThumb(clipManager, url, m_id, m_properties.value("file_hash"));
+        if (m_clipType == AV || m_clipType == AUDIO) slotCreateAudioTimer();
+    }
+    //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
 }
 
-DocClipBase & DocClipBase::operator=(const DocClipBase & clip)
-{
+/*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
     DocClipBase::operator=(clip);
-    m_xml = clip.toXML();
     m_id = clip.getId();
     m_clipType = clip.clipType();
     m_name = clip.name();
     m_duration = clip.duration();
+    m_audioThumbCreated = clip.audioThumbCreated();
+    m_properties = clip.properties();
     return *this;
-}
+}*/
 
 DocClipBase::~DocClipBase()
 {
-  //if (m_thumbProd) delete m_thumbProd;
+    kDebug() << "CLIP " << m_id << " DELETED******************************";
+    delete m_thumbProd;
+    if (m_audioTimer) {
+        m_audioTimer->stop();
+        delete m_audioTimer;
+    }
+    /*kDebug() <<" * * *CNT "<<m_baseTrackProducers.count();
+    if (m_baseTrackProducers.count() > 0) kDebug()<<"YOYO: "<<m_baseTrackProducers.at(0)->get_out()<<", CUT: "<<m_baseTrackProducers.at(0)->is_cut();*/
+    qDeleteAll(m_baseTrackProducers);
+    m_baseTrackProducers.clear();
+    qDeleteAll(m_audioTrackProducers);
+    m_audioTrackProducers.clear();
+    delete m_videoOnlyProducer;
+    m_videoOnlyProducer = NULL;
+}
+
+void DocClipBase::setZone(QPoint zone)
+{
+    m_properties.insert("zone_in", QString::number(zone.x()));
+    m_properties.insert("zone_out", QString::number(zone.y()));
+}
+
+QPoint DocClipBase::zone() const
+{
+    QPoint zone;
+    zone.setX(m_properties.value("zone_in").toInt());
+    zone.setY(m_properties.value("zone_out", "50").toInt());
+    return zone;
+}
+
+void DocClipBase::slotCreateAudioTimer()
+{
+    connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
+    connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
+    m_audioTimer = new QTimer(this);
+    connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
+}
+
+void DocClipBase::askForAudioThumbs()
+{
+    if (m_thumbProd) m_thumbProd->askForAudioThumbs(getId());
+}
+
+void DocClipBase::slotClearAudioCache()
+{
+    if (m_thumbProd) m_thumbProd->stopAudioThumbs();
+    if (m_audioTimer != NULL) m_audioTimer->stop();
+    m_audioFrameCache.clear();
+    m_audioThumbCreated = false;
 }
 
+/*void DocClipBase::getClipMainThumb() {
+    if (m_thumbProd) m_thumbProd->getMainThumb(m_properties.value("thumbnail").toInt());
+}*/
+
 KThumb *DocClipBase::thumbProducer()
 {
-  return m_thumbProd;
+    return m_thumbProd;
 }
 
-void DocClipBase::setName(const QString name)
+bool DocClipBase::audioThumbCreated() const
 {
-    m_name = name;
+    return m_audioThumbCreated;
 }
 
-const QString DocClipBase::name() const
+const QString DocClipBase::name() const
 {
-  
-    return m_name;
+
+    return m_properties.value("name");
 }
 
-uint DocClipBase::getId() const
+const QString &DocClipBase::getId() const
 {
     return m_id;
 }
 
-void DocClipBase::setId( const uint &newId)
+void DocClipBase::setId(const QString &newId)
 {
     m_id = newId;
 }
 
 const CLIPTYPE & DocClipBase::clipType() const
 {
-  return m_clipType;
+    return m_clipType;
 }
 
 void DocClipBase::setClipType(CLIPTYPE type)
 {
-  m_clipType = type;
+    m_clipType = type;
+
+    m_properties.insert("type", QString::number((int) type));
+    if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO))
+        slotCreateAudioTimer();
+}
+
+KUrl DocClipBase::fileURL() const
+{
+    QString res = m_properties.value("resource");
+    if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
+    return KUrl();
 }
 
-const KUrl & DocClipBase::fileURL() const
+void DocClipBase::setClipThumbFrame(const uint &ix)
 {
-  QString res = m_xml.attribute("resource");
-  if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
-  return KUrl();
+    m_properties.insert("thumbnail", QString::number((int) ix));
 }
 
-void DocClipBase::setProjectThumbFrame( const uint &ix)
+uint DocClipBase::getClipThumbFrame() const
 {
-    m_projectThumbFrame = ix;
+    return (uint) m_properties.value("thumbnail").toInt();
 }
 
-uint DocClipBase::getProjectThumbFrame() const
+const QString DocClipBase::description() const
 {
-    return m_projectThumbFrame;
+    return m_properties.value("description");
 }
 
-void DocClipBase::setDescription(const QString & description)
+bool DocClipBase::isTransparent() const
 {
-    m_description = description;
+    return (m_properties.value("transparency") == "1");
 }
 
-const QString & DocClipBase::description() const
+const QString DocClipBase::getProperty(const QString prop) const
 {
-    return m_description;
+    return m_properties.value(prop);
 }
 
 void DocClipBase::setDuration(GenTime dur)
 {
     m_duration = dur;
+    m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps())));
 }
 
 const GenTime &DocClipBase::duration() const
@@ -145,81 +230,45 @@ const GenTime &DocClipBase::duration() const
     return m_duration;
 }
 
+const GenTime DocClipBase::maxDuration() const
+{
+    if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW &&  m_properties.value("loop") == "1")) {
+        /*const GenTime dur(15000, KdenliveSettings::project_fps());
+        return dur;*/
+        return GenTime();
+    }
+    return m_duration;
+}
+
 bool DocClipBase::hasFileSize() const
 {
-  return true;
+    return true;
 }
 
 
 // virtual
 QDomElement DocClipBase::toXML() const
 {
-/*
     QDomDocument doc;
+    QDomElement clip = doc.createElement("producer");
 
-    QDomElement clip = doc.createElement("kdenliveclip");
-    QDomText text = doc.createTextNode(description());
-    clip.appendChild(text);
-    doc.appendChild(clip);
-*/
-    return m_xml;
-}
-
-DocClipBase *DocClipBase::
-createClip(KdenliveDoc *doc, const QDomElement & element)
-{
-    DocClipBase *clip = 0;
-    QString description;
-    QDomNode node = element;
-    node.normalize();
-    if (element.tagName() != "kdenliveclip") {
-       kWarning() <<
-           "DocClipBase::createClip() element has unknown tagName : " <<
-           element.tagName() << endl;
-       return 0;
-    }
-
-    QDomNode n = element.firstChild();
-
-    while (!n.isNull()) {
-       QDomElement e = n.toElement();
-       if (!e.isNull()) {
-           QString tagName = e.tagName();
-           if (e.tagName() == "avfile") {
-               // clip = DocClipAVFile::createClip(e);
-           } else if (e.tagName() == "DocTrackBaseList") {
-               // clip = DocClipProject::createClip(doc, e);
-           }
-       } else {
-           QDomText text = n.toText();
-           if (!text.isNull()) {
-               description = text.nodeValue();
-           }
-       }
-
-       n = n.nextSibling();
-    }
-    if (clip == 0) {
-       kWarning() << "DocClipBase::createClip() unable to create clip" <<
-           endl;
-    } else {
-       // setup DocClipBase specifics of the clip.
-       clip->setDescription(description);
-       clip->setAudioThumbCreated(false);
+    QMapIterator<QString, QString> i(m_properties);
+    while (i.hasNext()) {
+        i.next();
+        if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
     }
-    return clip;
+    doc.appendChild(clip);
+    //kDebug() << "/// CLIP XML: " << doc.toString();
+    return doc.documentElement();
 }
 
+
 void DocClipBase::setAudioThumbCreated(bool isDone)
 {
-    audioThumbCreated = isDone;
+    m_audioThumbCreated = isDone;
 }
 
 
-QDomDocument DocClipBase::generateSceneList(bool, bool) const
-{
-}
-
 void DocClipBase::setThumbnail(const QPixmap & pixmap)
 {
     m_thumbnail = pixmap;
@@ -230,18 +279,20 @@ const QPixmap & DocClipBase::thumbnail() const
     return m_thumbnail;
 }
 
-void DocClipBase::updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data)
+void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data)
 {
-    audioFrameChache = data;
-    audioThumbCreated = true;
+    //kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
+    m_audioFrameCache = data;
+    m_audioThumbCreated = true;
+    emit gotAudioData();
 }
 
 QList < GenTime > DocClipBase::snapMarkers() const
 {
     QList < GenTime > markers;
 
-    for (uint count = 0; count < m_snapMarkers.count(); ++count) {
-       markers.append(m_snapMarkers[count].time());
+    for (int count = 0; count < m_snapMarkers.count(); ++count) {
+        markers.append(m_snapMarkers[count].time());
     }
 
     return markers;
@@ -260,18 +311,17 @@ void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
 {
     QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
-    for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
-       if ((*it).time() >= time)
-           break;
+    for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
+        if ((*it).time() >= time)
+            break;
     }
 
     if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
-       kError() <<
-           "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
-           << endl;
+        (*it).setComment(comment);
+        //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo";
     } else {
-       CommentedTime t(time, comment);
-       m_snapMarkers.insert(it, t);
+        CommentedTime t(time, comment);
+        m_snapMarkers.insert(it, t);
     }
 
 }
@@ -279,15 +329,14 @@ void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
 {
     QList < CommentedTime >::Iterator it;
-    for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
-       if ((*it).time() == time)
-           break;
+    for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
+        if ((*it).time() == time)
+            break;
     }
     if (it != m_snapMarkers.end()) {
-       (*it).setComment(comment);
+        (*it).setComment(comment);
     } else {
-       kError() <<
-           "trying to edit Snap Marker that does not already exists"  << endl;
+        kError() << "trying to edit Snap Marker that does not already exists";
     }
 }
 
@@ -297,14 +346,14 @@ QString DocClipBase::deleteSnapMarker(const GenTime & time)
     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
 
     while (itt != m_snapMarkers.end()) {
-       if ((*itt).time() == time)
-           break;
-       ++itt;
+        if ((*itt).time() == time)
+            break;
+        ++itt;
     }
 
     if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
-       result = (*itt).comment();
-       m_snapMarkers.erase(itt);
+        result = (*itt).comment();
+        m_snapMarkers.erase(itt);
     }
     return result;
 }
@@ -315,9 +364,9 @@ GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
 
     while (itt != m_snapMarkers.end()) {
-       if ((*itt).time() == time)
-           return time;
-       ++itt;
+        if ((*itt).time() == time)
+            return time;
+        ++itt;
     }
 
     return GenTime(0.0);
@@ -326,22 +375,22 @@ GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
 {
     int it;
-    for ( it = 0; it < m_snapMarkers.count(); it++ ) {
-       if (m_snapMarkers[it].time() >= currTime)
-           break;
+    for (it = 0; it < m_snapMarkers.count(); it++) {
+        if (m_snapMarkers[it].time() >= currTime)
+            break;
     }
     if (it == 0) return GenTime();
     else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
-       return m_snapMarkers[it].time();
+        return m_snapMarkers[it].time();
     else return m_snapMarkers[it-1].time();
 }
 
 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
 {
     int it;
-    for ( it = 0; it < m_snapMarkers.count(); it++ ) {
-       if (m_snapMarkers[it].time() > currTime)
-           break;
+    for (it = 0; it < m_snapMarkers.count(); it++) {
+        if (m_snapMarkers[it].time() > currTime)
+            break;
     }
     if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
     return duration();
@@ -352,64 +401,418 @@ QString DocClipBase::markerComment(GenTime t)
     QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
 
     while (itt != m_snapMarkers.end()) {
-       if ((*itt).time() == t)
-           return (*itt).comment();
-       ++itt;
-    }
-    return QString::null;
-}
-
-//static
-QString DocClipBase::getTypeName(CLIPTYPE type)
-{
-    QString result;
-    switch (type) {
-       case AV:
-           result = i18n("Video Clip");
-           break;
-       case COLOR:
-           result = i18n("Color Clip");
-           break;
-       case PLAYLIST:
-           result = i18n("Playlist Clip");
-           break;
-       case IMAGE:
-           result = i18n("Image Clip");
-           break;
-       case SLIDESHOW:
-           result = i18n("Slideshow Clip");
-           break;
-       case VIRTUAL:
-           result = i18n("Virtual Clip");
-           break;
-       case AUDIO:
-           result = i18n("Audio Clip");
-           break;
-       case VIDEO:
-           result = i18n("Mute Video Clip");
-           break;
-       case TEXT:
-           result = i18n("Text Clip");
-           break;
-       default:
-           result = i18n("None");
-           break;
+        if ((*itt).time() == t)
+            return (*itt).comment();
+        ++itt;
     }
-    return result;
+    return QString();
+}
+
+void DocClipBase::deleteProducers()
+{
+    qDeleteAll(m_baseTrackProducers);
+    m_baseTrackProducers.clear();
+    if (m_thumbProd) m_thumbProd->clearProducer();
+    qDeleteAll(m_audioTrackProducers);
+    m_audioTrackProducers.clear();
+    delete m_videoOnlyProducer;
+    m_videoOnlyProducer = NULL;
 }
 
-void DocClipBase::slotGetAudioThumbs(){
-       kDebug() << "getting audio data";
-       if (audioThumbCreated){
-               if (m_audioTimer!=NULL)
-                       m_audioTimer->stop();
-       }else{
-               if (m_audioTimer!=NULL)
-                       m_audioTimer->start(2000);
-               double lengthInFrames=duration().frames(/*framesPerSecond()*/25);
-               m_thumbProd->getAudioThumbs(fileURL(), 1, 0, 10 /*must be number of frames*/, 20);
-               
-               
-       }
+void DocClipBase::setProducer(Mlt::Producer *producer, bool reset)
+{
+    if (producer == NULL) return;
+    if (reset) {
+        // Clear all previous producers
+        deleteProducers();
+    }
+    QString id = producer->get("id");
+    if (id.contains('_')) {
+        // this is a subtrack producer, insert it at correct place
+        id = id.section('_', 1);
+        if (id.endsWith("audio")) {
+            int pos = id.section('_', 0, 0).toInt();
+            if (pos >= m_audioTrackProducers.count()) {
+                while (m_audioTrackProducers.count() - 1 < pos) {
+                    m_audioTrackProducers.append(NULL);
+                }
+            }
+            if (m_audioTrackProducers.at(pos) == NULL) m_audioTrackProducers[pos] = producer;
+            return;
+        }
+        if (id.endsWith("video")) {
+            m_videoOnlyProducer = producer;
+            return;
+        }
+        int pos = id.toInt();
+        if (pos >= m_baseTrackProducers.count()) {
+            while (m_baseTrackProducers.count() - 1 < pos) {
+                m_baseTrackProducers.append(NULL);
+            }
+        }
+        if (m_baseTrackProducers.at(pos) == NULL) m_baseTrackProducers[pos] = producer;
+    } else {
+        if (m_baseTrackProducers.isEmpty()) m_baseTrackProducers.append(producer);
+        else if (m_baseTrackProducers.at(0) == NULL) m_baseTrackProducers[0] = producer;
+    }
+    //m_clipProducer = producer;
+    //m_clipProducer->set("transparency", m_properties.value("transparency").toInt());
+    if (m_thumbProd && (reset || !m_thumbProd->hasProducer())) m_thumbProd->setProducer(producer);
+}
+
+Mlt::Producer *DocClipBase::audioProducer(int track)
+{
+    if (m_audioTrackProducers.count() <= track) {
+        while (m_audioTrackProducers.count() - 1 < track) {
+            m_audioTrackProducers.append(NULL);
+        }
+    }
+    if (m_audioTrackProducers.at(track) == NULL) {
+        Mlt::Producer *base = producer();
+        m_audioTrackProducers[track] = new Mlt::Producer(*(base->profile()), base->get("resource"));
+        if (m_properties.contains("force_aspect_ratio")) m_audioTrackProducers.at(track)->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
+        if (m_properties.contains("threads")) m_audioTrackProducers.at(track)->set("threads", m_properties.value("threads").toInt());
+        m_audioTrackProducers.at(track)->set("video_index", -1);
+        if (m_properties.contains("audio_index")) m_audioTrackProducers.at(track)->set("audio_index", m_properties.value("audio_index").toInt());
+        char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track) + "_audio").toUtf8().data());
+        m_audioTrackProducers.at(track)->set("id", tmp);
+        delete[] tmp;
+    }
+    return m_audioTrackProducers.at(track);
+}
+
+Mlt::Producer *DocClipBase::videoProducer()
+{
+    if (m_videoOnlyProducer == NULL) {
+        int i;
+        for (i = 0; i < m_baseTrackProducers.count(); i++)
+            if (m_baseTrackProducers.at(i) != NULL) break;
+        if (i >= m_baseTrackProducers.count()) return NULL;
+        m_videoOnlyProducer = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
+        if (m_properties.contains("force_aspect_ratio")) m_videoOnlyProducer->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
+        if (m_properties.contains("threads")) m_videoOnlyProducer->set("threads", m_properties.value("threads").toInt());
+        m_videoOnlyProducer->set("audio_index", -1);
+        if (m_properties.contains("video_index")) m_videoOnlyProducer->set("video_index", m_properties.value("video_index").toInt());
+        char *tmp = (char *) qstrdup(QString(getId() + "_video").toUtf8().data());
+        m_videoOnlyProducer->set("id", tmp);
+        delete[] tmp;
+    }
+    return m_videoOnlyProducer;
+}
+
+Mlt::Producer *DocClipBase::producer(int track)
+{
+    /*for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+        if (m_baseTrackProducers.at(i)) kDebug() << "// PROD: " << i << ", ID: " << m_baseTrackProducers.at(i)->get("id");
+    }*/
+    if (track == -1 || (m_clipType != AUDIO && m_clipType != AV)) {
+        if (m_baseTrackProducers.count() == 0) return NULL;
+        for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+            if (m_baseTrackProducers.at(i) != NULL)
+                return m_baseTrackProducers.at(i);
+        }
+        return NULL;
+    }
+    if (track >= m_baseTrackProducers.count()) {
+        while (m_baseTrackProducers.count() - 1 < track) {
+            m_baseTrackProducers.append(NULL);
+        }
+    }
+    if (m_baseTrackProducers.at(track) == NULL) {
+        int i;
+        for (i = 0; i < m_baseTrackProducers.count(); i++)
+            if (m_baseTrackProducers.at(i) != NULL) break;
+
+        if (i >= m_baseTrackProducers.count()) return NULL;
+
+        if (KIO::NetAccess::exists(KUrl(m_baseTrackProducers.at(i)->get("resource")), KIO::NetAccess::SourceSide, 0))
+            m_baseTrackProducers[track] = new Mlt::Producer(*m_baseTrackProducers.at(i)->profile(), m_baseTrackProducers.at(i)->get("resource"));
+        else { // special case for placeholder clips
+            m_baseTrackProducers[track] = NULL;
+            return NULL;
+        }
+
+        if (m_properties.contains("force_aspect_ratio")) m_baseTrackProducers[track]->set("force_aspect_ratio", m_properties.value("force_aspect_ratio").toDouble());
+        if (m_properties.contains("threads")) m_baseTrackProducers[track]->set("threads", m_properties.value("threads").toInt());
+        if (m_properties.contains("video_index")) m_baseTrackProducers[track]->set("video_index", m_properties.value("video_index").toInt());
+        if (m_properties.contains("audio_index")) m_baseTrackProducers[track]->set("audio_index", m_properties.value("audio_index").toInt());
+        char *tmp = (char *) qstrdup(QString(getId() + '_' + QString::number(track)).toUtf8().data());
+        m_baseTrackProducers[track]->set("id", tmp);
+        delete[] tmp;
+        if (KdenliveSettings::dropbframes() && m_baseTrackProducers.at(i)->get("skip_loop_filter") && strcmp(m_baseTrackProducers.at(i)->get("skip_loop_filter"), "all") == 0) {
+            m_baseTrackProducers[track]->set("skip_loop_filter", "all");
+            m_baseTrackProducers[track]->set("skip_frame", "bidir");
+        }
+    }
+    return m_baseTrackProducers.at(track);
+}
+
+void DocClipBase::setProducerProperty(const char *name, int data)
+{
+    for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+        if (m_baseTrackProducers.at(i) != NULL)
+            m_baseTrackProducers[i]->set(name, data);
+    }
+}
+
+void DocClipBase::setProducerProperty(const char *name, double data)
+{
+    for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+        if (m_baseTrackProducers.at(i) != NULL)
+            m_baseTrackProducers[i]->set(name, data);
+    }
+}
+
+void DocClipBase::setProducerProperty(const char *name, const char *data)
+{
+    for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+        if (m_baseTrackProducers.at(i) != NULL)
+            m_baseTrackProducers[i]->set(name, data);
+    }
+}
+
+const char *DocClipBase::producerProperty(const char *name) const
+{
+    for (int i = 0; i < m_baseTrackProducers.count(); i++) {
+        if (m_baseTrackProducers.at(i) != NULL) {
+            return m_baseTrackProducers.at(i)->get(name);
+        }
+    }
+    return NULL;
+}
+
+
+void DocClipBase::slotRefreshProducer()
+{
+    if (m_baseTrackProducers.count() == 0) return;
+    kDebug() << "////////////   REFRESH CLIP !!!!!!!!!!!!!!!!";
+    if (m_clipType == SLIDESHOW) {
+        /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data());
+               Mlt::Producer producer(*(m_clipProducer->profile()), tmp);
+               delete[] tmp;
+        delete m_clipProducer;
+        m_clipProducer = new Mlt::Producer(producer.get_producer());
+        if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/
+        setProducerProperty("ttl", getProperty("ttl").toInt());
+        //m_clipProducer->set("id", getProperty("id"));
+        if (getProperty("fade") == "1") {
+            // we want a fade filter effect
+            kDebug() << "////////////   FADE WANTED";
+            Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
+            int ct = 0;
+            Mlt::Filter *filter = clipService.filter(ct);
+            while (filter) {
+                if (strcmp(filter->get("mlt_service"), "luma") == 0) {
+                    break;
+                }
+                ct++;
+                filter = clipService.filter(ct);
+            }
+
+            if (filter && strcmp(filter->get("mlt_service"), "luma") == 0) {
+                filter->set("period", getProperty("ttl").toInt() - 1);
+                filter->set("luma.out", getProperty("luma_duration").toInt());
+                QString resource = getProperty("luma_file");
+                char *tmp = (char *) qstrdup(resource.toUtf8().data());
+                filter->set("luma.resource", tmp);
+                delete[] tmp;
+                if (!getProperty("softness").isEmpty()) {
+                    int soft = getProperty("softness").toInt();
+                    filter->set("luma.softness", (double) soft / 100.0);
+                }
+            } else {
+                // filter does not exist, create it...
+                Mlt::Filter *filter = new Mlt::Filter(*(m_baseTrackProducers.at(0)->profile()), "luma");
+                filter->set("period", getProperty("ttl").toInt() - 1);
+                filter->set("luma.out", getProperty("luma_duration").toInt());
+                QString resource = getProperty("luma_file");
+                char *tmp = (char *) qstrdup(resource.toUtf8().data());
+                filter->set("luma.resource", tmp);
+                delete[] tmp;
+                if (!getProperty("softness").isEmpty()) {
+                    int soft = getProperty("softness").toInt();
+                    filter->set("luma.softness", (double) soft / 100.0);
+                }
+                clipService.attach(*filter);
+            }
+        } else {
+            kDebug() << "////////////   FADE NOT WANTED!!!";
+            Mlt::Service clipService(m_baseTrackProducers.at(0)->get_service());
+            int ct = 0;
+            Mlt::Filter *filter = clipService.filter(0);
+            while (filter) {
+                if (strcmp(filter->get("mlt_service"), "luma") == 0) {
+                    clipService.detach(*filter);
+                } else ct++;
+                filter = clipService.filter(ct);
+            }
+        }
+    }
+}
+
+void DocClipBase::setProperties(QMap <QString, QString> properties)
+{
+    // changing clip type is not allowed
+    properties.remove("type");
+    QMapIterator<QString, QString> i(properties);
+    bool refreshProducer = false;
+    QStringList keys;
+    keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness";
+    while (i.hasNext()) {
+        i.next();
+        setProperty(i.key(), i.value());
+        if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true;
+    }
+    if (refreshProducer) slotRefreshProducer();
+}
+
+void DocClipBase::setMetadata(QMap <QString, QString> properties)
+{
+    m_metadata = properties;
+}
+
+QMap <QString, QString> DocClipBase::metadata() const
+{
+    return m_metadata;
+}
+
+void DocClipBase::clearProperty(const QString &key)
+{
+    m_properties.remove(key);
+}
+
+void DocClipBase::getFileHash(const QString url)
+{
+    if (m_clipType == SLIDESHOW) return;
+    QFile file(url);
+    if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
+        QByteArray fileData;
+        QByteArray fileHash;
+        //kDebug() << "SETTING HASH of" << value;
+        m_properties.insert("file_size", QString::number(file.size()));
+        /*
+               * 1 MB = 1 second per 450 files (or faster)
+               * 10 MB = 9 seconds per 450 files (or faster)
+               */
+        if (file.size() > 1000000*2) {
+            fileData = file.read(1000000);
+            if (file.seek(file.size() - 1000000))
+                fileData.append(file.readAll());
+        } else
+            fileData = file.readAll();
+        file.close();
+        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
+        m_properties.insert("file_hash", QString(fileHash.toHex()));
+    }
+}
+
+QString DocClipBase::getClipHash() const
+{
+    QString hash;
+    if (m_clipType == SLIDESHOW) hash = QCryptographicHash::hash(m_properties.value("resource").toAscii().data(), QCryptographicHash::Md5).toHex();
+    else if (m_clipType == COLOR) hash = QCryptographicHash::hash(m_properties.value("colour").toAscii().data(), QCryptographicHash::Md5).toHex();
+    else hash = m_properties.value("file_hash");
+    return hash;
+}
+
+// static
+QString DocClipBase::getHash(const QString &path)
+{
+    QFile file(path);
+    if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
+        QByteArray fileData;
+        QByteArray fileHash;
+        /*
+               * 1 MB = 1 second per 450 files (or faster)
+               * 10 MB = 9 seconds per 450 files (or faster)
+               */
+        if (file.size() > 1000000*2) {
+            fileData = file.read(1000000);
+            if (file.seek(file.size() - 1000000))
+                fileData.append(file.readAll());
+        } else
+            fileData = file.readAll();
+        file.close();
+        return QCryptographicHash::hash(fileData, QCryptographicHash::Md5).toHex();
+    }
+    return QString();
+}
+
+void DocClipBase::refreshThumbUrl()
+{
+    if (m_thumbProd) m_thumbProd->updateThumbUrl(m_properties.value("file_hash"));
+}
+
+void DocClipBase::setProperty(const QString &key, const QString &value)
+{
+    m_properties.insert(key, value);
+    if (key == "resource") {
+        getFileHash(value);
+        if (m_thumbProd) m_thumbProd->updateClipUrl(KUrl(value), m_properties.value("file_hash"));
+    } else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps()));
+    //else if (key == "transparency") m_clipProducer->set("transparency", value.toInt());
+    else if (key == "colour") {
+        char *tmp = (char *) qstrdup(value.toUtf8().data());
+        setProducerProperty("colour", tmp);
+        delete[] tmp;
+    } else if (key == "templatetext") {
+        char *tmp = (char *) qstrdup(value.toUtf8().data());
+        setProducerProperty("templatetext", tmp);
+        delete[] tmp;
+        setProducerProperty("force_reload", 1);
+    } else if (key == "xmldata") {
+        char *tmp = (char *) qstrdup(value.toUtf8().data());
+        setProducerProperty("xmldata", tmp);
+        delete[] tmp;
+        setProducerProperty("force_reload", 1);
+    } else if (key == "force_aspect_ratio") {
+        if (value.isEmpty()) {
+            m_properties.remove("force_aspect_ratio");
+            setProducerProperty("force_aspect_ratio", 0);
+        } else setProducerProperty("force_aspect_ratio", value.toDouble());
+    } else if (key == "threads") {
+        if (value.isEmpty()) {
+            m_properties.remove("threads");
+            setProducerProperty("threads", 1);
+        } else setProducerProperty("threads", value.toInt());
+    } else if (key == "video_index") {
+        if (value.isEmpty()) {
+            m_properties.remove("video_index");
+            setProducerProperty("video_index", m_properties.value("default_video").toInt());
+        } else setProducerProperty("video_index", value.toInt());
+    } else if (key == "audio_index") {
+        if (value.isEmpty()) {
+            m_properties.remove("audio_index");
+            setProducerProperty("audio_index", m_properties.value("default_audio").toInt());
+        } else setProducerProperty("audio_index", value.toInt());
+    }
+}
+
+QMap <QString, QString> DocClipBase::properties() const
+{
+    return m_properties;
+}
+
+bool DocClipBase::slotGetAudioThumbs()
+{
+    if (m_thumbProd == NULL) return false;
+    if (!KdenliveSettings::audiothumbnails()) {
+        if (m_audioTimer != NULL) m_audioTimer->stop();
+        return false;
+    }
+    if (m_audioThumbCreated) {
+        if (m_audioTimer != NULL) m_audioTimer->stop();
+        return false;
+    }
+    if (m_audioTimer != NULL)
+        m_audioTimer->start(1500);
+    double lengthInFrames = duration().frames(KdenliveSettings::project_fps());
+    m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);
+    return true;
+}
+
+bool DocClipBase::isPlaceHolder() const
+{
+    return m_placeHolder;
 }