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 ***************************************************************************/
25 // ffmpeg Header files
35 #include <QApplication>
39 #include <KStandardDirs>
40 #include <KMessageBox>
42 #include <KTemporaryFile>
45 #include "kdenlivesettings.h"
47 #include "definitions.h"
49 #include <mlt++/Mlt.h>
51 #if LIBAVCODEC_VERSION_MAJOR > 51 || (LIBAVCODEC_VERSION_MAJOR > 50 && LIBAVCODEC_VERSION_MINOR > 54)
52 // long_name was added in FFmpeg avcodec version 51.55
53 #define ENABLE_FFMPEG_CODEC_DESCRIPTION 1
58 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
59 // detect if the producer has finished playing. Is there a better way to do it ?
60 if (self->m_isBlocked) return;
61 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
62 self->emitConsumerStopped();
64 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
68 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(-1), m_framePosition(0), m_generateScenelist(false), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false) {
69 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
70 refreshTimer = new QTimer(this);
71 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
73 if (rendererName == "project") m_monitorId = 10000;
74 else m_monitorId = 10001;
75 osdTimer = new QTimer(this);
76 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
78 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
81 m_externalwinid = extid;
83 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
84 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black");
85 m_mltProducer = producer;
86 if (m_blackClip) delete m_blackClip;
87 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
88 m_blackClip->set("id", "black");
89 m_mltConsumer->connect(*m_mltProducer);
90 m_mltProducer->set_speed(0.0);
98 void Render::closeMlt() {
102 delete m_mltConsumer;
104 delete m_mltProducer;
105 if (m_blackClip) delete m_blackClip;
110 void Render::buildConsumer() {
112 tmp = decodedString(KdenliveSettings::current_profile());
113 m_mltProfile = new Mlt::Profile(tmp);
115 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
116 m_mltConsumer->set("resize", 1);
117 m_mltConsumer->set("window_id", m_winid);
118 m_mltConsumer->set("terminate_on_pause", 1);
119 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
120 m_mltConsumer->set("rescale", "nearest");
121 QString audioDevice = KdenliveSettings::audiodevicename();
122 if (!audioDevice.isEmpty()) {
123 tmp = decodedString(audioDevice);
124 m_mltConsumer->set("audio_device", tmp);
128 QString videoDriver = KdenliveSettings::videodrivername();
129 if (!videoDriver.isEmpty()) {
130 if (videoDriver == "x11_noaccel") {
131 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
132 m_mltConsumer->set("video_driver", "x11");
134 unsetenv("SDL_VIDEO_YUV_HWACCEL");
135 tmp = decodedString(videoDriver);
136 m_mltConsumer->set("video_driver", tmp);
141 QString audioDriver = KdenliveSettings::audiodrivername();
142 if (!audioDriver.isEmpty()) {
143 tmp = decodedString(audioDriver);
144 m_mltConsumer->set("audio_driver", tmp);
149 m_mltConsumer->set("progressive", 1);
150 m_mltConsumer->set("audio_buffer", 1024);
151 m_mltConsumer->set("frequency", 48000);
154 int Render::resetProfile() {
155 if (!m_mltConsumer) return 0;
156 if (m_isSplitView) slotSplitView(false);
157 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
158 m_mltConsumer->purge();
159 delete m_mltConsumer;
160 m_mltConsumer = NULL;
161 QString scene = sceneList();
162 if (m_mltProducer) delete m_mltProducer;
163 m_mltProducer = NULL;
164 if (m_mltProfile) delete m_mltProfile;
168 kDebug() << "//RESET WITHSCENE: " << scene;
171 char *tmp = decodedString(scene);
172 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
174 m_mltProducer = producer;
175 if (m_blackClip) delete m_blackClip;
176 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
177 m_mltProducer->optimise();
178 m_mltProducer->set_speed(0);
181 //delete m_mltProfile;
182 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
183 //mlt_profile prof = m_mltProfile->get_profile();
184 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
185 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
186 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
187 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
189 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
194 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
195 void Render::seek(GenTime time) {
196 sendSeekCommand(time);
197 //emit positionChanged(time);
201 char *Render::decodedString(QString str) {
202 /*QCString fn = QFile::encodeName(str);
203 char *t = new char[fn.length() + 1];
204 strcpy(t, (const char *)fn);*/
206 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
210 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
211 QPixmap pix(width, height);
213 mlt_image_format format = mlt_image_rgb24a;
214 uint8_t *thumb = frame->get_image(format, width, height);
215 QImage image(thumb, width, height, QImage::Format_ARGB32);
217 if (!image.isNull()) {
218 pix = pix.fromImage(image);
220 QPainter painter(&pix);
221 painter.drawRect(0, 0, width - 1, height - 1);
223 } else pix.fill(Qt::black);
227 const int Render::renderWidth() const {
228 return (int)(m_mltProfile->height() * m_mltProfile->dar());
231 const int Render::renderHeight() const {
232 return m_mltProfile->height();
235 QPixmap Render::extractFrame(int frame_position, int width, int height) {
237 width = renderWidth();
238 height = renderHeight();
240 QPixmap pix(width, height);
241 if (!m_mltProducer) {
245 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
248 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
251 if (url.fileName().startsWith(".all.")) { // check for slideshow
252 QString fileType = url.fileName().right(3);
254 QStringList::Iterator it;
256 QDir dir(url.directory());
258 filter << "*." + fileType;
259 filter << "*." + fileType.toUpper();
260 more = dir.entryList(filter, QDir::Files);
261 im.load(url.directory() + "/" + more.at(0));
262 } else im.load(url.path());
263 //pixmap = im.scaled(width, height);
268 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
269 QPixmap pix(width, height);
270 char *tmp = decodedString(file);
271 Mlt::Profile *prof = new Mlt::Profile(profile);
272 Mlt::Producer m_producer(*prof, tmp);
274 if (m_producer.is_blank()) {
279 Mlt::Filter m_convert(*prof, "avcolour_space");
280 m_convert.set("forced", mlt_image_rgb24a);
281 m_producer.attach(m_convert);
282 m_producer.seek(frame_position);
283 Mlt::Frame * frame = m_producer.get_frame();
285 pix = frameThumbnail(frame, width, height, true);
288 if (prof) delete prof;
293 void Render::getImage(KUrl url, int frame_position, QPoint size)
295 char *tmp = decodedString(url.path());
296 Mlt::Producer m_producer(tmp);
298 if (m_producer.is_blank()) {
301 Mlt::Filter m_convert("avcolour_space");
302 m_convert.set("forced", mlt_image_rgb24a);
303 m_producer.attach(m_convert);
304 m_producer.seek(frame_position);
306 Mlt::Frame * frame = m_producer.get_frame();
309 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
311 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
315 /* Create thumbnail for color */
316 /*void Render::getImage(int id, QString color, QPoint size)
318 QPixmap pixmap(size.x() - 2, size.y() - 2);
319 color = color.replace(0, 2, "#");
320 color = color.left(7);
321 pixmap.fill(QColor(color));
322 QPixmap result(size.x(), size.y());
323 result.fill(Qt::black);
324 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
325 emit replyGetImage(id, result, size.x(), size.y());
329 /* Create thumbnail for image */
330 /*void Render::getImage(KUrl url, QPoint size)
334 if (url.fileName().startsWith(".all.")) { // check for slideshow
335 QString fileType = url.fileName().right(3);
337 QStringList::Iterator it;
339 QDir dir( url.directory() );
340 more = dir.entryList( QDir::Files );
341 for ( it = more.begin() ; it != more.end() ; ++it ) {
342 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
343 if (!im.load(url.directory() + "/" + *it))
344 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
349 else im.load(url.path());
351 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
352 QPixmap result(size.x(), size.y());
353 result.fill(Qt::black);
354 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
355 emit replyGetImage(url, 1, result, size.x(), size.y());
359 double Render::consumerRatio() const {
360 if (!m_mltConsumer) return 1.0;
361 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
365 int Render::getLength() {
368 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
369 return mlt_producer_get_playtime(m_mltProducer->get_producer());
374 bool Render::isValid(KUrl url) {
375 char *tmp = decodedString(url.path());
376 Mlt::Producer producer(*m_mltProfile, tmp);
378 if (producer.is_blank())
384 const double Render::dar() const {
385 return m_mltProfile->dar();
388 void Render::slotSplitView(bool doit) {
389 m_isSplitView = doit;
390 Mlt::Service service(m_mltProducer->parent().get_service());
391 Mlt::Tractor tractor(service);
392 if (service.type() != tractor_type || tractor.count() < 2) return;
393 Mlt::Field *field = tractor.field();
396 for (int i = 1; i < tractor.count() && screen < 4; i++) {
397 Mlt::Producer trackProducer(tractor.track(i));
398 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
399 if (QString(trackProducer.get("hide")).toInt() != 1) {
400 kDebug() << "// ADIDNG TRACK: " << i;
401 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
402 transition->set("mlt_service", "composite");
403 transition->set("a_track", 0);
404 transition->set("b_track", i);
405 transition->set("distort", 1);
406 transition->set("internal_added", "200");
413 tmp = "50%,0:50%x50%";
416 tmp = "0,50%:50%x50%";
419 tmp = "50%,50%:50%x50%";
422 transition->set("geometry", tmp);
423 transition->set("always_active", "1");
424 field->plant_transition(*transition, 0, i);
429 m_mltConsumer->set("refresh", 1);
431 mlt_service serv = m_mltProducer->parent().get_service();
432 mlt_service nextservice = mlt_service_get_producer(serv);
433 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
434 QString mlt_type = mlt_properties_get(properties, "mlt_type");
435 QString resource = mlt_properties_get(properties, "mlt_service");
437 while (mlt_type == "transition") {
438 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
439 if (added == "200") {
440 mlt_field_disconnect_service(field->get_field(), nextservice);
442 nextservice = mlt_service_producer(nextservice);
443 if (nextservice == NULL) break;
444 properties = MLT_SERVICE_PROPERTIES(nextservice);
445 mlt_type = mlt_properties_get(properties, "mlt_type");
446 resource = mlt_properties_get(properties, "mlt_service");
447 m_mltConsumer->set("refresh", 1);
452 void Render::getFileProperties(const QDomElement &xml, int clipId) {
454 int width = (int)(height * m_mltProfile->dar());
455 QMap < QString, QString > filePropertyMap;
456 QMap < QString, QString > metadataPropertyMap;
458 KUrl url = KUrl(xml.attribute("resource", QString::null));
459 Mlt::Producer *producer;
460 if (xml.attribute("type").toInt() == COLOR) {
461 char *tmp = decodedString("colour:" + xml.attribute("colour"));
462 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
464 } else if (url.isEmpty()) {
466 QDomElement westley = doc.createElement("westley");
467 QDomElement play = doc.createElement("playlist");
468 doc.appendChild(westley);
469 westley.appendChild(play);
470 play.appendChild(doc.importNode(xml, true));
471 kDebug() << "/ / / / /CLIP XML: " << doc.toString();
472 char *tmp = decodedString(doc.toString());
473 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
476 char *tmp = decodedString(url.path());
477 producer = new Mlt::Producer(*m_mltProfile, tmp);
480 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
482 if (producer->is_blank()) {
483 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
484 emit removeInvalidClip(clipId);
487 producer->set("id", clipId);
488 int frameNumber = xml.attribute("thumbnail", "0").toInt();
489 if (frameNumber != 0) producer->seek(frameNumber);
490 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
492 filePropertyMap["filename"] = url.path();
493 filePropertyMap["duration"] = QString::number(producer->get_playtime());
494 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
496 Mlt::Frame * frame = producer->get_frame();
498 if (xml.attribute("type").toInt() == SLIDESHOW) {
499 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
500 if (xml.attribute("fade") == "1") {
501 // user wants a fade effect to slideshow
502 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
503 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
504 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
505 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
506 char *tmp = decodedString(xml.attribute("luma_file"));
507 filter->set("luma.resource", tmp);
509 if (xml.hasAttribute("softness")) {
510 int soft = xml.attribute("softness").toInt();
511 filter->set("luma.softness", (double) soft / 100.0);
514 Mlt::Service clipService(producer->get_service());
515 clipService.attach(*filter);
520 filePropertyMap["fps"] = producer->get("source_fps");
522 if (frame && frame->is_valid()) {
523 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
524 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
525 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
526 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
528 if (frame->get_int("test_image") == 0) {
529 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
530 filePropertyMap["type"] = "playlist";
531 metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer->get_service()), "title"));
532 } else if (frame->get_int("test_audio") == 0)
533 filePropertyMap["type"] = "av";
535 filePropertyMap["type"] = "video";
537 mlt_image_format format = mlt_image_yuv422;
539 int frame_height = 0;
540 //frame->set("rescale.interp", "hyper");
541 frame->set("normalised_height", height);
542 frame->set("normalised_width", width);
543 QPixmap pix(width, height);
545 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
546 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
547 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
548 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
550 if (!image.isNull()) {
551 pix = pix.fromImage(image.rgbSwapped());
555 mlt_pool_release(new_image);
556 emit replyGetImage(clipId, 0, pix, width, height);
558 } else if (frame->get_int("test_audio") == 0) {
559 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
560 emit replyGetImage(clipId, 0, pixmap, width, height);
561 filePropertyMap["type"] = "audio";
565 // Retrieve audio / video codec name
567 // Fetch the video_context
570 AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
571 if (context != NULL) {
572 // Get the video_index
573 int index = mlt_properties_get_int(properties, "video_index");
575 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
576 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) {
577 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name;
580 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) {
581 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
583 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
584 context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
585 if (context != NULL) {
586 // Get the audio_index
587 int index = mlt_properties_get_int(properties, "audio_index");
589 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
590 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
591 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name;
594 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
595 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
600 mlt_properties metadata = mlt_properties_new();
601 mlt_properties_pass(metadata, properties, "meta.attr.");
602 int count = mlt_properties_count(metadata);
603 for (int i = 0; i < count; i ++) {
604 QString name = mlt_properties_get_name(metadata, i);
605 QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
606 if (name.endsWith("markup") && !value.isEmpty())
607 metadataPropertyMap[ name.section(".", 0, -2)] = value;
610 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
611 kDebug() << "REquested fuile info for: " << url.path();
612 if (frame) delete frame;
613 //if (producer) delete producer;
616 /** Create the producer from the Westley QDomDocument */
618 void Render::initSceneList() {
619 kDebug() << "-------- INIT SCENE LIST ------_";
621 QDomElement westley = doc.createElement("westley");
622 doc.appendChild(westley);
623 QDomElement prod = doc.createElement("producer");
624 prod.setAttribute("resource", "colour");
625 prod.setAttribute("colour", "red");
626 prod.setAttribute("id", "black");
627 prod.setAttribute("in", "0");
628 prod.setAttribute("out", "0");
630 QDomElement tractor = doc.createElement("tractor");
631 QDomElement multitrack = doc.createElement("multitrack");
633 QDomElement playlist1 = doc.createElement("playlist");
634 playlist1.appendChild(prod);
635 multitrack.appendChild(playlist1);
636 QDomElement playlist2 = doc.createElement("playlist");
637 multitrack.appendChild(playlist2);
638 QDomElement playlist3 = doc.createElement("playlist");
639 multitrack.appendChild(playlist3);
640 QDomElement playlist4 = doc.createElement("playlist");
641 multitrack.appendChild(playlist4);
642 QDomElement playlist5 = doc.createElement("playlist");
643 multitrack.appendChild(playlist5);
644 tractor.appendChild(multitrack);
645 westley.appendChild(tractor);
646 // kDebug()<<doc.toString();
648 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
649 setSceneList(doc, 0);
655 /** Create the producer from the Westley QDomDocument */
656 void Render::setProducer(Mlt::Producer *producer, int position) {
657 if (m_winid == -1) return;
658 m_generateScenelist = true;
661 m_mltConsumer->stop();
665 m_mltProducer->set_speed(0);
666 delete m_mltProducer;
667 m_mltProducer = NULL;
670 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
671 else m_mltProducer = new Mlt::Producer();
672 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
674 m_fps = m_mltProducer->get_fps();
676 if (position != -1) {
677 m_mltProducer->seek(position);
678 emit rendererPosition(position);
680 m_generateScenelist = false;
685 /** Create the producer from the Westley QDomDocument */
686 void Render::setSceneList(QDomDocument list, int position) {
687 setSceneList(list.toString(), position);
690 /** Create the producer from the Westley QDomDocument */
691 void Render::setSceneList(QString playlist, int position) {
692 if (m_winid == -1) return;
693 m_generateScenelist = true;
695 kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
699 if (!clip.is_valid()) {
700 kWarning()<<" ++++ WARNING, UNABLE TO CREATE MLT PRODUCER";
701 m_generateScenelist = false;
706 m_mltConsumer->stop();
707 //m_mltConsumer->set("refresh", 0);
711 m_mltProducer->set_speed(0);
712 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
714 delete m_mltProducer;
715 m_mltProducer = NULL;
719 char *tmp = decodedString(playlist);
720 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
722 if (m_blackClip) delete m_blackClip;
723 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
724 m_blackClip->set("id", "black");
725 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
726 m_mltProducer->optimise();
728 /*if (KdenliveSettings::osdtimecode()) {
729 // Attach filter for on screen display of timecode
731 QString attr = "attr_check";
732 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
733 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
734 mlt_producer_attach( m_mltProducer->get_producer(), filter );
735 mlt_filter_close( filter );
737 m_osdInfo = new Mlt::Filter("data_show");
738 tmp = decodedString(m_osdProfile);
739 m_osdInfo->set("resource", tmp);
741 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
742 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
743 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
744 m_osdInfo->set("dynamic", "1");
746 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
748 m_osdInfo->set("dynamic", "0");
751 m_fps = m_mltProducer->get_fps();
752 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
755 m_mltProducer->seek(position);
756 emit rendererPosition(position);
758 m_generateScenelist = false;
762 /** Create the producer from the Westley QDomDocument */
763 QString Render::sceneList() {
768 saveSceneList(temp.fileName());
769 QFile file(temp.fileName());
770 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
771 kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE";
774 QTextStream in(&file);
775 while (!in.atEnd()) {
776 result.append(in.readLine());
782 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
784 char *tmppath = decodedString("westley:" + path);
785 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
786 m_mltProducer->optimise();
788 westleyConsumer.set("terminate_on_pause", 1);
789 Mlt::Producer prod(m_mltProducer->get_producer());
790 bool split = m_isSplitView;
791 if (split) slotSplitView(false);
792 westleyConsumer.connect(prod);
793 //prod.set("title", "kdenlive document");
794 //westleyConsumer.listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
795 westleyConsumer.start();
796 while (!westleyConsumer.is_stopped()) {}
797 if (!kdenliveData.isNull()) {
798 // add Kdenlive specific tags
801 doc.setContent(&file, false);
802 QDomNode wes = doc.elementsByTagName("westley").at(0);
803 wes.appendChild(doc.importNode(kdenliveData, true));
805 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
806 kWarning() << "////// ERROR writing to file: " << path;
809 QTextStream out(&file);
810 out << doc.toString();
813 if (split) slotSplitView(true);
817 const double Render::fps() const {
821 void Render::connectPlaylist() {
822 if (!m_mltConsumer) return;
823 //m_mltConsumer->set("refresh", "0");
824 m_mltConsumer->connect(*m_mltProducer);
825 m_mltProducer->set_speed(0);
826 m_mltConsumer->start();
827 emit durationChanged(m_mltProducer->get_playtime());
830 if (m_mltConsumer->start() == -1) {
831 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."));
832 m_mltConsumer = NULL;
839 void Render::refreshDisplay() {
841 if (!m_mltProducer) return;
842 //m_mltConsumer->set("refresh", 0);
844 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
845 /*if (KdenliveSettings::osdtimecode()) {
846 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
847 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
848 m_osdInfo->set("dynamic", "1");
849 m_mltProducer->attach(*m_osdInfo);
852 m_mltProducer->detach(*m_osdInfo);
853 m_osdInfo->set("dynamic", "0");
858 void Render::setVolume(double volume) {
859 if (!m_mltConsumer || !m_mltProducer) return;
861 m_mltConsumer->set("refresh", 0);
862 // Attach filter for on screen display of timecode
863 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
864 mlt_properties_set_double( properties, "meta.volume", volume );
865 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
866 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
868 if (!KdenliveSettings::osdtimecode()) {
869 m_mltProducer->detach(*m_osdInfo);
870 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
871 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
874 osdTimer->setSingleShot(2500);
877 void Render::slotOsdTimeout() {
878 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
879 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
880 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
881 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
885 void Render::start() {
886 kDebug() << "----- STARTING MONITOR: " << m_name;
888 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
892 if (m_mltConsumer->is_stopped()) {
893 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
894 if (m_mltConsumer->start() == -1) {
895 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."));
896 m_mltConsumer = NULL;
899 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
907 void Render::clear() {
908 kDebug() << " ********* RENDER CLEAR";
910 //m_mltConsumer->set("refresh", 0);
911 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
915 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
916 m_mltProducer->set_speed(0.0);
917 delete m_mltProducer;
918 m_mltProducer = NULL;
923 void Render::stop() {
924 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
925 kDebug() << "///////////// RENDER STOPPED: " << m_name;
926 //m_mltConsumer->set("refresh", 0);
927 m_mltConsumer->stop();
929 kDebug() << "///////////// RENDER STOP2-------";
933 m_mltProducer->set_speed(0.0);
934 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
935 kDebug() << m_mltProducer->get_length();
937 kDebug() << "///////////// RENDER STOP3-------";
940 void Render::stop(const GenTime & startTime) {
942 kDebug() << "///////////// RENDER STOP-------2";
944 m_mltProducer->set_speed(0.0);
945 m_mltProducer->seek((int) startTime.frames(m_fps));
947 m_mltConsumer->purge();
950 void Render::switchPlay() {
953 if (m_mltProducer->get_speed() == 0.0) {
954 //m_isBlocked = false;
955 m_mltProducer->set_speed(1.0);
956 m_mltConsumer->set("refresh", 1);
957 kDebug() << " ********* RENDER PLAY: " << m_mltProducer->get_speed();
959 //m_isBlocked = true;
960 m_mltConsumer->set("refresh", 0);
961 m_mltProducer->set_speed(0.0);
962 //m_isBlocked = true;
963 m_mltProducer->seek((int) m_framePosition);
964 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
965 //m_mltConsumer->set("refresh", 0);
966 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
967 m_mltProducer->set_speed(0);
968 m_mltProducer->seek( position );
969 //m_mltProducer->seek((int) m_framePosition);
970 m_isBlocked = false;*/
972 /*if (speed == 0.0) {
973 m_mltProducer->seek((int) m_framePosition + 1);
974 m_mltConsumer->purge();
979 void Render::play(double speed) {
980 kDebug() << " ********* REDNER PLAY";
983 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
984 m_mltProducer->set_speed(speed);
985 /*if (speed == 0.0) {
986 m_mltProducer->seek((int) m_framePosition + 1);
987 m_mltConsumer->purge();
992 void Render::play(double speed, const GenTime & startTime) {
993 kDebug() << "///////////// RENDER PLAY2-------" << speed;
996 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
997 //if (speed == 0.0) m_mltConsumer->set("refresh", 0);
998 m_mltProducer->set_speed(speed);
999 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1000 //m_mltConsumer->purge();
1004 void Render::play(double speed, const GenTime & startTime,
1005 const GenTime & stopTime) {
1006 kDebug() << "///////////// RENDER PLAY3-------" << speed << stopTime.frames(m_fps);
1009 m_mltProducer->set("out", stopTime.frames(m_fps));
1010 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1011 m_mltConsumer->purge();
1012 m_mltProducer->set_speed(speed);
1017 void Render::sendSeekCommand(GenTime time) {
1018 //kDebug()<<" ********* RENDER SEND SEEK";
1021 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
1022 m_mltProducer->seek((int)(time.frames(m_fps)));
1026 void Render::seekToFrame(int pos) {
1027 //kDebug()<<" ********* RENDER SEEK TO POS";
1030 m_mltProducer->seek(pos);
1034 void Render::askForRefresh() {
1035 // Use a Timer so that we don't refresh too much
1036 refreshTimer->start(200);
1039 void Render::doRefresh() {
1040 // Use a Timer so that we don't refresh too much
1041 m_mltConsumer->set("refresh", 1);
1044 void Render::refresh() {
1045 if (!m_mltProducer || m_isBlocked)
1047 refreshTimer->stop();
1048 if (m_mltConsumer) {
1049 m_mltConsumer->set("refresh", 1);
1053 /** Sets the description of this renderer to desc. */
1054 void Render::setDescription(const QString & description) {
1055 m_description = description;
1058 /** Returns the description of this renderer */
1059 QString Render::description() {
1060 return m_description;
1064 double Render::playSpeed() {
1065 if (m_mltProducer) return m_mltProducer->get_speed();
1069 GenTime Render::seekPosition() const {
1070 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1071 else return GenTime();
1075 const QString & Render::rendererName() const {
1080 void Render::emitFrameNumber(double position) {
1081 if (m_generateScenelist) return;
1082 m_framePosition = position;
1083 emit rendererPosition((int) position);
1084 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1087 void Render::emitConsumerStopped() {
1088 // This is used to know when the playing stopped
1089 if (m_mltProducer && !m_generateScenelist) {
1090 double pos = m_mltProducer->position();
1091 emit rendererStopped((int) pos);
1092 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1093 //new QCustomEvent(10002));
1099 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1100 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1104 void Render::exportCurrentFrame(KUrl url, bool notify) {
1105 if (!m_mltProducer) {
1106 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1110 int height = 1080;//KdenliveSettings::defaultheight();
1111 int width = 1940; //KdenliveSettings::displaywidth();
1113 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1115 QPixmap pix(width, height);
1116 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1117 m_convert.set("forced", mlt_image_rgb24a);
1118 m_mltProducer->attach(m_convert);
1119 Mlt::Frame * frame = m_mltProducer->get_frame();
1120 m_mltProducer->detach(m_convert);
1122 pix = frameThumbnail(frame, width, height);
1125 pix.save(url.path(), "PNG");
1126 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1129 /** MLT PLAYLIST DIRECT MANIPULATON **/
1132 void Render::mltCheckLength(bool reload) {
1133 //kDebug()<<"checking track length: "<<track<<"..........";
1135 Mlt::Service service(m_mltProducer->get_service());
1136 Mlt::Tractor tractor(service);
1138 int trackNb = tractor.count();
1139 double duration = 0;
1140 double trackDuration;
1142 Mlt::Producer trackProducer(tractor.track(0));
1143 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1144 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1145 m_mltProducer->set("out", duration);
1146 emit durationChanged((int) duration);
1149 while (trackNb > 1) {
1150 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1151 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1152 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1154 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1155 if (trackDuration > duration) duration = trackDuration;
1159 Mlt::Producer blackTrackProducer(tractor.track(0));
1160 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1161 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1163 if (blackDuration != duration) {
1164 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1166 int dur = (int)duration;
1168 QDomElement black = doc.createElement("producer");
1169 black.setAttribute("mlt_service", "colour");
1170 black.setAttribute("colour", "black");
1171 black.setAttribute("id", "black");
1174 while (dur > 14000) {
1175 info.startPos = GenTime(i * 14000, m_fps);
1176 info.endPos = info.startPos + GenTime(13999, m_fps);
1177 mltInsertClip(info, black, m_blackClip);
1182 info.startPos = GenTime(i * 14000, m_fps);
1183 info.endPos = info.startPos + GenTime(dur, m_fps);
1184 mltInsertClip(info, black, m_blackClip);
1186 m_mltProducer->set("out", duration);
1187 emit durationChanged((int)duration);
1191 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1192 if (!m_mltProducer) {
1193 kDebug() << "PLAYLIST NOT INITIALISED //////";
1196 Mlt::Producer parentProd(m_mltProducer->parent());
1197 if (parentProd.get_producer() == NULL) {
1198 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1202 Mlt::Service service(parentProd.get_service());
1203 Mlt::Tractor tractor(service);
1204 mlt_service_lock(service.get_service());
1205 Mlt::Producer trackProducer(tractor.track(info.track));
1206 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1208 Mlt::Producer *clip = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1209 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1211 if (QString(prod->get("transparency")).toInt() == 1)
1212 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());
1214 mlt_service_unlock(service.get_service());
1216 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1217 //tractor.multitrack()->refresh();
1218 //tractor.refresh();
1222 void Render::mltCutClip(int track, GenTime position) {
1226 Mlt::Service service(m_mltProducer->parent().get_service());
1227 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1229 Mlt::Tractor tractor(service);
1230 Mlt::Producer trackProducer(tractor.track(track));
1231 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1234 /* // Display playlist info
1235 kDebug()<<"//////////// BEFORE";
1236 for (int i = 0; i < trackPlaylist.count(); i++) {
1237 int blankStart = trackPlaylist.clip_start(i);
1238 int blankDuration = trackPlaylist.clip_length(i) - 1;
1240 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1241 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1244 int cutPos = (int) position.frames(m_fps);
1246 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1247 if (trackPlaylist.is_blank(clipIndex)) {
1248 kDebug() << "// WARMNING, TRYING TO CUT A BLANK";
1249 m_isBlocked = false;
1252 mlt_service_lock(service.get_service());
1253 int clipStart = trackPlaylist.clip_start(clipIndex);
1254 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1256 // duplicate effects
1257 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1258 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1260 if (original == NULL || clip == NULL) {
1261 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1263 Mlt::Service clipService(original->get_service());
1264 Mlt::Service dupService(clip->get_service());
1266 Mlt::Filter *filter = clipService.filter(ct);
1268 if (filter->get("kdenlive_id") != "") {
1269 kDebug() << "++ ADDING FILTER: " << filter->get("kdenlive_id");
1270 Mlt::Filter *dup = new Mlt::Filter(filter->get_filter());
1271 dup->set("kdenlive_ix", filter->get("kdenlive_ix"));
1272 dup->set("kdenlive_id", filter->get("kdenlive_id"));
1273 dupService.attach(*dup);
1276 filter = clipService.filter(ct);
1278 mlt_service_unlock(service.get_service());
1280 /* // Display playlist info
1281 kDebug()<<"//////////// AFTER";
1282 for (int i = 0; i < trackPlaylist.count(); i++) {
1283 int blankStart = trackPlaylist.clip_start(i);
1284 int blankDuration = trackPlaylist.clip_length(i) - 1;
1286 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1287 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1290 m_isBlocked = false;
1293 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1295 mltRemoveClip(info.track, info.startPos);
1296 mltInsertClip(info, element, prod);
1300 bool Render::mltRemoveClip(int track, GenTime position) {
1301 Mlt::Service service(m_mltProducer->parent().get_service());
1302 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1304 Mlt::Tractor tractor(service);
1305 Mlt::Producer trackProducer(tractor.track(track));
1306 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1307 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1309 /* // Display playlist info
1310 kDebug()<<"//// BEFORE";
1311 for (int i = 0; i < trackPlaylist.count(); i++) {
1312 int blankStart = trackPlaylist.clip_start(i);
1313 int blankDuration = trackPlaylist.clip_length(i) - 1;
1315 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1316 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1319 if (trackPlaylist.is_blank(clipIndex)) {
1320 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1324 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1325 trackPlaylist.replace_with_blank(clipIndex);
1326 trackPlaylist.consolidate_blanks(0);
1327 if (QString(clip.parent().get("transparency")).toInt() == 1)
1328 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());
1330 /* // Display playlist info
1331 kDebug()<<"//// AFTER";
1332 for (int i = 0; i < trackPlaylist.count(); i++) {
1333 int blankStart = trackPlaylist.clip_start(i);
1334 int blankDuration = trackPlaylist.clip_length(i) - 1;
1336 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1337 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1340 if (track != 0 && trackPlaylist.count() > clipIndex) mltCheckLength();
1341 m_isBlocked = false;
1345 int Render::mltChangeClipSpeed(ItemInfo info, double speed, Mlt::Producer *prod) {
1348 Mlt::Service service(m_mltProducer->parent().get_service());
1349 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1350 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1351 Mlt::Tractor tractor(service);
1352 Mlt::Producer trackProducer(tractor.track(info.track));
1353 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1354 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1355 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1356 QString serv = clip.parent().get("mlt_service");
1357 QString id = clip.parent().get("id");
1358 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1359 if (serv == "avformat" && speed != 1.0) {
1360 mlt_service_lock(service.get_service());
1361 QString url = clip.parent().get("resource");
1362 url.append("?" + QString::number(speed));
1363 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1364 if (!slowprod || slowprod->get_producer() == NULL) {
1365 char *tmp = decodedString(url);
1366 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1368 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1369 tmp = decodedString(producerid);
1370 slowprod->set("id", tmp);
1372 m_slowmotionProducers.insert(url, slowprod);
1374 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1375 newLength = cut->get_length();
1376 trackPlaylist.replace_with_blank(clipIndex);
1377 trackPlaylist.consolidate_blanks(0);
1378 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1379 mlt_service_unlock(service.get_service());
1380 } else if (speed == 1.0) {
1381 mlt_service_lock(service.get_service());
1382 Mlt::Producer *cut = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1383 trackPlaylist.replace_with_blank(clipIndex);
1384 newLength = cut->get_length();
1385 trackPlaylist.consolidate_blanks(0);
1386 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1387 mlt_service_unlock(service.get_service());
1388 } else if (serv == "framebuffer") {
1389 mlt_service_lock(service.get_service());
1390 QString url = clip.parent().get("resource");
1391 url = url.section("?", 0, 0);
1392 url.append("?" + QString::number(speed));
1393 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1394 if (!slowprod || slowprod->get_producer() == NULL) {
1395 char *tmp = decodedString(url);
1396 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1398 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1399 tmp = decodedString(producerid);
1400 slowprod->set("id", tmp);
1402 m_slowmotionProducers.insert(url, slowprod);
1404 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1405 newLength = cut->get_length();
1406 trackPlaylist.replace_with_blank(clipIndex);
1407 trackPlaylist.consolidate_blanks(0);
1408 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1409 mlt_service_unlock(service.get_service());
1410 kDebug() << "AVFORMAT CLIP!!!:";
1413 m_isBlocked = false;
1417 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1419 Mlt::Service service(m_mltProducer->parent().get_service());
1420 bool success = false;
1421 Mlt::Tractor tractor(service);
1422 Mlt::Producer trackProducer(tractor.track(track));
1423 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1424 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1425 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1427 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1430 Mlt::Service clipService(clip->get_service());
1431 // if (tag.startsWith("ladspa")) tag = "ladspa";
1434 Mlt::Filter *filter = clipService.filter(ct);
1436 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1437 if (clipService.detach(*filter) == 0) success = true;
1438 kDebug() << " / / / DLEETED EFFECT: " << ct;
1440 filter = clipService.filter(ct);
1442 m_isBlocked = false;
1443 if (doRefresh) refresh();
1448 bool Render::mltAddEffect(int track, GenTime position, QMap <QString, QString> args, bool doRefresh) {
1450 Mlt::Service service(m_mltProducer->parent().get_service());
1452 Mlt::Tractor tractor(service);
1453 Mlt::Producer trackProducer(tractor.track(track));
1454 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1456 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1460 Mlt::Service clipService(clip->get_service());
1463 QString tag = args.value("tag");
1464 kDebug() << " / / INSERTING EFFECT: " << tag;
1465 if (tag.startsWith("ladspa")) tag = "ladspa";
1466 char *filterTag = decodedString(tag);
1467 char *filterId = decodedString(args.value("id"));
1468 QMap<QString, QString>::Iterator it;
1469 QString kfr = args.value("keyframes");
1471 if (!kfr.isEmpty()) {
1472 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1473 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1474 char *starttag = decodedString(args.value("starttag", "start"));
1475 char *endtag = decodedString(args.value("endtag", "end"));
1476 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1477 int duration = clip->get_playtime();
1478 double max = args.value("max").toDouble();
1479 double min = args.value("min").toDouble();
1480 double factor = args.value("factor", "1").toDouble();
1481 args.remove("starttag");
1482 args.remove("endtag");
1483 args.remove("keyframes");
1486 args.remove("factor");
1488 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1489 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1490 filter->set("kdenlive_id", filterId);
1491 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1492 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1493 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1494 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1495 if (x2 == -1) x2 = duration;
1496 for (it = args.begin(); it != args.end(); ++it) {
1497 char *name = decodedString(it.key());
1498 char *value = decodedString(it.value());
1499 filter->set(name, value);
1504 filter->set("in", x1);
1505 filter->set("out", x2);
1506 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1507 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1508 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1509 clipService.attach(*filter);
1515 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1516 if (filter && filter->is_valid())
1517 filter->set("kdenlive_id", filterId);
1519 kDebug() << "filter is NULL";
1520 m_isBlocked = false;
1524 for (it = args.begin(); it != args.end(); ++it) {
1525 char *name = decodedString(it.key());
1526 char *value = decodedString(it.value());
1527 filter->set(name, value);
1531 // attach filter to the clip
1532 clipService.attach(*filter);
1536 m_isBlocked = false;
1537 if (doRefresh) refresh();
1541 bool Render::mltEditEffect(int track, GenTime position, QMap <QString, QString> args) {
1542 QString index = args.value("kdenlive_ix");
1543 QString tag = args.value("tag");
1544 QMap<QString, QString>::Iterator it = args.begin();
1545 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1546 // This is a keyframe effect, to edit it, we remove it and re-add it.
1547 mltRemoveEffect(track, position, index);
1548 bool success = mltAddEffect(track, position, args);
1553 Mlt::Service service(m_mltProducer->parent().get_service());
1555 Mlt::Tractor tractor(service);
1556 Mlt::Producer trackProducer(tractor.track(track));
1557 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1558 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1559 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1561 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1564 Mlt::Service clipService(clip->get_service());
1567 Mlt::Filter *filter = clipService.filter(ct);
1569 if (filter->get("kdenlive_ix") == index) {
1573 filter = clipService.filter(ct);
1577 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1578 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1580 filter = clipService.filter(ct);
1581 QList <Mlt::Filter *> filtersList;
1583 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1584 filtersList.append(filter);
1585 clipService.detach(*filter);
1587 filter = clipService.filter(ct);
1589 bool success = mltAddEffect(track, position, args);
1591 for (int i = 0; i < filtersList.count(); i++) {
1592 clipService.attach(*(filtersList.at(i)));
1595 m_isBlocked = false;
1599 for (it = args.begin(); it != args.end(); ++it) {
1600 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1601 char *name = decodedString(it.key());
1602 char *value = decodedString(it.value());
1603 filter->set(name, value);
1607 m_isBlocked = false;
1612 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1614 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1615 Mlt::Service service(m_mltProducer->parent().get_service());
1617 Mlt::Tractor tractor(service);
1618 Mlt::Producer trackProducer(tractor.track(track));
1619 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1620 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1621 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1623 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1626 Mlt::Service clipService(clip->get_service());
1629 QList <Mlt::Filter *> filtersList;
1630 Mlt::Filter *filter = clipService.filter(ct);
1632 if (newPos > oldPos) {
1634 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1635 filter->set("kdenlive_ix", newPos);
1636 filtersList.append(filter);
1637 clipService.detach(*filter);
1638 filter = clipService.filter(ct);
1639 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1640 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1642 filter = clipService.filter(ct);
1646 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1647 filtersList.append(filter);
1648 clipService.detach(*filter);
1650 filter = clipService.filter(ct);
1654 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1655 filter->set("kdenlive_ix", newPos);
1656 filtersList.append(filter);
1657 clipService.detach(*filter);
1659 filter = clipService.filter(ct);
1663 filter = clipService.filter(ct);
1665 int pos = QString(filter->get("kdenlive_ix")).toInt();
1666 if (pos >= newPos) {
1667 if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
1668 filtersList.append(filter);
1669 clipService.detach(*filter);
1671 filter = clipService.filter(ct);
1675 for (int i = 0; i < filtersList.count(); i++) {
1676 clipService.attach(*(filtersList.at(i)));
1679 m_isBlocked = false;
1683 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
1686 Mlt::Service service(m_mltProducer->parent().get_service());
1688 Mlt::Tractor tractor(service);
1689 Mlt::Producer trackProducer(tractor.track(info.track));
1690 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1692 /* // Display playlist info
1693 kDebug()<<"//////////// BEFORE RESIZE";
1694 for (int i = 0; i < trackPlaylist.count(); i++) {
1695 int blankStart = trackPlaylist.clip_start(i);
1696 int blankDuration = trackPlaylist.clip_length(i) - 1;
1698 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1699 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1702 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
1703 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1704 m_isBlocked = false;
1707 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1708 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
1709 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1710 int previousStart = clip->get_in();
1711 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1712 int newDuration = (int) clipDuration.frames(m_fps) - 1;
1713 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
1714 //trackPlaylist.consolidate_blanks(0);
1715 // skip to next clip
1717 int diff = newDuration - previousDuration;
1718 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
1720 // clip was made longer, trim next blank if there is one.
1721 if (trackPlaylist.is_blank(clipIndex)) {
1722 int blankStart = trackPlaylist.clip_start(clipIndex);
1723 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
1724 if (diff - blankDuration == 1) {
1725 trackPlaylist.remove(clipIndex);
1726 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
1728 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
1730 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
1732 trackPlaylist.consolidate_blanks(0);
1734 /* // Display playlist info
1735 kDebug()<<"//////////// AFTER RESIZE";
1736 for (int i = 0; i < trackPlaylist.count(); i++) {
1737 int blankStart = trackPlaylist.clip_start(i);
1738 int blankDuration = trackPlaylist.clip_length(i) - 1;
1740 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1741 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1744 //tractor.multitrack()->refresh();
1745 //tractor.refresh();
1746 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
1747 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1748 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1749 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1750 ItemInfo transpinfo;
1751 transpinfo.startPos = info.startPos;
1752 transpinfo.endPos = info.startPos + clipDuration;
1753 transpinfo.track = info.track;
1754 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1756 m_isBlocked = false;
1760 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1761 Mlt::Service service(m_mltProducer->parent().get_service());
1762 Mlt::Tractor tractor(service);
1763 Mlt::Producer trackProducer(tractor.track(track));
1764 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1766 if (blind) trackProducer.set("hide", 3);
1767 else trackProducer.set("hide", 2);
1769 trackProducer.set("hide", 1);
1771 trackProducer.set("hide", 0);
1773 tractor.multitrack()->refresh();
1778 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
1779 Mlt::Service service(m_mltProducer->parent().get_service());
1780 int moveFrame = (int) diff.frames(m_fps);
1781 Mlt::Tractor tractor(service);
1782 Mlt::Producer trackProducer(tractor.track(info.track));
1783 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1784 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
1785 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1788 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
1789 /*int previousStart = trackPlaylist.clip_start(clipIndex);
1790 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
1791 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1792 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1794 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
1797 m_mltConsumer->set("refresh", 0);
1798 int previousStart = clip->get_in();
1799 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1801 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
1802 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
1803 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1805 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
1806 int blankIndex = clipIndex - 1;
1807 int blankLength = trackPlaylist.clip_length(blankIndex);
1808 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
1809 if (! trackPlaylist.is_blank(blankIndex)) {
1810 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
1812 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1813 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1815 trackPlaylist.consolidate_blanks(0);
1816 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1817 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
1818 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1819 ItemInfo transpinfo;
1820 transpinfo.startPos = info.startPos + diff;
1821 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
1822 transpinfo.track = info.track;
1823 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1825 m_isBlocked = false;
1826 m_mltConsumer->set("refresh", 1);
1830 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1831 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1835 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1838 m_mltConsumer->set("refresh", 0);
1839 mlt_service_lock(m_mltConsumer->get_service());
1840 Mlt::Service service(m_mltProducer->parent().get_service());
1841 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1843 Mlt::Tractor tractor(service);
1844 Mlt::Producer trackProducer(tractor.track(startTrack));
1845 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1846 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1847 bool checkLength = false;
1848 if (endTrack == startTrack) {
1849 //mlt_service_lock(service.get_service());
1850 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1852 if (!trackPlaylist.is_blank_at(moveEnd)) {
1853 // error, destination is not empty
1854 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
1855 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
1856 mlt_service_unlock(m_mltConsumer->get_service());
1857 m_isBlocked = false;
1860 trackPlaylist.consolidate_blanks(0);
1861 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1862 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1863 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1865 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
1867 //mlt_service_unlock(service.get_service());
1869 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1870 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1871 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
1872 // error, destination is not empty
1873 mlt_service_unlock(m_mltConsumer->get_service());
1874 m_isBlocked = false;
1877 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1878 trackPlaylist.consolidate_blanks(0);
1879 destTrackPlaylist.consolidate_blanks(1);
1880 int newIndex = destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1881 destTrackPlaylist.consolidate_blanks(0);
1882 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1883 kDebug() << "//////// moving clip transparency";
1884 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1886 if (clipIndex > trackPlaylist.count()) checkLength = true;
1887 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
1891 if (checkLength) mltCheckLength();
1892 mlt_service_unlock(m_mltConsumer->get_service());
1893 m_isBlocked = false;
1894 m_mltConsumer->set("refresh", 1);
1898 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1900 Mlt::Service service(m_mltProducer->parent().get_service());
1901 Mlt::Tractor tractor(service);
1902 Mlt::Field *field = tractor.field();
1904 mlt_service_lock(service.get_service());
1905 m_mltConsumer->set("refresh", 0);
1908 mlt_service serv = m_mltProducer->parent().get_service();
1909 mlt_service nextservice = mlt_service_get_producer(serv);
1910 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1911 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1912 QString resource = mlt_properties_get(properties, "mlt_service");
1913 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1915 int new_in = (int)newIn.frames(m_fps);
1916 int new_out = (int)newOut.frames(m_fps);
1918 while (mlt_type == "transition") {
1919 mlt_transition tr = (mlt_transition) nextservice;
1920 int currentTrack = mlt_transition_get_b_track(tr);
1921 int currentIn = (int) mlt_transition_get_in(tr);
1922 int currentOut = (int) mlt_transition_get_out(tr);
1924 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1925 mlt_transition_set_in_and_out(tr, new_in, new_out);
1926 if (newTrack - startTrack != 0) {
1927 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
1929 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1930 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
1931 mlt_properties_set_int(properties, "b_track", newTrack);
1932 //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);
1936 nextservice = mlt_service_producer(nextservice);
1937 if (nextservice == NULL) break;
1938 properties = MLT_SERVICE_PROPERTIES(nextservice);
1939 mlt_type = mlt_properties_get(properties, "mlt_type");
1940 resource = mlt_properties_get(properties, "mlt_service");
1942 m_isBlocked = false;
1943 mlt_service_unlock(service.get_service());
1944 m_mltConsumer->set("refresh", 1);
1947 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1948 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
1949 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
1951 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
1952 mltAddTransition(tag, a_track, b_track, in, out, xml);
1954 //mltSavePlaylist();
1957 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1960 Mlt::Service service(m_mltProducer->parent().get_service());
1961 Mlt::Tractor tractor(service);
1962 Mlt::Field *field = tractor.field();
1964 //m_mltConsumer->set("refresh", 0);
1965 mlt_service serv = m_mltProducer->parent().get_service();
1967 mlt_service nextservice = mlt_service_get_producer(serv);
1968 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1969 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1970 QString resource = mlt_properties_get(properties, "mlt_service");
1971 int in_pos = (int) in.frames(m_fps);
1972 int out_pos = (int) out.frames(m_fps);
1974 while (mlt_type == "transition") {
1975 mlt_transition tr = (mlt_transition) nextservice;
1976 int currentTrack = mlt_transition_get_b_track(tr);
1977 int currentIn = (int) mlt_transition_get_in(tr);
1978 int currentOut = (int) mlt_transition_get_out(tr);
1980 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
1982 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
1983 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
1984 QMap<QString, QString>::Iterator it;
1986 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
1988 for (it = map.begin(); it != map.end(); ++it) {
1990 char *name = decodedString(key);
1991 char *value = decodedString(it.value());
1992 mlt_properties_set(transproperties, name, value);
1993 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
1994 //filter->set("kdenlive_id", id);
2000 nextservice = mlt_service_producer(nextservice);
2001 if (nextservice == NULL) break;
2002 properties = MLT_SERVICE_PROPERTIES(nextservice);
2003 mlt_type = mlt_properties_get(properties, "mlt_type");
2004 resource = mlt_properties_get(properties, "mlt_service");
2006 m_isBlocked = false;
2007 m_mltConsumer->set("refresh", 1);
2010 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2011 Mlt::Service service(m_mltProducer->parent().get_service());
2012 Mlt::Tractor tractor(service);
2013 Mlt::Field *field = tractor.field();
2015 if (do_refresh) m_mltConsumer->set("refresh", 0);
2016 mlt_service serv = m_mltProducer->parent().get_service();
2018 mlt_service nextservice = mlt_service_get_producer(serv);
2019 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2020 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2021 QString resource = mlt_properties_get(properties, "mlt_service");
2022 int old_pos = (int)((in + out).frames(m_fps) / 2);
2024 while (mlt_type == "transition") {
2025 mlt_transition tr = (mlt_transition) nextservice;
2026 int currentTrack = mlt_transition_get_b_track(tr);
2027 int currentIn = (int) mlt_transition_get_in(tr);
2028 int currentOut = (int) mlt_transition_get_out(tr);
2029 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2031 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2032 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2033 mlt_field_disconnect_service(field->get_field(), nextservice);
2036 nextservice = mlt_service_producer(nextservice);
2037 if (nextservice == NULL) break;
2038 properties = MLT_SERVICE_PROPERTIES(nextservice);
2039 mlt_type = mlt_properties_get(properties, "mlt_type");
2040 resource = mlt_properties_get(properties, "mlt_service");
2042 if (do_refresh) m_mltConsumer->set("refresh", 1);
2045 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2046 QDomNodeList attribs = xml.elementsByTagName("parameter");
2047 QMap<QString, QString> map;
2048 for (int i = 0;i < attribs.count();i++) {
2049 QDomElement e = attribs.item(i).toElement();
2050 QString name = e.attribute("name");
2051 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2052 map[name] = e.attribute("default");
2053 if (!e.attribute("value").isEmpty()) {
2054 map[name] = e.attribute("value");
2056 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2057 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2058 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2061 if (e.attribute("namedesc").contains(";")) {
2062 QString format = e.attribute("format");
2063 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2064 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2066 QTextStream txtNeu(&neu);
2067 if (values.size() > 0)
2068 txtNeu << (int)values[0].toDouble();
2070 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2071 txtNeu << separators[i];
2072 txtNeu << (int)(values[i+1].toDouble());
2074 if (i < separators.size())
2075 txtNeu << separators[i];
2076 map[e.attribute("name")] = neu;
2083 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2084 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2085 Mlt::Service service(m_mltProducer->parent().get_service());
2086 Mlt::Tractor tractor(service);
2087 Mlt::Field *field = tractor.field();
2089 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2090 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2091 transition->set("transparency", id);
2092 transition->set("fill", 1);
2093 transition->set("internal_added", 237);
2094 field->plant_transition(*transition, transitiontrack, info.track);
2098 void Render::mltDeleteTransparency(int pos, int track, int id) {
2099 Mlt::Service service(m_mltProducer->parent().get_service());
2100 Mlt::Tractor tractor(service);
2101 Mlt::Field *field = tractor.field();
2103 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2104 mlt_service serv = m_mltProducer->parent().get_service();
2106 mlt_service nextservice = mlt_service_get_producer(serv);
2107 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2108 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2109 QString resource = mlt_properties_get(properties, "mlt_service");
2111 while (mlt_type == "transition") {
2112 mlt_transition tr = (mlt_transition) nextservice;
2113 int currentTrack = mlt_transition_get_b_track(tr);
2114 int currentIn = (int) mlt_transition_get_in(tr);
2115 int currentOut = (int) mlt_transition_get_out(tr);
2116 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2117 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2119 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2120 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2121 mlt_field_disconnect_service(field->get_field(), nextservice);
2124 nextservice = mlt_service_producer(nextservice);
2125 if (nextservice == NULL) break;
2126 properties = MLT_SERVICE_PROPERTIES(nextservice);
2127 mlt_type = mlt_properties_get(properties, "mlt_type");
2128 resource = mlt_properties_get(properties, "mlt_service");
2130 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2133 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2134 Mlt::Service service(m_mltProducer->parent().get_service());
2135 Mlt::Tractor tractor(service);
2136 Mlt::Field *field = tractor.field();
2138 mlt_service_lock(service.get_service());
2139 m_mltConsumer->set("refresh", 0);
2142 mlt_service serv = m_mltProducer->parent().get_service();
2143 mlt_service nextservice = mlt_service_get_producer(serv);
2144 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2145 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2146 QString resource = mlt_properties_get(properties, "mlt_service");
2147 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2148 while (mlt_type == "transition") {
2149 mlt_transition tr = (mlt_transition) nextservice;
2150 int currentTrack = mlt_transition_get_b_track(tr);
2151 int currentIn = (int) mlt_transition_get_in(tr);
2152 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2153 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2154 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2155 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2156 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2157 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2160 nextservice = mlt_service_producer(nextservice);
2161 if (nextservice == NULL) break;
2162 properties = MLT_SERVICE_PROPERTIES(nextservice);
2163 mlt_type = mlt_properties_get(properties, "mlt_type");
2164 resource = mlt_properties_get(properties, "mlt_service");
2166 m_isBlocked = false;
2167 mlt_service_unlock(service.get_service());
2168 m_mltConsumer->set("refresh", 1);
2172 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2173 Mlt::Service service(m_mltProducer->parent().get_service());
2174 Mlt::Tractor tractor(service);
2175 Mlt::Field *field = tractor.field();
2177 mlt_service_lock(service.get_service());
2178 m_mltConsumer->set("refresh", 0);
2181 mlt_service serv = m_mltProducer->parent().get_service();
2182 mlt_service nextservice = mlt_service_get_producer(serv);
2183 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2184 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2185 QString resource = mlt_properties_get(properties, "mlt_service");
2187 while (mlt_type == "transition") {
2188 mlt_transition tr = (mlt_transition) nextservice;
2189 int currentTrack = mlt_transition_get_b_track(tr);
2190 int currentaTrack = mlt_transition_get_a_track(tr);
2191 int currentIn = (int) mlt_transition_get_in(tr);
2192 int currentOut = (int) mlt_transition_get_out(tr);
2193 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2194 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2195 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2196 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2197 kDebug() << "//////MOVING";
2198 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2199 if (endTrack != startTrack) {
2200 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2201 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2202 mlt_properties_set_int(properties, "b_track", endTrack);
2206 nextservice = mlt_service_producer(nextservice);
2207 if (nextservice == NULL) break;
2208 properties = MLT_SERVICE_PROPERTIES(nextservice);
2209 mlt_type = mlt_properties_get(properties, "mlt_type");
2210 resource = mlt_properties_get(properties, "mlt_service");
2212 m_isBlocked = false;
2213 mlt_service_unlock(service.get_service());
2214 m_mltConsumer->set("refresh", 1);
2218 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2220 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2221 Mlt::Service service(m_mltProducer->parent().get_service());
2223 Mlt::Tractor tractor(service);
2224 Mlt::Field *field = tractor.field();
2226 char *transId = decodedString(tag);
2227 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2228 if (out != GenTime())
2229 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
2230 QMap<QString, QString>::Iterator it;
2233 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2235 for (it = args.begin(); it != args.end(); ++it) {
2237 char *name = decodedString(key);
2238 char *value = decodedString(it.value());
2239 transition->set(name, value);
2240 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2241 //filter->set("kdenlive_id", id);
2245 // attach filter to the clip
2246 field->plant_transition(*transition, a_track, b_track);
2251 void Render::mltSavePlaylist() {
2252 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2253 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2254 fileConsumer.set("resource", "/tmp/playlist.westley");
2256 Mlt::Service service(m_mltProducer->get_service());
2258 fileConsumer.connect(service);
2259 fileConsumer.start();
2263 #include "renderer.moc"