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
33 #include <QApplication>
37 #include <KStandardDirs>
38 #include <KMessageBox>
40 #include <KTemporaryFile>
43 #include "kdenlivesettings.h"
45 #include "definitions.h"
47 #include <mlt++/Mlt.h>
49 #if LIBAVCODEC_VERSION_MAJOR > 51 || (LIBAVCODEC_VERSION_MAJOR > 50 && LIBAVCODEC_VERSION_MINOR > 54)
50 // long_name was added in FFmpeg avcodec version 51.55
51 #define ENABLE_FFMPEG_CODEC_DESCRIPTION 1
54 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
55 // detect if the producer has finished playing. Is there a better way to do it ?
56 if (self->m_isBlocked) return;
57 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
58 self->emitConsumerStopped();
60 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
64 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) {
65 kDebug() << "////////// USING PROFILE: " << (char *)KdenliveSettings::current_profile().toUtf8().data();
66 m_mltProfile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
67 refreshTimer = new QTimer(this);
68 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
70 if (rendererName == "project") m_monitorId = 10000;
71 else m_monitorId = 10001;
72 osdTimer = new QTimer(this);
73 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
75 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
76 //if (rendererName == "clip")
78 //Mlt::Consumer *consumer = new Mlt::Consumer( profile , "sdl_preview");
79 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
80 m_mltConsumer->set("resize", 1);
81 m_mltConsumer->set("window_id", winid);
82 m_mltConsumer->set("terminate_on_pause", 1);
83 m_mltConsumer->set("rescale", "nearest");
84 m_mltConsumer->set("progressive", 1);
85 m_mltConsumer->set("audio_buffer", 1024);
86 m_mltConsumer->set("frequency", 48000);
87 m_externalwinid = extid;
89 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
90 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", "<westley><playlist><producer mlt_service=\"colour\" colour=\"blue\" in=\"0\" out=\"25\" /></playlist></westley>");
91 m_mltProducer = producer;
92 if (m_blackClip) delete m_blackClip;
93 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
94 m_mltConsumer->connect(*m_mltProducer);
95 m_mltProducer->set_speed(0.0);
97 //m_mltConsumer->start();
101 /*m_osdInfo = new Mlt::Filter("data_show");
102 char *tmp = decodedString(m_osdProfile);
103 m_osdInfo->set("resource", tmp);
105 // Does it do anything usefull? I mean, RenderThread doesn't do anything useful at the moment
106 // (except being cpu hungry :)
108 /* if(!s_renderThread) {
109 s_renderThread = new RenderThread;
110 s_renderThread->start();
119 void Render::closeMlt() {
123 delete m_mltConsumer;
125 delete m_mltProducer;
126 if (m_blackClip) delete m_blackClip;
132 int Render::resetProfile(QString profile) {
134 if (!m_mltConsumer) return 0;
135 if (m_isSplitView) slotSplitView(false);
136 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
137 m_mltConsumer->purge();
138 delete m_mltConsumer;
140 m_mltConsumer = NULL;
141 QString scene = sceneList();
142 if (m_mltProducer) delete m_mltProducer;
143 m_mltProducer = NULL;
144 if (m_mltProfile) delete m_mltProfile;
147 char *tmp = decodedString(profile);
148 m_mltProfile = new Mlt::Profile(tmp);
150 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
151 m_mltConsumer->set("resize", 1);
152 m_mltConsumer->set("window_id", m_winid);
153 m_mltConsumer->set("terminate_on_pause", 1);
154 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
155 m_mltConsumer->set("rescale", "nearest");
156 m_mltConsumer->set("progressive", 1);
157 m_mltConsumer->set("audio_buffer", 1024);
158 m_mltConsumer->set("frequency", 48000);
160 kDebug() << "//RESET WITHSCENE: " << scene;
163 tmp = decodedString(scene);
164 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
166 m_mltProducer = producer;
167 if (m_blackClip) delete m_blackClip;
168 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
169 m_mltProducer->optimise();
170 m_mltProducer->set_speed(0);
173 //delete m_mltProfile;
174 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
175 //mlt_profile prof = m_mltProfile->get_profile();
176 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
177 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
178 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
179 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
180 kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << profile << ", WIDTH: " << m_mltProfile->width();
182 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
187 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
188 void Render::seek(GenTime time) {
189 sendSeekCommand(time);
190 //emit positionChanged(time);
194 char *Render::decodedString(QString str) {
195 /*QCString fn = QFile::encodeName(str);
196 char *t = new char[fn.length() + 1];
197 strcpy(t, (const char *)fn);*/
199 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
203 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
204 QPixmap pix(width, height);
206 mlt_image_format format = mlt_image_rgb24a;
207 uint8_t *thumb = frame->get_image(format, width, height);
208 QImage image(thumb, width, height, QImage::Format_ARGB32);
210 if (!image.isNull()) {
211 pix = pix.fromImage(image);
213 QPainter painter(&pix);
214 painter.drawRect(0, 0, width - 1, height - 1);
216 } else pix.fill(Qt::black);
220 const int Render::renderWidth() const {
221 return (int)(m_mltProfile->height() * m_mltProfile->dar());
224 const int Render::renderHeight() const {
225 return m_mltProfile->height();
228 QPixmap Render::extractFrame(int frame_position, int width, int height) {
230 width = renderWidth();
231 height = renderHeight();
233 QPixmap pix(width, height);
234 if (!m_mltProducer) {
238 return KThumb::getFrame(*m_mltProducer, frame_position, width, height);
241 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
244 if (url.fileName().startsWith(".all.")) { // check for slideshow
245 QString fileType = url.fileName().right(3);
247 QStringList::Iterator it;
249 QDir dir(url.directory());
250 more = dir.entryList(QDir::Files);
252 for (it = more.begin() ; it != more.end() ; ++it) {
253 if ((*it).endsWith("." + fileType, Qt::CaseInsensitive)) {
254 im.load(url.directory() + "/" + *it);
258 } else im.load(url.path());
259 //pixmap = im.scaled(width, height);
264 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
265 QPixmap pix(width, height);
266 char *tmp = decodedString(file);
267 Mlt::Profile *prof = new Mlt::Profile(profile);
268 Mlt::Producer m_producer(*prof, tmp);
270 if (m_producer.is_blank()) {
275 Mlt::Filter m_convert(*prof, "avcolour_space");
276 m_convert.set("forced", mlt_image_rgb24a);
277 m_producer.attach(m_convert);
278 m_producer.seek(frame_position);
279 Mlt::Frame * frame = m_producer.get_frame();
281 pix = frameThumbnail(frame, width, height, true);
284 if (prof) delete prof;
289 void Render::getImage(KUrl url, int frame_position, QPoint size)
291 char *tmp = decodedString(url.path());
292 Mlt::Producer m_producer(tmp);
294 if (m_producer.is_blank()) {
297 Mlt::Filter m_convert("avcolour_space");
298 m_convert.set("forced", mlt_image_rgb24a);
299 m_producer.attach(m_convert);
300 m_producer.seek(frame_position);
302 Mlt::Frame * frame = m_producer.get_frame();
305 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
307 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
311 /* Create thumbnail for color */
312 /*void Render::getImage(int id, QString color, QPoint size)
314 QPixmap pixmap(size.x() - 2, size.y() - 2);
315 color = color.replace(0, 2, "#");
316 color = color.left(7);
317 pixmap.fill(QColor(color));
318 QPixmap result(size.x(), size.y());
319 result.fill(Qt::black);
320 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
321 emit replyGetImage(id, result, size.x(), size.y());
325 /* Create thumbnail for image */
326 /*void Render::getImage(KUrl url, QPoint size)
330 if (url.fileName().startsWith(".all.")) { // check for slideshow
331 QString fileType = url.fileName().right(3);
333 QStringList::Iterator it;
335 QDir dir( url.directory() );
336 more = dir.entryList( QDir::Files );
337 for ( it = more.begin() ; it != more.end() ; ++it ) {
338 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
339 if (!im.load(url.directory() + "/" + *it))
340 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
345 else im.load(url.path());
347 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
348 QPixmap result(size.x(), size.y());
349 result.fill(Qt::black);
350 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
351 emit replyGetImage(url, 1, result, size.x(), size.y());
355 double Render::consumerRatio() const {
356 if (!m_mltConsumer) return 1.0;
357 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
361 int Render::getLength() {
364 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
365 return mlt_producer_get_playtime(m_mltProducer->get_producer());
370 bool Render::isValid(KUrl url) {
371 char *tmp = decodedString(url.path());
372 Mlt::Producer producer(*m_mltProfile, tmp);
374 if (producer.is_blank())
380 const double Render::dar() const {
381 return m_mltProfile->dar();
384 void Render::slotSplitView(bool doit) {
385 m_isSplitView = doit;
386 Mlt::Service service(m_mltProducer->parent().get_service());
387 Mlt::Tractor tractor(service);
388 if (service.type() != tractor_type || tractor.count() < 2) return;
389 Mlt::Field *field = tractor.field();
392 for (int i = 1; i < tractor.count() && screen < 4; i++) {
393 Mlt::Producer trackProducer(tractor.track(i));
394 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
395 if (QString(trackProducer.get("hide")).toInt() != 1) {
396 kDebug() << "// ADIDNG TRACK: " << i;
397 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
398 transition->set("mlt_service", "composite");
399 transition->set("a_track", 0);
400 transition->set("b_track", i);
401 transition->set("distort", 1);
402 transition->set("internal_added", "200");
409 tmp = "50%,0:50%x50%";
412 tmp = "0,50%:50%x50%";
415 tmp = "50%,50%:50%x50%";
418 transition->set("geometry", tmp);
419 transition->set("always_active", "1");
420 field->plant_transition(*transition, 0, i);
425 m_mltConsumer->set("refresh", 1);
427 mlt_service serv = m_mltProducer->parent().get_service();
428 mlt_service nextservice = mlt_service_get_producer(serv);
429 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
430 QString mlt_type = mlt_properties_get(properties, "mlt_type");
431 QString resource = mlt_properties_get(properties, "mlt_service");
433 while (mlt_type == "transition") {
434 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
435 if (added == "200") {
436 mlt_field_disconnect_service(field->get_field(), nextservice);
438 nextservice = mlt_service_producer(nextservice);
439 if (nextservice == NULL) break;
440 properties = MLT_SERVICE_PROPERTIES(nextservice);
441 mlt_type = mlt_properties_get(properties, "mlt_type");
442 resource = mlt_properties_get(properties, "mlt_service");
443 m_mltConsumer->set("refresh", 1);
448 void Render::getFileProperties(const QDomElement &xml, int clipId) {
450 int width = (int)(height * m_mltProfile->dar());
451 QMap < QString, QString > filePropertyMap;
452 QMap < QString, QString > metadataPropertyMap;
454 KUrl url = KUrl(xml.attribute("resource", QString::null));
455 Mlt::Producer *producer;
456 if (xml.attribute("type").toInt() == COLOR) {
457 char *tmp = decodedString("colour:" + xml.attribute("colour"));
458 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
460 } else if (url.isEmpty()) {
462 QDomElement westley = doc.createElement("westley");
463 QDomElement play = doc.createElement("playlist");
464 doc.appendChild(westley);
465 westley.appendChild(play);
466 play.appendChild(doc.importNode(xml, true));
467 kDebug() << "/ / / / /CLIP XML: " << doc.toString();
468 char *tmp = decodedString(doc.toString());
469 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
472 char *tmp = decodedString(url.path());
473 producer = new Mlt::Producer(*m_mltProfile, tmp);
476 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
478 if (producer->is_blank()) {
479 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
482 producer->set("id", clipId);
483 int frameNumber = xml.attribute("thumbnail", "0").toInt();
484 if (frameNumber != 0) producer->seek(frameNumber);
485 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
487 filePropertyMap["filename"] = url.path();
488 filePropertyMap["duration"] = QString::number(producer->get_playtime());
489 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
491 Mlt::Frame * frame = producer->get_frame();
493 if (xml.attribute("type").toInt() == SLIDESHOW) {
494 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
495 if (xml.attribute("fade") == "1") {
496 // user wants a fade effect to slideshow
497 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
498 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
499 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
500 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
501 char *tmp = decodedString(xml.attribute("luma_file"));
502 filter->set("luma.resource", tmp);
504 if (xml.hasAttribute("softness")) {
505 int soft = xml.attribute("softness").toInt();
506 filter->set("luma.softness", (double) soft / 100.0);
509 Mlt::Service clipService(producer->get_service());
510 clipService.attach(*filter);
515 filePropertyMap["fps"] = producer->get("source_fps");
517 if (frame && frame->is_valid()) {
518 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
519 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
520 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
521 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
523 if (frame->get_int("test_image") == 0) {
524 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
525 filePropertyMap["type"] = "playlist";
526 metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer->get_service()), "title"));
527 } else if (frame->get_int("test_audio") == 0)
528 filePropertyMap["type"] = "av";
530 filePropertyMap["type"] = "video";
532 mlt_image_format format = mlt_image_yuv422;
534 int frame_height = 0;
535 //frame->set("rescale.interp", "hyper");
536 frame->set("normalised_height", height);
537 frame->set("normalised_width", width);
538 QPixmap pix(width, height);
540 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
541 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
542 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
543 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
545 if (!image.isNull()) {
546 pix = pix.fromImage(image.rgbSwapped());
550 mlt_pool_release(new_image);
551 emit replyGetImage(clipId, 0, pix, width, height);
553 } else if (frame->get_int("test_audio") == 0) {
554 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
555 emit replyGetImage(clipId, 0, pixmap, width, height);
556 filePropertyMap["type"] = "audio";
560 // Retrieve audio / video codec name
562 // Fetch the video_context
565 AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
566 if (context != NULL) {
567 // Get the video_index
568 int index = mlt_properties_get_int(properties, "video_index");
570 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
571 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) {
572 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name;
575 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) {
576 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
578 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
579 context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
580 if (context != NULL) {
581 // Get the audio_index
582 int index = mlt_properties_get_int(properties, "audio_index");
584 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
585 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
586 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name;
589 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
590 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
595 mlt_properties metadata = mlt_properties_new();
596 mlt_properties_pass(metadata, properties, "meta.attr.");
597 int count = mlt_properties_count(metadata);
598 for (int i = 0; i < count; i ++) {
599 QString name = mlt_properties_get_name(metadata, i);
600 QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
601 if (name.endsWith("markup") && !value.isEmpty())
602 metadataPropertyMap[ name.section(".", 0, -2)] = value;
605 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
606 kDebug() << "REquested fuile info for: " << url.path();
607 if (frame) delete frame;
608 //if (producer) delete producer;
611 /** Create the producer from the Westley QDomDocument */
613 void Render::initSceneList() {
614 kDebug() << "-------- INIT SCENE LIST ------_";
616 QDomElement westley = doc.createElement("westley");
617 doc.appendChild(westley);
618 QDomElement prod = doc.createElement("producer");
619 prod.setAttribute("resource", "colour");
620 prod.setAttribute("colour", "red");
621 prod.setAttribute("id", "black");
622 prod.setAttribute("in", "0");
623 prod.setAttribute("out", "0");
625 QDomElement tractor = doc.createElement("tractor");
626 QDomElement multitrack = doc.createElement("multitrack");
628 QDomElement playlist1 = doc.createElement("playlist");
629 playlist1.appendChild(prod);
630 multitrack.appendChild(playlist1);
631 QDomElement playlist2 = doc.createElement("playlist");
632 multitrack.appendChild(playlist2);
633 QDomElement playlist3 = doc.createElement("playlist");
634 multitrack.appendChild(playlist3);
635 QDomElement playlist4 = doc.createElement("playlist");
636 multitrack.appendChild(playlist4);
637 QDomElement playlist5 = doc.createElement("playlist");
638 multitrack.appendChild(playlist5);
639 tractor.appendChild(multitrack);
640 westley.appendChild(tractor);
641 // kDebug()<<doc.toString();
643 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
644 setSceneList(doc, 0);
650 /** Create the producer from the Westley QDomDocument */
651 void Render::setProducer(Mlt::Producer *producer, int position) {
652 if (m_winid == -1) return;
653 m_generateScenelist = true;
656 m_mltConsumer->stop();
660 m_mltProducer->set_speed(0);
661 delete m_mltProducer;
662 m_mltProducer = NULL;
665 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
666 else m_mltProducer = new Mlt::Producer();
667 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
668 m_mltProducer->optimise();
670 m_fps = m_mltProducer->get_fps();
673 m_mltProducer->seek(position);
674 emit rendererPosition(position);
676 m_generateScenelist = false;
681 /** Create the producer from the Westley QDomDocument */
682 void Render::setSceneList(QDomDocument list, int position) {
683 setSceneList(list.toString(), position);
686 /** Create the producer from the Westley QDomDocument */
687 void Render::setSceneList(QString playlist, int position) {
688 if (m_winid == -1) return;
689 m_generateScenelist = true;
691 kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
695 if (!clip.is_valid()) {
696 kWarning()<<" ++++ WARNING, UNABLE TO CREATE MLT PRODUCER";
697 m_generateScenelist = false;
702 m_mltConsumer->stop();
703 //m_mltConsumer->set("refresh", 0);
707 m_mltProducer->set_speed(0);
708 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
710 delete m_mltProducer;
711 m_mltProducer = NULL;
715 char *tmp = decodedString(playlist);
716 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
718 if (m_blackClip) delete m_blackClip;
719 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
720 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
721 m_mltProducer->optimise();
723 /*if (KdenliveSettings::osdtimecode()) {
724 // Attach filter for on screen display of timecode
726 QString attr = "attr_check";
727 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
728 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
729 mlt_producer_attach( m_mltProducer->get_producer(), filter );
730 mlt_filter_close( filter );
732 m_osdInfo = new Mlt::Filter("data_show");
733 tmp = decodedString(m_osdProfile);
734 m_osdInfo->set("resource", tmp);
736 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
737 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
738 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
739 m_osdInfo->set("dynamic", "1");
741 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
743 m_osdInfo->set("dynamic", "0");
746 m_fps = m_mltProducer->get_fps();
747 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
750 m_mltProducer->seek(position);
751 emit rendererPosition(position);
753 m_generateScenelist = false;
757 /** Create the producer from the Westley QDomDocument */
758 QString Render::sceneList() {
763 saveSceneList(temp.fileName());
764 QFile file(temp.fileName());
765 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
766 kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE";
769 QTextStream in(&file);
770 while (!in.atEnd()) {
771 result.append(in.readLine());
777 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
779 char *tmppath = decodedString("westley:" + path);
780 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
781 m_mltProducer->optimise();
783 westleyConsumer.set("terminate_on_pause", 1);
784 Mlt::Producer prod(m_mltProducer->get_producer());
785 bool split = m_isSplitView;
786 if (split) slotSplitView(false);
787 westleyConsumer.connect(prod);
788 //prod.set("title", "kdenlive document");
789 //westleyConsumer.listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
790 westleyConsumer.start();
791 while (!westleyConsumer.is_stopped()) {}
792 if (!kdenliveData.isNull()) {
793 // add Kdenlive specific tags
796 doc.setContent(&file, false);
797 QDomNode wes = doc.elementsByTagName("westley").at(0);
798 wes.appendChild(doc.importNode(kdenliveData, true));
800 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
801 kWarning() << "////// ERROR writing to file: " << path;
804 QTextStream out(&file);
805 out << doc.toString();
808 if (split) slotSplitView(true);
812 const double Render::fps() const {
816 void Render::connectPlaylist() {
817 if (!m_mltConsumer) return;
818 //m_mltConsumer->set("refresh", "0");
819 m_mltConsumer->connect(*m_mltProducer);
820 m_mltProducer->set_speed(0);
821 m_mltConsumer->start();
822 emit durationChanged(m_mltProducer->get_playtime());
825 if (m_mltConsumer->start() == -1) {
826 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."));
827 m_mltConsumer = NULL;
834 void Render::refreshDisplay() {
836 if (!m_mltProducer) return;
837 //m_mltConsumer->set("refresh", 0);
839 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
840 /*if (KdenliveSettings::osdtimecode()) {
841 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
842 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
843 m_osdInfo->set("dynamic", "1");
844 m_mltProducer->attach(*m_osdInfo);
847 m_mltProducer->detach(*m_osdInfo);
848 m_osdInfo->set("dynamic", "0");
853 void Render::setVolume(double volume) {
854 if (!m_mltConsumer || !m_mltProducer) return;
856 m_mltConsumer->set("refresh", 0);
857 // Attach filter for on screen display of timecode
858 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
859 mlt_properties_set_double( properties, "meta.volume", volume );
860 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
861 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
863 if (!KdenliveSettings::osdtimecode()) {
864 m_mltProducer->detach(*m_osdInfo);
865 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
866 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
869 osdTimer->setSingleShot(2500);
872 void Render::slotOsdTimeout() {
873 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
874 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
875 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
876 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
880 void Render::start() {
881 kDebug() << "----- STARTING MONITOR: " << m_name;
883 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
887 if (m_mltConsumer->is_stopped()) {
888 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
889 if (m_mltConsumer->start() == -1) {
890 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."));
891 m_mltConsumer = NULL;
894 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
902 void Render::clear() {
903 kDebug() << " ********* RENDER CLEAR";
905 //m_mltConsumer->set("refresh", 0);
906 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
910 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
911 m_mltProducer->set_speed(0.0);
912 delete m_mltProducer;
913 m_mltProducer = NULL;
918 void Render::stop() {
919 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
920 kDebug() << "///////////// RENDER STOPPED: " << m_name;
921 //m_mltConsumer->set("refresh", 0);
922 m_mltConsumer->stop();
924 kDebug() << "///////////// RENDER STOP2-------";
928 m_mltProducer->set_speed(0.0);
929 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
930 kDebug() << m_mltProducer->get_length();
932 kDebug() << "///////////// RENDER STOP3-------";
935 void Render::stop(const GenTime & startTime) {
937 kDebug() << "///////////// RENDER STOP-------2";
939 m_mltProducer->set_speed(0.0);
940 m_mltProducer->seek((int) startTime.frames(m_fps));
942 m_mltConsumer->purge();
945 void Render::switchPlay() {
948 if (m_mltProducer->get_speed() == 0.0) {
949 //m_isBlocked = false;
950 m_mltProducer->set_speed(1.0);
951 m_mltConsumer->set("refresh", 1);
952 kDebug() << " ********* RENDER PLAY: " << m_mltProducer->get_speed();
954 //m_isBlocked = true;
955 m_mltConsumer->set("refresh", 0);
956 m_mltProducer->set_speed(0.0);
957 //m_isBlocked = true;
958 m_mltProducer->seek((int) m_framePosition);
959 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
960 //m_mltConsumer->set("refresh", 0);
961 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
962 m_mltProducer->set_speed(0);
963 m_mltProducer->seek( position );
964 //m_mltProducer->seek((int) m_framePosition);
965 m_isBlocked = false;*/
967 /*if (speed == 0.0) {
968 m_mltProducer->seek((int) m_framePosition + 1);
969 m_mltConsumer->purge();
974 void Render::play(double speed) {
975 kDebug() << " ********* REDNER PLAY";
978 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
979 m_mltProducer->set_speed(speed);
980 /*if (speed == 0.0) {
981 m_mltProducer->seek((int) m_framePosition + 1);
982 m_mltConsumer->purge();
987 void Render::play(double speed, const GenTime & startTime) {
988 kDebug() << "///////////// RENDER PLAY2-------" << speed;
991 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
992 //if (speed == 0.0) m_mltConsumer->set("refresh", 0);
993 m_mltProducer->set_speed(speed);
994 m_mltProducer->seek((int)(startTime.frames(m_fps)));
995 //m_mltConsumer->purge();
999 void Render::play(double speed, const GenTime & startTime,
1000 const GenTime & stopTime) {
1001 kDebug() << "///////////// RENDER PLAY3-------" << speed << stopTime.frames(m_fps);
1004 m_mltProducer->set("out", stopTime.frames(m_fps));
1005 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1006 m_mltConsumer->purge();
1007 m_mltProducer->set_speed(speed);
1012 void Render::sendSeekCommand(GenTime time) {
1013 //kDebug()<<" ********* RENDER SEND SEEK";
1016 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
1017 m_mltProducer->seek((int)(time.frames(m_fps)));
1018 m_mltConsumer->set("refresh", 1);
1022 void Render::seekToFrame(int pos) {
1023 //kDebug()<<" ********* RENDER SEEK TO POS";
1026 m_mltProducer->seek(pos);
1030 void Render::askForRefresh() {
1031 // Use a Timer so that we don't refresh too much
1032 refreshTimer->start(200);
1035 void Render::doRefresh() {
1036 // Use a Timer so that we don't refresh too much
1037 m_mltConsumer->set("refresh", 1);
1040 void Render::refresh() {
1041 if (!m_mltProducer || m_isBlocked)
1043 refreshTimer->stop();
1044 if (m_mltConsumer) {
1045 m_mltConsumer->set("refresh", 1);
1049 /** Sets the description of this renderer to desc. */
1050 void Render::setDescription(const QString & description) {
1051 m_description = description;
1054 /** Returns the description of this renderer */
1055 QString Render::description() {
1056 return m_description;
1060 double Render::playSpeed() {
1061 if (m_mltProducer) return m_mltProducer->get_speed();
1065 GenTime Render::seekPosition() const {
1066 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1067 else return GenTime();
1071 const QString & Render::rendererName() const {
1076 void Render::emitFrameNumber(double position) {
1077 if (m_generateScenelist) return;
1078 m_framePosition = position;
1079 emit rendererPosition((int) position);
1080 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1083 void Render::emitConsumerStopped() {
1084 // This is used to know when the playing stopped
1085 if (m_mltProducer && !m_generateScenelist) {
1086 double pos = m_mltProducer->position();
1087 emit rendererStopped((int) pos);
1088 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1089 //new QCustomEvent(10002));
1095 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1096 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1100 void Render::exportCurrentFrame(KUrl url, bool notify) {
1101 if (!m_mltProducer) {
1102 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1106 int height = 1080;//KdenliveSettings::defaultheight();
1107 int width = 1940; //KdenliveSettings::displaywidth();
1109 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1111 QPixmap pix(width, height);
1112 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1113 m_convert.set("forced", mlt_image_rgb24a);
1114 m_mltProducer->attach(m_convert);
1115 Mlt::Frame * frame = m_mltProducer->get_frame();
1116 m_mltProducer->detach(m_convert);
1118 pix = frameThumbnail(frame, width, height);
1121 pix.save(url.path(), "PNG");
1122 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1125 /** MLT PLAYLIST DIRECT MANIPULATON **/
1128 void Render::mltCheckLength(bool reload) {
1129 //kDebug()<<"checking track length: "<<track<<"..........";
1131 Mlt::Service service(m_mltProducer->get_service());
1132 Mlt::Tractor tractor(service);
1134 int trackNb = tractor.count();
1135 double duration = 0;
1136 double trackDuration;
1138 Mlt::Producer trackProducer(tractor.track(0));
1139 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1140 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1141 m_mltProducer->set("out", duration);
1142 emit durationChanged((int) duration);
1145 while (trackNb > 1) {
1146 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1147 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1148 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1150 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1151 if (trackDuration > duration) duration = trackDuration;
1155 Mlt::Producer blackTrackProducer(tractor.track(0));
1156 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1157 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1159 if (blackDuration != duration) {
1160 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1162 int dur = (int)duration;
1164 QDomElement black = doc.createElement("producer");
1165 black.setAttribute("mlt_service", "colour");
1166 black.setAttribute("colour", "black");
1167 black.setAttribute("id", "black");
1170 while (dur > 14000) {
1171 info.startPos = GenTime(i * 14000, m_fps);
1172 info.endPos = info.startPos + GenTime(13999, m_fps);
1173 mltInsertClip(info, black, m_blackClip);
1178 info.startPos = GenTime(i * 14000, m_fps);
1179 info.endPos = info.startPos + GenTime(dur, m_fps);
1180 mltInsertClip(info, black, m_blackClip);
1182 m_mltProducer->set("out", duration);
1183 emit durationChanged((int)duration);
1187 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1188 if (!m_mltProducer) {
1189 kDebug() << "PLAYLIST NOT INITIALISED //////";
1192 Mlt::Producer parentProd(m_mltProducer->parent());
1193 if (parentProd.get_producer() == NULL) {
1194 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1198 Mlt::Service service(parentProd.get_service());
1199 Mlt::Tractor tractor(service);
1200 mlt_service_lock(service.get_service());
1201 Mlt::Producer trackProducer(tractor.track(info.track));
1202 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1204 Mlt::Producer *clip = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1205 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1207 if (QString(prod->get("transparency")).toInt() == 1)
1208 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());
1210 mlt_service_unlock(service.get_service());
1212 if (info.track != 0) mltCheckLength();
1213 //tractor.multitrack()->refresh();
1214 //tractor.refresh();
1218 void Render::mltCutClip(int track, GenTime position) {
1221 Mlt::Service service(m_mltProducer->parent().get_service());
1222 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1224 Mlt::Tractor tractor(service);
1225 Mlt::Producer trackProducer(tractor.track(track));
1226 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1227 trackPlaylist.split_at((int) position.frames(m_fps));
1228 trackPlaylist.consolidate_blanks(0);
1229 // duplicate effects
1230 Mlt::Producer *original = trackPlaylist.get_clip_at((int) position.frames(m_fps) - 1);
1231 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps) + 1);
1232 Mlt::Service clipService(original->get_service());
1233 Mlt::Service dupService(clip->get_service());
1235 Mlt::Filter *filter = clipService.filter(ct);
1237 Mlt::Filter *dup = new Mlt::Filter(filter->get_filter());
1238 dupService.attach(*dup);
1240 filter = clipService.filter(ct);
1244 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1246 mltRemoveClip(info.track, info.startPos);
1247 mltInsertClip(info, element, prod);
1251 void Render::mltRemoveClip(int track, GenTime position) {
1254 Mlt::Service service(m_mltProducer->parent().get_service());
1255 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1257 Mlt::Tractor tractor(service);
1258 Mlt::Producer trackProducer(tractor.track(track));
1259 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1260 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1261 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1262 if (QString(clip.parent().get("transparency")).toInt() == 1)
1263 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());
1264 trackPlaylist.replace_with_blank(clipIndex);
1265 trackPlaylist.consolidate_blanks(0);
1266 if (track != 0) mltCheckLength();
1267 //emit durationChanged();
1268 m_isBlocked = false;
1271 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1273 Mlt::Service service(m_mltProducer->parent().get_service());
1274 bool success = false;
1275 Mlt::Tractor tractor(service);
1276 Mlt::Producer trackProducer(tractor.track(track));
1277 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1278 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1279 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1281 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1284 Mlt::Service clipService(clip->get_service());
1285 // if (tag.startsWith("ladspa")) tag = "ladspa";
1288 Mlt::Filter *filter = clipService.filter(ct);
1290 if (index == "-1" || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1291 if (clipService.detach(*filter) == 0) success = true;
1292 kDebug() << " / / / DLEETED EFFECT: " << ct;
1294 filter = clipService.filter(ct);
1296 m_isBlocked = false;
1297 if (doRefresh) refresh();
1302 bool Render::mltAddEffect(int track, GenTime position, QMap <QString, QString> args, bool doRefresh) {
1304 Mlt::Service service(m_mltProducer->parent().get_service());
1306 Mlt::Tractor tractor(service);
1307 Mlt::Producer trackProducer(tractor.track(track));
1308 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1310 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1314 Mlt::Service clipService(clip->get_service());
1317 QString tag = args.value("tag");
1318 kDebug() << " / / INSERTING EFFECT: " << tag;
1319 if (tag.startsWith("ladspa")) tag = "ladspa";
1320 char *filterTag = decodedString(tag);
1321 char *filterId = decodedString(args.value("id"));
1322 QMap<QString, QString>::Iterator it;
1323 QString kfr = args.value("keyframes");
1325 if (!kfr.isEmpty()) {
1326 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1327 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1328 char *starttag = decodedString(args.value("starttag", "start"));
1329 char *endtag = decodedString(args.value("endtag", "end"));
1330 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1331 int duration = clip->get_playtime();
1332 double max = args.value("max").toDouble();
1333 double min = args.value("min").toDouble();
1334 double factor = args.value("factor", "1").toDouble();
1335 args.remove("starttag");
1336 args.remove("endtag");
1337 args.remove("keyframes");
1340 args.remove("factor");
1342 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1343 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1344 filter->set("kdenlive_id", filterId);
1345 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1346 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1347 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1348 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1349 if (x2 == -1) x2 = duration;
1350 for (it = args.begin(); it != args.end(); ++it) {
1351 char *name = decodedString(it.key());
1352 char *value = decodedString(it.value());
1353 filter->set(name, value);
1358 filter->set("in", x1);
1359 filter->set("out", x2);
1360 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1361 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1362 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1363 clipService.attach(*filter);
1369 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1370 if (filter && filter->is_valid())
1371 filter->set("kdenlive_id", filterId);
1373 kDebug() << "filter is NULL";
1374 m_isBlocked = false;
1378 for (it = args.begin(); it != args.end(); ++it) {
1379 char *name = decodedString(it.key());
1380 char *value = decodedString(it.value());
1381 filter->set(name, value);
1385 // attach filter to the clip
1386 clipService.attach(*filter);
1390 m_isBlocked = false;
1391 if (doRefresh) refresh();
1395 bool Render::mltEditEffect(int track, GenTime position, QMap <QString, QString> args) {
1396 QString index = args.value("kdenlive_ix");
1397 QString tag = args.value("tag");
1398 QMap<QString, QString>::Iterator it = args.begin();
1399 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1400 // This is a keyframe effect, to edit it, we remove it and re-add it.
1401 mltRemoveEffect(track, position, index);
1402 bool success = mltAddEffect(track, position, args);
1407 Mlt::Service service(m_mltProducer->parent().get_service());
1409 Mlt::Tractor tractor(service);
1410 Mlt::Producer trackProducer(tractor.track(track));
1411 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1412 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1413 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1415 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1418 Mlt::Service clipService(clip->get_service());
1421 Mlt::Filter *filter = clipService.filter(ct);
1423 if (filter->get("kdenlive_ix") == index) {
1427 filter = clipService.filter(ct);
1431 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1432 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1434 filter = clipService.filter(ct);
1435 QList <Mlt::Filter *> filtersList;
1437 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1438 filtersList.append(filter);
1439 clipService.detach(*filter);
1441 filter = clipService.filter(ct);
1443 bool success = mltAddEffect(track, position, args);
1445 for (int i = 0; i < filtersList.count(); i++) {
1446 clipService.attach(*(filtersList.at(i)));
1449 m_isBlocked = false;
1453 for (it = args.begin(); it != args.end(); ++it) {
1454 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1455 char *name = decodedString(it.key());
1456 char *value = decodedString(it.value());
1457 filter->set(name, value);
1461 m_isBlocked = false;
1466 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1468 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1469 Mlt::Service service(m_mltProducer->parent().get_service());
1471 Mlt::Tractor tractor(service);
1472 Mlt::Producer trackProducer(tractor.track(track));
1473 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1474 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1475 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1477 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1480 Mlt::Service clipService(clip->get_service());
1483 QList <Mlt::Filter *> filtersList;
1484 Mlt::Filter *filter = clipService.filter(ct);
1486 if (newPos > oldPos) {
1488 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1489 filter->set("kdenlive_ix", newPos);
1490 filtersList.append(filter);
1491 clipService.detach(*filter);
1492 filter = clipService.filter(ct);
1493 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1494 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1496 filter = clipService.filter(ct);
1500 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1501 filtersList.append(filter);
1502 clipService.detach(*filter);
1504 filter = clipService.filter(ct);
1508 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1509 filter->set("kdenlive_ix", newPos);
1510 filtersList.append(filter);
1511 clipService.detach(*filter);
1513 filter = clipService.filter(ct);
1517 filter = clipService.filter(ct);
1519 int pos = QString(filter->get("kdenlive_ix")).toInt();
1520 if (pos >= newPos) {
1521 if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
1522 filtersList.append(filter);
1523 clipService.detach(*filter);
1525 filter = clipService.filter(ct);
1529 for (int i = 0; i < filtersList.count(); i++) {
1530 clipService.attach(*(filtersList.at(i)));
1533 m_isBlocked = false;
1537 void Render::mltResizeClipEnd(int track, GenTime pos, GenTime in, GenTime out) {
1540 Mlt::Service service(m_mltProducer->parent().get_service());
1542 Mlt::Tractor tractor(service);
1543 Mlt::Producer trackProducer(tractor.track(track));
1544 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1545 if (trackPlaylist.is_blank_at((int) pos.frames(m_fps) + 1))
1546 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1547 int clipIndex = trackPlaylist.get_clip_index_at((int) pos.frames(m_fps) + 1);
1548 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1549 int previousStart = trackPlaylist.clip_start(clipIndex);
1550 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1551 int newDuration = (int) out.frames(m_fps) - 1;
1552 trackPlaylist.resize_clip(clipIndex, (int) in.frames(m_fps), newDuration);
1553 trackPlaylist.consolidate_blanks(0);
1554 if (previousDuration < newDuration) {
1555 // clip was made longer, trim next blank if there is one.
1556 if (trackPlaylist.is_blank(clipIndex + 1)) {
1557 trackPlaylist.split(clipIndex + 1, newDuration - previousDuration);
1558 trackPlaylist.remove(clipIndex + 1);
1560 } else trackPlaylist.insert_blank(clipIndex + 1, previousDuration - newDuration - 1);
1562 trackPlaylist.consolidate_blanks(0);
1564 //tractor.multitrack()->refresh();
1565 //tractor.refresh();
1566 if (track != 0) mltCheckLength();
1567 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1568 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1569 mltDeleteTransparency(previousStart, track, QString(clip->parent().get("id")).toInt());
1571 info.startPos = pos;
1572 info.endPos = pos + out - in;
1574 mltAddClipTransparency(info, info.track - 1, QString(clip->parent().get("id")).toInt());
1576 m_isBlocked = false;
1579 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1580 Mlt::Service service(m_mltProducer->parent().get_service());
1581 Mlt::Tractor tractor(service);
1582 Mlt::Producer trackProducer(tractor.track(track));
1583 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1585 if (blind) trackProducer.set("hide", 3);
1586 else trackProducer.set("hide", 2);
1588 trackProducer.set("hide", 1);
1590 trackProducer.set("hide", 0);
1592 tractor.multitrack()->refresh();
1597 void Render::mltResizeClipStart(int track, GenTime pos, GenTime moveEnd, GenTime moveStart, GenTime in, GenTime out) {
1600 Mlt::Service service(m_mltProducer->parent().get_service());
1602 int moveFrame = (int)(moveEnd - moveStart).frames(m_fps);
1604 Mlt::Tractor tractor(service);
1605 Mlt::Producer trackProducer(tractor.track(track));
1606 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1607 if (trackPlaylist.is_blank_at((int) pos.frames(m_fps) - 1))
1608 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1609 int clipIndex = trackPlaylist.get_clip_index_at((int) pos.frames(m_fps) - 1);
1610 int previousStart = trackPlaylist.clip_start(clipIndex);
1611 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1612 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1613 trackPlaylist.resize_clip(clipIndex, (int) in.frames(m_fps), (int) out.frames(m_fps));
1614 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1616 int midpos = (int)moveStart.frames(m_fps) - 1; //+ (moveFrame / 2)
1617 int blankIndex = trackPlaylist.get_clip_index_at(midpos);
1618 int blankLength = trackPlaylist.clip_length(blankIndex);
1620 kDebug() << " + resizing blank: " << blankIndex << ", Mid: " << midpos << ", Length: " << blankLength << ", SIZE DIFF: " << moveFrame;
1622 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1623 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1625 trackPlaylist.consolidate_blanks(0);
1626 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1627 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
1628 mltDeleteTransparency(previousStart, track, QString(clip->parent().get("id")).toInt());
1630 info.startPos = moveEnd;
1631 info.endPos = moveEnd + out - in;
1633 mltAddClipTransparency(info, info.track - 1, QString(clip->parent().get("id")).toInt());
1635 m_isBlocked = false;
1638 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1639 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1643 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1646 m_mltConsumer->set("refresh", 0);
1647 mlt_service_lock(m_mltConsumer->get_service());
1648 Mlt::Service service(m_mltProducer->parent().get_service());
1649 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1651 Mlt::Tractor tractor(service);
1652 Mlt::Producer trackProducer(tractor.track(startTrack));
1653 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1654 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1655 if (endTrack == startTrack) {
1656 //mlt_service_lock(service.get_service());
1657 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1658 trackPlaylist.consolidate_blanks(0);
1660 if (!trackPlaylist.is_blank_at(moveEnd)) {
1661 // error, destination is not empty
1662 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
1663 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
1664 mlt_service_unlock(m_mltConsumer->get_service());
1665 m_isBlocked = false;
1668 trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1669 trackPlaylist.consolidate_blanks(0);
1670 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1671 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1674 //mlt_service_unlock(service.get_service());
1676 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1677 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1678 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
1679 // error, destination is not empty
1680 mlt_service_unlock(m_mltConsumer->get_service());
1681 m_isBlocked = false;
1684 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1685 trackPlaylist.consolidate_blanks(0);
1686 destTrackPlaylist.consolidate_blanks(1);
1687 destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1688 destTrackPlaylist.consolidate_blanks(0);
1689 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1690 kDebug() << "//////// moving clip transparency";
1691 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1696 mlt_service_unlock(m_mltConsumer->get_service());
1697 m_isBlocked = false;
1698 m_mltConsumer->set("refresh", 1);
1702 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1704 Mlt::Service service(m_mltProducer->parent().get_service());
1705 Mlt::Tractor tractor(service);
1706 Mlt::Field *field = tractor.field();
1708 mlt_service_lock(service.get_service());
1709 m_mltConsumer->set("refresh", 0);
1712 mlt_service serv = m_mltProducer->parent().get_service();
1713 mlt_service nextservice = mlt_service_get_producer(serv);
1714 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1715 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1716 QString resource = mlt_properties_get(properties, "mlt_service");
1717 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1719 int new_in = (int)newIn.frames(m_fps);
1720 int new_out = (int)newOut.frames(m_fps);
1722 while (mlt_type == "transition") {
1723 mlt_transition tr = (mlt_transition) nextservice;
1724 int currentTrack = mlt_transition_get_b_track(tr);
1725 int currentIn = (int) mlt_transition_get_in(tr);
1726 int currentOut = (int) mlt_transition_get_out(tr);
1728 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1729 mlt_transition_set_in_and_out(tr, new_in, new_out);
1730 if (newTrack - startTrack != 0) {
1731 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
1733 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1734 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
1735 mlt_properties_set_int(properties, "b_track", newTrack);
1736 //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);
1740 nextservice = mlt_service_producer(nextservice);
1741 if (nextservice == NULL) break;
1742 properties = MLT_SERVICE_PROPERTIES(nextservice);
1743 mlt_type = mlt_properties_get(properties, "mlt_type");
1744 resource = mlt_properties_get(properties, "mlt_service");
1746 m_isBlocked = false;
1747 mlt_service_unlock(service.get_service());
1748 m_mltConsumer->set("refresh", 1);
1751 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1752 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
1753 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
1755 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
1756 mltAddTransition(tag, a_track, b_track, in, out, xml);
1758 //mltSavePlaylist();
1761 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1764 Mlt::Service service(m_mltProducer->parent().get_service());
1765 Mlt::Tractor tractor(service);
1766 Mlt::Field *field = tractor.field();
1768 //m_mltConsumer->set("refresh", 0);
1769 mlt_service serv = m_mltProducer->parent().get_service();
1771 mlt_service nextservice = mlt_service_get_producer(serv);
1772 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1773 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1774 QString resource = mlt_properties_get(properties, "mlt_service");
1775 int in_pos = (int) in.frames(m_fps);
1776 int out_pos = (int) out.frames(m_fps);
1778 while (mlt_type == "transition") {
1779 mlt_transition tr = (mlt_transition) nextservice;
1780 int currentTrack = mlt_transition_get_b_track(tr);
1781 int currentIn = (int) mlt_transition_get_in(tr);
1782 int currentOut = (int) mlt_transition_get_out(tr);
1784 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
1786 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
1787 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
1788 QMap<QString, QString>::Iterator it;
1790 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
1792 for (it = map.begin(); it != map.end(); ++it) {
1794 char *name = decodedString(key);
1795 char *value = decodedString(it.value());
1796 mlt_properties_set(transproperties, name, value);
1797 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
1798 //filter->set("kdenlive_id", id);
1804 nextservice = mlt_service_producer(nextservice);
1805 if (nextservice == NULL) break;
1806 properties = MLT_SERVICE_PROPERTIES(nextservice);
1807 mlt_type = mlt_properties_get(properties, "mlt_type");
1808 resource = mlt_properties_get(properties, "mlt_service");
1810 m_isBlocked = false;
1811 m_mltConsumer->set("refresh", 1);
1814 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
1815 Mlt::Service service(m_mltProducer->parent().get_service());
1816 Mlt::Tractor tractor(service);
1817 Mlt::Field *field = tractor.field();
1819 if (do_refresh) m_mltConsumer->set("refresh", 0);
1820 mlt_service serv = m_mltProducer->parent().get_service();
1822 mlt_service nextservice = mlt_service_get_producer(serv);
1823 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1824 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1825 QString resource = mlt_properties_get(properties, "mlt_service");
1826 int old_pos = (int)((in + out).frames(m_fps) / 2);
1828 while (mlt_type == "transition") {
1829 mlt_transition tr = (mlt_transition) nextservice;
1830 int currentTrack = mlt_transition_get_b_track(tr);
1831 int currentIn = (int) mlt_transition_get_in(tr);
1832 int currentOut = (int) mlt_transition_get_out(tr);
1833 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
1835 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1836 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
1837 mlt_field_disconnect_service(field->get_field(), nextservice);
1840 nextservice = mlt_service_producer(nextservice);
1841 if (nextservice == NULL) break;
1842 properties = MLT_SERVICE_PROPERTIES(nextservice);
1843 mlt_type = mlt_properties_get(properties, "mlt_type");
1844 resource = mlt_properties_get(properties, "mlt_service");
1846 if (do_refresh) m_mltConsumer->set("refresh", 1);
1849 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
1850 QDomNodeList attribs = xml.elementsByTagName("parameter");
1851 QMap<QString, QString> map;
1852 for (int i = 0;i < attribs.count();i++) {
1853 QDomElement e = attribs.item(i).toElement();
1854 QString name = e.attribute("name");
1855 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
1856 map[name] = e.attribute("default");
1857 if (!e.attribute("value").isEmpty()) {
1858 map[name] = e.attribute("value");
1860 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
1861 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
1862 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
1865 if (e.attribute("namedesc").contains(";")) {
1866 QString format = e.attribute("format");
1867 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1868 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1870 QTextStream txtNeu(&neu);
1871 if (values.size() > 0)
1872 txtNeu << (int)values[0].toDouble();
1874 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
1875 txtNeu << separators[i];
1876 txtNeu << (int)(values[i+1].toDouble());
1878 if (i < separators.size())
1879 txtNeu << separators[i];
1880 map[e.attribute("name")] = neu;
1887 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
1888 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
1889 Mlt::Service service(m_mltProducer->parent().get_service());
1890 Mlt::Tractor tractor(service);
1891 Mlt::Field *field = tractor.field();
1893 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
1894 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
1895 transition->set("transparency", id);
1896 transition->set("fill", 1);
1897 transition->set("internal_added", 237);
1898 field->plant_transition(*transition, transitiontrack, info.track);
1902 void Render::mltDeleteTransparency(int pos, int track, int id) {
1903 Mlt::Service service(m_mltProducer->parent().get_service());
1904 Mlt::Tractor tractor(service);
1905 Mlt::Field *field = tractor.field();
1907 //if (do_refresh) m_mltConsumer->set("refresh", 0);
1908 mlt_service serv = m_mltProducer->parent().get_service();
1910 mlt_service nextservice = mlt_service_get_producer(serv);
1911 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1912 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1913 QString resource = mlt_properties_get(properties, "mlt_service");
1915 while (mlt_type == "transition") {
1916 mlt_transition tr = (mlt_transition) nextservice;
1917 int currentTrack = mlt_transition_get_b_track(tr);
1918 int currentIn = (int) mlt_transition_get_in(tr);
1919 int currentOut = (int) mlt_transition_get_out(tr);
1920 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
1921 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
1923 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
1924 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
1925 mlt_field_disconnect_service(field->get_field(), nextservice);
1928 nextservice = mlt_service_producer(nextservice);
1929 if (nextservice == NULL) break;
1930 properties = MLT_SERVICE_PROPERTIES(nextservice);
1931 mlt_type = mlt_properties_get(properties, "mlt_type");
1932 resource = mlt_properties_get(properties, "mlt_service");
1934 //if (do_refresh) m_mltConsumer->set("refresh", 1);
1937 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
1938 Mlt::Service service(m_mltProducer->parent().get_service());
1939 Mlt::Tractor tractor(service);
1940 Mlt::Field *field = tractor.field();
1942 mlt_service_lock(service.get_service());
1943 m_mltConsumer->set("refresh", 0);
1946 mlt_service serv = m_mltProducer->parent().get_service();
1947 mlt_service nextservice = mlt_service_get_producer(serv);
1948 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1949 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1950 QString resource = mlt_properties_get(properties, "mlt_service");
1951 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
1952 while (mlt_type == "transition") {
1953 mlt_transition tr = (mlt_transition) nextservice;
1954 int currentTrack = mlt_transition_get_b_track(tr);
1955 int currentIn = (int) mlt_transition_get_in(tr);
1956 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
1957 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
1958 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
1959 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
1960 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
1961 mlt_transition_set_in_and_out(tr, newStart, newEnd);
1964 nextservice = mlt_service_producer(nextservice);
1965 if (nextservice == NULL) break;
1966 properties = MLT_SERVICE_PROPERTIES(nextservice);
1967 mlt_type = mlt_properties_get(properties, "mlt_type");
1968 resource = mlt_properties_get(properties, "mlt_service");
1970 m_isBlocked = false;
1971 mlt_service_unlock(service.get_service());
1972 m_mltConsumer->set("refresh", 1);
1976 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
1977 Mlt::Service service(m_mltProducer->parent().get_service());
1978 Mlt::Tractor tractor(service);
1979 Mlt::Field *field = tractor.field();
1981 mlt_service_lock(service.get_service());
1982 m_mltConsumer->set("refresh", 0);
1985 mlt_service serv = m_mltProducer->parent().get_service();
1986 mlt_service nextservice = mlt_service_get_producer(serv);
1987 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1988 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1989 QString resource = mlt_properties_get(properties, "mlt_service");
1991 while (mlt_type == "transition") {
1992 mlt_transition tr = (mlt_transition) nextservice;
1993 int currentTrack = mlt_transition_get_b_track(tr);
1994 int currentaTrack = mlt_transition_get_a_track(tr);
1995 int currentIn = (int) mlt_transition_get_in(tr);
1996 int currentOut = (int) mlt_transition_get_out(tr);
1997 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1998 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
1999 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2000 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2001 kDebug() << "//////MOVING";
2002 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2003 if (endTrack != startTrack) {
2004 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2005 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2006 mlt_properties_set_int(properties, "b_track", endTrack);
2010 nextservice = mlt_service_producer(nextservice);
2011 if (nextservice == NULL) break;
2012 properties = MLT_SERVICE_PROPERTIES(nextservice);
2013 mlt_type = mlt_properties_get(properties, "mlt_type");
2014 resource = mlt_properties_get(properties, "mlt_service");
2016 m_isBlocked = false;
2017 mlt_service_unlock(service.get_service());
2018 m_mltConsumer->set("refresh", 1);
2022 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2024 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2025 Mlt::Service service(m_mltProducer->parent().get_service());
2027 Mlt::Tractor tractor(service);
2028 Mlt::Field *field = tractor.field();
2030 char *transId = decodedString(tag);
2031 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2032 if (out != GenTime())
2033 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
2034 QMap<QString, QString>::Iterator it;
2037 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2039 for (it = args.begin(); it != args.end(); ++it) {
2041 char *name = decodedString(key);
2042 char *value = decodedString(it.value());
2043 transition->set(name, value);
2044 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2045 //filter->set("kdenlive_id", id);
2049 // attach filter to the clip
2050 field->plant_transition(*transition, a_track, b_track);
2055 void Render::mltSavePlaylist() {
2056 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2057 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2058 fileConsumer.set("resource", "/tmp/playlist.westley");
2060 Mlt::Service service(m_mltProducer->get_service());
2062 fileConsumer.connect(service);
2063 fileConsumer.start();
2067 #include "renderer.moc"