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>
34 #include <KStandardDirs>
35 #include <KMessageBox>
37 #include <KTemporaryFile>
41 #include <QApplication>
45 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
47 // detect if the producer has finished playing. Is there a better way to do it?
48 if (self->m_isBlocked) return;
49 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
50 self->emitConsumerStopped();
52 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
56 Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget *parent) :
69 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
70 m_refreshTimer = new QTimer(this);
71 connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
73 /*if (rendererName == "project") m_monitorId = 10000;
74 else m_monitorId = 10001;*/
75 m_osdTimer = new QTimer(this);
76 connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
80 m_mltProducer = m_blackClip->cut(0, 50);
81 m_mltConsumer->connect(*m_mltProducer);
82 m_mltProducer->set_speed(0.0);
92 void Render::closeMlt()
95 delete m_refreshTimer;
103 void Render::buildConsumer()
106 m_activeProfile = KdenliveSettings::current_profile();
107 tmp = decodedString(m_activeProfile);
108 setenv("MLT_PROFILE", tmp, 1);
112 m_mltProfile = new Mlt::Profile(tmp);
115 QString videoDriver = KdenliveSettings::videodrivername();
116 if (!videoDriver.isEmpty()) {
117 if (videoDriver == "x11_noaccel") {
118 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
121 unsetenv("SDL_VIDEO_YUV_HWACCEL");
124 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
126 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
127 m_mltConsumer->set("resize", 1);
128 m_mltConsumer->set("window_id", m_winid);
129 m_mltConsumer->set("terminate_on_pause", 1);
130 tmp = decodedString(KdenliveSettings::window_background().name());
131 m_mltConsumer->set("window_background", tmp);
134 // FIXME: the event object returned by the listen gets leaked...
135 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
136 m_mltConsumer->set("rescale", "nearest");
138 QString audioDevice = KdenliveSettings::audiodevicename();
139 if (!audioDevice.isEmpty()) {
140 tmp = decodedString(audioDevice);
141 m_mltConsumer->set("audio_device", tmp);
145 if (!videoDriver.isEmpty()) {
146 tmp = decodedString(videoDriver);
147 m_mltConsumer->set("video_driver", tmp);
151 QString audioDriver = KdenliveSettings::audiodrivername();
152 if (audioDriver.isEmpty())
153 audioDriver = KdenliveSettings::autoaudiodrivername();
154 if (!audioDriver.isEmpty()) {
155 tmp = decodedString(audioDriver);
156 m_mltConsumer->set("audio_driver", tmp);
161 m_mltConsumer->set("progressive", 1);
162 m_mltConsumer->set("audio_buffer", 1024);
163 m_mltConsumer->set("frequency", 48000);
165 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
166 m_blackClip->set("id", "black");
170 int Render::resetProfile()
172 if (!m_mltConsumer) return 0;
173 if (m_activeProfile == KdenliveSettings::current_profile()) {
174 kDebug() << "reset to same profile, nothing to do";
177 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
178 if (m_isSplitView) slotSplitView(false);
179 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
180 m_mltConsumer->purge();
181 delete m_mltConsumer;
182 m_mltConsumer = NULL;
183 QString scene = sceneList();
186 pos = m_mltProducer->position();
187 delete m_mltProducer;
189 m_mltProducer = NULL;
191 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
192 /*if (m_mltProfile) delete m_mltProfile;
193 m_mltProfile = NULL;*/
197 //kDebug() << "//RESET WITHSCENE: " << scene;
198 setSceneList(scene, pos);
200 /*char *tmp = decodedString(scene);
201 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
203 m_mltProducer = producer;
204 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
205 m_mltProducer->optimise();
206 m_mltProducer->set_speed(0);
209 //delete m_mltProfile;
210 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
211 //mlt_profile prof = m_mltProfile->get_profile();
212 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
213 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
214 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
215 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
217 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
222 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
223 void Render::seek(GenTime time)
228 m_mltProducer->seek((int)(time.frames(m_fps)));
233 char *Render::decodedString(QString str)
235 /*QCString fn = QFile::encodeName(str);
236 char *t = new char[fn.length() + 1];
237 strcpy(t, (const char *)fn);*/
239 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
243 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
244 QPixmap pix(width, height);
246 mlt_image_format format = mlt_image_rgb24a;
247 uint8_t *thumb = frame->get_image(format, width, height);
248 QImage image(thumb, width, height, QImage::Format_ARGB32);
250 if (!image.isNull()) {
251 pix = pix.fromImage(image);
253 QPainter painter(&pix);
254 painter.drawRect(0, 0, width - 1, height - 1);
256 } else pix.fill(Qt::black);
260 int Render::renderWidth() const
262 return (int)(m_mltProfile->height() * m_mltProfile->dar());
265 int Render::renderHeight() const
267 return m_mltProfile->height();
270 QPixmap Render::extractFrame(int frame_position, int width, int height)
273 width = renderWidth();
274 height = renderHeight();
275 } else if (width % 2 == 1) width++;
276 QPixmap pix(width, height);
277 if (!m_mltProducer) {
281 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
284 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
288 if (url.fileName().startsWith(".all.")) { // check for slideshow
289 QString fileType = url.fileName().right(3);
291 QStringList::Iterator it;
293 QDir dir(url.directory());
295 filter << "*." + fileType;
296 filter << "*." + fileType.toUpper();
297 more = dir.entryList(filter, QDir::Files);
298 im.load(url.directory() + '/' + more.at(0));
299 } else im.load(url.path());
300 //pixmap = im.scaled(width, height);
305 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
306 QPixmap pix(width, height);
307 char *tmp = decodedString(file);
308 Mlt::Profile *prof = new Mlt::Profile(profile);
309 Mlt::Producer m_producer(*prof, tmp);
311 if (m_producer.is_blank()) {
316 Mlt::Filter m_convert(*prof, "avcolour_space");
317 m_convert.set("forced", mlt_image_rgb24a);
318 m_producer.attach(m_convert);
319 m_producer.seek(frame_position);
320 Mlt::Frame * frame = m_producer.get_frame();
322 pix = frameThumbnail(frame, width, height, true);
325 if (prof) delete prof;
330 void Render::getImage(KUrl url, int frame_position, QPoint size)
332 char *tmp = decodedString(url.path());
333 Mlt::Producer m_producer(tmp);
335 if (m_producer.is_blank()) {
338 Mlt::Filter m_convert("avcolour_space");
339 m_convert.set("forced", mlt_image_rgb24a);
340 m_producer.attach(m_convert);
341 m_producer.seek(frame_position);
343 Mlt::Frame * frame = m_producer.get_frame();
346 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
348 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
352 /* Create thumbnail for color */
353 /*void Render::getImage(int id, QString color, QPoint size)
355 QPixmap pixmap(size.x() - 2, size.y() - 2);
356 color = color.replace(0, 2, "#");
357 color = color.left(7);
358 pixmap.fill(QColor(color));
359 QPixmap result(size.x(), size.y());
360 result.fill(Qt::black);
361 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
362 emit replyGetImage(id, result, size.x(), size.y());
366 /* Create thumbnail for image */
367 /*void Render::getImage(KUrl url, QPoint size)
371 if (url.fileName().startsWith(".all.")) { // check for slideshow
372 QString fileType = url.fileName().right(3);
374 QStringList::Iterator it;
376 QDir dir( url.directory() );
377 more = dir.entryList( QDir::Files );
378 for ( it = more.begin() ; it != more.end() ; ++it ) {
379 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
380 if (!im.load(url.directory() + '/' + *it))
381 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
386 else im.load(url.path());
388 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
389 QPixmap result(size.x(), size.y());
390 result.fill(Qt::black);
391 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
392 emit replyGetImage(url, 1, result, size.x(), size.y());
396 double Render::consumerRatio() const
398 if (!m_mltConsumer) return 1.0;
399 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
403 int Render::getLength()
407 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
408 return mlt_producer_get_playtime(m_mltProducer->get_producer());
413 bool Render::isValid(KUrl url)
415 char *tmp = decodedString(url.path());
416 Mlt::Producer producer(*m_mltProfile, tmp);
418 if (producer.is_blank())
424 double Render::dar() const
426 return m_mltProfile->dar();
429 void Render::slotSplitView(bool doit)
431 m_isSplitView = doit;
432 Mlt::Service service(m_mltProducer->parent().get_service());
433 Mlt::Tractor tractor(service);
434 if (service.type() != tractor_type || tractor.count() < 2) return;
435 Mlt::Field *field = tractor.field();
438 for (int i = 1; i < tractor.count() && screen < 4; i++) {
439 Mlt::Producer trackProducer(tractor.track(i));
440 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
441 if (QString(trackProducer.get("hide")).toInt() != 1) {
442 kDebug() << "// ADIDNG TRACK: " << i;
443 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
444 transition->set("mlt_service", "composite");
445 transition->set("a_track", 0);
446 transition->set("b_track", i);
447 transition->set("distort", 1);
448 transition->set("internal_added", "200");
455 tmp = "50%,0:50%x50%";
458 tmp = "0,50%:50%x50%";
462 tmp = "50%,50%:50%x50%";
465 transition->set("geometry", tmp);
466 transition->set("always_active", "1");
467 field->plant_transition(*transition, 0, i);
472 m_mltConsumer->set("refresh", 1);
474 mlt_service serv = m_mltProducer->parent().get_service();
475 mlt_service nextservice = mlt_service_get_producer(serv);
476 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
477 QString mlt_type = mlt_properties_get(properties, "mlt_type");
478 QString resource = mlt_properties_get(properties, "mlt_service");
480 while (mlt_type == "transition") {
481 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
482 if (added == "200") {
483 mlt_field_disconnect_service(field->get_field(), nextservice);
485 nextservice = mlt_service_producer(nextservice);
486 if (nextservice == NULL) break;
487 properties = MLT_SERVICE_PROPERTIES(nextservice);
488 mlt_type = mlt_properties_get(properties, "mlt_type");
489 resource = mlt_properties_get(properties, "mlt_service");
490 m_mltConsumer->set("refresh", 1);
495 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer)
497 KUrl url = KUrl(xml.attribute("resource", QString()));
498 Mlt::Producer *producer = NULL;
499 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
500 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
503 if (xml.attribute("type").toInt() == COLOR) {
504 char *tmp = decodedString("colour:" + xml.attribute("colour"));
505 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
507 } else if (url.isEmpty()) {
509 QDomElement mlt = doc.createElement("mlt");
510 QDomElement play = doc.createElement("playlist");
511 doc.appendChild(mlt);
512 mlt.appendChild(play);
513 play.appendChild(doc.importNode(xml, true));
514 char *tmp = decodedString(doc.toString());
515 producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
518 char *tmp = decodedString(url.path());
519 producer = new Mlt::Producer(*m_mltProfile, tmp);
523 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
524 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
525 emit removeInvalidClip(clipId, replaceProducer);
530 if (xml.hasAttribute("force_aspect_ratio")) {
531 double aspect = xml.attribute("force_aspect_ratio").toDouble();
532 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
534 if (xml.hasAttribute("threads")) {
535 int threads = xml.attribute("threads").toInt();
536 if (threads != 1) producer->set("threads", threads);
538 if (xml.hasAttribute("video_index")) {
539 int vindex = xml.attribute("video_index").toInt();
540 if (vindex != 0) producer->set("video_index", vindex);
542 if (xml.hasAttribute("audio_index")) {
543 int aindex = xml.attribute("audio_index").toInt();
544 if (aindex != 0) producer->set("audio_index", aindex);
547 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
549 char *tmp = decodedString(clipId);
550 producer->set("id", tmp);
554 int width = (int)(height * m_mltProfile->dar());
555 QMap < QString, QString > filePropertyMap;
556 QMap < QString, QString > metadataPropertyMap;
558 int frameNumber = xml.attribute("thumbnail", "0").toInt();
559 if (frameNumber != 0) producer->seek(frameNumber);
561 filePropertyMap["duration"] = QString::number(producer->get_playtime());
562 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
564 Mlt::Frame *frame = producer->get_frame();
566 if (xml.attribute("type").toInt() == SLIDESHOW) {
567 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
568 if (xml.attribute("fade") == "1") {
569 // user wants a fade effect to slideshow
570 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
571 if (filter && filter->is_valid()) {
572 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
573 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
574 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
575 char *tmp = decodedString(xml.attribute("luma_file"));
576 filter->set("luma.resource", tmp);
578 if (xml.hasAttribute("softness")) {
579 int soft = xml.attribute("softness").toInt();
580 filter->set("luma.softness", (double) soft / 100.0);
583 Mlt::Service clipService(producer->get_service());
584 clipService.attach(*filter);
590 filePropertyMap["fps"] = producer->get("source_fps");
592 if (frame && frame->is_valid()) {
593 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
594 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
595 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
596 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
598 if (frame->get_int("test_image") == 0) {
599 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
600 filePropertyMap["type"] = "playlist";
601 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
602 } else if (frame->get_int("test_audio") == 0)
603 filePropertyMap["type"] = "av";
605 filePropertyMap["type"] = "video";
607 mlt_image_format format = mlt_image_yuv422;
609 int frame_height = 0;
610 //frame->set("rescale.interp", "hyper");
611 frame->set("normalised_height", height);
612 frame->set("normalised_width", width);
613 QPixmap pix(width, height);
615 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
616 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
617 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
618 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
620 if (!image.isNull()) {
621 pix = QPixmap::fromImage(image.rgbSwapped());
625 mlt_pool_release(new_image);
626 emit replyGetImage(clipId, pix);
628 } else if (frame->get_int("test_audio") == 0) {
629 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
630 emit replyGetImage(clipId, pixmap);
631 filePropertyMap["type"] = "audio";
635 // Retrieve audio / video codec name
639 if (producer->get_int("video_index") > -1) {
640 /*if (context->duration == AV_NOPTS_VALUE) {
641 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
642 emit removeInvalidClip(clipId);
646 // Get the video_index
647 int default_video = producer->get_int("video_index");
649 int default_audio = producer->get_int("audio_index");
652 // Find maximum stream index values
653 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
654 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
655 QString type = producer->get(property);
658 else if (type == "audio")
661 filePropertyMap["default_video"] = QString::number(default_video);
662 filePropertyMap["video_max"] = QString::number(video_max);
663 filePropertyMap["default_audio"] = QString::number(default_audio);
664 filePropertyMap["audio_max"] = QString::number(audio_max);
666 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
667 if (producer->get(property)) {
668 filePropertyMap["videocodec"] = producer->get(property);
670 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
671 if (producer->get(property))
672 filePropertyMap["videocodec"] = producer->get(property);
675 if (KdenliveSettings::dropbframes()) {
676 kDebug() << "// LOOKING FOR H264 on: " << default_video;
677 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
678 kDebug() << "PROP: " << property << " = " << producer->get(property);
679 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
680 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
681 producer->set("skip_loop_filter", "all");
682 producer->set("skip_frame", "bidir");
686 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
687 if (producer->get_int("audio_index") > -1) {
688 // Get the audio_index
689 int index = producer->get_int("audio_index");
691 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
692 if (producer->get(property)) {
693 filePropertyMap["audiocodec"] = producer->get(property);
695 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
696 if (producer->get(property))
697 filePropertyMap["audiocodec"] = producer->get(property);
702 Mlt::Properties metadata;
703 metadata.pass_values(*producer, "meta.attr.");
704 int count = metadata.count();
705 for (int i = 0; i < count; i ++) {
706 QString name = metadata.get_name(i);
707 QString value = QString::fromUtf8(metadata.get(i));
708 if (name.endsWith("markup") && !value.isEmpty())
709 metadataPropertyMap[ name.section('.', 0, -2)] = value;
712 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
713 kDebug() << "REquested fuile info for: " << url.path();
715 // FIXME: should delete this to avoid a leak...
720 /** Create the producer from the MLT XML QDomDocument */
722 void Render::initSceneList()
724 kDebug() << "-------- INIT SCENE LIST ------_";
726 QDomElement mlt = doc.createElement("mlt");
727 doc.appendChild(mlt);
728 QDomElement prod = doc.createElement("producer");
729 prod.setAttribute("resource", "colour");
730 prod.setAttribute("colour", "red");
731 prod.setAttribute("id", "black");
732 prod.setAttribute("in", "0");
733 prod.setAttribute("out", "0");
735 QDomElement tractor = doc.createElement("tractor");
736 QDomElement multitrack = doc.createElement("multitrack");
738 QDomElement playlist1 = doc.createElement("playlist");
739 playlist1.appendChild(prod);
740 multitrack.appendChild(playlist1);
741 QDomElement playlist2 = doc.createElement("playlist");
742 multitrack.appendChild(playlist2);
743 QDomElement playlist3 = doc.createElement("playlist");
744 multitrack.appendChild(playlist3);
745 QDomElement playlist4 = doc.createElement("playlist");
746 multitrack.appendChild(playlist4);
747 QDomElement playlist5 = doc.createElement("playlist");
748 multitrack.appendChild(playlist5);
749 tractor.appendChild(multitrack);
750 mlt.appendChild(tractor);
751 // kDebug()<<doc.toString();
753 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
754 setSceneList(doc, 0);
760 /** Create the producer from the MLT XML QDomDocument */
761 void Render::setProducer(Mlt::Producer *producer, int position)
763 if (m_winid == -1) return;
766 m_mltConsumer->stop();
769 m_mltConsumer->purge();
773 m_mltProducer->set_speed(0);
774 delete m_mltProducer;
775 m_mltProducer = NULL;
779 m_mltProducer = new Mlt::Producer(producer->get_producer());
780 } else m_mltProducer = m_blackClip->cut(0, 50);
781 /*if (KdenliveSettings::dropbframes()) {
782 m_mltProducer->set("skip_loop_filter", "all");
783 m_mltProducer->set("skip_frame", "bidir");
785 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
787 m_fps = m_mltProducer->get_fps();
789 if (position != -1) {
790 m_mltProducer->seek(position);
791 emit rendererPosition(position);
798 /** Create the producer from the MLT XML QDomDocument */
799 void Render::setSceneList(QDomDocument list, int position)
801 setSceneList(list.toString(), position);
804 /** Create the producer from the MLT XML QDomDocument */
805 void Render::setSceneList(QString playlist, int position)
807 if (m_winid == -1) return;
809 qDeleteAll(m_slowmotionProducers.values());
810 m_slowmotionProducers.clear();
812 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
814 if (m_mltConsumer == NULL) {
815 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
820 if (!m_mltConsumer->is_stopped()) {
821 m_mltConsumer->stop();
822 //m_mltConsumer->set("refresh", 0);
826 m_mltProducer->set_speed(0);
827 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
829 delete m_mltProducer;
830 m_mltProducer = NULL;
835 char *tmp = decodedString(playlist);
836 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
838 if (!m_mltProducer || !m_mltProducer->is_valid()) {
839 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
840 m_mltProducer = m_blackClip->cut(0, 50);
844 m_mltProducer->optimise();
846 /*if (KdenliveSettings::osdtimecode()) {
847 // Attach filter for on screen display of timecode
849 QString attr = "attr_check";
850 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
851 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
852 mlt_producer_attach( m_mltProducer->get_producer(), filter );
853 mlt_filter_close( filter );
855 m_osdInfo = new Mlt::Filter("data_show");
856 tmp = decodedString(m_osdProfile);
857 m_osdInfo->set("resource", tmp);
859 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
860 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
861 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
862 m_osdInfo->set("dynamic", "1");
864 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
866 m_osdInfo->set("dynamic", "0");
869 m_fps = m_mltProducer->get_fps();
871 // Seek to correct place after opening project.
872 m_mltProducer->seek(position);
875 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
877 fillSlowMotionProducers();
881 emit refreshDocumentProducers();
882 //kDebug()<<"// SETSCN LST, POS: "<<position;
883 //if (position != 0) emit rendererPosition(position);
886 /** Create the producer from the MLT XML QDomDocument */
887 const QString Render::sceneList()
890 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
891 m_mltProducer->optimise();
892 xmlConsumer.set("terminate_on_pause", 1);
893 Mlt::Producer prod(m_mltProducer->get_producer());
894 bool split = m_isSplitView;
895 if (split) slotSplitView(false);
896 xmlConsumer.connect(prod);
898 while (!xmlConsumer.is_stopped()) {}
899 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
900 if (split) slotSplitView(true);
904 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
908 doc.setContent(sceneList(), false);
909 if (!kdenliveData.isNull()) {
910 // add Kdenlive specific tags
911 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
912 mlt.appendChild(doc.importNode(kdenliveData, true));
914 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
915 kWarning() << "////// ERROR writing to file: " << path;
918 file.write(doc.toString().toUtf8());
919 if (file.error() != QFile::NoError) {
928 void Render::saveZone(KUrl url, QString desc, QPoint zone)
930 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
931 char *tmppath = decodedString("xml:" + url.path());
932 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
933 m_mltProducer->optimise();
935 xmlConsumer.set("terminate_on_pause", 1);
936 if (m_name == "clip") {
937 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
938 tmppath = decodedString(desc);
940 list.insert_at(0, prod, 0);
941 list.set("title", tmppath);
943 xmlConsumer.connect(list);
946 //TODO: not working yet, save zone from timeline
947 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
948 /* Mlt::Service service(p1->parent().get_service());
949 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
951 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
952 tmppath = decodedString(desc);
953 //prod->set("title", tmppath);
955 xmlConsumer.connect(*p1); //list);
961 double Render::fps() const
966 void Render::connectPlaylist()
968 if (!m_mltConsumer) return;
969 //m_mltConsumer->set("refresh", "0");
970 m_mltConsumer->connect(*m_mltProducer);
971 m_mltProducer->set_speed(0);
972 m_mltConsumer->start();
973 emit durationChanged(m_mltProducer->get_playtime());
976 if (m_mltConsumer->start() == -1) {
977 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."));
978 delete m_mltConsumer;
979 m_mltConsumer = NULL;
986 void Render::refreshDisplay()
989 if (!m_mltProducer) return;
990 //m_mltConsumer->set("refresh", 0);
992 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
993 /*if (KdenliveSettings::osdtimecode()) {
994 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
995 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
996 m_osdInfo->set("dynamic", "1");
997 m_mltProducer->attach(*m_osdInfo);
1000 m_mltProducer->detach(*m_osdInfo);
1001 m_osdInfo->set("dynamic", "0");
1006 void Render::setVolume(double /*volume*/)
1008 if (!m_mltConsumer || !m_mltProducer) return;
1010 m_mltConsumer->set("refresh", 0);
1011 // Attach filter for on screen display of timecode
1012 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1013 mlt_properties_set_double( properties, "meta.volume", volume );
1014 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1015 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1017 if (!KdenliveSettings::osdtimecode()) {
1018 m_mltProducer->detach(*m_osdInfo);
1019 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1020 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1023 m_osdTimer->setSingleShot(2500);
1026 void Render::slotOsdTimeout()
1028 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1029 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1030 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1031 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1035 void Render::start()
1037 kDebug() << "----- STARTING MONITOR: " << m_name;
1038 if (m_winid == -1) {
1039 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1043 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1044 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1045 if (m_mltConsumer->start() == -1) {
1046 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."));
1047 delete m_mltConsumer;
1048 m_mltConsumer = NULL;
1051 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1052 m_isBlocked = false;
1056 m_isBlocked = false;
1059 void Render::clear()
1061 kDebug() << " ********* RENDER CLEAR";
1062 if (m_mltConsumer) {
1063 //m_mltConsumer->set("refresh", 0);
1064 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1067 if (m_mltProducer) {
1068 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1069 m_mltProducer->set_speed(0.0);
1070 delete m_mltProducer;
1071 m_mltProducer = NULL;
1078 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1079 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1081 //m_mltConsumer->set("refresh", 0);
1082 m_mltConsumer->stop();
1083 // delete m_mltConsumer;
1084 // m_mltConsumer = NULL;
1086 kDebug() << "///////////// RENDER STOP2-------";
1089 if (m_mltProducer) {
1090 if (m_isZoneMode) resetZoneMode();
1091 m_mltProducer->set_speed(0.0);
1092 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1093 //kDebug() << m_mltProducer->get_length();
1095 kDebug() << "///////////// RENDER STOP3-------";
1098 void Render::stop(const GenTime & startTime)
1101 kDebug() << "///////////// RENDER STOP-------2";
1102 if (m_mltProducer) {
1103 if (m_isZoneMode) resetZoneMode();
1104 m_mltProducer->set_speed(0.0);
1105 m_mltProducer->seek((int) startTime.frames(m_fps));
1107 m_mltConsumer->purge();
1110 void Render::pause()
1112 if (!m_mltProducer || !m_mltConsumer)
1114 if (m_mltProducer->get_speed() == 0.0) return;
1115 if (m_isZoneMode) resetZoneMode();
1117 m_mltConsumer->set("refresh", 0);
1118 m_mltProducer->set_speed(0.0);
1119 emit rendererPosition(m_framePosition);
1120 m_mltProducer->seek(m_framePosition);
1121 m_mltConsumer->purge();
1124 void Render::switchPlay()
1126 if (!m_mltProducer || !m_mltConsumer)
1128 if (m_isZoneMode) resetZoneMode();
1129 if (m_mltProducer->get_speed() == 0.0) {
1130 m_isBlocked = false;
1131 m_mltProducer->set_speed(1.0);
1132 m_mltConsumer->set("refresh", 1);
1135 m_mltConsumer->set("refresh", 0);
1136 m_mltProducer->set_speed(0.0);
1137 emit rendererPosition(m_framePosition);
1138 m_mltProducer->seek(m_framePosition);
1139 m_mltConsumer->purge();
1140 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1141 //m_mltConsumer->set("refresh", 0);
1142 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1143 m_mltProducer->set_speed(0);
1144 m_mltProducer->seek( position );
1145 //m_mltProducer->seek((int) m_framePosition);
1146 m_isBlocked = false;*/
1148 /*if (speed == 0.0) {
1149 m_mltProducer->seek((int) m_framePosition + 1);
1150 m_mltConsumer->purge();
1155 void Render::play(double speed)
1159 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1160 m_isBlocked = false;
1161 m_mltProducer->set_speed(speed);
1162 /*if (speed == 0.0) {
1163 m_mltProducer->seek((int) m_framePosition + 1);
1164 m_mltConsumer->purge();
1169 void Render::play(const GenTime & startTime)
1171 if (!m_mltProducer || !m_mltConsumer)
1173 m_isBlocked = false;
1174 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1175 m_mltProducer->set_speed(1.0);
1176 m_mltConsumer->set("refresh", 1);
1179 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1181 if (!m_mltProducer || !m_mltConsumer)
1183 //m_mltProducer->set("eof", "loop");
1184 m_isLoopMode = true;
1185 m_loopStart = startTime;
1186 playZone(startTime, stopTime);
1189 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1191 if (!m_mltProducer || !m_mltConsumer)
1193 m_isBlocked = false;
1194 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1195 m_mltProducer->set("out", stopTime.frames(m_fps));
1196 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1197 m_mltProducer->set_speed(1.0);
1198 m_mltConsumer->set("refresh", 1);
1199 m_isZoneMode = true;
1202 void Render::resetZoneMode()
1204 if (!m_isZoneMode && !m_isLoopMode) return;
1205 m_mltProducer->set("out", m_originalOut);
1206 //m_mltProducer->set("eof", "pause");
1207 m_isZoneMode = false;
1208 m_isLoopMode = false;
1211 void Render::seekToFrame(int pos)
1213 //kDebug()<<" ********* RENDER SEEK TO POS";
1216 m_isBlocked = false;
1218 m_mltProducer->seek(pos);
1222 void Render::askForRefresh()
1224 // Use a Timer so that we don't refresh too much
1225 m_refreshTimer->start(500);
1228 void Render::doRefresh()
1230 // Use a Timer so that we don't refresh too much
1231 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1234 void Render::refresh()
1236 if (!m_mltProducer || m_isBlocked)
1238 m_refreshTimer->stop();
1239 if (m_mltConsumer) {
1240 m_mltConsumer->set("refresh", 1);
1244 double Render::playSpeed()
1246 if (m_mltProducer) return m_mltProducer->get_speed();
1250 GenTime Render::seekPosition() const
1252 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1253 else return GenTime();
1257 const QString & Render::rendererName() const
1263 void Render::emitFrameNumber(double position)
1265 m_framePosition = position;
1266 emit rendererPosition((int) position);
1267 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1270 void Render::emitConsumerStopped()
1272 // This is used to know when the playing stopped
1273 if (m_mltProducer) {
1274 double pos = m_mltProducer->position();
1275 if (m_isLoopMode) play(m_loopStart);
1276 else if (m_isZoneMode) resetZoneMode();
1277 emit rendererStopped((int) pos);
1278 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1279 //new QCustomEvent(10002));
1285 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1287 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1291 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1293 if (!m_mltProducer) {
1294 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1298 //int height = 1080;//KdenliveSettings::defaultheight();
1299 //int width = 1940; //KdenliveSettings::displaywidth();
1301 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1303 QPixmap pix(width, height);
1304 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1305 m_convert.set("forced", mlt_image_rgb24a);
1306 m_mltProducer->attach(m_convert);
1307 Mlt::Frame * frame = m_mltProducer->get_frame();
1308 m_mltProducer->detach(m_convert);
1310 pix = frameThumbnail(frame, width, height);
1313 pix.save(url.path(), "PNG");
1314 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1317 /** MLT PLAYLIST DIRECT MANIPULATON **/
1320 void Render::mltCheckLength()
1322 //kDebug()<<"checking track length: "<<track<<"..........";
1324 Mlt::Service service(m_mltProducer->get_service());
1325 Mlt::Tractor tractor(service);
1327 int trackNb = tractor.count();
1331 Mlt::Producer trackProducer(tractor.track(0));
1332 duration = trackProducer.get_playtime() - 1;
1333 m_mltProducer->set("out", duration);
1334 emit durationChanged(duration);
1337 while (trackNb > 1) {
1338 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1339 trackDuration = trackProducer.get_playtime() - 1;
1341 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1342 if (trackDuration > duration) duration = trackDuration;
1346 Mlt::Producer blackTrackProducer(tractor.track(0));
1348 if (blackTrackProducer.get_playtime() - 1 != duration) {
1349 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1350 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1351 if (duration > m_blackClip->get_length()) {
1352 m_blackClip->set("length", duration);
1353 if (blackclip) blackclip->set("length", duration);
1355 if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
1356 blackTrackPlaylist.clear();
1357 blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
1358 } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1360 m_mltProducer->set("out", duration);
1361 emit durationChanged(duration);
1365 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1367 if (m_mltProducer == NULL) {
1368 kDebug() << "PLAYLIST NOT INITIALISED //////";
1371 Mlt::Producer parentProd(m_mltProducer->parent());
1372 if (parentProd.get_producer() == NULL) {
1373 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1377 Mlt::Service service(parentProd.get_service());
1378 Mlt::Tractor tractor(service);
1379 if (info.track > tractor.count() - 1) {
1380 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1383 mlt_service_lock(service.get_service());
1384 Mlt::Producer trackProducer(tractor.track(info.track));
1385 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1386 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1388 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1389 // We want a slowmotion producer
1390 double speed = element.attribute("speed", "1.0").toDouble();
1391 QString url = QString::fromUtf8(prod->get("resource"));
1392 url.append('?' + QString::number(speed));
1393 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1394 if (!slowprod || slowprod->get_producer() == NULL) {
1395 char *tmp = decodedString(url);
1396 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1398 QString id = prod->get("id");
1399 if (id.contains('_')) id = id.section('_', 0, 0);
1400 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1401 tmp = decodedString(producerid);
1402 slowprod->set("id", tmp);
1404 m_slowmotionProducers.insert(url, slowprod);
1409 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1410 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1412 /*if (QString(prod->get("transparency")).toInt() == 1)
1413 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1415 mlt_service_unlock(service.get_service());
1417 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1418 //tractor.multitrack()->refresh();
1419 //tractor.refresh();
1423 void Render::mltCutClip(int track, GenTime position)
1428 Mlt::Service service(m_mltProducer->parent().get_service());
1429 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1431 Mlt::Tractor tractor(service);
1432 Mlt::Producer trackProducer(tractor.track(track));
1433 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1436 /* // Display playlist info
1437 kDebug()<<"//////////// BEFORE";
1438 for (int i = 0; i < trackPlaylist.count(); i++) {
1439 int blankStart = trackPlaylist.clip_start(i);
1440 int blankDuration = trackPlaylist.clip_length(i) - 1;
1442 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1443 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1446 int cutPos = (int) position.frames(m_fps);
1448 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1449 if (trackPlaylist.is_blank(clipIndex)) {
1450 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1451 m_isBlocked = false;
1454 mlt_service_lock(service.get_service());
1455 int clipStart = trackPlaylist.clip_start(clipIndex);
1456 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1457 mlt_service_unlock(service.get_service());
1459 // duplicate effects
1460 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1461 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1463 if (original == NULL || clip == NULL) {
1464 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1466 Mlt::Service clipService(original->get_service());
1467 Mlt::Service dupService(clip->get_service());
1469 Mlt::Filter *filter = clipService.filter(ct);
1471 // Only duplicate Kdenlive filters, and skip the fade in effects
1472 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1473 // looks like there is no easy way to duplicate a filter,
1474 // so we will create a new one and duplicate its properties
1475 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1476 if (dup && dup->is_valid()) {
1477 Mlt::Properties entries(filter->get_properties());
1478 for (int i = 0;i < entries.count();i++) {
1479 dup->set(entries.get_name(i), entries.get(i));
1481 dupService.attach(*dup);
1485 filter = clipService.filter(ct);
1488 /* // Display playlist info
1489 kDebug()<<"//////////// AFTER";
1490 for (int i = 0; i < trackPlaylist.count(); i++) {
1491 int blankStart = trackPlaylist.clip_start(i);
1492 int blankDuration = trackPlaylist.clip_length(i) - 1;
1494 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1495 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1498 m_isBlocked = false;
1501 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1504 mltRemoveClip(info.track, info.startPos);
1505 mltInsertClip(info, element, prod);
1509 bool Render::mltRemoveClip(int track, GenTime position)
1511 Mlt::Service service(m_mltProducer->parent().get_service());
1512 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1514 Mlt::Tractor tractor(service);
1515 mlt_service_lock(service.get_service());
1516 Mlt::Producer trackProducer(tractor.track(track));
1517 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1518 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1520 /* // Display playlist info
1521 kDebug()<<"//// BEFORE";
1522 for (int i = 0; i < trackPlaylist.count(); i++) {
1523 int blankStart = trackPlaylist.clip_start(i);
1524 int blankDuration = trackPlaylist.clip_length(i) - 1;
1526 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1527 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1529 if (trackPlaylist.is_blank(clipIndex)) {
1530 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1534 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1535 trackPlaylist.replace_with_blank(clipIndex);
1536 trackPlaylist.consolidate_blanks(0);
1537 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1538 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1540 /* // Display playlist info
1541 kDebug()<<"//// AFTER";
1542 for (int i = 0; i < trackPlaylist.count(); i++) {
1543 int blankStart = trackPlaylist.clip_start(i);
1544 int blankDuration = trackPlaylist.clip_length(i) - 1;
1546 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1547 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1549 mlt_service_unlock(service.get_service());
1550 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1551 m_isBlocked = false;
1555 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1557 if (!m_mltProducer) {
1558 kDebug() << "PLAYLIST NOT INITIALISED //////";
1561 Mlt::Producer parentProd(m_mltProducer->parent());
1562 if (parentProd.get_producer() == NULL) {
1563 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1567 Mlt::Service service(parentProd.get_service());
1568 Mlt::Tractor tractor(service);
1569 int insertPos = pos.frames(m_fps);
1571 Mlt::Producer trackProducer(tractor.track(track));
1572 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1573 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1574 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1575 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1576 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1579 int Render::mltTrackDuration(int track)
1581 if (!m_mltProducer) {
1582 kDebug() << "PLAYLIST NOT INITIALISED //////";
1585 Mlt::Producer parentProd(m_mltProducer->parent());
1586 if (parentProd.get_producer() == NULL) {
1587 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1591 Mlt::Service service(parentProd.get_service());
1592 Mlt::Tractor tractor(service);
1594 Mlt::Producer trackProducer(tractor.track(track));
1595 return trackProducer.get_playtime() - 1;
1598 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1600 if (!m_mltProducer) {
1601 kDebug() << "PLAYLIST NOT INITIALISED //////";
1604 Mlt::Producer parentProd(m_mltProducer->parent());
1605 if (parentProd.get_producer() == NULL) {
1606 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1609 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1610 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1612 Mlt::Service service(parentProd.get_service());
1613 Mlt::Tractor tractor(service);
1614 mlt_service_lock(service.get_service());
1615 int diff = duration.frames(m_fps);
1616 int offset = timeOffset.frames(m_fps);
1620 // insert space in one track only
1621 Mlt::Producer trackProducer(tractor.track(track));
1622 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1623 insertPos = trackClipStartList.value(track);
1624 if (insertPos != -1) {
1625 insertPos += offset;
1626 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1627 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1629 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1630 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1631 int position = trackPlaylist.clip_start(clipIndex);
1632 trackPlaylist.remove_region(position, - diff - 1);
1634 trackPlaylist.consolidate_blanks(0);
1636 // now move transitions
1637 mlt_service serv = m_mltProducer->parent().get_service();
1638 mlt_service nextservice = mlt_service_get_producer(serv);
1639 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1640 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1641 QString resource = mlt_properties_get(properties, "mlt_service");
1643 while (mlt_type == "transition") {
1644 mlt_transition tr = (mlt_transition) nextservice;
1645 int currentTrack = mlt_transition_get_b_track(tr);
1646 int currentIn = (int) mlt_transition_get_in(tr);
1647 int currentOut = (int) mlt_transition_get_out(tr);
1648 insertPos = trackTransitionStartList.value(track);
1649 if (insertPos != -1) {
1650 insertPos += offset;
1651 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1652 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1655 nextservice = mlt_service_producer(nextservice);
1656 if (nextservice == NULL) break;
1657 properties = MLT_SERVICE_PROPERTIES(nextservice);
1658 mlt_type = mlt_properties_get(properties, "mlt_type");
1659 resource = mlt_properties_get(properties, "mlt_service");
1662 int trackNb = tractor.count();
1663 while (trackNb > 1) {
1664 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1665 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1668 //int clipNb = trackPlaylist.count();
1669 insertPos = trackClipStartList.value(trackNb - 1);
1670 if (insertPos != -1) {
1671 insertPos += offset;
1673 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1674 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1675 for (int i = 0; i < clipNb; i++) {
1676 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1677 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1678 kDebug()<<"-------------";
1680 kDebug()<<"END-------------";*/
1683 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1684 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1686 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1687 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1688 int position = trackPlaylist.clip_start(clipIndex);
1689 trackPlaylist.remove_region(position, - diff - 1);
1691 trackPlaylist.consolidate_blanks(0);
1695 // now move transitions
1696 mlt_service serv = m_mltProducer->parent().get_service();
1697 mlt_service nextservice = mlt_service_get_producer(serv);
1698 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1699 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1700 QString resource = mlt_properties_get(properties, "mlt_service");
1702 while (mlt_type == "transition") {
1703 mlt_transition tr = (mlt_transition) nextservice;
1704 int currentIn = (int) mlt_transition_get_in(tr);
1705 int currentOut = (int) mlt_transition_get_out(tr);
1706 int currentTrack = mlt_transition_get_b_track(tr);
1707 insertPos = trackTransitionStartList.value(currentTrack);
1708 if (insertPos != -1) {
1709 insertPos += offset;
1710 if (currentOut > insertPos && resource != "mix") {
1711 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1714 nextservice = mlt_service_producer(nextservice);
1715 if (nextservice == NULL) break;
1716 properties = MLT_SERVICE_PROPERTIES(nextservice);
1717 mlt_type = mlt_properties_get(properties, "mlt_type");
1718 resource = mlt_properties_get(properties, "mlt_service");
1721 mlt_service_unlock(service.get_service());
1723 m_mltConsumer->set("refresh", 1);
1726 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1730 Mlt::Service service(m_mltProducer->parent().get_service());
1731 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1732 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1733 Mlt::Tractor tractor(service);
1734 Mlt::Producer trackProducer(tractor.track(info.track));
1735 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1736 int startPos = info.startPos.frames(m_fps);
1737 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1738 int clipLength = trackPlaylist.clip_length(clipIndex);
1740 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1741 if (!clip.is_valid() || clip.is_blank()) {
1745 Mlt::Producer clipparent = clip.parent();
1746 if (!clipparent.is_valid() || clipparent.is_blank()) {
1750 QString serv = clipparent.get("mlt_service");
1751 QString id = clipparent.get("id");
1752 //kDebug() << "CLIP SERVICE: " << serv;
1753 if (serv == "avformat" && speed != 1.0) {
1754 mlt_service_lock(service.get_service());
1755 QString url = QString::fromUtf8(clipparent.get("resource"));
1756 url.append('?' + QString::number(speed));
1757 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1758 if (!slowprod || slowprod->get_producer() == NULL) {
1759 char *tmp = decodedString(url);
1760 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1762 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1763 tmp = decodedString(producerid);
1764 slowprod->set("id", tmp);
1766 m_slowmotionProducers.insert(url, slowprod);
1768 trackPlaylist.replace_with_blank(clipIndex);
1769 trackPlaylist.consolidate_blanks(0);
1770 // Check that the blank space is long enough for our new duration
1771 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1772 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1774 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1775 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1776 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1777 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1778 trackPlaylist.insert_at(startPos, *cut, 1);
1779 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1780 newLength = trackPlaylist.clip_length(clipIndex);
1781 mlt_service_unlock(service.get_service());
1782 } else if (speed == 1.0) {
1783 mlt_service_lock(service.get_service());
1785 trackPlaylist.replace_with_blank(clipIndex);
1786 trackPlaylist.consolidate_blanks(0);
1788 // Check that the blank space is long enough for our new duration
1789 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1790 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1793 GenTime oldDuration = GenTime(clipLength, m_fps);
1794 GenTime newDuration = oldDuration * oldspeed;
1795 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1796 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1797 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1798 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1799 trackPlaylist.insert_at(startPos, *cut, 1);
1800 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1801 newLength = trackPlaylist.clip_length(clipIndex);
1802 mlt_service_unlock(service.get_service());
1804 } else if (serv == "framebuffer") {
1805 mlt_service_lock(service.get_service());
1806 QString url = QString::fromUtf8(clipparent.get("resource"));
1807 url = url.section('?', 0, 0);
1808 url.append('?' + QString::number(speed));
1809 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1810 if (!slowprod || slowprod->get_producer() == NULL) {
1811 char *tmp = decodedString(url);
1812 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1814 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1815 tmp = decodedString(producerid);
1816 slowprod->set("id", tmp);
1818 m_slowmotionProducers.insert(url, slowprod);
1820 trackPlaylist.replace_with_blank(clipIndex);
1821 trackPlaylist.consolidate_blanks(0);
1823 GenTime oldDuration = GenTime(clipLength, m_fps);
1824 GenTime newDuration = oldDuration * oldspeed / speed;
1826 // Check that the blank space is long enough for our new duration
1827 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1828 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1831 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1832 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1833 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1834 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1836 trackPlaylist.insert_at(startPos, *cut, 1);
1837 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1838 newLength = trackPlaylist.clip_length(clipIndex);
1840 mlt_service_unlock(service.get_service());
1842 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1843 m_isBlocked = false;
1847 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1849 kDebug() << "// TRYing to remove effect at: " << index;
1850 Mlt::Service service(m_mltProducer->parent().get_service());
1851 bool success = false;
1852 Mlt::Tractor tractor(service);
1853 Mlt::Producer trackProducer(tractor.track(track));
1854 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1855 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1856 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1858 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1861 Mlt::Service clipService(clip->get_service());
1862 // if (tag.startsWith("ladspa")) tag = "ladspa";
1865 Mlt::Filter *filter = clipService.filter(ct);
1867 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1868 if (clipService.detach(*filter) == 0) success = true;
1869 kDebug() << " / / / DLEETED EFFECT: " << ct;
1870 } else if (updateIndex) {
1871 // Adjust the other effects index
1872 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1875 filter = clipService.filter(ct);
1877 m_isBlocked = false;
1878 if (doRefresh) refresh();
1883 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1886 Mlt::Service service(m_mltProducer->parent().get_service());
1888 Mlt::Tractor tractor(service);
1889 Mlt::Producer trackProducer(tractor.track(track));
1890 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1892 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1896 Mlt::Service clipService(clip->get_service());
1899 // temporarily remove all effects after insert point
1900 QList <Mlt::Filter *> filtersList;
1901 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1903 Mlt::Filter *filter = clipService.filter(ct);
1905 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1906 filtersList.append(filter);
1907 clipService.detach(*filter);
1909 filter = clipService.filter(ct);
1913 QString tag = params.paramValue("tag");
1914 kDebug() << " / / INSERTING EFFECT: " << tag;
1915 if (tag.startsWith("ladspa")) tag = "ladspa";
1916 char *filterTag = decodedString(tag);
1917 char *filterId = decodedString(params.paramValue("id"));
1918 QHash<QString, QString>::Iterator it;
1919 QString kfr = params.paramValue("keyframes");
1921 if (!kfr.isEmpty()) {
1922 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1923 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1924 char *starttag = decodedString(params.paramValue("starttag", "start"));
1925 char *endtag = decodedString(params.paramValue("endtag", "end"));
1926 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1927 int duration = clip->get_playtime();
1928 //double max = params.paramValue("max").toDouble();
1929 double min = params.paramValue("min").toDouble();
1930 double factor = params.paramValue("factor", "1").toDouble();
1931 params.removeParam("starttag");
1932 params.removeParam("endtag");
1933 params.removeParam("keyframes");
1934 params.removeParam("min");
1935 params.removeParam("max");
1936 params.removeParam("factor");
1938 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1939 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1940 if (filter && filter->is_valid()) {
1941 filter->set("kdenlive_id", filterId);
1942 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1943 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1944 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1945 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1946 if (x2 == -1) x2 = duration;
1948 for (int j = 0; j < params.count(); j++) {
1949 char *name = decodedString(params.at(j).name());
1950 char *value = decodedString(params.at(j).value());
1951 filter->set(name, value);
1956 filter->set("in", x1);
1957 filter->set("out", x2);
1958 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1959 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1960 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1961 clipService.attach(*filter);
1968 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1969 if (filter && filter->is_valid())
1970 filter->set("kdenlive_id", filterId);
1972 kDebug() << "filter is NULL";
1973 m_isBlocked = false;
1977 params.removeParam("kdenlive_id");
1979 for (int j = 0; j < params.count(); j++) {
1980 char *name = decodedString(params.at(j).name());
1981 char *value = decodedString(params.at(j).value());
1982 filter->set(name, value);
1988 QString effectArgs = params.paramValue("id").section('_', 1);
1990 params.removeParam("id");
1991 params.removeParam("kdenlive_ix");
1992 params.removeParam("tag");
1993 params.removeParam("disabled");
1995 for (int j = 0; j < params.count(); j++) {
1996 effectArgs.append(' ' + params.at(j).value());
1998 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1999 char *value = decodedString(effectArgs.simplified());
2000 filter->set("effect", value);
2005 // attach filter to the clip
2006 clipService.attach(*filter);
2011 // re-add following filters
2012 for (int i = 0; i < filtersList.count(); i++) {
2013 clipService.attach(*(filtersList.at(i)));
2016 m_isBlocked = false;
2017 if (doRefresh) refresh();
2021 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2023 QString index = params.paramValue("kdenlive_ix");
2024 QString tag = params.paramValue("tag");
2026 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2027 // This is a keyframe effect, to edit it, we remove it and re-add it.
2028 mltRemoveEffect(track, position, index, true);
2029 bool success = mltAddEffect(track, position, params);
2034 Mlt::Service service(m_mltProducer->parent().get_service());
2036 Mlt::Tractor tractor(service);
2037 Mlt::Producer trackProducer(tractor.track(track));
2038 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2039 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2040 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2042 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2045 Mlt::Service clipService(clip->get_service());
2048 Mlt::Filter *filter = clipService.filter(ct);
2050 if (filter->get("kdenlive_ix") == index) {
2054 filter = clipService.filter(ct);
2058 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2059 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2061 filter = clipService.filter(ct);
2062 QList <Mlt::Filter *> filtersList;
2064 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2065 filtersList.append(filter);
2066 clipService.detach(*filter);
2068 filter = clipService.filter(ct);
2070 bool success = mltAddEffect(track, position, params);
2072 for (int i = 0; i < filtersList.count(); i++) {
2073 clipService.attach(*(filtersList.at(i)));
2076 m_isBlocked = false;
2080 for (int j = 0; j < params.count(); j++) {
2081 char *name = decodedString(params.at(j).name());
2082 char *value = decodedString(params.at(j).value());
2083 filter->set(name, value);
2088 m_isBlocked = false;
2093 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2096 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2097 Mlt::Service service(m_mltProducer->parent().get_service());
2099 Mlt::Tractor tractor(service);
2100 Mlt::Producer trackProducer(tractor.track(track));
2101 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2102 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2103 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2105 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2108 Mlt::Service clipService(clip->get_service());
2111 QList <Mlt::Filter *> filtersList;
2112 Mlt::Filter *filter = clipService.filter(ct);
2114 if (newPos > oldPos) {
2116 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2117 filter->set("kdenlive_ix", newPos);
2118 filtersList.append(filter);
2119 clipService.detach(*filter);
2120 filter = clipService.filter(ct);
2121 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2122 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2124 filter = clipService.filter(ct);
2128 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2129 filtersList.append(filter);
2130 clipService.detach(*filter);
2132 filter = clipService.filter(ct);
2136 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2137 filter->set("kdenlive_ix", newPos);
2138 filtersList.append(filter);
2139 clipService.detach(*filter);
2141 filter = clipService.filter(ct);
2145 filter = clipService.filter(ct);
2147 int pos = QString(filter->get("kdenlive_ix")).toInt();
2148 if (pos >= newPos) {
2149 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2150 filtersList.append(filter);
2151 clipService.detach(*filter);
2153 filter = clipService.filter(ct);
2157 for (int i = 0; i < filtersList.count(); i++) {
2158 clipService.attach(*(filtersList.at(i)));
2161 m_isBlocked = false;
2165 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2169 Mlt::Service service(m_mltProducer->parent().get_service());
2171 Mlt::Tractor tractor(service);
2172 Mlt::Producer trackProducer(tractor.track(info.track));
2173 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2175 /* // Display playlist info
2176 kDebug()<<"//////////// BEFORE RESIZE";
2177 for (int i = 0; i < trackPlaylist.count(); i++) {
2178 int blankStart = trackPlaylist.clip_start(i);
2179 int blankDuration = trackPlaylist.clip_length(i) - 1;
2181 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2182 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2185 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2186 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2187 m_isBlocked = false;
2190 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2191 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2192 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2193 int previousStart = clip->get_in();
2194 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2195 int diff = newDuration - trackPlaylist.clip_length(clipIndex) - 1;
2196 if (newDuration > clip->get_length()) {
2197 clip->parent().set("length", newDuration + 1);
2198 clip->set("length", newDuration + 1);
2200 if (newDuration > clip->get_out()) {
2201 clip->parent().set_in_and_out(0, newDuration + 1);
2202 clip->set_in_and_out(0, newDuration + 1);
2204 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2205 trackPlaylist.consolidate_blanks(0);
2206 // skip to next clip
2208 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2210 // clip was made longer, trim next blank if there is one.
2211 if (clipIndex < trackPlaylist.count()) {
2212 // If this is not the last clip in playlist
2213 if (trackPlaylist.is_blank(clipIndex)) {
2214 int blankStart = trackPlaylist.clip_start(clipIndex);
2215 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2216 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2217 if (diff - blankDuration == 1) {
2218 trackPlaylist.remove(clipIndex);
2219 } else trackPlaylist.remove_region(blankStart, diff - 1);
2221 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2224 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2226 trackPlaylist.consolidate_blanks(0);
2229 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2230 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2231 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2232 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2233 ItemInfo transpinfo;
2234 transpinfo.startPos = info.startPos;
2235 transpinfo.endPos = info.startPos + clipDuration;
2236 transpinfo.track = info.track;
2237 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2239 m_isBlocked = false;
2240 m_mltConsumer->set("refresh", 1);
2244 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2246 Mlt::Service service(m_mltProducer->parent().get_service());
2247 Mlt::Tractor tractor(service);
2248 Mlt::Producer trackProducer(tractor.track(track));
2251 if (blind) trackProducer.set("hide", 3);
2252 else trackProducer.set("hide", 2);
2254 trackProducer.set("hide", 1);
2256 trackProducer.set("hide", 0);
2258 tractor.multitrack()->refresh();
2264 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2266 Mlt::Service service(m_mltProducer->parent().get_service());
2267 int frameOffset = (int) diff.frames(m_fps);
2268 Mlt::Tractor tractor(service);
2269 Mlt::Producer trackProducer(tractor.track(info.track));
2270 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2271 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2272 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2275 mlt_service_lock(service.get_service());
2276 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2277 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2279 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2280 mlt_service_unlock(service.get_service());
2283 int previousStart = clip->get_in();
2284 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2286 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2287 m_isBlocked = false;
2288 mlt_service_unlock(service.get_service());
2289 m_mltConsumer->set("refresh", 1);
2293 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2295 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2296 Mlt::Service service(m_mltProducer->parent().get_service());
2297 int moveFrame = (int) diff.frames(m_fps);
2298 Mlt::Tractor tractor(service);
2299 Mlt::Producer trackProducer(tractor.track(info.track));
2300 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2301 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2302 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2305 mlt_service_lock(service.get_service());
2306 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2307 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2309 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2310 mlt_service_unlock(service.get_service());
2313 int previousStart = clip->get_in();
2314 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2316 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2317 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2318 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2320 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2321 int blankIndex = clipIndex - 1;
2322 int blankLength = trackPlaylist.clip_length(blankIndex);
2323 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2324 if (! trackPlaylist.is_blank(blankIndex)) {
2325 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2327 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2328 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2330 trackPlaylist.consolidate_blanks(0);
2331 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2332 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2333 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2334 ItemInfo transpinfo;
2335 transpinfo.startPos = info.startPos + diff;
2336 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2337 transpinfo.track = info.track;
2338 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2340 m_isBlocked = false;
2341 //m_mltConsumer->set("refresh", 1);
2342 mlt_service_unlock(service.get_service());
2343 m_mltConsumer->set("refresh", 1);
2347 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2349 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2353 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2355 if (prod == NULL || !prod->is_valid()) {
2356 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2359 kDebug() << "NEW PROD ID: " << prod->get("id");
2361 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2362 mlt_service_lock(m_mltConsumer->get_service());
2363 Mlt::Service service(m_mltProducer->parent().get_service());
2364 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2366 Mlt::Tractor tractor(service);
2367 Mlt::Producer trackProducer(tractor.track(track));
2368 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2369 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2370 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2371 if (clipProducer.is_blank()) {
2372 kDebug() << "// ERROR UPDATING CLIP PROD";
2373 mlt_service_unlock(m_mltConsumer->get_service());
2377 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2379 // move all effects to the correct producer
2380 Mlt::Service clipService(clipProducer.get_service());
2381 Mlt::Service newClipService(clip->get_service());
2384 Mlt::Filter *filter = clipService.filter(ct);
2386 if (filter->get("kdenlive_ix") != 0) {
2387 clipService.detach(*filter);
2388 newClipService.attach(*filter);
2390 filter = clipService.filter(ct);
2393 trackPlaylist.insert_at(pos, clip, 1);
2394 mlt_service_unlock(m_mltConsumer->get_service());
2398 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2402 //m_mltConsumer->set("refresh", 0);
2403 mlt_service_lock(m_mltConsumer->get_service());
2404 Mlt::Service service(m_mltProducer->parent().get_service());
2405 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2407 Mlt::Tractor tractor(service);
2408 Mlt::Producer trackProducer(tractor.track(startTrack));
2409 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2410 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2411 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2412 bool checkLength = false;
2413 if (endTrack == startTrack) {
2414 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2415 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2416 // error, destination is not empty
2417 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2418 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2419 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2420 mlt_service_unlock(m_mltConsumer->get_service());
2424 trackPlaylist.consolidate_blanks(0);
2425 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2426 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2427 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2429 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2431 //mlt_service_unlock(service.get_service());
2433 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2434 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2435 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2436 // error, destination is not empty
2437 mlt_service_unlock(m_mltConsumer->get_service());
2441 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2442 if (clipProducer.is_blank()) {
2443 // error, destination is not empty
2444 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2445 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2446 mlt_service_unlock(m_mltConsumer->get_service());
2450 trackPlaylist.consolidate_blanks(0);
2451 destTrackPlaylist.consolidate_blanks(1);
2452 Mlt::Producer *clip;
2453 // check if we are moving a slowmotion producer
2454 QString serv = clipProducer.parent().get("mlt_service");
2455 QString currentid = clipProducer.parent().get("id");
2456 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2457 clip = &clipProducer;
2460 // Special case: prod is null when using placeholder clips.
2461 // in that case, use the producer existing in playlist. Note that
2462 // it will bypass the one producer per track logic and might cause
2463 // Sound cracks if clip is moved so that it overlaps another copy of itself
2464 clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
2465 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2468 // move all effects to the correct producer
2469 Mlt::Service clipService(clipProducer.get_service());
2470 Mlt::Service newClipService(clip->get_service());
2473 Mlt::Filter *filter = clipService.filter(ct);
2475 if (filter->get("kdenlive_ix") != 0) {
2476 clipService.detach(*filter);
2477 newClipService.attach(*filter);
2479 filter = clipService.filter(ct);
2482 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2483 destTrackPlaylist.consolidate_blanks(0);
2484 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2485 kDebug() << "//////// moving clip transparency";
2486 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2488 if (clipIndex > trackPlaylist.count()) checkLength = true;
2489 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2493 if (checkLength) mltCheckLength();
2494 mlt_service_unlock(m_mltConsumer->get_service());
2497 //m_mltConsumer->set("refresh", 1);
2501 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2503 int new_in = (int)newIn.frames(m_fps);
2504 int new_out = (int)newOut.frames(m_fps) - 1;
2505 if (new_in >= new_out) return false;
2507 Mlt::Service service(m_mltProducer->parent().get_service());
2508 Mlt::Tractor tractor(service);
2511 mlt_service_lock(service.get_service());
2512 //m_mltConsumer->set("refresh", 0);
2514 mlt_service serv = m_mltProducer->parent().get_service();
2515 mlt_service nextservice = mlt_service_get_producer(serv);
2516 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2517 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2518 QString resource = mlt_properties_get(properties, "mlt_service");
2519 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2521 while (mlt_type == "transition") {
2522 mlt_transition tr = (mlt_transition) nextservice;
2523 int currentTrack = mlt_transition_get_b_track(tr);
2524 int currentIn = (int) mlt_transition_get_in(tr);
2525 int currentOut = (int) mlt_transition_get_out(tr);
2527 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2528 mlt_transition_set_in_and_out(tr, new_in, new_out);
2529 if (newTrack - startTrack != 0) {
2530 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2532 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2533 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2534 mlt_properties_set_int(properties, "b_track", newTrack);
2535 //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);
2539 nextservice = mlt_service_producer(nextservice);
2540 if (nextservice == NULL) break;
2541 properties = MLT_SERVICE_PROPERTIES(nextservice);
2542 mlt_type = mlt_properties_get(properties, "mlt_type");
2543 resource = mlt_properties_get(properties, "mlt_service");
2545 mlt_service_unlock(service.get_service());
2548 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2552 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2554 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2556 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2557 mltAddTransition(tag, a_track, b_track, in, out, xml);
2559 //mltSavePlaylist();
2562 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2564 Mlt::Service service(m_mltProducer->parent().get_service());
2565 Mlt::Tractor tractor(service);
2566 mlt_service_lock(service.get_service());
2569 mlt_service serv = m_mltProducer->parent().get_service();
2570 mlt_service nextservice = mlt_service_get_producer(serv);
2571 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2572 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2573 QString resource = mlt_properties_get(properties, "mlt_service");
2574 int in_pos = (int) in.frames(m_fps);
2575 int out_pos = (int) out.frames(m_fps) - 1;
2577 while (mlt_type == "transition") {
2578 mlt_transition tr = (mlt_transition) nextservice;
2579 int currentTrack = mlt_transition_get_b_track(tr);
2580 int currentBTrack = mlt_transition_get_a_track(tr);
2581 int currentIn = (int) mlt_transition_get_in(tr);
2582 int currentOut = (int) mlt_transition_get_out(tr);
2584 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2586 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2587 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2588 QMap<QString, QString>::Iterator it;
2590 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2591 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2592 if (currentBTrack != a_track) {
2593 mlt_properties_set_int(properties, "a_track", a_track);
2595 for (it = map.begin(); it != map.end(); ++it) {
2597 char *name = decodedString(key);
2598 char *value = decodedString(it.value());
2599 mlt_properties_set(transproperties, name, value);
2600 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2601 //filter->set("kdenlive_id", id);
2607 nextservice = mlt_service_producer(nextservice);
2608 if (nextservice == NULL) break;
2609 properties = MLT_SERVICE_PROPERTIES(nextservice);
2610 mlt_type = mlt_properties_get(properties, "mlt_type");
2611 resource = mlt_properties_get(properties, "mlt_service");
2613 mlt_service_unlock(service.get_service());
2616 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2619 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2621 Mlt::Service service(m_mltProducer->parent().get_service());
2622 Mlt::Tractor tractor(service);
2624 mlt_service_lock(service.get_service());
2626 Mlt::Field *field = tractor.field();
2628 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2629 mlt_service serv = m_mltProducer->parent().get_service();
2631 mlt_service nextservice = mlt_service_get_producer(serv);
2632 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2633 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2634 QString resource = mlt_properties_get(properties, "mlt_service");
2636 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2637 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2639 while (mlt_type == "transition") {
2640 mlt_transition tr = (mlt_transition) nextservice;
2641 int currentTrack = mlt_transition_get_b_track(tr);
2642 int currentIn = (int) mlt_transition_get_in(tr);
2643 int currentOut = (int) mlt_transition_get_out(tr);
2644 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2646 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2647 mlt_field_disconnect_service(field->get_field(), nextservice);
2650 nextservice = mlt_service_producer(nextservice);
2651 if (nextservice == NULL) break;
2652 properties = MLT_SERVICE_PROPERTIES(nextservice);
2653 mlt_type = mlt_properties_get(properties, "mlt_type");
2654 resource = mlt_properties_get(properties, "mlt_service");
2656 mlt_service_unlock(service.get_service());
2659 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2662 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2664 QDomNodeList attribs = xml.elementsByTagName("parameter");
2665 QMap<QString, QString> map;
2666 for (int i = 0;i < attribs.count();i++) {
2667 QDomElement e = attribs.item(i).toElement();
2668 QString name = e.attribute("name");
2669 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2670 map[name] = e.attribute("default");
2671 if (!e.attribute("value").isEmpty()) {
2672 map[name] = e.attribute("value");
2674 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2675 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2676 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2679 if (e.attribute("namedesc").contains(';')) {
2680 QString format = e.attribute("format");
2681 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2682 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2684 QTextStream txtNeu(&neu);
2685 if (values.size() > 0)
2686 txtNeu << (int)values[0].toDouble();
2688 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2689 txtNeu << separators[i];
2690 txtNeu << (int)(values[i+1].toDouble());
2692 if (i < separators.size())
2693 txtNeu << separators[i];
2694 map[e.attribute("name")] = neu;
2701 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2703 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2704 Mlt::Service service(m_mltProducer->parent().get_service());
2705 Mlt::Tractor tractor(service);
2706 Mlt::Field *field = tractor.field();
2708 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2709 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2710 transition->set("transparency", id);
2711 transition->set("fill", 1);
2712 transition->set("internal_added", 237);
2713 field->plant_transition(*transition, transitiontrack, info.track);
2717 void Render::mltDeleteTransparency(int pos, int track, int id)
2719 Mlt::Service service(m_mltProducer->parent().get_service());
2720 Mlt::Tractor tractor(service);
2721 Mlt::Field *field = tractor.field();
2723 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2724 mlt_service serv = m_mltProducer->parent().get_service();
2726 mlt_service nextservice = mlt_service_get_producer(serv);
2727 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2728 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2729 QString resource = mlt_properties_get(properties, "mlt_service");
2731 while (mlt_type == "transition") {
2732 mlt_transition tr = (mlt_transition) nextservice;
2733 int currentTrack = mlt_transition_get_b_track(tr);
2734 int currentIn = (int) mlt_transition_get_in(tr);
2735 int currentOut = (int) mlt_transition_get_out(tr);
2736 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2737 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2739 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2740 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2741 mlt_field_disconnect_service(field->get_field(), nextservice);
2744 nextservice = mlt_service_producer(nextservice);
2745 if (nextservice == NULL) break;
2746 properties = MLT_SERVICE_PROPERTIES(nextservice);
2747 mlt_type = mlt_properties_get(properties, "mlt_type");
2748 resource = mlt_properties_get(properties, "mlt_service");
2750 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2753 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2755 Mlt::Service service(m_mltProducer->parent().get_service());
2756 Mlt::Tractor tractor(service);
2758 mlt_service_lock(service.get_service());
2759 m_mltConsumer->set("refresh", 0);
2762 mlt_service serv = m_mltProducer->parent().get_service();
2763 mlt_service nextservice = mlt_service_get_producer(serv);
2764 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2765 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2766 QString resource = mlt_properties_get(properties, "mlt_service");
2767 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2768 while (mlt_type == "transition") {
2769 mlt_transition tr = (mlt_transition) nextservice;
2770 int currentTrack = mlt_transition_get_b_track(tr);
2771 int currentIn = (int) mlt_transition_get_in(tr);
2772 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2773 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2774 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2775 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2776 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2777 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2780 nextservice = mlt_service_producer(nextservice);
2781 if (nextservice == NULL) break;
2782 properties = MLT_SERVICE_PROPERTIES(nextservice);
2783 mlt_type = mlt_properties_get(properties, "mlt_type");
2784 resource = mlt_properties_get(properties, "mlt_service");
2786 mlt_service_unlock(service.get_service());
2788 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2792 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2794 Mlt::Service service(m_mltProducer->parent().get_service());
2795 Mlt::Tractor tractor(service);
2797 mlt_service_lock(service.get_service());
2798 m_mltConsumer->set("refresh", 0);
2801 mlt_service serv = m_mltProducer->parent().get_service();
2802 mlt_service nextservice = mlt_service_get_producer(serv);
2803 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2804 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2805 QString resource = mlt_properties_get(properties, "mlt_service");
2807 while (mlt_type == "transition") {
2808 mlt_transition tr = (mlt_transition) nextservice;
2809 int currentTrack = mlt_transition_get_b_track(tr);
2810 int currentaTrack = mlt_transition_get_a_track(tr);
2811 int currentIn = (int) mlt_transition_get_in(tr);
2812 int currentOut = (int) mlt_transition_get_out(tr);
2813 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2814 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2815 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2816 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2817 kDebug() << "//////MOVING";
2818 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2819 if (endTrack != startTrack) {
2820 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2821 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2822 mlt_properties_set_int(properties, "b_track", endTrack);
2826 nextservice = mlt_service_producer(nextservice);
2827 if (nextservice == NULL) break;
2828 properties = MLT_SERVICE_PROPERTIES(nextservice);
2829 mlt_type = mlt_properties_get(properties, "mlt_type");
2830 resource = mlt_properties_get(properties, "mlt_service");
2833 mlt_service_unlock(service.get_service());
2834 m_mltConsumer->set("refresh", 1);
2838 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2840 if (in >= out) return false;
2841 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2842 Mlt::Service service(m_mltProducer->parent().get_service());
2844 Mlt::Tractor tractor(service);
2845 Mlt::Field *field = tractor.field();
2847 char *transId = decodedString(tag);
2848 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2849 if (out != GenTime())
2850 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2851 QMap<QString, QString>::Iterator it;
2853 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2854 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2855 if (xml.hasAttribute("id"))
2856 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
2858 for (it = args.begin(); it != args.end(); ++it) {
2860 char *name = decodedString(key);
2861 char *value = decodedString(it.value());
2862 if (it.value().isEmpty() == false) transition->set(name, value);
2863 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2867 // attach filter to the clip
2868 field->plant_transition(*transition, a_track, b_track);
2874 void Render::mltSavePlaylist()
2876 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2877 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2878 fileConsumer.set("resource", "/tmp/playlist.mlt");
2880 Mlt::Service service(m_mltProducer->get_service());
2882 fileConsumer.connect(service);
2883 fileConsumer.start();
2886 QList <Mlt::Producer *> Render::producersList()
2888 QList <Mlt::Producer *> prods;
2889 Mlt::Service service(m_mltProducer->parent().get_service());
2890 if (service.type() != tractor_type) return prods;
2891 Mlt::Tractor tractor(service);
2894 int trackNb = tractor.count();
2895 for (int t = 1; t < trackNb; t++) {
2896 Mlt::Producer *tt = tractor.track(t);
2897 Mlt::Producer trackProducer(tt);
2899 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2900 int clipNb = trackPlaylist.count();
2901 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2902 for (int i = 0; i < clipNb; i++) {
2903 Mlt::Producer *c = trackPlaylist.get_clip(i);
2904 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2906 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2907 ids.append(nprod->get("id"));
2908 prods.append(nprod);
2909 } else delete nprod;
2917 void Render::fillSlowMotionProducers()
2919 Mlt::Service service(m_mltProducer->parent().get_service());
2920 if (service.type() != tractor_type) return;
2922 Mlt::Tractor tractor(service);
2924 int trackNb = tractor.count();
2925 for (int t = 1; t < trackNb; t++) {
2926 Mlt::Producer *tt = tractor.track(t);
2927 Mlt::Producer trackProducer(tt);
2929 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2930 int clipNb = trackPlaylist.count();
2931 for (int i = 0; i < clipNb; i++) {
2932 Mlt::Producer *c = trackPlaylist.get_clip(i);
2933 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2935 QString id = nprod->get("id");
2936 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
2937 // this is a slowmotion producer, add it to the list
2938 QString url = QString::fromUtf8(nprod->get("resource"));
2939 if (!m_slowmotionProducers.contains(url)) {
2940 m_slowmotionProducers.insert(url, nprod);
2942 } else delete nprod;
2949 void Render::mltInsertTrack(int ix, bool videoTrack)
2954 m_mltConsumer->set("refresh", 0);
2955 mlt_service_lock(m_mltConsumer->get_service());
2956 Mlt::Service service(m_mltProducer->parent().get_service());
2957 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2959 Mlt::Tractor tractor(service);
2961 Mlt::Playlist playlist;
2962 int ct = tractor.count();
2964 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
2970 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2971 tractor.set_track(playlist, pos);
2972 Mlt::Producer newProd(tractor.track(pos));
2973 if (!videoTrack) newProd.set("hide", 1);
2975 for (; pos <= ct; pos++) {
2976 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2977 tractor.set_track(*prodToMove, pos);
2978 prodToMove = prodToMove2;
2981 tractor.set_track(playlist, ix);
2982 Mlt::Producer newProd(tractor.track(ix));
2983 if (!videoTrack) newProd.set("hide", 1);
2987 mlt_service serv = m_mltProducer->parent().get_service();
2988 mlt_service nextservice = mlt_service_get_producer(serv);
2989 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2990 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2991 QString resource = mlt_properties_get(properties, "mlt_service");
2993 while (mlt_type == "transition") {
2994 if (resource != "mix") {
2995 mlt_transition tr = (mlt_transition) nextservice;
2996 int currentTrack = mlt_transition_get_b_track(tr);
2997 int currentaTrack = mlt_transition_get_a_track(tr);
2998 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3000 if (currentTrack >= ix) {
3001 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3002 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3005 nextservice = mlt_service_producer(nextservice);
3006 if (nextservice == NULL) break;
3007 properties = MLT_SERVICE_PROPERTIES(nextservice);
3008 mlt_type = mlt_properties_get(properties, "mlt_type");
3009 resource = mlt_properties_get(properties, "mlt_service");
3012 // Add audio mix transition to last track
3013 Mlt::Field *field = tractor.field();
3014 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3015 //transition->set("mlt_service", "mix");
3016 transition->set("a_track", 1);
3017 transition->set("b_track", ct);
3018 transition->set("always_active", 1);
3019 transition->set("internal_added", 237);
3020 transition->set("combine", 1);
3021 field->plant_transition(*transition, 1, ct);
3023 mlt_service_unlock(m_mltConsumer->get_service());
3025 blockSignals(false);
3029 void Render::mltDeleteTrack(int ix)
3032 doc.setContent(sceneList(), false);
3033 int tracksCount = doc.elementsByTagName("track").count() - 1;
3034 QDomNode track = doc.elementsByTagName("track").at(ix);
3035 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3036 QDomNodeList transitions = doc.elementsByTagName("transition");
3037 for (int i = 0; i < transitions.count(); i++) {
3038 QDomElement e = transitions.at(i).toElement();
3039 QDomNodeList props = e.elementsByTagName("property");
3040 QMap <QString, QString> mappedProps;
3041 for (int j = 0; j < props.count(); j++) {
3042 QDomElement f = props.at(j).toElement();
3043 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3045 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3046 tractor.removeChild(transitions.at(i));
3048 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3049 // Transition needs to be moved
3050 int a_track = mappedProps.value("a_track").toInt();
3051 int b_track = mappedProps.value("b_track").toInt();
3052 if (a_track > 0 && a_track >= ix) a_track --;
3053 if (b_track > 0 && b_track >= ix) b_track --;
3054 for (int j = 0; j < props.count(); j++) {
3055 QDomElement f = props.at(j).toElement();
3056 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3057 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3062 tractor.removeChild(track);
3063 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3064 setSceneList(doc.toString(), m_framePosition);
3069 void Render::updatePreviewSettings()
3071 kDebug() << "////// RESTARTING CONSUMER";
3072 if (!m_mltConsumer || !m_mltProducer) return;
3073 if (m_mltProducer->get_playtime() == 0) return;
3074 Mlt::Service service(m_mltProducer->parent().get_service());
3075 if (service.type() != tractor_type) return;
3077 //m_mltConsumer->set("refresh", 0);
3078 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3079 m_mltConsumer->purge();
3080 QString scene = sceneList();
3082 if (m_mltProducer) {
3083 pos = m_mltProducer->position();
3084 delete m_mltProducer;
3086 m_mltProducer = NULL;
3087 setSceneList(scene, pos);
3090 #include "renderer.moc"