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) {
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);
1008 m_mltConsumer->set("refresh", 0);
1009 m_mltProducer->set_speed(0.0);
1010 emit rendererPosition(m_framePosition);
1011 m_mltProducer->seek(m_framePosition);
1012 m_mltConsumer->purge();
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) {
1031 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1032 m_isBlocked = false;
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_isBlocked = false;
1045 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1046 m_mltProducer->set_speed(1.0);
1047 m_mltConsumer->set("refresh", 1);
1050 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1051 if (!m_mltProducer || !m_mltConsumer)
1053 //m_mltProducer->set("eof", "loop");
1054 m_isLoopMode = true;
1055 m_loopStart = startTime;
1056 playZone(startTime, stopTime);
1059 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1060 if (!m_mltProducer || !m_mltConsumer)
1062 m_isBlocked = false;
1063 m_mltProducer->set("out", stopTime.frames(m_fps));
1064 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1065 m_mltProducer->set_speed(1.0);
1066 m_mltConsumer->set("refresh", 1);
1067 m_isZoneMode = true;
1070 void Render::resetZoneMode() {
1071 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1072 //m_mltProducer->set("eof", "pause");
1073 m_isZoneMode = false;
1074 m_isLoopMode = false;
1077 void Render::seekToFrame(int pos) {
1078 //kDebug()<<" ********* RENDER SEEK TO POS";
1081 m_isBlocked = false;
1083 m_mltProducer->seek(pos);
1087 void Render::askForRefresh() {
1088 // Use a Timer so that we don't refresh too much
1089 refreshTimer->start(200);
1092 void Render::doRefresh() {
1093 // Use a Timer so that we don't refresh too much
1094 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1097 void Render::refresh() {
1098 if (!m_mltProducer || m_isBlocked)
1100 refreshTimer->stop();
1101 if (m_mltConsumer) {
1102 m_mltConsumer->set("refresh", 1);
1106 double Render::playSpeed() {
1107 if (m_mltProducer) return m_mltProducer->get_speed();
1111 GenTime Render::seekPosition() const {
1112 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1113 else return GenTime();
1117 const QString & Render::rendererName() const {
1122 void Render::emitFrameNumber(double position) {
1123 m_framePosition = position;
1124 emit rendererPosition((int) position);
1125 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1128 void Render::emitConsumerStopped() {
1129 // This is used to know when the playing stopped
1130 if (m_mltProducer) {
1131 double pos = m_mltProducer->position();
1132 if (m_isLoopMode) play(m_loopStart);
1133 else if (m_isZoneMode) resetZoneMode();
1134 emit rendererStopped((int) pos);
1135 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1136 //new QCustomEvent(10002));
1142 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1143 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1147 void Render::exportCurrentFrame(KUrl url, bool notify) {
1148 if (!m_mltProducer) {
1149 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1153 int height = 1080;//KdenliveSettings::defaultheight();
1154 int width = 1940; //KdenliveSettings::displaywidth();
1156 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1158 QPixmap pix(width, height);
1159 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1160 m_convert.set("forced", mlt_image_rgb24a);
1161 m_mltProducer->attach(m_convert);
1162 Mlt::Frame * frame = m_mltProducer->get_frame();
1163 m_mltProducer->detach(m_convert);
1165 pix = frameThumbnail(frame, width, height);
1168 pix.save(url.path(), "PNG");
1169 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1172 /** MLT PLAYLIST DIRECT MANIPULATON **/
1175 void Render::mltCheckLength(bool reload) {
1176 //kDebug()<<"checking track length: "<<track<<"..........";
1178 Mlt::Service service(m_mltProducer->get_service());
1179 Mlt::Tractor tractor(service);
1181 int trackNb = tractor.count();
1182 double duration = 0;
1183 double trackDuration;
1185 Mlt::Producer trackProducer(tractor.track(0));
1186 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1187 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1188 m_mltProducer->set("out", duration);
1189 emit durationChanged((int) duration);
1192 while (trackNb > 1) {
1193 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1194 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1195 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1197 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1198 if (trackDuration > duration) duration = trackDuration;
1202 Mlt::Producer blackTrackProducer(tractor.track(0));
1203 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1204 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1206 if (blackDuration != duration) {
1207 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1209 int dur = (int)duration;
1211 QDomElement black = doc.createElement("producer");
1212 black.setAttribute("mlt_service", "colour");
1213 black.setAttribute("colour", "black");
1214 black.setAttribute("id", "black");
1217 while (dur > 14000) {
1218 info.startPos = GenTime(i * 14000, m_fps);
1219 info.endPos = info.startPos + GenTime(13999, m_fps);
1220 mltInsertClip(info, black, m_blackClip);
1225 info.startPos = GenTime(i * 14000, m_fps);
1226 info.endPos = info.startPos + GenTime(dur, m_fps);
1227 mltInsertClip(info, black, m_blackClip);
1229 m_mltProducer->set("out", duration);
1230 emit durationChanged((int)duration);
1234 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1235 if (!m_mltProducer) {
1236 kDebug() << "PLAYLIST NOT INITIALISED //////";
1239 Mlt::Producer parentProd(m_mltProducer->parent());
1240 if (parentProd.get_producer() == NULL) {
1241 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1245 Mlt::Service service(parentProd.get_service());
1246 Mlt::Tractor tractor(service);
1247 mlt_service_lock(service.get_service());
1248 Mlt::Producer trackProducer(tractor.track(info.track));
1249 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1250 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1251 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1252 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1254 if (QString(prod->get("transparency")).toInt() == 1)
1255 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());
1257 mlt_service_unlock(service.get_service());
1259 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1260 //tractor.multitrack()->refresh();
1261 //tractor.refresh();
1265 void Render::mltCutClip(int track, GenTime position) {
1269 Mlt::Service service(m_mltProducer->parent().get_service());
1270 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1272 Mlt::Tractor tractor(service);
1273 Mlt::Producer trackProducer(tractor.track(track));
1274 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1277 /* // Display playlist info
1278 kDebug()<<"//////////// BEFORE";
1279 for (int i = 0; i < trackPlaylist.count(); i++) {
1280 int blankStart = trackPlaylist.clip_start(i);
1281 int blankDuration = trackPlaylist.clip_length(i) - 1;
1283 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1284 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1287 int cutPos = (int) position.frames(m_fps);
1289 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1290 if (trackPlaylist.is_blank(clipIndex)) {
1291 kDebug() << "// WARMNING, TRYING TO CUT A BLANK";
1292 m_isBlocked = false;
1295 mlt_service_lock(service.get_service());
1296 int clipStart = trackPlaylist.clip_start(clipIndex);
1297 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1299 // duplicate effects
1300 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1301 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1303 if (original == NULL || clip == NULL) {
1304 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1306 Mlt::Service clipService(original->get_service());
1307 Mlt::Service dupService(clip->get_service());
1309 Mlt::Filter *filter = clipService.filter(ct);
1311 if (filter->get("kdenlive_id") != "") {
1312 kDebug() << "++ ADDING FILTER: " << filter->get("kdenlive_id");
1313 Mlt::Filter *dup = new Mlt::Filter(filter->get_filter());
1314 dup->set("kdenlive_ix", filter->get("kdenlive_ix"));
1315 dup->set("kdenlive_id", filter->get("kdenlive_id"));
1316 dupService.attach(*dup);
1319 filter = clipService.filter(ct);
1321 mlt_service_unlock(service.get_service());
1323 /* // Display playlist info
1324 kDebug()<<"//////////// AFTER";
1325 for (int i = 0; i < trackPlaylist.count(); i++) {
1326 int blankStart = trackPlaylist.clip_start(i);
1327 int blankDuration = trackPlaylist.clip_length(i) - 1;
1329 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1330 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1333 m_isBlocked = false;
1336 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1338 mltRemoveClip(info.track, info.startPos);
1339 mltInsertClip(info, element, prod);
1343 bool Render::mltRemoveClip(int track, GenTime position) {
1344 Mlt::Service service(m_mltProducer->parent().get_service());
1345 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1347 Mlt::Tractor tractor(service);
1348 Mlt::Producer trackProducer(tractor.track(track));
1349 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1350 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1352 /* // Display playlist info
1353 kDebug()<<"//// BEFORE";
1354 for (int i = 0; i < trackPlaylist.count(); i++) {
1355 int blankStart = trackPlaylist.clip_start(i);
1356 int blankDuration = trackPlaylist.clip_length(i) - 1;
1358 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1359 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1362 if (trackPlaylist.is_blank(clipIndex)) {
1363 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1367 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1368 trackPlaylist.replace_with_blank(clipIndex);
1369 trackPlaylist.consolidate_blanks(0);
1370 if (QString(clip.parent().get("transparency")).toInt() == 1)
1371 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());
1373 /* // Display playlist info
1374 kDebug()<<"//// AFTER";
1375 for (int i = 0; i < trackPlaylist.count(); i++) {
1376 int blankStart = trackPlaylist.clip_start(i);
1377 int blankDuration = trackPlaylist.clip_length(i) - 1;
1379 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1380 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1383 if (track != 0 && trackPlaylist.count() > clipIndex) mltCheckLength();
1384 m_isBlocked = false;
1388 int Render::mltChangeClipSpeed(ItemInfo info, double speed, Mlt::Producer *prod) {
1391 Mlt::Service service(m_mltProducer->parent().get_service());
1392 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1393 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1394 Mlt::Tractor tractor(service);
1395 Mlt::Producer trackProducer(tractor.track(info.track));
1396 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1397 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1398 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1399 QString serv = clip.parent().get("mlt_service");
1400 QString id = clip.parent().get("id");
1401 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1402 if (serv == "avformat" && speed != 1.0) {
1403 mlt_service_lock(service.get_service());
1404 QString url = clip.parent().get("resource");
1405 url.append("?" + QString::number(speed));
1406 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1407 if (!slowprod || slowprod->get_producer() == NULL) {
1408 char *tmp = decodedString(url);
1409 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1411 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1412 tmp = decodedString(producerid);
1413 slowprod->set("id", tmp);
1415 m_slowmotionProducers.insert(url, slowprod);
1417 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1418 newLength = cut->get_length();
1419 trackPlaylist.replace_with_blank(clipIndex);
1420 trackPlaylist.consolidate_blanks(0);
1421 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1422 mlt_service_unlock(service.get_service());
1423 } else if (speed == 1.0) {
1424 mlt_service_lock(service.get_service());
1425 Mlt::Producer *cut = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1426 trackPlaylist.replace_with_blank(clipIndex);
1427 newLength = cut->get_length();
1428 trackPlaylist.consolidate_blanks(0);
1429 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1430 mlt_service_unlock(service.get_service());
1431 } else if (serv == "framebuffer") {
1432 mlt_service_lock(service.get_service());
1433 QString url = clip.parent().get("resource");
1434 url = url.section("?", 0, 0);
1435 url.append("?" + QString::number(speed));
1436 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1437 if (!slowprod || slowprod->get_producer() == NULL) {
1438 char *tmp = decodedString(url);
1439 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1441 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1442 tmp = decodedString(producerid);
1443 slowprod->set("id", tmp);
1445 m_slowmotionProducers.insert(url, slowprod);
1447 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1448 newLength = cut->get_length();
1449 trackPlaylist.replace_with_blank(clipIndex);
1450 trackPlaylist.consolidate_blanks(0);
1451 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1452 mlt_service_unlock(service.get_service());
1453 kDebug() << "AVFORMAT CLIP!!!:";
1456 m_isBlocked = false;
1460 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1462 Mlt::Service service(m_mltProducer->parent().get_service());
1463 bool success = false;
1464 Mlt::Tractor tractor(service);
1465 Mlt::Producer trackProducer(tractor.track(track));
1466 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1467 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1468 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1470 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1473 Mlt::Service clipService(clip->get_service());
1474 // if (tag.startsWith("ladspa")) tag = "ladspa";
1477 Mlt::Filter *filter = clipService.filter(ct);
1479 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1480 if (clipService.detach(*filter) == 0) success = true;
1481 kDebug() << " / / / DLEETED EFFECT: " << ct;
1483 filter = clipService.filter(ct);
1485 m_isBlocked = false;
1486 if (doRefresh) refresh();
1491 bool Render::mltAddEffect(int track, GenTime position, QHash <QString, QString> args, bool doRefresh) {
1493 Mlt::Service service(m_mltProducer->parent().get_service());
1495 Mlt::Tractor tractor(service);
1496 Mlt::Producer trackProducer(tractor.track(track));
1497 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1499 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1503 Mlt::Service clipService(clip->get_service());
1506 QString tag = args.value("tag");
1507 kDebug() << " / / INSERTING EFFECT: " << tag;
1508 if (tag.startsWith("ladspa")) tag = "ladspa";
1509 char *filterTag = decodedString(tag);
1510 char *filterId = decodedString(args.value("id"));
1511 QHash<QString, QString>::Iterator it;
1512 QString kfr = args.value("keyframes");
1514 if (!kfr.isEmpty()) {
1515 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1516 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1517 char *starttag = decodedString(args.value("starttag", "start"));
1518 char *endtag = decodedString(args.value("endtag", "end"));
1519 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1520 int duration = clip->get_playtime();
1521 double max = args.value("max").toDouble();
1522 double min = args.value("min").toDouble();
1523 double factor = args.value("factor", "1").toDouble();
1524 args.remove("starttag");
1525 args.remove("endtag");
1526 args.remove("keyframes");
1529 args.remove("factor");
1531 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1532 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1533 filter->set("kdenlive_id", filterId);
1534 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1535 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1536 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1537 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1538 if (x2 == -1) x2 = duration;
1539 for (it = args.begin(); it != args.end(); ++it) {
1540 char *name = decodedString(it.key());
1541 char *value = decodedString(it.value());
1542 filter->set(name, value);
1547 filter->set("in", x1);
1548 filter->set("out", x2);
1549 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1550 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1551 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1552 clipService.attach(*filter);
1558 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1559 if (filter && filter->is_valid())
1560 filter->set("kdenlive_id", filterId);
1562 kDebug() << "filter is NULL";
1563 m_isBlocked = false;
1567 for (it = args.begin(); it != args.end(); ++it) {
1568 char *name = decodedString(it.key());
1569 char *value = decodedString(it.value());
1570 filter->set(name, value);
1574 // attach filter to the clip
1575 clipService.attach(*filter);
1579 m_isBlocked = false;
1580 if (doRefresh) refresh();
1584 bool Render::mltEditEffect(int track, GenTime position, QHash <QString, QString> args) {
1585 QString index = args.value("kdenlive_ix");
1586 QString tag = args.value("tag");
1587 QHash<QString, QString>::Iterator it = args.begin();
1588 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1589 // This is a keyframe effect, to edit it, we remove it and re-add it.
1590 mltRemoveEffect(track, position, index);
1591 bool success = mltAddEffect(track, position, args);
1596 Mlt::Service service(m_mltProducer->parent().get_service());
1598 Mlt::Tractor tractor(service);
1599 Mlt::Producer trackProducer(tractor.track(track));
1600 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1601 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1602 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1604 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1607 Mlt::Service clipService(clip->get_service());
1610 Mlt::Filter *filter = clipService.filter(ct);
1612 if (filter->get("kdenlive_ix") == index) {
1616 filter = clipService.filter(ct);
1620 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1621 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1623 filter = clipService.filter(ct);
1624 QList <Mlt::Filter *> filtersList;
1626 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1627 filtersList.append(filter);
1628 clipService.detach(*filter);
1630 filter = clipService.filter(ct);
1632 bool success = mltAddEffect(track, position, args);
1634 for (int i = 0; i < filtersList.count(); i++) {
1635 clipService.attach(*(filtersList.at(i)));
1638 m_isBlocked = false;
1642 for (it = args.begin(); it != args.end(); ++it) {
1643 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1644 char *name = decodedString(it.key());
1645 char *value = decodedString(it.value());
1646 filter->set(name, value);
1650 m_isBlocked = false;
1655 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1657 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1658 Mlt::Service service(m_mltProducer->parent().get_service());
1660 Mlt::Tractor tractor(service);
1661 Mlt::Producer trackProducer(tractor.track(track));
1662 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1663 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1664 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1666 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1669 Mlt::Service clipService(clip->get_service());
1672 QList <Mlt::Filter *> filtersList;
1673 Mlt::Filter *filter = clipService.filter(ct);
1675 if (newPos > oldPos) {
1677 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1678 filter->set("kdenlive_ix", newPos);
1679 filtersList.append(filter);
1680 clipService.detach(*filter);
1681 filter = clipService.filter(ct);
1682 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1683 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1685 filter = clipService.filter(ct);
1689 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1690 filtersList.append(filter);
1691 clipService.detach(*filter);
1693 filter = clipService.filter(ct);
1697 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1698 filter->set("kdenlive_ix", newPos);
1699 filtersList.append(filter);
1700 clipService.detach(*filter);
1702 filter = clipService.filter(ct);
1706 filter = clipService.filter(ct);
1708 int pos = QString(filter->get("kdenlive_ix")).toInt();
1709 if (pos >= newPos) {
1710 if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
1711 filtersList.append(filter);
1712 clipService.detach(*filter);
1714 filter = clipService.filter(ct);
1718 for (int i = 0; i < filtersList.count(); i++) {
1719 clipService.attach(*(filtersList.at(i)));
1722 m_isBlocked = false;
1726 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
1729 Mlt::Service service(m_mltProducer->parent().get_service());
1731 Mlt::Tractor tractor(service);
1732 Mlt::Producer trackProducer(tractor.track(info.track));
1733 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1735 /* // Display playlist info
1736 kDebug()<<"//////////// BEFORE RESIZE";
1737 for (int i = 0; i < trackPlaylist.count(); i++) {
1738 int blankStart = trackPlaylist.clip_start(i);
1739 int blankDuration = trackPlaylist.clip_length(i) - 1;
1741 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1742 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1745 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
1746 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1747 m_isBlocked = false;
1750 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1751 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
1752 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1753 int previousStart = clip->get_in();
1754 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1755 int newDuration = (int) clipDuration.frames(m_fps) - 1;
1756 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
1757 //trackPlaylist.consolidate_blanks(0);
1758 // skip to next clip
1760 int diff = newDuration - previousDuration;
1761 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
1763 // clip was made longer, trim next blank if there is one.
1764 if (trackPlaylist.is_blank(clipIndex)) {
1765 int blankStart = trackPlaylist.clip_start(clipIndex);
1766 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
1767 if (diff - blankDuration == 1) {
1768 trackPlaylist.remove(clipIndex);
1769 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
1771 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
1773 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
1775 trackPlaylist.consolidate_blanks(0);
1777 /* // Display playlist info
1778 kDebug()<<"//////////// AFTER RESIZE";
1779 for (int i = 0; i < trackPlaylist.count(); i++) {
1780 int blankStart = trackPlaylist.clip_start(i);
1781 int blankDuration = trackPlaylist.clip_length(i) - 1;
1783 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1784 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1787 //tractor.multitrack()->refresh();
1788 //tractor.refresh();
1789 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
1790 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1791 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1792 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1793 ItemInfo transpinfo;
1794 transpinfo.startPos = info.startPos;
1795 transpinfo.endPos = info.startPos + clipDuration;
1796 transpinfo.track = info.track;
1797 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1799 m_isBlocked = false;
1803 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1804 Mlt::Service service(m_mltProducer->parent().get_service());
1805 Mlt::Tractor tractor(service);
1806 Mlt::Producer trackProducer(tractor.track(track));
1807 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1809 if (blind) trackProducer.set("hide", 3);
1810 else trackProducer.set("hide", 2);
1812 trackProducer.set("hide", 1);
1814 trackProducer.set("hide", 0);
1816 tractor.multitrack()->refresh();
1821 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
1822 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
1823 Mlt::Service service(m_mltProducer->parent().get_service());
1824 int moveFrame = (int) diff.frames(m_fps);
1825 Mlt::Tractor tractor(service);
1826 Mlt::Producer trackProducer(tractor.track(info.track));
1827 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1828 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
1829 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1832 mlt_service_lock(service.get_service());
1833 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
1834 /*int previousStart = trackPlaylist.clip_start(clipIndex);
1835 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
1836 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1837 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1839 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
1840 mlt_service_unlock(service.get_service());
1843 //m_mltConsumer->set("refresh", 0);
1844 int previousStart = clip->get_in();
1845 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1847 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
1848 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
1849 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1851 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
1852 int blankIndex = clipIndex - 1;
1853 int blankLength = trackPlaylist.clip_length(blankIndex);
1854 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
1855 if (! trackPlaylist.is_blank(blankIndex)) {
1856 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
1858 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1859 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1861 trackPlaylist.consolidate_blanks(0);
1862 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1863 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
1864 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1865 ItemInfo transpinfo;
1866 transpinfo.startPos = info.startPos + diff;
1867 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
1868 transpinfo.track = info.track;
1869 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1871 m_isBlocked = false;
1872 //m_mltConsumer->set("refresh", 1);
1873 mlt_service_unlock(service.get_service());
1877 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1878 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1882 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1885 m_mltConsumer->set("refresh", 0);
1886 mlt_service_lock(m_mltConsumer->get_service());
1887 Mlt::Service service(m_mltProducer->parent().get_service());
1888 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1890 Mlt::Tractor tractor(service);
1891 Mlt::Producer trackProducer(tractor.track(startTrack));
1892 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1893 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1894 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
1895 bool checkLength = false;
1896 if (endTrack == startTrack) {
1897 //mlt_service_lock(service.get_service());
1898 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1900 if (!trackPlaylist.is_blank_at(moveEnd)) {
1901 // error, destination is not empty
1902 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
1903 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
1904 mlt_service_unlock(m_mltConsumer->get_service());
1905 m_isBlocked = false;
1908 trackPlaylist.consolidate_blanks(0);
1909 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1910 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1911 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1913 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
1915 //mlt_service_unlock(service.get_service());
1917 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1918 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1919 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
1920 // error, destination is not empty
1921 mlt_service_unlock(m_mltConsumer->get_service());
1922 m_isBlocked = false;
1925 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1926 trackPlaylist.consolidate_blanks(0);
1927 destTrackPlaylist.consolidate_blanks(1);
1928 int newIndex = destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1929 destTrackPlaylist.consolidate_blanks(0);
1930 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1931 kDebug() << "//////// moving clip transparency";
1932 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1934 if (clipIndex > trackPlaylist.count()) checkLength = true;
1935 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
1939 if (checkLength) mltCheckLength();
1940 mlt_service_unlock(m_mltConsumer->get_service());
1941 m_isBlocked = false;
1942 m_mltConsumer->set("refresh", 1);
1946 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1948 Mlt::Service service(m_mltProducer->parent().get_service());
1949 Mlt::Tractor tractor(service);
1950 Mlt::Field *field = tractor.field();
1952 mlt_service_lock(service.get_service());
1953 m_mltConsumer->set("refresh", 0);
1956 mlt_service serv = m_mltProducer->parent().get_service();
1957 mlt_service nextservice = mlt_service_get_producer(serv);
1958 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1959 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1960 QString resource = mlt_properties_get(properties, "mlt_service");
1961 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1963 int new_in = (int)newIn.frames(m_fps);
1964 int new_out = (int)newOut.frames(m_fps);
1966 while (mlt_type == "transition") {
1967 mlt_transition tr = (mlt_transition) nextservice;
1968 int currentTrack = mlt_transition_get_b_track(tr);
1969 int currentIn = (int) mlt_transition_get_in(tr);
1970 int currentOut = (int) mlt_transition_get_out(tr);
1972 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1973 mlt_transition_set_in_and_out(tr, new_in, new_out);
1974 if (newTrack - startTrack != 0) {
1975 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
1977 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1978 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
1979 mlt_properties_set_int(properties, "b_track", newTrack);
1980 //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);
1984 nextservice = mlt_service_producer(nextservice);
1985 if (nextservice == NULL) break;
1986 properties = MLT_SERVICE_PROPERTIES(nextservice);
1987 mlt_type = mlt_properties_get(properties, "mlt_type");
1988 resource = mlt_properties_get(properties, "mlt_service");
1990 m_isBlocked = false;
1991 mlt_service_unlock(service.get_service());
1992 m_mltConsumer->set("refresh", 1);
1995 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1996 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
1997 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
1999 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2000 mltAddTransition(tag, a_track, b_track, in, out, xml);
2002 //mltSavePlaylist();
2005 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2008 Mlt::Service service(m_mltProducer->parent().get_service());
2009 Mlt::Tractor tractor(service);
2010 Mlt::Field *field = tractor.field();
2012 //m_mltConsumer->set("refresh", 0);
2013 mlt_service serv = m_mltProducer->parent().get_service();
2015 mlt_service nextservice = mlt_service_get_producer(serv);
2016 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2017 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2018 QString resource = mlt_properties_get(properties, "mlt_service");
2019 int in_pos = (int) in.frames(m_fps);
2020 int out_pos = (int) out.frames(m_fps);
2022 while (mlt_type == "transition") {
2023 mlt_transition tr = (mlt_transition) nextservice;
2024 int currentTrack = mlt_transition_get_b_track(tr);
2025 int currentIn = (int) mlt_transition_get_in(tr);
2026 int currentOut = (int) mlt_transition_get_out(tr);
2028 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2030 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2031 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2032 QMap<QString, QString>::Iterator it;
2034 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2036 for (it = map.begin(); it != map.end(); ++it) {
2038 char *name = decodedString(key);
2039 char *value = decodedString(it.value());
2040 mlt_properties_set(transproperties, name, value);
2041 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2042 //filter->set("kdenlive_id", id);
2048 nextservice = mlt_service_producer(nextservice);
2049 if (nextservice == NULL) break;
2050 properties = MLT_SERVICE_PROPERTIES(nextservice);
2051 mlt_type = mlt_properties_get(properties, "mlt_type");
2052 resource = mlt_properties_get(properties, "mlt_service");
2054 m_isBlocked = false;
2055 m_mltConsumer->set("refresh", 1);
2058 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2059 Mlt::Service service(m_mltProducer->parent().get_service());
2060 Mlt::Tractor tractor(service);
2061 Mlt::Field *field = tractor.field();
2063 if (do_refresh) m_mltConsumer->set("refresh", 0);
2064 mlt_service serv = m_mltProducer->parent().get_service();
2066 mlt_service nextservice = mlt_service_get_producer(serv);
2067 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2068 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2069 QString resource = mlt_properties_get(properties, "mlt_service");
2070 int old_pos = (int)((in + out).frames(m_fps) / 2);
2072 while (mlt_type == "transition") {
2073 mlt_transition tr = (mlt_transition) nextservice;
2074 int currentTrack = mlt_transition_get_b_track(tr);
2075 int currentIn = (int) mlt_transition_get_in(tr);
2076 int currentOut = (int) mlt_transition_get_out(tr);
2077 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2079 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2080 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2081 mlt_field_disconnect_service(field->get_field(), nextservice);
2084 nextservice = mlt_service_producer(nextservice);
2085 if (nextservice == NULL) break;
2086 properties = MLT_SERVICE_PROPERTIES(nextservice);
2087 mlt_type = mlt_properties_get(properties, "mlt_type");
2088 resource = mlt_properties_get(properties, "mlt_service");
2090 if (do_refresh) m_mltConsumer->set("refresh", 1);
2093 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2094 QDomNodeList attribs = xml.elementsByTagName("parameter");
2095 QMap<QString, QString> map;
2096 for (int i = 0;i < attribs.count();i++) {
2097 QDomElement e = attribs.item(i).toElement();
2098 QString name = e.attribute("name");
2099 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2100 map[name] = e.attribute("default");
2101 if (!e.attribute("value").isEmpty()) {
2102 map[name] = e.attribute("value");
2104 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2105 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2106 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2109 if (e.attribute("namedesc").contains(";")) {
2110 QString format = e.attribute("format");
2111 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2112 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2114 QTextStream txtNeu(&neu);
2115 if (values.size() > 0)
2116 txtNeu << (int)values[0].toDouble();
2118 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2119 txtNeu << separators[i];
2120 txtNeu << (int)(values[i+1].toDouble());
2122 if (i < separators.size())
2123 txtNeu << separators[i];
2124 map[e.attribute("name")] = neu;
2131 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2132 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2133 Mlt::Service service(m_mltProducer->parent().get_service());
2134 Mlt::Tractor tractor(service);
2135 Mlt::Field *field = tractor.field();
2137 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2138 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2139 transition->set("transparency", id);
2140 transition->set("fill", 1);
2141 transition->set("internal_added", 237);
2142 field->plant_transition(*transition, transitiontrack, info.track);
2146 void Render::mltDeleteTransparency(int pos, int track, int id) {
2147 Mlt::Service service(m_mltProducer->parent().get_service());
2148 Mlt::Tractor tractor(service);
2149 Mlt::Field *field = tractor.field();
2151 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2152 mlt_service serv = m_mltProducer->parent().get_service();
2154 mlt_service nextservice = mlt_service_get_producer(serv);
2155 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2156 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2157 QString resource = mlt_properties_get(properties, "mlt_service");
2159 while (mlt_type == "transition") {
2160 mlt_transition tr = (mlt_transition) nextservice;
2161 int currentTrack = mlt_transition_get_b_track(tr);
2162 int currentIn = (int) mlt_transition_get_in(tr);
2163 int currentOut = (int) mlt_transition_get_out(tr);
2164 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2165 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2167 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2168 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2169 mlt_field_disconnect_service(field->get_field(), nextservice);
2172 nextservice = mlt_service_producer(nextservice);
2173 if (nextservice == NULL) break;
2174 properties = MLT_SERVICE_PROPERTIES(nextservice);
2175 mlt_type = mlt_properties_get(properties, "mlt_type");
2176 resource = mlt_properties_get(properties, "mlt_service");
2178 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2181 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2182 Mlt::Service service(m_mltProducer->parent().get_service());
2183 Mlt::Tractor tractor(service);
2184 Mlt::Field *field = tractor.field();
2186 mlt_service_lock(service.get_service());
2187 m_mltConsumer->set("refresh", 0);
2190 mlt_service serv = m_mltProducer->parent().get_service();
2191 mlt_service nextservice = mlt_service_get_producer(serv);
2192 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2193 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2194 QString resource = mlt_properties_get(properties, "mlt_service");
2195 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2196 while (mlt_type == "transition") {
2197 mlt_transition tr = (mlt_transition) nextservice;
2198 int currentTrack = mlt_transition_get_b_track(tr);
2199 int currentIn = (int) mlt_transition_get_in(tr);
2200 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2201 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2202 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2203 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2204 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2205 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2208 nextservice = mlt_service_producer(nextservice);
2209 if (nextservice == NULL) break;
2210 properties = MLT_SERVICE_PROPERTIES(nextservice);
2211 mlt_type = mlt_properties_get(properties, "mlt_type");
2212 resource = mlt_properties_get(properties, "mlt_service");
2214 m_isBlocked = false;
2215 mlt_service_unlock(service.get_service());
2216 m_mltConsumer->set("refresh", 1);
2220 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2221 Mlt::Service service(m_mltProducer->parent().get_service());
2222 Mlt::Tractor tractor(service);
2223 Mlt::Field *field = tractor.field();
2225 mlt_service_lock(service.get_service());
2226 m_mltConsumer->set("refresh", 0);
2229 mlt_service serv = m_mltProducer->parent().get_service();
2230 mlt_service nextservice = mlt_service_get_producer(serv);
2231 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2232 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2233 QString resource = mlt_properties_get(properties, "mlt_service");
2235 while (mlt_type == "transition") {
2236 mlt_transition tr = (mlt_transition) nextservice;
2237 int currentTrack = mlt_transition_get_b_track(tr);
2238 int currentaTrack = mlt_transition_get_a_track(tr);
2239 int currentIn = (int) mlt_transition_get_in(tr);
2240 int currentOut = (int) mlt_transition_get_out(tr);
2241 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2242 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2243 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2244 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2245 kDebug() << "//////MOVING";
2246 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2247 if (endTrack != startTrack) {
2248 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2249 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2250 mlt_properties_set_int(properties, "b_track", endTrack);
2254 nextservice = mlt_service_producer(nextservice);
2255 if (nextservice == NULL) break;
2256 properties = MLT_SERVICE_PROPERTIES(nextservice);
2257 mlt_type = mlt_properties_get(properties, "mlt_type");
2258 resource = mlt_properties_get(properties, "mlt_service");
2260 m_isBlocked = false;
2261 mlt_service_unlock(service.get_service());
2262 m_mltConsumer->set("refresh", 1);
2266 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2268 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2269 Mlt::Service service(m_mltProducer->parent().get_service());
2271 Mlt::Tractor tractor(service);
2272 Mlt::Field *field = tractor.field();
2274 char *transId = decodedString(tag);
2275 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2276 if (out != GenTime())
2277 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
2278 QMap<QString, QString>::Iterator it;
2281 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2283 for (it = args.begin(); it != args.end(); ++it) {
2285 char *name = decodedString(key);
2286 char *value = decodedString(it.value());
2287 transition->set(name, value);
2288 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2289 //filter->set("kdenlive_id", id);
2293 // attach filter to the clip
2294 field->plant_transition(*transition, a_track, b_track);
2299 void Render::mltSavePlaylist() {
2300 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2301 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2302 fileConsumer.set("resource", "/tmp/playlist.westley");
2304 Mlt::Service service(m_mltProducer->get_service());
2306 fileConsumer.connect(service);
2307 fileConsumer.start();
2310 #include "renderer.moc"