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");
68 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black");
69 m_mltProducer = producer;
70 if (m_blackClip) delete m_blackClip;
71 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
72 m_blackClip->set("id", "black");
73 m_mltConsumer->connect(*m_mltProducer);
74 m_mltProducer->set_speed(0.0);
82 void Render::closeMlt() {
89 if (m_blackClip) delete m_blackClip;
94 void Render::buildConsumer() {
96 tmp = decodedString(KdenliveSettings::current_profile());
97 m_mltProfile = new Mlt::Profile(tmp);
100 QString videoDriver = KdenliveSettings::videodrivername();
101 if (!videoDriver.isEmpty()) {
102 if (videoDriver == "x11_noaccel") {
103 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
106 unsetenv("SDL_VIDEO_YUV_HWACCEL");
109 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
111 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
112 m_mltConsumer->set("resize", 1);
113 m_mltConsumer->set("window_id", m_winid);
114 m_mltConsumer->set("terminate_on_pause", 1);
116 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
117 m_mltConsumer->set("rescale", "nearest");
119 QString audioDevice = KdenliveSettings::audiodevicename();
120 if (!audioDevice.isEmpty()) {
121 tmp = decodedString(audioDevice);
122 m_mltConsumer->set("audio_device", tmp);
126 if (!videoDriver.isEmpty()) {
127 tmp = decodedString(videoDriver);
128 m_mltConsumer->set("video_driver", tmp);
132 QString audioDriver = KdenliveSettings::audiodrivername();
133 if (!audioDriver.isEmpty()) {
134 tmp = decodedString(audioDriver);
135 m_mltConsumer->set("audio_driver", tmp);
140 m_mltConsumer->set("progressive", 1);
141 m_mltConsumer->set("audio_buffer", 1024);
142 m_mltConsumer->set("frequency", 48000);
145 int Render::resetProfile() {
146 if (!m_mltConsumer) return 0;
147 QString currentProfile = getenv("MLT_PROFILE");
148 if (currentProfile == KdenliveSettings::current_profile()) {
149 kDebug() << "reset to same profile, nothing to do";
152 kDebug() << "// RESETTING PROFILE FROM: " << currentProfile << " TO: " << KdenliveSettings::current_profile();
153 if (m_isSplitView) slotSplitView(false);
154 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
155 m_mltConsumer->purge();
156 delete m_mltConsumer;
157 m_mltConsumer = NULL;
158 QString scene = sceneList();
161 pos = m_mltProducer->position();
162 delete m_mltProducer;
164 m_mltProducer = NULL;
165 if (m_mltProfile) delete m_mltProfile;
169 //kDebug() << "//RESET WITHSCENE: " << scene;
170 setSceneList(scene, pos);
172 char *tmp = decodedString(scene);
173 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
175 m_mltProducer = producer;
176 if (m_blackClip) delete m_blackClip;
177 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
178 m_mltProducer->optimise();
179 m_mltProducer->set_speed(0);
182 //delete m_mltProfile;
183 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
184 //mlt_profile prof = m_mltProfile->get_profile();
185 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
186 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
187 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
188 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
190 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
195 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
196 void Render::seek(GenTime time) {
200 m_mltProducer->seek((int)(time.frames(m_fps)));
205 char *Render::decodedString(QString str) {
206 /*QCString fn = QFile::encodeName(str);
207 char *t = new char[fn.length() + 1];
208 strcpy(t, (const char *)fn);*/
210 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
214 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
215 QPixmap pix(width, height);
217 mlt_image_format format = mlt_image_rgb24a;
218 uint8_t *thumb = frame->get_image(format, width, height);
219 QImage image(thumb, width, height, QImage::Format_ARGB32);
221 if (!image.isNull()) {
222 pix = pix.fromImage(image);
224 QPainter painter(&pix);
225 painter.drawRect(0, 0, width - 1, height - 1);
227 } else pix.fill(Qt::black);
231 const int Render::renderWidth() const {
232 return (int)(m_mltProfile->height() * m_mltProfile->dar());
235 const int Render::renderHeight() const {
236 return m_mltProfile->height();
239 QPixmap Render::extractFrame(int frame_position, int width, int height) {
241 width = renderWidth();
242 height = renderHeight();
244 QPixmap pix(width, height);
245 if (!m_mltProducer) {
249 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
252 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
255 if (url.fileName().startsWith(".all.")) { // check for slideshow
256 QString fileType = url.fileName().right(3);
258 QStringList::Iterator it;
260 QDir dir(url.directory());
262 filter << "*." + fileType;
263 filter << "*." + fileType.toUpper();
264 more = dir.entryList(filter, QDir::Files);
265 im.load(url.directory() + "/" + more.at(0));
266 } else im.load(url.path());
267 //pixmap = im.scaled(width, height);
272 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
273 QPixmap pix(width, height);
274 char *tmp = decodedString(file);
275 Mlt::Profile *prof = new Mlt::Profile(profile);
276 Mlt::Producer m_producer(*prof, tmp);
278 if (m_producer.is_blank()) {
283 Mlt::Filter m_convert(*prof, "avcolour_space");
284 m_convert.set("forced", mlt_image_rgb24a);
285 m_producer.attach(m_convert);
286 m_producer.seek(frame_position);
287 Mlt::Frame * frame = m_producer.get_frame();
289 pix = frameThumbnail(frame, width, height, true);
292 if (prof) delete prof;
297 void Render::getImage(KUrl url, int frame_position, QPoint size)
299 char *tmp = decodedString(url.path());
300 Mlt::Producer m_producer(tmp);
302 if (m_producer.is_blank()) {
305 Mlt::Filter m_convert("avcolour_space");
306 m_convert.set("forced", mlt_image_rgb24a);
307 m_producer.attach(m_convert);
308 m_producer.seek(frame_position);
310 Mlt::Frame * frame = m_producer.get_frame();
313 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
315 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
319 /* Create thumbnail for color */
320 /*void Render::getImage(int id, QString color, QPoint size)
322 QPixmap pixmap(size.x() - 2, size.y() - 2);
323 color = color.replace(0, 2, "#");
324 color = color.left(7);
325 pixmap.fill(QColor(color));
326 QPixmap result(size.x(), size.y());
327 result.fill(Qt::black);
328 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
329 emit replyGetImage(id, result, size.x(), size.y());
333 /* Create thumbnail for image */
334 /*void Render::getImage(KUrl url, QPoint size)
338 if (url.fileName().startsWith(".all.")) { // check for slideshow
339 QString fileType = url.fileName().right(3);
341 QStringList::Iterator it;
343 QDir dir( url.directory() );
344 more = dir.entryList( QDir::Files );
345 for ( it = more.begin() ; it != more.end() ; ++it ) {
346 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
347 if (!im.load(url.directory() + "/" + *it))
348 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
353 else im.load(url.path());
355 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
356 QPixmap result(size.x(), size.y());
357 result.fill(Qt::black);
358 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
359 emit replyGetImage(url, 1, result, size.x(), size.y());
363 double Render::consumerRatio() const {
364 if (!m_mltConsumer) return 1.0;
365 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
369 int Render::getLength() {
372 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
373 return mlt_producer_get_playtime(m_mltProducer->get_producer());
378 bool Render::isValid(KUrl url) {
379 char *tmp = decodedString(url.path());
380 Mlt::Producer producer(*m_mltProfile, tmp);
382 if (producer.is_blank())
388 const double Render::dar() const {
389 return m_mltProfile->dar();
392 void Render::slotSplitView(bool doit) {
393 m_isSplitView = doit;
394 Mlt::Service service(m_mltProducer->parent().get_service());
395 Mlt::Tractor tractor(service);
396 if (service.type() != tractor_type || tractor.count() < 2) return;
397 Mlt::Field *field = tractor.field();
400 for (int i = 1; i < tractor.count() && screen < 4; i++) {
401 Mlt::Producer trackProducer(tractor.track(i));
402 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
403 if (QString(trackProducer.get("hide")).toInt() != 1) {
404 kDebug() << "// ADIDNG TRACK: " << i;
405 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
406 transition->set("mlt_service", "composite");
407 transition->set("a_track", 0);
408 transition->set("b_track", i);
409 transition->set("distort", 1);
410 transition->set("internal_added", "200");
417 tmp = "50%,0:50%x50%";
420 tmp = "0,50%:50%x50%";
423 tmp = "50%,50%:50%x50%";
426 transition->set("geometry", tmp);
427 transition->set("always_active", "1");
428 field->plant_transition(*transition, 0, i);
433 m_mltConsumer->set("refresh", 1);
435 mlt_service serv = m_mltProducer->parent().get_service();
436 mlt_service nextservice = mlt_service_get_producer(serv);
437 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
438 QString mlt_type = mlt_properties_get(properties, "mlt_type");
439 QString resource = mlt_properties_get(properties, "mlt_service");
441 while (mlt_type == "transition") {
442 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
443 if (added == "200") {
444 mlt_field_disconnect_service(field->get_field(), nextservice);
446 nextservice = mlt_service_producer(nextservice);
447 if (nextservice == NULL) break;
448 properties = MLT_SERVICE_PROPERTIES(nextservice);
449 mlt_type = mlt_properties_get(properties, "mlt_type");
450 resource = mlt_properties_get(properties, "mlt_service");
451 m_mltConsumer->set("refresh", 1);
456 void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
458 int width = (int)(height * m_mltProfile->dar());
459 QMap < QString, QString > filePropertyMap;
460 QMap < QString, QString > metadataPropertyMap;
462 KUrl url = KUrl(xml.attribute("resource", QString::null));
463 Mlt::Producer *producer = NULL;
464 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
465 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
468 if (xml.attribute("type").toInt() == COLOR) {
469 char *tmp = decodedString("colour:" + xml.attribute("colour"));
470 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
472 } else if (url.isEmpty()) {
474 QDomElement westley = doc.createElement("westley");
475 QDomElement play = doc.createElement("playlist");
476 doc.appendChild(westley);
477 westley.appendChild(play);
478 play.appendChild(doc.importNode(xml, true));
479 char *tmp = decodedString(doc.toString());
480 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
483 QString urlpath = url.path();
484 /*if (urlpath.contains(':')) {
485 if (!urlpath.startsWith("file:")) urlpath.prepend("file:");
486 char *tmp = decodedString(urlpath);
487 producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp);
491 char *tmp = decodedString(urlpath);
492 producer = new Mlt::Producer(*m_mltProfile, tmp);
495 if (xml.hasAttribute("force_aspect_ratio")) {
496 double aspect = xml.attribute("force_aspect_ratio").toDouble();
497 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
499 if (xml.hasAttribute("threads")) {
500 int threads = xml.attribute("threads").toInt();
501 if (threads != 1) producer->set("threads", threads);
503 if (xml.hasAttribute("video_index")) {
504 int vindex = xml.attribute("video_index").toInt();
505 if (vindex != 0) producer->set("video_index", vindex);
507 if (xml.hasAttribute("audio_index")) {
508 int aindex = xml.attribute("audio_index").toInt();
509 if (aindex != 0) producer->set("audio_index", aindex);
514 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
515 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
516 emit removeInvalidClip(clipId);
520 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
522 char *tmp = decodedString(clipId);
523 producer->set("id", tmp);
525 int frameNumber = xml.attribute("thumbnail", "0").toInt();
526 if (frameNumber != 0) producer->seek(frameNumber);
527 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
529 filePropertyMap["duration"] = QString::number(producer->get_playtime());
530 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
532 Mlt::Frame *frame = producer->get_frame();
534 if (xml.attribute("type").toInt() == SLIDESHOW) {
535 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
536 if (xml.attribute("fade") == "1") {
537 // user wants a fade effect to slideshow
538 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
539 if (filter && filter->is_valid()) {
540 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
541 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
542 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
543 char *tmp = decodedString(xml.attribute("luma_file"));
544 filter->set("luma.resource", tmp);
546 if (xml.hasAttribute("softness")) {
547 int soft = xml.attribute("softness").toInt();
548 filter->set("luma.softness", (double) soft / 100.0);
551 Mlt::Service clipService(producer->get_service());
552 clipService.attach(*filter);
558 filePropertyMap["fps"] = producer->get("source_fps");
560 if (frame && frame->is_valid()) {
561 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
562 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
563 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
564 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
566 if (frame->get_int("test_image") == 0) {
567 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
568 filePropertyMap["type"] = "playlist";
569 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
570 } else if (frame->get_int("test_audio") == 0)
571 filePropertyMap["type"] = "av";
573 filePropertyMap["type"] = "video";
575 mlt_image_format format = mlt_image_yuv422;
577 int frame_height = 0;
578 //frame->set("rescale.interp", "hyper");
579 frame->set("normalised_height", height);
580 frame->set("normalised_width", width);
581 QPixmap pix(width, height);
583 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
584 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
585 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
586 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
588 if (!image.isNull()) {
589 pix = QPixmap::fromImage(image.rgbSwapped());
593 mlt_pool_release(new_image);
594 emit replyGetImage(clipId, 0, pix, width, height);
596 } else if (frame->get_int("test_audio") == 0) {
597 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
598 emit replyGetImage(clipId, 0, pixmap, width, height);
599 filePropertyMap["type"] = "audio";
603 // Retrieve audio / video codec name
607 if (producer->get_int("video_index") > -1) {
608 /*if (context->duration == AV_NOPTS_VALUE) {
609 kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
610 emit removeInvalidClip(clipId);
613 // Get the video_index
614 int default_video = producer->get_int("video_index");
616 int default_audio = producer->get_int("audio_index");
619 // Find maximum stream index values
620 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
621 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
622 QString type = producer->get(property);
625 else if (type == "audio")
628 filePropertyMap["default_video"] = QString::number(default_video);
629 filePropertyMap["video_max"] = QString::number(video_max);
630 filePropertyMap["default_audio"] = QString::number(default_audio);
631 filePropertyMap["audio_max"] = QString::number(audio_max);
633 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
634 if (producer->get(property)) {
635 filePropertyMap["videocodec"] = producer->get(property);
637 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
638 if (producer->get(property))
639 filePropertyMap["videocodec"] = producer->get(property);
641 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
642 if (producer->get_int("audio_index") > -1) {
643 // Get the audio_index
644 int index = producer->get_int("audio_index");
646 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
647 if (producer->get(property)) {
648 filePropertyMap["audiocodec"] = producer->get(property);
650 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
651 if (producer->get(property))
652 filePropertyMap["audiocodec"] = producer->get(property);
657 Mlt::Properties metadata;
658 metadata.pass_values(*producer, "meta.attr.");
659 int count = metadata.count();
660 for (int i = 0; i < count; i ++) {
661 QString name = metadata.get_name(i);
662 QString value = QString::fromUtf8(metadata.get(i));
663 if (name.endsWith("markup") && !value.isEmpty())
664 metadataPropertyMap[ name.section(".", 0, -2)] = value;
667 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
668 kDebug() << "REquested fuile info for: " << url.path();
669 if (frame) delete frame;
670 //if (producer) delete producer;
674 /** Create the producer from the Westley QDomDocument */
676 void Render::initSceneList() {
677 kDebug() << "-------- INIT SCENE LIST ------_";
679 QDomElement westley = doc.createElement("westley");
680 doc.appendChild(westley);
681 QDomElement prod = doc.createElement("producer");
682 prod.setAttribute("resource", "colour");
683 prod.setAttribute("colour", "red");
684 prod.setAttribute("id", "black");
685 prod.setAttribute("in", "0");
686 prod.setAttribute("out", "0");
688 QDomElement tractor = doc.createElement("tractor");
689 QDomElement multitrack = doc.createElement("multitrack");
691 QDomElement playlist1 = doc.createElement("playlist");
692 playlist1.appendChild(prod);
693 multitrack.appendChild(playlist1);
694 QDomElement playlist2 = doc.createElement("playlist");
695 multitrack.appendChild(playlist2);
696 QDomElement playlist3 = doc.createElement("playlist");
697 multitrack.appendChild(playlist3);
698 QDomElement playlist4 = doc.createElement("playlist");
699 multitrack.appendChild(playlist4);
700 QDomElement playlist5 = doc.createElement("playlist");
701 multitrack.appendChild(playlist5);
702 tractor.appendChild(multitrack);
703 westley.appendChild(tractor);
704 // kDebug()<<doc.toString();
706 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
707 setSceneList(doc, 0);
713 /** Create the producer from the Westley QDomDocument */
714 void Render::setProducer(Mlt::Producer *producer, int position) {
715 if (m_winid == -1) return;
718 m_mltConsumer->stop();
723 m_mltProducer->set_speed(0);
724 delete m_mltProducer;
725 m_mltProducer = NULL;
728 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
729 else m_mltProducer = new Mlt::Producer();
730 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
732 m_fps = m_mltProducer->get_fps();
734 if (position != -1) {
735 m_mltProducer->seek(position);
736 emit rendererPosition(position);
743 /** Create the producer from the Westley QDomDocument */
744 void Render::setSceneList(QDomDocument list, int position) {
745 setSceneList(list.toString(), position);
748 /** Create the producer from the Westley QDomDocument */
749 void Render::setSceneList(QString playlist, int position) {
750 if (m_winid == -1) return;
753 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
756 m_mltConsumer->stop();
757 //m_mltConsumer->set("refresh", 0);
764 m_mltProducer->set_speed(0);
765 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
767 delete m_mltProducer;
768 m_mltProducer = NULL;
773 char *tmp = decodedString(playlist);
774 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
776 if (m_blackClip) delete m_blackClip;
777 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
778 m_blackClip->set("id", "black");
779 if (!m_mltProducer || !m_mltProducer->is_valid()) {
780 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
782 m_mltProducer->optimise();
784 /*if (KdenliveSettings::osdtimecode()) {
785 // Attach filter for on screen display of timecode
787 QString attr = "attr_check";
788 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
789 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
790 mlt_producer_attach( m_mltProducer->get_producer(), filter );
791 mlt_filter_close( filter );
793 m_osdInfo = new Mlt::Filter("data_show");
794 tmp = decodedString(m_osdProfile);
795 m_osdInfo->set("resource", tmp);
797 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
798 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
799 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
800 m_osdInfo->set("dynamic", "1");
802 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
804 m_osdInfo->set("dynamic", "0");
807 m_fps = m_mltProducer->get_fps();
808 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
811 //TODO: seek to correct place after opening project.
812 // Needs to be done from another place since it crashes here.
813 m_mltProducer->seek(position);
817 //kDebug()<<"// SETSCN LST, POS: "<<position;
818 //if (position != 0) emit rendererPosition(position);
821 /** Create the producer from the Westley QDomDocument */
822 QString Render::sceneList() {
824 Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
825 m_mltProducer->optimise();
826 westleyConsumer.set("terminate_on_pause", 1);
827 Mlt::Producer prod(m_mltProducer->get_producer());
828 bool split = m_isSplitView;
829 if (split) slotSplitView(false);
830 westleyConsumer.connect(prod);
831 westleyConsumer.start();
832 while (!westleyConsumer.is_stopped()) {}
833 playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
834 if (split) slotSplitView(true);
838 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
841 doc.setContent(sceneList(), false);
842 if (!kdenliveData.isNull()) {
843 // add Kdenlive specific tags
844 QDomNode wes = doc.elementsByTagName("westley").at(0);
845 wes.appendChild(doc.importNode(kdenliveData, true));
847 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
848 kWarning() << "////// ERROR writing to file: " << path;
851 QTextStream out(&file);
852 out << doc.toString();
857 void Render::saveZone(KUrl url, QString desc, QPoint zone) {
858 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
859 char *tmppath = decodedString("westley:" + url.path());
860 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
861 m_mltProducer->optimise();
863 westleyConsumer.set("terminate_on_pause", 1);
864 if (m_name == "clip") {
865 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
866 tmppath = decodedString(desc);
868 list.insert_at(0, prod, 0);
869 list.set("title", tmppath);
871 westleyConsumer.connect(list);
874 //TODO: not working yet, save zone from timeline
875 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
876 /* Mlt::Service service(p1->parent().get_service());
877 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
879 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
880 tmppath = decodedString(desc);
881 //prod->set("title", tmppath);
883 westleyConsumer.connect(*p1); //list);
886 westleyConsumer.start();
889 const double Render::fps() const {
893 void Render::connectPlaylist() {
894 if (!m_mltConsumer) return;
895 //m_mltConsumer->set("refresh", "0");
896 m_mltConsumer->connect(*m_mltProducer);
897 m_mltProducer->set_speed(0);
898 m_mltConsumer->start();
899 emit durationChanged(m_mltProducer->get_playtime());
902 if (m_mltConsumer->start() == -1) {
903 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."));
904 m_mltConsumer = NULL;
911 void Render::refreshDisplay() {
913 if (!m_mltProducer) return;
914 //m_mltConsumer->set("refresh", 0);
916 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
917 /*if (KdenliveSettings::osdtimecode()) {
918 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
919 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
920 m_osdInfo->set("dynamic", "1");
921 m_mltProducer->attach(*m_osdInfo);
924 m_mltProducer->detach(*m_osdInfo);
925 m_osdInfo->set("dynamic", "0");
930 void Render::setVolume(double volume) {
931 if (!m_mltConsumer || !m_mltProducer) return;
933 m_mltConsumer->set("refresh", 0);
934 // Attach filter for on screen display of timecode
935 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
936 mlt_properties_set_double( properties, "meta.volume", volume );
937 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
938 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
940 if (!KdenliveSettings::osdtimecode()) {
941 m_mltProducer->detach(*m_osdInfo);
942 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
943 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
946 osdTimer->setSingleShot(2500);
949 void Render::slotOsdTimeout() {
950 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
951 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
952 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
953 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
957 void Render::start() {
958 kDebug() << "----- STARTING MONITOR: " << m_name;
960 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
964 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
965 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
966 if (m_mltConsumer->start() == -1) {
967 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."));
968 m_mltConsumer = NULL;
971 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
979 void Render::clear() {
980 kDebug() << " ********* RENDER CLEAR";
982 //m_mltConsumer->set("refresh", 0);
983 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
987 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
988 m_mltProducer->set_speed(0.0);
989 delete m_mltProducer;
990 m_mltProducer = NULL;
995 void Render::stop() {
996 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
997 kDebug() << "///////////// RENDER STOPPED: " << m_name;
999 m_mltConsumer->set("refresh", 0);
1000 m_mltConsumer->stop();
1001 // delete m_mltConsumer;
1002 // m_mltConsumer = NULL;
1004 kDebug() << "///////////// RENDER STOP2-------";
1007 if (m_mltProducer) {
1008 if (m_isZoneMode) resetZoneMode();
1009 m_mltProducer->set_speed(0.0);
1010 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1011 //kDebug() << m_mltProducer->get_length();
1013 kDebug() << "///////////// RENDER STOP3-------";
1016 void Render::stop(const GenTime & startTime) {
1018 kDebug() << "///////////// RENDER STOP-------2";
1019 if (m_mltProducer) {
1020 if (m_isZoneMode) resetZoneMode();
1021 m_mltProducer->set_speed(0.0);
1022 m_mltProducer->seek((int) startTime.frames(m_fps));
1024 m_mltConsumer->purge();
1027 void Render::pause() {
1028 if (!m_mltProducer || !m_mltConsumer)
1030 if (m_mltProducer->get_speed() == 0.0) return;
1031 if (m_isZoneMode) resetZoneMode();
1033 m_mltConsumer->set("refresh", 0);
1034 m_mltProducer->set_speed(0.0);
1035 emit rendererPosition(m_framePosition);
1036 m_mltProducer->seek(m_framePosition);
1037 m_mltConsumer->purge();
1040 void Render::switchPlay() {
1041 if (!m_mltProducer || !m_mltConsumer)
1043 if (m_isZoneMode) resetZoneMode();
1044 if (m_mltProducer->get_speed() == 0.0) {
1045 m_isBlocked = false;
1046 m_mltProducer->set_speed(1.0);
1047 m_mltConsumer->set("refresh", 1);
1050 m_mltConsumer->set("refresh", 0);
1051 m_mltProducer->set_speed(0.0);
1052 emit rendererPosition(m_framePosition);
1053 m_mltProducer->seek(m_framePosition);
1054 m_mltConsumer->purge();
1055 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1056 //m_mltConsumer->set("refresh", 0);
1057 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1058 m_mltProducer->set_speed(0);
1059 m_mltProducer->seek( position );
1060 //m_mltProducer->seek((int) m_framePosition);
1061 m_isBlocked = false;*/
1063 /*if (speed == 0.0) {
1064 m_mltProducer->seek((int) m_framePosition + 1);
1065 m_mltConsumer->purge();
1070 void Render::play(double speed) {
1073 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1074 m_isBlocked = false;
1075 m_mltProducer->set_speed(speed);
1076 /*if (speed == 0.0) {
1077 m_mltProducer->seek((int) m_framePosition + 1);
1078 m_mltConsumer->purge();
1083 void Render::play(const GenTime & startTime) {
1084 if (!m_mltProducer || !m_mltConsumer)
1086 m_isBlocked = false;
1087 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1088 m_mltProducer->set_speed(1.0);
1089 m_mltConsumer->set("refresh", 1);
1092 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1093 if (!m_mltProducer || !m_mltConsumer)
1095 //m_mltProducer->set("eof", "loop");
1096 m_isLoopMode = true;
1097 m_loopStart = startTime;
1098 playZone(startTime, stopTime);
1101 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1102 if (!m_mltProducer || !m_mltConsumer)
1104 m_isBlocked = false;
1105 m_mltProducer->set("out", stopTime.frames(m_fps));
1106 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1107 m_mltProducer->set_speed(1.0);
1108 m_mltConsumer->set("refresh", 1);
1109 m_isZoneMode = true;
1112 void Render::resetZoneMode() {
1113 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1114 //m_mltProducer->set("eof", "pause");
1115 m_isZoneMode = false;
1116 m_isLoopMode = false;
1119 void Render::seekToFrame(int pos) {
1120 //kDebug()<<" ********* RENDER SEEK TO POS";
1123 m_isBlocked = false;
1125 m_mltProducer->seek(pos);
1129 void Render::askForRefresh() {
1130 // Use a Timer so that we don't refresh too much
1131 refreshTimer->start(200);
1134 void Render::doRefresh() {
1135 // Use a Timer so that we don't refresh too much
1136 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1139 void Render::refresh() {
1140 if (!m_mltProducer || m_isBlocked)
1142 refreshTimer->stop();
1143 if (m_mltConsumer) {
1144 m_mltConsumer->set("refresh", 1);
1148 double Render::playSpeed() {
1149 if (m_mltProducer) return m_mltProducer->get_speed();
1153 GenTime Render::seekPosition() const {
1154 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1155 else return GenTime();
1159 const QString & Render::rendererName() const {
1164 void Render::emitFrameNumber(double position) {
1165 m_framePosition = position;
1166 emit rendererPosition((int) position);
1167 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1170 void Render::emitConsumerStopped() {
1171 // This is used to know when the playing stopped
1172 if (m_mltProducer) {
1173 double pos = m_mltProducer->position();
1174 if (m_isLoopMode) play(m_loopStart);
1175 else if (m_isZoneMode) resetZoneMode();
1176 emit rendererStopped((int) pos);
1177 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1178 //new QCustomEvent(10002));
1184 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1185 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1189 void Render::exportCurrentFrame(KUrl url, bool notify) {
1190 if (!m_mltProducer) {
1191 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1195 int height = 1080;//KdenliveSettings::defaultheight();
1196 int width = 1940; //KdenliveSettings::displaywidth();
1198 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1200 QPixmap pix(width, height);
1201 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1202 m_convert.set("forced", mlt_image_rgb24a);
1203 m_mltProducer->attach(m_convert);
1204 Mlt::Frame * frame = m_mltProducer->get_frame();
1205 m_mltProducer->detach(m_convert);
1207 pix = frameThumbnail(frame, width, height);
1210 pix.save(url.path(), "PNG");
1211 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1214 /** MLT PLAYLIST DIRECT MANIPULATON **/
1217 void Render::mltCheckLength() {
1218 //kDebug()<<"checking track length: "<<track<<"..........";
1220 Mlt::Service service(m_mltProducer->get_service());
1221 Mlt::Tractor tractor(service);
1223 int trackNb = tractor.count();
1224 double duration = 0;
1225 double trackDuration;
1227 Mlt::Producer trackProducer(tractor.track(0));
1228 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1229 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1230 m_mltProducer->set("out", duration);
1231 emit durationChanged((int) duration);
1234 while (trackNb > 1) {
1235 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1236 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1237 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1239 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1240 if (trackDuration > duration) duration = trackDuration;
1244 Mlt::Producer blackTrackProducer(tractor.track(0));
1245 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1246 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1248 if (blackDuration != duration) {
1249 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1251 int dur = (int)duration;
1253 QDomElement black = doc.createElement("producer");
1254 black.setAttribute("mlt_service", "colour");
1255 black.setAttribute("colour", "black");
1256 black.setAttribute("id", "black");
1259 while (dur > 14000) {
1260 info.startPos = GenTime(i * 14000, m_fps);
1261 info.endPos = info.startPos + GenTime(13999, m_fps);
1262 mltInsertClip(info, black, m_blackClip);
1267 info.startPos = GenTime(i * 14000, m_fps);
1268 info.endPos = info.startPos + GenTime(dur, m_fps);
1269 mltInsertClip(info, black, m_blackClip);
1271 m_mltProducer->set("out", duration);
1272 emit durationChanged((int)duration);
1276 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1277 if (!m_mltProducer) {
1278 kDebug() << "PLAYLIST NOT INITIALISED //////";
1281 Mlt::Producer parentProd(m_mltProducer->parent());
1282 if (parentProd.get_producer() == NULL) {
1283 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1287 Mlt::Service service(parentProd.get_service());
1288 Mlt::Tractor tractor(service);
1289 mlt_service_lock(service.get_service());
1290 Mlt::Producer trackProducer(tractor.track(info.track));
1291 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1292 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1293 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1294 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1296 /*if (QString(prod->get("transparency")).toInt() == 1)
1297 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1299 mlt_service_unlock(service.get_service());
1301 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1302 //tractor.multitrack()->refresh();
1303 //tractor.refresh();
1307 void Render::mltCutClip(int track, GenTime position) {
1311 Mlt::Service service(m_mltProducer->parent().get_service());
1312 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1314 Mlt::Tractor tractor(service);
1315 Mlt::Producer trackProducer(tractor.track(track));
1316 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1319 /* // Display playlist info
1320 kDebug()<<"//////////// BEFORE";
1321 for (int i = 0; i < trackPlaylist.count(); i++) {
1322 int blankStart = trackPlaylist.clip_start(i);
1323 int blankDuration = trackPlaylist.clip_length(i) - 1;
1325 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1326 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1329 int cutPos = (int) position.frames(m_fps);
1331 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1332 if (trackPlaylist.is_blank(clipIndex)) {
1333 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1334 m_isBlocked = false;
1337 mlt_service_lock(service.get_service());
1338 int clipStart = trackPlaylist.clip_start(clipIndex);
1339 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1340 mlt_service_unlock(service.get_service());
1342 // duplicate effects
1343 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1344 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1346 if (original == NULL || clip == NULL) {
1347 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1349 Mlt::Service clipService(original->get_service());
1350 Mlt::Service dupService(clip->get_service());
1352 Mlt::Filter *filter = clipService.filter(ct);
1354 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1355 // looks like there is no easy way to duplicate a filter,
1356 // so we will create a new one and duplicate its properties
1357 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1358 if (dup && dup->is_valid()) {
1359 Mlt::Properties entries(filter->get_properties());
1360 for (int i = 0;i < entries.count();i++) {
1361 dup->set(entries.get_name(i), entries.get(i));
1363 dupService.attach(*dup);
1367 filter = clipService.filter(ct);
1370 /* // Display playlist info
1371 kDebug()<<"//////////// AFTER";
1372 for (int i = 0; i < trackPlaylist.count(); i++) {
1373 int blankStart = trackPlaylist.clip_start(i);
1374 int blankDuration = trackPlaylist.clip_length(i) - 1;
1376 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1377 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1380 m_isBlocked = false;
1383 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1385 mltRemoveClip(info.track, info.startPos);
1386 mltInsertClip(info, element, prod);
1390 bool Render::mltRemoveClip(int track, GenTime position) {
1391 Mlt::Service service(m_mltProducer->parent().get_service());
1392 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1394 Mlt::Tractor tractor(service);
1395 Mlt::Producer trackProducer(tractor.track(track));
1396 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1397 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1399 /* // Display playlist info
1400 kDebug()<<"//// BEFORE";
1401 for (int i = 0; i < trackPlaylist.count(); i++) {
1402 int blankStart = trackPlaylist.clip_start(i);
1403 int blankDuration = trackPlaylist.clip_length(i) - 1;
1405 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1406 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1409 if (trackPlaylist.is_blank(clipIndex)) {
1410 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1414 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1415 trackPlaylist.replace_with_blank(clipIndex);
1416 trackPlaylist.consolidate_blanks(0);
1417 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1418 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1420 /* // Display playlist info
1421 kDebug()<<"//// AFTER";
1422 for (int i = 0; i < trackPlaylist.count(); i++) {
1423 int blankStart = trackPlaylist.clip_start(i);
1424 int blankDuration = trackPlaylist.clip_length(i) - 1;
1426 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1427 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1430 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1431 m_isBlocked = false;
1435 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
1436 if (!m_mltProducer) {
1437 kDebug() << "PLAYLIST NOT INITIALISED //////";
1440 Mlt::Producer parentProd(m_mltProducer->parent());
1441 if (parentProd.get_producer() == NULL) {
1442 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1446 Mlt::Service service(parentProd.get_service());
1447 Mlt::Tractor tractor(service);
1448 int insertPos = pos.frames(m_fps);
1450 Mlt::Producer trackProducer(tractor.track(track));
1451 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1452 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1453 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1454 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1455 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1459 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
1460 if (!m_mltProducer) {
1461 kDebug() << "PLAYLIST NOT INITIALISED //////";
1464 Mlt::Producer parentProd(m_mltProducer->parent());
1465 if (parentProd.get_producer() == NULL) {
1466 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1469 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1470 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1472 Mlt::Service service(parentProd.get_service());
1473 Mlt::Tractor tractor(service);
1474 mlt_service_lock(service.get_service());
1475 int diff = duration.frames(m_fps);
1476 int offset = timeOffset.frames(m_fps);
1480 // insert space in one track only
1481 Mlt::Producer trackProducer(tractor.track(track));
1482 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1483 insertPos = trackClipStartList.value(track);
1484 if (insertPos != -1) {
1485 insertPos += offset;
1486 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1487 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1489 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1490 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1491 int position = trackPlaylist.clip_start(clipIndex);
1492 trackPlaylist.remove_region(position, - diff - 1);
1494 trackPlaylist.consolidate_blanks(0);
1496 // now move transitions
1497 mlt_service serv = m_mltProducer->parent().get_service();
1498 mlt_service nextservice = mlt_service_get_producer(serv);
1499 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1500 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1501 QString resource = mlt_properties_get(properties, "mlt_service");
1503 while (mlt_type == "transition") {
1504 mlt_transition tr = (mlt_transition) nextservice;
1505 int currentTrack = mlt_transition_get_b_track(tr);
1506 int currentIn = (int) mlt_transition_get_in(tr);
1507 int currentOut = (int) mlt_transition_get_out(tr);
1508 insertPos = trackTransitionStartList.value(track);
1509 if (insertPos != -1) {
1510 insertPos += offset;
1511 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1512 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1515 nextservice = mlt_service_producer(nextservice);
1516 if (nextservice == NULL) break;
1517 properties = MLT_SERVICE_PROPERTIES(nextservice);
1518 mlt_type = mlt_properties_get(properties, "mlt_type");
1519 resource = mlt_properties_get(properties, "mlt_service");
1522 int trackNb = tractor.count();
1523 while (trackNb > 1) {
1524 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1525 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1528 int clipNb = trackPlaylist.count();
1529 insertPos = trackClipStartList.value(trackNb - 1);
1530 if (insertPos != -1) {
1531 insertPos += offset;
1533 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1534 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1535 for (int i = 0; i < clipNb; i++) {
1536 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1537 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1538 kDebug()<<"-------------";
1540 kDebug()<<"END-------------";*/
1543 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1544 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1546 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1547 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1548 int position = trackPlaylist.clip_start(clipIndex);
1549 trackPlaylist.remove_region(position, - diff - 1);
1551 trackPlaylist.consolidate_blanks(0);
1555 // now move transitions
1556 mlt_service serv = m_mltProducer->parent().get_service();
1557 mlt_service nextservice = mlt_service_get_producer(serv);
1558 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1559 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1560 QString resource = mlt_properties_get(properties, "mlt_service");
1562 while (mlt_type == "transition") {
1563 mlt_transition tr = (mlt_transition) nextservice;
1564 int currentIn = (int) mlt_transition_get_in(tr);
1565 int currentOut = (int) mlt_transition_get_out(tr);
1566 int currentTrack = mlt_transition_get_b_track(tr);
1567 insertPos = trackTransitionStartList.value(currentTrack);
1568 if (insertPos != -1) {
1569 insertPos += offset;
1570 if (currentOut > insertPos && resource != "mix") {
1571 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1574 nextservice = mlt_service_producer(nextservice);
1575 if (nextservice == NULL) break;
1576 properties = MLT_SERVICE_PROPERTIES(nextservice);
1577 mlt_type = mlt_properties_get(properties, "mlt_type");
1578 resource = mlt_properties_get(properties, "mlt_service");
1581 mlt_service_unlock(service.get_service());
1583 m_mltConsumer->set("refresh", 1);
1586 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
1589 Mlt::Service service(m_mltProducer->parent().get_service());
1590 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1591 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1592 Mlt::Tractor tractor(service);
1593 Mlt::Producer trackProducer(tractor.track(info.track));
1594 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1595 int startPos = info.startPos.frames(m_fps);
1596 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1597 int clipLength = trackPlaylist.clip_length(clipIndex);
1599 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1600 QString serv = clip.parent().get("mlt_service");
1601 QString id = clip.parent().get("id");
1602 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1603 if (serv == "avformat" && speed != 1.0) {
1604 mlt_service_lock(service.get_service());
1605 QString url = clip.parent().get("resource");
1606 url.append("?" + QString::number(speed));
1607 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1608 if (!slowprod || slowprod->get_producer() == NULL) {
1609 char *tmp = decodedString(url);
1610 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1612 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1613 tmp = decodedString(producerid);
1614 slowprod->set("id", tmp);
1616 m_slowmotionProducers.insert(url, slowprod);
1618 trackPlaylist.replace_with_blank(clipIndex);
1619 trackPlaylist.consolidate_blanks(0);
1620 // Check that the blank space is long enough for our new duration
1621 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1622 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1624 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1625 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1626 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1627 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1628 trackPlaylist.insert_at(startPos, *cut, 1);
1629 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1630 newLength = trackPlaylist.clip_length(clipIndex);
1631 mlt_service_unlock(service.get_service());
1632 } else if (speed == 1.0) {
1633 mlt_service_lock(service.get_service());
1635 trackPlaylist.replace_with_blank(clipIndex);
1636 trackPlaylist.consolidate_blanks(0);
1638 // Check that the blank space is long enough for our new duration
1639 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1640 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1643 GenTime oldDuration = GenTime(clipLength, m_fps);
1644 GenTime newDuration = oldDuration * oldspeed;
1645 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1646 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1647 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1648 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1649 trackPlaylist.insert_at(startPos, *cut, 1);
1650 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1651 newLength = trackPlaylist.clip_length(clipIndex);
1652 mlt_service_unlock(service.get_service());
1654 } else if (serv == "framebuffer") {
1655 mlt_service_lock(service.get_service());
1656 QString url = clip.parent().get("resource");
1657 url = url.section("?", 0, 0);
1658 url.append("?" + QString::number(speed));
1659 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1660 if (!slowprod || slowprod->get_producer() == NULL) {
1661 char *tmp = decodedString(url);
1662 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1664 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1665 tmp = decodedString(producerid);
1666 slowprod->set("id", tmp);
1668 m_slowmotionProducers.insert(url, slowprod);
1670 trackPlaylist.replace_with_blank(clipIndex);
1671 trackPlaylist.consolidate_blanks(0);
1673 GenTime oldDuration = GenTime(clipLength, m_fps);
1674 GenTime newDuration = oldDuration * oldspeed / speed;
1676 // Check that the blank space is long enough for our new duration
1677 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1678 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1681 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1682 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1683 cut = slowprod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1684 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1686 trackPlaylist.insert_at(startPos, *cut, 1);
1687 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1688 newLength = trackPlaylist.clip_length(clipIndex);
1690 mlt_service_unlock(service.get_service());
1692 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1693 m_isBlocked = false;
1697 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1699 Mlt::Service service(m_mltProducer->parent().get_service());
1700 bool success = false;
1701 Mlt::Tractor tractor(service);
1702 Mlt::Producer trackProducer(tractor.track(track));
1703 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1704 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1705 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1707 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1710 Mlt::Service clipService(clip->get_service());
1711 // if (tag.startsWith("ladspa")) tag = "ladspa";
1714 Mlt::Filter *filter = clipService.filter(ct);
1716 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1717 if (clipService.detach(*filter) == 0) success = true;
1718 kDebug() << " / / / DLEETED EFFECT: " << ct;
1720 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1723 filter = clipService.filter(ct);
1725 m_isBlocked = false;
1726 if (doRefresh) refresh();
1731 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
1733 Mlt::Service service(m_mltProducer->parent().get_service());
1735 Mlt::Tractor tractor(service);
1736 Mlt::Producer trackProducer(tractor.track(track));
1737 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1739 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1743 Mlt::Service clipService(clip->get_service());
1746 // temporarily remove all effects after insert point
1747 QList <Mlt::Filter *> filtersList;
1748 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1750 Mlt::Filter *filter = clipService.filter(ct);
1752 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1753 filtersList.append(filter);
1754 clipService.detach(*filter);
1756 filter = clipService.filter(ct);
1760 QString tag = params.paramValue("tag");
1761 kDebug() << " / / INSERTING EFFECT: " << tag;
1762 if (tag.startsWith("ladspa")) tag = "ladspa";
1763 char *filterTag = decodedString(tag);
1764 char *filterId = decodedString(params.paramValue("id"));
1765 QHash<QString, QString>::Iterator it;
1766 QString kfr = params.paramValue("keyframes");
1768 if (!kfr.isEmpty()) {
1769 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1770 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1771 char *starttag = decodedString(params.paramValue("starttag", "start"));
1772 char *endtag = decodedString(params.paramValue("endtag", "end"));
1773 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1774 int duration = clip->get_playtime();
1775 double max = params.paramValue("max").toDouble();
1776 double min = params.paramValue("min").toDouble();
1777 double factor = params.paramValue("factor", "1").toDouble();
1778 params.removeParam("starttag");
1779 params.removeParam("endtag");
1780 params.removeParam("keyframes");
1781 params.removeParam("min");
1782 params.removeParam("max");
1783 params.removeParam("factor");
1785 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1786 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1787 if (filter && filter->is_valid()) {
1788 filter->set("kdenlive_id", filterId);
1789 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1790 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1791 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1792 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1793 if (x2 == -1) x2 = duration;
1795 for (int j = 0; j < params.count(); j++) {
1796 char *name = decodedString(params.at(j).name());
1797 char *value = decodedString(params.at(j).value());
1798 filter->set(name, value);
1803 filter->set("in", x1);
1804 filter->set("out", x2);
1805 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1806 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1807 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1808 clipService.attach(*filter);
1815 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1816 if (filter && filter->is_valid())
1817 filter->set("kdenlive_id", filterId);
1819 kDebug() << "filter is NULL";
1820 m_isBlocked = false;
1824 params.removeParam("kdenlive_id");
1826 for (int j = 0; j < params.count(); j++) {
1827 char *name = decodedString(params.at(j).name());
1828 char *value = decodedString(params.at(j).value());
1829 filter->set(name, value);
1835 QString effectArgs = params.paramValue("id").section('_', 1);
1837 params.removeParam("id");
1838 params.removeParam("kdenlive_ix");
1839 params.removeParam("tag");
1840 params.removeParam("disabled");
1842 for (int j = 0; j < params.count(); j++) {
1843 effectArgs.append(' ' + params.at(j).value());
1845 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1846 char *value = decodedString(effectArgs.simplified());
1847 filter->set("effect", value);
1852 // attach filter to the clip
1853 clipService.attach(*filter);
1858 // re-add following filters
1859 for (int i = 0; i < filtersList.count(); i++) {
1860 clipService.attach(*(filtersList.at(i)));
1863 m_isBlocked = false;
1864 if (doRefresh) refresh();
1868 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
1869 QString index = params.paramValue("kdenlive_ix");
1870 QString tag = params.paramValue("tag");
1872 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1873 // This is a keyframe effect, to edit it, we remove it and re-add it.
1874 mltRemoveEffect(track, position, index);
1875 bool success = mltAddEffect(track, position, params);
1880 Mlt::Service service(m_mltProducer->parent().get_service());
1882 Mlt::Tractor tractor(service);
1883 Mlt::Producer trackProducer(tractor.track(track));
1884 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1885 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1886 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1888 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1891 Mlt::Service clipService(clip->get_service());
1894 Mlt::Filter *filter = clipService.filter(ct);
1896 if (filter->get("kdenlive_ix") == index) {
1900 filter = clipService.filter(ct);
1904 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1905 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1907 filter = clipService.filter(ct);
1908 QList <Mlt::Filter *> filtersList;
1910 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1911 filtersList.append(filter);
1912 clipService.detach(*filter);
1914 filter = clipService.filter(ct);
1916 bool success = mltAddEffect(track, position, params);
1918 for (int i = 0; i < filtersList.count(); i++) {
1919 clipService.attach(*(filtersList.at(i)));
1922 m_isBlocked = false;
1926 for (int j = 0; j < params.count(); j++) {
1927 char *name = decodedString(params.at(j).name());
1928 char *value = decodedString(params.at(j).value());
1929 filter->set(name, value);
1934 m_isBlocked = false;
1939 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1941 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1942 Mlt::Service service(m_mltProducer->parent().get_service());
1944 Mlt::Tractor tractor(service);
1945 Mlt::Producer trackProducer(tractor.track(track));
1946 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1947 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1948 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1950 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1953 Mlt::Service clipService(clip->get_service());
1956 QList <Mlt::Filter *> filtersList;
1957 Mlt::Filter *filter = clipService.filter(ct);
1959 if (newPos > oldPos) {
1961 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1962 filter->set("kdenlive_ix", newPos);
1963 filtersList.append(filter);
1964 clipService.detach(*filter);
1965 filter = clipService.filter(ct);
1966 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1967 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1969 filter = clipService.filter(ct);
1973 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1974 filtersList.append(filter);
1975 clipService.detach(*filter);
1977 filter = clipService.filter(ct);
1981 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1982 filter->set("kdenlive_ix", newPos);
1983 filtersList.append(filter);
1984 clipService.detach(*filter);
1986 filter = clipService.filter(ct);
1990 filter = clipService.filter(ct);
1992 int pos = QString(filter->get("kdenlive_ix")).toInt();
1993 if (pos >= newPos) {
1994 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
1995 filtersList.append(filter);
1996 clipService.detach(*filter);
1998 filter = clipService.filter(ct);
2002 for (int i = 0; i < filtersList.count(); i++) {
2003 clipService.attach(*(filtersList.at(i)));
2006 m_isBlocked = false;
2010 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
2013 Mlt::Service service(m_mltProducer->parent().get_service());
2015 Mlt::Tractor tractor(service);
2016 Mlt::Producer trackProducer(tractor.track(info.track));
2017 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2019 /* // Display playlist info
2020 kDebug()<<"//////////// BEFORE RESIZE";
2021 for (int i = 0; i < trackPlaylist.count(); i++) {
2022 int blankStart = trackPlaylist.clip_start(i);
2023 int blankDuration = trackPlaylist.clip_length(i) - 1;
2025 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2026 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
2029 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2030 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2031 m_isBlocked = false;
2034 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2035 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2036 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2037 int previousStart = clip->get_in();
2038 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2039 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2040 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2041 //trackPlaylist.consolidate_blanks(0);
2042 // skip to next clip
2044 int diff = newDuration - previousDuration;
2045 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
2047 // clip was made longer, trim next blank if there is one.
2048 if (trackPlaylist.is_blank(clipIndex)) {
2049 int blankStart = trackPlaylist.clip_start(clipIndex);
2050 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2051 if (diff - blankDuration == 1) {
2052 trackPlaylist.remove(clipIndex);
2053 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
2055 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2057 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2059 trackPlaylist.consolidate_blanks(0);
2062 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2063 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2064 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2065 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2066 ItemInfo transpinfo;
2067 transpinfo.startPos = info.startPos;
2068 transpinfo.endPos = info.startPos + clipDuration;
2069 transpinfo.track = info.track;
2070 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2072 m_isBlocked = false;
2073 m_mltConsumer->set("refresh", 1);
2077 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
2078 Mlt::Service service(m_mltProducer->parent().get_service());
2079 Mlt::Tractor tractor(service);
2080 Mlt::Producer trackProducer(tractor.track(track));
2083 if (blind) trackProducer.set("hide", 3);
2084 else trackProducer.set("hide", 2);
2086 trackProducer.set("hide", 1);
2088 trackProducer.set("hide", 0);
2090 tractor.multitrack()->refresh();
2095 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
2096 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2097 Mlt::Service service(m_mltProducer->parent().get_service());
2098 int moveFrame = (int) diff.frames(m_fps);
2099 Mlt::Tractor tractor(service);
2100 Mlt::Producer trackProducer(tractor.track(info.track));
2101 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2102 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2103 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2106 mlt_service_lock(service.get_service());
2107 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2108 /*int previousStart = trackPlaylist.clip_start(clipIndex);
2109 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
2110 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
2111 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2113 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2114 mlt_service_unlock(service.get_service());
2117 //m_mltConsumer->set("refresh", 0);
2118 int previousStart = clip->get_in();
2119 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2121 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2122 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2123 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2125 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2126 int blankIndex = clipIndex - 1;
2127 int blankLength = trackPlaylist.clip_length(blankIndex);
2128 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2129 if (! trackPlaylist.is_blank(blankIndex)) {
2130 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2132 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2133 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2135 trackPlaylist.consolidate_blanks(0);
2136 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2137 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2138 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2139 ItemInfo transpinfo;
2140 transpinfo.startPos = info.startPos + diff;
2141 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2142 transpinfo.track = info.track;
2143 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2145 m_isBlocked = false;
2146 //m_mltConsumer->set("refresh", 1);
2147 mlt_service_unlock(service.get_service());
2148 m_mltConsumer->set("refresh", 1);
2152 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
2153 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2157 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
2158 kDebug() << "NEW PROD ID: " << prod->get("id");
2159 m_mltConsumer->set("refresh", 0);
2160 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2161 mlt_service_lock(m_mltConsumer->get_service());
2162 Mlt::Service service(m_mltProducer->parent().get_service());
2163 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2165 Mlt::Tractor tractor(service);
2166 Mlt::Producer trackProducer(tractor.track(track));
2167 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2168 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2169 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2170 if (clipProducer.is_blank()) {
2171 kDebug() << "// ERROR UPDATING CLIP PROD";
2172 mlt_service_unlock(m_mltConsumer->get_service());
2173 m_isBlocked = false;
2176 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2178 // move all effects to the correct producer
2179 Mlt::Service clipService(clipProducer.get_service());
2180 Mlt::Service newClipService(clip->get_service());
2183 Mlt::Filter *filter = clipService.filter(ct);
2185 if (filter->get("kdenlive_ix") != 0) {
2186 clipService.detach(*filter);
2187 newClipService.attach(*filter);
2189 filter = clipService.filter(ct);
2192 trackPlaylist.insert_at(pos, clip, 1);
2193 mlt_service_unlock(m_mltConsumer->get_service());
2194 m_isBlocked = false;
2197 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
2200 m_mltConsumer->set("refresh", 0);
2201 mlt_service_lock(m_mltConsumer->get_service());
2202 Mlt::Service service(m_mltProducer->parent().get_service());
2203 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2205 Mlt::Tractor tractor(service);
2206 Mlt::Producer trackProducer(tractor.track(startTrack));
2207 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2208 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2209 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2210 bool checkLength = false;
2211 if (endTrack == startTrack) {
2212 //mlt_service_lock(service.get_service());
2213 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2214 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2215 // error, destination is not empty
2216 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2217 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2218 mlt_service_unlock(m_mltConsumer->get_service());
2219 m_isBlocked = false;
2222 trackPlaylist.consolidate_blanks(0);
2223 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2224 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2225 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2227 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2229 //mlt_service_unlock(service.get_service());
2231 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2232 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2233 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2234 // error, destination is not empty
2235 mlt_service_unlock(m_mltConsumer->get_service());
2236 m_isBlocked = false;
2239 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2240 if (clipProducer.is_blank()) {
2241 // error, destination is not empty
2242 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2243 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2244 mlt_service_unlock(m_mltConsumer->get_service());
2245 m_isBlocked = false;
2248 trackPlaylist.consolidate_blanks(0);
2249 destTrackPlaylist.consolidate_blanks(1);
2250 Mlt::Producer *clip;
2251 // check if we are moving a slowmotion producer
2252 QString serv = clipProducer.parent().get("mlt_service");
2253 if (serv == "framebuffer") {
2254 clip = &clipProducer;
2255 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2257 // move all effects to the correct producer
2258 Mlt::Service clipService(clipProducer.get_service());
2259 Mlt::Service newClipService(clip->get_service());
2262 Mlt::Filter *filter = clipService.filter(ct);
2264 if (filter->get("kdenlive_ix") != 0) {
2265 clipService.detach(*filter);
2266 newClipService.attach(*filter);
2268 filter = clipService.filter(ct);
2271 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2272 destTrackPlaylist.consolidate_blanks(0);
2273 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2274 kDebug() << "//////// moving clip transparency";
2275 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2277 if (clipIndex > trackPlaylist.count()) checkLength = true;
2278 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2282 if (checkLength) mltCheckLength();
2283 mlt_service_unlock(m_mltConsumer->get_service());
2284 m_isBlocked = false;
2285 m_mltConsumer->set("refresh", 1);
2289 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
2290 Mlt::Service service(m_mltProducer->parent().get_service());
2291 Mlt::Tractor tractor(service);
2292 Mlt::Field *field = tractor.field();
2294 mlt_service_lock(service.get_service());
2295 m_mltConsumer->set("refresh", 0);
2298 mlt_service serv = m_mltProducer->parent().get_service();
2299 mlt_service nextservice = mlt_service_get_producer(serv);
2300 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2301 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2302 QString resource = mlt_properties_get(properties, "mlt_service");
2303 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2305 int new_in = (int)newIn.frames(m_fps);
2306 int new_out = (int)newOut.frames(m_fps) - 1;
2308 while (mlt_type == "transition") {
2309 mlt_transition tr = (mlt_transition) nextservice;
2310 int currentTrack = mlt_transition_get_b_track(tr);
2311 int currentIn = (int) mlt_transition_get_in(tr);
2312 int currentOut = (int) mlt_transition_get_out(tr);
2314 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2315 mlt_transition_set_in_and_out(tr, new_in, new_out);
2316 if (newTrack - startTrack != 0) {
2317 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
2319 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2320 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2321 mlt_properties_set_int(properties, "b_track", newTrack);
2322 //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);
2326 nextservice = mlt_service_producer(nextservice);
2327 if (nextservice == NULL) break;
2328 properties = MLT_SERVICE_PROPERTIES(nextservice);
2329 mlt_type = mlt_properties_get(properties, "mlt_type");
2330 resource = mlt_properties_get(properties, "mlt_service");
2332 m_isBlocked = false;
2333 mlt_service_unlock(service.get_service());
2334 m_mltConsumer->set("refresh", 1);
2337 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2338 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2339 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2341 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2342 mltAddTransition(tag, a_track, b_track, in, out, xml);
2344 //mltSavePlaylist();
2347 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2349 Mlt::Service service(m_mltProducer->parent().get_service());
2350 Mlt::Tractor tractor(service);
2351 Mlt::Field *field = tractor.field();
2353 //m_mltConsumer->set("refresh", 0);
2354 mlt_service serv = m_mltProducer->parent().get_service();
2356 mlt_service nextservice = mlt_service_get_producer(serv);
2357 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2358 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2359 QString resource = mlt_properties_get(properties, "mlt_service");
2360 int in_pos = (int) in.frames(m_fps);
2361 int out_pos = (int) out.frames(m_fps) - 1;
2363 while (mlt_type == "transition") {
2364 mlt_transition tr = (mlt_transition) nextservice;
2365 int currentTrack = mlt_transition_get_b_track(tr);
2366 int currentBTrack = mlt_transition_get_a_track(tr);
2367 int currentIn = (int) mlt_transition_get_in(tr);
2368 int currentOut = (int) mlt_transition_get_out(tr);
2370 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2372 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2373 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2374 QMap<QString, QString>::Iterator it;
2376 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2377 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2378 if (currentBTrack != a_track) {
2379 mlt_properties_set_int(properties, "a_track", a_track);
2381 for (it = map.begin(); it != map.end(); ++it) {
2383 char *name = decodedString(key);
2384 char *value = decodedString(it.value());
2385 mlt_properties_set(transproperties, name, value);
2386 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2387 //filter->set("kdenlive_id", id);
2393 nextservice = mlt_service_producer(nextservice);
2394 if (nextservice == NULL) break;
2395 properties = MLT_SERVICE_PROPERTIES(nextservice);
2396 mlt_type = mlt_properties_get(properties, "mlt_type");
2397 resource = mlt_properties_get(properties, "mlt_service");
2399 m_isBlocked = false;
2400 m_mltConsumer->set("refresh", 1);
2403 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2404 Mlt::Service service(m_mltProducer->parent().get_service());
2405 Mlt::Tractor tractor(service);
2406 Mlt::Field *field = tractor.field();
2408 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2409 mlt_service serv = m_mltProducer->parent().get_service();
2411 mlt_service nextservice = mlt_service_get_producer(serv);
2412 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2413 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2414 QString resource = mlt_properties_get(properties, "mlt_service");
2416 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2418 while (mlt_type == "transition") {
2419 mlt_transition tr = (mlt_transition) nextservice;
2420 int currentTrack = mlt_transition_get_b_track(tr);
2421 int currentIn = (int) mlt_transition_get_in(tr);
2422 int currentOut = (int) mlt_transition_get_out(tr);
2423 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2425 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2426 mlt_field_disconnect_service(field->get_field(), nextservice);
2429 nextservice = mlt_service_producer(nextservice);
2430 if (nextservice == NULL) break;
2431 properties = MLT_SERVICE_PROPERTIES(nextservice);
2432 mlt_type = mlt_properties_get(properties, "mlt_type");
2433 resource = mlt_properties_get(properties, "mlt_service");
2435 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2438 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2439 QDomNodeList attribs = xml.elementsByTagName("parameter");
2440 QMap<QString, QString> map;
2441 for (int i = 0;i < attribs.count();i++) {
2442 QDomElement e = attribs.item(i).toElement();
2443 QString name = e.attribute("name");
2444 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2445 map[name] = e.attribute("default");
2446 if (!e.attribute("value").isEmpty()) {
2447 map[name] = e.attribute("value");
2449 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2450 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2451 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2454 if (e.attribute("namedesc").contains(";")) {
2455 QString format = e.attribute("format");
2456 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2457 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2459 QTextStream txtNeu(&neu);
2460 if (values.size() > 0)
2461 txtNeu << (int)values[0].toDouble();
2463 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2464 txtNeu << separators[i];
2465 txtNeu << (int)(values[i+1].toDouble());
2467 if (i < separators.size())
2468 txtNeu << separators[i];
2469 map[e.attribute("name")] = neu;
2476 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2477 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2478 Mlt::Service service(m_mltProducer->parent().get_service());
2479 Mlt::Tractor tractor(service);
2480 Mlt::Field *field = tractor.field();
2482 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2483 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2484 transition->set("transparency", id);
2485 transition->set("fill", 1);
2486 transition->set("internal_added", 237);
2487 field->plant_transition(*transition, transitiontrack, info.track);
2491 void Render::mltDeleteTransparency(int pos, int track, int id) {
2492 Mlt::Service service(m_mltProducer->parent().get_service());
2493 Mlt::Tractor tractor(service);
2494 Mlt::Field *field = tractor.field();
2496 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2497 mlt_service serv = m_mltProducer->parent().get_service();
2499 mlt_service nextservice = mlt_service_get_producer(serv);
2500 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2501 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2502 QString resource = mlt_properties_get(properties, "mlt_service");
2504 while (mlt_type == "transition") {
2505 mlt_transition tr = (mlt_transition) nextservice;
2506 int currentTrack = mlt_transition_get_b_track(tr);
2507 int currentIn = (int) mlt_transition_get_in(tr);
2508 int currentOut = (int) mlt_transition_get_out(tr);
2509 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2510 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2512 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2513 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2514 mlt_field_disconnect_service(field->get_field(), nextservice);
2517 nextservice = mlt_service_producer(nextservice);
2518 if (nextservice == NULL) break;
2519 properties = MLT_SERVICE_PROPERTIES(nextservice);
2520 mlt_type = mlt_properties_get(properties, "mlt_type");
2521 resource = mlt_properties_get(properties, "mlt_service");
2523 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2526 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2527 Mlt::Service service(m_mltProducer->parent().get_service());
2528 Mlt::Tractor tractor(service);
2529 Mlt::Field *field = tractor.field();
2531 mlt_service_lock(service.get_service());
2532 m_mltConsumer->set("refresh", 0);
2535 mlt_service serv = m_mltProducer->parent().get_service();
2536 mlt_service nextservice = mlt_service_get_producer(serv);
2537 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2538 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2539 QString resource = mlt_properties_get(properties, "mlt_service");
2540 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2541 while (mlt_type == "transition") {
2542 mlt_transition tr = (mlt_transition) nextservice;
2543 int currentTrack = mlt_transition_get_b_track(tr);
2544 int currentIn = (int) mlt_transition_get_in(tr);
2545 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2546 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2547 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2548 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2549 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2550 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2553 nextservice = mlt_service_producer(nextservice);
2554 if (nextservice == NULL) break;
2555 properties = MLT_SERVICE_PROPERTIES(nextservice);
2556 mlt_type = mlt_properties_get(properties, "mlt_type");
2557 resource = mlt_properties_get(properties, "mlt_service");
2559 m_isBlocked = false;
2560 mlt_service_unlock(service.get_service());
2561 m_mltConsumer->set("refresh", 1);
2565 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2566 Mlt::Service service(m_mltProducer->parent().get_service());
2567 Mlt::Tractor tractor(service);
2568 Mlt::Field *field = tractor.field();
2570 mlt_service_lock(service.get_service());
2571 m_mltConsumer->set("refresh", 0);
2574 mlt_service serv = m_mltProducer->parent().get_service();
2575 mlt_service nextservice = mlt_service_get_producer(serv);
2576 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2577 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2578 QString resource = mlt_properties_get(properties, "mlt_service");
2580 while (mlt_type == "transition") {
2581 mlt_transition tr = (mlt_transition) nextservice;
2582 int currentTrack = mlt_transition_get_b_track(tr);
2583 int currentaTrack = mlt_transition_get_a_track(tr);
2584 int currentIn = (int) mlt_transition_get_in(tr);
2585 int currentOut = (int) mlt_transition_get_out(tr);
2586 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2587 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2588 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2589 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2590 kDebug() << "//////MOVING";
2591 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2592 if (endTrack != startTrack) {
2593 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2594 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2595 mlt_properties_set_int(properties, "b_track", endTrack);
2599 nextservice = mlt_service_producer(nextservice);
2600 if (nextservice == NULL) break;
2601 properties = MLT_SERVICE_PROPERTIES(nextservice);
2602 mlt_type = mlt_properties_get(properties, "mlt_type");
2603 resource = mlt_properties_get(properties, "mlt_service");
2605 m_isBlocked = false;
2606 mlt_service_unlock(service.get_service());
2607 m_mltConsumer->set("refresh", 1);
2611 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2613 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2614 Mlt::Service service(m_mltProducer->parent().get_service());
2616 Mlt::Tractor tractor(service);
2617 Mlt::Field *field = tractor.field();
2619 char *transId = decodedString(tag);
2620 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2621 if (out != GenTime())
2622 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2623 QMap<QString, QString>::Iterator it;
2625 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2626 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2628 for (it = args.begin(); it != args.end(); ++it) {
2630 char *name = decodedString(key);
2631 char *value = decodedString(it.value());
2632 transition->set(name, value);
2633 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2634 //filter->set("kdenlive_id", id);
2638 // attach filter to the clip
2639 field->plant_transition(*transition, a_track, b_track);
2644 void Render::mltSavePlaylist() {
2645 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2646 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2647 fileConsumer.set("resource", "/tmp/playlist.westley");
2649 Mlt::Service service(m_mltProducer->get_service());
2651 fileConsumer.connect(service);
2652 fileConsumer.start();
2655 QList <Mlt::Producer *> Render::producersList() {
2656 QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
2658 Mlt::Service service(m_mltProducer->parent().get_service());
2659 Mlt::Tractor tractor(service);
2661 int trackNb = tractor.count();
2662 for (int t = 1; t < trackNb; t++) {
2663 Mlt::Producer trackProducer(tractor.track(t));
2664 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2665 int clipNb = trackPlaylist.count();
2666 kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2667 for (int i = 0; i < clipNb; i++) {
2668 Mlt::Producer *prod = trackPlaylist.get_clip(i);
2669 Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
2670 //kDebug()<<"PROD: "<<nprod->get("producer")<<", ID: "<<nprod->get("id")<<nprod->get("resource");
2671 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2672 ids.append(nprod->get("id"));
2673 prods.append(nprod);
2680 void Render::mltInsertTrack(int ix, bool videoTrack) {
2684 m_mltConsumer->set("refresh", 0);
2685 mlt_service_lock(m_mltConsumer->get_service());
2686 Mlt::Service service(m_mltProducer->parent().get_service());
2687 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2689 Mlt::Tractor tractor(service);
2691 Mlt::Playlist playlist;// = new Mlt::Playlist();
2692 int ct = tractor.count();
2693 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2696 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2697 tractor.set_track(playlist, pos);
2698 Mlt::Producer newProd(tractor.track(pos));
2699 if (!videoTrack) newProd.set("hide", 1);
2701 for (; pos <= ct; pos++) {
2702 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2703 tractor.set_track(*prodToMove, pos);
2704 prodToMove = prodToMove2;
2707 tractor.set_track(playlist, ix);
2708 Mlt::Producer newProd(tractor.track(ix));
2709 if (!videoTrack) newProd.set("hide", 1);
2713 mlt_service serv = m_mltProducer->parent().get_service();
2714 mlt_service nextservice = mlt_service_get_producer(serv);
2715 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2716 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2717 QString resource = mlt_properties_get(properties, "mlt_service");
2719 while (mlt_type == "transition") {
2720 if (resource != "mix") {
2721 mlt_transition tr = (mlt_transition) nextservice;
2722 int currentTrack = mlt_transition_get_b_track(tr);
2723 int currentaTrack = mlt_transition_get_a_track(tr);
2724 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2726 if (currentTrack >= ix) {
2727 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2728 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2731 nextservice = mlt_service_producer(nextservice);
2732 if (nextservice == NULL) break;
2733 properties = MLT_SERVICE_PROPERTIES(nextservice);
2734 mlt_type = mlt_properties_get(properties, "mlt_type");
2735 resource = mlt_properties_get(properties, "mlt_service");
2738 // Add audio mix transition to last track
2739 Mlt::Field *field = tractor.field();
2740 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2741 //transition->set("mlt_service", "mix");
2742 transition->set("a_track", 1);
2743 transition->set("b_track", ct);
2744 transition->set("always_active", 1);
2745 transition->set("internal_added", 237);
2746 transition->set("combine", 1);
2747 field->plant_transition(*transition, 1, ct);
2749 mlt_service_unlock(m_mltConsumer->get_service());
2750 m_isBlocked = false;
2751 blockSignals(false);
2755 void Render::mltDeleteTrack(int ix) {
2757 doc.setContent(sceneList(), false);
2758 int tracksCount = doc.elementsByTagName("track").count() - 1;
2759 QDomNode track = doc.elementsByTagName("track").at(ix);
2760 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2761 QDomNodeList transitions = doc.elementsByTagName("transition");
2762 for (int i = 0; i < transitions.count(); i++) {
2763 QDomElement e = transitions.at(i).toElement();
2764 QDomNodeList props = e.elementsByTagName("property");
2765 QMap <QString, QString> mappedProps;
2766 for (int j = 0; j < props.count(); j++) {
2767 QDomElement f = props.at(j).toElement();
2768 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2770 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2771 tractor.removeChild(transitions.at(i));
2772 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2773 // Transition needs to be moved
2774 int a_track = mappedProps.value("a_track").toInt();
2775 int b_track = mappedProps.value("b_track").toInt();
2776 if (a_track > 0) a_track --;
2777 if (b_track > 0) b_track --;
2778 for (int j = 0; j < props.count(); j++) {
2779 QDomElement f = props.at(j).toElement();
2780 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2781 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2786 tractor.removeChild(track);
2787 setSceneList(doc.toString(), m_framePosition);
2793 m_mltConsumer->set("refresh", 0);
2794 mlt_service_lock(m_mltConsumer->get_service());
2795 Mlt::Service service(m_mltProducer->parent().get_service());
2796 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2798 /*Mlt::Tractor tractor(service);
2801 Mlt::Multitrack *multi = tractor.multitrack();
2804 int ct = tractor.count();
2805 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
2807 for (; pos < ct ; pos++) {
2808 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
2809 //mlt_service_close(lastTrack->get_service());
2811 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
2812 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
2813 mlt_service_close(prodToMove->get_service());
2814 mlt_service_close(prodToClose->get_service());
2815 tractor.set_track(*prodToMove, pos);
2819 /*mlt_service serv = m_mltProducer->parent().get_service();
2820 mlt_service nextservice = mlt_service_get_producer(serv);
2821 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2822 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2823 QString resource = mlt_properties_get(properties, "mlt_service");
2825 while (mlt_type == "transition") {
2826 if (resource != "mix") {
2827 mlt_transition tr = (mlt_transition) nextservice;
2828 int currentTrack = mlt_transition_get_b_track(tr);
2829 int currentaTrack = mlt_transition_get_a_track(tr);
2830 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2832 if (currentTrack >= ix) {
2833 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2834 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2837 nextservice = mlt_service_producer(nextservice);
2838 if (nextservice == NULL) break;
2839 properties = MLT_SERVICE_PROPERTIES(nextservice);
2840 mlt_type = mlt_properties_get(properties, "mlt_type");
2841 resource = mlt_properties_get(properties, "mlt_service");
2844 // Add audio mix transition to last track
2845 Mlt::Field *field = tractor.field();
2846 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2847 //transition->set("mlt_service", "mix");
2848 transition->set("a_track", 1);
2849 transition->set("b_track", ct);
2850 transition->set("always_active", 1);
2851 transition->set("internal_added", 237);
2852 transition->set("combine", 1);
2853 field->plant_transition(*transition, 1, ct);
2856 mlt_service_unlock(m_mltConsumer->get_service());
2857 m_isBlocked = false;
2858 blockSignals(false);
2861 #include "renderer.moc"