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) {
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 return trackPlaylist.clip_length(clipIndex);
1453 void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration) {
1454 if (!m_mltProducer) {
1455 kDebug() << "PLAYLIST NOT INITIALISED //////";
1458 Mlt::Producer parentProd(m_mltProducer->parent());
1459 if (parentProd.get_producer() == NULL) {
1460 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1464 Mlt::Service service(parentProd.get_service());
1465 Mlt::Tractor tractor(service);
1466 mlt_service_lock(service.get_service());
1467 int insertPos = pos.frames(m_fps);
1468 int diff = duration.frames(m_fps);
1471 // insert space in one track only
1472 Mlt::Producer trackProducer(tractor.track(track));
1473 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1474 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1475 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1477 int position = trackPlaylist.clip_start(clipIndex);
1478 trackPlaylist.remove_region(position + diff, -diff - 1);
1480 trackPlaylist.consolidate_blanks(0);
1482 // now move transitions
1483 mlt_service serv = m_mltProducer->parent().get_service();
1484 mlt_service nextservice = mlt_service_get_producer(serv);
1485 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1486 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1487 QString resource = mlt_properties_get(properties, "mlt_service");
1489 while (mlt_type == "transition") {
1490 mlt_transition tr = (mlt_transition) nextservice;
1491 int currentTrack = mlt_transition_get_b_track(tr);
1492 int currentIn = (int) mlt_transition_get_in(tr);
1493 int currentOut = (int) mlt_transition_get_out(tr);
1495 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1496 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1498 nextservice = mlt_service_producer(nextservice);
1499 if (nextservice == NULL) break;
1500 properties = MLT_SERVICE_PROPERTIES(nextservice);
1501 mlt_type = mlt_properties_get(properties, "mlt_type");
1502 resource = mlt_properties_get(properties, "mlt_service");
1505 int trackNb = tractor.count();
1506 while (trackNb > 1) {
1507 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1508 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1509 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1510 if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1);
1512 int position = trackPlaylist.clip_start(clipIndex);
1513 trackPlaylist.remove_region(position + diff, -diff - 1);
1515 trackPlaylist.consolidate_blanks(0);
1518 // now move transitions
1519 mlt_service serv = m_mltProducer->parent().get_service();
1520 mlt_service nextservice = mlt_service_get_producer(serv);
1521 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1522 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1523 QString resource = mlt_properties_get(properties, "mlt_service");
1525 while (mlt_type == "transition") {
1526 mlt_transition tr = (mlt_transition) nextservice;
1527 int currentIn = (int) mlt_transition_get_in(tr);
1528 int currentOut = (int) mlt_transition_get_out(tr);
1530 if (currentOut > insertPos && resource != "mix") {
1531 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1533 nextservice = mlt_service_producer(nextservice);
1534 if (nextservice == NULL) break;
1535 properties = MLT_SERVICE_PROPERTIES(nextservice);
1536 mlt_type = mlt_properties_get(properties, "mlt_type");
1537 resource = mlt_properties_get(properties, "mlt_service");
1540 mlt_service_unlock(service.get_service());
1544 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) {
1547 Mlt::Service service(m_mltProducer->parent().get_service());
1548 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
1549 kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1550 Mlt::Tractor tractor(service);
1551 Mlt::Producer trackProducer(tractor.track(info.track));
1552 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1553 int startPos = info.startPos.frames(m_fps);
1554 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1555 int clipLength = trackPlaylist.clip_length(clipIndex);
1557 Mlt::Producer clip(trackPlaylist.get_clip(clipIndex));
1558 QString serv = clip.parent().get("mlt_service");
1559 QString id = clip.parent().get("id");
1560 kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service");
1561 if (serv == "avformat" && speed != 1.0) {
1562 mlt_service_lock(service.get_service());
1563 QString url = clip.parent().get("resource");
1564 url.append("?" + QString::number(speed));
1565 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1566 if (!slowprod || slowprod->get_producer() == NULL) {
1567 char *tmp = decodedString(url);
1568 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1570 QString producerid = "slowmotion:" + id + ":" + QString::number(speed);
1571 tmp = decodedString(producerid);
1572 slowprod->set("id", tmp);
1574 m_slowmotionProducers.insert(url, slowprod);
1576 trackPlaylist.replace_with_blank(clipIndex);
1577 trackPlaylist.consolidate_blanks(0);
1578 // Check that the blank space is long enough for our new duration
1579 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1580 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1582 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1583 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1584 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1585 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1586 trackPlaylist.insert_at(startPos, *cut, 1);
1587 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1588 newLength = trackPlaylist.clip_length(clipIndex);
1589 mlt_service_unlock(service.get_service());
1590 } else if (speed == 1.0) {
1591 mlt_service_lock(service.get_service());
1593 trackPlaylist.replace_with_blank(clipIndex);
1594 trackPlaylist.consolidate_blanks(0);
1596 // Check that the blank space is long enough for our new duration
1597 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1598 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1601 GenTime oldDuration = GenTime(clipLength, m_fps);
1602 GenTime newDuration = oldDuration * oldspeed;
1603 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1604 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1605 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1606 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
1607 trackPlaylist.insert_at(startPos, *cut, 1);
1608 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1609 newLength = trackPlaylist.clip_length(clipIndex);
1610 mlt_service_unlock(service.get_service());
1612 } else if (serv == "framebuffer") {
1613 mlt_service_lock(service.get_service());
1614 QString url = clip.parent().get("resource");
1615 url = url.section("?", 0, 0);
1616 url.append("?" + QString::number(speed));
1617 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1618 if (!slowprod || slowprod->get_producer() == NULL) {
1619 char *tmp = decodedString(url);
1620 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1622 QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed);
1623 tmp = decodedString(producerid);
1624 slowprod->set("id", tmp);
1626 m_slowmotionProducers.insert(url, slowprod);
1628 trackPlaylist.replace_with_blank(clipIndex);
1629 trackPlaylist.consolidate_blanks(0);
1631 GenTime oldDuration = GenTime(clipLength, m_fps);
1632 GenTime newDuration = oldDuration * oldspeed / speed;
1634 // Check that the blank space is long enough for our new duration
1635 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1636 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1639 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
1640 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1641 cut = slowprod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
1642 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + 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);
1648 mlt_service_unlock(service.get_service());
1650 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength();
1651 m_isBlocked = false;
1655 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) {
1657 Mlt::Service service(m_mltProducer->parent().get_service());
1658 bool success = false;
1659 Mlt::Tractor tractor(service);
1660 Mlt::Producer trackProducer(tractor.track(track));
1661 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1662 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1663 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1665 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
1668 Mlt::Service clipService(clip->get_service());
1669 // if (tag.startsWith("ladspa")) tag = "ladspa";
1672 Mlt::Filter *filter = clipService.filter(ct);
1674 if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
1675 if (clipService.detach(*filter) == 0) success = true;
1676 kDebug() << " / / / DLEETED EFFECT: " << ct;
1678 filter = clipService.filter(ct);
1680 m_isBlocked = false;
1681 if (doRefresh) refresh();
1686 bool Render::mltAddEffect(int track, GenTime position, QHash <QString, QString> args, bool doRefresh) {
1688 Mlt::Service service(m_mltProducer->parent().get_service());
1690 Mlt::Tractor tractor(service);
1691 Mlt::Producer trackProducer(tractor.track(track));
1692 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1694 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1698 Mlt::Service clipService(clip->get_service());
1701 // temporarily remove all effects after insert point
1702 QList <Mlt::Filter *> filtersList;
1703 const int filter_ix = QString(args.value("kdenlive_ix")).toInt();
1705 Mlt::Filter *filter = clipService.filter(ct);
1707 if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) {
1708 filtersList.append(filter);
1709 clipService.detach(*filter);
1711 filter = clipService.filter(ct);
1715 QString tag = args.value("tag");
1716 kDebug() << " / / INSERTING EFFECT: " << tag;
1717 if (tag.startsWith("ladspa")) tag = "ladspa";
1718 char *filterTag = decodedString(tag);
1719 char *filterId = decodedString(args.value("id"));
1720 QHash<QString, QString>::Iterator it;
1721 QString kfr = args.value("keyframes");
1723 if (!kfr.isEmpty()) {
1724 QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts);
1725 kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes");
1726 char *starttag = decodedString(args.value("starttag", "start"));
1727 char *endtag = decodedString(args.value("endtag", "end"));
1728 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
1729 int duration = clip->get_playtime();
1730 double max = args.value("max").toDouble();
1731 double min = args.value("min").toDouble();
1732 double factor = args.value("factor", "1").toDouble();
1733 args.remove("starttag");
1734 args.remove("endtag");
1735 args.remove("keyframes");
1738 args.remove("factor");
1740 for (int i = 0; i < keyFrames.size() - 1; ++i) {
1741 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1742 if (filter && filter->is_valid()) {
1743 filter->set("kdenlive_id", filterId);
1744 int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset;
1745 double y1 = keyFrames.at(i).section(":", 1, 1).toDouble();
1746 int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt();
1747 double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble();
1748 if (x2 == -1) x2 = duration;
1749 for (it = args.begin(); it != args.end(); ++it) {
1750 char *name = decodedString(it.key());
1751 char *value = decodedString(it.value());
1752 filter->set(name, value);
1757 filter->set("in", x1);
1758 filter->set("out", x2);
1759 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
1760 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
1761 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
1762 clipService.attach(*filter);
1769 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
1770 if (filter && filter->is_valid())
1771 filter->set("kdenlive_id", filterId);
1773 kDebug() << "filter is NULL";
1774 m_isBlocked = false;
1778 for (it = args.begin(); it != args.end(); ++it) {
1779 char *name = decodedString(it.key());
1780 char *value = decodedString(it.value());
1781 filter->set(name, value);
1785 // attach filter to the clip
1786 clipService.attach(*filter);
1791 // re-add following filters
1792 for (int i = 0; i < filtersList.count(); i++) {
1793 clipService.attach(*(filtersList.at(i)));
1796 m_isBlocked = false;
1797 if (doRefresh) refresh();
1801 bool Render::mltEditEffect(int track, GenTime position, QHash <QString, QString> args) {
1802 QString index = args.value("kdenlive_ix");
1803 QString tag = args.value("tag");
1804 QHash<QString, QString>::Iterator it = args.begin();
1805 if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
1806 // This is a keyframe effect, to edit it, we remove it and re-add it.
1807 mltRemoveEffect(track, position, index);
1808 bool success = mltAddEffect(track, position, args);
1813 Mlt::Service service(m_mltProducer->parent().get_service());
1815 Mlt::Tractor tractor(service);
1816 Mlt::Producer trackProducer(tractor.track(track));
1817 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1818 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
1819 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
1821 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1824 Mlt::Service clipService(clip->get_service());
1827 Mlt::Filter *filter = clipService.filter(ct);
1829 if (filter->get("kdenlive_ix") == index) {
1833 filter = clipService.filter(ct);
1837 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
1838 // filter was not found, it was probably a disabled filter, so add it to the correct place...
1840 filter = clipService.filter(ct);
1841 QList <Mlt::Filter *> filtersList;
1843 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
1844 filtersList.append(filter);
1845 clipService.detach(*filter);
1847 filter = clipService.filter(ct);
1849 bool success = mltAddEffect(track, position, args);
1851 for (int i = 0; i < filtersList.count(); i++) {
1852 clipService.attach(*(filtersList.at(i)));
1855 m_isBlocked = false;
1859 for (it = args.begin(); it != args.end(); ++it) {
1860 kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value();
1861 char *name = decodedString(it.key());
1862 char *value = decodedString(it.value());
1863 filter->set(name, value);
1867 m_isBlocked = false;
1872 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) {
1874 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
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 QList <Mlt::Filter *> filtersList;
1890 Mlt::Filter *filter = clipService.filter(ct);
1892 if (newPos > oldPos) {
1894 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1895 filter->set("kdenlive_ix", newPos);
1896 filtersList.append(filter);
1897 clipService.detach(*filter);
1898 filter = clipService.filter(ct);
1899 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
1900 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
1902 filter = clipService.filter(ct);
1906 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
1907 filtersList.append(filter);
1908 clipService.detach(*filter);
1910 filter = clipService.filter(ct);
1914 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
1915 filter->set("kdenlive_ix", newPos);
1916 filtersList.append(filter);
1917 clipService.detach(*filter);
1919 filter = clipService.filter(ct);
1923 filter = clipService.filter(ct);
1925 int pos = QString(filter->get("kdenlive_ix")).toInt();
1926 if (pos >= newPos) {
1927 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
1928 filtersList.append(filter);
1929 clipService.detach(*filter);
1931 filter = clipService.filter(ct);
1935 for (int i = 0; i < filtersList.count(); i++) {
1936 clipService.attach(*(filtersList.at(i)));
1939 m_isBlocked = false;
1943 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) {
1946 Mlt::Service service(m_mltProducer->parent().get_service());
1948 Mlt::Tractor tractor(service);
1949 Mlt::Producer trackProducer(tractor.track(info.track));
1950 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1952 /* // Display playlist info
1953 kDebug()<<"//////////// BEFORE RESIZE";
1954 for (int i = 0; i < trackPlaylist.count(); i++) {
1955 int blankStart = trackPlaylist.clip_start(i);
1956 int blankDuration = trackPlaylist.clip_length(i) - 1;
1958 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1959 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<"x"<<blankStart + blankDuration<<")"<<blk;
1962 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
1963 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
1964 m_isBlocked = false;
1967 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
1968 kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
1969 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1970 int previousStart = clip->get_in();
1971 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
1972 int newDuration = (int) clipDuration.frames(m_fps) - 1;
1973 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
1974 //trackPlaylist.consolidate_blanks(0);
1975 // skip to next clip
1977 int diff = newDuration - previousDuration;
1978 kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration;
1980 // clip was made longer, trim next blank if there is one.
1981 if (trackPlaylist.is_blank(clipIndex)) {
1982 int blankStart = trackPlaylist.clip_start(clipIndex);
1983 int blankDuration = trackPlaylist.clip_length(clipIndex) - 1;
1984 if (diff - blankDuration == 1) {
1985 trackPlaylist.remove(clipIndex);
1986 } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff);
1988 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
1990 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
1992 trackPlaylist.consolidate_blanks(0);
1995 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength();
1996 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
1997 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
1998 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
1999 ItemInfo transpinfo;
2000 transpinfo.startPos = info.startPos;
2001 transpinfo.endPos = info.startPos + clipDuration;
2002 transpinfo.track = info.track;
2003 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2005 m_isBlocked = false;
2009 void Render::mltChangeTrackState(int track, bool mute, bool blind) {
2010 Mlt::Service service(m_mltProducer->parent().get_service());
2011 Mlt::Tractor tractor(service);
2012 Mlt::Producer trackProducer(tractor.track(track));
2015 if (blind) trackProducer.set("hide", 3);
2016 else trackProducer.set("hide", 2);
2018 trackProducer.set("hide", 1);
2020 trackProducer.set("hide", 0);
2022 tractor.multitrack()->refresh();
2027 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) {
2028 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2029 Mlt::Service service(m_mltProducer->parent().get_service());
2030 int moveFrame = (int) diff.frames(m_fps);
2031 Mlt::Tractor tractor(service);
2032 Mlt::Producer trackProducer(tractor.track(info.track));
2033 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2034 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2035 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2038 mlt_service_lock(service.get_service());
2039 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2040 /*int previousStart = trackPlaylist.clip_start(clipIndex);
2041 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/
2042 //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25);
2043 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2045 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2046 mlt_service_unlock(service.get_service());
2049 //m_mltConsumer->set("refresh", 0);
2050 int previousStart = clip->get_in();
2051 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2053 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2054 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2055 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2057 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2058 int blankIndex = clipIndex - 1;
2059 int blankLength = trackPlaylist.clip_length(blankIndex);
2060 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2061 if (! trackPlaylist.is_blank(blankIndex)) {
2062 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2064 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2065 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2067 trackPlaylist.consolidate_blanks(0);
2068 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2069 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2070 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2071 ItemInfo transpinfo;
2072 transpinfo.startPos = info.startPos + diff;
2073 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2074 transpinfo.track = info.track;
2075 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2077 m_isBlocked = false;
2078 //m_mltConsumer->set("refresh", 1);
2079 mlt_service_unlock(service.get_service());
2083 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) {
2084 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2088 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) {
2089 kDebug() << "NEW PROD ID: " << prod->get("id");
2090 m_mltConsumer->set("refresh", 0);
2091 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2092 mlt_service_lock(m_mltConsumer->get_service());
2093 Mlt::Service service(m_mltProducer->parent().get_service());
2094 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2096 Mlt::Tractor tractor(service);
2097 Mlt::Producer trackProducer(tractor.track(track));
2098 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2099 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2100 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2101 if (clipProducer.is_blank()) {
2102 kDebug() << "// ERROR UPDATING CLIP PROD";
2103 mlt_service_unlock(m_mltConsumer->get_service());
2104 m_isBlocked = false;
2107 Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2109 // move all effects to the correct producer
2110 Mlt::Service clipService(clipProducer.get_service());
2111 Mlt::Service newClipService(clip->get_service());
2114 Mlt::Filter *filter = clipService.filter(ct);
2116 if (filter->get("kdenlive_ix") != 0) {
2117 clipService.detach(*filter);
2118 newClipService.attach(*filter);
2120 filter = clipService.filter(ct);
2123 trackPlaylist.insert_at(pos, clip, 1);
2124 mlt_service_unlock(m_mltConsumer->get_service());
2125 m_isBlocked = false;
2128 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) {
2131 m_mltConsumer->set("refresh", 0);
2132 mlt_service_lock(m_mltConsumer->get_service());
2133 Mlt::Service service(m_mltProducer->parent().get_service());
2134 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2136 Mlt::Tractor tractor(service);
2137 Mlt::Producer trackProducer(tractor.track(startTrack));
2138 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2139 int clipIndex = trackPlaylist.get_clip_index_at(moveStart + 1);
2140 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2141 bool checkLength = false;
2142 if (endTrack == startTrack) {
2143 //mlt_service_lock(service.get_service());
2144 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2145 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) {
2146 // error, destination is not empty
2147 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2148 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2149 mlt_service_unlock(m_mltConsumer->get_service());
2150 m_isBlocked = false;
2153 trackPlaylist.consolidate_blanks(0);
2154 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2155 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2156 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2158 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2160 //mlt_service_unlock(service.get_service());
2162 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2163 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2164 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2165 // error, destination is not empty
2166 mlt_service_unlock(m_mltConsumer->get_service());
2167 m_isBlocked = false;
2170 Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex));
2171 if (clipProducer.is_blank()) {
2172 // error, destination is not empty
2173 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2174 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2175 mlt_service_unlock(m_mltConsumer->get_service());
2176 m_isBlocked = false;
2179 trackPlaylist.consolidate_blanks(0);
2180 destTrackPlaylist.consolidate_blanks(1);
2181 Mlt::Producer *clip;
2182 // check if we are moving a slowmotion producer
2183 QString serv = clipProducer.parent().get("mlt_service");
2184 if (serv == "framebuffer") {
2185 clip = &clipProducer;
2186 } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out());
2188 // move all effects to the correct producer
2189 Mlt::Service clipService(clipProducer.get_service());
2190 Mlt::Service newClipService(clip->get_service());
2193 Mlt::Filter *filter = clipService.filter(ct);
2195 if (filter->get("kdenlive_ix") != 0) {
2196 clipService.detach(*filter);
2197 newClipService.attach(*filter);
2199 filter = clipService.filter(ct);
2202 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2203 destTrackPlaylist.consolidate_blanks(0);
2204 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2205 kDebug() << "//////// moving clip transparency";
2206 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2208 if (clipIndex > trackPlaylist.count()) checkLength = true;
2209 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2213 if (checkLength) mltCheckLength();
2214 mlt_service_unlock(m_mltConsumer->get_service());
2215 m_isBlocked = false;
2216 m_mltConsumer->set("refresh", 1);
2220 void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) {
2221 Mlt::Service service(m_mltProducer->parent().get_service());
2222 Mlt::Tractor tractor(service);
2223 Mlt::Field *field = tractor.field();
2225 mlt_service_lock(service.get_service());
2226 m_mltConsumer->set("refresh", 0);
2229 mlt_service serv = m_mltProducer->parent().get_service();
2230 mlt_service nextservice = mlt_service_get_producer(serv);
2231 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2232 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2233 QString resource = mlt_properties_get(properties, "mlt_service");
2234 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2236 int new_in = (int)newIn.frames(m_fps);
2237 int new_out = (int)newOut.frames(m_fps) - 1;
2239 while (mlt_type == "transition") {
2240 mlt_transition tr = (mlt_transition) nextservice;
2241 int currentTrack = mlt_transition_get_b_track(tr);
2242 int currentIn = (int) mlt_transition_get_in(tr);
2243 int currentOut = (int) mlt_transition_get_out(tr);
2245 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2246 mlt_transition_set_in_and_out(tr, new_in, new_out);
2247 if (newTrack - startTrack != 0) {
2248 kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack;
2250 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2251 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2252 mlt_properties_set_int(properties, "b_track", newTrack);
2253 //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);
2257 nextservice = mlt_service_producer(nextservice);
2258 if (nextservice == NULL) break;
2259 properties = MLT_SERVICE_PROPERTIES(nextservice);
2260 mlt_type = mlt_properties_get(properties, "mlt_type");
2261 resource = mlt_properties_get(properties, "mlt_service");
2263 m_isBlocked = false;
2264 mlt_service_unlock(service.get_service());
2265 m_mltConsumer->set("refresh", 1);
2268 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2269 // kDebug() << "update transition" << tag << " at pos " << in.frames(25);
2270 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2272 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2273 mltAddTransition(tag, a_track, b_track, in, out, xml);
2275 //mltSavePlaylist();
2278 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) {
2280 Mlt::Service service(m_mltProducer->parent().get_service());
2281 Mlt::Tractor tractor(service);
2282 Mlt::Field *field = tractor.field();
2284 //m_mltConsumer->set("refresh", 0);
2285 mlt_service serv = m_mltProducer->parent().get_service();
2287 mlt_service nextservice = mlt_service_get_producer(serv);
2288 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2289 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2290 QString resource = mlt_properties_get(properties, "mlt_service");
2291 int in_pos = (int) in.frames(m_fps);
2292 int out_pos = (int) out.frames(m_fps) - 1;
2294 while (mlt_type == "transition") {
2295 mlt_transition tr = (mlt_transition) nextservice;
2296 int currentTrack = mlt_transition_get_b_track(tr);
2297 int currentBTrack = mlt_transition_get_a_track(tr);
2298 int currentIn = (int) mlt_transition_get_in(tr);
2299 int currentOut = (int) mlt_transition_get_out(tr);
2301 // kDebug()<<"Looking for transition : " << currentIn <<"x"<<currentOut<< ", OLD oNE: "<<in_pos<<"x"<<out_pos;
2303 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2304 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2305 QMap<QString, QString>::Iterator it;
2307 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2308 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2309 if (currentBTrack != a_track) {
2310 mlt_properties_set_int(properties, "a_track", a_track);
2312 for (it = map.begin(); it != map.end(); ++it) {
2314 char *name = decodedString(key);
2315 char *value = decodedString(it.value());
2316 mlt_properties_set(transproperties, name, value);
2317 kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2318 //filter->set("kdenlive_id", id);
2324 nextservice = mlt_service_producer(nextservice);
2325 if (nextservice == NULL) break;
2326 properties = MLT_SERVICE_PROPERTIES(nextservice);
2327 mlt_type = mlt_properties_get(properties, "mlt_type");
2328 resource = mlt_properties_get(properties, "mlt_service");
2330 m_isBlocked = false;
2331 m_mltConsumer->set("refresh", 1);
2334 void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2335 Mlt::Service service(m_mltProducer->parent().get_service());
2336 Mlt::Tractor tractor(service);
2337 Mlt::Field *field = tractor.field();
2339 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2340 mlt_service serv = m_mltProducer->parent().get_service();
2342 mlt_service nextservice = mlt_service_get_producer(serv);
2343 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2344 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2345 QString resource = mlt_properties_get(properties, "mlt_service");
2347 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2349 while (mlt_type == "transition") {
2350 mlt_transition tr = (mlt_transition) nextservice;
2351 int currentTrack = mlt_transition_get_b_track(tr);
2352 int currentIn = (int) mlt_transition_get_in(tr);
2353 int currentOut = (int) mlt_transition_get_out(tr);
2354 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2356 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2357 mlt_field_disconnect_service(field->get_field(), nextservice);
2360 nextservice = mlt_service_producer(nextservice);
2361 if (nextservice == NULL) break;
2362 properties = MLT_SERVICE_PROPERTIES(nextservice);
2363 mlt_type = mlt_properties_get(properties, "mlt_type");
2364 resource = mlt_properties_get(properties, "mlt_service");
2366 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2369 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml) {
2370 QDomNodeList attribs = xml.elementsByTagName("parameter");
2371 QMap<QString, QString> map;
2372 for (int i = 0;i < attribs.count();i++) {
2373 QDomElement e = attribs.item(i).toElement();
2374 QString name = e.attribute("name");
2375 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2376 map[name] = e.attribute("default");
2377 if (!e.attribute("value").isEmpty()) {
2378 map[name] = e.attribute("value");
2380 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2381 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2382 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2385 if (e.attribute("namedesc").contains(";")) {
2386 QString format = e.attribute("format");
2387 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2388 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2390 QTextStream txtNeu(&neu);
2391 if (values.size() > 0)
2392 txtNeu << (int)values[0].toDouble();
2394 for (i = 0;i < separators.size() && i + 1 < values.size();i++) {
2395 txtNeu << separators[i];
2396 txtNeu << (int)(values[i+1].toDouble());
2398 if (i < separators.size())
2399 txtNeu << separators[i];
2400 map[e.attribute("name")] = neu;
2407 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) {
2408 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2409 Mlt::Service service(m_mltProducer->parent().get_service());
2410 Mlt::Tractor tractor(service);
2411 Mlt::Field *field = tractor.field();
2413 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2414 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2415 transition->set("transparency", id);
2416 transition->set("fill", 1);
2417 transition->set("internal_added", 237);
2418 field->plant_transition(*transition, transitiontrack, info.track);
2422 void Render::mltDeleteTransparency(int pos, int track, int id) {
2423 Mlt::Service service(m_mltProducer->parent().get_service());
2424 Mlt::Tractor tractor(service);
2425 Mlt::Field *field = tractor.field();
2427 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2428 mlt_service serv = m_mltProducer->parent().get_service();
2430 mlt_service nextservice = mlt_service_get_producer(serv);
2431 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2432 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2433 QString resource = mlt_properties_get(properties, "mlt_service");
2435 while (mlt_type == "transition") {
2436 mlt_transition tr = (mlt_transition) nextservice;
2437 int currentTrack = mlt_transition_get_b_track(tr);
2438 int currentIn = (int) mlt_transition_get_in(tr);
2439 int currentOut = (int) mlt_transition_get_out(tr);
2440 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2441 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2443 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2444 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2445 mlt_field_disconnect_service(field->get_field(), nextservice);
2448 nextservice = mlt_service_producer(nextservice);
2449 if (nextservice == NULL) break;
2450 properties = MLT_SERVICE_PROPERTIES(nextservice);
2451 mlt_type = mlt_properties_get(properties, "mlt_type");
2452 resource = mlt_properties_get(properties, "mlt_service");
2454 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2457 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) {
2458 Mlt::Service service(m_mltProducer->parent().get_service());
2459 Mlt::Tractor tractor(service);
2460 Mlt::Field *field = tractor.field();
2462 mlt_service_lock(service.get_service());
2463 m_mltConsumer->set("refresh", 0);
2466 mlt_service serv = m_mltProducer->parent().get_service();
2467 mlt_service nextservice = mlt_service_get_producer(serv);
2468 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2469 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2470 QString resource = mlt_properties_get(properties, "mlt_service");
2471 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id;
2472 while (mlt_type == "transition") {
2473 mlt_transition tr = (mlt_transition) nextservice;
2474 int currentTrack = mlt_transition_get_b_track(tr);
2475 int currentIn = (int) mlt_transition_get_in(tr);
2476 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
2477 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2478 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ;
2479 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
2480 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd;
2481 mlt_transition_set_in_and_out(tr, newStart, newEnd);
2484 nextservice = mlt_service_producer(nextservice);
2485 if (nextservice == NULL) break;
2486 properties = MLT_SERVICE_PROPERTIES(nextservice);
2487 mlt_type = mlt_properties_get(properties, "mlt_type");
2488 resource = mlt_properties_get(properties, "mlt_service");
2490 m_isBlocked = false;
2491 mlt_service_unlock(service.get_service());
2492 m_mltConsumer->set("refresh", 1);
2496 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) {
2497 Mlt::Service service(m_mltProducer->parent().get_service());
2498 Mlt::Tractor tractor(service);
2499 Mlt::Field *field = tractor.field();
2501 mlt_service_lock(service.get_service());
2502 m_mltConsumer->set("refresh", 0);
2505 mlt_service serv = m_mltProducer->parent().get_service();
2506 mlt_service nextservice = mlt_service_get_producer(serv);
2507 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2508 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2509 QString resource = mlt_properties_get(properties, "mlt_service");
2511 while (mlt_type == "transition") {
2512 mlt_transition tr = (mlt_transition) nextservice;
2513 int currentTrack = mlt_transition_get_b_track(tr);
2514 int currentaTrack = mlt_transition_get_a_track(tr);
2515 int currentIn = (int) mlt_transition_get_in(tr);
2516 int currentOut = (int) mlt_transition_get_out(tr);
2517 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2518 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2519 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<"x"<<startTrack;
2520 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
2521 kDebug() << "//////MOVING";
2522 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
2523 if (endTrack != startTrack) {
2524 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2525 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
2526 mlt_properties_set_int(properties, "b_track", endTrack);
2530 nextservice = mlt_service_producer(nextservice);
2531 if (nextservice == NULL) break;
2532 properties = MLT_SERVICE_PROPERTIES(nextservice);
2533 mlt_type = mlt_properties_get(properties, "mlt_type");
2534 resource = mlt_properties_get(properties, "mlt_service");
2536 m_isBlocked = false;
2537 mlt_service_unlock(service.get_service());
2538 m_mltConsumer->set("refresh", 1);
2542 void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) {
2544 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
2545 Mlt::Service service(m_mltProducer->parent().get_service());
2547 Mlt::Tractor tractor(service);
2548 Mlt::Field *field = tractor.field();
2550 char *transId = decodedString(tag);
2551 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
2552 if (out != GenTime())
2553 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
2554 QMap<QString, QString>::Iterator it;
2556 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
2557 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
2559 for (it = args.begin(); it != args.end(); ++it) {
2561 char *name = decodedString(key);
2562 char *value = decodedString(it.value());
2563 transition->set(name, value);
2564 kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
2565 //filter->set("kdenlive_id", id);
2569 // attach filter to the clip
2570 field->plant_transition(*transition, a_track, b_track);
2575 void Render::mltSavePlaylist() {
2576 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
2577 Mlt::Consumer fileConsumer(*m_mltProfile, "westley");
2578 fileConsumer.set("resource", "/tmp/playlist.westley");
2580 Mlt::Service service(m_mltProducer->get_service());
2582 fileConsumer.connect(service);
2583 fileConsumer.start();
2586 QList <Mlt::Producer *> Render::producersList() {
2587 QList <Mlt::Producer *> prods = QList <Mlt::Producer *> ();
2589 Mlt::Service service(m_mltProducer->parent().get_service());
2590 Mlt::Tractor tractor(service);
2592 int trackNb = tractor.count();
2593 for (int t = 1; t < trackNb; t++) {
2594 Mlt::Producer trackProducer(tractor.track(t));
2595 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2596 int clipNb = trackPlaylist.count();
2597 kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
2598 for (int i = 0; i < clipNb; i++) {
2599 Mlt::Producer *prod = trackPlaylist.get_clip(i);
2600 Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent());
2601 //kDebug()<<"PROD: "<<nprod->get("producer")<<", ID: "<<nprod->get("id")<<nprod->get("resource");
2602 if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) {
2603 ids.append(nprod->get("id"));
2604 prods.append(nprod);
2611 void Render::mltInsertTrack(int ix, bool videoTrack) {
2615 m_mltConsumer->set("refresh", 0);
2616 mlt_service_lock(m_mltConsumer->get_service());
2617 Mlt::Service service(m_mltProducer->parent().get_service());
2618 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2620 Mlt::Tractor tractor(service);
2622 Mlt::Playlist playlist;// = new Mlt::Playlist();
2623 int ct = tractor.count();
2624 // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct;
2627 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
2628 tractor.set_track(playlist, pos);
2629 Mlt::Producer newProd(tractor.track(pos));
2630 if (!videoTrack) newProd.set("hide", 1);
2632 for (; pos <= ct; pos++) {
2633 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
2634 tractor.set_track(*prodToMove, pos);
2635 prodToMove = prodToMove2;
2638 tractor.set_track(playlist, ix);
2639 Mlt::Producer newProd(tractor.track(ix));
2640 if (!videoTrack) newProd.set("hide", 1);
2644 mlt_service serv = m_mltProducer->parent().get_service();
2645 mlt_service nextservice = mlt_service_get_producer(serv);
2646 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2647 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2648 QString resource = mlt_properties_get(properties, "mlt_service");
2650 while (mlt_type == "transition") {
2651 if (resource != "mix") {
2652 mlt_transition tr = (mlt_transition) nextservice;
2653 int currentTrack = mlt_transition_get_b_track(tr);
2654 int currentaTrack = mlt_transition_get_a_track(tr);
2655 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2657 if (currentTrack >= ix) {
2658 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2659 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2662 nextservice = mlt_service_producer(nextservice);
2663 if (nextservice == NULL) break;
2664 properties = MLT_SERVICE_PROPERTIES(nextservice);
2665 mlt_type = mlt_properties_get(properties, "mlt_type");
2666 resource = mlt_properties_get(properties, "mlt_service");
2669 // Add audio mix transition to last track
2670 Mlt::Field *field = tractor.field();
2671 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2672 //transition->set("mlt_service", "mix");
2673 transition->set("a_track", 1);
2674 transition->set("b_track", ct);
2675 transition->set("always_active", 1);
2676 transition->set("internal_added", 237);
2677 transition->set("combine", 1);
2678 field->plant_transition(*transition, 1, ct);
2680 mlt_service_unlock(m_mltConsumer->get_service());
2681 m_isBlocked = false;
2682 blockSignals(false);
2686 void Render::mltDeleteTrack(int ix) {
2688 doc.setContent(sceneList(), false);
2689 int tracksCount = doc.elementsByTagName("track").count() - 1;
2690 QDomNode track = doc.elementsByTagName("track").at(ix);
2691 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
2692 QDomNodeList transitions = doc.elementsByTagName("transition");
2693 for (int i = 0; i < transitions.count(); i++) {
2694 QDomElement e = transitions.at(i).toElement();
2695 QDomNodeList props = e.elementsByTagName("property");
2696 QMap <QString, QString> mappedProps;
2697 for (int j = 0; j < props.count(); j++) {
2698 QDomElement f = props.at(j).toElement();
2699 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
2701 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
2702 tractor.removeChild(transitions.at(i));
2703 } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) {
2704 // Transition needs to be moved
2705 int a_track = mappedProps.value("a_track").toInt();
2706 int b_track = mappedProps.value("b_track").toInt();
2707 if (a_track > 0) a_track --;
2708 if (b_track > 0) b_track --;
2709 for (int j = 0; j < props.count(); j++) {
2710 QDomElement f = props.at(j).toElement();
2711 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
2712 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
2717 tractor.removeChild(track);
2718 setSceneList(doc.toString(), m_framePosition);
2724 m_mltConsumer->set("refresh", 0);
2725 mlt_service_lock(m_mltConsumer->get_service());
2726 Mlt::Service service(m_mltProducer->parent().get_service());
2727 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";
2729 /*Mlt::Tractor tractor(service);
2732 Mlt::Multitrack *multi = tractor.multitrack();
2735 int ct = tractor.count();
2736 kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct;
2738 for (; pos < ct ; pos++) {
2739 Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service());
2740 //mlt_service_close(lastTrack->get_service());
2742 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1));
2743 Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos));
2744 mlt_service_close(prodToMove->get_service());
2745 mlt_service_close(prodToClose->get_service());
2746 tractor.set_track(*prodToMove, pos);
2750 /*mlt_service serv = m_mltProducer->parent().get_service();
2751 mlt_service nextservice = mlt_service_get_producer(serv);
2752 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2753 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2754 QString resource = mlt_properties_get(properties, "mlt_service");
2756 while (mlt_type == "transition") {
2757 if (resource != "mix") {
2758 mlt_transition tr = (mlt_transition) nextservice;
2759 int currentTrack = mlt_transition_get_b_track(tr);
2760 int currentaTrack = mlt_transition_get_a_track(tr);
2761 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2763 if (currentTrack >= ix) {
2764 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
2765 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
2768 nextservice = mlt_service_producer(nextservice);
2769 if (nextservice == NULL) break;
2770 properties = MLT_SERVICE_PROPERTIES(nextservice);
2771 mlt_type = mlt_properties_get(properties, "mlt_type");
2772 resource = mlt_properties_get(properties, "mlt_service");
2775 // Add audio mix transition to last track
2776 Mlt::Field *field = tractor.field();
2777 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
2778 //transition->set("mlt_service", "mix");
2779 transition->set("a_track", 1);
2780 transition->set("b_track", ct);
2781 transition->set("always_active", 1);
2782 transition->set("internal_added", 237);
2783 transition->set("combine", 1);
2784 field->plant_transition(*transition, 1, ct);
2787 mlt_service_unlock(m_mltConsumer->get_service());
2788 m_isBlocked = false;
2789 blockSignals(false);
2792 #include "renderer.moc"