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
28 //#include <libavformat/avformat.h>
32 #include <QApplication>
36 #include <KStandardDirs>
37 #include <KMessageBox>
39 #include <KTemporaryFile>
42 #include "kdenlivesettings.h"
45 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
46 // detect if the producer has finished playing. Is there a better way to do it ?
47 //if (self->isBlocked) return;
48 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
49 self->emitConsumerStopped();
51 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
55 Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(-1), m_framePosition(0), m_generateScenelist(false), m_isBlocked(true) {
56 kDebug() << "////////// USING PROFILE: " << (char *)KdenliveSettings::current_profile().toUtf8().data();
57 m_mltProfile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
58 refreshTimer = new QTimer(this);
59 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
61 m_connectTimer = new QTimer(this);
62 connect(m_connectTimer, SIGNAL(timeout()), this, SLOT(connectPlaylist()));
64 if (rendererName == "project") m_monitorId = 10000;
65 else m_monitorId = 10001;
66 osdTimer = new QTimer(this);
67 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
69 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
70 //if (rendererName == "clip")
72 //Mlt::Consumer *consumer = new Mlt::Consumer( profile , "sdl_preview");
73 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
74 m_mltConsumer->set("resize", 1);
75 m_mltConsumer->set("window_id", winid);
76 m_mltConsumer->set("terminate_on_pause", 1);
77 m_externalwinid = extid;
79 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
80 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", "<westley><playlist><producer mlt_service=\"colour\" colour=\"blue\" in=\"0\" out=\"25\" /></playlist></westley>");
81 m_mltProducer = producer;
82 m_mltConsumer->connect(*m_mltProducer);
83 m_mltProducer->set_speed(0.0);
84 //m_mltConsumer->start();
88 /*m_osdInfo = new Mlt::Filter("data_show");
89 char *tmp = decodedString(m_osdProfile);
90 m_osdInfo->set("resource", tmp);
92 // Does it do anything usefull? I mean, RenderThread doesn't do anything useful at the moment
93 // (except being cpu hungry :)
95 /* if(!s_renderThread) {
96 s_renderThread = new RenderThread;
97 s_renderThread->start();
106 void Render::closeMlt() {
107 delete m_connectTimer;
111 delete m_mltConsumer;
113 delete m_mltProducer;
119 int Render::resetProfile(QString profile) {
120 if (!m_mltConsumer) return 0;
121 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
122 m_mltConsumer->set("refresh", 0);
123 m_mltConsumer->purge();
124 delete m_mltConsumer;
125 m_mltConsumer = NULL;
126 QString scene = sceneList();
127 if (m_mltProducer) delete m_mltProducer;
128 m_mltProducer = NULL;
129 if (m_mltProfile) delete m_mltProfile;
132 m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
133 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
134 m_mltConsumer->set("resize", 1);
135 m_mltConsumer->set("window_id", m_winid);
136 m_mltConsumer->set("terminate_on_pause", 1);
137 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
139 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", (char *) scene.toUtf8().data());
140 m_mltProducer = producer;
141 m_mltConsumer->connect(*m_mltProducer);
142 m_mltProducer->set_speed(0.0);
144 //delete m_mltProfile;
145 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
146 //mlt_profile prof = m_mltProfile->get_profile();
147 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
148 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
149 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
150 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
151 kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << profile << ", WIDTH: " << m_mltProfile->width();
153 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
158 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
159 void Render::seek(GenTime time) {
160 sendSeekCommand(time);
161 //emit positionChanged(time);
165 char *Render::decodedString(QString str) {
166 /*QCString fn = QFile::encodeName(str);
167 char *t = new char[fn.length() + 1];
168 strcpy(t, (const char *)fn);*/
170 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
174 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
175 QPixmap pix(width, height);
177 mlt_image_format format = mlt_image_rgb24a;
178 uint8_t *thumb = frame->get_image(format, width, height);
179 QImage image(thumb, width, height, QImage::Format_ARGB32);
181 if (!image.isNull()) {
182 pix = pix.fromImage(image);
184 QPainter painter(&pix);
185 painter.drawRect(0, 0, width - 1, height - 1);
187 } else pix.fill(Qt::black);
192 QPixmap Render::extractFrame(int frame_position, int width, int height) {
193 QPixmap pix(width, height);
194 if (!m_mltProducer) {
198 Mlt::Producer *mlt_producer = m_mltProducer->cut(frame_position, frame_position + 1);
199 return KThumb::getFrame(m_mltProducer, -1, width, height);
200 /*Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
201 m_convert.set("forced", mlt_image_rgb24a);
202 mlt_producer->attach(m_convert);
203 Mlt::Frame *frame = mlt_producer->get_frame();
206 pix = frameThumbnail(frame, width, height);
208 } else pix.fill(Qt::black);
213 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
216 if (url.fileName().startsWith(".all.")) { // check for slideshow
217 QString fileType = url.fileName().right(3);
219 QStringList::Iterator it;
221 QDir dir(url.directory());
222 more = dir.entryList(QDir::Files);
224 for (it = more.begin() ; it != more.end() ; ++it) {
225 if ((*it).endsWith("." + fileType, Qt::CaseInsensitive)) {
226 im.load(url.directory() + "/" + *it);
230 } else im.load(url.path());
231 //pixmap = im.scaled(width, height);
236 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
237 QPixmap pix(width, height);
238 char *tmp = decodedString(file);
239 Mlt::Profile *prof = new Mlt::Profile(profile);
240 Mlt::Producer m_producer(*prof, tmp);
242 if (m_producer.is_blank()) {
247 Mlt::Filter m_convert(*prof, "avcolour_space");
248 m_convert.set("forced", mlt_image_rgb24a);
249 m_producer.attach(m_convert);
250 m_producer.seek(frame_position);
251 Mlt::Frame * frame = m_producer.get_frame();
253 pix = frameThumbnail(frame, width, height, true);
256 if (prof) delete prof;
261 void Render::getImage(KUrl url, int frame_position, QPoint size)
263 char *tmp = decodedString(url.path());
264 Mlt::Producer m_producer(tmp);
266 if (m_producer.is_blank()) {
269 Mlt::Filter m_convert("avcolour_space");
270 m_convert.set("forced", mlt_image_rgb24a);
271 m_producer.attach(m_convert);
272 m_producer.seek(frame_position);
274 Mlt::Frame * frame = m_producer.get_frame();
277 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
279 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
283 /* Create thumbnail for color */
284 /*void Render::getImage(int id, QString color, QPoint size)
286 QPixmap pixmap(size.x() - 2, size.y() - 2);
287 color = color.replace(0, 2, "#");
288 color = color.left(7);
289 pixmap.fill(QColor(color));
290 QPixmap result(size.x(), size.y());
291 result.fill(Qt::black);
292 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
293 emit replyGetImage(id, result, size.x(), size.y());
297 /* Create thumbnail for image */
298 /*void Render::getImage(KUrl url, QPoint size)
302 if (url.fileName().startsWith(".all.")) { // check for slideshow
303 QString fileType = url.fileName().right(3);
305 QStringList::Iterator it;
307 QDir dir( url.directory() );
308 more = dir.entryList( QDir::Files );
309 for ( it = more.begin() ; it != more.end() ; ++it ) {
310 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
311 if (!im.load(url.directory() + "/" + *it))
312 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
317 else im.load(url.path());
319 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
320 QPixmap result(size.x(), size.y());
321 result.fill(Qt::black);
322 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
323 emit replyGetImage(url, 1, result, size.x(), size.y());
327 double Render::consumerRatio() const {
328 if (!m_mltConsumer) return 1.0;
329 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
333 int Render::getLength() {
336 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
337 return mlt_producer_get_playtime(m_mltProducer->get_producer());
342 bool Render::isValid(KUrl url) {
343 char *tmp = decodedString(url.path());
344 Mlt::Producer producer(*m_mltProfile, tmp);
346 if (producer.is_blank())
352 void Render::getFileProperties(const QDomElement &xml, int clipId) {
354 int width = height * 16 / 9.0; //KdenliveSettings::displayratio();
356 QDomElement westley = doc.createElement("westley");
357 doc.appendChild(westley);
358 westley.appendChild(doc.importNode(xml, true));
359 kDebug() << "////////////\n" << doc.toString() << "////////////////\n";
360 char *tmp = decodedString(doc.toString());
362 Mlt::Producer producer(*m_mltProfile, "westley-xml", tmp);
365 if (producer.is_blank()) {
368 int frameNumber = xml.attribute("frame_thumbnail", 0).toInt();
369 if (frameNumber != 0) producer.seek(frameNumber);
370 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer.get_producer());
372 QMap < QString, QString > filePropertyMap;
373 QMap < QString, QString > metadataPropertyMap;
375 KUrl url = xml.attribute("resource", QString::null);
376 filePropertyMap["filename"] = url.path();
377 filePropertyMap["duration"] = QString::number(producer.get_playtime());
378 kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
379 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
380 m_convert.set("forced", mlt_image_rgb24a);
381 producer.attach(m_convert);
382 Mlt::Frame * frame = producer.get_frame();
384 filePropertyMap["fps"] =
385 QString::number(mlt_producer_get_fps(producer.get_producer()));
387 if (frame && frame->is_valid()) {
388 filePropertyMap["width"] =
389 QString::number(frame->get_int("width"));
390 filePropertyMap["height"] =
391 QString::number(frame->get_int("height"));
392 filePropertyMap["frequency"] =
393 QString::number(frame->get_int("frequency"));
394 filePropertyMap["channels"] =
395 QString::number(frame->get_int("channels"));
397 if (frame->get_int("test_image") == 0) {
398 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
399 filePropertyMap["type"] = "playlist";
400 metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer.get_service()), "title"));
401 } else if (frame->get_int("test_audio") == 0)
402 filePropertyMap["type"] = "av";
404 filePropertyMap["type"] = "video";
406 // Generate thumbnail for this frame
407 QPixmap pixmap = KThumb::getImage(url, 0, width, height);
409 emit replyGetImage(clipId, 0, pixmap, width, height);
411 } else if (frame->get_int("test_audio") == 0) {
412 QPixmap pixmap(KStandardDirs::locate("appdata", "graphics/music.png"));
413 emit replyGetImage(clipId, 0, pixmap, width, height);
414 filePropertyMap["type"] = "audio";
418 // Retrieve audio / video codec name
420 // Fetch the video_context
421 #if 0 //until the reason for the chrashs is found
422 AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
423 if (context != NULL) {
424 // Get the video_index
425 int index = mlt_properties_get_int(properties, "video_index");
426 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
427 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
429 context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
430 if (context != NULL) {
431 // Get the video_index
432 int index = mlt_properties_get_int(properties, "audio_index");
433 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
434 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
441 mlt_properties metadata = mlt_properties_new();
442 mlt_properties_pass(metadata, properties, "meta.attr.");
443 int count = mlt_properties_count(metadata);
444 for (int i = 0; i < count; i ++) {
445 QString name = mlt_properties_get_name(metadata, i);
446 QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
447 if (name.endsWith("markup") && !value.isEmpty())
448 metadataPropertyMap[ name.section(".", 0, -2)] = value;
451 emit replyGetFileProperties(clipId, filePropertyMap, metadataPropertyMap);
452 kDebug() << "REquested fuile info for: " << url.path();
453 if (frame) delete frame;
456 /** Create the producer from the Westley QDomDocument */
457 void Render::initSceneList() {
458 kDebug() << "-------- INIT SCENE LIST ------_";
460 QDomElement westley = doc.createElement("westley");
461 doc.appendChild(westley);
462 QDomElement prod = doc.createElement("producer");
463 prod.setAttribute("resource", "colour");
464 prod.setAttribute("colour", "red");
465 prod.setAttribute("id", "black");
466 prod.setAttribute("in", "0");
467 prod.setAttribute("out", "0");
469 QDomElement tractor = doc.createElement("tractor");
470 QDomElement multitrack = doc.createElement("multitrack");
472 QDomElement playlist1 = doc.createElement("playlist");
473 playlist1.appendChild(prod);
474 multitrack.appendChild(playlist1);
475 QDomElement playlist2 = doc.createElement("playlist");
476 multitrack.appendChild(playlist2);
477 QDomElement playlist3 = doc.createElement("playlist");
478 multitrack.appendChild(playlist3);
479 QDomElement playlist4 = doc.createElement("playlist");
480 multitrack.appendChild(playlist4);
481 QDomElement playlist5 = doc.createElement("playlist");
482 multitrack.appendChild(playlist5);
483 tractor.appendChild(multitrack);
484 westley.appendChild(tractor);
485 // kDebug()<<doc.toString();
487 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
488 setSceneList(doc, 0);
491 /** Create the producer from the Westley QDomDocument */
492 void Render::setSceneList(QDomDocument list, int position) {
493 setSceneList(list.toString(), position);
496 /** Create the producer from the Westley QDomDocument */
497 void Render::setSceneList(QString playlist, int position) {
498 if (m_winid == -1) return;
499 m_generateScenelist = true;
501 kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
505 if (!clip.is_valid()) {
506 kWarning()<<" ++++ WARNING, UNABLE TO CREATE MLT PRODUCER";
507 m_generateScenelist = false;
512 m_mltConsumer->set("refresh", 0);
515 m_mltProducer->set_speed(0.0);
516 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
518 delete m_mltProducer;
519 m_mltProducer = NULL;
523 char *tmp = decodedString(playlist);
524 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
526 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
527 //m_mltProducer->optimise();
528 if (position != 0) m_mltProducer->seek(position);
530 /*if (KdenliveSettings::osdtimecode()) {
531 // Attach filter for on screen display of timecode
533 QString attr = "attr_check";
534 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
535 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
536 mlt_producer_attach( m_mltProducer->get_producer(), filter );
537 mlt_filter_close( filter );
539 m_osdInfo = new Mlt::Filter("data_show");
540 tmp = decodedString(m_osdProfile);
541 m_osdInfo->set("resource", tmp);
543 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
544 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
545 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
546 m_osdInfo->set("dynamic", "1");
548 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
550 m_osdInfo->set("dynamic", "0");
553 m_fps = m_mltProducer->get_fps();
554 emit durationChanged(m_mltProducer->get_playtime());
555 //m_connectTimer->start( 1000 );
557 m_generateScenelist = false;
561 /** Create the producer from the Westley QDomDocument */
562 QString Render::sceneList() {
567 saveSceneList(temp.fileName());
568 QFile file(temp.fileName());
569 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
570 kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE";
573 QTextStream in(&file);
574 while (!in.atEnd()) {
575 result.append(in.readLine());
581 void Render::saveSceneList(QString path, QDomElement addedXml) {
582 char *tmppath = decodedString("westley:" + path);
583 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
585 westleyConsumer.set("terminate_on_pause", 1);
586 Mlt::Producer prod(m_mltProducer->get_producer());
587 westleyConsumer.connect(prod);
588 westleyConsumer.start();
589 if (!addedXml.isNull()) {
590 // add Kdenlive specific tags
593 doc.setContent(&file, false);
594 doc.documentElement().appendChild(doc.importNode(addedXml, true));
596 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
597 kWarning() << "////// ERROR writing to file: " << path;
600 QTextStream out(&file);
601 out << doc.toString();
607 const double Render::fps() const {
611 void Render::connectPlaylist() {
612 if (!m_mltConsumer) return;
613 m_connectTimer->stop();
614 m_mltConsumer->set("refresh", "0");
615 m_mltConsumer->connect(*m_mltProducer);
616 m_mltProducer->set_speed(0.0);
617 m_mltConsumer->start();
620 if (m_mltConsumer->start() == -1) {
621 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."));
622 m_mltConsumer = NULL;
629 void Render::refreshDisplay() {
631 if (!m_mltProducer) return;
632 m_mltConsumer->set("refresh", 0);
634 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
635 /*if (KdenliveSettings::osdtimecode()) {
636 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
637 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
638 m_osdInfo->set("dynamic", "1");
639 m_mltProducer->attach(*m_osdInfo);
642 m_mltProducer->detach(*m_osdInfo);
643 m_osdInfo->set("dynamic", "0");
648 void Render::setVolume(double volume) {
649 if (!m_mltConsumer || !m_mltProducer) return;
651 m_mltConsumer->set("refresh", 0);
652 // Attach filter for on screen display of timecode
653 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
654 mlt_properties_set_double( properties, "meta.volume", volume );
655 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
656 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
658 if (!KdenliveSettings::osdtimecode()) {
659 m_mltProducer->detach(*m_osdInfo);
660 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
661 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
664 osdTimer->setSingleShot(2500);
667 void Render::slotOsdTimeout() {
668 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
669 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
670 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
671 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
675 void Render::start() {
676 kDebug() << "----- STARTING MONITOR: " << m_name;
678 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
682 if (m_mltConsumer->is_stopped()) {
683 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
684 if (m_mltConsumer->start() == -1) {
685 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."));
686 m_mltConsumer = NULL;
689 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
696 void Render::clear() {
698 m_mltConsumer->set("refresh", 0);
699 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
703 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
704 m_mltProducer->set_speed(0.0);
705 delete m_mltProducer;
706 m_mltProducer = NULL;
711 void Render::stop() {
712 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
713 kDebug() << "///////////// RENDER STOPPED: " << m_name;
714 m_mltConsumer->set("refresh", 0);
715 m_mltConsumer->stop();
717 kDebug() << "///////////// RENDER STOP2-------";
721 m_mltProducer->set_speed(0.0);
722 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
724 kDebug() << "///////////// RENDER STOP3-------";
727 void Render::stop(const GenTime & startTime) {
728 kDebug() << "///////////// RENDER STOP-------2";
730 m_mltProducer->set_speed(0.0);
731 m_mltProducer->seek((int) startTime.frames(m_fps));
733 m_mltConsumer->purge();
736 void Render::switchPlay() {
739 if (m_mltProducer->get_speed() == 0.0) m_mltProducer->set_speed(1.0);
741 m_mltProducer->set_speed(0.0);
742 kDebug() << "// POSITON: " << m_framePosition;
743 m_mltProducer->seek((int) m_framePosition);
746 /*if (speed == 0.0) {
747 m_mltProducer->seek((int) m_framePosition + 1);
748 m_mltConsumer->purge();
753 void Render::play(double speed) {
756 if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
757 m_mltProducer->set_speed(speed);
758 /*if (speed == 0.0) {
759 m_mltProducer->seek((int) m_framePosition + 1);
760 m_mltConsumer->purge();
765 void Render::play(double speed, const GenTime & startTime) {
766 kDebug() << "///////////// RENDER PLAY2-------" << speed;
769 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
770 //if (speed == 0.0) m_mltConsumer->set("refresh", 0);
771 m_mltProducer->set_speed(speed);
772 m_mltProducer->seek((int)(startTime.frames(m_fps)));
773 //m_mltConsumer->purge();
777 void Render::play(double speed, const GenTime & startTime,
778 const GenTime & stopTime) {
779 kDebug() << "///////////// RENDER PLAY3-------" << speed;
782 m_mltProducer->set("out", stopTime.frames(m_fps));
783 m_mltProducer->seek((int)(startTime.frames(m_fps)));
784 m_mltConsumer->purge();
785 m_mltProducer->set_speed(speed);
790 void Render::sendSeekCommand(GenTime time) {
793 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
794 m_mltProducer->seek((int)(time.frames(m_fps)));
798 void Render::seekToFrame(int pos) {
801 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
802 m_mltProducer->seek(pos);
806 void Render::askForRefresh() {
807 // Use a Timer so that we don't refresh too much
808 refreshTimer->start(200);
811 void Render::doRefresh() {
812 // Use a Timer so that we don't refresh too much
816 void Render::refresh() {
817 if (!m_mltProducer || m_isBlocked)
819 refreshTimer->stop();
821 m_mltConsumer->set("refresh", 1);
825 /** Sets the description of this renderer to desc. */
826 void Render::setDescription(const QString & description) {
827 m_description = description;
830 /** Returns the description of this renderer */
831 QString Render::description() {
832 return m_description;
836 double Render::playSpeed() {
837 if (m_mltProducer) return m_mltProducer->get_speed();
841 const GenTime & Render::seekPosition() const {
842 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
843 else return GenTime();
847 const QString & Render::rendererName() const {
852 void Render::emitFrameNumber(double position) {
853 //kDebug()<<"// POSITON: "<<m_framePosition;
854 if (m_generateScenelist) return;
855 m_framePosition = position;
856 emit rendererPosition((int) position);
857 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
860 void Render::emitConsumerStopped() {
861 // This is used to know when the playing stopped
862 if (m_mltProducer && !m_generateScenelist) {
863 double pos = m_mltProducer->position();
864 emit rendererStopped((int) pos);
865 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
866 //new QCustomEvent(10002));
872 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
873 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
877 void Render::exportCurrentFrame(KUrl url, bool notify) {
878 if (!m_mltProducer) {
879 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
883 int height = 1080;//KdenliveSettings::defaultheight();
884 int width = 1940; //KdenliveSettings::displaywidth();
885 QPixmap pix = KThumb::getFrame(m_mltProducer, -1, width, height);
887 QPixmap pix(width, height);
888 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
889 m_convert.set("forced", mlt_image_rgb24a);
890 m_mltProducer->attach(m_convert);
891 Mlt::Frame * frame = m_mltProducer->get_frame();
892 m_mltProducer->detach(m_convert);
894 pix = frameThumbnail(frame, width, height);
897 pix.save(url.path(), "PNG");
898 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
901 /** MLT PLAYLIST DIRECT MANIPULATON **/
904 void Render::mltCheckLength() {
905 //kDebug()<<"checking track length: "<<track<<"..........";
906 Mlt::Service service(m_mltProducer->get_service());
907 Mlt::Tractor tractor(service);
909 int trackNb = tractor.count();
911 double trackDuration;
913 Mlt::Producer trackProducer(tractor.track(0));
914 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
915 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
916 m_mltProducer->set("out", duration);
917 emit durationChanged(duration);
920 while (trackNb > 1) {
921 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
922 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
923 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
925 kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
926 if (trackDuration > duration) duration = trackDuration;
930 Mlt::Producer blackTrackProducer(tractor.track(0));
931 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
932 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
933 kDebug() << " / / /DURATON FOR TRACK 0 = " << blackDuration;
934 if (blackDuration != duration) {
935 blackTrackPlaylist.remove_region(0, blackDuration);
939 QDomElement black = doc.createElement("producer");
940 black.setAttribute("mlt_service", "colour");
941 black.setAttribute("colour", "black");
942 black.setAttribute("in", "0");
943 black.setAttribute("out", "13999");
944 while (dur > 14000) { // <producer mlt_service=\"colour\" colour=\"black\" in=\"0\" out=\"13999\" />
945 mltInsertClip(0, GenTime(i * 14000, m_fps), black);
949 black.setAttribute("out", QString::number(dur));
950 mltInsertClip(0, GenTime(), black);
952 m_mltProducer->set("out", duration);
953 emit durationChanged(duration);
958 void Render::mltInsertClip(int track, GenTime position, QDomElement element) {
959 if (!m_mltProducer) {
960 kDebug() << "PLAYLIST NOT INITIALISED //////";
963 Mlt::Producer parentProd(m_mltProducer->parent());
964 if (parentProd.get_producer() == NULL) {
965 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
969 Mlt::Service service(parentProd.get_service());
970 Mlt::Tractor tractor(service);
973 doc.appendChild(doc.importNode(element, true));
974 QString resource = doc.toString();
975 kDebug() << "/////// ADDING CLIP TMLNE: " << resource << " ON TRACK: " << track;
976 Mlt::Producer trackProducer(tractor.track(track));
977 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
978 char *tmp = decodedString(resource);
979 Mlt::Producer clip(*m_mltProfile, "westley-xml", tmp);
980 //clip.set_in_and_out(in.frames(m_fps), out.frames(m_fps));
983 trackPlaylist.insert_at(position.frames(m_fps), clip, 1);
984 tractor.multitrack()->refresh();
986 if (track != 0) mltCheckLength();
990 void Render::mltCutClip(int track, GenTime position) {
992 Mlt::Service service(m_mltProducer->parent().get_service());
993 Mlt::Tractor tractor(service);
994 Mlt::Producer trackProducer(tractor.track(track));
995 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
996 trackPlaylist.split_at(position.frames(m_fps));
997 trackPlaylist.consolidate_blanks(0);
998 kDebug() << "/ / / /CUTTING CLIP AT: " << position.frames(m_fps);
1003 void Render::mltRemoveClip(int track, GenTime position) {
1005 Mlt::Service service(m_mltProducer->parent().get_service());
1006 Mlt::Tractor tractor(service);
1007 Mlt::Producer trackProducer(tractor.track(track));
1008 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1009 int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1010 //trackPlaylist.remove(clipIndex);
1011 trackPlaylist.replace_with_blank(clipIndex);
1012 trackPlaylist.consolidate_blanks(0);
1013 if (track != 0) mltCheckLength();
1014 //emit durationChanged();
1015 m_isBlocked = false;
1018 void Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1020 Mlt::Service service(m_mltProducer->parent().get_service());
1022 Mlt::Tractor tractor(service);
1023 Mlt::Producer trackProducer(tractor.track(track));
1024 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1025 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1026 Mlt::Producer *clip = trackPlaylist.get_clip_at(position.frames(m_fps));
1028 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1032 Mlt::Service clipService(clip->get_service());
1034 // if (tag.startsWith("ladspa")) tag = "ladspa";
1037 Mlt::Filter *filter = clipService.filter(ct);
1039 if (index == "-1" || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1040 clipService.detach(*filter);
1041 kDebug() << " / / / DLEETED EFFECT: " << ct;
1043 filter = clipService.filter(ct);
1045 m_isBlocked = false;
1046 if (doRefresh) refresh();
1050 void Render::mltAddEffect(int track, GenTime position, QMap <QString, QString> args, bool doRefresh) {
1051 Mlt::Service service(m_mltProducer->parent().get_service());
1052 Mlt::Tractor tractor(service);
1053 Mlt::Producer trackProducer(tractor.track(track));
1054 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1056 Mlt::Producer *clip = trackPlaylist.get_clip_at(position.frames(m_fps));
1059 kDebug() << "********** CANNOT FIND CLIP TO APPLY EFFECT-----------";
1062 Mlt::Service clipService(clip->get_service());
1065 QString tag = args.value("tag");
1066 //kDebug()<<" / / INSERTING EFFECT: "<<id;
1067 if (tag.startsWith("ladspa")) tag = "ladspa";
1068 char *filterId = decodedString(tag);
1069 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterId);
1070 if (filter && filter->is_valid())
1071 filter->set("kdenlive_id", filterId);
1073 kDebug() << "filter is NULL";
1077 QMap<QString, QString>::Iterator it;
1078 QString keyFrameNumber = "#0";
1080 for (it = args.begin(); it != args.end(); ++it) {
1081 //kDebug()<<" / / INSERTING EFFECT ARGS: "<<it.key()<<": "<<it.data();
1083 QString currentKeyFrameNumber;
1084 if (it.key().startsWith("#")) {
1085 currentKeyFrameNumber = it.key().section(":", 0, 0);
1086 if (currentKeyFrameNumber != keyFrameNumber) {
1087 // attach filter to the clip
1088 clipService.attach(*filter);
1089 filter = new Mlt::Filter(*m_mltProfile, filterId);
1090 filter->set("kdenlive_id", filterId);
1091 keyFrameNumber = currentKeyFrameNumber;
1093 key = it.key().section(":", 1);
1094 } else key = it.key();
1095 char *name = decodedString(key);
1096 char *value = decodedString(it.value());
1097 filter->set(name, value);
1101 // attach filter to the clip
1102 clipService.attach(*filter);
1104 m_isBlocked = false;
1105 if (doRefresh) refresh();
1109 void Render::mltEditEffect(int track, GenTime position, QMap <QString, QString> args) {
1110 QString index = args.value("kdenlive_ix");
1111 QString tag = args.value("tag");
1112 QMap<QString, QString>::Iterator it = args.begin();
1113 if (it.key().startsWith("#") || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1114 // This is a keyframe effect, to edit it, we remove it and re-add it.
1115 mltRemoveEffect(track, position, index);
1116 mltAddEffect(track, position, args);
1121 Mlt::Service service(m_mltProducer->parent().get_service());
1123 Mlt::Tractor tractor(service);
1124 Mlt::Producer trackProducer(tractor.track(track));
1125 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1126 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1127 Mlt::Producer *clip = trackPlaylist.get_clip_at(position.frames(m_fps));
1129 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1130 m_isBlocked = false;
1134 Mlt::Service clipService(clip->get_service());
1136 // if (tag.startsWith("ladspa")) tag = "ladspa";
1139 Mlt::Filter *filter = clipService.filter(ct);
1141 if (filter->get("kdenlive_ix") == index) {
1145 filter = clipService.filter(ct);
1150 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1151 mltAddEffect(track, position, args);
1152 m_isBlocked = false;
1156 for (it = args.begin(); it != args.end(); ++it) {
1157 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1158 char *name = decodedString(it.key());
1159 char *value = decodedString(it.value());
1160 filter->set(name, value);
1164 m_isBlocked = false;
1168 void Render::mltResizeClipEnd(int track, GenTime pos, GenTime in, GenTime out) {
1170 Mlt::Service service(m_mltProducer->parent().get_service());
1172 Mlt::Tractor tractor(service);
1173 Mlt::Producer trackProducer(tractor.track(track));
1174 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1175 if (trackPlaylist.is_blank_at(pos.frames(m_fps) + 1))
1176 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1177 int clipIndex = trackPlaylist.get_clip_index_at(pos.frames(m_fps) + 1);
1179 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1180 int newDuration = out.frames(m_fps) - 1;
1182 kDebug() << " ** RESIZING CLIP END:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", in: " << in.frames(25) << ", out: " << out.frames(25) << ", PREVIOUS duration: " << previousDuration;
1183 trackPlaylist.resize_clip(clipIndex, in.frames(m_fps), newDuration);
1184 trackPlaylist.consolidate_blanks(0);
1185 if (previousDuration < newDuration) {
1186 // clip was made longer, trim next blank if there is one.
1187 if (trackPlaylist.is_blank(clipIndex + 1)) {
1188 trackPlaylist.split(clipIndex + 1, newDuration - previousDuration);
1189 trackPlaylist.remove(clipIndex + 1);
1191 } else trackPlaylist.insert_blank(clipIndex + 1, previousDuration - newDuration - 1);
1193 trackPlaylist.consolidate_blanks(0);
1194 tractor.multitrack()->refresh();
1196 if (track != 0) mltCheckLength();
1197 m_isBlocked = false;
1200 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1201 Mlt::Service service(m_mltProducer->parent().get_service());
1203 Mlt::Tractor tractor(service);
1204 Mlt::Producer trackProducer(tractor.track(track));
1205 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1207 if (blind) trackProducer.set("hide", 3);
1208 else trackProducer.set("hide", 2);
1210 trackProducer.set("hide", 1);
1212 trackProducer.set("hide", 0);
1214 tractor.multitrack()->refresh();
1219 void Render::mltResizeClipStart(int track, GenTime pos, GenTime moveEnd, GenTime moveStart, GenTime in, GenTime out) {
1221 Mlt::Service service(m_mltProducer->parent().get_service());
1222 int moveFrame = (moveEnd - moveStart).frames(m_fps);
1224 Mlt::Tractor tractor(service);
1225 Mlt::Producer trackProducer(tractor.track(track));
1226 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1227 if (trackPlaylist.is_blank_at(pos.frames(m_fps) - 1))
1228 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1229 int clipIndex = trackPlaylist.get_clip_index_at(pos.frames(m_fps) - 1);
1230 kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1232 trackPlaylist.resize_clip(clipIndex, in.frames(m_fps), out.frames(m_fps));
1233 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1235 int midpos = moveStart.frames(m_fps) - 1; //+ (moveFrame / 2)
1236 int blankIndex = trackPlaylist.get_clip_index_at(midpos);
1237 int blankLength = trackPlaylist.clip_length(blankIndex);
1239 kDebug() << " + resizing blank: " << blankIndex << ", Mid: " << midpos << ", Length: " << blankLength << ", SIZE DIFF: " << moveFrame;
1242 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1243 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1245 trackPlaylist.consolidate_blanks(0);
1246 m_isBlocked = false;
1247 kDebug() << "-----------------\n" << "CLIP 0: " << trackPlaylist.clip_start(0) << ", LENGT: " << trackPlaylist.clip_length(0);
1248 kDebug() << "CLIP 1: " << trackPlaylist.clip_start(1) << ", LENGT: " << trackPlaylist.clip_length(1);
1249 kDebug() << "CLIP 2: " << trackPlaylist.clip_start(2) << ", LENGT: " << trackPlaylist.clip_length(2);
1250 kDebug() << "CLIP 3: " << trackPlaylist.clip_start(3) << ", LENGT: " << trackPlaylist.clip_length(3);
1251 kDebug() << "CLIP 4: " << trackPlaylist.clip_start(4) << ", LENGT: " << trackPlaylist.clip_length(4);
1254 void Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1255 mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1259 void Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1261 //m_mltConsumer->set("refresh", 0);
1262 Mlt::Service service(m_mltProducer->parent().get_service());
1264 Mlt::Tractor tractor(service);
1265 Mlt::Producer trackProducer(tractor.track(startTrack));
1266 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1267 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1268 mlt_field field = mlt_tractor_field(tractor.get_tractor());
1269 mlt_multitrack multitrack = mlt_field_multitrack(field); //mlt_tractor_multitrack(tractor.get_tractor());
1270 kDebug() << " -- CURRENT MULTIOTRACK HAS: " << mlt_multitrack_count(multitrack) << " tracks";;
1271 mlt_service multiprod = mlt_multitrack_service(multitrack);
1273 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1274 trackPlaylist.consolidate_blanks(0);
1275 mlt_events_block(MLT_PRODUCER_PROPERTIES(trackProducer.get_producer()), NULL);
1277 if (endTrack == startTrack) {
1278 if (!trackPlaylist.is_blank_at(moveEnd)) {
1279 kWarning() << "// ERROR, CLIP COLLISION----------";
1280 int ix = trackPlaylist.get_clip_index_at(moveEnd);
1281 kDebug() << "BAD CLIP STARTS AT: " << trackPlaylist.clip_start(ix) << ", LENGT: " << trackPlaylist.clip_length(ix);
1283 trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1284 trackPlaylist.consolidate_blanks(0);
1286 trackPlaylist.consolidate_blanks(0);
1287 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1288 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1289 destTrackPlaylist.consolidate_blanks(1);
1290 destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1291 destTrackPlaylist.consolidate_blanks(0);
1295 mlt_events_unblock(MLT_PRODUCER_PROPERTIES(trackProducer.get_producer()), NULL);
1296 m_isBlocked = false;
1297 m_mltConsumer->set("refresh", 1);
1300 void Render::mltMoveTransition(QString type, int startTrack, int trackOffset, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1302 m_mltConsumer->set("refresh", 0);
1303 mlt_service serv = m_mltProducer->parent().get_service();
1305 mlt_service nextservice = mlt_service_get_producer(serv);
1306 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1307 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1308 QString resource = mlt_properties_get(properties, "mlt_service");
1309 int old_pos = (oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1311 int new_in = newIn.frames(m_fps);
1312 int new_out = newOut.frames(m_fps) - 1;
1313 while (mlt_type == "transition") {
1314 mlt_transition tr = (mlt_transition) nextservice;
1315 int currentTrack = mlt_transition_get_b_track(tr);
1316 int currentIn = (int) mlt_transition_get_in(tr);
1317 int currentOut = (int) mlt_transition_get_out(tr);
1318 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
1319 //kDebug()<<"// LOOKING FOR IN: "<<old_in<<", OUT: "<<old_out;
1320 kDebug() << "// OLD IN: " << oldIn.frames(m_fps) << " // OLD OUT: " << oldOut.frames(m_fps) << ", TRACK: " << startTrack << ", MID POS: " << old_pos;
1321 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1322 mlt_transition_set_in_and_out(tr, new_in, new_out);
1323 if (trackOffset != 0) {
1324 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1325 mlt_properties_set_int(properties, "a_track", mlt_transition_get_a_track(tr) + trackOffset);
1326 mlt_properties_set_int(properties, "b_track", mlt_transition_get_b_track(tr) + trackOffset);
1330 nextservice = mlt_service_producer(nextservice);
1331 properties = MLT_SERVICE_PROPERTIES(nextservice);
1332 mlt_type = mlt_properties_get(properties, "mlt_type");
1333 resource = mlt_properties_get(properties, "mlt_service");
1335 m_isBlocked = false;
1338 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QMap <QString, QString> args) {
1339 kDebug() << "update transition" << tag;
1341 mltDeleteTransition(oldTag, a_track, b_track, in, out, args);
1342 mltAddTransition(tag, a_track, b_track, in, out, args);
1343 m_isBlocked = false;
1352 mlt_filter *filters;
1353 pthread_mutex_t mutex;
1357 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QMap <QString, QString> args) {
1358 Mlt::Service service(m_mltProducer->parent().get_service());
1360 Mlt::Tractor tractor(service);
1361 for (int track = 0;track < 10;track++) {
1362 Mlt::Producer *trackprod = tractor.track(track);
1365 Mlt::Producer trackProducer(trackprod);
1366 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1367 Mlt::Producer *prod = NULL;
1370 prod = trackPlaylist.get_clip(g++);
1373 for (int j = 0;j < prod->count();j++) {
1375 kDebug() << prod->get_name(j) << " " << prod->get(j);
1377 Mlt::Producer parprod = prod->parent();
1378 for (int j = 0;j < parprod.count();j++) {
1380 kDebug() << " " << parprod.get_name(j) << " " << parprod.get(j);
1382 Mlt::Tractor tractor(parprod);
1383 if (tractor.is_valid()) {
1384 kDebug() << "---------ja";
1387 kDebug() << "track=" << track << " " << g << " " << prod;
1389 /*Mlt::Tractor parent(prod->parent());
1390 if (!parent.get_tractor())
1392 Mlt::Producer *prod1=parent.track(1);
1401 m_mltConsumer->set("refresh", 0);
1402 mlt_service serv = m_mltProducer->parent().get_service();
1403 Mlt::Service service(m_mltProducer->parent().get_service());
1405 Mlt::Tractor tractor(service);
1406 mlt_service nextservice = mlt_service_get_producer(serv);
1407 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1409 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1410 QString resource = mlt_properties_get(properties, "mlt_service");
1411 int old_pos = (in.frames(m_fps) + out.frames(m_fps)) / 2;
1412 int trackOffset = 0;
1413 int new_in = in.frames(m_fps);
1414 int new_out = out.frames(m_fps) - 1;
1415 while (mlt_type == "transition") {
1416 mlt_transition tr = (mlt_transition) nextservice;
1417 int currentTrack = mlt_transition_get_b_track(tr);
1418 int currentIn = (int) mlt_transition_get_in(tr);
1419 int currentOut = (int) mlt_transition_get_out(tr);
1420 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
1421 //kDebug()<<"// LOOKING FOR IN: "<<old_in<<", OUT: "<<old_out;
1422 kDebug() << "// OLD IN: " << in.frames(m_fps) << " // OLD OUT: " << out.frames(m_fps) << ", TRACK: " << a_track << ", MID POS: " << old_pos;
1423 if (/*resource == type &&*/ b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1424 kDebug() << "found transition that matches" << resource;
1425 //mlt_transition_set_in_and_out(tr, new_in, new_out);
1426 Mlt::Field *field = tractor.field();
1427 Mlt::Transition tt(*m_mltProfile, "mix");
1428 field->plant_transition(tt, a_track, b_track);
1430 mlt_service service = MLT_TRANSITION_SERVICE(tr);
1431 mlt_service_base *base = (mlt_service_base*)service->local;
1432 for (int i = 0;i < base->count;i++) {
1433 kDebug() << base->in[i] << " " << tr << " " << service << nextservice;
1435 mlt_service service1 = MLT_TRACTOR_SERVICE(tractor.get_tractor());
1436 mlt_service_base *base1 = (mlt_service_base*)service1->local;
1437 for (int i = 0;i < base1->count;i++) {
1438 kDebug() << base1->in[i] << " " << tr << " " << service << nextservice;
1439 if (base1->in[i] == (mlt_service_s*)tr) {
1440 mlt_service_lock(MLT_SERVICE_PROPERTIES(tr));
1441 //mlt_properties_dec_ref( MLT_SERVICE_PROPERTIES( tr ) );
1442 /*mlt_service_unlock(MLT_SERVICE_PROPERTIES(tr));
1445 mlt_events_disconnect(properties, nextservice);
1446 mlt_transition_close(tr);
1447 //base1->in[i]=NULL;
1448 base1->out = NULL;*/
1449 base1->in[i] = NULL;
1452 mlt_service_base *basetr = (mlt_service_base*)service1->local;
1458 //service->child=NULL;
1459 ///mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1460 ///mlt_properties_set ( properties , "active" , 0 );
1461 ///7mlt_events_disconnect(properties, nextservice);
1462 //mlt_events_fire(MLT_SERVICE_PROPERTIES(nextservice), "service-changed", NULL);
1463 //mlt_properties_set_int(properties, "a_track", mlt_transition_get_a_track(tr) + trackOffset);
1464 //mlt_properties_set_int(properties, "b_track", mlt_transition_get_b_track(tr) + trackOffset);
1469 nextservice = mlt_service_producer(nextservice);
1470 properties = MLT_SERVICE_PROPERTIES(nextservice);
1471 mlt_type = mlt_properties_get(properties, "mlt_type");
1472 resource = mlt_properties_get(properties, "mlt_service");
1474 m_isBlocked = false;
1478 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QMap <QString, QString> args) {
1480 Mlt::Service service(m_mltProducer->parent().get_service());
1482 Mlt::Tractor tractor(service);
1483 for (int track = 0;track < 10;track++) {
1484 Mlt::Producer *trackprod = tractor.track(track);
1487 Mlt::Producer trackProducer(trackprod);
1488 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1490 int clipindex = trackPlaylist.get_clip_index_at(in.frames(m_fps));
1491 if (clipindex != 0) {
1492 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, decodedString(tag));
1493 if (!transition || !transition->get_transition())
1495 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
1496 QMap<QString, QString>::Iterator it;
1499 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
1501 for (it = args.begin(); it != args.end(); ++it) {
1503 char *name = decodedString(key);
1504 char *value = decodedString(it.value());
1505 transition->set(name, value);
1506 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
1507 //filter->set("kdenlive_id", id);
1511 Mlt::Producer *left = trackPlaylist.get_clip(clipindex - 1);
1512 Mlt::Producer *right = trackPlaylist.get_clip(clipindex);
1513 kDebug() << "left=" << left << " right=" << right;
1515 Mlt::Playlist track0;
1516 mixer.set_track(track0, 0);
1517 Mlt::Producer *out_frame = left->cut(left->get_in() + left->get_playtime() - 1, left->get_in() + left->get_playtime() - 1);
1518 track0.append(*out_frame);
1519 track0.repeat(0, 20);
1520 mixer.set_track(*right, 1);
1521 transition->set_in_and_out(0, 20 - 1);
1522 mixer.plant_transition(transition);
1523 trackPlaylist.insert(mixer, clipindex, 0, mixer.get_playtime());
1524 trackPlaylist.remove(clipindex + 1);
1530 Mlt::Service service(m_mltProducer->parent().get_service());
1532 Mlt::Tractor tractor(service);
1533 Mlt::Field *field = tractor.field();
1534 char *transId = decodedString(tag);
1535 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
1536 if (!transition || !transition->get_transition())
1538 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
1539 QMap<QString, QString>::Iterator it;
1542 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
1544 for (it = args.begin(); it != args.end(); ++it) {
1546 char *name = decodedString(key);
1547 char *value = decodedString(it.value());
1548 transition->set(name, value);
1549 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
1550 //filter->set("kdenlive_id", id);
1554 // attach filter to the clip
1555 field->plant_transition(*transition, a_track, b_track);
1557 m_isBlocked = false;
1562 void Render::mltSavePlaylist() {
1563 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
1564 Mlt::Consumer *fileConsumer = new Mlt::Consumer(*m_mltProfile, "westley");
1565 fileConsumer->set("resource", "/tmp/playlist.westley");
1567 Mlt::Service service(m_mltProducer->get_service());
1568 Mlt::Tractor tractor(service);
1570 fileConsumer->connect(service);
1571 fileConsumer->start();
1575 #include "renderer.moc"