1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
25 // ffmpeg Header files
35 #include <QApplication>
39 #include <KStandardDirs>
40 #include <KMessageBox>
42 #include <KTemporaryFile>
45 #include "kdenlivesettings.h"
47 #include "definitions.h"
49 #include <mlt++/Mlt.h>
51 #if LIBAVCODEC_VERSION_MAJOR > 51 || (LIBAVCODEC_VERSION_MAJOR > 50 && LIBAVCODEC_VERSION_MINOR > 54)
52 // long_name was added in FFmpeg avcodec version 51.55
53 #define ENABLE_FFMPEG_CODEC_DESCRIPTION 1
58 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
59 // detect if the producer has finished playing. Is there a better way to do it ?
60 if (self->m_isBlocked) return;
61 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
62 self->emitConsumerStopped();
64 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
68 Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid), m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false), m_isZoneMode(false), m_isLoopMode(false) {
69 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
70 refreshTimer = new QTimer(this);
71 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
73 /*if (rendererName == "project") m_monitorId = 10000;
74 else m_monitorId = 10001;*/
75 osdTimer = new QTimer(this);
76 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
78 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
81 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black");
82 m_mltProducer = producer;
83 if (m_blackClip) delete m_blackClip;
84 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
85 m_blackClip->set("id", "black");
86 m_mltConsumer->connect(*m_mltProducer);
87 m_mltProducer->set_speed(0.0);
95 void Render::closeMlt() {
101 delete m_mltProducer;
102 if (m_blackClip) delete m_blackClip;
107 void Render::buildConsumer() {
109 tmp = decodedString(KdenliveSettings::current_profile());
110 m_mltProfile = new Mlt::Profile(tmp);
114 QString videoDriver = KdenliveSettings::videodrivername();
115 if (!videoDriver.isEmpty()) {
116 if (videoDriver == "x11_noaccel") {
117 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
120 unsetenv("SDL_VIDEO_YUV_HWACCEL");
123 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
125 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
126 m_mltConsumer->set("resize", 1);
127 m_mltConsumer->set("window_id", m_winid);
128 m_mltConsumer->set("terminate_on_pause", 1);
129 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
130 m_mltConsumer->set("rescale", "nearest");
132 QString audioDevice = KdenliveSettings::audiodevicename();
133 if (!audioDevice.isEmpty()) {
134 tmp = decodedString(audioDevice);
135 m_mltConsumer->set("audio_device", tmp);
139 if (!videoDriver.isEmpty()) {
140 tmp = decodedString(videoDriver);
141 m_mltConsumer->set("video_driver", tmp);
145 QString audioDriver = KdenliveSettings::audiodrivername();
146 if (!audioDriver.isEmpty()) {
147 tmp = decodedString(audioDriver);
148 m_mltConsumer->set("audio_driver", tmp);
153 m_mltConsumer->set("progressive", 1);
154 m_mltConsumer->set("audio_buffer", 1024);
155 m_mltConsumer->set("frequency", 48000);
158 int Render::resetProfile() {
159 if (!m_mltConsumer) return 0;
160 QString currentProfile = getenv("MLT_PROFILE");
161 if (currentProfile == KdenliveSettings::current_profile()) {
162 kDebug() << "reset to same profile, nothing to do";
165 if (m_isSplitView) slotSplitView(false);
166 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
167 m_mltConsumer->purge();
168 delete m_mltConsumer;
169 m_mltConsumer = NULL;
170 QString scene = sceneList();
171 if (m_mltProducer) delete m_mltProducer;
172 m_mltProducer = NULL;
173 if (m_mltProfile) delete m_mltProfile;
177 kDebug() << "//RESET WITHSCENE: " << scene;
180 char *tmp = decodedString(scene);
181 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
183 m_mltProducer = producer;
184 if (m_blackClip) delete m_blackClip;
185 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
186 m_mltProducer->optimise();
187 m_mltProducer->set_speed(0);
190 //delete m_mltProfile;
191 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
192 //mlt_profile prof = m_mltProfile->get_profile();
193 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
194 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
195 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
196 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
198 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
203 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
204 void Render::seek(GenTime time) {
208 m_mltProducer->seek((int)(time.frames(m_fps)));
213 char *Render::decodedString(QString str) {
214 /*QCString fn = QFile::encodeName(str);
215 char *t = new char[fn.length() + 1];
216 strcpy(t, (const char *)fn);*/
218 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
222 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
223 QPixmap pix(width, height);
225 mlt_image_format format = mlt_image_rgb24a;
226 uint8_t *thumb = frame->get_image(format, width, height);
227 QImage image(thumb, width, height, QImage::Format_ARGB32);
229 if (!image.isNull()) {
230 pix = pix.fromImage(image);
232 QPainter painter(&pix);
233 painter.drawRect(0, 0, width - 1, height - 1);
235 } else pix.fill(Qt::black);
239 const int Render::renderWidth() const {
240 return (int)(m_mltProfile->height() * m_mltProfile->dar());
243 const int Render::renderHeight() const {
244 return m_mltProfile->height();
247 QPixmap Render::extractFrame(int frame_position, int width, int height) {
249 width = renderWidth();
250 height = renderHeight();
252 QPixmap pix(width, height);
253 if (!m_mltProducer) {
257 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
260 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
263 if (url.fileName().startsWith(".all.")) { // check for slideshow
264 QString fileType = url.fileName().right(3);
266 QStringList::Iterator it;
268 QDir dir(url.directory());
270 filter << "*." + fileType;
271 filter << "*." + fileType.toUpper();
272 more = dir.entryList(filter, QDir::Files);
273 im.load(url.directory() + "/" + more.at(0));
274 } else im.load(url.path());
275 //pixmap = im.scaled(width, height);
280 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
281 QPixmap pix(width, height);
282 char *tmp = decodedString(file);
283 Mlt::Profile *prof = new Mlt::Profile(profile);
284 Mlt::Producer m_producer(*prof, tmp);
286 if (m_producer.is_blank()) {
291 Mlt::Filter m_convert(*prof, "avcolour_space");
292 m_convert.set("forced", mlt_image_rgb24a);
293 m_producer.attach(m_convert);
294 m_producer.seek(frame_position);
295 Mlt::Frame * frame = m_producer.get_frame();
297 pix = frameThumbnail(frame, width, height, true);
300 if (prof) delete prof;
305 void Render::getImage(KUrl url, int frame_position, QPoint size)
307 char *tmp = decodedString(url.path());
308 Mlt::Producer m_producer(tmp);
310 if (m_producer.is_blank()) {
313 Mlt::Filter m_convert("avcolour_space");
314 m_convert.set("forced", mlt_image_rgb24a);
315 m_producer.attach(m_convert);
316 m_producer.seek(frame_position);
318 Mlt::Frame * frame = m_producer.get_frame();
321 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
323 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
327 /* Create thumbnail for color */
328 /*void Render::getImage(int id, QString color, QPoint size)
330 QPixmap pixmap(size.x() - 2, size.y() - 2);
331 color = color.replace(0, 2, "#");
332 color = color.left(7);
333 pixmap.fill(QColor(color));
334 QPixmap result(size.x(), size.y());
335 result.fill(Qt::black);
336 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
337 emit replyGetImage(id, result, size.x(), size.y());
341 /* Create thumbnail for image */
342 /*void Render::getImage(KUrl url, QPoint size)
346 if (url.fileName().startsWith(".all.")) { // check for slideshow
347 QString fileType = url.fileName().right(3);
349 QStringList::Iterator it;
351 QDir dir( url.directory() );
352 more = dir.entryList( QDir::Files );
353 for ( it = more.begin() ; it != more.end() ; ++it ) {
354 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
355 if (!im.load(url.directory() + "/" + *it))
356 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
361 else im.load(url.path());
363 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
364 QPixmap result(size.x(), size.y());
365 result.fill(Qt::black);
366 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
367 emit replyGetImage(url, 1, result, size.x(), size.y());
371 double Render::consumerRatio() const {
372 if (!m_mltConsumer) return 1.0;
373 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
377 int Render::getLength() {
380 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
381 return mlt_producer_get_playtime(m_mltProducer->get_producer());
386 bool Render::isValid(KUrl url) {
387 char *tmp = decodedString(url.path());
388 Mlt::Producer producer(*m_mltProfile, tmp);
390 if (producer.is_blank())
396 const double Render::dar() const {
397 return m_mltProfile->dar();
400 void Render::slotSplitView(bool doit) {
401 m_isSplitView = doit;
402 Mlt::Service service(m_mltProducer->parent().get_service());
403 Mlt::Tractor tractor(service);
404 if (service.type() != tractor_type || tractor.count() < 2) return;
405 Mlt::Field *field = tractor.field();
408 for (int i = 1; i < tractor.count() && screen < 4; i++) {
409 Mlt::Producer trackProducer(tractor.track(i));
410 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
411 if (QString(trackProducer.get("hide")).toInt() != 1) {
412 kDebug() << "// ADIDNG TRACK: " << i;
413 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
414 transition->set("mlt_service", "composite");
415 transition->set("a_track", 0);
416 transition->set("b_track", i);
417 transition->set("distort", 1);
418 transition->set("internal_added", "200");
425 tmp = "50%,0:50%x50%";
428 tmp = "0,50%:50%x50%";
431 tmp = "50%,50%:50%x50%";
434 transition->set("geometry", tmp);
435 transition->set("always_active", "1");
436 field->plant_transition(*transition, 0, i);
441 m_mltConsumer->set("refresh", 1);
443 mlt_service serv = m_mltProducer->parent().get_service();
444 mlt_service nextservice = mlt_service_get_producer(serv);
445 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
446 QString mlt_type = mlt_properties_get(properties, "mlt_type");
447 QString resource = mlt_properties_get(properties, "mlt_service");
449 while (mlt_type == "transition") {
450 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
451 if (added == "200") {
452 mlt_field_disconnect_service(field->get_field(), nextservice);
454 nextservice = mlt_service_producer(nextservice);
455 if (nextservice == NULL) break;
456 properties = MLT_SERVICE_PROPERTIES(nextservice);
457 mlt_type = mlt_properties_get(properties, "mlt_type");
458 resource = mlt_properties_get(properties, "mlt_service");
459 m_mltConsumer->set("refresh", 1);
464 void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
466 int width = (int)(height * m_mltProfile->dar());
467 QMap < QString, QString > filePropertyMap;
468 QMap < QString, QString > metadataPropertyMap;
470 KUrl url = KUrl(xml.attribute("resource", QString::null));
471 Mlt::Producer *producer;
472 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
475 if (xml.attribute("type").toInt() == COLOR) {
476 char *tmp = decodedString("colour:" + xml.attribute("colour"));
477 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
479 } else if (url.isEmpty()) {
481 QDomElement westley = doc.createElement("westley");
482 QDomElement play = doc.createElement("playlist");
483 doc.appendChild(westley);
484 westley.appendChild(play);
485 play.appendChild(doc.importNode(xml, true));
486 char *tmp = decodedString(doc.toString());
487 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
490 QString urlpath = url.path();
491 /*if (urlpath.contains(':')) {
492 if (!urlpath.startsWith("file:")) urlpath.prepend("file:");
493 char *tmp = decodedString(urlpath);
494 producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp);
498 char *tmp = decodedString(urlpath);
499 producer = new Mlt::Producer(*m_mltProfile, tmp);
503 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
505 if (producer->is_blank()) {
506 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
507 emit removeInvalidClip(clipId);
510 char *tmp = decodedString(clipId);
511 producer->set("id", tmp);
513 int frameNumber = xml.attribute("thumbnail", "0").toInt();
514 if (frameNumber != 0) producer->seek(frameNumber);
515 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
517 filePropertyMap["duration"] = QString::number(producer->get_playtime());
518 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
520 Mlt::Frame * frame = producer->get_frame();
522 if (xml.attribute("type").toInt() == SLIDESHOW) {
523 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
524 if (xml.attribute("fade") == "1") {
525 // user wants a fade effect to slideshow
526 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
527 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
528 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
529 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
530 char *tmp = decodedString(xml.attribute("luma_file"));
531 filter->set("luma.resource", tmp);
533 if (xml.hasAttribute("softness")) {
534 int soft = xml.attribute("softness").toInt();
535 filter->set("luma.softness", (double) soft / 100.0);
538 Mlt::Service clipService(producer->get_service());
539 clipService.attach(*filter);
544 filePropertyMap["fps"] = producer->get("source_fps");
546 if (frame && frame->is_valid()) {
547 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
548 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
549 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
550 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
552 if (frame->get_int("test_image") == 0) {
553 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
554 filePropertyMap["type"] = "playlist";
555 metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer->get_service()), "title"));
556 } else if (frame->get_int("test_audio") == 0)
557 filePropertyMap["type"] = "av";
559 filePropertyMap["type"] = "video";
561 mlt_image_format format = mlt_image_yuv422;
563 int frame_height = 0;
564 //frame->set("rescale.interp", "hyper");
565 frame->set("normalised_height", height);
566 frame->set("normalised_width", width);
567 QPixmap pix(width, height);
569 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
570 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
571 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
572 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
574 if (!image.isNull()) {
575 pix = QPixmap::fromImage(image.rgbSwapped());
579 mlt_pool_release(new_image);
580 emit replyGetImage(clipId, 0, pix, width, height);
582 } else if (frame->get_int("test_audio") == 0) {
583 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
584 emit replyGetImage(clipId, 0, pixmap, width, height);
585 filePropertyMap["type"] = "audio";
589 // Retrieve audio / video codec name
591 // Fetch the video_context
594 AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
595 if (context != NULL) {
596 /*if (context->duration == AV_NOPTS_VALUE) {
597 kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
598 emit removeInvalidClip(clipId);
601 // Get the video_index
602 int index = mlt_properties_get_int(properties, "video_index");
604 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
605 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) {
606 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name;
609 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) {
610 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
612 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
613 context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
614 if (context != NULL) {
615 // Get the audio_index
616 int index = mlt_properties_get_int(properties, "audio_index");
618 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
619 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
620 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name;
623 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
624 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
629 mlt_properties metadata = mlt_properties_new();
630 mlt_properties_pass(metadata, properties, "meta.attr.");
631 int count = mlt_properties_count(metadata);
632 for (int i = 0; i < count; i ++) {
633 QString name = mlt_properties_get_name(metadata, i);
634 QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
635 if (name.endsWith("markup") && !value.isEmpty())
636 metadataPropertyMap[ name.section(".", 0, -2)] = value;
639 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
640 kDebug() << "REquested fuile info for: " << url.path();
641 if (frame) delete frame;
642 //if (producer) delete producer;
645 /** Create the producer from the Westley QDomDocument */
647 void Render::initSceneList() {
648 kDebug() << "-------- INIT SCENE LIST ------_";
650 QDomElement westley = doc.createElement("westley");
651 doc.appendChild(westley);
652 QDomElement prod = doc.createElement("producer");
653 prod.setAttribute("resource", "colour");
654 prod.setAttribute("colour", "red");
655 prod.setAttribute("id", "black");
656 prod.setAttribute("in", "0");
657 prod.setAttribute("out", "0");
659 QDomElement tractor = doc.createElement("tractor");
660 QDomElement multitrack = doc.createElement("multitrack");
662 QDomElement playlist1 = doc.createElement("playlist");
663 playlist1.appendChild(prod);
664 multitrack.appendChild(playlist1);
665 QDomElement playlist2 = doc.createElement("playlist");
666 multitrack.appendChild(playlist2);
667 QDomElement playlist3 = doc.createElement("playlist");
668 multitrack.appendChild(playlist3);
669 QDomElement playlist4 = doc.createElement("playlist");
670 multitrack.appendChild(playlist4);
671 QDomElement playlist5 = doc.createElement("playlist");
672 multitrack.appendChild(playlist5);
673 tractor.appendChild(multitrack);
674 westley.appendChild(tractor);
675 // kDebug()<<doc.toString();
677 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
678 setSceneList(doc, 0);
684 /** Create the producer from the Westley QDomDocument */
685 void Render::setProducer(Mlt::Producer *producer, int position) {
686 if (m_winid == -1) return;
689 m_mltConsumer->stop();
694 m_mltProducer->set_speed(0);
695 delete m_mltProducer;
696 m_mltProducer = NULL;
699 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
700 else m_mltProducer = new Mlt::Producer();
701 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
703 m_fps = m_mltProducer->get_fps();
705 if (position != -1) {
706 m_mltProducer->seek(position);
707 emit rendererPosition(position);
714 /** Create the producer from the Westley QDomDocument */
715 void Render::setSceneList(QDomDocument list, int position) {
716 setSceneList(list.toString(), position);
719 /** Create the producer from the Westley QDomDocument */
720 void Render::setSceneList(QString playlist, int position) {
721 if (m_winid == -1) return;
724 kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
727 m_mltConsumer->stop();
728 //m_mltConsumer->set("refresh", 0);
732 m_mltProducer->set_speed(0);
733 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
735 delete m_mltProducer;
736 m_mltProducer = NULL;
740 char *tmp = decodedString(playlist);
741 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
743 if (m_blackClip) delete m_blackClip;
744 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
745 m_blackClip->set("id", "black");
746 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
747 m_mltProducer->optimise();
749 /*if (KdenliveSettings::osdtimecode()) {
750 // Attach filter for on screen display of timecode
752 QString attr = "attr_check";
753 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
754 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
755 mlt_producer_attach( m_mltProducer->get_producer(), filter );
756 mlt_filter_close( filter );
758 m_osdInfo = new Mlt::Filter("data_show");
759 tmp = decodedString(m_osdProfile);
760 m_osdInfo->set("resource", tmp);
762 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
763 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
764 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
765 m_osdInfo->set("dynamic", "1");
767 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
769 m_osdInfo->set("dynamic", "0");
772 m_fps = m_mltProducer->get_fps();
773 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
776 //TODO: seek to correct place after opening project.
777 // Needs to be done from another place since it crashes here.
778 //m_mltProducer->seek(position);
779 //emit rendererPosition(position);
785 /** Create the producer from the Westley QDomDocument */
786 QString Render::sceneList() {
791 saveSceneList(temp.fileName());
792 QFile file(temp.fileName());
793 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
794 kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE";
797 QTextStream in(&file);
798 while (!in.atEnd()) {
799 result.append(in.readLine());
805 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
807 char *tmppath = decodedString("westley:" + path);
808 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
809 m_mltProducer->optimise();
811 westleyConsumer.set("terminate_on_pause", 1);
812 Mlt::Producer prod(m_mltProducer->get_producer());
813 bool split = m_isSplitView;
814 if (split) slotSplitView(false);
815 westleyConsumer.connect(prod);
816 //prod.set("title", "kdenlive document");
817 westleyConsumer.start();
818 while (!westleyConsumer.is_stopped()) {}
819 if (!kdenliveData.isNull()) {
820 // add Kdenlive specific tags
823 doc.setContent(&file, false);
824 QDomNode wes = doc.elementsByTagName("westley").at(0);
825 wes.appendChild(doc.importNode(kdenliveData, true));
827 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
828 kWarning() << "////// ERROR writing to file: " << path;
831 QTextStream out(&file);
832 out << doc.toString();
835 if (split) slotSplitView(true);
839 void Render::saveZone(KUrl url, QString desc, QPoint zone) {
840 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
841 char *tmppath = decodedString("westley:" + url.path());
842 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
843 m_mltProducer->optimise();
845 westleyConsumer.set("terminate_on_pause", 1);
846 if (m_name == "clip") {
847 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
848 tmppath = decodedString(desc);
850 list.insert_at(0, prod, 0);
851 list.set("title", tmppath);
853 westleyConsumer.connect(list);
856 //TODO: not working yet, save zone from timeline
857 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
858 /* Mlt::Service service(p1->parent().get_service());
859 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
861 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
862 tmppath = decodedString(desc);
863 //prod->set("title", tmppath);
865 westleyConsumer.connect(*p1); //list);
868 westleyConsumer.start();
871 const double Render::fps() const {
875 void Render::connectPlaylist() {
876 if (!m_mltConsumer) return;
877 //m_mltConsumer->set("refresh", "0");
878 m_mltConsumer->connect(*m_mltProducer);
879 m_mltProducer->set_speed(0);
880 m_mltConsumer->start();
881 emit durationChanged(m_mltProducer->get_playtime());
884 if (m_mltConsumer->start() == -1) {
885 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."));
886 m_mltConsumer = NULL;
893 void Render::refreshDisplay() {
895 if (!m_mltProducer) return;
896 //m_mltConsumer->set("refresh", 0);
898 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
899 /*if (KdenliveSettings::osdtimecode()) {
900 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
901 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
902 m_osdInfo->set("dynamic", "1");
903 m_mltProducer->attach(*m_osdInfo);
906 m_mltProducer->detach(*m_osdInfo);
907 m_osdInfo->set("dynamic", "0");
912 void Render::setVolume(double volume) {
913 if (!m_mltConsumer || !m_mltProducer) return;
915 m_mltConsumer->set("refresh", 0);
916 // Attach filter for on screen display of timecode
917 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
918 mlt_properties_set_double( properties, "meta.volume", volume );
919 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
920 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
922 if (!KdenliveSettings::osdtimecode()) {
923 m_mltProducer->detach(*m_osdInfo);
924 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
925 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
928 osdTimer->setSingleShot(2500);
931 void Render::slotOsdTimeout() {
932 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
933 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
934 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
935 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
939 void Render::start() {
940 kDebug() << "----- STARTING MONITOR: " << m_name;
942 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
946 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
947 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
948 if (m_mltConsumer->start() == -1) {
949 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."));
950 m_mltConsumer = NULL;
953 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
961 void Render::clear() {
962 kDebug() << " ********* RENDER CLEAR";
964 //m_mltConsumer->set("refresh", 0);
965 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
969 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
970 m_mltProducer->set_speed(0.0);
971 delete m_mltProducer;
972 m_mltProducer = NULL;
977 void Render::stop() {
978 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
979 kDebug() << "///////////// RENDER STOPPED: " << m_name;
981 m_mltConsumer->set("refresh", 0);
982 m_mltConsumer->stop();
983 // delete m_mltConsumer;
984 // m_mltConsumer = NULL;
986 kDebug() << "///////////// RENDER STOP2-------";
990 if (m_isZoneMode) resetZoneMode();
991 m_mltProducer->set_speed(0.0);
992 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
993 //kDebug() << m_mltProducer->get_length();
995 kDebug() << "///////////// RENDER STOP3-------";
998 void Render::stop(const GenTime & startTime) {
1000 kDebug() << "///////////// RENDER STOP-------2";
1001 if (m_mltProducer) {
1002 if (m_isZoneMode) resetZoneMode();
1003 m_mltProducer->set_speed(0.0);
1004 m_mltProducer->seek((int) startTime.frames(m_fps));
1006 m_mltConsumer->purge();
1009 void Render::pause() {
1010 if (!m_mltProducer || !m_mltConsumer)
1012 if (m_mltProducer->get_speed() == 0.0) return;
1013 if (m_isZoneMode) resetZoneMode();
1015 m_mltConsumer->set("refresh", 0);
1016 m_mltProducer->set_speed(0.0);
1017 emit rendererPosition(m_framePosition);
1018 m_mltProducer->seek(m_framePosition);
1019 m_mltConsumer->purge();
1022 void Render::switchPlay() {
1023 if (!m_mltProducer || !m_mltConsumer)
1025 if (m_isZoneMode) resetZoneMode();
1026 if (m_mltProducer->get_speed() == 0.0) {
1027 m_isBlocked = false;
1028 m_mltProducer->set_speed(1.0);
1029 m_mltConsumer->set("refresh", 1);
1032 m_mltConsumer->set("refresh", 0);
1033 m_mltProducer->set_speed(0.0);
1034 emit rendererPosition(m_framePosition);
1035 m_mltProducer->seek(m_framePosition);
1036 m_mltConsumer->purge();
1037 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1038 //m_mltConsumer->set("refresh", 0);
1039 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1040 m_mltProducer->set_speed(0);
1041 m_mltProducer->seek( position );
1042 //m_mltProducer->seek((int) m_framePosition);
1043 m_isBlocked = false;*/
1045 /*if (speed == 0.0) {
1046 m_mltProducer->seek((int) m_framePosition + 1);
1047 m_mltConsumer->purge();
1052 void Render::play(double speed) {
1055 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1056 m_isBlocked = false;
1057 m_mltProducer->set_speed(speed);
1058 /*if (speed == 0.0) {
1059 m_mltProducer->seek((int) m_framePosition + 1);
1060 m_mltConsumer->purge();
1065 void Render::play(const GenTime & startTime) {
1066 if (!m_mltProducer || !m_mltConsumer)
1068 m_isBlocked = false;
1069 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1070 m_mltProducer->set_speed(1.0);
1071 m_mltConsumer->set("refresh", 1);
1074 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1075 if (!m_mltProducer || !m_mltConsumer)
1077 //m_mltProducer->set("eof", "loop");
1078 m_isLoopMode = true;
1079 m_loopStart = startTime;
1080 playZone(startTime, stopTime);
1083 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1084 if (!m_mltProducer || !m_mltConsumer)
1086 m_isBlocked = false;
1087 m_mltProducer->set("out", stopTime.frames(m_fps));
1088 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1089 m_mltProducer->set_speed(1.0);
1090 m_mltConsumer->set("refresh", 1);
1091 m_isZoneMode = true;
1094 void Render::resetZoneMode() {
1095 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1096 //m_mltProducer->set("eof", "pause");
1097 m_isZoneMode = false;
1098 m_isLoopMode = false;
1101 void Render::seekToFrame(int pos) {
1102 //kDebug()<<" ********* RENDER SEEK TO POS";
1105 m_isBlocked = false;
1107 m_mltProducer->seek(pos);
1111 void Render::askForRefresh() {
1112 // Use a Timer so that we don't refresh too much
1113 refreshTimer->start(200);
1116 void Render::doRefresh() {
1117 // Use a Timer so that we don't refresh too much
1118 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1121 void Render::refresh() {
1122 if (!m_mltProducer || m_isBlocked)
1124 refreshTimer->stop();
1125 if (m_mltConsumer) {
1126 m_mltConsumer->set("refresh", 1);
1130 double Render::playSpeed() {
1131 if (m_mltProducer) return m_mltProducer->get_speed();
1135 GenTime Render::seekPosition() const {
1136 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1137 else return GenTime();
1141 const QString & Render::rendererName() const {
1146 void Render::emitFrameNumber(double position) {
1147 m_framePosition = position;
1148 emit rendererPosition((int) position);
1149 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1152 void Render::emitConsumerStopped() {
1153 // This is used to know when the playing stopped
1154 if (m_mltProducer) {
1155 double pos = m_mltProducer->position();
1156 if (m_isLoopMode) play(m_loopStart);
1157 else if (m_isZoneMode) resetZoneMode();
1158 emit rendererStopped((int) pos);
1159 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1160 //new QCustomEvent(10002));
1166 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1167 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1171 void Render::exportCurrentFrame(KUrl url, bool notify) {
1172 if (!m_mltProducer) {
1173 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1177 int height = 1080;//KdenliveSettings::defaultheight();
1178 int width = 1940; //KdenliveSettings::displaywidth();
1180 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1182 QPixmap pix(width, height);
1183 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1184 m_convert.set("forced", mlt_image_rgb24a);
1185 m_mltProducer->attach(m_convert);
1186 Mlt::Frame * frame = m_mltProducer->get_frame();
1187 m_mltProducer->detach(m_convert);
1189 pix = frameThumbnail(frame, width, height);
1192 pix.save(url.path(), "PNG");
1193 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1196 /** MLT PLAYLIST DIRECT MANIPULATON **/
1199 void Render::mltCheckLength(bool reload) {
1200 //kDebug()<<"checking track length: "<<track<<"..........";
1202 Mlt::Service service(m_mltProducer->get_service());
1203 Mlt::Tractor tractor(service);
1205 int trackNb = tractor.count();
1206 double duration = 0;
1207 double trackDuration;
1209 Mlt::Producer trackProducer(tractor.track(0));
1210 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1211 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1212 m_mltProducer->set("out", duration);
1213 emit durationChanged((int) duration);
1216 while (trackNb > 1) {
1217 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1218 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1219 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1221 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1222 if (trackDuration > duration) duration = trackDuration;
1226 Mlt::Producer blackTrackProducer(tractor.track(0));
1227 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1228 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1230 if (blackDuration != duration) {
1231 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1233 int dur = (int)duration;
1235 QDomElement black = doc.createElement("producer");
1236 black.setAttribute("mlt_service", "colour");
1237 black.setAttribute("colour", "black");
1238 black.setAttribute("id", "black");
1241 while (dur > 14000) {
1242 info.startPos = GenTime(i * 14000, m_fps);
1243 info.endPos = info.startPos + GenTime(13999, m_fps);
1244 mltInsertClip(info, black, m_blackClip);
1249 info.startPos = GenTime(i * 14000, m_fps);
1250 info.endPos = info.startPos + GenTime(dur, m_fps);
1251 mltInsertClip(info, black, m_blackClip);
1253 m_mltProducer->set("out", duration);
1254 emit durationChanged((int)duration);
1258 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1259 if (!m_mltProducer) {
1260 kDebug() << "PLAYLIST NOT INITIALISED //////";
1263 Mlt::Producer parentProd(m_mltProducer->parent());
1264 if (parentProd.get_producer() == NULL) {
1265 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1269 Mlt::Service service(parentProd.get_service());
1270 Mlt::Tractor tractor(service);
1271 mlt_service_lock(service.get_service());
1272 Mlt::Producer trackProducer(tractor.track(info.track));
1273 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1274 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1275 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1276 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1278 if (QString(prod->get("transparency")).toInt() == 1)
1279 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());
1281 mlt_service_unlock(service.get_service());
1283 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1284 //tractor.multitrack()->refresh();
1285 //tractor.refresh();
1289 void Render::mltCutClip(int track, GenTime position) {
1293 Mlt::Service service(m_mltProducer->parent().get_service());
1294 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1296 Mlt::Tractor tractor(service);
1297 Mlt::Producer trackProducer(tractor.track(track));
1298 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1301 /* // Display playlist info
1302 kDebug()<<"//////////// BEFORE";
1303 for (int i = 0; i < trackPlaylist.count(); i++) {
1304 int blankStart = trackPlaylist.clip_start(i);
1305 int blankDuration = trackPlaylist.clip_length(i) - 1;
1307 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1308 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1311 int cutPos = (int) position.frames(m_fps);
1313 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1314 if (trackPlaylist.is_blank(clipIndex)) {
1315 kDebug() << "// WARMNING, TRYING TO CUT A BLANK";
1316 m_isBlocked = false;
1319 mlt_service_lock(service.get_service());
1320 int clipStart = trackPlaylist.clip_start(clipIndex);
1321 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1323 // duplicate effects
1324 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1325 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1327 if (original == NULL || clip == NULL) {
1328 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1330 Mlt::Service clipService(original->get_service());
1331 Mlt::Service dupService(clip->get_service());
1333 Mlt::Filter *filter = clipService.filter(ct);
1335 if (filter->get("kdenlive_id") != "") {
1336 kDebug() << "++ ADDING FILTER: " << filter->get("kdenlive_id");
1337 Mlt::Filter *dup = new Mlt::Filter(filter->get_filter());
1338 dup->set("kdenlive_ix", filter->get("kdenlive_ix"));
1339 dup->set("kdenlive_id", filter->get("kdenlive_id"));
1340 dupService.attach(*dup);
1343 filter = clipService.filter(ct);
1345 mlt_service_unlock(service.get_service());
1347 /* // Display playlist info
1348 kDebug()<<"//////////// AFTER";
1349 for (int i = 0; i < trackPlaylist.count(); i++) {
1350 int blankStart = trackPlaylist.clip_start(i);
1351 int blankDuration = trackPlaylist.clip_length(i) - 1;
1353 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1354 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1357 m_isBlocked = false;
1360 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1362 mltRemoveClip(info.track, info.startPos);
1363 mltInsertClip(info, element, prod);
1367 bool Render::mltRemoveClip(int track, GenTime position) {
1368 Mlt::Service service(m_mltProducer->parent().get_service());
1369 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1371 Mlt::Tractor tractor(service);
1372 Mlt::Producer trackProducer(tractor.track(track));
1373 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1374 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1376 /* // Display playlist info
1377 kDebug()<<"//// BEFORE";
1378 for (int i = 0; i < trackPlaylist.count(); i++) {
1379 int blankStart = trackPlaylist.clip_start(i);
1380 int blankDuration = trackPlaylist.clip_length(i) - 1;
1382 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1383 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1386 if (trackPlaylist.is_blank(clipIndex)) {
1387 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1391 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1392 trackPlaylist.replace_with_blank(clipIndex);
1393 trackPlaylist.consolidate_blanks(0);
1394 if (QString(clip.parent().get("transparency")).toInt() == 1)
1395 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());
1397 /* // Display playlist info
1398 kDebug()<<"//// AFTER";
1399 for (int i = 0; i < trackPlaylist.count(); i++) {
1400 int blankStart = trackPlaylist.clip_start(i);
1401 int blankDuration = trackPlaylist.clip_length(i) - 1;
1403 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1404 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1407 if (track != 0 && trackPlaylist.count() > clipIndex) mltCheckLength();
1408 m_isBlocked = false;
1412 int Render::mltChangeClipSpeed(ItemInfo info, double speed, Mlt::Producer *prod) {
1415 Mlt::Service service(m_mltProducer->parent().get_service());
1416 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1417 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1418 Mlt::Tractor tractor(service);
1419 Mlt::Producer trackProducer(tractor.track(info.track));
1420 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1421 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1422 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1423 QString serv = clip.parent().get("mlt_service");
1424 QString id = clip.parent().get("id");
1425 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1426 if (serv == "avformat" && speed != 1.0) {
1427 mlt_service_lock(service.get_service());
1428 QString url = clip.parent().get("resource");
1429 url.append("?" + QString::number(speed));
1430 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1431 if (!slowprod || slowprod->get_producer() == NULL) {
1432 char *tmp = decodedString(url);
1433 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1435 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1436 tmp = decodedString(producerid);
1437 slowprod->set("id", tmp);
1439 m_slowmotionProducers.insert(url, slowprod);
1441 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1442 newLength = cut->get_length();
1443 trackPlaylist.replace_with_blank(clipIndex);
1444 trackPlaylist.consolidate_blanks(0);
1445 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1446 mlt_service_unlock(service.get_service());
1447 } else if (speed == 1.0) {
1448 mlt_service_lock(service.get_service());
1449 Mlt::Producer *cut = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1450 trackPlaylist.replace_with_blank(clipIndex);
1451 newLength = cut->get_length();
1452 trackPlaylist.consolidate_blanks(0);
1453 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1454 mlt_service_unlock(service.get_service());
1455 } else if (serv == "framebuffer") {
1456 mlt_service_lock(service.get_service());
1457 QString url = clip.parent().get("resource");
1458 url = url.section("?", 0, 0);
1459 url.append("?" + QString::number(speed));
1460 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1461 if (!slowprod || slowprod->get_producer() == NULL) {
1462 char *tmp = decodedString(url);
1463 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1465 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1466 tmp = decodedString(producerid);
1467 slowprod->set("id", tmp);
1469 m_slowmotionProducers.insert(url, slowprod);
1471 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1472 newLength = cut->get_length();
1473 trackPlaylist.replace_with_blank(clipIndex);
1474 trackPlaylist.consolidate_blanks(0);
1475 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1476 mlt_service_unlock(service.get_service());
1477 kDebug() << "AVFORMAT CLIP!!!:";
1480 m_isBlocked = false;
1484 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1486 Mlt::Service service(m_mltProducer->parent().get_service());
1487 bool success = false;
1488 Mlt::Tractor tractor(service);
1489 Mlt::Producer trackProducer(tractor.track(track));
1490 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1491 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1492 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1494 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1497 Mlt::Service clipService(clip->get_service());
1498 // if (tag.startsWith("ladspa")) tag = "ladspa";
1501 Mlt::Filter *filter = clipService.filter(ct);
1503 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1504 if (clipService.detach(*filter) == 0) success = true;
1505 kDebug() << " / / / DLEETED EFFECT: " << ct;
1507 filter = clipService.filter(ct);
1509 m_isBlocked = false;
1510 if (doRefresh) refresh();
1515 bool Render::mltAddEffect(int track, GenTime position, QHash <QString, QString> args, bool doRefresh) {
1517 Mlt::Service service(m_mltProducer->parent().get_service());
1519 Mlt::Tractor tractor(service);
1520 Mlt::Producer trackProducer(tractor.track(track));
1521 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1523 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1527 Mlt::Service clipService(clip->get_service());
1530 QString tag = args.value("tag");
1531 kDebug() << " / / INSERTING EFFECT: " << tag;
1532 if (tag.startsWith("ladspa")) tag = "ladspa";
1533 char *filterTag = decodedString(tag);
1534 char *filterId = decodedString(args.value("id"));
1535 QHash<QString, QString>::Iterator it;
1536 QString kfr = args.value("keyframes");
1538 if (!kfr.isEmpty()) {
1539 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1540 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1541 char *starttag = decodedString(args.value("starttag", "start"));
1542 char *endtag = decodedString(args.value("endtag", "end"));
1543 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1544 int duration = clip->get_playtime();
1545 double max = args.value("max").toDouble();
1546 double min = args.value("min").toDouble();
1547 double factor = args.value("factor", "1").toDouble();
1548 args.remove("starttag");
1549 args.remove("endtag");
1550 args.remove("keyframes");
1553 args.remove("factor");
1555 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1556 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1557 filter->set("kdenlive_id", filterId);
1558 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1559 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1560 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1561 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1562 if (x2 == -1) x2 = duration;
1563 for (it = args.begin(); it != args.end(); ++it) {
1564 char *name = decodedString(it.key());
1565 char *value = decodedString(it.value());
1566 filter->set(name, value);
1571 filter->set("in", x1);
1572 filter->set("out", x2);
1573 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1574 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1575 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1576 clipService.attach(*filter);
1582 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1583 if (filter && filter->is_valid())
1584 filter->set("kdenlive_id", filterId);
1586 kDebug() << "filter is NULL";
1587 m_isBlocked = false;
1591 for (it = args.begin(); it != args.end(); ++it) {
1592 char *name = decodedString(it.key());
1593 char *value = decodedString(it.value());
1594 filter->set(name, value);
1598 // attach filter to the clip
1599 clipService.attach(*filter);
1603 m_isBlocked = false;
1604 if (doRefresh) refresh();
1608 bool Render::mltEditEffect(int track, GenTime position, QHash <QString, QString> args) {
1609 QString index = args.value("kdenlive_ix");
1610 QString tag = args.value("tag");
1611 QHash<QString, QString>::Iterator it = args.begin();
1612 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1613 // This is a keyframe effect, to edit it, we remove it and re-add it.
1614 mltRemoveEffect(track, position, index);
1615 bool success = mltAddEffect(track, position, args);
1620 Mlt::Service service(m_mltProducer->parent().get_service());
1622 Mlt::Tractor tractor(service);
1623 Mlt::Producer trackProducer(tractor.track(track));
1624 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1625 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1626 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1628 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1631 Mlt::Service clipService(clip->get_service());
1634 Mlt::Filter *filter = clipService.filter(ct);
1636 if (filter->get("kdenlive_ix") == index) {
1640 filter = clipService.filter(ct);
1644 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1645 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1647 filter = clipService.filter(ct);
1648 QList <Mlt::Filter *> filtersList;
1650 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1651 filtersList.append(filter);
1652 clipService.detach(*filter);
1654 filter = clipService.filter(ct);
1656 bool success = mltAddEffect(track, position, args);
1658 for (int i = 0; i < filtersList.count(); i++) {
1659 clipService.attach(*(filtersList.at(i)));
1662 m_isBlocked = false;
1666 for (it = args.begin(); it != args.end(); ++it) {
1667 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1668 char *name = decodedString(it.key());
1669 char *value = decodedString(it.value());
1670 filter->set(name, value);
1674 m_isBlocked = false;
1679 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1681 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1682 Mlt::Service service(m_mltProducer->parent().get_service());
1684 Mlt::Tractor tractor(service);
1685 Mlt::Producer trackProducer(tractor.track(track));
1686 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1687 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1688 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1690 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1693 Mlt::Service clipService(clip->get_service());
1696 QList <Mlt::Filter *> filtersList;
1697 Mlt::Filter *filter = clipService.filter(ct);
1699 if (newPos > oldPos) {
1701 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1702 filter->set("kdenlive_ix", newPos);
1703 filtersList.append(filter);
1704 clipService.detach(*filter);
1705 filter = clipService.filter(ct);
1706 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1707 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1709 filter = clipService.filter(ct);
1713 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1714 filtersList.append(filter);
1715 clipService.detach(*filter);
1717 filter = clipService.filter(ct);
1721 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1722 filter->set("kdenlive_ix", newPos);
1723 filtersList.append(filter);
1724 clipService.detach(*filter);
1726 filter = clipService.filter(ct);
1730 filter = clipService.filter(ct);
1732 int pos = QString(filter->get("kdenlive_ix")).toInt();
1733 if (pos >= newPos) {
1734 if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
1735 filtersList.append(filter);
1736 clipService.detach(*filter);
1738 filter = clipService.filter(ct);
1742 for (int i = 0; i < filtersList.count(); i++) {
1743 clipService.attach(*(filtersList.at(i)));
1746 m_isBlocked = false;
1750 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
1753 Mlt::Service service(m_mltProducer->parent().get_service());
1755 Mlt::Tractor tractor(service);
1756 Mlt::Producer trackProducer(tractor.track(info.track));
1757 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1759 /* // Display playlist info
1760 kDebug()<<"//////////// BEFORE RESIZE";
1761 for (int i = 0; i < trackPlaylist.count(); i++) {
1762 int blankStart = trackPlaylist.clip_start(i);
1763 int blankDuration = trackPlaylist.clip_length(i) - 1;
1765 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1766 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1769 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
1770 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1771 m_isBlocked = false;
1774 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1775 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
1776 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1777 int previousStart = clip->get_in();
1778 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1779 int newDuration = (int) clipDuration.frames(m_fps) - 1;
1780 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
1781 //trackPlaylist.consolidate_blanks(0);
1782 // skip to next clip
1784 int diff = newDuration - previousDuration;
1785 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
1787 // clip was made longer, trim next blank if there is one.
1788 if (trackPlaylist.is_blank(clipIndex)) {
1789 int blankStart = trackPlaylist.clip_start(clipIndex);
1790 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
1791 if (diff - blankDuration == 1) {
1792 trackPlaylist.remove(clipIndex);
1793 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
1795 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
1797 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
1799 trackPlaylist.consolidate_blanks(0);
1801 /* // Display playlist info
1802 kDebug()<<"//////////// AFTER RESIZE";
1803 for (int i = 0; i < trackPlaylist.count(); i++) {
1804 int blankStart = trackPlaylist.clip_start(i);
1805 int blankDuration = trackPlaylist.clip_length(i) - 1;
1807 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1808 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1811 //tractor.multitrack()->refresh();
1812 //tractor.refresh();
1813 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
1814 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1815 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1816 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1817 ItemInfo transpinfo;
1818 transpinfo.startPos = info.startPos;
1819 transpinfo.endPos = info.startPos + clipDuration;
1820 transpinfo.track = info.track;
1821 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1823 m_isBlocked = false;
1827 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1828 Mlt::Service service(m_mltProducer->parent().get_service());
1829 Mlt::Tractor tractor(service);
1830 Mlt::Producer trackProducer(tractor.track(track));
1831 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1833 if (blind) trackProducer.set("hide", 3);
1834 else trackProducer.set("hide", 2);
1836 trackProducer.set("hide", 1);
1838 trackProducer.set("hide", 0);
1840 tractor.multitrack()->refresh();
1845 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
1846 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
1847 Mlt::Service service(m_mltProducer->parent().get_service());
1848 int moveFrame = (int) diff.frames(m_fps);
1849 Mlt::Tractor tractor(service);
1850 Mlt::Producer trackProducer(tractor.track(info.track));
1851 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1852 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
1853 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1856 mlt_service_lock(service.get_service());
1857 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
1858 /*int previousStart = trackPlaylist.clip_start(clipIndex);
1859 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
1860 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1861 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1863 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
1864 mlt_service_unlock(service.get_service());
1867 //m_mltConsumer->set("refresh", 0);
1868 int previousStart = clip->get_in();
1869 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1871 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
1872 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
1873 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1875 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
1876 int blankIndex = clipIndex - 1;
1877 int blankLength = trackPlaylist.clip_length(blankIndex);
1878 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
1879 if (! trackPlaylist.is_blank(blankIndex)) {
1880 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
1882 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1883 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1885 trackPlaylist.consolidate_blanks(0);
1886 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1887 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
1888 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1889 ItemInfo transpinfo;
1890 transpinfo.startPos = info.startPos + diff;
1891 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
1892 transpinfo.track = info.track;
1893 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1895 m_isBlocked = false;
1896 //m_mltConsumer->set("refresh", 1);
1897 mlt_service_unlock(service.get_service());
1901 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1902 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1906 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1909 m_mltConsumer->set("refresh", 0);
1910 mlt_service_lock(m_mltConsumer->get_service());
1911 Mlt::Service service(m_mltProducer->parent().get_service());
1912 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1914 Mlt::Tractor tractor(service);
1915 Mlt::Producer trackProducer(tractor.track(startTrack));
1916 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1917 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1918 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
1919 bool checkLength = false;
1920 if (endTrack == startTrack) {
1921 //mlt_service_lock(service.get_service());
1922 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1924 if (!trackPlaylist.is_blank_at(moveEnd)) {
1925 // error, destination is not empty
1926 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
1927 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
1928 mlt_service_unlock(m_mltConsumer->get_service());
1929 m_isBlocked = false;
1932 trackPlaylist.consolidate_blanks(0);
1933 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1934 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1935 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1937 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
1939 //mlt_service_unlock(service.get_service());
1941 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1942 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1943 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
1944 // error, destination is not empty
1945 mlt_service_unlock(m_mltConsumer->get_service());
1946 m_isBlocked = false;
1949 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1950 trackPlaylist.consolidate_blanks(0);
1951 destTrackPlaylist.consolidate_blanks(1);
1952 int newIndex = destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1953 destTrackPlaylist.consolidate_blanks(0);
1954 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1955 kDebug() << "//////// moving clip transparency";
1956 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1958 if (clipIndex > trackPlaylist.count()) checkLength = true;
1959 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
1963 if (checkLength) mltCheckLength();
1964 mlt_service_unlock(m_mltConsumer->get_service());
1965 m_isBlocked = false;
1966 m_mltConsumer->set("refresh", 1);
1970 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1972 Mlt::Service service(m_mltProducer->parent().get_service());
1973 Mlt::Tractor tractor(service);
1974 Mlt::Field *field = tractor.field();
1976 mlt_service_lock(service.get_service());
1977 m_mltConsumer->set("refresh", 0);
1980 mlt_service serv = m_mltProducer->parent().get_service();
1981 mlt_service nextservice = mlt_service_get_producer(serv);
1982 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1983 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1984 QString resource = mlt_properties_get(properties, "mlt_service");
1985 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1987 int new_in = (int)newIn.frames(m_fps);
1988 int new_out = (int)newOut.frames(m_fps);
1990 while (mlt_type == "transition") {
1991 mlt_transition tr = (mlt_transition) nextservice;
1992 int currentTrack = mlt_transition_get_b_track(tr);
1993 int currentIn = (int) mlt_transition_get_in(tr);
1994 int currentOut = (int) mlt_transition_get_out(tr);
1996 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1997 mlt_transition_set_in_and_out(tr, new_in, new_out);
1998 if (newTrack - startTrack != 0) {
1999 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
2001 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2002 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2003 mlt_properties_set_int(properties, "b_track", newTrack);
2004 //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);
2008 nextservice = mlt_service_producer(nextservice);
2009 if (nextservice == NULL) break;
2010 properties = MLT_SERVICE_PROPERTIES(nextservice);
2011 mlt_type = mlt_properties_get(properties, "mlt_type");
2012 resource = mlt_properties_get(properties, "mlt_service");
2014 m_isBlocked = false;
2015 mlt_service_unlock(service.get_service());
2016 m_mltConsumer->set("refresh", 1);
2019 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2020 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2021 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2023 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2024 mltAddTransition(tag, a_track, b_track, in, out, xml);
2026 //mltSavePlaylist();
2029 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2032 Mlt::Service service(m_mltProducer->parent().get_service());
2033 Mlt::Tractor tractor(service);
2034 Mlt::Field *field = tractor.field();
2036 //m_mltConsumer->set("refresh", 0);
2037 mlt_service serv = m_mltProducer->parent().get_service();
2039 mlt_service nextservice = mlt_service_get_producer(serv);
2040 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2041 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2042 QString resource = mlt_properties_get(properties, "mlt_service");
2043 int in_pos = (int) in.frames(m_fps);
2044 int out_pos = (int) out.frames(m_fps);
2046 while (mlt_type == "transition") {
2047 mlt_transition tr = (mlt_transition) nextservice;
2048 int currentTrack = mlt_transition_get_b_track(tr);
2049 int currentIn = (int) mlt_transition_get_in(tr);
2050 int currentOut = (int) mlt_transition_get_out(tr);
2052 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2054 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2055 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2056 QMap<QString, QString>::Iterator it;
2058 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2060 for (it = map.begin(); it != map.end(); ++it) {
2062 char *name = decodedString(key);
2063 char *value = decodedString(it.value());
2064 mlt_properties_set(transproperties, name, value);
2065 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2066 //filter->set("kdenlive_id", id);
2072 nextservice = mlt_service_producer(nextservice);
2073 if (nextservice == NULL) break;
2074 properties = MLT_SERVICE_PROPERTIES(nextservice);
2075 mlt_type = mlt_properties_get(properties, "mlt_type");
2076 resource = mlt_properties_get(properties, "mlt_service");
2078 m_isBlocked = false;
2079 m_mltConsumer->set("refresh", 1);
2082 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2083 Mlt::Service service(m_mltProducer->parent().get_service());
2084 Mlt::Tractor tractor(service);
2085 Mlt::Field *field = tractor.field();
2087 if (do_refresh) m_mltConsumer->set("refresh", 0);
2088 mlt_service serv = m_mltProducer->parent().get_service();
2090 mlt_service nextservice = mlt_service_get_producer(serv);
2091 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2092 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2093 QString resource = mlt_properties_get(properties, "mlt_service");
2094 int old_pos = (int)((in + out).frames(m_fps) / 2);
2096 while (mlt_type == "transition") {
2097 mlt_transition tr = (mlt_transition) nextservice;
2098 int currentTrack = mlt_transition_get_b_track(tr);
2099 int currentIn = (int) mlt_transition_get_in(tr);
2100 int currentOut = (int) mlt_transition_get_out(tr);
2101 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2103 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2104 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2105 mlt_field_disconnect_service(field->get_field(), nextservice);
2108 nextservice = mlt_service_producer(nextservice);
2109 if (nextservice == NULL) break;
2110 properties = MLT_SERVICE_PROPERTIES(nextservice);
2111 mlt_type = mlt_properties_get(properties, "mlt_type");
2112 resource = mlt_properties_get(properties, "mlt_service");
2114 if (do_refresh) m_mltConsumer->set("refresh", 1);
2117 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2118 QDomNodeList attribs = xml.elementsByTagName("parameter");
2119 QMap<QString, QString> map;
2120 for (int i = 0;i < attribs.count();i++) {
2121 QDomElement e = attribs.item(i).toElement();
2122 QString name = e.attribute("name");
2123 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2124 map[name] = e.attribute("default");
2125 if (!e.attribute("value").isEmpty()) {
2126 map[name] = e.attribute("value");
2128 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2129 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2130 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2133 if (e.attribute("namedesc").contains(";")) {
2134 QString format = e.attribute("format");
2135 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2136 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2138 QTextStream txtNeu(&neu);
2139 if (values.size() > 0)
2140 txtNeu << (int)values[0].toDouble();
2142 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2143 txtNeu << separators[i];
2144 txtNeu << (int)(values[i+1].toDouble());
2146 if (i < separators.size())
2147 txtNeu << separators[i];
2148 map[e.attribute("name")] = neu;
2155 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2156 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2157 Mlt::Service service(m_mltProducer->parent().get_service());
2158 Mlt::Tractor tractor(service);
2159 Mlt::Field *field = tractor.field();
2161 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2162 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2163 transition->set("transparency", id);
2164 transition->set("fill", 1);
2165 transition->set("internal_added", 237);
2166 field->plant_transition(*transition, transitiontrack, info.track);
2170 void Render::mltDeleteTransparency(int pos, int track, int id) {
2171 Mlt::Service service(m_mltProducer->parent().get_service());
2172 Mlt::Tractor tractor(service);
2173 Mlt::Field *field = tractor.field();
2175 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2176 mlt_service serv = m_mltProducer->parent().get_service();
2178 mlt_service nextservice = mlt_service_get_producer(serv);
2179 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2180 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2181 QString resource = mlt_properties_get(properties, "mlt_service");
2183 while (mlt_type == "transition") {
2184 mlt_transition tr = (mlt_transition) nextservice;
2185 int currentTrack = mlt_transition_get_b_track(tr);
2186 int currentIn = (int) mlt_transition_get_in(tr);
2187 int currentOut = (int) mlt_transition_get_out(tr);
2188 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2189 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2191 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2192 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2193 mlt_field_disconnect_service(field->get_field(), nextservice);
2196 nextservice = mlt_service_producer(nextservice);
2197 if (nextservice == NULL) break;
2198 properties = MLT_SERVICE_PROPERTIES(nextservice);
2199 mlt_type = mlt_properties_get(properties, "mlt_type");
2200 resource = mlt_properties_get(properties, "mlt_service");
2202 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2205 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2206 Mlt::Service service(m_mltProducer->parent().get_service());
2207 Mlt::Tractor tractor(service);
2208 Mlt::Field *field = tractor.field();
2210 mlt_service_lock(service.get_service());
2211 m_mltConsumer->set("refresh", 0);
2214 mlt_service serv = m_mltProducer->parent().get_service();
2215 mlt_service nextservice = mlt_service_get_producer(serv);
2216 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2217 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2218 QString resource = mlt_properties_get(properties, "mlt_service");
2219 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2220 while (mlt_type == "transition") {
2221 mlt_transition tr = (mlt_transition) nextservice;
2222 int currentTrack = mlt_transition_get_b_track(tr);
2223 int currentIn = (int) mlt_transition_get_in(tr);
2224 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2225 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2226 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2227 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2228 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2229 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2232 nextservice = mlt_service_producer(nextservice);
2233 if (nextservice == NULL) break;
2234 properties = MLT_SERVICE_PROPERTIES(nextservice);
2235 mlt_type = mlt_properties_get(properties, "mlt_type");
2236 resource = mlt_properties_get(properties, "mlt_service");
2238 m_isBlocked = false;
2239 mlt_service_unlock(service.get_service());
2240 m_mltConsumer->set("refresh", 1);
2244 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2245 Mlt::Service service(m_mltProducer->parent().get_service());
2246 Mlt::Tractor tractor(service);
2247 Mlt::Field *field = tractor.field();
2249 mlt_service_lock(service.get_service());
2250 m_mltConsumer->set("refresh", 0);
2253 mlt_service serv = m_mltProducer->parent().get_service();
2254 mlt_service nextservice = mlt_service_get_producer(serv);
2255 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2256 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2257 QString resource = mlt_properties_get(properties, "mlt_service");
2259 while (mlt_type == "transition") {
2260 mlt_transition tr = (mlt_transition) nextservice;
2261 int currentTrack = mlt_transition_get_b_track(tr);
2262 int currentaTrack = mlt_transition_get_a_track(tr);
2263 int currentIn = (int) mlt_transition_get_in(tr);
2264 int currentOut = (int) mlt_transition_get_out(tr);
2265 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2266 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2267 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2268 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2269 kDebug() << "//////MOVING";
2270 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2271 if (endTrack != startTrack) {
2272 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2273 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2274 mlt_properties_set_int(properties, "b_track", endTrack);
2278 nextservice = mlt_service_producer(nextservice);
2279 if (nextservice == NULL) break;
2280 properties = MLT_SERVICE_PROPERTIES(nextservice);
2281 mlt_type = mlt_properties_get(properties, "mlt_type");
2282 resource = mlt_properties_get(properties, "mlt_service");
2284 m_isBlocked = false;
2285 mlt_service_unlock(service.get_service());
2286 m_mltConsumer->set("refresh", 1);
2290 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2292 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2293 Mlt::Service service(m_mltProducer->parent().get_service());
2295 Mlt::Tractor tractor(service);
2296 Mlt::Field *field = tractor.field();
2298 char *transId = decodedString(tag);
2299 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2300 if (out != GenTime())
2301 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
2302 QMap<QString, QString>::Iterator it;
2305 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2307 for (it = args.begin(); it != args.end(); ++it) {
2309 char *name = decodedString(key);
2310 char *value = decodedString(it.value());
2311 transition->set(name, value);
2312 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2313 //filter->set("kdenlive_id", id);
2317 // attach filter to the clip
2318 field->plant_transition(*transition, a_track, b_track);
2323 void Render::mltSavePlaylist() {
2324 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2325 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2326 fileConsumer.set("resource", "/tmp/playlist.westley");
2328 Mlt::Service service(m_mltProducer->get_service());
2330 fileConsumer.connect(service);
2331 fileConsumer.start();
2334 QList <Mlt::Producer *> Render::producersList() {
2335 QList <Mlt::Producer *> prods;
2337 Mlt::Service service(m_mltProducer->parent().get_service());
2338 Mlt::Tractor tractor(service);
2339 Mlt::Field *field = tractor.field();
2341 int trackNb = tractor.count();
2342 for (int t = 1; t < trackNb; t++) {
2343 Mlt::Producer trackProducer(tractor.track(t));
2344 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2345 int clipNb = trackPlaylist.count();
2346 kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2347 for (int i = 0; i < clipNb; i++) {
2348 Mlt::Producer *prod = trackPlaylist.get_clip(i);
2349 Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
2350 //kDebug()<<"PROD: "<<nprod->get("producer")<<", ID: "<<nprod->get("id")<<nprod->get("resource");
2351 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2352 ids.append(nprod->get("id"));
2353 prods.append(nprod);
2360 #include "renderer.moc"