1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
31 #include <mlt++/Mlt.h>
34 #include <KStandardDirs>
35 #include <KMessageBox>
37 #include <KTemporaryFile>
41 #include <QApplication>
45 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
47 // detect if the producer has finished playing. Is there a better way to do it?
48 if (self->m_isBlocked) return;
49 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
50 self->emitConsumerStopped();
52 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
56 Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget *parent) :
69 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
70 m_refreshTimer = new QTimer(this);
71 connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
73 /*if (rendererName == "project") m_monitorId = 10000;
74 else m_monitorId = 10001;*/
75 m_osdTimer = new QTimer(this);
76 connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
80 m_mltProducer = m_blackClip->cut(0, 50);
81 m_mltConsumer->connect(*m_mltProducer);
82 m_mltProducer->set_speed(0.0);
91 void Render::closeMlt()
94 delete m_refreshTimer;
102 void Render::buildConsumer()
105 m_activeProfile = KdenliveSettings::current_profile();
106 tmp = decodedString(m_activeProfile);
107 setenv("MLT_PROFILE", tmp, 1);
111 m_mltProfile = new Mlt::Profile(tmp);
114 QString videoDriver = KdenliveSettings::videodrivername();
115 if (!videoDriver.isEmpty()) {
116 if (videoDriver == "x11_noaccel") {
117 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
120 unsetenv("SDL_VIDEO_YUV_HWACCEL");
123 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
125 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
126 m_mltConsumer->set("resize", 1);
127 m_mltConsumer->set("window_id", m_winid);
128 m_mltConsumer->set("terminate_on_pause", 1);
129 tmp = decodedString(KdenliveSettings::window_background().name());
130 m_mltConsumer->set("window_background", tmp);
133 // FIXME: the event object returned by the listen gets leaked...
134 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
135 m_mltConsumer->set("rescale", "nearest");
137 QString audioDevice = KdenliveSettings::audiodevicename();
138 if (!audioDevice.isEmpty()) {
139 tmp = decodedString(audioDevice);
140 m_mltConsumer->set("audio_device", tmp);
144 if (!videoDriver.isEmpty()) {
145 tmp = decodedString(videoDriver);
146 m_mltConsumer->set("video_driver", tmp);
150 QString audioDriver = KdenliveSettings::audiodrivername();
151 if (audioDriver.isEmpty())
152 audioDriver = KdenliveSettings::autoaudiodrivername();
153 if (!audioDriver.isEmpty()) {
154 tmp = decodedString(audioDriver);
155 m_mltConsumer->set("audio_driver", tmp);
160 m_mltConsumer->set("progressive", 1);
161 m_mltConsumer->set("audio_buffer", 1024);
162 m_mltConsumer->set("frequency", 48000);
164 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
165 m_blackClip->set("id", "black");
169 int Render::resetProfile()
171 if (!m_mltConsumer) return 0;
172 if (m_activeProfile == KdenliveSettings::current_profile()) {
173 kDebug() << "reset to same profile, nothing to do";
176 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
177 if (m_isSplitView) slotSplitView(false);
178 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
179 m_mltConsumer->purge();
180 delete m_mltConsumer;
181 m_mltConsumer = NULL;
182 QString scene = sceneList();
185 pos = m_mltProducer->position();
186 delete m_mltProducer;
188 m_mltProducer = NULL;
190 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
191 /*if (m_mltProfile) delete m_mltProfile;
192 m_mltProfile = NULL;*/
196 //kDebug() << "//RESET WITHSCENE: " << scene;
197 setSceneList(scene, pos);
199 /*char *tmp = decodedString(scene);
200 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
202 m_mltProducer = producer;
203 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
204 m_mltProducer->optimise();
205 m_mltProducer->set_speed(0);
208 //delete m_mltProfile;
209 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
210 //mlt_profile prof = m_mltProfile->get_profile();
211 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
212 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
213 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
214 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
216 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
221 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
222 void Render::seek(GenTime time)
227 m_mltProducer->seek((int)(time.frames(m_fps)));
232 char *Render::decodedString(QString str)
234 /*QCString fn = QFile::encodeName(str);
235 char *t = new char[fn.length() + 1];
236 strcpy(t, (const char *)fn);*/
238 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
242 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
243 QPixmap pix(width, height);
245 mlt_image_format format = mlt_image_rgb24a;
246 uint8_t *thumb = frame->get_image(format, width, height);
247 QImage image(thumb, width, height, QImage::Format_ARGB32);
249 if (!image.isNull()) {
250 pix = pix.fromImage(image);
252 QPainter painter(&pix);
253 painter.drawRect(0, 0, width - 1, height - 1);
255 } else pix.fill(Qt::black);
259 int Render::renderWidth() const
261 return (int)(m_mltProfile->height() * m_mltProfile->dar());
264 int Render::renderHeight() const
266 return m_mltProfile->height();
269 QPixmap Render::extractFrame(int frame_position, int width, int height)
272 width = renderWidth();
273 height = renderHeight();
274 } else if (width % 2 == 1) width++;
275 QPixmap pix(width, height);
276 if (!m_mltProducer) {
280 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
283 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
287 if (url.fileName().startsWith(".all.")) { // check for slideshow
288 QString fileType = url.fileName().right(3);
290 QStringList::Iterator it;
292 QDir dir(url.directory());
294 filter << "*." + fileType;
295 filter << "*." + fileType.toUpper();
296 more = dir.entryList(filter, QDir::Files);
297 im.load(url.directory() + '/' + more.at(0));
298 } else im.load(url.path());
299 //pixmap = im.scaled(width, height);
304 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
305 QPixmap pix(width, height);
306 char *tmp = decodedString(file);
307 Mlt::Profile *prof = new Mlt::Profile(profile);
308 Mlt::Producer m_producer(*prof, tmp);
310 if (m_producer.is_blank()) {
315 Mlt::Filter m_convert(*prof, "avcolour_space");
316 m_convert.set("forced", mlt_image_rgb24a);
317 m_producer.attach(m_convert);
318 m_producer.seek(frame_position);
319 Mlt::Frame * frame = m_producer.get_frame();
321 pix = frameThumbnail(frame, width, height, true);
324 if (prof) delete prof;
329 void Render::getImage(KUrl url, int frame_position, QPoint size)
331 char *tmp = decodedString(url.path());
332 Mlt::Producer m_producer(tmp);
334 if (m_producer.is_blank()) {
337 Mlt::Filter m_convert("avcolour_space");
338 m_convert.set("forced", mlt_image_rgb24a);
339 m_producer.attach(m_convert);
340 m_producer.seek(frame_position);
342 Mlt::Frame * frame = m_producer.get_frame();
345 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
347 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
351 /* Create thumbnail for color */
352 /*void Render::getImage(int id, QString color, QPoint size)
354 QPixmap pixmap(size.x() - 2, size.y() - 2);
355 color = color.replace(0, 2, "#");
356 color = color.left(7);
357 pixmap.fill(QColor(color));
358 QPixmap result(size.x(), size.y());
359 result.fill(Qt::black);
360 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
361 emit replyGetImage(id, result, size.x(), size.y());
365 /* Create thumbnail for image */
366 /*void Render::getImage(KUrl url, QPoint size)
370 if (url.fileName().startsWith(".all.")) { // check for slideshow
371 QString fileType = url.fileName().right(3);
373 QStringList::Iterator it;
375 QDir dir( url.directory() );
376 more = dir.entryList( QDir::Files );
377 for ( it = more.begin() ; it != more.end() ; ++it ) {
378 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
379 if (!im.load(url.directory() + '/' + *it))
380 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
385 else im.load(url.path());
387 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
388 QPixmap result(size.x(), size.y());
389 result.fill(Qt::black);
390 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
391 emit replyGetImage(url, 1, result, size.x(), size.y());
395 double Render::consumerRatio() const
397 if (!m_mltConsumer) return 1.0;
398 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
402 int Render::getLength()
406 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
407 return mlt_producer_get_playtime(m_mltProducer->get_producer());
412 bool Render::isValid(KUrl url)
414 char *tmp = decodedString(url.path());
415 Mlt::Producer producer(*m_mltProfile, tmp);
417 if (producer.is_blank())
423 double Render::dar() const
425 return m_mltProfile->dar();
428 void Render::slotSplitView(bool doit)
430 m_isSplitView = doit;
431 Mlt::Service service(m_mltProducer->parent().get_service());
432 Mlt::Tractor tractor(service);
433 if (service.type() != tractor_type || tractor.count() < 2) return;
434 Mlt::Field *field = tractor.field();
437 for (int i = 1; i < tractor.count() && screen < 4; i++) {
438 Mlt::Producer trackProducer(tractor.track(i));
439 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
440 if (QString(trackProducer.get("hide")).toInt() != 1) {
441 kDebug() << "// ADIDNG TRACK: " << i;
442 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
443 transition->set("mlt_service", "composite");
444 transition->set("a_track", 0);
445 transition->set("b_track", i);
446 transition->set("distort", 1);
447 transition->set("internal_added", "200");
454 tmp = "50%,0:50%x50%";
457 tmp = "0,50%:50%x50%";
461 tmp = "50%,50%:50%x50%";
464 transition->set("geometry", tmp);
465 transition->set("always_active", "1");
466 field->plant_transition(*transition, 0, i);
471 m_mltConsumer->set("refresh", 1);
473 mlt_service serv = m_mltProducer->parent().get_service();
474 mlt_service nextservice = mlt_service_get_producer(serv);
475 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
476 QString mlt_type = mlt_properties_get(properties, "mlt_type");
477 QString resource = mlt_properties_get(properties, "mlt_service");
479 while (mlt_type == "transition") {
480 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
481 if (added == "200") {
482 mlt_field_disconnect_service(field->get_field(), nextservice);
484 nextservice = mlt_service_producer(nextservice);
485 if (nextservice == NULL) break;
486 properties = MLT_SERVICE_PROPERTIES(nextservice);
487 mlt_type = mlt_properties_get(properties, "mlt_type");
488 resource = mlt_properties_get(properties, "mlt_service");
489 m_mltConsumer->set("refresh", 1);
494 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer)
496 KUrl url = KUrl(xml.attribute("resource", QString()));
497 Mlt::Producer *producer = NULL;
498 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
499 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
502 if (xml.attribute("type").toInt() == COLOR) {
503 char *tmp = decodedString("colour:" + xml.attribute("colour"));
504 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
506 } else if (url.isEmpty()) {
508 QDomElement mlt = doc.createElement("mlt");
509 QDomElement play = doc.createElement("playlist");
510 doc.appendChild(mlt);
511 mlt.appendChild(play);
512 play.appendChild(doc.importNode(xml, true));
513 char *tmp = decodedString(doc.toString());
514 producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
517 char *tmp = decodedString(url.path());
518 producer = new Mlt::Producer(*m_mltProfile, tmp);
522 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
523 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
524 emit removeInvalidClip(clipId, replaceProducer);
529 if (xml.hasAttribute("force_aspect_ratio")) {
530 double aspect = xml.attribute("force_aspect_ratio").toDouble();
531 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
533 if (xml.hasAttribute("threads")) {
534 int threads = xml.attribute("threads").toInt();
535 if (threads != 1) producer->set("threads", threads);
537 if (xml.hasAttribute("video_index")) {
538 int vindex = xml.attribute("video_index").toInt();
539 if (vindex != 0) producer->set("video_index", vindex);
541 if (xml.hasAttribute("audio_index")) {
542 int aindex = xml.attribute("audio_index").toInt();
543 if (aindex != 0) producer->set("audio_index", aindex);
546 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
548 char *tmp = decodedString(clipId);
549 producer->set("id", tmp);
553 int width = (int)(height * m_mltProfile->dar());
554 QMap < QString, QString > filePropertyMap;
555 QMap < QString, QString > metadataPropertyMap;
557 int frameNumber = xml.attribute("thumbnail", "0").toInt();
558 if (frameNumber != 0) producer->seek(frameNumber);
560 filePropertyMap["duration"] = QString::number(producer->get_playtime());
561 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
563 Mlt::Frame *frame = producer->get_frame();
565 if (xml.attribute("type").toInt() == SLIDESHOW) {
566 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
567 if (xml.attribute("fade") == "1") {
568 // user wants a fade effect to slideshow
569 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
570 if (filter && filter->is_valid()) {
571 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
572 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
573 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
574 char *tmp = decodedString(xml.attribute("luma_file"));
575 filter->set("luma.resource", tmp);
577 if (xml.hasAttribute("softness")) {
578 int soft = xml.attribute("softness").toInt();
579 filter->set("luma.softness", (double) soft / 100.0);
582 Mlt::Service clipService(producer->get_service());
583 clipService.attach(*filter);
589 filePropertyMap["fps"] = producer->get("source_fps");
591 if (frame && frame->is_valid()) {
592 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
593 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
594 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
595 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
597 if (frame->get_int("test_image") == 0) {
598 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
599 filePropertyMap["type"] = "playlist";
600 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
601 } else if (frame->get_int("test_audio") == 0)
602 filePropertyMap["type"] = "av";
604 filePropertyMap["type"] = "video";
606 mlt_image_format format = mlt_image_yuv422;
608 int frame_height = 0;
609 //frame->set("rescale.interp", "hyper");
610 frame->set("normalised_height", height);
611 frame->set("normalised_width", width);
612 QPixmap pix(width, height);
614 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
615 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
616 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
617 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
619 if (!image.isNull()) {
620 pix = QPixmap::fromImage(image.rgbSwapped());
624 mlt_pool_release(new_image);
625 emit replyGetImage(clipId, pix);
627 } else if (frame->get_int("test_audio") == 0) {
628 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
629 emit replyGetImage(clipId, pixmap);
630 filePropertyMap["type"] = "audio";
634 // Retrieve audio / video codec name
638 if (producer->get_int("video_index") > -1) {
639 /*if (context->duration == AV_NOPTS_VALUE) {
640 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
641 emit removeInvalidClip(clipId);
645 // Get the video_index
646 int default_video = producer->get_int("video_index");
648 int default_audio = producer->get_int("audio_index");
651 // Find maximum stream index values
652 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
653 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
654 QString type = producer->get(property);
657 else if (type == "audio")
660 filePropertyMap["default_video"] = QString::number(default_video);
661 filePropertyMap["video_max"] = QString::number(video_max);
662 filePropertyMap["default_audio"] = QString::number(default_audio);
663 filePropertyMap["audio_max"] = QString::number(audio_max);
665 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
666 if (producer->get(property)) {
667 filePropertyMap["videocodec"] = producer->get(property);
669 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
670 if (producer->get(property))
671 filePropertyMap["videocodec"] = producer->get(property);
674 if (KdenliveSettings::dropbframes()) {
675 kDebug() << "// LOOKING FOR H264 on: " << default_video;
676 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
677 kDebug() << "PROP: " << property << " = " << producer->get(property);
678 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
679 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
680 producer->set("skip_loop_filter", "all");
681 producer->set("skip_frame", "bidir");
685 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
686 if (producer->get_int("audio_index") > -1) {
687 // Get the audio_index
688 int index = producer->get_int("audio_index");
690 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
691 if (producer->get(property)) {
692 filePropertyMap["audiocodec"] = producer->get(property);
694 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
695 if (producer->get(property))
696 filePropertyMap["audiocodec"] = producer->get(property);
701 Mlt::Properties metadata;
702 metadata.pass_values(*producer, "meta.attr.");
703 int count = metadata.count();
704 for (int i = 0; i < count; i ++) {
705 QString name = metadata.get_name(i);
706 QString value = QString::fromUtf8(metadata.get(i));
707 if (name.endsWith("markup") && !value.isEmpty())
708 metadataPropertyMap[ name.section('.', 0, -2)] = value;
711 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
712 kDebug() << "REquested fuile info for: " << url.path();
714 // FIXME: should delete this to avoid a leak...
719 /** Create the producer from the MLT XML QDomDocument */
721 void Render::initSceneList()
723 kDebug() << "-------- INIT SCENE LIST ------_";
725 QDomElement mlt = doc.createElement("mlt");
726 doc.appendChild(mlt);
727 QDomElement prod = doc.createElement("producer");
728 prod.setAttribute("resource", "colour");
729 prod.setAttribute("colour", "red");
730 prod.setAttribute("id", "black");
731 prod.setAttribute("in", "0");
732 prod.setAttribute("out", "0");
734 QDomElement tractor = doc.createElement("tractor");
735 QDomElement multitrack = doc.createElement("multitrack");
737 QDomElement playlist1 = doc.createElement("playlist");
738 playlist1.appendChild(prod);
739 multitrack.appendChild(playlist1);
740 QDomElement playlist2 = doc.createElement("playlist");
741 multitrack.appendChild(playlist2);
742 QDomElement playlist3 = doc.createElement("playlist");
743 multitrack.appendChild(playlist3);
744 QDomElement playlist4 = doc.createElement("playlist");
745 multitrack.appendChild(playlist4);
746 QDomElement playlist5 = doc.createElement("playlist");
747 multitrack.appendChild(playlist5);
748 tractor.appendChild(multitrack);
749 mlt.appendChild(tractor);
750 // kDebug()<<doc.toString();
752 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
753 setSceneList(doc, 0);
759 /** Create the producer from the MLT XML QDomDocument */
760 void Render::setProducer(Mlt::Producer *producer, int position)
762 if (m_winid == -1) return;
765 m_mltConsumer->stop();
768 m_mltConsumer->purge();
772 m_mltProducer->set_speed(0);
773 delete m_mltProducer;
774 m_mltProducer = NULL;
778 m_mltProducer = new Mlt::Producer(producer->get_producer());
779 } else m_mltProducer = m_blackClip->cut(0, 50);
780 /*if (KdenliveSettings::dropbframes()) {
781 m_mltProducer->set("skip_loop_filter", "all");
782 m_mltProducer->set("skip_frame", "bidir");
784 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
786 m_fps = m_mltProducer->get_fps();
788 if (position != -1) {
789 m_mltProducer->seek(position);
790 emit rendererPosition(position);
797 /** Create the producer from the MLT XML QDomDocument */
798 void Render::setSceneList(QDomDocument list, int position)
800 setSceneList(list.toString(), position);
803 /** Create the producer from the MLT XML QDomDocument */
804 void Render::setSceneList(QString playlist, int position)
806 if (m_winid == -1) return;
808 qDeleteAll(m_slowmotionProducers.values());
809 m_slowmotionProducers.clear();
811 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
813 if (m_mltConsumer == NULL) {
814 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
819 if (!m_mltConsumer->is_stopped()) {
820 m_mltConsumer->stop();
821 //m_mltConsumer->set("refresh", 0);
825 m_mltProducer->set_speed(0);
826 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
828 delete m_mltProducer;
829 m_mltProducer = NULL;
834 char *tmp = decodedString(playlist);
835 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
837 if (!m_mltProducer || !m_mltProducer->is_valid()) {
838 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
839 m_mltProducer = m_blackClip->cut(0, 50);
843 m_mltProducer->optimise();
845 /*if (KdenliveSettings::osdtimecode()) {
846 // Attach filter for on screen display of timecode
848 QString attr = "attr_check";
849 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
850 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
851 mlt_producer_attach( m_mltProducer->get_producer(), filter );
852 mlt_filter_close( filter );
854 m_osdInfo = new Mlt::Filter("data_show");
855 tmp = decodedString(m_osdProfile);
856 m_osdInfo->set("resource", tmp);
858 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
859 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
860 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
861 m_osdInfo->set("dynamic", "1");
863 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
865 m_osdInfo->set("dynamic", "0");
868 m_fps = m_mltProducer->get_fps();
869 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
871 fillSlowMotionProducers();
873 //TODO: seek to correct place after opening project.
874 // Needs to be done from another place since it crashes here.
875 m_mltProducer->seek(position);
879 emit refreshDocumentProducers();
880 //kDebug()<<"// SETSCN LST, POS: "<<position;
881 //if (position != 0) emit rendererPosition(position);
884 /** Create the producer from the MLT XML QDomDocument */
885 const QString Render::sceneList()
888 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
889 m_mltProducer->optimise();
890 xmlConsumer.set("terminate_on_pause", 1);
891 Mlt::Producer prod(m_mltProducer->get_producer());
892 bool split = m_isSplitView;
893 if (split) slotSplitView(false);
894 xmlConsumer.connect(prod);
896 while (!xmlConsumer.is_stopped()) {}
897 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
898 if (split) slotSplitView(true);
902 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
906 doc.setContent(sceneList(), false);
907 if (!kdenliveData.isNull()) {
908 // add Kdenlive specific tags
909 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
910 mlt.appendChild(doc.importNode(kdenliveData, true));
912 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
913 kWarning() << "////// ERROR writing to file: " << path;
916 file.write(doc.toString().toUtf8());
917 if (file.error() != QFile::NoError) {
926 void Render::saveZone(KUrl url, QString desc, QPoint zone)
928 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
929 char *tmppath = decodedString("xml:" + url.path());
930 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
931 m_mltProducer->optimise();
933 xmlConsumer.set("terminate_on_pause", 1);
934 if (m_name == "clip") {
935 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
936 tmppath = decodedString(desc);
938 list.insert_at(0, prod, 0);
939 list.set("title", tmppath);
941 xmlConsumer.connect(list);
944 //TODO: not working yet, save zone from timeline
945 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
946 /* Mlt::Service service(p1->parent().get_service());
947 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
949 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
950 tmppath = decodedString(desc);
951 //prod->set("title", tmppath);
953 xmlConsumer.connect(*p1); //list);
959 double Render::fps() const
964 void Render::connectPlaylist()
966 if (!m_mltConsumer) return;
967 //m_mltConsumer->set("refresh", "0");
968 m_mltConsumer->connect(*m_mltProducer);
969 m_mltProducer->set_speed(0);
970 m_mltConsumer->start();
971 emit durationChanged(m_mltProducer->get_playtime());
974 if (m_mltConsumer->start() == -1) {
975 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."));
976 delete m_mltConsumer;
977 m_mltConsumer = NULL;
984 void Render::refreshDisplay()
987 if (!m_mltProducer) return;
988 //m_mltConsumer->set("refresh", 0);
990 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
991 /*if (KdenliveSettings::osdtimecode()) {
992 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
993 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
994 m_osdInfo->set("dynamic", "1");
995 m_mltProducer->attach(*m_osdInfo);
998 m_mltProducer->detach(*m_osdInfo);
999 m_osdInfo->set("dynamic", "0");
1004 void Render::setVolume(double /*volume*/)
1006 if (!m_mltConsumer || !m_mltProducer) return;
1008 m_mltConsumer->set("refresh", 0);
1009 // Attach filter for on screen display of timecode
1010 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1011 mlt_properties_set_double( properties, "meta.volume", volume );
1012 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1013 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1015 if (!KdenliveSettings::osdtimecode()) {
1016 m_mltProducer->detach(*m_osdInfo);
1017 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1018 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1021 m_osdTimer->setSingleShot(2500);
1024 void Render::slotOsdTimeout()
1026 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1027 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1028 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1029 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1033 void Render::start()
1035 kDebug() << "----- STARTING MONITOR: " << m_name;
1036 if (m_winid == -1) {
1037 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1041 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1042 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1043 if (m_mltConsumer->start() == -1) {
1044 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."));
1045 delete m_mltConsumer;
1046 m_mltConsumer = NULL;
1049 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1050 m_isBlocked = false;
1054 m_isBlocked = false;
1057 void Render::clear()
1059 kDebug() << " ********* RENDER CLEAR";
1060 if (m_mltConsumer) {
1061 //m_mltConsumer->set("refresh", 0);
1062 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1065 if (m_mltProducer) {
1066 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1067 m_mltProducer->set_speed(0.0);
1068 delete m_mltProducer;
1069 m_mltProducer = NULL;
1076 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1077 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1079 //m_mltConsumer->set("refresh", 0);
1080 m_mltConsumer->stop();
1081 // delete m_mltConsumer;
1082 // m_mltConsumer = NULL;
1084 kDebug() << "///////////// RENDER STOP2-------";
1087 if (m_mltProducer) {
1088 if (m_isZoneMode) resetZoneMode();
1089 m_mltProducer->set_speed(0.0);
1090 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1091 //kDebug() << m_mltProducer->get_length();
1093 kDebug() << "///////////// RENDER STOP3-------";
1096 void Render::stop(const GenTime & startTime)
1099 kDebug() << "///////////// RENDER STOP-------2";
1100 if (m_mltProducer) {
1101 if (m_isZoneMode) resetZoneMode();
1102 m_mltProducer->set_speed(0.0);
1103 m_mltProducer->seek((int) startTime.frames(m_fps));
1105 m_mltConsumer->purge();
1108 void Render::pause()
1110 if (!m_mltProducer || !m_mltConsumer)
1112 if (m_mltProducer->get_speed() == 0.0) return;
1113 if (m_isZoneMode) resetZoneMode();
1115 m_mltConsumer->set("refresh", 0);
1116 m_mltProducer->set_speed(0.0);
1117 emit rendererPosition(m_framePosition);
1118 m_mltProducer->seek(m_framePosition);
1119 m_mltConsumer->purge();
1122 void Render::switchPlay()
1124 if (!m_mltProducer || !m_mltConsumer)
1126 if (m_isZoneMode) resetZoneMode();
1127 if (m_mltProducer->get_speed() == 0.0) {
1128 m_isBlocked = false;
1129 m_mltProducer->set_speed(1.0);
1130 m_mltConsumer->set("refresh", 1);
1133 m_mltConsumer->set("refresh", 0);
1134 m_mltProducer->set_speed(0.0);
1135 emit rendererPosition(m_framePosition);
1136 m_mltProducer->seek(m_framePosition);
1137 m_mltConsumer->purge();
1138 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1139 //m_mltConsumer->set("refresh", 0);
1140 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1141 m_mltProducer->set_speed(0);
1142 m_mltProducer->seek( position );
1143 //m_mltProducer->seek((int) m_framePosition);
1144 m_isBlocked = false;*/
1146 /*if (speed == 0.0) {
1147 m_mltProducer->seek((int) m_framePosition + 1);
1148 m_mltConsumer->purge();
1153 void Render::play(double speed)
1157 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1158 m_isBlocked = false;
1159 m_mltProducer->set_speed(speed);
1160 /*if (speed == 0.0) {
1161 m_mltProducer->seek((int) m_framePosition + 1);
1162 m_mltConsumer->purge();
1167 void Render::play(const GenTime & startTime)
1169 if (!m_mltProducer || !m_mltConsumer)
1171 m_isBlocked = false;
1172 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1173 m_mltProducer->set_speed(1.0);
1174 m_mltConsumer->set("refresh", 1);
1177 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1179 if (!m_mltProducer || !m_mltConsumer)
1181 //m_mltProducer->set("eof", "loop");
1182 m_isLoopMode = true;
1183 m_loopStart = startTime;
1184 playZone(startTime, stopTime);
1187 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1189 if (!m_mltProducer || !m_mltConsumer)
1191 m_isBlocked = false;
1192 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1193 m_mltProducer->set("out", stopTime.frames(m_fps));
1194 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1195 m_mltProducer->set_speed(1.0);
1196 m_mltConsumer->set("refresh", 1);
1197 m_isZoneMode = true;
1200 void Render::resetZoneMode()
1202 if (!m_isZoneMode && !m_isLoopMode) return;
1203 m_mltProducer->set("out", m_originalOut);
1204 //m_mltProducer->set("eof", "pause");
1205 m_isZoneMode = false;
1206 m_isLoopMode = false;
1209 void Render::seekToFrame(int pos)
1211 //kDebug()<<" ********* RENDER SEEK TO POS";
1214 m_isBlocked = false;
1216 m_mltProducer->seek(pos);
1220 void Render::askForRefresh()
1222 // Use a Timer so that we don't refresh too much
1223 m_refreshTimer->start(200);
1226 void Render::doRefresh()
1228 // Use a Timer so that we don't refresh too much
1229 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1232 void Render::refresh()
1234 if (!m_mltProducer || m_isBlocked)
1236 m_refreshTimer->stop();
1237 if (m_mltConsumer) {
1238 m_mltConsumer->set("refresh", 1);
1242 double Render::playSpeed()
1244 if (m_mltProducer) return m_mltProducer->get_speed();
1248 GenTime Render::seekPosition() const
1250 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1251 else return GenTime();
1255 const QString & Render::rendererName() const
1261 void Render::emitFrameNumber(double position)
1263 m_framePosition = position;
1264 emit rendererPosition((int) position);
1265 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1268 void Render::emitConsumerStopped()
1270 // This is used to know when the playing stopped
1271 if (m_mltProducer) {
1272 double pos = m_mltProducer->position();
1273 if (m_isLoopMode) play(m_loopStart);
1274 else if (m_isZoneMode) resetZoneMode();
1275 emit rendererStopped((int) pos);
1276 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1277 //new QCustomEvent(10002));
1283 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1285 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1289 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1291 if (!m_mltProducer) {
1292 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1296 //int height = 1080;//KdenliveSettings::defaultheight();
1297 //int width = 1940; //KdenliveSettings::displaywidth();
1299 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1301 QPixmap pix(width, height);
1302 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1303 m_convert.set("forced", mlt_image_rgb24a);
1304 m_mltProducer->attach(m_convert);
1305 Mlt::Frame * frame = m_mltProducer->get_frame();
1306 m_mltProducer->detach(m_convert);
1308 pix = frameThumbnail(frame, width, height);
1311 pix.save(url.path(), "PNG");
1312 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1315 /** MLT PLAYLIST DIRECT MANIPULATON **/
1318 void Render::mltCheckLength()
1320 //kDebug()<<"checking track length: "<<track<<"..........";
1322 Mlt::Service service(m_mltProducer->get_service());
1323 Mlt::Tractor tractor(service);
1325 int trackNb = tractor.count();
1329 Mlt::Producer trackProducer(tractor.track(0));
1330 duration = trackProducer.get_playtime() - 1;
1331 m_mltProducer->set("out", duration);
1332 emit durationChanged(duration);
1335 while (trackNb > 1) {
1336 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1337 trackDuration = trackProducer.get_playtime() - 1;
1339 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1340 if (trackDuration > duration) duration = trackDuration;
1344 Mlt::Producer blackTrackProducer(tractor.track(0));
1346 if (blackTrackProducer.get_playtime() - 1 != duration) {
1347 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1348 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1349 if (duration > m_blackClip->get_length()) {
1350 m_blackClip->set("length", duration);
1351 if (blackclip) blackclip->set("length", duration);
1353 if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
1354 blackTrackPlaylist.clear();
1355 blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
1356 } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1358 m_mltProducer->set("out", duration);
1359 emit durationChanged(duration);
1363 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1365 if (m_mltProducer == NULL) {
1366 kDebug() << "PLAYLIST NOT INITIALISED //////";
1369 Mlt::Producer parentProd(m_mltProducer->parent());
1370 if (parentProd.get_producer() == NULL) {
1371 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1375 Mlt::Service service(parentProd.get_service());
1376 Mlt::Tractor tractor(service);
1377 mlt_service_lock(service.get_service());
1378 Mlt::Producer trackProducer(tractor.track(info.track));
1379 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1380 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1382 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1383 // We want a slowmotion producer
1384 double speed = element.attribute("speed", "1.0").toDouble();
1385 QString url = QString::fromUtf8(prod->get("resource"));
1386 url.append('?' + QString::number(speed));
1387 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1388 if (!slowprod || slowprod->get_producer() == NULL) {
1389 char *tmp = decodedString(url);
1390 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1392 QString id = prod->get("id");
1393 if (id.contains('_')) id = id.section('_', 0, 0);
1394 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1395 tmp = decodedString(producerid);
1396 slowprod->set("id", tmp);
1398 m_slowmotionProducers.insert(url, slowprod);
1403 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1404 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1406 /*if (QString(prod->get("transparency")).toInt() == 1)
1407 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1409 mlt_service_unlock(service.get_service());
1411 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1412 //tractor.multitrack()->refresh();
1413 //tractor.refresh();
1417 void Render::mltCutClip(int track, GenTime position)
1422 Mlt::Service service(m_mltProducer->parent().get_service());
1423 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1425 Mlt::Tractor tractor(service);
1426 Mlt::Producer trackProducer(tractor.track(track));
1427 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1430 /* // Display playlist info
1431 kDebug()<<"//////////// BEFORE";
1432 for (int i = 0; i < trackPlaylist.count(); i++) {
1433 int blankStart = trackPlaylist.clip_start(i);
1434 int blankDuration = trackPlaylist.clip_length(i) - 1;
1436 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1437 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1440 int cutPos = (int) position.frames(m_fps);
1442 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1443 if (trackPlaylist.is_blank(clipIndex)) {
1444 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1445 m_isBlocked = false;
1448 mlt_service_lock(service.get_service());
1449 int clipStart = trackPlaylist.clip_start(clipIndex);
1450 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1451 mlt_service_unlock(service.get_service());
1453 // duplicate effects
1454 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1455 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1457 if (original == NULL || clip == NULL) {
1458 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1460 Mlt::Service clipService(original->get_service());
1461 Mlt::Service dupService(clip->get_service());
1463 Mlt::Filter *filter = clipService.filter(ct);
1465 // Only duplicate Kdenlive filters, and skip the fade in effects
1466 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1467 // looks like there is no easy way to duplicate a filter,
1468 // so we will create a new one and duplicate its properties
1469 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1470 if (dup && dup->is_valid()) {
1471 Mlt::Properties entries(filter->get_properties());
1472 for (int i = 0;i < entries.count();i++) {
1473 dup->set(entries.get_name(i), entries.get(i));
1475 dupService.attach(*dup);
1479 filter = clipService.filter(ct);
1482 /* // Display playlist info
1483 kDebug()<<"//////////// AFTER";
1484 for (int i = 0; i < trackPlaylist.count(); i++) {
1485 int blankStart = trackPlaylist.clip_start(i);
1486 int blankDuration = trackPlaylist.clip_length(i) - 1;
1488 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1489 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1492 m_isBlocked = false;
1495 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1498 mltRemoveClip(info.track, info.startPos);
1499 mltInsertClip(info, element, prod);
1503 bool Render::mltRemoveClip(int track, GenTime position)
1505 Mlt::Service service(m_mltProducer->parent().get_service());
1506 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1508 Mlt::Tractor tractor(service);
1509 Mlt::Producer trackProducer(tractor.track(track));
1510 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1511 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1513 /* // Display playlist info
1514 kDebug()<<"//// BEFORE";
1515 for (int i = 0; i < trackPlaylist.count(); i++) {
1516 int blankStart = trackPlaylist.clip_start(i);
1517 int blankDuration = trackPlaylist.clip_length(i) - 1;
1519 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1520 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1523 if (trackPlaylist.is_blank(clipIndex)) {
1524 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1528 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1529 trackPlaylist.replace_with_blank(clipIndex);
1530 trackPlaylist.consolidate_blanks(0);
1531 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1532 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1534 /* // Display playlist info
1535 kDebug()<<"//// AFTER";
1536 for (int i = 0; i < trackPlaylist.count(); i++) {
1537 int blankStart = trackPlaylist.clip_start(i);
1538 int blankDuration = trackPlaylist.clip_length(i) - 1;
1540 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1541 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1544 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1545 m_isBlocked = false;
1549 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
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);
1563 int insertPos = pos.frames(m_fps);
1565 Mlt::Producer trackProducer(tractor.track(track));
1566 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1567 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1568 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1569 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1570 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1573 int Render::mltTrackDuration(int track)
1575 if (!m_mltProducer) {
1576 kDebug() << "PLAYLIST NOT INITIALISED //////";
1579 Mlt::Producer parentProd(m_mltProducer->parent());
1580 if (parentProd.get_producer() == NULL) {
1581 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1585 Mlt::Service service(parentProd.get_service());
1586 Mlt::Tractor tractor(service);
1588 Mlt::Producer trackProducer(tractor.track(track));
1589 return trackProducer.get_playtime() - 1;
1592 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1594 if (!m_mltProducer) {
1595 kDebug() << "PLAYLIST NOT INITIALISED //////";
1598 Mlt::Producer parentProd(m_mltProducer->parent());
1599 if (parentProd.get_producer() == NULL) {
1600 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1603 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1604 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1606 Mlt::Service service(parentProd.get_service());
1607 Mlt::Tractor tractor(service);
1608 mlt_service_lock(service.get_service());
1609 int diff = duration.frames(m_fps);
1610 int offset = timeOffset.frames(m_fps);
1614 // insert space in one track only
1615 Mlt::Producer trackProducer(tractor.track(track));
1616 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1617 insertPos = trackClipStartList.value(track);
1618 if (insertPos != -1) {
1619 insertPos += offset;
1620 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1621 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1623 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1624 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1625 int position = trackPlaylist.clip_start(clipIndex);
1626 trackPlaylist.remove_region(position, - diff - 1);
1628 trackPlaylist.consolidate_blanks(0);
1630 // now move transitions
1631 mlt_service serv = m_mltProducer->parent().get_service();
1632 mlt_service nextservice = mlt_service_get_producer(serv);
1633 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1634 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1635 QString resource = mlt_properties_get(properties, "mlt_service");
1637 while (mlt_type == "transition") {
1638 mlt_transition tr = (mlt_transition) nextservice;
1639 int currentTrack = mlt_transition_get_b_track(tr);
1640 int currentIn = (int) mlt_transition_get_in(tr);
1641 int currentOut = (int) mlt_transition_get_out(tr);
1642 insertPos = trackTransitionStartList.value(track);
1643 if (insertPos != -1) {
1644 insertPos += offset;
1645 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1646 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1649 nextservice = mlt_service_producer(nextservice);
1650 if (nextservice == NULL) break;
1651 properties = MLT_SERVICE_PROPERTIES(nextservice);
1652 mlt_type = mlt_properties_get(properties, "mlt_type");
1653 resource = mlt_properties_get(properties, "mlt_service");
1656 int trackNb = tractor.count();
1657 while (trackNb > 1) {
1658 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1659 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1662 //int clipNb = trackPlaylist.count();
1663 insertPos = trackClipStartList.value(trackNb - 1);
1664 if (insertPos != -1) {
1665 insertPos += offset;
1667 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1668 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1669 for (int i = 0; i < clipNb; i++) {
1670 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1671 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1672 kDebug()<<"-------------";
1674 kDebug()<<"END-------------";*/
1677 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1678 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1680 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1681 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1682 int position = trackPlaylist.clip_start(clipIndex);
1683 trackPlaylist.remove_region(position, - diff - 1);
1685 trackPlaylist.consolidate_blanks(0);
1689 // now move transitions
1690 mlt_service serv = m_mltProducer->parent().get_service();
1691 mlt_service nextservice = mlt_service_get_producer(serv);
1692 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1693 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1694 QString resource = mlt_properties_get(properties, "mlt_service");
1696 while (mlt_type == "transition") {
1697 mlt_transition tr = (mlt_transition) nextservice;
1698 int currentIn = (int) mlt_transition_get_in(tr);
1699 int currentOut = (int) mlt_transition_get_out(tr);
1700 int currentTrack = mlt_transition_get_b_track(tr);
1701 insertPos = trackTransitionStartList.value(currentTrack);
1702 if (insertPos != -1) {
1703 insertPos += offset;
1704 if (currentOut > insertPos && resource != "mix") {
1705 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1708 nextservice = mlt_service_producer(nextservice);
1709 if (nextservice == NULL) break;
1710 properties = MLT_SERVICE_PROPERTIES(nextservice);
1711 mlt_type = mlt_properties_get(properties, "mlt_type");
1712 resource = mlt_properties_get(properties, "mlt_service");
1715 mlt_service_unlock(service.get_service());
1717 m_mltConsumer->set("refresh", 1);
1720 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1724 Mlt::Service service(m_mltProducer->parent().get_service());
1725 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1726 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1727 Mlt::Tractor tractor(service);
1728 Mlt::Producer trackProducer(tractor.track(info.track));
1729 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1730 int startPos = info.startPos.frames(m_fps);
1731 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1732 int clipLength = trackPlaylist.clip_length(clipIndex);
1734 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1735 if (!clip.is_valid() || clip.is_blank()) {
1739 Mlt::Producer clipparent = clip.parent();
1740 if (!clipparent.is_valid() || clipparent.is_blank()) {
1744 QString serv = clipparent.get("mlt_service");
1745 QString id = clipparent.get("id");
1746 //kDebug() << "CLIP SERVICE: " << serv;
1747 if (serv == "avformat" && speed != 1.0) {
1748 mlt_service_lock(service.get_service());
1749 QString url = QString::fromUtf8(clipparent.get("resource"));
1750 url.append('?' + QString::number(speed));
1751 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1752 if (!slowprod || slowprod->get_producer() == NULL) {
1753 char *tmp = decodedString(url);
1754 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1756 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1757 tmp = decodedString(producerid);
1758 slowprod->set("id", tmp);
1760 m_slowmotionProducers.insert(url, slowprod);
1762 trackPlaylist.replace_with_blank(clipIndex);
1763 trackPlaylist.consolidate_blanks(0);
1764 // Check that the blank space is long enough for our new duration
1765 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1766 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1768 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1769 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1770 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1771 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1772 trackPlaylist.insert_at(startPos, *cut, 1);
1773 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1774 newLength = trackPlaylist.clip_length(clipIndex);
1775 mlt_service_unlock(service.get_service());
1776 } else if (speed == 1.0) {
1777 mlt_service_lock(service.get_service());
1779 trackPlaylist.replace_with_blank(clipIndex);
1780 trackPlaylist.consolidate_blanks(0);
1782 // Check that the blank space is long enough for our new duration
1783 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1784 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1787 GenTime oldDuration = GenTime(clipLength, m_fps);
1788 GenTime newDuration = oldDuration * oldspeed;
1789 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1790 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1791 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1792 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1793 trackPlaylist.insert_at(startPos, *cut, 1);
1794 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1795 newLength = trackPlaylist.clip_length(clipIndex);
1796 mlt_service_unlock(service.get_service());
1798 } else if (serv == "framebuffer") {
1799 mlt_service_lock(service.get_service());
1800 QString url = QString::fromUtf8(clipparent.get("resource"));
1801 url = url.section('?', 0, 0);
1802 url.append('?' + QString::number(speed));
1803 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1804 if (!slowprod || slowprod->get_producer() == NULL) {
1805 char *tmp = decodedString(url);
1806 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1808 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1809 tmp = decodedString(producerid);
1810 slowprod->set("id", tmp);
1812 m_slowmotionProducers.insert(url, slowprod);
1814 trackPlaylist.replace_with_blank(clipIndex);
1815 trackPlaylist.consolidate_blanks(0);
1817 GenTime oldDuration = GenTime(clipLength, m_fps);
1818 GenTime newDuration = oldDuration * oldspeed / speed;
1820 // Check that the blank space is long enough for our new duration
1821 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1822 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1825 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1826 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1827 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1828 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1830 trackPlaylist.insert_at(startPos, *cut, 1);
1831 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1832 newLength = trackPlaylist.clip_length(clipIndex);
1834 mlt_service_unlock(service.get_service());
1836 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1837 m_isBlocked = false;
1841 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1843 kDebug() << "// TRYing to remove effect at: " << index;
1844 Mlt::Service service(m_mltProducer->parent().get_service());
1845 bool success = false;
1846 Mlt::Tractor tractor(service);
1847 Mlt::Producer trackProducer(tractor.track(track));
1848 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1849 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1850 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1852 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1855 Mlt::Service clipService(clip->get_service());
1856 // if (tag.startsWith("ladspa")) tag = "ladspa";
1859 Mlt::Filter *filter = clipService.filter(ct);
1861 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1862 if (clipService.detach(*filter) == 0) success = true;
1863 kDebug() << " / / / DLEETED EFFECT: " << ct;
1864 } else if (updateIndex) {
1865 // Adjust the other effects index
1866 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1869 filter = clipService.filter(ct);
1871 m_isBlocked = false;
1872 if (doRefresh) refresh();
1877 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1880 Mlt::Service service(m_mltProducer->parent().get_service());
1882 Mlt::Tractor tractor(service);
1883 Mlt::Producer trackProducer(tractor.track(track));
1884 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1886 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1890 Mlt::Service clipService(clip->get_service());
1893 // temporarily remove all effects after insert point
1894 QList <Mlt::Filter *> filtersList;
1895 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1897 Mlt::Filter *filter = clipService.filter(ct);
1899 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1900 filtersList.append(filter);
1901 clipService.detach(*filter);
1903 filter = clipService.filter(ct);
1907 QString tag = params.paramValue("tag");
1908 kDebug() << " / / INSERTING EFFECT: " << tag;
1909 if (tag.startsWith("ladspa")) tag = "ladspa";
1910 char *filterTag = decodedString(tag);
1911 char *filterId = decodedString(params.paramValue("id"));
1912 QHash<QString, QString>::Iterator it;
1913 QString kfr = params.paramValue("keyframes");
1915 if (!kfr.isEmpty()) {
1916 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1917 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1918 char *starttag = decodedString(params.paramValue("starttag", "start"));
1919 char *endtag = decodedString(params.paramValue("endtag", "end"));
1920 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1921 int duration = clip->get_playtime();
1922 //double max = params.paramValue("max").toDouble();
1923 double min = params.paramValue("min").toDouble();
1924 double factor = params.paramValue("factor", "1").toDouble();
1925 params.removeParam("starttag");
1926 params.removeParam("endtag");
1927 params.removeParam("keyframes");
1928 params.removeParam("min");
1929 params.removeParam("max");
1930 params.removeParam("factor");
1932 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1933 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1934 if (filter && filter->is_valid()) {
1935 filter->set("kdenlive_id", filterId);
1936 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1937 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1938 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1939 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1940 if (x2 == -1) x2 = duration;
1942 for (int j = 0; j < params.count(); j++) {
1943 char *name = decodedString(params.at(j).name());
1944 char *value = decodedString(params.at(j).value());
1945 filter->set(name, value);
1950 filter->set("in", x1);
1951 filter->set("out", x2);
1952 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1953 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1954 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1955 clipService.attach(*filter);
1962 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1963 if (filter && filter->is_valid())
1964 filter->set("kdenlive_id", filterId);
1966 kDebug() << "filter is NULL";
1967 m_isBlocked = false;
1971 params.removeParam("kdenlive_id");
1973 for (int j = 0; j < params.count(); j++) {
1974 char *name = decodedString(params.at(j).name());
1975 char *value = decodedString(params.at(j).value());
1976 filter->set(name, value);
1982 QString effectArgs = params.paramValue("id").section('_', 1);
1984 params.removeParam("id");
1985 params.removeParam("kdenlive_ix");
1986 params.removeParam("tag");
1987 params.removeParam("disabled");
1989 for (int j = 0; j < params.count(); j++) {
1990 effectArgs.append(' ' + params.at(j).value());
1992 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1993 char *value = decodedString(effectArgs.simplified());
1994 filter->set("effect", value);
1999 // attach filter to the clip
2000 clipService.attach(*filter);
2005 // re-add following filters
2006 for (int i = 0; i < filtersList.count(); i++) {
2007 clipService.attach(*(filtersList.at(i)));
2010 m_isBlocked = false;
2011 if (doRefresh) refresh();
2015 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2017 QString index = params.paramValue("kdenlive_ix");
2018 QString tag = params.paramValue("tag");
2020 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2021 // This is a keyframe effect, to edit it, we remove it and re-add it.
2022 mltRemoveEffect(track, position, index, true);
2023 bool success = mltAddEffect(track, position, params);
2028 Mlt::Service service(m_mltProducer->parent().get_service());
2030 Mlt::Tractor tractor(service);
2031 Mlt::Producer trackProducer(tractor.track(track));
2032 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2033 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2034 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2036 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2039 Mlt::Service clipService(clip->get_service());
2042 Mlt::Filter *filter = clipService.filter(ct);
2044 if (filter->get("kdenlive_ix") == index) {
2048 filter = clipService.filter(ct);
2052 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2053 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2055 filter = clipService.filter(ct);
2056 QList <Mlt::Filter *> filtersList;
2058 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2059 filtersList.append(filter);
2060 clipService.detach(*filter);
2062 filter = clipService.filter(ct);
2064 bool success = mltAddEffect(track, position, params);
2066 for (int i = 0; i < filtersList.count(); i++) {
2067 clipService.attach(*(filtersList.at(i)));
2070 m_isBlocked = false;
2074 for (int j = 0; j < params.count(); j++) {
2075 char *name = decodedString(params.at(j).name());
2076 char *value = decodedString(params.at(j).value());
2077 filter->set(name, value);
2082 m_isBlocked = false;
2087 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2090 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2091 Mlt::Service service(m_mltProducer->parent().get_service());
2093 Mlt::Tractor tractor(service);
2094 Mlt::Producer trackProducer(tractor.track(track));
2095 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2096 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2097 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2099 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2102 Mlt::Service clipService(clip->get_service());
2105 QList <Mlt::Filter *> filtersList;
2106 Mlt::Filter *filter = clipService.filter(ct);
2108 if (newPos > oldPos) {
2110 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2111 filter->set("kdenlive_ix", newPos);
2112 filtersList.append(filter);
2113 clipService.detach(*filter);
2114 filter = clipService.filter(ct);
2115 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2116 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2118 filter = clipService.filter(ct);
2122 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2123 filtersList.append(filter);
2124 clipService.detach(*filter);
2126 filter = clipService.filter(ct);
2130 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2131 filter->set("kdenlive_ix", newPos);
2132 filtersList.append(filter);
2133 clipService.detach(*filter);
2135 filter = clipService.filter(ct);
2139 filter = clipService.filter(ct);
2141 int pos = QString(filter->get("kdenlive_ix")).toInt();
2142 if (pos >= newPos) {
2143 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2144 filtersList.append(filter);
2145 clipService.detach(*filter);
2147 filter = clipService.filter(ct);
2151 for (int i = 0; i < filtersList.count(); i++) {
2152 clipService.attach(*(filtersList.at(i)));
2155 m_isBlocked = false;
2159 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2163 Mlt::Service service(m_mltProducer->parent().get_service());
2165 Mlt::Tractor tractor(service);
2166 Mlt::Producer trackProducer(tractor.track(info.track));
2167 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2169 /* // Display playlist info
2170 kDebug()<<"//////////// BEFORE RESIZE";
2171 for (int i = 0; i < trackPlaylist.count(); i++) {
2172 int blankStart = trackPlaylist.clip_start(i);
2173 int blankDuration = trackPlaylist.clip_length(i) - 1;
2175 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2176 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2179 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2180 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2181 m_isBlocked = false;
2184 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2185 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2186 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2187 int previousStart = clip->get_in();
2188 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2189 int diff = newDuration - trackPlaylist.clip_length(clipIndex) - 1;
2190 if (newDuration > clip->get_length()) {
2191 clip->parent().set("length", newDuration + 1);
2192 clip->set("length", newDuration + 1);
2194 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2195 trackPlaylist.consolidate_blanks(0);
2196 // skip to next clip
2198 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2200 // clip was made longer, trim next blank if there is one.
2201 if (clipIndex < trackPlaylist.count()) {
2202 // If this is not the last clip in playlist
2203 if (trackPlaylist.is_blank(clipIndex)) {
2204 int blankStart = trackPlaylist.clip_start(clipIndex);
2205 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2206 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2207 if (diff - blankDuration == 1) {
2208 trackPlaylist.remove(clipIndex);
2209 } else trackPlaylist.remove_region(blankStart, diff - 1);
2211 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2214 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2216 trackPlaylist.consolidate_blanks(0);
2219 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2220 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2221 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2222 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2223 ItemInfo transpinfo;
2224 transpinfo.startPos = info.startPos;
2225 transpinfo.endPos = info.startPos + clipDuration;
2226 transpinfo.track = info.track;
2227 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2229 m_isBlocked = false;
2230 m_mltConsumer->set("refresh", 1);
2234 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2236 Mlt::Service service(m_mltProducer->parent().get_service());
2237 Mlt::Tractor tractor(service);
2238 Mlt::Producer trackProducer(tractor.track(track));
2241 if (blind) trackProducer.set("hide", 3);
2242 else trackProducer.set("hide", 2);
2244 trackProducer.set("hide", 1);
2246 trackProducer.set("hide", 0);
2248 tractor.multitrack()->refresh();
2254 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2256 Mlt::Service service(m_mltProducer->parent().get_service());
2257 int frameOffset = (int) diff.frames(m_fps);
2258 Mlt::Tractor tractor(service);
2259 Mlt::Producer trackProducer(tractor.track(info.track));
2260 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2261 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2262 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2265 mlt_service_lock(service.get_service());
2266 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2267 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2269 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2270 mlt_service_unlock(service.get_service());
2273 int previousStart = clip->get_in();
2274 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2276 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2277 m_isBlocked = false;
2278 mlt_service_unlock(service.get_service());
2279 m_mltConsumer->set("refresh", 1);
2283 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2285 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2286 Mlt::Service service(m_mltProducer->parent().get_service());
2287 int moveFrame = (int) diff.frames(m_fps);
2288 Mlt::Tractor tractor(service);
2289 Mlt::Producer trackProducer(tractor.track(info.track));
2290 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2291 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2292 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2295 mlt_service_lock(service.get_service());
2296 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2297 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2299 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2300 mlt_service_unlock(service.get_service());
2303 int previousStart = clip->get_in();
2304 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2306 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2307 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2308 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2310 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2311 int blankIndex = clipIndex - 1;
2312 int blankLength = trackPlaylist.clip_length(blankIndex);
2313 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2314 if (! trackPlaylist.is_blank(blankIndex)) {
2315 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2317 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2318 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2320 trackPlaylist.consolidate_blanks(0);
2321 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2322 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2323 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2324 ItemInfo transpinfo;
2325 transpinfo.startPos = info.startPos + diff;
2326 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2327 transpinfo.track = info.track;
2328 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2330 m_isBlocked = false;
2331 //m_mltConsumer->set("refresh", 1);
2332 mlt_service_unlock(service.get_service());
2333 m_mltConsumer->set("refresh", 1);
2337 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2339 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2343 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2345 if (prod == NULL || !prod->is_valid()) {
2346 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2349 kDebug() << "NEW PROD ID: " << prod->get("id");
2350 m_mltConsumer->set("refresh", 0);
2351 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2352 mlt_service_lock(m_mltConsumer->get_service());
2353 Mlt::Service service(m_mltProducer->parent().get_service());
2354 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2356 Mlt::Tractor tractor(service);
2357 Mlt::Producer trackProducer(tractor.track(track));
2358 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2359 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2360 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2361 if (clipProducer.is_blank()) {
2362 kDebug() << "// ERROR UPDATING CLIP PROD";
2363 mlt_service_unlock(m_mltConsumer->get_service());
2364 m_isBlocked = false;
2367 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2369 // move all effects to the correct producer
2370 Mlt::Service clipService(clipProducer.get_service());
2371 Mlt::Service newClipService(clip->get_service());
2374 Mlt::Filter *filter = clipService.filter(ct);
2376 if (filter->get("kdenlive_ix") != 0) {
2377 clipService.detach(*filter);
2378 newClipService.attach(*filter);
2380 filter = clipService.filter(ct);
2383 trackPlaylist.insert_at(pos, clip, 1);
2384 mlt_service_unlock(m_mltConsumer->get_service());
2385 m_isBlocked = false;
2388 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2392 m_mltConsumer->set("refresh", 0);
2393 mlt_service_lock(m_mltConsumer->get_service());
2394 Mlt::Service service(m_mltProducer->parent().get_service());
2395 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2397 Mlt::Tractor tractor(service);
2398 Mlt::Producer trackProducer(tractor.track(startTrack));
2399 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2400 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2401 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2402 bool checkLength = false;
2403 if (endTrack == startTrack) {
2404 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2405 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2406 // error, destination is not empty
2407 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2408 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2409 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2410 mlt_service_unlock(m_mltConsumer->get_service());
2411 m_isBlocked = false;
2414 trackPlaylist.consolidate_blanks(0);
2415 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2416 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2417 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2419 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2421 //mlt_service_unlock(service.get_service());
2423 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2424 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2425 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2426 // error, destination is not empty
2427 mlt_service_unlock(m_mltConsumer->get_service());
2428 m_isBlocked = false;
2431 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2432 if (clipProducer.is_blank()) {
2433 // error, destination is not empty
2434 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2435 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2436 mlt_service_unlock(m_mltConsumer->get_service());
2437 m_isBlocked = false;
2440 trackPlaylist.consolidate_blanks(0);
2441 destTrackPlaylist.consolidate_blanks(1);
2442 Mlt::Producer *clip;
2443 // check if we are moving a slowmotion producer
2444 QString serv = clipProducer.parent().get("mlt_service");
2445 QString currentid = clipProducer.parent().get("id");
2446 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2447 clip = &clipProducer;
2450 // Special case: prod is null when using placeholder clips.
2451 // in that case, use the producer existing in playlist. Note that
2452 // it will bypass the one producer per track logic and might cause
2453 // Sound cracks if clip is moved so that it overlaps another copy of itself
2454 clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
2455 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2458 // move all effects to the correct producer
2459 Mlt::Service clipService(clipProducer.get_service());
2460 Mlt::Service newClipService(clip->get_service());
2463 Mlt::Filter *filter = clipService.filter(ct);
2465 if (filter->get("kdenlive_ix") != 0) {
2466 clipService.detach(*filter);
2467 newClipService.attach(*filter);
2469 filter = clipService.filter(ct);
2472 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2473 destTrackPlaylist.consolidate_blanks(0);
2474 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2475 kDebug() << "//////// moving clip transparency";
2476 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2478 if (clipIndex > trackPlaylist.count()) checkLength = true;
2479 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2483 if (checkLength) mltCheckLength();
2484 mlt_service_unlock(m_mltConsumer->get_service());
2485 m_isBlocked = false;
2486 m_mltConsumer->set("refresh", 1);
2490 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2492 int new_in = (int)newIn.frames(m_fps);
2493 int new_out = (int)newOut.frames(m_fps) - 1;
2494 if (new_in >= new_out) return false;
2496 Mlt::Service service(m_mltProducer->parent().get_service());
2497 Mlt::Tractor tractor(service);
2499 mlt_service_lock(service.get_service());
2500 m_mltConsumer->set("refresh", 0);
2503 mlt_service serv = m_mltProducer->parent().get_service();
2504 mlt_service nextservice = mlt_service_get_producer(serv);
2505 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2506 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2507 QString resource = mlt_properties_get(properties, "mlt_service");
2508 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2510 while (mlt_type == "transition") {
2511 mlt_transition tr = (mlt_transition) nextservice;
2512 int currentTrack = mlt_transition_get_b_track(tr);
2513 int currentIn = (int) mlt_transition_get_in(tr);
2514 int currentOut = (int) mlt_transition_get_out(tr);
2516 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2517 mlt_transition_set_in_and_out(tr, new_in, new_out);
2518 if (newTrack - startTrack != 0) {
2519 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2521 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2522 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2523 mlt_properties_set_int(properties, "b_track", newTrack);
2524 //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);
2528 nextservice = mlt_service_producer(nextservice);
2529 if (nextservice == NULL) break;
2530 properties = MLT_SERVICE_PROPERTIES(nextservice);
2531 mlt_type = mlt_properties_get(properties, "mlt_type");
2532 resource = mlt_properties_get(properties, "mlt_service");
2534 m_isBlocked = false;
2535 mlt_service_unlock(service.get_service());
2536 m_mltConsumer->set("refresh", 1);
2540 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2542 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2543 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2545 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2546 mltAddTransition(tag, a_track, b_track, in, out, xml);
2548 //mltSavePlaylist();
2551 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2554 Mlt::Service service(m_mltProducer->parent().get_service());
2555 Mlt::Tractor tractor(service);
2557 //m_mltConsumer->set("refresh", 0);
2558 mlt_service serv = m_mltProducer->parent().get_service();
2560 mlt_service nextservice = mlt_service_get_producer(serv);
2561 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2562 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2563 QString resource = mlt_properties_get(properties, "mlt_service");
2564 int in_pos = (int) in.frames(m_fps);
2565 int out_pos = (int) out.frames(m_fps) - 1;
2567 while (mlt_type == "transition") {
2568 mlt_transition tr = (mlt_transition) nextservice;
2569 int currentTrack = mlt_transition_get_b_track(tr);
2570 int currentBTrack = mlt_transition_get_a_track(tr);
2571 int currentIn = (int) mlt_transition_get_in(tr);
2572 int currentOut = (int) mlt_transition_get_out(tr);
2574 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2576 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2577 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2578 QMap<QString, QString>::Iterator it;
2580 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2581 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2582 if (currentBTrack != a_track) {
2583 mlt_properties_set_int(properties, "a_track", a_track);
2585 for (it = map.begin(); it != map.end(); ++it) {
2587 char *name = decodedString(key);
2588 char *value = decodedString(it.value());
2589 mlt_properties_set(transproperties, name, value);
2590 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2591 //filter->set("kdenlive_id", id);
2597 nextservice = mlt_service_producer(nextservice);
2598 if (nextservice == NULL) break;
2599 properties = MLT_SERVICE_PROPERTIES(nextservice);
2600 mlt_type = mlt_properties_get(properties, "mlt_type");
2601 resource = mlt_properties_get(properties, "mlt_service");
2603 m_isBlocked = false;
2604 m_mltConsumer->set("refresh", 1);
2607 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2609 Mlt::Service service(m_mltProducer->parent().get_service());
2610 Mlt::Tractor tractor(service);
2611 Mlt::Field *field = tractor.field();
2613 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2614 mlt_service serv = m_mltProducer->parent().get_service();
2616 mlt_service nextservice = mlt_service_get_producer(serv);
2617 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2618 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2619 QString resource = mlt_properties_get(properties, "mlt_service");
2621 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2623 while (mlt_type == "transition") {
2624 mlt_transition tr = (mlt_transition) nextservice;
2625 int currentTrack = mlt_transition_get_b_track(tr);
2626 int currentIn = (int) mlt_transition_get_in(tr);
2627 int currentOut = (int) mlt_transition_get_out(tr);
2628 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2630 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2631 mlt_field_disconnect_service(field->get_field(), nextservice);
2634 nextservice = mlt_service_producer(nextservice);
2635 if (nextservice == NULL) break;
2636 properties = MLT_SERVICE_PROPERTIES(nextservice);
2637 mlt_type = mlt_properties_get(properties, "mlt_type");
2638 resource = mlt_properties_get(properties, "mlt_service");
2640 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2643 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2645 QDomNodeList attribs = xml.elementsByTagName("parameter");
2646 QMap<QString, QString> map;
2647 for (int i = 0;i < attribs.count();i++) {
2648 QDomElement e = attribs.item(i).toElement();
2649 QString name = e.attribute("name");
2650 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2651 map[name] = e.attribute("default");
2652 if (!e.attribute("value").isEmpty()) {
2653 map[name] = e.attribute("value");
2655 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2656 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2657 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2660 if (e.attribute("namedesc").contains(';')) {
2661 QString format = e.attribute("format");
2662 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2663 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2665 QTextStream txtNeu(&neu);
2666 if (values.size() > 0)
2667 txtNeu << (int)values[0].toDouble();
2669 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2670 txtNeu << separators[i];
2671 txtNeu << (int)(values[i+1].toDouble());
2673 if (i < separators.size())
2674 txtNeu << separators[i];
2675 map[e.attribute("name")] = neu;
2682 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2684 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2685 Mlt::Service service(m_mltProducer->parent().get_service());
2686 Mlt::Tractor tractor(service);
2687 Mlt::Field *field = tractor.field();
2689 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2690 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2691 transition->set("transparency", id);
2692 transition->set("fill", 1);
2693 transition->set("internal_added", 237);
2694 field->plant_transition(*transition, transitiontrack, info.track);
2698 void Render::mltDeleteTransparency(int pos, int track, int id)
2700 Mlt::Service service(m_mltProducer->parent().get_service());
2701 Mlt::Tractor tractor(service);
2702 Mlt::Field *field = tractor.field();
2704 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2705 mlt_service serv = m_mltProducer->parent().get_service();
2707 mlt_service nextservice = mlt_service_get_producer(serv);
2708 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2709 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2710 QString resource = mlt_properties_get(properties, "mlt_service");
2712 while (mlt_type == "transition") {
2713 mlt_transition tr = (mlt_transition) nextservice;
2714 int currentTrack = mlt_transition_get_b_track(tr);
2715 int currentIn = (int) mlt_transition_get_in(tr);
2716 int currentOut = (int) mlt_transition_get_out(tr);
2717 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2718 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2720 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2721 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2722 mlt_field_disconnect_service(field->get_field(), nextservice);
2725 nextservice = mlt_service_producer(nextservice);
2726 if (nextservice == NULL) break;
2727 properties = MLT_SERVICE_PROPERTIES(nextservice);
2728 mlt_type = mlt_properties_get(properties, "mlt_type");
2729 resource = mlt_properties_get(properties, "mlt_service");
2731 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2734 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2736 Mlt::Service service(m_mltProducer->parent().get_service());
2737 Mlt::Tractor tractor(service);
2739 mlt_service_lock(service.get_service());
2740 m_mltConsumer->set("refresh", 0);
2743 mlt_service serv = m_mltProducer->parent().get_service();
2744 mlt_service nextservice = mlt_service_get_producer(serv);
2745 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2746 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2747 QString resource = mlt_properties_get(properties, "mlt_service");
2748 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2749 while (mlt_type == "transition") {
2750 mlt_transition tr = (mlt_transition) nextservice;
2751 int currentTrack = mlt_transition_get_b_track(tr);
2752 int currentIn = (int) mlt_transition_get_in(tr);
2753 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2754 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2755 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2756 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2757 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2758 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2761 nextservice = mlt_service_producer(nextservice);
2762 if (nextservice == NULL) break;
2763 properties = MLT_SERVICE_PROPERTIES(nextservice);
2764 mlt_type = mlt_properties_get(properties, "mlt_type");
2765 resource = mlt_properties_get(properties, "mlt_service");
2767 m_isBlocked = false;
2768 mlt_service_unlock(service.get_service());
2769 m_mltConsumer->set("refresh", 1);
2773 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2775 Mlt::Service service(m_mltProducer->parent().get_service());
2776 Mlt::Tractor tractor(service);
2778 mlt_service_lock(service.get_service());
2779 m_mltConsumer->set("refresh", 0);
2782 mlt_service serv = m_mltProducer->parent().get_service();
2783 mlt_service nextservice = mlt_service_get_producer(serv);
2784 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2785 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2786 QString resource = mlt_properties_get(properties, "mlt_service");
2788 while (mlt_type == "transition") {
2789 mlt_transition tr = (mlt_transition) nextservice;
2790 int currentTrack = mlt_transition_get_b_track(tr);
2791 int currentaTrack = mlt_transition_get_a_track(tr);
2792 int currentIn = (int) mlt_transition_get_in(tr);
2793 int currentOut = (int) mlt_transition_get_out(tr);
2794 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2795 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2796 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2797 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2798 kDebug() << "//////MOVING";
2799 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2800 if (endTrack != startTrack) {
2801 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2802 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2803 mlt_properties_set_int(properties, "b_track", endTrack);
2807 nextservice = mlt_service_producer(nextservice);
2808 if (nextservice == NULL) break;
2809 properties = MLT_SERVICE_PROPERTIES(nextservice);
2810 mlt_type = mlt_properties_get(properties, "mlt_type");
2811 resource = mlt_properties_get(properties, "mlt_service");
2813 m_isBlocked = false;
2814 mlt_service_unlock(service.get_service());
2815 m_mltConsumer->set("refresh", 1);
2819 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2821 if (in >= out) return false;
2822 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2823 Mlt::Service service(m_mltProducer->parent().get_service());
2825 Mlt::Tractor tractor(service);
2826 Mlt::Field *field = tractor.field();
2828 char *transId = decodedString(tag);
2829 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2830 if (out != GenTime())
2831 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2832 QMap<QString, QString>::Iterator it;
2834 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2835 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2836 if (xml.hasAttribute("id"))
2837 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
2839 for (it = args.begin(); it != args.end(); ++it) {
2841 char *name = decodedString(key);
2842 char *value = decodedString(it.value());
2843 if (it.value().isEmpty() == false) transition->set(name, value);
2844 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2848 // attach filter to the clip
2849 field->plant_transition(*transition, a_track, b_track);
2855 void Render::mltSavePlaylist()
2857 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2858 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2859 fileConsumer.set("resource", "/tmp/playlist.mlt");
2861 Mlt::Service service(m_mltProducer->get_service());
2863 fileConsumer.connect(service);
2864 fileConsumer.start();
2867 QList <Mlt::Producer *> Render::producersList()
2869 QList <Mlt::Producer *> prods;
2870 Mlt::Service service(m_mltProducer->parent().get_service());
2871 if (service.type() != tractor_type) return prods;
2872 Mlt::Tractor tractor(service);
2875 int trackNb = tractor.count();
2876 for (int t = 1; t < trackNb; t++) {
2877 Mlt::Producer *tt = tractor.track(t);
2878 Mlt::Producer trackProducer(tt);
2880 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2881 int clipNb = trackPlaylist.count();
2882 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2883 for (int i = 0; i < clipNb; i++) {
2884 Mlt::Producer *c = trackPlaylist.get_clip(i);
2885 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2887 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2888 ids.append(nprod->get("id"));
2889 prods.append(nprod);
2890 } else delete nprod;
2898 void Render::fillSlowMotionProducers()
2900 Mlt::Service service(m_mltProducer->parent().get_service());
2901 if (service.type() != tractor_type) return;
2903 Mlt::Tractor tractor(service);
2905 int trackNb = tractor.count();
2906 for (int t = 1; t < trackNb; t++) {
2907 Mlt::Producer *tt = tractor.track(t);
2908 Mlt::Producer trackProducer(tt);
2910 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2911 int clipNb = trackPlaylist.count();
2912 for (int i = 0; i < clipNb; i++) {
2913 Mlt::Producer *c = trackPlaylist.get_clip(i);
2914 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2916 QString id = nprod->get("id");
2917 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
2918 // this is a slowmotion producer, add it to the list
2919 QString url = QString::fromUtf8(nprod->get("resource"));
2920 if (!m_slowmotionProducers.contains(url)) {
2921 m_slowmotionProducers.insert(url, nprod);
2923 } else delete nprod;
2930 void Render::mltInsertTrack(int ix, bool videoTrack)
2935 m_mltConsumer->set("refresh", 0);
2936 mlt_service_lock(m_mltConsumer->get_service());
2937 Mlt::Service service(m_mltProducer->parent().get_service());
2938 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2940 Mlt::Tractor tractor(service);
2942 Mlt::Playlist playlist;
2943 int ct = tractor.count();
2945 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
2951 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2952 tractor.set_track(playlist, pos);
2953 Mlt::Producer newProd(tractor.track(pos));
2954 if (!videoTrack) newProd.set("hide", 1);
2956 for (; pos <= ct; pos++) {
2957 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2958 tractor.set_track(*prodToMove, pos);
2959 prodToMove = prodToMove2;
2962 tractor.set_track(playlist, ix);
2963 Mlt::Producer newProd(tractor.track(ix));
2964 if (!videoTrack) newProd.set("hide", 1);
2968 mlt_service serv = m_mltProducer->parent().get_service();
2969 mlt_service nextservice = mlt_service_get_producer(serv);
2970 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2971 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2972 QString resource = mlt_properties_get(properties, "mlt_service");
2974 while (mlt_type == "transition") {
2975 if (resource != "mix") {
2976 mlt_transition tr = (mlt_transition) nextservice;
2977 int currentTrack = mlt_transition_get_b_track(tr);
2978 int currentaTrack = mlt_transition_get_a_track(tr);
2979 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2981 if (currentTrack >= ix) {
2982 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2983 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2986 nextservice = mlt_service_producer(nextservice);
2987 if (nextservice == NULL) break;
2988 properties = MLT_SERVICE_PROPERTIES(nextservice);
2989 mlt_type = mlt_properties_get(properties, "mlt_type");
2990 resource = mlt_properties_get(properties, "mlt_service");
2993 // Add audio mix transition to last track
2994 Mlt::Field *field = tractor.field();
2995 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2996 //transition->set("mlt_service", "mix");
2997 transition->set("a_track", 1);
2998 transition->set("b_track", ct);
2999 transition->set("always_active", 1);
3000 transition->set("internal_added", 237);
3001 transition->set("combine", 1);
3002 field->plant_transition(*transition, 1, ct);
3004 mlt_service_unlock(m_mltConsumer->get_service());
3005 m_isBlocked = false;
3006 blockSignals(false);
3010 void Render::mltDeleteTrack(int ix)
3013 doc.setContent(sceneList(), false);
3014 int tracksCount = doc.elementsByTagName("track").count() - 1;
3015 QDomNode track = doc.elementsByTagName("track").at(ix);
3016 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3017 QDomNodeList transitions = doc.elementsByTagName("transition");
3018 for (int i = 0; i < transitions.count(); i++) {
3019 QDomElement e = transitions.at(i).toElement();
3020 QDomNodeList props = e.elementsByTagName("property");
3021 QMap <QString, QString> mappedProps;
3022 for (int j = 0; j < props.count(); j++) {
3023 QDomElement f = props.at(j).toElement();
3024 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3026 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3027 tractor.removeChild(transitions.at(i));
3028 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
3029 // Transition needs to be moved
3030 int a_track = mappedProps.value("a_track").toInt();
3031 int b_track = mappedProps.value("b_track").toInt();
3032 if (a_track > 0) a_track --;
3033 if (b_track > 0) b_track --;
3034 for (int j = 0; j < props.count(); j++) {
3035 QDomElement f = props.at(j).toElement();
3036 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3037 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3042 tractor.removeChild(track);
3043 setSceneList(doc.toString(), m_framePosition);
3048 void Render::updatePreviewSettings()
3050 kDebug() << "////// RESTARTING CONSUMER";
3051 if (!m_mltConsumer || !m_mltProducer) return;
3052 if (m_mltProducer->get_playtime() == 0) return;
3053 Mlt::Service service(m_mltProducer->parent().get_service());
3054 if (service.type() != tractor_type) return;
3056 //m_mltConsumer->set("refresh", 0);
3057 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3058 m_mltConsumer->purge();
3059 QString scene = sceneList();
3061 if (m_mltProducer) {
3062 pos = m_mltProducer->position();
3063 delete m_mltProducer;
3065 m_mltProducer = NULL;
3066 setSceneList(scene, pos);
3069 #include "renderer.moc"