1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
30 #include "slideshowclip.h"
32 #include <mlt++/Mlt.h>
35 #include <KStandardDirs>
36 #include <KMessageBox>
38 #include <KTemporaryFile>
43 #include <QApplication>
50 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
52 if (level > MLT_LOG_ERROR) return;
54 QApplication::postEvent(qApp->activeWindow() , new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
59 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
61 // detect if the producer has finished playing. Is there a better way to do it?
62 if (self->m_isBlocked) return;
63 Mlt::Frame frame(frame_ptr);
65 self->showFrame(frame);
68 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
69 if (frame_ptr->convert_image)
70 self->emitFrameUpdated(frame);
71 if (frame.get_double("_speed") == 0.0) {
72 self->emitConsumerStopped();
73 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
75 self->emitConsumerStopped();
80 Render::Render(const QString & rendererName, int winid, int /* extid */, QString profile, QWidget *parent) :
97 /*if (rendererName == "project") m_monitorId = 10000;
98 else m_monitorId = 10001;*/
99 /*m_osdTimer = new QTimer(this);
100 connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));*/
101 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
102 buildConsumer(profile);
104 m_mltProducer = m_blackClip->cut(0, 50);
105 m_mltConsumer->connect(*m_mltProducer);
106 m_mltProducer->set_speed(0.0);
116 void Render::closeMlt()
120 Mlt::Service service(m_mltProducer->parent().get_service());
121 mlt_service_lock(service.get_service());
123 if (service.type() == tractor_type) {
124 Mlt::Tractor tractor(service);
125 Mlt::Field *field = tractor.field();
126 mlt_service nextservice = mlt_service_get_producer(service.get_service());
127 mlt_service nextservicetodisconnect;
128 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
129 QString mlt_type = mlt_properties_get(properties, "mlt_type");
130 QString resource = mlt_properties_get(properties, "mlt_service");
131 // Delete all transitions
132 while (mlt_type == "transition") {
133 nextservicetodisconnect = nextservice;
134 nextservice = mlt_service_producer(nextservice);
135 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
136 nextservice = mlt_service_producer(nextservice);
137 if (nextservice == NULL) break;
138 properties = MLT_SERVICE_PROPERTIES(nextservice);
139 mlt_type = mlt_properties_get(properties, "mlt_type");
140 resource = mlt_properties_get(properties, "mlt_service");
143 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
144 Mlt::Producer trackProducer(tractor.track(trackNb));
145 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
146 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
149 mlt_service_unlock(service.get_service());
152 kDebug() << "// // // CLOSE RENDERER " << m_name;
153 delete m_mltConsumer;
154 delete m_mltProducer;
159 void Render::slotSwitchFullscreen()
161 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
164 void Render::buildConsumer(const QString profileName)
167 m_activeProfile = profileName;
168 tmp = decodedString(m_activeProfile);
169 setenv("MLT_PROFILE", tmp, 1);
173 //TODO: uncomment following line when everything is clean
174 //if (m_mltProfile) delete m_mltProfile;
175 m_mltProfile = new Mlt::Profile(tmp);
178 QString videoDriver = KdenliveSettings::videodrivername();
179 if (!videoDriver.isEmpty()) {
180 if (videoDriver == "x11_noaccel") {
181 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
184 unsetenv("SDL_VIDEO_YUV_HWACCEL");
187 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
189 //m_mltConsumer->set("fullscreen", 1);
191 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_audio");
192 m_mltConsumer->set("preview_off", 1);
193 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
195 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
197 m_mltConsumer->set("resize", 1);
198 m_mltConsumer->set("window_id", m_winid);
199 m_mltConsumer->set("terminate_on_pause", 1);
200 tmp = decodedString(KdenliveSettings::window_background().name());
201 m_mltConsumer->set("window_background", tmp);
204 // FIXME: the event object returned by the listen gets leaked...
205 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
206 m_mltConsumer->set("rescale", "nearest");
207 mlt_log_set_callback(kdenlive_callback);
209 QString audioDevice = KdenliveSettings::audiodevicename();
210 if (!audioDevice.isEmpty()) {
211 tmp = decodedString(audioDevice);
212 m_mltConsumer->set("audio_device", tmp);
216 if (!videoDriver.isEmpty()) {
217 tmp = decodedString(videoDriver);
218 m_mltConsumer->set("video_driver", tmp);
222 QString audioDriver = KdenliveSettings::audiodrivername();
225 // Disabled because the "auto" detected driver was sometimes wrong
226 if (audioDriver.isEmpty())
227 audioDriver = KdenliveSettings::autoaudiodrivername();
230 if (!audioDriver.isEmpty()) {
231 tmp = decodedString(audioDriver);
232 m_mltConsumer->set("audio_driver", tmp);
236 int volume = KdenliveSettings::volume();
237 m_mltConsumer->set("volume", (float)volume / 100);
239 m_mltConsumer->set("progressive", 1);
240 m_mltConsumer->set("audio_buffer", 1024);
241 m_mltConsumer->set("frequency", 48000);
243 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
244 m_blackClip->set("id", "black");
245 m_blackClip->set("mlt_type", "producer");
249 Mlt::Producer *Render::invalidProducer(const QString &id)
251 Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile , "colour", "red");
252 char *tmp = decodedString(id);
253 clip->set("id", tmp);
255 clip->set("mlt_type", "producer");
259 int Render::resetProfile(const QString profileName)
262 QString videoDriver = KdenliveSettings::videodrivername();
263 QString currentDriver = m_mltConsumer->get("video_driver");
264 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
265 QString background = KdenliveSettings::window_background().name();
266 QString currentBackground = m_mltConsumer->get("window_background");
267 int volume = KdenliveSettings::volume();
268 int currentVolume = (int)(QString(m_mltConsumer->get("volume")).toDouble() * 100.0);
269 if (m_activeProfile == profileName && currentDriver == videoDriver && volume == currentVolume && background == currentBackground) {
270 kDebug() << "reset to same profile, nothing to do";
274 if (m_isSplitView) slotSplitView(false);
275 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
276 m_mltConsumer->purge();
277 delete m_mltConsumer;
278 m_mltConsumer = NULL;
280 QString scene = sceneList();
282 double current_fps = m_mltProfile->fps();
287 pos = m_mltProducer->position();
289 Mlt::Service service(m_mltProducer->get_service());
290 if (service.type() == tractor_type) {
291 Mlt::Tractor tractor(service);
292 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
293 Mlt::Producer trackProducer(tractor.track(trackNb));
294 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
295 trackPlaylist.clear();
299 delete m_mltProducer;
301 m_mltProducer = NULL;
303 buildConsumer(profileName);
304 double new_fps = m_mltProfile->fps();
305 if (current_fps != new_fps) {
306 // fps changed, we must update the scenelist positions
307 scene = updateSceneListFps(current_fps, new_fps, scene);
309 //kDebug() << "//RESET WITHSCENE: " << scene;
310 setSceneList(scene, pos);
311 // producers have changed (different profile), so reset them...
312 emit refreshDocumentProducers();
313 /*char *tmp = decodedString(scene);
314 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
316 m_mltProducer = producer;
317 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
318 m_mltProducer->optimise();
319 m_mltProducer->set_speed(0);
322 //delete m_mltProfile;
323 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
324 //mlt_profile prof = m_mltProfile->get_profile();
325 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
326 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
327 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
328 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
330 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
335 void Render::seek(GenTime time)
340 m_mltProducer->seek((int)(time.frames(m_fps)));
345 char *Render::decodedString(QString str)
347 /*QCString fn = QFile::encodeName(str);
348 char *t = new char[fn.length() + 1];
349 strcpy(t, (const char *)fn);*/
351 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
355 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
356 QPixmap pix(width, height);
358 mlt_image_format format = mlt_image_rgb24a;
359 uint8_t *thumb = frame->get_image(format, width, height);
360 QImage image(thumb, width, height, QImage::Format_ARGB32);
362 if (!image.isNull()) {
363 pix = pix.fromImage(image);
365 QPainter painter(&pix);
366 painter.drawRect(0, 0, width - 1, height - 1);
368 } else pix.fill(Qt::black);
372 int Render::renderWidth() const
374 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
377 int Render::renderHeight() const
379 return m_mltProfile->height();
382 QImage Render::extractFrame(int frame_position, int width, int height)
385 width = renderWidth();
386 height = renderHeight();
387 } else if (width % 2 == 1) width++;
389 if (!m_mltProducer) {
390 QImage pix(width, height, QImage::Format_RGB32);
394 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
397 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
401 if (url.fileName().startsWith(".all.")) { // check for slideshow
402 QString fileType = url.fileName().right(3);
404 QStringList::Iterator it;
406 QDir dir(url.directory());
408 filter << "*." + fileType;
409 filter << "*." + fileType.toUpper();
410 more = dir.entryList(filter, QDir::Files);
411 im.load(url.directory() + '/' + more.at(0));
412 } else im.load(url.path());
413 //pixmap = im.scaled(width, height);
418 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
419 QPixmap pix(width, height);
420 char *tmp = decodedString(file);
421 Mlt::Profile *prof = new Mlt::Profile(profile);
422 Mlt::Producer m_producer(*prof, tmp);
424 if (m_producer.is_blank()) {
429 Mlt::Filter m_convert(*prof, "avcolour_space");
430 m_convert.set("forced", mlt_image_rgb24a);
431 m_producer.attach(m_convert);
432 m_producer.seek(frame_position);
433 Mlt::Frame * frame = m_producer.get_frame();
435 pix = frameThumbnail(frame, width, height, true);
438 if (prof) delete prof;
443 void Render::getImage(KUrl url, int frame_position, QPoint size)
445 char *tmp = decodedString(url.path());
446 Mlt::Producer m_producer(tmp);
448 if (m_producer.is_blank()) {
451 Mlt::Filter m_convert("avcolour_space");
452 m_convert.set("forced", mlt_image_rgb24a);
453 m_producer.attach(m_convert);
454 m_producer.seek(frame_position);
456 Mlt::Frame * frame = m_producer.get_frame();
459 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
461 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
465 /* Create thumbnail for color */
466 /*void Render::getImage(int id, QString color, QPoint size)
468 QPixmap pixmap(size.x() - 2, size.y() - 2);
469 color = color.replace(0, 2, "#");
470 color = color.left(7);
471 pixmap.fill(QColor(color));
472 QPixmap result(size.x(), size.y());
473 result.fill(Qt::black);
474 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
475 emit replyGetImage(id, result, size.x(), size.y());
479 /* Create thumbnail for image */
480 /*void Render::getImage(KUrl url, QPoint size)
484 if (url.fileName().startsWith(".all.")) { // check for slideshow
485 QString fileType = url.fileName().right(3);
487 QStringList::Iterator it;
489 QDir dir( url.directory() );
490 more = dir.entryList( QDir::Files );
491 for ( it = more.begin() ; it != more.end() ; ++it ) {
492 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
493 if (!im.load(url.directory() + '/' + *it))
494 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
499 else im.load(url.path());
501 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
502 QPixmap result(size.x(), size.y());
503 result.fill(Qt::black);
504 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
505 emit replyGetImage(url, 1, result, size.x(), size.y());
509 double Render::consumerRatio() const
511 if (!m_mltConsumer) return 1.0;
512 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
516 int Render::getLength()
520 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
521 return mlt_producer_get_playtime(m_mltProducer->get_producer());
526 bool Render::isValid(KUrl url)
528 char *tmp = decodedString(url.path());
529 Mlt::Producer producer(*m_mltProfile, tmp);
531 if (producer.is_blank())
537 double Render::dar() const
539 return m_mltProfile->dar();
542 void Render::slotSplitView(bool doit)
544 m_isSplitView = doit;
545 Mlt::Service service(m_mltProducer->parent().get_service());
546 Mlt::Tractor tractor(service);
547 if (service.type() != tractor_type || tractor.count() < 2) return;
548 Mlt::Field *field = tractor.field();
550 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
551 Mlt::Producer trackProducer(tractor.track(i));
552 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
553 if (QString(trackProducer.get("hide")).toInt() != 1) {
554 kDebug() << "// ADIDNG TRACK: " << i;
555 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
556 transition->set("mlt_service", "composite");
557 transition->set("a_track", 0);
558 transition->set("b_track", i);
559 transition->set("distort", 1);
560 transition->set("internal_added", "200");
567 tmp = "50%,0:50%x50%";
570 tmp = "0,50%:50%x50%";
574 tmp = "50%,50%:50%x50%";
577 transition->set("geometry", tmp);
578 transition->set("always_active", "1");
579 field->plant_transition(*transition, 0, i);
584 m_mltConsumer->set("refresh", 1);
586 mlt_service serv = m_mltProducer->parent().get_service();
587 mlt_service nextservice = mlt_service_get_producer(serv);
588 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
589 QString mlt_type = mlt_properties_get(properties, "mlt_type");
590 QString resource = mlt_properties_get(properties, "mlt_service");
592 while (mlt_type == "transition") {
593 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
594 if (added == "200") {
595 mlt_field_disconnect_service(field->get_field(), nextservice);
597 nextservice = mlt_service_producer(nextservice);
598 if (nextservice == NULL) break;
599 properties = MLT_SERVICE_PROPERTIES(nextservice);
600 mlt_type = mlt_properties_get(properties, "mlt_type");
601 resource = mlt_properties_get(properties, "mlt_service");
602 m_mltConsumer->set("refresh", 1);
607 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
609 KUrl url = KUrl(xml.attribute("resource", QString()));
610 Mlt::Producer *producer = NULL;
611 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
612 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
613 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
616 if (xml.attribute("type").toInt() == COLOR) {
617 char *tmp = decodedString("colour:" + xml.attribute("colour"));
618 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
620 } else if (xml.attribute("type").toInt() == TEXT) {
621 char *tmp = decodedString("kdenlivetitle:" + xml.attribute("resource"));
622 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
624 if (producer && xml.hasAttribute("xmldata")) {
625 tmp = decodedString(xml.attribute("xmldata"));
626 producer->set("xmldata", tmp);
629 } else if (url.isEmpty()) {
631 QDomElement mlt = doc.createElement("mlt");
632 QDomElement play = doc.createElement("playlist");
633 doc.appendChild(mlt);
634 mlt.appendChild(play);
635 play.appendChild(doc.importNode(xml, true));
636 char *tmp = decodedString(doc.toString());
637 producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
640 char *tmp = decodedString(url.path());
641 producer = new Mlt::Producer(*m_mltProfile, tmp);
645 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
646 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
647 emit removeInvalidClip(clipId, replaceProducer);
652 if (xml.hasAttribute("force_aspect_ratio")) {
653 double aspect = xml.attribute("force_aspect_ratio").toDouble();
654 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
657 if (xml.hasAttribute("force_fps")) {
658 double fps = xml.attribute("force_fps").toDouble();
659 if (fps > 0) producer->set("force_fps", fps);
662 if (xml.hasAttribute("force_progressive")) {
664 int progressive = xml.attribute("force_progressive").toInt(&ok);
665 if (ok) producer->set("force_progressive", progressive);
667 if (xml.hasAttribute("threads")) {
668 int threads = xml.attribute("threads").toInt();
669 if (threads != 1) producer->set("threads", threads);
671 if (xml.hasAttribute("video_index")) {
672 int vindex = xml.attribute("video_index").toInt();
673 if (vindex != 0) producer->set("video_index", vindex);
675 if (xml.hasAttribute("audio_index")) {
676 int aindex = xml.attribute("audio_index").toInt();
677 if (aindex != 0) producer->set("audio_index", aindex);
680 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken although outpoint is larger
681 if (xml.attribute("type").toInt() == COLOR || xml.attribute("type").toInt() == TEXT
682 || xml.attribute("type").toInt() == IMAGE || xml.attribute("type").toInt() == SLIDESHOW)
683 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
685 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
687 char *tmp = decodedString(clipId);
688 producer->set("id", tmp);
691 if (xml.hasAttribute("templatetext")) {
692 char *tmp = decodedString(xml.attribute("templatetext"));
693 producer->set("templatetext", tmp);
697 if (!replaceProducer && xml.hasAttribute("file_hash")) {
698 // Clip already has all properties
699 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
703 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
704 QMap < QString, QString > filePropertyMap;
705 QMap < QString, QString > metadataPropertyMap;
707 int frameNumber = xml.attribute("thumbnail", "0").toInt();
708 if (frameNumber != 0) producer->seek(frameNumber);
710 filePropertyMap["duration"] = QString::number(producer->get_playtime());
711 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
713 Mlt::Frame *frame = producer->get_frame();
715 if (xml.attribute("type").toInt() == SLIDESHOW) {
716 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
717 if (ttl) producer->set("ttl", ttl);
718 if (!xml.attribute("animation").isEmpty()) {
719 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
720 if (filter && filter->is_valid()) {
722 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
723 if (!geometry.isEmpty()) {
724 if (xml.attribute("animation").contains("low-pass")) {
725 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
726 if (blur && blur->is_valid())
727 producer->attach(*blur);
729 filter->set("transition.geometry", geometry.toUtf8().data());
730 filter->set("transition.cycle", cycle);
731 producer->attach(*filter);
735 if (xml.attribute("fade") == "1") {
736 // user wants a fade effect to slideshow
737 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
738 if (filter && filter->is_valid()) {
739 if (ttl) filter->set("cycle", ttl);
740 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
741 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
742 char *tmp = decodedString(xml.attribute("luma_file"));
743 filter->set("luma.resource", tmp);
745 if (xml.hasAttribute("softness")) {
746 int soft = xml.attribute("softness").toInt();
747 filter->set("luma.softness", (double) soft / 100.0);
750 producer->attach(*filter);
753 if (xml.attribute("crop") == "1") {
754 // user wants to center crop the slides
755 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
756 if (filter && filter->is_valid()) {
757 filter->set("center", 1);
758 producer->attach(*filter);
764 filePropertyMap["fps"] = producer->get("source_fps");
766 if (frame && frame->is_valid()) {
767 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
768 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
769 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
770 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
772 if (frame->get_int("test_image") == 0) {
773 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
774 filePropertyMap["type"] = "playlist";
775 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
776 } else if (frame->get_int("test_audio") == 0)
777 filePropertyMap["type"] = "av";
779 filePropertyMap["type"] = "video";
781 mlt_image_format format = mlt_image_rgb24a;
782 int frame_width = width;
783 int frame_height = imageHeight;
784 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
785 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32);
788 if (!image.isNull()) {
789 if (frame_width > (2 * width)) {
790 // there was a scaling problem, do it manually
791 QImage scaled = image.scaled(width, imageHeight);
792 pix = QPixmap::fromImage(scaled.rgbSwapped());
793 } else pix = QPixmap::fromImage(image.rgbSwapped());
797 emit replyGetImage(clipId, pix);
799 } else if (frame->get_int("test_audio") == 0) {
800 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
801 emit replyGetImage(clipId, pixmap);
802 filePropertyMap["type"] = "audio";
806 // Retrieve audio / video codec name
810 if (producer->get_int("video_index") > -1) {
811 /*if (context->duration == AV_NOPTS_VALUE) {
812 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
813 emit removeInvalidClip(clipId);
817 // Get the video_index
818 int default_video = producer->get_int("video_index");
820 int default_audio = producer->get_int("audio_index");
823 // Find maximum stream index values
824 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
825 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
826 QString type = producer->get(property);
829 else if (type == "audio")
832 filePropertyMap["default_video"] = QString::number(default_video);
833 filePropertyMap["video_max"] = QString::number(video_max);
834 filePropertyMap["default_audio"] = QString::number(default_audio);
835 filePropertyMap["audio_max"] = QString::number(audio_max);
837 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
838 if (producer->get(property)) {
839 filePropertyMap["videocodec"] = producer->get(property);
841 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
842 if (producer->get(property))
843 filePropertyMap["videocodec"] = producer->get(property);
846 if (KdenliveSettings::dropbframes()) {
847 kDebug() << "// LOOKING FOR H264 on: " << default_video;
848 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
849 kDebug() << "PROP: " << property << " = " << producer->get(property);
850 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
851 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
852 producer->set("skip_loop_filter", "all");
853 producer->set("skip_frame", "bidir");
857 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
858 if (producer->get_int("audio_index") > -1) {
859 // Get the audio_index
860 int index = producer->get_int("audio_index");
862 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
863 if (producer->get(property)) {
864 filePropertyMap["audiocodec"] = producer->get(property);
866 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
867 if (producer->get(property))
868 filePropertyMap["audiocodec"] = producer->get(property);
873 Mlt::Properties metadata;
874 metadata.pass_values(*producer, "meta.attr.");
875 int count = metadata.count();
876 for (int i = 0; i < count; i ++) {
877 QString name = metadata.get_name(i);
878 QString value = QString::fromUtf8(metadata.get(i));
879 if (name.endsWith("markup") && !value.isEmpty())
880 metadataPropertyMap[ name.section('.', 0, -2)] = value;
883 kDebug() << "REquested fuile info for: " << url.path();
884 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
885 // FIXME: should delete this to avoid a leak...
891 /** Create the producer from the MLT XML QDomDocument */
892 void Render::initSceneList()
894 kDebug() << "-------- INIT SCENE LIST ------_";
896 QDomElement mlt = doc.createElement("mlt");
897 doc.appendChild(mlt);
898 QDomElement prod = doc.createElement("producer");
899 prod.setAttribute("resource", "colour");
900 prod.setAttribute("colour", "red");
901 prod.setAttribute("id", "black");
902 prod.setAttribute("in", "0");
903 prod.setAttribute("out", "0");
905 QDomElement tractor = doc.createElement("tractor");
906 QDomElement multitrack = doc.createElement("multitrack");
908 QDomElement playlist1 = doc.createElement("playlist");
909 playlist1.appendChild(prod);
910 multitrack.appendChild(playlist1);
911 QDomElement playlist2 = doc.createElement("playlist");
912 multitrack.appendChild(playlist2);
913 QDomElement playlist3 = doc.createElement("playlist");
914 multitrack.appendChild(playlist3);
915 QDomElement playlist4 = doc.createElement("playlist");
916 multitrack.appendChild(playlist4);
917 QDomElement playlist5 = doc.createElement("playlist");
918 multitrack.appendChild(playlist5);
919 tractor.appendChild(multitrack);
920 mlt.appendChild(tractor);
921 // kDebug()<<doc.toString();
923 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
924 setSceneList(doc, 0);
928 int Render::setProducer(Mlt::Producer *producer, int position)
930 if (m_winid == -1) return -1;
933 m_mltConsumer->stop();
936 m_mltConsumer->purge();
940 m_mltProducer->set_speed(0);
941 delete m_mltProducer;
942 m_mltProducer = NULL;
946 m_mltProducer = new Mlt::Producer(producer->get_producer());
947 } else m_mltProducer = m_blackClip->cut(0, 50);
948 /*if (KdenliveSettings::dropbframes()) {
949 m_mltProducer->set("skip_loop_filter", "all");
950 m_mltProducer->set("skip_frame", "bidir");
952 if (!m_mltProducer || !m_mltProducer->is_valid()) {
953 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
957 m_fps = m_mltProducer->get_fps();
958 int error = connectPlaylist();
960 if (position != -1) {
961 m_mltProducer->seek(position);
962 emit rendererPosition(position);
963 } else emit rendererPosition((int) m_mltProducer->position());
968 int Render::setSceneList(QDomDocument list, int position)
970 return setSceneList(list.toString(), position);
973 int Render::setSceneList(QString playlist, int position)
975 if (m_winid == -1) return -1;
979 kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
982 if (!m_mltConsumer->is_stopped()) {
983 m_mltConsumer->stop();
985 m_mltConsumer->set("refresh", 0);
987 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
992 m_mltProducer->set_speed(0);
993 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
996 Mlt::Service service(m_mltProducer->parent().get_service());
997 mlt_service_lock(service.get_service());
999 if (service.type() == tractor_type) {
1000 Mlt::Tractor tractor(service);
1001 Mlt::Field *field = tractor.field();
1002 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1003 mlt_service nextservicetodisconnect;
1004 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1005 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1006 QString resource = mlt_properties_get(properties, "mlt_service");
1007 // Delete all transitions
1008 while (mlt_type == "transition") {
1009 nextservicetodisconnect = nextservice;
1010 nextservice = mlt_service_producer(nextservice);
1011 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1012 if (nextservice == NULL) break;
1013 properties = MLT_SERVICE_PROPERTIES(nextservice);
1014 mlt_type = mlt_properties_get(properties, "mlt_type");
1015 resource = mlt_properties_get(properties, "mlt_service");
1018 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1019 Mlt::Producer trackProducer(tractor.track(trackNb));
1020 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1021 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1025 mlt_service_unlock(service.get_service());
1027 qDeleteAll(m_slowmotionProducers.values());
1028 m_slowmotionProducers.clear();
1030 delete m_mltProducer;
1031 m_mltProducer = NULL;
1036 char *tmp = decodedString(playlist);
1037 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
1039 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1040 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
1041 m_mltProducer = m_blackClip->cut(0, 50);
1046 m_mltProducer->optimise();
1048 /*if (KdenliveSettings::osdtimecode()) {
1049 // Attach filter for on screen display of timecode
1051 QString attr = "attr_check";
1052 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1053 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1054 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1055 mlt_filter_close( filter );
1057 m_osdInfo = new Mlt::Filter("data_show");
1058 tmp = decodedString(m_osdProfile);
1059 m_osdInfo->set("resource", tmp);
1061 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1062 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1063 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1064 m_osdInfo->set("dynamic", "1");
1066 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1068 m_osdInfo->set("dynamic", "0");
1071 m_fps = m_mltProducer->get_fps();
1072 if (position != 0) {
1073 // Seek to correct place after opening project.
1074 m_mltProducer->seek(position);
1077 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1078 if (error == 0) error = connectPlaylist();
1079 else connectPlaylist();
1080 fillSlowMotionProducers();
1082 m_isBlocked = false;
1083 blockSignals(false);
1086 //kDebug()<<"// SETSCN LST, POS: "<<position;
1087 //if (position != 0) emit rendererPosition(position);
1090 const QString Render::sceneList()
1093 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
1094 m_mltProducer->optimise();
1095 xmlConsumer.set("terminate_on_pause", 1);
1096 Mlt::Producer prod(m_mltProducer->get_producer());
1097 bool split = m_isSplitView;
1098 if (split) slotSplitView(false);
1099 xmlConsumer.connect(prod);
1100 xmlConsumer.start();
1101 while (!xmlConsumer.is_stopped()) {}
1102 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1103 if (split) slotSplitView(true);
1107 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1111 doc.setContent(sceneList(), false);
1112 if (!kdenliveData.isNull()) {
1113 // add Kdenlive specific tags
1114 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1115 mlt.appendChild(doc.importNode(kdenliveData, true));
1117 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1118 kWarning() << "////// ERROR writing to file: " << path;
1121 file.write(doc.toString().toUtf8());
1122 if (file.error() != QFile::NoError) {
1130 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1132 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1133 char *tmppath = decodedString("xml:" + url.path());
1134 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
1135 m_mltProducer->optimise();
1137 xmlConsumer.set("terminate_on_pause", 1);
1138 if (m_name == "clip") {
1139 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1140 tmppath = decodedString(desc);
1142 list.insert_at(0, prod, 0);
1144 list.set("title", tmppath);
1146 xmlConsumer.connect(list);
1149 //TODO: not working yet, save zone from timeline
1150 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1151 /* Mlt::Service service(p1->parent().get_service());
1152 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1154 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1155 tmppath = decodedString(desc);
1156 //prod->set("title", tmppath);
1158 xmlConsumer.connect(*p1); //list);
1161 xmlConsumer.start();
1164 double Render::fps() const
1169 int Render::connectPlaylist()
1171 if (!m_mltConsumer) return -1;
1172 //m_mltConsumer->set("refresh", "0");
1173 m_mltConsumer->connect(*m_mltProducer);
1174 m_mltProducer->set_speed(0);
1175 if (m_mltConsumer->start() == -1) {
1176 // ARGH CONSUMER BROKEN!!!!
1177 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."));
1178 delete m_mltConsumer;
1179 m_mltConsumer = NULL;
1182 emit durationChanged(m_mltProducer->get_playtime());
1187 void Render::refreshDisplay()
1190 if (!m_mltProducer) return;
1191 //m_mltConsumer->set("refresh", 0);
1193 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1194 /*if (KdenliveSettings::osdtimecode()) {
1195 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1196 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1197 m_osdInfo->set("dynamic", "1");
1198 m_mltProducer->attach(*m_osdInfo);
1201 m_mltProducer->detach(*m_osdInfo);
1202 m_osdInfo->set("dynamic", "0");
1207 void Render::setVolume(double /*volume*/)
1209 if (!m_mltConsumer || !m_mltProducer) return;
1211 m_mltConsumer->set("refresh", 0);
1212 // Attach filter for on screen display of timecode
1213 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1214 mlt_properties_set_double( properties, "meta.volume", volume );
1215 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1216 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1218 if (!KdenliveSettings::osdtimecode()) {
1219 m_mltProducer->detach(*m_osdInfo);
1220 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1221 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1224 //m_osdTimer->setSingleShot(2500);
1227 void Render::slotOsdTimeout()
1229 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1230 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1231 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1232 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1236 void Render::start()
1238 kDebug() << "----- STARTING MONITOR: " << m_name;
1239 if (m_winid == -1) {
1240 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1243 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1244 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1245 if (m_mltConsumer->start() == -1) {
1246 //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."));
1247 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1249 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1250 m_isBlocked = false;
1254 m_isBlocked = false;
1259 if (m_mltProducer == NULL) return;
1260 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1261 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1263 //m_mltConsumer->set("refresh", 0);
1264 m_mltConsumer->stop();
1265 // delete m_mltConsumer;
1266 // m_mltConsumer = NULL;
1268 kDebug() << "///////////// RENDER STOP2-------";
1271 if (m_mltProducer) {
1272 if (m_isZoneMode) resetZoneMode();
1273 m_mltProducer->set_speed(0.0);
1274 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1275 //kDebug() << m_mltProducer->get_length();
1277 kDebug() << "///////////// RENDER STOP3-------";
1280 void Render::stop(const GenTime & startTime)
1283 kDebug() << "///////////// RENDER STOP-------2";
1284 if (m_mltProducer) {
1285 if (m_isZoneMode) resetZoneMode();
1286 m_mltProducer->set_speed(0.0);
1287 m_mltProducer->seek((int) startTime.frames(m_fps));
1289 m_mltConsumer->purge();
1292 void Render::pause()
1294 if (!m_mltProducer || !m_mltConsumer)
1296 if (m_mltProducer->get_speed() == 0.0) return;
1297 if (m_isZoneMode) resetZoneMode();
1299 m_mltConsumer->set("refresh", 0);
1300 m_mltProducer->set_speed(0.0);
1302 The 2 lines below create a flicker loop
1303 emit rendererPosition(m_framePosition);
1304 m_mltProducer->seek(m_framePosition);*/
1305 m_mltConsumer->purge();
1308 void Render::switchPlay()
1310 if (!m_mltProducer || !m_mltConsumer)
1312 if (m_isZoneMode) resetZoneMode();
1313 if (m_mltProducer->get_speed() == 0.0) {
1314 m_isBlocked = false;
1315 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1316 m_mltProducer->set_speed(1.0);
1317 m_mltConsumer->set("refresh", 1);
1320 m_mltConsumer->set("refresh", 0);
1321 m_mltProducer->set_speed(0.0);
1322 //emit rendererPosition(m_framePosition);
1323 m_mltProducer->seek(m_framePosition);
1324 m_mltConsumer->purge();
1325 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1326 //m_mltConsumer->set("refresh", 0);
1327 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1328 m_mltProducer->set_speed(0);
1329 m_mltProducer->seek( position );
1330 //m_mltProducer->seek((int) m_framePosition);
1331 m_isBlocked = false;*/
1333 /*if (speed == 0.0) {
1334 m_mltProducer->seek((int) m_framePosition + 1);
1335 m_mltConsumer->purge();
1340 void Render::play(double speed)
1344 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1345 m_isBlocked = false;
1346 m_mltProducer->set_speed(speed);
1347 /*if (speed == 0.0) {
1348 m_mltProducer->seek((int) m_framePosition + 1);
1349 m_mltConsumer->purge();
1354 void Render::play(const GenTime & startTime)
1356 if (!m_mltProducer || !m_mltConsumer)
1358 m_isBlocked = false;
1359 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1360 m_mltProducer->set_speed(1.0);
1361 m_mltConsumer->set("refresh", 1);
1364 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1366 if (!m_mltProducer || !m_mltConsumer)
1368 //m_mltProducer->set("eof", "loop");
1369 m_isLoopMode = true;
1370 m_loopStart = startTime;
1371 playZone(startTime, stopTime);
1374 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1376 if (!m_mltProducer || !m_mltConsumer)
1378 m_isBlocked = false;
1379 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1380 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1381 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1382 m_mltProducer->set_speed(1.0);
1383 m_mltConsumer->set("refresh", 1);
1384 m_isZoneMode = true;
1387 void Render::resetZoneMode()
1389 if (!m_isZoneMode && !m_isLoopMode) return;
1390 m_mltProducer->set("out", m_originalOut);
1391 //m_mltProducer->set("eof", "pause");
1392 m_isZoneMode = false;
1393 m_isLoopMode = false;
1396 void Render::seekToFrame(int pos)
1398 //kDebug()<<" ********* RENDER SEEK TO POS";
1401 m_isBlocked = false;
1403 m_mltProducer->seek(pos);
1407 void Render::seekToFrameDiff(int diff)
1409 //kDebug()<<" ********* RENDER SEEK TO POS";
1412 m_isBlocked = false;
1414 m_mltProducer->seek(m_mltProducer->position() + diff);
1418 void Render::doRefresh()
1420 // Use a Timer so that we don't refresh too much
1421 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1424 void Render::refresh()
1426 if (!m_mltProducer || m_isBlocked)
1428 if (m_mltConsumer) {
1429 m_mltConsumer->set("refresh", 1);
1433 void Render::setDropFrames(bool show)
1435 if (m_mltConsumer) {
1437 if (show == false) dropFrames = 0;
1438 m_mltConsumer->stop();
1440 m_mltConsumer->set("real_time", dropFrames);
1442 m_mltConsumer->set("play.real_time", dropFrames);
1444 if (m_mltConsumer->start() == -1) {
1445 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1451 double Render::playSpeed()
1453 if (m_mltProducer) return m_mltProducer->get_speed();
1457 GenTime Render::seekPosition() const
1459 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1460 else return GenTime();
1463 int Render::seekFramePosition() const
1465 if (m_mltProducer) return (int) m_mltProducer->position();
1469 const QString & Render::rendererName() const
1474 void Render::emitFrameUpdated(Mlt::Frame& frame)
1476 mlt_image_format format = mlt_image_rgb24a;
1479 const uchar* image = frame.get_image(format, width, height);
1480 QImage qimage(width, height, QImage::Format_ARGB32);
1481 memcpy(qimage.bits(), image, width * height * 4);
1482 emit frameUpdated(qimage.rgbSwapped());
1485 void Render::emitFrameNumber(double position)
1487 m_framePosition = position;
1488 emit rendererPosition((int) position);
1491 void Render::emitConsumerStopped()
1493 // This is used to know when the playing stopped
1494 if (m_mltProducer) {
1495 double pos = m_mltProducer->position();
1496 if (m_isLoopMode) play(m_loopStart);
1497 else if (m_isZoneMode) resetZoneMode();
1498 emit rendererStopped((int) pos);
1499 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1500 //new QCustomEvent(10002));
1504 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1506 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1509 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1511 if (!m_mltProducer) {
1512 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1516 //int height = 1080;//KdenliveSettings::defaultheight();
1517 //int width = 1940; //KdenliveSettings::displaywidth();
1519 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1521 QPixmap pix(width, height);
1522 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1523 m_convert.set("forced", mlt_image_rgb24a);
1524 m_mltProducer->attach(m_convert);
1525 Mlt::Frame * frame = m_mltProducer->get_frame();
1526 m_mltProducer->detach(m_convert);
1528 pix = frameThumbnail(frame, width, height);
1531 pix.save(url.path(), "PNG");
1532 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1536 void Render::showFrame(Mlt::Frame& frame)
1538 mlt_image_format format = mlt_image_rgb24a;
1541 const uchar* image = frame.get_image(format, width, height);
1542 QImage qimage(width, height, QImage::Format_ARGB32);
1543 memcpy(qimage.scanLine(0), image, width * height * 4);
1544 emit showImageSignal(qimage);
1550 * MLT playlist direct manipulation.
1553 void Render::mltCheckLength(Mlt::Tractor *tractor)
1555 //kDebug()<<"checking track length: "<<track<<"..........";
1557 int trackNb = tractor->count();
1561 Mlt::Producer trackProducer(tractor->track(0));
1562 duration = trackProducer.get_playtime() - 1;
1563 m_mltProducer->set("out", duration);
1564 emit durationChanged(duration);
1567 while (trackNb > 1) {
1568 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1569 trackDuration = trackProducer.get_playtime() - 1;
1570 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1571 if (trackDuration > duration) duration = trackDuration;
1575 Mlt::Producer blackTrackProducer(tractor->track(0));
1577 if (blackTrackProducer.get_playtime() - 1 != duration) {
1578 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1579 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1580 if (blackclip && blackclip->is_blank()) {
1585 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1586 blackTrackPlaylist.clear();
1587 m_blackClip->set("length", duration + 1);
1588 m_blackClip->set("out", duration);
1589 blackclip = m_blackClip->cut(0, duration);
1590 blackTrackPlaylist.insert_at(0, blackclip, 1);
1592 if (duration > blackclip->parent().get_length()) {
1593 blackclip->parent().set("length", duration + 1);
1594 blackclip->parent().set("out", duration);
1595 blackclip->set("length", duration + 1);
1597 blackTrackPlaylist.resize_clip(0, 0, duration);
1601 m_mltProducer->set("out", duration);
1602 emit durationChanged(duration);
1606 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1608 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1610 // We want a slowmotion producer
1611 double speed = element.attribute("speed", "1.0").toDouble();
1612 int strobe = element.attribute("strobe", "1").toInt();
1613 QString url = QString::fromUtf8(prod->get("resource"));
1614 url.append('?' + QString::number(speed));
1615 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1616 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1617 if (!slowprod || slowprod->get_producer() == NULL) {
1618 char *tmp = decodedString(url);
1619 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1620 if (strobe > 1) slowprod->set("strobe", strobe);
1622 QString id = prod->get("id");
1623 if (id.contains('_')) id = id.section('_', 0, 0);
1624 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1625 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1626 tmp = decodedString(producerid);
1627 slowprod->set("id", tmp);
1629 m_slowmotionProducers.insert(url, slowprod);
1634 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1636 if (m_mltProducer == NULL) {
1637 kDebug() << "PLAYLIST NOT INITIALISED //////";
1641 kDebug() << "Cannot insert clip without producer //////";
1644 Mlt::Producer parentProd(m_mltProducer->parent());
1645 if (parentProd.get_producer() == NULL) {
1646 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1650 Mlt::Service service(parentProd.get_service());
1651 if (service.type() != tractor_type) {
1652 kWarning() << "// TRACTOR PROBLEM";
1655 Mlt::Tractor tractor(service);
1656 if (info.track > tractor.count() - 1) {
1657 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1660 mlt_service_lock(service.get_service());
1661 Mlt::Producer trackProducer(tractor.track(info.track));
1662 int trackDuration = trackProducer.get_playtime() - 1;
1663 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1664 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1665 prod = checkSlowMotionProducer(prod, element);
1666 if (prod == NULL || !prod->is_valid()) {
1667 mlt_service_unlock(service.get_service());
1671 int cutPos = (int) info.cropStart.frames(m_fps);
1672 if (cutPos < 0) cutPos = 0;
1673 int insertPos = (int) info.startPos.frames(m_fps);
1674 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1675 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1676 if (overwrite && (insertPos < trackDuration)) {
1677 // Replace zone with blanks
1678 //trackPlaylist.split_at(insertPos, true);
1679 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1680 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1681 trackPlaylist.insert_blank(clipIndex, cutDuration);
1683 trackPlaylist.split_at(insertPos, true);
1684 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1685 trackPlaylist.insert_blank(clipIndex, cutDuration);
1687 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1689 /*if (QString(prod->get("transparency")).toInt() == 1)
1690 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1692 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1693 mlt_service_unlock(service.get_service());
1694 /*tractor.multitrack()->refresh();
1695 tractor.refresh();*/
1700 void Render::mltCutClip(int track, GenTime position)
1704 Mlt::Service service(m_mltProducer->parent().get_service());
1705 if (service.type() != tractor_type) {
1706 kWarning() << "// TRACTOR PROBLEM";
1710 Mlt::Tractor tractor(service);
1711 Mlt::Producer trackProducer(tractor.track(track));
1712 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1715 /* // Display playlist info
1716 kDebug()<<"//////////// BEFORE";
1717 for (int i = 0; i < trackPlaylist.count(); i++) {
1718 int blankStart = trackPlaylist.clip_start(i);
1719 int blankDuration = trackPlaylist.clip_length(i) - 1;
1721 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1722 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1725 int cutPos = (int) position.frames(m_fps);
1727 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1728 if (trackPlaylist.is_blank(clipIndex)) {
1729 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1730 m_isBlocked = false;
1733 mlt_service_lock(service.get_service());
1734 int clipStart = trackPlaylist.clip_start(clipIndex);
1735 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1736 mlt_service_unlock(service.get_service());
1738 // duplicate effects
1739 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1740 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1742 if (original == NULL || clip == NULL) {
1743 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1745 Mlt::Service clipService(original->get_service());
1746 Mlt::Service dupService(clip->get_service());
1750 Mlt::Filter *filter = clipService.filter(ct);
1752 // Only duplicate Kdenlive filters, and skip the fade in effects
1753 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1754 // looks like there is no easy way to duplicate a filter,
1755 // so we will create a new one and duplicate its properties
1756 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1757 if (dup && dup->is_valid()) {
1758 Mlt::Properties entries(filter->get_properties());
1759 for (int i = 0; i < entries.count(); i++) {
1760 dup->set(entries.get_name(i), entries.get(i));
1762 dupService.attach(*dup);
1766 filter = clipService.filter(ct);
1769 /* // Display playlist info
1770 kDebug()<<"//////////// AFTER";
1771 for (int i = 0; i < trackPlaylist.count(); i++) {
1772 int blankStart = trackPlaylist.clip_start(i);
1773 int blankDuration = trackPlaylist.clip_length(i) - 1;
1775 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1776 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1779 m_isBlocked = false;
1782 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1786 kDebug() << "Cannot update clip with null producer //////";
1789 Mlt::Service service(m_mltProducer->parent().get_service());
1790 if (service.type() != tractor_type) {
1791 kWarning() << "// TRACTOR PROBLEM";
1794 Mlt::Tractor tractor(service);
1795 Mlt::Producer trackProducer(tractor.track(info.track));
1796 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1797 int startPos = info.startPos.frames(m_fps);
1798 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1799 if (trackPlaylist.is_blank(clipIndex)) {
1800 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1803 mlt_service_lock(service.get_service());
1804 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1806 QList <Mlt::Filter *> filtersList;
1807 Mlt::Service sourceService(clip->get_service());
1809 Mlt::Filter *filter = sourceService.filter(ct);
1811 if (filter->get_int("kdenlive_ix") != 0) {
1812 filtersList.append(filter);
1815 filter = sourceService.filter(ct);
1818 trackPlaylist.replace_with_blank(clipIndex);
1820 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1821 prod = checkSlowMotionProducer(prod, element);
1822 if (prod == NULL || !prod->is_valid()) {
1823 mlt_service_unlock(service.get_service());
1826 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1827 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1831 //if (mltInsertClip(info, element, prod) == -1) return false;
1832 if (!filtersList.isEmpty()) {
1833 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1834 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1835 Mlt::Service destService(destclip->get_service());
1837 for (int i = 0; i < filtersList.count(); i++)
1838 destService.attach(*(filtersList.at(i)));
1840 mlt_service_unlock(service.get_service());
1845 bool Render::mltRemoveClip(int track, GenTime position)
1847 Mlt::Service service(m_mltProducer->parent().get_service());
1848 if (service.type() != tractor_type) {
1849 kWarning() << "// TRACTOR PROBLEM";
1853 Mlt::Tractor tractor(service);
1854 mlt_service_lock(service.get_service());
1855 Mlt::Producer trackProducer(tractor.track(track));
1856 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1857 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1859 // Display playlist info
1860 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1861 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1862 int blankStart = trackPlaylist.clip_start(i);
1863 int blankDuration = trackPlaylist.clip_length(i) - 1;
1865 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1866 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1868 if (trackPlaylist.is_blank(clipIndex)) {
1869 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1870 mlt_service_unlock(service.get_service());
1873 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1875 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1876 if (clip) delete clip;
1877 trackPlaylist.consolidate_blanks(0);
1878 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1879 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1881 /* // Display playlist info
1882 kDebug()<<"//// AFTER";
1883 for (int i = 0; i < trackPlaylist.count(); i++) {
1884 int blankStart = trackPlaylist.clip_start(i);
1885 int blankDuration = trackPlaylist.clip_length(i) - 1;
1887 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1888 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1890 mlt_service_unlock(service.get_service());
1891 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1892 m_isBlocked = false;
1896 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1898 if (!m_mltProducer) {
1899 kDebug() << "PLAYLIST NOT INITIALISED //////";
1902 Mlt::Producer parentProd(m_mltProducer->parent());
1903 if (parentProd.get_producer() == NULL) {
1904 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1908 Mlt::Service service(parentProd.get_service());
1909 Mlt::Tractor tractor(service);
1910 int insertPos = pos.frames(m_fps);
1912 Mlt::Producer trackProducer(tractor.track(track));
1913 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1914 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1915 if (clipIndex == trackPlaylist.count()) {
1916 // We are after the end of the playlist
1919 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1920 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1921 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1924 int Render::mltTrackDuration(int track)
1926 if (!m_mltProducer) {
1927 kDebug() << "PLAYLIST NOT INITIALISED //////";
1930 Mlt::Producer parentProd(m_mltProducer->parent());
1931 if (parentProd.get_producer() == NULL) {
1932 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1936 Mlt::Service service(parentProd.get_service());
1937 Mlt::Tractor tractor(service);
1939 Mlt::Producer trackProducer(tractor.track(track));
1940 return trackProducer.get_playtime() - 1;
1943 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1945 if (!m_mltProducer) {
1946 kDebug() << "PLAYLIST NOT INITIALISED //////";
1949 Mlt::Producer parentProd(m_mltProducer->parent());
1950 if (parentProd.get_producer() == NULL) {
1951 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1954 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1955 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1957 Mlt::Service service(parentProd.get_service());
1958 Mlt::Tractor tractor(service);
1959 mlt_service_lock(service.get_service());
1960 int diff = duration.frames(m_fps);
1961 int offset = timeOffset.frames(m_fps);
1965 // insert space in one track only
1966 Mlt::Producer trackProducer(tractor.track(track));
1967 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1968 insertPos = trackClipStartList.value(track);
1969 if (insertPos != -1) {
1970 insertPos += offset;
1971 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1973 trackPlaylist.insert_blank(clipIndex, diff - 1);
1975 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1976 if (!trackPlaylist.is_blank(clipIndex)) {
1977 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1979 int position = trackPlaylist.clip_start(clipIndex);
1980 int blankDuration = trackPlaylist.clip_length(clipIndex);
1982 if (blankDuration - diff == 0) {
1983 trackPlaylist.remove(clipIndex);
1984 } else trackPlaylist.remove_region(position, diff);
1986 trackPlaylist.consolidate_blanks(0);
1988 // now move transitions
1989 mlt_service serv = m_mltProducer->parent().get_service();
1990 mlt_service nextservice = mlt_service_get_producer(serv);
1991 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1992 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1993 QString resource = mlt_properties_get(properties, "mlt_service");
1995 while (mlt_type == "transition") {
1996 mlt_transition tr = (mlt_transition) nextservice;
1997 int currentTrack = mlt_transition_get_b_track(tr);
1998 int currentIn = (int) mlt_transition_get_in(tr);
1999 int currentOut = (int) mlt_transition_get_out(tr);
2000 insertPos = trackTransitionStartList.value(track);
2001 if (insertPos != -1) {
2002 insertPos += offset;
2003 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
2004 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2007 nextservice = mlt_service_producer(nextservice);
2008 if (nextservice == NULL) break;
2009 properties = MLT_SERVICE_PROPERTIES(nextservice);
2010 mlt_type = mlt_properties_get(properties, "mlt_type");
2011 resource = mlt_properties_get(properties, "mlt_service");
2014 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
2015 Mlt::Producer trackProducer(tractor.track(trackNb));
2016 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2018 //int clipNb = trackPlaylist.count();
2019 insertPos = trackClipStartList.value(trackNb);
2020 if (insertPos != -1) {
2021 insertPos += offset;
2023 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2024 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2025 for (int i = 0; i < clipNb; i++) {
2026 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2027 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2028 kDebug()<<"-------------";
2030 kDebug()<<"END-------------";*/
2033 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2035 trackPlaylist.insert_blank(clipIndex, diff - 1);
2037 if (!trackPlaylist.is_blank(clipIndex)) {
2040 if (!trackPlaylist.is_blank(clipIndex)) {
2041 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2043 int position = trackPlaylist.clip_start(clipIndex);
2044 int blankDuration = trackPlaylist.clip_length(clipIndex);
2045 if (diff + blankDuration == 0) {
2046 trackPlaylist.remove(clipIndex);
2047 } else trackPlaylist.remove_region(position, - diff);
2049 trackPlaylist.consolidate_blanks(0);
2052 // now move transitions
2053 mlt_service serv = m_mltProducer->parent().get_service();
2054 mlt_service nextservice = mlt_service_get_producer(serv);
2055 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2056 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2057 QString resource = mlt_properties_get(properties, "mlt_service");
2059 while (mlt_type == "transition") {
2060 mlt_transition tr = (mlt_transition) nextservice;
2061 int currentIn = (int) mlt_transition_get_in(tr);
2062 int currentOut = (int) mlt_transition_get_out(tr);
2063 int currentTrack = mlt_transition_get_b_track(tr);
2064 insertPos = trackTransitionStartList.value(currentTrack);
2065 if (insertPos != -1) {
2066 insertPos += offset;
2067 if (currentOut > insertPos && resource != "mix") {
2068 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2071 nextservice = mlt_service_producer(nextservice);
2072 if (nextservice == NULL) break;
2073 properties = MLT_SERVICE_PROPERTIES(nextservice);
2074 mlt_type = mlt_properties_get(properties, "mlt_type");
2075 resource = mlt_properties_get(properties, "mlt_service");
2078 mlt_service_unlock(service.get_service());
2079 mltCheckLength(&tractor);
2080 m_mltConsumer->set("refresh", 1);
2084 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2086 if (source == dest) return;
2087 Mlt::Service sourceService(source->get_service());
2088 Mlt::Service destService(dest->get_service());
2090 // move all effects to the correct producer
2092 Mlt::Filter *filter = sourceService.filter(ct);
2094 if (filter->get_int("kdenlive_ix") != 0) {
2095 sourceService.detach(*filter);
2096 destService.attach(*filter);
2098 filter = sourceService.filter(ct);
2102 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2106 Mlt::Service service(m_mltProducer->parent().get_service());
2107 if (service.type() != tractor_type) {
2108 kWarning() << "// TRACTOR PROBLEM";
2111 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2112 Mlt::Tractor tractor(service);
2113 Mlt::Producer trackProducer(tractor.track(info.track));
2114 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2115 int startPos = info.startPos.frames(m_fps);
2116 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2117 int clipLength = trackPlaylist.clip_length(clipIndex);
2119 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2120 if (original == NULL) {
2123 if (!original->is_valid() || original->is_blank()) {
2128 Mlt::Producer clipparent = original->parent();
2129 if (!clipparent.is_valid() || clipparent.is_blank()) {
2135 QString serv = clipparent.get("mlt_service");
2136 QString id = clipparent.get("id");
2137 if (speed <= 0 && speed > -1) speed = 1.0;
2138 //kDebug() << "CLIP SERVICE: " << serv;
2139 if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
2140 mlt_service_lock(service.get_service());
2141 QString url = QString::fromUtf8(clipparent.get("resource"));
2142 url.append('?' + QString::number(speed));
2143 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2144 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2145 if (!slowprod || slowprod->get_producer() == NULL) {
2146 char *tmp = decodedString("framebuffer:" + url);
2147 slowprod = new Mlt::Producer(*m_mltProfile, 0, tmp);
2148 if (strobe > 1) slowprod->set("strobe", strobe);
2150 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2151 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2152 tmp = decodedString(producerid);
2153 slowprod->set("id", tmp);
2155 // copy producer props
2156 double ar = original->parent().get_double("force_aspect_ratio");
2157 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2158 double fps = original->parent().get_double("force_fps");
2159 if (fps != 0.0) slowprod->set("force_fps", fps);
2160 int threads = original->parent().get_int("threads");
2161 if (threads != 0) slowprod->set("threads", threads);
2162 if (original->parent().get("force_progressive"))
2163 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2164 int ix = original->parent().get_int("video_index");
2165 if (ix != 0) slowprod->set("video_index", ix);
2166 m_slowmotionProducers.insert(url, slowprod);
2168 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2169 trackPlaylist.consolidate_blanks(0);
2171 // Check that the blank space is long enough for our new duration
2172 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2173 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2175 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2176 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2177 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2178 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2180 // move all effects to the correct producer
2181 mltPasteEffects(clip, cut);
2182 trackPlaylist.insert_at(startPos, cut, 1);
2185 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2186 newLength = trackPlaylist.clip_length(clipIndex);
2187 mlt_service_unlock(service.get_service());
2188 } else if (speed == 1.0 && strobe < 2) {
2189 mlt_service_lock(service.get_service());
2191 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2192 trackPlaylist.consolidate_blanks(0);
2194 // Check that the blank space is long enough for our new duration
2195 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2196 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2199 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2200 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2201 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2202 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2203 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2205 // move all effects to the correct producer
2206 mltPasteEffects(clip, cut);
2208 trackPlaylist.insert_at(startPos, cut, 1);
2211 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2212 newLength = trackPlaylist.clip_length(clipIndex);
2213 mlt_service_unlock(service.get_service());
2215 } else if (serv == "framebuffer") {
2216 mlt_service_lock(service.get_service());
2217 QString url = QString::fromUtf8(clipparent.get("resource"));
2218 url = url.section('?', 0, 0);
2219 url.append('?' + QString::number(speed));
2220 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2221 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2222 if (!slowprod || slowprod->get_producer() == NULL) {
2223 char *tmp = decodedString("framebuffer:" + url);
2224 slowprod = new Mlt::Producer(*m_mltProfile, 0, tmp);
2226 slowprod->set("strobe", strobe);
2227 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2228 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2229 tmp = decodedString(producerid);
2230 slowprod->set("id", tmp);
2232 // copy producer props
2233 double ar = original->parent().get_double("force_aspect_ratio");
2234 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2235 double fps = original->parent().get_double("force_fps");
2236 if (fps != 0.0) slowprod->set("force_fps", fps);
2237 if (original->parent().get("force_progressive"))
2238 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2239 int threads = original->parent().get_int("threads");
2240 if (threads != 0) slowprod->set("threads", threads);
2241 int ix = original->parent().get_int("video_index");
2242 if (ix != 0) slowprod->set("video_index", ix);
2243 m_slowmotionProducers.insert(url, slowprod);
2245 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2246 trackPlaylist.consolidate_blanks(0);
2248 GenTime duration = speedIndependantInfo.cropDuration / speed;
2249 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2251 // Check that the blank space is long enough for our new duration
2252 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2253 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2256 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2257 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2258 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2259 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2261 // move all effects to the correct producer
2262 mltPasteEffects(clip, cut);
2264 trackPlaylist.insert_at(startPos, cut, 1);
2267 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2268 newLength = trackPlaylist.clip_length(clipIndex);
2270 mlt_service_unlock(service.get_service());
2273 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2274 m_isBlocked = false;
2278 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2280 Mlt::Service service(m_mltProducer->parent().get_service());
2281 bool success = false;
2282 Mlt::Tractor tractor(service);
2283 Mlt::Producer trackProducer(tractor.track(track));
2284 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2285 Mlt::Service clipService(trackPlaylist.get_service());
2288 mlt_service_lock(service.get_service());
2290 Mlt::Filter *filter = clipService.filter(ct);
2292 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2293 if (clipService.detach(*filter) == 0) success = true;
2294 } else if (updateIndex) {
2295 // Adjust the other effects index
2296 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2299 filter = clipService.filter(ct);
2301 m_isBlocked = false;
2302 mlt_service_unlock(service.get_service());
2307 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2309 if (position < GenTime()) {
2310 // Remove track effect
2311 return mltRemoveTrackEffect(track, index, updateIndex);
2313 Mlt::Service service(m_mltProducer->parent().get_service());
2314 bool success = false;
2315 Mlt::Tractor tractor(service);
2316 Mlt::Producer trackProducer(tractor.track(track));
2317 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2319 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2320 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2322 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2326 Mlt::Service clipService(clip->get_service());
2327 int duration = clip->get_playtime();
2329 // Check if clip is visible in monitor
2330 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2331 if (diff < 0 || diff > duration) doRefresh = false;
2335 // if (tag.startsWith("ladspa")) tag = "ladspa";
2337 mlt_service_lock(service.get_service());
2339 Mlt::Filter *filter = clipService.filter(ct);
2341 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2342 if (clipService.detach(*filter) == 0) success = true;
2343 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2344 } else if (updateIndex) {
2345 // Adjust the other effects index
2346 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2349 filter = clipService.filter(ct);
2351 m_isBlocked = false;
2352 mlt_service_unlock(service.get_service());
2353 if (doRefresh) refresh();
2357 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2359 Mlt::Service service(m_mltProducer->parent().get_service());
2360 Mlt::Tractor tractor(service);
2361 Mlt::Producer trackProducer(tractor.track(track));
2362 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2363 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2364 return mltAddEffect(trackService, params, 15000, true);
2368 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2371 Mlt::Service service(m_mltProducer->parent().get_service());
2373 Mlt::Tractor tractor(service);
2374 Mlt::Producer trackProducer(tractor.track(track));
2375 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2377 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2378 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2383 Mlt::Service clipService(clip->get_service());
2384 int duration = clip->get_playtime();
2386 // Check if clip is visible in monitor
2387 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2388 if (diff < 0 || diff > duration) doRefresh = false;
2391 return mltAddEffect(clipService, params, duration, doRefresh);
2394 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2396 bool updateIndex = false;
2397 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2398 const QString region = params.paramValue("region");
2401 mlt_service_lock(service.get_service());
2403 Mlt::Filter *filter = service.filter(ct);
2405 if (filter->get_int("kdenlive_ix") == filter_ix) {
2406 // A filter at that position already existed, so we will increase all indexes later
2411 filter = service.filter(ct);
2414 if (params.paramValue("id") == "speed") {
2415 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2417 filter = service.filter(ct);
2419 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2420 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2423 filter = service.filter(ct);
2425 m_isBlocked = false;
2426 mlt_service_unlock(service.get_service());
2427 if (doRefresh) refresh();
2432 // temporarily remove all effects after insert point
2433 QList <Mlt::Filter *> filtersList;
2435 filter = service.filter(ct);
2437 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2438 filtersList.append(filter);
2439 service.detach(*filter);
2441 filter = service.filter(ct);
2445 QString tag = params.paramValue("tag");
2446 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2447 if (tag.startsWith("ladspa")) tag = "ladspa";
2448 char *filterTag = decodedString(tag);
2449 char *filterId = decodedString(params.paramValue("id"));
2450 QHash<QString, QString>::Iterator it;
2451 QString kfr = params.paramValue("keyframes");
2453 if (!kfr.isEmpty()) {
2454 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2455 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2456 char *starttag = decodedString(params.paramValue("starttag", "start"));
2457 char *endtag = decodedString(params.paramValue("endtag", "end"));
2458 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2459 //double max = params.paramValue("max").toDouble();
2460 double min = params.paramValue("min").toDouble();
2461 double factor = params.paramValue("factor", "1").toDouble();
2462 params.removeParam("starttag");
2463 params.removeParam("endtag");
2464 params.removeParam("keyframes");
2465 params.removeParam("min");
2466 params.removeParam("max");
2467 params.removeParam("factor");
2469 // Special case, only one keyframe, means we want a constant value
2470 if (keyFrames.count() == 1) {
2471 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2472 if (filter && filter->is_valid()) {
2473 filter->set("kdenlive_id", filterId);
2474 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2475 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2476 for (int j = 0; j < params.count(); j++) {
2477 char *name = decodedString(params.at(j).name());
2478 char *value = decodedString(params.at(j).value());
2479 filter->set(name, value);
2483 filter->set("in", x1);
2484 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2485 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2486 service.attach(*filter);
2488 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2489 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2490 if (filter && filter->is_valid()) {
2491 filter->set("kdenlive_id", filterId);
2492 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2493 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2494 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2495 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2496 if (x2 == -1) x2 = duration;
2498 for (int j = 0; j < params.count(); j++) {
2499 char *name = decodedString(params.at(j).name());
2500 char *value = decodedString(params.at(j).value());
2501 filter->set(name, value);
2506 filter->set("in", x1);
2507 filter->set("out", x2);
2508 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2509 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2510 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2511 service.attach(*filter);
2518 Mlt::Filter *filter;
2520 if (!region.isEmpty()) {
2521 filter = new Mlt::Filter(*m_mltProfile, "region");
2522 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2523 if (filter && filter->is_valid()) {
2524 filter->set("kdenlive_id", filterId);
2525 if (!region.isEmpty()) {
2526 char *tmp = decodedString(region);
2527 filter->set("resource", tmp);
2528 tmp = decodedString(params.paramValue("kdenlive_ix"));
2529 filter->set("kdenlive_ix", tmp);
2530 filter->set("filter0", filterTag);
2531 prefix = "filter0.";
2533 params.removeParam("id");
2534 params.removeParam("region");
2535 params.removeParam("kdenlive_ix");
2538 kDebug() << "filter is NULL";
2539 m_isBlocked = false;
2540 mlt_service_unlock(service.get_service());
2543 params.removeParam("kdenlive_id");
2545 for (int j = 0; j < params.count(); j++) {
2546 char *name = decodedString(prefix + params.at(j).name());
2547 char *value = decodedString(params.at(j).value());
2548 filter->set(name, value);
2554 QString effectArgs = params.paramValue("id").section('_', 1);
2556 params.removeParam("id");
2557 params.removeParam("kdenlive_ix");
2558 params.removeParam("tag");
2559 params.removeParam("disable");
2560 params.removeParam("region");
2562 for (int j = 0; j < params.count(); j++) {
2563 effectArgs.append(' ' + params.at(j).value());
2565 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2566 char *value = decodedString(effectArgs.simplified());
2567 filter->set("effect", value);
2571 if (params.paramValue("id") == "pan_zoom") {
2572 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2575 // attach filter to the clip
2576 service.attach(*filter);
2581 // re-add following filters
2582 for (int i = 0; i < filtersList.count(); i++) {
2583 Mlt::Filter *filter = filtersList.at(i);
2585 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2586 service.attach(*filter);
2588 m_isBlocked = false;
2589 mlt_service_unlock(service.get_service());
2590 if (doRefresh) refresh();
2594 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2596 Mlt::Service service(m_mltProducer->parent().get_service());
2597 Mlt::Tractor tractor(service);
2598 Mlt::Producer trackProducer(tractor.track(track));
2599 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2600 Mlt::Service clipService(trackPlaylist.get_service());
2603 QString index = params.paramValue("kdenlive_ix");
2604 QString tag = params.paramValue("tag");
2606 Mlt::Filter *filter = clipService.filter(ct);
2608 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2612 filter = clipService.filter(ct);
2616 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2617 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2619 bool success = false;//mltAddTrackEffect(track, params);
2620 m_isBlocked = false;
2624 QString ser = filter->get("mlt_service");
2625 if (ser == "region") prefix = "filter0.";
2626 mlt_service_lock(service.get_service());
2627 for (int j = 0; j < params.count(); j++) {
2628 char *name = decodedString(prefix + params.at(j).name());
2629 char *value = decodedString(params.at(j).value());
2630 filter->set(name, value);
2634 mlt_service_unlock(service.get_service());
2636 m_isBlocked = false;
2642 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2644 QString index = params.paramValue("kdenlive_ix");
2645 QString tag = params.paramValue("tag");
2647 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2648 // This is a keyframe effect, to edit it, we remove it and re-add it.
2649 bool success = mltRemoveEffect(track, position, index, false);
2650 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2651 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2652 else success = mltAddEffect(track, position, params);
2653 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2656 if (position < GenTime()) {
2657 return mltEditTrackEffect(track, params);
2660 Mlt::Service service(m_mltProducer->parent().get_service());
2661 Mlt::Tractor tractor(service);
2662 Mlt::Producer trackProducer(tractor.track(track));
2663 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2665 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2666 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2668 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2672 Mlt::Service clipService(clip->get_service());
2673 int duration = clip->get_playtime();
2674 bool doRefresh = true;
2675 // Check if clip is visible in monitor
2676 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2677 if (diff < 0 || diff > duration) doRefresh = false;
2681 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2682 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2684 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2686 filter = clipService.filter(ct);
2688 kDebug() << "++++++++++++++++++++++++++";
2690 filter = clipService.filter(ct); */
2692 Mlt::Filter *filter = clipService.filter(ct);
2694 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2698 filter = clipService.filter(ct);
2702 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2703 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2705 bool success = mltAddEffect(track, position, params);
2706 m_isBlocked = false;
2710 QString ser = filter->get("mlt_service");
2711 if (ser == "region") prefix = "filter0.";
2712 mlt_service_lock(service.get_service());
2713 for (int j = 0; j < params.count(); j++) {
2714 char *name = decodedString(prefix + params.at(j).name());
2715 char *value = decodedString(params.at(j).value());
2716 filter->set(name, value);
2720 mlt_service_unlock(service.get_service());
2722 m_isBlocked = false;
2723 if (doRefresh) refresh();
2727 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2729 Mlt::Service service(m_mltProducer->parent().get_service());
2730 Mlt::Tractor tractor(service);
2731 Mlt::Producer trackProducer(tractor.track(track));
2732 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2734 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2735 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2737 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2741 Mlt::Service clipService(clip->get_service());
2742 int duration = clip->get_playtime();
2743 bool doRefresh = true;
2744 // Check if clip is visible in monitor
2745 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2746 if (diff < 0 || diff > duration) doRefresh = false;
2751 Mlt::Filter *filter = clipService.filter(ct);
2753 int pos = filter->get_int("kdenlive_ix");
2754 if (pos == oldPos) {
2755 filter->set("kdenlive_ix", newPos);
2757 filter = clipService.filter(ct);
2760 m_isBlocked = false;
2761 if (doRefresh) refresh();
2764 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2766 if (position < GenTime()) {
2767 mltMoveTrackEffect(track, oldPos, newPos);
2770 Mlt::Service service(m_mltProducer->parent().get_service());
2771 Mlt::Tractor tractor(service);
2772 Mlt::Producer trackProducer(tractor.track(track));
2773 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2775 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2776 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2778 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2782 Mlt::Service clipService(clip->get_service());
2783 int duration = clip->get_playtime();
2784 bool doRefresh = true;
2785 // Check if clip is visible in monitor
2786 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2787 if (diff < 0 || diff > duration) doRefresh = false;
2792 QList <Mlt::Filter *> filtersList;
2793 Mlt::Filter *filter = clipService.filter(ct);
2795 if (newPos > oldPos) {
2797 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2798 filter->set("kdenlive_ix", newPos);
2799 filtersList.append(filter);
2800 clipService.detach(*filter);
2801 filter = clipService.filter(ct);
2802 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2803 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2805 filter = clipService.filter(ct);
2809 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2810 filtersList.append(filter);
2811 clipService.detach(*filter);
2813 filter = clipService.filter(ct);
2817 if (filter->get_int("kdenlive_ix") == oldPos) {
2818 filter->set("kdenlive_ix", newPos);
2819 filtersList.append(filter);
2820 clipService.detach(*filter);
2822 filter = clipService.filter(ct);
2826 filter = clipService.filter(ct);
2828 int pos = filter->get_int("kdenlive_ix");
2829 if (pos >= newPos) {
2830 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2831 filtersList.append(filter);
2832 clipService.detach(*filter);
2834 filter = clipService.filter(ct);
2838 for (int i = 0; i < filtersList.count(); i++) {
2839 clipService.attach(*(filtersList.at(i)));
2842 m_isBlocked = false;
2843 if (doRefresh) refresh();
2846 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2848 Mlt::Service service(m_mltProducer->parent().get_service());
2849 Mlt::Tractor tractor(service);
2850 Mlt::Producer trackProducer(tractor.track(track));
2851 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2853 Mlt::Service clipService(trackPlaylist.get_service());
2857 QList <Mlt::Filter *> filtersList;
2858 Mlt::Filter *filter = clipService.filter(ct);
2860 if (newPos > oldPos) {
2862 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2863 filter->set("kdenlive_ix", newPos);
2864 filtersList.append(filter);
2865 clipService.detach(*filter);
2866 filter = clipService.filter(ct);
2867 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2868 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2870 filter = clipService.filter(ct);
2874 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2875 filtersList.append(filter);
2876 clipService.detach(*filter);
2878 filter = clipService.filter(ct);
2882 if (filter->get_int("kdenlive_ix") == oldPos) {
2883 filter->set("kdenlive_ix", newPos);
2884 filtersList.append(filter);
2885 clipService.detach(*filter);
2887 filter = clipService.filter(ct);
2891 filter = clipService.filter(ct);
2893 int pos = filter->get_int("kdenlive_ix");
2894 if (pos >= newPos) {
2895 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2896 filtersList.append(filter);
2897 clipService.detach(*filter);
2899 filter = clipService.filter(ct);
2903 for (int i = 0; i < filtersList.count(); i++) {
2904 clipService.attach(*(filtersList.at(i)));
2906 m_isBlocked = false;
2910 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2913 Mlt::Service service(m_mltProducer->parent().get_service());
2914 Mlt::Tractor tractor(service);
2915 Mlt::Producer trackProducer(tractor.track(info.track));
2916 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2918 /* // Display playlist info
2919 kDebug()<<"//////////// BEFORE RESIZE";
2920 for (int i = 0; i < trackPlaylist.count(); i++) {
2921 int blankStart = trackPlaylist.clip_start(i);
2922 int blankDuration = trackPlaylist.clip_length(i) - 1;
2924 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2925 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2928 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2929 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2930 m_isBlocked = false;
2933 mlt_service_lock(service.get_service());
2934 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2935 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2936 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2937 int previousStart = clip->get_in();
2938 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2939 int currentOut = (int)(info.cropStart + info.cropDuration).frames(m_fps) - 1;
2940 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2941 if (currentOut > clip->get_length()) {
2942 clip->parent().set("length", currentOut + 1);
2943 clip->parent().set("out", currentOut);
2944 clip->set("length", currentOut + 1);
2946 /*if (newDuration > clip->get_out()) {
2947 clip->parent().set_in_and_out(0, newDuration + 1);
2948 clip->set_in_and_out(0, newDuration + 1);
2951 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2952 trackPlaylist.consolidate_blanks(0);
2953 // skip to next clip
2955 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2957 // clip was made longer, trim next blank if there is one.
2958 if (clipIndex < trackPlaylist.count()) {
2959 // If this is not the last clip in playlist
2960 if (trackPlaylist.is_blank(clipIndex)) {
2961 int blankStart = trackPlaylist.clip_start(clipIndex);
2962 int blankDuration = trackPlaylist.clip_length(clipIndex);
2963 if (diff > blankDuration) {
2964 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2966 if (diff - blankDuration == 0) {
2967 trackPlaylist.remove(clipIndex);
2968 } else trackPlaylist.remove_region(blankStart, diff);
2970 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2973 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2974 trackPlaylist.consolidate_blanks(0);
2975 mlt_service_unlock(service.get_service());
2977 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2978 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2979 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2980 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2981 ItemInfo transpinfo;
2982 transpinfo.startPos = info.startPos;
2983 transpinfo.endPos = info.startPos + clipDuration;
2984 transpinfo.track = info.track;
2985 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2987 m_isBlocked = false;
2988 m_mltConsumer->set("refresh", 1);
2992 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2994 Mlt::Service service(m_mltProducer->parent().get_service());
2995 Mlt::Tractor tractor(service);
2996 Mlt::Producer trackProducer(tractor.track(track));
2999 if (blind) trackProducer.set("hide", 3);
3000 else trackProducer.set("hide", 2);
3002 trackProducer.set("hide", 1);
3004 trackProducer.set("hide", 0);
3006 tractor.multitrack()->refresh();
3012 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
3014 Mlt::Service service(m_mltProducer->parent().get_service());
3015 int frameOffset = (int) diff.frames(m_fps);
3016 Mlt::Tractor tractor(service);
3017 Mlt::Producer trackProducer(tractor.track(info.track));
3018 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3019 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3020 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3023 mlt_service_lock(service.get_service());
3024 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3025 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3027 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3028 mlt_service_unlock(service.get_service());
3031 int previousStart = clip->get_in();
3032 int previousOut = clip->get_out();
3035 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
3036 m_isBlocked = false;
3037 mlt_service_unlock(service.get_service());
3038 m_mltConsumer->set("refresh", 1);
3042 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3044 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3045 Mlt::Service service(m_mltProducer->parent().get_service());
3046 int moveFrame = (int) diff.frames(m_fps);
3047 Mlt::Tractor tractor(service);
3048 Mlt::Producer trackProducer(tractor.track(info.track));
3049 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3050 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3051 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3054 mlt_service_lock(service.get_service());
3055 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3056 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3057 if (clip == NULL || clip->is_blank()) {
3058 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3059 mlt_service_unlock(service.get_service());
3062 int previousStart = clip->get_in();
3063 int previousOut = clip->get_out();
3066 previousStart += moveFrame;
3067 if (previousStart < 0) {
3068 // special case, in point becoming negative (resizing images)
3069 previousOut -= previousStart;
3072 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3073 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3074 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3076 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3077 int blankIndex = clipIndex - 1;
3078 int blankLength = trackPlaylist.clip_length(blankIndex);
3079 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3080 if (! trackPlaylist.is_blank(blankIndex)) {
3081 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3083 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
3084 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3086 trackPlaylist.consolidate_blanks(0);
3087 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3088 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3089 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3090 ItemInfo transpinfo;
3091 transpinfo.startPos = info.startPos + diff;
3092 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3093 transpinfo.track = info.track;
3094 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3096 m_isBlocked = false;
3097 //m_mltConsumer->set("refresh", 1);
3098 mlt_service_unlock(service.get_service());
3099 m_mltConsumer->set("refresh", 1);
3103 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3105 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3109 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3111 if (prod == NULL || !prod->is_valid()) {
3112 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3115 kDebug() << "NEW PROD ID: " << prod->get("id");
3117 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3118 Mlt::Service service(m_mltProducer->parent().get_service());
3119 if (service.type() != tractor_type) {
3120 kWarning() << "// TRACTOR PROBLEM";
3123 mlt_service_lock(service.get_service());
3124 Mlt::Tractor tractor(service);
3125 Mlt::Producer trackProducer(tractor.track(track));
3126 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3127 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3128 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3129 if (clipProducer == NULL || clipProducer->is_blank()) {
3130 kDebug() << "// ERROR UPDATING CLIP PROD";
3131 delete clipProducer;
3132 mlt_service_unlock(service.get_service());
3136 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3137 if (!clip || !clip->is_valid()) {
3138 if (clip) delete clip;
3139 delete clipProducer;
3140 mlt_service_unlock(service.get_service());
3144 // move all effects to the correct producer
3145 mltPasteEffects(clipProducer, clip);
3146 trackPlaylist.insert_at(pos, clip, 1);
3148 delete clipProducer;
3149 mlt_service_unlock(service.get_service());
3154 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3158 Mlt::Service service(m_mltProducer->parent().get_service());
3159 if (service.type() != tractor_type) {
3160 kWarning() << "// TRACTOR PROBLEM";
3164 Mlt::Tractor tractor(service);
3165 mlt_service_lock(service.get_service());
3166 Mlt::Producer trackProducer(tractor.track(startTrack));
3167 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3168 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3169 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3170 bool checkLength = false;
3171 if (endTrack == startTrack) {
3172 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3173 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3174 // error, destination is not empty
3176 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3177 delete clipProducer;
3179 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3180 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3181 mlt_service_unlock(service.get_service());
3185 trackPlaylist.consolidate_blanks(0);
3187 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3188 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3189 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3191 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3192 trackPlaylist.consolidate_blanks(1);
3193 delete clipProducer;
3194 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3195 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3197 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3199 //mlt_service_unlock(service.get_service());
3201 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3202 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3203 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3204 // error, destination is not empty
3205 mlt_service_unlock(service.get_service());
3209 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3210 if (!clipProducer || clipProducer->is_blank()) {
3211 // error, destination is not empty
3212 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3213 if (clipProducer) delete clipProducer;
3214 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3215 mlt_service_unlock(service.get_service());
3219 trackPlaylist.consolidate_blanks(0);
3220 destTrackPlaylist.consolidate_blanks(1);
3221 Mlt::Producer *clip;
3222 // check if we are moving a slowmotion producer
3223 QString serv = clipProducer->parent().get("mlt_service");
3224 QString currentid = clipProducer->parent().get("id");
3225 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3226 clip = clipProducer;
3229 // Special case: prod is null when using placeholder clips.
3230 // in that case, use the producer existing in playlist. Note that
3231 // it will bypass the one producer per track logic and might cause
3232 // Sound cracks if clip is moved so that it overlaps another copy of itself
3233 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3234 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3237 // move all effects to the correct producer
3238 mltPasteEffects(clipProducer, clip);
3241 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3242 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3243 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3246 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3248 if (clip == clipProducer) {
3253 delete clipProducer;
3255 destTrackPlaylist.consolidate_blanks(0);
3256 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3257 kDebug() << "//////// moving clip transparency";
3258 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3260 if (clipIndex > trackPlaylist.count()) checkLength = true;
3261 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3264 mlt_service_unlock(service.get_service());
3265 if (checkLength) mltCheckLength(&tractor);
3268 //m_mltConsumer->set("refresh", 1);
3273 QList <int> Render::checkTrackSequence(int track)
3276 Mlt::Service service(m_mltProducer->parent().get_service());
3277 if (service.type() != tractor_type) {
3278 kWarning() << "// TRACTOR PROBLEM";
3281 Mlt::Tractor tractor(service);
3282 mlt_service_lock(service.get_service());
3283 Mlt::Producer trackProducer(tractor.track(track));
3284 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3285 int clipNb = trackPlaylist.count();
3286 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3287 for (int i = 0; i < clipNb; i++) {
3288 Mlt::Producer *c = trackPlaylist.get_clip(i);
3289 int pos = trackPlaylist.clip_start(i);
3290 if (!list.contains(pos)) list.append(pos);
3291 pos += c->get_playtime();
3292 if (!list.contains(pos)) list.append(pos);
3298 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3300 int new_in = (int)newIn.frames(m_fps);
3301 int new_out = (int)newOut.frames(m_fps) - 1;
3302 if (new_in >= new_out) return false;
3303 int old_in = (int)oldIn.frames(m_fps);
3304 int old_out = (int)oldOut.frames(m_fps) - 1;
3306 Mlt::Service service(m_mltProducer->parent().get_service());
3307 Mlt::Tractor tractor(service);
3308 Mlt::Field *field = tractor.field();
3310 bool doRefresh = true;
3311 // Check if clip is visible in monitor
3312 int diff = old_out - m_mltProducer->position();
3313 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3315 diff = new_out - m_mltProducer->position();
3316 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3320 mlt_service_lock(service.get_service());
3322 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3323 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3324 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3325 QString resource = mlt_properties_get(properties, "mlt_service");
3326 int old_pos = (int)(old_in + old_out) / 2;
3329 while (mlt_type == "transition") {
3330 Mlt::Transition transition((mlt_transition) nextservice);
3331 int currentTrack = transition.get_b_track();
3332 int currentIn = (int) transition.get_in();
3333 int currentOut = (int) transition.get_out();
3335 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3337 if (newTrack - startTrack != 0) {
3338 Mlt::Properties trans_props(transition.get_properties());
3339 char *tmp = decodedString(transition.get("mlt_service"));
3340 Mlt::Transition new_transition(*m_mltProfile, tmp);
3342 Mlt::Properties new_trans_props(new_transition.get_properties());
3343 new_trans_props.inherit(trans_props);
3344 new_transition.set_in_and_out(new_in, new_out);
3345 field->disconnect_service(transition);
3346 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3347 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3348 } else transition.set_in_and_out(new_in, new_out);
3351 nextservice = mlt_service_producer(nextservice);
3352 if (nextservice == NULL) break;
3353 properties = MLT_SERVICE_PROPERTIES(nextservice);
3354 mlt_type = mlt_properties_get(properties, "mlt_type");
3355 resource = mlt_properties_get(properties, "mlt_service");
3357 mlt_service_unlock(service.get_service());
3359 if (doRefresh) refresh();
3360 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3365 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3367 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3368 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3369 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3370 QString resource = mlt_properties_get(properties, "mlt_service");
3371 QList <Mlt::Transition *> trList;
3373 while (mlt_type == "transition") {
3374 Mlt::Transition transition((mlt_transition) nextservice);
3375 int aTrack = transition.get_a_track();
3376 int bTrack = transition.get_b_track();
3377 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3378 Mlt::Properties trans_props(transition.get_properties());
3379 char *tmp = decodedString(transition.get("mlt_service"));
3380 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, tmp);
3382 Mlt::Properties new_trans_props(cp->get_properties());
3383 new_trans_props.inherit(trans_props);
3385 field->disconnect_service(transition);
3387 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3389 nextservice = mlt_service_producer(nextservice);
3390 if (nextservice == NULL) break;
3391 properties = MLT_SERVICE_PROPERTIES(nextservice);
3392 mlt_type = mlt_properties_get(properties, "mlt_type");
3393 resource = mlt_properties_get(properties, "mlt_service");
3396 field->plant_transition(tr, a_track, b_track);
3398 // re-add upper transitions
3399 for (int i = 0; i < trList.count(); i++) {
3400 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3401 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3405 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3407 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3409 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3410 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3413 if (m_mltProducer->position() > in.frames(m_fps) && m_mltProducer->position() < out.frames(m_fps)) refresh();
3416 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3418 mlt_service serv = m_mltProducer->parent().get_service();
3419 mlt_service_lock(serv);
3422 mlt_service nextservice = mlt_service_get_producer(serv);
3423 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3424 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3425 QString resource = mlt_properties_get(properties, "mlt_service");
3426 int in_pos = (int) in.frames(m_fps);
3427 int out_pos = (int) out.frames(m_fps) - 1;
3429 while (mlt_type == "transition") {
3430 mlt_transition tr = (mlt_transition) nextservice;
3431 int currentTrack = mlt_transition_get_b_track(tr);
3432 int currentBTrack = mlt_transition_get_a_track(tr);
3433 int currentIn = (int) mlt_transition_get_in(tr);
3434 int currentOut = (int) mlt_transition_get_out(tr);
3436 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3438 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3439 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3440 QMap<QString, QString>::Iterator it;
3442 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3444 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3445 if (currentId != xml.attribute("id")) {
3446 // The transition ID is not the same, so reset all properties
3447 char *tmp = decodedString(xml.attribute("id"));
3448 mlt_properties_set(transproperties, "kdenlive_id", tmp);
3450 // Cleanup previous properties
3451 QStringList permanentProps;
3452 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3453 permanentProps << "out" << "a_track" << "b_track";
3454 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3455 QString propName = mlt_properties_get_name(transproperties, i);
3456 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3457 tmp = decodedString(propName);
3458 mlt_properties_set(transproperties, tmp, "");
3464 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3465 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3467 if (currentBTrack != a_track) {
3468 mlt_properties_set_int(transproperties, "a_track", a_track);
3470 for (it = map.begin(); it != map.end(); ++it) {
3472 char *name = decodedString(key);
3473 char *value = decodedString(it.value());
3474 mlt_properties_set(transproperties, name, value);
3475 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
3476 //filter->set("kdenlive_id", id);
3482 nextservice = mlt_service_producer(nextservice);
3483 if (nextservice == NULL) break;
3484 properties = MLT_SERVICE_PROPERTIES(nextservice);
3485 mlt_type = mlt_properties_get(properties, "mlt_type");
3486 resource = mlt_properties_get(properties, "mlt_service");
3488 mlt_service_unlock(serv);
3491 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3494 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3496 mlt_service serv = m_mltProducer->parent().get_service();
3498 mlt_service_lock(serv);
3500 Mlt::Service service(serv);
3501 Mlt::Tractor tractor(service);
3502 Mlt::Field *field = tractor.field();
3504 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3506 mlt_service nextservice = mlt_service_get_producer(serv);
3507 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3508 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3509 QString resource = mlt_properties_get(properties, "mlt_service");
3511 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3512 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3514 while (mlt_type == "transition") {
3515 mlt_transition tr = (mlt_transition) nextservice;
3516 int currentTrack = mlt_transition_get_b_track(tr);
3517 int currentIn = (int) mlt_transition_get_in(tr);
3518 int currentOut = (int) mlt_transition_get_out(tr);
3519 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3521 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3522 mlt_field_disconnect_service(field->get_field(), nextservice);
3525 nextservice = mlt_service_producer(nextservice);
3526 if (nextservice == NULL) break;
3527 properties = MLT_SERVICE_PROPERTIES(nextservice);
3528 mlt_type = mlt_properties_get(properties, "mlt_type");
3529 resource = mlt_properties_get(properties, "mlt_service");
3531 mlt_service_unlock(serv);
3534 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3537 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3539 QDomNodeList attribs = xml.elementsByTagName("parameter");
3540 QMap<QString, QString> map;
3541 for (int i = 0; i < attribs.count(); i++) {
3542 QDomElement e = attribs.item(i).toElement();
3543 QString name = e.attribute("name");
3544 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3545 map[name] = e.attribute("default");
3546 if (!e.attribute("value").isEmpty()) {
3547 map[name] = e.attribute("value");
3549 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3550 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3551 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3554 if (e.attribute("namedesc").contains(';')) {
3555 QString format = e.attribute("format");
3556 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3557 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3559 QTextStream txtNeu(&neu);
3560 if (values.size() > 0)
3561 txtNeu << (int)values[0].toDouble();
3563 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3564 txtNeu << separators[i];
3565 txtNeu << (int)(values[i+1].toDouble());
3567 if (i < separators.size())
3568 txtNeu << separators[i];
3569 map[e.attribute("name")] = neu;
3576 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3578 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3579 Mlt::Service service(m_mltProducer->parent().get_service());
3580 Mlt::Tractor tractor(service);
3581 Mlt::Field *field = tractor.field();
3583 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3584 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3585 transition->set("transparency", id);
3586 transition->set("fill", 1);
3587 transition->set("internal_added", 237);
3588 field->plant_transition(*transition, transitiontrack, info.track);
3592 void Render::mltDeleteTransparency(int pos, int track, int id)
3594 Mlt::Service service(m_mltProducer->parent().get_service());
3595 Mlt::Tractor tractor(service);
3596 Mlt::Field *field = tractor.field();
3598 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3599 mlt_service serv = m_mltProducer->parent().get_service();
3601 mlt_service nextservice = mlt_service_get_producer(serv);
3602 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3603 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3604 QString resource = mlt_properties_get(properties, "mlt_service");
3606 while (mlt_type == "transition") {
3607 mlt_transition tr = (mlt_transition) nextservice;
3608 int currentTrack = mlt_transition_get_b_track(tr);
3609 int currentIn = (int) mlt_transition_get_in(tr);
3610 int currentOut = (int) mlt_transition_get_out(tr);
3611 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3612 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3614 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3615 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3616 mlt_field_disconnect_service(field->get_field(), nextservice);
3619 nextservice = mlt_service_producer(nextservice);
3620 if (nextservice == NULL) break;
3621 properties = MLT_SERVICE_PROPERTIES(nextservice);
3622 mlt_type = mlt_properties_get(properties, "mlt_type");
3623 resource = mlt_properties_get(properties, "mlt_service");
3625 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3628 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3630 Mlt::Service service(m_mltProducer->parent().get_service());
3631 Mlt::Tractor tractor(service);
3633 mlt_service_lock(service.get_service());
3634 m_mltConsumer->set("refresh", 0);
3637 mlt_service serv = m_mltProducer->parent().get_service();
3638 mlt_service nextservice = mlt_service_get_producer(serv);
3639 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3640 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3641 QString resource = mlt_properties_get(properties, "mlt_service");
3642 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3643 while (mlt_type == "transition") {
3644 mlt_transition tr = (mlt_transition) nextservice;
3645 int currentTrack = mlt_transition_get_b_track(tr);
3646 int currentIn = (int) mlt_transition_get_in(tr);
3647 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3648 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3649 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3650 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3651 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3652 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3655 nextservice = mlt_service_producer(nextservice);
3656 if (nextservice == NULL) break;
3657 properties = MLT_SERVICE_PROPERTIES(nextservice);
3658 mlt_type = mlt_properties_get(properties, "mlt_type");
3659 resource = mlt_properties_get(properties, "mlt_service");
3661 mlt_service_unlock(service.get_service());
3663 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3667 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3669 Mlt::Service service(m_mltProducer->parent().get_service());
3670 Mlt::Tractor tractor(service);
3672 mlt_service_lock(service.get_service());
3673 m_mltConsumer->set("refresh", 0);
3676 mlt_service serv = m_mltProducer->parent().get_service();
3677 mlt_service nextservice = mlt_service_get_producer(serv);
3678 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3679 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3680 QString resource = mlt_properties_get(properties, "mlt_service");
3682 while (mlt_type == "transition") {
3683 mlt_transition tr = (mlt_transition) nextservice;
3684 int currentTrack = mlt_transition_get_b_track(tr);
3685 int currentaTrack = mlt_transition_get_a_track(tr);
3686 int currentIn = (int) mlt_transition_get_in(tr);
3687 int currentOut = (int) mlt_transition_get_out(tr);
3688 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3689 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3690 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3691 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3692 kDebug() << "//////MOVING";
3693 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3694 if (endTrack != startTrack) {
3695 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3696 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3697 mlt_properties_set_int(properties, "b_track", endTrack);
3701 nextservice = mlt_service_producer(nextservice);
3702 if (nextservice == NULL) break;
3703 properties = MLT_SERVICE_PROPERTIES(nextservice);
3704 mlt_type = mlt_properties_get(properties, "mlt_type");
3705 resource = mlt_properties_get(properties, "mlt_service");
3708 mlt_service_unlock(service.get_service());
3709 m_mltConsumer->set("refresh", 1);
3713 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3715 if (in >= out) return false;
3716 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3717 Mlt::Service service(m_mltProducer->parent().get_service());
3719 Mlt::Tractor tractor(service);
3720 Mlt::Field *field = tractor.field();
3722 char *transId = decodedString(tag);
3723 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
3724 if (out != GenTime())
3725 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3727 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3728 QMap<QString, QString>::Iterator it;
3730 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3731 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3732 if (xml.hasAttribute("id"))
3733 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3735 for (it = args.begin(); it != args.end(); ++it) {
3737 char *name = decodedString(key);
3738 char *value = decodedString(it.value());
3739 if (it.value().isEmpty() == false) transition->set(name, value);
3740 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
3744 // attach transition
3745 mltPlantTransition(field, *transition, a_track, b_track);
3746 // field->plant_transition(*transition, a_track, b_track);
3748 if (do_refresh) refresh();
3752 void Render::mltSavePlaylist()
3754 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3755 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3756 fileConsumer.set("resource", "/tmp/playlist.mlt");
3758 Mlt::Service service(m_mltProducer->get_service());
3760 fileConsumer.connect(service);
3761 fileConsumer.start();
3764 const QList <Mlt::Producer *> Render::producersList()
3766 QList <Mlt::Producer *> prods;
3767 if (m_mltProducer == NULL) return prods;
3768 Mlt::Service service(m_mltProducer->parent().get_service());
3769 if (service.type() != tractor_type) return prods;
3770 Mlt::Tractor tractor(service);
3773 int trackNb = tractor.count();
3774 for (int t = 1; t < trackNb; t++) {
3775 Mlt::Producer *tt = tractor.track(t);
3776 Mlt::Producer trackProducer(tt);
3778 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3779 int clipNb = trackPlaylist.count();
3780 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3781 for (int i = 0; i < clipNb; i++) {
3782 Mlt::Producer *c = trackPlaylist.get_clip(i);
3783 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3785 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3786 ids.append(nprod->get("id"));
3787 prods.append(nprod);
3788 } else delete nprod;
3796 void Render::fillSlowMotionProducers()
3798 if (m_mltProducer == NULL) return;
3799 Mlt::Service service(m_mltProducer->parent().get_service());
3800 if (service.type() != tractor_type) return;
3802 Mlt::Tractor tractor(service);
3804 int trackNb = tractor.count();
3805 for (int t = 1; t < trackNb; t++) {
3806 Mlt::Producer *tt = tractor.track(t);
3807 Mlt::Producer trackProducer(tt);
3809 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3810 int clipNb = trackPlaylist.count();
3811 for (int i = 0; i < clipNb; i++) {
3812 Mlt::Producer *c = trackPlaylist.get_clip(i);
3813 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3815 QString id = nprod->get("id");
3816 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3817 // this is a slowmotion producer, add it to the list
3818 QString url = QString::fromUtf8(nprod->get("resource"));
3819 int strobe = nprod->get_int("strobe");
3820 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3821 if (!m_slowmotionProducers.contains(url)) {
3822 m_slowmotionProducers.insert(url, nprod);
3824 } else delete nprod;
3831 void Render::mltInsertTrack(int ix, bool videoTrack)
3836 Mlt::Service service(m_mltProducer->parent().get_service());
3837 mlt_service_lock(service.get_service());
3838 if (service.type() != tractor_type) {
3839 kWarning() << "// TRACTOR PROBLEM";
3843 Mlt::Tractor tractor(service);
3845 Mlt::Playlist playlist;
3846 int ct = tractor.count();
3848 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3854 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3855 tractor.set_track(playlist, pos);
3856 Mlt::Producer newProd(tractor.track(pos));
3857 if (!videoTrack) newProd.set("hide", 1);
3859 for (; pos <= ct; pos++) {
3860 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3861 tractor.set_track(*prodToMove, pos);
3862 prodToMove = prodToMove2;
3865 tractor.set_track(playlist, ix);
3866 Mlt::Producer newProd(tractor.track(ix));
3867 if (!videoTrack) newProd.set("hide", 1);
3871 mlt_service serv = m_mltProducer->parent().get_service();
3872 mlt_service nextservice = mlt_service_get_producer(serv);
3873 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3874 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3875 QString resource = mlt_properties_get(properties, "mlt_service");
3877 while (mlt_type == "transition") {
3878 if (resource != "mix") {
3879 mlt_transition tr = (mlt_transition) nextservice;
3880 int currentTrack = mlt_transition_get_b_track(tr);
3881 int currentaTrack = mlt_transition_get_a_track(tr);
3882 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3884 if (currentTrack >= ix) {
3885 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3886 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3889 nextservice = mlt_service_producer(nextservice);
3890 if (nextservice == NULL) break;
3891 properties = MLT_SERVICE_PROPERTIES(nextservice);
3892 mlt_type = mlt_properties_get(properties, "mlt_type");
3893 resource = mlt_properties_get(properties, "mlt_service");
3896 // Add audio mix transition to last track
3897 Mlt::Field *field = tractor.field();
3898 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3899 transition->set("a_track", 1);
3900 transition->set("b_track", ct);
3901 transition->set("always_active", 1);
3902 transition->set("internal_added", 237);
3903 transition->set("combine", 1);
3904 field->plant_transition(*transition, 1, ct);
3905 //mlt_service_unlock(m_mltConsumer->get_service());
3906 mlt_service_unlock(service.get_service());
3907 //tractor.multitrack()->refresh();
3908 //tractor.refresh();
3910 blockSignals(false);
3914 void Render::mltDeleteTrack(int ix)
3917 doc.setContent(sceneList(), false);
3918 int tracksCount = doc.elementsByTagName("track").count() - 1;
3919 QDomNode track = doc.elementsByTagName("track").at(ix);
3920 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3921 QDomNodeList transitions = doc.elementsByTagName("transition");
3922 for (int i = 0; i < transitions.count(); i++) {
3923 QDomElement e = transitions.at(i).toElement();
3924 QDomNodeList props = e.elementsByTagName("property");
3925 QMap <QString, QString> mappedProps;
3926 for (int j = 0; j < props.count(); j++) {
3927 QDomElement f = props.at(j).toElement();
3928 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3930 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3931 tractor.removeChild(transitions.at(i));
3933 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3934 // Transition needs to be moved
3935 int a_track = mappedProps.value("a_track").toInt();
3936 int b_track = mappedProps.value("b_track").toInt();
3937 if (a_track > 0 && a_track >= ix) a_track --;
3938 if (b_track == ix) {
3939 // transition was on the deleted track, so remove it
3940 tractor.removeChild(transitions.at(i));
3944 if (b_track > 0 && b_track > ix) b_track --;
3945 for (int j = 0; j < props.count(); j++) {
3946 QDomElement f = props.at(j).toElement();
3947 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3948 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3953 tractor.removeChild(track);
3954 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3955 setSceneList(doc.toString(), m_framePosition);
3957 /* if (m_mltProducer != NULL) {
3958 Mlt::Producer parentProd(m_mltProducer->parent());
3959 if (parentProd.get_producer() != NULL) {
3960 Mlt::Service service(parentProd.get_service());
3961 if (service.type() == tractor_type) {
3962 Mlt::Tractor tractor(service);
3963 mltCheckLength(&tractor);
3970 void Render::updatePreviewSettings()
3972 kDebug() << "////// RESTARTING CONSUMER";
3973 if (!m_mltConsumer || !m_mltProducer) return;
3974 if (m_mltProducer->get_playtime() == 0) return;
3975 Mlt::Service service(m_mltProducer->parent().get_service());
3976 if (service.type() != tractor_type) return;
3978 //m_mltConsumer->set("refresh", 0);
3979 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3980 m_mltConsumer->purge();
3981 QString scene = sceneList();
3983 if (m_mltProducer) {
3984 pos = m_mltProducer->position();
3987 setSceneList(scene, pos);
3991 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3993 // Update all frame positions to the new fps value
3994 //WARNING: there are probably some effects or other that hold a frame value
3995 // as parameter and will also need to be updated here!
3997 doc.setContent(scene);
3999 double factor = new_fps / current_fps;
4000 QDomNodeList producers = doc.elementsByTagName("producer");
4001 for (int i = 0; i < producers.count(); i++) {
4002 QDomElement prod = producers.at(i).toElement();
4003 prod.removeAttribute("in");
4004 prod.removeAttribute("out");
4006 QDomNodeList props = prod.childNodes();
4007 for (int j = 0; j < props.count(); j++) {
4008 QDomElement param = props.at(j).toElement();
4009 QString paramName = param.attribute("name");
4010 if (paramName.startsWith("meta.") || paramName == "length") {
4011 prod.removeChild(props.at(j));
4017 QDomNodeList entries = doc.elementsByTagName("entry");
4018 for (int i = 0; i < entries.count(); i++) {
4019 QDomElement entry = entries.at(i).toElement();
4020 int in = entry.attribute("in").toInt();
4021 int out = entry.attribute("out").toInt();
4022 in = factor * in + 0.5;
4023 out = factor * out + 0.5;
4024 entry.setAttribute("in", in);
4025 entry.setAttribute("out", out);
4028 QDomNodeList blanks = doc.elementsByTagName("blank");
4029 for (int i = 0; i < blanks.count(); i++) {
4030 QDomElement blank = blanks.at(i).toElement();
4031 int length = blank.attribute("length").toInt();
4032 length = factor * length + 0.5;
4033 blank.setAttribute("length", QString::number(length));
4036 QDomNodeList filters = doc.elementsByTagName("filter");
4037 for (int i = 0; i < filters.count(); i++) {
4038 QDomElement filter = filters.at(i).toElement();
4039 int in = filter.attribute("in").toInt();
4040 int out = filter.attribute("out").toInt();
4041 in = factor * in + 0.5;
4042 out = factor * out + 0.5;
4043 filter.setAttribute("in", in);
4044 filter.setAttribute("out", out);
4047 QDomNodeList transitions = doc.elementsByTagName("transition");
4048 for (int i = 0; i < transitions.count(); i++) {
4049 QDomElement transition = transitions.at(i).toElement();
4050 int in = transition.attribute("in").toInt();
4051 int out = transition.attribute("out").toInt();
4052 in = factor * in + 0.5;
4053 out = factor * out + 0.5;
4054 transition.setAttribute("in", in);
4055 transition.setAttribute("out", out);
4056 QDomNodeList props = transition.childNodes();
4057 for (int j = 0; j < props.count(); j++) {
4058 QDomElement param = props.at(j).toElement();
4059 QString paramName = param.attribute("name");
4060 if (paramName == "geometry") {
4061 QString geom = param.firstChild().nodeValue();
4062 QStringList keys = geom.split(';');
4063 QStringList newKeys;
4064 for (int k = 0; k < keys.size(); ++k) {
4065 if (keys.at(k).contains('=')) {
4066 int pos = keys.at(k).section('=', 0, 0).toInt();
4067 pos = factor * pos + 0.5;
4068 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4069 } else newKeys.append(keys.at(k));
4071 param.firstChild().setNodeValue(newKeys.join(";"));
4075 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
4076 int out = tractor.attribute("out").toInt();
4077 out = factor * out + 0.5;
4078 tractor.setAttribute("out", out);
4079 emit durationChanged(out);
4081 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4082 return doc.toString();
4085 #include "renderer.moc"