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 ***************************************************************************/
29 #include <QApplication>
32 #include <KStandardDirs>
33 #include <KMessageBox>
35 #include <KTemporaryFile>
38 #include "kdenlivesettings.h"
40 #include "definitions.h"
42 #include <mlt++/Mlt.h>
45 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
46 // detect if the producer has finished playing. Is there a better way to do it ?
47 if (self->m_isBlocked) return;
48 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
49 self->emitConsumerStopped();
51 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
55 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) {
56 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
57 refreshTimer = new QTimer(this);
58 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
60 /*if (rendererName == "project") m_monitorId = 10000;
61 else m_monitorId = 10001;*/
62 osdTimer = new QTimer(this);
63 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
65 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
69 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black");
70 m_mltProducer = producer;
71 if (m_blackClip) delete m_blackClip;
72 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
73 m_blackClip->set("id", "black");
74 m_mltConsumer->connect(*m_mltProducer);
75 m_mltProducer->set_speed(0.0);
83 void Render::closeMlt() {
90 if (m_blackClip) delete m_blackClip;
95 void Render::buildConsumer() {
97 m_activeProfile = KdenliveSettings::current_profile();
98 tmp = decodedString(m_activeProfile);
99 setenv("MLT_PROFILE", tmp, 1);
100 m_mltProfile = new Mlt::Profile(tmp);
103 QString videoDriver = KdenliveSettings::videodrivername();
104 if (!videoDriver.isEmpty()) {
105 if (videoDriver == "x11_noaccel") {
106 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
109 unsetenv("SDL_VIDEO_YUV_HWACCEL");
112 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
114 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
115 m_mltConsumer->set("resize", 1);
116 m_mltConsumer->set("window_id", m_winid);
117 m_mltConsumer->set("terminate_on_pause", 1);
119 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
120 m_mltConsumer->set("rescale", "nearest");
122 QString audioDevice = KdenliveSettings::audiodevicename();
123 if (!audioDevice.isEmpty()) {
124 tmp = decodedString(audioDevice);
125 m_mltConsumer->set("audio_device", tmp);
129 if (!videoDriver.isEmpty()) {
130 tmp = decodedString(videoDriver);
131 m_mltConsumer->set("video_driver", tmp);
135 QString audioDriver = KdenliveSettings::audiodrivername();
136 if (!audioDriver.isEmpty()) {
137 tmp = decodedString(audioDriver);
138 m_mltConsumer->set("audio_driver", tmp);
143 m_mltConsumer->set("progressive", 1);
144 m_mltConsumer->set("audio_buffer", 1024);
145 m_mltConsumer->set("frequency", 48000);
148 int Render::resetProfile() {
149 if (!m_mltConsumer) return 0;
150 if (m_activeProfile == KdenliveSettings::current_profile()) {
151 kDebug() << "reset to same profile, nothing to do";
154 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
155 if (m_isSplitView) slotSplitView(false);
156 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
157 m_mltConsumer->purge();
158 delete m_mltConsumer;
159 m_mltConsumer = NULL;
160 QString scene = sceneList();
163 pos = m_mltProducer->position();
164 delete m_mltProducer;
166 m_mltProducer = NULL;
168 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
169 /*if (m_mltProfile) delete m_mltProfile;
170 m_mltProfile = NULL;*/
174 //kDebug() << "//RESET WITHSCENE: " << scene;
175 setSceneList(scene, pos);
177 /*char *tmp = decodedString(scene);
178 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
180 m_mltProducer = producer;
181 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
182 m_mltProducer->optimise();
183 m_mltProducer->set_speed(0);
186 //delete m_mltProfile;
187 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
188 //mlt_profile prof = m_mltProfile->get_profile();
189 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
190 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
191 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
192 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
194 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
199 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
200 void Render::seek(GenTime time) {
204 m_mltProducer->seek((int)(time.frames(m_fps)));
209 char *Render::decodedString(QString str) {
210 /*QCString fn = QFile::encodeName(str);
211 char *t = new char[fn.length() + 1];
212 strcpy(t, (const char *)fn);*/
214 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
218 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
219 QPixmap pix(width, height);
221 mlt_image_format format = mlt_image_rgb24a;
222 uint8_t *thumb = frame->get_image(format, width, height);
223 QImage image(thumb, width, height, QImage::Format_ARGB32);
225 if (!image.isNull()) {
226 pix = pix.fromImage(image);
228 QPainter painter(&pix);
229 painter.drawRect(0, 0, width - 1, height - 1);
231 } else pix.fill(Qt::black);
235 const int Render::renderWidth() const {
236 return (int)(m_mltProfile->height() * m_mltProfile->dar());
239 const int Render::renderHeight() const {
240 return m_mltProfile->height();
243 QPixmap Render::extractFrame(int frame_position, int width, int height) {
245 width = renderWidth();
246 height = renderHeight();
248 QPixmap pix(width, height);
249 if (!m_mltProducer) {
253 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
256 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
259 if (url.fileName().startsWith(".all.")) { // check for slideshow
260 QString fileType = url.fileName().right(3);
262 QStringList::Iterator it;
264 QDir dir(url.directory());
266 filter << "*." + fileType;
267 filter << "*." + fileType.toUpper();
268 more = dir.entryList(filter, QDir::Files);
269 im.load(url.directory() + "/" + more.at(0));
270 } else im.load(url.path());
271 //pixmap = im.scaled(width, height);
276 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
277 QPixmap pix(width, height);
278 char *tmp = decodedString(file);
279 Mlt::Profile *prof = new Mlt::Profile(profile);
280 Mlt::Producer m_producer(*prof, tmp);
282 if (m_producer.is_blank()) {
287 Mlt::Filter m_convert(*prof, "avcolour_space");
288 m_convert.set("forced", mlt_image_rgb24a);
289 m_producer.attach(m_convert);
290 m_producer.seek(frame_position);
291 Mlt::Frame * frame = m_producer.get_frame();
293 pix = frameThumbnail(frame, width, height, true);
296 if (prof) delete prof;
301 void Render::getImage(KUrl url, int frame_position, QPoint size)
303 char *tmp = decodedString(url.path());
304 Mlt::Producer m_producer(tmp);
306 if (m_producer.is_blank()) {
309 Mlt::Filter m_convert("avcolour_space");
310 m_convert.set("forced", mlt_image_rgb24a);
311 m_producer.attach(m_convert);
312 m_producer.seek(frame_position);
314 Mlt::Frame * frame = m_producer.get_frame();
317 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
319 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
323 /* Create thumbnail for color */
324 /*void Render::getImage(int id, QString color, QPoint size)
326 QPixmap pixmap(size.x() - 2, size.y() - 2);
327 color = color.replace(0, 2, "#");
328 color = color.left(7);
329 pixmap.fill(QColor(color));
330 QPixmap result(size.x(), size.y());
331 result.fill(Qt::black);
332 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
333 emit replyGetImage(id, result, size.x(), size.y());
337 /* Create thumbnail for image */
338 /*void Render::getImage(KUrl url, QPoint size)
342 if (url.fileName().startsWith(".all.")) { // check for slideshow
343 QString fileType = url.fileName().right(3);
345 QStringList::Iterator it;
347 QDir dir( url.directory() );
348 more = dir.entryList( QDir::Files );
349 for ( it = more.begin() ; it != more.end() ; ++it ) {
350 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
351 if (!im.load(url.directory() + "/" + *it))
352 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
357 else im.load(url.path());
359 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
360 QPixmap result(size.x(), size.y());
361 result.fill(Qt::black);
362 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
363 emit replyGetImage(url, 1, result, size.x(), size.y());
367 double Render::consumerRatio() const {
368 if (!m_mltConsumer) return 1.0;
369 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
373 int Render::getLength() {
376 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
377 return mlt_producer_get_playtime(m_mltProducer->get_producer());
382 bool Render::isValid(KUrl url) {
383 char *tmp = decodedString(url.path());
384 Mlt::Producer producer(*m_mltProfile, tmp);
386 if (producer.is_blank())
392 const double Render::dar() const {
393 return m_mltProfile->dar();
396 void Render::slotSplitView(bool doit) {
397 m_isSplitView = doit;
398 Mlt::Service service(m_mltProducer->parent().get_service());
399 Mlt::Tractor tractor(service);
400 if (service.type() != tractor_type || tractor.count() < 2) return;
401 Mlt::Field *field = tractor.field();
404 for (int i = 1; i < tractor.count() && screen < 4; i++) {
405 Mlt::Producer trackProducer(tractor.track(i));
406 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
407 if (QString(trackProducer.get("hide")).toInt() != 1) {
408 kDebug() << "// ADIDNG TRACK: " << i;
409 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
410 transition->set("mlt_service", "composite");
411 transition->set("a_track", 0);
412 transition->set("b_track", i);
413 transition->set("distort", 1);
414 transition->set("internal_added", "200");
421 tmp = "50%,0:50%x50%";
424 tmp = "0,50%:50%x50%";
427 tmp = "50%,50%:50%x50%";
430 transition->set("geometry", tmp);
431 transition->set("always_active", "1");
432 field->plant_transition(*transition, 0, i);
437 m_mltConsumer->set("refresh", 1);
439 mlt_service serv = m_mltProducer->parent().get_service();
440 mlt_service nextservice = mlt_service_get_producer(serv);
441 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
442 QString mlt_type = mlt_properties_get(properties, "mlt_type");
443 QString resource = mlt_properties_get(properties, "mlt_service");
445 while (mlt_type == "transition") {
446 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
447 if (added == "200") {
448 mlt_field_disconnect_service(field->get_field(), nextservice);
450 nextservice = mlt_service_producer(nextservice);
451 if (nextservice == NULL) break;
452 properties = MLT_SERVICE_PROPERTIES(nextservice);
453 mlt_type = mlt_properties_get(properties, "mlt_type");
454 resource = mlt_properties_get(properties, "mlt_service");
455 m_mltConsumer->set("refresh", 1);
460 void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
462 int width = (int)(height * m_mltProfile->dar());
463 QMap < QString, QString > filePropertyMap;
464 QMap < QString, QString > metadataPropertyMap;
466 KUrl url = KUrl(xml.attribute("resource", QString::null));
467 Mlt::Producer *producer = NULL;
468 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
469 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
472 if (xml.attribute("type").toInt() == COLOR) {
473 char *tmp = decodedString("colour:" + xml.attribute("colour"));
474 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
476 } else if (url.isEmpty()) {
478 QDomElement westley = doc.createElement("westley");
479 QDomElement play = doc.createElement("playlist");
480 doc.appendChild(westley);
481 westley.appendChild(play);
482 play.appendChild(doc.importNode(xml, true));
483 char *tmp = decodedString(doc.toString());
484 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
487 QString urlpath = url.path();
488 /*if (urlpath.contains(':')) {
489 if (!urlpath.startsWith("file:")) urlpath.prepend("file:");
490 char *tmp = decodedString(urlpath);
491 producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp);
495 char *tmp = decodedString(urlpath);
496 producer = new Mlt::Producer(*m_mltProfile, tmp);
499 if (xml.hasAttribute("force_aspect_ratio")) {
500 double aspect = xml.attribute("force_aspect_ratio").toDouble();
501 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
503 if (xml.hasAttribute("threads")) {
504 int threads = xml.attribute("threads").toInt();
505 if (threads != 1) producer->set("threads", threads);
507 if (xml.hasAttribute("video_index")) {
508 int vindex = xml.attribute("video_index").toInt();
509 if (vindex != 0) producer->set("video_index", vindex);
511 if (xml.hasAttribute("audio_index")) {
512 int aindex = xml.attribute("audio_index").toInt();
513 if (aindex != 0) producer->set("audio_index", aindex);
518 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
519 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
520 emit removeInvalidClip(clipId);
524 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
526 char *tmp = decodedString(clipId);
527 producer->set("id", tmp);
529 int frameNumber = xml.attribute("thumbnail", "0").toInt();
530 if (frameNumber != 0) producer->seek(frameNumber);
531 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
533 filePropertyMap["duration"] = QString::number(producer->get_playtime());
534 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
536 Mlt::Frame *frame = producer->get_frame();
538 if (xml.attribute("type").toInt() == SLIDESHOW) {
539 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
540 if (xml.attribute("fade") == "1") {
541 // user wants a fade effect to slideshow
542 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
543 if (filter && filter->is_valid()) {
544 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
545 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
546 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
547 char *tmp = decodedString(xml.attribute("luma_file"));
548 filter->set("luma.resource", tmp);
550 if (xml.hasAttribute("softness")) {
551 int soft = xml.attribute("softness").toInt();
552 filter->set("luma.softness", (double) soft / 100.0);
555 Mlt::Service clipService(producer->get_service());
556 clipService.attach(*filter);
562 filePropertyMap["fps"] = producer->get("source_fps");
564 if (frame && frame->is_valid()) {
565 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
566 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
567 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
568 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
570 if (frame->get_int("test_image") == 0) {
571 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
572 filePropertyMap["type"] = "playlist";
573 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
574 } else if (frame->get_int("test_audio") == 0)
575 filePropertyMap["type"] = "av";
577 filePropertyMap["type"] = "video";
579 mlt_image_format format = mlt_image_yuv422;
581 int frame_height = 0;
582 //frame->set("rescale.interp", "hyper");
583 frame->set("normalised_height", height);
584 frame->set("normalised_width", width);
585 QPixmap pix(width, height);
587 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
588 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
589 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
590 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
592 if (!image.isNull()) {
593 pix = QPixmap::fromImage(image.rgbSwapped());
597 mlt_pool_release(new_image);
598 emit replyGetImage(clipId, 0, pix, width, height);
600 } else if (frame->get_int("test_audio") == 0) {
601 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
602 emit replyGetImage(clipId, 0, pixmap, width, height);
603 filePropertyMap["type"] = "audio";
607 // Retrieve audio / video codec name
611 if (producer->get_int("video_index") > -1) {
612 /*if (context->duration == AV_NOPTS_VALUE) {
613 kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
614 emit removeInvalidClip(clipId);
617 // Get the video_index
618 int default_video = producer->get_int("video_index");
620 int default_audio = producer->get_int("audio_index");
623 // Find maximum stream index values
624 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
625 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
626 QString type = producer->get(property);
629 else if (type == "audio")
632 filePropertyMap["default_video"] = QString::number(default_video);
633 filePropertyMap["video_max"] = QString::number(video_max);
634 filePropertyMap["default_audio"] = QString::number(default_audio);
635 filePropertyMap["audio_max"] = QString::number(audio_max);
637 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
638 if (producer->get(property)) {
639 filePropertyMap["videocodec"] = producer->get(property);
641 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
642 if (producer->get(property))
643 filePropertyMap["videocodec"] = producer->get(property);
645 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
646 if (producer->get_int("audio_index") > -1) {
647 // Get the audio_index
648 int index = producer->get_int("audio_index");
650 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
651 if (producer->get(property)) {
652 filePropertyMap["audiocodec"] = producer->get(property);
654 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
655 if (producer->get(property))
656 filePropertyMap["audiocodec"] = producer->get(property);
661 Mlt::Properties metadata;
662 metadata.pass_values(*producer, "meta.attr.");
663 int count = metadata.count();
664 for (int i = 0; i < count; i ++) {
665 QString name = metadata.get_name(i);
666 QString value = QString::fromUtf8(metadata.get(i));
667 if (name.endsWith("markup") && !value.isEmpty())
668 metadataPropertyMap[ name.section(".", 0, -2)] = value;
671 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
672 kDebug() << "REquested fuile info for: " << url.path();
673 if (frame) delete frame;
674 //if (producer) delete producer;
678 /** Create the producer from the Westley QDomDocument */
680 void Render::initSceneList() {
681 kDebug() << "-------- INIT SCENE LIST ------_";
683 QDomElement westley = doc.createElement("westley");
684 doc.appendChild(westley);
685 QDomElement prod = doc.createElement("producer");
686 prod.setAttribute("resource", "colour");
687 prod.setAttribute("colour", "red");
688 prod.setAttribute("id", "black");
689 prod.setAttribute("in", "0");
690 prod.setAttribute("out", "0");
692 QDomElement tractor = doc.createElement("tractor");
693 QDomElement multitrack = doc.createElement("multitrack");
695 QDomElement playlist1 = doc.createElement("playlist");
696 playlist1.appendChild(prod);
697 multitrack.appendChild(playlist1);
698 QDomElement playlist2 = doc.createElement("playlist");
699 multitrack.appendChild(playlist2);
700 QDomElement playlist3 = doc.createElement("playlist");
701 multitrack.appendChild(playlist3);
702 QDomElement playlist4 = doc.createElement("playlist");
703 multitrack.appendChild(playlist4);
704 QDomElement playlist5 = doc.createElement("playlist");
705 multitrack.appendChild(playlist5);
706 tractor.appendChild(multitrack);
707 westley.appendChild(tractor);
708 // kDebug()<<doc.toString();
710 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
711 setSceneList(doc, 0);
717 /** Create the producer from the Westley QDomDocument */
718 void Render::setProducer(Mlt::Producer *producer, int position) {
719 if (m_winid == -1) return;
722 m_mltConsumer->stop();
727 m_mltProducer->set_speed(0);
728 delete m_mltProducer;
729 m_mltProducer = NULL;
732 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
733 else m_mltProducer = new Mlt::Producer();
734 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
736 m_fps = m_mltProducer->get_fps();
738 if (position != -1) {
739 m_mltProducer->seek(position);
740 emit rendererPosition(position);
747 /** Create the producer from the Westley QDomDocument */
748 void Render::setSceneList(QDomDocument list, int position) {
749 setSceneList(list.toString(), position);
752 /** Create the producer from the Westley QDomDocument */
753 void Render::setSceneList(QString playlist, int position) {
754 if (m_winid == -1) return;
756 m_slowmotionProducers.clear();
758 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
761 m_mltConsumer->stop();
762 //m_mltConsumer->set("refresh", 0);
769 m_mltProducer->set_speed(0);
770 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
772 delete m_mltProducer;
773 m_mltProducer = NULL;
778 char *tmp = decodedString(playlist);
779 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
781 if (m_blackClip) delete m_blackClip;
782 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
783 m_blackClip->set("id", "black");
784 if (!m_mltProducer || !m_mltProducer->is_valid()) {
785 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
787 m_mltProducer->optimise();
789 /*if (KdenliveSettings::osdtimecode()) {
790 // Attach filter for on screen display of timecode
792 QString attr = "attr_check";
793 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
794 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
795 mlt_producer_attach( m_mltProducer->get_producer(), filter );
796 mlt_filter_close( filter );
798 m_osdInfo = new Mlt::Filter("data_show");
799 tmp = decodedString(m_osdProfile);
800 m_osdInfo->set("resource", tmp);
802 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
803 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
804 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
805 m_osdInfo->set("dynamic", "1");
807 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
809 m_osdInfo->set("dynamic", "0");
812 m_fps = m_mltProducer->get_fps();
813 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
815 fillSlowMotionProducers();
817 //TODO: seek to correct place after opening project.
818 // Needs to be done from another place since it crashes here.
819 m_mltProducer->seek(position);
823 //kDebug()<<"// SETSCN LST, POS: "<<position;
824 //if (position != 0) emit rendererPosition(position);
827 /** Create the producer from the Westley QDomDocument */
828 QString Render::sceneList() {
830 Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
831 m_mltProducer->optimise();
832 westleyConsumer.set("terminate_on_pause", 1);
833 Mlt::Producer prod(m_mltProducer->get_producer());
834 bool split = m_isSplitView;
835 if (split) slotSplitView(false);
836 westleyConsumer.connect(prod);
837 westleyConsumer.start();
838 while (!westleyConsumer.is_stopped()) {}
839 playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
840 if (split) slotSplitView(true);
844 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
847 doc.setContent(sceneList(), false);
848 if (!kdenliveData.isNull()) {
849 // add Kdenlive specific tags
850 QDomNode wes = doc.elementsByTagName("westley").at(0);
851 wes.appendChild(doc.importNode(kdenliveData, true));
853 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
854 kWarning() << "////// ERROR writing to file: " << path;
857 QTextStream out(&file);
858 out << doc.toString();
863 void Render::saveZone(KUrl url, QString desc, QPoint zone) {
864 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
865 char *tmppath = decodedString("westley:" + url.path());
866 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
867 m_mltProducer->optimise();
869 westleyConsumer.set("terminate_on_pause", 1);
870 if (m_name == "clip") {
871 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
872 tmppath = decodedString(desc);
874 list.insert_at(0, prod, 0);
875 list.set("title", tmppath);
877 westleyConsumer.connect(list);
880 //TODO: not working yet, save zone from timeline
881 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
882 /* Mlt::Service service(p1->parent().get_service());
883 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
885 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
886 tmppath = decodedString(desc);
887 //prod->set("title", tmppath);
889 westleyConsumer.connect(*p1); //list);
892 westleyConsumer.start();
895 const double Render::fps() const {
899 void Render::connectPlaylist() {
900 if (!m_mltConsumer) return;
901 //m_mltConsumer->set("refresh", "0");
902 m_mltConsumer->connect(*m_mltProducer);
903 m_mltProducer->set_speed(0);
904 m_mltConsumer->start();
905 emit durationChanged(m_mltProducer->get_playtime());
908 if (m_mltConsumer->start() == -1) {
909 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."));
910 m_mltConsumer = NULL;
917 void Render::refreshDisplay() {
919 if (!m_mltProducer) return;
920 //m_mltConsumer->set("refresh", 0);
922 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
923 /*if (KdenliveSettings::osdtimecode()) {
924 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
925 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
926 m_osdInfo->set("dynamic", "1");
927 m_mltProducer->attach(*m_osdInfo);
930 m_mltProducer->detach(*m_osdInfo);
931 m_osdInfo->set("dynamic", "0");
936 void Render::setVolume(double volume) {
937 if (!m_mltConsumer || !m_mltProducer) return;
939 m_mltConsumer->set("refresh", 0);
940 // Attach filter for on screen display of timecode
941 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
942 mlt_properties_set_double( properties, "meta.volume", volume );
943 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
944 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
946 if (!KdenliveSettings::osdtimecode()) {
947 m_mltProducer->detach(*m_osdInfo);
948 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
949 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
952 osdTimer->setSingleShot(2500);
955 void Render::slotOsdTimeout() {
956 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
957 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
958 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
959 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
963 void Render::start() {
964 kDebug() << "----- STARTING MONITOR: " << m_name;
966 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
970 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
971 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
972 if (m_mltConsumer->start() == -1) {
973 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."));
974 m_mltConsumer = NULL;
977 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
985 void Render::clear() {
986 kDebug() << " ********* RENDER CLEAR";
988 //m_mltConsumer->set("refresh", 0);
989 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
993 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
994 m_mltProducer->set_speed(0.0);
995 delete m_mltProducer;
996 m_mltProducer = NULL;
1001 void Render::stop() {
1002 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1003 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1005 m_mltConsumer->set("refresh", 0);
1006 m_mltConsumer->stop();
1007 // delete m_mltConsumer;
1008 // m_mltConsumer = NULL;
1010 kDebug() << "///////////// RENDER STOP2-------";
1013 if (m_mltProducer) {
1014 if (m_isZoneMode) resetZoneMode();
1015 m_mltProducer->set_speed(0.0);
1016 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1017 //kDebug() << m_mltProducer->get_length();
1019 kDebug() << "///////////// RENDER STOP3-------";
1022 void Render::stop(const GenTime & startTime) {
1024 kDebug() << "///////////// RENDER STOP-------2";
1025 if (m_mltProducer) {
1026 if (m_isZoneMode) resetZoneMode();
1027 m_mltProducer->set_speed(0.0);
1028 m_mltProducer->seek((int) startTime.frames(m_fps));
1030 m_mltConsumer->purge();
1033 void Render::pause() {
1034 if (!m_mltProducer || !m_mltConsumer)
1036 if (m_mltProducer->get_speed() == 0.0) return;
1037 if (m_isZoneMode) resetZoneMode();
1039 m_mltConsumer->set("refresh", 0);
1040 m_mltProducer->set_speed(0.0);
1041 emit rendererPosition(m_framePosition);
1042 m_mltProducer->seek(m_framePosition);
1043 m_mltConsumer->purge();
1046 void Render::switchPlay() {
1047 if (!m_mltProducer || !m_mltConsumer)
1049 if (m_isZoneMode) resetZoneMode();
1050 if (m_mltProducer->get_speed() == 0.0) {
1051 m_isBlocked = false;
1052 m_mltProducer->set_speed(1.0);
1053 m_mltConsumer->set("refresh", 1);
1056 m_mltConsumer->set("refresh", 0);
1057 m_mltProducer->set_speed(0.0);
1058 emit rendererPosition(m_framePosition);
1059 m_mltProducer->seek(m_framePosition);
1060 m_mltConsumer->purge();
1061 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1062 //m_mltConsumer->set("refresh", 0);
1063 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1064 m_mltProducer->set_speed(0);
1065 m_mltProducer->seek( position );
1066 //m_mltProducer->seek((int) m_framePosition);
1067 m_isBlocked = false;*/
1069 /*if (speed == 0.0) {
1070 m_mltProducer->seek((int) m_framePosition + 1);
1071 m_mltConsumer->purge();
1076 void Render::play(double speed) {
1079 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1080 m_isBlocked = false;
1081 m_mltProducer->set_speed(speed);
1082 /*if (speed == 0.0) {
1083 m_mltProducer->seek((int) m_framePosition + 1);
1084 m_mltConsumer->purge();
1089 void Render::play(const GenTime & startTime) {
1090 if (!m_mltProducer || !m_mltConsumer)
1092 m_isBlocked = false;
1093 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1094 m_mltProducer->set_speed(1.0);
1095 m_mltConsumer->set("refresh", 1);
1098 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1099 if (!m_mltProducer || !m_mltConsumer)
1101 //m_mltProducer->set("eof", "loop");
1102 m_isLoopMode = true;
1103 m_loopStart = startTime;
1104 playZone(startTime, stopTime);
1107 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1108 if (!m_mltProducer || !m_mltConsumer)
1110 m_isBlocked = false;
1111 m_mltProducer->set("out", stopTime.frames(m_fps));
1112 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1113 m_mltProducer->set_speed(1.0);
1114 m_mltConsumer->set("refresh", 1);
1115 m_isZoneMode = true;
1118 void Render::resetZoneMode() {
1119 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1120 //m_mltProducer->set("eof", "pause");
1121 m_isZoneMode = false;
1122 m_isLoopMode = false;
1125 void Render::seekToFrame(int pos) {
1126 //kDebug()<<" ********* RENDER SEEK TO POS";
1129 m_isBlocked = false;
1131 m_mltProducer->seek(pos);
1135 void Render::askForRefresh() {
1136 // Use a Timer so that we don't refresh too much
1137 refreshTimer->start(200);
1140 void Render::doRefresh() {
1141 // Use a Timer so that we don't refresh too much
1142 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1145 void Render::refresh() {
1146 if (!m_mltProducer || m_isBlocked)
1148 refreshTimer->stop();
1149 if (m_mltConsumer) {
1150 m_mltConsumer->set("refresh", 1);
1154 double Render::playSpeed() {
1155 if (m_mltProducer) return m_mltProducer->get_speed();
1159 GenTime Render::seekPosition() const {
1160 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1161 else return GenTime();
1165 const QString & Render::rendererName() const {
1170 void Render::emitFrameNumber(double position) {
1171 m_framePosition = position;
1172 emit rendererPosition((int) position);
1173 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1176 void Render::emitConsumerStopped() {
1177 // This is used to know when the playing stopped
1178 if (m_mltProducer) {
1179 double pos = m_mltProducer->position();
1180 if (m_isLoopMode) play(m_loopStart);
1181 else if (m_isZoneMode) resetZoneMode();
1182 emit rendererStopped((int) pos);
1183 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1184 //new QCustomEvent(10002));
1190 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1191 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1195 void Render::exportCurrentFrame(KUrl url, bool notify) {
1196 if (!m_mltProducer) {
1197 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1201 int height = 1080;//KdenliveSettings::defaultheight();
1202 int width = 1940; //KdenliveSettings::displaywidth();
1204 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1206 QPixmap pix(width, height);
1207 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1208 m_convert.set("forced", mlt_image_rgb24a);
1209 m_mltProducer->attach(m_convert);
1210 Mlt::Frame * frame = m_mltProducer->get_frame();
1211 m_mltProducer->detach(m_convert);
1213 pix = frameThumbnail(frame, width, height);
1216 pix.save(url.path(), "PNG");
1217 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1220 /** MLT PLAYLIST DIRECT MANIPULATON **/
1223 void Render::mltCheckLength() {
1224 //kDebug()<<"checking track length: "<<track<<"..........";
1226 Mlt::Service service(m_mltProducer->get_service());
1227 Mlt::Tractor tractor(service);
1229 int trackNb = tractor.count();
1230 double duration = 0;
1231 double trackDuration;
1233 Mlt::Producer trackProducer(tractor.track(0));
1234 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1235 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1236 m_mltProducer->set("out", duration);
1237 emit durationChanged((int) duration);
1240 while (trackNb > 1) {
1241 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1242 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1243 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1245 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1246 if (trackDuration > duration) duration = trackDuration;
1250 Mlt::Producer blackTrackProducer(tractor.track(0));
1251 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1252 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1254 if (blackDuration != duration) {
1255 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1257 int dur = (int)duration;
1259 QDomElement black = doc.createElement("producer");
1260 black.setAttribute("mlt_service", "colour");
1261 black.setAttribute("colour", "black");
1262 black.setAttribute("id", "black");
1265 while (dur > 14000) {
1266 info.startPos = GenTime(i * 14000, m_fps);
1267 info.endPos = info.startPos + GenTime(13999, m_fps);
1268 mltInsertClip(info, black, m_blackClip);
1273 info.startPos = GenTime(i * 14000, m_fps);
1274 info.endPos = info.startPos + GenTime(dur, m_fps);
1275 mltInsertClip(info, black, m_blackClip);
1277 m_mltProducer->set("out", duration);
1278 emit durationChanged((int)duration);
1282 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1283 if (!m_mltProducer) {
1284 kDebug() << "PLAYLIST NOT INITIALISED //////";
1287 Mlt::Producer parentProd(m_mltProducer->parent());
1288 if (parentProd.get_producer() == NULL) {
1289 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1293 Mlt::Service service(parentProd.get_service());
1294 Mlt::Tractor tractor(service);
1295 mlt_service_lock(service.get_service());
1296 Mlt::Producer trackProducer(tractor.track(info.track));
1297 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1298 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1300 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1301 // We want a slowmotion producer
1302 double speed = element.attribute("speed", "1.0").toDouble();
1303 QString url = prod->get("resource");
1304 url.append("?" + QString::number(speed));
1305 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1306 if (!slowprod || slowprod->get_producer() == NULL) {
1307 char *tmp = decodedString(url);
1308 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1310 QString id = prod->get("id");
1311 if (id.contains('_')) id = id.section('_', 0, 0);
1312 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1313 tmp = decodedString(producerid);
1314 slowprod->set("id", tmp);
1316 m_slowmotionProducers.insert(url, slowprod);
1321 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1322 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1324 /*if (QString(prod->get("transparency")).toInt() == 1)
1325 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1327 mlt_service_unlock(service.get_service());
1329 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1330 //tractor.multitrack()->refresh();
1331 //tractor.refresh();
1335 void Render::mltCutClip(int track, GenTime position) {
1339 Mlt::Service service(m_mltProducer->parent().get_service());
1340 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1342 Mlt::Tractor tractor(service);
1343 Mlt::Producer trackProducer(tractor.track(track));
1344 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1347 /* // Display playlist info
1348 kDebug()<<"//////////// BEFORE";
1349 for (int i = 0; i < trackPlaylist.count(); i++) {
1350 int blankStart = trackPlaylist.clip_start(i);
1351 int blankDuration = trackPlaylist.clip_length(i) - 1;
1353 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1354 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1357 int cutPos = (int) position.frames(m_fps);
1359 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1360 if (trackPlaylist.is_blank(clipIndex)) {
1361 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1362 m_isBlocked = false;
1365 mlt_service_lock(service.get_service());
1366 int clipStart = trackPlaylist.clip_start(clipIndex);
1367 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1368 mlt_service_unlock(service.get_service());
1370 // duplicate effects
1371 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1372 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1374 if (original == NULL || clip == NULL) {
1375 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1377 Mlt::Service clipService(original->get_service());
1378 Mlt::Service dupService(clip->get_service());
1380 Mlt::Filter *filter = clipService.filter(ct);
1382 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1383 // looks like there is no easy way to duplicate a filter,
1384 // so we will create a new one and duplicate its properties
1385 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1386 if (dup && dup->is_valid()) {
1387 Mlt::Properties entries(filter->get_properties());
1388 for (int i = 0;i < entries.count();i++) {
1389 dup->set(entries.get_name(i), entries.get(i));
1391 dupService.attach(*dup);
1395 filter = clipService.filter(ct);
1398 /* // Display playlist info
1399 kDebug()<<"//////////// AFTER";
1400 for (int i = 0; i < trackPlaylist.count(); i++) {
1401 int blankStart = trackPlaylist.clip_start(i);
1402 int blankDuration = trackPlaylist.clip_length(i) - 1;
1404 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1405 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1408 m_isBlocked = false;
1411 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1413 mltRemoveClip(info.track, info.startPos);
1414 mltInsertClip(info, element, prod);
1418 bool Render::mltRemoveClip(int track, GenTime position) {
1419 Mlt::Service service(m_mltProducer->parent().get_service());
1420 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1422 Mlt::Tractor tractor(service);
1423 Mlt::Producer trackProducer(tractor.track(track));
1424 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1425 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1427 /* // Display playlist info
1428 kDebug()<<"//// BEFORE";
1429 for (int i = 0; i < trackPlaylist.count(); i++) {
1430 int blankStart = trackPlaylist.clip_start(i);
1431 int blankDuration = trackPlaylist.clip_length(i) - 1;
1433 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1434 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1437 if (trackPlaylist.is_blank(clipIndex)) {
1438 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1442 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1443 trackPlaylist.replace_with_blank(clipIndex);
1444 trackPlaylist.consolidate_blanks(0);
1445 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1446 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1448 /* // Display playlist info
1449 kDebug()<<"//// AFTER";
1450 for (int i = 0; i < trackPlaylist.count(); i++) {
1451 int blankStart = trackPlaylist.clip_start(i);
1452 int blankDuration = trackPlaylist.clip_length(i) - 1;
1454 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1455 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1458 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1459 m_isBlocked = false;
1463 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
1464 if (!m_mltProducer) {
1465 kDebug() << "PLAYLIST NOT INITIALISED //////";
1468 Mlt::Producer parentProd(m_mltProducer->parent());
1469 if (parentProd.get_producer() == NULL) {
1470 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1474 Mlt::Service service(parentProd.get_service());
1475 Mlt::Tractor tractor(service);
1476 int insertPos = pos.frames(m_fps);
1478 Mlt::Producer trackProducer(tractor.track(track));
1479 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1480 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1481 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1482 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1483 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1487 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
1488 if (!m_mltProducer) {
1489 kDebug() << "PLAYLIST NOT INITIALISED //////";
1492 Mlt::Producer parentProd(m_mltProducer->parent());
1493 if (parentProd.get_producer() == NULL) {
1494 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1497 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1498 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1500 Mlt::Service service(parentProd.get_service());
1501 Mlt::Tractor tractor(service);
1502 mlt_service_lock(service.get_service());
1503 int diff = duration.frames(m_fps);
1504 int offset = timeOffset.frames(m_fps);
1508 // insert space in one track only
1509 Mlt::Producer trackProducer(tractor.track(track));
1510 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1511 insertPos = trackClipStartList.value(track);
1512 if (insertPos != -1) {
1513 insertPos += offset;
1514 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1515 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1517 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1518 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1519 int position = trackPlaylist.clip_start(clipIndex);
1520 trackPlaylist.remove_region(position, - diff - 1);
1522 trackPlaylist.consolidate_blanks(0);
1524 // now move transitions
1525 mlt_service serv = m_mltProducer->parent().get_service();
1526 mlt_service nextservice = mlt_service_get_producer(serv);
1527 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1528 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1529 QString resource = mlt_properties_get(properties, "mlt_service");
1531 while (mlt_type == "transition") {
1532 mlt_transition tr = (mlt_transition) nextservice;
1533 int currentTrack = mlt_transition_get_b_track(tr);
1534 int currentIn = (int) mlt_transition_get_in(tr);
1535 int currentOut = (int) mlt_transition_get_out(tr);
1536 insertPos = trackTransitionStartList.value(track);
1537 if (insertPos != -1) {
1538 insertPos += offset;
1539 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1540 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1543 nextservice = mlt_service_producer(nextservice);
1544 if (nextservice == NULL) break;
1545 properties = MLT_SERVICE_PROPERTIES(nextservice);
1546 mlt_type = mlt_properties_get(properties, "mlt_type");
1547 resource = mlt_properties_get(properties, "mlt_service");
1550 int trackNb = tractor.count();
1551 while (trackNb > 1) {
1552 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1553 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1556 int clipNb = trackPlaylist.count();
1557 insertPos = trackClipStartList.value(trackNb - 1);
1558 if (insertPos != -1) {
1559 insertPos += offset;
1561 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1562 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1563 for (int i = 0; i < clipNb; i++) {
1564 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1565 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1566 kDebug()<<"-------------";
1568 kDebug()<<"END-------------";*/
1571 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1572 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1574 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1575 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1576 int position = trackPlaylist.clip_start(clipIndex);
1577 trackPlaylist.remove_region(position, - diff - 1);
1579 trackPlaylist.consolidate_blanks(0);
1583 // now move transitions
1584 mlt_service serv = m_mltProducer->parent().get_service();
1585 mlt_service nextservice = mlt_service_get_producer(serv);
1586 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1587 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1588 QString resource = mlt_properties_get(properties, "mlt_service");
1590 while (mlt_type == "transition") {
1591 mlt_transition tr = (mlt_transition) nextservice;
1592 int currentIn = (int) mlt_transition_get_in(tr);
1593 int currentOut = (int) mlt_transition_get_out(tr);
1594 int currentTrack = mlt_transition_get_b_track(tr);
1595 insertPos = trackTransitionStartList.value(currentTrack);
1596 if (insertPos != -1) {
1597 insertPos += offset;
1598 if (currentOut > insertPos && resource != "mix") {
1599 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1602 nextservice = mlt_service_producer(nextservice);
1603 if (nextservice == NULL) break;
1604 properties = MLT_SERVICE_PROPERTIES(nextservice);
1605 mlt_type = mlt_properties_get(properties, "mlt_type");
1606 resource = mlt_properties_get(properties, "mlt_service");
1609 mlt_service_unlock(service.get_service());
1611 m_mltConsumer->set("refresh", 1);
1614 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
1617 Mlt::Service service(m_mltProducer->parent().get_service());
1618 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1619 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1620 Mlt::Tractor tractor(service);
1621 Mlt::Producer trackProducer(tractor.track(info.track));
1622 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1623 int startPos = info.startPos.frames(m_fps);
1624 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1625 int clipLength = trackPlaylist.clip_length(clipIndex);
1627 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1628 QString serv = clip.parent().get("mlt_service");
1629 QString id = clip.parent().get("id");
1630 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1631 if (serv == "avformat" && speed != 1.0) {
1632 mlt_service_lock(service.get_service());
1633 QString url = clip.parent().get("resource");
1634 url.append("?" + QString::number(speed));
1635 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1636 if (!slowprod || slowprod->get_producer() == NULL) {
1637 char *tmp = decodedString(url);
1638 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1640 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1641 tmp = decodedString(producerid);
1642 slowprod->set("id", tmp);
1644 m_slowmotionProducers.insert(url, slowprod);
1646 trackPlaylist.replace_with_blank(clipIndex);
1647 trackPlaylist.consolidate_blanks(0);
1648 // Check that the blank space is long enough for our new duration
1649 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1650 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1652 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1653 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1654 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1655 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1656 trackPlaylist.insert_at(startPos, *cut, 1);
1657 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1658 newLength = trackPlaylist.clip_length(clipIndex);
1659 mlt_service_unlock(service.get_service());
1660 } else if (speed == 1.0) {
1661 mlt_service_lock(service.get_service());
1663 trackPlaylist.replace_with_blank(clipIndex);
1664 trackPlaylist.consolidate_blanks(0);
1666 // Check that the blank space is long enough for our new duration
1667 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1668 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1671 GenTime oldDuration = GenTime(clipLength, m_fps);
1672 GenTime newDuration = oldDuration * oldspeed;
1673 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1674 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1675 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1676 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1677 trackPlaylist.insert_at(startPos, *cut, 1);
1678 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1679 newLength = trackPlaylist.clip_length(clipIndex);
1680 mlt_service_unlock(service.get_service());
1682 } else if (serv == "framebuffer") {
1683 mlt_service_lock(service.get_service());
1684 QString url = clip.parent().get("resource");
1685 url = url.section("?", 0, 0);
1686 url.append("?" + QString::number(speed));
1687 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1688 if (!slowprod || slowprod->get_producer() == NULL) {
1689 char *tmp = decodedString(url);
1690 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1692 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1693 tmp = decodedString(producerid);
1694 slowprod->set("id", tmp);
1696 m_slowmotionProducers.insert(url, slowprod);
1698 trackPlaylist.replace_with_blank(clipIndex);
1699 trackPlaylist.consolidate_blanks(0);
1701 GenTime oldDuration = GenTime(clipLength, m_fps);
1702 GenTime newDuration = oldDuration * oldspeed / speed;
1704 // Check that the blank space is long enough for our new duration
1705 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1706 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1709 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1710 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1711 cut = slowprod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1712 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1714 trackPlaylist.insert_at(startPos, *cut, 1);
1715 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1716 newLength = trackPlaylist.clip_length(clipIndex);
1718 mlt_service_unlock(service.get_service());
1720 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1721 m_isBlocked = false;
1725 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1727 Mlt::Service service(m_mltProducer->parent().get_service());
1728 bool success = false;
1729 Mlt::Tractor tractor(service);
1730 Mlt::Producer trackProducer(tractor.track(track));
1731 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1732 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1733 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1735 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1738 Mlt::Service clipService(clip->get_service());
1739 // if (tag.startsWith("ladspa")) tag = "ladspa";
1742 Mlt::Filter *filter = clipService.filter(ct);
1744 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1745 if (clipService.detach(*filter) == 0) success = true;
1746 kDebug() << " / / / DLEETED EFFECT: " << ct;
1748 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1751 filter = clipService.filter(ct);
1753 m_isBlocked = false;
1754 if (doRefresh) refresh();
1759 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
1761 Mlt::Service service(m_mltProducer->parent().get_service());
1763 Mlt::Tractor tractor(service);
1764 Mlt::Producer trackProducer(tractor.track(track));
1765 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1767 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1771 Mlt::Service clipService(clip->get_service());
1774 // temporarily remove all effects after insert point
1775 QList <Mlt::Filter *> filtersList;
1776 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1778 Mlt::Filter *filter = clipService.filter(ct);
1780 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1781 filtersList.append(filter);
1782 clipService.detach(*filter);
1784 filter = clipService.filter(ct);
1788 QString tag = params.paramValue("tag");
1789 kDebug() << " / / INSERTING EFFECT: " << tag;
1790 if (tag.startsWith("ladspa")) tag = "ladspa";
1791 char *filterTag = decodedString(tag);
1792 char *filterId = decodedString(params.paramValue("id"));
1793 QHash<QString, QString>::Iterator it;
1794 QString kfr = params.paramValue("keyframes");
1796 if (!kfr.isEmpty()) {
1797 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1798 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1799 char *starttag = decodedString(params.paramValue("starttag", "start"));
1800 char *endtag = decodedString(params.paramValue("endtag", "end"));
1801 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1802 int duration = clip->get_playtime();
1803 double max = params.paramValue("max").toDouble();
1804 double min = params.paramValue("min").toDouble();
1805 double factor = params.paramValue("factor", "1").toDouble();
1806 params.removeParam("starttag");
1807 params.removeParam("endtag");
1808 params.removeParam("keyframes");
1809 params.removeParam("min");
1810 params.removeParam("max");
1811 params.removeParam("factor");
1813 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1814 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1815 if (filter && filter->is_valid()) {
1816 filter->set("kdenlive_id", filterId);
1817 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1818 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1819 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1820 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1821 if (x2 == -1) x2 = duration;
1823 for (int j = 0; j < params.count(); j++) {
1824 char *name = decodedString(params.at(j).name());
1825 char *value = decodedString(params.at(j).value());
1826 filter->set(name, value);
1831 filter->set("in", x1);
1832 filter->set("out", x2);
1833 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1834 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1835 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1836 clipService.attach(*filter);
1843 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1844 if (filter && filter->is_valid())
1845 filter->set("kdenlive_id", filterId);
1847 kDebug() << "filter is NULL";
1848 m_isBlocked = false;
1852 params.removeParam("kdenlive_id");
1854 for (int j = 0; j < params.count(); j++) {
1855 char *name = decodedString(params.at(j).name());
1856 char *value = decodedString(params.at(j).value());
1857 filter->set(name, value);
1863 QString effectArgs = params.paramValue("id").section('_', 1);
1865 params.removeParam("id");
1866 params.removeParam("kdenlive_ix");
1867 params.removeParam("tag");
1868 params.removeParam("disabled");
1870 for (int j = 0; j < params.count(); j++) {
1871 effectArgs.append(' ' + params.at(j).value());
1873 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1874 char *value = decodedString(effectArgs.simplified());
1875 filter->set("effect", value);
1880 // attach filter to the clip
1881 clipService.attach(*filter);
1886 // re-add following filters
1887 for (int i = 0; i < filtersList.count(); i++) {
1888 clipService.attach(*(filtersList.at(i)));
1891 m_isBlocked = false;
1892 if (doRefresh) refresh();
1896 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
1897 QString index = params.paramValue("kdenlive_ix");
1898 QString tag = params.paramValue("tag");
1900 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1901 // This is a keyframe effect, to edit it, we remove it and re-add it.
1902 mltRemoveEffect(track, position, index);
1903 bool success = mltAddEffect(track, position, params);
1908 Mlt::Service service(m_mltProducer->parent().get_service());
1910 Mlt::Tractor tractor(service);
1911 Mlt::Producer trackProducer(tractor.track(track));
1912 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1913 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1914 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1916 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1919 Mlt::Service clipService(clip->get_service());
1922 Mlt::Filter *filter = clipService.filter(ct);
1924 if (filter->get("kdenlive_ix") == index) {
1928 filter = clipService.filter(ct);
1932 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1933 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1935 filter = clipService.filter(ct);
1936 QList <Mlt::Filter *> filtersList;
1938 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1939 filtersList.append(filter);
1940 clipService.detach(*filter);
1942 filter = clipService.filter(ct);
1944 bool success = mltAddEffect(track, position, params);
1946 for (int i = 0; i < filtersList.count(); i++) {
1947 clipService.attach(*(filtersList.at(i)));
1950 m_isBlocked = false;
1954 for (int j = 0; j < params.count(); j++) {
1955 char *name = decodedString(params.at(j).name());
1956 char *value = decodedString(params.at(j).value());
1957 filter->set(name, value);
1962 m_isBlocked = false;
1967 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1969 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1970 Mlt::Service service(m_mltProducer->parent().get_service());
1972 Mlt::Tractor tractor(service);
1973 Mlt::Producer trackProducer(tractor.track(track));
1974 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1975 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1976 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1978 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1981 Mlt::Service clipService(clip->get_service());
1984 QList <Mlt::Filter *> filtersList;
1985 Mlt::Filter *filter = clipService.filter(ct);
1987 if (newPos > oldPos) {
1989 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1990 filter->set("kdenlive_ix", newPos);
1991 filtersList.append(filter);
1992 clipService.detach(*filter);
1993 filter = clipService.filter(ct);
1994 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1995 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1997 filter = clipService.filter(ct);
2001 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2002 filtersList.append(filter);
2003 clipService.detach(*filter);
2005 filter = clipService.filter(ct);
2009 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2010 filter->set("kdenlive_ix", newPos);
2011 filtersList.append(filter);
2012 clipService.detach(*filter);
2014 filter = clipService.filter(ct);
2018 filter = clipService.filter(ct);
2020 int pos = QString(filter->get("kdenlive_ix")).toInt();
2021 if (pos >= newPos) {
2022 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2023 filtersList.append(filter);
2024 clipService.detach(*filter);
2026 filter = clipService.filter(ct);
2030 for (int i = 0; i < filtersList.count(); i++) {
2031 clipService.attach(*(filtersList.at(i)));
2034 m_isBlocked = false;
2038 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
2041 Mlt::Service service(m_mltProducer->parent().get_service());
2043 Mlt::Tractor tractor(service);
2044 Mlt::Producer trackProducer(tractor.track(info.track));
2045 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2047 /* // Display playlist info
2048 kDebug()<<"//////////// BEFORE RESIZE";
2049 for (int i = 0; i < trackPlaylist.count(); i++) {
2050 int blankStart = trackPlaylist.clip_start(i);
2051 int blankDuration = trackPlaylist.clip_length(i) - 1;
2053 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2054 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
2057 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2058 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2059 m_isBlocked = false;
2062 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2063 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2064 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2065 int previousStart = clip->get_in();
2066 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2067 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2068 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2069 //trackPlaylist.consolidate_blanks(0);
2070 // skip to next clip
2072 int diff = newDuration - previousDuration;
2073 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
2075 // clip was made longer, trim next blank if there is one.
2076 if (trackPlaylist.is_blank(clipIndex)) {
2077 int blankStart = trackPlaylist.clip_start(clipIndex);
2078 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2079 if (diff - blankDuration == 1) {
2080 trackPlaylist.remove(clipIndex);
2081 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
2083 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2085 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2087 trackPlaylist.consolidate_blanks(0);
2090 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2091 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2092 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2093 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2094 ItemInfo transpinfo;
2095 transpinfo.startPos = info.startPos;
2096 transpinfo.endPos = info.startPos + clipDuration;
2097 transpinfo.track = info.track;
2098 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2100 m_isBlocked = false;
2101 m_mltConsumer->set("refresh", 1);
2105 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
2106 Mlt::Service service(m_mltProducer->parent().get_service());
2107 Mlt::Tractor tractor(service);
2108 Mlt::Producer trackProducer(tractor.track(track));
2111 if (blind) trackProducer.set("hide", 3);
2112 else trackProducer.set("hide", 2);
2114 trackProducer.set("hide", 1);
2116 trackProducer.set("hide", 0);
2118 tractor.multitrack()->refresh();
2123 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
2124 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2125 Mlt::Service service(m_mltProducer->parent().get_service());
2126 int moveFrame = (int) diff.frames(m_fps);
2127 Mlt::Tractor tractor(service);
2128 Mlt::Producer trackProducer(tractor.track(info.track));
2129 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2130 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2131 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2134 mlt_service_lock(service.get_service());
2135 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2136 /*int previousStart = trackPlaylist.clip_start(clipIndex);
2137 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
2138 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
2139 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2141 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2142 mlt_service_unlock(service.get_service());
2145 //m_mltConsumer->set("refresh", 0);
2146 int previousStart = clip->get_in();
2147 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2149 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2150 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2151 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2153 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2154 int blankIndex = clipIndex - 1;
2155 int blankLength = trackPlaylist.clip_length(blankIndex);
2156 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2157 if (! trackPlaylist.is_blank(blankIndex)) {
2158 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2160 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2161 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2163 trackPlaylist.consolidate_blanks(0);
2164 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2165 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2166 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2167 ItemInfo transpinfo;
2168 transpinfo.startPos = info.startPos + diff;
2169 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2170 transpinfo.track = info.track;
2171 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2173 m_isBlocked = false;
2174 //m_mltConsumer->set("refresh", 1);
2175 mlt_service_unlock(service.get_service());
2176 m_mltConsumer->set("refresh", 1);
2180 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
2181 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2185 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
2186 kDebug() << "NEW PROD ID: " << prod->get("id");
2187 m_mltConsumer->set("refresh", 0);
2188 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2189 mlt_service_lock(m_mltConsumer->get_service());
2190 Mlt::Service service(m_mltProducer->parent().get_service());
2191 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2193 Mlt::Tractor tractor(service);
2194 Mlt::Producer trackProducer(tractor.track(track));
2195 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2196 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2197 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2198 if (clipProducer.is_blank()) {
2199 kDebug() << "// ERROR UPDATING CLIP PROD";
2200 mlt_service_unlock(m_mltConsumer->get_service());
2201 m_isBlocked = false;
2204 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2206 // move all effects to the correct producer
2207 Mlt::Service clipService(clipProducer.get_service());
2208 Mlt::Service newClipService(clip->get_service());
2211 Mlt::Filter *filter = clipService.filter(ct);
2213 if (filter->get("kdenlive_ix") != 0) {
2214 clipService.detach(*filter);
2215 newClipService.attach(*filter);
2217 filter = clipService.filter(ct);
2220 trackPlaylist.insert_at(pos, clip, 1);
2221 mlt_service_unlock(m_mltConsumer->get_service());
2222 m_isBlocked = false;
2225 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
2228 m_mltConsumer->set("refresh", 0);
2229 mlt_service_lock(m_mltConsumer->get_service());
2230 Mlt::Service service(m_mltProducer->parent().get_service());
2231 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2233 Mlt::Tractor tractor(service);
2234 Mlt::Producer trackProducer(tractor.track(startTrack));
2235 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2236 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2237 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2238 bool checkLength = false;
2239 if (endTrack == startTrack) {
2240 //mlt_service_lock(service.get_service());
2241 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2242 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2243 // error, destination is not empty
2244 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2245 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2246 mlt_service_unlock(m_mltConsumer->get_service());
2247 m_isBlocked = false;
2250 trackPlaylist.consolidate_blanks(0);
2251 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2252 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2253 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2255 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2257 //mlt_service_unlock(service.get_service());
2259 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2260 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2261 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2262 // error, destination is not empty
2263 mlt_service_unlock(m_mltConsumer->get_service());
2264 m_isBlocked = false;
2267 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2268 if (clipProducer.is_blank()) {
2269 // error, destination is not empty
2270 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2271 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2272 mlt_service_unlock(m_mltConsumer->get_service());
2273 m_isBlocked = false;
2276 trackPlaylist.consolidate_blanks(0);
2277 destTrackPlaylist.consolidate_blanks(1);
2278 Mlt::Producer *clip;
2279 // check if we are moving a slowmotion producer
2280 QString serv = clipProducer.parent().get("mlt_service");
2281 if (serv == "framebuffer") {
2282 clip = &clipProducer;
2283 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2285 // move all effects to the correct producer
2286 Mlt::Service clipService(clipProducer.get_service());
2287 Mlt::Service newClipService(clip->get_service());
2290 Mlt::Filter *filter = clipService.filter(ct);
2292 if (filter->get("kdenlive_ix") != 0) {
2293 clipService.detach(*filter);
2294 newClipService.attach(*filter);
2296 filter = clipService.filter(ct);
2299 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2300 destTrackPlaylist.consolidate_blanks(0);
2301 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2302 kDebug() << "//////// moving clip transparency";
2303 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2305 if (clipIndex > trackPlaylist.count()) checkLength = true;
2306 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2310 if (checkLength) mltCheckLength();
2311 mlt_service_unlock(m_mltConsumer->get_service());
2312 m_isBlocked = false;
2313 m_mltConsumer->set("refresh", 1);
2317 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
2318 int new_in = (int)newIn.frames(m_fps);
2319 int new_out = (int)newOut.frames(m_fps) - 1;
2320 if (new_in >= new_out) return false;
2322 Mlt::Service service(m_mltProducer->parent().get_service());
2323 Mlt::Tractor tractor(service);
2324 Mlt::Field *field = tractor.field();
2326 mlt_service_lock(service.get_service());
2327 m_mltConsumer->set("refresh", 0);
2330 mlt_service serv = m_mltProducer->parent().get_service();
2331 mlt_service nextservice = mlt_service_get_producer(serv);
2332 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2333 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2334 QString resource = mlt_properties_get(properties, "mlt_service");
2335 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2337 while (mlt_type == "transition") {
2338 mlt_transition tr = (mlt_transition) nextservice;
2339 int currentTrack = mlt_transition_get_b_track(tr);
2340 int currentIn = (int) mlt_transition_get_in(tr);
2341 int currentOut = (int) mlt_transition_get_out(tr);
2343 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2344 mlt_transition_set_in_and_out(tr, new_in, new_out);
2345 if (newTrack - startTrack != 0) {
2346 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
2348 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2349 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2350 mlt_properties_set_int(properties, "b_track", newTrack);
2351 //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);
2355 nextservice = mlt_service_producer(nextservice);
2356 if (nextservice == NULL) break;
2357 properties = MLT_SERVICE_PROPERTIES(nextservice);
2358 mlt_type = mlt_properties_get(properties, "mlt_type");
2359 resource = mlt_properties_get(properties, "mlt_service");
2361 m_isBlocked = false;
2362 mlt_service_unlock(service.get_service());
2363 m_mltConsumer->set("refresh", 1);
2367 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2368 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2369 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2371 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2372 mltAddTransition(tag, a_track, b_track, in, out, xml);
2374 //mltSavePlaylist();
2377 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2379 Mlt::Service service(m_mltProducer->parent().get_service());
2380 Mlt::Tractor tractor(service);
2381 Mlt::Field *field = tractor.field();
2383 //m_mltConsumer->set("refresh", 0);
2384 mlt_service serv = m_mltProducer->parent().get_service();
2386 mlt_service nextservice = mlt_service_get_producer(serv);
2387 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2388 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2389 QString resource = mlt_properties_get(properties, "mlt_service");
2390 int in_pos = (int) in.frames(m_fps);
2391 int out_pos = (int) out.frames(m_fps) - 1;
2393 while (mlt_type == "transition") {
2394 mlt_transition tr = (mlt_transition) nextservice;
2395 int currentTrack = mlt_transition_get_b_track(tr);
2396 int currentBTrack = mlt_transition_get_a_track(tr);
2397 int currentIn = (int) mlt_transition_get_in(tr);
2398 int currentOut = (int) mlt_transition_get_out(tr);
2400 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2402 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2403 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2404 QMap<QString, QString>::Iterator it;
2406 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2407 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2408 if (currentBTrack != a_track) {
2409 mlt_properties_set_int(properties, "a_track", a_track);
2411 for (it = map.begin(); it != map.end(); ++it) {
2413 char *name = decodedString(key);
2414 char *value = decodedString(it.value());
2415 mlt_properties_set(transproperties, name, value);
2416 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2417 //filter->set("kdenlive_id", id);
2423 nextservice = mlt_service_producer(nextservice);
2424 if (nextservice == NULL) break;
2425 properties = MLT_SERVICE_PROPERTIES(nextservice);
2426 mlt_type = mlt_properties_get(properties, "mlt_type");
2427 resource = mlt_properties_get(properties, "mlt_service");
2429 m_isBlocked = false;
2430 m_mltConsumer->set("refresh", 1);
2433 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2434 Mlt::Service service(m_mltProducer->parent().get_service());
2435 Mlt::Tractor tractor(service);
2436 Mlt::Field *field = tractor.field();
2438 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2439 mlt_service serv = m_mltProducer->parent().get_service();
2441 mlt_service nextservice = mlt_service_get_producer(serv);
2442 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2443 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2444 QString resource = mlt_properties_get(properties, "mlt_service");
2446 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2448 while (mlt_type == "transition") {
2449 mlt_transition tr = (mlt_transition) nextservice;
2450 int currentTrack = mlt_transition_get_b_track(tr);
2451 int currentIn = (int) mlt_transition_get_in(tr);
2452 int currentOut = (int) mlt_transition_get_out(tr);
2453 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2455 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2456 mlt_field_disconnect_service(field->get_field(), nextservice);
2459 nextservice = mlt_service_producer(nextservice);
2460 if (nextservice == NULL) break;
2461 properties = MLT_SERVICE_PROPERTIES(nextservice);
2462 mlt_type = mlt_properties_get(properties, "mlt_type");
2463 resource = mlt_properties_get(properties, "mlt_service");
2465 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2468 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2469 QDomNodeList attribs = xml.elementsByTagName("parameter");
2470 QMap<QString, QString> map;
2471 for (int i = 0;i < attribs.count();i++) {
2472 QDomElement e = attribs.item(i).toElement();
2473 QString name = e.attribute("name");
2474 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2475 map[name] = e.attribute("default");
2476 if (!e.attribute("value").isEmpty()) {
2477 map[name] = e.attribute("value");
2479 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2480 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2481 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2484 if (e.attribute("namedesc").contains(";")) {
2485 QString format = e.attribute("format");
2486 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2487 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2489 QTextStream txtNeu(&neu);
2490 if (values.size() > 0)
2491 txtNeu << (int)values[0].toDouble();
2493 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2494 txtNeu << separators[i];
2495 txtNeu << (int)(values[i+1].toDouble());
2497 if (i < separators.size())
2498 txtNeu << separators[i];
2499 map[e.attribute("name")] = neu;
2506 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2507 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2508 Mlt::Service service(m_mltProducer->parent().get_service());
2509 Mlt::Tractor tractor(service);
2510 Mlt::Field *field = tractor.field();
2512 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2513 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2514 transition->set("transparency", id);
2515 transition->set("fill", 1);
2516 transition->set("internal_added", 237);
2517 field->plant_transition(*transition, transitiontrack, info.track);
2521 void Render::mltDeleteTransparency(int pos, int track, int id) {
2522 Mlt::Service service(m_mltProducer->parent().get_service());
2523 Mlt::Tractor tractor(service);
2524 Mlt::Field *field = tractor.field();
2526 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2527 mlt_service serv = m_mltProducer->parent().get_service();
2529 mlt_service nextservice = mlt_service_get_producer(serv);
2530 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2531 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2532 QString resource = mlt_properties_get(properties, "mlt_service");
2534 while (mlt_type == "transition") {
2535 mlt_transition tr = (mlt_transition) nextservice;
2536 int currentTrack = mlt_transition_get_b_track(tr);
2537 int currentIn = (int) mlt_transition_get_in(tr);
2538 int currentOut = (int) mlt_transition_get_out(tr);
2539 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2540 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2542 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2543 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2544 mlt_field_disconnect_service(field->get_field(), nextservice);
2547 nextservice = mlt_service_producer(nextservice);
2548 if (nextservice == NULL) break;
2549 properties = MLT_SERVICE_PROPERTIES(nextservice);
2550 mlt_type = mlt_properties_get(properties, "mlt_type");
2551 resource = mlt_properties_get(properties, "mlt_service");
2553 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2556 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2557 Mlt::Service service(m_mltProducer->parent().get_service());
2558 Mlt::Tractor tractor(service);
2559 Mlt::Field *field = tractor.field();
2561 mlt_service_lock(service.get_service());
2562 m_mltConsumer->set("refresh", 0);
2565 mlt_service serv = m_mltProducer->parent().get_service();
2566 mlt_service nextservice = mlt_service_get_producer(serv);
2567 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2568 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2569 QString resource = mlt_properties_get(properties, "mlt_service");
2570 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2571 while (mlt_type == "transition") {
2572 mlt_transition tr = (mlt_transition) nextservice;
2573 int currentTrack = mlt_transition_get_b_track(tr);
2574 int currentIn = (int) mlt_transition_get_in(tr);
2575 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2576 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2577 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2578 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2579 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2580 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2583 nextservice = mlt_service_producer(nextservice);
2584 if (nextservice == NULL) break;
2585 properties = MLT_SERVICE_PROPERTIES(nextservice);
2586 mlt_type = mlt_properties_get(properties, "mlt_type");
2587 resource = mlt_properties_get(properties, "mlt_service");
2589 m_isBlocked = false;
2590 mlt_service_unlock(service.get_service());
2591 m_mltConsumer->set("refresh", 1);
2595 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2596 Mlt::Service service(m_mltProducer->parent().get_service());
2597 Mlt::Tractor tractor(service);
2598 Mlt::Field *field = tractor.field();
2600 mlt_service_lock(service.get_service());
2601 m_mltConsumer->set("refresh", 0);
2604 mlt_service serv = m_mltProducer->parent().get_service();
2605 mlt_service nextservice = mlt_service_get_producer(serv);
2606 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2607 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2608 QString resource = mlt_properties_get(properties, "mlt_service");
2610 while (mlt_type == "transition") {
2611 mlt_transition tr = (mlt_transition) nextservice;
2612 int currentTrack = mlt_transition_get_b_track(tr);
2613 int currentaTrack = mlt_transition_get_a_track(tr);
2614 int currentIn = (int) mlt_transition_get_in(tr);
2615 int currentOut = (int) mlt_transition_get_out(tr);
2616 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2617 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2618 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2619 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2620 kDebug() << "//////MOVING";
2621 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2622 if (endTrack != startTrack) {
2623 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2624 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2625 mlt_properties_set_int(properties, "b_track", endTrack);
2629 nextservice = mlt_service_producer(nextservice);
2630 if (nextservice == NULL) break;
2631 properties = MLT_SERVICE_PROPERTIES(nextservice);
2632 mlt_type = mlt_properties_get(properties, "mlt_type");
2633 resource = mlt_properties_get(properties, "mlt_service");
2635 m_isBlocked = false;
2636 mlt_service_unlock(service.get_service());
2637 m_mltConsumer->set("refresh", 1);
2641 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2642 if (in >= out) return false;
2643 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2644 Mlt::Service service(m_mltProducer->parent().get_service());
2646 Mlt::Tractor tractor(service);
2647 Mlt::Field *field = tractor.field();
2649 char *transId = decodedString(tag);
2650 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2651 if (out != GenTime())
2652 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2653 QMap<QString, QString>::Iterator it;
2655 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2656 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2658 for (it = args.begin(); it != args.end(); ++it) {
2660 char *name = decodedString(key);
2661 char *value = decodedString(it.value());
2662 transition->set(name, value);
2663 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2664 //filter->set("kdenlive_id", id);
2668 // attach filter to the clip
2669 field->plant_transition(*transition, a_track, b_track);
2675 void Render::mltSavePlaylist() {
2676 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2677 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2678 fileConsumer.set("resource", "/tmp/playlist.westley");
2680 Mlt::Service service(m_mltProducer->get_service());
2682 fileConsumer.connect(service);
2683 fileConsumer.start();
2686 QList <Mlt::Producer *> Render::producersList() {
2687 QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
2689 Mlt::Service service(m_mltProducer->parent().get_service());
2690 Mlt::Tractor tractor(service);
2692 int trackNb = tractor.count();
2693 for (int t = 1; t < trackNb; t++) {
2694 Mlt::Producer trackProducer(tractor.track(t));
2695 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2696 int clipNb = trackPlaylist.count();
2697 kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2698 for (int i = 0; i < clipNb; i++) {
2699 Mlt::Producer *prod = trackPlaylist.get_clip(i);
2700 Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
2701 //kDebug()<<"PROD: "<<nprod->get("producer")<<", ID: "<<nprod->get("id")<<nprod->get("resource");
2702 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2703 ids.append(nprod->get("id"));
2704 prods.append(nprod);
2711 void Render::fillSlowMotionProducers() {
2712 Mlt::Service service(m_mltProducer->parent().get_service());
2713 Mlt::Tractor tractor(service);
2715 int trackNb = tractor.count();
2716 for (int t = 1; t < trackNb; t++) {
2717 Mlt::Producer trackProducer(tractor.track(t));
2718 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2719 int clipNb = trackPlaylist.count();
2720 for (int i = 0; i < clipNb; i++) {
2721 Mlt::Producer *prod = trackPlaylist.get_clip(i);
2722 Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
2723 if (nprod && !nprod->is_blank()) {
2724 QString id = nprod->get("id");
2725 if (id.startsWith("slowmotion:")) {
2726 // this is a slowmotion producer, add it to the list
2727 QString url = nprod->get("resource");
2728 if (!m_slowmotionProducers.contains(url)) {
2729 m_slowmotionProducers.insert(url, nprod);
2737 void Render::mltInsertTrack(int ix, bool videoTrack) {
2741 m_mltConsumer->set("refresh", 0);
2742 mlt_service_lock(m_mltConsumer->get_service());
2743 Mlt::Service service(m_mltProducer->parent().get_service());
2744 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2746 Mlt::Tractor tractor(service);
2748 Mlt::Playlist playlist;// = new Mlt::Playlist();
2749 int ct = tractor.count();
2750 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2753 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2754 tractor.set_track(playlist, pos);
2755 Mlt::Producer newProd(tractor.track(pos));
2756 if (!videoTrack) newProd.set("hide", 1);
2758 for (; pos <= ct; pos++) {
2759 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2760 tractor.set_track(*prodToMove, pos);
2761 prodToMove = prodToMove2;
2764 tractor.set_track(playlist, ix);
2765 Mlt::Producer newProd(tractor.track(ix));
2766 if (!videoTrack) newProd.set("hide", 1);
2770 mlt_service serv = m_mltProducer->parent().get_service();
2771 mlt_service nextservice = mlt_service_get_producer(serv);
2772 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2773 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2774 QString resource = mlt_properties_get(properties, "mlt_service");
2776 while (mlt_type == "transition") {
2777 if (resource != "mix") {
2778 mlt_transition tr = (mlt_transition) nextservice;
2779 int currentTrack = mlt_transition_get_b_track(tr);
2780 int currentaTrack = mlt_transition_get_a_track(tr);
2781 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2783 if (currentTrack >= ix) {
2784 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2785 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2788 nextservice = mlt_service_producer(nextservice);
2789 if (nextservice == NULL) break;
2790 properties = MLT_SERVICE_PROPERTIES(nextservice);
2791 mlt_type = mlt_properties_get(properties, "mlt_type");
2792 resource = mlt_properties_get(properties, "mlt_service");
2795 // Add audio mix transition to last track
2796 Mlt::Field *field = tractor.field();
2797 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2798 //transition->set("mlt_service", "mix");
2799 transition->set("a_track", 1);
2800 transition->set("b_track", ct);
2801 transition->set("always_active", 1);
2802 transition->set("internal_added", 237);
2803 transition->set("combine", 1);
2804 field->plant_transition(*transition, 1, ct);
2806 mlt_service_unlock(m_mltConsumer->get_service());
2807 m_isBlocked = false;
2808 blockSignals(false);
2812 void Render::mltDeleteTrack(int ix) {
2814 doc.setContent(sceneList(), false);
2815 int tracksCount = doc.elementsByTagName("track").count() - 1;
2816 QDomNode track = doc.elementsByTagName("track").at(ix);
2817 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2818 QDomNodeList transitions = doc.elementsByTagName("transition");
2819 for (int i = 0; i < transitions.count(); i++) {
2820 QDomElement e = transitions.at(i).toElement();
2821 QDomNodeList props = e.elementsByTagName("property");
2822 QMap <QString, QString> mappedProps;
2823 for (int j = 0; j < props.count(); j++) {
2824 QDomElement f = props.at(j).toElement();
2825 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2827 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2828 tractor.removeChild(transitions.at(i));
2829 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2830 // Transition needs to be moved
2831 int a_track = mappedProps.value("a_track").toInt();
2832 int b_track = mappedProps.value("b_track").toInt();
2833 if (a_track > 0) a_track --;
2834 if (b_track > 0) b_track --;
2835 for (int j = 0; j < props.count(); j++) {
2836 QDomElement f = props.at(j).toElement();
2837 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2838 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2843 tractor.removeChild(track);
2844 setSceneList(doc.toString(), m_framePosition);
2850 m_mltConsumer->set("refresh", 0);
2851 mlt_service_lock(m_mltConsumer->get_service());
2852 Mlt::Service service(m_mltProducer->parent().get_service());
2853 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2855 /*Mlt::Tractor tractor(service);
2858 Mlt::Multitrack *multi = tractor.multitrack();
2861 int ct = tractor.count();
2862 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
2864 for (; pos < ct ; pos++) {
2865 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
2866 //mlt_service_close(lastTrack->get_service());
2868 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
2869 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
2870 mlt_service_close(prodToMove->get_service());
2871 mlt_service_close(prodToClose->get_service());
2872 tractor.set_track(*prodToMove, pos);
2876 /*mlt_service serv = m_mltProducer->parent().get_service();
2877 mlt_service nextservice = mlt_service_get_producer(serv);
2878 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2879 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2880 QString resource = mlt_properties_get(properties, "mlt_service");
2882 while (mlt_type == "transition") {
2883 if (resource != "mix") {
2884 mlt_transition tr = (mlt_transition) nextservice;
2885 int currentTrack = mlt_transition_get_b_track(tr);
2886 int currentaTrack = mlt_transition_get_a_track(tr);
2887 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2889 if (currentTrack >= ix) {
2890 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2891 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2894 nextservice = mlt_service_producer(nextservice);
2895 if (nextservice == NULL) break;
2896 properties = MLT_SERVICE_PROPERTIES(nextservice);
2897 mlt_type = mlt_properties_get(properties, "mlt_type");
2898 resource = mlt_properties_get(properties, "mlt_service");
2901 // Add audio mix transition to last track
2902 Mlt::Field *field = tractor.field();
2903 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2904 //transition->set("mlt_service", "mix");
2905 transition->set("a_track", 1);
2906 transition->set("b_track", ct);
2907 transition->set("always_active", 1);
2908 transition->set("internal_added", 237);
2909 transition->set("combine", 1);
2910 field->plant_transition(*transition, 1, ct);
2913 mlt_service_unlock(m_mltConsumer->get_service());
2914 m_isBlocked = false;
2915 blockSignals(false);
2919 void Render::updatePreviewSettings() {
2920 kDebug() << "////// RESTARTING CONSUMER";
2921 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
2922 m_mltConsumer->purge();
2923 QString scene = sceneList();
2925 if (m_mltProducer) {
2926 pos = m_mltProducer->position();
2927 delete m_mltProducer;
2929 m_mltProducer = NULL;
2930 setSceneList(scene, pos);
2933 #include "renderer.moc"