1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
30 #include "slideshowclip.h"
31 #include "profilesdialog.h"
32 #include "blackmagic/devices.h"
34 #include <mlt++/Mlt.h>
37 #include <KStandardDirs>
38 #include <KMessageBox>
40 #include <KTemporaryFile>
45 #include <QApplication>
52 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
54 if (level > MLT_LOG_ERROR) return;
56 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
61 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
63 // detect if the producer has finished playing. Is there a better way to do it?
64 if (self->m_isBlocked) return;
65 Mlt::Frame frame(frame_ptr);
66 if (!frame.is_valid()) return;
67 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
68 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
69 self->emitFrameUpdated(frame);
71 if (self->analyseAudio) {
72 self->showAudio(frame);
74 if (frame.get_double("_speed") == 0.0) {
75 self->emitConsumerStopped();
76 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
78 self->emitConsumerStopped();
82 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
84 // detect if the producer has finished playing. Is there a better way to do it?
85 if (self->m_isBlocked) return;
86 Mlt::Frame frame(frame_ptr);
87 self->showFrame(frame);
88 if (frame.get_double("_speed") == 0.0) {
89 self->emitConsumerStopped();
90 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
92 self->emitConsumerStopped();
96 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
99 sendFrameForAnalysis(false),
100 analyseAudio(KdenliveSettings::monitor_audio()),
101 m_name(rendererName),
106 m_externalConsumer(false),
109 m_isSplitView(false),
113 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
114 buildConsumer(profile);
116 m_mltProducer = m_blackClip->cut(0, 50);
117 m_mltConsumer->connect(*m_mltProducer);
118 m_mltProducer->set_speed(0.0);
128 void Render::closeMlt()
132 Mlt::Service service(m_mltProducer->parent().get_service());
133 mlt_service_lock(service.get_service());
135 if (service.type() == tractor_type) {
136 Mlt::Tractor tractor(service);
137 Mlt::Field *field = tractor.field();
138 mlt_service nextservice = mlt_service_get_producer(service.get_service());
139 mlt_service nextservicetodisconnect;
140 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
141 QString mlt_type = mlt_properties_get(properties, "mlt_type");
142 QString resource = mlt_properties_get(properties, "mlt_service");
143 // Delete all transitions
144 while (mlt_type == "transition") {
145 nextservicetodisconnect = nextservice;
146 nextservice = mlt_service_producer(nextservice);
147 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
148 nextservice = mlt_service_producer(nextservice);
149 if (nextservice == NULL) break;
150 properties = MLT_SERVICE_PROPERTIES(nextservice);
151 mlt_type = mlt_properties_get(properties, "mlt_type");
152 resource = mlt_properties_get(properties, "mlt_service");
155 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
156 Mlt::Producer trackProducer(tractor.track(trackNb));
157 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
158 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
161 mlt_service_unlock(service.get_service());
164 kDebug() << "// // // CLOSE RENDERER " << m_name;
165 delete m_mltConsumer;
166 delete m_mltProducer;
171 void Render::slotSwitchFullscreen()
173 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
176 void Render::buildConsumer(const QString profileName)
178 m_activeProfile = profileName;
179 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
180 setenv("MLT_PROFILE", tmp, 1);
184 //TODO: uncomment following line when everything is clean
185 //if (m_mltProfile) delete m_mltProfile;
186 m_mltProfile = new Mlt::Profile(tmp);
187 m_mltProfile->get_profile()->is_explicit = 1;
190 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
191 m_blackClip->set("id", "black");
192 m_blackClip->set("mlt_type", "producer");
194 if (KdenliveSettings::external_display() && m_name != "clip") {
195 // Use blackmagic card for video output
196 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
197 if (BMInterface::isSupportedProfile(KdenliveSettings::blackmagic_output_device(), profileProperties)) {
198 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
199 tmp = qstrdup(decklink.toUtf8().constData());
200 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, tmp);
202 if (m_mltConsumer->is_valid()) {
203 m_externalConsumer = true;
204 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
205 m_mltConsumer->set("terminate_on_pause", 0);
206 m_mltConsumer->set("buffer", 12);
207 m_mltConsumer->set("deinterlace_method", "onefield");
208 mlt_log_set_callback(kdenlive_callback);
210 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
211 } 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()));
213 m_externalConsumer = false;
214 QString videoDriver = KdenliveSettings::videodrivername();
215 if (!videoDriver.isEmpty()) {
216 if (videoDriver == "x11_noaccel") {
217 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
220 unsetenv("SDL_VIDEO_YUV_HWACCEL");
223 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
225 //m_mltConsumer->set("fullscreen", 1);
228 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
229 m_mltConsumer->set("preview_off", 1);
230 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
231 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
233 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
234 // FIXME: the event object returned by the listen gets leaked...
235 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
236 m_mltConsumer->set("window_id", m_winid);
238 m_mltConsumer->set("resize", 1);
239 m_mltConsumer->set("terminate_on_pause", 1);
240 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
241 m_mltConsumer->set("rescale", "nearest");
242 mlt_log_set_callback(kdenlive_callback);
244 QString audioDevice = KdenliveSettings::audiodevicename();
245 if (!audioDevice.isEmpty())
246 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
248 if (!videoDriver.isEmpty())
249 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
251 QString audioDriver = KdenliveSettings::audiodrivername();
254 // Disabled because the "auto" detected driver was sometimes wrong
255 if (audioDriver.isEmpty())
256 audioDriver = KdenliveSettings::autoaudiodrivername();
259 if (!audioDriver.isEmpty())
260 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
262 m_mltConsumer->set("progressive", 1);
263 m_mltConsumer->set("audio_buffer", 1024);
264 m_mltConsumer->set("frequency", 48000);
267 Mlt::Producer *Render::invalidProducer(const QString &id)
269 Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
270 clip->set("id", id.toUtf8().constData());
271 clip->set("mlt_type", "producer");
275 int Render::resetProfile(const QString profileName)
278 if (m_externalConsumer == KdenliveSettings::external_display()) {
279 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
280 QString videoDriver = KdenliveSettings::videodrivername();
281 QString currentDriver = m_mltConsumer->get("video_driver");
282 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
283 QString background = KdenliveSettings::window_background().name();
284 QString currentBackground = m_mltConsumer->get("window_background");
285 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
286 kDebug() << "reset to same profile, nothing to do";
291 if (m_isSplitView) slotSplitView(false);
292 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
293 m_mltConsumer->purge();
294 delete m_mltConsumer;
295 m_mltConsumer = NULL;
297 QString scene = sceneList();
299 double current_fps = m_mltProfile->fps();
304 pos = m_mltProducer->position();
306 Mlt::Service service(m_mltProducer->get_service());
307 if (service.type() == tractor_type) {
308 Mlt::Tractor tractor(service);
309 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
310 Mlt::Producer trackProducer(tractor.track(trackNb));
311 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
312 trackPlaylist.clear();
316 delete m_mltProducer;
318 m_mltProducer = NULL;
319 buildConsumer(profileName);
320 double new_fps = m_mltProfile->fps();
321 if (current_fps != new_fps) {
322 // fps changed, we must update the scenelist positions
323 scene = updateSceneListFps(current_fps, new_fps, scene);
325 //kDebug() << "//RESET WITHSCENE: " << scene;
326 setSceneList(scene, pos);
327 // producers have changed (different profile), so reset them...
328 emit refreshDocumentProducers();
329 /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
330 m_mltProducer = producer;
331 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
332 m_mltProducer->optimise();
333 m_mltProducer->set_speed(0);
336 //delete m_mltProfile;
337 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
338 //mlt_profile prof = m_mltProfile->get_profile();
339 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
340 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
341 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
342 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
344 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
349 void Render::seek(GenTime time)
354 m_mltProducer->seek((int)(time.frames(m_fps)));
359 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
360 QPixmap pix(width, height);
362 mlt_image_format format = mlt_image_rgb24a;
363 uint8_t *thumb = frame->get_image(format, width, height);
364 QImage image(thumb, width, height, QImage::Format_ARGB32);
366 if (!image.isNull()) {
367 pix = pix.fromImage(image);
369 QPainter painter(&pix);
370 painter.drawRect(0, 0, width - 1, height - 1);
372 } else pix.fill(Qt::black);
376 int Render::frameRenderWidth() const
378 return m_mltProfile->width();
381 int Render::renderWidth() const
383 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
386 int Render::renderHeight() const
388 return m_mltProfile->height();
391 QImage Render::extractFrame(int frame_position, int width, int height)
394 width = renderWidth();
395 height = renderHeight();
396 } else if (width % 2 == 1) width++;
398 if (!m_mltProducer) {
399 QImage pix(width, height, QImage::Format_RGB32);
403 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
406 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
410 if (url.fileName().startsWith(".all.")) { // check for slideshow
411 QString fileType = url.fileName().right(3);
413 QStringList::Iterator it;
415 QDir dir(url.directory());
417 filter << "*." + fileType;
418 filter << "*." + fileType.toUpper();
419 more = dir.entryList(filter, QDir::Files);
420 im.load(url.directory() + '/' + more.at(0));
421 } else im.load(url.path());
422 //pixmap = im.scaled(width, height);
426 double Render::consumerRatio() const
428 if (!m_mltConsumer) return 1.0;
429 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
433 int Render::getLength()
437 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
438 return mlt_producer_get_playtime(m_mltProducer->get_producer());
443 bool Render::isValid(KUrl url)
445 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
446 if (producer.is_blank())
452 double Render::dar() const
454 return m_mltProfile->dar();
458 void Render::slotSplitView(bool doit)
460 m_isSplitView = doit;
461 Mlt::Service service(m_mltProducer->parent().get_service());
462 Mlt::Tractor tractor(service);
463 if (service.type() != tractor_type || tractor.count() < 2) return;
464 Mlt::Field *field = tractor.field();
466 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
467 Mlt::Producer trackProducer(tractor.track(i));
468 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
469 if (QString(trackProducer.get("hide")).toInt() != 1) {
470 kDebug() << "// ADIDNG TRACK: " << i;
471 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
472 transition->set("mlt_service", "composite");
473 transition->set("a_track", 0);
474 transition->set("b_track", i);
475 transition->set("distort", 1);
476 transition->set("internal_added", "200");
483 tmp = "50%,0:50%x50%";
486 tmp = "0,50%:50%x50%";
490 tmp = "50%,50%:50%x50%";
493 transition->set("geometry", tmp);
494 transition->set("always_active", "1");
495 field->plant_transition(*transition, 0, i);
500 m_mltConsumer->set("refresh", 1);
502 mlt_service serv = m_mltProducer->parent().get_service();
503 mlt_service nextservice = mlt_service_get_producer(serv);
504 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
505 QString mlt_type = mlt_properties_get(properties, "mlt_type");
506 QString resource = mlt_properties_get(properties, "mlt_service");
508 while (mlt_type == "transition") {
509 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
510 if (added == "200") {
511 mlt_field_disconnect_service(field->get_field(), nextservice);
513 nextservice = mlt_service_producer(nextservice);
514 if (nextservice == NULL) break;
515 properties = MLT_SERVICE_PROPERTIES(nextservice);
516 mlt_type = mlt_properties_get(properties, "mlt_type");
517 resource = mlt_properties_get(properties, "mlt_service");
518 m_mltConsumer->set("refresh", 1);
523 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
525 KUrl url = KUrl(xml.attribute("resource", QString()));
526 Mlt::Producer *producer = NULL;
527 CLIPTYPE type = (CLIPTYPE)xml.attribute("type").toInt();
529 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
530 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
531 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
536 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
537 } else if (type == TEXT) {
538 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
539 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
540 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
541 } else if (url.isEmpty()) {
543 QDomElement mlt = doc.createElement("mlt");
544 QDomElement play = doc.createElement("playlist");
545 doc.appendChild(mlt);
546 mlt.appendChild(play);
547 play.appendChild(doc.importNode(xml, true));
548 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
550 producer = new Mlt::Producer(*m_mltProfile, url.path().toUtf8().constData());
553 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
554 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
555 emit removeInvalidClip(clipId, replaceProducer);
560 if (xml.hasAttribute("force_aspect_ratio")) {
561 double aspect = xml.attribute("force_aspect_ratio").toDouble();
562 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
565 if (xml.hasAttribute("force_aspect_num") && xml.hasAttribute("force_aspect_den")) {
566 int width = xml.attribute("frame_size").section('x', 0, 0).toInt();
567 int height = xml.attribute("frame_size").section('x', 1, 1).toInt();
568 int aspectNumerator = xml.attribute("force_aspect_num").toInt();
569 int aspectDenominator = xml.attribute("force_aspect_den").toInt();
570 if (aspectDenominator != 0 && width != 0)
571 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
574 if (xml.hasAttribute("force_fps")) {
575 double fps = xml.attribute("force_fps").toDouble();
576 if (fps > 0) producer->set("force_fps", fps);
579 if (xml.hasAttribute("force_progressive")) {
581 int progressive = xml.attribute("force_progressive").toInt(&ok);
582 if (ok) producer->set("force_progressive", progressive);
584 if (xml.hasAttribute("force_tff")) {
586 int fieldOrder = xml.attribute("force_tff").toInt(&ok);
587 if (ok) producer->set("force_tff", fieldOrder);
589 if (xml.hasAttribute("threads")) {
590 int threads = xml.attribute("threads").toInt();
591 if (threads != 1) producer->set("threads", threads);
593 if (xml.hasAttribute("video_index")) {
594 int vindex = xml.attribute("video_index").toInt();
595 if (vindex != 0) producer->set("video_index", vindex);
597 if (xml.hasAttribute("audio_index")) {
598 int aindex = xml.attribute("audio_index").toInt();
599 if (aindex != 0) producer->set("audio_index", aindex);
601 if (xml.hasAttribute("force_colorspace")) {
602 int colorspace = xml.attribute("force_colorspace").toInt();
603 if (colorspace != 0) producer->set("force_colorspace", colorspace);
605 if (xml.hasAttribute("full_luma")) {
606 int full_luma = xml.attribute("full_luma").toInt();
607 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
610 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
611 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW)
612 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
614 if (xml.hasAttribute("out"))
615 producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
617 producer->set("id", clipId.toUtf8().constData());
619 if (xml.hasAttribute("templatetext"))
620 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
622 if (!replaceProducer && xml.hasAttribute("file_hash")) {
623 // Clip already has all properties
624 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
628 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
629 QMap < QString, QString > filePropertyMap;
630 QMap < QString, QString > metadataPropertyMap;
632 int frameNumber = xml.attribute("thumbnail", "0").toInt();
633 if (frameNumber != 0) producer->seek(frameNumber);
635 filePropertyMap["duration"] = QString::number(producer->get_playtime());
636 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
638 Mlt::Frame *frame = producer->get_frame();
640 if (type == SLIDESHOW) {
641 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
642 if (ttl) producer->set("ttl", ttl);
643 if (!xml.attribute("animation").isEmpty()) {
644 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
645 if (filter && filter->is_valid()) {
647 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
648 if (!geometry.isEmpty()) {
649 if (xml.attribute("animation").contains("low-pass")) {
650 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
651 if (blur && blur->is_valid())
652 producer->attach(*blur);
654 filter->set("transition.geometry", geometry.toUtf8().data());
655 filter->set("transition.cycle", cycle);
656 producer->attach(*filter);
660 if (xml.attribute("fade") == "1") {
661 // user wants a fade effect to slideshow
662 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
663 if (filter && filter->is_valid()) {
664 if (ttl) filter->set("cycle", ttl);
665 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
666 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
667 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
668 if (xml.hasAttribute("softness")) {
669 int soft = xml.attribute("softness").toInt();
670 filter->set("luma.softness", (double) soft / 100.0);
673 producer->attach(*filter);
676 if (xml.attribute("crop") == "1") {
677 // user wants to center crop the slides
678 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
679 if (filter && filter->is_valid()) {
680 filter->set("center", 1);
681 producer->attach(*filter);
686 if (producer->get_double("meta.media.frame_rate_den") > 0) {
687 filePropertyMap["fps"] = QString::number(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
688 } else filePropertyMap["fps"] = producer->get("source_fps");
690 if (frame && frame->is_valid()) {
691 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
692 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
693 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
694 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
696 if (frame->get_int("test_image") == 0) {
697 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
698 filePropertyMap["type"] = "playlist";
699 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
700 } else if (frame->get_int("test_audio") == 0)
701 filePropertyMap["type"] = "av";
703 filePropertyMap["type"] = "video";
705 mlt_image_format format = mlt_image_rgb24a;
706 int frame_width = width;
707 int frame_height = imageHeight;
708 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
709 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied);
712 if (!image.isNull()) {
713 if (frame_width > (2 * width)) {
714 // there was a scaling problem, do it manually
715 QImage scaled = image.scaled(width, imageHeight);
716 pix = QPixmap::fromImage(scaled.rgbSwapped());
717 } else pix = QPixmap::fromImage(image.rgbSwapped());
721 emit replyGetImage(clipId, pix);
723 } else if (frame->get_int("test_audio") == 0) {
724 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
725 emit replyGetImage(clipId, pixmap);
726 filePropertyMap["type"] = "audio";
730 // Retrieve audio / video codec name
734 if (producer->get_int("video_index") > -1) {
735 /*if (context->duration == AV_NOPTS_VALUE) {
736 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
737 emit removeInvalidClip(clipId);
741 // Get the video_index
742 int default_video = producer->get_int("video_index");
744 int default_audio = producer->get_int("audio_index");
747 // Find maximum stream index values
748 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
749 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
750 QString type = producer->get(property);
753 else if (type == "audio")
756 filePropertyMap["default_video"] = QString::number(default_video);
757 filePropertyMap["video_max"] = QString::number(video_max);
758 filePropertyMap["default_audio"] = QString::number(default_audio);
759 filePropertyMap["audio_max"] = QString::number(audio_max);
761 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
762 if (producer->get(property)) {
763 filePropertyMap["videocodec"] = producer->get(property);
765 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
766 if (producer->get(property))
767 filePropertyMap["videocodec"] = producer->get(property);
770 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
771 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
772 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
774 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
775 if (producer->get_int("audio_index") > -1) {
776 // Get the audio_index
777 int index = producer->get_int("audio_index");
779 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
780 if (producer->get(property)) {
781 filePropertyMap["audiocodec"] = producer->get(property);
783 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
784 if (producer->get(property))
785 filePropertyMap["audiocodec"] = producer->get(property);
790 Mlt::Properties metadata;
791 metadata.pass_values(*producer, "meta.attr.");
792 int count = metadata.count();
793 for (int i = 0; i < count; i ++) {
794 QString name = metadata.get_name(i);
795 QString value = QString::fromUtf8(metadata.get(i));
796 if (name.endsWith("markup") && !value.isEmpty())
797 metadataPropertyMap[ name.section('.', 0, -2)] = value;
800 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
801 // FIXME: should delete this to avoid a leak...
807 /** Create the producer from the MLT XML QDomDocument */
808 void Render::initSceneList()
810 kDebug() << "-------- INIT SCENE LIST ------_";
812 QDomElement mlt = doc.createElement("mlt");
813 doc.appendChild(mlt);
814 QDomElement prod = doc.createElement("producer");
815 prod.setAttribute("resource", "colour");
816 prod.setAttribute("colour", "red");
817 prod.setAttribute("id", "black");
818 prod.setAttribute("in", "0");
819 prod.setAttribute("out", "0");
821 QDomElement tractor = doc.createElement("tractor");
822 QDomElement multitrack = doc.createElement("multitrack");
824 QDomElement playlist1 = doc.createElement("playlist");
825 playlist1.appendChild(prod);
826 multitrack.appendChild(playlist1);
827 QDomElement playlist2 = doc.createElement("playlist");
828 multitrack.appendChild(playlist2);
829 QDomElement playlist3 = doc.createElement("playlist");
830 multitrack.appendChild(playlist3);
831 QDomElement playlist4 = doc.createElement("playlist");
832 multitrack.appendChild(playlist4);
833 QDomElement playlist5 = doc.createElement("playlist");
834 multitrack.appendChild(playlist5);
835 tractor.appendChild(multitrack);
836 mlt.appendChild(tractor);
837 // kDebug()<<doc.toString();
839 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
840 setSceneList(doc, 0);
844 int Render::setProducer(Mlt::Producer *producer, int position)
846 if (m_winid == -1) return -1;
849 m_mltConsumer->stop();
852 m_mltConsumer->purge();
855 m_mltProducer->set_speed(0);
856 delete m_mltProducer;
857 m_mltProducer = NULL;
861 m_mltProducer = new Mlt::Producer(producer->get_producer());
862 } else m_mltProducer = m_blackClip->cut(0, 50);
864 if (!m_mltProducer || !m_mltProducer->is_valid()) {
865 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
868 int volume = KdenliveSettings::volume();
869 m_mltProducer->set("meta.volume", (double)volume / 100);
870 m_fps = m_mltProducer->get_fps();
871 int error = connectPlaylist();
873 if (position != -1) {
874 m_mltProducer->seek(position);
875 emit rendererPosition(position);
876 } else emit rendererPosition((int) m_mltProducer->position());
881 int Render::setSceneList(QDomDocument list, int position)
883 return setSceneList(list.toString(), position);
886 int Render::setSceneList(QString playlist, int position)
888 if (m_winid == -1) return -1;
892 //kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
895 if (!m_mltConsumer->is_stopped()) {
896 m_mltConsumer->stop();
898 m_mltConsumer->set("refresh", 0);
900 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
905 m_mltProducer->set_speed(0);
906 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
909 Mlt::Service service(m_mltProducer->parent().get_service());
910 mlt_service_lock(service.get_service());
912 if (service.type() == tractor_type) {
913 Mlt::Tractor tractor(service);
914 Mlt::Field *field = tractor.field();
915 mlt_service nextservice = mlt_service_get_producer(service.get_service());
916 mlt_service nextservicetodisconnect;
917 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
918 QString mlt_type = mlt_properties_get(properties, "mlt_type");
919 QString resource = mlt_properties_get(properties, "mlt_service");
920 // Delete all transitions
921 while (mlt_type == "transition") {
922 nextservicetodisconnect = nextservice;
923 nextservice = mlt_service_producer(nextservice);
924 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
925 if (nextservice == NULL) break;
926 properties = MLT_SERVICE_PROPERTIES(nextservice);
927 mlt_type = mlt_properties_get(properties, "mlt_type");
928 resource = mlt_properties_get(properties, "mlt_service");
931 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
932 Mlt::Producer trackProducer(tractor.track(trackNb));
933 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
934 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
938 mlt_service_unlock(service.get_service());
940 qDeleteAll(m_slowmotionProducers.values());
941 m_slowmotionProducers.clear();
943 delete m_mltProducer;
944 m_mltProducer = NULL;
950 // TODO: Better way to do this
951 if (KdenliveSettings::projectloading_avformatnovalidate())
952 playlist.replace(">avformat</property>", ">avformat-novalidate</property>");
954 playlist.replace(">avformat-novalidate</property>", ">avformat</property>");
956 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
958 if (!m_mltProducer || !m_mltProducer->is_valid()) {
959 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
960 m_mltProducer = m_blackClip->cut(0, 50);
963 int volume = KdenliveSettings::volume();
964 m_mltProducer->set("meta.volume", (double)volume / 100);
965 m_mltProducer->optimise();
967 /*if (KdenliveSettings::osdtimecode()) {
968 // Attach filter for on screen display of timecode
970 QString attr = "attr_check";
971 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
972 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
973 mlt_producer_attach( m_mltProducer->get_producer(), filter );
974 mlt_filter_close( filter );
976 m_osdInfo = new Mlt::Filter("data_show");
977 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
978 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
979 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
980 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
981 m_osdInfo->set("dynamic", "1");
983 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
985 m_osdInfo->set("dynamic", "0");
988 m_fps = m_mltProducer->get_fps();
990 // Seek to correct place after opening project.
991 m_mltProducer->seek(position);
994 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
995 if (error == 0) error = connectPlaylist();
996 else connectPlaylist();
997 fillSlowMotionProducers();
1000 blockSignals(false);
1003 //kDebug()<<"// SETSCN LST, POS: "<<position;
1004 //if (position != 0) emit rendererPosition(position);
1007 const QString Render::sceneList()
1010 Mlt::Profile profile((mlt_profile) 0);
1011 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1012 m_mltProducer->optimise();
1013 xmlConsumer.set("terminate_on_pause", 1);
1014 Mlt::Producer prod(m_mltProducer->get_producer());
1015 bool split = m_isSplitView;
1016 if (split) slotSplitView(false);
1017 xmlConsumer.connect(prod);
1018 xmlConsumer.start();
1019 while (!xmlConsumer.is_stopped()) {}
1020 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1021 if (split) slotSplitView(true);
1025 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1029 doc.setContent(sceneList(), false);
1030 if (!kdenliveData.isNull()) {
1031 // add Kdenlive specific tags
1032 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1033 mlt.appendChild(doc.importNode(kdenliveData, true));
1035 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1036 kWarning() << "////// ERROR writing to file: " << path;
1039 file.write(doc.toString().toUtf8());
1040 if (file.error() != QFile::NoError) {
1048 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1050 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1051 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1052 m_mltProducer->optimise();
1053 xmlConsumer.set("terminate_on_pause", 1);
1054 if (m_name == "clip") {
1055 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1057 list.insert_at(0, prod, 0);
1059 list.set("title", desc.toUtf8().constData());
1060 xmlConsumer.connect(list);
1063 //TODO: not working yet, save zone from timeline
1064 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1065 /* Mlt::Service service(p1->parent().get_service());
1066 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1068 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1069 //prod->set("title", desc.toUtf8().constData());
1070 xmlConsumer.connect(*p1); //list);
1073 xmlConsumer.start();
1076 double Render::fps() const
1081 int Render::connectPlaylist()
1083 if (!m_mltConsumer) return -1;
1084 //m_mltConsumer->set("refresh", "0");
1085 m_mltConsumer->connect(*m_mltProducer);
1086 m_mltProducer->set_speed(0);
1087 if (m_mltConsumer->start() == -1) {
1088 // ARGH CONSUMER BROKEN!!!!
1089 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."));
1090 delete m_mltConsumer;
1091 m_mltConsumer = NULL;
1094 emit durationChanged(m_mltProducer->get_playtime());
1099 void Render::refreshDisplay()
1102 if (!m_mltProducer) return;
1103 //m_mltConsumer->set("refresh", 0);
1105 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1106 /*if (KdenliveSettings::osdtimecode()) {
1107 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1108 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1109 m_osdInfo->set("dynamic", "1");
1110 m_mltProducer->attach(*m_osdInfo);
1113 m_mltProducer->detach(*m_osdInfo);
1114 m_osdInfo->set("dynamic", "0");
1119 int Render::volume() const
1121 if (!m_mltConsumer || !m_mltProducer) return -1;
1122 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1125 void Render::slotSetVolume(int volume)
1127 if (!m_mltConsumer || !m_mltProducer) return;
1128 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1131 m_mltConsumer->set("refresh", 0);
1132 // Attach filter for on screen display of timecode
1133 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1134 mlt_properties_set_double( properties, "meta.volume", volume );
1135 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1136 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1138 if (!KdenliveSettings::osdtimecode()) {
1139 m_mltProducer->detach(*m_osdInfo);
1140 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1141 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1144 //m_osdTimer->setSingleShot(2500);
1147 void Render::slotOsdTimeout()
1149 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1150 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1151 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1152 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1156 void Render::start()
1158 kDebug() << "----- STARTING MONITOR: " << m_name;
1159 if (m_winid == -1) {
1160 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1163 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1164 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1165 if (m_mltConsumer->start() == -1) {
1166 //KMessageBox::error(qApp->activeWindow(), i18n("Could not create the video preview window.\nThere is something wrong with your Kdenlive install or your driver settings, please fix it."));
1167 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1169 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1170 m_isBlocked = false;
1174 m_isBlocked = false;
1179 if (m_mltProducer == NULL) return;
1180 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1181 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1183 //m_mltConsumer->set("refresh", 0);
1184 m_mltConsumer->stop();
1185 // delete m_mltConsumer;
1186 // m_mltConsumer = NULL;
1188 kDebug() << "///////////// RENDER STOP2-------";
1191 if (m_mltProducer) {
1192 if (m_isZoneMode) resetZoneMode();
1193 m_mltProducer->set_speed(0.0);
1194 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1195 //kDebug() << m_mltProducer->get_length();
1197 kDebug() << "///////////// RENDER STOP3-------";
1200 void Render::stop(const GenTime & startTime)
1203 kDebug() << "///////////// RENDER STOP-------2";
1204 if (m_mltProducer) {
1205 if (m_isZoneMode) resetZoneMode();
1206 m_mltProducer->set_speed(0.0);
1207 m_mltProducer->seek((int) startTime.frames(m_fps));
1209 m_mltConsumer->purge();
1212 void Render::pause()
1214 if (!m_mltProducer || !m_mltConsumer)
1216 if (m_mltProducer->get_speed() == 0.0) return;
1217 if (m_isZoneMode) resetZoneMode();
1219 m_mltConsumer->set("refresh", 0);
1220 m_mltProducer->set_speed(0.0);
1222 The 2 lines below create a flicker loop
1223 emit rendererPosition(m_framePosition);
1224 m_mltProducer->seek(m_framePosition);*/
1225 m_mltConsumer->purge();
1228 void Render::switchPlay()
1230 if (!m_mltProducer || !m_mltConsumer)
1232 if (m_isZoneMode) resetZoneMode();
1233 if (m_mltProducer->get_speed() == 0.0) {
1234 m_isBlocked = false;
1235 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1236 m_mltProducer->set_speed(1.0);
1237 m_mltConsumer->set("refresh", 1);
1240 m_mltConsumer->set("refresh", 0);
1241 m_mltProducer->set_speed(0.0);
1242 //emit rendererPosition(m_framePosition);
1243 m_mltProducer->seek(m_framePosition);
1244 m_mltConsumer->purge();
1245 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1246 //m_mltConsumer->set("refresh", 0);
1247 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1248 m_mltProducer->set_speed(0);
1249 m_mltProducer->seek( position );
1250 //m_mltProducer->seek((int) m_framePosition);
1251 m_isBlocked = false;*/
1253 /*if (speed == 0.0) {
1254 m_mltProducer->seek((int) m_framePosition + 1);
1255 m_mltConsumer->purge();
1260 void Render::play(double speed)
1264 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1265 m_isBlocked = false;
1266 m_mltProducer->set_speed(speed);
1267 /*if (speed == 0.0) {
1268 m_mltProducer->seek((int) m_framePosition + 1);
1269 m_mltConsumer->purge();
1274 void Render::play(const GenTime & startTime)
1276 if (!m_mltProducer || !m_mltConsumer)
1278 m_isBlocked = false;
1279 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1280 m_mltProducer->set_speed(1.0);
1281 m_mltConsumer->set("refresh", 1);
1284 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1286 if (!m_mltProducer || !m_mltConsumer)
1288 //m_mltProducer->set("eof", "loop");
1289 m_isLoopMode = true;
1290 m_loopStart = startTime;
1291 playZone(startTime, stopTime);
1294 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1296 if (!m_mltProducer || !m_mltConsumer)
1298 m_isBlocked = false;
1299 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1300 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1301 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1302 m_mltProducer->set_speed(1.0);
1303 m_mltConsumer->set("refresh", 1);
1304 m_isZoneMode = true;
1307 void Render::resetZoneMode()
1309 if (!m_isZoneMode && !m_isLoopMode) return;
1310 m_mltProducer->set("out", m_originalOut);
1311 //m_mltProducer->set("eof", "pause");
1312 m_isZoneMode = false;
1313 m_isLoopMode = false;
1316 void Render::seekToFrame(int pos)
1318 //kDebug()<<" ********* RENDER SEEK TO POS";
1321 m_isBlocked = false;
1323 m_mltProducer->seek(pos);
1327 void Render::seekToFrameDiff(int diff)
1329 //kDebug()<<" ********* RENDER SEEK TO POS";
1332 m_isBlocked = false;
1334 m_mltProducer->seek(m_mltProducer->position() + diff);
1338 void Render::doRefresh()
1340 // Use a Timer so that we don't refresh too much
1341 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1344 void Render::refresh()
1346 if (!m_mltProducer || m_isBlocked)
1348 if (m_mltConsumer) {
1349 m_mltConsumer->set("refresh", 1);
1353 void Render::setDropFrames(bool show)
1355 if (m_mltConsumer) {
1357 if (show == false) dropFrames = 0;
1358 m_mltConsumer->stop();
1360 m_mltConsumer->set("real_time", dropFrames);
1362 m_mltConsumer->set("play.real_time", dropFrames);
1364 if (m_mltConsumer->start() == -1) {
1365 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1371 double Render::playSpeed()
1373 if (m_mltProducer) return m_mltProducer->get_speed();
1377 GenTime Render::seekPosition() const
1379 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1380 else return GenTime();
1383 int Render::seekFramePosition() const
1385 if (m_mltProducer) return (int) m_mltProducer->position();
1389 const QString & Render::rendererName() const
1394 void Render::emitFrameUpdated(Mlt::Frame& frame)
1396 mlt_image_format format = mlt_image_rgb24a;
1399 const uchar* image = frame.get_image(format, width, height);
1400 QImage qimage(width, height, QImage::Format_ARGB32);
1401 memcpy(qimage.bits(), image, width * height * 4);
1402 emit frameUpdated(qimage.rgbSwapped());
1405 void Render::emitFrameNumber(double position)
1407 m_framePosition = position;
1408 emit rendererPosition((int) position);
1411 void Render::emitConsumerStopped()
1413 // This is used to know when the playing stopped
1414 if (m_mltProducer) {
1415 double pos = m_mltProducer->position();
1416 if (m_isLoopMode) play(m_loopStart);
1417 else if (m_isZoneMode) resetZoneMode();
1418 emit rendererStopped((int) pos);
1422 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1424 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1427 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1429 if (!m_mltProducer) {
1430 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1434 //int height = 1080;//KdenliveSettings::defaultheight();
1435 //int width = 1940; //KdenliveSettings::displaywidth();
1437 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1439 QPixmap pix(width, height);
1440 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1441 m_convert.set("forced", mlt_image_rgb24a);
1442 m_mltProducer->attach(m_convert);
1443 Mlt::Frame * frame = m_mltProducer->get_frame();
1444 m_mltProducer->detach(m_convert);
1446 pix = frameThumbnail(frame, width, height);
1449 pix.save(url.path(), "PNG");
1450 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1454 void Render::showFrame(Mlt::Frame& frame)
1456 m_framePosition = qMax(frame.get_int("_position"), 0);
1457 emit rendererPosition((int) m_framePosition);
1458 mlt_image_format format = mlt_image_rgb24a;
1461 const uchar* image = frame.get_image(format, width, height);
1462 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1463 memcpy(qimage.scanLine(0), image, width * height * 4);
1464 emit showImageSignal(qimage);
1465 if (analyseAudio) showAudio(frame);
1466 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1467 emit frameUpdated(qimage.rgbSwapped());
1471 void Render::showAudio(Mlt::Frame& frame)
1473 if (!frame.is_valid() || frame.get_int("test_audio") != 0) {
1476 mlt_audio_format audio_format = mlt_audio_s16;
1478 int num_channels = 0;
1480 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1486 // Data format: [ c00 c10 c01 c11 c02 c12 c03 c13 ... c0{samples-1} c1{samples-1} for 2 channels.
1487 // So the vector is of size samples*channels.
1488 QVector<int16_t> sampleVector(samples*num_channels);
1489 memcpy(sampleVector.data(), data, samples*num_channels*sizeof(int16_t));
1492 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1497 * MLT playlist direct manipulation.
1500 void Render::mltCheckLength(Mlt::Tractor *tractor)
1502 //kDebug()<<"checking track length: "<<track<<"..........";
1504 int trackNb = tractor->count();
1508 Mlt::Producer trackProducer(tractor->track(0));
1509 duration = trackProducer.get_playtime() - 1;
1510 m_mltProducer->set("out", duration);
1511 emit durationChanged(duration);
1514 while (trackNb > 1) {
1515 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1516 trackDuration = trackProducer.get_playtime() - 1;
1517 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1518 if (trackDuration > duration) duration = trackDuration;
1522 Mlt::Producer blackTrackProducer(tractor->track(0));
1524 if (blackTrackProducer.get_playtime() - 1 != duration) {
1525 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1526 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1527 if (blackclip && blackclip->is_blank()) {
1532 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1533 blackTrackPlaylist.clear();
1534 m_blackClip->set("length", duration + 1);
1535 m_blackClip->set("out", duration);
1536 blackclip = m_blackClip->cut(0, duration);
1537 blackTrackPlaylist.insert_at(0, blackclip, 1);
1539 if (duration > blackclip->parent().get_length()) {
1540 blackclip->parent().set("length", duration + 1);
1541 blackclip->parent().set("out", duration);
1542 blackclip->set("length", duration + 1);
1544 blackTrackPlaylist.resize_clip(0, 0, duration);
1548 m_mltProducer->set("out", duration);
1549 emit durationChanged(duration);
1553 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1555 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1557 // We want a slowmotion producer
1558 double speed = element.attribute("speed", "1.0").toDouble();
1559 int strobe = element.attribute("strobe", "1").toInt();
1560 QString url = QString::fromUtf8(prod->get("resource"));
1561 url.append('?' + QString::number(speed));
1562 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1563 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1564 if (!slowprod || slowprod->get_producer() == NULL) {
1565 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1566 if (strobe > 1) slowprod->set("strobe", strobe);
1567 QString id = prod->get("id");
1568 if (id.contains('_')) id = id.section('_', 0, 0);
1569 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1570 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1571 slowprod->set("id", producerid.toUtf8().constData());
1572 m_slowmotionProducers.insert(url, slowprod);
1577 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1579 if (m_mltProducer == NULL) {
1580 kDebug() << "PLAYLIST NOT INITIALISED //////";
1584 kDebug() << "Cannot insert clip without producer //////";
1587 Mlt::Producer parentProd(m_mltProducer->parent());
1588 if (parentProd.get_producer() == NULL) {
1589 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1593 Mlt::Service service(parentProd.get_service());
1594 if (service.type() != tractor_type) {
1595 kWarning() << "// TRACTOR PROBLEM";
1598 Mlt::Tractor tractor(service);
1599 if (info.track > tractor.count() - 1) {
1600 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1603 mlt_service_lock(service.get_service());
1604 Mlt::Producer trackProducer(tractor.track(info.track));
1605 int trackDuration = trackProducer.get_playtime() - 1;
1606 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1607 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1608 prod = checkSlowMotionProducer(prod, element);
1609 if (prod == NULL || !prod->is_valid()) {
1610 mlt_service_unlock(service.get_service());
1614 int cutPos = (int) info.cropStart.frames(m_fps);
1615 if (cutPos < 0) cutPos = 0;
1616 int insertPos = (int) info.startPos.frames(m_fps);
1617 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1618 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1619 if (overwrite && (insertPos < trackDuration)) {
1620 // Replace zone with blanks
1621 //trackPlaylist.split_at(insertPos, true);
1622 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1623 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1624 trackPlaylist.insert_blank(clipIndex, cutDuration);
1626 trackPlaylist.split_at(insertPos, true);
1627 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1628 trackPlaylist.insert_blank(clipIndex, cutDuration);
1630 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1632 /*if (QString(prod->get("transparency")).toInt() == 1)
1633 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1635 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1636 mlt_service_unlock(service.get_service());
1637 /*tractor.multitrack()->refresh();
1638 tractor.refresh();*/
1643 void Render::mltCutClip(int track, GenTime position)
1647 Mlt::Service service(m_mltProducer->parent().get_service());
1648 if (service.type() != tractor_type) {
1649 kWarning() << "// TRACTOR PROBLEM";
1653 Mlt::Tractor tractor(service);
1654 Mlt::Producer trackProducer(tractor.track(track));
1655 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1658 /* // Display playlist info
1659 kDebug()<<"//////////// BEFORE";
1660 for (int i = 0; i < trackPlaylist.count(); i++) {
1661 int blankStart = trackPlaylist.clip_start(i);
1662 int blankDuration = trackPlaylist.clip_length(i) - 1;
1664 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1665 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1668 int cutPos = (int) position.frames(m_fps);
1670 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1671 if (trackPlaylist.is_blank(clipIndex)) {
1672 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1673 m_isBlocked = false;
1676 mlt_service_lock(service.get_service());
1677 int clipStart = trackPlaylist.clip_start(clipIndex);
1678 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1679 mlt_service_unlock(service.get_service());
1681 // duplicate effects
1682 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1683 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1685 if (original == NULL || clip == NULL) {
1686 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1688 Mlt::Service clipService(original->get_service());
1689 Mlt::Service dupService(clip->get_service());
1693 Mlt::Filter *filter = clipService.filter(ct);
1695 // Only duplicate Kdenlive filters, and skip the fade in effects
1696 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1697 // looks like there is no easy way to duplicate a filter,
1698 // so we will create a new one and duplicate its properties
1699 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1700 if (dup && dup->is_valid()) {
1701 Mlt::Properties entries(filter->get_properties());
1702 for (int i = 0; i < entries.count(); i++) {
1703 dup->set(entries.get_name(i), entries.get(i));
1705 dupService.attach(*dup);
1709 filter = clipService.filter(ct);
1712 /* // Display playlist info
1713 kDebug()<<"//////////// AFTER";
1714 for (int i = 0; i < trackPlaylist.count(); i++) {
1715 int blankStart = trackPlaylist.clip_start(i);
1716 int blankDuration = trackPlaylist.clip_length(i) - 1;
1718 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1719 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1722 m_isBlocked = false;
1725 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1729 kDebug() << "Cannot update clip with null producer //////";
1732 Mlt::Service service(m_mltProducer->parent().get_service());
1733 if (service.type() != tractor_type) {
1734 kWarning() << "// TRACTOR PROBLEM";
1737 Mlt::Tractor tractor(service);
1738 Mlt::Producer trackProducer(tractor.track(info.track));
1739 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1740 int startPos = info.startPos.frames(m_fps);
1741 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1742 if (trackPlaylist.is_blank(clipIndex)) {
1743 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1746 mlt_service_lock(service.get_service());
1747 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1749 QList <Mlt::Filter *> filtersList;
1750 Mlt::Service sourceService(clip->get_service());
1752 Mlt::Filter *filter = sourceService.filter(ct);
1754 if (filter->get_int("kdenlive_ix") != 0) {
1755 filtersList.append(filter);
1758 filter = sourceService.filter(ct);
1761 trackPlaylist.replace_with_blank(clipIndex);
1763 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1764 prod = checkSlowMotionProducer(prod, element);
1765 if (prod == NULL || !prod->is_valid()) {
1766 mlt_service_unlock(service.get_service());
1769 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1770 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1774 //if (mltInsertClip(info, element, prod) == -1) return false;
1775 if (!filtersList.isEmpty()) {
1776 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1777 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1778 Mlt::Service destService(destclip->get_service());
1780 for (int i = 0; i < filtersList.count(); i++)
1781 destService.attach(*(filtersList.at(i)));
1783 mlt_service_unlock(service.get_service());
1788 bool Render::mltRemoveClip(int track, GenTime position)
1790 Mlt::Service service(m_mltProducer->parent().get_service());
1791 if (service.type() != tractor_type) {
1792 kWarning() << "// TRACTOR PROBLEM";
1796 Mlt::Tractor tractor(service);
1797 mlt_service_lock(service.get_service());
1798 Mlt::Producer trackProducer(tractor.track(track));
1799 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1800 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1802 // Display playlist info
1803 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1804 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1805 int blankStart = trackPlaylist.clip_start(i);
1806 int blankDuration = trackPlaylist.clip_length(i) - 1;
1808 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1809 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1811 if (trackPlaylist.is_blank(clipIndex)) {
1812 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1813 mlt_service_unlock(service.get_service());
1816 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1818 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1819 if (clip) delete clip;
1820 trackPlaylist.consolidate_blanks(0);
1821 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1822 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1824 /* // Display playlist info
1825 kDebug()<<"//// AFTER";
1826 for (int i = 0; i < trackPlaylist.count(); i++) {
1827 int blankStart = trackPlaylist.clip_start(i);
1828 int blankDuration = trackPlaylist.clip_length(i) - 1;
1830 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1831 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1833 mlt_service_unlock(service.get_service());
1834 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1835 m_isBlocked = false;
1839 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1841 if (!m_mltProducer) {
1842 kDebug() << "PLAYLIST NOT INITIALISED //////";
1845 Mlt::Producer parentProd(m_mltProducer->parent());
1846 if (parentProd.get_producer() == NULL) {
1847 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1851 Mlt::Service service(parentProd.get_service());
1852 Mlt::Tractor tractor(service);
1853 int insertPos = pos.frames(m_fps);
1855 Mlt::Producer trackProducer(tractor.track(track));
1856 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1857 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1858 if (clipIndex == trackPlaylist.count()) {
1859 // We are after the end of the playlist
1862 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1863 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1864 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1867 int Render::mltTrackDuration(int track)
1869 if (!m_mltProducer) {
1870 kDebug() << "PLAYLIST NOT INITIALISED //////";
1873 Mlt::Producer parentProd(m_mltProducer->parent());
1874 if (parentProd.get_producer() == NULL) {
1875 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1879 Mlt::Service service(parentProd.get_service());
1880 Mlt::Tractor tractor(service);
1882 Mlt::Producer trackProducer(tractor.track(track));
1883 return trackProducer.get_playtime() - 1;
1886 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1888 if (!m_mltProducer) {
1889 kDebug() << "PLAYLIST NOT INITIALISED //////";
1892 Mlt::Producer parentProd(m_mltProducer->parent());
1893 if (parentProd.get_producer() == NULL) {
1894 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1897 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1898 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1900 Mlt::Service service(parentProd.get_service());
1901 Mlt::Tractor tractor(service);
1902 mlt_service_lock(service.get_service());
1903 int diff = duration.frames(m_fps);
1904 int offset = timeOffset.frames(m_fps);
1908 // insert space in one track only
1909 Mlt::Producer trackProducer(tractor.track(track));
1910 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1911 insertPos = trackClipStartList.value(track);
1912 if (insertPos != -1) {
1913 insertPos += offset;
1914 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1916 trackPlaylist.insert_blank(clipIndex, diff - 1);
1918 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1919 if (!trackPlaylist.is_blank(clipIndex)) {
1920 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1922 int position = trackPlaylist.clip_start(clipIndex);
1923 int blankDuration = trackPlaylist.clip_length(clipIndex);
1924 if (blankDuration + diff == 0) {
1925 trackPlaylist.remove(clipIndex);
1926 } else trackPlaylist.remove_region(position, -diff);
1928 trackPlaylist.consolidate_blanks(0);
1930 // now move transitions
1931 mlt_service serv = m_mltProducer->parent().get_service();
1932 mlt_service nextservice = mlt_service_get_producer(serv);
1933 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1934 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1935 QString resource = mlt_properties_get(properties, "mlt_service");
1937 while (mlt_type == "transition") {
1938 mlt_transition tr = (mlt_transition) nextservice;
1939 int currentTrack = mlt_transition_get_b_track(tr);
1940 int currentIn = (int) mlt_transition_get_in(tr);
1941 int currentOut = (int) mlt_transition_get_out(tr);
1942 insertPos = trackTransitionStartList.value(track);
1943 if (insertPos != -1) {
1944 insertPos += offset;
1945 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1946 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1949 nextservice = mlt_service_producer(nextservice);
1950 if (nextservice == NULL) break;
1951 properties = MLT_SERVICE_PROPERTIES(nextservice);
1952 mlt_type = mlt_properties_get(properties, "mlt_type");
1953 resource = mlt_properties_get(properties, "mlt_service");
1956 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1957 Mlt::Producer trackProducer(tractor.track(trackNb));
1958 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1960 //int clipNb = trackPlaylist.count();
1961 insertPos = trackClipStartList.value(trackNb);
1962 if (insertPos != -1) {
1963 insertPos += offset;
1965 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1966 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1967 for (int i = 0; i < clipNb; i++) {
1968 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1969 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1970 kDebug()<<"-------------";
1972 kDebug()<<"END-------------";*/
1975 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1977 trackPlaylist.insert_blank(clipIndex, diff - 1);
1979 if (!trackPlaylist.is_blank(clipIndex)) {
1982 if (!trackPlaylist.is_blank(clipIndex)) {
1983 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1985 int position = trackPlaylist.clip_start(clipIndex);
1986 int blankDuration = trackPlaylist.clip_length(clipIndex);
1987 if (diff + blankDuration == 0) {
1988 trackPlaylist.remove(clipIndex);
1989 } else trackPlaylist.remove_region(position, - diff);
1991 trackPlaylist.consolidate_blanks(0);
1994 // now move transitions
1995 mlt_service serv = m_mltProducer->parent().get_service();
1996 mlt_service nextservice = mlt_service_get_producer(serv);
1997 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1998 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1999 QString resource = mlt_properties_get(properties, "mlt_service");
2001 while (mlt_type == "transition") {
2002 mlt_transition tr = (mlt_transition) nextservice;
2003 int currentIn = (int) mlt_transition_get_in(tr);
2004 int currentOut = (int) mlt_transition_get_out(tr);
2005 int currentTrack = mlt_transition_get_b_track(tr);
2006 insertPos = trackTransitionStartList.value(currentTrack);
2007 if (insertPos != -1) {
2008 insertPos += offset;
2009 if (currentOut > insertPos && resource != "mix") {
2010 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2013 nextservice = mlt_service_producer(nextservice);
2014 if (nextservice == NULL) break;
2015 properties = MLT_SERVICE_PROPERTIES(nextservice);
2016 mlt_type = mlt_properties_get(properties, "mlt_type");
2017 resource = mlt_properties_get(properties, "mlt_service");
2020 mlt_service_unlock(service.get_service());
2021 mltCheckLength(&tractor);
2022 m_mltConsumer->set("refresh", 1);
2026 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2028 if (source == dest) return;
2029 Mlt::Service sourceService(source->get_service());
2030 Mlt::Service destService(dest->get_service());
2032 // move all effects to the correct producer
2034 Mlt::Filter *filter = sourceService.filter(ct);
2036 if (filter->get_int("kdenlive_ix") != 0) {
2037 sourceService.detach(*filter);
2038 destService.attach(*filter);
2040 filter = sourceService.filter(ct);
2044 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2048 Mlt::Service service(m_mltProducer->parent().get_service());
2049 if (service.type() != tractor_type) {
2050 kWarning() << "// TRACTOR PROBLEM";
2053 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2054 Mlt::Tractor tractor(service);
2055 Mlt::Producer trackProducer(tractor.track(info.track));
2056 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2057 int startPos = info.startPos.frames(m_fps);
2058 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2059 int clipLength = trackPlaylist.clip_length(clipIndex);
2061 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2062 if (original == NULL) {
2065 if (!original->is_valid() || original->is_blank()) {
2070 Mlt::Producer clipparent = original->parent();
2071 if (!clipparent.is_valid() || clipparent.is_blank()) {
2077 QString serv = clipparent.get("mlt_service");
2078 QString id = clipparent.get("id");
2079 if (speed <= 0 && speed > -1) speed = 1.0;
2080 //kDebug() << "CLIP SERVICE: " << serv;
2081 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2082 mlt_service_lock(service.get_service());
2083 QString url = QString::fromUtf8(clipparent.get("resource"));
2084 url.append('?' + QString::number(speed));
2085 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2086 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2087 if (!slowprod || slowprod->get_producer() == NULL) {
2088 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2089 if (strobe > 1) slowprod->set("strobe", strobe);
2090 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2091 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2092 slowprod->set("id", producerid.toUtf8().constData());
2093 // copy producer props
2094 double ar = original->parent().get_double("force_aspect_ratio");
2095 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2096 double fps = original->parent().get_double("force_fps");
2097 if (fps != 0.0) slowprod->set("force_fps", fps);
2098 int threads = original->parent().get_int("threads");
2099 if (threads != 0) slowprod->set("threads", threads);
2100 if (original->parent().get("force_progressive"))
2101 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2102 if (original->parent().get("force_tff"))
2103 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2104 int ix = original->parent().get_int("video_index");
2105 if (ix != 0) slowprod->set("video_index", ix);
2106 int colorspace = original->parent().get_int("force_colorspace");
2107 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2108 int full_luma = original->parent().get_int("set.force_full_luma");
2109 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2110 m_slowmotionProducers.insert(url, slowprod);
2112 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2113 trackPlaylist.consolidate_blanks(0);
2115 // Check that the blank space is long enough for our new duration
2116 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2117 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2119 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2120 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2121 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2122 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2124 // move all effects to the correct producer
2125 mltPasteEffects(clip, cut);
2126 trackPlaylist.insert_at(startPos, cut, 1);
2129 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2130 newLength = trackPlaylist.clip_length(clipIndex);
2131 mlt_service_unlock(service.get_service());
2132 } else if (speed == 1.0 && strobe < 2) {
2133 mlt_service_lock(service.get_service());
2135 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2136 trackPlaylist.consolidate_blanks(0);
2138 // Check that the blank space is long enough for our new duration
2139 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2140 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2143 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2144 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2145 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2146 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2147 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2149 // move all effects to the correct producer
2150 mltPasteEffects(clip, cut);
2152 trackPlaylist.insert_at(startPos, cut, 1);
2155 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2156 newLength = trackPlaylist.clip_length(clipIndex);
2157 mlt_service_unlock(service.get_service());
2159 } else if (serv == "framebuffer") {
2160 mlt_service_lock(service.get_service());
2161 QString url = QString::fromUtf8(clipparent.get("resource"));
2162 url = url.section('?', 0, 0);
2163 url.append('?' + QString::number(speed));
2164 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2165 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2166 if (!slowprod || slowprod->get_producer() == NULL) {
2167 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2168 slowprod->set("strobe", strobe);
2169 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2170 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2171 slowprod->set("id", producerid.toUtf8().constData());
2172 // copy producer props
2173 double ar = original->parent().get_double("force_aspect_ratio");
2174 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2175 double fps = original->parent().get_double("force_fps");
2176 if (fps != 0.0) slowprod->set("force_fps", fps);
2177 if (original->parent().get("force_progressive"))
2178 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2179 if (original->parent().get("force_tff"))
2180 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2181 int threads = original->parent().get_int("threads");
2182 if (threads != 0) slowprod->set("threads", threads);
2183 int ix = original->parent().get_int("video_index");
2184 if (ix != 0) slowprod->set("video_index", ix);
2185 int colorspace = original->parent().get_int("force_colorspace");
2186 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2187 int full_luma = original->parent().get_int("set.force_full_luma");
2188 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2189 m_slowmotionProducers.insert(url, slowprod);
2191 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2192 trackPlaylist.consolidate_blanks(0);
2194 GenTime duration = speedIndependantInfo.cropDuration / speed;
2195 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2197 // Check that the blank space is long enough for our new duration
2198 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2199 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2202 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2203 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2204 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2205 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2207 // move all effects to the correct producer
2208 mltPasteEffects(clip, cut);
2210 trackPlaylist.insert_at(startPos, cut, 1);
2213 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2214 newLength = trackPlaylist.clip_length(clipIndex);
2216 mlt_service_unlock(service.get_service());
2219 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2220 m_isBlocked = false;
2224 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2226 Mlt::Service service(m_mltProducer->parent().get_service());
2227 bool success = false;
2228 Mlt::Tractor tractor(service);
2229 Mlt::Producer trackProducer(tractor.track(track));
2230 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2231 Mlt::Service clipService(trackPlaylist.get_service());
2234 mlt_service_lock(service.get_service());
2236 Mlt::Filter *filter = clipService.filter(ct);
2238 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2239 if (clipService.detach(*filter) == 0) success = true;
2240 } else if (updateIndex) {
2241 // Adjust the other effects index
2242 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2245 filter = clipService.filter(ct);
2247 m_isBlocked = false;
2248 mlt_service_unlock(service.get_service());
2253 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2255 if (position < GenTime()) {
2256 // Remove track effect
2257 return mltRemoveTrackEffect(track, index, updateIndex);
2259 Mlt::Service service(m_mltProducer->parent().get_service());
2260 bool success = false;
2261 Mlt::Tractor tractor(service);
2262 Mlt::Producer trackProducer(tractor.track(track));
2263 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2265 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2266 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2268 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2272 Mlt::Service clipService(clip->get_service());
2273 int duration = clip->get_playtime();
2275 // Check if clip is visible in monitor
2276 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2277 if (diff < 0 || diff > duration) doRefresh = false;
2281 // if (tag.startsWith("ladspa")) tag = "ladspa";
2283 mlt_service_lock(service.get_service());
2285 Mlt::Filter *filter = clipService.filter(ct);
2287 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2288 if (clipService.detach(*filter) == 0) success = true;
2289 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2290 } else if (updateIndex) {
2291 // Adjust the other effects index
2292 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2295 filter = clipService.filter(ct);
2297 m_isBlocked = false;
2298 mlt_service_unlock(service.get_service());
2299 if (doRefresh) refresh();
2303 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2305 Mlt::Service service(m_mltProducer->parent().get_service());
2306 Mlt::Tractor tractor(service);
2307 Mlt::Producer trackProducer(tractor.track(track));
2308 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2309 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2310 return mltAddEffect(trackService, params, trackProducer.get_playtime() - 1, true);
2314 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2317 Mlt::Service service(m_mltProducer->parent().get_service());
2319 Mlt::Tractor tractor(service);
2320 Mlt::Producer trackProducer(tractor.track(track));
2321 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2323 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2324 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2329 Mlt::Service clipService(clip->get_service());
2330 int duration = clip->get_playtime();
2332 // Check if clip is visible in monitor
2333 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2334 if (diff < 0 || diff > duration) doRefresh = false;
2337 return mltAddEffect(clipService, params, duration, doRefresh);
2340 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2342 bool updateIndex = false;
2343 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2344 const QString region = params.paramValue("region");
2347 mlt_service_lock(service.get_service());
2349 Mlt::Filter *filter = service.filter(ct);
2351 if (filter->get_int("kdenlive_ix") == filter_ix) {
2352 // A filter at that position already existed, so we will increase all indexes later
2357 filter = service.filter(ct);
2360 if (params.paramValue("id") == "speed") {
2361 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2363 filter = service.filter(ct);
2365 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2366 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2369 filter = service.filter(ct);
2371 m_isBlocked = false;
2372 mlt_service_unlock(service.get_service());
2373 if (doRefresh) refresh();
2378 // temporarily remove all effects after insert point
2379 QList <Mlt::Filter *> filtersList;
2381 filter = service.filter(ct);
2383 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2384 filtersList.append(filter);
2385 service.detach(*filter);
2387 filter = service.filter(ct);
2391 QString tag = params.paramValue("tag");
2392 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2393 if (tag.startsWith("ladspa")) tag = "ladspa";
2394 char *filterTag = qstrdup(tag.toUtf8().constData());
2395 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2396 QHash<QString, QString>::Iterator it;
2397 QString kfr = params.paramValue("keyframes");
2399 if (!kfr.isEmpty()) {
2400 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2401 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2402 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2403 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2404 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2405 //double max = params.paramValue("max").toDouble();
2406 double min = params.paramValue("min").toDouble();
2407 double factor = params.paramValue("factor", "1").toDouble();
2408 params.removeParam("starttag");
2409 params.removeParam("endtag");
2410 params.removeParam("keyframes");
2411 params.removeParam("min");
2412 params.removeParam("max");
2413 params.removeParam("factor");
2415 // Special case, only one keyframe, means we want a constant value
2416 if (keyFrames.count() == 1) {
2417 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2418 if (filter && filter->is_valid()) {
2419 filter->set("kdenlive_id", filterId);
2420 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2421 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2422 for (int j = 0; j < params.count(); j++) {
2423 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2425 filter->set("in", x1);
2426 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2427 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2428 service.attach(*filter);
2430 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2431 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2432 if (filter && filter->is_valid()) {
2433 filter->set("kdenlive_id", filterId);
2434 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2435 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2436 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2437 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2438 if (x2 == -1) x2 = duration;
2440 for (int j = 0; j < params.count(); j++) {
2441 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2444 filter->set("in", x1);
2445 filter->set("out", x2);
2446 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2447 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2448 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2449 service.attach(*filter);
2456 Mlt::Filter *filter;
2458 if (!region.isEmpty()) {
2459 filter = new Mlt::Filter(*m_mltProfile, "region");
2460 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2461 if (filter && filter->is_valid()) {
2462 filter->set("kdenlive_id", filterId);
2463 if (!region.isEmpty()) {
2464 filter->set("resource", region.toUtf8().constData());
2465 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2466 filter->set("filter0", filterTag);
2467 prefix = "filter0.";
2468 params.removeParam("id");
2469 params.removeParam("region");
2470 params.removeParam("kdenlive_ix");
2473 kDebug() << "filter is NULL";
2474 m_isBlocked = false;
2475 mlt_service_unlock(service.get_service());
2478 params.removeParam("kdenlive_id");
2480 for (int j = 0; j < params.count(); j++) {
2481 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2485 QString effectArgs = params.paramValue("id").section('_', 1);
2487 params.removeParam("id");
2488 params.removeParam("kdenlive_ix");
2489 params.removeParam("tag");
2490 params.removeParam("disable");
2491 params.removeParam("region");
2493 for (int j = 0; j < params.count(); j++) {
2494 effectArgs.append(' ' + params.at(j).value());
2496 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2497 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2500 if (params.paramValue("id") == "pan_zoom") {
2501 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2504 // attach filter to the clip
2505 service.attach(*filter);
2510 // re-add following filters
2511 for (int i = 0; i < filtersList.count(); i++) {
2512 Mlt::Filter *filter = filtersList.at(i);
2514 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2515 service.attach(*filter);
2517 m_isBlocked = false;
2518 mlt_service_unlock(service.get_service());
2519 if (doRefresh) refresh();
2523 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2525 Mlt::Service service(m_mltProducer->parent().get_service());
2526 Mlt::Tractor tractor(service);
2527 Mlt::Producer trackProducer(tractor.track(track));
2528 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2529 Mlt::Service clipService(trackPlaylist.get_service());
2532 QString index = params.paramValue("kdenlive_ix");
2533 QString tag = params.paramValue("tag");
2535 Mlt::Filter *filter = clipService.filter(ct);
2537 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2541 filter = clipService.filter(ct);
2545 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2546 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2548 bool success = false;//mltAddTrackEffect(track, params);
2549 m_isBlocked = false;
2553 QString ser = filter->get("mlt_service");
2554 if (ser == "region") prefix = "filter0.";
2555 mlt_service_lock(service.get_service());
2556 for (int j = 0; j < params.count(); j++) {
2557 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2559 mlt_service_unlock(service.get_service());
2561 m_isBlocked = false;
2567 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2569 QString index = params.paramValue("kdenlive_ix");
2570 QString tag = params.paramValue("tag");
2572 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2573 // This is a keyframe effect, to edit it, we remove it and re-add it.
2574 bool success = mltRemoveEffect(track, position, index, false);
2575 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2576 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2577 else success = mltAddEffect(track, position, params);
2578 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2581 if (position < GenTime()) {
2582 return mltEditTrackEffect(track, params);
2585 Mlt::Service service(m_mltProducer->parent().get_service());
2586 Mlt::Tractor tractor(service);
2587 Mlt::Producer trackProducer(tractor.track(track));
2588 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2590 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2591 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2593 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2597 Mlt::Service clipService(clip->get_service());
2598 int duration = clip->get_playtime();
2599 bool doRefresh = true;
2600 // Check if clip is visible in monitor
2601 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2602 if (diff < 0 || diff > duration) doRefresh = false;
2606 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2607 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2609 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2611 filter = clipService.filter(ct);
2613 kDebug() << "++++++++++++++++++++++++++";
2615 filter = clipService.filter(ct); */
2617 Mlt::Filter *filter = clipService.filter(ct);
2619 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2623 filter = clipService.filter(ct);
2627 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2628 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2630 bool success = mltAddEffect(track, position, params);
2631 m_isBlocked = false;
2635 QString ser = filter->get("mlt_service");
2636 if (ser == "region") prefix = "filter0.";
2637 mlt_service_lock(service.get_service());
2638 for (int j = 0; j < params.count(); j++) {
2639 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2641 mlt_service_unlock(service.get_service());
2643 m_isBlocked = false;
2644 if (doRefresh) refresh();
2648 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2650 Mlt::Service service(m_mltProducer->parent().get_service());
2651 Mlt::Tractor tractor(service);
2652 Mlt::Producer trackProducer(tractor.track(track));
2653 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2655 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2656 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2658 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2662 Mlt::Service clipService(clip->get_service());
2663 int duration = clip->get_playtime();
2664 bool doRefresh = true;
2665 // Check if clip is visible in monitor
2666 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2667 if (diff < 0 || diff > duration) doRefresh = false;
2672 Mlt::Filter *filter = clipService.filter(ct);
2674 int pos = filter->get_int("kdenlive_ix");
2675 if (pos == oldPos) {
2676 filter->set("kdenlive_ix", newPos);
2678 filter = clipService.filter(ct);
2681 m_isBlocked = false;
2682 if (doRefresh) refresh();
2685 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2687 if (position < GenTime()) {
2688 mltMoveTrackEffect(track, oldPos, newPos);
2691 Mlt::Service service(m_mltProducer->parent().get_service());
2692 Mlt::Tractor tractor(service);
2693 Mlt::Producer trackProducer(tractor.track(track));
2694 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2696 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2697 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2699 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2703 Mlt::Service clipService(clip->get_service());
2704 int duration = clip->get_playtime();
2705 bool doRefresh = true;
2706 // Check if clip is visible in monitor
2707 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2708 if (diff < 0 || diff > duration) doRefresh = false;
2713 QList <Mlt::Filter *> filtersList;
2714 Mlt::Filter *filter = clipService.filter(ct);
2716 if (newPos > oldPos) {
2718 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2719 filter->set("kdenlive_ix", newPos);
2720 filtersList.append(filter);
2721 clipService.detach(*filter);
2722 filter = clipService.filter(ct);
2723 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2724 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2726 filter = clipService.filter(ct);
2730 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2731 filtersList.append(filter);
2732 clipService.detach(*filter);
2734 filter = clipService.filter(ct);
2738 if (filter->get_int("kdenlive_ix") == oldPos) {
2739 filter->set("kdenlive_ix", newPos);
2740 filtersList.append(filter);
2741 clipService.detach(*filter);
2743 filter = clipService.filter(ct);
2747 filter = clipService.filter(ct);
2749 int pos = filter->get_int("kdenlive_ix");
2750 if (pos >= newPos) {
2751 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2752 filtersList.append(filter);
2753 clipService.detach(*filter);
2755 filter = clipService.filter(ct);
2759 for (int i = 0; i < filtersList.count(); i++) {
2760 clipService.attach(*(filtersList.at(i)));
2763 m_isBlocked = false;
2764 if (doRefresh) refresh();
2767 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2769 Mlt::Service service(m_mltProducer->parent().get_service());
2770 Mlt::Tractor tractor(service);
2771 Mlt::Producer trackProducer(tractor.track(track));
2772 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2774 Mlt::Service clipService(trackPlaylist.get_service());
2778 QList <Mlt::Filter *> filtersList;
2779 Mlt::Filter *filter = clipService.filter(ct);
2781 if (newPos > oldPos) {
2783 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2784 filter->set("kdenlive_ix", newPos);
2785 filtersList.append(filter);
2786 clipService.detach(*filter);
2787 filter = clipService.filter(ct);
2788 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2789 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2791 filter = clipService.filter(ct);
2795 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2796 filtersList.append(filter);
2797 clipService.detach(*filter);
2799 filter = clipService.filter(ct);
2803 if (filter->get_int("kdenlive_ix") == oldPos) {
2804 filter->set("kdenlive_ix", newPos);
2805 filtersList.append(filter);
2806 clipService.detach(*filter);
2808 filter = clipService.filter(ct);
2812 filter = clipService.filter(ct);
2814 int pos = filter->get_int("kdenlive_ix");
2815 if (pos >= newPos) {
2816 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2817 filtersList.append(filter);
2818 clipService.detach(*filter);
2820 filter = clipService.filter(ct);
2824 for (int i = 0; i < filtersList.count(); i++) {
2825 clipService.attach(*(filtersList.at(i)));
2827 m_isBlocked = false;
2831 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2834 Mlt::Service service(m_mltProducer->parent().get_service());
2835 Mlt::Tractor tractor(service);
2836 Mlt::Producer trackProducer(tractor.track(info.track));
2837 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2839 /* // Display playlist info
2840 kDebug()<<"//////////// BEFORE RESIZE";
2841 for (int i = 0; i < trackPlaylist.count(); i++) {
2842 int blankStart = trackPlaylist.clip_start(i);
2843 int blankDuration = trackPlaylist.clip_length(i) - 1;
2845 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2846 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2849 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2850 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2851 m_isBlocked = false;
2854 mlt_service_lock(service.get_service());
2855 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2856 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2857 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2859 int previousStart = clip->get_in();
2860 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2861 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2863 int currentOut = newDuration + previousStart;
2864 if (currentOut > clip->get_length()) {
2865 clip->parent().set("length", currentOut + 1);
2866 clip->parent().set("out", currentOut);
2867 clip->set("length", currentOut + 1);
2870 /*if (newDuration > clip->get_out()) {
2871 clip->parent().set_in_and_out(0, newDuration + 1);
2872 clip->set_in_and_out(0, newDuration + 1);
2875 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2876 trackPlaylist.consolidate_blanks(0);
2877 // skip to next clip
2879 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2881 // clip was made longer, trim next blank if there is one.
2882 if (clipIndex < trackPlaylist.count()) {
2883 // If this is not the last clip in playlist
2884 if (trackPlaylist.is_blank(clipIndex)) {
2885 int blankStart = trackPlaylist.clip_start(clipIndex);
2886 int blankDuration = trackPlaylist.clip_length(clipIndex);
2887 if (diff > blankDuration) {
2888 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2890 if (diff - blankDuration == 0) {
2891 trackPlaylist.remove(clipIndex);
2892 } else trackPlaylist.remove_region(blankStart, diff);
2894 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2897 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2898 trackPlaylist.consolidate_blanks(0);
2899 mlt_service_unlock(service.get_service());
2901 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2902 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2903 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2904 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2905 ItemInfo transpinfo;
2906 transpinfo.startPos = info.startPos;
2907 transpinfo.endPos = info.startPos + clipDuration;
2908 transpinfo.track = info.track;
2909 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2911 m_isBlocked = false;
2912 m_mltConsumer->set("refresh", 1);
2916 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2918 Mlt::Service service(m_mltProducer->parent().get_service());
2919 Mlt::Tractor tractor(service);
2920 Mlt::Producer trackProducer(tractor.track(track));
2923 if (blind) trackProducer.set("hide", 3);
2924 else trackProducer.set("hide", 2);
2926 trackProducer.set("hide", 1);
2928 trackProducer.set("hide", 0);
2930 tractor.multitrack()->refresh();
2936 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2938 Mlt::Service service(m_mltProducer->parent().get_service());
2939 int frameOffset = (int) diff.frames(m_fps);
2940 Mlt::Tractor tractor(service);
2941 Mlt::Producer trackProducer(tractor.track(info.track));
2942 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2943 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2944 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2947 mlt_service_lock(service.get_service());
2948 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2949 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2951 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2952 mlt_service_unlock(service.get_service());
2955 int previousStart = clip->get_in();
2956 int previousOut = clip->get_out();
2959 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2960 m_isBlocked = false;
2961 mlt_service_unlock(service.get_service());
2962 m_mltConsumer->set("refresh", 1);
2966 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2968 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2969 Mlt::Service service(m_mltProducer->parent().get_service());
2970 int moveFrame = (int) diff.frames(m_fps);
2971 Mlt::Tractor tractor(service);
2972 Mlt::Producer trackProducer(tractor.track(info.track));
2973 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2974 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2975 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2978 mlt_service_lock(service.get_service());
2979 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2980 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2981 if (clip == NULL || clip->is_blank()) {
2982 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2983 mlt_service_unlock(service.get_service());
2986 int previousStart = clip->get_in();
2987 int previousOut = clip->get_out();
2990 previousStart += moveFrame;
2992 int length = previousOut + 1;
2993 if (length > clip->get_length()) {
2994 clip->parent().set("length", length + 1);
2995 clip->parent().set("out", length);
2996 clip->set("length", length + 1);
3000 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3001 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3002 if (moveFrame > 0) {
3003 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3005 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3006 int blankIndex = clipIndex - 1;
3007 int blankLength = trackPlaylist.clip_length(blankIndex);
3008 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3009 if (! trackPlaylist.is_blank(blankIndex)) {
3010 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3012 if (blankLength + moveFrame == 0)
3013 trackPlaylist.remove(blankIndex);
3015 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3017 trackPlaylist.consolidate_blanks(0);
3018 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3019 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3020 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3021 ItemInfo transpinfo;
3022 transpinfo.startPos = info.startPos + diff;
3023 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3024 transpinfo.track = info.track;
3025 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3027 m_isBlocked = false;
3028 //m_mltConsumer->set("refresh", 1);
3029 mlt_service_unlock(service.get_service());
3030 m_mltConsumer->set("refresh", 1);
3034 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3036 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3040 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3042 if (prod == NULL || !prod->is_valid()) {
3043 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3046 kDebug() << "NEW PROD ID: " << prod->get("id");
3048 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3049 Mlt::Service service(m_mltProducer->parent().get_service());
3050 if (service.type() != tractor_type) {
3051 kWarning() << "// TRACTOR PROBLEM";
3054 mlt_service_lock(service.get_service());
3055 Mlt::Tractor tractor(service);
3056 Mlt::Producer trackProducer(tractor.track(track));
3057 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3058 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3059 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3060 if (clipProducer == NULL || clipProducer->is_blank()) {
3061 kDebug() << "// ERROR UPDATING CLIP PROD";
3062 delete clipProducer;
3063 mlt_service_unlock(service.get_service());
3067 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3068 if (!clip || !clip->is_valid()) {
3069 if (clip) delete clip;
3070 delete clipProducer;
3071 mlt_service_unlock(service.get_service());
3075 // move all effects to the correct producer
3076 mltPasteEffects(clipProducer, clip);
3077 trackPlaylist.insert_at(pos, clip, 1);
3079 delete clipProducer;
3080 mlt_service_unlock(service.get_service());
3085 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3089 Mlt::Service service(m_mltProducer->parent().get_service());
3090 if (service.type() != tractor_type) {
3091 kWarning() << "// TRACTOR PROBLEM";
3095 Mlt::Tractor tractor(service);
3096 mlt_service_lock(service.get_service());
3097 Mlt::Producer trackProducer(tractor.track(startTrack));
3098 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3099 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3100 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3101 bool checkLength = false;
3102 if (endTrack == startTrack) {
3103 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3104 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3105 // error, destination is not empty
3107 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3108 delete clipProducer;
3110 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3111 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3112 mlt_service_unlock(service.get_service());
3116 trackPlaylist.consolidate_blanks(0);
3118 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3119 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3120 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3122 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3123 trackPlaylist.consolidate_blanks(1);
3124 delete clipProducer;
3125 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3126 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3128 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3130 //mlt_service_unlock(service.get_service());
3132 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3133 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3134 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3135 // error, destination is not empty
3136 mlt_service_unlock(service.get_service());
3140 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3141 if (!clipProducer || clipProducer->is_blank()) {
3142 // error, destination is not empty
3143 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3144 if (clipProducer) delete clipProducer;
3145 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3146 mlt_service_unlock(service.get_service());
3150 trackPlaylist.consolidate_blanks(0);
3151 destTrackPlaylist.consolidate_blanks(1);
3152 Mlt::Producer *clip;
3153 // check if we are moving a slowmotion producer
3154 QString serv = clipProducer->parent().get("mlt_service");
3155 QString currentid = clipProducer->parent().get("id");
3156 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3157 clip = clipProducer;
3160 // Special case: prod is null when using placeholder clips.
3161 // in that case, use the producer existing in playlist. Note that
3162 // it will bypass the one producer per track logic and might cause
3163 // Sound cracks if clip is moved so that it overlaps another copy of itself
3164 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3165 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3168 // move all effects to the correct producer
3169 mltPasteEffects(clipProducer, clip);
3172 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3173 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3174 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3177 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3179 if (clip == clipProducer) {
3184 delete clipProducer;
3186 destTrackPlaylist.consolidate_blanks(0);
3187 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3188 kDebug() << "//////// moving clip transparency";
3189 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3191 if (clipIndex > trackPlaylist.count()) checkLength = true;
3192 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3195 mlt_service_unlock(service.get_service());
3196 if (checkLength) mltCheckLength(&tractor);
3199 //m_mltConsumer->set("refresh", 1);
3204 QList <int> Render::checkTrackSequence(int track)
3207 Mlt::Service service(m_mltProducer->parent().get_service());
3208 if (service.type() != tractor_type) {
3209 kWarning() << "// TRACTOR PROBLEM";
3212 Mlt::Tractor tractor(service);
3213 mlt_service_lock(service.get_service());
3214 Mlt::Producer trackProducer(tractor.track(track));
3215 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3216 int clipNb = trackPlaylist.count();
3217 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3218 for (int i = 0; i < clipNb; i++) {
3219 Mlt::Producer *c = trackPlaylist.get_clip(i);
3220 int pos = trackPlaylist.clip_start(i);
3221 if (!list.contains(pos)) list.append(pos);
3222 pos += c->get_playtime();
3223 if (!list.contains(pos)) list.append(pos);
3229 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3231 int new_in = (int)newIn.frames(m_fps);
3232 int new_out = (int)newOut.frames(m_fps) - 1;
3233 if (new_in >= new_out) return false;
3234 int old_in = (int)oldIn.frames(m_fps);
3235 int old_out = (int)oldOut.frames(m_fps) - 1;
3237 Mlt::Service service(m_mltProducer->parent().get_service());
3238 Mlt::Tractor tractor(service);
3239 Mlt::Field *field = tractor.field();
3241 bool doRefresh = true;
3242 // Check if clip is visible in monitor
3243 int diff = old_out - m_mltProducer->position();
3244 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3246 diff = new_out - m_mltProducer->position();
3247 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3251 mlt_service_lock(service.get_service());
3253 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3254 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3255 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3256 QString resource = mlt_properties_get(properties, "mlt_service");
3257 int old_pos = (int)(old_in + old_out) / 2;
3260 while (mlt_type == "transition") {
3261 Mlt::Transition transition((mlt_transition) nextservice);
3262 int currentTrack = transition.get_b_track();
3263 int currentIn = (int) transition.get_in();
3264 int currentOut = (int) transition.get_out();
3266 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3268 if (newTrack - startTrack != 0) {
3269 Mlt::Properties trans_props(transition.get_properties());
3270 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3271 Mlt::Properties new_trans_props(new_transition.get_properties());
3272 new_trans_props.inherit(trans_props);
3273 new_transition.set_in_and_out(new_in, new_out);
3274 field->disconnect_service(transition);
3275 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3276 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3277 } else transition.set_in_and_out(new_in, new_out);
3280 nextservice = mlt_service_producer(nextservice);
3281 if (nextservice == NULL) break;
3282 properties = MLT_SERVICE_PROPERTIES(nextservice);
3283 mlt_type = mlt_properties_get(properties, "mlt_type");
3284 resource = mlt_properties_get(properties, "mlt_service");
3286 mlt_service_unlock(service.get_service());
3288 if (doRefresh) refresh();
3289 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3294 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3296 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3297 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3298 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3299 QString resource = mlt_properties_get(properties, "mlt_service");
3300 QList <Mlt::Transition *> trList;
3302 while (mlt_type == "transition") {
3303 Mlt::Transition transition((mlt_transition) nextservice);
3304 int aTrack = transition.get_a_track();
3305 int bTrack = transition.get_b_track();
3306 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3307 Mlt::Properties trans_props(transition.get_properties());
3308 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3309 Mlt::Properties new_trans_props(cp->get_properties());
3310 new_trans_props.inherit(trans_props);
3312 field->disconnect_service(transition);
3314 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3316 nextservice = mlt_service_producer(nextservice);
3317 if (nextservice == NULL) break;
3318 properties = MLT_SERVICE_PROPERTIES(nextservice);
3319 mlt_type = mlt_properties_get(properties, "mlt_type");
3320 resource = mlt_properties_get(properties, "mlt_service");
3323 field->plant_transition(tr, a_track, b_track);
3325 // re-add upper transitions
3326 for (int i = 0; i < trList.count(); i++) {
3327 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3328 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3332 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3334 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3336 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3337 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3340 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3343 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3345 mlt_service serv = m_mltProducer->parent().get_service();
3346 mlt_service_lock(serv);
3349 mlt_service nextservice = mlt_service_get_producer(serv);
3350 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3351 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3352 QString resource = mlt_properties_get(properties, "mlt_service");
3353 int in_pos = (int) in.frames(m_fps);
3354 int out_pos = (int) out.frames(m_fps) - 1;
3356 while (mlt_type == "transition") {
3357 mlt_transition tr = (mlt_transition) nextservice;
3358 int currentTrack = mlt_transition_get_b_track(tr);
3359 int currentBTrack = mlt_transition_get_a_track(tr);
3360 int currentIn = (int) mlt_transition_get_in(tr);
3361 int currentOut = (int) mlt_transition_get_out(tr);
3363 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3365 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3366 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3367 QMap<QString, QString>::Iterator it;
3369 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3371 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3372 if (currentId != xml.attribute("id")) {
3373 // The transition ID is not the same, so reset all properties
3374 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3375 // Cleanup previous properties
3376 QStringList permanentProps;
3377 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3378 permanentProps << "out" << "a_track" << "b_track";
3379 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3380 QString propName = mlt_properties_get_name(transproperties, i);
3381 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3382 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3387 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3388 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3390 if (currentBTrack != a_track) {
3391 mlt_properties_set_int(transproperties, "a_track", a_track);
3393 for (it = map.begin(); it != map.end(); ++it) {
3395 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3396 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3397 //filter->set("kdenlive_id", id);
3401 nextservice = mlt_service_producer(nextservice);
3402 if (nextservice == NULL) break;
3403 properties = MLT_SERVICE_PROPERTIES(nextservice);
3404 mlt_type = mlt_properties_get(properties, "mlt_type");
3405 resource = mlt_properties_get(properties, "mlt_service");
3407 mlt_service_unlock(serv);
3410 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3413 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3415 mlt_service serv = m_mltProducer->parent().get_service();
3417 mlt_service_lock(serv);
3419 Mlt::Service service(serv);
3420 Mlt::Tractor tractor(service);
3421 Mlt::Field *field = tractor.field();
3423 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3425 mlt_service nextservice = mlt_service_get_producer(serv);
3426 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3427 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3428 QString resource = mlt_properties_get(properties, "mlt_service");
3430 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3431 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3433 while (mlt_type == "transition") {
3434 mlt_transition tr = (mlt_transition) nextservice;
3435 int currentTrack = mlt_transition_get_b_track(tr);
3436 int currentIn = (int) mlt_transition_get_in(tr);
3437 int currentOut = (int) mlt_transition_get_out(tr);
3438 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3440 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3441 mlt_field_disconnect_service(field->get_field(), nextservice);
3444 nextservice = mlt_service_producer(nextservice);
3445 if (nextservice == NULL) break;
3446 properties = MLT_SERVICE_PROPERTIES(nextservice);
3447 mlt_type = mlt_properties_get(properties, "mlt_type");
3448 resource = mlt_properties_get(properties, "mlt_service");
3450 mlt_service_unlock(serv);
3453 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3456 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3458 QDomNodeList attribs = xml.elementsByTagName("parameter");
3459 QMap<QString, QString> map;
3460 for (int i = 0; i < attribs.count(); i++) {
3461 QDomElement e = attribs.item(i).toElement();
3462 QString name = e.attribute("name");
3463 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3464 map[name] = e.attribute("default");
3465 if (!e.attribute("value").isEmpty()) {
3466 map[name] = e.attribute("value");
3468 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3469 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3470 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3473 if (e.attribute("namedesc").contains(';')) {
3474 QString format = e.attribute("format");
3475 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3476 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3478 QTextStream txtNeu(&neu);
3479 if (values.size() > 0)
3480 txtNeu << (int)values[0].toDouble();
3482 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3483 txtNeu << separators[i];
3484 txtNeu << (int)(values[i+1].toDouble());
3486 if (i < separators.size())
3487 txtNeu << separators[i];
3488 map[e.attribute("name")] = neu;
3495 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3497 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3498 Mlt::Service service(m_mltProducer->parent().get_service());
3499 Mlt::Tractor tractor(service);
3500 Mlt::Field *field = tractor.field();
3502 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3503 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3504 transition->set("transparency", id);
3505 transition->set("fill", 1);
3506 transition->set("internal_added", 237);
3507 field->plant_transition(*transition, transitiontrack, info.track);
3511 void Render::mltDeleteTransparency(int pos, int track, int id)
3513 Mlt::Service service(m_mltProducer->parent().get_service());
3514 Mlt::Tractor tractor(service);
3515 Mlt::Field *field = tractor.field();
3517 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3518 mlt_service serv = m_mltProducer->parent().get_service();
3520 mlt_service nextservice = mlt_service_get_producer(serv);
3521 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3522 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3523 QString resource = mlt_properties_get(properties, "mlt_service");
3525 while (mlt_type == "transition") {
3526 mlt_transition tr = (mlt_transition) nextservice;
3527 int currentTrack = mlt_transition_get_b_track(tr);
3528 int currentIn = (int) mlt_transition_get_in(tr);
3529 int currentOut = (int) mlt_transition_get_out(tr);
3530 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3531 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3533 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3534 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3535 mlt_field_disconnect_service(field->get_field(), nextservice);
3538 nextservice = mlt_service_producer(nextservice);
3539 if (nextservice == NULL) break;
3540 properties = MLT_SERVICE_PROPERTIES(nextservice);
3541 mlt_type = mlt_properties_get(properties, "mlt_type");
3542 resource = mlt_properties_get(properties, "mlt_service");
3544 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3547 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3549 Mlt::Service service(m_mltProducer->parent().get_service());
3550 Mlt::Tractor tractor(service);
3552 mlt_service_lock(service.get_service());
3553 m_mltConsumer->set("refresh", 0);
3556 mlt_service serv = m_mltProducer->parent().get_service();
3557 mlt_service nextservice = mlt_service_get_producer(serv);
3558 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3559 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3560 QString resource = mlt_properties_get(properties, "mlt_service");
3561 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3562 while (mlt_type == "transition") {
3563 mlt_transition tr = (mlt_transition) nextservice;
3564 int currentTrack = mlt_transition_get_b_track(tr);
3565 int currentIn = (int) mlt_transition_get_in(tr);
3566 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3567 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3568 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3569 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3570 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3571 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3574 nextservice = mlt_service_producer(nextservice);
3575 if (nextservice == NULL) break;
3576 properties = MLT_SERVICE_PROPERTIES(nextservice);
3577 mlt_type = mlt_properties_get(properties, "mlt_type");
3578 resource = mlt_properties_get(properties, "mlt_service");
3580 mlt_service_unlock(service.get_service());
3582 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3586 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3588 Mlt::Service service(m_mltProducer->parent().get_service());
3589 Mlt::Tractor tractor(service);
3591 mlt_service_lock(service.get_service());
3592 m_mltConsumer->set("refresh", 0);
3595 mlt_service serv = m_mltProducer->parent().get_service();
3596 mlt_service nextservice = mlt_service_get_producer(serv);
3597 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3598 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3599 QString resource = mlt_properties_get(properties, "mlt_service");
3601 while (mlt_type == "transition") {
3602 mlt_transition tr = (mlt_transition) nextservice;
3603 int currentTrack = mlt_transition_get_b_track(tr);
3604 int currentaTrack = mlt_transition_get_a_track(tr);
3605 int currentIn = (int) mlt_transition_get_in(tr);
3606 int currentOut = (int) mlt_transition_get_out(tr);
3607 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3608 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3609 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3610 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3611 kDebug() << "//////MOVING";
3612 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3613 if (endTrack != startTrack) {
3614 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3615 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3616 mlt_properties_set_int(properties, "b_track", endTrack);
3620 nextservice = mlt_service_producer(nextservice);
3621 if (nextservice == NULL) break;
3622 properties = MLT_SERVICE_PROPERTIES(nextservice);
3623 mlt_type = mlt_properties_get(properties, "mlt_type");
3624 resource = mlt_properties_get(properties, "mlt_service");
3627 mlt_service_unlock(service.get_service());
3628 m_mltConsumer->set("refresh", 1);
3632 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3634 if (in >= out) return false;
3635 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3636 Mlt::Service service(m_mltProducer->parent().get_service());
3638 Mlt::Tractor tractor(service);
3639 Mlt::Field *field = tractor.field();
3641 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3642 if (out != GenTime())
3643 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3645 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3646 QMap<QString, QString>::Iterator it;
3648 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3649 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3650 if (xml.hasAttribute("id"))
3651 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3653 for (it = args.begin(); it != args.end(); ++it) {
3655 if (!it.value().isEmpty())
3656 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3657 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3659 // attach transition
3660 mltPlantTransition(field, *transition, a_track, b_track);
3661 // field->plant_transition(*transition, a_track, b_track);
3662 if (do_refresh) refresh();
3666 void Render::mltSavePlaylist()
3668 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3669 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3670 fileConsumer.set("resource", "/tmp/playlist.mlt");
3672 Mlt::Service service(m_mltProducer->get_service());
3674 fileConsumer.connect(service);
3675 fileConsumer.start();
3678 const QList <Mlt::Producer *> Render::producersList()
3680 QList <Mlt::Producer *> prods;
3681 if (m_mltProducer == NULL) return prods;
3682 Mlt::Service service(m_mltProducer->parent().get_service());
3683 if (service.type() != tractor_type) return prods;
3684 Mlt::Tractor tractor(service);
3687 int trackNb = tractor.count();
3688 for (int t = 1; t < trackNb; t++) {
3689 Mlt::Producer *tt = tractor.track(t);
3690 Mlt::Producer trackProducer(tt);
3692 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3693 int clipNb = trackPlaylist.count();
3694 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3695 for (int i = 0; i < clipNb; i++) {
3696 Mlt::Producer *c = trackPlaylist.get_clip(i);
3697 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3699 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3700 ids.append(nprod->get("id"));
3701 prods.append(nprod);
3702 } else delete nprod;
3710 void Render::fillSlowMotionProducers()
3712 if (m_mltProducer == NULL) return;
3713 Mlt::Service service(m_mltProducer->parent().get_service());
3714 if (service.type() != tractor_type) return;
3716 Mlt::Tractor tractor(service);
3718 int trackNb = tractor.count();
3719 for (int t = 1; t < trackNb; t++) {
3720 Mlt::Producer *tt = tractor.track(t);
3721 Mlt::Producer trackProducer(tt);
3723 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3724 int clipNb = trackPlaylist.count();
3725 for (int i = 0; i < clipNb; i++) {
3726 Mlt::Producer *c = trackPlaylist.get_clip(i);
3727 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3729 QString id = nprod->get("id");
3730 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3731 // this is a slowmotion producer, add it to the list
3732 QString url = QString::fromUtf8(nprod->get("resource"));
3733 int strobe = nprod->get_int("strobe");
3734 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3735 if (!m_slowmotionProducers.contains(url)) {
3736 m_slowmotionProducers.insert(url, nprod);
3738 } else delete nprod;
3745 void Render::mltInsertTrack(int ix, bool videoTrack)
3750 Mlt::Service service(m_mltProducer->parent().get_service());
3751 mlt_service_lock(service.get_service());
3752 if (service.type() != tractor_type) {
3753 kWarning() << "// TRACTOR PROBLEM";
3757 Mlt::Tractor tractor(service);
3759 Mlt::Playlist playlist;
3760 int ct = tractor.count();
3762 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3768 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3769 tractor.set_track(playlist, pos);
3770 Mlt::Producer newProd(tractor.track(pos));
3771 if (!videoTrack) newProd.set("hide", 1);
3773 for (; pos <= ct; pos++) {
3774 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3775 tractor.set_track(*prodToMove, pos);
3776 prodToMove = prodToMove2;
3779 tractor.set_track(playlist, ix);
3780 Mlt::Producer newProd(tractor.track(ix));
3781 if (!videoTrack) newProd.set("hide", 1);
3785 mlt_service serv = m_mltProducer->parent().get_service();
3786 mlt_service nextservice = mlt_service_get_producer(serv);
3787 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3788 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3789 QString resource = mlt_properties_get(properties, "mlt_service");
3791 while (mlt_type == "transition") {
3792 if (resource != "mix") {
3793 mlt_transition tr = (mlt_transition) nextservice;
3794 int currentTrack = mlt_transition_get_b_track(tr);
3795 int currentaTrack = mlt_transition_get_a_track(tr);
3796 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3798 if (currentTrack >= ix) {
3799 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3800 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3803 nextservice = mlt_service_producer(nextservice);
3804 if (nextservice == NULL) break;
3805 properties = MLT_SERVICE_PROPERTIES(nextservice);
3806 mlt_type = mlt_properties_get(properties, "mlt_type");
3807 resource = mlt_properties_get(properties, "mlt_service");
3810 // Add audio mix transition to last track
3811 Mlt::Field *field = tractor.field();
3812 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3813 transition->set("a_track", 1);
3814 transition->set("b_track", ct);
3815 transition->set("always_active", 1);
3816 transition->set("internal_added", 237);
3817 transition->set("combine", 1);
3818 field->plant_transition(*transition, 1, ct);
3819 //mlt_service_unlock(m_mltConsumer->get_service());
3820 mlt_service_unlock(service.get_service());
3821 //tractor.multitrack()->refresh();
3822 //tractor.refresh();
3824 blockSignals(false);
3828 void Render::mltDeleteTrack(int ix)
3831 doc.setContent(sceneList(), false);
3832 int tracksCount = doc.elementsByTagName("track").count() - 1;
3833 QDomNode track = doc.elementsByTagName("track").at(ix);
3834 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3835 QDomNodeList transitions = doc.elementsByTagName("transition");
3836 for (int i = 0; i < transitions.count(); i++) {
3837 QDomElement e = transitions.at(i).toElement();
3838 QDomNodeList props = e.elementsByTagName("property");
3839 QMap <QString, QString> mappedProps;
3840 for (int j = 0; j < props.count(); j++) {
3841 QDomElement f = props.at(j).toElement();
3842 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3844 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3845 tractor.removeChild(transitions.at(i));
3847 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3848 // Transition needs to be moved
3849 int a_track = mappedProps.value("a_track").toInt();
3850 int b_track = mappedProps.value("b_track").toInt();
3851 if (a_track > 0 && a_track >= ix) a_track --;
3852 if (b_track == ix) {
3853 // transition was on the deleted track, so remove it
3854 tractor.removeChild(transitions.at(i));
3858 if (b_track > 0 && b_track > ix) b_track --;
3859 for (int j = 0; j < props.count(); j++) {
3860 QDomElement f = props.at(j).toElement();
3861 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3862 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3867 tractor.removeChild(track);
3868 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3869 setSceneList(doc.toString(), m_framePosition);
3871 /* if (m_mltProducer != NULL) {
3872 Mlt::Producer parentProd(m_mltProducer->parent());
3873 if (parentProd.get_producer() != NULL) {
3874 Mlt::Service service(parentProd.get_service());
3875 if (service.type() == tractor_type) {
3876 Mlt::Tractor tractor(service);
3877 mltCheckLength(&tractor);
3884 void Render::updatePreviewSettings()
3886 kDebug() << "////// RESTARTING CONSUMER";
3887 if (!m_mltConsumer || !m_mltProducer) return;
3888 if (m_mltProducer->get_playtime() == 0) return;
3889 Mlt::Service service(m_mltProducer->parent().get_service());
3890 if (service.type() != tractor_type) return;
3892 //m_mltConsumer->set("refresh", 0);
3893 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3894 m_mltConsumer->purge();
3895 QString scene = sceneList();
3897 if (m_mltProducer) {
3898 pos = m_mltProducer->position();
3901 setSceneList(scene, pos);
3905 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3907 // Update all frame positions to the new fps value
3908 //WARNING: there are probably some effects or other that hold a frame value
3909 // as parameter and will also need to be updated here!
3911 doc.setContent(scene);
3913 double factor = new_fps / current_fps;
3914 QDomNodeList producers = doc.elementsByTagName("producer");
3915 for (int i = 0; i < producers.count(); i++) {
3916 QDomElement prod = producers.at(i).toElement();
3917 prod.removeAttribute("in");
3918 prod.removeAttribute("out");
3920 QDomNodeList props = prod.childNodes();
3921 for (int j = 0; j < props.count(); j++) {
3922 QDomElement param = props.at(j).toElement();
3923 QString paramName = param.attribute("name");
3924 if (paramName.startsWith("meta.") || paramName == "length") {
3925 prod.removeChild(props.at(j));
3931 QDomNodeList entries = doc.elementsByTagName("entry");
3932 for (int i = 0; i < entries.count(); i++) {
3933 QDomElement entry = entries.at(i).toElement();
3934 int in = entry.attribute("in").toInt();
3935 int out = entry.attribute("out").toInt();
3936 in = factor * in + 0.5;
3937 out = factor * out + 0.5;
3938 entry.setAttribute("in", in);
3939 entry.setAttribute("out", out);
3942 QDomNodeList blanks = doc.elementsByTagName("blank");
3943 for (int i = 0; i < blanks.count(); i++) {
3944 QDomElement blank = blanks.at(i).toElement();
3945 int length = blank.attribute("length").toInt();
3946 length = factor * length + 0.5;
3947 blank.setAttribute("length", QString::number(length));
3950 QDomNodeList filters = doc.elementsByTagName("filter");
3951 for (int i = 0; i < filters.count(); i++) {
3952 QDomElement filter = filters.at(i).toElement();
3953 int in = filter.attribute("in").toInt();
3954 int out = filter.attribute("out").toInt();
3955 in = factor * in + 0.5;
3956 out = factor * out + 0.5;
3957 filter.setAttribute("in", in);
3958 filter.setAttribute("out", out);
3961 QDomNodeList transitions = doc.elementsByTagName("transition");
3962 for (int i = 0; i < transitions.count(); i++) {
3963 QDomElement transition = transitions.at(i).toElement();
3964 int in = transition.attribute("in").toInt();
3965 int out = transition.attribute("out").toInt();
3966 in = factor * in + 0.5;
3967 out = factor * out + 0.5;
3968 transition.setAttribute("in", in);
3969 transition.setAttribute("out", out);
3970 QDomNodeList props = transition.childNodes();
3971 for (int j = 0; j < props.count(); j++) {
3972 QDomElement param = props.at(j).toElement();
3973 QString paramName = param.attribute("name");
3974 if (paramName == "geometry") {
3975 QString geom = param.firstChild().nodeValue();
3976 QStringList keys = geom.split(';');
3977 QStringList newKeys;
3978 for (int k = 0; k < keys.size(); ++k) {
3979 if (keys.at(k).contains('=')) {
3980 int pos = keys.at(k).section('=', 0, 0).toInt();
3981 pos = factor * pos + 0.5;
3982 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3983 } else newKeys.append(keys.at(k));
3985 param.firstChild().setNodeValue(newKeys.join(";"));
3989 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3990 int out = tractor.attribute("out").toInt();
3991 out = factor * out + 0.5;
3992 tractor.setAttribute("out", out);
3993 emit durationChanged(out);
3995 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3996 return doc.toString();
4000 void Render::sendFrameUpdate()
4002 if (m_mltProducer) {
4003 Mlt::Frame * frame = m_mltProducer->get_frame();
4004 emitFrameUpdated(*frame);
4010 #include "renderer.moc"