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>
52 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
54 // kDebug() << "log level" << level << QString().vsprintf(fmt, vl).simplified();
55 if (level > MLT_LOG_ERROR) return;
57 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
62 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
64 // detect if the producer has finished playing. Is there a better way to do it?
65 Mlt::Frame frame(frame_ptr);
66 if (!frame.is_valid()) return;
67 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
68 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
69 self->emitFrameUpdated(frame);
71 if (self->analyseAudio) {
72 self->showAudio(frame);
74 if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
76 self->emitConsumerStopped();
81 static void consumer_paused(mlt_consumer, Render * self, mlt_frame /*frame_ptr*/)
83 // detect if the producer has finished playing. Is there a better way to do it?
84 self->emitConsumerStopped();
88 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
90 // detect if the producer has finished playing. Is there a better way to do it?
91 Mlt::Frame frame(frame_ptr);
92 self->showFrame(frame);
93 if (frame.get_double("_speed") == 0.0) {
94 self->emitConsumerStopped();
95 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
97 self->emitConsumerStopped();
101 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
102 AbstractRender(rendererName, parent),
103 analyseAudio(KdenliveSettings::monitor_audio()),
104 m_name(rendererName),
109 m_externalConsumer(false),
112 m_isSplitView(false),
116 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
117 buildConsumer(profile);
119 m_mltProducer = m_blackClip->cut(0, 50);
120 m_mltConsumer->connect(*m_mltProducer);
121 m_mltProducer->set_speed(0.0);
131 void Render::closeMlt()
134 if (m_mltConsumer) delete m_mltConsumer;
135 if (m_mltProducer) delete m_mltProducer;
136 /*if (m_mltProducer) {
137 Mlt::Service service(m_mltProducer->parent().get_service());
138 mlt_service_lock(service.get_service());
140 if (service.type() == tractor_type) {
141 Mlt::Tractor tractor(service);
142 Mlt::Field *field = tractor.field();
143 mlt_service nextservice = mlt_service_get_producer(service.get_service());
144 mlt_service nextservicetodisconnect;
145 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
146 QString mlt_type = mlt_properties_get(properties, "mlt_type");
147 QString resource = mlt_properties_get(properties, "mlt_service");
148 // Delete all transitions
149 while (mlt_type == "transition") {
150 nextservicetodisconnect = nextservice;
151 nextservice = mlt_service_producer(nextservice);
152 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
153 if (nextservice == NULL) break;
154 properties = MLT_SERVICE_PROPERTIES(nextservice);
155 mlt_type = mlt_properties_get(properties, "mlt_type");
156 resource = mlt_properties_get(properties, "mlt_service");
162 mlt_service_unlock(service.get_service());
165 kDebug() << "// // // CLOSE RENDERER " << m_name;
166 if (m_blackClip) delete m_blackClip;
170 void Render::slotSwitchFullscreen()
172 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
175 void Render::buildConsumer(const QString &profileName)
180 //TODO: uncomment following line when everything is clean
181 // uncommented Feb 2011 --Granjow
182 if (m_mltProfile) delete m_mltProfile;
183 m_activeProfile = profileName;
184 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
185 setenv("MLT_PROFILE", tmp, 1);
186 m_mltProfile = new Mlt::Profile(tmp);
187 m_mltProfile->set_explicit(true);
188 kDebug()<<"// ********* PROFILE AR: "<<m_mltProfile->dar();
191 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
192 m_blackClip->set("id", "black");
193 m_blackClip->set("mlt_type", "producer");
195 if (KdenliveSettings::external_display() && m_name != "clip") {
196 // Use blackmagic card for video output
197 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
198 int device = KdenliveSettings::blackmagic_output_device();
200 if (BMInterface::isSupportedProfile(device, profileProperties)) {
201 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
202 tmp = qstrdup(decklink.toUtf8().constData());
203 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, tmp);
205 if (m_mltConsumer->is_valid()) {
206 m_externalConsumer = true;
207 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
208 m_mltConsumer->set("terminate_on_pause", 0);
209 m_mltConsumer->set("buffer", 12);
210 m_mltConsumer->set("deinterlace_method", "onefield");
211 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
212 mlt_log_set_callback(kdenlive_callback);
214 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
215 } 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()));
218 m_externalConsumer = false;
219 QString videoDriver = KdenliveSettings::videodrivername();
220 if (!videoDriver.isEmpty()) {
221 if (videoDriver == "x11_noaccel") {
222 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
225 unsetenv("SDL_VIDEO_YUV_HWACCEL");
228 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
230 //m_mltConsumer->set("fullscreen", 1);
233 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
234 m_mltConsumer->set("preview_off", 1);
235 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
236 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
238 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
239 // FIXME: the event object returned by the listen gets leaked...
240 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
241 m_mltConsumer->listen("consumer-sdl-paused", this, (mlt_listener) consumer_paused);
242 m_mltConsumer->set("window_id", m_winid);
244 m_mltConsumer->set("resize", 1);
245 m_mltConsumer->set("terminate_on_pause", 1);
246 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
247 m_mltConsumer->set("rescale", "nearest");
248 mlt_log_set_callback(kdenlive_callback);
250 QString audioDevice = KdenliveSettings::audiodevicename();
251 if (!audioDevice.isEmpty())
252 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
254 if (!videoDriver.isEmpty())
255 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
257 QString audioDriver = KdenliveSettings::audiodrivername();
260 // Disabled because the "auto" detected driver was sometimes wrong
261 if (audioDriver.isEmpty())
262 audioDriver = KdenliveSettings::autoaudiodrivername();
265 if (!audioDriver.isEmpty())
266 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
268 m_mltConsumer->set("progressive", 1);
269 m_mltConsumer->set("audio_buffer", 1024);
270 m_mltConsumer->set("frequency", 48000);
271 m_mltConsumer->set("real_time", KdenliveSettings::mltthreads());
274 Mlt::Producer *Render::invalidProducer(const QString &id)
277 QString txt = "+" + i18n("Missing clip") + ".txt";
278 char *tmp = qstrdup(txt.toUtf8().constData());
279 clip = new Mlt::Producer(*m_mltProfile, tmp);
281 if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
283 clip->set("bgcolour", "0xff0000ff");
284 clip->set("pad", "10");
286 clip->set("id", id.toUtf8().constData());
287 clip->set("mlt_type", "producer");
291 int Render::resetProfile(const QString &profileName, bool dropSceneList)
294 if (!dropSceneList) scene = sceneList();
296 if (m_externalConsumer == KdenliveSettings::external_display()) {
297 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
298 QString videoDriver = KdenliveSettings::videodrivername();
299 QString currentDriver = m_mltConsumer->get("video_driver");
300 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
301 QString background = KdenliveSettings::window_background().name();
302 QString currentBackground = m_mltConsumer->get("window_background");
303 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
304 kDebug() << "reset to same profile, nothing to do";
309 if (m_isSplitView) slotSplitView(false);
310 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
311 m_mltConsumer->purge();
312 delete m_mltConsumer;
313 m_mltConsumer = NULL;
316 double current_fps = m_mltProfile->fps();
317 double current_dar = m_mltProfile->dar();
322 pos = m_mltProducer->position();
324 Mlt::Service service(m_mltProducer->get_service());
325 if (service.type() == tractor_type) {
326 Mlt::Tractor tractor(service);
327 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
328 Mlt::Producer trackProducer(tractor.track(trackNb));
329 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
330 trackPlaylist.clear();
334 delete m_mltProducer;
336 m_mltProducer = NULL;
337 buildConsumer(profileName);
338 double new_fps = m_mltProfile->fps();
339 double new_dar = m_mltProfile->dar();
341 if (!dropSceneList) {
342 // We need to recover our playlist
343 if (current_fps != new_fps) {
344 // fps changed, we must update the scenelist positions
345 scene = updateSceneListFps(current_fps, new_fps, scene);
347 setSceneList(scene, pos);
348 // producers have changed (different profile), so reset them...
349 emit refreshDocumentProducers(new_dar != current_dar, current_fps != new_fps);
354 void Render::seek(GenTime time)
358 m_mltProducer->seek((int)(time.frames(m_fps)));
362 void Render::seek(int time)
366 m_mltProducer->seek(time);
371 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
372 QPixmap pix(width, height);
374 mlt_image_format format = mlt_image_rgb24a;
375 uint8_t *thumb = frame->get_image(format, width, height);
376 QImage image(thumb, width, height, QImage::Format_ARGB32);
378 if (!image.isNull()) {
379 pix = pix.fromImage(image);
381 QPainter painter(&pix);
382 painter.drawRect(0, 0, width - 1, height - 1);
384 } else pix.fill(Qt::black);
388 int Render::frameRenderWidth() const
390 return m_mltProfile->width();
393 int Render::renderWidth() const
395 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
398 int Render::renderHeight() const
400 return m_mltProfile->height();
403 QImage Render::extractFrame(int frame_position, QString path, int width, int height)
406 width = frameRenderWidth();
407 height = renderHeight();
408 } else if (width % 2 == 1) width++;
409 int dwidth = height * frameRenderWidth() / renderHeight();
410 if (!path.isEmpty()) {
411 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
413 if (producer->is_valid()) {
414 QImage img = KThumb::getFrame(producer, frame_position, dwidth, width, height);
418 else delete producer;
422 if (!m_mltProducer || !path.isEmpty()) {
423 QImage pix(width, height, QImage::Format_RGB32);
427 return KThumb::getFrame(m_mltProducer, frame_position, dwidth, width, height);
430 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
434 if (url.fileName().startsWith(".all.")) { // check for slideshow
435 QString fileType = url.fileName().right(3);
437 QStringList::Iterator it;
439 QDir dir(url.directory());
441 filter << "*." + fileType;
442 filter << "*." + fileType.toUpper();
443 more = dir.entryList(filter, QDir::Files);
444 im.load(url.directory() + '/' + more.at(0));
445 } else im.load(url.path());
446 //pixmap = im.scaled(width, height);
450 double Render::consumerRatio() const
452 if (!m_mltConsumer) return 1.0;
453 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
457 int Render::getLength()
461 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
462 return mlt_producer_get_playtime(m_mltProducer->get_producer());
467 bool Render::isValid(KUrl url)
469 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
470 if (producer.is_blank())
476 double Render::dar() const
478 return m_mltProfile->dar();
481 double Render::sar() const
483 return m_mltProfile->sar();
486 void Render::slotSplitView(bool doit)
488 m_isSplitView = doit;
489 Mlt::Service service(m_mltProducer->parent().get_service());
490 Mlt::Tractor tractor(service);
491 if (service.type() != tractor_type || tractor.count() < 2) return;
492 Mlt::Field *field = tractor.field();
494 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
495 Mlt::Producer trackProducer(tractor.track(i));
496 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
497 if (QString(trackProducer.get("hide")).toInt() != 1) {
498 kDebug() << "// ADIDNG TRACK: " << i;
499 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
500 transition->set("mlt_service", "composite");
501 transition->set("a_track", 0);
502 transition->set("b_track", i);
503 transition->set("distort", 1);
504 transition->set("internal_added", "200");
511 tmp = "50%,0:50%x50%";
514 tmp = "0,50%:50%x50%";
518 tmp = "50%,50%:50%x50%";
521 transition->set("geometry", tmp);
522 transition->set("always_active", "1");
523 field->plant_transition(*transition, 0, i);
528 m_mltConsumer->set("refresh", 1);
530 mlt_service serv = m_mltProducer->parent().get_service();
531 mlt_service nextservice = mlt_service_get_producer(serv);
532 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
533 QString mlt_type = mlt_properties_get(properties, "mlt_type");
534 QString resource = mlt_properties_get(properties, "mlt_service");
536 while (mlt_type == "transition") {
537 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
538 if (added == "200") {
539 mlt_field_disconnect_service(field->get_field(), nextservice);
541 nextservice = mlt_service_producer(nextservice);
542 if (nextservice == NULL) break;
543 properties = MLT_SERVICE_PROPERTIES(nextservice);
544 mlt_type = mlt_properties_get(properties, "mlt_type");
545 resource = mlt_properties_get(properties, "mlt_service");
546 m_mltConsumer->set("refresh", 1);
551 void Render::getFileProperties(const QDomElement &xml, const QString &clipId, int imageHeight, bool replaceProducer, bool selectClip)
556 if (xml.hasAttribute("proxy") && xml.attribute("proxy") != "-") {
557 path = xml.attribute("proxy");
558 proxyProducer = true;
561 path = xml.attribute("resource");
562 proxyProducer = false;
566 Mlt::Producer *producer = NULL;
567 CLIPTYPE type = (CLIPTYPE)xml.attribute("type").toInt();
568 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
569 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
570 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
575 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
576 } else if (type == TEXT) {
577 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
578 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
579 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
580 } else if (url.isEmpty()) {
582 QDomElement mlt = doc.createElement("mlt");
583 QDomElement play = doc.createElement("playlist");
584 doc.appendChild(mlt);
585 mlt.appendChild(play);
586 play.appendChild(doc.importNode(xml, true));
587 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
589 char *resTag = qstrdup(QString("nocache:" + path).toUtf8().constData());
590 producer = new Mlt::Producer(*m_mltProfile, path.toUtf8().constData());
595 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
596 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "<<path;
598 // Proxy file is corrupted
599 emit removeInvalidProxy(clipId, false);
601 else emit removeInvalidClip(clipId, replaceProducer);
606 if (proxyProducer && xml.hasAttribute("proxy_out")) {
607 producer->set("length", xml.attribute("proxy_out").toInt() + 1);
608 producer->set("out", xml.attribute("proxy_out").toInt());
609 if (producer->get_out() != xml.attribute("proxy_out").toInt()) {
610 // Proxy file length is different than original clip length, this will corrupt project so disable this proxy clip
611 emit removeInvalidProxy(clipId, true);
617 if (xml.hasAttribute("force_aspect_ratio")) {
618 double aspect = xml.attribute("force_aspect_ratio").toDouble();
619 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
622 if (xml.hasAttribute("force_aspect_num") && xml.hasAttribute("force_aspect_den")) {
623 int width = xml.attribute("frame_size").section('x', 0, 0).toInt();
624 int height = xml.attribute("frame_size").section('x', 1, 1).toInt();
625 int aspectNumerator = xml.attribute("force_aspect_num").toInt();
626 int aspectDenominator = xml.attribute("force_aspect_den").toInt();
627 if (aspectDenominator != 0 && width != 0)
628 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
631 if (xml.hasAttribute("force_fps")) {
632 double fps = xml.attribute("force_fps").toDouble();
633 if (fps > 0) producer->set("force_fps", fps);
636 if (xml.hasAttribute("force_progressive")) {
638 int progressive = xml.attribute("force_progressive").toInt(&ok);
639 if (ok) producer->set("force_progressive", progressive);
641 if (xml.hasAttribute("force_tff")) {
643 int fieldOrder = xml.attribute("force_tff").toInt(&ok);
644 if (ok) producer->set("force_tff", fieldOrder);
646 if (xml.hasAttribute("threads")) {
647 int threads = xml.attribute("threads").toInt();
648 if (threads != 1) producer->set("threads", threads);
650 if (xml.hasAttribute("video_index")) {
651 int vindex = xml.attribute("video_index").toInt();
652 if (vindex != 0) producer->set("video_index", vindex);
654 if (xml.hasAttribute("audio_index")) {
655 int aindex = xml.attribute("audio_index").toInt();
656 if (aindex != 0) producer->set("audio_index", aindex);
658 if (xml.hasAttribute("force_colorspace")) {
659 int colorspace = xml.attribute("force_colorspace").toInt();
660 if (colorspace != 0) producer->set("force_colorspace", colorspace);
662 if (xml.hasAttribute("full_luma")) {
663 int full_luma = xml.attribute("full_luma").toInt();
664 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
669 if (xml.hasAttribute("out")) clipOut = xml.attribute("out").toInt();
671 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
672 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
674 if (xml.hasAttribute("length")) {
675 if (clipOut > 0) duration = clipOut + 1;
676 length = xml.attribute("length").toInt();
677 clipOut = length - 1;
679 else length = xml.attribute("out").toInt() - xml.attribute("in").toInt();
680 producer->set("length", length);
683 if (clipOut > 0) producer->set_in_and_out(xml.attribute("in").toInt(), clipOut);
685 producer->set("id", clipId.toUtf8().constData());
687 if (xml.hasAttribute("templatetext"))
688 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
690 if ((!replaceProducer && xml.hasAttribute("file_hash")) || xml.hasAttribute("proxy")) {
691 // Clip already has all properties
692 if (replaceProducer) emit blockClipMonitor(clipId);
693 // Querying a frame is required by MLT, otherwise the producer is not correctly initialised
694 //Mlt::Frame *frame = producer->get_frame();
696 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer, selectClip);
700 int imageWidth = (int)((double) imageHeight * m_mltProfile->width() / m_mltProfile->height() + 0.5);
701 int fullWidth = (int)((double) imageHeight * m_mltProfile->dar() + 0.5);
702 QMap < QString, QString > filePropertyMap;
703 QMap < QString, QString > metadataPropertyMap;
705 int frameNumber = xml.attribute("thumbnail", "0").toInt();
706 if (frameNumber != 0) producer->seek(frameNumber);
708 filePropertyMap["duration"] = QString::number(duration > 0 ? duration : producer->get_playtime());
709 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
711 Mlt::Frame *frame = producer->get_frame();
713 if (type == SLIDESHOW) {
714 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
715 if (ttl) producer->set("ttl", ttl);
716 if (!xml.attribute("animation").isEmpty()) {
717 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
718 if (filter && filter->is_valid()) {
720 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
721 if (!geometry.isEmpty()) {
722 if (xml.attribute("animation").contains("low-pass")) {
723 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
724 if (blur && blur->is_valid())
725 producer->attach(*blur);
727 filter->set("transition.geometry", geometry.toUtf8().data());
728 filter->set("transition.cycle", cycle);
729 producer->attach(*filter);
733 if (xml.attribute("fade") == "1") {
734 // user wants a fade effect to slideshow
735 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
736 if (filter && filter->is_valid()) {
737 if (ttl) filter->set("cycle", ttl);
738 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
739 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
740 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
741 if (xml.hasAttribute("softness")) {
742 int soft = xml.attribute("softness").toInt();
743 filter->set("luma.softness", (double) soft / 100.0);
746 producer->attach(*filter);
749 if (xml.attribute("crop") == "1") {
750 // user wants to center crop the slides
751 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
752 if (filter && filter->is_valid()) {
753 filter->set("center", 1);
754 producer->attach(*filter);
759 if (producer->get_double("meta.media.frame_rate_den") > 0) {
760 filePropertyMap["fps"] = locale.toString(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
761 } else filePropertyMap["fps"] = producer->get("source_fps");
763 if (frame && frame->is_valid()) {
764 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
765 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
766 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
767 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
769 if (frame->get_int("test_image") == 0) {
770 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
771 filePropertyMap["type"] = "playlist";
772 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
773 } else if (frame->get_int("test_audio") == 0)
774 filePropertyMap["type"] = "av";
776 filePropertyMap["type"] = "video";
779 mlt_image_format format = mlt_image_rgb24a;
780 int frame_width = imageWidth;
781 int frame_height = imageHeight;
785 img = KThumb::getFrame(frame, imageWidth, fullWidth, imageHeight);
786 variance = KThumb::imageVariance(img);
787 if (frameNumber == 0 && variance< 6) {
788 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
790 producer->seek(frameNumber);
792 frame = producer->get_frame();
795 } while (variance == -1);
796 QPixmap pix = QPixmap::fromImage(img);
797 emit replyGetImage(clipId, pix);
799 } else if (frame->get_int("test_audio") == 0) {
800 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(fullWidth, imageHeight));
801 emit replyGetImage(clipId, pixmap);
802 filePropertyMap["type"] = "audio";
806 // Retrieve audio / video codec name
810 if (producer->get_int("video_index") > -1) {
811 /*if (context->duration == AV_NOPTS_VALUE) {
812 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
813 emit removeInvalidClip(clipId);
817 // Get the video_index
818 int default_video = producer->get_int("video_index");
820 int default_audio = producer->get_int("audio_index");
823 // Find maximum stream index values
824 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
825 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
826 QString type = producer->get(property);
829 else if (type == "audio")
832 filePropertyMap["default_video"] = QString::number(default_video);
833 filePropertyMap["video_max"] = QString::number(video_max);
834 filePropertyMap["default_audio"] = QString::number(default_audio);
835 filePropertyMap["audio_max"] = QString::number(audio_max);
837 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
838 if (producer->get(property)) {
839 filePropertyMap["videocodec"] = producer->get(property);
841 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
842 if (producer->get(property))
843 filePropertyMap["videocodec"] = producer->get(property);
846 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
847 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
848 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
850 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
851 if (producer->get_int("audio_index") > -1) {
852 // Get the audio_index
853 int index = producer->get_int("audio_index");
855 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
856 if (producer->get(property)) {
857 filePropertyMap["audiocodec"] = producer->get(property);
859 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
860 if (producer->get(property))
861 filePropertyMap["audiocodec"] = producer->get(property);
866 Mlt::Properties metadata;
867 metadata.pass_values(*producer, "meta.attr.");
868 int count = metadata.count();
869 for (int i = 0; i < count; i ++) {
870 QString name = metadata.get_name(i);
871 QString value = QString::fromUtf8(metadata.get(i));
872 if (name.endsWith("markup") && !value.isEmpty())
873 metadataPropertyMap[ name.section('.', 0, -2)] = value;
876 if (replaceProducer) emit blockClipMonitor(clipId);
877 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer, selectClip);
878 // FIXME: should delete this to avoid a leak...
884 /** Create the producer from the MLT XML QDomDocument */
885 void Render::initSceneList()
887 kDebug() << "-------- INIT SCENE LIST ------_";
889 QDomElement mlt = doc.createElement("mlt");
890 doc.appendChild(mlt);
891 QDomElement prod = doc.createElement("producer");
892 prod.setAttribute("resource", "colour");
893 prod.setAttribute("colour", "red");
894 prod.setAttribute("id", "black");
895 prod.setAttribute("in", "0");
896 prod.setAttribute("out", "0");
898 QDomElement tractor = doc.createElement("tractor");
899 QDomElement multitrack = doc.createElement("multitrack");
901 QDomElement playlist1 = doc.createElement("playlist");
902 playlist1.appendChild(prod);
903 multitrack.appendChild(playlist1);
904 QDomElement playlist2 = doc.createElement("playlist");
905 multitrack.appendChild(playlist2);
906 QDomElement playlist3 = doc.createElement("playlist");
907 multitrack.appendChild(playlist3);
908 QDomElement playlist4 = doc.createElement("playlist");
909 multitrack.appendChild(playlist4);
910 QDomElement playlist5 = doc.createElement("playlist");
911 multitrack.appendChild(playlist5);
912 tractor.appendChild(multitrack);
913 mlt.appendChild(tractor);
914 // kDebug()<<doc.toString();
916 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
917 setSceneList(doc, 0);
921 int Render::setProducer(Mlt::Producer *producer, int position)
923 QMutexLocker locker(&m_mutex);
924 if (m_winid == -1) return -1;
926 if (!m_mltConsumer->is_stopped()) {
927 m_mltConsumer->stop();
929 m_mltConsumer->set("refresh", 0);
936 m_mltProducer->set_speed(0);
937 delete m_mltProducer;
938 m_mltProducer = NULL;
942 if (producer && producer->is_valid()) {
943 m_mltProducer = new Mlt::Producer(producer->get_producer());
944 } else m_mltProducer = m_blackClip->cut(0, 50);
946 if (!m_mltProducer || !m_mltProducer->is_valid()) {
947 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
950 int volume = KdenliveSettings::volume();
951 m_mltProducer->set("meta.volume", (double)volume / 100);
952 m_fps = m_mltProducer->get_fps();
954 int error = connectPlaylist();
956 if (position != -1) {
957 m_mltProducer->seek(position);
958 emit rendererPosition(position);
959 } else emit rendererPosition((int) m_mltProducer->position());
963 int Render::setSceneList(QDomDocument list, int position)
965 return setSceneList(list.toString(), position);
968 int Render::setSceneList(QString playlist, int position)
970 if (m_winid == -1) return -1;
973 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
975 // Remove previous profile info
977 doc.setContent(playlist);
978 QDomElement profile = doc.documentElement().firstChildElement("profile");
979 doc.documentElement().removeChild(profile);
980 playlist = doc.toString();
983 if (!m_mltConsumer->is_stopped()) {
984 m_mltConsumer->stop();
986 m_mltConsumer->set("refresh", 0);
988 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
993 m_mltProducer->set_speed(0);
994 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
996 /*Mlt::Service service(m_mltProducer->parent().get_service());
997 mlt_service_lock(service.get_service());
999 if (service.type() == tractor_type) {
1000 Mlt::Tractor tractor(service);
1001 Mlt::Field *field = tractor.field();
1002 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1003 mlt_service nextservicetodisconnect;
1004 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1005 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1006 QString resource = mlt_properties_get(properties, "mlt_service");
1007 // Delete all transitions
1008 while (mlt_type == "transition") {
1009 nextservicetodisconnect = nextservice;
1010 nextservice = mlt_service_producer(nextservice);
1011 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1012 if (nextservice == NULL) break;
1013 properties = MLT_SERVICE_PROPERTIES(nextservice);
1014 mlt_type = mlt_properties_get(properties, "mlt_type");
1015 resource = mlt_properties_get(properties, "mlt_service");
1019 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1020 Mlt::Producer trackProducer(tractor.track(trackNb));
1021 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1022 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1026 mlt_service_unlock(service.get_service());*/
1028 qDeleteAll(m_slowmotionProducers.values());
1029 m_slowmotionProducers.clear();
1031 delete m_mltProducer;
1032 m_mltProducer = NULL;
1038 m_locale = QLocale();
1040 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1041 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1042 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1043 m_mltProducer = m_blackClip->cut(0, 50);
1046 int volume = KdenliveSettings::volume();
1047 m_mltProducer->set("meta.volume", (double)volume / 100);
1048 m_mltProducer->optimise();
1050 /*if (KdenliveSettings::osdtimecode()) {
1051 // Attach filter for on screen display of timecode
1053 QString attr = "attr_check";
1054 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1055 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1056 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1057 mlt_filter_close( filter );
1059 m_osdInfo = new Mlt::Filter("data_show");
1060 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1061 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1062 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1063 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1064 m_osdInfo->set("dynamic", "1");
1066 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1068 m_osdInfo->set("dynamic", "0");
1071 m_fps = m_mltProducer->get_fps();
1072 if (position != 0) {
1073 // Seek to correct place after opening project.
1074 m_mltProducer->seek(position);
1077 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1078 if (error == 0) error = connectPlaylist();
1079 else connectPlaylist();
1080 fillSlowMotionProducers();
1081 blockSignals(false);
1084 //kDebug()<<"// SETSCN LST, POS: "<<position;
1085 //if (position != 0) emit rendererPosition(position);
1088 const QString Render::sceneList()
1091 Mlt::Profile profile((mlt_profile) 0);
1092 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1093 m_mltProducer->optimise();
1094 xmlConsumer.set("terminate_on_pause", 1);
1095 Mlt::Producer prod(m_mltProducer->get_producer());
1096 bool split = m_isSplitView;
1097 if (split) slotSplitView(false);
1098 xmlConsumer.connect(prod);
1099 xmlConsumer.start();
1100 while (!xmlConsumer.is_stopped()) {}
1101 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1102 if (split) slotSplitView(true);
1106 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1110 doc.setContent(sceneList(), false);
1111 if (!kdenliveData.isNull()) {
1112 // add Kdenlive specific tags
1113 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1114 mlt.appendChild(doc.importNode(kdenliveData, true));
1116 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1117 kWarning() << "////// ERROR writing to file: " << path;
1120 file.write(doc.toString().toUtf8());
1121 if (file.error() != QFile::NoError) {
1129 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1131 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1132 m_mltProducer->optimise();
1133 xmlConsumer.set("terminate_on_pause", 1);
1134 if (m_name == "clip") {
1135 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1137 list.insert_at(0, prod, 0);
1139 list.set("title", desc.toUtf8().constData());
1140 xmlConsumer.connect(list);
1143 //TODO: not working yet, save zone from timeline
1144 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1145 /* Mlt::Service service(p1->parent().get_service());
1146 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1148 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1149 //prod->set("title", desc.toUtf8().constData());
1150 xmlConsumer.connect(*p1); //list);
1153 xmlConsumer.start();
1156 double Render::fps() const
1161 int Render::connectPlaylist()
1163 if (!m_mltConsumer) return -1;
1164 //m_mltConsumer->set("refresh", "0");
1165 m_mltConsumer->connect(*m_mltProducer);
1166 m_mltProducer->set_speed(0);
1167 if (m_mltConsumer->start() == -1) {
1168 // ARGH CONSUMER BROKEN!!!!
1169 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."));
1170 delete m_mltConsumer;
1171 m_mltConsumer = NULL;
1174 emit durationChanged(m_mltProducer->get_playtime());
1179 void Render::refreshDisplay()
1182 if (!m_mltProducer) return;
1183 //m_mltConsumer->set("refresh", 0);
1185 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1186 /*if (KdenliveSettings::osdtimecode()) {
1187 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1188 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1189 m_osdInfo->set("dynamic", "1");
1190 m_mltProducer->attach(*m_osdInfo);
1193 m_mltProducer->detach(*m_osdInfo);
1194 m_osdInfo->set("dynamic", "0");
1199 int Render::volume() const
1201 if (!m_mltConsumer || !m_mltProducer) return -1;
1202 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1205 void Render::slotSetVolume(int volume)
1207 if (!m_mltConsumer || !m_mltProducer) return;
1208 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1211 m_mltConsumer->set("refresh", 0);
1212 // Attach filter for on screen display of timecode
1213 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1214 mlt_properties_set_double( properties, "meta.volume", volume );
1215 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1216 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1218 if (!KdenliveSettings::osdtimecode()) {
1219 m_mltProducer->detach(*m_osdInfo);
1220 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1221 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1224 //m_osdTimer->setSingleShot(2500);
1227 void Render::slotOsdTimeout()
1229 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1230 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1231 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1232 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1236 void Render::start()
1238 if (m_winid == -1) {
1239 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1242 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1243 if (m_mltConsumer->start() == -1) {
1244 //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."));
1245 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1254 if (m_mltProducer == NULL) return;
1255 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1256 //kDebug() << "///////////// RENDER STOPPED: " << m_name;
1257 //m_mltConsumer->set("refresh", 0);
1258 m_mltConsumer->stop();
1259 // delete m_mltConsumer;
1260 // m_mltConsumer = NULL;
1263 if (m_mltProducer) {
1264 if (m_isZoneMode) resetZoneMode();
1265 m_mltProducer->set_speed(0.0);
1266 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1267 //kDebug() << m_mltProducer->get_length();
1271 void Render::stop(const GenTime & startTime)
1273 if (m_mltProducer) {
1274 if (m_isZoneMode) resetZoneMode();
1275 m_mltProducer->set_speed(0.0);
1276 m_mltProducer->seek((int) startTime.frames(m_fps));
1278 m_mltConsumer->purge();
1281 void Render::pause()
1283 if (!m_mltProducer || !m_mltConsumer)
1285 if (m_mltProducer->get_speed() == 0.0) return;
1286 if (m_isZoneMode) resetZoneMode();
1287 m_mltConsumer->set("refresh", 0);
1288 m_mltProducer->set_speed(0.0);
1290 The 2 lines below create a flicker loop
1291 emit rendererPosition(m_framePosition);
1292 m_mltProducer->seek(m_framePosition);*/
1293 m_mltConsumer->purge();
1296 void Render::switchPlay(bool play)
1298 if (!m_mltProducer || !m_mltConsumer)
1300 if (m_isZoneMode) resetZoneMode();
1301 if (play && m_mltProducer->get_speed() == 0.0) {
1302 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1303 m_mltProducer->set_speed(1.0);
1304 m_mltConsumer->set("refresh", 1);
1305 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1308 m_mltConsumer->set("refresh", "0");
1310 m_mltProducer->seek(m_framePosition);
1311 /*m_mltConsumer->set("refresh", 0);
1312 m_mltConsumer->stop();
1313 m_mltConsumer->purge();
1314 m_mltProducer->set_speed(0.0);
1315 //m_framePosition = m_mltProducer->position();
1316 m_mltProducer->seek(m_framePosition);
1317 emit rendererPosition(m_framePosition);*/
1321 void Render::play(double speed)
1325 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1326 m_mltProducer->set_speed(speed);
1327 /*if (speed == 0.0) {
1328 m_mltProducer->seek((int) m_framePosition + 1);
1329 m_mltConsumer->purge();
1334 void Render::play(const GenTime & startTime)
1336 if (!m_mltProducer || !m_mltConsumer)
1338 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1339 m_mltProducer->set_speed(1.0);
1340 m_mltConsumer->set("refresh", 1);
1343 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1345 if (!m_mltProducer || !m_mltConsumer)
1347 //m_mltProducer->set("eof", "loop");
1348 m_isLoopMode = true;
1349 m_loopStart = startTime;
1350 playZone(startTime, stopTime);
1353 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1355 if (!m_mltProducer || !m_mltConsumer)
1357 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1358 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1359 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1360 m_mltProducer->set_speed(1.0);
1361 m_mltConsumer->set("refresh", 1);
1362 m_isZoneMode = true;
1365 void Render::resetZoneMode()
1367 if (!m_isZoneMode && !m_isLoopMode) return;
1368 m_mltProducer->set("out", m_originalOut);
1369 //m_mltProducer->set("eof", "pause");
1370 m_isZoneMode = false;
1371 m_isLoopMode = false;
1374 void Render::seekToFrame(int pos)
1379 m_mltProducer->seek(pos);
1383 void Render::seekToFrameDiff(int diff)
1388 m_mltProducer->seek(m_mltProducer->position() + diff);
1392 void Render::doRefresh()
1394 // Use a Timer so that we don't refresh too much
1395 if (m_mltConsumer) {
1396 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1397 m_mltConsumer->set("refresh", 1);
1401 void Render::refresh()
1405 if (m_mltConsumer) {
1406 m_mltConsumer->set("refresh", 1);
1407 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1411 void Render::setDropFrames(bool show)
1413 if (m_mltConsumer) {
1414 int dropFrames = KdenliveSettings::mltthreads();
1415 if (show == false) dropFrames = -dropFrames;
1416 m_mltConsumer->stop();
1418 m_mltConsumer->set("real_time", dropFrames);
1420 m_mltConsumer->set("play.real_time", dropFrames);
1422 if (m_mltConsumer->start() == -1) {
1423 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1429 double Render::playSpeed()
1431 if (m_mltProducer) return m_mltProducer->get_speed();
1435 GenTime Render::seekPosition() const
1437 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1438 else return GenTime();
1441 int Render::seekFramePosition() const
1443 if (m_mltProducer) return (int) m_mltProducer->position();
1447 const QString & Render::rendererName() const
1452 void Render::emitFrameUpdated(Mlt::Frame& frame)
1454 mlt_image_format format = mlt_image_rgb24;
1457 const uchar* image = frame.get_image(format, width, height);
1458 QImage qimage(width, height, QImage::Format_RGB888);
1459 memcpy(qimage.bits(), image, width * height * 3);
1460 emit frameUpdated(qimage);
1463 void Render::emitFrameNumber(double position)
1465 m_framePosition = position;
1466 emit rendererPosition((int) position);
1469 void Render::emitConsumerStopped()
1471 // This is used to know when the playing stopped
1472 if (m_mltProducer) {
1473 double pos = m_mltProducer->position();
1474 if (m_isLoopMode) play(m_loopStart);
1475 else if (m_isZoneMode) resetZoneMode();
1476 emit rendererStopped((int) pos);
1480 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1482 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1485 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1487 if (!m_mltProducer) {
1488 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1492 //int height = 1080;//KdenliveSettings::defaultheight();
1493 //int width = 1940; //KdenliveSettings::displaywidth();
1495 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1497 QPixmap pix(width, height);
1498 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1499 m_convert.set("forced", mlt_image_rgb24a);
1500 m_mltProducer->attach(m_convert);
1501 Mlt::Frame * frame = m_mltProducer->get_frame();
1502 m_mltProducer->detach(m_convert);
1504 pix = frameThumbnail(frame, width, height);
1507 pix.save(url.path(), "PNG");
1508 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1512 void Render::showFrame(Mlt::Frame& frame)
1514 m_framePosition = qMax(frame.get_int("_position"), 0);
1515 emit rendererPosition((int) m_framePosition);
1516 mlt_image_format format = mlt_image_rgb24a;
1519 const uchar* image = frame.get_image(format, width, height);
1520 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1521 memcpy(qimage.scanLine(0), image, width * height * 4);
1522 emit showImageSignal(qimage);
1523 if (analyseAudio) showAudio(frame);
1524 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1525 emit frameUpdated(qimage.rgbSwapped());
1529 void Render::showAudio(Mlt::Frame& frame)
1531 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1534 mlt_audio_format audio_format = mlt_audio_s16;
1536 int num_channels = 0;
1538 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1544 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1545 // So the vector is of size samples*channels.
1546 QVector<int16_t> sampleVector(samples*num_channels);
1547 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1550 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1555 * MLT playlist direct manipulation.
1558 void Render::mltCheckLength(Mlt::Tractor *tractor)
1560 //kDebug()<<"checking track length: "<<track<<"..........";
1562 int trackNb = tractor->count();
1566 Mlt::Producer trackProducer(tractor->track(0));
1567 duration = trackProducer.get_playtime() - 1;
1568 m_mltProducer->set("out", duration);
1569 emit durationChanged(duration);
1572 while (trackNb > 1) {
1573 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1574 trackDuration = trackProducer.get_playtime() - 1;
1575 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1576 if (trackDuration > duration) duration = trackDuration;
1580 Mlt::Producer blackTrackProducer(tractor->track(0));
1582 if (blackTrackProducer.get_playtime() - 1 != duration) {
1583 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1584 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1585 if (blackclip && blackclip->is_blank()) {
1590 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1591 blackTrackPlaylist.clear();
1592 m_blackClip->set("length", duration + 1);
1593 m_blackClip->set("out", duration);
1594 blackclip = m_blackClip->cut(0, duration);
1595 blackTrackPlaylist.insert_at(0, blackclip, 1);
1597 if (duration > blackclip->parent().get_length()) {
1598 blackclip->parent().set("length", duration + 1);
1599 blackclip->parent().set("out", duration);
1600 blackclip->set("length", duration + 1);
1602 blackTrackPlaylist.resize_clip(0, 0, duration);
1606 m_mltProducer->set("out", duration);
1607 emit durationChanged(duration);
1611 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1613 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1615 // We want a slowmotion producer
1616 double speed = element.attribute("speed", "1.0").toDouble();
1617 int strobe = element.attribute("strobe", "1").toInt();
1618 QString url = QString::fromUtf8(prod->get("resource"));
1619 url.append('?' + locale.toString(speed));
1620 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1621 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1622 if (!slowprod || slowprod->get_producer() == NULL) {
1623 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
1624 if (strobe > 1) slowprod->set("strobe", strobe);
1625 QString id = prod->parent().get("id");
1626 if (id.contains('_')) id = id.section('_', 0, 0);
1627 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
1628 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1629 slowprod->set("id", producerid.toUtf8().constData());
1630 m_slowmotionProducers.insert(url, slowprod);
1635 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1637 if (m_mltProducer == NULL) {
1638 kDebug() << "PLAYLIST NOT INITIALISED //////";
1642 kDebug() << "Cannot insert clip without producer //////";
1645 Mlt::Producer parentProd(m_mltProducer->parent());
1646 if (parentProd.get_producer() == NULL) {
1647 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1651 Mlt::Service service(parentProd.get_service());
1652 if (service.type() != tractor_type) {
1653 kWarning() << "// TRACTOR PROBLEM";
1656 Mlt::Tractor tractor(service);
1657 if (info.track > tractor.count() - 1) {
1658 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1661 mlt_service_lock(service.get_service());
1662 Mlt::Producer trackProducer(tractor.track(info.track));
1663 int trackDuration = trackProducer.get_playtime() - 1;
1664 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1665 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1666 prod = checkSlowMotionProducer(prod, element);
1667 if (prod == NULL || !prod->is_valid()) {
1668 mlt_service_unlock(service.get_service());
1672 int cutPos = (int) info.cropStart.frames(m_fps);
1673 if (cutPos < 0) cutPos = 0;
1674 int insertPos = (int) info.startPos.frames(m_fps);
1675 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1676 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1677 if (overwrite && (insertPos < trackDuration)) {
1678 // Replace zone with blanks
1679 //trackPlaylist.split_at(insertPos, true);
1680 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1681 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1682 trackPlaylist.insert_blank(clipIndex, cutDuration);
1684 trackPlaylist.split_at(insertPos, true);
1685 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1686 trackPlaylist.insert_blank(clipIndex, cutDuration);
1688 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1690 /*if (QString(prod->get("transparency")).toInt() == 1)
1691 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1693 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1694 mlt_service_unlock(service.get_service());
1695 /*tractor.multitrack()->refresh();
1696 tractor.refresh();*/
1701 void Render::mltCutClip(int track, GenTime position)
1703 Mlt::Service service(m_mltProducer->parent().get_service());
1704 if (service.type() != tractor_type) {
1705 kWarning() << "// TRACTOR PROBLEM";
1709 Mlt::Tractor tractor(service);
1710 Mlt::Producer trackProducer(tractor.track(track));
1711 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1714 /* // Display playlist info
1715 kDebug()<<"//////////// BEFORE";
1716 for (int i = 0; i < trackPlaylist.count(); i++) {
1717 int blankStart = trackPlaylist.clip_start(i);
1718 int blankDuration = trackPlaylist.clip_length(i) - 1;
1720 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1721 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1724 int cutPos = (int) position.frames(m_fps);
1726 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1727 if (trackPlaylist.is_blank(clipIndex)) {
1728 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1731 mlt_service_lock(service.get_service());
1732 int clipStart = trackPlaylist.clip_start(clipIndex);
1733 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1734 mlt_service_unlock(service.get_service());
1736 // duplicate effects
1737 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1738 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1740 if (original == NULL || clip == NULL) {
1741 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1743 Mlt::Service clipService(original->get_service());
1744 Mlt::Service dupService(clip->get_service());
1748 Mlt::Filter *filter = clipService.filter(ct);
1750 // Only duplicate Kdenlive filters, and skip the fade in effects
1751 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1752 // looks like there is no easy way to duplicate a filter,
1753 // so we will create a new one and duplicate its properties
1754 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1755 if (dup && dup->is_valid()) {
1756 Mlt::Properties entries(filter->get_properties());
1757 for (int i = 0; i < entries.count(); i++) {
1758 dup->set(entries.get_name(i), entries.get(i));
1760 dupService.attach(*dup);
1764 filter = clipService.filter(ct);
1767 /* // Display playlist info
1768 kDebug()<<"//////////// AFTER";
1769 for (int i = 0; i < trackPlaylist.count(); i++) {
1770 int blankStart = trackPlaylist.clip_start(i);
1771 int blankDuration = trackPlaylist.clip_length(i) - 1;
1773 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1774 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1779 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1783 kDebug() << "Cannot update clip with null producer //////";
1786 Mlt::Service service(m_mltProducer->parent().get_service());
1787 if (service.type() != tractor_type) {
1788 kWarning() << "// TRACTOR PROBLEM";
1791 Mlt::Tractor tractor(service);
1792 Mlt::Producer trackProducer(tractor.track(tractor.count() - 1 - info.track));
1793 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1794 int startPos = info.startPos.frames(m_fps);
1795 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1796 if (trackPlaylist.is_blank(clipIndex)) {
1797 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1800 mlt_service_lock(service.get_service());
1801 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1803 QList <Mlt::Filter *> filtersList;
1804 Mlt::Service sourceService(clip->get_service());
1806 Mlt::Filter *filter = sourceService.filter(ct);
1808 if (filter->get_int("kdenlive_ix") != 0) {
1809 filtersList.append(filter);
1812 filter = sourceService.filter(ct);
1815 trackPlaylist.replace_with_blank(clipIndex);
1817 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1818 prod = checkSlowMotionProducer(prod, element);
1819 if (prod == NULL || !prod->is_valid()) {
1820 mlt_service_unlock(service.get_service());
1824 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
1825 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1829 //if (mltInsertClip(info, element, prod) == -1) return false;
1830 if (!filtersList.isEmpty()) {
1831 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1832 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1833 Mlt::Service destService(destclip->get_service());
1835 for (int i = 0; i < filtersList.count(); i++)
1836 destService.attach(*(filtersList.at(i)));
1838 mlt_service_unlock(service.get_service());
1843 bool Render::mltRemoveClip(int track, GenTime position)
1845 Mlt::Service service(m_mltProducer->parent().get_service());
1846 if (service.type() != tractor_type) {
1847 kWarning() << "// TRACTOR PROBLEM";
1851 Mlt::Tractor tractor(service);
1852 Mlt::Producer trackProducer(tractor.track(track));
1853 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1854 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1856 if (trackPlaylist.is_blank(clipIndex)) {
1857 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
1858 //mlt_service_unlock(service.get_service());
1861 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1862 if (clip) delete clip;
1863 trackPlaylist.consolidate_blanks(0);
1865 /* // Display playlist info
1866 kDebug()<<"//// AFTER";
1867 for (int i = 0; i < trackPlaylist.count(); i++) {
1868 int blankStart = trackPlaylist.clip_start(i);
1869 int blankDuration = trackPlaylist.clip_length(i) - 1;
1871 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1872 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1875 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1879 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
1881 if (!m_mltProducer) {
1882 kDebug() << "PLAYLIST NOT INITIALISED //////";
1885 Mlt::Producer parentProd(m_mltProducer->parent());
1886 if (parentProd.get_producer() == NULL) {
1887 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1891 Mlt::Service service(parentProd.get_service());
1892 Mlt::Tractor tractor(service);
1893 int insertPos = pos.frames(m_fps);
1895 Mlt::Producer trackProducer(tractor.track(track));
1896 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1897 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1898 if (clipIndex == trackPlaylist.count()) {
1899 // We are after the end of the playlist
1902 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1903 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1904 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1907 int Render::mltTrackDuration(int track)
1909 if (!m_mltProducer) {
1910 kDebug() << "PLAYLIST NOT INITIALISED //////";
1913 Mlt::Producer parentProd(m_mltProducer->parent());
1914 if (parentProd.get_producer() == NULL) {
1915 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1919 Mlt::Service service(parentProd.get_service());
1920 Mlt::Tractor tractor(service);
1922 Mlt::Producer trackProducer(tractor.track(track));
1923 return trackProducer.get_playtime() - 1;
1926 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
1928 if (!m_mltProducer) {
1929 kDebug() << "PLAYLIST NOT INITIALISED //////";
1932 Mlt::Producer parentProd(m_mltProducer->parent());
1933 if (parentProd.get_producer() == NULL) {
1934 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1937 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1938 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1940 Mlt::Service service(parentProd.get_service());
1941 Mlt::Tractor tractor(service);
1942 mlt_service_lock(service.get_service());
1943 int diff = duration.frames(m_fps);
1944 int offset = timeOffset.frames(m_fps);
1948 // insert space in one track only
1949 Mlt::Producer trackProducer(tractor.track(track));
1950 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1951 insertPos = trackClipStartList.value(track);
1952 if (insertPos != -1) {
1953 insertPos += offset;
1954 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1956 trackPlaylist.insert_blank(clipIndex, diff - 1);
1958 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1959 if (!trackPlaylist.is_blank(clipIndex)) {
1960 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1962 int position = trackPlaylist.clip_start(clipIndex);
1963 int blankDuration = trackPlaylist.clip_length(clipIndex);
1964 if (blankDuration + diff == 0) {
1965 trackPlaylist.remove(clipIndex);
1966 } else trackPlaylist.remove_region(position, -diff);
1968 trackPlaylist.consolidate_blanks(0);
1970 // now move transitions
1971 mlt_service serv = m_mltProducer->parent().get_service();
1972 mlt_service nextservice = mlt_service_get_producer(serv);
1973 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1974 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1975 QString resource = mlt_properties_get(properties, "mlt_service");
1977 while (mlt_type == "transition") {
1978 mlt_transition tr = (mlt_transition) nextservice;
1979 int currentTrack = mlt_transition_get_b_track(tr);
1980 int currentIn = (int) mlt_transition_get_in(tr);
1981 int currentOut = (int) mlt_transition_get_out(tr);
1982 insertPos = trackTransitionStartList.value(track);
1983 if (insertPos != -1) {
1984 insertPos += offset;
1985 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1986 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1989 nextservice = mlt_service_producer(nextservice);
1990 if (nextservice == NULL) break;
1991 properties = MLT_SERVICE_PROPERTIES(nextservice);
1992 mlt_type = mlt_properties_get(properties, "mlt_type");
1993 resource = mlt_properties_get(properties, "mlt_service");
1996 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1997 Mlt::Producer trackProducer(tractor.track(trackNb));
1998 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2000 //int clipNb = trackPlaylist.count();
2001 insertPos = trackClipStartList.value(trackNb);
2002 if (insertPos != -1) {
2003 insertPos += offset;
2005 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2006 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2007 for (int i = 0; i < clipNb; i++) {
2008 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2009 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2010 kDebug()<<"-------------";
2012 kDebug()<<"END-------------";*/
2015 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2017 trackPlaylist.insert_blank(clipIndex, diff - 1);
2019 if (!trackPlaylist.is_blank(clipIndex)) {
2022 if (!trackPlaylist.is_blank(clipIndex)) {
2023 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2025 int position = trackPlaylist.clip_start(clipIndex);
2026 int blankDuration = trackPlaylist.clip_length(clipIndex);
2027 if (diff + blankDuration == 0) {
2028 trackPlaylist.remove(clipIndex);
2029 } else trackPlaylist.remove_region(position, - diff);
2031 trackPlaylist.consolidate_blanks(0);
2034 // now move transitions
2035 mlt_service serv = m_mltProducer->parent().get_service();
2036 mlt_service nextservice = mlt_service_get_producer(serv);
2037 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2038 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2039 QString resource = mlt_properties_get(properties, "mlt_service");
2041 while (mlt_type == "transition") {
2042 mlt_transition tr = (mlt_transition) nextservice;
2043 int currentIn = (int) mlt_transition_get_in(tr);
2044 int currentOut = (int) mlt_transition_get_out(tr);
2045 int currentTrack = mlt_transition_get_b_track(tr);
2046 insertPos = trackTransitionStartList.value(currentTrack);
2047 if (insertPos != -1) {
2048 insertPos += offset;
2049 if (currentOut > insertPos && resource != "mix") {
2050 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2053 nextservice = mlt_service_producer(nextservice);
2054 if (nextservice == NULL) break;
2055 properties = MLT_SERVICE_PROPERTIES(nextservice);
2056 mlt_type = mlt_properties_get(properties, "mlt_type");
2057 resource = mlt_properties_get(properties, "mlt_service");
2060 mlt_service_unlock(service.get_service());
2061 mltCheckLength(&tractor);
2062 m_mltConsumer->set("refresh", 1);
2066 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2068 if (source == dest) return;
2069 Mlt::Service sourceService(source->get_service());
2070 Mlt::Service destService(dest->get_service());
2072 // move all effects to the correct producer
2074 Mlt::Filter *filter = sourceService.filter(ct);
2076 if (filter->get_int("kdenlive_ix") != 0) {
2077 sourceService.detach(*filter);
2078 destService.attach(*filter);
2080 filter = sourceService.filter(ct);
2084 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2087 Mlt::Service service(m_mltProducer->parent().get_service());
2088 if (service.type() != tractor_type) {
2089 kWarning() << "// TRACTOR PROBLEM";
2093 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2094 Mlt::Tractor tractor(service);
2095 Mlt::Producer trackProducer(tractor.track(info.track));
2096 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2097 int startPos = info.startPos.frames(m_fps);
2098 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2099 int clipLength = trackPlaylist.clip_length(clipIndex);
2101 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2102 if (original == NULL) {
2105 if (!original->is_valid() || original->is_blank()) {
2110 Mlt::Producer clipparent = original->parent();
2111 if (!clipparent.is_valid() || clipparent.is_blank()) {
2117 QString serv = clipparent.get("mlt_service");
2118 QString id = clipparent.get("id");
2119 if (speed <= 0 && speed > -1) speed = 1.0;
2120 //kDebug() << "CLIP SERVICE: " << serv;
2121 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2122 mlt_service_lock(service.get_service());
2123 QString url = QString::fromUtf8(clipparent.get("resource"));
2124 url.append('?' + m_locale.toString(speed));
2125 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2126 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2127 if (!slowprod || slowprod->get_producer() == NULL) {
2128 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2129 if (strobe > 1) slowprod->set("strobe", strobe);
2130 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2131 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2132 slowprod->set("id", producerid.toUtf8().constData());
2133 // copy producer props
2134 double ar = original->parent().get_double("force_aspect_ratio");
2135 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2136 double fps = original->parent().get_double("force_fps");
2137 if (fps != 0.0) slowprod->set("force_fps", fps);
2138 int threads = original->parent().get_int("threads");
2139 if (threads != 0) slowprod->set("threads", threads);
2140 if (original->parent().get("force_progressive"))
2141 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2142 if (original->parent().get("force_tff"))
2143 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2144 int ix = original->parent().get_int("video_index");
2145 if (ix != 0) slowprod->set("video_index", ix);
2146 int colorspace = original->parent().get_int("force_colorspace");
2147 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2148 int full_luma = original->parent().get_int("set.force_full_luma");
2149 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2150 m_slowmotionProducers.insert(url, slowprod);
2152 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2153 trackPlaylist.consolidate_blanks(0);
2155 // Check that the blank space is long enough for our new duration
2156 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2157 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2159 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2160 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2161 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2162 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2164 // move all effects to the correct producer
2165 mltPasteEffects(clip, cut);
2166 trackPlaylist.insert_at(startPos, cut, 1);
2169 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2170 newLength = trackPlaylist.clip_length(clipIndex);
2171 mlt_service_unlock(service.get_service());
2172 } else if (speed == 1.0 && strobe < 2) {
2173 mlt_service_lock(service.get_service());
2175 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2176 trackPlaylist.consolidate_blanks(0);
2178 // Check that the blank space is long enough for our new duration
2179 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2180 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2183 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2184 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2185 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2186 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2187 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2189 // move all effects to the correct producer
2190 mltPasteEffects(clip, cut);
2192 trackPlaylist.insert_at(startPos, cut, 1);
2195 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2196 newLength = trackPlaylist.clip_length(clipIndex);
2197 mlt_service_unlock(service.get_service());
2199 } else if (serv == "framebuffer") {
2200 mlt_service_lock(service.get_service());
2201 QString url = QString::fromUtf8(clipparent.get("resource"));
2202 url = url.section('?', 0, 0);
2203 url.append('?' + m_locale.toString(speed));
2204 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2205 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2206 if (!slowprod || slowprod->get_producer() == NULL) {
2207 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2208 slowprod->set("strobe", strobe);
2209 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2210 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2211 slowprod->set("id", producerid.toUtf8().constData());
2212 // copy producer props
2213 double ar = original->parent().get_double("force_aspect_ratio");
2214 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2215 double fps = original->parent().get_double("force_fps");
2216 if (fps != 0.0) slowprod->set("force_fps", fps);
2217 if (original->parent().get("force_progressive"))
2218 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2219 if (original->parent().get("force_tff"))
2220 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2221 int threads = original->parent().get_int("threads");
2222 if (threads != 0) slowprod->set("threads", threads);
2223 int ix = original->parent().get_int("video_index");
2224 if (ix != 0) slowprod->set("video_index", ix);
2225 int colorspace = original->parent().get_int("force_colorspace");
2226 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2227 int full_luma = original->parent().get_int("set.force_full_luma");
2228 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2229 m_slowmotionProducers.insert(url, slowprod);
2231 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2232 trackPlaylist.consolidate_blanks(0);
2234 GenTime duration = speedIndependantInfo.cropDuration / speed;
2235 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2237 // Check that the blank space is long enough for our new duration
2238 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2239 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2242 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2243 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2244 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2245 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2247 // move all effects to the correct producer
2248 mltPasteEffects(clip, cut);
2250 trackPlaylist.insert_at(startPos, cut, 1);
2253 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2254 newLength = trackPlaylist.clip_length(clipIndex);
2256 mlt_service_unlock(service.get_service());
2259 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2263 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2265 Mlt::Service service(m_mltProducer->parent().get_service());
2266 bool success = false;
2267 Mlt::Tractor tractor(service);
2268 Mlt::Producer trackProducer(tractor.track(track));
2269 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2270 Mlt::Service clipService(trackPlaylist.get_service());
2272 mlt_service_lock(service.get_service());
2274 Mlt::Filter *filter = clipService.filter(ct);
2276 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2277 if (clipService.detach(*filter) == 0) success = true;
2278 } else if (updateIndex) {
2279 // Adjust the other effects index
2280 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2283 filter = clipService.filter(ct);
2285 mlt_service_unlock(service.get_service());
2290 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2292 if (position < GenTime()) {
2293 // Remove track effect
2294 return mltRemoveTrackEffect(track, index, updateIndex);
2296 Mlt::Service service(m_mltProducer->parent().get_service());
2297 bool success = false;
2298 Mlt::Tractor tractor(service);
2299 Mlt::Producer trackProducer(tractor.track(track));
2300 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2302 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2303 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2305 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2309 Mlt::Service clipService(clip->get_service());
2310 int duration = clip->get_playtime();
2312 // Check if clip is visible in monitor
2313 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2314 if (diff < 0 || diff > duration) doRefresh = false;
2318 mlt_service_lock(service.get_service());
2320 Mlt::Filter *filter = clipService.filter(ct);
2322 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2323 if (clipService.detach(*filter) == 0) success = true;
2324 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2325 } else if (updateIndex) {
2326 // Adjust the other effects index
2327 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2330 filter = clipService.filter(ct);
2332 mlt_service_unlock(service.get_service());
2333 if (doRefresh) refresh();
2337 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2339 Mlt::Service service(m_mltProducer->parent().get_service());
2340 Mlt::Tractor tractor(service);
2341 Mlt::Producer trackProducer(tractor.track(track));
2342 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2343 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2344 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2348 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2351 Mlt::Service service(m_mltProducer->parent().get_service());
2353 Mlt::Tractor tractor(service);
2354 Mlt::Producer trackProducer(tractor.track(track));
2355 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2357 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2358 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2363 Mlt::Service clipService(clip->get_service());
2364 int duration = clip->get_playtime();
2366 // Check if clip is visible in monitor
2367 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2368 if (diff < 0 || diff > duration) doRefresh = false;
2371 return mltAddEffect(clipService, params, duration, doRefresh);
2374 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2376 bool updateIndex = false;
2377 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2378 const QString region = params.paramValue("region");
2380 mlt_service_lock(service.get_service());
2382 Mlt::Filter *filter = service.filter(ct);
2384 if (filter->get_int("kdenlive_ix") == filter_ix) {
2385 // A filter at that position already existed, so we will increase all indexes later
2390 filter = service.filter(ct);
2393 if (params.paramValue("id") == "speed") {
2394 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2396 filter = service.filter(ct);
2398 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2399 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2402 filter = service.filter(ct);
2404 mlt_service_unlock(service.get_service());
2405 if (doRefresh) refresh();
2410 // temporarily remove all effects after insert point
2411 QList <Mlt::Filter *> filtersList;
2413 filter = service.filter(ct);
2415 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2416 filtersList.append(filter);
2417 service.detach(*filter);
2419 filter = service.filter(ct);
2423 QString tag = params.paramValue("tag");
2424 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2425 char *filterTag = qstrdup(tag.toUtf8().constData());
2426 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2427 QHash<QString, QString>::Iterator it;
2428 QString kfr = params.paramValue("keyframes");
2430 if (!kfr.isEmpty()) {
2431 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2432 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2433 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2434 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2435 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2436 //double max = params.paramValue("max").toDouble();
2437 double min = params.paramValue("min").toDouble();
2438 double factor = params.paramValue("factor", "1").toDouble();
2439 double paramOffset = params.paramValue("offset", "0").toDouble();
2440 params.removeParam("starttag");
2441 params.removeParam("endtag");
2442 params.removeParam("keyframes");
2443 params.removeParam("min");
2444 params.removeParam("max");
2445 params.removeParam("factor");
2446 params.removeParam("offset");
2448 // Special case, only one keyframe, means we want a constant value
2449 if (keyFrames.count() == 1) {
2450 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2451 if (filter && filter->is_valid()) {
2452 filter->set("kdenlive_id", filterId);
2453 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2454 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2455 for (int j = 0; j < params.count(); j++) {
2456 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2458 filter->set("in", x1);
2459 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2460 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2461 service.attach(*filter);
2463 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2464 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2465 if (filter && filter->is_valid()) {
2466 filter->set("kdenlive_id", filterId);
2467 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2468 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2469 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2470 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2471 if (x2 == -1) x2 = duration;
2473 for (int j = 0; j < params.count(); j++) {
2474 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2477 filter->set("in", x1);
2478 filter->set("out", x2);
2479 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2480 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2481 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2482 service.attach(*filter);
2489 Mlt::Filter *filter;
2491 if (!region.isEmpty()) {
2492 filter = new Mlt::Filter(*m_mltProfile, "region");
2493 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2494 if (filter && filter->is_valid()) {
2495 filter->set("kdenlive_id", filterId);
2496 if (!region.isEmpty()) {
2497 filter->set("resource", region.toUtf8().constData());
2498 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2499 filter->set("filter0", filterTag);
2500 prefix = "filter0.";
2501 params.removeParam("id");
2502 params.removeParam("region");
2503 params.removeParam("kdenlive_ix");
2506 kDebug() << "filter is NULL";
2507 mlt_service_unlock(service.get_service());
2510 params.removeParam("kdenlive_id");
2511 if (params.hasParam("_sync_in_out")) {
2512 // This effect must sync in / out with parent clip
2513 params.removeParam("_sync_in_out");
2514 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2517 for (int j = 0; j < params.count(); j++) {
2518 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2522 QString effectArgs = params.paramValue("id").section('_', 1);
2524 params.removeParam("id");
2525 params.removeParam("kdenlive_ix");
2526 params.removeParam("tag");
2527 params.removeParam("disable");
2528 params.removeParam("region");
2530 for (int j = 0; j < params.count(); j++) {
2531 effectArgs.append(' ' + params.at(j).value());
2533 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2534 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2537 // attach filter to the clip
2538 service.attach(*filter);
2543 // re-add following filters
2544 for (int i = 0; i < filtersList.count(); i++) {
2545 Mlt::Filter *filter = filtersList.at(i);
2547 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2548 service.attach(*filter);
2550 mlt_service_unlock(service.get_service());
2551 if (doRefresh) refresh();
2555 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2557 Mlt::Service service(m_mltProducer->parent().get_service());
2558 Mlt::Tractor tractor(service);
2559 Mlt::Producer trackProducer(tractor.track(track));
2560 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2561 Mlt::Service clipService(trackPlaylist.get_service());
2563 QString index = params.paramValue("kdenlive_ix");
2564 QString tag = params.paramValue("tag");
2566 Mlt::Filter *filter = clipService.filter(ct);
2568 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2572 filter = clipService.filter(ct);
2576 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2577 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2579 bool success = false;//mltAddTrackEffect(track, params);
2583 QString ser = filter->get("mlt_service");
2584 if (ser == "region") prefix = "filter0.";
2585 mlt_service_lock(service.get_service());
2586 for (int j = 0; j < params.count(); j++) {
2587 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2589 mlt_service_unlock(service.get_service());
2596 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2598 int index = params.paramValue("kdenlive_ix").toInt();
2599 QString tag = params.paramValue("tag");
2601 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2602 // This is a keyframe effect, to edit it, we remove it and re-add it.
2603 bool success = mltRemoveEffect(track, position, index, false);
2604 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
2605 if (position < GenTime())
2606 success = mltAddTrackEffect(track, params);
2608 success = mltAddEffect(track, position, params);
2609 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
2612 if (position < GenTime()) {
2613 return mltEditTrackEffect(track, params);
2616 Mlt::Service service(m_mltProducer->parent().get_service());
2617 Mlt::Tractor tractor(service);
2618 Mlt::Producer trackProducer(tractor.track(track));
2619 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2621 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2622 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2624 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2628 int duration = clip->get_playtime();
2629 bool doRefresh = true;
2630 // Check if clip is visible in monitor
2631 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2632 if (diff < 0 || diff > duration)
2636 Mlt::Filter *filter = clip->filter(ct);
2638 if (filter->get_int("kdenlive_ix") == index) {
2642 filter = clip->filter(ct);
2646 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2647 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2649 bool success = mltAddEffect(track, position, params);
2653 QString ser = filter->get("mlt_service");
2654 if (ser == "region") prefix = "filter0.";
2655 if (params.hasParam("_sync_in_out")) {
2656 // This effect must sync in / out with parent clip
2657 params.removeParam("_sync_in_out");
2658 filter->set_in_and_out(clip->get_in(), clip->get_out());
2660 mlt_service_lock(service.get_service());
2661 for (int j = 0; j < params.count(); j++) {
2662 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2666 mlt_service_unlock(service.get_service());
2668 if (doRefresh) refresh();
2672 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2674 Mlt::Service service(m_mltProducer->parent().get_service());
2675 Mlt::Tractor tractor(service);
2676 Mlt::Producer trackProducer(tractor.track(track));
2677 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2679 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2680 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2682 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2686 Mlt::Service clipService(clip->get_service());
2687 int duration = clip->get_playtime();
2688 bool doRefresh = true;
2689 // Check if clip is visible in monitor
2690 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2691 if (diff < 0 || diff > duration) doRefresh = false;
2695 Mlt::Filter *filter = clipService.filter(ct);
2697 int pos = filter->get_int("kdenlive_ix");
2698 if (pos == oldPos) {
2699 filter->set("kdenlive_ix", newPos);
2701 filter = clipService.filter(ct);
2703 if (doRefresh) refresh();
2706 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2708 if (position < GenTime()) {
2709 mltMoveTrackEffect(track, oldPos, newPos);
2712 Mlt::Service service(m_mltProducer->parent().get_service());
2713 Mlt::Tractor tractor(service);
2714 Mlt::Producer trackProducer(tractor.track(track));
2715 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2717 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2718 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2720 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2724 Mlt::Service clipService(clip->get_service());
2725 int duration = clip->get_playtime();
2726 bool doRefresh = true;
2727 // Check if clip is visible in monitor
2728 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2729 if (diff < 0 || diff > duration) doRefresh = false;
2733 QList <Mlt::Filter *> filtersList;
2734 Mlt::Filter *filter = clipService.filter(ct);
2736 if (newPos > oldPos) {
2738 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2739 filter->set("kdenlive_ix", newPos);
2740 filtersList.append(filter);
2741 clipService.detach(*filter);
2742 filter = clipService.filter(ct);
2743 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2744 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2746 filter = clipService.filter(ct);
2750 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2751 filtersList.append(filter);
2752 clipService.detach(*filter);
2754 filter = clipService.filter(ct);
2758 if (filter->get_int("kdenlive_ix") == oldPos) {
2759 filter->set("kdenlive_ix", newPos);
2760 filtersList.append(filter);
2761 clipService.detach(*filter);
2763 filter = clipService.filter(ct);
2767 filter = clipService.filter(ct);
2769 int pos = filter->get_int("kdenlive_ix");
2770 if (pos >= newPos) {
2771 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2772 filtersList.append(filter);
2773 clipService.detach(*filter);
2775 filter = clipService.filter(ct);
2779 for (int i = 0; i < filtersList.count(); i++) {
2780 clipService.attach(*(filtersList.at(i)));
2783 if (doRefresh) refresh();
2786 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2788 Mlt::Service service(m_mltProducer->parent().get_service());
2789 Mlt::Tractor tractor(service);
2790 Mlt::Producer trackProducer(tractor.track(track));
2791 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2792 Mlt::Service clipService(trackPlaylist.get_service());
2794 QList <Mlt::Filter *> filtersList;
2795 Mlt::Filter *filter = clipService.filter(ct);
2797 if (newPos > oldPos) {
2799 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2800 filter->set("kdenlive_ix", newPos);
2801 filtersList.append(filter);
2802 clipService.detach(*filter);
2803 filter = clipService.filter(ct);
2804 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2805 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2807 filter = clipService.filter(ct);
2811 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2812 filtersList.append(filter);
2813 clipService.detach(*filter);
2815 filter = clipService.filter(ct);
2819 if (filter->get_int("kdenlive_ix") == oldPos) {
2820 filter->set("kdenlive_ix", newPos);
2821 filtersList.append(filter);
2822 clipService.detach(*filter);
2824 filter = clipService.filter(ct);
2828 filter = clipService.filter(ct);
2830 int pos = filter->get_int("kdenlive_ix");
2831 if (pos >= newPos) {
2832 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2833 filtersList.append(filter);
2834 clipService.detach(*filter);
2836 filter = clipService.filter(ct);
2840 for (int i = 0; i < filtersList.count(); i++) {
2841 clipService.attach(*(filtersList.at(i)));
2846 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2848 Mlt::Service service(m_mltProducer->parent().get_service());
2849 Mlt::Tractor tractor(service);
2850 Mlt::Producer trackProducer(tractor.track(info.track));
2851 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2853 /* // Display playlist info
2854 kDebug()<<"//////////// BEFORE RESIZE";
2855 for (int i = 0; i < trackPlaylist.count(); i++) {
2856 int blankStart = trackPlaylist.clip_start(i);
2857 int blankDuration = trackPlaylist.clip_length(i) - 1;
2859 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2860 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2863 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2864 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2867 mlt_service_lock(service.get_service());
2868 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2869 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2870 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2872 int previousStart = clip->get_in();
2873 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2874 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2876 int currentOut = newDuration + previousStart;
2877 if (currentOut > clip->get_length()) {
2878 clip->parent().set("length", currentOut + 1);
2879 clip->parent().set("out", currentOut);
2880 clip->set("length", currentOut + 1);
2883 /*if (newDuration > clip->get_out()) {
2884 clip->parent().set_in_and_out(0, newDuration + 1);
2885 clip->set_in_and_out(0, newDuration + 1);
2888 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2889 trackPlaylist.consolidate_blanks(0);
2890 // skip to next clip
2892 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2894 // clip was made longer, trim next blank if there is one.
2895 if (clipIndex < trackPlaylist.count()) {
2896 // If this is not the last clip in playlist
2897 if (trackPlaylist.is_blank(clipIndex)) {
2898 int blankStart = trackPlaylist.clip_start(clipIndex);
2899 int blankDuration = trackPlaylist.clip_length(clipIndex);
2900 if (diff > blankDuration) {
2901 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2903 if (diff - blankDuration == 0) {
2904 trackPlaylist.remove(clipIndex);
2905 } else trackPlaylist.remove_region(blankStart, diff);
2907 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2910 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2911 trackPlaylist.consolidate_blanks(0);
2912 mlt_service_unlock(service.get_service());
2914 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2915 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2916 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2917 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2918 ItemInfo transpinfo;
2919 transpinfo.startPos = info.startPos;
2920 transpinfo.endPos = info.startPos + clipDuration;
2921 transpinfo.track = info.track;
2922 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2924 m_mltConsumer->set("refresh", 1);
2928 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2930 Mlt::Service service(m_mltProducer->parent().get_service());
2931 Mlt::Tractor tractor(service);
2932 Mlt::Producer trackProducer(tractor.track(track));
2934 // Make sure muting will not produce problems with our audio mixing transition,
2935 // because audio mixing is done between each track and the lowest one
2936 bool audioMixingBroken = false;
2937 if (mute && trackProducer.get_int("hide") < 2 ) {
2938 // We mute a track with sound
2939 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
2940 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
2942 else if (!mute && trackProducer.get_int("hide") > 1 ) {
2943 // We un-mute a previously muted track
2944 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
2948 if (blind) trackProducer.set("hide", 3);
2949 else trackProducer.set("hide", 2);
2951 trackProducer.set("hide", 1);
2953 trackProducer.set("hide", 0);
2955 if (audioMixingBroken) fixAudioMixing(tractor);
2957 tractor.multitrack()->refresh();
2962 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
2964 for (int i = 1; i < tractor.count(); i++) {
2965 Mlt::Producer trackProducer(tractor.track(i));
2966 if (trackProducer.get_int("hide") < 2) return i;
2968 return tractor.count() - 1;
2971 void Render::fixAudioMixing(Mlt::Tractor tractor)
2973 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
2974 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
2976 mlt_service serv = m_mltProducer->parent().get_service();
2977 Mlt::Field *field = tractor.field();
2978 mlt_service_lock(serv);
2980 mlt_service nextservice = mlt_service_get_producer(serv);
2981 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2982 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2983 QString resource = mlt_properties_get(properties, "mlt_service");
2985 mlt_service nextservicetodisconnect;
2986 // Delete all audio mixing transitions
2987 while (mlt_type == "transition") {
2988 if (resource == "mix") {
2989 nextservicetodisconnect = nextservice;
2990 nextservice = mlt_service_producer(nextservice);
2991 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
2993 else nextservice = mlt_service_producer(nextservice);
2994 if (nextservice == NULL) break;
2995 properties = MLT_SERVICE_PROPERTIES(nextservice);
2996 mlt_type = mlt_properties_get(properties, "mlt_type");
2997 resource = mlt_properties_get(properties, "mlt_service");
3000 // Re-add correct audio transitions
3001 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
3002 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3003 transition->set("always_active", 1);
3004 transition->set("combine", 1);
3005 transition->set("internal_added", 237);
3006 field->plant_transition(*transition, lowestTrack, i);
3008 mlt_service_unlock(serv);
3011 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
3013 Mlt::Service service(m_mltProducer->parent().get_service());
3014 int frameOffset = (int) diff.frames(m_fps);
3015 Mlt::Tractor tractor(service);
3016 Mlt::Producer trackProducer(tractor.track(info.track));
3017 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3018 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3019 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3022 mlt_service_lock(service.get_service());
3023 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3024 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3026 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3027 mlt_service_unlock(service.get_service());
3030 int previousStart = clip->get_in();
3031 int previousOut = clip->get_out();
3033 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
3034 mlt_service_unlock(service.get_service());
3035 m_mltConsumer->set("refresh", 1);
3039 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3041 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3042 Mlt::Service service(m_mltProducer->parent().get_service());
3043 int moveFrame = (int) diff.frames(m_fps);
3044 Mlt::Tractor tractor(service);
3045 Mlt::Producer trackProducer(tractor.track(info.track));
3046 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3047 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3048 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3051 mlt_service_lock(service.get_service());
3052 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3053 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3054 if (clip == NULL || clip->is_blank()) {
3055 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3056 mlt_service_unlock(service.get_service());
3059 int previousStart = clip->get_in();
3060 int previousOut = clip->get_out();
3062 previousStart += moveFrame;
3064 if (previousStart < 0) {
3065 // this is possible for images and color clips
3066 previousOut -= previousStart;
3070 int length = previousOut + 1;
3071 if (length > clip->get_length()) {
3072 clip->parent().set("length", length + 1);
3073 clip->parent().set("out", length);
3074 clip->set("length", length + 1);
3078 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3079 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3080 if (moveFrame > 0) {
3081 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3083 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3084 int blankIndex = clipIndex - 1;
3085 int blankLength = trackPlaylist.clip_length(blankIndex);
3086 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3087 if (! trackPlaylist.is_blank(blankIndex)) {
3088 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3090 if (blankLength + moveFrame == 0)
3091 trackPlaylist.remove(blankIndex);
3093 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3095 trackPlaylist.consolidate_blanks(0);
3096 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3097 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3098 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3099 ItemInfo transpinfo;
3100 transpinfo.startPos = info.startPos + diff;
3101 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3102 transpinfo.track = info.track;
3103 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3105 //m_mltConsumer->set("refresh", 1);
3106 mlt_service_unlock(service.get_service());
3107 m_mltConsumer->set("refresh", 1);
3111 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3113 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3117 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3119 if (prod == NULL || !prod->is_valid()) {
3120 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3123 //kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3124 Mlt::Service service(m_mltProducer->parent().get_service());
3125 if (service.type() != tractor_type) {
3126 kWarning() << "// TRACTOR PROBLEM";
3129 mlt_service_lock(service.get_service());
3130 Mlt::Tractor tractor(service);
3131 Mlt::Producer trackProducer(tractor.track(track));
3132 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3133 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3134 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3135 if (clipProducer == NULL || clipProducer->is_blank()) {
3136 kDebug() << "// ERROR UPDATING CLIP PROD";
3137 delete clipProducer;
3138 mlt_service_unlock(service.get_service());
3141 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3142 if (!clip || !clip->is_valid()) {
3143 if (clip) delete clip;
3144 delete clipProducer;
3145 mlt_service_unlock(service.get_service());
3148 // move all effects to the correct producer
3149 mltPasteEffects(clipProducer, clip);
3150 trackPlaylist.insert_at(pos, clip, 1);
3152 delete clipProducer;
3153 mlt_service_unlock(service.get_service());
3157 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3159 Mlt::Service service(m_mltProducer->parent().get_service());
3160 if (service.type() != tractor_type) {
3161 kWarning() << "// TRACTOR PROBLEM";
3165 Mlt::Tractor tractor(service);
3166 mlt_service_lock(service.get_service());
3167 Mlt::Producer trackProducer(tractor.track(startTrack));
3168 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3169 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3170 //kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3171 bool checkLength = false;
3172 if (endTrack == startTrack) {
3173 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3174 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3175 // error, destination is not empty
3177 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3178 delete clipProducer;
3180 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3181 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3182 mlt_service_unlock(service.get_service());
3185 trackPlaylist.consolidate_blanks(0);
3187 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3188 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3189 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3191 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3192 trackPlaylist.consolidate_blanks(1);
3193 delete clipProducer;
3194 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3195 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3197 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3199 //mlt_service_unlock(service.get_service());
3201 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3202 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3203 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3204 // error, destination is not empty
3205 mlt_service_unlock(service.get_service());
3208 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3209 if (!clipProducer || clipProducer->is_blank()) {
3210 // error, destination is not empty
3211 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3212 if (clipProducer) delete clipProducer;
3213 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3214 mlt_service_unlock(service.get_service());
3217 trackPlaylist.consolidate_blanks(0);
3218 destTrackPlaylist.consolidate_blanks(1);
3219 Mlt::Producer *clip;
3220 // check if we are moving a slowmotion producer
3221 QString serv = clipProducer->parent().get("mlt_service");
3222 QString currentid = clipProducer->parent().get("id");
3223 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3224 clip = clipProducer;
3227 // Special case: prod is null when using placeholder clips.
3228 // in that case, use the producer existing in playlist. Note that
3229 // it will bypass the one producer per track logic and might cause
3230 // Sound cracks if clip is moved so that it overlaps another copy of itself
3231 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3232 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3235 // move all effects to the correct producer
3236 mltPasteEffects(clipProducer, clip);
3239 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3240 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3241 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3244 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3246 if (clip == clipProducer) {
3251 delete clipProducer;
3253 destTrackPlaylist.consolidate_blanks(0);
3254 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3255 kDebug() << "//////// moving clip transparency";
3256 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3258 if (clipIndex > trackPlaylist.count()) checkLength = true;
3259 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3262 mlt_service_unlock(service.get_service());
3263 if (checkLength) mltCheckLength(&tractor);
3265 //m_mltConsumer->set("refresh", 1);
3270 QList <int> Render::checkTrackSequence(int track)
3273 Mlt::Service service(m_mltProducer->parent().get_service());
3274 if (service.type() != tractor_type) {
3275 kWarning() << "// TRACTOR PROBLEM";
3278 Mlt::Tractor tractor(service);
3279 mlt_service_lock(service.get_service());
3280 Mlt::Producer trackProducer(tractor.track(track));
3281 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3282 int clipNb = trackPlaylist.count();
3283 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3284 for (int i = 0; i < clipNb; i++) {
3285 Mlt::Producer *c = trackPlaylist.get_clip(i);
3286 int pos = trackPlaylist.clip_start(i);
3287 if (!list.contains(pos)) list.append(pos);
3288 pos += c->get_playtime();
3289 if (!list.contains(pos)) list.append(pos);
3295 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3297 int new_in = (int)newIn.frames(m_fps);
3298 int new_out = (int)newOut.frames(m_fps) - 1;
3299 if (new_in >= new_out) return false;
3300 int old_in = (int)oldIn.frames(m_fps);
3301 int old_out = (int)oldOut.frames(m_fps) - 1;
3303 Mlt::Service service(m_mltProducer->parent().get_service());
3304 Mlt::Tractor tractor(service);
3305 Mlt::Field *field = tractor.field();
3307 bool doRefresh = true;
3308 // Check if clip is visible in monitor
3309 int diff = old_out - m_mltProducer->position();
3310 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3312 diff = new_out - m_mltProducer->position();
3313 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3315 mlt_service_lock(service.get_service());
3317 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3318 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3319 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3320 QString resource = mlt_properties_get(properties, "mlt_service");
3321 int old_pos = (int)(old_in + old_out) / 2;
3324 while (mlt_type == "transition") {
3325 Mlt::Transition transition((mlt_transition) nextservice);
3326 int currentTrack = transition.get_b_track();
3327 int currentIn = (int) transition.get_in();
3328 int currentOut = (int) transition.get_out();
3330 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3332 if (newTrack - startTrack != 0) {
3333 Mlt::Properties trans_props(transition.get_properties());
3334 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3335 Mlt::Properties new_trans_props(new_transition.get_properties());
3336 new_trans_props.inherit(trans_props);
3337 new_transition.set_in_and_out(new_in, new_out);
3338 field->disconnect_service(transition);
3339 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3340 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3341 } else transition.set_in_and_out(new_in, new_out);
3344 nextservice = mlt_service_producer(nextservice);
3345 if (nextservice == NULL) break;
3346 properties = MLT_SERVICE_PROPERTIES(nextservice);
3347 mlt_type = mlt_properties_get(properties, "mlt_type");
3348 resource = mlt_properties_get(properties, "mlt_service");
3350 mlt_service_unlock(service.get_service());
3351 if (doRefresh) refresh();
3352 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3357 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3359 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3360 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3361 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3362 QString resource = mlt_properties_get(properties, "mlt_service");
3363 QList <Mlt::Transition *> trList;
3365 while (mlt_type == "transition") {
3366 Mlt::Transition transition((mlt_transition) nextservice);
3367 int aTrack = transition.get_a_track();
3368 int bTrack = transition.get_b_track();
3369 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3370 Mlt::Properties trans_props(transition.get_properties());
3371 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3372 Mlt::Properties new_trans_props(cp->get_properties());
3373 new_trans_props.inherit(trans_props);
3375 field->disconnect_service(transition);
3377 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3379 nextservice = mlt_service_producer(nextservice);
3380 if (nextservice == NULL) break;
3381 properties = MLT_SERVICE_PROPERTIES(nextservice);
3382 mlt_type = mlt_properties_get(properties, "mlt_type");
3383 resource = mlt_properties_get(properties, "mlt_service");
3385 field->plant_transition(tr, a_track, b_track);
3387 // re-add upper transitions
3388 for (int i = trList.count() - 1; i >= 0; i--) {
3389 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3390 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3394 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3396 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3398 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3399 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3400 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3403 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3406 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3408 mlt_service serv = m_mltProducer->parent().get_service();
3409 mlt_service_lock(serv);
3411 mlt_service nextservice = mlt_service_get_producer(serv);
3412 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3413 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3414 QString resource = mlt_properties_get(properties, "mlt_service");
3415 int in_pos = (int) in.frames(m_fps);
3416 int out_pos = (int) out.frames(m_fps) - 1;
3418 while (mlt_type == "transition") {
3419 mlt_transition tr = (mlt_transition) nextservice;
3420 int currentTrack = mlt_transition_get_b_track(tr);
3421 int currentBTrack = mlt_transition_get_a_track(tr);
3422 int currentIn = (int) mlt_transition_get_in(tr);
3423 int currentOut = (int) mlt_transition_get_out(tr);
3425 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3426 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3427 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3428 QMap<QString, QString>::Iterator it;
3430 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3432 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3433 if (currentId != xml.attribute("id")) {
3434 // The transition ID is not the same, so reset all properties
3435 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3436 // Cleanup previous properties
3437 QStringList permanentProps;
3438 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3439 permanentProps << "out" << "a_track" << "b_track";
3440 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3441 QString propName = mlt_properties_get_name(transproperties, i);
3442 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3443 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3448 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3449 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3451 if (currentBTrack != a_track) {
3452 mlt_properties_set_int(transproperties, "a_track", a_track);
3454 for (it = map.begin(); it != map.end(); ++it) {
3456 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3457 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3458 //filter->set("kdenlive_id", id);
3462 nextservice = mlt_service_producer(nextservice);
3463 if (nextservice == NULL) break;
3464 properties = MLT_SERVICE_PROPERTIES(nextservice);
3465 mlt_type = mlt_properties_get(properties, "mlt_type");
3466 resource = mlt_properties_get(properties, "mlt_service");
3468 mlt_service_unlock(serv);
3470 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3473 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3475 mlt_service serv = m_mltProducer->parent().get_service();
3476 mlt_service_lock(serv);
3478 Mlt::Service service(serv);
3479 Mlt::Tractor tractor(service);
3480 Mlt::Field *field = tractor.field();
3482 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3484 mlt_service nextservice = mlt_service_get_producer(serv);
3485 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3486 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3487 QString resource = mlt_properties_get(properties, "mlt_service");
3489 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3490 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3492 while (mlt_type == "transition") {
3493 mlt_transition tr = (mlt_transition) nextservice;
3494 int currentTrack = mlt_transition_get_b_track(tr);
3495 int currentIn = (int) mlt_transition_get_in(tr);
3496 int currentOut = (int) mlt_transition_get_out(tr);
3497 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3499 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3500 mlt_field_disconnect_service(field->get_field(), nextservice);
3503 nextservice = mlt_service_producer(nextservice);
3504 if (nextservice == NULL) break;
3505 properties = MLT_SERVICE_PROPERTIES(nextservice);
3506 mlt_type = mlt_properties_get(properties, "mlt_type");
3507 resource = mlt_properties_get(properties, "mlt_service");
3509 mlt_service_unlock(serv);
3511 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3514 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3516 QDomNodeList attribs = xml.elementsByTagName("parameter");
3517 QMap<QString, QString> map;
3518 for (int i = 0; i < attribs.count(); i++) {
3519 QDomElement e = attribs.item(i).toElement();
3520 QString name = e.attribute("name");
3521 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3522 map[name] = e.attribute("default");
3523 if (!e.attribute("value").isEmpty()) {
3524 map[name] = e.attribute("value");
3526 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
3527 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
3528 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3531 if (e.attribute("namedesc").contains(';')) {
3532 QString format = e.attribute("format");
3533 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3534 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3536 QTextStream txtNeu(&neu);
3537 if (values.size() > 0)
3538 txtNeu << (int)values[0].toDouble();
3540 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3541 txtNeu << separators[i];
3542 txtNeu << (int)(values[i+1].toDouble());
3544 if (i < separators.size())
3545 txtNeu << separators[i];
3546 map[e.attribute("name")] = neu;
3553 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3555 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3556 Mlt::Service service(m_mltProducer->parent().get_service());
3557 Mlt::Tractor tractor(service);
3558 Mlt::Field *field = tractor.field();
3560 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3561 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3562 transition->set("transparency", id);
3563 transition->set("fill", 1);
3564 transition->set("internal_added", 237);
3565 field->plant_transition(*transition, transitiontrack, info.track);
3569 void Render::mltDeleteTransparency(int pos, int track, int id)
3571 Mlt::Service service(m_mltProducer->parent().get_service());
3572 Mlt::Tractor tractor(service);
3573 Mlt::Field *field = tractor.field();
3575 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3576 mlt_service serv = m_mltProducer->parent().get_service();
3578 mlt_service nextservice = mlt_service_get_producer(serv);
3579 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3580 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3581 QString resource = mlt_properties_get(properties, "mlt_service");
3583 while (mlt_type == "transition") {
3584 mlt_transition tr = (mlt_transition) nextservice;
3585 int currentTrack = mlt_transition_get_b_track(tr);
3586 int currentIn = (int) mlt_transition_get_in(tr);
3587 int currentOut = (int) mlt_transition_get_out(tr);
3588 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3589 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3591 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3592 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3593 mlt_field_disconnect_service(field->get_field(), nextservice);
3596 nextservice = mlt_service_producer(nextservice);
3597 if (nextservice == NULL) break;
3598 properties = MLT_SERVICE_PROPERTIES(nextservice);
3599 mlt_type = mlt_properties_get(properties, "mlt_type");
3600 resource = mlt_properties_get(properties, "mlt_service");
3602 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3605 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3607 Mlt::Service service(m_mltProducer->parent().get_service());
3608 Mlt::Tractor tractor(service);
3610 mlt_service_lock(service.get_service());
3611 m_mltConsumer->set("refresh", 0);
3613 mlt_service serv = m_mltProducer->parent().get_service();
3614 mlt_service nextservice = mlt_service_get_producer(serv);
3615 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3616 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3617 QString resource = mlt_properties_get(properties, "mlt_service");
3618 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3619 while (mlt_type == "transition") {
3620 mlt_transition tr = (mlt_transition) nextservice;
3621 int currentTrack = mlt_transition_get_b_track(tr);
3622 int currentIn = (int) mlt_transition_get_in(tr);
3623 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3624 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3625 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3626 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3627 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3628 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3631 nextservice = mlt_service_producer(nextservice);
3632 if (nextservice == NULL) break;
3633 properties = MLT_SERVICE_PROPERTIES(nextservice);
3634 mlt_type = mlt_properties_get(properties, "mlt_type");
3635 resource = mlt_properties_get(properties, "mlt_service");
3637 mlt_service_unlock(service.get_service());
3638 m_mltConsumer->set("refresh", 1);
3642 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3644 Mlt::Service service(m_mltProducer->parent().get_service());
3645 Mlt::Tractor tractor(service);
3647 mlt_service_lock(service.get_service());
3648 m_mltConsumer->set("refresh", 0);
3650 mlt_service serv = m_mltProducer->parent().get_service();
3651 mlt_service nextservice = mlt_service_get_producer(serv);
3652 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3653 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3654 QString resource = mlt_properties_get(properties, "mlt_service");
3656 while (mlt_type == "transition") {
3657 mlt_transition tr = (mlt_transition) nextservice;
3658 int currentTrack = mlt_transition_get_b_track(tr);
3659 int currentaTrack = mlt_transition_get_a_track(tr);
3660 int currentIn = (int) mlt_transition_get_in(tr);
3661 int currentOut = (int) mlt_transition_get_out(tr);
3662 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3663 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3664 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3665 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3666 kDebug() << "//////MOVING";
3667 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3668 if (endTrack != startTrack) {
3669 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3670 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3671 mlt_properties_set_int(properties, "b_track", endTrack);
3675 nextservice = mlt_service_producer(nextservice);
3676 if (nextservice == NULL) break;
3677 properties = MLT_SERVICE_PROPERTIES(nextservice);
3678 mlt_type = mlt_properties_get(properties, "mlt_type");
3679 resource = mlt_properties_get(properties, "mlt_service");
3681 mlt_service_unlock(service.get_service());
3682 m_mltConsumer->set("refresh", 1);
3686 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3688 if (in >= out) return false;
3689 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3690 Mlt::Service service(m_mltProducer->parent().get_service());
3692 Mlt::Tractor tractor(service);
3693 Mlt::Field *field = tractor.field();
3695 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3696 if (out != GenTime())
3697 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3699 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3700 QMap<QString, QString>::Iterator it;
3702 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3703 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3704 if (xml.hasAttribute("id"))
3705 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3706 if (xml.hasAttribute("force_track"))
3707 transition->set("force_track", xml.attribute("force_track").toInt());
3709 for (it = args.begin(); it != args.end(); ++it) {
3711 if (!it.value().isEmpty())
3712 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3713 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3715 // attach transition
3716 mlt_service_lock(service.get_service());
3717 mltPlantTransition(field, *transition, a_track, b_track);
3718 // field->plant_transition(*transition, a_track, b_track);
3719 mlt_service_unlock(service.get_service());
3720 if (do_refresh) refresh();
3724 void Render::mltSavePlaylist()
3726 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3727 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3728 fileConsumer.set("resource", "/tmp/playlist.mlt");
3730 Mlt::Service service(m_mltProducer->get_service());
3732 fileConsumer.connect(service);
3733 fileConsumer.start();
3736 const QList <Mlt::Producer *> Render::producersList()
3738 QList <Mlt::Producer *> prods;
3739 if (m_mltProducer == NULL) return prods;
3740 Mlt::Service service(m_mltProducer->parent().get_service());
3741 if (service.type() != tractor_type) return prods;
3742 Mlt::Tractor tractor(service);
3745 int trackNb = tractor.count();
3746 for (int t = 1; t < trackNb; t++) {
3747 Mlt::Producer *tt = tractor.track(t);
3748 Mlt::Producer trackProducer(tt);
3750 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3751 int clipNb = trackPlaylist.count();
3752 for (int i = 0; i < clipNb; i++) {
3753 Mlt::Producer *c = trackPlaylist.get_clip(i);
3754 if (c == NULL) continue;
3755 QString prodId = c->parent().get("id");
3756 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
3757 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3760 prods.append(nprod);
3769 void Render::fillSlowMotionProducers()
3771 if (m_mltProducer == NULL) return;
3772 Mlt::Service service(m_mltProducer->parent().get_service());
3773 if (service.type() != tractor_type) return;
3775 Mlt::Tractor tractor(service);
3777 int trackNb = tractor.count();
3778 for (int t = 1; t < trackNb; t++) {
3779 Mlt::Producer *tt = tractor.track(t);
3780 Mlt::Producer trackProducer(tt);
3782 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3783 int clipNb = trackPlaylist.count();
3784 for (int i = 0; i < clipNb; i++) {
3785 Mlt::Producer *c = trackPlaylist.get_clip(i);
3786 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3788 QString id = nprod->parent().get("id");
3789 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3790 // this is a slowmotion producer, add it to the list
3791 QString url = QString::fromUtf8(nprod->get("resource"));
3792 int strobe = nprod->get_int("strobe");
3793 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3794 if (!m_slowmotionProducers.contains(url)) {
3795 m_slowmotionProducers.insert(url, nprod);
3797 } else delete nprod;
3804 void Render::mltInsertTrack(int ix, bool videoTrack)
3808 Mlt::Service service(m_mltProducer->parent().get_service());
3809 mlt_service_lock(service.get_service());
3810 if (service.type() != tractor_type) {
3811 kWarning() << "// TRACTOR PROBLEM";
3815 Mlt::Tractor tractor(service);
3817 Mlt::Playlist playlist;
3818 int ct = tractor.count();
3820 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3826 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3827 tractor.set_track(playlist, pos);
3828 Mlt::Producer newProd(tractor.track(pos));
3829 if (!videoTrack) newProd.set("hide", 1);
3831 for (; pos <= ct; pos++) {
3832 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3833 tractor.set_track(*prodToMove, pos);
3834 prodToMove = prodToMove2;
3837 tractor.set_track(playlist, ix);
3838 Mlt::Producer newProd(tractor.track(ix));
3839 if (!videoTrack) newProd.set("hide", 1);
3843 mlt_service serv = m_mltProducer->parent().get_service();
3844 mlt_service nextservice = mlt_service_get_producer(serv);
3845 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3846 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3847 QString resource = mlt_properties_get(properties, "mlt_service");
3849 while (mlt_type == "transition") {
3850 if (resource != "mix") {
3851 mlt_transition tr = (mlt_transition) nextservice;
3852 int currentTrack = mlt_transition_get_b_track(tr);
3853 int currentaTrack = mlt_transition_get_a_track(tr);
3854 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3856 if (currentTrack >= ix) {
3857 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3858 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3861 nextservice = mlt_service_producer(nextservice);
3862 if (nextservice == NULL) break;
3863 properties = MLT_SERVICE_PROPERTIES(nextservice);
3864 mlt_type = mlt_properties_get(properties, "mlt_type");
3865 resource = mlt_properties_get(properties, "mlt_service");
3868 // Add audio mix transition to last track
3869 Mlt::Field *field = tractor.field();
3870 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3871 transition->set("a_track", 1);
3872 transition->set("b_track", ct);
3873 transition->set("always_active", 1);
3874 transition->set("internal_added", 237);
3875 transition->set("combine", 1);
3876 field->plant_transition(*transition, 1, ct);
3877 //mlt_service_unlock(m_mltConsumer->get_service());
3878 mlt_service_unlock(service.get_service());
3879 //tractor.multitrack()->refresh();
3880 //tractor.refresh();
3881 blockSignals(false);
3885 void Render::mltDeleteTrack(int ix)
3888 doc.setContent(sceneList(), false);
3889 int tracksCount = doc.elementsByTagName("track").count() - 1;
3890 QDomNode track = doc.elementsByTagName("track").at(ix);
3891 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3892 QDomNodeList transitions = doc.elementsByTagName("transition");
3893 for (int i = 0; i < transitions.count(); i++) {
3894 QDomElement e = transitions.at(i).toElement();
3895 QDomNodeList props = e.elementsByTagName("property");
3896 QMap <QString, QString> mappedProps;
3897 for (int j = 0; j < props.count(); j++) {
3898 QDomElement f = props.at(j).toElement();
3899 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3901 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3902 tractor.removeChild(transitions.at(i));
3904 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3905 // Transition needs to be moved
3906 int a_track = mappedProps.value("a_track").toInt();
3907 int b_track = mappedProps.value("b_track").toInt();
3908 if (a_track > 0 && a_track >= ix) a_track --;
3909 if (b_track == ix) {
3910 // transition was on the deleted track, so remove it
3911 tractor.removeChild(transitions.at(i));
3915 if (b_track > 0 && b_track > ix) b_track --;
3916 for (int j = 0; j < props.count(); j++) {
3917 QDomElement f = props.at(j).toElement();
3918 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3919 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3924 tractor.removeChild(track);
3925 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3926 setSceneList(doc.toString(), m_framePosition);
3927 emit refreshDocumentProducers(false, false);
3931 void Render::updatePreviewSettings()
3933 kDebug() << "////// RESTARTING CONSUMER";
3934 if (!m_mltConsumer || !m_mltProducer) return;
3935 if (m_mltProducer->get_playtime() == 0) return;
3936 Mlt::Service service(m_mltProducer->parent().get_service());
3937 if (service.type() != tractor_type) return;
3939 //m_mltConsumer->set("refresh", 0);
3940 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3941 m_mltConsumer->purge();
3942 QString scene = sceneList();
3944 if (m_mltProducer) {
3945 pos = m_mltProducer->position();
3948 setSceneList(scene, pos);
3952 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3954 // Update all frame positions to the new fps value
3955 //WARNING: there are probably some effects or other that hold a frame value
3956 // as parameter and will also need to be updated here!
3958 doc.setContent(scene);
3960 double factor = new_fps / current_fps;
3961 QDomNodeList producers = doc.elementsByTagName("producer");
3962 for (int i = 0; i < producers.count(); i++) {
3963 QDomElement prod = producers.at(i).toElement();
3964 prod.removeAttribute("in");
3965 prod.removeAttribute("out");
3967 QDomNodeList props = prod.childNodes();
3968 for (int j = 0; j < props.count(); j++) {
3969 QDomElement param = props.at(j).toElement();
3970 QString paramName = param.attribute("name");
3971 if (paramName.startsWith("meta.") || paramName == "length") {
3972 prod.removeChild(props.at(j));
3978 QDomNodeList entries = doc.elementsByTagName("entry");
3979 for (int i = 0; i < entries.count(); i++) {
3980 QDomElement entry = entries.at(i).toElement();
3981 int in = entry.attribute("in").toInt();
3982 int out = entry.attribute("out").toInt();
3983 in = factor * in + 0.5;
3984 out = factor * out + 0.5;
3985 entry.setAttribute("in", in);
3986 entry.setAttribute("out", out);
3989 QDomNodeList blanks = doc.elementsByTagName("blank");
3990 for (int i = 0; i < blanks.count(); i++) {
3991 QDomElement blank = blanks.at(i).toElement();
3992 int length = blank.attribute("length").toInt();
3993 length = factor * length + 0.5;
3994 blank.setAttribute("length", QString::number(length));
3997 QDomNodeList filters = doc.elementsByTagName("filter");
3998 for (int i = 0; i < filters.count(); i++) {
3999 QDomElement filter = filters.at(i).toElement();
4000 int in = filter.attribute("in").toInt();
4001 int out = filter.attribute("out").toInt();
4002 in = factor * in + 0.5;
4003 out = factor * out + 0.5;
4004 filter.setAttribute("in", in);
4005 filter.setAttribute("out", out);
4008 QDomNodeList transitions = doc.elementsByTagName("transition");
4009 for (int i = 0; i < transitions.count(); i++) {
4010 QDomElement transition = transitions.at(i).toElement();
4011 int in = transition.attribute("in").toInt();
4012 int out = transition.attribute("out").toInt();
4013 in = factor * in + 0.5;
4014 out = factor * out + 0.5;
4015 transition.setAttribute("in", in);
4016 transition.setAttribute("out", out);
4017 QDomNodeList props = transition.childNodes();
4018 for (int j = 0; j < props.count(); j++) {
4019 QDomElement param = props.at(j).toElement();
4020 QString paramName = param.attribute("name");
4021 if (paramName == "geometry") {
4022 QString geom = param.firstChild().nodeValue();
4023 QStringList keys = geom.split(';');
4024 QStringList newKeys;
4025 for (int k = 0; k < keys.size(); ++k) {
4026 if (keys.at(k).contains('=')) {
4027 int pos = keys.at(k).section('=', 0, 0).toInt();
4028 pos = factor * pos + 0.5;
4029 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4030 } else newKeys.append(keys.at(k));
4032 param.firstChild().setNodeValue(newKeys.join(";"));
4036 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
4037 int out = tractor.attribute("out").toInt();
4038 out = factor * out + 0.5;
4039 tractor.setAttribute("out", out);
4040 emit durationChanged(out);
4042 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4043 return doc.toString();
4047 void Render::sendFrameUpdate()
4049 if (m_mltProducer) {
4050 Mlt::Frame * frame = m_mltProducer->get_frame();
4051 emitFrameUpdated(*frame);
4056 Mlt::Producer* Render::getProducer()
4058 return m_mltProducer;
4062 #include "renderer.moc"