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),
133 qRegisterMetaType<stringMap> ("stringMap");
134 analyseAudio = KdenliveSettings::monitor_audio();
135 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
136 buildConsumer(profile);
137 m_mltProducer = m_blackClip->cut(0, 1);
138 m_mltConsumer->connect(*m_mltProducer);
139 m_mltProducer->set_speed(0.0);
140 m_refreshTimer.setSingleShot(true);
141 m_refreshTimer.setInterval(100);
142 connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
143 connect(this, SIGNAL(multiStreamFound(const QString &,QList<int>,QList<int>,stringMap)), this, SLOT(slotMultiStreamProducerFound(const QString &,QList<int>,QList<int>,stringMap)));
144 connect(this, SIGNAL(checkSeeking()), this, SLOT(slotCheckSeeking()));
145 connect(this, SIGNAL(mltFrameReceived(Mlt::Frame *)), this, SLOT(showFrame(Mlt::Frame *)), Qt::UniqueConnection);
155 void Render::closeMlt()
158 m_requestList.clear();
159 m_infoThread.waitForFinished();
160 if (m_showFrameEvent) delete m_showFrameEvent;
161 if (m_pauseEvent) delete m_pauseEvent;
162 if (m_mltConsumer) delete m_mltConsumer;
163 if (m_mltProducer) delete m_mltProducer;
164 /*if (m_mltProducer) {
165 Mlt::Service service(m_mltProducer->parent().get_service());
168 if (service.type() == tractor_type) {
169 Mlt::Tractor tractor(service);
170 Mlt::Field *field = tractor.field();
171 mlt_service nextservice = mlt_service_get_producer(service.get_service());
172 mlt_service nextservicetodisconnect;
173 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
174 QString mlt_type = mlt_properties_get(properties, "mlt_type");
175 QString resource = mlt_properties_get(properties, "mlt_service");
176 // Delete all transitions
177 while (mlt_type == "transition") {
178 nextservicetodisconnect = nextservice;
179 nextservice = mlt_service_producer(nextservice);
180 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
181 if (nextservice == NULL) break;
182 properties = MLT_SERVICE_PROPERTIES(nextservice);
183 mlt_type = mlt_properties_get(properties, "mlt_type");
184 resource = mlt_properties_get(properties, "mlt_service");
193 //kDebug() << "// // // CLOSE RENDERER " << m_name;
194 if (m_blackClip) delete m_blackClip;
198 void Render::slotSwitchFullscreen()
200 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
203 void Render::buildConsumer(const QString &profileName)
208 m_activeProfile = profileName;
210 Mlt::Profile tmpProfile(m_activeProfile.toUtf8().constData());
211 m_mltProfile->set_colorspace(tmpProfile.colorspace());
212 m_mltProfile->set_frame_rate(tmpProfile.frame_rate_num(), tmpProfile.frame_rate_den());
213 m_mltProfile->set_height(tmpProfile.height());
214 m_mltProfile->set_width(tmpProfile.width());
215 m_mltProfile->set_progressive(tmpProfile.progressive());
216 m_mltProfile->set_sample_aspect(tmpProfile.sample_aspect_num(), tmpProfile.sample_aspect_den());
217 m_mltProfile->get_profile()->display_aspect_num = tmpProfile.display_aspect_num();
218 m_mltProfile->get_profile()->display_aspect_den = tmpProfile.display_aspect_den();
221 m_mltProfile = new Mlt::Profile(m_activeProfile.toUtf8().constData());
223 setenv("MLT_PROFILE", m_activeProfile.toUtf8().constData(), 1);
224 m_mltProfile->set_explicit(true);
226 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour:black");
227 m_blackClip->set("id", "black");
228 m_blackClip->set("mlt_type", "producer");
229 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor && m_winid != 0) {
230 // Use blackmagic card for video output
231 int device = KdenliveSettings::blackmagic_output_device();
233 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
234 if (!m_mltConsumer) {
235 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
236 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
237 mlt_log_set_callback(kdenlive_callback);
239 if (m_mltConsumer->is_valid()) {
240 externalConsumer = true;
241 m_mltConsumer->set("terminate_on_pause", 0);
242 m_mltConsumer->set("deinterlace_method", KdenliveSettings::mltdeinterlacer().toUtf8().constData());
243 m_mltConsumer->set("rescale", KdenliveSettings::mltinterpolation().toUtf8().constData());
244 m_mltConsumer->set("buffer", "1");
245 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
247 if (m_mltConsumer && m_mltConsumer->is_valid()) {
250 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()));
253 externalConsumer = false;
254 QString videoDriver = KdenliveSettings::videodrivername();
255 if (!videoDriver.isEmpty()) {
256 if (videoDriver == "x11_noaccel") {
257 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
260 unsetenv("SDL_VIDEO_YUV_HWACCEL");
263 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
265 //m_mltConsumer->set("fullscreen", 1);
268 if (!m_mltConsumer) {
269 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) {
270 int device = KdenliveSettings::blackmagic_output_device();
272 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
273 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
274 // Set defaults for decklink consumer
276 m_mltConsumer->set("terminate_on_pause", 0);
277 m_mltConsumer->set("deinterlace_method", KdenliveSettings::mltdeinterlacer().toUtf8().constData());
278 externalConsumer = true;
282 if (!m_mltConsumer || !m_mltConsumer->is_valid()) {
283 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
284 m_mltConsumer->set("scrub_audio", 1);
285 m_mltConsumer->set("preview_off", 1);
286 m_mltConsumer->set("audio_buffer", 512);
287 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
289 m_mltConsumer->set("buffer", "1");
290 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
293 if (!m_mltConsumer) {
294 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
295 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
296 //m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
297 m_mltConsumer->set("progressive", 1);
299 m_mltConsumer->set("window_id", m_winid);
301 //m_mltConsumer->set("resize", 1);
302 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
303 m_mltConsumer->set("rescale", KdenliveSettings::mltinterpolation().toUtf8().constData());
304 mlt_log_set_callback(kdenlive_callback);
306 QString audioDevice = KdenliveSettings::audiodevicename();
307 if (!audioDevice.isEmpty())
308 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
310 if (!videoDriver.isEmpty())
311 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
313 QString audioDriver = KdenliveSettings::audiodrivername();
316 // Disabled because the "auto" detected driver was sometimes wrong
317 if (audioDriver.isEmpty())
318 audioDriver = KdenliveSettings::autoaudiodrivername();
321 if (!audioDriver.isEmpty())
322 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
324 m_mltConsumer->set("frequency", 48000);
325 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
328 Mlt::Producer *Render::invalidProducer(const QString &id)
331 QString txt = '+' + i18n("Missing clip") + ".txt";
332 char *tmp = qstrdup(txt.toUtf8().constData());
333 clip = new Mlt::Producer(*m_mltProfile, tmp);
335 if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
337 clip->set("bgcolour", "0xff0000ff");
338 clip->set("pad", "10");
340 clip->set("id", id.toUtf8().constData());
341 clip->set("mlt_type", "producer");
345 bool Render::hasProfile(const QString &profileName) const
347 return m_activeProfile == profileName;
350 int Render::resetProfile(const QString &profileName, bool dropSceneList)
352 m_refreshTimer.stop();
354 if (externalConsumer == KdenliveSettings::external_display()) {
355 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
356 QString videoDriver = KdenliveSettings::videodrivername();
357 QString currentDriver = m_mltConsumer->get("video_driver");
358 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
359 QString background = KdenliveSettings::window_background().name();
360 QString currentBackground = m_mltConsumer->get("window_background");
361 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
362 kDebug() << "reset to same profile, nothing to do";
367 if (m_isSplitView) slotSplitView(false);
368 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
369 m_mltConsumer->purge();
372 if (!dropSceneList) scene = sceneList();
374 double current_fps = m_mltProfile->fps();
375 double current_dar = m_mltProfile->dar();
378 m_requestList.clear();
379 m_infoThread.waitForFinished();
382 pos = m_mltProducer->position();
384 Mlt::Service service(m_mltProducer->get_service());
385 if (service.type() == tractor_type) {
386 Mlt::Tractor tractor(service);
387 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
388 Mlt::Producer trackProducer(tractor.track(trackNb));
389 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
390 trackPlaylist.clear();
394 delete m_mltProducer;
396 m_mltProducer = NULL;
397 buildConsumer(profileName);
398 double new_fps = m_mltProfile->fps();
399 double new_dar = m_mltProfile->dar();
401 if (!dropSceneList) {
402 // We need to recover our playlist
403 if (current_fps != new_fps) {
404 // fps changed, we must update the scenelist positions
405 scene = updateSceneListFps(current_fps, new_fps, scene);
407 setSceneList(scene, pos);
408 // producers have changed (different profile), so reset them...
409 emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
414 void Render::seek(GenTime time)
416 if (!m_mltProducer || !m_isActive)
418 int pos = time.frames(m_fps);
422 void Render::seek(int time)
425 time = qMax(0, time);
426 time = qMin(m_mltProducer->get_playtime(), time);
427 if (requestedSeekPosition == SEEK_INACTIVE) {
428 requestedSeekPosition = time;
429 m_mltConsumer->purge();
430 m_mltProducer->seek(time);
431 if (m_paused && !externalConsumer) {
432 m_mltConsumer->set("refresh", 1);
435 else if (m_winid != 0 && m_mltProducer->get_speed() == 0) {
436 // workaround specific bug in MLT's SDL consumer
437 m_mltConsumer->stop();
438 m_mltConsumer->start();
439 m_mltConsumer->set("refresh", 1);
442 else requestedSeekPosition = time;
446 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
447 QPixmap pix(width, height);
449 mlt_image_format format = mlt_image_rgb24a;
450 uint8_t *thumb = frame->get_image(format, width, height);
451 QImage image(thumb, width, height, QImage::Format_ARGB32);
453 if (!image.isNull()) {
454 pix = pix.fromImage(image);
456 QPainter painter(&pix);
457 painter.drawRect(0, 0, width - 1, height - 1);
459 } else pix.fill(Qt::black);
463 int Render::frameRenderWidth() const
465 return m_mltProfile->width();
468 int Render::renderWidth() const
470 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
473 int Render::renderHeight() const
475 return m_mltProfile->height();
478 QImage Render::extractFrame(int frame_position, QString path, int width, int height)
481 width = frameRenderWidth();
482 height = renderHeight();
483 } else if (width % 2 == 1) width++;
484 int dwidth = height * frameRenderWidth() / renderHeight();
485 if (!path.isEmpty()) {
486 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
488 if (producer->is_valid()) {
489 QImage img = KThumb::getFrame(producer, frame_position, dwidth, width, height);
493 else delete producer;
497 if (!m_mltProducer || !path.isEmpty()) {
498 QImage pix(width, height, QImage::Format_RGB32);
502 return KThumb::getFrame(m_mltProducer, frame_position, dwidth, width, height);
505 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
509 if (url.fileName().startsWith(".all.")) { // check for slideshow
510 QString fileType = url.fileName().right(3);
512 QStringList::Iterator it;
514 QDir dir(url.directory());
516 filter << "*." + fileType;
517 filter << "*." + fileType.toUpper();
518 more = dir.entryList(filter, QDir::Files);
519 im.load(url.directory() + '/' + more.at(0));
520 } else im.load(url.path());
521 //pixmap = im.scaled(width, height);
525 double Render::consumerRatio() const
527 if (!m_mltConsumer) return 1.0;
528 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
532 int Render::getLength()
536 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
537 return mlt_producer_get_playtime(m_mltProducer->get_producer());
542 bool Render::isValid(KUrl url)
544 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
545 if (producer.is_blank())
551 double Render::dar() const
553 return m_mltProfile->dar();
556 double Render::sar() const
558 return m_mltProfile->sar();
561 void Render::slotSplitView(bool doit)
563 m_isSplitView = doit;
564 Mlt::Service service(m_mltProducer->parent().get_service());
565 Mlt::Tractor tractor(service);
566 if (service.type() != tractor_type || tractor.count() < 2) return;
567 Mlt::Field *field = tractor.field();
569 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
570 Mlt::Producer trackProducer(tractor.track(i));
571 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
572 if (QString(trackProducer.get("hide")).toInt() != 1) {
573 kDebug() << "// ADIDNG TRACK: " << i;
574 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
575 transition->set("mlt_service", "composite");
576 transition->set("a_track", 0);
577 transition->set("b_track", i);
578 transition->set("distort", 0);
579 transition->set("aligned", 0);
580 transition->set("internal_added", "200");
584 geometry = "0/0:50%x50%";
587 geometry = "50%/0:50%x50%";
590 geometry = "0/50%:50%x50%";
594 geometry = "50%/50%:50%x50%";
597 transition->set("geometry", geometry.toUtf8().constData());
598 transition->set("always_active", "1");
599 field->plant_transition(*transition, 0, i);
603 m_mltConsumer->set("refresh", 1);
605 mlt_service serv = m_mltProducer->parent().get_service();
606 mlt_service nextservice = mlt_service_get_producer(serv);
607 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
608 QString mlt_type = mlt_properties_get(properties, "mlt_type");
609 QString resource = mlt_properties_get(properties, "mlt_service");
610 mlt_service nextservicetodisconnect;
612 while (mlt_type == "transition") {
613 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
614 if (added == "200") {
615 nextservicetodisconnect = nextservice;
616 nextservice = mlt_service_producer(nextservice);
617 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
619 else nextservice = mlt_service_producer(nextservice);
620 if (nextservice == NULL) break;
621 properties = MLT_SERVICE_PROPERTIES(nextservice);
622 mlt_type = mlt_properties_get(properties, "mlt_type");
623 resource = mlt_properties_get(properties, "mlt_service");
624 m_mltConsumer->set("refresh", 1);
629 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer)
631 // Make sure we don't request the info for same clip twice
633 if (m_processingClipId.contains(clipId)) {
634 m_infoMutex.unlock();
637 for (int i = 0; i < m_requestList.count(); i++) {
638 if (m_requestList.at(i).clipId == clipId) {
639 // Clip is already queued
640 m_infoMutex.unlock();
644 requestClipInfo info;
646 info.clipId = clipId;
647 info.imageHeight = imageHeight;
648 info.replaceProducer = replaceProducer;
649 m_requestList.append(info);
650 m_infoMutex.unlock();
651 if (!m_infoThread.isRunning()) {
652 m_infoThread = QtConcurrent::run(this, &Render::processFileProperties);
656 void Render::forceProcessing(const QString &id)
658 if (m_processingClipId.contains(id)) return;
659 QMutexLocker lock(&m_infoMutex);
660 for (int i = 0; i < m_requestList.count(); i++) {
661 requestClipInfo info = m_requestList.at(i);
662 if (info.clipId == id) {
665 m_requestList.removeAt(i);
666 m_requestList.prepend(info);
673 int Render::processingItems()
675 QMutexLocker lock(&m_infoMutex);
676 int count = m_requestList.count() + m_processingClipId.count();
680 void Render::processingDone(const QString &id)
682 QMutexLocker lock(&m_infoMutex);
683 m_processingClipId.removeAll(id);
686 bool Render::isProcessing(const QString &id)
688 if (m_processingClipId.contains(id)) return true;
689 QMutexLocker lock(&m_infoMutex);
690 for (int i = 0; i < m_requestList.count(); i++) {
691 if (m_requestList.at(i).clipId == id) {
698 void Render::processFileProperties()
700 requestClipInfo info;
702 while (!m_requestList.isEmpty()) {
704 info = m_requestList.takeFirst();
705 m_processingClipId.append(info.clipId);
706 m_infoMutex.unlock();
710 if (info.xml.hasAttribute("proxy") && info.xml.attribute("proxy") != "-") {
711 path = info.xml.attribute("proxy");
712 // Check for missing proxies
713 if (QFileInfo(path).size() <= 0) {
714 // proxy is missing, re-create it
715 emit requestProxy(info.clipId);
716 proxyProducer = false;
717 path = info.xml.attribute("resource");
719 else proxyProducer = true;
722 path = info.xml.attribute("resource");
723 proxyProducer = false;
726 Mlt::Producer *producer = NULL;
727 CLIPTYPE type = (CLIPTYPE)info.xml.attribute("type").toInt();
729 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + info.xml.attribute("colour")).toUtf8().constData());
730 } else if (type == TEXT) {
731 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
732 if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
733 producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
734 } else if (url.isEmpty()) {
735 //WARNING: when is this case used? Not sure it is working.. JBM/
737 QDomElement mlt = doc.createElement("mlt");
738 QDomElement play = doc.createElement("playlist");
739 play.setAttribute("id", "playlist0");
740 doc.appendChild(mlt);
741 mlt.appendChild(play);
742 play.appendChild(doc.importNode(info.xml, true));
743 QDomElement tractor = doc.createElement("tractor");
744 tractor.setAttribute("id", "tractor0");
745 QDomElement track = doc.createElement("track");
746 track.setAttribute("producer", "playlist0");
747 tractor.appendChild(track);
748 mlt.appendChild(tractor);
749 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
751 producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
754 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
755 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
756 m_processingClipId.removeAll(info.clipId);
758 // Proxy file is corrupted
759 emit removeInvalidProxy(info.clipId, false);
761 else emit removeInvalidClip(info.clipId, info.replaceProducer);
766 if (proxyProducer && info.xml.hasAttribute("proxy_out")) {
767 producer->set("length", info.xml.attribute("proxy_out").toInt() + 1);
768 producer->set("out", info.xml.attribute("proxy_out").toInt());
769 if (producer->get_out() != info.xml.attribute("proxy_out").toInt()) {
770 // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
771 m_processingClipId.removeAll(info.clipId);
772 emit removeInvalidProxy(info.clipId, true);
778 if (info.xml.hasAttribute("force_aspect_ratio")) {
779 double aspect = info.xml.attribute("force_aspect_ratio").toDouble();
780 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
783 if (info.xml.hasAttribute("force_aspect_num") && info.xml.hasAttribute("force_aspect_den")) {
784 int width = info.xml.attribute("frame_size").section('x', 0, 0).toInt();
785 int height = info.xml.attribute("frame_size").section('x', 1, 1).toInt();
786 int aspectNumerator = info.xml.attribute("force_aspect_num").toInt();
787 int aspectDenominator = info.xml.attribute("force_aspect_den").toInt();
788 if (aspectDenominator != 0 && width != 0)
789 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
792 if (info.xml.hasAttribute("force_fps")) {
793 double fps = info.xml.attribute("force_fps").toDouble();
794 if (fps > 0) producer->set("force_fps", fps);
797 if (info.xml.hasAttribute("force_progressive")) {
799 int progressive = info.xml.attribute("force_progressive").toInt(&ok);
800 if (ok) producer->set("force_progressive", progressive);
802 if (info.xml.hasAttribute("force_tff")) {
804 int fieldOrder = info.xml.attribute("force_tff").toInt(&ok);
805 if (ok) producer->set("force_tff", fieldOrder);
807 if (info.xml.hasAttribute("threads")) {
808 int threads = info.xml.attribute("threads").toInt();
809 if (threads != 1) producer->set("threads", threads);
811 if (info.xml.hasAttribute("video_index")) {
812 int vindex = info.xml.attribute("video_index").toInt();
813 if (vindex != 0) producer->set("video_index", vindex);
815 if (info.xml.hasAttribute("audio_index")) {
816 int aindex = info.xml.attribute("audio_index").toInt();
817 if (aindex != 0) producer->set("audio_index", aindex);
819 if (info.xml.hasAttribute("force_colorspace")) {
820 int colorspace = info.xml.attribute("force_colorspace").toInt();
821 if (colorspace != 0) producer->set("force_colorspace", colorspace);
823 if (info.xml.hasAttribute("full_luma")) {
824 int full_luma = info.xml.attribute("full_luma").toInt();
825 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
830 if (info.xml.hasAttribute("out")) clipOut = info.xml.attribute("out").toInt();
832 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
833 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
835 if (info.xml.hasAttribute("length")) {
836 length = info.xml.attribute("length").toInt();
837 clipOut = length - 1;
839 else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt() + 1;
840 // Pass duration if it was forced
841 if (info.xml.hasAttribute("duration")) {
842 duration = info.xml.attribute("duration").toInt();
843 if (length < duration) {
845 if (clipOut > 0) clipOut = length - 1;
848 if (duration == 0) duration = length;
849 producer->set("length", length);
852 if (clipOut > 0) producer->set_in_and_out(info.xml.attribute("in").toInt(), clipOut);
854 producer->set("id", info.clipId.toUtf8().constData());
856 if (info.xml.hasAttribute("templatetext"))
857 producer->set("templatetext", info.xml.attribute("templatetext").toUtf8().constData());
859 int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5);
860 int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5);
861 int frameNumber = info.xml.attribute("thumbnail", "-1").toInt();
863 if ((!info.replaceProducer && info.xml.hasAttribute("file_hash")) || proxyProducer) {
864 // Clip already has all properties
866 // Recreate clip thumb
867 if (frameNumber > 0) producer->seek(frameNumber);
868 Mlt::Frame *frame = producer->get_frame();
869 if (frame && frame->is_valid()) {
870 QImage img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
871 emit replyGetImage(info.clipId, img);
873 if (frame) delete frame;
875 emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
879 stringMap filePropertyMap;
880 stringMap metadataPropertyMap;
883 if (frameNumber > 0) producer->seek(frameNumber);
884 duration = duration > 0 ? duration : producer->get_playtime();
885 filePropertyMap["duration"] = QString::number(duration);
886 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
888 if (type == SLIDESHOW) {
889 int ttl = info.xml.hasAttribute("ttl") ? info.xml.attribute("ttl").toInt() : 0;
890 if (ttl) producer->set("ttl", ttl);
891 if (!info.xml.attribute("animation").isEmpty()) {
892 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
893 if (filter && filter->is_valid()) {
895 QString geometry = SlideshowClip::animationToGeometry(info.xml.attribute("animation"), cycle);
896 if (!geometry.isEmpty()) {
897 if (info.xml.attribute("animation").contains("low-pass")) {
898 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
899 if (blur && blur->is_valid())
900 producer->attach(*blur);
902 filter->set("transition.geometry", geometry.toUtf8().data());
903 filter->set("transition.cycle", cycle);
904 producer->attach(*filter);
908 if (info.xml.attribute("fade") == "1") {
909 // user wants a fade effect to slideshow
910 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
911 if (filter && filter->is_valid()) {
912 if (ttl) filter->set("cycle", ttl);
913 if (info.xml.hasAttribute("luma_duration") && !info.xml.attribute("luma_duration").isEmpty()) filter->set("duration", info.xml.attribute("luma_duration").toInt());
914 if (info.xml.hasAttribute("luma_file") && !info.xml.attribute("luma_file").isEmpty()) {
915 filter->set("luma.resource", info.xml.attribute("luma_file").toUtf8().constData());
916 if (info.xml.hasAttribute("softness")) {
917 int soft = info.xml.attribute("softness").toInt();
918 filter->set("luma.softness", (double) soft / 100.0);
921 producer->attach(*filter);
924 if (info.xml.attribute("crop") == "1") {
925 // user wants to center crop the slides
926 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
927 if (filter && filter->is_valid()) {
928 filter->set("center", 1);
929 producer->attach(*filter);
935 const QString mltService = producer->get("mlt_service");
936 if (mltService == "xml" || mltService == "consumer") {
937 // MLT playlist, create producer with blank profile to get real profile info
938 // TODO: is there an easier way to get this info (original source clip profile) from MLT?
939 Mlt::Profile *original_profile = new Mlt::Profile();
940 Mlt::Producer *tmpProd = new Mlt::Producer(*original_profile, path.toUtf8().constData());
941 filePropertyMap["progressive"] = QString::number(original_profile->progressive());
942 filePropertyMap["colorspace"] = QString::number(original_profile->colorspace());
943 filePropertyMap["fps"] = QString::number(original_profile->fps());
944 filePropertyMap["aspect_ratio"] = QString::number(original_profile->sar());
946 delete original_profile;
948 else if (mltService == "avformat") {
950 vindex = producer->get_int("video_index");
953 int streams = producer->get_int("meta.media.nb_streams");
954 QList <int> audio_list;
955 QList <int> video_list;
956 for (int i = 0; i < streams; i++) {
957 QByteArray propertyName = QString("meta.media.%1.stream.type").arg(i).toLocal8Bit();
958 QString type = producer->get(propertyName.data());
959 if (type == "audio") audio_list.append(i);
960 else if (type == "video") video_list.append(i);
963 if (!info.xml.hasAttribute("video_index") && video_list.count() > 1) {
964 // Clip has more than one video stream, ask which one should be used
965 QMap <QString, QString> data;
966 if (info.xml.hasAttribute("group")) data.insert("group", info.xml.attribute("group"));
967 if (info.xml.hasAttribute("groupId")) data.insert("groupId", info.xml.attribute("groupId"));
968 emit multiStreamFound(path, audio_list, video_list, data);
969 // Force video index so that when reloading the clip we don't ask again for other streams
970 filePropertyMap["video_index"] = QString::number(vindex);
974 snprintf(property, sizeof(property), "meta.media.%d.stream.frame_rate", vindex);
975 if (producer->get(property))
976 filePropertyMap["fps"] = producer->get(property);
979 if (!filePropertyMap.contains("fps")) {
980 if (producer->get_double("meta.media.frame_rate_den") > 0) {
981 filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
982 } else filePropertyMap["fps"] = producer->get("source_fps");
986 Mlt::Frame *frame = producer->get_frame();
987 if (frame && frame->is_valid()) {
988 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
989 int af = frame->get_int("audio_frequency");
990 int ac = frame->get_int("audio_channels");
991 // keep for compatibility with MLT <= 0.8.6
992 if (af == 0) af = frame->get_int("frequency");
993 if (ac == 0) ac = frame->get_int("channels");
994 if (af > 0) filePropertyMap["frequency"] = QString::number(af);
995 if (ac > 0) filePropertyMap["channels"] = QString::number(ac);
996 if (!filePropertyMap.contains("aspect_ratio")) filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
998 if (frame->get_int("test_image") == 0) {
999 if (mltService == "xml" || mltService == "consumer") {
1000 filePropertyMap["type"] = "playlist";
1001 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
1002 } else if (!mlt_frame_is_test_audio(frame->get_frame()))
1003 filePropertyMap["type"] = "av";
1005 filePropertyMap["type"] = "video";
1011 img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
1012 variance = KThumb::imageVariance(img);
1013 if (frameNumber == -1 && variance< 6) {
1014 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
1015 frameNumber = duration > 100 ? 100 : duration / 2 ;
1016 producer->seek(frameNumber);
1018 frame = producer->get_frame();
1021 } while (variance == -1);
1023 if (frameNumber > -1) filePropertyMap["thumbnail"] = QString::number(frameNumber);
1024 emit replyGetImage(info.clipId, img);
1025 } else if (frame->get_int("test_audio") == 0) {
1026 emit replyGetImage(info.clipId, "audio-x-generic", fullWidth, info.imageHeight);
1027 filePropertyMap["type"] = "audio";
1030 // Retrieve audio / video codec name
1033 if (mltService == "avformat") {
1035 /*if (context->duration == AV_NOPTS_VALUE) {
1036 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
1037 emit removeInvalidClip(clipId);
1041 // Get the video_index
1043 int default_audio = producer->get_int("audio_index");
1046 int scan = producer->get_int("meta.media.progressive");
1047 filePropertyMap["progressive"] = QString::number(scan);
1049 // Find maximum stream index values
1050 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
1051 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
1052 QString type = producer->get(property);
1053 if (type == "video")
1055 else if (type == "audio")
1058 filePropertyMap["default_video"] = QString::number(vindex);
1059 filePropertyMap["video_max"] = QString::number(video_max);
1060 filePropertyMap["default_audio"] = QString::number(default_audio);
1061 filePropertyMap["audio_max"] = QString::number(audio_max);
1063 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex);
1064 if (producer->get(property)) {
1065 filePropertyMap["videocodec"] = producer->get(property);
1067 snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex);
1068 if (producer->get(property)) {
1069 filePropertyMap["videocodecid"] = producer->get(property);
1072 query = QString("meta.media.%1.codec.pix_fmt").arg(vindex);
1073 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
1074 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
1076 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
1077 if (producer->get_int("audio_index") > -1) {
1078 // Get the audio_index
1079 int index = producer->get_int("audio_index");
1080 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
1081 if (producer->get(property)) {
1082 filePropertyMap["audiocodec"] = producer->get(property);
1084 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
1085 if (producer->get(property))
1086 filePropertyMap["audiocodec"] = producer->get(property);
1092 Mlt::Properties metadata;
1093 metadata.pass_values(*producer, "meta.attr.");
1094 int count = metadata.count();
1095 for (int i = 0; i < count; i ++) {
1096 QString name = metadata.get_name(i);
1097 QString value = QString::fromUtf8(metadata.get(i));
1098 if (name.endsWith(".markup") && !value.isEmpty())
1099 metadataPropertyMap[ name.section('.', 0, -2)] = value;
1102 emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer);
1108 /** Create the producer from the MLT XML QDomDocument */
1109 void Render::initSceneList()
1111 kDebug() << "-------- INIT SCENE LIST ------_";
1113 QDomElement mlt = doc.createElement("mlt");
1114 doc.appendChild(mlt);
1115 QDomElement prod = doc.createElement("producer");
1116 prod.setAttribute("resource", "colour");
1117 prod.setAttribute("colour", "red");
1118 prod.setAttribute("id", "black");
1119 prod.setAttribute("in", "0");
1120 prod.setAttribute("out", "0");
1122 QDomElement tractor = doc.createElement("tractor");
1123 QDomElement multitrack = doc.createElement("multitrack");
1125 QDomElement playlist1 = doc.createElement("playlist");
1126 playlist1.appendChild(prod);
1127 multitrack.appendChild(playlist1);
1128 QDomElement playlist2 = doc.createElement("playlist");
1129 multitrack.appendChild(playlist2);
1130 QDomElement playlist3 = doc.createElement("playlist");
1131 multitrack.appendChild(playlist3);
1132 QDomElement playlist4 = doc.createElement("playlist");
1133 multitrack.appendChild(playlist4);
1134 QDomElement playlist5 = doc.createElement("playlist");
1135 multitrack.appendChild(playlist5);
1136 tractor.appendChild(multitrack);
1137 mlt.appendChild(tractor);
1138 // kDebug()<<doc.toString();
1140 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
1141 setSceneList(doc, 0);
1145 void Render::loadUrl(const QString &url)
1147 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, url.toUtf8().constData());
1148 setProducer(producer, 0);
1151 int Render::setProducer(Mlt::Producer *producer, int position)
1153 m_refreshTimer.stop();
1154 requestedSeekPosition = SEEK_INACTIVE;
1155 QMutexLocker locker(&m_mutex);
1157 int consumerPosition = 0;
1158 if (m_winid == -1 || !m_mltConsumer) {
1159 kDebug()<<" / / / / WARNING, MONITOR NOT READY";
1160 if (producer) delete producer;
1163 bool monitorIsActive = false;
1164 m_mltConsumer->set("refresh", 0);
1165 if (!m_mltConsumer->is_stopped()) {
1166 monitorIsActive = true;
1167 m_mltConsumer->stop();
1169 m_mltConsumer->purge();
1170 consumerPosition = m_mltConsumer->position();
1174 if (!producer || !producer->is_valid()) {
1175 if (producer) delete producer;
1176 producer = m_blackClip->cut(0, 1);
1177 producer->set("id", "black");
1180 if (!producer || !producer->is_valid()) {
1181 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
1184 if (m_mltProducer) currentId = m_mltProducer->get("id");
1186 if (position == -1 && producer->get("id") == currentId) position = consumerPosition;
1187 if (position != -1) producer->seek(position);
1188 m_fps = producer->get_fps();
1189 int volume = KdenliveSettings::volume();
1190 if (producer->get_int("_audioclip") == 1) {
1191 // This is an audio only clip, create fake multitrack to apply audiowave filter
1192 Mlt::Tractor *tractor = new Mlt::Tractor();
1193 Mlt::Producer *color= new Mlt::Producer(*m_mltProfile, "color:red");
1194 color->set_in_and_out(0, producer->get_out());
1195 tractor->set_track(*producer, 0);
1196 tractor->set_track(*color, 1);
1198 Mlt::Consumer xmlConsumer(*m_mltProfile, "xml:audio_hack");
1199 if (!xmlConsumer.is_valid()) return -1;
1200 xmlConsumer.set("terminate_on_pause", 1);
1201 xmlConsumer.connect(tractor->parent());
1206 QString playlist = QString::fromUtf8(xmlConsumer.get("audio_hack"));
1208 Mlt::Producer *result = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1209 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "audiowave");
1210 result->attach(*filter);
1211 tractor = new Mlt::Tractor();
1212 tractor->set_track(*result, 0);
1215 producer = &(tractor->parent());
1216 m_mltConsumer->connect(*producer);
1219 producer->set("meta.volume", (double)volume / 100);
1220 blockSignals(false);
1221 m_mltConsumer->connect(*producer);
1223 if (m_mltProducer) {
1224 m_mltProducer->set_speed(0);
1225 delete m_mltProducer;
1226 m_mltProducer = NULL;
1228 m_mltProducer = producer;
1229 m_mltProducer->set_speed(0);
1230 if (monitorIsActive) {
1233 emit durationChanged(m_mltProducer->get_playtime());
1234 position = m_mltProducer->position();
1235 emit rendererPosition(position);
1239 void Render::startConsumer() {
1240 if (m_mltConsumer->is_stopped() && m_mltConsumer->start() == -1) {
1241 // ARGH CONSUMER BROKEN!!!!
1242 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."));
1243 if (m_showFrameEvent) delete m_showFrameEvent;
1244 m_showFrameEvent = NULL;
1245 if (m_pauseEvent) delete m_pauseEvent;
1246 m_pauseEvent = NULL;
1247 delete m_mltConsumer;
1248 m_mltConsumer = NULL;
1251 m_mltConsumer->set("refresh", 1);
1255 int Render::setSceneList(QDomDocument list, int position)
1257 return setSceneList(list.toString(), position);
1260 int Render::setSceneList(QString playlist, int position)
1262 requestedSeekPosition = SEEK_INACTIVE;
1263 m_refreshTimer.stop();
1264 QMutexLocker locker(&m_mutex);
1265 if (m_winid == -1) return -1;
1268 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
1270 // Remove previous profile info
1272 doc.setContent(playlist);
1273 QDomElement profile = doc.documentElement().firstChildElement("profile");
1274 doc.documentElement().removeChild(profile);
1275 playlist = doc.toString();
1277 if (m_mltConsumer) {
1278 if (!m_mltConsumer->is_stopped()) {
1279 m_mltConsumer->stop();
1281 m_mltConsumer->set("refresh", 0);
1283 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
1286 m_requestList.clear();
1287 m_infoThread.waitForFinished();
1289 if (m_mltProducer) {
1290 m_mltProducer->set_speed(0);
1291 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1293 /*Mlt::Service service(m_mltProducer->parent().get_service());
1296 if (service.type() == tractor_type) {
1297 Mlt::Tractor tractor(service);
1298 Mlt::Field *field = tractor.field();
1299 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1300 mlt_service nextservicetodisconnect;
1301 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1302 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1303 QString resource = mlt_properties_get(properties, "mlt_service");
1304 // Delete all transitions
1305 while (mlt_type == "transition") {
1306 nextservicetodisconnect = nextservice;
1307 nextservice = mlt_service_producer(nextservice);
1308 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1309 if (nextservice == NULL) break;
1310 properties = MLT_SERVICE_PROPERTIES(nextservice);
1311 mlt_type = mlt_properties_get(properties, "mlt_type");
1312 resource = mlt_properties_get(properties, "mlt_service");
1316 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1317 Mlt::Producer trackProducer(tractor.track(trackNb));
1318 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1319 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1325 qDeleteAll(m_slowmotionProducers.values());
1326 m_slowmotionProducers.clear();
1328 delete m_mltProducer;
1329 m_mltProducer = NULL;
1334 m_locale = QLocale();
1335 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1336 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1337 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1338 m_mltProducer = m_blackClip->cut(0, 1);
1341 m_mltProducer->set("eof", "pause");
1343 int volume = KdenliveSettings::volume();
1344 m_mltProducer->set("meta.volume", (double)volume / 100);
1345 m_mltProducer->optimise();
1347 /*if (KdenliveSettings::osdtimecode()) {
1348 // Attach filter for on screen display of timecode
1350 QString attr = "attr_check";
1351 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1352 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1353 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1354 mlt_filter_close( filter );
1356 m_osdInfo = new Mlt::Filter("data_show");
1357 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1358 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1359 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1360 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1361 m_osdInfo->set("dynamic", "1");
1363 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1365 m_osdInfo->set("dynamic", "0");
1368 m_fps = m_mltProducer->get_fps();
1369 if (position != 0) {
1370 // Seek to correct place after opening project.
1371 m_mltProducer->seek(position);
1374 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1375 m_mltConsumer->connect(*m_mltProducer);
1376 m_mltProducer->set_speed(0);
1377 fillSlowMotionProducers();
1378 blockSignals(false);
1379 emit durationChanged(m_mltProducer->get_playtime());
1382 //kDebug()<<"// SETSCN LST, POS: "<<position;
1383 //if (position != 0) emit rendererPosition(position);
1386 void Render::checkMaxThreads()
1388 // Make sure we don't use too much threads, MLT avformat does not cope with too much threads
1389 // Currently, Kdenlive uses the following avformat threads:
1390 // One thread to get info when adding a clip
1391 // One thread to create the timeline video thumbnails
1392 // One thread to create the audio thumbnails
1393 Mlt::Service service(m_mltProducer->parent().get_service());
1394 if (service.type() != tractor_type) {
1395 kWarning() << "// TRACTOR PROBLEM";
1398 Mlt::Tractor tractor(service);
1399 int mltMaxThreads = mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1400 int requestedThreads = tractor.count() + 4;
1401 if (requestedThreads > mltMaxThreads) {
1402 mlt_service_cache_set_size(service.get_service(), "producer_avformat", requestedThreads);
1403 kDebug()<<"// MLT threads updated to: "<<mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1407 const QString Render::sceneList()
1410 Mlt::Profile profile((mlt_profile) 0);
1411 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1412 if (!xmlConsumer.is_valid()) return QString();
1413 m_mltProducer->optimise();
1414 xmlConsumer.set("terminate_on_pause", 1);
1415 Mlt::Producer prod(m_mltProducer->get_producer());
1416 if (!prod.is_valid()) return QString();
1417 bool split = m_isSplitView;
1418 if (split) slotSplitView(false);
1419 xmlConsumer.connect(prod);
1421 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1422 if (split) slotSplitView(true);
1426 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1430 doc.setContent(sceneList(), false);
1431 if (doc.isNull()) return false;
1432 QDomElement root = doc.documentElement();
1433 if (!kdenliveData.isNull() && !root.isNull()) {
1434 // add Kdenlive specific tags
1435 root.appendChild(doc.importNode(kdenliveData, true));
1437 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1438 kWarning() << "////// ERROR writing to file: " << path;
1441 file.write(doc.toString().toUtf8());
1442 if (file.error() != QFile::NoError) {
1450 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1452 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1453 m_mltProducer->optimise();
1454 xmlConsumer.set("terminate_on_pause", 1);
1455 if (m_name == Kdenlive::clipMonitor) {
1456 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1458 list.insert_at(0, prod, 0);
1460 list.set("title", desc.toUtf8().constData());
1461 xmlConsumer.connect(list);
1464 //TODO: not working yet, save zone from timeline
1465 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1466 /* Mlt::Service service(p1->parent().get_service());
1467 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1469 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1470 //prod->set("title", desc.toUtf8().constData());
1471 xmlConsumer.connect(*p1); //list);
1474 xmlConsumer.start();
1478 bool Render::saveClip(int track, GenTime position, KUrl url, QString desc)
1481 Mlt::Service service(m_mltProducer->parent().get_service());
1482 Mlt::Tractor tractor(service);
1483 Mlt::Producer trackProducer(tractor.track(track));
1484 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1486 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1487 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1489 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1493 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1494 xmlConsumer.set("terminate_on_pause", 1);
1496 list.insert_at(0, clip, 0);
1498 list.set("title", desc.toUtf8().constData());
1499 xmlConsumer.connect(list);
1501 kDebug()<<"// SAVED: "<<url;
1505 double Render::fps() const
1510 int Render::volume() const
1512 if (!m_mltConsumer || !m_mltProducer) return -1;
1513 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1516 void Render::slotSetVolume(int volume)
1518 if (!m_mltConsumer || !m_mltProducer) return;
1519 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1522 m_mltConsumer->set("refresh", 0);
1523 // Attach filter for on screen display of timecode
1524 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1525 mlt_properties_set_double( properties, "meta.volume", volume );
1526 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1527 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1529 if (!KdenliveSettings::osdtimecode()) {
1530 m_mltProducer->detach(*m_osdInfo);
1531 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1532 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1535 //m_osdTimer->setSingleShot(2500);
1538 void Render::slotOsdTimeout()
1540 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1541 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1542 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1543 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1547 void Render::start()
1549 m_refreshTimer.stop();
1550 QMutexLocker locker(&m_mutex);
1551 if (m_winid == -1) {
1552 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1555 if (!m_mltConsumer) {
1556 kDebug()<<" / - - - STARTED BEFORE CONSUMER!!!";
1559 if (m_mltConsumer->is_stopped()) {
1560 if (m_mltConsumer->start() == -1) {
1561 //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."));
1562 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1564 m_mltConsumer->purge();
1565 m_mltConsumer->set("refresh", 1);
1572 requestedSeekPosition = SEEK_INACTIVE;
1573 m_refreshTimer.stop();
1574 QMutexLocker locker(&m_mutex);
1576 if (m_mltProducer == NULL) return;
1577 if (m_mltConsumer) {
1578 m_mltConsumer->set("refresh", 0);
1579 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1580 m_mltConsumer->purge();
1583 if (m_mltProducer) {
1584 if (m_isZoneMode) resetZoneMode();
1585 m_mltProducer->set_speed(0.0);
1589 void Render::stop(const GenTime & startTime)
1591 requestedSeekPosition = SEEK_INACTIVE;
1592 m_refreshTimer.stop();
1593 QMutexLocker locker(&m_mutex);
1595 if (m_mltProducer) {
1596 if (m_isZoneMode) resetZoneMode();
1597 m_mltProducer->set_speed(0.0);
1598 m_mltProducer->seek((int) startTime.frames(m_fps));
1600 m_mltConsumer->purge();
1603 void Render::pause()
1605 requestedSeekPosition = SEEK_INACTIVE;
1606 if (!m_mltProducer || !m_mltConsumer || !m_isActive)
1609 m_mltProducer->set_speed(0.0);
1610 /*m_mltConsumer->set("refresh", 0);
1611 //if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1612 m_mltProducer->seek(m_mltConsumer->position());*/
1615 void Render::setActiveMonitor()
1617 if (!m_isActive) emit activateMonitor(m_name);
1620 void Render::switchPlay(bool play)
1622 QMutexLocker locker(&m_mutex);
1623 requestedSeekPosition = SEEK_INACTIVE;
1624 if (!m_mltProducer || !m_mltConsumer || !m_isActive)
1626 if (m_isZoneMode) resetZoneMode();
1627 if (play && m_paused) {
1628 if (m_name == Kdenlive::clipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
1630 m_mltProducer->set_speed(1.0);
1631 if (m_mltConsumer->is_stopped()) {
1632 m_mltConsumer->start();
1634 m_mltConsumer->set("refresh", 1);
1639 m_mltProducer->set_speed(0.0);
1642 // SDL consumer, hack to allow pausing near the end of the playlist
1643 m_mltConsumer->set("refresh", 0);
1644 m_mltConsumer->stop();
1645 m_mltProducer->set_speed(0.0);
1646 m_mltProducer->seek(m_mltConsumer->position());
1647 m_mltConsumer->start();
1652 void Render::play(double speed)
1654 requestedSeekPosition = SEEK_INACTIVE;
1655 if (!m_mltProducer || !m_isActive) return;
1656 double current_speed = m_mltProducer->get_speed();
1657 if (current_speed == speed) return;
1658 if (m_isZoneMode) resetZoneMode();
1659 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1660 m_mltProducer->set_speed(speed);
1661 if (m_mltConsumer->is_stopped() && speed != 0) {
1662 m_mltConsumer->start();
1664 m_paused = speed == 0;
1665 if (current_speed == 0 && speed != 0) m_mltConsumer->set("refresh", 1);
1668 void Render::play(const GenTime & startTime)
1670 requestedSeekPosition = SEEK_INACTIVE;
1671 if (!m_mltProducer || !m_mltConsumer || !m_isActive)
1674 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1675 m_mltProducer->set_speed(1.0);
1676 m_mltConsumer->set("refresh", 1);
1679 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1681 requestedSeekPosition = SEEK_INACTIVE;
1682 if (!m_mltProducer || !m_mltConsumer || !m_isActive)
1684 //m_mltProducer->set("eof", "loop");
1685 m_isLoopMode = true;
1686 m_loopStart = startTime;
1687 playZone(startTime, stopTime);
1690 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1692 requestedSeekPosition = SEEK_INACTIVE;
1693 if (!m_mltProducer || !m_mltConsumer || !m_isActive)
1695 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1696 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1698 m_mltProducer->set_speed(1.0);
1699 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1700 m_mltConsumer->set("refresh", 1);
1701 m_isZoneMode = true;
1704 void Render::resetZoneMode()
1706 if (!m_isZoneMode && !m_isLoopMode) return;
1707 m_mltProducer->set("out", m_mltProducer->get_length());
1708 m_isZoneMode = false;
1709 m_isLoopMode = false;
1712 void Render::seekToFrame(int pos)
1714 if (!m_mltProducer || !m_isActive)
1720 void Render::seekToFrameDiff(int diff)
1722 if (!m_mltProducer || !m_isActive)
1725 if (requestedSeekPosition == SEEK_INACTIVE)
1726 seek(m_mltProducer->position() + diff);
1727 else seek(requestedSeekPosition + diff);
1730 void Render::refreshIfActive()
1732 if (!m_mltConsumer->is_stopped() && m_mltProducer && m_paused && m_isActive) m_refreshTimer.start();
1735 void Render::doRefresh()
1737 if (m_mltProducer && m_paused && m_isActive) m_refreshTimer.start();
1740 void Render::refresh()
1742 m_refreshTimer.stop();
1743 QMutexLocker locker(&m_mutex);
1744 if (!m_mltProducer || !m_isActive)
1746 if (m_mltConsumer) {
1747 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1748 m_mltConsumer->set("refresh", 1);
1749 //m_mltConsumer->purge();
1753 void Render::setDropFrames(bool show)
1755 QMutexLocker locker(&m_mutex);
1756 if (m_mltConsumer) {
1757 int dropFrames = KdenliveSettings::mltthreads();
1758 if (show == false) dropFrames = -dropFrames;
1759 m_mltConsumer->stop();
1760 m_mltConsumer->set("real_time", dropFrames);
1761 if (m_mltConsumer->start() == -1) {
1762 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1768 void Render::setConsumerProperty(const QString &name, const QString &value)
1770 QMutexLocker locker(&m_mutex);
1771 if (m_mltConsumer) {
1772 m_mltConsumer->stop();
1773 m_mltConsumer->set(name.toUtf8().constData(), value.toUtf8().constData());
1774 if (m_isActive && m_mltConsumer->start() == -1) {
1775 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1781 bool Render::isPlaying() const
1783 if (!m_mltConsumer || m_mltConsumer->is_stopped()) return false;
1787 double Render::playSpeed() const
1789 if (m_mltProducer) return m_mltProducer->get_speed();
1793 GenTime Render::seekPosition() const
1795 if (m_mltConsumer) return GenTime((int) m_mltConsumer->position(), m_fps);
1796 //if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1797 else return GenTime();
1800 int Render::seekFramePosition() const
1802 //if (m_mltProducer) return (int) m_mltProducer->position();
1803 if (m_mltConsumer) return (int) m_mltConsumer->position();
1807 void Render::emitFrameUpdated(Mlt::Frame& frame)
1809 mlt_image_format format = mlt_image_rgb24;
1812 const uchar* image = frame.get_image(format, width, height);
1813 QImage qimage(width, height, QImage::Format_RGB888); //Format_ARGB32_Premultiplied);
1814 memcpy(qimage.scanLine(0), image, width * height * 3);
1815 emit frameUpdated(qimage);
1818 int Render::getCurrentSeekPosition() const
1820 if (requestedSeekPosition != SEEK_INACTIVE) return requestedSeekPosition;
1821 return (int) m_mltProducer->position();
1824 void Render::emitFrameNumber()
1826 int currentPos = m_mltConsumer->position();
1827 if (currentPos == requestedSeekPosition) {
1828 requestedSeekPosition = SEEK_INACTIVE;
1831 emit rendererPosition(currentPos);
1832 if (requestedSeekPosition != SEEK_INACTIVE) {
1833 m_mltConsumer->purge();
1834 m_mltProducer->seek(requestedSeekPosition);
1835 if (m_mltProducer->get_speed() == 0 && !m_paused) {
1836 m_mltConsumer->set("refresh", 1);
1838 requestedSeekPosition = SEEK_INACTIVE;
1842 void Render::emitConsumerStopped(bool forcePause)
1844 // This is used to know when the playing stopped
1845 if (m_mltProducer && (forcePause || (!m_paused && m_mltProducer->get_speed() == 0))) {
1846 double pos = m_mltProducer->position();
1848 if (m_isLoopMode) play(m_loopStart);
1849 //else if (m_isZoneMode) resetZoneMode();
1850 emit rendererStopped((int) pos);
1854 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1856 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1859 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1861 if (!m_mltProducer) {
1862 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1866 //int height = 1080;//KdenliveSettings::defaultheight();
1867 //int width = 1940; //KdenliveSettings::displaywidth();
1869 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1871 QPixmap pix(width, height);
1872 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1873 m_convert.set("forced", mlt_image_rgb24a);
1874 m_mltProducer->attach(m_convert);
1875 Mlt::Frame * frame = m_mltProducer->get_frame();
1876 m_mltProducer->detach(m_convert);
1878 pix = frameThumbnail(frame, width, height);
1881 pix.save(url.path(), "PNG");
1882 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1886 void Render::showFrame(Mlt::Frame* frame)
1888 int currentPos = m_mltConsumer->position();
1889 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1890 emit rendererPosition(currentPos);
1891 if (frame->is_valid()) {
1892 mlt_image_format format = mlt_image_rgb24;
1895 const uchar* image = frame->get_image(format, width, height);
1896 QImage qimage(width, height, QImage::Format_RGB888); //Format_ARGB32_Premultiplied);
1897 memcpy(qimage.scanLine(0), image, width * height * 3);
1898 if (analyseAudio) showAudio(*frame);
1900 emit showImageSignal(qimage);
1901 if (sendFrameForAnalysis) {
1902 emit frameUpdated(qimage);//.rgbSwapped());
1904 } else delete frame;
1905 showFrameSemaphore.release();
1906 emit checkSeeking();
1909 void Render::slotCheckSeeking()
1911 if (requestedSeekPosition != SEEK_INACTIVE) {
1912 m_mltProducer->seek(requestedSeekPosition);
1916 requestedSeekPosition = SEEK_INACTIVE;
1920 void Render::disablePreview(bool disable)
1922 if (m_mltConsumer) {
1923 m_mltConsumer->stop();
1924 m_mltConsumer->set("preview_off", (int) disable);
1925 m_mltConsumer->set("refresh", 0);
1926 m_mltConsumer->start();
1930 void Render::showAudio(Mlt::Frame& frame)
1932 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1936 mlt_audio_format audio_format = mlt_audio_s16;
1937 //FIXME: should not be hardcoded..
1939 int num_channels = 2;
1941 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1947 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1948 // So the vector is of size samples*channels.
1949 QVector<int16_t> sampleVector(samples*num_channels);
1950 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1953 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1958 * MLT playlist direct manipulation.
1961 void Render::mltCheckLength(Mlt::Tractor *tractor)
1963 //kDebug()<<"checking track length: "<<track<<"..........";
1965 int trackNb = tractor->count();
1968 if (m_isZoneMode) resetZoneMode();
1970 Mlt::Producer trackProducer(tractor->track(0));
1971 duration = trackProducer.get_playtime() - 1;
1972 m_mltProducer->set("out", duration);
1973 emit durationChanged(duration);
1976 while (trackNb > 1) {
1977 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1978 trackDuration = trackProducer.get_playtime() - 1;
1979 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1980 if (trackDuration > duration) duration = trackDuration;
1984 Mlt::Producer blackTrackProducer(tractor->track(0));
1986 if (blackTrackProducer.get_playtime() - 1 != duration) {
1987 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1988 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1989 if (blackclip && blackclip->is_blank()) {
1994 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1995 if (blackclip) delete blackclip;
1996 blackTrackPlaylist.clear();
1997 m_blackClip->set("length", duration + 1);
1998 m_blackClip->set("out", duration);
1999 blackclip = m_blackClip->cut(0, duration);
2000 blackTrackPlaylist.insert_at(0, blackclip, 1);
2002 if (duration > blackclip->parent().get_length()) {
2003 blackclip->parent().set("length", duration + 1);
2004 blackclip->parent().set("out", duration);
2005 blackclip->set("length", duration + 1);
2007 blackTrackPlaylist.resize_clip(0, 0, duration);
2011 if (m_mltConsumer->position() > duration) {
2012 m_mltConsumer->purge();
2013 m_mltProducer->seek(duration);
2015 m_mltProducer->set("out", duration);
2016 emit durationChanged(duration);
2020 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
2022 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
2024 // We want a slowmotion producer
2025 double speed = element.attribute("speed", "1.0").toDouble();
2026 int strobe = element.attribute("strobe", "1").toInt();
2027 QString url = QString::fromUtf8(prod->get("resource"));
2028 url.append('?' + locale.toString(speed));
2029 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2030 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2031 if (!slowprod || slowprod->get_producer() == NULL) {
2032 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2033 if (strobe > 1) slowprod->set("strobe", strobe);
2034 QString id = prod->parent().get("id");
2035 if (id.contains('_')) id = id.section('_', 0, 0);
2036 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
2037 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2038 slowprod->set("id", producerid.toUtf8().constData());
2039 m_slowmotionProducers.insert(url, slowprod);
2044 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
2046 m_refreshTimer.stop();
2047 if (m_mltProducer == NULL) {
2048 kDebug() << "PLAYLIST NOT INITIALISED //////";
2052 kDebug() << "Cannot insert clip without producer //////";
2055 Mlt::Producer parentProd(m_mltProducer->parent());
2056 if (parentProd.get_producer() == NULL) {
2057 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2061 Mlt::Service service(parentProd.get_service());
2062 if (service.type() != tractor_type) {
2063 kWarning() << "// TRACTOR PROBLEM";
2066 Mlt::Tractor tractor(service);
2067 if (info.track > tractor.count() - 1) {
2068 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
2072 Mlt::Producer trackProducer(tractor.track(info.track));
2073 int trackDuration = trackProducer.get_playtime() - 1;
2074 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2075 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
2076 prod = checkSlowMotionProducer(prod, element);
2077 if (prod == NULL || !prod->is_valid()) {
2082 int cutPos = (int) info.cropStart.frames(m_fps);
2083 if (cutPos < 0) cutPos = 0;
2084 int insertPos = (int) info.startPos.frames(m_fps);
2085 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
2086 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
2087 if (overwrite && (insertPos < trackDuration)) {
2088 // Replace zone with blanks
2089 //trackPlaylist.split_at(insertPos, true);
2090 trackPlaylist.remove_region(insertPos, cutDuration + 1);
2091 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2092 trackPlaylist.insert_blank(clipIndex, cutDuration);
2094 trackPlaylist.split_at(insertPos, true);
2095 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2096 trackPlaylist.insert_blank(clipIndex, cutDuration);
2098 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
2100 /*if (QString(prod->get("transparency")).toInt() == 1)
2101 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
2103 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
2105 /*tractor.multitrack()->refresh();
2106 tractor.refresh();*/
2111 bool Render::mltCutClip(int track, GenTime position)
2113 Mlt::Service service(m_mltProducer->parent().get_service());
2114 if (service.type() != tractor_type) {
2115 kWarning() << "// TRACTOR PROBLEM";
2119 Mlt::Tractor tractor(service);
2120 Mlt::Producer trackProducer(tractor.track(track));
2121 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2124 /* // Display playlist info
2125 kDebug()<<"//////////// BEFORE";
2126 for (int i = 0; i < trackPlaylist.count(); i++) {
2127 int blankStart = trackPlaylist.clip_start(i);
2128 int blankDuration = trackPlaylist.clip_length(i) - 1;
2130 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2131 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2134 int cutPos = (int) position.frames(m_fps);
2136 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
2137 if (trackPlaylist.is_blank(clipIndex)) {
2138 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
2142 int clipStart = trackPlaylist.clip_start(clipIndex);
2143 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
2146 // duplicate effects
2147 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
2148 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
2150 if (original == NULL || clip == NULL) {
2151 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
2155 Mlt::Service clipService(original->get_service());
2156 Mlt::Service dupService(clip->get_service());
2162 Mlt::Filter *filter = clipService.filter(ct);
2164 // Only duplicate Kdenlive filters, and skip the fade in effects
2165 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
2166 // looks like there is no easy way to duplicate a filter,
2167 // so we will create a new one and duplicate its properties
2168 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
2169 if (dup && dup->is_valid()) {
2170 Mlt::Properties entries(filter->get_properties());
2171 for (int i = 0; i < entries.count(); i++) {
2172 dup->set(entries.get_name(i), entries.get(i));
2174 dupService.attach(*dup);
2178 filter = clipService.filter(ct);
2181 /* // Display playlist info
2182 kDebug()<<"//////////// AFTER";
2183 for (int i = 0; i < trackPlaylist.count(); i++) {
2184 int blankStart = trackPlaylist.clip_start(i);
2185 int blankDuration = trackPlaylist.clip_length(i) - 1;
2187 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2188 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2193 Mlt::Tractor *Render::lockService()
2195 // we are going to replace some clips, purge consumer
2196 if (!m_mltProducer) return NULL;
2197 QMutexLocker locker(&m_mutex);
2198 if (m_mltConsumer) {
2199 m_mltConsumer->purge();
2201 Mlt::Service service(m_mltProducer->parent().get_service());
2202 if (service.type() != tractor_type) {
2206 return new Mlt::Tractor(service);
2210 void Render::unlockService(Mlt::Tractor *tractor)
2215 if (!m_mltProducer) return;
2216 Mlt::Service service(m_mltProducer->parent().get_service());
2217 if (service.type() != tractor_type) {
2218 kWarning() << "// TRACTOR PROBLEM";
2224 bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement element, Mlt::Producer *prod)
2227 if (prod == NULL || tractor == NULL) {
2228 kDebug() << "Cannot update clip with null producer //////";
2232 Mlt::Producer trackProducer(tractor->track(tractor->count() - 1 - info.track));
2233 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2234 int startPos = info.startPos.frames(m_fps);
2235 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2236 if (trackPlaylist.is_blank(clipIndex)) {
2237 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
2240 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2242 QList <Mlt::Filter *> filtersList;
2243 Mlt::Service sourceService(clip->get_service());
2245 Mlt::Filter *filter = sourceService.filter(ct);
2247 if (filter->get_int("kdenlive_ix") != 0) {
2248 filtersList.append(filter);
2251 filter = sourceService.filter(ct);
2254 clip = trackPlaylist.replace_with_blank(clipIndex);
2256 prod = checkSlowMotionProducer(prod, element);
2257 if (prod == NULL || !prod->is_valid()) {
2261 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
2262 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
2263 Mlt::Service destService(clip2->get_service());
2266 if (!filtersList.isEmpty()) {
2267 for (int i = 0; i < filtersList.count(); i++)
2268 destService.attach(*(filtersList.at(i)));
2274 bool Render::mltRemoveClip(int track, GenTime position)
2276 m_refreshTimer.stop();
2278 Mlt::Service service(m_mltProducer->parent().get_service());
2279 if (service.type() != tractor_type) {
2280 kWarning() << "// TRACTOR PROBLEM";
2284 Mlt::Tractor tractor(service);
2285 Mlt::Producer trackProducer(tractor.track(track));
2286 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2287 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2289 if (trackPlaylist.is_blank(clipIndex)) {
2290 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
2294 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2295 if (clip) delete clip;
2296 trackPlaylist.consolidate_blanks(0);
2298 /* // Display playlist info
2299 kDebug()<<"//// AFTER";
2300 for (int i = 0; i < trackPlaylist.count(); i++) {
2301 int blankStart = trackPlaylist.clip_start(i);
2302 int blankDuration = trackPlaylist.clip_length(i) - 1;
2304 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2305 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2308 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
2312 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
2314 if (!m_mltProducer) {
2315 kDebug() << "PLAYLIST NOT INITIALISED //////";
2318 Mlt::Producer parentProd(m_mltProducer->parent());
2319 if (parentProd.get_producer() == NULL) {
2320 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2324 Mlt::Service service(parentProd.get_service());
2325 Mlt::Tractor tractor(service);
2326 int insertPos = pos.frames(m_fps);
2328 Mlt::Producer trackProducer(tractor.track(track));
2329 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2330 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2331 if (clipIndex == trackPlaylist.count()) {
2332 // We are after the end of the playlist
2335 if (!trackPlaylist.is_blank(clipIndex)) return 0;
2336 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
2337 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
2340 int Render::mltTrackDuration(int track)
2342 if (!m_mltProducer) {
2343 kDebug() << "PLAYLIST NOT INITIALISED //////";
2346 Mlt::Producer parentProd(m_mltProducer->parent());
2347 if (parentProd.get_producer() == NULL) {
2348 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2352 Mlt::Service service(parentProd.get_service());
2353 Mlt::Tractor tractor(service);
2355 Mlt::Producer trackProducer(tractor.track(track));
2356 return trackProducer.get_playtime() - 1;
2359 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
2361 if (!m_mltProducer) {
2362 kDebug() << "PLAYLIST NOT INITIALISED //////";
2365 Mlt::Producer parentProd(m_mltProducer->parent());
2366 if (parentProd.get_producer() == NULL) {
2367 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2370 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
2371 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
2373 Mlt::Service service(parentProd.get_service());
2374 Mlt::Tractor tractor(service);
2376 int diff = duration.frames(m_fps);
2377 int offset = timeOffset.frames(m_fps);
2381 // insert space in one track only
2382 Mlt::Producer trackProducer(tractor.track(track));
2383 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2384 insertPos = trackClipStartList.value(track);
2385 if (insertPos != -1) {
2386 insertPos += offset;
2387 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2389 trackPlaylist.insert_blank(clipIndex, diff - 1);
2391 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
2392 if (!trackPlaylist.is_blank(clipIndex)) {
2393 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2395 int position = trackPlaylist.clip_start(clipIndex);
2396 int blankDuration = trackPlaylist.clip_length(clipIndex);
2397 if (blankDuration + diff == 0) {
2398 trackPlaylist.remove(clipIndex);
2399 } else trackPlaylist.remove_region(position, -diff);
2401 trackPlaylist.consolidate_blanks(0);
2403 // now move transitions
2404 mlt_service serv = m_mltProducer->parent().get_service();
2405 mlt_service nextservice = mlt_service_get_producer(serv);
2406 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2407 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2408 QString resource = mlt_properties_get(properties, "mlt_service");
2410 while (mlt_type == "transition") {
2411 mlt_transition tr = (mlt_transition) nextservice;
2412 int currentTrack = mlt_transition_get_b_track(tr);
2413 int currentIn = (int) mlt_transition_get_in(tr);
2414 int currentOut = (int) mlt_transition_get_out(tr);
2415 insertPos = trackTransitionStartList.value(track);
2416 if (insertPos != -1) {
2417 insertPos += offset;
2418 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
2419 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2422 nextservice = mlt_service_producer(nextservice);
2423 if (nextservice == NULL) break;
2424 properties = MLT_SERVICE_PROPERTIES(nextservice);
2425 mlt_type = mlt_properties_get(properties, "mlt_type");
2426 resource = mlt_properties_get(properties, "mlt_service");
2429 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
2430 Mlt::Producer trackProducer(tractor.track(trackNb));
2431 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2433 //int clipNb = trackPlaylist.count();
2434 insertPos = trackClipStartList.value(trackNb);
2435 if (insertPos != -1) {
2436 insertPos += offset;
2438 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2439 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2440 for (int i = 0; i < clipNb; i++) {
2441 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2442 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2443 kDebug()<<"-------------";
2445 kDebug()<<"END-------------";*/
2448 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2450 trackPlaylist.insert_blank(clipIndex, diff - 1);
2452 if (!trackPlaylist.is_blank(clipIndex)) {
2455 if (!trackPlaylist.is_blank(clipIndex)) {
2456 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2458 int position = trackPlaylist.clip_start(clipIndex);
2459 int blankDuration = trackPlaylist.clip_length(clipIndex);
2460 if (diff + blankDuration == 0) {
2461 trackPlaylist.remove(clipIndex);
2462 } else trackPlaylist.remove_region(position, - diff);
2464 trackPlaylist.consolidate_blanks(0);
2467 // now move transitions
2468 mlt_service serv = m_mltProducer->parent().get_service();
2469 mlt_service nextservice = mlt_service_get_producer(serv);
2470 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2471 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2472 QString resource = mlt_properties_get(properties, "mlt_service");
2474 while (mlt_type == "transition") {
2475 mlt_transition tr = (mlt_transition) nextservice;
2476 int currentIn = (int) mlt_transition_get_in(tr);
2477 int currentOut = (int) mlt_transition_get_out(tr);
2478 int currentTrack = mlt_transition_get_b_track(tr);
2479 insertPos = trackTransitionStartList.value(currentTrack);
2480 if (insertPos != -1) {
2481 insertPos += offset;
2482 if (currentOut > insertPos && resource != "mix") {
2483 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2486 nextservice = mlt_service_producer(nextservice);
2487 if (nextservice == NULL) break;
2488 properties = MLT_SERVICE_PROPERTIES(nextservice);
2489 mlt_type = mlt_properties_get(properties, "mlt_type");
2490 resource = mlt_properties_get(properties, "mlt_service");
2494 mltCheckLength(&tractor);
2495 m_mltConsumer->set("refresh", 1);
2499 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2501 if (source == dest) return;
2502 Mlt::Service sourceService(source->get_service());
2503 Mlt::Service destService(dest->get_service());
2505 // move all effects to the correct producer
2507 Mlt::Filter *filter = sourceService.filter(ct);
2509 if (filter->get_int("kdenlive_ix") != 0) {
2510 sourceService.detach(*filter);
2511 destService.attach(*filter);
2513 filter = sourceService.filter(ct);
2517 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2520 Mlt::Service service(m_mltProducer->parent().get_service());
2521 if (service.type() != tractor_type) {
2522 kWarning() << "// TRACTOR PROBLEM";
2526 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2527 Mlt::Tractor tractor(service);
2528 Mlt::Producer trackProducer(tractor.track(info.track));
2529 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2530 int startPos = info.startPos.frames(m_fps);
2531 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2532 int clipLength = trackPlaylist.clip_length(clipIndex);
2534 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2535 if (original == NULL) {
2538 if (!original->is_valid() || original->is_blank()) {
2543 Mlt::Producer clipparent = original->parent();
2544 if (!clipparent.is_valid() || clipparent.is_blank()) {
2550 QString serv = clipparent.get("mlt_service");
2551 QString id = clipparent.get("id");
2552 if (speed <= 0 && speed > -1) speed = 1.0;
2553 //kDebug() << "CLIP SERVICE: " << serv;
2554 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2556 QString url = QString::fromUtf8(clipparent.get("resource"));
2557 url.append('?' + m_locale.toString(speed));
2558 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2559 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2560 if (!slowprod || slowprod->get_producer() == NULL) {
2561 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2562 if (strobe > 1) slowprod->set("strobe", strobe);
2563 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2564 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2565 slowprod->set("id", producerid.toUtf8().constData());
2566 // copy producer props
2567 double ar = original->parent().get_double("force_aspect_ratio");
2568 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2569 double fps = original->parent().get_double("force_fps");
2570 if (fps != 0.0) slowprod->set("force_fps", fps);
2571 int threads = original->parent().get_int("threads");
2572 if (threads != 0) slowprod->set("threads", threads);
2573 if (original->parent().get("force_progressive"))
2574 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2575 if (original->parent().get("force_tff"))
2576 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2577 int ix = original->parent().get_int("video_index");
2578 if (ix != 0) slowprod->set("video_index", ix);
2579 int colorspace = original->parent().get_int("force_colorspace");
2580 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2581 int full_luma = original->parent().get_int("set.force_full_luma");
2582 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2583 m_slowmotionProducers.insert(url, slowprod);
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);
2592 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2593 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2594 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2595 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2597 // move all effects to the correct producer
2598 mltPasteEffects(clip, cut);
2599 trackPlaylist.insert_at(startPos, cut, 1);
2602 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2603 newLength = trackPlaylist.clip_length(clipIndex);
2605 } else if (speed == 1.0 && strobe < 2) {
2608 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2609 trackPlaylist.consolidate_blanks(0);
2611 // Check that the blank space is long enough for our new duration
2612 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2613 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2616 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2617 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2618 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2619 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2620 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2622 // move all effects to the correct producer
2623 mltPasteEffects(clip, cut);
2625 trackPlaylist.insert_at(startPos, cut, 1);
2628 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2629 newLength = trackPlaylist.clip_length(clipIndex);
2632 } else if (serv == "framebuffer") {
2634 QString url = QString::fromUtf8(clipparent.get("resource"));
2635 url = url.section('?', 0, 0);
2636 url.append('?' + m_locale.toString(speed));
2637 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2638 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2639 if (!slowprod || slowprod->get_producer() == NULL) {
2640 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2641 slowprod->set("strobe", strobe);
2642 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2643 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2644 slowprod->set("id", producerid.toUtf8().constData());
2645 // copy producer props
2646 double ar = original->parent().get_double("force_aspect_ratio");
2647 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2648 double fps = original->parent().get_double("force_fps");
2649 if (fps != 0.0) slowprod->set("force_fps", fps);
2650 if (original->parent().get("force_progressive"))
2651 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2652 if (original->parent().get("force_tff"))
2653 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2654 int threads = original->parent().get_int("threads");
2655 if (threads != 0) slowprod->set("threads", threads);
2656 int ix = original->parent().get_int("video_index");
2657 if (ix != 0) slowprod->set("video_index", ix);
2658 int colorspace = original->parent().get_int("force_colorspace");
2659 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2660 int full_luma = original->parent().get_int("set.force_full_luma");
2661 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2662 m_slowmotionProducers.insert(url, slowprod);
2664 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2665 trackPlaylist.consolidate_blanks(0);
2667 GenTime duration = speedIndependantInfo.cropDuration / speed;
2668 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2670 // Check that the blank space is long enough for our new duration
2671 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2672 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2675 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2676 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2677 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2678 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2680 // move all effects to the correct producer
2681 mltPasteEffects(clip, cut);
2683 trackPlaylist.insert_at(startPos, cut, 1);
2686 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2687 newLength = trackPlaylist.clip_length(clipIndex);
2692 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2696 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2698 Mlt::Service service(m_mltProducer->parent().get_service());
2699 bool success = false;
2700 Mlt::Tractor tractor(service);
2701 Mlt::Producer trackProducer(tractor.track(track));
2702 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2703 Mlt::Service clipService(trackPlaylist.get_service());
2707 Mlt::Filter *filter = clipService.filter(ct);
2709 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2710 if (clipService.detach(*filter) == 0) success = true;
2711 } else if (updateIndex) {
2712 // Adjust the other effects index
2713 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2716 filter = clipService.filter(ct);
2723 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2725 if (position < GenTime()) {
2726 // Remove track effect
2727 return mltRemoveTrackEffect(track, index, updateIndex);
2729 Mlt::Service service(m_mltProducer->parent().get_service());
2730 bool success = false;
2731 Mlt::Tractor tractor(service);
2732 Mlt::Producer trackProducer(tractor.track(track));
2733 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2735 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2736 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2738 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2742 Mlt::Service clipService(clip->get_service());
2743 int duration = clip->get_playtime();
2745 // Check if clip is visible in monitor
2746 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2747 if (diff < 0 || diff > duration) doRefresh = false;
2753 Mlt::Filter *filter = clipService.filter(ct);
2755 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2756 if (clipService.detach(*filter) == 0) success = true;
2757 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2758 } else if (updateIndex) {
2759 // Adjust the other effects index
2760 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2763 filter = clipService.filter(ct);
2766 if (doRefresh) refresh();
2770 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2772 Mlt::Service service(m_mltProducer->parent().get_service());
2773 Mlt::Tractor tractor(service);
2774 Mlt::Producer trackProducer(tractor.track(track));
2775 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2776 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2777 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2781 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2784 Mlt::Service service(m_mltProducer->parent().get_service());
2786 Mlt::Tractor tractor(service);
2787 Mlt::Producer trackProducer(tractor.track(track));
2788 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2790 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2791 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2796 Mlt::Service clipService(clip->get_service());
2797 int duration = clip->get_playtime();
2799 // Check if clip is visible in monitor
2800 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2801 if (diff < 0 || diff > duration) doRefresh = false;
2804 return mltAddEffect(clipService, params, duration, doRefresh);
2807 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2809 bool updateIndex = false;
2810 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2814 Mlt::Filter *filter = service.filter(ct);
2816 if (filter->get_int("kdenlive_ix") == filter_ix) {
2817 // A filter at that position already existed, so we will increase all indexes later
2822 filter = service.filter(ct);
2825 if (params.paramValue("id") == "speed") {
2826 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2828 filter = service.filter(ct);
2830 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2831 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2834 filter = service.filter(ct);
2837 if (doRefresh) refresh();
2842 // temporarily remove all effects after insert point
2843 QList <Mlt::Filter *> filtersList;
2845 filter = service.filter(ct);
2847 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2848 filtersList.append(filter);
2849 service.detach(*filter);
2851 filter = service.filter(ct);
2854 addFilterToService(service, params, duration);
2856 // re-add following filters
2857 for (int i = 0; i < filtersList.count(); i++) {
2858 Mlt::Filter *filter = filtersList.at(i);
2860 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2861 service.attach(*filter);
2864 if (doRefresh) refresh();
2869 bool Render::addFilterToService(Mlt::Service service, EffectsParameterList params, int duration)
2872 QString tag = params.paramValue("tag");
2873 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2874 char *filterTag = qstrdup(tag.toUtf8().constData());
2875 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2876 QString kfr = params.paramValue("keyframes");
2877 if (!kfr.isEmpty()) {
2878 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2879 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2880 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2881 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2882 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2883 //double max = params.paramValue("max").toDouble();
2884 double min = params.paramValue("min").toDouble();
2885 double factor = params.paramValue("factor", "1").toDouble();
2886 double paramOffset = params.paramValue("offset", "0").toDouble();
2887 params.removeParam("starttag");
2888 params.removeParam("endtag");
2889 params.removeParam("keyframes");
2890 params.removeParam("min");
2891 params.removeParam("max");
2892 params.removeParam("factor");
2893 params.removeParam("offset");
2895 // Special case, only one keyframe, means we want a constant value
2896 if (keyFrames.count() == 1) {
2897 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2898 if (filter && filter->is_valid()) {
2899 filter->set("kdenlive_id", filterId);
2900 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2901 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2902 for (int j = 0; j < params.count(); j++) {
2903 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2905 filter->set("in", x1);
2906 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2907 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2908 service.attach(*filter);
2910 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2911 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2912 if (filter && filter->is_valid()) {
2913 filter->set("kdenlive_id", filterId);
2914 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2915 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2916 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2917 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2918 if (x2 == -1) x2 = duration;
2920 for (int j = 0; j < params.count(); j++) {
2921 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2924 filter->set("in", x1);
2925 filter->set("out", x2);
2926 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2927 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2928 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2929 service.attach(*filter);
2936 Mlt::Filter *filter;
2938 filter = new Mlt::Filter(*m_mltProfile, filterTag);
2939 if (filter && filter->is_valid()) {
2940 filter->set("kdenlive_id", filterId);
2942 kDebug() << "filter is NULL";
2946 params.removeParam("kdenlive_id");
2947 if (params.hasParam("_sync_in_out")) {
2948 // This effect must sync in / out with parent clip
2949 params.removeParam("_sync_in_out");
2950 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2953 for (int j = 0; j < params.count(); j++) {
2954 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2958 QString effectArgs = params.paramValue("id").section('_', 1);
2960 params.removeParam("id");
2961 params.removeParam("kdenlive_ix");
2962 params.removeParam("tag");
2963 params.removeParam("disable");
2964 params.removeParam("region");
2966 for (int j = 0; j < params.count(); j++) {
2967 effectArgs.append(' ' + params.at(j).value());
2969 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2970 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2972 // attach filter to the clip
2973 service.attach(*filter);
2981 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2983 Mlt::Service service(m_mltProducer->parent().get_service());
2984 Mlt::Tractor tractor(service);
2985 Mlt::Producer trackProducer(tractor.track(track));
2986 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2987 Mlt::Service clipService(trackPlaylist.get_service());
2989 QString index = params.paramValue("kdenlive_ix");
2990 QString tag = params.paramValue("tag");
2992 Mlt::Filter *filter = clipService.filter(ct);
2994 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2998 filter = clipService.filter(ct);
3002 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
3003 // filter was not found, it was probably a disabled filter, so add it to the correct place...
3005 bool success = false;//mltAddTrackEffect(track, params);
3009 QString ser = filter->get("mlt_service");
3010 if (ser == "region") prefix = "filter0.";
3012 for (int j = 0; j < params.count(); j++) {
3013 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
3021 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
3023 int index = params.paramValue("kdenlive_ix").toInt();
3024 QString tag = params.paramValue("tag");
3026 if (!params.paramValue("keyframes").isEmpty() || (tag == "affine" && params.hasParam("background")) || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
3027 // This is a keyframe effect, to edit it, we remove it and re-add it.
3028 bool success = mltRemoveEffect(track, position, index, false);
3029 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
3030 if (position < GenTime())
3031 success = mltAddTrackEffect(track, params);
3033 success = mltAddEffect(track, position, params);
3034 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
3037 if (position < GenTime()) {
3038 return mltEditTrackEffect(track, params);
3041 Mlt::Service service(m_mltProducer->parent().get_service());
3042 Mlt::Tractor tractor(service);
3043 Mlt::Producer trackProducer(tractor.track(track));
3044 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3046 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3047 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3049 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3053 int duration = clip->get_playtime();
3054 bool doRefresh = true;
3055 // Check if clip is visible in monitor
3056 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3057 if (diff < 0 || diff > duration)
3061 Mlt::Filter *filter = clip->filter(ct);
3063 if (filter->get_int("kdenlive_ix") == index) {
3067 filter = clip->filter(ct);
3071 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
3072 // filter was not found, it was probably a disabled filter, so add it to the correct place...
3074 bool success = mltAddEffect(track, position, params);
3078 QString ser = filter->get("mlt_service");
3079 QList <Mlt::Filter *> filtersList;
3082 // Effect service changes, delete effect and re-add it
3083 clip->detach(*filter);
3085 // Delete all effects after deleted one
3086 filter = clip->filter(ct);
3088 if (filter->get_int("kdenlive_ix") > index) {
3089 filtersList.append(filter);
3090 clip->detach(*filter);
3093 filter = clip->filter(ct);
3097 addFilterToService(*clip, params, clip->get_playtime());
3101 if (doRefresh) refresh();
3104 if (params.hasParam("_sync_in_out")) {
3105 // This effect must sync in / out with parent clip
3106 params.removeParam("_sync_in_out");
3107 filter->set_in_and_out(clip->get_in(), clip->get_out());
3110 for (int j = 0; j < params.count(); j++) {
3111 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
3114 for (int j = 0; j < filtersList.count(); j++) {
3115 clip->attach(*(filtersList.at(j)));
3121 if (doRefresh) refresh();
3125 bool Render::mltEnableEffects(int track, GenTime position, QList <int> effectIndexes, bool disable)
3127 if (position < GenTime()) {
3128 return mltEnableTrackEffects(track, effectIndexes, disable);
3131 Mlt::Service service(m_mltProducer->parent().get_service());
3132 Mlt::Tractor tractor(service);
3133 Mlt::Producer trackProducer(tractor.track(track));
3134 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3136 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3137 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3139 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3143 int duration = clip->get_playtime();
3144 bool doRefresh = true;
3145 // Check if clip is visible in monitor
3146 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3147 if (diff < 0 || diff > duration)
3151 Mlt::Filter *filter = clip->filter(ct);
3153 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3154 filter->set("disable", (int) disable);
3157 filter = clip->filter(ct);
3163 if (doRefresh) refresh();
3167 bool Render::mltEnableTrackEffects(int track, QList <int> effectIndexes, bool disable)
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());
3173 Mlt::Service clipService(trackPlaylist.get_service());
3176 Mlt::Filter *filter = clipService.filter(ct);
3178 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3179 filter->set("disable", (int) disable);
3182 filter = clipService.filter(ct);
3190 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
3192 Mlt::Service service(m_mltProducer->parent().get_service());
3193 Mlt::Tractor tractor(service);
3194 Mlt::Producer trackProducer(tractor.track(track));
3195 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3197 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3198 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3200 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3204 Mlt::Service clipService(clip->get_service());
3205 int duration = clip->get_playtime();
3206 bool doRefresh = true;
3207 // Check if clip is visible in monitor
3208 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3209 if (diff < 0 || diff > duration) doRefresh = false;
3213 Mlt::Filter *filter = clipService.filter(ct);
3215 int pos = filter->get_int("kdenlive_ix");
3216 if (pos == oldPos) {
3217 filter->set("kdenlive_ix", newPos);
3219 filter = clipService.filter(ct);
3221 if (doRefresh) refresh();
3224 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
3226 if (position < GenTime()) {
3227 mltMoveTrackEffect(track, oldPos, newPos);
3230 Mlt::Service service(m_mltProducer->parent().get_service());
3231 Mlt::Tractor tractor(service);
3232 Mlt::Producer trackProducer(tractor.track(track));
3233 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3235 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3236 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3238 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3242 Mlt::Service clipService(clip->get_service());
3243 int duration = clip->get_playtime();
3244 bool doRefresh = true;
3245 // Check if clip is visible in monitor
3246 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3247 if (diff < 0 || diff > duration) doRefresh = false;
3251 QList <Mlt::Filter *> filtersList;
3252 Mlt::Filter *filter = clipService.filter(ct);
3254 if (newPos > oldPos) {
3256 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3257 filter->set("kdenlive_ix", newPos);
3258 filtersList.append(filter);
3259 clipService.detach(*filter);
3260 filter = clipService.filter(ct);
3261 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3262 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3264 filter = clipService.filter(ct);
3268 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3269 filtersList.append(filter);
3270 clipService.detach(*filter);
3272 filter = clipService.filter(ct);
3276 if (filter->get_int("kdenlive_ix") == oldPos) {
3277 filter->set("kdenlive_ix", newPos);
3278 filtersList.append(filter);
3279 clipService.detach(*filter);
3281 filter = clipService.filter(ct);
3285 filter = clipService.filter(ct);
3287 int pos = filter->get_int("kdenlive_ix");
3288 if (pos >= newPos) {
3289 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3290 filtersList.append(filter);
3291 clipService.detach(*filter);
3293 filter = clipService.filter(ct);
3297 for (int i = 0; i < filtersList.count(); i++) {
3298 clipService.attach(*(filtersList.at(i)));
3301 if (doRefresh) refresh();
3304 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
3306 Mlt::Service service(m_mltProducer->parent().get_service());
3307 Mlt::Tractor tractor(service);
3308 Mlt::Producer trackProducer(tractor.track(track));
3309 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3310 Mlt::Service clipService(trackPlaylist.get_service());
3312 QList <Mlt::Filter *> filtersList;
3313 Mlt::Filter *filter = clipService.filter(ct);
3315 if (newPos > oldPos) {
3317 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3318 filter->set("kdenlive_ix", newPos);
3319 filtersList.append(filter);
3320 clipService.detach(*filter);
3321 filter = clipService.filter(ct);
3322 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3323 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3325 filter = clipService.filter(ct);
3329 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3330 filtersList.append(filter);
3331 clipService.detach(*filter);
3333 filter = clipService.filter(ct);
3337 if (filter->get_int("kdenlive_ix") == oldPos) {
3338 filter->set("kdenlive_ix", newPos);
3339 filtersList.append(filter);
3340 clipService.detach(*filter);
3342 filter = clipService.filter(ct);
3346 filter = clipService.filter(ct);
3348 int pos = filter->get_int("kdenlive_ix");
3349 if (pos >= newPos) {
3350 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3351 filtersList.append(filter);
3352 clipService.detach(*filter);
3354 filter = clipService.filter(ct);
3358 for (int i = 0; i < filtersList.count(); i++) {
3359 clipService.attach(*(filtersList.at(i)));
3364 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration, bool refresh)
3366 Mlt::Service service(m_mltProducer->parent().get_service());
3367 Mlt::Tractor tractor(service);
3368 Mlt::Producer trackProducer(tractor.track(info.track));
3369 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3371 /* // Display playlist info
3372 kDebug()<<"//////////// BEFORE RESIZE";
3373 for (int i = 0; i < trackPlaylist.count(); i++) {
3374 int blankStart = trackPlaylist.clip_start(i);
3375 int blankDuration = trackPlaylist.clip_length(i) - 1;
3377 if (trackPlaylist.is_blank(i)) blk = "(blank)";
3378 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
3381 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
3382 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3386 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
3387 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
3388 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3390 int previousStart = clip->get_in();
3391 int newDuration = (int) clipDuration.frames(m_fps) - 1;
3392 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
3394 int currentOut = newDuration + previousStart;
3395 if (currentOut > clip->get_length()) {
3396 clip->parent().set("length", currentOut + 1);
3397 clip->parent().set("out", currentOut);
3398 clip->set("length", currentOut + 1);
3401 /*if (newDuration > clip->get_out()) {
3402 clip->parent().set_in_and_out(0, newDuration + 1);
3403 clip->set_in_and_out(0, newDuration + 1);
3406 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
3407 trackPlaylist.consolidate_blanks(0);
3408 // skip to next clip
3410 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
3412 // clip was made longer, trim next blank if there is one.
3413 if (clipIndex < trackPlaylist.count()) {
3414 // If this is not the last clip in playlist
3415 if (trackPlaylist.is_blank(clipIndex)) {
3416 int blankStart = trackPlaylist.clip_start(clipIndex);
3417 int blankDuration = trackPlaylist.clip_length(clipIndex);
3418 if (diff > blankDuration) {
3419 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
3421 if (diff - blankDuration == 0) {
3422 trackPlaylist.remove(clipIndex);
3423 } else trackPlaylist.remove_region(blankStart, diff);
3425 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
3428 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
3429 trackPlaylist.consolidate_blanks(0);
3432 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
3433 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3434 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
3435 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3436 ItemInfo transpinfo;
3437 transpinfo.startPos = info.startPos;
3438 transpinfo.endPos = info.startPos + clipDuration;
3439 transpinfo.track = info.track;
3440 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3442 if (refresh) m_mltConsumer->set("refresh", 1);
3446 void Render::mltChangeTrackState(int track, bool mute, bool blind)
3448 Mlt::Service service(m_mltProducer->parent().get_service());
3449 Mlt::Tractor tractor(service);
3450 Mlt::Producer trackProducer(tractor.track(track));
3452 // Make sure muting will not produce problems with our audio mixing transition,
3453 // because audio mixing is done between each track and the lowest one
3454 bool audioMixingBroken = false;
3455 if (mute && trackProducer.get_int("hide") < 2 ) {
3456 // We mute a track with sound
3457 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3458 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
3460 else if (!mute && trackProducer.get_int("hide") > 1 ) {
3461 // We un-mute a previously muted track
3462 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3466 if (blind) trackProducer.set("hide", 3);
3467 else trackProducer.set("hide", 2);
3469 trackProducer.set("hide", 1);
3471 trackProducer.set("hide", 0);
3473 if (audioMixingBroken) fixAudioMixing(tractor);
3475 tractor.multitrack()->refresh();
3480 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
3482 for (int i = 1; i < tractor.count(); i++) {
3483 Mlt::Producer trackProducer(tractor.track(i));
3484 if (trackProducer.get_int("hide") < 2) return i;
3486 return tractor.count() - 1;
3489 void Render::fixAudioMixing(Mlt::Tractor tractor)
3491 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
3492 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
3494 mlt_service serv = m_mltProducer->parent().get_service();
3495 Mlt::Field *field = tractor.field();
3496 mlt_service_lock(serv);
3498 mlt_service nextservice = mlt_service_get_producer(serv);
3499 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3500 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3501 QString resource = mlt_properties_get(properties, "mlt_service");
3503 mlt_service nextservicetodisconnect;
3504 // Delete all audio mixing transitions
3505 while (mlt_type == "transition") {
3506 if (resource == "mix") {
3507 nextservicetodisconnect = nextservice;
3508 nextservice = mlt_service_producer(nextservice);
3509 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
3511 else nextservice = mlt_service_producer(nextservice);
3512 if (nextservice == NULL) break;
3513 properties = MLT_SERVICE_PROPERTIES(nextservice);
3514 mlt_type = mlt_properties_get(properties, "mlt_type");
3515 resource = mlt_properties_get(properties, "mlt_service");
3518 // Re-add correct audio transitions
3519 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
3520 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3521 transition->set("always_active", 1);
3522 transition->set("combine", 1);
3523 transition->set("internal_added", 237);
3524 field->plant_transition(*transition, lowestTrack, i);
3526 mlt_service_unlock(serv);
3529 bool Render::mltResizeClipCrop(ItemInfo info, GenTime newCropStart)
3531 Mlt::Service service(m_mltProducer->parent().get_service());
3532 int newCropFrame = (int) newCropStart.frames(m_fps);
3533 Mlt::Tractor tractor(service);
3534 Mlt::Producer trackProducer(tractor.track(info.track));
3535 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3536 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3537 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3541 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3542 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3544 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3548 int previousStart = clip->get_in();
3549 int previousOut = clip->get_out();
3551 if (previousStart == newCropFrame) {
3552 kDebug() << "//////// No ReSIZING Required";
3556 int frameOffset = newCropFrame - previousStart;
3557 trackPlaylist.resize_clip(clipIndex, newCropFrame, previousOut + frameOffset);
3559 m_mltConsumer->set("refresh", 1);
3563 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3565 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3566 Mlt::Service service(m_mltProducer->parent().get_service());
3567 int moveFrame = (int) diff.frames(m_fps);
3568 Mlt::Tractor tractor(service);
3569 Mlt::Producer trackProducer(tractor.track(info.track));
3570 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3571 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3572 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3576 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3577 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3578 if (clip == NULL || clip->is_blank()) {
3579 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3583 int previousStart = clip->get_in();
3584 int previousOut = clip->get_out();
3586 previousStart += moveFrame;
3588 if (previousStart < 0) {
3589 // this is possible for images and color clips
3590 previousOut -= previousStart;
3594 int length = previousOut + 1;
3595 if (length > clip->get_length()) {
3596 clip->parent().set("length", length + 1);
3597 clip->parent().set("out", length);
3598 clip->set("length", length + 1);
3602 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3603 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3604 if (moveFrame > 0) {
3605 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3607 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3608 int blankIndex = clipIndex - 1;
3609 int blankLength = trackPlaylist.clip_length(blankIndex);
3610 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3611 if (! trackPlaylist.is_blank(blankIndex)) {
3612 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3614 if (blankLength + moveFrame == 0)
3615 trackPlaylist.remove(blankIndex);
3617 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3619 trackPlaylist.consolidate_blanks(0);
3620 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3621 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3622 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3623 ItemInfo transpinfo;
3624 transpinfo.startPos = info.startPos + diff;
3625 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3626 transpinfo.track = info.track;
3627 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3629 //m_mltConsumer->set("refresh", 1);
3631 m_mltConsumer->set("refresh", 1);
3635 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3637 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3641 bool Render::mltUpdateClipProducer(Mlt::Tractor *tractor, int track, int pos, Mlt::Producer *prod)
3643 if (prod == NULL || !prod->is_valid() || tractor == NULL || !tractor->is_valid()) {
3644 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3648 Mlt::Producer trackProducer(tractor->track(track));
3649 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3650 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3651 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3652 if (clipProducer == NULL || clipProducer->is_blank()) {
3653 kDebug() << "// ERROR UPDATING CLIP PROD";
3654 delete clipProducer;
3657 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3658 if (!clip || !clip->is_valid()) {
3659 if (clip) delete clip;
3660 delete clipProducer;
3663 // move all effects to the correct producer
3664 mltPasteEffects(clipProducer, clip);
3665 trackPlaylist.insert_at(pos, clip, 1);
3667 delete clipProducer;
3671 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3673 Mlt::Service service(m_mltProducer->parent().get_service());
3674 if (service.type() != tractor_type) {
3675 kWarning() << "// TRACTOR PROBLEM";
3679 Mlt::Tractor tractor(service);
3681 Mlt::Producer trackProducer(tractor.track(startTrack));
3682 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3683 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3684 int clipDuration = trackPlaylist.clip_length(clipIndex);
3685 bool checkLength = false;
3686 if (endTrack == startTrack) {
3687 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3689 bool success = true;
3690 if (!trackPlaylist.is_blank_at(moveEnd) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3694 // Check that the destination region is empty
3695 trackPlaylist.consolidate_blanks(0);
3696 int destinationIndex = trackPlaylist.get_clip_index_at(moveEnd);
3697 if (destinationIndex < trackPlaylist.count() - 1) {
3698 // We are not at the end of the track
3699 int blankSize = trackPlaylist.blanks_from(destinationIndex, 1);
3700 // Make sure we have enough place to insert clip
3701 if (blankSize - clipDuration - (moveEnd - trackPlaylist.clip_start(destinationIndex)) < 0) success = false;
3706 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3707 delete clipProducer;
3709 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3716 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3717 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3718 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3720 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3721 if (newIndex == -1) {
3722 kDebug()<<"// CANNOT MOVE CLIP TO: "<<moveEnd;
3723 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3724 delete clipProducer;
3728 trackPlaylist.consolidate_blanks(1);
3729 delete clipProducer;
3730 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3732 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3733 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3734 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3735 // error, destination is not empty
3736 kDebug() << "Cannot move: Destination is not empty";
3740 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3741 if (!clipProducer || clipProducer->is_blank()) {
3742 // error, destination is not empty
3743 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3744 if (clipProducer) delete clipProducer;
3745 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3749 trackPlaylist.consolidate_blanks(0);
3750 destTrackPlaylist.consolidate_blanks(1);
3751 Mlt::Producer *clip;
3752 // check if we are moving a slowmotion producer
3753 QString serv = clipProducer->parent().get("mlt_service");
3754 QString currentid = clipProducer->parent().get("id");
3755 if (serv == "framebuffer") {
3756 clip = clipProducer;
3759 // Special case: prod is null when using placeholder clips.
3760 // in that case, use the producer existing in playlist. Note that
3761 // it will bypass the one producer per track logic and might cause
3762 // Sound cracks if clip is moved so that it overlaps another copy of itself
3763 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3764 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3767 // move all effects to the correct producer
3768 mltPasteEffects(clipProducer, clip);
3771 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3772 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3773 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3776 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3778 if (clip == clipProducer) {
3783 delete clipProducer;
3785 destTrackPlaylist.consolidate_blanks(0);
3786 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3787 kDebug() << "//////// moving clip transparency";
3788 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3790 if (clipIndex > trackPlaylist.count()) checkLength = true;
3791 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3795 if (checkLength) mltCheckLength(&tractor);
3797 //m_mltConsumer->set("refresh", 1);
3802 QList <int> Render::checkTrackSequence(int track)
3805 Mlt::Service service(m_mltProducer->parent().get_service());
3806 if (service.type() != tractor_type) {
3807 kWarning() << "// TRACTOR PROBLEM";
3810 Mlt::Tractor tractor(service);
3812 Mlt::Producer trackProducer(tractor.track(track));
3813 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3814 int clipNb = trackPlaylist.count();
3815 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3816 for (int i = 0; i < clipNb; i++) {
3817 Mlt::Producer *c = trackPlaylist.get_clip(i);
3818 int pos = trackPlaylist.clip_start(i);
3819 if (!list.contains(pos)) list.append(pos);
3820 pos += c->get_playtime();
3821 if (!list.contains(pos)) list.append(pos);
3827 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3829 int new_in = (int)newIn.frames(m_fps);
3830 int new_out = (int)newOut.frames(m_fps) - 1;
3831 if (new_in >= new_out) return false;
3832 int old_in = (int)oldIn.frames(m_fps);
3833 int old_out = (int)oldOut.frames(m_fps) - 1;
3835 Mlt::Service service(m_mltProducer->parent().get_service());
3836 Mlt::Tractor tractor(service);
3837 Mlt::Field *field = tractor.field();
3839 bool doRefresh = true;
3840 // Check if clip is visible in monitor
3841 int diff = old_out - m_mltProducer->position();
3842 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3844 diff = new_out - m_mltProducer->position();
3845 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3849 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3850 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3851 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3852 QString resource = mlt_properties_get(properties, "mlt_service");
3853 int old_pos = (int)(old_in + old_out) / 2;
3856 while (mlt_type == "transition") {
3857 Mlt::Transition transition((mlt_transition) nextservice);
3858 nextservice = mlt_service_producer(nextservice);
3859 int currentTrack = transition.get_b_track();
3860 int currentIn = (int) transition.get_in();
3861 int currentOut = (int) transition.get_out();
3863 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3865 if (newTrack - startTrack != 0) {
3866 Mlt::Properties trans_props(transition.get_properties());
3867 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3868 Mlt::Properties new_trans_props(new_transition.get_properties());
3869 new_trans_props.inherit(trans_props);
3870 new_transition.set_in_and_out(new_in, new_out);
3871 field->disconnect_service(transition);
3872 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3873 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3874 } else transition.set_in_and_out(new_in, new_out);
3877 if (nextservice == NULL) break;
3878 properties = MLT_SERVICE_PROPERTIES(nextservice);
3879 mlt_type = mlt_properties_get(properties, "mlt_type");
3880 resource = mlt_properties_get(properties, "mlt_service");
3883 if (doRefresh) refresh();
3884 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3889 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3891 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3892 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3893 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3894 QString resource = mlt_properties_get(properties, "mlt_service");
3895 QList <Mlt::Transition *> trList;
3896 mlt_properties insertproperties = tr.get_properties();
3897 QString insertresource = mlt_properties_get(insertproperties, "mlt_service");
3898 bool isMixTransition = insertresource == "mix";
3900 while (mlt_type == "transition") {
3901 Mlt::Transition transition((mlt_transition) nextservice);
3902 nextservice = mlt_service_producer(nextservice);
3903 int aTrack = transition.get_a_track();
3904 int bTrack = transition.get_b_track();
3905 if ((isMixTransition || resource != "mix") && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3906 Mlt::Properties trans_props(transition.get_properties());
3907 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3908 Mlt::Properties new_trans_props(cp->get_properties());
3909 new_trans_props.inherit(trans_props);
3911 field->disconnect_service(transition);
3913 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3915 if (nextservice == NULL) break;
3916 properties = MLT_SERVICE_PROPERTIES(nextservice);
3917 mlt_type = mlt_properties_get(properties, "mlt_type");
3918 resource = mlt_properties_get(properties, "mlt_service");
3920 field->plant_transition(tr, a_track, b_track);
3922 // re-add upper transitions
3923 for (int i = trList.count() - 1; i >= 0; i--) {
3924 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3925 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3930 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3932 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3934 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3935 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3936 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3939 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3942 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3944 mlt_service serv = m_mltProducer->parent().get_service();
3945 mlt_service_lock(serv);
3947 mlt_service nextservice = mlt_service_get_producer(serv);
3948 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3949 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3950 QString resource = mlt_properties_get(properties, "mlt_service");
3951 int in_pos = (int) in.frames(m_fps);
3952 int out_pos = (int) out.frames(m_fps) - 1;
3954 while (mlt_type == "transition") {
3955 mlt_transition tr = (mlt_transition) nextservice;
3956 int currentTrack = mlt_transition_get_b_track(tr);
3957 int currentBTrack = mlt_transition_get_a_track(tr);
3958 int currentIn = (int) mlt_transition_get_in(tr);
3959 int currentOut = (int) mlt_transition_get_out(tr);
3961 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3962 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3963 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3964 QMap<QString, QString>::Iterator it;
3966 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3968 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3969 if (currentId != xml.attribute("id")) {
3970 // The transition ID is not the same, so reset all properties
3971 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3972 // Cleanup previous properties
3973 QStringList permanentProps;
3974 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3975 permanentProps << "out" << "a_track" << "b_track";
3976 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3977 QString propName = mlt_properties_get_name(transproperties, i);
3978 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3979 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3984 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3985 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3987 if (currentBTrack != a_track) {
3988 mlt_properties_set_int(transproperties, "a_track", a_track);
3990 for (it = map.begin(); it != map.end(); ++it) {
3992 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3993 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3994 //filter->set("kdenlive_id", id);
3998 nextservice = mlt_service_producer(nextservice);
3999 if (nextservice == NULL) break;
4000 properties = MLT_SERVICE_PROPERTIES(nextservice);
4001 mlt_type = mlt_properties_get(properties, "mlt_type");
4002 resource = mlt_properties_get(properties, "mlt_service");
4004 mlt_service_unlock(serv);
4006 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
4009 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
4011 mlt_service serv = m_mltProducer->parent().get_service();
4012 mlt_service_lock(serv);
4014 Mlt::Service service(serv);
4015 Mlt::Tractor tractor(service);
4016 Mlt::Field *field = tractor.field();
4018 //if (do_refresh) m_mltConsumer->set("refresh", 0);
4020 mlt_service nextservice = mlt_service_get_producer(serv);
4021 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4022 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4023 QString resource = mlt_properties_get(properties, "mlt_service");
4025 const int old_pos = (int)((in + out).frames(m_fps) / 2);
4026 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
4028 while (mlt_type == "transition") {
4029 mlt_transition tr = (mlt_transition) nextservice;
4030 int currentTrack = mlt_transition_get_b_track(tr);
4031 int currentIn = (int) mlt_transition_get_in(tr);
4032 int currentOut = (int) mlt_transition_get_out(tr);
4033 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
4035 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
4036 mlt_field_disconnect_service(field->get_field(), nextservice);
4039 nextservice = mlt_service_producer(nextservice);
4040 if (nextservice == NULL) break;
4041 properties = MLT_SERVICE_PROPERTIES(nextservice);
4042 mlt_type = mlt_properties_get(properties, "mlt_type");
4043 resource = mlt_properties_get(properties, "mlt_service");
4045 mlt_service_unlock(serv);
4047 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
4050 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
4052 QDomNodeList attribs = xml.elementsByTagName("parameter");
4053 QMap<QString, QString> map;
4054 for (int i = 0; i < attribs.count(); i++) {
4055 QDomElement e = attribs.item(i).toElement();
4056 QString name = e.attribute("name");
4057 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
4058 map[name] = e.attribute("default");
4059 if (!e.attribute("value").isEmpty()) {
4060 map[name] = e.attribute("value");
4062 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
4063 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
4064 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
4067 if (e.attribute("namedesc").contains(';')) {
4068 QString format = e.attribute("format");
4069 QStringList separators = format.split("%d", QString::SkipEmptyParts);
4070 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
4072 QTextStream txtNeu(&neu);
4073 if (values.size() > 0)
4074 txtNeu << (int)values[0].toDouble();
4076 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
4077 txtNeu << separators[i];
4078 txtNeu << (int)(values[i+1].toDouble());
4080 if (i < separators.size())
4081 txtNeu << separators[i];
4082 map[e.attribute("name")] = neu;
4089 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
4091 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
4092 Mlt::Service service(m_mltProducer->parent().get_service());
4093 Mlt::Tractor tractor(service);
4094 Mlt::Field *field = tractor.field();
4096 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
4097 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
4098 transition->set("transparency", id);
4099 transition->set("fill", 1);
4100 transition->set("internal_added", 237);
4101 field->plant_transition(*transition, transitiontrack, info.track);
4105 void Render::mltDeleteTransparency(int pos, int track, int id)
4107 Mlt::Service service(m_mltProducer->parent().get_service());
4108 Mlt::Tractor tractor(service);
4109 Mlt::Field *field = tractor.field();
4111 //if (do_refresh) m_mltConsumer->set("refresh", 0);
4112 mlt_service serv = m_mltProducer->parent().get_service();
4114 mlt_service nextservice = mlt_service_get_producer(serv);
4115 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4116 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4117 QString resource = mlt_properties_get(properties, "mlt_service");
4119 while (mlt_type == "transition") {
4120 mlt_transition tr = (mlt_transition) nextservice;
4121 int currentTrack = mlt_transition_get_b_track(tr);
4122 int currentIn = (int) mlt_transition_get_in(tr);
4123 int currentOut = (int) mlt_transition_get_out(tr);
4124 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4125 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
4127 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
4128 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
4129 mlt_field_disconnect_service(field->get_field(), nextservice);
4132 nextservice = mlt_service_producer(nextservice);
4133 if (nextservice == NULL) break;
4134 properties = MLT_SERVICE_PROPERTIES(nextservice);
4135 mlt_type = mlt_properties_get(properties, "mlt_type");
4136 resource = mlt_properties_get(properties, "mlt_service");
4138 //if (do_refresh) m_mltConsumer->set("refresh", 1);
4141 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
4143 Mlt::Service service(m_mltProducer->parent().get_service());
4144 Mlt::Tractor tractor(service);
4147 m_mltConsumer->set("refresh", 0);
4149 mlt_service serv = m_mltProducer->parent().get_service();
4150 mlt_service nextservice = mlt_service_get_producer(serv);
4151 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4152 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4153 QString resource = mlt_properties_get(properties, "mlt_service");
4154 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
4155 while (mlt_type == "transition") {
4156 mlt_transition tr = (mlt_transition) nextservice;
4157 int currentTrack = mlt_transition_get_b_track(tr);
4158 int currentIn = (int) mlt_transition_get_in(tr);
4159 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
4160 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4161 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
4162 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
4163 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
4164 mlt_transition_set_in_and_out(tr, newStart, newEnd);
4167 nextservice = mlt_service_producer(nextservice);
4168 if (nextservice == NULL) break;
4169 properties = MLT_SERVICE_PROPERTIES(nextservice);
4170 mlt_type = mlt_properties_get(properties, "mlt_type");
4171 resource = mlt_properties_get(properties, "mlt_service");
4174 m_mltConsumer->set("refresh", 1);
4178 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
4180 Mlt::Service service(m_mltProducer->parent().get_service());
4181 Mlt::Tractor tractor(service);
4184 m_mltConsumer->set("refresh", 0);
4186 mlt_service serv = m_mltProducer->parent().get_service();
4187 mlt_service nextservice = mlt_service_get_producer(serv);
4188 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4189 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4190 QString resource = mlt_properties_get(properties, "mlt_service");
4192 while (mlt_type == "transition") {
4193 mlt_transition tr = (mlt_transition) nextservice;
4194 int currentTrack = mlt_transition_get_b_track(tr);
4195 int currentaTrack = mlt_transition_get_a_track(tr);
4196 int currentIn = (int) mlt_transition_get_in(tr);
4197 int currentOut = (int) mlt_transition_get_out(tr);
4198 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4199 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4200 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
4201 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
4202 kDebug() << "//////MOVING";
4203 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
4204 if (endTrack != startTrack) {
4205 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4206 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
4207 mlt_properties_set_int(properties, "b_track", endTrack);
4211 nextservice = mlt_service_producer(nextservice);
4212 if (nextservice == NULL) break;
4213 properties = MLT_SERVICE_PROPERTIES(nextservice);
4214 mlt_type = mlt_properties_get(properties, "mlt_type");
4215 resource = mlt_properties_get(properties, "mlt_service");
4218 m_mltConsumer->set("refresh", 1);
4222 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
4224 if (in >= out) return false;
4225 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
4226 Mlt::Service service(m_mltProducer->parent().get_service());
4228 Mlt::Tractor tractor(service);
4229 Mlt::Field *field = tractor.field();
4231 Mlt::Transition transition(*m_mltProfile, tag.toUtf8().constData());
4232 if (out != GenTime())
4233 transition.set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
4235 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
4236 QMap<QString, QString>::Iterator it;
4238 if (xml.attribute("automatic") == "1") transition.set("automatic", 1);
4239 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
4240 if (xml.hasAttribute("id"))
4241 transition.set("kdenlive_id", xml.attribute("id").toUtf8().constData());
4242 if (xml.hasAttribute("force_track"))
4243 transition.set("force_track", xml.attribute("force_track").toInt());
4245 for (it = args.begin(); it != args.end(); ++it) {
4247 if (!it.value().isEmpty())
4248 transition.set(key.toUtf8().constData(), it.value().toUtf8().constData());
4249 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
4251 // attach transition
4253 mltPlantTransition(field, transition, a_track, b_track);
4254 // field->plant_transition(*transition, a_track, b_track);
4256 if (do_refresh) refresh();
4260 void Render::mltSavePlaylist()
4262 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
4263 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
4264 fileConsumer.set("resource", "/tmp/playlist.mlt");
4266 Mlt::Service service(m_mltProducer->get_service());
4268 fileConsumer.connect(service);
4269 fileConsumer.start();
4272 const QList <Mlt::Producer *> Render::producersList()
4274 QList <Mlt::Producer *> prods;
4275 if (m_mltProducer == NULL) return prods;
4276 Mlt::Service service(m_mltProducer->parent().get_service());
4277 if (service.type() != tractor_type) return prods;
4278 Mlt::Tractor tractor(service);
4281 int trackNb = tractor.count();
4282 for (int t = 1; t < trackNb; t++) {
4283 Mlt::Producer *tt = tractor.track(t);
4284 Mlt::Producer trackProducer(tt);
4286 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4287 if (!trackPlaylist.is_valid()) continue;
4288 int clipNb = trackPlaylist.count();
4289 for (int i = 0; i < clipNb; i++) {
4290 Mlt::Producer *c = trackPlaylist.get_clip(i);
4291 if (c == NULL) continue;
4292 QString prodId = c->parent().get("id");
4293 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
4294 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4297 prods.append(nprod);
4306 void Render::fillSlowMotionProducers()
4308 if (m_mltProducer == NULL) return;
4309 Mlt::Service service(m_mltProducer->parent().get_service());
4310 if (service.type() != tractor_type) return;
4312 Mlt::Tractor tractor(service);
4314 int trackNb = tractor.count();
4315 for (int t = 1; t < trackNb; t++) {
4316 Mlt::Producer *tt = tractor.track(t);
4317 Mlt::Producer trackProducer(tt);
4319 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4320 if (!trackPlaylist.is_valid()) continue;
4321 int clipNb = trackPlaylist.count();
4322 for (int i = 0; i < clipNb; i++) {
4323 Mlt::Producer *c = trackPlaylist.get_clip(i);
4324 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4326 QString id = nprod->parent().get("id");
4327 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
4328 // this is a slowmotion producer, add it to the list
4329 QString url = QString::fromUtf8(nprod->get("resource"));
4330 int strobe = nprod->get_int("strobe");
4331 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
4332 if (!m_slowmotionProducers.contains(url)) {
4333 m_slowmotionProducers.insert(url, nprod);
4335 } else delete nprod;
4342 QList <TransitionInfo> Render::mltInsertTrack(int ix, bool videoTrack)
4344 Mlt::Service service(m_mltProducer->parent().get_service());
4345 if (service.type() != tractor_type) {
4346 kWarning() << "// TRACTOR PROBLEM";
4347 return QList <TransitionInfo> ();
4351 Mlt::Tractor tractor(service);
4352 QList <TransitionInfo> transitionInfos;
4353 Mlt::Playlist playlist;
4354 int ct = tractor.count();
4356 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
4362 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
4363 tractor.set_track(playlist, pos);
4364 Mlt::Producer newProd(tractor.track(pos));
4365 if (!videoTrack) newProd.set("hide", 1);
4367 for (; pos <= ct; pos++) {
4368 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
4369 tractor.set_track(*prodToMove, pos);
4370 prodToMove = prodToMove2;
4373 tractor.set_track(playlist, ix);
4374 Mlt::Producer newProd(tractor.track(ix));
4375 if (!videoTrack) newProd.set("hide", 1);
4380 mlt_service serv = m_mltProducer->parent().get_service();
4381 mlt_service nextservice = mlt_service_get_producer(serv);
4382 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4383 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4384 QString resource = mlt_properties_get(properties, "mlt_service");
4385 Mlt::Field *field = tractor.field();
4386 QList <Mlt::Transition *> trList;
4388 while (mlt_type == "transition") {
4389 if (resource != "mix") {
4390 Mlt::Transition transition((mlt_transition) nextservice);
4391 nextservice = mlt_service_producer(nextservice);
4392 int currentbTrack = transition.get_b_track();
4393 int currentaTrack = transition.get_a_track();
4394 bool trackChanged = false;
4395 bool forceTransitionTrack = false;
4396 if (currentbTrack >= ix) {
4397 if (currentbTrack == ix && currentaTrack < ix) forceTransitionTrack = true;
4399 trackChanged = true;
4401 if (currentaTrack >= ix) {
4403 trackChanged = true;
4405 kDebug()<<"// Newtrans: "<<currentaTrack<<"/"<<currentbTrack;
4407 // disconnect all transitions
4408 Mlt::Properties trans_props(transition.get_properties());
4409 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
4410 Mlt::Properties new_trans_props(cp->get_properties());
4411 new_trans_props.inherit(trans_props);
4414 // Transition track needs to be adjusted
4415 cp->set("a_track", currentaTrack);
4416 cp->set("b_track", currentbTrack);
4417 // Check if transition track was changed and needs to be forced
4418 if (forceTransitionTrack) cp->set("force_track", 1);
4419 TransitionInfo trInfo;
4420 trInfo.startPos = GenTime(transition.get_in(), m_fps);
4421 trInfo.a_track = currentaTrack;
4422 trInfo.b_track = currentbTrack;
4423 trInfo.forceTrack = cp->get_int("force_track");
4424 transitionInfos.append(trInfo);
4427 field->disconnect_service(transition);
4429 else nextservice = mlt_service_producer(nextservice);
4430 if (nextservice == NULL) break;
4431 properties = MLT_SERVICE_PROPERTIES(nextservice);
4432 mlt_type = mlt_properties_get(properties, "mlt_type");
4433 resource = mlt_properties_get(properties, "mlt_service");
4436 // Add audio mix transition to last track
4437 Mlt::Transition transition(*m_mltProfile, "mix");
4438 transition.set("a_track", 1);
4439 transition.set("b_track", ct);
4440 transition.set("always_active", 1);
4441 transition.set("internal_added", 237);
4442 transition.set("combine", 1);
4443 mltPlantTransition(field, transition, 1, ct);
4445 // re-add transitions
4446 for (int i = trList.count() - 1; i >= 0; i--) {
4447 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
4452 blockSignals(false);
4453 return transitionInfos;
4457 void Render::mltDeleteTrack(int ix)
4460 doc.setContent(sceneList(), false);
4461 int tracksCount = doc.elementsByTagName("track").count() - 1;
4462 QDomNode track = doc.elementsByTagName("track").at(ix);
4463 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
4464 QDomNodeList transitions = doc.elementsByTagName("transition");
4465 for (int i = 0; i < transitions.count(); i++) {
4466 QDomElement e = transitions.at(i).toElement();
4467 QDomNodeList props = e.elementsByTagName("property");
4468 QMap <QString, QString> mappedProps;
4469 for (int j = 0; j < props.count(); j++) {
4470 QDomElement f = props.at(j).toElement();
4471 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
4473 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
4474 tractor.removeChild(transitions.at(i));
4476 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
4477 // Transition needs to be moved
4478 int a_track = mappedProps.value("a_track").toInt();
4479 int b_track = mappedProps.value("b_track").toInt();
4480 if (a_track > 0 && a_track >= ix) a_track --;
4481 if (b_track == ix) {
4482 // transition was on the deleted track, so remove it
4483 tractor.removeChild(transitions.at(i));
4487 if (b_track > 0 && b_track > ix) b_track --;
4488 for (int j = 0; j < props.count(); j++) {
4489 QDomElement f = props.at(j).toElement();
4490 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
4491 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
4496 tractor.removeChild(track);
4497 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
4498 setSceneList(doc.toString(), m_mltConsumer->position());
4499 emit refreshDocumentProducers(false, false);
4503 void Render::updatePreviewSettings()
4505 kDebug() << "////// RESTARTING CONSUMER";
4506 if (!m_mltConsumer || !m_mltProducer) return;
4507 if (m_mltProducer->get_playtime() == 0) return;
4508 QMutexLocker locker(&m_mutex);
4509 Mlt::Service service(m_mltProducer->parent().get_service());
4510 if (service.type() != tractor_type) return;
4512 //m_mltConsumer->set("refresh", 0);
4513 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
4514 m_mltConsumer->purge();
4515 QString scene = sceneList();
4517 if (m_mltProducer) {
4518 pos = m_mltProducer->position();
4521 setSceneList(scene, pos);
4525 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
4527 // Update all frame positions to the new fps value
4528 //WARNING: there are probably some effects or other that hold a frame value
4529 // as parameter and will also need to be updated here!
4531 doc.setContent(scene);
4533 double factor = new_fps / current_fps;
4534 QDomNodeList producers = doc.elementsByTagName("producer");
4535 for (int i = 0; i < producers.count(); i++) {
4536 QDomElement prod = producers.at(i).toElement();
4537 prod.removeAttribute("in");
4538 prod.removeAttribute("out");
4540 QDomNodeList props = prod.childNodes();
4541 for (int j = 0; j < props.count(); j++) {
4542 QDomElement param = props.at(j).toElement();
4543 QString paramName = param.attribute("name");
4544 if (paramName.startsWith("meta.") || paramName == "length") {
4545 prod.removeChild(props.at(j));
4551 QDomNodeList entries = doc.elementsByTagName("entry");
4552 for (int i = 0; i < entries.count(); i++) {
4553 QDomElement entry = entries.at(i).toElement();
4554 int in = entry.attribute("in").toInt();
4555 int out = entry.attribute("out").toInt();
4556 in = factor * in + 0.5;
4557 out = factor * out + 0.5;
4558 entry.setAttribute("in", in);
4559 entry.setAttribute("out", out);
4562 QDomNodeList blanks = doc.elementsByTagName("blank");
4563 for (int i = 0; i < blanks.count(); i++) {
4564 QDomElement blank = blanks.at(i).toElement();
4565 int length = blank.attribute("length").toInt();
4566 length = factor * length + 0.5;
4567 blank.setAttribute("length", QString::number(length));
4570 QDomNodeList filters = doc.elementsByTagName("filter");
4571 for (int i = 0; i < filters.count(); i++) {
4572 QDomElement filter = filters.at(i).toElement();
4573 int in = filter.attribute("in").toInt();
4574 int out = filter.attribute("out").toInt();
4575 in = factor * in + 0.5;
4576 out = factor * out + 0.5;
4577 filter.setAttribute("in", in);
4578 filter.setAttribute("out", out);
4581 QDomNodeList transitions = doc.elementsByTagName("transition");
4582 for (int i = 0; i < transitions.count(); i++) {
4583 QDomElement transition = transitions.at(i).toElement();
4584 int in = transition.attribute("in").toInt();
4585 int out = transition.attribute("out").toInt();
4586 in = factor * in + 0.5;
4587 out = factor * out + 0.5;
4588 transition.setAttribute("in", in);
4589 transition.setAttribute("out", out);
4590 QDomNodeList props = transition.childNodes();
4591 for (int j = 0; j < props.count(); j++) {
4592 QDomElement param = props.at(j).toElement();
4593 QString paramName = param.attribute("name");
4594 if (paramName == "geometry") {
4595 QString geom = param.firstChild().nodeValue();
4596 QStringList keys = geom.split(';');
4597 QStringList newKeys;
4598 for (int k = 0; k < keys.size(); ++k) {
4599 if (keys.at(k).contains('=')) {
4600 int pos = keys.at(k).section('=', 0, 0).toInt();
4601 pos = factor * pos + 0.5;
4602 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4603 } else newKeys.append(keys.at(k));
4605 param.firstChild().setNodeValue(newKeys.join(";"));
4609 QDomElement root = doc.documentElement();
4610 if (!root.isNull()) {
4611 QDomElement tractor = root.firstChildElement("tractor");
4612 int out = tractor.attribute("out").toInt();
4613 out = factor * out + 0.5;
4614 tractor.setAttribute("out", out);
4615 emit durationChanged(out);
4618 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4619 return doc.toString();
4623 void Render::sendFrameUpdate()
4625 if (m_mltProducer) {
4626 Mlt::Frame * frame = m_mltProducer->get_frame();
4627 emitFrameUpdated(*frame);
4632 Mlt::Producer* Render::getProducer()
4634 return m_mltProducer;
4637 const QString Render::activeClipId()
4639 if (m_mltProducer) return m_mltProducer->get("id");
4644 bool Render::getBlackMagicDeviceList(KComboBox *devicelist, bool force)
4646 if (!force && !KdenliveSettings::decklink_device_found()) return false;
4647 Mlt::Profile profile;
4648 Mlt::Producer bm(profile, "decklink");
4649 int found_devices = 0;
4650 if (bm.is_valid()) {
4651 bm.set("list_devices", 1);
4652 found_devices = bm.get_int("devices");
4654 else KdenliveSettings::setDecklink_device_found(false);
4655 if (found_devices <= 0) {
4656 devicelist->setEnabled(false);
4659 KdenliveSettings::setDecklink_device_found(true);
4660 for (int i = 0; i < found_devices; i++) {
4661 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4662 devicelist->addItem(bm.get(tmp));
4668 bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist, bool force)
4670 if (!force && !KdenliveSettings::decklink_device_found()) return false;
4671 Mlt::Profile profile;
4672 Mlt::Consumer bm(profile, "decklink");
4673 int found_devices = 0;
4674 if (bm.is_valid()) {
4675 bm.set("list_devices", 1);;
4676 found_devices = bm.get_int("devices");
4678 else KdenliveSettings::setDecklink_device_found(false);
4679 if (found_devices <= 0) {
4680 devicelist->setEnabled(false);
4683 KdenliveSettings::setDecklink_device_found(true);
4684 for (int i = 0; i < found_devices; i++) {
4685 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4686 devicelist->addItem(bm.get(tmp));
4692 void Render::slotMultiStreamProducerFound(const QString path, QList<int> audio_list, QList<int> video_list, stringMap data)
4694 if (KdenliveSettings::automultistreams()) {
4695 for (int i = 1; i < video_list.count(); i++) {
4696 int vindex = video_list.at(i);
4698 if (i <= audio_list.count() -1) {
4699 aindex = audio_list.at(i);
4701 data.insert("video_index", QString::number(vindex));
4702 data.insert("audio_index", QString::number(aindex));
4703 data.insert("bypassDuplicate", "1");
4704 emit addClip(KUrl(path), data);
4709 int width = 60.0 * m_mltProfile->dar();
4710 int swidth = 60.0 * m_mltProfile->width() / m_mltProfile->height();
4711 if (width % 2 == 1) width++;
4713 KDialog dialog(qApp->activeWindow());
4714 dialog.setCaption("Multi Stream Clip");
4715 dialog.setButtons(KDialog::Ok | KDialog::Cancel);
4716 dialog.setButtonText(KDialog::Ok, i18n("Import selected clips"));
4717 QWidget *content = new QWidget(&dialog);
4718 dialog.setMainWidget(content);
4719 QVBoxLayout *vbox = new QVBoxLayout(content);
4720 QLabel *lab1 = new QLabel(i18n("Additional streams for clip\n %1", path), content);
4721 vbox->addWidget(lab1);
4722 QList <QGroupBox*> groupList;
4723 QList <QComboBox*> comboList;
4724 // We start loading the list at 1, video index 0 should already be loaded
4725 for (int j = 1; j < video_list.count(); j++) {
4726 Mlt::Producer multiprod(* m_mltProfile, path.toUtf8().constData());
4727 multiprod.set("video_index", video_list.at(j));
4728 QImage thumb = KThumb::getFrame(&multiprod, 0, swidth, width, 60);
4729 QGroupBox *streamFrame = new QGroupBox(i18n("Video stream %1", video_list.at(j)), content);
4730 streamFrame->setProperty("vindex", video_list.at(j));
4731 groupList << streamFrame;
4732 streamFrame->setCheckable(true);
4733 streamFrame->setChecked(true);
4734 QVBoxLayout *vh = new QVBoxLayout( streamFrame );
4735 QLabel *iconLabel = new QLabel(content);
4736 iconLabel->setPixmap(QPixmap::fromImage(thumb));
4737 vh->addWidget(iconLabel);
4738 if (audio_list.count() > 1) {
4739 QComboBox *cb = new QComboBox(content);
4740 for (int k = 0; k < audio_list.count(); k++) {
4741 cb->addItem(i18n("Audio stream %1", audio_list.at(k)), audio_list.at(k));
4744 cb->setCurrentIndex(qMin(j, audio_list.count() - 1));
4747 vbox->addWidget(streamFrame);
4749 if (dialog.exec() == QDialog::Accepted) {
4750 // import selected streams
4751 for (int i = 0; i < groupList.count(); i++) {
4752 if (groupList.at(i)->isChecked()) {
4753 int vindex = groupList.at(i)->property("vindex").toInt();
4754 int aindex = comboList.at(i)->itemData(comboList.at(i)->currentIndex()).toInt();
4755 data.insert("video_index", QString::number(vindex));
4756 data.insert("audio_index", QString::number(aindex));
4757 data.insert("bypassDuplicate", "1");
4758 emit addClip(KUrl(path), data);
4765 bool Render::checkX11Grab()
4767 if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::ffmpegpath().isEmpty()) return false;
4770 args << "avformat:f-list";
4771 p.start(KdenliveSettings::rendererpath(), args);
4772 if (!p.waitForStarted()) return false;
4773 if (!p.waitForFinished()) return false;
4774 QByteArray result = p.readAllStandardError();
4775 return result.contains("x11grab");
4778 #include "renderer.moc"