1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
25 // ffmpeg Header files
33 #include <QApplication>
37 #include <KStandardDirs>
38 #include <KMessageBox>
40 #include <KTemporaryFile>
43 #include "kdenlivesettings.h"
45 #include "definitions.h"
47 #include <mlt++/Mlt.h>
49 #if LIBAVCODEC_VERSION_MAJOR > 51 || (LIBAVCODEC_VERSION_MAJOR > 50 && LIBAVCODEC_VERSION_MINOR > 54)
50 // long_name was added in FFmpeg avcodec version 51.55
51 #define ENABLE_FFMPEG_CODEC_DESCRIPTION 1
54 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
55 // detect if the producer has finished playing. Is there a better way to do it ?
56 if (self->m_isBlocked) return;
57 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
58 self->emitConsumerStopped();
60 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
64 Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(-1), m_framePosition(0), m_generateScenelist(false), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false) {
65 kDebug() << "////////// USING PROFILE: " << (char *)KdenliveSettings::current_profile().toUtf8().data();
66 m_mltProfile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data());
67 refreshTimer = new QTimer(this);
68 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
70 if (rendererName == "project") m_monitorId = 10000;
71 else m_monitorId = 10001;
72 osdTimer = new QTimer(this);
73 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
75 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
76 //if (rendererName == "clip")
78 //Mlt::Consumer *consumer = new Mlt::Consumer( profile , "sdl_preview");
79 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
80 m_mltConsumer->set("resize", 1);
81 m_mltConsumer->set("window_id", winid);
82 m_mltConsumer->set("terminate_on_pause", 1);
83 m_mltConsumer->set("rescale", "nearest");
84 m_mltConsumer->set("progressive", 1);
85 m_mltConsumer->set("audio_buffer", 1024);
86 m_mltConsumer->set("frequency", 48000);
87 m_externalwinid = extid;
89 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
90 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", "<westley><playlist><producer mlt_service=\"colour\" colour=\"blue\" in=\"0\" out=\"25\" /></playlist></westley>");
91 m_mltProducer = producer;
92 if (m_blackClip) delete m_blackClip;
93 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
94 m_blackClip->set("id", "black");
95 m_mltConsumer->connect(*m_mltProducer);
96 m_mltProducer->set_speed(0.0);
98 //m_mltConsumer->start();
102 /*m_osdInfo = new Mlt::Filter("data_show");
103 char *tmp = decodedString(m_osdProfile);
104 m_osdInfo->set("resource", tmp);
106 // Does it do anything usefull? I mean, RenderThread doesn't do anything useful at the moment
107 // (except being cpu hungry :)
109 /* if(!s_renderThread) {
110 s_renderThread = new RenderThread;
111 s_renderThread->start();
120 void Render::closeMlt() {
124 delete m_mltConsumer;
126 delete m_mltProducer;
127 if (m_blackClip) delete m_blackClip;
133 int Render::resetProfile(QString profile) {
135 if (!m_mltConsumer) return 0;
136 if (m_isSplitView) slotSplitView(false);
137 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
138 m_mltConsumer->purge();
139 delete m_mltConsumer;
141 m_mltConsumer = NULL;
142 QString scene = sceneList();
143 if (m_mltProducer) delete m_mltProducer;
144 m_mltProducer = NULL;
145 if (m_mltProfile) delete m_mltProfile;
148 char *tmp = decodedString(profile);
149 m_mltProfile = new Mlt::Profile(tmp);
151 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer;
152 m_mltConsumer->set("resize", 1);
153 m_mltConsumer->set("window_id", m_winid);
154 m_mltConsumer->set("terminate_on_pause", 1);
155 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
156 m_mltConsumer->set("rescale", "nearest");
157 m_mltConsumer->set("progressive", 1);
158 m_mltConsumer->set("audio_buffer", 1024);
159 m_mltConsumer->set("frequency", 48000);
161 kDebug() << "//RESET WITHSCENE: " << scene;
164 tmp = decodedString(scene);
165 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
167 m_mltProducer = producer;
168 if (m_blackClip) delete m_blackClip;
169 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
170 m_mltProducer->optimise();
171 m_mltProducer->set_speed(0);
174 //delete m_mltProfile;
175 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
176 //mlt_profile prof = m_mltProfile->get_profile();
177 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
178 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
179 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
180 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
181 kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << profile << ", WIDTH: " << m_mltProfile->width();
183 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
188 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
189 void Render::seek(GenTime time) {
190 sendSeekCommand(time);
191 //emit positionChanged(time);
195 char *Render::decodedString(QString str) {
196 /*QCString fn = QFile::encodeName(str);
197 char *t = new char[fn.length() + 1];
198 strcpy(t, (const char *)fn);*/
200 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
204 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
205 QPixmap pix(width, height);
207 mlt_image_format format = mlt_image_rgb24a;
208 uint8_t *thumb = frame->get_image(format, width, height);
209 QImage image(thumb, width, height, QImage::Format_ARGB32);
211 if (!image.isNull()) {
212 pix = pix.fromImage(image);
214 QPainter painter(&pix);
215 painter.drawRect(0, 0, width - 1, height - 1);
217 } else pix.fill(Qt::black);
221 const int Render::renderWidth() const {
222 return (int)(m_mltProfile->height() * m_mltProfile->dar());
225 const int Render::renderHeight() const {
226 return m_mltProfile->height();
229 QPixmap Render::extractFrame(int frame_position, int width, int height) {
231 width = renderWidth();
232 height = renderHeight();
234 QPixmap pix(width, height);
235 if (!m_mltProducer) {
239 return KThumb::getFrame(*m_mltProducer, frame_position, width, height);
242 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
245 if (url.fileName().startsWith(".all.")) { // check for slideshow
246 QString fileType = url.fileName().right(3);
248 QStringList::Iterator it;
250 QDir dir(url.directory());
252 filter << "*." + fileType;
253 filter << "*." + fileType.toUpper();
254 more = dir.entryList(filter, QDir::Files);
255 im.load(url.directory() + "/" + more.at(0));
256 } else im.load(url.path());
257 //pixmap = im.scaled(width, height);
262 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
263 QPixmap pix(width, height);
264 char *tmp = decodedString(file);
265 Mlt::Profile *prof = new Mlt::Profile(profile);
266 Mlt::Producer m_producer(*prof, tmp);
268 if (m_producer.is_blank()) {
273 Mlt::Filter m_convert(*prof, "avcolour_space");
274 m_convert.set("forced", mlt_image_rgb24a);
275 m_producer.attach(m_convert);
276 m_producer.seek(frame_position);
277 Mlt::Frame * frame = m_producer.get_frame();
279 pix = frameThumbnail(frame, width, height, true);
282 if (prof) delete prof;
287 void Render::getImage(KUrl url, int frame_position, QPoint size)
289 char *tmp = decodedString(url.path());
290 Mlt::Producer m_producer(tmp);
292 if (m_producer.is_blank()) {
295 Mlt::Filter m_convert("avcolour_space");
296 m_convert.set("forced", mlt_image_rgb24a);
297 m_producer.attach(m_convert);
298 m_producer.seek(frame_position);
300 Mlt::Frame * frame = m_producer.get_frame();
303 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
305 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
309 /* Create thumbnail for color */
310 /*void Render::getImage(int id, QString color, QPoint size)
312 QPixmap pixmap(size.x() - 2, size.y() - 2);
313 color = color.replace(0, 2, "#");
314 color = color.left(7);
315 pixmap.fill(QColor(color));
316 QPixmap result(size.x(), size.y());
317 result.fill(Qt::black);
318 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
319 emit replyGetImage(id, result, size.x(), size.y());
323 /* Create thumbnail for image */
324 /*void Render::getImage(KUrl url, QPoint size)
328 if (url.fileName().startsWith(".all.")) { // check for slideshow
329 QString fileType = url.fileName().right(3);
331 QStringList::Iterator it;
333 QDir dir( url.directory() );
334 more = dir.entryList( QDir::Files );
335 for ( it = more.begin() ; it != more.end() ; ++it ) {
336 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
337 if (!im.load(url.directory() + "/" + *it))
338 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
343 else im.load(url.path());
345 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
346 QPixmap result(size.x(), size.y());
347 result.fill(Qt::black);
348 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
349 emit replyGetImage(url, 1, result, size.x(), size.y());
353 double Render::consumerRatio() const {
354 if (!m_mltConsumer) return 1.0;
355 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
359 int Render::getLength() {
362 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
363 return mlt_producer_get_playtime(m_mltProducer->get_producer());
368 bool Render::isValid(KUrl url) {
369 char *tmp = decodedString(url.path());
370 Mlt::Producer producer(*m_mltProfile, tmp);
372 if (producer.is_blank())
378 const double Render::dar() const {
379 return m_mltProfile->dar();
382 void Render::slotSplitView(bool doit) {
383 m_isSplitView = doit;
384 Mlt::Service service(m_mltProducer->parent().get_service());
385 Mlt::Tractor tractor(service);
386 if (service.type() != tractor_type || tractor.count() < 2) return;
387 Mlt::Field *field = tractor.field();
390 for (int i = 1; i < tractor.count() && screen < 4; i++) {
391 Mlt::Producer trackProducer(tractor.track(i));
392 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
393 if (QString(trackProducer.get("hide")).toInt() != 1) {
394 kDebug() << "// ADIDNG TRACK: " << i;
395 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
396 transition->set("mlt_service", "composite");
397 transition->set("a_track", 0);
398 transition->set("b_track", i);
399 transition->set("distort", 1);
400 transition->set("internal_added", "200");
407 tmp = "50%,0:50%x50%";
410 tmp = "0,50%:50%x50%";
413 tmp = "50%,50%:50%x50%";
416 transition->set("geometry", tmp);
417 transition->set("always_active", "1");
418 field->plant_transition(*transition, 0, i);
423 m_mltConsumer->set("refresh", 1);
425 mlt_service serv = m_mltProducer->parent().get_service();
426 mlt_service nextservice = mlt_service_get_producer(serv);
427 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
428 QString mlt_type = mlt_properties_get(properties, "mlt_type");
429 QString resource = mlt_properties_get(properties, "mlt_service");
431 while (mlt_type == "transition") {
432 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
433 if (added == "200") {
434 mlt_field_disconnect_service(field->get_field(), nextservice);
436 nextservice = mlt_service_producer(nextservice);
437 if (nextservice == NULL) break;
438 properties = MLT_SERVICE_PROPERTIES(nextservice);
439 mlt_type = mlt_properties_get(properties, "mlt_type");
440 resource = mlt_properties_get(properties, "mlt_service");
441 m_mltConsumer->set("refresh", 1);
446 void Render::getFileProperties(const QDomElement &xml, int clipId) {
448 int width = (int)(height * m_mltProfile->dar());
449 QMap < QString, QString > filePropertyMap;
450 QMap < QString, QString > metadataPropertyMap;
452 KUrl url = KUrl(xml.attribute("resource", QString::null));
453 Mlt::Producer *producer;
454 if (xml.attribute("type").toInt() == COLOR) {
455 char *tmp = decodedString("colour:" + xml.attribute("colour"));
456 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
458 } else if (url.isEmpty()) {
460 QDomElement westley = doc.createElement("westley");
461 QDomElement play = doc.createElement("playlist");
462 doc.appendChild(westley);
463 westley.appendChild(play);
464 play.appendChild(doc.importNode(xml, true));
465 kDebug() << "/ / / / /CLIP XML: " << doc.toString();
466 char *tmp = decodedString(doc.toString());
467 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
470 char *tmp = decodedString(url.path());
471 producer = new Mlt::Producer(*m_mltProfile, tmp);
474 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
476 if (producer->is_blank()) {
477 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
478 emit removeInvalidClip(clipId);
481 producer->set("id", clipId);
482 int frameNumber = xml.attribute("thumbnail", "0").toInt();
483 if (frameNumber != 0) producer->seek(frameNumber);
484 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
486 filePropertyMap["filename"] = url.path();
487 filePropertyMap["duration"] = QString::number(producer->get_playtime());
488 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
490 Mlt::Frame * frame = producer->get_frame();
492 if (xml.attribute("type").toInt() == SLIDESHOW) {
493 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
494 if (xml.attribute("fade") == "1") {
495 // user wants a fade effect to slideshow
496 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
497 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
498 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
499 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
500 char *tmp = decodedString(xml.attribute("luma_file"));
501 filter->set("luma.resource", tmp);
503 if (xml.hasAttribute("softness")) {
504 int soft = xml.attribute("softness").toInt();
505 filter->set("luma.softness", (double) soft / 100.0);
508 Mlt::Service clipService(producer->get_service());
509 clipService.attach(*filter);
514 filePropertyMap["fps"] = producer->get("source_fps");
516 if (frame && frame->is_valid()) {
517 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
518 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
519 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
520 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
522 if (frame->get_int("test_image") == 0) {
523 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
524 filePropertyMap["type"] = "playlist";
525 metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer->get_service()), "title"));
526 } else if (frame->get_int("test_audio") == 0)
527 filePropertyMap["type"] = "av";
529 filePropertyMap["type"] = "video";
531 mlt_image_format format = mlt_image_yuv422;
533 int frame_height = 0;
534 //frame->set("rescale.interp", "hyper");
535 frame->set("normalised_height", height);
536 frame->set("normalised_width", width);
537 QPixmap pix(width, height);
539 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
540 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
541 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
542 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
544 if (!image.isNull()) {
545 pix = pix.fromImage(image.rgbSwapped());
549 mlt_pool_release(new_image);
550 emit replyGetImage(clipId, 0, pix, width, height);
552 } else if (frame->get_int("test_audio") == 0) {
553 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
554 emit replyGetImage(clipId, 0, pixmap, width, height);
555 filePropertyMap["type"] = "audio";
559 // Retrieve audio / video codec name
561 // Fetch the video_context
564 AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
565 if (context != NULL) {
566 // Get the video_index
567 int index = mlt_properties_get_int(properties, "video_index");
569 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
570 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) {
571 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name;
574 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) {
575 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
577 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
578 context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
579 if (context != NULL) {
580 // Get the audio_index
581 int index = mlt_properties_get_int(properties, "audio_index");
583 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
584 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
585 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name;
588 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
589 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
594 mlt_properties metadata = mlt_properties_new();
595 mlt_properties_pass(metadata, properties, "meta.attr.");
596 int count = mlt_properties_count(metadata);
597 for (int i = 0; i < count; i ++) {
598 QString name = mlt_properties_get_name(metadata, i);
599 QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
600 if (name.endsWith("markup") && !value.isEmpty())
601 metadataPropertyMap[ name.section(".", 0, -2)] = value;
604 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
605 kDebug() << "REquested fuile info for: " << url.path();
606 if (frame) delete frame;
607 //if (producer) delete producer;
610 /** Create the producer from the Westley QDomDocument */
612 void Render::initSceneList() {
613 kDebug() << "-------- INIT SCENE LIST ------_";
615 QDomElement westley = doc.createElement("westley");
616 doc.appendChild(westley);
617 QDomElement prod = doc.createElement("producer");
618 prod.setAttribute("resource", "colour");
619 prod.setAttribute("colour", "red");
620 prod.setAttribute("id", "black");
621 prod.setAttribute("in", "0");
622 prod.setAttribute("out", "0");
624 QDomElement tractor = doc.createElement("tractor");
625 QDomElement multitrack = doc.createElement("multitrack");
627 QDomElement playlist1 = doc.createElement("playlist");
628 playlist1.appendChild(prod);
629 multitrack.appendChild(playlist1);
630 QDomElement playlist2 = doc.createElement("playlist");
631 multitrack.appendChild(playlist2);
632 QDomElement playlist3 = doc.createElement("playlist");
633 multitrack.appendChild(playlist3);
634 QDomElement playlist4 = doc.createElement("playlist");
635 multitrack.appendChild(playlist4);
636 QDomElement playlist5 = doc.createElement("playlist");
637 multitrack.appendChild(playlist5);
638 tractor.appendChild(multitrack);
639 westley.appendChild(tractor);
640 // kDebug()<<doc.toString();
642 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
643 setSceneList(doc, 0);
649 /** Create the producer from the Westley QDomDocument */
650 void Render::setProducer(Mlt::Producer *producer, int position) {
651 if (m_winid == -1) return;
652 m_generateScenelist = true;
655 m_mltConsumer->stop();
659 m_mltProducer->set_speed(0);
660 delete m_mltProducer;
661 m_mltProducer = NULL;
664 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
665 else m_mltProducer = new Mlt::Producer();
666 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
667 m_mltProducer->optimise();
669 m_fps = m_mltProducer->get_fps();
671 if (position != -1) {
672 m_mltProducer->seek(position);
673 emit rendererPosition(position);
675 m_generateScenelist = false;
680 /** Create the producer from the Westley QDomDocument */
681 void Render::setSceneList(QDomDocument list, int position) {
682 setSceneList(list.toString(), position);
685 /** Create the producer from the Westley QDomDocument */
686 void Render::setSceneList(QString playlist, int position) {
687 if (m_winid == -1) return;
688 m_generateScenelist = true;
690 kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
694 if (!clip.is_valid()) {
695 kWarning()<<" ++++ WARNING, UNABLE TO CREATE MLT PRODUCER";
696 m_generateScenelist = false;
701 m_mltConsumer->stop();
702 //m_mltConsumer->set("refresh", 0);
706 m_mltProducer->set_speed(0);
707 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
709 delete m_mltProducer;
710 m_mltProducer = NULL;
714 char *tmp = decodedString(playlist);
715 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
717 if (m_blackClip) delete m_blackClip;
718 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
719 m_blackClip->set("id", "black");
720 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
721 m_mltProducer->optimise();
723 /*if (KdenliveSettings::osdtimecode()) {
724 // Attach filter for on screen display of timecode
726 QString attr = "attr_check";
727 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
728 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
729 mlt_producer_attach( m_mltProducer->get_producer(), filter );
730 mlt_filter_close( filter );
732 m_osdInfo = new Mlt::Filter("data_show");
733 tmp = decodedString(m_osdProfile);
734 m_osdInfo->set("resource", tmp);
736 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
737 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
738 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
739 m_osdInfo->set("dynamic", "1");
741 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
743 m_osdInfo->set("dynamic", "0");
746 m_fps = m_mltProducer->get_fps();
747 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
750 m_mltProducer->seek(position);
751 emit rendererPosition(position);
753 m_generateScenelist = false;
757 /** Create the producer from the Westley QDomDocument */
758 QString Render::sceneList() {
763 saveSceneList(temp.fileName());
764 QFile file(temp.fileName());
765 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
766 kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE";
769 QTextStream in(&file);
770 while (!in.atEnd()) {
771 result.append(in.readLine());
777 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
779 char *tmppath = decodedString("westley:" + path);
780 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
781 m_mltProducer->optimise();
783 westleyConsumer.set("terminate_on_pause", 1);
784 Mlt::Producer prod(m_mltProducer->get_producer());
785 bool split = m_isSplitView;
786 if (split) slotSplitView(false);
787 westleyConsumer.connect(prod);
788 //prod.set("title", "kdenlive document");
789 //westleyConsumer.listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
790 westleyConsumer.start();
791 while (!westleyConsumer.is_stopped()) {}
792 if (!kdenliveData.isNull()) {
793 // add Kdenlive specific tags
796 doc.setContent(&file, false);
797 QDomNode wes = doc.elementsByTagName("westley").at(0);
798 wes.appendChild(doc.importNode(kdenliveData, true));
800 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
801 kWarning() << "////// ERROR writing to file: " << path;
804 QTextStream out(&file);
805 out << doc.toString();
808 if (split) slotSplitView(true);
812 const double Render::fps() const {
816 void Render::connectPlaylist() {
817 if (!m_mltConsumer) return;
818 //m_mltConsumer->set("refresh", "0");
819 m_mltConsumer->connect(*m_mltProducer);
820 m_mltProducer->set_speed(0);
821 m_mltConsumer->start();
822 emit durationChanged(m_mltProducer->get_playtime());
825 if (m_mltConsumer->start() == -1) {
826 KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
827 m_mltConsumer = NULL;
834 void Render::refreshDisplay() {
836 if (!m_mltProducer) return;
837 //m_mltConsumer->set("refresh", 0);
839 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
840 /*if (KdenliveSettings::osdtimecode()) {
841 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
842 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
843 m_osdInfo->set("dynamic", "1");
844 m_mltProducer->attach(*m_osdInfo);
847 m_mltProducer->detach(*m_osdInfo);
848 m_osdInfo->set("dynamic", "0");
853 void Render::setVolume(double volume) {
854 if (!m_mltConsumer || !m_mltProducer) return;
856 m_mltConsumer->set("refresh", 0);
857 // Attach filter for on screen display of timecode
858 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
859 mlt_properties_set_double( properties, "meta.volume", volume );
860 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
861 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
863 if (!KdenliveSettings::osdtimecode()) {
864 m_mltProducer->detach(*m_osdInfo);
865 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
866 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
869 osdTimer->setSingleShot(2500);
872 void Render::slotOsdTimeout() {
873 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
874 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
875 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
876 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
880 void Render::start() {
881 kDebug() << "----- STARTING MONITOR: " << m_name;
883 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
887 if (m_mltConsumer->is_stopped()) {
888 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
889 if (m_mltConsumer->start() == -1) {
890 KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
891 m_mltConsumer = NULL;
894 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
902 void Render::clear() {
903 kDebug() << " ********* RENDER CLEAR";
905 //m_mltConsumer->set("refresh", 0);
906 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
910 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
911 m_mltProducer->set_speed(0.0);
912 delete m_mltProducer;
913 m_mltProducer = NULL;
918 void Render::stop() {
919 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
920 kDebug() << "///////////// RENDER STOPPED: " << m_name;
921 //m_mltConsumer->set("refresh", 0);
922 m_mltConsumer->stop();
924 kDebug() << "///////////// RENDER STOP2-------";
928 m_mltProducer->set_speed(0.0);
929 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
930 kDebug() << m_mltProducer->get_length();
932 kDebug() << "///////////// RENDER STOP3-------";
935 void Render::stop(const GenTime & startTime) {
937 kDebug() << "///////////// RENDER STOP-------2";
939 m_mltProducer->set_speed(0.0);
940 m_mltProducer->seek((int) startTime.frames(m_fps));
942 m_mltConsumer->purge();
945 void Render::switchPlay() {
948 if (m_mltProducer->get_speed() == 0.0) {
949 //m_isBlocked = false;
950 m_mltProducer->set_speed(1.0);
951 m_mltConsumer->set("refresh", 1);
952 kDebug() << " ********* RENDER PLAY: " << m_mltProducer->get_speed();
954 //m_isBlocked = true;
955 m_mltConsumer->set("refresh", 0);
956 m_mltProducer->set_speed(0.0);
957 //m_isBlocked = true;
958 m_mltProducer->seek((int) m_framePosition);
959 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
960 //m_mltConsumer->set("refresh", 0);
961 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
962 m_mltProducer->set_speed(0);
963 m_mltProducer->seek( position );
964 //m_mltProducer->seek((int) m_framePosition);
965 m_isBlocked = false;*/
967 /*if (speed == 0.0) {
968 m_mltProducer->seek((int) m_framePosition + 1);
969 m_mltConsumer->purge();
974 void Render::play(double speed) {
975 kDebug() << " ********* REDNER PLAY";
978 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
979 m_mltProducer->set_speed(speed);
980 /*if (speed == 0.0) {
981 m_mltProducer->seek((int) m_framePosition + 1);
982 m_mltConsumer->purge();
987 void Render::play(double speed, const GenTime & startTime) {
988 kDebug() << "///////////// RENDER PLAY2-------" << speed;
991 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
992 //if (speed == 0.0) m_mltConsumer->set("refresh", 0);
993 m_mltProducer->set_speed(speed);
994 m_mltProducer->seek((int)(startTime.frames(m_fps)));
995 //m_mltConsumer->purge();
999 void Render::play(double speed, const GenTime & startTime,
1000 const GenTime & stopTime) {
1001 kDebug() << "///////////// RENDER PLAY3-------" << speed << stopTime.frames(m_fps);
1004 m_mltProducer->set("out", stopTime.frames(m_fps));
1005 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1006 m_mltConsumer->purge();
1007 m_mltProducer->set_speed(speed);
1012 void Render::sendSeekCommand(GenTime time) {
1013 //kDebug()<<" ********* RENDER SEND SEEK";
1016 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
1017 m_mltProducer->seek((int)(time.frames(m_fps)));
1018 m_mltConsumer->set("refresh", 1);
1022 void Render::seekToFrame(int pos) {
1023 //kDebug()<<" ********* RENDER SEEK TO POS";
1026 m_mltProducer->seek(pos);
1030 void Render::askForRefresh() {
1031 // Use a Timer so that we don't refresh too much
1032 refreshTimer->start(200);
1035 void Render::doRefresh() {
1036 // Use a Timer so that we don't refresh too much
1037 m_mltConsumer->set("refresh", 1);
1040 void Render::refresh() {
1041 if (!m_mltProducer || m_isBlocked)
1043 refreshTimer->stop();
1044 if (m_mltConsumer) {
1045 m_mltConsumer->set("refresh", 1);
1049 /** Sets the description of this renderer to desc. */
1050 void Render::setDescription(const QString & description) {
1051 m_description = description;
1054 /** Returns the description of this renderer */
1055 QString Render::description() {
1056 return m_description;
1060 double Render::playSpeed() {
1061 if (m_mltProducer) return m_mltProducer->get_speed();
1065 GenTime Render::seekPosition() const {
1066 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1067 else return GenTime();
1071 const QString & Render::rendererName() const {
1076 void Render::emitFrameNumber(double position) {
1077 if (m_generateScenelist) return;
1078 m_framePosition = position;
1079 emit rendererPosition((int) position);
1080 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1083 void Render::emitConsumerStopped() {
1084 // This is used to know when the playing stopped
1085 if (m_mltProducer && !m_generateScenelist) {
1086 double pos = m_mltProducer->position();
1087 emit rendererStopped((int) pos);
1088 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1089 //new QCustomEvent(10002));
1095 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1096 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1100 void Render::exportCurrentFrame(KUrl url, bool notify) {
1101 if (!m_mltProducer) {
1102 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1106 int height = 1080;//KdenliveSettings::defaultheight();
1107 int width = 1940; //KdenliveSettings::displaywidth();
1109 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1111 QPixmap pix(width, height);
1112 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1113 m_convert.set("forced", mlt_image_rgb24a);
1114 m_mltProducer->attach(m_convert);
1115 Mlt::Frame * frame = m_mltProducer->get_frame();
1116 m_mltProducer->detach(m_convert);
1118 pix = frameThumbnail(frame, width, height);
1121 pix.save(url.path(), "PNG");
1122 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1125 /** MLT PLAYLIST DIRECT MANIPULATON **/
1128 void Render::mltCheckLength(bool reload) {
1129 //kDebug()<<"checking track length: "<<track<<"..........";
1131 Mlt::Service service(m_mltProducer->get_service());
1132 Mlt::Tractor tractor(service);
1134 int trackNb = tractor.count();
1135 double duration = 0;
1136 double trackDuration;
1138 Mlt::Producer trackProducer(tractor.track(0));
1139 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1140 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1141 m_mltProducer->set("out", duration);
1142 emit durationChanged((int) duration);
1145 while (trackNb > 1) {
1146 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1147 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1148 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1150 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1151 if (trackDuration > duration) duration = trackDuration;
1155 Mlt::Producer blackTrackProducer(tractor.track(0));
1156 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1157 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1159 if (blackDuration != duration) {
1160 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1162 int dur = (int)duration;
1164 QDomElement black = doc.createElement("producer");
1165 black.setAttribute("mlt_service", "colour");
1166 black.setAttribute("colour", "black");
1167 black.setAttribute("id", "black");
1170 while (dur > 14000) {
1171 info.startPos = GenTime(i * 14000, m_fps);
1172 info.endPos = info.startPos + GenTime(13999, m_fps);
1173 mltInsertClip(info, black, m_blackClip);
1178 info.startPos = GenTime(i * 14000, m_fps);
1179 info.endPos = info.startPos + GenTime(dur, m_fps);
1180 mltInsertClip(info, black, m_blackClip);
1182 m_mltProducer->set("out", duration);
1183 emit durationChanged((int)duration);
1187 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1188 if (!m_mltProducer) {
1189 kDebug() << "PLAYLIST NOT INITIALISED //////";
1192 Mlt::Producer parentProd(m_mltProducer->parent());
1193 if (parentProd.get_producer() == NULL) {
1194 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1198 Mlt::Service service(parentProd.get_service());
1199 Mlt::Tractor tractor(service);
1200 mlt_service_lock(service.get_service());
1201 Mlt::Producer trackProducer(tractor.track(info.track));
1202 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1204 Mlt::Producer *clip = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1205 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1207 if (QString(prod->get("transparency")).toInt() == 1)
1208 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());
1210 mlt_service_unlock(service.get_service());
1212 if (info.track != 0) mltCheckLength();
1213 //tractor.multitrack()->refresh();
1214 //tractor.refresh();
1218 void Render::mltCutClip(int track, GenTime position) {
1221 Mlt::Service service(m_mltProducer->parent().get_service());
1222 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1224 Mlt::Tractor tractor(service);
1225 Mlt::Producer trackProducer(tractor.track(track));
1226 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1227 trackPlaylist.split_at((int) position.frames(m_fps));
1228 trackPlaylist.consolidate_blanks(0);
1229 // duplicate effects
1230 Mlt::Producer *original = trackPlaylist.get_clip_at((int) position.frames(m_fps) - 1);
1231 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps) + 1);
1232 Mlt::Service clipService(original->get_service());
1233 Mlt::Service dupService(clip->get_service());
1235 Mlt::Filter *filter = clipService.filter(ct);
1237 Mlt::Filter *dup = new Mlt::Filter(filter->get_filter());
1238 dupService.attach(*dup);
1240 filter = clipService.filter(ct);
1244 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1246 mltRemoveClip(info.track, info.startPos);
1247 mltInsertClip(info, element, prod);
1251 void Render::mltRemoveClip(int track, GenTime position) {
1254 Mlt::Service service(m_mltProducer->parent().get_service());
1255 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1257 Mlt::Tractor tractor(service);
1258 Mlt::Producer trackProducer(tractor.track(track));
1259 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1260 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1261 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1262 if (QString(clip.parent().get("transparency")).toInt() == 1)
1263 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());
1264 trackPlaylist.replace_with_blank(clipIndex);
1265 trackPlaylist.consolidate_blanks(0);
1266 if (track != 0) mltCheckLength();
1267 //emit durationChanged();
1268 m_isBlocked = false;
1271 int Render::mltChangeClipSpeed(ItemInfo info, double speed, Mlt::Producer *prod) {
1274 Mlt::Service service(m_mltProducer->parent().get_service());
1275 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1277 Mlt::Tractor tractor(service);
1278 Mlt::Producer trackProducer(tractor.track(info.track));
1279 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1280 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1281 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1282 QString serv = clip.parent().get("mlt_service");
1283 QString id = clip.parent().get("id");
1284 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1285 if (serv == "avformat" && speed != 1.0) {
1286 mlt_service_lock(service.get_service());
1287 QString url = clip.parent().get("resource");
1288 url.append(":" + QString::number(speed));
1289 char *tmp = decodedString(url);
1290 Mlt::Producer *slow = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1292 tmp = decodedString(id);
1293 slow->set("id", tmp);
1295 slow->set_in_and_out(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps));
1296 newLength = slow->get_length();
1297 trackPlaylist.replace_with_blank(clipIndex);
1298 trackPlaylist.consolidate_blanks(0);
1299 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *slow, 1);
1300 mlt_service_unlock(service.get_service());
1301 kDebug() << "AVFORMAT CLIP!!!:";
1302 } else if (speed == 1.0) {
1303 mlt_service_lock(service.get_service());
1304 Mlt::Producer *cut = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1305 trackPlaylist.replace_with_blank(clipIndex);
1306 newLength = cut->get_length();
1307 trackPlaylist.consolidate_blanks(0);
1308 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1309 mlt_service_unlock(service.get_service());
1310 } else if (serv == "framebuffer") {
1311 mlt_service_lock(service.get_service());
1312 QString url = clip.parent().get("resource");
1313 url = url.section(":", 0, -1);
1314 url.append(":" + QString::number(speed));
1315 char *tmp = decodedString(url);
1316 Mlt::Producer *slow = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1318 tmp = decodedString(id);
1319 slow->set("id", tmp);
1321 slow->set_in_and_out(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps));
1322 newLength = slow->get_length();
1323 trackPlaylist.replace_with_blank(clipIndex);
1324 trackPlaylist.consolidate_blanks(0);
1325 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *slow, 1);
1326 mlt_service_unlock(service.get_service());
1327 kDebug() << "AVFORMAT CLIP!!!:";
1330 m_isBlocked = false;
1334 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1336 Mlt::Service service(m_mltProducer->parent().get_service());
1337 bool success = false;
1338 Mlt::Tractor tractor(service);
1339 Mlt::Producer trackProducer(tractor.track(track));
1340 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1341 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1342 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1344 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1347 Mlt::Service clipService(clip->get_service());
1348 // if (tag.startsWith("ladspa")) tag = "ladspa";
1351 Mlt::Filter *filter = clipService.filter(ct);
1353 if (index == "-1" || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1354 if (clipService.detach(*filter) == 0) success = true;
1355 kDebug() << " / / / DLEETED EFFECT: " << ct;
1357 filter = clipService.filter(ct);
1359 m_isBlocked = false;
1360 if (doRefresh) refresh();
1365 bool Render::mltAddEffect(int track, GenTime position, QMap <QString, QString> args, bool doRefresh) {
1367 Mlt::Service service(m_mltProducer->parent().get_service());
1369 Mlt::Tractor tractor(service);
1370 Mlt::Producer trackProducer(tractor.track(track));
1371 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1373 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1377 Mlt::Service clipService(clip->get_service());
1380 QString tag = args.value("tag");
1381 kDebug() << " / / INSERTING EFFECT: " << tag;
1382 if (tag.startsWith("ladspa")) tag = "ladspa";
1383 char *filterTag = decodedString(tag);
1384 char *filterId = decodedString(args.value("id"));
1385 QMap<QString, QString>::Iterator it;
1386 QString kfr = args.value("keyframes");
1388 if (!kfr.isEmpty()) {
1389 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1390 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1391 char *starttag = decodedString(args.value("starttag", "start"));
1392 char *endtag = decodedString(args.value("endtag", "end"));
1393 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1394 int duration = clip->get_playtime();
1395 double max = args.value("max").toDouble();
1396 double min = args.value("min").toDouble();
1397 double factor = args.value("factor", "1").toDouble();
1398 args.remove("starttag");
1399 args.remove("endtag");
1400 args.remove("keyframes");
1403 args.remove("factor");
1405 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1406 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1407 filter->set("kdenlive_id", filterId);
1408 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1409 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1410 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1411 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1412 if (x2 == -1) x2 = duration;
1413 for (it = args.begin(); it != args.end(); ++it) {
1414 char *name = decodedString(it.key());
1415 char *value = decodedString(it.value());
1416 filter->set(name, value);
1421 filter->set("in", x1);
1422 filter->set("out", x2);
1423 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1424 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1425 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1426 clipService.attach(*filter);
1432 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1433 if (filter && filter->is_valid())
1434 filter->set("kdenlive_id", filterId);
1436 kDebug() << "filter is NULL";
1437 m_isBlocked = false;
1441 for (it = args.begin(); it != args.end(); ++it) {
1442 char *name = decodedString(it.key());
1443 char *value = decodedString(it.value());
1444 filter->set(name, value);
1448 // attach filter to the clip
1449 clipService.attach(*filter);
1453 m_isBlocked = false;
1454 if (doRefresh) refresh();
1458 bool Render::mltEditEffect(int track, GenTime position, QMap <QString, QString> args) {
1459 QString index = args.value("kdenlive_ix");
1460 QString tag = args.value("tag");
1461 QMap<QString, QString>::Iterator it = args.begin();
1462 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1463 // This is a keyframe effect, to edit it, we remove it and re-add it.
1464 mltRemoveEffect(track, position, index);
1465 bool success = mltAddEffect(track, position, args);
1470 Mlt::Service service(m_mltProducer->parent().get_service());
1472 Mlt::Tractor tractor(service);
1473 Mlt::Producer trackProducer(tractor.track(track));
1474 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1475 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1476 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1478 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1481 Mlt::Service clipService(clip->get_service());
1484 Mlt::Filter *filter = clipService.filter(ct);
1486 if (filter->get("kdenlive_ix") == index) {
1490 filter = clipService.filter(ct);
1494 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1495 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1497 filter = clipService.filter(ct);
1498 QList <Mlt::Filter *> filtersList;
1500 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1501 filtersList.append(filter);
1502 clipService.detach(*filter);
1504 filter = clipService.filter(ct);
1506 bool success = mltAddEffect(track, position, args);
1508 for (int i = 0; i < filtersList.count(); i++) {
1509 clipService.attach(*(filtersList.at(i)));
1512 m_isBlocked = false;
1516 for (it = args.begin(); it != args.end(); ++it) {
1517 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1518 char *name = decodedString(it.key());
1519 char *value = decodedString(it.value());
1520 filter->set(name, value);
1524 m_isBlocked = false;
1529 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1531 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1532 Mlt::Service service(m_mltProducer->parent().get_service());
1534 Mlt::Tractor tractor(service);
1535 Mlt::Producer trackProducer(tractor.track(track));
1536 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1537 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1538 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1540 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1543 Mlt::Service clipService(clip->get_service());
1546 QList <Mlt::Filter *> filtersList;
1547 Mlt::Filter *filter = clipService.filter(ct);
1549 if (newPos > oldPos) {
1551 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1552 filter->set("kdenlive_ix", newPos);
1553 filtersList.append(filter);
1554 clipService.detach(*filter);
1555 filter = clipService.filter(ct);
1556 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1557 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1559 filter = clipService.filter(ct);
1563 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1564 filtersList.append(filter);
1565 clipService.detach(*filter);
1567 filter = clipService.filter(ct);
1571 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1572 filter->set("kdenlive_ix", newPos);
1573 filtersList.append(filter);
1574 clipService.detach(*filter);
1576 filter = clipService.filter(ct);
1580 filter = clipService.filter(ct);
1582 int pos = QString(filter->get("kdenlive_ix")).toInt();
1583 if (pos >= newPos) {
1584 if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
1585 filtersList.append(filter);
1586 clipService.detach(*filter);
1588 filter = clipService.filter(ct);
1592 for (int i = 0; i < filtersList.count(); i++) {
1593 clipService.attach(*(filtersList.at(i)));
1596 m_isBlocked = false;
1600 void Render::mltResizeClipEnd(int track, GenTime pos, GenTime in, GenTime out) {
1603 Mlt::Service service(m_mltProducer->parent().get_service());
1605 Mlt::Tractor tractor(service);
1606 Mlt::Producer trackProducer(tractor.track(track));
1607 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1608 if (trackPlaylist.is_blank_at((int) pos.frames(m_fps) + 1))
1609 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1610 int clipIndex = trackPlaylist.get_clip_index_at((int) pos.frames(m_fps) + 1);
1611 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1612 int previousStart = trackPlaylist.clip_start(clipIndex);
1613 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1614 int newDuration = (int) out.frames(m_fps) - 1;
1615 trackPlaylist.resize_clip(clipIndex, (int) in.frames(m_fps), newDuration);
1616 trackPlaylist.consolidate_blanks(0);
1617 if (previousDuration < newDuration) {
1618 // clip was made longer, trim next blank if there is one.
1619 if (trackPlaylist.is_blank(clipIndex + 1)) {
1620 trackPlaylist.split(clipIndex + 1, newDuration - previousDuration);
1621 trackPlaylist.remove(clipIndex + 1);
1623 } else trackPlaylist.insert_blank(clipIndex + 1, previousDuration - newDuration - 1);
1625 trackPlaylist.consolidate_blanks(0);
1627 //tractor.multitrack()->refresh();
1628 //tractor.refresh();
1629 if (track != 0) mltCheckLength();
1630 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1631 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1632 mltDeleteTransparency(previousStart, track, QString(clip->parent().get("id")).toInt());
1634 info.startPos = pos;
1635 info.endPos = pos + out - in;
1637 mltAddClipTransparency(info, info.track - 1, QString(clip->parent().get("id")).toInt());
1639 m_isBlocked = false;
1642 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1643 Mlt::Service service(m_mltProducer->parent().get_service());
1644 Mlt::Tractor tractor(service);
1645 Mlt::Producer trackProducer(tractor.track(track));
1646 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1648 if (blind) trackProducer.set("hide", 3);
1649 else trackProducer.set("hide", 2);
1651 trackProducer.set("hide", 1);
1653 trackProducer.set("hide", 0);
1655 tractor.multitrack()->refresh();
1660 void Render::mltResizeClipStart(int track, GenTime pos, GenTime moveEnd, GenTime moveStart, GenTime in, GenTime out) {
1663 Mlt::Service service(m_mltProducer->parent().get_service());
1665 int moveFrame = (int)(moveEnd - moveStart).frames(m_fps);
1667 Mlt::Tractor tractor(service);
1668 Mlt::Producer trackProducer(tractor.track(track));
1669 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1670 if (trackPlaylist.is_blank_at((int) pos.frames(m_fps) - 1))
1671 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1672 int clipIndex = trackPlaylist.get_clip_index_at((int) pos.frames(m_fps) - 1);
1673 int previousStart = trackPlaylist.clip_start(clipIndex);
1674 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1675 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1676 trackPlaylist.resize_clip(clipIndex, (int) in.frames(m_fps), (int) out.frames(m_fps));
1677 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1679 int midpos = (int)moveStart.frames(m_fps) - 1; //+ (moveFrame / 2)
1680 int blankIndex = trackPlaylist.get_clip_index_at(midpos);
1681 int blankLength = trackPlaylist.clip_length(blankIndex);
1683 kDebug() << " + resizing blank: " << blankIndex << ", Mid: " << midpos << ", Length: " << blankLength << ", SIZE DIFF: " << moveFrame;
1685 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1686 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1688 trackPlaylist.consolidate_blanks(0);
1689 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1690 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
1691 mltDeleteTransparency(previousStart, track, QString(clip->parent().get("id")).toInt());
1693 info.startPos = moveEnd;
1694 info.endPos = moveEnd + out - in;
1696 mltAddClipTransparency(info, info.track - 1, QString(clip->parent().get("id")).toInt());
1698 m_isBlocked = false;
1701 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1702 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1706 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1709 m_mltConsumer->set("refresh", 0);
1710 mlt_service_lock(m_mltConsumer->get_service());
1711 Mlt::Service service(m_mltProducer->parent().get_service());
1712 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1714 Mlt::Tractor tractor(service);
1715 Mlt::Producer trackProducer(tractor.track(startTrack));
1716 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1717 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1718 if (endTrack == startTrack) {
1719 //mlt_service_lock(service.get_service());
1720 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1721 trackPlaylist.consolidate_blanks(0);
1723 if (!trackPlaylist.is_blank_at(moveEnd)) {
1724 // error, destination is not empty
1725 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
1726 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
1727 mlt_service_unlock(m_mltConsumer->get_service());
1728 m_isBlocked = false;
1731 trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1732 trackPlaylist.consolidate_blanks(0);
1733 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1734 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1737 //mlt_service_unlock(service.get_service());
1739 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1740 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1741 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
1742 // error, destination is not empty
1743 mlt_service_unlock(m_mltConsumer->get_service());
1744 m_isBlocked = false;
1747 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1748 trackPlaylist.consolidate_blanks(0);
1749 destTrackPlaylist.consolidate_blanks(1);
1750 destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1751 destTrackPlaylist.consolidate_blanks(0);
1752 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1753 kDebug() << "//////// moving clip transparency";
1754 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1759 mlt_service_unlock(m_mltConsumer->get_service());
1760 m_isBlocked = false;
1761 m_mltConsumer->set("refresh", 1);
1765 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1767 Mlt::Service service(m_mltProducer->parent().get_service());
1768 Mlt::Tractor tractor(service);
1769 Mlt::Field *field = tractor.field();
1771 mlt_service_lock(service.get_service());
1772 m_mltConsumer->set("refresh", 0);
1775 mlt_service serv = m_mltProducer->parent().get_service();
1776 mlt_service nextservice = mlt_service_get_producer(serv);
1777 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1778 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1779 QString resource = mlt_properties_get(properties, "mlt_service");
1780 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1782 int new_in = (int)newIn.frames(m_fps);
1783 int new_out = (int)newOut.frames(m_fps);
1785 while (mlt_type == "transition") {
1786 mlt_transition tr = (mlt_transition) nextservice;
1787 int currentTrack = mlt_transition_get_b_track(tr);
1788 int currentIn = (int) mlt_transition_get_in(tr);
1789 int currentOut = (int) mlt_transition_get_out(tr);
1791 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1792 mlt_transition_set_in_and_out(tr, new_in, new_out);
1793 if (newTrack - startTrack != 0) {
1794 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
1796 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1797 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
1798 mlt_properties_set_int(properties, "b_track", newTrack);
1799 //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);
1803 nextservice = mlt_service_producer(nextservice);
1804 if (nextservice == NULL) break;
1805 properties = MLT_SERVICE_PROPERTIES(nextservice);
1806 mlt_type = mlt_properties_get(properties, "mlt_type");
1807 resource = mlt_properties_get(properties, "mlt_service");
1809 m_isBlocked = false;
1810 mlt_service_unlock(service.get_service());
1811 m_mltConsumer->set("refresh", 1);
1814 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1815 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
1816 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
1818 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
1819 mltAddTransition(tag, a_track, b_track, in, out, xml);
1821 //mltSavePlaylist();
1824 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1827 Mlt::Service service(m_mltProducer->parent().get_service());
1828 Mlt::Tractor tractor(service);
1829 Mlt::Field *field = tractor.field();
1831 //m_mltConsumer->set("refresh", 0);
1832 mlt_service serv = m_mltProducer->parent().get_service();
1834 mlt_service nextservice = mlt_service_get_producer(serv);
1835 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1836 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1837 QString resource = mlt_properties_get(properties, "mlt_service");
1838 int in_pos = (int) in.frames(m_fps);
1839 int out_pos = (int) out.frames(m_fps);
1841 while (mlt_type == "transition") {
1842 mlt_transition tr = (mlt_transition) nextservice;
1843 int currentTrack = mlt_transition_get_b_track(tr);
1844 int currentIn = (int) mlt_transition_get_in(tr);
1845 int currentOut = (int) mlt_transition_get_out(tr);
1847 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
1849 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
1850 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
1851 QMap<QString, QString>::Iterator it;
1853 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
1855 for (it = map.begin(); it != map.end(); ++it) {
1857 char *name = decodedString(key);
1858 char *value = decodedString(it.value());
1859 mlt_properties_set(transproperties, name, value);
1860 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
1861 //filter->set("kdenlive_id", id);
1867 nextservice = mlt_service_producer(nextservice);
1868 if (nextservice == NULL) break;
1869 properties = MLT_SERVICE_PROPERTIES(nextservice);
1870 mlt_type = mlt_properties_get(properties, "mlt_type");
1871 resource = mlt_properties_get(properties, "mlt_service");
1873 m_isBlocked = false;
1874 m_mltConsumer->set("refresh", 1);
1877 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
1878 Mlt::Service service(m_mltProducer->parent().get_service());
1879 Mlt::Tractor tractor(service);
1880 Mlt::Field *field = tractor.field();
1882 if (do_refresh) m_mltConsumer->set("refresh", 0);
1883 mlt_service serv = m_mltProducer->parent().get_service();
1885 mlt_service nextservice = mlt_service_get_producer(serv);
1886 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1887 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1888 QString resource = mlt_properties_get(properties, "mlt_service");
1889 int old_pos = (int)((in + out).frames(m_fps) / 2);
1891 while (mlt_type == "transition") {
1892 mlt_transition tr = (mlt_transition) nextservice;
1893 int currentTrack = mlt_transition_get_b_track(tr);
1894 int currentIn = (int) mlt_transition_get_in(tr);
1895 int currentOut = (int) mlt_transition_get_out(tr);
1896 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
1898 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1899 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
1900 mlt_field_disconnect_service(field->get_field(), nextservice);
1903 nextservice = mlt_service_producer(nextservice);
1904 if (nextservice == NULL) break;
1905 properties = MLT_SERVICE_PROPERTIES(nextservice);
1906 mlt_type = mlt_properties_get(properties, "mlt_type");
1907 resource = mlt_properties_get(properties, "mlt_service");
1909 if (do_refresh) m_mltConsumer->set("refresh", 1);
1912 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
1913 QDomNodeList attribs = xml.elementsByTagName("parameter");
1914 QMap<QString, QString> map;
1915 for (int i = 0;i < attribs.count();i++) {
1916 QDomElement e = attribs.item(i).toElement();
1917 QString name = e.attribute("name");
1918 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
1919 map[name] = e.attribute("default");
1920 if (!e.attribute("value").isEmpty()) {
1921 map[name] = e.attribute("value");
1923 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
1924 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
1925 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
1928 if (e.attribute("namedesc").contains(";")) {
1929 QString format = e.attribute("format");
1930 QStringList separators = format.split("%d", QString::SkipEmptyParts);
1931 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
1933 QTextStream txtNeu(&neu);
1934 if (values.size() > 0)
1935 txtNeu << (int)values[0].toDouble();
1937 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
1938 txtNeu << separators[i];
1939 txtNeu << (int)(values[i+1].toDouble());
1941 if (i < separators.size())
1942 txtNeu << separators[i];
1943 map[e.attribute("name")] = neu;
1950 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
1951 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
1952 Mlt::Service service(m_mltProducer->parent().get_service());
1953 Mlt::Tractor tractor(service);
1954 Mlt::Field *field = tractor.field();
1956 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
1957 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
1958 transition->set("transparency", id);
1959 transition->set("fill", 1);
1960 transition->set("internal_added", 237);
1961 field->plant_transition(*transition, transitiontrack, info.track);
1965 void Render::mltDeleteTransparency(int pos, int track, int id) {
1966 Mlt::Service service(m_mltProducer->parent().get_service());
1967 Mlt::Tractor tractor(service);
1968 Mlt::Field *field = tractor.field();
1970 //if (do_refresh) m_mltConsumer->set("refresh", 0);
1971 mlt_service serv = m_mltProducer->parent().get_service();
1973 mlt_service nextservice = mlt_service_get_producer(serv);
1974 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1975 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1976 QString resource = mlt_properties_get(properties, "mlt_service");
1978 while (mlt_type == "transition") {
1979 mlt_transition tr = (mlt_transition) nextservice;
1980 int currentTrack = mlt_transition_get_b_track(tr);
1981 int currentIn = (int) mlt_transition_get_in(tr);
1982 int currentOut = (int) mlt_transition_get_out(tr);
1983 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
1984 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
1986 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
1987 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
1988 mlt_field_disconnect_service(field->get_field(), nextservice);
1991 nextservice = mlt_service_producer(nextservice);
1992 if (nextservice == NULL) break;
1993 properties = MLT_SERVICE_PROPERTIES(nextservice);
1994 mlt_type = mlt_properties_get(properties, "mlt_type");
1995 resource = mlt_properties_get(properties, "mlt_service");
1997 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2000 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2001 Mlt::Service service(m_mltProducer->parent().get_service());
2002 Mlt::Tractor tractor(service);
2003 Mlt::Field *field = tractor.field();
2005 mlt_service_lock(service.get_service());
2006 m_mltConsumer->set("refresh", 0);
2009 mlt_service serv = m_mltProducer->parent().get_service();
2010 mlt_service nextservice = mlt_service_get_producer(serv);
2011 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2012 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2013 QString resource = mlt_properties_get(properties, "mlt_service");
2014 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2015 while (mlt_type == "transition") {
2016 mlt_transition tr = (mlt_transition) nextservice;
2017 int currentTrack = mlt_transition_get_b_track(tr);
2018 int currentIn = (int) mlt_transition_get_in(tr);
2019 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2020 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2021 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2022 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2023 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2024 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2027 nextservice = mlt_service_producer(nextservice);
2028 if (nextservice == NULL) break;
2029 properties = MLT_SERVICE_PROPERTIES(nextservice);
2030 mlt_type = mlt_properties_get(properties, "mlt_type");
2031 resource = mlt_properties_get(properties, "mlt_service");
2033 m_isBlocked = false;
2034 mlt_service_unlock(service.get_service());
2035 m_mltConsumer->set("refresh", 1);
2039 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2040 Mlt::Service service(m_mltProducer->parent().get_service());
2041 Mlt::Tractor tractor(service);
2042 Mlt::Field *field = tractor.field();
2044 mlt_service_lock(service.get_service());
2045 m_mltConsumer->set("refresh", 0);
2048 mlt_service serv = m_mltProducer->parent().get_service();
2049 mlt_service nextservice = mlt_service_get_producer(serv);
2050 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2051 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2052 QString resource = mlt_properties_get(properties, "mlt_service");
2054 while (mlt_type == "transition") {
2055 mlt_transition tr = (mlt_transition) nextservice;
2056 int currentTrack = mlt_transition_get_b_track(tr);
2057 int currentaTrack = mlt_transition_get_a_track(tr);
2058 int currentIn = (int) mlt_transition_get_in(tr);
2059 int currentOut = (int) mlt_transition_get_out(tr);
2060 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2061 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2062 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2063 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2064 kDebug() << "//////MOVING";
2065 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2066 if (endTrack != startTrack) {
2067 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2068 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2069 mlt_properties_set_int(properties, "b_track", endTrack);
2073 nextservice = mlt_service_producer(nextservice);
2074 if (nextservice == NULL) break;
2075 properties = MLT_SERVICE_PROPERTIES(nextservice);
2076 mlt_type = mlt_properties_get(properties, "mlt_type");
2077 resource = mlt_properties_get(properties, "mlt_service");
2079 m_isBlocked = false;
2080 mlt_service_unlock(service.get_service());
2081 m_mltConsumer->set("refresh", 1);
2085 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2087 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2088 Mlt::Service service(m_mltProducer->parent().get_service());
2090 Mlt::Tractor tractor(service);
2091 Mlt::Field *field = tractor.field();
2093 char *transId = decodedString(tag);
2094 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2095 if (out != GenTime())
2096 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
2097 QMap<QString, QString>::Iterator it;
2100 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2102 for (it = args.begin(); it != args.end(); ++it) {
2104 char *name = decodedString(key);
2105 char *value = decodedString(it.value());
2106 transition->set(name, value);
2107 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2108 //filter->set("kdenlive_id", id);
2112 // attach filter to the clip
2113 field->plant_transition(*transition, a_track, b_track);
2118 void Render::mltSavePlaylist() {
2119 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2120 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2121 fileConsumer.set("resource", "/tmp/playlist.westley");
2123 Mlt::Service service(m_mltProducer->get_service());
2125 fileConsumer.connect(service);
2126 fileConsumer.start();
2130 #include "renderer.moc"