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);
101 QString videoDriver = KdenliveSettings::videodrivername();
102 if (!videoDriver.isEmpty()) {
103 if (videoDriver == "x11_noaccel") {
104 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
107 unsetenv("SDL_VIDEO_YUV_HWACCEL");
110 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
112 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
113 m_mltConsumer->set("resize", 1);
114 m_mltConsumer->set("window_id", m_winid);
115 m_mltConsumer->set("terminate_on_pause", 1);
116 //m_mltConsumer->set("fullscreen", 1);
117 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
118 m_mltConsumer->set("rescale", "nearest");
120 QString audioDevice = KdenliveSettings::audiodevicename();
121 if (!audioDevice.isEmpty()) {
122 tmp = decodedString(audioDevice);
123 m_mltConsumer->set("audio_device", tmp);
127 if (!videoDriver.isEmpty()) {
128 tmp = decodedString(videoDriver);
129 m_mltConsumer->set("video_driver", tmp);
133 QString audioDriver = KdenliveSettings::audiodrivername();
134 if (!audioDriver.isEmpty()) {
135 tmp = decodedString(audioDriver);
136 m_mltConsumer->set("audio_driver", tmp);
141 m_mltConsumer->set("progressive", 1);
142 m_mltConsumer->set("audio_buffer", 1024);
143 m_mltConsumer->set("frequency", 48000);
146 int Render::resetProfile() {
147 if (!m_mltConsumer) return 0;
148 QString currentProfile = getenv("MLT_PROFILE");
149 if (currentProfile == KdenliveSettings::current_profile()) {
150 kDebug() << "reset to same profile, nothing to do";
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();
159 if (m_mltProducer) delete m_mltProducer;
160 m_mltProducer = NULL;
161 if (m_mltProfile) delete m_mltProfile;
165 //kDebug() << "//RESET WITHSCENE: " << scene;
168 char *tmp = decodedString(scene);
169 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp);
171 m_mltProducer = producer;
172 if (m_blackClip) delete m_blackClip;
173 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
174 m_mltProducer->optimise();
175 m_mltProducer->set_speed(0);
178 //delete m_mltProfile;
179 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
180 //mlt_profile prof = m_mltProfile->get_profile();
181 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
182 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
183 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
184 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
186 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
191 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
192 void Render::seek(GenTime time) {
196 m_mltProducer->seek((int)(time.frames(m_fps)));
201 char *Render::decodedString(QString str) {
202 /*QCString fn = QFile::encodeName(str);
203 char *t = new char[fn.length() + 1];
204 strcpy(t, (const char *)fn);*/
206 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
210 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
211 QPixmap pix(width, height);
213 mlt_image_format format = mlt_image_rgb24a;
214 uint8_t *thumb = frame->get_image(format, width, height);
215 QImage image(thumb, width, height, QImage::Format_ARGB32);
217 if (!image.isNull()) {
218 pix = pix.fromImage(image);
220 QPainter painter(&pix);
221 painter.drawRect(0, 0, width - 1, height - 1);
223 } else pix.fill(Qt::black);
227 const int Render::renderWidth() const {
228 return (int)(m_mltProfile->height() * m_mltProfile->dar());
231 const int Render::renderHeight() const {
232 return m_mltProfile->height();
235 QPixmap Render::extractFrame(int frame_position, int width, int height) {
237 width = renderWidth();
238 height = renderHeight();
240 QPixmap pix(width, height);
241 if (!m_mltProducer) {
245 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
248 QPixmap Render::getImageThumbnail(KUrl url, int width, int height) {
251 if (url.fileName().startsWith(".all.")) { // check for slideshow
252 QString fileType = url.fileName().right(3);
254 QStringList::Iterator it;
256 QDir dir(url.directory());
258 filter << "*." + fileType;
259 filter << "*." + fileType.toUpper();
260 more = dir.entryList(filter, QDir::Files);
261 im.load(url.directory() + "/" + more.at(0));
262 } else im.load(url.path());
263 //pixmap = im.scaled(width, height);
268 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
269 QPixmap pix(width, height);
270 char *tmp = decodedString(file);
271 Mlt::Profile *prof = new Mlt::Profile(profile);
272 Mlt::Producer m_producer(*prof, tmp);
274 if (m_producer.is_blank()) {
279 Mlt::Filter m_convert(*prof, "avcolour_space");
280 m_convert.set("forced", mlt_image_rgb24a);
281 m_producer.attach(m_convert);
282 m_producer.seek(frame_position);
283 Mlt::Frame * frame = m_producer.get_frame();
285 pix = frameThumbnail(frame, width, height, true);
288 if (prof) delete prof;
293 void Render::getImage(KUrl url, int frame_position, QPoint size)
295 char *tmp = decodedString(url.path());
296 Mlt::Producer m_producer(tmp);
298 if (m_producer.is_blank()) {
301 Mlt::Filter m_convert("avcolour_space");
302 m_convert.set("forced", mlt_image_rgb24a);
303 m_producer.attach(m_convert);
304 m_producer.seek(frame_position);
306 Mlt::Frame * frame = m_producer.get_frame();
309 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
311 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
315 /* Create thumbnail for color */
316 /*void Render::getImage(int id, QString color, QPoint size)
318 QPixmap pixmap(size.x() - 2, size.y() - 2);
319 color = color.replace(0, 2, "#");
320 color = color.left(7);
321 pixmap.fill(QColor(color));
322 QPixmap result(size.x(), size.y());
323 result.fill(Qt::black);
324 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
325 emit replyGetImage(id, result, size.x(), size.y());
329 /* Create thumbnail for image */
330 /*void Render::getImage(KUrl url, QPoint size)
334 if (url.fileName().startsWith(".all.")) { // check for slideshow
335 QString fileType = url.fileName().right(3);
337 QStringList::Iterator it;
339 QDir dir( url.directory() );
340 more = dir.entryList( QDir::Files );
341 for ( it = more.begin() ; it != more.end() ; ++it ) {
342 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
343 if (!im.load(url.directory() + "/" + *it))
344 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + "/" + *it;
349 else im.load(url.path());
351 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
352 QPixmap result(size.x(), size.y());
353 result.fill(Qt::black);
354 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
355 emit replyGetImage(url, 1, result, size.x(), size.y());
359 double Render::consumerRatio() const {
360 if (!m_mltConsumer) return 1.0;
361 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
365 int Render::getLength() {
368 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
369 return mlt_producer_get_playtime(m_mltProducer->get_producer());
374 bool Render::isValid(KUrl url) {
375 char *tmp = decodedString(url.path());
376 Mlt::Producer producer(*m_mltProfile, tmp);
378 if (producer.is_blank())
384 const double Render::dar() const {
385 return m_mltProfile->dar();
388 void Render::slotSplitView(bool doit) {
389 m_isSplitView = doit;
390 Mlt::Service service(m_mltProducer->parent().get_service());
391 Mlt::Tractor tractor(service);
392 if (service.type() != tractor_type || tractor.count() < 2) return;
393 Mlt::Field *field = tractor.field();
396 for (int i = 1; i < tractor.count() && screen < 4; i++) {
397 Mlt::Producer trackProducer(tractor.track(i));
398 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
399 if (QString(trackProducer.get("hide")).toInt() != 1) {
400 kDebug() << "// ADIDNG TRACK: " << i;
401 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
402 transition->set("mlt_service", "composite");
403 transition->set("a_track", 0);
404 transition->set("b_track", i);
405 transition->set("distort", 1);
406 transition->set("internal_added", "200");
413 tmp = "50%,0:50%x50%";
416 tmp = "0,50%:50%x50%";
419 tmp = "50%,50%:50%x50%";
422 transition->set("geometry", tmp);
423 transition->set("always_active", "1");
424 field->plant_transition(*transition, 0, i);
429 m_mltConsumer->set("refresh", 1);
431 mlt_service serv = m_mltProducer->parent().get_service();
432 mlt_service nextservice = mlt_service_get_producer(serv);
433 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
434 QString mlt_type = mlt_properties_get(properties, "mlt_type");
435 QString resource = mlt_properties_get(properties, "mlt_service");
437 while (mlt_type == "transition") {
438 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
439 if (added == "200") {
440 mlt_field_disconnect_service(field->get_field(), nextservice);
442 nextservice = mlt_service_producer(nextservice);
443 if (nextservice == NULL) break;
444 properties = MLT_SERVICE_PROPERTIES(nextservice);
445 mlt_type = mlt_properties_get(properties, "mlt_type");
446 resource = mlt_properties_get(properties, "mlt_service");
447 m_mltConsumer->set("refresh", 1);
452 void Render::getFileProperties(const QDomElement &xml, const QString &clipId) {
454 int width = (int)(height * m_mltProfile->dar());
455 QMap < QString, QString > filePropertyMap;
456 QMap < QString, QString > metadataPropertyMap;
458 KUrl url = KUrl(xml.attribute("resource", QString::null));
459 Mlt::Producer *producer = NULL;
460 if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
461 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
464 if (xml.attribute("type").toInt() == COLOR) {
465 char *tmp = decodedString("colour:" + xml.attribute("colour"));
466 producer = new Mlt::Producer(*m_mltProfile, "fezzik", tmp);
468 } else if (url.isEmpty()) {
470 QDomElement westley = doc.createElement("westley");
471 QDomElement play = doc.createElement("playlist");
472 doc.appendChild(westley);
473 westley.appendChild(play);
474 play.appendChild(doc.importNode(xml, true));
475 char *tmp = decodedString(doc.toString());
476 producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
479 QString urlpath = url.path();
480 /*if (urlpath.contains(':')) {
481 if (!urlpath.startsWith("file:")) urlpath.prepend("file:");
482 char *tmp = decodedString(urlpath);
483 producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp);
487 char *tmp = decodedString(urlpath);
488 producer = new Mlt::Producer(*m_mltProfile, tmp);
491 if (xml.hasAttribute("force_aspect_ratio")) {
492 double aspect = xml.attribute("force_aspect_ratio").toDouble();
493 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
495 if (xml.hasAttribute("threads")) {
496 int threads = xml.attribute("threads").toInt();
497 if (threads != 1) producer->set("threads", threads);
499 if (xml.hasAttribute("video_index")) {
500 int vindex = xml.attribute("video_index").toInt();
501 if (vindex != 0) producer->set("video_index", vindex);
503 if (xml.hasAttribute("audio_index")) {
504 int aindex = xml.attribute("audio_index").toInt();
505 if (aindex != 0) producer->set("audio_index", aindex);
510 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
511 kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: ";
512 emit removeInvalidClip(clipId);
516 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
518 char *tmp = decodedString(clipId);
519 producer->set("id", tmp);
521 int frameNumber = xml.attribute("thumbnail", "0").toInt();
522 if (frameNumber != 0) producer->seek(frameNumber);
523 mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer());
525 filePropertyMap["duration"] = QString::number(producer->get_playtime());
526 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
528 Mlt::Frame *frame = producer->get_frame();
530 if (xml.attribute("type").toInt() == SLIDESHOW) {
531 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
532 if (xml.attribute("fade") == "1") {
533 // user wants a fade effect to slideshow
534 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
535 if (filter && filter->is_valid()) {
536 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
537 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
538 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
539 char *tmp = decodedString(xml.attribute("luma_file"));
540 filter->set("luma.resource", tmp);
542 if (xml.hasAttribute("softness")) {
543 int soft = xml.attribute("softness").toInt();
544 filter->set("luma.softness", (double) soft / 100.0);
547 Mlt::Service clipService(producer->get_service());
548 clipService.attach(*filter);
554 filePropertyMap["fps"] = producer->get("source_fps");
556 if (frame && frame->is_valid()) {
557 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height"));
558 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
559 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
560 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
562 if (frame->get_int("test_image") == 0) {
563 if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
564 filePropertyMap["type"] = "playlist";
565 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
566 } else if (frame->get_int("test_audio") == 0)
567 filePropertyMap["type"] = "av";
569 filePropertyMap["type"] = "video";
571 mlt_image_format format = mlt_image_yuv422;
573 int frame_height = 0;
574 //frame->set("rescale.interp", "hyper");
575 frame->set("normalised_height", height);
576 frame->set("normalised_width", width);
577 QPixmap pix(width, height);
579 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
580 uint8_t *new_image = (uint8_t *)mlt_pool_alloc(frame_width * (frame_height + 1) * 4);
581 mlt_convert_yuv422_to_rgb24a((uint8_t *)data, new_image, frame_width * frame_height);
582 QImage image((uchar *)new_image, frame_width, frame_height, QImage::Format_ARGB32);
584 if (!image.isNull()) {
585 pix = QPixmap::fromImage(image.rgbSwapped());
589 mlt_pool_release(new_image);
590 emit replyGetImage(clipId, 0, pix, width, height);
592 } else if (frame->get_int("test_audio") == 0) {
593 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
594 emit replyGetImage(clipId, 0, pixmap, width, height);
595 filePropertyMap["type"] = "audio";
599 // Retrieve audio / video codec name
603 if (producer->get_int("video_index") > -1) {
604 /*if (context->duration == AV_NOPTS_VALUE) {
605 kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION";
606 emit removeInvalidClip(clipId);
609 // Get the video_index
610 int default_video = producer->get_int("video_index");
612 int default_audio = producer->get_int("audio_index");
615 // Find maximum stream index values
616 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
617 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
618 QString type = producer->get(property);
621 else if (type == "audio")
624 filePropertyMap["default_video"] = QString::number(default_video);
625 filePropertyMap["video_max"] = QString::number(video_max);
626 filePropertyMap["default_audio"] = QString::number(default_audio);
627 filePropertyMap["audio_max"] = QString::number(audio_max);
629 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
630 if (producer->get(property)) {
631 filePropertyMap["videocodec"] = producer->get(property);
633 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
634 if (producer->get(property))
635 filePropertyMap["videocodec"] = producer->get(property);
637 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
638 if (producer->get_int("audio_index") > -1) {
639 // Get the audio_index
640 int index = producer->get_int("audio_index");
642 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
643 if (producer->get(property)) {
644 filePropertyMap["audiocodec"] = producer->get(property);
646 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
647 if (producer->get(property))
648 filePropertyMap["audiocodec"] = producer->get(property);
653 Mlt::Properties metadata;
654 metadata.pass_values(*producer, "meta.attr.");
655 int count = metadata.count();
656 for (int i = 0; i < count; i ++) {
657 QString name = metadata.get_name(i);
658 QString value = QString::fromUtf8(metadata.get(i));
659 if (name.endsWith("markup") && !value.isEmpty())
660 metadataPropertyMap[ name.section(".", 0, -2)] = value;
663 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap);
664 kDebug() << "REquested fuile info for: " << url.path();
665 if (frame) delete frame;
666 //if (producer) delete producer;
670 /** Create the producer from the Westley QDomDocument */
672 void Render::initSceneList() {
673 kDebug() << "-------- INIT SCENE LIST ------_";
675 QDomElement westley = doc.createElement("westley");
676 doc.appendChild(westley);
677 QDomElement prod = doc.createElement("producer");
678 prod.setAttribute("resource", "colour");
679 prod.setAttribute("colour", "red");
680 prod.setAttribute("id", "black");
681 prod.setAttribute("in", "0");
682 prod.setAttribute("out", "0");
684 QDomElement tractor = doc.createElement("tractor");
685 QDomElement multitrack = doc.createElement("multitrack");
687 QDomElement playlist1 = doc.createElement("playlist");
688 playlist1.appendChild(prod);
689 multitrack.appendChild(playlist1);
690 QDomElement playlist2 = doc.createElement("playlist");
691 multitrack.appendChild(playlist2);
692 QDomElement playlist3 = doc.createElement("playlist");
693 multitrack.appendChild(playlist3);
694 QDomElement playlist4 = doc.createElement("playlist");
695 multitrack.appendChild(playlist4);
696 QDomElement playlist5 = doc.createElement("playlist");
697 multitrack.appendChild(playlist5);
698 tractor.appendChild(multitrack);
699 westley.appendChild(tractor);
700 // kDebug()<<doc.toString();
702 QString tmp = QString("<westley><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></westley>");*/
703 setSceneList(doc, 0);
709 /** Create the producer from the Westley QDomDocument */
710 void Render::setProducer(Mlt::Producer *producer, int position) {
711 if (m_winid == -1) return;
714 m_mltConsumer->stop();
719 m_mltProducer->set_speed(0);
720 delete m_mltProducer;
721 m_mltProducer = NULL;
724 if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer());
725 else m_mltProducer = new Mlt::Producer();
726 if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
728 m_fps = m_mltProducer->get_fps();
730 if (position != -1) {
731 m_mltProducer->seek(position);
732 emit rendererPosition(position);
739 /** Create the producer from the Westley QDomDocument */
740 void Render::setSceneList(QDomDocument list, int position) {
741 setSceneList(list.toString(), position);
744 /** Create the producer from the Westley QDomDocument */
745 void Render::setSceneList(QString playlist, int position) {
746 if (m_winid == -1) return;
749 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
752 m_mltConsumer->stop();
753 //m_mltConsumer->set("refresh", 0);
760 m_mltProducer->set_speed(0);
761 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
763 delete m_mltProducer;
764 m_mltProducer = NULL;
769 char *tmp = decodedString(playlist);
770 m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp);
772 if (m_blackClip) delete m_blackClip;
773 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
774 m_blackClip->set("id", "black");
775 if (!m_mltProducer || !m_mltProducer->is_valid()) {
776 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
778 m_mltProducer->optimise();
780 /*if (KdenliveSettings::osdtimecode()) {
781 // Attach filter for on screen display of timecode
783 QString attr = "attr_check";
784 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
785 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_fezzik", 1 );
786 mlt_producer_attach( m_mltProducer->get_producer(), filter );
787 mlt_filter_close( filter );
789 m_osdInfo = new Mlt::Filter("data_show");
790 tmp = decodedString(m_osdProfile);
791 m_osdInfo->set("resource", tmp);
793 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
794 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
795 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
796 m_osdInfo->set("dynamic", "1");
798 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
800 m_osdInfo->set("dynamic", "0");
803 m_fps = m_mltProducer->get_fps();
804 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
807 //TODO: seek to correct place after opening project.
808 // Needs to be done from another place since it crashes here.
809 m_mltProducer->seek(position);
813 emit rendererPosition(position);
816 /** Create the producer from the Westley QDomDocument */
817 QString Render::sceneList() {
819 Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist");
820 m_mltProducer->optimise();
821 westleyConsumer.set("terminate_on_pause", 1);
822 Mlt::Producer prod(m_mltProducer->get_producer());
823 bool split = m_isSplitView;
824 if (split) slotSplitView(false);
825 westleyConsumer.connect(prod);
826 westleyConsumer.start();
827 while (!westleyConsumer.is_stopped()) {}
828 playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist"));
829 if (split) slotSplitView(true);
833 void Render::saveSceneList(QString path, QDomElement kdenliveData) {
836 doc.setContent(sceneList(), false);
837 if (!kdenliveData.isNull()) {
838 // add Kdenlive specific tags
839 QDomNode wes = doc.elementsByTagName("westley").at(0);
840 wes.appendChild(doc.importNode(kdenliveData, true));
842 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
843 kWarning() << "////// ERROR writing to file: " << path;
846 QTextStream out(&file);
847 out << doc.toString();
852 void Render::saveZone(KUrl url, QString desc, QPoint zone) {
853 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
854 char *tmppath = decodedString("westley:" + url.path());
855 Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath);
856 m_mltProducer->optimise();
858 westleyConsumer.set("terminate_on_pause", 1);
859 if (m_name == "clip") {
860 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
861 tmppath = decodedString(desc);
863 list.insert_at(0, prod, 0);
864 list.set("title", tmppath);
866 westleyConsumer.connect(list);
869 //TODO: not working yet, save zone from timeline
870 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
871 /* Mlt::Service service(p1->parent().get_service());
872 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
874 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
875 tmppath = decodedString(desc);
876 //prod->set("title", tmppath);
878 westleyConsumer.connect(*p1); //list);
881 westleyConsumer.start();
884 const double Render::fps() const {
888 void Render::connectPlaylist() {
889 if (!m_mltConsumer) return;
890 //m_mltConsumer->set("refresh", "0");
891 m_mltConsumer->connect(*m_mltProducer);
892 m_mltProducer->set_speed(0);
893 m_mltConsumer->start();
894 emit durationChanged(m_mltProducer->get_playtime());
897 if (m_mltConsumer->start() == -1) {
898 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."));
899 m_mltConsumer = NULL;
906 void Render::refreshDisplay() {
908 if (!m_mltProducer) return;
909 //m_mltConsumer->set("refresh", 0);
911 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
912 /*if (KdenliveSettings::osdtimecode()) {
913 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
914 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
915 m_osdInfo->set("dynamic", "1");
916 m_mltProducer->attach(*m_osdInfo);
919 m_mltProducer->detach(*m_osdInfo);
920 m_osdInfo->set("dynamic", "0");
925 void Render::setVolume(double volume) {
926 if (!m_mltConsumer || !m_mltProducer) return;
928 m_mltConsumer->set("refresh", 0);
929 // Attach filter for on screen display of timecode
930 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
931 mlt_properties_set_double( properties, "meta.volume", volume );
932 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
933 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
935 if (!KdenliveSettings::osdtimecode()) {
936 m_mltProducer->detach(*m_osdInfo);
937 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
938 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
941 osdTimer->setSingleShot(2500);
944 void Render::slotOsdTimeout() {
945 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
946 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
947 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
948 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
952 void Render::start() {
953 kDebug() << "----- STARTING MONITOR: " << m_name;
955 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
959 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
960 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
961 if (m_mltConsumer->start() == -1) {
962 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."));
963 m_mltConsumer = NULL;
966 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
974 void Render::clear() {
975 kDebug() << " ********* RENDER CLEAR";
977 //m_mltConsumer->set("refresh", 0);
978 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
982 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
983 m_mltProducer->set_speed(0.0);
984 delete m_mltProducer;
985 m_mltProducer = NULL;
990 void Render::stop() {
991 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
992 kDebug() << "///////////// RENDER STOPPED: " << m_name;
994 m_mltConsumer->set("refresh", 0);
995 m_mltConsumer->stop();
996 // delete m_mltConsumer;
997 // m_mltConsumer = NULL;
999 kDebug() << "///////////// RENDER STOP2-------";
1002 if (m_mltProducer) {
1003 if (m_isZoneMode) resetZoneMode();
1004 m_mltProducer->set_speed(0.0);
1005 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1006 //kDebug() << m_mltProducer->get_length();
1008 kDebug() << "///////////// RENDER STOP3-------";
1011 void Render::stop(const GenTime & startTime) {
1013 kDebug() << "///////////// RENDER STOP-------2";
1014 if (m_mltProducer) {
1015 if (m_isZoneMode) resetZoneMode();
1016 m_mltProducer->set_speed(0.0);
1017 m_mltProducer->seek((int) startTime.frames(m_fps));
1019 m_mltConsumer->purge();
1022 void Render::pause() {
1023 if (!m_mltProducer || !m_mltConsumer)
1025 if (m_mltProducer->get_speed() == 0.0) return;
1026 if (m_isZoneMode) resetZoneMode();
1028 m_mltConsumer->set("refresh", 0);
1029 m_mltProducer->set_speed(0.0);
1030 emit rendererPosition(m_framePosition);
1031 m_mltProducer->seek(m_framePosition);
1032 m_mltConsumer->purge();
1035 void Render::switchPlay() {
1036 if (!m_mltProducer || !m_mltConsumer)
1038 if (m_isZoneMode) resetZoneMode();
1039 if (m_mltProducer->get_speed() == 0.0) {
1040 m_isBlocked = false;
1041 m_mltProducer->set_speed(1.0);
1042 m_mltConsumer->set("refresh", 1);
1045 m_mltConsumer->set("refresh", 0);
1046 m_mltProducer->set_speed(0.0);
1047 emit rendererPosition(m_framePosition);
1048 m_mltProducer->seek(m_framePosition);
1049 m_mltConsumer->purge();
1050 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1051 //m_mltConsumer->set("refresh", 0);
1052 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1053 m_mltProducer->set_speed(0);
1054 m_mltProducer->seek( position );
1055 //m_mltProducer->seek((int) m_framePosition);
1056 m_isBlocked = false;*/
1058 /*if (speed == 0.0) {
1059 m_mltProducer->seek((int) m_framePosition + 1);
1060 m_mltConsumer->purge();
1065 void Render::play(double speed) {
1068 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1069 m_isBlocked = false;
1070 m_mltProducer->set_speed(speed);
1071 /*if (speed == 0.0) {
1072 m_mltProducer->seek((int) m_framePosition + 1);
1073 m_mltConsumer->purge();
1078 void Render::play(const GenTime & startTime) {
1079 if (!m_mltProducer || !m_mltConsumer)
1081 m_isBlocked = false;
1082 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1083 m_mltProducer->set_speed(1.0);
1084 m_mltConsumer->set("refresh", 1);
1087 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) {
1088 if (!m_mltProducer || !m_mltConsumer)
1090 //m_mltProducer->set("eof", "loop");
1091 m_isLoopMode = true;
1092 m_loopStart = startTime;
1093 playZone(startTime, stopTime);
1096 void Render::playZone(const GenTime & startTime, const GenTime & stopTime) {
1097 if (!m_mltProducer || !m_mltConsumer)
1099 m_isBlocked = false;
1100 m_mltProducer->set("out", stopTime.frames(m_fps));
1101 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1102 m_mltProducer->set_speed(1.0);
1103 m_mltConsumer->set("refresh", 1);
1104 m_isZoneMode = true;
1107 void Render::resetZoneMode() {
1108 m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1109 //m_mltProducer->set("eof", "pause");
1110 m_isZoneMode = false;
1111 m_isLoopMode = false;
1114 void Render::seekToFrame(int pos) {
1115 //kDebug()<<" ********* RENDER SEEK TO POS";
1118 m_isBlocked = false;
1120 m_mltProducer->seek(pos);
1124 void Render::askForRefresh() {
1125 // Use a Timer so that we don't refresh too much
1126 refreshTimer->start(200);
1129 void Render::doRefresh() {
1130 // Use a Timer so that we don't refresh too much
1131 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1134 void Render::refresh() {
1135 if (!m_mltProducer || m_isBlocked)
1137 refreshTimer->stop();
1138 if (m_mltConsumer) {
1139 m_mltConsumer->set("refresh", 1);
1143 double Render::playSpeed() {
1144 if (m_mltProducer) return m_mltProducer->get_speed();
1148 GenTime Render::seekPosition() const {
1149 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1150 else return GenTime();
1154 const QString & Render::rendererName() const {
1159 void Render::emitFrameNumber(double position) {
1160 m_framePosition = position;
1161 emit rendererPosition((int) position);
1162 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1165 void Render::emitConsumerStopped() {
1166 // This is used to know when the playing stopped
1167 if (m_mltProducer) {
1168 double pos = m_mltProducer->position();
1169 if (m_isLoopMode) play(m_loopStart);
1170 else if (m_isZoneMode) resetZoneMode();
1171 emit rendererStopped((int) pos);
1172 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1173 //new QCustomEvent(10002));
1179 void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) {
1180 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1184 void Render::exportCurrentFrame(KUrl url, bool notify) {
1185 if (!m_mltProducer) {
1186 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1190 int height = 1080;//KdenliveSettings::defaultheight();
1191 int width = 1940; //KdenliveSettings::displaywidth();
1193 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1195 QPixmap pix(width, height);
1196 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1197 m_convert.set("forced", mlt_image_rgb24a);
1198 m_mltProducer->attach(m_convert);
1199 Mlt::Frame * frame = m_mltProducer->get_frame();
1200 m_mltProducer->detach(m_convert);
1202 pix = frameThumbnail(frame, width, height);
1205 pix.save(url.path(), "PNG");
1206 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1209 /** MLT PLAYLIST DIRECT MANIPULATON **/
1212 void Render::mltCheckLength(bool reload) {
1213 //kDebug()<<"checking track length: "<<track<<"..........";
1215 Mlt::Service service(m_mltProducer->get_service());
1216 Mlt::Tractor tractor(service);
1218 int trackNb = tractor.count();
1219 double duration = 0;
1220 double trackDuration;
1222 Mlt::Producer trackProducer(tractor.track(0));
1223 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1224 duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1225 m_mltProducer->set("out", duration);
1226 emit durationChanged((int) duration);
1229 while (trackNb > 1) {
1230 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1231 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1232 trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1;
1234 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1235 if (trackDuration > duration) duration = trackDuration;
1239 Mlt::Producer blackTrackProducer(tractor.track(0));
1240 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1241 double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1;
1243 if (blackDuration != duration) {
1244 blackTrackPlaylist.remove_region(0, (int)blackDuration);
1246 int dur = (int)duration;
1248 QDomElement black = doc.createElement("producer");
1249 black.setAttribute("mlt_service", "colour");
1250 black.setAttribute("colour", "black");
1251 black.setAttribute("id", "black");
1254 while (dur > 14000) {
1255 info.startPos = GenTime(i * 14000, m_fps);
1256 info.endPos = info.startPos + GenTime(13999, m_fps);
1257 mltInsertClip(info, black, m_blackClip);
1262 info.startPos = GenTime(i * 14000, m_fps);
1263 info.endPos = info.startPos + GenTime(dur, m_fps);
1264 mltInsertClip(info, black, m_blackClip);
1266 m_mltProducer->set("out", duration);
1267 emit durationChanged((int)duration);
1271 void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1272 if (!m_mltProducer) {
1273 kDebug() << "PLAYLIST NOT INITIALISED //////";
1276 Mlt::Producer parentProd(m_mltProducer->parent());
1277 if (parentProd.get_producer() == NULL) {
1278 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1282 Mlt::Service service(parentProd.get_service());
1283 Mlt::Tractor tractor(service);
1284 mlt_service_lock(service.get_service());
1285 Mlt::Producer trackProducer(tractor.track(info.track));
1286 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1287 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1288 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1289 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
1291 /*if (QString(prod->get("transparency")).toInt() == 1)
1292 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1294 mlt_service_unlock(service.get_service());
1296 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength();
1297 //tractor.multitrack()->refresh();
1298 //tractor.refresh();
1302 void Render::mltCutClip(int track, GenTime position) {
1306 Mlt::Service service(m_mltProducer->parent().get_service());
1307 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1309 Mlt::Tractor tractor(service);
1310 Mlt::Producer trackProducer(tractor.track(track));
1311 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1314 /* // Display playlist info
1315 kDebug()<<"//////////// BEFORE";
1316 for (int i = 0; i < trackPlaylist.count(); i++) {
1317 int blankStart = trackPlaylist.clip_start(i);
1318 int blankDuration = trackPlaylist.clip_length(i) - 1;
1320 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1321 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1324 int cutPos = (int) position.frames(m_fps);
1326 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1327 if (trackPlaylist.is_blank(clipIndex)) {
1328 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1329 m_isBlocked = false;
1332 mlt_service_lock(service.get_service());
1333 int clipStart = trackPlaylist.clip_start(clipIndex);
1334 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1335 mlt_service_unlock(service.get_service());
1337 // duplicate effects
1338 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1339 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1341 if (original == NULL || clip == NULL) {
1342 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1344 Mlt::Service clipService(original->get_service());
1345 Mlt::Service dupService(clip->get_service());
1347 Mlt::Filter *filter = clipService.filter(ct);
1349 if (filter->is_valid() && filter->get("kdenlive_id") != "") {
1350 // looks like there is no easy way to duplicate a filter,
1351 // so we will create a new one and duplicate its properties
1352 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1353 if (dup && dup->is_valid()) {
1354 Mlt::Properties entries(filter->get_properties());
1355 for (int i = 0;i < entries.count();i++) {
1356 dup->set(entries.get_name(i), entries.get(i));
1358 dupService.attach(*dup);
1362 filter = clipService.filter(ct);
1365 /* // Display playlist info
1366 kDebug()<<"//////////// AFTER";
1367 for (int i = 0; i < trackPlaylist.count(); i++) {
1368 int blankStart = trackPlaylist.clip_start(i);
1369 int blankDuration = trackPlaylist.clip_length(i) - 1;
1371 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1372 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1375 m_isBlocked = false;
1378 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) {
1380 mltRemoveClip(info.track, info.startPos);
1381 mltInsertClip(info, element, prod);
1385 bool Render::mltRemoveClip(int track, GenTime position) {
1386 Mlt::Service service(m_mltProducer->parent().get_service());
1387 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1389 Mlt::Tractor tractor(service);
1390 Mlt::Producer trackProducer(tractor.track(track));
1391 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1392 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1394 /* // Display playlist info
1395 kDebug()<<"//// BEFORE";
1396 for (int i = 0; i < trackPlaylist.count(); i++) {
1397 int blankStart = trackPlaylist.clip_start(i);
1398 int blankDuration = trackPlaylist.clip_length(i) - 1;
1400 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1401 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1404 if (trackPlaylist.is_blank(clipIndex)) {
1405 kDebug() << "// WARMNING, TRYING TO REMOVE A BLANK: " << clipIndex << ", AT: " << position.frames(25);
1409 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1410 trackPlaylist.replace_with_blank(clipIndex);
1411 trackPlaylist.consolidate_blanks(0);
1412 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1413 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1415 /* // Display playlist info
1416 kDebug()<<"//// AFTER";
1417 for (int i = 0; i < trackPlaylist.count(); i++) {
1418 int blankStart = trackPlaylist.clip_start(i);
1419 int blankDuration = trackPlaylist.clip_length(i) - 1;
1421 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1422 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1425 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength();
1426 m_isBlocked = false;
1430 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) {
1431 if (!m_mltProducer) {
1432 kDebug() << "PLAYLIST NOT INITIALISED //////";
1435 Mlt::Producer parentProd(m_mltProducer->parent());
1436 if (parentProd.get_producer() == NULL) {
1437 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1441 Mlt::Service service(parentProd.get_service());
1442 Mlt::Tractor tractor(service);
1443 int insertPos = pos.frames(m_fps);
1445 Mlt::Producer trackProducer(tractor.track(track));
1446 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1447 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1448 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1449 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1450 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1454 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) {
1455 if (!m_mltProducer) {
1456 kDebug() << "PLAYLIST NOT INITIALISED //////";
1459 Mlt::Producer parentProd(m_mltProducer->parent());
1460 if (parentProd.get_producer() == NULL) {
1461 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1464 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1465 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1467 Mlt::Service service(parentProd.get_service());
1468 Mlt::Tractor tractor(service);
1469 mlt_service_lock(service.get_service());
1470 int diff = duration.frames(m_fps);
1471 int offset = timeOffset.frames(m_fps);
1475 // insert space in one track only
1476 Mlt::Producer trackProducer(tractor.track(track));
1477 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1478 insertPos = trackClipStartList.value(track);
1479 if (insertPos != -1) {
1480 insertPos += offset;
1481 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1482 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1484 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1485 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1486 int position = trackPlaylist.clip_start(clipIndex);
1487 trackPlaylist.remove_region(position, - diff - 1);
1489 trackPlaylist.consolidate_blanks(0);
1491 // now move transitions
1492 mlt_service serv = m_mltProducer->parent().get_service();
1493 mlt_service nextservice = mlt_service_get_producer(serv);
1494 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1495 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1496 QString resource = mlt_properties_get(properties, "mlt_service");
1498 while (mlt_type == "transition") {
1499 mlt_transition tr = (mlt_transition) nextservice;
1500 int currentTrack = mlt_transition_get_b_track(tr);
1501 int currentIn = (int) mlt_transition_get_in(tr);
1502 int currentOut = (int) mlt_transition_get_out(tr);
1503 insertPos = trackTransitionStartList.value(track);
1504 if (insertPos != -1) {
1505 insertPos += offset;
1506 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1507 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1510 nextservice = mlt_service_producer(nextservice);
1511 if (nextservice == NULL) break;
1512 properties = MLT_SERVICE_PROPERTIES(nextservice);
1513 mlt_type = mlt_properties_get(properties, "mlt_type");
1514 resource = mlt_properties_get(properties, "mlt_service");
1517 int trackNb = tractor.count();
1518 while (trackNb > 1) {
1519 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1520 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1523 int clipNb = trackPlaylist.count();
1524 insertPos = trackClipStartList.value(trackNb - 1);
1525 if (insertPos != -1) {
1526 insertPos += offset;
1528 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1529 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1530 for (int i = 0; i < clipNb; i++) {
1531 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1532 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1533 kDebug()<<"-------------";
1535 kDebug()<<"END-------------";*/
1538 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1539 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1541 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1542 if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1543 int position = trackPlaylist.clip_start(clipIndex);
1544 trackPlaylist.remove_region(position, - diff - 1);
1546 trackPlaylist.consolidate_blanks(0);
1550 // now move transitions
1551 mlt_service serv = m_mltProducer->parent().get_service();
1552 mlt_service nextservice = mlt_service_get_producer(serv);
1553 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1554 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1555 QString resource = mlt_properties_get(properties, "mlt_service");
1557 while (mlt_type == "transition") {
1558 mlt_transition tr = (mlt_transition) nextservice;
1559 int currentIn = (int) mlt_transition_get_in(tr);
1560 int currentOut = (int) mlt_transition_get_out(tr);
1561 int currentTrack = mlt_transition_get_b_track(tr);
1562 insertPos = trackTransitionStartList.value(currentTrack);
1563 if (insertPos != -1) {
1564 insertPos += offset;
1565 if (currentOut > insertPos && resource != "mix") {
1566 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1569 nextservice = mlt_service_producer(nextservice);
1570 if (nextservice == NULL) break;
1571 properties = MLT_SERVICE_PROPERTIES(nextservice);
1572 mlt_type = mlt_properties_get(properties, "mlt_type");
1573 resource = mlt_properties_get(properties, "mlt_service");
1576 mlt_service_unlock(service.get_service());
1578 m_mltConsumer->set("refresh", 1);
1581 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
1584 Mlt::Service service(m_mltProducer->parent().get_service());
1585 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1586 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1587 Mlt::Tractor tractor(service);
1588 Mlt::Producer trackProducer(tractor.track(info.track));
1589 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1590 int startPos = info.startPos.frames(m_fps);
1591 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1592 int clipLength = trackPlaylist.clip_length(clipIndex);
1594 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1595 QString serv = clip.parent().get("mlt_service");
1596 QString id = clip.parent().get("id");
1597 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1598 if (serv == "avformat" && speed != 1.0) {
1599 mlt_service_lock(service.get_service());
1600 QString url = clip.parent().get("resource");
1601 url.append("?" + QString::number(speed));
1602 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1603 if (!slowprod || slowprod->get_producer() == NULL) {
1604 char *tmp = decodedString(url);
1605 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1607 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1608 tmp = decodedString(producerid);
1609 slowprod->set("id", tmp);
1611 m_slowmotionProducers.insert(url, slowprod);
1613 trackPlaylist.replace_with_blank(clipIndex);
1614 trackPlaylist.consolidate_blanks(0);
1615 // Check that the blank space is long enough for our new duration
1616 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1617 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1619 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1620 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1621 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1622 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1623 trackPlaylist.insert_at(startPos, *cut, 1);
1624 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1625 newLength = trackPlaylist.clip_length(clipIndex);
1626 mlt_service_unlock(service.get_service());
1627 } else if (speed == 1.0) {
1628 mlt_service_lock(service.get_service());
1630 trackPlaylist.replace_with_blank(clipIndex);
1631 trackPlaylist.consolidate_blanks(0);
1633 // Check that the blank space is long enough for our new duration
1634 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1635 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1638 GenTime oldDuration = GenTime(clipLength, m_fps);
1639 GenTime newDuration = oldDuration * oldspeed;
1640 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1641 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1642 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1643 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1644 trackPlaylist.insert_at(startPos, *cut, 1);
1645 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1646 newLength = trackPlaylist.clip_length(clipIndex);
1647 mlt_service_unlock(service.get_service());
1649 } else if (serv == "framebuffer") {
1650 mlt_service_lock(service.get_service());
1651 QString url = clip.parent().get("resource");
1652 url = url.section("?", 0, 0);
1653 url.append("?" + QString::number(speed));
1654 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1655 if (!slowprod || slowprod->get_producer() == NULL) {
1656 char *tmp = decodedString(url);
1657 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1659 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1660 tmp = decodedString(producerid);
1661 slowprod->set("id", tmp);
1663 m_slowmotionProducers.insert(url, slowprod);
1665 trackPlaylist.replace_with_blank(clipIndex);
1666 trackPlaylist.consolidate_blanks(0);
1668 GenTime oldDuration = GenTime(clipLength, m_fps);
1669 GenTime newDuration = oldDuration * oldspeed / speed;
1671 // Check that the blank space is long enough for our new duration
1672 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1673 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1676 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1677 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1678 cut = slowprod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1679 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
1681 trackPlaylist.insert_at(startPos, *cut, 1);
1682 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1683 newLength = trackPlaylist.clip_length(clipIndex);
1685 mlt_service_unlock(service.get_service());
1687 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1688 m_isBlocked = false;
1692 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1694 Mlt::Service service(m_mltProducer->parent().get_service());
1695 bool success = false;
1696 Mlt::Tractor tractor(service);
1697 Mlt::Producer trackProducer(tractor.track(track));
1698 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1699 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1700 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1702 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1705 Mlt::Service clipService(clip->get_service());
1706 // if (tag.startsWith("ladspa")) tag = "ladspa";
1709 Mlt::Filter *filter = clipService.filter(ct);
1711 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1712 if (clipService.detach(*filter) == 0) success = true;
1713 kDebug() << " / / / DLEETED EFFECT: " << ct;
1715 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1718 filter = clipService.filter(ct);
1720 m_isBlocked = false;
1721 if (doRefresh) refresh();
1726 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) {
1728 Mlt::Service service(m_mltProducer->parent().get_service());
1730 Mlt::Tractor tractor(service);
1731 Mlt::Producer trackProducer(tractor.track(track));
1732 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1734 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1738 Mlt::Service clipService(clip->get_service());
1741 // temporarily remove all effects after insert point
1742 QList <Mlt::Filter *> filtersList;
1743 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
1745 Mlt::Filter *filter = clipService.filter(ct);
1747 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1748 filtersList.append(filter);
1749 clipService.detach(*filter);
1751 filter = clipService.filter(ct);
1755 QString tag = params.paramValue("tag");
1756 kDebug() << " / / INSERTING EFFECT: " << tag;
1757 if (tag.startsWith("ladspa")) tag = "ladspa";
1758 char *filterTag = decodedString(tag);
1759 char *filterId = decodedString(params.paramValue("id"));
1760 QHash<QString, QString>::Iterator it;
1761 QString kfr = params.paramValue("keyframes");
1763 if (!kfr.isEmpty()) {
1764 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1765 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
1766 char *starttag = decodedString(params.paramValue("starttag", "start"));
1767 char *endtag = decodedString(params.paramValue("endtag", "end"));
1768 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1769 int duration = clip->get_playtime();
1770 double max = params.paramValue("max").toDouble();
1771 double min = params.paramValue("min").toDouble();
1772 double factor = params.paramValue("factor", "1").toDouble();
1773 params.removeParam("starttag");
1774 params.removeParam("endtag");
1775 params.removeParam("keyframes");
1776 params.removeParam("min");
1777 params.removeParam("max");
1778 params.removeParam("factor");
1780 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1781 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1782 if (filter && filter->is_valid()) {
1783 filter->set("kdenlive_id", filterId);
1784 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1785 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1786 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1787 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1788 if (x2 == -1) x2 = duration;
1790 for (int j = 0; j < params.count(); j++) {
1791 char *name = decodedString(params.at(j).name());
1792 char *value = decodedString(params.at(j).value());
1793 filter->set(name, value);
1798 filter->set("in", x1);
1799 filter->set("out", x2);
1800 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1801 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1802 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1803 clipService.attach(*filter);
1810 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1811 if (filter && filter->is_valid())
1812 filter->set("kdenlive_id", filterId);
1814 kDebug() << "filter is NULL";
1815 m_isBlocked = false;
1819 params.removeParam("kdenlive_id");
1821 for (int j = 0; j < params.count(); j++) {
1822 char *name = decodedString(params.at(j).name());
1823 char *value = decodedString(params.at(j).value());
1824 filter->set(name, value);
1830 QString effectArgs = params.paramValue("id").section('_', 1);
1832 params.removeParam("id");
1833 params.removeParam("kdenlive_ix");
1834 params.removeParam("tag");
1835 params.removeParam("disabled");
1837 for (int j = 0; j < params.count(); j++) {
1838 effectArgs.append(' ' + params.at(j).value());
1840 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
1841 char *value = decodedString(effectArgs.simplified());
1842 filter->set("effect", value);
1847 // attach filter to the clip
1848 clipService.attach(*filter);
1853 // re-add following filters
1854 for (int i = 0; i < filtersList.count(); i++) {
1855 clipService.attach(*(filtersList.at(i)));
1858 m_isBlocked = false;
1859 if (doRefresh) refresh();
1863 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) {
1864 QString index = params.paramValue("kdenlive_ix");
1865 QString tag = params.paramValue("tag");
1867 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1868 // This is a keyframe effect, to edit it, we remove it and re-add it.
1869 mltRemoveEffect(track, position, index);
1870 bool success = mltAddEffect(track, position, params);
1875 Mlt::Service service(m_mltProducer->parent().get_service());
1877 Mlt::Tractor tractor(service);
1878 Mlt::Producer trackProducer(tractor.track(track));
1879 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1880 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1881 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1883 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1886 Mlt::Service clipService(clip->get_service());
1889 Mlt::Filter *filter = clipService.filter(ct);
1891 if (filter->get("kdenlive_ix") == index) {
1895 filter = clipService.filter(ct);
1899 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1900 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1902 filter = clipService.filter(ct);
1903 QList <Mlt::Filter *> filtersList;
1905 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1906 filtersList.append(filter);
1907 clipService.detach(*filter);
1909 filter = clipService.filter(ct);
1911 bool success = mltAddEffect(track, position, params);
1913 for (int i = 0; i < filtersList.count(); i++) {
1914 clipService.attach(*(filtersList.at(i)));
1917 m_isBlocked = false;
1921 for (int j = 0; j < params.count(); j++) {
1922 char *name = decodedString(params.at(j).name());
1923 char *value = decodedString(params.at(j).value());
1924 filter->set(name, value);
1929 m_isBlocked = false;
1934 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1936 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
1937 Mlt::Service service(m_mltProducer->parent().get_service());
1939 Mlt::Tractor tractor(service);
1940 Mlt::Producer trackProducer(tractor.track(track));
1941 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1942 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1943 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1945 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1948 Mlt::Service clipService(clip->get_service());
1951 QList <Mlt::Filter *> filtersList;
1952 Mlt::Filter *filter = clipService.filter(ct);
1954 if (newPos > oldPos) {
1956 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1957 filter->set("kdenlive_ix", newPos);
1958 filtersList.append(filter);
1959 clipService.detach(*filter);
1960 filter = clipService.filter(ct);
1961 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1962 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1964 filter = clipService.filter(ct);
1968 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1969 filtersList.append(filter);
1970 clipService.detach(*filter);
1972 filter = clipService.filter(ct);
1976 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1977 filter->set("kdenlive_ix", newPos);
1978 filtersList.append(filter);
1979 clipService.detach(*filter);
1981 filter = clipService.filter(ct);
1985 filter = clipService.filter(ct);
1987 int pos = QString(filter->get("kdenlive_ix")).toInt();
1988 if (pos >= newPos) {
1989 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
1990 filtersList.append(filter);
1991 clipService.detach(*filter);
1993 filter = clipService.filter(ct);
1997 for (int i = 0; i < filtersList.count(); i++) {
1998 clipService.attach(*(filtersList.at(i)));
2001 m_isBlocked = false;
2005 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
2008 Mlt::Service service(m_mltProducer->parent().get_service());
2010 Mlt::Tractor tractor(service);
2011 Mlt::Producer trackProducer(tractor.track(info.track));
2012 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2014 /* // Display playlist info
2015 kDebug()<<"//////////// BEFORE RESIZE";
2016 for (int i = 0; i < trackPlaylist.count(); i++) {
2017 int blankStart = trackPlaylist.clip_start(i);
2018 int blankDuration = trackPlaylist.clip_length(i) - 1;
2020 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2021 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
2024 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2025 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2026 m_isBlocked = false;
2029 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2030 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2031 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2032 int previousStart = clip->get_in();
2033 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2034 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2035 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2036 //trackPlaylist.consolidate_blanks(0);
2037 // skip to next clip
2039 int diff = newDuration - previousDuration;
2040 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
2042 // clip was made longer, trim next blank if there is one.
2043 if (trackPlaylist.is_blank(clipIndex)) {
2044 int blankStart = trackPlaylist.clip_start(clipIndex);
2045 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
2046 if (diff - blankDuration == 1) {
2047 trackPlaylist.remove(clipIndex);
2048 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
2050 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2052 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2054 trackPlaylist.consolidate_blanks(0);
2057 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
2058 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2059 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2060 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2061 ItemInfo transpinfo;
2062 transpinfo.startPos = info.startPos;
2063 transpinfo.endPos = info.startPos + clipDuration;
2064 transpinfo.track = info.track;
2065 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2067 m_isBlocked = false;
2068 m_mltConsumer->set("refresh", 1);
2072 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
2073 Mlt::Service service(m_mltProducer->parent().get_service());
2074 Mlt::Tractor tractor(service);
2075 Mlt::Producer trackProducer(tractor.track(track));
2078 if (blind) trackProducer.set("hide", 3);
2079 else trackProducer.set("hide", 2);
2081 trackProducer.set("hide", 1);
2083 trackProducer.set("hide", 0);
2085 tractor.multitrack()->refresh();
2090 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
2091 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2092 Mlt::Service service(m_mltProducer->parent().get_service());
2093 int moveFrame = (int) diff.frames(m_fps);
2094 Mlt::Tractor tractor(service);
2095 Mlt::Producer trackProducer(tractor.track(info.track));
2096 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2097 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2098 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2101 mlt_service_lock(service.get_service());
2102 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2103 /*int previousStart = trackPlaylist.clip_start(clipIndex);
2104 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
2105 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
2106 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2108 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2109 mlt_service_unlock(service.get_service());
2112 //m_mltConsumer->set("refresh", 0);
2113 int previousStart = clip->get_in();
2114 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2116 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2117 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2118 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2120 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2121 int blankIndex = clipIndex - 1;
2122 int blankLength = trackPlaylist.clip_length(blankIndex);
2123 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2124 if (! trackPlaylist.is_blank(blankIndex)) {
2125 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2127 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2128 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2130 trackPlaylist.consolidate_blanks(0);
2131 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2132 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2133 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2134 ItemInfo transpinfo;
2135 transpinfo.startPos = info.startPos + diff;
2136 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2137 transpinfo.track = info.track;
2138 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2140 m_isBlocked = false;
2141 //m_mltConsumer->set("refresh", 1);
2142 mlt_service_unlock(service.get_service());
2143 m_mltConsumer->set("refresh", 1);
2147 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
2148 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2152 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
2153 kDebug() << "NEW PROD ID: " << prod->get("id");
2154 m_mltConsumer->set("refresh", 0);
2155 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2156 mlt_service_lock(m_mltConsumer->get_service());
2157 Mlt::Service service(m_mltProducer->parent().get_service());
2158 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2160 Mlt::Tractor tractor(service);
2161 Mlt::Producer trackProducer(tractor.track(track));
2162 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2163 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2164 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2165 if (clipProducer.is_blank()) {
2166 kDebug() << "// ERROR UPDATING CLIP PROD";
2167 mlt_service_unlock(m_mltConsumer->get_service());
2168 m_isBlocked = false;
2171 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2173 // move all effects to the correct producer
2174 Mlt::Service clipService(clipProducer.get_service());
2175 Mlt::Service newClipService(clip->get_service());
2178 Mlt::Filter *filter = clipService.filter(ct);
2180 if (filter->get("kdenlive_ix") != 0) {
2181 clipService.detach(*filter);
2182 newClipService.attach(*filter);
2184 filter = clipService.filter(ct);
2187 trackPlaylist.insert_at(pos, clip, 1);
2188 mlt_service_unlock(m_mltConsumer->get_service());
2189 m_isBlocked = false;
2192 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
2195 m_mltConsumer->set("refresh", 0);
2196 mlt_service_lock(m_mltConsumer->get_service());
2197 Mlt::Service service(m_mltProducer->parent().get_service());
2198 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2200 Mlt::Tractor tractor(service);
2201 Mlt::Producer trackProducer(tractor.track(startTrack));
2202 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2203 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2204 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2205 bool checkLength = false;
2206 if (endTrack == startTrack) {
2207 //mlt_service_lock(service.get_service());
2208 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2209 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2210 // error, destination is not empty
2211 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2212 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2213 mlt_service_unlock(m_mltConsumer->get_service());
2214 m_isBlocked = false;
2217 trackPlaylist.consolidate_blanks(0);
2218 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2219 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2220 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2222 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2224 //mlt_service_unlock(service.get_service());
2226 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2227 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2228 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2229 // error, destination is not empty
2230 mlt_service_unlock(m_mltConsumer->get_service());
2231 m_isBlocked = false;
2234 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2235 if (clipProducer.is_blank()) {
2236 // error, destination is not empty
2237 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2238 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2239 mlt_service_unlock(m_mltConsumer->get_service());
2240 m_isBlocked = false;
2243 trackPlaylist.consolidate_blanks(0);
2244 destTrackPlaylist.consolidate_blanks(1);
2245 Mlt::Producer *clip;
2246 // check if we are moving a slowmotion producer
2247 QString serv = clipProducer.parent().get("mlt_service");
2248 if (serv == "framebuffer") {
2249 clip = &clipProducer;
2250 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2252 // move all effects to the correct producer
2253 Mlt::Service clipService(clipProducer.get_service());
2254 Mlt::Service newClipService(clip->get_service());
2257 Mlt::Filter *filter = clipService.filter(ct);
2259 if (filter->get("kdenlive_ix") != 0) {
2260 clipService.detach(*filter);
2261 newClipService.attach(*filter);
2263 filter = clipService.filter(ct);
2266 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2267 destTrackPlaylist.consolidate_blanks(0);
2268 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2269 kDebug() << "//////// moving clip transparency";
2270 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2272 if (clipIndex > trackPlaylist.count()) checkLength = true;
2273 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2277 if (checkLength) mltCheckLength();
2278 mlt_service_unlock(m_mltConsumer->get_service());
2279 m_isBlocked = false;
2280 m_mltConsumer->set("refresh", 1);
2284 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
2285 Mlt::Service service(m_mltProducer->parent().get_service());
2286 Mlt::Tractor tractor(service);
2287 Mlt::Field *field = tractor.field();
2289 mlt_service_lock(service.get_service());
2290 m_mltConsumer->set("refresh", 0);
2293 mlt_service serv = m_mltProducer->parent().get_service();
2294 mlt_service nextservice = mlt_service_get_producer(serv);
2295 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2296 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2297 QString resource = mlt_properties_get(properties, "mlt_service");
2298 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2300 int new_in = (int)newIn.frames(m_fps);
2301 int new_out = (int)newOut.frames(m_fps) - 1;
2303 while (mlt_type == "transition") {
2304 mlt_transition tr = (mlt_transition) nextservice;
2305 int currentTrack = mlt_transition_get_b_track(tr);
2306 int currentIn = (int) mlt_transition_get_in(tr);
2307 int currentOut = (int) mlt_transition_get_out(tr);
2309 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2310 mlt_transition_set_in_and_out(tr, new_in, new_out);
2311 if (newTrack - startTrack != 0) {
2312 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
2314 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2315 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2316 mlt_properties_set_int(properties, "b_track", newTrack);
2317 //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);
2321 nextservice = mlt_service_producer(nextservice);
2322 if (nextservice == NULL) break;
2323 properties = MLT_SERVICE_PROPERTIES(nextservice);
2324 mlt_type = mlt_properties_get(properties, "mlt_type");
2325 resource = mlt_properties_get(properties, "mlt_service");
2327 m_isBlocked = false;
2328 mlt_service_unlock(service.get_service());
2329 m_mltConsumer->set("refresh", 1);
2332 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2333 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2334 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2336 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2337 mltAddTransition(tag, a_track, b_track, in, out, xml);
2339 //mltSavePlaylist();
2342 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2344 Mlt::Service service(m_mltProducer->parent().get_service());
2345 Mlt::Tractor tractor(service);
2346 Mlt::Field *field = tractor.field();
2348 //m_mltConsumer->set("refresh", 0);
2349 mlt_service serv = m_mltProducer->parent().get_service();
2351 mlt_service nextservice = mlt_service_get_producer(serv);
2352 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2353 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2354 QString resource = mlt_properties_get(properties, "mlt_service");
2355 int in_pos = (int) in.frames(m_fps);
2356 int out_pos = (int) out.frames(m_fps) - 1;
2358 while (mlt_type == "transition") {
2359 mlt_transition tr = (mlt_transition) nextservice;
2360 int currentTrack = mlt_transition_get_b_track(tr);
2361 int currentBTrack = mlt_transition_get_a_track(tr);
2362 int currentIn = (int) mlt_transition_get_in(tr);
2363 int currentOut = (int) mlt_transition_get_out(tr);
2365 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2367 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2368 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2369 QMap<QString, QString>::Iterator it;
2371 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2372 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2373 if (currentBTrack != a_track) {
2374 mlt_properties_set_int(properties, "a_track", a_track);
2376 for (it = map.begin(); it != map.end(); ++it) {
2378 char *name = decodedString(key);
2379 char *value = decodedString(it.value());
2380 mlt_properties_set(transproperties, name, value);
2381 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2382 //filter->set("kdenlive_id", id);
2388 nextservice = mlt_service_producer(nextservice);
2389 if (nextservice == NULL) break;
2390 properties = MLT_SERVICE_PROPERTIES(nextservice);
2391 mlt_type = mlt_properties_get(properties, "mlt_type");
2392 resource = mlt_properties_get(properties, "mlt_service");
2394 m_isBlocked = false;
2395 m_mltConsumer->set("refresh", 1);
2398 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2399 Mlt::Service service(m_mltProducer->parent().get_service());
2400 Mlt::Tractor tractor(service);
2401 Mlt::Field *field = tractor.field();
2403 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2404 mlt_service serv = m_mltProducer->parent().get_service();
2406 mlt_service nextservice = mlt_service_get_producer(serv);
2407 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2408 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2409 QString resource = mlt_properties_get(properties, "mlt_service");
2411 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2413 while (mlt_type == "transition") {
2414 mlt_transition tr = (mlt_transition) nextservice;
2415 int currentTrack = mlt_transition_get_b_track(tr);
2416 int currentIn = (int) mlt_transition_get_in(tr);
2417 int currentOut = (int) mlt_transition_get_out(tr);
2418 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2420 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2421 mlt_field_disconnect_service(field->get_field(), nextservice);
2424 nextservice = mlt_service_producer(nextservice);
2425 if (nextservice == NULL) break;
2426 properties = MLT_SERVICE_PROPERTIES(nextservice);
2427 mlt_type = mlt_properties_get(properties, "mlt_type");
2428 resource = mlt_properties_get(properties, "mlt_service");
2430 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2433 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2434 QDomNodeList attribs = xml.elementsByTagName("parameter");
2435 QMap<QString, QString> map;
2436 for (int i = 0;i < attribs.count();i++) {
2437 QDomElement e = attribs.item(i).toElement();
2438 QString name = e.attribute("name");
2439 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2440 map[name] = e.attribute("default");
2441 if (!e.attribute("value").isEmpty()) {
2442 map[name] = e.attribute("value");
2444 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2445 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2446 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2449 if (e.attribute("namedesc").contains(";")) {
2450 QString format = e.attribute("format");
2451 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2452 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2454 QTextStream txtNeu(&neu);
2455 if (values.size() > 0)
2456 txtNeu << (int)values[0].toDouble();
2458 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2459 txtNeu << separators[i];
2460 txtNeu << (int)(values[i+1].toDouble());
2462 if (i < separators.size())
2463 txtNeu << separators[i];
2464 map[e.attribute("name")] = neu;
2471 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2472 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2473 Mlt::Service service(m_mltProducer->parent().get_service());
2474 Mlt::Tractor tractor(service);
2475 Mlt::Field *field = tractor.field();
2477 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2478 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2479 transition->set("transparency", id);
2480 transition->set("fill", 1);
2481 transition->set("internal_added", 237);
2482 field->plant_transition(*transition, transitiontrack, info.track);
2486 void Render::mltDeleteTransparency(int pos, int track, int id) {
2487 Mlt::Service service(m_mltProducer->parent().get_service());
2488 Mlt::Tractor tractor(service);
2489 Mlt::Field *field = tractor.field();
2491 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2492 mlt_service serv = m_mltProducer->parent().get_service();
2494 mlt_service nextservice = mlt_service_get_producer(serv);
2495 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2496 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2497 QString resource = mlt_properties_get(properties, "mlt_service");
2499 while (mlt_type == "transition") {
2500 mlt_transition tr = (mlt_transition) nextservice;
2501 int currentTrack = mlt_transition_get_b_track(tr);
2502 int currentIn = (int) mlt_transition_get_in(tr);
2503 int currentOut = (int) mlt_transition_get_out(tr);
2504 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2505 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2507 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2508 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2509 mlt_field_disconnect_service(field->get_field(), nextservice);
2512 nextservice = mlt_service_producer(nextservice);
2513 if (nextservice == NULL) break;
2514 properties = MLT_SERVICE_PROPERTIES(nextservice);
2515 mlt_type = mlt_properties_get(properties, "mlt_type");
2516 resource = mlt_properties_get(properties, "mlt_service");
2518 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2521 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2522 Mlt::Service service(m_mltProducer->parent().get_service());
2523 Mlt::Tractor tractor(service);
2524 Mlt::Field *field = tractor.field();
2526 mlt_service_lock(service.get_service());
2527 m_mltConsumer->set("refresh", 0);
2530 mlt_service serv = m_mltProducer->parent().get_service();
2531 mlt_service nextservice = mlt_service_get_producer(serv);
2532 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2533 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2534 QString resource = mlt_properties_get(properties, "mlt_service");
2535 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2536 while (mlt_type == "transition") {
2537 mlt_transition tr = (mlt_transition) nextservice;
2538 int currentTrack = mlt_transition_get_b_track(tr);
2539 int currentIn = (int) mlt_transition_get_in(tr);
2540 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2541 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2542 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2543 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2544 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2545 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2548 nextservice = mlt_service_producer(nextservice);
2549 if (nextservice == NULL) break;
2550 properties = MLT_SERVICE_PROPERTIES(nextservice);
2551 mlt_type = mlt_properties_get(properties, "mlt_type");
2552 resource = mlt_properties_get(properties, "mlt_service");
2554 m_isBlocked = false;
2555 mlt_service_unlock(service.get_service());
2556 m_mltConsumer->set("refresh", 1);
2560 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2561 Mlt::Service service(m_mltProducer->parent().get_service());
2562 Mlt::Tractor tractor(service);
2563 Mlt::Field *field = tractor.field();
2565 mlt_service_lock(service.get_service());
2566 m_mltConsumer->set("refresh", 0);
2569 mlt_service serv = m_mltProducer->parent().get_service();
2570 mlt_service nextservice = mlt_service_get_producer(serv);
2571 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2572 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2573 QString resource = mlt_properties_get(properties, "mlt_service");
2575 while (mlt_type == "transition") {
2576 mlt_transition tr = (mlt_transition) nextservice;
2577 int currentTrack = mlt_transition_get_b_track(tr);
2578 int currentaTrack = mlt_transition_get_a_track(tr);
2579 int currentIn = (int) mlt_transition_get_in(tr);
2580 int currentOut = (int) mlt_transition_get_out(tr);
2581 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2582 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2583 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2584 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2585 kDebug() << "//////MOVING";
2586 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2587 if (endTrack != startTrack) {
2588 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2589 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2590 mlt_properties_set_int(properties, "b_track", endTrack);
2594 nextservice = mlt_service_producer(nextservice);
2595 if (nextservice == NULL) break;
2596 properties = MLT_SERVICE_PROPERTIES(nextservice);
2597 mlt_type = mlt_properties_get(properties, "mlt_type");
2598 resource = mlt_properties_get(properties, "mlt_service");
2600 m_isBlocked = false;
2601 mlt_service_unlock(service.get_service());
2602 m_mltConsumer->set("refresh", 1);
2606 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2608 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2609 Mlt::Service service(m_mltProducer->parent().get_service());
2611 Mlt::Tractor tractor(service);
2612 Mlt::Field *field = tractor.field();
2614 char *transId = decodedString(tag);
2615 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2616 if (out != GenTime())
2617 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2618 QMap<QString, QString>::Iterator it;
2620 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2621 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2623 for (it = args.begin(); it != args.end(); ++it) {
2625 char *name = decodedString(key);
2626 char *value = decodedString(it.value());
2627 transition->set(name, value);
2628 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2629 //filter->set("kdenlive_id", id);
2633 // attach filter to the clip
2634 field->plant_transition(*transition, a_track, b_track);
2639 void Render::mltSavePlaylist() {
2640 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2641 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2642 fileConsumer.set("resource", "/tmp/playlist.westley");
2644 Mlt::Service service(m_mltProducer->get_service());
2646 fileConsumer.connect(service);
2647 fileConsumer.start();
2650 QList <Mlt::Producer *> Render::producersList() {
2651 QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
2653 Mlt::Service service(m_mltProducer->parent().get_service());
2654 Mlt::Tractor tractor(service);
2656 int trackNb = tractor.count();
2657 for (int t = 1; t < trackNb; t++) {
2658 Mlt::Producer trackProducer(tractor.track(t));
2659 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2660 int clipNb = trackPlaylist.count();
2661 kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2662 for (int i = 0; i < clipNb; i++) {
2663 Mlt::Producer *prod = trackPlaylist.get_clip(i);
2664 Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
2665 //kDebug()<<"PROD: "<<nprod->get("producer")<<", ID: "<<nprod->get("id")<<nprod->get("resource");
2666 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2667 ids.append(nprod->get("id"));
2668 prods.append(nprod);
2675 void Render::mltInsertTrack(int ix, bool videoTrack) {
2679 m_mltConsumer->set("refresh", 0);
2680 mlt_service_lock(m_mltConsumer->get_service());
2681 Mlt::Service service(m_mltProducer->parent().get_service());
2682 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2684 Mlt::Tractor tractor(service);
2686 Mlt::Playlist playlist;// = new Mlt::Playlist();
2687 int ct = tractor.count();
2688 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2691 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2692 tractor.set_track(playlist, pos);
2693 Mlt::Producer newProd(tractor.track(pos));
2694 if (!videoTrack) newProd.set("hide", 1);
2696 for (; pos <= ct; pos++) {
2697 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2698 tractor.set_track(*prodToMove, pos);
2699 prodToMove = prodToMove2;
2702 tractor.set_track(playlist, ix);
2703 Mlt::Producer newProd(tractor.track(ix));
2704 if (!videoTrack) newProd.set("hide", 1);
2708 mlt_service serv = m_mltProducer->parent().get_service();
2709 mlt_service nextservice = mlt_service_get_producer(serv);
2710 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2711 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2712 QString resource = mlt_properties_get(properties, "mlt_service");
2714 while (mlt_type == "transition") {
2715 if (resource != "mix") {
2716 mlt_transition tr = (mlt_transition) nextservice;
2717 int currentTrack = mlt_transition_get_b_track(tr);
2718 int currentaTrack = mlt_transition_get_a_track(tr);
2719 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2721 if (currentTrack >= ix) {
2722 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2723 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2726 nextservice = mlt_service_producer(nextservice);
2727 if (nextservice == NULL) break;
2728 properties = MLT_SERVICE_PROPERTIES(nextservice);
2729 mlt_type = mlt_properties_get(properties, "mlt_type");
2730 resource = mlt_properties_get(properties, "mlt_service");
2733 // Add audio mix transition to last track
2734 Mlt::Field *field = tractor.field();
2735 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2736 //transition->set("mlt_service", "mix");
2737 transition->set("a_track", 1);
2738 transition->set("b_track", ct);
2739 transition->set("always_active", 1);
2740 transition->set("internal_added", 237);
2741 transition->set("combine", 1);
2742 field->plant_transition(*transition, 1, ct);
2744 mlt_service_unlock(m_mltConsumer->get_service());
2745 m_isBlocked = false;
2746 blockSignals(false);
2750 void Render::mltDeleteTrack(int ix) {
2752 doc.setContent(sceneList(), false);
2753 int tracksCount = doc.elementsByTagName("track").count() - 1;
2754 QDomNode track = doc.elementsByTagName("track").at(ix);
2755 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2756 QDomNodeList transitions = doc.elementsByTagName("transition");
2757 for (int i = 0; i < transitions.count(); i++) {
2758 QDomElement e = transitions.at(i).toElement();
2759 QDomNodeList props = e.elementsByTagName("property");
2760 QMap <QString, QString> mappedProps;
2761 for (int j = 0; j < props.count(); j++) {
2762 QDomElement f = props.at(j).toElement();
2763 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2765 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2766 tractor.removeChild(transitions.at(i));
2767 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2768 // Transition needs to be moved
2769 int a_track = mappedProps.value("a_track").toInt();
2770 int b_track = mappedProps.value("b_track").toInt();
2771 if (a_track > 0) a_track --;
2772 if (b_track > 0) b_track --;
2773 for (int j = 0; j < props.count(); j++) {
2774 QDomElement f = props.at(j).toElement();
2775 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2776 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2781 tractor.removeChild(track);
2782 setSceneList(doc.toString(), m_framePosition);
2788 m_mltConsumer->set("refresh", 0);
2789 mlt_service_lock(m_mltConsumer->get_service());
2790 Mlt::Service service(m_mltProducer->parent().get_service());
2791 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2793 /*Mlt::Tractor tractor(service);
2796 Mlt::Multitrack *multi = tractor.multitrack();
2799 int ct = tractor.count();
2800 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
2802 for (; pos < ct ; pos++) {
2803 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
2804 //mlt_service_close(lastTrack->get_service());
2806 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
2807 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
2808 mlt_service_close(prodToMove->get_service());
2809 mlt_service_close(prodToClose->get_service());
2810 tractor.set_track(*prodToMove, pos);
2814 /*mlt_service serv = m_mltProducer->parent().get_service();
2815 mlt_service nextservice = mlt_service_get_producer(serv);
2816 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2817 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2818 QString resource = mlt_properties_get(properties, "mlt_service");
2820 while (mlt_type == "transition") {
2821 if (resource != "mix") {
2822 mlt_transition tr = (mlt_transition) nextservice;
2823 int currentTrack = mlt_transition_get_b_track(tr);
2824 int currentaTrack = mlt_transition_get_a_track(tr);
2825 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2827 if (currentTrack >= ix) {
2828 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2829 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2832 nextservice = mlt_service_producer(nextservice);
2833 if (nextservice == NULL) break;
2834 properties = MLT_SERVICE_PROPERTIES(nextservice);
2835 mlt_type = mlt_properties_get(properties, "mlt_type");
2836 resource = mlt_properties_get(properties, "mlt_service");
2839 // Add audio mix transition to last track
2840 Mlt::Field *field = tractor.field();
2841 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2842 //transition->set("mlt_service", "mix");
2843 transition->set("a_track", 1);
2844 transition->set("b_track", ct);
2845 transition->set("always_active", 1);
2846 transition->set("internal_added", 237);
2847 transition->set("combine", 1);
2848 field->plant_transition(*transition, 1, ct);
2851 mlt_service_unlock(m_mltConsumer->get_service());
2852 m_isBlocked = false;
2853 blockSignals(false);
2856 #include "renderer.moc"