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"
32 #include "blackmagic/devices.h"
34 #include <mlt++/Mlt.h>
37 #include <KStandardDirs>
38 #include <KMessageBox>
40 #include <KTemporaryFile>
45 #include <QApplication>
46 #include <QtConcurrentRun>
54 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
56 // kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified();
57 if (level > MLT_LOG_ERROR) return;
59 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
64 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
66 // detect if the producer has finished playing. Is there a better way to do it?
67 self->emitFrameNumber();
68 Mlt::Frame frame(frame_ptr);
69 if (!frame.is_valid()) return;
70 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
71 self->emitFrameUpdated(frame);
73 if (self->analyseAudio) {
74 self->showAudio(frame);
76 if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
78 self->emitConsumerStopped();
83 static void consumer_paused(mlt_consumer, Render * self, mlt_frame /*frame_ptr*/)
85 // detect if the producer has finished playing. Is there a better way to do it?
86 self->emitConsumerStopped();
90 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
92 // detect if the producer has finished playing. Is there a better way to do it?
93 Mlt::Frame frame(frame_ptr);
94 self->showFrame(frame);
95 if (frame.get_double("_speed") == 0.0) {
96 self->emitConsumerStopped();
97 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
99 self->emitConsumerStopped();
103 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
104 AbstractRender(rendererName, parent),
105 analyseAudio(KdenliveSettings::monitor_audio()),
106 m_name(rendererName),
110 m_showFrameEvent(NULL),
112 m_externalConsumer(false),
115 m_isSplitView(false),
119 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
120 buildConsumer(profile);
121 m_mltProducer = m_blackClip->cut(0, 1);
122 m_mltConsumer->connect(*m_mltProducer);
123 m_mltProducer->set_speed(0.0);
124 m_refreshTimer.setSingleShot(true);
125 m_refreshTimer.setInterval(50);
126 connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
136 void Render::closeMlt()
139 m_requestList.clear();
140 m_infoThread.waitForFinished();
141 if (m_showFrameEvent) delete m_showFrameEvent;
142 if (m_pauseEvent) delete m_pauseEvent;
143 if (m_mltConsumer) delete m_mltConsumer;
144 if (m_mltProducer) delete m_mltProducer;
145 /*if (m_mltProducer) {
146 Mlt::Service service(m_mltProducer->parent().get_service());
149 if (service.type() == tractor_type) {
150 Mlt::Tractor tractor(service);
151 Mlt::Field *field = tractor.field();
152 mlt_service nextservice = mlt_service_get_producer(service.get_service());
153 mlt_service nextservicetodisconnect;
154 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
155 QString mlt_type = mlt_properties_get(properties, "mlt_type");
156 QString resource = mlt_properties_get(properties, "mlt_service");
157 // Delete all transitions
158 while (mlt_type == "transition") {
159 nextservicetodisconnect = nextservice;
160 nextservice = mlt_service_producer(nextservice);
161 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
162 if (nextservice == NULL) break;
163 properties = MLT_SERVICE_PROPERTIES(nextservice);
164 mlt_type = mlt_properties_get(properties, "mlt_type");
165 resource = mlt_properties_get(properties, "mlt_service");
174 kDebug() << "// // // CLOSE RENDERER " << m_name;
175 if (m_blackClip) delete m_blackClip;
179 void Render::slotSwitchFullscreen()
181 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
184 void Render::buildConsumer(const QString &profileName)
189 //TODO: uncomment following line when everything is clean
190 // uncommented Feb 2011 --Granjow
191 if (m_mltProfile) delete m_mltProfile;
192 m_activeProfile = profileName;
193 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
194 setenv("MLT_PROFILE", tmp, 1);
195 m_mltProfile = new Mlt::Profile(tmp);
196 m_mltProfile->set_explicit(true);
199 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
200 m_blackClip->set("id", "black");
201 m_blackClip->set("mlt_type", "producer");
203 if (KdenliveSettings::external_display() && m_name != "clip") {
204 // Use blackmagic card for video output
205 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
206 int device = KdenliveSettings::blackmagic_output_device();
208 if (BMInterface::isSupportedProfile(device, profileProperties)) {
209 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
210 tmp = qstrdup(decklink.toUtf8().constData());
211 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, tmp);
213 if (m_mltConsumer->is_valid()) {
214 m_externalConsumer = true;
215 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
216 m_mltConsumer->set("terminate_on_pause", 0);
217 m_mltConsumer->set("deinterlace_method", "onefield");
218 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
219 mlt_log_set_callback(kdenlive_callback);
221 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
222 } 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()));
225 m_externalConsumer = false;
226 QString videoDriver = KdenliveSettings::videodrivername();
227 if (!videoDriver.isEmpty()) {
228 if (videoDriver == "x11_noaccel") {
229 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
232 unsetenv("SDL_VIDEO_YUV_HWACCEL");
235 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
237 //m_mltConsumer->set("fullscreen", 1);
240 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
241 m_mltConsumer->set("preview_off", 1);
242 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
243 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
245 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
246 m_showFrameEvent = m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
247 m_pauseEvent = m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
248 m_mltConsumer->set("window_id", m_winid);
250 m_mltConsumer->set("resize", 1);
251 m_mltConsumer->set("terminate_on_pause", 1);
252 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
253 m_mltConsumer->set("rescale", "nearest");
254 mlt_log_set_callback(kdenlive_callback);
256 QString audioDevice = KdenliveSettings::audiodevicename();
257 if (!audioDevice.isEmpty())
258 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
260 if (!videoDriver.isEmpty())
261 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
263 QString audioDriver = KdenliveSettings::audiodrivername();
266 // Disabled because the "auto" detected driver was sometimes wrong
267 if (audioDriver.isEmpty())
268 audioDriver = KdenliveSettings::autoaudiodrivername();
271 if (!audioDriver.isEmpty())
272 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
274 m_mltConsumer->set("progressive", 1);
275 m_mltConsumer->set("audio_buffer", 1024);
276 m_mltConsumer->set("frequency", 48000);
277 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
280 Mlt::Producer *Render::invalidProducer(const QString &id)
283 QString txt = "+" + i18n("Missing clip") + ".txt";
284 char *tmp = qstrdup(txt.toUtf8().constData());
285 clip = new Mlt::Producer(*m_mltProfile, tmp);
287 if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
289 clip->set("bgcolour", "0xff0000ff");
290 clip->set("pad", "10");
292 clip->set("id", id.toUtf8().constData());
293 clip->set("mlt_type", "producer");
297 bool Render::hasProfile(const QString &profileName) const
299 return m_activeProfile == profileName;
302 int Render::resetProfile(const QString &profileName, bool dropSceneList)
304 m_refreshTimer.stop();
306 if (m_externalConsumer == KdenliveSettings::external_display()) {
307 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
308 QString videoDriver = KdenliveSettings::videodrivername();
309 QString currentDriver = m_mltConsumer->get("video_driver");
310 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
311 QString background = KdenliveSettings::window_background().name();
312 QString currentBackground = m_mltConsumer->get("window_background");
313 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
314 kDebug() << "reset to same profile, nothing to do";
319 if (m_isSplitView) slotSplitView(false);
320 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
321 m_mltConsumer->purge();
322 if (m_showFrameEvent) delete m_showFrameEvent;
323 m_showFrameEvent = NULL;
324 if (m_pauseEvent) delete m_pauseEvent;
326 delete m_mltConsumer;
327 m_mltConsumer = NULL;
330 if (!dropSceneList) scene = sceneList();
332 double current_fps = m_mltProfile->fps();
333 double current_dar = m_mltProfile->dar();
336 m_requestList.clear();
337 m_infoThread.waitForFinished();
340 pos = m_mltProducer->position();
342 Mlt::Service service(m_mltProducer->get_service());
343 if (service.type() == tractor_type) {
344 Mlt::Tractor tractor(service);
345 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
346 Mlt::Producer trackProducer(tractor.track(trackNb));
347 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
348 trackPlaylist.clear();
352 delete m_mltProducer;
354 m_mltProducer = NULL;
355 buildConsumer(profileName);
356 double new_fps = m_mltProfile->fps();
357 double new_dar = m_mltProfile->dar();
359 if (!dropSceneList) {
360 // We need to recover our playlist
361 if (current_fps != new_fps) {
362 // fps changed, we must update the scenelist positions
363 scene = updateSceneListFps(current_fps, new_fps, scene);
365 setSceneList(scene, pos);
366 // producers have changed (different profile), so reset them...
367 emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
372 void Render::seek(GenTime time)
377 m_mltProducer->seek((int)(time.frames(m_fps)));
378 if (m_mltProducer->get_speed() == 0) {
383 void Render::seek(int time)
388 m_mltProducer->seek(time);
389 if (m_mltProducer->get_speed() == 0) {
395 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
396 QPixmap pix(width, height);
398 mlt_image_format format = mlt_image_rgb24a;
399 uint8_t *thumb = frame->get_image(format, width, height);
400 QImage image(thumb, width, height, QImage::Format_ARGB32);
402 if (!image.isNull()) {
403 pix = pix.fromImage(image);
405 QPainter painter(&pix);
406 painter.drawRect(0, 0, width - 1, height - 1);
408 } else pix.fill(Qt::black);
412 int Render::frameRenderWidth() const
414 return m_mltProfile->width();
417 int Render::renderWidth() const
419 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
422 int Render::renderHeight() const
424 return m_mltProfile->height();
427 QImage Render::extractFrame(int frame_position, QString path, int width, int height)
430 width = frameRenderWidth();
431 height = renderHeight();
432 } else if (width % 2 == 1) width++;
433 int dwidth = height * frameRenderWidth() / renderHeight();
434 if (!path.isEmpty()) {
435 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
437 if (producer->is_valid()) {
438 QImage img = KThumb::getFrame(producer, frame_position, dwidth, width, height);
442 else delete producer;
446 if (!m_mltProducer || !path.isEmpty()) {
447 QImage pix(width, height, QImage::Format_RGB32);
451 return KThumb::getFrame(m_mltProducer, frame_position, dwidth, width, height);
454 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
458 if (url.fileName().startsWith(".all.")) { // check for slideshow
459 QString fileType = url.fileName().right(3);
461 QStringList::Iterator it;
463 QDir dir(url.directory());
465 filter << "*." + fileType;
466 filter << "*." + fileType.toUpper();
467 more = dir.entryList(filter, QDir::Files);
468 im.load(url.directory() + '/' + more.at(0));
469 } else im.load(url.path());
470 //pixmap = im.scaled(width, height);
474 double Render::consumerRatio() const
476 if (!m_mltConsumer) return 1.0;
477 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
481 int Render::getLength()
485 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
486 return mlt_producer_get_playtime(m_mltProducer->get_producer());
491 bool Render::isValid(KUrl url)
493 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
494 if (producer.is_blank())
500 double Render::dar() const
502 return m_mltProfile->dar();
505 double Render::sar() const
507 return m_mltProfile->sar();
510 void Render::slotSplitView(bool doit)
512 m_isSplitView = doit;
513 Mlt::Service service(m_mltProducer->parent().get_service());
514 Mlt::Tractor tractor(service);
515 if (service.type() != tractor_type || tractor.count() < 2) return;
516 Mlt::Field *field = tractor.field();
518 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
519 Mlt::Producer trackProducer(tractor.track(i));
520 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
521 if (QString(trackProducer.get("hide")).toInt() != 1) {
522 kDebug() << "// ADIDNG TRACK: " << i;
523 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
524 transition->set("mlt_service", "composite");
525 transition->set("a_track", 0);
526 transition->set("b_track", i);
527 transition->set("distort", 1);
528 transition->set("internal_added", "200");
535 tmp = "50%,0:50%x50%";
538 tmp = "0,50%:50%x50%";
542 tmp = "50%,50%:50%x50%";
545 transition->set("geometry", tmp);
546 transition->set("always_active", "1");
547 field->plant_transition(*transition, 0, i);
552 m_mltConsumer->set("refresh", 1);
554 mlt_service serv = m_mltProducer->parent().get_service();
555 mlt_service nextservice = mlt_service_get_producer(serv);
556 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
557 QString mlt_type = mlt_properties_get(properties, "mlt_type");
558 QString resource = mlt_properties_get(properties, "mlt_service");
560 while (mlt_type == "transition") {
561 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
562 if (added == "200") {
563 mlt_field_disconnect_service(field->get_field(), nextservice);
565 nextservice = mlt_service_producer(nextservice);
566 if (nextservice == NULL) break;
567 properties = MLT_SERVICE_PROPERTIES(nextservice);
568 mlt_type = mlt_properties_get(properties, "mlt_type");
569 resource = mlt_properties_get(properties, "mlt_service");
570 m_mltConsumer->set("refresh", 1);
575 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer)
577 requestClipInfo info;
579 info.clipId = clipId;
580 info.imageHeight = imageHeight;
581 info.replaceProducer = replaceProducer;
582 // Make sure we don't request the info for same clip twice
584 m_requestList.removeAll(info);
585 m_requestList.append(info);
586 m_infoMutex.unlock();
587 if (!m_infoThread.isRunning()) {
588 m_infoThread = QtConcurrent::run(this, &Render::processFileProperties);
592 void Render::forceProcessing(const QString &id)
594 if (m_processingClipId == id) return;
595 QMutexLocker lock(&m_infoMutex);
596 for (int i = 0; i < m_requestList.count(); i++) {
597 requestClipInfo info = m_requestList.at(i);
598 if (info.clipId == id) {
601 m_requestList.removeAt(i);
602 m_requestList.prepend(info);
609 int Render::processingItems()
611 QMutexLocker lock(&m_infoMutex);
612 int count = m_requestList.count();
613 if (!m_processingClipId.isEmpty()) {
614 // one clip is currently processed
620 bool Render::isProcessing(const QString &id)
622 if (m_processingClipId == id) return true;
623 QMutexLocker lock(&m_infoMutex);
624 for (int i = 0; i < m_requestList.count(); i++) {
625 requestClipInfo info = m_requestList.at(i);
626 if (info.clipId == id) {
633 void Render::processFileProperties()
635 requestClipInfo info;
637 while (!m_requestList.isEmpty()) {
639 info = m_requestList.takeFirst();
640 m_processingClipId = info.clipId;
641 m_infoMutex.unlock();
645 if (info.xml.hasAttribute("proxy") && info.xml.attribute("proxy") != "-") {
646 path = info.xml.attribute("proxy");
647 proxyProducer = true;
650 path = info.xml.attribute("resource");
651 proxyProducer = false;
654 Mlt::Producer *producer = NULL;
655 CLIPTYPE type = (CLIPTYPE)info.xml.attribute("type").toInt();
658 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + info.xml.attribute("colour")).toUtf8().constData());
659 } else if (type == TEXT) {
660 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
661 if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
662 producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
663 } else if (url.isEmpty()) {
665 QDomElement mlt = doc.createElement("mlt");
666 QDomElement play = doc.createElement("playlist");
667 doc.appendChild(mlt);
668 mlt.appendChild(play);
669 play.appendChild(doc.importNode(info.xml, true));
670 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
672 producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
675 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
676 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
677 m_processingClipId.clear();
679 // Proxy file is corrupted
680 emit removeInvalidProxy(info.clipId, false);
682 else emit removeInvalidClip(info.clipId, info.replaceProducer);
687 if (proxyProducer && info.xml.hasAttribute("proxy_out")) {
688 producer->set("length", info.xml.attribute("proxy_out").toInt() + 1);
689 producer->set("out", info.xml.attribute("proxy_out").toInt());
690 if (producer->get_out() != info.xml.attribute("proxy_out").toInt()) {
691 // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
692 m_processingClipId.clear();
693 emit removeInvalidProxy(info.clipId, true);
699 if (info.xml.hasAttribute("force_aspect_ratio")) {
700 double aspect = info.xml.attribute("force_aspect_ratio").toDouble();
701 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
704 if (info.xml.hasAttribute("force_aspect_num") && info.xml.hasAttribute("force_aspect_den")) {
705 int width = info.xml.attribute("frame_size").section('x', 0, 0).toInt();
706 int height = info.xml.attribute("frame_size").section('x', 1, 1).toInt();
707 int aspectNumerator = info.xml.attribute("force_aspect_num").toInt();
708 int aspectDenominator = info.xml.attribute("force_aspect_den").toInt();
709 if (aspectDenominator != 0 && width != 0)
710 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
713 if (info.xml.hasAttribute("force_fps")) {
714 double fps = info.xml.attribute("force_fps").toDouble();
715 if (fps > 0) producer->set("force_fps", fps);
718 if (info.xml.hasAttribute("force_progressive")) {
720 int progressive = info.xml.attribute("force_progressive").toInt(&ok);
721 if (ok) producer->set("force_progressive", progressive);
723 if (info.xml.hasAttribute("force_tff")) {
725 int fieldOrder = info.xml.attribute("force_tff").toInt(&ok);
726 if (ok) producer->set("force_tff", fieldOrder);
728 if (info.xml.hasAttribute("threads")) {
729 int threads = info.xml.attribute("threads").toInt();
730 if (threads != 1) producer->set("threads", threads);
732 if (info.xml.hasAttribute("video_index")) {
733 int vindex = info.xml.attribute("video_index").toInt();
734 if (vindex != 0) producer->set("video_index", vindex);
736 if (info.xml.hasAttribute("audio_index")) {
737 int aindex = info.xml.attribute("audio_index").toInt();
738 if (aindex != 0) producer->set("audio_index", aindex);
740 if (info.xml.hasAttribute("force_colorspace")) {
741 int colorspace = info.xml.attribute("force_colorspace").toInt();
742 if (colorspace != 0) producer->set("force_colorspace", colorspace);
744 if (info.xml.hasAttribute("full_luma")) {
745 int full_luma = info.xml.attribute("full_luma").toInt();
746 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
751 if (info.xml.hasAttribute("out")) clipOut = info.xml.attribute("out").toInt();
753 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
754 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
756 if (info.xml.hasAttribute("length")) {
757 if (clipOut > 0) duration = clipOut + 1;
758 length = info.xml.attribute("length").toInt();
759 clipOut = length - 1;
761 else length = info.xml.attribute("out").toInt() - info.xml.attribute("in").toInt();
762 producer->set("length", length);
765 if (clipOut > 0) producer->set_in_and_out(info.xml.attribute("in").toInt(), clipOut);
767 producer->set("id", info.clipId.toUtf8().constData());
769 if (info.xml.hasAttribute("templatetext"))
770 producer->set("templatetext", info.xml.attribute("templatetext").toUtf8().constData());
772 int imageWidth = (int)((double) info.imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5);
773 int fullWidth = (int)((double) info.imageHeight * m_mltProfile->dar() + 0.5);
774 int frameNumber = info.xml.attribute("thumbnail", "-1").toInt();
776 if ((!info.replaceProducer && info.xml.hasAttribute("file_hash")) || proxyProducer) {
777 // Clip already has all properties
779 // Recreate clip thumb
780 if (frameNumber > 0) producer->seek(frameNumber);
781 Mlt::Frame *frame = producer->get_frame();
782 if (frame && frame->is_valid()) {
783 QImage img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
784 emit replyGetImage(info.clipId, img);
786 if (frame) delete frame;
788 m_processingClipId.clear();
789 emit replyGetFileProperties(info.clipId, producer, stringMap(), stringMap(), info.replaceProducer);
793 stringMap filePropertyMap;
794 stringMap metadataPropertyMap;
797 if (frameNumber > 0) producer->seek(frameNumber);
799 duration = duration > 0 ? duration : producer->get_playtime();
800 filePropertyMap["duration"] = QString::number(duration);
801 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
803 if (type == SLIDESHOW) {
804 int ttl = info.xml.hasAttribute("ttl") ? info.xml.attribute("ttl").toInt() : 0;
805 if (ttl) producer->set("ttl", ttl);
806 if (!info.xml.attribute("animation").isEmpty()) {
807 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
808 if (filter && filter->is_valid()) {
810 QString geometry = SlideshowClip::animationToGeometry(info.xml.attribute("animation"), cycle);
811 if (!geometry.isEmpty()) {
812 if (info.xml.attribute("animation").contains("low-pass")) {
813 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
814 if (blur && blur->is_valid())
815 producer->attach(*blur);
817 filter->set("transition.geometry", geometry.toUtf8().data());
818 filter->set("transition.cycle", cycle);
819 producer->attach(*filter);
823 if (info.xml.attribute("fade") == "1") {
824 // user wants a fade effect to slideshow
825 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
826 if (filter && filter->is_valid()) {
827 if (ttl) filter->set("cycle", ttl);
828 if (info.xml.hasAttribute("luma_duration") && !info.xml.attribute("luma_duration").isEmpty()) filter->set("duration", info.xml.attribute("luma_duration").toInt());
829 if (info.xml.hasAttribute("luma_file") && !info.xml.attribute("luma_file").isEmpty()) {
830 filter->set("luma.resource", info.xml.attribute("luma_file").toUtf8().constData());
831 if (info.xml.hasAttribute("softness")) {
832 int soft = info.xml.attribute("softness").toInt();
833 filter->set("luma.softness", (double) soft / 100.0);
836 producer->attach(*filter);
839 if (info.xml.attribute("crop") == "1") {
840 // user wants to center crop the slides
841 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
842 if (filter && filter->is_valid()) {
843 filter->set("center", 1);
844 producer->attach(*filter);
850 int vindex = producer->get_int("video_index");
852 snprintf(property, sizeof(property), "meta.media.%d.stream.frame_rate", vindex);
853 if (producer->get(property))
854 filePropertyMap["fps"] = producer->get(property);
857 if (!filePropertyMap.contains("fps")) {
858 if (producer->get_double("meta.media.frame_rate_den") > 0) {
859 filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
860 } else filePropertyMap["fps"] = producer->get("source_fps");
863 Mlt::Frame *frame = producer->get_frame();
864 if (frame && frame->is_valid()) {
865 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
866 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
867 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
868 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
870 if (frame->get_int("test_image") == 0) {
871 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
872 filePropertyMap["type"] = "playlist";
873 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
874 } else if (frame->get_int("test_audio") == 0)
875 filePropertyMap["type"] = "av";
877 filePropertyMap["type"] = "video";
883 img = KThumb::getFrame(frame, imageWidth, fullWidth, info.imageHeight);
884 variance = KThumb::imageVariance(img);
885 if (frameNumber == -1 && variance< 6) {
886 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
887 frameNumber = duration > 100 ? 100 : duration / 2 ;
888 producer->seek(frameNumber);
890 frame = producer->get_frame();
893 } while (variance == -1);
895 if (frameNumber > -1) filePropertyMap["thumbnail"] = QString::number(frameNumber);
896 emit replyGetImage(info.clipId, img);
897 } else if (frame->get_int("test_audio") == 0) {
898 emit replyGetImage(info.clipId, "audio-x-generic", fullWidth, info.imageHeight);
899 filePropertyMap["type"] = "audio";
902 // Retrieve audio / video codec name
906 /*if (context->duration == AV_NOPTS_VALUE) {
907 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
908 emit removeInvalidClip(clipId);
912 // Get the video_index
914 int default_audio = producer->get_int("audio_index");
917 int scan = producer->get_int("meta.media.progressive");
918 filePropertyMap["progressive"] = QString::number(scan);
920 // Find maximum stream index values
921 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
922 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
923 QString type = producer->get(property);
926 else if (type == "audio")
929 filePropertyMap["default_video"] = QString::number(vindex);
930 filePropertyMap["video_max"] = QString::number(video_max);
931 filePropertyMap["default_audio"] = QString::number(default_audio);
932 filePropertyMap["audio_max"] = QString::number(audio_max);
934 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", vindex);
935 if (producer->get(property)) {
936 filePropertyMap["videocodec"] = producer->get(property);
938 snprintf(property, sizeof(property), "meta.media.%d.codec.name", vindex);
939 if (producer->get(property))
940 filePropertyMap["videocodec"] = producer->get(property);
943 query = QString("meta.media.%1.codec.pix_fmt").arg(vindex);
944 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
945 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
947 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
948 if (producer->get_int("audio_index") > -1) {
949 // Get the audio_index
950 int index = producer->get_int("audio_index");
951 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
952 if (producer->get(property)) {
953 filePropertyMap["audiocodec"] = producer->get(property);
955 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
956 if (producer->get(property))
957 filePropertyMap["audiocodec"] = producer->get(property);
962 Mlt::Properties metadata;
963 metadata.pass_values(*producer, "meta.attr.");
964 int count = metadata.count();
965 for (int i = 0; i < count; i ++) {
966 QString name = metadata.get_name(i);
967 QString value = QString::fromUtf8(metadata.get(i));
968 if (name.endsWith("markup") && !value.isEmpty())
969 metadataPropertyMap[ name.section('.', 0, -2)] = value;
972 m_processingClipId.clear();
973 emit replyGetFileProperties(info.clipId, producer, filePropertyMap, metadataPropertyMap, info.replaceProducer);
975 m_processingClipId.clear();
980 /** Create the producer from the MLT XML QDomDocument */
981 void Render::initSceneList()
983 kDebug() << "-------- INIT SCENE LIST ------_";
985 QDomElement mlt = doc.createElement("mlt");
986 doc.appendChild(mlt);
987 QDomElement prod = doc.createElement("producer");
988 prod.setAttribute("resource", "colour");
989 prod.setAttribute("colour", "red");
990 prod.setAttribute("id", "black");
991 prod.setAttribute("in", "0");
992 prod.setAttribute("out", "0");
994 QDomElement tractor = doc.createElement("tractor");
995 QDomElement multitrack = doc.createElement("multitrack");
997 QDomElement playlist1 = doc.createElement("playlist");
998 playlist1.appendChild(prod);
999 multitrack.appendChild(playlist1);
1000 QDomElement playlist2 = doc.createElement("playlist");
1001 multitrack.appendChild(playlist2);
1002 QDomElement playlist3 = doc.createElement("playlist");
1003 multitrack.appendChild(playlist3);
1004 QDomElement playlist4 = doc.createElement("playlist");
1005 multitrack.appendChild(playlist4);
1006 QDomElement playlist5 = doc.createElement("playlist");
1007 multitrack.appendChild(playlist5);
1008 tractor.appendChild(multitrack);
1009 mlt.appendChild(tractor);
1010 // kDebug()<<doc.toString();
1012 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
1013 setSceneList(doc, 0);
1017 int Render::setProducer(Mlt::Producer *producer, int position)
1019 m_refreshTimer.stop();
1020 QMutexLocker locker(&m_mutex);
1022 int consumerPosition = 0;
1023 if (m_winid == -1 || !m_mltConsumer) {
1024 kDebug()<<" / / / / WARNING, MONITOR NOT READY";
1025 if (producer) delete producer;
1028 m_mltConsumer->set("refresh", 0);
1029 if (!m_mltConsumer->is_stopped()) {
1030 m_mltConsumer->stop();
1032 m_mltConsumer->purge();
1033 consumerPosition = m_mltConsumer->position();
1037 if (!producer || !producer->is_valid()) {
1038 if (producer) delete producer;
1039 producer = m_blackClip->cut(0, 1);
1042 if (!producer || !producer->is_valid()) {
1043 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
1046 if (m_mltProducer) currentId = m_mltProducer->get("id");
1048 if (position == -1 && producer->get("id") == currentId) position = consumerPosition;
1049 if (position != -1) producer->seek(position);
1050 int volume = KdenliveSettings::volume();
1051 producer->set("meta.volume", (double)volume / 100);
1052 m_fps = producer->get_fps();
1053 blockSignals(false);
1054 m_mltConsumer->connect(*producer);
1056 if (m_mltProducer) {
1057 m_mltProducer->set_speed(0);
1058 delete m_mltProducer;
1059 m_mltProducer = NULL;
1061 m_mltProducer = producer;
1062 m_mltProducer->set_speed(0);
1063 emit durationChanged(m_mltProducer->get_playtime());
1064 if (m_mltConsumer->start() == -1) {
1065 // ARGH CONSUMER BROKEN!!!!
1066 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."));
1067 if (m_showFrameEvent) delete m_showFrameEvent;
1068 m_showFrameEvent = NULL;
1069 if (m_pauseEvent) delete m_pauseEvent;
1070 m_pauseEvent = NULL;
1071 delete m_mltConsumer;
1072 m_mltConsumer = NULL;
1076 position = m_mltProducer->position();
1077 m_mltConsumer->set("refresh", 1);
1078 // Make sure the first frame is displayed, otherwise if we change producer too fast
1079 // We can crash the avformat producer
1080 Mlt::Event *ev = m_mltConsumer->setup_wait_for("consumer-frame-show");
1081 m_mltConsumer->wait_for(ev);
1083 emit rendererPosition(position);
1087 int Render::setSceneList(QDomDocument list, int position)
1089 return setSceneList(list.toString(), position);
1092 int Render::setSceneList(QString playlist, int position)
1094 m_refreshTimer.stop();
1095 QMutexLocker locker(&m_mutex);
1096 if (m_winid == -1) return -1;
1099 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
1101 // Remove previous profile info
1103 doc.setContent(playlist);
1104 QDomElement profile = doc.documentElement().firstChildElement("profile");
1105 doc.documentElement().removeChild(profile);
1106 playlist = doc.toString();
1108 if (m_mltConsumer) {
1109 if (!m_mltConsumer->is_stopped()) {
1110 m_mltConsumer->stop();
1112 m_mltConsumer->set("refresh", 0);
1114 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
1117 m_requestList.clear();
1118 m_infoThread.waitForFinished();
1120 if (m_mltProducer) {
1121 m_mltProducer->set_speed(0);
1122 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
1124 /*Mlt::Service service(m_mltProducer->parent().get_service());
1127 if (service.type() == tractor_type) {
1128 Mlt::Tractor tractor(service);
1129 Mlt::Field *field = tractor.field();
1130 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1131 mlt_service nextservicetodisconnect;
1132 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1133 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1134 QString resource = mlt_properties_get(properties, "mlt_service");
1135 // Delete all transitions
1136 while (mlt_type == "transition") {
1137 nextservicetodisconnect = nextservice;
1138 nextservice = mlt_service_producer(nextservice);
1139 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1140 if (nextservice == NULL) break;
1141 properties = MLT_SERVICE_PROPERTIES(nextservice);
1142 mlt_type = mlt_properties_get(properties, "mlt_type");
1143 resource = mlt_properties_get(properties, "mlt_service");
1147 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1148 Mlt::Producer trackProducer(tractor.track(trackNb));
1149 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1150 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1156 qDeleteAll(m_slowmotionProducers.values());
1157 m_slowmotionProducers.clear();
1159 delete m_mltProducer;
1160 m_mltProducer = NULL;
1165 m_locale = QLocale();
1167 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1168 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1169 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1170 m_mltProducer = m_blackClip->cut(0, 1);
1174 int volume = KdenliveSettings::volume();
1175 m_mltProducer->set("meta.volume", (double)volume / 100);
1176 m_mltProducer->optimise();
1178 /*if (KdenliveSettings::osdtimecode()) {
1179 // Attach filter for on screen display of timecode
1181 QString attr = "attr_check";
1182 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1183 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1184 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1185 mlt_filter_close( filter );
1187 m_osdInfo = new Mlt::Filter("data_show");
1188 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1189 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1190 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1191 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1192 m_osdInfo->set("dynamic", "1");
1194 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1196 m_osdInfo->set("dynamic", "0");
1199 m_fps = m_mltProducer->get_fps();
1200 if (position != 0) {
1201 // Seek to correct place after opening project.
1202 m_mltProducer->seek(position);
1205 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1206 m_mltConsumer->connect(*m_mltProducer);
1207 m_mltProducer->set_speed(0);
1208 fillSlowMotionProducers();
1209 blockSignals(false);
1210 emit durationChanged(m_mltProducer->get_playtime());
1213 //kDebug()<<"// SETSCN LST, POS: "<<position;
1214 //if (position != 0) emit rendererPosition(position);
1217 void Render::checkMaxThreads()
1219 // Make sure we don't use too much threads, MLT avformat does not cope with too much threads
1220 // Currently, Kdenlive uses the following avformat threads:
1221 // One thread to get info when adding a clip
1222 // One thread to create the timeline video thumbnails
1223 // One thread to create the audio thumbnails
1224 Mlt::Service service(m_mltProducer->parent().get_service());
1225 if (service.type() != tractor_type) {
1226 kWarning() << "// TRACTOR PROBLEM";
1229 Mlt::Tractor tractor(service);
1230 int mltMaxThreads = mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1231 int requestedThreads = tractor.count() + 4;
1232 if (requestedThreads > mltMaxThreads) {
1233 mlt_service_cache_set_size(service.get_service(), "producer_avformat", requestedThreads);
1234 kDebug()<<"// MLT threads updated to: "<<mlt_service_cache_get_size(service.get_service(), "producer_avformat");
1238 const QString Render::sceneList()
1241 Mlt::Profile profile((mlt_profile) 0);
1242 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1243 m_mltProducer->optimise();
1244 xmlConsumer.set("terminate_on_pause", 1);
1245 Mlt::Producer prod(m_mltProducer->get_producer());
1246 bool split = m_isSplitView;
1247 if (split) slotSplitView(false);
1248 xmlConsumer.connect(prod);
1249 xmlConsumer.start();
1250 while (!xmlConsumer.is_stopped()) {}
1251 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1252 if (split) slotSplitView(true);
1256 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1260 doc.setContent(sceneList(), false);
1261 if (!kdenliveData.isNull()) {
1262 // add Kdenlive specific tags
1263 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1264 mlt.appendChild(doc.importNode(kdenliveData, true));
1266 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1267 kWarning() << "////// ERROR writing to file: " << path;
1270 file.write(doc.toString().toUtf8());
1271 if (file.error() != QFile::NoError) {
1279 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1281 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1282 m_mltProducer->optimise();
1283 xmlConsumer.set("terminate_on_pause", 1);
1284 if (m_name == "clip") {
1285 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1287 list.insert_at(0, prod, 0);
1289 list.set("title", desc.toUtf8().constData());
1290 xmlConsumer.connect(list);
1293 //TODO: not working yet, save zone from timeline
1294 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1295 /* Mlt::Service service(p1->parent().get_service());
1296 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1298 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1299 //prod->set("title", desc.toUtf8().constData());
1300 xmlConsumer.connect(*p1); //list);
1303 xmlConsumer.start();
1306 double Render::fps() const
1311 int Render::volume() const
1313 if (!m_mltConsumer || !m_mltProducer) return -1;
1314 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1317 void Render::slotSetVolume(int volume)
1319 if (!m_mltConsumer || !m_mltProducer) return;
1320 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1323 m_mltConsumer->set("refresh", 0);
1324 // Attach filter for on screen display of timecode
1325 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1326 mlt_properties_set_double( properties, "meta.volume", volume );
1327 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1328 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1330 if (!KdenliveSettings::osdtimecode()) {
1331 m_mltProducer->detach(*m_osdInfo);
1332 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1333 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1336 //m_osdTimer->setSingleShot(2500);
1339 void Render::slotOsdTimeout()
1341 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1342 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1343 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1344 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1348 void Render::start()
1350 m_refreshTimer.stop();
1351 QMutexLocker locker(&m_mutex);
1352 if (m_winid == -1) {
1353 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1356 if (!m_mltConsumer) return;
1357 if (m_mltConsumer->is_stopped()) {
1358 if (m_mltConsumer->start() == -1) {
1359 //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."));
1360 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1362 m_mltConsumer->purge();
1363 m_mltConsumer->set("refresh", 1);
1370 m_refreshTimer.stop();
1371 QMutexLocker locker(&m_mutex);
1372 if (m_mltProducer == NULL) return;
1373 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1374 m_mltConsumer->stop();
1375 m_mltConsumer->purge();
1378 if (m_mltProducer) {
1379 if (m_isZoneMode) resetZoneMode();
1380 m_mltProducer->set_speed(0.0);
1384 void Render::stop(const GenTime & startTime)
1386 m_refreshTimer.stop();
1387 QMutexLocker locker(&m_mutex);
1388 if (m_mltProducer) {
1389 if (m_isZoneMode) resetZoneMode();
1390 m_mltProducer->set_speed(0.0);
1391 m_mltProducer->seek((int) startTime.frames(m_fps));
1393 m_mltConsumer->purge();
1396 void Render::pause()
1398 if (!m_mltProducer || !m_mltConsumer)
1400 if (m_mltProducer->get_speed() == 0.0) return;
1401 if (m_isZoneMode) resetZoneMode();
1402 m_mltConsumer->set("refresh", 0);
1403 m_mltProducer->set_speed(0.0);
1404 m_mltConsumer->purge();
1407 void Render::switchPlay(bool play)
1409 QMutexLocker locker(&m_mutex);
1410 if (!m_mltProducer || !m_mltConsumer)
1412 if (m_isZoneMode) resetZoneMode();
1413 if (play && m_mltProducer->get_speed() == 0.0) {
1414 if (m_name == "clip" && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
1415 if (m_mltConsumer->is_stopped()) {
1416 m_mltConsumer->start();
1418 m_mltProducer->set_speed(1.0);
1419 m_mltConsumer->set("refresh", 1);
1421 m_mltProducer->set_speed(0.0);
1422 m_mltConsumer->set("refresh", 0);
1423 m_mltProducer->seek(m_mltConsumer->position());
1424 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1425 if (m_isZoneMode) resetZoneMode();
1427 //emitConsumerStopped();
1428 /*m_mltConsumer->set("refresh", 0);
1429 m_mltConsumer->stop();
1430 m_mltConsumer->purge();
1431 m_mltProducer->set_speed(0.0);
1432 //m_framePosition = m_mltProducer->position();
1433 m_mltProducer->seek(m_framePosition);
1434 emit rendererPosition(m_framePosition);*/
1438 void Render::play(double speed)
1442 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1443 m_mltProducer->set_speed(speed);
1444 /*if (speed == 0.0) {
1445 m_mltProducer->seek((int) m_framePosition + 1);
1446 m_mltConsumer->purge();
1451 void Render::play(const GenTime & startTime)
1453 if (!m_mltProducer || !m_mltConsumer)
1455 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1456 m_mltProducer->set_speed(1.0);
1457 m_mltConsumer->set("refresh", 1);
1460 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1462 if (!m_mltProducer || !m_mltConsumer)
1464 //m_mltProducer->set("eof", "loop");
1465 m_isLoopMode = true;
1466 m_loopStart = startTime;
1467 playZone(startTime, stopTime);
1470 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1472 if (!m_mltProducer || !m_mltConsumer)
1474 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1475 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1476 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1477 m_mltProducer->set_speed(1.0);
1478 m_mltConsumer->set("refresh", 1);
1479 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1480 m_isZoneMode = true;
1483 void Render::resetZoneMode()
1485 if (!m_isZoneMode && !m_isLoopMode) return;
1486 m_mltProducer->set("out", m_originalOut);
1487 //m_mltProducer->set("eof", "pause");
1488 m_isZoneMode = false;
1489 m_isLoopMode = false;
1492 void Render::seekToFrame(int pos)
1498 m_mltProducer->seek(pos);
1499 if (m_mltProducer->get_speed() == 0) {
1504 void Render::seekToFrameDiff(int diff)
1509 m_mltProducer->seek(m_mltProducer->position() + diff);
1513 void Render::doRefresh()
1515 if (m_mltProducer && m_mltProducer->get_speed() == 0) m_refreshTimer.start();
1518 void Render::refresh()
1520 QMutexLocker locker(&m_mutex);
1523 if (m_mltConsumer) {
1524 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1525 m_mltConsumer->purge();
1526 m_mltConsumer->set("refresh", 1);
1530 void Render::setDropFrames(bool show)
1532 QMutexLocker locker(&m_mutex);
1533 if (m_mltConsumer) {
1534 int dropFrames = KdenliveSettings::mltthreads();
1535 if (show == false) dropFrames = -dropFrames;
1536 m_mltConsumer->stop();
1538 m_mltConsumer->set("real_time", dropFrames);
1540 m_mltConsumer->set("play.real_time", dropFrames);
1542 if (m_mltConsumer->start() == -1) {
1543 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1549 double Render::playSpeed() const
1551 if (m_mltProducer) return m_mltProducer->get_speed();
1555 GenTime Render::seekPosition() const
1557 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1558 else return GenTime();
1561 int Render::seekFramePosition() const
1563 //if (m_mltProducer) return (int) m_mltProducer->position();
1564 if (m_mltConsumer) return (int) m_mltConsumer->position();
1568 const QString & Render::rendererName() const
1573 void Render::emitFrameUpdated(Mlt::Frame& frame)
1575 mlt_image_format format = mlt_image_rgb24;
1578 const uchar* image = frame.get_image(format, width, height);
1579 QImage qimage(width, height, QImage::Format_RGB888);
1580 memcpy(qimage.bits(), image, width * height * 3);
1581 emit frameUpdated(qimage);
1584 void Render::emitFrameNumber()
1586 if (m_mltConsumer) emit rendererPosition((int) m_mltConsumer->position());
1589 void Render::emitConsumerStopped()
1591 // This is used to know when the playing stopped
1592 if (m_mltProducer) {
1593 double pos = m_mltProducer->position();
1594 if (m_isLoopMode) play(m_loopStart);
1595 else if (m_isZoneMode) resetZoneMode();
1596 emit rendererStopped((int) pos);
1600 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1602 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1605 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1607 if (!m_mltProducer) {
1608 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1612 //int height = 1080;//KdenliveSettings::defaultheight();
1613 //int width = 1940; //KdenliveSettings::displaywidth();
1615 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1617 QPixmap pix(width, height);
1618 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1619 m_convert.set("forced", mlt_image_rgb24a);
1620 m_mltProducer->attach(m_convert);
1621 Mlt::Frame * frame = m_mltProducer->get_frame();
1622 m_mltProducer->detach(m_convert);
1624 pix = frameThumbnail(frame, width, height);
1627 pix.save(url.path(), "PNG");
1628 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1632 void Render::showFrame(Mlt::Frame& frame)
1634 emit rendererPosition((int) m_mltConsumer->position());
1635 mlt_image_format format = mlt_image_rgb24a;
1638 const uchar* image = frame.get_image(format, width, height);
1639 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1640 memcpy(qimage.scanLine(0), image, width * height * 4);
1641 emit showImageSignal(qimage);
1642 if (analyseAudio) showAudio(frame);
1643 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1644 emit frameUpdated(qimage.rgbSwapped());
1648 void Render::showAudio(Mlt::Frame& frame)
1650 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1653 mlt_audio_format audio_format = mlt_audio_s16;
1655 int num_channels = 0;
1657 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1663 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1664 // So the vector is of size samples*channels.
1665 QVector<int16_t> sampleVector(samples*num_channels);
1666 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1669 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1674 * MLT playlist direct manipulation.
1677 void Render::mltCheckLength(Mlt::Tractor *tractor)
1679 //kDebug()<<"checking track length: "<<track<<"..........";
1681 int trackNb = tractor->count();
1685 Mlt::Producer trackProducer(tractor->track(0));
1686 duration = trackProducer.get_playtime() - 1;
1687 m_mltProducer->set("out", duration);
1688 emit durationChanged(duration);
1691 while (trackNb > 1) {
1692 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1693 trackDuration = trackProducer.get_playtime() - 1;
1694 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1695 if (trackDuration > duration) duration = trackDuration;
1699 Mlt::Producer blackTrackProducer(tractor->track(0));
1701 if (blackTrackProducer.get_playtime() - 1 != duration) {
1702 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1703 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1704 if (blackclip && blackclip->is_blank()) {
1709 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1710 if (blackclip) delete blackclip;
1711 blackTrackPlaylist.clear();
1712 m_blackClip->set("length", duration + 1);
1713 m_blackClip->set("out", duration);
1714 blackclip = m_blackClip->cut(0, duration);
1715 blackTrackPlaylist.insert_at(0, blackclip, 1);
1717 if (duration > blackclip->parent().get_length()) {
1718 blackclip->parent().set("length", duration + 1);
1719 blackclip->parent().set("out", duration);
1720 blackclip->set("length", duration + 1);
1722 blackTrackPlaylist.resize_clip(0, 0, duration);
1726 m_mltProducer->set("out", duration);
1727 emit durationChanged(duration);
1731 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1733 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1735 // We want a slowmotion producer
1736 double speed = element.attribute("speed", "1.0").toDouble();
1737 int strobe = element.attribute("strobe", "1").toInt();
1738 QString url = QString::fromUtf8(prod->get("resource"));
1739 url.append('?' + locale.toString(speed));
1740 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1741 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1742 if (!slowprod || slowprod->get_producer() == NULL) {
1743 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
1744 if (strobe > 1) slowprod->set("strobe", strobe);
1745 QString id = prod->parent().get("id");
1746 if (id.contains('_')) id = id.section('_', 0, 0);
1747 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
1748 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1749 slowprod->set("id", producerid.toUtf8().constData());
1750 m_slowmotionProducers.insert(url, slowprod);
1755 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1757 if (m_mltProducer == NULL) {
1758 kDebug() << "PLAYLIST NOT INITIALISED //////";
1762 kDebug() << "Cannot insert clip without producer //////";
1765 Mlt::Producer parentProd(m_mltProducer->parent());
1766 if (parentProd.get_producer() == NULL) {
1767 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1771 Mlt::Service service(parentProd.get_service());
1772 if (service.type() != tractor_type) {
1773 kWarning() << "// TRACTOR PROBLEM";
1776 Mlt::Tractor tractor(service);
1777 if (info.track > tractor.count() - 1) {
1778 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1782 Mlt::Producer trackProducer(tractor.track(info.track));
1783 int trackDuration = trackProducer.get_playtime() - 1;
1784 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1785 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1786 prod = checkSlowMotionProducer(prod, element);
1787 if (prod == NULL || !prod->is_valid()) {
1792 int cutPos = (int) info.cropStart.frames(m_fps);
1793 if (cutPos < 0) cutPos = 0;
1794 int insertPos = (int) info.startPos.frames(m_fps);
1795 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1796 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1797 if (overwrite && (insertPos < trackDuration)) {
1798 // Replace zone with blanks
1799 //trackPlaylist.split_at(insertPos, true);
1800 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1801 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1802 trackPlaylist.insert_blank(clipIndex, cutDuration);
1804 trackPlaylist.split_at(insertPos, true);
1805 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1806 trackPlaylist.insert_blank(clipIndex, cutDuration);
1808 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1810 /*if (QString(prod->get("transparency")).toInt() == 1)
1811 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1813 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1815 /*tractor.multitrack()->refresh();
1816 tractor.refresh();*/
1821 void Render::mltCutClip(int track, GenTime position)
1823 Mlt::Service service(m_mltProducer->parent().get_service());
1824 if (service.type() != tractor_type) {
1825 kWarning() << "// TRACTOR PROBLEM";
1829 Mlt::Tractor tractor(service);
1830 Mlt::Producer trackProducer(tractor.track(track));
1831 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1834 /* // Display playlist info
1835 kDebug()<<"//////////// BEFORE";
1836 for (int i = 0; i < trackPlaylist.count(); i++) {
1837 int blankStart = trackPlaylist.clip_start(i);
1838 int blankDuration = trackPlaylist.clip_length(i) - 1;
1840 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1841 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1844 int cutPos = (int) position.frames(m_fps);
1846 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1847 if (trackPlaylist.is_blank(clipIndex)) {
1848 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1852 int clipStart = trackPlaylist.clip_start(clipIndex);
1853 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1856 // duplicate effects
1857 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1858 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1860 if (original == NULL || clip == NULL) {
1861 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1863 Mlt::Service clipService(original->get_service());
1864 Mlt::Service dupService(clip->get_service());
1868 Mlt::Filter *filter = clipService.filter(ct);
1870 // Only duplicate Kdenlive filters, and skip the fade in effects
1871 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1872 // looks like there is no easy way to duplicate a filter,
1873 // so we will create a new one and duplicate its properties
1874 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1875 if (dup && dup->is_valid()) {
1876 Mlt::Properties entries(filter->get_properties());
1877 for (int i = 0; i < entries.count(); i++) {
1878 dup->set(entries.get_name(i), entries.get(i));
1880 dupService.attach(*dup);
1884 filter = clipService.filter(ct);
1887 /* // Display playlist info
1888 kDebug()<<"//////////// AFTER";
1889 for (int i = 0; i < trackPlaylist.count(); i++) {
1890 int blankStart = trackPlaylist.clip_start(i);
1891 int blankDuration = trackPlaylist.clip_length(i) - 1;
1893 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1894 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1899 Mlt::Tractor *Render::lockService()
1901 // we are going to replace some clips, purge consumer
1902 QMutexLocker locker(&m_mutex);
1903 if (!m_mltProducer) return NULL;
1904 if (m_mltConsumer) {
1905 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
1906 m_mltConsumer->purge();
1908 Mlt::Service service(m_mltProducer->parent().get_service());
1909 if (service.type() != tractor_type) {
1910 kWarning() << "// TRACTOR PROBLEM";
1914 return new Mlt::Tractor(service);
1918 void Render::unlockService(Mlt::Tractor *tractor)
1923 if (!m_mltProducer) return;
1924 Mlt::Service service(m_mltProducer->parent().get_service());
1925 if (service.type() != tractor_type) {
1926 kWarning() << "// TRACTOR PROBLEM";
1932 bool Render::mltUpdateClip(Mlt::Tractor *tractor, ItemInfo info, QDomElement element, Mlt::Producer *prod)
1935 if (prod == NULL || tractor == NULL) {
1936 kDebug() << "Cannot update clip with null producer //////";
1940 Mlt::Producer trackProducer(tractor->track(tractor->count() - 1 - info.track));
1941 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1942 int startPos = info.startPos.frames(m_fps);
1943 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1944 if (trackPlaylist.is_blank(clipIndex)) {
1945 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1948 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1950 QList <Mlt::Filter *> filtersList;
1951 Mlt::Service sourceService(clip->get_service());
1953 Mlt::Filter *filter = sourceService.filter(ct);
1955 if (filter->get_int("kdenlive_ix") != 0) {
1956 filtersList.append(filter);
1959 filter = sourceService.filter(ct);
1962 clip = trackPlaylist.replace_with_blank(clipIndex);
1964 prod = checkSlowMotionProducer(prod, element);
1965 if (prod == NULL || !prod->is_valid()) {
1969 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
1970 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1971 Mlt::Service destService(clip2->get_service());
1974 if (!filtersList.isEmpty()) {
1975 for (int i = 0; i < filtersList.count(); i++)
1976 destService.attach(*(filtersList.at(i)));
1982 bool Render::mltRemoveClip(int track, GenTime position)
1984 Mlt::Service service(m_mltProducer->parent().get_service());
1985 if (service.type() != tractor_type) {
1986 kWarning() << "// TRACTOR PROBLEM";
1990 Mlt::Tractor tractor(service);
1991 Mlt::Producer trackProducer(tractor.track(track));
1992 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1993 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1995 if (trackPlaylist.is_blank(clipIndex)) {
1996 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
2000 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2001 if (clip) delete clip;
2002 trackPlaylist.consolidate_blanks(0);
2004 /* // Display playlist info
2005 kDebug()<<"//// AFTER";
2006 for (int i = 0; i < trackPlaylist.count(); i++) {
2007 int blankStart = trackPlaylist.clip_start(i);
2008 int blankDuration = trackPlaylist.clip_length(i) - 1;
2010 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2011 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2014 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
2018 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
2020 if (!m_mltProducer) {
2021 kDebug() << "PLAYLIST NOT INITIALISED //////";
2024 Mlt::Producer parentProd(m_mltProducer->parent());
2025 if (parentProd.get_producer() == NULL) {
2026 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2030 Mlt::Service service(parentProd.get_service());
2031 Mlt::Tractor tractor(service);
2032 int insertPos = pos.frames(m_fps);
2034 Mlt::Producer trackProducer(tractor.track(track));
2035 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2036 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2037 if (clipIndex == trackPlaylist.count()) {
2038 // We are after the end of the playlist
2041 if (!trackPlaylist.is_blank(clipIndex)) return 0;
2042 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
2043 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
2046 int Render::mltTrackDuration(int track)
2048 if (!m_mltProducer) {
2049 kDebug() << "PLAYLIST NOT INITIALISED //////";
2052 Mlt::Producer parentProd(m_mltProducer->parent());
2053 if (parentProd.get_producer() == NULL) {
2054 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2058 Mlt::Service service(parentProd.get_service());
2059 Mlt::Tractor tractor(service);
2061 Mlt::Producer trackProducer(tractor.track(track));
2062 return trackProducer.get_playtime() - 1;
2065 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
2067 if (!m_mltProducer) {
2068 kDebug() << "PLAYLIST NOT INITIALISED //////";
2071 Mlt::Producer parentProd(m_mltProducer->parent());
2072 if (parentProd.get_producer() == NULL) {
2073 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
2076 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
2077 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
2079 Mlt::Service service(parentProd.get_service());
2080 Mlt::Tractor tractor(service);
2082 int diff = duration.frames(m_fps);
2083 int offset = timeOffset.frames(m_fps);
2087 // insert space in one track only
2088 Mlt::Producer trackProducer(tractor.track(track));
2089 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2090 insertPos = trackClipStartList.value(track);
2091 if (insertPos != -1) {
2092 insertPos += offset;
2093 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2095 trackPlaylist.insert_blank(clipIndex, diff - 1);
2097 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
2098 if (!trackPlaylist.is_blank(clipIndex)) {
2099 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2101 int position = trackPlaylist.clip_start(clipIndex);
2102 int blankDuration = trackPlaylist.clip_length(clipIndex);
2103 if (blankDuration + diff == 0) {
2104 trackPlaylist.remove(clipIndex);
2105 } else trackPlaylist.remove_region(position, -diff);
2107 trackPlaylist.consolidate_blanks(0);
2109 // now move transitions
2110 mlt_service serv = m_mltProducer->parent().get_service();
2111 mlt_service nextservice = mlt_service_get_producer(serv);
2112 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2113 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2114 QString resource = mlt_properties_get(properties, "mlt_service");
2116 while (mlt_type == "transition") {
2117 mlt_transition tr = (mlt_transition) nextservice;
2118 int currentTrack = mlt_transition_get_b_track(tr);
2119 int currentIn = (int) mlt_transition_get_in(tr);
2120 int currentOut = (int) mlt_transition_get_out(tr);
2121 insertPos = trackTransitionStartList.value(track);
2122 if (insertPos != -1) {
2123 insertPos += offset;
2124 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
2125 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2128 nextservice = mlt_service_producer(nextservice);
2129 if (nextservice == NULL) break;
2130 properties = MLT_SERVICE_PROPERTIES(nextservice);
2131 mlt_type = mlt_properties_get(properties, "mlt_type");
2132 resource = mlt_properties_get(properties, "mlt_service");
2135 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
2136 Mlt::Producer trackProducer(tractor.track(trackNb));
2137 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2139 //int clipNb = trackPlaylist.count();
2140 insertPos = trackClipStartList.value(trackNb);
2141 if (insertPos != -1) {
2142 insertPos += offset;
2144 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2145 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2146 for (int i = 0; i < clipNb; i++) {
2147 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2148 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2149 kDebug()<<"-------------";
2151 kDebug()<<"END-------------";*/
2154 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2156 trackPlaylist.insert_blank(clipIndex, diff - 1);
2158 if (!trackPlaylist.is_blank(clipIndex)) {
2161 if (!trackPlaylist.is_blank(clipIndex)) {
2162 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2164 int position = trackPlaylist.clip_start(clipIndex);
2165 int blankDuration = trackPlaylist.clip_length(clipIndex);
2166 if (diff + blankDuration == 0) {
2167 trackPlaylist.remove(clipIndex);
2168 } else trackPlaylist.remove_region(position, - diff);
2170 trackPlaylist.consolidate_blanks(0);
2173 // now move transitions
2174 mlt_service serv = m_mltProducer->parent().get_service();
2175 mlt_service nextservice = mlt_service_get_producer(serv);
2176 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2177 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2178 QString resource = mlt_properties_get(properties, "mlt_service");
2180 while (mlt_type == "transition") {
2181 mlt_transition tr = (mlt_transition) nextservice;
2182 int currentIn = (int) mlt_transition_get_in(tr);
2183 int currentOut = (int) mlt_transition_get_out(tr);
2184 int currentTrack = mlt_transition_get_b_track(tr);
2185 insertPos = trackTransitionStartList.value(currentTrack);
2186 if (insertPos != -1) {
2187 insertPos += offset;
2188 if (currentOut > insertPos && resource != "mix") {
2189 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2192 nextservice = mlt_service_producer(nextservice);
2193 if (nextservice == NULL) break;
2194 properties = MLT_SERVICE_PROPERTIES(nextservice);
2195 mlt_type = mlt_properties_get(properties, "mlt_type");
2196 resource = mlt_properties_get(properties, "mlt_service");
2200 mltCheckLength(&tractor);
2201 m_mltConsumer->set("refresh", 1);
2205 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2207 if (source == dest) return;
2208 Mlt::Service sourceService(source->get_service());
2209 Mlt::Service destService(dest->get_service());
2211 // move all effects to the correct producer
2213 Mlt::Filter *filter = sourceService.filter(ct);
2215 if (filter->get_int("kdenlive_ix") != 0) {
2216 sourceService.detach(*filter);
2217 destService.attach(*filter);
2219 filter = sourceService.filter(ct);
2223 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2226 Mlt::Service service(m_mltProducer->parent().get_service());
2227 if (service.type() != tractor_type) {
2228 kWarning() << "// TRACTOR PROBLEM";
2232 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2233 Mlt::Tractor tractor(service);
2234 Mlt::Producer trackProducer(tractor.track(info.track));
2235 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2236 int startPos = info.startPos.frames(m_fps);
2237 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2238 int clipLength = trackPlaylist.clip_length(clipIndex);
2240 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2241 if (original == NULL) {
2244 if (!original->is_valid() || original->is_blank()) {
2249 Mlt::Producer clipparent = original->parent();
2250 if (!clipparent.is_valid() || clipparent.is_blank()) {
2256 QString serv = clipparent.get("mlt_service");
2257 QString id = clipparent.get("id");
2258 if (speed <= 0 && speed > -1) speed = 1.0;
2259 //kDebug() << "CLIP SERVICE: " << serv;
2260 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2262 QString url = QString::fromUtf8(clipparent.get("resource"));
2263 url.append('?' + m_locale.toString(speed));
2264 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2265 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2266 if (!slowprod || slowprod->get_producer() == NULL) {
2267 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2268 if (strobe > 1) slowprod->set("strobe", strobe);
2269 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2270 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2271 slowprod->set("id", producerid.toUtf8().constData());
2272 // copy producer props
2273 double ar = original->parent().get_double("force_aspect_ratio");
2274 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2275 double fps = original->parent().get_double("force_fps");
2276 if (fps != 0.0) slowprod->set("force_fps", fps);
2277 int threads = original->parent().get_int("threads");
2278 if (threads != 0) slowprod->set("threads", threads);
2279 if (original->parent().get("force_progressive"))
2280 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2281 if (original->parent().get("force_tff"))
2282 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2283 int ix = original->parent().get_int("video_index");
2284 if (ix != 0) slowprod->set("video_index", ix);
2285 int colorspace = original->parent().get_int("force_colorspace");
2286 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2287 int full_luma = original->parent().get_int("set.force_full_luma");
2288 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2289 m_slowmotionProducers.insert(url, slowprod);
2291 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2292 trackPlaylist.consolidate_blanks(0);
2294 // Check that the blank space is long enough for our new duration
2295 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2296 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2298 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2299 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2300 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2301 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2303 // move all effects to the correct producer
2304 mltPasteEffects(clip, cut);
2305 trackPlaylist.insert_at(startPos, cut, 1);
2308 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2309 newLength = trackPlaylist.clip_length(clipIndex);
2311 } else if (speed == 1.0 && strobe < 2) {
2314 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2315 trackPlaylist.consolidate_blanks(0);
2317 // Check that the blank space is long enough for our new duration
2318 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2319 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2322 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2323 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2324 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2325 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2326 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2328 // move all effects to the correct producer
2329 mltPasteEffects(clip, cut);
2331 trackPlaylist.insert_at(startPos, cut, 1);
2334 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2335 newLength = trackPlaylist.clip_length(clipIndex);
2338 } else if (serv == "framebuffer") {
2340 QString url = QString::fromUtf8(clipparent.get("resource"));
2341 url = url.section('?', 0, 0);
2342 url.append('?' + m_locale.toString(speed));
2343 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2344 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2345 if (!slowprod || slowprod->get_producer() == NULL) {
2346 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2347 slowprod->set("strobe", strobe);
2348 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2349 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2350 slowprod->set("id", producerid.toUtf8().constData());
2351 // copy producer props
2352 double ar = original->parent().get_double("force_aspect_ratio");
2353 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2354 double fps = original->parent().get_double("force_fps");
2355 if (fps != 0.0) slowprod->set("force_fps", fps);
2356 if (original->parent().get("force_progressive"))
2357 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2358 if (original->parent().get("force_tff"))
2359 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2360 int threads = original->parent().get_int("threads");
2361 if (threads != 0) slowprod->set("threads", threads);
2362 int ix = original->parent().get_int("video_index");
2363 if (ix != 0) slowprod->set("video_index", ix);
2364 int colorspace = original->parent().get_int("force_colorspace");
2365 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2366 int full_luma = original->parent().get_int("set.force_full_luma");
2367 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2368 m_slowmotionProducers.insert(url, slowprod);
2370 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2371 trackPlaylist.consolidate_blanks(0);
2373 GenTime duration = speedIndependantInfo.cropDuration / speed;
2374 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2376 // Check that the blank space is long enough for our new duration
2377 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2378 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2381 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2382 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2383 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2384 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2386 // move all effects to the correct producer
2387 mltPasteEffects(clip, cut);
2389 trackPlaylist.insert_at(startPos, cut, 1);
2392 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2393 newLength = trackPlaylist.clip_length(clipIndex);
2398 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2402 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2404 Mlt::Service service(m_mltProducer->parent().get_service());
2405 bool success = false;
2406 Mlt::Tractor tractor(service);
2407 Mlt::Producer trackProducer(tractor.track(track));
2408 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2409 Mlt::Service clipService(trackPlaylist.get_service());
2413 Mlt::Filter *filter = clipService.filter(ct);
2415 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2416 if (clipService.detach(*filter) == 0) success = true;
2417 } else if (updateIndex) {
2418 // Adjust the other effects index
2419 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2422 filter = clipService.filter(ct);
2429 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2431 if (position < GenTime()) {
2432 // Remove track effect
2433 return mltRemoveTrackEffect(track, index, updateIndex);
2435 Mlt::Service service(m_mltProducer->parent().get_service());
2436 bool success = false;
2437 Mlt::Tractor tractor(service);
2438 Mlt::Producer trackProducer(tractor.track(track));
2439 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2441 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2442 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2444 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2448 Mlt::Service clipService(clip->get_service());
2449 int duration = clip->get_playtime();
2451 // Check if clip is visible in monitor
2452 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2453 if (diff < 0 || diff > duration) doRefresh = false;
2459 Mlt::Filter *filter = clipService.filter(ct);
2461 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2462 if (clipService.detach(*filter) == 0) success = true;
2463 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2464 } else if (updateIndex) {
2465 // Adjust the other effects index
2466 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2469 filter = clipService.filter(ct);
2472 if (doRefresh) refresh();
2476 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2478 Mlt::Service service(m_mltProducer->parent().get_service());
2479 Mlt::Tractor tractor(service);
2480 Mlt::Producer trackProducer(tractor.track(track));
2481 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2482 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2483 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2487 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2490 Mlt::Service service(m_mltProducer->parent().get_service());
2492 Mlt::Tractor tractor(service);
2493 Mlt::Producer trackProducer(tractor.track(track));
2494 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2496 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2497 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2502 Mlt::Service clipService(clip->get_service());
2503 int duration = clip->get_playtime();
2505 // Check if clip is visible in monitor
2506 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2507 if (diff < 0 || diff > duration) doRefresh = false;
2510 return mltAddEffect(clipService, params, duration, doRefresh);
2513 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2515 bool updateIndex = false;
2516 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2517 const QString region = params.paramValue("region");
2521 Mlt::Filter *filter = service.filter(ct);
2523 if (filter->get_int("kdenlive_ix") == filter_ix) {
2524 // A filter at that position already existed, so we will increase all indexes later
2529 filter = service.filter(ct);
2532 if (params.paramValue("id") == "speed") {
2533 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2535 filter = service.filter(ct);
2537 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2538 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2541 filter = service.filter(ct);
2544 if (doRefresh) refresh();
2549 // temporarily remove all effects after insert point
2550 QList <Mlt::Filter *> filtersList;
2552 filter = service.filter(ct);
2554 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2555 filtersList.append(filter);
2556 service.detach(*filter);
2558 filter = service.filter(ct);
2562 QString tag = params.paramValue("tag");
2563 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2564 char *filterTag = qstrdup(tag.toUtf8().constData());
2565 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2566 QHash<QString, QString>::Iterator it;
2567 QString kfr = params.paramValue("keyframes");
2569 if (!kfr.isEmpty()) {
2570 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2571 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2572 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2573 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2574 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2575 //double max = params.paramValue("max").toDouble();
2576 double min = params.paramValue("min").toDouble();
2577 double factor = params.paramValue("factor", "1").toDouble();
2578 double paramOffset = params.paramValue("offset", "0").toDouble();
2579 params.removeParam("starttag");
2580 params.removeParam("endtag");
2581 params.removeParam("keyframes");
2582 params.removeParam("min");
2583 params.removeParam("max");
2584 params.removeParam("factor");
2585 params.removeParam("offset");
2587 // Special case, only one keyframe, means we want a constant value
2588 if (keyFrames.count() == 1) {
2589 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2590 if (filter && filter->is_valid()) {
2591 filter->set("kdenlive_id", filterId);
2592 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2593 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2594 for (int j = 0; j < params.count(); j++) {
2595 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2597 filter->set("in", x1);
2598 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2599 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2600 service.attach(*filter);
2602 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2603 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2604 if (filter && filter->is_valid()) {
2605 filter->set("kdenlive_id", filterId);
2606 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2607 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2608 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2609 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2610 if (x2 == -1) x2 = duration;
2612 for (int j = 0; j < params.count(); j++) {
2613 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2616 filter->set("in", x1);
2617 filter->set("out", x2);
2618 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2619 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2620 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2621 service.attach(*filter);
2628 Mlt::Filter *filter;
2630 if (!region.isEmpty()) {
2631 filter = new Mlt::Filter(*m_mltProfile, "region");
2632 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2633 if (filter && filter->is_valid()) {
2634 filter->set("kdenlive_id", filterId);
2635 if (!region.isEmpty()) {
2636 filter->set("resource", region.toUtf8().constData());
2637 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2638 filter->set("filter0", filterTag);
2639 prefix = "filter0.";
2640 params.removeParam("id");
2641 params.removeParam("region");
2642 params.removeParam("kdenlive_ix");
2645 kDebug() << "filter is NULL";
2649 params.removeParam("kdenlive_id");
2650 if (params.hasParam("_sync_in_out")) {
2651 // This effect must sync in / out with parent clip
2652 params.removeParam("_sync_in_out");
2653 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2656 for (int j = 0; j < params.count(); j++) {
2657 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2661 QString effectArgs = params.paramValue("id").section('_', 1);
2663 params.removeParam("id");
2664 params.removeParam("kdenlive_ix");
2665 params.removeParam("tag");
2666 params.removeParam("disable");
2667 params.removeParam("region");
2669 for (int j = 0; j < params.count(); j++) {
2670 effectArgs.append(' ' + params.at(j).value());
2672 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2673 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2676 // attach filter to the clip
2677 service.attach(*filter);
2682 // re-add following filters
2683 for (int i = 0; i < filtersList.count(); i++) {
2684 Mlt::Filter *filter = filtersList.at(i);
2686 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2687 service.attach(*filter);
2690 if (doRefresh) refresh();
2694 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2696 Mlt::Service service(m_mltProducer->parent().get_service());
2697 Mlt::Tractor tractor(service);
2698 Mlt::Producer trackProducer(tractor.track(track));
2699 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2700 Mlt::Service clipService(trackPlaylist.get_service());
2702 QString index = params.paramValue("kdenlive_ix");
2703 QString tag = params.paramValue("tag");
2705 Mlt::Filter *filter = clipService.filter(ct);
2707 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2711 filter = clipService.filter(ct);
2715 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2716 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2718 bool success = false;//mltAddTrackEffect(track, params);
2722 QString ser = filter->get("mlt_service");
2723 if (ser == "region") prefix = "filter0.";
2725 for (int j = 0; j < params.count(); j++) {
2726 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2735 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2737 int index = params.paramValue("kdenlive_ix").toInt();
2738 QString tag = params.paramValue("tag");
2740 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2741 // This is a keyframe effect, to edit it, we remove it and re-add it.
2742 bool success = mltRemoveEffect(track, position, index, false);
2743 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
2744 if (position < GenTime())
2745 success = mltAddTrackEffect(track, params);
2747 success = mltAddEffect(track, position, params);
2748 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
2751 if (position < GenTime()) {
2752 return mltEditTrackEffect(track, params);
2755 Mlt::Service service(m_mltProducer->parent().get_service());
2756 Mlt::Tractor tractor(service);
2757 Mlt::Producer trackProducer(tractor.track(track));
2758 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2760 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2761 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2763 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2767 int duration = clip->get_playtime();
2768 bool doRefresh = true;
2769 // Check if clip is visible in monitor
2770 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2771 if (diff < 0 || diff > duration)
2775 Mlt::Filter *filter = clip->filter(ct);
2777 if (filter->get_int("kdenlive_ix") == index) {
2781 filter = clip->filter(ct);
2785 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2786 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2788 bool success = mltAddEffect(track, position, params);
2792 QString ser = filter->get("mlt_service");
2793 if (ser == "region") prefix = "filter0.";
2794 if (params.hasParam("_sync_in_out")) {
2795 // This effect must sync in / out with parent clip
2796 params.removeParam("_sync_in_out");
2797 filter->set_in_and_out(clip->get_in(), clip->get_out());
2800 for (int j = 0; j < params.count(); j++) {
2801 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2807 if (doRefresh) refresh();
2811 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2813 Mlt::Service service(m_mltProducer->parent().get_service());
2814 Mlt::Tractor tractor(service);
2815 Mlt::Producer trackProducer(tractor.track(track));
2816 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2818 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2819 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2821 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2825 Mlt::Service clipService(clip->get_service());
2826 int duration = clip->get_playtime();
2827 bool doRefresh = true;
2828 // Check if clip is visible in monitor
2829 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2830 if (diff < 0 || diff > duration) doRefresh = false;
2834 Mlt::Filter *filter = clipService.filter(ct);
2836 int pos = filter->get_int("kdenlive_ix");
2837 if (pos == oldPos) {
2838 filter->set("kdenlive_ix", newPos);
2840 filter = clipService.filter(ct);
2842 if (doRefresh) refresh();
2845 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2847 if (position < GenTime()) {
2848 mltMoveTrackEffect(track, oldPos, newPos);
2851 Mlt::Service service(m_mltProducer->parent().get_service());
2852 Mlt::Tractor tractor(service);
2853 Mlt::Producer trackProducer(tractor.track(track));
2854 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2856 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2857 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2859 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2863 Mlt::Service clipService(clip->get_service());
2864 int duration = clip->get_playtime();
2865 bool doRefresh = true;
2866 // Check if clip is visible in monitor
2867 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2868 if (diff < 0 || diff > duration) doRefresh = false;
2872 QList <Mlt::Filter *> filtersList;
2873 Mlt::Filter *filter = clipService.filter(ct);
2875 if (newPos > oldPos) {
2877 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2878 filter->set("kdenlive_ix", newPos);
2879 filtersList.append(filter);
2880 clipService.detach(*filter);
2881 filter = clipService.filter(ct);
2882 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2883 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2885 filter = clipService.filter(ct);
2889 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2890 filtersList.append(filter);
2891 clipService.detach(*filter);
2893 filter = clipService.filter(ct);
2897 if (filter->get_int("kdenlive_ix") == oldPos) {
2898 filter->set("kdenlive_ix", newPos);
2899 filtersList.append(filter);
2900 clipService.detach(*filter);
2902 filter = clipService.filter(ct);
2906 filter = clipService.filter(ct);
2908 int pos = filter->get_int("kdenlive_ix");
2909 if (pos >= newPos) {
2910 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2911 filtersList.append(filter);
2912 clipService.detach(*filter);
2914 filter = clipService.filter(ct);
2918 for (int i = 0; i < filtersList.count(); i++) {
2919 clipService.attach(*(filtersList.at(i)));
2922 if (doRefresh) refresh();
2925 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2927 Mlt::Service service(m_mltProducer->parent().get_service());
2928 Mlt::Tractor tractor(service);
2929 Mlt::Producer trackProducer(tractor.track(track));
2930 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2931 Mlt::Service clipService(trackPlaylist.get_service());
2933 QList <Mlt::Filter *> filtersList;
2934 Mlt::Filter *filter = clipService.filter(ct);
2936 if (newPos > oldPos) {
2938 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2939 filter->set("kdenlive_ix", newPos);
2940 filtersList.append(filter);
2941 clipService.detach(*filter);
2942 filter = clipService.filter(ct);
2943 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2944 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2946 filter = clipService.filter(ct);
2950 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2951 filtersList.append(filter);
2952 clipService.detach(*filter);
2954 filter = clipService.filter(ct);
2958 if (filter->get_int("kdenlive_ix") == oldPos) {
2959 filter->set("kdenlive_ix", newPos);
2960 filtersList.append(filter);
2961 clipService.detach(*filter);
2963 filter = clipService.filter(ct);
2967 filter = clipService.filter(ct);
2969 int pos = filter->get_int("kdenlive_ix");
2970 if (pos >= newPos) {
2971 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2972 filtersList.append(filter);
2973 clipService.detach(*filter);
2975 filter = clipService.filter(ct);
2979 for (int i = 0; i < filtersList.count(); i++) {
2980 clipService.attach(*(filtersList.at(i)));
2985 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2987 Mlt::Service service(m_mltProducer->parent().get_service());
2988 Mlt::Tractor tractor(service);
2989 Mlt::Producer trackProducer(tractor.track(info.track));
2990 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2992 /* // Display playlist info
2993 kDebug()<<"//////////// BEFORE RESIZE";
2994 for (int i = 0; i < trackPlaylist.count(); i++) {
2995 int blankStart = trackPlaylist.clip_start(i);
2996 int blankDuration = trackPlaylist.clip_length(i) - 1;
2998 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2999 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
3002 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
3003 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3007 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
3008 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
3009 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3011 int previousStart = clip->get_in();
3012 int newDuration = (int) clipDuration.frames(m_fps) - 1;
3013 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
3015 int currentOut = newDuration + previousStart;
3016 if (currentOut > clip->get_length()) {
3017 clip->parent().set("length", currentOut + 1);
3018 clip->parent().set("out", currentOut);
3019 clip->set("length", currentOut + 1);
3022 /*if (newDuration > clip->get_out()) {
3023 clip->parent().set_in_and_out(0, newDuration + 1);
3024 clip->set_in_and_out(0, newDuration + 1);
3027 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
3028 trackPlaylist.consolidate_blanks(0);
3029 // skip to next clip
3031 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
3033 // clip was made longer, trim next blank if there is one.
3034 if (clipIndex < trackPlaylist.count()) {
3035 // If this is not the last clip in playlist
3036 if (trackPlaylist.is_blank(clipIndex)) {
3037 int blankStart = trackPlaylist.clip_start(clipIndex);
3038 int blankDuration = trackPlaylist.clip_length(clipIndex);
3039 if (diff > blankDuration) {
3040 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
3042 if (diff - blankDuration == 0) {
3043 trackPlaylist.remove(clipIndex);
3044 } else trackPlaylist.remove_region(blankStart, diff);
3046 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
3049 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
3050 trackPlaylist.consolidate_blanks(0);
3053 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
3054 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3055 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
3056 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3057 ItemInfo transpinfo;
3058 transpinfo.startPos = info.startPos;
3059 transpinfo.endPos = info.startPos + clipDuration;
3060 transpinfo.track = info.track;
3061 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3063 m_mltConsumer->set("refresh", 1);
3067 void Render::mltChangeTrackState(int track, bool mute, bool blind)
3069 Mlt::Service service(m_mltProducer->parent().get_service());
3070 Mlt::Tractor tractor(service);
3071 Mlt::Producer trackProducer(tractor.track(track));
3073 // Make sure muting will not produce problems with our audio mixing transition,
3074 // because audio mixing is done between each track and the lowest one
3075 bool audioMixingBroken = false;
3076 if (mute && trackProducer.get_int("hide") < 2 ) {
3077 // We mute a track with sound
3078 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3079 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
3081 else if (!mute && trackProducer.get_int("hide") > 1 ) {
3082 // We un-mute a previously muted track
3083 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
3087 if (blind) trackProducer.set("hide", 3);
3088 else trackProducer.set("hide", 2);
3090 trackProducer.set("hide", 1);
3092 trackProducer.set("hide", 0);
3094 if (audioMixingBroken) fixAudioMixing(tractor);
3096 tractor.multitrack()->refresh();
3101 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
3103 for (int i = 1; i < tractor.count(); i++) {
3104 Mlt::Producer trackProducer(tractor.track(i));
3105 if (trackProducer.get_int("hide") < 2) return i;
3107 return tractor.count() - 1;
3110 void Render::fixAudioMixing(Mlt::Tractor tractor)
3112 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
3113 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
3115 mlt_service serv = m_mltProducer->parent().get_service();
3116 Mlt::Field *field = tractor.field();
3117 mlt_service_lock(serv);
3119 mlt_service nextservice = mlt_service_get_producer(serv);
3120 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3121 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3122 QString resource = mlt_properties_get(properties, "mlt_service");
3124 mlt_service nextservicetodisconnect;
3125 // Delete all audio mixing transitions
3126 while (mlt_type == "transition") {
3127 if (resource == "mix") {
3128 nextservicetodisconnect = nextservice;
3129 nextservice = mlt_service_producer(nextservice);
3130 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
3132 else nextservice = mlt_service_producer(nextservice);
3133 if (nextservice == NULL) break;
3134 properties = MLT_SERVICE_PROPERTIES(nextservice);
3135 mlt_type = mlt_properties_get(properties, "mlt_type");
3136 resource = mlt_properties_get(properties, "mlt_service");
3139 // Re-add correct audio transitions
3140 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
3141 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3142 transition->set("always_active", 1);
3143 transition->set("combine", 1);
3144 transition->set("internal_added", 237);
3145 field->plant_transition(*transition, lowestTrack, i);
3147 mlt_service_unlock(serv);
3150 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
3152 Mlt::Service service(m_mltProducer->parent().get_service());
3153 int frameOffset = (int) diff.frames(m_fps);
3154 Mlt::Tractor tractor(service);
3155 Mlt::Producer trackProducer(tractor.track(info.track));
3156 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3157 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3158 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3162 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3163 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3165 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3169 int previousStart = clip->get_in();
3170 int previousOut = clip->get_out();
3172 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
3174 m_mltConsumer->set("refresh", 1);
3178 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3180 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3181 Mlt::Service service(m_mltProducer->parent().get_service());
3182 int moveFrame = (int) diff.frames(m_fps);
3183 Mlt::Tractor tractor(service);
3184 Mlt::Producer trackProducer(tractor.track(info.track));
3185 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3186 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3187 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3191 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3192 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3193 if (clip == NULL || clip->is_blank()) {
3194 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3198 int previousStart = clip->get_in();
3199 int previousOut = clip->get_out();
3201 previousStart += moveFrame;
3203 if (previousStart < 0) {
3204 // this is possible for images and color clips
3205 previousOut -= previousStart;
3209 int length = previousOut + 1;
3210 if (length > clip->get_length()) {
3211 clip->parent().set("length", length + 1);
3212 clip->parent().set("out", length);
3213 clip->set("length", length + 1);
3217 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3218 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3219 if (moveFrame > 0) {
3220 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3222 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3223 int blankIndex = clipIndex - 1;
3224 int blankLength = trackPlaylist.clip_length(blankIndex);
3225 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3226 if (! trackPlaylist.is_blank(blankIndex)) {
3227 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3229 if (blankLength + moveFrame == 0)
3230 trackPlaylist.remove(blankIndex);
3232 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3234 trackPlaylist.consolidate_blanks(0);
3235 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3236 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3237 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3238 ItemInfo transpinfo;
3239 transpinfo.startPos = info.startPos + diff;
3240 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3241 transpinfo.track = info.track;
3242 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3244 //m_mltConsumer->set("refresh", 1);
3246 m_mltConsumer->set("refresh", 1);
3250 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3252 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3256 bool Render::mltUpdateClipProducer(Mlt::Tractor *tractor, int track, int pos, Mlt::Producer *prod)
3258 if (prod == NULL || !prod->is_valid() || tractor == NULL || !tractor->is_valid()) {
3259 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3263 Mlt::Producer trackProducer(tractor->track(track));
3264 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3265 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3266 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3267 if (clipProducer == NULL || clipProducer->is_blank()) {
3268 kDebug() << "// ERROR UPDATING CLIP PROD";
3269 delete clipProducer;
3272 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3273 if (!clip || !clip->is_valid()) {
3274 if (clip) delete clip;
3275 delete clipProducer;
3278 // move all effects to the correct producer
3279 mltPasteEffects(clipProducer, clip);
3280 trackPlaylist.insert_at(pos, clip, 1);
3282 delete clipProducer;
3286 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3288 Mlt::Service service(m_mltProducer->parent().get_service());
3289 if (service.type() != tractor_type) {
3290 kWarning() << "// TRACTOR PROBLEM";
3294 Mlt::Tractor tractor(service);
3296 Mlt::Producer trackProducer(tractor.track(startTrack));
3297 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3298 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3299 //kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3300 bool checkLength = false;
3301 if (endTrack == startTrack) {
3302 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3303 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3304 // error, destination is not empty
3306 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3307 delete clipProducer;
3309 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3310 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3314 trackPlaylist.consolidate_blanks(0);
3316 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3317 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3318 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3320 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3321 trackPlaylist.consolidate_blanks(1);
3322 delete clipProducer;
3323 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3324 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3326 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3330 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3331 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3332 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3333 // error, destination is not empty
3337 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3338 if (!clipProducer || clipProducer->is_blank()) {
3339 // error, destination is not empty
3340 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3341 if (clipProducer) delete clipProducer;
3342 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3346 trackPlaylist.consolidate_blanks(0);
3347 destTrackPlaylist.consolidate_blanks(1);
3348 Mlt::Producer *clip;
3349 // check if we are moving a slowmotion producer
3350 QString serv = clipProducer->parent().get("mlt_service");
3351 QString currentid = clipProducer->parent().get("id");
3352 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3353 clip = clipProducer;
3356 // Special case: prod is null when using placeholder clips.
3357 // in that case, use the producer existing in playlist. Note that
3358 // it will bypass the one producer per track logic and might cause
3359 // Sound cracks if clip is moved so that it overlaps another copy of itself
3360 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3361 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3364 // move all effects to the correct producer
3365 mltPasteEffects(clipProducer, clip);
3368 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3369 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3370 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3373 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3375 if (clip == clipProducer) {
3380 delete clipProducer;
3382 destTrackPlaylist.consolidate_blanks(0);
3383 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3384 kDebug() << "//////// moving clip transparency";
3385 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3387 if (clipIndex > trackPlaylist.count()) checkLength = true;
3388 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3392 if (checkLength) mltCheckLength(&tractor);
3394 //m_mltConsumer->set("refresh", 1);
3399 QList <int> Render::checkTrackSequence(int track)
3402 Mlt::Service service(m_mltProducer->parent().get_service());
3403 if (service.type() != tractor_type) {
3404 kWarning() << "// TRACTOR PROBLEM";
3407 Mlt::Tractor tractor(service);
3409 Mlt::Producer trackProducer(tractor.track(track));
3410 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3411 int clipNb = trackPlaylist.count();
3412 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3413 for (int i = 0; i < clipNb; i++) {
3414 Mlt::Producer *c = trackPlaylist.get_clip(i);
3415 int pos = trackPlaylist.clip_start(i);
3416 if (!list.contains(pos)) list.append(pos);
3417 pos += c->get_playtime();
3418 if (!list.contains(pos)) list.append(pos);
3424 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3426 int new_in = (int)newIn.frames(m_fps);
3427 int new_out = (int)newOut.frames(m_fps) - 1;
3428 if (new_in >= new_out) return false;
3429 int old_in = (int)oldIn.frames(m_fps);
3430 int old_out = (int)oldOut.frames(m_fps) - 1;
3432 Mlt::Service service(m_mltProducer->parent().get_service());
3433 Mlt::Tractor tractor(service);
3434 Mlt::Field *field = tractor.field();
3436 bool doRefresh = true;
3437 // Check if clip is visible in monitor
3438 int diff = old_out - m_mltProducer->position();
3439 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3441 diff = new_out - m_mltProducer->position();
3442 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3446 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3447 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3448 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3449 QString resource = mlt_properties_get(properties, "mlt_service");
3450 int old_pos = (int)(old_in + old_out) / 2;
3453 while (mlt_type == "transition") {
3454 Mlt::Transition transition((mlt_transition) nextservice);
3455 int currentTrack = transition.get_b_track();
3456 int currentIn = (int) transition.get_in();
3457 int currentOut = (int) transition.get_out();
3459 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3461 if (newTrack - startTrack != 0) {
3462 Mlt::Properties trans_props(transition.get_properties());
3463 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3464 Mlt::Properties new_trans_props(new_transition.get_properties());
3465 new_trans_props.inherit(trans_props);
3466 new_transition.set_in_and_out(new_in, new_out);
3467 field->disconnect_service(transition);
3468 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3469 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3470 } else transition.set_in_and_out(new_in, new_out);
3473 nextservice = mlt_service_producer(nextservice);
3474 if (nextservice == NULL) break;
3475 properties = MLT_SERVICE_PROPERTIES(nextservice);
3476 mlt_type = mlt_properties_get(properties, "mlt_type");
3477 resource = mlt_properties_get(properties, "mlt_service");
3480 if (doRefresh) refresh();
3481 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3486 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3488 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3489 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3490 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3491 QString resource = mlt_properties_get(properties, "mlt_service");
3492 QList <Mlt::Transition *> trList;
3494 while (mlt_type == "transition") {
3495 Mlt::Transition transition((mlt_transition) nextservice);
3496 int aTrack = transition.get_a_track();
3497 int bTrack = transition.get_b_track();
3498 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3499 Mlt::Properties trans_props(transition.get_properties());
3500 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3501 Mlt::Properties new_trans_props(cp->get_properties());
3502 new_trans_props.inherit(trans_props);
3504 field->disconnect_service(transition);
3506 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3508 nextservice = mlt_service_producer(nextservice);
3509 if (nextservice == NULL) break;
3510 properties = MLT_SERVICE_PROPERTIES(nextservice);
3511 mlt_type = mlt_properties_get(properties, "mlt_type");
3512 resource = mlt_properties_get(properties, "mlt_service");
3514 field->plant_transition(tr, a_track, b_track);
3516 // re-add upper transitions
3517 for (int i = trList.count() - 1; i >= 0; i--) {
3518 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3519 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3523 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3525 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3527 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3528 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3529 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3532 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3535 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3537 mlt_service serv = m_mltProducer->parent().get_service();
3538 mlt_service_lock(serv);
3540 mlt_service nextservice = mlt_service_get_producer(serv);
3541 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3542 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3543 QString resource = mlt_properties_get(properties, "mlt_service");
3544 int in_pos = (int) in.frames(m_fps);
3545 int out_pos = (int) out.frames(m_fps) - 1;
3547 while (mlt_type == "transition") {
3548 mlt_transition tr = (mlt_transition) nextservice;
3549 int currentTrack = mlt_transition_get_b_track(tr);
3550 int currentBTrack = mlt_transition_get_a_track(tr);
3551 int currentIn = (int) mlt_transition_get_in(tr);
3552 int currentOut = (int) mlt_transition_get_out(tr);
3554 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3555 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3556 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3557 QMap<QString, QString>::Iterator it;
3559 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3561 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3562 if (currentId != xml.attribute("id")) {
3563 // The transition ID is not the same, so reset all properties
3564 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3565 // Cleanup previous properties
3566 QStringList permanentProps;
3567 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3568 permanentProps << "out" << "a_track" << "b_track";
3569 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3570 QString propName = mlt_properties_get_name(transproperties, i);
3571 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3572 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3577 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3578 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3580 if (currentBTrack != a_track) {
3581 mlt_properties_set_int(transproperties, "a_track", a_track);
3583 for (it = map.begin(); it != map.end(); ++it) {
3585 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3586 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3587 //filter->set("kdenlive_id", id);
3591 nextservice = mlt_service_producer(nextservice);
3592 if (nextservice == NULL) break;
3593 properties = MLT_SERVICE_PROPERTIES(nextservice);
3594 mlt_type = mlt_properties_get(properties, "mlt_type");
3595 resource = mlt_properties_get(properties, "mlt_service");
3597 mlt_service_unlock(serv);
3599 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3602 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3604 mlt_service serv = m_mltProducer->parent().get_service();
3605 mlt_service_lock(serv);
3607 Mlt::Service service(serv);
3608 Mlt::Tractor tractor(service);
3609 Mlt::Field *field = tractor.field();
3611 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3613 mlt_service nextservice = mlt_service_get_producer(serv);
3614 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3615 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3616 QString resource = mlt_properties_get(properties, "mlt_service");
3618 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3619 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3621 while (mlt_type == "transition") {
3622 mlt_transition tr = (mlt_transition) nextservice;
3623 int currentTrack = mlt_transition_get_b_track(tr);
3624 int currentIn = (int) mlt_transition_get_in(tr);
3625 int currentOut = (int) mlt_transition_get_out(tr);
3626 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3628 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3629 mlt_field_disconnect_service(field->get_field(), nextservice);
3632 nextservice = mlt_service_producer(nextservice);
3633 if (nextservice == NULL) break;
3634 properties = MLT_SERVICE_PROPERTIES(nextservice);
3635 mlt_type = mlt_properties_get(properties, "mlt_type");
3636 resource = mlt_properties_get(properties, "mlt_service");
3638 mlt_service_unlock(serv);
3640 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3643 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3645 QDomNodeList attribs = xml.elementsByTagName("parameter");
3646 QMap<QString, QString> map;
3647 for (int i = 0; i < attribs.count(); i++) {
3648 QDomElement e = attribs.item(i).toElement();
3649 QString name = e.attribute("name");
3650 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3651 map[name] = e.attribute("default");
3652 if (!e.attribute("value").isEmpty()) {
3653 map[name] = e.attribute("value");
3655 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
3656 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
3657 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3660 if (e.attribute("namedesc").contains(';')) {
3661 QString format = e.attribute("format");
3662 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3663 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3665 QTextStream txtNeu(&neu);
3666 if (values.size() > 0)
3667 txtNeu << (int)values[0].toDouble();
3669 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3670 txtNeu << separators[i];
3671 txtNeu << (int)(values[i+1].toDouble());
3673 if (i < separators.size())
3674 txtNeu << separators[i];
3675 map[e.attribute("name")] = neu;
3682 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3684 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3685 Mlt::Service service(m_mltProducer->parent().get_service());
3686 Mlt::Tractor tractor(service);
3687 Mlt::Field *field = tractor.field();
3689 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3690 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3691 transition->set("transparency", id);
3692 transition->set("fill", 1);
3693 transition->set("internal_added", 237);
3694 field->plant_transition(*transition, transitiontrack, info.track);
3698 void Render::mltDeleteTransparency(int pos, int track, int id)
3700 Mlt::Service service(m_mltProducer->parent().get_service());
3701 Mlt::Tractor tractor(service);
3702 Mlt::Field *field = tractor.field();
3704 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3705 mlt_service serv = m_mltProducer->parent().get_service();
3707 mlt_service nextservice = mlt_service_get_producer(serv);
3708 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3709 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3710 QString resource = mlt_properties_get(properties, "mlt_service");
3712 while (mlt_type == "transition") {
3713 mlt_transition tr = (mlt_transition) nextservice;
3714 int currentTrack = mlt_transition_get_b_track(tr);
3715 int currentIn = (int) mlt_transition_get_in(tr);
3716 int currentOut = (int) mlt_transition_get_out(tr);
3717 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3718 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3720 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3721 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3722 mlt_field_disconnect_service(field->get_field(), nextservice);
3725 nextservice = mlt_service_producer(nextservice);
3726 if (nextservice == NULL) break;
3727 properties = MLT_SERVICE_PROPERTIES(nextservice);
3728 mlt_type = mlt_properties_get(properties, "mlt_type");
3729 resource = mlt_properties_get(properties, "mlt_service");
3731 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3734 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3736 Mlt::Service service(m_mltProducer->parent().get_service());
3737 Mlt::Tractor tractor(service);
3740 m_mltConsumer->set("refresh", 0);
3742 mlt_service serv = m_mltProducer->parent().get_service();
3743 mlt_service nextservice = mlt_service_get_producer(serv);
3744 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3745 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3746 QString resource = mlt_properties_get(properties, "mlt_service");
3747 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3748 while (mlt_type == "transition") {
3749 mlt_transition tr = (mlt_transition) nextservice;
3750 int currentTrack = mlt_transition_get_b_track(tr);
3751 int currentIn = (int) mlt_transition_get_in(tr);
3752 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3753 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3754 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3755 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3756 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3757 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3760 nextservice = mlt_service_producer(nextservice);
3761 if (nextservice == NULL) break;
3762 properties = MLT_SERVICE_PROPERTIES(nextservice);
3763 mlt_type = mlt_properties_get(properties, "mlt_type");
3764 resource = mlt_properties_get(properties, "mlt_service");
3767 m_mltConsumer->set("refresh", 1);
3771 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3773 Mlt::Service service(m_mltProducer->parent().get_service());
3774 Mlt::Tractor tractor(service);
3777 m_mltConsumer->set("refresh", 0);
3779 mlt_service serv = m_mltProducer->parent().get_service();
3780 mlt_service nextservice = mlt_service_get_producer(serv);
3781 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3782 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3783 QString resource = mlt_properties_get(properties, "mlt_service");
3785 while (mlt_type == "transition") {
3786 mlt_transition tr = (mlt_transition) nextservice;
3787 int currentTrack = mlt_transition_get_b_track(tr);
3788 int currentaTrack = mlt_transition_get_a_track(tr);
3789 int currentIn = (int) mlt_transition_get_in(tr);
3790 int currentOut = (int) mlt_transition_get_out(tr);
3791 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3792 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3793 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3794 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3795 kDebug() << "//////MOVING";
3796 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3797 if (endTrack != startTrack) {
3798 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3799 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3800 mlt_properties_set_int(properties, "b_track", endTrack);
3804 nextservice = mlt_service_producer(nextservice);
3805 if (nextservice == NULL) break;
3806 properties = MLT_SERVICE_PROPERTIES(nextservice);
3807 mlt_type = mlt_properties_get(properties, "mlt_type");
3808 resource = mlt_properties_get(properties, "mlt_service");
3811 m_mltConsumer->set("refresh", 1);
3815 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3817 if (in >= out) return false;
3818 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3819 Mlt::Service service(m_mltProducer->parent().get_service());
3821 Mlt::Tractor tractor(service);
3822 Mlt::Field *field = tractor.field();
3824 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3825 if (out != GenTime())
3826 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3828 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3829 QMap<QString, QString>::Iterator it;
3831 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3832 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3833 if (xml.hasAttribute("id"))
3834 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3835 if (xml.hasAttribute("force_track"))
3836 transition->set("force_track", xml.attribute("force_track").toInt());
3838 for (it = args.begin(); it != args.end(); ++it) {
3840 if (!it.value().isEmpty())
3841 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3842 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3844 // attach transition
3846 mltPlantTransition(field, *transition, a_track, b_track);
3847 // field->plant_transition(*transition, a_track, b_track);
3849 if (do_refresh) refresh();
3853 void Render::mltSavePlaylist()
3855 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3856 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3857 fileConsumer.set("resource", "/tmp/playlist.mlt");
3859 Mlt::Service service(m_mltProducer->get_service());
3861 fileConsumer.connect(service);
3862 fileConsumer.start();
3865 const QList <Mlt::Producer *> Render::producersList()
3867 QList <Mlt::Producer *> prods;
3868 if (m_mltProducer == NULL) return prods;
3869 Mlt::Service service(m_mltProducer->parent().get_service());
3870 if (service.type() != tractor_type) return prods;
3871 Mlt::Tractor tractor(service);
3874 int trackNb = tractor.count();
3875 for (int t = 1; t < trackNb; t++) {
3876 Mlt::Producer *tt = tractor.track(t);
3877 Mlt::Producer trackProducer(tt);
3879 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3880 int clipNb = trackPlaylist.count();
3881 for (int i = 0; i < clipNb; i++) {
3882 Mlt::Producer *c = trackPlaylist.get_clip(i);
3883 if (c == NULL) continue;
3884 QString prodId = c->parent().get("id");
3885 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
3886 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3889 prods.append(nprod);
3898 void Render::fillSlowMotionProducers()
3900 if (m_mltProducer == NULL) return;
3901 Mlt::Service service(m_mltProducer->parent().get_service());
3902 if (service.type() != tractor_type) return;
3904 Mlt::Tractor tractor(service);
3906 int trackNb = tractor.count();
3907 for (int t = 1; t < trackNb; t++) {
3908 Mlt::Producer *tt = tractor.track(t);
3909 Mlt::Producer trackProducer(tt);
3911 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3912 int clipNb = trackPlaylist.count();
3913 for (int i = 0; i < clipNb; i++) {
3914 Mlt::Producer *c = trackPlaylist.get_clip(i);
3915 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3917 QString id = nprod->parent().get("id");
3918 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3919 // this is a slowmotion producer, add it to the list
3920 QString url = QString::fromUtf8(nprod->get("resource"));
3921 int strobe = nprod->get_int("strobe");
3922 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3923 if (!m_slowmotionProducers.contains(url)) {
3924 m_slowmotionProducers.insert(url, nprod);
3926 } else delete nprod;
3933 void Render::mltInsertTrack(int ix, bool videoTrack)
3937 Mlt::Service service(m_mltProducer->parent().get_service());
3939 if (service.type() != tractor_type) {
3940 kWarning() << "// TRACTOR PROBLEM";
3944 Mlt::Tractor tractor(service);
3946 Mlt::Playlist playlist;
3947 int ct = tractor.count();
3949 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3955 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3956 tractor.set_track(playlist, pos);
3957 Mlt::Producer newProd(tractor.track(pos));
3958 if (!videoTrack) newProd.set("hide", 1);
3960 for (; pos <= ct; pos++) {
3961 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3962 tractor.set_track(*prodToMove, pos);
3963 prodToMove = prodToMove2;
3966 tractor.set_track(playlist, ix);
3967 Mlt::Producer newProd(tractor.track(ix));
3968 if (!videoTrack) newProd.set("hide", 1);
3973 mlt_service serv = m_mltProducer->parent().get_service();
3974 mlt_service nextservice = mlt_service_get_producer(serv);
3975 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3976 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3977 QString resource = mlt_properties_get(properties, "mlt_service");
3979 while (mlt_type == "transition") {
3980 if (resource != "mix") {
3981 mlt_transition tr = (mlt_transition) nextservice;
3982 int currentTrack = mlt_transition_get_b_track(tr);
3983 int currentaTrack = mlt_transition_get_a_track(tr);
3984 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3986 if (currentTrack >= ix) {
3987 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3988 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3991 nextservice = mlt_service_producer(nextservice);
3992 if (nextservice == NULL) break;
3993 properties = MLT_SERVICE_PROPERTIES(nextservice);
3994 mlt_type = mlt_properties_get(properties, "mlt_type");
3995 resource = mlt_properties_get(properties, "mlt_service");
3998 // Add audio mix transition to last track
3999 Mlt::Field *field = tractor.field();
4000 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
4001 transition->set("a_track", 1);
4002 transition->set("b_track", ct);
4003 transition->set("always_active", 1);
4004 transition->set("internal_added", 237);
4005 transition->set("combine", 1);
4006 field->plant_transition(*transition, 1, ct);
4007 //mlt_service_unlock(m_mltConsumer->get_service());
4009 //tractor.multitrack()->refresh();
4010 //tractor.refresh();
4011 blockSignals(false);
4015 void Render::mltDeleteTrack(int ix)
4018 doc.setContent(sceneList(), false);
4019 int tracksCount = doc.elementsByTagName("track").count() - 1;
4020 QDomNode track = doc.elementsByTagName("track").at(ix);
4021 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
4022 QDomNodeList transitions = doc.elementsByTagName("transition");
4023 for (int i = 0; i < transitions.count(); i++) {
4024 QDomElement e = transitions.at(i).toElement();
4025 QDomNodeList props = e.elementsByTagName("property");
4026 QMap <QString, QString> mappedProps;
4027 for (int j = 0; j < props.count(); j++) {
4028 QDomElement f = props.at(j).toElement();
4029 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
4031 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
4032 tractor.removeChild(transitions.at(i));
4034 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
4035 // Transition needs to be moved
4036 int a_track = mappedProps.value("a_track").toInt();
4037 int b_track = mappedProps.value("b_track").toInt();
4038 if (a_track > 0 && a_track >= ix) a_track --;
4039 if (b_track == ix) {
4040 // transition was on the deleted track, so remove it
4041 tractor.removeChild(transitions.at(i));
4045 if (b_track > 0 && b_track > ix) b_track --;
4046 for (int j = 0; j < props.count(); j++) {
4047 QDomElement f = props.at(j).toElement();
4048 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
4049 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
4054 tractor.removeChild(track);
4055 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
4056 setSceneList(doc.toString(), m_mltConsumer->position());
4057 emit refreshDocumentProducers(false, false);
4061 void Render::updatePreviewSettings()
4063 kDebug() << "////// RESTARTING CONSUMER";
4064 if (!m_mltConsumer || !m_mltProducer) return;
4065 if (m_mltProducer->get_playtime() == 0) return;
4066 QMutexLocker locker(&m_mutex);
4067 Mlt::Service service(m_mltProducer->parent().get_service());
4068 if (service.type() != tractor_type) return;
4070 //m_mltConsumer->set("refresh", 0);
4071 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
4072 m_mltConsumer->purge();
4073 QString scene = sceneList();
4075 if (m_mltProducer) {
4076 pos = m_mltProducer->position();
4079 setSceneList(scene, pos);
4083 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
4085 // Update all frame positions to the new fps value
4086 //WARNING: there are probably some effects or other that hold a frame value
4087 // as parameter and will also need to be updated here!
4089 doc.setContent(scene);
4091 double factor = new_fps / current_fps;
4092 QDomNodeList producers = doc.elementsByTagName("producer");
4093 for (int i = 0; i < producers.count(); i++) {
4094 QDomElement prod = producers.at(i).toElement();
4095 prod.removeAttribute("in");
4096 prod.removeAttribute("out");
4098 QDomNodeList props = prod.childNodes();
4099 for (int j = 0; j < props.count(); j++) {
4100 QDomElement param = props.at(j).toElement();
4101 QString paramName = param.attribute("name");
4102 if (paramName.startsWith("meta.") || paramName == "length") {
4103 prod.removeChild(props.at(j));
4109 QDomNodeList entries = doc.elementsByTagName("entry");
4110 for (int i = 0; i < entries.count(); i++) {
4111 QDomElement entry = entries.at(i).toElement();
4112 int in = entry.attribute("in").toInt();
4113 int out = entry.attribute("out").toInt();
4114 in = factor * in + 0.5;
4115 out = factor * out + 0.5;
4116 entry.setAttribute("in", in);
4117 entry.setAttribute("out", out);
4120 QDomNodeList blanks = doc.elementsByTagName("blank");
4121 for (int i = 0; i < blanks.count(); i++) {
4122 QDomElement blank = blanks.at(i).toElement();
4123 int length = blank.attribute("length").toInt();
4124 length = factor * length + 0.5;
4125 blank.setAttribute("length", QString::number(length));
4128 QDomNodeList filters = doc.elementsByTagName("filter");
4129 for (int i = 0; i < filters.count(); i++) {
4130 QDomElement filter = filters.at(i).toElement();
4131 int in = filter.attribute("in").toInt();
4132 int out = filter.attribute("out").toInt();
4133 in = factor * in + 0.5;
4134 out = factor * out + 0.5;
4135 filter.setAttribute("in", in);
4136 filter.setAttribute("out", out);
4139 QDomNodeList transitions = doc.elementsByTagName("transition");
4140 for (int i = 0; i < transitions.count(); i++) {
4141 QDomElement transition = transitions.at(i).toElement();
4142 int in = transition.attribute("in").toInt();
4143 int out = transition.attribute("out").toInt();
4144 in = factor * in + 0.5;
4145 out = factor * out + 0.5;
4146 transition.setAttribute("in", in);
4147 transition.setAttribute("out", out);
4148 QDomNodeList props = transition.childNodes();
4149 for (int j = 0; j < props.count(); j++) {
4150 QDomElement param = props.at(j).toElement();
4151 QString paramName = param.attribute("name");
4152 if (paramName == "geometry") {
4153 QString geom = param.firstChild().nodeValue();
4154 QStringList keys = geom.split(';');
4155 QStringList newKeys;
4156 for (int k = 0; k < keys.size(); ++k) {
4157 if (keys.at(k).contains('=')) {
4158 int pos = keys.at(k).section('=', 0, 0).toInt();
4159 pos = factor * pos + 0.5;
4160 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4161 } else newKeys.append(keys.at(k));
4163 param.firstChild().setNodeValue(newKeys.join(";"));
4167 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
4168 int out = tractor.attribute("out").toInt();
4169 out = factor * out + 0.5;
4170 tractor.setAttribute("out", out);
4171 emit durationChanged(out);
4173 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4174 return doc.toString();
4178 void Render::sendFrameUpdate()
4180 if (m_mltProducer) {
4181 Mlt::Frame * frame = m_mltProducer->get_frame();
4182 emitFrameUpdated(*frame);
4187 Mlt::Producer* Render::getProducer()
4189 return m_mltProducer;
4192 const QString Render::activeClipId()
4194 if (m_mltProducer) return m_mltProducer->get("id");
4198 #include "renderer.moc"