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"
31 #include "profilesdialog.h"
33 #include <mlt++/Mlt.h>
36 #include <KStandardDirs>
37 #include <KMessageBox>
39 #include <KTemporaryFile>
44 #include <QApplication>
45 #include <QtConcurrentRun>
52 #define SEEK_INACTIVE (-1)
54 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
56 if (level > MLT_LOG_ERROR) return;
57 //kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified();
59 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
65 void Render::consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
67 // detect if the producer has finished playing. Is there a better way to do it?
68 self->emitFrameNumber();
69 Mlt::Frame frame(frame_ptr);
70 if (!frame.is_valid()) return;
71 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
72 self->emitFrameUpdated(frame);
74 if (self->analyseAudio) {
75 self->showAudio(frame);
77 if (frame.get_double("_speed") == 0) self->emitConsumerStopped();
78 else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
80 self->emitConsumerStopped(true);
85 static void consumer_paused(mlt_consumer, Render * self, mlt_frame frame_ptr)
87 // detect if the producer has finished playing. Is there a better way to do it?
88 Mlt::Frame frame(frame_ptr);
89 if (!frame.is_valid()) return;
90 if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
92 self->emitConsumerStopped(true);
94 else self->emitConsumerStopped();
98 void Render::consumer_gl_frame_show(mlt_consumer consumer, Render * self, mlt_frame frame_ptr)
100 // detect if the producer has finished playing. Is there a better way to do it?
101 if (self->externalConsumer && !self->analyseAudio && !self->sendFrameForAnalysis) {
102 emit self->rendererPosition((int) mlt_consumer_position(consumer));
105 Mlt::Frame frame(frame_ptr);
106 if (frame.get_double("_speed") == 0) self->emitConsumerStopped();
107 else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
109 self->emitConsumerStopped(true);
111 emit self->mltFrameReceived(new Mlt::Frame(frame_ptr));
114 Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWidget *parent) :
115 AbstractRender(rendererName, parent),
116 requestedSeekPosition(SEEK_INACTIVE),
117 showFrameSemaphore(1),
118 externalConsumer(false),
119 m_name(rendererName),
123 m_showFrameEvent(NULL),
127 m_isSplitView(false),
132 qRegisterMetaType<stringMap> ("stringMap");
133 analyseAudio = KdenliveSettings::monitor_audio();
134 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
135 buildConsumer(profile);
136 m_mltProducer = m_blackClip->cut(0, 1);
137 m_mltConsumer->connect(*m_mltProducer);
138 m_mltProducer->set_speed(0.0);
139 m_refreshTimer.setSingleShot(true);
140 m_refreshTimer.setInterval(100);
141 connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
142 connect(this, SIGNAL(multiStreamFound(const QString &,QList<int>,QList<int>,stringMap)), this, SLOT(slotMultiStreamProducerFound(const QString &,QList<int>,QList<int>,stringMap)));
143 connect(this, SIGNAL(checkSeeking()), this, SLOT(slotCheckSeeking()));
144 connect(this, SIGNAL(mltFrameReceived(Mlt::Frame *)), this, SLOT(showFrame(Mlt::Frame *)), Qt::UniqueConnection);
154 void Render::closeMlt()
157 m_requestList.clear();
158 m_infoThread.waitForFinished();
159 if (m_showFrameEvent) delete m_showFrameEvent;
160 if (m_pauseEvent) delete m_pauseEvent;
161 if (m_mltConsumer) delete m_mltConsumer;
162 if (m_mltProducer) delete m_mltProducer;
163 /*if (m_mltProducer) {
164 Mlt::Service service(m_mltProducer->parent().get_service());
167 if (service.type() == tractor_type) {
168 Mlt::Tractor tractor(service);
169 Mlt::Field *field = tractor.field();
170 mlt_service nextservice = mlt_service_get_producer(service.get_service());
171 mlt_service nextservicetodisconnect;
172 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
173 QString mlt_type = mlt_properties_get(properties, "mlt_type");
174 QString resource = mlt_properties_get(properties, "mlt_service");
175 // Delete all transitions
176 while (mlt_type == "transition") {
177 nextservicetodisconnect = nextservice;
178 nextservice = mlt_service_producer(nextservice);
179 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
180 if (nextservice == NULL) break;
181 properties = MLT_SERVICE_PROPERTIES(nextservice);
182 mlt_type = mlt_properties_get(properties, "mlt_type");
183 resource = mlt_properties_get(properties, "mlt_service");
192 //kDebug() << "// // // CLOSE RENDERER " << m_name;
193 if (m_blackClip) delete m_blackClip;
197 void Render::slotSwitchFullscreen()
199 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
202 void Render::buildConsumer(const QString &profileName)
207 m_activeProfile = profileName;
209 Mlt::Profile tmpProfile(m_activeProfile.toUtf8().constData());
210 m_mltProfile->set_colorspace(tmpProfile.colorspace());
211 m_mltProfile->set_frame_rate(tmpProfile.frame_rate_num(), tmpProfile.frame_rate_den());
212 m_mltProfile->set_height(tmpProfile.height());
213 m_mltProfile->set_width(tmpProfile.width());
214 m_mltProfile->set_progressive(tmpProfile.progressive());
215 m_mltProfile->set_sample_aspect(tmpProfile.sample_aspect_num(), tmpProfile.sample_aspect_den());
216 m_mltProfile->get_profile()->display_aspect_num = tmpProfile.display_aspect_num();
217 m_mltProfile->get_profile()->display_aspect_den = tmpProfile.display_aspect_den();
220 m_mltProfile = new Mlt::Profile(m_activeProfile.toUtf8().constData());
222 setenv("MLT_PROFILE", m_activeProfile.toUtf8().constData(), 1);
223 m_mltProfile->set_explicit(true);
225 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
226 m_blackClip->set("id", "black");
227 m_blackClip->set("mlt_type", "producer");
228 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor && m_winid != 0) {
229 // Use blackmagic card for video output
230 int device = KdenliveSettings::blackmagic_output_device();
232 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
233 if (!m_mltConsumer) {
234 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
235 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
236 mlt_log_set_callback(kdenlive_callback);
238 if (m_mltConsumer->is_valid()) {
239 externalConsumer = true;
240 m_mltConsumer->set("terminate_on_pause", 0);
241 m_mltConsumer->set("deinterlace_method", "onefield");
242 m_mltConsumer->set("rescale", "nearest");
243 m_mltConsumer->set("buffer", "1");
244 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
246 if (m_mltConsumer && m_mltConsumer->is_valid()) {
249 KMessageBox::information(qApp->activeWindow(), i18n("Your project's profile %1 is not compatible with the blackmagic output card. Please see supported profiles below. Switching to normal video display.", m_mltProfile->description()));
252 externalConsumer = false;
253 QString videoDriver = KdenliveSettings::videodrivername();
254 if (!videoDriver.isEmpty()) {
255 if (videoDriver == "x11_noaccel") {
256 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
259 unsetenv("SDL_VIDEO_YUV_HWACCEL");
262 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
264 //m_mltConsumer->set("fullscreen", 1);
267 if (!m_mltConsumer) {
268 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) {
269 int device = KdenliveSettings::blackmagic_output_device();
271 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
272 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
273 // Set defaults for decklink consumer
275 m_mltConsumer->set("terminate_on_pause", 0);
276 m_mltConsumer->set("deinterlace_method", "onefield");
277 externalConsumer = true;
281 if (!m_mltConsumer || !m_mltConsumer->is_valid()) {
282 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
283 m_mltConsumer->set("scrub_audio", 1);
284 m_mltConsumer->set("preview_off", 1);
285 m_mltConsumer->set("audio_buffer", 512);
286 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
288 m_mltConsumer->set("buffer", "1");
289 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
292 if (!m_mltConsumer) {
293 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
294 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
295 //m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
296 m_mltConsumer->set("progressive", 1);
298 m_mltConsumer->set("window_id", m_winid);
300 //m_mltConsumer->set("resize", 1);
301 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
302 m_mltConsumer->set("rescale", "nearest");
303 mlt_log_set_callback(kdenlive_callback);
305 QString audioDevice = KdenliveSettings::audiodevicename();
306 if (!audioDevice.isEmpty())
307 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
309 if (!videoDriver.isEmpty())
310 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
312 QString audioDriver = KdenliveSettings::audiodrivername();
315 // Disabled because the "auto" detected driver was sometimes wrong
316 if (audioDriver.isEmpty())
317 audioDriver = KdenliveSettings::autoaudiodrivername();
320 if (!audioDriver.isEmpty())
321 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
323 m_mltConsumer->set("frequency", 48000);
324 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
327 Mlt::Producer *Render::invalidProducer(const QString &id)
330 QString txt = '+' + i18n("Missing clip") + ".txt";
331 char *tmp = qstrdup(txt.toUtf8().constData());
332 clip = new Mlt::Producer(*m_mltProfile, tmp);
334 if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
336 clip->set("bgcolour", "0xff0000ff");
337 clip->set("pad", "10");
339 clip->set("id", id.toUtf8().constData());
340 clip->set("mlt_type", "producer");
344 bool Render::hasProfile(const QString &profileName) const
346 return m_activeProfile == profileName;
349 int Render::resetProfile(const QString &profileName, bool dropSceneList)
351 m_refreshTimer.stop();
353 if (externalConsumer == KdenliveSettings::external_display()) {
354 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
355 QString videoDriver = KdenliveSettings::videodrivername();
356 QString currentDriver = m_mltConsumer->get("video_driver");
357 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
358 QString background = KdenliveSettings::window_background().name();
359 QString currentBackground = m_mltConsumer->get("window_background");
360 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
361 kDebug() << "reset to same profile, nothing to do";
366 if (m_isSplitView) slotSplitView(false);
367 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
368 m_mltConsumer->purge();
371 if (!dropSceneList) scene = sceneList();
373 double current_fps = m_mltProfile->fps();
374 double current_dar = m_mltProfile->dar();
377 m_requestList.clear();
378 m_infoThread.waitForFinished();
381 pos = m_mltProducer->position();
383 Mlt::Service service(m_mltProducer->get_service());
384 if (service.type() == tractor_type) {
385 Mlt::Tractor tractor(service);
386 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
387 Mlt::Producer trackProducer(tractor.track(trackNb));
388 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
389 trackPlaylist.clear();
393 delete m_mltProducer;
395 m_mltProducer = NULL;
396 buildConsumer(profileName);
397 double new_fps = m_mltProfile->fps();
398 double new_dar = m_mltProfile->dar();
400 if (!dropSceneList) {
401 // We need to recover our playlist
402 if (current_fps != new_fps) {
403 // fps changed, we must update the scenelist positions
404 scene = updateSceneListFps(current_fps, new_fps, scene);
406 setSceneList(scene, pos);
407 // producers have changed (different profile), so reset them...
408 emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
413 void Render::seek(GenTime time)
417 int pos = time.frames(m_fps);
421 void Render::seek(int time)
424 time = qMax(0, time);
425 time = qMin(m_mltProducer->get_playtime(), time);
426 if (requestedSeekPosition == SEEK_INACTIVE) {
427 requestedSeekPosition = time;
428 m_mltConsumer->purge();
429 m_mltProducer->seek(time);
430 if (m_paused && !externalConsumer) {
431 m_mltConsumer->set("refresh", 1);
434 else if (m_winid != 0 && m_mltProducer->get_speed() == 0) {
435 // workaround specific bug in MLT's SDL consumer
436 m_mltConsumer->stop();
437 m_mltConsumer->start();
438 m_mltConsumer->set("refresh", 1);
441 else requestedSeekPosition = time;
445 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
446 QPixmap pix(width, height);
448 mlt_image_format format = mlt_image_rgb24a;
449 uint8_t *thumb = frame->get_image(format, width, height);
450 QImage image(thumb, width, height, QImage::Format_ARGB32);
452 if (!image.isNull()) {
453 pix = pix.fromImage(image);
455 QPainter painter(&pix);
456 painter.drawRect(0, 0, width - 1, height - 1);
458 } else pix.fill(Qt::black);
462 int Render::frameRenderWidth() const
464 return m_mltProfile->width();
467 int Render::renderWidth() const
469 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
472 int Render::renderHeight() const
474 return m_mltProfile->height();
477 QImage Render::extractFrame(int frame_position, QString path, int width, int height)
480 width = frameRenderWidth();
481 height = renderHeight();
482 } else if (width % 2 == 1) width++;
483 int dwidth = height * frameRenderWidth() / renderHeight();
484 if (!path.isEmpty()) {
485 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
487 if (producer->is_valid()) {
488 QImage img = KThumb::getFrame(producer, frame_position, dwidth, width, height);
492 else delete producer;
496 if (!m_mltProducer || !path.isEmpty()) {
497 QImage pix(width, height, QImage::Format_RGB32);
501 return KThumb::getFrame(m_mltProducer, frame_position, dwidth, width, height);
504 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
508 if (url.fileName().startsWith(".all.")) { // check for slideshow
509 QString fileType = url.fileName().right(3);
511 QStringList::Iterator it;
513 QDir dir(url.directory());
515 filter << "*." + fileType;
516 filter << "*." + fileType.toUpper();
517 more = dir.entryList(filter, QDir::Files);
518 im.load(url.directory() + '/' + more.at(0));
519 } else im.load(url.path());
520 //pixmap = im.scaled(width, height);
524 double Render::consumerRatio() const
526 if (!m_mltConsumer) return 1.0;
527 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
531 int Render::getLength()
535 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
536 return mlt_producer_get_playtime(m_mltProducer->get_producer());
541 bool Render::isValid(KUrl url)
543 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
544 if (producer.is_blank())
550 double Render::dar() const
552 return m_mltProfile->dar();
555 double Render::sar() const
557 return m_mltProfile->sar();
560 void Render::slotSplitView(bool doit)
562 m_isSplitView = doit;
563 Mlt::Service service(m_mltProducer->parent().get_service());
564 Mlt::Tractor tractor(service);
565 if (service.type() != tractor_type || tractor.count() < 2) return;
566 Mlt::Field *field = tractor.field();
568 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
569 Mlt::Producer trackProducer(tractor.track(i));
570 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
571 if (QString(trackProducer.get("hide")).toInt() != 1) {
572 kDebug() << "// ADIDNG TRACK: " << i;
573 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
574 transition->set("mlt_service", "composite");
575 transition->set("a_track", 0);
576 transition->set("b_track", i);
577 transition->set("distort", 0);
578 transition->set("aligned", 0);
579 transition->set("internal_added", "200");
583 geometry = "0/0:50%x50%";
586 geometry = "50%/0:50%x50%";
589 geometry = "0/50%:50%x50%";
593 geometry = "50%/50%:50%x50%";
596 transition->set("geometry", geometry.toUtf8().constData());
597 transition->set("always_active", "1");
598 field->plant_transition(*transition, 0, i);
602 m_mltConsumer->set("refresh", 1);
604 mlt_service serv = m_mltProducer->parent().get_service();
605 mlt_service nextservice = mlt_service_get_producer(serv);
606 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
607 QString mlt_type = mlt_properties_get(properties, "mlt_type");
608 QString resource = mlt_properties_get(properties, "mlt_service");
609 mlt_service nextservicetodisconnect;
611 while (mlt_type == "transition") {
612 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
613 if (added == "200") {
614 nextservicetodisconnect = nextservice;
615 nextservice = mlt_service_producer(nextservice);
616 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
618 else nextservice = mlt_service_producer(nextservice);
619 if (nextservice == NULL) break;
620 properties = MLT_SERVICE_PROPERTIES(nextservice);
621 mlt_type = mlt_properties_get(properties, "mlt_type");
622 resource = mlt_properties_get(properties, "mlt_service");
623 m_mltConsumer->set("refresh", 1);
628 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer)
630 // Make sure we don't request the info for same clip twice
632 if (m_processingClipId.contains(clipId)) {
633 m_infoMutex.unlock();
636 for (int i = 0; i < m_requestList.count(); i++) {
637 if (m_requestList.at(i).clipId == clipId) {
638 // Clip is already queued
639 m_infoMutex.unlock();
643 requestClipInfo info;
645 info.clipId = clipId;
646 info.imageHeight = imageHeight;
647 info.replaceProducer = replaceProducer;
648 m_requestList.append(info);
649 m_infoMutex.unlock();
650 if (!m_infoThread.isRunning()) {
651 m_infoThread = QtConcurrent::run(this, &Render::processFileProperties);
655 void Render::forceProcessing(const QString &id)
657 if (m_processingClipId.contains(id)) return;
658 QMutexLocker lock(&m_infoMutex);
659 for (int i = 0; i < m_requestList.count(); i++) {
660 requestClipInfo info = m_requestList.at(i);
661 if (info.clipId == id) {
664 m_requestList.removeAt(i);
665 m_requestList.prepend(info);
672 int Render::processingItems()
674 QMutexLocker lock(&m_infoMutex);
675 int count = m_requestList.count() + m_processingClipId.count();
679 void Render::processingDone(const QString &id)
681 QMutexLocker lock(&m_infoMutex);
682 m_processingClipId.removeAll(id);
685 bool Render::isProcessing(const QString &id)
687 if (m_processingClipId.contains(id)) return true;
688 QMutexLocker lock(&m_infoMutex);
689 for (int i = 0; i < m_requestList.count(); i++) {
690 if (m_requestList.at(i).clipId == id) {
697 void Render::processFileProperties()
699 requestClipInfo info;
701 while (!m_requestList.isEmpty()) {
703 info = m_requestList.takeFirst();
704 m_processingClipId.append(info.clipId);
705 m_infoMutex.unlock();
709 if (info.xml.hasAttribute("proxy") && info.xml.attribute("proxy") != "-") {
710 path = info.xml.attribute("proxy");
711 // Check for missing proxies
712 if (QFileInfo(path).size() <= 0) {
713 // proxy is missing, re-create it
714 emit requestProxy(info.clipId);
715 proxyProducer = false;
716 path = info.xml.attribute("resource");
718 else proxyProducer = true;
721 path = info.xml.attribute("resource");
722 proxyProducer = false;
725 Mlt::Producer *producer = NULL;
726 CLIPTYPE type = (CLIPTYPE)info.xml.attribute("type").toInt();
728 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + info.xml.attribute("colour")).toUtf8().constData());
729 } else if (type == TEXT) {
730 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
731 if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
732 producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
733 } else if (url.isEmpty()) {
734 //WARNING: when is this case used? Not sure it is working.. JBM/
736 QDomElement mlt = doc.createElement("mlt");
737 QDomElement play = doc.createElement("playlist");
738 play.setAttribute("id", "playlist0");
739 doc.appendChild(mlt);
740 mlt.appendChild(play);
741 play.appendChild(doc.importNode(info.xml, true));
742 QDomElement tractor = doc.createElement("tractor");
743 tractor.setAttribute("id", "tractor0");
744 QDomElement track = doc.createElement("track");
745 track.setAttribute("producer", "playlist0");
746 tractor.appendChild(track);
747 mlt.appendChild(tractor);
748 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
750 producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
753 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
754 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
755 m_processingClipId.removeAll(info.clipId);
757 // Proxy file is corrupted
758 emit removeInvalidProxy(info.clipId, false);
760 else emit removeInvalidClip(info.clipId, info.replaceProducer);
765 if (proxyProducer && info.xml.hasAttribute("proxy_out")) {
766 producer->set("length", info.xml.attribute("proxy_out").toInt() + 1);
767 producer->set("out", info.xml.attribute("proxy_out").toInt());
768 if (producer->get_out() != info.xml.attribute("proxy_out").toInt()) {
769 // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
770 m_processingClipId.removeAll(info.clipId);
771 emit removeInvalidProxy(info.clipId, true);
777 if (info.xml.hasAttribute("force_aspect_ratio")) {
778 double aspect = info.xml.attribute("force_aspect_ratio").toDouble();
779 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
782 if (info.xml.hasAttribute("force_aspect_num") && info.xml.hasAttribute("force_aspect_den")) {
783 int width = info.xml.attribute("frame_size").section('x', 0, 0).toInt();
784 int height = info.xml.attribute("frame_size").section('x', 1, 1).toInt();
785 int aspectNumerator = info.xml.attribute("force_aspect_num").toInt();
786 int aspectDenominator = info.xml.attribute("force_aspect_den").toInt();
787 if (aspectDenominator != 0 && width != 0)
788 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
791 if (info.xml.hasAttribute("force_fps")) {
792 double fps = info.xml.attribute("force_fps").toDouble();
793 if (fps > 0) producer->set("force_fps", fps);
796 if (info.xml.hasAttribute("force_progressive")) {
798 int progressive = info.xml.attribute("force_progressive").toInt(&ok);
799 if (ok) producer->set("force_progressive", progressive);
801 if (info.xml.hasAttribute("force_tff")) {
803 int fieldOrder = info.xml.attribute("force_tff").toInt(&ok);
804 if (ok) producer->set("force_tff", fieldOrder);
806 if (info.xml.hasAttribute("threads")) {
807 int threads = info.xml.attribute("threads").toInt();
808 if (threads != 1) producer->set("threads", threads);
810 if (info.xml.hasAttribute("video_index")) {
811 int vindex = info.xml.attribute("video_index").toInt();
812 if (vindex != 0) producer->set("video_index", vindex);
814 if (info.xml.hasAttribute("audio_index")) {
815 int aindex = info.xml.attribute("audio_index").toInt();
816 if (aindex != 0) producer->set("audio_index", aindex);
818 if (info.xml.hasAttribute("force_colorspace")) {
819 int colorspace = info.xml.attribute("force_colorspace").toInt();
820 if (colorspace != 0) producer->set("force_colorspace", colorspace);
822 if (info.xml.hasAttribute("full_luma")) {
823 int full_luma = info.xml.attribute("full_luma").toInt();
824 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
829 if (info.xml.hasAttribute("out")) clipOut = info.xml.attribute("out").toInt();
831 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
832 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
834 if (info.xml.hasAttribute("length")) {
835 length = info.xml.attribute("length").toInt();
836 clipOut = length - 1;
838 else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt() + 1;
839 // Pass duration if it was forced
840 if (info.xml.hasAttribute("duration")) {
841 duration = info.xml.attribute("duration").toInt();
842 if (length < duration) {
844 if (clipOut > 0) clipOut = length - 1;
847 if (duration == 0) duration = length;
848 producer->set("length", length);
851 if (clipOut > 0) producer->set_in_and_out(info.xml.attribute("in").toInt(), clipOut);
853 producer->set("id", info.clipId.toUtf8().constData());
855 if (info.xml.hasAttribute("templatetext"))
856 producer->set("templatetext", info.xml.attribute("templatetext").toUtf8().constData());
858 int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5);
859 int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5);
860 int frameNumber = info.xml.attribute("thumbnail", "-1").toInt();
862 if ((!info.replaceProducer && info.xml.hasAttribute("file_hash")) || proxyProducer) {
863 // Clip already has all properties
865 // Recreate clip thumb
866 if (frameNumber > 0) producer->seek(frameNumber);
867 Mlt::Frame *frame = producer->get_frame();
868 if (frame && frame->is_valid()) {
869 QImage img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
870 emit replyGetImage(info.clipId, img);
872 if (frame) delete frame;
874 emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
878 stringMap filePropertyMap;
879 stringMap metadataPropertyMap;
882 if (frameNumber > 0) producer->seek(frameNumber);
883 duration = duration > 0 ? duration : producer->get_playtime();
884 filePropertyMap["duration"] = QString::number(duration);
885 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
887 if (type == SLIDESHOW) {
888 int ttl = info.xml.hasAttribute("ttl") ? info.xml.attribute("ttl").toInt() : 0;
889 if (ttl) producer->set("ttl", ttl);
890 if (!info.xml.attribute("animation").isEmpty()) {
891 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
892 if (filter && filter->is_valid()) {
894 QString geometry = SlideshowClip::animationToGeometry(info.xml.attribute("animation"), cycle);
895 if (!geometry.isEmpty()) {
896 if (info.xml.attribute("animation").contains("low-pass")) {
897 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
898 if (blur && blur->is_valid())
899 producer->attach(*blur);
901 filter->set("transition.geometry", geometry.toUtf8().data());
902 filter->set("transition.cycle", cycle);
903 producer->attach(*filter);
907 if (info.xml.attribute("fade") == "1") {
908 // user wants a fade effect to slideshow
909 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
910 if (filter && filter->is_valid()) {
911 if (ttl) filter->set("cycle", ttl);
912 if (info.xml.hasAttribute("luma_duration") && !info.xml.attribute("luma_duration").isEmpty()) filter->set("duration", info.xml.attribute("luma_duration").toInt());
913 if (info.xml.hasAttribute("luma_file") && !info.xml.attribute("luma_file").isEmpty()) {
914 filter->set("luma.resource", info.xml.attribute("luma_file").toUtf8().constData());
915 if (info.xml.hasAttribute("softness")) {
916 int soft = info.xml.attribute("softness").toInt();
917 filter->set("luma.softness", (double) soft / 100.0);
920 producer->attach(*filter);
923 if (info.xml.attribute("crop") == "1") {
924 // user wants to center crop the slides
925 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
926 if (filter && filter->is_valid()) {
927 filter->set("center", 1);
928 producer->attach(*filter);
934 const QString mltService = producer->get("mlt_service");
935 if (mltService == "xml" || mltService == "consumer") {
936 // MLT playlist, create producer with blank profile to get real profile info
937 // TODO: is there an easier way to get this info (original source clip profile) from MLT?
938 Mlt::Profile *original_profile = new Mlt::Profile();
939 Mlt::Producer *tmpProd = new Mlt::Producer(*original_profile, path.toUtf8().constData());
940 filePropertyMap["progressive"] = QString::number(original_profile->progressive());
941 filePropertyMap["colorspace"] = QString::number(original_profile->colorspace());
942 filePropertyMap["fps"] = QString::number(original_profile->fps());
943 filePropertyMap["aspect_ratio"] = QString::number(original_profile->sar());
945 delete original_profile;
947 else if (mltService == "avformat") {
949 vindex = producer->get_int("video_index");
952 int streams = producer->get_int("meta.media.nb_streams");
953 QList <int> audio_list;
954 QList <int> video_list;
955 for (int i = 0; i < streams; i++) {
956 QByteArray propertyName = QString("meta.media.%1.stream.type").arg(i).toLocal8Bit();
957 QString type = producer->get(propertyName.data());
958 if (type == "audio") audio_list.append(i);
959 else if (type == "video") video_list.append(i);
962 if (!info.xml.hasAttribute("video_index") && video_list.count() > 1) {
963 // Clip has more than one video stream, ask which one should be used
964 QMap <QString, QString> data;
965 if (info.xml.hasAttribute("group")) data.insert("group", info.xml.attribute("group"));
966 if (info.xml.hasAttribute("groupId")) data.insert("groupId", info.xml.attribute("groupId"));
967 emit multiStreamFound(path, audio_list, video_list, data);
968 // Force video index so that when reloading the clip we don't ask again for other streams
969 filePropertyMap["video_index"] = QString::number(vindex);
973 snprintf(property, sizeof(property), "meta.media.%d.stream.frame_rate", vindex);
974 if (producer->get(property))
975 filePropertyMap["fps"] = producer->get(property);
978 if (!filePropertyMap.contains("fps")) {
979 if (producer->get_double("meta.media.frame_rate_den") > 0) {
980 filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
981 } else filePropertyMap["fps"] = producer->get("source_fps");
985 Mlt::Frame *frame = producer->get_frame();
986 if (frame && frame->is_valid()) {
987 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
988 int af = frame->get_int("audio_frequency");
989 int ac = frame->get_int("audio_channels");
990 // keep for compatibility with MLT <= 0.8.6
991 if (af == 0) af = frame->get_int("frequency");
992 if (ac == 0) ac = frame->get_int("channels");
993 if (af > 0) filePropertyMap["frequency"] = QString::number(af);
994 if (ac > 0) filePropertyMap["channels"] = QString::number(ac);
995 if (!filePropertyMap.contains("aspect_ratio")) filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
997 if (frame->get_int("test_image") == 0) {
998 if (mltService == "xml" || mltService == "consumer") {
999 filePropertyMap["type"] = "playlist";
1000 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
1001 } else if (!mlt_frame_is_test_audio(frame->get_frame()))
1002 filePropertyMap["type"] = "av";
1004 filePropertyMap["type"] = "video";
1010 img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
1011 variance = KThumb::imageVariance(img);
1012 if (frameNumber == -1 && variance< 6) {
1013 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
1014 frameNumber = duration > 100 ? 100 : duration / 2 ;
1015 producer->seek(frameNumber);
1017 frame = producer->get_frame();
1020 } while (variance == -1);
1022 if (frameNumber > -1) filePropertyMap["thumbnail"] = QString::number(frameNumber);
1023 emit replyGetImage(info.clipId, img);
1024 } else if (frame->get_int("test_audio") == 0) {
1025 emit replyGetImage(info.clipId, "audio-x-generic", fullWidth, info.imageHeight);
1026 filePropertyMap["type"] = "audio";
1029 // Retrieve audio / video codec name
1032 if (mltService == "avformat") {
1034 /*if (context->duration == AV_NOPTS_VALUE) {
1035 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
1036 emit removeInvalidClip(clipId);
1040 // Get the video_index
1042 int default_audio = producer->get_int("audio_index");
1045 int scan = producer->get_int("meta.media.progressive");
1046 filePropertyMap["progressive"] = QString::number(scan);
1048 // Find maximum stream index values
1049 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
1050 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
1051 QString type = producer->get(property);
1052 if (type == "video")
1054 else if (type == "audio")
1057 filePropertyMap["default_video"] = QString::number(vindex);
1058 filePropertyMap["video_max"] = QString::number(video_max);
1059 filePropertyMap["default_audio"] = QString::number(default_audio);
1060 filePropertyMap["audio_max"] = QString::number(audio_max);
1062 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex);
1063 if (producer->get(property)) {
1064 filePropertyMap["videocodec"] = producer->get(property);
1066 snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex);
1067 if (producer->get(property)) {
1068 filePropertyMap["videocodecid"] = producer->get(property);
1071 query = QString("meta.media.%1.codec.pix_fmt").arg(vindex);
1072 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
1073 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
1075 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
1076 if (producer->get_int("audio_index") > -1) {
1077 // Get the audio_index
1078 int index = producer->get_int("audio_index");
1079 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
1080 if (producer->get(property)) {
1081 filePropertyMap["audiocodec"] = producer->get(property);
1083 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
1084 if (producer->get(property))
1085 filePropertyMap["audiocodec"] = producer->get(property);
1091 Mlt::Properties metadata;
1092 metadata.pass_values(*producer, "meta.attr.");
1093 int count = metadata.count();
1094 for (int i = 0; i < count; i ++) {
1095 QString name = metadata.get_name(i);
1096 QString value = QString::fromUtf8(metadata.get(i));
1097 if (name.endsWith(".markup") && !value.isEmpty())
1098 metadataPropertyMap[ name.section('.', 0, -2)] = value;
1101 emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer);
1107 /** Create the producer from the MLT XML QDomDocument */
1108 void Render::initSceneList()
1110 kDebug() << "-------- INIT SCENE LIST ------_";
1112 QDomElement mlt = doc.createElement("mlt");
1113 doc.appendChild(mlt);
1114 QDomElement prod = doc.createElement("producer");
1115 prod.setAttribute("resource", "colour");
1116 prod.setAttribute("colour", "red");
1117 prod.setAttribute("id", "black");
1118 prod.setAttribute("in", "0");
1119 prod.setAttribute("out", "0");
1121 QDomElement tractor = doc.createElement("tractor");
1122 QDomElement multitrack = doc.createElement("multitrack");
1124 QDomElement playlist1 = doc.createElement("playlist");
1125 playlist1.appendChild(prod);
1126 multitrack.appendChild(playlist1);
1127 QDomElement playlist2 = doc.createElement("playlist");
1128 multitrack.appendChild(playlist2);
1129 QDomElement playlist3 = doc.createElement("playlist");
1130 multitrack.appendChild(playlist3);
1131 QDomElement playlist4 = doc.createElement("playlist");
1132 multitrack.appendChild(playlist4);
1133 QDomElement playlist5 = doc.createElement("playlist");
1134 multitrack.appendChild(playlist5);
1135 tractor.appendChild(multitrack);
1136 mlt.appendChild(tractor);
1137 // kDebug()<<doc.toString();
1139 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
1140 setSceneList(doc, 0);
1144 void Render::loadUrl(const QString &url)
1146 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, url.toUtf8().constData());
1147 setProducer(producer, 0);
1150 int Render::setProducer(Mlt::Producer *producer, int position)
1152 m_refreshTimer.stop();
1153 requestedSeekPosition = SEEK_INACTIVE;
1154 QMutexLocker locker(&m_mutex);
1156 int consumerPosition = 0;
1157 if (m_winid == -1 || !m_mltConsumer) {
1158 kDebug()<<" / / / / WARNING, MONITOR NOT READY";
1159 if (producer) delete producer;
1162 bool monitorIsActive = false;
1163 m_mltConsumer->set("refresh", 0);
1164 if (!m_mltConsumer->is_stopped()) {
1165 monitorIsActive = true;
1166 m_mltConsumer->stop();
1168 m_mltConsumer->purge();
1169 consumerPosition = m_mltConsumer->position();
1173 if (!producer || !producer->is_valid()) {
1174 if (producer) delete producer;
1175 producer = m_blackClip->cut(0, 1);
1176 producer->set("id", "black");
1179 if (!producer || !producer->is_valid()) {
1180 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
1183 if (m_mltProducer) currentId = m_mltProducer->get("id");
1185 if (position == -1 && producer->get("id") == currentId) position = consumerPosition;
1186 if (position != -1) producer->seek(position);
1187 m_fps = producer->get_fps();
1188 int volume = KdenliveSettings::volume();
1189 if (producer->get_int("_audioclip") == 1) {
1190 // This is an audio only clip, create fake multitrack to apply audiowave filter
1191 Mlt::Tractor *tractor = new Mlt::Tractor();
1192 Mlt::Producer *color= new Mlt::Producer(*m_mltProfile, "color:red");
1193 color->set_in_and_out(0, producer->get_out());
1194 tractor->set_track(*producer, 0);
1195 tractor->set_track(*color, 1);
1197 Mlt::Consumer xmlConsumer(*m_mltProfile, "xml:audio_hack");
1198 if (!xmlConsumer.is_valid()) return -1;
1199 xmlConsumer.set("terminate_on_pause", 1);
1200 xmlConsumer.connect(tractor->parent());
1205 QString playlist = QString::fromUtf8(xmlConsumer.get("audio_hack"));
1207 Mlt::Producer *result = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1208 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "audiowave");
1209 result->attach(*filter);
1210 tractor = new Mlt::Tractor();
1211 tractor->set_track(*result, 0);
1214 producer = &(tractor->parent());
1215 m_mltConsumer->connect(*producer);
1218 producer->set("meta.volume", (double)volume / 100);
1219 blockSignals(false);
1220 m_mltConsumer->connect(*producer);
1222 if (m_mltProducer) {
1223 m_mltProducer->set_speed(0);
1224 delete m_mltProducer;
1225 m_mltProducer = NULL;
1227 m_mltProducer = producer;
1228 m_mltProducer->set_speed(0);
1229 if (monitorIsActive) {
1232 emit durationChanged(m_mltProducer->get_playtime());
1233 position = m_mltProducer->position();
1234 emit rendererPosition(position);
1238 void Render::startConsumer() {
1239 if (m_mltConsumer->is_stopped() && m_mltConsumer->start() == -1) {
1240 // ARGH CONSUMER BROKEN!!!!
1241 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."));
1242 if (m_showFrameEvent) delete m_showFrameEvent;
1243 m_showFrameEvent = NULL;
1244 if (m_pauseEvent) delete m_pauseEvent;
1245 m_pauseEvent = NULL;
1246 delete m_mltConsumer;
1247 m_mltConsumer = NULL;
1250 m_mltConsumer->set("refresh", 1);
1253 int Render::setSceneList(QDomDocument list, int position)
1255 return setSceneList(list.toString(), position);
1258 int Render::setSceneList(QString playlist, int position)
1260 requestedSeekPosition = SEEK_INACTIVE;
1261 m_refreshTimer.stop();
1262 QMutexLocker locker(&m_mutex);
1263 if (m_winid == -1) return -1;
1266 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
1268 // Remove previous profile info
1270 doc.setContent(playlist);
1271 QDomElement profile = doc.documentElement().firstChildElement("profile");
1272 doc.documentElement().removeChild(profile);
1273 playlist = doc.toString();
1275 if (m_mltConsumer) {
1276 if (!m_mltConsumer->is_stopped()) {
1277 m_mltConsumer->stop();
1279 m_mltConsumer->set("refresh", 0);
1281 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
1284 m_requestList.clear();
1285 m_infoThread.waitForFinished();
1287 if (m_mltProducer) {
1288 m_mltProducer->set_speed(0);
1289 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1291 /*Mlt::Service service(m_mltProducer->parent().get_service());
1294 if (service.type() == tractor_type) {
1295 Mlt::Tractor tractor(service);
1296 Mlt::Field *field = tractor.field();
1297 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1298 mlt_service nextservicetodisconnect;
1299 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1300 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1301 QString resource = mlt_properties_get(properties, "mlt_service");
1302 // Delete all transitions
1303 while (mlt_type == "transition") {
1304 nextservicetodisconnect = nextservice;
1305 nextservice = mlt_service_producer(nextservice);
1306 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1307 if (nextservice == NULL) break;
1308 properties = MLT_SERVICE_PROPERTIES(nextservice);
1309 mlt_type = mlt_properties_get(properties, "mlt_type");
1310 resource = mlt_properties_get(properties, "mlt_service");
1314 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1315 Mlt::Producer trackProducer(tractor.track(trackNb));
1316 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1317 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1323 qDeleteAll(m_slowmotionProducers.values());
1324 m_slowmotionProducers.clear();
1326 delete m_mltProducer;
1327 m_mltProducer = NULL;
1332 m_locale = QLocale();
1333 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1334 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1335 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1336 m_mltProducer = m_blackClip->cut(0, 1);
1339 m_mltProducer->set("eof", "pause");
1341 int volume = KdenliveSettings::volume();
1342 m_mltProducer->set("meta.volume", (double)volume / 100);
1343 m_mltProducer->optimise();
1345 /*if (KdenliveSettings::osdtimecode()) {
1346 // Attach filter for on screen display of timecode
1348 QString attr = "attr_check";
1349 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1350 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1351 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1352 mlt_filter_close( filter );
1354 m_osdInfo = new Mlt::Filter("data_show");
1355 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1356 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1357 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1358 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1359 m_osdInfo->set("dynamic", "1");
1361 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1363 m_osdInfo->set("dynamic", "0");
1366 m_fps = m_mltProducer->get_fps();
1367 if (position != 0) {
1368 // Seek to correct place after opening project.
1369 m_mltProducer->seek(position);
1372 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1373 m_mltConsumer->connect(*m_mltProducer);
1374 m_mltProducer->set_speed(0);
1375 fillSlowMotionProducers();
1376 blockSignals(false);
1377 emit durationChanged(m_mltProducer->get_playtime());
1380 //kDebug()<<"// SETSCN LST, POS: "<<position;
1381 //if (position != 0) emit rendererPosition(position);
1384 void Render::checkMaxThreads()
1386 // Make sure we don't use too much threads, MLT avformat does not cope with too much threads
1387 // Currently, Kdenlive uses the following avformat threads:
1388 // One thread to get info when adding a clip
1389 // One thread to create the timeline video thumbnails
1390 // One thread to create the audio thumbnails
1391 Mlt::Service service(m_mltProducer->parent().get_service());
1392 if (service.type() != tractor_type) {
1393 kWarning() << "// TRACTOR PROBLEM";
1396 Mlt::Tractor tractor(service);
1397 int mltMaxThreads = mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1398 int requestedThreads = tractor.count() + 4;
1399 if (requestedThreads > mltMaxThreads) {
1400 mlt_service_cache_set_size(service.get_service(), "producer_avformat", requestedThreads);
1401 kDebug()<<"// MLT threads updated to: "<<mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1405 const QString Render::sceneList()
1408 Mlt::Profile profile((mlt_profile) 0);
1409 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1410 if (!xmlConsumer.is_valid()) return QString();
1411 m_mltProducer->optimise();
1412 xmlConsumer.set("terminate_on_pause", 1);
1413 Mlt::Producer prod(m_mltProducer->get_producer());
1414 if (!prod.is_valid()) return QString();
1415 bool split = m_isSplitView;
1416 if (split) slotSplitView(false);
1417 xmlConsumer.connect(prod);
1419 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1420 if (split) slotSplitView(true);
1424 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1428 doc.setContent(sceneList(), false);
1429 if (doc.isNull()) return false;
1430 QDomElement root = doc.documentElement();
1431 if (!kdenliveData.isNull() && !root.isNull()) {
1432 // add Kdenlive specific tags
1433 root.appendChild(doc.importNode(kdenliveData, true));
1435 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1436 kWarning() << "////// ERROR writing to file: " << path;
1439 file.write(doc.toString().toUtf8());
1440 if (file.error() != QFile::NoError) {
1448 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1450 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1451 m_mltProducer->optimise();
1452 xmlConsumer.set("terminate_on_pause", 1);
1453 if (m_name == Kdenlive::clipMonitor) {
1454 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1456 list.insert_at(0, prod, 0);
1458 list.set("title", desc.toUtf8().constData());
1459 xmlConsumer.connect(list);
1462 //TODO: not working yet, save zone from timeline
1463 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1464 /* Mlt::Service service(p1->parent().get_service());
1465 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1467 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1468 //prod->set("title", desc.toUtf8().constData());
1469 xmlConsumer.connect(*p1); //list);
1472 xmlConsumer.start();
1476 bool Render::saveClip(int track, GenTime position, KUrl url, QString desc)
1479 Mlt::Service service(m_mltProducer->parent().get_service());
1480 Mlt::Tractor tractor(service);
1481 Mlt::Producer trackProducer(tractor.track(track));
1482 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1484 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1485 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1487 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1491 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1492 xmlConsumer.set("terminate_on_pause", 1);
1494 list.insert_at(0, clip, 0);
1496 list.set("title", desc.toUtf8().constData());
1497 xmlConsumer.connect(list);
1499 kDebug()<<"// SAVED: "<<url;
1503 double Render::fps() const
1508 int Render::volume() const
1510 if (!m_mltConsumer || !m_mltProducer) return -1;
1511 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1514 void Render::slotSetVolume(int volume)
1516 if (!m_mltConsumer || !m_mltProducer) return;
1517 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1520 m_mltConsumer->set("refresh", 0);
1521 // Attach filter for on screen display of timecode
1522 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1523 mlt_properties_set_double( properties, "meta.volume", volume );
1524 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1525 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1527 if (!KdenliveSettings::osdtimecode()) {
1528 m_mltProducer->detach(*m_osdInfo);
1529 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1530 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1533 //m_osdTimer->setSingleShot(2500);
1536 void Render::slotOsdTimeout()
1538 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1539 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1540 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1541 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1545 void Render::start()
1547 m_refreshTimer.stop();
1548 QMutexLocker locker(&m_mutex);
1549 if (m_winid == -1) {
1550 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1553 if (!m_mltConsumer) return;
1554 if (m_mltConsumer->is_stopped()) {
1555 if (m_mltConsumer->start() == -1) {
1556 //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."));
1557 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1559 m_mltConsumer->purge();
1560 m_mltConsumer->set("refresh", 1);
1567 requestedSeekPosition = SEEK_INACTIVE;
1568 m_refreshTimer.stop();
1569 QMutexLocker locker(&m_mutex);
1570 if (m_mltProducer == NULL) return;
1571 if (m_mltConsumer) {
1572 m_mltConsumer->set("refresh", 0);
1573 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1574 m_mltConsumer->purge();
1577 if (m_mltProducer) {
1578 if (m_isZoneMode) resetZoneMode();
1579 m_mltProducer->set_speed(0.0);
1583 void Render::stop(const GenTime & startTime)
1585 requestedSeekPosition = SEEK_INACTIVE;
1586 m_refreshTimer.stop();
1587 QMutexLocker locker(&m_mutex);
1588 if (m_mltProducer) {
1589 if (m_isZoneMode) resetZoneMode();
1590 m_mltProducer->set_speed(0.0);
1591 m_mltProducer->seek((int) startTime.frames(m_fps));
1593 m_mltConsumer->purge();
1596 void Render::pause()
1598 requestedSeekPosition = SEEK_INACTIVE;
1599 if (!m_mltProducer || !m_mltConsumer)
1602 m_mltProducer->set_speed(0.0);
1603 /*m_mltConsumer->set("refresh", 0);
1604 //if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1605 m_mltProducer->seek(m_mltConsumer->position());*/
1608 void Render::switchPlay(bool play)
1610 QMutexLocker locker(&m_mutex);
1611 requestedSeekPosition = SEEK_INACTIVE;
1612 if (!m_mltProducer || !m_mltConsumer)
1614 if (m_isZoneMode) resetZoneMode();
1615 if (play && m_paused) {
1616 if (m_name == Kdenlive::clipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
1618 m_mltProducer->set_speed(1.0);
1619 if (m_mltConsumer->is_stopped()) {
1620 m_mltConsumer->start();
1622 m_mltConsumer->set("refresh", 1);
1627 m_mltProducer->set_speed(0.0);
1630 // SDL consumer, hack to allow pausing near the end of the playlist
1631 m_mltConsumer->set("refresh", 0);
1632 m_mltConsumer->stop();
1633 m_mltProducer->set_speed(0.0);
1634 m_mltProducer->seek(m_mltConsumer->position());
1635 m_mltConsumer->start();
1640 void Render::play(double speed)
1642 requestedSeekPosition = SEEK_INACTIVE;
1643 if (!m_mltProducer) return;
1644 double current_speed = m_mltProducer->get_speed();
1645 if (current_speed == speed) return;
1646 if (m_isZoneMode) resetZoneMode();
1647 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1648 m_mltProducer->set_speed(speed);
1649 if (m_mltConsumer->is_stopped() && speed != 0) {
1650 m_mltConsumer->start();
1652 m_paused = speed == 0;
1653 if (current_speed == 0 && speed != 0) m_mltConsumer->set("refresh", 1);
1656 void Render::play(const GenTime & startTime)
1658 requestedSeekPosition = SEEK_INACTIVE;
1659 if (!m_mltProducer || !m_mltConsumer)
1662 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1663 m_mltProducer->set_speed(1.0);
1664 m_mltConsumer->set("refresh", 1);
1667 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1669 requestedSeekPosition = SEEK_INACTIVE;
1670 if (!m_mltProducer || !m_mltConsumer)
1672 //m_mltProducer->set("eof", "loop");
1673 m_isLoopMode = true;
1674 m_loopStart = startTime;
1675 playZone(startTime, stopTime);
1678 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1680 requestedSeekPosition = SEEK_INACTIVE;
1681 if (!m_mltProducer || !m_mltConsumer)
1683 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1684 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1686 m_mltProducer->set_speed(1.0);
1687 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1688 m_mltConsumer->set("refresh", 1);
1689 m_isZoneMode = true;
1692 void Render::resetZoneMode()
1694 if (!m_isZoneMode && !m_isLoopMode) return;
1695 m_mltProducer->set("out", m_mltProducer->get_length());
1696 m_isZoneMode = false;
1697 m_isLoopMode = false;
1700 void Render::seekToFrame(int pos)
1708 void Render::seekToFrameDiff(int diff)
1713 if (requestedSeekPosition == SEEK_INACTIVE)
1714 seek(m_mltProducer->position() + diff);
1715 else seek(requestedSeekPosition + diff);
1718 void Render::refreshIfActive()
1720 if (!m_mltConsumer->is_stopped() && m_mltProducer && m_paused) m_refreshTimer.start();
1723 void Render::doRefresh()
1725 if (m_mltProducer && m_paused) m_refreshTimer.start();
1728 void Render::refresh()
1730 m_refreshTimer.stop();
1731 QMutexLocker locker(&m_mutex);
1734 if (m_mltConsumer) {
1735 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1736 m_mltConsumer->set("refresh", 1);
1737 //m_mltConsumer->purge();
1741 void Render::setDropFrames(bool show)
1743 QMutexLocker locker(&m_mutex);
1744 if (m_mltConsumer) {
1745 int dropFrames = KdenliveSettings::mltthreads();
1746 if (show == false) dropFrames = -dropFrames;
1747 m_mltConsumer->stop();
1749 m_mltConsumer->set("real_time", dropFrames);
1751 m_mltConsumer->set("play.real_time", dropFrames);
1753 if (m_mltConsumer->start() == -1) {
1754 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1760 bool Render::isPlaying() const
1762 if (!m_mltConsumer || m_mltConsumer->is_stopped()) return false;
1766 double Render::playSpeed() const
1768 if (m_mltProducer) return m_mltProducer->get_speed();
1772 GenTime Render::seekPosition() const
1774 if (m_mltConsumer) return GenTime((int) m_mltConsumer->position(), m_fps);
1775 //if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1776 else return GenTime();
1779 int Render::seekFramePosition() const
1781 //if (m_mltProducer) return (int) m_mltProducer->position();
1782 if (m_mltConsumer) return (int) m_mltConsumer->position();
1786 void Render::emitFrameUpdated(Mlt::Frame& frame)
1788 mlt_image_format format = mlt_image_rgb24a;
1791 const uchar* image = frame.get_image(format, width, height);
1792 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1793 memcpy(qimage.scanLine(0), image, width * height * 4);
1794 emit frameUpdated(qimage.rgbSwapped());
1797 int Render::getCurrentSeekPosition() const
1799 if (requestedSeekPosition != SEEK_INACTIVE) return requestedSeekPosition;
1800 return (int) m_mltProducer->position();
1803 void Render::emitFrameNumber()
1805 int currentPos = m_mltConsumer->position();
1806 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1807 emit rendererPosition(currentPos);
1808 if (requestedSeekPosition != SEEK_INACTIVE) {
1809 m_mltConsumer->purge();
1810 m_mltProducer->seek(requestedSeekPosition);
1811 if (m_mltProducer->get_speed() == 0 && m_paused) {
1813 m_mltConsumer->set("refresh", 1);
1815 requestedSeekPosition = SEEK_INACTIVE;
1819 void Render::emitConsumerStopped(bool forcePause)
1821 // This is used to know when the playing stopped
1822 if (m_mltProducer && (forcePause || (!m_paused && m_mltProducer->get_speed() == 0))) {
1823 double pos = m_mltProducer->position();
1825 if (m_isLoopMode) play(m_loopStart);
1826 //else if (m_isZoneMode) resetZoneMode();
1827 emit rendererStopped((int) pos);
1831 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1833 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1836 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1838 if (!m_mltProducer) {
1839 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1843 //int height = 1080;//KdenliveSettings::defaultheight();
1844 //int width = 1940; //KdenliveSettings::displaywidth();
1846 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1848 QPixmap pix(width, height);
1849 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1850 m_convert.set("forced", mlt_image_rgb24a);
1851 m_mltProducer->attach(m_convert);
1852 Mlt::Frame * frame = m_mltProducer->get_frame();
1853 m_mltProducer->detach(m_convert);
1855 pix = frameThumbnail(frame, width, height);
1858 pix.save(url.path(), "PNG");
1859 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1863 void Render::showFrame(Mlt::Frame* frame)
1865 int currentPos = m_mltConsumer->position();
1866 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1867 emit rendererPosition(currentPos);
1868 if (frame->is_valid()) {
1869 mlt_image_format format = mlt_image_rgb24a;
1872 const uchar* image = frame->get_image(format, width, height);
1873 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1874 memcpy(qimage.scanLine(0), image, width * height * 4);
1875 if (analyseAudio) showAudio(*frame);
1877 emit showImageSignal(qimage);
1878 if (sendFrameForAnalysis) {
1879 emit frameUpdated(qimage.rgbSwapped());
1881 } else delete frame;
1882 showFrameSemaphore.release();
1883 emit checkSeeking();
1886 void Render::slotCheckSeeking()
1888 if (requestedSeekPosition != SEEK_INACTIVE) {
1889 m_mltProducer->seek(requestedSeekPosition);
1893 requestedSeekPosition = SEEK_INACTIVE;
1897 void Render::disablePreview(bool disable)
1899 if (m_mltConsumer) {
1900 m_mltConsumer->stop();
1901 m_mltConsumer->set("preview_off", (int) disable);
1902 m_mltConsumer->set("refresh", 0);
1903 m_mltConsumer->start();
1907 void Render::showAudio(Mlt::Frame& frame)
1909 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1913 mlt_audio_format audio_format = mlt_audio_s16;
1914 //FIXME: should not be hardcoded..
1916 int num_channels = 2;
1918 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1924 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1925 // So the vector is of size samples*channels.
1926 QVector<int16_t> sampleVector(samples*num_channels);
1927 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1930 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1935 * MLT playlist direct manipulation.
1938 void Render::mltCheckLength(Mlt::Tractor *tractor)
1940 //kDebug()<<"checking track length: "<<track<<"..........";
1942 int trackNb = tractor->count();
1945 if (m_isZoneMode) resetZoneMode();
1947 Mlt::Producer trackProducer(tractor->track(0));
1948 duration = trackProducer.get_playtime() - 1;
1949 m_mltProducer->set("out", duration);
1950 emit durationChanged(duration);
1953 while (trackNb > 1) {
1954 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1955 trackDuration = trackProducer.get_playtime() - 1;
1956 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1957 if (trackDuration > duration) duration = trackDuration;
1961 Mlt::Producer blackTrackProducer(tractor->track(0));
1963 if (blackTrackProducer.get_playtime() - 1 != duration) {
1964 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1965 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1966 if (blackclip && blackclip->is_blank()) {
1971 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1972 if (blackclip) delete blackclip;
1973 blackTrackPlaylist.clear();
1974 m_blackClip->set("length", duration + 1);
1975 m_blackClip->set("out", duration);
1976 blackclip = m_blackClip->cut(0, duration);
1977 blackTrackPlaylist.insert_at(0, blackclip, 1);
1979 if (duration > blackclip->parent().get_length()) {
1980 blackclip->parent().set("length", duration + 1);
1981 blackclip->parent().set("out", duration);
1982 blackclip->set("length", duration + 1);
1984 blackTrackPlaylist.resize_clip(0, 0, duration);
1988 if (m_mltConsumer->position() > duration) {
1989 m_mltConsumer->purge();
1990 m_mltProducer->seek(duration);
1992 m_mltProducer->set("out", duration);
1993 emit durationChanged(duration);
1997 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1999 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
2001 // We want a slowmotion producer
2002 double speed = element.attribute("speed", "1.0").toDouble();
2003 int strobe = element.attribute("strobe", "1").toInt();
2004 QString url = QString::fromUtf8(prod->get("resource"));
2005 url.append('?' + locale.toString(speed));
2006 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2007 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2008 if (!slowprod || slowprod->get_producer() == NULL) {
2009 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2010 if (strobe > 1) slowprod->set("strobe", strobe);
2011 QString id = prod->parent().get("id");
2012 if (id.contains('_')) id = id.section('_', 0, 0);
2013 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
2014 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2015 slowprod->set("id", producerid.toUtf8().constData());
2016 m_slowmotionProducers.insert(url, slowprod);
2021 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
2023 m_refreshTimer.stop();
2024 if (m_mltProducer == NULL) {
2025 kDebug() << "PLAYLIST NOT INITIALISED //////";
2029 kDebug() << "Cannot insert clip without producer //////";
2032 Mlt::Producer parentProd(m_mltProducer->parent());
2033 if (parentProd.get_producer() == NULL) {
2034 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2038 Mlt::Service service(parentProd.get_service());
2039 if (service.type() != tractor_type) {
2040 kWarning() << "// TRACTOR PROBLEM";
2043 Mlt::Tractor tractor(service);
2044 if (info.track > tractor.count() - 1) {
2045 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
2049 Mlt::Producer trackProducer(tractor.track(info.track));
2050 int trackDuration = trackProducer.get_playtime() - 1;
2051 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2052 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
2053 prod = checkSlowMotionProducer(prod, element);
2054 if (prod == NULL || !prod->is_valid()) {
2059 int cutPos = (int) info.cropStart.frames(m_fps);
2060 if (cutPos < 0) cutPos = 0;
2061 int insertPos = (int) info.startPos.frames(m_fps);
2062 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
2063 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
2064 if (overwrite && (insertPos < trackDuration)) {
2065 // Replace zone with blanks
2066 //trackPlaylist.split_at(insertPos, true);
2067 trackPlaylist.remove_region(insertPos, cutDuration + 1);
2068 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2069 trackPlaylist.insert_blank(clipIndex, cutDuration);
2071 trackPlaylist.split_at(insertPos, true);
2072 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2073 trackPlaylist.insert_blank(clipIndex, cutDuration);
2075 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
2077 /*if (QString(prod->get("transparency")).toInt() == 1)
2078 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
2080 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
2082 /*tractor.multitrack()->refresh();
2083 tractor.refresh();*/
2088 bool Render::mltCutClip(int track, GenTime position)
2090 Mlt::Service service(m_mltProducer->parent().get_service());
2091 if (service.type() != tractor_type) {
2092 kWarning() << "// TRACTOR PROBLEM";
2096 Mlt::Tractor tractor(service);
2097 Mlt::Producer trackProducer(tractor.track(track));
2098 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2101 /* // Display playlist info
2102 kDebug()<<"//////////// BEFORE";
2103 for (int i = 0; i < trackPlaylist.count(); i++) {
2104 int blankStart = trackPlaylist.clip_start(i);
2105 int blankDuration = trackPlaylist.clip_length(i) - 1;
2107 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2108 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2111 int cutPos = (int) position.frames(m_fps);
2113 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
2114 if (trackPlaylist.is_blank(clipIndex)) {
2115 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
2119 int clipStart = trackPlaylist.clip_start(clipIndex);
2120 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
2123 // duplicate effects
2124 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
2125 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
2127 if (original == NULL || clip == NULL) {
2128 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
2132 Mlt::Service clipService(original->get_service());
2133 Mlt::Service dupService(clip->get_service());
2139 Mlt::Filter *filter = clipService.filter(ct);
2141 // Only duplicate Kdenlive filters, and skip the fade in effects
2142 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
2143 // looks like there is no easy way to duplicate a filter,
2144 // so we will create a new one and duplicate its properties
2145 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
2146 if (dup && dup->is_valid()) {
2147 Mlt::Properties entries(filter->get_properties());
2148 for (int i = 0; i < entries.count(); i++) {
2149 dup->set(entries.get_name(i), entries.get(i));
2151 dupService.attach(*dup);
2155 filter = clipService.filter(ct);
2158 /* // Display playlist info
2159 kDebug()<<"//////////// AFTER";
2160 for (int i = 0; i < trackPlaylist.count(); i++) {
2161 int blankStart = trackPlaylist.clip_start(i);
2162 int blankDuration = trackPlaylist.clip_length(i) - 1;
2164 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2165 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2170 Mlt::Tractor *Render::lockService()
2172 // we are going to replace some clips, purge consumer
2173 if (!m_mltProducer) return NULL;
2174 QMutexLocker locker(&m_mutex);
2175 if (m_mltConsumer) {
2176 m_mltConsumer->purge();
2178 Mlt::Service service(m_mltProducer->parent().get_service());
2179 if (service.type() != tractor_type) {
2183 return new Mlt::Tractor(service);
2187 void Render::unlockService(Mlt::Tractor *tractor)
2192 if (!m_mltProducer) return;
2193 Mlt::Service service(m_mltProducer->parent().get_service());
2194 if (service.type() != tractor_type) {
2195 kWarning() << "// TRACTOR PROBLEM";
2201 bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement element, Mlt::Producer *prod)
2204 if (prod == NULL || tractor == NULL) {
2205 kDebug() << "Cannot update clip with null producer //////";
2209 Mlt::Producer trackProducer(tractor->track(tractor->count() - 1 - info.track));
2210 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2211 int startPos = info.startPos.frames(m_fps);
2212 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2213 if (trackPlaylist.is_blank(clipIndex)) {
2214 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
2217 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2219 QList <Mlt::Filter *> filtersList;
2220 Mlt::Service sourceService(clip->get_service());
2222 Mlt::Filter *filter = sourceService.filter(ct);
2224 if (filter->get_int("kdenlive_ix") != 0) {
2225 filtersList.append(filter);
2228 filter = sourceService.filter(ct);
2231 clip = trackPlaylist.replace_with_blank(clipIndex);
2233 prod = checkSlowMotionProducer(prod, element);
2234 if (prod == NULL || !prod->is_valid()) {
2238 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
2239 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
2240 Mlt::Service destService(clip2->get_service());
2243 if (!filtersList.isEmpty()) {
2244 for (int i = 0; i < filtersList.count(); i++)
2245 destService.attach(*(filtersList.at(i)));
2251 bool Render::mltRemoveClip(int track, GenTime position)
2253 m_refreshTimer.stop();
2255 Mlt::Service service(m_mltProducer->parent().get_service());
2256 if (service.type() != tractor_type) {
2257 kWarning() << "// TRACTOR PROBLEM";
2261 Mlt::Tractor tractor(service);
2262 Mlt::Producer trackProducer(tractor.track(track));
2263 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2264 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2266 if (trackPlaylist.is_blank(clipIndex)) {
2267 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
2271 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2272 if (clip) delete clip;
2273 trackPlaylist.consolidate_blanks(0);
2275 /* // Display playlist info
2276 kDebug()<<"//// AFTER";
2277 for (int i = 0; i < trackPlaylist.count(); i++) {
2278 int blankStart = trackPlaylist.clip_start(i);
2279 int blankDuration = trackPlaylist.clip_length(i) - 1;
2281 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2282 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2285 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
2289 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
2291 if (!m_mltProducer) {
2292 kDebug() << "PLAYLIST NOT INITIALISED //////";
2295 Mlt::Producer parentProd(m_mltProducer->parent());
2296 if (parentProd.get_producer() == NULL) {
2297 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2301 Mlt::Service service(parentProd.get_service());
2302 Mlt::Tractor tractor(service);
2303 int insertPos = pos.frames(m_fps);
2305 Mlt::Producer trackProducer(tractor.track(track));
2306 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2307 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2308 if (clipIndex == trackPlaylist.count()) {
2309 // We are after the end of the playlist
2312 if (!trackPlaylist.is_blank(clipIndex)) return 0;
2313 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
2314 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
2317 int Render::mltTrackDuration(int track)
2319 if (!m_mltProducer) {
2320 kDebug() << "PLAYLIST NOT INITIALISED //////";
2323 Mlt::Producer parentProd(m_mltProducer->parent());
2324 if (parentProd.get_producer() == NULL) {
2325 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2329 Mlt::Service service(parentProd.get_service());
2330 Mlt::Tractor tractor(service);
2332 Mlt::Producer trackProducer(tractor.track(track));
2333 return trackProducer.get_playtime() - 1;
2336 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
2338 if (!m_mltProducer) {
2339 kDebug() << "PLAYLIST NOT INITIALISED //////";
2342 Mlt::Producer parentProd(m_mltProducer->parent());
2343 if (parentProd.get_producer() == NULL) {
2344 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2347 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
2348 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
2350 Mlt::Service service(parentProd.get_service());
2351 Mlt::Tractor tractor(service);
2353 int diff = duration.frames(m_fps);
2354 int offset = timeOffset.frames(m_fps);
2358 // insert space in one track only
2359 Mlt::Producer trackProducer(tractor.track(track));
2360 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2361 insertPos = trackClipStartList.value(track);
2362 if (insertPos != -1) {
2363 insertPos += offset;
2364 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2366 trackPlaylist.insert_blank(clipIndex, diff - 1);
2368 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
2369 if (!trackPlaylist.is_blank(clipIndex)) {
2370 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2372 int position = trackPlaylist.clip_start(clipIndex);
2373 int blankDuration = trackPlaylist.clip_length(clipIndex);
2374 if (blankDuration + diff == 0) {
2375 trackPlaylist.remove(clipIndex);
2376 } else trackPlaylist.remove_region(position, -diff);
2378 trackPlaylist.consolidate_blanks(0);
2380 // now move transitions
2381 mlt_service serv = m_mltProducer->parent().get_service();
2382 mlt_service nextservice = mlt_service_get_producer(serv);
2383 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2384 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2385 QString resource = mlt_properties_get(properties, "mlt_service");
2387 while (mlt_type == "transition") {
2388 mlt_transition tr = (mlt_transition) nextservice;
2389 int currentTrack = mlt_transition_get_b_track(tr);
2390 int currentIn = (int) mlt_transition_get_in(tr);
2391 int currentOut = (int) mlt_transition_get_out(tr);
2392 insertPos = trackTransitionStartList.value(track);
2393 if (insertPos != -1) {
2394 insertPos += offset;
2395 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
2396 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2399 nextservice = mlt_service_producer(nextservice);
2400 if (nextservice == NULL) break;
2401 properties = MLT_SERVICE_PROPERTIES(nextservice);
2402 mlt_type = mlt_properties_get(properties, "mlt_type");
2403 resource = mlt_properties_get(properties, "mlt_service");
2406 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
2407 Mlt::Producer trackProducer(tractor.track(trackNb));
2408 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2410 //int clipNb = trackPlaylist.count();
2411 insertPos = trackClipStartList.value(trackNb);
2412 if (insertPos != -1) {
2413 insertPos += offset;
2415 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2416 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2417 for (int i = 0; i < clipNb; i++) {
2418 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2419 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2420 kDebug()<<"-------------";
2422 kDebug()<<"END-------------";*/
2425 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2427 trackPlaylist.insert_blank(clipIndex, diff - 1);
2429 if (!trackPlaylist.is_blank(clipIndex)) {
2432 if (!trackPlaylist.is_blank(clipIndex)) {
2433 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2435 int position = trackPlaylist.clip_start(clipIndex);
2436 int blankDuration = trackPlaylist.clip_length(clipIndex);
2437 if (diff + blankDuration == 0) {
2438 trackPlaylist.remove(clipIndex);
2439 } else trackPlaylist.remove_region(position, - diff);
2441 trackPlaylist.consolidate_blanks(0);
2444 // now move transitions
2445 mlt_service serv = m_mltProducer->parent().get_service();
2446 mlt_service nextservice = mlt_service_get_producer(serv);
2447 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2448 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2449 QString resource = mlt_properties_get(properties, "mlt_service");
2451 while (mlt_type == "transition") {
2452 mlt_transition tr = (mlt_transition) nextservice;
2453 int currentIn = (int) mlt_transition_get_in(tr);
2454 int currentOut = (int) mlt_transition_get_out(tr);
2455 int currentTrack = mlt_transition_get_b_track(tr);
2456 insertPos = trackTransitionStartList.value(currentTrack);
2457 if (insertPos != -1) {
2458 insertPos += offset;
2459 if (currentOut > insertPos && resource != "mix") {
2460 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2463 nextservice = mlt_service_producer(nextservice);
2464 if (nextservice == NULL) break;
2465 properties = MLT_SERVICE_PROPERTIES(nextservice);
2466 mlt_type = mlt_properties_get(properties, "mlt_type");
2467 resource = mlt_properties_get(properties, "mlt_service");
2471 mltCheckLength(&tractor);
2472 m_mltConsumer->set("refresh", 1);
2476 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2478 if (source == dest) return;
2479 Mlt::Service sourceService(source->get_service());
2480 Mlt::Service destService(dest->get_service());
2482 // move all effects to the correct producer
2484 Mlt::Filter *filter = sourceService.filter(ct);
2486 if (filter->get_int("kdenlive_ix") != 0) {
2487 sourceService.detach(*filter);
2488 destService.attach(*filter);
2490 filter = sourceService.filter(ct);
2494 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2497 Mlt::Service service(m_mltProducer->parent().get_service());
2498 if (service.type() != tractor_type) {
2499 kWarning() << "// TRACTOR PROBLEM";
2503 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2504 Mlt::Tractor tractor(service);
2505 Mlt::Producer trackProducer(tractor.track(info.track));
2506 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2507 int startPos = info.startPos.frames(m_fps);
2508 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2509 int clipLength = trackPlaylist.clip_length(clipIndex);
2511 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2512 if (original == NULL) {
2515 if (!original->is_valid() || original->is_blank()) {
2520 Mlt::Producer clipparent = original->parent();
2521 if (!clipparent.is_valid() || clipparent.is_blank()) {
2527 QString serv = clipparent.get("mlt_service");
2528 QString id = clipparent.get("id");
2529 if (speed <= 0 && speed > -1) speed = 1.0;
2530 //kDebug() << "CLIP SERVICE: " << serv;
2531 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2533 QString url = QString::fromUtf8(clipparent.get("resource"));
2534 url.append('?' + m_locale.toString(speed));
2535 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2536 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2537 if (!slowprod || slowprod->get_producer() == NULL) {
2538 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2539 if (strobe > 1) slowprod->set("strobe", strobe);
2540 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2541 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2542 slowprod->set("id", producerid.toUtf8().constData());
2543 // copy producer props
2544 double ar = original->parent().get_double("force_aspect_ratio");
2545 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2546 double fps = original->parent().get_double("force_fps");
2547 if (fps != 0.0) slowprod->set("force_fps", fps);
2548 int threads = original->parent().get_int("threads");
2549 if (threads != 0) slowprod->set("threads", threads);
2550 if (original->parent().get("force_progressive"))
2551 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2552 if (original->parent().get("force_tff"))
2553 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2554 int ix = original->parent().get_int("video_index");
2555 if (ix != 0) slowprod->set("video_index", ix);
2556 int colorspace = original->parent().get_int("force_colorspace");
2557 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2558 int full_luma = original->parent().get_int("set.force_full_luma");
2559 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2560 m_slowmotionProducers.insert(url, slowprod);
2562 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2563 trackPlaylist.consolidate_blanks(0);
2565 // Check that the blank space is long enough for our new duration
2566 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2567 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2569 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2570 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2571 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2572 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2574 // move all effects to the correct producer
2575 mltPasteEffects(clip, cut);
2576 trackPlaylist.insert_at(startPos, cut, 1);
2579 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2580 newLength = trackPlaylist.clip_length(clipIndex);
2582 } else if (speed == 1.0 && strobe < 2) {
2585 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2586 trackPlaylist.consolidate_blanks(0);
2588 // Check that the blank space is long enough for our new duration
2589 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2590 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2593 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2594 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2595 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2596 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2597 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2599 // move all effects to the correct producer
2600 mltPasteEffects(clip, cut);
2602 trackPlaylist.insert_at(startPos, cut, 1);
2605 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2606 newLength = trackPlaylist.clip_length(clipIndex);
2609 } else if (serv == "framebuffer") {
2611 QString url = QString::fromUtf8(clipparent.get("resource"));
2612 url = url.section('?', 0, 0);
2613 url.append('?' + m_locale.toString(speed));
2614 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2615 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2616 if (!slowprod || slowprod->get_producer() == NULL) {
2617 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2618 slowprod->set("strobe", strobe);
2619 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2620 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2621 slowprod->set("id", producerid.toUtf8().constData());
2622 // copy producer props
2623 double ar = original->parent().get_double("force_aspect_ratio");
2624 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2625 double fps = original->parent().get_double("force_fps");
2626 if (fps != 0.0) slowprod->set("force_fps", fps);
2627 if (original->parent().get("force_progressive"))
2628 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2629 if (original->parent().get("force_tff"))
2630 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2631 int threads = original->parent().get_int("threads");
2632 if (threads != 0) slowprod->set("threads", threads);
2633 int ix = original->parent().get_int("video_index");
2634 if (ix != 0) slowprod->set("video_index", ix);
2635 int colorspace = original->parent().get_int("force_colorspace");
2636 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2637 int full_luma = original->parent().get_int("set.force_full_luma");
2638 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2639 m_slowmotionProducers.insert(url, slowprod);
2641 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2642 trackPlaylist.consolidate_blanks(0);
2644 GenTime duration = speedIndependantInfo.cropDuration / speed;
2645 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2647 // Check that the blank space is long enough for our new duration
2648 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2649 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2652 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2653 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2654 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2655 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2657 // move all effects to the correct producer
2658 mltPasteEffects(clip, cut);
2660 trackPlaylist.insert_at(startPos, cut, 1);
2663 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2664 newLength = trackPlaylist.clip_length(clipIndex);
2669 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2673 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2675 Mlt::Service service(m_mltProducer->parent().get_service());
2676 bool success = false;
2677 Mlt::Tractor tractor(service);
2678 Mlt::Producer trackProducer(tractor.track(track));
2679 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2680 Mlt::Service clipService(trackPlaylist.get_service());
2684 Mlt::Filter *filter = clipService.filter(ct);
2686 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2687 if (clipService.detach(*filter) == 0) success = true;
2688 } else if (updateIndex) {
2689 // Adjust the other effects index
2690 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2693 filter = clipService.filter(ct);
2700 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2702 if (position < GenTime()) {
2703 // Remove track effect
2704 return mltRemoveTrackEffect(track, index, updateIndex);
2706 Mlt::Service service(m_mltProducer->parent().get_service());
2707 bool success = false;
2708 Mlt::Tractor tractor(service);
2709 Mlt::Producer trackProducer(tractor.track(track));
2710 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2712 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2713 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2715 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2719 Mlt::Service clipService(clip->get_service());
2720 int duration = clip->get_playtime();
2722 // Check if clip is visible in monitor
2723 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2724 if (diff < 0 || diff > duration) doRefresh = false;
2730 Mlt::Filter *filter = clipService.filter(ct);
2732 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2733 if (clipService.detach(*filter) == 0) success = true;
2734 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2735 } else if (updateIndex) {
2736 // Adjust the other effects index
2737 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2740 filter = clipService.filter(ct);
2743 if (doRefresh) refresh();
2747 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2749 Mlt::Service service(m_mltProducer->parent().get_service());
2750 Mlt::Tractor tractor(service);
2751 Mlt::Producer trackProducer(tractor.track(track));
2752 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2753 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2754 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2758 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2761 Mlt::Service service(m_mltProducer->parent().get_service());
2763 Mlt::Tractor tractor(service);
2764 Mlt::Producer trackProducer(tractor.track(track));
2765 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2767 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2768 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2773 Mlt::Service clipService(clip->get_service());
2774 int duration = clip->get_playtime();
2776 // Check if clip is visible in monitor
2777 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2778 if (diff < 0 || diff > duration) doRefresh = false;
2781 return mltAddEffect(clipService, params, duration, doRefresh);
2784 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2786 bool updateIndex = false;
2787 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2791 Mlt::Filter *filter = service.filter(ct);
2793 if (filter->get_int("kdenlive_ix") == filter_ix) {
2794 // A filter at that position already existed, so we will increase all indexes later
2799 filter = service.filter(ct);
2802 if (params.paramValue("id") == "speed") {
2803 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2805 filter = service.filter(ct);
2807 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2808 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2811 filter = service.filter(ct);
2814 if (doRefresh) refresh();
2819 // temporarily remove all effects after insert point
2820 QList <Mlt::Filter *> filtersList;
2822 filter = service.filter(ct);
2824 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2825 filtersList.append(filter);
2826 service.detach(*filter);
2828 filter = service.filter(ct);
2831 addFilterToService(service, params, duration);
2833 // re-add following filters
2834 for (int i = 0; i < filtersList.count(); i++) {
2835 Mlt::Filter *filter = filtersList.at(i);
2837 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2838 service.attach(*filter);
2841 if (doRefresh) refresh();
2846 bool Render::addFilterToService(Mlt::Service service, EffectsParameterList params, int duration)
2849 QString tag = params.paramValue("tag");
2850 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2851 char *filterTag = qstrdup(tag.toUtf8().constData());
2852 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2853 QString kfr = params.paramValue("keyframes");
2854 if (!kfr.isEmpty()) {
2855 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2856 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2857 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2858 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2859 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2860 //double max = params.paramValue("max").toDouble();
2861 double min = params.paramValue("min").toDouble();
2862 double factor = params.paramValue("factor", "1").toDouble();
2863 double paramOffset = params.paramValue("offset", "0").toDouble();
2864 params.removeParam("starttag");
2865 params.removeParam("endtag");
2866 params.removeParam("keyframes");
2867 params.removeParam("min");
2868 params.removeParam("max");
2869 params.removeParam("factor");
2870 params.removeParam("offset");
2872 // Special case, only one keyframe, means we want a constant value
2873 if (keyFrames.count() == 1) {
2874 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2875 if (filter && filter->is_valid()) {
2876 filter->set("kdenlive_id", filterId);
2877 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2878 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2879 for (int j = 0; j < params.count(); j++) {
2880 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2882 filter->set("in", x1);
2883 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2884 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2885 service.attach(*filter);
2887 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2888 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2889 if (filter && filter->is_valid()) {
2890 filter->set("kdenlive_id", filterId);
2891 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2892 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2893 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2894 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2895 if (x2 == -1) x2 = duration;
2897 for (int j = 0; j < params.count(); j++) {
2898 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2901 filter->set("in", x1);
2902 filter->set("out", x2);
2903 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2904 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2905 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2906 service.attach(*filter);
2913 Mlt::Filter *filter;
2915 filter = new Mlt::Filter(*m_mltProfile, filterTag);
2916 if (filter && filter->is_valid()) {
2917 filter->set("kdenlive_id", filterId);
2919 kDebug() << "filter is NULL";
2923 params.removeParam("kdenlive_id");
2924 if (params.hasParam("_sync_in_out")) {
2925 // This effect must sync in / out with parent clip
2926 params.removeParam("_sync_in_out");
2927 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2930 for (int j = 0; j < params.count(); j++) {
2931 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2935 QString effectArgs = params.paramValue("id").section('_', 1);
2937 params.removeParam("id");
2938 params.removeParam("kdenlive_ix");
2939 params.removeParam("tag");
2940 params.removeParam("disable");
2941 params.removeParam("region");
2943 for (int j = 0; j < params.count(); j++) {
2944 effectArgs.append(' ' + params.at(j).value());
2946 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2947 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2949 // attach filter to the clip
2950 service.attach(*filter);
2958 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2960 Mlt::Service service(m_mltProducer->parent().get_service());
2961 Mlt::Tractor tractor(service);
2962 Mlt::Producer trackProducer(tractor.track(track));
2963 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2964 Mlt::Service clipService(trackPlaylist.get_service());
2966 QString index = params.paramValue("kdenlive_ix");
2967 QString tag = params.paramValue("tag");
2969 Mlt::Filter *filter = clipService.filter(ct);
2971 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2975 filter = clipService.filter(ct);
2979 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2980 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2982 bool success = false;//mltAddTrackEffect(track, params);
2986 QString ser = filter->get("mlt_service");
2987 if (ser == "region") prefix = "filter0.";
2989 for (int j = 0; j < params.count(); j++) {
2990 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2998 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
3000 int index = params.paramValue("kdenlive_ix").toInt();
3001 QString tag = params.paramValue("tag");
3003 if (!params.paramValue("keyframes").isEmpty() || (tag == "affine" && params.hasParam("background")) || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
3004 // This is a keyframe effect, to edit it, we remove it and re-add it.
3005 bool success = mltRemoveEffect(track, position, index, false);
3006 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
3007 if (position < GenTime())
3008 success = mltAddTrackEffect(track, params);
3010 success = mltAddEffect(track, position, params);
3011 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
3014 if (position < GenTime()) {
3015 return mltEditTrackEffect(track, params);
3018 Mlt::Service service(m_mltProducer->parent().get_service());
3019 Mlt::Tractor tractor(service);
3020 Mlt::Producer trackProducer(tractor.track(track));
3021 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3023 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3024 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3026 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3030 int duration = clip->get_playtime();
3031 bool doRefresh = true;
3032 // Check if clip is visible in monitor
3033 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3034 if (diff < 0 || diff > duration)
3038 Mlt::Filter *filter = clip->filter(ct);
3040 if (filter->get_int("kdenlive_ix") == index) {
3044 filter = clip->filter(ct);
3048 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
3049 // filter was not found, it was probably a disabled filter, so add it to the correct place...
3051 bool success = mltAddEffect(track, position, params);
3055 QString ser = filter->get("mlt_service");
3056 QList <Mlt::Filter *> filtersList;
3059 // Effect service changes, delete effect and re-add it
3060 clip->detach(*filter);
3062 // Delete all effects after deleted one
3063 filter = clip->filter(ct);
3065 if (filter->get_int("kdenlive_ix") > index) {
3066 filtersList.append(filter);
3067 clip->detach(*filter);
3070 filter = clip->filter(ct);
3074 addFilterToService(*clip, params, clip->get_playtime());
3078 if (doRefresh) refresh();
3081 if (params.hasParam("_sync_in_out")) {
3082 // This effect must sync in / out with parent clip
3083 params.removeParam("_sync_in_out");
3084 filter->set_in_and_out(clip->get_in(), clip->get_out());
3087 for (int j = 0; j < params.count(); j++) {
3088 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
3091 for (int j = 0; j < filtersList.count(); j++) {
3092 clip->attach(*(filtersList.at(j)));
3098 if (doRefresh) refresh();
3102 bool Render::mltEnableEffects(int track, GenTime position, QList <int> effectIndexes, bool disable)
3104 if (position < GenTime()) {
3105 return mltEnableTrackEffects(track, effectIndexes, disable);
3108 Mlt::Service service(m_mltProducer->parent().get_service());
3109 Mlt::Tractor tractor(service);
3110 Mlt::Producer trackProducer(tractor.track(track));
3111 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3113 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3114 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3116 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3120 int duration = clip->get_playtime();
3121 bool doRefresh = true;
3122 // Check if clip is visible in monitor
3123 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3124 if (diff < 0 || diff > duration)
3128 Mlt::Filter *filter = clip->filter(ct);
3130 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3131 filter->set("disable", (int) disable);
3134 filter = clip->filter(ct);
3140 if (doRefresh) refresh();
3144 bool Render::mltEnableTrackEffects(int track, QList <int> effectIndexes, bool disable)
3146 Mlt::Service service(m_mltProducer->parent().get_service());
3147 Mlt::Tractor tractor(service);
3148 Mlt::Producer trackProducer(tractor.track(track));
3149 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3150 Mlt::Service clipService(trackPlaylist.get_service());
3153 Mlt::Filter *filter = clipService.filter(ct);
3155 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3156 filter->set("disable", (int) disable);
3159 filter = clipService.filter(ct);
3167 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
3169 Mlt::Service service(m_mltProducer->parent().get_service());
3170 Mlt::Tractor tractor(service);
3171 Mlt::Producer trackProducer(tractor.track(track));
3172 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3174 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3175 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3177 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3181 Mlt::Service clipService(clip->get_service());
3182 int duration = clip->get_playtime();
3183 bool doRefresh = true;
3184 // Check if clip is visible in monitor
3185 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3186 if (diff < 0 || diff > duration) doRefresh = false;
3190 Mlt::Filter *filter = clipService.filter(ct);
3192 int pos = filter->get_int("kdenlive_ix");
3193 if (pos == oldPos) {
3194 filter->set("kdenlive_ix", newPos);
3196 filter = clipService.filter(ct);
3198 if (doRefresh) refresh();
3201 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
3203 if (position < GenTime()) {
3204 mltMoveTrackEffect(track, oldPos, newPos);
3207 Mlt::Service service(m_mltProducer->parent().get_service());
3208 Mlt::Tractor tractor(service);
3209 Mlt::Producer trackProducer(tractor.track(track));
3210 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3212 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3213 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3215 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3219 Mlt::Service clipService(clip->get_service());
3220 int duration = clip->get_playtime();
3221 bool doRefresh = true;
3222 // Check if clip is visible in monitor
3223 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3224 if (diff < 0 || diff > duration) doRefresh = false;
3228 QList <Mlt::Filter *> filtersList;
3229 Mlt::Filter *filter = clipService.filter(ct);
3231 if (newPos > oldPos) {
3233 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3234 filter->set("kdenlive_ix", newPos);
3235 filtersList.append(filter);
3236 clipService.detach(*filter);
3237 filter = clipService.filter(ct);
3238 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3239 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3241 filter = clipService.filter(ct);
3245 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3246 filtersList.append(filter);
3247 clipService.detach(*filter);
3249 filter = clipService.filter(ct);
3253 if (filter->get_int("kdenlive_ix") == oldPos) {
3254 filter->set("kdenlive_ix", newPos);
3255 filtersList.append(filter);
3256 clipService.detach(*filter);
3258 filter = clipService.filter(ct);
3262 filter = clipService.filter(ct);
3264 int pos = filter->get_int("kdenlive_ix");
3265 if (pos >= newPos) {
3266 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3267 filtersList.append(filter);
3268 clipService.detach(*filter);
3270 filter = clipService.filter(ct);
3274 for (int i = 0; i < filtersList.count(); i++) {
3275 clipService.attach(*(filtersList.at(i)));
3278 if (doRefresh) refresh();
3281 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
3283 Mlt::Service service(m_mltProducer->parent().get_service());
3284 Mlt::Tractor tractor(service);
3285 Mlt::Producer trackProducer(tractor.track(track));
3286 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3287 Mlt::Service clipService(trackPlaylist.get_service());
3289 QList <Mlt::Filter *> filtersList;
3290 Mlt::Filter *filter = clipService.filter(ct);
3292 if (newPos > oldPos) {
3294 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3295 filter->set("kdenlive_ix", newPos);
3296 filtersList.append(filter);
3297 clipService.detach(*filter);
3298 filter = clipService.filter(ct);
3299 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3300 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3302 filter = clipService.filter(ct);
3306 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3307 filtersList.append(filter);
3308 clipService.detach(*filter);
3310 filter = clipService.filter(ct);
3314 if (filter->get_int("kdenlive_ix") == oldPos) {
3315 filter->set("kdenlive_ix", newPos);
3316 filtersList.append(filter);
3317 clipService.detach(*filter);
3319 filter = clipService.filter(ct);
3323 filter = clipService.filter(ct);
3325 int pos = filter->get_int("kdenlive_ix");
3326 if (pos >= newPos) {
3327 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3328 filtersList.append(filter);
3329 clipService.detach(*filter);
3331 filter = clipService.filter(ct);
3335 for (int i = 0; i < filtersList.count(); i++) {
3336 clipService.attach(*(filtersList.at(i)));
3341 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration, bool refresh)
3343 Mlt::Service service(m_mltProducer->parent().get_service());
3344 Mlt::Tractor tractor(service);
3345 Mlt::Producer trackProducer(tractor.track(info.track));
3346 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3348 /* // Display playlist info
3349 kDebug()<<"//////////// BEFORE RESIZE";
3350 for (int i = 0; i < trackPlaylist.count(); i++) {
3351 int blankStart = trackPlaylist.clip_start(i);
3352 int blankDuration = trackPlaylist.clip_length(i) - 1;
3354 if (trackPlaylist.is_blank(i)) blk = "(blank)";
3355 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
3358 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
3359 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3363 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
3364 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
3365 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3367 int previousStart = clip->get_in();
3368 int newDuration = (int) clipDuration.frames(m_fps) - 1;
3369 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
3371 int currentOut = newDuration + previousStart;
3372 if (currentOut > clip->get_length()) {
3373 clip->parent().set("length", currentOut + 1);
3374 clip->parent().set("out", currentOut);
3375 clip->set("length", currentOut + 1);
3378 /*if (newDuration > clip->get_out()) {
3379 clip->parent().set_in_and_out(0, newDuration + 1);
3380 clip->set_in_and_out(0, newDuration + 1);
3383 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
3384 trackPlaylist.consolidate_blanks(0);
3385 // skip to next clip
3387 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
3389 // clip was made longer, trim next blank if there is one.
3390 if (clipIndex < trackPlaylist.count()) {
3391 // If this is not the last clip in playlist
3392 if (trackPlaylist.is_blank(clipIndex)) {
3393 int blankStart = trackPlaylist.clip_start(clipIndex);
3394 int blankDuration = trackPlaylist.clip_length(clipIndex);
3395 if (diff > blankDuration) {
3396 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
3398 if (diff - blankDuration == 0) {
3399 trackPlaylist.remove(clipIndex);
3400 } else trackPlaylist.remove_region(blankStart, diff);
3402 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
3405 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
3406 trackPlaylist.consolidate_blanks(0);
3409 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
3410 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3411 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
3412 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3413 ItemInfo transpinfo;
3414 transpinfo.startPos = info.startPos;
3415 transpinfo.endPos = info.startPos + clipDuration;
3416 transpinfo.track = info.track;
3417 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3419 if (refresh) m_mltConsumer->set("refresh", 1);
3423 void Render::mltChangeTrackState(int track, bool mute, bool blind)
3425 Mlt::Service service(m_mltProducer->parent().get_service());
3426 Mlt::Tractor tractor(service);
3427 Mlt::Producer trackProducer(tractor.track(track));
3429 // Make sure muting will not produce problems with our audio mixing transition,
3430 // because audio mixing is done between each track and the lowest one
3431 bool audioMixingBroken = false;
3432 if (mute && trackProducer.get_int("hide") < 2 ) {
3433 // We mute a track with sound
3434 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3435 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
3437 else if (!mute && trackProducer.get_int("hide") > 1 ) {
3438 // We un-mute a previously muted track
3439 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3443 if (blind) trackProducer.set("hide", 3);
3444 else trackProducer.set("hide", 2);
3446 trackProducer.set("hide", 1);
3448 trackProducer.set("hide", 0);
3450 if (audioMixingBroken) fixAudioMixing(tractor);
3452 tractor.multitrack()->refresh();
3457 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
3459 for (int i = 1; i < tractor.count(); i++) {
3460 Mlt::Producer trackProducer(tractor.track(i));
3461 if (trackProducer.get_int("hide") < 2) return i;
3463 return tractor.count() - 1;
3466 void Render::fixAudioMixing(Mlt::Tractor tractor)
3468 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
3469 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
3471 mlt_service serv = m_mltProducer->parent().get_service();
3472 Mlt::Field *field = tractor.field();
3473 mlt_service_lock(serv);
3475 mlt_service nextservice = mlt_service_get_producer(serv);
3476 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3477 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3478 QString resource = mlt_properties_get(properties, "mlt_service");
3480 mlt_service nextservicetodisconnect;
3481 // Delete all audio mixing transitions
3482 while (mlt_type == "transition") {
3483 if (resource == "mix") {
3484 nextservicetodisconnect = nextservice;
3485 nextservice = mlt_service_producer(nextservice);
3486 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
3488 else nextservice = mlt_service_producer(nextservice);
3489 if (nextservice == NULL) break;
3490 properties = MLT_SERVICE_PROPERTIES(nextservice);
3491 mlt_type = mlt_properties_get(properties, "mlt_type");
3492 resource = mlt_properties_get(properties, "mlt_service");
3495 // Re-add correct audio transitions
3496 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
3497 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3498 transition->set("always_active", 1);
3499 transition->set("combine", 1);
3500 transition->set("internal_added", 237);
3501 field->plant_transition(*transition, lowestTrack, i);
3503 mlt_service_unlock(serv);
3506 bool Render::mltResizeClipCrop(ItemInfo info, GenTime newCropStart)
3508 Mlt::Service service(m_mltProducer->parent().get_service());
3509 int newCropFrame = (int) newCropStart.frames(m_fps);
3510 Mlt::Tractor tractor(service);
3511 Mlt::Producer trackProducer(tractor.track(info.track));
3512 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3513 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3514 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3518 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3519 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3521 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3525 int previousStart = clip->get_in();
3526 int previousOut = clip->get_out();
3528 if (previousStart == newCropFrame) {
3529 kDebug() << "//////// No ReSIZING Required";
3533 int frameOffset = newCropFrame - previousStart;
3534 trackPlaylist.resize_clip(clipIndex, newCropFrame, previousOut + frameOffset);
3536 m_mltConsumer->set("refresh", 1);
3540 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3542 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3543 Mlt::Service service(m_mltProducer->parent().get_service());
3544 int moveFrame = (int) diff.frames(m_fps);
3545 Mlt::Tractor tractor(service);
3546 Mlt::Producer trackProducer(tractor.track(info.track));
3547 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3548 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3549 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3553 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3554 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3555 if (clip == NULL || clip->is_blank()) {
3556 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3560 int previousStart = clip->get_in();
3561 int previousOut = clip->get_out();
3563 previousStart += moveFrame;
3565 if (previousStart < 0) {
3566 // this is possible for images and color clips
3567 previousOut -= previousStart;
3571 int length = previousOut + 1;
3572 if (length > clip->get_length()) {
3573 clip->parent().set("length", length + 1);
3574 clip->parent().set("out", length);
3575 clip->set("length", length + 1);
3579 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3580 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3581 if (moveFrame > 0) {
3582 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3584 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3585 int blankIndex = clipIndex - 1;
3586 int blankLength = trackPlaylist.clip_length(blankIndex);
3587 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3588 if (! trackPlaylist.is_blank(blankIndex)) {
3589 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3591 if (blankLength + moveFrame == 0)
3592 trackPlaylist.remove(blankIndex);
3594 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3596 trackPlaylist.consolidate_blanks(0);
3597 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3598 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3599 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3600 ItemInfo transpinfo;
3601 transpinfo.startPos = info.startPos + diff;
3602 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3603 transpinfo.track = info.track;
3604 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3606 //m_mltConsumer->set("refresh", 1);
3608 m_mltConsumer->set("refresh", 1);
3612 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3614 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3618 bool Render::mltUpdateClipProducer(Mlt::Tractor *tractor, int track, int pos, Mlt::Producer *prod)
3620 if (prod == NULL || !prod->is_valid() || tractor == NULL || !tractor->is_valid()) {
3621 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3625 Mlt::Producer trackProducer(tractor->track(track));
3626 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3627 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3628 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3629 if (clipProducer == NULL || clipProducer->is_blank()) {
3630 kDebug() << "// ERROR UPDATING CLIP PROD";
3631 delete clipProducer;
3634 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3635 if (!clip || !clip->is_valid()) {
3636 if (clip) delete clip;
3637 delete clipProducer;
3640 // move all effects to the correct producer
3641 mltPasteEffects(clipProducer, clip);
3642 trackPlaylist.insert_at(pos, clip, 1);
3644 delete clipProducer;
3648 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3650 Mlt::Service service(m_mltProducer->parent().get_service());
3651 if (service.type() != tractor_type) {
3652 kWarning() << "// TRACTOR PROBLEM";
3656 Mlt::Tractor tractor(service);
3658 Mlt::Producer trackProducer(tractor.track(startTrack));
3659 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3660 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3661 int clipDuration = trackPlaylist.clip_length(clipIndex);
3662 bool checkLength = false;
3663 if (endTrack == startTrack) {
3664 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3666 bool success = true;
3667 if (!trackPlaylist.is_blank_at(moveEnd) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3671 // Check that the destination region is empty
3672 trackPlaylist.consolidate_blanks(0);
3673 int destinationIndex = trackPlaylist.get_clip_index_at(moveEnd);
3674 if (destinationIndex < trackPlaylist.count() - 1) {
3675 // We are not at the end of the track
3676 int blankSize = trackPlaylist.blanks_from(destinationIndex, 1);
3677 // Make sure we have enough place to insert clip
3678 if (blankSize - clipDuration - (moveEnd - trackPlaylist.clip_start(destinationIndex)) < 0) success = false;
3683 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3684 delete clipProducer;
3686 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3693 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3694 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3695 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3697 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3698 if (newIndex == -1) {
3699 kDebug()<<"// CANNOT MOVE CLIP TO: "<<moveEnd;
3700 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3701 delete clipProducer;
3705 trackPlaylist.consolidate_blanks(1);
3706 delete clipProducer;
3707 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3709 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3710 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3711 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3712 // error, destination is not empty
3713 kDebug() << "Cannot move: Destination is not empty";
3717 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3718 if (!clipProducer || clipProducer->is_blank()) {
3719 // error, destination is not empty
3720 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3721 if (clipProducer) delete clipProducer;
3722 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3726 trackPlaylist.consolidate_blanks(0);
3727 destTrackPlaylist.consolidate_blanks(1);
3728 Mlt::Producer *clip;
3729 // check if we are moving a slowmotion producer
3730 QString serv = clipProducer->parent().get("mlt_service");
3731 QString currentid = clipProducer->parent().get("id");
3732 if (serv == "framebuffer") {
3733 clip = clipProducer;
3736 // Special case: prod is null when using placeholder clips.
3737 // in that case, use the producer existing in playlist. Note that
3738 // it will bypass the one producer per track logic and might cause
3739 // Sound cracks if clip is moved so that it overlaps another copy of itself
3740 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3741 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3744 // move all effects to the correct producer
3745 mltPasteEffects(clipProducer, clip);
3748 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3749 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3750 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3753 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3755 if (clip == clipProducer) {
3760 delete clipProducer;
3762 destTrackPlaylist.consolidate_blanks(0);
3763 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3764 kDebug() << "//////// moving clip transparency";
3765 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3767 if (clipIndex > trackPlaylist.count()) checkLength = true;
3768 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3772 if (checkLength) mltCheckLength(&tractor);
3774 //m_mltConsumer->set("refresh", 1);
3779 QList <int> Render::checkTrackSequence(int track)
3782 Mlt::Service service(m_mltProducer->parent().get_service());
3783 if (service.type() != tractor_type) {
3784 kWarning() << "// TRACTOR PROBLEM";
3787 Mlt::Tractor tractor(service);
3789 Mlt::Producer trackProducer(tractor.track(track));
3790 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3791 int clipNb = trackPlaylist.count();
3792 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3793 for (int i = 0; i < clipNb; i++) {
3794 Mlt::Producer *c = trackPlaylist.get_clip(i);
3795 int pos = trackPlaylist.clip_start(i);
3796 if (!list.contains(pos)) list.append(pos);
3797 pos += c->get_playtime();
3798 if (!list.contains(pos)) list.append(pos);
3804 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3806 int new_in = (int)newIn.frames(m_fps);
3807 int new_out = (int)newOut.frames(m_fps) - 1;
3808 if (new_in >= new_out) return false;
3809 int old_in = (int)oldIn.frames(m_fps);
3810 int old_out = (int)oldOut.frames(m_fps) - 1;
3812 Mlt::Service service(m_mltProducer->parent().get_service());
3813 Mlt::Tractor tractor(service);
3814 Mlt::Field *field = tractor.field();
3816 bool doRefresh = true;
3817 // Check if clip is visible in monitor
3818 int diff = old_out - m_mltProducer->position();
3819 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3821 diff = new_out - m_mltProducer->position();
3822 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3826 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3827 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3828 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3829 QString resource = mlt_properties_get(properties, "mlt_service");
3830 int old_pos = (int)(old_in + old_out) / 2;
3833 while (mlt_type == "transition") {
3834 Mlt::Transition transition((mlt_transition) nextservice);
3835 nextservice = mlt_service_producer(nextservice);
3836 int currentTrack = transition.get_b_track();
3837 int currentIn = (int) transition.get_in();
3838 int currentOut = (int) transition.get_out();
3840 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3842 if (newTrack - startTrack != 0) {
3843 Mlt::Properties trans_props(transition.get_properties());
3844 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3845 Mlt::Properties new_trans_props(new_transition.get_properties());
3846 new_trans_props.inherit(trans_props);
3847 new_transition.set_in_and_out(new_in, new_out);
3848 field->disconnect_service(transition);
3849 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3850 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3851 } else transition.set_in_and_out(new_in, new_out);
3854 if (nextservice == NULL) break;
3855 properties = MLT_SERVICE_PROPERTIES(nextservice);
3856 mlt_type = mlt_properties_get(properties, "mlt_type");
3857 resource = mlt_properties_get(properties, "mlt_service");
3860 if (doRefresh) refresh();
3861 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3866 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3868 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3869 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3870 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3871 QString resource = mlt_properties_get(properties, "mlt_service");
3872 QList <Mlt::Transition *> trList;
3873 mlt_properties insertproperties = tr.get_properties();
3874 QString insertresource = mlt_properties_get(insertproperties, "mlt_service");
3875 bool isMixTransition = insertresource == "mix";
3877 while (mlt_type == "transition") {
3878 Mlt::Transition transition((mlt_transition) nextservice);
3879 nextservice = mlt_service_producer(nextservice);
3880 int aTrack = transition.get_a_track();
3881 int bTrack = transition.get_b_track();
3882 if ((isMixTransition || resource != "mix") && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3883 Mlt::Properties trans_props(transition.get_properties());
3884 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3885 Mlt::Properties new_trans_props(cp->get_properties());
3886 new_trans_props.inherit(trans_props);
3888 field->disconnect_service(transition);
3890 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3892 if (nextservice == NULL) break;
3893 properties = MLT_SERVICE_PROPERTIES(nextservice);
3894 mlt_type = mlt_properties_get(properties, "mlt_type");
3895 resource = mlt_properties_get(properties, "mlt_service");
3897 field->plant_transition(tr, a_track, b_track);
3899 // re-add upper transitions
3900 for (int i = trList.count() - 1; i >= 0; i--) {
3901 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3902 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3907 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3909 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3911 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3912 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3913 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3916 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3919 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3921 mlt_service serv = m_mltProducer->parent().get_service();
3922 mlt_service_lock(serv);
3924 mlt_service nextservice = mlt_service_get_producer(serv);
3925 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3926 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3927 QString resource = mlt_properties_get(properties, "mlt_service");
3928 int in_pos = (int) in.frames(m_fps);
3929 int out_pos = (int) out.frames(m_fps) - 1;
3931 while (mlt_type == "transition") {
3932 mlt_transition tr = (mlt_transition) nextservice;
3933 int currentTrack = mlt_transition_get_b_track(tr);
3934 int currentBTrack = mlt_transition_get_a_track(tr);
3935 int currentIn = (int) mlt_transition_get_in(tr);
3936 int currentOut = (int) mlt_transition_get_out(tr);
3938 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3939 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3940 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3941 QMap<QString, QString>::Iterator it;
3943 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3945 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3946 if (currentId != xml.attribute("id")) {
3947 // The transition ID is not the same, so reset all properties
3948 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3949 // Cleanup previous properties
3950 QStringList permanentProps;
3951 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3952 permanentProps << "out" << "a_track" << "b_track";
3953 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3954 QString propName = mlt_properties_get_name(transproperties, i);
3955 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3956 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3961 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3962 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3964 if (currentBTrack != a_track) {
3965 mlt_properties_set_int(transproperties, "a_track", a_track);
3967 for (it = map.begin(); it != map.end(); ++it) {
3969 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3970 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3971 //filter->set("kdenlive_id", id);
3975 nextservice = mlt_service_producer(nextservice);
3976 if (nextservice == NULL) break;
3977 properties = MLT_SERVICE_PROPERTIES(nextservice);
3978 mlt_type = mlt_properties_get(properties, "mlt_type");
3979 resource = mlt_properties_get(properties, "mlt_service");
3981 mlt_service_unlock(serv);
3983 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3986 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3988 mlt_service serv = m_mltProducer->parent().get_service();
3989 mlt_service_lock(serv);
3991 Mlt::Service service(serv);
3992 Mlt::Tractor tractor(service);
3993 Mlt::Field *field = tractor.field();
3995 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3997 mlt_service nextservice = mlt_service_get_producer(serv);
3998 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3999 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4000 QString resource = mlt_properties_get(properties, "mlt_service");
4002 const int old_pos = (int)((in + out).frames(m_fps) / 2);
4003 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
4005 while (mlt_type == "transition") {
4006 mlt_transition tr = (mlt_transition) nextservice;
4007 int currentTrack = mlt_transition_get_b_track(tr);
4008 int currentIn = (int) mlt_transition_get_in(tr);
4009 int currentOut = (int) mlt_transition_get_out(tr);
4010 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
4012 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
4013 mlt_field_disconnect_service(field->get_field(), nextservice);
4016 nextservice = mlt_service_producer(nextservice);
4017 if (nextservice == NULL) break;
4018 properties = MLT_SERVICE_PROPERTIES(nextservice);
4019 mlt_type = mlt_properties_get(properties, "mlt_type");
4020 resource = mlt_properties_get(properties, "mlt_service");
4022 mlt_service_unlock(serv);
4024 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
4027 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
4029 QDomNodeList attribs = xml.elementsByTagName("parameter");
4030 QMap<QString, QString> map;
4031 for (int i = 0; i < attribs.count(); i++) {
4032 QDomElement e = attribs.item(i).toElement();
4033 QString name = e.attribute("name");
4034 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
4035 map[name] = e.attribute("default");
4036 if (!e.attribute("value").isEmpty()) {
4037 map[name] = e.attribute("value");
4039 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
4040 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
4041 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
4044 if (e.attribute("namedesc").contains(';')) {
4045 QString format = e.attribute("format");
4046 QStringList separators = format.split("%d", QString::SkipEmptyParts);
4047 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
4049 QTextStream txtNeu(&neu);
4050 if (values.size() > 0)
4051 txtNeu << (int)values[0].toDouble();
4053 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
4054 txtNeu << separators[i];
4055 txtNeu << (int)(values[i+1].toDouble());
4057 if (i < separators.size())
4058 txtNeu << separators[i];
4059 map[e.attribute("name")] = neu;
4066 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
4068 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
4069 Mlt::Service service(m_mltProducer->parent().get_service());
4070 Mlt::Tractor tractor(service);
4071 Mlt::Field *field = tractor.field();
4073 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
4074 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
4075 transition->set("transparency", id);
4076 transition->set("fill", 1);
4077 transition->set("internal_added", 237);
4078 field->plant_transition(*transition, transitiontrack, info.track);
4082 void Render::mltDeleteTransparency(int pos, int track, int id)
4084 Mlt::Service service(m_mltProducer->parent().get_service());
4085 Mlt::Tractor tractor(service);
4086 Mlt::Field *field = tractor.field();
4088 //if (do_refresh) m_mltConsumer->set("refresh", 0);
4089 mlt_service serv = m_mltProducer->parent().get_service();
4091 mlt_service nextservice = mlt_service_get_producer(serv);
4092 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4093 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4094 QString resource = mlt_properties_get(properties, "mlt_service");
4096 while (mlt_type == "transition") {
4097 mlt_transition tr = (mlt_transition) nextservice;
4098 int currentTrack = mlt_transition_get_b_track(tr);
4099 int currentIn = (int) mlt_transition_get_in(tr);
4100 int currentOut = (int) mlt_transition_get_out(tr);
4101 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4102 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
4104 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
4105 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
4106 mlt_field_disconnect_service(field->get_field(), nextservice);
4109 nextservice = mlt_service_producer(nextservice);
4110 if (nextservice == NULL) break;
4111 properties = MLT_SERVICE_PROPERTIES(nextservice);
4112 mlt_type = mlt_properties_get(properties, "mlt_type");
4113 resource = mlt_properties_get(properties, "mlt_service");
4115 //if (do_refresh) m_mltConsumer->set("refresh", 1);
4118 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
4120 Mlt::Service service(m_mltProducer->parent().get_service());
4121 Mlt::Tractor tractor(service);
4124 m_mltConsumer->set("refresh", 0);
4126 mlt_service serv = m_mltProducer->parent().get_service();
4127 mlt_service nextservice = mlt_service_get_producer(serv);
4128 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4129 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4130 QString resource = mlt_properties_get(properties, "mlt_service");
4131 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
4132 while (mlt_type == "transition") {
4133 mlt_transition tr = (mlt_transition) nextservice;
4134 int currentTrack = mlt_transition_get_b_track(tr);
4135 int currentIn = (int) mlt_transition_get_in(tr);
4136 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
4137 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4138 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
4139 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
4140 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
4141 mlt_transition_set_in_and_out(tr, newStart, newEnd);
4144 nextservice = mlt_service_producer(nextservice);
4145 if (nextservice == NULL) break;
4146 properties = MLT_SERVICE_PROPERTIES(nextservice);
4147 mlt_type = mlt_properties_get(properties, "mlt_type");
4148 resource = mlt_properties_get(properties, "mlt_service");
4151 m_mltConsumer->set("refresh", 1);
4155 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
4157 Mlt::Service service(m_mltProducer->parent().get_service());
4158 Mlt::Tractor tractor(service);
4161 m_mltConsumer->set("refresh", 0);
4163 mlt_service serv = m_mltProducer->parent().get_service();
4164 mlt_service nextservice = mlt_service_get_producer(serv);
4165 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4166 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4167 QString resource = mlt_properties_get(properties, "mlt_service");
4169 while (mlt_type == "transition") {
4170 mlt_transition tr = (mlt_transition) nextservice;
4171 int currentTrack = mlt_transition_get_b_track(tr);
4172 int currentaTrack = mlt_transition_get_a_track(tr);
4173 int currentIn = (int) mlt_transition_get_in(tr);
4174 int currentOut = (int) mlt_transition_get_out(tr);
4175 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4176 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4177 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
4178 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
4179 kDebug() << "//////MOVING";
4180 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
4181 if (endTrack != startTrack) {
4182 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4183 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
4184 mlt_properties_set_int(properties, "b_track", endTrack);
4188 nextservice = mlt_service_producer(nextservice);
4189 if (nextservice == NULL) break;
4190 properties = MLT_SERVICE_PROPERTIES(nextservice);
4191 mlt_type = mlt_properties_get(properties, "mlt_type");
4192 resource = mlt_properties_get(properties, "mlt_service");
4195 m_mltConsumer->set("refresh", 1);
4199 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
4201 if (in >= out) return false;
4202 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
4203 Mlt::Service service(m_mltProducer->parent().get_service());
4205 Mlt::Tractor tractor(service);
4206 Mlt::Field *field = tractor.field();
4208 Mlt::Transition transition(*m_mltProfile, tag.toUtf8().constData());
4209 if (out != GenTime())
4210 transition.set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
4212 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
4213 QMap<QString, QString>::Iterator it;
4215 if (xml.attribute("automatic") == "1") transition.set("automatic", 1);
4216 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
4217 if (xml.hasAttribute("id"))
4218 transition.set("kdenlive_id", xml.attribute("id").toUtf8().constData());
4219 if (xml.hasAttribute("force_track"))
4220 transition.set("force_track", xml.attribute("force_track").toInt());
4222 for (it = args.begin(); it != args.end(); ++it) {
4224 if (!it.value().isEmpty())
4225 transition.set(key.toUtf8().constData(), it.value().toUtf8().constData());
4226 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
4228 // attach transition
4230 mltPlantTransition(field, transition, a_track, b_track);
4231 // field->plant_transition(*transition, a_track, b_track);
4233 if (do_refresh) refresh();
4237 void Render::mltSavePlaylist()
4239 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
4240 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
4241 fileConsumer.set("resource", "/tmp/playlist.mlt");
4243 Mlt::Service service(m_mltProducer->get_service());
4245 fileConsumer.connect(service);
4246 fileConsumer.start();
4249 const QList <Mlt::Producer *> Render::producersList()
4251 QList <Mlt::Producer *> prods;
4252 if (m_mltProducer == NULL) return prods;
4253 Mlt::Service service(m_mltProducer->parent().get_service());
4254 if (service.type() != tractor_type) return prods;
4255 Mlt::Tractor tractor(service);
4258 int trackNb = tractor.count();
4259 for (int t = 1; t < trackNb; t++) {
4260 Mlt::Producer *tt = tractor.track(t);
4261 Mlt::Producer trackProducer(tt);
4263 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4264 if (!trackPlaylist.is_valid()) continue;
4265 int clipNb = trackPlaylist.count();
4266 for (int i = 0; i < clipNb; i++) {
4267 Mlt::Producer *c = trackPlaylist.get_clip(i);
4268 if (c == NULL) continue;
4269 QString prodId = c->parent().get("id");
4270 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
4271 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4274 prods.append(nprod);
4283 void Render::fillSlowMotionProducers()
4285 if (m_mltProducer == NULL) return;
4286 Mlt::Service service(m_mltProducer->parent().get_service());
4287 if (service.type() != tractor_type) return;
4289 Mlt::Tractor tractor(service);
4291 int trackNb = tractor.count();
4292 for (int t = 1; t < trackNb; t++) {
4293 Mlt::Producer *tt = tractor.track(t);
4294 Mlt::Producer trackProducer(tt);
4296 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4297 if (!trackPlaylist.is_valid()) continue;
4298 int clipNb = trackPlaylist.count();
4299 for (int i = 0; i < clipNb; i++) {
4300 Mlt::Producer *c = trackPlaylist.get_clip(i);
4301 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4303 QString id = nprod->parent().get("id");
4304 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
4305 // this is a slowmotion producer, add it to the list
4306 QString url = QString::fromUtf8(nprod->get("resource"));
4307 int strobe = nprod->get_int("strobe");
4308 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
4309 if (!m_slowmotionProducers.contains(url)) {
4310 m_slowmotionProducers.insert(url, nprod);
4312 } else delete nprod;
4319 QList <TransitionInfo> Render::mltInsertTrack(int ix, bool videoTrack)
4321 Mlt::Service service(m_mltProducer->parent().get_service());
4322 if (service.type() != tractor_type) {
4323 kWarning() << "// TRACTOR PROBLEM";
4324 return QList <TransitionInfo> ();
4328 Mlt::Tractor tractor(service);
4329 QList <TransitionInfo> transitionInfos;
4330 Mlt::Playlist playlist;
4331 int ct = tractor.count();
4333 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
4339 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
4340 tractor.set_track(playlist, pos);
4341 Mlt::Producer newProd(tractor.track(pos));
4342 if (!videoTrack) newProd.set("hide", 1);
4344 for (; pos <= ct; pos++) {
4345 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
4346 tractor.set_track(*prodToMove, pos);
4347 prodToMove = prodToMove2;
4350 tractor.set_track(playlist, ix);
4351 Mlt::Producer newProd(tractor.track(ix));
4352 if (!videoTrack) newProd.set("hide", 1);
4357 mlt_service serv = m_mltProducer->parent().get_service();
4358 mlt_service nextservice = mlt_service_get_producer(serv);
4359 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4360 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4361 QString resource = mlt_properties_get(properties, "mlt_service");
4362 Mlt::Field *field = tractor.field();
4363 QList <Mlt::Transition *> trList;
4365 while (mlt_type == "transition") {
4366 if (resource != "mix") {
4367 Mlt::Transition transition((mlt_transition) nextservice);
4368 nextservice = mlt_service_producer(nextservice);
4369 int currentbTrack = transition.get_b_track();
4370 int currentaTrack = transition.get_a_track();
4371 bool trackChanged = false;
4372 bool forceTransitionTrack = false;
4373 if (currentbTrack >= ix) {
4374 if (currentbTrack == ix && currentaTrack < ix) forceTransitionTrack = true;
4376 trackChanged = true;
4378 if (currentaTrack >= ix) {
4380 trackChanged = true;
4382 kDebug()<<"// Newtrans: "<<currentaTrack<<"/"<<currentbTrack;
4384 // disconnect all transitions
4385 Mlt::Properties trans_props(transition.get_properties());
4386 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
4387 Mlt::Properties new_trans_props(cp->get_properties());
4388 new_trans_props.inherit(trans_props);
4391 // Transition track needs to be adjusted
4392 cp->set("a_track", currentaTrack);
4393 cp->set("b_track", currentbTrack);
4394 // Check if transition track was changed and needs to be forced
4395 if (forceTransitionTrack) cp->set("force_track", 1);
4396 TransitionInfo trInfo;
4397 trInfo.startPos = GenTime(transition.get_in(), m_fps);
4398 trInfo.a_track = currentaTrack;
4399 trInfo.b_track = currentbTrack;
4400 trInfo.forceTrack = cp->get_int("force_track");
4401 transitionInfos.append(trInfo);
4404 field->disconnect_service(transition);
4406 else nextservice = mlt_service_producer(nextservice);
4407 if (nextservice == NULL) break;
4408 properties = MLT_SERVICE_PROPERTIES(nextservice);
4409 mlt_type = mlt_properties_get(properties, "mlt_type");
4410 resource = mlt_properties_get(properties, "mlt_service");
4413 // Add audio mix transition to last track
4414 Mlt::Transition transition(*m_mltProfile, "mix");
4415 transition.set("a_track", 1);
4416 transition.set("b_track", ct);
4417 transition.set("always_active", 1);
4418 transition.set("internal_added", 237);
4419 transition.set("combine", 1);
4420 mltPlantTransition(field, transition, 1, ct);
4422 // re-add transitions
4423 for (int i = trList.count() - 1; i >= 0; i--) {
4424 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
4429 blockSignals(false);
4430 return transitionInfos;
4434 void Render::mltDeleteTrack(int ix)
4437 doc.setContent(sceneList(), false);
4438 int tracksCount = doc.elementsByTagName("track").count() - 1;
4439 QDomNode track = doc.elementsByTagName("track").at(ix);
4440 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
4441 QDomNodeList transitions = doc.elementsByTagName("transition");
4442 for (int i = 0; i < transitions.count(); i++) {
4443 QDomElement e = transitions.at(i).toElement();
4444 QDomNodeList props = e.elementsByTagName("property");
4445 QMap <QString, QString> mappedProps;
4446 for (int j = 0; j < props.count(); j++) {
4447 QDomElement f = props.at(j).toElement();
4448 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
4450 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
4451 tractor.removeChild(transitions.at(i));
4453 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
4454 // Transition needs to be moved
4455 int a_track = mappedProps.value("a_track").toInt();
4456 int b_track = mappedProps.value("b_track").toInt();
4457 if (a_track > 0 && a_track >= ix) a_track --;
4458 if (b_track == ix) {
4459 // transition was on the deleted track, so remove it
4460 tractor.removeChild(transitions.at(i));
4464 if (b_track > 0 && b_track > ix) b_track --;
4465 for (int j = 0; j < props.count(); j++) {
4466 QDomElement f = props.at(j).toElement();
4467 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
4468 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
4473 tractor.removeChild(track);
4474 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
4475 setSceneList(doc.toString(), m_mltConsumer->position());
4476 emit refreshDocumentProducers(false, false);
4480 void Render::updatePreviewSettings()
4482 kDebug() << "////// RESTARTING CONSUMER";
4483 if (!m_mltConsumer || !m_mltProducer) return;
4484 if (m_mltProducer->get_playtime() == 0) return;
4485 QMutexLocker locker(&m_mutex);
4486 Mlt::Service service(m_mltProducer->parent().get_service());
4487 if (service.type() != tractor_type) return;
4489 //m_mltConsumer->set("refresh", 0);
4490 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
4491 m_mltConsumer->purge();
4492 QString scene = sceneList();
4494 if (m_mltProducer) {
4495 pos = m_mltProducer->position();
4498 setSceneList(scene, pos);
4502 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
4504 // Update all frame positions to the new fps value
4505 //WARNING: there are probably some effects or other that hold a frame value
4506 // as parameter and will also need to be updated here!
4508 doc.setContent(scene);
4510 double factor = new_fps / current_fps;
4511 QDomNodeList producers = doc.elementsByTagName("producer");
4512 for (int i = 0; i < producers.count(); i++) {
4513 QDomElement prod = producers.at(i).toElement();
4514 prod.removeAttribute("in");
4515 prod.removeAttribute("out");
4517 QDomNodeList props = prod.childNodes();
4518 for (int j = 0; j < props.count(); j++) {
4519 QDomElement param = props.at(j).toElement();
4520 QString paramName = param.attribute("name");
4521 if (paramName.startsWith("meta.") || paramName == "length") {
4522 prod.removeChild(props.at(j));
4528 QDomNodeList entries = doc.elementsByTagName("entry");
4529 for (int i = 0; i < entries.count(); i++) {
4530 QDomElement entry = entries.at(i).toElement();
4531 int in = entry.attribute("in").toInt();
4532 int out = entry.attribute("out").toInt();
4533 in = factor * in + 0.5;
4534 out = factor * out + 0.5;
4535 entry.setAttribute("in", in);
4536 entry.setAttribute("out", out);
4539 QDomNodeList blanks = doc.elementsByTagName("blank");
4540 for (int i = 0; i < blanks.count(); i++) {
4541 QDomElement blank = blanks.at(i).toElement();
4542 int length = blank.attribute("length").toInt();
4543 length = factor * length + 0.5;
4544 blank.setAttribute("length", QString::number(length));
4547 QDomNodeList filters = doc.elementsByTagName("filter");
4548 for (int i = 0; i < filters.count(); i++) {
4549 QDomElement filter = filters.at(i).toElement();
4550 int in = filter.attribute("in").toInt();
4551 int out = filter.attribute("out").toInt();
4552 in = factor * in + 0.5;
4553 out = factor * out + 0.5;
4554 filter.setAttribute("in", in);
4555 filter.setAttribute("out", out);
4558 QDomNodeList transitions = doc.elementsByTagName("transition");
4559 for (int i = 0; i < transitions.count(); i++) {
4560 QDomElement transition = transitions.at(i).toElement();
4561 int in = transition.attribute("in").toInt();
4562 int out = transition.attribute("out").toInt();
4563 in = factor * in + 0.5;
4564 out = factor * out + 0.5;
4565 transition.setAttribute("in", in);
4566 transition.setAttribute("out", out);
4567 QDomNodeList props = transition.childNodes();
4568 for (int j = 0; j < props.count(); j++) {
4569 QDomElement param = props.at(j).toElement();
4570 QString paramName = param.attribute("name");
4571 if (paramName == "geometry") {
4572 QString geom = param.firstChild().nodeValue();
4573 QStringList keys = geom.split(';');
4574 QStringList newKeys;
4575 for (int k = 0; k < keys.size(); ++k) {
4576 if (keys.at(k).contains('=')) {
4577 int pos = keys.at(k).section('=', 0, 0).toInt();
4578 pos = factor * pos + 0.5;
4579 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4580 } else newKeys.append(keys.at(k));
4582 param.firstChild().setNodeValue(newKeys.join(";"));
4586 QDomElement root = doc.documentElement();
4587 if (!root.isNull()) {
4588 QDomElement tractor = root.firstChildElement("tractor");
4589 int out = tractor.attribute("out").toInt();
4590 out = factor * out + 0.5;
4591 tractor.setAttribute("out", out);
4592 emit durationChanged(out);
4595 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4596 return doc.toString();
4600 void Render::sendFrameUpdate()
4602 if (m_mltProducer) {
4603 Mlt::Frame * frame = m_mltProducer->get_frame();
4604 emitFrameUpdated(*frame);
4609 Mlt::Producer* Render::getProducer()
4611 return m_mltProducer;
4614 const QString Render::activeClipId()
4616 if (m_mltProducer) return m_mltProducer->get("id");
4621 bool Render::getBlackMagicDeviceList(KComboBox *devicelist, bool force)
4623 if (!force && !KdenliveSettings::decklink_device_found()) return false;
4624 Mlt::Profile profile;
4625 Mlt::Producer bm(profile, "decklink");
4626 int found_devices = 0;
4627 if (bm.is_valid()) {
4628 bm.set("list_devices", 1);
4629 found_devices = bm.get_int("devices");
4631 else KdenliveSettings::setDecklink_device_found(false);
4632 if (found_devices <= 0) {
4633 devicelist->setEnabled(false);
4636 KdenliveSettings::setDecklink_device_found(true);
4637 for (int i = 0; i < found_devices; i++) {
4638 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4639 devicelist->addItem(bm.get(tmp));
4645 bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist, bool force)
4647 if (!force && !KdenliveSettings::decklink_device_found()) return false;
4648 Mlt::Profile profile;
4649 Mlt::Consumer bm(profile, "decklink");
4650 int found_devices = 0;
4651 if (bm.is_valid()) {
4652 bm.set("list_devices", 1);;
4653 found_devices = bm.get_int("devices");
4655 else KdenliveSettings::setDecklink_device_found(false);
4656 if (found_devices <= 0) {
4657 devicelist->setEnabled(false);
4660 KdenliveSettings::setDecklink_device_found(true);
4661 for (int i = 0; i < found_devices; i++) {
4662 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4663 devicelist->addItem(bm.get(tmp));
4669 void Render::slotMultiStreamProducerFound(const QString path, QList<int> audio_list, QList<int> video_list, stringMap data)
4671 if (KdenliveSettings::automultistreams()) {
4672 for (int i = 1; i < video_list.count(); i++) {
4673 int vindex = video_list.at(i);
4675 if (i <= audio_list.count() -1) {
4676 aindex = audio_list.at(i);
4678 data.insert("video_index", QString::number(vindex));
4679 data.insert("audio_index", QString::number(aindex));
4680 data.insert("bypassDuplicate", "1");
4681 emit addClip(KUrl(path), data);
4686 int width = 60.0 * m_mltProfile->dar();
4687 int swidth = 60.0 * m_mltProfile->width() / m_mltProfile->height();
4688 if (width % 2 == 1) width++;
4690 KDialog dialog(qApp->activeWindow());
4691 dialog.setCaption("Multi Stream Clip");
4692 dialog.setButtons(KDialog::Ok | KDialog::Cancel);
4693 dialog.setButtonText(KDialog::Ok, i18n("Import selected clips"));
4694 QWidget *content = new QWidget(&dialog);
4695 dialog.setMainWidget(content);
4696 QVBoxLayout *vbox = new QVBoxLayout(content);
4697 QLabel *lab1 = new QLabel(i18n("Additional streams for clip\n %1", path), content);
4698 vbox->addWidget(lab1);
4699 QList <QGroupBox*> groupList;
4700 QList <QComboBox*> comboList;
4701 // We start loading the list at 1, video index 0 should already be loaded
4702 for (int j = 1; j < video_list.count(); j++) {
4703 Mlt::Producer multiprod(* m_mltProfile, path.toUtf8().constData());
4704 multiprod.set("video_index", video_list.at(j));
4705 QImage thumb = KThumb::getFrame(&multiprod, 0, swidth, width, 60);
4706 QGroupBox *streamFrame = new QGroupBox(i18n("Video stream %1", video_list.at(j)), content);
4707 streamFrame->setProperty("vindex", video_list.at(j));
4708 groupList << streamFrame;
4709 streamFrame->setCheckable(true);
4710 streamFrame->setChecked(true);
4711 QVBoxLayout *vh = new QVBoxLayout( streamFrame );
4712 QLabel *iconLabel = new QLabel(content);
4713 iconLabel->setPixmap(QPixmap::fromImage(thumb));
4714 vh->addWidget(iconLabel);
4715 if (audio_list.count() > 1) {
4716 QComboBox *cb = new QComboBox(content);
4717 for (int k = 0; k < audio_list.count(); k++) {
4718 cb->addItem(i18n("Audio stream %1", audio_list.at(k)), audio_list.at(k));
4721 cb->setCurrentIndex(qMin(j, audio_list.count() - 1));
4724 vbox->addWidget(streamFrame);
4726 if (dialog.exec() == QDialog::Accepted) {
4727 // import selected streams
4728 for (int i = 0; i < groupList.count(); i++) {
4729 if (groupList.at(i)->isChecked()) {
4730 int vindex = groupList.at(i)->property("vindex").toInt();
4731 int aindex = comboList.at(i)->itemData(comboList.at(i)->currentIndex()).toInt();
4732 data.insert("video_index", QString::number(vindex));
4733 data.insert("audio_index", QString::number(aindex));
4734 data.insert("bypassDuplicate", "1");
4735 emit addClip(KUrl(path), data);
4742 bool Render::checkX11Grab()
4744 if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::ffmpegpath().isEmpty()) return false;
4747 args << "avformat:f-list";
4748 p.start(KdenliveSettings::rendererpath(), args);
4749 if (!p.waitForStarted()) return false;
4750 if (!p.waitForFinished()) return false;
4751 QByteArray result = p.readAllStandardError();
4752 return result.contains("x11grab");
4755 #include "renderer.moc"