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): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid), m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false), m_isZoneMode(false), m_isLoopMode(false)
58 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
59 refreshTimer = new QTimer(this);
60 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
62 /*if (rendererName == "project") m_monitorId = 10000;
63 else m_monitorId = 10001;*/
64 osdTimer = new QTimer(this);
65 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
67 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
71 m_mltProducer = m_blackClip->cut(0, 50);
72 m_mltConsumer->connect(*m_mltProducer);
73 m_mltProducer->set_speed(0.0);
82 void Render::closeMlt()
90 if (m_blackClip) delete m_blackClip;
95 void Render::buildConsumer()
98 m_activeProfile = KdenliveSettings::current_profile();
99 tmp = decodedString(m_activeProfile);
100 setenv("MLT_PROFILE", tmp, 1);
101 if (m_blackClip) delete m_blackClip;
104 m_mltProfile = new Mlt::Profile(tmp);
107 QString videoDriver = KdenliveSettings::videodrivername();
108 if (!videoDriver.isEmpty()) {
109 if (videoDriver == "x11_noaccel") {
110 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
113 unsetenv("SDL_VIDEO_YUV_HWACCEL");
116 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
118 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
119 m_mltConsumer->set("resize", 1);
120 m_mltConsumer->set("window_id", m_winid);
121 m_mltConsumer->set("terminate_on_pause", 1);
122 m_mltConsumer->set("window_background", decodedString(KdenliveSettings::window_background().name()));
124 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
125 m_mltConsumer->set("rescale", "nearest");
127 QString audioDevice = KdenliveSettings::audiodevicename();
128 if (!audioDevice.isEmpty()) {
129 tmp = decodedString(audioDevice);
130 m_mltConsumer->set("audio_device", tmp);
134 if (!videoDriver.isEmpty()) {
135 tmp = decodedString(videoDriver);
136 m_mltConsumer->set("video_driver", tmp);
140 QString audioDriver = KdenliveSettings::audiodrivername();
141 if (!audioDriver.isEmpty()) {
142 tmp = decodedString(audioDriver);
143 m_mltConsumer->set("audio_driver", tmp);
148 m_mltConsumer->set("progressive", 1);
149 m_mltConsumer->set("audio_buffer", 1024);
150 m_mltConsumer->set("frequency", 48000);
152 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
153 m_blackClip->set("id", "black");
157 int Render::resetProfile()
159 if (!m_mltConsumer) return 0;
160 if (m_activeProfile == KdenliveSettings::current_profile()) {
161 kDebug() << "reset to same profile, nothing to do";
164 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
165 if (m_isSplitView) slotSplitView(false);
166 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
167 m_mltConsumer->purge();
168 delete m_mltConsumer;
169 m_mltConsumer = NULL;
170 QString scene = sceneList();
173 pos = m_mltProducer->position();
174 delete m_mltProducer;
176 m_mltProducer = NULL;
178 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
179 /*if (m_mltProfile) delete m_mltProfile;
180 m_mltProfile = NULL;*/
184 //kDebug() << "//RESET WITHSCENE: " << scene;
185 setSceneList(scene, pos);
187 /*char *tmp = decodedString(scene);
188 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
190 m_mltProducer = producer;
191 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
192 m_mltProducer->optimise();
193 m_mltProducer->set_speed(0);
196 //delete m_mltProfile;
197 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
198 //mlt_profile prof = m_mltProfile->get_profile();
199 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
200 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
201 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
202 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
204 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
209 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
210 void Render::seek(GenTime time)
215 m_mltProducer->seek((int)(time.frames(m_fps)));
220 char *Render::decodedString(QString str)
222 /*QCString fn = QFile::encodeName(str);
223 char *t = new char[fn.length() + 1];
224 strcpy(t, (const char *)fn);*/
226 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
230 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
231 QPixmap pix(width, height);
233 mlt_image_format format = mlt_image_rgb24a;
234 uint8_t *thumb = frame->get_image(format, width, height);
235 QImage image(thumb, width, height, QImage::Format_ARGB32);
237 if (!image.isNull()) {
238 pix = pix.fromImage(image);
240 QPainter painter(&pix);
241 painter.drawRect(0, 0, width - 1, height - 1);
243 } else pix.fill(Qt::black);
247 int Render::renderWidth() const
249 return (int)(m_mltProfile->height() * m_mltProfile->dar());
252 int Render::renderHeight() const
254 return m_mltProfile->height();
257 QPixmap Render::extractFrame(int frame_position, int width, int height)
260 width = renderWidth();
261 height = renderHeight();
263 QPixmap pix(width, height);
264 if (!m_mltProducer) {
268 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
271 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
275 if (url.fileName().startsWith(".all.")) { // check for slideshow
276 QString fileType = url.fileName().right(3);
278 QStringList::Iterator it;
280 QDir dir(url.directory());
282 filter << "*." + fileType;
283 filter << "*." + fileType.toUpper();
284 more = dir.entryList(filter, QDir::Files);
285 im.load(url.directory() + '/' + more.at(0));
286 } else im.load(url.path());
287 //pixmap = im.scaled(width, height);
292 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
293 QPixmap pix(width, height);
294 char *tmp = decodedString(file);
295 Mlt::Profile *prof = new Mlt::Profile(profile);
296 Mlt::Producer m_producer(*prof, tmp);
298 if (m_producer.is_blank()) {
303 Mlt::Filter m_convert(*prof, "avcolour_space");
304 m_convert.set("forced", mlt_image_rgb24a);
305 m_producer.attach(m_convert);
306 m_producer.seek(frame_position);
307 Mlt::Frame * frame = m_producer.get_frame();
309 pix = frameThumbnail(frame, width, height, true);
312 if (prof) delete prof;
317 void Render::getImage(KUrl url, int frame_position, QPoint size)
319 char *tmp = decodedString(url.path());
320 Mlt::Producer m_producer(tmp);
322 if (m_producer.is_blank()) {
325 Mlt::Filter m_convert("avcolour_space");
326 m_convert.set("forced", mlt_image_rgb24a);
327 m_producer.attach(m_convert);
328 m_producer.seek(frame_position);
330 Mlt::Frame * frame = m_producer.get_frame();
333 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
335 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
339 /* Create thumbnail for color */
340 /*void Render::getImage(int id, QString color, QPoint size)
342 QPixmap pixmap(size.x() - 2, size.y() - 2);
343 color = color.replace(0, 2, "#");
344 color = color.left(7);
345 pixmap.fill(QColor(color));
346 QPixmap result(size.x(), size.y());
347 result.fill(Qt::black);
348 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
349 emit replyGetImage(id, result, size.x(), size.y());
353 /* Create thumbnail for image */
354 /*void Render::getImage(KUrl url, QPoint size)
358 if (url.fileName().startsWith(".all.")) { // check for slideshow
359 QString fileType = url.fileName().right(3);
361 QStringList::Iterator it;
363 QDir dir( url.directory() );
364 more = dir.entryList( QDir::Files );
365 for ( it = more.begin() ; it != more.end() ; ++it ) {
366 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
367 if (!im.load(url.directory() + '/' + *it))
368 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
373 else im.load(url.path());
375 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
376 QPixmap result(size.x(), size.y());
377 result.fill(Qt::black);
378 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
379 emit replyGetImage(url, 1, result, size.x(), size.y());
383 double Render::consumerRatio() const
385 if (!m_mltConsumer) return 1.0;
386 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
390 int Render::getLength()
394 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
395 return mlt_producer_get_playtime(m_mltProducer->get_producer());
400 bool Render::isValid(KUrl url)
402 char *tmp = decodedString(url.path());
403 Mlt::Producer producer(*m_mltProfile, tmp);
405 if (producer.is_blank())
411 double Render::dar() const
413 return m_mltProfile->dar();
416 void Render::slotSplitView(bool doit)
418 m_isSplitView = doit;
419 Mlt::Service service(m_mltProducer->parent().get_service());
420 Mlt::Tractor tractor(service);
421 if (service.type() != tractor_type || tractor.count() < 2) return;
422 Mlt::Field *field = tractor.field();
425 for (int i = 1; i < tractor.count() && screen < 4; i++) {
426 Mlt::Producer trackProducer(tractor.track(i));
427 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
428 if (QString(trackProducer.get("hide")).toInt() != 1) {
429 kDebug() << "// ADIDNG TRACK: " << i;
430 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
431 transition->set("mlt_service", "composite");
432 transition->set("a_track", 0);
433 transition->set("b_track", i);
434 transition->set("distort", 1);
435 transition->set("internal_added", "200");
442 tmp = "50%,0:50%x50%";
445 tmp = "0,50%:50%x50%";
449 tmp = "50%,50%:50%x50%";
452 transition->set("geometry", tmp);
453 transition->set("always_active", "1");
454 field->plant_transition(*transition, 0, i);
459 m_mltConsumer->set("refresh", 1);
461 mlt_service serv = m_mltProducer->parent().get_service();
462 mlt_service nextservice = mlt_service_get_producer(serv);
463 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
464 QString mlt_type = mlt_properties_get(properties, "mlt_type");
465 QString resource = mlt_properties_get(properties, "mlt_service");
467 while (mlt_type == "transition") {
468 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
469 if (added == "200") {
470 mlt_field_disconnect_service(field->get_field(), nextservice);
472 nextservice = mlt_service_producer(nextservice);
473 if (nextservice == NULL) break;
474 properties = MLT_SERVICE_PROPERTIES(nextservice);
475 mlt_type = mlt_properties_get(properties, "mlt_type");
476 resource = mlt_properties_get(properties, "mlt_service");
477 m_mltConsumer->set("refresh", 1);
482 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer)
484 KUrl url = KUrl(xml.attribute("resource", QString()));
485 Mlt::Producer *producer = NULL;
486 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
487 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
490 if (xml.attribute("type").toInt() == COLOR) {
491 char *tmp = decodedString("colour:" + xml.attribute("colour"));
492 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
494 } else if (url.isEmpty()) {
496 QDomElement westley = doc.createElement("westley");
497 QDomElement play = doc.createElement("playlist");
498 doc.appendChild(westley);
499 westley.appendChild(play);
500 play.appendChild(doc.importNode(xml, true));
501 char *tmp = decodedString(doc.toString());
502 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
505 char *tmp = decodedString(url.path());
506 producer = new Mlt::Producer(*m_mltProfile, tmp);
510 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
511 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
512 emit removeInvalidClip(clipId);
516 if (xml.hasAttribute("force_aspect_ratio")) {
517 double aspect = xml.attribute("force_aspect_ratio").toDouble();
518 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
520 if (xml.hasAttribute("threads")) {
521 int threads = xml.attribute("threads").toInt();
522 if (threads != 1) producer->set("threads", threads);
524 if (xml.hasAttribute("video_index")) {
525 int vindex = xml.attribute("video_index").toInt();
526 if (vindex != 0) producer->set("video_index", vindex);
528 if (xml.hasAttribute("audio_index")) {
529 int aindex = xml.attribute("audio_index").toInt();
530 if (aindex != 0) producer->set("audio_index", aindex);
533 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
535 char *tmp = decodedString(clipId);
536 producer->set("id", tmp);
540 int width = (int)(height * m_mltProfile->dar());
541 QMap < QString, QString > filePropertyMap;
542 QMap < QString, QString > metadataPropertyMap;
544 int frameNumber = xml.attribute("thumbnail", "0").toInt();
545 if (frameNumber != 0) producer->seek(frameNumber);
547 filePropertyMap["duration"] = QString::number(producer->get_playtime());
548 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
550 Mlt::Frame *frame = producer->get_frame();
552 if (xml.attribute("type").toInt() == SLIDESHOW) {
553 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
554 if (xml.attribute("fade") == "1") {
555 // user wants a fade effect to slideshow
556 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
557 if (filter && filter->is_valid()) {
558 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
559 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
560 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
561 char *tmp = decodedString(xml.attribute("luma_file"));
562 filter->set("luma.resource", tmp);
564 if (xml.hasAttribute("softness")) {
565 int soft = xml.attribute("softness").toInt();
566 filter->set("luma.softness", (double) soft / 100.0);
569 Mlt::Service clipService(producer->get_service());
570 clipService.attach(*filter);
576 filePropertyMap["fps"] = producer->get("source_fps");
578 if (frame && frame->is_valid()) {
579 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
580 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
581 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
582 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
584 if (frame->get_int("test_image") == 0) {
585 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
586 filePropertyMap["type"] = "playlist";
587 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
588 } else if (frame->get_int("test_audio") == 0)
589 filePropertyMap["type"] = "av";
591 filePropertyMap["type"] = "video";
593 mlt_image_format format = mlt_image_yuv422;
595 int frame_height = 0;
596 //frame->set("rescale.interp", "hyper");
597 frame->set("normalised_height", height);
598 frame->set("normalised_width", width);
599 QPixmap pix(width, height);
601 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
602 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
603 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
604 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
606 if (!image.isNull()) {
607 pix = QPixmap::fromImage(image.rgbSwapped());
611 mlt_pool_release(new_image);
612 emit replyGetImage(clipId, pix);
614 } else if (frame->get_int("test_audio") == 0) {
615 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
616 emit replyGetImage(clipId, pixmap);
617 filePropertyMap["type"] = "audio";
621 // Retrieve audio / video codec name
625 if (producer->get_int("video_index") > -1) {
626 /*if (context->duration == AV_NOPTS_VALUE) {
627 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
628 emit removeInvalidClip(clipId);
631 // Get the video_index
632 int default_video = producer->get_int("video_index");
634 int default_audio = producer->get_int("audio_index");
637 // Find maximum stream index values
638 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
639 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
640 QString type = producer->get(property);
643 else if (type == "audio")
646 filePropertyMap["default_video"] = QString::number(default_video);
647 filePropertyMap["video_max"] = QString::number(video_max);
648 filePropertyMap["default_audio"] = QString::number(default_audio);
649 filePropertyMap["audio_max"] = QString::number(audio_max);
651 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
652 if (producer->get(property)) {
653 filePropertyMap["videocodec"] = producer->get(property);
655 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
656 if (producer->get(property))
657 filePropertyMap["videocodec"] = producer->get(property);
660 if (KdenliveSettings::dropbframes()) {
661 kDebug() << "// LOOKING FOR H264 on: " << default_video;
662 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
663 kDebug() << "PROP: " << property << " = " << producer->get(property);
664 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
665 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
666 producer->set("skip_loop_filter", "all");
667 producer->set("skip_frame", "bidir");
671 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
672 if (producer->get_int("audio_index") > -1) {
673 // Get the audio_index
674 int index = producer->get_int("audio_index");
676 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
677 if (producer->get(property)) {
678 filePropertyMap["audiocodec"] = producer->get(property);
680 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
681 if (producer->get(property))
682 filePropertyMap["audiocodec"] = producer->get(property);
687 Mlt::Properties metadata;
688 metadata.pass_values(*producer, "meta.attr.");
689 int count = metadata.count();
690 for (int i = 0; i < count; i ++) {
691 QString name = metadata.get_name(i);
692 QString value = QString::fromUtf8(metadata.get(i));
693 if (name.endsWith("markup") && !value.isEmpty())
694 metadataPropertyMap[ name.section('.', 0, -2)] = value;
697 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
698 kDebug() << "REquested fuile info for: " << url.path();
699 if (frame) delete frame;
700 //if (producer) delete producer;
704 /** Create the producer from the Westley QDomDocument */
706 void Render::initSceneList()
708 kDebug() << "-------- INIT SCENE LIST ------_";
710 QDomElement westley = doc.createElement("westley");
711 doc.appendChild(westley);
712 QDomElement prod = doc.createElement("producer");
713 prod.setAttribute("resource", "colour");
714 prod.setAttribute("colour", "red");
715 prod.setAttribute("id", "black");
716 prod.setAttribute("in", "0");
717 prod.setAttribute("out", "0");
719 QDomElement tractor = doc.createElement("tractor");
720 QDomElement multitrack = doc.createElement("multitrack");
722 QDomElement playlist1 = doc.createElement("playlist");
723 playlist1.appendChild(prod);
724 multitrack.appendChild(playlist1);
725 QDomElement playlist2 = doc.createElement("playlist");
726 multitrack.appendChild(playlist2);
727 QDomElement playlist3 = doc.createElement("playlist");
728 multitrack.appendChild(playlist3);
729 QDomElement playlist4 = doc.createElement("playlist");
730 multitrack.appendChild(playlist4);
731 QDomElement playlist5 = doc.createElement("playlist");
732 multitrack.appendChild(playlist5);
733 tractor.appendChild(multitrack);
734 westley.appendChild(tractor);
735 // kDebug()<<doc.toString();
737 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
738 setSceneList(doc, 0);
744 /** Create the producer from the Westley QDomDocument */
745 void Render::setProducer(Mlt::Producer *producer, int position)
747 if (m_winid == -1) return;
750 m_mltConsumer->stop();
753 m_mltConsumer->purge();
757 m_mltProducer->set_speed(0);
758 delete m_mltProducer;
759 m_mltProducer = NULL;
763 m_mltProducer = new Mlt::Producer(producer->get_producer());
764 } else m_mltProducer = m_blackClip->cut(0, 50);
765 /*if (KdenliveSettings::dropbframes()) {
766 m_mltProducer->set("skip_loop_filter", "all");
767 m_mltProducer->set("skip_frame", "bidir");
769 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
771 m_fps = m_mltProducer->get_fps();
773 if (position != -1) {
774 m_mltProducer->seek(position);
775 emit rendererPosition(position);
782 /** Create the producer from the Westley QDomDocument */
783 void Render::setSceneList(QDomDocument list, int position)
785 setSceneList(list.toString(), position);
788 /** Create the producer from the Westley QDomDocument */
789 void Render::setSceneList(QString playlist, int position)
791 if (m_winid == -1) return;
793 m_slowmotionProducers.clear();
795 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
798 m_mltConsumer->stop();
799 //m_mltConsumer->set("refresh", 0);
806 m_mltProducer->set_speed(0);
807 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
809 delete m_mltProducer;
810 m_mltProducer = NULL;
815 char *tmp = decodedString(playlist);
816 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
819 if (!m_mltProducer || !m_mltProducer->is_valid()) {
820 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
822 m_mltProducer->optimise();
824 /*if (KdenliveSettings::osdtimecode()) {
825 // Attach filter for on screen display of timecode
827 QString attr = "attr_check";
828 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
829 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
830 mlt_producer_attach( m_mltProducer->get_producer(), filter );
831 mlt_filter_close( filter );
833 m_osdInfo = new Mlt::Filter("data_show");
834 tmp = decodedString(m_osdProfile);
835 m_osdInfo->set("resource", tmp);
837 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
838 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
839 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
840 m_osdInfo->set("dynamic", "1");
842 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
844 m_osdInfo->set("dynamic", "0");
847 m_fps = m_mltProducer->get_fps();
848 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
850 fillSlowMotionProducers();
852 //TODO: seek to correct place after opening project.
853 // Needs to be done from another place since it crashes here.
854 m_mltProducer->seek(position);
858 //kDebug()<<"// SETSCN LST, POS: "<<position;
859 //if (position != 0) emit rendererPosition(position);
862 /** Create the producer from the Westley QDomDocument */
863 const QString Render::sceneList()
866 Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
867 m_mltProducer->optimise();
868 westleyConsumer.set("terminate_on_pause", 1);
869 Mlt::Producer prod(m_mltProducer->get_producer());
870 bool split = m_isSplitView;
871 if (split) slotSplitView(false);
872 westleyConsumer.connect(prod);
873 westleyConsumer.start();
874 while (!westleyConsumer.is_stopped()) {}
875 playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
876 if (split) slotSplitView(true);
880 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
884 doc.setContent(sceneList(), false);
885 if (!kdenliveData.isNull()) {
886 // add Kdenlive specific tags
887 QDomNode wes = doc.elementsByTagName("westley").at(0);
888 wes.appendChild(doc.importNode(kdenliveData, true));
890 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
891 kWarning() << "////// ERROR writing to file: " << path;
894 QTextStream out(&file);
895 out << doc.toString();
896 if (file.error() != QFile::NoError) {
905 void Render::saveZone(KUrl url, QString desc, QPoint zone)
907 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
908 char *tmppath = decodedString("westley:" + url.path());
909 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
910 m_mltProducer->optimise();
912 westleyConsumer.set("terminate_on_pause", 1);
913 if (m_name == "clip") {
914 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
915 tmppath = decodedString(desc);
917 list.insert_at(0, prod, 0);
918 list.set("title", tmppath);
920 westleyConsumer.connect(list);
923 //TODO: not working yet, save zone from timeline
924 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
925 /* Mlt::Service service(p1->parent().get_service());
926 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
928 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
929 tmppath = decodedString(desc);
930 //prod->set("title", tmppath);
932 westleyConsumer.connect(*p1); //list);
935 westleyConsumer.start();
938 double Render::fps() const
943 void Render::connectPlaylist()
945 if (!m_mltConsumer) return;
946 //m_mltConsumer->set("refresh", "0");
947 m_mltConsumer->connect(*m_mltProducer);
948 m_mltProducer->set_speed(0);
949 m_mltConsumer->start();
950 emit durationChanged(m_mltProducer->get_playtime());
953 if (m_mltConsumer->start() == -1) {
954 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."));
955 m_mltConsumer = NULL;
962 void Render::refreshDisplay()
965 if (!m_mltProducer) return;
966 //m_mltConsumer->set("refresh", 0);
968 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
969 /*if (KdenliveSettings::osdtimecode()) {
970 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
971 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
972 m_osdInfo->set("dynamic", "1");
973 m_mltProducer->attach(*m_osdInfo);
976 m_mltProducer->detach(*m_osdInfo);
977 m_osdInfo->set("dynamic", "0");
982 void Render::setVolume(double /*volume*/)
984 if (!m_mltConsumer || !m_mltProducer) return;
986 m_mltConsumer->set("refresh", 0);
987 // Attach filter for on screen display of timecode
988 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
989 mlt_properties_set_double( properties, "meta.volume", volume );
990 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
991 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
993 if (!KdenliveSettings::osdtimecode()) {
994 m_mltProducer->detach(*m_osdInfo);
995 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
996 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
999 osdTimer->setSingleShot(2500);
1002 void Render::slotOsdTimeout()
1004 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1005 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1006 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1007 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1011 void Render::start()
1013 kDebug() << "----- STARTING MONITOR: " << m_name;
1014 if (m_winid == -1) {
1015 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1019 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1020 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1021 if (m_mltConsumer->start() == -1) {
1022 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."));
1023 m_mltConsumer = NULL;
1026 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1027 m_isBlocked = false;
1031 m_isBlocked = false;
1034 void Render::clear()
1036 kDebug() << " ********* RENDER CLEAR";
1037 if (m_mltConsumer) {
1038 //m_mltConsumer->set("refresh", 0);
1039 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1042 if (m_mltProducer) {
1043 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1044 m_mltProducer->set_speed(0.0);
1045 delete m_mltProducer;
1046 m_mltProducer = NULL;
1053 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1054 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1056 //m_mltConsumer->set("refresh", 0);
1057 m_mltConsumer->stop();
1058 // delete m_mltConsumer;
1059 // m_mltConsumer = NULL;
1061 kDebug() << "///////////// RENDER STOP2-------";
1064 if (m_mltProducer) {
1065 if (m_isZoneMode) resetZoneMode();
1066 m_mltProducer->set_speed(0.0);
1067 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1068 //kDebug() << m_mltProducer->get_length();
1070 kDebug() << "///////////// RENDER STOP3-------";
1073 void Render::stop(const GenTime & startTime)
1076 kDebug() << "///////////// RENDER STOP-------2";
1077 if (m_mltProducer) {
1078 if (m_isZoneMode) resetZoneMode();
1079 m_mltProducer->set_speed(0.0);
1080 m_mltProducer->seek((int) startTime.frames(m_fps));
1082 m_mltConsumer->purge();
1085 void Render::pause()
1087 if (!m_mltProducer || !m_mltConsumer)
1089 if (m_mltProducer->get_speed() == 0.0) return;
1090 if (m_isZoneMode) resetZoneMode();
1092 m_mltConsumer->set("refresh", 0);
1093 m_mltProducer->set_speed(0.0);
1094 emit rendererPosition(m_framePosition);
1095 m_mltProducer->seek(m_framePosition);
1096 m_mltConsumer->purge();
1099 void Render::switchPlay()
1101 if (!m_mltProducer || !m_mltConsumer)
1103 if (m_isZoneMode) resetZoneMode();
1104 if (m_mltProducer->get_speed() == 0.0) {
1105 m_isBlocked = false;
1106 m_mltProducer->set_speed(1.0);
1107 m_mltConsumer->set("refresh", 1);
1110 m_mltConsumer->set("refresh", 0);
1111 m_mltProducer->set_speed(0.0);
1112 emit rendererPosition(m_framePosition);
1113 m_mltProducer->seek(m_framePosition);
1114 m_mltConsumer->purge();
1115 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1116 //m_mltConsumer->set("refresh", 0);
1117 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1118 m_mltProducer->set_speed(0);
1119 m_mltProducer->seek( position );
1120 //m_mltProducer->seek((int) m_framePosition);
1121 m_isBlocked = false;*/
1123 /*if (speed == 0.0) {
1124 m_mltProducer->seek((int) m_framePosition + 1);
1125 m_mltConsumer->purge();
1130 void Render::play(double speed)
1134 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1135 m_isBlocked = false;
1136 m_mltProducer->set_speed(speed);
1137 /*if (speed == 0.0) {
1138 m_mltProducer->seek((int) m_framePosition + 1);
1139 m_mltConsumer->purge();
1144 void Render::play(const GenTime & startTime)
1146 if (!m_mltProducer || !m_mltConsumer)
1148 m_isBlocked = false;
1149 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1150 m_mltProducer->set_speed(1.0);
1151 m_mltConsumer->set("refresh", 1);
1154 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1156 if (!m_mltProducer || !m_mltConsumer)
1158 //m_mltProducer->set("eof", "loop");
1159 m_isLoopMode = true;
1160 m_loopStart = startTime;
1161 playZone(startTime, stopTime);
1164 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1166 if (!m_mltProducer || !m_mltConsumer)
1168 m_isBlocked = false;
1169 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1170 m_mltProducer->set("out", stopTime.frames(m_fps));
1171 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1172 m_mltProducer->set_speed(1.0);
1173 m_mltConsumer->set("refresh", 1);
1174 m_isZoneMode = true;
1177 void Render::resetZoneMode()
1179 if (!m_isZoneMode && !m_isLoopMode) return;
1180 m_mltProducer->set("out", m_originalOut);
1181 //m_mltProducer->set("eof", "pause");
1182 m_isZoneMode = false;
1183 m_isLoopMode = false;
1186 void Render::seekToFrame(int pos)
1188 //kDebug()<<" ********* RENDER SEEK TO POS";
1191 m_isBlocked = false;
1193 m_mltProducer->seek(pos);
1197 void Render::askForRefresh()
1199 // Use a Timer so that we don't refresh too much
1200 refreshTimer->start(200);
1203 void Render::doRefresh()
1205 // Use a Timer so that we don't refresh too much
1206 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1209 void Render::refresh()
1211 if (!m_mltProducer || m_isBlocked)
1213 refreshTimer->stop();
1214 if (m_mltConsumer) {
1215 m_mltConsumer->set("refresh", 1);
1219 double Render::playSpeed()
1221 if (m_mltProducer) return m_mltProducer->get_speed();
1225 GenTime Render::seekPosition() const
1227 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1228 else return GenTime();
1232 const QString & Render::rendererName() const
1238 void Render::emitFrameNumber(double position)
1240 m_framePosition = position;
1241 emit rendererPosition((int) position);
1242 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1245 void Render::emitConsumerStopped()
1247 // This is used to know when the playing stopped
1248 if (m_mltProducer) {
1249 double pos = m_mltProducer->position();
1250 if (m_isLoopMode) play(m_loopStart);
1251 else if (m_isZoneMode) resetZoneMode();
1252 emit rendererStopped((int) pos);
1253 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1254 //new QCustomEvent(10002));
1260 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1262 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1266 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1268 if (!m_mltProducer) {
1269 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1273 //int height = 1080;//KdenliveSettings::defaultheight();
1274 //int width = 1940; //KdenliveSettings::displaywidth();
1276 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1278 QPixmap pix(width, height);
1279 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1280 m_convert.set("forced", mlt_image_rgb24a);
1281 m_mltProducer->attach(m_convert);
1282 Mlt::Frame * frame = m_mltProducer->get_frame();
1283 m_mltProducer->detach(m_convert);
1285 pix = frameThumbnail(frame, width, height);
1288 pix.save(url.path(), "PNG");
1289 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1292 /** MLT PLAYLIST DIRECT MANIPULATON **/
1295 void Render::mltCheckLength()
1297 //kDebug()<<"checking track length: "<<track<<"..........";
1299 Mlt::Service service(m_mltProducer->get_service());
1300 Mlt::Tractor tractor(service);
1302 int trackNb = tractor.count();
1303 double duration = 0;
1304 double trackDuration;
1306 Mlt::Producer trackProducer(tractor.track(0));
1307 duration = trackProducer.get_playtime() - 1;
1308 m_mltProducer->set("out", duration);
1309 emit durationChanged((int) duration);
1312 while (trackNb > 1) {
1313 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1314 trackDuration = trackProducer.get_playtime() - 1;
1316 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1317 if (trackDuration > duration) duration = trackDuration;
1321 Mlt::Producer blackTrackProducer(tractor.track(0));
1322 double blackDuration = blackTrackProducer.get_playtime() - 1;
1324 if (blackDuration != duration) {
1325 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1326 blackTrackPlaylist.clear();
1327 int dur = (int)duration;
1328 while (dur > 14000) {
1329 blackTrackPlaylist.append(*m_blackClip, 0, 13999);
1333 blackTrackPlaylist.append(*m_blackClip, 0, dur);
1335 m_mltProducer->set("out", duration);
1336 emit durationChanged((int)duration);
1340 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1342 if (!m_mltProducer) {
1343 kDebug() << "PLAYLIST NOT INITIALISED //////";
1346 Mlt::Producer parentProd(m_mltProducer->parent());
1347 if (parentProd.get_producer() == NULL) {
1348 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1352 Mlt::Service service(parentProd.get_service());
1353 Mlt::Tractor tractor(service);
1354 mlt_service_lock(service.get_service());
1355 Mlt::Producer trackProducer(tractor.track(info.track));
1356 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1357 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1359 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1360 // We want a slowmotion producer
1361 double speed = element.attribute("speed", "1.0").toDouble();
1362 QString url = QString::fromUtf8(prod->get("resource"));
1363 url.append('?' + QString::number(speed));
1364 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1365 if (!slowprod || slowprod->get_producer() == NULL) {
1366 char *tmp = decodedString(url);
1367 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1369 QString id = prod->get("id");
1370 if (id.contains('_')) id = id.section('_', 0, 0);
1371 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1372 tmp = decodedString(producerid);
1373 slowprod->set("id", tmp);
1375 m_slowmotionProducers.insert(url, slowprod);
1380 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1381 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1383 /*if (QString(prod->get("transparency")).toInt() == 1)
1384 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1386 mlt_service_unlock(service.get_service());
1388 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1389 //tractor.multitrack()->refresh();
1390 //tractor.refresh();
1394 void Render::mltCutClip(int track, GenTime position)
1399 Mlt::Service service(m_mltProducer->parent().get_service());
1400 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1402 Mlt::Tractor tractor(service);
1403 Mlt::Producer trackProducer(tractor.track(track));
1404 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1407 /* // Display playlist info
1408 kDebug()<<"//////////// BEFORE";
1409 for (int i = 0; i < trackPlaylist.count(); i++) {
1410 int blankStart = trackPlaylist.clip_start(i);
1411 int blankDuration = trackPlaylist.clip_length(i) - 1;
1413 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1414 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1417 int cutPos = (int) position.frames(m_fps);
1419 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1420 if (trackPlaylist.is_blank(clipIndex)) {
1421 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1422 m_isBlocked = false;
1425 mlt_service_lock(service.get_service());
1426 int clipStart = trackPlaylist.clip_start(clipIndex);
1427 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1428 mlt_service_unlock(service.get_service());
1430 // duplicate effects
1431 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1432 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1434 if (original == NULL || clip == NULL) {
1435 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1437 Mlt::Service clipService(original->get_service());
1438 Mlt::Service dupService(clip->get_service());
1440 Mlt::Filter *filter = clipService.filter(ct);
1442 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1443 // looks like there is no easy way to duplicate a filter,
1444 // so we will create a new one and duplicate its properties
1445 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1446 if (dup && dup->is_valid()) {
1447 Mlt::Properties entries(filter->get_properties());
1448 for (int i = 0;i < entries.count();i++) {
1449 dup->set(entries.get_name(i), entries.get(i));
1451 dupService.attach(*dup);
1455 filter = clipService.filter(ct);
1458 /* // Display playlist info
1459 kDebug()<<"//////////// AFTER";
1460 for (int i = 0; i < trackPlaylist.count(); i++) {
1461 int blankStart = trackPlaylist.clip_start(i);
1462 int blankDuration = trackPlaylist.clip_length(i) - 1;
1464 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1465 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1468 m_isBlocked = false;
1471 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1474 mltRemoveClip(info.track, info.startPos);
1475 mltInsertClip(info, element, prod);
1479 bool Render::mltRemoveClip(int track, GenTime position)
1481 Mlt::Service service(m_mltProducer->parent().get_service());
1482 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1484 Mlt::Tractor tractor(service);
1485 Mlt::Producer trackProducer(tractor.track(track));
1486 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1487 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1489 /* // Display playlist info
1490 kDebug()<<"//// BEFORE";
1491 for (int i = 0; i < trackPlaylist.count(); i++) {
1492 int blankStart = trackPlaylist.clip_start(i);
1493 int blankDuration = trackPlaylist.clip_length(i) - 1;
1495 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1496 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1499 if (trackPlaylist.is_blank(clipIndex)) {
1500 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1504 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1505 trackPlaylist.replace_with_blank(clipIndex);
1506 trackPlaylist.consolidate_blanks(0);
1507 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1508 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1510 /* // Display playlist info
1511 kDebug()<<"//// AFTER";
1512 for (int i = 0; i < trackPlaylist.count(); i++) {
1513 int blankStart = trackPlaylist.clip_start(i);
1514 int blankDuration = trackPlaylist.clip_length(i) - 1;
1516 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1517 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1520 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1521 m_isBlocked = false;
1525 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1527 if (!m_mltProducer) {
1528 kDebug() << "PLAYLIST NOT INITIALISED //////";
1531 Mlt::Producer parentProd(m_mltProducer->parent());
1532 if (parentProd.get_producer() == NULL) {
1533 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1537 Mlt::Service service(parentProd.get_service());
1538 Mlt::Tractor tractor(service);
1539 int insertPos = pos.frames(m_fps);
1541 Mlt::Producer trackProducer(tractor.track(track));
1542 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1543 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1544 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1545 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1546 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1549 int Render::mltTrackDuration(int track)
1551 if (!m_mltProducer) {
1552 kDebug() << "PLAYLIST NOT INITIALISED //////";
1555 Mlt::Producer parentProd(m_mltProducer->parent());
1556 if (parentProd.get_producer() == NULL) {
1557 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1561 Mlt::Service service(parentProd.get_service());
1562 Mlt::Tractor tractor(service);
1564 Mlt::Producer trackProducer(tractor.track(track));
1565 return trackProducer.get_playtime() - 1;
1568 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1570 if (!m_mltProducer) {
1571 kDebug() << "PLAYLIST NOT INITIALISED //////";
1574 Mlt::Producer parentProd(m_mltProducer->parent());
1575 if (parentProd.get_producer() == NULL) {
1576 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1579 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1580 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1582 Mlt::Service service(parentProd.get_service());
1583 Mlt::Tractor tractor(service);
1584 mlt_service_lock(service.get_service());
1585 int diff = duration.frames(m_fps);
1586 int offset = timeOffset.frames(m_fps);
1590 // insert space in one track only
1591 Mlt::Producer trackProducer(tractor.track(track));
1592 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1593 insertPos = trackClipStartList.value(track);
1594 if (insertPos != -1) {
1595 insertPos += offset;
1596 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1597 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1599 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1600 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1601 int position = trackPlaylist.clip_start(clipIndex);
1602 trackPlaylist.remove_region(position, - diff - 1);
1604 trackPlaylist.consolidate_blanks(0);
1606 // now move transitions
1607 mlt_service serv = m_mltProducer->parent().get_service();
1608 mlt_service nextservice = mlt_service_get_producer(serv);
1609 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1610 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1611 QString resource = mlt_properties_get(properties, "mlt_service");
1613 while (mlt_type == "transition") {
1614 mlt_transition tr = (mlt_transition) nextservice;
1615 int currentTrack = mlt_transition_get_b_track(tr);
1616 int currentIn = (int) mlt_transition_get_in(tr);
1617 int currentOut = (int) mlt_transition_get_out(tr);
1618 insertPos = trackTransitionStartList.value(track);
1619 if (insertPos != -1) {
1620 insertPos += offset;
1621 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1622 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1625 nextservice = mlt_service_producer(nextservice);
1626 if (nextservice == NULL) break;
1627 properties = MLT_SERVICE_PROPERTIES(nextservice);
1628 mlt_type = mlt_properties_get(properties, "mlt_type");
1629 resource = mlt_properties_get(properties, "mlt_service");
1632 int trackNb = tractor.count();
1633 while (trackNb > 1) {
1634 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1635 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1638 //int clipNb = trackPlaylist.count();
1639 insertPos = trackClipStartList.value(trackNb - 1);
1640 if (insertPos != -1) {
1641 insertPos += offset;
1643 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1644 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1645 for (int i = 0; i < clipNb; i++) {
1646 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1647 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1648 kDebug()<<"-------------";
1650 kDebug()<<"END-------------";*/
1653 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1654 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1656 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1657 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1658 int position = trackPlaylist.clip_start(clipIndex);
1659 trackPlaylist.remove_region(position, - diff - 1);
1661 trackPlaylist.consolidate_blanks(0);
1665 // now move transitions
1666 mlt_service serv = m_mltProducer->parent().get_service();
1667 mlt_service nextservice = mlt_service_get_producer(serv);
1668 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1669 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1670 QString resource = mlt_properties_get(properties, "mlt_service");
1672 while (mlt_type == "transition") {
1673 mlt_transition tr = (mlt_transition) nextservice;
1674 int currentIn = (int) mlt_transition_get_in(tr);
1675 int currentOut = (int) mlt_transition_get_out(tr);
1676 int currentTrack = mlt_transition_get_b_track(tr);
1677 insertPos = trackTransitionStartList.value(currentTrack);
1678 if (insertPos != -1) {
1679 insertPos += offset;
1680 if (currentOut > insertPos && resource != "mix") {
1681 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1684 nextservice = mlt_service_producer(nextservice);
1685 if (nextservice == NULL) break;
1686 properties = MLT_SERVICE_PROPERTIES(nextservice);
1687 mlt_type = mlt_properties_get(properties, "mlt_type");
1688 resource = mlt_properties_get(properties, "mlt_service");
1691 mlt_service_unlock(service.get_service());
1693 m_mltConsumer->set("refresh", 1);
1696 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1700 Mlt::Service service(m_mltProducer->parent().get_service());
1701 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1702 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1703 Mlt::Tractor tractor(service);
1704 Mlt::Producer trackProducer(tractor.track(info.track));
1705 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1706 int startPos = info.startPos.frames(m_fps);
1707 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1708 int clipLength = trackPlaylist.clip_length(clipIndex);
1710 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1711 if (!clip.is_valid() || clip.is_blank()) {
1715 Mlt::Producer clipparent = clip.parent();
1716 if (!clipparent.is_valid() || clipparent.is_blank()) {
1720 QString serv = clipparent.get("mlt_service");
1721 QString id = clipparent.get("id");
1722 //kDebug() << "CLIP SERVICE: " << serv;
1723 if (serv == "avformat" && speed != 1.0) {
1724 mlt_service_lock(service.get_service());
1725 QString url = QString::fromUtf8(clipparent.get("resource"));
1726 url.append('?' + QString::number(speed));
1727 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1728 if (!slowprod || slowprod->get_producer() == NULL) {
1729 char *tmp = decodedString(url);
1730 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1732 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1733 tmp = decodedString(producerid);
1734 slowprod->set("id", tmp);
1736 m_slowmotionProducers.insert(url, slowprod);
1738 trackPlaylist.replace_with_blank(clipIndex);
1739 trackPlaylist.consolidate_blanks(0);
1740 // Check that the blank space is long enough for our new duration
1741 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1742 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1744 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1745 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1746 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1747 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1748 trackPlaylist.insert_at(startPos, *cut, 1);
1749 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1750 newLength = trackPlaylist.clip_length(clipIndex);
1751 mlt_service_unlock(service.get_service());
1752 } else if (speed == 1.0) {
1753 mlt_service_lock(service.get_service());
1755 trackPlaylist.replace_with_blank(clipIndex);
1756 trackPlaylist.consolidate_blanks(0);
1758 // Check that the blank space is long enough for our new duration
1759 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1760 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1763 GenTime oldDuration = GenTime(clipLength, m_fps);
1764 GenTime newDuration = oldDuration * oldspeed;
1765 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1766 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1767 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1768 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1769 trackPlaylist.insert_at(startPos, *cut, 1);
1770 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1771 newLength = trackPlaylist.clip_length(clipIndex);
1772 mlt_service_unlock(service.get_service());
1774 } else if (serv == "framebuffer") {
1775 mlt_service_lock(service.get_service());
1776 QString url = QString::fromUtf8(clipparent.get("resource"));
1777 url = url.section('?', 0, 0);
1778 url.append('?' + QString::number(speed));
1779 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1780 if (!slowprod || slowprod->get_producer() == NULL) {
1781 char *tmp = decodedString(url);
1782 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1784 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1785 tmp = decodedString(producerid);
1786 slowprod->set("id", tmp);
1788 m_slowmotionProducers.insert(url, slowprod);
1790 trackPlaylist.replace_with_blank(clipIndex);
1791 trackPlaylist.consolidate_blanks(0);
1793 GenTime oldDuration = GenTime(clipLength, m_fps);
1794 GenTime newDuration = oldDuration * oldspeed / speed;
1796 // Check that the blank space is long enough for our new duration
1797 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1798 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1801 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1802 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1803 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1804 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1806 trackPlaylist.insert_at(startPos, *cut, 1);
1807 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1808 newLength = trackPlaylist.clip_length(clipIndex);
1810 mlt_service_unlock(service.get_service());
1812 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1813 m_isBlocked = false;
1817 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1819 kDebug() << "// TRYing to remove effect at: " << index;
1820 Mlt::Service service(m_mltProducer->parent().get_service());
1821 bool success = false;
1822 Mlt::Tractor tractor(service);
1823 Mlt::Producer trackProducer(tractor.track(track));
1824 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1825 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1826 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1828 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1831 Mlt::Service clipService(clip->get_service());
1832 // if (tag.startsWith("ladspa")) tag = "ladspa";
1835 Mlt::Filter *filter = clipService.filter(ct);
1837 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1838 if (clipService.detach(*filter) == 0) success = true;
1839 kDebug() << " / / / DLEETED EFFECT: " << ct;
1840 } else if (updateIndex) {
1841 // Adjust the other effects index
1842 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1845 filter = clipService.filter(ct);
1847 m_isBlocked = false;
1848 if (doRefresh) refresh();
1853 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1856 Mlt::Service service(m_mltProducer->parent().get_service());
1858 Mlt::Tractor tractor(service);
1859 Mlt::Producer trackProducer(tractor.track(track));
1860 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1862 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1866 Mlt::Service clipService(clip->get_service());
1869 // temporarily remove all effects after insert point
1870 QList <Mlt::Filter *> filtersList;
1871 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1873 Mlt::Filter *filter = clipService.filter(ct);
1875 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1876 filtersList.append(filter);
1877 clipService.detach(*filter);
1879 filter = clipService.filter(ct);
1883 QString tag = params.paramValue("tag");
1884 kDebug() << " / / INSERTING EFFECT: " << tag;
1885 if (tag.startsWith("ladspa")) tag = "ladspa";
1886 char *filterTag = decodedString(tag);
1887 char *filterId = decodedString(params.paramValue("id"));
1888 QHash<QString, QString>::Iterator it;
1889 QString kfr = params.paramValue("keyframes");
1891 if (!kfr.isEmpty()) {
1892 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1893 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1894 char *starttag = decodedString(params.paramValue("starttag", "start"));
1895 char *endtag = decodedString(params.paramValue("endtag", "end"));
1896 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1897 int duration = clip->get_playtime();
1898 //double max = params.paramValue("max").toDouble();
1899 double min = params.paramValue("min").toDouble();
1900 double factor = params.paramValue("factor", "1").toDouble();
1901 params.removeParam("starttag");
1902 params.removeParam("endtag");
1903 params.removeParam("keyframes");
1904 params.removeParam("min");
1905 params.removeParam("max");
1906 params.removeParam("factor");
1908 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1909 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1910 if (filter && filter->is_valid()) {
1911 filter->set("kdenlive_id", filterId);
1912 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1913 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1914 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1915 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1916 if (x2 == -1) x2 = duration;
1918 for (int j = 0; j < params.count(); j++) {
1919 char *name = decodedString(params.at(j).name());
1920 char *value = decodedString(params.at(j).value());
1921 filter->set(name, value);
1926 filter->set("in", x1);
1927 filter->set("out", x2);
1928 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1929 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1930 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1931 clipService.attach(*filter);
1938 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1939 if (filter && filter->is_valid())
1940 filter->set("kdenlive_id", filterId);
1942 kDebug() << "filter is NULL";
1943 m_isBlocked = false;
1947 params.removeParam("kdenlive_id");
1949 for (int j = 0; j < params.count(); j++) {
1950 char *name = decodedString(params.at(j).name());
1951 char *value = decodedString(params.at(j).value());
1952 filter->set(name, value);
1958 QString effectArgs = params.paramValue("id").section('_', 1);
1960 params.removeParam("id");
1961 params.removeParam("kdenlive_ix");
1962 params.removeParam("tag");
1963 params.removeParam("disabled");
1965 for (int j = 0; j < params.count(); j++) {
1966 effectArgs.append(' ' + params.at(j).value());
1968 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1969 char *value = decodedString(effectArgs.simplified());
1970 filter->set("effect", value);
1975 // attach filter to the clip
1976 clipService.attach(*filter);
1981 // re-add following filters
1982 for (int i = 0; i < filtersList.count(); i++) {
1983 clipService.attach(*(filtersList.at(i)));
1986 m_isBlocked = false;
1987 if (doRefresh) refresh();
1991 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
1993 QString index = params.paramValue("kdenlive_ix");
1994 QString tag = params.paramValue("tag");
1996 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1997 // This is a keyframe effect, to edit it, we remove it and re-add it.
1998 mltRemoveEffect(track, position, index, true);
1999 bool success = mltAddEffect(track, position, params);
2004 Mlt::Service service(m_mltProducer->parent().get_service());
2006 Mlt::Tractor tractor(service);
2007 Mlt::Producer trackProducer(tractor.track(track));
2008 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2009 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2010 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2012 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2015 Mlt::Service clipService(clip->get_service());
2018 Mlt::Filter *filter = clipService.filter(ct);
2020 if (filter->get("kdenlive_ix") == index) {
2024 filter = clipService.filter(ct);
2028 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2029 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2031 filter = clipService.filter(ct);
2032 QList <Mlt::Filter *> filtersList;
2034 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2035 filtersList.append(filter);
2036 clipService.detach(*filter);
2038 filter = clipService.filter(ct);
2040 bool success = mltAddEffect(track, position, params);
2042 for (int i = 0; i < filtersList.count(); i++) {
2043 clipService.attach(*(filtersList.at(i)));
2046 m_isBlocked = false;
2050 for (int j = 0; j < params.count(); j++) {
2051 char *name = decodedString(params.at(j).name());
2052 char *value = decodedString(params.at(j).value());
2053 filter->set(name, value);
2058 m_isBlocked = false;
2063 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2066 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2067 Mlt::Service service(m_mltProducer->parent().get_service());
2069 Mlt::Tractor tractor(service);
2070 Mlt::Producer trackProducer(tractor.track(track));
2071 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2072 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2073 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2075 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2078 Mlt::Service clipService(clip->get_service());
2081 QList <Mlt::Filter *> filtersList;
2082 Mlt::Filter *filter = clipService.filter(ct);
2084 if (newPos > oldPos) {
2086 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2087 filter->set("kdenlive_ix", newPos);
2088 filtersList.append(filter);
2089 clipService.detach(*filter);
2090 filter = clipService.filter(ct);
2091 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2092 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2094 filter = clipService.filter(ct);
2098 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2099 filtersList.append(filter);
2100 clipService.detach(*filter);
2102 filter = clipService.filter(ct);
2106 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2107 filter->set("kdenlive_ix", newPos);
2108 filtersList.append(filter);
2109 clipService.detach(*filter);
2111 filter = clipService.filter(ct);
2115 filter = clipService.filter(ct);
2117 int pos = QString(filter->get("kdenlive_ix")).toInt();
2118 if (pos >= newPos) {
2119 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2120 filtersList.append(filter);
2121 clipService.detach(*filter);
2123 filter = clipService.filter(ct);
2127 for (int i = 0; i < filtersList.count(); i++) {
2128 clipService.attach(*(filtersList.at(i)));
2131 m_isBlocked = false;
2135 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2139 Mlt::Service service(m_mltProducer->parent().get_service());
2141 Mlt::Tractor tractor(service);
2142 Mlt::Producer trackProducer(tractor.track(info.track));
2143 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2145 /* // Display playlist info
2146 kDebug()<<"//////////// BEFORE RESIZE";
2147 for (int i = 0; i < trackPlaylist.count(); i++) {
2148 int blankStart = trackPlaylist.clip_start(i);
2149 int blankDuration = trackPlaylist.clip_length(i) - 1;
2151 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2152 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2155 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2156 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2157 m_isBlocked = false;
2160 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2161 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2162 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2163 int previousStart = clip->get_in();
2164 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2165 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2166 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2167 trackPlaylist.consolidate_blanks(0);
2168 // skip to next clip
2170 int diff = newDuration - previousDuration;
2171 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2173 // clip was made longer, trim next blank if there is one.
2174 if (clipIndex < trackPlaylist.count()) {
2175 // If this is not the last clip in playlist
2176 if (trackPlaylist.is_blank(clipIndex)) {
2177 int blankStart = trackPlaylist.clip_start(clipIndex);
2178 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2179 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2180 if (diff - blankDuration == 1) {
2181 trackPlaylist.remove(clipIndex);
2182 } else trackPlaylist.remove_region(blankStart, diff - 1);
2184 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2187 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2189 trackPlaylist.consolidate_blanks(0);
2192 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2193 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2194 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2195 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2196 ItemInfo transpinfo;
2197 transpinfo.startPos = info.startPos;
2198 transpinfo.endPos = info.startPos + clipDuration;
2199 transpinfo.track = info.track;
2200 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2202 m_isBlocked = false;
2203 m_mltConsumer->set("refresh", 1);
2207 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2209 Mlt::Service service(m_mltProducer->parent().get_service());
2210 Mlt::Tractor tractor(service);
2211 Mlt::Producer trackProducer(tractor.track(track));
2214 if (blind) trackProducer.set("hide", 3);
2215 else trackProducer.set("hide", 2);
2217 trackProducer.set("hide", 1);
2219 trackProducer.set("hide", 0);
2221 tractor.multitrack()->refresh();
2227 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2229 Mlt::Service service(m_mltProducer->parent().get_service());
2230 int frameOffset = (int) diff.frames(m_fps);
2231 Mlt::Tractor tractor(service);
2232 Mlt::Producer trackProducer(tractor.track(info.track));
2233 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2234 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2235 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2238 mlt_service_lock(service.get_service());
2239 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2240 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2242 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2243 mlt_service_unlock(service.get_service());
2246 int previousStart = clip->get_in();
2247 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2249 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2250 m_isBlocked = false;
2251 mlt_service_unlock(service.get_service());
2252 m_mltConsumer->set("refresh", 1);
2256 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2258 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2259 Mlt::Service service(m_mltProducer->parent().get_service());
2260 int moveFrame = (int) diff.frames(m_fps);
2261 Mlt::Tractor tractor(service);
2262 Mlt::Producer trackProducer(tractor.track(info.track));
2263 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2264 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2265 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2268 mlt_service_lock(service.get_service());
2269 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2270 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2272 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2273 mlt_service_unlock(service.get_service());
2276 int previousStart = clip->get_in();
2277 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2279 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2280 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2281 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2283 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2284 int blankIndex = clipIndex - 1;
2285 int blankLength = trackPlaylist.clip_length(blankIndex);
2286 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2287 if (! trackPlaylist.is_blank(blankIndex)) {
2288 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2290 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2291 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2293 trackPlaylist.consolidate_blanks(0);
2294 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2295 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2296 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2297 ItemInfo transpinfo;
2298 transpinfo.startPos = info.startPos + diff;
2299 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2300 transpinfo.track = info.track;
2301 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2303 m_isBlocked = false;
2304 //m_mltConsumer->set("refresh", 1);
2305 mlt_service_unlock(service.get_service());
2306 m_mltConsumer->set("refresh", 1);
2310 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2312 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2316 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2318 if (prod == NULL || !prod->is_valid()) {
2319 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2322 kDebug() << "NEW PROD ID: " << prod->get("id");
2323 m_mltConsumer->set("refresh", 0);
2324 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2325 mlt_service_lock(m_mltConsumer->get_service());
2326 Mlt::Service service(m_mltProducer->parent().get_service());
2327 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2329 Mlt::Tractor tractor(service);
2330 Mlt::Producer trackProducer(tractor.track(track));
2331 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2332 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2333 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2334 if (clipProducer.is_blank()) {
2335 kDebug() << "// ERROR UPDATING CLIP PROD";
2336 mlt_service_unlock(m_mltConsumer->get_service());
2337 m_isBlocked = false;
2340 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2342 // move all effects to the correct producer
2343 Mlt::Service clipService(clipProducer.get_service());
2344 Mlt::Service newClipService(clip->get_service());
2347 Mlt::Filter *filter = clipService.filter(ct);
2349 if (filter->get("kdenlive_ix") != 0) {
2350 clipService.detach(*filter);
2351 newClipService.attach(*filter);
2353 filter = clipService.filter(ct);
2356 trackPlaylist.insert_at(pos, clip, 1);
2357 mlt_service_unlock(m_mltConsumer->get_service());
2358 m_isBlocked = false;
2361 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2365 m_mltConsumer->set("refresh", 0);
2366 mlt_service_lock(m_mltConsumer->get_service());
2367 Mlt::Service service(m_mltProducer->parent().get_service());
2368 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2370 Mlt::Tractor tractor(service);
2371 Mlt::Producer trackProducer(tractor.track(startTrack));
2372 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2373 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2374 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2375 bool checkLength = false;
2376 if (endTrack == startTrack) {
2377 //mlt_service_lock(service.get_service());
2378 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2379 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2380 // error, destination is not empty
2381 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2382 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2383 mlt_service_unlock(m_mltConsumer->get_service());
2384 m_isBlocked = false;
2387 trackPlaylist.consolidate_blanks(0);
2388 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2389 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2390 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2392 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2394 //mlt_service_unlock(service.get_service());
2396 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2397 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2398 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2399 // error, destination is not empty
2400 mlt_service_unlock(m_mltConsumer->get_service());
2401 m_isBlocked = false;
2404 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2405 if (clipProducer.is_blank()) {
2406 // error, destination is not empty
2407 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2408 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2409 mlt_service_unlock(m_mltConsumer->get_service());
2410 m_isBlocked = false;
2413 trackPlaylist.consolidate_blanks(0);
2414 destTrackPlaylist.consolidate_blanks(1);
2415 Mlt::Producer *clip;
2416 // check if we are moving a slowmotion producer
2417 QString serv = clipProducer.parent().get("mlt_service");
2418 QString currentid = clipProducer.parent().get("id");
2419 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2420 clip = &clipProducer;
2421 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2423 // move all effects to the correct producer
2424 Mlt::Service clipService(clipProducer.get_service());
2425 Mlt::Service newClipService(clip->get_service());
2428 Mlt::Filter *filter = clipService.filter(ct);
2430 if (filter->get("kdenlive_ix") != 0) {
2431 clipService.detach(*filter);
2432 newClipService.attach(*filter);
2434 filter = clipService.filter(ct);
2437 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2438 destTrackPlaylist.consolidate_blanks(0);
2439 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2440 kDebug() << "//////// moving clip transparency";
2441 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2443 if (clipIndex > trackPlaylist.count()) checkLength = true;
2444 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2448 if (checkLength) mltCheckLength();
2449 mlt_service_unlock(m_mltConsumer->get_service());
2450 m_isBlocked = false;
2451 m_mltConsumer->set("refresh", 1);
2455 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2457 int new_in = (int)newIn.frames(m_fps);
2458 int new_out = (int)newOut.frames(m_fps) - 1;
2459 if (new_in >= new_out) return false;
2461 Mlt::Service service(m_mltProducer->parent().get_service());
2462 Mlt::Tractor tractor(service);
2464 mlt_service_lock(service.get_service());
2465 m_mltConsumer->set("refresh", 0);
2468 mlt_service serv = m_mltProducer->parent().get_service();
2469 mlt_service nextservice = mlt_service_get_producer(serv);
2470 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2471 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2472 QString resource = mlt_properties_get(properties, "mlt_service");
2473 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2475 while (mlt_type == "transition") {
2476 mlt_transition tr = (mlt_transition) nextservice;
2477 int currentTrack = mlt_transition_get_b_track(tr);
2478 int currentIn = (int) mlt_transition_get_in(tr);
2479 int currentOut = (int) mlt_transition_get_out(tr);
2481 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2482 mlt_transition_set_in_and_out(tr, new_in, new_out);
2483 if (newTrack - startTrack != 0) {
2484 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2486 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2487 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2488 mlt_properties_set_int(properties, "b_track", newTrack);
2489 //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);
2493 nextservice = mlt_service_producer(nextservice);
2494 if (nextservice == NULL) break;
2495 properties = MLT_SERVICE_PROPERTIES(nextservice);
2496 mlt_type = mlt_properties_get(properties, "mlt_type");
2497 resource = mlt_properties_get(properties, "mlt_service");
2499 m_isBlocked = false;
2500 mlt_service_unlock(service.get_service());
2501 m_mltConsumer->set("refresh", 1);
2505 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2507 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2508 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2510 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2511 mltAddTransition(tag, a_track, b_track, in, out, xml);
2513 //mltSavePlaylist();
2516 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2519 Mlt::Service service(m_mltProducer->parent().get_service());
2520 Mlt::Tractor tractor(service);
2522 //m_mltConsumer->set("refresh", 0);
2523 mlt_service serv = m_mltProducer->parent().get_service();
2525 mlt_service nextservice = mlt_service_get_producer(serv);
2526 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2527 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2528 QString resource = mlt_properties_get(properties, "mlt_service");
2529 int in_pos = (int) in.frames(m_fps);
2530 int out_pos = (int) out.frames(m_fps) - 1;
2532 while (mlt_type == "transition") {
2533 mlt_transition tr = (mlt_transition) nextservice;
2534 int currentTrack = mlt_transition_get_b_track(tr);
2535 int currentBTrack = mlt_transition_get_a_track(tr);
2536 int currentIn = (int) mlt_transition_get_in(tr);
2537 int currentOut = (int) mlt_transition_get_out(tr);
2539 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2541 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2542 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2543 QMap<QString, QString>::Iterator it;
2545 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2546 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2547 if (currentBTrack != a_track) {
2548 mlt_properties_set_int(properties, "a_track", a_track);
2550 for (it = map.begin(); it != map.end(); ++it) {
2552 char *name = decodedString(key);
2553 char *value = decodedString(it.value());
2554 mlt_properties_set(transproperties, name, value);
2555 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2556 //filter->set("kdenlive_id", id);
2562 nextservice = mlt_service_producer(nextservice);
2563 if (nextservice == NULL) break;
2564 properties = MLT_SERVICE_PROPERTIES(nextservice);
2565 mlt_type = mlt_properties_get(properties, "mlt_type");
2566 resource = mlt_properties_get(properties, "mlt_service");
2568 m_isBlocked = false;
2569 m_mltConsumer->set("refresh", 1);
2572 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2574 Mlt::Service service(m_mltProducer->parent().get_service());
2575 Mlt::Tractor tractor(service);
2576 Mlt::Field *field = tractor.field();
2578 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2579 mlt_service serv = m_mltProducer->parent().get_service();
2581 mlt_service nextservice = mlt_service_get_producer(serv);
2582 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2583 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2584 QString resource = mlt_properties_get(properties, "mlt_service");
2586 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2588 while (mlt_type == "transition") {
2589 mlt_transition tr = (mlt_transition) nextservice;
2590 int currentTrack = mlt_transition_get_b_track(tr);
2591 int currentIn = (int) mlt_transition_get_in(tr);
2592 int currentOut = (int) mlt_transition_get_out(tr);
2593 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2595 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2596 mlt_field_disconnect_service(field->get_field(), nextservice);
2599 nextservice = mlt_service_producer(nextservice);
2600 if (nextservice == NULL) break;
2601 properties = MLT_SERVICE_PROPERTIES(nextservice);
2602 mlt_type = mlt_properties_get(properties, "mlt_type");
2603 resource = mlt_properties_get(properties, "mlt_service");
2605 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2608 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2610 QDomNodeList attribs = xml.elementsByTagName("parameter");
2611 QMap<QString, QString> map;
2612 for (int i = 0;i < attribs.count();i++) {
2613 QDomElement e = attribs.item(i).toElement();
2614 QString name = e.attribute("name");
2615 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2616 map[name] = e.attribute("default");
2617 if (!e.attribute("value").isEmpty()) {
2618 map[name] = e.attribute("value");
2620 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2621 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2622 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2625 if (e.attribute("namedesc").contains(';')) {
2626 QString format = e.attribute("format");
2627 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2628 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2630 QTextStream txtNeu(&neu);
2631 if (values.size() > 0)
2632 txtNeu << (int)values[0].toDouble();
2634 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2635 txtNeu << separators[i];
2636 txtNeu << (int)(values[i+1].toDouble());
2638 if (i < separators.size())
2639 txtNeu << separators[i];
2640 map[e.attribute("name")] = neu;
2647 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2649 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2650 Mlt::Service service(m_mltProducer->parent().get_service());
2651 Mlt::Tractor tractor(service);
2652 Mlt::Field *field = tractor.field();
2654 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2655 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2656 transition->set("transparency", id);
2657 transition->set("fill", 1);
2658 transition->set("internal_added", 237);
2659 field->plant_transition(*transition, transitiontrack, info.track);
2663 void Render::mltDeleteTransparency(int pos, int track, int id)
2665 Mlt::Service service(m_mltProducer->parent().get_service());
2666 Mlt::Tractor tractor(service);
2667 Mlt::Field *field = tractor.field();
2669 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2670 mlt_service serv = m_mltProducer->parent().get_service();
2672 mlt_service nextservice = mlt_service_get_producer(serv);
2673 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2674 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2675 QString resource = mlt_properties_get(properties, "mlt_service");
2677 while (mlt_type == "transition") {
2678 mlt_transition tr = (mlt_transition) nextservice;
2679 int currentTrack = mlt_transition_get_b_track(tr);
2680 int currentIn = (int) mlt_transition_get_in(tr);
2681 int currentOut = (int) mlt_transition_get_out(tr);
2682 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2683 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2685 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2686 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2687 mlt_field_disconnect_service(field->get_field(), nextservice);
2690 nextservice = mlt_service_producer(nextservice);
2691 if (nextservice == NULL) break;
2692 properties = MLT_SERVICE_PROPERTIES(nextservice);
2693 mlt_type = mlt_properties_get(properties, "mlt_type");
2694 resource = mlt_properties_get(properties, "mlt_service");
2696 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2699 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2701 Mlt::Service service(m_mltProducer->parent().get_service());
2702 Mlt::Tractor tractor(service);
2704 mlt_service_lock(service.get_service());
2705 m_mltConsumer->set("refresh", 0);
2708 mlt_service serv = m_mltProducer->parent().get_service();
2709 mlt_service nextservice = mlt_service_get_producer(serv);
2710 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2711 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2712 QString resource = mlt_properties_get(properties, "mlt_service");
2713 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2714 while (mlt_type == "transition") {
2715 mlt_transition tr = (mlt_transition) nextservice;
2716 int currentTrack = mlt_transition_get_b_track(tr);
2717 int currentIn = (int) mlt_transition_get_in(tr);
2718 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2719 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2720 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2721 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2722 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2723 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2726 nextservice = mlt_service_producer(nextservice);
2727 if (nextservice == NULL) break;
2728 properties = MLT_SERVICE_PROPERTIES(nextservice);
2729 mlt_type = mlt_properties_get(properties, "mlt_type");
2730 resource = mlt_properties_get(properties, "mlt_service");
2732 m_isBlocked = false;
2733 mlt_service_unlock(service.get_service());
2734 m_mltConsumer->set("refresh", 1);
2738 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2740 Mlt::Service service(m_mltProducer->parent().get_service());
2741 Mlt::Tractor tractor(service);
2743 mlt_service_lock(service.get_service());
2744 m_mltConsumer->set("refresh", 0);
2747 mlt_service serv = m_mltProducer->parent().get_service();
2748 mlt_service nextservice = mlt_service_get_producer(serv);
2749 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2750 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2751 QString resource = mlt_properties_get(properties, "mlt_service");
2753 while (mlt_type == "transition") {
2754 mlt_transition tr = (mlt_transition) nextservice;
2755 int currentTrack = mlt_transition_get_b_track(tr);
2756 int currentaTrack = mlt_transition_get_a_track(tr);
2757 int currentIn = (int) mlt_transition_get_in(tr);
2758 int currentOut = (int) mlt_transition_get_out(tr);
2759 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2760 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2761 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2762 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2763 kDebug() << "//////MOVING";
2764 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2765 if (endTrack != startTrack) {
2766 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2767 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2768 mlt_properties_set_int(properties, "b_track", endTrack);
2772 nextservice = mlt_service_producer(nextservice);
2773 if (nextservice == NULL) break;
2774 properties = MLT_SERVICE_PROPERTIES(nextservice);
2775 mlt_type = mlt_properties_get(properties, "mlt_type");
2776 resource = mlt_properties_get(properties, "mlt_service");
2778 m_isBlocked = false;
2779 mlt_service_unlock(service.get_service());
2780 m_mltConsumer->set("refresh", 1);
2784 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2786 if (in >= out) return false;
2787 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2788 Mlt::Service service(m_mltProducer->parent().get_service());
2790 Mlt::Tractor tractor(service);
2791 Mlt::Field *field = tractor.field();
2793 char *transId = decodedString(tag);
2794 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2795 if (out != GenTime())
2796 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2797 QMap<QString, QString>::Iterator it;
2799 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2800 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2802 for (it = args.begin(); it != args.end(); ++it) {
2804 char *name = decodedString(key);
2805 char *value = decodedString(it.value());
2806 transition->set(name, value);
2807 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2808 //filter->set("kdenlive_id", id);
2812 // attach filter to the clip
2813 field->plant_transition(*transition, a_track, b_track);
2819 void Render::mltSavePlaylist()
2821 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2822 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2823 fileConsumer.set("resource", "/tmp/playlist.westley");
2825 Mlt::Service service(m_mltProducer->get_service());
2827 fileConsumer.connect(service);
2828 fileConsumer.start();
2831 QList <Mlt::Producer *> Render::producersList()
2833 QList <Mlt::Producer *> prods;
2834 Mlt::Service service(m_mltProducer->parent().get_service());
2835 if (service.type() != tractor_type) return prods;
2836 Mlt::Tractor tractor(service);
2839 int trackNb = tractor.count();
2840 for (int t = 1; t < trackNb; t++) {
2841 Mlt::Producer trackProducer(tractor.track(t));
2842 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2843 int clipNb = trackPlaylist.count();
2844 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2845 for (int i = 0; i < clipNb; i++) {
2846 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2847 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2848 ids.append(nprod->get("id"));
2849 prods.append(nprod);
2856 void Render::fillSlowMotionProducers()
2858 Mlt::Service service(m_mltProducer->parent().get_service());
2859 if (service.type() != tractor_type) return;
2861 Mlt::Tractor tractor(service);
2863 int trackNb = tractor.count();
2864 for (int t = 1; t < trackNb; t++) {
2865 Mlt::Producer trackProducer(tractor.track(t));
2866 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2867 int clipNb = trackPlaylist.count();
2868 for (int i = 0; i < clipNb; i++) {
2869 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2870 if (nprod && !nprod->is_blank()) {
2871 QString id = nprod->get("id");
2872 if (id.startsWith("slowmotion:")) {
2873 // this is a slowmotion producer, add it to the list
2874 QString url = QString::fromUtf8(nprod->get("resource"));
2875 if (!m_slowmotionProducers.contains(url)) {
2876 m_slowmotionProducers.insert(url, nprod);
2884 void Render::mltInsertTrack(int ix, bool videoTrack)
2889 m_mltConsumer->set("refresh", 0);
2890 mlt_service_lock(m_mltConsumer->get_service());
2891 Mlt::Service service(m_mltProducer->parent().get_service());
2892 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2894 Mlt::Tractor tractor(service);
2896 Mlt::Playlist playlist;// = new Mlt::Playlist();
2897 int ct = tractor.count();
2898 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2901 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2902 tractor.set_track(playlist, pos);
2903 Mlt::Producer newProd(tractor.track(pos));
2904 if (!videoTrack) newProd.set("hide", 1);
2906 for (; pos <= ct; pos++) {
2907 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2908 tractor.set_track(*prodToMove, pos);
2909 prodToMove = prodToMove2;
2912 tractor.set_track(playlist, ix);
2913 Mlt::Producer newProd(tractor.track(ix));
2914 if (!videoTrack) newProd.set("hide", 1);
2918 mlt_service serv = m_mltProducer->parent().get_service();
2919 mlt_service nextservice = mlt_service_get_producer(serv);
2920 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2921 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2922 QString resource = mlt_properties_get(properties, "mlt_service");
2924 while (mlt_type == "transition") {
2925 if (resource != "mix") {
2926 mlt_transition tr = (mlt_transition) nextservice;
2927 int currentTrack = mlt_transition_get_b_track(tr);
2928 int currentaTrack = mlt_transition_get_a_track(tr);
2929 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2931 if (currentTrack >= ix) {
2932 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2933 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2936 nextservice = mlt_service_producer(nextservice);
2937 if (nextservice == NULL) break;
2938 properties = MLT_SERVICE_PROPERTIES(nextservice);
2939 mlt_type = mlt_properties_get(properties, "mlt_type");
2940 resource = mlt_properties_get(properties, "mlt_service");
2943 // Add audio mix transition to last track
2944 Mlt::Field *field = tractor.field();
2945 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2946 //transition->set("mlt_service", "mix");
2947 transition->set("a_track", 1);
2948 transition->set("b_track", ct);
2949 transition->set("always_active", 1);
2950 transition->set("internal_added", 237);
2951 transition->set("combine", 1);
2952 field->plant_transition(*transition, 1, ct);
2954 mlt_service_unlock(m_mltConsumer->get_service());
2955 m_isBlocked = false;
2956 blockSignals(false);
2960 void Render::mltDeleteTrack(int ix)
2963 doc.setContent(sceneList(), false);
2964 int tracksCount = doc.elementsByTagName("track").count() - 1;
2965 QDomNode track = doc.elementsByTagName("track").at(ix);
2966 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2967 QDomNodeList transitions = doc.elementsByTagName("transition");
2968 for (int i = 0; i < transitions.count(); i++) {
2969 QDomElement e = transitions.at(i).toElement();
2970 QDomNodeList props = e.elementsByTagName("property");
2971 QMap <QString, QString> mappedProps;
2972 for (int j = 0; j < props.count(); j++) {
2973 QDomElement f = props.at(j).toElement();
2974 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2976 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2977 tractor.removeChild(transitions.at(i));
2978 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2979 // Transition needs to be moved
2980 int a_track = mappedProps.value("a_track").toInt();
2981 int b_track = mappedProps.value("b_track").toInt();
2982 if (a_track > 0) a_track --;
2983 if (b_track > 0) b_track --;
2984 for (int j = 0; j < props.count(); j++) {
2985 QDomElement f = props.at(j).toElement();
2986 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2987 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2992 tractor.removeChild(track);
2993 setSceneList(doc.toString(), m_framePosition);
3000 m_mltConsumer->set("refresh", 0);
3001 mlt_service_lock(m_mltConsumer->get_service());
3002 Mlt::Service service(m_mltProducer->parent().get_service());
3003 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
3005 /*Mlt::Tractor tractor(service);
3008 Mlt::Multitrack *multi = tractor.multitrack();
3011 int ct = tractor.count();
3012 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
3014 for (; pos < ct ; pos++) {
3015 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
3016 //mlt_service_close(lastTrack->get_service());
3018 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
3019 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
3020 mlt_service_close(prodToMove->get_service());
3021 mlt_service_close(prodToClose->get_service());
3022 tractor.set_track(*prodToMove, pos);
3026 /*mlt_service serv = m_mltProducer->parent().get_service();
3027 mlt_service nextservice = mlt_service_get_producer(serv);
3028 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3029 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3030 QString resource = mlt_properties_get(properties, "mlt_service");
3032 while (mlt_type == "transition") {
3033 if (resource != "mix") {
3034 mlt_transition tr = (mlt_transition) nextservice;
3035 int currentTrack = mlt_transition_get_b_track(tr);
3036 int currentaTrack = mlt_transition_get_a_track(tr);
3037 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3039 if (currentTrack >= ix) {
3040 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3041 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3044 nextservice = mlt_service_producer(nextservice);
3045 if (nextservice == NULL) break;
3046 properties = MLT_SERVICE_PROPERTIES(nextservice);
3047 mlt_type = mlt_properties_get(properties, "mlt_type");
3048 resource = mlt_properties_get(properties, "mlt_service");
3051 // Add audio mix transition to last track
3052 Mlt::Field *field = tractor.field();
3053 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3054 //transition->set("mlt_service", "mix");
3055 transition->set("a_track", 1);
3056 transition->set("b_track", ct);
3057 transition->set("always_active", 1);
3058 transition->set("internal_added", 237);
3059 transition->set("combine", 1);
3060 field->plant_transition(*transition, 1, ct);
3063 mlt_service_unlock(m_mltConsumer->get_service());
3064 m_isBlocked = false;
3065 blockSignals(false);
3069 void Render::updatePreviewSettings()
3071 kDebug() << "////// RESTARTING CONSUMER";
3072 if (!m_mltConsumer || !m_mltProducer) return;
3073 if (m_mltProducer->get_playtime() == 0) return;
3074 Mlt::Service service(m_mltProducer->parent().get_service());
3075 if (service.type() != tractor_type) return;
3077 //m_mltConsumer->set("refresh", 0);
3078 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3079 m_mltConsumer->purge();
3080 QString scene = sceneList();
3082 if (m_mltProducer) {
3083 pos = m_mltProducer->position();
3084 delete m_mltProducer;
3086 m_mltProducer = NULL;
3087 setSceneList(scene, pos);
3090 #include "renderer.moc"