1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
29 #include <QApplication>
32 #include <KStandardDirs>
33 #include <KMessageBox>
35 #include <KTemporaryFile>
38 #include "kdenlivesettings.h"
40 #include "definitions.h"
42 #include <mlt++/Mlt.h>
45 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) {
46 // detect if the producer has finished playing. Is there a better way to do it ?
47 if (self->m_isBlocked) return;
48 if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) {
49 self->emitConsumerStopped();
51 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
55 Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid), m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false), m_isZoneMode(false), m_isLoopMode(false) {
56 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
57 refreshTimer = new QTimer(this);
58 connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
60 /*if (rendererName == "project") m_monitorId = 10000;
61 else m_monitorId = 10001;*/
62 osdTimer = new QTimer(this);
63 connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));
65 m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties");
69 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black");
70 m_mltProducer = producer;
71 if (m_blackClip) delete m_blackClip;
72 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
73 m_blackClip->set("id", "black");
74 m_mltConsumer->connect(*m_mltProducer);
75 m_mltProducer->set_speed(0.0);
83 void Render::closeMlt() {
90 if (m_blackClip) delete m_blackClip;
95 void Render::buildConsumer() {
97 m_activeProfile = KdenliveSettings::current_profile();
98 tmp = decodedString(m_activeProfile);
99 setenv("MLT_PROFILE", tmp, 1);
100 m_mltProfile = new Mlt::Profile(tmp);
103 QString videoDriver = KdenliveSettings::videodrivername();
104 if (!videoDriver.isEmpty()) {
105 if (videoDriver == "x11_noaccel") {
106 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
109 unsetenv("SDL_VIDEO_YUV_HWACCEL");
112 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
114 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
115 m_mltConsumer->set("resize", 1);
116 m_mltConsumer->set("window_id", m_winid);
117 m_mltConsumer->set("terminate_on_pause", 1);
119 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
120 m_mltConsumer->set("rescale", "nearest");
122 QString audioDevice = KdenliveSettings::audiodevicename();
123 if (!audioDevice.isEmpty()) {
124 tmp = decodedString(audioDevice);
125 m_mltConsumer->set("audio_device", tmp);
129 if (!videoDriver.isEmpty()) {
130 tmp = decodedString(videoDriver);
131 m_mltConsumer->set("video_driver", tmp);
135 QString audioDriver = KdenliveSettings::audiodrivername();
136 if (!audioDriver.isEmpty()) {
137 tmp = decodedString(audioDriver);
138 m_mltConsumer->set("audio_driver", tmp);
143 m_mltConsumer->set("progressive", 1);
144 m_mltConsumer->set("audio_buffer", 1024);
145 m_mltConsumer->set("frequency", 48000);
148 int Render::resetProfile() {
149 if (!m_mltConsumer) return 0;
150 if (m_activeProfile == KdenliveSettings::current_profile()) {
151 kDebug() << "reset to same profile, nothing to do";
154 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
155 if (m_isSplitView) slotSplitView(false);
156 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
157 m_mltConsumer->purge();
158 delete m_mltConsumer;
159 m_mltConsumer = NULL;
160 QString scene = sceneList();
163 pos = m_mltProducer->position();
164 delete m_mltProducer;
166 m_mltProducer = NULL;
168 //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards...
169 /*if (m_mltProfile) delete m_mltProfile;
170 m_mltProfile = NULL;*/
174 //kDebug() << "//RESET WITHSCENE: " << scene;
175 setSceneList(scene, pos);
177 /*char *tmp = decodedString(scene);
178 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
180 m_mltProducer = producer;
181 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
182 m_mltProducer->optimise();
183 m_mltProducer->set_speed(0);
186 //delete m_mltProfile;
187 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
188 //mlt_profile prof = m_mltProfile->get_profile();
189 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
190 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
191 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
192 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
194 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
199 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
200 void Render::seek(GenTime time) {
204 m_mltProducer->seek((int)(time.frames(m_fps)));
209 char *Render::decodedString(QString str) {
210 /*QCString fn = QFile::encodeName(str);
211 char *t = new char[fn.length() + 1];
212 strcpy(t, (const char *)fn);*/
214 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
218 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
219 QPixmap pix(width, height);
221 mlt_image_format format = mlt_image_rgb24a;
222 uint8_t *thumb = frame->get_image(format, width, height);
223 QImage image(thumb, width, height, QImage::Format_ARGB32);
225 if (!image.isNull()) {
226 pix = pix.fromImage(image);
228 QPainter painter(&pix);
229 painter.drawRect(0, 0, width - 1, height - 1);
231 } else pix.fill(Qt::black);
235 const int Render::renderWidth() const {
236 return (int)(m_mltProfile->height() * m_mltProfile->dar());
239 const int Render::renderHeight() const {
240 return m_mltProfile->height();
243 QPixmap Render::extractFrame(int frame_position, int width, int height) {
245 width = renderWidth();
246 height = renderHeight();
248 QPixmap pix(width, height);
249 if (!m_mltProducer) {
253 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
256 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
259 if (url.fileName().startsWith(".all.")) { // check for slideshow
260 QString fileType = url.fileName().right(3);
262 QStringList::Iterator it;
264 QDir dir(url.directory());
266 filter << "*." + fileType;
267 filter << "*." + fileType.toUpper();
268 more = dir.entryList(filter, QDir::Files);
269 im.load(url.directory() + "/" + more.at(0));
270 } else im.load(url.path());
271 //pixmap = im.scaled(width, height);
276 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
277 QPixmap pix(width, height);
278 char *tmp = decodedString(file);
279 Mlt::Profile *prof = new Mlt::Profile(profile);
280 Mlt::Producer m_producer(*prof, tmp);
282 if (m_producer.is_blank()) {
287 Mlt::Filter m_convert(*prof, "avcolour_space");
288 m_convert.set("forced", mlt_image_rgb24a);
289 m_producer.attach(m_convert);
290 m_producer.seek(frame_position);
291 Mlt::Frame * frame = m_producer.get_frame();
293 pix = frameThumbnail(frame, width, height, true);
296 if (prof) delete prof;
301 void Render::getImage(KUrl url, int frame_position, QPoint size)
303 char *tmp = decodedString(url.path());
304 Mlt::Producer m_producer(tmp);
306 if (m_producer.is_blank()) {
309 Mlt::Filter m_convert("avcolour_space");
310 m_convert.set("forced", mlt_image_rgb24a);
311 m_producer.attach(m_convert);
312 m_producer.seek(frame_position);
314 Mlt::Frame * frame = m_producer.get_frame();
317 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
319 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
323 /* Create thumbnail for color */
324 /*void Render::getImage(int id, QString color, QPoint size)
326 QPixmap pixmap(size.x() - 2, size.y() - 2);
327 color = color.replace(0, 2, "#");
328 color = color.left(7);
329 pixmap.fill(QColor(color));
330 QPixmap result(size.x(), size.y());
331 result.fill(Qt::black);
332 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
333 emit replyGetImage(id, result, size.x(), size.y());
337 /* Create thumbnail for image */
338 /*void Render::getImage(KUrl url, QPoint size)
342 if (url.fileName().startsWith(".all.")) { // check for slideshow
343 QString fileType = url.fileName().right(3);
345 QStringList::Iterator it;
347 QDir dir( url.directory() );
348 more = dir.entryList( QDir::Files );
349 for ( it = more.begin() ; it != more.end() ; ++it ) {
350 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
351 if (!im.load(url.directory() + "/" + *it))
352 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
357 else im.load(url.path());
359 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
360 QPixmap result(size.x(), size.y());
361 result.fill(Qt::black);
362 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
363 emit replyGetImage(url, 1, result, size.x(), size.y());
367 double Render::consumerRatio() const {
368 if (!m_mltConsumer) return 1.0;
369 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
373 int Render::getLength() {
376 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
377 return mlt_producer_get_playtime(m_mltProducer->get_producer());
382 bool Render::isValid(KUrl url) {
383 char *tmp = decodedString(url.path());
384 Mlt::Producer producer(*m_mltProfile, tmp);
386 if (producer.is_blank())
392 const double Render::dar() const {
393 return m_mltProfile->dar();
396 void Render::slotSplitView(bool doit) {
397 m_isSplitView = doit;
398 Mlt::Service service(m_mltProducer->parent().get_service());
399 Mlt::Tractor tractor(service);
400 if (service.type() != tractor_type || tractor.count() < 2) return;
401 Mlt::Field *field = tractor.field();
404 for (int i = 1; i < tractor.count() && screen < 4; i++) {
405 Mlt::Producer trackProducer(tractor.track(i));
406 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
407 if (QString(trackProducer.get("hide")).toInt() != 1) {
408 kDebug() << "// ADIDNG TRACK: " << i;
409 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
410 transition->set("mlt_service", "composite");
411 transition->set("a_track", 0);
412 transition->set("b_track", i);
413 transition->set("distort", 1);
414 transition->set("internal_added", "200");
421 tmp = "50%,0:50%x50%";
424 tmp = "0,50%:50%x50%";
427 tmp = "50%,50%:50%x50%";
430 transition->set("geometry", tmp);
431 transition->set("always_active", "1");
432 field->plant_transition(*transition, 0, i);
437 m_mltConsumer->set("refresh", 1);
439 mlt_service serv = m_mltProducer->parent().get_service();
440 mlt_service nextservice = mlt_service_get_producer(serv);
441 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
442 QString mlt_type = mlt_properties_get(properties, "mlt_type");
443 QString resource = mlt_properties_get(properties, "mlt_service");
445 while (mlt_type == "transition") {
446 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
447 if (added == "200") {
448 mlt_field_disconnect_service(field->get_field(), nextservice);
450 nextservice = mlt_service_producer(nextservice);
451 if (nextservice == NULL) break;
452 properties = MLT_SERVICE_PROPERTIES(nextservice);
453 mlt_type = mlt_properties_get(properties, "mlt_type");
454 resource = mlt_properties_get(properties, "mlt_service");
455 m_mltConsumer->set("refresh", 1);
460 void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
462 int width = (int)(height * m_mltProfile->dar());
463 QMap < QString, QString > filePropertyMap;
464 QMap < QString, QString > metadataPropertyMap;
466 KUrl url = KUrl(xml.attribute("resource", QString::null));
467 Mlt::Producer *producer = NULL;
468 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
469 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
472 if (xml.attribute("type").toInt() == COLOR) {
473 char *tmp = decodedString("colour:" + xml.attribute("colour"));
474 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
476 } else if (url.isEmpty()) {
478 QDomElement westley = doc.createElement("westley");
479 QDomElement play = doc.createElement("playlist");
480 doc.appendChild(westley);
481 westley.appendChild(play);
482 play.appendChild(doc.importNode(xml, true));
483 char *tmp = decodedString(doc.toString());
484 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
487 QString urlpath = url.path();
488 /*if (urlpath.contains(':')) {
489 if (!urlpath.startsWith("file:")) urlpath.prepend("file:");
490 char *tmp = decodedString(urlpath);
491 producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp);
495 char *tmp = decodedString(urlpath);
496 producer = new Mlt::Producer(*m_mltProfile, tmp);
499 if (xml.hasAttribute("force_aspect_ratio")) {
500 double aspect = xml.attribute("force_aspect_ratio").toDouble();
501 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
503 if (xml.hasAttribute("threads")) {
504 int threads = xml.attribute("threads").toInt();
505 if (threads != 1) producer->set("threads", threads);
507 if (xml.hasAttribute("video_index")) {
508 int vindex = xml.attribute("video_index").toInt();
509 if (vindex != 0) producer->set("video_index", vindex);
511 if (xml.hasAttribute("audio_index")) {
512 int aindex = xml.attribute("audio_index").toInt();
513 if (aindex != 0) producer->set("audio_index", aindex);
518 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
519 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
520 emit removeInvalidClip(clipId);
524 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
526 char *tmp = decodedString(clipId);
527 producer->set("id", tmp);
529 int frameNumber = xml.attribute("thumbnail", "0").toInt();
530 if (frameNumber != 0) producer->seek(frameNumber);
531 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
533 filePropertyMap["duration"] = QString::number(producer->get_playtime());
534 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
536 Mlt::Frame *frame = producer->get_frame();
538 if (xml.attribute("type").toInt() == SLIDESHOW) {
539 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
540 if (xml.attribute("fade") == "1") {
541 // user wants a fade effect to slideshow
542 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
543 if (filter && filter->is_valid()) {
544 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
545 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
546 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
547 char *tmp = decodedString(xml.attribute("luma_file"));
548 filter->set("luma.resource", tmp);
550 if (xml.hasAttribute("softness")) {
551 int soft = xml.attribute("softness").toInt();
552 filter->set("luma.softness", (double) soft / 100.0);
555 Mlt::Service clipService(producer->get_service());
556 clipService.attach(*filter);
562 filePropertyMap["fps"] = producer->get("source_fps");
564 if (frame && frame->is_valid()) {
565 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
566 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
567 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
568 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
570 if (frame->get_int("test_image") == 0) {
571 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
572 filePropertyMap["type"] = "playlist";
573 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
574 } else if (frame->get_int("test_audio") == 0)
575 filePropertyMap["type"] = "av";
577 filePropertyMap["type"] = "video";
579 mlt_image_format format = mlt_image_yuv422;
581 int frame_height = 0;
582 //frame->set("rescale.interp", "hyper");
583 frame->set("normalised_height", height);
584 frame->set("normalised_width", width);
585 QPixmap pix(width, height);
587 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
588 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
589 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
590 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
592 if (!image.isNull()) {
593 pix = QPixmap::fromImage(image.rgbSwapped());
597 mlt_pool_release(new_image);
598 emit replyGetImage(clipId, 0, pix, width, height);
600 } else if (frame->get_int("test_audio") == 0) {
601 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
602 emit replyGetImage(clipId, 0, pixmap, width, height);
603 filePropertyMap["type"] = "audio";
607 // Retrieve audio / video codec name
611 if (producer->get_int("video_index") > -1) {
612 /*if (context->duration == AV_NOPTS_VALUE) {
613 kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
614 emit removeInvalidClip(clipId);
617 // Get the video_index
618 int default_video = producer->get_int("video_index");
620 int default_audio = producer->get_int("audio_index");
623 // Find maximum stream index values
624 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
625 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
626 QString type = producer->get(property);
629 else if (type == "audio")
632 filePropertyMap["default_video"] = QString::number(default_video);
633 filePropertyMap["video_max"] = QString::number(video_max);
634 filePropertyMap["default_audio"] = QString::number(default_audio);
635 filePropertyMap["audio_max"] = QString::number(audio_max);
637 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
638 if (producer->get(property)) {
639 filePropertyMap["videocodec"] = producer->get(property);
641 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
642 if (producer->get(property))
643 filePropertyMap["videocodec"] = producer->get(property);
645 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
646 if (producer->get_int("audio_index") > -1) {
647 // Get the audio_index
648 int index = producer->get_int("audio_index");
650 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
651 if (producer->get(property)) {
652 filePropertyMap["audiocodec"] = producer->get(property);
654 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
655 if (producer->get(property))
656 filePropertyMap["audiocodec"] = producer->get(property);
661 Mlt::Properties metadata;
662 metadata.pass_values(*producer, "meta.attr.");
663 int count = metadata.count();
664 for (int i = 0; i < count; i ++) {
665 QString name = metadata.get_name(i);
666 QString value = QString::fromUtf8(metadata.get(i));
667 if (name.endsWith("markup") && !value.isEmpty())
668 metadataPropertyMap[ name.section(".", 0, -2)] = value;
671 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
672 kDebug() << "REquested fuile info for: " << url.path();
673 if (frame) delete frame;
674 //if (producer) delete producer;
678 /** Create the producer from the Westley QDomDocument */
680 void Render::initSceneList() {
681 kDebug() << "-------- INIT SCENE LIST ------_";
683 QDomElement westley = doc.createElement("westley");
684 doc.appendChild(westley);
685 QDomElement prod = doc.createElement("producer");
686 prod.setAttribute("resource", "colour");
687 prod.setAttribute("colour", "red");
688 prod.setAttribute("id", "black");
689 prod.setAttribute("in", "0");
690 prod.setAttribute("out", "0");
692 QDomElement tractor = doc.createElement("tractor");
693 QDomElement multitrack = doc.createElement("multitrack");
695 QDomElement playlist1 = doc.createElement("playlist");
696 playlist1.appendChild(prod);
697 multitrack.appendChild(playlist1);
698 QDomElement playlist2 = doc.createElement("playlist");
699 multitrack.appendChild(playlist2);
700 QDomElement playlist3 = doc.createElement("playlist");
701 multitrack.appendChild(playlist3);
702 QDomElement playlist4 = doc.createElement("playlist");
703 multitrack.appendChild(playlist4);
704 QDomElement playlist5 = doc.createElement("playlist");
705 multitrack.appendChild(playlist5);
706 tractor.appendChild(multitrack);
707 westley.appendChild(tractor);
708 // kDebug()<<doc.toString();
710 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
711 setSceneList(doc, 0);
717 /** Create the producer from the Westley QDomDocument */
718 void Render::setProducer(Mlt::Producer *producer, int position) {
719 if (m_winid == -1) return;
722 m_mltConsumer->stop();
727 m_mltProducer->set_speed(0);
728 delete m_mltProducer;
729 m_mltProducer = NULL;
732 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
733 else m_mltProducer = new Mlt::Producer();
734 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
736 m_fps = m_mltProducer->get_fps();
738 if (position != -1) {
739 m_mltProducer->seek(position);
740 emit rendererPosition(position);
747 /** Create the producer from the Westley QDomDocument */
748 void Render::setSceneList(QDomDocument list, int position) {
749 setSceneList(list.toString(), position);
752 /** Create the producer from the Westley QDomDocument */
753 void Render::setSceneList(QString playlist, int position) {
754 if (m_winid == -1) return;
757 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
760 m_mltConsumer->stop();
761 //m_mltConsumer->set("refresh", 0);
768 m_mltProducer->set_speed(0);
769 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
771 delete m_mltProducer;
772 m_mltProducer = NULL;
777 char *tmp = decodedString(playlist);
778 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
780 if (m_blackClip) delete m_blackClip;
781 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
782 m_blackClip->set("id", "black");
783 if (!m_mltProducer || !m_mltProducer->is_valid()) {
784 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
786 m_mltProducer->optimise();
788 /*if (KdenliveSettings::osdtimecode()) {
789 // Attach filter for on screen display of timecode
791 QString attr = "attr_check";
792 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
793 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
794 mlt_producer_attach( m_mltProducer->get_producer(), filter );
795 mlt_filter_close( filter );
797 m_osdInfo = new Mlt::Filter("data_show");
798 tmp = decodedString(m_osdProfile);
799 m_osdInfo->set("resource", tmp);
801 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
802 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
803 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
804 m_osdInfo->set("dynamic", "1");
806 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
808 m_osdInfo->set("dynamic", "0");
811 m_fps = m_mltProducer->get_fps();
812 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
815 //TODO: seek to correct place after opening project.
816 // Needs to be done from another place since it crashes here.
817 m_mltProducer->seek(position);
821 //kDebug()<<"// SETSCN LST, POS: "<<position;
822 //if (position != 0) emit rendererPosition(position);
825 /** Create the producer from the Westley QDomDocument */
826 QString Render::sceneList() {
828 Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
829 m_mltProducer->optimise();
830 westleyConsumer.set("terminate_on_pause", 1);
831 Mlt::Producer prod(m_mltProducer->get_producer());
832 bool split = m_isSplitView;
833 if (split) slotSplitView(false);
834 westleyConsumer.connect(prod);
835 westleyConsumer.start();
836 while (!westleyConsumer.is_stopped()) {}
837 playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
838 if (split) slotSplitView(true);
842 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
845 doc.setContent(sceneList(), false);
846 if (!kdenliveData.isNull()) {
847 // add Kdenlive specific tags
848 QDomNode wes = doc.elementsByTagName("westley").at(0);
849 wes.appendChild(doc.importNode(kdenliveData, true));
851 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
852 kWarning() << "////// ERROR writing to file: " << path;
855 QTextStream out(&file);
856 out << doc.toString();
861 void Render::saveZone(KUrl url, QString desc, QPoint zone) {
862 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
863 char *tmppath = decodedString("westley:" + url.path());
864 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
865 m_mltProducer->optimise();
867 westleyConsumer.set("terminate_on_pause", 1);
868 if (m_name == "clip") {
869 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
870 tmppath = decodedString(desc);
872 list.insert_at(0, prod, 0);
873 list.set("title", tmppath);
875 westleyConsumer.connect(list);
878 //TODO: not working yet, save zone from timeline
879 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
880 /* Mlt::Service service(p1->parent().get_service());
881 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
883 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
884 tmppath = decodedString(desc);
885 //prod->set("title", tmppath);
887 westleyConsumer.connect(*p1); //list);
890 westleyConsumer.start();
893 const double Render::fps() const {
897 void Render::connectPlaylist() {
898 if (!m_mltConsumer) return;
899 //m_mltConsumer->set("refresh", "0");
900 m_mltConsumer->connect(*m_mltProducer);
901 m_mltProducer->set_speed(0);
902 m_mltConsumer->start();
903 emit durationChanged(m_mltProducer->get_playtime());
906 if (m_mltConsumer->start() == -1) {
907 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."));
908 m_mltConsumer = NULL;
915 void Render::refreshDisplay() {
917 if (!m_mltProducer) return;
918 //m_mltConsumer->set("refresh", 0);
920 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
921 /*if (KdenliveSettings::osdtimecode()) {
922 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
923 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
924 m_osdInfo->set("dynamic", "1");
925 m_mltProducer->attach(*m_osdInfo);
928 m_mltProducer->detach(*m_osdInfo);
929 m_osdInfo->set("dynamic", "0");
934 void Render::setVolume(double volume) {
935 if (!m_mltConsumer || !m_mltProducer) return;
937 m_mltConsumer->set("refresh", 0);
938 // Attach filter for on screen display of timecode
939 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
940 mlt_properties_set_double( properties, "meta.volume", volume );
941 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
942 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
944 if (!KdenliveSettings::osdtimecode()) {
945 m_mltProducer->detach(*m_osdInfo);
946 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
947 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
950 osdTimer->setSingleShot(2500);
953 void Render::slotOsdTimeout() {
954 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
955 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
956 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
957 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
961 void Render::start() {
962 kDebug() << "----- STARTING MONITOR: " << m_name;
964 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
968 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
969 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
970 if (m_mltConsumer->start() == -1) {
971 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."));
972 m_mltConsumer = NULL;
975 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
983 void Render::clear() {
984 kDebug() << " ********* RENDER CLEAR";
986 //m_mltConsumer->set("refresh", 0);
987 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
991 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
992 m_mltProducer->set_speed(0.0);
993 delete m_mltProducer;
994 m_mltProducer = NULL;
999 void Render::stop() {
1000 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1001 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1003 m_mltConsumer->set("refresh", 0);
1004 m_mltConsumer->stop();
1005 // delete m_mltConsumer;
1006 // m_mltConsumer = NULL;
1008 kDebug() << "///////////// RENDER STOP2-------";
1011 if (m_mltProducer) {
1012 if (m_isZoneMode) resetZoneMode();
1013 m_mltProducer->set_speed(0.0);
1014 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1015 //kDebug() << m_mltProducer->get_length();
1017 kDebug() << "///////////// RENDER STOP3-------";
1020 void Render::stop(const GenTime & startTime) {
1022 kDebug() << "///////////// RENDER STOP-------2";
1023 if (m_mltProducer) {
1024 if (m_isZoneMode) resetZoneMode();
1025 m_mltProducer->set_speed(0.0);
1026 m_mltProducer->seek((int) startTime.frames(m_fps));
1028 m_mltConsumer->purge();
1031 void Render::pause() {
1032 if (!m_mltProducer || !m_mltConsumer)
1034 if (m_mltProducer->get_speed() == 0.0) return;
1035 if (m_isZoneMode) resetZoneMode();
1037 m_mltConsumer->set("refresh", 0);
1038 m_mltProducer->set_speed(0.0);
1039 emit rendererPosition(m_framePosition);
1040 m_mltProducer->seek(m_framePosition);
1041 m_mltConsumer->purge();
1044 void Render::switchPlay() {
1045 if (!m_mltProducer || !m_mltConsumer)
1047 if (m_isZoneMode) resetZoneMode();
1048 if (m_mltProducer->get_speed() == 0.0) {
1049 m_isBlocked = false;
1050 m_mltProducer->set_speed(1.0);
1051 m_mltConsumer->set("refresh", 1);
1054 m_mltConsumer->set("refresh", 0);
1055 m_mltProducer->set_speed(0.0);
1056 emit rendererPosition(m_framePosition);
1057 m_mltProducer->seek(m_framePosition);
1058 m_mltConsumer->purge();
1059 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1060 //m_mltConsumer->set("refresh", 0);
1061 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1062 m_mltProducer->set_speed(0);
1063 m_mltProducer->seek( position );
1064 //m_mltProducer->seek((int) m_framePosition);
1065 m_isBlocked = false;*/
1067 /*if (speed == 0.0) {
1068 m_mltProducer->seek((int) m_framePosition + 1);
1069 m_mltConsumer->purge();
1074 void Render::play(double speed) {
1077 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1078 m_isBlocked = false;
1079 m_mltProducer->set_speed(speed);
1080 /*if (speed == 0.0) {
1081 m_mltProducer->seek((int) m_framePosition + 1);
1082 m_mltConsumer->purge();
1087 void Render::play(const GenTime & startTime) {
1088 if (!m_mltProducer || !m_mltConsumer)
1090 m_isBlocked = false;
1091 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1092 m_mltProducer->set_speed(1.0);
1093 m_mltConsumer->set("refresh", 1);
1096 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1097 if (!m_mltProducer || !m_mltConsumer)
1099 //m_mltProducer->set("eof", "loop");
1100 m_isLoopMode = true;
1101 m_loopStart = startTime;
1102 playZone(startTime, stopTime);
1105 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1106 if (!m_mltProducer || !m_mltConsumer)
1108 m_isBlocked = false;
1109 m_mltProducer->set("out", stopTime.frames(m_fps));
1110 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1111 m_mltProducer->set_speed(1.0);
1112 m_mltConsumer->set("refresh", 1);
1113 m_isZoneMode = true;
1116 void Render::resetZoneMode() {
1117 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1118 //m_mltProducer->set("eof", "pause");
1119 m_isZoneMode = false;
1120 m_isLoopMode = false;
1123 void Render::seekToFrame(int pos) {
1124 //kDebug()<<" ********* RENDER SEEK TO POS";
1127 m_isBlocked = false;
1129 m_mltProducer->seek(pos);
1133 void Render::askForRefresh() {
1134 // Use a Timer so that we don't refresh too much
1135 refreshTimer->start(200);
1138 void Render::doRefresh() {
1139 // Use a Timer so that we don't refresh too much
1140 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1143 void Render::refresh() {
1144 if (!m_mltProducer || m_isBlocked)
1146 refreshTimer->stop();
1147 if (m_mltConsumer) {
1148 m_mltConsumer->set("refresh", 1);
1152 double Render::playSpeed() {
1153 if (m_mltProducer) return m_mltProducer->get_speed();
1157 GenTime Render::seekPosition() const {
1158 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1159 else return GenTime();
1163 const QString & Render::rendererName() const {
1168 void Render::emitFrameNumber(double position) {
1169 m_framePosition = position;
1170 emit rendererPosition((int) position);
1171 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1174 void Render::emitConsumerStopped() {
1175 // This is used to know when the playing stopped
1176 if (m_mltProducer) {
1177 double pos = m_mltProducer->position();
1178 if (m_isLoopMode) play(m_loopStart);
1179 else if (m_isZoneMode) resetZoneMode();
1180 emit rendererStopped((int) pos);
1181 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1182 //new QCustomEvent(10002));
1188 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1189 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1193 void Render::exportCurrentFrame(KUrl url, bool notify) {
1194 if (!m_mltProducer) {
1195 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1199 int height = 1080;//KdenliveSettings::defaultheight();
1200 int width = 1940; //KdenliveSettings::displaywidth();
1202 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1204 QPixmap pix(width, height);
1205 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1206 m_convert.set("forced", mlt_image_rgb24a);
1207 m_mltProducer->attach(m_convert);
1208 Mlt::Frame * frame = m_mltProducer->get_frame();
1209 m_mltProducer->detach(m_convert);
1211 pix = frameThumbnail(frame, width, height);
1214 pix.save(url.path(), "PNG");
1215 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1218 /** MLT PLAYLIST DIRECT MANIPULATON **/
1221 void Render::mltCheckLength() {
1222 //kDebug()<<"checking track length: "<<track<<"..........";
1224 Mlt::Service service(m_mltProducer->get_service());
1225 Mlt::Tractor tractor(service);
1227 int trackNb = tractor.count();
1228 double duration = 0;
1229 double trackDuration;
1231 Mlt::Producer trackProducer(tractor.track(0));
1232 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1233 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1234 m_mltProducer->set("out", duration);
1235 emit durationChanged((int) duration);
1238 while (trackNb > 1) {
1239 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1240 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1241 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1243 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1244 if (trackDuration > duration) duration = trackDuration;
1248 Mlt::Producer blackTrackProducer(tractor.track(0));
1249 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1250 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1252 if (blackDuration != duration) {
1253 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1255 int dur = (int)duration;
1257 QDomElement black = doc.createElement("producer");
1258 black.setAttribute("mlt_service", "colour");
1259 black.setAttribute("colour", "black");
1260 black.setAttribute("id", "black");
1263 while (dur > 14000) {
1264 info.startPos = GenTime(i * 14000, m_fps);
1265 info.endPos = info.startPos + GenTime(13999, m_fps);
1266 mltInsertClip(info, black, m_blackClip);
1271 info.startPos = GenTime(i * 14000, m_fps);
1272 info.endPos = info.startPos + GenTime(dur, m_fps);
1273 mltInsertClip(info, black, m_blackClip);
1275 m_mltProducer->set("out", duration);
1276 emit durationChanged((int)duration);
1280 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1281 if (!m_mltProducer) {
1282 kDebug() << "PLAYLIST NOT INITIALISED //////";
1285 Mlt::Producer parentProd(m_mltProducer->parent());
1286 if (parentProd.get_producer() == NULL) {
1287 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1291 Mlt::Service service(parentProd.get_service());
1292 Mlt::Tractor tractor(service);
1293 mlt_service_lock(service.get_service());
1294 Mlt::Producer trackProducer(tractor.track(info.track));
1295 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1296 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1297 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1298 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1300 /*if (QString(prod->get("transparency")).toInt() == 1)
1301 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1303 mlt_service_unlock(service.get_service());
1305 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1306 //tractor.multitrack()->refresh();
1307 //tractor.refresh();
1311 void Render::mltCutClip(int track, GenTime position) {
1315 Mlt::Service service(m_mltProducer->parent().get_service());
1316 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1318 Mlt::Tractor tractor(service);
1319 Mlt::Producer trackProducer(tractor.track(track));
1320 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1323 /* // Display playlist info
1324 kDebug()<<"//////////// BEFORE";
1325 for (int i = 0; i < trackPlaylist.count(); i++) {
1326 int blankStart = trackPlaylist.clip_start(i);
1327 int blankDuration = trackPlaylist.clip_length(i) - 1;
1329 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1330 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1333 int cutPos = (int) position.frames(m_fps);
1335 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1336 if (trackPlaylist.is_blank(clipIndex)) {
1337 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1338 m_isBlocked = false;
1341 mlt_service_lock(service.get_service());
1342 int clipStart = trackPlaylist.clip_start(clipIndex);
1343 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1344 mlt_service_unlock(service.get_service());
1346 // duplicate effects
1347 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1348 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1350 if (original == NULL || clip == NULL) {
1351 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1353 Mlt::Service clipService(original->get_service());
1354 Mlt::Service dupService(clip->get_service());
1356 Mlt::Filter *filter = clipService.filter(ct);
1358 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1359 // looks like there is no easy way to duplicate a filter,
1360 // so we will create a new one and duplicate its properties
1361 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1362 if (dup && dup->is_valid()) {
1363 Mlt::Properties entries(filter->get_properties());
1364 for (int i = 0;i < entries.count();i++) {
1365 dup->set(entries.get_name(i), entries.get(i));
1367 dupService.attach(*dup);
1371 filter = clipService.filter(ct);
1374 /* // Display playlist info
1375 kDebug()<<"//////////// AFTER";
1376 for (int i = 0; i < trackPlaylist.count(); i++) {
1377 int blankStart = trackPlaylist.clip_start(i);
1378 int blankDuration = trackPlaylist.clip_length(i) - 1;
1380 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1381 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1384 m_isBlocked = false;
1387 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1389 mltRemoveClip(info.track, info.startPos);
1390 mltInsertClip(info, element, prod);
1394 bool Render::mltRemoveClip(int track, GenTime position) {
1395 Mlt::Service service(m_mltProducer->parent().get_service());
1396 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1398 Mlt::Tractor tractor(service);
1399 Mlt::Producer trackProducer(tractor.track(track));
1400 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1401 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1403 /* // Display playlist info
1404 kDebug()<<"//// BEFORE";
1405 for (int i = 0; i < trackPlaylist.count(); i++) {
1406 int blankStart = trackPlaylist.clip_start(i);
1407 int blankDuration = trackPlaylist.clip_length(i) - 1;
1409 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1410 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1413 if (trackPlaylist.is_blank(clipIndex)) {
1414 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1418 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1419 trackPlaylist.replace_with_blank(clipIndex);
1420 trackPlaylist.consolidate_blanks(0);
1421 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1422 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1424 /* // Display playlist info
1425 kDebug()<<"//// AFTER";
1426 for (int i = 0; i < trackPlaylist.count(); i++) {
1427 int blankStart = trackPlaylist.clip_start(i);
1428 int blankDuration = trackPlaylist.clip_length(i) - 1;
1430 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1431 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1434 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1435 m_isBlocked = false;
1439 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
1440 if (!m_mltProducer) {
1441 kDebug() << "PLAYLIST NOT INITIALISED //////";
1444 Mlt::Producer parentProd(m_mltProducer->parent());
1445 if (parentProd.get_producer() == NULL) {
1446 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1450 Mlt::Service service(parentProd.get_service());
1451 Mlt::Tractor tractor(service);
1452 int insertPos = pos.frames(m_fps);
1454 Mlt::Producer trackProducer(tractor.track(track));
1455 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1456 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1457 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1458 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1459 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1463 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
1464 if (!m_mltProducer) {
1465 kDebug() << "PLAYLIST NOT INITIALISED //////";
1468 Mlt::Producer parentProd(m_mltProducer->parent());
1469 if (parentProd.get_producer() == NULL) {
1470 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1473 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1474 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1476 Mlt::Service service(parentProd.get_service());
1477 Mlt::Tractor tractor(service);
1478 mlt_service_lock(service.get_service());
1479 int diff = duration.frames(m_fps);
1480 int offset = timeOffset.frames(m_fps);
1484 // insert space in one track only
1485 Mlt::Producer trackProducer(tractor.track(track));
1486 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1487 insertPos = trackClipStartList.value(track);
1488 if (insertPos != -1) {
1489 insertPos += offset;
1490 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1491 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1493 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1494 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1495 int position = trackPlaylist.clip_start(clipIndex);
1496 trackPlaylist.remove_region(position, - diff - 1);
1498 trackPlaylist.consolidate_blanks(0);
1500 // now move transitions
1501 mlt_service serv = m_mltProducer->parent().get_service();
1502 mlt_service nextservice = mlt_service_get_producer(serv);
1503 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1504 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1505 QString resource = mlt_properties_get(properties, "mlt_service");
1507 while (mlt_type == "transition") {
1508 mlt_transition tr = (mlt_transition) nextservice;
1509 int currentTrack = mlt_transition_get_b_track(tr);
1510 int currentIn = (int) mlt_transition_get_in(tr);
1511 int currentOut = (int) mlt_transition_get_out(tr);
1512 insertPos = trackTransitionStartList.value(track);
1513 if (insertPos != -1) {
1514 insertPos += offset;
1515 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1516 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1519 nextservice = mlt_service_producer(nextservice);
1520 if (nextservice == NULL) break;
1521 properties = MLT_SERVICE_PROPERTIES(nextservice);
1522 mlt_type = mlt_properties_get(properties, "mlt_type");
1523 resource = mlt_properties_get(properties, "mlt_service");
1526 int trackNb = tractor.count();
1527 while (trackNb > 1) {
1528 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1529 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1532 int clipNb = trackPlaylist.count();
1533 insertPos = trackClipStartList.value(trackNb - 1);
1534 if (insertPos != -1) {
1535 insertPos += offset;
1537 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1538 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1539 for (int i = 0; i < clipNb; i++) {
1540 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1541 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1542 kDebug()<<"-------------";
1544 kDebug()<<"END-------------";*/
1547 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1548 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1550 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1551 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1552 int position = trackPlaylist.clip_start(clipIndex);
1553 trackPlaylist.remove_region(position, - diff - 1);
1555 trackPlaylist.consolidate_blanks(0);
1559 // now move transitions
1560 mlt_service serv = m_mltProducer->parent().get_service();
1561 mlt_service nextservice = mlt_service_get_producer(serv);
1562 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1563 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1564 QString resource = mlt_properties_get(properties, "mlt_service");
1566 while (mlt_type == "transition") {
1567 mlt_transition tr = (mlt_transition) nextservice;
1568 int currentIn = (int) mlt_transition_get_in(tr);
1569 int currentOut = (int) mlt_transition_get_out(tr);
1570 int currentTrack = mlt_transition_get_b_track(tr);
1571 insertPos = trackTransitionStartList.value(currentTrack);
1572 if (insertPos != -1) {
1573 insertPos += offset;
1574 if (currentOut > insertPos && resource != "mix") {
1575 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1578 nextservice = mlt_service_producer(nextservice);
1579 if (nextservice == NULL) break;
1580 properties = MLT_SERVICE_PROPERTIES(nextservice);
1581 mlt_type = mlt_properties_get(properties, "mlt_type");
1582 resource = mlt_properties_get(properties, "mlt_service");
1585 mlt_service_unlock(service.get_service());
1587 m_mltConsumer->set("refresh", 1);
1590 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
1593 Mlt::Service service(m_mltProducer->parent().get_service());
1594 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1595 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1596 Mlt::Tractor tractor(service);
1597 Mlt::Producer trackProducer(tractor.track(info.track));
1598 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1599 int startPos = info.startPos.frames(m_fps);
1600 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1601 int clipLength = trackPlaylist.clip_length(clipIndex);
1603 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1604 QString serv = clip.parent().get("mlt_service");
1605 QString id = clip.parent().get("id");
1606 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1607 if (serv == "avformat" && speed != 1.0) {
1608 mlt_service_lock(service.get_service());
1609 QString url = clip.parent().get("resource");
1610 url.append("?" + QString::number(speed));
1611 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1612 if (!slowprod || slowprod->get_producer() == NULL) {
1613 char *tmp = decodedString(url);
1614 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1616 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1617 tmp = decodedString(producerid);
1618 slowprod->set("id", tmp);
1620 m_slowmotionProducers.insert(url, slowprod);
1622 trackPlaylist.replace_with_blank(clipIndex);
1623 trackPlaylist.consolidate_blanks(0);
1624 // Check that the blank space is long enough for our new duration
1625 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1626 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1628 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1629 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1630 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1631 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1632 trackPlaylist.insert_at(startPos, *cut, 1);
1633 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1634 newLength = trackPlaylist.clip_length(clipIndex);
1635 mlt_service_unlock(service.get_service());
1636 } else if (speed == 1.0) {
1637 mlt_service_lock(service.get_service());
1639 trackPlaylist.replace_with_blank(clipIndex);
1640 trackPlaylist.consolidate_blanks(0);
1642 // Check that the blank space is long enough for our new duration
1643 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1644 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1647 GenTime oldDuration = GenTime(clipLength, m_fps);
1648 GenTime newDuration = oldDuration * oldspeed;
1649 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1650 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1651 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1652 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1653 trackPlaylist.insert_at(startPos, *cut, 1);
1654 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1655 newLength = trackPlaylist.clip_length(clipIndex);
1656 mlt_service_unlock(service.get_service());
1658 } else if (serv == "framebuffer") {
1659 mlt_service_lock(service.get_service());
1660 QString url = clip.parent().get("resource");
1661 url = url.section("?", 0, 0);
1662 url.append("?" + QString::number(speed));
1663 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1664 if (!slowprod || slowprod->get_producer() == NULL) {
1665 char *tmp = decodedString(url);
1666 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1668 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1669 tmp = decodedString(producerid);
1670 slowprod->set("id", tmp);
1672 m_slowmotionProducers.insert(url, slowprod);
1674 trackPlaylist.replace_with_blank(clipIndex);
1675 trackPlaylist.consolidate_blanks(0);
1677 GenTime oldDuration = GenTime(clipLength, m_fps);
1678 GenTime newDuration = oldDuration * oldspeed / speed;
1680 // Check that the blank space is long enough for our new duration
1681 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1682 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1685 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1686 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1687 cut = slowprod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1688 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1690 trackPlaylist.insert_at(startPos, *cut, 1);
1691 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1692 newLength = trackPlaylist.clip_length(clipIndex);
1694 mlt_service_unlock(service.get_service());
1696 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1697 m_isBlocked = false;
1701 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1703 Mlt::Service service(m_mltProducer->parent().get_service());
1704 bool success = false;
1705 Mlt::Tractor tractor(service);
1706 Mlt::Producer trackProducer(tractor.track(track));
1707 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1708 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1709 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1711 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1714 Mlt::Service clipService(clip->get_service());
1715 // if (tag.startsWith("ladspa")) tag = "ladspa";
1718 Mlt::Filter *filter = clipService.filter(ct);
1720 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1721 if (clipService.detach(*filter) == 0) success = true;
1722 kDebug() << " / / / DLEETED EFFECT: " << ct;
1724 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1727 filter = clipService.filter(ct);
1729 m_isBlocked = false;
1730 if (doRefresh) refresh();
1735 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
1737 Mlt::Service service(m_mltProducer->parent().get_service());
1739 Mlt::Tractor tractor(service);
1740 Mlt::Producer trackProducer(tractor.track(track));
1741 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1743 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1747 Mlt::Service clipService(clip->get_service());
1750 // temporarily remove all effects after insert point
1751 QList <Mlt::Filter *> filtersList;
1752 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1754 Mlt::Filter *filter = clipService.filter(ct);
1756 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1757 filtersList.append(filter);
1758 clipService.detach(*filter);
1760 filter = clipService.filter(ct);
1764 QString tag = params.paramValue("tag");
1765 kDebug() << " / / INSERTING EFFECT: " << tag;
1766 if (tag.startsWith("ladspa")) tag = "ladspa";
1767 char *filterTag = decodedString(tag);
1768 char *filterId = decodedString(params.paramValue("id"));
1769 QHash<QString, QString>::Iterator it;
1770 QString kfr = params.paramValue("keyframes");
1772 if (!kfr.isEmpty()) {
1773 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1774 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1775 char *starttag = decodedString(params.paramValue("starttag", "start"));
1776 char *endtag = decodedString(params.paramValue("endtag", "end"));
1777 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1778 int duration = clip->get_playtime();
1779 double max = params.paramValue("max").toDouble();
1780 double min = params.paramValue("min").toDouble();
1781 double factor = params.paramValue("factor", "1").toDouble();
1782 params.removeParam("starttag");
1783 params.removeParam("endtag");
1784 params.removeParam("keyframes");
1785 params.removeParam("min");
1786 params.removeParam("max");
1787 params.removeParam("factor");
1789 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1790 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1791 if (filter && filter->is_valid()) {
1792 filter->set("kdenlive_id", filterId);
1793 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1794 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1795 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1796 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1797 if (x2 == -1) x2 = duration;
1799 for (int j = 0; j < params.count(); j++) {
1800 char *name = decodedString(params.at(j).name());
1801 char *value = decodedString(params.at(j).value());
1802 filter->set(name, value);
1807 filter->set("in", x1);
1808 filter->set("out", x2);
1809 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1810 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1811 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1812 clipService.attach(*filter);
1819 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1820 if (filter && filter->is_valid())
1821 filter->set("kdenlive_id", filterId);
1823 kDebug() << "filter is NULL";
1824 m_isBlocked = false;
1828 params.removeParam("kdenlive_id");
1830 for (int j = 0; j < params.count(); j++) {
1831 char *name = decodedString(params.at(j).name());
1832 char *value = decodedString(params.at(j).value());
1833 filter->set(name, value);
1839 QString effectArgs = params.paramValue("id").section('_', 1);
1841 params.removeParam("id");
1842 params.removeParam("kdenlive_ix");
1843 params.removeParam("tag");
1844 params.removeParam("disabled");
1846 for (int j = 0; j < params.count(); j++) {
1847 effectArgs.append(' ' + params.at(j).value());
1849 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1850 char *value = decodedString(effectArgs.simplified());
1851 filter->set("effect", value);
1856 // attach filter to the clip
1857 clipService.attach(*filter);
1862 // re-add following filters
1863 for (int i = 0; i < filtersList.count(); i++) {
1864 clipService.attach(*(filtersList.at(i)));
1867 m_isBlocked = false;
1868 if (doRefresh) refresh();
1872 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
1873 QString index = params.paramValue("kdenlive_ix");
1874 QString tag = params.paramValue("tag");
1876 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1877 // This is a keyframe effect, to edit it, we remove it and re-add it.
1878 mltRemoveEffect(track, position, index);
1879 bool success = mltAddEffect(track, position, params);
1884 Mlt::Service service(m_mltProducer->parent().get_service());
1886 Mlt::Tractor tractor(service);
1887 Mlt::Producer trackProducer(tractor.track(track));
1888 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1889 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1890 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1892 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1895 Mlt::Service clipService(clip->get_service());
1898 Mlt::Filter *filter = clipService.filter(ct);
1900 if (filter->get("kdenlive_ix") == index) {
1904 filter = clipService.filter(ct);
1908 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1909 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1911 filter = clipService.filter(ct);
1912 QList <Mlt::Filter *> filtersList;
1914 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1915 filtersList.append(filter);
1916 clipService.detach(*filter);
1918 filter = clipService.filter(ct);
1920 bool success = mltAddEffect(track, position, params);
1922 for (int i = 0; i < filtersList.count(); i++) {
1923 clipService.attach(*(filtersList.at(i)));
1926 m_isBlocked = false;
1930 for (int j = 0; j < params.count(); j++) {
1931 char *name = decodedString(params.at(j).name());
1932 char *value = decodedString(params.at(j).value());
1933 filter->set(name, value);
1938 m_isBlocked = false;
1943 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1945 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1946 Mlt::Service service(m_mltProducer->parent().get_service());
1948 Mlt::Tractor tractor(service);
1949 Mlt::Producer trackProducer(tractor.track(track));
1950 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1951 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1952 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1954 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1957 Mlt::Service clipService(clip->get_service());
1960 QList <Mlt::Filter *> filtersList;
1961 Mlt::Filter *filter = clipService.filter(ct);
1963 if (newPos > oldPos) {
1965 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1966 filter->set("kdenlive_ix", newPos);
1967 filtersList.append(filter);
1968 clipService.detach(*filter);
1969 filter = clipService.filter(ct);
1970 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1971 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1973 filter = clipService.filter(ct);
1977 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1978 filtersList.append(filter);
1979 clipService.detach(*filter);
1981 filter = clipService.filter(ct);
1985 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1986 filter->set("kdenlive_ix", newPos);
1987 filtersList.append(filter);
1988 clipService.detach(*filter);
1990 filter = clipService.filter(ct);
1994 filter = clipService.filter(ct);
1996 int pos = QString(filter->get("kdenlive_ix")).toInt();
1997 if (pos >= newPos) {
1998 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
1999 filtersList.append(filter);
2000 clipService.detach(*filter);
2002 filter = clipService.filter(ct);
2006 for (int i = 0; i < filtersList.count(); i++) {
2007 clipService.attach(*(filtersList.at(i)));
2010 m_isBlocked = false;
2014 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
2017 Mlt::Service service(m_mltProducer->parent().get_service());
2019 Mlt::Tractor tractor(service);
2020 Mlt::Producer trackProducer(tractor.track(info.track));
2021 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2023 /* // Display playlist info
2024 kDebug()<<"//////////// BEFORE RESIZE";
2025 for (int i = 0; i < trackPlaylist.count(); i++) {
2026 int blankStart = trackPlaylist.clip_start(i);
2027 int blankDuration = trackPlaylist.clip_length(i) - 1;
2029 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2030 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
2033 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2034 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2035 m_isBlocked = false;
2038 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2039 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2040 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2041 int previousStart = clip->get_in();
2042 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2043 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2044 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2045 //trackPlaylist.consolidate_blanks(0);
2046 // skip to next clip
2048 int diff = newDuration - previousDuration;
2049 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
2051 // clip was made longer, trim next blank if there is one.
2052 if (trackPlaylist.is_blank(clipIndex)) {
2053 int blankStart = trackPlaylist.clip_start(clipIndex);
2054 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2055 if (diff - blankDuration == 1) {
2056 trackPlaylist.remove(clipIndex);
2057 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
2059 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2061 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2063 trackPlaylist.consolidate_blanks(0);
2066 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2067 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2068 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2069 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2070 ItemInfo transpinfo;
2071 transpinfo.startPos = info.startPos;
2072 transpinfo.endPos = info.startPos + clipDuration;
2073 transpinfo.track = info.track;
2074 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2076 m_isBlocked = false;
2077 m_mltConsumer->set("refresh", 1);
2081 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
2082 Mlt::Service service(m_mltProducer->parent().get_service());
2083 Mlt::Tractor tractor(service);
2084 Mlt::Producer trackProducer(tractor.track(track));
2087 if (blind) trackProducer.set("hide", 3);
2088 else trackProducer.set("hide", 2);
2090 trackProducer.set("hide", 1);
2092 trackProducer.set("hide", 0);
2094 tractor.multitrack()->refresh();
2099 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
2100 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2101 Mlt::Service service(m_mltProducer->parent().get_service());
2102 int moveFrame = (int) diff.frames(m_fps);
2103 Mlt::Tractor tractor(service);
2104 Mlt::Producer trackProducer(tractor.track(info.track));
2105 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2106 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2107 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2110 mlt_service_lock(service.get_service());
2111 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2112 /*int previousStart = trackPlaylist.clip_start(clipIndex);
2113 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
2114 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
2115 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2117 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2118 mlt_service_unlock(service.get_service());
2121 //m_mltConsumer->set("refresh", 0);
2122 int previousStart = clip->get_in();
2123 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2125 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2126 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2127 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2129 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2130 int blankIndex = clipIndex - 1;
2131 int blankLength = trackPlaylist.clip_length(blankIndex);
2132 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2133 if (! trackPlaylist.is_blank(blankIndex)) {
2134 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2136 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2137 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2139 trackPlaylist.consolidate_blanks(0);
2140 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2141 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2142 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2143 ItemInfo transpinfo;
2144 transpinfo.startPos = info.startPos + diff;
2145 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2146 transpinfo.track = info.track;
2147 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2149 m_isBlocked = false;
2150 //m_mltConsumer->set("refresh", 1);
2151 mlt_service_unlock(service.get_service());
2152 m_mltConsumer->set("refresh", 1);
2156 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
2157 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2161 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
2162 kDebug() << "NEW PROD ID: " << prod->get("id");
2163 m_mltConsumer->set("refresh", 0);
2164 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2165 mlt_service_lock(m_mltConsumer->get_service());
2166 Mlt::Service service(m_mltProducer->parent().get_service());
2167 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2169 Mlt::Tractor tractor(service);
2170 Mlt::Producer trackProducer(tractor.track(track));
2171 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2172 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2173 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2174 if (clipProducer.is_blank()) {
2175 kDebug() << "// ERROR UPDATING CLIP PROD";
2176 mlt_service_unlock(m_mltConsumer->get_service());
2177 m_isBlocked = false;
2180 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2182 // move all effects to the correct producer
2183 Mlt::Service clipService(clipProducer.get_service());
2184 Mlt::Service newClipService(clip->get_service());
2187 Mlt::Filter *filter = clipService.filter(ct);
2189 if (filter->get("kdenlive_ix") != 0) {
2190 clipService.detach(*filter);
2191 newClipService.attach(*filter);
2193 filter = clipService.filter(ct);
2196 trackPlaylist.insert_at(pos, clip, 1);
2197 mlt_service_unlock(m_mltConsumer->get_service());
2198 m_isBlocked = false;
2201 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
2204 m_mltConsumer->set("refresh", 0);
2205 mlt_service_lock(m_mltConsumer->get_service());
2206 Mlt::Service service(m_mltProducer->parent().get_service());
2207 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2209 Mlt::Tractor tractor(service);
2210 Mlt::Producer trackProducer(tractor.track(startTrack));
2211 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2212 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2213 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2214 bool checkLength = false;
2215 if (endTrack == startTrack) {
2216 //mlt_service_lock(service.get_service());
2217 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2218 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2219 // error, destination is not empty
2220 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2221 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2222 mlt_service_unlock(m_mltConsumer->get_service());
2223 m_isBlocked = false;
2226 trackPlaylist.consolidate_blanks(0);
2227 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2228 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2229 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2231 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2233 //mlt_service_unlock(service.get_service());
2235 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2236 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2237 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2238 // error, destination is not empty
2239 mlt_service_unlock(m_mltConsumer->get_service());
2240 m_isBlocked = false;
2243 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2244 if (clipProducer.is_blank()) {
2245 // error, destination is not empty
2246 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2247 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2248 mlt_service_unlock(m_mltConsumer->get_service());
2249 m_isBlocked = false;
2252 trackPlaylist.consolidate_blanks(0);
2253 destTrackPlaylist.consolidate_blanks(1);
2254 Mlt::Producer *clip;
2255 // check if we are moving a slowmotion producer
2256 QString serv = clipProducer.parent().get("mlt_service");
2257 if (serv == "framebuffer") {
2258 clip = &clipProducer;
2259 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2261 // move all effects to the correct producer
2262 Mlt::Service clipService(clipProducer.get_service());
2263 Mlt::Service newClipService(clip->get_service());
2266 Mlt::Filter *filter = clipService.filter(ct);
2268 if (filter->get("kdenlive_ix") != 0) {
2269 clipService.detach(*filter);
2270 newClipService.attach(*filter);
2272 filter = clipService.filter(ct);
2275 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2276 destTrackPlaylist.consolidate_blanks(0);
2277 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2278 kDebug() << "//////// moving clip transparency";
2279 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2281 if (clipIndex > trackPlaylist.count()) checkLength = true;
2282 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2286 if (checkLength) mltCheckLength();
2287 mlt_service_unlock(m_mltConsumer->get_service());
2288 m_isBlocked = false;
2289 m_mltConsumer->set("refresh", 1);
2293 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
2294 Mlt::Service service(m_mltProducer->parent().get_service());
2295 Mlt::Tractor tractor(service);
2296 Mlt::Field *field = tractor.field();
2298 mlt_service_lock(service.get_service());
2299 m_mltConsumer->set("refresh", 0);
2302 mlt_service serv = m_mltProducer->parent().get_service();
2303 mlt_service nextservice = mlt_service_get_producer(serv);
2304 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2305 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2306 QString resource = mlt_properties_get(properties, "mlt_service");
2307 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2309 int new_in = (int)newIn.frames(m_fps);
2310 int new_out = (int)newOut.frames(m_fps) - 1;
2312 while (mlt_type == "transition") {
2313 mlt_transition tr = (mlt_transition) nextservice;
2314 int currentTrack = mlt_transition_get_b_track(tr);
2315 int currentIn = (int) mlt_transition_get_in(tr);
2316 int currentOut = (int) mlt_transition_get_out(tr);
2318 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2319 mlt_transition_set_in_and_out(tr, new_in, new_out);
2320 if (newTrack - startTrack != 0) {
2321 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
2323 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2324 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2325 mlt_properties_set_int(properties, "b_track", newTrack);
2326 //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);
2330 nextservice = mlt_service_producer(nextservice);
2331 if (nextservice == NULL) break;
2332 properties = MLT_SERVICE_PROPERTIES(nextservice);
2333 mlt_type = mlt_properties_get(properties, "mlt_type");
2334 resource = mlt_properties_get(properties, "mlt_service");
2336 m_isBlocked = false;
2337 mlt_service_unlock(service.get_service());
2338 m_mltConsumer->set("refresh", 1);
2341 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2342 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2343 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2345 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2346 mltAddTransition(tag, a_track, b_track, in, out, xml);
2348 //mltSavePlaylist();
2351 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2353 Mlt::Service service(m_mltProducer->parent().get_service());
2354 Mlt::Tractor tractor(service);
2355 Mlt::Field *field = tractor.field();
2357 //m_mltConsumer->set("refresh", 0);
2358 mlt_service serv = m_mltProducer->parent().get_service();
2360 mlt_service nextservice = mlt_service_get_producer(serv);
2361 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2362 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2363 QString resource = mlt_properties_get(properties, "mlt_service");
2364 int in_pos = (int) in.frames(m_fps);
2365 int out_pos = (int) out.frames(m_fps) - 1;
2367 while (mlt_type == "transition") {
2368 mlt_transition tr = (mlt_transition) nextservice;
2369 int currentTrack = mlt_transition_get_b_track(tr);
2370 int currentBTrack = mlt_transition_get_a_track(tr);
2371 int currentIn = (int) mlt_transition_get_in(tr);
2372 int currentOut = (int) mlt_transition_get_out(tr);
2374 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2376 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2377 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2378 QMap<QString, QString>::Iterator it;
2380 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2381 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2382 if (currentBTrack != a_track) {
2383 mlt_properties_set_int(properties, "a_track", a_track);
2385 for (it = map.begin(); it != map.end(); ++it) {
2387 char *name = decodedString(key);
2388 char *value = decodedString(it.value());
2389 mlt_properties_set(transproperties, name, value);
2390 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2391 //filter->set("kdenlive_id", id);
2397 nextservice = mlt_service_producer(nextservice);
2398 if (nextservice == NULL) break;
2399 properties = MLT_SERVICE_PROPERTIES(nextservice);
2400 mlt_type = mlt_properties_get(properties, "mlt_type");
2401 resource = mlt_properties_get(properties, "mlt_service");
2403 m_isBlocked = false;
2404 m_mltConsumer->set("refresh", 1);
2407 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2408 Mlt::Service service(m_mltProducer->parent().get_service());
2409 Mlt::Tractor tractor(service);
2410 Mlt::Field *field = tractor.field();
2412 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2413 mlt_service serv = m_mltProducer->parent().get_service();
2415 mlt_service nextservice = mlt_service_get_producer(serv);
2416 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2417 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2418 QString resource = mlt_properties_get(properties, "mlt_service");
2420 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2422 while (mlt_type == "transition") {
2423 mlt_transition tr = (mlt_transition) nextservice;
2424 int currentTrack = mlt_transition_get_b_track(tr);
2425 int currentIn = (int) mlt_transition_get_in(tr);
2426 int currentOut = (int) mlt_transition_get_out(tr);
2427 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2429 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2430 mlt_field_disconnect_service(field->get_field(), nextservice);
2433 nextservice = mlt_service_producer(nextservice);
2434 if (nextservice == NULL) break;
2435 properties = MLT_SERVICE_PROPERTIES(nextservice);
2436 mlt_type = mlt_properties_get(properties, "mlt_type");
2437 resource = mlt_properties_get(properties, "mlt_service");
2439 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2442 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2443 QDomNodeList attribs = xml.elementsByTagName("parameter");
2444 QMap<QString, QString> map;
2445 for (int i = 0;i < attribs.count();i++) {
2446 QDomElement e = attribs.item(i).toElement();
2447 QString name = e.attribute("name");
2448 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2449 map[name] = e.attribute("default");
2450 if (!e.attribute("value").isEmpty()) {
2451 map[name] = e.attribute("value");
2453 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2454 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2455 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2458 if (e.attribute("namedesc").contains(";")) {
2459 QString format = e.attribute("format");
2460 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2461 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2463 QTextStream txtNeu(&neu);
2464 if (values.size() > 0)
2465 txtNeu << (int)values[0].toDouble();
2467 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2468 txtNeu << separators[i];
2469 txtNeu << (int)(values[i+1].toDouble());
2471 if (i < separators.size())
2472 txtNeu << separators[i];
2473 map[e.attribute("name")] = neu;
2480 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2481 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2482 Mlt::Service service(m_mltProducer->parent().get_service());
2483 Mlt::Tractor tractor(service);
2484 Mlt::Field *field = tractor.field();
2486 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2487 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2488 transition->set("transparency", id);
2489 transition->set("fill", 1);
2490 transition->set("internal_added", 237);
2491 field->plant_transition(*transition, transitiontrack, info.track);
2495 void Render::mltDeleteTransparency(int pos, int track, int id) {
2496 Mlt::Service service(m_mltProducer->parent().get_service());
2497 Mlt::Tractor tractor(service);
2498 Mlt::Field *field = tractor.field();
2500 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2501 mlt_service serv = m_mltProducer->parent().get_service();
2503 mlt_service nextservice = mlt_service_get_producer(serv);
2504 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2505 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2506 QString resource = mlt_properties_get(properties, "mlt_service");
2508 while (mlt_type == "transition") {
2509 mlt_transition tr = (mlt_transition) nextservice;
2510 int currentTrack = mlt_transition_get_b_track(tr);
2511 int currentIn = (int) mlt_transition_get_in(tr);
2512 int currentOut = (int) mlt_transition_get_out(tr);
2513 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2514 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2516 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2517 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2518 mlt_field_disconnect_service(field->get_field(), nextservice);
2521 nextservice = mlt_service_producer(nextservice);
2522 if (nextservice == NULL) break;
2523 properties = MLT_SERVICE_PROPERTIES(nextservice);
2524 mlt_type = mlt_properties_get(properties, "mlt_type");
2525 resource = mlt_properties_get(properties, "mlt_service");
2527 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2530 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2531 Mlt::Service service(m_mltProducer->parent().get_service());
2532 Mlt::Tractor tractor(service);
2533 Mlt::Field *field = tractor.field();
2535 mlt_service_lock(service.get_service());
2536 m_mltConsumer->set("refresh", 0);
2539 mlt_service serv = m_mltProducer->parent().get_service();
2540 mlt_service nextservice = mlt_service_get_producer(serv);
2541 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2542 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2543 QString resource = mlt_properties_get(properties, "mlt_service");
2544 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2545 while (mlt_type == "transition") {
2546 mlt_transition tr = (mlt_transition) nextservice;
2547 int currentTrack = mlt_transition_get_b_track(tr);
2548 int currentIn = (int) mlt_transition_get_in(tr);
2549 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2550 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2551 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2552 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2553 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2554 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2557 nextservice = mlt_service_producer(nextservice);
2558 if (nextservice == NULL) break;
2559 properties = MLT_SERVICE_PROPERTIES(nextservice);
2560 mlt_type = mlt_properties_get(properties, "mlt_type");
2561 resource = mlt_properties_get(properties, "mlt_service");
2563 m_isBlocked = false;
2564 mlt_service_unlock(service.get_service());
2565 m_mltConsumer->set("refresh", 1);
2569 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2570 Mlt::Service service(m_mltProducer->parent().get_service());
2571 Mlt::Tractor tractor(service);
2572 Mlt::Field *field = tractor.field();
2574 mlt_service_lock(service.get_service());
2575 m_mltConsumer->set("refresh", 0);
2578 mlt_service serv = m_mltProducer->parent().get_service();
2579 mlt_service nextservice = mlt_service_get_producer(serv);
2580 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2581 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2582 QString resource = mlt_properties_get(properties, "mlt_service");
2584 while (mlt_type == "transition") {
2585 mlt_transition tr = (mlt_transition) nextservice;
2586 int currentTrack = mlt_transition_get_b_track(tr);
2587 int currentaTrack = mlt_transition_get_a_track(tr);
2588 int currentIn = (int) mlt_transition_get_in(tr);
2589 int currentOut = (int) mlt_transition_get_out(tr);
2590 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2591 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2592 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2593 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2594 kDebug() << "//////MOVING";
2595 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2596 if (endTrack != startTrack) {
2597 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2598 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2599 mlt_properties_set_int(properties, "b_track", endTrack);
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 m_isBlocked = false;
2610 mlt_service_unlock(service.get_service());
2611 m_mltConsumer->set("refresh", 1);
2615 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2617 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2618 Mlt::Service service(m_mltProducer->parent().get_service());
2620 Mlt::Tractor tractor(service);
2621 Mlt::Field *field = tractor.field();
2623 char *transId = decodedString(tag);
2624 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2625 if (out != GenTime())
2626 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2627 QMap<QString, QString>::Iterator it;
2629 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2630 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2632 for (it = args.begin(); it != args.end(); ++it) {
2634 char *name = decodedString(key);
2635 char *value = decodedString(it.value());
2636 transition->set(name, value);
2637 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2638 //filter->set("kdenlive_id", id);
2642 // attach filter to the clip
2643 field->plant_transition(*transition, a_track, b_track);
2648 void Render::mltSavePlaylist() {
2649 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2650 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2651 fileConsumer.set("resource", "/tmp/playlist.westley");
2653 Mlt::Service service(m_mltProducer->get_service());
2655 fileConsumer.connect(service);
2656 fileConsumer.start();
2659 QList <Mlt::Producer *> Render::producersList() {
2660 QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
2662 Mlt::Service service(m_mltProducer->parent().get_service());
2663 Mlt::Tractor tractor(service);
2665 int trackNb = tractor.count();
2666 for (int t = 1; t < trackNb; t++) {
2667 Mlt::Producer trackProducer(tractor.track(t));
2668 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2669 int clipNb = trackPlaylist.count();
2670 kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2671 for (int i = 0; i < clipNb; i++) {
2672 Mlt::Producer *prod = trackPlaylist.get_clip(i);
2673 Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
2674 //kDebug()<<"PROD: "<<nprod->get("producer")<<", ID: "<<nprod->get("id")<<nprod->get("resource");
2675 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2676 ids.append(nprod->get("id"));
2677 prods.append(nprod);
2684 void Render::mltInsertTrack(int ix, bool videoTrack) {
2688 m_mltConsumer->set("refresh", 0);
2689 mlt_service_lock(m_mltConsumer->get_service());
2690 Mlt::Service service(m_mltProducer->parent().get_service());
2691 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2693 Mlt::Tractor tractor(service);
2695 Mlt::Playlist playlist;// = new Mlt::Playlist();
2696 int ct = tractor.count();
2697 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2700 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2701 tractor.set_track(playlist, pos);
2702 Mlt::Producer newProd(tractor.track(pos));
2703 if (!videoTrack) newProd.set("hide", 1);
2705 for (; pos <= ct; pos++) {
2706 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2707 tractor.set_track(*prodToMove, pos);
2708 prodToMove = prodToMove2;
2711 tractor.set_track(playlist, ix);
2712 Mlt::Producer newProd(tractor.track(ix));
2713 if (!videoTrack) newProd.set("hide", 1);
2717 mlt_service serv = m_mltProducer->parent().get_service();
2718 mlt_service nextservice = mlt_service_get_producer(serv);
2719 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2720 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2721 QString resource = mlt_properties_get(properties, "mlt_service");
2723 while (mlt_type == "transition") {
2724 if (resource != "mix") {
2725 mlt_transition tr = (mlt_transition) nextservice;
2726 int currentTrack = mlt_transition_get_b_track(tr);
2727 int currentaTrack = mlt_transition_get_a_track(tr);
2728 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2730 if (currentTrack >= ix) {
2731 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2732 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2735 nextservice = mlt_service_producer(nextservice);
2736 if (nextservice == NULL) break;
2737 properties = MLT_SERVICE_PROPERTIES(nextservice);
2738 mlt_type = mlt_properties_get(properties, "mlt_type");
2739 resource = mlt_properties_get(properties, "mlt_service");
2742 // Add audio mix transition to last track
2743 Mlt::Field *field = tractor.field();
2744 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2745 //transition->set("mlt_service", "mix");
2746 transition->set("a_track", 1);
2747 transition->set("b_track", ct);
2748 transition->set("always_active", 1);
2749 transition->set("internal_added", 237);
2750 transition->set("combine", 1);
2751 field->plant_transition(*transition, 1, ct);
2753 mlt_service_unlock(m_mltConsumer->get_service());
2754 m_isBlocked = false;
2755 blockSignals(false);
2759 void Render::mltDeleteTrack(int ix) {
2761 doc.setContent(sceneList(), false);
2762 int tracksCount = doc.elementsByTagName("track").count() - 1;
2763 QDomNode track = doc.elementsByTagName("track").at(ix);
2764 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2765 QDomNodeList transitions = doc.elementsByTagName("transition");
2766 for (int i = 0; i < transitions.count(); i++) {
2767 QDomElement e = transitions.at(i).toElement();
2768 QDomNodeList props = e.elementsByTagName("property");
2769 QMap <QString, QString> mappedProps;
2770 for (int j = 0; j < props.count(); j++) {
2771 QDomElement f = props.at(j).toElement();
2772 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2774 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2775 tractor.removeChild(transitions.at(i));
2776 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2777 // Transition needs to be moved
2778 int a_track = mappedProps.value("a_track").toInt();
2779 int b_track = mappedProps.value("b_track").toInt();
2780 if (a_track > 0) a_track --;
2781 if (b_track > 0) b_track --;
2782 for (int j = 0; j < props.count(); j++) {
2783 QDomElement f = props.at(j).toElement();
2784 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2785 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2790 tractor.removeChild(track);
2791 setSceneList(doc.toString(), m_framePosition);
2797 m_mltConsumer->set("refresh", 0);
2798 mlt_service_lock(m_mltConsumer->get_service());
2799 Mlt::Service service(m_mltProducer->parent().get_service());
2800 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2802 /*Mlt::Tractor tractor(service);
2805 Mlt::Multitrack *multi = tractor.multitrack();
2808 int ct = tractor.count();
2809 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
2811 for (; pos < ct ; pos++) {
2812 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
2813 //mlt_service_close(lastTrack->get_service());
2815 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
2816 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
2817 mlt_service_close(prodToMove->get_service());
2818 mlt_service_close(prodToClose->get_service());
2819 tractor.set_track(*prodToMove, pos);
2823 /*mlt_service serv = m_mltProducer->parent().get_service();
2824 mlt_service nextservice = mlt_service_get_producer(serv);
2825 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2826 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2827 QString resource = mlt_properties_get(properties, "mlt_service");
2829 while (mlt_type == "transition") {
2830 if (resource != "mix") {
2831 mlt_transition tr = (mlt_transition) nextservice;
2832 int currentTrack = mlt_transition_get_b_track(tr);
2833 int currentaTrack = mlt_transition_get_a_track(tr);
2834 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2836 if (currentTrack >= ix) {
2837 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2838 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2841 nextservice = mlt_service_producer(nextservice);
2842 if (nextservice == NULL) break;
2843 properties = MLT_SERVICE_PROPERTIES(nextservice);
2844 mlt_type = mlt_properties_get(properties, "mlt_type");
2845 resource = mlt_properties_get(properties, "mlt_service");
2848 // Add audio mix transition to last track
2849 Mlt::Field *field = tractor.field();
2850 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2851 //transition->set("mlt_service", "mix");
2852 transition->set("a_track", 1);
2853 transition->set("b_track", ct);
2854 transition->set("always_active", 1);
2855 transition->set("internal_added", 237);
2856 transition->set("combine", 1);
2857 field->plant_transition(*transition, 1, ct);
2860 mlt_service_unlock(m_mltConsumer->get_service());
2861 m_isBlocked = false;
2862 blockSignals(false);
2865 #include "renderer.moc"