1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
31 #include <mlt++/Mlt.h>
34 #include <KStandardDirs>
35 #include <KMessageBox>
37 #include <KTemporaryFile>
41 #include <QApplication>
45 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
46 // detect if the producer has finished playing. Is there a better way to do it ?
47 if (self->m_isBlocked) return;
48 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
49 self->emitConsumerStopped();
51 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
55 Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid), m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false), m_isZoneMode(false), m_isLoopMode(false) {
56 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
57 refreshTimer = new QTimer(this);
58 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
60 /*if (rendererName == "project") m_monitorId = 10000;
61 else m_monitorId = 10001;*/
62 osdTimer = new QTimer(this);
63 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
65 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
69 m_mltProducer = m_blackClip->cut(0, 50);
70 m_mltConsumer->connect(*m_mltProducer);
71 m_mltProducer->set_speed(0.0);
79 void Render::closeMlt() {
86 if (m_blackClip) delete m_blackClip;
91 void Render::buildConsumer() {
93 m_activeProfile = KdenliveSettings::current_profile();
94 tmp = decodedString(m_activeProfile);
95 setenv("MLT_PROFILE", tmp, 1);
96 if (m_blackClip) delete m_blackClip;
99 m_mltProfile = new Mlt::Profile(tmp);
102 QString videoDriver = KdenliveSettings::videodrivername();
103 if (!videoDriver.isEmpty()) {
104 if (videoDriver == "x11_noaccel") {
105 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
108 unsetenv("SDL_VIDEO_YUV_HWACCEL");
111 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
113 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
114 m_mltConsumer->set("resize", 1);
115 m_mltConsumer->set("window_id", m_winid);
116 m_mltConsumer->set("terminate_on_pause", 1);
117 m_mltConsumer->set("window_background", decodedString(KdenliveSettings::window_background().name()));
119 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
120 m_mltConsumer->set("rescale", "nearest");
122 QString audioDevice = KdenliveSettings::audiodevicename();
123 if (!audioDevice.isEmpty()) {
124 tmp = decodedString(audioDevice);
125 m_mltConsumer->set("audio_device", tmp);
129 if (!videoDriver.isEmpty()) {
130 tmp = decodedString(videoDriver);
131 m_mltConsumer->set("video_driver", tmp);
135 QString audioDriver = KdenliveSettings::audiodrivername();
136 if (!audioDriver.isEmpty()) {
137 tmp = decodedString(audioDriver);
138 m_mltConsumer->set("audio_driver", tmp);
143 m_mltConsumer->set("progressive", 1);
144 m_mltConsumer->set("audio_buffer", 1024);
145 m_mltConsumer->set("frequency", 48000);
147 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
148 m_blackClip->set("id", "black");
152 int Render::resetProfile() {
153 if (!m_mltConsumer) return 0;
154 if (m_activeProfile == KdenliveSettings::current_profile()) {
155 kDebug() << "reset to same profile, nothing to do";
158 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
159 if (m_isSplitView) slotSplitView(false);
160 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
161 m_mltConsumer->purge();
162 delete m_mltConsumer;
163 m_mltConsumer = NULL;
164 QString scene = sceneList();
167 pos = m_mltProducer->position();
168 delete m_mltProducer;
170 m_mltProducer = NULL;
172 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
173 /*if (m_mltProfile) delete m_mltProfile;
174 m_mltProfile = NULL;*/
178 //kDebug() << "//RESET WITHSCENE: " << scene;
179 setSceneList(scene, pos);
181 /*char *tmp = decodedString(scene);
182 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
184 m_mltProducer = producer;
185 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
186 m_mltProducer->optimise();
187 m_mltProducer->set_speed(0);
190 //delete m_mltProfile;
191 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
192 //mlt_profile prof = m_mltProfile->get_profile();
193 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
194 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
195 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
196 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
198 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
203 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
204 void Render::seek(GenTime time) {
208 m_mltProducer->seek((int)(time.frames(m_fps)));
213 char *Render::decodedString(QString str) {
214 /*QCString fn = QFile::encodeName(str);
215 char *t = new char[fn.length() + 1];
216 strcpy(t, (const char *)fn);*/
218 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
222 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
223 QPixmap pix(width, height);
225 mlt_image_format format = mlt_image_rgb24a;
226 uint8_t *thumb = frame->get_image(format, width, height);
227 QImage image(thumb, width, height, QImage::Format_ARGB32);
229 if (!image.isNull()) {
230 pix = pix.fromImage(image);
232 QPainter painter(&pix);
233 painter.drawRect(0, 0, width - 1, height - 1);
235 } else pix.fill(Qt::black);
239 const int Render::renderWidth() const {
240 return (int)(m_mltProfile->height() * m_mltProfile->dar());
243 const int Render::renderHeight() const {
244 return m_mltProfile->height();
247 QPixmap Render::extractFrame(int frame_position, int width, int height) {
249 width = renderWidth();
250 height = renderHeight();
252 QPixmap pix(width, height);
253 if (!m_mltProducer) {
257 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
260 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
263 if (url.fileName().startsWith(".all.")) { // check for slideshow
264 QString fileType = url.fileName().right(3);
266 QStringList::Iterator it;
268 QDir dir(url.directory());
270 filter << "*." + fileType;
271 filter << "*." + fileType.toUpper();
272 more = dir.entryList(filter, QDir::Files);
273 im.load(url.directory() + '/' + more.at(0));
274 } else im.load(url.path());
275 //pixmap = im.scaled(width, height);
280 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
281 QPixmap pix(width, height);
282 char *tmp = decodedString(file);
283 Mlt::Profile *prof = new Mlt::Profile(profile);
284 Mlt::Producer m_producer(*prof, tmp);
286 if (m_producer.is_blank()) {
291 Mlt::Filter m_convert(*prof, "avcolour_space");
292 m_convert.set("forced", mlt_image_rgb24a);
293 m_producer.attach(m_convert);
294 m_producer.seek(frame_position);
295 Mlt::Frame * frame = m_producer.get_frame();
297 pix = frameThumbnail(frame, width, height, true);
300 if (prof) delete prof;
305 void Render::getImage(KUrl url, int frame_position, QPoint size)
307 char *tmp = decodedString(url.path());
308 Mlt::Producer m_producer(tmp);
310 if (m_producer.is_blank()) {
313 Mlt::Filter m_convert("avcolour_space");
314 m_convert.set("forced", mlt_image_rgb24a);
315 m_producer.attach(m_convert);
316 m_producer.seek(frame_position);
318 Mlt::Frame * frame = m_producer.get_frame();
321 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
323 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
327 /* Create thumbnail for color */
328 /*void Render::getImage(int id, QString color, QPoint size)
330 QPixmap pixmap(size.x() - 2, size.y() - 2);
331 color = color.replace(0, 2, "#");
332 color = color.left(7);
333 pixmap.fill(QColor(color));
334 QPixmap result(size.x(), size.y());
335 result.fill(Qt::black);
336 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
337 emit replyGetImage(id, result, size.x(), size.y());
341 /* Create thumbnail for image */
342 /*void Render::getImage(KUrl url, QPoint size)
346 if (url.fileName().startsWith(".all.")) { // check for slideshow
347 QString fileType = url.fileName().right(3);
349 QStringList::Iterator it;
351 QDir dir( url.directory() );
352 more = dir.entryList( QDir::Files );
353 for ( it = more.begin() ; it != more.end() ; ++it ) {
354 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
355 if (!im.load(url.directory() + '/' + *it))
356 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
361 else im.load(url.path());
363 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
364 QPixmap result(size.x(), size.y());
365 result.fill(Qt::black);
366 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
367 emit replyGetImage(url, 1, result, size.x(), size.y());
371 double Render::consumerRatio() const {
372 if (!m_mltConsumer) return 1.0;
373 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
377 int Render::getLength() {
380 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
381 return mlt_producer_get_playtime(m_mltProducer->get_producer());
386 bool Render::isValid(KUrl url) {
387 char *tmp = decodedString(url.path());
388 Mlt::Producer producer(*m_mltProfile, tmp);
390 if (producer.is_blank())
396 const double Render::dar() const {
397 return m_mltProfile->dar();
400 void Render::slotSplitView(bool doit) {
401 m_isSplitView = doit;
402 Mlt::Service service(m_mltProducer->parent().get_service());
403 Mlt::Tractor tractor(service);
404 if (service.type() != tractor_type || tractor.count() < 2) return;
405 Mlt::Field *field = tractor.field();
408 for (int i = 1; i < tractor.count() && screen < 4; i++) {
409 Mlt::Producer trackProducer(tractor.track(i));
410 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
411 if (QString(trackProducer.get("hide")).toInt() != 1) {
412 kDebug() << "// ADIDNG TRACK: " << i;
413 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
414 transition->set("mlt_service", "composite");
415 transition->set("a_track", 0);
416 transition->set("b_track", i);
417 transition->set("distort", 1);
418 transition->set("internal_added", "200");
425 tmp = "50%,0:50%x50%";
428 tmp = "0,50%:50%x50%";
432 tmp = "50%,50%:50%x50%";
435 transition->set("geometry", tmp);
436 transition->set("always_active", "1");
437 field->plant_transition(*transition, 0, i);
442 m_mltConsumer->set("refresh", 1);
444 mlt_service serv = m_mltProducer->parent().get_service();
445 mlt_service nextservice = mlt_service_get_producer(serv);
446 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
447 QString mlt_type = mlt_properties_get(properties, "mlt_type");
448 QString resource = mlt_properties_get(properties, "mlt_service");
450 while (mlt_type == "transition") {
451 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
452 if (added == "200") {
453 mlt_field_disconnect_service(field->get_field(), nextservice);
455 nextservice = mlt_service_producer(nextservice);
456 if (nextservice == NULL) break;
457 properties = MLT_SERVICE_PROPERTIES(nextservice);
458 mlt_type = mlt_properties_get(properties, "mlt_type");
459 resource = mlt_properties_get(properties, "mlt_service");
460 m_mltConsumer->set("refresh", 1);
465 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer) {
467 int width = (int)(height * m_mltProfile->dar());
468 QMap < QString, QString > filePropertyMap;
469 QMap < QString, QString > metadataPropertyMap;
471 KUrl url = KUrl(xml.attribute("resource", QString()));
472 Mlt::Producer *producer = NULL;
473 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
474 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
477 if (xml.attribute("type").toInt() == COLOR) {
478 char *tmp = decodedString("colour:" + xml.attribute("colour"));
479 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
481 } else if (url.isEmpty()) {
483 QDomElement westley = doc.createElement("westley");
484 QDomElement play = doc.createElement("playlist");
485 doc.appendChild(westley);
486 westley.appendChild(play);
487 play.appendChild(doc.importNode(xml, true));
488 char *tmp = decodedString(doc.toString());
489 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
492 QString urlpath = url.path();
493 /*if (urlpath.contains(':')) {
494 if (!urlpath.startsWith("file:")) urlpath.prepend("file:");
495 char *tmp = decodedString(urlpath);
496 producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp);
500 char *tmp = decodedString(urlpath);
501 producer = new Mlt::Producer(*m_mltProfile, tmp);
504 if (xml.hasAttribute("force_aspect_ratio")) {
505 double aspect = xml.attribute("force_aspect_ratio").toDouble();
506 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
508 if (xml.hasAttribute("threads")) {
509 int threads = xml.attribute("threads").toInt();
510 if (threads != 1) producer->set("threads", threads);
512 if (xml.hasAttribute("video_index")) {
513 int vindex = xml.attribute("video_index").toInt();
514 if (vindex != 0) producer->set("video_index", vindex);
516 if (xml.hasAttribute("audio_index")) {
517 int aindex = xml.attribute("audio_index").toInt();
518 if (aindex != 0) producer->set("audio_index", aindex);
523 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
524 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
525 emit removeInvalidClip(clipId);
529 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
531 char *tmp = decodedString(clipId);
532 producer->set("id", tmp);
534 int frameNumber = xml.attribute("thumbnail", "0").toInt();
535 if (frameNumber != 0) producer->seek(frameNumber);
536 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
538 filePropertyMap["duration"] = QString::number(producer->get_playtime());
539 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
541 Mlt::Frame *frame = producer->get_frame();
543 if (xml.attribute("type").toInt() == SLIDESHOW) {
544 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
545 if (xml.attribute("fade") == "1") {
546 // user wants a fade effect to slideshow
547 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
548 if (filter && filter->is_valid()) {
549 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
550 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
551 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
552 char *tmp = decodedString(xml.attribute("luma_file"));
553 filter->set("luma.resource", tmp);
555 if (xml.hasAttribute("softness")) {
556 int soft = xml.attribute("softness").toInt();
557 filter->set("luma.softness", (double) soft / 100.0);
560 Mlt::Service clipService(producer->get_service());
561 clipService.attach(*filter);
567 filePropertyMap["fps"] = producer->get("source_fps");
569 if (frame && frame->is_valid()) {
570 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
571 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
572 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
573 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
575 if (frame->get_int("test_image") == 0) {
576 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
577 filePropertyMap["type"] = "playlist";
578 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
579 } else if (frame->get_int("test_audio") == 0)
580 filePropertyMap["type"] = "av";
582 filePropertyMap["type"] = "video";
584 mlt_image_format format = mlt_image_yuv422;
586 int frame_height = 0;
587 //frame->set("rescale.interp", "hyper");
588 frame->set("normalised_height", height);
589 frame->set("normalised_width", width);
590 QPixmap pix(width, height);
592 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
593 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
594 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
595 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
597 if (!image.isNull()) {
598 pix = QPixmap::fromImage(image.rgbSwapped());
602 mlt_pool_release(new_image);
603 emit replyGetImage(clipId, pix);
605 } else if (frame->get_int("test_audio") == 0) {
606 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
607 emit replyGetImage(clipId, pixmap);
608 filePropertyMap["type"] = "audio";
612 // Retrieve audio / video codec name
616 if (producer->get_int("video_index") > -1) {
617 /*if (context->duration == AV_NOPTS_VALUE) {
618 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
619 emit removeInvalidClip(clipId);
622 // Get the video_index
623 int default_video = producer->get_int("video_index");
625 int default_audio = producer->get_int("audio_index");
628 // Find maximum stream index values
629 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
630 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
631 QString type = producer->get(property);
634 else if (type == "audio")
637 filePropertyMap["default_video"] = QString::number(default_video);
638 filePropertyMap["video_max"] = QString::number(video_max);
639 filePropertyMap["default_audio"] = QString::number(default_audio);
640 filePropertyMap["audio_max"] = QString::number(audio_max);
642 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
643 if (producer->get(property)) {
644 filePropertyMap["videocodec"] = producer->get(property);
646 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
647 if (producer->get(property))
648 filePropertyMap["videocodec"] = producer->get(property);
651 if (KdenliveSettings::dropbframes()) {
652 kDebug() << "// LOOKING FOR H264 on: " << default_video;
653 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
654 kDebug() << "PROP: " << property << " = " << producer->get(property);
655 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
656 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
657 producer->set("skip_loop_filter", "all");
658 producer->set("skip_frame", "bidir");
662 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
663 if (producer->get_int("audio_index") > -1) {
664 // Get the audio_index
665 int index = producer->get_int("audio_index");
667 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
668 if (producer->get(property)) {
669 filePropertyMap["audiocodec"] = producer->get(property);
671 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
672 if (producer->get(property))
673 filePropertyMap["audiocodec"] = producer->get(property);
678 Mlt::Properties metadata;
679 metadata.pass_values(*producer, "meta.attr.");
680 int count = metadata.count();
681 for (int i = 0; i < count; i ++) {
682 QString name = metadata.get_name(i);
683 QString value = QString::fromUtf8(metadata.get(i));
684 if (name.endsWith("markup") && !value.isEmpty())
685 metadataPropertyMap[ name.section('.', 0, -2)] = value;
688 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
689 kDebug() << "REquested fuile info for: " << url.path();
690 if (frame) delete frame;
691 //if (producer) delete producer;
695 /** Create the producer from the Westley QDomDocument */
697 void Render::initSceneList() {
698 kDebug() << "-------- INIT SCENE LIST ------_";
700 QDomElement westley = doc.createElement("westley");
701 doc.appendChild(westley);
702 QDomElement prod = doc.createElement("producer");
703 prod.setAttribute("resource", "colour");
704 prod.setAttribute("colour", "red");
705 prod.setAttribute("id", "black");
706 prod.setAttribute("in", "0");
707 prod.setAttribute("out", "0");
709 QDomElement tractor = doc.createElement("tractor");
710 QDomElement multitrack = doc.createElement("multitrack");
712 QDomElement playlist1 = doc.createElement("playlist");
713 playlist1.appendChild(prod);
714 multitrack.appendChild(playlist1);
715 QDomElement playlist2 = doc.createElement("playlist");
716 multitrack.appendChild(playlist2);
717 QDomElement playlist3 = doc.createElement("playlist");
718 multitrack.appendChild(playlist3);
719 QDomElement playlist4 = doc.createElement("playlist");
720 multitrack.appendChild(playlist4);
721 QDomElement playlist5 = doc.createElement("playlist");
722 multitrack.appendChild(playlist5);
723 tractor.appendChild(multitrack);
724 westley.appendChild(tractor);
725 // kDebug()<<doc.toString();
727 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
728 setSceneList(doc, 0);
734 /** Create the producer from the Westley QDomDocument */
735 void Render::setProducer(Mlt::Producer *producer, int position) {
736 if (m_winid == -1) return;
739 m_mltConsumer->stop();
742 m_mltConsumer->purge();
746 m_mltProducer->set_speed(0);
747 delete m_mltProducer;
748 m_mltProducer = NULL;
752 m_mltProducer = new Mlt::Producer(producer->get_producer());
753 } else m_mltProducer = m_blackClip->cut(0, 50);
754 /*if (KdenliveSettings::dropbframes()) {
755 m_mltProducer->set("skip_loop_filter", "all");
756 m_mltProducer->set("skip_frame", "bidir");
758 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
760 m_fps = m_mltProducer->get_fps();
762 if (position != -1) {
763 m_mltProducer->seek(position);
764 emit rendererPosition(position);
771 /** Create the producer from the Westley QDomDocument */
772 void Render::setSceneList(QDomDocument list, int position) {
773 setSceneList(list.toString(), position);
776 /** Create the producer from the Westley QDomDocument */
777 void Render::setSceneList(QString playlist, int position) {
778 if (m_winid == -1) return;
780 m_slowmotionProducers.clear();
782 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
785 m_mltConsumer->stop();
786 //m_mltConsumer->set("refresh", 0);
793 m_mltProducer->set_speed(0);
794 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
796 delete m_mltProducer;
797 m_mltProducer = NULL;
802 char *tmp = decodedString(playlist);
803 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
806 if (!m_mltProducer || !m_mltProducer->is_valid()) {
807 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
809 m_mltProducer->optimise();
811 /*if (KdenliveSettings::osdtimecode()) {
812 // Attach filter for on screen display of timecode
814 QString attr = "attr_check";
815 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
816 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
817 mlt_producer_attach( m_mltProducer->get_producer(), filter );
818 mlt_filter_close( filter );
820 m_osdInfo = new Mlt::Filter("data_show");
821 tmp = decodedString(m_osdProfile);
822 m_osdInfo->set("resource", tmp);
824 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
825 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
826 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
827 m_osdInfo->set("dynamic", "1");
829 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
831 m_osdInfo->set("dynamic", "0");
834 m_fps = m_mltProducer->get_fps();
835 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
837 fillSlowMotionProducers();
839 //TODO: seek to correct place after opening project.
840 // Needs to be done from another place since it crashes here.
841 m_mltProducer->seek(position);
845 //kDebug()<<"// SETSCN LST, POS: "<<position;
846 //if (position != 0) emit rendererPosition(position);
849 /** Create the producer from the Westley QDomDocument */
850 const QString Render::sceneList() {
852 Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
853 m_mltProducer->optimise();
854 westleyConsumer.set("terminate_on_pause", 1);
855 Mlt::Producer prod(m_mltProducer->get_producer());
856 bool split = m_isSplitView;
857 if (split) slotSplitView(false);
858 westleyConsumer.connect(prod);
859 westleyConsumer.start();
860 while (!westleyConsumer.is_stopped()) {}
861 playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
862 if (split) slotSplitView(true);
866 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
869 doc.setContent(sceneList(), false);
870 if (!kdenliveData.isNull()) {
871 // add Kdenlive specific tags
872 QDomNode wes = doc.elementsByTagName("westley").at(0);
873 wes.appendChild(doc.importNode(kdenliveData, true));
875 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
876 kWarning() << "////// ERROR writing to file: " << path;
879 QTextStream out(&file);
880 out << doc.toString();
885 void Render::saveZone(KUrl url, QString desc, QPoint zone) {
886 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
887 char *tmppath = decodedString("westley:" + url.path());
888 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
889 m_mltProducer->optimise();
891 westleyConsumer.set("terminate_on_pause", 1);
892 if (m_name == "clip") {
893 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
894 tmppath = decodedString(desc);
896 list.insert_at(0, prod, 0);
897 list.set("title", tmppath);
899 westleyConsumer.connect(list);
902 //TODO: not working yet, save zone from timeline
903 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
904 /* Mlt::Service service(p1->parent().get_service());
905 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
907 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
908 tmppath = decodedString(desc);
909 //prod->set("title", tmppath);
911 westleyConsumer.connect(*p1); //list);
914 westleyConsumer.start();
917 const double Render::fps() const {
921 void Render::connectPlaylist() {
922 if (!m_mltConsumer) return;
923 //m_mltConsumer->set("refresh", "0");
924 m_mltConsumer->connect(*m_mltProducer);
925 m_mltProducer->set_speed(0);
926 m_mltConsumer->start();
927 emit durationChanged(m_mltProducer->get_playtime());
930 if (m_mltConsumer->start() == -1) {
931 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."));
932 m_mltConsumer = NULL;
939 void Render::refreshDisplay() {
941 if (!m_mltProducer) return;
942 //m_mltConsumer->set("refresh", 0);
944 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
945 /*if (KdenliveSettings::osdtimecode()) {
946 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
947 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
948 m_osdInfo->set("dynamic", "1");
949 m_mltProducer->attach(*m_osdInfo);
952 m_mltProducer->detach(*m_osdInfo);
953 m_osdInfo->set("dynamic", "0");
958 void Render::setVolume(double volume) {
959 if (!m_mltConsumer || !m_mltProducer) return;
961 m_mltConsumer->set("refresh", 0);
962 // Attach filter for on screen display of timecode
963 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
964 mlt_properties_set_double( properties, "meta.volume", volume );
965 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
966 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
968 if (!KdenliveSettings::osdtimecode()) {
969 m_mltProducer->detach(*m_osdInfo);
970 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
971 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
974 osdTimer->setSingleShot(2500);
977 void Render::slotOsdTimeout() {
978 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
979 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
980 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
981 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
985 void Render::start() {
986 kDebug() << "----- STARTING MONITOR: " << m_name;
988 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
992 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
993 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
994 if (m_mltConsumer->start() == -1) {
995 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."));
996 m_mltConsumer = NULL;
999 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1000 m_isBlocked = false;
1004 m_isBlocked = false;
1007 void Render::clear() {
1008 kDebug() << " ********* RENDER CLEAR";
1009 if (m_mltConsumer) {
1010 //m_mltConsumer->set("refresh", 0);
1011 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1014 if (m_mltProducer) {
1015 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1016 m_mltProducer->set_speed(0.0);
1017 delete m_mltProducer;
1018 m_mltProducer = NULL;
1023 void Render::stop() {
1024 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1025 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1027 //m_mltConsumer->set("refresh", 0);
1028 m_mltConsumer->stop();
1029 // delete m_mltConsumer;
1030 // m_mltConsumer = NULL;
1032 kDebug() << "///////////// RENDER STOP2-------";
1035 if (m_mltProducer) {
1036 if (m_isZoneMode) resetZoneMode();
1037 m_mltProducer->set_speed(0.0);
1038 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1039 //kDebug() << m_mltProducer->get_length();
1041 kDebug() << "///////////// RENDER STOP3-------";
1044 void Render::stop(const GenTime & startTime) {
1046 kDebug() << "///////////// RENDER STOP-------2";
1047 if (m_mltProducer) {
1048 if (m_isZoneMode) resetZoneMode();
1049 m_mltProducer->set_speed(0.0);
1050 m_mltProducer->seek((int) startTime.frames(m_fps));
1052 m_mltConsumer->purge();
1055 void Render::pause() {
1056 if (!m_mltProducer || !m_mltConsumer)
1058 if (m_mltProducer->get_speed() == 0.0) return;
1059 if (m_isZoneMode) resetZoneMode();
1061 m_mltConsumer->set("refresh", 0);
1062 m_mltProducer->set_speed(0.0);
1063 emit rendererPosition(m_framePosition);
1064 m_mltProducer->seek(m_framePosition);
1065 m_mltConsumer->purge();
1068 void Render::switchPlay() {
1069 if (!m_mltProducer || !m_mltConsumer)
1071 if (m_isZoneMode) resetZoneMode();
1072 if (m_mltProducer->get_speed() == 0.0) {
1073 m_isBlocked = false;
1074 m_mltProducer->set_speed(1.0);
1075 m_mltConsumer->set("refresh", 1);
1078 m_mltConsumer->set("refresh", 0);
1079 m_mltProducer->set_speed(0.0);
1080 emit rendererPosition(m_framePosition);
1081 m_mltProducer->seek(m_framePosition);
1082 m_mltConsumer->purge();
1083 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1084 //m_mltConsumer->set("refresh", 0);
1085 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1086 m_mltProducer->set_speed(0);
1087 m_mltProducer->seek( position );
1088 //m_mltProducer->seek((int) m_framePosition);
1089 m_isBlocked = false;*/
1091 /*if (speed == 0.0) {
1092 m_mltProducer->seek((int) m_framePosition + 1);
1093 m_mltConsumer->purge();
1098 void Render::play(double speed) {
1101 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1102 m_isBlocked = false;
1103 m_mltProducer->set_speed(speed);
1104 /*if (speed == 0.0) {
1105 m_mltProducer->seek((int) m_framePosition + 1);
1106 m_mltConsumer->purge();
1111 void Render::play(const GenTime & startTime) {
1112 if (!m_mltProducer || !m_mltConsumer)
1114 m_isBlocked = false;
1115 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1116 m_mltProducer->set_speed(1.0);
1117 m_mltConsumer->set("refresh", 1);
1120 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1121 if (!m_mltProducer || !m_mltConsumer)
1123 //m_mltProducer->set("eof", "loop");
1124 m_isLoopMode = true;
1125 m_loopStart = startTime;
1126 playZone(startTime, stopTime);
1129 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1130 if (!m_mltProducer || !m_mltConsumer)
1132 m_isBlocked = false;
1133 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1134 m_mltProducer->set("out", stopTime.frames(m_fps));
1135 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1136 m_mltProducer->set_speed(1.0);
1137 m_mltConsumer->set("refresh", 1);
1138 m_isZoneMode = true;
1141 void Render::resetZoneMode() {
1142 if (!m_isZoneMode && !m_isLoopMode) return;
1143 m_mltProducer->set("out", m_originalOut);
1144 //m_mltProducer->set("eof", "pause");
1145 m_isZoneMode = false;
1146 m_isLoopMode = false;
1149 void Render::seekToFrame(int pos) {
1150 //kDebug()<<" ********* RENDER SEEK TO POS";
1153 m_isBlocked = false;
1155 m_mltProducer->seek(pos);
1159 void Render::askForRefresh() {
1160 // Use a Timer so that we don't refresh too much
1161 refreshTimer->start(200);
1164 void Render::doRefresh() {
1165 // Use a Timer so that we don't refresh too much
1166 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1169 void Render::refresh() {
1170 if (!m_mltProducer || m_isBlocked)
1172 refreshTimer->stop();
1173 if (m_mltConsumer) {
1174 m_mltConsumer->set("refresh", 1);
1178 double Render::playSpeed() {
1179 if (m_mltProducer) return m_mltProducer->get_speed();
1183 GenTime Render::seekPosition() const {
1184 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1185 else return GenTime();
1189 const QString & Render::rendererName() const {
1194 void Render::emitFrameNumber(double position) {
1195 m_framePosition = position;
1196 emit rendererPosition((int) position);
1197 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1200 void Render::emitConsumerStopped() {
1201 // This is used to know when the playing stopped
1202 if (m_mltProducer) {
1203 double pos = m_mltProducer->position();
1204 if (m_isLoopMode) play(m_loopStart);
1205 else if (m_isZoneMode) resetZoneMode();
1206 emit rendererStopped((int) pos);
1207 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1208 //new QCustomEvent(10002));
1214 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1215 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1219 void Render::exportCurrentFrame(KUrl url, bool notify) {
1220 if (!m_mltProducer) {
1221 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1225 int height = 1080;//KdenliveSettings::defaultheight();
1226 int width = 1940; //KdenliveSettings::displaywidth();
1228 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1230 QPixmap pix(width, height);
1231 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1232 m_convert.set("forced", mlt_image_rgb24a);
1233 m_mltProducer->attach(m_convert);
1234 Mlt::Frame * frame = m_mltProducer->get_frame();
1235 m_mltProducer->detach(m_convert);
1237 pix = frameThumbnail(frame, width, height);
1240 pix.save(url.path(), "PNG");
1241 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1244 /** MLT PLAYLIST DIRECT MANIPULATON **/
1247 void Render::mltCheckLength() {
1248 //kDebug()<<"checking track length: "<<track<<"..........";
1250 Mlt::Service service(m_mltProducer->get_service());
1251 Mlt::Tractor tractor(service);
1253 int trackNb = tractor.count();
1254 double duration = 0;
1255 double trackDuration;
1257 Mlt::Producer trackProducer(tractor.track(0));
1258 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1259 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1260 m_mltProducer->set("out", duration);
1261 emit durationChanged((int) duration);
1264 while (trackNb > 1) {
1265 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1266 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1267 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1269 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1270 if (trackDuration > duration) duration = trackDuration;
1274 Mlt::Producer blackTrackProducer(tractor.track(0));
1275 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1276 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1278 if (blackDuration != duration) {
1279 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1281 int dur = (int)duration;
1283 QDomElement black = doc.createElement("producer");
1284 black.setAttribute("mlt_service", "colour");
1285 black.setAttribute("colour", "black");
1286 black.setAttribute("id", "black");
1289 while (dur > 14000) {
1290 info.startPos = GenTime(i * 14000, m_fps);
1291 info.endPos = info.startPos + GenTime(13999, m_fps);
1292 mltInsertClip(info, black, m_blackClip);
1297 info.startPos = GenTime(i * 14000, m_fps);
1298 info.endPos = info.startPos + GenTime(dur, m_fps);
1299 mltInsertClip(info, black, m_blackClip);
1301 m_mltProducer->set("out", duration);
1302 emit durationChanged((int)duration);
1306 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1307 if (!m_mltProducer) {
1308 kDebug() << "PLAYLIST NOT INITIALISED //////";
1311 Mlt::Producer parentProd(m_mltProducer->parent());
1312 if (parentProd.get_producer() == NULL) {
1313 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1317 Mlt::Service service(parentProd.get_service());
1318 Mlt::Tractor tractor(service);
1319 mlt_service_lock(service.get_service());
1320 Mlt::Producer trackProducer(tractor.track(info.track));
1321 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1322 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1324 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1325 // We want a slowmotion producer
1326 double speed = element.attribute("speed", "1.0").toDouble();
1327 QString url = QString::fromUtf8(prod->get("resource"));
1328 url.append('?' + QString::number(speed));
1329 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1330 if (!slowprod || slowprod->get_producer() == NULL) {
1331 char *tmp = decodedString(url);
1332 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1334 QString id = prod->get("id");
1335 if (id.contains('_')) id = id.section('_', 0, 0);
1336 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1337 tmp = decodedString(producerid);
1338 slowprod->set("id", tmp);
1340 m_slowmotionProducers.insert(url, slowprod);
1345 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1346 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1348 /*if (QString(prod->get("transparency")).toInt() == 1)
1349 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1351 mlt_service_unlock(service.get_service());
1353 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1354 //tractor.multitrack()->refresh();
1355 //tractor.refresh();
1359 void Render::mltCutClip(int track, GenTime position) {
1363 Mlt::Service service(m_mltProducer->parent().get_service());
1364 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1366 Mlt::Tractor tractor(service);
1367 Mlt::Producer trackProducer(tractor.track(track));
1368 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1371 /* // Display playlist info
1372 kDebug()<<"//////////// BEFORE";
1373 for (int i = 0; i < trackPlaylist.count(); i++) {
1374 int blankStart = trackPlaylist.clip_start(i);
1375 int blankDuration = trackPlaylist.clip_length(i) - 1;
1377 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1378 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1381 int cutPos = (int) position.frames(m_fps);
1383 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1384 if (trackPlaylist.is_blank(clipIndex)) {
1385 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1386 m_isBlocked = false;
1389 mlt_service_lock(service.get_service());
1390 int clipStart = trackPlaylist.clip_start(clipIndex);
1391 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1392 mlt_service_unlock(service.get_service());
1394 // duplicate effects
1395 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1396 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1398 if (original == NULL || clip == NULL) {
1399 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1401 Mlt::Service clipService(original->get_service());
1402 Mlt::Service dupService(clip->get_service());
1404 Mlt::Filter *filter = clipService.filter(ct);
1406 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1407 // looks like there is no easy way to duplicate a filter,
1408 // so we will create a new one and duplicate its properties
1409 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1410 if (dup && dup->is_valid()) {
1411 Mlt::Properties entries(filter->get_properties());
1412 for (int i = 0;i < entries.count();i++) {
1413 dup->set(entries.get_name(i), entries.get(i));
1415 dupService.attach(*dup);
1419 filter = clipService.filter(ct);
1422 /* // Display playlist info
1423 kDebug()<<"//////////// AFTER";
1424 for (int i = 0; i < trackPlaylist.count(); i++) {
1425 int blankStart = trackPlaylist.clip_start(i);
1426 int blankDuration = trackPlaylist.clip_length(i) - 1;
1428 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1429 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1432 m_isBlocked = false;
1435 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1437 mltRemoveClip(info.track, info.startPos);
1438 mltInsertClip(info, element, prod);
1442 bool Render::mltRemoveClip(int track, GenTime position) {
1443 Mlt::Service service(m_mltProducer->parent().get_service());
1444 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1446 Mlt::Tractor tractor(service);
1447 Mlt::Producer trackProducer(tractor.track(track));
1448 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1449 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1451 /* // Display playlist info
1452 kDebug()<<"//// BEFORE";
1453 for (int i = 0; i < trackPlaylist.count(); i++) {
1454 int blankStart = trackPlaylist.clip_start(i);
1455 int blankDuration = trackPlaylist.clip_length(i) - 1;
1457 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1458 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1461 if (trackPlaylist.is_blank(clipIndex)) {
1462 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1466 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1467 trackPlaylist.replace_with_blank(clipIndex);
1468 trackPlaylist.consolidate_blanks(0);
1469 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1470 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1472 /* // Display playlist info
1473 kDebug()<<"//// AFTER";
1474 for (int i = 0; i < trackPlaylist.count(); i++) {
1475 int blankStart = trackPlaylist.clip_start(i);
1476 int blankDuration = trackPlaylist.clip_length(i) - 1;
1478 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1479 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1482 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1483 m_isBlocked = false;
1487 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
1488 if (!m_mltProducer) {
1489 kDebug() << "PLAYLIST NOT INITIALISED //////";
1492 Mlt::Producer parentProd(m_mltProducer->parent());
1493 if (parentProd.get_producer() == NULL) {
1494 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1498 Mlt::Service service(parentProd.get_service());
1499 Mlt::Tractor tractor(service);
1500 int insertPos = pos.frames(m_fps);
1502 Mlt::Producer trackProducer(tractor.track(track));
1503 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1504 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1505 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1506 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1507 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1511 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
1512 if (!m_mltProducer) {
1513 kDebug() << "PLAYLIST NOT INITIALISED //////";
1516 Mlt::Producer parentProd(m_mltProducer->parent());
1517 if (parentProd.get_producer() == NULL) {
1518 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1521 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1522 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1524 Mlt::Service service(parentProd.get_service());
1525 Mlt::Tractor tractor(service);
1526 mlt_service_lock(service.get_service());
1527 int diff = duration.frames(m_fps);
1528 int offset = timeOffset.frames(m_fps);
1532 // insert space in one track only
1533 Mlt::Producer trackProducer(tractor.track(track));
1534 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1535 insertPos = trackClipStartList.value(track);
1536 if (insertPos != -1) {
1537 insertPos += offset;
1538 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1539 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1541 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1542 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1543 int position = trackPlaylist.clip_start(clipIndex);
1544 trackPlaylist.remove_region(position, - diff - 1);
1546 trackPlaylist.consolidate_blanks(0);
1548 // now move transitions
1549 mlt_service serv = m_mltProducer->parent().get_service();
1550 mlt_service nextservice = mlt_service_get_producer(serv);
1551 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1552 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1553 QString resource = mlt_properties_get(properties, "mlt_service");
1555 while (mlt_type == "transition") {
1556 mlt_transition tr = (mlt_transition) nextservice;
1557 int currentTrack = mlt_transition_get_b_track(tr);
1558 int currentIn = (int) mlt_transition_get_in(tr);
1559 int currentOut = (int) mlt_transition_get_out(tr);
1560 insertPos = trackTransitionStartList.value(track);
1561 if (insertPos != -1) {
1562 insertPos += offset;
1563 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1564 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1567 nextservice = mlt_service_producer(nextservice);
1568 if (nextservice == NULL) break;
1569 properties = MLT_SERVICE_PROPERTIES(nextservice);
1570 mlt_type = mlt_properties_get(properties, "mlt_type");
1571 resource = mlt_properties_get(properties, "mlt_service");
1574 int trackNb = tractor.count();
1575 while (trackNb > 1) {
1576 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1577 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1580 int clipNb = trackPlaylist.count();
1581 insertPos = trackClipStartList.value(trackNb - 1);
1582 if (insertPos != -1) {
1583 insertPos += offset;
1585 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1586 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1587 for (int i = 0; i < clipNb; i++) {
1588 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1589 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1590 kDebug()<<"-------------";
1592 kDebug()<<"END-------------";*/
1595 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1596 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1598 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1599 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1600 int position = trackPlaylist.clip_start(clipIndex);
1601 trackPlaylist.remove_region(position, - diff - 1);
1603 trackPlaylist.consolidate_blanks(0);
1607 // now move transitions
1608 mlt_service serv = m_mltProducer->parent().get_service();
1609 mlt_service nextservice = mlt_service_get_producer(serv);
1610 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1611 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1612 QString resource = mlt_properties_get(properties, "mlt_service");
1614 while (mlt_type == "transition") {
1615 mlt_transition tr = (mlt_transition) nextservice;
1616 int currentIn = (int) mlt_transition_get_in(tr);
1617 int currentOut = (int) mlt_transition_get_out(tr);
1618 int currentTrack = mlt_transition_get_b_track(tr);
1619 insertPos = trackTransitionStartList.value(currentTrack);
1620 if (insertPos != -1) {
1621 insertPos += offset;
1622 if (currentOut > insertPos && resource != "mix") {
1623 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1626 nextservice = mlt_service_producer(nextservice);
1627 if (nextservice == NULL) break;
1628 properties = MLT_SERVICE_PROPERTIES(nextservice);
1629 mlt_type = mlt_properties_get(properties, "mlt_type");
1630 resource = mlt_properties_get(properties, "mlt_service");
1633 mlt_service_unlock(service.get_service());
1635 m_mltConsumer->set("refresh", 1);
1638 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
1641 Mlt::Service service(m_mltProducer->parent().get_service());
1642 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1643 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1644 Mlt::Tractor tractor(service);
1645 Mlt::Producer trackProducer(tractor.track(info.track));
1646 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1647 int startPos = info.startPos.frames(m_fps);
1648 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1649 int clipLength = trackPlaylist.clip_length(clipIndex);
1651 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1652 if (!clip.is_valid() || clip.is_blank()) {
1656 Mlt::Producer clipparent = clip.parent();
1657 if (!clipparent.is_valid() || clipparent.is_blank()) {
1661 QString serv = clipparent.get("mlt_service");
1662 QString id = clipparent.get("id");
1663 //kDebug() << "CLIP SERVICE: " << serv;
1664 if (serv == "avformat" && speed != 1.0) {
1665 mlt_service_lock(service.get_service());
1666 QString url = QString::fromUtf8(clipparent.get("resource"));
1667 url.append('?' + QString::number(speed));
1668 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1669 if (!slowprod || slowprod->get_producer() == NULL) {
1670 char *tmp = decodedString(url);
1671 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1673 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1674 tmp = decodedString(producerid);
1675 slowprod->set("id", tmp);
1677 m_slowmotionProducers.insert(url, slowprod);
1679 trackPlaylist.replace_with_blank(clipIndex);
1680 trackPlaylist.consolidate_blanks(0);
1681 // Check that the blank space is long enough for our new duration
1682 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1683 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1685 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1686 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1687 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1688 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1689 trackPlaylist.insert_at(startPos, *cut, 1);
1690 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1691 newLength = trackPlaylist.clip_length(clipIndex);
1692 mlt_service_unlock(service.get_service());
1693 } else if (speed == 1.0) {
1694 mlt_service_lock(service.get_service());
1696 trackPlaylist.replace_with_blank(clipIndex);
1697 trackPlaylist.consolidate_blanks(0);
1699 // Check that the blank space is long enough for our new duration
1700 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1701 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1704 GenTime oldDuration = GenTime(clipLength, m_fps);
1705 GenTime newDuration = oldDuration * oldspeed;
1706 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1707 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1708 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1709 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1710 trackPlaylist.insert_at(startPos, *cut, 1);
1711 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1712 newLength = trackPlaylist.clip_length(clipIndex);
1713 mlt_service_unlock(service.get_service());
1715 } else if (serv == "framebuffer") {
1716 mlt_service_lock(service.get_service());
1717 QString url = QString::fromUtf8(clipparent.get("resource"));
1718 url = url.section('?', 0, 0);
1719 url.append('?' + QString::number(speed));
1720 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1721 if (!slowprod || slowprod->get_producer() == NULL) {
1722 char *tmp = decodedString(url);
1723 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1725 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1726 tmp = decodedString(producerid);
1727 slowprod->set("id", tmp);
1729 m_slowmotionProducers.insert(url, slowprod);
1731 trackPlaylist.replace_with_blank(clipIndex);
1732 trackPlaylist.consolidate_blanks(0);
1734 GenTime oldDuration = GenTime(clipLength, m_fps);
1735 GenTime newDuration = oldDuration * oldspeed / speed;
1737 // Check that the blank space is long enough for our new duration
1738 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1739 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1742 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1743 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1744 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1745 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1747 trackPlaylist.insert_at(startPos, *cut, 1);
1748 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1749 newLength = trackPlaylist.clip_length(clipIndex);
1751 mlt_service_unlock(service.get_service());
1753 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1754 m_isBlocked = false;
1758 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh) {
1759 kDebug() << "// TRYing to remove effect at: " << index;
1760 Mlt::Service service(m_mltProducer->parent().get_service());
1761 bool success = false;
1762 Mlt::Tractor tractor(service);
1763 Mlt::Producer trackProducer(tractor.track(track));
1764 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1765 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1766 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1768 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1771 Mlt::Service clipService(clip->get_service());
1772 // if (tag.startsWith("ladspa")) tag = "ladspa";
1775 Mlt::Filter *filter = clipService.filter(ct);
1777 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1778 if (clipService.detach(*filter) == 0) success = true;
1779 kDebug() << " / / / DLEETED EFFECT: " << ct;
1780 } else if (updateIndex) {
1781 // Adjust the other effects index
1782 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1785 filter = clipService.filter(ct);
1787 m_isBlocked = false;
1788 if (doRefresh) refresh();
1793 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
1795 Mlt::Service service(m_mltProducer->parent().get_service());
1797 Mlt::Tractor tractor(service);
1798 Mlt::Producer trackProducer(tractor.track(track));
1799 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1801 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1805 Mlt::Service clipService(clip->get_service());
1808 // temporarily remove all effects after insert point
1809 QList <Mlt::Filter *> filtersList;
1810 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1812 Mlt::Filter *filter = clipService.filter(ct);
1814 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1815 filtersList.append(filter);
1816 clipService.detach(*filter);
1818 filter = clipService.filter(ct);
1822 QString tag = params.paramValue("tag");
1823 kDebug() << " / / INSERTING EFFECT: " << tag;
1824 if (tag.startsWith("ladspa")) tag = "ladspa";
1825 char *filterTag = decodedString(tag);
1826 char *filterId = decodedString(params.paramValue("id"));
1827 QHash<QString, QString>::Iterator it;
1828 QString kfr = params.paramValue("keyframes");
1830 if (!kfr.isEmpty()) {
1831 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1832 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1833 char *starttag = decodedString(params.paramValue("starttag", "start"));
1834 char *endtag = decodedString(params.paramValue("endtag", "end"));
1835 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1836 int duration = clip->get_playtime();
1837 double max = params.paramValue("max").toDouble();
1838 double min = params.paramValue("min").toDouble();
1839 double factor = params.paramValue("factor", "1").toDouble();
1840 params.removeParam("starttag");
1841 params.removeParam("endtag");
1842 params.removeParam("keyframes");
1843 params.removeParam("min");
1844 params.removeParam("max");
1845 params.removeParam("factor");
1847 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1848 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1849 if (filter && filter->is_valid()) {
1850 filter->set("kdenlive_id", filterId);
1851 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1852 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1853 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1854 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1855 if (x2 == -1) x2 = duration;
1857 for (int j = 0; j < params.count(); j++) {
1858 char *name = decodedString(params.at(j).name());
1859 char *value = decodedString(params.at(j).value());
1860 filter->set(name, value);
1865 filter->set("in", x1);
1866 filter->set("out", x2);
1867 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1868 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1869 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1870 clipService.attach(*filter);
1877 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1878 if (filter && filter->is_valid())
1879 filter->set("kdenlive_id", filterId);
1881 kDebug() << "filter is NULL";
1882 m_isBlocked = false;
1886 params.removeParam("kdenlive_id");
1888 for (int j = 0; j < params.count(); j++) {
1889 char *name = decodedString(params.at(j).name());
1890 char *value = decodedString(params.at(j).value());
1891 filter->set(name, value);
1897 QString effectArgs = params.paramValue("id").section('_', 1);
1899 params.removeParam("id");
1900 params.removeParam("kdenlive_ix");
1901 params.removeParam("tag");
1902 params.removeParam("disabled");
1904 for (int j = 0; j < params.count(); j++) {
1905 effectArgs.append(' ' + params.at(j).value());
1907 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1908 char *value = decodedString(effectArgs.simplified());
1909 filter->set("effect", value);
1914 // attach filter to the clip
1915 clipService.attach(*filter);
1920 // re-add following filters
1921 for (int i = 0; i < filtersList.count(); i++) {
1922 clipService.attach(*(filtersList.at(i)));
1925 m_isBlocked = false;
1926 if (doRefresh) refresh();
1930 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
1931 QString index = params.paramValue("kdenlive_ix");
1932 QString tag = params.paramValue("tag");
1934 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1935 // This is a keyframe effect, to edit it, we remove it and re-add it.
1936 mltRemoveEffect(track, position, index, true);
1937 bool success = mltAddEffect(track, position, params);
1942 Mlt::Service service(m_mltProducer->parent().get_service());
1944 Mlt::Tractor tractor(service);
1945 Mlt::Producer trackProducer(tractor.track(track));
1946 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1947 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1948 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1950 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1953 Mlt::Service clipService(clip->get_service());
1956 Mlt::Filter *filter = clipService.filter(ct);
1958 if (filter->get("kdenlive_ix") == index) {
1962 filter = clipService.filter(ct);
1966 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1967 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1969 filter = clipService.filter(ct);
1970 QList <Mlt::Filter *> filtersList;
1972 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1973 filtersList.append(filter);
1974 clipService.detach(*filter);
1976 filter = clipService.filter(ct);
1978 bool success = mltAddEffect(track, position, params);
1980 for (int i = 0; i < filtersList.count(); i++) {
1981 clipService.attach(*(filtersList.at(i)));
1984 m_isBlocked = false;
1988 for (int j = 0; j < params.count(); j++) {
1989 char *name = decodedString(params.at(j).name());
1990 char *value = decodedString(params.at(j).value());
1991 filter->set(name, value);
1996 m_isBlocked = false;
2001 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
2003 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2004 Mlt::Service service(m_mltProducer->parent().get_service());
2006 Mlt::Tractor tractor(service);
2007 Mlt::Producer trackProducer(tractor.track(track));
2008 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2009 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2010 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2012 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2015 Mlt::Service clipService(clip->get_service());
2018 QList <Mlt::Filter *> filtersList;
2019 Mlt::Filter *filter = clipService.filter(ct);
2021 if (newPos > oldPos) {
2023 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2024 filter->set("kdenlive_ix", newPos);
2025 filtersList.append(filter);
2026 clipService.detach(*filter);
2027 filter = clipService.filter(ct);
2028 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2029 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2031 filter = clipService.filter(ct);
2035 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2036 filtersList.append(filter);
2037 clipService.detach(*filter);
2039 filter = clipService.filter(ct);
2043 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2044 filter->set("kdenlive_ix", newPos);
2045 filtersList.append(filter);
2046 clipService.detach(*filter);
2048 filter = clipService.filter(ct);
2052 filter = clipService.filter(ct);
2054 int pos = QString(filter->get("kdenlive_ix")).toInt();
2055 if (pos >= newPos) {
2056 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2057 filtersList.append(filter);
2058 clipService.detach(*filter);
2060 filter = clipService.filter(ct);
2064 for (int i = 0; i < filtersList.count(); i++) {
2065 clipService.attach(*(filtersList.at(i)));
2068 m_isBlocked = false;
2072 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
2075 Mlt::Service service(m_mltProducer->parent().get_service());
2077 Mlt::Tractor tractor(service);
2078 Mlt::Producer trackProducer(tractor.track(info.track));
2079 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2081 /* // Display playlist info
2082 kDebug()<<"//////////// BEFORE RESIZE";
2083 for (int i = 0; i < trackPlaylist.count(); i++) {
2084 int blankStart = trackPlaylist.clip_start(i);
2085 int blankDuration = trackPlaylist.clip_length(i) - 1;
2087 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2088 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2091 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2092 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2093 m_isBlocked = false;
2096 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2097 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2098 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2099 int previousStart = clip->get_in();
2100 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2101 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2102 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2103 trackPlaylist.consolidate_blanks(0);
2104 // skip to next clip
2106 int diff = newDuration - previousDuration;
2107 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2109 // clip was made longer, trim next blank if there is one.
2110 if (clipIndex < trackPlaylist.count()) {
2111 // If this is not the last clip in playlist
2112 if (trackPlaylist.is_blank(clipIndex)) {
2113 int blankStart = trackPlaylist.clip_start(clipIndex);
2114 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2115 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2116 if (diff - blankDuration == 1) {
2117 trackPlaylist.remove(clipIndex);
2118 } else trackPlaylist.remove_region(blankStart, diff - 1);
2120 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2123 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2125 trackPlaylist.consolidate_blanks(0);
2128 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2129 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2130 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2131 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2132 ItemInfo transpinfo;
2133 transpinfo.startPos = info.startPos;
2134 transpinfo.endPos = info.startPos + clipDuration;
2135 transpinfo.track = info.track;
2136 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2138 m_isBlocked = false;
2139 m_mltConsumer->set("refresh", 1);
2143 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
2144 Mlt::Service service(m_mltProducer->parent().get_service());
2145 Mlt::Tractor tractor(service);
2146 Mlt::Producer trackProducer(tractor.track(track));
2149 if (blind) trackProducer.set("hide", 3);
2150 else trackProducer.set("hide", 2);
2152 trackProducer.set("hide", 1);
2154 trackProducer.set("hide", 0);
2156 tractor.multitrack()->refresh();
2162 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) {
2163 Mlt::Service service(m_mltProducer->parent().get_service());
2164 int frameOffset = (int) diff.frames(m_fps);
2165 Mlt::Tractor tractor(service);
2166 Mlt::Producer trackProducer(tractor.track(info.track));
2167 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2168 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2169 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2172 mlt_service_lock(service.get_service());
2173 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2174 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2176 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2177 mlt_service_unlock(service.get_service());
2180 int previousStart = clip->get_in();
2181 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2183 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2184 m_isBlocked = false;
2185 mlt_service_unlock(service.get_service());
2186 m_mltConsumer->set("refresh", 1);
2190 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
2191 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2192 Mlt::Service service(m_mltProducer->parent().get_service());
2193 int moveFrame = (int) diff.frames(m_fps);
2194 Mlt::Tractor tractor(service);
2195 Mlt::Producer trackProducer(tractor.track(info.track));
2196 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2197 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2198 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2201 mlt_service_lock(service.get_service());
2202 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2203 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2205 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2206 mlt_service_unlock(service.get_service());
2209 int previousStart = clip->get_in();
2210 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2212 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2213 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2214 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2216 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2217 int blankIndex = clipIndex - 1;
2218 int blankLength = trackPlaylist.clip_length(blankIndex);
2219 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2220 if (! trackPlaylist.is_blank(blankIndex)) {
2221 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2223 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2224 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2226 trackPlaylist.consolidate_blanks(0);
2227 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2228 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2229 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2230 ItemInfo transpinfo;
2231 transpinfo.startPos = info.startPos + diff;
2232 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2233 transpinfo.track = info.track;
2234 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2236 m_isBlocked = false;
2237 //m_mltConsumer->set("refresh", 1);
2238 mlt_service_unlock(service.get_service());
2239 m_mltConsumer->set("refresh", 1);
2243 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
2244 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2248 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
2249 if (prod == NULL || !prod->is_valid()) {
2250 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2253 kDebug() << "NEW PROD ID: " << prod->get("id");
2254 m_mltConsumer->set("refresh", 0);
2255 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2256 mlt_service_lock(m_mltConsumer->get_service());
2257 Mlt::Service service(m_mltProducer->parent().get_service());
2258 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2260 Mlt::Tractor tractor(service);
2261 Mlt::Producer trackProducer(tractor.track(track));
2262 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2263 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2264 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2265 if (clipProducer.is_blank()) {
2266 kDebug() << "// ERROR UPDATING CLIP PROD";
2267 mlt_service_unlock(m_mltConsumer->get_service());
2268 m_isBlocked = false;
2271 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2273 // move all effects to the correct producer
2274 Mlt::Service clipService(clipProducer.get_service());
2275 Mlt::Service newClipService(clip->get_service());
2278 Mlt::Filter *filter = clipService.filter(ct);
2280 if (filter->get("kdenlive_ix") != 0) {
2281 clipService.detach(*filter);
2282 newClipService.attach(*filter);
2284 filter = clipService.filter(ct);
2287 trackPlaylist.insert_at(pos, clip, 1);
2288 mlt_service_unlock(m_mltConsumer->get_service());
2289 m_isBlocked = false;
2292 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
2295 m_mltConsumer->set("refresh", 0);
2296 mlt_service_lock(m_mltConsumer->get_service());
2297 Mlt::Service service(m_mltProducer->parent().get_service());
2298 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2300 Mlt::Tractor tractor(service);
2301 Mlt::Producer trackProducer(tractor.track(startTrack));
2302 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2303 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2304 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2305 bool checkLength = false;
2306 if (endTrack == startTrack) {
2307 //mlt_service_lock(service.get_service());
2308 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2309 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2310 // error, destination is not empty
2311 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2312 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2313 mlt_service_unlock(m_mltConsumer->get_service());
2314 m_isBlocked = false;
2317 trackPlaylist.consolidate_blanks(0);
2318 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2319 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2320 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2322 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2324 //mlt_service_unlock(service.get_service());
2326 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2327 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2328 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2329 // error, destination is not empty
2330 mlt_service_unlock(m_mltConsumer->get_service());
2331 m_isBlocked = false;
2334 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2335 if (clipProducer.is_blank()) {
2336 // error, destination is not empty
2337 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2338 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2339 mlt_service_unlock(m_mltConsumer->get_service());
2340 m_isBlocked = false;
2343 trackPlaylist.consolidate_blanks(0);
2344 destTrackPlaylist.consolidate_blanks(1);
2345 Mlt::Producer *clip;
2346 // check if we are moving a slowmotion producer
2347 QString serv = clipProducer.parent().get("mlt_service");
2348 if (serv == "framebuffer") {
2349 clip = &clipProducer;
2350 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2352 // move all effects to the correct producer
2353 Mlt::Service clipService(clipProducer.get_service());
2354 Mlt::Service newClipService(clip->get_service());
2357 Mlt::Filter *filter = clipService.filter(ct);
2359 if (filter->get("kdenlive_ix") != 0) {
2360 clipService.detach(*filter);
2361 newClipService.attach(*filter);
2363 filter = clipService.filter(ct);
2366 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2367 destTrackPlaylist.consolidate_blanks(0);
2368 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2369 kDebug() << "//////// moving clip transparency";
2370 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2372 if (clipIndex > trackPlaylist.count()) checkLength = true;
2373 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2377 if (checkLength) mltCheckLength();
2378 mlt_service_unlock(m_mltConsumer->get_service());
2379 m_isBlocked = false;
2380 m_mltConsumer->set("refresh", 1);
2384 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
2385 int new_in = (int)newIn.frames(m_fps);
2386 int new_out = (int)newOut.frames(m_fps) - 1;
2387 if (new_in >= new_out) return false;
2389 Mlt::Service service(m_mltProducer->parent().get_service());
2390 Mlt::Tractor tractor(service);
2391 Mlt::Field *field = tractor.field();
2393 mlt_service_lock(service.get_service());
2394 m_mltConsumer->set("refresh", 0);
2397 mlt_service serv = m_mltProducer->parent().get_service();
2398 mlt_service nextservice = mlt_service_get_producer(serv);
2399 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2400 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2401 QString resource = mlt_properties_get(properties, "mlt_service");
2402 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2404 while (mlt_type == "transition") {
2405 mlt_transition tr = (mlt_transition) nextservice;
2406 int currentTrack = mlt_transition_get_b_track(tr);
2407 int currentIn = (int) mlt_transition_get_in(tr);
2408 int currentOut = (int) mlt_transition_get_out(tr);
2410 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2411 mlt_transition_set_in_and_out(tr, new_in, new_out);
2412 if (newTrack - startTrack != 0) {
2413 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2415 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2416 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2417 mlt_properties_set_int(properties, "b_track", newTrack);
2418 //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);
2422 nextservice = mlt_service_producer(nextservice);
2423 if (nextservice == NULL) break;
2424 properties = MLT_SERVICE_PROPERTIES(nextservice);
2425 mlt_type = mlt_properties_get(properties, "mlt_type");
2426 resource = mlt_properties_get(properties, "mlt_service");
2428 m_isBlocked = false;
2429 mlt_service_unlock(service.get_service());
2430 m_mltConsumer->set("refresh", 1);
2434 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2435 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2436 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2438 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2439 mltAddTransition(tag, a_track, b_track, in, out, xml);
2441 //mltSavePlaylist();
2444 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2446 Mlt::Service service(m_mltProducer->parent().get_service());
2447 Mlt::Tractor tractor(service);
2448 Mlt::Field *field = tractor.field();
2450 //m_mltConsumer->set("refresh", 0);
2451 mlt_service serv = m_mltProducer->parent().get_service();
2453 mlt_service nextservice = mlt_service_get_producer(serv);
2454 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2455 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2456 QString resource = mlt_properties_get(properties, "mlt_service");
2457 int in_pos = (int) in.frames(m_fps);
2458 int out_pos = (int) out.frames(m_fps) - 1;
2460 while (mlt_type == "transition") {
2461 mlt_transition tr = (mlt_transition) nextservice;
2462 int currentTrack = mlt_transition_get_b_track(tr);
2463 int currentBTrack = mlt_transition_get_a_track(tr);
2464 int currentIn = (int) mlt_transition_get_in(tr);
2465 int currentOut = (int) mlt_transition_get_out(tr);
2467 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2469 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2470 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2471 QMap<QString, QString>::Iterator it;
2473 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2474 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2475 if (currentBTrack != a_track) {
2476 mlt_properties_set_int(properties, "a_track", a_track);
2478 for (it = map.begin(); it != map.end(); ++it) {
2480 char *name = decodedString(key);
2481 char *value = decodedString(it.value());
2482 mlt_properties_set(transproperties, name, value);
2483 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2484 //filter->set("kdenlive_id", id);
2490 nextservice = mlt_service_producer(nextservice);
2491 if (nextservice == NULL) break;
2492 properties = MLT_SERVICE_PROPERTIES(nextservice);
2493 mlt_type = mlt_properties_get(properties, "mlt_type");
2494 resource = mlt_properties_get(properties, "mlt_service");
2496 m_isBlocked = false;
2497 m_mltConsumer->set("refresh", 1);
2500 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2501 Mlt::Service service(m_mltProducer->parent().get_service());
2502 Mlt::Tractor tractor(service);
2503 Mlt::Field *field = tractor.field();
2505 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2506 mlt_service serv = m_mltProducer->parent().get_service();
2508 mlt_service nextservice = mlt_service_get_producer(serv);
2509 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2510 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2511 QString resource = mlt_properties_get(properties, "mlt_service");
2513 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2515 while (mlt_type == "transition") {
2516 mlt_transition tr = (mlt_transition) nextservice;
2517 int currentTrack = mlt_transition_get_b_track(tr);
2518 int currentIn = (int) mlt_transition_get_in(tr);
2519 int currentOut = (int) mlt_transition_get_out(tr);
2520 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2522 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2523 mlt_field_disconnect_service(field->get_field(), nextservice);
2526 nextservice = mlt_service_producer(nextservice);
2527 if (nextservice == NULL) break;
2528 properties = MLT_SERVICE_PROPERTIES(nextservice);
2529 mlt_type = mlt_properties_get(properties, "mlt_type");
2530 resource = mlt_properties_get(properties, "mlt_service");
2532 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2535 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2536 QDomNodeList attribs = xml.elementsByTagName("parameter");
2537 QMap<QString, QString> map;
2538 for (int i = 0;i < attribs.count();i++) {
2539 QDomElement e = attribs.item(i).toElement();
2540 QString name = e.attribute("name");
2541 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2542 map[name] = e.attribute("default");
2543 if (!e.attribute("value").isEmpty()) {
2544 map[name] = e.attribute("value");
2546 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2547 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2548 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2551 if (e.attribute("namedesc").contains(';')) {
2552 QString format = e.attribute("format");
2553 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2554 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2556 QTextStream txtNeu(&neu);
2557 if (values.size() > 0)
2558 txtNeu << (int)values[0].toDouble();
2560 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2561 txtNeu << separators[i];
2562 txtNeu << (int)(values[i+1].toDouble());
2564 if (i < separators.size())
2565 txtNeu << separators[i];
2566 map[e.attribute("name")] = neu;
2573 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2574 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2575 Mlt::Service service(m_mltProducer->parent().get_service());
2576 Mlt::Tractor tractor(service);
2577 Mlt::Field *field = tractor.field();
2579 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2580 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2581 transition->set("transparency", id);
2582 transition->set("fill", 1);
2583 transition->set("internal_added", 237);
2584 field->plant_transition(*transition, transitiontrack, info.track);
2588 void Render::mltDeleteTransparency(int pos, int track, int id) {
2589 Mlt::Service service(m_mltProducer->parent().get_service());
2590 Mlt::Tractor tractor(service);
2591 Mlt::Field *field = tractor.field();
2593 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2594 mlt_service serv = m_mltProducer->parent().get_service();
2596 mlt_service nextservice = mlt_service_get_producer(serv);
2597 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2598 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2599 QString resource = mlt_properties_get(properties, "mlt_service");
2601 while (mlt_type == "transition") {
2602 mlt_transition tr = (mlt_transition) nextservice;
2603 int currentTrack = mlt_transition_get_b_track(tr);
2604 int currentIn = (int) mlt_transition_get_in(tr);
2605 int currentOut = (int) mlt_transition_get_out(tr);
2606 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2607 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2609 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2610 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2611 mlt_field_disconnect_service(field->get_field(), nextservice);
2614 nextservice = mlt_service_producer(nextservice);
2615 if (nextservice == NULL) break;
2616 properties = MLT_SERVICE_PROPERTIES(nextservice);
2617 mlt_type = mlt_properties_get(properties, "mlt_type");
2618 resource = mlt_properties_get(properties, "mlt_service");
2620 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2623 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2624 Mlt::Service service(m_mltProducer->parent().get_service());
2625 Mlt::Tractor tractor(service);
2626 Mlt::Field *field = tractor.field();
2628 mlt_service_lock(service.get_service());
2629 m_mltConsumer->set("refresh", 0);
2632 mlt_service serv = m_mltProducer->parent().get_service();
2633 mlt_service nextservice = mlt_service_get_producer(serv);
2634 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2635 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2636 QString resource = mlt_properties_get(properties, "mlt_service");
2637 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2638 while (mlt_type == "transition") {
2639 mlt_transition tr = (mlt_transition) nextservice;
2640 int currentTrack = mlt_transition_get_b_track(tr);
2641 int currentIn = (int) mlt_transition_get_in(tr);
2642 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2643 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2644 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2645 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2646 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2647 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2650 nextservice = mlt_service_producer(nextservice);
2651 if (nextservice == NULL) break;
2652 properties = MLT_SERVICE_PROPERTIES(nextservice);
2653 mlt_type = mlt_properties_get(properties, "mlt_type");
2654 resource = mlt_properties_get(properties, "mlt_service");
2656 m_isBlocked = false;
2657 mlt_service_unlock(service.get_service());
2658 m_mltConsumer->set("refresh", 1);
2662 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2663 Mlt::Service service(m_mltProducer->parent().get_service());
2664 Mlt::Tractor tractor(service);
2665 Mlt::Field *field = tractor.field();
2667 mlt_service_lock(service.get_service());
2668 m_mltConsumer->set("refresh", 0);
2671 mlt_service serv = m_mltProducer->parent().get_service();
2672 mlt_service nextservice = mlt_service_get_producer(serv);
2673 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2674 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2675 QString resource = mlt_properties_get(properties, "mlt_service");
2677 while (mlt_type == "transition") {
2678 mlt_transition tr = (mlt_transition) nextservice;
2679 int currentTrack = mlt_transition_get_b_track(tr);
2680 int currentaTrack = mlt_transition_get_a_track(tr);
2681 int currentIn = (int) mlt_transition_get_in(tr);
2682 int currentOut = (int) mlt_transition_get_out(tr);
2683 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2684 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2685 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2686 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2687 kDebug() << "//////MOVING";
2688 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2689 if (endTrack != startTrack) {
2690 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2691 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2692 mlt_properties_set_int(properties, "b_track", endTrack);
2696 nextservice = mlt_service_producer(nextservice);
2697 if (nextservice == NULL) break;
2698 properties = MLT_SERVICE_PROPERTIES(nextservice);
2699 mlt_type = mlt_properties_get(properties, "mlt_type");
2700 resource = mlt_properties_get(properties, "mlt_service");
2702 m_isBlocked = false;
2703 mlt_service_unlock(service.get_service());
2704 m_mltConsumer->set("refresh", 1);
2708 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2709 if (in >= out) return false;
2710 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2711 Mlt::Service service(m_mltProducer->parent().get_service());
2713 Mlt::Tractor tractor(service);
2714 Mlt::Field *field = tractor.field();
2716 char *transId = decodedString(tag);
2717 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2718 if (out != GenTime())
2719 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2720 QMap<QString, QString>::Iterator it;
2722 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2723 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2725 for (it = args.begin(); it != args.end(); ++it) {
2727 char *name = decodedString(key);
2728 char *value = decodedString(it.value());
2729 transition->set(name, value);
2730 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2731 //filter->set("kdenlive_id", id);
2735 // attach filter to the clip
2736 field->plant_transition(*transition, a_track, b_track);
2742 void Render::mltSavePlaylist() {
2743 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2744 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2745 fileConsumer.set("resource", "/tmp/playlist.westley");
2747 Mlt::Service service(m_mltProducer->get_service());
2749 fileConsumer.connect(service);
2750 fileConsumer.start();
2753 QList <Mlt::Producer *> Render::producersList() {
2754 QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
2755 Mlt::Service service(m_mltProducer->parent().get_service());
2756 if (service.type() != tractor_type) return prods;
2757 Mlt::Tractor tractor(service);
2760 int trackNb = tractor.count();
2761 for (int t = 1; t < trackNb; t++) {
2762 Mlt::Producer trackProducer(tractor.track(t));
2763 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2764 int clipNb = trackPlaylist.count();
2765 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2766 for (int i = 0; i < clipNb; i++) {
2767 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2768 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2769 ids.append(nprod->get("id"));
2770 prods.append(nprod);
2777 void Render::fillSlowMotionProducers() {
2778 Mlt::Service service(m_mltProducer->parent().get_service());
2779 if (service.type() != tractor_type) return;
2781 Mlt::Tractor tractor(service);
2783 int trackNb = tractor.count();
2784 for (int t = 1; t < trackNb; t++) {
2785 Mlt::Producer trackProducer(tractor.track(t));
2786 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2787 int clipNb = trackPlaylist.count();
2788 for (int i = 0; i < clipNb; i++) {
2789 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2790 if (nprod && !nprod->is_blank()) {
2791 QString id = nprod->get("id");
2792 if (id.startsWith("slowmotion:")) {
2793 // this is a slowmotion producer, add it to the list
2794 QString url = QString::fromUtf8(nprod->get("resource"));
2795 if (!m_slowmotionProducers.contains(url)) {
2796 m_slowmotionProducers.insert(url, nprod);
2804 void Render::mltInsertTrack(int ix, bool videoTrack) {
2808 m_mltConsumer->set("refresh", 0);
2809 mlt_service_lock(m_mltConsumer->get_service());
2810 Mlt::Service service(m_mltProducer->parent().get_service());
2811 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2813 Mlt::Tractor tractor(service);
2815 Mlt::Playlist playlist;// = new Mlt::Playlist();
2816 int ct = tractor.count();
2817 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2820 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2821 tractor.set_track(playlist, pos);
2822 Mlt::Producer newProd(tractor.track(pos));
2823 if (!videoTrack) newProd.set("hide", 1);
2825 for (; pos <= ct; pos++) {
2826 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2827 tractor.set_track(*prodToMove, pos);
2828 prodToMove = prodToMove2;
2831 tractor.set_track(playlist, ix);
2832 Mlt::Producer newProd(tractor.track(ix));
2833 if (!videoTrack) newProd.set("hide", 1);
2837 mlt_service serv = m_mltProducer->parent().get_service();
2838 mlt_service nextservice = mlt_service_get_producer(serv);
2839 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2840 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2841 QString resource = mlt_properties_get(properties, "mlt_service");
2843 while (mlt_type == "transition") {
2844 if (resource != "mix") {
2845 mlt_transition tr = (mlt_transition) nextservice;
2846 int currentTrack = mlt_transition_get_b_track(tr);
2847 int currentaTrack = mlt_transition_get_a_track(tr);
2848 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2850 if (currentTrack >= ix) {
2851 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2852 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2855 nextservice = mlt_service_producer(nextservice);
2856 if (nextservice == NULL) break;
2857 properties = MLT_SERVICE_PROPERTIES(nextservice);
2858 mlt_type = mlt_properties_get(properties, "mlt_type");
2859 resource = mlt_properties_get(properties, "mlt_service");
2862 // Add audio mix transition to last track
2863 Mlt::Field *field = tractor.field();
2864 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2865 //transition->set("mlt_service", "mix");
2866 transition->set("a_track", 1);
2867 transition->set("b_track", ct);
2868 transition->set("always_active", 1);
2869 transition->set("internal_added", 237);
2870 transition->set("combine", 1);
2871 field->plant_transition(*transition, 1, ct);
2873 mlt_service_unlock(m_mltConsumer->get_service());
2874 m_isBlocked = false;
2875 blockSignals(false);
2879 void Render::mltDeleteTrack(int ix) {
2881 doc.setContent(sceneList(), false);
2882 int tracksCount = doc.elementsByTagName("track").count() - 1;
2883 QDomNode track = doc.elementsByTagName("track").at(ix);
2884 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2885 QDomNodeList transitions = doc.elementsByTagName("transition");
2886 for (int i = 0; i < transitions.count(); i++) {
2887 QDomElement e = transitions.at(i).toElement();
2888 QDomNodeList props = e.elementsByTagName("property");
2889 QMap <QString, QString> mappedProps;
2890 for (int j = 0; j < props.count(); j++) {
2891 QDomElement f = props.at(j).toElement();
2892 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2894 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2895 tractor.removeChild(transitions.at(i));
2896 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2897 // Transition needs to be moved
2898 int a_track = mappedProps.value("a_track").toInt();
2899 int b_track = mappedProps.value("b_track").toInt();
2900 if (a_track > 0) a_track --;
2901 if (b_track > 0) b_track --;
2902 for (int j = 0; j < props.count(); j++) {
2903 QDomElement f = props.at(j).toElement();
2904 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2905 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2910 tractor.removeChild(track);
2911 setSceneList(doc.toString(), m_framePosition);
2918 m_mltConsumer->set("refresh", 0);
2919 mlt_service_lock(m_mltConsumer->get_service());
2920 Mlt::Service service(m_mltProducer->parent().get_service());
2921 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2923 /*Mlt::Tractor tractor(service);
2926 Mlt::Multitrack *multi = tractor.multitrack();
2929 int ct = tractor.count();
2930 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
2932 for (; pos < ct ; pos++) {
2933 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
2934 //mlt_service_close(lastTrack->get_service());
2936 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
2937 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
2938 mlt_service_close(prodToMove->get_service());
2939 mlt_service_close(prodToClose->get_service());
2940 tractor.set_track(*prodToMove, pos);
2944 /*mlt_service serv = m_mltProducer->parent().get_service();
2945 mlt_service nextservice = mlt_service_get_producer(serv);
2946 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2947 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2948 QString resource = mlt_properties_get(properties, "mlt_service");
2950 while (mlt_type == "transition") {
2951 if (resource != "mix") {
2952 mlt_transition tr = (mlt_transition) nextservice;
2953 int currentTrack = mlt_transition_get_b_track(tr);
2954 int currentaTrack = mlt_transition_get_a_track(tr);
2955 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2957 if (currentTrack >= ix) {
2958 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2959 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2962 nextservice = mlt_service_producer(nextservice);
2963 if (nextservice == NULL) break;
2964 properties = MLT_SERVICE_PROPERTIES(nextservice);
2965 mlt_type = mlt_properties_get(properties, "mlt_type");
2966 resource = mlt_properties_get(properties, "mlt_service");
2969 // Add audio mix transition to last track
2970 Mlt::Field *field = tractor.field();
2971 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2972 //transition->set("mlt_service", "mix");
2973 transition->set("a_track", 1);
2974 transition->set("b_track", ct);
2975 transition->set("always_active", 1);
2976 transition->set("internal_added", 237);
2977 transition->set("combine", 1);
2978 field->plant_transition(*transition, 1, ct);
2981 mlt_service_unlock(m_mltConsumer->get_service());
2982 m_isBlocked = false;
2983 blockSignals(false);
2987 void Render::updatePreviewSettings() {
2988 kDebug() << "////// RESTARTING CONSUMER";
2989 if (!m_mltConsumer || !m_mltProducer) return;
2990 if (m_mltProducer->get_playtime() == 0) return;
2991 Mlt::Service service(m_mltProducer->parent().get_service());
2992 if (service.type() != tractor_type) return;
2994 //m_mltConsumer->set("refresh", 0);
2995 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
2996 m_mltConsumer->purge();
2997 QString scene = sceneList();
2999 if (m_mltProducer) {
3000 pos = m_mltProducer->position();
3001 delete m_mltProducer;
3003 m_mltProducer = NULL;
3004 setSceneList(scene, pos);
3007 #include "renderer.moc"