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 if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
100 self->emitConsumerStopped();
102 self->showFrame(frame);
105 Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWidget *parent) :
106 AbstractRender(rendererName, parent),
107 requestedSeekPosition(SEEK_INACTIVE),
108 m_name(rendererName),
112 m_showFrameEvent(NULL),
114 m_externalConsumer(false),
117 m_isSplitView(false),
121 qRegisterMetaType<stringMap> ("stringMap");
122 analyseAudio = KdenliveSettings::monitor_audio();
123 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
124 buildConsumer(profile);
125 m_mltProducer = m_blackClip->cut(0, 1);
126 m_mltConsumer->connect(*m_mltProducer);
127 m_mltProducer->set_speed(0.0);
128 m_refreshTimer.setSingleShot(true);
129 m_refreshTimer.setInterval(100);
130 connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
131 connect(this, SIGNAL(multiStreamFound(const QString &,QList<int>,QList<int>,stringMap)), this, SLOT(slotMultiStreamProducerFound(const QString &,QList<int>,QList<int>,stringMap)));
132 connect(this, SIGNAL(checkSeeking()), this, SLOT(slotCheckSeeking()));
142 void Render::closeMlt()
145 m_requestList.clear();
146 m_infoThread.waitForFinished();
147 if (m_showFrameEvent) delete m_showFrameEvent;
148 if (m_pauseEvent) delete m_pauseEvent;
149 if (m_mltConsumer) delete m_mltConsumer;
150 if (m_mltProducer) delete m_mltProducer;
151 /*if (m_mltProducer) {
152 Mlt::Service service(m_mltProducer->parent().get_service());
155 if (service.type() == tractor_type) {
156 Mlt::Tractor tractor(service);
157 Mlt::Field *field = tractor.field();
158 mlt_service nextservice = mlt_service_get_producer(service.get_service());
159 mlt_service nextservicetodisconnect;
160 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
161 QString mlt_type = mlt_properties_get(properties, "mlt_type");
162 QString resource = mlt_properties_get(properties, "mlt_service");
163 // Delete all transitions
164 while (mlt_type == "transition") {
165 nextservicetodisconnect = nextservice;
166 nextservice = mlt_service_producer(nextservice);
167 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
168 if (nextservice == NULL) break;
169 properties = MLT_SERVICE_PROPERTIES(nextservice);
170 mlt_type = mlt_properties_get(properties, "mlt_type");
171 resource = mlt_properties_get(properties, "mlt_service");
180 //kDebug() << "// // // CLOSE RENDERER " << m_name;
181 if (m_blackClip) delete m_blackClip;
185 void Render::slotSwitchFullscreen()
187 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
190 void Render::buildConsumer(const QString &profileName)
195 m_activeProfile = profileName;
197 Mlt::Profile tmpProfile(m_activeProfile.toUtf8().constData());
198 m_mltProfile->set_colorspace(tmpProfile.colorspace());
199 m_mltProfile->set_frame_rate(tmpProfile.frame_rate_num(), tmpProfile.frame_rate_den());
200 m_mltProfile->set_height(tmpProfile.height());
201 m_mltProfile->set_width(tmpProfile.width());
202 m_mltProfile->set_progressive(tmpProfile.progressive());
203 m_mltProfile->set_sample_aspect(tmpProfile.sample_aspect_num(), tmpProfile.sample_aspect_den());
204 m_mltProfile->get_profile()->display_aspect_num = tmpProfile.display_aspect_num();
205 m_mltProfile->get_profile()->display_aspect_den = tmpProfile.display_aspect_den();
208 m_mltProfile = new Mlt::Profile(m_activeProfile.toUtf8().constData());
210 setenv("MLT_PROFILE", m_activeProfile.toUtf8().constData(), 1);
211 m_mltProfile->set_explicit(true);
213 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
214 m_blackClip->set("id", "black");
215 m_blackClip->set("mlt_type", "producer");
217 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) {
218 #ifdef USE_BLACKMAGIC
219 // Use blackmagic card for video output
220 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
221 int device = KdenliveSettings::blackmagic_output_device();
223 if (BMInterface::isSupportedProfile(device, profileProperties)) {
224 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
225 if (!m_mltConsumer) {
226 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
227 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
228 mlt_log_set_callback(kdenlive_callback);
230 if (m_mltConsumer->is_valid()) {
231 m_externalConsumer = true;
232 m_mltConsumer->set("terminate_on_pause", 0);
233 m_mltConsumer->set("deinterlace_method", "onefield");
234 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
236 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
237 } 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()));
241 m_externalConsumer = false;
242 QString videoDriver = KdenliveSettings::videodrivername();
243 if (!videoDriver.isEmpty()) {
244 if (videoDriver == "x11_noaccel") {
245 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
248 unsetenv("SDL_VIDEO_YUV_HWACCEL");
251 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
253 //m_mltConsumer->set("fullscreen", 1);
256 if (!m_mltConsumer) {
257 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
258 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
260 m_mltConsumer->set("preview_off", 1);
261 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
263 if (!m_mltConsumer) {
264 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
265 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
266 m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
268 m_mltConsumer->set("window_id", m_winid);
270 m_mltConsumer->set("resize", 1);
271 m_mltConsumer->set("terminate_on_pause", 1);
272 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
273 m_mltConsumer->set("rescale", "nearest");
274 mlt_log_set_callback(kdenlive_callback);
276 QString audioDevice = KdenliveSettings::audiodevicename();
277 if (!audioDevice.isEmpty())
278 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
280 if (!videoDriver.isEmpty())
281 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
283 QString audioDriver = KdenliveSettings::audiodrivername();
286 // Disabled because the "auto" detected driver was sometimes wrong
287 if (audioDriver.isEmpty())
288 audioDriver = KdenliveSettings::autoaudiodrivername();
291 if (!audioDriver.isEmpty())
292 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
294 m_mltConsumer->set("progressive", 1);
295 m_mltConsumer->set("audio_buffer", 1024);
296 m_mltConsumer->set("frequency", 48000);
297 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
300 Mlt::Producer *Render::invalidProducer(const QString &id)
303 QString txt = '+' + i18n("Missing clip") + ".txt";
304 char *tmp = qstrdup(txt.toUtf8().constData());
305 clip = new Mlt::Producer(*m_mltProfile, tmp);
307 if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
309 clip->set("bgcolour", "0xff0000ff");
310 clip->set("pad", "10");
312 clip->set("id", id.toUtf8().constData());
313 clip->set("mlt_type", "producer");
317 bool Render::hasProfile(const QString &profileName) const
319 return m_activeProfile == profileName;
322 int Render::resetProfile(const QString &profileName, bool dropSceneList)
324 m_refreshTimer.stop();
326 if (m_externalConsumer == KdenliveSettings::external_display()) {
327 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
328 QString videoDriver = KdenliveSettings::videodrivername();
329 QString currentDriver = m_mltConsumer->get("video_driver");
330 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
331 QString background = KdenliveSettings::window_background().name();
332 QString currentBackground = m_mltConsumer->get("window_background");
333 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
334 kDebug() << "reset to same profile, nothing to do";
339 if (m_isSplitView) slotSplitView(false);
340 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
341 m_mltConsumer->purge();
344 if (!dropSceneList) scene = sceneList();
346 double current_fps = m_mltProfile->fps();
347 double current_dar = m_mltProfile->dar();
350 m_requestList.clear();
351 m_infoThread.waitForFinished();
354 pos = m_mltProducer->position();
356 Mlt::Service service(m_mltProducer->get_service());
357 if (service.type() == tractor_type) {
358 Mlt::Tractor tractor(service);
359 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
360 Mlt::Producer trackProducer(tractor.track(trackNb));
361 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
362 trackPlaylist.clear();
366 delete m_mltProducer;
368 m_mltProducer = NULL;
369 buildConsumer(profileName);
370 double new_fps = m_mltProfile->fps();
371 double new_dar = m_mltProfile->dar();
373 if (!dropSceneList) {
374 // We need to recover our playlist
375 if (current_fps != new_fps) {
376 // fps changed, we must update the scenelist positions
377 scene = updateSceneListFps(current_fps, new_fps, scene);
379 setSceneList(scene, pos);
380 // producers have changed (different profile), so reset them...
381 emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
386 void Render::seek(GenTime time)
388 int pos = time.frames(m_fps);
392 void Render::seek(int time)
396 if (requestedSeekPosition == SEEK_INACTIVE) {
397 requestedSeekPosition = time;
398 m_mltProducer->seek(time);
399 //m_mltConsumer->purge();
400 if (m_mltProducer->get_speed() == 0) {
404 else requestedSeekPosition = time;
408 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
409 QPixmap pix(width, height);
411 mlt_image_format format = mlt_image_rgb24a;
412 uint8_t *thumb = frame->get_image(format, width, height);
413 QImage image(thumb, width, height, QImage::Format_ARGB32);
415 if (!image.isNull()) {
416 pix = pix.fromImage(image);
418 QPainter painter(&pix);
419 painter.drawRect(0, 0, width - 1, height - 1);
421 } else pix.fill(Qt::black);
425 int Render::frameRenderWidth() const
427 return m_mltProfile->width();
430 int Render::renderWidth() const
432 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
435 int Render::renderHeight() const
437 return m_mltProfile->height();
440 QImage Render::extractFrame(int frame_position, QString path, int width, int height)
443 width = frameRenderWidth();
444 height = renderHeight();
445 } else if (width % 2 == 1) width++;
446 int dwidth = height * frameRenderWidth() / renderHeight();
447 if (!path.isEmpty()) {
448 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
450 if (producer->is_valid()) {
451 QImage img = KThumb::getFrame(producer, frame_position, dwidth, width, height);
455 else delete producer;
459 if (!m_mltProducer || !path.isEmpty()) {
460 QImage pix(width, height, QImage::Format_RGB32);
464 return KThumb::getFrame(m_mltProducer, frame_position, dwidth, width, height);
467 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
471 if (url.fileName().startsWith(".all.")) { // check for slideshow
472 QString fileType = url.fileName().right(3);
474 QStringList::Iterator it;
476 QDir dir(url.directory());
478 filter << "*." + fileType;
479 filter << "*." + fileType.toUpper();
480 more = dir.entryList(filter, QDir::Files);
481 im.load(url.directory() + '/' + more.at(0));
482 } else im.load(url.path());
483 //pixmap = im.scaled(width, height);
487 double Render::consumerRatio() const
489 if (!m_mltConsumer) return 1.0;
490 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
494 int Render::getLength()
498 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
499 return mlt_producer_get_playtime(m_mltProducer->get_producer());
504 bool Render::isValid(KUrl url)
506 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
507 if (producer.is_blank())
513 double Render::dar() const
515 return m_mltProfile->dar();
518 double Render::sar() const
520 return m_mltProfile->sar();
523 void Render::slotSplitView(bool doit)
525 m_isSplitView = doit;
526 Mlt::Service service(m_mltProducer->parent().get_service());
527 Mlt::Tractor tractor(service);
528 if (service.type() != tractor_type || tractor.count() < 2) return;
529 Mlt::Field *field = tractor.field();
531 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
532 Mlt::Producer trackProducer(tractor.track(i));
533 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
534 if (QString(trackProducer.get("hide")).toInt() != 1) {
535 kDebug() << "// ADIDNG TRACK: " << i;
536 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
537 transition->set("mlt_service", "composite");
538 transition->set("a_track", 0);
539 transition->set("b_track", i);
540 transition->set("distort", 0);
541 transition->set("aligned", 0);
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();
680 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + info.xml.attribute("colour")).toUtf8().constData());
681 } else if (type == TEXT) {
682 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
683 if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
684 producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
685 } else if (url.isEmpty()) {
686 //WARNING: when is this case used? Not sure it is working.. JBM/
688 QDomElement mlt = doc.createElement("mlt");
689 QDomElement play = doc.createElement("playlist");
690 play.setAttribute("id", "playlist0");
691 doc.appendChild(mlt);
692 mlt.appendChild(play);
693 play.appendChild(doc.importNode(info.xml, true));
694 QDomElement tractor = doc.createElement("tractor");
695 tractor.setAttribute("id", "tractor0");
696 QDomElement track = doc.createElement("track");
697 track.setAttribute("producer", "playlist0");
698 tractor.appendChild(track);
699 mlt.appendChild(tractor);
700 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
702 producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
705 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
706 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
707 m_processingClipId.clear();
709 // Proxy file is corrupted
710 emit removeInvalidProxy(info.clipId, false);
712 else emit removeInvalidClip(info.clipId, info.replaceProducer);
717 if (proxyProducer && info.xml.hasAttribute("proxy_out")) {
718 producer->set("length", info.xml.attribute("proxy_out").toInt() + 1);
719 producer->set("out", info.xml.attribute("proxy_out").toInt());
720 if (producer->get_out() != info.xml.attribute("proxy_out").toInt()) {
721 // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
722 m_processingClipId.clear();
723 emit removeInvalidProxy(info.clipId, true);
729 if (info.xml.hasAttribute("force_aspect_ratio")) {
730 double aspect = info.xml.attribute("force_aspect_ratio").toDouble();
731 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
734 if (info.xml.hasAttribute("force_aspect_num") && info.xml.hasAttribute("force_aspect_den")) {
735 int width = info.xml.attribute("frame_size").section('x', 0, 0).toInt();
736 int height = info.xml.attribute("frame_size").section('x', 1, 1).toInt();
737 int aspectNumerator = info.xml.attribute("force_aspect_num").toInt();
738 int aspectDenominator = info.xml.attribute("force_aspect_den").toInt();
739 if (aspectDenominator != 0 && width != 0)
740 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
743 if (info.xml.hasAttribute("force_fps")) {
744 double fps = info.xml.attribute("force_fps").toDouble();
745 if (fps > 0) producer->set("force_fps", fps);
748 if (info.xml.hasAttribute("force_progressive")) {
750 int progressive = info.xml.attribute("force_progressive").toInt(&ok);
751 if (ok) producer->set("force_progressive", progressive);
753 if (info.xml.hasAttribute("force_tff")) {
755 int fieldOrder = info.xml.attribute("force_tff").toInt(&ok);
756 if (ok) producer->set("force_tff", fieldOrder);
758 if (info.xml.hasAttribute("threads")) {
759 int threads = info.xml.attribute("threads").toInt();
760 if (threads != 1) producer->set("threads", threads);
762 if (info.xml.hasAttribute("video_index")) {
763 int vindex = info.xml.attribute("video_index").toInt();
764 if (vindex != 0) producer->set("video_index", vindex);
766 if (info.xml.hasAttribute("audio_index")) {
767 int aindex = info.xml.attribute("audio_index").toInt();
768 if (aindex != 0) producer->set("audio_index", aindex);
770 if (info.xml.hasAttribute("force_colorspace")) {
771 int colorspace = info.xml.attribute("force_colorspace").toInt();
772 if (colorspace != 0) producer->set("force_colorspace", colorspace);
774 if (info.xml.hasAttribute("full_luma")) {
775 int full_luma = info.xml.attribute("full_luma").toInt();
776 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
781 if (info.xml.hasAttribute("out")) clipOut = info.xml.attribute("out").toInt();
783 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
784 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
786 if (info.xml.hasAttribute("length")) {
787 length = info.xml.attribute("length").toInt();
788 clipOut = length - 1;
790 else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt();
791 producer->set("length", length);
795 if (clipOut > 0) producer->set_in_and_out(info.xml.attribute("in").toInt(), clipOut);
797 producer->set("id", info.clipId.toUtf8().constData());
799 if (info.xml.hasAttribute("templatetext"))
800 producer->set("templatetext", info.xml.attribute("templatetext").toUtf8().constData());
802 int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5);
803 int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5);
804 int frameNumber = info.xml.attribute("thumbnail", "-1").toInt();
806 if ((!info.replaceProducer && info.xml.hasAttribute("file_hash")) || proxyProducer) {
807 // Clip already has all properties
809 // Recreate clip thumb
810 if (frameNumber > 0) producer->seek(frameNumber);
811 Mlt::Frame *frame = producer->get_frame();
812 if (frame && frame->is_valid()) {
813 QImage img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
814 emit replyGetImage(info.clipId, img);
816 if (frame) delete frame;
818 m_processingClipId.clear();
819 emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
823 stringMap filePropertyMap;
824 stringMap metadataPropertyMap;
827 if (frameNumber > 0) producer->seek(frameNumber);
828 duration = duration > 0 ? duration : producer->get_playtime();
829 filePropertyMap["duration"] = QString::number(duration);
830 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
832 if (type == SLIDESHOW) {
833 int ttl = info.xml.hasAttribute("ttl") ? info.xml.attribute("ttl").toInt() : 0;
834 if (ttl) producer->set("ttl", ttl);
835 if (!info.xml.attribute("animation").isEmpty()) {
836 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
837 if (filter && filter->is_valid()) {
839 QString geometry = SlideshowClip::animationToGeometry(info.xml.attribute("animation"), cycle);
840 if (!geometry.isEmpty()) {
841 if (info.xml.attribute("animation").contains("low-pass")) {
842 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
843 if (blur && blur->is_valid())
844 producer->attach(*blur);
846 filter->set("transition.geometry", geometry.toUtf8().data());
847 filter->set("transition.cycle", cycle);
848 producer->attach(*filter);
852 if (info.xml.attribute("fade") == "1") {
853 // user wants a fade effect to slideshow
854 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
855 if (filter && filter->is_valid()) {
856 if (ttl) filter->set("cycle", ttl);
857 if (info.xml.hasAttribute("luma_duration") && !info.xml.attribute("luma_duration").isEmpty()) filter->set("duration", info.xml.attribute("luma_duration").toInt());
858 if (info.xml.hasAttribute("luma_file") && !info.xml.attribute("luma_file").isEmpty()) {
859 filter->set("luma.resource", info.xml.attribute("luma_file").toUtf8().constData());
860 if (info.xml.hasAttribute("softness")) {
861 int soft = info.xml.attribute("softness").toInt();
862 filter->set("luma.softness", (double) soft / 100.0);
865 producer->attach(*filter);
868 if (info.xml.attribute("crop") == "1") {
869 // user wants to center crop the slides
870 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
871 if (filter && filter->is_valid()) {
872 filter->set("center", 1);
873 producer->attach(*filter);
879 const QString mltService = producer->get("mlt_service");
880 if (mltService == "xml" || mltService == "consumer") {
881 // MLT playlist, create producer with blank profile to get real profile info
882 // TODO: is there an easier way to get this info (original source clip profile) from MLT?
883 Mlt::Profile *original_profile = new Mlt::Profile();
884 Mlt::Producer *tmpProd = new Mlt::Producer(*original_profile, path.toUtf8().constData());
885 filePropertyMap["progressive"] = QString::number(original_profile->progressive());
886 filePropertyMap["colorspace"] = QString::number(original_profile->colorspace());
887 filePropertyMap["fps"] = QString::number(original_profile->fps());
888 filePropertyMap["aspect_ratio"] = QString::number(original_profile->sar());
890 delete original_profile;
892 else if (mltService == "avformat") {
894 vindex = producer->get_int("video_index");
897 int streams = producer->get_int("meta.media.nb_streams");
898 QList <int> audio_list;
899 QList <int> video_list;
900 for (int i = 0; i < streams; i++) {
901 QByteArray propertyName = QString("meta.media.%1.stream.type").arg(i).toLocal8Bit();
902 QString type = producer->get(propertyName.data());
903 if (type == "audio") audio_list.append(i);
904 else if (type == "video") video_list.append(i);
907 if (!info.xml.hasAttribute("video_index") && video_list.count() > 1) {
908 // Clip has more than one video stream, ask which one should be used
909 QMap <QString, QString> data;
910 if (info.xml.hasAttribute("group")) data.insert("group", info.xml.attribute("group"));
911 if (info.xml.hasAttribute("groupId")) data.insert("groupId", info.xml.attribute("groupId"));
912 emit multiStreamFound(path, audio_list, video_list, data);
913 // Force video index so that when reloading the clip we don't ask again for other streams
914 filePropertyMap["video_index"] = QString::number(vindex);
918 snprintf(property, sizeof(property), "meta.media.%d.stream.frame_rate", vindex);
919 if (producer->get(property))
920 filePropertyMap["fps"] = producer->get(property);
923 if (!filePropertyMap.contains("fps")) {
924 if (producer->get_double("meta.media.frame_rate_den") > 0) {
925 filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
926 } else filePropertyMap["fps"] = producer->get("source_fps");
930 Mlt::Frame *frame = producer->get_frame();
931 if (frame && frame->is_valid()) {
932 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
933 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
934 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
935 if (!filePropertyMap.contains("aspect_ratio")) filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
937 if (frame->get_int("test_image") == 0) {
938 if (mltService == "xml" || mltService == "consumer") {
939 filePropertyMap["type"] = "playlist";
940 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
941 } else if (frame->get_int("test_audio") == 0)
942 filePropertyMap["type"] = "av";
944 filePropertyMap["type"] = "video";
950 img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
951 variance = KThumb::imageVariance(img);
952 if (frameNumber == -1 && variance< 6) {
953 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
954 frameNumber = duration > 100 ? 100 : duration / 2 ;
955 producer->seek(frameNumber);
957 frame = producer->get_frame();
960 } while (variance == -1);
962 if (frameNumber > -1) filePropertyMap["thumbnail"] = QString::number(frameNumber);
963 emit replyGetImage(info.clipId, img);
964 } else if (frame->get_int("test_audio") == 0) {
965 emit replyGetImage(info.clipId, "audio-x-generic", fullWidth, info.imageHeight);
966 filePropertyMap["type"] = "audio";
969 // Retrieve audio / video codec name
972 if (mltService == "avformat") {
974 /*if (context->duration == AV_NOPTS_VALUE) {
975 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
976 emit removeInvalidClip(clipId);
980 // Get the video_index
982 int default_audio = producer->get_int("audio_index");
985 int scan = producer->get_int("meta.media.progressive");
986 filePropertyMap["progressive"] = QString::number(scan);
988 // Find maximum stream index values
989 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
990 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
991 QString type = producer->get(property);
994 else if (type == "audio")
997 filePropertyMap["default_video"] = QString::number(vindex);
998 filePropertyMap["video_max"] = QString::number(video_max);
999 filePropertyMap["default_audio"] = QString::number(default_audio);
1000 filePropertyMap["audio_max"] = QString::number(audio_max);
1002 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex);
1003 if (producer->get(property)) {
1004 filePropertyMap["videocodec"] = producer->get(property);
1006 snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex);
1007 if (producer->get(property))
1008 filePropertyMap["videocodec"] = producer->get(property);
1011 query = QString("meta.media.%1.codec.pix_fmt").arg(vindex);
1012 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
1013 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
1015 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
1016 if (producer->get_int("audio_index") > -1) {
1017 // Get the audio_index
1018 int index = producer->get_int("audio_index");
1019 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
1020 if (producer->get(property)) {
1021 filePropertyMap["audiocodec"] = producer->get(property);
1023 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
1024 if (producer->get(property))
1025 filePropertyMap["audiocodec"] = producer->get(property);
1031 Mlt::Properties metadata;
1032 metadata.pass_values(*producer, "meta.attr.");
1033 int count = metadata.count();
1034 for (int i = 0; i < count; i ++) {
1035 QString name = metadata.get_name(i);
1036 QString value = QString::fromUtf8(metadata.get(i));
1037 if (name.endsWith("markup") && !value.isEmpty())
1038 metadataPropertyMap[ name.section('.', 0, -2)] = value;
1041 m_processingClipId.clear();
1042 emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer);
1044 m_processingClipId.clear();
1049 /** Create the producer from the MLT XML QDomDocument */
1050 void Render::initSceneList()
1052 kDebug() << "-------- INIT SCENE LIST ------_";
1054 QDomElement mlt = doc.createElement("mlt");
1055 doc.appendChild(mlt);
1056 QDomElement prod = doc.createElement("producer");
1057 prod.setAttribute("resource", "colour");
1058 prod.setAttribute("colour", "red");
1059 prod.setAttribute("id", "black");
1060 prod.setAttribute("in", "0");
1061 prod.setAttribute("out", "0");
1063 QDomElement tractor = doc.createElement("tractor");
1064 QDomElement multitrack = doc.createElement("multitrack");
1066 QDomElement playlist1 = doc.createElement("playlist");
1067 playlist1.appendChild(prod);
1068 multitrack.appendChild(playlist1);
1069 QDomElement playlist2 = doc.createElement("playlist");
1070 multitrack.appendChild(playlist2);
1071 QDomElement playlist3 = doc.createElement("playlist");
1072 multitrack.appendChild(playlist3);
1073 QDomElement playlist4 = doc.createElement("playlist");
1074 multitrack.appendChild(playlist4);
1075 QDomElement playlist5 = doc.createElement("playlist");
1076 multitrack.appendChild(playlist5);
1077 tractor.appendChild(multitrack);
1078 mlt.appendChild(tractor);
1079 // kDebug()<<doc.toString();
1081 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
1082 setSceneList(doc, 0);
1086 int Render::setProducer(Mlt::Producer *producer, int position)
1088 m_refreshTimer.stop();
1089 requestedSeekPosition = SEEK_INACTIVE;
1090 QMutexLocker locker(&m_mutex);
1092 int consumerPosition = 0;
1093 if (m_winid == -1 || !m_mltConsumer) {
1094 kDebug()<<" / / / / WARNING, MONITOR NOT READY";
1095 if (producer) delete producer;
1098 m_mltConsumer->set("refresh", 0);
1099 if (!m_mltConsumer->is_stopped()) {
1100 m_mltConsumer->stop();
1102 m_mltConsumer->purge();
1103 consumerPosition = m_mltConsumer->position();
1107 if (!producer || !producer->is_valid()) {
1108 if (producer) delete producer;
1109 producer = m_blackClip->cut(0, 1);
1112 if (!producer || !producer->is_valid()) {
1113 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
1116 if (m_mltProducer) currentId = m_mltProducer->get("id");
1118 if (position == -1 && producer->get("id") == currentId) position = consumerPosition;
1119 if (position != -1) producer->seek(position);
1120 m_fps = producer->get_fps();
1121 int volume = KdenliveSettings::volume();
1122 if (producer->get_int("_audioclip") == 1) {
1123 // This is an audio only clip, create fake multitrack to apply audiowave filter
1124 Mlt::Tractor *tractor = new Mlt::Tractor();
1125 Mlt::Producer *color= new Mlt::Producer(*m_mltProfile, "color:red");
1126 color->set_in_and_out(0, producer->get_out());
1127 tractor->set_track(*producer, 0);
1128 tractor->set_track(*color, 1);
1130 Mlt::Consumer xmlConsumer(*m_mltProfile, "xml:audio_hack");
1131 if (!xmlConsumer.is_valid()) return -1;
1132 xmlConsumer.set("terminate_on_pause", 1);
1133 xmlConsumer.connect(tractor->parent());
1138 QString playlist = QString::fromUtf8(xmlConsumer.get("audio_hack"));
1140 Mlt::Producer *result = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1141 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "audiowave");
1142 result->attach(*filter);
1143 tractor = new Mlt::Tractor();
1144 tractor->set_track(*result, 0);
1147 producer = &(tractor->parent());
1148 m_mltConsumer->connect(*producer);
1151 producer->set("meta.volume", (double)volume / 100);
1152 blockSignals(false);
1153 m_mltConsumer->connect(*producer);
1155 if (m_mltProducer) {
1156 m_mltProducer->set_speed(0);
1157 delete m_mltProducer;
1158 m_mltProducer = NULL;
1160 m_mltProducer = producer;
1161 m_mltProducer->set_speed(0);
1162 emit durationChanged(m_mltProducer->get_playtime());
1163 if (m_mltConsumer->start() == -1) {
1164 // ARGH CONSUMER BROKEN!!!!
1165 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."));
1166 if (m_showFrameEvent) delete m_showFrameEvent;
1167 m_showFrameEvent = NULL;
1168 if (m_pauseEvent) delete m_pauseEvent;
1169 m_pauseEvent = NULL;
1170 delete m_mltConsumer;
1171 m_mltConsumer = NULL;
1175 position = m_mltProducer->position();
1176 m_mltConsumer->set("refresh", 1);
1177 // Make sure the first frame is displayed, otherwise if we change producer too fast
1178 // We can crash the avformat producer
1179 Mlt::Event *ev = m_mltConsumer->setup_wait_for("consumer-frame-show");
1180 m_mltConsumer->wait_for(ev);
1182 emit rendererPosition(position);
1186 int Render::setSceneList(QDomDocument list, int position)
1188 return setSceneList(list.toString(), position);
1191 int Render::setSceneList(QString playlist, int position)
1193 requestedSeekPosition = SEEK_INACTIVE;
1194 m_refreshTimer.stop();
1195 QMutexLocker locker(&m_mutex);
1196 if (m_winid == -1) return -1;
1199 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
1201 // Remove previous profile info
1203 doc.setContent(playlist);
1204 QDomElement profile = doc.documentElement().firstChildElement("profile");
1205 doc.documentElement().removeChild(profile);
1206 playlist = doc.toString();
1208 if (m_mltConsumer) {
1209 if (!m_mltConsumer->is_stopped()) {
1210 m_mltConsumer->stop();
1212 m_mltConsumer->set("refresh", 0);
1214 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
1217 m_requestList.clear();
1218 m_infoThread.waitForFinished();
1220 if (m_mltProducer) {
1221 m_mltProducer->set_speed(0);
1222 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1224 /*Mlt::Service service(m_mltProducer->parent().get_service());
1227 if (service.type() == tractor_type) {
1228 Mlt::Tractor tractor(service);
1229 Mlt::Field *field = tractor.field();
1230 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1231 mlt_service nextservicetodisconnect;
1232 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1233 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1234 QString resource = mlt_properties_get(properties, "mlt_service");
1235 // Delete all transitions
1236 while (mlt_type == "transition") {
1237 nextservicetodisconnect = nextservice;
1238 nextservice = mlt_service_producer(nextservice);
1239 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1240 if (nextservice == NULL) break;
1241 properties = MLT_SERVICE_PROPERTIES(nextservice);
1242 mlt_type = mlt_properties_get(properties, "mlt_type");
1243 resource = mlt_properties_get(properties, "mlt_service");
1247 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1248 Mlt::Producer trackProducer(tractor.track(trackNb));
1249 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1250 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1256 qDeleteAll(m_slowmotionProducers.values());
1257 m_slowmotionProducers.clear();
1259 delete m_mltProducer;
1260 m_mltProducer = NULL;
1265 m_locale = QLocale();
1266 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1267 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1268 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1269 m_mltProducer = m_blackClip->cut(0, 1);
1273 int volume = KdenliveSettings::volume();
1274 m_mltProducer->set("meta.volume", (double)volume / 100);
1275 m_mltProducer->optimise();
1277 /*if (KdenliveSettings::osdtimecode()) {
1278 // Attach filter for on screen display of timecode
1280 QString attr = "attr_check";
1281 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1282 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1283 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1284 mlt_filter_close( filter );
1286 m_osdInfo = new Mlt::Filter("data_show");
1287 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1288 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1289 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1290 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1291 m_osdInfo->set("dynamic", "1");
1293 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1295 m_osdInfo->set("dynamic", "0");
1298 m_fps = m_mltProducer->get_fps();
1299 if (position != 0) {
1300 // Seek to correct place after opening project.
1301 m_mltProducer->seek(position);
1304 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1305 m_mltConsumer->connect(*m_mltProducer);
1306 m_mltProducer->set_speed(0);
1307 fillSlowMotionProducers();
1308 blockSignals(false);
1309 emit durationChanged(m_mltProducer->get_playtime());
1312 //kDebug()<<"// SETSCN LST, POS: "<<position;
1313 //if (position != 0) emit rendererPosition(position);
1316 void Render::checkMaxThreads()
1318 // Make sure we don't use too much threads, MLT avformat does not cope with too much threads
1319 // Currently, Kdenlive uses the following avformat threads:
1320 // One thread to get info when adding a clip
1321 // One thread to create the timeline video thumbnails
1322 // One thread to create the audio thumbnails
1323 Mlt::Service service(m_mltProducer->parent().get_service());
1324 if (service.type() != tractor_type) {
1325 kWarning() << "// TRACTOR PROBLEM";
1328 Mlt::Tractor tractor(service);
1329 int mltMaxThreads = mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1330 int requestedThreads = tractor.count() + 4;
1331 if (requestedThreads > mltMaxThreads) {
1332 mlt_service_cache_set_size(service.get_service(), "producer_avformat", requestedThreads);
1333 kDebug()<<"// MLT threads updated to: "<<mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1337 const QString Render::sceneList()
1340 Mlt::Profile profile((mlt_profile) 0);
1341 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1342 if (!xmlConsumer.is_valid()) return QString();
1343 m_mltProducer->optimise();
1344 xmlConsumer.set("terminate_on_pause", 1);
1345 Mlt::Producer prod(m_mltProducer->get_producer());
1346 if (!prod.is_valid()) return QString();
1347 bool split = m_isSplitView;
1348 if (split) slotSplitView(false);
1349 xmlConsumer.connect(prod);
1351 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1352 if (split) slotSplitView(true);
1356 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1360 doc.setContent(sceneList(), false);
1361 if (doc.isNull()) return false;
1362 QDomElement root = doc.documentElement();
1363 if (!kdenliveData.isNull() && !root.isNull()) {
1364 // add Kdenlive specific tags
1365 root.appendChild(doc.importNode(kdenliveData, true));
1367 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1368 kWarning() << "////// ERROR writing to file: " << path;
1371 file.write(doc.toString().toUtf8());
1372 if (file.error() != QFile::NoError) {
1380 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1382 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1383 m_mltProducer->optimise();
1384 xmlConsumer.set("terminate_on_pause", 1);
1385 if (m_name == Kdenlive::clipMonitor) {
1386 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1388 list.insert_at(0, prod, 0);
1390 list.set("title", desc.toUtf8().constData());
1391 xmlConsumer.connect(list);
1394 //TODO: not working yet, save zone from timeline
1395 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1396 /* Mlt::Service service(p1->parent().get_service());
1397 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1399 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1400 //prod->set("title", desc.toUtf8().constData());
1401 xmlConsumer.connect(*p1); //list);
1404 xmlConsumer.start();
1408 bool Render::saveClip(int track, GenTime position, KUrl url, QString desc)
1411 Mlt::Service service(m_mltProducer->parent().get_service());
1412 Mlt::Tractor tractor(service);
1413 Mlt::Producer trackProducer(tractor.track(track));
1414 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1416 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1417 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1419 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1423 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1424 xmlConsumer.set("terminate_on_pause", 1);
1426 list.insert_at(0, clip, 0);
1428 list.set("title", desc.toUtf8().constData());
1429 xmlConsumer.connect(list);
1431 kDebug()<<"// SAVED: "<<url;
1435 double Render::fps() const
1440 int Render::volume() const
1442 if (!m_mltConsumer || !m_mltProducer) return -1;
1443 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1446 void Render::slotSetVolume(int volume)
1448 if (!m_mltConsumer || !m_mltProducer) return;
1449 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1452 m_mltConsumer->set("refresh", 0);
1453 // Attach filter for on screen display of timecode
1454 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1455 mlt_properties_set_double( properties, "meta.volume", volume );
1456 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1457 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1459 if (!KdenliveSettings::osdtimecode()) {
1460 m_mltProducer->detach(*m_osdInfo);
1461 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1462 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1465 //m_osdTimer->setSingleShot(2500);
1468 void Render::slotOsdTimeout()
1470 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1471 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1472 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1473 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1477 void Render::start()
1479 m_refreshTimer.stop();
1480 QMutexLocker locker(&m_mutex);
1481 if (m_winid == -1) {
1482 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1485 if (!m_mltConsumer) return;
1486 if (m_mltConsumer->is_stopped()) {
1487 if (m_mltConsumer->start() == -1) {
1488 //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."));
1489 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1491 m_mltConsumer->purge();
1492 m_mltConsumer->set("refresh", 1);
1499 requestedSeekPosition = SEEK_INACTIVE;
1500 m_refreshTimer.stop();
1501 QMutexLocker locker(&m_mutex);
1502 if (m_mltProducer == NULL) return;
1503 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1504 m_mltConsumer->stop();
1505 m_mltConsumer->purge();
1508 if (m_mltProducer) {
1509 if (m_isZoneMode) resetZoneMode();
1510 m_mltProducer->set_speed(0.0);
1514 void Render::stop(const GenTime & startTime)
1516 requestedSeekPosition = SEEK_INACTIVE;
1517 m_refreshTimer.stop();
1518 QMutexLocker locker(&m_mutex);
1519 if (m_mltProducer) {
1520 if (m_isZoneMode) resetZoneMode();
1521 m_mltProducer->set_speed(0.0);
1522 m_mltProducer->seek((int) startTime.frames(m_fps));
1524 m_mltConsumer->purge();
1527 void Render::pause()
1529 requestedSeekPosition = SEEK_INACTIVE;
1530 if (!m_mltProducer || !m_mltConsumer)
1532 if (m_mltProducer->get_speed() == 0.0) return;
1533 if (m_isZoneMode) resetZoneMode();
1534 m_mltConsumer->set("refresh", 0);
1535 m_mltProducer->set_speed(0.0);
1536 m_mltConsumer->purge();
1539 void Render::switchPlay(bool play)
1541 QMutexLocker locker(&m_mutex);
1542 requestedSeekPosition = SEEK_INACTIVE;
1543 if (!m_mltProducer || !m_mltConsumer)
1545 if (m_isZoneMode) resetZoneMode();
1546 if (play && m_mltProducer->get_speed() == 0.0) {
1547 if (m_name == Kdenlive::clipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
1548 if (m_mltConsumer->is_stopped()) {
1549 m_mltConsumer->start();
1551 m_mltProducer->set_speed(1.0);
1552 m_mltConsumer->set("refresh", 1);
1554 m_mltProducer->set_speed(0.0);
1555 m_mltConsumer->set("refresh", 0);
1556 m_mltProducer->seek(m_mltConsumer->position());
1557 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1558 if (m_isZoneMode) resetZoneMode();
1560 //emitConsumerStopped();
1561 /*m_mltConsumer->set("refresh", 0);
1562 m_mltConsumer->stop();
1563 m_mltConsumer->purge();
1564 m_mltProducer->set_speed(0.0);
1565 //m_framePosition = m_mltProducer->position();
1566 m_mltProducer->seek(m_framePosition);
1567 emit rendererPosition(m_framePosition);*/
1571 void Render::play(double speed)
1573 requestedSeekPosition = SEEK_INACTIVE;
1576 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1577 m_mltProducer->set_speed(speed);
1578 /*if (speed == 0.0) {
1579 m_mltProducer->seek((int) m_framePosition + 1);
1580 m_mltConsumer->purge();
1585 void Render::play(const GenTime & startTime)
1587 requestedSeekPosition = SEEK_INACTIVE;
1588 if (!m_mltProducer || !m_mltConsumer)
1590 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1591 m_mltProducer->set_speed(1.0);
1592 m_mltConsumer->set("refresh", 1);
1595 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1597 requestedSeekPosition = SEEK_INACTIVE;
1598 if (!m_mltProducer || !m_mltConsumer)
1600 //m_mltProducer->set("eof", "loop");
1601 m_isLoopMode = true;
1602 m_loopStart = startTime;
1603 playZone(startTime, stopTime);
1606 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1608 requestedSeekPosition = SEEK_INACTIVE;
1609 if (!m_mltProducer || !m_mltConsumer)
1611 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1612 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1613 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1614 m_mltProducer->set_speed(1.0);
1615 m_mltConsumer->set("refresh", 1);
1616 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1617 m_isZoneMode = true;
1620 void Render::resetZoneMode()
1622 if (!m_mltProducer || (!m_isZoneMode && !m_isLoopMode)) return;
1623 m_mltProducer->set("out", m_originalOut);
1624 //m_mltProducer->set("eof", "pause");
1625 m_isZoneMode = false;
1626 m_isLoopMode = false;
1629 void Render::seekToFrame(int pos)
1635 void Render::seekToFrameDiff(int diff)
1638 if (requestedSeekPosition == SEEK_INACTIVE)
1639 seek(m_mltProducer->position() + diff);
1640 else seek(requestedSeekPosition + diff);
1643 void Render::doRefresh()
1645 if (m_mltProducer && m_mltProducer->get_speed() == 0) m_refreshTimer.start();
1648 void Render::refresh()
1650 QMutexLocker locker(&m_mutex);
1653 if (m_mltConsumer) {
1654 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1655 //m_mltConsumer->purge();
1656 m_mltConsumer->set("refresh", 1);
1660 void Render::setDropFrames(bool show)
1662 QMutexLocker locker(&m_mutex);
1663 if (m_mltConsumer) {
1664 int dropFrames = KdenliveSettings::mltthreads();
1665 if (show == false) dropFrames = -dropFrames;
1666 m_mltConsumer->stop();
1668 m_mltConsumer->set("real_time", dropFrames);
1670 m_mltConsumer->set("play.real_time", dropFrames);
1672 if (m_mltConsumer->start() == -1) {
1673 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1679 double Render::playSpeed() const
1681 if (m_mltProducer) return m_mltProducer->get_speed();
1685 GenTime Render::seekPosition() const
1687 if (m_mltConsumer) return GenTime((int) m_mltConsumer->position(), m_fps);
1688 //if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1689 else return GenTime();
1692 int Render::seekFramePosition() const
1694 //if (m_mltProducer) return (int) m_mltProducer->position();
1695 if (m_mltConsumer) return (int) m_mltConsumer->position();
1699 void Render::emitFrameUpdated(Mlt::Frame& frame)
1701 mlt_image_format format = mlt_image_rgb24a;
1704 const uchar* image = frame.get_image(format, width, height);
1705 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1706 memcpy(qimage.scanLine(0), image, width * height * 4);
1707 emit frameUpdated(qimage.rgbSwapped());
1710 void Render::emitFrameNumber()
1712 int currentPos = m_mltConsumer->position();
1713 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1714 emit rendererPosition(currentPos);
1715 if (requestedSeekPosition != SEEK_INACTIVE) {
1716 m_mltProducer->seek(requestedSeekPosition);
1717 if (m_mltProducer->get_speed() == 0) {
1720 requestedSeekPosition = SEEK_INACTIVE;
1724 void Render::emitConsumerStopped()
1726 // This is used to know when the playing stopped
1727 if (m_mltProducer) {
1728 double pos = m_mltProducer->position();
1729 if (m_isLoopMode) play(m_loopStart);
1730 //else if (m_isZoneMode) resetZoneMode();
1731 emit rendererStopped((int) pos);
1735 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1737 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1740 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1742 if (!m_mltProducer) {
1743 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1747 //int height = 1080;//KdenliveSettings::defaultheight();
1748 //int width = 1940; //KdenliveSettings::displaywidth();
1750 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1752 QPixmap pix(width, height);
1753 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1754 m_convert.set("forced", mlt_image_rgb24a);
1755 m_mltProducer->attach(m_convert);
1756 Mlt::Frame * frame = m_mltProducer->get_frame();
1757 m_mltProducer->detach(m_convert);
1759 pix = frameThumbnail(frame, width, height);
1762 pix.save(url.path(), "PNG");
1763 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1767 void Render::showFrame(Mlt::Frame& frame)
1769 int currentPos = m_mltConsumer->position();
1770 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1771 emit rendererPosition(currentPos);
1772 if (frame.is_valid()) {
1773 mlt_image_format format = mlt_image_rgb24a;
1776 const uchar* image = frame.get_image(format, width, height);
1777 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1778 memcpy(qimage.scanLine(0), image, width * height * 4);
1779 emit showImageSignal(qimage);
1780 if (analyseAudio) showAudio(frame);
1781 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1782 emit frameUpdated(qimage.rgbSwapped());
1785 emit checkSeeking();
1788 void Render::slotCheckSeeking()
1790 if (requestedSeekPosition != SEEK_INACTIVE) {
1791 m_mltProducer->seek(requestedSeekPosition);
1792 if (m_mltProducer->get_speed() == 0) {
1798 void Render::disablePreview(bool disable)
1800 if (m_mltConsumer) {
1801 m_mltConsumer->stop();
1802 m_mltConsumer->set("preview_off", (int) disable);
1803 m_mltConsumer->set("refresh", 0);
1804 m_mltConsumer->start();
1808 void Render::showAudio(Mlt::Frame& frame)
1810 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1813 mlt_audio_format audio_format = mlt_audio_s16;
1814 //FIXME: should not be hardcoded..
1816 int num_channels = 2;
1818 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1824 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1825 // So the vector is of size samples*channels.
1826 QVector<int16_t> sampleVector(samples*num_channels);
1827 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1830 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1835 * MLT playlist direct manipulation.
1838 void Render::mltCheckLength(Mlt::Tractor *tractor)
1840 //kDebug()<<"checking track length: "<<track<<"..........";
1842 int trackNb = tractor->count();
1846 Mlt::Producer trackProducer(tractor->track(0));
1847 duration = trackProducer.get_playtime() - 1;
1848 m_mltProducer->set("out", duration);
1849 emit durationChanged(duration);
1852 while (trackNb > 1) {
1853 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1854 trackDuration = trackProducer.get_playtime() - 1;
1855 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1856 if (trackDuration > duration) duration = trackDuration;
1860 Mlt::Producer blackTrackProducer(tractor->track(0));
1862 if (blackTrackProducer.get_playtime() - 1 != duration) {
1863 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1864 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1865 if (blackclip && blackclip->is_blank()) {
1870 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1871 if (blackclip) delete blackclip;
1872 blackTrackPlaylist.clear();
1873 m_blackClip->set("length", duration + 1);
1874 m_blackClip->set("out", duration);
1875 blackclip = m_blackClip->cut(0, duration);
1876 blackTrackPlaylist.insert_at(0, blackclip, 1);
1878 if (duration > blackclip->parent().get_length()) {
1879 blackclip->parent().set("length", duration + 1);
1880 blackclip->parent().set("out", duration);
1881 blackclip->set("length", duration + 1);
1883 blackTrackPlaylist.resize_clip(0, 0, duration);
1887 m_mltProducer->set("out", duration);
1888 emit durationChanged(duration);
1892 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1894 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1896 // We want a slowmotion producer
1897 double speed = element.attribute("speed", "1.0").toDouble();
1898 int strobe = element.attribute("strobe", "1").toInt();
1899 QString url = QString::fromUtf8(prod->get("resource"));
1900 url.append('?' + locale.toString(speed));
1901 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1902 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1903 if (!slowprod || slowprod->get_producer() == NULL) {
1904 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
1905 if (strobe > 1) slowprod->set("strobe", strobe);
1906 QString id = prod->parent().get("id");
1907 if (id.contains('_')) id = id.section('_', 0, 0);
1908 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
1909 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1910 slowprod->set("id", producerid.toUtf8().constData());
1911 m_slowmotionProducers.insert(url, slowprod);
1916 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1918 if (m_mltProducer == NULL) {
1919 kDebug() << "PLAYLIST NOT INITIALISED //////";
1923 kDebug() << "Cannot insert clip without producer //////";
1926 Mlt::Producer parentProd(m_mltProducer->parent());
1927 if (parentProd.get_producer() == NULL) {
1928 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1932 Mlt::Service service(parentProd.get_service());
1933 if (service.type() != tractor_type) {
1934 kWarning() << "// TRACTOR PROBLEM";
1937 Mlt::Tractor tractor(service);
1938 if (info.track > tractor.count() - 1) {
1939 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1943 Mlt::Producer trackProducer(tractor.track(info.track));
1944 int trackDuration = trackProducer.get_playtime() - 1;
1945 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1946 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1947 prod = checkSlowMotionProducer(prod, element);
1948 if (prod == NULL || !prod->is_valid()) {
1953 int cutPos = (int) info.cropStart.frames(m_fps);
1954 if (cutPos < 0) cutPos = 0;
1955 int insertPos = (int) info.startPos.frames(m_fps);
1956 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1957 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1958 if (overwrite && (insertPos < trackDuration)) {
1959 // Replace zone with blanks
1960 //trackPlaylist.split_at(insertPos, true);
1961 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1962 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1963 trackPlaylist.insert_blank(clipIndex, cutDuration);
1965 trackPlaylist.split_at(insertPos, true);
1966 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1967 trackPlaylist.insert_blank(clipIndex, cutDuration);
1969 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1971 /*if (QString(prod->get("transparency")).toInt() == 1)
1972 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1974 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1976 /*tractor.multitrack()->refresh();
1977 tractor.refresh();*/
1982 bool Render::mltCutClip(int track, GenTime position)
1984 Mlt::Service service(m_mltProducer->parent().get_service());
1985 if (service.type() != tractor_type) {
1986 kWarning() << "// TRACTOR PROBLEM";
1990 Mlt::Tractor tractor(service);
1991 Mlt::Producer trackProducer(tractor.track(track));
1992 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1995 /* // Display playlist info
1996 kDebug()<<"//////////// BEFORE";
1997 for (int i = 0; i < trackPlaylist.count(); i++) {
1998 int blankStart = trackPlaylist.clip_start(i);
1999 int blankDuration = trackPlaylist.clip_length(i) - 1;
2001 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2002 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2005 int cutPos = (int) position.frames(m_fps);
2007 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
2008 if (trackPlaylist.is_blank(clipIndex)) {
2009 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
2013 int clipStart = trackPlaylist.clip_start(clipIndex);
2014 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
2017 // duplicate effects
2018 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
2019 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
2021 if (original == NULL || clip == NULL) {
2022 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
2026 Mlt::Service clipService(original->get_service());
2027 Mlt::Service dupService(clip->get_service());
2033 Mlt::Filter *filter = clipService.filter(ct);
2035 // Only duplicate Kdenlive filters, and skip the fade in effects
2036 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
2037 // looks like there is no easy way to duplicate a filter,
2038 // so we will create a new one and duplicate its properties
2039 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
2040 if (dup && dup->is_valid()) {
2041 Mlt::Properties entries(filter->get_properties());
2042 for (int i = 0; i < entries.count(); i++) {
2043 dup->set(entries.get_name(i), entries.get(i));
2045 dupService.attach(*dup);
2049 filter = clipService.filter(ct);
2052 /* // Display playlist info
2053 kDebug()<<"//////////// AFTER";
2054 for (int i = 0; i < trackPlaylist.count(); i++) {
2055 int blankStart = trackPlaylist.clip_start(i);
2056 int blankDuration = trackPlaylist.clip_length(i) - 1;
2058 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2059 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2064 Mlt::Tractor *Render::lockService()
2066 // we are going to replace some clips, purge consumer
2067 QMutexLocker locker(&m_mutex);
2068 if (!m_mltProducer) return NULL;
2069 if (m_mltConsumer) {
2070 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
2071 m_mltConsumer->purge();
2073 Mlt::Service service(m_mltProducer->parent().get_service());
2074 if (service.type() != tractor_type) {
2075 kWarning() << "// TRACTOR PROBLEM";
2079 return new Mlt::Tractor(service);
2083 void Render::unlockService(Mlt::Tractor *tractor)
2088 if (!m_mltProducer) return;
2089 Mlt::Service service(m_mltProducer->parent().get_service());
2090 if (service.type() != tractor_type) {
2091 kWarning() << "// TRACTOR PROBLEM";
2097 bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement element, Mlt::Producer *prod)
2100 if (prod == NULL || tractor == NULL) {
2101 kDebug() << "Cannot update clip with null producer //////";
2105 Mlt::Producer trackProducer(tractor->track(tractor->count() - 1 - info.track));
2106 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2107 int startPos = info.startPos.frames(m_fps);
2108 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2109 if (trackPlaylist.is_blank(clipIndex)) {
2110 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
2113 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2115 QList <Mlt::Filter *> filtersList;
2116 Mlt::Service sourceService(clip->get_service());
2118 Mlt::Filter *filter = sourceService.filter(ct);
2120 if (filter->get_int("kdenlive_ix") != 0) {
2121 filtersList.append(filter);
2124 filter = sourceService.filter(ct);
2127 clip = trackPlaylist.replace_with_blank(clipIndex);
2129 prod = checkSlowMotionProducer(prod, element);
2130 if (prod == NULL || !prod->is_valid()) {
2134 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
2135 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
2136 Mlt::Service destService(clip2->get_service());
2139 if (!filtersList.isEmpty()) {
2140 for (int i = 0; i < filtersList.count(); i++)
2141 destService.attach(*(filtersList.at(i)));
2147 bool Render::mltRemoveClip(int track, GenTime position)
2149 Mlt::Service service(m_mltProducer->parent().get_service());
2150 if (service.type() != tractor_type) {
2151 kWarning() << "// TRACTOR PROBLEM";
2155 Mlt::Tractor tractor(service);
2156 Mlt::Producer trackProducer(tractor.track(track));
2157 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2158 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2160 if (trackPlaylist.is_blank(clipIndex)) {
2161 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
2165 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2166 if (clip) delete clip;
2167 trackPlaylist.consolidate_blanks(0);
2169 /* // Display playlist info
2170 kDebug()<<"//// AFTER";
2171 for (int i = 0; i < trackPlaylist.count(); i++) {
2172 int blankStart = trackPlaylist.clip_start(i);
2173 int blankDuration = trackPlaylist.clip_length(i) - 1;
2175 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2176 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2179 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
2183 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
2185 if (!m_mltProducer) {
2186 kDebug() << "PLAYLIST NOT INITIALISED //////";
2189 Mlt::Producer parentProd(m_mltProducer->parent());
2190 if (parentProd.get_producer() == NULL) {
2191 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2195 Mlt::Service service(parentProd.get_service());
2196 Mlt::Tractor tractor(service);
2197 int insertPos = pos.frames(m_fps);
2199 Mlt::Producer trackProducer(tractor.track(track));
2200 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2201 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2202 if (clipIndex == trackPlaylist.count()) {
2203 // We are after the end of the playlist
2206 if (!trackPlaylist.is_blank(clipIndex)) return 0;
2207 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
2208 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
2211 int Render::mltTrackDuration(int track)
2213 if (!m_mltProducer) {
2214 kDebug() << "PLAYLIST NOT INITIALISED //////";
2217 Mlt::Producer parentProd(m_mltProducer->parent());
2218 if (parentProd.get_producer() == NULL) {
2219 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2223 Mlt::Service service(parentProd.get_service());
2224 Mlt::Tractor tractor(service);
2226 Mlt::Producer trackProducer(tractor.track(track));
2227 return trackProducer.get_playtime() - 1;
2230 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
2232 if (!m_mltProducer) {
2233 kDebug() << "PLAYLIST NOT INITIALISED //////";
2236 Mlt::Producer parentProd(m_mltProducer->parent());
2237 if (parentProd.get_producer() == NULL) {
2238 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2241 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
2242 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
2244 Mlt::Service service(parentProd.get_service());
2245 Mlt::Tractor tractor(service);
2247 int diff = duration.frames(m_fps);
2248 int offset = timeOffset.frames(m_fps);
2252 // insert space in one track only
2253 Mlt::Producer trackProducer(tractor.track(track));
2254 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2255 insertPos = trackClipStartList.value(track);
2256 if (insertPos != -1) {
2257 insertPos += offset;
2258 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2260 trackPlaylist.insert_blank(clipIndex, diff - 1);
2262 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
2263 if (!trackPlaylist.is_blank(clipIndex)) {
2264 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2266 int position = trackPlaylist.clip_start(clipIndex);
2267 int blankDuration = trackPlaylist.clip_length(clipIndex);
2268 if (blankDuration + diff == 0) {
2269 trackPlaylist.remove(clipIndex);
2270 } else trackPlaylist.remove_region(position, -diff);
2272 trackPlaylist.consolidate_blanks(0);
2274 // now move transitions
2275 mlt_service serv = m_mltProducer->parent().get_service();
2276 mlt_service nextservice = mlt_service_get_producer(serv);
2277 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2278 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2279 QString resource = mlt_properties_get(properties, "mlt_service");
2281 while (mlt_type == "transition") {
2282 mlt_transition tr = (mlt_transition) nextservice;
2283 int currentTrack = mlt_transition_get_b_track(tr);
2284 int currentIn = (int) mlt_transition_get_in(tr);
2285 int currentOut = (int) mlt_transition_get_out(tr);
2286 insertPos = trackTransitionStartList.value(track);
2287 if (insertPos != -1) {
2288 insertPos += offset;
2289 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
2290 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2293 nextservice = mlt_service_producer(nextservice);
2294 if (nextservice == NULL) break;
2295 properties = MLT_SERVICE_PROPERTIES(nextservice);
2296 mlt_type = mlt_properties_get(properties, "mlt_type");
2297 resource = mlt_properties_get(properties, "mlt_service");
2300 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
2301 Mlt::Producer trackProducer(tractor.track(trackNb));
2302 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2304 //int clipNb = trackPlaylist.count();
2305 insertPos = trackClipStartList.value(trackNb);
2306 if (insertPos != -1) {
2307 insertPos += offset;
2309 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2310 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2311 for (int i = 0; i < clipNb; i++) {
2312 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2313 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2314 kDebug()<<"-------------";
2316 kDebug()<<"END-------------";*/
2319 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2321 trackPlaylist.insert_blank(clipIndex, diff - 1);
2323 if (!trackPlaylist.is_blank(clipIndex)) {
2326 if (!trackPlaylist.is_blank(clipIndex)) {
2327 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2329 int position = trackPlaylist.clip_start(clipIndex);
2330 int blankDuration = trackPlaylist.clip_length(clipIndex);
2331 if (diff + blankDuration == 0) {
2332 trackPlaylist.remove(clipIndex);
2333 } else trackPlaylist.remove_region(position, - diff);
2335 trackPlaylist.consolidate_blanks(0);
2338 // now move transitions
2339 mlt_service serv = m_mltProducer->parent().get_service();
2340 mlt_service nextservice = mlt_service_get_producer(serv);
2341 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2342 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2343 QString resource = mlt_properties_get(properties, "mlt_service");
2345 while (mlt_type == "transition") {
2346 mlt_transition tr = (mlt_transition) nextservice;
2347 int currentIn = (int) mlt_transition_get_in(tr);
2348 int currentOut = (int) mlt_transition_get_out(tr);
2349 int currentTrack = mlt_transition_get_b_track(tr);
2350 insertPos = trackTransitionStartList.value(currentTrack);
2351 if (insertPos != -1) {
2352 insertPos += offset;
2353 if (currentOut > insertPos && resource != "mix") {
2354 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2357 nextservice = mlt_service_producer(nextservice);
2358 if (nextservice == NULL) break;
2359 properties = MLT_SERVICE_PROPERTIES(nextservice);
2360 mlt_type = mlt_properties_get(properties, "mlt_type");
2361 resource = mlt_properties_get(properties, "mlt_service");
2365 mltCheckLength(&tractor);
2366 m_mltConsumer->set("refresh", 1);
2370 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2372 if (source == dest) return;
2373 Mlt::Service sourceService(source->get_service());
2374 Mlt::Service destService(dest->get_service());
2376 // move all effects to the correct producer
2378 Mlt::Filter *filter = sourceService.filter(ct);
2380 if (filter->get_int("kdenlive_ix") != 0) {
2381 sourceService.detach(*filter);
2382 destService.attach(*filter);
2384 filter = sourceService.filter(ct);
2388 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2391 Mlt::Service service(m_mltProducer->parent().get_service());
2392 if (service.type() != tractor_type) {
2393 kWarning() << "// TRACTOR PROBLEM";
2397 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2398 Mlt::Tractor tractor(service);
2399 Mlt::Producer trackProducer(tractor.track(info.track));
2400 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2401 int startPos = info.startPos.frames(m_fps);
2402 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2403 int clipLength = trackPlaylist.clip_length(clipIndex);
2405 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2406 if (original == NULL) {
2409 if (!original->is_valid() || original->is_blank()) {
2414 Mlt::Producer clipparent = original->parent();
2415 if (!clipparent.is_valid() || clipparent.is_blank()) {
2421 QString serv = clipparent.get("mlt_service");
2422 QString id = clipparent.get("id");
2423 if (speed <= 0 && speed > -1) speed = 1.0;
2424 //kDebug() << "CLIP SERVICE: " << serv;
2425 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2427 QString url = QString::fromUtf8(clipparent.get("resource"));
2428 url.append('?' + m_locale.toString(speed));
2429 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2430 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2431 if (!slowprod || slowprod->get_producer() == NULL) {
2432 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2433 if (strobe > 1) slowprod->set("strobe", strobe);
2434 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2435 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2436 slowprod->set("id", producerid.toUtf8().constData());
2437 // copy producer props
2438 double ar = original->parent().get_double("force_aspect_ratio");
2439 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2440 double fps = original->parent().get_double("force_fps");
2441 if (fps != 0.0) slowprod->set("force_fps", fps);
2442 int threads = original->parent().get_int("threads");
2443 if (threads != 0) slowprod->set("threads", threads);
2444 if (original->parent().get("force_progressive"))
2445 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2446 if (original->parent().get("force_tff"))
2447 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2448 int ix = original->parent().get_int("video_index");
2449 if (ix != 0) slowprod->set("video_index", ix);
2450 int colorspace = original->parent().get_int("force_colorspace");
2451 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2452 int full_luma = original->parent().get_int("set.force_full_luma");
2453 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2454 m_slowmotionProducers.insert(url, slowprod);
2456 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2457 trackPlaylist.consolidate_blanks(0);
2459 // Check that the blank space is long enough for our new duration
2460 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2461 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2463 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2464 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2465 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2466 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2468 // move all effects to the correct producer
2469 mltPasteEffects(clip, cut);
2470 trackPlaylist.insert_at(startPos, cut, 1);
2473 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2474 newLength = trackPlaylist.clip_length(clipIndex);
2476 } else if (speed == 1.0 && strobe < 2) {
2479 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2480 trackPlaylist.consolidate_blanks(0);
2482 // Check that the blank space is long enough for our new duration
2483 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2484 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2487 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2488 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2489 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2490 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2491 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2493 // move all effects to the correct producer
2494 mltPasteEffects(clip, cut);
2496 trackPlaylist.insert_at(startPos, cut, 1);
2499 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2500 newLength = trackPlaylist.clip_length(clipIndex);
2503 } else if (serv == "framebuffer") {
2505 QString url = QString::fromUtf8(clipparent.get("resource"));
2506 url = url.section('?', 0, 0);
2507 url.append('?' + m_locale.toString(speed));
2508 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2509 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2510 if (!slowprod || slowprod->get_producer() == NULL) {
2511 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2512 slowprod->set("strobe", strobe);
2513 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2514 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2515 slowprod->set("id", producerid.toUtf8().constData());
2516 // copy producer props
2517 double ar = original->parent().get_double("force_aspect_ratio");
2518 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2519 double fps = original->parent().get_double("force_fps");
2520 if (fps != 0.0) slowprod->set("force_fps", fps);
2521 if (original->parent().get("force_progressive"))
2522 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2523 if (original->parent().get("force_tff"))
2524 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2525 int threads = original->parent().get_int("threads");
2526 if (threads != 0) slowprod->set("threads", threads);
2527 int ix = original->parent().get_int("video_index");
2528 if (ix != 0) slowprod->set("video_index", ix);
2529 int colorspace = original->parent().get_int("force_colorspace");
2530 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2531 int full_luma = original->parent().get_int("set.force_full_luma");
2532 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2533 m_slowmotionProducers.insert(url, slowprod);
2535 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2536 trackPlaylist.consolidate_blanks(0);
2538 GenTime duration = speedIndependantInfo.cropDuration / speed;
2539 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2541 // Check that the blank space is long enough for our new duration
2542 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2543 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2546 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2547 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2548 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2549 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2551 // move all effects to the correct producer
2552 mltPasteEffects(clip, cut);
2554 trackPlaylist.insert_at(startPos, cut, 1);
2557 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2558 newLength = trackPlaylist.clip_length(clipIndex);
2563 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2567 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2569 Mlt::Service service(m_mltProducer->parent().get_service());
2570 bool success = false;
2571 Mlt::Tractor tractor(service);
2572 Mlt::Producer trackProducer(tractor.track(track));
2573 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2574 Mlt::Service clipService(trackPlaylist.get_service());
2578 Mlt::Filter *filter = clipService.filter(ct);
2580 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2581 if (clipService.detach(*filter) == 0) success = true;
2582 } else if (updateIndex) {
2583 // Adjust the other effects index
2584 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2587 filter = clipService.filter(ct);
2594 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2596 if (position < GenTime()) {
2597 // Remove track effect
2598 return mltRemoveTrackEffect(track, index, updateIndex);
2600 Mlt::Service service(m_mltProducer->parent().get_service());
2601 bool success = false;
2602 Mlt::Tractor tractor(service);
2603 Mlt::Producer trackProducer(tractor.track(track));
2604 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2606 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2607 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2609 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2613 Mlt::Service clipService(clip->get_service());
2614 int duration = clip->get_playtime();
2616 // Check if clip is visible in monitor
2617 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2618 if (diff < 0 || diff > duration) doRefresh = false;
2624 Mlt::Filter *filter = clipService.filter(ct);
2626 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2627 if (clipService.detach(*filter) == 0) success = true;
2628 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2629 } else if (updateIndex) {
2630 // Adjust the other effects index
2631 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2634 filter = clipService.filter(ct);
2637 if (doRefresh) refresh();
2641 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2643 Mlt::Service service(m_mltProducer->parent().get_service());
2644 Mlt::Tractor tractor(service);
2645 Mlt::Producer trackProducer(tractor.track(track));
2646 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2647 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2648 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2652 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2655 Mlt::Service service(m_mltProducer->parent().get_service());
2657 Mlt::Tractor tractor(service);
2658 Mlt::Producer trackProducer(tractor.track(track));
2659 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2661 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2662 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2667 Mlt::Service clipService(clip->get_service());
2668 int duration = clip->get_playtime();
2670 // Check if clip is visible in monitor
2671 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2672 if (diff < 0 || diff > duration) doRefresh = false;
2675 return mltAddEffect(clipService, params, duration, doRefresh);
2678 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2680 bool updateIndex = false;
2681 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2685 Mlt::Filter *filter = service.filter(ct);
2687 if (filter->get_int("kdenlive_ix") == filter_ix) {
2688 // A filter at that position already existed, so we will increase all indexes later
2693 filter = service.filter(ct);
2696 if (params.paramValue("id") == "speed") {
2697 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2699 filter = service.filter(ct);
2701 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2702 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2705 filter = service.filter(ct);
2708 if (doRefresh) refresh();
2713 // temporarily remove all effects after insert point
2714 QList <Mlt::Filter *> filtersList;
2716 filter = service.filter(ct);
2718 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2719 filtersList.append(filter);
2720 service.detach(*filter);
2722 filter = service.filter(ct);
2725 addFilterToService(service, params, duration);
2727 // re-add following filters
2728 for (int i = 0; i < filtersList.count(); i++) {
2729 Mlt::Filter *filter = filtersList.at(i);
2731 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2732 service.attach(*filter);
2735 if (doRefresh) refresh();
2740 bool Render::addFilterToService(Mlt::Service service, EffectsParameterList params, int duration)
2743 QString tag = params.paramValue("tag");
2744 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2745 char *filterTag = qstrdup(tag.toUtf8().constData());
2746 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2747 QString kfr = params.paramValue("keyframes");
2748 if (!kfr.isEmpty()) {
2749 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2750 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2751 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2752 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2753 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2754 //double max = params.paramValue("max").toDouble();
2755 double min = params.paramValue("min").toDouble();
2756 double factor = params.paramValue("factor", "1").toDouble();
2757 double paramOffset = params.paramValue("offset", "0").toDouble();
2758 params.removeParam("starttag");
2759 params.removeParam("endtag");
2760 params.removeParam("keyframes");
2761 params.removeParam("min");
2762 params.removeParam("max");
2763 params.removeParam("factor");
2764 params.removeParam("offset");
2766 // Special case, only one keyframe, means we want a constant value
2767 if (keyFrames.count() == 1) {
2768 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2769 if (filter && filter->is_valid()) {
2770 filter->set("kdenlive_id", filterId);
2771 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2772 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2773 for (int j = 0; j < params.count(); j++) {
2774 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2776 filter->set("in", x1);
2777 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2778 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2779 service.attach(*filter);
2781 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2782 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2783 if (filter && filter->is_valid()) {
2784 filter->set("kdenlive_id", filterId);
2785 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2786 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2787 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2788 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2789 if (x2 == -1) x2 = duration;
2791 for (int j = 0; j < params.count(); j++) {
2792 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2795 filter->set("in", x1);
2796 filter->set("out", x2);
2797 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2798 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2799 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2800 service.attach(*filter);
2807 Mlt::Filter *filter;
2809 filter = new Mlt::Filter(*m_mltProfile, filterTag);
2810 if (filter && filter->is_valid()) {
2811 filter->set("kdenlive_id", filterId);
2813 kDebug() << "filter is NULL";
2817 params.removeParam("kdenlive_id");
2818 if (params.hasParam("_sync_in_out")) {
2819 // This effect must sync in / out with parent clip
2820 params.removeParam("_sync_in_out");
2821 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2824 for (int j = 0; j < params.count(); j++) {
2825 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2829 QString effectArgs = params.paramValue("id").section('_', 1);
2831 params.removeParam("id");
2832 params.removeParam("kdenlive_ix");
2833 params.removeParam("tag");
2834 params.removeParam("disable");
2835 params.removeParam("region");
2837 for (int j = 0; j < params.count(); j++) {
2838 effectArgs.append(' ' + params.at(j).value());
2840 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2841 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2843 // attach filter to the clip
2844 service.attach(*filter);
2852 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2854 Mlt::Service service(m_mltProducer->parent().get_service());
2855 Mlt::Tractor tractor(service);
2856 Mlt::Producer trackProducer(tractor.track(track));
2857 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2858 Mlt::Service clipService(trackPlaylist.get_service());
2860 QString index = params.paramValue("kdenlive_ix");
2861 QString tag = params.paramValue("tag");
2863 Mlt::Filter *filter = clipService.filter(ct);
2865 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2869 filter = clipService.filter(ct);
2873 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2874 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2876 bool success = false;//mltAddTrackEffect(track, params);
2880 QString ser = filter->get("mlt_service");
2881 if (ser == "region") prefix = "filter0.";
2883 for (int j = 0; j < params.count(); j++) {
2884 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2892 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2894 int index = params.paramValue("kdenlive_ix").toInt();
2895 QString tag = params.paramValue("tag");
2897 if (!params.paramValue("keyframes").isEmpty() || (tag == "affine" && params.hasParam("background")) || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2898 // This is a keyframe effect, to edit it, we remove it and re-add it.
2899 bool success = mltRemoveEffect(track, position, index, false);
2900 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
2901 if (position < GenTime())
2902 success = mltAddTrackEffect(track, params);
2904 success = mltAddEffect(track, position, params);
2905 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
2908 if (position < GenTime()) {
2909 return mltEditTrackEffect(track, params);
2912 Mlt::Service service(m_mltProducer->parent().get_service());
2913 Mlt::Tractor tractor(service);
2914 Mlt::Producer trackProducer(tractor.track(track));
2915 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2917 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2918 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2920 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2924 int duration = clip->get_playtime();
2925 bool doRefresh = true;
2926 // Check if clip is visible in monitor
2927 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2928 if (diff < 0 || diff > duration)
2932 Mlt::Filter *filter = clip->filter(ct);
2934 if (filter->get_int("kdenlive_ix") == index) {
2938 filter = clip->filter(ct);
2942 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2943 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2945 bool success = mltAddEffect(track, position, params);
2949 QString ser = filter->get("mlt_service");
2950 QList <Mlt::Filter *> filtersList;
2953 // Effect service changes, delete effect and re-add it
2954 clip->detach(*filter);
2956 // Delete all effects after deleted one
2957 filter = clip->filter(ct);
2959 if (filter->get_int("kdenlive_ix") > index) {
2960 filtersList.append(filter);
2961 clip->detach(*filter);
2964 filter = clip->filter(ct);
2968 addFilterToService(*clip, params, clip->get_playtime());
2972 if (doRefresh) refresh();
2975 if (params.hasParam("_sync_in_out")) {
2976 // This effect must sync in / out with parent clip
2977 params.removeParam("_sync_in_out");
2978 filter->set_in_and_out(clip->get_in(), clip->get_out());
2981 for (int j = 0; j < params.count(); j++) {
2982 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2985 for (int j = 0; j < filtersList.count(); j++) {
2986 clip->attach(*(filtersList.at(j)));
2992 if (doRefresh) refresh();
2996 bool Render::mltEnableEffects(int track, GenTime position, QList <int> effectIndexes, bool disable)
2998 if (position < GenTime()) {
2999 return mltEnableTrackEffects(track, effectIndexes, disable);
3002 Mlt::Service service(m_mltProducer->parent().get_service());
3003 Mlt::Tractor tractor(service);
3004 Mlt::Producer trackProducer(tractor.track(track));
3005 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3007 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3008 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3010 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3014 int duration = clip->get_playtime();
3015 bool doRefresh = true;
3016 // Check if clip is visible in monitor
3017 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3018 if (diff < 0 || diff > duration)
3022 Mlt::Filter *filter = clip->filter(ct);
3024 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3025 filter->set("disable", (int) disable);
3028 filter = clip->filter(ct);
3034 if (doRefresh) refresh();
3038 bool Render::mltEnableTrackEffects(int track, QList <int> effectIndexes, bool disable)
3040 Mlt::Service service(m_mltProducer->parent().get_service());
3041 Mlt::Tractor tractor(service);
3042 Mlt::Producer trackProducer(tractor.track(track));
3043 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3044 Mlt::Service clipService(trackPlaylist.get_service());
3047 Mlt::Filter *filter = clipService.filter(ct);
3049 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3050 filter->set("disable", (int) disable);
3053 filter = clipService.filter(ct);
3061 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
3063 Mlt::Service service(m_mltProducer->parent().get_service());
3064 Mlt::Tractor tractor(service);
3065 Mlt::Producer trackProducer(tractor.track(track));
3066 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3068 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3069 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3071 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3075 Mlt::Service clipService(clip->get_service());
3076 int duration = clip->get_playtime();
3077 bool doRefresh = true;
3078 // Check if clip is visible in monitor
3079 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3080 if (diff < 0 || diff > duration) doRefresh = false;
3084 Mlt::Filter *filter = clipService.filter(ct);
3086 int pos = filter->get_int("kdenlive_ix");
3087 if (pos == oldPos) {
3088 filter->set("kdenlive_ix", newPos);
3090 filter = clipService.filter(ct);
3092 if (doRefresh) refresh();
3095 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
3097 if (position < GenTime()) {
3098 mltMoveTrackEffect(track, oldPos, newPos);
3101 Mlt::Service service(m_mltProducer->parent().get_service());
3102 Mlt::Tractor tractor(service);
3103 Mlt::Producer trackProducer(tractor.track(track));
3104 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3106 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3107 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3109 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3113 Mlt::Service clipService(clip->get_service());
3114 int duration = clip->get_playtime();
3115 bool doRefresh = true;
3116 // Check if clip is visible in monitor
3117 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3118 if (diff < 0 || diff > duration) doRefresh = false;
3122 QList <Mlt::Filter *> filtersList;
3123 Mlt::Filter *filter = clipService.filter(ct);
3125 if (newPos > oldPos) {
3127 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3128 filter->set("kdenlive_ix", newPos);
3129 filtersList.append(filter);
3130 clipService.detach(*filter);
3131 filter = clipService.filter(ct);
3132 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3133 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3135 filter = clipService.filter(ct);
3139 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3140 filtersList.append(filter);
3141 clipService.detach(*filter);
3143 filter = clipService.filter(ct);
3147 if (filter->get_int("kdenlive_ix") == oldPos) {
3148 filter->set("kdenlive_ix", newPos);
3149 filtersList.append(filter);
3150 clipService.detach(*filter);
3152 filter = clipService.filter(ct);
3156 filter = clipService.filter(ct);
3158 int pos = filter->get_int("kdenlive_ix");
3159 if (pos >= newPos) {
3160 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3161 filtersList.append(filter);
3162 clipService.detach(*filter);
3164 filter = clipService.filter(ct);
3168 for (int i = 0; i < filtersList.count(); i++) {
3169 clipService.attach(*(filtersList.at(i)));
3172 if (doRefresh) refresh();
3175 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
3177 Mlt::Service service(m_mltProducer->parent().get_service());
3178 Mlt::Tractor tractor(service);
3179 Mlt::Producer trackProducer(tractor.track(track));
3180 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3181 Mlt::Service clipService(trackPlaylist.get_service());
3183 QList <Mlt::Filter *> filtersList;
3184 Mlt::Filter *filter = clipService.filter(ct);
3186 if (newPos > oldPos) {
3188 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3189 filter->set("kdenlive_ix", newPos);
3190 filtersList.append(filter);
3191 clipService.detach(*filter);
3192 filter = clipService.filter(ct);
3193 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3194 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3196 filter = clipService.filter(ct);
3200 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3201 filtersList.append(filter);
3202 clipService.detach(*filter);
3204 filter = clipService.filter(ct);
3208 if (filter->get_int("kdenlive_ix") == oldPos) {
3209 filter->set("kdenlive_ix", newPos);
3210 filtersList.append(filter);
3211 clipService.detach(*filter);
3213 filter = clipService.filter(ct);
3217 filter = clipService.filter(ct);
3219 int pos = filter->get_int("kdenlive_ix");
3220 if (pos >= newPos) {
3221 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3222 filtersList.append(filter);
3223 clipService.detach(*filter);
3225 filter = clipService.filter(ct);
3229 for (int i = 0; i < filtersList.count(); i++) {
3230 clipService.attach(*(filtersList.at(i)));
3235 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
3237 Mlt::Service service(m_mltProducer->parent().get_service());
3238 Mlt::Tractor tractor(service);
3239 Mlt::Producer trackProducer(tractor.track(info.track));
3240 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3242 /* // Display playlist info
3243 kDebug()<<"//////////// BEFORE RESIZE";
3244 for (int i = 0; i < trackPlaylist.count(); i++) {
3245 int blankStart = trackPlaylist.clip_start(i);
3246 int blankDuration = trackPlaylist.clip_length(i) - 1;
3248 if (trackPlaylist.is_blank(i)) blk = "(blank)";
3249 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
3252 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
3253 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3257 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
3258 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
3259 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3261 int previousStart = clip->get_in();
3262 int newDuration = (int) clipDuration.frames(m_fps) - 1;
3263 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
3265 int currentOut = newDuration + previousStart;
3266 if (currentOut > clip->get_length()) {
3267 clip->parent().set("length", currentOut + 1);
3268 clip->parent().set("out", currentOut);
3269 clip->set("length", currentOut + 1);
3272 /*if (newDuration > clip->get_out()) {
3273 clip->parent().set_in_and_out(0, newDuration + 1);
3274 clip->set_in_and_out(0, newDuration + 1);
3277 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
3278 trackPlaylist.consolidate_blanks(0);
3279 // skip to next clip
3281 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
3283 // clip was made longer, trim next blank if there is one.
3284 if (clipIndex < trackPlaylist.count()) {
3285 // If this is not the last clip in playlist
3286 if (trackPlaylist.is_blank(clipIndex)) {
3287 int blankStart = trackPlaylist.clip_start(clipIndex);
3288 int blankDuration = trackPlaylist.clip_length(clipIndex);
3289 if (diff > blankDuration) {
3290 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
3292 if (diff - blankDuration == 0) {
3293 trackPlaylist.remove(clipIndex);
3294 } else trackPlaylist.remove_region(blankStart, diff);
3296 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
3299 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
3300 trackPlaylist.consolidate_blanks(0);
3303 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
3304 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3305 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
3306 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3307 ItemInfo transpinfo;
3308 transpinfo.startPos = info.startPos;
3309 transpinfo.endPos = info.startPos + clipDuration;
3310 transpinfo.track = info.track;
3311 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3313 m_mltConsumer->set("refresh", 1);
3317 void Render::mltChangeTrackState(int track, bool mute, bool blind)
3319 Mlt::Service service(m_mltProducer->parent().get_service());
3320 Mlt::Tractor tractor(service);
3321 Mlt::Producer trackProducer(tractor.track(track));
3323 // Make sure muting will not produce problems with our audio mixing transition,
3324 // because audio mixing is done between each track and the lowest one
3325 bool audioMixingBroken = false;
3326 if (mute && trackProducer.get_int("hide") < 2 ) {
3327 // We mute a track with sound
3328 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3329 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
3331 else if (!mute && trackProducer.get_int("hide") > 1 ) {
3332 // We un-mute a previously muted track
3333 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3337 if (blind) trackProducer.set("hide", 3);
3338 else trackProducer.set("hide", 2);
3340 trackProducer.set("hide", 1);
3342 trackProducer.set("hide", 0);
3344 if (audioMixingBroken) fixAudioMixing(tractor);
3346 tractor.multitrack()->refresh();
3351 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
3353 for (int i = 1; i < tractor.count(); i++) {
3354 Mlt::Producer trackProducer(tractor.track(i));
3355 if (trackProducer.get_int("hide") < 2) return i;
3357 return tractor.count() - 1;
3360 void Render::fixAudioMixing(Mlt::Tractor tractor)
3362 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
3363 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
3365 mlt_service serv = m_mltProducer->parent().get_service();
3366 Mlt::Field *field = tractor.field();
3367 mlt_service_lock(serv);
3369 mlt_service nextservice = mlt_service_get_producer(serv);
3370 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3371 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3372 QString resource = mlt_properties_get(properties, "mlt_service");
3374 mlt_service nextservicetodisconnect;
3375 // Delete all audio mixing transitions
3376 while (mlt_type == "transition") {
3377 if (resource == "mix") {
3378 nextservicetodisconnect = nextservice;
3379 nextservice = mlt_service_producer(nextservice);
3380 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
3382 else nextservice = mlt_service_producer(nextservice);
3383 if (nextservice == NULL) break;
3384 properties = MLT_SERVICE_PROPERTIES(nextservice);
3385 mlt_type = mlt_properties_get(properties, "mlt_type");
3386 resource = mlt_properties_get(properties, "mlt_service");
3389 // Re-add correct audio transitions
3390 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
3391 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3392 transition->set("always_active", 1);
3393 transition->set("combine", 1);
3394 transition->set("internal_added", 237);
3395 field->plant_transition(*transition, lowestTrack, i);
3397 mlt_service_unlock(serv);
3400 bool Render::mltResizeClipCrop(ItemInfo info, GenTime newCropStart)
3402 Mlt::Service service(m_mltProducer->parent().get_service());
3403 int newCropFrame = (int) newCropStart.frames(m_fps);
3404 Mlt::Tractor tractor(service);
3405 Mlt::Producer trackProducer(tractor.track(info.track));
3406 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3407 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3408 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3412 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3413 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3415 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3419 int previousStart = clip->get_in();
3420 int previousOut = clip->get_out();
3422 if (previousStart == newCropFrame) {
3423 kDebug() << "//////// No ReSIZING Required";
3427 int frameOffset = newCropFrame - previousStart;
3428 trackPlaylist.resize_clip(clipIndex, newCropFrame, previousOut + frameOffset);
3430 m_mltConsumer->set("refresh", 1);
3434 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3436 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3437 Mlt::Service service(m_mltProducer->parent().get_service());
3438 int moveFrame = (int) diff.frames(m_fps);
3439 Mlt::Tractor tractor(service);
3440 Mlt::Producer trackProducer(tractor.track(info.track));
3441 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3442 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3443 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3447 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3448 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3449 if (clip == NULL || clip->is_blank()) {
3450 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3454 int previousStart = clip->get_in();
3455 int previousOut = clip->get_out();
3457 previousStart += moveFrame;
3459 if (previousStart < 0) {
3460 // this is possible for images and color clips
3461 previousOut -= previousStart;
3465 int length = previousOut + 1;
3466 if (length > clip->get_length()) {
3467 clip->parent().set("length", length + 1);
3468 clip->parent().set("out", length);
3469 clip->set("length", length + 1);
3473 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3474 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3475 if (moveFrame > 0) {
3476 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3478 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3479 int blankIndex = clipIndex - 1;
3480 int blankLength = trackPlaylist.clip_length(blankIndex);
3481 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3482 if (! trackPlaylist.is_blank(blankIndex)) {
3483 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3485 if (blankLength + moveFrame == 0)
3486 trackPlaylist.remove(blankIndex);
3488 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3490 trackPlaylist.consolidate_blanks(0);
3491 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3492 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3493 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3494 ItemInfo transpinfo;
3495 transpinfo.startPos = info.startPos + diff;
3496 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3497 transpinfo.track = info.track;
3498 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3500 //m_mltConsumer->set("refresh", 1);
3502 m_mltConsumer->set("refresh", 1);
3506 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3508 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3512 bool Render::mltUpdateClipProducer(Mlt::Tractor *tractor, int track, int pos, Mlt::Producer *prod)
3514 if (prod == NULL || !prod->is_valid() || tractor == NULL || !tractor->is_valid()) {
3515 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3519 Mlt::Producer trackProducer(tractor->track(track));
3520 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3521 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3522 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3523 if (clipProducer == NULL || clipProducer->is_blank()) {
3524 kDebug() << "// ERROR UPDATING CLIP PROD";
3525 delete clipProducer;
3528 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3529 if (!clip || !clip->is_valid()) {
3530 if (clip) delete clip;
3531 delete clipProducer;
3534 // move all effects to the correct producer
3535 mltPasteEffects(clipProducer, clip);
3536 trackPlaylist.insert_at(pos, clip, 1);
3538 delete clipProducer;
3542 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3544 Mlt::Service service(m_mltProducer->parent().get_service());
3545 if (service.type() != tractor_type) {
3546 kWarning() << "// TRACTOR PROBLEM";
3550 Mlt::Tractor tractor(service);
3552 Mlt::Producer trackProducer(tractor.track(startTrack));
3553 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3554 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3555 int clipDuration = trackPlaylist.clip_length(clipIndex);
3556 bool checkLength = false;
3557 if (endTrack == startTrack) {
3558 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3560 bool success = true;
3561 if (!trackPlaylist.is_blank_at(moveEnd) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3565 // Check that the destination region is empty
3566 trackPlaylist.consolidate_blanks(0);
3567 int destinationIndex = trackPlaylist.get_clip_index_at(moveEnd);
3568 if (destinationIndex < trackPlaylist.count() - 1) {
3569 // We are not at the end of the track
3570 int blankSize = trackPlaylist.blanks_from(destinationIndex, 1);
3571 // Make sure we have enough place to insert clip
3572 if (blankSize - clipDuration - (moveEnd - trackPlaylist.clip_start(destinationIndex)) < 0) success = false;
3577 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3578 delete clipProducer;
3580 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3587 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3588 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3589 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3591 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3592 if (newIndex == -1) {
3593 kDebug()<<"// CANNOT MOVE CLIP TO: "<<moveEnd;
3594 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3595 delete clipProducer;
3599 trackPlaylist.consolidate_blanks(1);
3600 delete clipProducer;
3601 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3603 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3604 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3605 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3606 // error, destination is not empty
3607 kDebug() << "Cannot move: Destination is not empty";
3611 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3612 if (!clipProducer || clipProducer->is_blank()) {
3613 // error, destination is not empty
3614 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3615 if (clipProducer) delete clipProducer;
3616 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3620 trackPlaylist.consolidate_blanks(0);
3621 destTrackPlaylist.consolidate_blanks(1);
3622 Mlt::Producer *clip;
3623 // check if we are moving a slowmotion producer
3624 QString serv = clipProducer->parent().get("mlt_service");
3625 QString currentid = clipProducer->parent().get("id");
3626 if (serv == "framebuffer") {
3627 clip = clipProducer;
3630 // Special case: prod is null when using placeholder clips.
3631 // in that case, use the producer existing in playlist. Note that
3632 // it will bypass the one producer per track logic and might cause
3633 // Sound cracks if clip is moved so that it overlaps another copy of itself
3634 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3635 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3638 // move all effects to the correct producer
3639 mltPasteEffects(clipProducer, clip);
3642 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3643 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3644 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3647 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3649 if (clip == clipProducer) {
3654 delete clipProducer;
3656 destTrackPlaylist.consolidate_blanks(0);
3657 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3658 kDebug() << "//////// moving clip transparency";
3659 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3661 if (clipIndex > trackPlaylist.count()) checkLength = true;
3662 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3666 if (checkLength) mltCheckLength(&tractor);
3668 //m_mltConsumer->set("refresh", 1);
3673 QList <int> Render::checkTrackSequence(int track)
3676 Mlt::Service service(m_mltProducer->parent().get_service());
3677 if (service.type() != tractor_type) {
3678 kWarning() << "// TRACTOR PROBLEM";
3681 Mlt::Tractor tractor(service);
3683 Mlt::Producer trackProducer(tractor.track(track));
3684 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3685 int clipNb = trackPlaylist.count();
3686 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3687 for (int i = 0; i < clipNb; i++) {
3688 Mlt::Producer *c = trackPlaylist.get_clip(i);
3689 int pos = trackPlaylist.clip_start(i);
3690 if (!list.contains(pos)) list.append(pos);
3691 pos += c->get_playtime();
3692 if (!list.contains(pos)) list.append(pos);
3698 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3700 int new_in = (int)newIn.frames(m_fps);
3701 int new_out = (int)newOut.frames(m_fps) - 1;
3702 if (new_in >= new_out) return false;
3703 int old_in = (int)oldIn.frames(m_fps);
3704 int old_out = (int)oldOut.frames(m_fps) - 1;
3706 Mlt::Service service(m_mltProducer->parent().get_service());
3707 Mlt::Tractor tractor(service);
3708 Mlt::Field *field = tractor.field();
3710 bool doRefresh = true;
3711 // Check if clip is visible in monitor
3712 int diff = old_out - m_mltProducer->position();
3713 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3715 diff = new_out - m_mltProducer->position();
3716 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3720 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3721 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3722 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3723 QString resource = mlt_properties_get(properties, "mlt_service");
3724 int old_pos = (int)(old_in + old_out) / 2;
3727 while (mlt_type == "transition") {
3728 Mlt::Transition transition((mlt_transition) nextservice);
3729 nextservice = mlt_service_producer(nextservice);
3730 int currentTrack = transition.get_b_track();
3731 int currentIn = (int) transition.get_in();
3732 int currentOut = (int) transition.get_out();
3734 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3736 if (newTrack - startTrack != 0) {
3737 Mlt::Properties trans_props(transition.get_properties());
3738 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3739 Mlt::Properties new_trans_props(new_transition.get_properties());
3740 new_trans_props.inherit(trans_props);
3741 new_transition.set_in_and_out(new_in, new_out);
3742 field->disconnect_service(transition);
3743 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3744 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3745 } else transition.set_in_and_out(new_in, new_out);
3748 if (nextservice == NULL) break;
3749 properties = MLT_SERVICE_PROPERTIES(nextservice);
3750 mlt_type = mlt_properties_get(properties, "mlt_type");
3751 resource = mlt_properties_get(properties, "mlt_service");
3754 if (doRefresh) refresh();
3755 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3760 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3762 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3763 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3764 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3765 QString resource = mlt_properties_get(properties, "mlt_service");
3766 QList <Mlt::Transition *> trList;
3767 mlt_properties insertproperties = tr.get_properties();
3768 QString insertresource = mlt_properties_get(insertproperties, "mlt_service");
3769 bool isMixTransition = insertresource == "mix";
3771 while (mlt_type == "transition") {
3772 Mlt::Transition transition((mlt_transition) nextservice);
3773 nextservice = mlt_service_producer(nextservice);
3774 int aTrack = transition.get_a_track();
3775 int bTrack = transition.get_b_track();
3776 if ((isMixTransition || resource != "mix") && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3777 Mlt::Properties trans_props(transition.get_properties());
3778 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3779 Mlt::Properties new_trans_props(cp->get_properties());
3780 new_trans_props.inherit(trans_props);
3782 field->disconnect_service(transition);
3784 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3786 if (nextservice == NULL) break;
3787 properties = MLT_SERVICE_PROPERTIES(nextservice);
3788 mlt_type = mlt_properties_get(properties, "mlt_type");
3789 resource = mlt_properties_get(properties, "mlt_service");
3791 field->plant_transition(tr, a_track, b_track);
3793 // re-add upper transitions
3794 for (int i = trList.count() - 1; i >= 0; i--) {
3795 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3796 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3801 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3803 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3805 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3806 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3807 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3810 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3813 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3815 mlt_service serv = m_mltProducer->parent().get_service();
3816 mlt_service_lock(serv);
3818 mlt_service nextservice = mlt_service_get_producer(serv);
3819 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3820 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3821 QString resource = mlt_properties_get(properties, "mlt_service");
3822 int in_pos = (int) in.frames(m_fps);
3823 int out_pos = (int) out.frames(m_fps) - 1;
3825 while (mlt_type == "transition") {
3826 mlt_transition tr = (mlt_transition) nextservice;
3827 int currentTrack = mlt_transition_get_b_track(tr);
3828 int currentBTrack = mlt_transition_get_a_track(tr);
3829 int currentIn = (int) mlt_transition_get_in(tr);
3830 int currentOut = (int) mlt_transition_get_out(tr);
3832 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3833 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3834 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3835 QMap<QString, QString>::Iterator it;
3837 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3839 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3840 if (currentId != xml.attribute("id")) {
3841 // The transition ID is not the same, so reset all properties
3842 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3843 // Cleanup previous properties
3844 QStringList permanentProps;
3845 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3846 permanentProps << "out" << "a_track" << "b_track";
3847 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3848 QString propName = mlt_properties_get_name(transproperties, i);
3849 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3850 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3855 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3856 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3858 if (currentBTrack != a_track) {
3859 mlt_properties_set_int(transproperties, "a_track", a_track);
3861 for (it = map.begin(); it != map.end(); ++it) {
3863 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3864 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3865 //filter->set("kdenlive_id", id);
3869 nextservice = mlt_service_producer(nextservice);
3870 if (nextservice == NULL) break;
3871 properties = MLT_SERVICE_PROPERTIES(nextservice);
3872 mlt_type = mlt_properties_get(properties, "mlt_type");
3873 resource = mlt_properties_get(properties, "mlt_service");
3875 mlt_service_unlock(serv);
3877 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3880 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3882 mlt_service serv = m_mltProducer->parent().get_service();
3883 mlt_service_lock(serv);
3885 Mlt::Service service(serv);
3886 Mlt::Tractor tractor(service);
3887 Mlt::Field *field = tractor.field();
3889 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3891 mlt_service nextservice = mlt_service_get_producer(serv);
3892 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3893 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3894 QString resource = mlt_properties_get(properties, "mlt_service");
3896 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3897 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3899 while (mlt_type == "transition") {
3900 mlt_transition tr = (mlt_transition) nextservice;
3901 int currentTrack = mlt_transition_get_b_track(tr);
3902 int currentIn = (int) mlt_transition_get_in(tr);
3903 int currentOut = (int) mlt_transition_get_out(tr);
3904 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3906 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3907 mlt_field_disconnect_service(field->get_field(), nextservice);
3910 nextservice = mlt_service_producer(nextservice);
3911 if (nextservice == NULL) break;
3912 properties = MLT_SERVICE_PROPERTIES(nextservice);
3913 mlt_type = mlt_properties_get(properties, "mlt_type");
3914 resource = mlt_properties_get(properties, "mlt_service");
3916 mlt_service_unlock(serv);
3918 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3921 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3923 QDomNodeList attribs = xml.elementsByTagName("parameter");
3924 QMap<QString, QString> map;
3925 for (int i = 0; i < attribs.count(); i++) {
3926 QDomElement e = attribs.item(i).toElement();
3927 QString name = e.attribute("name");
3928 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3929 map[name] = e.attribute("default");
3930 if (!e.attribute("value").isEmpty()) {
3931 map[name] = e.attribute("value");
3933 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
3934 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
3935 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3938 if (e.attribute("namedesc").contains(';')) {
3939 QString format = e.attribute("format");
3940 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3941 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3943 QTextStream txtNeu(&neu);
3944 if (values.size() > 0)
3945 txtNeu << (int)values[0].toDouble();
3947 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3948 txtNeu << separators[i];
3949 txtNeu << (int)(values[i+1].toDouble());
3951 if (i < separators.size())
3952 txtNeu << separators[i];
3953 map[e.attribute("name")] = neu;
3960 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3962 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3963 Mlt::Service service(m_mltProducer->parent().get_service());
3964 Mlt::Tractor tractor(service);
3965 Mlt::Field *field = tractor.field();
3967 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3968 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3969 transition->set("transparency", id);
3970 transition->set("fill", 1);
3971 transition->set("internal_added", 237);
3972 field->plant_transition(*transition, transitiontrack, info.track);
3976 void Render::mltDeleteTransparency(int pos, int track, int id)
3978 Mlt::Service service(m_mltProducer->parent().get_service());
3979 Mlt::Tractor tractor(service);
3980 Mlt::Field *field = tractor.field();
3982 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3983 mlt_service serv = m_mltProducer->parent().get_service();
3985 mlt_service nextservice = mlt_service_get_producer(serv);
3986 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3987 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3988 QString resource = mlt_properties_get(properties, "mlt_service");
3990 while (mlt_type == "transition") {
3991 mlt_transition tr = (mlt_transition) nextservice;
3992 int currentTrack = mlt_transition_get_b_track(tr);
3993 int currentIn = (int) mlt_transition_get_in(tr);
3994 int currentOut = (int) mlt_transition_get_out(tr);
3995 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3996 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3998 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3999 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
4000 mlt_field_disconnect_service(field->get_field(), nextservice);
4003 nextservice = mlt_service_producer(nextservice);
4004 if (nextservice == NULL) break;
4005 properties = MLT_SERVICE_PROPERTIES(nextservice);
4006 mlt_type = mlt_properties_get(properties, "mlt_type");
4007 resource = mlt_properties_get(properties, "mlt_service");
4009 //if (do_refresh) m_mltConsumer->set("refresh", 1);
4012 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
4014 Mlt::Service service(m_mltProducer->parent().get_service());
4015 Mlt::Tractor tractor(service);
4018 m_mltConsumer->set("refresh", 0);
4020 mlt_service serv = m_mltProducer->parent().get_service();
4021 mlt_service nextservice = mlt_service_get_producer(serv);
4022 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4023 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4024 QString resource = mlt_properties_get(properties, "mlt_service");
4025 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
4026 while (mlt_type == "transition") {
4027 mlt_transition tr = (mlt_transition) nextservice;
4028 int currentTrack = mlt_transition_get_b_track(tr);
4029 int currentIn = (int) mlt_transition_get_in(tr);
4030 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
4031 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4032 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
4033 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
4034 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
4035 mlt_transition_set_in_and_out(tr, newStart, newEnd);
4038 nextservice = mlt_service_producer(nextservice);
4039 if (nextservice == NULL) break;
4040 properties = MLT_SERVICE_PROPERTIES(nextservice);
4041 mlt_type = mlt_properties_get(properties, "mlt_type");
4042 resource = mlt_properties_get(properties, "mlt_service");
4045 m_mltConsumer->set("refresh", 1);
4049 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
4051 Mlt::Service service(m_mltProducer->parent().get_service());
4052 Mlt::Tractor tractor(service);
4055 m_mltConsumer->set("refresh", 0);
4057 mlt_service serv = m_mltProducer->parent().get_service();
4058 mlt_service nextservice = mlt_service_get_producer(serv);
4059 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4060 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4061 QString resource = mlt_properties_get(properties, "mlt_service");
4063 while (mlt_type == "transition") {
4064 mlt_transition tr = (mlt_transition) nextservice;
4065 int currentTrack = mlt_transition_get_b_track(tr);
4066 int currentaTrack = mlt_transition_get_a_track(tr);
4067 int currentIn = (int) mlt_transition_get_in(tr);
4068 int currentOut = (int) mlt_transition_get_out(tr);
4069 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4070 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4071 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
4072 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
4073 kDebug() << "//////MOVING";
4074 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
4075 if (endTrack != startTrack) {
4076 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4077 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
4078 mlt_properties_set_int(properties, "b_track", endTrack);
4082 nextservice = mlt_service_producer(nextservice);
4083 if (nextservice == NULL) break;
4084 properties = MLT_SERVICE_PROPERTIES(nextservice);
4085 mlt_type = mlt_properties_get(properties, "mlt_type");
4086 resource = mlt_properties_get(properties, "mlt_service");
4089 m_mltConsumer->set("refresh", 1);
4093 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
4095 if (in >= out) return false;
4096 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
4097 Mlt::Service service(m_mltProducer->parent().get_service());
4099 Mlt::Tractor tractor(service);
4100 Mlt::Field *field = tractor.field();
4102 Mlt::Transition transition(*m_mltProfile, tag.toUtf8().constData());
4103 if (out != GenTime())
4104 transition.set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
4106 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
4107 QMap<QString, QString>::Iterator it;
4109 if (xml.attribute("automatic") == "1") transition.set("automatic", 1);
4110 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
4111 if (xml.hasAttribute("id"))
4112 transition.set("kdenlive_id", xml.attribute("id").toUtf8().constData());
4113 if (xml.hasAttribute("force_track"))
4114 transition.set("force_track", xml.attribute("force_track").toInt());
4116 for (it = args.begin(); it != args.end(); ++it) {
4118 if (!it.value().isEmpty())
4119 transition.set(key.toUtf8().constData(), it.value().toUtf8().constData());
4120 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
4122 // attach transition
4124 mltPlantTransition(field, transition, a_track, b_track);
4125 // field->plant_transition(*transition, a_track, b_track);
4127 if (do_refresh) refresh();
4131 void Render::mltSavePlaylist()
4133 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
4134 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
4135 fileConsumer.set("resource", "/tmp/playlist.mlt");
4137 Mlt::Service service(m_mltProducer->get_service());
4139 fileConsumer.connect(service);
4140 fileConsumer.start();
4143 const QList <Mlt::Producer *> Render::producersList()
4145 QList <Mlt::Producer *> prods;
4146 if (m_mltProducer == NULL) return prods;
4147 Mlt::Service service(m_mltProducer->parent().get_service());
4148 if (service.type() != tractor_type) return prods;
4149 Mlt::Tractor tractor(service);
4152 int trackNb = tractor.count();
4153 for (int t = 1; t < trackNb; t++) {
4154 Mlt::Producer *tt = tractor.track(t);
4155 Mlt::Producer trackProducer(tt);
4157 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4158 if (!trackPlaylist.is_valid()) continue;
4159 int clipNb = trackPlaylist.count();
4160 for (int i = 0; i < clipNb; i++) {
4161 Mlt::Producer *c = trackPlaylist.get_clip(i);
4162 if (c == NULL) continue;
4163 QString prodId = c->parent().get("id");
4164 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
4165 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4168 prods.append(nprod);
4177 void Render::fillSlowMotionProducers()
4179 if (m_mltProducer == NULL) return;
4180 Mlt::Service service(m_mltProducer->parent().get_service());
4181 if (service.type() != tractor_type) return;
4183 Mlt::Tractor tractor(service);
4185 int trackNb = tractor.count();
4186 for (int t = 1; t < trackNb; t++) {
4187 Mlt::Producer *tt = tractor.track(t);
4188 Mlt::Producer trackProducer(tt);
4190 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4191 if (!trackPlaylist.is_valid()) continue;
4192 int clipNb = trackPlaylist.count();
4193 for (int i = 0; i < clipNb; i++) {
4194 Mlt::Producer *c = trackPlaylist.get_clip(i);
4195 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4197 QString id = nprod->parent().get("id");
4198 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
4199 // this is a slowmotion producer, add it to the list
4200 QString url = QString::fromUtf8(nprod->get("resource"));
4201 int strobe = nprod->get_int("strobe");
4202 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
4203 if (!m_slowmotionProducers.contains(url)) {
4204 m_slowmotionProducers.insert(url, nprod);
4206 } else delete nprod;
4213 QList <TransitionInfo> Render::mltInsertTrack(int ix, bool videoTrack)
4215 Mlt::Service service(m_mltProducer->parent().get_service());
4216 if (service.type() != tractor_type) {
4217 kWarning() << "// TRACTOR PROBLEM";
4218 return QList <TransitionInfo> ();
4222 Mlt::Tractor tractor(service);
4223 QList <TransitionInfo> transitionInfos;
4224 Mlt::Playlist playlist;
4225 int ct = tractor.count();
4227 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
4233 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
4234 tractor.set_track(playlist, pos);
4235 Mlt::Producer newProd(tractor.track(pos));
4236 if (!videoTrack) newProd.set("hide", 1);
4238 for (; pos <= ct; pos++) {
4239 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
4240 tractor.set_track(*prodToMove, pos);
4241 prodToMove = prodToMove2;
4244 tractor.set_track(playlist, ix);
4245 Mlt::Producer newProd(tractor.track(ix));
4246 if (!videoTrack) newProd.set("hide", 1);
4251 mlt_service serv = m_mltProducer->parent().get_service();
4252 mlt_service nextservice = mlt_service_get_producer(serv);
4253 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4254 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4255 QString resource = mlt_properties_get(properties, "mlt_service");
4256 Mlt::Field *field = tractor.field();
4257 QList <Mlt::Transition *> trList;
4259 while (mlt_type == "transition") {
4260 if (resource != "mix") {
4261 Mlt::Transition transition((mlt_transition) nextservice);
4262 nextservice = mlt_service_producer(nextservice);
4263 int currentbTrack = transition.get_b_track();
4264 int currentaTrack = transition.get_a_track();
4265 bool trackChanged = false;
4266 bool forceTransitionTrack = false;
4267 if (currentbTrack >= ix) {
4268 if (currentbTrack == ix && currentaTrack < ix) forceTransitionTrack = true;
4270 trackChanged = true;
4272 if (currentaTrack >= ix) {
4274 trackChanged = true;
4276 kDebug()<<"// Newtrans: "<<currentaTrack<<"/"<<currentbTrack;
4278 // disconnect all transitions
4279 Mlt::Properties trans_props(transition.get_properties());
4280 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
4281 Mlt::Properties new_trans_props(cp->get_properties());
4282 new_trans_props.inherit(trans_props);
4285 // Transition track needs to be adjusted
4286 cp->set("a_track", currentaTrack);
4287 cp->set("b_track", currentbTrack);
4288 // Check if transition track was changed and needs to be forced
4289 if (forceTransitionTrack) cp->set("force_track", 1);
4290 TransitionInfo trInfo;
4291 trInfo.startPos = GenTime(transition.get_in(), m_fps);
4292 trInfo.a_track = currentaTrack;
4293 trInfo.b_track = currentbTrack;
4294 trInfo.forceTrack = cp->get_int("force_track");
4295 transitionInfos.append(trInfo);
4298 field->disconnect_service(transition);
4300 else nextservice = mlt_service_producer(nextservice);
4301 if (nextservice == NULL) break;
4302 properties = MLT_SERVICE_PROPERTIES(nextservice);
4303 mlt_type = mlt_properties_get(properties, "mlt_type");
4304 resource = mlt_properties_get(properties, "mlt_service");
4307 // Add audio mix transition to last track
4308 Mlt::Transition transition(*m_mltProfile, "mix");
4309 transition.set("a_track", 1);
4310 transition.set("b_track", ct);
4311 transition.set("always_active", 1);
4312 transition.set("internal_added", 237);
4313 transition.set("combine", 1);
4314 mltPlantTransition(field, transition, 1, ct);
4316 // re-add transitions
4317 for (int i = trList.count() - 1; i >= 0; i--) {
4318 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
4323 blockSignals(false);
4324 return transitionInfos;
4328 void Render::mltDeleteTrack(int ix)
4331 doc.setContent(sceneList(), false);
4332 int tracksCount = doc.elementsByTagName("track").count() - 1;
4333 QDomNode track = doc.elementsByTagName("track").at(ix);
4334 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
4335 QDomNodeList transitions = doc.elementsByTagName("transition");
4336 for (int i = 0; i < transitions.count(); i++) {
4337 QDomElement e = transitions.at(i).toElement();
4338 QDomNodeList props = e.elementsByTagName("property");
4339 QMap <QString, QString> mappedProps;
4340 for (int j = 0; j < props.count(); j++) {
4341 QDomElement f = props.at(j).toElement();
4342 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
4344 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
4345 tractor.removeChild(transitions.at(i));
4347 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
4348 // Transition needs to be moved
4349 int a_track = mappedProps.value("a_track").toInt();
4350 int b_track = mappedProps.value("b_track").toInt();
4351 if (a_track > 0 && a_track >= ix) a_track --;
4352 if (b_track == ix) {
4353 // transition was on the deleted track, so remove it
4354 tractor.removeChild(transitions.at(i));
4358 if (b_track > 0 && b_track > ix) b_track --;
4359 for (int j = 0; j < props.count(); j++) {
4360 QDomElement f = props.at(j).toElement();
4361 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
4362 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
4367 tractor.removeChild(track);
4368 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
4369 setSceneList(doc.toString(), m_mltConsumer->position());
4370 emit refreshDocumentProducers(false, false);
4374 void Render::updatePreviewSettings()
4376 kDebug() << "////// RESTARTING CONSUMER";
4377 if (!m_mltConsumer || !m_mltProducer) return;
4378 if (m_mltProducer->get_playtime() == 0) return;
4379 QMutexLocker locker(&m_mutex);
4380 Mlt::Service service(m_mltProducer->parent().get_service());
4381 if (service.type() != tractor_type) return;
4383 //m_mltConsumer->set("refresh", 0);
4384 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
4385 m_mltConsumer->purge();
4386 QString scene = sceneList();
4388 if (m_mltProducer) {
4389 pos = m_mltProducer->position();
4392 setSceneList(scene, pos);
4396 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
4398 // Update all frame positions to the new fps value
4399 //WARNING: there are probably some effects or other that hold a frame value
4400 // as parameter and will also need to be updated here!
4402 doc.setContent(scene);
4404 double factor = new_fps / current_fps;
4405 QDomNodeList producers = doc.elementsByTagName("producer");
4406 for (int i = 0; i < producers.count(); i++) {
4407 QDomElement prod = producers.at(i).toElement();
4408 prod.removeAttribute("in");
4409 prod.removeAttribute("out");
4411 QDomNodeList props = prod.childNodes();
4412 for (int j = 0; j < props.count(); j++) {
4413 QDomElement param = props.at(j).toElement();
4414 QString paramName = param.attribute("name");
4415 if (paramName.startsWith("meta.") || paramName == "length") {
4416 prod.removeChild(props.at(j));
4422 QDomNodeList entries = doc.elementsByTagName("entry");
4423 for (int i = 0; i < entries.count(); i++) {
4424 QDomElement entry = entries.at(i).toElement();
4425 int in = entry.attribute("in").toInt();
4426 int out = entry.attribute("out").toInt();
4427 in = factor * in + 0.5;
4428 out = factor * out + 0.5;
4429 entry.setAttribute("in", in);
4430 entry.setAttribute("out", out);
4433 QDomNodeList blanks = doc.elementsByTagName("blank");
4434 for (int i = 0; i < blanks.count(); i++) {
4435 QDomElement blank = blanks.at(i).toElement();
4436 int length = blank.attribute("length").toInt();
4437 length = factor * length + 0.5;
4438 blank.setAttribute("length", QString::number(length));
4441 QDomNodeList filters = doc.elementsByTagName("filter");
4442 for (int i = 0; i < filters.count(); i++) {
4443 QDomElement filter = filters.at(i).toElement();
4444 int in = filter.attribute("in").toInt();
4445 int out = filter.attribute("out").toInt();
4446 in = factor * in + 0.5;
4447 out = factor * out + 0.5;
4448 filter.setAttribute("in", in);
4449 filter.setAttribute("out", out);
4452 QDomNodeList transitions = doc.elementsByTagName("transition");
4453 for (int i = 0; i < transitions.count(); i++) {
4454 QDomElement transition = transitions.at(i).toElement();
4455 int in = transition.attribute("in").toInt();
4456 int out = transition.attribute("out").toInt();
4457 in = factor * in + 0.5;
4458 out = factor * out + 0.5;
4459 transition.setAttribute("in", in);
4460 transition.setAttribute("out", out);
4461 QDomNodeList props = transition.childNodes();
4462 for (int j = 0; j < props.count(); j++) {
4463 QDomElement param = props.at(j).toElement();
4464 QString paramName = param.attribute("name");
4465 if (paramName == "geometry") {
4466 QString geom = param.firstChild().nodeValue();
4467 QStringList keys = geom.split(';');
4468 QStringList newKeys;
4469 for (int k = 0; k < keys.size(); ++k) {
4470 if (keys.at(k).contains('=')) {
4471 int pos = keys.at(k).section('=', 0, 0).toInt();
4472 pos = factor * pos + 0.5;
4473 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4474 } else newKeys.append(keys.at(k));
4476 param.firstChild().setNodeValue(newKeys.join(";"));
4480 QDomElement root = doc.documentElement();
4481 if (!root.isNull()) {
4482 QDomElement tractor = root.firstChildElement("tractor");
4483 int out = tractor.attribute("out").toInt();
4484 out = factor * out + 0.5;
4485 tractor.setAttribute("out", out);
4486 emit durationChanged(out);
4489 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4490 return doc.toString();
4494 void Render::sendFrameUpdate()
4496 if (m_mltProducer) {
4497 Mlt::Frame * frame = m_mltProducer->get_frame();
4498 emitFrameUpdated(*frame);
4503 Mlt::Producer* Render::getProducer()
4505 return m_mltProducer;
4508 const QString Render::activeClipId()
4510 if (m_mltProducer) return m_mltProducer->get("id");
4515 bool Render::getBlackMagicDeviceList(KComboBox *devicelist)
4517 if (!KdenliveSettings::decklink_device_found()) return false;
4518 Mlt::Profile profile;
4519 Mlt::Producer bm(profile, "decklink");
4520 int found_devices = 0;
4521 if (bm.is_valid()) {
4522 bm.set("list_devices", 1);
4523 found_devices = bm.get_int("devices");
4525 else KdenliveSettings::setDecklink_device_found(false);
4526 if (found_devices <= 0) {
4527 devicelist->setEnabled(false);
4530 for (int i = 0; i < found_devices; i++) {
4531 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4532 devicelist->addItem(bm.get(tmp));
4538 bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist)
4540 if (!KdenliveSettings::decklink_device_found()) return false;
4541 Mlt::Profile profile;
4542 Mlt::Consumer bm(profile, "decklink");
4543 int found_devices = 0;
4544 if (bm.is_valid()) {
4545 bm.set("list_devices", 1);
4546 found_devices = bm.get_int("devices");
4548 else KdenliveSettings::setDecklink_device_found(false);
4549 if (found_devices <= 0) {
4550 devicelist->setEnabled(false);
4553 for (int i = 0; i < found_devices; i++) {
4554 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4555 devicelist->addItem(bm.get(tmp));
4561 void Render::slotMultiStreamProducerFound(const QString path, QList<int> audio_list, QList<int> video_list, stringMap data)
4563 if (KdenliveSettings::automultistreams()) {
4564 for (int i = 1; i < video_list.count(); i++) {
4565 int vindex = video_list.at(i);
4567 if (i <= audio_list.count() -1) {
4568 aindex = audio_list.at(i);
4570 data.insert("video_index", QString::number(vindex));
4571 data.insert("audio_index", QString::number(aindex));
4572 data.insert("bypassDuplicate", "1");
4573 emit addClip(KUrl(path), data);
4578 int width = 60.0 * m_mltProfile->dar();
4579 int swidth = 60.0 * m_mltProfile->width() / m_mltProfile->height();
4580 if (width % 2 == 1) width++;
4582 KDialog dialog(qApp->activeWindow());
4583 dialog.setCaption("Multi Stream Clip");
4584 dialog.setButtons(KDialog::Ok | KDialog::Cancel);
4585 dialog.setButtonText(KDialog::Ok, i18n("Import selected clips"));
4586 QWidget *content = new QWidget(&dialog);
4587 dialog.setMainWidget(content);
4588 QVBoxLayout *vbox = new QVBoxLayout(content);
4589 QLabel *lab1 = new QLabel(i18n("Additional streams for clip\n %1", path), content);
4590 vbox->addWidget(lab1);
4591 QList <QGroupBox*> groupList;
4592 QList <QComboBox*> comboList;
4593 // We start loading the list at 1, video index 0 should already be loaded
4594 for (int j = 1; j < video_list.count(); j++) {
4595 Mlt::Producer multiprod(* m_mltProfile, path.toUtf8().constData());
4596 multiprod.set("video_index", video_list.at(j));
4597 QImage thumb = KThumb::getFrame(&multiprod, 0, swidth, width, 60);
4598 QGroupBox *streamFrame = new QGroupBox(i18n("Video stream %1", video_list.at(j)), content);
4599 streamFrame->setProperty("vindex", video_list.at(j));
4600 groupList << streamFrame;
4601 streamFrame->setCheckable(true);
4602 streamFrame->setChecked(true);
4603 QVBoxLayout *vh = new QVBoxLayout( streamFrame );
4604 QLabel *iconLabel = new QLabel(content);
4605 iconLabel->setPixmap(QPixmap::fromImage(thumb));
4606 vh->addWidget(iconLabel);
4607 if (audio_list.count() > 1) {
4608 QComboBox *cb = new QComboBox(content);
4609 for (int k = 0; k < audio_list.count(); k++) {
4610 cb->addItem(i18n("Audio stream %1", audio_list.at(k)), audio_list.at(k));
4613 cb->setCurrentIndex(qMin(j, audio_list.count() - 1));
4616 vbox->addWidget(streamFrame);
4618 if (dialog.exec() == QDialog::Accepted) {
4619 // import selected streams
4620 for (int i = 0; i < groupList.count(); i++) {
4621 if (groupList.at(i)->isChecked()) {
4622 int vindex = groupList.at(i)->property("vindex").toInt();
4623 int aindex = comboList.at(i)->itemData(comboList.at(i)->currentIndex()).toInt();
4624 data.insert("video_index", QString::number(vindex));
4625 data.insert("audio_index", QString::number(aindex));
4626 data.insert("bypassDuplicate", "1");
4627 emit addClip(KUrl(path), data);
4633 #include "renderer.moc"