1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
30 #include "slideshowclip.h"
31 #include "profilesdialog.h"
34 #include "blackmagic/devices.h"
37 #include <mlt++/Mlt.h>
40 #include <KStandardDirs>
41 #include <KMessageBox>
43 #include <KTemporaryFile>
48 #include <QApplication>
49 #include <QtConcurrentRun>
56 #define SEEK_INACTIVE (-1)
58 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
60 // kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified();
61 if (level > MLT_LOG_ERROR) return;
63 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
68 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
70 // detect if the producer has finished playing. Is there a better way to do it?
71 self->emitFrameNumber();
72 Mlt::Frame frame(frame_ptr);
73 if (!frame.is_valid()) return;
74 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
75 self->emitFrameUpdated(frame);
77 if (self->analyseAudio) {
78 self->showAudio(frame);
80 if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
82 self->emitConsumerStopped();
87 static void consumer_paused(mlt_consumer, Render * self, mlt_frame /*frame_ptr*/)
89 // detect if the producer has finished playing. Is there a better way to do it?
90 self->emitConsumerStopped();
94 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
96 // detect if the producer has finished playing. Is there a better way to do it?
97 Mlt::Frame frame(frame_ptr);
98 self->showFrame(frame);
99 if (frame.get_double("_speed") == 0.0) {
100 self->emitConsumerStopped();
101 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
103 self->emitConsumerStopped();
107 Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWidget *parent) :
108 AbstractRender(rendererName, parent),
109 requestedSeekPosition(SEEK_INACTIVE),
110 m_name(rendererName),
114 m_showFrameEvent(NULL),
116 m_externalConsumer(false),
119 m_isSplitView(false),
123 qRegisterMetaType<stringMap> ("stringMap");
124 analyseAudio = KdenliveSettings::monitor_audio();
125 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
126 buildConsumer(profile);
127 m_mltProducer = m_blackClip->cut(0, 1);
128 m_mltConsumer->connect(*m_mltProducer);
129 m_mltProducer->set_speed(0.0);
130 m_refreshTimer.setSingleShot(true);
131 m_refreshTimer.setInterval(70);
132 connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
133 connect(this, SIGNAL(multiStreamFound(const QString &,QList<int>,QList<int>,stringMap)), this, SLOT(slotMultiStreamProducerFound(const QString &,QList<int>,QList<int>,stringMap)));
143 void Render::closeMlt()
146 m_requestList.clear();
147 m_infoThread.waitForFinished();
148 if (m_showFrameEvent) delete m_showFrameEvent;
149 if (m_pauseEvent) delete m_pauseEvent;
150 if (m_mltConsumer) delete m_mltConsumer;
151 if (m_mltProducer) delete m_mltProducer;
152 /*if (m_mltProducer) {
153 Mlt::Service service(m_mltProducer->parent().get_service());
156 if (service.type() == tractor_type) {
157 Mlt::Tractor tractor(service);
158 Mlt::Field *field = tractor.field();
159 mlt_service nextservice = mlt_service_get_producer(service.get_service());
160 mlt_service nextservicetodisconnect;
161 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
162 QString mlt_type = mlt_properties_get(properties, "mlt_type");
163 QString resource = mlt_properties_get(properties, "mlt_service");
164 // Delete all transitions
165 while (mlt_type == "transition") {
166 nextservicetodisconnect = nextservice;
167 nextservice = mlt_service_producer(nextservice);
168 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
169 if (nextservice == NULL) break;
170 properties = MLT_SERVICE_PROPERTIES(nextservice);
171 mlt_type = mlt_properties_get(properties, "mlt_type");
172 resource = mlt_properties_get(properties, "mlt_service");
181 //kDebug() << "// // // CLOSE RENDERER " << m_name;
182 if (m_blackClip) delete m_blackClip;
186 void Render::slotSwitchFullscreen()
188 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
191 void Render::buildConsumer(const QString &profileName)
196 m_activeProfile = profileName;
198 Mlt::Profile tmpProfile(m_activeProfile.toUtf8().constData());
199 m_mltProfile->set_colorspace(tmpProfile.colorspace());
200 m_mltProfile->set_frame_rate(tmpProfile.frame_rate_num(), tmpProfile.frame_rate_den());
201 m_mltProfile->set_height(tmpProfile.height());
202 m_mltProfile->set_width(tmpProfile.width());
203 m_mltProfile->set_progressive(tmpProfile.progressive());
204 m_mltProfile->set_sample_aspect(tmpProfile.sample_aspect_num(), tmpProfile.sample_aspect_den());
205 m_mltProfile->get_profile()->display_aspect_num = tmpProfile.display_aspect_num();
206 m_mltProfile->get_profile()->display_aspect_den = tmpProfile.display_aspect_den();
209 m_mltProfile = new Mlt::Profile(m_activeProfile.toUtf8().constData());
211 setenv("MLT_PROFILE", m_activeProfile.toUtf8().constData(), 1);
212 m_mltProfile->set_explicit(true);
214 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
215 m_blackClip->set("id", "black");
216 m_blackClip->set("mlt_type", "producer");
218 if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) {
219 #ifdef USE_BLACKMAGIC
220 // Use blackmagic card for video output
221 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
222 int device = KdenliveSettings::blackmagic_output_device();
224 if (BMInterface::isSupportedProfile(device, profileProperties)) {
225 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
226 if (!m_mltConsumer) {
227 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, decklink.toUtf8().constData());
228 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
229 mlt_log_set_callback(kdenlive_callback);
231 if (m_mltConsumer->is_valid()) {
232 m_externalConsumer = true;
233 m_mltConsumer->set("terminate_on_pause", 0);
234 m_mltConsumer->set("deinterlace_method", "onefield");
235 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
237 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
238 } else KMessageBox::informationList(qApp->activeWindow(), i18n("Your project's profile %1 is not compatible with the blackmagic output card. Please see supported profiles below. Switching to normal video display.", m_mltProfile->description()), BMInterface::supportedModes(KdenliveSettings::blackmagic_output_device()));
242 m_externalConsumer = false;
243 QString videoDriver = KdenliveSettings::videodrivername();
244 if (!videoDriver.isEmpty()) {
245 if (videoDriver == "x11_noaccel") {
246 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
249 unsetenv("SDL_VIDEO_YUV_HWACCEL");
252 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
254 //m_mltConsumer->set("fullscreen", 1);
257 if (!m_mltConsumer) {
258 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
259 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
261 m_mltConsumer->set("preview_off", 1);
262 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
264 if (!m_mltConsumer) {
265 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
266 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
267 m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
269 m_mltConsumer->set("window_id", m_winid);
271 m_mltConsumer->set("resize", 1);
272 m_mltConsumer->set("terminate_on_pause", 1);
273 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
274 m_mltConsumer->set("rescale", "nearest");
275 mlt_log_set_callback(kdenlive_callback);
277 QString audioDevice = KdenliveSettings::audiodevicename();
278 if (!audioDevice.isEmpty())
279 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
281 if (!videoDriver.isEmpty())
282 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
284 QString audioDriver = KdenliveSettings::audiodrivername();
287 // Disabled because the "auto" detected driver was sometimes wrong
288 if (audioDriver.isEmpty())
289 audioDriver = KdenliveSettings::autoaudiodrivername();
292 if (!audioDriver.isEmpty())
293 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
295 m_mltConsumer->set("progressive", 1);
296 m_mltConsumer->set("audio_buffer", 1024);
297 m_mltConsumer->set("frequency", 48000);
298 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
301 Mlt::Producer *Render::invalidProducer(const QString &id)
304 QString txt = '+' + i18n("Missing clip") + ".txt";
305 char *tmp = qstrdup(txt.toUtf8().constData());
306 clip = new Mlt::Producer(*m_mltProfile, tmp);
308 if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
310 clip->set("bgcolour", "0xff0000ff");
311 clip->set("pad", "10");
313 clip->set("id", id.toUtf8().constData());
314 clip->set("mlt_type", "producer");
318 bool Render::hasProfile(const QString &profileName) const
320 return m_activeProfile == profileName;
323 int Render::resetProfile(const QString &profileName, bool dropSceneList)
325 m_refreshTimer.stop();
327 if (m_externalConsumer == KdenliveSettings::external_display()) {
328 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
329 QString videoDriver = KdenliveSettings::videodrivername();
330 QString currentDriver = m_mltConsumer->get("video_driver");
331 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
332 QString background = KdenliveSettings::window_background().name();
333 QString currentBackground = m_mltConsumer->get("window_background");
334 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
335 kDebug() << "reset to same profile, nothing to do";
340 if (m_isSplitView) slotSplitView(false);
341 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
342 m_mltConsumer->purge();
345 if (!dropSceneList) scene = sceneList();
347 double current_fps = m_mltProfile->fps();
348 double current_dar = m_mltProfile->dar();
351 m_requestList.clear();
352 m_infoThread.waitForFinished();
355 pos = m_mltProducer->position();
357 Mlt::Service service(m_mltProducer->get_service());
358 if (service.type() == tractor_type) {
359 Mlt::Tractor tractor(service);
360 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
361 Mlt::Producer trackProducer(tractor.track(trackNb));
362 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
363 trackPlaylist.clear();
367 delete m_mltProducer;
369 m_mltProducer = NULL;
370 buildConsumer(profileName);
371 double new_fps = m_mltProfile->fps();
372 double new_dar = m_mltProfile->dar();
374 if (!dropSceneList) {
375 // We need to recover our playlist
376 if (current_fps != new_fps) {
377 // fps changed, we must update the scenelist positions
378 scene = updateSceneListFps(current_fps, new_fps, scene);
380 setSceneList(scene, pos);
381 // producers have changed (different profile), so reset them...
382 emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
387 void Render::seek(GenTime time)
389 int pos = time.frames(m_fps);
393 void Render::seek(int time)
397 if (requestedSeekPosition == SEEK_INACTIVE) {
398 requestedSeekPosition = time;
399 m_mltProducer->seek(time);
400 m_mltConsumer->purge();
401 if (m_mltProducer->get_speed() == 0) {
405 else requestedSeekPosition = time;
409 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
410 QPixmap pix(width, height);
412 mlt_image_format format = mlt_image_rgb24a;
413 uint8_t *thumb = frame->get_image(format, width, height);
414 QImage image(thumb, width, height, QImage::Format_ARGB32);
416 if (!image.isNull()) {
417 pix = pix.fromImage(image);
419 QPainter painter(&pix);
420 painter.drawRect(0, 0, width - 1, height - 1);
422 } else pix.fill(Qt::black);
426 int Render::frameRenderWidth() const
428 return m_mltProfile->width();
431 int Render::renderWidth() const
433 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
436 int Render::renderHeight() const
438 return m_mltProfile->height();
441 QImage Render::extractFrame(int frame_position, QString path, int width, int height)
444 width = frameRenderWidth();
445 height = renderHeight();
446 } else if (width % 2 == 1) width++;
447 int dwidth = height * frameRenderWidth() / renderHeight();
448 if (!path.isEmpty()) {
449 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
451 if (producer->is_valid()) {
452 QImage img = KThumb::getFrame(producer, frame_position, dwidth, width, height);
456 else delete producer;
460 if (!m_mltProducer || !path.isEmpty()) {
461 QImage pix(width, height, QImage::Format_RGB32);
465 return KThumb::getFrame(m_mltProducer, frame_position, dwidth, width, height);
468 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
472 if (url.fileName().startsWith(".all.")) { // check for slideshow
473 QString fileType = url.fileName().right(3);
475 QStringList::Iterator it;
477 QDir dir(url.directory());
479 filter << "*." + fileType;
480 filter << "*." + fileType.toUpper();
481 more = dir.entryList(filter, QDir::Files);
482 im.load(url.directory() + '/' + more.at(0));
483 } else im.load(url.path());
484 //pixmap = im.scaled(width, height);
488 double Render::consumerRatio() const
490 if (!m_mltConsumer) return 1.0;
491 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
495 int Render::getLength()
499 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
500 return mlt_producer_get_playtime(m_mltProducer->get_producer());
505 bool Render::isValid(KUrl url)
507 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
508 if (producer.is_blank())
514 double Render::dar() const
516 return m_mltProfile->dar();
519 double Render::sar() const
521 return m_mltProfile->sar();
524 void Render::slotSplitView(bool doit)
526 m_isSplitView = doit;
527 Mlt::Service service(m_mltProducer->parent().get_service());
528 Mlt::Tractor tractor(service);
529 if (service.type() != tractor_type || tractor.count() < 2) return;
530 Mlt::Field *field = tractor.field();
532 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
533 Mlt::Producer trackProducer(tractor.track(i));
534 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
535 if (QString(trackProducer.get("hide")).toInt() != 1) {
536 kDebug() << "// ADIDNG TRACK: " << i;
537 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
538 transition->set("mlt_service", "composite");
539 transition->set("a_track", 0);
540 transition->set("b_track", i);
541 transition->set("distort", 0);
542 transition->set("aligned", 0);
543 transition->set("internal_added", "200");
547 geometry = "0/0:50%x50%";
550 geometry = "50%/0:50%x50%";
553 geometry = "0/50%:50%x50%";
557 geometry = "50%/50%:50%x50%";
560 transition->set("geometry", geometry.toUtf8().constData());
561 transition->set("always_active", "1");
562 field->plant_transition(*transition, 0, i);
566 m_mltConsumer->set("refresh", 1);
568 mlt_service serv = m_mltProducer->parent().get_service();
569 mlt_service nextservice = mlt_service_get_producer(serv);
570 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
571 QString mlt_type = mlt_properties_get(properties, "mlt_type");
572 QString resource = mlt_properties_get(properties, "mlt_service");
573 mlt_service nextservicetodisconnect;
575 while (mlt_type == "transition") {
576 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
577 if (added == "200") {
578 nextservicetodisconnect = nextservice;
579 nextservice = mlt_service_producer(nextservice);
580 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
582 else nextservice = mlt_service_producer(nextservice);
583 if (nextservice == NULL) break;
584 properties = MLT_SERVICE_PROPERTIES(nextservice);
585 mlt_type = mlt_properties_get(properties, "mlt_type");
586 resource = mlt_properties_get(properties, "mlt_service");
587 m_mltConsumer->set("refresh", 1);
592 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer)
594 requestClipInfo info;
596 info.clipId = clipId;
597 info.imageHeight = imageHeight;
598 info.replaceProducer = replaceProducer;
599 // Make sure we don't request the info for same clip twice
601 m_requestList.removeAll(info);
602 m_requestList.append(info);
603 m_infoMutex.unlock();
604 if (!m_infoThread.isRunning()) {
605 m_infoThread = QtConcurrent::run(this, &Render::processFileProperties);
609 void Render::forceProcessing(const QString &id)
611 if (m_processingClipId == id) return;
612 QMutexLocker lock(&m_infoMutex);
613 for (int i = 0; i < m_requestList.count(); i++) {
614 requestClipInfo info = m_requestList.at(i);
615 if (info.clipId == id) {
618 m_requestList.removeAt(i);
619 m_requestList.prepend(info);
626 int Render::processingItems()
628 QMutexLocker lock(&m_infoMutex);
629 int count = m_requestList.count();
630 if (!m_processingClipId.isEmpty()) {
631 // one clip is currently processed
637 bool Render::isProcessing(const QString &id)
639 if (m_processingClipId == id) return true;
640 QMutexLocker lock(&m_infoMutex);
641 for (int i = 0; i < m_requestList.count(); i++) {
642 requestClipInfo info = m_requestList.at(i);
643 if (info.clipId == id) {
650 void Render::processFileProperties()
652 requestClipInfo info;
654 while (!m_requestList.isEmpty()) {
656 info = m_requestList.takeFirst();
657 m_processingClipId = info.clipId;
658 m_infoMutex.unlock();
662 if (info.xml.hasAttribute("proxy") && info.xml.attribute("proxy") != "-") {
663 path = info.xml.attribute("proxy");
664 // Check for missing proxies
665 if (QFileInfo(path).size() <= 0) {
666 // proxy is missing, re-create it
667 emit requestProxy(info.clipId);
668 proxyProducer = false;
669 path = info.xml.attribute("resource");
671 else proxyProducer = true;
674 path = info.xml.attribute("resource");
675 proxyProducer = false;
678 Mlt::Producer *producer = NULL;
679 CLIPTYPE type = (CLIPTYPE)info.xml.attribute("type").toInt();
681 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + info.xml.attribute("colour")).toUtf8().constData());
682 } else if (type == TEXT) {
683 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
684 if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
685 producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
686 } else if (url.isEmpty()) {
687 //WARNING: when is this case used? Not sure it is working.. JBM/
689 QDomElement mlt = doc.createElement("mlt");
690 QDomElement play = doc.createElement("playlist");
691 play.setAttribute("id", "playlist0");
692 doc.appendChild(mlt);
693 mlt.appendChild(play);
694 play.appendChild(doc.importNode(info.xml, true));
695 QDomElement tractor = doc.createElement("tractor");
696 tractor.setAttribute("id", "tractor0");
697 QDomElement track = doc.createElement("track");
698 track.setAttribute("producer", "playlist0");
699 tractor.appendChild(track);
700 mlt.appendChild(tractor);
701 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
703 producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
706 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
707 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
708 m_processingClipId.clear();
710 // Proxy file is corrupted
711 emit removeInvalidProxy(info.clipId, false);
713 else emit removeInvalidClip(info.clipId, info.replaceProducer);
718 if (proxyProducer && info.xml.hasAttribute("proxy_out")) {
719 producer->set("length", info.xml.attribute("proxy_out").toInt() + 1);
720 producer->set("out", info.xml.attribute("proxy_out").toInt());
721 if (producer->get_out() != info.xml.attribute("proxy_out").toInt()) {
722 // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
723 m_processingClipId.clear();
724 emit removeInvalidProxy(info.clipId, true);
730 if (info.xml.hasAttribute("force_aspect_ratio")) {
731 double aspect = info.xml.attribute("force_aspect_ratio").toDouble();
732 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
735 if (info.xml.hasAttribute("force_aspect_num") && info.xml.hasAttribute("force_aspect_den")) {
736 int width = info.xml.attribute("frame_size").section('x', 0, 0).toInt();
737 int height = info.xml.attribute("frame_size").section('x', 1, 1).toInt();
738 int aspectNumerator = info.xml.attribute("force_aspect_num").toInt();
739 int aspectDenominator = info.xml.attribute("force_aspect_den").toInt();
740 if (aspectDenominator != 0 && width != 0)
741 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
744 if (info.xml.hasAttribute("force_fps")) {
745 double fps = info.xml.attribute("force_fps").toDouble();
746 if (fps > 0) producer->set("force_fps", fps);
749 if (info.xml.hasAttribute("force_progressive")) {
751 int progressive = info.xml.attribute("force_progressive").toInt(&ok);
752 if (ok) producer->set("force_progressive", progressive);
754 if (info.xml.hasAttribute("force_tff")) {
756 int fieldOrder = info.xml.attribute("force_tff").toInt(&ok);
757 if (ok) producer->set("force_tff", fieldOrder);
759 if (info.xml.hasAttribute("threads")) {
760 int threads = info.xml.attribute("threads").toInt();
761 if (threads != 1) producer->set("threads", threads);
763 if (info.xml.hasAttribute("video_index")) {
764 int vindex = info.xml.attribute("video_index").toInt();
765 if (vindex != 0) producer->set("video_index", vindex);
767 if (info.xml.hasAttribute("audio_index")) {
768 int aindex = info.xml.attribute("audio_index").toInt();
769 if (aindex != 0) producer->set("audio_index", aindex);
771 if (info.xml.hasAttribute("force_colorspace")) {
772 int colorspace = info.xml.attribute("force_colorspace").toInt();
773 if (colorspace != 0) producer->set("force_colorspace", colorspace);
775 if (info.xml.hasAttribute("full_luma")) {
776 int full_luma = info.xml.attribute("full_luma").toInt();
777 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
782 if (info.xml.hasAttribute("out")) clipOut = info.xml.attribute("out").toInt();
784 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
785 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
787 if (info.xml.hasAttribute("length")) {
788 length = info.xml.attribute("length").toInt();
789 clipOut = length - 1;
791 else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt();
792 producer->set("length", length);
796 if (clipOut > 0) producer->set_in_and_out(info.xml.attribute("in").toInt(), clipOut);
798 producer->set("id", info.clipId.toUtf8().constData());
800 if (info.xml.hasAttribute("templatetext"))
801 producer->set("templatetext", info.xml.attribute("templatetext").toUtf8().constData());
803 int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5);
804 int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5);
805 int frameNumber = info.xml.attribute("thumbnail", "-1").toInt();
807 if ((!info.replaceProducer && info.xml.hasAttribute("file_hash")) || proxyProducer) {
808 // Clip already has all properties
810 // Recreate clip thumb
811 if (frameNumber > 0) producer->seek(frameNumber);
812 Mlt::Frame *frame = producer->get_frame();
813 if (frame && frame->is_valid()) {
814 QImage img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
815 emit replyGetImage(info.clipId, img);
817 if (frame) delete frame;
819 m_processingClipId.clear();
820 emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
824 stringMap filePropertyMap;
825 stringMap metadataPropertyMap;
828 if (frameNumber > 0) producer->seek(frameNumber);
829 duration = duration > 0 ? duration : producer->get_playtime();
830 filePropertyMap["duration"] = QString::number(duration);
831 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
833 if (type == SLIDESHOW) {
834 int ttl = info.xml.hasAttribute("ttl") ? info.xml.attribute("ttl").toInt() : 0;
835 if (ttl) producer->set("ttl", ttl);
836 if (!info.xml.attribute("animation").isEmpty()) {
837 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
838 if (filter && filter->is_valid()) {
840 QString geometry = SlideshowClip::animationToGeometry(info.xml.attribute("animation"), cycle);
841 if (!geometry.isEmpty()) {
842 if (info.xml.attribute("animation").contains("low-pass")) {
843 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
844 if (blur && blur->is_valid())
845 producer->attach(*blur);
847 filter->set("transition.geometry", geometry.toUtf8().data());
848 filter->set("transition.cycle", cycle);
849 producer->attach(*filter);
853 if (info.xml.attribute("fade") == "1") {
854 // user wants a fade effect to slideshow
855 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
856 if (filter && filter->is_valid()) {
857 if (ttl) filter->set("cycle", ttl);
858 if (info.xml.hasAttribute("luma_duration") && !info.xml.attribute("luma_duration").isEmpty()) filter->set("duration", info.xml.attribute("luma_duration").toInt());
859 if (info.xml.hasAttribute("luma_file") && !info.xml.attribute("luma_file").isEmpty()) {
860 filter->set("luma.resource", info.xml.attribute("luma_file").toUtf8().constData());
861 if (info.xml.hasAttribute("softness")) {
862 int soft = info.xml.attribute("softness").toInt();
863 filter->set("luma.softness", (double) soft / 100.0);
866 producer->attach(*filter);
869 if (info.xml.attribute("crop") == "1") {
870 // user wants to center crop the slides
871 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
872 if (filter && filter->is_valid()) {
873 filter->set("center", 1);
874 producer->attach(*filter);
880 const QString mltService = producer->get("mlt_service");
881 if (mltService == "xml" || mltService == "consumer") {
882 // MLT playlist, create producer with blank profile to get real profile info
883 // TODO: is there an easier way to get this info (original source clip profile) from MLT?
884 Mlt::Profile *original_profile = new Mlt::Profile();
885 Mlt::Producer *tmpProd = new Mlt::Producer(*original_profile, path.toUtf8().constData());
886 filePropertyMap["progressive"] = QString::number(original_profile->progressive());
887 filePropertyMap["colorspace"] = QString::number(original_profile->colorspace());
888 filePropertyMap["fps"] = QString::number(original_profile->fps());
889 filePropertyMap["aspect_ratio"] = QString::number(original_profile->sar());
891 delete original_profile;
893 else if (mltService == "avformat") {
895 vindex = producer->get_int("video_index");
898 int streams = producer->get_int("meta.media.nb_streams");
899 QList <int> audio_list;
900 QList <int> video_list;
901 for (int i = 0; i < streams; i++) {
902 QByteArray propertyName = QString("meta.media.%1.stream.type").arg(i).toLocal8Bit();
903 QString type = producer->get(propertyName.data());
904 if (type == "audio") audio_list.append(i);
905 else if (type == "video") video_list.append(i);
908 if (!info.xml.hasAttribute("video_index") && video_list.count() > 1) {
909 // Clip has more than one video stream, ask which one should be used
910 QMap <QString, QString> data;
911 if (info.xml.hasAttribute("group")) data.insert("group", info.xml.attribute("group"));
912 if (info.xml.hasAttribute("groupId")) data.insert("groupId", info.xml.attribute("groupId"));
913 emit multiStreamFound(path, audio_list, video_list, data);
914 // Force video index so that when reloading the clip we don't ask again for other streams
915 filePropertyMap["video_index"] = QString::number(vindex);
919 snprintf(property, sizeof(property), "meta.media.%d.stream.frame_rate", vindex);
920 if (producer->get(property))
921 filePropertyMap["fps"] = producer->get(property);
924 if (!filePropertyMap.contains("fps")) {
925 if (producer->get_double("meta.media.frame_rate_den") > 0) {
926 filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
927 } else filePropertyMap["fps"] = producer->get("source_fps");
931 Mlt::Frame *frame = producer->get_frame();
932 if (frame && frame->is_valid()) {
933 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
934 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
935 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
936 if (!filePropertyMap.contains("aspect_ratio")) filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
938 if (frame->get_int("test_image") == 0) {
939 if (mltService == "xml" || mltService == "consumer") {
940 filePropertyMap["type"] = "playlist";
941 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
942 } else if (frame->get_int("test_audio") == 0)
943 filePropertyMap["type"] = "av";
945 filePropertyMap["type"] = "video";
951 img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
952 variance = KThumb::imageVariance(img);
953 if (frameNumber == -1 && variance< 6) {
954 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
955 frameNumber = duration > 100 ? 100 : duration / 2 ;
956 producer->seek(frameNumber);
958 frame = producer->get_frame();
961 } while (variance == -1);
963 if (frameNumber > -1) filePropertyMap["thumbnail"] = QString::number(frameNumber);
964 emit replyGetImage(info.clipId, img);
965 } else if (frame->get_int("test_audio") == 0) {
966 emit replyGetImage(info.clipId, "audio-x-generic", fullWidth, info.imageHeight);
967 filePropertyMap["type"] = "audio";
970 // Retrieve audio / video codec name
973 if (mltService == "avformat") {
975 /*if (context->duration == AV_NOPTS_VALUE) {
976 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
977 emit removeInvalidClip(clipId);
981 // Get the video_index
983 int default_audio = producer->get_int("audio_index");
986 int scan = producer->get_int("meta.media.progressive");
987 filePropertyMap["progressive"] = QString::number(scan);
989 // Find maximum stream index values
990 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
991 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
992 QString type = producer->get(property);
995 else if (type == "audio")
998 filePropertyMap["default_video"] = QString::number(vindex);
999 filePropertyMap["video_max"] = QString::number(video_max);
1000 filePropertyMap["default_audio"] = QString::number(default_audio);
1001 filePropertyMap["audio_max"] = QString::number(audio_max);
1003 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex);
1004 if (producer->get(property)) {
1005 filePropertyMap["videocodec"] = producer->get(property);
1007 snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex);
1008 if (producer->get(property))
1009 filePropertyMap["videocodec"] = producer->get(property);
1012 query = QString("meta.media.%1.codec.pix_fmt").arg(vindex);
1013 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
1014 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
1016 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
1017 if (producer->get_int("audio_index") > -1) {
1018 // Get the audio_index
1019 int index = producer->get_int("audio_index");
1020 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
1021 if (producer->get(property)) {
1022 filePropertyMap["audiocodec"] = producer->get(property);
1024 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
1025 if (producer->get(property))
1026 filePropertyMap["audiocodec"] = producer->get(property);
1032 Mlt::Properties metadata;
1033 metadata.pass_values(*producer, "meta.attr.");
1034 int count = metadata.count();
1035 for (int i = 0; i < count; i ++) {
1036 QString name = metadata.get_name(i);
1037 QString value = QString::fromUtf8(metadata.get(i));
1038 if (name.endsWith("markup") && !value.isEmpty())
1039 metadataPropertyMap[ name.section('.', 0, -2)] = value;
1042 m_processingClipId.clear();
1043 emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer);
1045 m_processingClipId.clear();
1050 /** Create the producer from the MLT XML QDomDocument */
1051 void Render::initSceneList()
1053 kDebug() << "-------- INIT SCENE LIST ------_";
1055 QDomElement mlt = doc.createElement("mlt");
1056 doc.appendChild(mlt);
1057 QDomElement prod = doc.createElement("producer");
1058 prod.setAttribute("resource", "colour");
1059 prod.setAttribute("colour", "red");
1060 prod.setAttribute("id", "black");
1061 prod.setAttribute("in", "0");
1062 prod.setAttribute("out", "0");
1064 QDomElement tractor = doc.createElement("tractor");
1065 QDomElement multitrack = doc.createElement("multitrack");
1067 QDomElement playlist1 = doc.createElement("playlist");
1068 playlist1.appendChild(prod);
1069 multitrack.appendChild(playlist1);
1070 QDomElement playlist2 = doc.createElement("playlist");
1071 multitrack.appendChild(playlist2);
1072 QDomElement playlist3 = doc.createElement("playlist");
1073 multitrack.appendChild(playlist3);
1074 QDomElement playlist4 = doc.createElement("playlist");
1075 multitrack.appendChild(playlist4);
1076 QDomElement playlist5 = doc.createElement("playlist");
1077 multitrack.appendChild(playlist5);
1078 tractor.appendChild(multitrack);
1079 mlt.appendChild(tractor);
1080 // kDebug()<<doc.toString();
1082 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
1083 setSceneList(doc, 0);
1087 int Render::setProducer(Mlt::Producer *producer, int position)
1089 m_refreshTimer.stop();
1090 requestedSeekPosition = SEEK_INACTIVE;
1091 QMutexLocker locker(&m_mutex);
1093 int consumerPosition = 0;
1094 if (m_winid == -1 || !m_mltConsumer) {
1095 kDebug()<<" / / / / WARNING, MONITOR NOT READY";
1096 if (producer) delete producer;
1099 m_mltConsumer->set("refresh", 0);
1100 if (!m_mltConsumer->is_stopped()) {
1101 m_mltConsumer->stop();
1103 m_mltConsumer->purge();
1104 consumerPosition = m_mltConsumer->position();
1108 if (!producer || !producer->is_valid()) {
1109 if (producer) delete producer;
1110 producer = m_blackClip->cut(0, 1);
1113 if (!producer || !producer->is_valid()) {
1114 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
1117 if (m_mltProducer) currentId = m_mltProducer->get("id");
1119 if (position == -1 && producer->get("id") == currentId) position = consumerPosition;
1120 if (position != -1) producer->seek(position);
1121 int volume = KdenliveSettings::volume();
1122 producer->set("meta.volume", (double)volume / 100);
1123 m_fps = producer->get_fps();
1124 blockSignals(false);
1125 m_mltConsumer->connect(*producer);
1127 if (m_mltProducer) {
1128 m_mltProducer->set_speed(0);
1129 delete m_mltProducer;
1130 m_mltProducer = NULL;
1132 m_mltProducer = producer;
1133 m_mltProducer->set_speed(0);
1134 emit durationChanged(m_mltProducer->get_playtime());
1135 if (m_mltConsumer->start() == -1) {
1136 // ARGH CONSUMER BROKEN!!!!
1137 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."));
1138 if (m_showFrameEvent) delete m_showFrameEvent;
1139 m_showFrameEvent = NULL;
1140 if (m_pauseEvent) delete m_pauseEvent;
1141 m_pauseEvent = NULL;
1142 delete m_mltConsumer;
1143 m_mltConsumer = NULL;
1147 position = m_mltProducer->position();
1148 m_mltConsumer->set("refresh", 1);
1149 // Make sure the first frame is displayed, otherwise if we change producer too fast
1150 // We can crash the avformat producer
1151 Mlt::Event *ev = m_mltConsumer->setup_wait_for("consumer-frame-show");
1152 m_mltConsumer->wait_for(ev);
1154 emit rendererPosition(position);
1158 int Render::setSceneList(QDomDocument list, int position)
1160 return setSceneList(list.toString(), position);
1163 int Render::setSceneList(QString playlist, int position)
1165 requestedSeekPosition = SEEK_INACTIVE;
1166 m_refreshTimer.stop();
1167 QMutexLocker locker(&m_mutex);
1168 if (m_winid == -1) return -1;
1171 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
1173 // Remove previous profile info
1175 doc.setContent(playlist);
1176 QDomElement profile = doc.documentElement().firstChildElement("profile");
1177 doc.documentElement().removeChild(profile);
1178 playlist = doc.toString();
1180 if (m_mltConsumer) {
1181 if (!m_mltConsumer->is_stopped()) {
1182 m_mltConsumer->stop();
1184 m_mltConsumer->set("refresh", 0);
1186 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
1189 m_requestList.clear();
1190 m_infoThread.waitForFinished();
1192 if (m_mltProducer) {
1193 m_mltProducer->set_speed(0);
1194 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1196 /*Mlt::Service service(m_mltProducer->parent().get_service());
1199 if (service.type() == tractor_type) {
1200 Mlt::Tractor tractor(service);
1201 Mlt::Field *field = tractor.field();
1202 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1203 mlt_service nextservicetodisconnect;
1204 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1205 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1206 QString resource = mlt_properties_get(properties, "mlt_service");
1207 // Delete all transitions
1208 while (mlt_type == "transition") {
1209 nextservicetodisconnect = nextservice;
1210 nextservice = mlt_service_producer(nextservice);
1211 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1212 if (nextservice == NULL) break;
1213 properties = MLT_SERVICE_PROPERTIES(nextservice);
1214 mlt_type = mlt_properties_get(properties, "mlt_type");
1215 resource = mlt_properties_get(properties, "mlt_service");
1219 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1220 Mlt::Producer trackProducer(tractor.track(trackNb));
1221 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1222 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1228 qDeleteAll(m_slowmotionProducers.values());
1229 m_slowmotionProducers.clear();
1231 delete m_mltProducer;
1232 m_mltProducer = NULL;
1237 m_locale = QLocale();
1238 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1239 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1240 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1241 m_mltProducer = m_blackClip->cut(0, 1);
1245 int volume = KdenliveSettings::volume();
1246 m_mltProducer->set("meta.volume", (double)volume / 100);
1247 m_mltProducer->optimise();
1249 /*if (KdenliveSettings::osdtimecode()) {
1250 // Attach filter for on screen display of timecode
1252 QString attr = "attr_check";
1253 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1254 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1255 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1256 mlt_filter_close( filter );
1258 m_osdInfo = new Mlt::Filter("data_show");
1259 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1260 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1261 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1262 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1263 m_osdInfo->set("dynamic", "1");
1265 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1267 m_osdInfo->set("dynamic", "0");
1270 m_fps = m_mltProducer->get_fps();
1271 if (position != 0) {
1272 // Seek to correct place after opening project.
1273 m_mltProducer->seek(position);
1276 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1277 m_mltConsumer->connect(*m_mltProducer);
1278 m_mltProducer->set_speed(0);
1279 fillSlowMotionProducers();
1280 blockSignals(false);
1281 emit durationChanged(m_mltProducer->get_playtime());
1284 //kDebug()<<"// SETSCN LST, POS: "<<position;
1285 //if (position != 0) emit rendererPosition(position);
1288 void Render::checkMaxThreads()
1290 // Make sure we don't use too much threads, MLT avformat does not cope with too much threads
1291 // Currently, Kdenlive uses the following avformat threads:
1292 // One thread to get info when adding a clip
1293 // One thread to create the timeline video thumbnails
1294 // One thread to create the audio thumbnails
1295 Mlt::Service service(m_mltProducer->parent().get_service());
1296 if (service.type() != tractor_type) {
1297 kWarning() << "// TRACTOR PROBLEM";
1300 Mlt::Tractor tractor(service);
1301 int mltMaxThreads = mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1302 int requestedThreads = tractor.count() + 4;
1303 if (requestedThreads > mltMaxThreads) {
1304 mlt_service_cache_set_size(service.get_service(), "producer_avformat", requestedThreads);
1305 kDebug()<<"// MLT threads updated to: "<<mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1309 const QString Render::sceneList()
1312 Mlt::Profile profile((mlt_profile) 0);
1313 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1314 if (!xmlConsumer.is_valid()) return QString();
1315 m_mltProducer->optimise();
1316 xmlConsumer.set("terminate_on_pause", 1);
1317 Mlt::Producer prod(m_mltProducer->get_producer());
1318 if (!prod.is_valid()) return QString();
1319 bool split = m_isSplitView;
1320 if (split) slotSplitView(false);
1321 xmlConsumer.connect(prod);
1323 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1324 if (split) slotSplitView(true);
1328 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1332 doc.setContent(sceneList(), false);
1333 if (doc.isNull()) return false;
1334 QDomElement root = doc.documentElement();
1335 if (!kdenliveData.isNull() && !root.isNull()) {
1336 // add Kdenlive specific tags
1337 root.appendChild(doc.importNode(kdenliveData, true));
1339 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1340 kWarning() << "////// ERROR writing to file: " << path;
1343 file.write(doc.toString().toUtf8());
1344 if (file.error() != QFile::NoError) {
1352 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1354 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1355 m_mltProducer->optimise();
1356 xmlConsumer.set("terminate_on_pause", 1);
1357 if (m_name == Kdenlive::clipMonitor) {
1358 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1360 list.insert_at(0, prod, 0);
1362 list.set("title", desc.toUtf8().constData());
1363 xmlConsumer.connect(list);
1366 //TODO: not working yet, save zone from timeline
1367 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1368 /* Mlt::Service service(p1->parent().get_service());
1369 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1371 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1372 //prod->set("title", desc.toUtf8().constData());
1373 xmlConsumer.connect(*p1); //list);
1376 xmlConsumer.start();
1380 bool Render::saveClip(int track, GenTime position, KUrl url, QString desc)
1383 Mlt::Service service(m_mltProducer->parent().get_service());
1384 Mlt::Tractor tractor(service);
1385 Mlt::Producer trackProducer(tractor.track(track));
1386 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1388 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1389 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1391 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
1395 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1396 xmlConsumer.set("terminate_on_pause", 1);
1398 list.insert_at(0, clip, 0);
1400 list.set("title", desc.toUtf8().constData());
1401 xmlConsumer.connect(list);
1403 kDebug()<<"// SAVED: "<<url;
1407 double Render::fps() const
1412 int Render::volume() const
1414 if (!m_mltConsumer || !m_mltProducer) return -1;
1415 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1418 void Render::slotSetVolume(int volume)
1420 if (!m_mltConsumer || !m_mltProducer) return;
1421 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1424 m_mltConsumer->set("refresh", 0);
1425 // Attach filter for on screen display of timecode
1426 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1427 mlt_properties_set_double( properties, "meta.volume", volume );
1428 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1429 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1431 if (!KdenliveSettings::osdtimecode()) {
1432 m_mltProducer->detach(*m_osdInfo);
1433 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1434 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1437 //m_osdTimer->setSingleShot(2500);
1440 void Render::slotOsdTimeout()
1442 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1443 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1444 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1445 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1449 void Render::start()
1451 m_refreshTimer.stop();
1452 QMutexLocker locker(&m_mutex);
1453 if (m_winid == -1) {
1454 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1457 if (!m_mltConsumer) return;
1458 if (m_mltConsumer->is_stopped()) {
1459 if (m_mltConsumer->start() == -1) {
1460 //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."));
1461 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1463 m_mltConsumer->purge();
1464 m_mltConsumer->set("refresh", 1);
1471 requestedSeekPosition = SEEK_INACTIVE;
1472 m_refreshTimer.stop();
1473 QMutexLocker locker(&m_mutex);
1474 if (m_mltProducer == NULL) return;
1475 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1476 m_mltConsumer->stop();
1477 m_mltConsumer->purge();
1480 if (m_mltProducer) {
1481 if (m_isZoneMode) resetZoneMode();
1482 m_mltProducer->set_speed(0.0);
1486 void Render::stop(const GenTime & startTime)
1488 requestedSeekPosition = SEEK_INACTIVE;
1489 m_refreshTimer.stop();
1490 QMutexLocker locker(&m_mutex);
1491 if (m_mltProducer) {
1492 if (m_isZoneMode) resetZoneMode();
1493 m_mltProducer->set_speed(0.0);
1494 m_mltProducer->seek((int) startTime.frames(m_fps));
1496 m_mltConsumer->purge();
1499 void Render::pause()
1501 requestedSeekPosition = SEEK_INACTIVE;
1502 if (!m_mltProducer || !m_mltConsumer)
1504 if (m_mltProducer->get_speed() == 0.0) return;
1505 if (m_isZoneMode) resetZoneMode();
1506 m_mltConsumer->set("refresh", 0);
1507 m_mltProducer->set_speed(0.0);
1508 m_mltConsumer->purge();
1511 void Render::switchPlay(bool play)
1513 QMutexLocker locker(&m_mutex);
1514 requestedSeekPosition = SEEK_INACTIVE;
1515 if (!m_mltProducer || !m_mltConsumer)
1517 if (m_isZoneMode) resetZoneMode();
1518 if (play && m_mltProducer->get_speed() == 0.0) {
1519 if (m_name == Kdenlive::clipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
1520 if (m_mltConsumer->is_stopped()) {
1521 m_mltConsumer->start();
1523 m_mltProducer->set_speed(1.0);
1524 m_mltConsumer->set("refresh", 1);
1526 m_mltProducer->set_speed(0.0);
1527 m_mltConsumer->set("refresh", 0);
1528 m_mltProducer->seek(m_mltConsumer->position());
1529 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1530 if (m_isZoneMode) resetZoneMode();
1532 //emitConsumerStopped();
1533 /*m_mltConsumer->set("refresh", 0);
1534 m_mltConsumer->stop();
1535 m_mltConsumer->purge();
1536 m_mltProducer->set_speed(0.0);
1537 //m_framePosition = m_mltProducer->position();
1538 m_mltProducer->seek(m_framePosition);
1539 emit rendererPosition(m_framePosition);*/
1543 void Render::play(double speed)
1545 requestedSeekPosition = SEEK_INACTIVE;
1548 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1549 m_mltProducer->set_speed(speed);
1550 /*if (speed == 0.0) {
1551 m_mltProducer->seek((int) m_framePosition + 1);
1552 m_mltConsumer->purge();
1557 void Render::play(const GenTime & startTime)
1559 requestedSeekPosition = SEEK_INACTIVE;
1560 if (!m_mltProducer || !m_mltConsumer)
1562 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1563 m_mltProducer->set_speed(1.0);
1564 m_mltConsumer->set("refresh", 1);
1567 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1569 requestedSeekPosition = SEEK_INACTIVE;
1570 if (!m_mltProducer || !m_mltConsumer)
1572 //m_mltProducer->set("eof", "loop");
1573 m_isLoopMode = true;
1574 m_loopStart = startTime;
1575 playZone(startTime, stopTime);
1578 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1580 requestedSeekPosition = SEEK_INACTIVE;
1581 if (!m_mltProducer || !m_mltConsumer)
1583 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1584 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1585 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1586 m_mltProducer->set_speed(1.0);
1587 m_mltConsumer->set("refresh", 1);
1588 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1589 m_isZoneMode = true;
1592 void Render::resetZoneMode()
1594 if (!m_mltProducer || (!m_isZoneMode && !m_isLoopMode)) return;
1595 m_mltProducer->set("out", m_originalOut);
1596 //m_mltProducer->set("eof", "pause");
1597 m_isZoneMode = false;
1598 m_isLoopMode = false;
1601 void Render::seekToFrame(int pos)
1607 void Render::seekToFrameDiff(int diff)
1610 if (requestedSeekPosition == SEEK_INACTIVE)
1611 seek(m_mltProducer->position() + diff);
1612 else seek(requestedSeekPosition + diff);
1615 void Render::doRefresh()
1617 if (m_mltProducer && m_mltProducer->get_speed() == 0) m_refreshTimer.start();
1620 void Render::refresh()
1622 QMutexLocker locker(&m_mutex);
1625 if (m_mltConsumer) {
1626 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1627 m_mltConsumer->purge();
1628 m_mltConsumer->set("refresh", 1);
1632 void Render::setDropFrames(bool show)
1634 QMutexLocker locker(&m_mutex);
1635 if (m_mltConsumer) {
1636 int dropFrames = KdenliveSettings::mltthreads();
1637 if (show == false) dropFrames = -dropFrames;
1638 m_mltConsumer->stop();
1640 m_mltConsumer->set("real_time", dropFrames);
1642 m_mltConsumer->set("play.real_time", dropFrames);
1644 if (m_mltConsumer->start() == -1) {
1645 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1651 double Render::playSpeed() const
1653 if (m_mltProducer) return m_mltProducer->get_speed();
1657 GenTime Render::seekPosition() const
1659 if (m_mltConsumer) return GenTime((int) m_mltConsumer->position(), m_fps);
1660 //if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1661 else return GenTime();
1664 int Render::seekFramePosition() const
1666 //if (m_mltProducer) return (int) m_mltProducer->position();
1667 if (m_mltConsumer) return (int) m_mltConsumer->position();
1671 void Render::emitFrameUpdated(Mlt::Frame& frame)
1673 mlt_image_format format = mlt_image_rgb24a;
1676 const uchar* image = frame.get_image(format, width, height);
1677 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1678 memcpy(qimage.scanLine(0), image, width * height * 4);
1680 /*mlt_image_format format = mlt_image_rgb24;
1683 const uchar* image = frame.get_image(format, width, height);
1684 QImage qimage(width, height, QImage::Format_RGB888);
1685 memcpy(qimage.bits(), image, width * height * 3);*/
1686 emit frameUpdated(qimage.rgbSwapped());
1689 void Render::emitFrameNumber()
1691 int currentPos = m_mltConsumer->position();
1692 if (currentPos == requestedSeekPosition) requestedSeekPosition = SEEK_INACTIVE;
1693 emit rendererPosition(currentPos);
1694 if (requestedSeekPosition != SEEK_INACTIVE) {
1695 m_mltProducer->seek(requestedSeekPosition);
1696 requestedSeekPosition = SEEK_INACTIVE;
1697 if (m_mltProducer->get_speed() == 0) {
1703 void Render::emitConsumerStopped()
1705 // This is used to know when the playing stopped
1706 if (m_mltProducer) {
1707 double pos = m_mltProducer->position();
1708 if (m_isLoopMode) play(m_loopStart);
1709 //else if (m_isZoneMode) resetZoneMode();
1710 emit rendererStopped((int) pos);
1714 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1716 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1719 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1721 if (!m_mltProducer) {
1722 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1726 //int height = 1080;//KdenliveSettings::defaultheight();
1727 //int width = 1940; //KdenliveSettings::displaywidth();
1729 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1731 QPixmap pix(width, height);
1732 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1733 m_convert.set("forced", mlt_image_rgb24a);
1734 m_mltProducer->attach(m_convert);
1735 Mlt::Frame * frame = m_mltProducer->get_frame();
1736 m_mltProducer->detach(m_convert);
1738 pix = frameThumbnail(frame, width, height);
1741 pix.save(url.path(), "PNG");
1742 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1746 void Render::showFrame(Mlt::Frame& frame)
1748 emit rendererPosition((int) m_mltConsumer->position());
1749 mlt_image_format format = mlt_image_rgb24a;
1752 const uchar* image = frame.get_image(format, width, height);
1753 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1754 memcpy(qimage.scanLine(0), image, width * height * 4);
1755 emit showImageSignal(qimage);
1756 if (analyseAudio) showAudio(frame);
1757 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1758 emit frameUpdated(qimage.rgbSwapped());
1762 void Render::disablePreview(bool disable)
1764 if (m_mltConsumer) {
1765 m_mltConsumer->stop();
1766 m_mltConsumer->set("preview_off", (int) disable);
1767 m_mltConsumer->set("refresh", 0);
1768 m_mltConsumer->start();
1772 void Render::showAudio(Mlt::Frame& frame)
1774 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1777 mlt_audio_format audio_format = mlt_audio_s16;
1778 //FIXME: should not be hardcoded..
1780 int num_channels = 2;
1782 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1788 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1789 // So the vector is of size samples*channels.
1790 QVector<int16_t> sampleVector(samples*num_channels);
1791 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1794 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1799 * MLT playlist direct manipulation.
1802 void Render::mltCheckLength(Mlt::Tractor *tractor)
1804 //kDebug()<<"checking track length: "<<track<<"..........";
1806 int trackNb = tractor->count();
1810 Mlt::Producer trackProducer(tractor->track(0));
1811 duration = trackProducer.get_playtime() - 1;
1812 m_mltProducer->set("out", duration);
1813 emit durationChanged(duration);
1816 while (trackNb > 1) {
1817 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1818 trackDuration = trackProducer.get_playtime() - 1;
1819 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1820 if (trackDuration > duration) duration = trackDuration;
1824 Mlt::Producer blackTrackProducer(tractor->track(0));
1826 if (blackTrackProducer.get_playtime() - 1 != duration) {
1827 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1828 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1829 if (blackclip && blackclip->is_blank()) {
1834 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1835 if (blackclip) delete blackclip;
1836 blackTrackPlaylist.clear();
1837 m_blackClip->set("length", duration + 1);
1838 m_blackClip->set("out", duration);
1839 blackclip = m_blackClip->cut(0, duration);
1840 blackTrackPlaylist.insert_at(0, blackclip, 1);
1842 if (duration > blackclip->parent().get_length()) {
1843 blackclip->parent().set("length", duration + 1);
1844 blackclip->parent().set("out", duration);
1845 blackclip->set("length", duration + 1);
1847 blackTrackPlaylist.resize_clip(0, 0, duration);
1851 m_mltProducer->set("out", duration);
1852 emit durationChanged(duration);
1856 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1858 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1860 // We want a slowmotion producer
1861 double speed = element.attribute("speed", "1.0").toDouble();
1862 int strobe = element.attribute("strobe", "1").toInt();
1863 QString url = QString::fromUtf8(prod->get("resource"));
1864 url.append('?' + locale.toString(speed));
1865 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1866 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1867 if (!slowprod || slowprod->get_producer() == NULL) {
1868 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
1869 if (strobe > 1) slowprod->set("strobe", strobe);
1870 QString id = prod->parent().get("id");
1871 if (id.contains('_')) id = id.section('_', 0, 0);
1872 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
1873 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1874 slowprod->set("id", producerid.toUtf8().constData());
1875 m_slowmotionProducers.insert(url, slowprod);
1880 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1882 if (m_mltProducer == NULL) {
1883 kDebug() << "PLAYLIST NOT INITIALISED //////";
1887 kDebug() << "Cannot insert clip without producer //////";
1890 Mlt::Producer parentProd(m_mltProducer->parent());
1891 if (parentProd.get_producer() == NULL) {
1892 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1896 Mlt::Service service(parentProd.get_service());
1897 if (service.type() != tractor_type) {
1898 kWarning() << "// TRACTOR PROBLEM";
1901 Mlt::Tractor tractor(service);
1902 if (info.track > tractor.count() - 1) {
1903 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1907 Mlt::Producer trackProducer(tractor.track(info.track));
1908 int trackDuration = trackProducer.get_playtime() - 1;
1909 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1910 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1911 prod = checkSlowMotionProducer(prod, element);
1912 if (prod == NULL || !prod->is_valid()) {
1917 int cutPos = (int) info.cropStart.frames(m_fps);
1918 if (cutPos < 0) cutPos = 0;
1919 int insertPos = (int) info.startPos.frames(m_fps);
1920 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1921 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1922 if (overwrite && (insertPos < trackDuration)) {
1923 // Replace zone with blanks
1924 //trackPlaylist.split_at(insertPos, true);
1925 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1926 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1927 trackPlaylist.insert_blank(clipIndex, cutDuration);
1929 trackPlaylist.split_at(insertPos, true);
1930 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1931 trackPlaylist.insert_blank(clipIndex, cutDuration);
1933 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1935 /*if (QString(prod->get("transparency")).toInt() == 1)
1936 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1938 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1940 /*tractor.multitrack()->refresh();
1941 tractor.refresh();*/
1946 bool Render::mltCutClip(int track, GenTime position)
1948 Mlt::Service service(m_mltProducer->parent().get_service());
1949 if (service.type() != tractor_type) {
1950 kWarning() << "// TRACTOR PROBLEM";
1954 Mlt::Tractor tractor(service);
1955 Mlt::Producer trackProducer(tractor.track(track));
1956 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1959 /* // Display playlist info
1960 kDebug()<<"//////////// BEFORE";
1961 for (int i = 0; i < trackPlaylist.count(); i++) {
1962 int blankStart = trackPlaylist.clip_start(i);
1963 int blankDuration = trackPlaylist.clip_length(i) - 1;
1965 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1966 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1969 int cutPos = (int) position.frames(m_fps);
1971 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1972 if (trackPlaylist.is_blank(clipIndex)) {
1973 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1977 int clipStart = trackPlaylist.clip_start(clipIndex);
1978 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1981 // duplicate effects
1982 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1983 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1985 if (original == NULL || clip == NULL) {
1986 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1990 Mlt::Service clipService(original->get_service());
1991 Mlt::Service dupService(clip->get_service());
1997 Mlt::Filter *filter = clipService.filter(ct);
1999 // Only duplicate Kdenlive filters, and skip the fade in effects
2000 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
2001 // looks like there is no easy way to duplicate a filter,
2002 // so we will create a new one and duplicate its properties
2003 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
2004 if (dup && dup->is_valid()) {
2005 Mlt::Properties entries(filter->get_properties());
2006 for (int i = 0; i < entries.count(); i++) {
2007 dup->set(entries.get_name(i), entries.get(i));
2009 dupService.attach(*dup);
2013 filter = clipService.filter(ct);
2016 /* // Display playlist info
2017 kDebug()<<"//////////// AFTER";
2018 for (int i = 0; i < trackPlaylist.count(); i++) {
2019 int blankStart = trackPlaylist.clip_start(i);
2020 int blankDuration = trackPlaylist.clip_length(i) - 1;
2022 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2023 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2028 Mlt::Tractor *Render::lockService()
2030 // we are going to replace some clips, purge consumer
2031 QMutexLocker locker(&m_mutex);
2032 if (!m_mltProducer) return NULL;
2033 if (m_mltConsumer) {
2034 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
2035 m_mltConsumer->purge();
2037 Mlt::Service service(m_mltProducer->parent().get_service());
2038 if (service.type() != tractor_type) {
2039 kWarning() << "// TRACTOR PROBLEM";
2043 return new Mlt::Tractor(service);
2047 void Render::unlockService(Mlt::Tractor *tractor)
2052 if (!m_mltProducer) return;
2053 Mlt::Service service(m_mltProducer->parent().get_service());
2054 if (service.type() != tractor_type) {
2055 kWarning() << "// TRACTOR PROBLEM";
2061 bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement element, Mlt::Producer *prod)
2064 if (prod == NULL || tractor == NULL) {
2065 kDebug() << "Cannot update clip with null producer //////";
2069 Mlt::Producer trackProducer(tractor->track(tractor->count() - 1 - info.track));
2070 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2071 int startPos = info.startPos.frames(m_fps);
2072 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2073 if (trackPlaylist.is_blank(clipIndex)) {
2074 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
2077 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2079 QList <Mlt::Filter *> filtersList;
2080 Mlt::Service sourceService(clip->get_service());
2082 Mlt::Filter *filter = sourceService.filter(ct);
2084 if (filter->get_int("kdenlive_ix") != 0) {
2085 filtersList.append(filter);
2088 filter = sourceService.filter(ct);
2091 clip = trackPlaylist.replace_with_blank(clipIndex);
2093 prod = checkSlowMotionProducer(prod, element);
2094 if (prod == NULL || !prod->is_valid()) {
2098 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
2099 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
2100 Mlt::Service destService(clip2->get_service());
2103 if (!filtersList.isEmpty()) {
2104 for (int i = 0; i < filtersList.count(); i++)
2105 destService.attach(*(filtersList.at(i)));
2111 bool Render::mltRemoveClip(int track, GenTime position)
2113 Mlt::Service service(m_mltProducer->parent().get_service());
2114 if (service.type() != tractor_type) {
2115 kWarning() << "// TRACTOR PROBLEM";
2119 Mlt::Tractor tractor(service);
2120 Mlt::Producer trackProducer(tractor.track(track));
2121 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2122 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2124 if (trackPlaylist.is_blank(clipIndex)) {
2125 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
2129 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2130 if (clip) delete clip;
2131 trackPlaylist.consolidate_blanks(0);
2133 /* // Display playlist info
2134 kDebug()<<"//// AFTER";
2135 for (int i = 0; i < trackPlaylist.count(); i++) {
2136 int blankStart = trackPlaylist.clip_start(i);
2137 int blankDuration = trackPlaylist.clip_length(i) - 1;
2139 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2140 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2143 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
2147 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
2149 if (!m_mltProducer) {
2150 kDebug() << "PLAYLIST NOT INITIALISED //////";
2153 Mlt::Producer parentProd(m_mltProducer->parent());
2154 if (parentProd.get_producer() == NULL) {
2155 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2159 Mlt::Service service(parentProd.get_service());
2160 Mlt::Tractor tractor(service);
2161 int insertPos = pos.frames(m_fps);
2163 Mlt::Producer trackProducer(tractor.track(track));
2164 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2165 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2166 if (clipIndex == trackPlaylist.count()) {
2167 // We are after the end of the playlist
2170 if (!trackPlaylist.is_blank(clipIndex)) return 0;
2171 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
2172 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
2175 int Render::mltTrackDuration(int track)
2177 if (!m_mltProducer) {
2178 kDebug() << "PLAYLIST NOT INITIALISED //////";
2181 Mlt::Producer parentProd(m_mltProducer->parent());
2182 if (parentProd.get_producer() == NULL) {
2183 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2187 Mlt::Service service(parentProd.get_service());
2188 Mlt::Tractor tractor(service);
2190 Mlt::Producer trackProducer(tractor.track(track));
2191 return trackProducer.get_playtime() - 1;
2194 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
2196 if (!m_mltProducer) {
2197 kDebug() << "PLAYLIST NOT INITIALISED //////";
2200 Mlt::Producer parentProd(m_mltProducer->parent());
2201 if (parentProd.get_producer() == NULL) {
2202 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2205 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
2206 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
2208 Mlt::Service service(parentProd.get_service());
2209 Mlt::Tractor tractor(service);
2211 int diff = duration.frames(m_fps);
2212 int offset = timeOffset.frames(m_fps);
2216 // insert space in one track only
2217 Mlt::Producer trackProducer(tractor.track(track));
2218 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2219 insertPos = trackClipStartList.value(track);
2220 if (insertPos != -1) {
2221 insertPos += offset;
2222 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2224 trackPlaylist.insert_blank(clipIndex, diff - 1);
2226 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
2227 if (!trackPlaylist.is_blank(clipIndex)) {
2228 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2230 int position = trackPlaylist.clip_start(clipIndex);
2231 int blankDuration = trackPlaylist.clip_length(clipIndex);
2232 if (blankDuration + diff == 0) {
2233 trackPlaylist.remove(clipIndex);
2234 } else trackPlaylist.remove_region(position, -diff);
2236 trackPlaylist.consolidate_blanks(0);
2238 // now move transitions
2239 mlt_service serv = m_mltProducer->parent().get_service();
2240 mlt_service nextservice = mlt_service_get_producer(serv);
2241 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2242 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2243 QString resource = mlt_properties_get(properties, "mlt_service");
2245 while (mlt_type == "transition") {
2246 mlt_transition tr = (mlt_transition) nextservice;
2247 int currentTrack = mlt_transition_get_b_track(tr);
2248 int currentIn = (int) mlt_transition_get_in(tr);
2249 int currentOut = (int) mlt_transition_get_out(tr);
2250 insertPos = trackTransitionStartList.value(track);
2251 if (insertPos != -1) {
2252 insertPos += offset;
2253 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
2254 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2257 nextservice = mlt_service_producer(nextservice);
2258 if (nextservice == NULL) break;
2259 properties = MLT_SERVICE_PROPERTIES(nextservice);
2260 mlt_type = mlt_properties_get(properties, "mlt_type");
2261 resource = mlt_properties_get(properties, "mlt_service");
2264 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
2265 Mlt::Producer trackProducer(tractor.track(trackNb));
2266 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2268 //int clipNb = trackPlaylist.count();
2269 insertPos = trackClipStartList.value(trackNb);
2270 if (insertPos != -1) {
2271 insertPos += offset;
2273 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2274 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2275 for (int i = 0; i < clipNb; i++) {
2276 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2277 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2278 kDebug()<<"-------------";
2280 kDebug()<<"END-------------";*/
2283 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2285 trackPlaylist.insert_blank(clipIndex, diff - 1);
2287 if (!trackPlaylist.is_blank(clipIndex)) {
2290 if (!trackPlaylist.is_blank(clipIndex)) {
2291 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2293 int position = trackPlaylist.clip_start(clipIndex);
2294 int blankDuration = trackPlaylist.clip_length(clipIndex);
2295 if (diff + blankDuration == 0) {
2296 trackPlaylist.remove(clipIndex);
2297 } else trackPlaylist.remove_region(position, - diff);
2299 trackPlaylist.consolidate_blanks(0);
2302 // now move transitions
2303 mlt_service serv = m_mltProducer->parent().get_service();
2304 mlt_service nextservice = mlt_service_get_producer(serv);
2305 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2306 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2307 QString resource = mlt_properties_get(properties, "mlt_service");
2309 while (mlt_type == "transition") {
2310 mlt_transition tr = (mlt_transition) nextservice;
2311 int currentIn = (int) mlt_transition_get_in(tr);
2312 int currentOut = (int) mlt_transition_get_out(tr);
2313 int currentTrack = mlt_transition_get_b_track(tr);
2314 insertPos = trackTransitionStartList.value(currentTrack);
2315 if (insertPos != -1) {
2316 insertPos += offset;
2317 if (currentOut > insertPos && resource != "mix") {
2318 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2321 nextservice = mlt_service_producer(nextservice);
2322 if (nextservice == NULL) break;
2323 properties = MLT_SERVICE_PROPERTIES(nextservice);
2324 mlt_type = mlt_properties_get(properties, "mlt_type");
2325 resource = mlt_properties_get(properties, "mlt_service");
2329 mltCheckLength(&tractor);
2330 m_mltConsumer->set("refresh", 1);
2334 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2336 if (source == dest) return;
2337 Mlt::Service sourceService(source->get_service());
2338 Mlt::Service destService(dest->get_service());
2340 // move all effects to the correct producer
2342 Mlt::Filter *filter = sourceService.filter(ct);
2344 if (filter->get_int("kdenlive_ix") != 0) {
2345 sourceService.detach(*filter);
2346 destService.attach(*filter);
2348 filter = sourceService.filter(ct);
2352 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2355 Mlt::Service service(m_mltProducer->parent().get_service());
2356 if (service.type() != tractor_type) {
2357 kWarning() << "// TRACTOR PROBLEM";
2361 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2362 Mlt::Tractor tractor(service);
2363 Mlt::Producer trackProducer(tractor.track(info.track));
2364 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2365 int startPos = info.startPos.frames(m_fps);
2366 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2367 int clipLength = trackPlaylist.clip_length(clipIndex);
2369 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2370 if (original == NULL) {
2373 if (!original->is_valid() || original->is_blank()) {
2378 Mlt::Producer clipparent = original->parent();
2379 if (!clipparent.is_valid() || clipparent.is_blank()) {
2385 QString serv = clipparent.get("mlt_service");
2386 QString id = clipparent.get("id");
2387 if (speed <= 0 && speed > -1) speed = 1.0;
2388 //kDebug() << "CLIP SERVICE: " << serv;
2389 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2391 QString url = QString::fromUtf8(clipparent.get("resource"));
2392 url.append('?' + m_locale.toString(speed));
2393 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2394 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2395 if (!slowprod || slowprod->get_producer() == NULL) {
2396 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2397 if (strobe > 1) slowprod->set("strobe", strobe);
2398 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2399 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2400 slowprod->set("id", producerid.toUtf8().constData());
2401 // copy producer props
2402 double ar = original->parent().get_double("force_aspect_ratio");
2403 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2404 double fps = original->parent().get_double("force_fps");
2405 if (fps != 0.0) slowprod->set("force_fps", fps);
2406 int threads = original->parent().get_int("threads");
2407 if (threads != 0) slowprod->set("threads", threads);
2408 if (original->parent().get("force_progressive"))
2409 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2410 if (original->parent().get("force_tff"))
2411 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2412 int ix = original->parent().get_int("video_index");
2413 if (ix != 0) slowprod->set("video_index", ix);
2414 int colorspace = original->parent().get_int("force_colorspace");
2415 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2416 int full_luma = original->parent().get_int("set.force_full_luma");
2417 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2418 m_slowmotionProducers.insert(url, slowprod);
2420 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2421 trackPlaylist.consolidate_blanks(0);
2423 // Check that the blank space is long enough for our new duration
2424 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2425 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2427 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2428 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2429 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2430 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2432 // move all effects to the correct producer
2433 mltPasteEffects(clip, cut);
2434 trackPlaylist.insert_at(startPos, cut, 1);
2437 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2438 newLength = trackPlaylist.clip_length(clipIndex);
2440 } else if (speed == 1.0 && strobe < 2) {
2443 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2444 trackPlaylist.consolidate_blanks(0);
2446 // Check that the blank space is long enough for our new duration
2447 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2448 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2451 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2452 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2453 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2454 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2455 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2457 // move all effects to the correct producer
2458 mltPasteEffects(clip, cut);
2460 trackPlaylist.insert_at(startPos, cut, 1);
2463 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2464 newLength = trackPlaylist.clip_length(clipIndex);
2467 } else if (serv == "framebuffer") {
2469 QString url = QString::fromUtf8(clipparent.get("resource"));
2470 url = url.section('?', 0, 0);
2471 url.append('?' + m_locale.toString(speed));
2472 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2473 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2474 if (!slowprod || slowprod->get_producer() == NULL) {
2475 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2476 slowprod->set("strobe", strobe);
2477 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2478 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2479 slowprod->set("id", producerid.toUtf8().constData());
2480 // copy producer props
2481 double ar = original->parent().get_double("force_aspect_ratio");
2482 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2483 double fps = original->parent().get_double("force_fps");
2484 if (fps != 0.0) slowprod->set("force_fps", fps);
2485 if (original->parent().get("force_progressive"))
2486 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2487 if (original->parent().get("force_tff"))
2488 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2489 int threads = original->parent().get_int("threads");
2490 if (threads != 0) slowprod->set("threads", threads);
2491 int ix = original->parent().get_int("video_index");
2492 if (ix != 0) slowprod->set("video_index", ix);
2493 int colorspace = original->parent().get_int("force_colorspace");
2494 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2495 int full_luma = original->parent().get_int("set.force_full_luma");
2496 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2497 m_slowmotionProducers.insert(url, slowprod);
2499 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2500 trackPlaylist.consolidate_blanks(0);
2502 GenTime duration = speedIndependantInfo.cropDuration / speed;
2503 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2505 // Check that the blank space is long enough for our new duration
2506 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2507 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2510 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2511 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2512 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2513 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2515 // move all effects to the correct producer
2516 mltPasteEffects(clip, cut);
2518 trackPlaylist.insert_at(startPos, cut, 1);
2521 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2522 newLength = trackPlaylist.clip_length(clipIndex);
2527 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2531 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2533 Mlt::Service service(m_mltProducer->parent().get_service());
2534 bool success = false;
2535 Mlt::Tractor tractor(service);
2536 Mlt::Producer trackProducer(tractor.track(track));
2537 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2538 Mlt::Service clipService(trackPlaylist.get_service());
2542 Mlt::Filter *filter = clipService.filter(ct);
2544 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2545 if (clipService.detach(*filter) == 0) success = true;
2546 } else if (updateIndex) {
2547 // Adjust the other effects index
2548 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2551 filter = clipService.filter(ct);
2558 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2560 if (position < GenTime()) {
2561 // Remove track effect
2562 return mltRemoveTrackEffect(track, index, updateIndex);
2564 Mlt::Service service(m_mltProducer->parent().get_service());
2565 bool success = false;
2566 Mlt::Tractor tractor(service);
2567 Mlt::Producer trackProducer(tractor.track(track));
2568 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2570 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2571 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2573 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2577 Mlt::Service clipService(clip->get_service());
2578 int duration = clip->get_playtime();
2580 // Check if clip is visible in monitor
2581 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2582 if (diff < 0 || diff > duration) doRefresh = false;
2588 Mlt::Filter *filter = clipService.filter(ct);
2590 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2591 if (clipService.detach(*filter) == 0) success = true;
2592 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2593 } else if (updateIndex) {
2594 // Adjust the other effects index
2595 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2598 filter = clipService.filter(ct);
2601 if (doRefresh) refresh();
2605 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2607 Mlt::Service service(m_mltProducer->parent().get_service());
2608 Mlt::Tractor tractor(service);
2609 Mlt::Producer trackProducer(tractor.track(track));
2610 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2611 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2612 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2616 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2619 Mlt::Service service(m_mltProducer->parent().get_service());
2621 Mlt::Tractor tractor(service);
2622 Mlt::Producer trackProducer(tractor.track(track));
2623 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2625 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2626 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2631 Mlt::Service clipService(clip->get_service());
2632 int duration = clip->get_playtime();
2634 // Check if clip is visible in monitor
2635 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2636 if (diff < 0 || diff > duration) doRefresh = false;
2639 return mltAddEffect(clipService, params, duration, doRefresh);
2642 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2644 bool updateIndex = false;
2645 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2649 Mlt::Filter *filter = service.filter(ct);
2651 if (filter->get_int("kdenlive_ix") == filter_ix) {
2652 // A filter at that position already existed, so we will increase all indexes later
2657 filter = service.filter(ct);
2660 if (params.paramValue("id") == "speed") {
2661 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2663 filter = service.filter(ct);
2665 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2666 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2669 filter = service.filter(ct);
2672 if (doRefresh) refresh();
2677 // temporarily remove all effects after insert point
2678 QList <Mlt::Filter *> filtersList;
2680 filter = service.filter(ct);
2682 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2683 filtersList.append(filter);
2684 service.detach(*filter);
2686 filter = service.filter(ct);
2689 addFilterToService(service, params, duration);
2691 // re-add following filters
2692 for (int i = 0; i < filtersList.count(); i++) {
2693 Mlt::Filter *filter = filtersList.at(i);
2695 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2696 service.attach(*filter);
2699 if (doRefresh) refresh();
2704 bool Render::addFilterToService(Mlt::Service service, EffectsParameterList params, int duration)
2707 QString tag = params.paramValue("tag");
2708 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2709 char *filterTag = qstrdup(tag.toUtf8().constData());
2710 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2711 QString kfr = params.paramValue("keyframes");
2712 if (!kfr.isEmpty()) {
2713 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2714 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2715 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2716 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2717 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2718 //double max = params.paramValue("max").toDouble();
2719 double min = params.paramValue("min").toDouble();
2720 double factor = params.paramValue("factor", "1").toDouble();
2721 double paramOffset = params.paramValue("offset", "0").toDouble();
2722 params.removeParam("starttag");
2723 params.removeParam("endtag");
2724 params.removeParam("keyframes");
2725 params.removeParam("min");
2726 params.removeParam("max");
2727 params.removeParam("factor");
2728 params.removeParam("offset");
2730 // Special case, only one keyframe, means we want a constant value
2731 if (keyFrames.count() == 1) {
2732 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2733 if (filter && filter->is_valid()) {
2734 filter->set("kdenlive_id", filterId);
2735 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2736 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2737 for (int j = 0; j < params.count(); j++) {
2738 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2740 filter->set("in", x1);
2741 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2742 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2743 service.attach(*filter);
2745 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2746 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2747 if (filter && filter->is_valid()) {
2748 filter->set("kdenlive_id", filterId);
2749 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2750 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2751 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2752 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2753 if (x2 == -1) x2 = duration;
2755 for (int j = 0; j < params.count(); j++) {
2756 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2759 filter->set("in", x1);
2760 filter->set("out", x2);
2761 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2762 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2763 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2764 service.attach(*filter);
2771 Mlt::Filter *filter;
2773 filter = new Mlt::Filter(*m_mltProfile, filterTag);
2774 if (filter && filter->is_valid()) {
2775 filter->set("kdenlive_id", filterId);
2777 kDebug() << "filter is NULL";
2781 params.removeParam("kdenlive_id");
2782 if (params.hasParam("_sync_in_out")) {
2783 // This effect must sync in / out with parent clip
2784 params.removeParam("_sync_in_out");
2785 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2788 for (int j = 0; j < params.count(); j++) {
2789 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2793 QString effectArgs = params.paramValue("id").section('_', 1);
2795 params.removeParam("id");
2796 params.removeParam("kdenlive_ix");
2797 params.removeParam("tag");
2798 params.removeParam("disable");
2799 params.removeParam("region");
2801 for (int j = 0; j < params.count(); j++) {
2802 effectArgs.append(' ' + params.at(j).value());
2804 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2805 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2807 // attach filter to the clip
2808 service.attach(*filter);
2816 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2818 Mlt::Service service(m_mltProducer->parent().get_service());
2819 Mlt::Tractor tractor(service);
2820 Mlt::Producer trackProducer(tractor.track(track));
2821 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2822 Mlt::Service clipService(trackPlaylist.get_service());
2824 QString index = params.paramValue("kdenlive_ix");
2825 QString tag = params.paramValue("tag");
2827 Mlt::Filter *filter = clipService.filter(ct);
2829 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2833 filter = clipService.filter(ct);
2837 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2838 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2840 bool success = false;//mltAddTrackEffect(track, params);
2844 QString ser = filter->get("mlt_service");
2845 if (ser == "region") prefix = "filter0.";
2847 for (int j = 0; j < params.count(); j++) {
2848 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2856 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2858 int index = params.paramValue("kdenlive_ix").toInt();
2859 QString tag = params.paramValue("tag");
2861 if (!params.paramValue("keyframes").isEmpty() || (tag == "affine" && params.hasParam("background")) || tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2862 // This is a keyframe effect, to edit it, we remove it and re-add it.
2863 bool success = mltRemoveEffect(track, position, index, false);
2864 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
2865 if (position < GenTime())
2866 success = mltAddTrackEffect(track, params);
2868 success = mltAddEffect(track, position, params);
2869 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
2872 if (position < GenTime()) {
2873 return mltEditTrackEffect(track, params);
2876 Mlt::Service service(m_mltProducer->parent().get_service());
2877 Mlt::Tractor tractor(service);
2878 Mlt::Producer trackProducer(tractor.track(track));
2879 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2881 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2882 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2884 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2888 int duration = clip->get_playtime();
2889 bool doRefresh = true;
2890 // Check if clip is visible in monitor
2891 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2892 if (diff < 0 || diff > duration)
2896 Mlt::Filter *filter = clip->filter(ct);
2898 if (filter->get_int("kdenlive_ix") == index) {
2902 filter = clip->filter(ct);
2906 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2907 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2909 bool success = mltAddEffect(track, position, params);
2913 QString ser = filter->get("mlt_service");
2914 QList <Mlt::Filter *> filtersList;
2917 // Effect service changes, delete effect and re-add it
2918 clip->detach(*filter);
2920 // Delete all effects after deleted one
2921 filter = clip->filter(ct);
2923 if (filter->get_int("kdenlive_ix") > index) {
2924 filtersList.append(filter);
2925 clip->detach(*filter);
2928 filter = clip->filter(ct);
2932 addFilterToService(*clip, params, clip->get_playtime());
2936 if (doRefresh) refresh();
2939 if (params.hasParam("_sync_in_out")) {
2940 // This effect must sync in / out with parent clip
2941 params.removeParam("_sync_in_out");
2942 filter->set_in_and_out(clip->get_in(), clip->get_out());
2945 for (int j = 0; j < params.count(); j++) {
2946 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2949 for (int j = 0; j < filtersList.count(); j++) {
2950 clip->attach(*(filtersList.at(j)));
2956 if (doRefresh) refresh();
2960 bool Render::mltEnableEffects(int track, GenTime position, QList <int> effectIndexes, bool disable)
2962 if (position < GenTime()) {
2963 return mltEnableTrackEffects(track, effectIndexes, disable);
2966 Mlt::Service service(m_mltProducer->parent().get_service());
2967 Mlt::Tractor tractor(service);
2968 Mlt::Producer trackProducer(tractor.track(track));
2969 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2971 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2972 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2974 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2978 int duration = clip->get_playtime();
2979 bool doRefresh = true;
2980 // Check if clip is visible in monitor
2981 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2982 if (diff < 0 || diff > duration)
2986 Mlt::Filter *filter = clip->filter(ct);
2988 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
2989 filter->set("disable", (int) disable);
2992 filter = clip->filter(ct);
2998 if (doRefresh) refresh();
3002 bool Render::mltEnableTrackEffects(int track, QList <int> effectIndexes, bool disable)
3004 Mlt::Service service(m_mltProducer->parent().get_service());
3005 Mlt::Tractor tractor(service);
3006 Mlt::Producer trackProducer(tractor.track(track));
3007 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3008 Mlt::Service clipService(trackPlaylist.get_service());
3011 Mlt::Filter *filter = clipService.filter(ct);
3013 if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
3014 filter->set("disable", (int) disable);
3017 filter = clipService.filter(ct);
3025 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
3027 Mlt::Service service(m_mltProducer->parent().get_service());
3028 Mlt::Tractor tractor(service);
3029 Mlt::Producer trackProducer(tractor.track(track));
3030 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3032 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3033 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3035 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3039 Mlt::Service clipService(clip->get_service());
3040 int duration = clip->get_playtime();
3041 bool doRefresh = true;
3042 // Check if clip is visible in monitor
3043 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3044 if (diff < 0 || diff > duration) doRefresh = false;
3048 Mlt::Filter *filter = clipService.filter(ct);
3050 int pos = filter->get_int("kdenlive_ix");
3051 if (pos == oldPos) {
3052 filter->set("kdenlive_ix", newPos);
3054 filter = clipService.filter(ct);
3056 if (doRefresh) refresh();
3059 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
3061 if (position < GenTime()) {
3062 mltMoveTrackEffect(track, oldPos, newPos);
3065 Mlt::Service service(m_mltProducer->parent().get_service());
3066 Mlt::Tractor tractor(service);
3067 Mlt::Producer trackProducer(tractor.track(track));
3068 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3070 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
3071 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3073 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
3077 Mlt::Service clipService(clip->get_service());
3078 int duration = clip->get_playtime();
3079 bool doRefresh = true;
3080 // Check if clip is visible in monitor
3081 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
3082 if (diff < 0 || diff > duration) doRefresh = false;
3086 QList <Mlt::Filter *> filtersList;
3087 Mlt::Filter *filter = clipService.filter(ct);
3089 if (newPos > oldPos) {
3091 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3092 filter->set("kdenlive_ix", newPos);
3093 filtersList.append(filter);
3094 clipService.detach(*filter);
3095 filter = clipService.filter(ct);
3096 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3097 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3099 filter = clipService.filter(ct);
3103 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3104 filtersList.append(filter);
3105 clipService.detach(*filter);
3107 filter = clipService.filter(ct);
3111 if (filter->get_int("kdenlive_ix") == oldPos) {
3112 filter->set("kdenlive_ix", newPos);
3113 filtersList.append(filter);
3114 clipService.detach(*filter);
3116 filter = clipService.filter(ct);
3120 filter = clipService.filter(ct);
3122 int pos = filter->get_int("kdenlive_ix");
3123 if (pos >= newPos) {
3124 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3125 filtersList.append(filter);
3126 clipService.detach(*filter);
3128 filter = clipService.filter(ct);
3132 for (int i = 0; i < filtersList.count(); i++) {
3133 clipService.attach(*(filtersList.at(i)));
3136 if (doRefresh) refresh();
3139 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
3141 Mlt::Service service(m_mltProducer->parent().get_service());
3142 Mlt::Tractor tractor(service);
3143 Mlt::Producer trackProducer(tractor.track(track));
3144 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3145 Mlt::Service clipService(trackPlaylist.get_service());
3147 QList <Mlt::Filter *> filtersList;
3148 Mlt::Filter *filter = clipService.filter(ct);
3150 if (newPos > oldPos) {
3152 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
3153 filter->set("kdenlive_ix", newPos);
3154 filtersList.append(filter);
3155 clipService.detach(*filter);
3156 filter = clipService.filter(ct);
3157 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
3158 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
3160 filter = clipService.filter(ct);
3164 if (filter && filter->get_int("kdenlive_ix") > newPos) {
3165 filtersList.append(filter);
3166 clipService.detach(*filter);
3168 filter = clipService.filter(ct);
3172 if (filter->get_int("kdenlive_ix") == oldPos) {
3173 filter->set("kdenlive_ix", newPos);
3174 filtersList.append(filter);
3175 clipService.detach(*filter);
3177 filter = clipService.filter(ct);
3181 filter = clipService.filter(ct);
3183 int pos = filter->get_int("kdenlive_ix");
3184 if (pos >= newPos) {
3185 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
3186 filtersList.append(filter);
3187 clipService.detach(*filter);
3189 filter = clipService.filter(ct);
3193 for (int i = 0; i < filtersList.count(); i++) {
3194 clipService.attach(*(filtersList.at(i)));
3199 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
3201 Mlt::Service service(m_mltProducer->parent().get_service());
3202 Mlt::Tractor tractor(service);
3203 Mlt::Producer trackProducer(tractor.track(info.track));
3204 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3206 /* // Display playlist info
3207 kDebug()<<"//////////// BEFORE RESIZE";
3208 for (int i = 0; i < trackPlaylist.count(); i++) {
3209 int blankStart = trackPlaylist.clip_start(i);
3210 int blankDuration = trackPlaylist.clip_length(i) - 1;
3212 if (trackPlaylist.is_blank(i)) blk = "(blank)";
3213 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
3216 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
3217 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3221 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
3222 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
3223 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3225 int previousStart = clip->get_in();
3226 int newDuration = (int) clipDuration.frames(m_fps) - 1;
3227 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
3229 int currentOut = newDuration + previousStart;
3230 if (currentOut > clip->get_length()) {
3231 clip->parent().set("length", currentOut + 1);
3232 clip->parent().set("out", currentOut);
3233 clip->set("length", currentOut + 1);
3236 /*if (newDuration > clip->get_out()) {
3237 clip->parent().set_in_and_out(0, newDuration + 1);
3238 clip->set_in_and_out(0, newDuration + 1);
3241 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
3242 trackPlaylist.consolidate_blanks(0);
3243 // skip to next clip
3245 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
3247 // clip was made longer, trim next blank if there is one.
3248 if (clipIndex < trackPlaylist.count()) {
3249 // If this is not the last clip in playlist
3250 if (trackPlaylist.is_blank(clipIndex)) {
3251 int blankStart = trackPlaylist.clip_start(clipIndex);
3252 int blankDuration = trackPlaylist.clip_length(clipIndex);
3253 if (diff > blankDuration) {
3254 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
3256 if (diff - blankDuration == 0) {
3257 trackPlaylist.remove(clipIndex);
3258 } else trackPlaylist.remove_region(blankStart, diff);
3260 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
3263 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
3264 trackPlaylist.consolidate_blanks(0);
3267 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
3268 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3269 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
3270 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3271 ItemInfo transpinfo;
3272 transpinfo.startPos = info.startPos;
3273 transpinfo.endPos = info.startPos + clipDuration;
3274 transpinfo.track = info.track;
3275 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3277 m_mltConsumer->set("refresh", 1);
3281 void Render::mltChangeTrackState(int track, bool mute, bool blind)
3283 Mlt::Service service(m_mltProducer->parent().get_service());
3284 Mlt::Tractor tractor(service);
3285 Mlt::Producer trackProducer(tractor.track(track));
3287 // Make sure muting will not produce problems with our audio mixing transition,
3288 // because audio mixing is done between each track and the lowest one
3289 bool audioMixingBroken = false;
3290 if (mute && trackProducer.get_int("hide") < 2 ) {
3291 // We mute a track with sound
3292 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3293 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
3295 else if (!mute && trackProducer.get_int("hide") > 1 ) {
3296 // We un-mute a previously muted track
3297 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3301 if (blind) trackProducer.set("hide", 3);
3302 else trackProducer.set("hide", 2);
3304 trackProducer.set("hide", 1);
3306 trackProducer.set("hide", 0);
3308 if (audioMixingBroken) fixAudioMixing(tractor);
3310 tractor.multitrack()->refresh();
3315 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
3317 for (int i = 1; i < tractor.count(); i++) {
3318 Mlt::Producer trackProducer(tractor.track(i));
3319 if (trackProducer.get_int("hide") < 2) return i;
3321 return tractor.count() - 1;
3324 void Render::fixAudioMixing(Mlt::Tractor tractor)
3326 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
3327 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
3329 mlt_service serv = m_mltProducer->parent().get_service();
3330 Mlt::Field *field = tractor.field();
3331 mlt_service_lock(serv);
3333 mlt_service nextservice = mlt_service_get_producer(serv);
3334 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3335 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3336 QString resource = mlt_properties_get(properties, "mlt_service");
3338 mlt_service nextservicetodisconnect;
3339 // Delete all audio mixing transitions
3340 while (mlt_type == "transition") {
3341 if (resource == "mix") {
3342 nextservicetodisconnect = nextservice;
3343 nextservice = mlt_service_producer(nextservice);
3344 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
3346 else nextservice = mlt_service_producer(nextservice);
3347 if (nextservice == NULL) break;
3348 properties = MLT_SERVICE_PROPERTIES(nextservice);
3349 mlt_type = mlt_properties_get(properties, "mlt_type");
3350 resource = mlt_properties_get(properties, "mlt_service");
3353 // Re-add correct audio transitions
3354 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
3355 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3356 transition->set("always_active", 1);
3357 transition->set("combine", 1);
3358 transition->set("internal_added", 237);
3359 field->plant_transition(*transition, lowestTrack, i);
3361 mlt_service_unlock(serv);
3364 bool Render::mltResizeClipCrop(ItemInfo info, GenTime newCropStart)
3366 Mlt::Service service(m_mltProducer->parent().get_service());
3367 int newCropFrame = (int) newCropStart.frames(m_fps);
3368 Mlt::Tractor tractor(service);
3369 Mlt::Producer trackProducer(tractor.track(info.track));
3370 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3371 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3372 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3376 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3377 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3379 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3383 int previousStart = clip->get_in();
3384 int previousOut = clip->get_out();
3386 if (previousStart == newCropFrame) {
3387 kDebug() << "//////// No ReSIZING Required";
3391 int frameOffset = newCropFrame - previousStart;
3392 trackPlaylist.resize_clip(clipIndex, newCropFrame, previousOut + frameOffset);
3394 m_mltConsumer->set("refresh", 1);
3398 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3400 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3401 Mlt::Service service(m_mltProducer->parent().get_service());
3402 int moveFrame = (int) diff.frames(m_fps);
3403 Mlt::Tractor tractor(service);
3404 Mlt::Producer trackProducer(tractor.track(info.track));
3405 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3406 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3407 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3411 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3412 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3413 if (clip == NULL || clip->is_blank()) {
3414 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3418 int previousStart = clip->get_in();
3419 int previousOut = clip->get_out();
3421 previousStart += moveFrame;
3423 if (previousStart < 0) {
3424 // this is possible for images and color clips
3425 previousOut -= previousStart;
3429 int length = previousOut + 1;
3430 if (length > clip->get_length()) {
3431 clip->parent().set("length", length + 1);
3432 clip->parent().set("out", length);
3433 clip->set("length", length + 1);
3437 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3438 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3439 if (moveFrame > 0) {
3440 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3442 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3443 int blankIndex = clipIndex - 1;
3444 int blankLength = trackPlaylist.clip_length(blankIndex);
3445 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3446 if (! trackPlaylist.is_blank(blankIndex)) {
3447 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3449 if (blankLength + moveFrame == 0)
3450 trackPlaylist.remove(blankIndex);
3452 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3454 trackPlaylist.consolidate_blanks(0);
3455 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3456 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3457 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3458 ItemInfo transpinfo;
3459 transpinfo.startPos = info.startPos + diff;
3460 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3461 transpinfo.track = info.track;
3462 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3464 //m_mltConsumer->set("refresh", 1);
3466 m_mltConsumer->set("refresh", 1);
3470 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3472 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3476 bool Render::mltUpdateClipProducer(Mlt::Tractor *tractor, int track, int pos, Mlt::Producer *prod)
3478 if (prod == NULL || !prod->is_valid() || tractor == NULL || !tractor->is_valid()) {
3479 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3483 Mlt::Producer trackProducer(tractor->track(track));
3484 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3485 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3486 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3487 if (clipProducer == NULL || clipProducer->is_blank()) {
3488 kDebug() << "// ERROR UPDATING CLIP PROD";
3489 delete clipProducer;
3492 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3493 if (!clip || !clip->is_valid()) {
3494 if (clip) delete clip;
3495 delete clipProducer;
3498 // move all effects to the correct producer
3499 mltPasteEffects(clipProducer, clip);
3500 trackPlaylist.insert_at(pos, clip, 1);
3502 delete clipProducer;
3506 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3508 Mlt::Service service(m_mltProducer->parent().get_service());
3509 if (service.type() != tractor_type) {
3510 kWarning() << "// TRACTOR PROBLEM";
3514 Mlt::Tractor tractor(service);
3516 Mlt::Producer trackProducer(tractor.track(startTrack));
3517 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3518 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3519 int clipDuration = trackPlaylist.clip_length(clipIndex);
3520 bool checkLength = false;
3521 if (endTrack == startTrack) {
3522 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3524 bool success = true;
3525 if (!trackPlaylist.is_blank_at(moveEnd) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3529 // Check that the destination region is empty
3530 trackPlaylist.consolidate_blanks(0);
3531 int destinationIndex = trackPlaylist.get_clip_index_at(moveEnd);
3532 if (destinationIndex < trackPlaylist.count() - 1) {
3533 // We are not at the end of the track
3534 int blankSize = trackPlaylist.blanks_from(destinationIndex, 1);
3535 // Make sure we have enough place to insert clip
3536 if (blankSize - clipDuration - (moveEnd - trackPlaylist.clip_start(destinationIndex)) < 0) success = false;
3541 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3542 delete clipProducer;
3544 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3551 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3552 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3553 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3555 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3556 if (newIndex == -1) {
3557 kDebug()<<"// CANNOT MOVE CLIP TO: "<<moveEnd;
3558 trackPlaylist.insert_at(moveStart, clipProducer, 1);
3559 delete clipProducer;
3563 trackPlaylist.consolidate_blanks(1);
3564 delete clipProducer;
3565 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3567 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3568 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3569 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3570 // error, destination is not empty
3571 kDebug() << "Cannot move: Destination is not empty";
3575 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3576 if (!clipProducer || clipProducer->is_blank()) {
3577 // error, destination is not empty
3578 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3579 if (clipProducer) delete clipProducer;
3580 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3584 trackPlaylist.consolidate_blanks(0);
3585 destTrackPlaylist.consolidate_blanks(1);
3586 Mlt::Producer *clip;
3587 // check if we are moving a slowmotion producer
3588 QString serv = clipProducer->parent().get("mlt_service");
3589 QString currentid = clipProducer->parent().get("id");
3590 if (serv == "framebuffer") {
3591 clip = clipProducer;
3594 // Special case: prod is null when using placeholder clips.
3595 // in that case, use the producer existing in playlist. Note that
3596 // it will bypass the one producer per track logic and might cause
3597 // Sound cracks if clip is moved so that it overlaps another copy of itself
3598 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3599 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3602 // move all effects to the correct producer
3603 mltPasteEffects(clipProducer, clip);
3606 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3607 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3608 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3611 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3613 if (clip == clipProducer) {
3618 delete clipProducer;
3620 destTrackPlaylist.consolidate_blanks(0);
3621 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3622 kDebug() << "//////// moving clip transparency";
3623 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3625 if (clipIndex > trackPlaylist.count()) checkLength = true;
3626 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3630 if (checkLength) mltCheckLength(&tractor);
3632 //m_mltConsumer->set("refresh", 1);
3637 QList <int> Render::checkTrackSequence(int track)
3640 Mlt::Service service(m_mltProducer->parent().get_service());
3641 if (service.type() != tractor_type) {
3642 kWarning() << "// TRACTOR PROBLEM";
3645 Mlt::Tractor tractor(service);
3647 Mlt::Producer trackProducer(tractor.track(track));
3648 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3649 int clipNb = trackPlaylist.count();
3650 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3651 for (int i = 0; i < clipNb; i++) {
3652 Mlt::Producer *c = trackPlaylist.get_clip(i);
3653 int pos = trackPlaylist.clip_start(i);
3654 if (!list.contains(pos)) list.append(pos);
3655 pos += c->get_playtime();
3656 if (!list.contains(pos)) list.append(pos);
3662 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3664 int new_in = (int)newIn.frames(m_fps);
3665 int new_out = (int)newOut.frames(m_fps) - 1;
3666 if (new_in >= new_out) return false;
3667 int old_in = (int)oldIn.frames(m_fps);
3668 int old_out = (int)oldOut.frames(m_fps) - 1;
3670 Mlt::Service service(m_mltProducer->parent().get_service());
3671 Mlt::Tractor tractor(service);
3672 Mlt::Field *field = tractor.field();
3674 bool doRefresh = true;
3675 // Check if clip is visible in monitor
3676 int diff = old_out - m_mltProducer->position();
3677 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3679 diff = new_out - m_mltProducer->position();
3680 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3684 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3685 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3686 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3687 QString resource = mlt_properties_get(properties, "mlt_service");
3688 int old_pos = (int)(old_in + old_out) / 2;
3691 while (mlt_type == "transition") {
3692 Mlt::Transition transition((mlt_transition) nextservice);
3693 nextservice = mlt_service_producer(nextservice);
3694 int currentTrack = transition.get_b_track();
3695 int currentIn = (int) transition.get_in();
3696 int currentOut = (int) transition.get_out();
3698 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3700 if (newTrack - startTrack != 0) {
3701 Mlt::Properties trans_props(transition.get_properties());
3702 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3703 Mlt::Properties new_trans_props(new_transition.get_properties());
3704 new_trans_props.inherit(trans_props);
3705 new_transition.set_in_and_out(new_in, new_out);
3706 field->disconnect_service(transition);
3707 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3708 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3709 } else transition.set_in_and_out(new_in, new_out);
3712 if (nextservice == NULL) break;
3713 properties = MLT_SERVICE_PROPERTIES(nextservice);
3714 mlt_type = mlt_properties_get(properties, "mlt_type");
3715 resource = mlt_properties_get(properties, "mlt_service");
3718 if (doRefresh) refresh();
3719 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3724 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3726 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3727 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3728 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3729 QString resource = mlt_properties_get(properties, "mlt_service");
3730 QList <Mlt::Transition *> trList;
3731 mlt_properties insertproperties = tr.get_properties();
3732 QString insertresource = mlt_properties_get(insertproperties, "mlt_service");
3733 bool isMixTransition = insertresource == "mix";
3735 while (mlt_type == "transition") {
3736 Mlt::Transition transition((mlt_transition) nextservice);
3737 nextservice = mlt_service_producer(nextservice);
3738 int aTrack = transition.get_a_track();
3739 int bTrack = transition.get_b_track();
3740 if ((isMixTransition || resource != "mix") && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3741 Mlt::Properties trans_props(transition.get_properties());
3742 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3743 Mlt::Properties new_trans_props(cp->get_properties());
3744 new_trans_props.inherit(trans_props);
3746 field->disconnect_service(transition);
3748 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3750 if (nextservice == NULL) break;
3751 properties = MLT_SERVICE_PROPERTIES(nextservice);
3752 mlt_type = mlt_properties_get(properties, "mlt_type");
3753 resource = mlt_properties_get(properties, "mlt_service");
3755 field->plant_transition(tr, a_track, b_track);
3757 // re-add upper transitions
3758 for (int i = trList.count() - 1; i >= 0; i--) {
3759 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3760 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3765 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3767 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3769 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3770 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3771 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3774 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3777 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3779 mlt_service serv = m_mltProducer->parent().get_service();
3780 mlt_service_lock(serv);
3782 mlt_service nextservice = mlt_service_get_producer(serv);
3783 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3784 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3785 QString resource = mlt_properties_get(properties, "mlt_service");
3786 int in_pos = (int) in.frames(m_fps);
3787 int out_pos = (int) out.frames(m_fps) - 1;
3789 while (mlt_type == "transition") {
3790 mlt_transition tr = (mlt_transition) nextservice;
3791 int currentTrack = mlt_transition_get_b_track(tr);
3792 int currentBTrack = mlt_transition_get_a_track(tr);
3793 int currentIn = (int) mlt_transition_get_in(tr);
3794 int currentOut = (int) mlt_transition_get_out(tr);
3796 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3797 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3798 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3799 QMap<QString, QString>::Iterator it;
3801 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3803 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3804 if (currentId != xml.attribute("id")) {
3805 // The transition ID is not the same, so reset all properties
3806 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3807 // Cleanup previous properties
3808 QStringList permanentProps;
3809 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3810 permanentProps << "out" << "a_track" << "b_track";
3811 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3812 QString propName = mlt_properties_get_name(transproperties, i);
3813 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3814 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3819 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3820 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3822 if (currentBTrack != a_track) {
3823 mlt_properties_set_int(transproperties, "a_track", a_track);
3825 for (it = map.begin(); it != map.end(); ++it) {
3827 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3828 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3829 //filter->set("kdenlive_id", id);
3833 nextservice = mlt_service_producer(nextservice);
3834 if (nextservice == NULL) break;
3835 properties = MLT_SERVICE_PROPERTIES(nextservice);
3836 mlt_type = mlt_properties_get(properties, "mlt_type");
3837 resource = mlt_properties_get(properties, "mlt_service");
3839 mlt_service_unlock(serv);
3841 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3844 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3846 mlt_service serv = m_mltProducer->parent().get_service();
3847 mlt_service_lock(serv);
3849 Mlt::Service service(serv);
3850 Mlt::Tractor tractor(service);
3851 Mlt::Field *field = tractor.field();
3853 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3855 mlt_service nextservice = mlt_service_get_producer(serv);
3856 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3857 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3858 QString resource = mlt_properties_get(properties, "mlt_service");
3860 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3861 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3863 while (mlt_type == "transition") {
3864 mlt_transition tr = (mlt_transition) nextservice;
3865 int currentTrack = mlt_transition_get_b_track(tr);
3866 int currentIn = (int) mlt_transition_get_in(tr);
3867 int currentOut = (int) mlt_transition_get_out(tr);
3868 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3870 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3871 mlt_field_disconnect_service(field->get_field(), nextservice);
3874 nextservice = mlt_service_producer(nextservice);
3875 if (nextservice == NULL) break;
3876 properties = MLT_SERVICE_PROPERTIES(nextservice);
3877 mlt_type = mlt_properties_get(properties, "mlt_type");
3878 resource = mlt_properties_get(properties, "mlt_service");
3880 mlt_service_unlock(serv);
3882 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3885 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3887 QDomNodeList attribs = xml.elementsByTagName("parameter");
3888 QMap<QString, QString> map;
3889 for (int i = 0; i < attribs.count(); i++) {
3890 QDomElement e = attribs.item(i).toElement();
3891 QString name = e.attribute("name");
3892 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3893 map[name] = e.attribute("default");
3894 if (!e.attribute("value").isEmpty()) {
3895 map[name] = e.attribute("value");
3897 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
3898 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
3899 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3902 if (e.attribute("namedesc").contains(';')) {
3903 QString format = e.attribute("format");
3904 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3905 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3907 QTextStream txtNeu(&neu);
3908 if (values.size() > 0)
3909 txtNeu << (int)values[0].toDouble();
3911 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3912 txtNeu << separators[i];
3913 txtNeu << (int)(values[i+1].toDouble());
3915 if (i < separators.size())
3916 txtNeu << separators[i];
3917 map[e.attribute("name")] = neu;
3924 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3926 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3927 Mlt::Service service(m_mltProducer->parent().get_service());
3928 Mlt::Tractor tractor(service);
3929 Mlt::Field *field = tractor.field();
3931 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3932 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3933 transition->set("transparency", id);
3934 transition->set("fill", 1);
3935 transition->set("internal_added", 237);
3936 field->plant_transition(*transition, transitiontrack, info.track);
3940 void Render::mltDeleteTransparency(int pos, int track, int id)
3942 Mlt::Service service(m_mltProducer->parent().get_service());
3943 Mlt::Tractor tractor(service);
3944 Mlt::Field *field = tractor.field();
3946 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3947 mlt_service serv = m_mltProducer->parent().get_service();
3949 mlt_service nextservice = mlt_service_get_producer(serv);
3950 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3951 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3952 QString resource = mlt_properties_get(properties, "mlt_service");
3954 while (mlt_type == "transition") {
3955 mlt_transition tr = (mlt_transition) nextservice;
3956 int currentTrack = mlt_transition_get_b_track(tr);
3957 int currentIn = (int) mlt_transition_get_in(tr);
3958 int currentOut = (int) mlt_transition_get_out(tr);
3959 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3960 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3962 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3963 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3964 mlt_field_disconnect_service(field->get_field(), nextservice);
3967 nextservice = mlt_service_producer(nextservice);
3968 if (nextservice == NULL) break;
3969 properties = MLT_SERVICE_PROPERTIES(nextservice);
3970 mlt_type = mlt_properties_get(properties, "mlt_type");
3971 resource = mlt_properties_get(properties, "mlt_service");
3973 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3976 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3978 Mlt::Service service(m_mltProducer->parent().get_service());
3979 Mlt::Tractor tractor(service);
3982 m_mltConsumer->set("refresh", 0);
3984 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");
3989 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
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 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3995 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3996 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3997 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3998 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3999 mlt_transition_set_in_and_out(tr, newStart, newEnd);
4002 nextservice = mlt_service_producer(nextservice);
4003 if (nextservice == NULL) break;
4004 properties = MLT_SERVICE_PROPERTIES(nextservice);
4005 mlt_type = mlt_properties_get(properties, "mlt_type");
4006 resource = mlt_properties_get(properties, "mlt_service");
4009 m_mltConsumer->set("refresh", 1);
4013 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
4015 Mlt::Service service(m_mltProducer->parent().get_service());
4016 Mlt::Tractor tractor(service);
4019 m_mltConsumer->set("refresh", 0);
4021 mlt_service serv = m_mltProducer->parent().get_service();
4022 mlt_service nextservice = mlt_service_get_producer(serv);
4023 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4024 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4025 QString resource = mlt_properties_get(properties, "mlt_service");
4027 while (mlt_type == "transition") {
4028 mlt_transition tr = (mlt_transition) nextservice;
4029 int currentTrack = mlt_transition_get_b_track(tr);
4030 int currentaTrack = mlt_transition_get_a_track(tr);
4031 int currentIn = (int) mlt_transition_get_in(tr);
4032 int currentOut = (int) mlt_transition_get_out(tr);
4033 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4034 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
4035 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
4036 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
4037 kDebug() << "//////MOVING";
4038 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
4039 if (endTrack != startTrack) {
4040 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
4041 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
4042 mlt_properties_set_int(properties, "b_track", endTrack);
4046 nextservice = mlt_service_producer(nextservice);
4047 if (nextservice == NULL) break;
4048 properties = MLT_SERVICE_PROPERTIES(nextservice);
4049 mlt_type = mlt_properties_get(properties, "mlt_type");
4050 resource = mlt_properties_get(properties, "mlt_service");
4053 m_mltConsumer->set("refresh", 1);
4057 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
4059 if (in >= out) return false;
4060 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
4061 Mlt::Service service(m_mltProducer->parent().get_service());
4063 Mlt::Tractor tractor(service);
4064 Mlt::Field *field = tractor.field();
4066 Mlt::Transition transition(*m_mltProfile, tag.toUtf8().constData());
4067 if (out != GenTime())
4068 transition.set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
4070 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
4071 QMap<QString, QString>::Iterator it;
4073 if (xml.attribute("automatic") == "1") transition.set("automatic", 1);
4074 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
4075 if (xml.hasAttribute("id"))
4076 transition.set("kdenlive_id", xml.attribute("id").toUtf8().constData());
4077 if (xml.hasAttribute("force_track"))
4078 transition.set("force_track", xml.attribute("force_track").toInt());
4080 for (it = args.begin(); it != args.end(); ++it) {
4082 if (!it.value().isEmpty())
4083 transition.set(key.toUtf8().constData(), it.value().toUtf8().constData());
4084 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
4086 // attach transition
4088 mltPlantTransition(field, transition, a_track, b_track);
4089 // field->plant_transition(*transition, a_track, b_track);
4091 if (do_refresh) refresh();
4095 void Render::mltSavePlaylist()
4097 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
4098 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
4099 fileConsumer.set("resource", "/tmp/playlist.mlt");
4101 Mlt::Service service(m_mltProducer->get_service());
4103 fileConsumer.connect(service);
4104 fileConsumer.start();
4107 const QList <Mlt::Producer *> Render::producersList()
4109 QList <Mlt::Producer *> prods;
4110 if (m_mltProducer == NULL) return prods;
4111 Mlt::Service service(m_mltProducer->parent().get_service());
4112 if (service.type() != tractor_type) return prods;
4113 Mlt::Tractor tractor(service);
4116 int trackNb = tractor.count();
4117 for (int t = 1; t < trackNb; t++) {
4118 Mlt::Producer *tt = tractor.track(t);
4119 Mlt::Producer trackProducer(tt);
4121 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4122 if (!trackPlaylist.is_valid()) continue;
4123 int clipNb = trackPlaylist.count();
4124 for (int i = 0; i < clipNb; i++) {
4125 Mlt::Producer *c = trackPlaylist.get_clip(i);
4126 if (c == NULL) continue;
4127 QString prodId = c->parent().get("id");
4128 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
4129 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4132 prods.append(nprod);
4141 void Render::fillSlowMotionProducers()
4143 if (m_mltProducer == NULL) return;
4144 Mlt::Service service(m_mltProducer->parent().get_service());
4145 if (service.type() != tractor_type) return;
4147 Mlt::Tractor tractor(service);
4149 int trackNb = tractor.count();
4150 for (int t = 1; t < trackNb; t++) {
4151 Mlt::Producer *tt = tractor.track(t);
4152 Mlt::Producer trackProducer(tt);
4154 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
4155 if (!trackPlaylist.is_valid()) continue;
4156 int clipNb = trackPlaylist.count();
4157 for (int i = 0; i < clipNb; i++) {
4158 Mlt::Producer *c = trackPlaylist.get_clip(i);
4159 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
4161 QString id = nprod->parent().get("id");
4162 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
4163 // this is a slowmotion producer, add it to the list
4164 QString url = QString::fromUtf8(nprod->get("resource"));
4165 int strobe = nprod->get_int("strobe");
4166 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
4167 if (!m_slowmotionProducers.contains(url)) {
4168 m_slowmotionProducers.insert(url, nprod);
4170 } else delete nprod;
4177 QList <TransitionInfo> Render::mltInsertTrack(int ix, bool videoTrack)
4179 Mlt::Service service(m_mltProducer->parent().get_service());
4180 if (service.type() != tractor_type) {
4181 kWarning() << "// TRACTOR PROBLEM";
4182 return QList <TransitionInfo> ();
4186 Mlt::Tractor tractor(service);
4187 QList <TransitionInfo> transitionInfos;
4188 Mlt::Playlist playlist;
4189 int ct = tractor.count();
4191 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
4197 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
4198 tractor.set_track(playlist, pos);
4199 Mlt::Producer newProd(tractor.track(pos));
4200 if (!videoTrack) newProd.set("hide", 1);
4202 for (; pos <= ct; pos++) {
4203 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
4204 tractor.set_track(*prodToMove, pos);
4205 prodToMove = prodToMove2;
4208 tractor.set_track(playlist, ix);
4209 Mlt::Producer newProd(tractor.track(ix));
4210 if (!videoTrack) newProd.set("hide", 1);
4215 mlt_service serv = m_mltProducer->parent().get_service();
4216 mlt_service nextservice = mlt_service_get_producer(serv);
4217 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
4218 QString mlt_type = mlt_properties_get(properties, "mlt_type");
4219 QString resource = mlt_properties_get(properties, "mlt_service");
4220 Mlt::Field *field = tractor.field();
4221 QList <Mlt::Transition *> trList;
4223 while (mlt_type == "transition") {
4224 if (resource != "mix") {
4225 Mlt::Transition transition((mlt_transition) nextservice);
4226 nextservice = mlt_service_producer(nextservice);
4227 int currentbTrack = transition.get_b_track();
4228 int currentaTrack = transition.get_a_track();
4229 bool trackChanged = false;
4230 bool forceTransitionTrack = false;
4231 if (currentbTrack >= ix) {
4232 if (currentbTrack == ix && currentaTrack < ix) forceTransitionTrack = true;
4234 trackChanged = true;
4236 if (currentaTrack >= ix) {
4238 trackChanged = true;
4240 kDebug()<<"// Newtrans: "<<currentaTrack<<"/"<<currentbTrack;
4242 // disconnect all transitions
4243 Mlt::Properties trans_props(transition.get_properties());
4244 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
4245 Mlt::Properties new_trans_props(cp->get_properties());
4246 new_trans_props.inherit(trans_props);
4249 // Transition track needs to be adjusted
4250 cp->set("a_track", currentaTrack);
4251 cp->set("b_track", currentbTrack);
4252 // Check if transition track was changed and needs to be forced
4253 if (forceTransitionTrack) cp->set("force_track", 1);
4254 TransitionInfo trInfo;
4255 trInfo.startPos = GenTime(transition.get_in(), m_fps);
4256 trInfo.a_track = currentaTrack;
4257 trInfo.b_track = currentbTrack;
4258 trInfo.forceTrack = cp->get_int("force_track");
4259 transitionInfos.append(trInfo);
4262 field->disconnect_service(transition);
4264 else nextservice = mlt_service_producer(nextservice);
4265 if (nextservice == NULL) break;
4266 properties = MLT_SERVICE_PROPERTIES(nextservice);
4267 mlt_type = mlt_properties_get(properties, "mlt_type");
4268 resource = mlt_properties_get(properties, "mlt_service");
4271 // Add audio mix transition to last track
4272 Mlt::Transition transition(*m_mltProfile, "mix");
4273 transition.set("a_track", 1);
4274 transition.set("b_track", ct);
4275 transition.set("always_active", 1);
4276 transition.set("internal_added", 237);
4277 transition.set("combine", 1);
4278 mltPlantTransition(field, transition, 1, ct);
4280 // re-add transitions
4281 for (int i = trList.count() - 1; i >= 0; i--) {
4282 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
4287 blockSignals(false);
4288 return transitionInfos;
4292 void Render::mltDeleteTrack(int ix)
4295 doc.setContent(sceneList(), false);
4296 int tracksCount = doc.elementsByTagName("track").count() - 1;
4297 QDomNode track = doc.elementsByTagName("track").at(ix);
4298 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
4299 QDomNodeList transitions = doc.elementsByTagName("transition");
4300 for (int i = 0; i < transitions.count(); i++) {
4301 QDomElement e = transitions.at(i).toElement();
4302 QDomNodeList props = e.elementsByTagName("property");
4303 QMap <QString, QString> mappedProps;
4304 for (int j = 0; j < props.count(); j++) {
4305 QDomElement f = props.at(j).toElement();
4306 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
4308 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
4309 tractor.removeChild(transitions.at(i));
4311 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
4312 // Transition needs to be moved
4313 int a_track = mappedProps.value("a_track").toInt();
4314 int b_track = mappedProps.value("b_track").toInt();
4315 if (a_track > 0 && a_track >= ix) a_track --;
4316 if (b_track == ix) {
4317 // transition was on the deleted track, so remove it
4318 tractor.removeChild(transitions.at(i));
4322 if (b_track > 0 && b_track > ix) b_track --;
4323 for (int j = 0; j < props.count(); j++) {
4324 QDomElement f = props.at(j).toElement();
4325 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
4326 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
4331 tractor.removeChild(track);
4332 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
4333 setSceneList(doc.toString(), m_mltConsumer->position());
4334 emit refreshDocumentProducers(false, false);
4338 void Render::updatePreviewSettings()
4340 kDebug() << "////// RESTARTING CONSUMER";
4341 if (!m_mltConsumer || !m_mltProducer) return;
4342 if (m_mltProducer->get_playtime() == 0) return;
4343 QMutexLocker locker(&m_mutex);
4344 Mlt::Service service(m_mltProducer->parent().get_service());
4345 if (service.type() != tractor_type) return;
4347 //m_mltConsumer->set("refresh", 0);
4348 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
4349 m_mltConsumer->purge();
4350 QString scene = sceneList();
4352 if (m_mltProducer) {
4353 pos = m_mltProducer->position();
4356 setSceneList(scene, pos);
4360 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
4362 // Update all frame positions to the new fps value
4363 //WARNING: there are probably some effects or other that hold a frame value
4364 // as parameter and will also need to be updated here!
4366 doc.setContent(scene);
4368 double factor = new_fps / current_fps;
4369 QDomNodeList producers = doc.elementsByTagName("producer");
4370 for (int i = 0; i < producers.count(); i++) {
4371 QDomElement prod = producers.at(i).toElement();
4372 prod.removeAttribute("in");
4373 prod.removeAttribute("out");
4375 QDomNodeList props = prod.childNodes();
4376 for (int j = 0; j < props.count(); j++) {
4377 QDomElement param = props.at(j).toElement();
4378 QString paramName = param.attribute("name");
4379 if (paramName.startsWith("meta.") || paramName == "length") {
4380 prod.removeChild(props.at(j));
4386 QDomNodeList entries = doc.elementsByTagName("entry");
4387 for (int i = 0; i < entries.count(); i++) {
4388 QDomElement entry = entries.at(i).toElement();
4389 int in = entry.attribute("in").toInt();
4390 int out = entry.attribute("out").toInt();
4391 in = factor * in + 0.5;
4392 out = factor * out + 0.5;
4393 entry.setAttribute("in", in);
4394 entry.setAttribute("out", out);
4397 QDomNodeList blanks = doc.elementsByTagName("blank");
4398 for (int i = 0; i < blanks.count(); i++) {
4399 QDomElement blank = blanks.at(i).toElement();
4400 int length = blank.attribute("length").toInt();
4401 length = factor * length + 0.5;
4402 blank.setAttribute("length", QString::number(length));
4405 QDomNodeList filters = doc.elementsByTagName("filter");
4406 for (int i = 0; i < filters.count(); i++) {
4407 QDomElement filter = filters.at(i).toElement();
4408 int in = filter.attribute("in").toInt();
4409 int out = filter.attribute("out").toInt();
4410 in = factor * in + 0.5;
4411 out = factor * out + 0.5;
4412 filter.setAttribute("in", in);
4413 filter.setAttribute("out", out);
4416 QDomNodeList transitions = doc.elementsByTagName("transition");
4417 for (int i = 0; i < transitions.count(); i++) {
4418 QDomElement transition = transitions.at(i).toElement();
4419 int in = transition.attribute("in").toInt();
4420 int out = transition.attribute("out").toInt();
4421 in = factor * in + 0.5;
4422 out = factor * out + 0.5;
4423 transition.setAttribute("in", in);
4424 transition.setAttribute("out", out);
4425 QDomNodeList props = transition.childNodes();
4426 for (int j = 0; j < props.count(); j++) {
4427 QDomElement param = props.at(j).toElement();
4428 QString paramName = param.attribute("name");
4429 if (paramName == "geometry") {
4430 QString geom = param.firstChild().nodeValue();
4431 QStringList keys = geom.split(';');
4432 QStringList newKeys;
4433 for (int k = 0; k < keys.size(); ++k) {
4434 if (keys.at(k).contains('=')) {
4435 int pos = keys.at(k).section('=', 0, 0).toInt();
4436 pos = factor * pos + 0.5;
4437 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4438 } else newKeys.append(keys.at(k));
4440 param.firstChild().setNodeValue(newKeys.join(";"));
4444 QDomElement root = doc.documentElement();
4445 if (!root.isNull()) {
4446 QDomElement tractor = root.firstChildElement("tractor");
4447 int out = tractor.attribute("out").toInt();
4448 out = factor * out + 0.5;
4449 tractor.setAttribute("out", out);
4450 emit durationChanged(out);
4453 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4454 return doc.toString();
4458 void Render::sendFrameUpdate()
4460 if (m_mltProducer) {
4461 Mlt::Frame * frame = m_mltProducer->get_frame();
4462 emitFrameUpdated(*frame);
4467 Mlt::Producer* Render::getProducer()
4469 return m_mltProducer;
4472 const QString Render::activeClipId()
4474 if (m_mltProducer) return m_mltProducer->get("id");
4479 bool Render::getBlackMagicDeviceList(KComboBox *devicelist)
4481 if (!KdenliveSettings::decklink_device_found()) return false;
4482 Mlt::Profile profile;
4483 Mlt::Producer bm(profile, "decklink");
4484 int found_devices = 0;
4485 if (bm.is_valid()) {
4486 bm.set("list_devices", 1);
4487 found_devices = bm.get_int("devices");
4489 else KdenliveSettings::setDecklink_device_found(false);
4490 if (found_devices <= 0) {
4491 devicelist->setEnabled(false);
4494 for (int i = 0; i < found_devices; i++) {
4495 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4496 devicelist->addItem(bm.get(tmp));
4502 bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist)
4504 if (!KdenliveSettings::decklink_device_found()) return false;
4505 Mlt::Profile profile;
4506 Mlt::Consumer bm(profile, "decklink");
4507 int found_devices = 0;
4508 if (bm.is_valid()) {
4509 bm.set("list_devices", 1);
4510 found_devices = bm.get_int("devices");
4512 else KdenliveSettings::setDecklink_device_found(false);
4513 if (found_devices <= 0) {
4514 devicelist->setEnabled(false);
4517 for (int i = 0; i < found_devices; i++) {
4518 char *tmp = qstrdup(QString("device.%1").arg(i).toUtf8().constData());
4519 devicelist->addItem(bm.get(tmp));
4525 void Render::slotMultiStreamProducerFound(const QString path, QList<int> audio_list, QList<int> video_list, stringMap data)
4527 if (KdenliveSettings::automultistreams()) {
4528 for (int i = 1; i < video_list.count(); i++) {
4529 int vindex = video_list.at(i);
4531 if (i <= audio_list.count() -1) {
4532 aindex = audio_list.at(i);
4534 data.insert("video_index", QString::number(vindex));
4535 data.insert("audio_index", QString::number(aindex));
4536 data.insert("bypassDuplicate", "1");
4537 emit addClip(KUrl(path), data);
4542 int width = 60.0 * m_mltProfile->dar();
4543 int swidth = 60.0 * m_mltProfile->width() / m_mltProfile->height();
4544 if (width % 2 == 1) width++;
4546 KDialog dialog(qApp->activeWindow());
4547 dialog.setCaption("Multi Stream Clip");
4548 dialog.setButtons(KDialog::Ok | KDialog::Cancel);
4549 dialog.setButtonText(KDialog::Ok, i18n("Import selected clips"));
4550 QWidget *content = new QWidget(&dialog);
4551 dialog.setMainWidget(content);
4552 QVBoxLayout *vbox = new QVBoxLayout(content);
4553 QLabel *lab1 = new QLabel(i18n("Additional streams for clip\n %1", path), content);
4554 vbox->addWidget(lab1);
4555 QList <QGroupBox*> groupList;
4556 QList <QComboBox*> comboList;
4557 // We start loading the list at 1, video index 0 should already be loaded
4558 for (int j = 1; j < video_list.count(); j++) {
4559 Mlt::Producer multiprod(* m_mltProfile, path.toUtf8().constData());
4560 multiprod.set("video_index", video_list.at(j));
4561 QImage thumb = KThumb::getFrame(&multiprod, 0, swidth, width, 60);
4562 QGroupBox *streamFrame = new QGroupBox(i18n("Video stream %1", video_list.at(j)), content);
4563 streamFrame->setProperty("vindex", video_list.at(j));
4564 groupList << streamFrame;
4565 streamFrame->setCheckable(true);
4566 streamFrame->setChecked(true);
4567 QVBoxLayout *vh = new QVBoxLayout( streamFrame );
4568 QLabel *iconLabel = new QLabel(content);
4569 iconLabel->setPixmap(QPixmap::fromImage(thumb));
4570 vh->addWidget(iconLabel);
4571 if (audio_list.count() > 1) {
4572 QComboBox *cb = new QComboBox(content);
4573 for (int k = 0; k < audio_list.count(); k++) {
4574 cb->addItem(i18n("Audio stream %1", audio_list.at(k)), audio_list.at(k));
4577 cb->setCurrentIndex(qMin(j, audio_list.count() - 1));
4580 vbox->addWidget(streamFrame);
4582 if (dialog.exec() == QDialog::Accepted) {
4583 // import selected streams
4584 for (int i = 0; i < groupList.count(); i++) {
4585 if (groupList.at(i)->isChecked()) {
4586 int vindex = groupList.at(i)->property("vindex").toInt();
4587 int aindex = comboList.at(i)->itemData(comboList.at(i)->currentIndex()).toInt();
4588 data.insert("video_index", QString::number(vindex));
4589 data.insert("audio_index", QString::number(aindex));
4590 data.insert("bypassDuplicate", "1");
4591 emit addClip(KUrl(path), data);
4597 #include "renderer.moc"