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.remove_region(0, (int)blackDuration);
1272 int dur = (int)duration;
1274 QDomElement black = doc.createElement("producer");
1275 black.setAttribute("mlt_service", "colour");
1276 black.setAttribute("colour", "black");
1277 black.setAttribute("id", "black");
1280 while (dur > 14000) {
1281 info.startPos = GenTime(i * 14000, m_fps);
1282 info.endPos = info.startPos + GenTime(13999, m_fps);
1283 mltInsertClip(info, black, m_blackClip);
1288 info.startPos = GenTime(i * 14000, m_fps);
1289 info.endPos = info.startPos + GenTime(dur, m_fps);
1290 mltInsertClip(info, black, m_blackClip);
1292 m_mltProducer->set("out", duration);
1293 emit durationChanged((int)duration);
1297 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1298 if (!m_mltProducer) {
1299 kDebug() << "PLAYLIST NOT INITIALISED //////";
1302 Mlt::Producer parentProd(m_mltProducer->parent());
1303 if (parentProd.get_producer() == NULL) {
1304 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1308 Mlt::Service service(parentProd.get_service());
1309 Mlt::Tractor tractor(service);
1310 mlt_service_lock(service.get_service());
1311 Mlt::Producer trackProducer(tractor.track(info.track));
1312 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1313 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1315 if (element.attribute("speed", "1.0").toDouble() != 1.0) {
1316 // We want a slowmotion producer
1317 double speed = element.attribute("speed", "1.0").toDouble();
1318 QString url = QString::fromUtf8(prod->get("resource"));
1319 url.append('?' + QString::number(speed));
1320 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1321 if (!slowprod || slowprod->get_producer() == NULL) {
1322 char *tmp = decodedString(url);
1323 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1325 QString id = prod->get("id");
1326 if (id.contains('_')) id = id.section('_', 0, 0);
1327 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1328 tmp = decodedString(producerid);
1329 slowprod->set("id", tmp);
1331 m_slowmotionProducers.insert(url, slowprod);
1336 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1337 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1339 /*if (QString(prod->get("transparency")).toInt() == 1)
1340 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1342 mlt_service_unlock(service.get_service());
1344 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1345 //tractor.multitrack()->refresh();
1346 //tractor.refresh();
1350 void Render::mltCutClip(int track, GenTime position) {
1354 Mlt::Service service(m_mltProducer->parent().get_service());
1355 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1357 Mlt::Tractor tractor(service);
1358 Mlt::Producer trackProducer(tractor.track(track));
1359 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1362 /* // Display playlist info
1363 kDebug()<<"//////////// BEFORE";
1364 for (int i = 0; i < trackPlaylist.count(); i++) {
1365 int blankStart = trackPlaylist.clip_start(i);
1366 int blankDuration = trackPlaylist.clip_length(i) - 1;
1368 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1369 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1372 int cutPos = (int) position.frames(m_fps);
1374 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1375 if (trackPlaylist.is_blank(clipIndex)) {
1376 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1377 m_isBlocked = false;
1380 mlt_service_lock(service.get_service());
1381 int clipStart = trackPlaylist.clip_start(clipIndex);
1382 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1383 mlt_service_unlock(service.get_service());
1385 // duplicate effects
1386 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1387 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1389 if (original == NULL || clip == NULL) {
1390 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1392 Mlt::Service clipService(original->get_service());
1393 Mlt::Service dupService(clip->get_service());
1395 Mlt::Filter *filter = clipService.filter(ct);
1397 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1398 // looks like there is no easy way to duplicate a filter,
1399 // so we will create a new one and duplicate its properties
1400 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1401 if (dup && dup->is_valid()) {
1402 Mlt::Properties entries(filter->get_properties());
1403 for (int i = 0;i < entries.count();i++) {
1404 dup->set(entries.get_name(i), entries.get(i));
1406 dupService.attach(*dup);
1410 filter = clipService.filter(ct);
1413 /* // Display playlist info
1414 kDebug()<<"//////////// AFTER";
1415 for (int i = 0; i < trackPlaylist.count(); i++) {
1416 int blankStart = trackPlaylist.clip_start(i);
1417 int blankDuration = trackPlaylist.clip_length(i) - 1;
1419 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1420 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1423 m_isBlocked = false;
1426 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1428 mltRemoveClip(info.track, info.startPos);
1429 mltInsertClip(info, element, prod);
1433 bool Render::mltRemoveClip(int track, GenTime position) {
1434 Mlt::Service service(m_mltProducer->parent().get_service());
1435 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1437 Mlt::Tractor tractor(service);
1438 Mlt::Producer trackProducer(tractor.track(track));
1439 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1440 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1442 /* // Display playlist info
1443 kDebug()<<"//// BEFORE";
1444 for (int i = 0; i < trackPlaylist.count(); i++) {
1445 int blankStart = trackPlaylist.clip_start(i);
1446 int blankDuration = trackPlaylist.clip_length(i) - 1;
1448 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1449 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1452 if (trackPlaylist.is_blank(clipIndex)) {
1453 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1457 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1458 trackPlaylist.replace_with_blank(clipIndex);
1459 trackPlaylist.consolidate_blanks(0);
1460 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1461 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1463 /* // Display playlist info
1464 kDebug()<<"//// AFTER";
1465 for (int i = 0; i < trackPlaylist.count(); i++) {
1466 int blankStart = trackPlaylist.clip_start(i);
1467 int blankDuration = trackPlaylist.clip_length(i) - 1;
1469 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1470 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1473 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1474 m_isBlocked = false;
1478 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
1479 if (!m_mltProducer) {
1480 kDebug() << "PLAYLIST NOT INITIALISED //////";
1483 Mlt::Producer parentProd(m_mltProducer->parent());
1484 if (parentProd.get_producer() == NULL) {
1485 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1489 Mlt::Service service(parentProd.get_service());
1490 Mlt::Tractor tractor(service);
1491 int insertPos = pos.frames(m_fps);
1493 Mlt::Producer trackProducer(tractor.track(track));
1494 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1495 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1496 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1497 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1498 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1502 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
1503 if (!m_mltProducer) {
1504 kDebug() << "PLAYLIST NOT INITIALISED //////";
1507 Mlt::Producer parentProd(m_mltProducer->parent());
1508 if (parentProd.get_producer() == NULL) {
1509 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1512 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1513 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1515 Mlt::Service service(parentProd.get_service());
1516 Mlt::Tractor tractor(service);
1517 mlt_service_lock(service.get_service());
1518 int diff = duration.frames(m_fps);
1519 int offset = timeOffset.frames(m_fps);
1523 // insert space in one track only
1524 Mlt::Producer trackProducer(tractor.track(track));
1525 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1526 insertPos = trackClipStartList.value(track);
1527 if (insertPos != -1) {
1528 insertPos += offset;
1529 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1530 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1532 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1533 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1534 int position = trackPlaylist.clip_start(clipIndex);
1535 trackPlaylist.remove_region(position, - diff - 1);
1537 trackPlaylist.consolidate_blanks(0);
1539 // now move transitions
1540 mlt_service serv = m_mltProducer->parent().get_service();
1541 mlt_service nextservice = mlt_service_get_producer(serv);
1542 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1543 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1544 QString resource = mlt_properties_get(properties, "mlt_service");
1546 while (mlt_type == "transition") {
1547 mlt_transition tr = (mlt_transition) nextservice;
1548 int currentTrack = mlt_transition_get_b_track(tr);
1549 int currentIn = (int) mlt_transition_get_in(tr);
1550 int currentOut = (int) mlt_transition_get_out(tr);
1551 insertPos = trackTransitionStartList.value(track);
1552 if (insertPos != -1) {
1553 insertPos += offset;
1554 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1555 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1558 nextservice = mlt_service_producer(nextservice);
1559 if (nextservice == NULL) break;
1560 properties = MLT_SERVICE_PROPERTIES(nextservice);
1561 mlt_type = mlt_properties_get(properties, "mlt_type");
1562 resource = mlt_properties_get(properties, "mlt_service");
1565 int trackNb = tractor.count();
1566 while (trackNb > 1) {
1567 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1568 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1571 //int clipNb = trackPlaylist.count();
1572 insertPos = trackClipStartList.value(trackNb - 1);
1573 if (insertPos != -1) {
1574 insertPos += offset;
1576 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1577 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1578 for (int i = 0; i < clipNb; i++) {
1579 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1580 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1581 kDebug()<<"-------------";
1583 kDebug()<<"END-------------";*/
1586 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1587 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1589 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1590 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1591 int position = trackPlaylist.clip_start(clipIndex);
1592 trackPlaylist.remove_region(position, - diff - 1);
1594 trackPlaylist.consolidate_blanks(0);
1598 // now move transitions
1599 mlt_service serv = m_mltProducer->parent().get_service();
1600 mlt_service nextservice = mlt_service_get_producer(serv);
1601 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1602 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1603 QString resource = mlt_properties_get(properties, "mlt_service");
1605 while (mlt_type == "transition") {
1606 mlt_transition tr = (mlt_transition) nextservice;
1607 int currentIn = (int) mlt_transition_get_in(tr);
1608 int currentOut = (int) mlt_transition_get_out(tr);
1609 int currentTrack = mlt_transition_get_b_track(tr);
1610 insertPos = trackTransitionStartList.value(currentTrack);
1611 if (insertPos != -1) {
1612 insertPos += offset;
1613 if (currentOut > insertPos && resource != "mix") {
1614 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1617 nextservice = mlt_service_producer(nextservice);
1618 if (nextservice == NULL) break;
1619 properties = MLT_SERVICE_PROPERTIES(nextservice);
1620 mlt_type = mlt_properties_get(properties, "mlt_type");
1621 resource = mlt_properties_get(properties, "mlt_service");
1624 mlt_service_unlock(service.get_service());
1626 m_mltConsumer->set("refresh", 1);
1629 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
1632 Mlt::Service service(m_mltProducer->parent().get_service());
1633 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1634 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1635 Mlt::Tractor tractor(service);
1636 Mlt::Producer trackProducer(tractor.track(info.track));
1637 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1638 int startPos = info.startPos.frames(m_fps);
1639 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1640 int clipLength = trackPlaylist.clip_length(clipIndex);
1642 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1643 if (!clip.is_valid() || clip.is_blank()) {
1647 Mlt::Producer clipparent = clip.parent();
1648 if (!clipparent.is_valid() || clipparent.is_blank()) {
1652 QString serv = clipparent.get("mlt_service");
1653 QString id = clipparent.get("id");
1654 //kDebug() << "CLIP SERVICE: " << serv;
1655 if (serv == "avformat" && speed != 1.0) {
1656 mlt_service_lock(service.get_service());
1657 QString url = QString::fromUtf8(clipparent.get("resource"));
1658 url.append('?' + QString::number(speed));
1659 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1660 if (!slowprod || slowprod->get_producer() == NULL) {
1661 char *tmp = decodedString(url);
1662 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1664 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1665 tmp = decodedString(producerid);
1666 slowprod->set("id", tmp);
1668 m_slowmotionProducers.insert(url, slowprod);
1670 trackPlaylist.replace_with_blank(clipIndex);
1671 trackPlaylist.consolidate_blanks(0);
1672 // Check that the blank space is long enough for our new duration
1673 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1674 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1676 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1677 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1678 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1679 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1680 trackPlaylist.insert_at(startPos, *cut, 1);
1681 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1682 newLength = trackPlaylist.clip_length(clipIndex);
1683 mlt_service_unlock(service.get_service());
1684 } else if (speed == 1.0) {
1685 mlt_service_lock(service.get_service());
1687 trackPlaylist.replace_with_blank(clipIndex);
1688 trackPlaylist.consolidate_blanks(0);
1690 // Check that the blank space is long enough for our new duration
1691 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1692 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1695 GenTime oldDuration = GenTime(clipLength, m_fps);
1696 GenTime newDuration = oldDuration * oldspeed;
1697 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1698 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1699 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1700 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1701 trackPlaylist.insert_at(startPos, *cut, 1);
1702 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1703 newLength = trackPlaylist.clip_length(clipIndex);
1704 mlt_service_unlock(service.get_service());
1706 } else if (serv == "framebuffer") {
1707 mlt_service_lock(service.get_service());
1708 QString url = QString::fromUtf8(clipparent.get("resource"));
1709 url = url.section('?', 0, 0);
1710 url.append('?' + QString::number(speed));
1711 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1712 if (!slowprod || slowprod->get_producer() == NULL) {
1713 char *tmp = decodedString(url);
1714 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1716 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
1717 tmp = decodedString(producerid);
1718 slowprod->set("id", tmp);
1720 m_slowmotionProducers.insert(url, slowprod);
1722 trackPlaylist.replace_with_blank(clipIndex);
1723 trackPlaylist.consolidate_blanks(0);
1725 GenTime oldDuration = GenTime(clipLength, m_fps);
1726 GenTime newDuration = oldDuration * oldspeed / speed;
1728 // Check that the blank space is long enough for our new duration
1729 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1730 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1733 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1734 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1735 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1736 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1738 trackPlaylist.insert_at(startPos, *cut, 1);
1739 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1740 newLength = trackPlaylist.clip_length(clipIndex);
1742 mlt_service_unlock(service.get_service());
1744 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1745 m_isBlocked = false;
1749 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh) {
1750 kDebug() << "// TRYing to remove effect at: " << index;
1751 Mlt::Service service(m_mltProducer->parent().get_service());
1752 bool success = false;
1753 Mlt::Tractor tractor(service);
1754 Mlt::Producer trackProducer(tractor.track(track));
1755 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1756 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1757 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1759 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1762 Mlt::Service clipService(clip->get_service());
1763 // if (tag.startsWith("ladspa")) tag = "ladspa";
1766 Mlt::Filter *filter = clipService.filter(ct);
1768 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1769 if (clipService.detach(*filter) == 0) success = true;
1770 kDebug() << " / / / DLEETED EFFECT: " << ct;
1771 } else if (updateIndex) {
1772 // Adjust the other effects index
1773 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1776 filter = clipService.filter(ct);
1778 m_isBlocked = false;
1779 if (doRefresh) refresh();
1784 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
1786 Mlt::Service service(m_mltProducer->parent().get_service());
1788 Mlt::Tractor tractor(service);
1789 Mlt::Producer trackProducer(tractor.track(track));
1790 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1792 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1796 Mlt::Service clipService(clip->get_service());
1799 // temporarily remove all effects after insert point
1800 QList <Mlt::Filter *> filtersList;
1801 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1803 Mlt::Filter *filter = clipService.filter(ct);
1805 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1806 filtersList.append(filter);
1807 clipService.detach(*filter);
1809 filter = clipService.filter(ct);
1813 QString tag = params.paramValue("tag");
1814 kDebug() << " / / INSERTING EFFECT: " << tag;
1815 if (tag.startsWith("ladspa")) tag = "ladspa";
1816 char *filterTag = decodedString(tag);
1817 char *filterId = decodedString(params.paramValue("id"));
1818 QHash<QString, QString>::Iterator it;
1819 QString kfr = params.paramValue("keyframes");
1821 if (!kfr.isEmpty()) {
1822 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
1823 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1824 char *starttag = decodedString(params.paramValue("starttag", "start"));
1825 char *endtag = decodedString(params.paramValue("endtag", "end"));
1826 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1827 int duration = clip->get_playtime();
1828 //double max = params.paramValue("max").toDouble();
1829 double min = params.paramValue("min").toDouble();
1830 double factor = params.paramValue("factor", "1").toDouble();
1831 params.removeParam("starttag");
1832 params.removeParam("endtag");
1833 params.removeParam("keyframes");
1834 params.removeParam("min");
1835 params.removeParam("max");
1836 params.removeParam("factor");
1838 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1839 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1840 if (filter && filter->is_valid()) {
1841 filter->set("kdenlive_id", filterId);
1842 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
1843 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
1844 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
1845 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
1846 if (x2 == -1) x2 = duration;
1848 for (int j = 0; j < params.count(); j++) {
1849 char *name = decodedString(params.at(j).name());
1850 char *value = decodedString(params.at(j).value());
1851 filter->set(name, value);
1856 filter->set("in", x1);
1857 filter->set("out", x2);
1858 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1859 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1860 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1861 clipService.attach(*filter);
1868 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1869 if (filter && filter->is_valid())
1870 filter->set("kdenlive_id", filterId);
1872 kDebug() << "filter is NULL";
1873 m_isBlocked = false;
1877 params.removeParam("kdenlive_id");
1879 for (int j = 0; j < params.count(); j++) {
1880 char *name = decodedString(params.at(j).name());
1881 char *value = decodedString(params.at(j).value());
1882 filter->set(name, value);
1888 QString effectArgs = params.paramValue("id").section('_', 1);
1890 params.removeParam("id");
1891 params.removeParam("kdenlive_ix");
1892 params.removeParam("tag");
1893 params.removeParam("disabled");
1895 for (int j = 0; j < params.count(); j++) {
1896 effectArgs.append(' ' + params.at(j).value());
1898 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1899 char *value = decodedString(effectArgs.simplified());
1900 filter->set("effect", value);
1905 // attach filter to the clip
1906 clipService.attach(*filter);
1911 // re-add following filters
1912 for (int i = 0; i < filtersList.count(); i++) {
1913 clipService.attach(*(filtersList.at(i)));
1916 m_isBlocked = false;
1917 if (doRefresh) refresh();
1921 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
1922 QString index = params.paramValue("kdenlive_ix");
1923 QString tag = params.paramValue("tag");
1925 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1926 // This is a keyframe effect, to edit it, we remove it and re-add it.
1927 mltRemoveEffect(track, position, index, true);
1928 bool success = mltAddEffect(track, position, params);
1933 Mlt::Service service(m_mltProducer->parent().get_service());
1935 Mlt::Tractor tractor(service);
1936 Mlt::Producer trackProducer(tractor.track(track));
1937 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1938 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1939 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1941 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1944 Mlt::Service clipService(clip->get_service());
1947 Mlt::Filter *filter = clipService.filter(ct);
1949 if (filter->get("kdenlive_ix") == index) {
1953 filter = clipService.filter(ct);
1957 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1958 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1960 filter = clipService.filter(ct);
1961 QList <Mlt::Filter *> filtersList;
1963 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1964 filtersList.append(filter);
1965 clipService.detach(*filter);
1967 filter = clipService.filter(ct);
1969 bool success = mltAddEffect(track, position, params);
1971 for (int i = 0; i < filtersList.count(); i++) {
1972 clipService.attach(*(filtersList.at(i)));
1975 m_isBlocked = false;
1979 for (int j = 0; j < params.count(); j++) {
1980 char *name = decodedString(params.at(j).name());
1981 char *value = decodedString(params.at(j).value());
1982 filter->set(name, value);
1987 m_isBlocked = false;
1992 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1994 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1995 Mlt::Service service(m_mltProducer->parent().get_service());
1997 Mlt::Tractor tractor(service);
1998 Mlt::Producer trackProducer(tractor.track(track));
1999 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2000 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2001 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2003 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2006 Mlt::Service clipService(clip->get_service());
2009 QList <Mlt::Filter *> filtersList;
2010 Mlt::Filter *filter = clipService.filter(ct);
2012 if (newPos > oldPos) {
2014 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2015 filter->set("kdenlive_ix", newPos);
2016 filtersList.append(filter);
2017 clipService.detach(*filter);
2018 filter = clipService.filter(ct);
2019 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2020 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2022 filter = clipService.filter(ct);
2026 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2027 filtersList.append(filter);
2028 clipService.detach(*filter);
2030 filter = clipService.filter(ct);
2034 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2035 filter->set("kdenlive_ix", newPos);
2036 filtersList.append(filter);
2037 clipService.detach(*filter);
2039 filter = clipService.filter(ct);
2043 filter = clipService.filter(ct);
2045 int pos = QString(filter->get("kdenlive_ix")).toInt();
2046 if (pos >= newPos) {
2047 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2048 filtersList.append(filter);
2049 clipService.detach(*filter);
2051 filter = clipService.filter(ct);
2055 for (int i = 0; i < filtersList.count(); i++) {
2056 clipService.attach(*(filtersList.at(i)));
2059 m_isBlocked = false;
2063 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
2066 Mlt::Service service(m_mltProducer->parent().get_service());
2068 Mlt::Tractor tractor(service);
2069 Mlt::Producer trackProducer(tractor.track(info.track));
2070 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2072 /* // Display playlist info
2073 kDebug()<<"//////////// BEFORE RESIZE";
2074 for (int i = 0; i < trackPlaylist.count(); i++) {
2075 int blankStart = trackPlaylist.clip_start(i);
2076 int blankDuration = trackPlaylist.clip_length(i) - 1;
2078 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2079 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2082 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2083 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2084 m_isBlocked = false;
2087 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2088 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2089 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2090 int previousStart = clip->get_in();
2091 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2092 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2093 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2094 trackPlaylist.consolidate_blanks(0);
2095 // skip to next clip
2097 int diff = newDuration - previousDuration;
2098 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2100 // clip was made longer, trim next blank if there is one.
2101 if (clipIndex < trackPlaylist.count()) {
2102 // If this is not the last clip in playlist
2103 if (trackPlaylist.is_blank(clipIndex)) {
2104 int blankStart = trackPlaylist.clip_start(clipIndex);
2105 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2106 if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2107 if (diff - blankDuration == 1) {
2108 trackPlaylist.remove(clipIndex);
2109 } else trackPlaylist.remove_region(blankStart, diff - 1);
2111 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2114 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2116 trackPlaylist.consolidate_blanks(0);
2119 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2120 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2121 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2122 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2123 ItemInfo transpinfo;
2124 transpinfo.startPos = info.startPos;
2125 transpinfo.endPos = info.startPos + clipDuration;
2126 transpinfo.track = info.track;
2127 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2129 m_isBlocked = false;
2130 m_mltConsumer->set("refresh", 1);
2134 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
2135 Mlt::Service service(m_mltProducer->parent().get_service());
2136 Mlt::Tractor tractor(service);
2137 Mlt::Producer trackProducer(tractor.track(track));
2140 if (blind) trackProducer.set("hide", 3);
2141 else trackProducer.set("hide", 2);
2143 trackProducer.set("hide", 1);
2145 trackProducer.set("hide", 0);
2147 tractor.multitrack()->refresh();
2153 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) {
2154 Mlt::Service service(m_mltProducer->parent().get_service());
2155 int frameOffset = (int) diff.frames(m_fps);
2156 Mlt::Tractor tractor(service);
2157 Mlt::Producer trackProducer(tractor.track(info.track));
2158 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2159 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2160 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2163 mlt_service_lock(service.get_service());
2164 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2165 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2167 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2168 mlt_service_unlock(service.get_service());
2171 int previousStart = clip->get_in();
2172 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2174 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2175 m_isBlocked = false;
2176 mlt_service_unlock(service.get_service());
2177 m_mltConsumer->set("refresh", 1);
2181 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
2182 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2183 Mlt::Service service(m_mltProducer->parent().get_service());
2184 int moveFrame = (int) diff.frames(m_fps);
2185 Mlt::Tractor tractor(service);
2186 Mlt::Producer trackProducer(tractor.track(info.track));
2187 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2188 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2189 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2192 mlt_service_lock(service.get_service());
2193 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2194 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2196 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2197 mlt_service_unlock(service.get_service());
2200 int previousStart = clip->get_in();
2201 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2203 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2204 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2205 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2207 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2208 int blankIndex = clipIndex - 1;
2209 int blankLength = trackPlaylist.clip_length(blankIndex);
2210 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2211 if (! trackPlaylist.is_blank(blankIndex)) {
2212 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2214 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2215 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2217 trackPlaylist.consolidate_blanks(0);
2218 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2219 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2220 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2221 ItemInfo transpinfo;
2222 transpinfo.startPos = info.startPos + diff;
2223 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2224 transpinfo.track = info.track;
2225 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2227 m_isBlocked = false;
2228 //m_mltConsumer->set("refresh", 1);
2229 mlt_service_unlock(service.get_service());
2230 m_mltConsumer->set("refresh", 1);
2234 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
2235 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2239 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
2240 if (prod == NULL || !prod->is_valid()) {
2241 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2244 kDebug() << "NEW PROD ID: " << prod->get("id");
2245 m_mltConsumer->set("refresh", 0);
2246 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2247 mlt_service_lock(m_mltConsumer->get_service());
2248 Mlt::Service service(m_mltProducer->parent().get_service());
2249 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2251 Mlt::Tractor tractor(service);
2252 Mlt::Producer trackProducer(tractor.track(track));
2253 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2254 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2255 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2256 if (clipProducer.is_blank()) {
2257 kDebug() << "// ERROR UPDATING CLIP PROD";
2258 mlt_service_unlock(m_mltConsumer->get_service());
2259 m_isBlocked = false;
2262 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2264 // move all effects to the correct producer
2265 Mlt::Service clipService(clipProducer.get_service());
2266 Mlt::Service newClipService(clip->get_service());
2269 Mlt::Filter *filter = clipService.filter(ct);
2271 if (filter->get("kdenlive_ix") != 0) {
2272 clipService.detach(*filter);
2273 newClipService.attach(*filter);
2275 filter = clipService.filter(ct);
2278 trackPlaylist.insert_at(pos, clip, 1);
2279 mlt_service_unlock(m_mltConsumer->get_service());
2280 m_isBlocked = false;
2283 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
2286 m_mltConsumer->set("refresh", 0);
2287 mlt_service_lock(m_mltConsumer->get_service());
2288 Mlt::Service service(m_mltProducer->parent().get_service());
2289 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2291 Mlt::Tractor tractor(service);
2292 Mlt::Producer trackProducer(tractor.track(startTrack));
2293 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2294 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2295 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2296 bool checkLength = false;
2297 if (endTrack == startTrack) {
2298 //mlt_service_lock(service.get_service());
2299 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2300 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2301 // error, destination is not empty
2302 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2303 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2304 mlt_service_unlock(m_mltConsumer->get_service());
2305 m_isBlocked = false;
2308 trackPlaylist.consolidate_blanks(0);
2309 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2310 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2311 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2313 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2315 //mlt_service_unlock(service.get_service());
2317 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2318 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2319 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2320 // error, destination is not empty
2321 mlt_service_unlock(m_mltConsumer->get_service());
2322 m_isBlocked = false;
2325 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2326 if (clipProducer.is_blank()) {
2327 // error, destination is not empty
2328 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2329 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2330 mlt_service_unlock(m_mltConsumer->get_service());
2331 m_isBlocked = false;
2334 trackPlaylist.consolidate_blanks(0);
2335 destTrackPlaylist.consolidate_blanks(1);
2336 Mlt::Producer *clip;
2337 // check if we are moving a slowmotion producer
2338 QString serv = clipProducer.parent().get("mlt_service");
2339 if (serv == "framebuffer") {
2340 clip = &clipProducer;
2341 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2343 // move all effects to the correct producer
2344 Mlt::Service clipService(clipProducer.get_service());
2345 Mlt::Service newClipService(clip->get_service());
2348 Mlt::Filter *filter = clipService.filter(ct);
2350 if (filter->get("kdenlive_ix") != 0) {
2351 clipService.detach(*filter);
2352 newClipService.attach(*filter);
2354 filter = clipService.filter(ct);
2357 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2358 destTrackPlaylist.consolidate_blanks(0);
2359 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2360 kDebug() << "//////// moving clip transparency";
2361 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2363 if (clipIndex > trackPlaylist.count()) checkLength = true;
2364 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2368 if (checkLength) mltCheckLength();
2369 mlt_service_unlock(m_mltConsumer->get_service());
2370 m_isBlocked = false;
2371 m_mltConsumer->set("refresh", 1);
2375 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
2376 int new_in = (int)newIn.frames(m_fps);
2377 int new_out = (int)newOut.frames(m_fps) - 1;
2378 if (new_in >= new_out) return false;
2380 Mlt::Service service(m_mltProducer->parent().get_service());
2381 Mlt::Tractor tractor(service);
2383 mlt_service_lock(service.get_service());
2384 m_mltConsumer->set("refresh", 0);
2387 mlt_service serv = m_mltProducer->parent().get_service();
2388 mlt_service nextservice = mlt_service_get_producer(serv);
2389 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2390 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2391 QString resource = mlt_properties_get(properties, "mlt_service");
2392 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2394 while (mlt_type == "transition") {
2395 mlt_transition tr = (mlt_transition) nextservice;
2396 int currentTrack = mlt_transition_get_b_track(tr);
2397 int currentIn = (int) mlt_transition_get_in(tr);
2398 int currentOut = (int) mlt_transition_get_out(tr);
2400 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2401 mlt_transition_set_in_and_out(tr, new_in, new_out);
2402 if (newTrack - startTrack != 0) {
2403 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2405 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2406 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2407 mlt_properties_set_int(properties, "b_track", newTrack);
2408 //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);
2412 nextservice = mlt_service_producer(nextservice);
2413 if (nextservice == NULL) break;
2414 properties = MLT_SERVICE_PROPERTIES(nextservice);
2415 mlt_type = mlt_properties_get(properties, "mlt_type");
2416 resource = mlt_properties_get(properties, "mlt_service");
2418 m_isBlocked = false;
2419 mlt_service_unlock(service.get_service());
2420 m_mltConsumer->set("refresh", 1);
2424 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2425 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2426 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2428 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2429 mltAddTransition(tag, a_track, b_track, in, out, xml);
2431 //mltSavePlaylist();
2434 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2436 Mlt::Service service(m_mltProducer->parent().get_service());
2437 Mlt::Tractor tractor(service);
2439 //m_mltConsumer->set("refresh", 0);
2440 mlt_service serv = m_mltProducer->parent().get_service();
2442 mlt_service nextservice = mlt_service_get_producer(serv);
2443 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2444 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2445 QString resource = mlt_properties_get(properties, "mlt_service");
2446 int in_pos = (int) in.frames(m_fps);
2447 int out_pos = (int) out.frames(m_fps) - 1;
2449 while (mlt_type == "transition") {
2450 mlt_transition tr = (mlt_transition) nextservice;
2451 int currentTrack = mlt_transition_get_b_track(tr);
2452 int currentBTrack = mlt_transition_get_a_track(tr);
2453 int currentIn = (int) mlt_transition_get_in(tr);
2454 int currentOut = (int) mlt_transition_get_out(tr);
2456 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2458 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2459 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2460 QMap<QString, QString>::Iterator it;
2462 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2463 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2464 if (currentBTrack != a_track) {
2465 mlt_properties_set_int(properties, "a_track", a_track);
2467 for (it = map.begin(); it != map.end(); ++it) {
2469 char *name = decodedString(key);
2470 char *value = decodedString(it.value());
2471 mlt_properties_set(transproperties, name, value);
2472 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2473 //filter->set("kdenlive_id", id);
2479 nextservice = mlt_service_producer(nextservice);
2480 if (nextservice == NULL) break;
2481 properties = MLT_SERVICE_PROPERTIES(nextservice);
2482 mlt_type = mlt_properties_get(properties, "mlt_type");
2483 resource = mlt_properties_get(properties, "mlt_service");
2485 m_isBlocked = false;
2486 m_mltConsumer->set("refresh", 1);
2489 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2490 Mlt::Service service(m_mltProducer->parent().get_service());
2491 Mlt::Tractor tractor(service);
2492 Mlt::Field *field = tractor.field();
2494 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2495 mlt_service serv = m_mltProducer->parent().get_service();
2497 mlt_service nextservice = mlt_service_get_producer(serv);
2498 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2499 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2500 QString resource = mlt_properties_get(properties, "mlt_service");
2502 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2504 while (mlt_type == "transition") {
2505 mlt_transition tr = (mlt_transition) nextservice;
2506 int currentTrack = mlt_transition_get_b_track(tr);
2507 int currentIn = (int) mlt_transition_get_in(tr);
2508 int currentOut = (int) mlt_transition_get_out(tr);
2509 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2511 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2512 mlt_field_disconnect_service(field->get_field(), nextservice);
2515 nextservice = mlt_service_producer(nextservice);
2516 if (nextservice == NULL) break;
2517 properties = MLT_SERVICE_PROPERTIES(nextservice);
2518 mlt_type = mlt_properties_get(properties, "mlt_type");
2519 resource = mlt_properties_get(properties, "mlt_service");
2521 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2524 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2525 QDomNodeList attribs = xml.elementsByTagName("parameter");
2526 QMap<QString, QString> map;
2527 for (int i = 0;i < attribs.count();i++) {
2528 QDomElement e = attribs.item(i).toElement();
2529 QString name = e.attribute("name");
2530 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2531 map[name] = e.attribute("default");
2532 if (!e.attribute("value").isEmpty()) {
2533 map[name] = e.attribute("value");
2535 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2536 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2537 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2540 if (e.attribute("namedesc").contains(';')) {
2541 QString format = e.attribute("format");
2542 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2543 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2545 QTextStream txtNeu(&neu);
2546 if (values.size() > 0)
2547 txtNeu << (int)values[0].toDouble();
2549 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2550 txtNeu << separators[i];
2551 txtNeu << (int)(values[i+1].toDouble());
2553 if (i < separators.size())
2554 txtNeu << separators[i];
2555 map[e.attribute("name")] = neu;
2562 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2563 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2564 Mlt::Service service(m_mltProducer->parent().get_service());
2565 Mlt::Tractor tractor(service);
2566 Mlt::Field *field = tractor.field();
2568 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2569 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2570 transition->set("transparency", id);
2571 transition->set("fill", 1);
2572 transition->set("internal_added", 237);
2573 field->plant_transition(*transition, transitiontrack, info.track);
2577 void Render::mltDeleteTransparency(int pos, int track, int id) {
2578 Mlt::Service service(m_mltProducer->parent().get_service());
2579 Mlt::Tractor tractor(service);
2580 Mlt::Field *field = tractor.field();
2582 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2583 mlt_service serv = m_mltProducer->parent().get_service();
2585 mlt_service nextservice = mlt_service_get_producer(serv);
2586 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2587 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2588 QString resource = mlt_properties_get(properties, "mlt_service");
2590 while (mlt_type == "transition") {
2591 mlt_transition tr = (mlt_transition) nextservice;
2592 int currentTrack = mlt_transition_get_b_track(tr);
2593 int currentIn = (int) mlt_transition_get_in(tr);
2594 int currentOut = (int) mlt_transition_get_out(tr);
2595 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2596 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2598 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2599 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2600 mlt_field_disconnect_service(field->get_field(), nextservice);
2603 nextservice = mlt_service_producer(nextservice);
2604 if (nextservice == NULL) break;
2605 properties = MLT_SERVICE_PROPERTIES(nextservice);
2606 mlt_type = mlt_properties_get(properties, "mlt_type");
2607 resource = mlt_properties_get(properties, "mlt_service");
2609 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2612 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2613 Mlt::Service service(m_mltProducer->parent().get_service());
2614 Mlt::Tractor tractor(service);
2616 mlt_service_lock(service.get_service());
2617 m_mltConsumer->set("refresh", 0);
2620 mlt_service serv = m_mltProducer->parent().get_service();
2621 mlt_service nextservice = mlt_service_get_producer(serv);
2622 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2623 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2624 QString resource = mlt_properties_get(properties, "mlt_service");
2625 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
2626 while (mlt_type == "transition") {
2627 mlt_transition tr = (mlt_transition) nextservice;
2628 int currentTrack = mlt_transition_get_b_track(tr);
2629 int currentIn = (int) mlt_transition_get_in(tr);
2630 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2631 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2632 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
2633 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2634 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
2635 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2638 nextservice = mlt_service_producer(nextservice);
2639 if (nextservice == NULL) break;
2640 properties = MLT_SERVICE_PROPERTIES(nextservice);
2641 mlt_type = mlt_properties_get(properties, "mlt_type");
2642 resource = mlt_properties_get(properties, "mlt_service");
2644 m_isBlocked = false;
2645 mlt_service_unlock(service.get_service());
2646 m_mltConsumer->set("refresh", 1);
2650 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2651 Mlt::Service service(m_mltProducer->parent().get_service());
2652 Mlt::Tractor tractor(service);
2654 mlt_service_lock(service.get_service());
2655 m_mltConsumer->set("refresh", 0);
2658 mlt_service serv = m_mltProducer->parent().get_service();
2659 mlt_service nextservice = mlt_service_get_producer(serv);
2660 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2661 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2662 QString resource = mlt_properties_get(properties, "mlt_service");
2664 while (mlt_type == "transition") {
2665 mlt_transition tr = (mlt_transition) nextservice;
2666 int currentTrack = mlt_transition_get_b_track(tr);
2667 int currentaTrack = mlt_transition_get_a_track(tr);
2668 int currentIn = (int) mlt_transition_get_in(tr);
2669 int currentOut = (int) mlt_transition_get_out(tr);
2670 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2671 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2672 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
2673 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2674 kDebug() << "//////MOVING";
2675 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2676 if (endTrack != startTrack) {
2677 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2678 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2679 mlt_properties_set_int(properties, "b_track", endTrack);
2683 nextservice = mlt_service_producer(nextservice);
2684 if (nextservice == NULL) break;
2685 properties = MLT_SERVICE_PROPERTIES(nextservice);
2686 mlt_type = mlt_properties_get(properties, "mlt_type");
2687 resource = mlt_properties_get(properties, "mlt_service");
2689 m_isBlocked = false;
2690 mlt_service_unlock(service.get_service());
2691 m_mltConsumer->set("refresh", 1);
2695 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2696 if (in >= out) return false;
2697 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2698 Mlt::Service service(m_mltProducer->parent().get_service());
2700 Mlt::Tractor tractor(service);
2701 Mlt::Field *field = tractor.field();
2703 char *transId = decodedString(tag);
2704 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2705 if (out != GenTime())
2706 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2707 QMap<QString, QString>::Iterator it;
2709 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2710 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2712 for (it = args.begin(); it != args.end(); ++it) {
2714 char *name = decodedString(key);
2715 char *value = decodedString(it.value());
2716 transition->set(name, value);
2717 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2718 //filter->set("kdenlive_id", id);
2722 // attach filter to the clip
2723 field->plant_transition(*transition, a_track, b_track);
2729 void Render::mltSavePlaylist() {
2730 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2731 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2732 fileConsumer.set("resource", "/tmp/playlist.westley");
2734 Mlt::Service service(m_mltProducer->get_service());
2736 fileConsumer.connect(service);
2737 fileConsumer.start();
2740 QList <Mlt::Producer *> Render::producersList() {
2741 QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
2742 Mlt::Service service(m_mltProducer->parent().get_service());
2743 if (service.type() != tractor_type) return prods;
2744 Mlt::Tractor tractor(service);
2747 int trackNb = tractor.count();
2748 for (int t = 1; t < trackNb; t++) {
2749 Mlt::Producer trackProducer(tractor.track(t));
2750 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2751 int clipNb = trackPlaylist.count();
2752 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2753 for (int i = 0; i < clipNb; i++) {
2754 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2755 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2756 ids.append(nprod->get("id"));
2757 prods.append(nprod);
2764 void Render::fillSlowMotionProducers() {
2765 Mlt::Service service(m_mltProducer->parent().get_service());
2766 if (service.type() != tractor_type) return;
2768 Mlt::Tractor tractor(service);
2770 int trackNb = tractor.count();
2771 for (int t = 1; t < trackNb; t++) {
2772 Mlt::Producer trackProducer(tractor.track(t));
2773 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2774 int clipNb = trackPlaylist.count();
2775 for (int i = 0; i < clipNb; i++) {
2776 Mlt::Producer *nprod = new Mlt::Producer(trackPlaylist.get_clip(i)->get_parent());
2777 if (nprod && !nprod->is_blank()) {
2778 QString id = nprod->get("id");
2779 if (id.startsWith("slowmotion:")) {
2780 // this is a slowmotion producer, add it to the list
2781 QString url = QString::fromUtf8(nprod->get("resource"));
2782 if (!m_slowmotionProducers.contains(url)) {
2783 m_slowmotionProducers.insert(url, nprod);
2791 void Render::mltInsertTrack(int ix, bool videoTrack) {
2795 m_mltConsumer->set("refresh", 0);
2796 mlt_service_lock(m_mltConsumer->get_service());
2797 Mlt::Service service(m_mltProducer->parent().get_service());
2798 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2800 Mlt::Tractor tractor(service);
2802 Mlt::Playlist playlist;// = new Mlt::Playlist();
2803 int ct = tractor.count();
2804 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2807 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2808 tractor.set_track(playlist, pos);
2809 Mlt::Producer newProd(tractor.track(pos));
2810 if (!videoTrack) newProd.set("hide", 1);
2812 for (; pos <= ct; pos++) {
2813 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2814 tractor.set_track(*prodToMove, pos);
2815 prodToMove = prodToMove2;
2818 tractor.set_track(playlist, ix);
2819 Mlt::Producer newProd(tractor.track(ix));
2820 if (!videoTrack) newProd.set("hide", 1);
2824 mlt_service serv = m_mltProducer->parent().get_service();
2825 mlt_service nextservice = mlt_service_get_producer(serv);
2826 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2827 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2828 QString resource = mlt_properties_get(properties, "mlt_service");
2830 while (mlt_type == "transition") {
2831 if (resource != "mix") {
2832 mlt_transition tr = (mlt_transition) nextservice;
2833 int currentTrack = mlt_transition_get_b_track(tr);
2834 int currentaTrack = mlt_transition_get_a_track(tr);
2835 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2837 if (currentTrack >= ix) {
2838 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2839 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2842 nextservice = mlt_service_producer(nextservice);
2843 if (nextservice == NULL) break;
2844 properties = MLT_SERVICE_PROPERTIES(nextservice);
2845 mlt_type = mlt_properties_get(properties, "mlt_type");
2846 resource = mlt_properties_get(properties, "mlt_service");
2849 // Add audio mix transition to last track
2850 Mlt::Field *field = tractor.field();
2851 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2852 //transition->set("mlt_service", "mix");
2853 transition->set("a_track", 1);
2854 transition->set("b_track", ct);
2855 transition->set("always_active", 1);
2856 transition->set("internal_added", 237);
2857 transition->set("combine", 1);
2858 field->plant_transition(*transition, 1, ct);
2860 mlt_service_unlock(m_mltConsumer->get_service());
2861 m_isBlocked = false;
2862 blockSignals(false);
2866 void Render::mltDeleteTrack(int ix) {
2868 doc.setContent(sceneList(), false);
2869 int tracksCount = doc.elementsByTagName("track").count() - 1;
2870 QDomNode track = doc.elementsByTagName("track").at(ix);
2871 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2872 QDomNodeList transitions = doc.elementsByTagName("transition");
2873 for (int i = 0; i < transitions.count(); i++) {
2874 QDomElement e = transitions.at(i).toElement();
2875 QDomNodeList props = e.elementsByTagName("property");
2876 QMap <QString, QString> mappedProps;
2877 for (int j = 0; j < props.count(); j++) {
2878 QDomElement f = props.at(j).toElement();
2879 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2881 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2882 tractor.removeChild(transitions.at(i));
2883 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2884 // Transition needs to be moved
2885 int a_track = mappedProps.value("a_track").toInt();
2886 int b_track = mappedProps.value("b_track").toInt();
2887 if (a_track > 0) a_track --;
2888 if (b_track > 0) b_track --;
2889 for (int j = 0; j < props.count(); j++) {
2890 QDomElement f = props.at(j).toElement();
2891 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2892 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2897 tractor.removeChild(track);
2898 setSceneList(doc.toString(), m_framePosition);
2905 m_mltConsumer->set("refresh", 0);
2906 mlt_service_lock(m_mltConsumer->get_service());
2907 Mlt::Service service(m_mltProducer->parent().get_service());
2908 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2910 /*Mlt::Tractor tractor(service);
2913 Mlt::Multitrack *multi = tractor.multitrack();
2916 int ct = tractor.count();
2917 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
2919 for (; pos < ct ; pos++) {
2920 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
2921 //mlt_service_close(lastTrack->get_service());
2923 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
2924 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
2925 mlt_service_close(prodToMove->get_service());
2926 mlt_service_close(prodToClose->get_service());
2927 tractor.set_track(*prodToMove, pos);
2931 /*mlt_service serv = m_mltProducer->parent().get_service();
2932 mlt_service nextservice = mlt_service_get_producer(serv);
2933 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2934 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2935 QString resource = mlt_properties_get(properties, "mlt_service");
2937 while (mlt_type == "transition") {
2938 if (resource != "mix") {
2939 mlt_transition tr = (mlt_transition) nextservice;
2940 int currentTrack = mlt_transition_get_b_track(tr);
2941 int currentaTrack = mlt_transition_get_a_track(tr);
2942 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2944 if (currentTrack >= ix) {
2945 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2946 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2949 nextservice = mlt_service_producer(nextservice);
2950 if (nextservice == NULL) break;
2951 properties = MLT_SERVICE_PROPERTIES(nextservice);
2952 mlt_type = mlt_properties_get(properties, "mlt_type");
2953 resource = mlt_properties_get(properties, "mlt_service");
2956 // Add audio mix transition to last track
2957 Mlt::Field *field = tractor.field();
2958 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2959 //transition->set("mlt_service", "mix");
2960 transition->set("a_track", 1);
2961 transition->set("b_track", ct);
2962 transition->set("always_active", 1);
2963 transition->set("internal_added", 237);
2964 transition->set("combine", 1);
2965 field->plant_transition(*transition, 1, ct);
2968 mlt_service_unlock(m_mltConsumer->get_service());
2969 m_isBlocked = false;
2970 blockSignals(false);
2974 void Render::updatePreviewSettings() {
2975 kDebug() << "////// RESTARTING CONSUMER";
2976 if (!m_mltConsumer || !m_mltProducer) return;
2977 if (m_mltProducer->get_playtime() == 0) return;
2978 Mlt::Service service(m_mltProducer->parent().get_service());
2979 if (service.type() != tractor_type) return;
2981 //m_mltConsumer->set("refresh", 0);
2982 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
2983 m_mltConsumer->purge();
2984 QString scene = sceneList();
2986 if (m_mltProducer) {
2987 pos = m_mltProducer->position();
2988 delete m_mltProducer;
2990 m_mltProducer = NULL;
2991 setSceneList(scene, pos);
2994 #include "renderer.moc"