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");
124 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
125 m_mltConsumer->set("resize", 1);
126 m_mltConsumer->set("window_id", m_winid);
127 m_mltConsumer->set("terminate_on_pause", 1);
128 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
129 m_mltConsumer->set("rescale", "nearest");
131 QString audioDevice = KdenliveSettings::audiodevicename();
132 if (!audioDevice.isEmpty()) {
133 tmp = decodedString(audioDevice);
134 m_mltConsumer->set("audio_device", tmp);
138 if (!videoDriver.isEmpty()) {
139 tmp = decodedString(videoDriver);
140 m_mltConsumer->set("video_driver", tmp);
144 QString audioDriver = KdenliveSettings::audiodrivername();
145 if (!audioDriver.isEmpty()) {
146 tmp = decodedString(audioDriver);
147 m_mltConsumer->set("audio_driver", tmp);
152 m_mltConsumer->set("progressive", 1);
153 m_mltConsumer->set("audio_buffer", 1024);
154 m_mltConsumer->set("frequency", 48000);
157 int Render::resetProfile() {
158 if (!m_mltConsumer) return 0;
159 QString currentProfile = getenv("MLT_PROFILE");
160 if (currentProfile == KdenliveSettings::current_profile()) {
161 kDebug() << "reset to same profile, nothing to do";
164 if (m_isSplitView) slotSplitView(false);
165 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
166 m_mltConsumer->purge();
167 delete m_mltConsumer;
168 m_mltConsumer = NULL;
169 QString scene = sceneList();
170 if (m_mltProducer) delete m_mltProducer;
171 m_mltProducer = NULL;
172 if (m_mltProfile) delete m_mltProfile;
176 kDebug() << "//RESET WITHSCENE: " << scene;
179 char *tmp = decodedString(scene);
180 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
182 m_mltProducer = producer;
183 if (m_blackClip) delete m_blackClip;
184 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
185 m_mltProducer->optimise();
186 m_mltProducer->set_speed(0);
189 //delete m_mltProfile;
190 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
191 //mlt_profile prof = m_mltProfile->get_profile();
192 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
193 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
194 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
195 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
197 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
202 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
203 void Render::seek(GenTime time) {
206 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
207 m_mltProducer->seek((int)(time.frames(m_fps)));
212 char *Render::decodedString(QString str) {
213 /*QCString fn = QFile::encodeName(str);
214 char *t = new char[fn.length() + 1];
215 strcpy(t, (const char *)fn);*/
217 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
221 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
222 QPixmap pix(width, height);
224 mlt_image_format format = mlt_image_rgb24a;
225 uint8_t *thumb = frame->get_image(format, width, height);
226 QImage image(thumb, width, height, QImage::Format_ARGB32);
228 if (!image.isNull()) {
229 pix = pix.fromImage(image);
231 QPainter painter(&pix);
232 painter.drawRect(0, 0, width - 1, height - 1);
234 } else pix.fill(Qt::black);
238 const int Render::renderWidth() const {
239 return (int)(m_mltProfile->height() * m_mltProfile->dar());
242 const int Render::renderHeight() const {
243 return m_mltProfile->height();
246 QPixmap Render::extractFrame(int frame_position, int width, int height) {
248 width = renderWidth();
249 height = renderHeight();
251 QPixmap pix(width, height);
252 if (!m_mltProducer) {
256 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
259 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
262 if (url.fileName().startsWith(".all.")) { // check for slideshow
263 QString fileType = url.fileName().right(3);
265 QStringList::Iterator it;
267 QDir dir(url.directory());
269 filter << "*." + fileType;
270 filter << "*." + fileType.toUpper();
271 more = dir.entryList(filter, QDir::Files);
272 im.load(url.directory() + "/" + more.at(0));
273 } else im.load(url.path());
274 //pixmap = im.scaled(width, height);
279 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
280 QPixmap pix(width, height);
281 char *tmp = decodedString(file);
282 Mlt::Profile *prof = new Mlt::Profile(profile);
283 Mlt::Producer m_producer(*prof, tmp);
285 if (m_producer.is_blank()) {
290 Mlt::Filter m_convert(*prof, "avcolour_space");
291 m_convert.set("forced", mlt_image_rgb24a);
292 m_producer.attach(m_convert);
293 m_producer.seek(frame_position);
294 Mlt::Frame * frame = m_producer.get_frame();
296 pix = frameThumbnail(frame, width, height, true);
299 if (prof) delete prof;
304 void Render::getImage(KUrl url, int frame_position, QPoint size)
306 char *tmp = decodedString(url.path());
307 Mlt::Producer m_producer(tmp);
309 if (m_producer.is_blank()) {
312 Mlt::Filter m_convert("avcolour_space");
313 m_convert.set("forced", mlt_image_rgb24a);
314 m_producer.attach(m_convert);
315 m_producer.seek(frame_position);
317 Mlt::Frame * frame = m_producer.get_frame();
320 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
322 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
326 /* Create thumbnail for color */
327 /*void Render::getImage(int id, QString color, QPoint size)
329 QPixmap pixmap(size.x() - 2, size.y() - 2);
330 color = color.replace(0, 2, "#");
331 color = color.left(7);
332 pixmap.fill(QColor(color));
333 QPixmap result(size.x(), size.y());
334 result.fill(Qt::black);
335 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
336 emit replyGetImage(id, result, size.x(), size.y());
340 /* Create thumbnail for image */
341 /*void Render::getImage(KUrl url, QPoint size)
345 if (url.fileName().startsWith(".all.")) { // check for slideshow
346 QString fileType = url.fileName().right(3);
348 QStringList::Iterator it;
350 QDir dir( url.directory() );
351 more = dir.entryList( QDir::Files );
352 for ( it = more.begin() ; it != more.end() ; ++it ) {
353 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
354 if (!im.load(url.directory() + "/" + *it))
355 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
360 else im.load(url.path());
362 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
363 QPixmap result(size.x(), size.y());
364 result.fill(Qt::black);
365 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
366 emit replyGetImage(url, 1, result, size.x(), size.y());
370 double Render::consumerRatio() const {
371 if (!m_mltConsumer) return 1.0;
372 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
376 int Render::getLength() {
379 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
380 return mlt_producer_get_playtime(m_mltProducer->get_producer());
385 bool Render::isValid(KUrl url) {
386 char *tmp = decodedString(url.path());
387 Mlt::Producer producer(*m_mltProfile, tmp);
389 if (producer.is_blank())
395 const double Render::dar() const {
396 return m_mltProfile->dar();
399 void Render::slotSplitView(bool doit) {
400 m_isSplitView = doit;
401 Mlt::Service service(m_mltProducer->parent().get_service());
402 Mlt::Tractor tractor(service);
403 if (service.type() != tractor_type || tractor.count() < 2) return;
404 Mlt::Field *field = tractor.field();
407 for (int i = 1; i < tractor.count() && screen < 4; i++) {
408 Mlt::Producer trackProducer(tractor.track(i));
409 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
410 if (QString(trackProducer.get("hide")).toInt() != 1) {
411 kDebug() << "// ADIDNG TRACK: " << i;
412 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
413 transition->set("mlt_service", "composite");
414 transition->set("a_track", 0);
415 transition->set("b_track", i);
416 transition->set("distort", 1);
417 transition->set("internal_added", "200");
424 tmp = "50%,0:50%x50%";
427 tmp = "0,50%:50%x50%";
430 tmp = "50%,50%:50%x50%";
433 transition->set("geometry", tmp);
434 transition->set("always_active", "1");
435 field->plant_transition(*transition, 0, i);
440 m_mltConsumer->set("refresh", 1);
442 mlt_service serv = m_mltProducer->parent().get_service();
443 mlt_service nextservice = mlt_service_get_producer(serv);
444 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
445 QString mlt_type = mlt_properties_get(properties, "mlt_type");
446 QString resource = mlt_properties_get(properties, "mlt_service");
448 while (mlt_type == "transition") {
449 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
450 if (added == "200") {
451 mlt_field_disconnect_service(field->get_field(), nextservice);
453 nextservice = mlt_service_producer(nextservice);
454 if (nextservice == NULL) break;
455 properties = MLT_SERVICE_PROPERTIES(nextservice);
456 mlt_type = mlt_properties_get(properties, "mlt_type");
457 resource = mlt_properties_get(properties, "mlt_service");
458 m_mltConsumer->set("refresh", 1);
463 void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
465 int width = (int)(height * m_mltProfile->dar());
466 QMap < QString, QString > filePropertyMap;
467 QMap < QString, QString > metadataPropertyMap;
469 KUrl url = KUrl(xml.attribute("resource", QString::null));
470 Mlt::Producer *producer;
471 if (xml.attribute("type").toInt() == COLOR) {
472 char *tmp = decodedString("colour:" + xml.attribute("colour"));
473 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
475 } else if (url.isEmpty()) {
477 QDomElement westley = doc.createElement("westley");
478 QDomElement play = doc.createElement("playlist");
479 doc.appendChild(westley);
480 westley.appendChild(play);
481 play.appendChild(doc.importNode(xml, true));
482 kDebug() << "/ / / / /CLIP XML: " << doc.toString();
483 char *tmp = decodedString(doc.toString());
484 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
487 char *tmp = decodedString(url.path());
488 producer = new Mlt::Producer(*m_mltProfile, tmp);
491 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
493 if (producer->is_blank()) {
494 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
495 emit removeInvalidClip(clipId);
498 char *tmp = decodedString(clipId);
499 producer->set("id", tmp);
501 int frameNumber = xml.attribute("thumbnail", "0").toInt();
502 if (frameNumber != 0) producer->seek(frameNumber);
503 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
505 filePropertyMap["filename"] = url.path();
506 filePropertyMap["duration"] = QString::number(producer->get_playtime());
507 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
509 Mlt::Frame * frame = producer->get_frame();
511 if (xml.attribute("type").toInt() == SLIDESHOW) {
512 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
513 if (xml.attribute("fade") == "1") {
514 // user wants a fade effect to slideshow
515 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
516 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
517 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
518 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
519 char *tmp = decodedString(xml.attribute("luma_file"));
520 filter->set("luma.resource", tmp);
522 if (xml.hasAttribute("softness")) {
523 int soft = xml.attribute("softness").toInt();
524 filter->set("luma.softness", (double) soft / 100.0);
527 Mlt::Service clipService(producer->get_service());
528 clipService.attach(*filter);
533 filePropertyMap["fps"] = producer->get("source_fps");
535 if (frame && frame->is_valid()) {
536 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
537 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
538 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
539 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
541 if (frame->get_int("test_image") == 0) {
542 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
543 filePropertyMap["type"] = "playlist";
544 metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer->get_service()), "title"));
545 } else if (frame->get_int("test_audio") == 0)
546 filePropertyMap["type"] = "av";
548 filePropertyMap["type"] = "video";
550 mlt_image_format format = mlt_image_yuv422;
552 int frame_height = 0;
553 //frame->set("rescale.interp", "hyper");
554 frame->set("normalised_height", height);
555 frame->set("normalised_width", width);
556 QPixmap pix(width, height);
558 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
559 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
560 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
561 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
563 if (!image.isNull()) {
564 pix = QPixmap::fromImage(image.rgbSwapped());
568 mlt_pool_release(new_image);
569 emit replyGetImage(clipId, 0, pix, width, height);
571 } else if (frame->get_int("test_audio") == 0) {
572 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
573 emit replyGetImage(clipId, 0, pixmap, width, height);
574 filePropertyMap["type"] = "audio";
578 // Retrieve audio / video codec name
580 // Fetch the video_context
583 AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
584 if (context != NULL) {
585 /*if (context->duration == AV_NOPTS_VALUE) {
586 kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
587 emit removeInvalidClip(clipId);
590 // Get the video_index
591 int index = mlt_properties_get_int(properties, "video_index");
593 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
594 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) {
595 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name;
598 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) {
599 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
601 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
602 context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
603 if (context != NULL) {
604 // Get the audio_index
605 int index = mlt_properties_get_int(properties, "audio_index");
607 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
608 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
609 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name;
612 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
613 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
618 mlt_properties metadata = mlt_properties_new();
619 mlt_properties_pass(metadata, properties, "meta.attr.");
620 int count = mlt_properties_count(metadata);
621 for (int i = 0; i < count; i ++) {
622 QString name = mlt_properties_get_name(metadata, i);
623 QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
624 if (name.endsWith("markup") && !value.isEmpty())
625 metadataPropertyMap[ name.section(".", 0, -2)] = value;
628 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
629 kDebug() << "REquested fuile info for: " << url.path();
630 if (frame) delete frame;
631 //if (producer) delete producer;
634 /** Create the producer from the Westley QDomDocument */
636 void Render::initSceneList() {
637 kDebug() << "-------- INIT SCENE LIST ------_";
639 QDomElement westley = doc.createElement("westley");
640 doc.appendChild(westley);
641 QDomElement prod = doc.createElement("producer");
642 prod.setAttribute("resource", "colour");
643 prod.setAttribute("colour", "red");
644 prod.setAttribute("id", "black");
645 prod.setAttribute("in", "0");
646 prod.setAttribute("out", "0");
648 QDomElement tractor = doc.createElement("tractor");
649 QDomElement multitrack = doc.createElement("multitrack");
651 QDomElement playlist1 = doc.createElement("playlist");
652 playlist1.appendChild(prod);
653 multitrack.appendChild(playlist1);
654 QDomElement playlist2 = doc.createElement("playlist");
655 multitrack.appendChild(playlist2);
656 QDomElement playlist3 = doc.createElement("playlist");
657 multitrack.appendChild(playlist3);
658 QDomElement playlist4 = doc.createElement("playlist");
659 multitrack.appendChild(playlist4);
660 QDomElement playlist5 = doc.createElement("playlist");
661 multitrack.appendChild(playlist5);
662 tractor.appendChild(multitrack);
663 westley.appendChild(tractor);
664 // kDebug()<<doc.toString();
666 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
667 setSceneList(doc, 0);
673 /** Create the producer from the Westley QDomDocument */
674 void Render::setProducer(Mlt::Producer *producer, int position) {
675 if (m_winid == -1) return;
678 m_mltConsumer->stop();
683 m_mltProducer->set_speed(0);
684 delete m_mltProducer;
685 m_mltProducer = NULL;
688 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
689 else m_mltProducer = new Mlt::Producer();
690 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
692 m_fps = m_mltProducer->get_fps();
694 if (position != -1) {
695 m_mltProducer->seek(position);
696 emit rendererPosition(position);
703 /** Create the producer from the Westley QDomDocument */
704 void Render::setSceneList(QDomDocument list, int position) {
705 setSceneList(list.toString(), position);
708 /** Create the producer from the Westley QDomDocument */
709 void Render::setSceneList(QString playlist, int position) {
710 if (m_winid == -1) return;
713 kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
716 m_mltConsumer->stop();
717 //m_mltConsumer->set("refresh", 0);
721 m_mltProducer->set_speed(0);
722 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
724 delete m_mltProducer;
725 m_mltProducer = NULL;
729 char *tmp = decodedString(playlist);
730 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
732 if (m_blackClip) delete m_blackClip;
733 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
734 m_blackClip->set("id", "black");
735 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
736 m_mltProducer->optimise();
738 /*if (KdenliveSettings::osdtimecode()) {
739 // Attach filter for on screen display of timecode
741 QString attr = "attr_check";
742 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
743 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
744 mlt_producer_attach( m_mltProducer->get_producer(), filter );
745 mlt_filter_close( filter );
747 m_osdInfo = new Mlt::Filter("data_show");
748 tmp = decodedString(m_osdProfile);
749 m_osdInfo->set("resource", tmp);
751 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
752 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
753 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
754 m_osdInfo->set("dynamic", "1");
756 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
758 m_osdInfo->set("dynamic", "0");
761 m_fps = m_mltProducer->get_fps();
762 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
765 //TODO: seek to correct place after opening project.
766 // Needs to be done from another place since it crashes here.
767 //m_mltProducer->seek(position);
768 //emit rendererPosition(position);
774 /** Create the producer from the Westley QDomDocument */
775 QString Render::sceneList() {
780 saveSceneList(temp.fileName());
781 QFile file(temp.fileName());
782 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
783 kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE";
786 QTextStream in(&file);
787 while (!in.atEnd()) {
788 result.append(in.readLine());
794 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
796 char *tmppath = decodedString("westley:" + path);
797 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
798 m_mltProducer->optimise();
800 westleyConsumer.set("terminate_on_pause", 1);
801 Mlt::Producer prod(m_mltProducer->get_producer());
802 bool split = m_isSplitView;
803 if (split) slotSplitView(false);
804 westleyConsumer.connect(prod);
805 //prod.set("title", "kdenlive document");
806 westleyConsumer.start();
807 while (!westleyConsumer.is_stopped()) {}
808 if (!kdenliveData.isNull()) {
809 // add Kdenlive specific tags
812 doc.setContent(&file, false);
813 QDomNode wes = doc.elementsByTagName("westley").at(0);
814 wes.appendChild(doc.importNode(kdenliveData, true));
816 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
817 kWarning() << "////// ERROR writing to file: " << path;
820 QTextStream out(&file);
821 out << doc.toString();
824 if (split) slotSplitView(true);
828 void Render::saveZone(KUrl url, QString desc, QPoint zone) {
829 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
830 char *tmppath = decodedString("westley:" + url.path());
831 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
832 m_mltProducer->optimise();
834 westleyConsumer.set("terminate_on_pause", 1);
835 if (m_name == "clip") {
836 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
837 tmppath = decodedString(desc);
839 list.insert_at(0, prod, 0);
840 list.set("title", tmppath);
842 westleyConsumer.connect(list);
845 //TODO: not working yet, save zone from timeline
846 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
847 /* Mlt::Service service(p1->parent().get_service());
848 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
850 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
851 tmppath = decodedString(desc);
852 //prod->set("title", tmppath);
854 westleyConsumer.connect(*p1); //list);
857 westleyConsumer.start();
860 const double Render::fps() const {
864 void Render::connectPlaylist() {
865 if (!m_mltConsumer) return;
866 //m_mltConsumer->set("refresh", "0");
867 m_mltConsumer->connect(*m_mltProducer);
868 m_mltProducer->set_speed(0);
869 m_mltConsumer->start();
870 emit durationChanged(m_mltProducer->get_playtime());
873 if (m_mltConsumer->start() == -1) {
874 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."));
875 m_mltConsumer = NULL;
882 void Render::refreshDisplay() {
884 if (!m_mltProducer) return;
885 //m_mltConsumer->set("refresh", 0);
887 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
888 /*if (KdenliveSettings::osdtimecode()) {
889 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
890 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
891 m_osdInfo->set("dynamic", "1");
892 m_mltProducer->attach(*m_osdInfo);
895 m_mltProducer->detach(*m_osdInfo);
896 m_osdInfo->set("dynamic", "0");
901 void Render::setVolume(double volume) {
902 if (!m_mltConsumer || !m_mltProducer) return;
904 m_mltConsumer->set("refresh", 0);
905 // Attach filter for on screen display of timecode
906 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
907 mlt_properties_set_double( properties, "meta.volume", volume );
908 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
909 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
911 if (!KdenliveSettings::osdtimecode()) {
912 m_mltProducer->detach(*m_osdInfo);
913 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
914 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
917 osdTimer->setSingleShot(2500);
920 void Render::slotOsdTimeout() {
921 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
922 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
923 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
924 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
928 void Render::start() {
929 kDebug() << "----- STARTING MONITOR: " << m_name;
931 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
935 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
936 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
937 if (m_mltConsumer->start() == -1) {
938 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."));
939 m_mltConsumer = NULL;
942 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
950 void Render::clear() {
951 kDebug() << " ********* RENDER CLEAR";
953 //m_mltConsumer->set("refresh", 0);
954 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
958 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
959 m_mltProducer->set_speed(0.0);
960 delete m_mltProducer;
961 m_mltProducer = NULL;
966 void Render::stop() {
967 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
968 kDebug() << "///////////// RENDER STOPPED: " << m_name;
970 m_mltConsumer->set("refresh", 0);
971 m_mltConsumer->stop();
972 // delete m_mltConsumer;
973 // m_mltConsumer = NULL;
975 kDebug() << "///////////// RENDER STOP2-------";
979 if (m_isZoneMode) resetZoneMode();
980 m_mltProducer->set_speed(0.0);
981 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
982 //kDebug() << m_mltProducer->get_length();
984 kDebug() << "///////////// RENDER STOP3-------";
987 void Render::stop(const GenTime & startTime) {
989 kDebug() << "///////////// RENDER STOP-------2";
991 if (m_isZoneMode) resetZoneMode();
992 m_mltProducer->set_speed(0.0);
993 m_mltProducer->seek((int) startTime.frames(m_fps));
995 m_mltConsumer->purge();
998 void Render::switchPlay() {
999 if (!m_mltProducer || !m_mltConsumer)
1001 if (m_isZoneMode) resetZoneMode();
1002 if (m_mltProducer->get_speed() == 0.0) {
1003 //m_isBlocked = false;
1004 m_mltProducer->set_speed(1.0);
1005 m_mltConsumer->set("refresh", 1);
1006 kDebug() << " ********* RENDER PLAY: " << m_mltProducer->get_speed();
1008 //m_isBlocked = true;
1009 m_mltConsumer->set("refresh", 0);
1010 m_mltProducer->set_speed(0.0);
1011 //m_isBlocked = true;
1012 m_mltProducer->seek((int) m_framePosition);
1013 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1014 //m_mltConsumer->set("refresh", 0);
1015 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1016 m_mltProducer->set_speed(0);
1017 m_mltProducer->seek( position );
1018 //m_mltProducer->seek((int) m_framePosition);
1019 m_isBlocked = false;*/
1021 /*if (speed == 0.0) {
1022 m_mltProducer->seek((int) m_framePosition + 1);
1023 m_mltConsumer->purge();
1028 void Render::play(double speed) {
1029 kDebug() << " ********* REDNER PLAY";
1032 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1033 m_mltProducer->set_speed(speed);
1034 /*if (speed == 0.0) {
1035 m_mltProducer->seek((int) m_framePosition + 1);
1036 m_mltConsumer->purge();
1041 void Render::play(const GenTime & startTime) {
1042 if (!m_mltProducer || !m_mltConsumer)
1044 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1045 m_mltProducer->set_speed(1.0);
1046 m_mltConsumer->set("refresh", 1);
1049 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1050 if (!m_mltProducer || !m_mltConsumer)
1052 //m_mltProducer->set("eof", "loop");
1053 m_isLoopMode = true;
1054 m_loopStart = startTime;
1055 playZone(startTime, stopTime);
1058 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1059 if (!m_mltProducer || !m_mltConsumer)
1061 m_mltProducer->set("out", stopTime.frames(m_fps));
1062 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1063 m_mltProducer->set_speed(1.0);
1064 m_mltConsumer->set("refresh", 1);
1065 m_isZoneMode = true;
1068 void Render::resetZoneMode() {
1069 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1070 //m_mltProducer->set("eof", "pause");
1071 m_isZoneMode = false;
1072 m_isLoopMode = false;
1075 void Render::seekToFrame(int pos) {
1076 //kDebug()<<" ********* RENDER SEEK TO POS";
1080 m_mltProducer->seek(pos);
1084 void Render::askForRefresh() {
1085 // Use a Timer so that we don't refresh too much
1086 refreshTimer->start(200);
1089 void Render::doRefresh() {
1090 // Use a Timer so that we don't refresh too much
1091 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1094 void Render::refresh() {
1095 if (!m_mltProducer || m_isBlocked)
1097 refreshTimer->stop();
1098 if (m_mltConsumer) {
1099 m_mltConsumer->set("refresh", 1);
1103 double Render::playSpeed() {
1104 if (m_mltProducer) return m_mltProducer->get_speed();
1108 GenTime Render::seekPosition() const {
1109 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1110 else return GenTime();
1114 const QString & Render::rendererName() const {
1119 void Render::emitFrameNumber(double position) {
1120 m_framePosition = position;
1121 emit rendererPosition((int) position);
1122 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1125 void Render::emitConsumerStopped() {
1126 // This is used to know when the playing stopped
1127 if (m_mltProducer) {
1128 double pos = m_mltProducer->position();
1129 if (m_isLoopMode) play(m_loopStart);
1130 else if (m_isZoneMode) resetZoneMode();
1131 emit rendererStopped((int) pos);
1132 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1133 //new QCustomEvent(10002));
1139 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1140 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1144 void Render::exportCurrentFrame(KUrl url, bool notify) {
1145 if (!m_mltProducer) {
1146 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1150 int height = 1080;//KdenliveSettings::defaultheight();
1151 int width = 1940; //KdenliveSettings::displaywidth();
1153 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1155 QPixmap pix(width, height);
1156 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1157 m_convert.set("forced", mlt_image_rgb24a);
1158 m_mltProducer->attach(m_convert);
1159 Mlt::Frame * frame = m_mltProducer->get_frame();
1160 m_mltProducer->detach(m_convert);
1162 pix = frameThumbnail(frame, width, height);
1165 pix.save(url.path(), "PNG");
1166 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1169 /** MLT PLAYLIST DIRECT MANIPULATON **/
1172 void Render::mltCheckLength(bool reload) {
1173 //kDebug()<<"checking track length: "<<track<<"..........";
1175 Mlt::Service service(m_mltProducer->get_service());
1176 Mlt::Tractor tractor(service);
1178 int trackNb = tractor.count();
1179 double duration = 0;
1180 double trackDuration;
1182 Mlt::Producer trackProducer(tractor.track(0));
1183 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1184 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1185 m_mltProducer->set("out", duration);
1186 emit durationChanged((int) duration);
1189 while (trackNb > 1) {
1190 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1191 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1192 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1194 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1195 if (trackDuration > duration) duration = trackDuration;
1199 Mlt::Producer blackTrackProducer(tractor.track(0));
1200 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1201 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1203 if (blackDuration != duration) {
1204 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1206 int dur = (int)duration;
1208 QDomElement black = doc.createElement("producer");
1209 black.setAttribute("mlt_service", "colour");
1210 black.setAttribute("colour", "black");
1211 black.setAttribute("id", "black");
1214 while (dur > 14000) {
1215 info.startPos = GenTime(i * 14000, m_fps);
1216 info.endPos = info.startPos + GenTime(13999, m_fps);
1217 mltInsertClip(info, black, m_blackClip);
1222 info.startPos = GenTime(i * 14000, m_fps);
1223 info.endPos = info.startPos + GenTime(dur, m_fps);
1224 mltInsertClip(info, black, m_blackClip);
1226 m_mltProducer->set("out", duration);
1227 emit durationChanged((int)duration);
1231 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1232 if (!m_mltProducer) {
1233 kDebug() << "PLAYLIST NOT INITIALISED //////";
1236 Mlt::Producer parentProd(m_mltProducer->parent());
1237 if (parentProd.get_producer() == NULL) {
1238 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1242 Mlt::Service service(parentProd.get_service());
1243 Mlt::Tractor tractor(service);
1244 mlt_service_lock(service.get_service());
1245 Mlt::Producer trackProducer(tractor.track(info.track));
1246 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1247 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1248 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1249 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1251 if (QString(prod->get("transparency")).toInt() == 1)
1252 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());
1254 mlt_service_unlock(service.get_service());
1256 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1257 //tractor.multitrack()->refresh();
1258 //tractor.refresh();
1262 void Render::mltCutClip(int track, GenTime position) {
1266 Mlt::Service service(m_mltProducer->parent().get_service());
1267 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1269 Mlt::Tractor tractor(service);
1270 Mlt::Producer trackProducer(tractor.track(track));
1271 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1274 /* // Display playlist info
1275 kDebug()<<"//////////// BEFORE";
1276 for (int i = 0; i < trackPlaylist.count(); i++) {
1277 int blankStart = trackPlaylist.clip_start(i);
1278 int blankDuration = trackPlaylist.clip_length(i) - 1;
1280 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1281 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1284 int cutPos = (int) position.frames(m_fps);
1286 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1287 if (trackPlaylist.is_blank(clipIndex)) {
1288 kDebug() << "// WARMNING, TRYING TO CUT A BLANK";
1289 m_isBlocked = false;
1292 mlt_service_lock(service.get_service());
1293 int clipStart = trackPlaylist.clip_start(clipIndex);
1294 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1296 // duplicate effects
1297 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1298 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1300 if (original == NULL || clip == NULL) {
1301 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1303 Mlt::Service clipService(original->get_service());
1304 Mlt::Service dupService(clip->get_service());
1306 Mlt::Filter *filter = clipService.filter(ct);
1308 if (filter->get("kdenlive_id") != "") {
1309 kDebug() << "++ ADDING FILTER: " << filter->get("kdenlive_id");
1310 Mlt::Filter *dup = new Mlt::Filter(filter->get_filter());
1311 dup->set("kdenlive_ix", filter->get("kdenlive_ix"));
1312 dup->set("kdenlive_id", filter->get("kdenlive_id"));
1313 dupService.attach(*dup);
1316 filter = clipService.filter(ct);
1318 mlt_service_unlock(service.get_service());
1320 /* // Display playlist info
1321 kDebug()<<"//////////// AFTER";
1322 for (int i = 0; i < trackPlaylist.count(); i++) {
1323 int blankStart = trackPlaylist.clip_start(i);
1324 int blankDuration = trackPlaylist.clip_length(i) - 1;
1326 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1327 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1330 m_isBlocked = false;
1333 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1335 mltRemoveClip(info.track, info.startPos);
1336 mltInsertClip(info, element, prod);
1340 bool Render::mltRemoveClip(int track, GenTime position) {
1341 Mlt::Service service(m_mltProducer->parent().get_service());
1342 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1344 Mlt::Tractor tractor(service);
1345 Mlt::Producer trackProducer(tractor.track(track));
1346 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1347 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1349 /* // Display playlist info
1350 kDebug()<<"//// BEFORE";
1351 for (int i = 0; i < trackPlaylist.count(); i++) {
1352 int blankStart = trackPlaylist.clip_start(i);
1353 int blankDuration = trackPlaylist.clip_length(i) - 1;
1355 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1356 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1359 if (trackPlaylist.is_blank(clipIndex)) {
1360 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1364 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1365 trackPlaylist.replace_with_blank(clipIndex);
1366 trackPlaylist.consolidate_blanks(0);
1367 if (QString(clip.parent().get("transparency")).toInt() == 1)
1368 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());
1370 /* // Display playlist info
1371 kDebug()<<"//// AFTER";
1372 for (int i = 0; i < trackPlaylist.count(); i++) {
1373 int blankStart = trackPlaylist.clip_start(i);
1374 int blankDuration = trackPlaylist.clip_length(i) - 1;
1376 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1377 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1380 if (track != 0 && trackPlaylist.count() > clipIndex) mltCheckLength();
1381 m_isBlocked = false;
1385 int Render::mltChangeClipSpeed(ItemInfo info, double speed, Mlt::Producer *prod) {
1388 Mlt::Service service(m_mltProducer->parent().get_service());
1389 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1390 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1391 Mlt::Tractor tractor(service);
1392 Mlt::Producer trackProducer(tractor.track(info.track));
1393 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1394 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1395 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1396 QString serv = clip.parent().get("mlt_service");
1397 QString id = clip.parent().get("id");
1398 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1399 if (serv == "avformat" && speed != 1.0) {
1400 mlt_service_lock(service.get_service());
1401 QString url = clip.parent().get("resource");
1402 url.append("?" + QString::number(speed));
1403 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1404 if (!slowprod || slowprod->get_producer() == NULL) {
1405 char *tmp = decodedString(url);
1406 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1408 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1409 tmp = decodedString(producerid);
1410 slowprod->set("id", tmp);
1412 m_slowmotionProducers.insert(url, slowprod);
1414 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1415 newLength = cut->get_length();
1416 trackPlaylist.replace_with_blank(clipIndex);
1417 trackPlaylist.consolidate_blanks(0);
1418 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1419 mlt_service_unlock(service.get_service());
1420 } else if (speed == 1.0) {
1421 mlt_service_lock(service.get_service());
1422 Mlt::Producer *cut = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1423 trackPlaylist.replace_with_blank(clipIndex);
1424 newLength = cut->get_length();
1425 trackPlaylist.consolidate_blanks(0);
1426 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1427 mlt_service_unlock(service.get_service());
1428 } else if (serv == "framebuffer") {
1429 mlt_service_lock(service.get_service());
1430 QString url = clip.parent().get("resource");
1431 url = url.section("?", 0, 0);
1432 url.append("?" + QString::number(speed));
1433 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1434 if (!slowprod || slowprod->get_producer() == NULL) {
1435 char *tmp = decodedString(url);
1436 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1438 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1439 tmp = decodedString(producerid);
1440 slowprod->set("id", tmp);
1442 m_slowmotionProducers.insert(url, slowprod);
1444 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1445 newLength = cut->get_length();
1446 trackPlaylist.replace_with_blank(clipIndex);
1447 trackPlaylist.consolidate_blanks(0);
1448 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1449 mlt_service_unlock(service.get_service());
1450 kDebug() << "AVFORMAT CLIP!!!:";
1453 m_isBlocked = false;
1457 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1459 Mlt::Service service(m_mltProducer->parent().get_service());
1460 bool success = false;
1461 Mlt::Tractor tractor(service);
1462 Mlt::Producer trackProducer(tractor.track(track));
1463 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1464 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1465 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1467 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1470 Mlt::Service clipService(clip->get_service());
1471 // if (tag.startsWith("ladspa")) tag = "ladspa";
1474 Mlt::Filter *filter = clipService.filter(ct);
1476 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1477 if (clipService.detach(*filter) == 0) success = true;
1478 kDebug() << " / / / DLEETED EFFECT: " << ct;
1480 filter = clipService.filter(ct);
1482 m_isBlocked = false;
1483 if (doRefresh) refresh();
1488 bool Render::mltAddEffect(int track, GenTime position, QHash <QString, QString> args, bool doRefresh) {
1490 Mlt::Service service(m_mltProducer->parent().get_service());
1492 Mlt::Tractor tractor(service);
1493 Mlt::Producer trackProducer(tractor.track(track));
1494 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1496 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1500 Mlt::Service clipService(clip->get_service());
1503 QString tag = args.value("tag");
1504 kDebug() << " / / INSERTING EFFECT: " << tag;
1505 if (tag.startsWith("ladspa")) tag = "ladspa";
1506 char *filterTag = decodedString(tag);
1507 char *filterId = decodedString(args.value("id"));
1508 QHash<QString, QString>::Iterator it;
1509 QString kfr = args.value("keyframes");
1511 if (!kfr.isEmpty()) {
1512 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1513 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1514 char *starttag = decodedString(args.value("starttag", "start"));
1515 char *endtag = decodedString(args.value("endtag", "end"));
1516 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1517 int duration = clip->get_playtime();
1518 double max = args.value("max").toDouble();
1519 double min = args.value("min").toDouble();
1520 double factor = args.value("factor", "1").toDouble();
1521 args.remove("starttag");
1522 args.remove("endtag");
1523 args.remove("keyframes");
1526 args.remove("factor");
1528 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1529 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1530 filter->set("kdenlive_id", filterId);
1531 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1532 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1533 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1534 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1535 if (x2 == -1) x2 = duration;
1536 for (it = args.begin(); it != args.end(); ++it) {
1537 char *name = decodedString(it.key());
1538 char *value = decodedString(it.value());
1539 filter->set(name, value);
1544 filter->set("in", x1);
1545 filter->set("out", x2);
1546 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1547 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1548 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1549 clipService.attach(*filter);
1555 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1556 if (filter && filter->is_valid())
1557 filter->set("kdenlive_id", filterId);
1559 kDebug() << "filter is NULL";
1560 m_isBlocked = false;
1564 for (it = args.begin(); it != args.end(); ++it) {
1565 char *name = decodedString(it.key());
1566 char *value = decodedString(it.value());
1567 filter->set(name, value);
1571 // attach filter to the clip
1572 clipService.attach(*filter);
1576 m_isBlocked = false;
1577 if (doRefresh) refresh();
1581 bool Render::mltEditEffect(int track, GenTime position, QHash <QString, QString> args) {
1582 QString index = args.value("kdenlive_ix");
1583 QString tag = args.value("tag");
1584 QHash<QString, QString>::Iterator it = args.begin();
1585 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1586 // This is a keyframe effect, to edit it, we remove it and re-add it.
1587 mltRemoveEffect(track, position, index);
1588 bool success = mltAddEffect(track, position, args);
1593 Mlt::Service service(m_mltProducer->parent().get_service());
1595 Mlt::Tractor tractor(service);
1596 Mlt::Producer trackProducer(tractor.track(track));
1597 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1598 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1599 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1601 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1604 Mlt::Service clipService(clip->get_service());
1607 Mlt::Filter *filter = clipService.filter(ct);
1609 if (filter->get("kdenlive_ix") == index) {
1613 filter = clipService.filter(ct);
1617 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1618 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1620 filter = clipService.filter(ct);
1621 QList <Mlt::Filter *> filtersList;
1623 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1624 filtersList.append(filter);
1625 clipService.detach(*filter);
1627 filter = clipService.filter(ct);
1629 bool success = mltAddEffect(track, position, args);
1631 for (int i = 0; i < filtersList.count(); i++) {
1632 clipService.attach(*(filtersList.at(i)));
1635 m_isBlocked = false;
1639 for (it = args.begin(); it != args.end(); ++it) {
1640 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1641 char *name = decodedString(it.key());
1642 char *value = decodedString(it.value());
1643 filter->set(name, value);
1647 m_isBlocked = false;
1652 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1654 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1655 Mlt::Service service(m_mltProducer->parent().get_service());
1657 Mlt::Tractor tractor(service);
1658 Mlt::Producer trackProducer(tractor.track(track));
1659 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1660 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1661 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1663 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1666 Mlt::Service clipService(clip->get_service());
1669 QList <Mlt::Filter *> filtersList;
1670 Mlt::Filter *filter = clipService.filter(ct);
1672 if (newPos > oldPos) {
1674 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1675 filter->set("kdenlive_ix", newPos);
1676 filtersList.append(filter);
1677 clipService.detach(*filter);
1678 filter = clipService.filter(ct);
1679 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1680 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1682 filter = clipService.filter(ct);
1686 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1687 filtersList.append(filter);
1688 clipService.detach(*filter);
1690 filter = clipService.filter(ct);
1694 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1695 filter->set("kdenlive_ix", newPos);
1696 filtersList.append(filter);
1697 clipService.detach(*filter);
1699 filter = clipService.filter(ct);
1703 filter = clipService.filter(ct);
1705 int pos = QString(filter->get("kdenlive_ix")).toInt();
1706 if (pos >= newPos) {
1707 if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
1708 filtersList.append(filter);
1709 clipService.detach(*filter);
1711 filter = clipService.filter(ct);
1715 for (int i = 0; i < filtersList.count(); i++) {
1716 clipService.attach(*(filtersList.at(i)));
1719 m_isBlocked = false;
1723 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
1726 Mlt::Service service(m_mltProducer->parent().get_service());
1728 Mlt::Tractor tractor(service);
1729 Mlt::Producer trackProducer(tractor.track(info.track));
1730 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1732 /* // Display playlist info
1733 kDebug()<<"//////////// BEFORE RESIZE";
1734 for (int i = 0; i < trackPlaylist.count(); i++) {
1735 int blankStart = trackPlaylist.clip_start(i);
1736 int blankDuration = trackPlaylist.clip_length(i) - 1;
1738 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1739 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1742 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
1743 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1744 m_isBlocked = false;
1747 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1748 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
1749 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1750 int previousStart = clip->get_in();
1751 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1752 int newDuration = (int) clipDuration.frames(m_fps) - 1;
1753 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
1754 //trackPlaylist.consolidate_blanks(0);
1755 // skip to next clip
1757 int diff = newDuration - previousDuration;
1758 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
1760 // clip was made longer, trim next blank if there is one.
1761 if (trackPlaylist.is_blank(clipIndex)) {
1762 int blankStart = trackPlaylist.clip_start(clipIndex);
1763 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
1764 if (diff - blankDuration == 1) {
1765 trackPlaylist.remove(clipIndex);
1766 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
1768 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
1770 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
1772 trackPlaylist.consolidate_blanks(0);
1774 /* // Display playlist info
1775 kDebug()<<"//////////// AFTER RESIZE";
1776 for (int i = 0; i < trackPlaylist.count(); i++) {
1777 int blankStart = trackPlaylist.clip_start(i);
1778 int blankDuration = trackPlaylist.clip_length(i) - 1;
1780 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1781 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1784 //tractor.multitrack()->refresh();
1785 //tractor.refresh();
1786 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
1787 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1788 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1789 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1790 ItemInfo transpinfo;
1791 transpinfo.startPos = info.startPos;
1792 transpinfo.endPos = info.startPos + clipDuration;
1793 transpinfo.track = info.track;
1794 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1796 m_isBlocked = false;
1800 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1801 Mlt::Service service(m_mltProducer->parent().get_service());
1802 Mlt::Tractor tractor(service);
1803 Mlt::Producer trackProducer(tractor.track(track));
1804 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1806 if (blind) trackProducer.set("hide", 3);
1807 else trackProducer.set("hide", 2);
1809 trackProducer.set("hide", 1);
1811 trackProducer.set("hide", 0);
1813 tractor.multitrack()->refresh();
1818 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
1819 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
1820 Mlt::Service service(m_mltProducer->parent().get_service());
1821 int moveFrame = (int) diff.frames(m_fps);
1822 Mlt::Tractor tractor(service);
1823 Mlt::Producer trackProducer(tractor.track(info.track));
1824 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1825 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
1826 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1829 mlt_service_lock(service.get_service());
1830 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
1831 /*int previousStart = trackPlaylist.clip_start(clipIndex);
1832 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
1833 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1834 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1836 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
1837 mlt_service_unlock(service.get_service());
1840 //m_mltConsumer->set("refresh", 0);
1841 int previousStart = clip->get_in();
1842 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1844 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
1845 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
1846 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1848 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
1849 int blankIndex = clipIndex - 1;
1850 int blankLength = trackPlaylist.clip_length(blankIndex);
1851 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
1852 if (! trackPlaylist.is_blank(blankIndex)) {
1853 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
1855 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1856 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1858 trackPlaylist.consolidate_blanks(0);
1859 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1860 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
1861 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1862 ItemInfo transpinfo;
1863 transpinfo.startPos = info.startPos + diff;
1864 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
1865 transpinfo.track = info.track;
1866 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1868 m_isBlocked = false;
1869 //m_mltConsumer->set("refresh", 1);
1870 mlt_service_unlock(service.get_service());
1874 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1875 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1879 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1882 m_mltConsumer->set("refresh", 0);
1883 mlt_service_lock(m_mltConsumer->get_service());
1884 Mlt::Service service(m_mltProducer->parent().get_service());
1885 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1887 Mlt::Tractor tractor(service);
1888 Mlt::Producer trackProducer(tractor.track(startTrack));
1889 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1890 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1891 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
1892 bool checkLength = false;
1893 if (endTrack == startTrack) {
1894 //mlt_service_lock(service.get_service());
1895 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1897 if (!trackPlaylist.is_blank_at(moveEnd)) {
1898 // error, destination is not empty
1899 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
1900 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
1901 mlt_service_unlock(m_mltConsumer->get_service());
1902 m_isBlocked = false;
1905 trackPlaylist.consolidate_blanks(0);
1906 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1907 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1908 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1910 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
1912 //mlt_service_unlock(service.get_service());
1914 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1915 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1916 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
1917 // error, destination is not empty
1918 mlt_service_unlock(m_mltConsumer->get_service());
1919 m_isBlocked = false;
1922 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1923 trackPlaylist.consolidate_blanks(0);
1924 destTrackPlaylist.consolidate_blanks(1);
1925 int newIndex = destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1926 destTrackPlaylist.consolidate_blanks(0);
1927 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1928 kDebug() << "//////// moving clip transparency";
1929 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1931 if (clipIndex > trackPlaylist.count()) checkLength = true;
1932 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
1936 if (checkLength) mltCheckLength();
1937 mlt_service_unlock(m_mltConsumer->get_service());
1938 m_isBlocked = false;
1939 m_mltConsumer->set("refresh", 1);
1943 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1945 Mlt::Service service(m_mltProducer->parent().get_service());
1946 Mlt::Tractor tractor(service);
1947 Mlt::Field *field = tractor.field();
1949 mlt_service_lock(service.get_service());
1950 m_mltConsumer->set("refresh", 0);
1953 mlt_service serv = m_mltProducer->parent().get_service();
1954 mlt_service nextservice = mlt_service_get_producer(serv);
1955 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1956 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1957 QString resource = mlt_properties_get(properties, "mlt_service");
1958 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1960 int new_in = (int)newIn.frames(m_fps);
1961 int new_out = (int)newOut.frames(m_fps);
1963 while (mlt_type == "transition") {
1964 mlt_transition tr = (mlt_transition) nextservice;
1965 int currentTrack = mlt_transition_get_b_track(tr);
1966 int currentIn = (int) mlt_transition_get_in(tr);
1967 int currentOut = (int) mlt_transition_get_out(tr);
1969 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1970 mlt_transition_set_in_and_out(tr, new_in, new_out);
1971 if (newTrack - startTrack != 0) {
1972 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
1974 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1975 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
1976 mlt_properties_set_int(properties, "b_track", newTrack);
1977 //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);
1981 nextservice = mlt_service_producer(nextservice);
1982 if (nextservice == NULL) break;
1983 properties = MLT_SERVICE_PROPERTIES(nextservice);
1984 mlt_type = mlt_properties_get(properties, "mlt_type");
1985 resource = mlt_properties_get(properties, "mlt_service");
1987 m_isBlocked = false;
1988 mlt_service_unlock(service.get_service());
1989 m_mltConsumer->set("refresh", 1);
1992 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1993 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
1994 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
1996 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
1997 mltAddTransition(tag, a_track, b_track, in, out, xml);
1999 //mltSavePlaylist();
2002 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2005 Mlt::Service service(m_mltProducer->parent().get_service());
2006 Mlt::Tractor tractor(service);
2007 Mlt::Field *field = tractor.field();
2009 //m_mltConsumer->set("refresh", 0);
2010 mlt_service serv = m_mltProducer->parent().get_service();
2012 mlt_service nextservice = mlt_service_get_producer(serv);
2013 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2014 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2015 QString resource = mlt_properties_get(properties, "mlt_service");
2016 int in_pos = (int) in.frames(m_fps);
2017 int out_pos = (int) out.frames(m_fps);
2019 while (mlt_type == "transition") {
2020 mlt_transition tr = (mlt_transition) nextservice;
2021 int currentTrack = mlt_transition_get_b_track(tr);
2022 int currentIn = (int) mlt_transition_get_in(tr);
2023 int currentOut = (int) mlt_transition_get_out(tr);
2025 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2027 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2028 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2029 QMap<QString, QString>::Iterator it;
2031 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2033 for (it = map.begin(); it != map.end(); ++it) {
2035 char *name = decodedString(key);
2036 char *value = decodedString(it.value());
2037 mlt_properties_set(transproperties, name, value);
2038 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2039 //filter->set("kdenlive_id", id);
2045 nextservice = mlt_service_producer(nextservice);
2046 if (nextservice == NULL) break;
2047 properties = MLT_SERVICE_PROPERTIES(nextservice);
2048 mlt_type = mlt_properties_get(properties, "mlt_type");
2049 resource = mlt_properties_get(properties, "mlt_service");
2051 m_isBlocked = false;
2052 m_mltConsumer->set("refresh", 1);
2055 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2056 Mlt::Service service(m_mltProducer->parent().get_service());
2057 Mlt::Tractor tractor(service);
2058 Mlt::Field *field = tractor.field();
2060 if (do_refresh) m_mltConsumer->set("refresh", 0);
2061 mlt_service serv = m_mltProducer->parent().get_service();
2063 mlt_service nextservice = mlt_service_get_producer(serv);
2064 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2065 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2066 QString resource = mlt_properties_get(properties, "mlt_service");
2067 int old_pos = (int)((in + out).frames(m_fps) / 2);
2069 while (mlt_type == "transition") {
2070 mlt_transition tr = (mlt_transition) nextservice;
2071 int currentTrack = mlt_transition_get_b_track(tr);
2072 int currentIn = (int) mlt_transition_get_in(tr);
2073 int currentOut = (int) mlt_transition_get_out(tr);
2074 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2076 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2077 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2078 mlt_field_disconnect_service(field->get_field(), nextservice);
2081 nextservice = mlt_service_producer(nextservice);
2082 if (nextservice == NULL) break;
2083 properties = MLT_SERVICE_PROPERTIES(nextservice);
2084 mlt_type = mlt_properties_get(properties, "mlt_type");
2085 resource = mlt_properties_get(properties, "mlt_service");
2087 if (do_refresh) m_mltConsumer->set("refresh", 1);
2090 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2091 QDomNodeList attribs = xml.elementsByTagName("parameter");
2092 QMap<QString, QString> map;
2093 for (int i = 0;i < attribs.count();i++) {
2094 QDomElement e = attribs.item(i).toElement();
2095 QString name = e.attribute("name");
2096 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2097 map[name] = e.attribute("default");
2098 if (!e.attribute("value").isEmpty()) {
2099 map[name] = e.attribute("value");
2101 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2102 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2103 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2106 if (e.attribute("namedesc").contains(";")) {
2107 QString format = e.attribute("format");
2108 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2109 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2111 QTextStream txtNeu(&neu);
2112 if (values.size() > 0)
2113 txtNeu << (int)values[0].toDouble();
2115 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2116 txtNeu << separators[i];
2117 txtNeu << (int)(values[i+1].toDouble());
2119 if (i < separators.size())
2120 txtNeu << separators[i];
2121 map[e.attribute("name")] = neu;
2128 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2129 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2130 Mlt::Service service(m_mltProducer->parent().get_service());
2131 Mlt::Tractor tractor(service);
2132 Mlt::Field *field = tractor.field();
2134 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2135 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2136 transition->set("transparency", id);
2137 transition->set("fill", 1);
2138 transition->set("internal_added", 237);
2139 field->plant_transition(*transition, transitiontrack, info.track);
2143 void Render::mltDeleteTransparency(int pos, int track, int id) {
2144 Mlt::Service service(m_mltProducer->parent().get_service());
2145 Mlt::Tractor tractor(service);
2146 Mlt::Field *field = tractor.field();
2148 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2149 mlt_service serv = m_mltProducer->parent().get_service();
2151 mlt_service nextservice = mlt_service_get_producer(serv);
2152 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2153 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2154 QString resource = mlt_properties_get(properties, "mlt_service");
2156 while (mlt_type == "transition") {
2157 mlt_transition tr = (mlt_transition) nextservice;
2158 int currentTrack = mlt_transition_get_b_track(tr);
2159 int currentIn = (int) mlt_transition_get_in(tr);
2160 int currentOut = (int) mlt_transition_get_out(tr);
2161 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2162 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2164 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2165 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2166 mlt_field_disconnect_service(field->get_field(), nextservice);
2169 nextservice = mlt_service_producer(nextservice);
2170 if (nextservice == NULL) break;
2171 properties = MLT_SERVICE_PROPERTIES(nextservice);
2172 mlt_type = mlt_properties_get(properties, "mlt_type");
2173 resource = mlt_properties_get(properties, "mlt_service");
2175 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2178 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2179 Mlt::Service service(m_mltProducer->parent().get_service());
2180 Mlt::Tractor tractor(service);
2181 Mlt::Field *field = tractor.field();
2183 mlt_service_lock(service.get_service());
2184 m_mltConsumer->set("refresh", 0);
2187 mlt_service serv = m_mltProducer->parent().get_service();
2188 mlt_service nextservice = mlt_service_get_producer(serv);
2189 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2190 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2191 QString resource = mlt_properties_get(properties, "mlt_service");
2192 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2193 while (mlt_type == "transition") {
2194 mlt_transition tr = (mlt_transition) nextservice;
2195 int currentTrack = mlt_transition_get_b_track(tr);
2196 int currentIn = (int) mlt_transition_get_in(tr);
2197 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2198 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2199 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2200 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2201 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2202 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2205 nextservice = mlt_service_producer(nextservice);
2206 if (nextservice == NULL) break;
2207 properties = MLT_SERVICE_PROPERTIES(nextservice);
2208 mlt_type = mlt_properties_get(properties, "mlt_type");
2209 resource = mlt_properties_get(properties, "mlt_service");
2211 m_isBlocked = false;
2212 mlt_service_unlock(service.get_service());
2213 m_mltConsumer->set("refresh", 1);
2217 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2218 Mlt::Service service(m_mltProducer->parent().get_service());
2219 Mlt::Tractor tractor(service);
2220 Mlt::Field *field = tractor.field();
2222 mlt_service_lock(service.get_service());
2223 m_mltConsumer->set("refresh", 0);
2226 mlt_service serv = m_mltProducer->parent().get_service();
2227 mlt_service nextservice = mlt_service_get_producer(serv);
2228 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2229 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2230 QString resource = mlt_properties_get(properties, "mlt_service");
2232 while (mlt_type == "transition") {
2233 mlt_transition tr = (mlt_transition) nextservice;
2234 int currentTrack = mlt_transition_get_b_track(tr);
2235 int currentaTrack = mlt_transition_get_a_track(tr);
2236 int currentIn = (int) mlt_transition_get_in(tr);
2237 int currentOut = (int) mlt_transition_get_out(tr);
2238 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2239 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2240 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2241 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2242 kDebug() << "//////MOVING";
2243 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2244 if (endTrack != startTrack) {
2245 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2246 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2247 mlt_properties_set_int(properties, "b_track", endTrack);
2251 nextservice = mlt_service_producer(nextservice);
2252 if (nextservice == NULL) break;
2253 properties = MLT_SERVICE_PROPERTIES(nextservice);
2254 mlt_type = mlt_properties_get(properties, "mlt_type");
2255 resource = mlt_properties_get(properties, "mlt_service");
2257 m_isBlocked = false;
2258 mlt_service_unlock(service.get_service());
2259 m_mltConsumer->set("refresh", 1);
2263 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2265 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2266 Mlt::Service service(m_mltProducer->parent().get_service());
2268 Mlt::Tractor tractor(service);
2269 Mlt::Field *field = tractor.field();
2271 char *transId = decodedString(tag);
2272 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2273 if (out != GenTime())
2274 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
2275 QMap<QString, QString>::Iterator it;
2278 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2280 for (it = args.begin(); it != args.end(); ++it) {
2282 char *name = decodedString(key);
2283 char *value = decodedString(it.value());
2284 transition->set(name, value);
2285 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2286 //filter->set("kdenlive_id", id);
2290 // attach filter to the clip
2291 field->plant_transition(*transition, a_track, b_track);
2296 void Render::mltSavePlaylist() {
2297 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2298 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2299 fileConsumer.set("resource", "/tmp/playlist.westley");
2301 Mlt::Service service(m_mltProducer->get_service());
2303 fileConsumer.connect(service);
2304 fileConsumer.start();
2307 #include "renderer.moc"