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>
47 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
49 if (level > MLT_LOG_ERROR) return;
51 QApplication::postEvent(qApp->activeWindow() , new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
55 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
57 // detect if the producer has finished playing. Is there a better way to do it?
58 if (self->m_isBlocked) return;
59 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
60 self->emitConsumerStopped();
62 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
66 Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget *parent) :
79 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
81 /*if (rendererName == "project") m_monitorId = 10000;
82 else m_monitorId = 10001;*/
83 /*m_osdTimer = new QTimer(this);
84 connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));*/
88 m_mltProducer = m_blackClip->cut(0, 50);
89 m_mltConsumer->connect(*m_mltProducer);
90 m_mltProducer->set_speed(0.0);
100 void Render::closeMlt()
104 Mlt::Service service(m_mltProducer->get_service());
105 if (service.type() == tractor_type) {
106 Mlt::Tractor tractor(service);
107 int trackNb = tractor.count();
109 while (trackNb > 1) {
110 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
111 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
112 trackPlaylist.clear();
117 kDebug() << "// // // CLOSE RENDERER";
118 delete m_mltConsumer;
119 delete m_mltProducer;
125 void Render::buildConsumer()
128 m_activeProfile = KdenliveSettings::current_profile();
129 tmp = decodedString(m_activeProfile);
130 setenv("MLT_PROFILE", tmp, 1);
134 m_mltProfile = new Mlt::Profile(tmp);
137 QString videoDriver = KdenliveSettings::videodrivername();
138 if (!videoDriver.isEmpty()) {
139 if (videoDriver == "x11_noaccel") {
140 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
143 unsetenv("SDL_VIDEO_YUV_HWACCEL");
146 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
148 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
149 m_mltConsumer->set("resize", 1);
150 m_mltConsumer->set("window_id", m_winid);
151 m_mltConsumer->set("terminate_on_pause", 1);
152 tmp = decodedString(KdenliveSettings::window_background().name());
153 m_mltConsumer->set("window_background", tmp);
156 // FIXME: the event object returned by the listen gets leaked...
157 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
158 m_mltConsumer->set("rescale", "nearest");
159 mlt_log_set_callback(kdenlive_callback);
161 QString audioDevice = KdenliveSettings::audiodevicename();
162 if (!audioDevice.isEmpty()) {
163 tmp = decodedString(audioDevice);
164 m_mltConsumer->set("audio_device", tmp);
168 if (!videoDriver.isEmpty()) {
169 tmp = decodedString(videoDriver);
170 m_mltConsumer->set("video_driver", tmp);
174 QString audioDriver = KdenliveSettings::audiodrivername();
177 // Disabled because the "auto" detected driver was sometimes wrong
178 if (audioDriver.isEmpty())
179 audioDriver = KdenliveSettings::autoaudiodrivername();
182 if (!audioDriver.isEmpty()) {
183 tmp = decodedString(audioDriver);
184 m_mltConsumer->set("audio_driver", tmp);
189 m_mltConsumer->set("progressive", 1);
190 m_mltConsumer->set("audio_buffer", 1024);
191 m_mltConsumer->set("frequency", 48000);
193 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
194 m_blackClip->set("id", "black");
198 int Render::resetProfile()
200 if (!m_mltConsumer) return 0;
201 if (m_activeProfile == KdenliveSettings::current_profile()) {
202 kDebug() << "reset to same profile, nothing to do";
205 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
206 if (m_isSplitView) slotSplitView(false);
207 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
208 m_mltConsumer->purge();
209 delete m_mltConsumer;
210 m_mltConsumer = NULL;
211 QString scene = sceneList();
214 pos = m_mltProducer->position();
215 delete m_mltProducer;
217 m_mltProducer = NULL;
219 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
220 /*if (m_mltProfile) delete m_mltProfile;
221 m_mltProfile = NULL;*/
225 //kDebug() << "//RESET WITHSCENE: " << scene;
226 setSceneList(scene, pos);
228 /*char *tmp = decodedString(scene);
229 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
231 m_mltProducer = producer;
232 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
233 m_mltProducer->optimise();
234 m_mltProducer->set_speed(0);
237 //delete m_mltProfile;
238 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
239 //mlt_profile prof = m_mltProfile->get_profile();
240 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
241 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
242 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
243 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
245 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
250 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
251 void Render::seek(GenTime time)
256 m_mltProducer->seek((int)(time.frames(m_fps)));
261 char *Render::decodedString(QString str)
263 /*QCString fn = QFile::encodeName(str);
264 char *t = new char[fn.length() + 1];
265 strcpy(t, (const char *)fn);*/
267 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
271 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
272 QPixmap pix(width, height);
274 mlt_image_format format = mlt_image_rgb24a;
275 uint8_t *thumb = frame->get_image(format, width, height);
276 QImage image(thumb, width, height, QImage::Format_ARGB32);
278 if (!image.isNull()) {
279 pix = pix.fromImage(image);
281 QPainter painter(&pix);
282 painter.drawRect(0, 0, width - 1, height - 1);
284 } else pix.fill(Qt::black);
288 int Render::renderWidth() const
290 return (int)(m_mltProfile->height() * m_mltProfile->dar());
293 int Render::renderHeight() const
295 return m_mltProfile->height();
298 QPixmap Render::extractFrame(int frame_position, int width, int height)
301 width = renderWidth();
302 height = renderHeight();
303 } else if (width % 2 == 1) width++;
304 QPixmap pix(width, height);
305 if (!m_mltProducer) {
309 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
312 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
316 if (url.fileName().startsWith(".all.")) { // check for slideshow
317 QString fileType = url.fileName().right(3);
319 QStringList::Iterator it;
321 QDir dir(url.directory());
323 filter << "*." + fileType;
324 filter << "*." + fileType.toUpper();
325 more = dir.entryList(filter, QDir::Files);
326 im.load(url.directory() + '/' + more.at(0));
327 } else im.load(url.path());
328 //pixmap = im.scaled(width, height);
333 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
334 QPixmap pix(width, height);
335 char *tmp = decodedString(file);
336 Mlt::Profile *prof = new Mlt::Profile(profile);
337 Mlt::Producer m_producer(*prof, tmp);
339 if (m_producer.is_blank()) {
344 Mlt::Filter m_convert(*prof, "avcolour_space");
345 m_convert.set("forced", mlt_image_rgb24a);
346 m_producer.attach(m_convert);
347 m_producer.seek(frame_position);
348 Mlt::Frame * frame = m_producer.get_frame();
350 pix = frameThumbnail(frame, width, height, true);
353 if (prof) delete prof;
358 void Render::getImage(KUrl url, int frame_position, QPoint size)
360 char *tmp = decodedString(url.path());
361 Mlt::Producer m_producer(tmp);
363 if (m_producer.is_blank()) {
366 Mlt::Filter m_convert("avcolour_space");
367 m_convert.set("forced", mlt_image_rgb24a);
368 m_producer.attach(m_convert);
369 m_producer.seek(frame_position);
371 Mlt::Frame * frame = m_producer.get_frame();
374 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
376 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
380 /* Create thumbnail for color */
381 /*void Render::getImage(int id, QString color, QPoint size)
383 QPixmap pixmap(size.x() - 2, size.y() - 2);
384 color = color.replace(0, 2, "#");
385 color = color.left(7);
386 pixmap.fill(QColor(color));
387 QPixmap result(size.x(), size.y());
388 result.fill(Qt::black);
389 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
390 emit replyGetImage(id, result, size.x(), size.y());
394 /* Create thumbnail for image */
395 /*void Render::getImage(KUrl url, QPoint size)
399 if (url.fileName().startsWith(".all.")) { // check for slideshow
400 QString fileType = url.fileName().right(3);
402 QStringList::Iterator it;
404 QDir dir( url.directory() );
405 more = dir.entryList( QDir::Files );
406 for ( it = more.begin() ; it != more.end() ; ++it ) {
407 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
408 if (!im.load(url.directory() + '/' + *it))
409 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
414 else im.load(url.path());
416 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
417 QPixmap result(size.x(), size.y());
418 result.fill(Qt::black);
419 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
420 emit replyGetImage(url, 1, result, size.x(), size.y());
424 double Render::consumerRatio() const
426 if (!m_mltConsumer) return 1.0;
427 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
431 int Render::getLength()
435 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
436 return mlt_producer_get_playtime(m_mltProducer->get_producer());
441 bool Render::isValid(KUrl url)
443 char *tmp = decodedString(url.path());
444 Mlt::Producer producer(*m_mltProfile, tmp);
446 if (producer.is_blank())
452 double Render::dar() const
454 return m_mltProfile->dar();
457 void Render::slotSplitView(bool doit)
459 m_isSplitView = doit;
460 Mlt::Service service(m_mltProducer->parent().get_service());
461 Mlt::Tractor tractor(service);
462 if (service.type() != tractor_type || tractor.count() < 2) return;
463 Mlt::Field *field = tractor.field();
466 for (int i = 1; i < tractor.count() && screen < 4; i++) {
467 Mlt::Producer trackProducer(tractor.track(i));
468 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
469 if (QString(trackProducer.get("hide")).toInt() != 1) {
470 kDebug() << "// ADIDNG TRACK: " << i;
471 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
472 transition->set("mlt_service", "composite");
473 transition->set("a_track", 0);
474 transition->set("b_track", i);
475 transition->set("distort", 1);
476 transition->set("internal_added", "200");
483 tmp = "50%,0:50%x50%";
486 tmp = "0,50%:50%x50%";
490 tmp = "50%,50%:50%x50%";
493 transition->set("geometry", tmp);
494 transition->set("always_active", "1");
495 field->plant_transition(*transition, 0, i);
500 m_mltConsumer->set("refresh", 1);
502 mlt_service serv = m_mltProducer->parent().get_service();
503 mlt_service nextservice = mlt_service_get_producer(serv);
504 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
505 QString mlt_type = mlt_properties_get(properties, "mlt_type");
506 QString resource = mlt_properties_get(properties, "mlt_service");
508 while (mlt_type == "transition") {
509 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
510 if (added == "200") {
511 mlt_field_disconnect_service(field->get_field(), nextservice);
513 nextservice = mlt_service_producer(nextservice);
514 if (nextservice == NULL) break;
515 properties = MLT_SERVICE_PROPERTIES(nextservice);
516 mlt_type = mlt_properties_get(properties, "mlt_type");
517 resource = mlt_properties_get(properties, "mlt_service");
518 m_mltConsumer->set("refresh", 1);
523 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer)
525 KUrl url = KUrl(xml.attribute("resource", QString()));
526 Mlt::Producer *producer = NULL;
527 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
528 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
531 if (xml.attribute("type").toInt() == COLOR) {
532 char *tmp = decodedString("colour:" + xml.attribute("colour"));
533 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
535 } else if (xml.attribute("type").toInt() == TEXT) {
536 char *tmp = decodedString("kdenlivetitle:" + xml.attribute("resource"));
537 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
539 if (xml.hasAttribute("xmldata")) {
540 char *tmp = decodedString(xml.attribute("xmldata"));
541 producer->set("xmldata", tmp);
544 } else if (url.isEmpty()) {
546 QDomElement mlt = doc.createElement("mlt");
547 QDomElement play = doc.createElement("playlist");
548 doc.appendChild(mlt);
549 mlt.appendChild(play);
550 play.appendChild(doc.importNode(xml, true));
551 char *tmp = decodedString(doc.toString());
552 producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
555 char *tmp = decodedString(url.path());
556 producer = new Mlt::Producer(*m_mltProfile, tmp);
560 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
561 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
562 emit removeInvalidClip(clipId, replaceProducer);
567 if (xml.hasAttribute("force_aspect_ratio")) {
568 double aspect = xml.attribute("force_aspect_ratio").toDouble();
569 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
571 if (xml.hasAttribute("threads")) {
572 int threads = xml.attribute("threads").toInt();
573 if (threads != 1) producer->set("threads", threads);
575 if (xml.hasAttribute("video_index")) {
576 int vindex = xml.attribute("video_index").toInt();
577 if (vindex != 0) producer->set("video_index", vindex);
579 if (xml.hasAttribute("audio_index")) {
580 int aindex = xml.attribute("audio_index").toInt();
581 if (aindex != 0) producer->set("audio_index", aindex);
584 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
586 char *tmp = decodedString(clipId);
587 producer->set("id", tmp);
590 if (!replaceProducer && xml.hasAttribute("file_hash")) {
591 // Clip already has all properties
592 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
597 int width = (int)(height * m_mltProfile->dar());
598 QMap < QString, QString > filePropertyMap;
599 QMap < QString, QString > metadataPropertyMap;
601 int frameNumber = xml.attribute("thumbnail", "0").toInt();
602 if (frameNumber != 0) producer->seek(frameNumber);
604 filePropertyMap["duration"] = QString::number(producer->get_playtime());
605 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
607 Mlt::Frame *frame = producer->get_frame();
609 if (xml.attribute("type").toInt() == SLIDESHOW) {
610 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
611 if (xml.attribute("fade") == "1") {
612 // user wants a fade effect to slideshow
613 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
614 if (filter && filter->is_valid()) {
615 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
616 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
617 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
618 char *tmp = decodedString(xml.attribute("luma_file"));
619 filter->set("luma.resource", tmp);
621 if (xml.hasAttribute("softness")) {
622 int soft = xml.attribute("softness").toInt();
623 filter->set("luma.softness", (double) soft / 100.0);
626 Mlt::Service clipService(producer->get_service());
627 clipService.attach(*filter);
633 filePropertyMap["fps"] = producer->get("source_fps");
635 if (frame && frame->is_valid()) {
636 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
637 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
638 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
639 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
641 if (frame->get_int("test_image") == 0) {
642 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
643 filePropertyMap["type"] = "playlist";
644 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
645 } else if (frame->get_int("test_audio") == 0)
646 filePropertyMap["type"] = "av";
648 filePropertyMap["type"] = "video";
650 mlt_image_format format = mlt_image_rgb24a;
651 int frame_width = width;
652 int frame_height = height;
653 QPixmap pix(width, height);
654 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
655 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32);
657 if (!image.isNull()) {
658 pix = QPixmap::fromImage(image.rgbSwapped());
662 emit replyGetImage(clipId, pix);
664 } else if (frame->get_int("test_audio") == 0) {
665 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
666 emit replyGetImage(clipId, pixmap);
667 filePropertyMap["type"] = "audio";
671 // Retrieve audio / video codec name
675 if (producer->get_int("video_index") > -1) {
676 /*if (context->duration == AV_NOPTS_VALUE) {
677 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
678 emit removeInvalidClip(clipId);
682 // Get the video_index
683 int default_video = producer->get_int("video_index");
685 int default_audio = producer->get_int("audio_index");
688 // Find maximum stream index values
689 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
690 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
691 QString type = producer->get(property);
694 else if (type == "audio")
697 filePropertyMap["default_video"] = QString::number(default_video);
698 filePropertyMap["video_max"] = QString::number(video_max);
699 filePropertyMap["default_audio"] = QString::number(default_audio);
700 filePropertyMap["audio_max"] = QString::number(audio_max);
702 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
703 if (producer->get(property)) {
704 filePropertyMap["videocodec"] = producer->get(property);
706 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
707 if (producer->get(property))
708 filePropertyMap["videocodec"] = producer->get(property);
711 if (KdenliveSettings::dropbframes()) {
712 kDebug() << "// LOOKING FOR H264 on: " << default_video;
713 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
714 kDebug() << "PROP: " << property << " = " << producer->get(property);
715 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
716 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
717 producer->set("skip_loop_filter", "all");
718 producer->set("skip_frame", "bidir");
722 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
723 if (producer->get_int("audio_index") > -1) {
724 // Get the audio_index
725 int index = producer->get_int("audio_index");
727 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
728 if (producer->get(property)) {
729 filePropertyMap["audiocodec"] = producer->get(property);
731 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
732 if (producer->get(property))
733 filePropertyMap["audiocodec"] = producer->get(property);
738 Mlt::Properties metadata;
739 metadata.pass_values(*producer, "meta.attr.");
740 int count = metadata.count();
741 for (int i = 0; i < count; i ++) {
742 QString name = metadata.get_name(i);
743 QString value = QString::fromUtf8(metadata.get(i));
744 if (name.endsWith("markup") && !value.isEmpty())
745 metadataPropertyMap[ name.section('.', 0, -2)] = value;
748 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
749 kDebug() << "REquested fuile info for: " << url.path();
751 // FIXME: should delete this to avoid a leak...
756 /** Create the producer from the MLT XML QDomDocument */
758 void Render::initSceneList()
760 kDebug() << "-------- INIT SCENE LIST ------_";
762 QDomElement mlt = doc.createElement("mlt");
763 doc.appendChild(mlt);
764 QDomElement prod = doc.createElement("producer");
765 prod.setAttribute("resource", "colour");
766 prod.setAttribute("colour", "red");
767 prod.setAttribute("id", "black");
768 prod.setAttribute("in", "0");
769 prod.setAttribute("out", "0");
771 QDomElement tractor = doc.createElement("tractor");
772 QDomElement multitrack = doc.createElement("multitrack");
774 QDomElement playlist1 = doc.createElement("playlist");
775 playlist1.appendChild(prod);
776 multitrack.appendChild(playlist1);
777 QDomElement playlist2 = doc.createElement("playlist");
778 multitrack.appendChild(playlist2);
779 QDomElement playlist3 = doc.createElement("playlist");
780 multitrack.appendChild(playlist3);
781 QDomElement playlist4 = doc.createElement("playlist");
782 multitrack.appendChild(playlist4);
783 QDomElement playlist5 = doc.createElement("playlist");
784 multitrack.appendChild(playlist5);
785 tractor.appendChild(multitrack);
786 mlt.appendChild(tractor);
787 // kDebug()<<doc.toString();
789 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
790 setSceneList(doc, 0);
796 /** Create the producer from the MLT XML QDomDocument */
797 int Render::setProducer(Mlt::Producer *producer, int position)
799 if (m_winid == -1) return -1;
802 m_mltConsumer->stop();
805 m_mltConsumer->purge();
809 m_mltProducer->set_speed(0);
810 delete m_mltProducer;
811 m_mltProducer = NULL;
815 m_mltProducer = new Mlt::Producer(producer->get_producer());
816 } else m_mltProducer = m_blackClip->cut(0, 50);
817 /*if (KdenliveSettings::dropbframes()) {
818 m_mltProducer->set("skip_loop_filter", "all");
819 m_mltProducer->set("skip_frame", "bidir");
821 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
823 m_fps = m_mltProducer->get_fps();
824 int error = connectPlaylist();
825 if (position != -1) {
826 m_mltProducer->seek(position);
827 emit rendererPosition(position);
835 /** Create the producer from the MLT XML QDomDocument */
836 int Render::setSceneList(QDomDocument list, int position)
838 return setSceneList(list.toString(), position);
841 /** Create the producer from the MLT XML QDomDocument */
842 int Render::setSceneList(QString playlist, int position)
844 if (m_winid == -1) return -1;
847 qDeleteAll(m_slowmotionProducers.values());
848 m_slowmotionProducers.clear();
850 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
852 if (m_mltConsumer == NULL) {
853 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
858 if (!m_mltConsumer->is_stopped()) {
859 m_mltConsumer->stop();
860 //m_mltConsumer->set("refresh", 0);
864 m_mltProducer->set_speed(0);
865 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
867 delete m_mltProducer;
868 m_mltProducer = NULL;
873 char *tmp = decodedString(playlist);
874 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
876 if (!m_mltProducer || !m_mltProducer->is_valid()) {
877 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
878 m_mltProducer = m_blackClip->cut(0, 50);
882 m_mltProducer->optimise();
884 /*if (KdenliveSettings::osdtimecode()) {
885 // Attach filter for on screen display of timecode
887 QString attr = "attr_check";
888 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
889 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
890 mlt_producer_attach( m_mltProducer->get_producer(), filter );
891 mlt_filter_close( filter );
893 m_osdInfo = new Mlt::Filter("data_show");
894 tmp = decodedString(m_osdProfile);
895 m_osdInfo->set("resource", tmp);
897 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
898 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
899 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
900 m_osdInfo->set("dynamic", "1");
902 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
904 m_osdInfo->set("dynamic", "0");
907 m_fps = m_mltProducer->get_fps();
909 // Seek to correct place after opening project.
910 m_mltProducer->seek(position);
913 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
914 error = connectPlaylist();
915 fillSlowMotionProducers();
919 emit refreshDocumentProducers();
921 //kDebug()<<"// SETSCN LST, POS: "<<position;
922 //if (position != 0) emit rendererPosition(position);
925 /** Create the producer from the MLT XML QDomDocument */
926 const QString Render::sceneList()
929 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
930 m_mltProducer->optimise();
931 xmlConsumer.set("terminate_on_pause", 1);
932 Mlt::Producer prod(m_mltProducer->get_producer());
933 bool split = m_isSplitView;
934 if (split) slotSplitView(false);
935 xmlConsumer.connect(prod);
937 while (!xmlConsumer.is_stopped()) {}
938 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
939 if (split) slotSplitView(true);
943 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
947 doc.setContent(sceneList(), false);
948 if (!kdenliveData.isNull()) {
949 // add Kdenlive specific tags
950 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
951 mlt.appendChild(doc.importNode(kdenliveData, true));
953 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
954 kWarning() << "////// ERROR writing to file: " << path;
957 file.write(doc.toString().toUtf8());
958 if (file.error() != QFile::NoError) {
967 void Render::saveZone(KUrl url, QString desc, QPoint zone)
969 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
970 char *tmppath = decodedString("xml:" + url.path());
971 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
972 m_mltProducer->optimise();
974 xmlConsumer.set("terminate_on_pause", 1);
975 if (m_name == "clip") {
976 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
977 tmppath = decodedString(desc);
979 list.insert_at(0, prod, 0);
981 list.set("title", tmppath);
983 xmlConsumer.connect(list);
986 //TODO: not working yet, save zone from timeline
987 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
988 /* Mlt::Service service(p1->parent().get_service());
989 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
991 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
992 tmppath = decodedString(desc);
993 //prod->set("title", tmppath);
995 xmlConsumer.connect(*p1); //list);
1001 double Render::fps() const
1006 int Render::connectPlaylist()
1008 if (!m_mltConsumer) return -1;
1009 //m_mltConsumer->set("refresh", "0");
1010 m_mltConsumer->connect(*m_mltProducer);
1011 m_mltProducer->set_speed(0);
1012 if (m_mltConsumer->start() == -1) {
1013 // ARGH CONSUMER BROKEN!!!!
1014 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."));
1015 emit blockMonitors();
1016 delete m_mltProducer;
1017 m_mltProducer = NULL;
1020 emit durationChanged(m_mltProducer->get_playtime());
1025 void Render::refreshDisplay()
1028 if (!m_mltProducer) return;
1029 //m_mltConsumer->set("refresh", 0);
1031 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1032 /*if (KdenliveSettings::osdtimecode()) {
1033 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1034 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1035 m_osdInfo->set("dynamic", "1");
1036 m_mltProducer->attach(*m_osdInfo);
1039 m_mltProducer->detach(*m_osdInfo);
1040 m_osdInfo->set("dynamic", "0");
1045 void Render::setVolume(double /*volume*/)
1047 if (!m_mltConsumer || !m_mltProducer) return;
1049 m_mltConsumer->set("refresh", 0);
1050 // Attach filter for on screen display of timecode
1051 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1052 mlt_properties_set_double( properties, "meta.volume", volume );
1053 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1054 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1056 if (!KdenliveSettings::osdtimecode()) {
1057 m_mltProducer->detach(*m_osdInfo);
1058 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1059 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1062 //m_osdTimer->setSingleShot(2500);
1065 void Render::slotOsdTimeout()
1067 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1068 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1069 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1070 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1074 void Render::start()
1076 kDebug() << "----- STARTING MONITOR: " << m_name;
1077 if (m_winid == -1) {
1078 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1081 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1082 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1083 if (m_mltConsumer->start() == -1) {
1084 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."));
1085 emit blockMonitors();
1086 delete m_mltProducer;
1087 m_mltProducer = NULL;
1089 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1090 m_isBlocked = false;
1094 m_isBlocked = false;
1097 void Render::clear()
1099 kDebug() << " ********* RENDER CLEAR";
1100 if (m_mltConsumer) {
1101 //m_mltConsumer->set("refresh", 0);
1102 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1105 if (m_mltProducer) {
1106 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1107 m_mltProducer->set_speed(0.0);
1108 delete m_mltProducer;
1109 m_mltProducer = NULL;
1116 if (m_mltProducer == NULL) return;
1117 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1118 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1120 //m_mltConsumer->set("refresh", 0);
1121 m_mltConsumer->stop();
1122 // delete m_mltConsumer;
1123 // m_mltConsumer = NULL;
1125 kDebug() << "///////////// RENDER STOP2-------";
1128 if (m_mltProducer) {
1129 if (m_isZoneMode) resetZoneMode();
1130 m_mltProducer->set_speed(0.0);
1131 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1132 //kDebug() << m_mltProducer->get_length();
1134 kDebug() << "///////////// RENDER STOP3-------";
1137 void Render::stop(const GenTime & startTime)
1140 kDebug() << "///////////// RENDER STOP-------2";
1141 if (m_mltProducer) {
1142 if (m_isZoneMode) resetZoneMode();
1143 m_mltProducer->set_speed(0.0);
1144 m_mltProducer->seek((int) startTime.frames(m_fps));
1146 m_mltConsumer->purge();
1149 void Render::pause()
1151 if (!m_mltProducer || !m_mltConsumer)
1153 if (m_mltProducer->get_speed() == 0.0) return;
1154 if (m_isZoneMode) resetZoneMode();
1156 m_mltConsumer->set("refresh", 0);
1157 m_mltProducer->set_speed(0.0);
1158 emit rendererPosition(m_framePosition);
1159 m_mltProducer->seek(m_framePosition);
1160 m_mltConsumer->purge();
1163 void Render::switchPlay()
1165 if (!m_mltProducer || !m_mltConsumer)
1167 if (m_isZoneMode) resetZoneMode();
1168 if (m_mltProducer->get_speed() == 0.0) {
1169 m_isBlocked = false;
1170 m_mltProducer->set_speed(1.0);
1171 m_mltConsumer->set("refresh", 1);
1174 m_mltConsumer->set("refresh", 0);
1175 m_mltProducer->set_speed(0.0);
1176 emit rendererPosition(m_framePosition);
1177 m_mltProducer->seek(m_framePosition);
1178 m_mltConsumer->purge();
1179 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1180 //m_mltConsumer->set("refresh", 0);
1181 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1182 m_mltProducer->set_speed(0);
1183 m_mltProducer->seek( position );
1184 //m_mltProducer->seek((int) m_framePosition);
1185 m_isBlocked = false;*/
1187 /*if (speed == 0.0) {
1188 m_mltProducer->seek((int) m_framePosition + 1);
1189 m_mltConsumer->purge();
1194 void Render::play(double speed)
1198 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1199 m_isBlocked = false;
1200 m_mltProducer->set_speed(speed);
1201 /*if (speed == 0.0) {
1202 m_mltProducer->seek((int) m_framePosition + 1);
1203 m_mltConsumer->purge();
1208 void Render::play(const GenTime & startTime)
1210 if (!m_mltProducer || !m_mltConsumer)
1212 m_isBlocked = false;
1213 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1214 m_mltProducer->set_speed(1.0);
1215 m_mltConsumer->set("refresh", 1);
1218 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1220 if (!m_mltProducer || !m_mltConsumer)
1222 //m_mltProducer->set("eof", "loop");
1223 m_isLoopMode = true;
1224 m_loopStart = startTime;
1225 playZone(startTime, stopTime);
1228 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1230 if (!m_mltProducer || !m_mltConsumer)
1232 m_isBlocked = false;
1233 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1234 m_mltProducer->set("out", stopTime.frames(m_fps));
1235 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1236 m_mltProducer->set_speed(1.0);
1237 m_mltConsumer->set("refresh", 1);
1238 m_isZoneMode = true;
1241 void Render::resetZoneMode()
1243 if (!m_isZoneMode && !m_isLoopMode) return;
1244 m_mltProducer->set("out", m_originalOut);
1245 //m_mltProducer->set("eof", "pause");
1246 m_isZoneMode = false;
1247 m_isLoopMode = false;
1250 void Render::seekToFrame(int pos)
1252 //kDebug()<<" ********* RENDER SEEK TO POS";
1255 m_isBlocked = false;
1257 m_mltProducer->seek(pos);
1261 void Render::seekToFrameDiff(int diff)
1263 //kDebug()<<" ********* RENDER SEEK TO POS";
1266 m_isBlocked = false;
1268 m_mltProducer->seek(m_mltProducer->position() + diff);
1272 void Render::doRefresh()
1274 // Use a Timer so that we don't refresh too much
1275 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1278 void Render::refresh()
1280 if (!m_mltProducer || m_isBlocked)
1282 if (m_mltConsumer) {
1283 m_mltConsumer->set("refresh", 1);
1287 void Render::setDropFrames(bool show)
1289 if (m_mltConsumer) {
1291 if (show == false) dropFrames = 0;
1292 m_mltConsumer->stop();
1293 m_mltConsumer->set("play.real_time", dropFrames);
1294 if (m_mltConsumer->start() == -1) {
1295 emit blockMonitors();
1296 delete m_mltProducer;
1297 m_mltProducer = NULL;
1303 double Render::playSpeed()
1305 if (m_mltProducer) return m_mltProducer->get_speed();
1309 GenTime Render::seekPosition() const
1311 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1312 else return GenTime();
1315 int Render::seekFramePosition() const
1317 if (m_mltProducer) return (int) m_mltProducer->position();
1321 const QString & Render::rendererName() const
1327 void Render::emitFrameNumber(double position)
1329 m_framePosition = position;
1330 emit rendererPosition((int) position);
1331 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1334 void Render::emitConsumerStopped()
1336 // This is used to know when the playing stopped
1337 if (m_mltProducer) {
1338 double pos = m_mltProducer->position();
1339 if (m_isLoopMode) play(m_loopStart);
1340 else if (m_isZoneMode) resetZoneMode();
1341 emit rendererStopped((int) pos);
1342 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1343 //new QCustomEvent(10002));
1349 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1351 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1355 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1357 if (!m_mltProducer) {
1358 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1362 //int height = 1080;//KdenliveSettings::defaultheight();
1363 //int width = 1940; //KdenliveSettings::displaywidth();
1365 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1367 QPixmap pix(width, height);
1368 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1369 m_convert.set("forced", mlt_image_rgb24a);
1370 m_mltProducer->attach(m_convert);
1371 Mlt::Frame * frame = m_mltProducer->get_frame();
1372 m_mltProducer->detach(m_convert);
1374 pix = frameThumbnail(frame, width, height);
1377 pix.save(url.path(), "PNG");
1378 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1381 /** MLT PLAYLIST DIRECT MANIPULATON **/
1384 void Render::mltCheckLength()
1386 //kDebug()<<"checking track length: "<<track<<"..........";
1388 Mlt::Service service(m_mltProducer->get_service());
1389 Mlt::Tractor tractor(service);
1391 int trackNb = tractor.count();
1395 Mlt::Producer trackProducer(tractor.track(0));
1396 duration = trackProducer.get_playtime() - 1;
1397 m_mltProducer->set("out", duration);
1398 emit durationChanged(duration);
1401 while (trackNb > 1) {
1402 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1403 trackDuration = trackProducer.get_playtime() - 1;
1405 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1406 if (trackDuration > duration) duration = trackDuration;
1410 Mlt::Producer blackTrackProducer(tractor.track(0));
1412 if (blackTrackProducer.get_playtime() - 1 != duration) {
1413 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1414 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1415 if (duration > m_blackClip->get_length()) {
1416 m_blackClip->set("length", duration);
1417 m_blackClip->set("out", duration - 1);
1418 if (blackclip) blackclip->set("length", duration);
1420 if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
1421 blackTrackPlaylist.clear();
1422 blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
1423 } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1425 m_mltProducer->set("out", duration);
1426 emit durationChanged(duration);
1430 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1432 if (m_mltProducer == NULL) {
1433 kDebug() << "PLAYLIST NOT INITIALISED //////";
1436 Mlt::Producer parentProd(m_mltProducer->parent());
1437 if (parentProd.get_producer() == NULL) {
1438 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1442 Mlt::Service service(parentProd.get_service());
1443 Mlt::Tractor tractor(service);
1444 if (info.track > tractor.count() - 1) {
1445 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1448 mlt_service_lock(service.get_service());
1449 Mlt::Producer trackProducer(tractor.track(info.track));
1450 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1451 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1453 if (element.attribute("speed", "1.0").toDouble() != 1.0 || element.attribute("strobe", "1").toInt() > 1) {
1454 // We want a slowmotion producer
1455 double speed = element.attribute("speed", "1.0").toDouble();
1456 int strobe = element.attribute("strobe", "1").toInt();
1457 QString url = QString::fromUtf8(prod->get("resource"));
1458 url.append('?' + QString::number(speed));
1459 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1460 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1461 if (!slowprod || slowprod->get_producer() == NULL) {
1462 char *tmp = decodedString(url);
1463 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1464 if (strobe > 1) slowprod->set("strobe", strobe);
1466 QString id = prod->get("id");
1467 if (id.contains('_')) id = id.section('_', 0, 0);
1468 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1469 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1470 tmp = decodedString(producerid);
1471 slowprod->set("id", tmp);
1473 m_slowmotionProducers.insert(url, slowprod);
1478 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1479 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), clip, 1);
1481 /*if (QString(prod->get("transparency")).toInt() == 1)
1482 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1484 mlt_service_unlock(service.get_service());
1486 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1487 //tractor.multitrack()->refresh();
1488 //tractor.refresh();
1492 void Render::mltCutClip(int track, GenTime position)
1497 Mlt::Service service(m_mltProducer->parent().get_service());
1498 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1500 Mlt::Tractor tractor(service);
1501 Mlt::Producer trackProducer(tractor.track(track));
1502 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1505 /* // Display playlist info
1506 kDebug()<<"//////////// BEFORE";
1507 for (int i = 0; i < trackPlaylist.count(); i++) {
1508 int blankStart = trackPlaylist.clip_start(i);
1509 int blankDuration = trackPlaylist.clip_length(i) - 1;
1511 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1512 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1515 int cutPos = (int) position.frames(m_fps);
1517 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1518 if (trackPlaylist.is_blank(clipIndex)) {
1519 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1520 m_isBlocked = false;
1523 mlt_service_lock(service.get_service());
1524 int clipStart = trackPlaylist.clip_start(clipIndex);
1525 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1526 mlt_service_unlock(service.get_service());
1528 // duplicate effects
1529 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1530 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1532 if (original == NULL || clip == NULL) {
1533 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1535 Mlt::Service clipService(original->get_service());
1536 Mlt::Service dupService(clip->get_service());
1540 Mlt::Filter *filter = clipService.filter(ct);
1542 // Only duplicate Kdenlive filters, and skip the fade in effects
1543 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1544 // looks like there is no easy way to duplicate a filter,
1545 // so we will create a new one and duplicate its properties
1546 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1547 if (dup && dup->is_valid()) {
1548 Mlt::Properties entries(filter->get_properties());
1549 for (int i = 0; i < entries.count(); i++) {
1550 dup->set(entries.get_name(i), entries.get(i));
1552 dupService.attach(*dup);
1556 filter = clipService.filter(ct);
1559 /* // Display playlist info
1560 kDebug()<<"//////////// AFTER";
1561 for (int i = 0; i < trackPlaylist.count(); i++) {
1562 int blankStart = trackPlaylist.clip_start(i);
1563 int blankDuration = trackPlaylist.clip_length(i) - 1;
1565 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1566 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1569 m_isBlocked = false;
1572 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1575 mltRemoveClip(info.track, info.startPos);
1576 mltInsertClip(info, element, prod);
1580 bool Render::mltRemoveClip(int track, GenTime position)
1582 Mlt::Service service(m_mltProducer->parent().get_service());
1583 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1585 Mlt::Tractor tractor(service);
1586 mlt_service_lock(service.get_service());
1587 Mlt::Producer trackProducer(tractor.track(track));
1588 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1589 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1591 // Display playlist info
1592 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1593 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1594 int blankStart = trackPlaylist.clip_start(i);
1595 int blankDuration = trackPlaylist.clip_length(i) - 1;
1597 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1598 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1600 if (trackPlaylist.is_blank(clipIndex)) {
1601 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1602 mlt_service_unlock(service.get_service());
1605 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1607 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1609 trackPlaylist.consolidate_blanks(0);
1610 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1611 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1613 /* // Display playlist info
1614 kDebug()<<"//// AFTER";
1615 for (int i = 0; i < trackPlaylist.count(); i++) {
1616 int blankStart = trackPlaylist.clip_start(i);
1617 int blankDuration = trackPlaylist.clip_length(i) - 1;
1619 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1620 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1622 mlt_service_unlock(service.get_service());
1623 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1624 m_isBlocked = false;
1628 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1630 if (!m_mltProducer) {
1631 kDebug() << "PLAYLIST NOT INITIALISED //////";
1634 Mlt::Producer parentProd(m_mltProducer->parent());
1635 if (parentProd.get_producer() == NULL) {
1636 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1640 Mlt::Service service(parentProd.get_service());
1641 Mlt::Tractor tractor(service);
1642 int insertPos = pos.frames(m_fps);
1644 Mlt::Producer trackProducer(tractor.track(track));
1645 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1646 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1647 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1648 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1649 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1652 int Render::mltTrackDuration(int track)
1654 if (!m_mltProducer) {
1655 kDebug() << "PLAYLIST NOT INITIALISED //////";
1658 Mlt::Producer parentProd(m_mltProducer->parent());
1659 if (parentProd.get_producer() == NULL) {
1660 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1664 Mlt::Service service(parentProd.get_service());
1665 Mlt::Tractor tractor(service);
1667 Mlt::Producer trackProducer(tractor.track(track));
1668 return trackProducer.get_playtime() - 1;
1671 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1673 if (!m_mltProducer) {
1674 kDebug() << "PLAYLIST NOT INITIALISED //////";
1677 Mlt::Producer parentProd(m_mltProducer->parent());
1678 if (parentProd.get_producer() == NULL) {
1679 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1682 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1683 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1685 Mlt::Service service(parentProd.get_service());
1686 Mlt::Tractor tractor(service);
1687 mlt_service_lock(service.get_service());
1688 int diff = duration.frames(m_fps);
1689 int offset = timeOffset.frames(m_fps);
1693 // insert space in one track only
1694 Mlt::Producer trackProducer(tractor.track(track));
1695 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1696 insertPos = trackClipStartList.value(track);
1697 if (insertPos != -1) {
1698 insertPos += offset;
1699 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1700 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1702 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1703 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1704 int position = trackPlaylist.clip_start(clipIndex);
1705 int blankDuration = trackPlaylist.clip_length(clipIndex);
1707 if (blankDuration - diff == 0)
1708 trackPlaylist.remove(clipIndex);
1709 else trackPlaylist.remove_region(position, diff);
1711 trackPlaylist.consolidate_blanks(0);
1713 // now move transitions
1714 mlt_service serv = m_mltProducer->parent().get_service();
1715 mlt_service nextservice = mlt_service_get_producer(serv);
1716 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1717 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1718 QString resource = mlt_properties_get(properties, "mlt_service");
1720 while (mlt_type == "transition") {
1721 mlt_transition tr = (mlt_transition) nextservice;
1722 int currentTrack = mlt_transition_get_b_track(tr);
1723 int currentIn = (int) mlt_transition_get_in(tr);
1724 int currentOut = (int) mlt_transition_get_out(tr);
1725 insertPos = trackTransitionStartList.value(track);
1726 if (insertPos != -1) {
1727 insertPos += offset;
1728 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1729 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1732 nextservice = mlt_service_producer(nextservice);
1733 if (nextservice == NULL) break;
1734 properties = MLT_SERVICE_PROPERTIES(nextservice);
1735 mlt_type = mlt_properties_get(properties, "mlt_type");
1736 resource = mlt_properties_get(properties, "mlt_service");
1739 int trackNb = tractor.count();
1740 while (trackNb > 1) {
1741 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1742 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1745 //int clipNb = trackPlaylist.count();
1746 insertPos = trackClipStartList.value(trackNb - 1);
1747 if (insertPos != -1) {
1748 insertPos += offset;
1750 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1751 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1752 for (int i = 0; i < clipNb; i++) {
1753 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1754 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1755 kDebug()<<"-------------";
1757 kDebug()<<"END-------------";*/
1760 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1761 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1763 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1764 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1765 int position = trackPlaylist.clip_start(clipIndex);
1766 int blankDuration = trackPlaylist.clip_length(clipIndex);
1767 if (diff + blankDuration == 0)
1768 trackPlaylist.remove(clipIndex);
1769 else trackPlaylist.remove_region(position, - diff);
1771 trackPlaylist.consolidate_blanks(0);
1775 // now move transitions
1776 mlt_service serv = m_mltProducer->parent().get_service();
1777 mlt_service nextservice = mlt_service_get_producer(serv);
1778 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1779 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1780 QString resource = mlt_properties_get(properties, "mlt_service");
1782 while (mlt_type == "transition") {
1783 mlt_transition tr = (mlt_transition) nextservice;
1784 int currentIn = (int) mlt_transition_get_in(tr);
1785 int currentOut = (int) mlt_transition_get_out(tr);
1786 int currentTrack = mlt_transition_get_b_track(tr);
1787 insertPos = trackTransitionStartList.value(currentTrack);
1788 if (insertPos != -1) {
1789 insertPos += offset;
1790 if (currentOut > insertPos && resource != "mix") {
1791 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1794 nextservice = mlt_service_producer(nextservice);
1795 if (nextservice == NULL) break;
1796 properties = MLT_SERVICE_PROPERTIES(nextservice);
1797 mlt_type = mlt_properties_get(properties, "mlt_type");
1798 resource = mlt_properties_get(properties, "mlt_service");
1801 mlt_service_unlock(service.get_service());
1803 m_mltConsumer->set("refresh", 1);
1807 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1809 Mlt::Service sourceService(source->get_service());
1810 Mlt::Service destService(dest->get_service());
1812 // move all effects to the correct producer
1814 Mlt::Filter *filter = sourceService.filter(ct);
1816 if (filter->get("kdenlive_ix") != 0) {
1817 sourceService.detach(*filter);
1818 destService.attach(*filter);
1820 filter = sourceService.filter(ct);
1824 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, int strobe, Mlt::Producer *prod)
1828 Mlt::Service service(m_mltProducer->parent().get_service());
1829 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1830 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1831 Mlt::Tractor tractor(service);
1832 Mlt::Producer trackProducer(tractor.track(info.track));
1833 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1834 int startPos = info.startPos.frames(m_fps);
1835 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1836 int clipLength = trackPlaylist.clip_length(clipIndex);
1838 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1842 if (!clip->is_valid() || clip->is_blank()) {
1847 Mlt::Producer clipparent = clip->parent();
1848 if (!clipparent.is_valid() || clipparent.is_blank()) {
1854 QString serv = clipparent.get("mlt_service");
1855 QString id = clipparent.get("id");
1856 //kDebug() << "CLIP SERVICE: " << serv;
1857 if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
1858 mlt_service_lock(service.get_service());
1859 QString url = QString::fromUtf8(clipparent.get("resource"));
1860 url.append('?' + QString::number(speed));
1861 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1862 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1863 if (!slowprod || slowprod->get_producer() == NULL) {
1864 char *tmp = decodedString(url);
1865 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1866 if (strobe > 1) slowprod->set("strobe", strobe);
1868 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1869 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1870 tmp = decodedString(producerid);
1871 slowprod->set("id", tmp);
1873 m_slowmotionProducers.insert(url, slowprod);
1875 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1877 trackPlaylist.consolidate_blanks(0);
1878 // Check that the blank space is long enough for our new duration
1879 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1880 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1882 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1883 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1884 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1885 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1887 // move all effects to the correct producer
1888 mltPasteEffects(clip, cut);
1890 trackPlaylist.insert_at(startPos, cut, 1);
1892 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1893 newLength = trackPlaylist.clip_length(clipIndex);
1894 mlt_service_unlock(service.get_service());
1895 } else if (speed == 1.0 && strobe < 2) {
1896 mlt_service_lock(service.get_service());
1898 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1900 trackPlaylist.consolidate_blanks(0);
1902 // Check that the blank space is long enough for our new duration
1903 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1904 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1907 GenTime oldDuration = GenTime(clipLength, m_fps);
1908 GenTime newDuration = oldDuration * oldspeed;
1909 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1910 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1911 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1912 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1914 // move all effects to the correct producer
1915 mltPasteEffects(clip, cut);
1917 trackPlaylist.insert_at(startPos, cut, 1);
1919 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1920 newLength = trackPlaylist.clip_length(clipIndex);
1921 mlt_service_unlock(service.get_service());
1923 } else if (serv == "framebuffer") {
1924 mlt_service_lock(service.get_service());
1925 QString url = QString::fromUtf8(clipparent.get("resource"));
1926 url = url.section('?', 0, 0);
1927 url.append('?' + QString::number(speed));
1928 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1929 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1930 if (!slowprod || slowprod->get_producer() == NULL) {
1931 char *tmp = decodedString(url);
1932 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1934 slowprod->set("strobe", strobe);
1935 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1936 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1937 tmp = decodedString(producerid);
1938 slowprod->set("id", tmp);
1940 m_slowmotionProducers.insert(url, slowprod);
1942 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1944 trackPlaylist.consolidate_blanks(0);
1946 GenTime oldDuration = GenTime(clipLength, m_fps);
1947 GenTime newDuration = oldDuration * (oldspeed / speed);
1949 // Check that the blank space is long enough for our new duration
1950 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1951 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1954 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1955 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1956 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1957 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1959 // move all effects to the correct producer
1960 mltPasteEffects(clip, cut);
1962 trackPlaylist.insert_at(startPos, cut, 1);
1964 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1965 newLength = trackPlaylist.clip_length(clipIndex);
1967 mlt_service_unlock(service.get_service());
1971 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1972 m_isBlocked = false;
1976 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1978 Mlt::Service service(m_mltProducer->parent().get_service());
1979 bool success = false;
1980 Mlt::Tractor tractor(service);
1981 Mlt::Producer trackProducer(tractor.track(track));
1982 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1983 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1984 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1986 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1989 Mlt::Service clipService(clip->get_service());
1991 // if (tag.startsWith("ladspa")) tag = "ladspa";
1994 Mlt::Filter *filter = clipService.filter(ct);
1996 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1997 if (clipService.detach(*filter) == 0) success = true;
1998 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
1999 } else if (updateIndex) {
2000 // Adjust the other effects index
2001 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2004 filter = clipService.filter(ct);
2006 m_isBlocked = false;
2007 if (doRefresh) refresh();
2012 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2015 Mlt::Service service(m_mltProducer->parent().get_service());
2017 Mlt::Tractor tractor(service);
2018 Mlt::Producer trackProducer(tractor.track(track));
2019 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2021 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2025 Mlt::Service clipService(clip->get_service());
2028 // temporarily remove all effects after insert point
2029 QList <Mlt::Filter *> filtersList;
2030 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2032 Mlt::Filter *filter = clipService.filter(ct);
2034 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
2035 filtersList.append(filter);
2036 clipService.detach(*filter);
2038 filter = clipService.filter(ct);
2042 QString tag = params.paramValue("tag");
2043 kDebug() << " / / INSERTING EFFECT: " << tag;
2044 if (tag.startsWith("ladspa")) tag = "ladspa";
2045 char *filterTag = decodedString(tag);
2046 char *filterId = decodedString(params.paramValue("id"));
2047 QHash<QString, QString>::Iterator it;
2048 QString kfr = params.paramValue("keyframes");
2050 if (!kfr.isEmpty()) {
2051 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2052 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2053 char *starttag = decodedString(params.paramValue("starttag", "start"));
2054 char *endtag = decodedString(params.paramValue("endtag", "end"));
2055 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2056 int duration = clip->get_playtime();
2057 //double max = params.paramValue("max").toDouble();
2058 double min = params.paramValue("min").toDouble();
2059 double factor = params.paramValue("factor", "1").toDouble();
2060 params.removeParam("starttag");
2061 params.removeParam("endtag");
2062 params.removeParam("keyframes");
2063 params.removeParam("min");
2064 params.removeParam("max");
2065 params.removeParam("factor");
2067 for (int i = 0; i < keyFrames.size() - 1; ++i) {
2068 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2069 if (filter && filter->is_valid()) {
2070 filter->set("kdenlive_id", filterId);
2071 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2072 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2073 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2074 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2075 if (x2 == -1) x2 = duration;
2077 for (int j = 0; j < params.count(); j++) {
2078 char *name = decodedString(params.at(j).name());
2079 char *value = decodedString(params.at(j).value());
2080 filter->set(name, value);
2085 filter->set("in", x1);
2086 filter->set("out", x2);
2087 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2088 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2089 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2090 clipService.attach(*filter);
2097 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2098 if (filter && filter->is_valid())
2099 filter->set("kdenlive_id", filterId);
2101 kDebug() << "filter is NULL";
2102 m_isBlocked = false;
2106 params.removeParam("kdenlive_id");
2108 for (int j = 0; j < params.count(); j++) {
2109 char *name = decodedString(params.at(j).name());
2110 char *value = decodedString(params.at(j).value());
2111 filter->set(name, value);
2117 QString effectArgs = params.paramValue("id").section('_', 1);
2119 params.removeParam("id");
2120 params.removeParam("kdenlive_ix");
2121 params.removeParam("tag");
2122 params.removeParam("disabled");
2124 for (int j = 0; j < params.count(); j++) {
2125 effectArgs.append(' ' + params.at(j).value());
2127 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2128 char *value = decodedString(effectArgs.simplified());
2129 filter->set("effect", value);
2134 // attach filter to the clip
2135 clipService.attach(*filter);
2140 // re-add following filters
2141 for (int i = 0; i < filtersList.count(); i++) {
2142 clipService.attach(*(filtersList.at(i)));
2145 m_isBlocked = false;
2146 if (doRefresh) refresh();
2150 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2152 QString index = params.paramValue("kdenlive_ix");
2153 QString tag = params.paramValue("tag");
2155 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2156 // This is a keyframe effect, to edit it, we remove it and re-add it.
2157 mltRemoveEffect(track, position, index, false);
2158 bool success = mltAddEffect(track, position, params);
2163 Mlt::Service service(m_mltProducer->parent().get_service());
2165 Mlt::Tractor tractor(service);
2166 Mlt::Producer trackProducer(tractor.track(track));
2167 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2168 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2169 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2171 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2174 Mlt::Service clipService(clip->get_service());
2178 Mlt::Filter *filter = clipService.filter(ct);
2180 if (filter->get("kdenlive_ix") == index) {
2184 filter = clipService.filter(ct);
2188 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2189 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2191 filter = clipService.filter(ct);
2192 QList <Mlt::Filter *> filtersList;
2194 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2195 filtersList.append(filter);
2196 clipService.detach(*filter);
2198 filter = clipService.filter(ct);
2200 bool success = mltAddEffect(track, position, params);
2202 for (int i = 0; i < filtersList.count(); i++) {
2203 clipService.attach(*(filtersList.at(i)));
2206 m_isBlocked = false;
2209 mlt_service_lock(service.get_service());
2210 for (int j = 0; j < params.count(); j++) {
2211 char *name = decodedString(params.at(j).name());
2212 char *value = decodedString(params.at(j).value());
2213 filter->set(name, value);
2217 mlt_service_unlock(service.get_service());
2219 m_isBlocked = false;
2224 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2227 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2228 Mlt::Service service(m_mltProducer->parent().get_service());
2230 Mlt::Tractor tractor(service);
2231 Mlt::Producer trackProducer(tractor.track(track));
2232 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2233 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2234 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2236 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2239 Mlt::Service clipService(clip->get_service());
2243 QList <Mlt::Filter *> filtersList;
2244 Mlt::Filter *filter = clipService.filter(ct);
2246 if (newPos > oldPos) {
2248 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2249 filter->set("kdenlive_ix", newPos);
2250 filtersList.append(filter);
2251 clipService.detach(*filter);
2252 filter = clipService.filter(ct);
2253 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2254 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2256 filter = clipService.filter(ct);
2260 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2261 filtersList.append(filter);
2262 clipService.detach(*filter);
2264 filter = clipService.filter(ct);
2268 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2269 filter->set("kdenlive_ix", newPos);
2270 filtersList.append(filter);
2271 clipService.detach(*filter);
2273 filter = clipService.filter(ct);
2277 filter = clipService.filter(ct);
2279 int pos = QString(filter->get("kdenlive_ix")).toInt();
2280 if (pos >= newPos) {
2281 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2282 filtersList.append(filter);
2283 clipService.detach(*filter);
2285 filter = clipService.filter(ct);
2289 for (int i = 0; i < filtersList.count(); i++) {
2290 clipService.attach(*(filtersList.at(i)));
2293 m_isBlocked = false;
2297 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2300 Mlt::Service service(m_mltProducer->parent().get_service());
2301 Mlt::Tractor tractor(service);
2302 Mlt::Producer trackProducer(tractor.track(info.track));
2303 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2305 /* // Display playlist info
2306 kDebug()<<"//////////// BEFORE RESIZE";
2307 for (int i = 0; i < trackPlaylist.count(); i++) {
2308 int blankStart = trackPlaylist.clip_start(i);
2309 int blankDuration = trackPlaylist.clip_length(i) - 1;
2311 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2312 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2315 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2316 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2317 m_isBlocked = false;
2320 mlt_service_lock(service.get_service());
2321 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2322 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2323 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2324 int previousStart = clip->get_in();
2325 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2326 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2327 if (newDuration > clip->get_length()) {
2328 clip->parent().set("length", newDuration + 1);
2329 clip->set("length", newDuration + 1);
2331 if (newDuration > clip->get_out()) {
2332 clip->parent().set_in_and_out(0, newDuration + 1);
2333 clip->set_in_and_out(0, newDuration + 1);
2336 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2337 trackPlaylist.consolidate_blanks(0);
2338 // skip to next clip
2340 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2342 // clip was made longer, trim next blank if there is one.
2343 if (clipIndex < trackPlaylist.count()) {
2344 // If this is not the last clip in playlist
2345 if (trackPlaylist.is_blank(clipIndex)) {
2346 int blankStart = trackPlaylist.clip_start(clipIndex);
2347 int blankDuration = trackPlaylist.clip_length(clipIndex);
2348 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2349 if (diff - blankDuration == 0) {
2350 trackPlaylist.remove(clipIndex);
2351 } else trackPlaylist.remove_region(blankStart, diff);
2353 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2356 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2357 trackPlaylist.consolidate_blanks(0);
2358 mlt_service_unlock(service.get_service());
2360 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2361 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2362 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2363 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2364 ItemInfo transpinfo;
2365 transpinfo.startPos = info.startPos;
2366 transpinfo.endPos = info.startPos + clipDuration;
2367 transpinfo.track = info.track;
2368 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2370 m_isBlocked = false;
2371 m_mltConsumer->set("refresh", 1);
2375 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2377 Mlt::Service service(m_mltProducer->parent().get_service());
2378 Mlt::Tractor tractor(service);
2379 Mlt::Producer trackProducer(tractor.track(track));
2382 if (blind) trackProducer.set("hide", 3);
2383 else trackProducer.set("hide", 2);
2385 trackProducer.set("hide", 1);
2387 trackProducer.set("hide", 0);
2389 tractor.multitrack()->refresh();
2395 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2397 Mlt::Service service(m_mltProducer->parent().get_service());
2398 int frameOffset = (int) diff.frames(m_fps);
2399 Mlt::Tractor tractor(service);
2400 Mlt::Producer trackProducer(tractor.track(info.track));
2401 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2402 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2403 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2406 mlt_service_lock(service.get_service());
2407 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2408 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2410 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2411 mlt_service_unlock(service.get_service());
2414 int previousStart = clip->get_in();
2416 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2418 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2419 m_isBlocked = false;
2420 mlt_service_unlock(service.get_service());
2421 m_mltConsumer->set("refresh", 1);
2425 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2427 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2428 Mlt::Service service(m_mltProducer->parent().get_service());
2429 int moveFrame = (int) diff.frames(m_fps);
2430 Mlt::Tractor tractor(service);
2431 Mlt::Producer trackProducer(tractor.track(info.track));
2432 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2433 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2434 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2437 mlt_service_lock(service.get_service());
2438 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2439 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2441 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2442 mlt_service_unlock(service.get_service());
2445 int previousStart = clip->get_in();
2447 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2449 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2450 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2451 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2453 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2454 int blankIndex = clipIndex - 1;
2455 int blankLength = trackPlaylist.clip_length(blankIndex);
2456 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2457 if (! trackPlaylist.is_blank(blankIndex)) {
2458 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2460 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2461 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2463 trackPlaylist.consolidate_blanks(0);
2464 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2465 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2466 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2467 ItemInfo transpinfo;
2468 transpinfo.startPos = info.startPos + diff;
2469 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2470 transpinfo.track = info.track;
2471 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2473 m_isBlocked = false;
2474 //m_mltConsumer->set("refresh", 1);
2475 mlt_service_unlock(service.get_service());
2476 m_mltConsumer->set("refresh", 1);
2480 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2482 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2486 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2488 if (prod == NULL || !prod->is_valid()) {
2489 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2492 kDebug() << "NEW PROD ID: " << prod->get("id");
2494 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2495 mlt_service_lock(m_mltConsumer->get_service());
2496 Mlt::Service service(m_mltProducer->parent().get_service());
2497 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2499 Mlt::Tractor tractor(service);
2500 Mlt::Producer trackProducer(tractor.track(track));
2501 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2502 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2503 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2504 if (clipProducer->is_blank()) {
2505 kDebug() << "// ERROR UPDATING CLIP PROD";
2506 delete clipProducer;
2507 mlt_service_unlock(m_mltConsumer->get_service());
2511 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2513 // move all effects to the correct producer
2514 mltPasteEffects(clipProducer, clip);
2515 trackPlaylist.insert_at(pos, clip, 1);
2517 delete clipProducer;
2518 mlt_service_unlock(m_mltConsumer->get_service());
2522 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2526 Mlt::Service service(m_mltProducer->parent().get_service());
2527 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2529 Mlt::Tractor tractor(service);
2530 mlt_service_lock(service.get_service());
2531 Mlt::Producer trackProducer(tractor.track(startTrack));
2532 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2533 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
2534 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2535 bool checkLength = false;
2536 if (endTrack == startTrack) {
2537 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2538 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer->is_blank()) {
2539 // error, destination is not empty
2540 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2541 delete clipProducer;
2542 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2543 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2544 mlt_service_unlock(service.get_service());
2548 trackPlaylist.consolidate_blanks(0);
2549 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2550 delete clipProducer;
2551 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2552 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2554 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2556 //mlt_service_unlock(service.get_service());
2558 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2559 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2560 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2561 // error, destination is not empty
2562 mlt_service_unlock(service.get_service());
2566 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2567 if (clipProducer->is_blank()) {
2568 // error, destination is not empty
2569 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2570 delete clipProducer;
2571 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2572 mlt_service_unlock(service.get_service());
2576 trackPlaylist.consolidate_blanks(0);
2577 destTrackPlaylist.consolidate_blanks(1);
2578 Mlt::Producer *clip;
2579 // check if we are moving a slowmotion producer
2580 QString serv = clipProducer->parent().get("mlt_service");
2581 QString currentid = clipProducer->parent().get("id");
2582 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2583 clip = clipProducer;
2586 // Special case: prod is null when using placeholder clips.
2587 // in that case, use the producer existing in playlist. Note that
2588 // it will bypass the one producer per track logic and might cause
2589 // Sound cracks if clip is moved so that it overlaps another copy of itself
2590 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
2591 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2594 // move all effects to the correct producer
2595 mltPasteEffects(clipProducer, clip);
2597 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2600 if (clipProducer) delete clipProducer;
2601 destTrackPlaylist.consolidate_blanks(0);
2602 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2603 kDebug() << "//////// moving clip transparency";
2604 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2606 if (clipIndex > trackPlaylist.count()) checkLength = true;
2607 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2610 mlt_service_unlock(service.get_service());
2611 if (checkLength) mltCheckLength();
2614 //m_mltConsumer->set("refresh", 1);
2618 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2620 int new_in = (int)newIn.frames(m_fps);
2621 int new_out = (int)newOut.frames(m_fps) - 1;
2622 if (new_in >= new_out) return false;
2624 mlt_service serv = m_mltProducer->parent().get_service();
2626 mlt_service_lock(serv);
2627 //m_mltConsumer->set("refresh", 0);
2630 mlt_service nextservice = mlt_service_get_producer(serv);
2631 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2632 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2633 QString resource = mlt_properties_get(properties, "mlt_service");
2634 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2636 while (mlt_type == "transition") {
2637 mlt_transition tr = (mlt_transition) nextservice;
2638 int currentTrack = mlt_transition_get_b_track(tr);
2639 int currentIn = (int) mlt_transition_get_in(tr);
2640 int currentOut = (int) mlt_transition_get_out(tr);
2642 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2643 mlt_transition_set_in_and_out(tr, new_in, new_out);
2644 if (newTrack - startTrack != 0) {
2645 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2647 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2648 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2649 mlt_properties_set_int(properties, "b_track", newTrack);
2650 //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);
2654 nextservice = mlt_service_producer(nextservice);
2655 if (nextservice == NULL) break;
2656 properties = MLT_SERVICE_PROPERTIES(nextservice);
2657 mlt_type = mlt_properties_get(properties, "mlt_type");
2658 resource = mlt_properties_get(properties, "mlt_service");
2660 mlt_service_unlock(serv);
2663 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2667 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2669 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2671 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2672 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
2675 //mltSavePlaylist();
2678 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2680 mlt_service serv = m_mltProducer->parent().get_service();
2681 mlt_service_lock(serv);
2684 mlt_service nextservice = mlt_service_get_producer(serv);
2685 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2686 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2687 QString resource = mlt_properties_get(properties, "mlt_service");
2688 int in_pos = (int) in.frames(m_fps);
2689 int out_pos = (int) out.frames(m_fps) - 1;
2691 while (mlt_type == "transition") {
2692 mlt_transition tr = (mlt_transition) nextservice;
2693 int currentTrack = mlt_transition_get_b_track(tr);
2694 int currentBTrack = mlt_transition_get_a_track(tr);
2695 int currentIn = (int) mlt_transition_get_in(tr);
2696 int currentOut = (int) mlt_transition_get_out(tr);
2698 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2700 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2701 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2702 QMap<QString, QString>::Iterator it;
2704 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2705 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2706 // update the transition id in case it uses the same MLT service but different Kdenlive id
2707 char *tmp = decodedString(xml.attribute("id"));
2708 mlt_properties_set(transproperties, "kdenlive_id", tmp);
2710 if (currentBTrack != a_track) {
2711 mlt_properties_set_int(properties, "a_track", a_track);
2713 for (it = map.begin(); it != map.end(); ++it) {
2715 char *name = decodedString(key);
2716 char *value = decodedString(it.value());
2717 mlt_properties_set(transproperties, name, value);
2718 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2719 //filter->set("kdenlive_id", id);
2725 nextservice = mlt_service_producer(nextservice);
2726 if (nextservice == NULL) break;
2727 properties = MLT_SERVICE_PROPERTIES(nextservice);
2728 mlt_type = mlt_properties_get(properties, "mlt_type");
2729 resource = mlt_properties_get(properties, "mlt_service");
2731 mlt_service_unlock(serv);
2734 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2737 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2739 mlt_service serv = m_mltProducer->parent().get_service();
2741 mlt_service_lock(serv);
2743 Mlt::Service service(serv);
2744 Mlt::Tractor tractor(service);
2745 Mlt::Field *field = tractor.field();
2747 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2749 mlt_service nextservice = mlt_service_get_producer(serv);
2750 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2751 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2752 QString resource = mlt_properties_get(properties, "mlt_service");
2754 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2755 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2757 while (mlt_type == "transition") {
2758 mlt_transition tr = (mlt_transition) nextservice;
2759 int currentTrack = mlt_transition_get_b_track(tr);
2760 int currentIn = (int) mlt_transition_get_in(tr);
2761 int currentOut = (int) mlt_transition_get_out(tr);
2762 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2764 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2765 mlt_field_disconnect_service(field->get_field(), nextservice);
2768 nextservice = mlt_service_producer(nextservice);
2769 if (nextservice == NULL) break;
2770 properties = MLT_SERVICE_PROPERTIES(nextservice);
2771 mlt_type = mlt_properties_get(properties, "mlt_type");
2772 resource = mlt_properties_get(properties, "mlt_service");
2774 mlt_service_unlock(serv);
2777 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2780 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2782 QDomNodeList attribs = xml.elementsByTagName("parameter");
2783 QMap<QString, QString> map;
2784 for (int i = 0; i < attribs.count(); i++) {
2785 QDomElement e = attribs.item(i).toElement();
2786 QString name = e.attribute("name");
2787 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2788 map[name] = e.attribute("default");
2789 if (!e.attribute("value").isEmpty()) {
2790 map[name] = e.attribute("value");
2792 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2793 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2794 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2797 if (e.attribute("namedesc").contains(';')) {
2798 QString format = e.attribute("format");
2799 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2800 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2802 QTextStream txtNeu(&neu);
2803 if (values.size() > 0)
2804 txtNeu << (int)values[0].toDouble();
2806 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
2807 txtNeu << separators[i];
2808 txtNeu << (int)(values[i+1].toDouble());
2810 if (i < separators.size())
2811 txtNeu << separators[i];
2812 map[e.attribute("name")] = neu;
2819 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2821 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2822 Mlt::Service service(m_mltProducer->parent().get_service());
2823 Mlt::Tractor tractor(service);
2824 Mlt::Field *field = tractor.field();
2826 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2827 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2828 transition->set("transparency", id);
2829 transition->set("fill", 1);
2830 transition->set("internal_added", 237);
2831 field->plant_transition(*transition, transitiontrack, info.track);
2835 void Render::mltDeleteTransparency(int pos, int track, int id)
2837 Mlt::Service service(m_mltProducer->parent().get_service());
2838 Mlt::Tractor tractor(service);
2839 Mlt::Field *field = tractor.field();
2841 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2842 mlt_service serv = m_mltProducer->parent().get_service();
2844 mlt_service nextservice = mlt_service_get_producer(serv);
2845 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2846 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2847 QString resource = mlt_properties_get(properties, "mlt_service");
2849 while (mlt_type == "transition") {
2850 mlt_transition tr = (mlt_transition) nextservice;
2851 int currentTrack = mlt_transition_get_b_track(tr);
2852 int currentIn = (int) mlt_transition_get_in(tr);
2853 int currentOut = (int) mlt_transition_get_out(tr);
2854 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2855 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2857 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2858 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2859 mlt_field_disconnect_service(field->get_field(), nextservice);
2862 nextservice = mlt_service_producer(nextservice);
2863 if (nextservice == NULL) break;
2864 properties = MLT_SERVICE_PROPERTIES(nextservice);
2865 mlt_type = mlt_properties_get(properties, "mlt_type");
2866 resource = mlt_properties_get(properties, "mlt_service");
2868 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2871 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2873 Mlt::Service service(m_mltProducer->parent().get_service());
2874 Mlt::Tractor tractor(service);
2876 mlt_service_lock(service.get_service());
2877 m_mltConsumer->set("refresh", 0);
2880 mlt_service serv = m_mltProducer->parent().get_service();
2881 mlt_service nextservice = mlt_service_get_producer(serv);
2882 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2883 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2884 QString resource = mlt_properties_get(properties, "mlt_service");
2885 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2886 while (mlt_type == "transition") {
2887 mlt_transition tr = (mlt_transition) nextservice;
2888 int currentTrack = mlt_transition_get_b_track(tr);
2889 int currentIn = (int) mlt_transition_get_in(tr);
2890 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2891 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2892 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2893 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2894 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2895 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2898 nextservice = mlt_service_producer(nextservice);
2899 if (nextservice == NULL) break;
2900 properties = MLT_SERVICE_PROPERTIES(nextservice);
2901 mlt_type = mlt_properties_get(properties, "mlt_type");
2902 resource = mlt_properties_get(properties, "mlt_service");
2904 mlt_service_unlock(service.get_service());
2906 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2910 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2912 Mlt::Service service(m_mltProducer->parent().get_service());
2913 Mlt::Tractor tractor(service);
2915 mlt_service_lock(service.get_service());
2916 m_mltConsumer->set("refresh", 0);
2919 mlt_service serv = m_mltProducer->parent().get_service();
2920 mlt_service nextservice = mlt_service_get_producer(serv);
2921 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2922 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2923 QString resource = mlt_properties_get(properties, "mlt_service");
2925 while (mlt_type == "transition") {
2926 mlt_transition tr = (mlt_transition) nextservice;
2927 int currentTrack = mlt_transition_get_b_track(tr);
2928 int currentaTrack = mlt_transition_get_a_track(tr);
2929 int currentIn = (int) mlt_transition_get_in(tr);
2930 int currentOut = (int) mlt_transition_get_out(tr);
2931 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2932 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2933 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2934 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2935 kDebug() << "//////MOVING";
2936 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2937 if (endTrack != startTrack) {
2938 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2939 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2940 mlt_properties_set_int(properties, "b_track", endTrack);
2944 nextservice = mlt_service_producer(nextservice);
2945 if (nextservice == NULL) break;
2946 properties = MLT_SERVICE_PROPERTIES(nextservice);
2947 mlt_type = mlt_properties_get(properties, "mlt_type");
2948 resource = mlt_properties_get(properties, "mlt_service");
2951 mlt_service_unlock(service.get_service());
2952 m_mltConsumer->set("refresh", 1);
2956 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
2958 if (in >= out) return false;
2959 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2960 Mlt::Service service(m_mltProducer->parent().get_service());
2962 Mlt::Tractor tractor(service);
2963 Mlt::Field *field = tractor.field();
2965 char *transId = decodedString(tag);
2966 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2967 if (out != GenTime())
2968 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2969 QMap<QString, QString>::Iterator it;
2971 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2972 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2973 if (xml.hasAttribute("id"))
2974 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
2976 for (it = args.begin(); it != args.end(); ++it) {
2978 char *name = decodedString(key);
2979 char *value = decodedString(it.value());
2980 if (it.value().isEmpty() == false) transition->set(name, value);
2981 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2985 // attach filter to the clip
2986 field->plant_transition(*transition, a_track, b_track);
2988 if (do_refresh) refresh();
2992 void Render::mltSavePlaylist()
2994 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2995 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2996 fileConsumer.set("resource", "/tmp/playlist.mlt");
2998 Mlt::Service service(m_mltProducer->get_service());
3000 fileConsumer.connect(service);
3001 fileConsumer.start();
3004 QList <Mlt::Producer *> Render::producersList()
3006 QList <Mlt::Producer *> prods;
3007 if (m_mltProducer == NULL) return prods;
3008 Mlt::Service service(m_mltProducer->parent().get_service());
3009 if (service.type() != tractor_type) return prods;
3010 Mlt::Tractor tractor(service);
3013 int trackNb = tractor.count();
3014 for (int t = 1; t < trackNb; t++) {
3015 Mlt::Producer *tt = tractor.track(t);
3016 Mlt::Producer trackProducer(tt);
3018 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3019 int clipNb = trackPlaylist.count();
3020 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3021 for (int i = 0; i < clipNb; i++) {
3022 Mlt::Producer *c = trackPlaylist.get_clip(i);
3023 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3025 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3026 ids.append(nprod->get("id"));
3027 prods.append(nprod);
3028 } else delete nprod;
3036 void Render::fillSlowMotionProducers()
3038 if (m_mltProducer == NULL) return;
3039 Mlt::Service service(m_mltProducer->parent().get_service());
3040 if (service.type() != tractor_type) return;
3042 Mlt::Tractor tractor(service);
3044 int trackNb = tractor.count();
3045 for (int t = 1; t < trackNb; t++) {
3046 Mlt::Producer *tt = tractor.track(t);
3047 Mlt::Producer trackProducer(tt);
3049 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3050 int clipNb = trackPlaylist.count();
3051 for (int i = 0; i < clipNb; i++) {
3052 Mlt::Producer *c = trackPlaylist.get_clip(i);
3053 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3055 QString id = nprod->get("id");
3056 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3057 // this is a slowmotion producer, add it to the list
3058 QString url = QString::fromUtf8(nprod->get("resource"));
3059 int strobe = nprod->get_int("strobe");
3060 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3061 if (!m_slowmotionProducers.contains(url)) {
3062 m_slowmotionProducers.insert(url, nprod);
3064 } else delete nprod;
3071 void Render::mltInsertTrack(int ix, bool videoTrack)
3076 Mlt::Service service(m_mltProducer->parent().get_service());
3077 mlt_service_lock(service.get_service());
3078 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
3080 Mlt::Tractor tractor(service);
3082 Mlt::Playlist playlist;
3083 int ct = tractor.count();
3085 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3091 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3092 tractor.set_track(playlist, pos);
3093 Mlt::Producer newProd(tractor.track(pos));
3094 if (!videoTrack) newProd.set("hide", 1);
3096 for (; pos <= ct; pos++) {
3097 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3098 tractor.set_track(*prodToMove, pos);
3099 prodToMove = prodToMove2;
3102 tractor.set_track(playlist, ix);
3103 Mlt::Producer newProd(tractor.track(ix));
3104 if (!videoTrack) newProd.set("hide", 1);
3108 mlt_service serv = m_mltProducer->parent().get_service();
3109 mlt_service nextservice = mlt_service_get_producer(serv);
3110 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3111 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3112 QString resource = mlt_properties_get(properties, "mlt_service");
3114 while (mlt_type == "transition") {
3115 if (resource != "mix") {
3116 mlt_transition tr = (mlt_transition) nextservice;
3117 int currentTrack = mlt_transition_get_b_track(tr);
3118 int currentaTrack = mlt_transition_get_a_track(tr);
3119 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3121 if (currentTrack >= ix) {
3122 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3123 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3126 nextservice = mlt_service_producer(nextservice);
3127 if (nextservice == NULL) break;
3128 properties = MLT_SERVICE_PROPERTIES(nextservice);
3129 mlt_type = mlt_properties_get(properties, "mlt_type");
3130 resource = mlt_properties_get(properties, "mlt_service");
3133 // Add audio mix transition to last track
3134 Mlt::Field *field = tractor.field();
3135 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3136 transition->set("a_track", 1);
3137 transition->set("b_track", ct);
3138 transition->set("always_active", 1);
3139 transition->set("internal_added", 237);
3140 transition->set("combine", 1);
3141 field->plant_transition(*transition, 1, ct);
3142 //mlt_service_unlock(m_mltConsumer->get_service());
3143 mlt_service_unlock(service.get_service());
3144 //tractor.multitrack()->refresh();
3145 //tractor.refresh();
3147 blockSignals(false);
3151 void Render::mltDeleteTrack(int ix)
3154 doc.setContent(sceneList(), false);
3155 int tracksCount = doc.elementsByTagName("track").count() - 1;
3156 QDomNode track = doc.elementsByTagName("track").at(ix);
3157 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3158 QDomNodeList transitions = doc.elementsByTagName("transition");
3159 for (int i = 0; i < transitions.count(); i++) {
3160 QDomElement e = transitions.at(i).toElement();
3161 QDomNodeList props = e.elementsByTagName("property");
3162 QMap <QString, QString> mappedProps;
3163 for (int j = 0; j < props.count(); j++) {
3164 QDomElement f = props.at(j).toElement();
3165 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3167 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3168 tractor.removeChild(transitions.at(i));
3170 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3171 // Transition needs to be moved
3172 int a_track = mappedProps.value("a_track").toInt();
3173 int b_track = mappedProps.value("b_track").toInt();
3174 if (a_track > 0 && a_track >= ix) a_track --;
3175 if (b_track > 0 && b_track >= ix) b_track --;
3176 for (int j = 0; j < props.count(); j++) {
3177 QDomElement f = props.at(j).toElement();
3178 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3179 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3184 tractor.removeChild(track);
3185 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3186 setSceneList(doc.toString(), m_framePosition);
3191 void Render::updatePreviewSettings()
3193 kDebug() << "////// RESTARTING CONSUMER";
3194 if (!m_mltConsumer || !m_mltProducer) return;
3195 if (m_mltProducer->get_playtime() == 0) return;
3196 Mlt::Service service(m_mltProducer->parent().get_service());
3197 if (service.type() != tractor_type) return;
3199 //m_mltConsumer->set("refresh", 0);
3200 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3201 m_mltConsumer->purge();
3202 QString scene = sceneList();
3204 if (m_mltProducer) {
3205 pos = m_mltProducer->position();
3206 delete m_mltProducer;
3208 m_mltProducer = NULL;
3209 setSceneList(scene, pos);
3212 #include "renderer.moc"