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>
51 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
53 if (level > MLT_LOG_ERROR) return;
55 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
60 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
62 // detect if the producer has finished playing. Is there a better way to do it?
63 if (self->m_isBlocked) return;
64 Mlt::Frame frame(frame_ptr);
65 if (!frame.is_valid()) return;
66 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
67 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
68 self->emitFrameUpdated(frame);
70 if (self->analyseAudio) self->showAudio(frame);
71 if (frame.get_double("_speed") == 0.0) {
72 self->emitConsumerStopped();
73 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
75 self->emitConsumerStopped();
79 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
81 // detect if the producer has finished playing. Is there a better way to do it?
82 if (self->m_isBlocked) return;
83 Mlt::Frame frame(frame_ptr);
84 self->showFrame(frame);
85 if (frame.get_double("_speed") == 0.0) {
86 self->emitConsumerStopped();
87 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
89 self->emitConsumerStopped();
93 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
96 sendFrameForAnalysis(false),
97 analyseAudio(KdenliveSettings::monitor_audio()),
103 m_externalConsumer(false),
106 m_isSplitView(false),
110 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
111 buildConsumer(profile);
113 m_mltProducer = m_blackClip->cut(0, 50);
114 m_mltConsumer->connect(*m_mltProducer);
115 m_mltProducer->set_speed(0.0);
125 void Render::closeMlt()
129 Mlt::Service service(m_mltProducer->parent().get_service());
130 mlt_service_lock(service.get_service());
132 if (service.type() == tractor_type) {
133 Mlt::Tractor tractor(service);
134 Mlt::Field *field = tractor.field();
135 mlt_service nextservice = mlt_service_get_producer(service.get_service());
136 mlt_service nextservicetodisconnect;
137 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
138 QString mlt_type = mlt_properties_get(properties, "mlt_type");
139 QString resource = mlt_properties_get(properties, "mlt_service");
140 // Delete all transitions
141 while (mlt_type == "transition") {
142 nextservicetodisconnect = nextservice;
143 nextservice = mlt_service_producer(nextservice);
144 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
145 nextservice = mlt_service_producer(nextservice);
146 if (nextservice == NULL) break;
147 properties = MLT_SERVICE_PROPERTIES(nextservice);
148 mlt_type = mlt_properties_get(properties, "mlt_type");
149 resource = mlt_properties_get(properties, "mlt_service");
152 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
153 Mlt::Producer trackProducer(tractor.track(trackNb));
154 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
155 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
158 mlt_service_unlock(service.get_service());
161 kDebug() << "// // // CLOSE RENDERER " << m_name;
162 delete m_mltConsumer;
163 delete m_mltProducer;
168 void Render::slotSwitchFullscreen()
170 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
173 void Render::buildConsumer(const QString profileName)
175 m_activeProfile = profileName;
176 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
177 setenv("MLT_PROFILE", tmp, 1);
181 //TODO: uncomment following line when everything is clean
182 //if (m_mltProfile) delete m_mltProfile;
183 m_mltProfile = new Mlt::Profile(tmp);
184 m_mltProfile->get_profile()->is_explicit = 1;
187 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
188 m_blackClip->set("id", "black");
189 m_blackClip->set("mlt_type", "producer");
191 if (KdenliveSettings::external_display() && m_name != "clip") {
192 // Use blackmagic card for video output
193 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
194 if (BMInterface::isSupportedProfile(KdenliveSettings::blackmagic_output_device(), profileProperties)) {
195 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
196 tmp = qstrdup(decklink.toUtf8().constData());
197 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, tmp);
200 m_externalConsumer = true;
201 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
202 m_mltConsumer->set("terminate_on_pause", 0);
203 mlt_log_set_callback(kdenlive_callback);
205 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
206 } 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()));
208 m_externalConsumer = false;
209 QString videoDriver = KdenliveSettings::videodrivername();
210 if (!videoDriver.isEmpty()) {
211 if (videoDriver == "x11_noaccel") {
212 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
215 unsetenv("SDL_VIDEO_YUV_HWACCEL");
218 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
220 //m_mltConsumer->set("fullscreen", 1);
223 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
224 m_mltConsumer->set("preview_off", 1);
225 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
226 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
228 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
229 // FIXME: the event object returned by the listen gets leaked...
230 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
231 m_mltConsumer->set("window_id", m_winid);
233 m_mltConsumer->set("resize", 1);
234 m_mltConsumer->set("terminate_on_pause", 1);
235 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
236 m_mltConsumer->set("rescale", "nearest");
237 mlt_log_set_callback(kdenlive_callback);
239 QString audioDevice = KdenliveSettings::audiodevicename();
240 if (!audioDevice.isEmpty())
241 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
243 if (!videoDriver.isEmpty())
244 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
246 QString audioDriver = KdenliveSettings::audiodrivername();
249 // Disabled because the "auto" detected driver was sometimes wrong
250 if (audioDriver.isEmpty())
251 audioDriver = KdenliveSettings::autoaudiodrivername();
254 if (!audioDriver.isEmpty())
255 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
257 m_mltConsumer->set("progressive", 1);
258 m_mltConsumer->set("audio_buffer", 1024);
259 m_mltConsumer->set("frequency", 48000);
262 Mlt::Producer *Render::invalidProducer(const QString &id)
264 Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
265 clip->set("id", id.toUtf8().constData());
266 clip->set("mlt_type", "producer");
270 int Render::resetProfile(const QString profileName)
273 if (m_externalConsumer == KdenliveSettings::external_display()) {
274 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
275 QString videoDriver = KdenliveSettings::videodrivername();
276 QString currentDriver = m_mltConsumer->get("video_driver");
277 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
278 QString background = KdenliveSettings::window_background().name();
279 QString currentBackground = m_mltConsumer->get("window_background");
280 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
281 kDebug() << "reset to same profile, nothing to do";
286 if (m_isSplitView) slotSplitView(false);
287 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
288 m_mltConsumer->purge();
289 delete m_mltConsumer;
290 m_mltConsumer = NULL;
292 QString scene = sceneList();
294 double current_fps = m_mltProfile->fps();
299 pos = m_mltProducer->position();
301 Mlt::Service service(m_mltProducer->get_service());
302 if (service.type() == tractor_type) {
303 Mlt::Tractor tractor(service);
304 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
305 Mlt::Producer trackProducer(tractor.track(trackNb));
306 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
307 trackPlaylist.clear();
311 delete m_mltProducer;
313 m_mltProducer = NULL;
314 buildConsumer(profileName);
315 double new_fps = m_mltProfile->fps();
316 if (current_fps != new_fps) {
317 // fps changed, we must update the scenelist positions
318 scene = updateSceneListFps(current_fps, new_fps, scene);
320 //kDebug() << "//RESET WITHSCENE: " << scene;
321 setSceneList(scene, pos);
322 // producers have changed (different profile), so reset them...
323 emit refreshDocumentProducers();
324 /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
325 m_mltProducer = producer;
326 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
327 m_mltProducer->optimise();
328 m_mltProducer->set_speed(0);
331 //delete m_mltProfile;
332 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
333 //mlt_profile prof = m_mltProfile->get_profile();
334 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
335 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
336 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
337 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
339 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
344 void Render::seek(GenTime time)
349 m_mltProducer->seek((int)(time.frames(m_fps)));
354 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
355 QPixmap pix(width, height);
357 mlt_image_format format = mlt_image_rgb24a;
358 uint8_t *thumb = frame->get_image(format, width, height);
359 QImage image(thumb, width, height, QImage::Format_ARGB32);
361 if (!image.isNull()) {
362 pix = pix.fromImage(image);
364 QPainter painter(&pix);
365 painter.drawRect(0, 0, width - 1, height - 1);
367 } else pix.fill(Qt::black);
371 int Render::frameRenderWidth() const
373 return m_mltProfile->width();
376 int Render::renderWidth() const
378 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
381 int Render::renderHeight() const
383 return m_mltProfile->height();
386 QImage Render::extractFrame(int frame_position, int width, int height)
389 width = renderWidth();
390 height = renderHeight();
391 } else if (width % 2 == 1) width++;
393 if (!m_mltProducer) {
394 QImage pix(width, height, QImage::Format_RGB32);
398 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
401 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
405 if (url.fileName().startsWith(".all.")) { // check for slideshow
406 QString fileType = url.fileName().right(3);
408 QStringList::Iterator it;
410 QDir dir(url.directory());
412 filter << "*." + fileType;
413 filter << "*." + fileType.toUpper();
414 more = dir.entryList(filter, QDir::Files);
415 im.load(url.directory() + '/' + more.at(0));
416 } else im.load(url.path());
417 //pixmap = im.scaled(width, height);
421 double Render::consumerRatio() const
423 if (!m_mltConsumer) return 1.0;
424 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
428 int Render::getLength()
432 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
433 return mlt_producer_get_playtime(m_mltProducer->get_producer());
438 bool Render::isValid(KUrl url)
440 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
441 if (producer.is_blank())
447 double Render::dar() const
449 return m_mltProfile->dar();
453 void Render::slotSplitView(bool doit)
455 m_isSplitView = doit;
456 Mlt::Service service(m_mltProducer->parent().get_service());
457 Mlt::Tractor tractor(service);
458 if (service.type() != tractor_type || tractor.count() < 2) return;
459 Mlt::Field *field = tractor.field();
461 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
462 Mlt::Producer trackProducer(tractor.track(i));
463 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
464 if (QString(trackProducer.get("hide")).toInt() != 1) {
465 kDebug() << "// ADIDNG TRACK: " << i;
466 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
467 transition->set("mlt_service", "composite");
468 transition->set("a_track", 0);
469 transition->set("b_track", i);
470 transition->set("distort", 1);
471 transition->set("internal_added", "200");
478 tmp = "50%,0:50%x50%";
481 tmp = "0,50%:50%x50%";
485 tmp = "50%,50%:50%x50%";
488 transition->set("geometry", tmp);
489 transition->set("always_active", "1");
490 field->plant_transition(*transition, 0, i);
495 m_mltConsumer->set("refresh", 1);
497 mlt_service serv = m_mltProducer->parent().get_service();
498 mlt_service nextservice = mlt_service_get_producer(serv);
499 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
500 QString mlt_type = mlt_properties_get(properties, "mlt_type");
501 QString resource = mlt_properties_get(properties, "mlt_service");
503 while (mlt_type == "transition") {
504 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
505 if (added == "200") {
506 mlt_field_disconnect_service(field->get_field(), nextservice);
508 nextservice = mlt_service_producer(nextservice);
509 if (nextservice == NULL) break;
510 properties = MLT_SERVICE_PROPERTIES(nextservice);
511 mlt_type = mlt_properties_get(properties, "mlt_type");
512 resource = mlt_properties_get(properties, "mlt_service");
513 m_mltConsumer->set("refresh", 1);
518 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
520 KUrl url = KUrl(xml.attribute("resource", QString()));
521 Mlt::Producer *producer = NULL;
522 CLIPTYPE type = (CLIPTYPE)xml.attribute("type").toInt();
524 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
525 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
526 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
531 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
532 } else if (type == TEXT) {
533 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
534 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
535 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
536 } else if (url.isEmpty()) {
538 QDomElement mlt = doc.createElement("mlt");
539 QDomElement play = doc.createElement("playlist");
540 doc.appendChild(mlt);
541 mlt.appendChild(play);
542 play.appendChild(doc.importNode(xml, true));
543 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
545 producer = new Mlt::Producer(*m_mltProfile, url.path().toUtf8().constData());
548 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
549 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
550 emit removeInvalidClip(clipId, replaceProducer);
555 if (xml.hasAttribute("force_aspect_ratio")) {
556 double aspect = xml.attribute("force_aspect_ratio").toDouble();
557 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
560 if (xml.hasAttribute("force_aspect_num") && xml.hasAttribute("force_aspect_den")) {
561 int width = xml.attribute("frame_size").section('x', 0, 0).toInt();
562 int height = xml.attribute("frame_size").section('x', 1, 1).toInt();
563 int aspectNumerator = xml.attribute("force_aspect_num").toInt();
564 int aspectDenominator = xml.attribute("force_aspect_den").toInt();
565 if (aspectDenominator != 0 && width != 0)
566 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
569 if (xml.hasAttribute("force_fps")) {
570 double fps = xml.attribute("force_fps").toDouble();
571 if (fps > 0) producer->set("force_fps", fps);
574 if (xml.hasAttribute("force_progressive")) {
576 int progressive = xml.attribute("force_progressive").toInt(&ok);
577 if (ok) producer->set("force_progressive", progressive);
579 if (xml.hasAttribute("force_tff")) {
581 int fieldOrder = xml.attribute("force_tff").toInt(&ok);
582 if (ok) producer->set("force_tff", fieldOrder);
584 if (xml.hasAttribute("threads")) {
585 int threads = xml.attribute("threads").toInt();
586 if (threads != 1) producer->set("threads", threads);
588 if (xml.hasAttribute("video_index")) {
589 int vindex = xml.attribute("video_index").toInt();
590 if (vindex != 0) producer->set("video_index", vindex);
592 if (xml.hasAttribute("audio_index")) {
593 int aindex = xml.attribute("audio_index").toInt();
594 if (aindex != 0) producer->set("audio_index", aindex);
596 if (xml.hasAttribute("force_colorspace")) {
597 int colorspace = xml.attribute("force_colorspace").toInt();
598 if (colorspace != 0) producer->set("force_colorspace", colorspace);
600 if (xml.hasAttribute("full_luma")) {
601 int full_luma = xml.attribute("full_luma").toInt();
602 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
605 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
606 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW)
607 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
609 if (xml.hasAttribute("out"))
610 producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
612 producer->set("id", clipId.toUtf8().constData());
614 if (xml.hasAttribute("templatetext"))
615 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
617 if (!replaceProducer && xml.hasAttribute("file_hash")) {
618 // Clip already has all properties
619 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
623 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
624 QMap < QString, QString > filePropertyMap;
625 QMap < QString, QString > metadataPropertyMap;
627 int frameNumber = xml.attribute("thumbnail", "0").toInt();
628 if (frameNumber != 0) producer->seek(frameNumber);
630 filePropertyMap["duration"] = QString::number(producer->get_playtime());
631 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
633 Mlt::Frame *frame = producer->get_frame();
635 if (type == SLIDESHOW) {
636 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
637 if (ttl) producer->set("ttl", ttl);
638 if (!xml.attribute("animation").isEmpty()) {
639 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
640 if (filter && filter->is_valid()) {
642 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
643 if (!geometry.isEmpty()) {
644 if (xml.attribute("animation").contains("low-pass")) {
645 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
646 if (blur && blur->is_valid())
647 producer->attach(*blur);
649 filter->set("transition.geometry", geometry.toUtf8().data());
650 filter->set("transition.cycle", cycle);
651 producer->attach(*filter);
655 if (xml.attribute("fade") == "1") {
656 // user wants a fade effect to slideshow
657 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
658 if (filter && filter->is_valid()) {
659 if (ttl) filter->set("cycle", ttl);
660 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
661 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
662 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
663 if (xml.hasAttribute("softness")) {
664 int soft = xml.attribute("softness").toInt();
665 filter->set("luma.softness", (double) soft / 100.0);
668 producer->attach(*filter);
671 if (xml.attribute("crop") == "1") {
672 // user wants to center crop the slides
673 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
674 if (filter && filter->is_valid()) {
675 filter->set("center", 1);
676 producer->attach(*filter);
681 if (producer->get_double("meta.media.frame_rate_den") > 0) {
682 filePropertyMap["fps"] = QString::number(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
683 } else filePropertyMap["fps"] = producer->get("source_fps");
685 if (frame && frame->is_valid()) {
686 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
687 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
688 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
689 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
691 if (frame->get_int("test_image") == 0) {
692 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
693 filePropertyMap["type"] = "playlist";
694 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
695 } else if (frame->get_int("test_audio") == 0)
696 filePropertyMap["type"] = "av";
698 filePropertyMap["type"] = "video";
700 mlt_image_format format = mlt_image_rgb24a;
701 int frame_width = width;
702 int frame_height = imageHeight;
703 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
704 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied);
707 if (!image.isNull()) {
708 if (frame_width > (2 * width)) {
709 // there was a scaling problem, do it manually
710 QImage scaled = image.scaled(width, imageHeight);
711 pix = QPixmap::fromImage(scaled.rgbSwapped());
712 } else pix = QPixmap::fromImage(image.rgbSwapped());
716 emit replyGetImage(clipId, pix);
718 } else if (frame->get_int("test_audio") == 0) {
719 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
720 emit replyGetImage(clipId, pixmap);
721 filePropertyMap["type"] = "audio";
725 // Retrieve audio / video codec name
729 if (producer->get_int("video_index") > -1) {
730 /*if (context->duration == AV_NOPTS_VALUE) {
731 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
732 emit removeInvalidClip(clipId);
736 // Get the video_index
737 int default_video = producer->get_int("video_index");
739 int default_audio = producer->get_int("audio_index");
742 // Find maximum stream index values
743 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
744 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
745 QString type = producer->get(property);
748 else if (type == "audio")
751 filePropertyMap["default_video"] = QString::number(default_video);
752 filePropertyMap["video_max"] = QString::number(video_max);
753 filePropertyMap["default_audio"] = QString::number(default_audio);
754 filePropertyMap["audio_max"] = QString::number(audio_max);
756 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
757 if (producer->get(property)) {
758 filePropertyMap["videocodec"] = producer->get(property);
760 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
761 if (producer->get(property))
762 filePropertyMap["videocodec"] = producer->get(property);
765 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
766 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
767 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
769 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
770 if (producer->get_int("audio_index") > -1) {
771 // Get the audio_index
772 int index = producer->get_int("audio_index");
774 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
775 if (producer->get(property)) {
776 filePropertyMap["audiocodec"] = producer->get(property);
778 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
779 if (producer->get(property))
780 filePropertyMap["audiocodec"] = producer->get(property);
785 Mlt::Properties metadata;
786 metadata.pass_values(*producer, "meta.attr.");
787 int count = metadata.count();
788 for (int i = 0; i < count; i ++) {
789 QString name = metadata.get_name(i);
790 QString value = QString::fromUtf8(metadata.get(i));
791 if (name.endsWith("markup") && !value.isEmpty())
792 metadataPropertyMap[ name.section('.', 0, -2)] = value;
795 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
796 // FIXME: should delete this to avoid a leak...
802 /** Create the producer from the MLT XML QDomDocument */
803 void Render::initSceneList()
805 kDebug() << "-------- INIT SCENE LIST ------_";
807 QDomElement mlt = doc.createElement("mlt");
808 doc.appendChild(mlt);
809 QDomElement prod = doc.createElement("producer");
810 prod.setAttribute("resource", "colour");
811 prod.setAttribute("colour", "red");
812 prod.setAttribute("id", "black");
813 prod.setAttribute("in", "0");
814 prod.setAttribute("out", "0");
816 QDomElement tractor = doc.createElement("tractor");
817 QDomElement multitrack = doc.createElement("multitrack");
819 QDomElement playlist1 = doc.createElement("playlist");
820 playlist1.appendChild(prod);
821 multitrack.appendChild(playlist1);
822 QDomElement playlist2 = doc.createElement("playlist");
823 multitrack.appendChild(playlist2);
824 QDomElement playlist3 = doc.createElement("playlist");
825 multitrack.appendChild(playlist3);
826 QDomElement playlist4 = doc.createElement("playlist");
827 multitrack.appendChild(playlist4);
828 QDomElement playlist5 = doc.createElement("playlist");
829 multitrack.appendChild(playlist5);
830 tractor.appendChild(multitrack);
831 mlt.appendChild(tractor);
832 // kDebug()<<doc.toString();
834 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
835 setSceneList(doc, 0);
839 int Render::setProducer(Mlt::Producer *producer, int position)
841 if (m_winid == -1) return -1;
844 m_mltConsumer->stop();
847 m_mltConsumer->purge();
850 m_mltProducer->set_speed(0);
851 delete m_mltProducer;
852 m_mltProducer = NULL;
856 m_mltProducer = new Mlt::Producer(producer->get_producer());
857 } else m_mltProducer = m_blackClip->cut(0, 50);
859 if (!m_mltProducer || !m_mltProducer->is_valid()) {
860 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
863 int volume = KdenliveSettings::volume();
864 m_mltProducer->set("meta.volume", (double)volume / 100);
865 m_fps = m_mltProducer->get_fps();
866 int error = connectPlaylist();
868 if (position != -1) {
869 m_mltProducer->seek(position);
870 emit rendererPosition(position);
871 } else emit rendererPosition((int) m_mltProducer->position());
876 int Render::setSceneList(QDomDocument list, int position)
878 return setSceneList(list.toString(), position);
881 int Render::setSceneList(QString playlist, int position)
883 if (m_winid == -1) return -1;
887 //kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
890 if (!m_mltConsumer->is_stopped()) {
891 m_mltConsumer->stop();
893 m_mltConsumer->set("refresh", 0);
895 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
900 m_mltProducer->set_speed(0);
901 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
904 Mlt::Service service(m_mltProducer->parent().get_service());
905 mlt_service_lock(service.get_service());
907 if (service.type() == tractor_type) {
908 Mlt::Tractor tractor(service);
909 Mlt::Field *field = tractor.field();
910 mlt_service nextservice = mlt_service_get_producer(service.get_service());
911 mlt_service nextservicetodisconnect;
912 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
913 QString mlt_type = mlt_properties_get(properties, "mlt_type");
914 QString resource = mlt_properties_get(properties, "mlt_service");
915 // Delete all transitions
916 while (mlt_type == "transition") {
917 nextservicetodisconnect = nextservice;
918 nextservice = mlt_service_producer(nextservice);
919 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
920 if (nextservice == NULL) break;
921 properties = MLT_SERVICE_PROPERTIES(nextservice);
922 mlt_type = mlt_properties_get(properties, "mlt_type");
923 resource = mlt_properties_get(properties, "mlt_service");
926 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
927 Mlt::Producer trackProducer(tractor.track(trackNb));
928 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
929 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
933 mlt_service_unlock(service.get_service());
935 qDeleteAll(m_slowmotionProducers.values());
936 m_slowmotionProducers.clear();
938 delete m_mltProducer;
939 m_mltProducer = NULL;
945 // TODO: Better way to do this
946 if (KdenliveSettings::projectloading_avformatnovalidate())
947 playlist.replace(">avformat</property>", ">avformat-novalidate</property>");
949 playlist.replace(">avformat-novalidate</property>", ">avformat</property>");
951 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
953 if (!m_mltProducer || !m_mltProducer->is_valid()) {
954 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
955 m_mltProducer = m_blackClip->cut(0, 50);
958 int volume = KdenliveSettings::volume();
959 m_mltProducer->set("meta.volume", (double)volume / 100);
960 m_mltProducer->optimise();
962 /*if (KdenliveSettings::osdtimecode()) {
963 // Attach filter for on screen display of timecode
965 QString attr = "attr_check";
966 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
967 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
968 mlt_producer_attach( m_mltProducer->get_producer(), filter );
969 mlt_filter_close( filter );
971 m_osdInfo = new Mlt::Filter("data_show");
972 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
973 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
974 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
975 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
976 m_osdInfo->set("dynamic", "1");
978 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
980 m_osdInfo->set("dynamic", "0");
983 m_fps = m_mltProducer->get_fps();
985 // Seek to correct place after opening project.
986 m_mltProducer->seek(position);
989 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
990 if (error == 0) error = connectPlaylist();
991 else connectPlaylist();
992 fillSlowMotionProducers();
998 //kDebug()<<"// SETSCN LST, POS: "<<position;
999 //if (position != 0) emit rendererPosition(position);
1002 const QString Render::sceneList()
1005 Mlt::Profile profile((mlt_profile) 0);
1006 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1007 m_mltProducer->optimise();
1008 xmlConsumer.set("terminate_on_pause", 1);
1009 Mlt::Producer prod(m_mltProducer->get_producer());
1010 bool split = m_isSplitView;
1011 if (split) slotSplitView(false);
1012 xmlConsumer.connect(prod);
1013 xmlConsumer.start();
1014 while (!xmlConsumer.is_stopped()) {}
1015 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1016 if (split) slotSplitView(true);
1020 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1024 doc.setContent(sceneList(), false);
1025 if (!kdenliveData.isNull()) {
1026 // add Kdenlive specific tags
1027 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1028 mlt.appendChild(doc.importNode(kdenliveData, true));
1030 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1031 kWarning() << "////// ERROR writing to file: " << path;
1034 file.write(doc.toString().toUtf8());
1035 if (file.error() != QFile::NoError) {
1043 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1045 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1046 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1047 m_mltProducer->optimise();
1048 xmlConsumer.set("terminate_on_pause", 1);
1049 if (m_name == "clip") {
1050 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1052 list.insert_at(0, prod, 0);
1054 list.set("title", desc.toUtf8().constData());
1055 xmlConsumer.connect(list);
1058 //TODO: not working yet, save zone from timeline
1059 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1060 /* Mlt::Service service(p1->parent().get_service());
1061 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1063 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1064 //prod->set("title", desc.toUtf8().constData());
1065 xmlConsumer.connect(*p1); //list);
1068 xmlConsumer.start();
1071 double Render::fps() const
1076 int Render::connectPlaylist()
1078 if (!m_mltConsumer) return -1;
1079 //m_mltConsumer->set("refresh", "0");
1080 m_mltConsumer->connect(*m_mltProducer);
1081 m_mltProducer->set_speed(0);
1082 if (m_mltConsumer->start() == -1) {
1083 // ARGH CONSUMER BROKEN!!!!
1084 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."));
1085 delete m_mltConsumer;
1086 m_mltConsumer = NULL;
1089 emit durationChanged(m_mltProducer->get_playtime());
1094 void Render::refreshDisplay()
1097 if (!m_mltProducer) return;
1098 //m_mltConsumer->set("refresh", 0);
1100 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1101 /*if (KdenliveSettings::osdtimecode()) {
1102 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1103 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1104 m_osdInfo->set("dynamic", "1");
1105 m_mltProducer->attach(*m_osdInfo);
1108 m_mltProducer->detach(*m_osdInfo);
1109 m_osdInfo->set("dynamic", "0");
1114 int Render::volume() const
1116 if (!m_mltConsumer || !m_mltProducer) return -1;
1117 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1120 void Render::slotSetVolume(int volume)
1122 if (!m_mltConsumer || !m_mltProducer) return;
1123 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1126 m_mltConsumer->set("refresh", 0);
1127 // Attach filter for on screen display of timecode
1128 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1129 mlt_properties_set_double( properties, "meta.volume", volume );
1130 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1131 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1133 if (!KdenliveSettings::osdtimecode()) {
1134 m_mltProducer->detach(*m_osdInfo);
1135 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1136 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1139 //m_osdTimer->setSingleShot(2500);
1142 void Render::slotOsdTimeout()
1144 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1145 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1146 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1147 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1151 void Render::start()
1153 kDebug() << "----- STARTING MONITOR: " << m_name;
1154 if (m_winid == -1) {
1155 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1158 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1159 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1160 if (m_mltConsumer->start() == -1) {
1161 //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."));
1162 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1164 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1165 m_isBlocked = false;
1169 m_isBlocked = false;
1174 if (m_mltProducer == NULL) return;
1175 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1176 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1178 //m_mltConsumer->set("refresh", 0);
1179 m_mltConsumer->stop();
1180 // delete m_mltConsumer;
1181 // m_mltConsumer = NULL;
1183 kDebug() << "///////////// RENDER STOP2-------";
1186 if (m_mltProducer) {
1187 if (m_isZoneMode) resetZoneMode();
1188 m_mltProducer->set_speed(0.0);
1189 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1190 //kDebug() << m_mltProducer->get_length();
1192 kDebug() << "///////////// RENDER STOP3-------";
1195 void Render::stop(const GenTime & startTime)
1198 kDebug() << "///////////// RENDER STOP-------2";
1199 if (m_mltProducer) {
1200 if (m_isZoneMode) resetZoneMode();
1201 m_mltProducer->set_speed(0.0);
1202 m_mltProducer->seek((int) startTime.frames(m_fps));
1204 m_mltConsumer->purge();
1207 void Render::pause()
1209 if (!m_mltProducer || !m_mltConsumer)
1211 if (m_mltProducer->get_speed() == 0.0) return;
1212 if (m_isZoneMode) resetZoneMode();
1214 m_mltConsumer->set("refresh", 0);
1215 m_mltProducer->set_speed(0.0);
1217 The 2 lines below create a flicker loop
1218 emit rendererPosition(m_framePosition);
1219 m_mltProducer->seek(m_framePosition);*/
1220 m_mltConsumer->purge();
1223 void Render::switchPlay()
1225 if (!m_mltProducer || !m_mltConsumer)
1227 if (m_isZoneMode) resetZoneMode();
1228 if (m_mltProducer->get_speed() == 0.0) {
1229 m_isBlocked = false;
1230 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1231 m_mltProducer->set_speed(1.0);
1232 m_mltConsumer->set("refresh", 1);
1235 m_mltConsumer->set("refresh", 0);
1236 m_mltProducer->set_speed(0.0);
1237 //emit rendererPosition(m_framePosition);
1238 m_mltProducer->seek(m_framePosition);
1239 m_mltConsumer->purge();
1240 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1241 //m_mltConsumer->set("refresh", 0);
1242 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1243 m_mltProducer->set_speed(0);
1244 m_mltProducer->seek( position );
1245 //m_mltProducer->seek((int) m_framePosition);
1246 m_isBlocked = false;*/
1248 /*if (speed == 0.0) {
1249 m_mltProducer->seek((int) m_framePosition + 1);
1250 m_mltConsumer->purge();
1255 void Render::play(double speed)
1259 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1260 m_isBlocked = false;
1261 m_mltProducer->set_speed(speed);
1262 /*if (speed == 0.0) {
1263 m_mltProducer->seek((int) m_framePosition + 1);
1264 m_mltConsumer->purge();
1269 void Render::play(const GenTime & startTime)
1271 if (!m_mltProducer || !m_mltConsumer)
1273 m_isBlocked = false;
1274 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1275 m_mltProducer->set_speed(1.0);
1276 m_mltConsumer->set("refresh", 1);
1279 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1281 if (!m_mltProducer || !m_mltConsumer)
1283 //m_mltProducer->set("eof", "loop");
1284 m_isLoopMode = true;
1285 m_loopStart = startTime;
1286 playZone(startTime, stopTime);
1289 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1291 if (!m_mltProducer || !m_mltConsumer)
1293 m_isBlocked = false;
1294 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1295 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1296 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1297 m_mltProducer->set_speed(1.0);
1298 m_mltConsumer->set("refresh", 1);
1299 m_isZoneMode = true;
1302 void Render::resetZoneMode()
1304 if (!m_isZoneMode && !m_isLoopMode) return;
1305 m_mltProducer->set("out", m_originalOut);
1306 //m_mltProducer->set("eof", "pause");
1307 m_isZoneMode = false;
1308 m_isLoopMode = false;
1311 void Render::seekToFrame(int pos)
1313 //kDebug()<<" ********* RENDER SEEK TO POS";
1316 m_isBlocked = false;
1318 m_mltProducer->seek(pos);
1322 void Render::seekToFrameDiff(int diff)
1324 //kDebug()<<" ********* RENDER SEEK TO POS";
1327 m_isBlocked = false;
1329 m_mltProducer->seek(m_mltProducer->position() + diff);
1333 void Render::doRefresh()
1335 // Use a Timer so that we don't refresh too much
1336 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1339 void Render::refresh()
1341 if (!m_mltProducer || m_isBlocked)
1343 if (m_mltConsumer) {
1344 m_mltConsumer->set("refresh", 1);
1348 void Render::setDropFrames(bool show)
1350 if (m_mltConsumer) {
1352 if (show == false) dropFrames = 0;
1353 m_mltConsumer->stop();
1355 m_mltConsumer->set("real_time", dropFrames);
1357 m_mltConsumer->set("play.real_time", dropFrames);
1359 if (m_mltConsumer->start() == -1) {
1360 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1366 double Render::playSpeed()
1368 if (m_mltProducer) return m_mltProducer->get_speed();
1372 GenTime Render::seekPosition() const
1374 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1375 else return GenTime();
1378 int Render::seekFramePosition() const
1380 if (m_mltProducer) return (int) m_mltProducer->position();
1384 const QString & Render::rendererName() const
1389 void Render::emitFrameUpdated(Mlt::Frame& frame)
1391 mlt_image_format format = mlt_image_rgb24a;
1394 const uchar* image = frame.get_image(format, width, height);
1395 QImage qimage(width, height, QImage::Format_ARGB32);
1396 memcpy(qimage.bits(), image, width * height * 4);
1397 emit frameUpdated(qimage.rgbSwapped());
1400 void Render::emitFrameNumber(double position)
1402 m_framePosition = position;
1403 emit rendererPosition((int) position);
1406 void Render::emitConsumerStopped()
1408 // This is used to know when the playing stopped
1409 if (m_mltProducer) {
1410 double pos = m_mltProducer->position();
1411 if (m_isLoopMode) play(m_loopStart);
1412 else if (m_isZoneMode) resetZoneMode();
1413 emit rendererStopped((int) pos);
1417 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1419 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1422 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1424 if (!m_mltProducer) {
1425 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1429 //int height = 1080;//KdenliveSettings::defaultheight();
1430 //int width = 1940; //KdenliveSettings::displaywidth();
1432 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1434 QPixmap pix(width, height);
1435 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1436 m_convert.set("forced", mlt_image_rgb24a);
1437 m_mltProducer->attach(m_convert);
1438 Mlt::Frame * frame = m_mltProducer->get_frame();
1439 m_mltProducer->detach(m_convert);
1441 pix = frameThumbnail(frame, width, height);
1444 pix.save(url.path(), "PNG");
1445 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1449 void Render::showFrame(Mlt::Frame& frame)
1451 m_framePosition = qMax(frame.get_int("_position"), 0);
1452 emit rendererPosition((int) m_framePosition);
1453 mlt_image_format format = mlt_image_rgb24a;
1456 const uchar* image = frame.get_image(format, width, height);
1457 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1458 memcpy(qimage.scanLine(0), image, width * height * 4);
1459 emit showImageSignal(qimage);
1460 if (analyseAudio) showAudio(frame);
1461 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1462 emit frameUpdated(qimage.rgbSwapped());
1466 void Render::showAudio(Mlt::Frame& frame)
1468 if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
1469 mlt_audio_format audio_format = mlt_audio_s16;
1471 int num_channels = 0;
1473 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1476 int num_samples = samples > 200 ? 200 : samples;
1477 QByteArray channels;
1478 for (int i = 0; i < num_channels; i++) {
1480 for (int s = 0; s < num_samples; s ++) {
1481 val += abs(data[i+s*num_channels] / 128);
1483 channels.append(val / num_samples);
1488 emit showAudioSignal(channels);
1490 emit showAudioSignal(QByteArray());
1494 * MLT playlist direct manipulation.
1497 void Render::mltCheckLength(Mlt::Tractor *tractor)
1499 //kDebug()<<"checking track length: "<<track<<"..........";
1501 int trackNb = tractor->count();
1505 Mlt::Producer trackProducer(tractor->track(0));
1506 duration = trackProducer.get_playtime() - 1;
1507 m_mltProducer->set("out", duration);
1508 emit durationChanged(duration);
1511 while (trackNb > 1) {
1512 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1513 trackDuration = trackProducer.get_playtime() - 1;
1514 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1515 if (trackDuration > duration) duration = trackDuration;
1519 Mlt::Producer blackTrackProducer(tractor->track(0));
1521 if (blackTrackProducer.get_playtime() - 1 != duration) {
1522 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1523 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1524 if (blackclip && blackclip->is_blank()) {
1529 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1530 blackTrackPlaylist.clear();
1531 m_blackClip->set("length", duration + 1);
1532 m_blackClip->set("out", duration);
1533 blackclip = m_blackClip->cut(0, duration);
1534 blackTrackPlaylist.insert_at(0, blackclip, 1);
1536 if (duration > blackclip->parent().get_length()) {
1537 blackclip->parent().set("length", duration + 1);
1538 blackclip->parent().set("out", duration);
1539 blackclip->set("length", duration + 1);
1541 blackTrackPlaylist.resize_clip(0, 0, duration);
1545 m_mltProducer->set("out", duration);
1546 emit durationChanged(duration);
1550 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1552 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1554 // We want a slowmotion producer
1555 double speed = element.attribute("speed", "1.0").toDouble();
1556 int strobe = element.attribute("strobe", "1").toInt();
1557 QString url = QString::fromUtf8(prod->get("resource"));
1558 url.append('?' + QString::number(speed));
1559 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1560 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1561 if (!slowprod || slowprod->get_producer() == NULL) {
1562 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1563 if (strobe > 1) slowprod->set("strobe", strobe);
1564 QString id = prod->get("id");
1565 if (id.contains('_')) id = id.section('_', 0, 0);
1566 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1567 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1568 slowprod->set("id", producerid.toUtf8().constData());
1569 m_slowmotionProducers.insert(url, slowprod);
1574 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1576 if (m_mltProducer == NULL) {
1577 kDebug() << "PLAYLIST NOT INITIALISED //////";
1581 kDebug() << "Cannot insert clip without producer //////";
1584 Mlt::Producer parentProd(m_mltProducer->parent());
1585 if (parentProd.get_producer() == NULL) {
1586 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1590 Mlt::Service service(parentProd.get_service());
1591 if (service.type() != tractor_type) {
1592 kWarning() << "// TRACTOR PROBLEM";
1595 Mlt::Tractor tractor(service);
1596 if (info.track > tractor.count() - 1) {
1597 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1600 mlt_service_lock(service.get_service());
1601 Mlt::Producer trackProducer(tractor.track(info.track));
1602 int trackDuration = trackProducer.get_playtime() - 1;
1603 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1604 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1605 prod = checkSlowMotionProducer(prod, element);
1606 if (prod == NULL || !prod->is_valid()) {
1607 mlt_service_unlock(service.get_service());
1611 int cutPos = (int) info.cropStart.frames(m_fps);
1612 if (cutPos < 0) cutPos = 0;
1613 int insertPos = (int) info.startPos.frames(m_fps);
1614 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1615 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1616 if (overwrite && (insertPos < trackDuration)) {
1617 // Replace zone with blanks
1618 //trackPlaylist.split_at(insertPos, true);
1619 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1620 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1621 trackPlaylist.insert_blank(clipIndex, cutDuration);
1623 trackPlaylist.split_at(insertPos, true);
1624 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1625 trackPlaylist.insert_blank(clipIndex, cutDuration);
1627 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1629 /*if (QString(prod->get("transparency")).toInt() == 1)
1630 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1632 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1633 mlt_service_unlock(service.get_service());
1634 /*tractor.multitrack()->refresh();
1635 tractor.refresh();*/
1640 void Render::mltCutClip(int track, GenTime position)
1644 Mlt::Service service(m_mltProducer->parent().get_service());
1645 if (service.type() != tractor_type) {
1646 kWarning() << "// TRACTOR PROBLEM";
1650 Mlt::Tractor tractor(service);
1651 Mlt::Producer trackProducer(tractor.track(track));
1652 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1655 /* // Display playlist info
1656 kDebug()<<"//////////// BEFORE";
1657 for (int i = 0; i < trackPlaylist.count(); i++) {
1658 int blankStart = trackPlaylist.clip_start(i);
1659 int blankDuration = trackPlaylist.clip_length(i) - 1;
1661 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1662 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1665 int cutPos = (int) position.frames(m_fps);
1667 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1668 if (trackPlaylist.is_blank(clipIndex)) {
1669 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1670 m_isBlocked = false;
1673 mlt_service_lock(service.get_service());
1674 int clipStart = trackPlaylist.clip_start(clipIndex);
1675 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1676 mlt_service_unlock(service.get_service());
1678 // duplicate effects
1679 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1680 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1682 if (original == NULL || clip == NULL) {
1683 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1685 Mlt::Service clipService(original->get_service());
1686 Mlt::Service dupService(clip->get_service());
1690 Mlt::Filter *filter = clipService.filter(ct);
1692 // Only duplicate Kdenlive filters, and skip the fade in effects
1693 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1694 // looks like there is no easy way to duplicate a filter,
1695 // so we will create a new one and duplicate its properties
1696 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1697 if (dup && dup->is_valid()) {
1698 Mlt::Properties entries(filter->get_properties());
1699 for (int i = 0; i < entries.count(); i++) {
1700 dup->set(entries.get_name(i), entries.get(i));
1702 dupService.attach(*dup);
1706 filter = clipService.filter(ct);
1709 /* // Display playlist info
1710 kDebug()<<"//////////// AFTER";
1711 for (int i = 0; i < trackPlaylist.count(); i++) {
1712 int blankStart = trackPlaylist.clip_start(i);
1713 int blankDuration = trackPlaylist.clip_length(i) - 1;
1715 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1716 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1719 m_isBlocked = false;
1722 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1726 kDebug() << "Cannot update clip with null producer //////";
1729 Mlt::Service service(m_mltProducer->parent().get_service());
1730 if (service.type() != tractor_type) {
1731 kWarning() << "// TRACTOR PROBLEM";
1734 Mlt::Tractor tractor(service);
1735 Mlt::Producer trackProducer(tractor.track(info.track));
1736 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1737 int startPos = info.startPos.frames(m_fps);
1738 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1739 if (trackPlaylist.is_blank(clipIndex)) {
1740 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1743 mlt_service_lock(service.get_service());
1744 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1746 QList <Mlt::Filter *> filtersList;
1747 Mlt::Service sourceService(clip->get_service());
1749 Mlt::Filter *filter = sourceService.filter(ct);
1751 if (filter->get_int("kdenlive_ix") != 0) {
1752 filtersList.append(filter);
1755 filter = sourceService.filter(ct);
1758 trackPlaylist.replace_with_blank(clipIndex);
1760 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1761 prod = checkSlowMotionProducer(prod, element);
1762 if (prod == NULL || !prod->is_valid()) {
1763 mlt_service_unlock(service.get_service());
1766 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1767 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1771 //if (mltInsertClip(info, element, prod) == -1) return false;
1772 if (!filtersList.isEmpty()) {
1773 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1774 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1775 Mlt::Service destService(destclip->get_service());
1777 for (int i = 0; i < filtersList.count(); i++)
1778 destService.attach(*(filtersList.at(i)));
1780 mlt_service_unlock(service.get_service());
1785 bool Render::mltRemoveClip(int track, GenTime position)
1787 Mlt::Service service(m_mltProducer->parent().get_service());
1788 if (service.type() != tractor_type) {
1789 kWarning() << "// TRACTOR PROBLEM";
1793 Mlt::Tractor tractor(service);
1794 mlt_service_lock(service.get_service());
1795 Mlt::Producer trackProducer(tractor.track(track));
1796 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1797 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1799 // Display playlist info
1800 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1801 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1802 int blankStart = trackPlaylist.clip_start(i);
1803 int blankDuration = trackPlaylist.clip_length(i) - 1;
1805 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1806 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1808 if (trackPlaylist.is_blank(clipIndex)) {
1809 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1810 mlt_service_unlock(service.get_service());
1813 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1815 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1816 if (clip) delete clip;
1817 trackPlaylist.consolidate_blanks(0);
1818 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1819 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1821 /* // Display playlist info
1822 kDebug()<<"//// AFTER";
1823 for (int i = 0; i < trackPlaylist.count(); i++) {
1824 int blankStart = trackPlaylist.clip_start(i);
1825 int blankDuration = trackPlaylist.clip_length(i) - 1;
1827 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1828 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1830 mlt_service_unlock(service.get_service());
1831 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1832 m_isBlocked = false;
1836 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1838 if (!m_mltProducer) {
1839 kDebug() << "PLAYLIST NOT INITIALISED //////";
1842 Mlt::Producer parentProd(m_mltProducer->parent());
1843 if (parentProd.get_producer() == NULL) {
1844 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1848 Mlt::Service service(parentProd.get_service());
1849 Mlt::Tractor tractor(service);
1850 int insertPos = pos.frames(m_fps);
1852 Mlt::Producer trackProducer(tractor.track(track));
1853 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1854 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1855 if (clipIndex == trackPlaylist.count()) {
1856 // We are after the end of the playlist
1859 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1860 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1861 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1864 int Render::mltTrackDuration(int track)
1866 if (!m_mltProducer) {
1867 kDebug() << "PLAYLIST NOT INITIALISED //////";
1870 Mlt::Producer parentProd(m_mltProducer->parent());
1871 if (parentProd.get_producer() == NULL) {
1872 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1876 Mlt::Service service(parentProd.get_service());
1877 Mlt::Tractor tractor(service);
1879 Mlt::Producer trackProducer(tractor.track(track));
1880 return trackProducer.get_playtime() - 1;
1883 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1885 if (!m_mltProducer) {
1886 kDebug() << "PLAYLIST NOT INITIALISED //////";
1889 Mlt::Producer parentProd(m_mltProducer->parent());
1890 if (parentProd.get_producer() == NULL) {
1891 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1894 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1895 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1897 Mlt::Service service(parentProd.get_service());
1898 Mlt::Tractor tractor(service);
1899 mlt_service_lock(service.get_service());
1900 int diff = duration.frames(m_fps);
1901 int offset = timeOffset.frames(m_fps);
1905 // insert space in one track only
1906 Mlt::Producer trackProducer(tractor.track(track));
1907 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1908 insertPos = trackClipStartList.value(track);
1909 if (insertPos != -1) {
1910 insertPos += offset;
1911 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1913 trackPlaylist.insert_blank(clipIndex, diff - 1);
1915 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1916 if (!trackPlaylist.is_blank(clipIndex)) {
1917 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1919 int position = trackPlaylist.clip_start(clipIndex);
1920 int blankDuration = trackPlaylist.clip_length(clipIndex);
1922 if (blankDuration - diff == 0) {
1923 trackPlaylist.remove(clipIndex);
1924 } else trackPlaylist.remove_region(position, diff);
1926 trackPlaylist.consolidate_blanks(0);
1928 // now move transitions
1929 mlt_service serv = m_mltProducer->parent().get_service();
1930 mlt_service nextservice = mlt_service_get_producer(serv);
1931 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1932 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1933 QString resource = mlt_properties_get(properties, "mlt_service");
1935 while (mlt_type == "transition") {
1936 mlt_transition tr = (mlt_transition) nextservice;
1937 int currentTrack = mlt_transition_get_b_track(tr);
1938 int currentIn = (int) mlt_transition_get_in(tr);
1939 int currentOut = (int) mlt_transition_get_out(tr);
1940 insertPos = trackTransitionStartList.value(track);
1941 if (insertPos != -1) {
1942 insertPos += offset;
1943 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1944 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1947 nextservice = mlt_service_producer(nextservice);
1948 if (nextservice == NULL) break;
1949 properties = MLT_SERVICE_PROPERTIES(nextservice);
1950 mlt_type = mlt_properties_get(properties, "mlt_type");
1951 resource = mlt_properties_get(properties, "mlt_service");
1954 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1955 Mlt::Producer trackProducer(tractor.track(trackNb));
1956 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1958 //int clipNb = trackPlaylist.count();
1959 insertPos = trackClipStartList.value(trackNb);
1960 if (insertPos != -1) {
1961 insertPos += offset;
1963 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1964 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1965 for (int i = 0; i < clipNb; i++) {
1966 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1967 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1968 kDebug()<<"-------------";
1970 kDebug()<<"END-------------";*/
1973 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1975 trackPlaylist.insert_blank(clipIndex, diff - 1);
1977 if (!trackPlaylist.is_blank(clipIndex)) {
1980 if (!trackPlaylist.is_blank(clipIndex)) {
1981 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1983 int position = trackPlaylist.clip_start(clipIndex);
1984 int blankDuration = trackPlaylist.clip_length(clipIndex);
1985 if (diff + blankDuration == 0) {
1986 trackPlaylist.remove(clipIndex);
1987 } else trackPlaylist.remove_region(position, - diff);
1989 trackPlaylist.consolidate_blanks(0);
1992 // now move transitions
1993 mlt_service serv = m_mltProducer->parent().get_service();
1994 mlt_service nextservice = mlt_service_get_producer(serv);
1995 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1996 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1997 QString resource = mlt_properties_get(properties, "mlt_service");
1999 while (mlt_type == "transition") {
2000 mlt_transition tr = (mlt_transition) nextservice;
2001 int currentIn = (int) mlt_transition_get_in(tr);
2002 int currentOut = (int) mlt_transition_get_out(tr);
2003 int currentTrack = mlt_transition_get_b_track(tr);
2004 insertPos = trackTransitionStartList.value(currentTrack);
2005 if (insertPos != -1) {
2006 insertPos += offset;
2007 if (currentOut > insertPos && resource != "mix") {
2008 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2011 nextservice = mlt_service_producer(nextservice);
2012 if (nextservice == NULL) break;
2013 properties = MLT_SERVICE_PROPERTIES(nextservice);
2014 mlt_type = mlt_properties_get(properties, "mlt_type");
2015 resource = mlt_properties_get(properties, "mlt_service");
2018 mlt_service_unlock(service.get_service());
2019 mltCheckLength(&tractor);
2020 m_mltConsumer->set("refresh", 1);
2024 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2026 if (source == dest) return;
2027 Mlt::Service sourceService(source->get_service());
2028 Mlt::Service destService(dest->get_service());
2030 // move all effects to the correct producer
2032 Mlt::Filter *filter = sourceService.filter(ct);
2034 if (filter->get_int("kdenlive_ix") != 0) {
2035 sourceService.detach(*filter);
2036 destService.attach(*filter);
2038 filter = sourceService.filter(ct);
2042 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2046 Mlt::Service service(m_mltProducer->parent().get_service());
2047 if (service.type() != tractor_type) {
2048 kWarning() << "// TRACTOR PROBLEM";
2051 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2052 Mlt::Tractor tractor(service);
2053 Mlt::Producer trackProducer(tractor.track(info.track));
2054 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2055 int startPos = info.startPos.frames(m_fps);
2056 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2057 int clipLength = trackPlaylist.clip_length(clipIndex);
2059 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2060 if (original == NULL) {
2063 if (!original->is_valid() || original->is_blank()) {
2068 Mlt::Producer clipparent = original->parent();
2069 if (!clipparent.is_valid() || clipparent.is_blank()) {
2075 QString serv = clipparent.get("mlt_service");
2076 QString id = clipparent.get("id");
2077 if (speed <= 0 && speed > -1) speed = 1.0;
2078 //kDebug() << "CLIP SERVICE: " << serv;
2079 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2080 mlt_service_lock(service.get_service());
2081 QString url = QString::fromUtf8(clipparent.get("resource"));
2082 url.append('?' + QString::number(speed));
2083 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2084 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2085 if (!slowprod || slowprod->get_producer() == NULL) {
2086 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2087 if (strobe > 1) slowprod->set("strobe", strobe);
2088 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2089 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2090 slowprod->set("id", producerid.toUtf8().constData());
2091 // copy producer props
2092 double ar = original->parent().get_double("force_aspect_ratio");
2093 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2094 double fps = original->parent().get_double("force_fps");
2095 if (fps != 0.0) slowprod->set("force_fps", fps);
2096 int threads = original->parent().get_int("threads");
2097 if (threads != 0) slowprod->set("threads", threads);
2098 if (original->parent().get("force_progressive"))
2099 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2100 if (original->parent().get("force_tff"))
2101 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2102 int ix = original->parent().get_int("video_index");
2103 if (ix != 0) slowprod->set("video_index", ix);
2104 int colorspace = original->parent().get_int("force_colorspace");
2105 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2106 int full_luma = original->parent().get_int("set.force_full_luma");
2107 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2108 m_slowmotionProducers.insert(url, slowprod);
2110 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2111 trackPlaylist.consolidate_blanks(0);
2113 // Check that the blank space is long enough for our new duration
2114 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2115 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2117 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2118 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2119 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2120 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2122 // move all effects to the correct producer
2123 mltPasteEffects(clip, cut);
2124 trackPlaylist.insert_at(startPos, cut, 1);
2127 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2128 newLength = trackPlaylist.clip_length(clipIndex);
2129 mlt_service_unlock(service.get_service());
2130 } else if (speed == 1.0 && strobe < 2) {
2131 mlt_service_lock(service.get_service());
2133 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2134 trackPlaylist.consolidate_blanks(0);
2136 // Check that the blank space is long enough for our new duration
2137 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2138 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2141 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2142 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2143 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2144 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2145 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2147 // move all effects to the correct producer
2148 mltPasteEffects(clip, cut);
2150 trackPlaylist.insert_at(startPos, cut, 1);
2153 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2154 newLength = trackPlaylist.clip_length(clipIndex);
2155 mlt_service_unlock(service.get_service());
2157 } else if (serv == "framebuffer") {
2158 mlt_service_lock(service.get_service());
2159 QString url = QString::fromUtf8(clipparent.get("resource"));
2160 url = url.section('?', 0, 0);
2161 url.append('?' + QString::number(speed));
2162 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2163 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2164 if (!slowprod || slowprod->get_producer() == NULL) {
2165 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2166 slowprod->set("strobe", strobe);
2167 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2168 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2169 slowprod->set("id", producerid.toUtf8().constData());
2170 // copy producer props
2171 double ar = original->parent().get_double("force_aspect_ratio");
2172 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2173 double fps = original->parent().get_double("force_fps");
2174 if (fps != 0.0) slowprod->set("force_fps", fps);
2175 if (original->parent().get("force_progressive"))
2176 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2177 if (original->parent().get("force_tff"))
2178 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2179 int threads = original->parent().get_int("threads");
2180 if (threads != 0) slowprod->set("threads", threads);
2181 int ix = original->parent().get_int("video_index");
2182 if (ix != 0) slowprod->set("video_index", ix);
2183 int colorspace = original->parent().get_int("force_colorspace");
2184 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2185 int full_luma = original->parent().get_int("set.force_full_luma");
2186 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2187 m_slowmotionProducers.insert(url, slowprod);
2189 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2190 trackPlaylist.consolidate_blanks(0);
2192 GenTime duration = speedIndependantInfo.cropDuration / speed;
2193 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2195 // Check that the blank space is long enough for our new duration
2196 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2197 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2200 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2201 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2202 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2203 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2205 // move all effects to the correct producer
2206 mltPasteEffects(clip, cut);
2208 trackPlaylist.insert_at(startPos, cut, 1);
2211 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2212 newLength = trackPlaylist.clip_length(clipIndex);
2214 mlt_service_unlock(service.get_service());
2217 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2218 m_isBlocked = false;
2222 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2224 Mlt::Service service(m_mltProducer->parent().get_service());
2225 bool success = false;
2226 Mlt::Tractor tractor(service);
2227 Mlt::Producer trackProducer(tractor.track(track));
2228 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2229 Mlt::Service clipService(trackPlaylist.get_service());
2232 mlt_service_lock(service.get_service());
2234 Mlt::Filter *filter = clipService.filter(ct);
2236 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2237 if (clipService.detach(*filter) == 0) success = true;
2238 } else if (updateIndex) {
2239 // Adjust the other effects index
2240 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2243 filter = clipService.filter(ct);
2245 m_isBlocked = false;
2246 mlt_service_unlock(service.get_service());
2251 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2253 if (position < GenTime()) {
2254 // Remove track effect
2255 return mltRemoveTrackEffect(track, index, updateIndex);
2257 Mlt::Service service(m_mltProducer->parent().get_service());
2258 bool success = false;
2259 Mlt::Tractor tractor(service);
2260 Mlt::Producer trackProducer(tractor.track(track));
2261 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2263 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2264 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2266 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2270 Mlt::Service clipService(clip->get_service());
2271 int duration = clip->get_playtime();
2273 // Check if clip is visible in monitor
2274 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2275 if (diff < 0 || diff > duration) doRefresh = false;
2279 // if (tag.startsWith("ladspa")) tag = "ladspa";
2281 mlt_service_lock(service.get_service());
2283 Mlt::Filter *filter = clipService.filter(ct);
2285 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2286 if (clipService.detach(*filter) == 0) success = true;
2287 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2288 } else if (updateIndex) {
2289 // Adjust the other effects index
2290 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2293 filter = clipService.filter(ct);
2295 m_isBlocked = false;
2296 mlt_service_unlock(service.get_service());
2297 if (doRefresh) refresh();
2301 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2303 Mlt::Service service(m_mltProducer->parent().get_service());
2304 Mlt::Tractor tractor(service);
2305 Mlt::Producer trackProducer(tractor.track(track));
2306 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2307 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2308 return mltAddEffect(trackService, params, 15000, true);
2312 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2315 Mlt::Service service(m_mltProducer->parent().get_service());
2317 Mlt::Tractor tractor(service);
2318 Mlt::Producer trackProducer(tractor.track(track));
2319 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2321 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2322 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2327 Mlt::Service clipService(clip->get_service());
2328 int duration = clip->get_playtime();
2330 // Check if clip is visible in monitor
2331 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2332 if (diff < 0 || diff > duration) doRefresh = false;
2335 return mltAddEffect(clipService, params, duration, doRefresh);
2338 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2340 bool updateIndex = false;
2341 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2342 const QString region = params.paramValue("region");
2345 mlt_service_lock(service.get_service());
2347 Mlt::Filter *filter = service.filter(ct);
2349 if (filter->get_int("kdenlive_ix") == filter_ix) {
2350 // A filter at that position already existed, so we will increase all indexes later
2355 filter = service.filter(ct);
2358 if (params.paramValue("id") == "speed") {
2359 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2361 filter = service.filter(ct);
2363 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2364 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2367 filter = service.filter(ct);
2369 m_isBlocked = false;
2370 mlt_service_unlock(service.get_service());
2371 if (doRefresh) refresh();
2376 // temporarily remove all effects after insert point
2377 QList <Mlt::Filter *> filtersList;
2379 filter = service.filter(ct);
2381 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2382 filtersList.append(filter);
2383 service.detach(*filter);
2385 filter = service.filter(ct);
2389 QString tag = params.paramValue("tag");
2390 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2391 if (tag.startsWith("ladspa")) tag = "ladspa";
2392 char *filterTag = qstrdup(tag.toUtf8().constData());
2393 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2394 QHash<QString, QString>::Iterator it;
2395 QString kfr = params.paramValue("keyframes");
2397 if (!kfr.isEmpty()) {
2398 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2399 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2400 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2401 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2402 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2403 //double max = params.paramValue("max").toDouble();
2404 double min = params.paramValue("min").toDouble();
2405 double factor = params.paramValue("factor", "1").toDouble();
2406 params.removeParam("starttag");
2407 params.removeParam("endtag");
2408 params.removeParam("keyframes");
2409 params.removeParam("min");
2410 params.removeParam("max");
2411 params.removeParam("factor");
2413 // Special case, only one keyframe, means we want a constant value
2414 if (keyFrames.count() == 1) {
2415 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2416 if (filter && filter->is_valid()) {
2417 filter->set("kdenlive_id", filterId);
2418 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2419 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2420 for (int j = 0; j < params.count(); j++) {
2421 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2423 filter->set("in", x1);
2424 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2425 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2426 service.attach(*filter);
2428 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2429 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2430 if (filter && filter->is_valid()) {
2431 filter->set("kdenlive_id", filterId);
2432 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2433 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2434 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2435 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2436 if (x2 == -1) x2 = duration;
2438 for (int j = 0; j < params.count(); j++) {
2439 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2442 filter->set("in", x1);
2443 filter->set("out", x2);
2444 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2445 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2446 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2447 service.attach(*filter);
2454 Mlt::Filter *filter;
2456 if (!region.isEmpty()) {
2457 filter = new Mlt::Filter(*m_mltProfile, "region");
2458 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2459 if (filter && filter->is_valid()) {
2460 filter->set("kdenlive_id", filterId);
2461 if (!region.isEmpty()) {
2462 filter->set("resource", region.toUtf8().constData());
2463 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2464 filter->set("filter0", filterTag);
2465 prefix = "filter0.";
2466 params.removeParam("id");
2467 params.removeParam("region");
2468 params.removeParam("kdenlive_ix");
2471 kDebug() << "filter is NULL";
2472 m_isBlocked = false;
2473 mlt_service_unlock(service.get_service());
2476 params.removeParam("kdenlive_id");
2478 for (int j = 0; j < params.count(); j++) {
2479 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2483 QString effectArgs = params.paramValue("id").section('_', 1);
2485 params.removeParam("id");
2486 params.removeParam("kdenlive_ix");
2487 params.removeParam("tag");
2488 params.removeParam("disable");
2489 params.removeParam("region");
2491 for (int j = 0; j < params.count(); j++) {
2492 effectArgs.append(' ' + params.at(j).value());
2494 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2495 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2498 if (params.paramValue("id") == "pan_zoom") {
2499 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2502 // attach filter to the clip
2503 service.attach(*filter);
2508 // re-add following filters
2509 for (int i = 0; i < filtersList.count(); i++) {
2510 Mlt::Filter *filter = filtersList.at(i);
2512 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2513 service.attach(*filter);
2515 m_isBlocked = false;
2516 mlt_service_unlock(service.get_service());
2517 if (doRefresh) refresh();
2521 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2523 Mlt::Service service(m_mltProducer->parent().get_service());
2524 Mlt::Tractor tractor(service);
2525 Mlt::Producer trackProducer(tractor.track(track));
2526 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2527 Mlt::Service clipService(trackPlaylist.get_service());
2530 QString index = params.paramValue("kdenlive_ix");
2531 QString tag = params.paramValue("tag");
2533 Mlt::Filter *filter = clipService.filter(ct);
2535 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2539 filter = clipService.filter(ct);
2543 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2544 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2546 bool success = false;//mltAddTrackEffect(track, params);
2547 m_isBlocked = false;
2551 QString ser = filter->get("mlt_service");
2552 if (ser == "region") prefix = "filter0.";
2553 mlt_service_lock(service.get_service());
2554 for (int j = 0; j < params.count(); j++) {
2555 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2557 mlt_service_unlock(service.get_service());
2559 m_isBlocked = false;
2565 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2567 QString index = params.paramValue("kdenlive_ix");
2568 QString tag = params.paramValue("tag");
2570 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2571 // This is a keyframe effect, to edit it, we remove it and re-add it.
2572 bool success = mltRemoveEffect(track, position, index, false);
2573 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2574 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2575 else success = mltAddEffect(track, position, params);
2576 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2579 if (position < GenTime()) {
2580 return mltEditTrackEffect(track, params);
2583 Mlt::Service service(m_mltProducer->parent().get_service());
2584 Mlt::Tractor tractor(service);
2585 Mlt::Producer trackProducer(tractor.track(track));
2586 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2588 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2589 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2591 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2595 Mlt::Service clipService(clip->get_service());
2596 int duration = clip->get_playtime();
2597 bool doRefresh = true;
2598 // Check if clip is visible in monitor
2599 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2600 if (diff < 0 || diff > duration) doRefresh = false;
2604 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2605 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2607 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2609 filter = clipService.filter(ct);
2611 kDebug() << "++++++++++++++++++++++++++";
2613 filter = clipService.filter(ct); */
2615 Mlt::Filter *filter = clipService.filter(ct);
2617 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2621 filter = clipService.filter(ct);
2625 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2626 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2628 bool success = mltAddEffect(track, position, params);
2629 m_isBlocked = false;
2633 QString ser = filter->get("mlt_service");
2634 if (ser == "region") prefix = "filter0.";
2635 mlt_service_lock(service.get_service());
2636 for (int j = 0; j < params.count(); j++) {
2637 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2639 mlt_service_unlock(service.get_service());
2641 m_isBlocked = false;
2642 if (doRefresh) refresh();
2646 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2648 Mlt::Service service(m_mltProducer->parent().get_service());
2649 Mlt::Tractor tractor(service);
2650 Mlt::Producer trackProducer(tractor.track(track));
2651 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2653 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2654 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2656 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2660 Mlt::Service clipService(clip->get_service());
2661 int duration = clip->get_playtime();
2662 bool doRefresh = true;
2663 // Check if clip is visible in monitor
2664 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2665 if (diff < 0 || diff > duration) doRefresh = false;
2670 Mlt::Filter *filter = clipService.filter(ct);
2672 int pos = filter->get_int("kdenlive_ix");
2673 if (pos == oldPos) {
2674 filter->set("kdenlive_ix", newPos);
2676 filter = clipService.filter(ct);
2679 m_isBlocked = false;
2680 if (doRefresh) refresh();
2683 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2685 if (position < GenTime()) {
2686 mltMoveTrackEffect(track, oldPos, newPos);
2689 Mlt::Service service(m_mltProducer->parent().get_service());
2690 Mlt::Tractor tractor(service);
2691 Mlt::Producer trackProducer(tractor.track(track));
2692 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2694 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2695 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2697 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2701 Mlt::Service clipService(clip->get_service());
2702 int duration = clip->get_playtime();
2703 bool doRefresh = true;
2704 // Check if clip is visible in monitor
2705 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2706 if (diff < 0 || diff > duration) doRefresh = false;
2711 QList <Mlt::Filter *> filtersList;
2712 Mlt::Filter *filter = clipService.filter(ct);
2714 if (newPos > oldPos) {
2716 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2717 filter->set("kdenlive_ix", newPos);
2718 filtersList.append(filter);
2719 clipService.detach(*filter);
2720 filter = clipService.filter(ct);
2721 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2722 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2724 filter = clipService.filter(ct);
2728 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2729 filtersList.append(filter);
2730 clipService.detach(*filter);
2732 filter = clipService.filter(ct);
2736 if (filter->get_int("kdenlive_ix") == oldPos) {
2737 filter->set("kdenlive_ix", newPos);
2738 filtersList.append(filter);
2739 clipService.detach(*filter);
2741 filter = clipService.filter(ct);
2745 filter = clipService.filter(ct);
2747 int pos = filter->get_int("kdenlive_ix");
2748 if (pos >= newPos) {
2749 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2750 filtersList.append(filter);
2751 clipService.detach(*filter);
2753 filter = clipService.filter(ct);
2757 for (int i = 0; i < filtersList.count(); i++) {
2758 clipService.attach(*(filtersList.at(i)));
2761 m_isBlocked = false;
2762 if (doRefresh) refresh();
2765 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2767 Mlt::Service service(m_mltProducer->parent().get_service());
2768 Mlt::Tractor tractor(service);
2769 Mlt::Producer trackProducer(tractor.track(track));
2770 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2772 Mlt::Service clipService(trackPlaylist.get_service());
2776 QList <Mlt::Filter *> filtersList;
2777 Mlt::Filter *filter = clipService.filter(ct);
2779 if (newPos > oldPos) {
2781 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2782 filter->set("kdenlive_ix", newPos);
2783 filtersList.append(filter);
2784 clipService.detach(*filter);
2785 filter = clipService.filter(ct);
2786 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2787 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2789 filter = clipService.filter(ct);
2793 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2794 filtersList.append(filter);
2795 clipService.detach(*filter);
2797 filter = clipService.filter(ct);
2801 if (filter->get_int("kdenlive_ix") == oldPos) {
2802 filter->set("kdenlive_ix", newPos);
2803 filtersList.append(filter);
2804 clipService.detach(*filter);
2806 filter = clipService.filter(ct);
2810 filter = clipService.filter(ct);
2812 int pos = filter->get_int("kdenlive_ix");
2813 if (pos >= newPos) {
2814 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2815 filtersList.append(filter);
2816 clipService.detach(*filter);
2818 filter = clipService.filter(ct);
2822 for (int i = 0; i < filtersList.count(); i++) {
2823 clipService.attach(*(filtersList.at(i)));
2825 m_isBlocked = false;
2829 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2832 Mlt::Service service(m_mltProducer->parent().get_service());
2833 Mlt::Tractor tractor(service);
2834 Mlt::Producer trackProducer(tractor.track(info.track));
2835 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2837 /* // Display playlist info
2838 kDebug()<<"//////////// BEFORE RESIZE";
2839 for (int i = 0; i < trackPlaylist.count(); i++) {
2840 int blankStart = trackPlaylist.clip_start(i);
2841 int blankDuration = trackPlaylist.clip_length(i) - 1;
2843 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2844 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2847 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2848 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2849 m_isBlocked = false;
2852 mlt_service_lock(service.get_service());
2853 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2854 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2855 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2857 int previousStart = clip->get_in();
2858 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2859 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2861 int currentOut = newDuration + previousStart;
2862 if (currentOut > clip->get_length()) {
2863 clip->parent().set("length", currentOut + 1);
2864 clip->parent().set("out", currentOut);
2865 clip->set("length", currentOut + 1);
2868 /*if (newDuration > clip->get_out()) {
2869 clip->parent().set_in_and_out(0, newDuration + 1);
2870 clip->set_in_and_out(0, newDuration + 1);
2873 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2874 trackPlaylist.consolidate_blanks(0);
2875 // skip to next clip
2877 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2879 // clip was made longer, trim next blank if there is one.
2880 if (clipIndex < trackPlaylist.count()) {
2881 // If this is not the last clip in playlist
2882 if (trackPlaylist.is_blank(clipIndex)) {
2883 int blankStart = trackPlaylist.clip_start(clipIndex);
2884 int blankDuration = trackPlaylist.clip_length(clipIndex);
2885 if (diff > blankDuration) {
2886 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2888 if (diff - blankDuration == 0) {
2889 trackPlaylist.remove(clipIndex);
2890 } else trackPlaylist.remove_region(blankStart, diff);
2892 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2895 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2896 trackPlaylist.consolidate_blanks(0);
2897 mlt_service_unlock(service.get_service());
2899 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2900 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2901 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2902 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2903 ItemInfo transpinfo;
2904 transpinfo.startPos = info.startPos;
2905 transpinfo.endPos = info.startPos + clipDuration;
2906 transpinfo.track = info.track;
2907 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2909 m_isBlocked = false;
2910 m_mltConsumer->set("refresh", 1);
2914 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2916 Mlt::Service service(m_mltProducer->parent().get_service());
2917 Mlt::Tractor tractor(service);
2918 Mlt::Producer trackProducer(tractor.track(track));
2921 if (blind) trackProducer.set("hide", 3);
2922 else trackProducer.set("hide", 2);
2924 trackProducer.set("hide", 1);
2926 trackProducer.set("hide", 0);
2928 tractor.multitrack()->refresh();
2934 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2936 Mlt::Service service(m_mltProducer->parent().get_service());
2937 int frameOffset = (int) diff.frames(m_fps);
2938 Mlt::Tractor tractor(service);
2939 Mlt::Producer trackProducer(tractor.track(info.track));
2940 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2941 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2942 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2945 mlt_service_lock(service.get_service());
2946 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2947 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2949 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2950 mlt_service_unlock(service.get_service());
2953 int previousStart = clip->get_in();
2954 int previousOut = clip->get_out();
2957 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2958 m_isBlocked = false;
2959 mlt_service_unlock(service.get_service());
2960 m_mltConsumer->set("refresh", 1);
2964 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2966 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2967 Mlt::Service service(m_mltProducer->parent().get_service());
2968 int moveFrame = (int) diff.frames(m_fps);
2969 Mlt::Tractor tractor(service);
2970 Mlt::Producer trackProducer(tractor.track(info.track));
2971 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2972 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2973 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2976 mlt_service_lock(service.get_service());
2977 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2978 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2979 if (clip == NULL || clip->is_blank()) {
2980 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2981 mlt_service_unlock(service.get_service());
2984 int previousStart = clip->get_in();
2985 int previousOut = clip->get_out();
2988 previousStart += moveFrame;
2990 int length = previousOut + 1;
2991 if (length > clip->get_length()) {
2992 clip->parent().set("length", length + 1);
2993 clip->parent().set("out", length);
2994 clip->set("length", length + 1);
2998 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
2999 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3000 if (moveFrame > 0) {
3001 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3003 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3004 int blankIndex = clipIndex - 1;
3005 int blankLength = trackPlaylist.clip_length(blankIndex);
3006 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3007 if (! trackPlaylist.is_blank(blankIndex)) {
3008 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3010 if (blankLength + moveFrame == 0)
3011 trackPlaylist.remove(blankIndex);
3013 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3015 trackPlaylist.consolidate_blanks(0);
3016 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3017 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3018 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3019 ItemInfo transpinfo;
3020 transpinfo.startPos = info.startPos + diff;
3021 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3022 transpinfo.track = info.track;
3023 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3025 m_isBlocked = false;
3026 //m_mltConsumer->set("refresh", 1);
3027 mlt_service_unlock(service.get_service());
3028 m_mltConsumer->set("refresh", 1);
3032 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3034 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3038 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3040 if (prod == NULL || !prod->is_valid()) {
3041 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3044 kDebug() << "NEW PROD ID: " << prod->get("id");
3046 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3047 Mlt::Service service(m_mltProducer->parent().get_service());
3048 if (service.type() != tractor_type) {
3049 kWarning() << "// TRACTOR PROBLEM";
3052 mlt_service_lock(service.get_service());
3053 Mlt::Tractor tractor(service);
3054 Mlt::Producer trackProducer(tractor.track(track));
3055 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3056 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3057 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3058 if (clipProducer == NULL || clipProducer->is_blank()) {
3059 kDebug() << "// ERROR UPDATING CLIP PROD";
3060 delete clipProducer;
3061 mlt_service_unlock(service.get_service());
3065 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3066 if (!clip || !clip->is_valid()) {
3067 if (clip) delete clip;
3068 delete clipProducer;
3069 mlt_service_unlock(service.get_service());
3073 // move all effects to the correct producer
3074 mltPasteEffects(clipProducer, clip);
3075 trackPlaylist.insert_at(pos, clip, 1);
3077 delete clipProducer;
3078 mlt_service_unlock(service.get_service());
3083 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3087 Mlt::Service service(m_mltProducer->parent().get_service());
3088 if (service.type() != tractor_type) {
3089 kWarning() << "// TRACTOR PROBLEM";
3093 Mlt::Tractor tractor(service);
3094 mlt_service_lock(service.get_service());
3095 Mlt::Producer trackProducer(tractor.track(startTrack));
3096 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3097 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3098 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3099 bool checkLength = false;
3100 if (endTrack == startTrack) {
3101 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3102 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3103 // error, destination is not empty
3105 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3106 delete clipProducer;
3108 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3109 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3110 mlt_service_unlock(service.get_service());
3114 trackPlaylist.consolidate_blanks(0);
3116 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3117 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3118 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3120 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3121 trackPlaylist.consolidate_blanks(1);
3122 delete clipProducer;
3123 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3124 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3126 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3128 //mlt_service_unlock(service.get_service());
3130 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3131 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3132 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3133 // error, destination is not empty
3134 mlt_service_unlock(service.get_service());
3138 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3139 if (!clipProducer || clipProducer->is_blank()) {
3140 // error, destination is not empty
3141 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3142 if (clipProducer) delete clipProducer;
3143 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3144 mlt_service_unlock(service.get_service());
3148 trackPlaylist.consolidate_blanks(0);
3149 destTrackPlaylist.consolidate_blanks(1);
3150 Mlt::Producer *clip;
3151 // check if we are moving a slowmotion producer
3152 QString serv = clipProducer->parent().get("mlt_service");
3153 QString currentid = clipProducer->parent().get("id");
3154 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3155 clip = clipProducer;
3158 // Special case: prod is null when using placeholder clips.
3159 // in that case, use the producer existing in playlist. Note that
3160 // it will bypass the one producer per track logic and might cause
3161 // Sound cracks if clip is moved so that it overlaps another copy of itself
3162 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3163 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3166 // move all effects to the correct producer
3167 mltPasteEffects(clipProducer, clip);
3170 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3171 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3172 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3175 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3177 if (clip == clipProducer) {
3182 delete clipProducer;
3184 destTrackPlaylist.consolidate_blanks(0);
3185 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3186 kDebug() << "//////// moving clip transparency";
3187 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3189 if (clipIndex > trackPlaylist.count()) checkLength = true;
3190 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3193 mlt_service_unlock(service.get_service());
3194 if (checkLength) mltCheckLength(&tractor);
3197 //m_mltConsumer->set("refresh", 1);
3202 QList <int> Render::checkTrackSequence(int track)
3205 Mlt::Service service(m_mltProducer->parent().get_service());
3206 if (service.type() != tractor_type) {
3207 kWarning() << "// TRACTOR PROBLEM";
3210 Mlt::Tractor tractor(service);
3211 mlt_service_lock(service.get_service());
3212 Mlt::Producer trackProducer(tractor.track(track));
3213 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3214 int clipNb = trackPlaylist.count();
3215 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3216 for (int i = 0; i < clipNb; i++) {
3217 Mlt::Producer *c = trackPlaylist.get_clip(i);
3218 int pos = trackPlaylist.clip_start(i);
3219 if (!list.contains(pos)) list.append(pos);
3220 pos += c->get_playtime();
3221 if (!list.contains(pos)) list.append(pos);
3227 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3229 int new_in = (int)newIn.frames(m_fps);
3230 int new_out = (int)newOut.frames(m_fps) - 1;
3231 if (new_in >= new_out) return false;
3232 int old_in = (int)oldIn.frames(m_fps);
3233 int old_out = (int)oldOut.frames(m_fps) - 1;
3235 Mlt::Service service(m_mltProducer->parent().get_service());
3236 Mlt::Tractor tractor(service);
3237 Mlt::Field *field = tractor.field();
3239 bool doRefresh = true;
3240 // Check if clip is visible in monitor
3241 int diff = old_out - m_mltProducer->position();
3242 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3244 diff = new_out - m_mltProducer->position();
3245 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3249 mlt_service_lock(service.get_service());
3251 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3252 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3253 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3254 QString resource = mlt_properties_get(properties, "mlt_service");
3255 int old_pos = (int)(old_in + old_out) / 2;
3258 while (mlt_type == "transition") {
3259 Mlt::Transition transition((mlt_transition) nextservice);
3260 int currentTrack = transition.get_b_track();
3261 int currentIn = (int) transition.get_in();
3262 int currentOut = (int) transition.get_out();
3264 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3266 if (newTrack - startTrack != 0) {
3267 Mlt::Properties trans_props(transition.get_properties());
3268 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3269 Mlt::Properties new_trans_props(new_transition.get_properties());
3270 new_trans_props.inherit(trans_props);
3271 new_transition.set_in_and_out(new_in, new_out);
3272 field->disconnect_service(transition);
3273 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3274 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3275 } else transition.set_in_and_out(new_in, new_out);
3278 nextservice = mlt_service_producer(nextservice);
3279 if (nextservice == NULL) break;
3280 properties = MLT_SERVICE_PROPERTIES(nextservice);
3281 mlt_type = mlt_properties_get(properties, "mlt_type");
3282 resource = mlt_properties_get(properties, "mlt_service");
3284 mlt_service_unlock(service.get_service());
3286 if (doRefresh) refresh();
3287 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3292 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3294 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3295 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3296 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3297 QString resource = mlt_properties_get(properties, "mlt_service");
3298 QList <Mlt::Transition *> trList;
3300 while (mlt_type == "transition") {
3301 Mlt::Transition transition((mlt_transition) nextservice);
3302 int aTrack = transition.get_a_track();
3303 int bTrack = transition.get_b_track();
3304 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3305 Mlt::Properties trans_props(transition.get_properties());
3306 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3307 Mlt::Properties new_trans_props(cp->get_properties());
3308 new_trans_props.inherit(trans_props);
3310 field->disconnect_service(transition);
3312 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3314 nextservice = mlt_service_producer(nextservice);
3315 if (nextservice == NULL) break;
3316 properties = MLT_SERVICE_PROPERTIES(nextservice);
3317 mlt_type = mlt_properties_get(properties, "mlt_type");
3318 resource = mlt_properties_get(properties, "mlt_service");
3321 field->plant_transition(tr, a_track, b_track);
3323 // re-add upper transitions
3324 for (int i = 0; i < trList.count(); i++) {
3325 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3326 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3330 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3332 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3334 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3335 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3338 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3341 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3343 mlt_service serv = m_mltProducer->parent().get_service();
3344 mlt_service_lock(serv);
3347 mlt_service nextservice = mlt_service_get_producer(serv);
3348 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3349 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3350 QString resource = mlt_properties_get(properties, "mlt_service");
3351 int in_pos = (int) in.frames(m_fps);
3352 int out_pos = (int) out.frames(m_fps) - 1;
3354 while (mlt_type == "transition") {
3355 mlt_transition tr = (mlt_transition) nextservice;
3356 int currentTrack = mlt_transition_get_b_track(tr);
3357 int currentBTrack = mlt_transition_get_a_track(tr);
3358 int currentIn = (int) mlt_transition_get_in(tr);
3359 int currentOut = (int) mlt_transition_get_out(tr);
3361 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3363 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3364 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3365 QMap<QString, QString>::Iterator it;
3367 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3369 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3370 if (currentId != xml.attribute("id")) {
3371 // The transition ID is not the same, so reset all properties
3372 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3373 // Cleanup previous properties
3374 QStringList permanentProps;
3375 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3376 permanentProps << "out" << "a_track" << "b_track";
3377 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3378 QString propName = mlt_properties_get_name(transproperties, i);
3379 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3380 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3385 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3386 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3388 if (currentBTrack != a_track) {
3389 mlt_properties_set_int(transproperties, "a_track", a_track);
3391 for (it = map.begin(); it != map.end(); ++it) {
3393 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3394 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3395 //filter->set("kdenlive_id", id);
3399 nextservice = mlt_service_producer(nextservice);
3400 if (nextservice == NULL) break;
3401 properties = MLT_SERVICE_PROPERTIES(nextservice);
3402 mlt_type = mlt_properties_get(properties, "mlt_type");
3403 resource = mlt_properties_get(properties, "mlt_service");
3405 mlt_service_unlock(serv);
3408 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3411 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3413 mlt_service serv = m_mltProducer->parent().get_service();
3415 mlt_service_lock(serv);
3417 Mlt::Service service(serv);
3418 Mlt::Tractor tractor(service);
3419 Mlt::Field *field = tractor.field();
3421 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3423 mlt_service nextservice = mlt_service_get_producer(serv);
3424 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3425 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3426 QString resource = mlt_properties_get(properties, "mlt_service");
3428 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3429 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3431 while (mlt_type == "transition") {
3432 mlt_transition tr = (mlt_transition) nextservice;
3433 int currentTrack = mlt_transition_get_b_track(tr);
3434 int currentIn = (int) mlt_transition_get_in(tr);
3435 int currentOut = (int) mlt_transition_get_out(tr);
3436 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3438 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3439 mlt_field_disconnect_service(field->get_field(), nextservice);
3442 nextservice = mlt_service_producer(nextservice);
3443 if (nextservice == NULL) break;
3444 properties = MLT_SERVICE_PROPERTIES(nextservice);
3445 mlt_type = mlt_properties_get(properties, "mlt_type");
3446 resource = mlt_properties_get(properties, "mlt_service");
3448 mlt_service_unlock(serv);
3451 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3454 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3456 QDomNodeList attribs = xml.elementsByTagName("parameter");
3457 QMap<QString, QString> map;
3458 for (int i = 0; i < attribs.count(); i++) {
3459 QDomElement e = attribs.item(i).toElement();
3460 QString name = e.attribute("name");
3461 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3462 map[name] = e.attribute("default");
3463 if (!e.attribute("value").isEmpty()) {
3464 map[name] = e.attribute("value");
3466 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3467 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3468 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3471 if (e.attribute("namedesc").contains(';')) {
3472 QString format = e.attribute("format");
3473 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3474 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3476 QTextStream txtNeu(&neu);
3477 if (values.size() > 0)
3478 txtNeu << (int)values[0].toDouble();
3480 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3481 txtNeu << separators[i];
3482 txtNeu << (int)(values[i+1].toDouble());
3484 if (i < separators.size())
3485 txtNeu << separators[i];
3486 map[e.attribute("name")] = neu;
3493 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3495 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3496 Mlt::Service service(m_mltProducer->parent().get_service());
3497 Mlt::Tractor tractor(service);
3498 Mlt::Field *field = tractor.field();
3500 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3501 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3502 transition->set("transparency", id);
3503 transition->set("fill", 1);
3504 transition->set("internal_added", 237);
3505 field->plant_transition(*transition, transitiontrack, info.track);
3509 void Render::mltDeleteTransparency(int pos, int track, int id)
3511 Mlt::Service service(m_mltProducer->parent().get_service());
3512 Mlt::Tractor tractor(service);
3513 Mlt::Field *field = tractor.field();
3515 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3516 mlt_service serv = m_mltProducer->parent().get_service();
3518 mlt_service nextservice = mlt_service_get_producer(serv);
3519 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3520 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3521 QString resource = mlt_properties_get(properties, "mlt_service");
3523 while (mlt_type == "transition") {
3524 mlt_transition tr = (mlt_transition) nextservice;
3525 int currentTrack = mlt_transition_get_b_track(tr);
3526 int currentIn = (int) mlt_transition_get_in(tr);
3527 int currentOut = (int) mlt_transition_get_out(tr);
3528 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3529 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3531 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3532 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3533 mlt_field_disconnect_service(field->get_field(), nextservice);
3536 nextservice = mlt_service_producer(nextservice);
3537 if (nextservice == NULL) break;
3538 properties = MLT_SERVICE_PROPERTIES(nextservice);
3539 mlt_type = mlt_properties_get(properties, "mlt_type");
3540 resource = mlt_properties_get(properties, "mlt_service");
3542 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3545 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3547 Mlt::Service service(m_mltProducer->parent().get_service());
3548 Mlt::Tractor tractor(service);
3550 mlt_service_lock(service.get_service());
3551 m_mltConsumer->set("refresh", 0);
3554 mlt_service serv = m_mltProducer->parent().get_service();
3555 mlt_service nextservice = mlt_service_get_producer(serv);
3556 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3557 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3558 QString resource = mlt_properties_get(properties, "mlt_service");
3559 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3560 while (mlt_type == "transition") {
3561 mlt_transition tr = (mlt_transition) nextservice;
3562 int currentTrack = mlt_transition_get_b_track(tr);
3563 int currentIn = (int) mlt_transition_get_in(tr);
3564 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3565 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3566 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3567 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3568 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3569 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3572 nextservice = mlt_service_producer(nextservice);
3573 if (nextservice == NULL) break;
3574 properties = MLT_SERVICE_PROPERTIES(nextservice);
3575 mlt_type = mlt_properties_get(properties, "mlt_type");
3576 resource = mlt_properties_get(properties, "mlt_service");
3578 mlt_service_unlock(service.get_service());
3580 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3584 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3586 Mlt::Service service(m_mltProducer->parent().get_service());
3587 Mlt::Tractor tractor(service);
3589 mlt_service_lock(service.get_service());
3590 m_mltConsumer->set("refresh", 0);
3593 mlt_service serv = m_mltProducer->parent().get_service();
3594 mlt_service nextservice = mlt_service_get_producer(serv);
3595 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3596 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3597 QString resource = mlt_properties_get(properties, "mlt_service");
3599 while (mlt_type == "transition") {
3600 mlt_transition tr = (mlt_transition) nextservice;
3601 int currentTrack = mlt_transition_get_b_track(tr);
3602 int currentaTrack = mlt_transition_get_a_track(tr);
3603 int currentIn = (int) mlt_transition_get_in(tr);
3604 int currentOut = (int) mlt_transition_get_out(tr);
3605 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3606 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3607 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3608 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3609 kDebug() << "//////MOVING";
3610 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3611 if (endTrack != startTrack) {
3612 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3613 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3614 mlt_properties_set_int(properties, "b_track", endTrack);
3618 nextservice = mlt_service_producer(nextservice);
3619 if (nextservice == NULL) break;
3620 properties = MLT_SERVICE_PROPERTIES(nextservice);
3621 mlt_type = mlt_properties_get(properties, "mlt_type");
3622 resource = mlt_properties_get(properties, "mlt_service");
3625 mlt_service_unlock(service.get_service());
3626 m_mltConsumer->set("refresh", 1);
3630 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3632 if (in >= out) return false;
3633 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3634 Mlt::Service service(m_mltProducer->parent().get_service());
3636 Mlt::Tractor tractor(service);
3637 Mlt::Field *field = tractor.field();
3639 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3640 if (out != GenTime())
3641 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3643 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3644 QMap<QString, QString>::Iterator it;
3646 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3647 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3648 if (xml.hasAttribute("id"))
3649 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3651 for (it = args.begin(); it != args.end(); ++it) {
3653 if (!it.value().isEmpty())
3654 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3655 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3657 // attach transition
3658 mltPlantTransition(field, *transition, a_track, b_track);
3659 // field->plant_transition(*transition, a_track, b_track);
3660 if (do_refresh) refresh();
3664 void Render::mltSavePlaylist()
3666 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3667 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3668 fileConsumer.set("resource", "/tmp/playlist.mlt");
3670 Mlt::Service service(m_mltProducer->get_service());
3672 fileConsumer.connect(service);
3673 fileConsumer.start();
3676 const QList <Mlt::Producer *> Render::producersList()
3678 QList <Mlt::Producer *> prods;
3679 if (m_mltProducer == NULL) return prods;
3680 Mlt::Service service(m_mltProducer->parent().get_service());
3681 if (service.type() != tractor_type) return prods;
3682 Mlt::Tractor tractor(service);
3685 int trackNb = tractor.count();
3686 for (int t = 1; t < trackNb; t++) {
3687 Mlt::Producer *tt = tractor.track(t);
3688 Mlt::Producer trackProducer(tt);
3690 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3691 int clipNb = trackPlaylist.count();
3692 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3693 for (int i = 0; i < clipNb; i++) {
3694 Mlt::Producer *c = trackPlaylist.get_clip(i);
3695 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3697 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3698 ids.append(nprod->get("id"));
3699 prods.append(nprod);
3700 } else delete nprod;
3708 void Render::fillSlowMotionProducers()
3710 if (m_mltProducer == NULL) return;
3711 Mlt::Service service(m_mltProducer->parent().get_service());
3712 if (service.type() != tractor_type) return;
3714 Mlt::Tractor tractor(service);
3716 int trackNb = tractor.count();
3717 for (int t = 1; t < trackNb; t++) {
3718 Mlt::Producer *tt = tractor.track(t);
3719 Mlt::Producer trackProducer(tt);
3721 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3722 int clipNb = trackPlaylist.count();
3723 for (int i = 0; i < clipNb; i++) {
3724 Mlt::Producer *c = trackPlaylist.get_clip(i);
3725 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3727 QString id = nprod->get("id");
3728 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3729 // this is a slowmotion producer, add it to the list
3730 QString url = QString::fromUtf8(nprod->get("resource"));
3731 int strobe = nprod->get_int("strobe");
3732 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3733 if (!m_slowmotionProducers.contains(url)) {
3734 m_slowmotionProducers.insert(url, nprod);
3736 } else delete nprod;
3743 void Render::mltInsertTrack(int ix, bool videoTrack)
3748 Mlt::Service service(m_mltProducer->parent().get_service());
3749 mlt_service_lock(service.get_service());
3750 if (service.type() != tractor_type) {
3751 kWarning() << "// TRACTOR PROBLEM";
3755 Mlt::Tractor tractor(service);
3757 Mlt::Playlist playlist;
3758 int ct = tractor.count();
3760 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3766 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3767 tractor.set_track(playlist, pos);
3768 Mlt::Producer newProd(tractor.track(pos));
3769 if (!videoTrack) newProd.set("hide", 1);
3771 for (; pos <= ct; pos++) {
3772 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3773 tractor.set_track(*prodToMove, pos);
3774 prodToMove = prodToMove2;
3777 tractor.set_track(playlist, ix);
3778 Mlt::Producer newProd(tractor.track(ix));
3779 if (!videoTrack) newProd.set("hide", 1);
3783 mlt_service serv = m_mltProducer->parent().get_service();
3784 mlt_service nextservice = mlt_service_get_producer(serv);
3785 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3786 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3787 QString resource = mlt_properties_get(properties, "mlt_service");
3789 while (mlt_type == "transition") {
3790 if (resource != "mix") {
3791 mlt_transition tr = (mlt_transition) nextservice;
3792 int currentTrack = mlt_transition_get_b_track(tr);
3793 int currentaTrack = mlt_transition_get_a_track(tr);
3794 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3796 if (currentTrack >= ix) {
3797 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3798 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3801 nextservice = mlt_service_producer(nextservice);
3802 if (nextservice == NULL) break;
3803 properties = MLT_SERVICE_PROPERTIES(nextservice);
3804 mlt_type = mlt_properties_get(properties, "mlt_type");
3805 resource = mlt_properties_get(properties, "mlt_service");
3808 // Add audio mix transition to last track
3809 Mlt::Field *field = tractor.field();
3810 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3811 transition->set("a_track", 1);
3812 transition->set("b_track", ct);
3813 transition->set("always_active", 1);
3814 transition->set("internal_added", 237);
3815 transition->set("combine", 1);
3816 field->plant_transition(*transition, 1, ct);
3817 //mlt_service_unlock(m_mltConsumer->get_service());
3818 mlt_service_unlock(service.get_service());
3819 //tractor.multitrack()->refresh();
3820 //tractor.refresh();
3822 blockSignals(false);
3826 void Render::mltDeleteTrack(int ix)
3829 doc.setContent(sceneList(), false);
3830 int tracksCount = doc.elementsByTagName("track").count() - 1;
3831 QDomNode track = doc.elementsByTagName("track").at(ix);
3832 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3833 QDomNodeList transitions = doc.elementsByTagName("transition");
3834 for (int i = 0; i < transitions.count(); i++) {
3835 QDomElement e = transitions.at(i).toElement();
3836 QDomNodeList props = e.elementsByTagName("property");
3837 QMap <QString, QString> mappedProps;
3838 for (int j = 0; j < props.count(); j++) {
3839 QDomElement f = props.at(j).toElement();
3840 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3842 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3843 tractor.removeChild(transitions.at(i));
3845 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3846 // Transition needs to be moved
3847 int a_track = mappedProps.value("a_track").toInt();
3848 int b_track = mappedProps.value("b_track").toInt();
3849 if (a_track > 0 && a_track >= ix) a_track --;
3850 if (b_track == ix) {
3851 // transition was on the deleted track, so remove it
3852 tractor.removeChild(transitions.at(i));
3856 if (b_track > 0 && b_track > ix) b_track --;
3857 for (int j = 0; j < props.count(); j++) {
3858 QDomElement f = props.at(j).toElement();
3859 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3860 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3865 tractor.removeChild(track);
3866 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3867 setSceneList(doc.toString(), m_framePosition);
3869 /* if (m_mltProducer != NULL) {
3870 Mlt::Producer parentProd(m_mltProducer->parent());
3871 if (parentProd.get_producer() != NULL) {
3872 Mlt::Service service(parentProd.get_service());
3873 if (service.type() == tractor_type) {
3874 Mlt::Tractor tractor(service);
3875 mltCheckLength(&tractor);
3882 void Render::updatePreviewSettings()
3884 kDebug() << "////// RESTARTING CONSUMER";
3885 if (!m_mltConsumer || !m_mltProducer) return;
3886 if (m_mltProducer->get_playtime() == 0) return;
3887 Mlt::Service service(m_mltProducer->parent().get_service());
3888 if (service.type() != tractor_type) return;
3890 //m_mltConsumer->set("refresh", 0);
3891 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3892 m_mltConsumer->purge();
3893 QString scene = sceneList();
3895 if (m_mltProducer) {
3896 pos = m_mltProducer->position();
3899 setSceneList(scene, pos);
3903 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3905 // Update all frame positions to the new fps value
3906 //WARNING: there are probably some effects or other that hold a frame value
3907 // as parameter and will also need to be updated here!
3909 doc.setContent(scene);
3911 double factor = new_fps / current_fps;
3912 QDomNodeList producers = doc.elementsByTagName("producer");
3913 for (int i = 0; i < producers.count(); i++) {
3914 QDomElement prod = producers.at(i).toElement();
3915 prod.removeAttribute("in");
3916 prod.removeAttribute("out");
3918 QDomNodeList props = prod.childNodes();
3919 for (int j = 0; j < props.count(); j++) {
3920 QDomElement param = props.at(j).toElement();
3921 QString paramName = param.attribute("name");
3922 if (paramName.startsWith("meta.") || paramName == "length") {
3923 prod.removeChild(props.at(j));
3929 QDomNodeList entries = doc.elementsByTagName("entry");
3930 for (int i = 0; i < entries.count(); i++) {
3931 QDomElement entry = entries.at(i).toElement();
3932 int in = entry.attribute("in").toInt();
3933 int out = entry.attribute("out").toInt();
3934 in = factor * in + 0.5;
3935 out = factor * out + 0.5;
3936 entry.setAttribute("in", in);
3937 entry.setAttribute("out", out);
3940 QDomNodeList blanks = doc.elementsByTagName("blank");
3941 for (int i = 0; i < blanks.count(); i++) {
3942 QDomElement blank = blanks.at(i).toElement();
3943 int length = blank.attribute("length").toInt();
3944 length = factor * length + 0.5;
3945 blank.setAttribute("length", QString::number(length));
3948 QDomNodeList filters = doc.elementsByTagName("filter");
3949 for (int i = 0; i < filters.count(); i++) {
3950 QDomElement filter = filters.at(i).toElement();
3951 int in = filter.attribute("in").toInt();
3952 int out = filter.attribute("out").toInt();
3953 in = factor * in + 0.5;
3954 out = factor * out + 0.5;
3955 filter.setAttribute("in", in);
3956 filter.setAttribute("out", out);
3959 QDomNodeList transitions = doc.elementsByTagName("transition");
3960 for (int i = 0; i < transitions.count(); i++) {
3961 QDomElement transition = transitions.at(i).toElement();
3962 int in = transition.attribute("in").toInt();
3963 int out = transition.attribute("out").toInt();
3964 in = factor * in + 0.5;
3965 out = factor * out + 0.5;
3966 transition.setAttribute("in", in);
3967 transition.setAttribute("out", out);
3968 QDomNodeList props = transition.childNodes();
3969 for (int j = 0; j < props.count(); j++) {
3970 QDomElement param = props.at(j).toElement();
3971 QString paramName = param.attribute("name");
3972 if (paramName == "geometry") {
3973 QString geom = param.firstChild().nodeValue();
3974 QStringList keys = geom.split(';');
3975 QStringList newKeys;
3976 for (int k = 0; k < keys.size(); ++k) {
3977 if (keys.at(k).contains('=')) {
3978 int pos = keys.at(k).section('=', 0, 0).toInt();
3979 pos = factor * pos + 0.5;
3980 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3981 } else newKeys.append(keys.at(k));
3983 param.firstChild().setNodeValue(newKeys.join(";"));
3987 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3988 int out = tractor.attribute("out").toInt();
3989 out = factor * out + 0.5;
3990 tractor.setAttribute("out", out);
3991 emit durationChanged(out);
3993 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3994 return doc.toString();
3998 void Render::sendFrameUpdate()
4000 if (m_mltProducer) {
4001 Mlt::Frame * frame = m_mltProducer->get_frame();
4002 emitFrameUpdated(*frame);
4008 #include "renderer.moc"