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
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 <ffmpeg/avformat.h>
46 #include <mlt++/Mlt.h>
48 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
49 // detect if the producer has finished playing. Is there a better way to do it ?
50 //if (self->isBlocked) return;
51 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
52 self->emitConsumerStopped();
54 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
58 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) {
59 kDebug() << "////////// USING PROFILE: " << (char *)KdenliveSettings::current_profile().toUtf8().data();
60 m_mltProfile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
61 refreshTimer = new QTimer(this);
62 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
64 m_connectTimer = new QTimer(this);
65 connect(m_connectTimer, SIGNAL(timeout()), this, SLOT(connectPlaylist()));
67 if (rendererName == "project") m_monitorId = 10000;
68 else m_monitorId = 10001;
69 osdTimer = new QTimer(this);
70 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
72 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
73 //if (rendererName == "clip")
75 //Mlt::Consumer *consumer = new Mlt::Consumer( profile , "sdl_preview");
76 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
77 m_mltConsumer->set("resize", 1);
78 m_mltConsumer->set("window_id", winid);
79 m_mltConsumer->set("terminate_on_pause", 1);
80 m_mltConsumer->set("rescale", "nearest");
81 m_mltConsumer->set("progressive", 1);
82 m_mltConsumer->set("audio_buffer", 1024);
83 m_mltConsumer->set("frequency", 48000);
84 m_externalwinid = extid;
86 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
87 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", "<westley><playlist><producer mlt_service=\"colour\" colour=\"blue\" in=\"0\" out=\"25\" /></playlist></westley>");
88 m_mltProducer = producer;
89 m_mltConsumer->connect(*m_mltProducer);
90 m_mltProducer->set_speed(0.0);
92 //m_mltConsumer->start();
96 /*m_osdInfo = new Mlt::Filter("data_show");
97 char *tmp = decodedString(m_osdProfile);
98 m_osdInfo->set("resource", tmp);
100 // Does it do anything usefull? I mean, RenderThread doesn't do anything useful at the moment
101 // (except being cpu hungry :)
103 /* if(!s_renderThread) {
104 s_renderThread = new RenderThread;
105 s_renderThread->start();
114 void Render::closeMlt() {
115 delete m_connectTimer;
119 delete m_mltConsumer;
121 delete m_mltProducer;
127 int Render::resetProfile(QString profile) {
128 if (!m_mltConsumer) return 0;
129 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
130 m_mltConsumer->set("refresh", 0);
131 m_mltConsumer->purge();
132 delete m_mltConsumer;
133 m_mltConsumer = NULL;
134 QString scene = sceneList();
135 if (m_mltProducer) delete m_mltProducer;
136 m_mltProducer = NULL;
137 if (m_mltProfile) delete m_mltProfile;
140 m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
141 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
142 m_mltConsumer->set("resize", 1);
143 m_mltConsumer->set("window_id", m_winid);
144 m_mltConsumer->set("terminate_on_pause", 1);
145 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
146 m_mltConsumer->set("rescale", "nearest");
147 m_mltConsumer->set("progressive", 1);
148 m_mltConsumer->set("audio_buffer", 1024);
149 m_mltConsumer->set("frequency", 48000);
151 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", (char *) scene.toUtf8().data());
152 m_mltProducer = producer;
153 m_mltConsumer->connect(*m_mltProducer);
154 m_mltProducer->set_speed(0.0);
156 //delete m_mltProfile;
157 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
158 //mlt_profile prof = m_mltProfile->get_profile();
159 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
160 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
161 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
162 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
163 kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << profile << ", WIDTH: " << m_mltProfile->width();
165 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
170 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
171 void Render::seek(GenTime time) {
172 sendSeekCommand(time);
173 //emit positionChanged(time);
177 char *Render::decodedString(QString str) {
178 /*QCString fn = QFile::encodeName(str);
179 char *t = new char[fn.length() + 1];
180 strcpy(t, (const char *)fn);*/
182 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
186 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
187 QPixmap pix(width, height);
189 mlt_image_format format = mlt_image_rgb24a;
190 uint8_t *thumb = frame->get_image(format, width, height);
191 QImage image(thumb, width, height, QImage::Format_ARGB32);
193 if (!image.isNull()) {
194 pix = pix.fromImage(image);
196 QPainter painter(&pix);
197 painter.drawRect(0, 0, width - 1, height - 1);
199 } else pix.fill(Qt::black);
203 const int Render::renderWidth() const {
204 return (int)(m_mltProfile->height() * m_mltProfile->dar());
207 const int Render::renderHeight() const {
208 return m_mltProfile->height();
211 QPixmap Render::extractFrame(int frame_position, int width, int height) {
213 width = renderWidth();
214 height = renderHeight();
216 QPixmap pix(width, height);
217 if (!m_mltProducer) {
221 //Mlt::Producer *mlt_producer = m_mltProducer->cut(frame_position, frame_position + 1);
222 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
223 /*Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
224 m_convert.set("forced", mlt_image_rgb24a);
225 mlt_producer->attach(m_convert);
226 Mlt::Frame *frame = mlt_producer->get_frame();
229 pix = frameThumbnail(frame, width, height);
231 } else pix.fill(Qt::black);
236 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
239 if (url.fileName().startsWith(".all.")) { // check for slideshow
240 QString fileType = url.fileName().right(3);
242 QStringList::Iterator it;
244 QDir dir(url.directory());
245 more = dir.entryList(QDir::Files);
247 for (it = more.begin() ; it != more.end() ; ++it) {
248 if ((*it).endsWith("." + fileType, Qt::CaseInsensitive)) {
249 im.load(url.directory() + "/" + *it);
253 } else im.load(url.path());
254 //pixmap = im.scaled(width, height);
259 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
260 QPixmap pix(width, height);
261 char *tmp = decodedString(file);
262 Mlt::Profile *prof = new Mlt::Profile(profile);
263 Mlt::Producer m_producer(*prof, tmp);
265 if (m_producer.is_blank()) {
270 Mlt::Filter m_convert(*prof, "avcolour_space");
271 m_convert.set("forced", mlt_image_rgb24a);
272 m_producer.attach(m_convert);
273 m_producer.seek(frame_position);
274 Mlt::Frame * frame = m_producer.get_frame();
276 pix = frameThumbnail(frame, width, height, true);
279 if (prof) delete prof;
284 void Render::getImage(KUrl url, int frame_position, QPoint size)
286 char *tmp = decodedString(url.path());
287 Mlt::Producer m_producer(tmp);
289 if (m_producer.is_blank()) {
292 Mlt::Filter m_convert("avcolour_space");
293 m_convert.set("forced", mlt_image_rgb24a);
294 m_producer.attach(m_convert);
295 m_producer.seek(frame_position);
297 Mlt::Frame * frame = m_producer.get_frame();
300 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
302 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
306 /* Create thumbnail for color */
307 /*void Render::getImage(int id, QString color, QPoint size)
309 QPixmap pixmap(size.x() - 2, size.y() - 2);
310 color = color.replace(0, 2, "#");
311 color = color.left(7);
312 pixmap.fill(QColor(color));
313 QPixmap result(size.x(), size.y());
314 result.fill(Qt::black);
315 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
316 emit replyGetImage(id, result, size.x(), size.y());
320 /* Create thumbnail for image */
321 /*void Render::getImage(KUrl url, QPoint size)
325 if (url.fileName().startsWith(".all.")) { // check for slideshow
326 QString fileType = url.fileName().right(3);
328 QStringList::Iterator it;
330 QDir dir( url.directory() );
331 more = dir.entryList( QDir::Files );
332 for ( it = more.begin() ; it != more.end() ; ++it ) {
333 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
334 if (!im.load(url.directory() + "/" + *it))
335 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
340 else im.load(url.path());
342 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
343 QPixmap result(size.x(), size.y());
344 result.fill(Qt::black);
345 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
346 emit replyGetImage(url, 1, result, size.x(), size.y());
350 double Render::consumerRatio() const {
351 if (!m_mltConsumer) return 1.0;
352 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
356 int Render::getLength() {
359 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
360 return mlt_producer_get_playtime(m_mltProducer->get_producer());
365 bool Render::isValid(KUrl url) {
366 char *tmp = decodedString(url.path());
367 Mlt::Producer producer(*m_mltProfile, tmp);
369 if (producer.is_blank())
375 void Render::getFileProperties(const QDomElement &xml, int clipId) {
377 int width = (int)(height * m_mltProfile->dar());
379 QDomElement westley = doc.createElement("westley");
380 doc.appendChild(westley);
381 westley.appendChild(doc.importNode(xml, true));
382 //kDebug() << "////////////\n" << doc.toString() << "////////////////\n";
383 char *tmp = decodedString(doc.toString());
385 Mlt::Producer producer(*m_mltProfile, "westley-xml", tmp);
388 if (producer.is_blank()) {
391 int frameNumber = xml.attribute("frame_thumbnail", 0).toInt();
392 if (frameNumber != 0) producer.seek(frameNumber);
393 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer.get_producer());
395 QMap < QString, QString > filePropertyMap;
396 QMap < QString, QString > metadataPropertyMap;
398 KUrl url = xml.attribute("resource", QString::null);
399 filePropertyMap["filename"] = url.path();
400 filePropertyMap["duration"] = QString::number(producer.get_playtime());
401 kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
402 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
403 m_convert.set("forced", mlt_image_rgb24a);
404 producer.attach(m_convert);
405 Mlt::Frame * frame = producer.get_frame();
407 //filePropertyMap["fps"] = QString::number(mlt_producer_get_fps(producer.get_producer()));
408 filePropertyMap["fps"] = producer.get("source_fps");
410 if (frame && frame->is_valid()) {
411 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
412 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
413 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
414 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
416 if (frame->get_int("test_image") == 0) {
417 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
418 filePropertyMap["type"] = "playlist";
419 metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer.get_service()), "title"));
420 } else if (frame->get_int("test_audio") == 0)
421 filePropertyMap["type"] = "av";
423 filePropertyMap["type"] = "video";
425 // Generate thumbnail for this frame
426 QPixmap pixmap = KThumb::getFrame(&producer, 0, width, height);
428 emit replyGetImage(clipId, 0, pixmap, width, height);
430 } else if (frame->get_int("test_audio") == 0) {
431 QPixmap pixmap(KStandardDirs::locate("appdata", "graphics/music.png"));
432 emit replyGetImage(clipId, 0, pixmap, width, height);
433 filePropertyMap["type"] = "audio";
437 // Retrieve audio / video codec name
439 // Fetch the video_context
441 AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
442 if (context != NULL) {
443 // Get the video_index
444 int index = mlt_properties_get_int(properties, "video_index");
445 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
446 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
448 context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
449 if (context != NULL) {
450 // Get the video_index
451 int index = mlt_properties_get_int(properties, "audio_index");
452 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
453 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
458 mlt_properties metadata = mlt_properties_new();
459 mlt_properties_pass(metadata, properties, "meta.attr.");
460 int count = mlt_properties_count(metadata);
461 for (int i = 0; i < count; i ++) {
462 QString name = mlt_properties_get_name(metadata, i);
463 QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
464 if (name.endsWith("markup") && !value.isEmpty())
465 metadataPropertyMap[ name.section(".", 0, -2)] = value;
468 emit replyGetFileProperties(clipId, filePropertyMap, metadataPropertyMap);
469 kDebug() << "REquested fuile info for: " << url.path();
470 if (frame) delete frame;
473 /** Create the producer from the Westley QDomDocument */
475 void Render::initSceneList() {
476 kDebug() << "-------- INIT SCENE LIST ------_";
478 QDomElement westley = doc.createElement("westley");
479 doc.appendChild(westley);
480 QDomElement prod = doc.createElement("producer");
481 prod.setAttribute("resource", "colour");
482 prod.setAttribute("colour", "red");
483 prod.setAttribute("id", "black");
484 prod.setAttribute("in", "0");
485 prod.setAttribute("out", "0");
487 QDomElement tractor = doc.createElement("tractor");
488 QDomElement multitrack = doc.createElement("multitrack");
490 QDomElement playlist1 = doc.createElement("playlist");
491 playlist1.appendChild(prod);
492 multitrack.appendChild(playlist1);
493 QDomElement playlist2 = doc.createElement("playlist");
494 multitrack.appendChild(playlist2);
495 QDomElement playlist3 = doc.createElement("playlist");
496 multitrack.appendChild(playlist3);
497 QDomElement playlist4 = doc.createElement("playlist");
498 multitrack.appendChild(playlist4);
499 QDomElement playlist5 = doc.createElement("playlist");
500 multitrack.appendChild(playlist5);
501 tractor.appendChild(multitrack);
502 westley.appendChild(tractor);
503 // kDebug()<<doc.toString();
505 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
506 setSceneList(doc, 0);
509 /** Create the producer from the Westley QDomDocument */
510 void Render::setSceneList(QDomDocument list, int position) {
511 setSceneList(list.toString(), position);
514 /** Create the producer from the Westley QDomDocument */
515 void Render::setSceneList(QString playlist, int position) {
516 if (m_winid == -1) return;
517 m_generateScenelist = true;
519 kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
523 if (!clip.is_valid()) {
524 kWarning()<<" ++++ WARNING, UNABLE TO CREATE MLT PRODUCER";
525 m_generateScenelist = false;
530 m_mltConsumer->stop();
531 m_mltConsumer->set("refresh", 0);
534 m_mltProducer->set_speed(0.0);
535 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
537 delete m_mltProducer;
538 m_mltProducer = NULL;
542 char *tmp = decodedString(playlist);
543 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
545 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
546 //m_mltProducer->optimise();
547 if (position != 0) m_mltProducer->seek(position);
549 /*if (KdenliveSettings::osdtimecode()) {
550 // Attach filter for on screen display of timecode
552 QString attr = "attr_check";
553 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
554 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
555 mlt_producer_attach( m_mltProducer->get_producer(), filter );
556 mlt_filter_close( filter );
558 m_osdInfo = new Mlt::Filter("data_show");
559 tmp = decodedString(m_osdProfile);
560 m_osdInfo->set("resource", tmp);
562 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
563 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
564 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
565 m_osdInfo->set("dynamic", "1");
567 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
569 m_osdInfo->set("dynamic", "0");
572 m_fps = m_mltProducer->get_fps();
573 emit durationChanged(m_mltProducer->get_playtime());
574 //m_connectTimer->start( 1000 );
576 m_generateScenelist = false;
580 /** Create the producer from the Westley QDomDocument */
581 QString Render::sceneList() {
586 saveSceneList(temp.fileName());
587 QFile file(temp.fileName());
588 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
589 kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE";
592 QTextStream in(&file);
593 while (!in.atEnd()) {
594 result.append(in.readLine());
600 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
602 char *tmppath = decodedString("westley:" + path);
603 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
605 westleyConsumer.set("terminate_on_pause", 1);
606 Mlt::Producer prod(m_mltProducer->get_producer());
607 westleyConsumer.connect(prod);
608 //prod.set("title", "kdenlive document");
609 //westleyConsumer.listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
610 westleyConsumer.start();
611 while (!westleyConsumer.is_stopped()) {}
612 if (!kdenliveData.isNull()) {
613 // add Kdenlive specific tags
616 doc.setContent(&file, false);
617 QDomNode wes = doc.elementsByTagName("westley").at(0);
618 wes.appendChild(doc.importNode(kdenliveData, true));
620 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
621 kWarning() << "////// ERROR writing to file: " << path;
624 QTextStream out(&file);
625 out << doc.toString();
631 const double Render::fps() const {
635 void Render::connectPlaylist() {
636 if (!m_mltConsumer) return;
637 m_connectTimer->stop();
638 m_mltConsumer->set("refresh", "0");
639 m_mltConsumer->connect(*m_mltProducer);
640 m_mltProducer->set_speed(0.0);
641 m_mltConsumer->start();
644 if (m_mltConsumer->start() == -1) {
645 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."));
646 m_mltConsumer = NULL;
653 void Render::refreshDisplay() {
655 if (!m_mltProducer) return;
656 m_mltConsumer->set("refresh", 0);
658 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
659 /*if (KdenliveSettings::osdtimecode()) {
660 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
661 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
662 m_osdInfo->set("dynamic", "1");
663 m_mltProducer->attach(*m_osdInfo);
666 m_mltProducer->detach(*m_osdInfo);
667 m_osdInfo->set("dynamic", "0");
672 void Render::setVolume(double volume) {
673 if (!m_mltConsumer || !m_mltProducer) return;
675 m_mltConsumer->set("refresh", 0);
676 // Attach filter for on screen display of timecode
677 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
678 mlt_properties_set_double( properties, "meta.volume", volume );
679 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
680 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
682 if (!KdenliveSettings::osdtimecode()) {
683 m_mltProducer->detach(*m_osdInfo);
684 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
685 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
688 osdTimer->setSingleShot(2500);
691 void Render::slotOsdTimeout() {
692 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
693 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
694 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
695 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
699 void Render::start() {
700 kDebug() << "----- STARTING MONITOR: " << m_name;
702 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
706 if (m_mltConsumer->is_stopped()) {
707 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
708 if (m_mltConsumer->start() == -1) {
709 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."));
710 m_mltConsumer = NULL;
713 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
720 void Render::clear() {
722 m_mltConsumer->set("refresh", 0);
723 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
727 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
728 m_mltProducer->set_speed(0.0);
729 delete m_mltProducer;
730 m_mltProducer = NULL;
735 void Render::stop() {
736 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
737 kDebug() << "///////////// RENDER STOPPED: " << m_name;
738 m_mltConsumer->set("refresh", 0);
739 m_mltConsumer->stop();
741 kDebug() << "///////////// RENDER STOP2-------";
745 m_mltProducer->set_speed(0.0);
746 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
747 kDebug() << m_mltProducer->get_length();
749 kDebug() << "///////////// RENDER STOP3-------";
752 void Render::stop(const GenTime & startTime) {
753 kDebug() << "///////////// RENDER STOP-------2";
755 m_mltProducer->set_speed(0.0);
756 m_mltProducer->seek((int) startTime.frames(m_fps));
758 m_mltConsumer->purge();
761 void Render::switchPlay() {
764 if (m_mltProducer->get_speed() == 0.0) m_mltProducer->set_speed(1.0);
766 m_mltProducer->set_speed(0.0);
767 kDebug() << "// POSITON: " << m_framePosition;
768 m_mltProducer->seek((int) m_framePosition);
771 /*if (speed == 0.0) {
772 m_mltProducer->seek((int) m_framePosition + 1);
773 m_mltConsumer->purge();
778 void Render::play(double speed) {
781 if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
782 m_mltProducer->set_speed(speed);
783 /*if (speed == 0.0) {
784 m_mltProducer->seek((int) m_framePosition + 1);
785 m_mltConsumer->purge();
790 void Render::play(double speed, const GenTime & startTime) {
791 kDebug() << "///////////// RENDER PLAY2-------" << speed;
794 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
795 //if (speed == 0.0) m_mltConsumer->set("refresh", 0);
796 m_mltProducer->set_speed(speed);
797 m_mltProducer->seek((int)(startTime.frames(m_fps)));
798 //m_mltConsumer->purge();
802 void Render::play(double speed, const GenTime & startTime,
803 const GenTime & stopTime) {
804 kDebug() << "///////////// RENDER PLAY3-------" << speed << stopTime.frames(m_fps);
807 m_mltProducer->set("out", stopTime.frames(m_fps));
808 m_mltProducer->seek((int)(startTime.frames(m_fps)));
809 m_mltConsumer->purge();
810 m_mltProducer->set_speed(speed);
815 void Render::sendSeekCommand(GenTime time) {
818 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
819 m_mltProducer->seek((int)(time.frames(m_fps)));
823 void Render::seekToFrame(int pos) {
826 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
827 m_mltProducer->seek(pos);
831 void Render::askForRefresh() {
832 // Use a Timer so that we don't refresh too much
833 refreshTimer->start(200);
836 void Render::doRefresh() {
837 // Use a Timer so that we don't refresh too much
841 void Render::refresh() {
842 if (!m_mltProducer || m_isBlocked)
844 refreshTimer->stop();
846 m_mltConsumer->set("refresh", 1);
850 /** Sets the description of this renderer to desc. */
851 void Render::setDescription(const QString & description) {
852 m_description = description;
855 /** Returns the description of this renderer */
856 QString Render::description() {
857 return m_description;
861 double Render::playSpeed() {
862 if (m_mltProducer) return m_mltProducer->get_speed();
866 GenTime Render::seekPosition() const {
867 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
868 else return GenTime();
872 const QString & Render::rendererName() const {
877 void Render::emitFrameNumber(double position) {
878 //kDebug()<<"// POSITON: "<<m_framePosition;
879 if (m_generateScenelist) return;
880 m_framePosition = position;
881 emit rendererPosition((int) position);
882 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
885 void Render::emitConsumerStopped() {
886 // This is used to know when the playing stopped
887 if (m_mltProducer && !m_generateScenelist) {
888 double pos = m_mltProducer->position();
889 emit rendererStopped((int) pos);
890 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
891 //new QCustomEvent(10002));
897 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
898 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
902 void Render::exportCurrentFrame(KUrl url, bool notify) {
903 if (!m_mltProducer) {
904 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
908 int height = 1080;//KdenliveSettings::defaultheight();
909 int width = 1940; //KdenliveSettings::displaywidth();
910 QPixmap pix = KThumb::getFrame(m_mltProducer, -1, width, height);
912 QPixmap pix(width, height);
913 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
914 m_convert.set("forced", mlt_image_rgb24a);
915 m_mltProducer->attach(m_convert);
916 Mlt::Frame * frame = m_mltProducer->get_frame();
917 m_mltProducer->detach(m_convert);
919 pix = frameThumbnail(frame, width, height);
922 pix.save(url.path(), "PNG");
923 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
926 /** MLT PLAYLIST DIRECT MANIPULATON **/
929 void Render::mltCheckLength(bool reload) {
930 //kDebug()<<"checking track length: "<<track<<"..........";
932 Mlt::Service service(m_mltProducer->get_service());
933 Mlt::Tractor tractor(service);
935 int trackNb = tractor.count();
937 double trackDuration;
939 Mlt::Producer trackProducer(tractor.track(0));
940 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
941 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
942 m_mltProducer->set("out", duration);
943 emit durationChanged((int) duration);
946 while (trackNb > 1) {
947 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
948 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
949 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
951 kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
952 if (trackDuration > duration) duration = trackDuration;
956 Mlt::Producer blackTrackProducer(tractor.track(0));
957 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
958 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
959 kDebug() << " / / /DURATON FOR TRACK 0 = " << blackDuration;
960 if (blackDuration != duration) {
961 blackTrackPlaylist.remove_region(0, (int)blackDuration);
963 int dur = (int)duration;
965 QDomElement black = doc.createElement("producer");
966 black.setAttribute("mlt_service", "colour");
967 black.setAttribute("colour", "black");
968 black.setAttribute("in", "0");
969 black.setAttribute("out", "13999");
970 while (dur > 14000) { // <producer mlt_service=\"colour\" colour=\"black\" in=\"0\" out=\"13999\" />
971 mltInsertClip(0, GenTime(i * 14000, m_fps), black);
975 black.setAttribute("out", QString::number(dur));
976 mltInsertClip(0, GenTime(), black);
978 m_mltProducer->set("out", duration);
979 emit durationChanged((int)duration);
983 void Render::mltInsertClip(int track, GenTime position, QDomElement element) {
984 if (!m_mltProducer) {
985 kDebug() << "PLAYLIST NOT INITIALISED //////";
988 Mlt::Producer parentProd(m_mltProducer->parent());
989 if (parentProd.get_producer() == NULL) {
990 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
993 Mlt::Service service(parentProd.get_service());
994 Mlt::Tractor tractor(service);
996 Mlt::Producer trackProducer(tractor.track(track));
997 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1000 doc.appendChild(doc.importNode(element, true));
1001 QString resource = doc.toString();
1002 char *tmp = decodedString(resource);
1003 Mlt::Producer clip(*m_mltProfile, "westley-xml", tmp);
1004 //clip.set_in_and_out(in.frames(m_fps), out.frames(m_fps));
1007 trackPlaylist.insert_at((int) position.frames(m_fps), clip, 1);
1008 if (track != 0) mltCheckLength();
1009 tractor.multitrack()->refresh();
1013 void Render::mltCutClip(int track, GenTime position) {
1016 Mlt::Service service(m_mltProducer->parent().get_service());
1017 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1019 Mlt::Tractor tractor(service);
1020 Mlt::Producer trackProducer(tractor.track(track));
1021 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1022 trackPlaylist.split_at((int) position.frames(m_fps));
1023 trackPlaylist.consolidate_blanks(0);
1024 m_isBlocked = false;
1027 void Render::mltUpdateClip(int track, GenTime position, QDomElement element) {
1029 mltRemoveClip(track, position);
1030 mltInsertClip(track, position, element);
1034 void Render::mltRemoveClip(int track, GenTime position) {
1037 Mlt::Service service(m_mltProducer->parent().get_service());
1038 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1040 Mlt::Tractor tractor(service);
1041 Mlt::Producer trackProducer(tractor.track(track));
1042 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1043 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1044 trackPlaylist.replace_with_blank(clipIndex);
1045 trackPlaylist.consolidate_blanks(0);
1046 if (track != 0) mltCheckLength();
1047 //emit durationChanged();
1048 m_isBlocked = false;
1051 void Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1053 Mlt::Service service(m_mltProducer->parent().get_service());
1055 Mlt::Tractor tractor(service);
1056 Mlt::Producer trackProducer(tractor.track(track));
1057 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1058 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1059 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1061 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1064 Mlt::Service clipService(clip->get_service());
1065 // if (tag.startsWith("ladspa")) tag = "ladspa";
1068 Mlt::Filter *filter = clipService.filter(ct);
1070 if (index == "-1" || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1071 clipService.detach(*filter);
1072 kDebug() << " / / / DLEETED EFFECT: " << ct;
1074 filter = clipService.filter(ct);
1076 m_isBlocked = false;
1077 if (doRefresh) refresh();
1081 void Render::mltAddEffect(int track, GenTime position, QMap <QString, QString> args, bool doRefresh) {
1083 Mlt::Service service(m_mltProducer->parent().get_service());
1085 Mlt::Tractor tractor(service);
1086 Mlt::Producer trackProducer(tractor.track(track));
1087 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1089 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1092 kDebug() << "********** CANNOT FIND CLIP TO APPLY EFFECT-----------";
1095 Mlt::Service clipService(clip->get_service());
1098 QString tag = args.value("tag");
1099 //kDebug()<<" / / INSERTING EFFECT: "<<id;
1100 if (tag.startsWith("ladspa")) tag = "ladspa";
1101 char *filterId = decodedString(tag);
1102 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterId);
1103 if (filter && filter->is_valid())
1104 filter->set("kdenlive_id", filterId);
1106 kDebug() << "filter is NULL";
1107 m_isBlocked = false;
1111 QMap<QString, QString>::Iterator it;
1112 QString keyFrameNumber = "#0";
1114 for (it = args.begin(); it != args.end(); ++it) {
1115 //kDebug()<<" / / INSERTING EFFECT ARGS: "<<it.key()<<": "<<it.data();
1117 QString currentKeyFrameNumber;
1118 if (it.key().startsWith("#")) {
1119 currentKeyFrameNumber = it.key().section(":", 0, 0);
1120 if (currentKeyFrameNumber != keyFrameNumber) {
1121 // attach filter to the clip
1122 clipService.attach(*filter);
1123 filter = new Mlt::Filter(*m_mltProfile, filterId);
1124 filter->set("kdenlive_id", filterId);
1125 keyFrameNumber = currentKeyFrameNumber;
1127 key = it.key().section(":", 1);
1128 } else key = it.key();
1129 char *name = decodedString(key);
1130 char *value = decodedString(it.value());
1131 filter->set(name, value);
1135 // attach filter to the clip
1136 clipService.attach(*filter);
1138 m_isBlocked = false;
1139 if (doRefresh) refresh();
1142 void Render::mltEditEffect(int track, GenTime position, QMap <QString, QString> args) {
1143 QString index = args.value("kdenlive_ix");
1144 QString tag = args.value("tag");
1145 QMap<QString, QString>::Iterator it = args.begin();
1146 if (it.key().startsWith("#") || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1147 // This is a keyframe effect, to edit it, we remove it and re-add it.
1148 mltRemoveEffect(track, position, index);
1149 mltAddEffect(track, position, args);
1154 Mlt::Service service(m_mltProducer->parent().get_service());
1156 Mlt::Tractor tractor(service);
1157 Mlt::Producer trackProducer(tractor.track(track));
1158 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1159 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1160 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1162 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1165 Mlt::Service clipService(clip->get_service());
1168 Mlt::Filter *filter = clipService.filter(ct);
1170 if (filter->get("kdenlive_ix") == index) {
1174 filter = clipService.filter(ct);
1179 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1180 mltAddEffect(track, position, args);
1181 m_isBlocked = false;
1185 for (it = args.begin(); it != args.end(); ++it) {
1186 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1187 char *name = decodedString(it.key());
1188 char *value = decodedString(it.value());
1189 filter->set(name, value);
1193 m_isBlocked = false;
1197 void Render::mltResizeClipEnd(int track, GenTime pos, GenTime in, GenTime out) {
1200 Mlt::Service service(m_mltProducer->parent().get_service());
1202 Mlt::Tractor tractor(service);
1203 Mlt::Producer trackProducer(tractor.track(track));
1204 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1205 if (trackPlaylist.is_blank_at((int) pos.frames(m_fps) + 1))
1206 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1207 int clipIndex = trackPlaylist.get_clip_index_at((int) pos.frames(m_fps) + 1);
1209 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1210 int newDuration = (int) out.frames(m_fps) - 1;
1212 kDebug() << " ** RESIZING CLIP END:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", in: " << in.frames(25) << ", out: " << out.frames(25) << ", PREVIOUS duration: " << previousDuration;
1213 trackPlaylist.resize_clip(clipIndex, (int) in.frames(m_fps), newDuration);
1214 trackPlaylist.consolidate_blanks(0);
1215 if (previousDuration < newDuration) {
1216 // clip was made longer, trim next blank if there is one.
1217 if (trackPlaylist.is_blank(clipIndex + 1)) {
1218 trackPlaylist.split(clipIndex + 1, newDuration - previousDuration);
1219 trackPlaylist.remove(clipIndex + 1);
1221 } else trackPlaylist.insert_blank(clipIndex + 1, previousDuration - newDuration - 1);
1223 trackPlaylist.consolidate_blanks(0);
1224 tractor.multitrack()->refresh();
1226 if (track != 0) mltCheckLength();
1227 m_isBlocked = false;
1230 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1231 Mlt::Service service(m_mltProducer->parent().get_service());
1232 Mlt::Tractor tractor(service);
1233 Mlt::Producer trackProducer(tractor.track(track));
1234 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1236 if (blind) trackProducer.set("hide", 3);
1237 else trackProducer.set("hide", 2);
1239 trackProducer.set("hide", 1);
1241 trackProducer.set("hide", 0);
1243 tractor.multitrack()->refresh();
1248 void Render::mltResizeClipStart(int track, GenTime pos, GenTime moveEnd, GenTime moveStart, GenTime in, GenTime out) {
1251 Mlt::Service service(m_mltProducer->parent().get_service());
1253 int moveFrame = (int)(moveEnd - moveStart).frames(m_fps);
1255 Mlt::Tractor tractor(service);
1256 Mlt::Producer trackProducer(tractor.track(track));
1257 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1258 if (trackPlaylist.is_blank_at((int) pos.frames(m_fps) - 1))
1259 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1260 int clipIndex = trackPlaylist.get_clip_index_at((int) pos.frames(m_fps) - 1);
1261 kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1263 trackPlaylist.resize_clip(clipIndex, (int) in.frames(m_fps), (int) out.frames(m_fps));
1264 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1266 int midpos = (int)moveStart.frames(m_fps) - 1; //+ (moveFrame / 2)
1267 int blankIndex = trackPlaylist.get_clip_index_at(midpos);
1268 int blankLength = trackPlaylist.clip_length(blankIndex);
1270 kDebug() << " + resizing blank: " << blankIndex << ", Mid: " << midpos << ", Length: " << blankLength << ", SIZE DIFF: " << moveFrame;
1272 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1273 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1275 trackPlaylist.consolidate_blanks(0);
1276 m_isBlocked = false;
1279 void Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1280 mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1284 void Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1287 m_mltConsumer->set("refresh", 0);
1289 Mlt::Service service(m_mltProducer->parent().get_service());
1290 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1292 Mlt::Tractor tractor(service);
1293 Mlt::Producer trackProducer(tractor.track(startTrack));
1294 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1295 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1297 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1298 trackPlaylist.consolidate_blanks(0);
1299 //mlt_events_block( MLT_PRODUCER_PROPERTIES(clipProducer.get_producer()), NULL );
1301 if (endTrack == startTrack) {
1302 if (!trackPlaylist.is_blank_at(moveEnd)) {
1303 kWarning() << "// ERROR, CLIP COLLISION----------";
1304 int ix = trackPlaylist.get_clip_index_at(moveEnd);
1305 kDebug() << "BAD CLIP STARTS AT: " << trackPlaylist.clip_start(ix) << ", LENGT: " << trackPlaylist.clip_length(ix);
1307 trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1308 trackPlaylist.consolidate_blanks(0);
1310 trackPlaylist.consolidate_blanks(0);
1311 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1312 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1313 destTrackPlaylist.consolidate_blanks(1);
1314 destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1315 destTrackPlaylist.consolidate_blanks(0);
1319 m_isBlocked = false;
1320 m_mltConsumer->set("refresh", 1);
1321 //mlt_events_unblock( MLT_PRODUCER_PROPERTIES(clipProducer.get_producer()), NULL );
1324 void Render::mltMoveTransition(QString type, int startTrack, int trackOffset, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1326 Mlt::Service service(m_mltProducer->parent().get_service());
1327 Mlt::Tractor tractor(service);
1328 Mlt::Field *field = tractor.field();
1330 m_mltConsumer->set("refresh", 0);
1331 mlt_service serv = m_mltProducer->parent().get_service();
1333 mlt_service nextservice = mlt_service_get_producer(serv);
1334 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1335 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1336 QString resource = mlt_properties_get(properties, "mlt_service");
1337 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1339 int new_in = (int)newIn.frames(m_fps);
1340 int new_out = (int)newOut.frames(m_fps) - 1;
1342 while (mlt_type == "transition") {
1343 mlt_transition tr = (mlt_transition) nextservice;
1344 int currentTrack = mlt_transition_get_b_track(tr);
1345 int currentIn = (int) mlt_transition_get_in(tr);
1346 int currentOut = (int) mlt_transition_get_out(tr);
1348 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1349 mlt_transition_set_in_and_out(tr, new_in, new_out);
1350 if (trackOffset != 0) {
1351 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1352 mlt_properties_set_int(properties, "a_track", mlt_transition_get_a_track(tr) + trackOffset);
1353 mlt_properties_set_int(properties, "b_track", mlt_transition_get_b_track(tr) + trackOffset);
1354 //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);
1359 nextservice = mlt_service_producer(nextservice);
1360 properties = MLT_SERVICE_PROPERTIES(nextservice);
1361 mlt_type = mlt_properties_get(properties, "mlt_type");
1362 resource = mlt_properties_get(properties, "mlt_service");
1364 m_isBlocked = false;
1365 m_mltConsumer->set("refresh", 1);
1368 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1369 //kDebug() << "update transition" << tag;
1370 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
1372 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
1373 mltAddTransition(tag, a_track, b_track, in, out, xml);
1378 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1381 Mlt::Service service(m_mltProducer->parent().get_service());
1382 Mlt::Tractor tractor(service);
1383 Mlt::Field *field = tractor.field();
1385 m_mltConsumer->set("refresh", 0);
1386 mlt_service serv = m_mltProducer->parent().get_service();
1388 mlt_service nextservice = mlt_service_get_producer(serv);
1389 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1390 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1391 QString resource = mlt_properties_get(properties, "mlt_service");
1392 int in_pos = (int) in.frames(m_fps);
1393 int out_pos = (int) out.frames(m_fps);
1395 while (mlt_type == "transition") {
1396 mlt_transition tr = (mlt_transition) nextservice;
1397 int currentTrack = mlt_transition_get_b_track(tr);
1398 int currentIn = (int) mlt_transition_get_in(tr);
1399 int currentOut = (int) mlt_transition_get_out(tr);
1401 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
1402 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
1403 QMap<QString, QString>::Iterator it;
1405 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
1407 for (it = map.begin(); it != map.end(); ++it) {
1409 char *name = decodedString(key);
1410 char *value = decodedString(it.value());
1411 mlt_properties_set(transproperties, name, value);
1412 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
1413 //filter->set("kdenlive_id", id);
1419 nextservice = mlt_service_producer(nextservice);
1420 properties = MLT_SERVICE_PROPERTIES(nextservice);
1421 mlt_type = mlt_properties_get(properties, "mlt_type");
1422 resource = mlt_properties_get(properties, "mlt_service");
1424 m_isBlocked = false;
1425 m_mltConsumer->set("refresh", 1);
1428 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
1430 Mlt::Service service(m_mltProducer->parent().get_service());
1431 Mlt::Tractor tractor(service);
1432 Mlt::Field *field = tractor.field();
1434 m_mltConsumer->set("refresh", 0);
1435 mlt_service serv = m_mltProducer->parent().get_service();
1437 mlt_service nextservice = mlt_service_get_producer(serv);
1438 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1439 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1440 QString resource = mlt_properties_get(properties, "mlt_service");
1441 int old_pos = (int)((in + out).frames(m_fps) / 2);
1443 while (mlt_type == "transition") {
1444 mlt_transition tr = (mlt_transition) nextservice;
1445 int currentTrack = mlt_transition_get_b_track(tr);
1446 int currentIn = (int) mlt_transition_get_in(tr);
1447 int currentOut = (int) mlt_transition_get_out(tr);
1448 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
1450 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1451 mlt_field_disconnect_service(field->get_field(), nextservice);
1454 nextservice = mlt_service_producer(nextservice);
1455 properties = MLT_SERVICE_PROPERTIES(nextservice);
1456 mlt_type = mlt_properties_get(properties, "mlt_type");
1457 resource = mlt_properties_get(properties, "mlt_service");
1459 m_mltConsumer->set("refresh", 1);
1462 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
1463 QDomNodeList attribs = xml.elementsByTagName("parameter");
1464 QMap<QString, QString> map;
1465 for (int i = 0;i < attribs.count();i++) {
1466 QDomElement e = attribs.item(i).toElement();
1467 QString name = e.attribute("name");
1468 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
1469 map[name] = e.attribute("default");
1470 if (!e.attribute("value").isEmpty()) {
1471 map[name] = e.attribute("value");
1473 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
1474 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
1475 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
1478 if (e.attribute("namedesc").contains(";")) {
1479 QString format = e.attribute("format");
1480 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1481 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1483 QTextStream txtNeu(&neu);
1484 if (values.size() > 0)
1485 txtNeu << (int)values[0].toDouble();
1487 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
1488 txtNeu << separators[i];
1489 txtNeu << (int)(values[i+1].toDouble());
1491 if (i < separators.size())
1492 txtNeu << separators[i];
1493 map[e.attribute("name")] = neu;
1500 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
1501 //kDebug() << "-- ADDING TRANSITION: " << tag << ", ON TRACKS: " << a_track << ", " << b_track;
1502 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
1505 Mlt::Service service(m_mltProducer->parent().get_service());
1507 Mlt::Tractor tractor(service);
1508 Mlt::Field *field = tractor.field();
1510 char *transId = decodedString(tag);
1511 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
1512 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
1513 QMap<QString, QString>::Iterator it;
1516 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
1518 for (it = args.begin(); it != args.end(); ++it) {
1520 char *name = decodedString(key);
1521 char *value = decodedString(it.value());
1522 transition->set(name, value);
1523 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
1524 //filter->set("kdenlive_id", id);
1528 // attach filter to the clip
1529 field->plant_transition(*transition, a_track, b_track);
1534 void Render::mltSavePlaylist() {
1535 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
1536 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
1537 fileConsumer.set("resource", "/tmp/playlist.westley");
1539 Mlt::Service service(m_mltProducer->get_service());
1541 fileConsumer.connect(service);
1542 fileConsumer.start();
1546 #include "renderer.moc"