+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, 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()));
+ //kDebug() << file.fileName() << file.size() << 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;
+}
+
+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 == "xmldata") {
+ 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;