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);
553 if (!replaceProducer && xml.hasAttribute("file_hash")) {
554 // Clip already has all properties
555 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
560 int width = (int)(height * m_mltProfile->dar());
561 QMap < QString, QString > filePropertyMap;
562 QMap < QString, QString > metadataPropertyMap;
564 int frameNumber = xml.attribute("thumbnail", "0").toInt();
565 if (frameNumber != 0) producer->seek(frameNumber);
567 filePropertyMap["duration"] = QString::number(producer->get_playtime());
568 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
570 Mlt::Frame *frame = producer->get_frame();
572 if (xml.attribute("type").toInt() == SLIDESHOW) {
573 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
574 if (xml.attribute("fade") == "1") {
575 // user wants a fade effect to slideshow
576 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
577 if (filter && filter->is_valid()) {
578 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
579 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
580 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
581 char *tmp = decodedString(xml.attribute("luma_file"));
582 filter->set("luma.resource", tmp);
584 if (xml.hasAttribute("softness")) {
585 int soft = xml.attribute("softness").toInt();
586 filter->set("luma.softness", (double) soft / 100.0);
589 Mlt::Service clipService(producer->get_service());
590 clipService.attach(*filter);
596 filePropertyMap["fps"] = producer->get("source_fps");
598 if (frame && frame->is_valid()) {
599 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
600 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
601 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
602 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
604 if (frame->get_int("test_image") == 0) {
605 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
606 filePropertyMap["type"] = "playlist";
607 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
608 } else if (frame->get_int("test_audio") == 0)
609 filePropertyMap["type"] = "av";
611 filePropertyMap["type"] = "video";
613 mlt_image_format format = mlt_image_yuv422;
615 int frame_height = 0;
616 //frame->set("rescale.interp", "hyper");
617 frame->set("normalised_height", height);
618 frame->set("normalised_width", width);
619 QPixmap pix(width, height);
621 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
622 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
623 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
624 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
626 if (!image.isNull()) {
627 pix = QPixmap::fromImage(image.rgbSwapped());
631 mlt_pool_release(new_image);
632 emit replyGetImage(clipId, pix);
634 } else if (frame->get_int("test_audio") == 0) {
635 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
636 emit replyGetImage(clipId, pixmap);
637 filePropertyMap["type"] = "audio";
641 // Retrieve audio / video codec name
645 if (producer->get_int("video_index") > -1) {
646 /*if (context->duration == AV_NOPTS_VALUE) {
647 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
648 emit removeInvalidClip(clipId);
652 // Get the video_index
653 int default_video = producer->get_int("video_index");
655 int default_audio = producer->get_int("audio_index");
658 // Find maximum stream index values
659 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
660 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
661 QString type = producer->get(property);
664 else if (type == "audio")
667 filePropertyMap["default_video"] = QString::number(default_video);
668 filePropertyMap["video_max"] = QString::number(video_max);
669 filePropertyMap["default_audio"] = QString::number(default_audio);
670 filePropertyMap["audio_max"] = QString::number(audio_max);
672 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
673 if (producer->get(property)) {
674 filePropertyMap["videocodec"] = producer->get(property);
676 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
677 if (producer->get(property))
678 filePropertyMap["videocodec"] = producer->get(property);
681 if (KdenliveSettings::dropbframes()) {
682 kDebug() << "// LOOKING FOR H264 on: " << default_video;
683 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
684 kDebug() << "PROP: " << property << " = " << producer->get(property);
685 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
686 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
687 producer->set("skip_loop_filter", "all");
688 producer->set("skip_frame", "bidir");
692 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
693 if (producer->get_int("audio_index") > -1) {
694 // Get the audio_index
695 int index = producer->get_int("audio_index");
697 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
698 if (producer->get(property)) {
699 filePropertyMap["audiocodec"] = producer->get(property);
701 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
702 if (producer->get(property))
703 filePropertyMap["audiocodec"] = producer->get(property);
708 Mlt::Properties metadata;
709 metadata.pass_values(*producer, "meta.attr.");
710 int count = metadata.count();
711 for (int i = 0; i < count; i ++) {
712 QString name = metadata.get_name(i);
713 QString value = QString::fromUtf8(metadata.get(i));
714 if (name.endsWith("markup") && !value.isEmpty())
715 metadataPropertyMap[ name.section('.', 0, -2)] = value;
718 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
719 kDebug() << "REquested fuile info for: " << url.path();
721 // FIXME: should delete this to avoid a leak...
726 /** Create the producer from the MLT XML QDomDocument */
728 void Render::initSceneList()
730 kDebug() << "-------- INIT SCENE LIST ------_";
732 QDomElement mlt = doc.createElement("mlt");
733 doc.appendChild(mlt);
734 QDomElement prod = doc.createElement("producer");
735 prod.setAttribute("resource", "colour");
736 prod.setAttribute("colour", "red");
737 prod.setAttribute("id", "black");
738 prod.setAttribute("in", "0");
739 prod.setAttribute("out", "0");
741 QDomElement tractor = doc.createElement("tractor");
742 QDomElement multitrack = doc.createElement("multitrack");
744 QDomElement playlist1 = doc.createElement("playlist");
745 playlist1.appendChild(prod);
746 multitrack.appendChild(playlist1);
747 QDomElement playlist2 = doc.createElement("playlist");
748 multitrack.appendChild(playlist2);
749 QDomElement playlist3 = doc.createElement("playlist");
750 multitrack.appendChild(playlist3);
751 QDomElement playlist4 = doc.createElement("playlist");
752 multitrack.appendChild(playlist4);
753 QDomElement playlist5 = doc.createElement("playlist");
754 multitrack.appendChild(playlist5);
755 tractor.appendChild(multitrack);
756 mlt.appendChild(tractor);
757 // kDebug()<<doc.toString();
759 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
760 setSceneList(doc, 0);
766 /** Create the producer from the MLT XML QDomDocument */
767 int Render::setProducer(Mlt::Producer *producer, int position)
769 if (m_winid == -1) return -1;
772 m_mltConsumer->stop();
775 m_mltConsumer->purge();
779 m_mltProducer->set_speed(0);
780 delete m_mltProducer;
781 m_mltProducer = NULL;
785 m_mltProducer = new Mlt::Producer(producer->get_producer());
786 } else m_mltProducer = m_blackClip->cut(0, 50);
787 /*if (KdenliveSettings::dropbframes()) {
788 m_mltProducer->set("skip_loop_filter", "all");
789 m_mltProducer->set("skip_frame", "bidir");
791 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
793 m_fps = m_mltProducer->get_fps();
794 int error = connectPlaylist();
795 if (position != -1) {
796 m_mltProducer->seek(position);
797 emit rendererPosition(position);
805 /** Create the producer from the MLT XML QDomDocument */
806 int Render::setSceneList(QDomDocument list, int position)
808 return setSceneList(list.toString(), position);
811 /** Create the producer from the MLT XML QDomDocument */
812 int Render::setSceneList(QString playlist, int position)
814 if (m_winid == -1) return -1;
817 qDeleteAll(m_slowmotionProducers.values());
818 m_slowmotionProducers.clear();
820 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
822 if (m_mltConsumer == NULL) {
823 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
828 if (!m_mltConsumer->is_stopped()) {
829 m_mltConsumer->stop();
830 //m_mltConsumer->set("refresh", 0);
834 m_mltProducer->set_speed(0);
835 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
837 delete m_mltProducer;
838 m_mltProducer = NULL;
843 char *tmp = decodedString(playlist);
844 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
846 if (!m_mltProducer || !m_mltProducer->is_valid()) {
847 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
848 m_mltProducer = m_blackClip->cut(0, 50);
852 m_mltProducer->optimise();
854 /*if (KdenliveSettings::osdtimecode()) {
855 // Attach filter for on screen display of timecode
857 QString attr = "attr_check";
858 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
859 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
860 mlt_producer_attach( m_mltProducer->get_producer(), filter );
861 mlt_filter_close( filter );
863 m_osdInfo = new Mlt::Filter("data_show");
864 tmp = decodedString(m_osdProfile);
865 m_osdInfo->set("resource", tmp);
867 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
868 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
869 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
870 m_osdInfo->set("dynamic", "1");
872 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
874 m_osdInfo->set("dynamic", "0");
877 m_fps = m_mltProducer->get_fps();
879 // Seek to correct place after opening project.
880 m_mltProducer->seek(position);
883 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
884 error = connectPlaylist();
885 fillSlowMotionProducers();
889 emit refreshDocumentProducers();
891 //kDebug()<<"// SETSCN LST, POS: "<<position;
892 //if (position != 0) emit rendererPosition(position);
895 /** Create the producer from the MLT XML QDomDocument */
896 const QString Render::sceneList()
899 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
900 m_mltProducer->optimise();
901 xmlConsumer.set("terminate_on_pause", 1);
902 Mlt::Producer prod(m_mltProducer->get_producer());
903 bool split = m_isSplitView;
904 if (split) slotSplitView(false);
905 xmlConsumer.connect(prod);
907 while (!xmlConsumer.is_stopped()) {}
908 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
909 if (split) slotSplitView(true);
913 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
917 doc.setContent(sceneList(), false);
918 if (!kdenliveData.isNull()) {
919 // add Kdenlive specific tags
920 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
921 mlt.appendChild(doc.importNode(kdenliveData, true));
923 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
924 kWarning() << "////// ERROR writing to file: " << path;
927 file.write(doc.toString().toUtf8());
928 if (file.error() != QFile::NoError) {
937 void Render::saveZone(KUrl url, QString desc, QPoint zone)
939 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
940 char *tmppath = decodedString("xml:" + url.path());
941 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
942 m_mltProducer->optimise();
944 xmlConsumer.set("terminate_on_pause", 1);
945 if (m_name == "clip") {
946 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
947 tmppath = decodedString(desc);
949 list.insert_at(0, prod, 0);
950 list.set("title", tmppath);
952 xmlConsumer.connect(list);
955 //TODO: not working yet, save zone from timeline
956 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
957 /* Mlt::Service service(p1->parent().get_service());
958 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
960 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
961 tmppath = decodedString(desc);
962 //prod->set("title", tmppath);
964 xmlConsumer.connect(*p1); //list);
970 double Render::fps() const
975 int Render::connectPlaylist()
977 if (!m_mltConsumer) return -1;
978 //m_mltConsumer->set("refresh", "0");
979 m_mltConsumer->connect(*m_mltProducer);
980 m_mltProducer->set_speed(0);
981 if (m_mltConsumer->start() == -1) {
982 // ARGH CONSUMER BROKEN!!!!
983 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."));
984 emit blockMonitors();
985 delete m_mltProducer;
986 m_mltProducer = NULL;
989 emit durationChanged(m_mltProducer->get_playtime());
994 void Render::refreshDisplay()
997 if (!m_mltProducer) return;
998 //m_mltConsumer->set("refresh", 0);
1000 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1001 /*if (KdenliveSettings::osdtimecode()) {
1002 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1003 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1004 m_osdInfo->set("dynamic", "1");
1005 m_mltProducer->attach(*m_osdInfo);
1008 m_mltProducer->detach(*m_osdInfo);
1009 m_osdInfo->set("dynamic", "0");
1014 void Render::setVolume(double /*volume*/)
1016 if (!m_mltConsumer || !m_mltProducer) return;
1018 m_mltConsumer->set("refresh", 0);
1019 // Attach filter for on screen display of timecode
1020 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1021 mlt_properties_set_double( properties, "meta.volume", volume );
1022 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1023 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1025 if (!KdenliveSettings::osdtimecode()) {
1026 m_mltProducer->detach(*m_osdInfo);
1027 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1028 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1031 m_osdTimer->setSingleShot(2500);
1034 void Render::slotOsdTimeout()
1036 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1037 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1038 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1039 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1043 void Render::start()
1045 kDebug() << "----- STARTING MONITOR: " << m_name;
1046 if (m_winid == -1) {
1047 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1050 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1051 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1052 if (m_mltConsumer->start() == -1) {
1053 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."));
1054 emit blockMonitors();
1055 delete m_mltProducer;
1056 m_mltProducer = NULL;
1058 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1059 m_isBlocked = false;
1063 m_isBlocked = false;
1066 void Render::clear()
1068 kDebug() << " ********* RENDER CLEAR";
1069 if (m_mltConsumer) {
1070 //m_mltConsumer->set("refresh", 0);
1071 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1074 if (m_mltProducer) {
1075 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1076 m_mltProducer->set_speed(0.0);
1077 delete m_mltProducer;
1078 m_mltProducer = NULL;
1085 if (m_mltProducer == NULL) return;
1086 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1087 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1089 //m_mltConsumer->set("refresh", 0);
1090 m_mltConsumer->stop();
1091 // delete m_mltConsumer;
1092 // m_mltConsumer = NULL;
1094 kDebug() << "///////////// RENDER STOP2-------";
1097 if (m_mltProducer) {
1098 if (m_isZoneMode) resetZoneMode();
1099 m_mltProducer->set_speed(0.0);
1100 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1101 //kDebug() << m_mltProducer->get_length();
1103 kDebug() << "///////////// RENDER STOP3-------";
1106 void Render::stop(const GenTime & startTime)
1109 kDebug() << "///////////// RENDER STOP-------2";
1110 if (m_mltProducer) {
1111 if (m_isZoneMode) resetZoneMode();
1112 m_mltProducer->set_speed(0.0);
1113 m_mltProducer->seek((int) startTime.frames(m_fps));
1115 m_mltConsumer->purge();
1118 void Render::pause()
1120 if (!m_mltProducer || !m_mltConsumer)
1122 if (m_mltProducer->get_speed() == 0.0) return;
1123 if (m_isZoneMode) resetZoneMode();
1125 m_mltConsumer->set("refresh", 0);
1126 m_mltProducer->set_speed(0.0);
1127 emit rendererPosition(m_framePosition);
1128 m_mltProducer->seek(m_framePosition);
1129 m_mltConsumer->purge();
1132 void Render::switchPlay()
1134 if (!m_mltProducer || !m_mltConsumer)
1136 if (m_isZoneMode) resetZoneMode();
1137 if (m_mltProducer->get_speed() == 0.0) {
1138 m_isBlocked = false;
1139 m_mltProducer->set_speed(1.0);
1140 m_mltConsumer->set("refresh", 1);
1143 m_mltConsumer->set("refresh", 0);
1144 m_mltProducer->set_speed(0.0);
1145 emit rendererPosition(m_framePosition);
1146 m_mltProducer->seek(m_framePosition);
1147 m_mltConsumer->purge();
1148 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1149 //m_mltConsumer->set("refresh", 0);
1150 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1151 m_mltProducer->set_speed(0);
1152 m_mltProducer->seek( position );
1153 //m_mltProducer->seek((int) m_framePosition);
1154 m_isBlocked = false;*/
1156 /*if (speed == 0.0) {
1157 m_mltProducer->seek((int) m_framePosition + 1);
1158 m_mltConsumer->purge();
1163 void Render::play(double speed)
1167 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1168 m_isBlocked = false;
1169 m_mltProducer->set_speed(speed);
1170 /*if (speed == 0.0) {
1171 m_mltProducer->seek((int) m_framePosition + 1);
1172 m_mltConsumer->purge();
1177 void Render::play(const GenTime & startTime)
1179 if (!m_mltProducer || !m_mltConsumer)
1181 m_isBlocked = false;
1182 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1183 m_mltProducer->set_speed(1.0);
1184 m_mltConsumer->set("refresh", 1);
1187 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1189 if (!m_mltProducer || !m_mltConsumer)
1191 //m_mltProducer->set("eof", "loop");
1192 m_isLoopMode = true;
1193 m_loopStart = startTime;
1194 playZone(startTime, stopTime);
1197 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1199 if (!m_mltProducer || !m_mltConsumer)
1201 m_isBlocked = false;
1202 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1203 m_mltProducer->set("out", stopTime.frames(m_fps));
1204 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1205 m_mltProducer->set_speed(1.0);
1206 m_mltConsumer->set("refresh", 1);
1207 m_isZoneMode = true;
1210 void Render::resetZoneMode()
1212 if (!m_isZoneMode && !m_isLoopMode) return;
1213 m_mltProducer->set("out", m_originalOut);
1214 //m_mltProducer->set("eof", "pause");
1215 m_isZoneMode = false;
1216 m_isLoopMode = false;
1219 void Render::seekToFrame(int pos)
1221 //kDebug()<<" ********* RENDER SEEK TO POS";
1224 m_isBlocked = false;
1226 m_mltProducer->seek(pos);
1230 void Render::askForRefresh()
1232 // Use a Timer so that we don't refresh too much
1233 m_refreshTimer->start(300);
1236 void Render::doRefresh()
1238 // Use a Timer so that we don't refresh too much
1239 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1242 void Render::refresh()
1244 if (!m_mltProducer || m_isBlocked)
1246 m_refreshTimer->stop();
1247 if (m_mltConsumer) {
1248 m_mltConsumer->set("refresh", 1);
1252 void Render::setDropFrames(bool show)
1254 if (m_mltConsumer) {
1256 if (show == false) dropFrames = 0;
1257 m_mltConsumer->stop();
1258 m_mltConsumer->set("play.real_time", dropFrames);
1259 if (m_mltConsumer->start() == -1) {
1260 emit blockMonitors();
1261 delete m_mltProducer;
1262 m_mltProducer = NULL;
1268 double Render::playSpeed()
1270 if (m_mltProducer) return m_mltProducer->get_speed();
1274 GenTime Render::seekPosition() const
1276 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1277 else return GenTime();
1281 const QString & Render::rendererName() const
1287 void Render::emitFrameNumber(double position)
1289 m_framePosition = position;
1290 emit rendererPosition((int) position);
1291 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1294 void Render::emitConsumerStopped()
1296 // This is used to know when the playing stopped
1297 if (m_mltProducer) {
1298 double pos = m_mltProducer->position();
1299 if (m_isLoopMode) play(m_loopStart);
1300 else if (m_isZoneMode) resetZoneMode();
1301 emit rendererStopped((int) pos);
1302 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1303 //new QCustomEvent(10002));
1309 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1311 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1315 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1317 if (!m_mltProducer) {
1318 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1322 //int height = 1080;//KdenliveSettings::defaultheight();
1323 //int width = 1940; //KdenliveSettings::displaywidth();
1325 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1327 QPixmap pix(width, height);
1328 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1329 m_convert.set("forced", mlt_image_rgb24a);
1330 m_mltProducer->attach(m_convert);
1331 Mlt::Frame * frame = m_mltProducer->get_frame();
1332 m_mltProducer->detach(m_convert);
1334 pix = frameThumbnail(frame, width, height);
1337 pix.save(url.path(), "PNG");
1338 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1341 /** MLT PLAYLIST DIRECT MANIPULATON **/
1344 void Render::mltCheckLength()
1346 //kDebug()<<"checking track length: "<<track<<"..........";
1348 Mlt::Service service(m_mltProducer->get_service());
1349 Mlt::Tractor tractor(service);
1351 int trackNb = tractor.count();
1355 Mlt::Producer trackProducer(tractor.track(0));
1356 duration = trackProducer.get_playtime() - 1;
1357 m_mltProducer->set("out", duration);
1358 emit durationChanged(duration);
1361 while (trackNb > 1) {
1362 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1363 trackDuration = trackProducer.get_playtime() - 1;
1365 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1366 if (trackDuration > duration) duration = trackDuration;
1370 Mlt::Producer blackTrackProducer(tractor.track(0));
1372 if (blackTrackProducer.get_playtime() - 1 != duration) {
1373 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1374 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1375 if (duration > m_blackClip->get_length()) {
1376 m_blackClip->set("length", duration);
1377 if (blackclip) blackclip->set("length", duration);
1379 if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
1380 blackTrackPlaylist.clear();
1381 blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
1382 } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1384 m_mltProducer->set("out", duration);
1385 emit durationChanged(duration);
1389 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1391 if (m_mltProducer == NULL) {
1392 kDebug() << "PLAYLIST NOT INITIALISED //////";
1395 Mlt::Producer parentProd(m_mltProducer->parent());
1396 if (parentProd.get_producer() == NULL) {
1397 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1401 Mlt::Service service(parentProd.get_service());
1402 Mlt::Tractor tractor(service);
1403 if (info.track > tractor.count() - 1) {
1404 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1407 mlt_service_lock(service.get_service());
1408 Mlt::Producer trackProducer(tractor.track(info.track));
1409 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1410 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1412 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1413 // We want a slowmotion producer
1414 double speed = element.attribute("speed", "1.0").toDouble();
1415 QString url = QString::fromUtf8(prod->get("resource"));
1416 url.append('?' + QString::number(speed));
1417 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1418 if (!slowprod || slowprod->get_producer() == NULL) {
1419 char *tmp = decodedString(url);
1420 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1422 QString id = prod->get("id");
1423 if (id.contains('_')) id = id.section('_', 0, 0);
1424 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1425 tmp = decodedString(producerid);
1426 slowprod->set("id", tmp);
1428 m_slowmotionProducers.insert(url, slowprod);
1433 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1434 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1436 /*if (QString(prod->get("transparency")).toInt() == 1)
1437 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1439 mlt_service_unlock(service.get_service());
1441 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1442 //tractor.multitrack()->refresh();
1443 //tractor.refresh();
1447 void Render::mltCutClip(int track, GenTime position)
1452 Mlt::Service service(m_mltProducer->parent().get_service());
1453 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1455 Mlt::Tractor tractor(service);
1456 Mlt::Producer trackProducer(tractor.track(track));
1457 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1460 /* // Display playlist info
1461 kDebug()<<"//////////// BEFORE";
1462 for (int i = 0; i < trackPlaylist.count(); i++) {
1463 int blankStart = trackPlaylist.clip_start(i);
1464 int blankDuration = trackPlaylist.clip_length(i) - 1;
1466 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1467 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1470 int cutPos = (int) position.frames(m_fps);
1472 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1473 if (trackPlaylist.is_blank(clipIndex)) {
1474 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1475 m_isBlocked = false;
1478 mlt_service_lock(service.get_service());
1479 int clipStart = trackPlaylist.clip_start(clipIndex);
1480 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1481 mlt_service_unlock(service.get_service());
1483 // duplicate effects
1484 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1485 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1487 if (original == NULL || clip == NULL) {
1488 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1490 Mlt::Service clipService(original->get_service());
1491 Mlt::Service dupService(clip->get_service());
1493 Mlt::Filter *filter = clipService.filter(ct);
1495 // Only duplicate Kdenlive filters, and skip the fade in effects
1496 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1497 // looks like there is no easy way to duplicate a filter,
1498 // so we will create a new one and duplicate its properties
1499 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1500 if (dup && dup->is_valid()) {
1501 Mlt::Properties entries(filter->get_properties());
1502 for (int i = 0; i < entries.count(); i++) {
1503 dup->set(entries.get_name(i), entries.get(i));
1505 dupService.attach(*dup);
1509 filter = clipService.filter(ct);
1512 /* // Display playlist info
1513 kDebug()<<"//////////// AFTER";
1514 for (int i = 0; i < trackPlaylist.count(); i++) {
1515 int blankStart = trackPlaylist.clip_start(i);
1516 int blankDuration = trackPlaylist.clip_length(i) - 1;
1518 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1519 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1522 m_isBlocked = false;
1525 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1528 mltRemoveClip(info.track, info.startPos);
1529 mltInsertClip(info, element, prod);
1533 bool Render::mltRemoveClip(int track, GenTime position)
1535 Mlt::Service service(m_mltProducer->parent().get_service());
1536 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1538 Mlt::Tractor tractor(service);
1539 mlt_service_lock(service.get_service());
1540 Mlt::Producer trackProducer(tractor.track(track));
1541 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1542 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1544 // Display playlist info
1545 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1546 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1547 int blankStart = trackPlaylist.clip_start(i);
1548 int blankDuration = trackPlaylist.clip_length(i) - 1;
1550 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1551 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1553 if (trackPlaylist.is_blank(clipIndex)) {
1554 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1555 mlt_service_unlock(service.get_service());
1558 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1560 trackPlaylist.replace_with_blank(clipIndex);
1561 trackPlaylist.consolidate_blanks(0);
1562 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1563 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1565 /* // Display playlist info
1566 kDebug()<<"//// AFTER";
1567 for (int i = 0; i < trackPlaylist.count(); i++) {
1568 int blankStart = trackPlaylist.clip_start(i);
1569 int blankDuration = trackPlaylist.clip_length(i) - 1;
1571 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1572 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1574 mlt_service_unlock(service.get_service());
1575 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1576 m_isBlocked = false;
1580 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1582 if (!m_mltProducer) {
1583 kDebug() << "PLAYLIST NOT INITIALISED //////";
1586 Mlt::Producer parentProd(m_mltProducer->parent());
1587 if (parentProd.get_producer() == NULL) {
1588 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1592 Mlt::Service service(parentProd.get_service());
1593 Mlt::Tractor tractor(service);
1594 int insertPos = pos.frames(m_fps);
1596 Mlt::Producer trackProducer(tractor.track(track));
1597 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1598 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1599 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1600 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1601 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1604 int Render::mltTrackDuration(int track)
1606 if (!m_mltProducer) {
1607 kDebug() << "PLAYLIST NOT INITIALISED //////";
1610 Mlt::Producer parentProd(m_mltProducer->parent());
1611 if (parentProd.get_producer() == NULL) {
1612 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1616 Mlt::Service service(parentProd.get_service());
1617 Mlt::Tractor tractor(service);
1619 Mlt::Producer trackProducer(tractor.track(track));
1620 return trackProducer.get_playtime() - 1;
1623 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1625 if (!m_mltProducer) {
1626 kDebug() << "PLAYLIST NOT INITIALISED //////";
1629 Mlt::Producer parentProd(m_mltProducer->parent());
1630 if (parentProd.get_producer() == NULL) {
1631 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1634 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1635 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1637 Mlt::Service service(parentProd.get_service());
1638 Mlt::Tractor tractor(service);
1639 mlt_service_lock(service.get_service());
1640 int diff = duration.frames(m_fps);
1641 int offset = timeOffset.frames(m_fps);
1645 // insert space in one track only
1646 Mlt::Producer trackProducer(tractor.track(track));
1647 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1648 insertPos = trackClipStartList.value(track);
1649 if (insertPos != -1) {
1650 insertPos += offset;
1651 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1652 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1654 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1655 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1656 int position = trackPlaylist.clip_start(clipIndex);
1657 trackPlaylist.remove_region(position, - diff - 1);
1659 trackPlaylist.consolidate_blanks(0);
1661 // now move transitions
1662 mlt_service serv = m_mltProducer->parent().get_service();
1663 mlt_service nextservice = mlt_service_get_producer(serv);
1664 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1665 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1666 QString resource = mlt_properties_get(properties, "mlt_service");
1668 while (mlt_type == "transition") {
1669 mlt_transition tr = (mlt_transition) nextservice;
1670 int currentTrack = mlt_transition_get_b_track(tr);
1671 int currentIn = (int) mlt_transition_get_in(tr);
1672 int currentOut = (int) mlt_transition_get_out(tr);
1673 insertPos = trackTransitionStartList.value(track);
1674 if (insertPos != -1) {
1675 insertPos += offset;
1676 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1677 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1680 nextservice = mlt_service_producer(nextservice);
1681 if (nextservice == NULL) break;
1682 properties = MLT_SERVICE_PROPERTIES(nextservice);
1683 mlt_type = mlt_properties_get(properties, "mlt_type");
1684 resource = mlt_properties_get(properties, "mlt_service");
1687 int trackNb = tractor.count();
1688 while (trackNb > 1) {
1689 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1690 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1693 //int clipNb = trackPlaylist.count();
1694 insertPos = trackClipStartList.value(trackNb - 1);
1695 if (insertPos != -1) {
1696 insertPos += offset;
1698 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1699 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1700 for (int i = 0; i < clipNb; i++) {
1701 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1702 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1703 kDebug()<<"-------------";
1705 kDebug()<<"END-------------";*/
1708 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1709 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1711 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1712 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1713 int position = trackPlaylist.clip_start(clipIndex);
1714 trackPlaylist.remove_region(position, - diff - 1);
1716 trackPlaylist.consolidate_blanks(0);
1720 // now move transitions
1721 mlt_service serv = m_mltProducer->parent().get_service();
1722 mlt_service nextservice = mlt_service_get_producer(serv);
1723 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1724 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1725 QString resource = mlt_properties_get(properties, "mlt_service");
1727 while (mlt_type == "transition") {
1728 mlt_transition tr = (mlt_transition) nextservice;
1729 int currentIn = (int) mlt_transition_get_in(tr);
1730 int currentOut = (int) mlt_transition_get_out(tr);
1731 int currentTrack = mlt_transition_get_b_track(tr);
1732 insertPos = trackTransitionStartList.value(currentTrack);
1733 if (insertPos != -1) {
1734 insertPos += offset;
1735 if (currentOut > insertPos && resource != "mix") {
1736 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1739 nextservice = mlt_service_producer(nextservice);
1740 if (nextservice == NULL) break;
1741 properties = MLT_SERVICE_PROPERTIES(nextservice);
1742 mlt_type = mlt_properties_get(properties, "mlt_type");
1743 resource = mlt_properties_get(properties, "mlt_service");
1746 mlt_service_unlock(service.get_service());
1748 m_mltConsumer->set("refresh", 1);
1752 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1754 Mlt::Service sourceService(source->get_service());
1755 Mlt::Service destService(dest->get_service());
1757 // move all effects to the correct producer
1759 Mlt::Filter *filter = sourceService.filter(ct);
1761 if (filter->get("kdenlive_ix") != 0) {
1762 sourceService.detach(*filter);
1763 destService.attach(*filter);
1765 filter = sourceService.filter(ct);
1769 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1773 Mlt::Service service(m_mltProducer->parent().get_service());
1774 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1775 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1776 Mlt::Tractor tractor(service);
1777 Mlt::Producer trackProducer(tractor.track(info.track));
1778 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1779 int startPos = info.startPos.frames(m_fps);
1780 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1781 int clipLength = trackPlaylist.clip_length(clipIndex);
1783 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1787 if (!clip->is_valid() || clip->is_blank()) {
1792 Mlt::Producer clipparent = clip->parent();
1793 if (!clipparent.is_valid() || clipparent.is_blank()) {
1799 QString serv = clipparent.get("mlt_service");
1800 QString id = clipparent.get("id");
1801 //kDebug() << "CLIP SERVICE: " << serv;
1802 if (serv == "avformat" && speed != 1.0) {
1803 mlt_service_lock(service.get_service());
1804 QString url = QString::fromUtf8(clipparent.get("resource"));
1805 url.append('?' + QString::number(speed));
1806 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1807 if (!slowprod || slowprod->get_producer() == NULL) {
1808 char *tmp = decodedString(url);
1809 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1811 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1812 tmp = decodedString(producerid);
1813 slowprod->set("id", tmp);
1815 m_slowmotionProducers.insert(url, slowprod);
1817 trackPlaylist.replace_with_blank(clipIndex);
1818 trackPlaylist.consolidate_blanks(0);
1819 // Check that the blank space is long enough for our new duration
1820 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1821 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1823 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1824 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1825 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1826 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1828 // move all effects to the correct producer
1829 mltPasteEffects(clip, cut);
1831 trackPlaylist.insert_at(startPos, *cut, 1);
1832 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1833 newLength = trackPlaylist.clip_length(clipIndex);
1834 mlt_service_unlock(service.get_service());
1835 } else if (speed == 1.0) {
1836 mlt_service_lock(service.get_service());
1838 trackPlaylist.replace_with_blank(clipIndex);
1839 trackPlaylist.consolidate_blanks(0);
1841 // Check that the blank space is long enough for our new duration
1842 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1843 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1846 GenTime oldDuration = GenTime(clipLength, m_fps);
1847 GenTime newDuration = oldDuration * oldspeed;
1848 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1849 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1850 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1851 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1853 // move all effects to the correct producer
1854 mltPasteEffects(clip, cut);
1856 trackPlaylist.insert_at(startPos, *cut, 1);
1857 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1858 newLength = trackPlaylist.clip_length(clipIndex);
1859 mlt_service_unlock(service.get_service());
1861 } else if (serv == "framebuffer") {
1862 mlt_service_lock(service.get_service());
1863 QString url = QString::fromUtf8(clipparent.get("resource"));
1864 url = url.section('?', 0, 0);
1865 url.append('?' + QString::number(speed));
1866 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1867 if (!slowprod || slowprod->get_producer() == NULL) {
1868 char *tmp = decodedString(url);
1869 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1871 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1872 tmp = decodedString(producerid);
1873 slowprod->set("id", tmp);
1875 m_slowmotionProducers.insert(url, slowprod);
1877 trackPlaylist.replace_with_blank(clipIndex);
1878 trackPlaylist.consolidate_blanks(0);
1880 GenTime oldDuration = GenTime(clipLength, m_fps);
1881 GenTime newDuration = oldDuration * oldspeed / speed;
1883 // Check that the blank space is long enough for our new duration
1884 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1885 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1888 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1889 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1890 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1891 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1893 // move all effects to the correct producer
1894 mltPasteEffects(clip, cut);
1896 trackPlaylist.insert_at(startPos, *cut, 1);
1897 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1898 newLength = trackPlaylist.clip_length(clipIndex);
1900 mlt_service_unlock(service.get_service());
1904 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1905 m_isBlocked = false;
1909 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1911 kDebug() << "// TRYing to remove effect at: " << index;
1912 Mlt::Service service(m_mltProducer->parent().get_service());
1913 bool success = false;
1914 Mlt::Tractor tractor(service);
1915 Mlt::Producer trackProducer(tractor.track(track));
1916 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1917 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1918 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1920 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1923 Mlt::Service clipService(clip->get_service());
1924 // if (tag.startsWith("ladspa")) tag = "ladspa";
1927 Mlt::Filter *filter = clipService.filter(ct);
1929 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1930 if (clipService.detach(*filter) == 0) success = true;
1931 kDebug() << " / / / DLEETED EFFECT: " << ct;
1932 } else if (updateIndex) {
1933 // Adjust the other effects index
1934 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1937 filter = clipService.filter(ct);
1939 m_isBlocked = false;
1940 if (doRefresh) refresh();
1945 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1948 Mlt::Service service(m_mltProducer->parent().get_service());
1950 Mlt::Tractor tractor(service);
1951 Mlt::Producer trackProducer(tractor.track(track));
1952 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1954 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1958 Mlt::Service clipService(clip->get_service());
1961 // temporarily remove all effects after insert point
1962 QList <Mlt::Filter *> filtersList;
1963 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1965 Mlt::Filter *filter = clipService.filter(ct);
1967 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1968 filtersList.append(filter);
1969 clipService.detach(*filter);
1971 filter = clipService.filter(ct);
1975 QString tag = params.paramValue("tag");
1976 kDebug() << " / / INSERTING EFFECT: " << tag;
1977 if (tag.startsWith("ladspa")) tag = "ladspa";
1978 char *filterTag = decodedString(tag);
1979 char *filterId = decodedString(params.paramValue("id"));
1980 QHash<QString, QString>::Iterator it;
1981 QString kfr = params.paramValue("keyframes");
1983 if (!kfr.isEmpty()) {
1984 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1985 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1986 char *starttag = decodedString(params.paramValue("starttag", "start"));
1987 char *endtag = decodedString(params.paramValue("endtag", "end"));
1988 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1989 int duration = clip->get_playtime();
1990 //double max = params.paramValue("max").toDouble();
1991 double min = params.paramValue("min").toDouble();
1992 double factor = params.paramValue("factor", "1").toDouble();
1993 params.removeParam("starttag");
1994 params.removeParam("endtag");
1995 params.removeParam("keyframes");
1996 params.removeParam("min");
1997 params.removeParam("max");
1998 params.removeParam("factor");
2000 for (int i = 0; i < keyFrames.size() - 1; ++i) {
2001 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2002 if (filter && filter->is_valid()) {
2003 filter->set("kdenlive_id", filterId);
2004 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2005 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2006 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2007 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2008 if (x2 == -1) x2 = duration;
2010 for (int j = 0; j < params.count(); j++) {
2011 char *name = decodedString(params.at(j).name());
2012 char *value = decodedString(params.at(j).value());
2013 filter->set(name, value);
2018 filter->set("in", x1);
2019 filter->set("out", x2);
2020 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2021 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2022 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2023 clipService.attach(*filter);
2030 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2031 if (filter && filter->is_valid())
2032 filter->set("kdenlive_id", filterId);
2034 kDebug() << "filter is NULL";
2035 m_isBlocked = false;
2039 params.removeParam("kdenlive_id");
2041 for (int j = 0; j < params.count(); j++) {
2042 char *name = decodedString(params.at(j).name());
2043 char *value = decodedString(params.at(j).value());
2044 filter->set(name, value);
2050 QString effectArgs = params.paramValue("id").section('_', 1);
2052 params.removeParam("id");
2053 params.removeParam("kdenlive_ix");
2054 params.removeParam("tag");
2055 params.removeParam("disabled");
2057 for (int j = 0; j < params.count(); j++) {
2058 effectArgs.append(' ' + params.at(j).value());
2060 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2061 char *value = decodedString(effectArgs.simplified());
2062 filter->set("effect", value);
2067 // attach filter to the clip
2068 clipService.attach(*filter);
2073 // re-add following filters
2074 for (int i = 0; i < filtersList.count(); i++) {
2075 clipService.attach(*(filtersList.at(i)));
2078 m_isBlocked = false;
2079 if (doRefresh) refresh();
2083 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2085 QString index = params.paramValue("kdenlive_ix");
2086 QString tag = params.paramValue("tag");
2088 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2089 // This is a keyframe effect, to edit it, we remove it and re-add it.
2090 mltRemoveEffect(track, position, index, true);
2091 bool success = mltAddEffect(track, position, params);
2096 Mlt::Service service(m_mltProducer->parent().get_service());
2098 Mlt::Tractor tractor(service);
2099 Mlt::Producer trackProducer(tractor.track(track));
2100 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2101 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2102 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2104 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2107 Mlt::Service clipService(clip->get_service());
2110 Mlt::Filter *filter = clipService.filter(ct);
2112 if (filter->get("kdenlive_ix") == index) {
2116 filter = clipService.filter(ct);
2120 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2121 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2123 filter = clipService.filter(ct);
2124 QList <Mlt::Filter *> filtersList;
2126 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2127 filtersList.append(filter);
2128 clipService.detach(*filter);
2130 filter = clipService.filter(ct);
2132 bool success = mltAddEffect(track, position, params);
2134 for (int i = 0; i < filtersList.count(); i++) {
2135 clipService.attach(*(filtersList.at(i)));
2138 m_isBlocked = false;
2142 for (int j = 0; j < params.count(); j++) {
2143 char *name = decodedString(params.at(j).name());
2144 char *value = decodedString(params.at(j).value());
2145 filter->set(name, value);
2150 m_isBlocked = false;
2155 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2158 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2159 Mlt::Service service(m_mltProducer->parent().get_service());
2161 Mlt::Tractor tractor(service);
2162 Mlt::Producer trackProducer(tractor.track(track));
2163 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2164 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2165 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2167 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2170 Mlt::Service clipService(clip->get_service());
2173 QList <Mlt::Filter *> filtersList;
2174 Mlt::Filter *filter = clipService.filter(ct);
2176 if (newPos > oldPos) {
2178 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2179 filter->set("kdenlive_ix", newPos);
2180 filtersList.append(filter);
2181 clipService.detach(*filter);
2182 filter = clipService.filter(ct);
2183 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2184 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2186 filter = clipService.filter(ct);
2190 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2191 filtersList.append(filter);
2192 clipService.detach(*filter);
2194 filter = clipService.filter(ct);
2198 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2199 filter->set("kdenlive_ix", newPos);
2200 filtersList.append(filter);
2201 clipService.detach(*filter);
2203 filter = clipService.filter(ct);
2207 filter = clipService.filter(ct);
2209 int pos = QString(filter->get("kdenlive_ix")).toInt();
2210 if (pos >= newPos) {
2211 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2212 filtersList.append(filter);
2213 clipService.detach(*filter);
2215 filter = clipService.filter(ct);
2219 for (int i = 0; i < filtersList.count(); i++) {
2220 clipService.attach(*(filtersList.at(i)));
2223 m_isBlocked = false;
2227 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2230 Mlt::Service service(m_mltProducer->parent().get_service());
2231 Mlt::Tractor tractor(service);
2232 Mlt::Producer trackProducer(tractor.track(info.track));
2233 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2235 /* // Display playlist info
2236 kDebug()<<"//////////// BEFORE RESIZE";
2237 for (int i = 0; i < trackPlaylist.count(); i++) {
2238 int blankStart = trackPlaylist.clip_start(i);
2239 int blankDuration = trackPlaylist.clip_length(i) - 1;
2241 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2242 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2245 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2246 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2247 m_isBlocked = false;
2250 mlt_service_lock(service.get_service());
2251 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2252 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2253 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2254 int previousStart = clip->get_in();
2255 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2256 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2257 if (newDuration > clip->get_length()) {
2258 clip->parent().set("length", newDuration + 1);
2259 clip->set("length", newDuration + 1);
2261 if (newDuration > clip->get_out()) {
2262 clip->parent().set_in_and_out(0, newDuration + 1);
2263 clip->set_in_and_out(0, newDuration + 1);
2266 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2267 trackPlaylist.consolidate_blanks(0);
2268 // skip to next clip
2270 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2272 // clip was made longer, trim next blank if there is one.
2273 if (clipIndex < trackPlaylist.count()) {
2274 // If this is not the last clip in playlist
2275 if (trackPlaylist.is_blank(clipIndex)) {
2276 int blankStart = trackPlaylist.clip_start(clipIndex);
2277 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2278 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2279 if (diff - blankDuration == 1) {
2280 trackPlaylist.remove(clipIndex);
2281 } else trackPlaylist.remove_region(blankStart, diff - 1);
2283 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2286 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2287 trackPlaylist.consolidate_blanks(0);
2288 mlt_service_unlock(service.get_service());
2290 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2291 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2292 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2293 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2294 ItemInfo transpinfo;
2295 transpinfo.startPos = info.startPos;
2296 transpinfo.endPos = info.startPos + clipDuration;
2297 transpinfo.track = info.track;
2298 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2300 m_isBlocked = false;
2301 m_mltConsumer->set("refresh", 1);
2305 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2307 Mlt::Service service(m_mltProducer->parent().get_service());
2308 Mlt::Tractor tractor(service);
2309 Mlt::Producer trackProducer(tractor.track(track));
2312 if (blind) trackProducer.set("hide", 3);
2313 else trackProducer.set("hide", 2);
2315 trackProducer.set("hide", 1);
2317 trackProducer.set("hide", 0);
2319 tractor.multitrack()->refresh();
2325 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2327 Mlt::Service service(m_mltProducer->parent().get_service());
2328 int frameOffset = (int) diff.frames(m_fps);
2329 Mlt::Tractor tractor(service);
2330 Mlt::Producer trackProducer(tractor.track(info.track));
2331 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2332 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2333 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2336 mlt_service_lock(service.get_service());
2337 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2338 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2340 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2341 mlt_service_unlock(service.get_service());
2344 int previousStart = clip->get_in();
2346 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2348 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2349 m_isBlocked = false;
2350 mlt_service_unlock(service.get_service());
2351 m_mltConsumer->set("refresh", 1);
2355 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2357 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2358 Mlt::Service service(m_mltProducer->parent().get_service());
2359 int moveFrame = (int) diff.frames(m_fps);
2360 Mlt::Tractor tractor(service);
2361 Mlt::Producer trackProducer(tractor.track(info.track));
2362 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2363 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2364 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2367 mlt_service_lock(service.get_service());
2368 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2369 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2371 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2372 mlt_service_unlock(service.get_service());
2375 int previousStart = clip->get_in();
2377 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2379 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2380 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2381 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2383 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2384 int blankIndex = clipIndex - 1;
2385 int blankLength = trackPlaylist.clip_length(blankIndex);
2386 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2387 if (! trackPlaylist.is_blank(blankIndex)) {
2388 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2390 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2391 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2393 trackPlaylist.consolidate_blanks(0);
2394 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2395 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2396 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2397 ItemInfo transpinfo;
2398 transpinfo.startPos = info.startPos + diff;
2399 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2400 transpinfo.track = info.track;
2401 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2403 m_isBlocked = false;
2404 //m_mltConsumer->set("refresh", 1);
2405 mlt_service_unlock(service.get_service());
2406 m_mltConsumer->set("refresh", 1);
2410 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2412 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2416 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2418 if (prod == NULL || !prod->is_valid()) {
2419 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2422 kDebug() << "NEW PROD ID: " << prod->get("id");
2424 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2425 mlt_service_lock(m_mltConsumer->get_service());
2426 Mlt::Service service(m_mltProducer->parent().get_service());
2427 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2429 Mlt::Tractor tractor(service);
2430 Mlt::Producer trackProducer(tractor.track(track));
2431 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2432 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2433 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2434 if (clipProducer.is_blank()) {
2435 kDebug() << "// ERROR UPDATING CLIP PROD";
2436 mlt_service_unlock(m_mltConsumer->get_service());
2440 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2442 // move all effects to the correct producer
2443 mltPasteEffects(&clipProducer, clip);
2445 trackPlaylist.insert_at(pos, clip, 1);
2446 mlt_service_unlock(m_mltConsumer->get_service());
2450 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2454 Mlt::Service service(m_mltProducer->parent().get_service());
2455 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2457 Mlt::Tractor tractor(service);
2458 mlt_service_lock(service.get_service());
2459 Mlt::Producer trackProducer(tractor.track(startTrack));
2460 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2461 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
2462 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2463 bool checkLength = false;
2464 if (endTrack == startTrack) {
2465 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2466 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2467 // error, destination is not empty
2468 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2469 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2470 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2471 mlt_service_unlock(service.get_service());
2475 trackPlaylist.consolidate_blanks(0);
2476 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2477 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2478 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2480 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2482 //mlt_service_unlock(service.get_service());
2484 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2485 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2486 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2487 // error, destination is not empty
2488 mlt_service_unlock(service.get_service());
2492 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2493 if (clipProducer.is_blank()) {
2494 // error, destination is not empty
2495 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2496 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2497 mlt_service_unlock(service.get_service());
2501 trackPlaylist.consolidate_blanks(0);
2502 destTrackPlaylist.consolidate_blanks(1);
2503 Mlt::Producer *clip;
2504 // check if we are moving a slowmotion producer
2505 QString serv = clipProducer.parent().get("mlt_service");
2506 QString currentid = clipProducer.parent().get("id");
2507 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2508 clip = &clipProducer;
2511 // Special case: prod is null when using placeholder clips.
2512 // in that case, use the producer existing in playlist. Note that
2513 // it will bypass the one producer per track logic and might cause
2514 // Sound cracks if clip is moved so that it overlaps another copy of itself
2515 clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
2516 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2519 // move all effects to the correct producer
2520 mltPasteEffects(&clipProducer, clip);
2522 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2523 destTrackPlaylist.consolidate_blanks(0);
2524 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2525 kDebug() << "//////// moving clip transparency";
2526 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2528 if (clipIndex > trackPlaylist.count()) checkLength = true;
2529 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2532 mlt_service_unlock(service.get_service());
2533 if (checkLength) mltCheckLength();
2536 //m_mltConsumer->set("refresh", 1);
2540 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2542 int new_in = (int)newIn.frames(m_fps);
2543 int new_out = (int)newOut.frames(m_fps) - 1;
2544 if (new_in >= new_out) return false;
2546 mlt_service serv = m_mltProducer->parent().get_service();
2548 mlt_service_lock(serv);
2549 //m_mltConsumer->set("refresh", 0);
2552 mlt_service nextservice = mlt_service_get_producer(serv);
2553 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2554 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2555 QString resource = mlt_properties_get(properties, "mlt_service");
2556 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2558 while (mlt_type == "transition") {
2559 mlt_transition tr = (mlt_transition) nextservice;
2560 int currentTrack = mlt_transition_get_b_track(tr);
2561 int currentIn = (int) mlt_transition_get_in(tr);
2562 int currentOut = (int) mlt_transition_get_out(tr);
2564 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2565 mlt_transition_set_in_and_out(tr, new_in, new_out);
2566 if (newTrack - startTrack != 0) {
2567 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2569 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2570 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2571 mlt_properties_set_int(properties, "b_track", newTrack);
2572 //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);
2576 nextservice = mlt_service_producer(nextservice);
2577 if (nextservice == NULL) break;
2578 properties = MLT_SERVICE_PROPERTIES(nextservice);
2579 mlt_type = mlt_properties_get(properties, "mlt_type");
2580 resource = mlt_properties_get(properties, "mlt_service");
2582 mlt_service_unlock(serv);
2585 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2589 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2591 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2593 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2594 mltAddTransition(tag, a_track, b_track, in, out, xml);
2596 //mltSavePlaylist();
2599 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2601 mlt_service serv = m_mltProducer->parent().get_service();
2602 mlt_service_lock(serv);
2606 mlt_service nextservice = mlt_service_get_producer(serv);
2607 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2608 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2609 QString resource = mlt_properties_get(properties, "mlt_service");
2610 int in_pos = (int) in.frames(m_fps);
2611 int out_pos = (int) out.frames(m_fps) - 1;
2613 while (mlt_type == "transition") {
2614 mlt_transition tr = (mlt_transition) nextservice;
2615 int currentTrack = mlt_transition_get_b_track(tr);
2616 int currentBTrack = mlt_transition_get_a_track(tr);
2617 int currentIn = (int) mlt_transition_get_in(tr);
2618 int currentOut = (int) mlt_transition_get_out(tr);
2620 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2622 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2623 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2624 QMap<QString, QString>::Iterator it;
2626 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2627 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2628 if (currentBTrack != a_track) {
2629 mlt_properties_set_int(properties, "a_track", a_track);
2631 for (it = map.begin(); it != map.end(); ++it) {
2633 char *name = decodedString(key);
2634 char *value = decodedString(it.value());
2635 mlt_properties_set(transproperties, name, value);
2636 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2637 //filter->set("kdenlive_id", id);
2643 nextservice = mlt_service_producer(nextservice);
2644 if (nextservice == NULL) break;
2645 properties = MLT_SERVICE_PROPERTIES(nextservice);
2646 mlt_type = mlt_properties_get(properties, "mlt_type");
2647 resource = mlt_properties_get(properties, "mlt_service");
2649 mlt_service_unlock(serv);
2652 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2655 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2657 mlt_service serv = m_mltProducer->parent().get_service();
2659 mlt_service_lock(serv);
2661 Mlt::Service service(serv);
2662 Mlt::Tractor tractor(service);
2663 Mlt::Field *field = tractor.field();
2665 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2667 mlt_service nextservice = mlt_service_get_producer(serv);
2668 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2669 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2670 QString resource = mlt_properties_get(properties, "mlt_service");
2672 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2673 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2675 while (mlt_type == "transition") {
2676 mlt_transition tr = (mlt_transition) nextservice;
2677 int currentTrack = mlt_transition_get_b_track(tr);
2678 int currentIn = (int) mlt_transition_get_in(tr);
2679 int currentOut = (int) mlt_transition_get_out(tr);
2680 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2682 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2683 mlt_field_disconnect_service(field->get_field(), nextservice);
2686 nextservice = mlt_service_producer(nextservice);
2687 if (nextservice == NULL) break;
2688 properties = MLT_SERVICE_PROPERTIES(nextservice);
2689 mlt_type = mlt_properties_get(properties, "mlt_type");
2690 resource = mlt_properties_get(properties, "mlt_service");
2692 mlt_service_unlock(serv);
2695 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2698 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2700 QDomNodeList attribs = xml.elementsByTagName("parameter");
2701 QMap<QString, QString> map;
2702 for (int i = 0; i < attribs.count(); i++) {
2703 QDomElement e = attribs.item(i).toElement();
2704 QString name = e.attribute("name");
2705 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2706 map[name] = e.attribute("default");
2707 if (!e.attribute("value").isEmpty()) {
2708 map[name] = e.attribute("value");
2710 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2711 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2712 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2715 if (e.attribute("namedesc").contains(';')) {
2716 QString format = e.attribute("format");
2717 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2718 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2720 QTextStream txtNeu(&neu);
2721 if (values.size() > 0)
2722 txtNeu << (int)values[0].toDouble();
2724 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
2725 txtNeu << separators[i];
2726 txtNeu << (int)(values[i+1].toDouble());
2728 if (i < separators.size())
2729 txtNeu << separators[i];
2730 map[e.attribute("name")] = neu;
2737 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2739 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2740 Mlt::Service service(m_mltProducer->parent().get_service());
2741 Mlt::Tractor tractor(service);
2742 Mlt::Field *field = tractor.field();
2744 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2745 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2746 transition->set("transparency", id);
2747 transition->set("fill", 1);
2748 transition->set("internal_added", 237);
2749 field->plant_transition(*transition, transitiontrack, info.track);
2753 void Render::mltDeleteTransparency(int pos, int track, int id)
2755 Mlt::Service service(m_mltProducer->parent().get_service());
2756 Mlt::Tractor tractor(service);
2757 Mlt::Field *field = tractor.field();
2759 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2760 mlt_service serv = m_mltProducer->parent().get_service();
2762 mlt_service nextservice = mlt_service_get_producer(serv);
2763 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2764 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2765 QString resource = mlt_properties_get(properties, "mlt_service");
2767 while (mlt_type == "transition") {
2768 mlt_transition tr = (mlt_transition) nextservice;
2769 int currentTrack = mlt_transition_get_b_track(tr);
2770 int currentIn = (int) mlt_transition_get_in(tr);
2771 int currentOut = (int) mlt_transition_get_out(tr);
2772 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2773 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2775 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2776 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2777 mlt_field_disconnect_service(field->get_field(), nextservice);
2780 nextservice = mlt_service_producer(nextservice);
2781 if (nextservice == NULL) break;
2782 properties = MLT_SERVICE_PROPERTIES(nextservice);
2783 mlt_type = mlt_properties_get(properties, "mlt_type");
2784 resource = mlt_properties_get(properties, "mlt_service");
2786 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2789 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2791 Mlt::Service service(m_mltProducer->parent().get_service());
2792 Mlt::Tractor tractor(service);
2794 mlt_service_lock(service.get_service());
2795 m_mltConsumer->set("refresh", 0);
2798 mlt_service serv = m_mltProducer->parent().get_service();
2799 mlt_service nextservice = mlt_service_get_producer(serv);
2800 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2801 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2802 QString resource = mlt_properties_get(properties, "mlt_service");
2803 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2804 while (mlt_type == "transition") {
2805 mlt_transition tr = (mlt_transition) nextservice;
2806 int currentTrack = mlt_transition_get_b_track(tr);
2807 int currentIn = (int) mlt_transition_get_in(tr);
2808 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2809 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2810 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2811 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2812 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2813 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2816 nextservice = mlt_service_producer(nextservice);
2817 if (nextservice == NULL) break;
2818 properties = MLT_SERVICE_PROPERTIES(nextservice);
2819 mlt_type = mlt_properties_get(properties, "mlt_type");
2820 resource = mlt_properties_get(properties, "mlt_service");
2822 mlt_service_unlock(service.get_service());
2824 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2828 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2830 Mlt::Service service(m_mltProducer->parent().get_service());
2831 Mlt::Tractor tractor(service);
2833 mlt_service_lock(service.get_service());
2834 m_mltConsumer->set("refresh", 0);
2837 mlt_service serv = m_mltProducer->parent().get_service();
2838 mlt_service nextservice = mlt_service_get_producer(serv);
2839 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2840 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2841 QString resource = mlt_properties_get(properties, "mlt_service");
2843 while (mlt_type == "transition") {
2844 mlt_transition tr = (mlt_transition) nextservice;
2845 int currentTrack = mlt_transition_get_b_track(tr);
2846 int currentaTrack = mlt_transition_get_a_track(tr);
2847 int currentIn = (int) mlt_transition_get_in(tr);
2848 int currentOut = (int) mlt_transition_get_out(tr);
2849 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2850 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2851 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2852 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2853 kDebug() << "//////MOVING";
2854 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2855 if (endTrack != startTrack) {
2856 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2857 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2858 mlt_properties_set_int(properties, "b_track", endTrack);
2862 nextservice = mlt_service_producer(nextservice);
2863 if (nextservice == NULL) break;
2864 properties = MLT_SERVICE_PROPERTIES(nextservice);
2865 mlt_type = mlt_properties_get(properties, "mlt_type");
2866 resource = mlt_properties_get(properties, "mlt_service");
2869 mlt_service_unlock(service.get_service());
2870 m_mltConsumer->set("refresh", 1);
2874 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2876 if (in >= out) return false;
2877 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2878 Mlt::Service service(m_mltProducer->parent().get_service());
2880 Mlt::Tractor tractor(service);
2881 Mlt::Field *field = tractor.field();
2883 char *transId = decodedString(tag);
2884 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2885 if (out != GenTime())
2886 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2887 QMap<QString, QString>::Iterator it;
2889 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2890 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2891 if (xml.hasAttribute("id"))
2892 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
2894 for (it = args.begin(); it != args.end(); ++it) {
2896 char *name = decodedString(key);
2897 char *value = decodedString(it.value());
2898 if (it.value().isEmpty() == false) transition->set(name, value);
2899 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2903 // attach filter to the clip
2904 field->plant_transition(*transition, a_track, b_track);
2910 void Render::mltSavePlaylist()
2912 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2913 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2914 fileConsumer.set("resource", "/tmp/playlist.mlt");
2916 Mlt::Service service(m_mltProducer->get_service());
2918 fileConsumer.connect(service);
2919 fileConsumer.start();
2922 QList <Mlt::Producer *> Render::producersList()
2924 QList <Mlt::Producer *> prods;
2925 if (m_mltProducer == NULL) return prods;
2926 Mlt::Service service(m_mltProducer->parent().get_service());
2927 if (service.type() != tractor_type) return prods;
2928 Mlt::Tractor tractor(service);
2931 int trackNb = tractor.count();
2932 for (int t = 1; t < trackNb; t++) {
2933 Mlt::Producer *tt = tractor.track(t);
2934 Mlt::Producer trackProducer(tt);
2936 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2937 int clipNb = trackPlaylist.count();
2938 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2939 for (int i = 0; i < clipNb; i++) {
2940 Mlt::Producer *c = trackPlaylist.get_clip(i);
2941 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2943 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2944 ids.append(nprod->get("id"));
2945 prods.append(nprod);
2946 } else delete nprod;
2954 void Render::fillSlowMotionProducers()
2956 if (m_mltProducer == NULL) return;
2957 Mlt::Service service(m_mltProducer->parent().get_service());
2958 if (service.type() != tractor_type) return;
2960 Mlt::Tractor tractor(service);
2962 int trackNb = tractor.count();
2963 for (int t = 1; t < trackNb; t++) {
2964 Mlt::Producer *tt = tractor.track(t);
2965 Mlt::Producer trackProducer(tt);
2967 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2968 int clipNb = trackPlaylist.count();
2969 for (int i = 0; i < clipNb; i++) {
2970 Mlt::Producer *c = trackPlaylist.get_clip(i);
2971 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2973 QString id = nprod->get("id");
2974 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
2975 // this is a slowmotion producer, add it to the list
2976 QString url = QString::fromUtf8(nprod->get("resource"));
2977 if (!m_slowmotionProducers.contains(url)) {
2978 m_slowmotionProducers.insert(url, nprod);
2980 } else delete nprod;
2987 void Render::mltInsertTrack(int ix, bool videoTrack)
2992 Mlt::Service service(m_mltProducer->parent().get_service());
2993 mlt_service_lock(service.get_service());
2994 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2996 Mlt::Tractor tractor(service);
2998 Mlt::Playlist playlist;
2999 int ct = tractor.count();
3001 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3007 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3008 tractor.set_track(playlist, pos);
3009 Mlt::Producer newProd(tractor.track(pos));
3010 if (!videoTrack) newProd.set("hide", 1);
3012 for (; pos <= ct; pos++) {
3013 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3014 tractor.set_track(*prodToMove, pos);
3015 prodToMove = prodToMove2;
3018 tractor.set_track(playlist, ix);
3019 Mlt::Producer newProd(tractor.track(ix));
3020 if (!videoTrack) newProd.set("hide", 1);
3024 mlt_service serv = m_mltProducer->parent().get_service();
3025 mlt_service nextservice = mlt_service_get_producer(serv);
3026 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3027 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3028 QString resource = mlt_properties_get(properties, "mlt_service");
3030 while (mlt_type == "transition") {
3031 if (resource != "mix") {
3032 mlt_transition tr = (mlt_transition) nextservice;
3033 int currentTrack = mlt_transition_get_b_track(tr);
3034 int currentaTrack = mlt_transition_get_a_track(tr);
3035 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3037 if (currentTrack >= ix) {
3038 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3039 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3042 nextservice = mlt_service_producer(nextservice);
3043 if (nextservice == NULL) break;
3044 properties = MLT_SERVICE_PROPERTIES(nextservice);
3045 mlt_type = mlt_properties_get(properties, "mlt_type");
3046 resource = mlt_properties_get(properties, "mlt_service");
3049 // Add audio mix transition to last track
3050 Mlt::Field *field = tractor.field();
3051 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3052 transition->set("a_track", 1);
3053 transition->set("b_track", ct);
3054 transition->set("always_active", 1);
3055 transition->set("internal_added", 237);
3056 transition->set("combine", 1);
3057 field->plant_transition(*transition, 1, ct);
3058 //mlt_service_unlock(m_mltConsumer->get_service());
3059 mlt_service_unlock(service.get_service());
3060 //tractor.multitrack()->refresh();
3061 //tractor.refresh();
3063 blockSignals(false);
3067 void Render::mltDeleteTrack(int ix)
3070 doc.setContent(sceneList(), false);
3071 int tracksCount = doc.elementsByTagName("track").count() - 1;
3072 QDomNode track = doc.elementsByTagName("track").at(ix);
3073 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3074 QDomNodeList transitions = doc.elementsByTagName("transition");
3075 for (int i = 0; i < transitions.count(); i++) {
3076 QDomElement e = transitions.at(i).toElement();
3077 QDomNodeList props = e.elementsByTagName("property");
3078 QMap <QString, QString> mappedProps;
3079 for (int j = 0; j < props.count(); j++) {
3080 QDomElement f = props.at(j).toElement();
3081 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3083 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3084 tractor.removeChild(transitions.at(i));
3086 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3087 // Transition needs to be moved
3088 int a_track = mappedProps.value("a_track").toInt();
3089 int b_track = mappedProps.value("b_track").toInt();
3090 if (a_track > 0 && a_track >= ix) a_track --;
3091 if (b_track > 0 && b_track >= ix) b_track --;
3092 for (int j = 0; j < props.count(); j++) {
3093 QDomElement f = props.at(j).toElement();
3094 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3095 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3100 tractor.removeChild(track);
3101 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3102 setSceneList(doc.toString(), m_framePosition);
3107 void Render::updatePreviewSettings()
3109 kDebug() << "////// RESTARTING CONSUMER";
3110 if (!m_mltConsumer || !m_mltProducer) return;
3111 if (m_mltProducer->get_playtime() == 0) return;
3112 Mlt::Service service(m_mltProducer->parent().get_service());
3113 if (service.type() != tractor_type) return;
3115 //m_mltConsumer->set("refresh", 0);
3116 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3117 m_mltConsumer->purge();
3118 QString scene = sceneList();
3120 if (m_mltProducer) {
3121 pos = m_mltProducer->position();
3122 delete m_mltProducer;
3124 m_mltProducer = NULL;
3125 setSceneList(scene, pos);
3128 #include "renderer.moc"