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(300);
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 void Render::setDropFrames(bool show)
1246 if (m_mltConsumer) {
1248 if (show == false) dropFrames = 0;
1249 m_mltConsumer->stop();
1250 m_mltConsumer->set("play.real_time", dropFrames);
1251 m_mltConsumer->start();
1255 double Render::playSpeed()
1257 if (m_mltProducer) return m_mltProducer->get_speed();
1261 GenTime Render::seekPosition() const
1263 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1264 else return GenTime();
1268 const QString & Render::rendererName() const
1274 void Render::emitFrameNumber(double position)
1276 m_framePosition = position;
1277 emit rendererPosition((int) position);
1278 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1281 void Render::emitConsumerStopped()
1283 // This is used to know when the playing stopped
1284 if (m_mltProducer) {
1285 double pos = m_mltProducer->position();
1286 if (m_isLoopMode) play(m_loopStart);
1287 else if (m_isZoneMode) resetZoneMode();
1288 emit rendererStopped((int) pos);
1289 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1290 //new QCustomEvent(10002));
1296 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1298 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1302 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1304 if (!m_mltProducer) {
1305 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1309 //int height = 1080;//KdenliveSettings::defaultheight();
1310 //int width = 1940; //KdenliveSettings::displaywidth();
1312 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1314 QPixmap pix(width, height);
1315 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1316 m_convert.set("forced", mlt_image_rgb24a);
1317 m_mltProducer->attach(m_convert);
1318 Mlt::Frame * frame = m_mltProducer->get_frame();
1319 m_mltProducer->detach(m_convert);
1321 pix = frameThumbnail(frame, width, height);
1324 pix.save(url.path(), "PNG");
1325 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1328 /** MLT PLAYLIST DIRECT MANIPULATON **/
1331 void Render::mltCheckLength()
1333 //kDebug()<<"checking track length: "<<track<<"..........";
1335 Mlt::Service service(m_mltProducer->get_service());
1336 Mlt::Tractor tractor(service);
1338 int trackNb = tractor.count();
1342 Mlt::Producer trackProducer(tractor.track(0));
1343 duration = trackProducer.get_playtime() - 1;
1344 m_mltProducer->set("out", duration);
1345 emit durationChanged(duration);
1348 while (trackNb > 1) {
1349 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1350 trackDuration = trackProducer.get_playtime() - 1;
1352 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1353 if (trackDuration > duration) duration = trackDuration;
1357 Mlt::Producer blackTrackProducer(tractor.track(0));
1359 if (blackTrackProducer.get_playtime() - 1 != duration) {
1360 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1361 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1362 if (duration > m_blackClip->get_length()) {
1363 m_blackClip->set("length", duration);
1364 if (blackclip) blackclip->set("length", duration);
1366 if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
1367 blackTrackPlaylist.clear();
1368 blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
1369 } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1371 m_mltProducer->set("out", duration);
1372 emit durationChanged(duration);
1376 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1378 if (m_mltProducer == NULL) {
1379 kDebug() << "PLAYLIST NOT INITIALISED //////";
1382 Mlt::Producer parentProd(m_mltProducer->parent());
1383 if (parentProd.get_producer() == NULL) {
1384 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1388 Mlt::Service service(parentProd.get_service());
1389 Mlt::Tractor tractor(service);
1390 if (info.track > tractor.count() - 1) {
1391 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1394 mlt_service_lock(service.get_service());
1395 Mlt::Producer trackProducer(tractor.track(info.track));
1396 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1397 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1399 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1400 // We want a slowmotion producer
1401 double speed = element.attribute("speed", "1.0").toDouble();
1402 QString url = QString::fromUtf8(prod->get("resource"));
1403 url.append('?' + QString::number(speed));
1404 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1405 if (!slowprod || slowprod->get_producer() == NULL) {
1406 char *tmp = decodedString(url);
1407 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1409 QString id = prod->get("id");
1410 if (id.contains('_')) id = id.section('_', 0, 0);
1411 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1412 tmp = decodedString(producerid);
1413 slowprod->set("id", tmp);
1415 m_slowmotionProducers.insert(url, slowprod);
1420 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1421 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1423 /*if (QString(prod->get("transparency")).toInt() == 1)
1424 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1426 mlt_service_unlock(service.get_service());
1428 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1429 //tractor.multitrack()->refresh();
1430 //tractor.refresh();
1434 void Render::mltCutClip(int track, GenTime position)
1439 Mlt::Service service(m_mltProducer->parent().get_service());
1440 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1442 Mlt::Tractor tractor(service);
1443 Mlt::Producer trackProducer(tractor.track(track));
1444 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1447 /* // Display playlist info
1448 kDebug()<<"//////////// BEFORE";
1449 for (int i = 0; i < trackPlaylist.count(); i++) {
1450 int blankStart = trackPlaylist.clip_start(i);
1451 int blankDuration = trackPlaylist.clip_length(i) - 1;
1453 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1454 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1457 int cutPos = (int) position.frames(m_fps);
1459 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1460 if (trackPlaylist.is_blank(clipIndex)) {
1461 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1462 m_isBlocked = false;
1465 mlt_service_lock(service.get_service());
1466 int clipStart = trackPlaylist.clip_start(clipIndex);
1467 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1468 mlt_service_unlock(service.get_service());
1470 // duplicate effects
1471 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1472 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1474 if (original == NULL || clip == NULL) {
1475 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1477 Mlt::Service clipService(original->get_service());
1478 Mlt::Service dupService(clip->get_service());
1480 Mlt::Filter *filter = clipService.filter(ct);
1482 // Only duplicate Kdenlive filters, and skip the fade in effects
1483 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1484 // looks like there is no easy way to duplicate a filter,
1485 // so we will create a new one and duplicate its properties
1486 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1487 if (dup && dup->is_valid()) {
1488 Mlt::Properties entries(filter->get_properties());
1489 for (int i = 0;i < entries.count();i++) {
1490 dup->set(entries.get_name(i), entries.get(i));
1492 dupService.attach(*dup);
1496 filter = clipService.filter(ct);
1499 /* // Display playlist info
1500 kDebug()<<"//////////// AFTER";
1501 for (int i = 0; i < trackPlaylist.count(); i++) {
1502 int blankStart = trackPlaylist.clip_start(i);
1503 int blankDuration = trackPlaylist.clip_length(i) - 1;
1505 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1506 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1509 m_isBlocked = false;
1512 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1515 mltRemoveClip(info.track, info.startPos);
1516 mltInsertClip(info, element, prod);
1520 bool Render::mltRemoveClip(int track, GenTime position)
1522 Mlt::Service service(m_mltProducer->parent().get_service());
1523 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1525 Mlt::Tractor tractor(service);
1526 mlt_service_lock(service.get_service());
1527 Mlt::Producer trackProducer(tractor.track(track));
1528 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1529 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1531 /* // Display playlist info
1532 kDebug()<<"//// BEFORE";
1533 for (int i = 0; i < trackPlaylist.count(); i++) {
1534 int blankStart = trackPlaylist.clip_start(i);
1535 int blankDuration = trackPlaylist.clip_length(i) - 1;
1537 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1538 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1540 if (trackPlaylist.is_blank(clipIndex)) {
1541 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1545 trackPlaylist.replace_with_blank(clipIndex);
1546 trackPlaylist.consolidate_blanks(0);
1547 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1548 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1550 /* // Display playlist info
1551 kDebug()<<"//// AFTER";
1552 for (int i = 0; i < trackPlaylist.count(); i++) {
1553 int blankStart = trackPlaylist.clip_start(i);
1554 int blankDuration = trackPlaylist.clip_length(i) - 1;
1556 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1557 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1559 mlt_service_unlock(service.get_service());
1560 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1561 m_isBlocked = false;
1565 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1567 if (!m_mltProducer) {
1568 kDebug() << "PLAYLIST NOT INITIALISED //////";
1571 Mlt::Producer parentProd(m_mltProducer->parent());
1572 if (parentProd.get_producer() == NULL) {
1573 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1577 Mlt::Service service(parentProd.get_service());
1578 Mlt::Tractor tractor(service);
1579 int insertPos = pos.frames(m_fps);
1581 Mlt::Producer trackProducer(tractor.track(track));
1582 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1583 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1584 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1585 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1586 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1589 int Render::mltTrackDuration(int track)
1591 if (!m_mltProducer) {
1592 kDebug() << "PLAYLIST NOT INITIALISED //////";
1595 Mlt::Producer parentProd(m_mltProducer->parent());
1596 if (parentProd.get_producer() == NULL) {
1597 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1601 Mlt::Service service(parentProd.get_service());
1602 Mlt::Tractor tractor(service);
1604 Mlt::Producer trackProducer(tractor.track(track));
1605 return trackProducer.get_playtime() - 1;
1608 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1610 if (!m_mltProducer) {
1611 kDebug() << "PLAYLIST NOT INITIALISED //////";
1614 Mlt::Producer parentProd(m_mltProducer->parent());
1615 if (parentProd.get_producer() == NULL) {
1616 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1619 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1620 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1622 Mlt::Service service(parentProd.get_service());
1623 Mlt::Tractor tractor(service);
1624 mlt_service_lock(service.get_service());
1625 int diff = duration.frames(m_fps);
1626 int offset = timeOffset.frames(m_fps);
1630 // insert space in one track only
1631 Mlt::Producer trackProducer(tractor.track(track));
1632 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1633 insertPos = trackClipStartList.value(track);
1634 if (insertPos != -1) {
1635 insertPos += offset;
1636 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1637 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1639 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1640 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1641 int position = trackPlaylist.clip_start(clipIndex);
1642 trackPlaylist.remove_region(position, - diff - 1);
1644 trackPlaylist.consolidate_blanks(0);
1646 // now move transitions
1647 mlt_service serv = m_mltProducer->parent().get_service();
1648 mlt_service nextservice = mlt_service_get_producer(serv);
1649 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1650 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1651 QString resource = mlt_properties_get(properties, "mlt_service");
1653 while (mlt_type == "transition") {
1654 mlt_transition tr = (mlt_transition) nextservice;
1655 int currentTrack = mlt_transition_get_b_track(tr);
1656 int currentIn = (int) mlt_transition_get_in(tr);
1657 int currentOut = (int) mlt_transition_get_out(tr);
1658 insertPos = trackTransitionStartList.value(track);
1659 if (insertPos != -1) {
1660 insertPos += offset;
1661 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1662 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1665 nextservice = mlt_service_producer(nextservice);
1666 if (nextservice == NULL) break;
1667 properties = MLT_SERVICE_PROPERTIES(nextservice);
1668 mlt_type = mlt_properties_get(properties, "mlt_type");
1669 resource = mlt_properties_get(properties, "mlt_service");
1672 int trackNb = tractor.count();
1673 while (trackNb > 1) {
1674 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1675 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1678 //int clipNb = trackPlaylist.count();
1679 insertPos = trackClipStartList.value(trackNb - 1);
1680 if (insertPos != -1) {
1681 insertPos += offset;
1683 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1684 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1685 for (int i = 0; i < clipNb; i++) {
1686 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1687 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1688 kDebug()<<"-------------";
1690 kDebug()<<"END-------------";*/
1693 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1694 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1696 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1697 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1698 int position = trackPlaylist.clip_start(clipIndex);
1699 trackPlaylist.remove_region(position, - diff - 1);
1701 trackPlaylist.consolidate_blanks(0);
1705 // now move transitions
1706 mlt_service serv = m_mltProducer->parent().get_service();
1707 mlt_service nextservice = mlt_service_get_producer(serv);
1708 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1709 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1710 QString resource = mlt_properties_get(properties, "mlt_service");
1712 while (mlt_type == "transition") {
1713 mlt_transition tr = (mlt_transition) nextservice;
1714 int currentIn = (int) mlt_transition_get_in(tr);
1715 int currentOut = (int) mlt_transition_get_out(tr);
1716 int currentTrack = mlt_transition_get_b_track(tr);
1717 insertPos = trackTransitionStartList.value(currentTrack);
1718 if (insertPos != -1) {
1719 insertPos += offset;
1720 if (currentOut > insertPos && resource != "mix") {
1721 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1724 nextservice = mlt_service_producer(nextservice);
1725 if (nextservice == NULL) break;
1726 properties = MLT_SERVICE_PROPERTIES(nextservice);
1727 mlt_type = mlt_properties_get(properties, "mlt_type");
1728 resource = mlt_properties_get(properties, "mlt_service");
1731 mlt_service_unlock(service.get_service());
1733 m_mltConsumer->set("refresh", 1);
1736 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1740 Mlt::Service service(m_mltProducer->parent().get_service());
1741 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1742 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1743 Mlt::Tractor tractor(service);
1744 Mlt::Producer trackProducer(tractor.track(info.track));
1745 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1746 int startPos = info.startPos.frames(m_fps);
1747 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1748 int clipLength = trackPlaylist.clip_length(clipIndex);
1750 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1754 if (!clip->is_valid() || clip->is_blank()) {
1759 Mlt::Producer clipparent = clip->parent();
1760 if (!clipparent.is_valid() || clipparent.is_blank()) {
1766 QString serv = clipparent.get("mlt_service");
1767 QString id = clipparent.get("id");
1768 //kDebug() << "CLIP SERVICE: " << serv;
1769 if (serv == "avformat" && speed != 1.0) {
1770 mlt_service_lock(service.get_service());
1771 QString url = QString::fromUtf8(clipparent.get("resource"));
1772 url.append('?' + QString::number(speed));
1773 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1774 if (!slowprod || slowprod->get_producer() == NULL) {
1775 char *tmp = decodedString(url);
1776 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1778 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1779 tmp = decodedString(producerid);
1780 slowprod->set("id", tmp);
1782 m_slowmotionProducers.insert(url, slowprod);
1784 trackPlaylist.replace_with_blank(clipIndex);
1785 trackPlaylist.consolidate_blanks(0);
1786 // Check that the blank space is long enough for our new duration
1787 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1788 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1790 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1791 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1792 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1793 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1794 trackPlaylist.insert_at(startPos, *cut, 1);
1795 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1796 newLength = trackPlaylist.clip_length(clipIndex);
1797 mlt_service_unlock(service.get_service());
1798 } else if (speed == 1.0) {
1799 mlt_service_lock(service.get_service());
1801 trackPlaylist.replace_with_blank(clipIndex);
1802 trackPlaylist.consolidate_blanks(0);
1804 // Check that the blank space is long enough for our new duration
1805 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1806 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1809 GenTime oldDuration = GenTime(clipLength, m_fps);
1810 GenTime newDuration = oldDuration * oldspeed;
1811 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1812 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1813 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1814 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1815 trackPlaylist.insert_at(startPos, *cut, 1);
1816 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1817 newLength = trackPlaylist.clip_length(clipIndex);
1818 mlt_service_unlock(service.get_service());
1820 } else if (serv == "framebuffer") {
1821 mlt_service_lock(service.get_service());
1822 QString url = QString::fromUtf8(clipparent.get("resource"));
1823 url = url.section('?', 0, 0);
1824 url.append('?' + QString::number(speed));
1825 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1826 if (!slowprod || slowprod->get_producer() == NULL) {
1827 char *tmp = decodedString(url);
1828 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1830 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1831 tmp = decodedString(producerid);
1832 slowprod->set("id", tmp);
1834 m_slowmotionProducers.insert(url, slowprod);
1836 trackPlaylist.replace_with_blank(clipIndex);
1837 trackPlaylist.consolidate_blanks(0);
1839 GenTime oldDuration = GenTime(clipLength, m_fps);
1840 GenTime newDuration = oldDuration * oldspeed / speed;
1842 // Check that the blank space is long enough for our new duration
1843 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1844 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1847 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1848 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1849 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1850 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1852 trackPlaylist.insert_at(startPos, *cut, 1);
1853 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1854 newLength = trackPlaylist.clip_length(clipIndex);
1856 mlt_service_unlock(service.get_service());
1858 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1859 m_isBlocked = false;
1863 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1865 kDebug() << "// TRYing to remove effect at: " << index;
1866 Mlt::Service service(m_mltProducer->parent().get_service());
1867 bool success = false;
1868 Mlt::Tractor tractor(service);
1869 Mlt::Producer trackProducer(tractor.track(track));
1870 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1871 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1872 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1874 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1877 Mlt::Service clipService(clip->get_service());
1878 // if (tag.startsWith("ladspa")) tag = "ladspa";
1881 Mlt::Filter *filter = clipService.filter(ct);
1883 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1884 if (clipService.detach(*filter) == 0) success = true;
1885 kDebug() << " / / / DLEETED EFFECT: " << ct;
1886 } else if (updateIndex) {
1887 // Adjust the other effects index
1888 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1891 filter = clipService.filter(ct);
1893 m_isBlocked = false;
1894 if (doRefresh) refresh();
1899 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1902 Mlt::Service service(m_mltProducer->parent().get_service());
1904 Mlt::Tractor tractor(service);
1905 Mlt::Producer trackProducer(tractor.track(track));
1906 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1908 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1912 Mlt::Service clipService(clip->get_service());
1915 // temporarily remove all effects after insert point
1916 QList <Mlt::Filter *> filtersList;
1917 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1919 Mlt::Filter *filter = clipService.filter(ct);
1921 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1922 filtersList.append(filter);
1923 clipService.detach(*filter);
1925 filter = clipService.filter(ct);
1929 QString tag = params.paramValue("tag");
1930 kDebug() << " / / INSERTING EFFECT: " << tag;
1931 if (tag.startsWith("ladspa")) tag = "ladspa";
1932 char *filterTag = decodedString(tag);
1933 char *filterId = decodedString(params.paramValue("id"));
1934 QHash<QString, QString>::Iterator it;
1935 QString kfr = params.paramValue("keyframes");
1937 if (!kfr.isEmpty()) {
1938 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1939 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1940 char *starttag = decodedString(params.paramValue("starttag", "start"));
1941 char *endtag = decodedString(params.paramValue("endtag", "end"));
1942 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1943 int duration = clip->get_playtime();
1944 //double max = params.paramValue("max").toDouble();
1945 double min = params.paramValue("min").toDouble();
1946 double factor = params.paramValue("factor", "1").toDouble();
1947 params.removeParam("starttag");
1948 params.removeParam("endtag");
1949 params.removeParam("keyframes");
1950 params.removeParam("min");
1951 params.removeParam("max");
1952 params.removeParam("factor");
1954 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1955 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1956 if (filter && filter->is_valid()) {
1957 filter->set("kdenlive_id", filterId);
1958 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1959 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1960 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1961 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1962 if (x2 == -1) x2 = duration;
1964 for (int j = 0; j < params.count(); j++) {
1965 char *name = decodedString(params.at(j).name());
1966 char *value = decodedString(params.at(j).value());
1967 filter->set(name, value);
1972 filter->set("in", x1);
1973 filter->set("out", x2);
1974 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1975 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1976 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1977 clipService.attach(*filter);
1984 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1985 if (filter && filter->is_valid())
1986 filter->set("kdenlive_id", filterId);
1988 kDebug() << "filter is NULL";
1989 m_isBlocked = false;
1993 params.removeParam("kdenlive_id");
1995 for (int j = 0; j < params.count(); j++) {
1996 char *name = decodedString(params.at(j).name());
1997 char *value = decodedString(params.at(j).value());
1998 filter->set(name, value);
2004 QString effectArgs = params.paramValue("id").section('_', 1);
2006 params.removeParam("id");
2007 params.removeParam("kdenlive_ix");
2008 params.removeParam("tag");
2009 params.removeParam("disabled");
2011 for (int j = 0; j < params.count(); j++) {
2012 effectArgs.append(' ' + params.at(j).value());
2014 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2015 char *value = decodedString(effectArgs.simplified());
2016 filter->set("effect", value);
2021 // attach filter to the clip
2022 clipService.attach(*filter);
2027 // re-add following filters
2028 for (int i = 0; i < filtersList.count(); i++) {
2029 clipService.attach(*(filtersList.at(i)));
2032 m_isBlocked = false;
2033 if (doRefresh) refresh();
2037 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2039 QString index = params.paramValue("kdenlive_ix");
2040 QString tag = params.paramValue("tag");
2042 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2043 // This is a keyframe effect, to edit it, we remove it and re-add it.
2044 mltRemoveEffect(track, position, index, true);
2045 bool success = mltAddEffect(track, position, params);
2050 Mlt::Service service(m_mltProducer->parent().get_service());
2052 Mlt::Tractor tractor(service);
2053 Mlt::Producer trackProducer(tractor.track(track));
2054 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2055 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2056 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2058 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2061 Mlt::Service clipService(clip->get_service());
2064 Mlt::Filter *filter = clipService.filter(ct);
2066 if (filter->get("kdenlive_ix") == index) {
2070 filter = clipService.filter(ct);
2074 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2075 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2077 filter = clipService.filter(ct);
2078 QList <Mlt::Filter *> filtersList;
2080 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2081 filtersList.append(filter);
2082 clipService.detach(*filter);
2084 filter = clipService.filter(ct);
2086 bool success = mltAddEffect(track, position, params);
2088 for (int i = 0; i < filtersList.count(); i++) {
2089 clipService.attach(*(filtersList.at(i)));
2092 m_isBlocked = false;
2096 for (int j = 0; j < params.count(); j++) {
2097 char *name = decodedString(params.at(j).name());
2098 char *value = decodedString(params.at(j).value());
2099 filter->set(name, value);
2104 m_isBlocked = false;
2109 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2112 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2113 Mlt::Service service(m_mltProducer->parent().get_service());
2115 Mlt::Tractor tractor(service);
2116 Mlt::Producer trackProducer(tractor.track(track));
2117 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2118 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2119 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2121 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2124 Mlt::Service clipService(clip->get_service());
2127 QList <Mlt::Filter *> filtersList;
2128 Mlt::Filter *filter = clipService.filter(ct);
2130 if (newPos > oldPos) {
2132 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2133 filter->set("kdenlive_ix", newPos);
2134 filtersList.append(filter);
2135 clipService.detach(*filter);
2136 filter = clipService.filter(ct);
2137 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2138 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2140 filter = clipService.filter(ct);
2144 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2145 filtersList.append(filter);
2146 clipService.detach(*filter);
2148 filter = clipService.filter(ct);
2152 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2153 filter->set("kdenlive_ix", newPos);
2154 filtersList.append(filter);
2155 clipService.detach(*filter);
2157 filter = clipService.filter(ct);
2161 filter = clipService.filter(ct);
2163 int pos = QString(filter->get("kdenlive_ix")).toInt();
2164 if (pos >= newPos) {
2165 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2166 filtersList.append(filter);
2167 clipService.detach(*filter);
2169 filter = clipService.filter(ct);
2173 for (int i = 0; i < filtersList.count(); i++) {
2174 clipService.attach(*(filtersList.at(i)));
2177 m_isBlocked = false;
2181 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2184 Mlt::Service service(m_mltProducer->parent().get_service());
2185 Mlt::Tractor tractor(service);
2186 Mlt::Producer trackProducer(tractor.track(info.track));
2187 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2189 /* // Display playlist info
2190 kDebug()<<"//////////// BEFORE RESIZE";
2191 for (int i = 0; i < trackPlaylist.count(); i++) {
2192 int blankStart = trackPlaylist.clip_start(i);
2193 int blankDuration = trackPlaylist.clip_length(i) - 1;
2195 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2196 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2199 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2200 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2201 m_isBlocked = false;
2204 mlt_service_lock(service.get_service());
2205 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2206 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2207 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2208 int previousStart = clip->get_in();
2209 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2210 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2211 if (newDuration > clip->get_length()) {
2212 clip->parent().set("length", newDuration + 1);
2213 clip->set("length", newDuration + 1);
2215 if (newDuration > clip->get_out()) {
2216 clip->parent().set_in_and_out(0, newDuration + 1);
2217 clip->set_in_and_out(0, newDuration + 1);
2220 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2221 trackPlaylist.consolidate_blanks(0);
2222 // skip to next clip
2224 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2226 // clip was made longer, trim next blank if there is one.
2227 if (clipIndex < trackPlaylist.count()) {
2228 // If this is not the last clip in playlist
2229 if (trackPlaylist.is_blank(clipIndex)) {
2230 int blankStart = trackPlaylist.clip_start(clipIndex);
2231 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2232 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2233 if (diff - blankDuration == 1) {
2234 trackPlaylist.remove(clipIndex);
2235 } else trackPlaylist.remove_region(blankStart, diff - 1);
2237 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2240 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2241 trackPlaylist.consolidate_blanks(0);
2242 mlt_service_unlock(service.get_service());
2244 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2245 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2246 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2247 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2248 ItemInfo transpinfo;
2249 transpinfo.startPos = info.startPos;
2250 transpinfo.endPos = info.startPos + clipDuration;
2251 transpinfo.track = info.track;
2252 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2254 m_isBlocked = false;
2255 m_mltConsumer->set("refresh", 1);
2259 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2261 Mlt::Service service(m_mltProducer->parent().get_service());
2262 Mlt::Tractor tractor(service);
2263 Mlt::Producer trackProducer(tractor.track(track));
2266 if (blind) trackProducer.set("hide", 3);
2267 else trackProducer.set("hide", 2);
2269 trackProducer.set("hide", 1);
2271 trackProducer.set("hide", 0);
2273 tractor.multitrack()->refresh();
2279 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2281 Mlt::Service service(m_mltProducer->parent().get_service());
2282 int frameOffset = (int) diff.frames(m_fps);
2283 Mlt::Tractor tractor(service);
2284 Mlt::Producer trackProducer(tractor.track(info.track));
2285 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2286 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2287 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2290 mlt_service_lock(service.get_service());
2291 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2292 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2294 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2295 mlt_service_unlock(service.get_service());
2298 int previousStart = clip->get_in();
2300 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2302 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2303 m_isBlocked = false;
2304 mlt_service_unlock(service.get_service());
2305 m_mltConsumer->set("refresh", 1);
2309 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2311 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2312 Mlt::Service service(m_mltProducer->parent().get_service());
2313 int moveFrame = (int) diff.frames(m_fps);
2314 Mlt::Tractor tractor(service);
2315 Mlt::Producer trackProducer(tractor.track(info.track));
2316 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2317 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2318 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2321 mlt_service_lock(service.get_service());
2322 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2323 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2325 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2326 mlt_service_unlock(service.get_service());
2329 int previousStart = clip->get_in();
2331 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2333 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2334 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2335 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2337 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2338 int blankIndex = clipIndex - 1;
2339 int blankLength = trackPlaylist.clip_length(blankIndex);
2340 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2341 if (! trackPlaylist.is_blank(blankIndex)) {
2342 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2344 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2345 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2347 trackPlaylist.consolidate_blanks(0);
2348 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2349 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2350 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2351 ItemInfo transpinfo;
2352 transpinfo.startPos = info.startPos + diff;
2353 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2354 transpinfo.track = info.track;
2355 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2357 m_isBlocked = false;
2358 //m_mltConsumer->set("refresh", 1);
2359 mlt_service_unlock(service.get_service());
2360 m_mltConsumer->set("refresh", 1);
2364 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2366 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2370 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2372 if (prod == NULL || !prod->is_valid()) {
2373 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2376 kDebug() << "NEW PROD ID: " << prod->get("id");
2378 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2379 mlt_service_lock(m_mltConsumer->get_service());
2380 Mlt::Service service(m_mltProducer->parent().get_service());
2381 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2383 Mlt::Tractor tractor(service);
2384 Mlt::Producer trackProducer(tractor.track(track));
2385 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2386 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2387 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2388 if (clipProducer.is_blank()) {
2389 kDebug() << "// ERROR UPDATING CLIP PROD";
2390 mlt_service_unlock(m_mltConsumer->get_service());
2394 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2396 // move all effects to the correct producer
2397 Mlt::Service clipService(clipProducer.get_service());
2398 Mlt::Service newClipService(clip->get_service());
2401 Mlt::Filter *filter = clipService.filter(ct);
2403 if (filter->get("kdenlive_ix") != 0) {
2404 clipService.detach(*filter);
2405 newClipService.attach(*filter);
2407 filter = clipService.filter(ct);
2410 trackPlaylist.insert_at(pos, clip, 1);
2411 mlt_service_unlock(m_mltConsumer->get_service());
2415 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2419 Mlt::Service service(m_mltProducer->parent().get_service());
2420 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2422 Mlt::Tractor tractor(service);
2423 mlt_service_lock(service.get_service());
2424 Mlt::Producer trackProducer(tractor.track(startTrack));
2425 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2426 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2427 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2428 bool checkLength = false;
2429 if (endTrack == startTrack) {
2430 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2431 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2432 // error, destination is not empty
2433 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2434 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2435 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2436 mlt_service_unlock(service.get_service());
2440 trackPlaylist.consolidate_blanks(0);
2441 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2442 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2443 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2445 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2447 //mlt_service_unlock(service.get_service());
2449 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2450 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2451 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2452 // error, destination is not empty
2453 mlt_service_unlock(service.get_service());
2457 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2458 if (clipProducer.is_blank()) {
2459 // error, destination is not empty
2460 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2461 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2462 mlt_service_unlock(service.get_service());
2466 trackPlaylist.consolidate_blanks(0);
2467 destTrackPlaylist.consolidate_blanks(1);
2468 Mlt::Producer *clip;
2469 // check if we are moving a slowmotion producer
2470 QString serv = clipProducer.parent().get("mlt_service");
2471 QString currentid = clipProducer.parent().get("id");
2472 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2473 clip = &clipProducer;
2476 // Special case: prod is null when using placeholder clips.
2477 // in that case, use the producer existing in playlist. Note that
2478 // it will bypass the one producer per track logic and might cause
2479 // Sound cracks if clip is moved so that it overlaps another copy of itself
2480 clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
2481 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2484 // move all effects to the correct producer
2485 Mlt::Service clipService(clipProducer.get_service());
2486 Mlt::Service newClipService(clip->get_service());
2489 Mlt::Filter *filter = clipService.filter(ct);
2491 if (filter->get("kdenlive_ix") != 0) {
2492 clipService.detach(*filter);
2493 newClipService.attach(*filter);
2495 filter = clipService.filter(ct);
2498 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2499 destTrackPlaylist.consolidate_blanks(0);
2500 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2501 kDebug() << "//////// moving clip transparency";
2502 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2504 if (clipIndex > trackPlaylist.count()) checkLength = true;
2505 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2508 mlt_service_unlock(service.get_service());
2509 if (checkLength) mltCheckLength();
2512 //m_mltConsumer->set("refresh", 1);
2516 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2518 int new_in = (int)newIn.frames(m_fps);
2519 int new_out = (int)newOut.frames(m_fps) - 1;
2520 if (new_in >= new_out) return false;
2522 mlt_service serv = m_mltProducer->parent().get_service();
2524 mlt_service_lock(serv);
2525 //m_mltConsumer->set("refresh", 0);
2528 mlt_service nextservice = mlt_service_get_producer(serv);
2529 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2530 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2531 QString resource = mlt_properties_get(properties, "mlt_service");
2532 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2534 while (mlt_type == "transition") {
2535 mlt_transition tr = (mlt_transition) nextservice;
2536 int currentTrack = mlt_transition_get_b_track(tr);
2537 int currentIn = (int) mlt_transition_get_in(tr);
2538 int currentOut = (int) mlt_transition_get_out(tr);
2540 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2541 mlt_transition_set_in_and_out(tr, new_in, new_out);
2542 if (newTrack - startTrack != 0) {
2543 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2545 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2546 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2547 mlt_properties_set_int(properties, "b_track", newTrack);
2548 //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);
2552 nextservice = mlt_service_producer(nextservice);
2553 if (nextservice == NULL) break;
2554 properties = MLT_SERVICE_PROPERTIES(nextservice);
2555 mlt_type = mlt_properties_get(properties, "mlt_type");
2556 resource = mlt_properties_get(properties, "mlt_service");
2558 mlt_service_unlock(serv);
2561 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2565 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2567 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2569 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2570 mltAddTransition(tag, a_track, b_track, in, out, xml);
2572 //mltSavePlaylist();
2575 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2577 mlt_service serv = m_mltProducer->parent().get_service();
2578 mlt_service_lock(serv);
2582 mlt_service nextservice = mlt_service_get_producer(serv);
2583 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2584 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2585 QString resource = mlt_properties_get(properties, "mlt_service");
2586 int in_pos = (int) in.frames(m_fps);
2587 int out_pos = (int) out.frames(m_fps) - 1;
2589 while (mlt_type == "transition") {
2590 mlt_transition tr = (mlt_transition) nextservice;
2591 int currentTrack = mlt_transition_get_b_track(tr);
2592 int currentBTrack = mlt_transition_get_a_track(tr);
2593 int currentIn = (int) mlt_transition_get_in(tr);
2594 int currentOut = (int) mlt_transition_get_out(tr);
2596 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2598 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2599 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2600 QMap<QString, QString>::Iterator it;
2602 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2603 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2604 if (currentBTrack != a_track) {
2605 mlt_properties_set_int(properties, "a_track", a_track);
2607 for (it = map.begin(); it != map.end(); ++it) {
2609 char *name = decodedString(key);
2610 char *value = decodedString(it.value());
2611 mlt_properties_set(transproperties, name, value);
2612 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2613 //filter->set("kdenlive_id", id);
2619 nextservice = mlt_service_producer(nextservice);
2620 if (nextservice == NULL) break;
2621 properties = MLT_SERVICE_PROPERTIES(nextservice);
2622 mlt_type = mlt_properties_get(properties, "mlt_type");
2623 resource = mlt_properties_get(properties, "mlt_service");
2625 mlt_service_unlock(serv);
2628 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2631 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2633 mlt_service serv = m_mltProducer->parent().get_service();
2635 mlt_service_lock(serv);
2637 Mlt::Service service(serv);
2638 Mlt::Tractor tractor(service);
2639 Mlt::Field *field = tractor.field();
2641 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2643 mlt_service nextservice = mlt_service_get_producer(serv);
2644 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2645 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2646 QString resource = mlt_properties_get(properties, "mlt_service");
2648 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2649 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2651 while (mlt_type == "transition") {
2652 mlt_transition tr = (mlt_transition) nextservice;
2653 int currentTrack = mlt_transition_get_b_track(tr);
2654 int currentIn = (int) mlt_transition_get_in(tr);
2655 int currentOut = (int) mlt_transition_get_out(tr);
2656 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2658 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2659 mlt_field_disconnect_service(field->get_field(), nextservice);
2662 nextservice = mlt_service_producer(nextservice);
2663 if (nextservice == NULL) break;
2664 properties = MLT_SERVICE_PROPERTIES(nextservice);
2665 mlt_type = mlt_properties_get(properties, "mlt_type");
2666 resource = mlt_properties_get(properties, "mlt_service");
2668 mlt_service_unlock(serv);
2671 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2674 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2676 QDomNodeList attribs = xml.elementsByTagName("parameter");
2677 QMap<QString, QString> map;
2678 for (int i = 0;i < attribs.count();i++) {
2679 QDomElement e = attribs.item(i).toElement();
2680 QString name = e.attribute("name");
2681 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2682 map[name] = e.attribute("default");
2683 if (!e.attribute("value").isEmpty()) {
2684 map[name] = e.attribute("value");
2686 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2687 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2688 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2691 if (e.attribute("namedesc").contains(';')) {
2692 QString format = e.attribute("format");
2693 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2694 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2696 QTextStream txtNeu(&neu);
2697 if (values.size() > 0)
2698 txtNeu << (int)values[0].toDouble();
2700 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2701 txtNeu << separators[i];
2702 txtNeu << (int)(values[i+1].toDouble());
2704 if (i < separators.size())
2705 txtNeu << separators[i];
2706 map[e.attribute("name")] = neu;
2713 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2715 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2716 Mlt::Service service(m_mltProducer->parent().get_service());
2717 Mlt::Tractor tractor(service);
2718 Mlt::Field *field = tractor.field();
2720 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2721 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2722 transition->set("transparency", id);
2723 transition->set("fill", 1);
2724 transition->set("internal_added", 237);
2725 field->plant_transition(*transition, transitiontrack, info.track);
2729 void Render::mltDeleteTransparency(int pos, int track, int id)
2731 Mlt::Service service(m_mltProducer->parent().get_service());
2732 Mlt::Tractor tractor(service);
2733 Mlt::Field *field = tractor.field();
2735 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2736 mlt_service serv = m_mltProducer->parent().get_service();
2738 mlt_service nextservice = mlt_service_get_producer(serv);
2739 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2740 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2741 QString resource = mlt_properties_get(properties, "mlt_service");
2743 while (mlt_type == "transition") {
2744 mlt_transition tr = (mlt_transition) nextservice;
2745 int currentTrack = mlt_transition_get_b_track(tr);
2746 int currentIn = (int) mlt_transition_get_in(tr);
2747 int currentOut = (int) mlt_transition_get_out(tr);
2748 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2749 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2751 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2752 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2753 mlt_field_disconnect_service(field->get_field(), nextservice);
2756 nextservice = mlt_service_producer(nextservice);
2757 if (nextservice == NULL) break;
2758 properties = MLT_SERVICE_PROPERTIES(nextservice);
2759 mlt_type = mlt_properties_get(properties, "mlt_type");
2760 resource = mlt_properties_get(properties, "mlt_service");
2762 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2765 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2767 Mlt::Service service(m_mltProducer->parent().get_service());
2768 Mlt::Tractor tractor(service);
2770 mlt_service_lock(service.get_service());
2771 m_mltConsumer->set("refresh", 0);
2774 mlt_service serv = m_mltProducer->parent().get_service();
2775 mlt_service nextservice = mlt_service_get_producer(serv);
2776 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2777 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2778 QString resource = mlt_properties_get(properties, "mlt_service");
2779 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2780 while (mlt_type == "transition") {
2781 mlt_transition tr = (mlt_transition) nextservice;
2782 int currentTrack = mlt_transition_get_b_track(tr);
2783 int currentIn = (int) mlt_transition_get_in(tr);
2784 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2785 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2786 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2787 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2788 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2789 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2792 nextservice = mlt_service_producer(nextservice);
2793 if (nextservice == NULL) break;
2794 properties = MLT_SERVICE_PROPERTIES(nextservice);
2795 mlt_type = mlt_properties_get(properties, "mlt_type");
2796 resource = mlt_properties_get(properties, "mlt_service");
2798 mlt_service_unlock(service.get_service());
2800 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2804 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2806 Mlt::Service service(m_mltProducer->parent().get_service());
2807 Mlt::Tractor tractor(service);
2809 mlt_service_lock(service.get_service());
2810 m_mltConsumer->set("refresh", 0);
2813 mlt_service serv = m_mltProducer->parent().get_service();
2814 mlt_service nextservice = mlt_service_get_producer(serv);
2815 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2816 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2817 QString resource = mlt_properties_get(properties, "mlt_service");
2819 while (mlt_type == "transition") {
2820 mlt_transition tr = (mlt_transition) nextservice;
2821 int currentTrack = mlt_transition_get_b_track(tr);
2822 int currentaTrack = mlt_transition_get_a_track(tr);
2823 int currentIn = (int) mlt_transition_get_in(tr);
2824 int currentOut = (int) mlt_transition_get_out(tr);
2825 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2826 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2827 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2828 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2829 kDebug() << "//////MOVING";
2830 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2831 if (endTrack != startTrack) {
2832 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2833 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2834 mlt_properties_set_int(properties, "b_track", endTrack);
2838 nextservice = mlt_service_producer(nextservice);
2839 if (nextservice == NULL) break;
2840 properties = MLT_SERVICE_PROPERTIES(nextservice);
2841 mlt_type = mlt_properties_get(properties, "mlt_type");
2842 resource = mlt_properties_get(properties, "mlt_service");
2845 mlt_service_unlock(service.get_service());
2846 m_mltConsumer->set("refresh", 1);
2850 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2852 if (in >= out) return false;
2853 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2854 Mlt::Service service(m_mltProducer->parent().get_service());
2856 Mlt::Tractor tractor(service);
2857 Mlt::Field *field = tractor.field();
2859 char *transId = decodedString(tag);
2860 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2861 if (out != GenTime())
2862 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2863 QMap<QString, QString>::Iterator it;
2865 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2866 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2867 if (xml.hasAttribute("id"))
2868 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
2870 for (it = args.begin(); it != args.end(); ++it) {
2872 char *name = decodedString(key);
2873 char *value = decodedString(it.value());
2874 if (it.value().isEmpty() == false) transition->set(name, value);
2875 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2879 // attach filter to the clip
2880 field->plant_transition(*transition, a_track, b_track);
2886 void Render::mltSavePlaylist()
2888 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2889 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2890 fileConsumer.set("resource", "/tmp/playlist.mlt");
2892 Mlt::Service service(m_mltProducer->get_service());
2894 fileConsumer.connect(service);
2895 fileConsumer.start();
2898 QList <Mlt::Producer *> Render::producersList()
2900 QList <Mlt::Producer *> prods;
2901 Mlt::Service service(m_mltProducer->parent().get_service());
2902 if (service.type() != tractor_type) return prods;
2903 Mlt::Tractor tractor(service);
2906 int trackNb = tractor.count();
2907 for (int t = 1; t < trackNb; t++) {
2908 Mlt::Producer *tt = tractor.track(t);
2909 Mlt::Producer trackProducer(tt);
2911 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2912 int clipNb = trackPlaylist.count();
2913 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2914 for (int i = 0; i < clipNb; i++) {
2915 Mlt::Producer *c = trackPlaylist.get_clip(i);
2916 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2918 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2919 ids.append(nprod->get("id"));
2920 prods.append(nprod);
2921 } else delete nprod;
2929 void Render::fillSlowMotionProducers()
2931 Mlt::Service service(m_mltProducer->parent().get_service());
2932 if (service.type() != tractor_type) return;
2934 Mlt::Tractor tractor(service);
2936 int trackNb = tractor.count();
2937 for (int t = 1; t < trackNb; t++) {
2938 Mlt::Producer *tt = tractor.track(t);
2939 Mlt::Producer trackProducer(tt);
2941 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2942 int clipNb = trackPlaylist.count();
2943 for (int i = 0; i < clipNb; i++) {
2944 Mlt::Producer *c = trackPlaylist.get_clip(i);
2945 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2947 QString id = nprod->get("id");
2948 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
2949 // this is a slowmotion producer, add it to the list
2950 QString url = QString::fromUtf8(nprod->get("resource"));
2951 if (!m_slowmotionProducers.contains(url)) {
2952 m_slowmotionProducers.insert(url, nprod);
2954 } else delete nprod;
2961 void Render::mltInsertTrack(int ix, bool videoTrack)
2966 Mlt::Service service(m_mltProducer->parent().get_service());
2967 mlt_service_lock(service.get_service());
2968 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2970 Mlt::Tractor tractor(service);
2972 Mlt::Playlist playlist;
2973 int ct = tractor.count();
2975 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
2981 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2982 tractor.set_track(playlist, pos);
2983 Mlt::Producer newProd(tractor.track(pos));
2984 if (!videoTrack) newProd.set("hide", 1);
2986 for (; pos <= ct; pos++) {
2987 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2988 tractor.set_track(*prodToMove, pos);
2989 prodToMove = prodToMove2;
2992 tractor.set_track(playlist, ix);
2993 Mlt::Producer newProd(tractor.track(ix));
2994 if (!videoTrack) newProd.set("hide", 1);
2998 mlt_service serv = m_mltProducer->parent().get_service();
2999 mlt_service nextservice = mlt_service_get_producer(serv);
3000 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3001 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3002 QString resource = mlt_properties_get(properties, "mlt_service");
3004 while (mlt_type == "transition") {
3005 if (resource != "mix") {
3006 mlt_transition tr = (mlt_transition) nextservice;
3007 int currentTrack = mlt_transition_get_b_track(tr);
3008 int currentaTrack = mlt_transition_get_a_track(tr);
3009 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3011 if (currentTrack >= ix) {
3012 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3013 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3016 nextservice = mlt_service_producer(nextservice);
3017 if (nextservice == NULL) break;
3018 properties = MLT_SERVICE_PROPERTIES(nextservice);
3019 mlt_type = mlt_properties_get(properties, "mlt_type");
3020 resource = mlt_properties_get(properties, "mlt_service");
3023 // Add audio mix transition to last track
3024 Mlt::Field *field = tractor.field();
3025 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3026 transition->set("a_track", 1);
3027 transition->set("b_track", ct);
3028 transition->set("always_active", 1);
3029 transition->set("internal_added", 237);
3030 transition->set("combine", 1);
3031 field->plant_transition(*transition, 1, ct);
3032 //mlt_service_unlock(m_mltConsumer->get_service());
3033 mlt_service_unlock(service.get_service());
3034 //tractor.multitrack()->refresh();
3035 //tractor.refresh();
3037 blockSignals(false);
3041 void Render::mltDeleteTrack(int ix)
3044 doc.setContent(sceneList(), false);
3045 int tracksCount = doc.elementsByTagName("track").count() - 1;
3046 QDomNode track = doc.elementsByTagName("track").at(ix);
3047 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3048 QDomNodeList transitions = doc.elementsByTagName("transition");
3049 for (int i = 0; i < transitions.count(); i++) {
3050 QDomElement e = transitions.at(i).toElement();
3051 QDomNodeList props = e.elementsByTagName("property");
3052 QMap <QString, QString> mappedProps;
3053 for (int j = 0; j < props.count(); j++) {
3054 QDomElement f = props.at(j).toElement();
3055 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3057 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3058 tractor.removeChild(transitions.at(i));
3060 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3061 // Transition needs to be moved
3062 int a_track = mappedProps.value("a_track").toInt();
3063 int b_track = mappedProps.value("b_track").toInt();
3064 if (a_track > 0 && a_track >= ix) a_track --;
3065 if (b_track > 0 && b_track >= ix) b_track --;
3066 for (int j = 0; j < props.count(); j++) {
3067 QDomElement f = props.at(j).toElement();
3068 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3069 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3074 tractor.removeChild(track);
3075 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3076 setSceneList(doc.toString(), m_framePosition);
3081 void Render::updatePreviewSettings()
3083 kDebug() << "////// RESTARTING CONSUMER";
3084 if (!m_mltConsumer || !m_mltProducer) return;
3085 if (m_mltProducer->get_playtime() == 0) return;
3086 Mlt::Service service(m_mltProducer->parent().get_service());
3087 if (service.type() != tractor_type) return;
3089 //m_mltConsumer->set("refresh", 0);
3090 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3091 m_mltConsumer->purge();
3092 QString scene = sceneList();
3094 if (m_mltProducer) {
3095 pos = m_mltProducer->position();
3096 delete m_mltProducer;
3098 m_mltProducer = NULL;
3099 setSceneList(scene, pos);
3102 #include "renderer.moc"