1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
31 #include <mlt++/Mlt.h>
32 //#include <framework/mlt_log.h>
35 #include <KStandardDirs>
36 #include <KMessageBox>
38 #include <KTemporaryFile>
42 #include <QApplication>
48 static void kdenlive_callback(void* ptr, int level, const char* fmt, va_list vl)
50 if (level > MLT_LOG_ERROR) return;
52 QProcess::startDetached("kdialog", QStringList() << "--error" << error.vsprintf(fmt, vl));
56 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
58 // detect if the producer has finished playing. Is there a better way to do it?
59 if (self->m_isBlocked) return;
60 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
61 self->emitConsumerStopped();
63 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
67 Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget *parent) :
80 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
81 m_refreshTimer = new QTimer(this);
82 connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
84 /*if (rendererName == "project") m_monitorId = 10000;
85 else m_monitorId = 10001;*/
86 m_osdTimer = new QTimer(this);
87 connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
91 m_mltProducer = m_blackClip->cut(0, 50);
92 m_mltConsumer->connect(*m_mltProducer);
93 m_mltProducer->set_speed(0.0);
103 void Render::closeMlt()
106 delete m_refreshTimer;
107 delete m_mltConsumer;
108 delete m_mltProducer;
114 void Render::buildConsumer()
117 m_activeProfile = KdenliveSettings::current_profile();
118 tmp = decodedString(m_activeProfile);
119 setenv("MLT_PROFILE", tmp, 1);
123 m_mltProfile = new Mlt::Profile(tmp);
126 QString videoDriver = KdenliveSettings::videodrivername();
127 if (!videoDriver.isEmpty()) {
128 if (videoDriver == "x11_noaccel") {
129 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
132 unsetenv("SDL_VIDEO_YUV_HWACCEL");
135 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
137 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
138 m_mltConsumer->set("resize", 1);
139 m_mltConsumer->set("window_id", m_winid);
140 m_mltConsumer->set("terminate_on_pause", 1);
141 tmp = decodedString(KdenliveSettings::window_background().name());
142 m_mltConsumer->set("window_background", tmp);
145 // FIXME: the event object returned by the listen gets leaked...
146 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
147 m_mltConsumer->set("rescale", "nearest");
148 //mlt_log_set_callback(kdenlive_callback);
150 QString audioDevice = KdenliveSettings::audiodevicename();
151 if (!audioDevice.isEmpty()) {
152 tmp = decodedString(audioDevice);
153 m_mltConsumer->set("audio_device", tmp);
157 if (!videoDriver.isEmpty()) {
158 tmp = decodedString(videoDriver);
159 m_mltConsumer->set("video_driver", tmp);
163 QString audioDriver = KdenliveSettings::audiodrivername();
166 // Disabled because the "auto" detected driver was sometimes wrong
167 if (audioDriver.isEmpty())
168 audioDriver = KdenliveSettings::autoaudiodrivername();
171 if (!audioDriver.isEmpty()) {
172 tmp = decodedString(audioDriver);
173 m_mltConsumer->set("audio_driver", tmp);
178 m_mltConsumer->set("progressive", 1);
179 m_mltConsumer->set("audio_buffer", 1024);
180 m_mltConsumer->set("frequency", 48000);
182 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
183 m_blackClip->set("id", "black");
187 int Render::resetProfile()
189 if (!m_mltConsumer) return 0;
190 if (m_activeProfile == KdenliveSettings::current_profile()) {
191 kDebug() << "reset to same profile, nothing to do";
194 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
195 if (m_isSplitView) slotSplitView(false);
196 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
197 m_mltConsumer->purge();
198 delete m_mltConsumer;
199 m_mltConsumer = NULL;
200 QString scene = sceneList();
203 pos = m_mltProducer->position();
204 delete m_mltProducer;
206 m_mltProducer = NULL;
208 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
209 /*if (m_mltProfile) delete m_mltProfile;
210 m_mltProfile = NULL;*/
214 //kDebug() << "//RESET WITHSCENE: " << scene;
215 setSceneList(scene, pos);
217 /*char *tmp = decodedString(scene);
218 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
220 m_mltProducer = producer;
221 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
222 m_mltProducer->optimise();
223 m_mltProducer->set_speed(0);
226 //delete m_mltProfile;
227 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
228 //mlt_profile prof = m_mltProfile->get_profile();
229 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
230 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
231 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
232 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
234 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
239 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
240 void Render::seek(GenTime time)
245 m_mltProducer->seek((int)(time.frames(m_fps)));
250 char *Render::decodedString(QString str)
252 /*QCString fn = QFile::encodeName(str);
253 char *t = new char[fn.length() + 1];
254 strcpy(t, (const char *)fn);*/
256 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
260 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
261 QPixmap pix(width, height);
263 mlt_image_format format = mlt_image_rgb24a;
264 uint8_t *thumb = frame->get_image(format, width, height);
265 QImage image(thumb, width, height, QImage::Format_ARGB32);
267 if (!image.isNull()) {
268 pix = pix.fromImage(image);
270 QPainter painter(&pix);
271 painter.drawRect(0, 0, width - 1, height - 1);
273 } else pix.fill(Qt::black);
277 int Render::renderWidth() const
279 return (int)(m_mltProfile->height() * m_mltProfile->dar());
282 int Render::renderHeight() const
284 return m_mltProfile->height();
287 QPixmap Render::extractFrame(int frame_position, int width, int height)
290 width = renderWidth();
291 height = renderHeight();
292 } else if (width % 2 == 1) width++;
293 QPixmap pix(width, height);
294 if (!m_mltProducer) {
298 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
301 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
305 if (url.fileName().startsWith(".all.")) { // check for slideshow
306 QString fileType = url.fileName().right(3);
308 QStringList::Iterator it;
310 QDir dir(url.directory());
312 filter << "*." + fileType;
313 filter << "*." + fileType.toUpper();
314 more = dir.entryList(filter, QDir::Files);
315 im.load(url.directory() + '/' + more.at(0));
316 } else im.load(url.path());
317 //pixmap = im.scaled(width, height);
322 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
323 QPixmap pix(width, height);
324 char *tmp = decodedString(file);
325 Mlt::Profile *prof = new Mlt::Profile(profile);
326 Mlt::Producer m_producer(*prof, tmp);
328 if (m_producer.is_blank()) {
333 Mlt::Filter m_convert(*prof, "avcolour_space");
334 m_convert.set("forced", mlt_image_rgb24a);
335 m_producer.attach(m_convert);
336 m_producer.seek(frame_position);
337 Mlt::Frame * frame = m_producer.get_frame();
339 pix = frameThumbnail(frame, width, height, true);
342 if (prof) delete prof;
347 void Render::getImage(KUrl url, int frame_position, QPoint size)
349 char *tmp = decodedString(url.path());
350 Mlt::Producer m_producer(tmp);
352 if (m_producer.is_blank()) {
355 Mlt::Filter m_convert("avcolour_space");
356 m_convert.set("forced", mlt_image_rgb24a);
357 m_producer.attach(m_convert);
358 m_producer.seek(frame_position);
360 Mlt::Frame * frame = m_producer.get_frame();
363 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
365 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
369 /* Create thumbnail for color */
370 /*void Render::getImage(int id, QString color, QPoint size)
372 QPixmap pixmap(size.x() - 2, size.y() - 2);
373 color = color.replace(0, 2, "#");
374 color = color.left(7);
375 pixmap.fill(QColor(color));
376 QPixmap result(size.x(), size.y());
377 result.fill(Qt::black);
378 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
379 emit replyGetImage(id, result, size.x(), size.y());
383 /* Create thumbnail for image */
384 /*void Render::getImage(KUrl url, QPoint size)
388 if (url.fileName().startsWith(".all.")) { // check for slideshow
389 QString fileType = url.fileName().right(3);
391 QStringList::Iterator it;
393 QDir dir( url.directory() );
394 more = dir.entryList( QDir::Files );
395 for ( it = more.begin() ; it != more.end() ; ++it ) {
396 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
397 if (!im.load(url.directory() + '/' + *it))
398 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
403 else im.load(url.path());
405 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
406 QPixmap result(size.x(), size.y());
407 result.fill(Qt::black);
408 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
409 emit replyGetImage(url, 1, result, size.x(), size.y());
413 double Render::consumerRatio() const
415 if (!m_mltConsumer) return 1.0;
416 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
420 int Render::getLength()
424 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
425 return mlt_producer_get_playtime(m_mltProducer->get_producer());
430 bool Render::isValid(KUrl url)
432 char *tmp = decodedString(url.path());
433 Mlt::Producer producer(*m_mltProfile, tmp);
435 if (producer.is_blank())
441 double Render::dar() const
443 return m_mltProfile->dar();
446 void Render::slotSplitView(bool doit)
448 m_isSplitView = doit;
449 Mlt::Service service(m_mltProducer->parent().get_service());
450 Mlt::Tractor tractor(service);
451 if (service.type() != tractor_type || tractor.count() < 2) return;
452 Mlt::Field *field = tractor.field();
455 for (int i = 1; i < tractor.count() && screen < 4; i++) {
456 Mlt::Producer trackProducer(tractor.track(i));
457 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
458 if (QString(trackProducer.get("hide")).toInt() != 1) {
459 kDebug() << "// ADIDNG TRACK: " << i;
460 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
461 transition->set("mlt_service", "composite");
462 transition->set("a_track", 0);
463 transition->set("b_track", i);
464 transition->set("distort", 1);
465 transition->set("internal_added", "200");
472 tmp = "50%,0:50%x50%";
475 tmp = "0,50%:50%x50%";
479 tmp = "50%,50%:50%x50%";
482 transition->set("geometry", tmp);
483 transition->set("always_active", "1");
484 field->plant_transition(*transition, 0, i);
489 m_mltConsumer->set("refresh", 1);
491 mlt_service serv = m_mltProducer->parent().get_service();
492 mlt_service nextservice = mlt_service_get_producer(serv);
493 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
494 QString mlt_type = mlt_properties_get(properties, "mlt_type");
495 QString resource = mlt_properties_get(properties, "mlt_service");
497 while (mlt_type == "transition") {
498 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
499 if (added == "200") {
500 mlt_field_disconnect_service(field->get_field(), nextservice);
502 nextservice = mlt_service_producer(nextservice);
503 if (nextservice == NULL) break;
504 properties = MLT_SERVICE_PROPERTIES(nextservice);
505 mlt_type = mlt_properties_get(properties, "mlt_type");
506 resource = mlt_properties_get(properties, "mlt_service");
507 m_mltConsumer->set("refresh", 1);
512 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer)
514 KUrl url = KUrl(xml.attribute("resource", QString()));
515 Mlt::Producer *producer = NULL;
516 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
517 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
520 if (xml.attribute("type").toInt() == COLOR) {
521 char *tmp = decodedString("colour:" + xml.attribute("colour"));
522 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
524 } else if (url.isEmpty()) {
526 QDomElement mlt = doc.createElement("mlt");
527 QDomElement play = doc.createElement("playlist");
528 doc.appendChild(mlt);
529 mlt.appendChild(play);
530 play.appendChild(doc.importNode(xml, true));
531 char *tmp = decodedString(doc.toString());
532 producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
535 char *tmp = decodedString(url.path());
536 producer = new Mlt::Producer(*m_mltProfile, tmp);
540 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
541 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
542 emit removeInvalidClip(clipId, replaceProducer);
547 if (xml.hasAttribute("force_aspect_ratio")) {
548 double aspect = xml.attribute("force_aspect_ratio").toDouble();
549 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
551 if (xml.hasAttribute("threads")) {
552 int threads = xml.attribute("threads").toInt();
553 if (threads != 1) producer->set("threads", threads);
555 if (xml.hasAttribute("video_index")) {
556 int vindex = xml.attribute("video_index").toInt();
557 if (vindex != 0) producer->set("video_index", vindex);
559 if (xml.hasAttribute("audio_index")) {
560 int aindex = xml.attribute("audio_index").toInt();
561 if (aindex != 0) producer->set("audio_index", aindex);
564 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
566 char *tmp = decodedString(clipId);
567 producer->set("id", tmp);
570 if (!replaceProducer && xml.hasAttribute("file_hash")) {
571 // Clip already has all properties
572 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
577 int width = (int)(height * m_mltProfile->dar());
578 QMap < QString, QString > filePropertyMap;
579 QMap < QString, QString > metadataPropertyMap;
581 int frameNumber = xml.attribute("thumbnail", "0").toInt();
582 if (frameNumber != 0) producer->seek(frameNumber);
584 filePropertyMap["duration"] = QString::number(producer->get_playtime());
585 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
587 Mlt::Frame *frame = producer->get_frame();
589 if (xml.attribute("type").toInt() == SLIDESHOW) {
590 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
591 if (xml.attribute("fade") == "1") {
592 // user wants a fade effect to slideshow
593 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
594 if (filter && filter->is_valid()) {
595 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
596 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
597 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
598 char *tmp = decodedString(xml.attribute("luma_file"));
599 filter->set("luma.resource", tmp);
601 if (xml.hasAttribute("softness")) {
602 int soft = xml.attribute("softness").toInt();
603 filter->set("luma.softness", (double) soft / 100.0);
606 Mlt::Service clipService(producer->get_service());
607 clipService.attach(*filter);
613 filePropertyMap["fps"] = producer->get("source_fps");
615 if (frame && frame->is_valid()) {
616 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
617 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
618 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
619 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
621 if (frame->get_int("test_image") == 0) {
622 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
623 filePropertyMap["type"] = "playlist";
624 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
625 } else if (frame->get_int("test_audio") == 0)
626 filePropertyMap["type"] = "av";
628 filePropertyMap["type"] = "video";
630 mlt_image_format format = mlt_image_yuv422;
632 int frame_height = 0;
633 //frame->set("rescale.interp", "hyper");
634 frame->set("normalised_height", height);
635 frame->set("normalised_width", width);
636 QPixmap pix(width, height);
638 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
639 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
640 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
641 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
643 if (!image.isNull()) {
644 pix = QPixmap::fromImage(image.rgbSwapped());
648 mlt_pool_release(new_image);
649 emit replyGetImage(clipId, pix);
651 } else if (frame->get_int("test_audio") == 0) {
652 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
653 emit replyGetImage(clipId, pixmap);
654 filePropertyMap["type"] = "audio";
658 // Retrieve audio / video codec name
662 if (producer->get_int("video_index") > -1) {
663 /*if (context->duration == AV_NOPTS_VALUE) {
664 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
665 emit removeInvalidClip(clipId);
669 // Get the video_index
670 int default_video = producer->get_int("video_index");
672 int default_audio = producer->get_int("audio_index");
675 // Find maximum stream index values
676 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
677 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
678 QString type = producer->get(property);
681 else if (type == "audio")
684 filePropertyMap["default_video"] = QString::number(default_video);
685 filePropertyMap["video_max"] = QString::number(video_max);
686 filePropertyMap["default_audio"] = QString::number(default_audio);
687 filePropertyMap["audio_max"] = QString::number(audio_max);
689 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
690 if (producer->get(property)) {
691 filePropertyMap["videocodec"] = producer->get(property);
693 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
694 if (producer->get(property))
695 filePropertyMap["videocodec"] = producer->get(property);
698 if (KdenliveSettings::dropbframes()) {
699 kDebug() << "// LOOKING FOR H264 on: " << default_video;
700 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
701 kDebug() << "PROP: " << property << " = " << producer->get(property);
702 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
703 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
704 producer->set("skip_loop_filter", "all");
705 producer->set("skip_frame", "bidir");
709 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
710 if (producer->get_int("audio_index") > -1) {
711 // Get the audio_index
712 int index = producer->get_int("audio_index");
714 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
715 if (producer->get(property)) {
716 filePropertyMap["audiocodec"] = producer->get(property);
718 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
719 if (producer->get(property))
720 filePropertyMap["audiocodec"] = producer->get(property);
725 Mlt::Properties metadata;
726 metadata.pass_values(*producer, "meta.attr.");
727 int count = metadata.count();
728 for (int i = 0; i < count; i ++) {
729 QString name = metadata.get_name(i);
730 QString value = QString::fromUtf8(metadata.get(i));
731 if (name.endsWith("markup") && !value.isEmpty())
732 metadataPropertyMap[ name.section('.', 0, -2)] = value;
735 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
736 kDebug() << "REquested fuile info for: " << url.path();
738 // FIXME: should delete this to avoid a leak...
743 /** Create the producer from the MLT XML QDomDocument */
745 void Render::initSceneList()
747 kDebug() << "-------- INIT SCENE LIST ------_";
749 QDomElement mlt = doc.createElement("mlt");
750 doc.appendChild(mlt);
751 QDomElement prod = doc.createElement("producer");
752 prod.setAttribute("resource", "colour");
753 prod.setAttribute("colour", "red");
754 prod.setAttribute("id", "black");
755 prod.setAttribute("in", "0");
756 prod.setAttribute("out", "0");
758 QDomElement tractor = doc.createElement("tractor");
759 QDomElement multitrack = doc.createElement("multitrack");
761 QDomElement playlist1 = doc.createElement("playlist");
762 playlist1.appendChild(prod);
763 multitrack.appendChild(playlist1);
764 QDomElement playlist2 = doc.createElement("playlist");
765 multitrack.appendChild(playlist2);
766 QDomElement playlist3 = doc.createElement("playlist");
767 multitrack.appendChild(playlist3);
768 QDomElement playlist4 = doc.createElement("playlist");
769 multitrack.appendChild(playlist4);
770 QDomElement playlist5 = doc.createElement("playlist");
771 multitrack.appendChild(playlist5);
772 tractor.appendChild(multitrack);
773 mlt.appendChild(tractor);
774 // kDebug()<<doc.toString();
776 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
777 setSceneList(doc, 0);
783 /** Create the producer from the MLT XML QDomDocument */
784 int Render::setProducer(Mlt::Producer *producer, int position)
786 if (m_winid == -1) return -1;
789 m_mltConsumer->stop();
792 m_mltConsumer->purge();
796 m_mltProducer->set_speed(0);
797 delete m_mltProducer;
798 m_mltProducer = NULL;
802 m_mltProducer = new Mlt::Producer(producer->get_producer());
803 } else m_mltProducer = m_blackClip->cut(0, 50);
804 /*if (KdenliveSettings::dropbframes()) {
805 m_mltProducer->set("skip_loop_filter", "all");
806 m_mltProducer->set("skip_frame", "bidir");
808 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
810 m_fps = m_mltProducer->get_fps();
811 int error = connectPlaylist();
812 if (position != -1) {
813 m_mltProducer->seek(position);
814 emit rendererPosition(position);
822 /** Create the producer from the MLT XML QDomDocument */
823 int Render::setSceneList(QDomDocument list, int position)
825 return setSceneList(list.toString(), position);
828 /** Create the producer from the MLT XML QDomDocument */
829 int Render::setSceneList(QString playlist, int position)
831 if (m_winid == -1) return -1;
834 qDeleteAll(m_slowmotionProducers.values());
835 m_slowmotionProducers.clear();
837 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
839 if (m_mltConsumer == NULL) {
840 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
845 if (!m_mltConsumer->is_stopped()) {
846 m_mltConsumer->stop();
847 //m_mltConsumer->set("refresh", 0);
851 m_mltProducer->set_speed(0);
852 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
854 delete m_mltProducer;
855 m_mltProducer = NULL;
860 char *tmp = decodedString(playlist);
861 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
863 if (!m_mltProducer || !m_mltProducer->is_valid()) {
864 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
865 m_mltProducer = m_blackClip->cut(0, 50);
869 m_mltProducer->optimise();
871 /*if (KdenliveSettings::osdtimecode()) {
872 // Attach filter for on screen display of timecode
874 QString attr = "attr_check";
875 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
876 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
877 mlt_producer_attach( m_mltProducer->get_producer(), filter );
878 mlt_filter_close( filter );
880 m_osdInfo = new Mlt::Filter("data_show");
881 tmp = decodedString(m_osdProfile);
882 m_osdInfo->set("resource", tmp);
884 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
885 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
886 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
887 m_osdInfo->set("dynamic", "1");
889 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
891 m_osdInfo->set("dynamic", "0");
894 m_fps = m_mltProducer->get_fps();
896 // Seek to correct place after opening project.
897 m_mltProducer->seek(position);
900 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
901 error = connectPlaylist();
902 fillSlowMotionProducers();
906 emit refreshDocumentProducers();
908 //kDebug()<<"// SETSCN LST, POS: "<<position;
909 //if (position != 0) emit rendererPosition(position);
912 /** Create the producer from the MLT XML QDomDocument */
913 const QString Render::sceneList()
916 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
917 m_mltProducer->optimise();
918 xmlConsumer.set("terminate_on_pause", 1);
919 Mlt::Producer prod(m_mltProducer->get_producer());
920 bool split = m_isSplitView;
921 if (split) slotSplitView(false);
922 xmlConsumer.connect(prod);
924 while (!xmlConsumer.is_stopped()) {}
925 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
926 if (split) slotSplitView(true);
930 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
934 doc.setContent(sceneList(), false);
935 if (!kdenliveData.isNull()) {
936 // add Kdenlive specific tags
937 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
938 mlt.appendChild(doc.importNode(kdenliveData, true));
940 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
941 kWarning() << "////// ERROR writing to file: " << path;
944 file.write(doc.toString().toUtf8());
945 if (file.error() != QFile::NoError) {
954 void Render::saveZone(KUrl url, QString desc, QPoint zone)
956 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
957 char *tmppath = decodedString("xml:" + url.path());
958 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
959 m_mltProducer->optimise();
961 xmlConsumer.set("terminate_on_pause", 1);
962 if (m_name == "clip") {
963 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
964 tmppath = decodedString(desc);
966 list.insert_at(0, prod, 0);
967 list.set("title", tmppath);
969 xmlConsumer.connect(list);
972 //TODO: not working yet, save zone from timeline
973 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
974 /* Mlt::Service service(p1->parent().get_service());
975 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
977 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
978 tmppath = decodedString(desc);
979 //prod->set("title", tmppath);
981 xmlConsumer.connect(*p1); //list);
987 double Render::fps() const
992 int Render::connectPlaylist()
994 if (!m_mltConsumer) return -1;
995 //m_mltConsumer->set("refresh", "0");
996 m_mltConsumer->connect(*m_mltProducer);
997 m_mltProducer->set_speed(0);
998 if (m_mltConsumer->start() == -1) {
999 // ARGH CONSUMER BROKEN!!!!
1000 KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
1001 emit blockMonitors();
1002 delete m_mltProducer;
1003 m_mltProducer = NULL;
1006 emit durationChanged(m_mltProducer->get_playtime());
1011 void Render::refreshDisplay()
1014 if (!m_mltProducer) return;
1015 //m_mltConsumer->set("refresh", 0);
1017 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1018 /*if (KdenliveSettings::osdtimecode()) {
1019 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1020 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1021 m_osdInfo->set("dynamic", "1");
1022 m_mltProducer->attach(*m_osdInfo);
1025 m_mltProducer->detach(*m_osdInfo);
1026 m_osdInfo->set("dynamic", "0");
1031 void Render::setVolume(double /*volume*/)
1033 if (!m_mltConsumer || !m_mltProducer) return;
1035 m_mltConsumer->set("refresh", 0);
1036 // Attach filter for on screen display of timecode
1037 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1038 mlt_properties_set_double( properties, "meta.volume", volume );
1039 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1040 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1042 if (!KdenliveSettings::osdtimecode()) {
1043 m_mltProducer->detach(*m_osdInfo);
1044 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1045 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1048 m_osdTimer->setSingleShot(2500);
1051 void Render::slotOsdTimeout()
1053 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1054 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1055 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1056 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1060 void Render::start()
1062 kDebug() << "----- STARTING MONITOR: " << m_name;
1063 if (m_winid == -1) {
1064 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1067 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1068 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1069 if (m_mltConsumer->start() == -1) {
1070 KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
1071 emit blockMonitors();
1072 delete m_mltProducer;
1073 m_mltProducer = NULL;
1075 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1076 m_isBlocked = false;
1080 m_isBlocked = false;
1083 void Render::clear()
1085 kDebug() << " ********* RENDER CLEAR";
1086 if (m_mltConsumer) {
1087 //m_mltConsumer->set("refresh", 0);
1088 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1091 if (m_mltProducer) {
1092 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1093 m_mltProducer->set_speed(0.0);
1094 delete m_mltProducer;
1095 m_mltProducer = NULL;
1102 if (m_mltProducer == NULL) return;
1103 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1104 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1106 //m_mltConsumer->set("refresh", 0);
1107 m_mltConsumer->stop();
1108 // delete m_mltConsumer;
1109 // m_mltConsumer = NULL;
1111 kDebug() << "///////////// RENDER STOP2-------";
1114 if (m_mltProducer) {
1115 if (m_isZoneMode) resetZoneMode();
1116 m_mltProducer->set_speed(0.0);
1117 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1118 //kDebug() << m_mltProducer->get_length();
1120 kDebug() << "///////////// RENDER STOP3-------";
1123 void Render::stop(const GenTime & startTime)
1126 kDebug() << "///////////// RENDER STOP-------2";
1127 if (m_mltProducer) {
1128 if (m_isZoneMode) resetZoneMode();
1129 m_mltProducer->set_speed(0.0);
1130 m_mltProducer->seek((int) startTime.frames(m_fps));
1132 m_mltConsumer->purge();
1135 void Render::pause()
1137 if (!m_mltProducer || !m_mltConsumer)
1139 if (m_mltProducer->get_speed() == 0.0) return;
1140 if (m_isZoneMode) resetZoneMode();
1142 m_mltConsumer->set("refresh", 0);
1143 m_mltProducer->set_speed(0.0);
1144 emit rendererPosition(m_framePosition);
1145 m_mltProducer->seek(m_framePosition);
1146 m_mltConsumer->purge();
1149 void Render::switchPlay()
1151 if (!m_mltProducer || !m_mltConsumer)
1153 if (m_isZoneMode) resetZoneMode();
1154 if (m_mltProducer->get_speed() == 0.0) {
1155 m_isBlocked = false;
1156 m_mltProducer->set_speed(1.0);
1157 m_mltConsumer->set("refresh", 1);
1160 m_mltConsumer->set("refresh", 0);
1161 m_mltProducer->set_speed(0.0);
1162 emit rendererPosition(m_framePosition);
1163 m_mltProducer->seek(m_framePosition);
1164 m_mltConsumer->purge();
1165 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1166 //m_mltConsumer->set("refresh", 0);
1167 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1168 m_mltProducer->set_speed(0);
1169 m_mltProducer->seek( position );
1170 //m_mltProducer->seek((int) m_framePosition);
1171 m_isBlocked = false;*/
1173 /*if (speed == 0.0) {
1174 m_mltProducer->seek((int) m_framePosition + 1);
1175 m_mltConsumer->purge();
1180 void Render::play(double speed)
1184 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1185 m_isBlocked = false;
1186 m_mltProducer->set_speed(speed);
1187 /*if (speed == 0.0) {
1188 m_mltProducer->seek((int) m_framePosition + 1);
1189 m_mltConsumer->purge();
1194 void Render::play(const GenTime & startTime)
1196 if (!m_mltProducer || !m_mltConsumer)
1198 m_isBlocked = false;
1199 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1200 m_mltProducer->set_speed(1.0);
1201 m_mltConsumer->set("refresh", 1);
1204 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1206 if (!m_mltProducer || !m_mltConsumer)
1208 //m_mltProducer->set("eof", "loop");
1209 m_isLoopMode = true;
1210 m_loopStart = startTime;
1211 playZone(startTime, stopTime);
1214 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1216 if (!m_mltProducer || !m_mltConsumer)
1218 m_isBlocked = false;
1219 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1220 m_mltProducer->set("out", stopTime.frames(m_fps));
1221 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1222 m_mltProducer->set_speed(1.0);
1223 m_mltConsumer->set("refresh", 1);
1224 m_isZoneMode = true;
1227 void Render::resetZoneMode()
1229 if (!m_isZoneMode && !m_isLoopMode) return;
1230 m_mltProducer->set("out", m_originalOut);
1231 //m_mltProducer->set("eof", "pause");
1232 m_isZoneMode = false;
1233 m_isLoopMode = false;
1236 void Render::seekToFrame(int pos)
1238 //kDebug()<<" ********* RENDER SEEK TO POS";
1241 m_isBlocked = false;
1243 m_mltProducer->seek(pos);
1247 void Render::askForRefresh()
1249 // Use a Timer so that we don't refresh too much
1250 m_refreshTimer->start(300);
1253 void Render::doRefresh()
1255 // Use a Timer so that we don't refresh too much
1256 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1259 void Render::refresh()
1261 if (!m_mltProducer || m_isBlocked)
1263 m_refreshTimer->stop();
1264 if (m_mltConsumer) {
1265 m_mltConsumer->set("refresh", 1);
1269 void Render::setDropFrames(bool show)
1271 if (m_mltConsumer) {
1273 if (show == false) dropFrames = 0;
1274 m_mltConsumer->stop();
1275 m_mltConsumer->set("play.real_time", dropFrames);
1276 if (m_mltConsumer->start() == -1) {
1277 emit blockMonitors();
1278 delete m_mltProducer;
1279 m_mltProducer = NULL;
1285 double Render::playSpeed()
1287 if (m_mltProducer) return m_mltProducer->get_speed();
1291 GenTime Render::seekPosition() const
1293 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1294 else return GenTime();
1298 const QString & Render::rendererName() const
1304 void Render::emitFrameNumber(double position)
1306 m_framePosition = position;
1307 emit rendererPosition((int) position);
1308 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1311 void Render::emitConsumerStopped()
1313 // This is used to know when the playing stopped
1314 if (m_mltProducer) {
1315 double pos = m_mltProducer->position();
1316 if (m_isLoopMode) play(m_loopStart);
1317 else if (m_isZoneMode) resetZoneMode();
1318 emit rendererStopped((int) pos);
1319 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1320 //new QCustomEvent(10002));
1326 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1328 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1332 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1334 if (!m_mltProducer) {
1335 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1339 //int height = 1080;//KdenliveSettings::defaultheight();
1340 //int width = 1940; //KdenliveSettings::displaywidth();
1342 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1344 QPixmap pix(width, height);
1345 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1346 m_convert.set("forced", mlt_image_rgb24a);
1347 m_mltProducer->attach(m_convert);
1348 Mlt::Frame * frame = m_mltProducer->get_frame();
1349 m_mltProducer->detach(m_convert);
1351 pix = frameThumbnail(frame, width, height);
1354 pix.save(url.path(), "PNG");
1355 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1358 /** MLT PLAYLIST DIRECT MANIPULATON **/
1361 void Render::mltCheckLength()
1363 //kDebug()<<"checking track length: "<<track<<"..........";
1365 Mlt::Service service(m_mltProducer->get_service());
1366 Mlt::Tractor tractor(service);
1368 int trackNb = tractor.count();
1372 Mlt::Producer trackProducer(tractor.track(0));
1373 duration = trackProducer.get_playtime() - 1;
1374 m_mltProducer->set("out", duration);
1375 emit durationChanged(duration);
1378 while (trackNb > 1) {
1379 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1380 trackDuration = trackProducer.get_playtime() - 1;
1382 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1383 if (trackDuration > duration) duration = trackDuration;
1387 Mlt::Producer blackTrackProducer(tractor.track(0));
1389 if (blackTrackProducer.get_playtime() - 1 != duration) {
1390 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1391 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1392 if (duration > m_blackClip->get_length()) {
1393 m_blackClip->set("length", duration);
1394 if (blackclip) blackclip->set("length", duration);
1396 if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
1397 blackTrackPlaylist.clear();
1398 blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
1399 } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1401 m_mltProducer->set("out", duration);
1402 emit durationChanged(duration);
1406 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1408 if (m_mltProducer == NULL) {
1409 kDebug() << "PLAYLIST NOT INITIALISED //////";
1412 Mlt::Producer parentProd(m_mltProducer->parent());
1413 if (parentProd.get_producer() == NULL) {
1414 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1418 Mlt::Service service(parentProd.get_service());
1419 Mlt::Tractor tractor(service);
1420 if (info.track > tractor.count() - 1) {
1421 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1424 mlt_service_lock(service.get_service());
1425 Mlt::Producer trackProducer(tractor.track(info.track));
1426 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1427 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1429 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1430 // We want a slowmotion producer
1431 double speed = element.attribute("speed", "1.0").toDouble();
1432 QString url = QString::fromUtf8(prod->get("resource"));
1433 url.append('?' + QString::number(speed));
1434 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1435 if (!slowprod || slowprod->get_producer() == NULL) {
1436 char *tmp = decodedString(url);
1437 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1439 QString id = prod->get("id");
1440 if (id.contains('_')) id = id.section('_', 0, 0);
1441 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1442 tmp = decodedString(producerid);
1443 slowprod->set("id", tmp);
1445 m_slowmotionProducers.insert(url, slowprod);
1450 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1451 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1453 /*if (QString(prod->get("transparency")).toInt() == 1)
1454 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1456 mlt_service_unlock(service.get_service());
1458 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1459 //tractor.multitrack()->refresh();
1460 //tractor.refresh();
1464 void Render::mltCutClip(int track, GenTime position)
1469 Mlt::Service service(m_mltProducer->parent().get_service());
1470 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1472 Mlt::Tractor tractor(service);
1473 Mlt::Producer trackProducer(tractor.track(track));
1474 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1477 /* // Display playlist info
1478 kDebug()<<"//////////// BEFORE";
1479 for (int i = 0; i < trackPlaylist.count(); i++) {
1480 int blankStart = trackPlaylist.clip_start(i);
1481 int blankDuration = trackPlaylist.clip_length(i) - 1;
1483 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1484 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1487 int cutPos = (int) position.frames(m_fps);
1489 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1490 if (trackPlaylist.is_blank(clipIndex)) {
1491 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1492 m_isBlocked = false;
1495 mlt_service_lock(service.get_service());
1496 int clipStart = trackPlaylist.clip_start(clipIndex);
1497 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1498 mlt_service_unlock(service.get_service());
1500 // duplicate effects
1501 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1502 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1504 if (original == NULL || clip == NULL) {
1505 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1507 Mlt::Service clipService(original->get_service());
1508 Mlt::Service dupService(clip->get_service());
1510 Mlt::Filter *filter = clipService.filter(ct);
1512 // Only duplicate Kdenlive filters, and skip the fade in effects
1513 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1514 // looks like there is no easy way to duplicate a filter,
1515 // so we will create a new one and duplicate its properties
1516 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1517 if (dup && dup->is_valid()) {
1518 Mlt::Properties entries(filter->get_properties());
1519 for (int i = 0; i < entries.count(); i++) {
1520 dup->set(entries.get_name(i), entries.get(i));
1522 dupService.attach(*dup);
1526 filter = clipService.filter(ct);
1529 /* // Display playlist info
1530 kDebug()<<"//////////// AFTER";
1531 for (int i = 0; i < trackPlaylist.count(); i++) {
1532 int blankStart = trackPlaylist.clip_start(i);
1533 int blankDuration = trackPlaylist.clip_length(i) - 1;
1535 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1536 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1539 m_isBlocked = false;
1542 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1545 mltRemoveClip(info.track, info.startPos);
1546 mltInsertClip(info, element, prod);
1550 bool Render::mltRemoveClip(int track, GenTime position)
1552 Mlt::Service service(m_mltProducer->parent().get_service());
1553 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1555 Mlt::Tractor tractor(service);
1556 mlt_service_lock(service.get_service());
1557 Mlt::Producer trackProducer(tractor.track(track));
1558 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1559 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1561 // Display playlist info
1562 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1563 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1564 int blankStart = trackPlaylist.clip_start(i);
1565 int blankDuration = trackPlaylist.clip_length(i) - 1;
1567 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1568 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1570 if (trackPlaylist.is_blank(clipIndex)) {
1571 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1572 mlt_service_unlock(service.get_service());
1575 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1577 trackPlaylist.replace_with_blank(clipIndex);
1578 trackPlaylist.consolidate_blanks(0);
1579 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1580 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1582 /* // Display playlist info
1583 kDebug()<<"//// AFTER";
1584 for (int i = 0; i < trackPlaylist.count(); i++) {
1585 int blankStart = trackPlaylist.clip_start(i);
1586 int blankDuration = trackPlaylist.clip_length(i) - 1;
1588 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1589 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1591 mlt_service_unlock(service.get_service());
1592 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1593 m_isBlocked = false;
1597 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1599 if (!m_mltProducer) {
1600 kDebug() << "PLAYLIST NOT INITIALISED //////";
1603 Mlt::Producer parentProd(m_mltProducer->parent());
1604 if (parentProd.get_producer() == NULL) {
1605 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1609 Mlt::Service service(parentProd.get_service());
1610 Mlt::Tractor tractor(service);
1611 int insertPos = pos.frames(m_fps);
1613 Mlt::Producer trackProducer(tractor.track(track));
1614 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1615 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1616 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1617 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1618 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1621 int Render::mltTrackDuration(int track)
1623 if (!m_mltProducer) {
1624 kDebug() << "PLAYLIST NOT INITIALISED //////";
1627 Mlt::Producer parentProd(m_mltProducer->parent());
1628 if (parentProd.get_producer() == NULL) {
1629 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1633 Mlt::Service service(parentProd.get_service());
1634 Mlt::Tractor tractor(service);
1636 Mlt::Producer trackProducer(tractor.track(track));
1637 return trackProducer.get_playtime() - 1;
1640 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1642 if (!m_mltProducer) {
1643 kDebug() << "PLAYLIST NOT INITIALISED //////";
1646 Mlt::Producer parentProd(m_mltProducer->parent());
1647 if (parentProd.get_producer() == NULL) {
1648 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1651 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1652 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1654 Mlt::Service service(parentProd.get_service());
1655 Mlt::Tractor tractor(service);
1656 mlt_service_lock(service.get_service());
1657 int diff = duration.frames(m_fps);
1658 int offset = timeOffset.frames(m_fps);
1662 // insert space in one track only
1663 Mlt::Producer trackProducer(tractor.track(track));
1664 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1665 insertPos = trackClipStartList.value(track);
1666 if (insertPos != -1) {
1667 insertPos += offset;
1668 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1669 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1671 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1672 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1673 int position = trackPlaylist.clip_start(clipIndex);
1674 trackPlaylist.remove_region(position, - diff - 1);
1676 trackPlaylist.consolidate_blanks(0);
1678 // now move transitions
1679 mlt_service serv = m_mltProducer->parent().get_service();
1680 mlt_service nextservice = mlt_service_get_producer(serv);
1681 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1682 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1683 QString resource = mlt_properties_get(properties, "mlt_service");
1685 while (mlt_type == "transition") {
1686 mlt_transition tr = (mlt_transition) nextservice;
1687 int currentTrack = mlt_transition_get_b_track(tr);
1688 int currentIn = (int) mlt_transition_get_in(tr);
1689 int currentOut = (int) mlt_transition_get_out(tr);
1690 insertPos = trackTransitionStartList.value(track);
1691 if (insertPos != -1) {
1692 insertPos += offset;
1693 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1694 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1697 nextservice = mlt_service_producer(nextservice);
1698 if (nextservice == NULL) break;
1699 properties = MLT_SERVICE_PROPERTIES(nextservice);
1700 mlt_type = mlt_properties_get(properties, "mlt_type");
1701 resource = mlt_properties_get(properties, "mlt_service");
1704 int trackNb = tractor.count();
1705 while (trackNb > 1) {
1706 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1707 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1710 //int clipNb = trackPlaylist.count();
1711 insertPos = trackClipStartList.value(trackNb - 1);
1712 if (insertPos != -1) {
1713 insertPos += offset;
1715 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1716 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1717 for (int i = 0; i < clipNb; i++) {
1718 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1719 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1720 kDebug()<<"-------------";
1722 kDebug()<<"END-------------";*/
1725 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1726 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1728 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1729 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1730 int position = trackPlaylist.clip_start(clipIndex);
1731 trackPlaylist.remove_region(position, - diff - 1);
1733 trackPlaylist.consolidate_blanks(0);
1737 // now move transitions
1738 mlt_service serv = m_mltProducer->parent().get_service();
1739 mlt_service nextservice = mlt_service_get_producer(serv);
1740 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1741 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1742 QString resource = mlt_properties_get(properties, "mlt_service");
1744 while (mlt_type == "transition") {
1745 mlt_transition tr = (mlt_transition) nextservice;
1746 int currentIn = (int) mlt_transition_get_in(tr);
1747 int currentOut = (int) mlt_transition_get_out(tr);
1748 int currentTrack = mlt_transition_get_b_track(tr);
1749 insertPos = trackTransitionStartList.value(currentTrack);
1750 if (insertPos != -1) {
1751 insertPos += offset;
1752 if (currentOut > insertPos && resource != "mix") {
1753 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1756 nextservice = mlt_service_producer(nextservice);
1757 if (nextservice == NULL) break;
1758 properties = MLT_SERVICE_PROPERTIES(nextservice);
1759 mlt_type = mlt_properties_get(properties, "mlt_type");
1760 resource = mlt_properties_get(properties, "mlt_service");
1763 mlt_service_unlock(service.get_service());
1765 m_mltConsumer->set("refresh", 1);
1769 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1771 Mlt::Service sourceService(source->get_service());
1772 Mlt::Service destService(dest->get_service());
1774 // move all effects to the correct producer
1776 Mlt::Filter *filter = sourceService.filter(ct);
1778 if (filter->get("kdenlive_ix") != 0) {
1779 sourceService.detach(*filter);
1780 destService.attach(*filter);
1782 filter = sourceService.filter(ct);
1786 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1790 Mlt::Service service(m_mltProducer->parent().get_service());
1791 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1792 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1793 Mlt::Tractor tractor(service);
1794 Mlt::Producer trackProducer(tractor.track(info.track));
1795 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1796 int startPos = info.startPos.frames(m_fps);
1797 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1798 int clipLength = trackPlaylist.clip_length(clipIndex);
1800 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1804 if (!clip->is_valid() || clip->is_blank()) {
1809 Mlt::Producer clipparent = clip->parent();
1810 if (!clipparent.is_valid() || clipparent.is_blank()) {
1816 QString serv = clipparent.get("mlt_service");
1817 QString id = clipparent.get("id");
1818 //kDebug() << "CLIP SERVICE: " << serv;
1819 if (serv == "avformat" && speed != 1.0) {
1820 mlt_service_lock(service.get_service());
1821 QString url = QString::fromUtf8(clipparent.get("resource"));
1822 url.append('?' + QString::number(speed));
1823 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1824 if (!slowprod || slowprod->get_producer() == NULL) {
1825 char *tmp = decodedString(url);
1826 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1828 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1829 tmp = decodedString(producerid);
1830 slowprod->set("id", tmp);
1832 m_slowmotionProducers.insert(url, slowprod);
1834 trackPlaylist.replace_with_blank(clipIndex);
1835 trackPlaylist.consolidate_blanks(0);
1836 // Check that the blank space is long enough for our new duration
1837 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1838 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1840 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1841 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1842 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1843 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1845 // move all effects to the correct producer
1846 mltPasteEffects(clip, cut);
1848 trackPlaylist.insert_at(startPos, *cut, 1);
1849 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1850 newLength = trackPlaylist.clip_length(clipIndex);
1851 mlt_service_unlock(service.get_service());
1852 } else if (speed == 1.0) {
1853 mlt_service_lock(service.get_service());
1855 trackPlaylist.replace_with_blank(clipIndex);
1856 trackPlaylist.consolidate_blanks(0);
1858 // Check that the blank space is long enough for our new duration
1859 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1860 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1863 GenTime oldDuration = GenTime(clipLength, m_fps);
1864 GenTime newDuration = oldDuration * oldspeed;
1865 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1866 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1867 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1868 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1870 // move all effects to the correct producer
1871 mltPasteEffects(clip, cut);
1873 trackPlaylist.insert_at(startPos, *cut, 1);
1874 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1875 newLength = trackPlaylist.clip_length(clipIndex);
1876 mlt_service_unlock(service.get_service());
1878 } else if (serv == "framebuffer") {
1879 mlt_service_lock(service.get_service());
1880 QString url = QString::fromUtf8(clipparent.get("resource"));
1881 url = url.section('?', 0, 0);
1882 url.append('?' + QString::number(speed));
1883 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1884 if (!slowprod || slowprod->get_producer() == NULL) {
1885 char *tmp = decodedString(url);
1886 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1888 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1889 tmp = decodedString(producerid);
1890 slowprod->set("id", tmp);
1892 m_slowmotionProducers.insert(url, slowprod);
1894 trackPlaylist.replace_with_blank(clipIndex);
1895 trackPlaylist.consolidate_blanks(0);
1897 GenTime oldDuration = GenTime(clipLength, m_fps);
1898 GenTime newDuration = oldDuration * oldspeed / speed;
1900 // Check that the blank space is long enough for our new duration
1901 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1902 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1905 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1906 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1907 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1908 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1910 // move all effects to the correct producer
1911 mltPasteEffects(clip, cut);
1913 trackPlaylist.insert_at(startPos, *cut, 1);
1914 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1915 newLength = trackPlaylist.clip_length(clipIndex);
1917 mlt_service_unlock(service.get_service());
1921 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1922 m_isBlocked = false;
1926 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1928 kDebug() << "// TRYing to remove effect at: " << index;
1929 Mlt::Service service(m_mltProducer->parent().get_service());
1930 bool success = false;
1931 Mlt::Tractor tractor(service);
1932 Mlt::Producer trackProducer(tractor.track(track));
1933 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1934 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1935 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1937 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1940 Mlt::Service clipService(clip->get_service());
1941 // if (tag.startsWith("ladspa")) tag = "ladspa";
1944 Mlt::Filter *filter = clipService.filter(ct);
1946 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1947 if (clipService.detach(*filter) == 0) success = true;
1948 kDebug() << " / / / DLEETED EFFECT: " << ct;
1949 } else if (updateIndex) {
1950 // Adjust the other effects index
1951 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1954 filter = clipService.filter(ct);
1956 m_isBlocked = false;
1957 if (doRefresh) refresh();
1962 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1965 Mlt::Service service(m_mltProducer->parent().get_service());
1967 Mlt::Tractor tractor(service);
1968 Mlt::Producer trackProducer(tractor.track(track));
1969 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1971 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1975 Mlt::Service clipService(clip->get_service());
1978 // temporarily remove all effects after insert point
1979 QList <Mlt::Filter *> filtersList;
1980 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1982 Mlt::Filter *filter = clipService.filter(ct);
1984 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1985 filtersList.append(filter);
1986 clipService.detach(*filter);
1988 filter = clipService.filter(ct);
1992 QString tag = params.paramValue("tag");
1993 kDebug() << " / / INSERTING EFFECT: " << tag;
1994 if (tag.startsWith("ladspa")) tag = "ladspa";
1995 char *filterTag = decodedString(tag);
1996 char *filterId = decodedString(params.paramValue("id"));
1997 QHash<QString, QString>::Iterator it;
1998 QString kfr = params.paramValue("keyframes");
2000 if (!kfr.isEmpty()) {
2001 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2002 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2003 char *starttag = decodedString(params.paramValue("starttag", "start"));
2004 char *endtag = decodedString(params.paramValue("endtag", "end"));
2005 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2006 int duration = clip->get_playtime();
2007 //double max = params.paramValue("max").toDouble();
2008 double min = params.paramValue("min").toDouble();
2009 double factor = params.paramValue("factor", "1").toDouble();
2010 params.removeParam("starttag");
2011 params.removeParam("endtag");
2012 params.removeParam("keyframes");
2013 params.removeParam("min");
2014 params.removeParam("max");
2015 params.removeParam("factor");
2017 for (int i = 0; i < keyFrames.size() - 1; ++i) {
2018 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2019 if (filter && filter->is_valid()) {
2020 filter->set("kdenlive_id", filterId);
2021 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2022 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2023 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2024 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2025 if (x2 == -1) x2 = duration;
2027 for (int j = 0; j < params.count(); j++) {
2028 char *name = decodedString(params.at(j).name());
2029 char *value = decodedString(params.at(j).value());
2030 filter->set(name, value);
2035 filter->set("in", x1);
2036 filter->set("out", x2);
2037 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2038 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2039 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2040 clipService.attach(*filter);
2047 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2048 if (filter && filter->is_valid())
2049 filter->set("kdenlive_id", filterId);
2051 kDebug() << "filter is NULL";
2052 m_isBlocked = false;
2056 params.removeParam("kdenlive_id");
2058 for (int j = 0; j < params.count(); j++) {
2059 char *name = decodedString(params.at(j).name());
2060 char *value = decodedString(params.at(j).value());
2061 filter->set(name, value);
2067 QString effectArgs = params.paramValue("id").section('_', 1);
2069 params.removeParam("id");
2070 params.removeParam("kdenlive_ix");
2071 params.removeParam("tag");
2072 params.removeParam("disabled");
2074 for (int j = 0; j < params.count(); j++) {
2075 effectArgs.append(' ' + params.at(j).value());
2077 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2078 char *value = decodedString(effectArgs.simplified());
2079 filter->set("effect", value);
2084 // attach filter to the clip
2085 clipService.attach(*filter);
2090 // re-add following filters
2091 for (int i = 0; i < filtersList.count(); i++) {
2092 clipService.attach(*(filtersList.at(i)));
2095 m_isBlocked = false;
2096 if (doRefresh) refresh();
2100 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2102 QString index = params.paramValue("kdenlive_ix");
2103 QString tag = params.paramValue("tag");
2105 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2106 // This is a keyframe effect, to edit it, we remove it and re-add it.
2107 mltRemoveEffect(track, position, index, true);
2108 bool success = mltAddEffect(track, position, params);
2113 Mlt::Service service(m_mltProducer->parent().get_service());
2115 Mlt::Tractor tractor(service);
2116 Mlt::Producer trackProducer(tractor.track(track));
2117 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2118 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2119 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2121 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2124 Mlt::Service clipService(clip->get_service());
2127 Mlt::Filter *filter = clipService.filter(ct);
2129 if (filter->get("kdenlive_ix") == index) {
2133 filter = clipService.filter(ct);
2137 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2138 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2140 filter = clipService.filter(ct);
2141 QList <Mlt::Filter *> filtersList;
2143 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2144 filtersList.append(filter);
2145 clipService.detach(*filter);
2147 filter = clipService.filter(ct);
2149 bool success = mltAddEffect(track, position, params);
2151 for (int i = 0; i < filtersList.count(); i++) {
2152 clipService.attach(*(filtersList.at(i)));
2155 m_isBlocked = false;
2159 for (int j = 0; j < params.count(); j++) {
2160 char *name = decodedString(params.at(j).name());
2161 char *value = decodedString(params.at(j).value());
2162 filter->set(name, value);
2167 m_isBlocked = false;
2172 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2175 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2176 Mlt::Service service(m_mltProducer->parent().get_service());
2178 Mlt::Tractor tractor(service);
2179 Mlt::Producer trackProducer(tractor.track(track));
2180 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2181 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2182 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2184 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2187 Mlt::Service clipService(clip->get_service());
2190 QList <Mlt::Filter *> filtersList;
2191 Mlt::Filter *filter = clipService.filter(ct);
2193 if (newPos > oldPos) {
2195 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2196 filter->set("kdenlive_ix", newPos);
2197 filtersList.append(filter);
2198 clipService.detach(*filter);
2199 filter = clipService.filter(ct);
2200 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2201 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2203 filter = clipService.filter(ct);
2207 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2208 filtersList.append(filter);
2209 clipService.detach(*filter);
2211 filter = clipService.filter(ct);
2215 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2216 filter->set("kdenlive_ix", newPos);
2217 filtersList.append(filter);
2218 clipService.detach(*filter);
2220 filter = clipService.filter(ct);
2224 filter = clipService.filter(ct);
2226 int pos = QString(filter->get("kdenlive_ix")).toInt();
2227 if (pos >= newPos) {
2228 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2229 filtersList.append(filter);
2230 clipService.detach(*filter);
2232 filter = clipService.filter(ct);
2236 for (int i = 0; i < filtersList.count(); i++) {
2237 clipService.attach(*(filtersList.at(i)));
2240 m_isBlocked = false;
2244 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2247 Mlt::Service service(m_mltProducer->parent().get_service());
2248 Mlt::Tractor tractor(service);
2249 Mlt::Producer trackProducer(tractor.track(info.track));
2250 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2252 /* // Display playlist info
2253 kDebug()<<"//////////// BEFORE RESIZE";
2254 for (int i = 0; i < trackPlaylist.count(); i++) {
2255 int blankStart = trackPlaylist.clip_start(i);
2256 int blankDuration = trackPlaylist.clip_length(i) - 1;
2258 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2259 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2262 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2263 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2264 m_isBlocked = false;
2267 mlt_service_lock(service.get_service());
2268 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2269 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2270 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2271 int previousStart = clip->get_in();
2272 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2273 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2274 if (newDuration > clip->get_length()) {
2275 clip->parent().set("length", newDuration + 1);
2276 clip->set("length", newDuration + 1);
2278 if (newDuration > clip->get_out()) {
2279 clip->parent().set_in_and_out(0, newDuration + 1);
2280 clip->set_in_and_out(0, newDuration + 1);
2283 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2284 trackPlaylist.consolidate_blanks(0);
2285 // skip to next clip
2287 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2289 // clip was made longer, trim next blank if there is one.
2290 if (clipIndex < trackPlaylist.count()) {
2291 // If this is not the last clip in playlist
2292 if (trackPlaylist.is_blank(clipIndex)) {
2293 int blankStart = trackPlaylist.clip_start(clipIndex);
2294 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2295 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2296 if (diff - blankDuration == 1) {
2297 trackPlaylist.remove(clipIndex);
2298 } else trackPlaylist.remove_region(blankStart, diff - 1);
2300 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2303 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2304 trackPlaylist.consolidate_blanks(0);
2305 mlt_service_unlock(service.get_service());
2307 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2308 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2309 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2310 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2311 ItemInfo transpinfo;
2312 transpinfo.startPos = info.startPos;
2313 transpinfo.endPos = info.startPos + clipDuration;
2314 transpinfo.track = info.track;
2315 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2317 m_isBlocked = false;
2318 m_mltConsumer->set("refresh", 1);
2322 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2324 Mlt::Service service(m_mltProducer->parent().get_service());
2325 Mlt::Tractor tractor(service);
2326 Mlt::Producer trackProducer(tractor.track(track));
2329 if (blind) trackProducer.set("hide", 3);
2330 else trackProducer.set("hide", 2);
2332 trackProducer.set("hide", 1);
2334 trackProducer.set("hide", 0);
2336 tractor.multitrack()->refresh();
2342 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2344 Mlt::Service service(m_mltProducer->parent().get_service());
2345 int frameOffset = (int) diff.frames(m_fps);
2346 Mlt::Tractor tractor(service);
2347 Mlt::Producer trackProducer(tractor.track(info.track));
2348 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2349 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2350 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2353 mlt_service_lock(service.get_service());
2354 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2355 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2357 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2358 mlt_service_unlock(service.get_service());
2361 int previousStart = clip->get_in();
2363 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2365 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2366 m_isBlocked = false;
2367 mlt_service_unlock(service.get_service());
2368 m_mltConsumer->set("refresh", 1);
2372 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2374 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2375 Mlt::Service service(m_mltProducer->parent().get_service());
2376 int moveFrame = (int) diff.frames(m_fps);
2377 Mlt::Tractor tractor(service);
2378 Mlt::Producer trackProducer(tractor.track(info.track));
2379 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2380 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2381 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2384 mlt_service_lock(service.get_service());
2385 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2386 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2388 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2389 mlt_service_unlock(service.get_service());
2392 int previousStart = clip->get_in();
2394 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2396 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2397 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2398 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2400 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2401 int blankIndex = clipIndex - 1;
2402 int blankLength = trackPlaylist.clip_length(blankIndex);
2403 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2404 if (! trackPlaylist.is_blank(blankIndex)) {
2405 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2407 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2408 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2410 trackPlaylist.consolidate_blanks(0);
2411 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2412 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2413 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2414 ItemInfo transpinfo;
2415 transpinfo.startPos = info.startPos + diff;
2416 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2417 transpinfo.track = info.track;
2418 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2420 m_isBlocked = false;
2421 //m_mltConsumer->set("refresh", 1);
2422 mlt_service_unlock(service.get_service());
2423 m_mltConsumer->set("refresh", 1);
2427 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2429 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2433 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2435 if (prod == NULL || !prod->is_valid()) {
2436 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2439 kDebug() << "NEW PROD ID: " << prod->get("id");
2441 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2442 mlt_service_lock(m_mltConsumer->get_service());
2443 Mlt::Service service(m_mltProducer->parent().get_service());
2444 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2446 Mlt::Tractor tractor(service);
2447 Mlt::Producer trackProducer(tractor.track(track));
2448 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2449 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2450 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2451 if (clipProducer.is_blank()) {
2452 kDebug() << "// ERROR UPDATING CLIP PROD";
2453 mlt_service_unlock(m_mltConsumer->get_service());
2457 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2459 // move all effects to the correct producer
2460 mltPasteEffects(&clipProducer, clip);
2462 trackPlaylist.insert_at(pos, clip, 1);
2463 mlt_service_unlock(m_mltConsumer->get_service());
2467 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2471 Mlt::Service service(m_mltProducer->parent().get_service());
2472 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2474 Mlt::Tractor tractor(service);
2475 mlt_service_lock(service.get_service());
2476 Mlt::Producer trackProducer(tractor.track(startTrack));
2477 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2478 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
2479 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2480 bool checkLength = false;
2481 if (endTrack == startTrack) {
2482 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2483 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2484 // error, destination is not empty
2485 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2486 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2487 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2488 mlt_service_unlock(service.get_service());
2492 trackPlaylist.consolidate_blanks(0);
2493 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2494 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2495 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2497 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2499 //mlt_service_unlock(service.get_service());
2501 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2502 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2503 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2504 // error, destination is not empty
2505 mlt_service_unlock(service.get_service());
2509 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2510 if (clipProducer.is_blank()) {
2511 // error, destination is not empty
2512 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2513 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2514 mlt_service_unlock(service.get_service());
2518 trackPlaylist.consolidate_blanks(0);
2519 destTrackPlaylist.consolidate_blanks(1);
2520 Mlt::Producer *clip;
2521 // check if we are moving a slowmotion producer
2522 QString serv = clipProducer.parent().get("mlt_service");
2523 QString currentid = clipProducer.parent().get("id");
2524 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2525 clip = &clipProducer;
2528 // Special case: prod is null when using placeholder clips.
2529 // in that case, use the producer existing in playlist. Note that
2530 // it will bypass the one producer per track logic and might cause
2531 // Sound cracks if clip is moved so that it overlaps another copy of itself
2532 clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
2533 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2536 // move all effects to the correct producer
2537 mltPasteEffects(&clipProducer, clip);
2539 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2540 destTrackPlaylist.consolidate_blanks(0);
2541 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2542 kDebug() << "//////// moving clip transparency";
2543 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2545 if (clipIndex > trackPlaylist.count()) checkLength = true;
2546 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2549 mlt_service_unlock(service.get_service());
2550 if (checkLength) mltCheckLength();
2553 //m_mltConsumer->set("refresh", 1);
2557 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2559 int new_in = (int)newIn.frames(m_fps);
2560 int new_out = (int)newOut.frames(m_fps) - 1;
2561 if (new_in >= new_out) return false;
2563 mlt_service serv = m_mltProducer->parent().get_service();
2565 mlt_service_lock(serv);
2566 //m_mltConsumer->set("refresh", 0);
2569 mlt_service nextservice = mlt_service_get_producer(serv);
2570 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2571 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2572 QString resource = mlt_properties_get(properties, "mlt_service");
2573 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2575 while (mlt_type == "transition") {
2576 mlt_transition tr = (mlt_transition) nextservice;
2577 int currentTrack = mlt_transition_get_b_track(tr);
2578 int currentIn = (int) mlt_transition_get_in(tr);
2579 int currentOut = (int) mlt_transition_get_out(tr);
2581 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2582 mlt_transition_set_in_and_out(tr, new_in, new_out);
2583 if (newTrack - startTrack != 0) {
2584 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2586 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2587 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2588 mlt_properties_set_int(properties, "b_track", newTrack);
2589 //kDebug() << "set new start & end :" << new_in << new_out<< "TR OFFSET: "<<trackOffset<<", TRACKS: "<<mlt_transition_get_a_track(tr)<<'x'<<mlt_transition_get_b_track(tr);
2593 nextservice = mlt_service_producer(nextservice);
2594 if (nextservice == NULL) break;
2595 properties = MLT_SERVICE_PROPERTIES(nextservice);
2596 mlt_type = mlt_properties_get(properties, "mlt_type");
2597 resource = mlt_properties_get(properties, "mlt_service");
2599 mlt_service_unlock(serv);
2602 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2606 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2608 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2610 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2611 mltAddTransition(tag, a_track, b_track, in, out, xml);
2613 //mltSavePlaylist();
2616 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2618 mlt_service serv = m_mltProducer->parent().get_service();
2619 mlt_service_lock(serv);
2623 mlt_service nextservice = mlt_service_get_producer(serv);
2624 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2625 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2626 QString resource = mlt_properties_get(properties, "mlt_service");
2627 int in_pos = (int) in.frames(m_fps);
2628 int out_pos = (int) out.frames(m_fps) - 1;
2630 while (mlt_type == "transition") {
2631 mlt_transition tr = (mlt_transition) nextservice;
2632 int currentTrack = mlt_transition_get_b_track(tr);
2633 int currentBTrack = mlt_transition_get_a_track(tr);
2634 int currentIn = (int) mlt_transition_get_in(tr);
2635 int currentOut = (int) mlt_transition_get_out(tr);
2637 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2639 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2640 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2641 QMap<QString, QString>::Iterator it;
2643 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2644 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2645 if (currentBTrack != a_track) {
2646 mlt_properties_set_int(properties, "a_track", a_track);
2648 for (it = map.begin(); it != map.end(); ++it) {
2650 char *name = decodedString(key);
2651 char *value = decodedString(it.value());
2652 mlt_properties_set(transproperties, name, value);
2653 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2654 //filter->set("kdenlive_id", id);
2660 nextservice = mlt_service_producer(nextservice);
2661 if (nextservice == NULL) break;
2662 properties = MLT_SERVICE_PROPERTIES(nextservice);
2663 mlt_type = mlt_properties_get(properties, "mlt_type");
2664 resource = mlt_properties_get(properties, "mlt_service");
2666 mlt_service_unlock(serv);
2669 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2672 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2674 mlt_service serv = m_mltProducer->parent().get_service();
2676 mlt_service_lock(serv);
2678 Mlt::Service service(serv);
2679 Mlt::Tractor tractor(service);
2680 Mlt::Field *field = tractor.field();
2682 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2684 mlt_service nextservice = mlt_service_get_producer(serv);
2685 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2686 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2687 QString resource = mlt_properties_get(properties, "mlt_service");
2689 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2690 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2692 while (mlt_type == "transition") {
2693 mlt_transition tr = (mlt_transition) nextservice;
2694 int currentTrack = mlt_transition_get_b_track(tr);
2695 int currentIn = (int) mlt_transition_get_in(tr);
2696 int currentOut = (int) mlt_transition_get_out(tr);
2697 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2699 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2700 mlt_field_disconnect_service(field->get_field(), nextservice);
2703 nextservice = mlt_service_producer(nextservice);
2704 if (nextservice == NULL) break;
2705 properties = MLT_SERVICE_PROPERTIES(nextservice);
2706 mlt_type = mlt_properties_get(properties, "mlt_type");
2707 resource = mlt_properties_get(properties, "mlt_service");
2709 mlt_service_unlock(serv);
2712 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2715 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2717 QDomNodeList attribs = xml.elementsByTagName("parameter");
2718 QMap<QString, QString> map;
2719 for (int i = 0; i < attribs.count(); i++) {
2720 QDomElement e = attribs.item(i).toElement();
2721 QString name = e.attribute("name");
2722 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2723 map[name] = e.attribute("default");
2724 if (!e.attribute("value").isEmpty()) {
2725 map[name] = e.attribute("value");
2727 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2728 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2729 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2732 if (e.attribute("namedesc").contains(';')) {
2733 QString format = e.attribute("format");
2734 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2735 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2737 QTextStream txtNeu(&neu);
2738 if (values.size() > 0)
2739 txtNeu << (int)values[0].toDouble();
2741 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
2742 txtNeu << separators[i];
2743 txtNeu << (int)(values[i+1].toDouble());
2745 if (i < separators.size())
2746 txtNeu << separators[i];
2747 map[e.attribute("name")] = neu;
2754 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2756 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2757 Mlt::Service service(m_mltProducer->parent().get_service());
2758 Mlt::Tractor tractor(service);
2759 Mlt::Field *field = tractor.field();
2761 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2762 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2763 transition->set("transparency", id);
2764 transition->set("fill", 1);
2765 transition->set("internal_added", 237);
2766 field->plant_transition(*transition, transitiontrack, info.track);
2770 void Render::mltDeleteTransparency(int pos, int track, int id)
2772 Mlt::Service service(m_mltProducer->parent().get_service());
2773 Mlt::Tractor tractor(service);
2774 Mlt::Field *field = tractor.field();
2776 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2777 mlt_service serv = m_mltProducer->parent().get_service();
2779 mlt_service nextservice = mlt_service_get_producer(serv);
2780 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2781 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2782 QString resource = mlt_properties_get(properties, "mlt_service");
2784 while (mlt_type == "transition") {
2785 mlt_transition tr = (mlt_transition) nextservice;
2786 int currentTrack = mlt_transition_get_b_track(tr);
2787 int currentIn = (int) mlt_transition_get_in(tr);
2788 int currentOut = (int) mlt_transition_get_out(tr);
2789 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2790 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2792 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2793 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2794 mlt_field_disconnect_service(field->get_field(), nextservice);
2797 nextservice = mlt_service_producer(nextservice);
2798 if (nextservice == NULL) break;
2799 properties = MLT_SERVICE_PROPERTIES(nextservice);
2800 mlt_type = mlt_properties_get(properties, "mlt_type");
2801 resource = mlt_properties_get(properties, "mlt_service");
2803 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2806 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2808 Mlt::Service service(m_mltProducer->parent().get_service());
2809 Mlt::Tractor tractor(service);
2811 mlt_service_lock(service.get_service());
2812 m_mltConsumer->set("refresh", 0);
2815 mlt_service serv = m_mltProducer->parent().get_service();
2816 mlt_service nextservice = mlt_service_get_producer(serv);
2817 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2818 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2819 QString resource = mlt_properties_get(properties, "mlt_service");
2820 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2821 while (mlt_type == "transition") {
2822 mlt_transition tr = (mlt_transition) nextservice;
2823 int currentTrack = mlt_transition_get_b_track(tr);
2824 int currentIn = (int) mlt_transition_get_in(tr);
2825 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2826 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2827 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2828 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2829 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2830 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2833 nextservice = mlt_service_producer(nextservice);
2834 if (nextservice == NULL) break;
2835 properties = MLT_SERVICE_PROPERTIES(nextservice);
2836 mlt_type = mlt_properties_get(properties, "mlt_type");
2837 resource = mlt_properties_get(properties, "mlt_service");
2839 mlt_service_unlock(service.get_service());
2841 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2845 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2847 Mlt::Service service(m_mltProducer->parent().get_service());
2848 Mlt::Tractor tractor(service);
2850 mlt_service_lock(service.get_service());
2851 m_mltConsumer->set("refresh", 0);
2854 mlt_service serv = m_mltProducer->parent().get_service();
2855 mlt_service nextservice = mlt_service_get_producer(serv);
2856 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2857 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2858 QString resource = mlt_properties_get(properties, "mlt_service");
2860 while (mlt_type == "transition") {
2861 mlt_transition tr = (mlt_transition) nextservice;
2862 int currentTrack = mlt_transition_get_b_track(tr);
2863 int currentaTrack = mlt_transition_get_a_track(tr);
2864 int currentIn = (int) mlt_transition_get_in(tr);
2865 int currentOut = (int) mlt_transition_get_out(tr);
2866 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2867 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2868 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2869 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2870 kDebug() << "//////MOVING";
2871 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2872 if (endTrack != startTrack) {
2873 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2874 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2875 mlt_properties_set_int(properties, "b_track", endTrack);
2879 nextservice = mlt_service_producer(nextservice);
2880 if (nextservice == NULL) break;
2881 properties = MLT_SERVICE_PROPERTIES(nextservice);
2882 mlt_type = mlt_properties_get(properties, "mlt_type");
2883 resource = mlt_properties_get(properties, "mlt_service");
2886 mlt_service_unlock(service.get_service());
2887 m_mltConsumer->set("refresh", 1);
2891 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2893 if (in >= out) return false;
2894 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2895 Mlt::Service service(m_mltProducer->parent().get_service());
2897 Mlt::Tractor tractor(service);
2898 Mlt::Field *field = tractor.field();
2900 char *transId = decodedString(tag);
2901 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2902 if (out != GenTime())
2903 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2904 QMap<QString, QString>::Iterator it;
2906 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2907 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2908 if (xml.hasAttribute("id"))
2909 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
2911 for (it = args.begin(); it != args.end(); ++it) {
2913 char *name = decodedString(key);
2914 char *value = decodedString(it.value());
2915 if (it.value().isEmpty() == false) transition->set(name, value);
2916 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2920 // attach filter to the clip
2921 field->plant_transition(*transition, a_track, b_track);
2927 void Render::mltSavePlaylist()
2929 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2930 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2931 fileConsumer.set("resource", "/tmp/playlist.mlt");
2933 Mlt::Service service(m_mltProducer->get_service());
2935 fileConsumer.connect(service);
2936 fileConsumer.start();
2939 QList <Mlt::Producer *> Render::producersList()
2941 QList <Mlt::Producer *> prods;
2942 if (m_mltProducer == NULL) return prods;
2943 Mlt::Service service(m_mltProducer->parent().get_service());
2944 if (service.type() != tractor_type) return prods;
2945 Mlt::Tractor tractor(service);
2948 int trackNb = tractor.count();
2949 for (int t = 1; t < trackNb; t++) {
2950 Mlt::Producer *tt = tractor.track(t);
2951 Mlt::Producer trackProducer(tt);
2953 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2954 int clipNb = trackPlaylist.count();
2955 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2956 for (int i = 0; i < clipNb; i++) {
2957 Mlt::Producer *c = trackPlaylist.get_clip(i);
2958 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2960 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2961 ids.append(nprod->get("id"));
2962 prods.append(nprod);
2963 } else delete nprod;
2971 void Render::fillSlowMotionProducers()
2973 if (m_mltProducer == NULL) return;
2974 Mlt::Service service(m_mltProducer->parent().get_service());
2975 if (service.type() != tractor_type) return;
2977 Mlt::Tractor tractor(service);
2979 int trackNb = tractor.count();
2980 for (int t = 1; t < trackNb; t++) {
2981 Mlt::Producer *tt = tractor.track(t);
2982 Mlt::Producer trackProducer(tt);
2984 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2985 int clipNb = trackPlaylist.count();
2986 for (int i = 0; i < clipNb; i++) {
2987 Mlt::Producer *c = trackPlaylist.get_clip(i);
2988 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2990 QString id = nprod->get("id");
2991 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
2992 // this is a slowmotion producer, add it to the list
2993 QString url = QString::fromUtf8(nprod->get("resource"));
2994 if (!m_slowmotionProducers.contains(url)) {
2995 m_slowmotionProducers.insert(url, nprod);
2997 } else delete nprod;
3004 void Render::mltInsertTrack(int ix, bool videoTrack)
3009 Mlt::Service service(m_mltProducer->parent().get_service());
3010 mlt_service_lock(service.get_service());
3011 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
3013 Mlt::Tractor tractor(service);
3015 Mlt::Playlist playlist;
3016 int ct = tractor.count();
3018 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3024 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3025 tractor.set_track(playlist, pos);
3026 Mlt::Producer newProd(tractor.track(pos));
3027 if (!videoTrack) newProd.set("hide", 1);
3029 for (; pos <= ct; pos++) {
3030 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3031 tractor.set_track(*prodToMove, pos);
3032 prodToMove = prodToMove2;
3035 tractor.set_track(playlist, ix);
3036 Mlt::Producer newProd(tractor.track(ix));
3037 if (!videoTrack) newProd.set("hide", 1);
3041 mlt_service serv = m_mltProducer->parent().get_service();
3042 mlt_service nextservice = mlt_service_get_producer(serv);
3043 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3044 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3045 QString resource = mlt_properties_get(properties, "mlt_service");
3047 while (mlt_type == "transition") {
3048 if (resource != "mix") {
3049 mlt_transition tr = (mlt_transition) nextservice;
3050 int currentTrack = mlt_transition_get_b_track(tr);
3051 int currentaTrack = mlt_transition_get_a_track(tr);
3052 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3054 if (currentTrack >= ix) {
3055 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3056 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3059 nextservice = mlt_service_producer(nextservice);
3060 if (nextservice == NULL) break;
3061 properties = MLT_SERVICE_PROPERTIES(nextservice);
3062 mlt_type = mlt_properties_get(properties, "mlt_type");
3063 resource = mlt_properties_get(properties, "mlt_service");
3066 // Add audio mix transition to last track
3067 Mlt::Field *field = tractor.field();
3068 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3069 transition->set("a_track", 1);
3070 transition->set("b_track", ct);
3071 transition->set("always_active", 1);
3072 transition->set("internal_added", 237);
3073 transition->set("combine", 1);
3074 field->plant_transition(*transition, 1, ct);
3075 //mlt_service_unlock(m_mltConsumer->get_service());
3076 mlt_service_unlock(service.get_service());
3077 //tractor.multitrack()->refresh();
3078 //tractor.refresh();
3080 blockSignals(false);
3084 void Render::mltDeleteTrack(int ix)
3087 doc.setContent(sceneList(), false);
3088 int tracksCount = doc.elementsByTagName("track").count() - 1;
3089 QDomNode track = doc.elementsByTagName("track").at(ix);
3090 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3091 QDomNodeList transitions = doc.elementsByTagName("transition");
3092 for (int i = 0; i < transitions.count(); i++) {
3093 QDomElement e = transitions.at(i).toElement();
3094 QDomNodeList props = e.elementsByTagName("property");
3095 QMap <QString, QString> mappedProps;
3096 for (int j = 0; j < props.count(); j++) {
3097 QDomElement f = props.at(j).toElement();
3098 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3100 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3101 tractor.removeChild(transitions.at(i));
3103 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3104 // Transition needs to be moved
3105 int a_track = mappedProps.value("a_track").toInt();
3106 int b_track = mappedProps.value("b_track").toInt();
3107 if (a_track > 0 && a_track >= ix) a_track --;
3108 if (b_track > 0 && b_track >= ix) b_track --;
3109 for (int j = 0; j < props.count(); j++) {
3110 QDomElement f = props.at(j).toElement();
3111 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3112 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3117 tractor.removeChild(track);
3118 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3119 setSceneList(doc.toString(), m_framePosition);
3124 void Render::updatePreviewSettings()
3126 kDebug() << "////// RESTARTING CONSUMER";
3127 if (!m_mltConsumer || !m_mltProducer) return;
3128 if (m_mltProducer->get_playtime() == 0) return;
3129 Mlt::Service service(m_mltProducer->parent().get_service());
3130 if (service.type() != tractor_type) return;
3132 //m_mltConsumer->set("refresh", 0);
3133 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3134 m_mltConsumer->purge();
3135 QString scene = sceneList();
3137 if (m_mltProducer) {
3138 pos = m_mltProducer->position();
3139 delete m_mltProducer;
3141 m_mltProducer = NULL;
3142 setSceneList(scene, pos);
3145 #include "renderer.moc"