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 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
31 #include <mlt++/Mlt.h>
34 #include <KStandardDirs>
35 #include <KMessageBox>
37 #include <KTemporaryFile>
41 #include <QApplication>
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 m_mltProducer = m_blackClip->cut(0, 50);
70 m_mltConsumer->connect(*m_mltProducer);
71 m_mltProducer->set_speed(0.0);
79 void Render::closeMlt() {
86 if (m_blackClip) delete m_blackClip;
91 void Render::buildConsumer() {
93 m_activeProfile = KdenliveSettings::current_profile();
94 tmp = decodedString(m_activeProfile);
95 setenv("MLT_PROFILE", tmp, 1);
96 if (m_blackClip) delete m_blackClip;
99 m_mltProfile = new Mlt::Profile(tmp);
102 QString videoDriver = KdenliveSettings::videodrivername();
103 if (!videoDriver.isEmpty()) {
104 if (videoDriver == "x11_noaccel") {
105 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
108 unsetenv("SDL_VIDEO_YUV_HWACCEL");
111 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
113 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
114 m_mltConsumer->set("resize", 1);
115 m_mltConsumer->set("window_id", m_winid);
116 m_mltConsumer->set("terminate_on_pause", 1);
117 m_mltConsumer->set("window_background", decodedString(KdenliveSettings::window_background().name()));
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);
147 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
148 m_blackClip->set("id", "black");
152 int Render::resetProfile() {
153 if (!m_mltConsumer) return 0;
154 if (m_activeProfile == KdenliveSettings::current_profile()) {
155 kDebug() << "reset to same profile, nothing to do";
158 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
159 if (m_isSplitView) slotSplitView(false);
160 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
161 m_mltConsumer->purge();
162 delete m_mltConsumer;
163 m_mltConsumer = NULL;
164 QString scene = sceneList();
167 pos = m_mltProducer->position();
168 delete m_mltProducer;
170 m_mltProducer = NULL;
172 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
173 /*if (m_mltProfile) delete m_mltProfile;
174 m_mltProfile = NULL;*/
178 //kDebug() << "//RESET WITHSCENE: " << scene;
179 setSceneList(scene, pos);
181 /*char *tmp = decodedString(scene);
182 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
184 m_mltProducer = producer;
185 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
186 m_mltProducer->optimise();
187 m_mltProducer->set_speed(0);
190 //delete m_mltProfile;
191 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
192 //mlt_profile prof = m_mltProfile->get_profile();
193 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
194 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
195 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
196 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
198 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
203 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
204 void Render::seek(GenTime time) {
208 m_mltProducer->seek((int)(time.frames(m_fps)));
213 char *Render::decodedString(QString str) {
214 /*QCString fn = QFile::encodeName(str);
215 char *t = new char[fn.length() + 1];
216 strcpy(t, (const char *)fn);*/
218 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
222 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
223 QPixmap pix(width, height);
225 mlt_image_format format = mlt_image_rgb24a;
226 uint8_t *thumb = frame->get_image(format, width, height);
227 QImage image(thumb, width, height, QImage::Format_ARGB32);
229 if (!image.isNull()) {
230 pix = pix.fromImage(image);
232 QPainter painter(&pix);
233 painter.drawRect(0, 0, width - 1, height - 1);
235 } else pix.fill(Qt::black);
239 const int Render::renderWidth() const {
240 return (int)(m_mltProfile->height() * m_mltProfile->dar());
243 const int Render::renderHeight() const {
244 return m_mltProfile->height();
247 QPixmap Render::extractFrame(int frame_position, int width, int height) {
249 width = renderWidth();
250 height = renderHeight();
252 QPixmap pix(width, height);
253 if (!m_mltProducer) {
257 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
260 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
263 if (url.fileName().startsWith(".all.")) { // check for slideshow
264 QString fileType = url.fileName().right(3);
266 QStringList::Iterator it;
268 QDir dir(url.directory());
270 filter << "*." + fileType;
271 filter << "*." + fileType.toUpper();
272 more = dir.entryList(filter, QDir::Files);
273 im.load(url.directory() + '/' + more.at(0));
274 } else im.load(url.path());
275 //pixmap = im.scaled(width, height);
280 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
281 QPixmap pix(width, height);
282 char *tmp = decodedString(file);
283 Mlt::Profile *prof = new Mlt::Profile(profile);
284 Mlt::Producer m_producer(*prof, tmp);
286 if (m_producer.is_blank()) {
291 Mlt::Filter m_convert(*prof, "avcolour_space");
292 m_convert.set("forced", mlt_image_rgb24a);
293 m_producer.attach(m_convert);
294 m_producer.seek(frame_position);
295 Mlt::Frame * frame = m_producer.get_frame();
297 pix = frameThumbnail(frame, width, height, true);
300 if (prof) delete prof;
305 void Render::getImage(KUrl url, int frame_position, QPoint size)
307 char *tmp = decodedString(url.path());
308 Mlt::Producer m_producer(tmp);
310 if (m_producer.is_blank()) {
313 Mlt::Filter m_convert("avcolour_space");
314 m_convert.set("forced", mlt_image_rgb24a);
315 m_producer.attach(m_convert);
316 m_producer.seek(frame_position);
318 Mlt::Frame * frame = m_producer.get_frame();
321 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
323 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
327 /* Create thumbnail for color */
328 /*void Render::getImage(int id, QString color, QPoint size)
330 QPixmap pixmap(size.x() - 2, size.y() - 2);
331 color = color.replace(0, 2, "#");
332 color = color.left(7);
333 pixmap.fill(QColor(color));
334 QPixmap result(size.x(), size.y());
335 result.fill(Qt::black);
336 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
337 emit replyGetImage(id, result, size.x(), size.y());
341 /* Create thumbnail for image */
342 /*void Render::getImage(KUrl url, QPoint size)
346 if (url.fileName().startsWith(".all.")) { // check for slideshow
347 QString fileType = url.fileName().right(3);
349 QStringList::Iterator it;
351 QDir dir( url.directory() );
352 more = dir.entryList( QDir::Files );
353 for ( it = more.begin() ; it != more.end() ; ++it ) {
354 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
355 if (!im.load(url.directory() + '/' + *it))
356 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
361 else im.load(url.path());
363 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
364 QPixmap result(size.x(), size.y());
365 result.fill(Qt::black);
366 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
367 emit replyGetImage(url, 1, result, size.x(), size.y());
371 double Render::consumerRatio() const {
372 if (!m_mltConsumer) return 1.0;
373 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
377 int Render::getLength() {
380 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
381 return mlt_producer_get_playtime(m_mltProducer->get_producer());
386 bool Render::isValid(KUrl url) {
387 char *tmp = decodedString(url.path());
388 Mlt::Producer producer(*m_mltProfile, tmp);
390 if (producer.is_blank())
396 const double Render::dar() const {
397 return m_mltProfile->dar();
400 void Render::slotSplitView(bool doit) {
401 m_isSplitView = doit;
402 Mlt::Service service(m_mltProducer->parent().get_service());
403 Mlt::Tractor tractor(service);
404 if (service.type() != tractor_type || tractor.count() < 2) return;
405 Mlt::Field *field = tractor.field();
408 for (int i = 1; i < tractor.count() && screen < 4; i++) {
409 Mlt::Producer trackProducer(tractor.track(i));
410 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
411 if (QString(trackProducer.get("hide")).toInt() != 1) {
412 kDebug() << "// ADIDNG TRACK: " << i;
413 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
414 transition->set("mlt_service", "composite");
415 transition->set("a_track", 0);
416 transition->set("b_track", i);
417 transition->set("distort", 1);
418 transition->set("internal_added", "200");
425 tmp = "50%,0:50%x50%";
428 tmp = "0,50%:50%x50%";
432 tmp = "50%,50%:50%x50%";
435 transition->set("geometry", tmp);
436 transition->set("always_active", "1");
437 field->plant_transition(*transition, 0, i);
442 m_mltConsumer->set("refresh", 1);
444 mlt_service serv = m_mltProducer->parent().get_service();
445 mlt_service nextservice = mlt_service_get_producer(serv);
446 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
447 QString mlt_type = mlt_properties_get(properties, "mlt_type");
448 QString resource = mlt_properties_get(properties, "mlt_service");
450 while (mlt_type == "transition") {
451 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
452 if (added == "200") {
453 mlt_field_disconnect_service(field->get_field(), nextservice);
455 nextservice = mlt_service_producer(nextservice);
456 if (nextservice == NULL) break;
457 properties = MLT_SERVICE_PROPERTIES(nextservice);
458 mlt_type = mlt_properties_get(properties, "mlt_type");
459 resource = mlt_properties_get(properties, "mlt_service");
460 m_mltConsumer->set("refresh", 1);
465 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer) {
466 KUrl url = KUrl(xml.attribute("resource", QString()));
467 Mlt::Producer *producer = NULL;
468 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
469 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
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 char *tmp = decodedString(url.path());
488 producer = new Mlt::Producer(*m_mltProfile, tmp);
492 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
493 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
494 emit removeInvalidClip(clipId);
498 if (xml.hasAttribute("force_aspect_ratio")) {
499 double aspect = xml.attribute("force_aspect_ratio").toDouble();
500 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
502 if (xml.hasAttribute("threads")) {
503 int threads = xml.attribute("threads").toInt();
504 if (threads != 1) producer->set("threads", threads);
506 if (xml.hasAttribute("video_index")) {
507 int vindex = xml.attribute("video_index").toInt();
508 if (vindex != 0) producer->set("video_index", vindex);
510 if (xml.hasAttribute("audio_index")) {
511 int aindex = xml.attribute("audio_index").toInt();
512 if (aindex != 0) producer->set("audio_index", aindex);
515 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
517 char *tmp = decodedString(clipId);
518 producer->set("id", tmp);
522 int width = (int)(height * m_mltProfile->dar());
523 QMap < QString, QString > filePropertyMap;
524 QMap < QString, QString > metadataPropertyMap;
526 int frameNumber = xml.attribute("thumbnail", "0").toInt();
527 if (frameNumber != 0) producer->seek(frameNumber);
529 filePropertyMap["duration"] = QString::number(producer->get_playtime());
530 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
532 Mlt::Frame *frame = producer->get_frame();
534 if (xml.attribute("type").toInt() == SLIDESHOW) {
535 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
536 if (xml.attribute("fade") == "1") {
537 // user wants a fade effect to slideshow
538 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
539 if (filter && filter->is_valid()) {
540 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
541 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
542 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
543 char *tmp = decodedString(xml.attribute("luma_file"));
544 filter->set("luma.resource", tmp);
546 if (xml.hasAttribute("softness")) {
547 int soft = xml.attribute("softness").toInt();
548 filter->set("luma.softness", (double) soft / 100.0);
551 Mlt::Service clipService(producer->get_service());
552 clipService.attach(*filter);
558 filePropertyMap["fps"] = producer->get("source_fps");
560 if (frame && frame->is_valid()) {
561 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
562 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
563 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
564 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
566 if (frame->get_int("test_image") == 0) {
567 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
568 filePropertyMap["type"] = "playlist";
569 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
570 } else if (frame->get_int("test_audio") == 0)
571 filePropertyMap["type"] = "av";
573 filePropertyMap["type"] = "video";
575 mlt_image_format format = mlt_image_yuv422;
577 int frame_height = 0;
578 //frame->set("rescale.interp", "hyper");
579 frame->set("normalised_height", height);
580 frame->set("normalised_width", width);
581 QPixmap pix(width, height);
583 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
584 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
585 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
586 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
588 if (!image.isNull()) {
589 pix = QPixmap::fromImage(image.rgbSwapped());
593 mlt_pool_release(new_image);
594 emit replyGetImage(clipId, pix);
596 } else if (frame->get_int("test_audio") == 0) {
597 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
598 emit replyGetImage(clipId, pixmap);
599 filePropertyMap["type"] = "audio";
603 // Retrieve audio / video codec name
607 if (producer->get_int("video_index") > -1) {
608 /*if (context->duration == AV_NOPTS_VALUE) {
609 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
610 emit removeInvalidClip(clipId);
613 // Get the video_index
614 int default_video = producer->get_int("video_index");
616 int default_audio = producer->get_int("audio_index");
619 // Find maximum stream index values
620 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
621 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
622 QString type = producer->get(property);
625 else if (type == "audio")
628 filePropertyMap["default_video"] = QString::number(default_video);
629 filePropertyMap["video_max"] = QString::number(video_max);
630 filePropertyMap["default_audio"] = QString::number(default_audio);
631 filePropertyMap["audio_max"] = QString::number(audio_max);
633 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
634 if (producer->get(property)) {
635 filePropertyMap["videocodec"] = producer->get(property);
637 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
638 if (producer->get(property))
639 filePropertyMap["videocodec"] = producer->get(property);
642 if (KdenliveSettings::dropbframes()) {
643 kDebug() << "// LOOKING FOR H264 on: " << default_video;
644 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
645 kDebug() << "PROP: " << property << " = " << producer->get(property);
646 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
647 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
648 producer->set("skip_loop_filter", "all");
649 producer->set("skip_frame", "bidir");
653 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
654 if (producer->get_int("audio_index") > -1) {
655 // Get the audio_index
656 int index = producer->get_int("audio_index");
658 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
659 if (producer->get(property)) {
660 filePropertyMap["audiocodec"] = producer->get(property);
662 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
663 if (producer->get(property))
664 filePropertyMap["audiocodec"] = producer->get(property);
669 Mlt::Properties metadata;
670 metadata.pass_values(*producer, "meta.attr.");
671 int count = metadata.count();
672 for (int i = 0; i < count; i ++) {
673 QString name = metadata.get_name(i);
674 QString value = QString::fromUtf8(metadata.get(i));
675 if (name.endsWith("markup") && !value.isEmpty())
676 metadataPropertyMap[ name.section('.', 0, -2)] = value;
679 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
680 kDebug() << "REquested fuile info for: " << url.path();
681 if (frame) delete frame;
682 //if (producer) delete producer;
686 /** Create the producer from the Westley QDomDocument */
688 void Render::initSceneList() {
689 kDebug() << "-------- INIT SCENE LIST ------_";
691 QDomElement westley = doc.createElement("westley");
692 doc.appendChild(westley);
693 QDomElement prod = doc.createElement("producer");
694 prod.setAttribute("resource", "colour");
695 prod.setAttribute("colour", "red");
696 prod.setAttribute("id", "black");
697 prod.setAttribute("in", "0");
698 prod.setAttribute("out", "0");
700 QDomElement tractor = doc.createElement("tractor");
701 QDomElement multitrack = doc.createElement("multitrack");
703 QDomElement playlist1 = doc.createElement("playlist");
704 playlist1.appendChild(prod);
705 multitrack.appendChild(playlist1);
706 QDomElement playlist2 = doc.createElement("playlist");
707 multitrack.appendChild(playlist2);
708 QDomElement playlist3 = doc.createElement("playlist");
709 multitrack.appendChild(playlist3);
710 QDomElement playlist4 = doc.createElement("playlist");
711 multitrack.appendChild(playlist4);
712 QDomElement playlist5 = doc.createElement("playlist");
713 multitrack.appendChild(playlist5);
714 tractor.appendChild(multitrack);
715 westley.appendChild(tractor);
716 // kDebug()<<doc.toString();
718 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
719 setSceneList(doc, 0);
725 /** Create the producer from the Westley QDomDocument */
726 void Render::setProducer(Mlt::Producer *producer, int position) {
727 if (m_winid == -1) return;
730 m_mltConsumer->stop();
733 m_mltConsumer->purge();
737 m_mltProducer->set_speed(0);
738 delete m_mltProducer;
739 m_mltProducer = NULL;
743 m_mltProducer = new Mlt::Producer(producer->get_producer());
744 } else m_mltProducer = m_blackClip->cut(0, 50);
745 /*if (KdenliveSettings::dropbframes()) {
746 m_mltProducer->set("skip_loop_filter", "all");
747 m_mltProducer->set("skip_frame", "bidir");
749 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
751 m_fps = m_mltProducer->get_fps();
753 if (position != -1) {
754 m_mltProducer->seek(position);
755 emit rendererPosition(position);
762 /** Create the producer from the Westley QDomDocument */
763 void Render::setSceneList(QDomDocument list, int position) {
764 setSceneList(list.toString(), position);
767 /** Create the producer from the Westley QDomDocument */
768 void Render::setSceneList(QString playlist, int position) {
769 if (m_winid == -1) return;
771 m_slowmotionProducers.clear();
773 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
776 m_mltConsumer->stop();
777 //m_mltConsumer->set("refresh", 0);
784 m_mltProducer->set_speed(0);
785 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
787 delete m_mltProducer;
788 m_mltProducer = NULL;
793 char *tmp = decodedString(playlist);
794 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
797 if (!m_mltProducer || !m_mltProducer->is_valid()) {
798 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
800 m_mltProducer->optimise();
802 /*if (KdenliveSettings::osdtimecode()) {
803 // Attach filter for on screen display of timecode
805 QString attr = "attr_check";
806 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
807 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
808 mlt_producer_attach( m_mltProducer->get_producer(), filter );
809 mlt_filter_close( filter );
811 m_osdInfo = new Mlt::Filter("data_show");
812 tmp = decodedString(m_osdProfile);
813 m_osdInfo->set("resource", tmp);
815 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
816 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
817 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
818 m_osdInfo->set("dynamic", "1");
820 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
822 m_osdInfo->set("dynamic", "0");
825 m_fps = m_mltProducer->get_fps();
826 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
828 fillSlowMotionProducers();
830 //TODO: seek to correct place after opening project.
831 // Needs to be done from another place since it crashes here.
832 m_mltProducer->seek(position);
836 //kDebug()<<"// SETSCN LST, POS: "<<position;
837 //if (position != 0) emit rendererPosition(position);
840 /** Create the producer from the Westley QDomDocument */
841 const QString Render::sceneList() {
843 Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
844 m_mltProducer->optimise();
845 westleyConsumer.set("terminate_on_pause", 1);
846 Mlt::Producer prod(m_mltProducer->get_producer());
847 bool split = m_isSplitView;
848 if (split) slotSplitView(false);
849 westleyConsumer.connect(prod);
850 westleyConsumer.start();
851 while (!westleyConsumer.is_stopped()) {}
852 playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
853 if (split) slotSplitView(true);
857 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
860 doc.setContent(sceneList(), false);
861 if (!kdenliveData.isNull()) {
862 // add Kdenlive specific tags
863 QDomNode wes = doc.elementsByTagName("westley").at(0);
864 wes.appendChild(doc.importNode(kdenliveData, true));
866 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
867 kWarning() << "////// ERROR writing to file: " << path;
870 QTextStream out(&file);
871 out << doc.toString();
876 void Render::saveZone(KUrl url, QString desc, QPoint zone) {
877 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
878 char *tmppath = decodedString("westley:" + url.path());
879 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
880 m_mltProducer->optimise();
882 westleyConsumer.set("terminate_on_pause", 1);
883 if (m_name == "clip") {
884 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
885 tmppath = decodedString(desc);
887 list.insert_at(0, prod, 0);
888 list.set("title", tmppath);
890 westleyConsumer.connect(list);
893 //TODO: not working yet, save zone from timeline
894 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
895 /* Mlt::Service service(p1->parent().get_service());
896 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
898 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
899 tmppath = decodedString(desc);
900 //prod->set("title", tmppath);
902 westleyConsumer.connect(*p1); //list);
905 westleyConsumer.start();
908 const double Render::fps() const {
912 void Render::connectPlaylist() {
913 if (!m_mltConsumer) return;
914 //m_mltConsumer->set("refresh", "0");
915 m_mltConsumer->connect(*m_mltProducer);
916 m_mltProducer->set_speed(0);
917 m_mltConsumer->start();
918 emit durationChanged(m_mltProducer->get_playtime());
921 if (m_mltConsumer->start() == -1) {
922 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."));
923 m_mltConsumer = NULL;
930 void Render::refreshDisplay() {
932 if (!m_mltProducer) return;
933 //m_mltConsumer->set("refresh", 0);
935 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
936 /*if (KdenliveSettings::osdtimecode()) {
937 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
938 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
939 m_osdInfo->set("dynamic", "1");
940 m_mltProducer->attach(*m_osdInfo);
943 m_mltProducer->detach(*m_osdInfo);
944 m_osdInfo->set("dynamic", "0");
949 void Render::setVolume(double volume) {
950 if (!m_mltConsumer || !m_mltProducer) return;
952 m_mltConsumer->set("refresh", 0);
953 // Attach filter for on screen display of timecode
954 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
955 mlt_properties_set_double( properties, "meta.volume", volume );
956 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
957 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
959 if (!KdenliveSettings::osdtimecode()) {
960 m_mltProducer->detach(*m_osdInfo);
961 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
962 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
965 osdTimer->setSingleShot(2500);
968 void Render::slotOsdTimeout() {
969 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
970 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
971 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
972 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
976 void Render::start() {
977 kDebug() << "----- STARTING MONITOR: " << m_name;
979 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
983 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
984 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
985 if (m_mltConsumer->start() == -1) {
986 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."));
987 m_mltConsumer = NULL;
990 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
998 void Render::clear() {
999 kDebug() << " ********* RENDER CLEAR";
1000 if (m_mltConsumer) {
1001 //m_mltConsumer->set("refresh", 0);
1002 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1005 if (m_mltProducer) {
1006 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1007 m_mltProducer->set_speed(0.0);
1008 delete m_mltProducer;
1009 m_mltProducer = NULL;
1014 void Render::stop() {
1015 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1016 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1018 //m_mltConsumer->set("refresh", 0);
1019 m_mltConsumer->stop();
1020 // delete m_mltConsumer;
1021 // m_mltConsumer = NULL;
1023 kDebug() << "///////////// RENDER STOP2-------";
1026 if (m_mltProducer) {
1027 if (m_isZoneMode) resetZoneMode();
1028 m_mltProducer->set_speed(0.0);
1029 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1030 //kDebug() << m_mltProducer->get_length();
1032 kDebug() << "///////////// RENDER STOP3-------";
1035 void Render::stop(const GenTime & startTime) {
1037 kDebug() << "///////////// RENDER STOP-------2";
1038 if (m_mltProducer) {
1039 if (m_isZoneMode) resetZoneMode();
1040 m_mltProducer->set_speed(0.0);
1041 m_mltProducer->seek((int) startTime.frames(m_fps));
1043 m_mltConsumer->purge();
1046 void Render::pause() {
1047 if (!m_mltProducer || !m_mltConsumer)
1049 if (m_mltProducer->get_speed() == 0.0) return;
1050 if (m_isZoneMode) resetZoneMode();
1052 m_mltConsumer->set("refresh", 0);
1053 m_mltProducer->set_speed(0.0);
1054 emit rendererPosition(m_framePosition);
1055 m_mltProducer->seek(m_framePosition);
1056 m_mltConsumer->purge();
1059 void Render::switchPlay() {
1060 if (!m_mltProducer || !m_mltConsumer)
1062 if (m_isZoneMode) resetZoneMode();
1063 if (m_mltProducer->get_speed() == 0.0) {
1064 m_isBlocked = false;
1065 m_mltProducer->set_speed(1.0);
1066 m_mltConsumer->set("refresh", 1);
1069 m_mltConsumer->set("refresh", 0);
1070 m_mltProducer->set_speed(0.0);
1071 emit rendererPosition(m_framePosition);
1072 m_mltProducer->seek(m_framePosition);
1073 m_mltConsumer->purge();
1074 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1075 //m_mltConsumer->set("refresh", 0);
1076 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1077 m_mltProducer->set_speed(0);
1078 m_mltProducer->seek( position );
1079 //m_mltProducer->seek((int) m_framePosition);
1080 m_isBlocked = false;*/
1082 /*if (speed == 0.0) {
1083 m_mltProducer->seek((int) m_framePosition + 1);
1084 m_mltConsumer->purge();
1089 void Render::play(double speed) {
1092 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1093 m_isBlocked = false;
1094 m_mltProducer->set_speed(speed);
1095 /*if (speed == 0.0) {
1096 m_mltProducer->seek((int) m_framePosition + 1);
1097 m_mltConsumer->purge();
1102 void Render::play(const GenTime & startTime) {
1103 if (!m_mltProducer || !m_mltConsumer)
1105 m_isBlocked = false;
1106 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1107 m_mltProducer->set_speed(1.0);
1108 m_mltConsumer->set("refresh", 1);
1111 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1112 if (!m_mltProducer || !m_mltConsumer)
1114 //m_mltProducer->set("eof", "loop");
1115 m_isLoopMode = true;
1116 m_loopStart = startTime;
1117 playZone(startTime, stopTime);
1120 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1121 if (!m_mltProducer || !m_mltConsumer)
1123 m_isBlocked = false;
1124 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1125 m_mltProducer->set("out", stopTime.frames(m_fps));
1126 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1127 m_mltProducer->set_speed(1.0);
1128 m_mltConsumer->set("refresh", 1);
1129 m_isZoneMode = true;
1132 void Render::resetZoneMode() {
1133 if (!m_isZoneMode && !m_isLoopMode) return;
1134 m_mltProducer->set("out", m_originalOut);
1135 //m_mltProducer->set("eof", "pause");
1136 m_isZoneMode = false;
1137 m_isLoopMode = false;
1140 void Render::seekToFrame(int pos) {
1141 //kDebug()<<" ********* RENDER SEEK TO POS";
1144 m_isBlocked = false;
1146 m_mltProducer->seek(pos);
1150 void Render::askForRefresh() {
1151 // Use a Timer so that we don't refresh too much
1152 refreshTimer->start(200);
1155 void Render::doRefresh() {
1156 // Use a Timer so that we don't refresh too much
1157 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1160 void Render::refresh() {
1161 if (!m_mltProducer || m_isBlocked)
1163 refreshTimer->stop();
1164 if (m_mltConsumer) {
1165 m_mltConsumer->set("refresh", 1);
1169 double Render::playSpeed() {
1170 if (m_mltProducer) return m_mltProducer->get_speed();
1174 GenTime Render::seekPosition() const {
1175 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1176 else return GenTime();
1180 const QString & Render::rendererName() const {
1185 void Render::emitFrameNumber(double position) {
1186 m_framePosition = position;
1187 emit rendererPosition((int) position);
1188 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1191 void Render::emitConsumerStopped() {
1192 // This is used to know when the playing stopped
1193 if (m_mltProducer) {
1194 double pos = m_mltProducer->position();
1195 if (m_isLoopMode) play(m_loopStart);
1196 else if (m_isZoneMode) resetZoneMode();
1197 emit rendererStopped((int) pos);
1198 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1199 //new QCustomEvent(10002));
1205 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1206 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1210 void Render::exportCurrentFrame(KUrl url, bool notify) {
1211 if (!m_mltProducer) {
1212 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1216 //int height = 1080;//KdenliveSettings::defaultheight();
1217 //int width = 1940; //KdenliveSettings::displaywidth();
1219 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1221 QPixmap pix(width, height);
1222 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1223 m_convert.set("forced", mlt_image_rgb24a);
1224 m_mltProducer->attach(m_convert);
1225 Mlt::Frame * frame = m_mltProducer->get_frame();
1226 m_mltProducer->detach(m_convert);
1228 pix = frameThumbnail(frame, width, height);
1231 pix.save(url.path(), "PNG");
1232 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1235 /** MLT PLAYLIST DIRECT MANIPULATON **/
1238 void Render::mltCheckLength() {
1239 //kDebug()<<"checking track length: "<<track<<"..........";
1241 Mlt::Service service(m_mltProducer->get_service());
1242 Mlt::Tractor tractor(service);
1244 int trackNb = tractor.count();
1245 double duration = 0;
1246 double trackDuration;
1248 Mlt::Producer trackProducer(tractor.track(0));
1249 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1250 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1251 m_mltProducer->set("out", duration);
1252 emit durationChanged((int) duration);
1255 while (trackNb > 1) {
1256 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1257 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1258 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1260 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1261 if (trackDuration > duration) duration = trackDuration;
1265 Mlt::Producer blackTrackProducer(tractor.track(0));
1266 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1267 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1269 if (blackDuration != duration) {
1270 blackTrackPlaylist.clear();
1271 int dur = (int)duration;
1272 while (dur > 14000) {
1274 blackTrackPlaylist.append(*m_blackClip, 0, 13999);
1279 blackTrackPlaylist.append(*m_blackClip, 0, dur);
1281 m_mltProducer->set("out", duration);
1282 emit durationChanged((int)duration);
1286 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1287 if (!m_mltProducer) {
1288 kDebug() << "PLAYLIST NOT INITIALISED //////";
1291 Mlt::Producer parentProd(m_mltProducer->parent());
1292 if (parentProd.get_producer() == NULL) {
1293 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1297 Mlt::Service service(parentProd.get_service());
1298 Mlt::Tractor tractor(service);
1299 mlt_service_lock(service.get_service());
1300 Mlt::Producer trackProducer(tractor.track(info.track));
1301 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1302 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1304 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1305 // We want a slowmotion producer
1306 double speed = element.attribute("speed", "1.0").toDouble();
1307 QString url = QString::fromUtf8(prod->get("resource"));
1308 url.append('?' + QString::number(speed));
1309 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1310 if (!slowprod || slowprod->get_producer() == NULL) {
1311 char *tmp = decodedString(url);
1312 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1314 QString id = prod->get("id");
1315 if (id.contains('_')) id = id.section('_', 0, 0);
1316 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1317 tmp = decodedString(producerid);
1318 slowprod->set("id", tmp);
1320 m_slowmotionProducers.insert(url, slowprod);
1325 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1326 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1328 /*if (QString(prod->get("transparency")).toInt() == 1)
1329 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1331 mlt_service_unlock(service.get_service());
1333 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1334 //tractor.multitrack()->refresh();
1335 //tractor.refresh();
1339 void Render::mltCutClip(int track, GenTime position) {
1343 Mlt::Service service(m_mltProducer->parent().get_service());
1344 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1346 Mlt::Tractor tractor(service);
1347 Mlt::Producer trackProducer(tractor.track(track));
1348 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1351 /* // Display playlist info
1352 kDebug()<<"//////////// BEFORE";
1353 for (int i = 0; i < trackPlaylist.count(); i++) {
1354 int blankStart = trackPlaylist.clip_start(i);
1355 int blankDuration = trackPlaylist.clip_length(i) - 1;
1357 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1358 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1361 int cutPos = (int) position.frames(m_fps);
1363 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1364 if (trackPlaylist.is_blank(clipIndex)) {
1365 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1366 m_isBlocked = false;
1369 mlt_service_lock(service.get_service());
1370 int clipStart = trackPlaylist.clip_start(clipIndex);
1371 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1372 mlt_service_unlock(service.get_service());
1374 // duplicate effects
1375 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1376 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1378 if (original == NULL || clip == NULL) {
1379 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1381 Mlt::Service clipService(original->get_service());
1382 Mlt::Service dupService(clip->get_service());
1384 Mlt::Filter *filter = clipService.filter(ct);
1386 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1387 // looks like there is no easy way to duplicate a filter,
1388 // so we will create a new one and duplicate its properties
1389 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1390 if (dup && dup->is_valid()) {
1391 Mlt::Properties entries(filter->get_properties());
1392 for (int i = 0;i < entries.count();i++) {
1393 dup->set(entries.get_name(i), entries.get(i));
1395 dupService.attach(*dup);
1399 filter = clipService.filter(ct);
1402 /* // Display playlist info
1403 kDebug()<<"//////////// AFTER";
1404 for (int i = 0; i < trackPlaylist.count(); i++) {
1405 int blankStart = trackPlaylist.clip_start(i);
1406 int blankDuration = trackPlaylist.clip_length(i) - 1;
1408 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1409 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1412 m_isBlocked = false;
1415 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1417 mltRemoveClip(info.track, info.startPos);
1418 mltInsertClip(info, element, prod);
1422 bool Render::mltRemoveClip(int track, GenTime position) {
1423 Mlt::Service service(m_mltProducer->parent().get_service());
1424 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1426 Mlt::Tractor tractor(service);
1427 Mlt::Producer trackProducer(tractor.track(track));
1428 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1429 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1431 /* // Display playlist info
1432 kDebug()<<"//// BEFORE";
1433 for (int i = 0; i < trackPlaylist.count(); i++) {
1434 int blankStart = trackPlaylist.clip_start(i);
1435 int blankDuration = trackPlaylist.clip_length(i) - 1;
1437 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1438 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1441 if (trackPlaylist.is_blank(clipIndex)) {
1442 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1446 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1447 trackPlaylist.replace_with_blank(clipIndex);
1448 trackPlaylist.consolidate_blanks(0);
1449 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1450 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1452 /* // Display playlist info
1453 kDebug()<<"//// AFTER";
1454 for (int i = 0; i < trackPlaylist.count(); i++) {
1455 int blankStart = trackPlaylist.clip_start(i);
1456 int blankDuration = trackPlaylist.clip_length(i) - 1;
1458 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1459 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1462 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1463 m_isBlocked = false;
1467 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
1468 if (!m_mltProducer) {
1469 kDebug() << "PLAYLIST NOT INITIALISED //////";
1472 Mlt::Producer parentProd(m_mltProducer->parent());
1473 if (parentProd.get_producer() == NULL) {
1474 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1478 Mlt::Service service(parentProd.get_service());
1479 Mlt::Tractor tractor(service);
1480 int insertPos = pos.frames(m_fps);
1482 Mlt::Producer trackProducer(tractor.track(track));
1483 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1484 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1485 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1486 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1487 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1491 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
1492 if (!m_mltProducer) {
1493 kDebug() << "PLAYLIST NOT INITIALISED //////";
1496 Mlt::Producer parentProd(m_mltProducer->parent());
1497 if (parentProd.get_producer() == NULL) {
1498 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1501 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1502 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1504 Mlt::Service service(parentProd.get_service());
1505 Mlt::Tractor tractor(service);
1506 mlt_service_lock(service.get_service());
1507 int diff = duration.frames(m_fps);
1508 int offset = timeOffset.frames(m_fps);
1512 // insert space in one track only
1513 Mlt::Producer trackProducer(tractor.track(track));
1514 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1515 insertPos = trackClipStartList.value(track);
1516 if (insertPos != -1) {
1517 insertPos += offset;
1518 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1519 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1521 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1522 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1523 int position = trackPlaylist.clip_start(clipIndex);
1524 trackPlaylist.remove_region(position, - diff - 1);
1526 trackPlaylist.consolidate_blanks(0);
1528 // now move transitions
1529 mlt_service serv = m_mltProducer->parent().get_service();
1530 mlt_service nextservice = mlt_service_get_producer(serv);
1531 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1532 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1533 QString resource = mlt_properties_get(properties, "mlt_service");
1535 while (mlt_type == "transition") {
1536 mlt_transition tr = (mlt_transition) nextservice;
1537 int currentTrack = mlt_transition_get_b_track(tr);
1538 int currentIn = (int) mlt_transition_get_in(tr);
1539 int currentOut = (int) mlt_transition_get_out(tr);
1540 insertPos = trackTransitionStartList.value(track);
1541 if (insertPos != -1) {
1542 insertPos += offset;
1543 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1544 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1547 nextservice = mlt_service_producer(nextservice);
1548 if (nextservice == NULL) break;
1549 properties = MLT_SERVICE_PROPERTIES(nextservice);
1550 mlt_type = mlt_properties_get(properties, "mlt_type");
1551 resource = mlt_properties_get(properties, "mlt_service");
1554 int trackNb = tractor.count();
1555 while (trackNb > 1) {
1556 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1557 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1560 //int clipNb = trackPlaylist.count();
1561 insertPos = trackClipStartList.value(trackNb - 1);
1562 if (insertPos != -1) {
1563 insertPos += offset;
1565 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1566 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1567 for (int i = 0; i < clipNb; i++) {
1568 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1569 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1570 kDebug()<<"-------------";
1572 kDebug()<<"END-------------";*/
1575 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1576 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1578 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1579 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1580 int position = trackPlaylist.clip_start(clipIndex);
1581 trackPlaylist.remove_region(position, - diff - 1);
1583 trackPlaylist.consolidate_blanks(0);
1587 // now move transitions
1588 mlt_service serv = m_mltProducer->parent().get_service();
1589 mlt_service nextservice = mlt_service_get_producer(serv);
1590 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1591 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1592 QString resource = mlt_properties_get(properties, "mlt_service");
1594 while (mlt_type == "transition") {
1595 mlt_transition tr = (mlt_transition) nextservice;
1596 int currentIn = (int) mlt_transition_get_in(tr);
1597 int currentOut = (int) mlt_transition_get_out(tr);
1598 int currentTrack = mlt_transition_get_b_track(tr);
1599 insertPos = trackTransitionStartList.value(currentTrack);
1600 if (insertPos != -1) {
1601 insertPos += offset;
1602 if (currentOut > insertPos && resource != "mix") {
1603 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1606 nextservice = mlt_service_producer(nextservice);
1607 if (nextservice == NULL) break;
1608 properties = MLT_SERVICE_PROPERTIES(nextservice);
1609 mlt_type = mlt_properties_get(properties, "mlt_type");
1610 resource = mlt_properties_get(properties, "mlt_service");
1613 mlt_service_unlock(service.get_service());
1615 m_mltConsumer->set("refresh", 1);
1618 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
1621 Mlt::Service service(m_mltProducer->parent().get_service());
1622 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1623 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1624 Mlt::Tractor tractor(service);
1625 Mlt::Producer trackProducer(tractor.track(info.track));
1626 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1627 int startPos = info.startPos.frames(m_fps);
1628 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1629 int clipLength = trackPlaylist.clip_length(clipIndex);
1631 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1632 if (!clip.is_valid() || clip.is_blank()) {
1636 Mlt::Producer clipparent = clip.parent();
1637 if (!clipparent.is_valid() || clipparent.is_blank()) {
1641 QString serv = clipparent.get("mlt_service");
1642 QString id = clipparent.get("id");
1643 //kDebug() << "CLIP SERVICE: " << serv;
1644 if (serv == "avformat" && speed != 1.0) {
1645 mlt_service_lock(service.get_service());
1646 QString url = QString::fromUtf8(clipparent.get("resource"));
1647 url.append('?' + QString::number(speed));
1648 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1649 if (!slowprod || slowprod->get_producer() == NULL) {
1650 char *tmp = decodedString(url);
1651 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1653 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1654 tmp = decodedString(producerid);
1655 slowprod->set("id", tmp);
1657 m_slowmotionProducers.insert(url, slowprod);
1659 trackPlaylist.replace_with_blank(clipIndex);
1660 trackPlaylist.consolidate_blanks(0);
1661 // Check that the blank space is long enough for our new duration
1662 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1663 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1665 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1666 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1667 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1668 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1669 trackPlaylist.insert_at(startPos, *cut, 1);
1670 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1671 newLength = trackPlaylist.clip_length(clipIndex);
1672 mlt_service_unlock(service.get_service());
1673 } else if (speed == 1.0) {
1674 mlt_service_lock(service.get_service());
1676 trackPlaylist.replace_with_blank(clipIndex);
1677 trackPlaylist.consolidate_blanks(0);
1679 // Check that the blank space is long enough for our new duration
1680 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1681 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1684 GenTime oldDuration = GenTime(clipLength, m_fps);
1685 GenTime newDuration = oldDuration * oldspeed;
1686 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1687 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1688 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1689 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1690 trackPlaylist.insert_at(startPos, *cut, 1);
1691 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1692 newLength = trackPlaylist.clip_length(clipIndex);
1693 mlt_service_unlock(service.get_service());
1695 } else if (serv == "framebuffer") {
1696 mlt_service_lock(service.get_service());
1697 QString url = QString::fromUtf8(clipparent.get("resource"));
1698 url = url.section('?', 0, 0);
1699 url.append('?' + QString::number(speed));
1700 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1701 if (!slowprod || slowprod->get_producer() == NULL) {
1702 char *tmp = decodedString(url);
1703 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1705 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1706 tmp = decodedString(producerid);
1707 slowprod->set("id", tmp);
1709 m_slowmotionProducers.insert(url, slowprod);
1711 trackPlaylist.replace_with_blank(clipIndex);
1712 trackPlaylist.consolidate_blanks(0);
1714 GenTime oldDuration = GenTime(clipLength, m_fps);
1715 GenTime newDuration = oldDuration * oldspeed / speed;
1717 // Check that the blank space is long enough for our new duration
1718 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1719 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1722 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1723 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1724 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1725 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1727 trackPlaylist.insert_at(startPos, *cut, 1);
1728 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1729 newLength = trackPlaylist.clip_length(clipIndex);
1731 mlt_service_unlock(service.get_service());
1733 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1734 m_isBlocked = false;
1738 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh) {
1739 kDebug() << "// TRYing to remove effect at: " << index;
1740 Mlt::Service service(m_mltProducer->parent().get_service());
1741 bool success = false;
1742 Mlt::Tractor tractor(service);
1743 Mlt::Producer trackProducer(tractor.track(track));
1744 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1745 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1746 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1748 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1751 Mlt::Service clipService(clip->get_service());
1752 // if (tag.startsWith("ladspa")) tag = "ladspa";
1755 Mlt::Filter *filter = clipService.filter(ct);
1757 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1758 if (clipService.detach(*filter) == 0) success = true;
1759 kDebug() << " / / / DLEETED EFFECT: " << ct;
1760 } else if (updateIndex) {
1761 // Adjust the other effects index
1762 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1765 filter = clipService.filter(ct);
1767 m_isBlocked = false;
1768 if (doRefresh) refresh();
1773 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
1775 Mlt::Service service(m_mltProducer->parent().get_service());
1777 Mlt::Tractor tractor(service);
1778 Mlt::Producer trackProducer(tractor.track(track));
1779 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1781 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1785 Mlt::Service clipService(clip->get_service());
1788 // temporarily remove all effects after insert point
1789 QList <Mlt::Filter *> filtersList;
1790 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1792 Mlt::Filter *filter = clipService.filter(ct);
1794 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1795 filtersList.append(filter);
1796 clipService.detach(*filter);
1798 filter = clipService.filter(ct);
1802 QString tag = params.paramValue("tag");
1803 kDebug() << " / / INSERTING EFFECT: " << tag;
1804 if (tag.startsWith("ladspa")) tag = "ladspa";
1805 char *filterTag = decodedString(tag);
1806 char *filterId = decodedString(params.paramValue("id"));
1807 QHash<QString, QString>::Iterator it;
1808 QString kfr = params.paramValue("keyframes");
1810 if (!kfr.isEmpty()) {
1811 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1812 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1813 char *starttag = decodedString(params.paramValue("starttag", "start"));
1814 char *endtag = decodedString(params.paramValue("endtag", "end"));
1815 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1816 int duration = clip->get_playtime();
1817 //double max = params.paramValue("max").toDouble();
1818 double min = params.paramValue("min").toDouble();
1819 double factor = params.paramValue("factor", "1").toDouble();
1820 params.removeParam("starttag");
1821 params.removeParam("endtag");
1822 params.removeParam("keyframes");
1823 params.removeParam("min");
1824 params.removeParam("max");
1825 params.removeParam("factor");
1827 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1828 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1829 if (filter && filter->is_valid()) {
1830 filter->set("kdenlive_id", filterId);
1831 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1832 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1833 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1834 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1835 if (x2 == -1) x2 = duration;
1837 for (int j = 0; j < params.count(); j++) {
1838 char *name = decodedString(params.at(j).name());
1839 char *value = decodedString(params.at(j).value());
1840 filter->set(name, value);
1845 filter->set("in", x1);
1846 filter->set("out", x2);
1847 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1848 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1849 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1850 clipService.attach(*filter);
1857 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1858 if (filter && filter->is_valid())
1859 filter->set("kdenlive_id", filterId);
1861 kDebug() << "filter is NULL";
1862 m_isBlocked = false;
1866 params.removeParam("kdenlive_id");
1868 for (int j = 0; j < params.count(); j++) {
1869 char *name = decodedString(params.at(j).name());
1870 char *value = decodedString(params.at(j).value());
1871 filter->set(name, value);
1877 QString effectArgs = params.paramValue("id").section('_', 1);
1879 params.removeParam("id");
1880 params.removeParam("kdenlive_ix");
1881 params.removeParam("tag");
1882 params.removeParam("disabled");
1884 for (int j = 0; j < params.count(); j++) {
1885 effectArgs.append(' ' + params.at(j).value());
1887 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1888 char *value = decodedString(effectArgs.simplified());
1889 filter->set("effect", value);
1894 // attach filter to the clip
1895 clipService.attach(*filter);
1900 // re-add following filters
1901 for (int i = 0; i < filtersList.count(); i++) {
1902 clipService.attach(*(filtersList.at(i)));
1905 m_isBlocked = false;
1906 if (doRefresh) refresh();
1910 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
1911 QString index = params.paramValue("kdenlive_ix");
1912 QString tag = params.paramValue("tag");
1914 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1915 // This is a keyframe effect, to edit it, we remove it and re-add it.
1916 mltRemoveEffect(track, position, index, true);
1917 bool success = mltAddEffect(track, position, params);
1922 Mlt::Service service(m_mltProducer->parent().get_service());
1924 Mlt::Tractor tractor(service);
1925 Mlt::Producer trackProducer(tractor.track(track));
1926 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1927 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1928 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1930 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1933 Mlt::Service clipService(clip->get_service());
1936 Mlt::Filter *filter = clipService.filter(ct);
1938 if (filter->get("kdenlive_ix") == index) {
1942 filter = clipService.filter(ct);
1946 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1947 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1949 filter = clipService.filter(ct);
1950 QList <Mlt::Filter *> filtersList;
1952 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1953 filtersList.append(filter);
1954 clipService.detach(*filter);
1956 filter = clipService.filter(ct);
1958 bool success = mltAddEffect(track, position, params);
1960 for (int i = 0; i < filtersList.count(); i++) {
1961 clipService.attach(*(filtersList.at(i)));
1964 m_isBlocked = false;
1968 for (int j = 0; j < params.count(); j++) {
1969 char *name = decodedString(params.at(j).name());
1970 char *value = decodedString(params.at(j).value());
1971 filter->set(name, value);
1976 m_isBlocked = false;
1981 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1983 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1984 Mlt::Service service(m_mltProducer->parent().get_service());
1986 Mlt::Tractor tractor(service);
1987 Mlt::Producer trackProducer(tractor.track(track));
1988 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1989 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1990 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1992 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1995 Mlt::Service clipService(clip->get_service());
1998 QList <Mlt::Filter *> filtersList;
1999 Mlt::Filter *filter = clipService.filter(ct);
2001 if (newPos > oldPos) {
2003 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2004 filter->set("kdenlive_ix", newPos);
2005 filtersList.append(filter);
2006 clipService.detach(*filter);
2007 filter = clipService.filter(ct);
2008 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2009 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2011 filter = clipService.filter(ct);
2015 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2016 filtersList.append(filter);
2017 clipService.detach(*filter);
2019 filter = clipService.filter(ct);
2023 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2024 filter->set("kdenlive_ix", newPos);
2025 filtersList.append(filter);
2026 clipService.detach(*filter);
2028 filter = clipService.filter(ct);
2032 filter = clipService.filter(ct);
2034 int pos = QString(filter->get("kdenlive_ix")).toInt();
2035 if (pos >= newPos) {
2036 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2037 filtersList.append(filter);
2038 clipService.detach(*filter);
2040 filter = clipService.filter(ct);
2044 for (int i = 0; i < filtersList.count(); i++) {
2045 clipService.attach(*(filtersList.at(i)));
2048 m_isBlocked = false;
2052 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
2055 Mlt::Service service(m_mltProducer->parent().get_service());
2057 Mlt::Tractor tractor(service);
2058 Mlt::Producer trackProducer(tractor.track(info.track));
2059 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2061 /* // Display playlist info
2062 kDebug()<<"//////////// BEFORE RESIZE";
2063 for (int i = 0; i < trackPlaylist.count(); i++) {
2064 int blankStart = trackPlaylist.clip_start(i);
2065 int blankDuration = trackPlaylist.clip_length(i) - 1;
2067 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2068 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2071 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2072 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2073 m_isBlocked = false;
2076 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2077 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2078 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2079 int previousStart = clip->get_in();
2080 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2081 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2082 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2083 trackPlaylist.consolidate_blanks(0);
2084 // skip to next clip
2086 int diff = newDuration - previousDuration;
2087 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2089 // clip was made longer, trim next blank if there is one.
2090 if (clipIndex < trackPlaylist.count()) {
2091 // If this is not the last clip in playlist
2092 if (trackPlaylist.is_blank(clipIndex)) {
2093 int blankStart = trackPlaylist.clip_start(clipIndex);
2094 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2095 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2096 if (diff - blankDuration == 1) {
2097 trackPlaylist.remove(clipIndex);
2098 } else trackPlaylist.remove_region(blankStart, diff - 1);
2100 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2103 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2105 trackPlaylist.consolidate_blanks(0);
2108 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2109 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2110 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2111 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2112 ItemInfo transpinfo;
2113 transpinfo.startPos = info.startPos;
2114 transpinfo.endPos = info.startPos + clipDuration;
2115 transpinfo.track = info.track;
2116 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2118 m_isBlocked = false;
2119 m_mltConsumer->set("refresh", 1);
2123 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
2124 Mlt::Service service(m_mltProducer->parent().get_service());
2125 Mlt::Tractor tractor(service);
2126 Mlt::Producer trackProducer(tractor.track(track));
2129 if (blind) trackProducer.set("hide", 3);
2130 else trackProducer.set("hide", 2);
2132 trackProducer.set("hide", 1);
2134 trackProducer.set("hide", 0);
2136 tractor.multitrack()->refresh();
2142 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) {
2143 Mlt::Service service(m_mltProducer->parent().get_service());
2144 int frameOffset = (int) diff.frames(m_fps);
2145 Mlt::Tractor tractor(service);
2146 Mlt::Producer trackProducer(tractor.track(info.track));
2147 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2148 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2149 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2152 mlt_service_lock(service.get_service());
2153 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2154 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2156 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2157 mlt_service_unlock(service.get_service());
2160 int previousStart = clip->get_in();
2161 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2163 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2164 m_isBlocked = false;
2165 mlt_service_unlock(service.get_service());
2166 m_mltConsumer->set("refresh", 1);
2170 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
2171 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2172 Mlt::Service service(m_mltProducer->parent().get_service());
2173 int moveFrame = (int) diff.frames(m_fps);
2174 Mlt::Tractor tractor(service);
2175 Mlt::Producer trackProducer(tractor.track(info.track));
2176 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2177 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2178 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2181 mlt_service_lock(service.get_service());
2182 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2183 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2185 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2186 mlt_service_unlock(service.get_service());
2189 int previousStart = clip->get_in();
2190 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2192 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2193 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2194 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2196 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2197 int blankIndex = clipIndex - 1;
2198 int blankLength = trackPlaylist.clip_length(blankIndex);
2199 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2200 if (! trackPlaylist.is_blank(blankIndex)) {
2201 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2203 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2204 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2206 trackPlaylist.consolidate_blanks(0);
2207 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2208 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2209 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2210 ItemInfo transpinfo;
2211 transpinfo.startPos = info.startPos + diff;
2212 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2213 transpinfo.track = info.track;
2214 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2216 m_isBlocked = false;
2217 //m_mltConsumer->set("refresh", 1);
2218 mlt_service_unlock(service.get_service());
2219 m_mltConsumer->set("refresh", 1);
2223 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
2224 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2228 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
2229 if (prod == NULL || !prod->is_valid()) {
2230 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2233 kDebug() << "NEW PROD ID: " << prod->get("id");
2234 m_mltConsumer->set("refresh", 0);
2235 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2236 mlt_service_lock(m_mltConsumer->get_service());
2237 Mlt::Service service(m_mltProducer->parent().get_service());
2238 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2240 Mlt::Tractor tractor(service);
2241 Mlt::Producer trackProducer(tractor.track(track));
2242 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2243 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2244 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2245 if (clipProducer.is_blank()) {
2246 kDebug() << "// ERROR UPDATING CLIP PROD";
2247 mlt_service_unlock(m_mltConsumer->get_service());
2248 m_isBlocked = false;
2251 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2253 // move all effects to the correct producer
2254 Mlt::Service clipService(clipProducer.get_service());
2255 Mlt::Service newClipService(clip->get_service());
2258 Mlt::Filter *filter = clipService.filter(ct);
2260 if (filter->get("kdenlive_ix") != 0) {
2261 clipService.detach(*filter);
2262 newClipService.attach(*filter);
2264 filter = clipService.filter(ct);
2267 trackPlaylist.insert_at(pos, clip, 1);
2268 mlt_service_unlock(m_mltConsumer->get_service());
2269 m_isBlocked = false;
2272 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
2275 m_mltConsumer->set("refresh", 0);
2276 mlt_service_lock(m_mltConsumer->get_service());
2277 Mlt::Service service(m_mltProducer->parent().get_service());
2278 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2280 Mlt::Tractor tractor(service);
2281 Mlt::Producer trackProducer(tractor.track(startTrack));
2282 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2283 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2284 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2285 bool checkLength = false;
2286 if (endTrack == startTrack) {
2287 //mlt_service_lock(service.get_service());
2288 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2289 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2290 // error, destination is not empty
2291 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2292 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2293 mlt_service_unlock(m_mltConsumer->get_service());
2294 m_isBlocked = false;
2297 trackPlaylist.consolidate_blanks(0);
2298 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2299 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2300 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2302 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2304 //mlt_service_unlock(service.get_service());
2306 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2307 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2308 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2309 // error, destination is not empty
2310 mlt_service_unlock(m_mltConsumer->get_service());
2311 m_isBlocked = false;
2314 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2315 if (clipProducer.is_blank()) {
2316 // error, destination is not empty
2317 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2318 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2319 mlt_service_unlock(m_mltConsumer->get_service());
2320 m_isBlocked = false;
2323 trackPlaylist.consolidate_blanks(0);
2324 destTrackPlaylist.consolidate_blanks(1);
2325 Mlt::Producer *clip;
2326 // check if we are moving a slowmotion producer
2327 QString serv = clipProducer.parent().get("mlt_service");
2328 if (serv == "framebuffer") {
2329 clip = &clipProducer;
2330 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2332 // move all effects to the correct producer
2333 Mlt::Service clipService(clipProducer.get_service());
2334 Mlt::Service newClipService(clip->get_service());
2337 Mlt::Filter *filter = clipService.filter(ct);
2339 if (filter->get("kdenlive_ix") != 0) {
2340 clipService.detach(*filter);
2341 newClipService.attach(*filter);
2343 filter = clipService.filter(ct);
2346 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2347 destTrackPlaylist.consolidate_blanks(0);
2348 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2349 kDebug() << "//////// moving clip transparency";
2350 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2352 if (clipIndex > trackPlaylist.count()) checkLength = true;
2353 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2357 if (checkLength) mltCheckLength();
2358 mlt_service_unlock(m_mltConsumer->get_service());
2359 m_isBlocked = false;
2360 m_mltConsumer->set("refresh", 1);
2364 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
2365 int new_in = (int)newIn.frames(m_fps);
2366 int new_out = (int)newOut.frames(m_fps) - 1;
2367 if (new_in >= new_out) return false;
2369 Mlt::Service service(m_mltProducer->parent().get_service());
2370 Mlt::Tractor tractor(service);
2372 mlt_service_lock(service.get_service());
2373 m_mltConsumer->set("refresh", 0);
2376 mlt_service serv = m_mltProducer->parent().get_service();
2377 mlt_service nextservice = mlt_service_get_producer(serv);
2378 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2379 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2380 QString resource = mlt_properties_get(properties, "mlt_service");
2381 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2383 while (mlt_type == "transition") {
2384 mlt_transition tr = (mlt_transition) nextservice;
2385 int currentTrack = mlt_transition_get_b_track(tr);
2386 int currentIn = (int) mlt_transition_get_in(tr);
2387 int currentOut = (int) mlt_transition_get_out(tr);
2389 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2390 mlt_transition_set_in_and_out(tr, new_in, new_out);
2391 if (newTrack - startTrack != 0) {
2392 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2394 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2395 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2396 mlt_properties_set_int(properties, "b_track", newTrack);
2397 //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);
2401 nextservice = mlt_service_producer(nextservice);
2402 if (nextservice == NULL) break;
2403 properties = MLT_SERVICE_PROPERTIES(nextservice);
2404 mlt_type = mlt_properties_get(properties, "mlt_type");
2405 resource = mlt_properties_get(properties, "mlt_service");
2407 m_isBlocked = false;
2408 mlt_service_unlock(service.get_service());
2409 m_mltConsumer->set("refresh", 1);
2413 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2414 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2415 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2417 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2418 mltAddTransition(tag, a_track, b_track, in, out, xml);
2420 //mltSavePlaylist();
2423 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2425 Mlt::Service service(m_mltProducer->parent().get_service());
2426 Mlt::Tractor tractor(service);
2428 //m_mltConsumer->set("refresh", 0);
2429 mlt_service serv = m_mltProducer->parent().get_service();
2431 mlt_service nextservice = mlt_service_get_producer(serv);
2432 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2433 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2434 QString resource = mlt_properties_get(properties, "mlt_service");
2435 int in_pos = (int) in.frames(m_fps);
2436 int out_pos = (int) out.frames(m_fps) - 1;
2438 while (mlt_type == "transition") {
2439 mlt_transition tr = (mlt_transition) nextservice;
2440 int currentTrack = mlt_transition_get_b_track(tr);
2441 int currentBTrack = mlt_transition_get_a_track(tr);
2442 int currentIn = (int) mlt_transition_get_in(tr);
2443 int currentOut = (int) mlt_transition_get_out(tr);
2445 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2447 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2448 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2449 QMap<QString, QString>::Iterator it;
2451 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2452 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2453 if (currentBTrack != a_track) {
2454 mlt_properties_set_int(properties, "a_track", a_track);
2456 for (it = map.begin(); it != map.end(); ++it) {
2458 char *name = decodedString(key);
2459 char *value = decodedString(it.value());
2460 mlt_properties_set(transproperties, name, value);
2461 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2462 //filter->set("kdenlive_id", id);
2468 nextservice = mlt_service_producer(nextservice);
2469 if (nextservice == NULL) break;
2470 properties = MLT_SERVICE_PROPERTIES(nextservice);
2471 mlt_type = mlt_properties_get(properties, "mlt_type");
2472 resource = mlt_properties_get(properties, "mlt_service");
2474 m_isBlocked = false;
2475 m_mltConsumer->set("refresh", 1);
2478 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2479 Mlt::Service service(m_mltProducer->parent().get_service());
2480 Mlt::Tractor tractor(service);
2481 Mlt::Field *field = tractor.field();
2483 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2484 mlt_service serv = m_mltProducer->parent().get_service();
2486 mlt_service nextservice = mlt_service_get_producer(serv);
2487 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2488 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2489 QString resource = mlt_properties_get(properties, "mlt_service");
2491 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2493 while (mlt_type == "transition") {
2494 mlt_transition tr = (mlt_transition) nextservice;
2495 int currentTrack = mlt_transition_get_b_track(tr);
2496 int currentIn = (int) mlt_transition_get_in(tr);
2497 int currentOut = (int) mlt_transition_get_out(tr);
2498 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2500 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2501 mlt_field_disconnect_service(field->get_field(), nextservice);
2504 nextservice = mlt_service_producer(nextservice);
2505 if (nextservice == NULL) break;
2506 properties = MLT_SERVICE_PROPERTIES(nextservice);
2507 mlt_type = mlt_properties_get(properties, "mlt_type");
2508 resource = mlt_properties_get(properties, "mlt_service");
2510 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2513 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2514 QDomNodeList attribs = xml.elementsByTagName("parameter");
2515 QMap<QString, QString> map;
2516 for (int i = 0;i < attribs.count();i++) {
2517 QDomElement e = attribs.item(i).toElement();
2518 QString name = e.attribute("name");
2519 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2520 map[name] = e.attribute("default");
2521 if (!e.attribute("value").isEmpty()) {
2522 map[name] = e.attribute("value");
2524 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2525 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2526 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2529 if (e.attribute("namedesc").contains(';')) {
2530 QString format = e.attribute("format");
2531 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2532 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2534 QTextStream txtNeu(&neu);
2535 if (values.size() > 0)
2536 txtNeu << (int)values[0].toDouble();
2538 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2539 txtNeu << separators[i];
2540 txtNeu << (int)(values[i+1].toDouble());
2542 if (i < separators.size())
2543 txtNeu << separators[i];
2544 map[e.attribute("name")] = neu;
2551 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2552 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2553 Mlt::Service service(m_mltProducer->parent().get_service());
2554 Mlt::Tractor tractor(service);
2555 Mlt::Field *field = tractor.field();
2557 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2558 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2559 transition->set("transparency", id);
2560 transition->set("fill", 1);
2561 transition->set("internal_added", 237);
2562 field->plant_transition(*transition, transitiontrack, info.track);
2566 void Render::mltDeleteTransparency(int pos, int track, int id) {
2567 Mlt::Service service(m_mltProducer->parent().get_service());
2568 Mlt::Tractor tractor(service);
2569 Mlt::Field *field = tractor.field();
2571 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2572 mlt_service serv = m_mltProducer->parent().get_service();
2574 mlt_service nextservice = mlt_service_get_producer(serv);
2575 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2576 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2577 QString resource = mlt_properties_get(properties, "mlt_service");
2579 while (mlt_type == "transition") {
2580 mlt_transition tr = (mlt_transition) nextservice;
2581 int currentTrack = mlt_transition_get_b_track(tr);
2582 int currentIn = (int) mlt_transition_get_in(tr);
2583 int currentOut = (int) mlt_transition_get_out(tr);
2584 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2585 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2587 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2588 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2589 mlt_field_disconnect_service(field->get_field(), nextservice);
2592 nextservice = mlt_service_producer(nextservice);
2593 if (nextservice == NULL) break;
2594 properties = MLT_SERVICE_PROPERTIES(nextservice);
2595 mlt_type = mlt_properties_get(properties, "mlt_type");
2596 resource = mlt_properties_get(properties, "mlt_service");
2598 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2601 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2602 Mlt::Service service(m_mltProducer->parent().get_service());
2603 Mlt::Tractor tractor(service);
2605 mlt_service_lock(service.get_service());
2606 m_mltConsumer->set("refresh", 0);
2609 mlt_service serv = m_mltProducer->parent().get_service();
2610 mlt_service nextservice = mlt_service_get_producer(serv);
2611 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2612 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2613 QString resource = mlt_properties_get(properties, "mlt_service");
2614 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2615 while (mlt_type == "transition") {
2616 mlt_transition tr = (mlt_transition) nextservice;
2617 int currentTrack = mlt_transition_get_b_track(tr);
2618 int currentIn = (int) mlt_transition_get_in(tr);
2619 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2620 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2621 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2622 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2623 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2624 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2627 nextservice = mlt_service_producer(nextservice);
2628 if (nextservice == NULL) break;
2629 properties = MLT_SERVICE_PROPERTIES(nextservice);
2630 mlt_type = mlt_properties_get(properties, "mlt_type");
2631 resource = mlt_properties_get(properties, "mlt_service");
2633 m_isBlocked = false;
2634 mlt_service_unlock(service.get_service());
2635 m_mltConsumer->set("refresh", 1);
2639 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2640 Mlt::Service service(m_mltProducer->parent().get_service());
2641 Mlt::Tractor tractor(service);
2643 mlt_service_lock(service.get_service());
2644 m_mltConsumer->set("refresh", 0);
2647 mlt_service serv = m_mltProducer->parent().get_service();
2648 mlt_service nextservice = mlt_service_get_producer(serv);
2649 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2650 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2651 QString resource = mlt_properties_get(properties, "mlt_service");
2653 while (mlt_type == "transition") {
2654 mlt_transition tr = (mlt_transition) nextservice;
2655 int currentTrack = mlt_transition_get_b_track(tr);
2656 int currentaTrack = mlt_transition_get_a_track(tr);
2657 int currentIn = (int) mlt_transition_get_in(tr);
2658 int currentOut = (int) mlt_transition_get_out(tr);
2659 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2660 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2661 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2662 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2663 kDebug() << "//////MOVING";
2664 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2665 if (endTrack != startTrack) {
2666 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2667 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2668 mlt_properties_set_int(properties, "b_track", endTrack);
2672 nextservice = mlt_service_producer(nextservice);
2673 if (nextservice == NULL) break;
2674 properties = MLT_SERVICE_PROPERTIES(nextservice);
2675 mlt_type = mlt_properties_get(properties, "mlt_type");
2676 resource = mlt_properties_get(properties, "mlt_service");
2678 m_isBlocked = false;
2679 mlt_service_unlock(service.get_service());
2680 m_mltConsumer->set("refresh", 1);
2684 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2685 if (in >= out) return false;
2686 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2687 Mlt::Service service(m_mltProducer->parent().get_service());
2689 Mlt::Tractor tractor(service);
2690 Mlt::Field *field = tractor.field();
2692 char *transId = decodedString(tag);
2693 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2694 if (out != GenTime())
2695 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2696 QMap<QString, QString>::Iterator it;
2698 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2699 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2701 for (it = args.begin(); it != args.end(); ++it) {
2703 char *name = decodedString(key);
2704 char *value = decodedString(it.value());
2705 transition->set(name, value);
2706 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2707 //filter->set("kdenlive_id", id);
2711 // attach filter to the clip
2712 field->plant_transition(*transition, a_track, b_track);
2718 void Render::mltSavePlaylist() {
2719 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2720 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2721 fileConsumer.set("resource", "/tmp/playlist.westley");
2723 Mlt::Service service(m_mltProducer->get_service());
2725 fileConsumer.connect(service);
2726 fileConsumer.start();
2729 QList <Mlt::Producer *> Render::producersList() {
2730 QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
2731 Mlt::Service service(m_mltProducer->parent().get_service());
2732 if (service.type() != tractor_type) return prods;
2733 Mlt::Tractor tractor(service);
2736 int trackNb = tractor.count();
2737 for (int t = 1; t < trackNb; t++) {
2738 Mlt::Producer trackProducer(tractor.track(t));
2739 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2740 int clipNb = trackPlaylist.count();
2741 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2742 for (int i = 0; i < clipNb; i++) {
2743 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2744 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2745 ids.append(nprod->get("id"));
2746 prods.append(nprod);
2753 void Render::fillSlowMotionProducers() {
2754 Mlt::Service service(m_mltProducer->parent().get_service());
2755 if (service.type() != tractor_type) return;
2757 Mlt::Tractor tractor(service);
2759 int trackNb = tractor.count();
2760 for (int t = 1; t < trackNb; t++) {
2761 Mlt::Producer trackProducer(tractor.track(t));
2762 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2763 int clipNb = trackPlaylist.count();
2764 for (int i = 0; i < clipNb; i++) {
2765 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2766 if (nprod && !nprod->is_blank()) {
2767 QString id = nprod->get("id");
2768 if (id.startsWith("slowmotion:")) {
2769 // this is a slowmotion producer, add it to the list
2770 QString url = QString::fromUtf8(nprod->get("resource"));
2771 if (!m_slowmotionProducers.contains(url)) {
2772 m_slowmotionProducers.insert(url, nprod);
2780 void Render::mltInsertTrack(int ix, bool videoTrack) {
2784 m_mltConsumer->set("refresh", 0);
2785 mlt_service_lock(m_mltConsumer->get_service());
2786 Mlt::Service service(m_mltProducer->parent().get_service());
2787 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2789 Mlt::Tractor tractor(service);
2791 Mlt::Playlist playlist;// = new Mlt::Playlist();
2792 int ct = tractor.count();
2793 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2796 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2797 tractor.set_track(playlist, pos);
2798 Mlt::Producer newProd(tractor.track(pos));
2799 if (!videoTrack) newProd.set("hide", 1);
2801 for (; pos <= ct; pos++) {
2802 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2803 tractor.set_track(*prodToMove, pos);
2804 prodToMove = prodToMove2;
2807 tractor.set_track(playlist, ix);
2808 Mlt::Producer newProd(tractor.track(ix));
2809 if (!videoTrack) newProd.set("hide", 1);
2813 mlt_service serv = m_mltProducer->parent().get_service();
2814 mlt_service nextservice = mlt_service_get_producer(serv);
2815 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2816 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2817 QString resource = mlt_properties_get(properties, "mlt_service");
2819 while (mlt_type == "transition") {
2820 if (resource != "mix") {
2821 mlt_transition tr = (mlt_transition) nextservice;
2822 int currentTrack = mlt_transition_get_b_track(tr);
2823 int currentaTrack = mlt_transition_get_a_track(tr);
2824 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2826 if (currentTrack >= ix) {
2827 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2828 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2831 nextservice = mlt_service_producer(nextservice);
2832 if (nextservice == NULL) break;
2833 properties = MLT_SERVICE_PROPERTIES(nextservice);
2834 mlt_type = mlt_properties_get(properties, "mlt_type");
2835 resource = mlt_properties_get(properties, "mlt_service");
2838 // Add audio mix transition to last track
2839 Mlt::Field *field = tractor.field();
2840 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2841 //transition->set("mlt_service", "mix");
2842 transition->set("a_track", 1);
2843 transition->set("b_track", ct);
2844 transition->set("always_active", 1);
2845 transition->set("internal_added", 237);
2846 transition->set("combine", 1);
2847 field->plant_transition(*transition, 1, ct);
2849 mlt_service_unlock(m_mltConsumer->get_service());
2850 m_isBlocked = false;
2851 blockSignals(false);
2855 void Render::mltDeleteTrack(int ix) {
2857 doc.setContent(sceneList(), false);
2858 int tracksCount = doc.elementsByTagName("track").count() - 1;
2859 QDomNode track = doc.elementsByTagName("track").at(ix);
2860 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2861 QDomNodeList transitions = doc.elementsByTagName("transition");
2862 for (int i = 0; i < transitions.count(); i++) {
2863 QDomElement e = transitions.at(i).toElement();
2864 QDomNodeList props = e.elementsByTagName("property");
2865 QMap <QString, QString> mappedProps;
2866 for (int j = 0; j < props.count(); j++) {
2867 QDomElement f = props.at(j).toElement();
2868 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2870 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2871 tractor.removeChild(transitions.at(i));
2872 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2873 // Transition needs to be moved
2874 int a_track = mappedProps.value("a_track").toInt();
2875 int b_track = mappedProps.value("b_track").toInt();
2876 if (a_track > 0) a_track --;
2877 if (b_track > 0) b_track --;
2878 for (int j = 0; j < props.count(); j++) {
2879 QDomElement f = props.at(j).toElement();
2880 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2881 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2886 tractor.removeChild(track);
2887 setSceneList(doc.toString(), m_framePosition);
2894 m_mltConsumer->set("refresh", 0);
2895 mlt_service_lock(m_mltConsumer->get_service());
2896 Mlt::Service service(m_mltProducer->parent().get_service());
2897 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2899 /*Mlt::Tractor tractor(service);
2902 Mlt::Multitrack *multi = tractor.multitrack();
2905 int ct = tractor.count();
2906 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
2908 for (; pos < ct ; pos++) {
2909 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
2910 //mlt_service_close(lastTrack->get_service());
2912 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
2913 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
2914 mlt_service_close(prodToMove->get_service());
2915 mlt_service_close(prodToClose->get_service());
2916 tractor.set_track(*prodToMove, pos);
2920 /*mlt_service serv = m_mltProducer->parent().get_service();
2921 mlt_service nextservice = mlt_service_get_producer(serv);
2922 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2923 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2924 QString resource = mlt_properties_get(properties, "mlt_service");
2926 while (mlt_type == "transition") {
2927 if (resource != "mix") {
2928 mlt_transition tr = (mlt_transition) nextservice;
2929 int currentTrack = mlt_transition_get_b_track(tr);
2930 int currentaTrack = mlt_transition_get_a_track(tr);
2931 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2933 if (currentTrack >= ix) {
2934 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2935 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2938 nextservice = mlt_service_producer(nextservice);
2939 if (nextservice == NULL) break;
2940 properties = MLT_SERVICE_PROPERTIES(nextservice);
2941 mlt_type = mlt_properties_get(properties, "mlt_type");
2942 resource = mlt_properties_get(properties, "mlt_service");
2945 // Add audio mix transition to last track
2946 Mlt::Field *field = tractor.field();
2947 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2948 //transition->set("mlt_service", "mix");
2949 transition->set("a_track", 1);
2950 transition->set("b_track", ct);
2951 transition->set("always_active", 1);
2952 transition->set("internal_added", 237);
2953 transition->set("combine", 1);
2954 field->plant_transition(*transition, 1, ct);
2957 mlt_service_unlock(m_mltConsumer->get_service());
2958 m_isBlocked = false;
2959 blockSignals(false);
2963 void Render::updatePreviewSettings() {
2964 kDebug() << "////// RESTARTING CONSUMER";
2965 if (!m_mltConsumer || !m_mltProducer) return;
2966 if (m_mltProducer->get_playtime() == 0) return;
2967 Mlt::Service service(m_mltProducer->parent().get_service());
2968 if (service.type() != tractor_type) return;
2970 //m_mltConsumer->set("refresh", 0);
2971 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
2972 m_mltConsumer->purge();
2973 QString scene = sceneList();
2975 if (m_mltProducer) {
2976 pos = m_mltProducer->position();
2977 delete m_mltProducer;
2979 m_mltProducer = NULL;
2980 setSceneList(scene, pos);
2983 #include "renderer.moc"