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"
34 #include "blackmagic/devices.h"
37 #include <mlt++/Mlt.h>
40 #include <KStandardDirs>
41 #include <KMessageBox>
43 #include <KTemporaryFile>
48 #include <QApplication>
49 #include <QtConcurrentRun>
56 #define SEEK_INACTIVE (-1)
58 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
60 // kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified();
61 if (level > MLT_LOG_ERROR) return;
63 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
68 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
70 // detect if the producer has finished playing. Is there a better way to do it?
71 self->emitFrameNumber();
72 Mlt::Frame frame(frame_ptr);
73 if (!frame.is_valid()) return;
74 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
75 self->emitFrameUpdated(frame);
77 if (self->analyseAudio) {
78 self->showAudio(frame);
80 if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
82 self->emitConsumerStopped();
87 static void consumer_paused(mlt_consumer, Render * self, mlt_frame /*frame_ptr*/)
89 // detect if the producer has finished playing. Is there a better way to do it?
90 self->emitConsumerStopped();
94 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
96 // detect if the producer has finished playing. Is there a better way to do it?
97 Mlt::Frame frame(frame_ptr);
98 self->showFrame(frame);
99 if (frame.get_double("_speed") == 0.0) {
100 self->emitConsumerStopped();
101 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
103 self->emitConsumerStopped();
107 Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWidget *parent) :
108 AbstractRender(rendererName, parent),
109 requestedSeekPosition(SEEK_INACTIVE),
110 m_name(rendererName),
114 m_showFrameEvent(NULL),
116 m_externalConsumer(false),
119 m_isSplitView(false),
123 qRegisterMetaType<stringMap> ("stringMap");
124 analyseAudio = KdenliveSettings::monitor_audio();
125 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
126 buildConsumer(profile);
127 m_mltProducer = m_blackClip->cut(0, 1);
128 m_mltConsumer->connect(*m_mltProducer);
129 m_mltProducer->set_speed(0.0);
130 m_refreshTimer.setSingleShot(true);
131 m_refreshTimer.setInterval(70);
132 connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
133 connect(this, SIGNAL(multiStreamFound(const QString &,QList<int>,QList<int>,stringMap)), this, SLOT(slotMultiStreamProducerFound(const QString &,QList<int>,QList<int>,stringMap)));
143 void Render::closeMlt()
146 m_requestList.clear();
147 m_infoThread.waitForFinished();
148 if (m_showFrameEvent) delete m_showFrameEvent;
149 if (m_pauseEvent) delete m_pauseEvent;
150 if (m_mltConsumer) delete m_mltConsumer;
151 if (m_mltProducer) delete m_mltProducer;
152 /*if (m_mltProducer) {
153 Mlt::Service service(m_mltProducer->parent().get_service());
156 if (service.type() == tractor_type) {
157 Mlt::Tractor tractor(service);
158 Mlt::Field *field = tractor.field();
159 mlt_service nextservice = mlt_service_get_producer(service.get_service());
160 mlt_service nextservicetodisconnect;
161 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
162 QString mlt_type = mlt_properties_get(properties, "mlt_type");
163 QString resource = mlt_properties_get(properties, "mlt_service");
164 // Delete all transitions
165 while (mlt_type == "transition") {
166 nextservicetodisconnect = nextservice;
167 nextservice = mlt_service_producer(nextservice);
168 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
169 if (nextservice == NULL) break;
170 properties = MLT_SERVICE_PROPERTIES(nextservice);
171 mlt_type = mlt_properties_get(properties, "mlt_type");
172 resource = mlt_properties_get(properties, "mlt_service");
181 //kDebug() << "// // // CLOSE RENDERER " << m_name;
182 if (m_blackClip) delete m_blackClip;
186 void Render::slotSwitchFullscreen()
188 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
191 void Render::buildConsumer(const QString &profileName)
196 m_activeProfile = profileName;
198 Mlt::Profile tmpProfile(m_activeProfile.toUtf8().constData());
199 m_mltProfile->set_colorspace(tmpProfile.colorspace());
200 m_mltProfile->set_frame_rate(tmpProfile.frame_rate_num(), tmpProfile.frame_rate_den());
201 m_mltProfile->set_height(tmpProfile.height());
202 m_mltProfile->set_width(tmpProfile.width());
203 m_mltProfile->set_progressive(tmpProfile.progressive());
204 m_mltProfile->set_sample_aspect(tmpProfile.sample_aspect_num(), tmpProfile.sample_aspect_den());
205 m_mltProfile->get_profile()->display_aspect_num = tmpProfile.display_aspect_num();
206 m_mltProfile->get_profile()->display_aspect_den = tmpProfile.display_aspect_den();
209 m_mltProfile = new Mlt::Profile(m_activeProfile.toUtf8().constData());
211 setenv("MLT_PROFILE", m_activeProfile.toUtf8().constData(), 1);
212 m_mltProfile->set_explicit(true);
214 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
215 m_blackClip->set("id", "black");
216 m_blackClip->set("mlt_type", "producer");
218 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) {
219 #ifdef USE_BLACKMAGIC
220 // Use blackmagic card for video output
221 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
222 int device = KdenliveSettings::blackmagic_output_device();
224 if (BMInterface::isSupportedProfile(device, profileProperties)) {
225 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
226 if (!m_mltConsumer) {
227 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
228 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
229 mlt_log_set_callback(kdenlive_callback);
231 if (m_mltConsumer->is_valid()) {
232 m_externalConsumer = true;
233 m_mltConsumer->set("terminate_on_pause", 0);
234 m_mltConsumer->set("deinterlace_method", "onefield");
235 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
237 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
238 } else KMessageBox::informationList(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()), BMInterface::supportedModes(KdenliveSettings::blackmagic_output_device()));
242 m_externalConsumer = false;
243 QString videoDriver = KdenliveSettings::videodrivername();
244 if (!videoDriver.isEmpty()) {
245 if (videoDriver == "x11_noaccel") {
246 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
249 unsetenv("SDL_VIDEO_YUV_HWACCEL");
252 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
254 //m_mltConsumer->set("fullscreen", 1);
257 if (!m_mltConsumer) {
258 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
259 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
261 m_mltConsumer->set("preview_off", 1);
262 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
264 if (!m_mltConsumer) {
265 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
266 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
267 m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
269 m_mltConsumer->set("window_id", m_winid);
271 m_mltConsumer->set("resize", 1);
272 m_mltConsumer->set("terminate_on_pause", 1);
273 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
274 m_mltConsumer->set("rescale", "nearest");
275 mlt_log_set_callback(kdenlive_callback);
277 QString audioDevice = KdenliveSettings::audiodevicename();
278 if (!audioDevice.isEmpty())
279 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
281 if (!videoDriver.isEmpty())
282 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
284 QString audioDriver = KdenliveSettings::audiodrivername();
287 // Disabled because the "auto" detected driver was sometimes wrong
288 if (audioDriver.isEmpty())
289 audioDriver = KdenliveSettings::autoaudiodrivername();
292 if (!audioDriver.isEmpty())
293 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
295 m_mltConsumer->set("progressive", 1);
296 m_mltConsumer->set("audio_buffer", 1024);
297 m_mltConsumer->set("frequency", 48000);
298 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
301 Mlt::Producer *Render::invalidProducer(const QString &id)
304 QString txt = '+' + i18n("Missing clip") + ".txt";
305 char *tmp = qstrdup(txt.toUtf8().constData());
306 clip = new Mlt::Producer(*m_mltProfile, tmp);
308 if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
310 clip->set("bgcolour", "0xff0000ff");
311 clip->set("pad", "10");
313 clip->set("id", id.toUtf8().constData());
314 clip->set("mlt_type", "producer");
318 bool Render::hasProfile(const QString &profileName) const
320 return m_activeProfile == profileName;
323 int Render::resetProfile(const QString &profileName, bool dropSceneList)
325 m_refreshTimer.stop();
327 if (m_externalConsumer == KdenliveSettings::external_display()) {
328 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
329 QString videoDriver = KdenliveSettings::videodrivername();
330 QString currentDriver = m_mltConsumer->get("video_driver");
331 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
332 QString background = KdenliveSettings::window_background().name();
333 QString currentBackground = m_mltConsumer->get("window_background");
334 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
335 kDebug() << "reset to same profile, nothing to do";
340 if (m_isSplitView) slotSplitView(false);
341 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
342 m_mltConsumer->purge();
345 if (!dropSceneList) scene = sceneList();
347 double current_fps = m_mltProfile->fps();
348 double current_dar = m_mltProfile->dar();
351 m_requestList.clear();
352 m_infoThread.waitForFinished();
355 pos = m_mltProducer->position();
357 Mlt::Service service(m_mltProducer->get_service());
358 if (service.type() == tractor_type) {
359 Mlt::Tractor tractor(service);
360 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
361 Mlt::Producer trackProducer(tractor.track(trackNb));
362 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
363 trackPlaylist.clear();
367 delete m_mltProducer;
369 m_mltProducer = NULL;
370 buildConsumer(profileName);
371 double new_fps = m_mltProfile->fps();
372 double new_dar = m_mltProfile->dar();
374 if (!dropSceneList) {
375 // We need to recover our playlist
376 if (current_fps != new_fps) {
377 // fps changed, we must update the scenelist positions
378 scene = updateSceneListFps(current_fps, new_fps, scene);
380 setSceneList(scene, pos);
381 // producers have changed (different profile), so reset them...
382 emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
387 void Render::seek(GenTime time)
389 int pos = time.frames(m_fps);
393 void Render::seek(int time)
397 if (requestedSeekPosition == SEEK_INACTIVE) {
398 requestedSeekPosition = time;
399 m_mltProducer->seek(time);
400 m_mltConsumer->purge();
401 if (m_mltProducer->get_speed() == 0) {
405 else requestedSeekPosition = time;
409 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
410 QPixmap pix(width, height);
412 mlt_image_format format = mlt_image_rgb24a;
413 uint8_t *thumb = frame->get_image(format, width, height);
414 QImage image(thumb, width, height, QImage::Format_ARGB32);
416 if (!image.isNull()) {
417 pix = pix.fromImage(image);
419 QPainter painter(&pix);
420 painter.drawRect(0, 0, width - 1, height - 1);
422 } else pix.fill(Qt::black);
426 int Render::frameRenderWidth() const
428 return m_mltProfile->width();
431 int Render::renderWidth() const
433 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
436 int Render::renderHeight() const
438 return m_mltProfile->height();
441 QImage Render::extractFrame(int frame_position, QString path, int width, int height)
444 width = frameRenderWidth();
445 height = renderHeight();
446 } else if (width % 2 == 1) width++;
447 int dwidth = height * frameRenderWidth() / renderHeight();
448 if (!path.isEmpty()) {
449 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
451 if (producer->is_valid()) {
452 QImage img = KThumb::getFrame(producer, frame_position, dwidth, width, height);
456 else delete producer;
460 if (!m_mltProducer || !path.isEmpty()) {
461 QImage pix(width, height, QImage::Format_RGB32);
465 return KThumb::getFrame(m_mltProducer, frame_position, dwidth, width, height);
468 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
472 if (url.fileName().startsWith(".all.")) { // check for slideshow
473 QString fileType = url.fileName().right(3);
475 QStringList::Iterator it;
477 QDir dir(url.directory());
479 filter << "*." + fileType;
480 filter << "*." + fileType.toUpper();
481 more = dir.entryList(filter, QDir::Files);
482 im.load(url.directory() + '/' + more.at(0));
483 } else im.load(url.path());
484 //pixmap = im.scaled(width, height);
488 double Render::consumerRatio() const
490 if (!m_mltConsumer) return 1.0;
491 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
495 int Render::getLength()
499 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
500 return mlt_producer_get_playtime(m_mltProducer->get_producer());
505 bool Render::isValid(KUrl url)
507 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
508 if (producer.is_blank())
514 double Render::dar() const
516 return m_mltProfile->dar();
519 double Render::sar() const
521 return m_mltProfile->sar();
524 void Render::slotSplitView(bool doit)
526 m_isSplitView = doit;
527 Mlt::Service service(m_mltProducer->parent().get_service());
528 Mlt::Tractor tractor(service);
529 if (service.type() != tractor_type || tractor.count() < 2) return;
530 Mlt::Field *field = tractor.field();
532 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
533 Mlt::Producer trackProducer(tractor.track(i));
534 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
535 if (QString(trackProducer.get("hide")).toInt() != 1) {
536 kDebug() << "// ADIDNG TRACK: " << i;
537 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
538 transition->set("mlt_service", "composite");
539 transition->set("a_track", 0);
540 transition->set("b_track", i);
541 transition->set("distort", 1);
542 transition->set("internal_added", "200");
546 geometry = "0/0:50%x50%";
549 geometry = "50%/0:50%x50%";
552 geometry = "0/50%:50%x50%";
556 geometry = "50%/50%:50%x50%";
559 transition->set("geometry", geometry.toUtf8().constData());
560 transition->set("always_active", "1");
561 field->plant_transition(*transition, 0, i);
565 m_mltConsumer->set("refresh", 1);
567 mlt_service serv = m_mltProducer->parent().get_service();
568 mlt_service nextservice = mlt_service_get_producer(serv);
569 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
570 QString mlt_type = mlt_properties_get(properties, "mlt_type");
571 QString resource = mlt_properties_get(properties, "mlt_service");
572 mlt_service nextservicetodisconnect;
574 while (mlt_type == "transition") {
575 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
576 if (added == "200") {
577 nextservicetodisconnect = nextservice;
578 nextservice = mlt_service_producer(nextservice);
579 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
581 else nextservice = mlt_service_producer(nextservice);
582 if (nextservice == NULL) break;
583 properties = MLT_SERVICE_PROPERTIES(nextservice);
584 mlt_type = mlt_properties_get(properties, "mlt_type");
585 resource = mlt_properties_get(properties, "mlt_service");
586 m_mltConsumer->set("refresh", 1);
591 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer)
593 requestClipInfo info;
595 info.clipId = clipId;
596 info.imageHeight = imageHeight;
597 info.replaceProducer = replaceProducer;
598 // Make sure we don't request the info for same clip twice
600 m_requestList.removeAll(info);
601 m_requestList.append(info);
602 m_infoMutex.unlock();
603 if (!m_infoThread.isRunning()) {
604 m_infoThread = QtConcurrent::run(this, &Render::processFileProperties);
608 void Render::forceProcessing(const QString &id)
610 if (m_processingClipId == id) return;
611 QMutexLocker lock(&m_infoMutex);
612 for (int i = 0; i < m_requestList.count(); i++) {
613 requestClipInfo info = m_requestList.at(i);
614 if (info.clipId == id) {
617 m_requestList.removeAt(i);
618 m_requestList.prepend(info);
625 int Render::processingItems()
627 QMutexLocker lock(&m_infoMutex);
628 int count = m_requestList.count();
629 if (!m_processingClipId.isEmpty()) {
630 // one clip is currently processed
636 bool Render::isProcessing(const QString &id)
638 if (m_processingClipId == id) return true;
639 QMutexLocker lock(&m_infoMutex);
640 for (int i = 0; i < m_requestList.count(); i++) {
641 requestClipInfo info = m_requestList.at(i);
642 if (info.clipId == id) {
649 void Render::processFileProperties()
651 requestClipInfo info;
653 while (!m_requestList.isEmpty()) {
655 info = m_requestList.takeFirst();
656 m_processingClipId = info.clipId;
657 m_infoMutex.unlock();
661 if (info.xml.hasAttribute("proxy") && info.xml.attribute("proxy") != "-") {
662 path = info.xml.attribute("proxy");
663 // Check for missing proxies
664 if (QFileInfo(path).size() <= 0) {
665 // proxy is missing, re-create it
666 emit requestProxy(info.clipId);
667 proxyProducer = false;
668 path = info.xml.attribute("resource");
670 else proxyProducer = true;
673 path = info.xml.attribute("resource");
674 proxyProducer = false;
677 Mlt::Producer *producer = NULL;
678 CLIPTYPE type = (CLIPTYPE)info.xml.attribute("type").toInt();
681 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + info.xml.attribute("colour")).toUtf8().constData());
682 } else if (type == TEXT) {
683 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
684 if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
685 producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
686 } else if (url.isEmpty()) {
687 //WARNING: when is this case used? Not sure it is working.. JBM/
689 QDomElement mlt = doc.createElement("mlt");
690 QDomElement play = doc.createElement("playlist");
691 play.setAttribute("id", "playlist0");
692 doc.appendChild(mlt);
693 mlt.appendChild(play);
694 play.appendChild(doc.importNode(info.xml, true));
695 QDomElement tractor = doc.createElement("tractor");
696 tractor.setAttribute("id", "tractor0");
697 QDomElement track = doc.createElement("track");
698 track.setAttribute("producer", "playlist0");
699 tractor.appendChild(track);
700 mlt.appendChild(tractor);
701 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
703 producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
706 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
707 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
708 m_processingClipId.clear();
710 // Proxy file is corrupted
711 emit removeInvalidProxy(info.clipId, false);
713 else emit removeInvalidClip(info.clipId, info.replaceProducer);
718 if (proxyProducer && info.xml.hasAttribute("proxy_out")) {
719 producer->set("length", info.xml.attribute("proxy_out").toInt() + 1);
720 producer->set("out", info.xml.attribute("proxy_out").toInt());
721 if (producer->get_out() != info.xml.attribute("proxy_out").toInt()) {
722 // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
723 m_processingClipId.clear();
724 emit removeInvalidProxy(info.clipId, true);
730 if (info.xml.hasAttribute("force_aspect_ratio")) {
731 double aspect = info.xml.attribute("force_aspect_ratio").toDouble();
732 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
735 if (info.xml.hasAttribute("force_aspect_num") && info.xml.hasAttribute("force_aspect_den")) {
736 int width = info.xml.attribute("frame_size").section('x', 0, 0).toInt();
737 int height = info.xml.attribute("frame_size").section('x', 1, 1).toInt();
738 int aspectNumerator = info.xml.attribute("force_aspect_num").toInt();
739 int aspectDenominator = info.xml.attribute("force_aspect_den").toInt();
740 if (aspectDenominator != 0 && width != 0)
741 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
744 if (info.xml.hasAttribute("force_fps")) {
745 double fps = info.xml.attribute("force_fps").toDouble();
746 if (fps > 0) producer->set("force_fps", fps);
749 if (info.xml.hasAttribute("force_progressive")) {
751 int progressive = info.xml.attribute("force_progressive").toInt(&ok);
752 if (ok) producer->set("force_progressive", progressive);
754 if (info.xml.hasAttribute("force_tff")) {
756 int fieldOrder = info.xml.attribute("force_tff").toInt(&ok);
757 if (ok) producer->set("force_tff", fieldOrder);
759 if (info.xml.hasAttribute("threads")) {
760 int threads = info.xml.attribute("threads").toInt();
761 if (threads != 1) producer->set("threads", threads);
763 if (info.xml.hasAttribute("video_index")) {
764 int vindex = info.xml.attribute("video_index").toInt();
765 if (vindex != 0) producer->set("video_index", vindex);
767 if (info.xml.hasAttribute("audio_index")) {
768 int aindex = info.xml.attribute("audio_index").toInt();
769 if (aindex != 0) producer->set("audio_index", aindex);
771 if (info.xml.hasAttribute("force_colorspace")) {
772 int colorspace = info.xml.attribute("force_colorspace").toInt();
773 if (colorspace != 0) producer->set("force_colorspace", colorspace);
775 if (info.xml.hasAttribute("full_luma")) {
776 int full_luma = info.xml.attribute("full_luma").toInt();
777 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
782 if (info.xml.hasAttribute("out")) clipOut = info.xml.attribute("out").toInt();
784 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
785 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
787 if (info.xml.hasAttribute("length")) {
788 length = info.xml.attribute("length").toInt();
789 clipOut = length - 1;
791 else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt();
792 producer->set("length", length);
796 if (clipOut > 0) producer->set_in_and_out(info.xml.attribute("in").toInt(), clipOut);
798 producer->set("id", info.clipId.toUtf8().constData());
800 if (info.xml.hasAttribute("templatetext"))
801 producer->set("templatetext", info.xml.attribute("templatetext").toUtf8().constData());
803 int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5);
804 int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5);
805 int frameNumber = info.xml.attribute("thumbnail", "-1").toInt();
807 if ((!info.replaceProducer && info.xml.hasAttribute("file_hash")) || proxyProducer) {
808 // Clip already has all properties
810 // Recreate clip thumb
811 if (frameNumber > 0) producer->seek(frameNumber);
812 Mlt::Frame *frame = producer->get_frame();
813 if (frame && frame->is_valid()) {
814 QImage img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
815 emit replyGetImage(info.clipId, img);
817 if (frame) delete frame;
819 m_processingClipId.clear();
820 emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
824 stringMap filePropertyMap;
825 stringMap metadataPropertyMap;
828 if (frameNumber > 0) producer->seek(frameNumber);
829 duration = duration > 0 ? duration : producer->get_playtime();
830 filePropertyMap["duration"] = QString::number(duration);
831 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
833 if (type == SLIDESHOW) {
834 int ttl = info.xml.hasAttribute("ttl") ? info.xml.attribute("ttl").toInt() : 0;
835 if (ttl) producer->set("ttl", ttl);
836 if (!info.xml.attribute("animation").isEmpty()) {
837 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
838 if (filter && filter->is_valid()) {
840 QString geometry = SlideshowClip::animationToGeometry(info.xml.attribute("animation"), cycle);
841 if (!geometry.isEmpty()) {
842 if (info.xml.attribute("animation").contains("low-pass")) {
843 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
844 if (blur && blur->is_valid())
845 producer->attach(*blur);
847 filter->set("transition.geometry", geometry.toUtf8().data());
848 filter->set("transition.cycle", cycle);
849 producer->attach(*filter);
853 if (info.xml.attribute("fade") == "1") {
854 // user wants a fade effect to slideshow
855 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
856 if (filter && filter->is_valid()) {
857 if (ttl) filter->set("cycle", ttl);
858 if (info.xml.hasAttribute("luma_duration") && !info.xml.attribute("luma_duration").isEmpty()) filter->set("duration", info.xml.attribute("luma_duration").toInt());
859 if (info.xml.hasAttribute("luma_file") && !info.xml.attribute("luma_file").isEmpty()) {
860 filter->set("luma.resource", info.xml.attribute("luma_file").toUtf8().constData());
861 if (info.xml.hasAttribute("softness")) {
862 int soft = info.xml.attribute("softness").toInt();
863 filter->set("luma.softness", (double) soft / 100.0);
866 producer->attach(*filter);
869 if (info.xml.attribute("crop") == "1") {
870 // user wants to center crop the slides
871 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
872 if (filter && filter->is_valid()) {
873 filter->set("center", 1);
874 producer->attach(*filter);
880 const QString mltService = producer->get("mlt_service");
882 if (mltService == "xml" || mltService == "consumer") {
884 mlt_profile prof = producer->get_profile();
885 filePropertyMap["progressive"] = QString::number(prof->progressive);
886 filePropertyMap["colorspace"] = QString::number(prof->colorspace);
887 filePropertyMap["fps"] = QString::number(mlt_profile_fps(prof));
889 else if (mltService == "avformat") {
891 vindex = producer->get_int("video_index");
894 int streams = producer->get_int("meta.media.nb_streams");
895 QList <int> audio_list;
896 QList <int> video_list;
897 for (int i = 0; i < streams; i++) {
898 QByteArray propertyName = QString("meta.media.%1.stream.type").arg(i).toLocal8Bit();
899 QString type = producer->get(propertyName.data());
900 if (type == "audio") audio_list.append(i);
901 else if (type == "video") video_list.append(i);
904 if (!info.xml.hasAttribute("video_index") && video_list.count() > 1) {
905 // Clip has more than one video stream, ask which one should be used
906 QMap <QString, QString> data;
907 if (info.xml.hasAttribute("group")) data.insert("group", info.xml.attribute("group"));
908 if (info.xml.hasAttribute("groupId")) data.insert("groupId", info.xml.attribute("groupId"));
909 emit multiStreamFound(path, audio_list, video_list, data);
910 // Force video index so that when reloading the clip we don't ask again for other streams
911 filePropertyMap["video_index"] = QString::number(vindex);
915 snprintf(property, sizeof(property), "meta.media.%d.stream.frame_rate", vindex);
916 if (producer->get(property))
917 filePropertyMap["fps"] = producer->get(property);
920 if (!filePropertyMap.contains("fps")) {
921 if (producer->get_double("meta.media.frame_rate_den") > 0) {
922 filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
923 } else filePropertyMap["fps"] = producer->get("source_fps");
927 Mlt::Frame *frame = producer->get_frame();
928 if (frame && frame->is_valid()) {
929 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
930 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
931 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
932 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
934 if (frame->get_int("test_image") == 0) {
935 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
936 filePropertyMap["type"] = "playlist";
937 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
938 } else if (frame->get_int("test_audio") == 0)
939 filePropertyMap["type"] = "av";
941 filePropertyMap["type"] = "video";
947 img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
948 variance = KThumb::imageVariance(img);
949 if (frameNumber == -1 && variance< 6) {
950 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
951 frameNumber = duration > 100 ? 100 : duration / 2 ;
952 producer->seek(frameNumber);
954 frame = producer->get_frame();
957 } while (variance == -1);
959 if (frameNumber > -1) filePropertyMap["thumbnail"] = QString::number(frameNumber);
960 emit replyGetImage(info.clipId, img);
961 } else if (frame->get_int("test_audio") == 0) {
962 emit replyGetImage(info.clipId, "audio-x-generic", fullWidth, info.imageHeight);
963 filePropertyMap["type"] = "audio";
966 // Retrieve audio / video codec name
969 if (mltService == "avformat") {
971 /*if (context->duration == AV_NOPTS_VALUE) {
972 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
973 emit removeInvalidClip(clipId);
977 // Get the video_index
979 int default_audio = producer->get_int("audio_index");
982 int scan = producer->get_int("meta.media.progressive");
983 filePropertyMap["progressive"] = QString::number(scan);
985 // Find maximum stream index values
986 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
987 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
988 QString type = producer->get(property);
991 else if (type == "audio")
994 filePropertyMap["default_video"] = QString::number(vindex);
995 filePropertyMap["video_max"] = QString::number(video_max);
996 filePropertyMap["default_audio"] = QString::number(default_audio);
997 filePropertyMap["audio_max"] = QString::number(audio_max);
999 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex);
1000 if (producer->get(property)) {
1001 filePropertyMap["videocodec"] = producer->get(property);
1003 snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex);
1004 if (producer->get(property))
1005 filePropertyMap["videocodec"] = producer->get(property);
1008 query = QString("meta.media.%1.codec.pix_fmt").arg(vindex);
1009 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
1010 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
1012 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
1013 if (producer->get_int("audio_index") > -1) {
1014 // Get the audio_index
1015 int index = producer->get_int("audio_index");
1016 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
1017 if (producer->get(property)) {
1018 filePropertyMap["audiocodec"] = producer->get(property);
1020 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
1021 if (producer->get(property))
1022 filePropertyMap["audiocodec"] = producer->get(property);
1028 Mlt::Properties metadata;
1029 metadata.pass_values(*producer, "meta.attr.");
1030 int count = metadata.count();
1031 for (int i = 0; i < count; i ++) {
1032 QString name = metadata.get_name(i);
1033 QString value = QString::fromUtf8(metadata.get(i));
1034 if (name.endsWith("markup") && !value.isEmpty())
1035 metadataPropertyMap[ name.section('.', 0, -2)] = value;
1038 m_processingClipId.clear();
1039 emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer);
1041 m_processingClipId.clear();
1046 /** Create the producer from the MLT XML QDomDocument */
1047 void Render::initSceneList()
1049 kDebug() << "-------- INIT SCENE LIST ------_";
1051 QDomElement mlt = doc.createElement("mlt");
1052 doc.appendChild(mlt);
1053 QDomElement prod = doc.createElement("producer");
1054 prod.setAttribute("resource", "colour");
1055 prod.setAttribute("colour", "red");
1056 prod.setAttribute("id", "black");
1057 prod.setAttribute("in", "0");
1058 prod.setAttribute("out", "0");
1060 QDomElement tractor = doc.createElement("tractor");
1061 QDomElement multitrack = doc.createElement("multitrack");
1063 QDomElement playlist1 = doc.createElement("playlist");
1064 playlist1.appendChild(prod);
1065 multitrack.appendChild(playlist1);
1066 QDomElement playlist2 = doc.createElement("playlist");
1067 multitrack.appendChild(playlist2);
1068 QDomElement playlist3 = doc.createElement("playlist");
1069 multitrack.appendChild(playlist3);
1070 QDomElement playlist4 = doc.createElement("playlist");
1071 multitrack.appendChild(playlist4);
1072 QDomElement playlist5 = doc.createElement("playlist");
1073 multitrack.appendChild(playlist5);
1074 tractor.appendChild(multitrack);
1075 mlt.appendChild(tractor);
1076 // kDebug()<<doc.toString();
1078 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
1079 setSceneList(doc, 0);
1083 int Render::setProducer(Mlt::Producer *producer, int position)
1085 m_refreshTimer.stop();
1086 requestedSeekPosition = SEEK_INACTIVE;
1087 QMutexLocker locker(&m_mutex);
1089 int consumerPosition = 0;
1090 if (m_winid == -1 || !m_mltConsumer) {
1091 kDebug()<<" / / / / WARNING, MONITOR NOT READY";
1092 if (producer) delete producer;
1095 m_mltConsumer->set("refresh", 0);
1096 if (!m_mltConsumer->is_stopped()) {
1097 m_mltConsumer->stop();
1099 m_mltConsumer->purge();
1100 consumerPosition = m_mltConsumer->position();
1104 if (!producer || !producer->is_valid()) {
1105 if (producer) delete producer;
1106 producer = m_blackClip->cut(0, 1);
1109 if (!producer || !producer->is_valid()) {
1110 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
1113 if (m_mltProducer) currentId = m_mltProducer->get("id");
1115 if (position == -1 && producer->get("id") == currentId) position = consumerPosition;
1116 if (position != -1) producer->seek(position);
1117 int volume = KdenliveSettings::volume();
1118 producer->set("meta.volume", (double)volume / 100);
1119 m_fps = producer->get_fps();
1120 blockSignals(false);
1121 m_mltConsumer->connect(*producer);
1123 if (m_mltProducer) {
1124 m_mltProducer->set_speed(0);
1125 delete m_mltProducer;
1126 m_mltProducer = NULL;
1128 m_mltProducer = producer;
1129 m_mltProducer->set_speed(0);
1130 emit durationChanged(m_mltProducer->get_playtime());
1131 if (m_mltConsumer->start() == -1) {
1132 // ARGH CONSUMER BROKEN!!!!
1133 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."));
1134 if (m_showFrameEvent) delete m_showFrameEvent;
1135 m_showFrameEvent = NULL;
1136 if (m_pauseEvent) delete m_pauseEvent;
1137 m_pauseEvent = NULL;
1138 delete m_mltConsumer;
1139 m_mltConsumer = NULL;
1143 position = m_mltProducer->position();
1144 m_mltConsumer->set("refresh", 1);
1145 // Make sure the first frame is displayed, otherwise if we change producer too fast
1146 // We can crash the avformat producer
1147 Mlt::Event *ev = m_mltConsumer->setup_wait_for("consumer-frame-show");
1148 m_mltConsumer->wait_for(ev);
1150 emit rendererPosition(position);
1154 int Render::setSceneList(QDomDocument list, int position)
1156 return setSceneList(list.toString(), position);
1159 int Render::setSceneList(QString playlist, int position)
1161 requestedSeekPosition = SEEK_INACTIVE;
1162 m_refreshTimer.stop();
1163 QMutexLocker locker(&m_mutex);
1164 if (m_winid == -1) return -1;
1167 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
1169 // Remove previous profile info
1171 doc.setContent(playlist);
1172 QDomElement profile = doc.documentElement().firstChildElement("profile");
1173 doc.documentElement().removeChild(profile);
1174 playlist = doc.toString();
1176 if (m_mltConsumer) {
1177 if (!m_mltConsumer->is_stopped()) {
1178 m_mltConsumer->stop();
1180 m_mltConsumer->set("refresh", 0);
1182 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
1185 m_requestList.clear();
1186 m_infoThread.waitForFinished();
1188 if (m_mltProducer) {
1189 m_mltProducer->set_speed(0);
1190 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1192 /*Mlt::Service service(m_mltProducer->parent().get_service());
1195 if (service.type() == tractor_type) {
1196 Mlt::Tractor tractor(service);
1197 Mlt::Field *field = tractor.field();
1198 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1199 mlt_service nextservicetodisconnect;
1200 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1201 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1202 QString resource = mlt_properties_get(properties, "mlt_service");
1203 // Delete all transitions
1204 while (mlt_type == "transition") {
1205 nextservicetodisconnect = nextservice;
1206 nextservice = mlt_service_producer(nextservice);
1207 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1208 if (nextservice == NULL) break;
1209 properties = MLT_SERVICE_PROPERTIES(nextservice);
1210 mlt_type = mlt_properties_get(properties, "mlt_type");
1211 resource = mlt_properties_get(properties, "mlt_service");
1215 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1216 Mlt::Producer trackProducer(tractor.track(trackNb));
1217 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1218 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1224 qDeleteAll(m_slowmotionProducers.values());
1225 m_slowmotionProducers.clear();
1227 delete m_mltProducer;
1228 m_mltProducer = NULL;
1233 m_locale = QLocale();
1234 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1235 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1236 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1237 m_mltProducer = m_blackClip->cut(0, 1);
1241 int volume = KdenliveSettings::volume();
1242 m_mltProducer->set("meta.volume", (double)volume / 100);
1243 m_mltProducer->optimise();
1245 /*if (KdenliveSettings::osdtimecode()) {
1246 // Attach filter for on screen display of timecode
1248 QString attr = "attr_check";
1249 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1250 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1251 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1252 mlt_filter_close( filter );
1254 m_osdInfo = new Mlt::Filter("data_show");
1255 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1256 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1257 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1258 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1259 m_osdInfo->set("dynamic", "1");
1261 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1263 m_osdInfo->set("dynamic", "0");
1266 m_fps = m_mltProducer->get_fps();
1267 if (position != 0) {
1268 // Seek to correct place after opening project.
1269 m_mltProducer->seek(position);
1272 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1273 m_mltConsumer->connect(*m_mltProducer);
1274 m_mltProducer->set_speed(0);
1275 fillSlowMotionProducers();
1276 blockSignals(false);
1277 emit durationChanged(m_mltProducer->get_playtime());
1280 //kDebug()<<"// SETSCN LST, POS: "<<position;
1281 //if (position != 0) emit rendererPosition(position);
1284 void Render::checkMaxThreads()
1286 // Make sure we don't use too much threads, MLT avformat does not cope with too much threads
1287 // Currently, Kdenlive uses the following avformat threads:
1288 // One thread to get info when adding a clip
1289 // One thread to create the timeline video thumbnails
1290 // One thread to create the audio thumbnails
1291 Mlt::Service service(m_mltProducer->parent().get_service());
1292 if (service.type() != tractor_type) {
1293 kWarning() << "// TRACTOR PROBLEM";
1296 Mlt::Tractor tractor(service);
1297 int mltMaxThreads = mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1298 int requestedThreads = tractor.count() + 4;
1299 if (requestedThreads > mltMaxThreads) {
1300 mlt_service_cache_set_size(service.get_service(), "producer_avformat", requestedThreads);
1301 kDebug()<<"// MLT threads updated to: "<<mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1305 const QString Render::sceneList()
1308 Mlt::Profile profile((mlt_profile) 0);
1309 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1310 if (!xmlConsumer.is_valid()) return QString();
1311 m_mltProducer->optimise();
1312 xmlConsumer.set("terminate_on_pause", 1);
1313 Mlt::Producer prod(m_mltProducer->get_producer());
1314 if (!prod.is_valid()) return QString();
1315 bool split = m_isSplitView;
1316 if (split) slotSplitView(false);
1317 xmlConsumer.connect(prod);
1319 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1320 if (split) slotSplitView(true);
1324 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1328 doc.setContent(sceneList(), false);
1329 if (doc.isNull()) return false;
1330 QDomElement root = doc.documentElement();
1331 if (!kdenliveData.isNull() && !root.isNull()) {
1332 // add Kdenlive specific tags
1333 root.appendChild(doc.importNode(kdenliveData, true));
1335 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1336 kWarning() << "////// ERROR writing to file: " << path;
1339 file.write(doc.toString().toUtf8());
1340 if (file.error() != QFile::NoError) {
1348 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1350 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1351 m_mltProducer->optimise();
1352 xmlConsumer.set("terminate_on_pause", 1);
1353 if (m_name == Kdenlive::clipMonitor) {
1354 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1356 list.insert_at(0, prod, 0);
1358 list.set("title", desc.toUtf8().constData());
1359 xmlConsumer.connect(list);
1362 //TODO: not working yet, save zone from timeline
1363 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1364 /* Mlt::Service service(p1->parent().get_service());
1365 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1367 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1368 //prod->set("title", desc.toUtf8().constData());
1369 xmlConsumer.connect(*p1); //list);
1372 xmlConsumer.start();
1376 bool Render::saveClip(int track, GenTime position, KUrl url, QString desc)
1379 Mlt::Service service(m_mltProducer->parent().get_service());
1380 Mlt::Tractor tractor(service);
1381 Mlt::Producer trackProducer(tractor.track(track));
1382 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1384 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1385 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1387 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1391 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1392 xmlConsumer.set("terminate_on_pause", 1);
1394 list.insert_at(0, clip, 0);
1396 list.set("title", desc.toUtf8().constData());
1397 xmlConsumer.connect(list);
1399 kDebug()<<"// SAVED: "<<url;
1403 double Render::fps() const
1408 int Render::volume() const
1410 if (!m_mltConsumer || !m_mltProducer) return -1;
1411 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1414 void Render::slotSetVolume(int volume)
1416 if (!m_mltConsumer || !m_mltProducer) return;
1417 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1420 m_mltConsumer->set("refresh", 0);
1421 // Attach filter for on screen display of timecode
1422 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1423 mlt_properties_set_double( properties, "meta.volume", volume );
1424 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1425 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1427 if (!KdenliveSettings::osdtimecode()) {
1428 m_mltProducer->detach(*m_osdInfo);
1429 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1430 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1433 //m_osdTimer->setSingleShot(2500);
1436 void Render::slotOsdTimeout()
1438 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1439 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1440 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1441 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1445 void Render::start()
1447 m_refreshTimer.stop();
1448 QMutexLocker locker(&m_mutex);
1449 if (m_winid == -1) {
1450 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1453 if (!m_mltConsumer) return;
1454 if (m_mltConsumer->is_stopped()) {
1455 if (m_mltConsumer->start() == -1) {
1456 //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."));
1457 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1459 m_mltConsumer->purge();
1460 m_mltConsumer->set("refresh", 1);
1467 requestedSeekPosition = SEEK_INACTIVE;
1468 m_refreshTimer.stop();
1469 QMutexLocker locker(&m_mutex);
1470 if (m_mltProducer == NULL) return;
1471 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1472 m_mltConsumer->stop();
1473 m_mltConsumer->purge();
1476 if (m_mltProducer) {
1477 if (m_isZoneMode) resetZoneMode();
1478 m_mltProducer->set_speed(0.0);
1482 void Render::stop(const GenTime & startTime)
1484 requestedSeekPosition = SEEK_INACTIVE;
1485 m_refreshTimer.stop();
1486 QMutexLocker locker(&m_mutex);
1487 if (m_mltProducer) {
1488 if (m_isZoneMode) resetZoneMode();
1489 m_mltProducer->set_speed(0.0);
1490 m_mltProducer->seek((int) startTime.frames(m_fps));
1492 m_mltConsumer->purge();
1495 void Render::pause()
1497 requestedSeekPosition = SEEK_INACTIVE;
1498 if (!m_mltProducer || !m_mltConsumer)
1500 if (m_mltProducer->get_speed() == 0.0) return;
1501 if (m_isZoneMode) resetZoneMode();
1502 m_mltConsumer->set("refresh", 0);
1503 m_mltProducer->set_speed(0.0);
1504 m_mltConsumer->purge();
1507 void Render::switchPlay(bool play)
1509 QMutexLocker locker(&m_mutex);
1510 requestedSeekPosition = SEEK_INACTIVE;
1511 if (!m_mltProducer || !m_mltConsumer)
1513 if (m_isZoneMode) resetZoneMode();
1514 if (play && m_mltProducer->get_speed() == 0.0) {
1515 if (m_name == Kdenlive::clipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
1516 if (m_mltConsumer->is_stopped()) {
1517 m_mltConsumer->start();
1519 m_mltProducer->set_speed(1.0);
1520 m_mltConsumer->set("refresh", 1);
1522 m_mltProducer->set_speed(0.0);
1523 m_mltConsumer->set("refresh", 0);
1524 m_mltProducer->seek(m_mltConsumer->position());
1525 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1526 if (m_isZoneMode) resetZoneMode();
1528 //emitConsumerStopped();
1529 /*m_mltConsumer->set("refresh", 0);
1530 m_mltConsumer->stop();
1531 m_mltConsumer->purge();
1532 m_mltProducer->set_speed(0.0);
1533 //m_framePosition = m_mltProducer->position();
1534 m_mltProducer->seek(m_framePosition);
1535 emit rendererPosition(m_framePosition);*/
1539 void Render::play(double speed)
1541 requestedSeekPosition = SEEK_INACTIVE;
1544 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1545 m_mltProducer->set_speed(speed);
1546 /*if (speed == 0.0) {
1547 m_mltProducer->seek((int) m_framePosition + 1);
1548 m_mltConsumer->purge();
1553 void Render::play(const GenTime & startTime)
1555 requestedSeekPosition = SEEK_INACTIVE;
1556 if (!m_mltProducer || !m_mltConsumer)
1558 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1559 m_mltProducer->set_speed(1.0);
1560 m_mltConsumer->set("refresh", 1);
1563 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1565 requestedSeekPosition = SEEK_INACTIVE;
1566 if (!m_mltProducer || !m_mltConsumer)
1568 //m_mltProducer->set("eof", "loop");
1569 m_isLoopMode = true;
1570 m_loopStart = startTime;
1571 playZone(startTime, stopTime);
1574 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1576 requestedSeekPosition = SEEK_INACTIVE;
1577 if (!m_mltProducer || !m_mltConsumer)
1579 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1580 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1581 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1582 m_mltProducer->set_speed(1.0);
1583 m_mltConsumer->set("refresh", 1);
1584 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1585 m_isZoneMode = true;
1588 void Render::resetZoneMode()
1590 if (!m_mltProducer || (!m_isZoneMode && !m_isLoopMode)) return;
1591 m_mltProducer->set("out", m_originalOut);
1592 //m_mltProducer->set("eof", "pause");
1593 m_isZoneMode = false;
1594 m_isLoopMode = false;
1597 void Render::seekToFrame(int pos)
1603 void Render::seekToFrameDiff(int diff)
1606 if (requestedSeekPosition == SEEK_INACTIVE)
1607 seek(m_mltProducer->position() + diff);
1608 else seek(requestedSeekPosition + diff);
1611 void Render::doRefresh()
1613 if (m_mltProducer && m_mltProducer->get_speed() == 0) m_refreshTimer.start();
1616 void Render::refresh()
1618 QMutexLocker locker(&m_mutex);
1621 if (m_mltConsumer) {
1622 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1623 m_mltConsumer->purge();
1624 m_mltConsumer->set("refresh", 1);
1628 void Render::setDropFrames(bool show)
1630 QMutexLocker locker(&m_mutex);
1631 if (m_mltConsumer) {
1632 int dropFrames = KdenliveSettings::mltthreads();
1633 if (show == false) dropFrames = -dropFrames;
1634 m_mltConsumer->stop();
1636 m_mltConsumer->set("real_time", dropFrames);
1638 m_mltConsumer->set("play.real_time", dropFrames);
1640 if (m_mltConsumer->start() == -1) {
1641 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1647 double Render::playSpeed() const
1649 if (m_mltProducer) return m_mltProducer->get_speed();
1653 GenTime Render::seekPosition() const
1655 if (m_mltConsumer) return GenTime((int) m_mltConsumer->position(), m_fps);
1656 //if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1657 else return GenTime();
1660 int Render::seekFramePosition() const
1662 //if (m_mltProducer) return (int) m_mltProducer->position();
1663 if (m_mltConsumer) return (int) m_mltConsumer->position();
1667 void Render::emitFrameUpdated(Mlt::Frame& frame)
1669 mlt_image_format format = mlt_image_rgb24a;
1672 const uchar* image = frame.get_image(format, width, height);
1673 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1674 memcpy(qimage.scanLine(0), image, width * height * 4);
1676 /*mlt_image_format format = mlt_image_rgb24;
1679 const uchar* image = frame.get_image(format, width, height);
1680 QImage qimage(width, height, QImage::Format_RGB888);
1681 memcpy(qimage.bits(), image, width * height * 3);*/
1682 emit frameUpdated(qimage.rgbSwapped());
1685 void Render::emitFrameNumber()
1687 int currentPos = m_mltConsumer->position();
1688 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1689 emit rendererPosition(currentPos);
1690 if (requestedSeekPosition != SEEK_INACTIVE) {
1691 m_mltProducer->seek(requestedSeekPosition);
1692 requestedSeekPosition = SEEK_INACTIVE;
1693 if (m_mltProducer->get_speed() == 0) {
1699 void Render::emitConsumerStopped()
1701 // This is used to know when the playing stopped
1702 if (m_mltProducer) {
1703 double pos = m_mltProducer->position();
1704 if (m_isLoopMode) play(m_loopStart);
1705 //else if (m_isZoneMode) resetZoneMode();
1706 emit rendererStopped((int) pos);
1710 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1712 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1715 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1717 if (!m_mltProducer) {
1718 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1722 //int height = 1080;//KdenliveSettings::defaultheight();
1723 //int width = 1940; //KdenliveSettings::displaywidth();
1725 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1727 QPixmap pix(width, height);
1728 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1729 m_convert.set("forced", mlt_image_rgb24a);
1730 m_mltProducer->attach(m_convert);
1731 Mlt::Frame * frame = m_mltProducer->get_frame();
1732 m_mltProducer->detach(m_convert);
1734 pix = frameThumbnail(frame, width, height);
1737 pix.save(url.path(), "PNG");
1738 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1742 void Render::showFrame(Mlt::Frame& frame)
1744 emit rendererPosition((int) m_mltConsumer->position());
1745 mlt_image_format format = mlt_image_rgb24a;
1748 const uchar* image = frame.get_image(format, width, height);
1749 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1750 memcpy(qimage.scanLine(0), image, width * height * 4);
1751 emit showImageSignal(qimage);
1752 if (analyseAudio) showAudio(frame);
1753 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1754 emit frameUpdated(qimage.rgbSwapped());
1758 void Render::disablePreview(bool disable)
1760 if (m_mltConsumer) {
1761 m_mltConsumer->stop();
1762 m_mltConsumer->set("preview_off", (int) disable);
1763 m_mltConsumer->set("refresh", 0);
1764 m_mltConsumer->start();
1768 void Render::showAudio(Mlt::Frame& frame)
1770 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1773 mlt_audio_format audio_format = mlt_audio_s16;
1774 //FIXME: should not be hardcoded..
1776 int num_channels = 2;
1778 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1784 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1785 // So the vector is of size samples*channels.
1786 QVector<int16_t> sampleVector(samples*num_channels);
1787 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1790 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1795 * MLT playlist direct manipulation.
1798 void Render::mltCheckLength(Mlt::Tractor *tractor)
1800 //kDebug()<<"checking track length: "<<track<<"..........";
1802 int trackNb = tractor->count();
1806 Mlt::Producer trackProducer(tractor->track(0));
1807 duration = trackProducer.get_playtime() - 1;
1808 m_mltProducer->set("out", duration);
1809 emit durationChanged(duration);
1812 while (trackNb > 1) {
1813 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1814 trackDuration = trackProducer.get_playtime() - 1;
1815 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1816 if (trackDuration > duration) duration = trackDuration;
1820 Mlt::Producer blackTrackProducer(tractor->track(0));
1822 if (blackTrackProducer.get_playtime() - 1 != duration) {
1823 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1824 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1825 if (blackclip && blackclip->is_blank()) {
1830 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1831 if (blackclip) delete blackclip;
1832 blackTrackPlaylist.clear();
1833 m_blackClip->set("length", duration + 1);
1834 m_blackClip->set("out", duration);
1835 blackclip = m_blackClip->cut(0, duration);
1836 blackTrackPlaylist.insert_at(0, blackclip, 1);
1838 if (duration > blackclip->parent().get_length()) {
1839 blackclip->parent().set("length", duration + 1);
1840 blackclip->parent().set("out", duration);
1841 blackclip->set("length", duration + 1);
1843 blackTrackPlaylist.resize_clip(0, 0, duration);
1847 m_mltProducer->set("out", duration);
1848 emit durationChanged(duration);
1852 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1854 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1856 // We want a slowmotion producer
1857 double speed = element.attribute("speed", "1.0").toDouble();
1858 int strobe = element.attribute("strobe", "1").toInt();
1859 QString url = QString::fromUtf8(prod->get("resource"));
1860 url.append('?' + locale.toString(speed));
1861 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1862 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1863 if (!slowprod || slowprod->get_producer() == NULL) {
1864 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
1865 if (strobe > 1) slowprod->set("strobe", strobe);
1866 QString id = prod->parent().get("id");
1867 if (id.contains('_')) id = id.section('_', 0, 0);
1868 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
1869 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1870 slowprod->set("id", producerid.toUtf8().constData());
1871 m_slowmotionProducers.insert(url, slowprod);
1876 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1878 if (m_mltProducer == NULL) {
1879 kDebug() << "PLAYLIST NOT INITIALISED //////";
1883 kDebug() << "Cannot insert clip without producer //////";
1886 Mlt::Producer parentProd(m_mltProducer->parent());
1887 if (parentProd.get_producer() == NULL) {
1888 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1892 Mlt::Service service(parentProd.get_service());
1893 if (service.type() != tractor_type) {
1894 kWarning() << "// TRACTOR PROBLEM";
1897 Mlt::Tractor tractor(service);
1898 if (info.track > tractor.count() - 1) {
1899 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1903 Mlt::Producer trackProducer(tractor.track(info.track));
1904 int trackDuration = trackProducer.get_playtime() - 1;
1905 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1906 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1907 prod = checkSlowMotionProducer(prod, element);
1908 if (prod == NULL || !prod->is_valid()) {
1913 int cutPos = (int) info.cropStart.frames(m_fps);
1914 if (cutPos < 0) cutPos = 0;
1915 int insertPos = (int) info.startPos.frames(m_fps);
1916 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1917 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1918 if (overwrite && (insertPos < trackDuration)) {
1919 // Replace zone with blanks
1920 //trackPlaylist.split_at(insertPos, true);
1921 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1922 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1923 trackPlaylist.insert_blank(clipIndex, cutDuration);
1925 trackPlaylist.split_at(insertPos, true);
1926 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1927 trackPlaylist.insert_blank(clipIndex, cutDuration);
1929 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1931 /*if (QString(prod->get("transparency")).toInt() == 1)
1932 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1934 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1936 /*tractor.multitrack()->refresh();
1937 tractor.refresh();*/
1942 bool Render::mltCutClip(int track, GenTime position)
1944 Mlt::Service service(m_mltProducer->parent().get_service());
1945 if (service.type() != tractor_type) {
1946 kWarning() << "// TRACTOR PROBLEM";
1950 Mlt::Tractor tractor(service);
1951 Mlt::Producer trackProducer(tractor.track(track));
1952 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1955 /* // Display playlist info
1956 kDebug()<<"//////////// BEFORE";
1957 for (int i = 0; i < trackPlaylist.count(); i++) {
1958 int blankStart = trackPlaylist.clip_start(i);
1959 int blankDuration = trackPlaylist.clip_length(i) - 1;
1961 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1962 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1965 int cutPos = (int) position.frames(m_fps);
1967 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1968 if (trackPlaylist.is_blank(clipIndex)) {
1969 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1973 int clipStart = trackPlaylist.clip_start(clipIndex);
1974 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1977 // duplicate effects
1978 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1979 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1981 if (original == NULL || clip == NULL) {
1982 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1986 Mlt::Service clipService(original->get_service());
1987 Mlt::Service dupService(clip->get_service());
1993 Mlt::Filter *filter = clipService.filter(ct);
1995 // Only duplicate Kdenlive filters, and skip the fade in effects
1996 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1997 // looks like there is no easy way to duplicate a filter,
1998 // so we will create a new one and duplicate its properties
1999 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
2000 if (dup && dup->is_valid()) {
2001 Mlt::Properties entries(filter->get_properties());
2002 for (int i = 0; i < entries.count(); i++) {
2003 dup->set(entries.get_name(i), entries.get(i));
2005 dupService.attach(*dup);
2009 filter = clipService.filter(ct);
2012 /* // Display playlist info
2013 kDebug()<<"//////////// AFTER";
2014 for (int i = 0; i < trackPlaylist.count(); i++) {
2015 int blankStart = trackPlaylist.clip_start(i);
2016 int blankDuration = trackPlaylist.clip_length(i) - 1;
2018 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2019 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2024 Mlt::Tractor *Render::lockService()
2026 // we are going to replace some clips, purge consumer
2027 QMutexLocker locker(&m_mutex);
2028 if (!m_mltProducer) return NULL;
2029 if (m_mltConsumer) {
2030 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
2031 m_mltConsumer->purge();
2033 Mlt::Service service(m_mltProducer->parent().get_service());
2034 if (service.type() != tractor_type) {
2035 kWarning() << "// TRACTOR PROBLEM";
2039 return new Mlt::Tractor(service);
2043 void Render::unlockService(Mlt::Tractor *tractor)
2048 if (!m_mltProducer) return;
2049 Mlt::Service service(m_mltProducer->parent().get_service());
2050 if (service.type() != tractor_type) {
2051 kWarning() << "// TRACTOR PROBLEM";
2057 bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement element, Mlt::Producer *prod)
2060 if (prod == NULL || tractor == NULL) {
2061 kDebug() << "Cannot update clip with null producer //////";
2065 Mlt::Producer trackProducer(tractor->track(tractor->count() - 1 - info.track));
2066 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2067 int startPos = info.startPos.frames(m_fps);
2068 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2069 if (trackPlaylist.is_blank(clipIndex)) {
2070 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
2073 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2075 QList <Mlt::Filter *> filtersList;
2076 Mlt::Service sourceService(clip->get_service());
2078 Mlt::Filter *filter = sourceService.filter(ct);
2080 if (filter->get_int("kdenlive_ix") != 0) {
2081 filtersList.append(filter);
2084 filter = sourceService.filter(ct);
2087 clip = trackPlaylist.replace_with_blank(clipIndex);
2089 prod = checkSlowMotionProducer(prod, element);
2090 if (prod == NULL || !prod->is_valid()) {
2094 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
2095 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
2096 Mlt::Service destService(clip2->get_service());
2099 if (!filtersList.isEmpty()) {
2100 for (int i = 0; i < filtersList.count(); i++)
2101 destService.attach(*(filtersList.at(i)));
2107 bool Render::mltRemoveClip(int track, GenTime position)
2109 Mlt::Service service(m_mltProducer->parent().get_service());
2110 if (service.type() != tractor_type) {
2111 kWarning() << "// TRACTOR PROBLEM";
2115 Mlt::Tractor tractor(service);
2116 Mlt::Producer trackProducer(tractor.track(track));
2117 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2118 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2120 if (trackPlaylist.is_blank(clipIndex)) {
2121 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
2125 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2126 if (clip) delete clip;
2127 trackPlaylist.consolidate_blanks(0);
2129 /* // Display playlist info
2130 kDebug()<<"//// AFTER";
2131 for (int i = 0; i < trackPlaylist.count(); i++) {
2132 int blankStart = trackPlaylist.clip_start(i);
2133 int blankDuration = trackPlaylist.clip_length(i) - 1;
2135 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2136 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2139 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
2143 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
2145 if (!m_mltProducer) {
2146 kDebug() << "PLAYLIST NOT INITIALISED //////";
2149 Mlt::Producer parentProd(m_mltProducer->parent());
2150 if (parentProd.get_producer() == NULL) {
2151 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2155 Mlt::Service service(parentProd.get_service());
2156 Mlt::Tractor tractor(service);
2157 int insertPos = pos.frames(m_fps);
2159 Mlt::Producer trackProducer(tractor.track(track));
2160 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2161 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2162 if (clipIndex == trackPlaylist.count()) {
2163 // We are after the end of the playlist
2166 if (!trackPlaylist.is_blank(clipIndex)) return 0;
2167 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
2168 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
2171 int Render::mltTrackDuration(int track)
2173 if (!m_mltProducer) {
2174 kDebug() << "PLAYLIST NOT INITIALISED //////";
2177 Mlt::Producer parentProd(m_mltProducer->parent());
2178 if (parentProd.get_producer() == NULL) {
2179 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2183 Mlt::Service service(parentProd.get_service());
2184 Mlt::Tractor tractor(service);
2186 Mlt::Producer trackProducer(tractor.track(track));
2187 return trackProducer.get_playtime() - 1;
2190 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
2192 if (!m_mltProducer) {
2193 kDebug() << "PLAYLIST NOT INITIALISED //////";
2196 Mlt::Producer parentProd(m_mltProducer->parent());
2197 if (parentProd.get_producer() == NULL) {
2198 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2201 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
2202 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
2204 Mlt::Service service(parentProd.get_service());
2205 Mlt::Tractor tractor(service);
2207 int diff = duration.frames(m_fps);
2208 int offset = timeOffset.frames(m_fps);
2212 // insert space in one track only
2213 Mlt::Producer trackProducer(tractor.track(track));
2214 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2215 insertPos = trackClipStartList.value(track);
2216 if (insertPos != -1) {
2217 insertPos += offset;
2218 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2220 trackPlaylist.insert_blank(clipIndex, diff - 1);
2222 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
2223 if (!trackPlaylist.is_blank(clipIndex)) {
2224 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2226 int position = trackPlaylist.clip_start(clipIndex);
2227 int blankDuration = trackPlaylist.clip_length(clipIndex);
2228 if (blankDuration + diff == 0) {
2229 trackPlaylist.remove(clipIndex);
2230 } else trackPlaylist.remove_region(position, -diff);
2232 trackPlaylist.consolidate_blanks(0);
2234 // now move transitions
2235 mlt_service serv = m_mltProducer->parent().get_service();
2236 mlt_service nextservice = mlt_service_get_producer(serv);
2237 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2238 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2239 QString resource = mlt_properties_get(properties, "mlt_service");
2241 while (mlt_type == "transition") {
2242 mlt_transition tr = (mlt_transition) nextservice;
2243 int currentTrack = mlt_transition_get_b_track(tr);
2244 int currentIn = (int) mlt_transition_get_in(tr);
2245 int currentOut = (int) mlt_transition_get_out(tr);
2246 insertPos = trackTransitionStartList.value(track);
2247 if (insertPos != -1) {
2248 insertPos += offset;
2249 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
2250 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2253 nextservice = mlt_service_producer(nextservice);
2254 if (nextservice == NULL) break;
2255 properties = MLT_SERVICE_PROPERTIES(nextservice);
2256 mlt_type = mlt_properties_get(properties, "mlt_type");
2257 resource = mlt_properties_get(properties, "mlt_service");
2260 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
2261 Mlt::Producer trackProducer(tractor.track(trackNb));
2262 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2264 //int clipNb = trackPlaylist.count();
2265 insertPos = trackClipStartList.value(trackNb);
2266 if (insertPos != -1) {
2267 insertPos += offset;
2269 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2270 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2271 for (int i = 0; i < clipNb; i++) {
2272 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2273 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2274 kDebug()<<"-------------";
2276 kDebug()<<"END-------------";*/
2279 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2281 trackPlaylist.insert_blank(clipIndex, diff - 1);
2283 if (!trackPlaylist.is_blank(clipIndex)) {
2286 if (!trackPlaylist.is_blank(clipIndex)) {
2287 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2289 int position = trackPlaylist.clip_start(clipIndex);
2290 int blankDuration = trackPlaylist.clip_length(clipIndex);
2291 if (diff + blankDuration == 0) {
2292 trackPlaylist.remove(clipIndex);
2293 } else trackPlaylist.remove_region(position, - diff);
2295 trackPlaylist.consolidate_blanks(0);
2298 // now move transitions
2299 mlt_service serv = m_mltProducer->parent().get_service();
2300 mlt_service nextservice = mlt_service_get_producer(serv);
2301 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2302 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2303 QString resource = mlt_properties_get(properties, "mlt_service");
2305 while (mlt_type == "transition") {
2306 mlt_transition tr = (mlt_transition) nextservice;
2307 int currentIn = (int) mlt_transition_get_in(tr);
2308 int currentOut = (int) mlt_transition_get_out(tr);
2309 int currentTrack = mlt_transition_get_b_track(tr);
2310 insertPos = trackTransitionStartList.value(currentTrack);
2311 if (insertPos != -1) {
2312 insertPos += offset;
2313 if (currentOut > insertPos && resource != "mix") {
2314 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2317 nextservice = mlt_service_producer(nextservice);
2318 if (nextservice == NULL) break;
2319 properties = MLT_SERVICE_PROPERTIES(nextservice);
2320 mlt_type = mlt_properties_get(properties, "mlt_type");
2321 resource = mlt_properties_get(properties, "mlt_service");
2325 mltCheckLength(&tractor);
2326 m_mltConsumer->set("refresh", 1);
2330 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2332 if (source == dest) return;
2333 Mlt::Service sourceService(source->get_service());
2334 Mlt::Service destService(dest->get_service());
2336 // move all effects to the correct producer
2338 Mlt::Filter *filter = sourceService.filter(ct);
2340 if (filter->get_int("kdenlive_ix") != 0) {
2341 sourceService.detach(*filter);
2342 destService.attach(*filter);
2344 filter = sourceService.filter(ct);
2348 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2351 Mlt::Service service(m_mltProducer->parent().get_service());
2352 if (service.type() != tractor_type) {
2353 kWarning() << "// TRACTOR PROBLEM";
2357 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2358 Mlt::Tractor tractor(service);
2359 Mlt::Producer trackProducer(tractor.track(info.track));
2360 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2361 int startPos = info.startPos.frames(m_fps);
2362 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2363 int clipLength = trackPlaylist.clip_length(clipIndex);
2365 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2366 if (original == NULL) {
2369 if (!original->is_valid() || original->is_blank()) {
2374 Mlt::Producer clipparent = original->parent();
2375 if (!clipparent.is_valid() || clipparent.is_blank()) {
2381 QString serv = clipparent.get("mlt_service");
2382 QString id = clipparent.get("id");
2383 if (speed <= 0 && speed > -1) speed = 1.0;
2384 //kDebug() << "CLIP SERVICE: " << serv;
2385 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2387 QString url = QString::fromUtf8(clipparent.get("resource"));
2388 url.append('?' + m_locale.toString(speed));
2389 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2390 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2391 if (!slowprod || slowprod->get_producer() == NULL) {
2392 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2393 if (strobe > 1) slowprod->set("strobe", strobe);
2394 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2395 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2396 slowprod->set("id", producerid.toUtf8().constData());
2397 // copy producer props
2398 double ar = original->parent().get_double("force_aspect_ratio");
2399 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2400 double fps = original->parent().get_double("force_fps");
2401 if (fps != 0.0) slowprod->set("force_fps", fps);
2402 int threads = original->parent().get_int("threads");
2403 if (threads != 0) slowprod->set("threads", threads);
2404 if (original->parent().get("force_progressive"))
2405 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2406 if (original->parent().get("force_tff"))
2407 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2408 int ix = original->parent().get_int("video_index");
2409 if (ix != 0) slowprod->set("video_index", ix);
2410 int colorspace = original->parent().get_int("force_colorspace");
2411 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2412 int full_luma = original->parent().get_int("set.force_full_luma");
2413 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2414 m_slowmotionProducers.insert(url, slowprod);
2416 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2417 trackPlaylist.consolidate_blanks(0);
2419 // Check that the blank space is long enough for our new duration
2420 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2421 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2423 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2424 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2425 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2426 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2428 // move all effects to the correct producer
2429 mltPasteEffects(clip, cut);
2430 trackPlaylist.insert_at(startPos, cut, 1);
2433 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2434 newLength = trackPlaylist.clip_length(clipIndex);
2436 } else if (speed == 1.0 && strobe < 2) {
2439 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2440 trackPlaylist.consolidate_blanks(0);
2442 // Check that the blank space is long enough for our new duration
2443 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2444 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2447 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2448 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2449 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2450 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2451 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2453 // move all effects to the correct producer
2454 mltPasteEffects(clip, cut);
2456 trackPlaylist.insert_at(startPos, cut, 1);
2459 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2460 newLength = trackPlaylist.clip_length(clipIndex);
2463 } else if (serv == "framebuffer") {
2465 QString url = QString::fromUtf8(clipparent.get("resource"));
2466 url = url.section('?', 0, 0);
2467 url.append('?' + m_locale.toString(speed));
2468 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2469 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2470 if (!slowprod || slowprod->get_producer() == NULL) {
2471 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2472 slowprod->set("strobe", strobe);
2473 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2474 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2475 slowprod->set("id", producerid.toUtf8().constData());
2476 // copy producer props
2477 double ar = original->parent().get_double("force_aspect_ratio");
2478 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2479 double fps = original->parent().get_double("force_fps");
2480 if (fps != 0.0) slowprod->set("force_fps", fps);
2481 if (original->parent().get("force_progressive"))
2482 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2483 if (original->parent().get("force_tff"))
2484 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2485 int threads = original->parent().get_int("threads");
2486 if (threads != 0) slowprod->set("threads", threads);
2487 int ix = original->parent().get_int("video_index");
2488 if (ix != 0) slowprod->set("video_index", ix);
2489 int colorspace = original->parent().get_int("force_colorspace");
2490 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2491 int full_luma = original->parent().get_int("set.force_full_luma");
2492 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2493 m_slowmotionProducers.insert(url, slowprod);
2495 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2496 trackPlaylist.consolidate_blanks(0);
2498 GenTime duration = speedIndependantInfo.cropDuration / speed;
2499 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2501 // Check that the blank space is long enough for our new duration
2502 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2503 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2506 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2507 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2508 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2509 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2511 // move all effects to the correct producer
2512 mltPasteEffects(clip, cut);
2514 trackPlaylist.insert_at(startPos, cut, 1);
2517 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2518 newLength = trackPlaylist.clip_length(clipIndex);
2523 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2527 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2529 Mlt::Service service(m_mltProducer->parent().get_service());
2530 bool success = false;
2531 Mlt::Tractor tractor(service);
2532 Mlt::Producer trackProducer(tractor.track(track));
2533 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2534 Mlt::Service clipService(trackPlaylist.get_service());
2538 Mlt::Filter *filter = clipService.filter(ct);
2540 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2541 if (clipService.detach(*filter) == 0) success = true;
2542 } else if (updateIndex) {
2543 // Adjust the other effects index
2544 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2547 filter = clipService.filter(ct);
2554 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2556 if (position < GenTime()) {
2557 // Remove track effect
2558 return mltRemoveTrackEffect(track, index, updateIndex);
2560 Mlt::Service service(m_mltProducer->parent().get_service());
2561 bool success = false;
2562 Mlt::Tractor tractor(service);
2563 Mlt::Producer trackProducer(tractor.track(track));
2564 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2566 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2567 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2569 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2573 Mlt::Service clipService(clip->get_service());
2574 int duration = clip->get_playtime();
2576 // Check if clip is visible in monitor
2577 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2578 if (diff < 0 || diff > duration) doRefresh = false;
2584 Mlt::Filter *filter = clipService.filter(ct);
2586 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2587 if (clipService.detach(*filter) == 0) success = true;
2588 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2589 } else if (updateIndex) {
2590 // Adjust the other effects index
2591 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2594 filter = clipService.filter(ct);
2597 if (doRefresh) refresh();
2601 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2603 Mlt::Service service(m_mltProducer->parent().get_service());
2604 Mlt::Tractor tractor(service);
2605 Mlt::Producer trackProducer(tractor.track(track));
2606 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2607 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2608 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2612 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2615 Mlt::Service service(m_mltProducer->parent().get_service());
2617 Mlt::Tractor tractor(service);
2618 Mlt::Producer trackProducer(tractor.track(track));
2619 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2621 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2622 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2627 Mlt::Service clipService(clip->get_service());
2628 int duration = clip->get_playtime();
2630 // Check if clip is visible in monitor
2631 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2632 if (diff < 0 || diff > duration) doRefresh = false;
2635 return mltAddEffect(clipService, params, duration, doRefresh);
2638 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2640 bool updateIndex = false;
2641 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2645 Mlt::Filter *filter = service.filter(ct);
2647 if (filter->get_int("kdenlive_ix") == filter_ix) {
2648 // A filter at that position already existed, so we will increase all indexes later
2653 filter = service.filter(ct);
2656 if (params.paramValue("id") == "speed") {
2657 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2659 filter = service.filter(ct);
2661 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2662 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2665 filter = service.filter(ct);
2668 if (doRefresh) refresh();
2673 // temporarily remove all effects after insert point
2674 QList <Mlt::Filter *> filtersList;
2676 filter = service.filter(ct);
2678 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2679 filtersList.append(filter);
2680 service.detach(*filter);
2682 filter = service.filter(ct);
2685 addFilterToService(service, params, duration);
2687 // re-add following filters
2688 for (int i = 0; i < filtersList.count(); i++) {
2689 Mlt::Filter *filter = filtersList.at(i);
2691 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2692 service.attach(*filter);
2695 if (doRefresh) refresh();
2700 bool Render::addFilterToService(Mlt::Service service, EffectsParameterList params, int duration)
2703 QString tag = params.paramValue("tag");
2704 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2705 char *filterTag = qstrdup(tag.toUtf8().constData());
2706 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2707 QString kfr = params.paramValue("keyframes");
2708 if (!kfr.isEmpty()) {
2709 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2710 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2711 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2712 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2713 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2714 //double max = params.paramValue("max").toDouble();
2715 double min = params.paramValue("min").toDouble();
2716 double factor = params.paramValue("factor", "1").toDouble();
2717 double paramOffset = params.paramValue("offset", "0").toDouble();
2718 params.removeParam("starttag");
2719 params.removeParam("endtag");
2720 params.removeParam("keyframes");
2721 params.removeParam("min");
2722 params.removeParam("max");
2723 params.removeParam("factor");
2724 params.removeParam("offset");
2726 // Special case, only one keyframe, means we want a constant value
2727 if (keyFrames.count() == 1) {
2728 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2729 if (filter && filter->is_valid()) {
2730 filter->set("kdenlive_id", filterId);
2731 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2732 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2733 for (int j = 0; j < params.count(); j++) {
2734 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2736 filter->set("in", x1);
2737 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2738 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2739 service.attach(*filter);
2741 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2742 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2743 if (filter && filter->is_valid()) {
2744 filter->set("kdenlive_id", filterId);
2745 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2746 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2747 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2748 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2749 if (x2 == -1) x2 = duration;
2751 for (int j = 0; j < params.count(); j++) {
2752 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2755 filter->set("in", x1);
2756 filter->set("out", x2);
2757 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2758 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2759 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2760 service.attach(*filter);
2767 Mlt::Filter *filter;
2769 filter = new Mlt::Filter(*m_mltProfile, filterTag);
2770 if (filter && filter->is_valid()) {
2771 filter->set("kdenlive_id", filterId);
2773 kDebug() << "filter is NULL";
2777 params.removeParam("kdenlive_id");
2778 if (params.hasParam("_sync_in_out")) {
2779 // This effect must sync in / out with parent clip
2780 params.removeParam("_sync_in_out");
2781 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2784 for (int j = 0; j < params.count(); j++) {
2785 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2789 QString effectArgs = params.paramValue("id").section('_', 1);
2791 params.removeParam("id");
2792 params.removeParam("kdenlive_ix");
2793 params.removeParam("tag");
2794 params.removeParam("disable");
2795 params.removeParam("region");
2797 for (int j = 0; j < params.count(); j++) {
2798 effectArgs.append(' ' + params.at(j).value());
2800 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2801 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2803 // attach filter to the clip
2804 service.attach(*filter);
2812 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2814 Mlt::Service service(m_mltProducer->parent().get_service());
2815 Mlt::Tractor tractor(service);
2816 Mlt::Producer trackProducer(tractor.track(track));
2817 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2818 Mlt::Service clipService(trackPlaylist.get_service());
2820 QString index = params.paramValue("kdenlive_ix");
2821 QString tag = params.paramValue("tag");
2823 Mlt::Filter *filter = clipService.filter(ct);
2825 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2829 filter = clipService.filter(ct);
2833 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2834 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2836 bool success = false;//mltAddTrackEffect(track, params);
2840 QString ser = filter->get("mlt_service");
2841 if (ser == "region") prefix = "filter0.";
2843 for (int j = 0; j < params.count(); j++) {
2844 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2852 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2854 int index = params.paramValue("kdenlive_ix").toInt();
2855 QString tag = params.paramValue("tag");
2857 if (!params.paramValue("keyframes").isEmpty() || (tag == "affine" && params.hasParam("background")) || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2858 // This is a keyframe effect, to edit it, we remove it and re-add it.
2859 bool success = mltRemoveEffect(track, position, index, false);
2860 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
2861 if (position < GenTime())
2862 success = mltAddTrackEffect(track, params);
2864 success = mltAddEffect(track, position, params);
2865 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
2868 if (position < GenTime()) {
2869 return mltEditTrackEffect(track, params);
2872 Mlt::Service service(m_mltProducer->parent().get_service());
2873 Mlt::Tractor tractor(service);
2874 Mlt::Producer trackProducer(tractor.track(track));
2875 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2877 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2878 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2880 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2884 int duration = clip->get_playtime();
2885 bool doRefresh = true;
2886 // Check if clip is visible in monitor
2887 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2888 if (diff < 0 || diff > duration)
2892 Mlt::Filter *filter = clip->filter(ct);
2894 if (filter->get_int("kdenlive_ix") == index) {
2898 filter = clip->filter(ct);
2902 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2903 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2905 bool success = mltAddEffect(track, position, params);
2909 QString ser = filter->get("mlt_service");
2910 QList <Mlt::Filter *> filtersList;
2913 // Effect service changes, delete effect and re-add it
2914 clip->detach(*filter);
2916 // Delete all effects after deleted one
2917 filter = clip->filter(ct);
2919 if (filter->get_int("kdenlive_ix") > index) {
2920 filtersList.append(filter);
2921 clip->detach(*filter);
2924 filter = clip->filter(ct);
2928 addFilterToService(*clip, params, clip->get_playtime());
2932 if (doRefresh) refresh();
2935 if (params.hasParam("_sync_in_out")) {
2936 // This effect must sync in / out with parent clip
2937 params.removeParam("_sync_in_out");
2938 filter->set_in_and_out(clip->get_in(), clip->get_out());
2941 for (int j = 0; j < params.count(); j++) {
2942 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2945 for (int j = 0; j < filtersList.count(); j++) {
2946 clip->attach(*(filtersList.at(j)));
2952 if (doRefresh) refresh();
2956 bool Render::mltEnableEffects(int track, GenTime position, QList <int> effectIndexes, bool disable)
2958 if (position < GenTime()) {
2959 return mltEnableTrackEffects(track, effectIndexes, disable);
2962 Mlt::Service service(m_mltProducer->parent().get_service());
2963 Mlt::Tractor tractor(service);
2964 Mlt::Producer trackProducer(tractor.track(track));
2965 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2967 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2968 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2970 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2974 int duration = clip->get_playtime();
2975 bool doRefresh = true;
2976 // Check if clip is visible in monitor
2977 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2978 if (diff < 0 || diff > duration)
2982 Mlt::Filter *filter = clip->filter(ct);
2984 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
2985 filter->set("disable", (int) disable);
2988 filter = clip->filter(ct);
2994 if (doRefresh) refresh();
2998 bool Render::mltEnableTrackEffects(int track, QList <int> effectIndexes, bool disable)
3000 Mlt::Service service(m_mltProducer->parent().get_service());
3001 Mlt::Tractor tractor(service);
3002 Mlt::Producer trackProducer(tractor.track(track));
3003 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3004 Mlt::Service clipService(trackPlaylist.get_service());
3007 Mlt::Filter *filter = clipService.filter(ct);
3009 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3010 filter->set("disable", (int) disable);
3013 filter = clipService.filter(ct);
3021 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
3023 Mlt::Service service(m_mltProducer->parent().get_service());
3024 Mlt::Tractor tractor(service);
3025 Mlt::Producer trackProducer(tractor.track(track));
3026 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3028 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3029 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3031 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3035 Mlt::Service clipService(clip->get_service());
3036 int duration = clip->get_playtime();
3037 bool doRefresh = true;
3038 // Check if clip is visible in monitor
3039 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3040 if (diff < 0 || diff > duration) doRefresh = false;
3044 Mlt::Filter *filter = clipService.filter(ct);
3046 int pos = filter->get_int("kdenlive_ix");
3047 if (pos == oldPos) {
3048 filter->set("kdenlive_ix", newPos);
3050 filter = clipService.filter(ct);
3052 if (doRefresh) refresh();
3055 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
3057 if (position < GenTime()) {
3058 mltMoveTrackEffect(track, oldPos, newPos);
3061 Mlt::Service service(m_mltProducer->parent().get_service());
3062 Mlt::Tractor tractor(service);
3063 Mlt::Producer trackProducer(tractor.track(track));
3064 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3066 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3067 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3069 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3073 Mlt::Service clipService(clip->get_service());
3074 int duration = clip->get_playtime();
3075 bool doRefresh = true;
3076 // Check if clip is visible in monitor
3077 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3078 if (diff < 0 || diff > duration) doRefresh = false;
3082 QList <Mlt::Filter *> filtersList;
3083 Mlt::Filter *filter = clipService.filter(ct);
3085 if (newPos > oldPos) {
3087 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3088 filter->set("kdenlive_ix", newPos);
3089 filtersList.append(filter);
3090 clipService.detach(*filter);
3091 filter = clipService.filter(ct);
3092 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3093 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3095 filter = clipService.filter(ct);
3099 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3100 filtersList.append(filter);
3101 clipService.detach(*filter);
3103 filter = clipService.filter(ct);
3107 if (filter->get_int("kdenlive_ix") == oldPos) {
3108 filter->set("kdenlive_ix", newPos);
3109 filtersList.append(filter);
3110 clipService.detach(*filter);
3112 filter = clipService.filter(ct);
3116 filter = clipService.filter(ct);
3118 int pos = filter->get_int("kdenlive_ix");
3119 if (pos >= newPos) {
3120 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3121 filtersList.append(filter);
3122 clipService.detach(*filter);
3124 filter = clipService.filter(ct);
3128 for (int i = 0; i < filtersList.count(); i++) {
3129 clipService.attach(*(filtersList.at(i)));
3132 if (doRefresh) refresh();
3135 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
3137 Mlt::Service service(m_mltProducer->parent().get_service());
3138 Mlt::Tractor tractor(service);
3139 Mlt::Producer trackProducer(tractor.track(track));
3140 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3141 Mlt::Service clipService(trackPlaylist.get_service());
3143 QList <Mlt::Filter *> filtersList;
3144 Mlt::Filter *filter = clipService.filter(ct);
3146 if (newPos > oldPos) {
3148 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3149 filter->set("kdenlive_ix", newPos);
3150 filtersList.append(filter);
3151 clipService.detach(*filter);
3152 filter = clipService.filter(ct);
3153 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3154 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3156 filter = clipService.filter(ct);
3160 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3161 filtersList.append(filter);
3162 clipService.detach(*filter);
3164 filter = clipService.filter(ct);
3168 if (filter->get_int("kdenlive_ix") == oldPos) {
3169 filter->set("kdenlive_ix", newPos);
3170 filtersList.append(filter);
3171 clipService.detach(*filter);
3173 filter = clipService.filter(ct);
3177 filter = clipService.filter(ct);
3179 int pos = filter->get_int("kdenlive_ix");
3180 if (pos >= newPos) {
3181 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3182 filtersList.append(filter);
3183 clipService.detach(*filter);
3185 filter = clipService.filter(ct);
3189 for (int i = 0; i < filtersList.count(); i++) {
3190 clipService.attach(*(filtersList.at(i)));
3195 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
3197 Mlt::Service service(m_mltProducer->parent().get_service());
3198 Mlt::Tractor tractor(service);
3199 Mlt::Producer trackProducer(tractor.track(info.track));
3200 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3202 /* // Display playlist info
3203 kDebug()<<"//////////// BEFORE RESIZE";
3204 for (int i = 0; i < trackPlaylist.count(); i++) {
3205 int blankStart = trackPlaylist.clip_start(i);
3206 int blankDuration = trackPlaylist.clip_length(i) - 1;
3208 if (trackPlaylist.is_blank(i)) blk = "(blank)";
3209 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
3212 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
3213 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3217 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
3218 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
3219 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3221 int previousStart = clip->get_in();
3222 int newDuration = (int) clipDuration.frames(m_fps) - 1;
3223 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
3225 int currentOut = newDuration + previousStart;
3226 if (currentOut > clip->get_length()) {
3227 clip->parent().set("length", currentOut + 1);
3228 clip->parent().set("out", currentOut);
3229 clip->set("length", currentOut + 1);
3232 /*if (newDuration > clip->get_out()) {
3233 clip->parent().set_in_and_out(0, newDuration + 1);
3234 clip->set_in_and_out(0, newDuration + 1);
3237 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
3238 trackPlaylist.consolidate_blanks(0);
3239 // skip to next clip
3241 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
3243 // clip was made longer, trim next blank if there is one.
3244 if (clipIndex < trackPlaylist.count()) {
3245 // If this is not the last clip in playlist
3246 if (trackPlaylist.is_blank(clipIndex)) {
3247 int blankStart = trackPlaylist.clip_start(clipIndex);
3248 int blankDuration = trackPlaylist.clip_length(clipIndex);
3249 if (diff > blankDuration) {
3250 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
3252 if (diff - blankDuration == 0) {
3253 trackPlaylist.remove(clipIndex);
3254 } else trackPlaylist.remove_region(blankStart, diff);
3256 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
3259 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
3260 trackPlaylist.consolidate_blanks(0);
3263 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
3264 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3265 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
3266 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3267 ItemInfo transpinfo;
3268 transpinfo.startPos = info.startPos;
3269 transpinfo.endPos = info.startPos + clipDuration;
3270 transpinfo.track = info.track;
3271 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3273 m_mltConsumer->set("refresh", 1);
3277 void Render::mltChangeTrackState(int track, bool mute, bool blind)
3279 Mlt::Service service(m_mltProducer->parent().get_service());
3280 Mlt::Tractor tractor(service);
3281 Mlt::Producer trackProducer(tractor.track(track));
3283 // Make sure muting will not produce problems with our audio mixing transition,
3284 // because audio mixing is done between each track and the lowest one
3285 bool audioMixingBroken = false;
3286 if (mute && trackProducer.get_int("hide") < 2 ) {
3287 // We mute a track with sound
3288 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3289 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
3291 else if (!mute && trackProducer.get_int("hide") > 1 ) {
3292 // We un-mute a previously muted track
3293 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3297 if (blind) trackProducer.set("hide", 3);
3298 else trackProducer.set("hide", 2);
3300 trackProducer.set("hide", 1);
3302 trackProducer.set("hide", 0);
3304 if (audioMixingBroken) fixAudioMixing(tractor);
3306 tractor.multitrack()->refresh();
3311 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
3313 for (int i = 1; i < tractor.count(); i++) {
3314 Mlt::Producer trackProducer(tractor.track(i));
3315 if (trackProducer.get_int("hide") < 2) return i;
3317 return tractor.count() - 1;
3320 void Render::fixAudioMixing(Mlt::Tractor tractor)
3322 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
3323 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
3325 mlt_service serv = m_mltProducer->parent().get_service();
3326 Mlt::Field *field = tractor.field();
3327 mlt_service_lock(serv);
3329 mlt_service nextservice = mlt_service_get_producer(serv);
3330 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3331 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3332 QString resource = mlt_properties_get(properties, "mlt_service");
3334 mlt_service nextservicetodisconnect;
3335 // Delete all audio mixing transitions
3336 while (mlt_type == "transition") {
3337 if (resource == "mix") {
3338 nextservicetodisconnect = nextservice;
3339 nextservice = mlt_service_producer(nextservice);
3340 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
3342 else nextservice = mlt_service_producer(nextservice);
3343 if (nextservice == NULL) break;
3344 properties = MLT_SERVICE_PROPERTIES(nextservice);
3345 mlt_type = mlt_properties_get(properties, "mlt_type");
3346 resource = mlt_properties_get(properties, "mlt_service");
3349 // Re-add correct audio transitions
3350 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
3351 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3352 transition->set("always_active", 1);
3353 transition->set("combine", 1);
3354 transition->set("internal_added", 237);
3355 field->plant_transition(*transition, lowestTrack, i);
3357 mlt_service_unlock(serv);
3360 bool Render::mltResizeClipCrop(ItemInfo info, GenTime newCropStart)
3362 Mlt::Service service(m_mltProducer->parent().get_service());
3363 int newCropFrame = (int) newCropStart.frames(m_fps);
3364 Mlt::Tractor tractor(service);
3365 Mlt::Producer trackProducer(tractor.track(info.track));
3366 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3367 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3368 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3372 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3373 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3375 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3379 int previousStart = clip->get_in();
3380 int previousOut = clip->get_out();
3382 if (previousStart == newCropFrame) {
3383 kDebug() << "//////// No ReSIZING Required";
3387 int frameOffset = newCropFrame - previousStart;
3388 trackPlaylist.resize_clip(clipIndex, newCropFrame, previousOut + frameOffset);
3390 m_mltConsumer->set("refresh", 1);
3394 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3396 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3397 Mlt::Service service(m_mltProducer->parent().get_service());
3398 int moveFrame = (int) diff.frames(m_fps);
3399 Mlt::Tractor tractor(service);
3400 Mlt::Producer trackProducer(tractor.track(info.track));
3401 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3402 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3403 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3407 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3408 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3409 if (clip == NULL || clip->is_blank()) {
3410 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3414 int previousStart = clip->get_in();
3415 int previousOut = clip->get_out();
3417 previousStart += moveFrame;
3419 if (previousStart < 0) {
3420 // this is possible for images and color clips
3421 previousOut -= previousStart;
3425 int length = previousOut + 1;
3426 if (length > clip->get_length()) {
3427 clip->parent().set("length", length + 1);
3428 clip->parent().set("out", length);
3429 clip->set("length", length + 1);
3433 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3434 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3435 if (moveFrame > 0) {
3436 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3438 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3439 int blankIndex = clipIndex - 1;
3440 int blankLength = trackPlaylist.clip_length(blankIndex);
3441 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3442 if (! trackPlaylist.is_blank(blankIndex)) {
3443 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3445 if (blankLength + moveFrame == 0)
3446 trackPlaylist.remove(blankIndex);
3448 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3450 trackPlaylist.consolidate_blanks(0);
3451 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3452 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3453 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3454 ItemInfo transpinfo;
3455 transpinfo.startPos = info.startPos + diff;
3456 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3457 transpinfo.track = info.track;
3458 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3460 //m_mltConsumer->set("refresh", 1);
3462 m_mltConsumer->set("refresh", 1);
3466 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3468 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3472 bool Render::mltUpdateClipProducer(Mlt::Tractor *tractor, int track, int pos, Mlt::Producer *prod)
3474 if (prod == NULL || !prod->is_valid() || tractor == NULL || !tractor->is_valid()) {
3475 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3479 Mlt::Producer trackProducer(tractor->track(track));
3480 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3481 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3482 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3483 if (clipProducer == NULL || clipProducer->is_blank()) {
3484 kDebug() << "// ERROR UPDATING CLIP PROD";
3485 delete clipProducer;
3488 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3489 if (!clip || !clip->is_valid()) {
3490 if (clip) delete clip;
3491 delete clipProducer;
3494 // move all effects to the correct producer
3495 mltPasteEffects(clipProducer, clip);
3496 trackPlaylist.insert_at(pos, clip, 1);
3498 delete clipProducer;
3502 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3504 Mlt::Service service(m_mltProducer->parent().get_service());
3505 if (service.type() != tractor_type) {
3506 kWarning() << "// TRACTOR PROBLEM";
3510 Mlt::Tractor tractor(service);
3512 Mlt::Producer trackProducer(tractor.track(startTrack));
3513 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3514 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3515 int clipDuration = trackPlaylist.clip_length(clipIndex);
3516 bool checkLength = false;
3517 if (endTrack == startTrack) {
3518 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3520 bool success = true;
3521 if (!trackPlaylist.is_blank_at(moveEnd) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3525 // Check that the destination region is empty
3526 trackPlaylist.consolidate_blanks(0);
3527 int destinationIndex = trackPlaylist.get_clip_index_at(moveEnd);
3528 if (destinationIndex < trackPlaylist.count() - 1) {
3529 // We are not at the end of the track
3530 int blankSize = trackPlaylist.blanks_from(destinationIndex, 1);
3531 // Make sure we have enough place to insert clip
3532 if (blankSize - clipDuration - (moveEnd - trackPlaylist.clip_start(destinationIndex)) < 0) success = false;
3537 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3538 delete clipProducer;
3540 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3547 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3548 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3549 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3551 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3552 if (newIndex == -1) {
3553 kDebug()<<"// CANNOT MOVE CLIP TO: "<<moveEnd;
3554 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3555 delete clipProducer;
3559 trackPlaylist.consolidate_blanks(1);
3560 delete clipProducer;
3561 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3563 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3564 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3565 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3566 // error, destination is not empty
3567 kDebug() << "Cannot move: Destination is not empty";
3571 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3572 if (!clipProducer || clipProducer->is_blank()) {
3573 // error, destination is not empty
3574 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3575 if (clipProducer) delete clipProducer;
3576 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3580 trackPlaylist.consolidate_blanks(0);
3581 destTrackPlaylist.consolidate_blanks(1);
3582 Mlt::Producer *clip;
3583 // check if we are moving a slowmotion producer
3584 QString serv = clipProducer->parent().get("mlt_service");
3585 QString currentid = clipProducer->parent().get("id");
3586 if (serv == "framebuffer") {
3587 clip = clipProducer;
3590 // Special case: prod is null when using placeholder clips.
3591 // in that case, use the producer existing in playlist. Note that
3592 // it will bypass the one producer per track logic and might cause
3593 // Sound cracks if clip is moved so that it overlaps another copy of itself
3594 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3595 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3598 // move all effects to the correct producer
3599 mltPasteEffects(clipProducer, clip);
3602 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3603 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3604 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3607 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3609 if (clip == clipProducer) {
3614 delete clipProducer;
3616 destTrackPlaylist.consolidate_blanks(0);
3617 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3618 kDebug() << "//////// moving clip transparency";
3619 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3621 if (clipIndex > trackPlaylist.count()) checkLength = true;
3622 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3626 if (checkLength) mltCheckLength(&tractor);
3628 //m_mltConsumer->set("refresh", 1);
3633 QList <int> Render::checkTrackSequence(int track)
3636 Mlt::Service service(m_mltProducer->parent().get_service());
3637 if (service.type() != tractor_type) {
3638 kWarning() << "// TRACTOR PROBLEM";
3641 Mlt::Tractor tractor(service);
3643 Mlt::Producer trackProducer(tractor.track(track));
3644 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3645 int clipNb = trackPlaylist.count();
3646 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3647 for (int i = 0; i < clipNb; i++) {
3648 Mlt::Producer *c = trackPlaylist.get_clip(i);
3649 int pos = trackPlaylist.clip_start(i);
3650 if (!list.contains(pos)) list.append(pos);
3651 pos += c->get_playtime();
3652 if (!list.contains(pos)) list.append(pos);
3658 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3660 int new_in = (int)newIn.frames(m_fps);
3661 int new_out = (int)newOut.frames(m_fps) - 1;
3662 if (new_in >= new_out) return false;
3663 int old_in = (int)oldIn.frames(m_fps);
3664 int old_out = (int)oldOut.frames(m_fps) - 1;
3666 Mlt::Service service(m_mltProducer->parent().get_service());
3667 Mlt::Tractor tractor(service);
3668 Mlt::Field *field = tractor.field();
3670 bool doRefresh = true;
3671 // Check if clip is visible in monitor
3672 int diff = old_out - m_mltProducer->position();
3673 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3675 diff = new_out - m_mltProducer->position();
3676 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3680 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3681 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3682 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3683 QString resource = mlt_properties_get(properties, "mlt_service");
3684 int old_pos = (int)(old_in + old_out) / 2;
3687 while (mlt_type == "transition") {
3688 Mlt::Transition transition((mlt_transition) nextservice);
3689 nextservice = mlt_service_producer(nextservice);
3690 int currentTrack = transition.get_b_track();
3691 int currentIn = (int) transition.get_in();
3692 int currentOut = (int) transition.get_out();
3694 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3696 if (newTrack - startTrack != 0) {
3697 Mlt::Properties trans_props(transition.get_properties());
3698 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3699 Mlt::Properties new_trans_props(new_transition.get_properties());
3700 new_trans_props.inherit(trans_props);
3701 new_transition.set_in_and_out(new_in, new_out);
3702 field->disconnect_service(transition);
3703 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3704 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3705 } else transition.set_in_and_out(new_in, new_out);
3708 if (nextservice == NULL) break;
3709 properties = MLT_SERVICE_PROPERTIES(nextservice);
3710 mlt_type = mlt_properties_get(properties, "mlt_type");
3711 resource = mlt_properties_get(properties, "mlt_service");
3714 if (doRefresh) refresh();
3715 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3720 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3722 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3723 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3724 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3725 QString resource = mlt_properties_get(properties, "mlt_service");
3726 QList <Mlt::Transition *> trList;
3727 mlt_properties insertproperties = tr.get_properties();
3728 QString insertresource = mlt_properties_get(insertproperties, "mlt_service");
3729 bool isMixTransition = insertresource == "mix";
3731 while (mlt_type == "transition") {
3732 Mlt::Transition transition((mlt_transition) nextservice);
3733 nextservice = mlt_service_producer(nextservice);
3734 int aTrack = transition.get_a_track();
3735 int bTrack = transition.get_b_track();
3736 if ((isMixTransition || resource != "mix") && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3737 Mlt::Properties trans_props(transition.get_properties());
3738 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3739 Mlt::Properties new_trans_props(cp->get_properties());
3740 new_trans_props.inherit(trans_props);
3742 field->disconnect_service(transition);
3744 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3746 if (nextservice == NULL) break;
3747 properties = MLT_SERVICE_PROPERTIES(nextservice);
3748 mlt_type = mlt_properties_get(properties, "mlt_type");
3749 resource = mlt_properties_get(properties, "mlt_service");
3751 field->plant_transition(tr, a_track, b_track);
3753 // re-add upper transitions
3754 for (int i = trList.count() - 1; i >= 0; i--) {
3755 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3756 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3761 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3763 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3765 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3766 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3767 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3770 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3773 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3775 mlt_service serv = m_mltProducer->parent().get_service();
3776 mlt_service_lock(serv);
3778 mlt_service nextservice = mlt_service_get_producer(serv);
3779 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3780 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3781 QString resource = mlt_properties_get(properties, "mlt_service");
3782 int in_pos = (int) in.frames(m_fps);
3783 int out_pos = (int) out.frames(m_fps) - 1;
3785 while (mlt_type == "transition") {
3786 mlt_transition tr = (mlt_transition) nextservice;
3787 int currentTrack = mlt_transition_get_b_track(tr);
3788 int currentBTrack = mlt_transition_get_a_track(tr);
3789 int currentIn = (int) mlt_transition_get_in(tr);
3790 int currentOut = (int) mlt_transition_get_out(tr);
3792 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3793 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3794 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3795 QMap<QString, QString>::Iterator it;
3797 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3799 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3800 if (currentId != xml.attribute("id")) {
3801 // The transition ID is not the same, so reset all properties
3802 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3803 // Cleanup previous properties
3804 QStringList permanentProps;
3805 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3806 permanentProps << "out" << "a_track" << "b_track";
3807 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3808 QString propName = mlt_properties_get_name(transproperties, i);
3809 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3810 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3815 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3816 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3818 if (currentBTrack != a_track) {
3819 mlt_properties_set_int(transproperties, "a_track", a_track);
3821 for (it = map.begin(); it != map.end(); ++it) {
3823 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3824 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3825 //filter->set("kdenlive_id", id);
3829 nextservice = mlt_service_producer(nextservice);
3830 if (nextservice == NULL) break;
3831 properties = MLT_SERVICE_PROPERTIES(nextservice);
3832 mlt_type = mlt_properties_get(properties, "mlt_type");
3833 resource = mlt_properties_get(properties, "mlt_service");
3835 mlt_service_unlock(serv);
3837 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3840 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3842 mlt_service serv = m_mltProducer->parent().get_service();
3843 mlt_service_lock(serv);
3845 Mlt::Service service(serv);
3846 Mlt::Tractor tractor(service);
3847 Mlt::Field *field = tractor.field();
3849 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3851 mlt_service nextservice = mlt_service_get_producer(serv);
3852 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3853 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3854 QString resource = mlt_properties_get(properties, "mlt_service");
3856 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3857 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3859 while (mlt_type == "transition") {
3860 mlt_transition tr = (mlt_transition) nextservice;
3861 int currentTrack = mlt_transition_get_b_track(tr);
3862 int currentIn = (int) mlt_transition_get_in(tr);
3863 int currentOut = (int) mlt_transition_get_out(tr);
3864 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3866 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3867 mlt_field_disconnect_service(field->get_field(), nextservice);
3870 nextservice = mlt_service_producer(nextservice);
3871 if (nextservice == NULL) break;
3872 properties = MLT_SERVICE_PROPERTIES(nextservice);
3873 mlt_type = mlt_properties_get(properties, "mlt_type");
3874 resource = mlt_properties_get(properties, "mlt_service");
3876 mlt_service_unlock(serv);
3878 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3881 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3883 QDomNodeList attribs = xml.elementsByTagName("parameter");
3884 QMap<QString, QString> map;
3885 for (int i = 0; i < attribs.count(); i++) {
3886 QDomElement e = attribs.item(i).toElement();
3887 QString name = e.attribute("name");
3888 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3889 map[name] = e.attribute("default");
3890 if (!e.attribute("value").isEmpty()) {
3891 map[name] = e.attribute("value");
3893 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
3894 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
3895 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3898 if (e.attribute("namedesc").contains(';')) {
3899 QString format = e.attribute("format");
3900 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3901 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3903 QTextStream txtNeu(&neu);
3904 if (values.size() > 0)
3905 txtNeu << (int)values[0].toDouble();
3907 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3908 txtNeu << separators[i];
3909 txtNeu << (int)(values[i+1].toDouble());
3911 if (i < separators.size())
3912 txtNeu << separators[i];
3913 map[e.attribute("name")] = neu;
3920 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3922 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3923 Mlt::Service service(m_mltProducer->parent().get_service());
3924 Mlt::Tractor tractor(service);
3925 Mlt::Field *field = tractor.field();
3927 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3928 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3929 transition->set("transparency", id);
3930 transition->set("fill", 1);
3931 transition->set("internal_added", 237);
3932 field->plant_transition(*transition, transitiontrack, info.track);
3936 void Render::mltDeleteTransparency(int pos, int track, int id)
3938 Mlt::Service service(m_mltProducer->parent().get_service());
3939 Mlt::Tractor tractor(service);
3940 Mlt::Field *field = tractor.field();
3942 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3943 mlt_service serv = m_mltProducer->parent().get_service();
3945 mlt_service nextservice = mlt_service_get_producer(serv);
3946 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3947 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3948 QString resource = mlt_properties_get(properties, "mlt_service");
3950 while (mlt_type == "transition") {
3951 mlt_transition tr = (mlt_transition) nextservice;
3952 int currentTrack = mlt_transition_get_b_track(tr);
3953 int currentIn = (int) mlt_transition_get_in(tr);
3954 int currentOut = (int) mlt_transition_get_out(tr);
3955 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3956 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3958 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3959 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3960 mlt_field_disconnect_service(field->get_field(), nextservice);
3963 nextservice = mlt_service_producer(nextservice);
3964 if (nextservice == NULL) break;
3965 properties = MLT_SERVICE_PROPERTIES(nextservice);
3966 mlt_type = mlt_properties_get(properties, "mlt_type");
3967 resource = mlt_properties_get(properties, "mlt_service");
3969 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3972 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3974 Mlt::Service service(m_mltProducer->parent().get_service());
3975 Mlt::Tractor tractor(service);
3978 m_mltConsumer->set("refresh", 0);
3980 mlt_service serv = m_mltProducer->parent().get_service();
3981 mlt_service nextservice = mlt_service_get_producer(serv);
3982 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3983 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3984 QString resource = mlt_properties_get(properties, "mlt_service");
3985 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3986 while (mlt_type == "transition") {
3987 mlt_transition tr = (mlt_transition) nextservice;
3988 int currentTrack = mlt_transition_get_b_track(tr);
3989 int currentIn = (int) mlt_transition_get_in(tr);
3990 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3991 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3992 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3993 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3994 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3995 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3998 nextservice = mlt_service_producer(nextservice);
3999 if (nextservice == NULL) break;
4000 properties = MLT_SERVICE_PROPERTIES(nextservice);
4001 mlt_type = mlt_properties_get(properties, "mlt_type");
4002 resource = mlt_properties_get(properties, "mlt_service");
4005 m_mltConsumer->set("refresh", 1);
4009 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
4011 Mlt::Service service(m_mltProducer->parent().get_service());
4012 Mlt::Tractor tractor(service);
4015 m_mltConsumer->set("refresh", 0);
4017 mlt_service serv = m_mltProducer->parent().get_service();
4018 mlt_service nextservice = mlt_service_get_producer(serv);
4019 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4020 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4021 QString resource = mlt_properties_get(properties, "mlt_service");
4023 while (mlt_type == "transition") {
4024 mlt_transition tr = (mlt_transition) nextservice;
4025 int currentTrack = mlt_transition_get_b_track(tr);
4026 int currentaTrack = mlt_transition_get_a_track(tr);
4027 int currentIn = (int) mlt_transition_get_in(tr);
4028 int currentOut = (int) mlt_transition_get_out(tr);
4029 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4030 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4031 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
4032 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
4033 kDebug() << "//////MOVING";
4034 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
4035 if (endTrack != startTrack) {
4036 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4037 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
4038 mlt_properties_set_int(properties, "b_track", endTrack);
4042 nextservice = mlt_service_producer(nextservice);
4043 if (nextservice == NULL) break;
4044 properties = MLT_SERVICE_PROPERTIES(nextservice);
4045 mlt_type = mlt_properties_get(properties, "mlt_type");
4046 resource = mlt_properties_get(properties, "mlt_service");
4049 m_mltConsumer->set("refresh", 1);
4053 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
4055 if (in >= out) return false;
4056 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
4057 Mlt::Service service(m_mltProducer->parent().get_service());
4059 Mlt::Tractor tractor(service);
4060 Mlt::Field *field = tractor.field();
4062 Mlt::Transition transition(*m_mltProfile, tag.toUtf8().constData());
4063 if (out != GenTime())
4064 transition.set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
4066 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
4067 QMap<QString, QString>::Iterator it;
4069 if (xml.attribute("automatic") == "1") transition.set("automatic", 1);
4070 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
4071 if (xml.hasAttribute("id"))
4072 transition.set("kdenlive_id", xml.attribute("id").toUtf8().constData());
4073 if (xml.hasAttribute("force_track"))
4074 transition.set("force_track", xml.attribute("force_track").toInt());
4076 for (it = args.begin(); it != args.end(); ++it) {
4078 if (!it.value().isEmpty())
4079 transition.set(key.toUtf8().constData(), it.value().toUtf8().constData());
4080 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
4082 // attach transition
4084 mltPlantTransition(field, transition, a_track, b_track);
4085 // field->plant_transition(*transition, a_track, b_track);
4087 if (do_refresh) refresh();
4091 void Render::mltSavePlaylist()
4093 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
4094 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
4095 fileConsumer.set("resource", "/tmp/playlist.mlt");
4097 Mlt::Service service(m_mltProducer->get_service());
4099 fileConsumer.connect(service);
4100 fileConsumer.start();
4103 const QList <Mlt::Producer *> Render::producersList()
4105 QList <Mlt::Producer *> prods;
4106 if (m_mltProducer == NULL) return prods;
4107 Mlt::Service service(m_mltProducer->parent().get_service());
4108 if (service.type() != tractor_type) return prods;
4109 Mlt::Tractor tractor(service);
4112 int trackNb = tractor.count();
4113 for (int t = 1; t < trackNb; t++) {
4114 Mlt::Producer *tt = tractor.track(t);
4115 Mlt::Producer trackProducer(tt);
4117 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4118 if (!trackPlaylist.is_valid()) continue;
4119 int clipNb = trackPlaylist.count();
4120 for (int i = 0; i < clipNb; i++) {
4121 Mlt::Producer *c = trackPlaylist.get_clip(i);
4122 if (c == NULL) continue;
4123 QString prodId = c->parent().get("id");
4124 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
4125 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4128 prods.append(nprod);
4137 void Render::fillSlowMotionProducers()
4139 if (m_mltProducer == NULL) return;
4140 Mlt::Service service(m_mltProducer->parent().get_service());
4141 if (service.type() != tractor_type) return;
4143 Mlt::Tractor tractor(service);
4145 int trackNb = tractor.count();
4146 for (int t = 1; t < trackNb; t++) {
4147 Mlt::Producer *tt = tractor.track(t);
4148 Mlt::Producer trackProducer(tt);
4150 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4151 if (!trackPlaylist.is_valid()) continue;
4152 int clipNb = trackPlaylist.count();
4153 for (int i = 0; i < clipNb; i++) {
4154 Mlt::Producer *c = trackPlaylist.get_clip(i);
4155 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4157 QString id = nprod->parent().get("id");
4158 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
4159 // this is a slowmotion producer, add it to the list
4160 QString url = QString::fromUtf8(nprod->get("resource"));
4161 int strobe = nprod->get_int("strobe");
4162 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
4163 if (!m_slowmotionProducers.contains(url)) {
4164 m_slowmotionProducers.insert(url, nprod);
4166 } else delete nprod;
4173 QList <TransitionInfo> Render::mltInsertTrack(int ix, bool videoTrack)
4175 Mlt::Service service(m_mltProducer->parent().get_service());
4176 if (service.type() != tractor_type) {
4177 kWarning() << "// TRACTOR PROBLEM";
4178 return QList <TransitionInfo> ();
4182 Mlt::Tractor tractor(service);
4183 QList <TransitionInfo> transitionInfos;
4184 Mlt::Playlist playlist;
4185 int ct = tractor.count();
4187 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
4193 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
4194 tractor.set_track(playlist, pos);
4195 Mlt::Producer newProd(tractor.track(pos));
4196 if (!videoTrack) newProd.set("hide", 1);
4198 for (; pos <= ct; pos++) {
4199 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
4200 tractor.set_track(*prodToMove, pos);
4201 prodToMove = prodToMove2;
4204 tractor.set_track(playlist, ix);
4205 Mlt::Producer newProd(tractor.track(ix));
4206 if (!videoTrack) newProd.set("hide", 1);
4211 mlt_service serv = m_mltProducer->parent().get_service();
4212 mlt_service nextservice = mlt_service_get_producer(serv);
4213 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4214 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4215 QString resource = mlt_properties_get(properties, "mlt_service");
4216 Mlt::Field *field = tractor.field();
4217 QList <Mlt::Transition *> trList;
4219 while (mlt_type == "transition") {
4220 if (resource != "mix") {
4221 Mlt::Transition transition((mlt_transition) nextservice);
4222 nextservice = mlt_service_producer(nextservice);
4223 int currentbTrack = transition.get_b_track();
4224 int currentaTrack = transition.get_a_track();
4225 bool trackChanged = false;
4226 bool forceTransitionTrack = false;
4227 if (currentbTrack >= ix) {
4228 if (currentbTrack == ix && currentaTrack < ix) forceTransitionTrack = true;
4230 trackChanged = true;
4232 if (currentaTrack >= ix) {
4234 trackChanged = true;
4236 kDebug()<<"// Newtrans: "<<currentaTrack<<"/"<<currentbTrack;
4238 // disconnect all transitions
4239 Mlt::Properties trans_props(transition.get_properties());
4240 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
4241 Mlt::Properties new_trans_props(cp->get_properties());
4242 new_trans_props.inherit(trans_props);
4245 // Transition track needs to be adjusted
4246 cp->set("a_track", currentaTrack);
4247 cp->set("b_track", currentbTrack);
4248 // Check if transition track was changed and needs to be forced
4249 if (forceTransitionTrack) cp->set("force_track", 1);
4250 TransitionInfo trInfo;
4251 trInfo.startPos = GenTime(transition.get_in(), m_fps);
4252 trInfo.a_track = currentaTrack;
4253 trInfo.b_track = currentbTrack;
4254 trInfo.forceTrack = cp->get_int("force_track");
4255 transitionInfos.append(trInfo);
4258 field->disconnect_service(transition);
4260 else nextservice = mlt_service_producer(nextservice);
4261 if (nextservice == NULL) break;
4262 properties = MLT_SERVICE_PROPERTIES(nextservice);
4263 mlt_type = mlt_properties_get(properties, "mlt_type");
4264 resource = mlt_properties_get(properties, "mlt_service");
4267 // Add audio mix transition to last track
4268 Mlt::Transition transition(*m_mltProfile, "mix");
4269 transition.set("a_track", 1);
4270 transition.set("b_track", ct);
4271 transition.set("always_active", 1);
4272 transition.set("internal_added", 237);
4273 transition.set("combine", 1);
4274 mltPlantTransition(field, transition, 1, ct);
4276 // re-add transitions
4277 for (int i = trList.count() - 1; i >= 0; i--) {
4278 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
4283 blockSignals(false);
4284 return transitionInfos;
4288 void Render::mltDeleteTrack(int ix)
4291 doc.setContent(sceneList(), false);
4292 int tracksCount = doc.elementsByTagName("track").count() - 1;
4293 QDomNode track = doc.elementsByTagName("track").at(ix);
4294 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
4295 QDomNodeList transitions = doc.elementsByTagName("transition");
4296 for (int i = 0; i < transitions.count(); i++) {
4297 QDomElement e = transitions.at(i).toElement();
4298 QDomNodeList props = e.elementsByTagName("property");
4299 QMap <QString, QString> mappedProps;
4300 for (int j = 0; j < props.count(); j++) {
4301 QDomElement f = props.at(j).toElement();
4302 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
4304 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
4305 tractor.removeChild(transitions.at(i));
4307 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
4308 // Transition needs to be moved
4309 int a_track = mappedProps.value("a_track").toInt();
4310 int b_track = mappedProps.value("b_track").toInt();
4311 if (a_track > 0 && a_track >= ix) a_track --;
4312 if (b_track == ix) {
4313 // transition was on the deleted track, so remove it
4314 tractor.removeChild(transitions.at(i));
4318 if (b_track > 0 && b_track > ix) b_track --;
4319 for (int j = 0; j < props.count(); j++) {
4320 QDomElement f = props.at(j).toElement();
4321 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
4322 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
4327 tractor.removeChild(track);
4328 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
4329 setSceneList(doc.toString(), m_mltConsumer->position());
4330 emit refreshDocumentProducers(false, false);
4334 void Render::updatePreviewSettings()
4336 kDebug() << "////// RESTARTING CONSUMER";
4337 if (!m_mltConsumer || !m_mltProducer) return;
4338 if (m_mltProducer->get_playtime() == 0) return;
4339 QMutexLocker locker(&m_mutex);
4340 Mlt::Service service(m_mltProducer->parent().get_service());
4341 if (service.type() != tractor_type) return;
4343 //m_mltConsumer->set("refresh", 0);
4344 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
4345 m_mltConsumer->purge();
4346 QString scene = sceneList();
4348 if (m_mltProducer) {
4349 pos = m_mltProducer->position();
4352 setSceneList(scene, pos);
4356 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
4358 // Update all frame positions to the new fps value
4359 //WARNING: there are probably some effects or other that hold a frame value
4360 // as parameter and will also need to be updated here!
4362 doc.setContent(scene);
4364 double factor = new_fps / current_fps;
4365 QDomNodeList producers = doc.elementsByTagName("producer");
4366 for (int i = 0; i < producers.count(); i++) {
4367 QDomElement prod = producers.at(i).toElement();
4368 prod.removeAttribute("in");
4369 prod.removeAttribute("out");
4371 QDomNodeList props = prod.childNodes();
4372 for (int j = 0; j < props.count(); j++) {
4373 QDomElement param = props.at(j).toElement();
4374 QString paramName = param.attribute("name");
4375 if (paramName.startsWith("meta.") || paramName == "length") {
4376 prod.removeChild(props.at(j));
4382 QDomNodeList entries = doc.elementsByTagName("entry");
4383 for (int i = 0; i < entries.count(); i++) {
4384 QDomElement entry = entries.at(i).toElement();
4385 int in = entry.attribute("in").toInt();
4386 int out = entry.attribute("out").toInt();
4387 in = factor * in + 0.5;
4388 out = factor * out + 0.5;
4389 entry.setAttribute("in", in);
4390 entry.setAttribute("out", out);
4393 QDomNodeList blanks = doc.elementsByTagName("blank");
4394 for (int i = 0; i < blanks.count(); i++) {
4395 QDomElement blank = blanks.at(i).toElement();
4396 int length = blank.attribute("length").toInt();
4397 length = factor * length + 0.5;
4398 blank.setAttribute("length", QString::number(length));
4401 QDomNodeList filters = doc.elementsByTagName("filter");
4402 for (int i = 0; i < filters.count(); i++) {
4403 QDomElement filter = filters.at(i).toElement();
4404 int in = filter.attribute("in").toInt();
4405 int out = filter.attribute("out").toInt();
4406 in = factor * in + 0.5;
4407 out = factor * out + 0.5;
4408 filter.setAttribute("in", in);
4409 filter.setAttribute("out", out);
4412 QDomNodeList transitions = doc.elementsByTagName("transition");
4413 for (int i = 0; i < transitions.count(); i++) {
4414 QDomElement transition = transitions.at(i).toElement();
4415 int in = transition.attribute("in").toInt();
4416 int out = transition.attribute("out").toInt();
4417 in = factor * in + 0.5;
4418 out = factor * out + 0.5;
4419 transition.setAttribute("in", in);
4420 transition.setAttribute("out", out);
4421 QDomNodeList props = transition.childNodes();
4422 for (int j = 0; j < props.count(); j++) {
4423 QDomElement param = props.at(j).toElement();
4424 QString paramName = param.attribute("name");
4425 if (paramName == "geometry") {
4426 QString geom = param.firstChild().nodeValue();
4427 QStringList keys = geom.split(';');
4428 QStringList newKeys;
4429 for (int k = 0; k < keys.size(); ++k) {
4430 if (keys.at(k).contains('=')) {
4431 int pos = keys.at(k).section('=', 0, 0).toInt();
4432 pos = factor * pos + 0.5;
4433 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4434 } else newKeys.append(keys.at(k));
4436 param.firstChild().setNodeValue(newKeys.join(";"));
4440 QDomElement root = doc.documentElement();
4441 if (!root.isNull()) {
4442 QDomElement tractor = root.firstChildElement("tractor");
4443 int out = tractor.attribute("out").toInt();
4444 out = factor * out + 0.5;
4445 tractor.setAttribute("out", out);
4446 emit durationChanged(out);
4449 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4450 return doc.toString();
4454 void Render::sendFrameUpdate()
4456 if (m_mltProducer) {
4457 Mlt::Frame * frame = m_mltProducer->get_frame();
4458 emitFrameUpdated(*frame);
4463 Mlt::Producer* Render::getProducer()
4465 return m_mltProducer;
4468 const QString Render::activeClipId()
4470 if (m_mltProducer) return m_mltProducer->get("id");
4475 bool Render::getBlackMagicDeviceList(KComboBox *devicelist)
4477 if (!KdenliveSettings::decklink_device_found()) return false;
4478 Mlt::Profile profile;
4479 Mlt::Producer bm(profile, "decklink");
4480 int found_devices = 0;
4481 if (bm.is_valid()) {
4482 bm.set("list_devices", 1);
4483 found_devices = bm.get_int("devices");
4485 else KdenliveSettings::setDecklink_device_found(false);
4486 if (found_devices <= 0) {
4487 devicelist->setEnabled(false);
4490 for (int i = 0; i < found_devices; i++) {
4491 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4492 devicelist->addItem(bm.get(tmp));
4498 bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist)
4500 if (!KdenliveSettings::decklink_device_found()) return false;
4501 Mlt::Profile profile;
4502 Mlt::Consumer bm(profile, "decklink");
4503 int found_devices = 0;
4504 if (bm.is_valid()) {
4505 bm.set("list_devices", 1);
4506 found_devices = bm.get_int("devices");
4508 else KdenliveSettings::setDecklink_device_found(false);
4509 if (found_devices <= 0) {
4510 devicelist->setEnabled(false);
4513 for (int i = 0; i < found_devices; i++) {
4514 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4515 devicelist->addItem(bm.get(tmp));
4521 void Render::slotMultiStreamProducerFound(const QString path, QList<int> audio_list, QList<int> video_list, stringMap data)
4523 if (KdenliveSettings::automultistreams()) {
4524 for (int i = 1; i < video_list.count(); i++) {
4525 int vindex = video_list.at(i);
4527 if (i <= audio_list.count() -1) {
4528 aindex = audio_list.at(i);
4530 data.insert("video_index", QString::number(vindex));
4531 data.insert("audio_index", QString::number(aindex));
4532 data.insert("bypassDuplicate", "1");
4533 emit addClip(KUrl(path), data);
4538 int width = 60.0 * m_mltProfile->dar();
4539 int swidth = 60.0 * m_mltProfile->width() / m_mltProfile->height();
4540 if (width % 2 == 1) width++;
4542 KDialog dialog(qApp->activeWindow());
4543 dialog.setCaption("Multi Stream Clip");
4544 dialog.setButtons(KDialog::Ok | KDialog::Cancel);
4545 dialog.setButtonText(KDialog::Ok, i18n("Import selected clips"));
4546 QWidget *content = new QWidget(&dialog);
4547 dialog.setMainWidget(content);
4548 QVBoxLayout *vbox = new QVBoxLayout(content);
4549 QLabel *lab1 = new QLabel(i18n("Additional streams for clip\n %1", path), content);
4550 vbox->addWidget(lab1);
4551 QList <QGroupBox*> groupList;
4552 QList <QComboBox*> comboList;
4553 // We start loading the list at 1, video index 0 should already be loaded
4554 for (int j = 1; j < video_list.count(); j++) {
4555 Mlt::Producer multiprod(* m_mltProfile, path.toUtf8().constData());
4556 multiprod.set("video_index", video_list.at(j));
4557 QImage thumb = KThumb::getFrame(&multiprod, 0, swidth, width, 60);
4558 QGroupBox *streamFrame = new QGroupBox(i18n("Video stream %1", video_list.at(j)), content);
4559 streamFrame->setProperty("vindex", video_list.at(j));
4560 groupList << streamFrame;
4561 streamFrame->setCheckable(true);
4562 streamFrame->setChecked(true);
4563 QVBoxLayout *vh = new QVBoxLayout( streamFrame );
4564 QLabel *iconLabel = new QLabel(content);
4565 iconLabel->setPixmap(QPixmap::fromImage(thumb));
4566 vh->addWidget(iconLabel);
4567 if (audio_list.count() > 1) {
4568 QComboBox *cb = new QComboBox(content);
4569 for (int k = 0; k < audio_list.count(); k++) {
4570 cb->addItem(i18n("Audio stream %1", audio_list.at(k)), audio_list.at(k));
4573 cb->setCurrentIndex(qMin(j, audio_list.count() - 1));
4576 vbox->addWidget(streamFrame);
4578 if (dialog.exec() == QDialog::Accepted) {
4579 // import selected streams
4580 for (int i = 0; i < groupList.count(); i++) {
4581 if (groupList.at(i)->isChecked()) {
4582 int vindex = groupList.at(i)->property("vindex").toInt();
4583 int aindex = comboList.at(i)->itemData(comboList.at(i)->currentIndex()).toInt();
4584 data.insert("video_index", QString::number(vindex));
4585 data.insert("audio_index", QString::number(aindex));
4586 data.insert("bypassDuplicate", "1");
4587 emit addClip(KUrl(path), data);
4593 #include "renderer.moc"