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) :
62 m_mltTextProducer(NULL),
69 m_externalwinid(extid)
71 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
72 refreshTimer = new QTimer(this);
73 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
75 /*if (rendererName == "project") m_monitorId = 10000;
76 else m_monitorId = 10001;*/
77 osdTimer = new QTimer(this);
78 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
80 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
84 m_mltProducer = m_blackClip->cut(0, 50);
85 m_mltConsumer->connect(*m_mltProducer);
86 m_mltProducer->set_speed(0.0);
95 void Render::closeMlt()
100 delete m_mltConsumer;
102 delete m_mltProducer;
103 if (m_blackClip) delete m_blackClip;
108 void Render::buildConsumer()
111 m_activeProfile = KdenliveSettings::current_profile();
112 tmp = decodedString(m_activeProfile);
113 setenv("MLT_PROFILE", tmp, 1);
114 if (m_blackClip) delete m_blackClip;
117 m_mltProfile = new Mlt::Profile(tmp);
120 QString videoDriver = KdenliveSettings::videodrivername();
121 if (!videoDriver.isEmpty()) {
122 if (videoDriver == "x11_noaccel") {
123 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
126 unsetenv("SDL_VIDEO_YUV_HWACCEL");
129 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
131 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
132 m_mltConsumer->set("resize", 1);
133 m_mltConsumer->set("window_id", m_winid);
134 m_mltConsumer->set("terminate_on_pause", 1);
135 m_mltConsumer->set("window_background", decodedString(KdenliveSettings::window_background().name()));
137 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
138 m_mltConsumer->set("rescale", "nearest");
140 QString audioDevice = KdenliveSettings::audiodevicename();
141 if (!audioDevice.isEmpty()) {
142 tmp = decodedString(audioDevice);
143 m_mltConsumer->set("audio_device", tmp);
147 if (!videoDriver.isEmpty()) {
148 tmp = decodedString(videoDriver);
149 m_mltConsumer->set("video_driver", tmp);
153 QString audioDriver = KdenliveSettings::audiodrivername();
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 , "westley-xml", 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();
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, "fezzik", tmp);
507 } else if (url.isEmpty()) {
509 QDomElement westley = doc.createElement("westley");
510 QDomElement play = doc.createElement("playlist");
511 doc.appendChild(westley);
512 westley.appendChild(play);
513 play.appendChild(doc.importNode(xml, true));
514 char *tmp = decodedString(doc.toString());
515 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", 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);
529 if (xml.hasAttribute("force_aspect_ratio")) {
530 double aspect = xml.attribute("force_aspect_ratio").toDouble();
531 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
533 if (xml.hasAttribute("threads")) {
534 int threads = xml.attribute("threads").toInt();
535 if (threads != 1) producer->set("threads", threads);
537 if (xml.hasAttribute("video_index")) {
538 int vindex = xml.attribute("video_index").toInt();
539 if (vindex != 0) producer->set("video_index", vindex);
541 if (xml.hasAttribute("audio_index")) {
542 int aindex = xml.attribute("audio_index").toInt();
543 if (aindex != 0) producer->set("audio_index", aindex);
546 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
548 char *tmp = decodedString(clipId);
549 producer->set("id", tmp);
553 int width = (int)(height * m_mltProfile->dar());
554 QMap < QString, QString > filePropertyMap;
555 QMap < QString, QString > metadataPropertyMap;
557 int frameNumber = xml.attribute("thumbnail", "0").toInt();
558 if (frameNumber != 0) producer->seek(frameNumber);
560 filePropertyMap["duration"] = QString::number(producer->get_playtime());
561 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
563 Mlt::Frame *frame = producer->get_frame();
565 if (xml.attribute("type").toInt() == SLIDESHOW) {
566 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
567 if (xml.attribute("fade") == "1") {
568 // user wants a fade effect to slideshow
569 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
570 if (filter && filter->is_valid()) {
571 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
572 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
573 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
574 char *tmp = decodedString(xml.attribute("luma_file"));
575 filter->set("luma.resource", tmp);
577 if (xml.hasAttribute("softness")) {
578 int soft = xml.attribute("softness").toInt();
579 filter->set("luma.softness", (double) soft / 100.0);
582 Mlt::Service clipService(producer->get_service());
583 clipService.attach(*filter);
589 filePropertyMap["fps"] = producer->get("source_fps");
591 if (frame && frame->is_valid()) {
592 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
593 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
594 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
595 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
597 if (frame->get_int("test_image") == 0) {
598 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
599 filePropertyMap["type"] = "playlist";
600 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
601 } else if (frame->get_int("test_audio") == 0)
602 filePropertyMap["type"] = "av";
604 filePropertyMap["type"] = "video";
606 mlt_image_format format = mlt_image_yuv422;
608 int frame_height = 0;
609 //frame->set("rescale.interp", "hyper");
610 frame->set("normalised_height", height);
611 frame->set("normalised_width", width);
612 QPixmap pix(width, height);
614 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
615 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
616 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
617 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
619 if (!image.isNull()) {
620 pix = QPixmap::fromImage(image.rgbSwapped());
624 mlt_pool_release(new_image);
625 emit replyGetImage(clipId, pix);
627 } else if (frame->get_int("test_audio") == 0) {
628 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
629 emit replyGetImage(clipId, pixmap);
630 filePropertyMap["type"] = "audio";
634 // Retrieve audio / video codec name
638 if (producer->get_int("video_index") > -1) {
639 /*if (context->duration == AV_NOPTS_VALUE) {
640 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
641 emit removeInvalidClip(clipId);
644 // Get the video_index
645 int default_video = producer->get_int("video_index");
647 int default_audio = producer->get_int("audio_index");
650 // Find maximum stream index values
651 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
652 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
653 QString type = producer->get(property);
656 else if (type == "audio")
659 filePropertyMap["default_video"] = QString::number(default_video);
660 filePropertyMap["video_max"] = QString::number(video_max);
661 filePropertyMap["default_audio"] = QString::number(default_audio);
662 filePropertyMap["audio_max"] = QString::number(audio_max);
664 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
665 if (producer->get(property)) {
666 filePropertyMap["videocodec"] = producer->get(property);
668 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
669 if (producer->get(property))
670 filePropertyMap["videocodec"] = producer->get(property);
673 if (KdenliveSettings::dropbframes()) {
674 kDebug() << "// LOOKING FOR H264 on: " << default_video;
675 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
676 kDebug() << "PROP: " << property << " = " << producer->get(property);
677 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
678 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
679 producer->set("skip_loop_filter", "all");
680 producer->set("skip_frame", "bidir");
684 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
685 if (producer->get_int("audio_index") > -1) {
686 // Get the audio_index
687 int index = producer->get_int("audio_index");
689 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
690 if (producer->get(property)) {
691 filePropertyMap["audiocodec"] = producer->get(property);
693 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
694 if (producer->get(property))
695 filePropertyMap["audiocodec"] = producer->get(property);
700 Mlt::Properties metadata;
701 metadata.pass_values(*producer, "meta.attr.");
702 int count = metadata.count();
703 for (int i = 0; i < count; i ++) {
704 QString name = metadata.get_name(i);
705 QString value = QString::fromUtf8(metadata.get(i));
706 if (name.endsWith("markup") && !value.isEmpty())
707 metadataPropertyMap[ name.section('.', 0, -2)] = value;
710 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
711 kDebug() << "REquested fuile info for: " << url.path();
712 if (frame) delete frame;
713 //if (producer) delete producer;
717 /** Create the producer from the Westley QDomDocument */
719 void Render::initSceneList()
721 kDebug() << "-------- INIT SCENE LIST ------_";
723 QDomElement westley = doc.createElement("westley");
724 doc.appendChild(westley);
725 QDomElement prod = doc.createElement("producer");
726 prod.setAttribute("resource", "colour");
727 prod.setAttribute("colour", "red");
728 prod.setAttribute("id", "black");
729 prod.setAttribute("in", "0");
730 prod.setAttribute("out", "0");
732 QDomElement tractor = doc.createElement("tractor");
733 QDomElement multitrack = doc.createElement("multitrack");
735 QDomElement playlist1 = doc.createElement("playlist");
736 playlist1.appendChild(prod);
737 multitrack.appendChild(playlist1);
738 QDomElement playlist2 = doc.createElement("playlist");
739 multitrack.appendChild(playlist2);
740 QDomElement playlist3 = doc.createElement("playlist");
741 multitrack.appendChild(playlist3);
742 QDomElement playlist4 = doc.createElement("playlist");
743 multitrack.appendChild(playlist4);
744 QDomElement playlist5 = doc.createElement("playlist");
745 multitrack.appendChild(playlist5);
746 tractor.appendChild(multitrack);
747 westley.appendChild(tractor);
748 // kDebug()<<doc.toString();
750 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
751 setSceneList(doc, 0);
757 /** Create the producer from the Westley QDomDocument */
758 void Render::setProducer(Mlt::Producer *producer, int position)
760 if (m_winid == -1) return;
763 m_mltConsumer->stop();
766 m_mltConsumer->purge();
770 m_mltProducer->set_speed(0);
771 delete m_mltProducer;
772 m_mltProducer = NULL;
776 m_mltProducer = new Mlt::Producer(producer->get_producer());
777 } else m_mltProducer = m_blackClip->cut(0, 50);
778 /*if (KdenliveSettings::dropbframes()) {
779 m_mltProducer->set("skip_loop_filter", "all");
780 m_mltProducer->set("skip_frame", "bidir");
782 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
784 m_fps = m_mltProducer->get_fps();
786 if (position != -1) {
787 m_mltProducer->seek(position);
788 emit rendererPosition(position);
795 /** Create the producer from the Westley QDomDocument */
796 void Render::setSceneList(QDomDocument list, int position)
798 setSceneList(list.toString(), position);
801 /** Create the producer from the Westley QDomDocument */
802 void Render::setSceneList(QString playlist, int position)
804 if (m_winid == -1) return;
806 m_slowmotionProducers.clear();
808 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
811 m_mltConsumer->stop();
812 //m_mltConsumer->set("refresh", 0);
819 m_mltProducer->set_speed(0);
820 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
822 delete m_mltProducer;
823 m_mltProducer = NULL;
828 char *tmp = decodedString(playlist);
829 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
832 if (!m_mltProducer || !m_mltProducer->is_valid()) {
833 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
835 m_mltProducer->optimise();
837 /*if (KdenliveSettings::osdtimecode()) {
838 // Attach filter for on screen display of timecode
840 QString attr = "attr_check";
841 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
842 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
843 mlt_producer_attach( m_mltProducer->get_producer(), filter );
844 mlt_filter_close( filter );
846 m_osdInfo = new Mlt::Filter("data_show");
847 tmp = decodedString(m_osdProfile);
848 m_osdInfo->set("resource", tmp);
850 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
851 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
852 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
853 m_osdInfo->set("dynamic", "1");
855 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
857 m_osdInfo->set("dynamic", "0");
860 m_fps = m_mltProducer->get_fps();
861 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
863 fillSlowMotionProducers();
865 //TODO: seek to correct place after opening project.
866 // Needs to be done from another place since it crashes here.
867 m_mltProducer->seek(position);
871 //kDebug()<<"// SETSCN LST, POS: "<<position;
872 //if (position != 0) emit rendererPosition(position);
875 /** Create the producer from the Westley QDomDocument */
876 const QString Render::sceneList()
879 Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
880 m_mltProducer->optimise();
881 westleyConsumer.set("terminate_on_pause", 1);
882 Mlt::Producer prod(m_mltProducer->get_producer());
883 bool split = m_isSplitView;
884 if (split) slotSplitView(false);
885 westleyConsumer.connect(prod);
886 westleyConsumer.start();
887 while (!westleyConsumer.is_stopped()) {}
888 playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
889 if (split) slotSplitView(true);
893 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
897 doc.setContent(sceneList(), false);
898 if (!kdenliveData.isNull()) {
899 // add Kdenlive specific tags
900 QDomNode wes = doc.elementsByTagName("westley").at(0);
901 wes.appendChild(doc.importNode(kdenliveData, true));
903 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
904 kWarning() << "////// ERROR writing to file: " << path;
907 file.write(doc.toString().toUtf8());
908 if (file.error() != QFile::NoError) {
917 void Render::saveZone(KUrl url, QString desc, QPoint zone)
919 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
920 char *tmppath = decodedString("westley:" + url.path());
921 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
922 m_mltProducer->optimise();
924 westleyConsumer.set("terminate_on_pause", 1);
925 if (m_name == "clip") {
926 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
927 tmppath = decodedString(desc);
929 list.insert_at(0, prod, 0);
930 list.set("title", tmppath);
932 westleyConsumer.connect(list);
935 //TODO: not working yet, save zone from timeline
936 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
937 /* Mlt::Service service(p1->parent().get_service());
938 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
940 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
941 tmppath = decodedString(desc);
942 //prod->set("title", tmppath);
944 westleyConsumer.connect(*p1); //list);
947 westleyConsumer.start();
950 double Render::fps() const
955 void Render::connectPlaylist()
957 if (!m_mltConsumer) return;
958 //m_mltConsumer->set("refresh", "0");
959 m_mltConsumer->connect(*m_mltProducer);
960 m_mltProducer->set_speed(0);
961 m_mltConsumer->start();
962 emit durationChanged(m_mltProducer->get_playtime());
965 if (m_mltConsumer->start() == -1) {
966 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."));
967 m_mltConsumer = NULL;
974 void Render::refreshDisplay()
977 if (!m_mltProducer) return;
978 //m_mltConsumer->set("refresh", 0);
980 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
981 /*if (KdenliveSettings::osdtimecode()) {
982 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
983 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
984 m_osdInfo->set("dynamic", "1");
985 m_mltProducer->attach(*m_osdInfo);
988 m_mltProducer->detach(*m_osdInfo);
989 m_osdInfo->set("dynamic", "0");
994 void Render::setVolume(double /*volume*/)
996 if (!m_mltConsumer || !m_mltProducer) return;
998 m_mltConsumer->set("refresh", 0);
999 // Attach filter for on screen display of timecode
1000 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1001 mlt_properties_set_double( properties, "meta.volume", volume );
1002 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1003 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1005 if (!KdenliveSettings::osdtimecode()) {
1006 m_mltProducer->detach(*m_osdInfo);
1007 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1008 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1011 osdTimer->setSingleShot(2500);
1014 void Render::slotOsdTimeout()
1016 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1017 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1018 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1019 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1023 void Render::start()
1025 kDebug() << "----- STARTING MONITOR: " << m_name;
1026 if (m_winid == -1) {
1027 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1031 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1032 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1033 if (m_mltConsumer->start() == -1) {
1034 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."));
1035 m_mltConsumer = NULL;
1038 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1039 m_isBlocked = false;
1043 m_isBlocked = false;
1046 void Render::clear()
1048 kDebug() << " ********* RENDER CLEAR";
1049 if (m_mltConsumer) {
1050 //m_mltConsumer->set("refresh", 0);
1051 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1054 if (m_mltProducer) {
1055 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1056 m_mltProducer->set_speed(0.0);
1057 delete m_mltProducer;
1058 m_mltProducer = NULL;
1065 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1066 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1068 //m_mltConsumer->set("refresh", 0);
1069 m_mltConsumer->stop();
1070 // delete m_mltConsumer;
1071 // m_mltConsumer = NULL;
1073 kDebug() << "///////////// RENDER STOP2-------";
1076 if (m_mltProducer) {
1077 if (m_isZoneMode) resetZoneMode();
1078 m_mltProducer->set_speed(0.0);
1079 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1080 //kDebug() << m_mltProducer->get_length();
1082 kDebug() << "///////////// RENDER STOP3-------";
1085 void Render::stop(const GenTime & startTime)
1088 kDebug() << "///////////// RENDER STOP-------2";
1089 if (m_mltProducer) {
1090 if (m_isZoneMode) resetZoneMode();
1091 m_mltProducer->set_speed(0.0);
1092 m_mltProducer->seek((int) startTime.frames(m_fps));
1094 m_mltConsumer->purge();
1097 void Render::pause()
1099 if (!m_mltProducer || !m_mltConsumer)
1101 if (m_mltProducer->get_speed() == 0.0) return;
1102 if (m_isZoneMode) resetZoneMode();
1104 m_mltConsumer->set("refresh", 0);
1105 m_mltProducer->set_speed(0.0);
1106 emit rendererPosition(m_framePosition);
1107 m_mltProducer->seek(m_framePosition);
1108 m_mltConsumer->purge();
1111 void Render::switchPlay()
1113 if (!m_mltProducer || !m_mltConsumer)
1115 if (m_isZoneMode) resetZoneMode();
1116 if (m_mltProducer->get_speed() == 0.0) {
1117 m_isBlocked = false;
1118 m_mltProducer->set_speed(1.0);
1119 m_mltConsumer->set("refresh", 1);
1122 m_mltConsumer->set("refresh", 0);
1123 m_mltProducer->set_speed(0.0);
1124 emit rendererPosition(m_framePosition);
1125 m_mltProducer->seek(m_framePosition);
1126 m_mltConsumer->purge();
1127 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1128 //m_mltConsumer->set("refresh", 0);
1129 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1130 m_mltProducer->set_speed(0);
1131 m_mltProducer->seek( position );
1132 //m_mltProducer->seek((int) m_framePosition);
1133 m_isBlocked = false;*/
1135 /*if (speed == 0.0) {
1136 m_mltProducer->seek((int) m_framePosition + 1);
1137 m_mltConsumer->purge();
1142 void Render::play(double speed)
1146 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1147 m_isBlocked = false;
1148 m_mltProducer->set_speed(speed);
1149 /*if (speed == 0.0) {
1150 m_mltProducer->seek((int) m_framePosition + 1);
1151 m_mltConsumer->purge();
1156 void Render::play(const GenTime & startTime)
1158 if (!m_mltProducer || !m_mltConsumer)
1160 m_isBlocked = false;
1161 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1162 m_mltProducer->set_speed(1.0);
1163 m_mltConsumer->set("refresh", 1);
1166 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1168 if (!m_mltProducer || !m_mltConsumer)
1170 //m_mltProducer->set("eof", "loop");
1171 m_isLoopMode = true;
1172 m_loopStart = startTime;
1173 playZone(startTime, stopTime);
1176 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1178 if (!m_mltProducer || !m_mltConsumer)
1180 m_isBlocked = false;
1181 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1182 m_mltProducer->set("out", stopTime.frames(m_fps));
1183 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1184 m_mltProducer->set_speed(1.0);
1185 m_mltConsumer->set("refresh", 1);
1186 m_isZoneMode = true;
1189 void Render::resetZoneMode()
1191 if (!m_isZoneMode && !m_isLoopMode) return;
1192 m_mltProducer->set("out", m_originalOut);
1193 //m_mltProducer->set("eof", "pause");
1194 m_isZoneMode = false;
1195 m_isLoopMode = false;
1198 void Render::seekToFrame(int pos)
1200 //kDebug()<<" ********* RENDER SEEK TO POS";
1203 m_isBlocked = false;
1205 m_mltProducer->seek(pos);
1209 void Render::askForRefresh()
1211 // Use a Timer so that we don't refresh too much
1212 refreshTimer->start(200);
1215 void Render::doRefresh()
1217 // Use a Timer so that we don't refresh too much
1218 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1221 void Render::refresh()
1223 if (!m_mltProducer || m_isBlocked)
1225 refreshTimer->stop();
1226 if (m_mltConsumer) {
1227 m_mltConsumer->set("refresh", 1);
1231 double Render::playSpeed()
1233 if (m_mltProducer) return m_mltProducer->get_speed();
1237 GenTime Render::seekPosition() const
1239 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1240 else return GenTime();
1244 const QString & Render::rendererName() const
1250 void Render::emitFrameNumber(double position)
1252 m_framePosition = position;
1253 emit rendererPosition((int) position);
1254 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1257 void Render::emitConsumerStopped()
1259 // This is used to know when the playing stopped
1260 if (m_mltProducer) {
1261 double pos = m_mltProducer->position();
1262 if (m_isLoopMode) play(m_loopStart);
1263 else if (m_isZoneMode) resetZoneMode();
1264 emit rendererStopped((int) pos);
1265 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1266 //new QCustomEvent(10002));
1272 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1274 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1278 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1280 if (!m_mltProducer) {
1281 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1285 //int height = 1080;//KdenliveSettings::defaultheight();
1286 //int width = 1940; //KdenliveSettings::displaywidth();
1288 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1290 QPixmap pix(width, height);
1291 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1292 m_convert.set("forced", mlt_image_rgb24a);
1293 m_mltProducer->attach(m_convert);
1294 Mlt::Frame * frame = m_mltProducer->get_frame();
1295 m_mltProducer->detach(m_convert);
1297 pix = frameThumbnail(frame, width, height);
1300 pix.save(url.path(), "PNG");
1301 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1304 /** MLT PLAYLIST DIRECT MANIPULATON **/
1307 void Render::mltCheckLength()
1309 //kDebug()<<"checking track length: "<<track<<"..........";
1311 Mlt::Service service(m_mltProducer->get_service());
1312 Mlt::Tractor tractor(service);
1314 int trackNb = tractor.count();
1315 double duration = 0;
1316 double trackDuration;
1318 Mlt::Producer trackProducer(tractor.track(0));
1319 duration = trackProducer.get_playtime() - 1;
1320 m_mltProducer->set("out", duration);
1321 emit durationChanged((int) duration);
1324 while (trackNb > 1) {
1325 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1326 trackDuration = trackProducer.get_playtime() - 1;
1328 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1329 if (trackDuration > duration) duration = trackDuration;
1333 Mlt::Producer blackTrackProducer(tractor.track(0));
1334 double blackDuration = blackTrackProducer.get_playtime() - 1;
1336 if (blackDuration != duration) {
1337 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1338 blackTrackPlaylist.clear();
1339 int dur = (int)duration;
1340 while (dur > 14000) {
1341 blackTrackPlaylist.append(*m_blackClip, 0, 13999);
1345 blackTrackPlaylist.append(*m_blackClip, 0, dur);
1347 m_mltProducer->set("out", duration);
1348 emit durationChanged((int)duration);
1352 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1354 if (!m_mltProducer) {
1355 kDebug() << "PLAYLIST NOT INITIALISED //////";
1358 Mlt::Producer parentProd(m_mltProducer->parent());
1359 if (parentProd.get_producer() == NULL) {
1360 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1364 Mlt::Service service(parentProd.get_service());
1365 Mlt::Tractor tractor(service);
1366 mlt_service_lock(service.get_service());
1367 Mlt::Producer trackProducer(tractor.track(info.track));
1368 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1369 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1371 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1372 // We want a slowmotion producer
1373 double speed = element.attribute("speed", "1.0").toDouble();
1374 QString url = QString::fromUtf8(prod->get("resource"));
1375 url.append('?' + QString::number(speed));
1376 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1377 if (!slowprod || slowprod->get_producer() == NULL) {
1378 char *tmp = decodedString(url);
1379 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1381 QString id = prod->get("id");
1382 if (id.contains('_')) id = id.section('_', 0, 0);
1383 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1384 tmp = decodedString(producerid);
1385 slowprod->set("id", tmp);
1387 m_slowmotionProducers.insert(url, slowprod);
1392 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1393 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1395 /*if (QString(prod->get("transparency")).toInt() == 1)
1396 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1398 mlt_service_unlock(service.get_service());
1400 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1401 //tractor.multitrack()->refresh();
1402 //tractor.refresh();
1406 void Render::mltCutClip(int track, GenTime position)
1411 Mlt::Service service(m_mltProducer->parent().get_service());
1412 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1414 Mlt::Tractor tractor(service);
1415 Mlt::Producer trackProducer(tractor.track(track));
1416 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1419 /* // Display playlist info
1420 kDebug()<<"//////////// BEFORE";
1421 for (int i = 0; i < trackPlaylist.count(); i++) {
1422 int blankStart = trackPlaylist.clip_start(i);
1423 int blankDuration = trackPlaylist.clip_length(i) - 1;
1425 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1426 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1429 int cutPos = (int) position.frames(m_fps);
1431 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1432 if (trackPlaylist.is_blank(clipIndex)) {
1433 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1434 m_isBlocked = false;
1437 mlt_service_lock(service.get_service());
1438 int clipStart = trackPlaylist.clip_start(clipIndex);
1439 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1440 mlt_service_unlock(service.get_service());
1442 // duplicate effects
1443 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1444 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1446 if (original == NULL || clip == NULL) {
1447 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1449 Mlt::Service clipService(original->get_service());
1450 Mlt::Service dupService(clip->get_service());
1452 Mlt::Filter *filter = clipService.filter(ct);
1454 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1455 // looks like there is no easy way to duplicate a filter,
1456 // so we will create a new one and duplicate its properties
1457 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1458 if (dup && dup->is_valid()) {
1459 Mlt::Properties entries(filter->get_properties());
1460 for (int i = 0;i < entries.count();i++) {
1461 dup->set(entries.get_name(i), entries.get(i));
1463 dupService.attach(*dup);
1467 filter = clipService.filter(ct);
1470 /* // Display playlist info
1471 kDebug()<<"//////////// AFTER";
1472 for (int i = 0; i < trackPlaylist.count(); i++) {
1473 int blankStart = trackPlaylist.clip_start(i);
1474 int blankDuration = trackPlaylist.clip_length(i) - 1;
1476 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1477 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1480 m_isBlocked = false;
1483 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1486 mltRemoveClip(info.track, info.startPos);
1487 mltInsertClip(info, element, prod);
1491 bool Render::mltRemoveClip(int track, GenTime position)
1493 Mlt::Service service(m_mltProducer->parent().get_service());
1494 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1496 Mlt::Tractor tractor(service);
1497 Mlt::Producer trackProducer(tractor.track(track));
1498 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1499 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1501 /* // Display playlist info
1502 kDebug()<<"//// BEFORE";
1503 for (int i = 0; i < trackPlaylist.count(); i++) {
1504 int blankStart = trackPlaylist.clip_start(i);
1505 int blankDuration = trackPlaylist.clip_length(i) - 1;
1507 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1508 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1511 if (trackPlaylist.is_blank(clipIndex)) {
1512 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1516 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1517 trackPlaylist.replace_with_blank(clipIndex);
1518 trackPlaylist.consolidate_blanks(0);
1519 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1520 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1522 /* // Display playlist info
1523 kDebug()<<"//// AFTER";
1524 for (int i = 0; i < trackPlaylist.count(); i++) {
1525 int blankStart = trackPlaylist.clip_start(i);
1526 int blankDuration = trackPlaylist.clip_length(i) - 1;
1528 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1529 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1532 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1533 m_isBlocked = false;
1537 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1539 if (!m_mltProducer) {
1540 kDebug() << "PLAYLIST NOT INITIALISED //////";
1543 Mlt::Producer parentProd(m_mltProducer->parent());
1544 if (parentProd.get_producer() == NULL) {
1545 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1549 Mlt::Service service(parentProd.get_service());
1550 Mlt::Tractor tractor(service);
1551 int insertPos = pos.frames(m_fps);
1553 Mlt::Producer trackProducer(tractor.track(track));
1554 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1555 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1556 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1557 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1558 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1561 int Render::mltTrackDuration(int track)
1563 if (!m_mltProducer) {
1564 kDebug() << "PLAYLIST NOT INITIALISED //////";
1567 Mlt::Producer parentProd(m_mltProducer->parent());
1568 if (parentProd.get_producer() == NULL) {
1569 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1573 Mlt::Service service(parentProd.get_service());
1574 Mlt::Tractor tractor(service);
1576 Mlt::Producer trackProducer(tractor.track(track));
1577 return trackProducer.get_playtime() - 1;
1580 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
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 //////";
1591 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1592 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1594 Mlt::Service service(parentProd.get_service());
1595 Mlt::Tractor tractor(service);
1596 mlt_service_lock(service.get_service());
1597 int diff = duration.frames(m_fps);
1598 int offset = timeOffset.frames(m_fps);
1602 // insert space in one track only
1603 Mlt::Producer trackProducer(tractor.track(track));
1604 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1605 insertPos = trackClipStartList.value(track);
1606 if (insertPos != -1) {
1607 insertPos += offset;
1608 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1609 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1611 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1612 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1613 int position = trackPlaylist.clip_start(clipIndex);
1614 trackPlaylist.remove_region(position, - diff - 1);
1616 trackPlaylist.consolidate_blanks(0);
1618 // now move transitions
1619 mlt_service serv = m_mltProducer->parent().get_service();
1620 mlt_service nextservice = mlt_service_get_producer(serv);
1621 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1622 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1623 QString resource = mlt_properties_get(properties, "mlt_service");
1625 while (mlt_type == "transition") {
1626 mlt_transition tr = (mlt_transition) nextservice;
1627 int currentTrack = mlt_transition_get_b_track(tr);
1628 int currentIn = (int) mlt_transition_get_in(tr);
1629 int currentOut = (int) mlt_transition_get_out(tr);
1630 insertPos = trackTransitionStartList.value(track);
1631 if (insertPos != -1) {
1632 insertPos += offset;
1633 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1634 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1637 nextservice = mlt_service_producer(nextservice);
1638 if (nextservice == NULL) break;
1639 properties = MLT_SERVICE_PROPERTIES(nextservice);
1640 mlt_type = mlt_properties_get(properties, "mlt_type");
1641 resource = mlt_properties_get(properties, "mlt_service");
1644 int trackNb = tractor.count();
1645 while (trackNb > 1) {
1646 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1647 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1650 //int clipNb = trackPlaylist.count();
1651 insertPos = trackClipStartList.value(trackNb - 1);
1652 if (insertPos != -1) {
1653 insertPos += offset;
1655 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1656 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1657 for (int i = 0; i < clipNb; i++) {
1658 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1659 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1660 kDebug()<<"-------------";
1662 kDebug()<<"END-------------";*/
1665 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1666 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1668 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1669 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1670 int position = trackPlaylist.clip_start(clipIndex);
1671 trackPlaylist.remove_region(position, - diff - 1);
1673 trackPlaylist.consolidate_blanks(0);
1677 // now move transitions
1678 mlt_service serv = m_mltProducer->parent().get_service();
1679 mlt_service nextservice = mlt_service_get_producer(serv);
1680 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1681 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1682 QString resource = mlt_properties_get(properties, "mlt_service");
1684 while (mlt_type == "transition") {
1685 mlt_transition tr = (mlt_transition) nextservice;
1686 int currentIn = (int) mlt_transition_get_in(tr);
1687 int currentOut = (int) mlt_transition_get_out(tr);
1688 int currentTrack = mlt_transition_get_b_track(tr);
1689 insertPos = trackTransitionStartList.value(currentTrack);
1690 if (insertPos != -1) {
1691 insertPos += offset;
1692 if (currentOut > insertPos && resource != "mix") {
1693 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1696 nextservice = mlt_service_producer(nextservice);
1697 if (nextservice == NULL) break;
1698 properties = MLT_SERVICE_PROPERTIES(nextservice);
1699 mlt_type = mlt_properties_get(properties, "mlt_type");
1700 resource = mlt_properties_get(properties, "mlt_service");
1703 mlt_service_unlock(service.get_service());
1705 m_mltConsumer->set("refresh", 1);
1708 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1712 Mlt::Service service(m_mltProducer->parent().get_service());
1713 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1714 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1715 Mlt::Tractor tractor(service);
1716 Mlt::Producer trackProducer(tractor.track(info.track));
1717 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1718 int startPos = info.startPos.frames(m_fps);
1719 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1720 int clipLength = trackPlaylist.clip_length(clipIndex);
1722 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1723 if (!clip.is_valid() || clip.is_blank()) {
1727 Mlt::Producer clipparent = clip.parent();
1728 if (!clipparent.is_valid() || clipparent.is_blank()) {
1732 QString serv = clipparent.get("mlt_service");
1733 QString id = clipparent.get("id");
1734 //kDebug() << "CLIP SERVICE: " << serv;
1735 if (serv == "avformat" && speed != 1.0) {
1736 mlt_service_lock(service.get_service());
1737 QString url = QString::fromUtf8(clipparent.get("resource"));
1738 url.append('?' + QString::number(speed));
1739 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1740 if (!slowprod || slowprod->get_producer() == NULL) {
1741 char *tmp = decodedString(url);
1742 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1744 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1745 tmp = decodedString(producerid);
1746 slowprod->set("id", tmp);
1748 m_slowmotionProducers.insert(url, slowprod);
1750 trackPlaylist.replace_with_blank(clipIndex);
1751 trackPlaylist.consolidate_blanks(0);
1752 // Check that the blank space is long enough for our new duration
1753 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1754 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1756 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1757 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1758 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1759 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1760 trackPlaylist.insert_at(startPos, *cut, 1);
1761 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1762 newLength = trackPlaylist.clip_length(clipIndex);
1763 mlt_service_unlock(service.get_service());
1764 } else if (speed == 1.0) {
1765 mlt_service_lock(service.get_service());
1767 trackPlaylist.replace_with_blank(clipIndex);
1768 trackPlaylist.consolidate_blanks(0);
1770 // Check that the blank space is long enough for our new duration
1771 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1772 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1775 GenTime oldDuration = GenTime(clipLength, m_fps);
1776 GenTime newDuration = oldDuration * oldspeed;
1777 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1778 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1779 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1780 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1781 trackPlaylist.insert_at(startPos, *cut, 1);
1782 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1783 newLength = trackPlaylist.clip_length(clipIndex);
1784 mlt_service_unlock(service.get_service());
1786 } else if (serv == "framebuffer") {
1787 mlt_service_lock(service.get_service());
1788 QString url = QString::fromUtf8(clipparent.get("resource"));
1789 url = url.section('?', 0, 0);
1790 url.append('?' + QString::number(speed));
1791 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1792 if (!slowprod || slowprod->get_producer() == NULL) {
1793 char *tmp = decodedString(url);
1794 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1796 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1797 tmp = decodedString(producerid);
1798 slowprod->set("id", tmp);
1800 m_slowmotionProducers.insert(url, slowprod);
1802 trackPlaylist.replace_with_blank(clipIndex);
1803 trackPlaylist.consolidate_blanks(0);
1805 GenTime oldDuration = GenTime(clipLength, m_fps);
1806 GenTime newDuration = oldDuration * oldspeed / speed;
1808 // Check that the blank space is long enough for our new duration
1809 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1810 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1813 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1814 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1815 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1816 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1818 trackPlaylist.insert_at(startPos, *cut, 1);
1819 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1820 newLength = trackPlaylist.clip_length(clipIndex);
1822 mlt_service_unlock(service.get_service());
1824 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1825 m_isBlocked = false;
1829 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1831 kDebug() << "// TRYing to remove effect at: " << index;
1832 Mlt::Service service(m_mltProducer->parent().get_service());
1833 bool success = false;
1834 Mlt::Tractor tractor(service);
1835 Mlt::Producer trackProducer(tractor.track(track));
1836 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1837 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1838 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1840 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1843 Mlt::Service clipService(clip->get_service());
1844 // if (tag.startsWith("ladspa")) tag = "ladspa";
1847 Mlt::Filter *filter = clipService.filter(ct);
1849 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1850 if (clipService.detach(*filter) == 0) success = true;
1851 kDebug() << " / / / DLEETED EFFECT: " << ct;
1852 } else if (updateIndex) {
1853 // Adjust the other effects index
1854 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1857 filter = clipService.filter(ct);
1859 m_isBlocked = false;
1860 if (doRefresh) refresh();
1865 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1868 Mlt::Service service(m_mltProducer->parent().get_service());
1870 Mlt::Tractor tractor(service);
1871 Mlt::Producer trackProducer(tractor.track(track));
1872 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1874 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1878 Mlt::Service clipService(clip->get_service());
1881 // temporarily remove all effects after insert point
1882 QList <Mlt::Filter *> filtersList;
1883 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1885 Mlt::Filter *filter = clipService.filter(ct);
1887 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1888 filtersList.append(filter);
1889 clipService.detach(*filter);
1891 filter = clipService.filter(ct);
1895 QString tag = params.paramValue("tag");
1896 kDebug() << " / / INSERTING EFFECT: " << tag;
1897 if (tag.startsWith("ladspa")) tag = "ladspa";
1898 char *filterTag = decodedString(tag);
1899 char *filterId = decodedString(params.paramValue("id"));
1900 QHash<QString, QString>::Iterator it;
1901 QString kfr = params.paramValue("keyframes");
1903 if (!kfr.isEmpty()) {
1904 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1905 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1906 char *starttag = decodedString(params.paramValue("starttag", "start"));
1907 char *endtag = decodedString(params.paramValue("endtag", "end"));
1908 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1909 int duration = clip->get_playtime();
1910 //double max = params.paramValue("max").toDouble();
1911 double min = params.paramValue("min").toDouble();
1912 double factor = params.paramValue("factor", "1").toDouble();
1913 params.removeParam("starttag");
1914 params.removeParam("endtag");
1915 params.removeParam("keyframes");
1916 params.removeParam("min");
1917 params.removeParam("max");
1918 params.removeParam("factor");
1920 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1921 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1922 if (filter && filter->is_valid()) {
1923 filter->set("kdenlive_id", filterId);
1924 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1925 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1926 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1927 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1928 if (x2 == -1) x2 = duration;
1930 for (int j = 0; j < params.count(); j++) {
1931 char *name = decodedString(params.at(j).name());
1932 char *value = decodedString(params.at(j).value());
1933 filter->set(name, value);
1938 filter->set("in", x1);
1939 filter->set("out", x2);
1940 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1941 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1942 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1943 clipService.attach(*filter);
1950 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1951 if (filter && filter->is_valid())
1952 filter->set("kdenlive_id", filterId);
1954 kDebug() << "filter is NULL";
1955 m_isBlocked = false;
1959 params.removeParam("kdenlive_id");
1961 for (int j = 0; j < params.count(); j++) {
1962 char *name = decodedString(params.at(j).name());
1963 char *value = decodedString(params.at(j).value());
1964 filter->set(name, value);
1970 QString effectArgs = params.paramValue("id").section('_', 1);
1972 params.removeParam("id");
1973 params.removeParam("kdenlive_ix");
1974 params.removeParam("tag");
1975 params.removeParam("disabled");
1977 for (int j = 0; j < params.count(); j++) {
1978 effectArgs.append(' ' + params.at(j).value());
1980 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1981 char *value = decodedString(effectArgs.simplified());
1982 filter->set("effect", value);
1987 // attach filter to the clip
1988 clipService.attach(*filter);
1993 // re-add following filters
1994 for (int i = 0; i < filtersList.count(); i++) {
1995 clipService.attach(*(filtersList.at(i)));
1998 m_isBlocked = false;
1999 if (doRefresh) refresh();
2003 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2005 QString index = params.paramValue("kdenlive_ix");
2006 QString tag = params.paramValue("tag");
2008 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2009 // This is a keyframe effect, to edit it, we remove it and re-add it.
2010 mltRemoveEffect(track, position, index, true);
2011 bool success = mltAddEffect(track, position, params);
2016 Mlt::Service service(m_mltProducer->parent().get_service());
2018 Mlt::Tractor tractor(service);
2019 Mlt::Producer trackProducer(tractor.track(track));
2020 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2021 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2022 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2024 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2027 Mlt::Service clipService(clip->get_service());
2030 Mlt::Filter *filter = clipService.filter(ct);
2032 if (filter->get("kdenlive_ix") == index) {
2036 filter = clipService.filter(ct);
2040 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2041 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2043 filter = clipService.filter(ct);
2044 QList <Mlt::Filter *> filtersList;
2046 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2047 filtersList.append(filter);
2048 clipService.detach(*filter);
2050 filter = clipService.filter(ct);
2052 bool success = mltAddEffect(track, position, params);
2054 for (int i = 0; i < filtersList.count(); i++) {
2055 clipService.attach(*(filtersList.at(i)));
2058 m_isBlocked = false;
2062 for (int j = 0; j < params.count(); j++) {
2063 char *name = decodedString(params.at(j).name());
2064 char *value = decodedString(params.at(j).value());
2065 filter->set(name, value);
2070 m_isBlocked = false;
2075 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2078 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2079 Mlt::Service service(m_mltProducer->parent().get_service());
2081 Mlt::Tractor tractor(service);
2082 Mlt::Producer trackProducer(tractor.track(track));
2083 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2084 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2085 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2087 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2090 Mlt::Service clipService(clip->get_service());
2093 QList <Mlt::Filter *> filtersList;
2094 Mlt::Filter *filter = clipService.filter(ct);
2096 if (newPos > oldPos) {
2098 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2099 filter->set("kdenlive_ix", newPos);
2100 filtersList.append(filter);
2101 clipService.detach(*filter);
2102 filter = clipService.filter(ct);
2103 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2104 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2106 filter = clipService.filter(ct);
2110 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2111 filtersList.append(filter);
2112 clipService.detach(*filter);
2114 filter = clipService.filter(ct);
2118 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2119 filter->set("kdenlive_ix", newPos);
2120 filtersList.append(filter);
2121 clipService.detach(*filter);
2123 filter = clipService.filter(ct);
2127 filter = clipService.filter(ct);
2129 int pos = QString(filter->get("kdenlive_ix")).toInt();
2130 if (pos >= newPos) {
2131 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2132 filtersList.append(filter);
2133 clipService.detach(*filter);
2135 filter = clipService.filter(ct);
2139 for (int i = 0; i < filtersList.count(); i++) {
2140 clipService.attach(*(filtersList.at(i)));
2143 m_isBlocked = false;
2147 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2151 Mlt::Service service(m_mltProducer->parent().get_service());
2153 Mlt::Tractor tractor(service);
2154 Mlt::Producer trackProducer(tractor.track(info.track));
2155 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2157 /* // Display playlist info
2158 kDebug()<<"//////////// BEFORE RESIZE";
2159 for (int i = 0; i < trackPlaylist.count(); i++) {
2160 int blankStart = trackPlaylist.clip_start(i);
2161 int blankDuration = trackPlaylist.clip_length(i) - 1;
2163 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2164 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2167 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2168 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2169 m_isBlocked = false;
2172 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2173 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2174 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2175 int previousStart = clip->get_in();
2176 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2177 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2178 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2179 trackPlaylist.consolidate_blanks(0);
2180 // skip to next clip
2182 int diff = newDuration - previousDuration;
2183 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2185 // clip was made longer, trim next blank if there is one.
2186 if (clipIndex < trackPlaylist.count()) {
2187 // If this is not the last clip in playlist
2188 if (trackPlaylist.is_blank(clipIndex)) {
2189 int blankStart = trackPlaylist.clip_start(clipIndex);
2190 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2191 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2192 if (diff - blankDuration == 1) {
2193 trackPlaylist.remove(clipIndex);
2194 } else trackPlaylist.remove_region(blankStart, diff - 1);
2196 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2199 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2201 trackPlaylist.consolidate_blanks(0);
2204 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2205 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2206 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2207 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2208 ItemInfo transpinfo;
2209 transpinfo.startPos = info.startPos;
2210 transpinfo.endPos = info.startPos + clipDuration;
2211 transpinfo.track = info.track;
2212 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2214 m_isBlocked = false;
2215 m_mltConsumer->set("refresh", 1);
2219 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2221 Mlt::Service service(m_mltProducer->parent().get_service());
2222 Mlt::Tractor tractor(service);
2223 Mlt::Producer trackProducer(tractor.track(track));
2226 if (blind) trackProducer.set("hide", 3);
2227 else trackProducer.set("hide", 2);
2229 trackProducer.set("hide", 1);
2231 trackProducer.set("hide", 0);
2233 tractor.multitrack()->refresh();
2239 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2241 Mlt::Service service(m_mltProducer->parent().get_service());
2242 int frameOffset = (int) diff.frames(m_fps);
2243 Mlt::Tractor tractor(service);
2244 Mlt::Producer trackProducer(tractor.track(info.track));
2245 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2246 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2247 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2250 mlt_service_lock(service.get_service());
2251 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2252 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2254 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2255 mlt_service_unlock(service.get_service());
2258 int previousStart = clip->get_in();
2259 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2261 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2262 m_isBlocked = false;
2263 mlt_service_unlock(service.get_service());
2264 m_mltConsumer->set("refresh", 1);
2268 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2270 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2271 Mlt::Service service(m_mltProducer->parent().get_service());
2272 int moveFrame = (int) diff.frames(m_fps);
2273 Mlt::Tractor tractor(service);
2274 Mlt::Producer trackProducer(tractor.track(info.track));
2275 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2276 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2277 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2280 mlt_service_lock(service.get_service());
2281 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2282 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2284 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2285 mlt_service_unlock(service.get_service());
2288 int previousStart = clip->get_in();
2289 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2291 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2292 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2293 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2295 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2296 int blankIndex = clipIndex - 1;
2297 int blankLength = trackPlaylist.clip_length(blankIndex);
2298 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2299 if (! trackPlaylist.is_blank(blankIndex)) {
2300 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2302 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2303 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2305 trackPlaylist.consolidate_blanks(0);
2306 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2307 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2308 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2309 ItemInfo transpinfo;
2310 transpinfo.startPos = info.startPos + diff;
2311 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2312 transpinfo.track = info.track;
2313 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2315 m_isBlocked = false;
2316 //m_mltConsumer->set("refresh", 1);
2317 mlt_service_unlock(service.get_service());
2318 m_mltConsumer->set("refresh", 1);
2322 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2324 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2328 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2330 if (prod == NULL || !prod->is_valid()) {
2331 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2334 kDebug() << "NEW PROD ID: " << prod->get("id");
2335 m_mltConsumer->set("refresh", 0);
2336 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2337 mlt_service_lock(m_mltConsumer->get_service());
2338 Mlt::Service service(m_mltProducer->parent().get_service());
2339 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2341 Mlt::Tractor tractor(service);
2342 Mlt::Producer trackProducer(tractor.track(track));
2343 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2344 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2345 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2346 if (clipProducer.is_blank()) {
2347 kDebug() << "// ERROR UPDATING CLIP PROD";
2348 mlt_service_unlock(m_mltConsumer->get_service());
2349 m_isBlocked = false;
2352 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2354 // move all effects to the correct producer
2355 Mlt::Service clipService(clipProducer.get_service());
2356 Mlt::Service newClipService(clip->get_service());
2359 Mlt::Filter *filter = clipService.filter(ct);
2361 if (filter->get("kdenlive_ix") != 0) {
2362 clipService.detach(*filter);
2363 newClipService.attach(*filter);
2365 filter = clipService.filter(ct);
2368 trackPlaylist.insert_at(pos, clip, 1);
2369 mlt_service_unlock(m_mltConsumer->get_service());
2370 m_isBlocked = false;
2373 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2377 m_mltConsumer->set("refresh", 0);
2378 mlt_service_lock(m_mltConsumer->get_service());
2379 Mlt::Service service(m_mltProducer->parent().get_service());
2380 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2382 Mlt::Tractor tractor(service);
2383 Mlt::Producer trackProducer(tractor.track(startTrack));
2384 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2385 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2386 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2387 bool checkLength = false;
2388 if (endTrack == startTrack) {
2389 //mlt_service_lock(service.get_service());
2390 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2391 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2392 // error, destination is not empty
2393 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2394 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2395 mlt_service_unlock(m_mltConsumer->get_service());
2396 m_isBlocked = false;
2399 trackPlaylist.consolidate_blanks(0);
2400 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2401 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2402 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2404 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2406 //mlt_service_unlock(service.get_service());
2408 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2409 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2410 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2411 // error, destination is not empty
2412 mlt_service_unlock(m_mltConsumer->get_service());
2413 m_isBlocked = false;
2416 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2417 if (clipProducer.is_blank()) {
2418 // error, destination is not empty
2419 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2420 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2421 mlt_service_unlock(m_mltConsumer->get_service());
2422 m_isBlocked = false;
2425 trackPlaylist.consolidate_blanks(0);
2426 destTrackPlaylist.consolidate_blanks(1);
2427 Mlt::Producer *clip;
2428 // check if we are moving a slowmotion producer
2429 QString serv = clipProducer.parent().get("mlt_service");
2430 QString currentid = clipProducer.parent().get("id");
2431 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2432 clip = &clipProducer;
2433 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2435 // move all effects to the correct producer
2436 Mlt::Service clipService(clipProducer.get_service());
2437 Mlt::Service newClipService(clip->get_service());
2440 Mlt::Filter *filter = clipService.filter(ct);
2442 if (filter->get("kdenlive_ix") != 0) {
2443 clipService.detach(*filter);
2444 newClipService.attach(*filter);
2446 filter = clipService.filter(ct);
2449 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2450 destTrackPlaylist.consolidate_blanks(0);
2451 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2452 kDebug() << "//////// moving clip transparency";
2453 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2455 if (clipIndex > trackPlaylist.count()) checkLength = true;
2456 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2460 if (checkLength) mltCheckLength();
2461 mlt_service_unlock(m_mltConsumer->get_service());
2462 m_isBlocked = false;
2463 m_mltConsumer->set("refresh", 1);
2467 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2469 int new_in = (int)newIn.frames(m_fps);
2470 int new_out = (int)newOut.frames(m_fps) - 1;
2471 if (new_in >= new_out) return false;
2473 Mlt::Service service(m_mltProducer->parent().get_service());
2474 Mlt::Tractor tractor(service);
2476 mlt_service_lock(service.get_service());
2477 m_mltConsumer->set("refresh", 0);
2480 mlt_service serv = m_mltProducer->parent().get_service();
2481 mlt_service nextservice = mlt_service_get_producer(serv);
2482 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2483 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2484 QString resource = mlt_properties_get(properties, "mlt_service");
2485 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2487 while (mlt_type == "transition") {
2488 mlt_transition tr = (mlt_transition) nextservice;
2489 int currentTrack = mlt_transition_get_b_track(tr);
2490 int currentIn = (int) mlt_transition_get_in(tr);
2491 int currentOut = (int) mlt_transition_get_out(tr);
2493 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2494 mlt_transition_set_in_and_out(tr, new_in, new_out);
2495 if (newTrack - startTrack != 0) {
2496 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2498 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2499 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2500 mlt_properties_set_int(properties, "b_track", newTrack);
2501 //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);
2505 nextservice = mlt_service_producer(nextservice);
2506 if (nextservice == NULL) break;
2507 properties = MLT_SERVICE_PROPERTIES(nextservice);
2508 mlt_type = mlt_properties_get(properties, "mlt_type");
2509 resource = mlt_properties_get(properties, "mlt_service");
2511 m_isBlocked = false;
2512 mlt_service_unlock(service.get_service());
2513 m_mltConsumer->set("refresh", 1);
2517 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2519 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2520 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2522 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2523 mltAddTransition(tag, a_track, b_track, in, out, xml);
2525 //mltSavePlaylist();
2528 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2531 Mlt::Service service(m_mltProducer->parent().get_service());
2532 Mlt::Tractor tractor(service);
2534 //m_mltConsumer->set("refresh", 0);
2535 mlt_service serv = m_mltProducer->parent().get_service();
2537 mlt_service nextservice = mlt_service_get_producer(serv);
2538 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2539 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2540 QString resource = mlt_properties_get(properties, "mlt_service");
2541 int in_pos = (int) in.frames(m_fps);
2542 int out_pos = (int) out.frames(m_fps) - 1;
2544 while (mlt_type == "transition") {
2545 mlt_transition tr = (mlt_transition) nextservice;
2546 int currentTrack = mlt_transition_get_b_track(tr);
2547 int currentBTrack = mlt_transition_get_a_track(tr);
2548 int currentIn = (int) mlt_transition_get_in(tr);
2549 int currentOut = (int) mlt_transition_get_out(tr);
2551 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2553 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2554 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2555 QMap<QString, QString>::Iterator it;
2557 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2558 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2559 if (currentBTrack != a_track) {
2560 mlt_properties_set_int(properties, "a_track", a_track);
2562 for (it = map.begin(); it != map.end(); ++it) {
2564 char *name = decodedString(key);
2565 char *value = decodedString(it.value());
2566 mlt_properties_set(transproperties, name, value);
2567 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2568 //filter->set("kdenlive_id", id);
2574 nextservice = mlt_service_producer(nextservice);
2575 if (nextservice == NULL) break;
2576 properties = MLT_SERVICE_PROPERTIES(nextservice);
2577 mlt_type = mlt_properties_get(properties, "mlt_type");
2578 resource = mlt_properties_get(properties, "mlt_service");
2580 m_isBlocked = false;
2581 m_mltConsumer->set("refresh", 1);
2584 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2586 Mlt::Service service(m_mltProducer->parent().get_service());
2587 Mlt::Tractor tractor(service);
2588 Mlt::Field *field = tractor.field();
2590 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2591 mlt_service serv = m_mltProducer->parent().get_service();
2593 mlt_service nextservice = mlt_service_get_producer(serv);
2594 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2595 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2596 QString resource = mlt_properties_get(properties, "mlt_service");
2598 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2600 while (mlt_type == "transition") {
2601 mlt_transition tr = (mlt_transition) nextservice;
2602 int currentTrack = mlt_transition_get_b_track(tr);
2603 int currentIn = (int) mlt_transition_get_in(tr);
2604 int currentOut = (int) mlt_transition_get_out(tr);
2605 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2607 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2608 mlt_field_disconnect_service(field->get_field(), nextservice);
2611 nextservice = mlt_service_producer(nextservice);
2612 if (nextservice == NULL) break;
2613 properties = MLT_SERVICE_PROPERTIES(nextservice);
2614 mlt_type = mlt_properties_get(properties, "mlt_type");
2615 resource = mlt_properties_get(properties, "mlt_service");
2617 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2620 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2622 QDomNodeList attribs = xml.elementsByTagName("parameter");
2623 QMap<QString, QString> map;
2624 for (int i = 0;i < attribs.count();i++) {
2625 QDomElement e = attribs.item(i).toElement();
2626 QString name = e.attribute("name");
2627 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2628 map[name] = e.attribute("default");
2629 if (!e.attribute("value").isEmpty()) {
2630 map[name] = e.attribute("value");
2632 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2633 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2634 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2637 if (e.attribute("namedesc").contains(';')) {
2638 QString format = e.attribute("format");
2639 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2640 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2642 QTextStream txtNeu(&neu);
2643 if (values.size() > 0)
2644 txtNeu << (int)values[0].toDouble();
2646 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2647 txtNeu << separators[i];
2648 txtNeu << (int)(values[i+1].toDouble());
2650 if (i < separators.size())
2651 txtNeu << separators[i];
2652 map[e.attribute("name")] = neu;
2659 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2661 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2662 Mlt::Service service(m_mltProducer->parent().get_service());
2663 Mlt::Tractor tractor(service);
2664 Mlt::Field *field = tractor.field();
2666 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2667 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2668 transition->set("transparency", id);
2669 transition->set("fill", 1);
2670 transition->set("internal_added", 237);
2671 field->plant_transition(*transition, transitiontrack, info.track);
2675 void Render::mltDeleteTransparency(int pos, int track, int id)
2677 Mlt::Service service(m_mltProducer->parent().get_service());
2678 Mlt::Tractor tractor(service);
2679 Mlt::Field *field = tractor.field();
2681 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2682 mlt_service serv = m_mltProducer->parent().get_service();
2684 mlt_service nextservice = mlt_service_get_producer(serv);
2685 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2686 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2687 QString resource = mlt_properties_get(properties, "mlt_service");
2689 while (mlt_type == "transition") {
2690 mlt_transition tr = (mlt_transition) nextservice;
2691 int currentTrack = mlt_transition_get_b_track(tr);
2692 int currentIn = (int) mlt_transition_get_in(tr);
2693 int currentOut = (int) mlt_transition_get_out(tr);
2694 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2695 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2697 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2698 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2699 mlt_field_disconnect_service(field->get_field(), nextservice);
2702 nextservice = mlt_service_producer(nextservice);
2703 if (nextservice == NULL) break;
2704 properties = MLT_SERVICE_PROPERTIES(nextservice);
2705 mlt_type = mlt_properties_get(properties, "mlt_type");
2706 resource = mlt_properties_get(properties, "mlt_service");
2708 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2711 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2713 Mlt::Service service(m_mltProducer->parent().get_service());
2714 Mlt::Tractor tractor(service);
2716 mlt_service_lock(service.get_service());
2717 m_mltConsumer->set("refresh", 0);
2720 mlt_service serv = m_mltProducer->parent().get_service();
2721 mlt_service nextservice = mlt_service_get_producer(serv);
2722 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2723 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2724 QString resource = mlt_properties_get(properties, "mlt_service");
2725 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2726 while (mlt_type == "transition") {
2727 mlt_transition tr = (mlt_transition) nextservice;
2728 int currentTrack = mlt_transition_get_b_track(tr);
2729 int currentIn = (int) mlt_transition_get_in(tr);
2730 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2731 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2732 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2733 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2734 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2735 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2738 nextservice = mlt_service_producer(nextservice);
2739 if (nextservice == NULL) break;
2740 properties = MLT_SERVICE_PROPERTIES(nextservice);
2741 mlt_type = mlt_properties_get(properties, "mlt_type");
2742 resource = mlt_properties_get(properties, "mlt_service");
2744 m_isBlocked = false;
2745 mlt_service_unlock(service.get_service());
2746 m_mltConsumer->set("refresh", 1);
2750 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2752 Mlt::Service service(m_mltProducer->parent().get_service());
2753 Mlt::Tractor tractor(service);
2755 mlt_service_lock(service.get_service());
2756 m_mltConsumer->set("refresh", 0);
2759 mlt_service serv = m_mltProducer->parent().get_service();
2760 mlt_service nextservice = mlt_service_get_producer(serv);
2761 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2762 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2763 QString resource = mlt_properties_get(properties, "mlt_service");
2765 while (mlt_type == "transition") {
2766 mlt_transition tr = (mlt_transition) nextservice;
2767 int currentTrack = mlt_transition_get_b_track(tr);
2768 int currentaTrack = mlt_transition_get_a_track(tr);
2769 int currentIn = (int) mlt_transition_get_in(tr);
2770 int currentOut = (int) mlt_transition_get_out(tr);
2771 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2772 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2773 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2774 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2775 kDebug() << "//////MOVING";
2776 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2777 if (endTrack != startTrack) {
2778 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2779 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2780 mlt_properties_set_int(properties, "b_track", endTrack);
2784 nextservice = mlt_service_producer(nextservice);
2785 if (nextservice == NULL) break;
2786 properties = MLT_SERVICE_PROPERTIES(nextservice);
2787 mlt_type = mlt_properties_get(properties, "mlt_type");
2788 resource = mlt_properties_get(properties, "mlt_service");
2790 m_isBlocked = false;
2791 mlt_service_unlock(service.get_service());
2792 m_mltConsumer->set("refresh", 1);
2796 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2798 if (in >= out) return false;
2799 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2800 Mlt::Service service(m_mltProducer->parent().get_service());
2802 Mlt::Tractor tractor(service);
2803 Mlt::Field *field = tractor.field();
2805 char *transId = decodedString(tag);
2806 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2807 if (out != GenTime())
2808 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2809 QMap<QString, QString>::Iterator it;
2811 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2812 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2814 for (it = args.begin(); it != args.end(); ++it) {
2816 char *name = decodedString(key);
2817 char *value = decodedString(it.value());
2818 if (it.value().isEmpty() == false) transition->set(name, value);
2819 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2820 //filter->set("kdenlive_id", id);
2824 // attach filter to the clip
2825 field->plant_transition(*transition, a_track, b_track);
2831 void Render::mltSavePlaylist()
2833 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2834 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2835 fileConsumer.set("resource", "/tmp/playlist.westley");
2837 Mlt::Service service(m_mltProducer->get_service());
2839 fileConsumer.connect(service);
2840 fileConsumer.start();
2843 QList <Mlt::Producer *> Render::producersList()
2845 QList <Mlt::Producer *> prods;
2846 Mlt::Service service(m_mltProducer->parent().get_service());
2847 if (service.type() != tractor_type) return prods;
2848 Mlt::Tractor tractor(service);
2851 int trackNb = tractor.count();
2852 for (int t = 1; t < trackNb; t++) {
2853 Mlt::Producer trackProducer(tractor.track(t));
2854 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2855 int clipNb = trackPlaylist.count();
2856 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2857 for (int i = 0; i < clipNb; i++) {
2858 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2859 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2860 ids.append(nprod->get("id"));
2861 prods.append(nprod);
2868 void Render::fillSlowMotionProducers()
2870 Mlt::Service service(m_mltProducer->parent().get_service());
2871 if (service.type() != tractor_type) return;
2873 Mlt::Tractor tractor(service);
2875 int trackNb = tractor.count();
2876 for (int t = 1; t < trackNb; t++) {
2877 Mlt::Producer trackProducer(tractor.track(t));
2878 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2879 int clipNb = trackPlaylist.count();
2880 for (int i = 0; i < clipNb; i++) {
2881 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2882 if (nprod && !nprod->is_blank()) {
2883 QString id = nprod->get("id");
2884 if (id.startsWith("slowmotion:")) {
2885 // this is a slowmotion producer, add it to the list
2886 QString url = QString::fromUtf8(nprod->get("resource"));
2887 if (!m_slowmotionProducers.contains(url)) {
2888 m_slowmotionProducers.insert(url, nprod);
2896 void Render::mltInsertTrack(int ix, bool videoTrack)
2901 m_mltConsumer->set("refresh", 0);
2902 mlt_service_lock(m_mltConsumer->get_service());
2903 Mlt::Service service(m_mltProducer->parent().get_service());
2904 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2906 Mlt::Tractor tractor(service);
2908 Mlt::Playlist playlist;// = new Mlt::Playlist();
2909 int ct = tractor.count();
2910 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2913 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2914 tractor.set_track(playlist, pos);
2915 Mlt::Producer newProd(tractor.track(pos));
2916 if (!videoTrack) newProd.set("hide", 1);
2918 for (; pos <= ct; pos++) {
2919 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2920 tractor.set_track(*prodToMove, pos);
2921 prodToMove = prodToMove2;
2924 tractor.set_track(playlist, ix);
2925 Mlt::Producer newProd(tractor.track(ix));
2926 if (!videoTrack) newProd.set("hide", 1);
2930 mlt_service serv = m_mltProducer->parent().get_service();
2931 mlt_service nextservice = mlt_service_get_producer(serv);
2932 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2933 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2934 QString resource = mlt_properties_get(properties, "mlt_service");
2936 while (mlt_type == "transition") {
2937 if (resource != "mix") {
2938 mlt_transition tr = (mlt_transition) nextservice;
2939 int currentTrack = mlt_transition_get_b_track(tr);
2940 int currentaTrack = mlt_transition_get_a_track(tr);
2941 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2943 if (currentTrack >= ix) {
2944 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2945 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2948 nextservice = mlt_service_producer(nextservice);
2949 if (nextservice == NULL) break;
2950 properties = MLT_SERVICE_PROPERTIES(nextservice);
2951 mlt_type = mlt_properties_get(properties, "mlt_type");
2952 resource = mlt_properties_get(properties, "mlt_service");
2955 // Add audio mix transition to last track
2956 Mlt::Field *field = tractor.field();
2957 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2958 //transition->set("mlt_service", "mix");
2959 transition->set("a_track", 1);
2960 transition->set("b_track", ct);
2961 transition->set("always_active", 1);
2962 transition->set("internal_added", 237);
2963 transition->set("combine", 1);
2964 field->plant_transition(*transition, 1, ct);
2966 mlt_service_unlock(m_mltConsumer->get_service());
2967 m_isBlocked = false;
2968 blockSignals(false);
2972 void Render::mltDeleteTrack(int ix)
2975 doc.setContent(sceneList(), false);
2976 int tracksCount = doc.elementsByTagName("track").count() - 1;
2977 QDomNode track = doc.elementsByTagName("track").at(ix);
2978 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2979 QDomNodeList transitions = doc.elementsByTagName("transition");
2980 for (int i = 0; i < transitions.count(); i++) {
2981 QDomElement e = transitions.at(i).toElement();
2982 QDomNodeList props = e.elementsByTagName("property");
2983 QMap <QString, QString> mappedProps;
2984 for (int j = 0; j < props.count(); j++) {
2985 QDomElement f = props.at(j).toElement();
2986 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2988 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2989 tractor.removeChild(transitions.at(i));
2990 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2991 // Transition needs to be moved
2992 int a_track = mappedProps.value("a_track").toInt();
2993 int b_track = mappedProps.value("b_track").toInt();
2994 if (a_track > 0) a_track --;
2995 if (b_track > 0) b_track --;
2996 for (int j = 0; j < props.count(); j++) {
2997 QDomElement f = props.at(j).toElement();
2998 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2999 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3004 tractor.removeChild(track);
3005 setSceneList(doc.toString(), m_framePosition);
3012 m_mltConsumer->set("refresh", 0);
3013 mlt_service_lock(m_mltConsumer->get_service());
3014 Mlt::Service service(m_mltProducer->parent().get_service());
3015 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
3017 /*Mlt::Tractor tractor(service);
3020 Mlt::Multitrack *multi = tractor.multitrack();
3023 int ct = tractor.count();
3024 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
3026 for (; pos < ct ; pos++) {
3027 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
3028 //mlt_service_close(lastTrack->get_service());
3030 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
3031 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
3032 mlt_service_close(prodToMove->get_service());
3033 mlt_service_close(prodToClose->get_service());
3034 tractor.set_track(*prodToMove, pos);
3038 /*mlt_service serv = m_mltProducer->parent().get_service();
3039 mlt_service nextservice = mlt_service_get_producer(serv);
3040 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3041 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3042 QString resource = mlt_properties_get(properties, "mlt_service");
3044 while (mlt_type == "transition") {
3045 if (resource != "mix") {
3046 mlt_transition tr = (mlt_transition) nextservice;
3047 int currentTrack = mlt_transition_get_b_track(tr);
3048 int currentaTrack = mlt_transition_get_a_track(tr);
3049 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3051 if (currentTrack >= ix) {
3052 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3053 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3056 nextservice = mlt_service_producer(nextservice);
3057 if (nextservice == NULL) break;
3058 properties = MLT_SERVICE_PROPERTIES(nextservice);
3059 mlt_type = mlt_properties_get(properties, "mlt_type");
3060 resource = mlt_properties_get(properties, "mlt_service");
3063 // Add audio mix transition to last track
3064 Mlt::Field *field = tractor.field();
3065 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3066 //transition->set("mlt_service", "mix");
3067 transition->set("a_track", 1);
3068 transition->set("b_track", ct);
3069 transition->set("always_active", 1);
3070 transition->set("internal_added", 237);
3071 transition->set("combine", 1);
3072 field->plant_transition(*transition, 1, ct);
3075 mlt_service_unlock(m_mltConsumer->get_service());
3076 m_isBlocked = false;
3077 blockSignals(false);
3081 void Render::updatePreviewSettings()
3083 kDebug() << "////// RESTARTING CONSUMER";
3084 if (!m_mltConsumer || !m_mltProducer) return;
3085 if (m_mltProducer->get_playtime() == 0) return;
3086 Mlt::Service service(m_mltProducer->parent().get_service());
3087 if (service.type() != tractor_type) return;
3089 //m_mltConsumer->set("refresh", 0);
3090 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3091 m_mltConsumer->purge();
3092 QString scene = sceneList();
3094 if (m_mltProducer) {
3095 pos = m_mltProducer->position();
3096 delete m_mltProducer;
3098 m_mltProducer = NULL;
3099 setSceneList(scene, pos);
3102 #include "renderer.moc"