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(-1), m_framePosition(0), m_generateScenelist(false), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(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 m_externalwinid = extid;
83 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
84 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black");
85 m_mltProducer = producer;
86 if (m_blackClip) delete m_blackClip;
87 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
88 m_blackClip->set("id", "black");
89 m_mltConsumer->connect(*m_mltProducer);
90 m_mltProducer->set_speed(0.0);
98 void Render::closeMlt() {
102 delete m_mltConsumer;
104 delete m_mltProducer;
105 if (m_blackClip) delete m_blackClip;
110 void Render::buildConsumer() {
112 tmp = decodedString(KdenliveSettings::current_profile());
113 m_mltProfile = new Mlt::Profile(tmp);
117 QString videoDriver = KdenliveSettings::videodrivername();
118 if (!videoDriver.isEmpty()) {
119 if (videoDriver == "x11_noaccel") {
120 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
123 unsetenv("SDL_VIDEO_YUV_HWACCEL");
127 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
128 m_mltConsumer->set("resize", 1);
129 m_mltConsumer->set("window_id", m_winid);
130 m_mltConsumer->set("terminate_on_pause", 1);
131 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
132 m_mltConsumer->set("rescale", "nearest");
134 QString audioDevice = KdenliveSettings::audiodevicename();
135 if (!audioDevice.isEmpty()) {
136 tmp = decodedString(audioDevice);
137 m_mltConsumer->set("audio_device", tmp);
141 if (!videoDriver.isEmpty()) {
142 tmp = decodedString(videoDriver);
143 m_mltConsumer->set("video_driver", tmp);
147 QString audioDriver = KdenliveSettings::audiodrivername();
148 if (!audioDriver.isEmpty()) {
149 tmp = decodedString(audioDriver);
150 m_mltConsumer->set("audio_driver", tmp);
155 m_mltConsumer->set("progressive", 1);
156 m_mltConsumer->set("audio_buffer", 1024);
157 m_mltConsumer->set("frequency", 48000);
160 int Render::resetProfile() {
161 if (!m_mltConsumer) return 0;
162 QString currentProfile = getenv("MLT_PROFILE");
163 if (currentProfile == KdenliveSettings::current_profile()) {
164 kDebug() << "reset to same profile, nothing to do";
167 if (m_isSplitView) slotSplitView(false);
168 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
169 m_mltConsumer->purge();
170 delete m_mltConsumer;
171 m_mltConsumer = NULL;
172 QString scene = sceneList();
173 if (m_mltProducer) delete m_mltProducer;
174 m_mltProducer = NULL;
175 if (m_mltProfile) delete m_mltProfile;
179 kDebug() << "//RESET WITHSCENE: " << scene;
182 char *tmp = decodedString(scene);
183 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
185 m_mltProducer = producer;
186 if (m_blackClip) delete m_blackClip;
187 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
188 m_mltProducer->optimise();
189 m_mltProducer->set_speed(0);
192 //delete m_mltProfile;
193 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
194 //mlt_profile prof = m_mltProfile->get_profile();
195 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
196 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
197 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
198 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
200 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
205 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
206 void Render::seek(GenTime time) {
207 sendSeekCommand(time);
208 //emit positionChanged(time);
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, int 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 producer->set("id", clipId);
499 int frameNumber = xml.attribute("thumbnail", "0").toInt();
500 if (frameNumber != 0) producer->seek(frameNumber);
501 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
503 filePropertyMap["filename"] = url.path();
504 filePropertyMap["duration"] = QString::number(producer->get_playtime());
505 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
507 Mlt::Frame * frame = producer->get_frame();
509 if (xml.attribute("type").toInt() == SLIDESHOW) {
510 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
511 if (xml.attribute("fade") == "1") {
512 // user wants a fade effect to slideshow
513 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
514 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
515 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
516 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
517 char *tmp = decodedString(xml.attribute("luma_file"));
518 filter->set("luma.resource", tmp);
520 if (xml.hasAttribute("softness")) {
521 int soft = xml.attribute("softness").toInt();
522 filter->set("luma.softness", (double) soft / 100.0);
525 Mlt::Service clipService(producer->get_service());
526 clipService.attach(*filter);
531 filePropertyMap["fps"] = producer->get("source_fps");
533 if (frame && frame->is_valid()) {
534 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
535 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
536 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
537 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
539 if (frame->get_int("test_image") == 0) {
540 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
541 filePropertyMap["type"] = "playlist";
542 metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer->get_service()), "title"));
543 } else if (frame->get_int("test_audio") == 0)
544 filePropertyMap["type"] = "av";
546 filePropertyMap["type"] = "video";
548 mlt_image_format format = mlt_image_yuv422;
550 int frame_height = 0;
551 //frame->set("rescale.interp", "hyper");
552 frame->set("normalised_height", height);
553 frame->set("normalised_width", width);
554 QPixmap pix(width, height);
556 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
557 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
558 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
559 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
561 if (!image.isNull()) {
562 pix = pix.fromImage(image.rgbSwapped());
566 mlt_pool_release(new_image);
567 emit replyGetImage(clipId, 0, pix, width, height);
569 } else if (frame->get_int("test_audio") == 0) {
570 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
571 emit replyGetImage(clipId, 0, pixmap, width, height);
572 filePropertyMap["type"] = "audio";
576 // Retrieve audio / video codec name
578 // Fetch the video_context
581 AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL);
582 if (context != NULL) {
583 // Get the video_index
584 int index = mlt_properties_get_int(properties, "video_index");
586 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
587 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) {
588 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name;
591 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) {
592 filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name;
594 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
595 context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL);
596 if (context != NULL) {
597 // Get the audio_index
598 int index = mlt_properties_get_int(properties, "audio_index");
600 #if ENABLE_FFMPEG_CODEC_DESCRIPTION
601 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name)
602 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name;
605 if (context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name)
606 filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name;
611 mlt_properties metadata = mlt_properties_new();
612 mlt_properties_pass(metadata, properties, "meta.attr.");
613 int count = mlt_properties_count(metadata);
614 for (int i = 0; i < count; i ++) {
615 QString name = mlt_properties_get_name(metadata, i);
616 QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i));
617 if (name.endsWith("markup") && !value.isEmpty())
618 metadataPropertyMap[ name.section(".", 0, -2)] = value;
621 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
622 kDebug() << "REquested fuile info for: " << url.path();
623 if (frame) delete frame;
624 //if (producer) delete producer;
627 /** Create the producer from the Westley QDomDocument */
629 void Render::initSceneList() {
630 kDebug() << "-------- INIT SCENE LIST ------_";
632 QDomElement westley = doc.createElement("westley");
633 doc.appendChild(westley);
634 QDomElement prod = doc.createElement("producer");
635 prod.setAttribute("resource", "colour");
636 prod.setAttribute("colour", "red");
637 prod.setAttribute("id", "black");
638 prod.setAttribute("in", "0");
639 prod.setAttribute("out", "0");
641 QDomElement tractor = doc.createElement("tractor");
642 QDomElement multitrack = doc.createElement("multitrack");
644 QDomElement playlist1 = doc.createElement("playlist");
645 playlist1.appendChild(prod);
646 multitrack.appendChild(playlist1);
647 QDomElement playlist2 = doc.createElement("playlist");
648 multitrack.appendChild(playlist2);
649 QDomElement playlist3 = doc.createElement("playlist");
650 multitrack.appendChild(playlist3);
651 QDomElement playlist4 = doc.createElement("playlist");
652 multitrack.appendChild(playlist4);
653 QDomElement playlist5 = doc.createElement("playlist");
654 multitrack.appendChild(playlist5);
655 tractor.appendChild(multitrack);
656 westley.appendChild(tractor);
657 // kDebug()<<doc.toString();
659 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
660 setSceneList(doc, 0);
666 /** Create the producer from the Westley QDomDocument */
667 void Render::setProducer(Mlt::Producer *producer, int position) {
668 if (m_winid == -1) return;
669 m_generateScenelist = true;
672 m_mltConsumer->stop();
676 m_mltProducer->set_speed(0);
677 delete m_mltProducer;
678 m_mltProducer = NULL;
681 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
682 else m_mltProducer = new Mlt::Producer();
683 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
685 m_fps = m_mltProducer->get_fps();
687 if (position != -1) {
688 m_mltProducer->seek(position);
689 emit rendererPosition(position);
691 m_generateScenelist = false;
696 /** Create the producer from the Westley QDomDocument */
697 void Render::setSceneList(QDomDocument list, int position) {
698 setSceneList(list.toString(), position);
701 /** Create the producer from the Westley QDomDocument */
702 void Render::setSceneList(QString playlist, int position) {
703 if (m_winid == -1) return;
704 m_generateScenelist = true;
706 kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
710 if (!clip.is_valid()) {
711 kWarning()<<" ++++ WARNING, UNABLE TO CREATE MLT PRODUCER";
712 m_generateScenelist = false;
717 m_mltConsumer->stop();
718 //m_mltConsumer->set("refresh", 0);
722 m_mltProducer->set_speed(0);
723 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
725 delete m_mltProducer;
726 m_mltProducer = NULL;
730 char *tmp = decodedString(playlist);
731 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
733 if (m_blackClip) delete m_blackClip;
734 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
735 m_blackClip->set("id", "black");
736 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
737 m_mltProducer->optimise();
739 /*if (KdenliveSettings::osdtimecode()) {
740 // Attach filter for on screen display of timecode
742 QString attr = "attr_check";
743 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
744 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
745 mlt_producer_attach( m_mltProducer->get_producer(), filter );
746 mlt_filter_close( filter );
748 m_osdInfo = new Mlt::Filter("data_show");
749 tmp = decodedString(m_osdProfile);
750 m_osdInfo->set("resource", tmp);
752 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
753 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
754 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
755 m_osdInfo->set("dynamic", "1");
757 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
759 m_osdInfo->set("dynamic", "0");
762 m_fps = m_mltProducer->get_fps();
763 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
766 m_mltProducer->seek(position);
767 emit rendererPosition(position);
769 m_generateScenelist = false;
773 /** Create the producer from the Westley QDomDocument */
774 QString Render::sceneList() {
779 saveSceneList(temp.fileName());
780 QFile file(temp.fileName());
781 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
782 kWarning() << "++++++++++++++++ CANNOT READ TMP SCENELIST FILE";
785 QTextStream in(&file);
786 while (!in.atEnd()) {
787 result.append(in.readLine());
793 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
795 char *tmppath = decodedString("westley:" + path);
796 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
797 m_mltProducer->optimise();
799 westleyConsumer.set("terminate_on_pause", 1);
800 Mlt::Producer prod(m_mltProducer->get_producer());
801 bool split = m_isSplitView;
802 if (split) slotSplitView(false);
803 westleyConsumer.connect(prod);
804 //prod.set("title", "kdenlive document");
805 //westleyConsumer.listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
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 const double Render::fps() const {
832 void Render::connectPlaylist() {
833 if (!m_mltConsumer) return;
834 //m_mltConsumer->set("refresh", "0");
835 m_mltConsumer->connect(*m_mltProducer);
836 m_mltProducer->set_speed(0);
837 m_mltConsumer->start();
838 emit durationChanged(m_mltProducer->get_playtime());
841 if (m_mltConsumer->start() == -1) {
842 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."));
843 m_mltConsumer = NULL;
850 void Render::refreshDisplay() {
852 if (!m_mltProducer) return;
853 //m_mltConsumer->set("refresh", 0);
855 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
856 /*if (KdenliveSettings::osdtimecode()) {
857 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
858 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
859 m_osdInfo->set("dynamic", "1");
860 m_mltProducer->attach(*m_osdInfo);
863 m_mltProducer->detach(*m_osdInfo);
864 m_osdInfo->set("dynamic", "0");
869 void Render::setVolume(double volume) {
870 if (!m_mltConsumer || !m_mltProducer) return;
872 m_mltConsumer->set("refresh", 0);
873 // Attach filter for on screen display of timecode
874 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
875 mlt_properties_set_double( properties, "meta.volume", volume );
876 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
877 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
879 if (!KdenliveSettings::osdtimecode()) {
880 m_mltProducer->detach(*m_osdInfo);
881 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
882 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
885 osdTimer->setSingleShot(2500);
888 void Render::slotOsdTimeout() {
889 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
890 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
891 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
892 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
896 void Render::start() {
897 kDebug() << "----- STARTING MONITOR: " << m_name;
899 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
903 if (m_mltConsumer->is_stopped()) {
904 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
905 if (m_mltConsumer->start() == -1) {
906 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."));
907 m_mltConsumer = NULL;
910 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
918 void Render::clear() {
919 kDebug() << " ********* RENDER CLEAR";
921 //m_mltConsumer->set("refresh", 0);
922 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
926 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
927 m_mltProducer->set_speed(0.0);
928 delete m_mltProducer;
929 m_mltProducer = NULL;
934 void Render::stop() {
935 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
936 kDebug() << "///////////// RENDER STOPPED: " << m_name;
937 //m_mltConsumer->set("refresh", 0);
938 m_mltConsumer->stop();
940 kDebug() << "///////////// RENDER STOP2-------";
944 m_mltProducer->set_speed(0.0);
945 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
946 kDebug() << m_mltProducer->get_length();
948 kDebug() << "///////////// RENDER STOP3-------";
951 void Render::stop(const GenTime & startTime) {
953 kDebug() << "///////////// RENDER STOP-------2";
955 m_mltProducer->set_speed(0.0);
956 m_mltProducer->seek((int) startTime.frames(m_fps));
958 m_mltConsumer->purge();
961 void Render::switchPlay() {
964 if (m_mltProducer->get_speed() == 0.0) {
965 //m_isBlocked = false;
966 m_mltProducer->set_speed(1.0);
967 m_mltConsumer->set("refresh", 1);
968 kDebug() << " ********* RENDER PLAY: " << m_mltProducer->get_speed();
970 //m_isBlocked = true;
971 m_mltConsumer->set("refresh", 0);
972 m_mltProducer->set_speed(0.0);
973 //m_isBlocked = true;
974 m_mltProducer->seek((int) m_framePosition);
975 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
976 //m_mltConsumer->set("refresh", 0);
977 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
978 m_mltProducer->set_speed(0);
979 m_mltProducer->seek( position );
980 //m_mltProducer->seek((int) m_framePosition);
981 m_isBlocked = false;*/
983 /*if (speed == 0.0) {
984 m_mltProducer->seek((int) m_framePosition + 1);
985 m_mltConsumer->purge();
990 void Render::play(double speed) {
991 kDebug() << " ********* REDNER PLAY";
994 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
995 m_mltProducer->set_speed(speed);
996 /*if (speed == 0.0) {
997 m_mltProducer->seek((int) m_framePosition + 1);
998 m_mltConsumer->purge();
1003 void Render::play(double speed, const GenTime & startTime) {
1004 kDebug() << "///////////// RENDER PLAY2-------" << speed;
1007 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1008 //if (speed == 0.0) m_mltConsumer->set("refresh", 0);
1009 m_mltProducer->set_speed(speed);
1010 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1011 //m_mltConsumer->purge();
1015 void Render::play(double speed, const GenTime & startTime,
1016 const GenTime & stopTime) {
1017 kDebug() << "///////////// RENDER PLAY3-------" << speed << stopTime.frames(m_fps);
1020 m_mltProducer->set("out", stopTime.frames(m_fps));
1021 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1022 m_mltConsumer->purge();
1023 m_mltProducer->set_speed(speed);
1028 void Render::sendSeekCommand(GenTime time) {
1029 //kDebug()<<" ********* RENDER SEND SEEK";
1032 //kDebug()<<"////////// KDENLIVE SEEK: "<<(int) (time.frames(m_fps));
1033 m_mltProducer->seek((int)(time.frames(m_fps)));
1037 void Render::seekToFrame(int pos) {
1038 //kDebug()<<" ********* RENDER SEEK TO POS";
1041 m_mltProducer->seek(pos);
1045 void Render::askForRefresh() {
1046 // Use a Timer so that we don't refresh too much
1047 refreshTimer->start(200);
1050 void Render::doRefresh() {
1051 // Use a Timer so that we don't refresh too much
1052 m_mltConsumer->set("refresh", 1);
1055 void Render::refresh() {
1056 if (!m_mltProducer || m_isBlocked)
1058 refreshTimer->stop();
1059 if (m_mltConsumer) {
1060 m_mltConsumer->set("refresh", 1);
1064 /** Sets the description of this renderer to desc. */
1065 void Render::setDescription(const QString & description) {
1066 m_description = description;
1069 /** Returns the description of this renderer */
1070 QString Render::description() {
1071 return m_description;
1075 double Render::playSpeed() {
1076 if (m_mltProducer) return m_mltProducer->get_speed();
1080 GenTime Render::seekPosition() const {
1081 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1082 else return GenTime();
1086 const QString & Render::rendererName() const {
1091 void Render::emitFrameNumber(double position) {
1092 if (m_generateScenelist) return;
1093 m_framePosition = position;
1094 emit rendererPosition((int) position);
1095 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1098 void Render::emitConsumerStopped() {
1099 // This is used to know when the playing stopped
1100 if (m_mltProducer && !m_generateScenelist) {
1101 double pos = m_mltProducer->position();
1102 emit rendererStopped((int) pos);
1103 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1104 //new QCustomEvent(10002));
1110 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1111 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1115 void Render::exportCurrentFrame(KUrl url, bool notify) {
1116 if (!m_mltProducer) {
1117 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1121 int height = 1080;//KdenliveSettings::defaultheight();
1122 int width = 1940; //KdenliveSettings::displaywidth();
1124 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1126 QPixmap pix(width, height);
1127 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1128 m_convert.set("forced", mlt_image_rgb24a);
1129 m_mltProducer->attach(m_convert);
1130 Mlt::Frame * frame = m_mltProducer->get_frame();
1131 m_mltProducer->detach(m_convert);
1133 pix = frameThumbnail(frame, width, height);
1136 pix.save(url.path(), "PNG");
1137 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1140 /** MLT PLAYLIST DIRECT MANIPULATON **/
1143 void Render::mltCheckLength(bool reload) {
1144 //kDebug()<<"checking track length: "<<track<<"..........";
1146 Mlt::Service service(m_mltProducer->get_service());
1147 Mlt::Tractor tractor(service);
1149 int trackNb = tractor.count();
1150 double duration = 0;
1151 double trackDuration;
1153 Mlt::Producer trackProducer(tractor.track(0));
1154 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1155 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1156 m_mltProducer->set("out", duration);
1157 emit durationChanged((int) duration);
1160 while (trackNb > 1) {
1161 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1162 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1163 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1165 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1166 if (trackDuration > duration) duration = trackDuration;
1170 Mlt::Producer blackTrackProducer(tractor.track(0));
1171 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1172 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1174 if (blackDuration != duration) {
1175 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1177 int dur = (int)duration;
1179 QDomElement black = doc.createElement("producer");
1180 black.setAttribute("mlt_service", "colour");
1181 black.setAttribute("colour", "black");
1182 black.setAttribute("id", "black");
1185 while (dur > 14000) {
1186 info.startPos = GenTime(i * 14000, m_fps);
1187 info.endPos = info.startPos + GenTime(13999, m_fps);
1188 mltInsertClip(info, black, m_blackClip);
1193 info.startPos = GenTime(i * 14000, m_fps);
1194 info.endPos = info.startPos + GenTime(dur, m_fps);
1195 mltInsertClip(info, black, m_blackClip);
1197 m_mltProducer->set("out", duration);
1198 emit durationChanged((int)duration);
1202 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1203 if (!m_mltProducer) {
1204 kDebug() << "PLAYLIST NOT INITIALISED //////";
1207 Mlt::Producer parentProd(m_mltProducer->parent());
1208 if (parentProd.get_producer() == NULL) {
1209 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1213 Mlt::Service service(parentProd.get_service());
1214 Mlt::Tractor tractor(service);
1215 mlt_service_lock(service.get_service());
1216 Mlt::Producer trackProducer(tractor.track(info.track));
1217 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1219 Mlt::Producer *clip = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1220 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1222 if (QString(prod->get("transparency")).toInt() == 1)
1223 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());
1225 mlt_service_unlock(service.get_service());
1227 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1228 //tractor.multitrack()->refresh();
1229 //tractor.refresh();
1233 void Render::mltCutClip(int track, GenTime position) {
1237 Mlt::Service service(m_mltProducer->parent().get_service());
1238 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1240 Mlt::Tractor tractor(service);
1241 Mlt::Producer trackProducer(tractor.track(track));
1242 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1245 /* // Display playlist info
1246 kDebug()<<"//////////// BEFORE";
1247 for (int i = 0; i < trackPlaylist.count(); i++) {
1248 int blankStart = trackPlaylist.clip_start(i);
1249 int blankDuration = trackPlaylist.clip_length(i) - 1;
1251 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1252 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1255 int cutPos = (int) position.frames(m_fps);
1257 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1258 if (trackPlaylist.is_blank(clipIndex)) {
1259 kDebug() << "// WARMNING, TRYING TO CUT A BLANK";
1260 m_isBlocked = false;
1263 mlt_service_lock(service.get_service());
1264 int clipStart = trackPlaylist.clip_start(clipIndex);
1265 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1267 // duplicate effects
1268 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1269 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1271 if (original == NULL || clip == NULL) {
1272 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1274 Mlt::Service clipService(original->get_service());
1275 Mlt::Service dupService(clip->get_service());
1277 Mlt::Filter *filter = clipService.filter(ct);
1279 if (filter->get("kdenlive_id") != "") {
1280 kDebug() << "++ ADDING FILTER: " << filter->get("kdenlive_id");
1281 Mlt::Filter *dup = new Mlt::Filter(filter->get_filter());
1282 dup->set("kdenlive_ix", filter->get("kdenlive_ix"));
1283 dup->set("kdenlive_id", filter->get("kdenlive_id"));
1284 dupService.attach(*dup);
1287 filter = clipService.filter(ct);
1289 mlt_service_unlock(service.get_service());
1291 /* // Display playlist info
1292 kDebug()<<"//////////// AFTER";
1293 for (int i = 0; i < trackPlaylist.count(); i++) {
1294 int blankStart = trackPlaylist.clip_start(i);
1295 int blankDuration = trackPlaylist.clip_length(i) - 1;
1297 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1298 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1301 m_isBlocked = false;
1304 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1306 mltRemoveClip(info.track, info.startPos);
1307 mltInsertClip(info, element, prod);
1311 bool Render::mltRemoveClip(int track, GenTime position) {
1312 Mlt::Service service(m_mltProducer->parent().get_service());
1313 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1315 Mlt::Tractor tractor(service);
1316 Mlt::Producer trackProducer(tractor.track(track));
1317 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1318 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1320 /* // Display playlist info
1321 kDebug()<<"//// BEFORE";
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 if (trackPlaylist.is_blank(clipIndex)) {
1331 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1335 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1336 trackPlaylist.replace_with_blank(clipIndex);
1337 trackPlaylist.consolidate_blanks(0);
1338 if (QString(clip.parent().get("transparency")).toInt() == 1)
1339 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());
1341 /* // Display playlist info
1342 kDebug()<<"//// AFTER";
1343 for (int i = 0; i < trackPlaylist.count(); i++) {
1344 int blankStart = trackPlaylist.clip_start(i);
1345 int blankDuration = trackPlaylist.clip_length(i) - 1;
1347 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1348 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1351 if (track != 0 && trackPlaylist.count() > clipIndex) mltCheckLength();
1352 m_isBlocked = false;
1356 int Render::mltChangeClipSpeed(ItemInfo info, double speed, Mlt::Producer *prod) {
1359 Mlt::Service service(m_mltProducer->parent().get_service());
1360 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1361 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1362 Mlt::Tractor tractor(service);
1363 Mlt::Producer trackProducer(tractor.track(info.track));
1364 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1365 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1366 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1367 QString serv = clip.parent().get("mlt_service");
1368 QString id = clip.parent().get("id");
1369 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1370 if (serv == "avformat" && speed != 1.0) {
1371 mlt_service_lock(service.get_service());
1372 QString url = clip.parent().get("resource");
1373 url.append("?" + QString::number(speed));
1374 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1375 if (!slowprod || slowprod->get_producer() == NULL) {
1376 char *tmp = decodedString(url);
1377 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1379 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1380 tmp = decodedString(producerid);
1381 slowprod->set("id", tmp);
1383 m_slowmotionProducers.insert(url, slowprod);
1385 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1386 newLength = cut->get_length();
1387 trackPlaylist.replace_with_blank(clipIndex);
1388 trackPlaylist.consolidate_blanks(0);
1389 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1390 mlt_service_unlock(service.get_service());
1391 } else if (speed == 1.0) {
1392 mlt_service_lock(service.get_service());
1393 Mlt::Producer *cut = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1394 trackPlaylist.replace_with_blank(clipIndex);
1395 newLength = cut->get_length();
1396 trackPlaylist.consolidate_blanks(0);
1397 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1398 mlt_service_unlock(service.get_service());
1399 } else if (serv == "framebuffer") {
1400 mlt_service_lock(service.get_service());
1401 QString url = clip.parent().get("resource");
1402 url = url.section("?", 0, 0);
1403 url.append("?" + QString::number(speed));
1404 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1405 if (!slowprod || slowprod->get_producer() == NULL) {
1406 char *tmp = decodedString(url);
1407 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1409 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1410 tmp = decodedString(producerid);
1411 slowprod->set("id", tmp);
1413 m_slowmotionProducers.insert(url, slowprod);
1415 Mlt::Producer *cut = slowprod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
1416 newLength = cut->get_length();
1417 trackPlaylist.replace_with_blank(clipIndex);
1418 trackPlaylist.consolidate_blanks(0);
1419 trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *cut, 1);
1420 mlt_service_unlock(service.get_service());
1421 kDebug() << "AVFORMAT CLIP!!!:";
1424 m_isBlocked = false;
1428 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1430 Mlt::Service service(m_mltProducer->parent().get_service());
1431 bool success = false;
1432 Mlt::Tractor tractor(service);
1433 Mlt::Producer trackProducer(tractor.track(track));
1434 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1435 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1436 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1438 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1441 Mlt::Service clipService(clip->get_service());
1442 // if (tag.startsWith("ladspa")) tag = "ladspa";
1445 Mlt::Filter *filter = clipService.filter(ct);
1447 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1448 if (clipService.detach(*filter) == 0) success = true;
1449 kDebug() << " / / / DLEETED EFFECT: " << ct;
1451 filter = clipService.filter(ct);
1453 m_isBlocked = false;
1454 if (doRefresh) refresh();
1459 bool Render::mltAddEffect(int track, GenTime position, QMap <QString, QString> args, bool doRefresh) {
1461 Mlt::Service service(m_mltProducer->parent().get_service());
1463 Mlt::Tractor tractor(service);
1464 Mlt::Producer trackProducer(tractor.track(track));
1465 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1467 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1471 Mlt::Service clipService(clip->get_service());
1474 QString tag = args.value("tag");
1475 kDebug() << " / / INSERTING EFFECT: " << tag;
1476 if (tag.startsWith("ladspa")) tag = "ladspa";
1477 char *filterTag = decodedString(tag);
1478 char *filterId = decodedString(args.value("id"));
1479 QMap<QString, QString>::Iterator it;
1480 QString kfr = args.value("keyframes");
1482 if (!kfr.isEmpty()) {
1483 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1484 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1485 char *starttag = decodedString(args.value("starttag", "start"));
1486 char *endtag = decodedString(args.value("endtag", "end"));
1487 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1488 int duration = clip->get_playtime();
1489 double max = args.value("max").toDouble();
1490 double min = args.value("min").toDouble();
1491 double factor = args.value("factor", "1").toDouble();
1492 args.remove("starttag");
1493 args.remove("endtag");
1494 args.remove("keyframes");
1497 args.remove("factor");
1499 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1500 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1501 filter->set("kdenlive_id", filterId);
1502 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1503 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1504 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1505 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1506 if (x2 == -1) x2 = duration;
1507 for (it = args.begin(); it != args.end(); ++it) {
1508 char *name = decodedString(it.key());
1509 char *value = decodedString(it.value());
1510 filter->set(name, value);
1515 filter->set("in", x1);
1516 filter->set("out", x2);
1517 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1518 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1519 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1520 clipService.attach(*filter);
1526 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1527 if (filter && filter->is_valid())
1528 filter->set("kdenlive_id", filterId);
1530 kDebug() << "filter is NULL";
1531 m_isBlocked = false;
1535 for (it = args.begin(); it != args.end(); ++it) {
1536 char *name = decodedString(it.key());
1537 char *value = decodedString(it.value());
1538 filter->set(name, value);
1542 // attach filter to the clip
1543 clipService.attach(*filter);
1547 m_isBlocked = false;
1548 if (doRefresh) refresh();
1552 bool Render::mltEditEffect(int track, GenTime position, QMap <QString, QString> args) {
1553 QString index = args.value("kdenlive_ix");
1554 QString tag = args.value("tag");
1555 QMap<QString, QString>::Iterator it = args.begin();
1556 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1557 // This is a keyframe effect, to edit it, we remove it and re-add it.
1558 mltRemoveEffect(track, position, index);
1559 bool success = mltAddEffect(track, position, args);
1564 Mlt::Service service(m_mltProducer->parent().get_service());
1566 Mlt::Tractor tractor(service);
1567 Mlt::Producer trackProducer(tractor.track(track));
1568 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1569 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1570 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1572 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1575 Mlt::Service clipService(clip->get_service());
1578 Mlt::Filter *filter = clipService.filter(ct);
1580 if (filter->get("kdenlive_ix") == index) {
1584 filter = clipService.filter(ct);
1588 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1589 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1591 filter = clipService.filter(ct);
1592 QList <Mlt::Filter *> filtersList;
1594 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1595 filtersList.append(filter);
1596 clipService.detach(*filter);
1598 filter = clipService.filter(ct);
1600 bool success = mltAddEffect(track, position, args);
1602 for (int i = 0; i < filtersList.count(); i++) {
1603 clipService.attach(*(filtersList.at(i)));
1606 m_isBlocked = false;
1610 for (it = args.begin(); it != args.end(); ++it) {
1611 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1612 char *name = decodedString(it.key());
1613 char *value = decodedString(it.value());
1614 filter->set(name, value);
1618 m_isBlocked = false;
1623 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1625 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1626 Mlt::Service service(m_mltProducer->parent().get_service());
1628 Mlt::Tractor tractor(service);
1629 Mlt::Producer trackProducer(tractor.track(track));
1630 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1631 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1632 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1634 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1637 Mlt::Service clipService(clip->get_service());
1640 QList <Mlt::Filter *> filtersList;
1641 Mlt::Filter *filter = clipService.filter(ct);
1643 if (newPos > oldPos) {
1645 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1646 filter->set("kdenlive_ix", newPos);
1647 filtersList.append(filter);
1648 clipService.detach(*filter);
1649 filter = clipService.filter(ct);
1650 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1651 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1653 filter = clipService.filter(ct);
1657 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1658 filtersList.append(filter);
1659 clipService.detach(*filter);
1661 filter = clipService.filter(ct);
1665 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1666 filter->set("kdenlive_ix", newPos);
1667 filtersList.append(filter);
1668 clipService.detach(*filter);
1670 filter = clipService.filter(ct);
1674 filter = clipService.filter(ct);
1676 int pos = QString(filter->get("kdenlive_ix")).toInt();
1677 if (pos >= newPos) {
1678 if (pos < oldPos) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
1679 filtersList.append(filter);
1680 clipService.detach(*filter);
1682 filter = clipService.filter(ct);
1686 for (int i = 0; i < filtersList.count(); i++) {
1687 clipService.attach(*(filtersList.at(i)));
1690 m_isBlocked = false;
1694 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
1697 Mlt::Service service(m_mltProducer->parent().get_service());
1699 Mlt::Tractor tractor(service);
1700 Mlt::Producer trackProducer(tractor.track(info.track));
1701 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1703 /* // Display playlist info
1704 kDebug()<<"//////////// BEFORE RESIZE";
1705 for (int i = 0; i < trackPlaylist.count(); i++) {
1706 int blankStart = trackPlaylist.clip_start(i);
1707 int blankDuration = trackPlaylist.clip_length(i) - 1;
1709 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1710 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1713 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
1714 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1715 m_isBlocked = false;
1718 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1719 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
1720 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1721 int previousStart = clip->get_in();
1722 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1723 int newDuration = (int) clipDuration.frames(m_fps) - 1;
1724 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
1725 //trackPlaylist.consolidate_blanks(0);
1726 // skip to next clip
1728 int diff = newDuration - previousDuration;
1729 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
1731 // clip was made longer, trim next blank if there is one.
1732 if (trackPlaylist.is_blank(clipIndex)) {
1733 int blankStart = trackPlaylist.clip_start(clipIndex);
1734 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
1735 if (diff - blankDuration == 1) {
1736 trackPlaylist.remove(clipIndex);
1737 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
1739 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
1741 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
1743 trackPlaylist.consolidate_blanks(0);
1745 /* // Display playlist info
1746 kDebug()<<"//////////// AFTER RESIZE";
1747 for (int i = 0; i < trackPlaylist.count(); i++) {
1748 int blankStart = trackPlaylist.clip_start(i);
1749 int blankDuration = trackPlaylist.clip_length(i) - 1;
1751 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1752 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1755 //tractor.multitrack()->refresh();
1756 //tractor.refresh();
1757 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
1758 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1759 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1760 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1761 ItemInfo transpinfo;
1762 transpinfo.startPos = info.startPos;
1763 transpinfo.endPos = info.startPos + clipDuration;
1764 transpinfo.track = info.track;
1765 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1767 m_isBlocked = false;
1771 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
1772 Mlt::Service service(m_mltProducer->parent().get_service());
1773 Mlt::Tractor tractor(service);
1774 Mlt::Producer trackProducer(tractor.track(track));
1775 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1777 if (blind) trackProducer.set("hide", 3);
1778 else trackProducer.set("hide", 2);
1780 trackProducer.set("hide", 1);
1782 trackProducer.set("hide", 0);
1784 tractor.multitrack()->refresh();
1789 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
1790 Mlt::Service service(m_mltProducer->parent().get_service());
1791 int moveFrame = (int) diff.frames(m_fps);
1792 Mlt::Tractor tractor(service);
1793 Mlt::Producer trackProducer(tractor.track(info.track));
1794 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1795 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
1796 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1799 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
1800 /*int previousStart = trackPlaylist.clip_start(clipIndex);
1801 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
1802 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
1803 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1805 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
1808 m_mltConsumer->set("refresh", 0);
1809 int previousStart = clip->get_in();
1810 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1812 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
1813 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
1814 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
1816 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
1817 int blankIndex = clipIndex - 1;
1818 int blankLength = trackPlaylist.clip_length(blankIndex);
1819 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
1820 if (! trackPlaylist.is_blank(blankIndex)) {
1821 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
1823 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
1824 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
1826 trackPlaylist.consolidate_blanks(0);
1827 if (QString(clip->parent().get("transparency")).toInt() == 1) {
1828 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
1829 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1830 ItemInfo transpinfo;
1831 transpinfo.startPos = info.startPos + diff;
1832 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
1833 transpinfo.track = info.track;
1834 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
1836 m_isBlocked = false;
1837 m_mltConsumer->set("refresh", 1);
1841 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd) {
1842 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps));
1846 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd) {
1849 m_mltConsumer->set("refresh", 0);
1850 mlt_service_lock(m_mltConsumer->get_service());
1851 Mlt::Service service(m_mltProducer->parent().get_service());
1852 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1854 Mlt::Tractor tractor(service);
1855 Mlt::Producer trackProducer(tractor.track(startTrack));
1856 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1857 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
1858 bool checkLength = false;
1859 if (endTrack == startTrack) {
1860 //mlt_service_lock(service.get_service());
1861 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1863 if (!trackPlaylist.is_blank_at(moveEnd)) {
1864 // error, destination is not empty
1865 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
1866 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
1867 mlt_service_unlock(m_mltConsumer->get_service());
1868 m_isBlocked = false;
1871 trackPlaylist.consolidate_blanks(0);
1872 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
1873 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1874 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1876 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
1878 //mlt_service_unlock(service.get_service());
1880 Mlt::Producer destTrackProducer(tractor.track(endTrack));
1881 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
1882 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
1883 // error, destination is not empty
1884 mlt_service_unlock(m_mltConsumer->get_service());
1885 m_isBlocked = false;
1888 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
1889 trackPlaylist.consolidate_blanks(0);
1890 destTrackPlaylist.consolidate_blanks(1);
1891 int newIndex = destTrackPlaylist.insert_at(moveEnd, clipProducer, 1);
1892 destTrackPlaylist.consolidate_blanks(0);
1893 if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
1894 kDebug() << "//////// moving clip transparency";
1895 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
1897 if (clipIndex > trackPlaylist.count()) checkLength = true;
1898 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
1902 if (checkLength) mltCheckLength();
1903 mlt_service_unlock(m_mltConsumer->get_service());
1904 m_isBlocked = false;
1905 m_mltConsumer->set("refresh", 1);
1909 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
1911 Mlt::Service service(m_mltProducer->parent().get_service());
1912 Mlt::Tractor tractor(service);
1913 Mlt::Field *field = tractor.field();
1915 mlt_service_lock(service.get_service());
1916 m_mltConsumer->set("refresh", 0);
1919 mlt_service serv = m_mltProducer->parent().get_service();
1920 mlt_service nextservice = mlt_service_get_producer(serv);
1921 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1922 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1923 QString resource = mlt_properties_get(properties, "mlt_service");
1924 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
1926 int new_in = (int)newIn.frames(m_fps);
1927 int new_out = (int)newOut.frames(m_fps);
1929 while (mlt_type == "transition") {
1930 mlt_transition tr = (mlt_transition) nextservice;
1931 int currentTrack = mlt_transition_get_b_track(tr);
1932 int currentIn = (int) mlt_transition_get_in(tr);
1933 int currentOut = (int) mlt_transition_get_out(tr);
1935 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
1936 mlt_transition_set_in_and_out(tr, new_in, new_out);
1937 if (newTrack - startTrack != 0) {
1938 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
1940 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
1941 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
1942 mlt_properties_set_int(properties, "b_track", newTrack);
1943 //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);
1947 nextservice = mlt_service_producer(nextservice);
1948 if (nextservice == NULL) break;
1949 properties = MLT_SERVICE_PROPERTIES(nextservice);
1950 mlt_type = mlt_properties_get(properties, "mlt_type");
1951 resource = mlt_properties_get(properties, "mlt_service");
1953 m_isBlocked = false;
1954 mlt_service_unlock(service.get_service());
1955 m_mltConsumer->set("refresh", 1);
1958 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1959 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
1960 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
1962 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
1963 mltAddTransition(tag, a_track, b_track, in, out, xml);
1965 //mltSavePlaylist();
1968 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
1971 Mlt::Service service(m_mltProducer->parent().get_service());
1972 Mlt::Tractor tractor(service);
1973 Mlt::Field *field = tractor.field();
1975 //m_mltConsumer->set("refresh", 0);
1976 mlt_service serv = m_mltProducer->parent().get_service();
1978 mlt_service nextservice = mlt_service_get_producer(serv);
1979 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1980 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1981 QString resource = mlt_properties_get(properties, "mlt_service");
1982 int in_pos = (int) in.frames(m_fps);
1983 int out_pos = (int) out.frames(m_fps);
1985 while (mlt_type == "transition") {
1986 mlt_transition tr = (mlt_transition) nextservice;
1987 int currentTrack = mlt_transition_get_b_track(tr);
1988 int currentIn = (int) mlt_transition_get_in(tr);
1989 int currentOut = (int) mlt_transition_get_out(tr);
1991 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
1993 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
1994 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
1995 QMap<QString, QString>::Iterator it;
1997 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
1999 for (it = map.begin(); it != map.end(); ++it) {
2001 char *name = decodedString(key);
2002 char *value = decodedString(it.value());
2003 mlt_properties_set(transproperties, name, value);
2004 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2005 //filter->set("kdenlive_id", id);
2011 nextservice = mlt_service_producer(nextservice);
2012 if (nextservice == NULL) break;
2013 properties = MLT_SERVICE_PROPERTIES(nextservice);
2014 mlt_type = mlt_properties_get(properties, "mlt_type");
2015 resource = mlt_properties_get(properties, "mlt_service");
2017 m_isBlocked = false;
2018 m_mltConsumer->set("refresh", 1);
2021 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2022 Mlt::Service service(m_mltProducer->parent().get_service());
2023 Mlt::Tractor tractor(service);
2024 Mlt::Field *field = tractor.field();
2026 if (do_refresh) m_mltConsumer->set("refresh", 0);
2027 mlt_service serv = m_mltProducer->parent().get_service();
2029 mlt_service nextservice = mlt_service_get_producer(serv);
2030 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2031 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2032 QString resource = mlt_properties_get(properties, "mlt_service");
2033 int old_pos = (int)((in + out).frames(m_fps) / 2);
2035 while (mlt_type == "transition") {
2036 mlt_transition tr = (mlt_transition) nextservice;
2037 int currentTrack = mlt_transition_get_b_track(tr);
2038 int currentIn = (int) mlt_transition_get_in(tr);
2039 int currentOut = (int) mlt_transition_get_out(tr);
2040 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2042 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2043 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2044 mlt_field_disconnect_service(field->get_field(), nextservice);
2047 nextservice = mlt_service_producer(nextservice);
2048 if (nextservice == NULL) break;
2049 properties = MLT_SERVICE_PROPERTIES(nextservice);
2050 mlt_type = mlt_properties_get(properties, "mlt_type");
2051 resource = mlt_properties_get(properties, "mlt_service");
2053 if (do_refresh) m_mltConsumer->set("refresh", 1);
2056 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2057 QDomNodeList attribs = xml.elementsByTagName("parameter");
2058 QMap<QString, QString> map;
2059 for (int i = 0;i < attribs.count();i++) {
2060 QDomElement e = attribs.item(i).toElement();
2061 QString name = e.attribute("name");
2062 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2063 map[name] = e.attribute("default");
2064 if (!e.attribute("value").isEmpty()) {
2065 map[name] = e.attribute("value");
2067 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2068 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2069 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2072 if (e.attribute("namedesc").contains(";")) {
2073 QString format = e.attribute("format");
2074 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2075 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2077 QTextStream txtNeu(&neu);
2078 if (values.size() > 0)
2079 txtNeu << (int)values[0].toDouble();
2081 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2082 txtNeu << separators[i];
2083 txtNeu << (int)(values[i+1].toDouble());
2085 if (i < separators.size())
2086 txtNeu << separators[i];
2087 map[e.attribute("name")] = neu;
2094 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2095 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2096 Mlt::Service service(m_mltProducer->parent().get_service());
2097 Mlt::Tractor tractor(service);
2098 Mlt::Field *field = tractor.field();
2100 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2101 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2102 transition->set("transparency", id);
2103 transition->set("fill", 1);
2104 transition->set("internal_added", 237);
2105 field->plant_transition(*transition, transitiontrack, info.track);
2109 void Render::mltDeleteTransparency(int pos, int track, int id) {
2110 Mlt::Service service(m_mltProducer->parent().get_service());
2111 Mlt::Tractor tractor(service);
2112 Mlt::Field *field = tractor.field();
2114 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2115 mlt_service serv = m_mltProducer->parent().get_service();
2117 mlt_service nextservice = mlt_service_get_producer(serv);
2118 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2119 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2120 QString resource = mlt_properties_get(properties, "mlt_service");
2122 while (mlt_type == "transition") {
2123 mlt_transition tr = (mlt_transition) nextservice;
2124 int currentTrack = mlt_transition_get_b_track(tr);
2125 int currentIn = (int) mlt_transition_get_in(tr);
2126 int currentOut = (int) mlt_transition_get_out(tr);
2127 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2128 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2130 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2131 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2132 mlt_field_disconnect_service(field->get_field(), nextservice);
2135 nextservice = mlt_service_producer(nextservice);
2136 if (nextservice == NULL) break;
2137 properties = MLT_SERVICE_PROPERTIES(nextservice);
2138 mlt_type = mlt_properties_get(properties, "mlt_type");
2139 resource = mlt_properties_get(properties, "mlt_service");
2141 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2144 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2145 Mlt::Service service(m_mltProducer->parent().get_service());
2146 Mlt::Tractor tractor(service);
2147 Mlt::Field *field = tractor.field();
2149 mlt_service_lock(service.get_service());
2150 m_mltConsumer->set("refresh", 0);
2153 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");
2158 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
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 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2164 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2165 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2166 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2167 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2168 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2171 nextservice = mlt_service_producer(nextservice);
2172 if (nextservice == NULL) break;
2173 properties = MLT_SERVICE_PROPERTIES(nextservice);
2174 mlt_type = mlt_properties_get(properties, "mlt_type");
2175 resource = mlt_properties_get(properties, "mlt_service");
2177 m_isBlocked = false;
2178 mlt_service_unlock(service.get_service());
2179 m_mltConsumer->set("refresh", 1);
2183 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2184 Mlt::Service service(m_mltProducer->parent().get_service());
2185 Mlt::Tractor tractor(service);
2186 Mlt::Field *field = tractor.field();
2188 mlt_service_lock(service.get_service());
2189 m_mltConsumer->set("refresh", 0);
2192 mlt_service serv = m_mltProducer->parent().get_service();
2193 mlt_service nextservice = mlt_service_get_producer(serv);
2194 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2195 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2196 QString resource = mlt_properties_get(properties, "mlt_service");
2198 while (mlt_type == "transition") {
2199 mlt_transition tr = (mlt_transition) nextservice;
2200 int currentTrack = mlt_transition_get_b_track(tr);
2201 int currentaTrack = mlt_transition_get_a_track(tr);
2202 int currentIn = (int) mlt_transition_get_in(tr);
2203 int currentOut = (int) mlt_transition_get_out(tr);
2204 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2205 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2206 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2207 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2208 kDebug() << "//////MOVING";
2209 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2210 if (endTrack != startTrack) {
2211 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2212 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2213 mlt_properties_set_int(properties, "b_track", endTrack);
2217 nextservice = mlt_service_producer(nextservice);
2218 if (nextservice == NULL) break;
2219 properties = MLT_SERVICE_PROPERTIES(nextservice);
2220 mlt_type = mlt_properties_get(properties, "mlt_type");
2221 resource = mlt_properties_get(properties, "mlt_service");
2223 m_isBlocked = false;
2224 mlt_service_unlock(service.get_service());
2225 m_mltConsumer->set("refresh", 1);
2229 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2231 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2232 Mlt::Service service(m_mltProducer->parent().get_service());
2234 Mlt::Tractor tractor(service);
2235 Mlt::Field *field = tractor.field();
2237 char *transId = decodedString(tag);
2238 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2239 if (out != GenTime())
2240 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps));
2241 QMap<QString, QString>::Iterator it;
2244 kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2246 for (it = args.begin(); it != args.end(); ++it) {
2248 char *name = decodedString(key);
2249 char *value = decodedString(it.value());
2250 transition->set(name, value);
2251 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2252 //filter->set("kdenlive_id", id);
2256 // attach filter to the clip
2257 field->plant_transition(*transition, a_track, b_track);
2262 void Render::mltSavePlaylist() {
2263 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2264 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2265 fileConsumer.set("resource", "/tmp/playlist.westley");
2267 Mlt::Service service(m_mltProducer->get_service());
2269 fileConsumer.connect(service);
2270 fileConsumer.start();
2274 #include "renderer.moc"