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 // kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified();
57 if (level > MLT_LOG_ERROR) return;
59 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
65 void Render::consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
67 // detect if the producer has finished playing. Is there a better way to do it?
68 self->emitFrameNumber();
69 Mlt::Frame frame(frame_ptr);
70 if (!frame.is_valid()) return;
71 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
72 self->emitFrameUpdated(frame);
74 if (self->analyseAudio) {
75 self->showAudio(frame);
77 if (frame.get_double("_speed") == 0) self->emitConsumerStopped();
78 else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
80 self->emitConsumerStopped(true);
85 static void consumer_paused(mlt_consumer, Render * self, mlt_frame frame_ptr)
87 // detect if the producer has finished playing. Is there a better way to do it?
88 Mlt::Frame frame(frame_ptr);
89 if (!frame.is_valid()) return;
90 if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
92 self->emitConsumerStopped(true);
94 else self->emitConsumerStopped();
98 void Render::consumer_gl_frame_show(mlt_consumer consumer, Render * self, mlt_frame frame_ptr)
100 // detect if the producer has finished playing. Is there a better way to do it?
101 if (self->externalConsumer && !self->analyseAudio && !self->sendFrameForAnalysis) {
102 emit self->rendererPosition((int) mlt_consumer_position(consumer));
105 Mlt::Frame frame(frame_ptr);
106 if (frame.get_double("_speed") == 0) self->emitConsumerStopped();
107 else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
109 self->emitConsumerStopped(true);
111 emit self->mltFrameReceived(new Mlt::Frame(frame_ptr));
114 Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWidget *parent) :
115 AbstractRender(rendererName, parent),
116 requestedSeekPosition(SEEK_INACTIVE),
117 showFrameSemaphore(1),
118 externalConsumer(false),
119 m_name(rendererName),
123 m_showFrameEvent(NULL),
127 m_isSplitView(false),
132 qRegisterMetaType<stringMap> ("stringMap");
133 analyseAudio = KdenliveSettings::monitor_audio();
134 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
135 buildConsumer(profile);
136 m_mltProducer = m_blackClip->cut(0, 1);
137 m_mltConsumer->connect(*m_mltProducer);
138 m_mltProducer->set_speed(0.0);
139 m_refreshTimer.setSingleShot(true);
140 m_refreshTimer.setInterval(100);
141 connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
142 connect(this, SIGNAL(multiStreamFound(const QString &,QList<int>,QList<int>,stringMap)), this, SLOT(slotMultiStreamProducerFound(const QString &,QList<int>,QList<int>,stringMap)));
143 connect(this, SIGNAL(checkSeeking()), this, SLOT(slotCheckSeeking()));
144 connect(this, SIGNAL(mltFrameReceived(Mlt::Frame *)), this, SLOT(showFrame(Mlt::Frame *)), Qt::UniqueConnection);
154 void Render::closeMlt()
157 m_requestList.clear();
158 m_infoThread.waitForFinished();
159 if (m_showFrameEvent) delete m_showFrameEvent;
160 if (m_pauseEvent) delete m_pauseEvent;
161 if (m_mltConsumer) delete m_mltConsumer;
162 if (m_mltProducer) delete m_mltProducer;
163 /*if (m_mltProducer) {
164 Mlt::Service service(m_mltProducer->parent().get_service());
167 if (service.type() == tractor_type) {
168 Mlt::Tractor tractor(service);
169 Mlt::Field *field = tractor.field();
170 mlt_service nextservice = mlt_service_get_producer(service.get_service());
171 mlt_service nextservicetodisconnect;
172 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
173 QString mlt_type = mlt_properties_get(properties, "mlt_type");
174 QString resource = mlt_properties_get(properties, "mlt_service");
175 // Delete all transitions
176 while (mlt_type == "transition") {
177 nextservicetodisconnect = nextservice;
178 nextservice = mlt_service_producer(nextservice);
179 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
180 if (nextservice == NULL) break;
181 properties = MLT_SERVICE_PROPERTIES(nextservice);
182 mlt_type = mlt_properties_get(properties, "mlt_type");
183 resource = mlt_properties_get(properties, "mlt_service");
192 //kDebug() << "// // // CLOSE RENDERER " << m_name;
193 if (m_blackClip) delete m_blackClip;
197 void Render::slotSwitchFullscreen()
199 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
202 void Render::buildConsumer(const QString &profileName)
207 m_activeProfile = profileName;
209 Mlt::Profile tmpProfile(m_activeProfile.toUtf8().constData());
210 m_mltProfile->set_colorspace(tmpProfile.colorspace());
211 m_mltProfile->set_frame_rate(tmpProfile.frame_rate_num(), tmpProfile.frame_rate_den());
212 m_mltProfile->set_height(tmpProfile.height());
213 m_mltProfile->set_width(tmpProfile.width());
214 m_mltProfile->set_progressive(tmpProfile.progressive());
215 m_mltProfile->set_sample_aspect(tmpProfile.sample_aspect_num(), tmpProfile.sample_aspect_den());
216 m_mltProfile->get_profile()->display_aspect_num = tmpProfile.display_aspect_num();
217 m_mltProfile->get_profile()->display_aspect_den = tmpProfile.display_aspect_den();
220 m_mltProfile = new Mlt::Profile(m_activeProfile.toUtf8().constData());
222 setenv("MLT_PROFILE", m_activeProfile.toUtf8().constData(), 1);
223 m_mltProfile->set_explicit(true);
225 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
226 m_blackClip->set("id", "black");
227 m_blackClip->set("mlt_type", "producer");
228 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor && m_winid != 0) {
229 // Use blackmagic card for video output
230 int device = KdenliveSettings::blackmagic_output_device();
232 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
233 if (!m_mltConsumer) {
234 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
235 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
236 mlt_log_set_callback(kdenlive_callback);
238 if (m_mltConsumer->is_valid()) {
239 externalConsumer = true;
240 m_mltConsumer->set("terminate_on_pause", 0);
241 m_mltConsumer->set("deinterlace_method", "onefield");
242 m_mltConsumer->set("rescale", "nearest");
243 m_mltConsumer->set("buffer", "1");
244 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
246 if (m_mltConsumer && m_mltConsumer->is_valid()) {
249 KMessageBox::information(qApp->activeWindow(), i18n("Your project's profile %1 is not compatible with the blackmagic output card. Please see supported profiles below. Switching to normal video display.", m_mltProfile->description()));
252 externalConsumer = false;
253 QString videoDriver = KdenliveSettings::videodrivername();
254 if (!videoDriver.isEmpty()) {
255 if (videoDriver == "x11_noaccel") {
256 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
259 unsetenv("SDL_VIDEO_YUV_HWACCEL");
262 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
264 //m_mltConsumer->set("fullscreen", 1);
267 if (!m_mltConsumer) {
268 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) {
269 int device = KdenliveSettings::blackmagic_output_device();
271 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
272 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
273 // Set defaults for decklink consumer
275 m_mltConsumer->set("terminate_on_pause", 0);
276 m_mltConsumer->set("deinterlace_method", "onefield");
277 externalConsumer = true;
281 if (!m_mltConsumer || !m_mltConsumer->is_valid()) {
282 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
283 m_mltConsumer->set("scrub_audio", 1);
284 m_mltConsumer->set("preview_off", 1);
285 m_mltConsumer->set("audio_buffer", 512);
286 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
288 m_mltConsumer->set("buffer", "1");
289 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
292 if (!m_mltConsumer) {
293 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
294 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
295 //m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
296 m_mltConsumer->set("progressive", 1);
298 m_mltConsumer->set("window_id", m_winid);
300 //m_mltConsumer->set("resize", 1);
301 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
302 m_mltConsumer->set("rescale", "nearest");
303 mlt_log_set_callback(kdenlive_callback);
305 QString audioDevice = KdenliveSettings::audiodevicename();
306 if (!audioDevice.isEmpty())
307 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
309 if (!videoDriver.isEmpty())
310 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
312 QString audioDriver = KdenliveSettings::audiodrivername();
315 // Disabled because the "auto" detected driver was sometimes wrong
316 if (audioDriver.isEmpty())
317 audioDriver = KdenliveSettings::autoaudiodrivername();
320 if (!audioDriver.isEmpty())
321 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
323 m_mltConsumer->set("frequency", 48000);
324 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
327 Mlt::Producer *Render::invalidProducer(const QString &id)
330 QString txt = '+' + i18n("Missing clip") + ".txt";
331 char *tmp = qstrdup(txt.toUtf8().constData());
332 clip = new Mlt::Producer(*m_mltProfile, tmp);
334 if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
336 clip->set("bgcolour", "0xff0000ff");
337 clip->set("pad", "10");
339 clip->set("id", id.toUtf8().constData());
340 clip->set("mlt_type", "producer");
344 bool Render::hasProfile(const QString &profileName) const
346 return m_activeProfile == profileName;
349 int Render::resetProfile(const QString &profileName, bool dropSceneList)
351 m_refreshTimer.stop();
353 if (externalConsumer == KdenliveSettings::external_display()) {
354 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
355 QString videoDriver = KdenliveSettings::videodrivername();
356 QString currentDriver = m_mltConsumer->get("video_driver");
357 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
358 QString background = KdenliveSettings::window_background().name();
359 QString currentBackground = m_mltConsumer->get("window_background");
360 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
361 kDebug() << "reset to same profile, nothing to do";
366 if (m_isSplitView) slotSplitView(false);
367 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
368 m_mltConsumer->purge();
371 if (!dropSceneList) scene = sceneList();
373 double current_fps = m_mltProfile->fps();
374 double current_dar = m_mltProfile->dar();
377 m_requestList.clear();
378 m_infoThread.waitForFinished();
381 pos = m_mltProducer->position();
383 Mlt::Service service(m_mltProducer->get_service());
384 if (service.type() == tractor_type) {
385 Mlt::Tractor tractor(service);
386 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
387 Mlt::Producer trackProducer(tractor.track(trackNb));
388 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
389 trackPlaylist.clear();
393 delete m_mltProducer;
395 m_mltProducer = NULL;
396 buildConsumer(profileName);
397 double new_fps = m_mltProfile->fps();
398 double new_dar = m_mltProfile->dar();
400 if (!dropSceneList) {
401 // We need to recover our playlist
402 if (current_fps != new_fps) {
403 // fps changed, we must update the scenelist positions
404 scene = updateSceneListFps(current_fps, new_fps, scene);
406 setSceneList(scene, pos);
407 // producers have changed (different profile), so reset them...
408 emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
413 void Render::seek(GenTime time)
417 int pos = time.frames(m_fps);
421 void Render::seek(int time)
424 time = qMax(0, time);
425 time = qMin(m_mltProducer->get_playtime(), time);
426 if (requestedSeekPosition == SEEK_INACTIVE) {
427 requestedSeekPosition = time;
428 m_mltConsumer->purge();
429 m_mltProducer->seek(time);
430 if (m_paused && !externalConsumer) {
431 m_mltConsumer->set("refresh", 1);
434 else requestedSeekPosition = time;
438 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
439 QPixmap pix(width, height);
441 mlt_image_format format = mlt_image_rgb24a;
442 uint8_t *thumb = frame->get_image(format, width, height);
443 QImage image(thumb, width, height, QImage::Format_ARGB32);
445 if (!image.isNull()) {
446 pix = pix.fromImage(image);
448 QPainter painter(&pix);
449 painter.drawRect(0, 0, width - 1, height - 1);
451 } else pix.fill(Qt::black);
455 int Render::frameRenderWidth() const
457 return m_mltProfile->width();
460 int Render::renderWidth() const
462 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
465 int Render::renderHeight() const
467 return m_mltProfile->height();
470 QImage Render::extractFrame(int frame_position, QString path, int width, int height)
473 width = frameRenderWidth();
474 height = renderHeight();
475 } else if (width % 2 == 1) width++;
476 int dwidth = height * frameRenderWidth() / renderHeight();
477 if (!path.isEmpty()) {
478 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
480 if (producer->is_valid()) {
481 QImage img = KThumb::getFrame(producer, frame_position, dwidth, width, height);
485 else delete producer;
489 if (!m_mltProducer || !path.isEmpty()) {
490 QImage pix(width, height, QImage::Format_RGB32);
494 return KThumb::getFrame(m_mltProducer, frame_position, dwidth, width, height);
497 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
501 if (url.fileName().startsWith(".all.")) { // check for slideshow
502 QString fileType = url.fileName().right(3);
504 QStringList::Iterator it;
506 QDir dir(url.directory());
508 filter << "*." + fileType;
509 filter << "*." + fileType.toUpper();
510 more = dir.entryList(filter, QDir::Files);
511 im.load(url.directory() + '/' + more.at(0));
512 } else im.load(url.path());
513 //pixmap = im.scaled(width, height);
517 double Render::consumerRatio() const
519 if (!m_mltConsumer) return 1.0;
520 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
524 int Render::getLength()
528 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
529 return mlt_producer_get_playtime(m_mltProducer->get_producer());
534 bool Render::isValid(KUrl url)
536 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
537 if (producer.is_blank())
543 double Render::dar() const
545 return m_mltProfile->dar();
548 double Render::sar() const
550 return m_mltProfile->sar();
553 void Render::slotSplitView(bool doit)
555 m_isSplitView = doit;
556 Mlt::Service service(m_mltProducer->parent().get_service());
557 Mlt::Tractor tractor(service);
558 if (service.type() != tractor_type || tractor.count() < 2) return;
559 Mlt::Field *field = tractor.field();
561 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
562 Mlt::Producer trackProducer(tractor.track(i));
563 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
564 if (QString(trackProducer.get("hide")).toInt() != 1) {
565 kDebug() << "// ADIDNG TRACK: " << i;
566 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
567 transition->set("mlt_service", "composite");
568 transition->set("a_track", 0);
569 transition->set("b_track", i);
570 transition->set("distort", 0);
571 transition->set("aligned", 0);
572 transition->set("internal_added", "200");
576 geometry = "0/0:50%x50%";
579 geometry = "50%/0:50%x50%";
582 geometry = "0/50%:50%x50%";
586 geometry = "50%/50%:50%x50%";
589 transition->set("geometry", geometry.toUtf8().constData());
590 transition->set("always_active", "1");
591 field->plant_transition(*transition, 0, i);
595 m_mltConsumer->set("refresh", 1);
597 mlt_service serv = m_mltProducer->parent().get_service();
598 mlt_service nextservice = mlt_service_get_producer(serv);
599 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
600 QString mlt_type = mlt_properties_get(properties, "mlt_type");
601 QString resource = mlt_properties_get(properties, "mlt_service");
602 mlt_service nextservicetodisconnect;
604 while (mlt_type == "transition") {
605 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
606 if (added == "200") {
607 nextservicetodisconnect = nextservice;
608 nextservice = mlt_service_producer(nextservice);
609 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
611 else nextservice = mlt_service_producer(nextservice);
612 if (nextservice == NULL) break;
613 properties = MLT_SERVICE_PROPERTIES(nextservice);
614 mlt_type = mlt_properties_get(properties, "mlt_type");
615 resource = mlt_properties_get(properties, "mlt_service");
616 m_mltConsumer->set("refresh", 1);
621 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer)
623 // Make sure we don't request the info for same clip twice
625 if (m_processingClipId.contains(clipId)) {
626 m_infoMutex.unlock();
629 for (int i = 0; i < m_requestList.count(); i++) {
630 if (m_requestList.at(i).clipId == clipId) {
631 // Clip is already queued
632 m_infoMutex.unlock();
636 requestClipInfo info;
638 info.clipId = clipId;
639 info.imageHeight = imageHeight;
640 info.replaceProducer = replaceProducer;
641 m_requestList.append(info);
642 m_infoMutex.unlock();
643 if (!m_infoThread.isRunning()) {
644 m_infoThread = QtConcurrent::run(this, &Render::processFileProperties);
648 void Render::forceProcessing(const QString &id)
650 if (m_processingClipId.contains(id)) return;
651 QMutexLocker lock(&m_infoMutex);
652 for (int i = 0; i < m_requestList.count(); i++) {
653 requestClipInfo info = m_requestList.at(i);
654 if (info.clipId == id) {
657 m_requestList.removeAt(i);
658 m_requestList.prepend(info);
665 int Render::processingItems()
667 QMutexLocker lock(&m_infoMutex);
668 int count = m_requestList.count() + m_processingClipId.count();
672 void Render::processingDone(const QString &id)
674 QMutexLocker lock(&m_infoMutex);
675 m_processingClipId.removeAll(id);
678 bool Render::isProcessing(const QString &id)
680 if (m_processingClipId.contains(id)) return true;
681 QMutexLocker lock(&m_infoMutex);
682 for (int i = 0; i < m_requestList.count(); i++) {
683 if (m_requestList.at(i).clipId == id) {
690 void Render::processFileProperties()
692 requestClipInfo info;
694 while (!m_requestList.isEmpty()) {
696 info = m_requestList.takeFirst();
697 m_processingClipId.append(info.clipId);
698 m_infoMutex.unlock();
702 if (info.xml.hasAttribute("proxy") && info.xml.attribute("proxy") != "-") {
703 path = info.xml.attribute("proxy");
704 // Check for missing proxies
705 if (QFileInfo(path).size() <= 0) {
706 // proxy is missing, re-create it
707 emit requestProxy(info.clipId);
708 proxyProducer = false;
709 path = info.xml.attribute("resource");
711 else proxyProducer = true;
714 path = info.xml.attribute("resource");
715 proxyProducer = false;
718 Mlt::Producer *producer = NULL;
719 CLIPTYPE type = (CLIPTYPE)info.xml.attribute("type").toInt();
721 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + info.xml.attribute("colour")).toUtf8().constData());
722 } else if (type == TEXT) {
723 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
724 if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
725 producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
726 } else if (url.isEmpty()) {
727 //WARNING: when is this case used? Not sure it is working.. JBM/
729 QDomElement mlt = doc.createElement("mlt");
730 QDomElement play = doc.createElement("playlist");
731 play.setAttribute("id", "playlist0");
732 doc.appendChild(mlt);
733 mlt.appendChild(play);
734 play.appendChild(doc.importNode(info.xml, true));
735 QDomElement tractor = doc.createElement("tractor");
736 tractor.setAttribute("id", "tractor0");
737 QDomElement track = doc.createElement("track");
738 track.setAttribute("producer", "playlist0");
739 tractor.appendChild(track);
740 mlt.appendChild(tractor);
741 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
743 producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
746 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
747 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
748 m_processingClipId.removeAll(info.clipId);
750 // Proxy file is corrupted
751 emit removeInvalidProxy(info.clipId, false);
753 else emit removeInvalidClip(info.clipId, info.replaceProducer);
758 if (proxyProducer && info.xml.hasAttribute("proxy_out")) {
759 producer->set("length", info.xml.attribute("proxy_out").toInt() + 1);
760 producer->set("out", info.xml.attribute("proxy_out").toInt());
761 if (producer->get_out() != info.xml.attribute("proxy_out").toInt()) {
762 // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
763 m_processingClipId.removeAll(info.clipId);
764 emit removeInvalidProxy(info.clipId, true);
770 if (info.xml.hasAttribute("force_aspect_ratio")) {
771 double aspect = info.xml.attribute("force_aspect_ratio").toDouble();
772 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
775 if (info.xml.hasAttribute("force_aspect_num") && info.xml.hasAttribute("force_aspect_den")) {
776 int width = info.xml.attribute("frame_size").section('x', 0, 0).toInt();
777 int height = info.xml.attribute("frame_size").section('x', 1, 1).toInt();
778 int aspectNumerator = info.xml.attribute("force_aspect_num").toInt();
779 int aspectDenominator = info.xml.attribute("force_aspect_den").toInt();
780 if (aspectDenominator != 0 && width != 0)
781 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
784 if (info.xml.hasAttribute("force_fps")) {
785 double fps = info.xml.attribute("force_fps").toDouble();
786 if (fps > 0) producer->set("force_fps", fps);
789 if (info.xml.hasAttribute("force_progressive")) {
791 int progressive = info.xml.attribute("force_progressive").toInt(&ok);
792 if (ok) producer->set("force_progressive", progressive);
794 if (info.xml.hasAttribute("force_tff")) {
796 int fieldOrder = info.xml.attribute("force_tff").toInt(&ok);
797 if (ok) producer->set("force_tff", fieldOrder);
799 if (info.xml.hasAttribute("threads")) {
800 int threads = info.xml.attribute("threads").toInt();
801 if (threads != 1) producer->set("threads", threads);
803 if (info.xml.hasAttribute("video_index")) {
804 int vindex = info.xml.attribute("video_index").toInt();
805 if (vindex != 0) producer->set("video_index", vindex);
807 if (info.xml.hasAttribute("audio_index")) {
808 int aindex = info.xml.attribute("audio_index").toInt();
809 if (aindex != 0) producer->set("audio_index", aindex);
811 if (info.xml.hasAttribute("force_colorspace")) {
812 int colorspace = info.xml.attribute("force_colorspace").toInt();
813 if (colorspace != 0) producer->set("force_colorspace", colorspace);
815 if (info.xml.hasAttribute("full_luma")) {
816 int full_luma = info.xml.attribute("full_luma").toInt();
817 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
822 if (info.xml.hasAttribute("out")) clipOut = info.xml.attribute("out").toInt();
824 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
825 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
827 if (info.xml.hasAttribute("length")) {
828 length = info.xml.attribute("length").toInt();
829 clipOut = length - 1;
831 else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt() + 1;
832 // Pass duration if it was forced
833 if (info.xml.hasAttribute("duration")) {
834 duration = info.xml.attribute("duration").toInt();
835 if (length < duration) {
837 if (clipOut > 0) clipOut = length - 1;
840 if (duration == 0) duration = length;
841 producer->set("length", length);
844 if (clipOut > 0) producer->set_in_and_out(info.xml.attribute("in").toInt(), clipOut);
846 producer->set("id", info.clipId.toUtf8().constData());
848 if (info.xml.hasAttribute("templatetext"))
849 producer->set("templatetext", info.xml.attribute("templatetext").toUtf8().constData());
851 int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5);
852 int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5);
853 int frameNumber = info.xml.attribute("thumbnail", "-1").toInt();
855 if ((!info.replaceProducer && info.xml.hasAttribute("file_hash")) || proxyProducer) {
856 // Clip already has all properties
858 // Recreate clip thumb
859 if (frameNumber > 0) producer->seek(frameNumber);
860 Mlt::Frame *frame = producer->get_frame();
861 if (frame && frame->is_valid()) {
862 QImage img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
863 emit replyGetImage(info.clipId, img);
865 if (frame) delete frame;
867 emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
871 stringMap filePropertyMap;
872 stringMap metadataPropertyMap;
875 if (frameNumber > 0) producer->seek(frameNumber);
876 duration = duration > 0 ? duration : producer->get_playtime();
877 filePropertyMap["duration"] = QString::number(duration);
878 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
880 if (type == SLIDESHOW) {
881 int ttl = info.xml.hasAttribute("ttl") ? info.xml.attribute("ttl").toInt() : 0;
882 if (ttl) producer->set("ttl", ttl);
883 if (!info.xml.attribute("animation").isEmpty()) {
884 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
885 if (filter && filter->is_valid()) {
887 QString geometry = SlideshowClip::animationToGeometry(info.xml.attribute("animation"), cycle);
888 if (!geometry.isEmpty()) {
889 if (info.xml.attribute("animation").contains("low-pass")) {
890 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
891 if (blur && blur->is_valid())
892 producer->attach(*blur);
894 filter->set("transition.geometry", geometry.toUtf8().data());
895 filter->set("transition.cycle", cycle);
896 producer->attach(*filter);
900 if (info.xml.attribute("fade") == "1") {
901 // user wants a fade effect to slideshow
902 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
903 if (filter && filter->is_valid()) {
904 if (ttl) filter->set("cycle", ttl);
905 if (info.xml.hasAttribute("luma_duration") && !info.xml.attribute("luma_duration").isEmpty()) filter->set("duration", info.xml.attribute("luma_duration").toInt());
906 if (info.xml.hasAttribute("luma_file") && !info.xml.attribute("luma_file").isEmpty()) {
907 filter->set("luma.resource", info.xml.attribute("luma_file").toUtf8().constData());
908 if (info.xml.hasAttribute("softness")) {
909 int soft = info.xml.attribute("softness").toInt();
910 filter->set("luma.softness", (double) soft / 100.0);
913 producer->attach(*filter);
916 if (info.xml.attribute("crop") == "1") {
917 // user wants to center crop the slides
918 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
919 if (filter && filter->is_valid()) {
920 filter->set("center", 1);
921 producer->attach(*filter);
927 const QString mltService = producer->get("mlt_service");
928 if (mltService == "xml" || mltService == "consumer") {
929 // MLT playlist, create producer with blank profile to get real profile info
930 // TODO: is there an easier way to get this info (original source clip profile) from MLT?
931 Mlt::Profile *original_profile = new Mlt::Profile();
932 Mlt::Producer *tmpProd = new Mlt::Producer(*original_profile, path.toUtf8().constData());
933 filePropertyMap["progressive"] = QString::number(original_profile->progressive());
934 filePropertyMap["colorspace"] = QString::number(original_profile->colorspace());
935 filePropertyMap["fps"] = QString::number(original_profile->fps());
936 filePropertyMap["aspect_ratio"] = QString::number(original_profile->sar());
938 delete original_profile;
940 else if (mltService == "avformat") {
942 vindex = producer->get_int("video_index");
945 int streams = producer->get_int("meta.media.nb_streams");
946 QList <int> audio_list;
947 QList <int> video_list;
948 for (int i = 0; i < streams; i++) {
949 QByteArray propertyName = QString("meta.media.%1.stream.type").arg(i).toLocal8Bit();
950 QString type = producer->get(propertyName.data());
951 if (type == "audio") audio_list.append(i);
952 else if (type == "video") video_list.append(i);
955 if (!info.xml.hasAttribute("video_index") && video_list.count() > 1) {
956 // Clip has more than one video stream, ask which one should be used
957 QMap <QString, QString> data;
958 if (info.xml.hasAttribute("group")) data.insert("group", info.xml.attribute("group"));
959 if (info.xml.hasAttribute("groupId")) data.insert("groupId", info.xml.attribute("groupId"));
960 emit multiStreamFound(path, audio_list, video_list, data);
961 // Force video index so that when reloading the clip we don't ask again for other streams
962 filePropertyMap["video_index"] = QString::number(vindex);
966 snprintf(property, sizeof(property), "meta.media.%d.stream.frame_rate", vindex);
967 if (producer->get(property))
968 filePropertyMap["fps"] = producer->get(property);
971 if (!filePropertyMap.contains("fps")) {
972 if (producer->get_double("meta.media.frame_rate_den") > 0) {
973 filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
974 } else filePropertyMap["fps"] = producer->get("source_fps");
978 Mlt::Frame *frame = producer->get_frame();
979 if (frame && frame->is_valid()) {
980 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
981 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
982 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
983 if (!filePropertyMap.contains("aspect_ratio")) filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
985 if (frame->get_int("test_image") == 0) {
986 if (mltService == "xml" || mltService == "consumer") {
987 filePropertyMap["type"] = "playlist";
988 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
989 } else if (frame->get_int("test_audio") == 0)
990 filePropertyMap["type"] = "av";
992 filePropertyMap["type"] = "video";
998 img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
999 variance = KThumb::imageVariance(img);
1000 if (frameNumber == -1 && variance< 6) {
1001 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
1002 frameNumber = duration > 100 ? 100 : duration / 2 ;
1003 producer->seek(frameNumber);
1005 frame = producer->get_frame();
1008 } while (variance == -1);
1010 if (frameNumber > -1) filePropertyMap["thumbnail"] = QString::number(frameNumber);
1011 emit replyGetImage(info.clipId, img);
1012 } else if (frame->get_int("test_audio") == 0) {
1013 emit replyGetImage(info.clipId, "audio-x-generic", fullWidth, info.imageHeight);
1014 filePropertyMap["type"] = "audio";
1017 // Retrieve audio / video codec name
1020 if (mltService == "avformat") {
1022 /*if (context->duration == AV_NOPTS_VALUE) {
1023 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
1024 emit removeInvalidClip(clipId);
1028 // Get the video_index
1030 int default_audio = producer->get_int("audio_index");
1033 int scan = producer->get_int("meta.media.progressive");
1034 filePropertyMap["progressive"] = QString::number(scan);
1036 // Find maximum stream index values
1037 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
1038 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
1039 QString type = producer->get(property);
1040 if (type == "video")
1042 else if (type == "audio")
1045 filePropertyMap["default_video"] = QString::number(vindex);
1046 filePropertyMap["video_max"] = QString::number(video_max);
1047 filePropertyMap["default_audio"] = QString::number(default_audio);
1048 filePropertyMap["audio_max"] = QString::number(audio_max);
1050 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex);
1051 if (producer->get(property)) {
1052 filePropertyMap["videocodec"] = producer->get(property);
1054 snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex);
1055 if (producer->get(property))
1056 filePropertyMap["videocodec"] = producer->get(property);
1059 query = QString("meta.media.%1.codec.pix_fmt").arg(vindex);
1060 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
1061 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
1063 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
1064 if (producer->get_int("audio_index") > -1) {
1065 // Get the audio_index
1066 int index = producer->get_int("audio_index");
1067 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
1068 if (producer->get(property)) {
1069 filePropertyMap["audiocodec"] = producer->get(property);
1071 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
1072 if (producer->get(property))
1073 filePropertyMap["audiocodec"] = producer->get(property);
1079 Mlt::Properties metadata;
1080 metadata.pass_values(*producer, "meta.attr.");
1081 int count = metadata.count();
1082 for (int i = 0; i < count; i ++) {
1083 QString name = metadata.get_name(i);
1084 QString value = QString::fromUtf8(metadata.get(i));
1085 if (name.endsWith("markup") && !value.isEmpty())
1086 metadataPropertyMap[ name.section('.', 0, -2)] = value;
1089 emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer);
1095 /** Create the producer from the MLT XML QDomDocument */
1096 void Render::initSceneList()
1098 kDebug() << "-------- INIT SCENE LIST ------_";
1100 QDomElement mlt = doc.createElement("mlt");
1101 doc.appendChild(mlt);
1102 QDomElement prod = doc.createElement("producer");
1103 prod.setAttribute("resource", "colour");
1104 prod.setAttribute("colour", "red");
1105 prod.setAttribute("id", "black");
1106 prod.setAttribute("in", "0");
1107 prod.setAttribute("out", "0");
1109 QDomElement tractor = doc.createElement("tractor");
1110 QDomElement multitrack = doc.createElement("multitrack");
1112 QDomElement playlist1 = doc.createElement("playlist");
1113 playlist1.appendChild(prod);
1114 multitrack.appendChild(playlist1);
1115 QDomElement playlist2 = doc.createElement("playlist");
1116 multitrack.appendChild(playlist2);
1117 QDomElement playlist3 = doc.createElement("playlist");
1118 multitrack.appendChild(playlist3);
1119 QDomElement playlist4 = doc.createElement("playlist");
1120 multitrack.appendChild(playlist4);
1121 QDomElement playlist5 = doc.createElement("playlist");
1122 multitrack.appendChild(playlist5);
1123 tractor.appendChild(multitrack);
1124 mlt.appendChild(tractor);
1125 // kDebug()<<doc.toString();
1127 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
1128 setSceneList(doc, 0);
1132 int Render::setProducer(Mlt::Producer *producer, int position)
1134 m_refreshTimer.stop();
1135 requestedSeekPosition = SEEK_INACTIVE;
1136 QMutexLocker locker(&m_mutex);
1138 int consumerPosition = 0;
1139 if (m_winid == -1 || !m_mltConsumer) {
1140 kDebug()<<" / / / / WARNING, MONITOR NOT READY";
1141 if (producer) delete producer;
1144 bool monitorIsActive = false;
1145 m_mltConsumer->set("refresh", 0);
1146 if (!m_mltConsumer->is_stopped()) {
1147 monitorIsActive = true;
1148 m_mltConsumer->stop();
1150 m_mltConsumer->purge();
1151 consumerPosition = m_mltConsumer->position();
1155 if (!producer || !producer->is_valid()) {
1156 if (producer) delete producer;
1157 producer = m_blackClip->cut(0, 1);
1158 producer->set("id", "black");
1161 if (!producer || !producer->is_valid()) {
1162 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
1165 if (m_mltProducer) currentId = m_mltProducer->get("id");
1167 if (position == -1 && producer->get("id") == currentId) position = consumerPosition;
1168 if (position != -1) producer->seek(position);
1169 m_fps = producer->get_fps();
1170 int volume = KdenliveSettings::volume();
1171 if (producer->get_int("_audioclip") == 1) {
1172 // This is an audio only clip, create fake multitrack to apply audiowave filter
1173 Mlt::Tractor *tractor = new Mlt::Tractor();
1174 Mlt::Producer *color= new Mlt::Producer(*m_mltProfile, "color:red");
1175 color->set_in_and_out(0, producer->get_out());
1176 tractor->set_track(*producer, 0);
1177 tractor->set_track(*color, 1);
1179 Mlt::Consumer xmlConsumer(*m_mltProfile, "xml:audio_hack");
1180 if (!xmlConsumer.is_valid()) return -1;
1181 xmlConsumer.set("terminate_on_pause", 1);
1182 xmlConsumer.connect(tractor->parent());
1187 QString playlist = QString::fromUtf8(xmlConsumer.get("audio_hack"));
1189 Mlt::Producer *result = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1190 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "audiowave");
1191 result->attach(*filter);
1192 tractor = new Mlt::Tractor();
1193 tractor->set_track(*result, 0);
1196 producer = &(tractor->parent());
1197 m_mltConsumer->connect(*producer);
1200 producer->set("meta.volume", (double)volume / 100);
1201 blockSignals(false);
1202 m_mltConsumer->connect(*producer);
1204 if (m_mltProducer) {
1205 m_mltProducer->set_speed(0);
1206 delete m_mltProducer;
1207 m_mltProducer = NULL;
1209 m_mltProducer = producer;
1210 m_mltProducer->set_speed(0);
1211 if (monitorIsActive) {
1214 emit durationChanged(m_mltProducer->get_playtime());
1215 position = m_mltProducer->position();
1216 emit rendererPosition(position);
1220 void Render::startConsumer() {
1221 if (m_mltConsumer->is_stopped() && m_mltConsumer->start() == -1) {
1222 // ARGH CONSUMER BROKEN!!!!
1223 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."));
1224 if (m_showFrameEvent) delete m_showFrameEvent;
1225 m_showFrameEvent = NULL;
1226 if (m_pauseEvent) delete m_pauseEvent;
1227 m_pauseEvent = NULL;
1228 delete m_mltConsumer;
1229 m_mltConsumer = NULL;
1232 m_mltConsumer->set("refresh", 1);
1235 int Render::setSceneList(QDomDocument list, int position)
1237 return setSceneList(list.toString(), position);
1240 int Render::setSceneList(QString playlist, int position)
1242 requestedSeekPosition = SEEK_INACTIVE;
1243 m_refreshTimer.stop();
1244 QMutexLocker locker(&m_mutex);
1245 if (m_winid == -1) return -1;
1248 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
1250 // Remove previous profile info
1252 doc.setContent(playlist);
1253 QDomElement profile = doc.documentElement().firstChildElement("profile");
1254 doc.documentElement().removeChild(profile);
1255 playlist = doc.toString();
1257 if (m_mltConsumer) {
1258 if (!m_mltConsumer->is_stopped()) {
1259 m_mltConsumer->stop();
1261 m_mltConsumer->set("refresh", 0);
1263 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
1266 m_requestList.clear();
1267 m_infoThread.waitForFinished();
1269 if (m_mltProducer) {
1270 m_mltProducer->set_speed(0);
1271 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1273 /*Mlt::Service service(m_mltProducer->parent().get_service());
1276 if (service.type() == tractor_type) {
1277 Mlt::Tractor tractor(service);
1278 Mlt::Field *field = tractor.field();
1279 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1280 mlt_service nextservicetodisconnect;
1281 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1282 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1283 QString resource = mlt_properties_get(properties, "mlt_service");
1284 // Delete all transitions
1285 while (mlt_type == "transition") {
1286 nextservicetodisconnect = nextservice;
1287 nextservice = mlt_service_producer(nextservice);
1288 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1289 if (nextservice == NULL) break;
1290 properties = MLT_SERVICE_PROPERTIES(nextservice);
1291 mlt_type = mlt_properties_get(properties, "mlt_type");
1292 resource = mlt_properties_get(properties, "mlt_service");
1296 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1297 Mlt::Producer trackProducer(tractor.track(trackNb));
1298 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1299 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1305 qDeleteAll(m_slowmotionProducers.values());
1306 m_slowmotionProducers.clear();
1308 delete m_mltProducer;
1309 m_mltProducer = NULL;
1314 m_locale = QLocale();
1315 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1316 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1317 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1318 m_mltProducer = m_blackClip->cut(0, 1);
1321 m_mltProducer->set("eof", "pause");
1323 int volume = KdenliveSettings::volume();
1324 m_mltProducer->set("meta.volume", (double)volume / 100);
1325 m_mltProducer->optimise();
1327 /*if (KdenliveSettings::osdtimecode()) {
1328 // Attach filter for on screen display of timecode
1330 QString attr = "attr_check";
1331 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1332 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1333 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1334 mlt_filter_close( filter );
1336 m_osdInfo = new Mlt::Filter("data_show");
1337 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1338 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1339 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1340 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1341 m_osdInfo->set("dynamic", "1");
1343 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1345 m_osdInfo->set("dynamic", "0");
1348 m_fps = m_mltProducer->get_fps();
1349 if (position != 0) {
1350 // Seek to correct place after opening project.
1351 m_mltProducer->seek(position);
1354 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1355 m_mltConsumer->connect(*m_mltProducer);
1356 m_mltProducer->set_speed(0);
1357 fillSlowMotionProducers();
1358 blockSignals(false);
1359 emit durationChanged(m_mltProducer->get_playtime());
1362 //kDebug()<<"// SETSCN LST, POS: "<<position;
1363 //if (position != 0) emit rendererPosition(position);
1366 void Render::checkMaxThreads()
1368 // Make sure we don't use too much threads, MLT avformat does not cope with too much threads
1369 // Currently, Kdenlive uses the following avformat threads:
1370 // One thread to get info when adding a clip
1371 // One thread to create the timeline video thumbnails
1372 // One thread to create the audio thumbnails
1373 Mlt::Service service(m_mltProducer->parent().get_service());
1374 if (service.type() != tractor_type) {
1375 kWarning() << "// TRACTOR PROBLEM";
1378 Mlt::Tractor tractor(service);
1379 int mltMaxThreads = mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1380 int requestedThreads = tractor.count() + 4;
1381 if (requestedThreads > mltMaxThreads) {
1382 mlt_service_cache_set_size(service.get_service(), "producer_avformat", requestedThreads);
1383 kDebug()<<"// MLT threads updated to: "<<mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1387 const QString Render::sceneList()
1390 Mlt::Profile profile((mlt_profile) 0);
1391 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1392 if (!xmlConsumer.is_valid()) return QString();
1393 m_mltProducer->optimise();
1394 xmlConsumer.set("terminate_on_pause", 1);
1395 Mlt::Producer prod(m_mltProducer->get_producer());
1396 if (!prod.is_valid()) return QString();
1397 bool split = m_isSplitView;
1398 if (split) slotSplitView(false);
1399 xmlConsumer.connect(prod);
1401 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1402 if (split) slotSplitView(true);
1406 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1410 doc.setContent(sceneList(), false);
1411 if (doc.isNull()) return false;
1412 QDomElement root = doc.documentElement();
1413 if (!kdenliveData.isNull() && !root.isNull()) {
1414 // add Kdenlive specific tags
1415 root.appendChild(doc.importNode(kdenliveData, true));
1417 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1418 kWarning() << "////// ERROR writing to file: " << path;
1421 file.write(doc.toString().toUtf8());
1422 if (file.error() != QFile::NoError) {
1430 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1432 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1433 m_mltProducer->optimise();
1434 xmlConsumer.set("terminate_on_pause", 1);
1435 if (m_name == Kdenlive::clipMonitor) {
1436 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1438 list.insert_at(0, prod, 0);
1440 list.set("title", desc.toUtf8().constData());
1441 xmlConsumer.connect(list);
1444 //TODO: not working yet, save zone from timeline
1445 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1446 /* Mlt::Service service(p1->parent().get_service());
1447 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1449 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1450 //prod->set("title", desc.toUtf8().constData());
1451 xmlConsumer.connect(*p1); //list);
1454 xmlConsumer.start();
1458 bool Render::saveClip(int track, GenTime position, KUrl url, QString desc)
1461 Mlt::Service service(m_mltProducer->parent().get_service());
1462 Mlt::Tractor tractor(service);
1463 Mlt::Producer trackProducer(tractor.track(track));
1464 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1466 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1467 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1469 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1473 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1474 xmlConsumer.set("terminate_on_pause", 1);
1476 list.insert_at(0, clip, 0);
1478 list.set("title", desc.toUtf8().constData());
1479 xmlConsumer.connect(list);
1481 kDebug()<<"// SAVED: "<<url;
1485 double Render::fps() const
1490 int Render::volume() const
1492 if (!m_mltConsumer || !m_mltProducer) return -1;
1493 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1496 void Render::slotSetVolume(int volume)
1498 if (!m_mltConsumer || !m_mltProducer) return;
1499 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1502 m_mltConsumer->set("refresh", 0);
1503 // Attach filter for on screen display of timecode
1504 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1505 mlt_properties_set_double( properties, "meta.volume", volume );
1506 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1507 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1509 if (!KdenliveSettings::osdtimecode()) {
1510 m_mltProducer->detach(*m_osdInfo);
1511 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1512 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1515 //m_osdTimer->setSingleShot(2500);
1518 void Render::slotOsdTimeout()
1520 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1521 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1522 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1523 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1527 void Render::start()
1529 m_refreshTimer.stop();
1530 QMutexLocker locker(&m_mutex);
1531 if (m_winid == -1) {
1532 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1535 if (!m_mltConsumer) return;
1536 if (m_mltConsumer->is_stopped()) {
1537 if (m_mltConsumer->start() == -1) {
1538 //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."));
1539 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1541 m_mltConsumer->purge();
1542 m_mltConsumer->set("refresh", 1);
1549 requestedSeekPosition = SEEK_INACTIVE;
1550 m_refreshTimer.stop();
1551 QMutexLocker locker(&m_mutex);
1552 if (m_mltProducer == NULL) return;
1553 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1554 m_mltConsumer->stop();
1555 m_mltConsumer->purge();
1558 if (m_mltProducer) {
1559 if (m_isZoneMode) resetZoneMode();
1560 m_mltProducer->set_speed(0.0);
1564 void Render::stop(const GenTime & startTime)
1566 requestedSeekPosition = SEEK_INACTIVE;
1567 m_refreshTimer.stop();
1568 QMutexLocker locker(&m_mutex);
1569 if (m_mltProducer) {
1570 if (m_isZoneMode) resetZoneMode();
1571 m_mltProducer->set_speed(0.0);
1572 m_mltProducer->seek((int) startTime.frames(m_fps));
1574 m_mltConsumer->purge();
1577 void Render::pause()
1579 requestedSeekPosition = SEEK_INACTIVE;
1580 if (!m_mltProducer || !m_mltConsumer)
1583 m_mltProducer->set_speed(0.0);
1584 /*m_mltConsumer->set("refresh", 0);
1585 //if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1586 m_mltProducer->seek(m_mltConsumer->position());*/
1589 void Render::switchPlay(bool play)
1591 QMutexLocker locker(&m_mutex);
1592 requestedSeekPosition = SEEK_INACTIVE;
1593 if (!m_mltProducer || !m_mltConsumer)
1595 if (m_isZoneMode) resetZoneMode();
1596 if (play && m_paused) {
1597 if (m_name == Kdenlive::clipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
1599 m_mltProducer->set_speed(1.0);
1600 if (m_mltConsumer->is_stopped()) {
1601 m_mltConsumer->start();
1603 m_mltConsumer->set("refresh", 1);
1606 m_mltProducer->set_speed(0.0);
1610 void Render::play(double speed)
1612 requestedSeekPosition = SEEK_INACTIVE;
1613 if (!m_mltProducer) return;
1614 double current_speed = m_mltProducer->get_speed();
1615 if (current_speed == speed) return;
1616 if (m_isZoneMode) resetZoneMode();
1617 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1618 m_mltProducer->set_speed(speed);
1619 if (m_mltConsumer->is_stopped() && speed != 0) {
1620 m_mltConsumer->start();
1622 m_paused = speed == 0;
1623 if (current_speed == 0 && speed != 0) m_mltConsumer->set("refresh", 1);
1626 void Render::play(const GenTime & startTime)
1628 requestedSeekPosition = SEEK_INACTIVE;
1629 if (!m_mltProducer || !m_mltConsumer)
1632 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1633 m_mltProducer->set_speed(1.0);
1634 m_mltConsumer->set("refresh", 1);
1637 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1639 requestedSeekPosition = SEEK_INACTIVE;
1640 if (!m_mltProducer || !m_mltConsumer)
1642 //m_mltProducer->set("eof", "loop");
1643 m_isLoopMode = true;
1644 m_loopStart = startTime;
1645 playZone(startTime, stopTime);
1648 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1650 requestedSeekPosition = SEEK_INACTIVE;
1651 if (!m_mltProducer || !m_mltConsumer)
1653 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1654 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1656 m_mltProducer->set_speed(1.0);
1657 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1658 m_mltConsumer->set("refresh", 1);
1659 m_isZoneMode = true;
1662 void Render::resetZoneMode()
1664 if (!m_isZoneMode && !m_isLoopMode) return;
1665 m_mltProducer->set("out", m_mltProducer->get_length());
1666 m_isZoneMode = false;
1667 m_isLoopMode = false;
1670 void Render::seekToFrame(int pos)
1678 void Render::seekToFrameDiff(int diff)
1683 if (requestedSeekPosition == SEEK_INACTIVE)
1684 seek(m_mltProducer->position() + diff);
1685 else seek(requestedSeekPosition + diff);
1688 void Render::refreshIfActive()
1690 if (!m_mltConsumer->is_stopped() && m_mltProducer && m_paused) m_refreshTimer.start();
1693 void Render::doRefresh()
1695 if (m_mltProducer && m_paused) m_refreshTimer.start();
1698 void Render::refresh()
1700 m_refreshTimer.stop();
1701 QMutexLocker locker(&m_mutex);
1704 if (m_mltConsumer) {
1705 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1706 m_mltConsumer->set("refresh", 1);
1707 //m_mltConsumer->purge();
1711 void Render::setDropFrames(bool show)
1713 QMutexLocker locker(&m_mutex);
1714 if (m_mltConsumer) {
1715 int dropFrames = KdenliveSettings::mltthreads();
1716 if (show == false) dropFrames = -dropFrames;
1717 m_mltConsumer->stop();
1719 m_mltConsumer->set("real_time", dropFrames);
1721 m_mltConsumer->set("play.real_time", dropFrames);
1723 if (m_mltConsumer->start() == -1) {
1724 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1730 bool Render::isPlaying() const
1732 if (!m_mltConsumer || m_mltConsumer->is_stopped()) return false;
1736 double Render::playSpeed() const
1738 if (m_mltProducer) return m_mltProducer->get_speed();
1742 GenTime Render::seekPosition() const
1744 if (m_mltConsumer) return GenTime((int) m_mltConsumer->position(), m_fps);
1745 //if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1746 else return GenTime();
1749 int Render::seekFramePosition() const
1751 //if (m_mltProducer) return (int) m_mltProducer->position();
1752 if (m_mltConsumer) return (int) m_mltConsumer->position();
1756 void Render::emitFrameUpdated(Mlt::Frame& frame)
1758 mlt_image_format format = mlt_image_rgb24a;
1761 const uchar* image = frame.get_image(format, width, height);
1762 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1763 memcpy(qimage.scanLine(0), image, width * height * 4);
1764 emit frameUpdated(qimage.rgbSwapped());
1767 void Render::emitFrameNumber()
1769 int currentPos = m_mltConsumer->position();
1770 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1771 emit rendererPosition(currentPos);
1772 if (requestedSeekPosition != SEEK_INACTIVE) {
1773 m_mltConsumer->purge();
1774 m_mltProducer->seek(requestedSeekPosition);
1775 if (m_mltProducer->get_speed() == 0) m_mltConsumer->set("refresh", 1);
1776 requestedSeekPosition = SEEK_INACTIVE;
1780 void Render::emitConsumerStopped(bool forcePause)
1782 // This is used to know when the playing stopped
1783 if (m_mltProducer && (forcePause || (!m_paused && m_mltProducer->get_speed() == 0))) {
1784 double pos = m_mltProducer->position();
1786 if (m_isLoopMode) play(m_loopStart);
1787 //else if (m_isZoneMode) resetZoneMode();
1788 emit rendererStopped((int) pos);
1792 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1794 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1797 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1799 if (!m_mltProducer) {
1800 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1804 //int height = 1080;//KdenliveSettings::defaultheight();
1805 //int width = 1940; //KdenliveSettings::displaywidth();
1807 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1809 QPixmap pix(width, height);
1810 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1811 m_convert.set("forced", mlt_image_rgb24a);
1812 m_mltProducer->attach(m_convert);
1813 Mlt::Frame * frame = m_mltProducer->get_frame();
1814 m_mltProducer->detach(m_convert);
1816 pix = frameThumbnail(frame, width, height);
1819 pix.save(url.path(), "PNG");
1820 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1824 void Render::showFrame(Mlt::Frame* frame)
1826 int currentPos = m_mltConsumer->position();
1827 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1828 emit rendererPosition(currentPos);
1829 if (frame->is_valid()) {
1830 mlt_image_format format = mlt_image_rgb24a;
1833 const uchar* image = frame->get_image(format, width, height);
1834 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1835 memcpy(qimage.scanLine(0), image, width * height * 4);
1836 if (analyseAudio) showAudio(*frame);
1838 emit showImageSignal(qimage);
1839 if (sendFrameForAnalysis) {
1840 emit frameUpdated(qimage.rgbSwapped());
1842 } else delete frame;
1843 showFrameSemaphore.release();
1844 emit checkSeeking();
1847 void Render::slotCheckSeeking()
1849 if (requestedSeekPosition != SEEK_INACTIVE) {
1850 m_mltProducer->seek(requestedSeekPosition);
1854 requestedSeekPosition = SEEK_INACTIVE;
1858 void Render::disablePreview(bool disable)
1860 if (m_mltConsumer) {
1861 m_mltConsumer->stop();
1862 m_mltConsumer->set("preview_off", (int) disable);
1863 m_mltConsumer->set("refresh", 0);
1864 m_mltConsumer->start();
1868 void Render::showAudio(Mlt::Frame& frame)
1870 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1874 mlt_audio_format audio_format = mlt_audio_s16;
1875 //FIXME: should not be hardcoded..
1877 int num_channels = 2;
1879 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1885 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1886 // So the vector is of size samples*channels.
1887 QVector<int16_t> sampleVector(samples*num_channels);
1888 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1891 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1896 * MLT playlist direct manipulation.
1899 void Render::mltCheckLength(Mlt::Tractor *tractor)
1901 //kDebug()<<"checking track length: "<<track<<"..........";
1903 int trackNb = tractor->count();
1906 if (m_isZoneMode) resetZoneMode();
1908 Mlt::Producer trackProducer(tractor->track(0));
1909 duration = trackProducer.get_playtime() - 1;
1910 m_mltProducer->set("out", duration);
1911 emit durationChanged(duration);
1914 while (trackNb > 1) {
1915 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1916 trackDuration = trackProducer.get_playtime() - 1;
1917 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1918 if (trackDuration > duration) duration = trackDuration;
1922 Mlt::Producer blackTrackProducer(tractor->track(0));
1924 if (blackTrackProducer.get_playtime() - 1 != duration) {
1925 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1926 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1927 if (blackclip && blackclip->is_blank()) {
1932 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1933 if (blackclip) delete blackclip;
1934 blackTrackPlaylist.clear();
1935 m_blackClip->set("length", duration + 1);
1936 m_blackClip->set("out", duration);
1937 blackclip = m_blackClip->cut(0, duration);
1938 blackTrackPlaylist.insert_at(0, blackclip, 1);
1940 if (duration > blackclip->parent().get_length()) {
1941 blackclip->parent().set("length", duration + 1);
1942 blackclip->parent().set("out", duration);
1943 blackclip->set("length", duration + 1);
1945 blackTrackPlaylist.resize_clip(0, 0, duration);
1949 if (m_mltConsumer->position() > duration) {
1950 m_mltConsumer->purge();
1951 m_mltProducer->seek(duration);
1953 m_mltProducer->set("out", duration);
1954 emit durationChanged(duration);
1958 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1960 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1962 // We want a slowmotion producer
1963 double speed = element.attribute("speed", "1.0").toDouble();
1964 int strobe = element.attribute("strobe", "1").toInt();
1965 QString url = QString::fromUtf8(prod->get("resource"));
1966 url.append('?' + locale.toString(speed));
1967 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1968 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1969 if (!slowprod || slowprod->get_producer() == NULL) {
1970 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
1971 if (strobe > 1) slowprod->set("strobe", strobe);
1972 QString id = prod->parent().get("id");
1973 if (id.contains('_')) id = id.section('_', 0, 0);
1974 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
1975 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1976 slowprod->set("id", producerid.toUtf8().constData());
1977 m_slowmotionProducers.insert(url, slowprod);
1982 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1984 m_refreshTimer.stop();
1985 if (m_mltProducer == NULL) {
1986 kDebug() << "PLAYLIST NOT INITIALISED //////";
1990 kDebug() << "Cannot insert clip without producer //////";
1993 Mlt::Producer parentProd(m_mltProducer->parent());
1994 if (parentProd.get_producer() == NULL) {
1995 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1999 Mlt::Service service(parentProd.get_service());
2000 if (service.type() != tractor_type) {
2001 kWarning() << "// TRACTOR PROBLEM";
2004 Mlt::Tractor tractor(service);
2005 if (info.track > tractor.count() - 1) {
2006 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
2010 Mlt::Producer trackProducer(tractor.track(info.track));
2011 int trackDuration = trackProducer.get_playtime() - 1;
2012 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2013 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
2014 prod = checkSlowMotionProducer(prod, element);
2015 if (prod == NULL || !prod->is_valid()) {
2020 int cutPos = (int) info.cropStart.frames(m_fps);
2021 if (cutPos < 0) cutPos = 0;
2022 int insertPos = (int) info.startPos.frames(m_fps);
2023 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
2024 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
2025 if (overwrite && (insertPos < trackDuration)) {
2026 // Replace zone with blanks
2027 //trackPlaylist.split_at(insertPos, true);
2028 trackPlaylist.remove_region(insertPos, cutDuration + 1);
2029 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2030 trackPlaylist.insert_blank(clipIndex, cutDuration);
2032 trackPlaylist.split_at(insertPos, true);
2033 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2034 trackPlaylist.insert_blank(clipIndex, cutDuration);
2036 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
2038 /*if (QString(prod->get("transparency")).toInt() == 1)
2039 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
2041 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
2043 /*tractor.multitrack()->refresh();
2044 tractor.refresh();*/
2049 bool Render::mltCutClip(int track, GenTime position)
2051 Mlt::Service service(m_mltProducer->parent().get_service());
2052 if (service.type() != tractor_type) {
2053 kWarning() << "// TRACTOR PROBLEM";
2057 Mlt::Tractor tractor(service);
2058 Mlt::Producer trackProducer(tractor.track(track));
2059 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2062 /* // Display playlist info
2063 kDebug()<<"//////////// BEFORE";
2064 for (int i = 0; i < trackPlaylist.count(); i++) {
2065 int blankStart = trackPlaylist.clip_start(i);
2066 int blankDuration = trackPlaylist.clip_length(i) - 1;
2068 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2069 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2072 int cutPos = (int) position.frames(m_fps);
2074 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
2075 if (trackPlaylist.is_blank(clipIndex)) {
2076 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
2080 int clipStart = trackPlaylist.clip_start(clipIndex);
2081 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
2084 // duplicate effects
2085 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
2086 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
2088 if (original == NULL || clip == NULL) {
2089 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
2093 Mlt::Service clipService(original->get_service());
2094 Mlt::Service dupService(clip->get_service());
2100 Mlt::Filter *filter = clipService.filter(ct);
2102 // Only duplicate Kdenlive filters, and skip the fade in effects
2103 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
2104 // looks like there is no easy way to duplicate a filter,
2105 // so we will create a new one and duplicate its properties
2106 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
2107 if (dup && dup->is_valid()) {
2108 Mlt::Properties entries(filter->get_properties());
2109 for (int i = 0; i < entries.count(); i++) {
2110 dup->set(entries.get_name(i), entries.get(i));
2112 dupService.attach(*dup);
2116 filter = clipService.filter(ct);
2119 /* // Display playlist info
2120 kDebug()<<"//////////// AFTER";
2121 for (int i = 0; i < trackPlaylist.count(); i++) {
2122 int blankStart = trackPlaylist.clip_start(i);
2123 int blankDuration = trackPlaylist.clip_length(i) - 1;
2125 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2126 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2131 Mlt::Tractor *Render::lockService()
2133 // we are going to replace some clips, purge consumer
2134 if (!m_mltProducer) return NULL;
2135 QMutexLocker locker(&m_mutex);
2136 if (m_mltConsumer) {
2137 m_mltConsumer->purge();
2139 Mlt::Service service(m_mltProducer->parent().get_service());
2140 if (service.type() != tractor_type) {
2144 return new Mlt::Tractor(service);
2148 void Render::unlockService(Mlt::Tractor *tractor)
2153 if (!m_mltProducer) return;
2154 Mlt::Service service(m_mltProducer->parent().get_service());
2155 if (service.type() != tractor_type) {
2156 kWarning() << "// TRACTOR PROBLEM";
2162 bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement element, Mlt::Producer *prod)
2165 if (prod == NULL || tractor == NULL) {
2166 kDebug() << "Cannot update clip with null producer //////";
2170 Mlt::Producer trackProducer(tractor->track(tractor->count() - 1 - info.track));
2171 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2172 int startPos = info.startPos.frames(m_fps);
2173 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2174 if (trackPlaylist.is_blank(clipIndex)) {
2175 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
2178 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2180 QList <Mlt::Filter *> filtersList;
2181 Mlt::Service sourceService(clip->get_service());
2183 Mlt::Filter *filter = sourceService.filter(ct);
2185 if (filter->get_int("kdenlive_ix") != 0) {
2186 filtersList.append(filter);
2189 filter = sourceService.filter(ct);
2192 clip = trackPlaylist.replace_with_blank(clipIndex);
2194 prod = checkSlowMotionProducer(prod, element);
2195 if (prod == NULL || !prod->is_valid()) {
2199 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
2200 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
2201 Mlt::Service destService(clip2->get_service());
2204 if (!filtersList.isEmpty()) {
2205 for (int i = 0; i < filtersList.count(); i++)
2206 destService.attach(*(filtersList.at(i)));
2212 bool Render::mltRemoveClip(int track, GenTime position)
2214 m_refreshTimer.stop();
2215 Mlt::Service service(m_mltProducer->parent().get_service());
2216 if (service.type() != tractor_type) {
2217 kWarning() << "// TRACTOR PROBLEM";
2221 Mlt::Tractor tractor(service);
2222 Mlt::Producer trackProducer(tractor.track(track));
2223 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2224 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2226 if (trackPlaylist.is_blank(clipIndex)) {
2227 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
2231 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2232 if (clip) delete clip;
2233 trackPlaylist.consolidate_blanks(0);
2235 /* // Display playlist info
2236 kDebug()<<"//// AFTER";
2237 for (int i = 0; i < trackPlaylist.count(); i++) {
2238 int blankStart = trackPlaylist.clip_start(i);
2239 int blankDuration = trackPlaylist.clip_length(i) - 1;
2241 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2242 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2245 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
2249 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
2251 if (!m_mltProducer) {
2252 kDebug() << "PLAYLIST NOT INITIALISED //////";
2255 Mlt::Producer parentProd(m_mltProducer->parent());
2256 if (parentProd.get_producer() == NULL) {
2257 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2261 Mlt::Service service(parentProd.get_service());
2262 Mlt::Tractor tractor(service);
2263 int insertPos = pos.frames(m_fps);
2265 Mlt::Producer trackProducer(tractor.track(track));
2266 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2267 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2268 if (clipIndex == trackPlaylist.count()) {
2269 // We are after the end of the playlist
2272 if (!trackPlaylist.is_blank(clipIndex)) return 0;
2273 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
2274 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
2277 int Render::mltTrackDuration(int track)
2279 if (!m_mltProducer) {
2280 kDebug() << "PLAYLIST NOT INITIALISED //////";
2283 Mlt::Producer parentProd(m_mltProducer->parent());
2284 if (parentProd.get_producer() == NULL) {
2285 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2289 Mlt::Service service(parentProd.get_service());
2290 Mlt::Tractor tractor(service);
2292 Mlt::Producer trackProducer(tractor.track(track));
2293 return trackProducer.get_playtime() - 1;
2296 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
2298 if (!m_mltProducer) {
2299 kDebug() << "PLAYLIST NOT INITIALISED //////";
2302 Mlt::Producer parentProd(m_mltProducer->parent());
2303 if (parentProd.get_producer() == NULL) {
2304 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2307 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
2308 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
2310 Mlt::Service service(parentProd.get_service());
2311 Mlt::Tractor tractor(service);
2313 int diff = duration.frames(m_fps);
2314 int offset = timeOffset.frames(m_fps);
2318 // insert space in one track only
2319 Mlt::Producer trackProducer(tractor.track(track));
2320 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2321 insertPos = trackClipStartList.value(track);
2322 if (insertPos != -1) {
2323 insertPos += offset;
2324 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2326 trackPlaylist.insert_blank(clipIndex, diff - 1);
2328 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
2329 if (!trackPlaylist.is_blank(clipIndex)) {
2330 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2332 int position = trackPlaylist.clip_start(clipIndex);
2333 int blankDuration = trackPlaylist.clip_length(clipIndex);
2334 if (blankDuration + diff == 0) {
2335 trackPlaylist.remove(clipIndex);
2336 } else trackPlaylist.remove_region(position, -diff);
2338 trackPlaylist.consolidate_blanks(0);
2340 // now move transitions
2341 mlt_service serv = m_mltProducer->parent().get_service();
2342 mlt_service nextservice = mlt_service_get_producer(serv);
2343 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2344 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2345 QString resource = mlt_properties_get(properties, "mlt_service");
2347 while (mlt_type == "transition") {
2348 mlt_transition tr = (mlt_transition) nextservice;
2349 int currentTrack = mlt_transition_get_b_track(tr);
2350 int currentIn = (int) mlt_transition_get_in(tr);
2351 int currentOut = (int) mlt_transition_get_out(tr);
2352 insertPos = trackTransitionStartList.value(track);
2353 if (insertPos != -1) {
2354 insertPos += offset;
2355 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
2356 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2359 nextservice = mlt_service_producer(nextservice);
2360 if (nextservice == NULL) break;
2361 properties = MLT_SERVICE_PROPERTIES(nextservice);
2362 mlt_type = mlt_properties_get(properties, "mlt_type");
2363 resource = mlt_properties_get(properties, "mlt_service");
2366 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
2367 Mlt::Producer trackProducer(tractor.track(trackNb));
2368 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2370 //int clipNb = trackPlaylist.count();
2371 insertPos = trackClipStartList.value(trackNb);
2372 if (insertPos != -1) {
2373 insertPos += offset;
2375 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2376 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2377 for (int i = 0; i < clipNb; i++) {
2378 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2379 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2380 kDebug()<<"-------------";
2382 kDebug()<<"END-------------";*/
2385 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2387 trackPlaylist.insert_blank(clipIndex, diff - 1);
2389 if (!trackPlaylist.is_blank(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 (diff + blankDuration == 0) {
2398 trackPlaylist.remove(clipIndex);
2399 } else trackPlaylist.remove_region(position, - diff);
2401 trackPlaylist.consolidate_blanks(0);
2404 // now move transitions
2405 mlt_service serv = m_mltProducer->parent().get_service();
2406 mlt_service nextservice = mlt_service_get_producer(serv);
2407 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2408 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2409 QString resource = mlt_properties_get(properties, "mlt_service");
2411 while (mlt_type == "transition") {
2412 mlt_transition tr = (mlt_transition) nextservice;
2413 int currentIn = (int) mlt_transition_get_in(tr);
2414 int currentOut = (int) mlt_transition_get_out(tr);
2415 int currentTrack = mlt_transition_get_b_track(tr);
2416 insertPos = trackTransitionStartList.value(currentTrack);
2417 if (insertPos != -1) {
2418 insertPos += offset;
2419 if (currentOut > insertPos && resource != "mix") {
2420 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2423 nextservice = mlt_service_producer(nextservice);
2424 if (nextservice == NULL) break;
2425 properties = MLT_SERVICE_PROPERTIES(nextservice);
2426 mlt_type = mlt_properties_get(properties, "mlt_type");
2427 resource = mlt_properties_get(properties, "mlt_service");
2431 mltCheckLength(&tractor);
2432 m_mltConsumer->set("refresh", 1);
2436 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2438 if (source == dest) return;
2439 Mlt::Service sourceService(source->get_service());
2440 Mlt::Service destService(dest->get_service());
2442 // move all effects to the correct producer
2444 Mlt::Filter *filter = sourceService.filter(ct);
2446 if (filter->get_int("kdenlive_ix") != 0) {
2447 sourceService.detach(*filter);
2448 destService.attach(*filter);
2450 filter = sourceService.filter(ct);
2454 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2457 Mlt::Service service(m_mltProducer->parent().get_service());
2458 if (service.type() != tractor_type) {
2459 kWarning() << "// TRACTOR PROBLEM";
2463 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2464 Mlt::Tractor tractor(service);
2465 Mlt::Producer trackProducer(tractor.track(info.track));
2466 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2467 int startPos = info.startPos.frames(m_fps);
2468 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2469 int clipLength = trackPlaylist.clip_length(clipIndex);
2471 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2472 if (original == NULL) {
2475 if (!original->is_valid() || original->is_blank()) {
2480 Mlt::Producer clipparent = original->parent();
2481 if (!clipparent.is_valid() || clipparent.is_blank()) {
2487 QString serv = clipparent.get("mlt_service");
2488 QString id = clipparent.get("id");
2489 if (speed <= 0 && speed > -1) speed = 1.0;
2490 //kDebug() << "CLIP SERVICE: " << serv;
2491 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2493 QString url = QString::fromUtf8(clipparent.get("resource"));
2494 url.append('?' + m_locale.toString(speed));
2495 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2496 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2497 if (!slowprod || slowprod->get_producer() == NULL) {
2498 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2499 if (strobe > 1) slowprod->set("strobe", strobe);
2500 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2501 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2502 slowprod->set("id", producerid.toUtf8().constData());
2503 // copy producer props
2504 double ar = original->parent().get_double("force_aspect_ratio");
2505 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2506 double fps = original->parent().get_double("force_fps");
2507 if (fps != 0.0) slowprod->set("force_fps", fps);
2508 int threads = original->parent().get_int("threads");
2509 if (threads != 0) slowprod->set("threads", threads);
2510 if (original->parent().get("force_progressive"))
2511 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2512 if (original->parent().get("force_tff"))
2513 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2514 int ix = original->parent().get_int("video_index");
2515 if (ix != 0) slowprod->set("video_index", ix);
2516 int colorspace = original->parent().get_int("force_colorspace");
2517 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2518 int full_luma = original->parent().get_int("set.force_full_luma");
2519 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2520 m_slowmotionProducers.insert(url, slowprod);
2522 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2523 trackPlaylist.consolidate_blanks(0);
2525 // Check that the blank space is long enough for our new duration
2526 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2527 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2529 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2530 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2531 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2532 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2534 // move all effects to the correct producer
2535 mltPasteEffects(clip, cut);
2536 trackPlaylist.insert_at(startPos, cut, 1);
2539 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2540 newLength = trackPlaylist.clip_length(clipIndex);
2542 } else if (speed == 1.0 && strobe < 2) {
2545 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2546 trackPlaylist.consolidate_blanks(0);
2548 // Check that the blank space is long enough for our new duration
2549 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2550 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2553 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2554 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2555 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2556 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2557 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2559 // move all effects to the correct producer
2560 mltPasteEffects(clip, cut);
2562 trackPlaylist.insert_at(startPos, cut, 1);
2565 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2566 newLength = trackPlaylist.clip_length(clipIndex);
2569 } else if (serv == "framebuffer") {
2571 QString url = QString::fromUtf8(clipparent.get("resource"));
2572 url = url.section('?', 0, 0);
2573 url.append('?' + m_locale.toString(speed));
2574 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2575 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2576 if (!slowprod || slowprod->get_producer() == NULL) {
2577 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2578 slowprod->set("strobe", strobe);
2579 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2580 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2581 slowprod->set("id", producerid.toUtf8().constData());
2582 // copy producer props
2583 double ar = original->parent().get_double("force_aspect_ratio");
2584 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2585 double fps = original->parent().get_double("force_fps");
2586 if (fps != 0.0) slowprod->set("force_fps", fps);
2587 if (original->parent().get("force_progressive"))
2588 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2589 if (original->parent().get("force_tff"))
2590 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2591 int threads = original->parent().get_int("threads");
2592 if (threads != 0) slowprod->set("threads", threads);
2593 int ix = original->parent().get_int("video_index");
2594 if (ix != 0) slowprod->set("video_index", ix);
2595 int colorspace = original->parent().get_int("force_colorspace");
2596 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2597 int full_luma = original->parent().get_int("set.force_full_luma");
2598 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2599 m_slowmotionProducers.insert(url, slowprod);
2601 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2602 trackPlaylist.consolidate_blanks(0);
2604 GenTime duration = speedIndependantInfo.cropDuration / speed;
2605 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2607 // Check that the blank space is long enough for our new duration
2608 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2609 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2612 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2613 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2614 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2615 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2617 // move all effects to the correct producer
2618 mltPasteEffects(clip, cut);
2620 trackPlaylist.insert_at(startPos, cut, 1);
2623 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2624 newLength = trackPlaylist.clip_length(clipIndex);
2629 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2633 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2635 Mlt::Service service(m_mltProducer->parent().get_service());
2636 bool success = false;
2637 Mlt::Tractor tractor(service);
2638 Mlt::Producer trackProducer(tractor.track(track));
2639 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2640 Mlt::Service clipService(trackPlaylist.get_service());
2644 Mlt::Filter *filter = clipService.filter(ct);
2646 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2647 if (clipService.detach(*filter) == 0) success = true;
2648 } else if (updateIndex) {
2649 // Adjust the other effects index
2650 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2653 filter = clipService.filter(ct);
2660 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2662 if (position < GenTime()) {
2663 // Remove track effect
2664 return mltRemoveTrackEffect(track, index, updateIndex);
2666 Mlt::Service service(m_mltProducer->parent().get_service());
2667 bool success = false;
2668 Mlt::Tractor tractor(service);
2669 Mlt::Producer trackProducer(tractor.track(track));
2670 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2672 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2673 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2675 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2679 Mlt::Service clipService(clip->get_service());
2680 int duration = clip->get_playtime();
2682 // Check if clip is visible in monitor
2683 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2684 if (diff < 0 || diff > duration) doRefresh = false;
2690 Mlt::Filter *filter = clipService.filter(ct);
2692 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2693 if (clipService.detach(*filter) == 0) success = true;
2694 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2695 } else if (updateIndex) {
2696 // Adjust the other effects index
2697 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2700 filter = clipService.filter(ct);
2703 if (doRefresh) refresh();
2707 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2709 Mlt::Service service(m_mltProducer->parent().get_service());
2710 Mlt::Tractor tractor(service);
2711 Mlt::Producer trackProducer(tractor.track(track));
2712 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2713 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2714 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2718 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2721 Mlt::Service service(m_mltProducer->parent().get_service());
2723 Mlt::Tractor tractor(service);
2724 Mlt::Producer trackProducer(tractor.track(track));
2725 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2727 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2728 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2733 Mlt::Service clipService(clip->get_service());
2734 int duration = clip->get_playtime();
2736 // Check if clip is visible in monitor
2737 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2738 if (diff < 0 || diff > duration) doRefresh = false;
2741 return mltAddEffect(clipService, params, duration, doRefresh);
2744 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2746 bool updateIndex = false;
2747 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2751 Mlt::Filter *filter = service.filter(ct);
2753 if (filter->get_int("kdenlive_ix") == filter_ix) {
2754 // A filter at that position already existed, so we will increase all indexes later
2759 filter = service.filter(ct);
2762 if (params.paramValue("id") == "speed") {
2763 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2765 filter = service.filter(ct);
2767 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2768 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2771 filter = service.filter(ct);
2774 if (doRefresh) refresh();
2779 // temporarily remove all effects after insert point
2780 QList <Mlt::Filter *> filtersList;
2782 filter = service.filter(ct);
2784 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2785 filtersList.append(filter);
2786 service.detach(*filter);
2788 filter = service.filter(ct);
2791 addFilterToService(service, params, duration);
2793 // re-add following filters
2794 for (int i = 0; i < filtersList.count(); i++) {
2795 Mlt::Filter *filter = filtersList.at(i);
2797 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2798 service.attach(*filter);
2801 if (doRefresh) refresh();
2806 bool Render::addFilterToService(Mlt::Service service, EffectsParameterList params, int duration)
2809 QString tag = params.paramValue("tag");
2810 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2811 char *filterTag = qstrdup(tag.toUtf8().constData());
2812 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2813 QString kfr = params.paramValue("keyframes");
2814 if (!kfr.isEmpty()) {
2815 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2816 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2817 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2818 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2819 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2820 //double max = params.paramValue("max").toDouble();
2821 double min = params.paramValue("min").toDouble();
2822 double factor = params.paramValue("factor", "1").toDouble();
2823 double paramOffset = params.paramValue("offset", "0").toDouble();
2824 params.removeParam("starttag");
2825 params.removeParam("endtag");
2826 params.removeParam("keyframes");
2827 params.removeParam("min");
2828 params.removeParam("max");
2829 params.removeParam("factor");
2830 params.removeParam("offset");
2832 // Special case, only one keyframe, means we want a constant value
2833 if (keyFrames.count() == 1) {
2834 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2835 if (filter && filter->is_valid()) {
2836 filter->set("kdenlive_id", filterId);
2837 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2838 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2839 for (int j = 0; j < params.count(); j++) {
2840 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2842 filter->set("in", x1);
2843 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2844 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2845 service.attach(*filter);
2847 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2848 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2849 if (filter && filter->is_valid()) {
2850 filter->set("kdenlive_id", filterId);
2851 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2852 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2853 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2854 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2855 if (x2 == -1) x2 = duration;
2857 for (int j = 0; j < params.count(); j++) {
2858 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2861 filter->set("in", x1);
2862 filter->set("out", x2);
2863 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2864 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2865 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2866 service.attach(*filter);
2873 Mlt::Filter *filter;
2875 filter = new Mlt::Filter(*m_mltProfile, filterTag);
2876 if (filter && filter->is_valid()) {
2877 filter->set("kdenlive_id", filterId);
2879 kDebug() << "filter is NULL";
2883 params.removeParam("kdenlive_id");
2884 if (params.hasParam("_sync_in_out")) {
2885 // This effect must sync in / out with parent clip
2886 params.removeParam("_sync_in_out");
2887 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2890 for (int j = 0; j < params.count(); j++) {
2891 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2895 QString effectArgs = params.paramValue("id").section('_', 1);
2897 params.removeParam("id");
2898 params.removeParam("kdenlive_ix");
2899 params.removeParam("tag");
2900 params.removeParam("disable");
2901 params.removeParam("region");
2903 for (int j = 0; j < params.count(); j++) {
2904 effectArgs.append(' ' + params.at(j).value());
2906 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2907 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2909 // attach filter to the clip
2910 service.attach(*filter);
2918 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2920 Mlt::Service service(m_mltProducer->parent().get_service());
2921 Mlt::Tractor tractor(service);
2922 Mlt::Producer trackProducer(tractor.track(track));
2923 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2924 Mlt::Service clipService(trackPlaylist.get_service());
2926 QString index = params.paramValue("kdenlive_ix");
2927 QString tag = params.paramValue("tag");
2929 Mlt::Filter *filter = clipService.filter(ct);
2931 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2935 filter = clipService.filter(ct);
2939 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2940 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2942 bool success = false;//mltAddTrackEffect(track, params);
2946 QString ser = filter->get("mlt_service");
2947 if (ser == "region") prefix = "filter0.";
2949 for (int j = 0; j < params.count(); j++) {
2950 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2958 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2960 int index = params.paramValue("kdenlive_ix").toInt();
2961 QString tag = params.paramValue("tag");
2963 if (!params.paramValue("keyframes").isEmpty() || (tag == "affine" && params.hasParam("background")) || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2964 // This is a keyframe effect, to edit it, we remove it and re-add it.
2965 bool success = mltRemoveEffect(track, position, index, false);
2966 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
2967 if (position < GenTime())
2968 success = mltAddTrackEffect(track, params);
2970 success = mltAddEffect(track, position, params);
2971 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
2974 if (position < GenTime()) {
2975 return mltEditTrackEffect(track, params);
2978 Mlt::Service service(m_mltProducer->parent().get_service());
2979 Mlt::Tractor tractor(service);
2980 Mlt::Producer trackProducer(tractor.track(track));
2981 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2983 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2984 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2986 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2990 int duration = clip->get_playtime();
2991 bool doRefresh = true;
2992 // Check if clip is visible in monitor
2993 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2994 if (diff < 0 || diff > duration)
2998 Mlt::Filter *filter = clip->filter(ct);
3000 if (filter->get_int("kdenlive_ix") == index) {
3004 filter = clip->filter(ct);
3008 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
3009 // filter was not found, it was probably a disabled filter, so add it to the correct place...
3011 bool success = mltAddEffect(track, position, params);
3015 QString ser = filter->get("mlt_service");
3016 QList <Mlt::Filter *> filtersList;
3019 // Effect service changes, delete effect and re-add it
3020 clip->detach(*filter);
3022 // Delete all effects after deleted one
3023 filter = clip->filter(ct);
3025 if (filter->get_int("kdenlive_ix") > index) {
3026 filtersList.append(filter);
3027 clip->detach(*filter);
3030 filter = clip->filter(ct);
3034 addFilterToService(*clip, params, clip->get_playtime());
3038 if (doRefresh) refresh();
3041 if (params.hasParam("_sync_in_out")) {
3042 // This effect must sync in / out with parent clip
3043 params.removeParam("_sync_in_out");
3044 filter->set_in_and_out(clip->get_in(), clip->get_out());
3047 for (int j = 0; j < params.count(); j++) {
3048 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
3051 for (int j = 0; j < filtersList.count(); j++) {
3052 clip->attach(*(filtersList.at(j)));
3058 if (doRefresh) refresh();
3062 bool Render::mltEnableEffects(int track, GenTime position, QList <int> effectIndexes, bool disable)
3064 if (position < GenTime()) {
3065 return mltEnableTrackEffects(track, effectIndexes, disable);
3068 Mlt::Service service(m_mltProducer->parent().get_service());
3069 Mlt::Tractor tractor(service);
3070 Mlt::Producer trackProducer(tractor.track(track));
3071 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3073 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3074 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3076 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3080 int duration = clip->get_playtime();
3081 bool doRefresh = true;
3082 // Check if clip is visible in monitor
3083 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3084 if (diff < 0 || diff > duration)
3088 Mlt::Filter *filter = clip->filter(ct);
3090 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3091 filter->set("disable", (int) disable);
3094 filter = clip->filter(ct);
3100 if (doRefresh) refresh();
3104 bool Render::mltEnableTrackEffects(int track, QList <int> effectIndexes, bool disable)
3106 Mlt::Service service(m_mltProducer->parent().get_service());
3107 Mlt::Tractor tractor(service);
3108 Mlt::Producer trackProducer(tractor.track(track));
3109 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3110 Mlt::Service clipService(trackPlaylist.get_service());
3113 Mlt::Filter *filter = clipService.filter(ct);
3115 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3116 filter->set("disable", (int) disable);
3119 filter = clipService.filter(ct);
3127 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
3129 Mlt::Service service(m_mltProducer->parent().get_service());
3130 Mlt::Tractor tractor(service);
3131 Mlt::Producer trackProducer(tractor.track(track));
3132 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3134 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3135 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3137 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3141 Mlt::Service clipService(clip->get_service());
3142 int duration = clip->get_playtime();
3143 bool doRefresh = true;
3144 // Check if clip is visible in monitor
3145 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3146 if (diff < 0 || diff > duration) doRefresh = false;
3150 Mlt::Filter *filter = clipService.filter(ct);
3152 int pos = filter->get_int("kdenlive_ix");
3153 if (pos == oldPos) {
3154 filter->set("kdenlive_ix", newPos);
3156 filter = clipService.filter(ct);
3158 if (doRefresh) refresh();
3161 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
3163 if (position < GenTime()) {
3164 mltMoveTrackEffect(track, oldPos, newPos);
3167 Mlt::Service service(m_mltProducer->parent().get_service());
3168 Mlt::Tractor tractor(service);
3169 Mlt::Producer trackProducer(tractor.track(track));
3170 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3172 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3173 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3175 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3179 Mlt::Service clipService(clip->get_service());
3180 int duration = clip->get_playtime();
3181 bool doRefresh = true;
3182 // Check if clip is visible in monitor
3183 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3184 if (diff < 0 || diff > duration) doRefresh = false;
3188 QList <Mlt::Filter *> filtersList;
3189 Mlt::Filter *filter = clipService.filter(ct);
3191 if (newPos > oldPos) {
3193 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3194 filter->set("kdenlive_ix", newPos);
3195 filtersList.append(filter);
3196 clipService.detach(*filter);
3197 filter = clipService.filter(ct);
3198 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3199 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3201 filter = clipService.filter(ct);
3205 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3206 filtersList.append(filter);
3207 clipService.detach(*filter);
3209 filter = clipService.filter(ct);
3213 if (filter->get_int("kdenlive_ix") == oldPos) {
3214 filter->set("kdenlive_ix", newPos);
3215 filtersList.append(filter);
3216 clipService.detach(*filter);
3218 filter = clipService.filter(ct);
3222 filter = clipService.filter(ct);
3224 int pos = filter->get_int("kdenlive_ix");
3225 if (pos >= newPos) {
3226 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3227 filtersList.append(filter);
3228 clipService.detach(*filter);
3230 filter = clipService.filter(ct);
3234 for (int i = 0; i < filtersList.count(); i++) {
3235 clipService.attach(*(filtersList.at(i)));
3238 if (doRefresh) refresh();
3241 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
3243 Mlt::Service service(m_mltProducer->parent().get_service());
3244 Mlt::Tractor tractor(service);
3245 Mlt::Producer trackProducer(tractor.track(track));
3246 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3247 Mlt::Service clipService(trackPlaylist.get_service());
3249 QList <Mlt::Filter *> filtersList;
3250 Mlt::Filter *filter = clipService.filter(ct);
3252 if (newPos > oldPos) {
3254 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3255 filter->set("kdenlive_ix", newPos);
3256 filtersList.append(filter);
3257 clipService.detach(*filter);
3258 filter = clipService.filter(ct);
3259 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3260 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3262 filter = clipService.filter(ct);
3266 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3267 filtersList.append(filter);
3268 clipService.detach(*filter);
3270 filter = clipService.filter(ct);
3274 if (filter->get_int("kdenlive_ix") == oldPos) {
3275 filter->set("kdenlive_ix", newPos);
3276 filtersList.append(filter);
3277 clipService.detach(*filter);
3279 filter = clipService.filter(ct);
3283 filter = clipService.filter(ct);
3285 int pos = filter->get_int("kdenlive_ix");
3286 if (pos >= newPos) {
3287 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3288 filtersList.append(filter);
3289 clipService.detach(*filter);
3291 filter = clipService.filter(ct);
3295 for (int i = 0; i < filtersList.count(); i++) {
3296 clipService.attach(*(filtersList.at(i)));
3301 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration, bool refresh)
3303 Mlt::Service service(m_mltProducer->parent().get_service());
3304 Mlt::Tractor tractor(service);
3305 Mlt::Producer trackProducer(tractor.track(info.track));
3306 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3308 /* // Display playlist info
3309 kDebug()<<"//////////// BEFORE RESIZE";
3310 for (int i = 0; i < trackPlaylist.count(); i++) {
3311 int blankStart = trackPlaylist.clip_start(i);
3312 int blankDuration = trackPlaylist.clip_length(i) - 1;
3314 if (trackPlaylist.is_blank(i)) blk = "(blank)";
3315 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
3318 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
3319 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3323 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
3324 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
3325 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3327 int previousStart = clip->get_in();
3328 int newDuration = (int) clipDuration.frames(m_fps) - 1;
3329 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
3331 int currentOut = newDuration + previousStart;
3332 if (currentOut > clip->get_length()) {
3333 clip->parent().set("length", currentOut + 1);
3334 clip->parent().set("out", currentOut);
3335 clip->set("length", currentOut + 1);
3338 /*if (newDuration > clip->get_out()) {
3339 clip->parent().set_in_and_out(0, newDuration + 1);
3340 clip->set_in_and_out(0, newDuration + 1);
3343 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
3344 trackPlaylist.consolidate_blanks(0);
3345 // skip to next clip
3347 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
3349 // clip was made longer, trim next blank if there is one.
3350 if (clipIndex < trackPlaylist.count()) {
3351 // If this is not the last clip in playlist
3352 if (trackPlaylist.is_blank(clipIndex)) {
3353 int blankStart = trackPlaylist.clip_start(clipIndex);
3354 int blankDuration = trackPlaylist.clip_length(clipIndex);
3355 if (diff > blankDuration) {
3356 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
3358 if (diff - blankDuration == 0) {
3359 trackPlaylist.remove(clipIndex);
3360 } else trackPlaylist.remove_region(blankStart, diff);
3362 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
3365 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
3366 trackPlaylist.consolidate_blanks(0);
3369 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
3370 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3371 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
3372 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3373 ItemInfo transpinfo;
3374 transpinfo.startPos = info.startPos;
3375 transpinfo.endPos = info.startPos + clipDuration;
3376 transpinfo.track = info.track;
3377 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3379 if (refresh) m_mltConsumer->set("refresh", 1);
3383 void Render::mltChangeTrackState(int track, bool mute, bool blind)
3385 Mlt::Service service(m_mltProducer->parent().get_service());
3386 Mlt::Tractor tractor(service);
3387 Mlt::Producer trackProducer(tractor.track(track));
3389 // Make sure muting will not produce problems with our audio mixing transition,
3390 // because audio mixing is done between each track and the lowest one
3391 bool audioMixingBroken = false;
3392 if (mute && trackProducer.get_int("hide") < 2 ) {
3393 // We mute a track with sound
3394 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3395 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
3397 else if (!mute && trackProducer.get_int("hide") > 1 ) {
3398 // We un-mute a previously muted track
3399 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3403 if (blind) trackProducer.set("hide", 3);
3404 else trackProducer.set("hide", 2);
3406 trackProducer.set("hide", 1);
3408 trackProducer.set("hide", 0);
3410 if (audioMixingBroken) fixAudioMixing(tractor);
3412 tractor.multitrack()->refresh();
3417 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
3419 for (int i = 1; i < tractor.count(); i++) {
3420 Mlt::Producer trackProducer(tractor.track(i));
3421 if (trackProducer.get_int("hide") < 2) return i;
3423 return tractor.count() - 1;
3426 void Render::fixAudioMixing(Mlt::Tractor tractor)
3428 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
3429 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
3431 mlt_service serv = m_mltProducer->parent().get_service();
3432 Mlt::Field *field = tractor.field();
3433 mlt_service_lock(serv);
3435 mlt_service nextservice = mlt_service_get_producer(serv);
3436 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3437 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3438 QString resource = mlt_properties_get(properties, "mlt_service");
3440 mlt_service nextservicetodisconnect;
3441 // Delete all audio mixing transitions
3442 while (mlt_type == "transition") {
3443 if (resource == "mix") {
3444 nextservicetodisconnect = nextservice;
3445 nextservice = mlt_service_producer(nextservice);
3446 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
3448 else nextservice = mlt_service_producer(nextservice);
3449 if (nextservice == NULL) break;
3450 properties = MLT_SERVICE_PROPERTIES(nextservice);
3451 mlt_type = mlt_properties_get(properties, "mlt_type");
3452 resource = mlt_properties_get(properties, "mlt_service");
3455 // Re-add correct audio transitions
3456 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
3457 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3458 transition->set("always_active", 1);
3459 transition->set("combine", 1);
3460 transition->set("internal_added", 237);
3461 field->plant_transition(*transition, lowestTrack, i);
3463 mlt_service_unlock(serv);
3466 bool Render::mltResizeClipCrop(ItemInfo info, GenTime newCropStart)
3468 Mlt::Service service(m_mltProducer->parent().get_service());
3469 int newCropFrame = (int) newCropStart.frames(m_fps);
3470 Mlt::Tractor tractor(service);
3471 Mlt::Producer trackProducer(tractor.track(info.track));
3472 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3473 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3474 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3478 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3479 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3481 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3485 int previousStart = clip->get_in();
3486 int previousOut = clip->get_out();
3488 if (previousStart == newCropFrame) {
3489 kDebug() << "//////// No ReSIZING Required";
3493 int frameOffset = newCropFrame - previousStart;
3494 trackPlaylist.resize_clip(clipIndex, newCropFrame, previousOut + frameOffset);
3496 m_mltConsumer->set("refresh", 1);
3500 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3502 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3503 Mlt::Service service(m_mltProducer->parent().get_service());
3504 int moveFrame = (int) diff.frames(m_fps);
3505 Mlt::Tractor tractor(service);
3506 Mlt::Producer trackProducer(tractor.track(info.track));
3507 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3508 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3509 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3513 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3514 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3515 if (clip == NULL || clip->is_blank()) {
3516 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3520 int previousStart = clip->get_in();
3521 int previousOut = clip->get_out();
3523 previousStart += moveFrame;
3525 if (previousStart < 0) {
3526 // this is possible for images and color clips
3527 previousOut -= previousStart;
3531 int length = previousOut + 1;
3532 if (length > clip->get_length()) {
3533 clip->parent().set("length", length + 1);
3534 clip->parent().set("out", length);
3535 clip->set("length", length + 1);
3539 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3540 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3541 if (moveFrame > 0) {
3542 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3544 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3545 int blankIndex = clipIndex - 1;
3546 int blankLength = trackPlaylist.clip_length(blankIndex);
3547 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3548 if (! trackPlaylist.is_blank(blankIndex)) {
3549 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3551 if (blankLength + moveFrame == 0)
3552 trackPlaylist.remove(blankIndex);
3554 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3556 trackPlaylist.consolidate_blanks(0);
3557 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3558 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3559 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3560 ItemInfo transpinfo;
3561 transpinfo.startPos = info.startPos + diff;
3562 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3563 transpinfo.track = info.track;
3564 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3566 //m_mltConsumer->set("refresh", 1);
3568 m_mltConsumer->set("refresh", 1);
3572 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3574 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3578 bool Render::mltUpdateClipProducer(Mlt::Tractor *tractor, int track, int pos, Mlt::Producer *prod)
3580 if (prod == NULL || !prod->is_valid() || tractor == NULL || !tractor->is_valid()) {
3581 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3585 Mlt::Producer trackProducer(tractor->track(track));
3586 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3587 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3588 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3589 if (clipProducer == NULL || clipProducer->is_blank()) {
3590 kDebug() << "// ERROR UPDATING CLIP PROD";
3591 delete clipProducer;
3594 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3595 if (!clip || !clip->is_valid()) {
3596 if (clip) delete clip;
3597 delete clipProducer;
3600 // move all effects to the correct producer
3601 mltPasteEffects(clipProducer, clip);
3602 trackPlaylist.insert_at(pos, clip, 1);
3604 delete clipProducer;
3608 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3610 Mlt::Service service(m_mltProducer->parent().get_service());
3611 if (service.type() != tractor_type) {
3612 kWarning() << "// TRACTOR PROBLEM";
3616 Mlt::Tractor tractor(service);
3618 Mlt::Producer trackProducer(tractor.track(startTrack));
3619 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3620 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3621 int clipDuration = trackPlaylist.clip_length(clipIndex);
3622 bool checkLength = false;
3623 if (endTrack == startTrack) {
3624 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3626 bool success = true;
3627 if (!trackPlaylist.is_blank_at(moveEnd) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3631 // Check that the destination region is empty
3632 trackPlaylist.consolidate_blanks(0);
3633 int destinationIndex = trackPlaylist.get_clip_index_at(moveEnd);
3634 if (destinationIndex < trackPlaylist.count() - 1) {
3635 // We are not at the end of the track
3636 int blankSize = trackPlaylist.blanks_from(destinationIndex, 1);
3637 // Make sure we have enough place to insert clip
3638 if (blankSize - clipDuration - (moveEnd - trackPlaylist.clip_start(destinationIndex)) < 0) success = false;
3643 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3644 delete clipProducer;
3646 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3653 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3654 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3655 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3657 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3658 if (newIndex == -1) {
3659 kDebug()<<"// CANNOT MOVE CLIP TO: "<<moveEnd;
3660 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3661 delete clipProducer;
3665 trackPlaylist.consolidate_blanks(1);
3666 delete clipProducer;
3667 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3669 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3670 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3671 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3672 // error, destination is not empty
3673 kDebug() << "Cannot move: Destination is not empty";
3677 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3678 if (!clipProducer || clipProducer->is_blank()) {
3679 // error, destination is not empty
3680 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3681 if (clipProducer) delete clipProducer;
3682 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3686 trackPlaylist.consolidate_blanks(0);
3687 destTrackPlaylist.consolidate_blanks(1);
3688 Mlt::Producer *clip;
3689 // check if we are moving a slowmotion producer
3690 QString serv = clipProducer->parent().get("mlt_service");
3691 QString currentid = clipProducer->parent().get("id");
3692 if (serv == "framebuffer") {
3693 clip = clipProducer;
3696 // Special case: prod is null when using placeholder clips.
3697 // in that case, use the producer existing in playlist. Note that
3698 // it will bypass the one producer per track logic and might cause
3699 // Sound cracks if clip is moved so that it overlaps another copy of itself
3700 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3701 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3704 // move all effects to the correct producer
3705 mltPasteEffects(clipProducer, clip);
3708 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3709 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3710 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3713 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3715 if (clip == clipProducer) {
3720 delete clipProducer;
3722 destTrackPlaylist.consolidate_blanks(0);
3723 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3724 kDebug() << "//////// moving clip transparency";
3725 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3727 if (clipIndex > trackPlaylist.count()) checkLength = true;
3728 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3732 if (checkLength) mltCheckLength(&tractor);
3734 //m_mltConsumer->set("refresh", 1);
3739 QList <int> Render::checkTrackSequence(int track)
3742 Mlt::Service service(m_mltProducer->parent().get_service());
3743 if (service.type() != tractor_type) {
3744 kWarning() << "// TRACTOR PROBLEM";
3747 Mlt::Tractor tractor(service);
3749 Mlt::Producer trackProducer(tractor.track(track));
3750 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3751 int clipNb = trackPlaylist.count();
3752 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3753 for (int i = 0; i < clipNb; i++) {
3754 Mlt::Producer *c = trackPlaylist.get_clip(i);
3755 int pos = trackPlaylist.clip_start(i);
3756 if (!list.contains(pos)) list.append(pos);
3757 pos += c->get_playtime();
3758 if (!list.contains(pos)) list.append(pos);
3764 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3766 int new_in = (int)newIn.frames(m_fps);
3767 int new_out = (int)newOut.frames(m_fps) - 1;
3768 if (new_in >= new_out) return false;
3769 int old_in = (int)oldIn.frames(m_fps);
3770 int old_out = (int)oldOut.frames(m_fps) - 1;
3772 Mlt::Service service(m_mltProducer->parent().get_service());
3773 Mlt::Tractor tractor(service);
3774 Mlt::Field *field = tractor.field();
3776 bool doRefresh = true;
3777 // Check if clip is visible in monitor
3778 int diff = old_out - m_mltProducer->position();
3779 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3781 diff = new_out - m_mltProducer->position();
3782 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3786 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3787 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3788 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3789 QString resource = mlt_properties_get(properties, "mlt_service");
3790 int old_pos = (int)(old_in + old_out) / 2;
3793 while (mlt_type == "transition") {
3794 Mlt::Transition transition((mlt_transition) nextservice);
3795 nextservice = mlt_service_producer(nextservice);
3796 int currentTrack = transition.get_b_track();
3797 int currentIn = (int) transition.get_in();
3798 int currentOut = (int) transition.get_out();
3800 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3802 if (newTrack - startTrack != 0) {
3803 Mlt::Properties trans_props(transition.get_properties());
3804 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3805 Mlt::Properties new_trans_props(new_transition.get_properties());
3806 new_trans_props.inherit(trans_props);
3807 new_transition.set_in_and_out(new_in, new_out);
3808 field->disconnect_service(transition);
3809 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3810 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3811 } else transition.set_in_and_out(new_in, new_out);
3814 if (nextservice == NULL) break;
3815 properties = MLT_SERVICE_PROPERTIES(nextservice);
3816 mlt_type = mlt_properties_get(properties, "mlt_type");
3817 resource = mlt_properties_get(properties, "mlt_service");
3820 if (doRefresh) refresh();
3821 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3826 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3828 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3829 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3830 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3831 QString resource = mlt_properties_get(properties, "mlt_service");
3832 QList <Mlt::Transition *> trList;
3833 mlt_properties insertproperties = tr.get_properties();
3834 QString insertresource = mlt_properties_get(insertproperties, "mlt_service");
3835 bool isMixTransition = insertresource == "mix";
3837 while (mlt_type == "transition") {
3838 Mlt::Transition transition((mlt_transition) nextservice);
3839 nextservice = mlt_service_producer(nextservice);
3840 int aTrack = transition.get_a_track();
3841 int bTrack = transition.get_b_track();
3842 if ((isMixTransition || resource != "mix") && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3843 Mlt::Properties trans_props(transition.get_properties());
3844 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3845 Mlt::Properties new_trans_props(cp->get_properties());
3846 new_trans_props.inherit(trans_props);
3848 field->disconnect_service(transition);
3850 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3852 if (nextservice == NULL) break;
3853 properties = MLT_SERVICE_PROPERTIES(nextservice);
3854 mlt_type = mlt_properties_get(properties, "mlt_type");
3855 resource = mlt_properties_get(properties, "mlt_service");
3857 field->plant_transition(tr, a_track, b_track);
3859 // re-add upper transitions
3860 for (int i = trList.count() - 1; i >= 0; i--) {
3861 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3862 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3867 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3869 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3871 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3872 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3873 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3876 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3879 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3881 mlt_service serv = m_mltProducer->parent().get_service();
3882 mlt_service_lock(serv);
3884 mlt_service nextservice = mlt_service_get_producer(serv);
3885 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3886 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3887 QString resource = mlt_properties_get(properties, "mlt_service");
3888 int in_pos = (int) in.frames(m_fps);
3889 int out_pos = (int) out.frames(m_fps) - 1;
3891 while (mlt_type == "transition") {
3892 mlt_transition tr = (mlt_transition) nextservice;
3893 int currentTrack = mlt_transition_get_b_track(tr);
3894 int currentBTrack = mlt_transition_get_a_track(tr);
3895 int currentIn = (int) mlt_transition_get_in(tr);
3896 int currentOut = (int) mlt_transition_get_out(tr);
3898 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3899 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3900 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3901 QMap<QString, QString>::Iterator it;
3903 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3905 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3906 if (currentId != xml.attribute("id")) {
3907 // The transition ID is not the same, so reset all properties
3908 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3909 // Cleanup previous properties
3910 QStringList permanentProps;
3911 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3912 permanentProps << "out" << "a_track" << "b_track";
3913 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3914 QString propName = mlt_properties_get_name(transproperties, i);
3915 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3916 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3921 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3922 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3924 if (currentBTrack != a_track) {
3925 mlt_properties_set_int(transproperties, "a_track", a_track);
3927 for (it = map.begin(); it != map.end(); ++it) {
3929 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3930 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3931 //filter->set("kdenlive_id", id);
3935 nextservice = mlt_service_producer(nextservice);
3936 if (nextservice == NULL) break;
3937 properties = MLT_SERVICE_PROPERTIES(nextservice);
3938 mlt_type = mlt_properties_get(properties, "mlt_type");
3939 resource = mlt_properties_get(properties, "mlt_service");
3941 mlt_service_unlock(serv);
3943 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3946 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3948 mlt_service serv = m_mltProducer->parent().get_service();
3949 mlt_service_lock(serv);
3951 Mlt::Service service(serv);
3952 Mlt::Tractor tractor(service);
3953 Mlt::Field *field = tractor.field();
3955 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3957 mlt_service nextservice = mlt_service_get_producer(serv);
3958 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3959 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3960 QString resource = mlt_properties_get(properties, "mlt_service");
3962 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3963 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3965 while (mlt_type == "transition") {
3966 mlt_transition tr = (mlt_transition) nextservice;
3967 int currentTrack = mlt_transition_get_b_track(tr);
3968 int currentIn = (int) mlt_transition_get_in(tr);
3969 int currentOut = (int) mlt_transition_get_out(tr);
3970 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3972 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3973 mlt_field_disconnect_service(field->get_field(), nextservice);
3976 nextservice = mlt_service_producer(nextservice);
3977 if (nextservice == NULL) break;
3978 properties = MLT_SERVICE_PROPERTIES(nextservice);
3979 mlt_type = mlt_properties_get(properties, "mlt_type");
3980 resource = mlt_properties_get(properties, "mlt_service");
3982 mlt_service_unlock(serv);
3984 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3987 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3989 QDomNodeList attribs = xml.elementsByTagName("parameter");
3990 QMap<QString, QString> map;
3991 for (int i = 0; i < attribs.count(); i++) {
3992 QDomElement e = attribs.item(i).toElement();
3993 QString name = e.attribute("name");
3994 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3995 map[name] = e.attribute("default");
3996 if (!e.attribute("value").isEmpty()) {
3997 map[name] = e.attribute("value");
3999 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
4000 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
4001 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
4004 if (e.attribute("namedesc").contains(';')) {
4005 QString format = e.attribute("format");
4006 QStringList separators = format.split("%d", QString::SkipEmptyParts);
4007 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
4009 QTextStream txtNeu(&neu);
4010 if (values.size() > 0)
4011 txtNeu << (int)values[0].toDouble();
4013 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
4014 txtNeu << separators[i];
4015 txtNeu << (int)(values[i+1].toDouble());
4017 if (i < separators.size())
4018 txtNeu << separators[i];
4019 map[e.attribute("name")] = neu;
4026 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
4028 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
4029 Mlt::Service service(m_mltProducer->parent().get_service());
4030 Mlt::Tractor tractor(service);
4031 Mlt::Field *field = tractor.field();
4033 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
4034 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
4035 transition->set("transparency", id);
4036 transition->set("fill", 1);
4037 transition->set("internal_added", 237);
4038 field->plant_transition(*transition, transitiontrack, info.track);
4042 void Render::mltDeleteTransparency(int pos, int track, int id)
4044 Mlt::Service service(m_mltProducer->parent().get_service());
4045 Mlt::Tractor tractor(service);
4046 Mlt::Field *field = tractor.field();
4048 //if (do_refresh) m_mltConsumer->set("refresh", 0);
4049 mlt_service serv = m_mltProducer->parent().get_service();
4051 mlt_service nextservice = mlt_service_get_producer(serv);
4052 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4053 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4054 QString resource = mlt_properties_get(properties, "mlt_service");
4056 while (mlt_type == "transition") {
4057 mlt_transition tr = (mlt_transition) nextservice;
4058 int currentTrack = mlt_transition_get_b_track(tr);
4059 int currentIn = (int) mlt_transition_get_in(tr);
4060 int currentOut = (int) mlt_transition_get_out(tr);
4061 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4062 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
4064 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
4065 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
4066 mlt_field_disconnect_service(field->get_field(), nextservice);
4069 nextservice = mlt_service_producer(nextservice);
4070 if (nextservice == NULL) break;
4071 properties = MLT_SERVICE_PROPERTIES(nextservice);
4072 mlt_type = mlt_properties_get(properties, "mlt_type");
4073 resource = mlt_properties_get(properties, "mlt_service");
4075 //if (do_refresh) m_mltConsumer->set("refresh", 1);
4078 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
4080 Mlt::Service service(m_mltProducer->parent().get_service());
4081 Mlt::Tractor tractor(service);
4084 m_mltConsumer->set("refresh", 0);
4086 mlt_service serv = m_mltProducer->parent().get_service();
4087 mlt_service nextservice = mlt_service_get_producer(serv);
4088 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4089 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4090 QString resource = mlt_properties_get(properties, "mlt_service");
4091 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
4092 while (mlt_type == "transition") {
4093 mlt_transition tr = (mlt_transition) nextservice;
4094 int currentTrack = mlt_transition_get_b_track(tr);
4095 int currentIn = (int) mlt_transition_get_in(tr);
4096 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
4097 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4098 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
4099 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
4100 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
4101 mlt_transition_set_in_and_out(tr, newStart, newEnd);
4104 nextservice = mlt_service_producer(nextservice);
4105 if (nextservice == NULL) break;
4106 properties = MLT_SERVICE_PROPERTIES(nextservice);
4107 mlt_type = mlt_properties_get(properties, "mlt_type");
4108 resource = mlt_properties_get(properties, "mlt_service");
4111 m_mltConsumer->set("refresh", 1);
4115 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
4117 Mlt::Service service(m_mltProducer->parent().get_service());
4118 Mlt::Tractor tractor(service);
4121 m_mltConsumer->set("refresh", 0);
4123 mlt_service serv = m_mltProducer->parent().get_service();
4124 mlt_service nextservice = mlt_service_get_producer(serv);
4125 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4126 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4127 QString resource = mlt_properties_get(properties, "mlt_service");
4129 while (mlt_type == "transition") {
4130 mlt_transition tr = (mlt_transition) nextservice;
4131 int currentTrack = mlt_transition_get_b_track(tr);
4132 int currentaTrack = mlt_transition_get_a_track(tr);
4133 int currentIn = (int) mlt_transition_get_in(tr);
4134 int currentOut = (int) mlt_transition_get_out(tr);
4135 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4136 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4137 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
4138 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
4139 kDebug() << "//////MOVING";
4140 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
4141 if (endTrack != startTrack) {
4142 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4143 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
4144 mlt_properties_set_int(properties, "b_track", endTrack);
4148 nextservice = mlt_service_producer(nextservice);
4149 if (nextservice == NULL) break;
4150 properties = MLT_SERVICE_PROPERTIES(nextservice);
4151 mlt_type = mlt_properties_get(properties, "mlt_type");
4152 resource = mlt_properties_get(properties, "mlt_service");
4155 m_mltConsumer->set("refresh", 1);
4159 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
4161 if (in >= out) return false;
4162 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
4163 Mlt::Service service(m_mltProducer->parent().get_service());
4165 Mlt::Tractor tractor(service);
4166 Mlt::Field *field = tractor.field();
4168 Mlt::Transition transition(*m_mltProfile, tag.toUtf8().constData());
4169 if (out != GenTime())
4170 transition.set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
4172 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
4173 QMap<QString, QString>::Iterator it;
4175 if (xml.attribute("automatic") == "1") transition.set("automatic", 1);
4176 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
4177 if (xml.hasAttribute("id"))
4178 transition.set("kdenlive_id", xml.attribute("id").toUtf8().constData());
4179 if (xml.hasAttribute("force_track"))
4180 transition.set("force_track", xml.attribute("force_track").toInt());
4182 for (it = args.begin(); it != args.end(); ++it) {
4184 if (!it.value().isEmpty())
4185 transition.set(key.toUtf8().constData(), it.value().toUtf8().constData());
4186 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
4188 // attach transition
4190 mltPlantTransition(field, transition, a_track, b_track);
4191 // field->plant_transition(*transition, a_track, b_track);
4193 if (do_refresh) refresh();
4197 void Render::mltSavePlaylist()
4199 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
4200 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
4201 fileConsumer.set("resource", "/tmp/playlist.mlt");
4203 Mlt::Service service(m_mltProducer->get_service());
4205 fileConsumer.connect(service);
4206 fileConsumer.start();
4209 const QList <Mlt::Producer *> Render::producersList()
4211 QList <Mlt::Producer *> prods;
4212 if (m_mltProducer == NULL) return prods;
4213 Mlt::Service service(m_mltProducer->parent().get_service());
4214 if (service.type() != tractor_type) return prods;
4215 Mlt::Tractor tractor(service);
4218 int trackNb = tractor.count();
4219 for (int t = 1; t < trackNb; t++) {
4220 Mlt::Producer *tt = tractor.track(t);
4221 Mlt::Producer trackProducer(tt);
4223 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4224 if (!trackPlaylist.is_valid()) continue;
4225 int clipNb = trackPlaylist.count();
4226 for (int i = 0; i < clipNb; i++) {
4227 Mlt::Producer *c = trackPlaylist.get_clip(i);
4228 if (c == NULL) continue;
4229 QString prodId = c->parent().get("id");
4230 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
4231 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4234 prods.append(nprod);
4243 void Render::fillSlowMotionProducers()
4245 if (m_mltProducer == NULL) return;
4246 Mlt::Service service(m_mltProducer->parent().get_service());
4247 if (service.type() != tractor_type) return;
4249 Mlt::Tractor tractor(service);
4251 int trackNb = tractor.count();
4252 for (int t = 1; t < trackNb; t++) {
4253 Mlt::Producer *tt = tractor.track(t);
4254 Mlt::Producer trackProducer(tt);
4256 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4257 if (!trackPlaylist.is_valid()) continue;
4258 int clipNb = trackPlaylist.count();
4259 for (int i = 0; i < clipNb; i++) {
4260 Mlt::Producer *c = trackPlaylist.get_clip(i);
4261 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4263 QString id = nprod->parent().get("id");
4264 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
4265 // this is a slowmotion producer, add it to the list
4266 QString url = QString::fromUtf8(nprod->get("resource"));
4267 int strobe = nprod->get_int("strobe");
4268 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
4269 if (!m_slowmotionProducers.contains(url)) {
4270 m_slowmotionProducers.insert(url, nprod);
4272 } else delete nprod;
4279 QList <TransitionInfo> Render::mltInsertTrack(int ix, bool videoTrack)
4281 Mlt::Service service(m_mltProducer->parent().get_service());
4282 if (service.type() != tractor_type) {
4283 kWarning() << "// TRACTOR PROBLEM";
4284 return QList <TransitionInfo> ();
4288 Mlt::Tractor tractor(service);
4289 QList <TransitionInfo> transitionInfos;
4290 Mlt::Playlist playlist;
4291 int ct = tractor.count();
4293 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
4299 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
4300 tractor.set_track(playlist, pos);
4301 Mlt::Producer newProd(tractor.track(pos));
4302 if (!videoTrack) newProd.set("hide", 1);
4304 for (; pos <= ct; pos++) {
4305 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
4306 tractor.set_track(*prodToMove, pos);
4307 prodToMove = prodToMove2;
4310 tractor.set_track(playlist, ix);
4311 Mlt::Producer newProd(tractor.track(ix));
4312 if (!videoTrack) newProd.set("hide", 1);
4317 mlt_service serv = m_mltProducer->parent().get_service();
4318 mlt_service nextservice = mlt_service_get_producer(serv);
4319 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4320 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4321 QString resource = mlt_properties_get(properties, "mlt_service");
4322 Mlt::Field *field = tractor.field();
4323 QList <Mlt::Transition *> trList;
4325 while (mlt_type == "transition") {
4326 if (resource != "mix") {
4327 Mlt::Transition transition((mlt_transition) nextservice);
4328 nextservice = mlt_service_producer(nextservice);
4329 int currentbTrack = transition.get_b_track();
4330 int currentaTrack = transition.get_a_track();
4331 bool trackChanged = false;
4332 bool forceTransitionTrack = false;
4333 if (currentbTrack >= ix) {
4334 if (currentbTrack == ix && currentaTrack < ix) forceTransitionTrack = true;
4336 trackChanged = true;
4338 if (currentaTrack >= ix) {
4340 trackChanged = true;
4342 kDebug()<<"// Newtrans: "<<currentaTrack<<"/"<<currentbTrack;
4344 // disconnect all transitions
4345 Mlt::Properties trans_props(transition.get_properties());
4346 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
4347 Mlt::Properties new_trans_props(cp->get_properties());
4348 new_trans_props.inherit(trans_props);
4351 // Transition track needs to be adjusted
4352 cp->set("a_track", currentaTrack);
4353 cp->set("b_track", currentbTrack);
4354 // Check if transition track was changed and needs to be forced
4355 if (forceTransitionTrack) cp->set("force_track", 1);
4356 TransitionInfo trInfo;
4357 trInfo.startPos = GenTime(transition.get_in(), m_fps);
4358 trInfo.a_track = currentaTrack;
4359 trInfo.b_track = currentbTrack;
4360 trInfo.forceTrack = cp->get_int("force_track");
4361 transitionInfos.append(trInfo);
4364 field->disconnect_service(transition);
4366 else nextservice = mlt_service_producer(nextservice);
4367 if (nextservice == NULL) break;
4368 properties = MLT_SERVICE_PROPERTIES(nextservice);
4369 mlt_type = mlt_properties_get(properties, "mlt_type");
4370 resource = mlt_properties_get(properties, "mlt_service");
4373 // Add audio mix transition to last track
4374 Mlt::Transition transition(*m_mltProfile, "mix");
4375 transition.set("a_track", 1);
4376 transition.set("b_track", ct);
4377 transition.set("always_active", 1);
4378 transition.set("internal_added", 237);
4379 transition.set("combine", 1);
4380 mltPlantTransition(field, transition, 1, ct);
4382 // re-add transitions
4383 for (int i = trList.count() - 1; i >= 0; i--) {
4384 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
4389 blockSignals(false);
4390 return transitionInfos;
4394 void Render::mltDeleteTrack(int ix)
4397 doc.setContent(sceneList(), false);
4398 int tracksCount = doc.elementsByTagName("track").count() - 1;
4399 QDomNode track = doc.elementsByTagName("track").at(ix);
4400 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
4401 QDomNodeList transitions = doc.elementsByTagName("transition");
4402 for (int i = 0; i < transitions.count(); i++) {
4403 QDomElement e = transitions.at(i).toElement();
4404 QDomNodeList props = e.elementsByTagName("property");
4405 QMap <QString, QString> mappedProps;
4406 for (int j = 0; j < props.count(); j++) {
4407 QDomElement f = props.at(j).toElement();
4408 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
4410 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
4411 tractor.removeChild(transitions.at(i));
4413 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
4414 // Transition needs to be moved
4415 int a_track = mappedProps.value("a_track").toInt();
4416 int b_track = mappedProps.value("b_track").toInt();
4417 if (a_track > 0 && a_track >= ix) a_track --;
4418 if (b_track == ix) {
4419 // transition was on the deleted track, so remove it
4420 tractor.removeChild(transitions.at(i));
4424 if (b_track > 0 && b_track > ix) b_track --;
4425 for (int j = 0; j < props.count(); j++) {
4426 QDomElement f = props.at(j).toElement();
4427 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
4428 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
4433 tractor.removeChild(track);
4434 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
4435 setSceneList(doc.toString(), m_mltConsumer->position());
4436 emit refreshDocumentProducers(false, false);
4440 void Render::updatePreviewSettings()
4442 kDebug() << "////// RESTARTING CONSUMER";
4443 if (!m_mltConsumer || !m_mltProducer) return;
4444 if (m_mltProducer->get_playtime() == 0) return;
4445 QMutexLocker locker(&m_mutex);
4446 Mlt::Service service(m_mltProducer->parent().get_service());
4447 if (service.type() != tractor_type) return;
4449 //m_mltConsumer->set("refresh", 0);
4450 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
4451 m_mltConsumer->purge();
4452 QString scene = sceneList();
4454 if (m_mltProducer) {
4455 pos = m_mltProducer->position();
4458 setSceneList(scene, pos);
4462 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
4464 // Update all frame positions to the new fps value
4465 //WARNING: there are probably some effects or other that hold a frame value
4466 // as parameter and will also need to be updated here!
4468 doc.setContent(scene);
4470 double factor = new_fps / current_fps;
4471 QDomNodeList producers = doc.elementsByTagName("producer");
4472 for (int i = 0; i < producers.count(); i++) {
4473 QDomElement prod = producers.at(i).toElement();
4474 prod.removeAttribute("in");
4475 prod.removeAttribute("out");
4477 QDomNodeList props = prod.childNodes();
4478 for (int j = 0; j < props.count(); j++) {
4479 QDomElement param = props.at(j).toElement();
4480 QString paramName = param.attribute("name");
4481 if (paramName.startsWith("meta.") || paramName == "length") {
4482 prod.removeChild(props.at(j));
4488 QDomNodeList entries = doc.elementsByTagName("entry");
4489 for (int i = 0; i < entries.count(); i++) {
4490 QDomElement entry = entries.at(i).toElement();
4491 int in = entry.attribute("in").toInt();
4492 int out = entry.attribute("out").toInt();
4493 in = factor * in + 0.5;
4494 out = factor * out + 0.5;
4495 entry.setAttribute("in", in);
4496 entry.setAttribute("out", out);
4499 QDomNodeList blanks = doc.elementsByTagName("blank");
4500 for (int i = 0; i < blanks.count(); i++) {
4501 QDomElement blank = blanks.at(i).toElement();
4502 int length = blank.attribute("length").toInt();
4503 length = factor * length + 0.5;
4504 blank.setAttribute("length", QString::number(length));
4507 QDomNodeList filters = doc.elementsByTagName("filter");
4508 for (int i = 0; i < filters.count(); i++) {
4509 QDomElement filter = filters.at(i).toElement();
4510 int in = filter.attribute("in").toInt();
4511 int out = filter.attribute("out").toInt();
4512 in = factor * in + 0.5;
4513 out = factor * out + 0.5;
4514 filter.setAttribute("in", in);
4515 filter.setAttribute("out", out);
4518 QDomNodeList transitions = doc.elementsByTagName("transition");
4519 for (int i = 0; i < transitions.count(); i++) {
4520 QDomElement transition = transitions.at(i).toElement();
4521 int in = transition.attribute("in").toInt();
4522 int out = transition.attribute("out").toInt();
4523 in = factor * in + 0.5;
4524 out = factor * out + 0.5;
4525 transition.setAttribute("in", in);
4526 transition.setAttribute("out", out);
4527 QDomNodeList props = transition.childNodes();
4528 for (int j = 0; j < props.count(); j++) {
4529 QDomElement param = props.at(j).toElement();
4530 QString paramName = param.attribute("name");
4531 if (paramName == "geometry") {
4532 QString geom = param.firstChild().nodeValue();
4533 QStringList keys = geom.split(';');
4534 QStringList newKeys;
4535 for (int k = 0; k < keys.size(); ++k) {
4536 if (keys.at(k).contains('=')) {
4537 int pos = keys.at(k).section('=', 0, 0).toInt();
4538 pos = factor * pos + 0.5;
4539 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4540 } else newKeys.append(keys.at(k));
4542 param.firstChild().setNodeValue(newKeys.join(";"));
4546 QDomElement root = doc.documentElement();
4547 if (!root.isNull()) {
4548 QDomElement tractor = root.firstChildElement("tractor");
4549 int out = tractor.attribute("out").toInt();
4550 out = factor * out + 0.5;
4551 tractor.setAttribute("out", out);
4552 emit durationChanged(out);
4555 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4556 return doc.toString();
4560 void Render::sendFrameUpdate()
4562 if (m_mltProducer) {
4563 Mlt::Frame * frame = m_mltProducer->get_frame();
4564 emitFrameUpdated(*frame);
4569 Mlt::Producer* Render::getProducer()
4571 return m_mltProducer;
4574 const QString Render::activeClipId()
4576 if (m_mltProducer) return m_mltProducer->get("id");
4581 bool Render::getBlackMagicDeviceList(KComboBox *devicelist, bool force)
4583 if (!force && !KdenliveSettings::decklink_device_found()) return false;
4584 Mlt::Profile profile;
4585 Mlt::Producer bm(profile, "decklink");
4586 int found_devices = 0;
4587 if (bm.is_valid()) {
4588 bm.set("list_devices", 1);
4589 found_devices = bm.get_int("devices");
4591 else KdenliveSettings::setDecklink_device_found(false);
4592 if (found_devices <= 0) {
4593 devicelist->setEnabled(false);
4596 KdenliveSettings::setDecklink_device_found(true);
4597 for (int i = 0; i < found_devices; i++) {
4598 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4599 devicelist->addItem(bm.get(tmp));
4605 bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist, bool force)
4607 if (!force && !KdenliveSettings::decklink_device_found()) return false;
4608 Mlt::Profile profile;
4609 Mlt::Consumer bm(profile, "decklink");
4610 int found_devices = 0;
4611 if (bm.is_valid()) {
4612 bm.set("list_devices", 1);;
4613 found_devices = bm.get_int("devices");
4615 else KdenliveSettings::setDecklink_device_found(false);
4616 if (found_devices <= 0) {
4617 devicelist->setEnabled(false);
4620 KdenliveSettings::setDecklink_device_found(true);
4621 for (int i = 0; i < found_devices; i++) {
4622 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4623 devicelist->addItem(bm.get(tmp));
4629 void Render::slotMultiStreamProducerFound(const QString path, QList<int> audio_list, QList<int> video_list, stringMap data)
4631 if (KdenliveSettings::automultistreams()) {
4632 for (int i = 1; i < video_list.count(); i++) {
4633 int vindex = video_list.at(i);
4635 if (i <= audio_list.count() -1) {
4636 aindex = audio_list.at(i);
4638 data.insert("video_index", QString::number(vindex));
4639 data.insert("audio_index", QString::number(aindex));
4640 data.insert("bypassDuplicate", "1");
4641 emit addClip(KUrl(path), data);
4646 int width = 60.0 * m_mltProfile->dar();
4647 int swidth = 60.0 * m_mltProfile->width() / m_mltProfile->height();
4648 if (width % 2 == 1) width++;
4650 KDialog dialog(qApp->activeWindow());
4651 dialog.setCaption("Multi Stream Clip");
4652 dialog.setButtons(KDialog::Ok | KDialog::Cancel);
4653 dialog.setButtonText(KDialog::Ok, i18n("Import selected clips"));
4654 QWidget *content = new QWidget(&dialog);
4655 dialog.setMainWidget(content);
4656 QVBoxLayout *vbox = new QVBoxLayout(content);
4657 QLabel *lab1 = new QLabel(i18n("Additional streams for clip\n %1", path), content);
4658 vbox->addWidget(lab1);
4659 QList <QGroupBox*> groupList;
4660 QList <QComboBox*> comboList;
4661 // We start loading the list at 1, video index 0 should already be loaded
4662 for (int j = 1; j < video_list.count(); j++) {
4663 Mlt::Producer multiprod(* m_mltProfile, path.toUtf8().constData());
4664 multiprod.set("video_index", video_list.at(j));
4665 QImage thumb = KThumb::getFrame(&multiprod, 0, swidth, width, 60);
4666 QGroupBox *streamFrame = new QGroupBox(i18n("Video stream %1", video_list.at(j)), content);
4667 streamFrame->setProperty("vindex", video_list.at(j));
4668 groupList << streamFrame;
4669 streamFrame->setCheckable(true);
4670 streamFrame->setChecked(true);
4671 QVBoxLayout *vh = new QVBoxLayout( streamFrame );
4672 QLabel *iconLabel = new QLabel(content);
4673 iconLabel->setPixmap(QPixmap::fromImage(thumb));
4674 vh->addWidget(iconLabel);
4675 if (audio_list.count() > 1) {
4676 QComboBox *cb = new QComboBox(content);
4677 for (int k = 0; k < audio_list.count(); k++) {
4678 cb->addItem(i18n("Audio stream %1", audio_list.at(k)), audio_list.at(k));
4681 cb->setCurrentIndex(qMin(j, audio_list.count() - 1));
4684 vbox->addWidget(streamFrame);
4686 if (dialog.exec() == QDialog::Accepted) {
4687 // import selected streams
4688 for (int i = 0; i < groupList.count(); i++) {
4689 if (groupList.at(i)->isChecked()) {
4690 int vindex = groupList.at(i)->property("vindex").toInt();
4691 int aindex = comboList.at(i)->itemData(comboList.at(i)->currentIndex()).toInt();
4692 data.insert("video_index", QString::number(vindex));
4693 data.insert("audio_index", QString::number(aindex));
4694 data.insert("bypassDuplicate", "1");
4695 emit addClip(KUrl(path), data);
4701 #include "renderer.moc"