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_isZoneMode) resetZoneMode();
1014 m_mltConsumer->set("refresh", 0);
1015 m_mltProducer->set_speed(0.0);
1016 emit rendererPosition(m_framePosition);
1017 m_mltProducer->seek(m_framePosition);
1018 m_mltConsumer->purge();
1021 void Render::switchPlay() {
1022 if (!m_mltProducer || !m_mltConsumer)
1024 if (m_isZoneMode) resetZoneMode();
1025 if (m_mltProducer->get_speed() == 0.0) {
1026 m_isBlocked = false;
1027 m_mltProducer->set_speed(1.0);
1028 m_mltConsumer->set("refresh", 1);
1031 m_mltConsumer->set("refresh", 0);
1032 m_mltProducer->set_speed(0.0);
1033 emit rendererPosition(m_framePosition);
1034 m_mltProducer->seek(m_framePosition);
1035 m_mltConsumer->purge();
1036 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1037 //m_mltConsumer->set("refresh", 0);
1038 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1039 m_mltProducer->set_speed(0);
1040 m_mltProducer->seek( position );
1041 //m_mltProducer->seek((int) m_framePosition);
1042 m_isBlocked = false;*/
1044 /*if (speed == 0.0) {
1045 m_mltProducer->seek((int) m_framePosition + 1);
1046 m_mltConsumer->purge();
1051 void Render::play(double speed) {
1054 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1055 m_isBlocked = false;
1056 m_mltProducer->set_speed(speed);
1057 /*if (speed == 0.0) {
1058 m_mltProducer->seek((int) m_framePosition + 1);
1059 m_mltConsumer->purge();
1064 void Render::play(const GenTime & startTime) {
1065 if (!m_mltProducer || !m_mltConsumer)
1067 m_isBlocked = false;
1068 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1069 m_mltProducer->set_speed(1.0);
1070 m_mltConsumer->set("refresh", 1);
1073 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1074 if (!m_mltProducer || !m_mltConsumer)
1076 //m_mltProducer->set("eof", "loop");
1077 m_isLoopMode = true;
1078 m_loopStart = startTime;
1079 playZone(startTime, stopTime);
1082 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1083 if (!m_mltProducer || !m_mltConsumer)
1085 m_isBlocked = false;
1086 m_mltProducer->set("out", stopTime.frames(m_fps));
1087 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1088 m_mltProducer->set_speed(1.0);
1089 m_mltConsumer->set("refresh", 1);
1090 m_isZoneMode = true;
1093 void Render::resetZoneMode() {
1094 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1095 //m_mltProducer->set("eof", "pause");
1096 m_isZoneMode = false;
1097 m_isLoopMode = false;
1100 void Render::seekToFrame(int pos) {
1101 //kDebug()<<" ********* RENDER SEEK TO POS";
1104 m_isBlocked = false;
1106 m_mltProducer->seek(pos);
1110 void Render::askForRefresh() {
1111 // Use a Timer so that we don't refresh too much
1112 refreshTimer->start(200);
1115 void Render::doRefresh() {
1116 // Use a Timer so that we don't refresh too much
1117 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1120 void Render::refresh() {
1121 if (!m_mltProducer || m_isBlocked)
1123 refreshTimer->stop();
1124 if (m_mltConsumer) {
1125 m_mltConsumer->set("refresh", 1);
1129 double Render::playSpeed() {
1130 if (m_mltProducer) return m_mltProducer->get_speed();
1134 GenTime Render::seekPosition() const {
1135 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1136 else return GenTime();
1140 const QString & Render::rendererName() const {
1145 void Render::emitFrameNumber(double position) {
1146 m_framePosition = position;
1147 emit rendererPosition((int) position);
1148 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1151 void Render::emitConsumerStopped() {
1152 // This is used to know when the playing stopped
1153 if (m_mltProducer) {
1154 double pos = m_mltProducer->position();
1155 if (m_isLoopMode) play(m_loopStart);
1156 else if (m_isZoneMode) resetZoneMode();
1157 emit rendererStopped((int) pos);
1158 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1159 //new QCustomEvent(10002));
1165 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1166 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1170 void Render::exportCurrentFrame(KUrl url, bool notify) {
1171 if (!m_mltProducer) {
1172 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1176 int height = 1080;//KdenliveSettings::defaultheight();
1177 int width = 1940; //KdenliveSettings::displaywidth();
1179 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1181 QPixmap pix(width, height);
1182 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1183 m_convert.set("forced", mlt_image_rgb24a);
1184 m_mltProducer->attach(m_convert);
1185 Mlt::Frame * frame = m_mltProducer->get_frame();
1186 m_mltProducer->detach(m_convert);
1188 pix = frameThumbnail(frame, width, height);
1191 pix.save(url.path(), "PNG");
1192 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1195 /** MLT PLAYLIST DIRECT MANIPULATON **/
1198 void Render::mltCheckLength(bool reload) {
1199 //kDebug()<<"checking track length: "<<track<<"..........";
1201 Mlt::Service service(m_mltProducer->get_service());
1202 Mlt::Tractor tractor(service);
1204 int trackNb = tractor.count();
1205 double duration = 0;
1206 double trackDuration;
1208 Mlt::Producer trackProducer(tractor.track(0));
1209 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1210 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1211 m_mltProducer->set("out", duration);
1212 emit durationChanged((int) duration);
1215 while (trackNb > 1) {
1216 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1217 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1218 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1220 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1221 if (trackDuration > duration) duration = trackDuration;
1225 Mlt::Producer blackTrackProducer(tractor.track(0));
1226 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1227 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1229 if (blackDuration != duration) {
1230 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1232 int dur = (int)duration;
1234 QDomElement black = doc.createElement("producer");
1235 black.setAttribute("mlt_service", "colour");
1236 black.setAttribute("colour", "black");
1237 black.setAttribute("id", "black");
1240 while (dur > 14000) {
1241 info.startPos = GenTime(i * 14000, m_fps);
1242 info.endPos = info.startPos + GenTime(13999, m_fps);
1243 mltInsertClip(info, black, m_blackClip);
1248 info.startPos = GenTime(i * 14000, m_fps);
1249 info.endPos = info.startPos + GenTime(dur, m_fps);
1250 mltInsertClip(info, black, m_blackClip);
1252 m_mltProducer->set("out", duration);
1253 emit durationChanged((int)duration);
1257 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1258 if (!m_mltProducer) {
1259 kDebug() << "PLAYLIST NOT INITIALISED //////";
1262 Mlt::Producer parentProd(m_mltProducer->parent());
1263 if (parentProd.get_producer() == NULL) {
1264 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1268 Mlt::Service service(parentProd.get_service());
1269 Mlt::Tractor tractor(service);
1270 mlt_service_lock(service.get_service());
1271 Mlt::Producer trackProducer(tractor.track(info.track));
1272 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1273 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1274 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1275 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1277 if (QString(prod->get("transparency")).toInt() == 1)
1278 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());
1280 mlt_service_unlock(service.get_service());
1282 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1283 //tractor.multitrack()->refresh();
1284 //tractor.refresh();
1288 void Render::mltCutClip(int track, GenTime position) {
1292 Mlt::Service service(m_mltProducer->parent().get_service());
1293 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1295 Mlt::Tractor tractor(service);
1296 Mlt::Producer trackProducer(tractor.track(track));
1297 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1300 /* // Display playlist info
1301 kDebug()<<"//////////// BEFORE";
1302 for (int i = 0; i < trackPlaylist.count(); i++) {
1303 int blankStart = trackPlaylist.clip_start(i);
1304 int blankDuration = trackPlaylist.clip_length(i) - 1;
1306 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1307 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1310 int cutPos = (int) position.frames(m_fps);
1312 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1313 if (trackPlaylist.is_blank(clipIndex)) {
1314 kDebug() << "// WARMNING, TRYING TO CUT A BLANK";
1315 m_isBlocked = false;
1318 mlt_service_lock(service.get_service());
1319 int clipStart = trackPlaylist.clip_start(clipIndex);
1320 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1322 // duplicate effects
1323 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1324 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1326 if (original == NULL || clip == NULL) {
1327 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1329 Mlt::Service clipService(original->get_service());
1330 Mlt::Service dupService(clip->get_service());
1332 Mlt::Filter *filter = clipService.filter(ct);
1334 if (filter->get("kdenlive_id") != "") {
1335 kDebug() << "++ ADDING FILTER: " << filter->get("kdenlive_id");
1336 Mlt::Filter *dup = new Mlt::Filter(filter->get_filter());
1337 dup->set("kdenlive_ix", filter->get("kdenlive_ix"));
1338 dup->set("kdenlive_id", filter->get("kdenlive_id"));
1339 dupService.attach(*dup);
1342 filter = clipService.filter(ct);
1344 mlt_service_unlock(service.get_service());
1346 /* // Display playlist info
1347 kDebug()<<"//////////// AFTER";
1348 for (int i = 0; i < trackPlaylist.count(); i++) {
1349 int blankStart = trackPlaylist.clip_start(i);
1350 int blankDuration = trackPlaylist.clip_length(i) - 1;
1352 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1353 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1356 m_isBlocked = false;
1359 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1361 mltRemoveClip(info.track, info.startPos);
1362 mltInsertClip(info, element, prod);
1366 bool Render::mltRemoveClip(int track, GenTime position) {
1367 Mlt::Service service(m_mltProducer->parent().get_service());
1368 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1370 Mlt::Tractor tractor(service);
1371 Mlt::Producer trackProducer(tractor.track(track));
1372 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1373 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1375 /* // Display playlist info
1376 kDebug()<<"//// BEFORE";
1377 for (int i = 0; i < trackPlaylist.count(); i++) {
1378 int blankStart = trackPlaylist.clip_start(i);
1379 int blankDuration = trackPlaylist.clip_length(i) - 1;
1381 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1382 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1385 if (trackPlaylist.is_blank(clipIndex)) {
1386 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1390 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1391 trackPlaylist.replace_with_blank(clipIndex);
1392 trackPlaylist.consolidate_blanks(0);
1393 if (QString(clip.parent().get("transparency")).toInt() == 1)
1394 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());
1396 /* // Display playlist info
1397 kDebug()<<"//// AFTER";
1398 for (int i = 0; i < trackPlaylist.count(); i++) {
1399 int blankStart = trackPlaylist.clip_start(i);
1400 int blankDuration = trackPlaylist.clip_length(i) - 1;
1402 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1403 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1406 if (track != 0 && trackPlaylist.count() > clipIndex) mltCheckLength();
1407 m_isBlocked = false;
1411 int Render::mltChangeClipSpeed(ItemInfo info, double speed, Mlt::Producer *prod) {
1414 Mlt::Service service(m_mltProducer->parent().get_service());
1415 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1416 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1417 Mlt::Tractor tractor(service);
1418 Mlt::Producer trackProducer(tractor.track(info.track));
1419 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1420 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1421 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1422 QString serv = clip.parent().get("mlt_service");
1423 QString id = clip.parent().get("id");
1424 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1425 if (serv == "avformat" && speed != 1.0) {
1426 mlt_service_lock(service.get_service());
1427 QString url = clip.parent().get("resource");
1428 url.append("?" + QString::number(speed));
1429 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1430 if (!slowprod || slowprod->get_producer() == NULL) {
1431 char *tmp = decodedString(url);
1432 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1434 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1435 tmp = decodedString(producerid);
1436 slowprod->set("id", tmp);
1438 m_slowmotionProducers.insert(url, slowprod);
1440 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1441 newLength = cut->get_length();
1442 trackPlaylist.replace_with_blank(clipIndex);
1443 trackPlaylist.consolidate_blanks(0);
1444 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1445 mlt_service_unlock(service.get_service());
1446 } else if (speed == 1.0) {
1447 mlt_service_lock(service.get_service());
1448 Mlt::Producer *cut = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1449 trackPlaylist.replace_with_blank(clipIndex);
1450 newLength = cut->get_length();
1451 trackPlaylist.consolidate_blanks(0);
1452 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1453 mlt_service_unlock(service.get_service());
1454 } else if (serv == "framebuffer") {
1455 mlt_service_lock(service.get_service());
1456 QString url = clip.parent().get("resource");
1457 url = url.section("?", 0, 0);
1458 url.append("?" + QString::number(speed));
1459 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1460 if (!slowprod || slowprod->get_producer() == NULL) {
1461 char *tmp = decodedString(url);
1462 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1464 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1465 tmp = decodedString(producerid);
1466 slowprod->set("id", tmp);
1468 m_slowmotionProducers.insert(url, slowprod);
1470 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1471 newLength = cut->get_length();
1472 trackPlaylist.replace_with_blank(clipIndex);
1473 trackPlaylist.consolidate_blanks(0);
1474 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1475 mlt_service_unlock(service.get_service());
1476 kDebug() << "AVFORMAT CLIP!!!:";
1479 m_isBlocked = false;
1483 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1485 Mlt::Service service(m_mltProducer->parent().get_service());
1486 bool success = false;
1487 Mlt::Tractor tractor(service);
1488 Mlt::Producer trackProducer(tractor.track(track));
1489 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1490 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1491 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1493 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1496 Mlt::Service clipService(clip->get_service());
1497 // if (tag.startsWith("ladspa")) tag = "ladspa";
1500 Mlt::Filter *filter = clipService.filter(ct);
1502 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1503 if (clipService.detach(*filter) == 0) success = true;
1504 kDebug() << " / / / DLEETED EFFECT: " << ct;
1506 filter = clipService.filter(ct);
1508 m_isBlocked = false;
1509 if (doRefresh) refresh();
1514 bool Render::mltAddEffect(int track, GenTime position, QHash <QString, QString> args, bool doRefresh) {
1516 Mlt::Service service(m_mltProducer->parent().get_service());
1518 Mlt::Tractor tractor(service);
1519 Mlt::Producer trackProducer(tractor.track(track));
1520 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1522 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1526 Mlt::Service clipService(clip->get_service());
1529 QString tag = args.value("tag");
1530 kDebug() << " / / INSERTING EFFECT: " << tag;
1531 if (tag.startsWith("ladspa")) tag = "ladspa";
1532 char *filterTag = decodedString(tag);
1533 char *filterId = decodedString(args.value("id"));
1534 QHash<QString, QString>::Iterator it;
1535 QString kfr = args.value("keyframes");
1537 if (!kfr.isEmpty()) {
1538 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1539 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1540 char *starttag = decodedString(args.value("starttag", "start"));
1541 char *endtag = decodedString(args.value("endtag", "end"));
1542 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1543 int duration = clip->get_playtime();
1544 double max = args.value("max").toDouble();
1545 double min = args.value("min").toDouble();
1546 double factor = args.value("factor", "1").toDouble();
1547 args.remove("starttag");
1548 args.remove("endtag");
1549 args.remove("keyframes");
1552 args.remove("factor");
1554 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1555 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1556 filter->set("kdenlive_id", filterId);
1557 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1558 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1559 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1560 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1561 if (x2 == -1) x2 = duration;
1562 for (it = args.begin(); it != args.end(); ++it) {
1563 char *name = decodedString(it.key());
1564 char *value = decodedString(it.value());
1565 filter->set(name, value);
1570 filter->set("in", x1);
1571 filter->set("out", x2);
1572 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1573 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1574 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1575 clipService.attach(*filter);
1581 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1582 if (filter && filter->is_valid())
1583 filter->set("kdenlive_id", filterId);
1585 kDebug() << "filter is NULL";
1586 m_isBlocked = false;
1590 for (it = args.begin(); it != args.end(); ++it) {
1591 char *name = decodedString(it.key());
1592 char *value = decodedString(it.value());
1593 filter->set(name, value);
1597 // attach filter to the clip
1598 clipService.attach(*filter);
1602 m_isBlocked = false;
1603 if (doRefresh) refresh();
1607 bool Render::mltEditEffect(int track, GenTime position, QHash <QString, QString> args) {
1608 QString index = args.value("kdenlive_ix");
1609 QString tag = args.value("tag");
1610 QHash<QString, QString>::Iterator it = args.begin();
1611 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1612 // This is a keyframe effect, to edit it, we remove it and re-add it.
1613 mltRemoveEffect(track, position, index);
1614 bool success = mltAddEffect(track, position, args);
1619 Mlt::Service service(m_mltProducer->parent().get_service());
1621 Mlt::Tractor tractor(service);
1622 Mlt::Producer trackProducer(tractor.track(track));
1623 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1624 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1625 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1627 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1630 Mlt::Service clipService(clip->get_service());
1633 Mlt::Filter *filter = clipService.filter(ct);
1635 if (filter->get("kdenlive_ix") == index) {
1639 filter = clipService.filter(ct);
1643 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1644 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1646 filter = clipService.filter(ct);
1647 QList <Mlt::Filter *> filtersList;
1649 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1650 filtersList.append(filter);
1651 clipService.detach(*filter);
1653 filter = clipService.filter(ct);
1655 bool success = mltAddEffect(track, position, args);
1657 for (int i = 0; i < filtersList.count(); i++) {
1658 clipService.attach(*(filtersList.at(i)));
1661 m_isBlocked = false;
1665 for (it = args.begin(); it != args.end(); ++it) {
1666 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1667 char *name = decodedString(it.key());
1668 char *value = decodedString(it.value());
1669 filter->set(name, value);
1673 m_isBlocked = false;
1678 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1680 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1681 Mlt::Service service(m_mltProducer->parent().get_service());
1683 Mlt::Tractor tractor(service);
1684 Mlt::Producer trackProducer(tractor.track(track));
1685 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1686 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1687 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1689 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1692 Mlt::Service clipService(clip->get_service());
1695 QList <Mlt::Filter *> filtersList;
1696 Mlt::Filter *filter = clipService.filter(ct);
1698 if (newPos > oldPos) {
1700 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1701 filter->set("kdenlive_ix", newPos);
1702 filtersList.append(filter);
1703 clipService.detach(*filter);
1704 filter = clipService.filter(ct);
1705 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1706 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1708 filter = clipService.filter(ct);
1712 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1713 filtersList.append(filter);
1714 clipService.detach(*filter);
1716 filter = clipService.filter(ct);
1720 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1721 filter->set("kdenlive_ix", newPos);
1722 filtersList.append(filter);
1723 clipService.detach(*filter);
1725 filter = clipService.filter(ct);
1729 filter = clipService.filter(ct);
1731 int pos = QString(filter->get("kdenlive_ix")).toInt();
1732 if (pos >= newPos) {
1733 if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
1734 filtersList.append(filter);
1735 clipService.detach(*filter);
1737 filter = clipService.filter(ct);
1741 for (int i = 0; i < filtersList.count(); i++) {
1742 clipService.attach(*(filtersList.at(i)));
1745 m_isBlocked = false;
1749 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
1752 Mlt::Service service(m_mltProducer->parent().get_service());
1754 Mlt::Tractor tractor(service);
1755 Mlt::Producer trackProducer(tractor.track(info.track));
1756 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1758 /* // Display playlist info
1759 kDebug()<<"//////////// BEFORE RESIZE";
1760 for (int i = 0; i < trackPlaylist.count(); i++) {
1761 int blankStart = trackPlaylist.clip_start(i);
1762 int blankDuration = trackPlaylist.clip_length(i) - 1;
1764 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1765 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1768 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
1769 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1770 m_isBlocked = false;
1773 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1774 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
1775 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1776 int previousStart = clip->get_in();
1777 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1778 int newDuration = (int) clipDuration.frames(m_fps) - 1;
1779 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
1780 //trackPlaylist.consolidate_blanks(0);
1781 // skip to next clip
1783 int diff = newDuration - previousDuration;
1784 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
1786 // clip was made longer, trim next blank if there is one.
1787 if (trackPlaylist.is_blank(clipIndex)) {
1788 int blankStart = trackPlaylist.clip_start(clipIndex);
1789 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
1790 if (diff - blankDuration == 1) {
1791 trackPlaylist.remove(clipIndex);
1792 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
1794 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
1796 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
1798 trackPlaylist.consolidate_blanks(0);
1800 /* // Display playlist info
1801 kDebug()<<"//////////// AFTER RESIZE";
1802 for (int i = 0; i < trackPlaylist.count(); i++) {
1803 int blankStart = trackPlaylist.clip_start(i);
1804 int blankDuration = trackPlaylist.clip_length(i) - 1;
1806 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1807 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1810 //tractor.multitrack()->refresh();
1811 //tractor.refresh();
1812 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
1813 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1814 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1815 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1816 ItemInfo transpinfo;
1817 transpinfo.startPos = info.startPos;
1818 transpinfo.endPos = info.startPos + clipDuration;
1819 transpinfo.track = info.track;
1820 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1822 m_isBlocked = false;
1826 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1827 Mlt::Service service(m_mltProducer->parent().get_service());
1828 Mlt::Tractor tractor(service);
1829 Mlt::Producer trackProducer(tractor.track(track));
1830 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1832 if (blind) trackProducer.set("hide", 3);
1833 else trackProducer.set("hide", 2);
1835 trackProducer.set("hide", 1);
1837 trackProducer.set("hide", 0);
1839 tractor.multitrack()->refresh();
1844 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
1845 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
1846 Mlt::Service service(m_mltProducer->parent().get_service());
1847 int moveFrame = (int) diff.frames(m_fps);
1848 Mlt::Tractor tractor(service);
1849 Mlt::Producer trackProducer(tractor.track(info.track));
1850 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1851 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
1852 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1855 mlt_service_lock(service.get_service());
1856 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
1857 /*int previousStart = trackPlaylist.clip_start(clipIndex);
1858 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
1859 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1860 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1862 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
1863 mlt_service_unlock(service.get_service());
1866 //m_mltConsumer->set("refresh", 0);
1867 int previousStart = clip->get_in();
1868 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1870 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
1871 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
1872 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1874 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
1875 int blankIndex = clipIndex - 1;
1876 int blankLength = trackPlaylist.clip_length(blankIndex);
1877 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
1878 if (! trackPlaylist.is_blank(blankIndex)) {
1879 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
1881 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1882 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1884 trackPlaylist.consolidate_blanks(0);
1885 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1886 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
1887 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1888 ItemInfo transpinfo;
1889 transpinfo.startPos = info.startPos + diff;
1890 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
1891 transpinfo.track = info.track;
1892 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1894 m_isBlocked = false;
1895 //m_mltConsumer->set("refresh", 1);
1896 mlt_service_unlock(service.get_service());
1900 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1901 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1905 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1908 m_mltConsumer->set("refresh", 0);
1909 mlt_service_lock(m_mltConsumer->get_service());
1910 Mlt::Service service(m_mltProducer->parent().get_service());
1911 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1913 Mlt::Tractor tractor(service);
1914 Mlt::Producer trackProducer(tractor.track(startTrack));
1915 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1916 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1917 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
1918 bool checkLength = false;
1919 if (endTrack == startTrack) {
1920 //mlt_service_lock(service.get_service());
1921 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1923 if (!trackPlaylist.is_blank_at(moveEnd)) {
1924 // error, destination is not empty
1925 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
1926 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
1927 mlt_service_unlock(m_mltConsumer->get_service());
1928 m_isBlocked = false;
1931 trackPlaylist.consolidate_blanks(0);
1932 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1933 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1934 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1936 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
1938 //mlt_service_unlock(service.get_service());
1940 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1941 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1942 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
1943 // error, destination is not empty
1944 mlt_service_unlock(m_mltConsumer->get_service());
1945 m_isBlocked = false;
1948 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1949 trackPlaylist.consolidate_blanks(0);
1950 destTrackPlaylist.consolidate_blanks(1);
1951 int newIndex = destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1952 destTrackPlaylist.consolidate_blanks(0);
1953 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1954 kDebug() << "//////// moving clip transparency";
1955 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1957 if (clipIndex > trackPlaylist.count()) checkLength = true;
1958 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
1962 if (checkLength) mltCheckLength();
1963 mlt_service_unlock(m_mltConsumer->get_service());
1964 m_isBlocked = false;
1965 m_mltConsumer->set("refresh", 1);
1969 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1971 Mlt::Service service(m_mltProducer->parent().get_service());
1972 Mlt::Tractor tractor(service);
1973 Mlt::Field *field = tractor.field();
1975 mlt_service_lock(service.get_service());
1976 m_mltConsumer->set("refresh", 0);
1979 mlt_service serv = m_mltProducer->parent().get_service();
1980 mlt_service nextservice = mlt_service_get_producer(serv);
1981 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1982 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1983 QString resource = mlt_properties_get(properties, "mlt_service");
1984 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1986 int new_in = (int)newIn.frames(m_fps);
1987 int new_out = (int)newOut.frames(m_fps);
1989 while (mlt_type == "transition") {
1990 mlt_transition tr = (mlt_transition) nextservice;
1991 int currentTrack = mlt_transition_get_b_track(tr);
1992 int currentIn = (int) mlt_transition_get_in(tr);
1993 int currentOut = (int) mlt_transition_get_out(tr);
1995 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1996 mlt_transition_set_in_and_out(tr, new_in, new_out);
1997 if (newTrack - startTrack != 0) {
1998 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
2000 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2001 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2002 mlt_properties_set_int(properties, "b_track", newTrack);
2003 //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);
2007 nextservice = mlt_service_producer(nextservice);
2008 if (nextservice == NULL) break;
2009 properties = MLT_SERVICE_PROPERTIES(nextservice);
2010 mlt_type = mlt_properties_get(properties, "mlt_type");
2011 resource = mlt_properties_get(properties, "mlt_service");
2013 m_isBlocked = false;
2014 mlt_service_unlock(service.get_service());
2015 m_mltConsumer->set("refresh", 1);
2018 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2019 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2020 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2022 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2023 mltAddTransition(tag, a_track, b_track, in, out, xml);
2025 //mltSavePlaylist();
2028 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2031 Mlt::Service service(m_mltProducer->parent().get_service());
2032 Mlt::Tractor tractor(service);
2033 Mlt::Field *field = tractor.field();
2035 //m_mltConsumer->set("refresh", 0);
2036 mlt_service serv = m_mltProducer->parent().get_service();
2038 mlt_service nextservice = mlt_service_get_producer(serv);
2039 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2040 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2041 QString resource = mlt_properties_get(properties, "mlt_service");
2042 int in_pos = (int) in.frames(m_fps);
2043 int out_pos = (int) out.frames(m_fps);
2045 while (mlt_type == "transition") {
2046 mlt_transition tr = (mlt_transition) nextservice;
2047 int currentTrack = mlt_transition_get_b_track(tr);
2048 int currentIn = (int) mlt_transition_get_in(tr);
2049 int currentOut = (int) mlt_transition_get_out(tr);
2051 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2053 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2054 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2055 QMap<QString, QString>::Iterator it;
2057 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2059 for (it = map.begin(); it != map.end(); ++it) {
2061 char *name = decodedString(key);
2062 char *value = decodedString(it.value());
2063 mlt_properties_set(transproperties, name, value);
2064 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2065 //filter->set("kdenlive_id", id);
2071 nextservice = mlt_service_producer(nextservice);
2072 if (nextservice == NULL) break;
2073 properties = MLT_SERVICE_PROPERTIES(nextservice);
2074 mlt_type = mlt_properties_get(properties, "mlt_type");
2075 resource = mlt_properties_get(properties, "mlt_service");
2077 m_isBlocked = false;
2078 m_mltConsumer->set("refresh", 1);
2081 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2082 Mlt::Service service(m_mltProducer->parent().get_service());
2083 Mlt::Tractor tractor(service);
2084 Mlt::Field *field = tractor.field();
2086 if (do_refresh) m_mltConsumer->set("refresh", 0);
2087 mlt_service serv = m_mltProducer->parent().get_service();
2089 mlt_service nextservice = mlt_service_get_producer(serv);
2090 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2091 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2092 QString resource = mlt_properties_get(properties, "mlt_service");
2093 int old_pos = (int)((in + out).frames(m_fps) / 2);
2095 while (mlt_type == "transition") {
2096 mlt_transition tr = (mlt_transition) nextservice;
2097 int currentTrack = mlt_transition_get_b_track(tr);
2098 int currentIn = (int) mlt_transition_get_in(tr);
2099 int currentOut = (int) mlt_transition_get_out(tr);
2100 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2102 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2103 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2104 mlt_field_disconnect_service(field->get_field(), nextservice);
2107 nextservice = mlt_service_producer(nextservice);
2108 if (nextservice == NULL) break;
2109 properties = MLT_SERVICE_PROPERTIES(nextservice);
2110 mlt_type = mlt_properties_get(properties, "mlt_type");
2111 resource = mlt_properties_get(properties, "mlt_service");
2113 if (do_refresh) m_mltConsumer->set("refresh", 1);
2116 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2117 QDomNodeList attribs = xml.elementsByTagName("parameter");
2118 QMap<QString, QString> map;
2119 for (int i = 0;i < attribs.count();i++) {
2120 QDomElement e = attribs.item(i).toElement();
2121 QString name = e.attribute("name");
2122 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2123 map[name] = e.attribute("default");
2124 if (!e.attribute("value").isEmpty()) {
2125 map[name] = e.attribute("value");
2127 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2128 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2129 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2132 if (e.attribute("namedesc").contains(";")) {
2133 QString format = e.attribute("format");
2134 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2135 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2137 QTextStream txtNeu(&neu);
2138 if (values.size() > 0)
2139 txtNeu << (int)values[0].toDouble();
2141 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2142 txtNeu << separators[i];
2143 txtNeu << (int)(values[i+1].toDouble());
2145 if (i < separators.size())
2146 txtNeu << separators[i];
2147 map[e.attribute("name")] = neu;
2154 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2155 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2156 Mlt::Service service(m_mltProducer->parent().get_service());
2157 Mlt::Tractor tractor(service);
2158 Mlt::Field *field = tractor.field();
2160 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2161 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2162 transition->set("transparency", id);
2163 transition->set("fill", 1);
2164 transition->set("internal_added", 237);
2165 field->plant_transition(*transition, transitiontrack, info.track);
2169 void Render::mltDeleteTransparency(int pos, int track, int id) {
2170 Mlt::Service service(m_mltProducer->parent().get_service());
2171 Mlt::Tractor tractor(service);
2172 Mlt::Field *field = tractor.field();
2174 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2175 mlt_service serv = m_mltProducer->parent().get_service();
2177 mlt_service nextservice = mlt_service_get_producer(serv);
2178 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2179 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2180 QString resource = mlt_properties_get(properties, "mlt_service");
2182 while (mlt_type == "transition") {
2183 mlt_transition tr = (mlt_transition) nextservice;
2184 int currentTrack = mlt_transition_get_b_track(tr);
2185 int currentIn = (int) mlt_transition_get_in(tr);
2186 int currentOut = (int) mlt_transition_get_out(tr);
2187 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2188 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2190 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2191 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2192 mlt_field_disconnect_service(field->get_field(), nextservice);
2195 nextservice = mlt_service_producer(nextservice);
2196 if (nextservice == NULL) break;
2197 properties = MLT_SERVICE_PROPERTIES(nextservice);
2198 mlt_type = mlt_properties_get(properties, "mlt_type");
2199 resource = mlt_properties_get(properties, "mlt_service");
2201 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2204 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2205 Mlt::Service service(m_mltProducer->parent().get_service());
2206 Mlt::Tractor tractor(service);
2207 Mlt::Field *field = tractor.field();
2209 mlt_service_lock(service.get_service());
2210 m_mltConsumer->set("refresh", 0);
2213 mlt_service serv = m_mltProducer->parent().get_service();
2214 mlt_service nextservice = mlt_service_get_producer(serv);
2215 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2216 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2217 QString resource = mlt_properties_get(properties, "mlt_service");
2218 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2219 while (mlt_type == "transition") {
2220 mlt_transition tr = (mlt_transition) nextservice;
2221 int currentTrack = mlt_transition_get_b_track(tr);
2222 int currentIn = (int) mlt_transition_get_in(tr);
2223 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2224 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2225 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2226 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2227 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2228 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2231 nextservice = mlt_service_producer(nextservice);
2232 if (nextservice == NULL) break;
2233 properties = MLT_SERVICE_PROPERTIES(nextservice);
2234 mlt_type = mlt_properties_get(properties, "mlt_type");
2235 resource = mlt_properties_get(properties, "mlt_service");
2237 m_isBlocked = false;
2238 mlt_service_unlock(service.get_service());
2239 m_mltConsumer->set("refresh", 1);
2243 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2244 Mlt::Service service(m_mltProducer->parent().get_service());
2245 Mlt::Tractor tractor(service);
2246 Mlt::Field *field = tractor.field();
2248 mlt_service_lock(service.get_service());
2249 m_mltConsumer->set("refresh", 0);
2252 mlt_service serv = m_mltProducer->parent().get_service();
2253 mlt_service nextservice = mlt_service_get_producer(serv);
2254 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2255 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2256 QString resource = mlt_properties_get(properties, "mlt_service");
2258 while (mlt_type == "transition") {
2259 mlt_transition tr = (mlt_transition) nextservice;
2260 int currentTrack = mlt_transition_get_b_track(tr);
2261 int currentaTrack = mlt_transition_get_a_track(tr);
2262 int currentIn = (int) mlt_transition_get_in(tr);
2263 int currentOut = (int) mlt_transition_get_out(tr);
2264 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2265 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2266 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2267 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2268 kDebug() << "//////MOVING";
2269 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2270 if (endTrack != startTrack) {
2271 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2272 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2273 mlt_properties_set_int(properties, "b_track", endTrack);
2277 nextservice = mlt_service_producer(nextservice);
2278 if (nextservice == NULL) break;
2279 properties = MLT_SERVICE_PROPERTIES(nextservice);
2280 mlt_type = mlt_properties_get(properties, "mlt_type");
2281 resource = mlt_properties_get(properties, "mlt_service");
2283 m_isBlocked = false;
2284 mlt_service_unlock(service.get_service());
2285 m_mltConsumer->set("refresh", 1);
2289 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2291 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2292 Mlt::Service service(m_mltProducer->parent().get_service());
2294 Mlt::Tractor tractor(service);
2295 Mlt::Field *field = tractor.field();
2297 char *transId = decodedString(tag);
2298 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2299 if (out != GenTime())
2300 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
2301 QMap<QString, QString>::Iterator it;
2304 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2306 for (it = args.begin(); it != args.end(); ++it) {
2308 char *name = decodedString(key);
2309 char *value = decodedString(it.value());
2310 transition->set(name, value);
2311 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2312 //filter->set("kdenlive_id", id);
2316 // attach filter to the clip
2317 field->plant_transition(*transition, a_track, b_track);
2322 void Render::mltSavePlaylist() {
2323 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2324 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2325 fileConsumer.set("resource", "/tmp/playlist.westley");
2327 Mlt::Service service(m_mltProducer->get_service());
2329 fileConsumer.connect(service);
2330 fileConsumer.start();
2333 QList <Mlt::Producer *> Render::producersList() {
2334 QList <Mlt::Producer *> prods;
2336 Mlt::Service service(m_mltProducer->parent().get_service());
2337 Mlt::Tractor tractor(service);
2338 Mlt::Field *field = tractor.field();
2340 int trackNb = tractor.count();
2341 for (int t = 1; t < trackNb; t++) {
2342 Mlt::Producer trackProducer(tractor.track(t));
2343 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2344 int clipNb = trackPlaylist.count();
2345 kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2346 for (int i = 0; i < clipNb; i++) {
2347 Mlt::Producer *prod = trackPlaylist.get_clip(i);
2348 Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
2349 //kDebug()<<"PROD: "<<nprod->get("producer")<<", ID: "<<nprod->get("id")<<nprod->get("resource");
2350 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2351 ids.append(nprod->get("id"));
2352 prods.append(nprod);
2359 #include "renderer.moc"