1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
30 #include "slideshowclip.h"
31 #include "profilesdialog.h"
32 #include "blackmagic/devices.h"
34 #include <mlt++/Mlt.h>
37 #include <KStandardDirs>
38 #include <KMessageBox>
40 #include <KTemporaryFile>
45 #include <QApplication>
51 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
53 if (level > MLT_LOG_ERROR) return;
55 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
60 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
62 // detect if the producer has finished playing. Is there a better way to do it?
63 if (self->m_isBlocked) return;
64 Mlt::Frame frame(frame_ptr);
65 if (!frame.is_valid()) return;
66 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
67 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
68 self->emitFrameUpdated(frame);
70 if (self->analyseAudio) self->showAudio(frame);
71 if (frame.get_double("_speed") == 0.0) {
72 self->emitConsumerStopped();
73 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
75 self->emitConsumerStopped();
79 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
81 // detect if the producer has finished playing. Is there a better way to do it?
82 if (self->m_isBlocked) return;
83 Mlt::Frame frame(frame_ptr);
84 self->showFrame(frame);
85 if (frame.get_double("_speed") == 0.0) {
86 self->emitConsumerStopped();
87 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
89 self->emitConsumerStopped();
93 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
96 sendFrameForAnalysis(false),
97 analyseAudio(KdenliveSettings::monitor_audio()),
105 m_isSplitView(false),
109 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
110 buildConsumer(profile);
112 m_mltProducer = m_blackClip->cut(0, 50);
113 m_mltConsumer->connect(*m_mltProducer);
114 m_mltProducer->set_speed(0.0);
124 void Render::closeMlt()
128 Mlt::Service service(m_mltProducer->parent().get_service());
129 mlt_service_lock(service.get_service());
131 if (service.type() == tractor_type) {
132 Mlt::Tractor tractor(service);
133 Mlt::Field *field = tractor.field();
134 mlt_service nextservice = mlt_service_get_producer(service.get_service());
135 mlt_service nextservicetodisconnect;
136 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
137 QString mlt_type = mlt_properties_get(properties, "mlt_type");
138 QString resource = mlt_properties_get(properties, "mlt_service");
139 // Delete all transitions
140 while (mlt_type == "transition") {
141 nextservicetodisconnect = nextservice;
142 nextservice = mlt_service_producer(nextservice);
143 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
144 nextservice = mlt_service_producer(nextservice);
145 if (nextservice == NULL) break;
146 properties = MLT_SERVICE_PROPERTIES(nextservice);
147 mlt_type = mlt_properties_get(properties, "mlt_type");
148 resource = mlt_properties_get(properties, "mlt_service");
151 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
152 Mlt::Producer trackProducer(tractor.track(trackNb));
153 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
154 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
157 mlt_service_unlock(service.get_service());
160 kDebug() << "// // // CLOSE RENDERER " << m_name;
161 delete m_mltConsumer;
162 delete m_mltProducer;
167 void Render::slotSwitchFullscreen()
169 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
172 void Render::buildConsumer(const QString profileName)
174 m_activeProfile = profileName;
175 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
176 setenv("MLT_PROFILE", tmp, 1);
180 //TODO: uncomment following line when everything is clean
181 //if (m_mltProfile) delete m_mltProfile;
182 m_mltProfile = new Mlt::Profile(tmp);
183 m_mltProfile->get_profile()->is_explicit = 1;
186 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
187 m_blackClip->set("id", "black");
188 m_blackClip->set("mlt_type", "producer");
190 if (KdenliveSettings::external_display() && m_name != "clip") {
191 // Use blackmagic card for video output
192 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
193 if (BMInterface::isSupportedProfile(KdenliveSettings::blackmagic_output_device(), profileProperties)) {
194 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
195 tmp = qstrdup(decklink.toUtf8().constData());
196 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, tmp);
199 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
200 m_mltConsumer->set("terminate_on_pause", 0);
201 m_mltConsumer->set("audio_buffer", 1024);
202 m_mltConsumer->set("frequency", 48000);
203 mlt_log_set_callback(kdenlive_callback);
205 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
206 } else KMessageBox::informationList(qApp->activeWindow(), i18n("Your project's profile %1 is not compatible with the blackmagic output card. Please see supported profiles below. Switching to normal video display.", m_mltProfile->description()), BMInterface::supportedModes(KdenliveSettings::blackmagic_output_device()));
209 QString videoDriver = KdenliveSettings::videodrivername();
210 if (!videoDriver.isEmpty()) {
211 if (videoDriver == "x11_noaccel") {
212 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
215 unsetenv("SDL_VIDEO_YUV_HWACCEL");
218 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
220 //m_mltConsumer->set("fullscreen", 1);
223 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
224 m_mltConsumer->set("preview_off", 1);
225 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
226 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
228 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
229 // FIXME: the event object returned by the listen gets leaked...
230 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
231 m_mltConsumer->set("window_id", m_winid);
233 m_mltConsumer->set("resize", 1);
234 m_mltConsumer->set("terminate_on_pause", 1);
235 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
236 m_mltConsumer->set("rescale", "nearest");
237 mlt_log_set_callback(kdenlive_callback);
239 QString audioDevice = KdenliveSettings::audiodevicename();
240 if (!audioDevice.isEmpty())
241 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
243 if (!videoDriver.isEmpty())
244 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
246 QString audioDriver = KdenliveSettings::audiodrivername();
249 // Disabled because the "auto" detected driver was sometimes wrong
250 if (audioDriver.isEmpty())
251 audioDriver = KdenliveSettings::autoaudiodrivername();
254 if (!audioDriver.isEmpty())
255 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
257 m_mltConsumer->set("progressive", 1);
258 m_mltConsumer->set("audio_buffer", 1024);
259 m_mltConsumer->set("frequency", 48000);
262 Mlt::Producer *Render::invalidProducer(const QString &id)
264 Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
265 clip->set("id", id.toUtf8().constData());
266 clip->set("mlt_type", "producer");
270 int Render::resetProfile(const QString profileName)
273 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
274 QString videoDriver = KdenliveSettings::videodrivername();
275 QString currentDriver = m_mltConsumer->get("video_driver");
276 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
277 QString background = KdenliveSettings::window_background().name();
278 QString currentBackground = m_mltConsumer->get("window_background");
279 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
280 kDebug() << "reset to same profile, nothing to do";
284 if (m_isSplitView) slotSplitView(false);
285 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
286 m_mltConsumer->purge();
287 delete m_mltConsumer;
288 m_mltConsumer = NULL;
290 QString scene = sceneList();
292 double current_fps = m_mltProfile->fps();
297 pos = m_mltProducer->position();
299 Mlt::Service service(m_mltProducer->get_service());
300 if (service.type() == tractor_type) {
301 Mlt::Tractor tractor(service);
302 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
303 Mlt::Producer trackProducer(tractor.track(trackNb));
304 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
305 trackPlaylist.clear();
309 delete m_mltProducer;
311 m_mltProducer = NULL;
312 buildConsumer(profileName);
313 double new_fps = m_mltProfile->fps();
314 if (current_fps != new_fps) {
315 // fps changed, we must update the scenelist positions
316 scene = updateSceneListFps(current_fps, new_fps, scene);
318 //kDebug() << "//RESET WITHSCENE: " << scene;
319 setSceneList(scene, pos);
320 // producers have changed (different profile), so reset them...
321 emit refreshDocumentProducers();
322 /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
323 m_mltProducer = producer;
324 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
325 m_mltProducer->optimise();
326 m_mltProducer->set_speed(0);
329 //delete m_mltProfile;
330 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
331 //mlt_profile prof = m_mltProfile->get_profile();
332 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
333 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
334 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
335 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
337 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
342 void Render::seek(GenTime time)
347 m_mltProducer->seek((int)(time.frames(m_fps)));
352 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
353 QPixmap pix(width, height);
355 mlt_image_format format = mlt_image_rgb24a;
356 uint8_t *thumb = frame->get_image(format, width, height);
357 QImage image(thumb, width, height, QImage::Format_ARGB32);
359 if (!image.isNull()) {
360 pix = pix.fromImage(image);
362 QPainter painter(&pix);
363 painter.drawRect(0, 0, width - 1, height - 1);
365 } else pix.fill(Qt::black);
369 int Render::frameRenderWidth() const
371 return m_mltProfile->width();
374 int Render::renderWidth() const
376 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
379 int Render::renderHeight() const
381 return m_mltProfile->height();
384 QImage Render::extractFrame(int frame_position, int width, int height)
387 width = renderWidth();
388 height = renderHeight();
389 } else if (width % 2 == 1) width++;
391 if (!m_mltProducer) {
392 QImage pix(width, height, QImage::Format_RGB32);
396 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
399 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
403 if (url.fileName().startsWith(".all.")) { // check for slideshow
404 QString fileType = url.fileName().right(3);
406 QStringList::Iterator it;
408 QDir dir(url.directory());
410 filter << "*." + fileType;
411 filter << "*." + fileType.toUpper();
412 more = dir.entryList(filter, QDir::Files);
413 im.load(url.directory() + '/' + more.at(0));
414 } else im.load(url.path());
415 //pixmap = im.scaled(width, height);
419 double Render::consumerRatio() const
421 if (!m_mltConsumer) return 1.0;
422 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
426 int Render::getLength()
430 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
431 return mlt_producer_get_playtime(m_mltProducer->get_producer());
436 bool Render::isValid(KUrl url)
438 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
439 if (producer.is_blank())
445 double Render::dar() const
447 return m_mltProfile->dar();
451 void Render::slotSplitView(bool doit)
453 m_isSplitView = doit;
454 Mlt::Service service(m_mltProducer->parent().get_service());
455 Mlt::Tractor tractor(service);
456 if (service.type() != tractor_type || tractor.count() < 2) return;
457 Mlt::Field *field = tractor.field();
459 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
460 Mlt::Producer trackProducer(tractor.track(i));
461 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
462 if (QString(trackProducer.get("hide")).toInt() != 1) {
463 kDebug() << "// ADIDNG TRACK: " << i;
464 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
465 transition->set("mlt_service", "composite");
466 transition->set("a_track", 0);
467 transition->set("b_track", i);
468 transition->set("distort", 1);
469 transition->set("internal_added", "200");
476 tmp = "50%,0:50%x50%";
479 tmp = "0,50%:50%x50%";
483 tmp = "50%,50%:50%x50%";
486 transition->set("geometry", tmp);
487 transition->set("always_active", "1");
488 field->plant_transition(*transition, 0, i);
493 m_mltConsumer->set("refresh", 1);
495 mlt_service serv = m_mltProducer->parent().get_service();
496 mlt_service nextservice = mlt_service_get_producer(serv);
497 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
498 QString mlt_type = mlt_properties_get(properties, "mlt_type");
499 QString resource = mlt_properties_get(properties, "mlt_service");
501 while (mlt_type == "transition") {
502 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
503 if (added == "200") {
504 mlt_field_disconnect_service(field->get_field(), nextservice);
506 nextservice = mlt_service_producer(nextservice);
507 if (nextservice == NULL) break;
508 properties = MLT_SERVICE_PROPERTIES(nextservice);
509 mlt_type = mlt_properties_get(properties, "mlt_type");
510 resource = mlt_properties_get(properties, "mlt_service");
511 m_mltConsumer->set("refresh", 1);
516 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
518 KUrl url = KUrl(xml.attribute("resource", QString()));
519 Mlt::Producer *producer = NULL;
520 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
521 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
522 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
525 if (xml.attribute("type").toInt() == COLOR) {
526 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
527 } else if (xml.attribute("type").toInt() == TEXT) {
528 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
529 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
530 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
531 } else if (url.isEmpty()) {
533 QDomElement mlt = doc.createElement("mlt");
534 QDomElement play = doc.createElement("playlist");
535 doc.appendChild(mlt);
536 mlt.appendChild(play);
537 play.appendChild(doc.importNode(xml, true));
538 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
540 producer = new Mlt::Producer(*m_mltProfile, url.path().toUtf8().constData());
543 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
544 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
545 emit removeInvalidClip(clipId, replaceProducer);
550 if (xml.hasAttribute("force_aspect_ratio")) {
551 double aspect = xml.attribute("force_aspect_ratio").toDouble();
552 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
555 if (xml.hasAttribute("force_aspect_num") && xml.hasAttribute("force_aspect_den")) {
556 int width = xml.attribute("frame_size").section('x', 0, 0).toInt();
557 int height = xml.attribute("frame_size").section('x', 1, 1).toInt();
558 int aspectNumerator = xml.attribute("force_aspect_num").toInt();
559 int aspectDenominator = xml.attribute("force_aspect_den").toInt();
560 if (aspectDenominator != 0 && width != 0)
561 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
564 if (xml.hasAttribute("force_fps")) {
565 double fps = xml.attribute("force_fps").toDouble();
566 if (fps > 0) producer->set("force_fps", fps);
569 if (xml.hasAttribute("force_progressive")) {
571 int progressive = xml.attribute("force_progressive").toInt(&ok);
572 if (ok) producer->set("force_progressive", progressive);
574 if (xml.hasAttribute("force_tff")) {
576 int fieldOrder = xml.attribute("force_tff").toInt(&ok);
577 if (ok) producer->set("force_tff", fieldOrder);
579 if (xml.hasAttribute("threads")) {
580 int threads = xml.attribute("threads").toInt();
581 if (threads != 1) producer->set("threads", threads);
583 if (xml.hasAttribute("video_index")) {
584 int vindex = xml.attribute("video_index").toInt();
585 if (vindex != 0) producer->set("video_index", vindex);
587 if (xml.hasAttribute("audio_index")) {
588 int aindex = xml.attribute("audio_index").toInt();
589 if (aindex != 0) producer->set("audio_index", aindex);
591 if (xml.hasAttribute("force_colorspace")) {
592 int colorspace = xml.attribute("force_colorspace").toInt();
593 if (colorspace != 0) producer->set("force_colorspace", colorspace);
595 if (xml.hasAttribute("full_luma")) {
596 int full_luma = xml.attribute("full_luma").toInt();
597 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
600 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
601 if (xml.attribute("type").toInt() == COLOR || xml.attribute("type").toInt() == TEXT
602 || xml.attribute("type").toInt() == IMAGE || xml.attribute("type").toInt() == SLIDESHOW)
603 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
605 if (xml.hasAttribute("out"))
606 producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
608 producer->set("id", clipId.toUtf8().constData());
610 if (xml.hasAttribute("templatetext"))
611 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
613 if (!replaceProducer && xml.hasAttribute("file_hash")) {
614 // Clip already has all properties
615 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
619 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
620 QMap < QString, QString > filePropertyMap;
621 QMap < QString, QString > metadataPropertyMap;
623 int frameNumber = xml.attribute("thumbnail", "0").toInt();
624 if (frameNumber != 0) producer->seek(frameNumber);
626 filePropertyMap["duration"] = QString::number(producer->get_playtime());
627 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
629 Mlt::Frame *frame = producer->get_frame();
631 if (xml.attribute("type").toInt() == SLIDESHOW) {
632 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
633 if (ttl) producer->set("ttl", ttl);
634 if (!xml.attribute("animation").isEmpty()) {
635 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
636 if (filter && filter->is_valid()) {
638 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
639 if (!geometry.isEmpty()) {
640 if (xml.attribute("animation").contains("low-pass")) {
641 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
642 if (blur && blur->is_valid())
643 producer->attach(*blur);
645 filter->set("transition.geometry", geometry.toUtf8().data());
646 filter->set("transition.cycle", cycle);
647 producer->attach(*filter);
651 if (xml.attribute("fade") == "1") {
652 // user wants a fade effect to slideshow
653 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
654 if (filter && filter->is_valid()) {
655 if (ttl) filter->set("cycle", ttl);
656 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
657 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
658 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
659 if (xml.hasAttribute("softness")) {
660 int soft = xml.attribute("softness").toInt();
661 filter->set("luma.softness", (double) soft / 100.0);
664 producer->attach(*filter);
667 if (xml.attribute("crop") == "1") {
668 // user wants to center crop the slides
669 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
670 if (filter && filter->is_valid()) {
671 filter->set("center", 1);
672 producer->attach(*filter);
677 if (producer->get_double("meta.media.frame_rate_den") > 0) {
678 filePropertyMap["fps"] = QString::number(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
679 } else filePropertyMap["fps"] = producer->get("source_fps");
681 if (frame && frame->is_valid()) {
682 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
683 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
684 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
685 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
687 if (frame->get_int("test_image") == 0) {
688 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
689 filePropertyMap["type"] = "playlist";
690 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
691 } else if (frame->get_int("test_audio") == 0)
692 filePropertyMap["type"] = "av";
694 filePropertyMap["type"] = "video";
696 mlt_image_format format = mlt_image_rgb24a;
697 int frame_width = width;
698 int frame_height = imageHeight;
699 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
700 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied);
703 if (!image.isNull()) {
704 if (frame_width > (2 * width)) {
705 // there was a scaling problem, do it manually
706 QImage scaled = image.scaled(width, imageHeight);
707 pix = QPixmap::fromImage(scaled.rgbSwapped());
708 } else pix = QPixmap::fromImage(image.rgbSwapped());
712 emit replyGetImage(clipId, pix);
714 } else if (frame->get_int("test_audio") == 0) {
715 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
716 emit replyGetImage(clipId, pixmap);
717 filePropertyMap["type"] = "audio";
721 // Retrieve audio / video codec name
725 if (producer->get_int("video_index") > -1) {
726 /*if (context->duration == AV_NOPTS_VALUE) {
727 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
728 emit removeInvalidClip(clipId);
732 // Get the video_index
733 int default_video = producer->get_int("video_index");
735 int default_audio = producer->get_int("audio_index");
738 // Find maximum stream index values
739 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
740 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
741 QString type = producer->get(property);
744 else if (type == "audio")
747 filePropertyMap["default_video"] = QString::number(default_video);
748 filePropertyMap["video_max"] = QString::number(video_max);
749 filePropertyMap["default_audio"] = QString::number(default_audio);
750 filePropertyMap["audio_max"] = QString::number(audio_max);
752 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
753 if (producer->get(property)) {
754 filePropertyMap["videocodec"] = producer->get(property);
756 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
757 if (producer->get(property))
758 filePropertyMap["videocodec"] = producer->get(property);
761 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
762 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
763 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
765 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
766 if (producer->get_int("audio_index") > -1) {
767 // Get the audio_index
768 int index = producer->get_int("audio_index");
770 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
771 if (producer->get(property)) {
772 filePropertyMap["audiocodec"] = producer->get(property);
774 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
775 if (producer->get(property))
776 filePropertyMap["audiocodec"] = producer->get(property);
781 Mlt::Properties metadata;
782 metadata.pass_values(*producer, "meta.attr.");
783 int count = metadata.count();
784 for (int i = 0; i < count; i ++) {
785 QString name = metadata.get_name(i);
786 QString value = QString::fromUtf8(metadata.get(i));
787 if (name.endsWith("markup") && !value.isEmpty())
788 metadataPropertyMap[ name.section('.', 0, -2)] = value;
791 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
792 // FIXME: should delete this to avoid a leak...
798 /** Create the producer from the MLT XML QDomDocument */
799 void Render::initSceneList()
801 kDebug() << "-------- INIT SCENE LIST ------_";
803 QDomElement mlt = doc.createElement("mlt");
804 doc.appendChild(mlt);
805 QDomElement prod = doc.createElement("producer");
806 prod.setAttribute("resource", "colour");
807 prod.setAttribute("colour", "red");
808 prod.setAttribute("id", "black");
809 prod.setAttribute("in", "0");
810 prod.setAttribute("out", "0");
812 QDomElement tractor = doc.createElement("tractor");
813 QDomElement multitrack = doc.createElement("multitrack");
815 QDomElement playlist1 = doc.createElement("playlist");
816 playlist1.appendChild(prod);
817 multitrack.appendChild(playlist1);
818 QDomElement playlist2 = doc.createElement("playlist");
819 multitrack.appendChild(playlist2);
820 QDomElement playlist3 = doc.createElement("playlist");
821 multitrack.appendChild(playlist3);
822 QDomElement playlist4 = doc.createElement("playlist");
823 multitrack.appendChild(playlist4);
824 QDomElement playlist5 = doc.createElement("playlist");
825 multitrack.appendChild(playlist5);
826 tractor.appendChild(multitrack);
827 mlt.appendChild(tractor);
828 // kDebug()<<doc.toString();
830 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
831 setSceneList(doc, 0);
835 int Render::setProducer(Mlt::Producer *producer, int position)
837 if (m_winid == -1) return -1;
840 m_mltConsumer->stop();
843 m_mltConsumer->purge();
846 m_mltProducer->set_speed(0);
847 delete m_mltProducer;
848 m_mltProducer = NULL;
852 m_mltProducer = new Mlt::Producer(producer->get_producer());
853 } else m_mltProducer = m_blackClip->cut(0, 50);
855 if (!m_mltProducer || !m_mltProducer->is_valid()) {
856 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
859 int volume = KdenliveSettings::volume();
860 m_mltProducer->set("meta.volume", (double)volume / 100);
861 m_fps = m_mltProducer->get_fps();
862 int error = connectPlaylist();
864 if (position != -1) {
865 m_mltProducer->seek(position);
866 emit rendererPosition(position);
867 } else emit rendererPosition((int) m_mltProducer->position());
872 int Render::setSceneList(QDomDocument list, int position)
874 return setSceneList(list.toString(), position);
877 int Render::setSceneList(QString playlist, int position)
879 if (m_winid == -1) return -1;
883 //kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
886 if (!m_mltConsumer->is_stopped()) {
887 m_mltConsumer->stop();
889 m_mltConsumer->set("refresh", 0);
891 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
896 m_mltProducer->set_speed(0);
897 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
900 Mlt::Service service(m_mltProducer->parent().get_service());
901 mlt_service_lock(service.get_service());
903 if (service.type() == tractor_type) {
904 Mlt::Tractor tractor(service);
905 Mlt::Field *field = tractor.field();
906 mlt_service nextservice = mlt_service_get_producer(service.get_service());
907 mlt_service nextservicetodisconnect;
908 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
909 QString mlt_type = mlt_properties_get(properties, "mlt_type");
910 QString resource = mlt_properties_get(properties, "mlt_service");
911 // Delete all transitions
912 while (mlt_type == "transition") {
913 nextservicetodisconnect = nextservice;
914 nextservice = mlt_service_producer(nextservice);
915 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
916 if (nextservice == NULL) break;
917 properties = MLT_SERVICE_PROPERTIES(nextservice);
918 mlt_type = mlt_properties_get(properties, "mlt_type");
919 resource = mlt_properties_get(properties, "mlt_service");
922 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
923 Mlt::Producer trackProducer(tractor.track(trackNb));
924 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
925 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
929 mlt_service_unlock(service.get_service());
931 qDeleteAll(m_slowmotionProducers.values());
932 m_slowmotionProducers.clear();
934 delete m_mltProducer;
935 m_mltProducer = NULL;
941 // TODO: Better way to do this
942 if (KdenliveSettings::projectloading_avformatnovalidate())
943 playlist.replace(">avformat</property>", ">avformat-novalidate</property>");
945 playlist.replace(">avformat-novalidate</property>", ">avformat</property>");
947 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
949 if (!m_mltProducer || !m_mltProducer->is_valid()) {
950 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
951 m_mltProducer = m_blackClip->cut(0, 50);
954 int volume = KdenliveSettings::volume();
955 m_mltProducer->set("meta.volume", (double)volume / 100);
956 m_mltProducer->optimise();
958 /*if (KdenliveSettings::osdtimecode()) {
959 // Attach filter for on screen display of timecode
961 QString attr = "attr_check";
962 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
963 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
964 mlt_producer_attach( m_mltProducer->get_producer(), filter );
965 mlt_filter_close( filter );
967 m_osdInfo = new Mlt::Filter("data_show");
968 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
969 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
970 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
971 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
972 m_osdInfo->set("dynamic", "1");
974 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
976 m_osdInfo->set("dynamic", "0");
979 m_fps = m_mltProducer->get_fps();
981 // Seek to correct place after opening project.
982 m_mltProducer->seek(position);
985 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
986 if (error == 0) error = connectPlaylist();
987 else connectPlaylist();
988 fillSlowMotionProducers();
994 //kDebug()<<"// SETSCN LST, POS: "<<position;
995 //if (position != 0) emit rendererPosition(position);
998 const QString Render::sceneList()
1001 Mlt::Profile profile((mlt_profile) 0);
1002 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1003 m_mltProducer->optimise();
1004 xmlConsumer.set("terminate_on_pause", 1);
1005 Mlt::Producer prod(m_mltProducer->get_producer());
1006 bool split = m_isSplitView;
1007 if (split) slotSplitView(false);
1008 xmlConsumer.connect(prod);
1009 xmlConsumer.start();
1010 while (!xmlConsumer.is_stopped()) {}
1011 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1012 if (split) slotSplitView(true);
1016 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1020 doc.setContent(sceneList(), false);
1021 if (!kdenliveData.isNull()) {
1022 // add Kdenlive specific tags
1023 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1024 mlt.appendChild(doc.importNode(kdenliveData, true));
1026 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1027 kWarning() << "////// ERROR writing to file: " << path;
1030 file.write(doc.toString().toUtf8());
1031 if (file.error() != QFile::NoError) {
1039 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1041 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1042 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1043 m_mltProducer->optimise();
1044 xmlConsumer.set("terminate_on_pause", 1);
1045 if (m_name == "clip") {
1046 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1048 list.insert_at(0, prod, 0);
1050 list.set("title", desc.toUtf8().constData());
1051 xmlConsumer.connect(list);
1054 //TODO: not working yet, save zone from timeline
1055 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1056 /* Mlt::Service service(p1->parent().get_service());
1057 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1059 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1060 //prod->set("title", desc.toUtf8().constData());
1061 xmlConsumer.connect(*p1); //list);
1064 xmlConsumer.start();
1067 double Render::fps() const
1072 int Render::connectPlaylist()
1074 if (!m_mltConsumer) return -1;
1075 //m_mltConsumer->set("refresh", "0");
1076 m_mltConsumer->connect(*m_mltProducer);
1077 m_mltProducer->set_speed(0);
1078 if (m_mltConsumer->start() == -1) {
1079 // ARGH CONSUMER BROKEN!!!!
1080 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."));
1081 delete m_mltConsumer;
1082 m_mltConsumer = NULL;
1085 emit durationChanged(m_mltProducer->get_playtime());
1090 void Render::refreshDisplay()
1093 if (!m_mltProducer) return;
1094 //m_mltConsumer->set("refresh", 0);
1096 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1097 /*if (KdenliveSettings::osdtimecode()) {
1098 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1099 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1100 m_osdInfo->set("dynamic", "1");
1101 m_mltProducer->attach(*m_osdInfo);
1104 m_mltProducer->detach(*m_osdInfo);
1105 m_osdInfo->set("dynamic", "0");
1110 int Render::volume() const
1112 if (!m_mltConsumer || !m_mltProducer) return -1;
1113 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1116 void Render::slotSetVolume(int volume)
1118 if (!m_mltConsumer || !m_mltProducer) return;
1119 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1122 m_mltConsumer->set("refresh", 0);
1123 // Attach filter for on screen display of timecode
1124 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1125 mlt_properties_set_double( properties, "meta.volume", volume );
1126 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1127 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1129 if (!KdenliveSettings::osdtimecode()) {
1130 m_mltProducer->detach(*m_osdInfo);
1131 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1132 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1135 //m_osdTimer->setSingleShot(2500);
1138 void Render::slotOsdTimeout()
1140 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1141 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1142 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1143 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1147 void Render::start()
1149 kDebug() << "----- STARTING MONITOR: " << m_name;
1150 if (m_winid == -1) {
1151 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1154 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1155 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1156 if (m_mltConsumer->start() == -1) {
1157 //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."));
1158 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1160 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1161 m_isBlocked = false;
1165 m_isBlocked = false;
1170 if (m_mltProducer == NULL) return;
1171 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1172 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1174 //m_mltConsumer->set("refresh", 0);
1175 m_mltConsumer->stop();
1176 // delete m_mltConsumer;
1177 // m_mltConsumer = NULL;
1179 kDebug() << "///////////// RENDER STOP2-------";
1182 if (m_mltProducer) {
1183 if (m_isZoneMode) resetZoneMode();
1184 m_mltProducer->set_speed(0.0);
1185 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1186 //kDebug() << m_mltProducer->get_length();
1188 kDebug() << "///////////// RENDER STOP3-------";
1191 void Render::stop(const GenTime & startTime)
1194 kDebug() << "///////////// RENDER STOP-------2";
1195 if (m_mltProducer) {
1196 if (m_isZoneMode) resetZoneMode();
1197 m_mltProducer->set_speed(0.0);
1198 m_mltProducer->seek((int) startTime.frames(m_fps));
1200 m_mltConsumer->purge();
1203 void Render::pause()
1205 if (!m_mltProducer || !m_mltConsumer)
1207 if (m_mltProducer->get_speed() == 0.0) return;
1208 if (m_isZoneMode) resetZoneMode();
1210 m_mltConsumer->set("refresh", 0);
1211 m_mltProducer->set_speed(0.0);
1213 The 2 lines below create a flicker loop
1214 emit rendererPosition(m_framePosition);
1215 m_mltProducer->seek(m_framePosition);*/
1216 m_mltConsumer->purge();
1219 void Render::switchPlay()
1221 if (!m_mltProducer || !m_mltConsumer)
1223 if (m_isZoneMode) resetZoneMode();
1224 if (m_mltProducer->get_speed() == 0.0) {
1225 m_isBlocked = false;
1226 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1227 m_mltProducer->set_speed(1.0);
1228 m_mltConsumer->set("refresh", 1);
1231 m_mltConsumer->set("refresh", 0);
1232 m_mltProducer->set_speed(0.0);
1233 //emit rendererPosition(m_framePosition);
1234 m_mltProducer->seek(m_framePosition);
1235 m_mltConsumer->purge();
1236 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1237 //m_mltConsumer->set("refresh", 0);
1238 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1239 m_mltProducer->set_speed(0);
1240 m_mltProducer->seek( position );
1241 //m_mltProducer->seek((int) m_framePosition);
1242 m_isBlocked = false;*/
1244 /*if (speed == 0.0) {
1245 m_mltProducer->seek((int) m_framePosition + 1);
1246 m_mltConsumer->purge();
1251 void Render::play(double speed)
1255 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1256 m_isBlocked = false;
1257 m_mltProducer->set_speed(speed);
1258 /*if (speed == 0.0) {
1259 m_mltProducer->seek((int) m_framePosition + 1);
1260 m_mltConsumer->purge();
1265 void Render::play(const GenTime & startTime)
1267 if (!m_mltProducer || !m_mltConsumer)
1269 m_isBlocked = false;
1270 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1271 m_mltProducer->set_speed(1.0);
1272 m_mltConsumer->set("refresh", 1);
1275 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1277 if (!m_mltProducer || !m_mltConsumer)
1279 //m_mltProducer->set("eof", "loop");
1280 m_isLoopMode = true;
1281 m_loopStart = startTime;
1282 playZone(startTime, stopTime);
1285 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1287 if (!m_mltProducer || !m_mltConsumer)
1289 m_isBlocked = false;
1290 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1291 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1292 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1293 m_mltProducer->set_speed(1.0);
1294 m_mltConsumer->set("refresh", 1);
1295 m_isZoneMode = true;
1298 void Render::resetZoneMode()
1300 if (!m_isZoneMode && !m_isLoopMode) return;
1301 m_mltProducer->set("out", m_originalOut);
1302 //m_mltProducer->set("eof", "pause");
1303 m_isZoneMode = false;
1304 m_isLoopMode = false;
1307 void Render::seekToFrame(int pos)
1309 //kDebug()<<" ********* RENDER SEEK TO POS";
1312 m_isBlocked = false;
1314 m_mltProducer->seek(pos);
1318 void Render::seekToFrameDiff(int diff)
1320 //kDebug()<<" ********* RENDER SEEK TO POS";
1323 m_isBlocked = false;
1325 m_mltProducer->seek(m_mltProducer->position() + diff);
1329 void Render::doRefresh()
1331 // Use a Timer so that we don't refresh too much
1332 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1335 void Render::refresh()
1337 if (!m_mltProducer || m_isBlocked)
1339 if (m_mltConsumer) {
1340 m_mltConsumer->set("refresh", 1);
1344 void Render::setDropFrames(bool show)
1346 if (m_mltConsumer) {
1348 if (show == false) dropFrames = 0;
1349 m_mltConsumer->stop();
1351 m_mltConsumer->set("real_time", dropFrames);
1353 m_mltConsumer->set("play.real_time", dropFrames);
1355 if (m_mltConsumer->start() == -1) {
1356 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1362 double Render::playSpeed()
1364 if (m_mltProducer) return m_mltProducer->get_speed();
1368 GenTime Render::seekPosition() const
1370 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1371 else return GenTime();
1374 int Render::seekFramePosition() const
1376 if (m_mltProducer) return (int) m_mltProducer->position();
1380 const QString & Render::rendererName() const
1385 void Render::emitFrameUpdated(Mlt::Frame& frame)
1387 mlt_image_format format = mlt_image_rgb24a;
1390 const uchar* image = frame.get_image(format, width, height);
1391 QImage qimage(width, height, QImage::Format_ARGB32);
1392 memcpy(qimage.bits(), image, width * height * 4);
1393 emit frameUpdated(qimage.rgbSwapped());
1396 void Render::emitFrameNumber(double position)
1398 m_framePosition = position;
1399 emit rendererPosition((int) position);
1402 void Render::emitConsumerStopped()
1404 // This is used to know when the playing stopped
1405 if (m_mltProducer) {
1406 double pos = m_mltProducer->position();
1407 if (m_isLoopMode) play(m_loopStart);
1408 else if (m_isZoneMode) resetZoneMode();
1409 emit rendererStopped((int) pos);
1413 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1415 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1418 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1420 if (!m_mltProducer) {
1421 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1425 //int height = 1080;//KdenliveSettings::defaultheight();
1426 //int width = 1940; //KdenliveSettings::displaywidth();
1428 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1430 QPixmap pix(width, height);
1431 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1432 m_convert.set("forced", mlt_image_rgb24a);
1433 m_mltProducer->attach(m_convert);
1434 Mlt::Frame * frame = m_mltProducer->get_frame();
1435 m_mltProducer->detach(m_convert);
1437 pix = frameThumbnail(frame, width, height);
1440 pix.save(url.path(), "PNG");
1441 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1445 void Render::showFrame(Mlt::Frame& frame)
1447 m_framePosition = qMax(frame.get_int("_position"), 0);
1448 emit rendererPosition((int) m_framePosition);
1449 mlt_image_format format = mlt_image_rgb24a;
1452 const uchar* image = frame.get_image(format, width, height);
1453 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1454 memcpy(qimage.scanLine(0), image, width * height * 4);
1455 emit showImageSignal(qimage);
1456 if (analyseAudio) showAudio(frame);
1457 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1458 emit frameUpdated(qimage.rgbSwapped());
1462 void Render::showAudio(Mlt::Frame& frame)
1464 if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
1465 mlt_audio_format audio_format = mlt_audio_s16;
1467 int num_channels = 0;
1469 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1472 int num_samples = samples > 200 ? 200 : samples;
1473 QByteArray channels;
1474 for (int i = 0; i < num_channels; i++) {
1476 for (int s = 0; s < num_samples; s ++) {
1477 val += abs(data[i+s*num_channels] / 128);
1479 channels.append(val / num_samples);
1484 emit showAudioSignal(channels);
1486 emit showAudioSignal(QByteArray());
1490 * MLT playlist direct manipulation.
1493 void Render::mltCheckLength(Mlt::Tractor *tractor)
1495 //kDebug()<<"checking track length: "<<track<<"..........";
1497 int trackNb = tractor->count();
1501 Mlt::Producer trackProducer(tractor->track(0));
1502 duration = trackProducer.get_playtime() - 1;
1503 m_mltProducer->set("out", duration);
1504 emit durationChanged(duration);
1507 while (trackNb > 1) {
1508 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1509 trackDuration = trackProducer.get_playtime() - 1;
1510 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1511 if (trackDuration > duration) duration = trackDuration;
1515 Mlt::Producer blackTrackProducer(tractor->track(0));
1517 if (blackTrackProducer.get_playtime() - 1 != duration) {
1518 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1519 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1520 if (blackclip && blackclip->is_blank()) {
1525 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1526 blackTrackPlaylist.clear();
1527 m_blackClip->set("length", duration + 1);
1528 m_blackClip->set("out", duration);
1529 blackclip = m_blackClip->cut(0, duration);
1530 blackTrackPlaylist.insert_at(0, blackclip, 1);
1532 if (duration > blackclip->parent().get_length()) {
1533 blackclip->parent().set("length", duration + 1);
1534 blackclip->parent().set("out", duration);
1535 blackclip->set("length", duration + 1);
1537 blackTrackPlaylist.resize_clip(0, 0, duration);
1541 m_mltProducer->set("out", duration);
1542 emit durationChanged(duration);
1546 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1548 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1550 // We want a slowmotion producer
1551 double speed = element.attribute("speed", "1.0").toDouble();
1552 int strobe = element.attribute("strobe", "1").toInt();
1553 QString url = QString::fromUtf8(prod->get("resource"));
1554 url.append('?' + QString::number(speed));
1555 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1556 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1557 if (!slowprod || slowprod->get_producer() == NULL) {
1558 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1559 if (strobe > 1) slowprod->set("strobe", strobe);
1560 QString id = prod->get("id");
1561 if (id.contains('_')) id = id.section('_', 0, 0);
1562 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1563 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1564 slowprod->set("id", producerid.toUtf8().constData());
1565 m_slowmotionProducers.insert(url, slowprod);
1570 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1572 if (m_mltProducer == NULL) {
1573 kDebug() << "PLAYLIST NOT INITIALISED //////";
1577 kDebug() << "Cannot insert clip without producer //////";
1580 Mlt::Producer parentProd(m_mltProducer->parent());
1581 if (parentProd.get_producer() == NULL) {
1582 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1586 Mlt::Service service(parentProd.get_service());
1587 if (service.type() != tractor_type) {
1588 kWarning() << "// TRACTOR PROBLEM";
1591 Mlt::Tractor tractor(service);
1592 if (info.track > tractor.count() - 1) {
1593 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1596 mlt_service_lock(service.get_service());
1597 Mlt::Producer trackProducer(tractor.track(info.track));
1598 int trackDuration = trackProducer.get_playtime() - 1;
1599 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1600 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1601 prod = checkSlowMotionProducer(prod, element);
1602 if (prod == NULL || !prod->is_valid()) {
1603 mlt_service_unlock(service.get_service());
1607 int cutPos = (int) info.cropStart.frames(m_fps);
1608 if (cutPos < 0) cutPos = 0;
1609 int insertPos = (int) info.startPos.frames(m_fps);
1610 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1611 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1612 if (overwrite && (insertPos < trackDuration)) {
1613 // Replace zone with blanks
1614 //trackPlaylist.split_at(insertPos, true);
1615 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1616 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1617 trackPlaylist.insert_blank(clipIndex, cutDuration);
1619 trackPlaylist.split_at(insertPos, true);
1620 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1621 trackPlaylist.insert_blank(clipIndex, cutDuration);
1623 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1625 /*if (QString(prod->get("transparency")).toInt() == 1)
1626 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1628 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1629 mlt_service_unlock(service.get_service());
1630 /*tractor.multitrack()->refresh();
1631 tractor.refresh();*/
1636 void Render::mltCutClip(int track, GenTime position)
1640 Mlt::Service service(m_mltProducer->parent().get_service());
1641 if (service.type() != tractor_type) {
1642 kWarning() << "// TRACTOR PROBLEM";
1646 Mlt::Tractor tractor(service);
1647 Mlt::Producer trackProducer(tractor.track(track));
1648 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1651 /* // Display playlist info
1652 kDebug()<<"//////////// BEFORE";
1653 for (int i = 0; i < trackPlaylist.count(); i++) {
1654 int blankStart = trackPlaylist.clip_start(i);
1655 int blankDuration = trackPlaylist.clip_length(i) - 1;
1657 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1658 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1661 int cutPos = (int) position.frames(m_fps);
1663 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1664 if (trackPlaylist.is_blank(clipIndex)) {
1665 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1666 m_isBlocked = false;
1669 mlt_service_lock(service.get_service());
1670 int clipStart = trackPlaylist.clip_start(clipIndex);
1671 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1672 mlt_service_unlock(service.get_service());
1674 // duplicate effects
1675 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1676 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1678 if (original == NULL || clip == NULL) {
1679 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1681 Mlt::Service clipService(original->get_service());
1682 Mlt::Service dupService(clip->get_service());
1686 Mlt::Filter *filter = clipService.filter(ct);
1688 // Only duplicate Kdenlive filters, and skip the fade in effects
1689 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1690 // looks like there is no easy way to duplicate a filter,
1691 // so we will create a new one and duplicate its properties
1692 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1693 if (dup && dup->is_valid()) {
1694 Mlt::Properties entries(filter->get_properties());
1695 for (int i = 0; i < entries.count(); i++) {
1696 dup->set(entries.get_name(i), entries.get(i));
1698 dupService.attach(*dup);
1702 filter = clipService.filter(ct);
1705 /* // Display playlist info
1706 kDebug()<<"//////////// AFTER";
1707 for (int i = 0; i < trackPlaylist.count(); i++) {
1708 int blankStart = trackPlaylist.clip_start(i);
1709 int blankDuration = trackPlaylist.clip_length(i) - 1;
1711 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1712 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1715 m_isBlocked = false;
1718 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1722 kDebug() << "Cannot update clip with null producer //////";
1725 Mlt::Service service(m_mltProducer->parent().get_service());
1726 if (service.type() != tractor_type) {
1727 kWarning() << "// TRACTOR PROBLEM";
1730 Mlt::Tractor tractor(service);
1731 Mlt::Producer trackProducer(tractor.track(info.track));
1732 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1733 int startPos = info.startPos.frames(m_fps);
1734 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1735 if (trackPlaylist.is_blank(clipIndex)) {
1736 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1739 mlt_service_lock(service.get_service());
1740 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1742 QList <Mlt::Filter *> filtersList;
1743 Mlt::Service sourceService(clip->get_service());
1745 Mlt::Filter *filter = sourceService.filter(ct);
1747 if (filter->get_int("kdenlive_ix") != 0) {
1748 filtersList.append(filter);
1751 filter = sourceService.filter(ct);
1754 trackPlaylist.replace_with_blank(clipIndex);
1756 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1757 prod = checkSlowMotionProducer(prod, element);
1758 if (prod == NULL || !prod->is_valid()) {
1759 mlt_service_unlock(service.get_service());
1762 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1763 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1767 //if (mltInsertClip(info, element, prod) == -1) return false;
1768 if (!filtersList.isEmpty()) {
1769 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1770 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1771 Mlt::Service destService(destclip->get_service());
1773 for (int i = 0; i < filtersList.count(); i++)
1774 destService.attach(*(filtersList.at(i)));
1776 mlt_service_unlock(service.get_service());
1781 bool Render::mltRemoveClip(int track, GenTime position)
1783 Mlt::Service service(m_mltProducer->parent().get_service());
1784 if (service.type() != tractor_type) {
1785 kWarning() << "// TRACTOR PROBLEM";
1789 Mlt::Tractor tractor(service);
1790 mlt_service_lock(service.get_service());
1791 Mlt::Producer trackProducer(tractor.track(track));
1792 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1793 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1795 // Display playlist info
1796 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1797 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1798 int blankStart = trackPlaylist.clip_start(i);
1799 int blankDuration = trackPlaylist.clip_length(i) - 1;
1801 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1802 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1804 if (trackPlaylist.is_blank(clipIndex)) {
1805 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1806 mlt_service_unlock(service.get_service());
1809 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1811 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1812 if (clip) delete clip;
1813 trackPlaylist.consolidate_blanks(0);
1814 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1815 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1817 /* // Display playlist info
1818 kDebug()<<"//// AFTER";
1819 for (int i = 0; i < trackPlaylist.count(); i++) {
1820 int blankStart = trackPlaylist.clip_start(i);
1821 int blankDuration = trackPlaylist.clip_length(i) - 1;
1823 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1824 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1826 mlt_service_unlock(service.get_service());
1827 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1828 m_isBlocked = false;
1832 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1834 if (!m_mltProducer) {
1835 kDebug() << "PLAYLIST NOT INITIALISED //////";
1838 Mlt::Producer parentProd(m_mltProducer->parent());
1839 if (parentProd.get_producer() == NULL) {
1840 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1844 Mlt::Service service(parentProd.get_service());
1845 Mlt::Tractor tractor(service);
1846 int insertPos = pos.frames(m_fps);
1848 Mlt::Producer trackProducer(tractor.track(track));
1849 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1850 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1851 if (clipIndex == trackPlaylist.count()) {
1852 // We are after the end of the playlist
1855 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1856 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1857 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1860 int Render::mltTrackDuration(int track)
1862 if (!m_mltProducer) {
1863 kDebug() << "PLAYLIST NOT INITIALISED //////";
1866 Mlt::Producer parentProd(m_mltProducer->parent());
1867 if (parentProd.get_producer() == NULL) {
1868 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1872 Mlt::Service service(parentProd.get_service());
1873 Mlt::Tractor tractor(service);
1875 Mlt::Producer trackProducer(tractor.track(track));
1876 return trackProducer.get_playtime() - 1;
1879 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1881 if (!m_mltProducer) {
1882 kDebug() << "PLAYLIST NOT INITIALISED //////";
1885 Mlt::Producer parentProd(m_mltProducer->parent());
1886 if (parentProd.get_producer() == NULL) {
1887 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1890 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1891 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1893 Mlt::Service service(parentProd.get_service());
1894 Mlt::Tractor tractor(service);
1895 mlt_service_lock(service.get_service());
1896 int diff = duration.frames(m_fps);
1897 int offset = timeOffset.frames(m_fps);
1901 // insert space in one track only
1902 Mlt::Producer trackProducer(tractor.track(track));
1903 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1904 insertPos = trackClipStartList.value(track);
1905 if (insertPos != -1) {
1906 insertPos += offset;
1907 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1909 trackPlaylist.insert_blank(clipIndex, diff - 1);
1911 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1912 if (!trackPlaylist.is_blank(clipIndex)) {
1913 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1915 int position = trackPlaylist.clip_start(clipIndex);
1916 int blankDuration = trackPlaylist.clip_length(clipIndex);
1918 if (blankDuration - diff == 0) {
1919 trackPlaylist.remove(clipIndex);
1920 } else trackPlaylist.remove_region(position, diff);
1922 trackPlaylist.consolidate_blanks(0);
1924 // now move transitions
1925 mlt_service serv = m_mltProducer->parent().get_service();
1926 mlt_service nextservice = mlt_service_get_producer(serv);
1927 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1928 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1929 QString resource = mlt_properties_get(properties, "mlt_service");
1931 while (mlt_type == "transition") {
1932 mlt_transition tr = (mlt_transition) nextservice;
1933 int currentTrack = mlt_transition_get_b_track(tr);
1934 int currentIn = (int) mlt_transition_get_in(tr);
1935 int currentOut = (int) mlt_transition_get_out(tr);
1936 insertPos = trackTransitionStartList.value(track);
1937 if (insertPos != -1) {
1938 insertPos += offset;
1939 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1940 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1943 nextservice = mlt_service_producer(nextservice);
1944 if (nextservice == NULL) break;
1945 properties = MLT_SERVICE_PROPERTIES(nextservice);
1946 mlt_type = mlt_properties_get(properties, "mlt_type");
1947 resource = mlt_properties_get(properties, "mlt_service");
1950 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1951 Mlt::Producer trackProducer(tractor.track(trackNb));
1952 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1954 //int clipNb = trackPlaylist.count();
1955 insertPos = trackClipStartList.value(trackNb);
1956 if (insertPos != -1) {
1957 insertPos += offset;
1959 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1960 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1961 for (int i = 0; i < clipNb; i++) {
1962 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1963 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1964 kDebug()<<"-------------";
1966 kDebug()<<"END-------------";*/
1969 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1971 trackPlaylist.insert_blank(clipIndex, diff - 1);
1973 if (!trackPlaylist.is_blank(clipIndex)) {
1976 if (!trackPlaylist.is_blank(clipIndex)) {
1977 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1979 int position = trackPlaylist.clip_start(clipIndex);
1980 int blankDuration = trackPlaylist.clip_length(clipIndex);
1981 if (diff + blankDuration == 0) {
1982 trackPlaylist.remove(clipIndex);
1983 } else trackPlaylist.remove_region(position, - diff);
1985 trackPlaylist.consolidate_blanks(0);
1988 // now move transitions
1989 mlt_service serv = m_mltProducer->parent().get_service();
1990 mlt_service nextservice = mlt_service_get_producer(serv);
1991 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1992 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1993 QString resource = mlt_properties_get(properties, "mlt_service");
1995 while (mlt_type == "transition") {
1996 mlt_transition tr = (mlt_transition) nextservice;
1997 int currentIn = (int) mlt_transition_get_in(tr);
1998 int currentOut = (int) mlt_transition_get_out(tr);
1999 int currentTrack = mlt_transition_get_b_track(tr);
2000 insertPos = trackTransitionStartList.value(currentTrack);
2001 if (insertPos != -1) {
2002 insertPos += offset;
2003 if (currentOut > insertPos && resource != "mix") {
2004 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2007 nextservice = mlt_service_producer(nextservice);
2008 if (nextservice == NULL) break;
2009 properties = MLT_SERVICE_PROPERTIES(nextservice);
2010 mlt_type = mlt_properties_get(properties, "mlt_type");
2011 resource = mlt_properties_get(properties, "mlt_service");
2014 mlt_service_unlock(service.get_service());
2015 mltCheckLength(&tractor);
2016 m_mltConsumer->set("refresh", 1);
2020 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2022 if (source == dest) return;
2023 Mlt::Service sourceService(source->get_service());
2024 Mlt::Service destService(dest->get_service());
2026 // move all effects to the correct producer
2028 Mlt::Filter *filter = sourceService.filter(ct);
2030 if (filter->get_int("kdenlive_ix") != 0) {
2031 sourceService.detach(*filter);
2032 destService.attach(*filter);
2034 filter = sourceService.filter(ct);
2038 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2042 Mlt::Service service(m_mltProducer->parent().get_service());
2043 if (service.type() != tractor_type) {
2044 kWarning() << "// TRACTOR PROBLEM";
2047 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2048 Mlt::Tractor tractor(service);
2049 Mlt::Producer trackProducer(tractor.track(info.track));
2050 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2051 int startPos = info.startPos.frames(m_fps);
2052 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2053 int clipLength = trackPlaylist.clip_length(clipIndex);
2055 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2056 if (original == NULL) {
2059 if (!original->is_valid() || original->is_blank()) {
2064 Mlt::Producer clipparent = original->parent();
2065 if (!clipparent.is_valid() || clipparent.is_blank()) {
2071 QString serv = clipparent.get("mlt_service");
2072 QString id = clipparent.get("id");
2073 if (speed <= 0 && speed > -1) speed = 1.0;
2074 //kDebug() << "CLIP SERVICE: " << serv;
2075 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2076 mlt_service_lock(service.get_service());
2077 QString url = QString::fromUtf8(clipparent.get("resource"));
2078 url.append('?' + QString::number(speed));
2079 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2080 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2081 if (!slowprod || slowprod->get_producer() == NULL) {
2082 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2083 if (strobe > 1) slowprod->set("strobe", strobe);
2084 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2085 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2086 slowprod->set("id", producerid.toUtf8().constData());
2087 // copy producer props
2088 double ar = original->parent().get_double("force_aspect_ratio");
2089 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2090 double fps = original->parent().get_double("force_fps");
2091 if (fps != 0.0) slowprod->set("force_fps", fps);
2092 int threads = original->parent().get_int("threads");
2093 if (threads != 0) slowprod->set("threads", threads);
2094 if (original->parent().get("force_progressive"))
2095 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2096 if (original->parent().get("force_tff"))
2097 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2098 int ix = original->parent().get_int("video_index");
2099 if (ix != 0) slowprod->set("video_index", ix);
2100 int colorspace = original->parent().get_int("force_colorspace");
2101 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2102 int full_luma = original->parent().get_int("set.force_full_luma");
2103 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2104 m_slowmotionProducers.insert(url, slowprod);
2106 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2107 trackPlaylist.consolidate_blanks(0);
2109 // Check that the blank space is long enough for our new duration
2110 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2111 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2113 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2114 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2115 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2116 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2118 // move all effects to the correct producer
2119 mltPasteEffects(clip, cut);
2120 trackPlaylist.insert_at(startPos, cut, 1);
2123 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2124 newLength = trackPlaylist.clip_length(clipIndex);
2125 mlt_service_unlock(service.get_service());
2126 } else if (speed == 1.0 && strobe < 2) {
2127 mlt_service_lock(service.get_service());
2129 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2130 trackPlaylist.consolidate_blanks(0);
2132 // Check that the blank space is long enough for our new duration
2133 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2134 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2137 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2138 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2139 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2140 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2141 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2143 // move all effects to the correct producer
2144 mltPasteEffects(clip, cut);
2146 trackPlaylist.insert_at(startPos, cut, 1);
2149 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2150 newLength = trackPlaylist.clip_length(clipIndex);
2151 mlt_service_unlock(service.get_service());
2153 } else if (serv == "framebuffer") {
2154 mlt_service_lock(service.get_service());
2155 QString url = QString::fromUtf8(clipparent.get("resource"));
2156 url = url.section('?', 0, 0);
2157 url.append('?' + QString::number(speed));
2158 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2159 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2160 if (!slowprod || slowprod->get_producer() == NULL) {
2161 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2162 slowprod->set("strobe", strobe);
2163 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2164 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2165 slowprod->set("id", producerid.toUtf8().constData());
2166 // copy producer props
2167 double ar = original->parent().get_double("force_aspect_ratio");
2168 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2169 double fps = original->parent().get_double("force_fps");
2170 if (fps != 0.0) slowprod->set("force_fps", fps);
2171 if (original->parent().get("force_progressive"))
2172 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2173 if (original->parent().get("force_tff"))
2174 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2175 int threads = original->parent().get_int("threads");
2176 if (threads != 0) slowprod->set("threads", threads);
2177 int ix = original->parent().get_int("video_index");
2178 if (ix != 0) slowprod->set("video_index", ix);
2179 int colorspace = original->parent().get_int("force_colorspace");
2180 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2181 int full_luma = original->parent().get_int("set.force_full_luma");
2182 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2183 m_slowmotionProducers.insert(url, slowprod);
2185 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2186 trackPlaylist.consolidate_blanks(0);
2188 GenTime duration = speedIndependantInfo.cropDuration / speed;
2189 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2191 // Check that the blank space is long enough for our new duration
2192 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2193 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2196 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2197 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2198 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2199 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2201 // move all effects to the correct producer
2202 mltPasteEffects(clip, cut);
2204 trackPlaylist.insert_at(startPos, cut, 1);
2207 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2208 newLength = trackPlaylist.clip_length(clipIndex);
2210 mlt_service_unlock(service.get_service());
2213 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2214 m_isBlocked = false;
2218 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2220 Mlt::Service service(m_mltProducer->parent().get_service());
2221 bool success = false;
2222 Mlt::Tractor tractor(service);
2223 Mlt::Producer trackProducer(tractor.track(track));
2224 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2225 Mlt::Service clipService(trackPlaylist.get_service());
2228 mlt_service_lock(service.get_service());
2230 Mlt::Filter *filter = clipService.filter(ct);
2232 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2233 if (clipService.detach(*filter) == 0) success = true;
2234 } else if (updateIndex) {
2235 // Adjust the other effects index
2236 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2239 filter = clipService.filter(ct);
2241 m_isBlocked = false;
2242 mlt_service_unlock(service.get_service());
2247 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2249 if (position < GenTime()) {
2250 // Remove track effect
2251 return mltRemoveTrackEffect(track, index, updateIndex);
2253 Mlt::Service service(m_mltProducer->parent().get_service());
2254 bool success = false;
2255 Mlt::Tractor tractor(service);
2256 Mlt::Producer trackProducer(tractor.track(track));
2257 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2259 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2260 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2262 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2266 Mlt::Service clipService(clip->get_service());
2267 int duration = clip->get_playtime();
2269 // Check if clip is visible in monitor
2270 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2271 if (diff < 0 || diff > duration) doRefresh = false;
2275 // if (tag.startsWith("ladspa")) tag = "ladspa";
2277 mlt_service_lock(service.get_service());
2279 Mlt::Filter *filter = clipService.filter(ct);
2281 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2282 if (clipService.detach(*filter) == 0) success = true;
2283 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2284 } else if (updateIndex) {
2285 // Adjust the other effects index
2286 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2289 filter = clipService.filter(ct);
2291 m_isBlocked = false;
2292 mlt_service_unlock(service.get_service());
2293 if (doRefresh) refresh();
2297 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2299 Mlt::Service service(m_mltProducer->parent().get_service());
2300 Mlt::Tractor tractor(service);
2301 Mlt::Producer trackProducer(tractor.track(track));
2302 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2303 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2304 return mltAddEffect(trackService, params, 15000, true);
2308 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2311 Mlt::Service service(m_mltProducer->parent().get_service());
2313 Mlt::Tractor tractor(service);
2314 Mlt::Producer trackProducer(tractor.track(track));
2315 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2317 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2318 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2323 Mlt::Service clipService(clip->get_service());
2324 int duration = clip->get_playtime();
2326 // Check if clip is visible in monitor
2327 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2328 if (diff < 0 || diff > duration) doRefresh = false;
2331 return mltAddEffect(clipService, params, duration, doRefresh);
2334 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2336 bool updateIndex = false;
2337 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2338 const QString region = params.paramValue("region");
2341 mlt_service_lock(service.get_service());
2343 Mlt::Filter *filter = service.filter(ct);
2345 if (filter->get_int("kdenlive_ix") == filter_ix) {
2346 // A filter at that position already existed, so we will increase all indexes later
2351 filter = service.filter(ct);
2354 if (params.paramValue("id") == "speed") {
2355 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2357 filter = service.filter(ct);
2359 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2360 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2363 filter = service.filter(ct);
2365 m_isBlocked = false;
2366 mlt_service_unlock(service.get_service());
2367 if (doRefresh) refresh();
2372 // temporarily remove all effects after insert point
2373 QList <Mlt::Filter *> filtersList;
2375 filter = service.filter(ct);
2377 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2378 filtersList.append(filter);
2379 service.detach(*filter);
2381 filter = service.filter(ct);
2385 QString tag = params.paramValue("tag");
2386 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2387 if (tag.startsWith("ladspa")) tag = "ladspa";
2388 char *filterTag = qstrdup(tag.toUtf8().constData());
2389 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2390 QHash<QString, QString>::Iterator it;
2391 QString kfr = params.paramValue("keyframes");
2393 if (!kfr.isEmpty()) {
2394 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2395 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2396 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2397 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2398 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2399 //double max = params.paramValue("max").toDouble();
2400 double min = params.paramValue("min").toDouble();
2401 double factor = params.paramValue("factor", "1").toDouble();
2402 params.removeParam("starttag");
2403 params.removeParam("endtag");
2404 params.removeParam("keyframes");
2405 params.removeParam("min");
2406 params.removeParam("max");
2407 params.removeParam("factor");
2409 // Special case, only one keyframe, means we want a constant value
2410 if (keyFrames.count() == 1) {
2411 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2412 if (filter && filter->is_valid()) {
2413 filter->set("kdenlive_id", filterId);
2414 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2415 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2416 for (int j = 0; j < params.count(); j++) {
2417 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2419 filter->set("in", x1);
2420 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2421 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2422 service.attach(*filter);
2424 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2425 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2426 if (filter && filter->is_valid()) {
2427 filter->set("kdenlive_id", filterId);
2428 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2429 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2430 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2431 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2432 if (x2 == -1) x2 = duration;
2434 for (int j = 0; j < params.count(); j++) {
2435 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2438 filter->set("in", x1);
2439 filter->set("out", x2);
2440 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2441 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2442 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2443 service.attach(*filter);
2450 Mlt::Filter *filter;
2452 if (!region.isEmpty()) {
2453 filter = new Mlt::Filter(*m_mltProfile, "region");
2454 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2455 if (filter && filter->is_valid()) {
2456 filter->set("kdenlive_id", filterId);
2457 if (!region.isEmpty()) {
2458 filter->set("resource", region.toUtf8().constData());
2459 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2460 filter->set("filter0", filterTag);
2461 prefix = "filter0.";
2462 params.removeParam("id");
2463 params.removeParam("region");
2464 params.removeParam("kdenlive_ix");
2467 kDebug() << "filter is NULL";
2468 m_isBlocked = false;
2469 mlt_service_unlock(service.get_service());
2472 params.removeParam("kdenlive_id");
2474 for (int j = 0; j < params.count(); j++) {
2475 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2479 QString effectArgs = params.paramValue("id").section('_', 1);
2481 params.removeParam("id");
2482 params.removeParam("kdenlive_ix");
2483 params.removeParam("tag");
2484 params.removeParam("disable");
2485 params.removeParam("region");
2487 for (int j = 0; j < params.count(); j++) {
2488 effectArgs.append(' ' + params.at(j).value());
2490 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2491 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2494 if (params.paramValue("id") == "pan_zoom") {
2495 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2498 // attach filter to the clip
2499 service.attach(*filter);
2504 // re-add following filters
2505 for (int i = 0; i < filtersList.count(); i++) {
2506 Mlt::Filter *filter = filtersList.at(i);
2508 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2509 service.attach(*filter);
2511 m_isBlocked = false;
2512 mlt_service_unlock(service.get_service());
2513 if (doRefresh) refresh();
2517 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2519 Mlt::Service service(m_mltProducer->parent().get_service());
2520 Mlt::Tractor tractor(service);
2521 Mlt::Producer trackProducer(tractor.track(track));
2522 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2523 Mlt::Service clipService(trackPlaylist.get_service());
2526 QString index = params.paramValue("kdenlive_ix");
2527 QString tag = params.paramValue("tag");
2529 Mlt::Filter *filter = clipService.filter(ct);
2531 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2535 filter = clipService.filter(ct);
2539 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2540 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2542 bool success = false;//mltAddTrackEffect(track, params);
2543 m_isBlocked = false;
2547 QString ser = filter->get("mlt_service");
2548 if (ser == "region") prefix = "filter0.";
2549 mlt_service_lock(service.get_service());
2550 for (int j = 0; j < params.count(); j++) {
2551 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2553 mlt_service_unlock(service.get_service());
2555 m_isBlocked = false;
2561 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2563 QString index = params.paramValue("kdenlive_ix");
2564 QString tag = params.paramValue("tag");
2566 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2567 // This is a keyframe effect, to edit it, we remove it and re-add it.
2568 bool success = mltRemoveEffect(track, position, index, false);
2569 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2570 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2571 else success = mltAddEffect(track, position, params);
2572 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2575 if (position < GenTime()) {
2576 return mltEditTrackEffect(track, params);
2579 Mlt::Service service(m_mltProducer->parent().get_service());
2580 Mlt::Tractor tractor(service);
2581 Mlt::Producer trackProducer(tractor.track(track));
2582 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2584 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2585 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2587 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2591 Mlt::Service clipService(clip->get_service());
2592 int duration = clip->get_playtime();
2593 bool doRefresh = true;
2594 // Check if clip is visible in monitor
2595 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2596 if (diff < 0 || diff > duration) doRefresh = false;
2600 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2601 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2603 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2605 filter = clipService.filter(ct);
2607 kDebug() << "++++++++++++++++++++++++++";
2609 filter = clipService.filter(ct); */
2611 Mlt::Filter *filter = clipService.filter(ct);
2613 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2617 filter = clipService.filter(ct);
2621 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2622 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2624 bool success = mltAddEffect(track, position, params);
2625 m_isBlocked = false;
2629 QString ser = filter->get("mlt_service");
2630 if (ser == "region") prefix = "filter0.";
2631 mlt_service_lock(service.get_service());
2632 for (int j = 0; j < params.count(); j++) {
2633 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2635 mlt_service_unlock(service.get_service());
2637 m_isBlocked = false;
2638 if (doRefresh) refresh();
2642 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2644 Mlt::Service service(m_mltProducer->parent().get_service());
2645 Mlt::Tractor tractor(service);
2646 Mlt::Producer trackProducer(tractor.track(track));
2647 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2649 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2650 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2652 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2656 Mlt::Service clipService(clip->get_service());
2657 int duration = clip->get_playtime();
2658 bool doRefresh = true;
2659 // Check if clip is visible in monitor
2660 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2661 if (diff < 0 || diff > duration) doRefresh = false;
2666 Mlt::Filter *filter = clipService.filter(ct);
2668 int pos = filter->get_int("kdenlive_ix");
2669 if (pos == oldPos) {
2670 filter->set("kdenlive_ix", newPos);
2672 filter = clipService.filter(ct);
2675 m_isBlocked = false;
2676 if (doRefresh) refresh();
2679 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2681 if (position < GenTime()) {
2682 mltMoveTrackEffect(track, oldPos, newPos);
2685 Mlt::Service service(m_mltProducer->parent().get_service());
2686 Mlt::Tractor tractor(service);
2687 Mlt::Producer trackProducer(tractor.track(track));
2688 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2690 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2691 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2693 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2697 Mlt::Service clipService(clip->get_service());
2698 int duration = clip->get_playtime();
2699 bool doRefresh = true;
2700 // Check if clip is visible in monitor
2701 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2702 if (diff < 0 || diff > duration) doRefresh = false;
2707 QList <Mlt::Filter *> filtersList;
2708 Mlt::Filter *filter = clipService.filter(ct);
2710 if (newPos > oldPos) {
2712 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2713 filter->set("kdenlive_ix", newPos);
2714 filtersList.append(filter);
2715 clipService.detach(*filter);
2716 filter = clipService.filter(ct);
2717 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2718 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2720 filter = clipService.filter(ct);
2724 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2725 filtersList.append(filter);
2726 clipService.detach(*filter);
2728 filter = clipService.filter(ct);
2732 if (filter->get_int("kdenlive_ix") == oldPos) {
2733 filter->set("kdenlive_ix", newPos);
2734 filtersList.append(filter);
2735 clipService.detach(*filter);
2737 filter = clipService.filter(ct);
2741 filter = clipService.filter(ct);
2743 int pos = filter->get_int("kdenlive_ix");
2744 if (pos >= newPos) {
2745 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2746 filtersList.append(filter);
2747 clipService.detach(*filter);
2749 filter = clipService.filter(ct);
2753 for (int i = 0; i < filtersList.count(); i++) {
2754 clipService.attach(*(filtersList.at(i)));
2757 m_isBlocked = false;
2758 if (doRefresh) refresh();
2761 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2763 Mlt::Service service(m_mltProducer->parent().get_service());
2764 Mlt::Tractor tractor(service);
2765 Mlt::Producer trackProducer(tractor.track(track));
2766 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2768 Mlt::Service clipService(trackPlaylist.get_service());
2772 QList <Mlt::Filter *> filtersList;
2773 Mlt::Filter *filter = clipService.filter(ct);
2775 if (newPos > oldPos) {
2777 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2778 filter->set("kdenlive_ix", newPos);
2779 filtersList.append(filter);
2780 clipService.detach(*filter);
2781 filter = clipService.filter(ct);
2782 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2783 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2785 filter = clipService.filter(ct);
2789 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2790 filtersList.append(filter);
2791 clipService.detach(*filter);
2793 filter = clipService.filter(ct);
2797 if (filter->get_int("kdenlive_ix") == oldPos) {
2798 filter->set("kdenlive_ix", newPos);
2799 filtersList.append(filter);
2800 clipService.detach(*filter);
2802 filter = clipService.filter(ct);
2806 filter = clipService.filter(ct);
2808 int pos = filter->get_int("kdenlive_ix");
2809 if (pos >= newPos) {
2810 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2811 filtersList.append(filter);
2812 clipService.detach(*filter);
2814 filter = clipService.filter(ct);
2818 for (int i = 0; i < filtersList.count(); i++) {
2819 clipService.attach(*(filtersList.at(i)));
2821 m_isBlocked = false;
2825 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2828 Mlt::Service service(m_mltProducer->parent().get_service());
2829 Mlt::Tractor tractor(service);
2830 Mlt::Producer trackProducer(tractor.track(info.track));
2831 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2833 /* // Display playlist info
2834 kDebug()<<"//////////// BEFORE RESIZE";
2835 for (int i = 0; i < trackPlaylist.count(); i++) {
2836 int blankStart = trackPlaylist.clip_start(i);
2837 int blankDuration = trackPlaylist.clip_length(i) - 1;
2839 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2840 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2843 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2844 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2845 m_isBlocked = false;
2848 mlt_service_lock(service.get_service());
2849 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2850 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2851 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2853 int previousStart = clip->get_in();
2854 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2855 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2857 int currentOut = newDuration + previousStart;
2858 if (currentOut > clip->get_length()) {
2859 clip->parent().set("length", currentOut + 1);
2860 clip->parent().set("out", currentOut);
2861 clip->set("length", currentOut + 1);
2864 /*if (newDuration > clip->get_out()) {
2865 clip->parent().set_in_and_out(0, newDuration + 1);
2866 clip->set_in_and_out(0, newDuration + 1);
2869 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2870 trackPlaylist.consolidate_blanks(0);
2871 // skip to next clip
2873 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2875 // clip was made longer, trim next blank if there is one.
2876 if (clipIndex < trackPlaylist.count()) {
2877 // If this is not the last clip in playlist
2878 if (trackPlaylist.is_blank(clipIndex)) {
2879 int blankStart = trackPlaylist.clip_start(clipIndex);
2880 int blankDuration = trackPlaylist.clip_length(clipIndex);
2881 if (diff > blankDuration) {
2882 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2884 if (diff - blankDuration == 0) {
2885 trackPlaylist.remove(clipIndex);
2886 } else trackPlaylist.remove_region(blankStart, diff);
2888 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2891 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2892 trackPlaylist.consolidate_blanks(0);
2893 mlt_service_unlock(service.get_service());
2895 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2896 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2897 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2898 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2899 ItemInfo transpinfo;
2900 transpinfo.startPos = info.startPos;
2901 transpinfo.endPos = info.startPos + clipDuration;
2902 transpinfo.track = info.track;
2903 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2905 m_isBlocked = false;
2906 m_mltConsumer->set("refresh", 1);
2910 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2912 Mlt::Service service(m_mltProducer->parent().get_service());
2913 Mlt::Tractor tractor(service);
2914 Mlt::Producer trackProducer(tractor.track(track));
2917 if (blind) trackProducer.set("hide", 3);
2918 else trackProducer.set("hide", 2);
2920 trackProducer.set("hide", 1);
2922 trackProducer.set("hide", 0);
2924 tractor.multitrack()->refresh();
2930 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2932 Mlt::Service service(m_mltProducer->parent().get_service());
2933 int frameOffset = (int) diff.frames(m_fps);
2934 Mlt::Tractor tractor(service);
2935 Mlt::Producer trackProducer(tractor.track(info.track));
2936 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2937 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2938 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2941 mlt_service_lock(service.get_service());
2942 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2943 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2945 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2946 mlt_service_unlock(service.get_service());
2949 int previousStart = clip->get_in();
2950 int previousOut = clip->get_out();
2953 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2954 m_isBlocked = false;
2955 mlt_service_unlock(service.get_service());
2956 m_mltConsumer->set("refresh", 1);
2960 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2962 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2963 Mlt::Service service(m_mltProducer->parent().get_service());
2964 int moveFrame = (int) diff.frames(m_fps);
2965 Mlt::Tractor tractor(service);
2966 Mlt::Producer trackProducer(tractor.track(info.track));
2967 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2968 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2969 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2972 mlt_service_lock(service.get_service());
2973 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2974 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2975 if (clip == NULL || clip->is_blank()) {
2976 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2977 mlt_service_unlock(service.get_service());
2980 int previousStart = clip->get_in();
2981 int previousOut = clip->get_out();
2984 previousStart += moveFrame;
2986 int length = previousOut + 1;
2987 if (length > clip->get_length()) {
2988 clip->parent().set("length", length + 1);
2989 clip->parent().set("out", length);
2990 clip->set("length", length + 1);
2994 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
2995 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
2996 if (moveFrame > 0) {
2997 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2999 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3000 int blankIndex = clipIndex - 1;
3001 int blankLength = trackPlaylist.clip_length(blankIndex);
3002 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3003 if (! trackPlaylist.is_blank(blankIndex)) {
3004 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3006 if (blankLength + moveFrame == 0)
3007 trackPlaylist.remove(blankIndex);
3009 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3011 trackPlaylist.consolidate_blanks(0);
3012 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3013 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3014 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3015 ItemInfo transpinfo;
3016 transpinfo.startPos = info.startPos + diff;
3017 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3018 transpinfo.track = info.track;
3019 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3021 m_isBlocked = false;
3022 //m_mltConsumer->set("refresh", 1);
3023 mlt_service_unlock(service.get_service());
3024 m_mltConsumer->set("refresh", 1);
3028 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3030 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3034 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3036 if (prod == NULL || !prod->is_valid()) {
3037 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3040 kDebug() << "NEW PROD ID: " << prod->get("id");
3042 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3043 Mlt::Service service(m_mltProducer->parent().get_service());
3044 if (service.type() != tractor_type) {
3045 kWarning() << "// TRACTOR PROBLEM";
3048 mlt_service_lock(service.get_service());
3049 Mlt::Tractor tractor(service);
3050 Mlt::Producer trackProducer(tractor.track(track));
3051 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3052 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3053 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3054 if (clipProducer == NULL || clipProducer->is_blank()) {
3055 kDebug() << "// ERROR UPDATING CLIP PROD";
3056 delete clipProducer;
3057 mlt_service_unlock(service.get_service());
3061 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3062 if (!clip || !clip->is_valid()) {
3063 if (clip) delete clip;
3064 delete clipProducer;
3065 mlt_service_unlock(service.get_service());
3069 // move all effects to the correct producer
3070 mltPasteEffects(clipProducer, clip);
3071 trackPlaylist.insert_at(pos, clip, 1);
3073 delete clipProducer;
3074 mlt_service_unlock(service.get_service());
3079 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3083 Mlt::Service service(m_mltProducer->parent().get_service());
3084 if (service.type() != tractor_type) {
3085 kWarning() << "// TRACTOR PROBLEM";
3089 Mlt::Tractor tractor(service);
3090 mlt_service_lock(service.get_service());
3091 Mlt::Producer trackProducer(tractor.track(startTrack));
3092 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3093 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3094 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3095 bool checkLength = false;
3096 if (endTrack == startTrack) {
3097 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3098 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3099 // error, destination is not empty
3101 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3102 delete clipProducer;
3104 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3105 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3106 mlt_service_unlock(service.get_service());
3110 trackPlaylist.consolidate_blanks(0);
3112 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3113 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3114 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3116 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3117 trackPlaylist.consolidate_blanks(1);
3118 delete clipProducer;
3119 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3120 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3122 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3124 //mlt_service_unlock(service.get_service());
3126 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3127 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3128 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3129 // error, destination is not empty
3130 mlt_service_unlock(service.get_service());
3134 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3135 if (!clipProducer || clipProducer->is_blank()) {
3136 // error, destination is not empty
3137 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3138 if (clipProducer) delete clipProducer;
3139 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3140 mlt_service_unlock(service.get_service());
3144 trackPlaylist.consolidate_blanks(0);
3145 destTrackPlaylist.consolidate_blanks(1);
3146 Mlt::Producer *clip;
3147 // check if we are moving a slowmotion producer
3148 QString serv = clipProducer->parent().get("mlt_service");
3149 QString currentid = clipProducer->parent().get("id");
3150 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3151 clip = clipProducer;
3154 // Special case: prod is null when using placeholder clips.
3155 // in that case, use the producer existing in playlist. Note that
3156 // it will bypass the one producer per track logic and might cause
3157 // Sound cracks if clip is moved so that it overlaps another copy of itself
3158 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3159 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3162 // move all effects to the correct producer
3163 mltPasteEffects(clipProducer, clip);
3166 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3167 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3168 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3171 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3173 if (clip == clipProducer) {
3178 delete clipProducer;
3180 destTrackPlaylist.consolidate_blanks(0);
3181 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3182 kDebug() << "//////// moving clip transparency";
3183 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3185 if (clipIndex > trackPlaylist.count()) checkLength = true;
3186 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3189 mlt_service_unlock(service.get_service());
3190 if (checkLength) mltCheckLength(&tractor);
3193 //m_mltConsumer->set("refresh", 1);
3198 QList <int> Render::checkTrackSequence(int track)
3201 Mlt::Service service(m_mltProducer->parent().get_service());
3202 if (service.type() != tractor_type) {
3203 kWarning() << "// TRACTOR PROBLEM";
3206 Mlt::Tractor tractor(service);
3207 mlt_service_lock(service.get_service());
3208 Mlt::Producer trackProducer(tractor.track(track));
3209 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3210 int clipNb = trackPlaylist.count();
3211 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3212 for (int i = 0; i < clipNb; i++) {
3213 Mlt::Producer *c = trackPlaylist.get_clip(i);
3214 int pos = trackPlaylist.clip_start(i);
3215 if (!list.contains(pos)) list.append(pos);
3216 pos += c->get_playtime();
3217 if (!list.contains(pos)) list.append(pos);
3223 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3225 int new_in = (int)newIn.frames(m_fps);
3226 int new_out = (int)newOut.frames(m_fps) - 1;
3227 if (new_in >= new_out) return false;
3228 int old_in = (int)oldIn.frames(m_fps);
3229 int old_out = (int)oldOut.frames(m_fps) - 1;
3231 Mlt::Service service(m_mltProducer->parent().get_service());
3232 Mlt::Tractor tractor(service);
3233 Mlt::Field *field = tractor.field();
3235 bool doRefresh = true;
3236 // Check if clip is visible in monitor
3237 int diff = old_out - m_mltProducer->position();
3238 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3240 diff = new_out - m_mltProducer->position();
3241 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3245 mlt_service_lock(service.get_service());
3247 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3248 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3249 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3250 QString resource = mlt_properties_get(properties, "mlt_service");
3251 int old_pos = (int)(old_in + old_out) / 2;
3254 while (mlt_type == "transition") {
3255 Mlt::Transition transition((mlt_transition) nextservice);
3256 int currentTrack = transition.get_b_track();
3257 int currentIn = (int) transition.get_in();
3258 int currentOut = (int) transition.get_out();
3260 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3262 if (newTrack - startTrack != 0) {
3263 Mlt::Properties trans_props(transition.get_properties());
3264 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3265 Mlt::Properties new_trans_props(new_transition.get_properties());
3266 new_trans_props.inherit(trans_props);
3267 new_transition.set_in_and_out(new_in, new_out);
3268 field->disconnect_service(transition);
3269 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3270 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3271 } else transition.set_in_and_out(new_in, new_out);
3274 nextservice = mlt_service_producer(nextservice);
3275 if (nextservice == NULL) break;
3276 properties = MLT_SERVICE_PROPERTIES(nextservice);
3277 mlt_type = mlt_properties_get(properties, "mlt_type");
3278 resource = mlt_properties_get(properties, "mlt_service");
3280 mlt_service_unlock(service.get_service());
3282 if (doRefresh) refresh();
3283 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3288 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3290 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3291 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3292 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3293 QString resource = mlt_properties_get(properties, "mlt_service");
3294 QList <Mlt::Transition *> trList;
3296 while (mlt_type == "transition") {
3297 Mlt::Transition transition((mlt_transition) nextservice);
3298 int aTrack = transition.get_a_track();
3299 int bTrack = transition.get_b_track();
3300 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3301 Mlt::Properties trans_props(transition.get_properties());
3302 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3303 Mlt::Properties new_trans_props(cp->get_properties());
3304 new_trans_props.inherit(trans_props);
3306 field->disconnect_service(transition);
3308 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3310 nextservice = mlt_service_producer(nextservice);
3311 if (nextservice == NULL) break;
3312 properties = MLT_SERVICE_PROPERTIES(nextservice);
3313 mlt_type = mlt_properties_get(properties, "mlt_type");
3314 resource = mlt_properties_get(properties, "mlt_service");
3317 field->plant_transition(tr, a_track, b_track);
3319 // re-add upper transitions
3320 for (int i = 0; i < trList.count(); i++) {
3321 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3322 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3326 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3328 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3330 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3331 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3334 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3337 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3339 mlt_service serv = m_mltProducer->parent().get_service();
3340 mlt_service_lock(serv);
3343 mlt_service nextservice = mlt_service_get_producer(serv);
3344 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3345 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3346 QString resource = mlt_properties_get(properties, "mlt_service");
3347 int in_pos = (int) in.frames(m_fps);
3348 int out_pos = (int) out.frames(m_fps) - 1;
3350 while (mlt_type == "transition") {
3351 mlt_transition tr = (mlt_transition) nextservice;
3352 int currentTrack = mlt_transition_get_b_track(tr);
3353 int currentBTrack = mlt_transition_get_a_track(tr);
3354 int currentIn = (int) mlt_transition_get_in(tr);
3355 int currentOut = (int) mlt_transition_get_out(tr);
3357 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3359 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3360 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3361 QMap<QString, QString>::Iterator it;
3363 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3365 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3366 if (currentId != xml.attribute("id")) {
3367 // The transition ID is not the same, so reset all properties
3368 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3369 // Cleanup previous properties
3370 QStringList permanentProps;
3371 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3372 permanentProps << "out" << "a_track" << "b_track";
3373 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3374 QString propName = mlt_properties_get_name(transproperties, i);
3375 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3376 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3381 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3382 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3384 if (currentBTrack != a_track) {
3385 mlt_properties_set_int(transproperties, "a_track", a_track);
3387 for (it = map.begin(); it != map.end(); ++it) {
3389 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3390 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3391 //filter->set("kdenlive_id", id);
3395 nextservice = mlt_service_producer(nextservice);
3396 if (nextservice == NULL) break;
3397 properties = MLT_SERVICE_PROPERTIES(nextservice);
3398 mlt_type = mlt_properties_get(properties, "mlt_type");
3399 resource = mlt_properties_get(properties, "mlt_service");
3401 mlt_service_unlock(serv);
3404 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3407 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3409 mlt_service serv = m_mltProducer->parent().get_service();
3411 mlt_service_lock(serv);
3413 Mlt::Service service(serv);
3414 Mlt::Tractor tractor(service);
3415 Mlt::Field *field = tractor.field();
3417 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3419 mlt_service nextservice = mlt_service_get_producer(serv);
3420 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3421 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3422 QString resource = mlt_properties_get(properties, "mlt_service");
3424 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3425 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3427 while (mlt_type == "transition") {
3428 mlt_transition tr = (mlt_transition) nextservice;
3429 int currentTrack = mlt_transition_get_b_track(tr);
3430 int currentIn = (int) mlt_transition_get_in(tr);
3431 int currentOut = (int) mlt_transition_get_out(tr);
3432 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3434 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3435 mlt_field_disconnect_service(field->get_field(), nextservice);
3438 nextservice = mlt_service_producer(nextservice);
3439 if (nextservice == NULL) break;
3440 properties = MLT_SERVICE_PROPERTIES(nextservice);
3441 mlt_type = mlt_properties_get(properties, "mlt_type");
3442 resource = mlt_properties_get(properties, "mlt_service");
3444 mlt_service_unlock(serv);
3447 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3450 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3452 QDomNodeList attribs = xml.elementsByTagName("parameter");
3453 QMap<QString, QString> map;
3454 for (int i = 0; i < attribs.count(); i++) {
3455 QDomElement e = attribs.item(i).toElement();
3456 QString name = e.attribute("name");
3457 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3458 map[name] = e.attribute("default");
3459 if (!e.attribute("value").isEmpty()) {
3460 map[name] = e.attribute("value");
3462 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3463 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3464 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3467 if (e.attribute("namedesc").contains(';')) {
3468 QString format = e.attribute("format");
3469 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3470 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3472 QTextStream txtNeu(&neu);
3473 if (values.size() > 0)
3474 txtNeu << (int)values[0].toDouble();
3476 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3477 txtNeu << separators[i];
3478 txtNeu << (int)(values[i+1].toDouble());
3480 if (i < separators.size())
3481 txtNeu << separators[i];
3482 map[e.attribute("name")] = neu;
3489 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3491 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3492 Mlt::Service service(m_mltProducer->parent().get_service());
3493 Mlt::Tractor tractor(service);
3494 Mlt::Field *field = tractor.field();
3496 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3497 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3498 transition->set("transparency", id);
3499 transition->set("fill", 1);
3500 transition->set("internal_added", 237);
3501 field->plant_transition(*transition, transitiontrack, info.track);
3505 void Render::mltDeleteTransparency(int pos, int track, int id)
3507 Mlt::Service service(m_mltProducer->parent().get_service());
3508 Mlt::Tractor tractor(service);
3509 Mlt::Field *field = tractor.field();
3511 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3512 mlt_service serv = m_mltProducer->parent().get_service();
3514 mlt_service nextservice = mlt_service_get_producer(serv);
3515 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3516 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3517 QString resource = mlt_properties_get(properties, "mlt_service");
3519 while (mlt_type == "transition") {
3520 mlt_transition tr = (mlt_transition) nextservice;
3521 int currentTrack = mlt_transition_get_b_track(tr);
3522 int currentIn = (int) mlt_transition_get_in(tr);
3523 int currentOut = (int) mlt_transition_get_out(tr);
3524 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3525 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3527 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3528 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3529 mlt_field_disconnect_service(field->get_field(), nextservice);
3532 nextservice = mlt_service_producer(nextservice);
3533 if (nextservice == NULL) break;
3534 properties = MLT_SERVICE_PROPERTIES(nextservice);
3535 mlt_type = mlt_properties_get(properties, "mlt_type");
3536 resource = mlt_properties_get(properties, "mlt_service");
3538 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3541 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3543 Mlt::Service service(m_mltProducer->parent().get_service());
3544 Mlt::Tractor tractor(service);
3546 mlt_service_lock(service.get_service());
3547 m_mltConsumer->set("refresh", 0);
3550 mlt_service serv = m_mltProducer->parent().get_service();
3551 mlt_service nextservice = mlt_service_get_producer(serv);
3552 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3553 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3554 QString resource = mlt_properties_get(properties, "mlt_service");
3555 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3556 while (mlt_type == "transition") {
3557 mlt_transition tr = (mlt_transition) nextservice;
3558 int currentTrack = mlt_transition_get_b_track(tr);
3559 int currentIn = (int) mlt_transition_get_in(tr);
3560 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3561 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3562 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3563 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3564 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3565 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3568 nextservice = mlt_service_producer(nextservice);
3569 if (nextservice == NULL) break;
3570 properties = MLT_SERVICE_PROPERTIES(nextservice);
3571 mlt_type = mlt_properties_get(properties, "mlt_type");
3572 resource = mlt_properties_get(properties, "mlt_service");
3574 mlt_service_unlock(service.get_service());
3576 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3580 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3582 Mlt::Service service(m_mltProducer->parent().get_service());
3583 Mlt::Tractor tractor(service);
3585 mlt_service_lock(service.get_service());
3586 m_mltConsumer->set("refresh", 0);
3589 mlt_service serv = m_mltProducer->parent().get_service();
3590 mlt_service nextservice = mlt_service_get_producer(serv);
3591 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3592 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3593 QString resource = mlt_properties_get(properties, "mlt_service");
3595 while (mlt_type == "transition") {
3596 mlt_transition tr = (mlt_transition) nextservice;
3597 int currentTrack = mlt_transition_get_b_track(tr);
3598 int currentaTrack = mlt_transition_get_a_track(tr);
3599 int currentIn = (int) mlt_transition_get_in(tr);
3600 int currentOut = (int) mlt_transition_get_out(tr);
3601 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3602 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3603 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3604 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3605 kDebug() << "//////MOVING";
3606 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3607 if (endTrack != startTrack) {
3608 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3609 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3610 mlt_properties_set_int(properties, "b_track", endTrack);
3614 nextservice = mlt_service_producer(nextservice);
3615 if (nextservice == NULL) break;
3616 properties = MLT_SERVICE_PROPERTIES(nextservice);
3617 mlt_type = mlt_properties_get(properties, "mlt_type");
3618 resource = mlt_properties_get(properties, "mlt_service");
3621 mlt_service_unlock(service.get_service());
3622 m_mltConsumer->set("refresh", 1);
3626 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3628 if (in >= out) return false;
3629 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3630 Mlt::Service service(m_mltProducer->parent().get_service());
3632 Mlt::Tractor tractor(service);
3633 Mlt::Field *field = tractor.field();
3635 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3636 if (out != GenTime())
3637 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3639 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3640 QMap<QString, QString>::Iterator it;
3642 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3643 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3644 if (xml.hasAttribute("id"))
3645 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3647 for (it = args.begin(); it != args.end(); ++it) {
3649 if (!it.value().isEmpty())
3650 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3651 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3653 // attach transition
3654 mltPlantTransition(field, *transition, a_track, b_track);
3655 // field->plant_transition(*transition, a_track, b_track);
3656 if (do_refresh) refresh();
3660 void Render::mltSavePlaylist()
3662 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3663 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3664 fileConsumer.set("resource", "/tmp/playlist.mlt");
3666 Mlt::Service service(m_mltProducer->get_service());
3668 fileConsumer.connect(service);
3669 fileConsumer.start();
3672 const QList <Mlt::Producer *> Render::producersList()
3674 QList <Mlt::Producer *> prods;
3675 if (m_mltProducer == NULL) return prods;
3676 Mlt::Service service(m_mltProducer->parent().get_service());
3677 if (service.type() != tractor_type) return prods;
3678 Mlt::Tractor tractor(service);
3681 int trackNb = tractor.count();
3682 for (int t = 1; t < trackNb; t++) {
3683 Mlt::Producer *tt = tractor.track(t);
3684 Mlt::Producer trackProducer(tt);
3686 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3687 int clipNb = trackPlaylist.count();
3688 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3689 for (int i = 0; i < clipNb; i++) {
3690 Mlt::Producer *c = trackPlaylist.get_clip(i);
3691 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3693 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3694 ids.append(nprod->get("id"));
3695 prods.append(nprod);
3696 } else delete nprod;
3704 void Render::fillSlowMotionProducers()
3706 if (m_mltProducer == NULL) return;
3707 Mlt::Service service(m_mltProducer->parent().get_service());
3708 if (service.type() != tractor_type) return;
3710 Mlt::Tractor tractor(service);
3712 int trackNb = tractor.count();
3713 for (int t = 1; t < trackNb; t++) {
3714 Mlt::Producer *tt = tractor.track(t);
3715 Mlt::Producer trackProducer(tt);
3717 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3718 int clipNb = trackPlaylist.count();
3719 for (int i = 0; i < clipNb; i++) {
3720 Mlt::Producer *c = trackPlaylist.get_clip(i);
3721 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3723 QString id = nprod->get("id");
3724 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3725 // this is a slowmotion producer, add it to the list
3726 QString url = QString::fromUtf8(nprod->get("resource"));
3727 int strobe = nprod->get_int("strobe");
3728 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3729 if (!m_slowmotionProducers.contains(url)) {
3730 m_slowmotionProducers.insert(url, nprod);
3732 } else delete nprod;
3739 void Render::mltInsertTrack(int ix, bool videoTrack)
3744 Mlt::Service service(m_mltProducer->parent().get_service());
3745 mlt_service_lock(service.get_service());
3746 if (service.type() != tractor_type) {
3747 kWarning() << "// TRACTOR PROBLEM";
3751 Mlt::Tractor tractor(service);
3753 Mlt::Playlist playlist;
3754 int ct = tractor.count();
3756 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3762 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3763 tractor.set_track(playlist, pos);
3764 Mlt::Producer newProd(tractor.track(pos));
3765 if (!videoTrack) newProd.set("hide", 1);
3767 for (; pos <= ct; pos++) {
3768 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3769 tractor.set_track(*prodToMove, pos);
3770 prodToMove = prodToMove2;
3773 tractor.set_track(playlist, ix);
3774 Mlt::Producer newProd(tractor.track(ix));
3775 if (!videoTrack) newProd.set("hide", 1);
3779 mlt_service serv = m_mltProducer->parent().get_service();
3780 mlt_service nextservice = mlt_service_get_producer(serv);
3781 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3782 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3783 QString resource = mlt_properties_get(properties, "mlt_service");
3785 while (mlt_type == "transition") {
3786 if (resource != "mix") {
3787 mlt_transition tr = (mlt_transition) nextservice;
3788 int currentTrack = mlt_transition_get_b_track(tr);
3789 int currentaTrack = mlt_transition_get_a_track(tr);
3790 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3792 if (currentTrack >= ix) {
3793 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3794 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3797 nextservice = mlt_service_producer(nextservice);
3798 if (nextservice == NULL) break;
3799 properties = MLT_SERVICE_PROPERTIES(nextservice);
3800 mlt_type = mlt_properties_get(properties, "mlt_type");
3801 resource = mlt_properties_get(properties, "mlt_service");
3804 // Add audio mix transition to last track
3805 Mlt::Field *field = tractor.field();
3806 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3807 transition->set("a_track", 1);
3808 transition->set("b_track", ct);
3809 transition->set("always_active", 1);
3810 transition->set("internal_added", 237);
3811 transition->set("combine", 1);
3812 field->plant_transition(*transition, 1, ct);
3813 //mlt_service_unlock(m_mltConsumer->get_service());
3814 mlt_service_unlock(service.get_service());
3815 //tractor.multitrack()->refresh();
3816 //tractor.refresh();
3818 blockSignals(false);
3822 void Render::mltDeleteTrack(int ix)
3825 doc.setContent(sceneList(), false);
3826 int tracksCount = doc.elementsByTagName("track").count() - 1;
3827 QDomNode track = doc.elementsByTagName("track").at(ix);
3828 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3829 QDomNodeList transitions = doc.elementsByTagName("transition");
3830 for (int i = 0; i < transitions.count(); i++) {
3831 QDomElement e = transitions.at(i).toElement();
3832 QDomNodeList props = e.elementsByTagName("property");
3833 QMap <QString, QString> mappedProps;
3834 for (int j = 0; j < props.count(); j++) {
3835 QDomElement f = props.at(j).toElement();
3836 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3838 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3839 tractor.removeChild(transitions.at(i));
3841 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3842 // Transition needs to be moved
3843 int a_track = mappedProps.value("a_track").toInt();
3844 int b_track = mappedProps.value("b_track").toInt();
3845 if (a_track > 0 && a_track >= ix) a_track --;
3846 if (b_track == ix) {
3847 // transition was on the deleted track, so remove it
3848 tractor.removeChild(transitions.at(i));
3852 if (b_track > 0 && b_track > ix) b_track --;
3853 for (int j = 0; j < props.count(); j++) {
3854 QDomElement f = props.at(j).toElement();
3855 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3856 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3861 tractor.removeChild(track);
3862 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3863 setSceneList(doc.toString(), m_framePosition);
3865 /* if (m_mltProducer != NULL) {
3866 Mlt::Producer parentProd(m_mltProducer->parent());
3867 if (parentProd.get_producer() != NULL) {
3868 Mlt::Service service(parentProd.get_service());
3869 if (service.type() == tractor_type) {
3870 Mlt::Tractor tractor(service);
3871 mltCheckLength(&tractor);
3878 void Render::updatePreviewSettings()
3880 kDebug() << "////// RESTARTING CONSUMER";
3881 if (!m_mltConsumer || !m_mltProducer) return;
3882 if (m_mltProducer->get_playtime() == 0) return;
3883 Mlt::Service service(m_mltProducer->parent().get_service());
3884 if (service.type() != tractor_type) return;
3886 //m_mltConsumer->set("refresh", 0);
3887 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3888 m_mltConsumer->purge();
3889 QString scene = sceneList();
3891 if (m_mltProducer) {
3892 pos = m_mltProducer->position();
3895 setSceneList(scene, pos);
3899 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3901 // Update all frame positions to the new fps value
3902 //WARNING: there are probably some effects or other that hold a frame value
3903 // as parameter and will also need to be updated here!
3905 doc.setContent(scene);
3907 double factor = new_fps / current_fps;
3908 QDomNodeList producers = doc.elementsByTagName("producer");
3909 for (int i = 0; i < producers.count(); i++) {
3910 QDomElement prod = producers.at(i).toElement();
3911 prod.removeAttribute("in");
3912 prod.removeAttribute("out");
3914 QDomNodeList props = prod.childNodes();
3915 for (int j = 0; j < props.count(); j++) {
3916 QDomElement param = props.at(j).toElement();
3917 QString paramName = param.attribute("name");
3918 if (paramName.startsWith("meta.") || paramName == "length") {
3919 prod.removeChild(props.at(j));
3925 QDomNodeList entries = doc.elementsByTagName("entry");
3926 for (int i = 0; i < entries.count(); i++) {
3927 QDomElement entry = entries.at(i).toElement();
3928 int in = entry.attribute("in").toInt();
3929 int out = entry.attribute("out").toInt();
3930 in = factor * in + 0.5;
3931 out = factor * out + 0.5;
3932 entry.setAttribute("in", in);
3933 entry.setAttribute("out", out);
3936 QDomNodeList blanks = doc.elementsByTagName("blank");
3937 for (int i = 0; i < blanks.count(); i++) {
3938 QDomElement blank = blanks.at(i).toElement();
3939 int length = blank.attribute("length").toInt();
3940 length = factor * length + 0.5;
3941 blank.setAttribute("length", QString::number(length));
3944 QDomNodeList filters = doc.elementsByTagName("filter");
3945 for (int i = 0; i < filters.count(); i++) {
3946 QDomElement filter = filters.at(i).toElement();
3947 int in = filter.attribute("in").toInt();
3948 int out = filter.attribute("out").toInt();
3949 in = factor * in + 0.5;
3950 out = factor * out + 0.5;
3951 filter.setAttribute("in", in);
3952 filter.setAttribute("out", out);
3955 QDomNodeList transitions = doc.elementsByTagName("transition");
3956 for (int i = 0; i < transitions.count(); i++) {
3957 QDomElement transition = transitions.at(i).toElement();
3958 int in = transition.attribute("in").toInt();
3959 int out = transition.attribute("out").toInt();
3960 in = factor * in + 0.5;
3961 out = factor * out + 0.5;
3962 transition.setAttribute("in", in);
3963 transition.setAttribute("out", out);
3964 QDomNodeList props = transition.childNodes();
3965 for (int j = 0; j < props.count(); j++) {
3966 QDomElement param = props.at(j).toElement();
3967 QString paramName = param.attribute("name");
3968 if (paramName == "geometry") {
3969 QString geom = param.firstChild().nodeValue();
3970 QStringList keys = geom.split(';');
3971 QStringList newKeys;
3972 for (int k = 0; k < keys.size(); ++k) {
3973 if (keys.at(k).contains('=')) {
3974 int pos = keys.at(k).section('=', 0, 0).toInt();
3975 pos = factor * pos + 0.5;
3976 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3977 } else newKeys.append(keys.at(k));
3979 param.firstChild().setNodeValue(newKeys.join(";"));
3983 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3984 int out = tractor.attribute("out").toInt();
3985 out = factor * out + 0.5;
3986 tractor.setAttribute("out", out);
3987 emit durationChanged(out);
3989 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3990 return doc.toString();
3994 void Render::sendFrameUpdate()
3996 if (m_mltProducer) {
3997 Mlt::Frame * frame = m_mltProducer->get_frame();
3998 emitFrameUpdated(*frame);
4004 #include "renderer.moc"