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()),
105 m_isSplitView(false),
109 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
110 buildConsumer(profile);
112 m_mltProducer = m_blackClip->cut(0, 50);
113 m_mltConsumer->connect(*m_mltProducer);
114 m_mltProducer->set_speed(0.0);
124 void Render::closeMlt()
128 Mlt::Service service(m_mltProducer->parent().get_service());
129 mlt_service_lock(service.get_service());
131 if (service.type() == tractor_type) {
132 Mlt::Tractor tractor(service);
133 Mlt::Field *field = tractor.field();
134 mlt_service nextservice = mlt_service_get_producer(service.get_service());
135 mlt_service nextservicetodisconnect;
136 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
137 QString mlt_type = mlt_properties_get(properties, "mlt_type");
138 QString resource = mlt_properties_get(properties, "mlt_service");
139 // Delete all transitions
140 while (mlt_type == "transition") {
141 nextservicetodisconnect = nextservice;
142 nextservice = mlt_service_producer(nextservice);
143 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
144 nextservice = mlt_service_producer(nextservice);
145 if (nextservice == NULL) break;
146 properties = MLT_SERVICE_PROPERTIES(nextservice);
147 mlt_type = mlt_properties_get(properties, "mlt_type");
148 resource = mlt_properties_get(properties, "mlt_service");
151 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
152 Mlt::Producer trackProducer(tractor.track(trackNb));
153 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
154 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
157 mlt_service_unlock(service.get_service());
160 kDebug() << "// // // CLOSE RENDERER " << m_name;
161 delete m_mltConsumer;
162 delete m_mltProducer;
167 void Render::slotSwitchFullscreen()
169 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
172 void Render::buildConsumer(const QString profileName)
174 m_activeProfile = profileName;
175 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
176 setenv("MLT_PROFILE", tmp, 1);
180 //TODO: uncomment following line when everything is clean
181 //if (m_mltProfile) delete m_mltProfile;
182 m_mltProfile = new Mlt::Profile(tmp);
183 m_mltProfile->get_profile()->is_explicit = 1;
186 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
187 m_blackClip->set("id", "black");
188 m_blackClip->set("mlt_type", "producer");
190 if (KdenliveSettings::external_display() && m_name != "clip") {
191 // Use blackmagic card for video output
192 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
193 if (BMInterface::isSupportedProfile(KdenliveSettings::blackmagic_output_device(), profileProperties)) {
194 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
195 tmp = qstrdup(decklink.toUtf8().constData());
196 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, tmp);
199 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
200 m_mltConsumer->set("terminate_on_pause", 0);
201 m_mltConsumer->set("audio_buffer", 1024);
202 m_mltConsumer->set("frequency", 48000);
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()));
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 (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
274 QString videoDriver = KdenliveSettings::videodrivername();
275 QString currentDriver = m_mltConsumer->get("video_driver");
276 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
277 QString background = KdenliveSettings::window_background().name();
278 QString currentBackground = m_mltConsumer->get("window_background");
279 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
280 kDebug() << "reset to same profile, nothing to do";
284 if (m_isSplitView) slotSplitView(false);
285 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
286 m_mltConsumer->purge();
287 delete m_mltConsumer;
288 m_mltConsumer = NULL;
290 QString scene = sceneList();
292 double current_fps = m_mltProfile->fps();
297 pos = m_mltProducer->position();
299 Mlt::Service service(m_mltProducer->get_service());
300 if (service.type() == tractor_type) {
301 Mlt::Tractor tractor(service);
302 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
303 Mlt::Producer trackProducer(tractor.track(trackNb));
304 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
305 trackPlaylist.clear();
309 delete m_mltProducer;
311 m_mltProducer = NULL;
312 buildConsumer(profileName);
313 double new_fps = m_mltProfile->fps();
314 if (current_fps != new_fps) {
315 // fps changed, we must update the scenelist positions
316 scene = updateSceneListFps(current_fps, new_fps, scene);
318 //kDebug() << "//RESET WITHSCENE: " << scene;
319 setSceneList(scene, pos);
320 // producers have changed (different profile), so reset them...
321 emit refreshDocumentProducers();
322 /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
323 m_mltProducer = producer;
324 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
325 m_mltProducer->optimise();
326 m_mltProducer->set_speed(0);
329 //delete m_mltProfile;
330 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
331 //mlt_profile prof = m_mltProfile->get_profile();
332 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
333 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
334 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
335 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
337 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
342 void Render::seek(GenTime time)
347 m_mltProducer->seek((int)(time.frames(m_fps)));
352 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
353 QPixmap pix(width, height);
355 mlt_image_format format = mlt_image_rgb24a;
356 uint8_t *thumb = frame->get_image(format, width, height);
357 QImage image(thumb, width, height, QImage::Format_ARGB32);
359 if (!image.isNull()) {
360 pix = pix.fromImage(image);
362 QPainter painter(&pix);
363 painter.drawRect(0, 0, width - 1, height - 1);
365 } else pix.fill(Qt::black);
369 int Render::frameRenderWidth() const
371 return m_mltProfile->width();
374 int Render::renderWidth() const
376 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
379 int Render::renderHeight() const
381 return m_mltProfile->height();
384 QImage Render::extractFrame(int frame_position, int width, int height)
387 width = renderWidth();
388 height = renderHeight();
389 } else if (width % 2 == 1) width++;
391 if (!m_mltProducer) {
392 QImage pix(width, height, QImage::Format_RGB32);
396 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
399 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
403 if (url.fileName().startsWith(".all.")) { // check for slideshow
404 QString fileType = url.fileName().right(3);
406 QStringList::Iterator it;
408 QDir dir(url.directory());
410 filter << "*." + fileType;
411 filter << "*." + fileType.toUpper();
412 more = dir.entryList(filter, QDir::Files);
413 im.load(url.directory() + '/' + more.at(0));
414 } else im.load(url.path());
415 //pixmap = im.scaled(width, height);
419 double Render::consumerRatio() const
421 if (!m_mltConsumer) return 1.0;
422 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
426 int Render::getLength()
430 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
431 return mlt_producer_get_playtime(m_mltProducer->get_producer());
436 bool Render::isValid(KUrl url)
438 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
439 if (producer.is_blank())
445 double Render::dar() const
447 return m_mltProfile->dar();
451 void Render::slotSplitView(bool doit)
453 m_isSplitView = doit;
454 Mlt::Service service(m_mltProducer->parent().get_service());
455 Mlt::Tractor tractor(service);
456 if (service.type() != tractor_type || tractor.count() < 2) return;
457 Mlt::Field *field = tractor.field();
459 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
460 Mlt::Producer trackProducer(tractor.track(i));
461 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
462 if (QString(trackProducer.get("hide")).toInt() != 1) {
463 kDebug() << "// ADIDNG TRACK: " << i;
464 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
465 transition->set("mlt_service", "composite");
466 transition->set("a_track", 0);
467 transition->set("b_track", i);
468 transition->set("distort", 1);
469 transition->set("internal_added", "200");
476 tmp = "50%,0:50%x50%";
479 tmp = "0,50%:50%x50%";
483 tmp = "50%,50%:50%x50%";
486 transition->set("geometry", tmp);
487 transition->set("always_active", "1");
488 field->plant_transition(*transition, 0, i);
493 m_mltConsumer->set("refresh", 1);
495 mlt_service serv = m_mltProducer->parent().get_service();
496 mlt_service nextservice = mlt_service_get_producer(serv);
497 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
498 QString mlt_type = mlt_properties_get(properties, "mlt_type");
499 QString resource = mlt_properties_get(properties, "mlt_service");
501 while (mlt_type == "transition") {
502 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
503 if (added == "200") {
504 mlt_field_disconnect_service(field->get_field(), nextservice);
506 nextservice = mlt_service_producer(nextservice);
507 if (nextservice == NULL) break;
508 properties = MLT_SERVICE_PROPERTIES(nextservice);
509 mlt_type = mlt_properties_get(properties, "mlt_type");
510 resource = mlt_properties_get(properties, "mlt_service");
511 m_mltConsumer->set("refresh", 1);
516 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
518 KUrl url = KUrl(xml.attribute("resource", QString()));
519 Mlt::Producer *producer = NULL;
520 CLIPTYPE type = (CLIPTYPE)xml.attribute("type").toInt();
522 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
523 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
524 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
529 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
530 } else if (type == TEXT) {
531 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
532 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
533 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
534 } else if (url.isEmpty()) {
536 QDomElement mlt = doc.createElement("mlt");
537 QDomElement play = doc.createElement("playlist");
538 doc.appendChild(mlt);
539 mlt.appendChild(play);
540 play.appendChild(doc.importNode(xml, true));
541 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
543 producer = new Mlt::Producer(*m_mltProfile, url.path().toUtf8().constData());
546 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
547 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
548 emit removeInvalidClip(clipId, replaceProducer);
553 if (xml.hasAttribute("force_aspect_ratio")) {
554 double aspect = xml.attribute("force_aspect_ratio").toDouble();
555 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
558 if (xml.hasAttribute("force_aspect_num") && xml.hasAttribute("force_aspect_den")) {
559 int width = xml.attribute("frame_size").section('x', 0, 0).toInt();
560 int height = xml.attribute("frame_size").section('x', 1, 1).toInt();
561 int aspectNumerator = xml.attribute("force_aspect_num").toInt();
562 int aspectDenominator = xml.attribute("force_aspect_den").toInt();
563 if (aspectDenominator != 0 && width != 0)
564 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
567 if (xml.hasAttribute("force_fps")) {
568 double fps = xml.attribute("force_fps").toDouble();
569 if (fps > 0) producer->set("force_fps", fps);
572 if (xml.hasAttribute("force_progressive")) {
574 int progressive = xml.attribute("force_progressive").toInt(&ok);
575 if (ok) producer->set("force_progressive", progressive);
577 if (xml.hasAttribute("force_tff")) {
579 int fieldOrder = xml.attribute("force_tff").toInt(&ok);
580 if (ok) producer->set("force_tff", fieldOrder);
582 if (xml.hasAttribute("threads")) {
583 int threads = xml.attribute("threads").toInt();
584 if (threads != 1) producer->set("threads", threads);
586 if (xml.hasAttribute("video_index")) {
587 int vindex = xml.attribute("video_index").toInt();
588 if (vindex != 0) producer->set("video_index", vindex);
590 if (xml.hasAttribute("audio_index")) {
591 int aindex = xml.attribute("audio_index").toInt();
592 if (aindex != 0) producer->set("audio_index", aindex);
594 if (xml.hasAttribute("force_colorspace")) {
595 int colorspace = xml.attribute("force_colorspace").toInt();
596 if (colorspace != 0) producer->set("force_colorspace", colorspace);
598 if (xml.hasAttribute("full_luma")) {
599 int full_luma = xml.attribute("full_luma").toInt();
600 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
603 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
604 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW)
605 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
607 if (xml.hasAttribute("out"))
608 producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
610 producer->set("id", clipId.toUtf8().constData());
612 if (xml.hasAttribute("templatetext"))
613 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
615 if (!replaceProducer && xml.hasAttribute("file_hash")) {
616 // Clip already has all properties
617 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
621 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
622 QMap < QString, QString > filePropertyMap;
623 QMap < QString, QString > metadataPropertyMap;
625 int frameNumber = xml.attribute("thumbnail", "0").toInt();
626 if (frameNumber != 0) producer->seek(frameNumber);
628 filePropertyMap["duration"] = QString::number(producer->get_playtime());
629 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
631 Mlt::Frame *frame = producer->get_frame();
633 if (type == SLIDESHOW) {
634 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
635 if (ttl) producer->set("ttl", ttl);
636 if (!xml.attribute("animation").isEmpty()) {
637 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
638 if (filter && filter->is_valid()) {
640 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
641 if (!geometry.isEmpty()) {
642 if (xml.attribute("animation").contains("low-pass")) {
643 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
644 if (blur && blur->is_valid())
645 producer->attach(*blur);
647 filter->set("transition.geometry", geometry.toUtf8().data());
648 filter->set("transition.cycle", cycle);
649 producer->attach(*filter);
653 if (xml.attribute("fade") == "1") {
654 // user wants a fade effect to slideshow
655 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
656 if (filter && filter->is_valid()) {
657 if (ttl) filter->set("cycle", ttl);
658 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
659 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
660 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
661 if (xml.hasAttribute("softness")) {
662 int soft = xml.attribute("softness").toInt();
663 filter->set("luma.softness", (double) soft / 100.0);
666 producer->attach(*filter);
669 if (xml.attribute("crop") == "1") {
670 // user wants to center crop the slides
671 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
672 if (filter && filter->is_valid()) {
673 filter->set("center", 1);
674 producer->attach(*filter);
679 if (producer->get_double("meta.media.frame_rate_den") > 0) {
680 filePropertyMap["fps"] = QString::number(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
681 } else filePropertyMap["fps"] = producer->get("source_fps");
683 if (frame && frame->is_valid()) {
684 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
685 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
686 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
687 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
689 if (frame->get_int("test_image") == 0) {
690 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
691 filePropertyMap["type"] = "playlist";
692 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
693 } else if (frame->get_int("test_audio") == 0)
694 filePropertyMap["type"] = "av";
696 filePropertyMap["type"] = "video";
698 mlt_image_format format = mlt_image_rgb24a;
699 int frame_width = width;
700 int frame_height = imageHeight;
701 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
702 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied);
705 if (!image.isNull()) {
706 if (frame_width > (2 * width)) {
707 // there was a scaling problem, do it manually
708 QImage scaled = image.scaled(width, imageHeight);
709 pix = QPixmap::fromImage(scaled.rgbSwapped());
710 } else pix = QPixmap::fromImage(image.rgbSwapped());
714 emit replyGetImage(clipId, pix);
716 } else if (frame->get_int("test_audio") == 0) {
717 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
718 emit replyGetImage(clipId, pixmap);
719 filePropertyMap["type"] = "audio";
723 // Retrieve audio / video codec name
727 if (producer->get_int("video_index") > -1) {
728 /*if (context->duration == AV_NOPTS_VALUE) {
729 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
730 emit removeInvalidClip(clipId);
734 // Get the video_index
735 int default_video = producer->get_int("video_index");
737 int default_audio = producer->get_int("audio_index");
740 // Find maximum stream index values
741 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
742 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
743 QString type = producer->get(property);
746 else if (type == "audio")
749 filePropertyMap["default_video"] = QString::number(default_video);
750 filePropertyMap["video_max"] = QString::number(video_max);
751 filePropertyMap["default_audio"] = QString::number(default_audio);
752 filePropertyMap["audio_max"] = QString::number(audio_max);
754 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
755 if (producer->get(property)) {
756 filePropertyMap["videocodec"] = producer->get(property);
758 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
759 if (producer->get(property))
760 filePropertyMap["videocodec"] = producer->get(property);
763 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
764 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
765 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
767 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
768 if (producer->get_int("audio_index") > -1) {
769 // Get the audio_index
770 int index = producer->get_int("audio_index");
772 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
773 if (producer->get(property)) {
774 filePropertyMap["audiocodec"] = producer->get(property);
776 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
777 if (producer->get(property))
778 filePropertyMap["audiocodec"] = producer->get(property);
783 Mlt::Properties metadata;
784 metadata.pass_values(*producer, "meta.attr.");
785 int count = metadata.count();
786 for (int i = 0; i < count; i ++) {
787 QString name = metadata.get_name(i);
788 QString value = QString::fromUtf8(metadata.get(i));
789 if (name.endsWith("markup") && !value.isEmpty())
790 metadataPropertyMap[ name.section('.', 0, -2)] = value;
793 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
794 // FIXME: should delete this to avoid a leak...
800 /** Create the producer from the MLT XML QDomDocument */
801 void Render::initSceneList()
803 kDebug() << "-------- INIT SCENE LIST ------_";
805 QDomElement mlt = doc.createElement("mlt");
806 doc.appendChild(mlt);
807 QDomElement prod = doc.createElement("producer");
808 prod.setAttribute("resource", "colour");
809 prod.setAttribute("colour", "red");
810 prod.setAttribute("id", "black");
811 prod.setAttribute("in", "0");
812 prod.setAttribute("out", "0");
814 QDomElement tractor = doc.createElement("tractor");
815 QDomElement multitrack = doc.createElement("multitrack");
817 QDomElement playlist1 = doc.createElement("playlist");
818 playlist1.appendChild(prod);
819 multitrack.appendChild(playlist1);
820 QDomElement playlist2 = doc.createElement("playlist");
821 multitrack.appendChild(playlist2);
822 QDomElement playlist3 = doc.createElement("playlist");
823 multitrack.appendChild(playlist3);
824 QDomElement playlist4 = doc.createElement("playlist");
825 multitrack.appendChild(playlist4);
826 QDomElement playlist5 = doc.createElement("playlist");
827 multitrack.appendChild(playlist5);
828 tractor.appendChild(multitrack);
829 mlt.appendChild(tractor);
830 // kDebug()<<doc.toString();
832 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
833 setSceneList(doc, 0);
837 int Render::setProducer(Mlt::Producer *producer, int position)
839 if (m_winid == -1) return -1;
842 m_mltConsumer->stop();
845 m_mltConsumer->purge();
848 m_mltProducer->set_speed(0);
849 delete m_mltProducer;
850 m_mltProducer = NULL;
854 m_mltProducer = new Mlt::Producer(producer->get_producer());
855 } else m_mltProducer = m_blackClip->cut(0, 50);
857 if (!m_mltProducer || !m_mltProducer->is_valid()) {
858 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
861 int volume = KdenliveSettings::volume();
862 m_mltProducer->set("meta.volume", (double)volume / 100);
863 m_fps = m_mltProducer->get_fps();
864 int error = connectPlaylist();
866 if (position != -1) {
867 m_mltProducer->seek(position);
868 emit rendererPosition(position);
869 } else emit rendererPosition((int) m_mltProducer->position());
874 int Render::setSceneList(QDomDocument list, int position)
876 return setSceneList(list.toString(), position);
879 int Render::setSceneList(QString playlist, int position)
881 if (m_winid == -1) return -1;
885 //kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
888 if (!m_mltConsumer->is_stopped()) {
889 m_mltConsumer->stop();
891 m_mltConsumer->set("refresh", 0);
893 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
898 m_mltProducer->set_speed(0);
899 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
902 Mlt::Service service(m_mltProducer->parent().get_service());
903 mlt_service_lock(service.get_service());
905 if (service.type() == tractor_type) {
906 Mlt::Tractor tractor(service);
907 Mlt::Field *field = tractor.field();
908 mlt_service nextservice = mlt_service_get_producer(service.get_service());
909 mlt_service nextservicetodisconnect;
910 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
911 QString mlt_type = mlt_properties_get(properties, "mlt_type");
912 QString resource = mlt_properties_get(properties, "mlt_service");
913 // Delete all transitions
914 while (mlt_type == "transition") {
915 nextservicetodisconnect = nextservice;
916 nextservice = mlt_service_producer(nextservice);
917 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
918 if (nextservice == NULL) break;
919 properties = MLT_SERVICE_PROPERTIES(nextservice);
920 mlt_type = mlt_properties_get(properties, "mlt_type");
921 resource = mlt_properties_get(properties, "mlt_service");
924 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
925 Mlt::Producer trackProducer(tractor.track(trackNb));
926 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
927 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
931 mlt_service_unlock(service.get_service());
933 qDeleteAll(m_slowmotionProducers.values());
934 m_slowmotionProducers.clear();
936 delete m_mltProducer;
937 m_mltProducer = NULL;
943 // TODO: Better way to do this
944 if (KdenliveSettings::projectloading_avformatnovalidate())
945 playlist.replace(">avformat</property>", ">avformat-novalidate</property>");
947 playlist.replace(">avformat-novalidate</property>", ">avformat</property>");
949 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
951 if (!m_mltProducer || !m_mltProducer->is_valid()) {
952 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
953 m_mltProducer = m_blackClip->cut(0, 50);
956 int volume = KdenliveSettings::volume();
957 m_mltProducer->set("meta.volume", (double)volume / 100);
958 m_mltProducer->optimise();
960 /*if (KdenliveSettings::osdtimecode()) {
961 // Attach filter for on screen display of timecode
963 QString attr = "attr_check";
964 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
965 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
966 mlt_producer_attach( m_mltProducer->get_producer(), filter );
967 mlt_filter_close( filter );
969 m_osdInfo = new Mlt::Filter("data_show");
970 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
971 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
972 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
973 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
974 m_osdInfo->set("dynamic", "1");
976 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
978 m_osdInfo->set("dynamic", "0");
981 m_fps = m_mltProducer->get_fps();
983 // Seek to correct place after opening project.
984 m_mltProducer->seek(position);
987 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
988 if (error == 0) error = connectPlaylist();
989 else connectPlaylist();
990 fillSlowMotionProducers();
996 //kDebug()<<"// SETSCN LST, POS: "<<position;
997 //if (position != 0) emit rendererPosition(position);
1000 const QString Render::sceneList()
1003 Mlt::Profile profile((mlt_profile) 0);
1004 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1005 m_mltProducer->optimise();
1006 xmlConsumer.set("terminate_on_pause", 1);
1007 Mlt::Producer prod(m_mltProducer->get_producer());
1008 bool split = m_isSplitView;
1009 if (split) slotSplitView(false);
1010 xmlConsumer.connect(prod);
1011 xmlConsumer.start();
1012 while (!xmlConsumer.is_stopped()) {}
1013 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1014 if (split) slotSplitView(true);
1018 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1022 doc.setContent(sceneList(), false);
1023 if (!kdenliveData.isNull()) {
1024 // add Kdenlive specific tags
1025 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1026 mlt.appendChild(doc.importNode(kdenliveData, true));
1028 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1029 kWarning() << "////// ERROR writing to file: " << path;
1032 file.write(doc.toString().toUtf8());
1033 if (file.error() != QFile::NoError) {
1041 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1043 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1044 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1045 m_mltProducer->optimise();
1046 xmlConsumer.set("terminate_on_pause", 1);
1047 if (m_name == "clip") {
1048 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1050 list.insert_at(0, prod, 0);
1052 list.set("title", desc.toUtf8().constData());
1053 xmlConsumer.connect(list);
1056 //TODO: not working yet, save zone from timeline
1057 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1058 /* Mlt::Service service(p1->parent().get_service());
1059 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1061 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1062 //prod->set("title", desc.toUtf8().constData());
1063 xmlConsumer.connect(*p1); //list);
1066 xmlConsumer.start();
1069 double Render::fps() const
1074 int Render::connectPlaylist()
1076 if (!m_mltConsumer) return -1;
1077 //m_mltConsumer->set("refresh", "0");
1078 m_mltConsumer->connect(*m_mltProducer);
1079 m_mltProducer->set_speed(0);
1080 if (m_mltConsumer->start() == -1) {
1081 // ARGH CONSUMER BROKEN!!!!
1082 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."));
1083 delete m_mltConsumer;
1084 m_mltConsumer = NULL;
1087 emit durationChanged(m_mltProducer->get_playtime());
1092 void Render::refreshDisplay()
1095 if (!m_mltProducer) return;
1096 //m_mltConsumer->set("refresh", 0);
1098 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1099 /*if (KdenliveSettings::osdtimecode()) {
1100 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1101 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1102 m_osdInfo->set("dynamic", "1");
1103 m_mltProducer->attach(*m_osdInfo);
1106 m_mltProducer->detach(*m_osdInfo);
1107 m_osdInfo->set("dynamic", "0");
1112 int Render::volume() const
1114 if (!m_mltConsumer || !m_mltProducer) return -1;
1115 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1118 void Render::slotSetVolume(int volume)
1120 if (!m_mltConsumer || !m_mltProducer) return;
1121 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1124 m_mltConsumer->set("refresh", 0);
1125 // Attach filter for on screen display of timecode
1126 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1127 mlt_properties_set_double( properties, "meta.volume", volume );
1128 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1129 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1131 if (!KdenliveSettings::osdtimecode()) {
1132 m_mltProducer->detach(*m_osdInfo);
1133 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1134 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1137 //m_osdTimer->setSingleShot(2500);
1140 void Render::slotOsdTimeout()
1142 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1143 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1144 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1145 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1149 void Render::start()
1151 kDebug() << "----- STARTING MONITOR: " << m_name;
1152 if (m_winid == -1) {
1153 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1156 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1157 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1158 if (m_mltConsumer->start() == -1) {
1159 //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."));
1160 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1162 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1163 m_isBlocked = false;
1167 m_isBlocked = false;
1172 if (m_mltProducer == NULL) return;
1173 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1174 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1176 //m_mltConsumer->set("refresh", 0);
1177 m_mltConsumer->stop();
1178 // delete m_mltConsumer;
1179 // m_mltConsumer = NULL;
1181 kDebug() << "///////////// RENDER STOP2-------";
1184 if (m_mltProducer) {
1185 if (m_isZoneMode) resetZoneMode();
1186 m_mltProducer->set_speed(0.0);
1187 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1188 //kDebug() << m_mltProducer->get_length();
1190 kDebug() << "///////////// RENDER STOP3-------";
1193 void Render::stop(const GenTime & startTime)
1196 kDebug() << "///////////// RENDER STOP-------2";
1197 if (m_mltProducer) {
1198 if (m_isZoneMode) resetZoneMode();
1199 m_mltProducer->set_speed(0.0);
1200 m_mltProducer->seek((int) startTime.frames(m_fps));
1202 m_mltConsumer->purge();
1205 void Render::pause()
1207 if (!m_mltProducer || !m_mltConsumer)
1209 if (m_mltProducer->get_speed() == 0.0) return;
1210 if (m_isZoneMode) resetZoneMode();
1212 m_mltConsumer->set("refresh", 0);
1213 m_mltProducer->set_speed(0.0);
1215 The 2 lines below create a flicker loop
1216 emit rendererPosition(m_framePosition);
1217 m_mltProducer->seek(m_framePosition);*/
1218 m_mltConsumer->purge();
1221 void Render::switchPlay()
1223 if (!m_mltProducer || !m_mltConsumer)
1225 if (m_isZoneMode) resetZoneMode();
1226 if (m_mltProducer->get_speed() == 0.0) {
1227 m_isBlocked = false;
1228 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1229 m_mltProducer->set_speed(1.0);
1230 m_mltConsumer->set("refresh", 1);
1233 m_mltConsumer->set("refresh", 0);
1234 m_mltProducer->set_speed(0.0);
1235 //emit rendererPosition(m_framePosition);
1236 m_mltProducer->seek(m_framePosition);
1237 m_mltConsumer->purge();
1238 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1239 //m_mltConsumer->set("refresh", 0);
1240 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1241 m_mltProducer->set_speed(0);
1242 m_mltProducer->seek( position );
1243 //m_mltProducer->seek((int) m_framePosition);
1244 m_isBlocked = false;*/
1246 /*if (speed == 0.0) {
1247 m_mltProducer->seek((int) m_framePosition + 1);
1248 m_mltConsumer->purge();
1253 void Render::play(double speed)
1257 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1258 m_isBlocked = false;
1259 m_mltProducer->set_speed(speed);
1260 /*if (speed == 0.0) {
1261 m_mltProducer->seek((int) m_framePosition + 1);
1262 m_mltConsumer->purge();
1267 void Render::play(const GenTime & startTime)
1269 if (!m_mltProducer || !m_mltConsumer)
1271 m_isBlocked = false;
1272 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1273 m_mltProducer->set_speed(1.0);
1274 m_mltConsumer->set("refresh", 1);
1277 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1279 if (!m_mltProducer || !m_mltConsumer)
1281 //m_mltProducer->set("eof", "loop");
1282 m_isLoopMode = true;
1283 m_loopStart = startTime;
1284 playZone(startTime, stopTime);
1287 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1289 if (!m_mltProducer || !m_mltConsumer)
1291 m_isBlocked = false;
1292 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1293 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1294 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1295 m_mltProducer->set_speed(1.0);
1296 m_mltConsumer->set("refresh", 1);
1297 m_isZoneMode = true;
1300 void Render::resetZoneMode()
1302 if (!m_isZoneMode && !m_isLoopMode) return;
1303 m_mltProducer->set("out", m_originalOut);
1304 //m_mltProducer->set("eof", "pause");
1305 m_isZoneMode = false;
1306 m_isLoopMode = false;
1309 void Render::seekToFrame(int pos)
1311 //kDebug()<<" ********* RENDER SEEK TO POS";
1314 m_isBlocked = false;
1316 m_mltProducer->seek(pos);
1320 void Render::seekToFrameDiff(int diff)
1322 //kDebug()<<" ********* RENDER SEEK TO POS";
1325 m_isBlocked = false;
1327 m_mltProducer->seek(m_mltProducer->position() + diff);
1331 void Render::doRefresh()
1333 // Use a Timer so that we don't refresh too much
1334 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1337 void Render::refresh()
1339 if (!m_mltProducer || m_isBlocked)
1341 if (m_mltConsumer) {
1342 m_mltConsumer->set("refresh", 1);
1346 void Render::setDropFrames(bool show)
1348 if (m_mltConsumer) {
1350 if (show == false) dropFrames = 0;
1351 m_mltConsumer->stop();
1353 m_mltConsumer->set("real_time", dropFrames);
1355 m_mltConsumer->set("play.real_time", dropFrames);
1357 if (m_mltConsumer->start() == -1) {
1358 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1364 double Render::playSpeed()
1366 if (m_mltProducer) return m_mltProducer->get_speed();
1370 GenTime Render::seekPosition() const
1372 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1373 else return GenTime();
1376 int Render::seekFramePosition() const
1378 if (m_mltProducer) return (int) m_mltProducer->position();
1382 const QString & Render::rendererName() const
1387 void Render::emitFrameUpdated(Mlt::Frame& frame)
1389 mlt_image_format format = mlt_image_rgb24a;
1392 const uchar* image = frame.get_image(format, width, height);
1393 QImage qimage(width, height, QImage::Format_ARGB32);
1394 memcpy(qimage.bits(), image, width * height * 4);
1395 emit frameUpdated(qimage.rgbSwapped());
1398 void Render::emitFrameNumber(double position)
1400 m_framePosition = position;
1401 emit rendererPosition((int) position);
1404 void Render::emitConsumerStopped()
1406 // This is used to know when the playing stopped
1407 if (m_mltProducer) {
1408 double pos = m_mltProducer->position();
1409 if (m_isLoopMode) play(m_loopStart);
1410 else if (m_isZoneMode) resetZoneMode();
1411 emit rendererStopped((int) pos);
1415 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1417 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1420 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1422 if (!m_mltProducer) {
1423 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1427 //int height = 1080;//KdenliveSettings::defaultheight();
1428 //int width = 1940; //KdenliveSettings::displaywidth();
1430 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1432 QPixmap pix(width, height);
1433 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1434 m_convert.set("forced", mlt_image_rgb24a);
1435 m_mltProducer->attach(m_convert);
1436 Mlt::Frame * frame = m_mltProducer->get_frame();
1437 m_mltProducer->detach(m_convert);
1439 pix = frameThumbnail(frame, width, height);
1442 pix.save(url.path(), "PNG");
1443 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1447 void Render::showFrame(Mlt::Frame& frame)
1449 m_framePosition = qMax(frame.get_int("_position"), 0);
1450 emit rendererPosition((int) m_framePosition);
1451 mlt_image_format format = mlt_image_rgb24a;
1454 const uchar* image = frame.get_image(format, width, height);
1455 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1456 memcpy(qimage.scanLine(0), image, width * height * 4);
1457 emit showImageSignal(qimage);
1458 if (analyseAudio) showAudio(frame);
1459 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1460 emit frameUpdated(qimage.rgbSwapped());
1464 void Render::showAudio(Mlt::Frame& frame)
1466 if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
1467 mlt_audio_format audio_format = mlt_audio_s16;
1469 int num_channels = 0;
1471 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1474 int num_samples = samples > 200 ? 200 : samples;
1475 QByteArray channels;
1476 for (int i = 0; i < num_channels; i++) {
1478 for (int s = 0; s < num_samples; s ++) {
1479 val += abs(data[i+s*num_channels] / 128);
1481 channels.append(val / num_samples);
1486 emit showAudioSignal(channels);
1488 emit showAudioSignal(QByteArray());
1492 * MLT playlist direct manipulation.
1495 void Render::mltCheckLength(Mlt::Tractor *tractor)
1497 //kDebug()<<"checking track length: "<<track<<"..........";
1499 int trackNb = tractor->count();
1503 Mlt::Producer trackProducer(tractor->track(0));
1504 duration = trackProducer.get_playtime() - 1;
1505 m_mltProducer->set("out", duration);
1506 emit durationChanged(duration);
1509 while (trackNb > 1) {
1510 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1511 trackDuration = trackProducer.get_playtime() - 1;
1512 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1513 if (trackDuration > duration) duration = trackDuration;
1517 Mlt::Producer blackTrackProducer(tractor->track(0));
1519 if (blackTrackProducer.get_playtime() - 1 != duration) {
1520 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1521 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1522 if (blackclip && blackclip->is_blank()) {
1527 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1528 blackTrackPlaylist.clear();
1529 m_blackClip->set("length", duration + 1);
1530 m_blackClip->set("out", duration);
1531 blackclip = m_blackClip->cut(0, duration);
1532 blackTrackPlaylist.insert_at(0, blackclip, 1);
1534 if (duration > blackclip->parent().get_length()) {
1535 blackclip->parent().set("length", duration + 1);
1536 blackclip->parent().set("out", duration);
1537 blackclip->set("length", duration + 1);
1539 blackTrackPlaylist.resize_clip(0, 0, duration);
1543 m_mltProducer->set("out", duration);
1544 emit durationChanged(duration);
1548 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1550 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1552 // We want a slowmotion producer
1553 double speed = element.attribute("speed", "1.0").toDouble();
1554 int strobe = element.attribute("strobe", "1").toInt();
1555 QString url = QString::fromUtf8(prod->get("resource"));
1556 url.append('?' + QString::number(speed));
1557 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1558 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1559 if (!slowprod || slowprod->get_producer() == NULL) {
1560 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1561 if (strobe > 1) slowprod->set("strobe", strobe);
1562 QString id = prod->get("id");
1563 if (id.contains('_')) id = id.section('_', 0, 0);
1564 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1565 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1566 slowprod->set("id", producerid.toUtf8().constData());
1567 m_slowmotionProducers.insert(url, slowprod);
1572 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1574 if (m_mltProducer == NULL) {
1575 kDebug() << "PLAYLIST NOT INITIALISED //////";
1579 kDebug() << "Cannot insert clip without producer //////";
1582 Mlt::Producer parentProd(m_mltProducer->parent());
1583 if (parentProd.get_producer() == NULL) {
1584 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1588 Mlt::Service service(parentProd.get_service());
1589 if (service.type() != tractor_type) {
1590 kWarning() << "// TRACTOR PROBLEM";
1593 Mlt::Tractor tractor(service);
1594 if (info.track > tractor.count() - 1) {
1595 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1598 mlt_service_lock(service.get_service());
1599 Mlt::Producer trackProducer(tractor.track(info.track));
1600 int trackDuration = trackProducer.get_playtime() - 1;
1601 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1602 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1603 prod = checkSlowMotionProducer(prod, element);
1604 if (prod == NULL || !prod->is_valid()) {
1605 mlt_service_unlock(service.get_service());
1609 int cutPos = (int) info.cropStart.frames(m_fps);
1610 if (cutPos < 0) cutPos = 0;
1611 int insertPos = (int) info.startPos.frames(m_fps);
1612 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1613 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1614 if (overwrite && (insertPos < trackDuration)) {
1615 // Replace zone with blanks
1616 //trackPlaylist.split_at(insertPos, true);
1617 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1618 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1619 trackPlaylist.insert_blank(clipIndex, cutDuration);
1621 trackPlaylist.split_at(insertPos, true);
1622 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1623 trackPlaylist.insert_blank(clipIndex, cutDuration);
1625 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1627 /*if (QString(prod->get("transparency")).toInt() == 1)
1628 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1630 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1631 mlt_service_unlock(service.get_service());
1632 /*tractor.multitrack()->refresh();
1633 tractor.refresh();*/
1638 void Render::mltCutClip(int track, GenTime position)
1642 Mlt::Service service(m_mltProducer->parent().get_service());
1643 if (service.type() != tractor_type) {
1644 kWarning() << "// TRACTOR PROBLEM";
1648 Mlt::Tractor tractor(service);
1649 Mlt::Producer trackProducer(tractor.track(track));
1650 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1653 /* // Display playlist info
1654 kDebug()<<"//////////// BEFORE";
1655 for (int i = 0; i < trackPlaylist.count(); i++) {
1656 int blankStart = trackPlaylist.clip_start(i);
1657 int blankDuration = trackPlaylist.clip_length(i) - 1;
1659 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1660 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1663 int cutPos = (int) position.frames(m_fps);
1665 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1666 if (trackPlaylist.is_blank(clipIndex)) {
1667 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1668 m_isBlocked = false;
1671 mlt_service_lock(service.get_service());
1672 int clipStart = trackPlaylist.clip_start(clipIndex);
1673 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1674 mlt_service_unlock(service.get_service());
1676 // duplicate effects
1677 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1678 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1680 if (original == NULL || clip == NULL) {
1681 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1683 Mlt::Service clipService(original->get_service());
1684 Mlt::Service dupService(clip->get_service());
1688 Mlt::Filter *filter = clipService.filter(ct);
1690 // Only duplicate Kdenlive filters, and skip the fade in effects
1691 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1692 // looks like there is no easy way to duplicate a filter,
1693 // so we will create a new one and duplicate its properties
1694 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1695 if (dup && dup->is_valid()) {
1696 Mlt::Properties entries(filter->get_properties());
1697 for (int i = 0; i < entries.count(); i++) {
1698 dup->set(entries.get_name(i), entries.get(i));
1700 dupService.attach(*dup);
1704 filter = clipService.filter(ct);
1707 /* // Display playlist info
1708 kDebug()<<"//////////// AFTER";
1709 for (int i = 0; i < trackPlaylist.count(); i++) {
1710 int blankStart = trackPlaylist.clip_start(i);
1711 int blankDuration = trackPlaylist.clip_length(i) - 1;
1713 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1714 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1717 m_isBlocked = false;
1720 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1724 kDebug() << "Cannot update clip with null producer //////";
1727 Mlt::Service service(m_mltProducer->parent().get_service());
1728 if (service.type() != tractor_type) {
1729 kWarning() << "// TRACTOR PROBLEM";
1732 Mlt::Tractor tractor(service);
1733 Mlt::Producer trackProducer(tractor.track(info.track));
1734 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1735 int startPos = info.startPos.frames(m_fps);
1736 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1737 if (trackPlaylist.is_blank(clipIndex)) {
1738 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1741 mlt_service_lock(service.get_service());
1742 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1744 QList <Mlt::Filter *> filtersList;
1745 Mlt::Service sourceService(clip->get_service());
1747 Mlt::Filter *filter = sourceService.filter(ct);
1749 if (filter->get_int("kdenlive_ix") != 0) {
1750 filtersList.append(filter);
1753 filter = sourceService.filter(ct);
1756 trackPlaylist.replace_with_blank(clipIndex);
1758 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1759 prod = checkSlowMotionProducer(prod, element);
1760 if (prod == NULL || !prod->is_valid()) {
1761 mlt_service_unlock(service.get_service());
1764 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1765 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1769 //if (mltInsertClip(info, element, prod) == -1) return false;
1770 if (!filtersList.isEmpty()) {
1771 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1772 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1773 Mlt::Service destService(destclip->get_service());
1775 for (int i = 0; i < filtersList.count(); i++)
1776 destService.attach(*(filtersList.at(i)));
1778 mlt_service_unlock(service.get_service());
1783 bool Render::mltRemoveClip(int track, GenTime position)
1785 Mlt::Service service(m_mltProducer->parent().get_service());
1786 if (service.type() != tractor_type) {
1787 kWarning() << "// TRACTOR PROBLEM";
1791 Mlt::Tractor tractor(service);
1792 mlt_service_lock(service.get_service());
1793 Mlt::Producer trackProducer(tractor.track(track));
1794 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1795 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1797 // Display playlist info
1798 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1799 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1800 int blankStart = trackPlaylist.clip_start(i);
1801 int blankDuration = trackPlaylist.clip_length(i) - 1;
1803 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1804 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1806 if (trackPlaylist.is_blank(clipIndex)) {
1807 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1808 mlt_service_unlock(service.get_service());
1811 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1813 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1814 if (clip) delete clip;
1815 trackPlaylist.consolidate_blanks(0);
1816 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1817 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1819 /* // Display playlist info
1820 kDebug()<<"//// AFTER";
1821 for (int i = 0; i < trackPlaylist.count(); i++) {
1822 int blankStart = trackPlaylist.clip_start(i);
1823 int blankDuration = trackPlaylist.clip_length(i) - 1;
1825 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1826 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1828 mlt_service_unlock(service.get_service());
1829 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1830 m_isBlocked = false;
1834 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1836 if (!m_mltProducer) {
1837 kDebug() << "PLAYLIST NOT INITIALISED //////";
1840 Mlt::Producer parentProd(m_mltProducer->parent());
1841 if (parentProd.get_producer() == NULL) {
1842 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1846 Mlt::Service service(parentProd.get_service());
1847 Mlt::Tractor tractor(service);
1848 int insertPos = pos.frames(m_fps);
1850 Mlt::Producer trackProducer(tractor.track(track));
1851 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1852 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1853 if (clipIndex == trackPlaylist.count()) {
1854 // We are after the end of the playlist
1857 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1858 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1859 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1862 int Render::mltTrackDuration(int track)
1864 if (!m_mltProducer) {
1865 kDebug() << "PLAYLIST NOT INITIALISED //////";
1868 Mlt::Producer parentProd(m_mltProducer->parent());
1869 if (parentProd.get_producer() == NULL) {
1870 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1874 Mlt::Service service(parentProd.get_service());
1875 Mlt::Tractor tractor(service);
1877 Mlt::Producer trackProducer(tractor.track(track));
1878 return trackProducer.get_playtime() - 1;
1881 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1883 if (!m_mltProducer) {
1884 kDebug() << "PLAYLIST NOT INITIALISED //////";
1887 Mlt::Producer parentProd(m_mltProducer->parent());
1888 if (parentProd.get_producer() == NULL) {
1889 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1892 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1893 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1895 Mlt::Service service(parentProd.get_service());
1896 Mlt::Tractor tractor(service);
1897 mlt_service_lock(service.get_service());
1898 int diff = duration.frames(m_fps);
1899 int offset = timeOffset.frames(m_fps);
1903 // insert space in one track only
1904 Mlt::Producer trackProducer(tractor.track(track));
1905 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1906 insertPos = trackClipStartList.value(track);
1907 if (insertPos != -1) {
1908 insertPos += offset;
1909 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1911 trackPlaylist.insert_blank(clipIndex, diff - 1);
1913 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1914 if (!trackPlaylist.is_blank(clipIndex)) {
1915 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1917 int position = trackPlaylist.clip_start(clipIndex);
1918 int blankDuration = trackPlaylist.clip_length(clipIndex);
1920 if (blankDuration - diff == 0) {
1921 trackPlaylist.remove(clipIndex);
1922 } else trackPlaylist.remove_region(position, diff);
1924 trackPlaylist.consolidate_blanks(0);
1926 // now move transitions
1927 mlt_service serv = m_mltProducer->parent().get_service();
1928 mlt_service nextservice = mlt_service_get_producer(serv);
1929 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1930 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1931 QString resource = mlt_properties_get(properties, "mlt_service");
1933 while (mlt_type == "transition") {
1934 mlt_transition tr = (mlt_transition) nextservice;
1935 int currentTrack = mlt_transition_get_b_track(tr);
1936 int currentIn = (int) mlt_transition_get_in(tr);
1937 int currentOut = (int) mlt_transition_get_out(tr);
1938 insertPos = trackTransitionStartList.value(track);
1939 if (insertPos != -1) {
1940 insertPos += offset;
1941 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1942 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1945 nextservice = mlt_service_producer(nextservice);
1946 if (nextservice == NULL) break;
1947 properties = MLT_SERVICE_PROPERTIES(nextservice);
1948 mlt_type = mlt_properties_get(properties, "mlt_type");
1949 resource = mlt_properties_get(properties, "mlt_service");
1952 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1953 Mlt::Producer trackProducer(tractor.track(trackNb));
1954 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1956 //int clipNb = trackPlaylist.count();
1957 insertPos = trackClipStartList.value(trackNb);
1958 if (insertPos != -1) {
1959 insertPos += offset;
1961 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1962 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1963 for (int i = 0; i < clipNb; i++) {
1964 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1965 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1966 kDebug()<<"-------------";
1968 kDebug()<<"END-------------";*/
1971 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1973 trackPlaylist.insert_blank(clipIndex, diff - 1);
1975 if (!trackPlaylist.is_blank(clipIndex)) {
1978 if (!trackPlaylist.is_blank(clipIndex)) {
1979 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1981 int position = trackPlaylist.clip_start(clipIndex);
1982 int blankDuration = trackPlaylist.clip_length(clipIndex);
1983 if (diff + blankDuration == 0) {
1984 trackPlaylist.remove(clipIndex);
1985 } else trackPlaylist.remove_region(position, - diff);
1987 trackPlaylist.consolidate_blanks(0);
1990 // now move transitions
1991 mlt_service serv = m_mltProducer->parent().get_service();
1992 mlt_service nextservice = mlt_service_get_producer(serv);
1993 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1994 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1995 QString resource = mlt_properties_get(properties, "mlt_service");
1997 while (mlt_type == "transition") {
1998 mlt_transition tr = (mlt_transition) nextservice;
1999 int currentIn = (int) mlt_transition_get_in(tr);
2000 int currentOut = (int) mlt_transition_get_out(tr);
2001 int currentTrack = mlt_transition_get_b_track(tr);
2002 insertPos = trackTransitionStartList.value(currentTrack);
2003 if (insertPos != -1) {
2004 insertPos += offset;
2005 if (currentOut > insertPos && resource != "mix") {
2006 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2009 nextservice = mlt_service_producer(nextservice);
2010 if (nextservice == NULL) break;
2011 properties = MLT_SERVICE_PROPERTIES(nextservice);
2012 mlt_type = mlt_properties_get(properties, "mlt_type");
2013 resource = mlt_properties_get(properties, "mlt_service");
2016 mlt_service_unlock(service.get_service());
2017 mltCheckLength(&tractor);
2018 m_mltConsumer->set("refresh", 1);
2022 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2024 if (source == dest) return;
2025 Mlt::Service sourceService(source->get_service());
2026 Mlt::Service destService(dest->get_service());
2028 // move all effects to the correct producer
2030 Mlt::Filter *filter = sourceService.filter(ct);
2032 if (filter->get_int("kdenlive_ix") != 0) {
2033 sourceService.detach(*filter);
2034 destService.attach(*filter);
2036 filter = sourceService.filter(ct);
2040 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2044 Mlt::Service service(m_mltProducer->parent().get_service());
2045 if (service.type() != tractor_type) {
2046 kWarning() << "// TRACTOR PROBLEM";
2049 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2050 Mlt::Tractor tractor(service);
2051 Mlt::Producer trackProducer(tractor.track(info.track));
2052 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2053 int startPos = info.startPos.frames(m_fps);
2054 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2055 int clipLength = trackPlaylist.clip_length(clipIndex);
2057 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2058 if (original == NULL) {
2061 if (!original->is_valid() || original->is_blank()) {
2066 Mlt::Producer clipparent = original->parent();
2067 if (!clipparent.is_valid() || clipparent.is_blank()) {
2073 QString serv = clipparent.get("mlt_service");
2074 QString id = clipparent.get("id");
2075 if (speed <= 0 && speed > -1) speed = 1.0;
2076 //kDebug() << "CLIP SERVICE: " << serv;
2077 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2078 mlt_service_lock(service.get_service());
2079 QString url = QString::fromUtf8(clipparent.get("resource"));
2080 url.append('?' + QString::number(speed));
2081 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2082 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2083 if (!slowprod || slowprod->get_producer() == NULL) {
2084 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2085 if (strobe > 1) slowprod->set("strobe", strobe);
2086 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2087 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2088 slowprod->set("id", producerid.toUtf8().constData());
2089 // copy producer props
2090 double ar = original->parent().get_double("force_aspect_ratio");
2091 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2092 double fps = original->parent().get_double("force_fps");
2093 if (fps != 0.0) slowprod->set("force_fps", fps);
2094 int threads = original->parent().get_int("threads");
2095 if (threads != 0) slowprod->set("threads", threads);
2096 if (original->parent().get("force_progressive"))
2097 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2098 if (original->parent().get("force_tff"))
2099 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2100 int ix = original->parent().get_int("video_index");
2101 if (ix != 0) slowprod->set("video_index", ix);
2102 int colorspace = original->parent().get_int("force_colorspace");
2103 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2104 int full_luma = original->parent().get_int("set.force_full_luma");
2105 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2106 m_slowmotionProducers.insert(url, slowprod);
2108 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2109 trackPlaylist.consolidate_blanks(0);
2111 // Check that the blank space is long enough for our new duration
2112 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2113 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2115 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2116 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2117 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2118 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2120 // move all effects to the correct producer
2121 mltPasteEffects(clip, cut);
2122 trackPlaylist.insert_at(startPos, cut, 1);
2125 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2126 newLength = trackPlaylist.clip_length(clipIndex);
2127 mlt_service_unlock(service.get_service());
2128 } else if (speed == 1.0 && strobe < 2) {
2129 mlt_service_lock(service.get_service());
2131 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2132 trackPlaylist.consolidate_blanks(0);
2134 // Check that the blank space is long enough for our new duration
2135 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2136 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2139 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2140 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2141 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2142 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2143 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2145 // move all effects to the correct producer
2146 mltPasteEffects(clip, cut);
2148 trackPlaylist.insert_at(startPos, cut, 1);
2151 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2152 newLength = trackPlaylist.clip_length(clipIndex);
2153 mlt_service_unlock(service.get_service());
2155 } else if (serv == "framebuffer") {
2156 mlt_service_lock(service.get_service());
2157 QString url = QString::fromUtf8(clipparent.get("resource"));
2158 url = url.section('?', 0, 0);
2159 url.append('?' + QString::number(speed));
2160 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2161 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2162 if (!slowprod || slowprod->get_producer() == NULL) {
2163 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2164 slowprod->set("strobe", strobe);
2165 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2166 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2167 slowprod->set("id", producerid.toUtf8().constData());
2168 // copy producer props
2169 double ar = original->parent().get_double("force_aspect_ratio");
2170 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2171 double fps = original->parent().get_double("force_fps");
2172 if (fps != 0.0) slowprod->set("force_fps", fps);
2173 if (original->parent().get("force_progressive"))
2174 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2175 if (original->parent().get("force_tff"))
2176 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2177 int threads = original->parent().get_int("threads");
2178 if (threads != 0) slowprod->set("threads", threads);
2179 int ix = original->parent().get_int("video_index");
2180 if (ix != 0) slowprod->set("video_index", ix);
2181 int colorspace = original->parent().get_int("force_colorspace");
2182 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2183 int full_luma = original->parent().get_int("set.force_full_luma");
2184 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2185 m_slowmotionProducers.insert(url, slowprod);
2187 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2188 trackPlaylist.consolidate_blanks(0);
2190 GenTime duration = speedIndependantInfo.cropDuration / speed;
2191 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2193 // Check that the blank space is long enough for our new duration
2194 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2195 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2198 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2199 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2200 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2201 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2203 // move all effects to the correct producer
2204 mltPasteEffects(clip, cut);
2206 trackPlaylist.insert_at(startPos, cut, 1);
2209 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2210 newLength = trackPlaylist.clip_length(clipIndex);
2212 mlt_service_unlock(service.get_service());
2215 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2216 m_isBlocked = false;
2220 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2222 Mlt::Service service(m_mltProducer->parent().get_service());
2223 bool success = false;
2224 Mlt::Tractor tractor(service);
2225 Mlt::Producer trackProducer(tractor.track(track));
2226 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2227 Mlt::Service clipService(trackPlaylist.get_service());
2230 mlt_service_lock(service.get_service());
2232 Mlt::Filter *filter = clipService.filter(ct);
2234 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2235 if (clipService.detach(*filter) == 0) success = true;
2236 } else if (updateIndex) {
2237 // Adjust the other effects index
2238 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2241 filter = clipService.filter(ct);
2243 m_isBlocked = false;
2244 mlt_service_unlock(service.get_service());
2249 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2251 if (position < GenTime()) {
2252 // Remove track effect
2253 return mltRemoveTrackEffect(track, index, updateIndex);
2255 Mlt::Service service(m_mltProducer->parent().get_service());
2256 bool success = false;
2257 Mlt::Tractor tractor(service);
2258 Mlt::Producer trackProducer(tractor.track(track));
2259 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2261 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2262 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2264 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2268 Mlt::Service clipService(clip->get_service());
2269 int duration = clip->get_playtime();
2271 // Check if clip is visible in monitor
2272 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2273 if (diff < 0 || diff > duration) doRefresh = false;
2277 // if (tag.startsWith("ladspa")) tag = "ladspa";
2279 mlt_service_lock(service.get_service());
2281 Mlt::Filter *filter = clipService.filter(ct);
2283 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2284 if (clipService.detach(*filter) == 0) success = true;
2285 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2286 } else if (updateIndex) {
2287 // Adjust the other effects index
2288 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2291 filter = clipService.filter(ct);
2293 m_isBlocked = false;
2294 mlt_service_unlock(service.get_service());
2295 if (doRefresh) refresh();
2299 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2301 Mlt::Service service(m_mltProducer->parent().get_service());
2302 Mlt::Tractor tractor(service);
2303 Mlt::Producer trackProducer(tractor.track(track));
2304 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2305 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2306 return mltAddEffect(trackService, params, 15000, true);
2310 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2313 Mlt::Service service(m_mltProducer->parent().get_service());
2315 Mlt::Tractor tractor(service);
2316 Mlt::Producer trackProducer(tractor.track(track));
2317 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2319 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2320 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2325 Mlt::Service clipService(clip->get_service());
2326 int duration = clip->get_playtime();
2328 // Check if clip is visible in monitor
2329 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2330 if (diff < 0 || diff > duration) doRefresh = false;
2333 return mltAddEffect(clipService, params, duration, doRefresh);
2336 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2338 bool updateIndex = false;
2339 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2340 const QString region = params.paramValue("region");
2343 mlt_service_lock(service.get_service());
2345 Mlt::Filter *filter = service.filter(ct);
2347 if (filter->get_int("kdenlive_ix") == filter_ix) {
2348 // A filter at that position already existed, so we will increase all indexes later
2353 filter = service.filter(ct);
2356 if (params.paramValue("id") == "speed") {
2357 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2359 filter = service.filter(ct);
2361 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2362 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2365 filter = service.filter(ct);
2367 m_isBlocked = false;
2368 mlt_service_unlock(service.get_service());
2369 if (doRefresh) refresh();
2374 // temporarily remove all effects after insert point
2375 QList <Mlt::Filter *> filtersList;
2377 filter = service.filter(ct);
2379 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2380 filtersList.append(filter);
2381 service.detach(*filter);
2383 filter = service.filter(ct);
2387 QString tag = params.paramValue("tag");
2388 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2389 if (tag.startsWith("ladspa")) tag = "ladspa";
2390 char *filterTag = qstrdup(tag.toUtf8().constData());
2391 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2392 QHash<QString, QString>::Iterator it;
2393 QString kfr = params.paramValue("keyframes");
2395 if (!kfr.isEmpty()) {
2396 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2397 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2398 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2399 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2400 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2401 //double max = params.paramValue("max").toDouble();
2402 double min = params.paramValue("min").toDouble();
2403 double factor = params.paramValue("factor", "1").toDouble();
2404 params.removeParam("starttag");
2405 params.removeParam("endtag");
2406 params.removeParam("keyframes");
2407 params.removeParam("min");
2408 params.removeParam("max");
2409 params.removeParam("factor");
2411 // Special case, only one keyframe, means we want a constant value
2412 if (keyFrames.count() == 1) {
2413 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2414 if (filter && filter->is_valid()) {
2415 filter->set("kdenlive_id", filterId);
2416 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2417 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2418 for (int j = 0; j < params.count(); j++) {
2419 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2421 filter->set("in", x1);
2422 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2423 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2424 service.attach(*filter);
2426 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2427 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2428 if (filter && filter->is_valid()) {
2429 filter->set("kdenlive_id", filterId);
2430 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2431 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2432 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2433 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2434 if (x2 == -1) x2 = duration;
2436 for (int j = 0; j < params.count(); j++) {
2437 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2440 filter->set("in", x1);
2441 filter->set("out", x2);
2442 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2443 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2444 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2445 service.attach(*filter);
2452 Mlt::Filter *filter;
2454 if (!region.isEmpty()) {
2455 filter = new Mlt::Filter(*m_mltProfile, "region");
2456 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2457 if (filter && filter->is_valid()) {
2458 filter->set("kdenlive_id", filterId);
2459 if (!region.isEmpty()) {
2460 filter->set("resource", region.toUtf8().constData());
2461 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2462 filter->set("filter0", filterTag);
2463 prefix = "filter0.";
2464 params.removeParam("id");
2465 params.removeParam("region");
2466 params.removeParam("kdenlive_ix");
2469 kDebug() << "filter is NULL";
2470 m_isBlocked = false;
2471 mlt_service_unlock(service.get_service());
2474 params.removeParam("kdenlive_id");
2476 for (int j = 0; j < params.count(); j++) {
2477 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2481 QString effectArgs = params.paramValue("id").section('_', 1);
2483 params.removeParam("id");
2484 params.removeParam("kdenlive_ix");
2485 params.removeParam("tag");
2486 params.removeParam("disable");
2487 params.removeParam("region");
2489 for (int j = 0; j < params.count(); j++) {
2490 effectArgs.append(' ' + params.at(j).value());
2492 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2493 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2496 if (params.paramValue("id") == "pan_zoom") {
2497 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2500 // attach filter to the clip
2501 service.attach(*filter);
2506 // re-add following filters
2507 for (int i = 0; i < filtersList.count(); i++) {
2508 Mlt::Filter *filter = filtersList.at(i);
2510 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2511 service.attach(*filter);
2513 m_isBlocked = false;
2514 mlt_service_unlock(service.get_service());
2515 if (doRefresh) refresh();
2519 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2521 Mlt::Service service(m_mltProducer->parent().get_service());
2522 Mlt::Tractor tractor(service);
2523 Mlt::Producer trackProducer(tractor.track(track));
2524 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2525 Mlt::Service clipService(trackPlaylist.get_service());
2528 QString index = params.paramValue("kdenlive_ix");
2529 QString tag = params.paramValue("tag");
2531 Mlt::Filter *filter = clipService.filter(ct);
2533 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2537 filter = clipService.filter(ct);
2541 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2542 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2544 bool success = false;//mltAddTrackEffect(track, params);
2545 m_isBlocked = false;
2549 QString ser = filter->get("mlt_service");
2550 if (ser == "region") prefix = "filter0.";
2551 mlt_service_lock(service.get_service());
2552 for (int j = 0; j < params.count(); j++) {
2553 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2555 mlt_service_unlock(service.get_service());
2557 m_isBlocked = false;
2563 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2565 QString index = params.paramValue("kdenlive_ix");
2566 QString tag = params.paramValue("tag");
2568 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2569 // This is a keyframe effect, to edit it, we remove it and re-add it.
2570 bool success = mltRemoveEffect(track, position, index, false);
2571 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2572 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2573 else success = mltAddEffect(track, position, params);
2574 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2577 if (position < GenTime()) {
2578 return mltEditTrackEffect(track, params);
2581 Mlt::Service service(m_mltProducer->parent().get_service());
2582 Mlt::Tractor tractor(service);
2583 Mlt::Producer trackProducer(tractor.track(track));
2584 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2586 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2587 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2589 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2593 Mlt::Service clipService(clip->get_service());
2594 int duration = clip->get_playtime();
2595 bool doRefresh = true;
2596 // Check if clip is visible in monitor
2597 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2598 if (diff < 0 || diff > duration) doRefresh = false;
2602 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2603 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2605 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2607 filter = clipService.filter(ct);
2609 kDebug() << "++++++++++++++++++++++++++";
2611 filter = clipService.filter(ct); */
2613 Mlt::Filter *filter = clipService.filter(ct);
2615 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2619 filter = clipService.filter(ct);
2623 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2624 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2626 bool success = mltAddEffect(track, position, params);
2627 m_isBlocked = false;
2631 QString ser = filter->get("mlt_service");
2632 if (ser == "region") prefix = "filter0.";
2633 mlt_service_lock(service.get_service());
2634 for (int j = 0; j < params.count(); j++) {
2635 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2637 mlt_service_unlock(service.get_service());
2639 m_isBlocked = false;
2640 if (doRefresh) refresh();
2644 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2646 Mlt::Service service(m_mltProducer->parent().get_service());
2647 Mlt::Tractor tractor(service);
2648 Mlt::Producer trackProducer(tractor.track(track));
2649 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2651 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2652 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2654 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2658 Mlt::Service clipService(clip->get_service());
2659 int duration = clip->get_playtime();
2660 bool doRefresh = true;
2661 // Check if clip is visible in monitor
2662 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2663 if (diff < 0 || diff > duration) doRefresh = false;
2668 Mlt::Filter *filter = clipService.filter(ct);
2670 int pos = filter->get_int("kdenlive_ix");
2671 if (pos == oldPos) {
2672 filter->set("kdenlive_ix", newPos);
2674 filter = clipService.filter(ct);
2677 m_isBlocked = false;
2678 if (doRefresh) refresh();
2681 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2683 if (position < GenTime()) {
2684 mltMoveTrackEffect(track, oldPos, newPos);
2687 Mlt::Service service(m_mltProducer->parent().get_service());
2688 Mlt::Tractor tractor(service);
2689 Mlt::Producer trackProducer(tractor.track(track));
2690 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2692 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2693 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2695 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2699 Mlt::Service clipService(clip->get_service());
2700 int duration = clip->get_playtime();
2701 bool doRefresh = true;
2702 // Check if clip is visible in monitor
2703 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2704 if (diff < 0 || diff > duration) doRefresh = false;
2709 QList <Mlt::Filter *> filtersList;
2710 Mlt::Filter *filter = clipService.filter(ct);
2712 if (newPos > oldPos) {
2714 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2715 filter->set("kdenlive_ix", newPos);
2716 filtersList.append(filter);
2717 clipService.detach(*filter);
2718 filter = clipService.filter(ct);
2719 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2720 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2722 filter = clipService.filter(ct);
2726 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2727 filtersList.append(filter);
2728 clipService.detach(*filter);
2730 filter = clipService.filter(ct);
2734 if (filter->get_int("kdenlive_ix") == oldPos) {
2735 filter->set("kdenlive_ix", newPos);
2736 filtersList.append(filter);
2737 clipService.detach(*filter);
2739 filter = clipService.filter(ct);
2743 filter = clipService.filter(ct);
2745 int pos = filter->get_int("kdenlive_ix");
2746 if (pos >= newPos) {
2747 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2748 filtersList.append(filter);
2749 clipService.detach(*filter);
2751 filter = clipService.filter(ct);
2755 for (int i = 0; i < filtersList.count(); i++) {
2756 clipService.attach(*(filtersList.at(i)));
2759 m_isBlocked = false;
2760 if (doRefresh) refresh();
2763 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2765 Mlt::Service service(m_mltProducer->parent().get_service());
2766 Mlt::Tractor tractor(service);
2767 Mlt::Producer trackProducer(tractor.track(track));
2768 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2770 Mlt::Service clipService(trackPlaylist.get_service());
2774 QList <Mlt::Filter *> filtersList;
2775 Mlt::Filter *filter = clipService.filter(ct);
2777 if (newPos > oldPos) {
2779 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2780 filter->set("kdenlive_ix", newPos);
2781 filtersList.append(filter);
2782 clipService.detach(*filter);
2783 filter = clipService.filter(ct);
2784 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2785 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2787 filter = clipService.filter(ct);
2791 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2792 filtersList.append(filter);
2793 clipService.detach(*filter);
2795 filter = clipService.filter(ct);
2799 if (filter->get_int("kdenlive_ix") == oldPos) {
2800 filter->set("kdenlive_ix", newPos);
2801 filtersList.append(filter);
2802 clipService.detach(*filter);
2804 filter = clipService.filter(ct);
2808 filter = clipService.filter(ct);
2810 int pos = filter->get_int("kdenlive_ix");
2811 if (pos >= newPos) {
2812 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2813 filtersList.append(filter);
2814 clipService.detach(*filter);
2816 filter = clipService.filter(ct);
2820 for (int i = 0; i < filtersList.count(); i++) {
2821 clipService.attach(*(filtersList.at(i)));
2823 m_isBlocked = false;
2827 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2830 Mlt::Service service(m_mltProducer->parent().get_service());
2831 Mlt::Tractor tractor(service);
2832 Mlt::Producer trackProducer(tractor.track(info.track));
2833 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2835 /* // Display playlist info
2836 kDebug()<<"//////////// BEFORE RESIZE";
2837 for (int i = 0; i < trackPlaylist.count(); i++) {
2838 int blankStart = trackPlaylist.clip_start(i);
2839 int blankDuration = trackPlaylist.clip_length(i) - 1;
2841 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2842 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2845 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2846 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2847 m_isBlocked = false;
2850 mlt_service_lock(service.get_service());
2851 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2852 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2853 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2855 int previousStart = clip->get_in();
2856 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2857 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2859 int currentOut = newDuration + previousStart;
2860 if (currentOut > clip->get_length()) {
2861 clip->parent().set("length", currentOut + 1);
2862 clip->parent().set("out", currentOut);
2863 clip->set("length", currentOut + 1);
2866 /*if (newDuration > clip->get_out()) {
2867 clip->parent().set_in_and_out(0, newDuration + 1);
2868 clip->set_in_and_out(0, newDuration + 1);
2871 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2872 trackPlaylist.consolidate_blanks(0);
2873 // skip to next clip
2875 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2877 // clip was made longer, trim next blank if there is one.
2878 if (clipIndex < trackPlaylist.count()) {
2879 // If this is not the last clip in playlist
2880 if (trackPlaylist.is_blank(clipIndex)) {
2881 int blankStart = trackPlaylist.clip_start(clipIndex);
2882 int blankDuration = trackPlaylist.clip_length(clipIndex);
2883 if (diff > blankDuration) {
2884 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2886 if (diff - blankDuration == 0) {
2887 trackPlaylist.remove(clipIndex);
2888 } else trackPlaylist.remove_region(blankStart, diff);
2890 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2893 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2894 trackPlaylist.consolidate_blanks(0);
2895 mlt_service_unlock(service.get_service());
2897 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2898 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2899 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2900 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2901 ItemInfo transpinfo;
2902 transpinfo.startPos = info.startPos;
2903 transpinfo.endPos = info.startPos + clipDuration;
2904 transpinfo.track = info.track;
2905 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2907 m_isBlocked = false;
2908 m_mltConsumer->set("refresh", 1);
2912 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2914 Mlt::Service service(m_mltProducer->parent().get_service());
2915 Mlt::Tractor tractor(service);
2916 Mlt::Producer trackProducer(tractor.track(track));
2919 if (blind) trackProducer.set("hide", 3);
2920 else trackProducer.set("hide", 2);
2922 trackProducer.set("hide", 1);
2924 trackProducer.set("hide", 0);
2926 tractor.multitrack()->refresh();
2932 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2934 Mlt::Service service(m_mltProducer->parent().get_service());
2935 int frameOffset = (int) diff.frames(m_fps);
2936 Mlt::Tractor tractor(service);
2937 Mlt::Producer trackProducer(tractor.track(info.track));
2938 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2939 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2940 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2943 mlt_service_lock(service.get_service());
2944 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2945 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2947 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2948 mlt_service_unlock(service.get_service());
2951 int previousStart = clip->get_in();
2952 int previousOut = clip->get_out();
2955 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2956 m_isBlocked = false;
2957 mlt_service_unlock(service.get_service());
2958 m_mltConsumer->set("refresh", 1);
2962 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2964 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2965 Mlt::Service service(m_mltProducer->parent().get_service());
2966 int moveFrame = (int) diff.frames(m_fps);
2967 Mlt::Tractor tractor(service);
2968 Mlt::Producer trackProducer(tractor.track(info.track));
2969 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2970 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2971 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2974 mlt_service_lock(service.get_service());
2975 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2976 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2977 if (clip == NULL || clip->is_blank()) {
2978 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2979 mlt_service_unlock(service.get_service());
2982 int previousStart = clip->get_in();
2983 int previousOut = clip->get_out();
2986 previousStart += moveFrame;
2988 int length = previousOut + 1;
2989 if (length > clip->get_length()) {
2990 clip->parent().set("length", length + 1);
2991 clip->parent().set("out", length);
2992 clip->set("length", length + 1);
2996 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
2997 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
2998 if (moveFrame > 0) {
2999 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3001 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3002 int blankIndex = clipIndex - 1;
3003 int blankLength = trackPlaylist.clip_length(blankIndex);
3004 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3005 if (! trackPlaylist.is_blank(blankIndex)) {
3006 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3008 if (blankLength + moveFrame == 0)
3009 trackPlaylist.remove(blankIndex);
3011 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3013 trackPlaylist.consolidate_blanks(0);
3014 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3015 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3016 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3017 ItemInfo transpinfo;
3018 transpinfo.startPos = info.startPos + diff;
3019 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3020 transpinfo.track = info.track;
3021 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3023 m_isBlocked = false;
3024 //m_mltConsumer->set("refresh", 1);
3025 mlt_service_unlock(service.get_service());
3026 m_mltConsumer->set("refresh", 1);
3030 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3032 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3036 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3038 if (prod == NULL || !prod->is_valid()) {
3039 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3042 kDebug() << "NEW PROD ID: " << prod->get("id");
3044 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3045 Mlt::Service service(m_mltProducer->parent().get_service());
3046 if (service.type() != tractor_type) {
3047 kWarning() << "// TRACTOR PROBLEM";
3050 mlt_service_lock(service.get_service());
3051 Mlt::Tractor tractor(service);
3052 Mlt::Producer trackProducer(tractor.track(track));
3053 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3054 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3055 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3056 if (clipProducer == NULL || clipProducer->is_blank()) {
3057 kDebug() << "// ERROR UPDATING CLIP PROD";
3058 delete clipProducer;
3059 mlt_service_unlock(service.get_service());
3063 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3064 if (!clip || !clip->is_valid()) {
3065 if (clip) delete clip;
3066 delete clipProducer;
3067 mlt_service_unlock(service.get_service());
3071 // move all effects to the correct producer
3072 mltPasteEffects(clipProducer, clip);
3073 trackPlaylist.insert_at(pos, clip, 1);
3075 delete clipProducer;
3076 mlt_service_unlock(service.get_service());
3081 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3085 Mlt::Service service(m_mltProducer->parent().get_service());
3086 if (service.type() != tractor_type) {
3087 kWarning() << "// TRACTOR PROBLEM";
3091 Mlt::Tractor tractor(service);
3092 mlt_service_lock(service.get_service());
3093 Mlt::Producer trackProducer(tractor.track(startTrack));
3094 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3095 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3096 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3097 bool checkLength = false;
3098 if (endTrack == startTrack) {
3099 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3100 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3101 // error, destination is not empty
3103 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3104 delete clipProducer;
3106 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3107 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3108 mlt_service_unlock(service.get_service());
3112 trackPlaylist.consolidate_blanks(0);
3114 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3115 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3116 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3118 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3119 trackPlaylist.consolidate_blanks(1);
3120 delete clipProducer;
3121 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3122 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3124 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3126 //mlt_service_unlock(service.get_service());
3128 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3129 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3130 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3131 // error, destination is not empty
3132 mlt_service_unlock(service.get_service());
3136 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3137 if (!clipProducer || clipProducer->is_blank()) {
3138 // error, destination is not empty
3139 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3140 if (clipProducer) delete clipProducer;
3141 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3142 mlt_service_unlock(service.get_service());
3146 trackPlaylist.consolidate_blanks(0);
3147 destTrackPlaylist.consolidate_blanks(1);
3148 Mlt::Producer *clip;
3149 // check if we are moving a slowmotion producer
3150 QString serv = clipProducer->parent().get("mlt_service");
3151 QString currentid = clipProducer->parent().get("id");
3152 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3153 clip = clipProducer;
3156 // Special case: prod is null when using placeholder clips.
3157 // in that case, use the producer existing in playlist. Note that
3158 // it will bypass the one producer per track logic and might cause
3159 // Sound cracks if clip is moved so that it overlaps another copy of itself
3160 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3161 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3164 // move all effects to the correct producer
3165 mltPasteEffects(clipProducer, clip);
3168 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3169 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3170 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3173 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3175 if (clip == clipProducer) {
3180 delete clipProducer;
3182 destTrackPlaylist.consolidate_blanks(0);
3183 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3184 kDebug() << "//////// moving clip transparency";
3185 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3187 if (clipIndex > trackPlaylist.count()) checkLength = true;
3188 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3191 mlt_service_unlock(service.get_service());
3192 if (checkLength) mltCheckLength(&tractor);
3195 //m_mltConsumer->set("refresh", 1);
3200 QList <int> Render::checkTrackSequence(int track)
3203 Mlt::Service service(m_mltProducer->parent().get_service());
3204 if (service.type() != tractor_type) {
3205 kWarning() << "// TRACTOR PROBLEM";
3208 Mlt::Tractor tractor(service);
3209 mlt_service_lock(service.get_service());
3210 Mlt::Producer trackProducer(tractor.track(track));
3211 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3212 int clipNb = trackPlaylist.count();
3213 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3214 for (int i = 0; i < clipNb; i++) {
3215 Mlt::Producer *c = trackPlaylist.get_clip(i);
3216 int pos = trackPlaylist.clip_start(i);
3217 if (!list.contains(pos)) list.append(pos);
3218 pos += c->get_playtime();
3219 if (!list.contains(pos)) list.append(pos);
3225 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3227 int new_in = (int)newIn.frames(m_fps);
3228 int new_out = (int)newOut.frames(m_fps) - 1;
3229 if (new_in >= new_out) return false;
3230 int old_in = (int)oldIn.frames(m_fps);
3231 int old_out = (int)oldOut.frames(m_fps) - 1;
3233 Mlt::Service service(m_mltProducer->parent().get_service());
3234 Mlt::Tractor tractor(service);
3235 Mlt::Field *field = tractor.field();
3237 bool doRefresh = true;
3238 // Check if clip is visible in monitor
3239 int diff = old_out - m_mltProducer->position();
3240 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3242 diff = new_out - m_mltProducer->position();
3243 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3247 mlt_service_lock(service.get_service());
3249 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3250 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3251 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3252 QString resource = mlt_properties_get(properties, "mlt_service");
3253 int old_pos = (int)(old_in + old_out) / 2;
3256 while (mlt_type == "transition") {
3257 Mlt::Transition transition((mlt_transition) nextservice);
3258 int currentTrack = transition.get_b_track();
3259 int currentIn = (int) transition.get_in();
3260 int currentOut = (int) transition.get_out();
3262 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3264 if (newTrack - startTrack != 0) {
3265 Mlt::Properties trans_props(transition.get_properties());
3266 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3267 Mlt::Properties new_trans_props(new_transition.get_properties());
3268 new_trans_props.inherit(trans_props);
3269 new_transition.set_in_and_out(new_in, new_out);
3270 field->disconnect_service(transition);
3271 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3272 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3273 } else transition.set_in_and_out(new_in, new_out);
3276 nextservice = mlt_service_producer(nextservice);
3277 if (nextservice == NULL) break;
3278 properties = MLT_SERVICE_PROPERTIES(nextservice);
3279 mlt_type = mlt_properties_get(properties, "mlt_type");
3280 resource = mlt_properties_get(properties, "mlt_service");
3282 mlt_service_unlock(service.get_service());
3284 if (doRefresh) refresh();
3285 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3290 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3292 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3293 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3294 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3295 QString resource = mlt_properties_get(properties, "mlt_service");
3296 QList <Mlt::Transition *> trList;
3298 while (mlt_type == "transition") {
3299 Mlt::Transition transition((mlt_transition) nextservice);
3300 int aTrack = transition.get_a_track();
3301 int bTrack = transition.get_b_track();
3302 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3303 Mlt::Properties trans_props(transition.get_properties());
3304 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3305 Mlt::Properties new_trans_props(cp->get_properties());
3306 new_trans_props.inherit(trans_props);
3308 field->disconnect_service(transition);
3310 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3312 nextservice = mlt_service_producer(nextservice);
3313 if (nextservice == NULL) break;
3314 properties = MLT_SERVICE_PROPERTIES(nextservice);
3315 mlt_type = mlt_properties_get(properties, "mlt_type");
3316 resource = mlt_properties_get(properties, "mlt_service");
3319 field->plant_transition(tr, a_track, b_track);
3321 // re-add upper transitions
3322 for (int i = 0; i < trList.count(); i++) {
3323 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3324 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3328 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3330 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3332 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3333 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3336 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3339 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3341 mlt_service serv = m_mltProducer->parent().get_service();
3342 mlt_service_lock(serv);
3345 mlt_service nextservice = mlt_service_get_producer(serv);
3346 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3347 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3348 QString resource = mlt_properties_get(properties, "mlt_service");
3349 int in_pos = (int) in.frames(m_fps);
3350 int out_pos = (int) out.frames(m_fps) - 1;
3352 while (mlt_type == "transition") {
3353 mlt_transition tr = (mlt_transition) nextservice;
3354 int currentTrack = mlt_transition_get_b_track(tr);
3355 int currentBTrack = mlt_transition_get_a_track(tr);
3356 int currentIn = (int) mlt_transition_get_in(tr);
3357 int currentOut = (int) mlt_transition_get_out(tr);
3359 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3361 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3362 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3363 QMap<QString, QString>::Iterator it;
3365 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3367 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3368 if (currentId != xml.attribute("id")) {
3369 // The transition ID is not the same, so reset all properties
3370 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3371 // Cleanup previous properties
3372 QStringList permanentProps;
3373 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3374 permanentProps << "out" << "a_track" << "b_track";
3375 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3376 QString propName = mlt_properties_get_name(transproperties, i);
3377 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3378 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3383 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3384 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3386 if (currentBTrack != a_track) {
3387 mlt_properties_set_int(transproperties, "a_track", a_track);
3389 for (it = map.begin(); it != map.end(); ++it) {
3391 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3392 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3393 //filter->set("kdenlive_id", id);
3397 nextservice = mlt_service_producer(nextservice);
3398 if (nextservice == NULL) break;
3399 properties = MLT_SERVICE_PROPERTIES(nextservice);
3400 mlt_type = mlt_properties_get(properties, "mlt_type");
3401 resource = mlt_properties_get(properties, "mlt_service");
3403 mlt_service_unlock(serv);
3406 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3409 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3411 mlt_service serv = m_mltProducer->parent().get_service();
3413 mlt_service_lock(serv);
3415 Mlt::Service service(serv);
3416 Mlt::Tractor tractor(service);
3417 Mlt::Field *field = tractor.field();
3419 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3421 mlt_service nextservice = mlt_service_get_producer(serv);
3422 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3423 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3424 QString resource = mlt_properties_get(properties, "mlt_service");
3426 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3427 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3429 while (mlt_type == "transition") {
3430 mlt_transition tr = (mlt_transition) nextservice;
3431 int currentTrack = mlt_transition_get_b_track(tr);
3432 int currentIn = (int) mlt_transition_get_in(tr);
3433 int currentOut = (int) mlt_transition_get_out(tr);
3434 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3436 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3437 mlt_field_disconnect_service(field->get_field(), nextservice);
3440 nextservice = mlt_service_producer(nextservice);
3441 if (nextservice == NULL) break;
3442 properties = MLT_SERVICE_PROPERTIES(nextservice);
3443 mlt_type = mlt_properties_get(properties, "mlt_type");
3444 resource = mlt_properties_get(properties, "mlt_service");
3446 mlt_service_unlock(serv);
3449 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3452 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3454 QDomNodeList attribs = xml.elementsByTagName("parameter");
3455 QMap<QString, QString> map;
3456 for (int i = 0; i < attribs.count(); i++) {
3457 QDomElement e = attribs.item(i).toElement();
3458 QString name = e.attribute("name");
3459 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3460 map[name] = e.attribute("default");
3461 if (!e.attribute("value").isEmpty()) {
3462 map[name] = e.attribute("value");
3464 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3465 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3466 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3469 if (e.attribute("namedesc").contains(';')) {
3470 QString format = e.attribute("format");
3471 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3472 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3474 QTextStream txtNeu(&neu);
3475 if (values.size() > 0)
3476 txtNeu << (int)values[0].toDouble();
3478 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3479 txtNeu << separators[i];
3480 txtNeu << (int)(values[i+1].toDouble());
3482 if (i < separators.size())
3483 txtNeu << separators[i];
3484 map[e.attribute("name")] = neu;
3491 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3493 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3494 Mlt::Service service(m_mltProducer->parent().get_service());
3495 Mlt::Tractor tractor(service);
3496 Mlt::Field *field = tractor.field();
3498 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3499 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3500 transition->set("transparency", id);
3501 transition->set("fill", 1);
3502 transition->set("internal_added", 237);
3503 field->plant_transition(*transition, transitiontrack, info.track);
3507 void Render::mltDeleteTransparency(int pos, int track, int id)
3509 Mlt::Service service(m_mltProducer->parent().get_service());
3510 Mlt::Tractor tractor(service);
3511 Mlt::Field *field = tractor.field();
3513 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3514 mlt_service serv = m_mltProducer->parent().get_service();
3516 mlt_service nextservice = mlt_service_get_producer(serv);
3517 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3518 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3519 QString resource = mlt_properties_get(properties, "mlt_service");
3521 while (mlt_type == "transition") {
3522 mlt_transition tr = (mlt_transition) nextservice;
3523 int currentTrack = mlt_transition_get_b_track(tr);
3524 int currentIn = (int) mlt_transition_get_in(tr);
3525 int currentOut = (int) mlt_transition_get_out(tr);
3526 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3527 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3529 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3530 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3531 mlt_field_disconnect_service(field->get_field(), nextservice);
3534 nextservice = mlt_service_producer(nextservice);
3535 if (nextservice == NULL) break;
3536 properties = MLT_SERVICE_PROPERTIES(nextservice);
3537 mlt_type = mlt_properties_get(properties, "mlt_type");
3538 resource = mlt_properties_get(properties, "mlt_service");
3540 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3543 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3545 Mlt::Service service(m_mltProducer->parent().get_service());
3546 Mlt::Tractor tractor(service);
3548 mlt_service_lock(service.get_service());
3549 m_mltConsumer->set("refresh", 0);
3552 mlt_service serv = m_mltProducer->parent().get_service();
3553 mlt_service nextservice = mlt_service_get_producer(serv);
3554 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3555 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3556 QString resource = mlt_properties_get(properties, "mlt_service");
3557 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3558 while (mlt_type == "transition") {
3559 mlt_transition tr = (mlt_transition) nextservice;
3560 int currentTrack = mlt_transition_get_b_track(tr);
3561 int currentIn = (int) mlt_transition_get_in(tr);
3562 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3563 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3564 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3565 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3566 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3567 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3570 nextservice = mlt_service_producer(nextservice);
3571 if (nextservice == NULL) break;
3572 properties = MLT_SERVICE_PROPERTIES(nextservice);
3573 mlt_type = mlt_properties_get(properties, "mlt_type");
3574 resource = mlt_properties_get(properties, "mlt_service");
3576 mlt_service_unlock(service.get_service());
3578 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3582 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3584 Mlt::Service service(m_mltProducer->parent().get_service());
3585 Mlt::Tractor tractor(service);
3587 mlt_service_lock(service.get_service());
3588 m_mltConsumer->set("refresh", 0);
3591 mlt_service serv = m_mltProducer->parent().get_service();
3592 mlt_service nextservice = mlt_service_get_producer(serv);
3593 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3594 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3595 QString resource = mlt_properties_get(properties, "mlt_service");
3597 while (mlt_type == "transition") {
3598 mlt_transition tr = (mlt_transition) nextservice;
3599 int currentTrack = mlt_transition_get_b_track(tr);
3600 int currentaTrack = mlt_transition_get_a_track(tr);
3601 int currentIn = (int) mlt_transition_get_in(tr);
3602 int currentOut = (int) mlt_transition_get_out(tr);
3603 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3604 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3605 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3606 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3607 kDebug() << "//////MOVING";
3608 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3609 if (endTrack != startTrack) {
3610 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3611 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3612 mlt_properties_set_int(properties, "b_track", endTrack);
3616 nextservice = mlt_service_producer(nextservice);
3617 if (nextservice == NULL) break;
3618 properties = MLT_SERVICE_PROPERTIES(nextservice);
3619 mlt_type = mlt_properties_get(properties, "mlt_type");
3620 resource = mlt_properties_get(properties, "mlt_service");
3623 mlt_service_unlock(service.get_service());
3624 m_mltConsumer->set("refresh", 1);
3628 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3630 if (in >= out) return false;
3631 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3632 Mlt::Service service(m_mltProducer->parent().get_service());
3634 Mlt::Tractor tractor(service);
3635 Mlt::Field *field = tractor.field();
3637 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3638 if (out != GenTime())
3639 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3641 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3642 QMap<QString, QString>::Iterator it;
3644 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3645 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3646 if (xml.hasAttribute("id"))
3647 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3649 for (it = args.begin(); it != args.end(); ++it) {
3651 if (!it.value().isEmpty())
3652 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3653 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3655 // attach transition
3656 mltPlantTransition(field, *transition, a_track, b_track);
3657 // field->plant_transition(*transition, a_track, b_track);
3658 if (do_refresh) refresh();
3662 void Render::mltSavePlaylist()
3664 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3665 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3666 fileConsumer.set("resource", "/tmp/playlist.mlt");
3668 Mlt::Service service(m_mltProducer->get_service());
3670 fileConsumer.connect(service);
3671 fileConsumer.start();
3674 const QList <Mlt::Producer *> Render::producersList()
3676 QList <Mlt::Producer *> prods;
3677 if (m_mltProducer == NULL) return prods;
3678 Mlt::Service service(m_mltProducer->parent().get_service());
3679 if (service.type() != tractor_type) return prods;
3680 Mlt::Tractor tractor(service);
3683 int trackNb = tractor.count();
3684 for (int t = 1; t < trackNb; t++) {
3685 Mlt::Producer *tt = tractor.track(t);
3686 Mlt::Producer trackProducer(tt);
3688 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3689 int clipNb = trackPlaylist.count();
3690 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3691 for (int i = 0; i < clipNb; i++) {
3692 Mlt::Producer *c = trackPlaylist.get_clip(i);
3693 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3695 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3696 ids.append(nprod->get("id"));
3697 prods.append(nprod);
3698 } else delete nprod;
3706 void Render::fillSlowMotionProducers()
3708 if (m_mltProducer == NULL) return;
3709 Mlt::Service service(m_mltProducer->parent().get_service());
3710 if (service.type() != tractor_type) return;
3712 Mlt::Tractor tractor(service);
3714 int trackNb = tractor.count();
3715 for (int t = 1; t < trackNb; t++) {
3716 Mlt::Producer *tt = tractor.track(t);
3717 Mlt::Producer trackProducer(tt);
3719 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3720 int clipNb = trackPlaylist.count();
3721 for (int i = 0; i < clipNb; i++) {
3722 Mlt::Producer *c = trackPlaylist.get_clip(i);
3723 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3725 QString id = nprod->get("id");
3726 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3727 // this is a slowmotion producer, add it to the list
3728 QString url = QString::fromUtf8(nprod->get("resource"));
3729 int strobe = nprod->get_int("strobe");
3730 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3731 if (!m_slowmotionProducers.contains(url)) {
3732 m_slowmotionProducers.insert(url, nprod);
3734 } else delete nprod;
3741 void Render::mltInsertTrack(int ix, bool videoTrack)
3746 Mlt::Service service(m_mltProducer->parent().get_service());
3747 mlt_service_lock(service.get_service());
3748 if (service.type() != tractor_type) {
3749 kWarning() << "// TRACTOR PROBLEM";
3753 Mlt::Tractor tractor(service);
3755 Mlt::Playlist playlist;
3756 int ct = tractor.count();
3758 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3764 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3765 tractor.set_track(playlist, pos);
3766 Mlt::Producer newProd(tractor.track(pos));
3767 if (!videoTrack) newProd.set("hide", 1);
3769 for (; pos <= ct; pos++) {
3770 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3771 tractor.set_track(*prodToMove, pos);
3772 prodToMove = prodToMove2;
3775 tractor.set_track(playlist, ix);
3776 Mlt::Producer newProd(tractor.track(ix));
3777 if (!videoTrack) newProd.set("hide", 1);
3781 mlt_service serv = m_mltProducer->parent().get_service();
3782 mlt_service nextservice = mlt_service_get_producer(serv);
3783 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3784 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3785 QString resource = mlt_properties_get(properties, "mlt_service");
3787 while (mlt_type == "transition") {
3788 if (resource != "mix") {
3789 mlt_transition tr = (mlt_transition) nextservice;
3790 int currentTrack = mlt_transition_get_b_track(tr);
3791 int currentaTrack = mlt_transition_get_a_track(tr);
3792 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3794 if (currentTrack >= ix) {
3795 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3796 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3799 nextservice = mlt_service_producer(nextservice);
3800 if (nextservice == NULL) break;
3801 properties = MLT_SERVICE_PROPERTIES(nextservice);
3802 mlt_type = mlt_properties_get(properties, "mlt_type");
3803 resource = mlt_properties_get(properties, "mlt_service");
3806 // Add audio mix transition to last track
3807 Mlt::Field *field = tractor.field();
3808 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3809 transition->set("a_track", 1);
3810 transition->set("b_track", ct);
3811 transition->set("always_active", 1);
3812 transition->set("internal_added", 237);
3813 transition->set("combine", 1);
3814 field->plant_transition(*transition, 1, ct);
3815 //mlt_service_unlock(m_mltConsumer->get_service());
3816 mlt_service_unlock(service.get_service());
3817 //tractor.multitrack()->refresh();
3818 //tractor.refresh();
3820 blockSignals(false);
3824 void Render::mltDeleteTrack(int ix)
3827 doc.setContent(sceneList(), false);
3828 int tracksCount = doc.elementsByTagName("track").count() - 1;
3829 QDomNode track = doc.elementsByTagName("track").at(ix);
3830 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3831 QDomNodeList transitions = doc.elementsByTagName("transition");
3832 for (int i = 0; i < transitions.count(); i++) {
3833 QDomElement e = transitions.at(i).toElement();
3834 QDomNodeList props = e.elementsByTagName("property");
3835 QMap <QString, QString> mappedProps;
3836 for (int j = 0; j < props.count(); j++) {
3837 QDomElement f = props.at(j).toElement();
3838 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3840 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3841 tractor.removeChild(transitions.at(i));
3843 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3844 // Transition needs to be moved
3845 int a_track = mappedProps.value("a_track").toInt();
3846 int b_track = mappedProps.value("b_track").toInt();
3847 if (a_track > 0 && a_track >= ix) a_track --;
3848 if (b_track == ix) {
3849 // transition was on the deleted track, so remove it
3850 tractor.removeChild(transitions.at(i));
3854 if (b_track > 0 && b_track > ix) b_track --;
3855 for (int j = 0; j < props.count(); j++) {
3856 QDomElement f = props.at(j).toElement();
3857 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3858 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3863 tractor.removeChild(track);
3864 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3865 setSceneList(doc.toString(), m_framePosition);
3867 /* if (m_mltProducer != NULL) {
3868 Mlt::Producer parentProd(m_mltProducer->parent());
3869 if (parentProd.get_producer() != NULL) {
3870 Mlt::Service service(parentProd.get_service());
3871 if (service.type() == tractor_type) {
3872 Mlt::Tractor tractor(service);
3873 mltCheckLength(&tractor);
3880 void Render::updatePreviewSettings()
3882 kDebug() << "////// RESTARTING CONSUMER";
3883 if (!m_mltConsumer || !m_mltProducer) return;
3884 if (m_mltProducer->get_playtime() == 0) return;
3885 Mlt::Service service(m_mltProducer->parent().get_service());
3886 if (service.type() != tractor_type) return;
3888 //m_mltConsumer->set("refresh", 0);
3889 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3890 m_mltConsumer->purge();
3891 QString scene = sceneList();
3893 if (m_mltProducer) {
3894 pos = m_mltProducer->position();
3897 setSceneList(scene, pos);
3901 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3903 // Update all frame positions to the new fps value
3904 //WARNING: there are probably some effects or other that hold a frame value
3905 // as parameter and will also need to be updated here!
3907 doc.setContent(scene);
3909 double factor = new_fps / current_fps;
3910 QDomNodeList producers = doc.elementsByTagName("producer");
3911 for (int i = 0; i < producers.count(); i++) {
3912 QDomElement prod = producers.at(i).toElement();
3913 prod.removeAttribute("in");
3914 prod.removeAttribute("out");
3916 QDomNodeList props = prod.childNodes();
3917 for (int j = 0; j < props.count(); j++) {
3918 QDomElement param = props.at(j).toElement();
3919 QString paramName = param.attribute("name");
3920 if (paramName.startsWith("meta.") || paramName == "length") {
3921 prod.removeChild(props.at(j));
3927 QDomNodeList entries = doc.elementsByTagName("entry");
3928 for (int i = 0; i < entries.count(); i++) {
3929 QDomElement entry = entries.at(i).toElement();
3930 int in = entry.attribute("in").toInt();
3931 int out = entry.attribute("out").toInt();
3932 in = factor * in + 0.5;
3933 out = factor * out + 0.5;
3934 entry.setAttribute("in", in);
3935 entry.setAttribute("out", out);
3938 QDomNodeList blanks = doc.elementsByTagName("blank");
3939 for (int i = 0; i < blanks.count(); i++) {
3940 QDomElement blank = blanks.at(i).toElement();
3941 int length = blank.attribute("length").toInt();
3942 length = factor * length + 0.5;
3943 blank.setAttribute("length", QString::number(length));
3946 QDomNodeList filters = doc.elementsByTagName("filter");
3947 for (int i = 0; i < filters.count(); i++) {
3948 QDomElement filter = filters.at(i).toElement();
3949 int in = filter.attribute("in").toInt();
3950 int out = filter.attribute("out").toInt();
3951 in = factor * in + 0.5;
3952 out = factor * out + 0.5;
3953 filter.setAttribute("in", in);
3954 filter.setAttribute("out", out);
3957 QDomNodeList transitions = doc.elementsByTagName("transition");
3958 for (int i = 0; i < transitions.count(); i++) {
3959 QDomElement transition = transitions.at(i).toElement();
3960 int in = transition.attribute("in").toInt();
3961 int out = transition.attribute("out").toInt();
3962 in = factor * in + 0.5;
3963 out = factor * out + 0.5;
3964 transition.setAttribute("in", in);
3965 transition.setAttribute("out", out);
3966 QDomNodeList props = transition.childNodes();
3967 for (int j = 0; j < props.count(); j++) {
3968 QDomElement param = props.at(j).toElement();
3969 QString paramName = param.attribute("name");
3970 if (paramName == "geometry") {
3971 QString geom = param.firstChild().nodeValue();
3972 QStringList keys = geom.split(';');
3973 QStringList newKeys;
3974 for (int k = 0; k < keys.size(); ++k) {
3975 if (keys.at(k).contains('=')) {
3976 int pos = keys.at(k).section('=', 0, 0).toInt();
3977 pos = factor * pos + 0.5;
3978 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3979 } else newKeys.append(keys.at(k));
3981 param.firstChild().setNodeValue(newKeys.join(";"));
3985 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3986 int out = tractor.attribute("out").toInt();
3987 out = factor * out + 0.5;
3988 tractor.setAttribute("out", out);
3989 emit durationChanged(out);
3991 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3992 return doc.toString();
3996 void Render::sendFrameUpdate()
3998 if (m_mltProducer) {
3999 Mlt::Frame * frame = m_mltProducer->get_frame();
4000 emitFrameUpdated(*frame);
4006 #include "renderer.moc"