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 tmp = decodedString(audioDriver);
153 m_mltConsumer->set("audio_driver", tmp);
158 m_mltConsumer->set("progressive", 1);
159 m_mltConsumer->set("audio_buffer", 1024);
160 m_mltConsumer->set("frequency", 48000);
162 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
163 m_blackClip->set("id", "black");
167 int Render::resetProfile()
169 if (!m_mltConsumer) return 0;
170 if (m_activeProfile == KdenliveSettings::current_profile()) {
171 kDebug() << "reset to same profile, nothing to do";
174 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
175 if (m_isSplitView) slotSplitView(false);
176 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
177 m_mltConsumer->purge();
178 delete m_mltConsumer;
179 m_mltConsumer = NULL;
180 QString scene = sceneList();
183 pos = m_mltProducer->position();
184 delete m_mltProducer;
186 m_mltProducer = NULL;
188 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
189 /*if (m_mltProfile) delete m_mltProfile;
190 m_mltProfile = NULL;*/
194 //kDebug() << "//RESET WITHSCENE: " << scene;
195 setSceneList(scene, pos);
197 /*char *tmp = decodedString(scene);
198 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
200 m_mltProducer = producer;
201 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
202 m_mltProducer->optimise();
203 m_mltProducer->set_speed(0);
206 //delete m_mltProfile;
207 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
208 //mlt_profile prof = m_mltProfile->get_profile();
209 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
210 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
211 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
212 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
214 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
219 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
220 void Render::seek(GenTime time)
225 m_mltProducer->seek((int)(time.frames(m_fps)));
230 char *Render::decodedString(QString str)
232 /*QCString fn = QFile::encodeName(str);
233 char *t = new char[fn.length() + 1];
234 strcpy(t, (const char *)fn);*/
236 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
240 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
241 QPixmap pix(width, height);
243 mlt_image_format format = mlt_image_rgb24a;
244 uint8_t *thumb = frame->get_image(format, width, height);
245 QImage image(thumb, width, height, QImage::Format_ARGB32);
247 if (!image.isNull()) {
248 pix = pix.fromImage(image);
250 QPainter painter(&pix);
251 painter.drawRect(0, 0, width - 1, height - 1);
253 } else pix.fill(Qt::black);
257 int Render::renderWidth() const
259 return (int)(m_mltProfile->height() * m_mltProfile->dar());
262 int Render::renderHeight() const
264 return m_mltProfile->height();
267 QPixmap Render::extractFrame(int frame_position, int width, int height)
270 width = renderWidth();
271 height = renderHeight();
273 QPixmap pix(width, height);
274 if (!m_mltProducer) {
278 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
281 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
285 if (url.fileName().startsWith(".all.")) { // check for slideshow
286 QString fileType = url.fileName().right(3);
288 QStringList::Iterator it;
290 QDir dir(url.directory());
292 filter << "*." + fileType;
293 filter << "*." + fileType.toUpper();
294 more = dir.entryList(filter, QDir::Files);
295 im.load(url.directory() + '/' + more.at(0));
296 } else im.load(url.path());
297 //pixmap = im.scaled(width, height);
302 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
303 QPixmap pix(width, height);
304 char *tmp = decodedString(file);
305 Mlt::Profile *prof = new Mlt::Profile(profile);
306 Mlt::Producer m_producer(*prof, tmp);
308 if (m_producer.is_blank()) {
313 Mlt::Filter m_convert(*prof, "avcolour_space");
314 m_convert.set("forced", mlt_image_rgb24a);
315 m_producer.attach(m_convert);
316 m_producer.seek(frame_position);
317 Mlt::Frame * frame = m_producer.get_frame();
319 pix = frameThumbnail(frame, width, height, true);
322 if (prof) delete prof;
327 void Render::getImage(KUrl url, int frame_position, QPoint size)
329 char *tmp = decodedString(url.path());
330 Mlt::Producer m_producer(tmp);
332 if (m_producer.is_blank()) {
335 Mlt::Filter m_convert("avcolour_space");
336 m_convert.set("forced", mlt_image_rgb24a);
337 m_producer.attach(m_convert);
338 m_producer.seek(frame_position);
340 Mlt::Frame * frame = m_producer.get_frame();
343 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
345 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
349 /* Create thumbnail for color */
350 /*void Render::getImage(int id, QString color, QPoint size)
352 QPixmap pixmap(size.x() - 2, size.y() - 2);
353 color = color.replace(0, 2, "#");
354 color = color.left(7);
355 pixmap.fill(QColor(color));
356 QPixmap result(size.x(), size.y());
357 result.fill(Qt::black);
358 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
359 emit replyGetImage(id, result, size.x(), size.y());
363 /* Create thumbnail for image */
364 /*void Render::getImage(KUrl url, QPoint size)
368 if (url.fileName().startsWith(".all.")) { // check for slideshow
369 QString fileType = url.fileName().right(3);
371 QStringList::Iterator it;
373 QDir dir( url.directory() );
374 more = dir.entryList( QDir::Files );
375 for ( it = more.begin() ; it != more.end() ; ++it ) {
376 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
377 if (!im.load(url.directory() + '/' + *it))
378 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
383 else im.load(url.path());
385 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
386 QPixmap result(size.x(), size.y());
387 result.fill(Qt::black);
388 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
389 emit replyGetImage(url, 1, result, size.x(), size.y());
393 double Render::consumerRatio() const
395 if (!m_mltConsumer) return 1.0;
396 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
400 int Render::getLength()
404 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
405 return mlt_producer_get_playtime(m_mltProducer->get_producer());
410 bool Render::isValid(KUrl url)
412 char *tmp = decodedString(url.path());
413 Mlt::Producer producer(*m_mltProfile, tmp);
415 if (producer.is_blank())
421 double Render::dar() const
423 return m_mltProfile->dar();
426 void Render::slotSplitView(bool doit)
428 m_isSplitView = doit;
429 Mlt::Service service(m_mltProducer->parent().get_service());
430 Mlt::Tractor tractor(service);
431 if (service.type() != tractor_type || tractor.count() < 2) return;
432 Mlt::Field *field = tractor.field();
435 for (int i = 1; i < tractor.count() && screen < 4; i++) {
436 Mlt::Producer trackProducer(tractor.track(i));
437 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
438 if (QString(trackProducer.get("hide")).toInt() != 1) {
439 kDebug() << "// ADIDNG TRACK: " << i;
440 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
441 transition->set("mlt_service", "composite");
442 transition->set("a_track", 0);
443 transition->set("b_track", i);
444 transition->set("distort", 1);
445 transition->set("internal_added", "200");
452 tmp = "50%,0:50%x50%";
455 tmp = "0,50%:50%x50%";
459 tmp = "50%,50%:50%x50%";
462 transition->set("geometry", tmp);
463 transition->set("always_active", "1");
464 field->plant_transition(*transition, 0, i);
469 m_mltConsumer->set("refresh", 1);
471 mlt_service serv = m_mltProducer->parent().get_service();
472 mlt_service nextservice = mlt_service_get_producer(serv);
473 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
474 QString mlt_type = mlt_properties_get(properties, "mlt_type");
475 QString resource = mlt_properties_get(properties, "mlt_service");
477 while (mlt_type == "transition") {
478 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
479 if (added == "200") {
480 mlt_field_disconnect_service(field->get_field(), nextservice);
482 nextservice = mlt_service_producer(nextservice);
483 if (nextservice == NULL) break;
484 properties = MLT_SERVICE_PROPERTIES(nextservice);
485 mlt_type = mlt_properties_get(properties, "mlt_type");
486 resource = mlt_properties_get(properties, "mlt_service");
487 m_mltConsumer->set("refresh", 1);
492 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer)
494 KUrl url = KUrl(xml.attribute("resource", QString()));
495 Mlt::Producer *producer = NULL;
496 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
497 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
500 if (xml.attribute("type").toInt() == COLOR) {
501 char *tmp = decodedString("colour:" + xml.attribute("colour"));
502 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
504 } else if (url.isEmpty()) {
506 QDomElement mlt = doc.createElement("mlt");
507 QDomElement play = doc.createElement("playlist");
508 doc.appendChild(mlt);
509 mlt.appendChild(play);
510 play.appendChild(doc.importNode(xml, true));
511 char *tmp = decodedString(doc.toString());
512 producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
515 char *tmp = decodedString(url.path());
516 producer = new Mlt::Producer(*m_mltProfile, tmp);
520 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
521 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
522 emit removeInvalidClip(clipId, replaceProducer);
527 if (xml.hasAttribute("force_aspect_ratio")) {
528 double aspect = xml.attribute("force_aspect_ratio").toDouble();
529 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
531 if (xml.hasAttribute("threads")) {
532 int threads = xml.attribute("threads").toInt();
533 if (threads != 1) producer->set("threads", threads);
535 if (xml.hasAttribute("video_index")) {
536 int vindex = xml.attribute("video_index").toInt();
537 if (vindex != 0) producer->set("video_index", vindex);
539 if (xml.hasAttribute("audio_index")) {
540 int aindex = xml.attribute("audio_index").toInt();
541 if (aindex != 0) producer->set("audio_index", aindex);
544 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
546 char *tmp = decodedString(clipId);
547 producer->set("id", tmp);
551 int width = (int)(height * m_mltProfile->dar());
552 QMap < QString, QString > filePropertyMap;
553 QMap < QString, QString > metadataPropertyMap;
555 int frameNumber = xml.attribute("thumbnail", "0").toInt();
556 if (frameNumber != 0) producer->seek(frameNumber);
558 filePropertyMap["duration"] = QString::number(producer->get_playtime());
559 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
561 Mlt::Frame *frame = producer->get_frame();
563 if (xml.attribute("type").toInt() == SLIDESHOW) {
564 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
565 if (xml.attribute("fade") == "1") {
566 // user wants a fade effect to slideshow
567 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
568 if (filter && filter->is_valid()) {
569 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
570 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
571 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
572 char *tmp = decodedString(xml.attribute("luma_file"));
573 filter->set("luma.resource", tmp);
575 if (xml.hasAttribute("softness")) {
576 int soft = xml.attribute("softness").toInt();
577 filter->set("luma.softness", (double) soft / 100.0);
580 Mlt::Service clipService(producer->get_service());
581 clipService.attach(*filter);
587 filePropertyMap["fps"] = producer->get("source_fps");
589 if (frame && frame->is_valid()) {
590 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
591 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
592 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
593 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
595 if (frame->get_int("test_image") == 0) {
596 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
597 filePropertyMap["type"] = "playlist";
598 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
599 } else if (frame->get_int("test_audio") == 0)
600 filePropertyMap["type"] = "av";
602 filePropertyMap["type"] = "video";
604 mlt_image_format format = mlt_image_yuv422;
606 int frame_height = 0;
607 //frame->set("rescale.interp", "hyper");
608 frame->set("normalised_height", height);
609 frame->set("normalised_width", width);
610 QPixmap pix(width, height);
612 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
613 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
614 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
615 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
617 if (!image.isNull()) {
618 pix = QPixmap::fromImage(image.rgbSwapped());
622 mlt_pool_release(new_image);
623 emit replyGetImage(clipId, pix);
625 } else if (frame->get_int("test_audio") == 0) {
626 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
627 emit replyGetImage(clipId, pixmap);
628 filePropertyMap["type"] = "audio";
632 // Retrieve audio / video codec name
636 if (producer->get_int("video_index") > -1) {
637 /*if (context->duration == AV_NOPTS_VALUE) {
638 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
639 emit removeInvalidClip(clipId);
643 // Get the video_index
644 int default_video = producer->get_int("video_index");
646 int default_audio = producer->get_int("audio_index");
649 // Find maximum stream index values
650 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
651 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
652 QString type = producer->get(property);
655 else if (type == "audio")
658 filePropertyMap["default_video"] = QString::number(default_video);
659 filePropertyMap["video_max"] = QString::number(video_max);
660 filePropertyMap["default_audio"] = QString::number(default_audio);
661 filePropertyMap["audio_max"] = QString::number(audio_max);
663 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
664 if (producer->get(property)) {
665 filePropertyMap["videocodec"] = producer->get(property);
667 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
668 if (producer->get(property))
669 filePropertyMap["videocodec"] = producer->get(property);
672 if (KdenliveSettings::dropbframes()) {
673 kDebug() << "// LOOKING FOR H264 on: " << default_video;
674 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
675 kDebug() << "PROP: " << property << " = " << producer->get(property);
676 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
677 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
678 producer->set("skip_loop_filter", "all");
679 producer->set("skip_frame", "bidir");
683 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
684 if (producer->get_int("audio_index") > -1) {
685 // Get the audio_index
686 int index = producer->get_int("audio_index");
688 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
689 if (producer->get(property)) {
690 filePropertyMap["audiocodec"] = producer->get(property);
692 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
693 if (producer->get(property))
694 filePropertyMap["audiocodec"] = producer->get(property);
699 Mlt::Properties metadata;
700 metadata.pass_values(*producer, "meta.attr.");
701 int count = metadata.count();
702 for (int i = 0; i < count; i ++) {
703 QString name = metadata.get_name(i);
704 QString value = QString::fromUtf8(metadata.get(i));
705 if (name.endsWith("markup") && !value.isEmpty())
706 metadataPropertyMap[ name.section('.', 0, -2)] = value;
709 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
710 kDebug() << "REquested fuile info for: " << url.path();
712 // FIXME: should delete this to avoid a leak...
717 /** Create the producer from the MLT XML QDomDocument */
719 void Render::initSceneList()
721 kDebug() << "-------- INIT SCENE LIST ------_";
723 QDomElement mlt = doc.createElement("mlt");
724 doc.appendChild(mlt);
725 QDomElement prod = doc.createElement("producer");
726 prod.setAttribute("resource", "colour");
727 prod.setAttribute("colour", "red");
728 prod.setAttribute("id", "black");
729 prod.setAttribute("in", "0");
730 prod.setAttribute("out", "0");
732 QDomElement tractor = doc.createElement("tractor");
733 QDomElement multitrack = doc.createElement("multitrack");
735 QDomElement playlist1 = doc.createElement("playlist");
736 playlist1.appendChild(prod);
737 multitrack.appendChild(playlist1);
738 QDomElement playlist2 = doc.createElement("playlist");
739 multitrack.appendChild(playlist2);
740 QDomElement playlist3 = doc.createElement("playlist");
741 multitrack.appendChild(playlist3);
742 QDomElement playlist4 = doc.createElement("playlist");
743 multitrack.appendChild(playlist4);
744 QDomElement playlist5 = doc.createElement("playlist");
745 multitrack.appendChild(playlist5);
746 tractor.appendChild(multitrack);
747 mlt.appendChild(tractor);
748 // kDebug()<<doc.toString();
750 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
751 setSceneList(doc, 0);
757 /** Create the producer from the MLT XML QDomDocument */
758 void Render::setProducer(Mlt::Producer *producer, int position)
760 if (m_winid == -1) return;
763 m_mltConsumer->stop();
766 m_mltConsumer->purge();
770 m_mltProducer->set_speed(0);
771 delete m_mltProducer;
772 m_mltProducer = NULL;
776 m_mltProducer = new Mlt::Producer(producer->get_producer());
777 } else m_mltProducer = m_blackClip->cut(0, 50);
778 /*if (KdenliveSettings::dropbframes()) {
779 m_mltProducer->set("skip_loop_filter", "all");
780 m_mltProducer->set("skip_frame", "bidir");
782 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
784 m_fps = m_mltProducer->get_fps();
786 if (position != -1) {
787 m_mltProducer->seek(position);
788 emit rendererPosition(position);
795 /** Create the producer from the MLT XML QDomDocument */
796 void Render::setSceneList(QDomDocument list, int position)
798 setSceneList(list.toString(), position);
801 /** Create the producer from the MLT XML QDomDocument */
802 void Render::setSceneList(QString playlist, int position)
804 if (m_winid == -1) return;
806 qDeleteAll(m_slowmotionProducers.values());
807 m_slowmotionProducers.clear();
809 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
812 m_mltConsumer->stop();
813 //m_mltConsumer->set("refresh", 0);
820 m_mltProducer->set_speed(0);
821 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
823 delete m_mltProducer;
824 m_mltProducer = NULL;
829 char *tmp = decodedString(playlist);
830 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
832 if (!m_mltProducer || !m_mltProducer->is_valid()) {
833 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
834 m_mltProducer = m_blackClip->cut(0, 50);
838 m_mltProducer->optimise();
840 /*if (KdenliveSettings::osdtimecode()) {
841 // Attach filter for on screen display of timecode
843 QString attr = "attr_check";
844 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
845 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
846 mlt_producer_attach( m_mltProducer->get_producer(), filter );
847 mlt_filter_close( filter );
849 m_osdInfo = new Mlt::Filter("data_show");
850 tmp = decodedString(m_osdProfile);
851 m_osdInfo->set("resource", tmp);
853 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
854 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
855 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
856 m_osdInfo->set("dynamic", "1");
858 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
860 m_osdInfo->set("dynamic", "0");
863 m_fps = m_mltProducer->get_fps();
864 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
866 fillSlowMotionProducers();
868 //TODO: seek to correct place after opening project.
869 // Needs to be done from another place since it crashes here.
870 m_mltProducer->seek(position);
874 emit refreshDocumentProducers();
875 //kDebug()<<"// SETSCN LST, POS: "<<position;
876 //if (position != 0) emit rendererPosition(position);
879 /** Create the producer from the MLT XML QDomDocument */
880 const QString Render::sceneList()
883 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
884 m_mltProducer->optimise();
885 xmlConsumer.set("terminate_on_pause", 1);
886 Mlt::Producer prod(m_mltProducer->get_producer());
887 bool split = m_isSplitView;
888 if (split) slotSplitView(false);
889 xmlConsumer.connect(prod);
891 while (!xmlConsumer.is_stopped()) {}
892 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
893 if (split) slotSplitView(true);
897 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
901 doc.setContent(sceneList(), false);
902 if (!kdenliveData.isNull()) {
903 // add Kdenlive specific tags
904 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
905 mlt.appendChild(doc.importNode(kdenliveData, true));
907 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
908 kWarning() << "////// ERROR writing to file: " << path;
911 file.write(doc.toString().toUtf8());
912 if (file.error() != QFile::NoError) {
921 void Render::saveZone(KUrl url, QString desc, QPoint zone)
923 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
924 char *tmppath = decodedString("xml:" + url.path());
925 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
926 m_mltProducer->optimise();
928 xmlConsumer.set("terminate_on_pause", 1);
929 if (m_name == "clip") {
930 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
931 tmppath = decodedString(desc);
933 list.insert_at(0, prod, 0);
934 list.set("title", tmppath);
936 xmlConsumer.connect(list);
939 //TODO: not working yet, save zone from timeline
940 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
941 /* Mlt::Service service(p1->parent().get_service());
942 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
944 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
945 tmppath = decodedString(desc);
946 //prod->set("title", tmppath);
948 xmlConsumer.connect(*p1); //list);
954 double Render::fps() const
959 void Render::connectPlaylist()
961 if (!m_mltConsumer) return;
962 //m_mltConsumer->set("refresh", "0");
963 m_mltConsumer->connect(*m_mltProducer);
964 m_mltProducer->set_speed(0);
965 m_mltConsumer->start();
966 emit durationChanged(m_mltProducer->get_playtime());
969 if (m_mltConsumer->start() == -1) {
970 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."));
971 delete m_mltConsumer;
972 m_mltConsumer = NULL;
979 void Render::refreshDisplay()
982 if (!m_mltProducer) return;
983 //m_mltConsumer->set("refresh", 0);
985 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
986 /*if (KdenliveSettings::osdtimecode()) {
987 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
988 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
989 m_osdInfo->set("dynamic", "1");
990 m_mltProducer->attach(*m_osdInfo);
993 m_mltProducer->detach(*m_osdInfo);
994 m_osdInfo->set("dynamic", "0");
999 void Render::setVolume(double /*volume*/)
1001 if (!m_mltConsumer || !m_mltProducer) return;
1003 m_mltConsumer->set("refresh", 0);
1004 // Attach filter for on screen display of timecode
1005 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1006 mlt_properties_set_double( properties, "meta.volume", volume );
1007 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1008 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1010 if (!KdenliveSettings::osdtimecode()) {
1011 m_mltProducer->detach(*m_osdInfo);
1012 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1013 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1016 m_osdTimer->setSingleShot(2500);
1019 void Render::slotOsdTimeout()
1021 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1022 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1023 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1024 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1028 void Render::start()
1030 kDebug() << "----- STARTING MONITOR: " << m_name;
1031 if (m_winid == -1) {
1032 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1036 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1037 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1038 if (m_mltConsumer->start() == -1) {
1039 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."));
1040 delete m_mltConsumer;
1041 m_mltConsumer = NULL;
1044 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1045 m_isBlocked = false;
1049 m_isBlocked = false;
1052 void Render::clear()
1054 kDebug() << " ********* RENDER CLEAR";
1055 if (m_mltConsumer) {
1056 //m_mltConsumer->set("refresh", 0);
1057 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1060 if (m_mltProducer) {
1061 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1062 m_mltProducer->set_speed(0.0);
1063 delete m_mltProducer;
1064 m_mltProducer = NULL;
1071 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1072 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1074 //m_mltConsumer->set("refresh", 0);
1075 m_mltConsumer->stop();
1076 // delete m_mltConsumer;
1077 // m_mltConsumer = NULL;
1079 kDebug() << "///////////// RENDER STOP2-------";
1082 if (m_mltProducer) {
1083 if (m_isZoneMode) resetZoneMode();
1084 m_mltProducer->set_speed(0.0);
1085 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1086 //kDebug() << m_mltProducer->get_length();
1088 kDebug() << "///////////// RENDER STOP3-------";
1091 void Render::stop(const GenTime & startTime)
1094 kDebug() << "///////////// RENDER STOP-------2";
1095 if (m_mltProducer) {
1096 if (m_isZoneMode) resetZoneMode();
1097 m_mltProducer->set_speed(0.0);
1098 m_mltProducer->seek((int) startTime.frames(m_fps));
1100 m_mltConsumer->purge();
1103 void Render::pause()
1105 if (!m_mltProducer || !m_mltConsumer)
1107 if (m_mltProducer->get_speed() == 0.0) return;
1108 if (m_isZoneMode) resetZoneMode();
1110 m_mltConsumer->set("refresh", 0);
1111 m_mltProducer->set_speed(0.0);
1112 emit rendererPosition(m_framePosition);
1113 m_mltProducer->seek(m_framePosition);
1114 m_mltConsumer->purge();
1117 void Render::switchPlay()
1119 if (!m_mltProducer || !m_mltConsumer)
1121 if (m_isZoneMode) resetZoneMode();
1122 if (m_mltProducer->get_speed() == 0.0) {
1123 m_isBlocked = false;
1124 m_mltProducer->set_speed(1.0);
1125 m_mltConsumer->set("refresh", 1);
1128 m_mltConsumer->set("refresh", 0);
1129 m_mltProducer->set_speed(0.0);
1130 emit rendererPosition(m_framePosition);
1131 m_mltProducer->seek(m_framePosition);
1132 m_mltConsumer->purge();
1133 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1134 //m_mltConsumer->set("refresh", 0);
1135 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1136 m_mltProducer->set_speed(0);
1137 m_mltProducer->seek( position );
1138 //m_mltProducer->seek((int) m_framePosition);
1139 m_isBlocked = false;*/
1141 /*if (speed == 0.0) {
1142 m_mltProducer->seek((int) m_framePosition + 1);
1143 m_mltConsumer->purge();
1148 void Render::play(double speed)
1152 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1153 m_isBlocked = false;
1154 m_mltProducer->set_speed(speed);
1155 /*if (speed == 0.0) {
1156 m_mltProducer->seek((int) m_framePosition + 1);
1157 m_mltConsumer->purge();
1162 void Render::play(const GenTime & startTime)
1164 if (!m_mltProducer || !m_mltConsumer)
1166 m_isBlocked = false;
1167 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1168 m_mltProducer->set_speed(1.0);
1169 m_mltConsumer->set("refresh", 1);
1172 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1174 if (!m_mltProducer || !m_mltConsumer)
1176 //m_mltProducer->set("eof", "loop");
1177 m_isLoopMode = true;
1178 m_loopStart = startTime;
1179 playZone(startTime, stopTime);
1182 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1184 if (!m_mltProducer || !m_mltConsumer)
1186 m_isBlocked = false;
1187 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1188 m_mltProducer->set("out", stopTime.frames(m_fps));
1189 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1190 m_mltProducer->set_speed(1.0);
1191 m_mltConsumer->set("refresh", 1);
1192 m_isZoneMode = true;
1195 void Render::resetZoneMode()
1197 if (!m_isZoneMode && !m_isLoopMode) return;
1198 m_mltProducer->set("out", m_originalOut);
1199 //m_mltProducer->set("eof", "pause");
1200 m_isZoneMode = false;
1201 m_isLoopMode = false;
1204 void Render::seekToFrame(int pos)
1206 //kDebug()<<" ********* RENDER SEEK TO POS";
1209 m_isBlocked = false;
1211 m_mltProducer->seek(pos);
1215 void Render::askForRefresh()
1217 // Use a Timer so that we don't refresh too much
1218 m_refreshTimer->start(200);
1221 void Render::doRefresh()
1223 // Use a Timer so that we don't refresh too much
1224 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1227 void Render::refresh()
1229 if (!m_mltProducer || m_isBlocked)
1231 m_refreshTimer->stop();
1232 if (m_mltConsumer) {
1233 m_mltConsumer->set("refresh", 1);
1237 double Render::playSpeed()
1239 if (m_mltProducer) return m_mltProducer->get_speed();
1243 GenTime Render::seekPosition() const
1245 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1246 else return GenTime();
1250 const QString & Render::rendererName() const
1256 void Render::emitFrameNumber(double position)
1258 m_framePosition = position;
1259 emit rendererPosition((int) position);
1260 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1263 void Render::emitConsumerStopped()
1265 // This is used to know when the playing stopped
1266 if (m_mltProducer) {
1267 double pos = m_mltProducer->position();
1268 if (m_isLoopMode) play(m_loopStart);
1269 else if (m_isZoneMode) resetZoneMode();
1270 emit rendererStopped((int) pos);
1271 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1272 //new QCustomEvent(10002));
1278 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1280 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1284 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1286 if (!m_mltProducer) {
1287 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1291 //int height = 1080;//KdenliveSettings::defaultheight();
1292 //int width = 1940; //KdenliveSettings::displaywidth();
1294 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1296 QPixmap pix(width, height);
1297 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1298 m_convert.set("forced", mlt_image_rgb24a);
1299 m_mltProducer->attach(m_convert);
1300 Mlt::Frame * frame = m_mltProducer->get_frame();
1301 m_mltProducer->detach(m_convert);
1303 pix = frameThumbnail(frame, width, height);
1306 pix.save(url.path(), "PNG");
1307 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1310 /** MLT PLAYLIST DIRECT MANIPULATON **/
1313 void Render::mltCheckLength()
1315 //kDebug()<<"checking track length: "<<track<<"..........";
1317 Mlt::Service service(m_mltProducer->get_service());
1318 Mlt::Tractor tractor(service);
1320 int trackNb = tractor.count();
1324 Mlt::Producer trackProducer(tractor.track(0));
1325 duration = trackProducer.get_playtime() - 1;
1326 m_mltProducer->set("out", duration);
1327 emit durationChanged(duration);
1330 while (trackNb > 1) {
1331 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1332 trackDuration = trackProducer.get_playtime() - 1;
1334 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1335 if (trackDuration > duration) duration = trackDuration;
1339 Mlt::Producer blackTrackProducer(tractor.track(0));
1340 int blackDuration = blackTrackProducer.get_playtime() - 1;
1342 if (blackDuration != duration) {
1343 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1344 blackTrackPlaylist.clear();
1346 while (dur > 14000) {
1347 blackTrackPlaylist.append(*m_blackClip, 0, 13999);
1351 blackTrackPlaylist.append(*m_blackClip, 0, dur);
1353 m_mltProducer->set("out", duration);
1354 emit durationChanged(duration);
1358 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1360 if (!m_mltProducer) {
1361 kDebug() << "PLAYLIST NOT INITIALISED //////";
1364 Mlt::Producer parentProd(m_mltProducer->parent());
1365 if (parentProd.get_producer() == NULL) {
1366 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1370 Mlt::Service service(parentProd.get_service());
1371 Mlt::Tractor tractor(service);
1372 mlt_service_lock(service.get_service());
1373 Mlt::Producer trackProducer(tractor.track(info.track));
1374 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1375 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1377 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1378 // We want a slowmotion producer
1379 double speed = element.attribute("speed", "1.0").toDouble();
1380 QString url = QString::fromUtf8(prod->get("resource"));
1381 url.append('?' + QString::number(speed));
1382 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1383 if (!slowprod || slowprod->get_producer() == NULL) {
1384 char *tmp = decodedString(url);
1385 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1387 QString id = prod->get("id");
1388 if (id.contains('_')) id = id.section('_', 0, 0);
1389 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1390 tmp = decodedString(producerid);
1391 slowprod->set("id", tmp);
1393 m_slowmotionProducers.insert(url, slowprod);
1398 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1399 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1401 /*if (QString(prod->get("transparency")).toInt() == 1)
1402 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1404 mlt_service_unlock(service.get_service());
1406 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1407 //tractor.multitrack()->refresh();
1408 //tractor.refresh();
1412 void Render::mltCutClip(int track, GenTime position)
1417 Mlt::Service service(m_mltProducer->parent().get_service());
1418 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1420 Mlt::Tractor tractor(service);
1421 Mlt::Producer trackProducer(tractor.track(track));
1422 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1425 /* // Display playlist info
1426 kDebug()<<"//////////// BEFORE";
1427 for (int i = 0; i < trackPlaylist.count(); i++) {
1428 int blankStart = trackPlaylist.clip_start(i);
1429 int blankDuration = trackPlaylist.clip_length(i) - 1;
1431 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1432 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1435 int cutPos = (int) position.frames(m_fps);
1437 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1438 if (trackPlaylist.is_blank(clipIndex)) {
1439 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1440 m_isBlocked = false;
1443 mlt_service_lock(service.get_service());
1444 int clipStart = trackPlaylist.clip_start(clipIndex);
1445 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1446 mlt_service_unlock(service.get_service());
1448 // duplicate effects
1449 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1450 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1452 if (original == NULL || clip == NULL) {
1453 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1455 Mlt::Service clipService(original->get_service());
1456 Mlt::Service dupService(clip->get_service());
1458 Mlt::Filter *filter = clipService.filter(ct);
1460 // Only duplicate Kdenlive filters, and skip the fade in effects
1461 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1462 // looks like there is no easy way to duplicate a filter,
1463 // so we will create a new one and duplicate its properties
1464 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1465 if (dup && dup->is_valid()) {
1466 Mlt::Properties entries(filter->get_properties());
1467 for (int i = 0;i < entries.count();i++) {
1468 dup->set(entries.get_name(i), entries.get(i));
1470 dupService.attach(*dup);
1474 filter = clipService.filter(ct);
1477 /* // Display playlist info
1478 kDebug()<<"//////////// AFTER";
1479 for (int i = 0; i < trackPlaylist.count(); i++) {
1480 int blankStart = trackPlaylist.clip_start(i);
1481 int blankDuration = trackPlaylist.clip_length(i) - 1;
1483 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1484 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1487 m_isBlocked = false;
1490 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1493 mltRemoveClip(info.track, info.startPos);
1494 mltInsertClip(info, element, prod);
1498 bool Render::mltRemoveClip(int track, GenTime position)
1500 Mlt::Service service(m_mltProducer->parent().get_service());
1501 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1503 Mlt::Tractor tractor(service);
1504 Mlt::Producer trackProducer(tractor.track(track));
1505 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1506 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1508 /* // Display playlist info
1509 kDebug()<<"//// BEFORE";
1510 for (int i = 0; i < trackPlaylist.count(); i++) {
1511 int blankStart = trackPlaylist.clip_start(i);
1512 int blankDuration = trackPlaylist.clip_length(i) - 1;
1514 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1515 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1518 if (trackPlaylist.is_blank(clipIndex)) {
1519 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1523 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1524 trackPlaylist.replace_with_blank(clipIndex);
1525 trackPlaylist.consolidate_blanks(0);
1526 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1527 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1529 /* // Display playlist info
1530 kDebug()<<"//// AFTER";
1531 for (int i = 0; i < trackPlaylist.count(); i++) {
1532 int blankStart = trackPlaylist.clip_start(i);
1533 int blankDuration = trackPlaylist.clip_length(i) - 1;
1535 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1536 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1539 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1540 m_isBlocked = false;
1544 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1546 if (!m_mltProducer) {
1547 kDebug() << "PLAYLIST NOT INITIALISED //////";
1550 Mlt::Producer parentProd(m_mltProducer->parent());
1551 if (parentProd.get_producer() == NULL) {
1552 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1556 Mlt::Service service(parentProd.get_service());
1557 Mlt::Tractor tractor(service);
1558 int insertPos = pos.frames(m_fps);
1560 Mlt::Producer trackProducer(tractor.track(track));
1561 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1562 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1563 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1564 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1565 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1568 int Render::mltTrackDuration(int track)
1570 if (!m_mltProducer) {
1571 kDebug() << "PLAYLIST NOT INITIALISED //////";
1574 Mlt::Producer parentProd(m_mltProducer->parent());
1575 if (parentProd.get_producer() == NULL) {
1576 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1580 Mlt::Service service(parentProd.get_service());
1581 Mlt::Tractor tractor(service);
1583 Mlt::Producer trackProducer(tractor.track(track));
1584 return trackProducer.get_playtime() - 1;
1587 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1589 if (!m_mltProducer) {
1590 kDebug() << "PLAYLIST NOT INITIALISED //////";
1593 Mlt::Producer parentProd(m_mltProducer->parent());
1594 if (parentProd.get_producer() == NULL) {
1595 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1598 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1599 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1601 Mlt::Service service(parentProd.get_service());
1602 Mlt::Tractor tractor(service);
1603 mlt_service_lock(service.get_service());
1604 int diff = duration.frames(m_fps);
1605 int offset = timeOffset.frames(m_fps);
1609 // insert space in one track only
1610 Mlt::Producer trackProducer(tractor.track(track));
1611 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1612 insertPos = trackClipStartList.value(track);
1613 if (insertPos != -1) {
1614 insertPos += offset;
1615 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1616 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1618 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1619 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1620 int position = trackPlaylist.clip_start(clipIndex);
1621 trackPlaylist.remove_region(position, - diff - 1);
1623 trackPlaylist.consolidate_blanks(0);
1625 // now move transitions
1626 mlt_service serv = m_mltProducer->parent().get_service();
1627 mlt_service nextservice = mlt_service_get_producer(serv);
1628 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1629 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1630 QString resource = mlt_properties_get(properties, "mlt_service");
1632 while (mlt_type == "transition") {
1633 mlt_transition tr = (mlt_transition) nextservice;
1634 int currentTrack = mlt_transition_get_b_track(tr);
1635 int currentIn = (int) mlt_transition_get_in(tr);
1636 int currentOut = (int) mlt_transition_get_out(tr);
1637 insertPos = trackTransitionStartList.value(track);
1638 if (insertPos != -1) {
1639 insertPos += offset;
1640 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1641 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1644 nextservice = mlt_service_producer(nextservice);
1645 if (nextservice == NULL) break;
1646 properties = MLT_SERVICE_PROPERTIES(nextservice);
1647 mlt_type = mlt_properties_get(properties, "mlt_type");
1648 resource = mlt_properties_get(properties, "mlt_service");
1651 int trackNb = tractor.count();
1652 while (trackNb > 1) {
1653 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1654 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1657 //int clipNb = trackPlaylist.count();
1658 insertPos = trackClipStartList.value(trackNb - 1);
1659 if (insertPos != -1) {
1660 insertPos += offset;
1662 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1663 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1664 for (int i = 0; i < clipNb; i++) {
1665 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1666 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1667 kDebug()<<"-------------";
1669 kDebug()<<"END-------------";*/
1672 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1673 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1675 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1676 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1677 int position = trackPlaylist.clip_start(clipIndex);
1678 trackPlaylist.remove_region(position, - diff - 1);
1680 trackPlaylist.consolidate_blanks(0);
1684 // now move transitions
1685 mlt_service serv = m_mltProducer->parent().get_service();
1686 mlt_service nextservice = mlt_service_get_producer(serv);
1687 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1688 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1689 QString resource = mlt_properties_get(properties, "mlt_service");
1691 while (mlt_type == "transition") {
1692 mlt_transition tr = (mlt_transition) nextservice;
1693 int currentIn = (int) mlt_transition_get_in(tr);
1694 int currentOut = (int) mlt_transition_get_out(tr);
1695 int currentTrack = mlt_transition_get_b_track(tr);
1696 insertPos = trackTransitionStartList.value(currentTrack);
1697 if (insertPos != -1) {
1698 insertPos += offset;
1699 if (currentOut > insertPos && resource != "mix") {
1700 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1703 nextservice = mlt_service_producer(nextservice);
1704 if (nextservice == NULL) break;
1705 properties = MLT_SERVICE_PROPERTIES(nextservice);
1706 mlt_type = mlt_properties_get(properties, "mlt_type");
1707 resource = mlt_properties_get(properties, "mlt_service");
1710 mlt_service_unlock(service.get_service());
1712 m_mltConsumer->set("refresh", 1);
1715 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod)
1719 Mlt::Service service(m_mltProducer->parent().get_service());
1720 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1721 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1722 Mlt::Tractor tractor(service);
1723 Mlt::Producer trackProducer(tractor.track(info.track));
1724 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1725 int startPos = info.startPos.frames(m_fps);
1726 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1727 int clipLength = trackPlaylist.clip_length(clipIndex);
1729 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1730 if (!clip.is_valid() || clip.is_blank()) {
1734 Mlt::Producer clipparent = clip.parent();
1735 if (!clipparent.is_valid() || clipparent.is_blank()) {
1739 QString serv = clipparent.get("mlt_service");
1740 QString id = clipparent.get("id");
1741 //kDebug() << "CLIP SERVICE: " << serv;
1742 if (serv == "avformat" && speed != 1.0) {
1743 mlt_service_lock(service.get_service());
1744 QString url = QString::fromUtf8(clipparent.get("resource"));
1745 url.append('?' + QString::number(speed));
1746 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1747 if (!slowprod || slowprod->get_producer() == NULL) {
1748 char *tmp = decodedString(url);
1749 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1751 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1752 tmp = decodedString(producerid);
1753 slowprod->set("id", tmp);
1755 m_slowmotionProducers.insert(url, slowprod);
1757 trackPlaylist.replace_with_blank(clipIndex);
1758 trackPlaylist.consolidate_blanks(0);
1759 // Check that the blank space is long enough for our new duration
1760 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1761 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1763 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1764 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1765 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1766 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1767 trackPlaylist.insert_at(startPos, *cut, 1);
1768 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1769 newLength = trackPlaylist.clip_length(clipIndex);
1770 mlt_service_unlock(service.get_service());
1771 } else if (speed == 1.0) {
1772 mlt_service_lock(service.get_service());
1774 trackPlaylist.replace_with_blank(clipIndex);
1775 trackPlaylist.consolidate_blanks(0);
1777 // Check that the blank space is long enough for our new duration
1778 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1779 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1782 GenTime oldDuration = GenTime(clipLength, m_fps);
1783 GenTime newDuration = oldDuration * oldspeed;
1784 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1785 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1786 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1787 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1788 trackPlaylist.insert_at(startPos, *cut, 1);
1789 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1790 newLength = trackPlaylist.clip_length(clipIndex);
1791 mlt_service_unlock(service.get_service());
1793 } else if (serv == "framebuffer") {
1794 mlt_service_lock(service.get_service());
1795 QString url = QString::fromUtf8(clipparent.get("resource"));
1796 url = url.section('?', 0, 0);
1797 url.append('?' + QString::number(speed));
1798 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1799 if (!slowprod || slowprod->get_producer() == NULL) {
1800 char *tmp = decodedString(url);
1801 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1803 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1804 tmp = decodedString(producerid);
1805 slowprod->set("id", tmp);
1807 m_slowmotionProducers.insert(url, slowprod);
1809 trackPlaylist.replace_with_blank(clipIndex);
1810 trackPlaylist.consolidate_blanks(0);
1812 GenTime oldDuration = GenTime(clipLength, m_fps);
1813 GenTime newDuration = oldDuration * oldspeed / speed;
1815 // Check that the blank space is long enough for our new duration
1816 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1817 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1820 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1821 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1822 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1823 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1825 trackPlaylist.insert_at(startPos, *cut, 1);
1826 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1827 newLength = trackPlaylist.clip_length(clipIndex);
1829 mlt_service_unlock(service.get_service());
1831 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1832 m_isBlocked = false;
1836 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1838 kDebug() << "// TRYing to remove effect at: " << index;
1839 Mlt::Service service(m_mltProducer->parent().get_service());
1840 bool success = false;
1841 Mlt::Tractor tractor(service);
1842 Mlt::Producer trackProducer(tractor.track(track));
1843 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1844 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1845 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1847 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1850 Mlt::Service clipService(clip->get_service());
1851 // if (tag.startsWith("ladspa")) tag = "ladspa";
1854 Mlt::Filter *filter = clipService.filter(ct);
1856 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1857 if (clipService.detach(*filter) == 0) success = true;
1858 kDebug() << " / / / DLEETED EFFECT: " << ct;
1859 } else if (updateIndex) {
1860 // Adjust the other effects index
1861 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1864 filter = clipService.filter(ct);
1866 m_isBlocked = false;
1867 if (doRefresh) refresh();
1872 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
1875 Mlt::Service service(m_mltProducer->parent().get_service());
1877 Mlt::Tractor tractor(service);
1878 Mlt::Producer trackProducer(tractor.track(track));
1879 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1881 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1885 Mlt::Service clipService(clip->get_service());
1888 // temporarily remove all effects after insert point
1889 QList <Mlt::Filter *> filtersList;
1890 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1892 Mlt::Filter *filter = clipService.filter(ct);
1894 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1895 filtersList.append(filter);
1896 clipService.detach(*filter);
1898 filter = clipService.filter(ct);
1902 QString tag = params.paramValue("tag");
1903 kDebug() << " / / INSERTING EFFECT: " << tag;
1904 if (tag.startsWith("ladspa")) tag = "ladspa";
1905 char *filterTag = decodedString(tag);
1906 char *filterId = decodedString(params.paramValue("id"));
1907 QHash<QString, QString>::Iterator it;
1908 QString kfr = params.paramValue("keyframes");
1910 if (!kfr.isEmpty()) {
1911 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1912 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1913 char *starttag = decodedString(params.paramValue("starttag", "start"));
1914 char *endtag = decodedString(params.paramValue("endtag", "end"));
1915 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1916 int duration = clip->get_playtime();
1917 //double max = params.paramValue("max").toDouble();
1918 double min = params.paramValue("min").toDouble();
1919 double factor = params.paramValue("factor", "1").toDouble();
1920 params.removeParam("starttag");
1921 params.removeParam("endtag");
1922 params.removeParam("keyframes");
1923 params.removeParam("min");
1924 params.removeParam("max");
1925 params.removeParam("factor");
1927 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1928 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1929 if (filter && filter->is_valid()) {
1930 filter->set("kdenlive_id", filterId);
1931 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1932 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1933 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1934 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1935 if (x2 == -1) x2 = duration;
1937 for (int j = 0; j < params.count(); j++) {
1938 char *name = decodedString(params.at(j).name());
1939 char *value = decodedString(params.at(j).value());
1940 filter->set(name, value);
1945 filter->set("in", x1);
1946 filter->set("out", x2);
1947 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1948 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1949 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1950 clipService.attach(*filter);
1957 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1958 if (filter && filter->is_valid())
1959 filter->set("kdenlive_id", filterId);
1961 kDebug() << "filter is NULL";
1962 m_isBlocked = false;
1966 params.removeParam("kdenlive_id");
1968 for (int j = 0; j < params.count(); j++) {
1969 char *name = decodedString(params.at(j).name());
1970 char *value = decodedString(params.at(j).value());
1971 filter->set(name, value);
1977 QString effectArgs = params.paramValue("id").section('_', 1);
1979 params.removeParam("id");
1980 params.removeParam("kdenlive_ix");
1981 params.removeParam("tag");
1982 params.removeParam("disabled");
1984 for (int j = 0; j < params.count(); j++) {
1985 effectArgs.append(' ' + params.at(j).value());
1987 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1988 char *value = decodedString(effectArgs.simplified());
1989 filter->set("effect", value);
1994 // attach filter to the clip
1995 clipService.attach(*filter);
2000 // re-add following filters
2001 for (int i = 0; i < filtersList.count(); i++) {
2002 clipService.attach(*(filtersList.at(i)));
2005 m_isBlocked = false;
2006 if (doRefresh) refresh();
2010 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2012 QString index = params.paramValue("kdenlive_ix");
2013 QString tag = params.paramValue("tag");
2015 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2016 // This is a keyframe effect, to edit it, we remove it and re-add it.
2017 mltRemoveEffect(track, position, index, true);
2018 bool success = mltAddEffect(track, position, params);
2023 Mlt::Service service(m_mltProducer->parent().get_service());
2025 Mlt::Tractor tractor(service);
2026 Mlt::Producer trackProducer(tractor.track(track));
2027 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2028 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2029 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2031 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2034 Mlt::Service clipService(clip->get_service());
2037 Mlt::Filter *filter = clipService.filter(ct);
2039 if (filter->get("kdenlive_ix") == index) {
2043 filter = clipService.filter(ct);
2047 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2048 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2050 filter = clipService.filter(ct);
2051 QList <Mlt::Filter *> filtersList;
2053 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2054 filtersList.append(filter);
2055 clipService.detach(*filter);
2057 filter = clipService.filter(ct);
2059 bool success = mltAddEffect(track, position, params);
2061 for (int i = 0; i < filtersList.count(); i++) {
2062 clipService.attach(*(filtersList.at(i)));
2065 m_isBlocked = false;
2069 for (int j = 0; j < params.count(); j++) {
2070 char *name = decodedString(params.at(j).name());
2071 char *value = decodedString(params.at(j).value());
2072 filter->set(name, value);
2077 m_isBlocked = false;
2082 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2085 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2086 Mlt::Service service(m_mltProducer->parent().get_service());
2088 Mlt::Tractor tractor(service);
2089 Mlt::Producer trackProducer(tractor.track(track));
2090 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2091 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2092 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2094 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2097 Mlt::Service clipService(clip->get_service());
2100 QList <Mlt::Filter *> filtersList;
2101 Mlt::Filter *filter = clipService.filter(ct);
2103 if (newPos > oldPos) {
2105 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2106 filter->set("kdenlive_ix", newPos);
2107 filtersList.append(filter);
2108 clipService.detach(*filter);
2109 filter = clipService.filter(ct);
2110 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2111 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2113 filter = clipService.filter(ct);
2117 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2118 filtersList.append(filter);
2119 clipService.detach(*filter);
2121 filter = clipService.filter(ct);
2125 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2126 filter->set("kdenlive_ix", newPos);
2127 filtersList.append(filter);
2128 clipService.detach(*filter);
2130 filter = clipService.filter(ct);
2134 filter = clipService.filter(ct);
2136 int pos = QString(filter->get("kdenlive_ix")).toInt();
2137 if (pos >= newPos) {
2138 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2139 filtersList.append(filter);
2140 clipService.detach(*filter);
2142 filter = clipService.filter(ct);
2146 for (int i = 0; i < filtersList.count(); i++) {
2147 clipService.attach(*(filtersList.at(i)));
2150 m_isBlocked = false;
2154 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2158 Mlt::Service service(m_mltProducer->parent().get_service());
2160 Mlt::Tractor tractor(service);
2161 Mlt::Producer trackProducer(tractor.track(info.track));
2162 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2164 /* // Display playlist info
2165 kDebug()<<"//////////// BEFORE RESIZE";
2166 for (int i = 0; i < trackPlaylist.count(); i++) {
2167 int blankStart = trackPlaylist.clip_start(i);
2168 int blankDuration = trackPlaylist.clip_length(i) - 1;
2170 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2171 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2174 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2175 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2176 m_isBlocked = false;
2179 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2180 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2181 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2182 int previousStart = clip->get_in();
2183 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2184 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2185 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2186 trackPlaylist.consolidate_blanks(0);
2187 // skip to next clip
2189 int diff = newDuration - previousDuration;
2190 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2192 // clip was made longer, trim next blank if there is one.
2193 if (clipIndex < trackPlaylist.count()) {
2194 // If this is not the last clip in playlist
2195 if (trackPlaylist.is_blank(clipIndex)) {
2196 int blankStart = trackPlaylist.clip_start(clipIndex);
2197 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2198 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2199 if (diff - blankDuration == 1) {
2200 trackPlaylist.remove(clipIndex);
2201 } else trackPlaylist.remove_region(blankStart, diff - 1);
2203 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2206 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2208 trackPlaylist.consolidate_blanks(0);
2211 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2212 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2213 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2214 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2215 ItemInfo transpinfo;
2216 transpinfo.startPos = info.startPos;
2217 transpinfo.endPos = info.startPos + clipDuration;
2218 transpinfo.track = info.track;
2219 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2221 m_isBlocked = false;
2222 m_mltConsumer->set("refresh", 1);
2226 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2228 Mlt::Service service(m_mltProducer->parent().get_service());
2229 Mlt::Tractor tractor(service);
2230 Mlt::Producer trackProducer(tractor.track(track));
2233 if (blind) trackProducer.set("hide", 3);
2234 else trackProducer.set("hide", 2);
2236 trackProducer.set("hide", 1);
2238 trackProducer.set("hide", 0);
2240 tractor.multitrack()->refresh();
2246 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2248 Mlt::Service service(m_mltProducer->parent().get_service());
2249 int frameOffset = (int) diff.frames(m_fps);
2250 Mlt::Tractor tractor(service);
2251 Mlt::Producer trackProducer(tractor.track(info.track));
2252 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2253 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2254 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2257 mlt_service_lock(service.get_service());
2258 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2259 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2261 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2262 mlt_service_unlock(service.get_service());
2265 int previousStart = clip->get_in();
2266 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2268 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2269 m_isBlocked = false;
2270 mlt_service_unlock(service.get_service());
2271 m_mltConsumer->set("refresh", 1);
2275 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2277 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2278 Mlt::Service service(m_mltProducer->parent().get_service());
2279 int moveFrame = (int) diff.frames(m_fps);
2280 Mlt::Tractor tractor(service);
2281 Mlt::Producer trackProducer(tractor.track(info.track));
2282 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2283 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2284 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2287 mlt_service_lock(service.get_service());
2288 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2289 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2291 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2292 mlt_service_unlock(service.get_service());
2295 int previousStart = clip->get_in();
2296 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2298 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2299 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2300 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2302 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2303 int blankIndex = clipIndex - 1;
2304 int blankLength = trackPlaylist.clip_length(blankIndex);
2305 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2306 if (! trackPlaylist.is_blank(blankIndex)) {
2307 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2309 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2310 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2312 trackPlaylist.consolidate_blanks(0);
2313 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2314 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2315 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2316 ItemInfo transpinfo;
2317 transpinfo.startPos = info.startPos + diff;
2318 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2319 transpinfo.track = info.track;
2320 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2322 m_isBlocked = false;
2323 //m_mltConsumer->set("refresh", 1);
2324 mlt_service_unlock(service.get_service());
2325 m_mltConsumer->set("refresh", 1);
2329 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2331 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2335 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2337 if (prod == NULL || !prod->is_valid()) {
2338 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2341 kDebug() << "NEW PROD ID: " << prod->get("id");
2342 m_mltConsumer->set("refresh", 0);
2343 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2344 mlt_service_lock(m_mltConsumer->get_service());
2345 Mlt::Service service(m_mltProducer->parent().get_service());
2346 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2348 Mlt::Tractor tractor(service);
2349 Mlt::Producer trackProducer(tractor.track(track));
2350 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2351 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2352 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2353 if (clipProducer.is_blank()) {
2354 kDebug() << "// ERROR UPDATING CLIP PROD";
2355 mlt_service_unlock(m_mltConsumer->get_service());
2356 m_isBlocked = false;
2359 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2361 // move all effects to the correct producer
2362 Mlt::Service clipService(clipProducer.get_service());
2363 Mlt::Service newClipService(clip->get_service());
2366 Mlt::Filter *filter = clipService.filter(ct);
2368 if (filter->get("kdenlive_ix") != 0) {
2369 clipService.detach(*filter);
2370 newClipService.attach(*filter);
2372 filter = clipService.filter(ct);
2375 trackPlaylist.insert_at(pos, clip, 1);
2376 mlt_service_unlock(m_mltConsumer->get_service());
2377 m_isBlocked = false;
2380 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2384 m_mltConsumer->set("refresh", 0);
2385 mlt_service_lock(m_mltConsumer->get_service());
2386 Mlt::Service service(m_mltProducer->parent().get_service());
2387 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2389 Mlt::Tractor tractor(service);
2390 Mlt::Producer trackProducer(tractor.track(startTrack));
2391 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2392 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2393 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2394 bool checkLength = false;
2395 if (endTrack == startTrack) {
2396 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2397 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2398 // error, destination is not empty
2399 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2400 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2401 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2402 mlt_service_unlock(m_mltConsumer->get_service());
2403 m_isBlocked = false;
2406 trackPlaylist.consolidate_blanks(0);
2407 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2408 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2409 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2411 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2413 //mlt_service_unlock(service.get_service());
2415 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2416 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2417 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2418 // error, destination is not empty
2419 mlt_service_unlock(m_mltConsumer->get_service());
2420 m_isBlocked = false;
2423 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2424 if (clipProducer.is_blank()) {
2425 // error, destination is not empty
2426 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2427 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2428 mlt_service_unlock(m_mltConsumer->get_service());
2429 m_isBlocked = false;
2432 trackPlaylist.consolidate_blanks(0);
2433 destTrackPlaylist.consolidate_blanks(1);
2434 Mlt::Producer *clip;
2435 // check if we are moving a slowmotion producer
2436 QString serv = clipProducer.parent().get("mlt_service");
2437 QString currentid = clipProducer.parent().get("id");
2438 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2439 clip = &clipProducer;
2442 // Special case: prod is null when using placeholder clips.
2443 // in that case, use the producer existing in playlist. Note that
2444 // it will bypass the one producer per track logic and might cause
2445 // Sound cracks if clip is moved so that it overlaps another copy of itself
2446 clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out());
2447 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2450 // move all effects to the correct producer
2451 Mlt::Service clipService(clipProducer.get_service());
2452 Mlt::Service newClipService(clip->get_service());
2455 Mlt::Filter *filter = clipService.filter(ct);
2457 if (filter->get("kdenlive_ix") != 0) {
2458 clipService.detach(*filter);
2459 newClipService.attach(*filter);
2461 filter = clipService.filter(ct);
2464 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2465 destTrackPlaylist.consolidate_blanks(0);
2466 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2467 kDebug() << "//////// moving clip transparency";
2468 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2470 if (clipIndex > trackPlaylist.count()) checkLength = true;
2471 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2475 if (checkLength) mltCheckLength();
2476 mlt_service_unlock(m_mltConsumer->get_service());
2477 m_isBlocked = false;
2478 m_mltConsumer->set("refresh", 1);
2482 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2484 int new_in = (int)newIn.frames(m_fps);
2485 int new_out = (int)newOut.frames(m_fps) - 1;
2486 if (new_in >= new_out) return false;
2488 Mlt::Service service(m_mltProducer->parent().get_service());
2489 Mlt::Tractor tractor(service);
2491 mlt_service_lock(service.get_service());
2492 m_mltConsumer->set("refresh", 0);
2495 mlt_service serv = m_mltProducer->parent().get_service();
2496 mlt_service nextservice = mlt_service_get_producer(serv);
2497 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2498 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2499 QString resource = mlt_properties_get(properties, "mlt_service");
2500 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2502 while (mlt_type == "transition") {
2503 mlt_transition tr = (mlt_transition) nextservice;
2504 int currentTrack = mlt_transition_get_b_track(tr);
2505 int currentIn = (int) mlt_transition_get_in(tr);
2506 int currentOut = (int) mlt_transition_get_out(tr);
2508 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2509 mlt_transition_set_in_and_out(tr, new_in, new_out);
2510 if (newTrack - startTrack != 0) {
2511 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2513 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2514 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2515 mlt_properties_set_int(properties, "b_track", newTrack);
2516 //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);
2520 nextservice = mlt_service_producer(nextservice);
2521 if (nextservice == NULL) break;
2522 properties = MLT_SERVICE_PROPERTIES(nextservice);
2523 mlt_type = mlt_properties_get(properties, "mlt_type");
2524 resource = mlt_properties_get(properties, "mlt_service");
2526 m_isBlocked = false;
2527 mlt_service_unlock(service.get_service());
2528 m_mltConsumer->set("refresh", 1);
2532 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2534 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2535 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2537 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2538 mltAddTransition(tag, a_track, b_track, in, out, xml);
2540 //mltSavePlaylist();
2543 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2546 Mlt::Service service(m_mltProducer->parent().get_service());
2547 Mlt::Tractor tractor(service);
2549 //m_mltConsumer->set("refresh", 0);
2550 mlt_service serv = m_mltProducer->parent().get_service();
2552 mlt_service nextservice = mlt_service_get_producer(serv);
2553 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2554 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2555 QString resource = mlt_properties_get(properties, "mlt_service");
2556 int in_pos = (int) in.frames(m_fps);
2557 int out_pos = (int) out.frames(m_fps) - 1;
2559 while (mlt_type == "transition") {
2560 mlt_transition tr = (mlt_transition) nextservice;
2561 int currentTrack = mlt_transition_get_b_track(tr);
2562 int currentBTrack = mlt_transition_get_a_track(tr);
2563 int currentIn = (int) mlt_transition_get_in(tr);
2564 int currentOut = (int) mlt_transition_get_out(tr);
2566 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2568 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2569 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2570 QMap<QString, QString>::Iterator it;
2572 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2573 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2574 if (currentBTrack != a_track) {
2575 mlt_properties_set_int(properties, "a_track", a_track);
2577 for (it = map.begin(); it != map.end(); ++it) {
2579 char *name = decodedString(key);
2580 char *value = decodedString(it.value());
2581 mlt_properties_set(transproperties, name, value);
2582 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2583 //filter->set("kdenlive_id", id);
2589 nextservice = mlt_service_producer(nextservice);
2590 if (nextservice == NULL) break;
2591 properties = MLT_SERVICE_PROPERTIES(nextservice);
2592 mlt_type = mlt_properties_get(properties, "mlt_type");
2593 resource = mlt_properties_get(properties, "mlt_service");
2595 m_isBlocked = false;
2596 m_mltConsumer->set("refresh", 1);
2599 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2601 Mlt::Service service(m_mltProducer->parent().get_service());
2602 Mlt::Tractor tractor(service);
2603 Mlt::Field *field = tractor.field();
2605 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2606 mlt_service serv = m_mltProducer->parent().get_service();
2608 mlt_service nextservice = mlt_service_get_producer(serv);
2609 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2610 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2611 QString resource = mlt_properties_get(properties, "mlt_service");
2613 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2615 while (mlt_type == "transition") {
2616 mlt_transition tr = (mlt_transition) nextservice;
2617 int currentTrack = mlt_transition_get_b_track(tr);
2618 int currentIn = (int) mlt_transition_get_in(tr);
2619 int currentOut = (int) mlt_transition_get_out(tr);
2620 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2622 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2623 mlt_field_disconnect_service(field->get_field(), nextservice);
2626 nextservice = mlt_service_producer(nextservice);
2627 if (nextservice == NULL) break;
2628 properties = MLT_SERVICE_PROPERTIES(nextservice);
2629 mlt_type = mlt_properties_get(properties, "mlt_type");
2630 resource = mlt_properties_get(properties, "mlt_service");
2632 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2635 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2637 QDomNodeList attribs = xml.elementsByTagName("parameter");
2638 QMap<QString, QString> map;
2639 for (int i = 0;i < attribs.count();i++) {
2640 QDomElement e = attribs.item(i).toElement();
2641 QString name = e.attribute("name");
2642 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2643 map[name] = e.attribute("default");
2644 if (!e.attribute("value").isEmpty()) {
2645 map[name] = e.attribute("value");
2647 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2648 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2649 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2652 if (e.attribute("namedesc").contains(';')) {
2653 QString format = e.attribute("format");
2654 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2655 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2657 QTextStream txtNeu(&neu);
2658 if (values.size() > 0)
2659 txtNeu << (int)values[0].toDouble();
2661 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2662 txtNeu << separators[i];
2663 txtNeu << (int)(values[i+1].toDouble());
2665 if (i < separators.size())
2666 txtNeu << separators[i];
2667 map[e.attribute("name")] = neu;
2674 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2676 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2677 Mlt::Service service(m_mltProducer->parent().get_service());
2678 Mlt::Tractor tractor(service);
2679 Mlt::Field *field = tractor.field();
2681 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2682 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2683 transition->set("transparency", id);
2684 transition->set("fill", 1);
2685 transition->set("internal_added", 237);
2686 field->plant_transition(*transition, transitiontrack, info.track);
2690 void Render::mltDeleteTransparency(int pos, int track, int id)
2692 Mlt::Service service(m_mltProducer->parent().get_service());
2693 Mlt::Tractor tractor(service);
2694 Mlt::Field *field = tractor.field();
2696 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2697 mlt_service serv = m_mltProducer->parent().get_service();
2699 mlt_service nextservice = mlt_service_get_producer(serv);
2700 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2701 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2702 QString resource = mlt_properties_get(properties, "mlt_service");
2704 while (mlt_type == "transition") {
2705 mlt_transition tr = (mlt_transition) nextservice;
2706 int currentTrack = mlt_transition_get_b_track(tr);
2707 int currentIn = (int) mlt_transition_get_in(tr);
2708 int currentOut = (int) mlt_transition_get_out(tr);
2709 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2710 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2712 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2713 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2714 mlt_field_disconnect_service(field->get_field(), nextservice);
2717 nextservice = mlt_service_producer(nextservice);
2718 if (nextservice == NULL) break;
2719 properties = MLT_SERVICE_PROPERTIES(nextservice);
2720 mlt_type = mlt_properties_get(properties, "mlt_type");
2721 resource = mlt_properties_get(properties, "mlt_service");
2723 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2726 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2728 Mlt::Service service(m_mltProducer->parent().get_service());
2729 Mlt::Tractor tractor(service);
2731 mlt_service_lock(service.get_service());
2732 m_mltConsumer->set("refresh", 0);
2735 mlt_service serv = m_mltProducer->parent().get_service();
2736 mlt_service nextservice = mlt_service_get_producer(serv);
2737 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2738 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2739 QString resource = mlt_properties_get(properties, "mlt_service");
2740 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2741 while (mlt_type == "transition") {
2742 mlt_transition tr = (mlt_transition) nextservice;
2743 int currentTrack = mlt_transition_get_b_track(tr);
2744 int currentIn = (int) mlt_transition_get_in(tr);
2745 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2746 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2747 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2748 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2749 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2750 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2753 nextservice = mlt_service_producer(nextservice);
2754 if (nextservice == NULL) break;
2755 properties = MLT_SERVICE_PROPERTIES(nextservice);
2756 mlt_type = mlt_properties_get(properties, "mlt_type");
2757 resource = mlt_properties_get(properties, "mlt_service");
2759 m_isBlocked = false;
2760 mlt_service_unlock(service.get_service());
2761 m_mltConsumer->set("refresh", 1);
2765 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2767 Mlt::Service service(m_mltProducer->parent().get_service());
2768 Mlt::Tractor tractor(service);
2770 mlt_service_lock(service.get_service());
2771 m_mltConsumer->set("refresh", 0);
2774 mlt_service serv = m_mltProducer->parent().get_service();
2775 mlt_service nextservice = mlt_service_get_producer(serv);
2776 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2777 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2778 QString resource = mlt_properties_get(properties, "mlt_service");
2780 while (mlt_type == "transition") {
2781 mlt_transition tr = (mlt_transition) nextservice;
2782 int currentTrack = mlt_transition_get_b_track(tr);
2783 int currentaTrack = mlt_transition_get_a_track(tr);
2784 int currentIn = (int) mlt_transition_get_in(tr);
2785 int currentOut = (int) mlt_transition_get_out(tr);
2786 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2787 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2788 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2789 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2790 kDebug() << "//////MOVING";
2791 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2792 if (endTrack != startTrack) {
2793 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2794 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2795 mlt_properties_set_int(properties, "b_track", endTrack);
2799 nextservice = mlt_service_producer(nextservice);
2800 if (nextservice == NULL) break;
2801 properties = MLT_SERVICE_PROPERTIES(nextservice);
2802 mlt_type = mlt_properties_get(properties, "mlt_type");
2803 resource = mlt_properties_get(properties, "mlt_service");
2805 m_isBlocked = false;
2806 mlt_service_unlock(service.get_service());
2807 m_mltConsumer->set("refresh", 1);
2811 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool /*do_refresh*/)
2813 if (in >= out) return false;
2814 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2815 Mlt::Service service(m_mltProducer->parent().get_service());
2817 Mlt::Tractor tractor(service);
2818 Mlt::Field *field = tractor.field();
2820 char *transId = decodedString(tag);
2821 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2822 if (out != GenTime())
2823 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2824 QMap<QString, QString>::Iterator it;
2826 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2827 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2829 for (it = args.begin(); it != args.end(); ++it) {
2831 char *name = decodedString(key);
2832 char *value = decodedString(it.value());
2833 if (it.value().isEmpty() == false) transition->set(name, value);
2834 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2835 //filter->set("kdenlive_id", id);
2839 // attach filter to the clip
2840 field->plant_transition(*transition, a_track, b_track);
2846 void Render::mltSavePlaylist()
2848 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2849 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2850 fileConsumer.set("resource", "/tmp/playlist.mlt");
2852 Mlt::Service service(m_mltProducer->get_service());
2854 fileConsumer.connect(service);
2855 fileConsumer.start();
2858 QList <Mlt::Producer *> Render::producersList()
2860 QList <Mlt::Producer *> prods;
2861 Mlt::Service service(m_mltProducer->parent().get_service());
2862 if (service.type() != tractor_type) return prods;
2863 Mlt::Tractor tractor(service);
2866 int trackNb = tractor.count();
2867 for (int t = 1; t < trackNb; t++) {
2868 Mlt::Producer *tt = tractor.track(t);
2869 Mlt::Producer trackProducer(tt);
2871 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2872 int clipNb = trackPlaylist.count();
2873 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2874 for (int i = 0; i < clipNb; i++) {
2875 Mlt::Producer *c = trackPlaylist.get_clip(i);
2876 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2878 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2879 ids.append(nprod->get("id"));
2880 prods.append(nprod);
2881 } else delete nprod;
2889 void Render::fillSlowMotionProducers()
2891 Mlt::Service service(m_mltProducer->parent().get_service());
2892 if (service.type() != tractor_type) return;
2894 Mlt::Tractor tractor(service);
2896 int trackNb = tractor.count();
2897 for (int t = 1; t < trackNb; t++) {
2898 Mlt::Producer *tt = tractor.track(t);
2899 Mlt::Producer trackProducer(tt);
2901 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2902 int clipNb = trackPlaylist.count();
2903 for (int i = 0; i < clipNb; i++) {
2904 Mlt::Producer *c = trackPlaylist.get_clip(i);
2905 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
2907 QString id = nprod->get("id");
2908 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
2909 // this is a slowmotion producer, add it to the list
2910 QString url = QString::fromUtf8(nprod->get("resource"));
2911 if (!m_slowmotionProducers.contains(url)) {
2912 m_slowmotionProducers.insert(url, nprod);
2914 } else delete nprod;
2921 void Render::mltInsertTrack(int ix, bool videoTrack)
2926 m_mltConsumer->set("refresh", 0);
2927 mlt_service_lock(m_mltConsumer->get_service());
2928 Mlt::Service service(m_mltProducer->parent().get_service());
2929 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2931 Mlt::Tractor tractor(service);
2933 Mlt::Playlist playlist;
2934 int ct = tractor.count();
2936 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
2942 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2943 tractor.set_track(playlist, pos);
2944 Mlt::Producer newProd(tractor.track(pos));
2945 if (!videoTrack) newProd.set("hide", 1);
2947 for (; pos <= ct; pos++) {
2948 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2949 tractor.set_track(*prodToMove, pos);
2950 prodToMove = prodToMove2;
2953 tractor.set_track(playlist, ix);
2954 Mlt::Producer newProd(tractor.track(ix));
2955 if (!videoTrack) newProd.set("hide", 1);
2959 mlt_service serv = m_mltProducer->parent().get_service();
2960 mlt_service nextservice = mlt_service_get_producer(serv);
2961 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2962 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2963 QString resource = mlt_properties_get(properties, "mlt_service");
2965 while (mlt_type == "transition") {
2966 if (resource != "mix") {
2967 mlt_transition tr = (mlt_transition) nextservice;
2968 int currentTrack = mlt_transition_get_b_track(tr);
2969 int currentaTrack = mlt_transition_get_a_track(tr);
2970 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2972 if (currentTrack >= ix) {
2973 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2974 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2977 nextservice = mlt_service_producer(nextservice);
2978 if (nextservice == NULL) break;
2979 properties = MLT_SERVICE_PROPERTIES(nextservice);
2980 mlt_type = mlt_properties_get(properties, "mlt_type");
2981 resource = mlt_properties_get(properties, "mlt_service");
2984 // Add audio mix transition to last track
2985 Mlt::Field *field = tractor.field();
2986 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2987 //transition->set("mlt_service", "mix");
2988 transition->set("a_track", 1);
2989 transition->set("b_track", ct);
2990 transition->set("always_active", 1);
2991 transition->set("internal_added", 237);
2992 transition->set("combine", 1);
2993 field->plant_transition(*transition, 1, ct);
2995 mlt_service_unlock(m_mltConsumer->get_service());
2996 m_isBlocked = false;
2997 blockSignals(false);
3001 void Render::mltDeleteTrack(int ix)
3004 doc.setContent(sceneList(), false);
3005 int tracksCount = doc.elementsByTagName("track").count() - 1;
3006 QDomNode track = doc.elementsByTagName("track").at(ix);
3007 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3008 QDomNodeList transitions = doc.elementsByTagName("transition");
3009 for (int i = 0; i < transitions.count(); i++) {
3010 QDomElement e = transitions.at(i).toElement();
3011 QDomNodeList props = e.elementsByTagName("property");
3012 QMap <QString, QString> mappedProps;
3013 for (int j = 0; j < props.count(); j++) {
3014 QDomElement f = props.at(j).toElement();
3015 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3017 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3018 tractor.removeChild(transitions.at(i));
3019 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
3020 // Transition needs to be moved
3021 int a_track = mappedProps.value("a_track").toInt();
3022 int b_track = mappedProps.value("b_track").toInt();
3023 if (a_track > 0) a_track --;
3024 if (b_track > 0) b_track --;
3025 for (int j = 0; j < props.count(); j++) {
3026 QDomElement f = props.at(j).toElement();
3027 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3028 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3033 tractor.removeChild(track);
3034 setSceneList(doc.toString(), m_framePosition);
3039 void Render::updatePreviewSettings()
3041 kDebug() << "////// RESTARTING CONSUMER";
3042 if (!m_mltConsumer || !m_mltProducer) return;
3043 if (m_mltProducer->get_playtime() == 0) return;
3044 Mlt::Service service(m_mltProducer->parent().get_service());
3045 if (service.type() != tractor_type) return;
3047 //m_mltConsumer->set("refresh", 0);
3048 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3049 m_mltConsumer->purge();
3050 QString scene = sceneList();
3052 if (m_mltProducer) {
3053 pos = m_mltProducer->position();
3054 delete m_mltProducer;
3056 m_mltProducer = NULL;
3057 setSceneList(scene, pos);
3060 #include "renderer.moc"