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";
782 img = KThumb::getFrame(frame, imageWidth, fullWidth, imageHeight);
783 variance = KThumb::imageVariance(img);
784 if (frameNumber == 0 && variance< 6) {
785 // Thumbnail is not interesting (for example all black, seek to fetch better thumb
787 producer->seek(frameNumber);
789 frame = producer->get_frame();
792 } while (variance == -1);
793 QPixmap pix = QPixmap::fromImage(img);
794 emit replyGetImage(clipId, pix);
796 } else if (frame->get_int("test_audio") == 0) {
797 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(fullWidth, imageHeight));
798 emit replyGetImage(clipId, pixmap);
799 filePropertyMap["type"] = "audio";
803 // Retrieve audio / video codec name
807 if (producer->get_int("video_index") > -1) {
808 /*if (context->duration == AV_NOPTS_VALUE) {
809 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
810 emit removeInvalidClip(clipId);
814 // Get the video_index
815 int default_video = producer->get_int("video_index");
817 int default_audio = producer->get_int("audio_index");
820 // Find maximum stream index values
821 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
822 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
823 QString type = producer->get(property);
826 else if (type == "audio")
829 filePropertyMap["default_video"] = QString::number(default_video);
830 filePropertyMap["video_max"] = QString::number(video_max);
831 filePropertyMap["default_audio"] = QString::number(default_audio);
832 filePropertyMap["audio_max"] = QString::number(audio_max);
834 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
835 if (producer->get(property)) {
836 filePropertyMap["videocodec"] = producer->get(property);
838 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
839 if (producer->get(property))
840 filePropertyMap["videocodec"] = producer->get(property);
843 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
844 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
845 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
847 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
848 if (producer->get_int("audio_index") > -1) {
849 // Get the audio_index
850 int index = producer->get_int("audio_index");
852 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
853 if (producer->get(property)) {
854 filePropertyMap["audiocodec"] = producer->get(property);
856 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
857 if (producer->get(property))
858 filePropertyMap["audiocodec"] = producer->get(property);
863 Mlt::Properties metadata;
864 metadata.pass_values(*producer, "meta.attr.");
865 int count = metadata.count();
866 for (int i = 0; i < count; i ++) {
867 QString name = metadata.get_name(i);
868 QString value = QString::fromUtf8(metadata.get(i));
869 if (name.endsWith("markup") && !value.isEmpty())
870 metadataPropertyMap[ name.section('.', 0, -2)] = value;
873 if (replaceProducer) emit blockClipMonitor(clipId);
874 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer, selectClip);
875 // FIXME: should delete this to avoid a leak...
881 /** Create the producer from the MLT XML QDomDocument */
882 void Render::initSceneList()
884 kDebug() << "-------- INIT SCENE LIST ------_";
886 QDomElement mlt = doc.createElement("mlt");
887 doc.appendChild(mlt);
888 QDomElement prod = doc.createElement("producer");
889 prod.setAttribute("resource", "colour");
890 prod.setAttribute("colour", "red");
891 prod.setAttribute("id", "black");
892 prod.setAttribute("in", "0");
893 prod.setAttribute("out", "0");
895 QDomElement tractor = doc.createElement("tractor");
896 QDomElement multitrack = doc.createElement("multitrack");
898 QDomElement playlist1 = doc.createElement("playlist");
899 playlist1.appendChild(prod);
900 multitrack.appendChild(playlist1);
901 QDomElement playlist2 = doc.createElement("playlist");
902 multitrack.appendChild(playlist2);
903 QDomElement playlist3 = doc.createElement("playlist");
904 multitrack.appendChild(playlist3);
905 QDomElement playlist4 = doc.createElement("playlist");
906 multitrack.appendChild(playlist4);
907 QDomElement playlist5 = doc.createElement("playlist");
908 multitrack.appendChild(playlist5);
909 tractor.appendChild(multitrack);
910 mlt.appendChild(tractor);
911 // kDebug()<<doc.toString();
913 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
914 setSceneList(doc, 0);
918 int Render::setProducer(Mlt::Producer *producer, int position)
920 QMutexLocker locker(&m_mutex);
921 if (m_winid == -1) return -1;
923 if (!m_mltConsumer->is_stopped()) {
924 m_mltConsumer->stop();
926 m_mltConsumer->set("refresh", 0);
933 m_mltProducer->set_speed(0);
934 delete m_mltProducer;
935 m_mltProducer = NULL;
939 if (producer && producer->is_valid()) {
940 m_mltProducer = new Mlt::Producer(producer->get_producer());
941 } else m_mltProducer = m_blackClip->cut(0, 50);
943 if (!m_mltProducer || !m_mltProducer->is_valid()) {
944 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
947 int volume = KdenliveSettings::volume();
948 m_mltProducer->set("meta.volume", (double)volume / 100);
949 m_fps = m_mltProducer->get_fps();
951 int error = connectPlaylist();
953 if (position != -1) {
954 m_mltProducer->seek(position);
955 emit rendererPosition(position);
956 } else emit rendererPosition((int) m_mltProducer->position());
960 int Render::setSceneList(QDomDocument list, int position)
962 return setSceneList(list.toString(), position);
965 int Render::setSceneList(QString playlist, int position)
967 if (m_winid == -1) return -1;
970 //kDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
972 // Remove previous profile info
974 doc.setContent(playlist);
975 QDomElement profile = doc.documentElement().firstChildElement("profile");
976 doc.documentElement().removeChild(profile);
977 playlist = doc.toString();
980 if (!m_mltConsumer->is_stopped()) {
981 m_mltConsumer->stop();
983 m_mltConsumer->set("refresh", 0);
985 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
990 m_mltProducer->set_speed(0);
991 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
993 /*Mlt::Service service(m_mltProducer->parent().get_service());
994 mlt_service_lock(service.get_service());
996 if (service.type() == tractor_type) {
997 Mlt::Tractor tractor(service);
998 Mlt::Field *field = tractor.field();
999 mlt_service nextservice = mlt_service_get_producer(service.get_service());
1000 mlt_service nextservicetodisconnect;
1001 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1002 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1003 QString resource = mlt_properties_get(properties, "mlt_service");
1004 // Delete all transitions
1005 while (mlt_type == "transition") {
1006 nextservicetodisconnect = nextservice;
1007 nextservice = mlt_service_producer(nextservice);
1008 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
1009 if (nextservice == NULL) break;
1010 properties = MLT_SERVICE_PROPERTIES(nextservice);
1011 mlt_type = mlt_properties_get(properties, "mlt_type");
1012 resource = mlt_properties_get(properties, "mlt_service");
1016 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
1017 Mlt::Producer trackProducer(tractor.track(trackNb));
1018 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1019 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
1023 mlt_service_unlock(service.get_service());*/
1025 qDeleteAll(m_slowmotionProducers.values());
1026 m_slowmotionProducers.clear();
1028 delete m_mltProducer;
1029 m_mltProducer = NULL;
1035 m_locale = QLocale();
1037 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
1038 if (!m_mltProducer || !m_mltProducer->is_valid()) {
1039 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
1040 m_mltProducer = m_blackClip->cut(0, 50);
1043 int volume = KdenliveSettings::volume();
1044 m_mltProducer->set("meta.volume", (double)volume / 100);
1045 m_mltProducer->optimise();
1047 /*if (KdenliveSettings::osdtimecode()) {
1048 // Attach filter for on screen display of timecode
1050 QString attr = "attr_check";
1051 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
1052 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
1053 mlt_producer_attach( m_mltProducer->get_producer(), filter );
1054 mlt_filter_close( filter );
1056 m_osdInfo = new Mlt::Filter("data_show");
1057 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
1058 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1059 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1060 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1061 m_osdInfo->set("dynamic", "1");
1063 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1065 m_osdInfo->set("dynamic", "0");
1068 m_fps = m_mltProducer->get_fps();
1069 if (position != 0) {
1070 // Seek to correct place after opening project.
1071 m_mltProducer->seek(position);
1074 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1075 if (error == 0) error = connectPlaylist();
1076 else connectPlaylist();
1077 fillSlowMotionProducers();
1078 blockSignals(false);
1081 //kDebug()<<"// SETSCN LST, POS: "<<position;
1082 //if (position != 0) emit rendererPosition(position);
1085 const QString Render::sceneList()
1088 Mlt::Profile profile((mlt_profile) 0);
1089 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1090 m_mltProducer->optimise();
1091 xmlConsumer.set("terminate_on_pause", 1);
1092 Mlt::Producer prod(m_mltProducer->get_producer());
1093 bool split = m_isSplitView;
1094 if (split) slotSplitView(false);
1095 xmlConsumer.connect(prod);
1096 xmlConsumer.start();
1097 while (!xmlConsumer.is_stopped()) {}
1098 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1099 if (split) slotSplitView(true);
1103 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1107 doc.setContent(sceneList(), false);
1108 if (!kdenliveData.isNull()) {
1109 // add Kdenlive specific tags
1110 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1111 mlt.appendChild(doc.importNode(kdenliveData, true));
1113 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1114 kWarning() << "////// ERROR writing to file: " << path;
1117 file.write(doc.toString().toUtf8());
1118 if (file.error() != QFile::NoError) {
1126 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1128 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1129 m_mltProducer->optimise();
1130 xmlConsumer.set("terminate_on_pause", 1);
1131 if (m_name == "clip") {
1132 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1134 list.insert_at(0, prod, 0);
1136 list.set("title", desc.toUtf8().constData());
1137 xmlConsumer.connect(list);
1140 //TODO: not working yet, save zone from timeline
1141 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1142 /* Mlt::Service service(p1->parent().get_service());
1143 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1145 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1146 //prod->set("title", desc.toUtf8().constData());
1147 xmlConsumer.connect(*p1); //list);
1150 xmlConsumer.start();
1153 double Render::fps() const
1158 int Render::connectPlaylist()
1160 if (!m_mltConsumer) return -1;
1161 //m_mltConsumer->set("refresh", "0");
1162 m_mltConsumer->connect(*m_mltProducer);
1163 m_mltProducer->set_speed(0);
1164 if (m_mltConsumer->start() == -1) {
1165 // ARGH CONSUMER BROKEN!!!!
1166 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."));
1167 delete m_mltConsumer;
1168 m_mltConsumer = NULL;
1171 emit durationChanged(m_mltProducer->get_playtime());
1176 void Render::refreshDisplay()
1179 if (!m_mltProducer) return;
1180 //m_mltConsumer->set("refresh", 0);
1182 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1183 /*if (KdenliveSettings::osdtimecode()) {
1184 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1185 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1186 m_osdInfo->set("dynamic", "1");
1187 m_mltProducer->attach(*m_osdInfo);
1190 m_mltProducer->detach(*m_osdInfo);
1191 m_osdInfo->set("dynamic", "0");
1196 int Render::volume() const
1198 if (!m_mltConsumer || !m_mltProducer) return -1;
1199 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1202 void Render::slotSetVolume(int volume)
1204 if (!m_mltConsumer || !m_mltProducer) return;
1205 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1208 m_mltConsumer->set("refresh", 0);
1209 // Attach filter for on screen display of timecode
1210 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1211 mlt_properties_set_double( properties, "meta.volume", volume );
1212 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1213 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1215 if (!KdenliveSettings::osdtimecode()) {
1216 m_mltProducer->detach(*m_osdInfo);
1217 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1218 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1221 //m_osdTimer->setSingleShot(2500);
1224 void Render::slotOsdTimeout()
1226 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1227 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1228 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1229 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1233 void Render::start()
1235 if (m_winid == -1) {
1236 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1239 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1240 if (m_mltConsumer->start() == -1) {
1241 //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."));
1242 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1251 if (m_mltProducer == NULL) return;
1252 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1253 //kDebug() << "///////////// RENDER STOPPED: " << m_name;
1254 //m_mltConsumer->set("refresh", 0);
1255 m_mltConsumer->stop();
1256 // delete m_mltConsumer;
1257 // m_mltConsumer = NULL;
1260 if (m_mltProducer) {
1261 if (m_isZoneMode) resetZoneMode();
1262 m_mltProducer->set_speed(0.0);
1263 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1264 //kDebug() << m_mltProducer->get_length();
1268 void Render::stop(const GenTime & startTime)
1270 if (m_mltProducer) {
1271 if (m_isZoneMode) resetZoneMode();
1272 m_mltProducer->set_speed(0.0);
1273 m_mltProducer->seek((int) startTime.frames(m_fps));
1275 m_mltConsumer->purge();
1278 void Render::pause()
1280 if (!m_mltProducer || !m_mltConsumer)
1282 if (m_mltProducer->get_speed() == 0.0) return;
1283 if (m_isZoneMode) resetZoneMode();
1284 m_mltConsumer->set("refresh", 0);
1285 m_mltProducer->set_speed(0.0);
1287 The 2 lines below create a flicker loop
1288 emit rendererPosition(m_framePosition);
1289 m_mltProducer->seek(m_framePosition);*/
1290 m_mltConsumer->purge();
1293 void Render::switchPlay(bool play)
1295 if (!m_mltProducer || !m_mltConsumer)
1297 if (m_isZoneMode) resetZoneMode();
1298 if (play && m_mltProducer->get_speed() == 0.0) {
1299 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1300 m_mltProducer->set_speed(1.0);
1301 m_mltConsumer->set("refresh", 1);
1302 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1305 m_mltConsumer->set("refresh", "0");
1307 m_mltProducer->seek(m_framePosition);
1308 /*m_mltConsumer->set("refresh", 0);
1309 m_mltConsumer->stop();
1310 m_mltConsumer->purge();
1311 m_mltProducer->set_speed(0.0);
1312 //m_framePosition = m_mltProducer->position();
1313 m_mltProducer->seek(m_framePosition);
1314 emit rendererPosition(m_framePosition);*/
1318 void Render::play(double speed)
1322 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1323 m_mltProducer->set_speed(speed);
1324 /*if (speed == 0.0) {
1325 m_mltProducer->seek((int) m_framePosition + 1);
1326 m_mltConsumer->purge();
1331 void Render::play(const GenTime & startTime)
1333 if (!m_mltProducer || !m_mltConsumer)
1335 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1336 m_mltProducer->set_speed(1.0);
1337 m_mltConsumer->set("refresh", 1);
1340 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1342 if (!m_mltProducer || !m_mltConsumer)
1344 //m_mltProducer->set("eof", "loop");
1345 m_isLoopMode = true;
1346 m_loopStart = startTime;
1347 playZone(startTime, stopTime);
1350 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1352 if (!m_mltProducer || !m_mltConsumer)
1354 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1355 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1356 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1357 m_mltProducer->set_speed(1.0);
1358 m_mltConsumer->set("refresh", 1);
1359 m_isZoneMode = true;
1362 void Render::resetZoneMode()
1364 if (!m_isZoneMode && !m_isLoopMode) return;
1365 m_mltProducer->set("out", m_originalOut);
1366 //m_mltProducer->set("eof", "pause");
1367 m_isZoneMode = false;
1368 m_isLoopMode = false;
1371 void Render::seekToFrame(int pos)
1376 m_mltProducer->seek(pos);
1380 void Render::seekToFrameDiff(int diff)
1385 m_mltProducer->seek(m_mltProducer->position() + diff);
1389 void Render::doRefresh()
1391 // Use a Timer so that we don't refresh too much
1392 if (m_mltConsumer) {
1393 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1394 m_mltConsumer->set("refresh", 1);
1398 void Render::refresh()
1402 if (m_mltConsumer) {
1403 m_mltConsumer->set("refresh", 1);
1404 if (m_mltConsumer->is_stopped()) m_mltConsumer->start();
1408 void Render::setDropFrames(bool show)
1410 if (m_mltConsumer) {
1411 int dropFrames = KdenliveSettings::mltthreads();
1412 if (show == false) dropFrames = -dropFrames;
1413 m_mltConsumer->stop();
1415 m_mltConsumer->set("real_time", dropFrames);
1417 m_mltConsumer->set("play.real_time", dropFrames);
1419 if (m_mltConsumer->start() == -1) {
1420 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1426 double Render::playSpeed()
1428 if (m_mltProducer) return m_mltProducer->get_speed();
1432 GenTime Render::seekPosition() const
1434 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1435 else return GenTime();
1438 int Render::seekFramePosition() const
1440 if (m_mltProducer) return (int) m_mltProducer->position();
1444 const QString & Render::rendererName() const
1449 void Render::emitFrameUpdated(Mlt::Frame& frame)
1451 mlt_image_format format = mlt_image_rgb24;
1454 const uchar* image = frame.get_image(format, width, height);
1455 QImage qimage(width, height, QImage::Format_RGB888);
1456 memcpy(qimage.bits(), image, width * height * 3);
1457 emit frameUpdated(qimage);
1460 void Render::emitFrameNumber(double position)
1462 m_framePosition = position;
1463 emit rendererPosition((int) position);
1466 void Render::emitConsumerStopped()
1468 // This is used to know when the playing stopped
1469 if (m_mltProducer) {
1470 double pos = m_mltProducer->position();
1471 if (m_isLoopMode) play(m_loopStart);
1472 else if (m_isZoneMode) resetZoneMode();
1473 emit rendererStopped((int) pos);
1477 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1479 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1482 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1484 if (!m_mltProducer) {
1485 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1489 //int height = 1080;//KdenliveSettings::defaultheight();
1490 //int width = 1940; //KdenliveSettings::displaywidth();
1492 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1494 QPixmap pix(width, height);
1495 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1496 m_convert.set("forced", mlt_image_rgb24a);
1497 m_mltProducer->attach(m_convert);
1498 Mlt::Frame * frame = m_mltProducer->get_frame();
1499 m_mltProducer->detach(m_convert);
1501 pix = frameThumbnail(frame, width, height);
1504 pix.save(url.path(), "PNG");
1505 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1509 void Render::showFrame(Mlt::Frame& frame)
1511 m_framePosition = qMax(frame.get_int("_position"), 0);
1512 emit rendererPosition((int) m_framePosition);
1513 mlt_image_format format = mlt_image_rgb24a;
1516 const uchar* image = frame.get_image(format, width, height);
1517 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1518 memcpy(qimage.scanLine(0), image, width * height * 4);
1519 emit showImageSignal(qimage);
1520 if (analyseAudio) showAudio(frame);
1521 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1522 emit frameUpdated(qimage.rgbSwapped());
1526 void Render::showAudio(Mlt::Frame& frame)
1528 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1531 mlt_audio_format audio_format = mlt_audio_s16;
1533 int num_channels = 0;
1535 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1541 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1542 // So the vector is of size samples*channels.
1543 QVector<int16_t> sampleVector(samples*num_channels);
1544 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1547 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1552 * MLT playlist direct manipulation.
1555 void Render::mltCheckLength(Mlt::Tractor *tractor)
1557 //kDebug()<<"checking track length: "<<track<<"..........";
1559 int trackNb = tractor->count();
1563 Mlt::Producer trackProducer(tractor->track(0));
1564 duration = trackProducer.get_playtime() - 1;
1565 m_mltProducer->set("out", duration);
1566 emit durationChanged(duration);
1569 while (trackNb > 1) {
1570 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1571 trackDuration = trackProducer.get_playtime() - 1;
1572 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1573 if (trackDuration > duration) duration = trackDuration;
1577 Mlt::Producer blackTrackProducer(tractor->track(0));
1579 if (blackTrackProducer.get_playtime() - 1 != duration) {
1580 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1581 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1582 if (blackclip && blackclip->is_blank()) {
1587 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1588 blackTrackPlaylist.clear();
1589 m_blackClip->set("length", duration + 1);
1590 m_blackClip->set("out", duration);
1591 blackclip = m_blackClip->cut(0, duration);
1592 blackTrackPlaylist.insert_at(0, blackclip, 1);
1594 if (duration > blackclip->parent().get_length()) {
1595 blackclip->parent().set("length", duration + 1);
1596 blackclip->parent().set("out", duration);
1597 blackclip->set("length", duration + 1);
1599 blackTrackPlaylist.resize_clip(0, 0, duration);
1603 m_mltProducer->set("out", duration);
1604 emit durationChanged(duration);
1608 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1610 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1612 // We want a slowmotion producer
1613 double speed = element.attribute("speed", "1.0").toDouble();
1614 int strobe = element.attribute("strobe", "1").toInt();
1615 QString url = QString::fromUtf8(prod->get("resource"));
1616 url.append('?' + locale.toString(speed));
1617 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1618 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1619 if (!slowprod || slowprod->get_producer() == NULL) {
1620 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
1621 if (strobe > 1) slowprod->set("strobe", strobe);
1622 QString id = prod->parent().get("id");
1623 if (id.contains('_')) id = id.section('_', 0, 0);
1624 QString producerid = "slowmotion:" + id + ':' + locale.toString(speed);
1625 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1626 slowprod->set("id", producerid.toUtf8().constData());
1627 m_slowmotionProducers.insert(url, slowprod);
1632 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1634 if (m_mltProducer == NULL) {
1635 kDebug() << "PLAYLIST NOT INITIALISED //////";
1639 kDebug() << "Cannot insert clip without producer //////";
1642 Mlt::Producer parentProd(m_mltProducer->parent());
1643 if (parentProd.get_producer() == NULL) {
1644 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1648 Mlt::Service service(parentProd.get_service());
1649 if (service.type() != tractor_type) {
1650 kWarning() << "// TRACTOR PROBLEM";
1653 Mlt::Tractor tractor(service);
1654 if (info.track > tractor.count() - 1) {
1655 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1658 mlt_service_lock(service.get_service());
1659 Mlt::Producer trackProducer(tractor.track(info.track));
1660 int trackDuration = trackProducer.get_playtime() - 1;
1661 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1662 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1663 prod = checkSlowMotionProducer(prod, element);
1664 if (prod == NULL || !prod->is_valid()) {
1665 mlt_service_unlock(service.get_service());
1669 int cutPos = (int) info.cropStart.frames(m_fps);
1670 if (cutPos < 0) cutPos = 0;
1671 int insertPos = (int) info.startPos.frames(m_fps);
1672 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1673 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1674 if (overwrite && (insertPos < trackDuration)) {
1675 // Replace zone with blanks
1676 //trackPlaylist.split_at(insertPos, true);
1677 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1678 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1679 trackPlaylist.insert_blank(clipIndex, cutDuration);
1681 trackPlaylist.split_at(insertPos, true);
1682 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1683 trackPlaylist.insert_blank(clipIndex, cutDuration);
1685 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1687 /*if (QString(prod->get("transparency")).toInt() == 1)
1688 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1690 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1691 mlt_service_unlock(service.get_service());
1692 /*tractor.multitrack()->refresh();
1693 tractor.refresh();*/
1698 void Render::mltCutClip(int track, GenTime position)
1700 Mlt::Service service(m_mltProducer->parent().get_service());
1701 if (service.type() != tractor_type) {
1702 kWarning() << "// TRACTOR PROBLEM";
1706 Mlt::Tractor tractor(service);
1707 Mlt::Producer trackProducer(tractor.track(track));
1708 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1711 /* // Display playlist info
1712 kDebug()<<"//////////// BEFORE";
1713 for (int i = 0; i < trackPlaylist.count(); i++) {
1714 int blankStart = trackPlaylist.clip_start(i);
1715 int blankDuration = trackPlaylist.clip_length(i) - 1;
1717 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1718 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1721 int cutPos = (int) position.frames(m_fps);
1723 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1724 if (trackPlaylist.is_blank(clipIndex)) {
1725 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1728 mlt_service_lock(service.get_service());
1729 int clipStart = trackPlaylist.clip_start(clipIndex);
1730 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1731 mlt_service_unlock(service.get_service());
1733 // duplicate effects
1734 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1735 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1737 if (original == NULL || clip == NULL) {
1738 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1740 Mlt::Service clipService(original->get_service());
1741 Mlt::Service dupService(clip->get_service());
1745 Mlt::Filter *filter = clipService.filter(ct);
1747 // Only duplicate Kdenlive filters, and skip the fade in effects
1748 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1749 // looks like there is no easy way to duplicate a filter,
1750 // so we will create a new one and duplicate its properties
1751 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1752 if (dup && dup->is_valid()) {
1753 Mlt::Properties entries(filter->get_properties());
1754 for (int i = 0; i < entries.count(); i++) {
1755 dup->set(entries.get_name(i), entries.get(i));
1757 dupService.attach(*dup);
1761 filter = clipService.filter(ct);
1764 /* // Display playlist info
1765 kDebug()<<"//////////// AFTER";
1766 for (int i = 0; i < trackPlaylist.count(); i++) {
1767 int blankStart = trackPlaylist.clip_start(i);
1768 int blankDuration = trackPlaylist.clip_length(i) - 1;
1770 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1771 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1776 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1780 kDebug() << "Cannot update clip with null producer //////";
1783 Mlt::Service service(m_mltProducer->parent().get_service());
1784 if (service.type() != tractor_type) {
1785 kWarning() << "// TRACTOR PROBLEM";
1788 Mlt::Tractor tractor(service);
1789 Mlt::Producer trackProducer(tractor.track(tractor.count() - 1 - info.track));
1790 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1791 int startPos = info.startPos.frames(m_fps);
1792 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1793 if (trackPlaylist.is_blank(clipIndex)) {
1794 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1797 mlt_service_lock(service.get_service());
1798 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1800 QList <Mlt::Filter *> filtersList;
1801 Mlt::Service sourceService(clip->get_service());
1803 Mlt::Filter *filter = sourceService.filter(ct);
1805 if (filter->get_int("kdenlive_ix") != 0) {
1806 filtersList.append(filter);
1809 filter = sourceService.filter(ct);
1812 trackPlaylist.replace_with_blank(clipIndex);
1814 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1815 prod = checkSlowMotionProducer(prod, element);
1816 if (prod == NULL || !prod->is_valid()) {
1817 mlt_service_unlock(service.get_service());
1821 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps) - 1);
1822 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1826 //if (mltInsertClip(info, element, prod) == -1) return false;
1827 if (!filtersList.isEmpty()) {
1828 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1829 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1830 Mlt::Service destService(destclip->get_service());
1832 for (int i = 0; i < filtersList.count(); i++)
1833 destService.attach(*(filtersList.at(i)));
1835 mlt_service_unlock(service.get_service());
1840 bool Render::mltRemoveClip(int track, GenTime position)
1842 Mlt::Service service(m_mltProducer->parent().get_service());
1843 if (service.type() != tractor_type) {
1844 kWarning() << "// TRACTOR PROBLEM";
1848 Mlt::Tractor tractor(service);
1849 Mlt::Producer trackProducer(tractor.track(track));
1850 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1851 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1853 if (trackPlaylist.is_blank(clipIndex)) {
1854 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(m_fps);
1855 //mlt_service_unlock(service.get_service());
1858 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1859 if (clip) delete clip;
1860 trackPlaylist.consolidate_blanks(0);
1862 /* // Display playlist info
1863 kDebug()<<"//// AFTER";
1864 for (int i = 0; i < trackPlaylist.count(); i++) {
1865 int blankStart = trackPlaylist.clip_start(i);
1866 int blankDuration = trackPlaylist.clip_length(i) - 1;
1868 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1869 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1872 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1876 int Render::mltGetSpaceLength(const GenTime &pos, int track, bool fromBlankStart)
1878 if (!m_mltProducer) {
1879 kDebug() << "PLAYLIST NOT INITIALISED //////";
1882 Mlt::Producer parentProd(m_mltProducer->parent());
1883 if (parentProd.get_producer() == NULL) {
1884 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1888 Mlt::Service service(parentProd.get_service());
1889 Mlt::Tractor tractor(service);
1890 int insertPos = pos.frames(m_fps);
1892 Mlt::Producer trackProducer(tractor.track(track));
1893 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1894 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1895 if (clipIndex == trackPlaylist.count()) {
1896 // We are after the end of the playlist
1899 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1900 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1901 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1904 int Render::mltTrackDuration(int track)
1906 if (!m_mltProducer) {
1907 kDebug() << "PLAYLIST NOT INITIALISED //////";
1910 Mlt::Producer parentProd(m_mltProducer->parent());
1911 if (parentProd.get_producer() == NULL) {
1912 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1916 Mlt::Service service(parentProd.get_service());
1917 Mlt::Tractor tractor(service);
1919 Mlt::Producer trackProducer(tractor.track(track));
1920 return trackProducer.get_playtime() - 1;
1923 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime &duration, const GenTime &timeOffset)
1925 if (!m_mltProducer) {
1926 kDebug() << "PLAYLIST NOT INITIALISED //////";
1929 Mlt::Producer parentProd(m_mltProducer->parent());
1930 if (parentProd.get_producer() == NULL) {
1931 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1934 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1935 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1937 Mlt::Service service(parentProd.get_service());
1938 Mlt::Tractor tractor(service);
1939 mlt_service_lock(service.get_service());
1940 int diff = duration.frames(m_fps);
1941 int offset = timeOffset.frames(m_fps);
1945 // insert space in one track only
1946 Mlt::Producer trackProducer(tractor.track(track));
1947 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1948 insertPos = trackClipStartList.value(track);
1949 if (insertPos != -1) {
1950 insertPos += offset;
1951 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1953 trackPlaylist.insert_blank(clipIndex, diff - 1);
1955 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1956 if (!trackPlaylist.is_blank(clipIndex)) {
1957 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1959 int position = trackPlaylist.clip_start(clipIndex);
1960 int blankDuration = trackPlaylist.clip_length(clipIndex);
1961 if (blankDuration + diff == 0) {
1962 trackPlaylist.remove(clipIndex);
1963 } else trackPlaylist.remove_region(position, -diff);
1965 trackPlaylist.consolidate_blanks(0);
1967 // now move transitions
1968 mlt_service serv = m_mltProducer->parent().get_service();
1969 mlt_service nextservice = mlt_service_get_producer(serv);
1970 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1971 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1972 QString resource = mlt_properties_get(properties, "mlt_service");
1974 while (mlt_type == "transition") {
1975 mlt_transition tr = (mlt_transition) nextservice;
1976 int currentTrack = mlt_transition_get_b_track(tr);
1977 int currentIn = (int) mlt_transition_get_in(tr);
1978 int currentOut = (int) mlt_transition_get_out(tr);
1979 insertPos = trackTransitionStartList.value(track);
1980 if (insertPos != -1) {
1981 insertPos += offset;
1982 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1983 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1986 nextservice = mlt_service_producer(nextservice);
1987 if (nextservice == NULL) break;
1988 properties = MLT_SERVICE_PROPERTIES(nextservice);
1989 mlt_type = mlt_properties_get(properties, "mlt_type");
1990 resource = mlt_properties_get(properties, "mlt_service");
1993 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1994 Mlt::Producer trackProducer(tractor.track(trackNb));
1995 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1997 //int clipNb = trackPlaylist.count();
1998 insertPos = trackClipStartList.value(trackNb);
1999 if (insertPos != -1) {
2000 insertPos += offset;
2002 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
2003 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
2004 for (int i = 0; i < clipNb; i++) {
2005 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
2006 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
2007 kDebug()<<"-------------";
2009 kDebug()<<"END-------------";*/
2012 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
2014 trackPlaylist.insert_blank(clipIndex, diff - 1);
2016 if (!trackPlaylist.is_blank(clipIndex)) {
2019 if (!trackPlaylist.is_blank(clipIndex)) {
2020 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
2022 int position = trackPlaylist.clip_start(clipIndex);
2023 int blankDuration = trackPlaylist.clip_length(clipIndex);
2024 if (diff + blankDuration == 0) {
2025 trackPlaylist.remove(clipIndex);
2026 } else trackPlaylist.remove_region(position, - diff);
2028 trackPlaylist.consolidate_blanks(0);
2031 // now move transitions
2032 mlt_service serv = m_mltProducer->parent().get_service();
2033 mlt_service nextservice = mlt_service_get_producer(serv);
2034 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2035 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2036 QString resource = mlt_properties_get(properties, "mlt_service");
2038 while (mlt_type == "transition") {
2039 mlt_transition tr = (mlt_transition) nextservice;
2040 int currentIn = (int) mlt_transition_get_in(tr);
2041 int currentOut = (int) mlt_transition_get_out(tr);
2042 int currentTrack = mlt_transition_get_b_track(tr);
2043 insertPos = trackTransitionStartList.value(currentTrack);
2044 if (insertPos != -1) {
2045 insertPos += offset;
2046 if (currentOut > insertPos && resource != "mix") {
2047 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2050 nextservice = mlt_service_producer(nextservice);
2051 if (nextservice == NULL) break;
2052 properties = MLT_SERVICE_PROPERTIES(nextservice);
2053 mlt_type = mlt_properties_get(properties, "mlt_type");
2054 resource = mlt_properties_get(properties, "mlt_service");
2057 mlt_service_unlock(service.get_service());
2058 mltCheckLength(&tractor);
2059 m_mltConsumer->set("refresh", 1);
2063 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2065 if (source == dest) return;
2066 Mlt::Service sourceService(source->get_service());
2067 Mlt::Service destService(dest->get_service());
2069 // move all effects to the correct producer
2071 Mlt::Filter *filter = sourceService.filter(ct);
2073 if (filter->get_int("kdenlive_ix") != 0) {
2074 sourceService.detach(*filter);
2075 destService.attach(*filter);
2077 filter = sourceService.filter(ct);
2081 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2084 Mlt::Service service(m_mltProducer->parent().get_service());
2085 if (service.type() != tractor_type) {
2086 kWarning() << "// TRACTOR PROBLEM";
2090 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2091 Mlt::Tractor tractor(service);
2092 Mlt::Producer trackProducer(tractor.track(info.track));
2093 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2094 int startPos = info.startPos.frames(m_fps);
2095 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2096 int clipLength = trackPlaylist.clip_length(clipIndex);
2098 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2099 if (original == NULL) {
2102 if (!original->is_valid() || original->is_blank()) {
2107 Mlt::Producer clipparent = original->parent();
2108 if (!clipparent.is_valid() || clipparent.is_blank()) {
2114 QString serv = clipparent.get("mlt_service");
2115 QString id = clipparent.get("id");
2116 if (speed <= 0 && speed > -1) speed = 1.0;
2117 //kDebug() << "CLIP SERVICE: " << serv;
2118 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2119 mlt_service_lock(service.get_service());
2120 QString url = QString::fromUtf8(clipparent.get("resource"));
2121 url.append('?' + m_locale.toString(speed));
2122 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2123 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2124 if (!slowprod || slowprod->get_producer() == NULL) {
2125 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2126 if (strobe > 1) slowprod->set("strobe", strobe);
2127 QString producerid = "slowmotion:" + id + ':' + m_locale.toString(speed);
2128 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2129 slowprod->set("id", producerid.toUtf8().constData());
2130 // copy producer props
2131 double ar = original->parent().get_double("force_aspect_ratio");
2132 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2133 double fps = original->parent().get_double("force_fps");
2134 if (fps != 0.0) slowprod->set("force_fps", fps);
2135 int threads = original->parent().get_int("threads");
2136 if (threads != 0) slowprod->set("threads", threads);
2137 if (original->parent().get("force_progressive"))
2138 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2139 if (original->parent().get("force_tff"))
2140 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2141 int ix = original->parent().get_int("video_index");
2142 if (ix != 0) slowprod->set("video_index", ix);
2143 int colorspace = original->parent().get_int("force_colorspace");
2144 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2145 int full_luma = original->parent().get_int("set.force_full_luma");
2146 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2147 m_slowmotionProducers.insert(url, slowprod);
2149 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2150 trackPlaylist.consolidate_blanks(0);
2152 // Check that the blank space is long enough for our new duration
2153 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2154 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2156 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2157 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2158 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2159 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2161 // move all effects to the correct producer
2162 mltPasteEffects(clip, cut);
2163 trackPlaylist.insert_at(startPos, cut, 1);
2166 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2167 newLength = trackPlaylist.clip_length(clipIndex);
2168 mlt_service_unlock(service.get_service());
2169 } else if (speed == 1.0 && strobe < 2) {
2170 mlt_service_lock(service.get_service());
2172 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2173 trackPlaylist.consolidate_blanks(0);
2175 // Check that the blank space is long enough for our new duration
2176 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2177 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2180 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2181 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2182 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2183 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2184 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2186 // move all effects to the correct producer
2187 mltPasteEffects(clip, cut);
2189 trackPlaylist.insert_at(startPos, cut, 1);
2192 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2193 newLength = trackPlaylist.clip_length(clipIndex);
2194 mlt_service_unlock(service.get_service());
2196 } else if (serv == "framebuffer") {
2197 mlt_service_lock(service.get_service());
2198 QString url = QString::fromUtf8(clipparent.get("resource"));
2199 url = url.section('?', 0, 0);
2200 url.append('?' + m_locale.toString(speed));
2201 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2202 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2203 if (!slowprod || slowprod->get_producer() == NULL) {
2204 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2205 slowprod->set("strobe", strobe);
2206 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + m_locale.toString(speed);
2207 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2208 slowprod->set("id", producerid.toUtf8().constData());
2209 // copy producer props
2210 double ar = original->parent().get_double("force_aspect_ratio");
2211 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2212 double fps = original->parent().get_double("force_fps");
2213 if (fps != 0.0) slowprod->set("force_fps", fps);
2214 if (original->parent().get("force_progressive"))
2215 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2216 if (original->parent().get("force_tff"))
2217 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2218 int threads = original->parent().get_int("threads");
2219 if (threads != 0) slowprod->set("threads", threads);
2220 int ix = original->parent().get_int("video_index");
2221 if (ix != 0) slowprod->set("video_index", ix);
2222 int colorspace = original->parent().get_int("force_colorspace");
2223 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2224 int full_luma = original->parent().get_int("set.force_full_luma");
2225 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2226 m_slowmotionProducers.insert(url, slowprod);
2228 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2229 trackPlaylist.consolidate_blanks(0);
2231 GenTime duration = speedIndependantInfo.cropDuration / speed;
2232 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2234 // Check that the blank space is long enough for our new duration
2235 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2236 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2239 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2240 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2241 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2242 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2244 // move all effects to the correct producer
2245 mltPasteEffects(clip, cut);
2247 trackPlaylist.insert_at(startPos, cut, 1);
2250 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2251 newLength = trackPlaylist.clip_length(clipIndex);
2253 mlt_service_unlock(service.get_service());
2256 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2260 bool Render::mltRemoveTrackEffect(int track, int index, bool updateIndex)
2262 Mlt::Service service(m_mltProducer->parent().get_service());
2263 bool success = false;
2264 Mlt::Tractor tractor(service);
2265 Mlt::Producer trackProducer(tractor.track(track));
2266 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2267 Mlt::Service clipService(trackPlaylist.get_service());
2269 mlt_service_lock(service.get_service());
2271 Mlt::Filter *filter = clipService.filter(ct);
2273 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {
2274 if (clipService.detach(*filter) == 0) success = true;
2275 } else if (updateIndex) {
2276 // Adjust the other effects index
2277 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2280 filter = clipService.filter(ct);
2282 mlt_service_unlock(service.get_service());
2287 bool Render::mltRemoveEffect(int track, GenTime position, int index, bool updateIndex, bool doRefresh)
2289 if (position < GenTime()) {
2290 // Remove track effect
2291 return mltRemoveTrackEffect(track, index, updateIndex);
2293 Mlt::Service service(m_mltProducer->parent().get_service());
2294 bool success = false;
2295 Mlt::Tractor tractor(service);
2296 Mlt::Producer trackProducer(tractor.track(track));
2297 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2299 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2300 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2302 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2306 Mlt::Service clipService(clip->get_service());
2307 int duration = clip->get_playtime();
2309 // Check if clip is visible in monitor
2310 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2311 if (diff < 0 || diff > duration) doRefresh = false;
2315 mlt_service_lock(service.get_service());
2317 Mlt::Filter *filter = clipService.filter(ct);
2319 if ((index == -1 && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2320 if (clipService.detach(*filter) == 0) success = true;
2321 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2322 } else if (updateIndex) {
2323 // Adjust the other effects index
2324 if (filter->get_int("kdenlive_ix") > index) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2327 filter = clipService.filter(ct);
2329 mlt_service_unlock(service.get_service());
2330 if (doRefresh) refresh();
2334 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2336 Mlt::Service service(m_mltProducer->parent().get_service());
2337 Mlt::Tractor tractor(service);
2338 Mlt::Producer trackProducer(tractor.track(track));
2339 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2340 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2341 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2345 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2348 Mlt::Service service(m_mltProducer->parent().get_service());
2350 Mlt::Tractor tractor(service);
2351 Mlt::Producer trackProducer(tractor.track(track));
2352 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2354 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2355 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2360 Mlt::Service clipService(clip->get_service());
2361 int duration = clip->get_playtime();
2363 // Check if clip is visible in monitor
2364 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2365 if (diff < 0 || diff > duration) doRefresh = false;
2368 return mltAddEffect(clipService, params, duration, doRefresh);
2371 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2373 bool updateIndex = false;
2374 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2375 const QString region = params.paramValue("region");
2377 mlt_service_lock(service.get_service());
2379 Mlt::Filter *filter = service.filter(ct);
2381 if (filter->get_int("kdenlive_ix") == filter_ix) {
2382 // A filter at that position already existed, so we will increase all indexes later
2387 filter = service.filter(ct);
2390 if (params.paramValue("id") == "speed") {
2391 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2393 filter = service.filter(ct);
2395 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2396 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2399 filter = service.filter(ct);
2401 mlt_service_unlock(service.get_service());
2402 if (doRefresh) refresh();
2407 // temporarily remove all effects after insert point
2408 QList <Mlt::Filter *> filtersList;
2410 filter = service.filter(ct);
2412 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2413 filtersList.append(filter);
2414 service.detach(*filter);
2416 filter = service.filter(ct);
2420 QString tag = params.paramValue("tag");
2421 //kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2422 char *filterTag = qstrdup(tag.toUtf8().constData());
2423 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2424 QHash<QString, QString>::Iterator it;
2425 QString kfr = params.paramValue("keyframes");
2427 if (!kfr.isEmpty()) {
2428 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2429 //kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2430 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2431 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2432 //kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2433 //double max = params.paramValue("max").toDouble();
2434 double min = params.paramValue("min").toDouble();
2435 double factor = params.paramValue("factor", "1").toDouble();
2436 double paramOffset = params.paramValue("offset", "0").toDouble();
2437 params.removeParam("starttag");
2438 params.removeParam("endtag");
2439 params.removeParam("keyframes");
2440 params.removeParam("min");
2441 params.removeParam("max");
2442 params.removeParam("factor");
2443 params.removeParam("offset");
2445 // Special case, only one keyframe, means we want a constant value
2446 if (keyFrames.count() == 1) {
2447 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2448 if (filter && filter->is_valid()) {
2449 filter->set("kdenlive_id", filterId);
2450 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2451 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2452 for (int j = 0; j < params.count(); j++) {
2453 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2455 filter->set("in", x1);
2456 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2457 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2458 service.attach(*filter);
2460 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2461 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2462 if (filter && filter->is_valid()) {
2463 filter->set("kdenlive_id", filterId);
2464 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2465 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2466 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2467 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2468 if (x2 == -1) x2 = duration;
2470 for (int j = 0; j < params.count(); j++) {
2471 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2474 filter->set("in", x1);
2475 filter->set("out", x2);
2476 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2477 filter->set(starttag, m_locale.toString(((min + y1) - paramOffset) / factor).toUtf8().data());
2478 filter->set(endtag, m_locale.toString(((min + y2) - paramOffset) / factor).toUtf8().data());
2479 service.attach(*filter);
2486 Mlt::Filter *filter;
2488 if (!region.isEmpty()) {
2489 filter = new Mlt::Filter(*m_mltProfile, "region");
2490 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2491 if (filter && filter->is_valid()) {
2492 filter->set("kdenlive_id", filterId);
2493 if (!region.isEmpty()) {
2494 filter->set("resource", region.toUtf8().constData());
2495 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2496 filter->set("filter0", filterTag);
2497 prefix = "filter0.";
2498 params.removeParam("id");
2499 params.removeParam("region");
2500 params.removeParam("kdenlive_ix");
2503 kDebug() << "filter is NULL";
2504 mlt_service_unlock(service.get_service());
2507 params.removeParam("kdenlive_id");
2508 if (params.hasParam("_sync_in_out")) {
2509 // This effect must sync in / out with parent clip
2510 params.removeParam("_sync_in_out");
2511 filter->set_in_and_out(service.get_int("in"), service.get_int("out"));
2514 for (int j = 0; j < params.count(); j++) {
2515 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2519 QString effectArgs = params.paramValue("id").section('_', 1);
2521 params.removeParam("id");
2522 params.removeParam("kdenlive_ix");
2523 params.removeParam("tag");
2524 params.removeParam("disable");
2525 params.removeParam("region");
2527 for (int j = 0; j < params.count(); j++) {
2528 effectArgs.append(' ' + params.at(j).value());
2530 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2531 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2534 // attach filter to the clip
2535 service.attach(*filter);
2540 // re-add following filters
2541 for (int i = 0; i < filtersList.count(); i++) {
2542 Mlt::Filter *filter = filtersList.at(i);
2544 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2545 service.attach(*filter);
2547 mlt_service_unlock(service.get_service());
2548 if (doRefresh) refresh();
2552 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2554 Mlt::Service service(m_mltProducer->parent().get_service());
2555 Mlt::Tractor tractor(service);
2556 Mlt::Producer trackProducer(tractor.track(track));
2557 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2558 Mlt::Service clipService(trackPlaylist.get_service());
2560 QString index = params.paramValue("kdenlive_ix");
2561 QString tag = params.paramValue("tag");
2563 Mlt::Filter *filter = clipService.filter(ct);
2565 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2569 filter = clipService.filter(ct);
2573 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2574 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2576 bool success = false;//mltAddTrackEffect(track, params);
2580 QString ser = filter->get("mlt_service");
2581 if (ser == "region") prefix = "filter0.";
2582 mlt_service_lock(service.get_service());
2583 for (int j = 0; j < params.count(); j++) {
2584 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2586 mlt_service_unlock(service.get_service());
2593 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2595 int index = params.paramValue("kdenlive_ix").toInt();
2596 QString tag = params.paramValue("tag");
2598 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2599 // This is a keyframe effect, to edit it, we remove it and re-add it.
2600 bool success = mltRemoveEffect(track, position, index, false);
2601 // if (!success) kDebug() << "// ERROR Removing effect : " << index;
2602 if (position < GenTime())
2603 success = mltAddTrackEffect(track, params);
2605 success = mltAddEffect(track, position, params);
2606 // if (!success) kDebug() << "// ERROR Adding effect : " << index;
2609 if (position < GenTime()) {
2610 return mltEditTrackEffect(track, params);
2613 Mlt::Service service(m_mltProducer->parent().get_service());
2614 Mlt::Tractor tractor(service);
2615 Mlt::Producer trackProducer(tractor.track(track));
2616 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2618 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2619 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2621 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2625 int duration = clip->get_playtime();
2626 bool doRefresh = true;
2627 // Check if clip is visible in monitor
2628 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2629 if (diff < 0 || diff > duration)
2633 Mlt::Filter *filter = clip->filter(ct);
2635 if (filter->get_int("kdenlive_ix") == index) {
2639 filter = clip->filter(ct);
2643 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2644 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2646 bool success = mltAddEffect(track, position, params);
2650 QString ser = filter->get("mlt_service");
2651 if (ser == "region") prefix = "filter0.";
2652 if (params.hasParam("_sync_in_out")) {
2653 // This effect must sync in / out with parent clip
2654 params.removeParam("_sync_in_out");
2655 filter->set_in_and_out(clip->get_in(), clip->get_out());
2657 mlt_service_lock(service.get_service());
2658 for (int j = 0; j < params.count(); j++) {
2659 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2663 mlt_service_unlock(service.get_service());
2665 if (doRefresh) refresh();
2669 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2671 Mlt::Service service(m_mltProducer->parent().get_service());
2672 Mlt::Tractor tractor(service);
2673 Mlt::Producer trackProducer(tractor.track(track));
2674 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2676 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2677 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2679 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2683 Mlt::Service clipService(clip->get_service());
2684 int duration = clip->get_playtime();
2685 bool doRefresh = true;
2686 // Check if clip is visible in monitor
2687 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2688 if (diff < 0 || diff > duration) doRefresh = false;
2692 Mlt::Filter *filter = clipService.filter(ct);
2694 int pos = filter->get_int("kdenlive_ix");
2695 if (pos == oldPos) {
2696 filter->set("kdenlive_ix", newPos);
2698 filter = clipService.filter(ct);
2700 if (doRefresh) refresh();
2703 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2705 if (position < GenTime()) {
2706 mltMoveTrackEffect(track, oldPos, newPos);
2709 Mlt::Service service(m_mltProducer->parent().get_service());
2710 Mlt::Tractor tractor(service);
2711 Mlt::Producer trackProducer(tractor.track(track));
2712 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2714 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2715 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2717 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2721 Mlt::Service clipService(clip->get_service());
2722 int duration = clip->get_playtime();
2723 bool doRefresh = true;
2724 // Check if clip is visible in monitor
2725 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2726 if (diff < 0 || diff > duration) doRefresh = false;
2730 QList <Mlt::Filter *> filtersList;
2731 Mlt::Filter *filter = clipService.filter(ct);
2733 if (newPos > oldPos) {
2735 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2736 filter->set("kdenlive_ix", newPos);
2737 filtersList.append(filter);
2738 clipService.detach(*filter);
2739 filter = clipService.filter(ct);
2740 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2741 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2743 filter = clipService.filter(ct);
2747 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2748 filtersList.append(filter);
2749 clipService.detach(*filter);
2751 filter = clipService.filter(ct);
2755 if (filter->get_int("kdenlive_ix") == oldPos) {
2756 filter->set("kdenlive_ix", newPos);
2757 filtersList.append(filter);
2758 clipService.detach(*filter);
2760 filter = clipService.filter(ct);
2764 filter = clipService.filter(ct);
2766 int pos = filter->get_int("kdenlive_ix");
2767 if (pos >= newPos) {
2768 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2769 filtersList.append(filter);
2770 clipService.detach(*filter);
2772 filter = clipService.filter(ct);
2776 for (int i = 0; i < filtersList.count(); i++) {
2777 clipService.attach(*(filtersList.at(i)));
2780 if (doRefresh) refresh();
2783 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2785 Mlt::Service service(m_mltProducer->parent().get_service());
2786 Mlt::Tractor tractor(service);
2787 Mlt::Producer trackProducer(tractor.track(track));
2788 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2789 Mlt::Service clipService(trackPlaylist.get_service());
2791 QList <Mlt::Filter *> filtersList;
2792 Mlt::Filter *filter = clipService.filter(ct);
2794 if (newPos > oldPos) {
2796 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2797 filter->set("kdenlive_ix", newPos);
2798 filtersList.append(filter);
2799 clipService.detach(*filter);
2800 filter = clipService.filter(ct);
2801 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2802 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2804 filter = clipService.filter(ct);
2808 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2809 filtersList.append(filter);
2810 clipService.detach(*filter);
2812 filter = clipService.filter(ct);
2816 if (filter->get_int("kdenlive_ix") == oldPos) {
2817 filter->set("kdenlive_ix", newPos);
2818 filtersList.append(filter);
2819 clipService.detach(*filter);
2821 filter = clipService.filter(ct);
2825 filter = clipService.filter(ct);
2827 int pos = filter->get_int("kdenlive_ix");
2828 if (pos >= newPos) {
2829 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2830 filtersList.append(filter);
2831 clipService.detach(*filter);
2833 filter = clipService.filter(ct);
2837 for (int i = 0; i < filtersList.count(); i++) {
2838 clipService.attach(*(filtersList.at(i)));
2843 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2845 Mlt::Service service(m_mltProducer->parent().get_service());
2846 Mlt::Tractor tractor(service);
2847 Mlt::Producer trackProducer(tractor.track(info.track));
2848 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2850 /* // Display playlist info
2851 kDebug()<<"//////////// BEFORE RESIZE";
2852 for (int i = 0; i < trackPlaylist.count(); i++) {
2853 int blankStart = trackPlaylist.clip_start(i);
2854 int blankDuration = trackPlaylist.clip_length(i) - 1;
2856 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2857 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2860 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2861 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2864 mlt_service_lock(service.get_service());
2865 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2866 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2867 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2869 int previousStart = clip->get_in();
2870 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2871 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2873 int currentOut = newDuration + previousStart;
2874 if (currentOut > clip->get_length()) {
2875 clip->parent().set("length", currentOut + 1);
2876 clip->parent().set("out", currentOut);
2877 clip->set("length", currentOut + 1);
2880 /*if (newDuration > clip->get_out()) {
2881 clip->parent().set_in_and_out(0, newDuration + 1);
2882 clip->set_in_and_out(0, newDuration + 1);
2885 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2886 trackPlaylist.consolidate_blanks(0);
2887 // skip to next clip
2889 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2891 // clip was made longer, trim next blank if there is one.
2892 if (clipIndex < trackPlaylist.count()) {
2893 // If this is not the last clip in playlist
2894 if (trackPlaylist.is_blank(clipIndex)) {
2895 int blankStart = trackPlaylist.clip_start(clipIndex);
2896 int blankDuration = trackPlaylist.clip_length(clipIndex);
2897 if (diff > blankDuration) {
2898 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2900 if (diff - blankDuration == 0) {
2901 trackPlaylist.remove(clipIndex);
2902 } else trackPlaylist.remove_region(blankStart, diff);
2904 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2907 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2908 trackPlaylist.consolidate_blanks(0);
2909 mlt_service_unlock(service.get_service());
2911 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2912 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2913 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2914 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2915 ItemInfo transpinfo;
2916 transpinfo.startPos = info.startPos;
2917 transpinfo.endPos = info.startPos + clipDuration;
2918 transpinfo.track = info.track;
2919 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2921 m_mltConsumer->set("refresh", 1);
2925 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2927 Mlt::Service service(m_mltProducer->parent().get_service());
2928 Mlt::Tractor tractor(service);
2929 Mlt::Producer trackProducer(tractor.track(track));
2931 // Make sure muting will not produce problems with our audio mixing transition,
2932 // because audio mixing is done between each track and the lowest one
2933 bool audioMixingBroken = false;
2934 if (mute && trackProducer.get_int("hide") < 2 ) {
2935 // We mute a track with sound
2936 if (track == getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
2937 kDebug()<<"Muting track: "<<track <<" / "<<getLowestNonMutedAudioTrack(tractor);
2939 else if (!mute && trackProducer.get_int("hide") > 1 ) {
2940 // We un-mute a previously muted track
2941 if (track < getLowestNonMutedAudioTrack(tractor)) audioMixingBroken = true;
2945 if (blind) trackProducer.set("hide", 3);
2946 else trackProducer.set("hide", 2);
2948 trackProducer.set("hide", 1);
2950 trackProducer.set("hide", 0);
2952 if (audioMixingBroken) fixAudioMixing(tractor);
2954 tractor.multitrack()->refresh();
2959 int Render::getLowestNonMutedAudioTrack(Mlt::Tractor tractor)
2961 for (int i = 1; i < tractor.count(); i++) {
2962 Mlt::Producer trackProducer(tractor.track(i));
2963 if (trackProducer.get_int("hide") < 2) return i;
2965 return tractor.count() - 1;
2968 void Render::fixAudioMixing(Mlt::Tractor tractor)
2970 // Make sure the audio mixing transitions are applied to the lowest audible (non muted) track
2971 int lowestTrack = getLowestNonMutedAudioTrack(tractor);
2973 mlt_service serv = m_mltProducer->parent().get_service();
2974 Mlt::Field *field = tractor.field();
2975 mlt_service_lock(serv);
2977 mlt_service nextservice = mlt_service_get_producer(serv);
2978 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2979 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2980 QString resource = mlt_properties_get(properties, "mlt_service");
2982 mlt_service nextservicetodisconnect;
2983 // Delete all audio mixing transitions
2984 while (mlt_type == "transition") {
2985 if (resource == "mix") {
2986 nextservicetodisconnect = nextservice;
2987 nextservice = mlt_service_producer(nextservice);
2988 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
2990 else nextservice = mlt_service_producer(nextservice);
2991 if (nextservice == NULL) break;
2992 properties = MLT_SERVICE_PROPERTIES(nextservice);
2993 mlt_type = mlt_properties_get(properties, "mlt_type");
2994 resource = mlt_properties_get(properties, "mlt_service");
2997 // Re-add correct audio transitions
2998 for (int i = lowestTrack + 1; i < tractor.count(); i++) {
2999 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3000 transition->set("always_active", 1);
3001 transition->set("combine", 1);
3002 transition->set("internal_added", 237);
3003 field->plant_transition(*transition, lowestTrack, i);
3005 mlt_service_unlock(serv);
3008 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
3010 Mlt::Service service(m_mltProducer->parent().get_service());
3011 int frameOffset = (int) diff.frames(m_fps);
3012 Mlt::Tractor tractor(service);
3013 Mlt::Producer trackProducer(tractor.track(info.track));
3014 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3015 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3016 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3019 mlt_service_lock(service.get_service());
3020 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3021 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3023 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3024 mlt_service_unlock(service.get_service());
3027 int previousStart = clip->get_in();
3028 int previousOut = clip->get_out();
3030 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
3031 mlt_service_unlock(service.get_service());
3032 m_mltConsumer->set("refresh", 1);
3036 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
3038 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
3039 Mlt::Service service(m_mltProducer->parent().get_service());
3040 int moveFrame = (int) diff.frames(m_fps);
3041 Mlt::Tractor tractor(service);
3042 Mlt::Producer trackProducer(tractor.track(info.track));
3043 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3044 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
3045 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
3048 mlt_service_lock(service.get_service());
3049 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
3050 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
3051 if (clip == NULL || clip->is_blank()) {
3052 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
3053 mlt_service_unlock(service.get_service());
3056 int previousStart = clip->get_in();
3057 int previousOut = clip->get_out();
3059 previousStart += moveFrame;
3061 if (previousStart < 0) {
3062 // this is possible for images and color clips
3063 previousOut -= previousStart;
3067 int length = previousOut + 1;
3068 if (length > clip->get_length()) {
3069 clip->parent().set("length", length + 1);
3070 clip->parent().set("out", length);
3071 clip->set("length", length + 1);
3075 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3076 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3077 if (moveFrame > 0) {
3078 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3080 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3081 int blankIndex = clipIndex - 1;
3082 int blankLength = trackPlaylist.clip_length(blankIndex);
3083 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3084 if (! trackPlaylist.is_blank(blankIndex)) {
3085 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3087 if (blankLength + moveFrame == 0)
3088 trackPlaylist.remove(blankIndex);
3090 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3092 trackPlaylist.consolidate_blanks(0);
3093 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3094 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3095 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3096 ItemInfo transpinfo;
3097 transpinfo.startPos = info.startPos + diff;
3098 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3099 transpinfo.track = info.track;
3100 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3102 //m_mltConsumer->set("refresh", 1);
3103 mlt_service_unlock(service.get_service());
3104 m_mltConsumer->set("refresh", 1);
3108 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3110 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3114 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3116 if (prod == NULL || !prod->is_valid()) {
3117 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3120 //kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3121 Mlt::Service service(m_mltProducer->parent().get_service());
3122 if (service.type() != tractor_type) {
3123 kWarning() << "// TRACTOR PROBLEM";
3126 mlt_service_lock(service.get_service());
3127 Mlt::Tractor tractor(service);
3128 Mlt::Producer trackProducer(tractor.track(track));
3129 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3130 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3131 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3132 if (clipProducer == NULL || clipProducer->is_blank()) {
3133 kDebug() << "// ERROR UPDATING CLIP PROD";
3134 delete clipProducer;
3135 mlt_service_unlock(service.get_service());
3138 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3139 if (!clip || !clip->is_valid()) {
3140 if (clip) delete clip;
3141 delete clipProducer;
3142 mlt_service_unlock(service.get_service());
3145 // move all effects to the correct producer
3146 mltPasteEffects(clipProducer, clip);
3147 trackPlaylist.insert_at(pos, clip, 1);
3149 delete clipProducer;
3150 mlt_service_unlock(service.get_service());
3154 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3156 Mlt::Service service(m_mltProducer->parent().get_service());
3157 if (service.type() != tractor_type) {
3158 kWarning() << "// TRACTOR PROBLEM";
3162 Mlt::Tractor tractor(service);
3163 mlt_service_lock(service.get_service());
3164 Mlt::Producer trackProducer(tractor.track(startTrack));
3165 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3166 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3167 //kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3168 bool checkLength = false;
3169 if (endTrack == startTrack) {
3170 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3171 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3172 // error, destination is not empty
3174 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3175 delete clipProducer;
3177 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3178 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3179 mlt_service_unlock(service.get_service());
3182 trackPlaylist.consolidate_blanks(0);
3184 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3185 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3186 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3188 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3189 trackPlaylist.consolidate_blanks(1);
3190 delete clipProducer;
3191 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3192 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3194 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3196 //mlt_service_unlock(service.get_service());
3198 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3199 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3200 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3201 // error, destination is not empty
3202 mlt_service_unlock(service.get_service());
3205 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3206 if (!clipProducer || clipProducer->is_blank()) {
3207 // error, destination is not empty
3208 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3209 if (clipProducer) delete clipProducer;
3210 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3211 mlt_service_unlock(service.get_service());
3214 trackPlaylist.consolidate_blanks(0);
3215 destTrackPlaylist.consolidate_blanks(1);
3216 Mlt::Producer *clip;
3217 // check if we are moving a slowmotion producer
3218 QString serv = clipProducer->parent().get("mlt_service");
3219 QString currentid = clipProducer->parent().get("id");
3220 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3221 clip = clipProducer;
3224 // Special case: prod is null when using placeholder clips.
3225 // in that case, use the producer existing in playlist. Note that
3226 // it will bypass the one producer per track logic and might cause
3227 // Sound cracks if clip is moved so that it overlaps another copy of itself
3228 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3229 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3232 // move all effects to the correct producer
3233 mltPasteEffects(clipProducer, clip);
3236 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3237 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3238 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3241 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3243 if (clip == clipProducer) {
3248 delete clipProducer;
3250 destTrackPlaylist.consolidate_blanks(0);
3251 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3252 kDebug() << "//////// moving clip transparency";
3253 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3255 if (clipIndex > trackPlaylist.count()) checkLength = true;
3256 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3259 mlt_service_unlock(service.get_service());
3260 if (checkLength) mltCheckLength(&tractor);
3262 //m_mltConsumer->set("refresh", 1);
3267 QList <int> Render::checkTrackSequence(int track)
3270 Mlt::Service service(m_mltProducer->parent().get_service());
3271 if (service.type() != tractor_type) {
3272 kWarning() << "// TRACTOR PROBLEM";
3275 Mlt::Tractor tractor(service);
3276 mlt_service_lock(service.get_service());
3277 Mlt::Producer trackProducer(tractor.track(track));
3278 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3279 int clipNb = trackPlaylist.count();
3280 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3281 for (int i = 0; i < clipNb; i++) {
3282 Mlt::Producer *c = trackPlaylist.get_clip(i);
3283 int pos = trackPlaylist.clip_start(i);
3284 if (!list.contains(pos)) list.append(pos);
3285 pos += c->get_playtime();
3286 if (!list.contains(pos)) list.append(pos);
3292 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3294 int new_in = (int)newIn.frames(m_fps);
3295 int new_out = (int)newOut.frames(m_fps) - 1;
3296 if (new_in >= new_out) return false;
3297 int old_in = (int)oldIn.frames(m_fps);
3298 int old_out = (int)oldOut.frames(m_fps) - 1;
3300 Mlt::Service service(m_mltProducer->parent().get_service());
3301 Mlt::Tractor tractor(service);
3302 Mlt::Field *field = tractor.field();
3304 bool doRefresh = true;
3305 // Check if clip is visible in monitor
3306 int diff = old_out - m_mltProducer->position();
3307 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3309 diff = new_out - m_mltProducer->position();
3310 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3312 mlt_service_lock(service.get_service());
3314 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3315 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3316 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3317 QString resource = mlt_properties_get(properties, "mlt_service");
3318 int old_pos = (int)(old_in + old_out) / 2;
3321 while (mlt_type == "transition") {
3322 Mlt::Transition transition((mlt_transition) nextservice);
3323 int currentTrack = transition.get_b_track();
3324 int currentIn = (int) transition.get_in();
3325 int currentOut = (int) transition.get_out();
3327 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3329 if (newTrack - startTrack != 0) {
3330 Mlt::Properties trans_props(transition.get_properties());
3331 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3332 Mlt::Properties new_trans_props(new_transition.get_properties());
3333 new_trans_props.inherit(trans_props);
3334 new_transition.set_in_and_out(new_in, new_out);
3335 field->disconnect_service(transition);
3336 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3337 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3338 } else transition.set_in_and_out(new_in, new_out);
3341 nextservice = mlt_service_producer(nextservice);
3342 if (nextservice == NULL) break;
3343 properties = MLT_SERVICE_PROPERTIES(nextservice);
3344 mlt_type = mlt_properties_get(properties, "mlt_type");
3345 resource = mlt_properties_get(properties, "mlt_service");
3347 mlt_service_unlock(service.get_service());
3348 if (doRefresh) refresh();
3349 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3354 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3356 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3357 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3358 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3359 QString resource = mlt_properties_get(properties, "mlt_service");
3360 QList <Mlt::Transition *> trList;
3362 while (mlt_type == "transition") {
3363 Mlt::Transition transition((mlt_transition) nextservice);
3364 int aTrack = transition.get_a_track();
3365 int bTrack = transition.get_b_track();
3366 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3367 Mlt::Properties trans_props(transition.get_properties());
3368 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3369 Mlt::Properties new_trans_props(cp->get_properties());
3370 new_trans_props.inherit(trans_props);
3372 field->disconnect_service(transition);
3374 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3376 nextservice = mlt_service_producer(nextservice);
3377 if (nextservice == NULL) break;
3378 properties = MLT_SERVICE_PROPERTIES(nextservice);
3379 mlt_type = mlt_properties_get(properties, "mlt_type");
3380 resource = mlt_properties_get(properties, "mlt_service");
3382 field->plant_transition(tr, a_track, b_track);
3384 // re-add upper transitions
3385 for (int i = trList.count() - 1; i >= 0; i--) {
3386 //kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3387 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3391 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3393 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3395 //kDebug()<<"// DELETING TRANS: "<<a_track<<"-"<<b_track;
3396 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3397 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3400 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3403 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3405 mlt_service serv = m_mltProducer->parent().get_service();
3406 mlt_service_lock(serv);
3408 mlt_service nextservice = mlt_service_get_producer(serv);
3409 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3410 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3411 QString resource = mlt_properties_get(properties, "mlt_service");
3412 int in_pos = (int) in.frames(m_fps);
3413 int out_pos = (int) out.frames(m_fps) - 1;
3415 while (mlt_type == "transition") {
3416 mlt_transition tr = (mlt_transition) nextservice;
3417 int currentTrack = mlt_transition_get_b_track(tr);
3418 int currentBTrack = mlt_transition_get_a_track(tr);
3419 int currentIn = (int) mlt_transition_get_in(tr);
3420 int currentOut = (int) mlt_transition_get_out(tr);
3422 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3423 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3424 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3425 QMap<QString, QString>::Iterator it;
3427 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3429 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3430 if (currentId != xml.attribute("id")) {
3431 // The transition ID is not the same, so reset all properties
3432 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3433 // Cleanup previous properties
3434 QStringList permanentProps;
3435 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3436 permanentProps << "out" << "a_track" << "b_track";
3437 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3438 QString propName = mlt_properties_get_name(transproperties, i);
3439 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3440 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3445 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3446 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3448 if (currentBTrack != a_track) {
3449 mlt_properties_set_int(transproperties, "a_track", a_track);
3451 for (it = map.begin(); it != map.end(); ++it) {
3453 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3454 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3455 //filter->set("kdenlive_id", id);
3459 nextservice = mlt_service_producer(nextservice);
3460 if (nextservice == NULL) break;
3461 properties = MLT_SERVICE_PROPERTIES(nextservice);
3462 mlt_type = mlt_properties_get(properties, "mlt_type");
3463 resource = mlt_properties_get(properties, "mlt_service");
3465 mlt_service_unlock(serv);
3467 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3470 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3472 mlt_service serv = m_mltProducer->parent().get_service();
3473 mlt_service_lock(serv);
3475 Mlt::Service service(serv);
3476 Mlt::Tractor tractor(service);
3477 Mlt::Field *field = tractor.field();
3479 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3481 mlt_service nextservice = mlt_service_get_producer(serv);
3482 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3483 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3484 QString resource = mlt_properties_get(properties, "mlt_service");
3486 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3487 //kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3489 while (mlt_type == "transition") {
3490 mlt_transition tr = (mlt_transition) nextservice;
3491 int currentTrack = mlt_transition_get_b_track(tr);
3492 int currentIn = (int) mlt_transition_get_in(tr);
3493 int currentOut = (int) mlt_transition_get_out(tr);
3494 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3496 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3497 mlt_field_disconnect_service(field->get_field(), nextservice);
3500 nextservice = mlt_service_producer(nextservice);
3501 if (nextservice == NULL) break;
3502 properties = MLT_SERVICE_PROPERTIES(nextservice);
3503 mlt_type = mlt_properties_get(properties, "mlt_type");
3504 resource = mlt_properties_get(properties, "mlt_service");
3506 mlt_service_unlock(serv);
3508 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3511 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3513 QDomNodeList attribs = xml.elementsByTagName("parameter");
3514 QMap<QString, QString> map;
3515 for (int i = 0; i < attribs.count(); i++) {
3516 QDomElement e = attribs.item(i).toElement();
3517 QString name = e.attribute("name");
3518 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3519 map[name] = e.attribute("default");
3520 if (!e.attribute("value").isEmpty()) {
3521 map[name] = e.attribute("value");
3523 if (e.attribute("type") != "addedgeometry" && (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0")) {
3524 map[name] = m_locale.toString((map.value(name).toDouble() - e.attribute("offset", "0").toDouble()) / e.attribute("factor", "1").toDouble());
3525 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3528 if (e.attribute("namedesc").contains(';')) {
3529 QString format = e.attribute("format");
3530 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3531 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3533 QTextStream txtNeu(&neu);
3534 if (values.size() > 0)
3535 txtNeu << (int)values[0].toDouble();
3537 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3538 txtNeu << separators[i];
3539 txtNeu << (int)(values[i+1].toDouble());
3541 if (i < separators.size())
3542 txtNeu << separators[i];
3543 map[e.attribute("name")] = neu;
3550 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3552 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3553 Mlt::Service service(m_mltProducer->parent().get_service());
3554 Mlt::Tractor tractor(service);
3555 Mlt::Field *field = tractor.field();
3557 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3558 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3559 transition->set("transparency", id);
3560 transition->set("fill", 1);
3561 transition->set("internal_added", 237);
3562 field->plant_transition(*transition, transitiontrack, info.track);
3566 void Render::mltDeleteTransparency(int pos, int track, int id)
3568 Mlt::Service service(m_mltProducer->parent().get_service());
3569 Mlt::Tractor tractor(service);
3570 Mlt::Field *field = tractor.field();
3572 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3573 mlt_service serv = m_mltProducer->parent().get_service();
3575 mlt_service nextservice = mlt_service_get_producer(serv);
3576 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3577 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3578 QString resource = mlt_properties_get(properties, "mlt_service");
3580 while (mlt_type == "transition") {
3581 mlt_transition tr = (mlt_transition) nextservice;
3582 int currentTrack = mlt_transition_get_b_track(tr);
3583 int currentIn = (int) mlt_transition_get_in(tr);
3584 int currentOut = (int) mlt_transition_get_out(tr);
3585 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3586 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3588 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3589 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3590 mlt_field_disconnect_service(field->get_field(), nextservice);
3593 nextservice = mlt_service_producer(nextservice);
3594 if (nextservice == NULL) break;
3595 properties = MLT_SERVICE_PROPERTIES(nextservice);
3596 mlt_type = mlt_properties_get(properties, "mlt_type");
3597 resource = mlt_properties_get(properties, "mlt_service");
3599 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3602 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3604 Mlt::Service service(m_mltProducer->parent().get_service());
3605 Mlt::Tractor tractor(service);
3607 mlt_service_lock(service.get_service());
3608 m_mltConsumer->set("refresh", 0);
3610 mlt_service serv = m_mltProducer->parent().get_service();
3611 mlt_service nextservice = mlt_service_get_producer(serv);
3612 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3613 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3614 QString resource = mlt_properties_get(properties, "mlt_service");
3615 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3616 while (mlt_type == "transition") {
3617 mlt_transition tr = (mlt_transition) nextservice;
3618 int currentTrack = mlt_transition_get_b_track(tr);
3619 int currentIn = (int) mlt_transition_get_in(tr);
3620 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3621 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3622 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3623 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3624 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3625 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3628 nextservice = mlt_service_producer(nextservice);
3629 if (nextservice == NULL) break;
3630 properties = MLT_SERVICE_PROPERTIES(nextservice);
3631 mlt_type = mlt_properties_get(properties, "mlt_type");
3632 resource = mlt_properties_get(properties, "mlt_service");
3634 mlt_service_unlock(service.get_service());
3635 m_mltConsumer->set("refresh", 1);
3639 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3641 Mlt::Service service(m_mltProducer->parent().get_service());
3642 Mlt::Tractor tractor(service);
3644 mlt_service_lock(service.get_service());
3645 m_mltConsumer->set("refresh", 0);
3647 mlt_service serv = m_mltProducer->parent().get_service();
3648 mlt_service nextservice = mlt_service_get_producer(serv);
3649 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3650 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3651 QString resource = mlt_properties_get(properties, "mlt_service");
3653 while (mlt_type == "transition") {
3654 mlt_transition tr = (mlt_transition) nextservice;
3655 int currentTrack = mlt_transition_get_b_track(tr);
3656 int currentaTrack = mlt_transition_get_a_track(tr);
3657 int currentIn = (int) mlt_transition_get_in(tr);
3658 int currentOut = (int) mlt_transition_get_out(tr);
3659 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3660 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3661 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3662 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3663 kDebug() << "//////MOVING";
3664 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3665 if (endTrack != startTrack) {
3666 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3667 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3668 mlt_properties_set_int(properties, "b_track", endTrack);
3672 nextservice = mlt_service_producer(nextservice);
3673 if (nextservice == NULL) break;
3674 properties = MLT_SERVICE_PROPERTIES(nextservice);
3675 mlt_type = mlt_properties_get(properties, "mlt_type");
3676 resource = mlt_properties_get(properties, "mlt_service");
3678 mlt_service_unlock(service.get_service());
3679 m_mltConsumer->set("refresh", 1);
3683 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3685 if (in >= out) return false;
3686 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3687 Mlt::Service service(m_mltProducer->parent().get_service());
3689 Mlt::Tractor tractor(service);
3690 Mlt::Field *field = tractor.field();
3692 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3693 if (out != GenTime())
3694 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3696 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3697 QMap<QString, QString>::Iterator it;
3699 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3700 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3701 if (xml.hasAttribute("id"))
3702 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3703 if (xml.hasAttribute("force_track"))
3704 transition->set("force_track", xml.attribute("force_track").toInt());
3706 for (it = args.begin(); it != args.end(); ++it) {
3708 if (!it.value().isEmpty())
3709 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3710 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3712 // attach transition
3713 mlt_service_lock(service.get_service());
3714 mltPlantTransition(field, *transition, a_track, b_track);
3715 // field->plant_transition(*transition, a_track, b_track);
3716 mlt_service_unlock(service.get_service());
3717 if (do_refresh) refresh();
3721 void Render::mltSavePlaylist()
3723 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3724 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3725 fileConsumer.set("resource", "/tmp/playlist.mlt");
3727 Mlt::Service service(m_mltProducer->get_service());
3729 fileConsumer.connect(service);
3730 fileConsumer.start();
3733 const QList <Mlt::Producer *> Render::producersList()
3735 QList <Mlt::Producer *> prods;
3736 if (m_mltProducer == NULL) return prods;
3737 Mlt::Service service(m_mltProducer->parent().get_service());
3738 if (service.type() != tractor_type) return prods;
3739 Mlt::Tractor tractor(service);
3742 int trackNb = tractor.count();
3743 for (int t = 1; t < trackNb; t++) {
3744 Mlt::Producer *tt = tractor.track(t);
3745 Mlt::Producer trackProducer(tt);
3747 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3748 int clipNb = trackPlaylist.count();
3749 for (int i = 0; i < clipNb; i++) {
3750 Mlt::Producer *c = trackPlaylist.get_clip(i);
3751 if (c == NULL) continue;
3752 QString prodId = c->parent().get("id");
3753 if (!c->is_blank() && !ids.contains(prodId) && !prodId.startsWith("slowmotion") && !prodId.isEmpty()) {
3754 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3757 prods.append(nprod);
3766 void Render::fillSlowMotionProducers()
3768 if (m_mltProducer == NULL) return;
3769 Mlt::Service service(m_mltProducer->parent().get_service());
3770 if (service.type() != tractor_type) return;
3772 Mlt::Tractor tractor(service);
3774 int trackNb = tractor.count();
3775 for (int t = 1; t < trackNb; t++) {
3776 Mlt::Producer *tt = tractor.track(t);
3777 Mlt::Producer trackProducer(tt);
3779 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3780 int clipNb = trackPlaylist.count();
3781 for (int i = 0; i < clipNb; i++) {
3782 Mlt::Producer *c = trackPlaylist.get_clip(i);
3783 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3785 QString id = nprod->parent().get("id");
3786 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3787 // this is a slowmotion producer, add it to the list
3788 QString url = QString::fromUtf8(nprod->get("resource"));
3789 int strobe = nprod->get_int("strobe");
3790 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3791 if (!m_slowmotionProducers.contains(url)) {
3792 m_slowmotionProducers.insert(url, nprod);
3794 } else delete nprod;
3801 void Render::mltInsertTrack(int ix, bool videoTrack)
3805 Mlt::Service service(m_mltProducer->parent().get_service());
3806 mlt_service_lock(service.get_service());
3807 if (service.type() != tractor_type) {
3808 kWarning() << "// TRACTOR PROBLEM";
3812 Mlt::Tractor tractor(service);
3814 Mlt::Playlist playlist;
3815 int ct = tractor.count();
3817 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3823 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3824 tractor.set_track(playlist, pos);
3825 Mlt::Producer newProd(tractor.track(pos));
3826 if (!videoTrack) newProd.set("hide", 1);
3828 for (; pos <= ct; pos++) {
3829 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3830 tractor.set_track(*prodToMove, pos);
3831 prodToMove = prodToMove2;
3834 tractor.set_track(playlist, ix);
3835 Mlt::Producer newProd(tractor.track(ix));
3836 if (!videoTrack) newProd.set("hide", 1);
3840 mlt_service serv = m_mltProducer->parent().get_service();
3841 mlt_service nextservice = mlt_service_get_producer(serv);
3842 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3843 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3844 QString resource = mlt_properties_get(properties, "mlt_service");
3846 while (mlt_type == "transition") {
3847 if (resource != "mix") {
3848 mlt_transition tr = (mlt_transition) nextservice;
3849 int currentTrack = mlt_transition_get_b_track(tr);
3850 int currentaTrack = mlt_transition_get_a_track(tr);
3851 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3853 if (currentTrack >= ix) {
3854 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3855 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3858 nextservice = mlt_service_producer(nextservice);
3859 if (nextservice == NULL) break;
3860 properties = MLT_SERVICE_PROPERTIES(nextservice);
3861 mlt_type = mlt_properties_get(properties, "mlt_type");
3862 resource = mlt_properties_get(properties, "mlt_service");
3865 // Add audio mix transition to last track
3866 Mlt::Field *field = tractor.field();
3867 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3868 transition->set("a_track", 1);
3869 transition->set("b_track", ct);
3870 transition->set("always_active", 1);
3871 transition->set("internal_added", 237);
3872 transition->set("combine", 1);
3873 field->plant_transition(*transition, 1, ct);
3874 //mlt_service_unlock(m_mltConsumer->get_service());
3875 mlt_service_unlock(service.get_service());
3876 //tractor.multitrack()->refresh();
3877 //tractor.refresh();
3878 blockSignals(false);
3882 void Render::mltDeleteTrack(int ix)
3885 doc.setContent(sceneList(), false);
3886 int tracksCount = doc.elementsByTagName("track").count() - 1;
3887 QDomNode track = doc.elementsByTagName("track").at(ix);
3888 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3889 QDomNodeList transitions = doc.elementsByTagName("transition");
3890 for (int i = 0; i < transitions.count(); i++) {
3891 QDomElement e = transitions.at(i).toElement();
3892 QDomNodeList props = e.elementsByTagName("property");
3893 QMap <QString, QString> mappedProps;
3894 for (int j = 0; j < props.count(); j++) {
3895 QDomElement f = props.at(j).toElement();
3896 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3898 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3899 tractor.removeChild(transitions.at(i));
3901 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3902 // Transition needs to be moved
3903 int a_track = mappedProps.value("a_track").toInt();
3904 int b_track = mappedProps.value("b_track").toInt();
3905 if (a_track > 0 && a_track >= ix) a_track --;
3906 if (b_track == ix) {
3907 // transition was on the deleted track, so remove it
3908 tractor.removeChild(transitions.at(i));
3912 if (b_track > 0 && b_track > ix) b_track --;
3913 for (int j = 0; j < props.count(); j++) {
3914 QDomElement f = props.at(j).toElement();
3915 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3916 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3921 tractor.removeChild(track);
3922 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3923 setSceneList(doc.toString(), m_framePosition);
3924 emit refreshDocumentProducers(false, false);
3928 void Render::updatePreviewSettings()
3930 kDebug() << "////// RESTARTING CONSUMER";
3931 if (!m_mltConsumer || !m_mltProducer) return;
3932 if (m_mltProducer->get_playtime() == 0) return;
3933 Mlt::Service service(m_mltProducer->parent().get_service());
3934 if (service.type() != tractor_type) return;
3936 //m_mltConsumer->set("refresh", 0);
3937 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3938 m_mltConsumer->purge();
3939 QString scene = sceneList();
3941 if (m_mltProducer) {
3942 pos = m_mltProducer->position();
3945 setSceneList(scene, pos);
3949 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3951 // Update all frame positions to the new fps value
3952 //WARNING: there are probably some effects or other that hold a frame value
3953 // as parameter and will also need to be updated here!
3955 doc.setContent(scene);
3957 double factor = new_fps / current_fps;
3958 QDomNodeList producers = doc.elementsByTagName("producer");
3959 for (int i = 0; i < producers.count(); i++) {
3960 QDomElement prod = producers.at(i).toElement();
3961 prod.removeAttribute("in");
3962 prod.removeAttribute("out");
3964 QDomNodeList props = prod.childNodes();
3965 for (int j = 0; j < props.count(); j++) {
3966 QDomElement param = props.at(j).toElement();
3967 QString paramName = param.attribute("name");
3968 if (paramName.startsWith("meta.") || paramName == "length") {
3969 prod.removeChild(props.at(j));
3975 QDomNodeList entries = doc.elementsByTagName("entry");
3976 for (int i = 0; i < entries.count(); i++) {
3977 QDomElement entry = entries.at(i).toElement();
3978 int in = entry.attribute("in").toInt();
3979 int out = entry.attribute("out").toInt();
3980 in = factor * in + 0.5;
3981 out = factor * out + 0.5;
3982 entry.setAttribute("in", in);
3983 entry.setAttribute("out", out);
3986 QDomNodeList blanks = doc.elementsByTagName("blank");
3987 for (int i = 0; i < blanks.count(); i++) {
3988 QDomElement blank = blanks.at(i).toElement();
3989 int length = blank.attribute("length").toInt();
3990 length = factor * length + 0.5;
3991 blank.setAttribute("length", QString::number(length));
3994 QDomNodeList filters = doc.elementsByTagName("filter");
3995 for (int i = 0; i < filters.count(); i++) {
3996 QDomElement filter = filters.at(i).toElement();
3997 int in = filter.attribute("in").toInt();
3998 int out = filter.attribute("out").toInt();
3999 in = factor * in + 0.5;
4000 out = factor * out + 0.5;
4001 filter.setAttribute("in", in);
4002 filter.setAttribute("out", out);
4005 QDomNodeList transitions = doc.elementsByTagName("transition");
4006 for (int i = 0; i < transitions.count(); i++) {
4007 QDomElement transition = transitions.at(i).toElement();
4008 int in = transition.attribute("in").toInt();
4009 int out = transition.attribute("out").toInt();
4010 in = factor * in + 0.5;
4011 out = factor * out + 0.5;
4012 transition.setAttribute("in", in);
4013 transition.setAttribute("out", out);
4014 QDomNodeList props = transition.childNodes();
4015 for (int j = 0; j < props.count(); j++) {
4016 QDomElement param = props.at(j).toElement();
4017 QString paramName = param.attribute("name");
4018 if (paramName == "geometry") {
4019 QString geom = param.firstChild().nodeValue();
4020 QStringList keys = geom.split(';');
4021 QStringList newKeys;
4022 for (int k = 0; k < keys.size(); ++k) {
4023 if (keys.at(k).contains('=')) {
4024 int pos = keys.at(k).section('=', 0, 0).toInt();
4025 pos = factor * pos + 0.5;
4026 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
4027 } else newKeys.append(keys.at(k));
4029 param.firstChild().setNodeValue(newKeys.join(";"));
4033 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
4034 int out = tractor.attribute("out").toInt();
4035 out = factor * out + 0.5;
4036 tractor.setAttribute("out", out);
4037 emit durationChanged(out);
4039 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4040 return doc.toString();
4044 void Render::sendFrameUpdate()
4046 if (m_mltProducer) {
4047 Mlt::Frame * frame = m_mltProducer->get_frame();
4048 emitFrameUpdated(*frame);
4053 Mlt::Producer* Render::getProducer()
4055 return m_mltProducer;
4059 #include "renderer.moc"