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 if (blackclip) blackclip->set("length", duration);
1419 if (blackclip == NULL || blackclip->is_blank() || blackTrackPlaylist.count() != 1) {
1420 blackTrackPlaylist.clear();
1421 blackTrackPlaylist.append(*m_blackClip, 0, duration - 1);
1422 } else blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1424 m_mltProducer->set("out", duration);
1425 emit durationChanged(duration);
1429 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1431 if (m_mltProducer == NULL) {
1432 kDebug() << "PLAYLIST NOT INITIALISED //////";
1435 Mlt::Producer parentProd(m_mltProducer->parent());
1436 if (parentProd.get_producer() == NULL) {
1437 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1441 Mlt::Service service(parentProd.get_service());
1442 Mlt::Tractor tractor(service);
1443 if (info.track > tractor.count() - 1) {
1444 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1447 mlt_service_lock(service.get_service());
1448 Mlt::Producer trackProducer(tractor.track(info.track));
1449 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1450 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1452 if (element.attribute("speed", "1.0").toDouble() != 1.0 || element.attribute("strobe", "1").toInt() > 1) {
1453 // We want a slowmotion producer
1454 double speed = element.attribute("speed", "1.0").toDouble();
1455 int strobe = element.attribute("strobe", "1").toInt();
1456 QString url = QString::fromUtf8(prod->get("resource"));
1457 url.append('?' + QString::number(speed));
1458 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1459 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1460 if (!slowprod || slowprod->get_producer() == NULL) {
1461 char *tmp = decodedString(url);
1462 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1463 if (strobe > 1) slowprod->set("strobe", strobe);
1465 QString id = prod->get("id");
1466 if (id.contains('_')) id = id.section('_', 0, 0);
1467 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1468 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1469 tmp = decodedString(producerid);
1470 slowprod->set("id", tmp);
1472 m_slowmotionProducers.insert(url, slowprod);
1477 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1478 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), clip, 1);
1480 /*if (QString(prod->get("transparency")).toInt() == 1)
1481 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1483 mlt_service_unlock(service.get_service());
1485 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1486 //tractor.multitrack()->refresh();
1487 //tractor.refresh();
1491 void Render::mltCutClip(int track, GenTime position)
1496 Mlt::Service service(m_mltProducer->parent().get_service());
1497 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1499 Mlt::Tractor tractor(service);
1500 Mlt::Producer trackProducer(tractor.track(track));
1501 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1504 /* // Display playlist info
1505 kDebug()<<"//////////// BEFORE";
1506 for (int i = 0; i < trackPlaylist.count(); i++) {
1507 int blankStart = trackPlaylist.clip_start(i);
1508 int blankDuration = trackPlaylist.clip_length(i) - 1;
1510 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1511 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1514 int cutPos = (int) position.frames(m_fps);
1516 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1517 if (trackPlaylist.is_blank(clipIndex)) {
1518 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1519 m_isBlocked = false;
1522 mlt_service_lock(service.get_service());
1523 int clipStart = trackPlaylist.clip_start(clipIndex);
1524 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1525 mlt_service_unlock(service.get_service());
1527 // duplicate effects
1528 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1529 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1531 if (original == NULL || clip == NULL) {
1532 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1534 Mlt::Service clipService(original->get_service());
1535 Mlt::Service dupService(clip->get_service());
1539 Mlt::Filter *filter = clipService.filter(ct);
1541 // Only duplicate Kdenlive filters, and skip the fade in effects
1542 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1543 // looks like there is no easy way to duplicate a filter,
1544 // so we will create a new one and duplicate its properties
1545 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1546 if (dup && dup->is_valid()) {
1547 Mlt::Properties entries(filter->get_properties());
1548 for (int i = 0; i < entries.count(); i++) {
1549 dup->set(entries.get_name(i), entries.get(i));
1551 dupService.attach(*dup);
1555 filter = clipService.filter(ct);
1558 /* // Display playlist info
1559 kDebug()<<"//////////// AFTER";
1560 for (int i = 0; i < trackPlaylist.count(); i++) {
1561 int blankStart = trackPlaylist.clip_start(i);
1562 int blankDuration = trackPlaylist.clip_length(i) - 1;
1564 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1565 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1568 m_isBlocked = false;
1571 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1574 mltRemoveClip(info.track, info.startPos);
1575 mltInsertClip(info, element, prod);
1579 bool Render::mltRemoveClip(int track, GenTime position)
1581 Mlt::Service service(m_mltProducer->parent().get_service());
1582 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1584 Mlt::Tractor tractor(service);
1585 mlt_service_lock(service.get_service());
1586 Mlt::Producer trackProducer(tractor.track(track));
1587 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1588 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1590 // Display playlist info
1591 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1592 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1593 int blankStart = trackPlaylist.clip_start(i);
1594 int blankDuration = trackPlaylist.clip_length(i) - 1;
1596 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1597 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1599 if (trackPlaylist.is_blank(clipIndex)) {
1600 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1601 mlt_service_unlock(service.get_service());
1604 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1606 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1608 trackPlaylist.consolidate_blanks(0);
1609 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1610 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1612 /* // Display playlist info
1613 kDebug()<<"//// AFTER";
1614 for (int i = 0; i < trackPlaylist.count(); i++) {
1615 int blankStart = trackPlaylist.clip_start(i);
1616 int blankDuration = trackPlaylist.clip_length(i) - 1;
1618 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1619 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1621 mlt_service_unlock(service.get_service());
1622 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1623 m_isBlocked = false;
1627 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1629 if (!m_mltProducer) {
1630 kDebug() << "PLAYLIST NOT INITIALISED //////";
1633 Mlt::Producer parentProd(m_mltProducer->parent());
1634 if (parentProd.get_producer() == NULL) {
1635 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1639 Mlt::Service service(parentProd.get_service());
1640 Mlt::Tractor tractor(service);
1641 int insertPos = pos.frames(m_fps);
1643 Mlt::Producer trackProducer(tractor.track(track));
1644 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1645 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1646 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1647 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1648 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1651 int Render::mltTrackDuration(int track)
1653 if (!m_mltProducer) {
1654 kDebug() << "PLAYLIST NOT INITIALISED //////";
1657 Mlt::Producer parentProd(m_mltProducer->parent());
1658 if (parentProd.get_producer() == NULL) {
1659 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1663 Mlt::Service service(parentProd.get_service());
1664 Mlt::Tractor tractor(service);
1666 Mlt::Producer trackProducer(tractor.track(track));
1667 return trackProducer.get_playtime() - 1;
1670 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1672 if (!m_mltProducer) {
1673 kDebug() << "PLAYLIST NOT INITIALISED //////";
1676 Mlt::Producer parentProd(m_mltProducer->parent());
1677 if (parentProd.get_producer() == NULL) {
1678 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1681 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1682 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1684 Mlt::Service service(parentProd.get_service());
1685 Mlt::Tractor tractor(service);
1686 mlt_service_lock(service.get_service());
1687 int diff = duration.frames(m_fps);
1688 int offset = timeOffset.frames(m_fps);
1692 // insert space in one track only
1693 Mlt::Producer trackProducer(tractor.track(track));
1694 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1695 insertPos = trackClipStartList.value(track);
1696 if (insertPos != -1) {
1697 insertPos += offset;
1698 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1699 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1701 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1702 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1703 int position = trackPlaylist.clip_start(clipIndex);
1704 int blankDuration = trackPlaylist.clip_length(clipIndex);
1706 if (blankDuration - diff == 0)
1707 trackPlaylist.remove(clipIndex);
1708 else trackPlaylist.remove_region(position, diff);
1710 trackPlaylist.consolidate_blanks(0);
1712 // now move transitions
1713 mlt_service serv = m_mltProducer->parent().get_service();
1714 mlt_service nextservice = mlt_service_get_producer(serv);
1715 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1716 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1717 QString resource = mlt_properties_get(properties, "mlt_service");
1719 while (mlt_type == "transition") {
1720 mlt_transition tr = (mlt_transition) nextservice;
1721 int currentTrack = mlt_transition_get_b_track(tr);
1722 int currentIn = (int) mlt_transition_get_in(tr);
1723 int currentOut = (int) mlt_transition_get_out(tr);
1724 insertPos = trackTransitionStartList.value(track);
1725 if (insertPos != -1) {
1726 insertPos += offset;
1727 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1728 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1731 nextservice = mlt_service_producer(nextservice);
1732 if (nextservice == NULL) break;
1733 properties = MLT_SERVICE_PROPERTIES(nextservice);
1734 mlt_type = mlt_properties_get(properties, "mlt_type");
1735 resource = mlt_properties_get(properties, "mlt_service");
1738 int trackNb = tractor.count();
1739 while (trackNb > 1) {
1740 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1741 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1744 //int clipNb = trackPlaylist.count();
1745 insertPos = trackClipStartList.value(trackNb - 1);
1746 if (insertPos != -1) {
1747 insertPos += offset;
1749 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1750 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1751 for (int i = 0; i < clipNb; i++) {
1752 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1753 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1754 kDebug()<<"-------------";
1756 kDebug()<<"END-------------";*/
1759 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1760 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1762 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1763 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1764 int position = trackPlaylist.clip_start(clipIndex);
1765 int blankDuration = trackPlaylist.clip_length(clipIndex);
1766 if (diff + blankDuration == 0)
1767 trackPlaylist.remove(clipIndex);
1768 else trackPlaylist.remove_region(position, - diff);
1770 trackPlaylist.consolidate_blanks(0);
1774 // now move transitions
1775 mlt_service serv = m_mltProducer->parent().get_service();
1776 mlt_service nextservice = mlt_service_get_producer(serv);
1777 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1778 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1779 QString resource = mlt_properties_get(properties, "mlt_service");
1781 while (mlt_type == "transition") {
1782 mlt_transition tr = (mlt_transition) nextservice;
1783 int currentIn = (int) mlt_transition_get_in(tr);
1784 int currentOut = (int) mlt_transition_get_out(tr);
1785 int currentTrack = mlt_transition_get_b_track(tr);
1786 insertPos = trackTransitionStartList.value(currentTrack);
1787 if (insertPos != -1) {
1788 insertPos += offset;
1789 if (currentOut > insertPos && resource != "mix") {
1790 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1793 nextservice = mlt_service_producer(nextservice);
1794 if (nextservice == NULL) break;
1795 properties = MLT_SERVICE_PROPERTIES(nextservice);
1796 mlt_type = mlt_properties_get(properties, "mlt_type");
1797 resource = mlt_properties_get(properties, "mlt_service");
1800 mlt_service_unlock(service.get_service());
1802 m_mltConsumer->set("refresh", 1);
1806 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1808 Mlt::Service sourceService(source->get_service());
1809 Mlt::Service destService(dest->get_service());
1811 // move all effects to the correct producer
1813 Mlt::Filter *filter = sourceService.filter(ct);
1815 if (filter->get("kdenlive_ix") != 0) {
1816 sourceService.detach(*filter);
1817 destService.attach(*filter);
1819 filter = sourceService.filter(ct);
1823 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, int strobe, Mlt::Producer *prod)
1827 Mlt::Service service(m_mltProducer->parent().get_service());
1828 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1829 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1830 Mlt::Tractor tractor(service);
1831 Mlt::Producer trackProducer(tractor.track(info.track));
1832 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1833 int startPos = info.startPos.frames(m_fps);
1834 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1835 int clipLength = trackPlaylist.clip_length(clipIndex);
1837 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1841 if (!clip->is_valid() || clip->is_blank()) {
1846 Mlt::Producer clipparent = clip->parent();
1847 if (!clipparent.is_valid() || clipparent.is_blank()) {
1853 QString serv = clipparent.get("mlt_service");
1854 QString id = clipparent.get("id");
1855 //kDebug() << "CLIP SERVICE: " << serv;
1856 if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
1857 mlt_service_lock(service.get_service());
1858 QString url = QString::fromUtf8(clipparent.get("resource"));
1859 url.append('?' + QString::number(speed));
1860 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1861 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1862 if (!slowprod || slowprod->get_producer() == NULL) {
1863 char *tmp = decodedString(url);
1864 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1865 if (strobe > 1) slowprod->set("strobe", strobe);
1867 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1868 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1869 tmp = decodedString(producerid);
1870 slowprod->set("id", tmp);
1872 m_slowmotionProducers.insert(url, slowprod);
1874 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1876 trackPlaylist.consolidate_blanks(0);
1877 // Check that the blank space is long enough for our new duration
1878 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1879 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1881 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1882 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1883 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1884 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1886 // move all effects to the correct producer
1887 mltPasteEffects(clip, cut);
1889 trackPlaylist.insert_at(startPos, cut, 1);
1891 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1892 newLength = trackPlaylist.clip_length(clipIndex);
1893 mlt_service_unlock(service.get_service());
1894 } else if (speed == 1.0 && strobe < 2) {
1895 mlt_service_lock(service.get_service());
1897 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1899 trackPlaylist.consolidate_blanks(0);
1901 // Check that the blank space is long enough for our new duration
1902 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1903 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1906 GenTime oldDuration = GenTime(clipLength, m_fps);
1907 GenTime newDuration = oldDuration * oldspeed;
1908 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1909 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1910 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1911 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1913 // move all effects to the correct producer
1914 mltPasteEffects(clip, cut);
1916 trackPlaylist.insert_at(startPos, cut, 1);
1918 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1919 newLength = trackPlaylist.clip_length(clipIndex);
1920 mlt_service_unlock(service.get_service());
1922 } else if (serv == "framebuffer") {
1923 mlt_service_lock(service.get_service());
1924 QString url = QString::fromUtf8(clipparent.get("resource"));
1925 url = url.section('?', 0, 0);
1926 url.append('?' + QString::number(speed));
1927 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1928 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1929 if (!slowprod || slowprod->get_producer() == NULL) {
1930 char *tmp = decodedString(url);
1931 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1933 slowprod->set("strobe", strobe);
1934 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1935 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1936 tmp = decodedString(producerid);
1937 slowprod->set("id", tmp);
1939 m_slowmotionProducers.insert(url, slowprod);
1941 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1943 trackPlaylist.consolidate_blanks(0);
1945 GenTime oldDuration = GenTime(clipLength, m_fps);
1946 GenTime newDuration = oldDuration * (oldspeed / speed);
1948 // Check that the blank space is long enough for our new duration
1949 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1950 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1953 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1954 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1955 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1956 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1958 // move all effects to the correct producer
1959 mltPasteEffects(clip, cut);
1961 trackPlaylist.insert_at(startPos, cut, 1);
1963 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1964 newLength = trackPlaylist.clip_length(clipIndex);
1966 mlt_service_unlock(service.get_service());
1970 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1971 m_isBlocked = false;
1975 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
1977 Mlt::Service service(m_mltProducer->parent().get_service());
1978 bool success = false;
1979 Mlt::Tractor tractor(service);
1980 Mlt::Producer trackProducer(tractor.track(track));
1981 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1982 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1983 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1985 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1988 Mlt::Service clipService(clip->get_service());
1990 // if (tag.startsWith("ladspa")) tag = "ladspa";
1993 Mlt::Filter *filter = clipService.filter(ct);
1995 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1996 if (clipService.detach(*filter) == 0) success = true;
1997 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
1998 } else if (updateIndex) {
1999 // Adjust the other effects index
2000 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2003 filter = clipService.filter(ct);
2005 m_isBlocked = false;
2006 if (doRefresh) refresh();
2011 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2014 Mlt::Service service(m_mltProducer->parent().get_service());
2016 Mlt::Tractor tractor(service);
2017 Mlt::Producer trackProducer(tractor.track(track));
2018 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2020 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2024 Mlt::Service clipService(clip->get_service());
2027 // temporarily remove all effects after insert point
2028 QList <Mlt::Filter *> filtersList;
2029 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2031 Mlt::Filter *filter = clipService.filter(ct);
2033 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
2034 filtersList.append(filter);
2035 clipService.detach(*filter);
2037 filter = clipService.filter(ct);
2041 QString tag = params.paramValue("tag");
2042 kDebug() << " / / INSERTING EFFECT: " << tag;
2043 if (tag.startsWith("ladspa")) tag = "ladspa";
2044 char *filterTag = decodedString(tag);
2045 char *filterId = decodedString(params.paramValue("id"));
2046 QHash<QString, QString>::Iterator it;
2047 QString kfr = params.paramValue("keyframes");
2049 if (!kfr.isEmpty()) {
2050 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2051 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2052 char *starttag = decodedString(params.paramValue("starttag", "start"));
2053 char *endtag = decodedString(params.paramValue("endtag", "end"));
2054 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2055 int duration = clip->get_playtime();
2056 //double max = params.paramValue("max").toDouble();
2057 double min = params.paramValue("min").toDouble();
2058 double factor = params.paramValue("factor", "1").toDouble();
2059 params.removeParam("starttag");
2060 params.removeParam("endtag");
2061 params.removeParam("keyframes");
2062 params.removeParam("min");
2063 params.removeParam("max");
2064 params.removeParam("factor");
2066 for (int i = 0; i < keyFrames.size() - 1; ++i) {
2067 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2068 if (filter && filter->is_valid()) {
2069 filter->set("kdenlive_id", filterId);
2070 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2071 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2072 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2073 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2074 if (x2 == -1) x2 = duration;
2076 for (int j = 0; j < params.count(); j++) {
2077 char *name = decodedString(params.at(j).name());
2078 char *value = decodedString(params.at(j).value());
2079 filter->set(name, value);
2084 filter->set("in", x1);
2085 filter->set("out", x2);
2086 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2087 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2088 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2089 clipService.attach(*filter);
2096 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2097 if (filter && filter->is_valid())
2098 filter->set("kdenlive_id", filterId);
2100 kDebug() << "filter is NULL";
2101 m_isBlocked = false;
2105 params.removeParam("kdenlive_id");
2107 for (int j = 0; j < params.count(); j++) {
2108 char *name = decodedString(params.at(j).name());
2109 char *value = decodedString(params.at(j).value());
2110 filter->set(name, value);
2116 QString effectArgs = params.paramValue("id").section('_', 1);
2118 params.removeParam("id");
2119 params.removeParam("kdenlive_ix");
2120 params.removeParam("tag");
2121 params.removeParam("disabled");
2123 for (int j = 0; j < params.count(); j++) {
2124 effectArgs.append(' ' + params.at(j).value());
2126 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2127 char *value = decodedString(effectArgs.simplified());
2128 filter->set("effect", value);
2133 // attach filter to the clip
2134 clipService.attach(*filter);
2139 // re-add following filters
2140 for (int i = 0; i < filtersList.count(); i++) {
2141 clipService.attach(*(filtersList.at(i)));
2144 m_isBlocked = false;
2145 if (doRefresh) refresh();
2149 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2151 QString index = params.paramValue("kdenlive_ix");
2152 QString tag = params.paramValue("tag");
2154 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2155 // This is a keyframe effect, to edit it, we remove it and re-add it.
2156 mltRemoveEffect(track, position, index, false);
2157 bool success = mltAddEffect(track, position, params);
2162 Mlt::Service service(m_mltProducer->parent().get_service());
2164 Mlt::Tractor tractor(service);
2165 Mlt::Producer trackProducer(tractor.track(track));
2166 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2167 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2168 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2170 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2173 Mlt::Service clipService(clip->get_service());
2177 Mlt::Filter *filter = clipService.filter(ct);
2179 if (filter->get("kdenlive_ix") == index) {
2183 filter = clipService.filter(ct);
2187 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2188 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2190 filter = clipService.filter(ct);
2191 QList <Mlt::Filter *> filtersList;
2193 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2194 filtersList.append(filter);
2195 clipService.detach(*filter);
2197 filter = clipService.filter(ct);
2199 bool success = mltAddEffect(track, position, params);
2201 for (int i = 0; i < filtersList.count(); i++) {
2202 clipService.attach(*(filtersList.at(i)));
2205 m_isBlocked = false;
2208 mlt_service_lock(service.get_service());
2209 for (int j = 0; j < params.count(); j++) {
2210 char *name = decodedString(params.at(j).name());
2211 char *value = decodedString(params.at(j).value());
2212 filter->set(name, value);
2216 mlt_service_unlock(service.get_service());
2218 m_isBlocked = false;
2223 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2226 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2227 Mlt::Service service(m_mltProducer->parent().get_service());
2229 Mlt::Tractor tractor(service);
2230 Mlt::Producer trackProducer(tractor.track(track));
2231 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2232 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2233 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2235 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2238 Mlt::Service clipService(clip->get_service());
2242 QList <Mlt::Filter *> filtersList;
2243 Mlt::Filter *filter = clipService.filter(ct);
2245 if (newPos > oldPos) {
2247 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2248 filter->set("kdenlive_ix", newPos);
2249 filtersList.append(filter);
2250 clipService.detach(*filter);
2251 filter = clipService.filter(ct);
2252 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2253 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2255 filter = clipService.filter(ct);
2259 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2260 filtersList.append(filter);
2261 clipService.detach(*filter);
2263 filter = clipService.filter(ct);
2267 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2268 filter->set("kdenlive_ix", newPos);
2269 filtersList.append(filter);
2270 clipService.detach(*filter);
2272 filter = clipService.filter(ct);
2276 filter = clipService.filter(ct);
2278 int pos = QString(filter->get("kdenlive_ix")).toInt();
2279 if (pos >= newPos) {
2280 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2281 filtersList.append(filter);
2282 clipService.detach(*filter);
2284 filter = clipService.filter(ct);
2288 for (int i = 0; i < filtersList.count(); i++) {
2289 clipService.attach(*(filtersList.at(i)));
2292 m_isBlocked = false;
2296 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2299 Mlt::Service service(m_mltProducer->parent().get_service());
2300 Mlt::Tractor tractor(service);
2301 Mlt::Producer trackProducer(tractor.track(info.track));
2302 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2304 /* // Display playlist info
2305 kDebug()<<"//////////// BEFORE RESIZE";
2306 for (int i = 0; i < trackPlaylist.count(); i++) {
2307 int blankStart = trackPlaylist.clip_start(i);
2308 int blankDuration = trackPlaylist.clip_length(i) - 1;
2310 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2311 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2314 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2315 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2316 m_isBlocked = false;
2319 mlt_service_lock(service.get_service());
2320 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2321 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2322 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2323 int previousStart = clip->get_in();
2324 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2325 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2326 if (newDuration > clip->get_length()) {
2327 clip->parent().set("length", newDuration + 1);
2328 clip->set("length", newDuration + 1);
2330 if (newDuration > clip->get_out()) {
2331 clip->parent().set_in_and_out(0, newDuration + 1);
2332 clip->set_in_and_out(0, newDuration + 1);
2335 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2336 trackPlaylist.consolidate_blanks(0);
2337 // skip to next clip
2339 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2341 // clip was made longer, trim next blank if there is one.
2342 if (clipIndex < trackPlaylist.count()) {
2343 // If this is not the last clip in playlist
2344 if (trackPlaylist.is_blank(clipIndex)) {
2345 int blankStart = trackPlaylist.clip_start(clipIndex);
2346 int blankDuration = trackPlaylist.clip_length(clipIndex);
2347 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2348 if (diff - blankDuration == 0) {
2349 trackPlaylist.remove(clipIndex);
2350 } else trackPlaylist.remove_region(blankStart, diff);
2352 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2355 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2356 trackPlaylist.consolidate_blanks(0);
2357 mlt_service_unlock(service.get_service());
2359 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2360 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2361 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2362 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2363 ItemInfo transpinfo;
2364 transpinfo.startPos = info.startPos;
2365 transpinfo.endPos = info.startPos + clipDuration;
2366 transpinfo.track = info.track;
2367 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2369 m_isBlocked = false;
2370 m_mltConsumer->set("refresh", 1);
2374 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2376 Mlt::Service service(m_mltProducer->parent().get_service());
2377 Mlt::Tractor tractor(service);
2378 Mlt::Producer trackProducer(tractor.track(track));
2381 if (blind) trackProducer.set("hide", 3);
2382 else trackProducer.set("hide", 2);
2384 trackProducer.set("hide", 1);
2386 trackProducer.set("hide", 0);
2388 tractor.multitrack()->refresh();
2394 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2396 Mlt::Service service(m_mltProducer->parent().get_service());
2397 int frameOffset = (int) diff.frames(m_fps);
2398 Mlt::Tractor tractor(service);
2399 Mlt::Producer trackProducer(tractor.track(info.track));
2400 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2401 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2402 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2405 mlt_service_lock(service.get_service());
2406 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2407 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2409 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2410 mlt_service_unlock(service.get_service());
2413 int previousStart = clip->get_in();
2415 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2417 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2418 m_isBlocked = false;
2419 mlt_service_unlock(service.get_service());
2420 m_mltConsumer->set("refresh", 1);
2424 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2426 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2427 Mlt::Service service(m_mltProducer->parent().get_service());
2428 int moveFrame = (int) diff.frames(m_fps);
2429 Mlt::Tractor tractor(service);
2430 Mlt::Producer trackProducer(tractor.track(info.track));
2431 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2432 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2433 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2436 mlt_service_lock(service.get_service());
2437 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2438 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2440 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2441 mlt_service_unlock(service.get_service());
2444 int previousStart = clip->get_in();
2446 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2448 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2449 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2450 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2452 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2453 int blankIndex = clipIndex - 1;
2454 int blankLength = trackPlaylist.clip_length(blankIndex);
2455 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2456 if (! trackPlaylist.is_blank(blankIndex)) {
2457 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2459 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2460 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2462 trackPlaylist.consolidate_blanks(0);
2463 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2464 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2465 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2466 ItemInfo transpinfo;
2467 transpinfo.startPos = info.startPos + diff;
2468 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2469 transpinfo.track = info.track;
2470 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2472 m_isBlocked = false;
2473 //m_mltConsumer->set("refresh", 1);
2474 mlt_service_unlock(service.get_service());
2475 m_mltConsumer->set("refresh", 1);
2479 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2481 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2485 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2487 if (prod == NULL || !prod->is_valid()) {
2488 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2491 kDebug() << "NEW PROD ID: " << prod->get("id");
2493 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2494 mlt_service_lock(m_mltConsumer->get_service());
2495 Mlt::Service service(m_mltProducer->parent().get_service());
2496 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2498 Mlt::Tractor tractor(service);
2499 Mlt::Producer trackProducer(tractor.track(track));
2500 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2501 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2502 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2503 if (clipProducer->is_blank()) {
2504 kDebug() << "// ERROR UPDATING CLIP PROD";
2505 delete clipProducer;
2506 mlt_service_unlock(m_mltConsumer->get_service());
2510 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2512 // move all effects to the correct producer
2513 mltPasteEffects(clipProducer, clip);
2514 trackPlaylist.insert_at(pos, clip, 1);
2516 delete clipProducer;
2517 mlt_service_unlock(m_mltConsumer->get_service());
2521 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2525 Mlt::Service service(m_mltProducer->parent().get_service());
2526 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2528 Mlt::Tractor tractor(service);
2529 mlt_service_lock(service.get_service());
2530 Mlt::Producer trackProducer(tractor.track(startTrack));
2531 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2532 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
2533 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2534 bool checkLength = false;
2535 if (endTrack == startTrack) {
2536 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2537 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer->is_blank()) {
2538 // error, destination is not empty
2539 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2540 delete clipProducer;
2541 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2542 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2543 mlt_service_unlock(service.get_service());
2547 trackPlaylist.consolidate_blanks(0);
2548 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2549 delete clipProducer;
2550 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2551 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2553 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2555 //mlt_service_unlock(service.get_service());
2557 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2558 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2559 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2560 // error, destination is not empty
2561 mlt_service_unlock(service.get_service());
2565 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2566 if (clipProducer->is_blank()) {
2567 // error, destination is not empty
2568 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2569 delete clipProducer;
2570 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2571 mlt_service_unlock(service.get_service());
2575 trackPlaylist.consolidate_blanks(0);
2576 destTrackPlaylist.consolidate_blanks(1);
2577 Mlt::Producer *clip;
2578 // check if we are moving a slowmotion producer
2579 QString serv = clipProducer->parent().get("mlt_service");
2580 QString currentid = clipProducer->parent().get("id");
2581 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2582 clip = clipProducer;
2585 // Special case: prod is null when using placeholder clips.
2586 // in that case, use the producer existing in playlist. Note that
2587 // it will bypass the one producer per track logic and might cause
2588 // Sound cracks if clip is moved so that it overlaps another copy of itself
2589 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
2590 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2593 // move all effects to the correct producer
2594 mltPasteEffects(clipProducer, clip);
2596 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2599 if (clipProducer) delete clipProducer;
2600 destTrackPlaylist.consolidate_blanks(0);
2601 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2602 kDebug() << "//////// moving clip transparency";
2603 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2605 if (clipIndex > trackPlaylist.count()) checkLength = true;
2606 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2609 mlt_service_unlock(service.get_service());
2610 if (checkLength) mltCheckLength();
2613 //m_mltConsumer->set("refresh", 1);
2617 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2619 int new_in = (int)newIn.frames(m_fps);
2620 int new_out = (int)newOut.frames(m_fps) - 1;
2621 if (new_in >= new_out) return false;
2623 mlt_service serv = m_mltProducer->parent().get_service();
2625 mlt_service_lock(serv);
2626 //m_mltConsumer->set("refresh", 0);
2629 mlt_service nextservice = mlt_service_get_producer(serv);
2630 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2631 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2632 QString resource = mlt_properties_get(properties, "mlt_service");
2633 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2635 while (mlt_type == "transition") {
2636 mlt_transition tr = (mlt_transition) nextservice;
2637 int currentTrack = mlt_transition_get_b_track(tr);
2638 int currentIn = (int) mlt_transition_get_in(tr);
2639 int currentOut = (int) mlt_transition_get_out(tr);
2641 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2642 mlt_transition_set_in_and_out(tr, new_in, new_out);
2643 if (newTrack - startTrack != 0) {
2644 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2646 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2647 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2648 mlt_properties_set_int(properties, "b_track", newTrack);
2649 //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);
2653 nextservice = mlt_service_producer(nextservice);
2654 if (nextservice == NULL) break;
2655 properties = MLT_SERVICE_PROPERTIES(nextservice);
2656 mlt_type = mlt_properties_get(properties, "mlt_type");
2657 resource = mlt_properties_get(properties, "mlt_service");
2659 mlt_service_unlock(serv);
2662 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2666 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2668 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2670 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2671 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
2674 //mltSavePlaylist();
2677 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2679 mlt_service serv = m_mltProducer->parent().get_service();
2680 mlt_service_lock(serv);
2683 mlt_service nextservice = mlt_service_get_producer(serv);
2684 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2685 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2686 QString resource = mlt_properties_get(properties, "mlt_service");
2687 int in_pos = (int) in.frames(m_fps);
2688 int out_pos = (int) out.frames(m_fps) - 1;
2690 while (mlt_type == "transition") {
2691 mlt_transition tr = (mlt_transition) nextservice;
2692 int currentTrack = mlt_transition_get_b_track(tr);
2693 int currentBTrack = mlt_transition_get_a_track(tr);
2694 int currentIn = (int) mlt_transition_get_in(tr);
2695 int currentOut = (int) mlt_transition_get_out(tr);
2697 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2699 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2700 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2701 QMap<QString, QString>::Iterator it;
2703 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2704 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2705 // update the transition id in case it uses the same MLT service but different Kdenlive id
2706 char *tmp = decodedString(xml.attribute("id"));
2707 mlt_properties_set(transproperties, "kdenlive_id", tmp);
2709 if (currentBTrack != a_track) {
2710 mlt_properties_set_int(properties, "a_track", a_track);
2712 for (it = map.begin(); it != map.end(); ++it) {
2714 char *name = decodedString(key);
2715 char *value = decodedString(it.value());
2716 mlt_properties_set(transproperties, name, value);
2717 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2718 //filter->set("kdenlive_id", id);
2724 nextservice = mlt_service_producer(nextservice);
2725 if (nextservice == NULL) break;
2726 properties = MLT_SERVICE_PROPERTIES(nextservice);
2727 mlt_type = mlt_properties_get(properties, "mlt_type");
2728 resource = mlt_properties_get(properties, "mlt_service");
2730 mlt_service_unlock(serv);
2733 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2736 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2738 mlt_service serv = m_mltProducer->parent().get_service();
2740 mlt_service_lock(serv);
2742 Mlt::Service service(serv);
2743 Mlt::Tractor tractor(service);
2744 Mlt::Field *field = tractor.field();
2746 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2748 mlt_service nextservice = mlt_service_get_producer(serv);
2749 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2750 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2751 QString resource = mlt_properties_get(properties, "mlt_service");
2753 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2754 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2756 while (mlt_type == "transition") {
2757 mlt_transition tr = (mlt_transition) nextservice;
2758 int currentTrack = mlt_transition_get_b_track(tr);
2759 int currentIn = (int) mlt_transition_get_in(tr);
2760 int currentOut = (int) mlt_transition_get_out(tr);
2761 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2763 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2764 mlt_field_disconnect_service(field->get_field(), nextservice);
2767 nextservice = mlt_service_producer(nextservice);
2768 if (nextservice == NULL) break;
2769 properties = MLT_SERVICE_PROPERTIES(nextservice);
2770 mlt_type = mlt_properties_get(properties, "mlt_type");
2771 resource = mlt_properties_get(properties, "mlt_service");
2773 mlt_service_unlock(serv);
2776 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2779 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2781 QDomNodeList attribs = xml.elementsByTagName("parameter");
2782 QMap<QString, QString> map;
2783 for (int i = 0; i < attribs.count(); i++) {
2784 QDomElement e = attribs.item(i).toElement();
2785 QString name = e.attribute("name");
2786 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2787 map[name] = e.attribute("default");
2788 if (!e.attribute("value").isEmpty()) {
2789 map[name] = e.attribute("value");
2791 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2792 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2793 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2796 if (e.attribute("namedesc").contains(';')) {
2797 QString format = e.attribute("format");
2798 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2799 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2801 QTextStream txtNeu(&neu);
2802 if (values.size() > 0)
2803 txtNeu << (int)values[0].toDouble();
2805 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
2806 txtNeu << separators[i];
2807 txtNeu << (int)(values[i+1].toDouble());
2809 if (i < separators.size())
2810 txtNeu << separators[i];
2811 map[e.attribute("name")] = neu;
2818 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2820 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2821 Mlt::Service service(m_mltProducer->parent().get_service());
2822 Mlt::Tractor tractor(service);
2823 Mlt::Field *field = tractor.field();
2825 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2826 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2827 transition->set("transparency", id);
2828 transition->set("fill", 1);
2829 transition->set("internal_added", 237);
2830 field->plant_transition(*transition, transitiontrack, info.track);
2834 void Render::mltDeleteTransparency(int pos, int track, int id)
2836 Mlt::Service service(m_mltProducer->parent().get_service());
2837 Mlt::Tractor tractor(service);
2838 Mlt::Field *field = tractor.field();
2840 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2841 mlt_service serv = m_mltProducer->parent().get_service();
2843 mlt_service nextservice = mlt_service_get_producer(serv);
2844 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2845 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2846 QString resource = mlt_properties_get(properties, "mlt_service");
2848 while (mlt_type == "transition") {
2849 mlt_transition tr = (mlt_transition) nextservice;
2850 int currentTrack = mlt_transition_get_b_track(tr);
2851 int currentIn = (int) mlt_transition_get_in(tr);
2852 int currentOut = (int) mlt_transition_get_out(tr);
2853 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2854 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2856 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2857 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2858 mlt_field_disconnect_service(field->get_field(), nextservice);
2861 nextservice = mlt_service_producer(nextservice);
2862 if (nextservice == NULL) break;
2863 properties = MLT_SERVICE_PROPERTIES(nextservice);
2864 mlt_type = mlt_properties_get(properties, "mlt_type");
2865 resource = mlt_properties_get(properties, "mlt_service");
2867 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2870 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2872 Mlt::Service service(m_mltProducer->parent().get_service());
2873 Mlt::Tractor tractor(service);
2875 mlt_service_lock(service.get_service());
2876 m_mltConsumer->set("refresh", 0);
2879 mlt_service serv = m_mltProducer->parent().get_service();
2880 mlt_service nextservice = mlt_service_get_producer(serv);
2881 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2882 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2883 QString resource = mlt_properties_get(properties, "mlt_service");
2884 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2885 while (mlt_type == "transition") {
2886 mlt_transition tr = (mlt_transition) nextservice;
2887 int currentTrack = mlt_transition_get_b_track(tr);
2888 int currentIn = (int) mlt_transition_get_in(tr);
2889 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2890 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2891 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2892 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2893 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2894 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2897 nextservice = mlt_service_producer(nextservice);
2898 if (nextservice == NULL) break;
2899 properties = MLT_SERVICE_PROPERTIES(nextservice);
2900 mlt_type = mlt_properties_get(properties, "mlt_type");
2901 resource = mlt_properties_get(properties, "mlt_service");
2903 mlt_service_unlock(service.get_service());
2905 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2909 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
2911 Mlt::Service service(m_mltProducer->parent().get_service());
2912 Mlt::Tractor tractor(service);
2914 mlt_service_lock(service.get_service());
2915 m_mltConsumer->set("refresh", 0);
2918 mlt_service serv = m_mltProducer->parent().get_service();
2919 mlt_service nextservice = mlt_service_get_producer(serv);
2920 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2921 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2922 QString resource = mlt_properties_get(properties, "mlt_service");
2924 while (mlt_type == "transition") {
2925 mlt_transition tr = (mlt_transition) nextservice;
2926 int currentTrack = mlt_transition_get_b_track(tr);
2927 int currentaTrack = mlt_transition_get_a_track(tr);
2928 int currentIn = (int) mlt_transition_get_in(tr);
2929 int currentOut = (int) mlt_transition_get_out(tr);
2930 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2931 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2932 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2933 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2934 kDebug() << "//////MOVING";
2935 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2936 if (endTrack != startTrack) {
2937 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2938 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2939 mlt_properties_set_int(properties, "b_track", endTrack);
2943 nextservice = mlt_service_producer(nextservice);
2944 if (nextservice == NULL) break;
2945 properties = MLT_SERVICE_PROPERTIES(nextservice);
2946 mlt_type = mlt_properties_get(properties, "mlt_type");
2947 resource = mlt_properties_get(properties, "mlt_service");
2950 mlt_service_unlock(service.get_service());
2951 m_mltConsumer->set("refresh", 1);
2955 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
2957 if (in >= out) return false;
2958 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2959 Mlt::Service service(m_mltProducer->parent().get_service());
2961 Mlt::Tractor tractor(service);
2962 Mlt::Field *field = tractor.field();
2964 char *transId = decodedString(tag);
2965 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2966 if (out != GenTime())
2967 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2968 QMap<QString, QString>::Iterator it;
2970 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2971 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2972 if (xml.hasAttribute("id"))
2973 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
2975 for (it = args.begin(); it != args.end(); ++it) {
2977 char *name = decodedString(key);
2978 char *value = decodedString(it.value());
2979 if (it.value().isEmpty() == false) transition->set(name, value);
2980 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2984 // attach filter to the clip
2985 field->plant_transition(*transition, a_track, b_track);
2987 if (do_refresh) refresh();
2991 void Render::mltSavePlaylist()
2993 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2994 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
2995 fileConsumer.set("resource", "/tmp/playlist.mlt");
2997 Mlt::Service service(m_mltProducer->get_service());
2999 fileConsumer.connect(service);
3000 fileConsumer.start();
3003 QList <Mlt::Producer *> Render::producersList()
3005 QList <Mlt::Producer *> prods;
3006 if (m_mltProducer == NULL) return prods;
3007 Mlt::Service service(m_mltProducer->parent().get_service());
3008 if (service.type() != tractor_type) return prods;
3009 Mlt::Tractor tractor(service);
3012 int trackNb = tractor.count();
3013 for (int t = 1; t < trackNb; t++) {
3014 Mlt::Producer *tt = tractor.track(t);
3015 Mlt::Producer trackProducer(tt);
3017 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3018 int clipNb = trackPlaylist.count();
3019 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3020 for (int i = 0; i < clipNb; i++) {
3021 Mlt::Producer *c = trackPlaylist.get_clip(i);
3022 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3024 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3025 ids.append(nprod->get("id"));
3026 prods.append(nprod);
3027 } else delete nprod;
3035 void Render::fillSlowMotionProducers()
3037 if (m_mltProducer == NULL) return;
3038 Mlt::Service service(m_mltProducer->parent().get_service());
3039 if (service.type() != tractor_type) return;
3041 Mlt::Tractor tractor(service);
3043 int trackNb = tractor.count();
3044 for (int t = 1; t < trackNb; t++) {
3045 Mlt::Producer *tt = tractor.track(t);
3046 Mlt::Producer trackProducer(tt);
3048 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3049 int clipNb = trackPlaylist.count();
3050 for (int i = 0; i < clipNb; i++) {
3051 Mlt::Producer *c = trackPlaylist.get_clip(i);
3052 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3054 QString id = nprod->get("id");
3055 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3056 // this is a slowmotion producer, add it to the list
3057 QString url = QString::fromUtf8(nprod->get("resource"));
3058 int strobe = nprod->get_int("strobe");
3059 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3060 if (!m_slowmotionProducers.contains(url)) {
3061 m_slowmotionProducers.insert(url, nprod);
3063 } else delete nprod;
3070 void Render::mltInsertTrack(int ix, bool videoTrack)
3075 Mlt::Service service(m_mltProducer->parent().get_service());
3076 mlt_service_lock(service.get_service());
3077 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
3079 Mlt::Tractor tractor(service);
3081 Mlt::Playlist playlist;
3082 int ct = tractor.count();
3084 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3090 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3091 tractor.set_track(playlist, pos);
3092 Mlt::Producer newProd(tractor.track(pos));
3093 if (!videoTrack) newProd.set("hide", 1);
3095 for (; pos <= ct; pos++) {
3096 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3097 tractor.set_track(*prodToMove, pos);
3098 prodToMove = prodToMove2;
3101 tractor.set_track(playlist, ix);
3102 Mlt::Producer newProd(tractor.track(ix));
3103 if (!videoTrack) newProd.set("hide", 1);
3107 mlt_service serv = m_mltProducer->parent().get_service();
3108 mlt_service nextservice = mlt_service_get_producer(serv);
3109 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3110 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3111 QString resource = mlt_properties_get(properties, "mlt_service");
3113 while (mlt_type == "transition") {
3114 if (resource != "mix") {
3115 mlt_transition tr = (mlt_transition) nextservice;
3116 int currentTrack = mlt_transition_get_b_track(tr);
3117 int currentaTrack = mlt_transition_get_a_track(tr);
3118 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3120 if (currentTrack >= ix) {
3121 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3122 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3125 nextservice = mlt_service_producer(nextservice);
3126 if (nextservice == NULL) break;
3127 properties = MLT_SERVICE_PROPERTIES(nextservice);
3128 mlt_type = mlt_properties_get(properties, "mlt_type");
3129 resource = mlt_properties_get(properties, "mlt_service");
3132 // Add audio mix transition to last track
3133 Mlt::Field *field = tractor.field();
3134 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3135 transition->set("a_track", 1);
3136 transition->set("b_track", ct);
3137 transition->set("always_active", 1);
3138 transition->set("internal_added", 237);
3139 transition->set("combine", 1);
3140 field->plant_transition(*transition, 1, ct);
3141 //mlt_service_unlock(m_mltConsumer->get_service());
3142 mlt_service_unlock(service.get_service());
3143 //tractor.multitrack()->refresh();
3144 //tractor.refresh();
3146 blockSignals(false);
3150 void Render::mltDeleteTrack(int ix)
3153 doc.setContent(sceneList(), false);
3154 int tracksCount = doc.elementsByTagName("track").count() - 1;
3155 QDomNode track = doc.elementsByTagName("track").at(ix);
3156 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3157 QDomNodeList transitions = doc.elementsByTagName("transition");
3158 for (int i = 0; i < transitions.count(); i++) {
3159 QDomElement e = transitions.at(i).toElement();
3160 QDomNodeList props = e.elementsByTagName("property");
3161 QMap <QString, QString> mappedProps;
3162 for (int j = 0; j < props.count(); j++) {
3163 QDomElement f = props.at(j).toElement();
3164 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3166 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3167 tractor.removeChild(transitions.at(i));
3169 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3170 // Transition needs to be moved
3171 int a_track = mappedProps.value("a_track").toInt();
3172 int b_track = mappedProps.value("b_track").toInt();
3173 if (a_track > 0 && a_track >= ix) a_track --;
3174 if (b_track > 0 && b_track >= ix) b_track --;
3175 for (int j = 0; j < props.count(); j++) {
3176 QDomElement f = props.at(j).toElement();
3177 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3178 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3183 tractor.removeChild(track);
3184 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3185 setSceneList(doc.toString(), m_framePosition);
3190 void Render::updatePreviewSettings()
3192 kDebug() << "////// RESTARTING CONSUMER";
3193 if (!m_mltConsumer || !m_mltProducer) return;
3194 if (m_mltProducer->get_playtime() == 0) return;
3195 Mlt::Service service(m_mltProducer->parent().get_service());
3196 if (service.type() != tractor_type) return;
3198 //m_mltConsumer->set("refresh", 0);
3199 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3200 m_mltConsumer->purge();
3201 QString scene = sceneList();
3203 if (m_mltProducer) {
3204 pos = m_mltProducer->position();
3205 delete m_mltProducer;
3207 m_mltProducer = NULL;
3208 setSceneList(scene, pos);
3211 #include "renderer.moc"