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 trackPlaylist.replace_with_blank(clipIndex);
1535 trackPlaylist.consolidate_blanks(0);
1536 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1537 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1539 /* // Display playlist info
1540 kDebug()<<"//// AFTER";
1541 for (int i = 0; i < trackPlaylist.count(); i++) {
1542 int blankStart = trackPlaylist.clip_start(i);
1543 int blankDuration = trackPlaylist.clip_length(i) - 1;
1545 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1546 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1548 mlt_service_unlock(service.get_service());
1549 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1550 m_isBlocked = false;
1554 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1556 if (!m_mltProducer) {
1557 kDebug() << "PLAYLIST NOT INITIALISED //////";
1560 Mlt::Producer parentProd(m_mltProducer->parent());
1561 if (parentProd.get_producer() == NULL) {
1562 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1566 Mlt::Service service(parentProd.get_service());
1567 Mlt::Tractor tractor(service);
1568 int insertPos = pos.frames(m_fps);
1570 Mlt::Producer trackProducer(tractor.track(track));
1571 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1572 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1573 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1574 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1575 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1578 int Render::mltTrackDuration(int track)
1580 if (!m_mltProducer) {
1581 kDebug() << "PLAYLIST NOT INITIALISED //////";
1584 Mlt::Producer parentProd(m_mltProducer->parent());
1585 if (parentProd.get_producer() == NULL) {
1586 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1590 Mlt::Service service(parentProd.get_service());
1591 Mlt::Tractor tractor(service);
1593 Mlt::Producer trackProducer(tractor.track(track));
1594 return trackProducer.get_playtime() - 1;
1597 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1599 if (!m_mltProducer) {
1600 kDebug() << "PLAYLIST NOT INITIALISED //////";
1603 Mlt::Producer parentProd(m_mltProducer->parent());
1604 if (parentProd.get_producer() == NULL) {
1605 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1608 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1609 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1611 Mlt::Service service(parentProd.get_service());
1612 Mlt::Tractor tractor(service);
1613 mlt_service_lock(service.get_service());
1614 int diff = duration.frames(m_fps);
1615 int offset = timeOffset.frames(m_fps);
1619 // insert space in one track only
1620 Mlt::Producer trackProducer(tractor.track(track));
1621 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1622 insertPos = trackClipStartList.value(track);
1623 if (insertPos != -1) {
1624 insertPos += offset;
1625 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1626 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1628 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1629 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1630 int position = trackPlaylist.clip_start(clipIndex);
1631 trackPlaylist.remove_region(position, - diff - 1);
1633 trackPlaylist.consolidate_blanks(0);
1635 // now move transitions
1636 mlt_service serv = m_mltProducer->parent().get_service();
1637 mlt_service nextservice = mlt_service_get_producer(serv);
1638 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1639 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1640 QString resource = mlt_properties_get(properties, "mlt_service");
1642 while (mlt_type == "transition") {
1643 mlt_transition tr = (mlt_transition) nextservice;
1644 int currentTrack = mlt_transition_get_b_track(tr);
1645 int currentIn = (int) mlt_transition_get_in(tr);
1646 int currentOut = (int) mlt_transition_get_out(tr);
1647 insertPos = trackTransitionStartList.value(track);
1648 if (insertPos != -1) {
1649 insertPos += offset;
1650 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1651 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1654 nextservice = mlt_service_producer(nextservice);
1655 if (nextservice == NULL) break;
1656 properties = MLT_SERVICE_PROPERTIES(nextservice);
1657 mlt_type = mlt_properties_get(properties, "mlt_type");
1658 resource = mlt_properties_get(properties, "mlt_service");
1661 int trackNb = tractor.count();
1662 while (trackNb > 1) {
1663 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1664 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1667 //int clipNb = trackPlaylist.count();
1668 insertPos = trackClipStartList.value(trackNb - 1);
1669 if (insertPos != -1) {
1670 insertPos += offset;
1672 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1673 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1674 for (int i = 0; i < clipNb; i++) {
1675 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1676 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1677 kDebug()<<"-------------";
1679 kDebug()<<"END-------------";*/
1682 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1683 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1685 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1686 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1687 int position = trackPlaylist.clip_start(clipIndex);
1688 trackPlaylist.remove_region(position, - diff - 1);
1690 trackPlaylist.consolidate_blanks(0);
1694 // now move transitions
1695 mlt_service serv = m_mltProducer->parent().get_service();
1696 mlt_service nextservice = mlt_service_get_producer(serv);
1697 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1698 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1699 QString resource = mlt_properties_get(properties, "mlt_service");
1701 while (mlt_type == "transition") {
1702 mlt_transition tr = (mlt_transition) nextservice;
1703 int currentIn = (int) mlt_transition_get_in(tr);
1704 int currentOut = (int) mlt_transition_get_out(tr);
1705 int currentTrack = mlt_transition_get_b_track(tr);
1706 insertPos = trackTransitionStartList.value(currentTrack);
1707 if (insertPos != -1) {
1708 insertPos += offset;
1709 if (currentOut > insertPos && resource != "mix") {
1710 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1713 nextservice = mlt_service_producer(nextservice);
1714 if (nextservice == NULL) break;
1715 properties = MLT_SERVICE_PROPERTIES(nextservice);
1716 mlt_type = mlt_properties_get(properties, "mlt_type");
1717 resource = mlt_properties_get(properties, "mlt_service");
1720 mlt_service_unlock(service.get_service());
1722 m_mltConsumer->set("refresh", 1);
1725 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1729 Mlt::Service service(m_mltProducer->parent().get_service());
1730 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1731 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1732 Mlt::Tractor tractor(service);
1733 Mlt::Producer trackProducer(tractor.track(info.track));
1734 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1735 int startPos = info.startPos.frames(m_fps);
1736 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1737 int clipLength = trackPlaylist.clip_length(clipIndex);
1739 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1743 if (!clip->is_valid() || clip->is_blank()) {
1748 Mlt::Producer clipparent = clip->parent();
1749 if (!clipparent.is_valid() || clipparent.is_blank()) {
1755 QString serv = clipparent.get("mlt_service");
1756 QString id = clipparent.get("id");
1757 //kDebug() << "CLIP SERVICE: " << serv;
1758 if (serv == "avformat" && speed != 1.0) {
1759 mlt_service_lock(service.get_service());
1760 QString url = QString::fromUtf8(clipparent.get("resource"));
1761 url.append('?' + QString::number(speed));
1762 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1763 if (!slowprod || slowprod->get_producer() == NULL) {
1764 char *tmp = decodedString(url);
1765 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1767 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1768 tmp = decodedString(producerid);
1769 slowprod->set("id", tmp);
1771 m_slowmotionProducers.insert(url, slowprod);
1773 trackPlaylist.replace_with_blank(clipIndex);
1774 trackPlaylist.consolidate_blanks(0);
1775 // Check that the blank space is long enough for our new duration
1776 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1777 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1779 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1780 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1781 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1782 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1783 trackPlaylist.insert_at(startPos, *cut, 1);
1784 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1785 newLength = trackPlaylist.clip_length(clipIndex);
1786 mlt_service_unlock(service.get_service());
1787 } else if (speed == 1.0) {
1788 mlt_service_lock(service.get_service());
1790 trackPlaylist.replace_with_blank(clipIndex);
1791 trackPlaylist.consolidate_blanks(0);
1793 // Check that the blank space is long enough for our new duration
1794 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1795 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1798 GenTime oldDuration = GenTime(clipLength, m_fps);
1799 GenTime newDuration = oldDuration * oldspeed;
1800 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1801 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1802 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1803 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1804 trackPlaylist.insert_at(startPos, *cut, 1);
1805 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1806 newLength = trackPlaylist.clip_length(clipIndex);
1807 mlt_service_unlock(service.get_service());
1809 } else if (serv == "framebuffer") {
1810 mlt_service_lock(service.get_service());
1811 QString url = QString::fromUtf8(clipparent.get("resource"));
1812 url = url.section('?', 0, 0);
1813 url.append('?' + QString::number(speed));
1814 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1815 if (!slowprod || slowprod->get_producer() == NULL) {
1816 char *tmp = decodedString(url);
1817 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1819 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1820 tmp = decodedString(producerid);
1821 slowprod->set("id", tmp);
1823 m_slowmotionProducers.insert(url, slowprod);
1825 trackPlaylist.replace_with_blank(clipIndex);
1826 trackPlaylist.consolidate_blanks(0);
1828 GenTime oldDuration = GenTime(clipLength, m_fps);
1829 GenTime newDuration = oldDuration * oldspeed / speed;
1831 // Check that the blank space is long enough for our new duration
1832 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1833 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1836 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1837 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1838 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1839 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1841 trackPlaylist.insert_at(startPos, *cut, 1);
1842 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1843 newLength = trackPlaylist.clip_length(clipIndex);
1845 mlt_service_unlock(service.get_service());
1847 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1848 m_isBlocked = false;
1852 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1854 kDebug() << "// TRYing to remove effect at: " << index;
1855 Mlt::Service service(m_mltProducer->parent().get_service());
1856 bool success = false;
1857 Mlt::Tractor tractor(service);
1858 Mlt::Producer trackProducer(tractor.track(track));
1859 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1860 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1861 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1863 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1866 Mlt::Service clipService(clip->get_service());
1867 // if (tag.startsWith("ladspa")) tag = "ladspa";
1870 Mlt::Filter *filter = clipService.filter(ct);
1872 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1873 if (clipService.detach(*filter) == 0) success = true;
1874 kDebug() << " / / / DLEETED EFFECT: " << ct;
1875 } else if (updateIndex) {
1876 // Adjust the other effects index
1877 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1880 filter = clipService.filter(ct);
1882 m_isBlocked = false;
1883 if (doRefresh) refresh();
1888 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1891 Mlt::Service service(m_mltProducer->parent().get_service());
1893 Mlt::Tractor tractor(service);
1894 Mlt::Producer trackProducer(tractor.track(track));
1895 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1897 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1901 Mlt::Service clipService(clip->get_service());
1904 // temporarily remove all effects after insert point
1905 QList <Mlt::Filter *> filtersList;
1906 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1908 Mlt::Filter *filter = clipService.filter(ct);
1910 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1911 filtersList.append(filter);
1912 clipService.detach(*filter);
1914 filter = clipService.filter(ct);
1918 QString tag = params.paramValue("tag");
1919 kDebug() << " / / INSERTING EFFECT: " << tag;
1920 if (tag.startsWith("ladspa")) tag = "ladspa";
1921 char *filterTag = decodedString(tag);
1922 char *filterId = decodedString(params.paramValue("id"));
1923 QHash<QString, QString>::Iterator it;
1924 QString kfr = params.paramValue("keyframes");
1926 if (!kfr.isEmpty()) {
1927 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1928 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1929 char *starttag = decodedString(params.paramValue("starttag", "start"));
1930 char *endtag = decodedString(params.paramValue("endtag", "end"));
1931 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1932 int duration = clip->get_playtime();
1933 //double max = params.paramValue("max").toDouble();
1934 double min = params.paramValue("min").toDouble();
1935 double factor = params.paramValue("factor", "1").toDouble();
1936 params.removeParam("starttag");
1937 params.removeParam("endtag");
1938 params.removeParam("keyframes");
1939 params.removeParam("min");
1940 params.removeParam("max");
1941 params.removeParam("factor");
1943 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1944 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1945 if (filter && filter->is_valid()) {
1946 filter->set("kdenlive_id", filterId);
1947 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1948 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1949 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1950 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1951 if (x2 == -1) x2 = duration;
1953 for (int j = 0; j < params.count(); j++) {
1954 char *name = decodedString(params.at(j).name());
1955 char *value = decodedString(params.at(j).value());
1956 filter->set(name, value);
1961 filter->set("in", x1);
1962 filter->set("out", x2);
1963 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1964 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1965 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1966 clipService.attach(*filter);
1973 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1974 if (filter && filter->is_valid())
1975 filter->set("kdenlive_id", filterId);
1977 kDebug() << "filter is NULL";
1978 m_isBlocked = false;
1982 params.removeParam("kdenlive_id");
1984 for (int j = 0; j < params.count(); j++) {
1985 char *name = decodedString(params.at(j).name());
1986 char *value = decodedString(params.at(j).value());
1987 filter->set(name, value);
1993 QString effectArgs = params.paramValue("id").section('_', 1);
1995 params.removeParam("id");
1996 params.removeParam("kdenlive_ix");
1997 params.removeParam("tag");
1998 params.removeParam("disabled");
2000 for (int j = 0; j < params.count(); j++) {
2001 effectArgs.append(' ' + params.at(j).value());
2003 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2004 char *value = decodedString(effectArgs.simplified());
2005 filter->set("effect", value);
2010 // attach filter to the clip
2011 clipService.attach(*filter);
2016 // re-add following filters
2017 for (int i = 0; i < filtersList.count(); i++) {
2018 clipService.attach(*(filtersList.at(i)));
2021 m_isBlocked = false;
2022 if (doRefresh) refresh();
2026 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2028 QString index = params.paramValue("kdenlive_ix");
2029 QString tag = params.paramValue("tag");
2031 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2032 // This is a keyframe effect, to edit it, we remove it and re-add it.
2033 mltRemoveEffect(track, position, index, true);
2034 bool success = mltAddEffect(track, position, params);
2039 Mlt::Service service(m_mltProducer->parent().get_service());
2041 Mlt::Tractor tractor(service);
2042 Mlt::Producer trackProducer(tractor.track(track));
2043 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2044 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2045 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2047 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2050 Mlt::Service clipService(clip->get_service());
2053 Mlt::Filter *filter = clipService.filter(ct);
2055 if (filter->get("kdenlive_ix") == index) {
2059 filter = clipService.filter(ct);
2063 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2064 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2066 filter = clipService.filter(ct);
2067 QList <Mlt::Filter *> filtersList;
2069 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2070 filtersList.append(filter);
2071 clipService.detach(*filter);
2073 filter = clipService.filter(ct);
2075 bool success = mltAddEffect(track, position, params);
2077 for (int i = 0; i < filtersList.count(); i++) {
2078 clipService.attach(*(filtersList.at(i)));
2081 m_isBlocked = false;
2085 for (int j = 0; j < params.count(); j++) {
2086 char *name = decodedString(params.at(j).name());
2087 char *value = decodedString(params.at(j).value());
2088 filter->set(name, value);
2093 m_isBlocked = false;
2098 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2101 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2102 Mlt::Service service(m_mltProducer->parent().get_service());
2104 Mlt::Tractor tractor(service);
2105 Mlt::Producer trackProducer(tractor.track(track));
2106 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2107 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2108 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2110 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2113 Mlt::Service clipService(clip->get_service());
2116 QList <Mlt::Filter *> filtersList;
2117 Mlt::Filter *filter = clipService.filter(ct);
2119 if (newPos > oldPos) {
2121 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2122 filter->set("kdenlive_ix", newPos);
2123 filtersList.append(filter);
2124 clipService.detach(*filter);
2125 filter = clipService.filter(ct);
2126 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2127 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2129 filter = clipService.filter(ct);
2133 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2134 filtersList.append(filter);
2135 clipService.detach(*filter);
2137 filter = clipService.filter(ct);
2141 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2142 filter->set("kdenlive_ix", newPos);
2143 filtersList.append(filter);
2144 clipService.detach(*filter);
2146 filter = clipService.filter(ct);
2150 filter = clipService.filter(ct);
2152 int pos = QString(filter->get("kdenlive_ix")).toInt();
2153 if (pos >= newPos) {
2154 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2155 filtersList.append(filter);
2156 clipService.detach(*filter);
2158 filter = clipService.filter(ct);
2162 for (int i = 0; i < filtersList.count(); i++) {
2163 clipService.attach(*(filtersList.at(i)));
2166 m_isBlocked = false;
2170 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2173 Mlt::Service service(m_mltProducer->parent().get_service());
2174 Mlt::Tractor tractor(service);
2175 Mlt::Producer trackProducer(tractor.track(info.track));
2176 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2178 /* // Display playlist info
2179 kDebug()<<"//////////// BEFORE RESIZE";
2180 for (int i = 0; i < trackPlaylist.count(); i++) {
2181 int blankStart = trackPlaylist.clip_start(i);
2182 int blankDuration = trackPlaylist.clip_length(i) - 1;
2184 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2185 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2188 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2189 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2190 m_isBlocked = false;
2193 mlt_service_lock(service.get_service());
2194 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2195 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2196 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2197 int previousStart = clip->get_in();
2198 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2199 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2200 if (newDuration > clip->get_length()) {
2201 clip->parent().set("length", newDuration + 1);
2202 clip->set("length", newDuration + 1);
2204 if (newDuration > clip->get_out()) {
2205 clip->parent().set_in_and_out(0, newDuration + 1);
2206 clip->set_in_and_out(0, newDuration + 1);
2209 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2210 trackPlaylist.consolidate_blanks(0);
2211 // skip to next clip
2213 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2215 // clip was made longer, trim next blank if there is one.
2216 if (clipIndex < trackPlaylist.count()) {
2217 // If this is not the last clip in playlist
2218 if (trackPlaylist.is_blank(clipIndex)) {
2219 int blankStart = trackPlaylist.clip_start(clipIndex);
2220 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2221 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2222 if (diff - blankDuration == 1) {
2223 trackPlaylist.remove(clipIndex);
2224 } else trackPlaylist.remove_region(blankStart, diff - 1);
2226 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2229 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2230 trackPlaylist.consolidate_blanks(0);
2231 mlt_service_unlock(service.get_service());
2233 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2234 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2235 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2236 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2237 ItemInfo transpinfo;
2238 transpinfo.startPos = info.startPos;
2239 transpinfo.endPos = info.startPos + clipDuration;
2240 transpinfo.track = info.track;
2241 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2243 m_isBlocked = false;
2244 m_mltConsumer->set("refresh", 1);
2248 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2250 Mlt::Service service(m_mltProducer->parent().get_service());
2251 Mlt::Tractor tractor(service);
2252 Mlt::Producer trackProducer(tractor.track(track));
2255 if (blind) trackProducer.set("hide", 3);
2256 else trackProducer.set("hide", 2);
2258 trackProducer.set("hide", 1);
2260 trackProducer.set("hide", 0);
2262 tractor.multitrack()->refresh();
2268 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2270 Mlt::Service service(m_mltProducer->parent().get_service());
2271 int frameOffset = (int) diff.frames(m_fps);
2272 Mlt::Tractor tractor(service);
2273 Mlt::Producer trackProducer(tractor.track(info.track));
2274 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2275 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2276 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2279 mlt_service_lock(service.get_service());
2280 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2281 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2283 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2284 mlt_service_unlock(service.get_service());
2287 int previousStart = clip->get_in();
2289 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2291 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2292 m_isBlocked = false;
2293 mlt_service_unlock(service.get_service());
2294 m_mltConsumer->set("refresh", 1);
2298 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2300 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2301 Mlt::Service service(m_mltProducer->parent().get_service());
2302 int moveFrame = (int) diff.frames(m_fps);
2303 Mlt::Tractor tractor(service);
2304 Mlt::Producer trackProducer(tractor.track(info.track));
2305 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2306 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2307 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2310 mlt_service_lock(service.get_service());
2311 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2312 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2314 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2315 mlt_service_unlock(service.get_service());
2318 int previousStart = clip->get_in();
2320 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2322 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2323 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2324 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2326 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2327 int blankIndex = clipIndex - 1;
2328 int blankLength = trackPlaylist.clip_length(blankIndex);
2329 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2330 if (! trackPlaylist.is_blank(blankIndex)) {
2331 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2333 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2334 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2336 trackPlaylist.consolidate_blanks(0);
2337 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2338 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2339 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2340 ItemInfo transpinfo;
2341 transpinfo.startPos = info.startPos + diff;
2342 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2343 transpinfo.track = info.track;
2344 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2346 m_isBlocked = false;
2347 //m_mltConsumer->set("refresh", 1);
2348 mlt_service_unlock(service.get_service());
2349 m_mltConsumer->set("refresh", 1);
2353 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2355 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2359 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2361 if (prod == NULL || !prod->is_valid()) {
2362 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2365 kDebug() << "NEW PROD ID: " << prod->get("id");
2367 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2368 mlt_service_lock(m_mltConsumer->get_service());
2369 Mlt::Service service(m_mltProducer->parent().get_service());
2370 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2372 Mlt::Tractor tractor(service);
2373 Mlt::Producer trackProducer(tractor.track(track));
2374 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2375 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2376 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2377 if (clipProducer.is_blank()) {
2378 kDebug() << "// ERROR UPDATING CLIP PROD";
2379 mlt_service_unlock(m_mltConsumer->get_service());
2383 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2385 // move all effects to the correct producer
2386 Mlt::Service clipService(clipProducer.get_service());
2387 Mlt::Service newClipService(clip->get_service());
2390 Mlt::Filter *filter = clipService.filter(ct);
2392 if (filter->get("kdenlive_ix") != 0) {
2393 clipService.detach(*filter);
2394 newClipService.attach(*filter);
2396 filter = clipService.filter(ct);
2399 trackPlaylist.insert_at(pos, clip, 1);
2400 mlt_service_unlock(m_mltConsumer->get_service());
2404 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2408 Mlt::Service service(m_mltProducer->parent().get_service());
2409 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2411 Mlt::Tractor tractor(service);
2412 mlt_service_lock(service.get_service());
2413 Mlt::Producer trackProducer(tractor.track(startTrack));
2414 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2415 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2416 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2417 bool checkLength = false;
2418 if (endTrack == startTrack) {
2419 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2420 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2421 // error, destination is not empty
2422 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2423 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2424 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2425 mlt_service_unlock(service.get_service());
2429 trackPlaylist.consolidate_blanks(0);
2430 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2431 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2432 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2434 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2436 //mlt_service_unlock(service.get_service());
2438 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2439 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2440 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2441 // error, destination is not empty
2442 mlt_service_unlock(service.get_service());
2446 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2447 if (clipProducer.is_blank()) {
2448 // error, destination is not empty
2449 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2450 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2451 mlt_service_unlock(service.get_service());
2455 trackPlaylist.consolidate_blanks(0);
2456 destTrackPlaylist.consolidate_blanks(1);
2457 Mlt::Producer *clip;
2458 // check if we are moving a slowmotion producer
2459 QString serv = clipProducer.parent().get("mlt_service");
2460 QString currentid = clipProducer.parent().get("id");
2461 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2462 clip = &clipProducer;
2465 // Special case: prod is null when using placeholder clips.
2466 // in that case, use the producer existing in playlist. Note that
2467 // it will bypass the one producer per track logic and might cause
2468 // Sound cracks if clip is moved so that it overlaps another copy of itself
2469 clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
2470 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2473 // move all effects to the correct producer
2474 Mlt::Service clipService(clipProducer.get_service());
2475 Mlt::Service newClipService(clip->get_service());
2478 Mlt::Filter *filter = clipService.filter(ct);
2480 if (filter->get("kdenlive_ix") != 0) {
2481 clipService.detach(*filter);
2482 newClipService.attach(*filter);
2484 filter = clipService.filter(ct);
2487 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2488 destTrackPlaylist.consolidate_blanks(0);
2489 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2490 kDebug() << "//////// moving clip transparency";
2491 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2493 if (clipIndex > trackPlaylist.count()) checkLength = true;
2494 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2497 mlt_service_unlock(service.get_service());
2498 if (checkLength) mltCheckLength();
2501 //m_mltConsumer->set("refresh", 1);
2505 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2507 int new_in = (int)newIn.frames(m_fps);
2508 int new_out = (int)newOut.frames(m_fps) - 1;
2509 if (new_in >= new_out) return false;
2511 mlt_service serv = m_mltProducer->parent().get_service();
2513 mlt_service_lock(serv);
2514 //m_mltConsumer->set("refresh", 0);
2517 mlt_service nextservice = mlt_service_get_producer(serv);
2518 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2519 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2520 QString resource = mlt_properties_get(properties, "mlt_service");
2521 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2523 while (mlt_type == "transition") {
2524 mlt_transition tr = (mlt_transition) nextservice;
2525 int currentTrack = mlt_transition_get_b_track(tr);
2526 int currentIn = (int) mlt_transition_get_in(tr);
2527 int currentOut = (int) mlt_transition_get_out(tr);
2529 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2530 mlt_transition_set_in_and_out(tr, new_in, new_out);
2531 if (newTrack - startTrack != 0) {
2532 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2534 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2535 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2536 mlt_properties_set_int(properties, "b_track", newTrack);
2537 //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);
2541 nextservice = mlt_service_producer(nextservice);
2542 if (nextservice == NULL) break;
2543 properties = MLT_SERVICE_PROPERTIES(nextservice);
2544 mlt_type = mlt_properties_get(properties, "mlt_type");
2545 resource = mlt_properties_get(properties, "mlt_service");
2547 mlt_service_unlock(serv);
2550 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2554 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2556 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2558 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2559 mltAddTransition(tag, a_track, b_track, in, out, xml);
2561 //mltSavePlaylist();
2564 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2566 mlt_service serv = m_mltProducer->parent().get_service();
2567 mlt_service_lock(serv);
2571 mlt_service nextservice = mlt_service_get_producer(serv);
2572 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2573 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2574 QString resource = mlt_properties_get(properties, "mlt_service");
2575 int in_pos = (int) in.frames(m_fps);
2576 int out_pos = (int) out.frames(m_fps) - 1;
2578 while (mlt_type == "transition") {
2579 mlt_transition tr = (mlt_transition) nextservice;
2580 int currentTrack = mlt_transition_get_b_track(tr);
2581 int currentBTrack = mlt_transition_get_a_track(tr);
2582 int currentIn = (int) mlt_transition_get_in(tr);
2583 int currentOut = (int) mlt_transition_get_out(tr);
2585 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2587 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2588 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2589 QMap<QString, QString>::Iterator it;
2591 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2592 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2593 if (currentBTrack != a_track) {
2594 mlt_properties_set_int(properties, "a_track", a_track);
2596 for (it = map.begin(); it != map.end(); ++it) {
2598 char *name = decodedString(key);
2599 char *value = decodedString(it.value());
2600 mlt_properties_set(transproperties, name, value);
2601 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2602 //filter->set("kdenlive_id", id);
2608 nextservice = mlt_service_producer(nextservice);
2609 if (nextservice == NULL) break;
2610 properties = MLT_SERVICE_PROPERTIES(nextservice);
2611 mlt_type = mlt_properties_get(properties, "mlt_type");
2612 resource = mlt_properties_get(properties, "mlt_service");
2614 mlt_service_unlock(serv);
2617 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2620 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2622 mlt_service serv = m_mltProducer->parent().get_service();
2624 mlt_service_lock(serv);
2626 Mlt::Service service(serv);
2627 Mlt::Tractor tractor(service);
2628 Mlt::Field *field = tractor.field();
2630 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2632 mlt_service nextservice = mlt_service_get_producer(serv);
2633 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2634 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2635 QString resource = mlt_properties_get(properties, "mlt_service");
2637 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2638 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2640 while (mlt_type == "transition") {
2641 mlt_transition tr = (mlt_transition) nextservice;
2642 int currentTrack = mlt_transition_get_b_track(tr);
2643 int currentIn = (int) mlt_transition_get_in(tr);
2644 int currentOut = (int) mlt_transition_get_out(tr);
2645 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2647 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2648 mlt_field_disconnect_service(field->get_field(), nextservice);
2651 nextservice = mlt_service_producer(nextservice);
2652 if (nextservice == NULL) break;
2653 properties = MLT_SERVICE_PROPERTIES(nextservice);
2654 mlt_type = mlt_properties_get(properties, "mlt_type");
2655 resource = mlt_properties_get(properties, "mlt_service");
2657 mlt_service_unlock(serv);
2660 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2663 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2665 QDomNodeList attribs = xml.elementsByTagName("parameter");
2666 QMap<QString, QString> map;
2667 for (int i = 0;i < attribs.count();i++) {
2668 QDomElement e = attribs.item(i).toElement();
2669 QString name = e.attribute("name");
2670 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2671 map[name] = e.attribute("default");
2672 if (!e.attribute("value").isEmpty()) {
2673 map[name] = e.attribute("value");
2675 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2676 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2677 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2680 if (e.attribute("namedesc").contains(';')) {
2681 QString format = e.attribute("format");
2682 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2683 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2685 QTextStream txtNeu(&neu);
2686 if (values.size() > 0)
2687 txtNeu << (int)values[0].toDouble();
2689 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2690 txtNeu << separators[i];
2691 txtNeu << (int)(values[i+1].toDouble());
2693 if (i < separators.size())
2694 txtNeu << separators[i];
2695 map[e.attribute("name")] = neu;
2702 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2704 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2705 Mlt::Service service(m_mltProducer->parent().get_service());
2706 Mlt::Tractor tractor(service);
2707 Mlt::Field *field = tractor.field();
2709 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2710 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2711 transition->set("transparency", id);
2712 transition->set("fill", 1);
2713 transition->set("internal_added", 237);
2714 field->plant_transition(*transition, transitiontrack, info.track);
2718 void Render::mltDeleteTransparency(int pos, int track, int id)
2720 Mlt::Service service(m_mltProducer->parent().get_service());
2721 Mlt::Tractor tractor(service);
2722 Mlt::Field *field = tractor.field();
2724 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2725 mlt_service serv = m_mltProducer->parent().get_service();
2727 mlt_service nextservice = mlt_service_get_producer(serv);
2728 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2729 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2730 QString resource = mlt_properties_get(properties, "mlt_service");
2732 while (mlt_type == "transition") {
2733 mlt_transition tr = (mlt_transition) nextservice;
2734 int currentTrack = mlt_transition_get_b_track(tr);
2735 int currentIn = (int) mlt_transition_get_in(tr);
2736 int currentOut = (int) mlt_transition_get_out(tr);
2737 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2738 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2740 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2741 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2742 mlt_field_disconnect_service(field->get_field(), nextservice);
2745 nextservice = mlt_service_producer(nextservice);
2746 if (nextservice == NULL) break;
2747 properties = MLT_SERVICE_PROPERTIES(nextservice);
2748 mlt_type = mlt_properties_get(properties, "mlt_type");
2749 resource = mlt_properties_get(properties, "mlt_service");
2751 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2754 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2756 Mlt::Service service(m_mltProducer->parent().get_service());
2757 Mlt::Tractor tractor(service);
2759 mlt_service_lock(service.get_service());
2760 m_mltConsumer->set("refresh", 0);
2763 mlt_service serv = m_mltProducer->parent().get_service();
2764 mlt_service nextservice = mlt_service_get_producer(serv);
2765 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2766 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2767 QString resource = mlt_properties_get(properties, "mlt_service");
2768 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2769 while (mlt_type == "transition") {
2770 mlt_transition tr = (mlt_transition) nextservice;
2771 int currentTrack = mlt_transition_get_b_track(tr);
2772 int currentIn = (int) mlt_transition_get_in(tr);
2773 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2774 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2775 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2776 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2777 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2778 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2781 nextservice = mlt_service_producer(nextservice);
2782 if (nextservice == NULL) break;
2783 properties = MLT_SERVICE_PROPERTIES(nextservice);
2784 mlt_type = mlt_properties_get(properties, "mlt_type");
2785 resource = mlt_properties_get(properties, "mlt_service");
2787 mlt_service_unlock(service.get_service());
2789 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2793 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2795 Mlt::Service service(m_mltProducer->parent().get_service());
2796 Mlt::Tractor tractor(service);
2798 mlt_service_lock(service.get_service());
2799 m_mltConsumer->set("refresh", 0);
2802 mlt_service serv = m_mltProducer->parent().get_service();
2803 mlt_service nextservice = mlt_service_get_producer(serv);
2804 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2805 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2806 QString resource = mlt_properties_get(properties, "mlt_service");
2808 while (mlt_type == "transition") {
2809 mlt_transition tr = (mlt_transition) nextservice;
2810 int currentTrack = mlt_transition_get_b_track(tr);
2811 int currentaTrack = mlt_transition_get_a_track(tr);
2812 int currentIn = (int) mlt_transition_get_in(tr);
2813 int currentOut = (int) mlt_transition_get_out(tr);
2814 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2815 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2816 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2817 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2818 kDebug() << "//////MOVING";
2819 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2820 if (endTrack != startTrack) {
2821 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2822 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2823 mlt_properties_set_int(properties, "b_track", endTrack);
2827 nextservice = mlt_service_producer(nextservice);
2828 if (nextservice == NULL) break;
2829 properties = MLT_SERVICE_PROPERTIES(nextservice);
2830 mlt_type = mlt_properties_get(properties, "mlt_type");
2831 resource = mlt_properties_get(properties, "mlt_service");
2834 mlt_service_unlock(service.get_service());
2835 m_mltConsumer->set("refresh", 1);
2839 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2841 if (in >= out) return false;
2842 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2843 Mlt::Service service(m_mltProducer->parent().get_service());
2845 Mlt::Tractor tractor(service);
2846 Mlt::Field *field = tractor.field();
2848 char *transId = decodedString(tag);
2849 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2850 if (out != GenTime())
2851 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2852 QMap<QString, QString>::Iterator it;
2854 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2855 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2856 if (xml.hasAttribute("id"))
2857 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
2859 for (it = args.begin(); it != args.end(); ++it) {
2861 char *name = decodedString(key);
2862 char *value = decodedString(it.value());
2863 if (it.value().isEmpty() == false) transition->set(name, value);
2864 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2868 // attach filter to the clip
2869 field->plant_transition(*transition, a_track, b_track);
2875 void Render::mltSavePlaylist()
2877 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2878 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2879 fileConsumer.set("resource", "/tmp/playlist.mlt");
2881 Mlt::Service service(m_mltProducer->get_service());
2883 fileConsumer.connect(service);
2884 fileConsumer.start();
2887 QList <Mlt::Producer *> Render::producersList()
2889 QList <Mlt::Producer *> prods;
2890 Mlt::Service service(m_mltProducer->parent().get_service());
2891 if (service.type() != tractor_type) return prods;
2892 Mlt::Tractor tractor(service);
2895 int trackNb = tractor.count();
2896 for (int t = 1; t < trackNb; t++) {
2897 Mlt::Producer *tt = tractor.track(t);
2898 Mlt::Producer trackProducer(tt);
2900 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2901 int clipNb = trackPlaylist.count();
2902 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2903 for (int i = 0; i < clipNb; i++) {
2904 Mlt::Producer *c = trackPlaylist.get_clip(i);
2905 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2907 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2908 ids.append(nprod->get("id"));
2909 prods.append(nprod);
2910 } else delete nprod;
2918 void Render::fillSlowMotionProducers()
2920 Mlt::Service service(m_mltProducer->parent().get_service());
2921 if (service.type() != tractor_type) return;
2923 Mlt::Tractor tractor(service);
2925 int trackNb = tractor.count();
2926 for (int t = 1; t < trackNb; t++) {
2927 Mlt::Producer *tt = tractor.track(t);
2928 Mlt::Producer trackProducer(tt);
2930 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2931 int clipNb = trackPlaylist.count();
2932 for (int i = 0; i < clipNb; i++) {
2933 Mlt::Producer *c = trackPlaylist.get_clip(i);
2934 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2936 QString id = nprod->get("id");
2937 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
2938 // this is a slowmotion producer, add it to the list
2939 QString url = QString::fromUtf8(nprod->get("resource"));
2940 if (!m_slowmotionProducers.contains(url)) {
2941 m_slowmotionProducers.insert(url, nprod);
2943 } else delete nprod;
2950 void Render::mltInsertTrack(int ix, bool videoTrack)
2955 Mlt::Service service(m_mltProducer->parent().get_service());
2956 mlt_service_lock(service.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("a_track", 1);
3016 transition->set("b_track", ct);
3017 transition->set("always_active", 1);
3018 transition->set("internal_added", 237);
3019 transition->set("combine", 1);
3020 field->plant_transition(*transition, 1, ct);
3021 //mlt_service_unlock(m_mltConsumer->get_service());
3022 mlt_service_unlock(service.get_service());
3023 //tractor.multitrack()->refresh();
3024 //tractor.refresh();
3026 blockSignals(false);
3030 void Render::mltDeleteTrack(int ix)
3033 doc.setContent(sceneList(), false);
3034 int tracksCount = doc.elementsByTagName("track").count() - 1;
3035 QDomNode track = doc.elementsByTagName("track").at(ix);
3036 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3037 QDomNodeList transitions = doc.elementsByTagName("transition");
3038 for (int i = 0; i < transitions.count(); i++) {
3039 QDomElement e = transitions.at(i).toElement();
3040 QDomNodeList props = e.elementsByTagName("property");
3041 QMap <QString, QString> mappedProps;
3042 for (int j = 0; j < props.count(); j++) {
3043 QDomElement f = props.at(j).toElement();
3044 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3046 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3047 tractor.removeChild(transitions.at(i));
3049 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3050 // Transition needs to be moved
3051 int a_track = mappedProps.value("a_track").toInt();
3052 int b_track = mappedProps.value("b_track").toInt();
3053 if (a_track > 0 && a_track >= ix) a_track --;
3054 if (b_track > 0 && b_track >= ix) b_track --;
3055 for (int j = 0; j < props.count(); j++) {
3056 QDomElement f = props.at(j).toElement();
3057 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3058 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3063 tractor.removeChild(track);
3064 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3065 setSceneList(doc.toString(), m_framePosition);
3070 void Render::updatePreviewSettings()
3072 kDebug() << "////// RESTARTING CONSUMER";
3073 if (!m_mltConsumer || !m_mltProducer) return;
3074 if (m_mltProducer->get_playtime() == 0) return;
3075 Mlt::Service service(m_mltProducer->parent().get_service());
3076 if (service.type() != tractor_type) return;
3078 //m_mltConsumer->set("refresh", 0);
3079 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3080 m_mltConsumer->purge();
3081 QString scene = sceneList();
3083 if (m_mltProducer) {
3084 pos = m_mltProducer->position();
3085 delete m_mltProducer;
3087 m_mltProducer = NULL;
3088 setSceneList(scene, pos);
3091 #include "renderer.moc"