1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
30 #include "slideshowclip.h"
31 #include "profilesdialog.h"
32 #include "blackmagic/devices.h"
34 #include <mlt++/Mlt.h>
37 #include <KStandardDirs>
38 #include <KMessageBox>
40 #include <KTemporaryFile>
45 #include <QApplication>
52 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
54 if (level > MLT_LOG_ERROR) return;
56 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
61 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
63 // detect if the producer has finished playing. Is there a better way to do it?
64 if (self->m_isBlocked) return;
65 Mlt::Frame frame(frame_ptr);
66 if (!frame.is_valid()) return;
67 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
68 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
69 self->emitFrameUpdated(frame);
71 if (self->analyseAudio) self->showAudio(frame);
72 if (frame.get_double("_speed") == 0.0) {
73 self->emitConsumerStopped();
74 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
76 self->emitConsumerStopped();
80 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
82 // detect if the producer has finished playing. Is there a better way to do it?
83 if (self->m_isBlocked) return;
84 Mlt::Frame frame(frame_ptr);
85 self->showFrame(frame);
86 if (frame.get_double("_speed") == 0.0) {
87 self->emitConsumerStopped();
88 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
90 self->emitConsumerStopped();
94 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
97 sendFrameForAnalysis(false),
98 analyseAudio(KdenliveSettings::monitor_audio()),
104 m_externalConsumer(false),
107 m_isSplitView(false),
111 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
112 buildConsumer(profile);
114 m_mltProducer = m_blackClip->cut(0, 50);
115 m_mltConsumer->connect(*m_mltProducer);
116 m_mltProducer->set_speed(0.0);
126 void Render::closeMlt()
130 Mlt::Service service(m_mltProducer->parent().get_service());
131 mlt_service_lock(service.get_service());
133 if (service.type() == tractor_type) {
134 Mlt::Tractor tractor(service);
135 Mlt::Field *field = tractor.field();
136 mlt_service nextservice = mlt_service_get_producer(service.get_service());
137 mlt_service nextservicetodisconnect;
138 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
139 QString mlt_type = mlt_properties_get(properties, "mlt_type");
140 QString resource = mlt_properties_get(properties, "mlt_service");
141 // Delete all transitions
142 while (mlt_type == "transition") {
143 nextservicetodisconnect = nextservice;
144 nextservice = mlt_service_producer(nextservice);
145 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
146 nextservice = mlt_service_producer(nextservice);
147 if (nextservice == NULL) break;
148 properties = MLT_SERVICE_PROPERTIES(nextservice);
149 mlt_type = mlt_properties_get(properties, "mlt_type");
150 resource = mlt_properties_get(properties, "mlt_service");
153 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
154 Mlt::Producer trackProducer(tractor.track(trackNb));
155 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
156 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
159 mlt_service_unlock(service.get_service());
162 kDebug() << "// // // CLOSE RENDERER " << m_name;
163 delete m_mltConsumer;
164 delete m_mltProducer;
169 void Render::slotSwitchFullscreen()
171 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
174 void Render::buildConsumer(const QString profileName)
176 m_activeProfile = profileName;
177 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
178 setenv("MLT_PROFILE", tmp, 1);
182 //TODO: uncomment following line when everything is clean
183 //if (m_mltProfile) delete m_mltProfile;
184 m_mltProfile = new Mlt::Profile(tmp);
185 m_mltProfile->get_profile()->is_explicit = 1;
188 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
189 m_blackClip->set("id", "black");
190 m_blackClip->set("mlt_type", "producer");
192 if (KdenliveSettings::external_display() && m_name != "clip") {
193 // Use blackmagic card for video output
194 QMap< QString, QString > profileProperties = ProfilesDialog::getSettingsFromFile(profileName);
195 if (BMInterface::isSupportedProfile(KdenliveSettings::blackmagic_output_device(), profileProperties)) {
196 QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
197 tmp = qstrdup(decklink.toUtf8().constData());
198 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, tmp);
201 m_externalConsumer = true;
202 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
203 m_mltConsumer->set("terminate_on_pause", 0);
204 mlt_log_set_callback(kdenlive_callback);
206 if (m_mltConsumer && m_mltConsumer->is_valid()) return;
207 } 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 m_externalConsumer = false;
210 QString videoDriver = KdenliveSettings::videodrivername();
211 if (!videoDriver.isEmpty()) {
212 if (videoDriver == "x11_noaccel") {
213 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
216 unsetenv("SDL_VIDEO_YUV_HWACCEL");
219 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
221 //m_mltConsumer->set("fullscreen", 1);
224 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
225 m_mltConsumer->set("preview_off", 1);
226 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
227 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
229 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
230 // FIXME: the event object returned by the listen gets leaked...
231 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
232 m_mltConsumer->set("window_id", m_winid);
234 m_mltConsumer->set("resize", 1);
235 m_mltConsumer->set("terminate_on_pause", 1);
236 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
237 m_mltConsumer->set("rescale", "nearest");
238 mlt_log_set_callback(kdenlive_callback);
240 QString audioDevice = KdenliveSettings::audiodevicename();
241 if (!audioDevice.isEmpty())
242 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
244 if (!videoDriver.isEmpty())
245 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
247 QString audioDriver = KdenliveSettings::audiodrivername();
250 // Disabled because the "auto" detected driver was sometimes wrong
251 if (audioDriver.isEmpty())
252 audioDriver = KdenliveSettings::autoaudiodrivername();
255 if (!audioDriver.isEmpty())
256 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
258 m_mltConsumer->set("progressive", 1);
259 m_mltConsumer->set("audio_buffer", 1024);
260 m_mltConsumer->set("frequency", 48000);
263 Mlt::Producer *Render::invalidProducer(const QString &id)
265 Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
266 clip->set("id", id.toUtf8().constData());
267 clip->set("mlt_type", "producer");
271 int Render::resetProfile(const QString profileName)
274 if (m_externalConsumer == KdenliveSettings::external_display()) {
275 if (KdenliveSettings::external_display() && m_activeProfile == profileName) return 1;
276 QString videoDriver = KdenliveSettings::videodrivername();
277 QString currentDriver = m_mltConsumer->get("video_driver");
278 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
279 QString background = KdenliveSettings::window_background().name();
280 QString currentBackground = m_mltConsumer->get("window_background");
281 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
282 kDebug() << "reset to same profile, nothing to do";
287 if (m_isSplitView) slotSplitView(false);
288 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
289 m_mltConsumer->purge();
290 delete m_mltConsumer;
291 m_mltConsumer = NULL;
293 QString scene = sceneList();
295 double current_fps = m_mltProfile->fps();
300 pos = m_mltProducer->position();
302 Mlt::Service service(m_mltProducer->get_service());
303 if (service.type() == tractor_type) {
304 Mlt::Tractor tractor(service);
305 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
306 Mlt::Producer trackProducer(tractor.track(trackNb));
307 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
308 trackPlaylist.clear();
312 delete m_mltProducer;
314 m_mltProducer = NULL;
315 buildConsumer(profileName);
316 double new_fps = m_mltProfile->fps();
317 if (current_fps != new_fps) {
318 // fps changed, we must update the scenelist positions
319 scene = updateSceneListFps(current_fps, new_fps, scene);
321 //kDebug() << "//RESET WITHSCENE: " << scene;
322 setSceneList(scene, pos);
323 // producers have changed (different profile), so reset them...
324 emit refreshDocumentProducers();
325 /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
326 m_mltProducer = producer;
327 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
328 m_mltProducer->optimise();
329 m_mltProducer->set_speed(0);
332 //delete m_mltProfile;
333 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
334 //mlt_profile prof = m_mltProfile->get_profile();
335 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
336 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
337 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
338 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
340 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
345 void Render::seek(GenTime time)
350 m_mltProducer->seek((int)(time.frames(m_fps)));
355 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
356 QPixmap pix(width, height);
358 mlt_image_format format = mlt_image_rgb24a;
359 uint8_t *thumb = frame->get_image(format, width, height);
360 QImage image(thumb, width, height, QImage::Format_ARGB32);
362 if (!image.isNull()) {
363 pix = pix.fromImage(image);
365 QPainter painter(&pix);
366 painter.drawRect(0, 0, width - 1, height - 1);
368 } else pix.fill(Qt::black);
372 int Render::frameRenderWidth() const
374 return m_mltProfile->width();
377 int Render::renderWidth() const
379 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
382 int Render::renderHeight() const
384 return m_mltProfile->height();
387 QImage Render::extractFrame(int frame_position, int width, int height)
390 width = renderWidth();
391 height = renderHeight();
392 } else if (width % 2 == 1) width++;
394 if (!m_mltProducer) {
395 QImage pix(width, height, QImage::Format_RGB32);
399 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
402 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
406 if (url.fileName().startsWith(".all.")) { // check for slideshow
407 QString fileType = url.fileName().right(3);
409 QStringList::Iterator it;
411 QDir dir(url.directory());
413 filter << "*." + fileType;
414 filter << "*." + fileType.toUpper();
415 more = dir.entryList(filter, QDir::Files);
416 im.load(url.directory() + '/' + more.at(0));
417 } else im.load(url.path());
418 //pixmap = im.scaled(width, height);
422 double Render::consumerRatio() const
424 if (!m_mltConsumer) return 1.0;
425 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
429 int Render::getLength()
433 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
434 return mlt_producer_get_playtime(m_mltProducer->get_producer());
439 bool Render::isValid(KUrl url)
441 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
442 if (producer.is_blank())
448 double Render::dar() const
450 return m_mltProfile->dar();
454 void Render::slotSplitView(bool doit)
456 m_isSplitView = doit;
457 Mlt::Service service(m_mltProducer->parent().get_service());
458 Mlt::Tractor tractor(service);
459 if (service.type() != tractor_type || tractor.count() < 2) return;
460 Mlt::Field *field = tractor.field();
462 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
463 Mlt::Producer trackProducer(tractor.track(i));
464 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
465 if (QString(trackProducer.get("hide")).toInt() != 1) {
466 kDebug() << "// ADIDNG TRACK: " << i;
467 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
468 transition->set("mlt_service", "composite");
469 transition->set("a_track", 0);
470 transition->set("b_track", i);
471 transition->set("distort", 1);
472 transition->set("internal_added", "200");
479 tmp = "50%,0:50%x50%";
482 tmp = "0,50%:50%x50%";
486 tmp = "50%,50%:50%x50%";
489 transition->set("geometry", tmp);
490 transition->set("always_active", "1");
491 field->plant_transition(*transition, 0, i);
496 m_mltConsumer->set("refresh", 1);
498 mlt_service serv = m_mltProducer->parent().get_service();
499 mlt_service nextservice = mlt_service_get_producer(serv);
500 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
501 QString mlt_type = mlt_properties_get(properties, "mlt_type");
502 QString resource = mlt_properties_get(properties, "mlt_service");
504 while (mlt_type == "transition") {
505 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
506 if (added == "200") {
507 mlt_field_disconnect_service(field->get_field(), nextservice);
509 nextservice = mlt_service_producer(nextservice);
510 if (nextservice == NULL) break;
511 properties = MLT_SERVICE_PROPERTIES(nextservice);
512 mlt_type = mlt_properties_get(properties, "mlt_type");
513 resource = mlt_properties_get(properties, "mlt_service");
514 m_mltConsumer->set("refresh", 1);
519 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
521 KUrl url = KUrl(xml.attribute("resource", QString()));
522 Mlt::Producer *producer = NULL;
523 CLIPTYPE type = (CLIPTYPE)xml.attribute("type").toInt();
525 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
526 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
527 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
532 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
533 } else if (type == TEXT) {
534 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
535 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
536 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
537 } else if (url.isEmpty()) {
539 QDomElement mlt = doc.createElement("mlt");
540 QDomElement play = doc.createElement("playlist");
541 doc.appendChild(mlt);
542 mlt.appendChild(play);
543 play.appendChild(doc.importNode(xml, true));
544 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
546 producer = new Mlt::Producer(*m_mltProfile, url.path().toUtf8().constData());
549 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
550 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
551 emit removeInvalidClip(clipId, replaceProducer);
556 if (xml.hasAttribute("force_aspect_ratio")) {
557 double aspect = xml.attribute("force_aspect_ratio").toDouble();
558 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
561 if (xml.hasAttribute("force_aspect_num") && xml.hasAttribute("force_aspect_den")) {
562 int width = xml.attribute("frame_size").section('x', 0, 0).toInt();
563 int height = xml.attribute("frame_size").section('x', 1, 1).toInt();
564 int aspectNumerator = xml.attribute("force_aspect_num").toInt();
565 int aspectDenominator = xml.attribute("force_aspect_den").toInt();
566 if (aspectDenominator != 0 && width != 0)
567 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width);
570 if (xml.hasAttribute("force_fps")) {
571 double fps = xml.attribute("force_fps").toDouble();
572 if (fps > 0) producer->set("force_fps", fps);
575 if (xml.hasAttribute("force_progressive")) {
577 int progressive = xml.attribute("force_progressive").toInt(&ok);
578 if (ok) producer->set("force_progressive", progressive);
580 if (xml.hasAttribute("force_tff")) {
582 int fieldOrder = xml.attribute("force_tff").toInt(&ok);
583 if (ok) producer->set("force_tff", fieldOrder);
585 if (xml.hasAttribute("threads")) {
586 int threads = xml.attribute("threads").toInt();
587 if (threads != 1) producer->set("threads", threads);
589 if (xml.hasAttribute("video_index")) {
590 int vindex = xml.attribute("video_index").toInt();
591 if (vindex != 0) producer->set("video_index", vindex);
593 if (xml.hasAttribute("audio_index")) {
594 int aindex = xml.attribute("audio_index").toInt();
595 if (aindex != 0) producer->set("audio_index", aindex);
597 if (xml.hasAttribute("force_colorspace")) {
598 int colorspace = xml.attribute("force_colorspace").toInt();
599 if (colorspace != 0) producer->set("force_colorspace", colorspace);
601 if (xml.hasAttribute("full_luma")) {
602 int full_luma = xml.attribute("full_luma").toInt();
603 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
606 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
607 if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW)
608 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
610 if (xml.hasAttribute("out"))
611 producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
613 producer->set("id", clipId.toUtf8().constData());
615 if (xml.hasAttribute("templatetext"))
616 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
618 if (!replaceProducer && xml.hasAttribute("file_hash")) {
619 // Clip already has all properties
620 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
624 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
625 QMap < QString, QString > filePropertyMap;
626 QMap < QString, QString > metadataPropertyMap;
628 int frameNumber = xml.attribute("thumbnail", "0").toInt();
629 if (frameNumber != 0) producer->seek(frameNumber);
631 filePropertyMap["duration"] = QString::number(producer->get_playtime());
632 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
634 Mlt::Frame *frame = producer->get_frame();
636 if (type == SLIDESHOW) {
637 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
638 if (ttl) producer->set("ttl", ttl);
639 if (!xml.attribute("animation").isEmpty()) {
640 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
641 if (filter && filter->is_valid()) {
643 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
644 if (!geometry.isEmpty()) {
645 if (xml.attribute("animation").contains("low-pass")) {
646 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
647 if (blur && blur->is_valid())
648 producer->attach(*blur);
650 filter->set("transition.geometry", geometry.toUtf8().data());
651 filter->set("transition.cycle", cycle);
652 producer->attach(*filter);
656 if (xml.attribute("fade") == "1") {
657 // user wants a fade effect to slideshow
658 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
659 if (filter && filter->is_valid()) {
660 if (ttl) filter->set("cycle", ttl);
661 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
662 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
663 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
664 if (xml.hasAttribute("softness")) {
665 int soft = xml.attribute("softness").toInt();
666 filter->set("luma.softness", (double) soft / 100.0);
669 producer->attach(*filter);
672 if (xml.attribute("crop") == "1") {
673 // user wants to center crop the slides
674 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
675 if (filter && filter->is_valid()) {
676 filter->set("center", 1);
677 producer->attach(*filter);
682 if (producer->get_double("meta.media.frame_rate_den") > 0) {
683 filePropertyMap["fps"] = QString::number(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
684 } else filePropertyMap["fps"] = producer->get("source_fps");
686 if (frame && frame->is_valid()) {
687 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
688 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
689 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
690 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
692 if (frame->get_int("test_image") == 0) {
693 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
694 filePropertyMap["type"] = "playlist";
695 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
696 } else if (frame->get_int("test_audio") == 0)
697 filePropertyMap["type"] = "av";
699 filePropertyMap["type"] = "video";
701 mlt_image_format format = mlt_image_rgb24a;
702 int frame_width = width;
703 int frame_height = imageHeight;
704 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
705 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied);
708 if (!image.isNull()) {
709 if (frame_width > (2 * width)) {
710 // there was a scaling problem, do it manually
711 QImage scaled = image.scaled(width, imageHeight);
712 pix = QPixmap::fromImage(scaled.rgbSwapped());
713 } else pix = QPixmap::fromImage(image.rgbSwapped());
717 emit replyGetImage(clipId, pix);
719 } else if (frame->get_int("test_audio") == 0) {
720 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
721 emit replyGetImage(clipId, pixmap);
722 filePropertyMap["type"] = "audio";
726 // Retrieve audio / video codec name
730 if (producer->get_int("video_index") > -1) {
731 /*if (context->duration == AV_NOPTS_VALUE) {
732 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
733 emit removeInvalidClip(clipId);
737 // Get the video_index
738 int default_video = producer->get_int("video_index");
740 int default_audio = producer->get_int("audio_index");
743 // Find maximum stream index values
744 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
745 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
746 QString type = producer->get(property);
749 else if (type == "audio")
752 filePropertyMap["default_video"] = QString::number(default_video);
753 filePropertyMap["video_max"] = QString::number(video_max);
754 filePropertyMap["default_audio"] = QString::number(default_audio);
755 filePropertyMap["audio_max"] = QString::number(audio_max);
757 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
758 if (producer->get(property)) {
759 filePropertyMap["videocodec"] = producer->get(property);
761 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
762 if (producer->get(property))
763 filePropertyMap["videocodec"] = producer->get(property);
766 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
767 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
768 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
770 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
771 if (producer->get_int("audio_index") > -1) {
772 // Get the audio_index
773 int index = producer->get_int("audio_index");
775 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
776 if (producer->get(property)) {
777 filePropertyMap["audiocodec"] = producer->get(property);
779 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
780 if (producer->get(property))
781 filePropertyMap["audiocodec"] = producer->get(property);
786 Mlt::Properties metadata;
787 metadata.pass_values(*producer, "meta.attr.");
788 int count = metadata.count();
789 for (int i = 0; i < count; i ++) {
790 QString name = metadata.get_name(i);
791 QString value = QString::fromUtf8(metadata.get(i));
792 if (name.endsWith("markup") && !value.isEmpty())
793 metadataPropertyMap[ name.section('.', 0, -2)] = value;
796 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
797 // FIXME: should delete this to avoid a leak...
803 /** Create the producer from the MLT XML QDomDocument */
804 void Render::initSceneList()
806 kDebug() << "-------- INIT SCENE LIST ------_";
808 QDomElement mlt = doc.createElement("mlt");
809 doc.appendChild(mlt);
810 QDomElement prod = doc.createElement("producer");
811 prod.setAttribute("resource", "colour");
812 prod.setAttribute("colour", "red");
813 prod.setAttribute("id", "black");
814 prod.setAttribute("in", "0");
815 prod.setAttribute("out", "0");
817 QDomElement tractor = doc.createElement("tractor");
818 QDomElement multitrack = doc.createElement("multitrack");
820 QDomElement playlist1 = doc.createElement("playlist");
821 playlist1.appendChild(prod);
822 multitrack.appendChild(playlist1);
823 QDomElement playlist2 = doc.createElement("playlist");
824 multitrack.appendChild(playlist2);
825 QDomElement playlist3 = doc.createElement("playlist");
826 multitrack.appendChild(playlist3);
827 QDomElement playlist4 = doc.createElement("playlist");
828 multitrack.appendChild(playlist4);
829 QDomElement playlist5 = doc.createElement("playlist");
830 multitrack.appendChild(playlist5);
831 tractor.appendChild(multitrack);
832 mlt.appendChild(tractor);
833 // kDebug()<<doc.toString();
835 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
836 setSceneList(doc, 0);
840 int Render::setProducer(Mlt::Producer *producer, int position)
842 if (m_winid == -1) return -1;
845 m_mltConsumer->stop();
848 m_mltConsumer->purge();
851 m_mltProducer->set_speed(0);
852 delete m_mltProducer;
853 m_mltProducer = NULL;
857 m_mltProducer = new Mlt::Producer(producer->get_producer());
858 } else m_mltProducer = m_blackClip->cut(0, 50);
860 if (!m_mltProducer || !m_mltProducer->is_valid()) {
861 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
864 int volume = KdenliveSettings::volume();
865 m_mltProducer->set("meta.volume", (double)volume / 100);
866 m_fps = m_mltProducer->get_fps();
867 int error = connectPlaylist();
869 if (position != -1) {
870 m_mltProducer->seek(position);
871 emit rendererPosition(position);
872 } else emit rendererPosition((int) m_mltProducer->position());
877 int Render::setSceneList(QDomDocument list, int position)
879 return setSceneList(list.toString(), position);
882 int Render::setSceneList(QString playlist, int position)
884 if (m_winid == -1) return -1;
888 //kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
891 if (!m_mltConsumer->is_stopped()) {
892 m_mltConsumer->stop();
894 m_mltConsumer->set("refresh", 0);
896 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
901 m_mltProducer->set_speed(0);
902 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
905 Mlt::Service service(m_mltProducer->parent().get_service());
906 mlt_service_lock(service.get_service());
908 if (service.type() == tractor_type) {
909 Mlt::Tractor tractor(service);
910 Mlt::Field *field = tractor.field();
911 mlt_service nextservice = mlt_service_get_producer(service.get_service());
912 mlt_service nextservicetodisconnect;
913 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
914 QString mlt_type = mlt_properties_get(properties, "mlt_type");
915 QString resource = mlt_properties_get(properties, "mlt_service");
916 // Delete all transitions
917 while (mlt_type == "transition") {
918 nextservicetodisconnect = nextservice;
919 nextservice = mlt_service_producer(nextservice);
920 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
921 if (nextservice == NULL) break;
922 properties = MLT_SERVICE_PROPERTIES(nextservice);
923 mlt_type = mlt_properties_get(properties, "mlt_type");
924 resource = mlt_properties_get(properties, "mlt_service");
927 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
928 Mlt::Producer trackProducer(tractor.track(trackNb));
929 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
930 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
934 mlt_service_unlock(service.get_service());
936 qDeleteAll(m_slowmotionProducers.values());
937 m_slowmotionProducers.clear();
939 delete m_mltProducer;
940 m_mltProducer = NULL;
946 // TODO: Better way to do this
947 if (KdenliveSettings::projectloading_avformatnovalidate())
948 playlist.replace(">avformat</property>", ">avformat-novalidate</property>");
950 playlist.replace(">avformat-novalidate</property>", ">avformat</property>");
952 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
954 if (!m_mltProducer || !m_mltProducer->is_valid()) {
955 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
956 m_mltProducer = m_blackClip->cut(0, 50);
959 int volume = KdenliveSettings::volume();
960 m_mltProducer->set("meta.volume", (double)volume / 100);
961 m_mltProducer->optimise();
963 /*if (KdenliveSettings::osdtimecode()) {
964 // Attach filter for on screen display of timecode
966 QString attr = "attr_check";
967 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
968 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
969 mlt_producer_attach( m_mltProducer->get_producer(), filter );
970 mlt_filter_close( filter );
972 m_osdInfo = new Mlt::Filter("data_show");
973 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
974 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
975 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
976 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
977 m_osdInfo->set("dynamic", "1");
979 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
981 m_osdInfo->set("dynamic", "0");
984 m_fps = m_mltProducer->get_fps();
986 // Seek to correct place after opening project.
987 m_mltProducer->seek(position);
990 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
991 if (error == 0) error = connectPlaylist();
992 else connectPlaylist();
993 fillSlowMotionProducers();
999 //kDebug()<<"// SETSCN LST, POS: "<<position;
1000 //if (position != 0) emit rendererPosition(position);
1003 const QString Render::sceneList()
1006 Mlt::Profile profile((mlt_profile) 0);
1007 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
1008 m_mltProducer->optimise();
1009 xmlConsumer.set("terminate_on_pause", 1);
1010 Mlt::Producer prod(m_mltProducer->get_producer());
1011 bool split = m_isSplitView;
1012 if (split) slotSplitView(false);
1013 xmlConsumer.connect(prod);
1014 xmlConsumer.start();
1015 while (!xmlConsumer.is_stopped()) {}
1016 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1017 if (split) slotSplitView(true);
1021 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1025 doc.setContent(sceneList(), false);
1026 if (!kdenliveData.isNull()) {
1027 // add Kdenlive specific tags
1028 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1029 mlt.appendChild(doc.importNode(kdenliveData, true));
1031 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1032 kWarning() << "////// ERROR writing to file: " << path;
1035 file.write(doc.toString().toUtf8());
1036 if (file.error() != QFile::NoError) {
1044 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1046 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1047 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1048 m_mltProducer->optimise();
1049 xmlConsumer.set("terminate_on_pause", 1);
1050 if (m_name == "clip") {
1051 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1053 list.insert_at(0, prod, 0);
1055 list.set("title", desc.toUtf8().constData());
1056 xmlConsumer.connect(list);
1059 //TODO: not working yet, save zone from timeline
1060 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1061 /* Mlt::Service service(p1->parent().get_service());
1062 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1064 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1065 //prod->set("title", desc.toUtf8().constData());
1066 xmlConsumer.connect(*p1); //list);
1069 xmlConsumer.start();
1072 double Render::fps() const
1077 int Render::connectPlaylist()
1079 if (!m_mltConsumer) return -1;
1080 //m_mltConsumer->set("refresh", "0");
1081 m_mltConsumer->connect(*m_mltProducer);
1082 m_mltProducer->set_speed(0);
1083 if (m_mltConsumer->start() == -1) {
1084 // ARGH CONSUMER BROKEN!!!!
1085 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."));
1086 delete m_mltConsumer;
1087 m_mltConsumer = NULL;
1090 emit durationChanged(m_mltProducer->get_playtime());
1095 void Render::refreshDisplay()
1098 if (!m_mltProducer) return;
1099 //m_mltConsumer->set("refresh", 0);
1101 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1102 /*if (KdenliveSettings::osdtimecode()) {
1103 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1104 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1105 m_osdInfo->set("dynamic", "1");
1106 m_mltProducer->attach(*m_osdInfo);
1109 m_mltProducer->detach(*m_osdInfo);
1110 m_osdInfo->set("dynamic", "0");
1115 int Render::volume() const
1117 if (!m_mltConsumer || !m_mltProducer) return -1;
1118 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1121 void Render::slotSetVolume(int volume)
1123 if (!m_mltConsumer || !m_mltProducer) return;
1124 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1127 m_mltConsumer->set("refresh", 0);
1128 // Attach filter for on screen display of timecode
1129 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1130 mlt_properties_set_double( properties, "meta.volume", volume );
1131 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1132 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1134 if (!KdenliveSettings::osdtimecode()) {
1135 m_mltProducer->detach(*m_osdInfo);
1136 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1137 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1140 //m_osdTimer->setSingleShot(2500);
1143 void Render::slotOsdTimeout()
1145 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1146 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1147 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1148 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1152 void Render::start()
1154 kDebug() << "----- STARTING MONITOR: " << m_name;
1155 if (m_winid == -1) {
1156 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1159 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1160 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1161 if (m_mltConsumer->start() == -1) {
1162 //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."));
1163 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1165 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1166 m_isBlocked = false;
1170 m_isBlocked = false;
1175 if (m_mltProducer == NULL) return;
1176 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1177 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1179 //m_mltConsumer->set("refresh", 0);
1180 m_mltConsumer->stop();
1181 // delete m_mltConsumer;
1182 // m_mltConsumer = NULL;
1184 kDebug() << "///////////// RENDER STOP2-------";
1187 if (m_mltProducer) {
1188 if (m_isZoneMode) resetZoneMode();
1189 m_mltProducer->set_speed(0.0);
1190 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1191 //kDebug() << m_mltProducer->get_length();
1193 kDebug() << "///////////// RENDER STOP3-------";
1196 void Render::stop(const GenTime & startTime)
1199 kDebug() << "///////////// RENDER STOP-------2";
1200 if (m_mltProducer) {
1201 if (m_isZoneMode) resetZoneMode();
1202 m_mltProducer->set_speed(0.0);
1203 m_mltProducer->seek((int) startTime.frames(m_fps));
1205 m_mltConsumer->purge();
1208 void Render::pause()
1210 if (!m_mltProducer || !m_mltConsumer)
1212 if (m_mltProducer->get_speed() == 0.0) return;
1213 if (m_isZoneMode) resetZoneMode();
1215 m_mltConsumer->set("refresh", 0);
1216 m_mltProducer->set_speed(0.0);
1218 The 2 lines below create a flicker loop
1219 emit rendererPosition(m_framePosition);
1220 m_mltProducer->seek(m_framePosition);*/
1221 m_mltConsumer->purge();
1224 void Render::switchPlay()
1226 if (!m_mltProducer || !m_mltConsumer)
1228 if (m_isZoneMode) resetZoneMode();
1229 if (m_mltProducer->get_speed() == 0.0) {
1230 m_isBlocked = false;
1231 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1232 m_mltProducer->set_speed(1.0);
1233 m_mltConsumer->set("refresh", 1);
1236 m_mltConsumer->set("refresh", 0);
1237 m_mltProducer->set_speed(0.0);
1238 //emit rendererPosition(m_framePosition);
1239 m_mltProducer->seek(m_framePosition);
1240 m_mltConsumer->purge();
1241 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1242 //m_mltConsumer->set("refresh", 0);
1243 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1244 m_mltProducer->set_speed(0);
1245 m_mltProducer->seek( position );
1246 //m_mltProducer->seek((int) m_framePosition);
1247 m_isBlocked = false;*/
1249 /*if (speed == 0.0) {
1250 m_mltProducer->seek((int) m_framePosition + 1);
1251 m_mltConsumer->purge();
1256 void Render::play(double speed)
1260 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1261 m_isBlocked = false;
1262 m_mltProducer->set_speed(speed);
1263 /*if (speed == 0.0) {
1264 m_mltProducer->seek((int) m_framePosition + 1);
1265 m_mltConsumer->purge();
1270 void Render::play(const GenTime & startTime)
1272 if (!m_mltProducer || !m_mltConsumer)
1274 m_isBlocked = false;
1275 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1276 m_mltProducer->set_speed(1.0);
1277 m_mltConsumer->set("refresh", 1);
1280 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1282 if (!m_mltProducer || !m_mltConsumer)
1284 //m_mltProducer->set("eof", "loop");
1285 m_isLoopMode = true;
1286 m_loopStart = startTime;
1287 playZone(startTime, stopTime);
1290 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1292 if (!m_mltProducer || !m_mltConsumer)
1294 m_isBlocked = false;
1295 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1296 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1297 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1298 m_mltProducer->set_speed(1.0);
1299 m_mltConsumer->set("refresh", 1);
1300 m_isZoneMode = true;
1303 void Render::resetZoneMode()
1305 if (!m_isZoneMode && !m_isLoopMode) return;
1306 m_mltProducer->set("out", m_originalOut);
1307 //m_mltProducer->set("eof", "pause");
1308 m_isZoneMode = false;
1309 m_isLoopMode = false;
1312 void Render::seekToFrame(int pos)
1314 //kDebug()<<" ********* RENDER SEEK TO POS";
1317 m_isBlocked = false;
1319 m_mltProducer->seek(pos);
1323 void Render::seekToFrameDiff(int diff)
1325 //kDebug()<<" ********* RENDER SEEK TO POS";
1328 m_isBlocked = false;
1330 m_mltProducer->seek(m_mltProducer->position() + diff);
1334 void Render::doRefresh()
1336 // Use a Timer so that we don't refresh too much
1337 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1340 void Render::refresh()
1342 if (!m_mltProducer || m_isBlocked)
1344 if (m_mltConsumer) {
1345 m_mltConsumer->set("refresh", 1);
1349 void Render::setDropFrames(bool show)
1351 if (m_mltConsumer) {
1353 if (show == false) dropFrames = 0;
1354 m_mltConsumer->stop();
1356 m_mltConsumer->set("real_time", dropFrames);
1358 m_mltConsumer->set("play.real_time", dropFrames);
1360 if (m_mltConsumer->start() == -1) {
1361 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1367 double Render::playSpeed()
1369 if (m_mltProducer) return m_mltProducer->get_speed();
1373 GenTime Render::seekPosition() const
1375 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1376 else return GenTime();
1379 int Render::seekFramePosition() const
1381 if (m_mltProducer) return (int) m_mltProducer->position();
1385 const QString & Render::rendererName() const
1390 void Render::emitFrameUpdated(Mlt::Frame& frame)
1392 mlt_image_format format = mlt_image_rgb24a;
1395 const uchar* image = frame.get_image(format, width, height);
1396 QImage qimage(width, height, QImage::Format_ARGB32);
1397 memcpy(qimage.bits(), image, width * height * 4);
1398 emit frameUpdated(qimage.rgbSwapped());
1401 void Render::emitFrameNumber(double position)
1403 m_framePosition = position;
1404 emit rendererPosition((int) position);
1407 void Render::emitConsumerStopped()
1409 // This is used to know when the playing stopped
1410 if (m_mltProducer) {
1411 double pos = m_mltProducer->position();
1412 if (m_isLoopMode) play(m_loopStart);
1413 else if (m_isZoneMode) resetZoneMode();
1414 emit rendererStopped((int) pos);
1418 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1420 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1423 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1425 if (!m_mltProducer) {
1426 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1430 //int height = 1080;//KdenliveSettings::defaultheight();
1431 //int width = 1940; //KdenliveSettings::displaywidth();
1433 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1435 QPixmap pix(width, height);
1436 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1437 m_convert.set("forced", mlt_image_rgb24a);
1438 m_mltProducer->attach(m_convert);
1439 Mlt::Frame * frame = m_mltProducer->get_frame();
1440 m_mltProducer->detach(m_convert);
1442 pix = frameThumbnail(frame, width, height);
1445 pix.save(url.path(), "PNG");
1446 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1450 void Render::showFrame(Mlt::Frame& frame)
1452 m_framePosition = qMax(frame.get_int("_position"), 0);
1453 emit rendererPosition((int) m_framePosition);
1454 mlt_image_format format = mlt_image_rgb24a;
1457 const uchar* image = frame.get_image(format, width, height);
1458 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1459 memcpy(qimage.scanLine(0), image, width * height * 4);
1460 emit showImageSignal(qimage);
1461 if (analyseAudio) showAudio(frame);
1462 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1463 emit frameUpdated(qimage.rgbSwapped());
1467 void Render::showAudio(Mlt::Frame& frame)
1469 if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
1470 mlt_audio_format audio_format = mlt_audio_s16;
1472 int num_channels = 0;
1474 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1476 QVector<int16_t> sampleVector(samples);
1477 memcpy(sampleVector.data(), data, samples*sizeof(int16_t));
1478 //qDebug() << samples << " samples. Freq=" << freq << ", channels=" << num_channels;
1482 /*int num_samples = samples > 200 ? 200 : samples;
1485 QByteArray channels;
1486 for (int i = 0; i < num_channels; i++) {
1488 for (int s = 0; s < num_samples; s ++) {
1489 val += abs(data[i+s*num_channels] / 128);
1491 channels.append(val / num_samples);
1495 //emit showAudioSignal(channels);
1496 //qDebug() << "Emitting audioSamplesSignal with " << samples << " samples.";
1497 emit audioSamplesSignal(sampleVector, freq, num_channels, samples);
1499 //emit showAudioSignal(QByteArray());
1500 //qDebug() << "Not emitting audioSamplesSignal.";
1505 * MLT playlist direct manipulation.
1508 void Render::mltCheckLength(Mlt::Tractor *tractor)
1510 //kDebug()<<"checking track length: "<<track<<"..........";
1512 int trackNb = tractor->count();
1516 Mlt::Producer trackProducer(tractor->track(0));
1517 duration = trackProducer.get_playtime() - 1;
1518 m_mltProducer->set("out", duration);
1519 emit durationChanged(duration);
1522 while (trackNb > 1) {
1523 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1524 trackDuration = trackProducer.get_playtime() - 1;
1525 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1526 if (trackDuration > duration) duration = trackDuration;
1530 Mlt::Producer blackTrackProducer(tractor->track(0));
1532 if (blackTrackProducer.get_playtime() - 1 != duration) {
1533 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1534 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1535 if (blackclip && blackclip->is_blank()) {
1540 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1541 blackTrackPlaylist.clear();
1542 m_blackClip->set("length", duration + 1);
1543 m_blackClip->set("out", duration);
1544 blackclip = m_blackClip->cut(0, duration);
1545 blackTrackPlaylist.insert_at(0, blackclip, 1);
1547 if (duration > blackclip->parent().get_length()) {
1548 blackclip->parent().set("length", duration + 1);
1549 blackclip->parent().set("out", duration);
1550 blackclip->set("length", duration + 1);
1552 blackTrackPlaylist.resize_clip(0, 0, duration);
1556 m_mltProducer->set("out", duration);
1557 emit durationChanged(duration);
1561 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1563 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1565 // We want a slowmotion producer
1566 double speed = element.attribute("speed", "1.0").toDouble();
1567 int strobe = element.attribute("strobe", "1").toInt();
1568 QString url = QString::fromUtf8(prod->get("resource"));
1569 url.append('?' + QString::number(speed));
1570 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1571 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1572 if (!slowprod || slowprod->get_producer() == NULL) {
1573 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1574 if (strobe > 1) slowprod->set("strobe", strobe);
1575 QString id = prod->get("id");
1576 if (id.contains('_')) id = id.section('_', 0, 0);
1577 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1578 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1579 slowprod->set("id", producerid.toUtf8().constData());
1580 m_slowmotionProducers.insert(url, slowprod);
1585 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1587 if (m_mltProducer == NULL) {
1588 kDebug() << "PLAYLIST NOT INITIALISED //////";
1592 kDebug() << "Cannot insert clip without producer //////";
1595 Mlt::Producer parentProd(m_mltProducer->parent());
1596 if (parentProd.get_producer() == NULL) {
1597 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1601 Mlt::Service service(parentProd.get_service());
1602 if (service.type() != tractor_type) {
1603 kWarning() << "// TRACTOR PROBLEM";
1606 Mlt::Tractor tractor(service);
1607 if (info.track > tractor.count() - 1) {
1608 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1611 mlt_service_lock(service.get_service());
1612 Mlt::Producer trackProducer(tractor.track(info.track));
1613 int trackDuration = trackProducer.get_playtime() - 1;
1614 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1615 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1616 prod = checkSlowMotionProducer(prod, element);
1617 if (prod == NULL || !prod->is_valid()) {
1618 mlt_service_unlock(service.get_service());
1622 int cutPos = (int) info.cropStart.frames(m_fps);
1623 if (cutPos < 0) cutPos = 0;
1624 int insertPos = (int) info.startPos.frames(m_fps);
1625 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1626 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1627 if (overwrite && (insertPos < trackDuration)) {
1628 // Replace zone with blanks
1629 //trackPlaylist.split_at(insertPos, true);
1630 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1631 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1632 trackPlaylist.insert_blank(clipIndex, cutDuration);
1634 trackPlaylist.split_at(insertPos, true);
1635 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1636 trackPlaylist.insert_blank(clipIndex, cutDuration);
1638 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1640 /*if (QString(prod->get("transparency")).toInt() == 1)
1641 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1643 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1644 mlt_service_unlock(service.get_service());
1645 /*tractor.multitrack()->refresh();
1646 tractor.refresh();*/
1651 void Render::mltCutClip(int track, GenTime position)
1655 Mlt::Service service(m_mltProducer->parent().get_service());
1656 if (service.type() != tractor_type) {
1657 kWarning() << "// TRACTOR PROBLEM";
1661 Mlt::Tractor tractor(service);
1662 Mlt::Producer trackProducer(tractor.track(track));
1663 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1666 /* // Display playlist info
1667 kDebug()<<"//////////// BEFORE";
1668 for (int i = 0; i < trackPlaylist.count(); i++) {
1669 int blankStart = trackPlaylist.clip_start(i);
1670 int blankDuration = trackPlaylist.clip_length(i) - 1;
1672 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1673 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1676 int cutPos = (int) position.frames(m_fps);
1678 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1679 if (trackPlaylist.is_blank(clipIndex)) {
1680 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1681 m_isBlocked = false;
1684 mlt_service_lock(service.get_service());
1685 int clipStart = trackPlaylist.clip_start(clipIndex);
1686 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1687 mlt_service_unlock(service.get_service());
1689 // duplicate effects
1690 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1691 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1693 if (original == NULL || clip == NULL) {
1694 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1696 Mlt::Service clipService(original->get_service());
1697 Mlt::Service dupService(clip->get_service());
1701 Mlt::Filter *filter = clipService.filter(ct);
1703 // Only duplicate Kdenlive filters, and skip the fade in effects
1704 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1705 // looks like there is no easy way to duplicate a filter,
1706 // so we will create a new one and duplicate its properties
1707 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1708 if (dup && dup->is_valid()) {
1709 Mlt::Properties entries(filter->get_properties());
1710 for (int i = 0; i < entries.count(); i++) {
1711 dup->set(entries.get_name(i), entries.get(i));
1713 dupService.attach(*dup);
1717 filter = clipService.filter(ct);
1720 /* // Display playlist info
1721 kDebug()<<"//////////// AFTER";
1722 for (int i = 0; i < trackPlaylist.count(); i++) {
1723 int blankStart = trackPlaylist.clip_start(i);
1724 int blankDuration = trackPlaylist.clip_length(i) - 1;
1726 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1727 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1730 m_isBlocked = false;
1733 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1737 kDebug() << "Cannot update clip with null producer //////";
1740 Mlt::Service service(m_mltProducer->parent().get_service());
1741 if (service.type() != tractor_type) {
1742 kWarning() << "// TRACTOR PROBLEM";
1745 Mlt::Tractor tractor(service);
1746 Mlt::Producer trackProducer(tractor.track(info.track));
1747 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1748 int startPos = info.startPos.frames(m_fps);
1749 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1750 if (trackPlaylist.is_blank(clipIndex)) {
1751 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1754 mlt_service_lock(service.get_service());
1755 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1757 QList <Mlt::Filter *> filtersList;
1758 Mlt::Service sourceService(clip->get_service());
1760 Mlt::Filter *filter = sourceService.filter(ct);
1762 if (filter->get_int("kdenlive_ix") != 0) {
1763 filtersList.append(filter);
1766 filter = sourceService.filter(ct);
1769 trackPlaylist.replace_with_blank(clipIndex);
1771 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1772 prod = checkSlowMotionProducer(prod, element);
1773 if (prod == NULL || !prod->is_valid()) {
1774 mlt_service_unlock(service.get_service());
1777 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1778 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1782 //if (mltInsertClip(info, element, prod) == -1) return false;
1783 if (!filtersList.isEmpty()) {
1784 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1785 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1786 Mlt::Service destService(destclip->get_service());
1788 for (int i = 0; i < filtersList.count(); i++)
1789 destService.attach(*(filtersList.at(i)));
1791 mlt_service_unlock(service.get_service());
1796 bool Render::mltRemoveClip(int track, GenTime position)
1798 Mlt::Service service(m_mltProducer->parent().get_service());
1799 if (service.type() != tractor_type) {
1800 kWarning() << "// TRACTOR PROBLEM";
1804 Mlt::Tractor tractor(service);
1805 mlt_service_lock(service.get_service());
1806 Mlt::Producer trackProducer(tractor.track(track));
1807 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1808 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1810 // Display playlist info
1811 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1812 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1813 int blankStart = trackPlaylist.clip_start(i);
1814 int blankDuration = trackPlaylist.clip_length(i) - 1;
1816 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1817 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1819 if (trackPlaylist.is_blank(clipIndex)) {
1820 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1821 mlt_service_unlock(service.get_service());
1824 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1826 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1827 if (clip) delete clip;
1828 trackPlaylist.consolidate_blanks(0);
1829 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1830 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1832 /* // Display playlist info
1833 kDebug()<<"//// AFTER";
1834 for (int i = 0; i < trackPlaylist.count(); i++) {
1835 int blankStart = trackPlaylist.clip_start(i);
1836 int blankDuration = trackPlaylist.clip_length(i) - 1;
1838 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1839 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1841 mlt_service_unlock(service.get_service());
1842 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1843 m_isBlocked = false;
1847 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1849 if (!m_mltProducer) {
1850 kDebug() << "PLAYLIST NOT INITIALISED //////";
1853 Mlt::Producer parentProd(m_mltProducer->parent());
1854 if (parentProd.get_producer() == NULL) {
1855 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1859 Mlt::Service service(parentProd.get_service());
1860 Mlt::Tractor tractor(service);
1861 int insertPos = pos.frames(m_fps);
1863 Mlt::Producer trackProducer(tractor.track(track));
1864 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1865 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1866 if (clipIndex == trackPlaylist.count()) {
1867 // We are after the end of the playlist
1870 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1871 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1872 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1875 int Render::mltTrackDuration(int track)
1877 if (!m_mltProducer) {
1878 kDebug() << "PLAYLIST NOT INITIALISED //////";
1881 Mlt::Producer parentProd(m_mltProducer->parent());
1882 if (parentProd.get_producer() == NULL) {
1883 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1887 Mlt::Service service(parentProd.get_service());
1888 Mlt::Tractor tractor(service);
1890 Mlt::Producer trackProducer(tractor.track(track));
1891 return trackProducer.get_playtime() - 1;
1894 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1896 if (!m_mltProducer) {
1897 kDebug() << "PLAYLIST NOT INITIALISED //////";
1900 Mlt::Producer parentProd(m_mltProducer->parent());
1901 if (parentProd.get_producer() == NULL) {
1902 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1905 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1906 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1908 Mlt::Service service(parentProd.get_service());
1909 Mlt::Tractor tractor(service);
1910 mlt_service_lock(service.get_service());
1911 int diff = duration.frames(m_fps);
1912 int offset = timeOffset.frames(m_fps);
1916 // insert space in one track only
1917 Mlt::Producer trackProducer(tractor.track(track));
1918 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1919 insertPos = trackClipStartList.value(track);
1920 if (insertPos != -1) {
1921 insertPos += offset;
1922 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1924 trackPlaylist.insert_blank(clipIndex, diff - 1);
1926 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1927 if (!trackPlaylist.is_blank(clipIndex)) {
1928 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1930 int position = trackPlaylist.clip_start(clipIndex);
1931 int blankDuration = trackPlaylist.clip_length(clipIndex);
1933 if (blankDuration - diff == 0) {
1934 trackPlaylist.remove(clipIndex);
1935 } else trackPlaylist.remove_region(position, diff);
1937 trackPlaylist.consolidate_blanks(0);
1939 // now move transitions
1940 mlt_service serv = m_mltProducer->parent().get_service();
1941 mlt_service nextservice = mlt_service_get_producer(serv);
1942 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1943 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1944 QString resource = mlt_properties_get(properties, "mlt_service");
1946 while (mlt_type == "transition") {
1947 mlt_transition tr = (mlt_transition) nextservice;
1948 int currentTrack = mlt_transition_get_b_track(tr);
1949 int currentIn = (int) mlt_transition_get_in(tr);
1950 int currentOut = (int) mlt_transition_get_out(tr);
1951 insertPos = trackTransitionStartList.value(track);
1952 if (insertPos != -1) {
1953 insertPos += offset;
1954 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1955 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1958 nextservice = mlt_service_producer(nextservice);
1959 if (nextservice == NULL) break;
1960 properties = MLT_SERVICE_PROPERTIES(nextservice);
1961 mlt_type = mlt_properties_get(properties, "mlt_type");
1962 resource = mlt_properties_get(properties, "mlt_service");
1965 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1966 Mlt::Producer trackProducer(tractor.track(trackNb));
1967 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1969 //int clipNb = trackPlaylist.count();
1970 insertPos = trackClipStartList.value(trackNb);
1971 if (insertPos != -1) {
1972 insertPos += offset;
1974 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1975 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1976 for (int i = 0; i < clipNb; i++) {
1977 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1978 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1979 kDebug()<<"-------------";
1981 kDebug()<<"END-------------";*/
1984 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1986 trackPlaylist.insert_blank(clipIndex, diff - 1);
1988 if (!trackPlaylist.is_blank(clipIndex)) {
1991 if (!trackPlaylist.is_blank(clipIndex)) {
1992 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1994 int position = trackPlaylist.clip_start(clipIndex);
1995 int blankDuration = trackPlaylist.clip_length(clipIndex);
1996 if (diff + blankDuration == 0) {
1997 trackPlaylist.remove(clipIndex);
1998 } else trackPlaylist.remove_region(position, - diff);
2000 trackPlaylist.consolidate_blanks(0);
2003 // now move transitions
2004 mlt_service serv = m_mltProducer->parent().get_service();
2005 mlt_service nextservice = mlt_service_get_producer(serv);
2006 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2007 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2008 QString resource = mlt_properties_get(properties, "mlt_service");
2010 while (mlt_type == "transition") {
2011 mlt_transition tr = (mlt_transition) nextservice;
2012 int currentIn = (int) mlt_transition_get_in(tr);
2013 int currentOut = (int) mlt_transition_get_out(tr);
2014 int currentTrack = mlt_transition_get_b_track(tr);
2015 insertPos = trackTransitionStartList.value(currentTrack);
2016 if (insertPos != -1) {
2017 insertPos += offset;
2018 if (currentOut > insertPos && resource != "mix") {
2019 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2022 nextservice = mlt_service_producer(nextservice);
2023 if (nextservice == NULL) break;
2024 properties = MLT_SERVICE_PROPERTIES(nextservice);
2025 mlt_type = mlt_properties_get(properties, "mlt_type");
2026 resource = mlt_properties_get(properties, "mlt_service");
2029 mlt_service_unlock(service.get_service());
2030 mltCheckLength(&tractor);
2031 m_mltConsumer->set("refresh", 1);
2035 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2037 if (source == dest) return;
2038 Mlt::Service sourceService(source->get_service());
2039 Mlt::Service destService(dest->get_service());
2041 // move all effects to the correct producer
2043 Mlt::Filter *filter = sourceService.filter(ct);
2045 if (filter->get_int("kdenlive_ix") != 0) {
2046 sourceService.detach(*filter);
2047 destService.attach(*filter);
2049 filter = sourceService.filter(ct);
2053 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2057 Mlt::Service service(m_mltProducer->parent().get_service());
2058 if (service.type() != tractor_type) {
2059 kWarning() << "// TRACTOR PROBLEM";
2062 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2063 Mlt::Tractor tractor(service);
2064 Mlt::Producer trackProducer(tractor.track(info.track));
2065 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2066 int startPos = info.startPos.frames(m_fps);
2067 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2068 int clipLength = trackPlaylist.clip_length(clipIndex);
2070 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2071 if (original == NULL) {
2074 if (!original->is_valid() || original->is_blank()) {
2079 Mlt::Producer clipparent = original->parent();
2080 if (!clipparent.is_valid() || clipparent.is_blank()) {
2086 QString serv = clipparent.get("mlt_service");
2087 QString id = clipparent.get("id");
2088 if (speed <= 0 && speed > -1) speed = 1.0;
2089 //kDebug() << "CLIP SERVICE: " << serv;
2090 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2091 mlt_service_lock(service.get_service());
2092 QString url = QString::fromUtf8(clipparent.get("resource"));
2093 url.append('?' + QString::number(speed));
2094 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2095 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2096 if (!slowprod || slowprod->get_producer() == NULL) {
2097 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2098 if (strobe > 1) slowprod->set("strobe", strobe);
2099 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2100 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2101 slowprod->set("id", producerid.toUtf8().constData());
2102 // copy producer props
2103 double ar = original->parent().get_double("force_aspect_ratio");
2104 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2105 double fps = original->parent().get_double("force_fps");
2106 if (fps != 0.0) slowprod->set("force_fps", fps);
2107 int threads = original->parent().get_int("threads");
2108 if (threads != 0) slowprod->set("threads", threads);
2109 if (original->parent().get("force_progressive"))
2110 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2111 if (original->parent().get("force_tff"))
2112 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2113 int ix = original->parent().get_int("video_index");
2114 if (ix != 0) slowprod->set("video_index", ix);
2115 int colorspace = original->parent().get_int("force_colorspace");
2116 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2117 int full_luma = original->parent().get_int("set.force_full_luma");
2118 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2119 m_slowmotionProducers.insert(url, slowprod);
2121 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2122 trackPlaylist.consolidate_blanks(0);
2124 // Check that the blank space is long enough for our new duration
2125 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2126 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2128 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2129 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2130 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2131 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2133 // move all effects to the correct producer
2134 mltPasteEffects(clip, cut);
2135 trackPlaylist.insert_at(startPos, cut, 1);
2138 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2139 newLength = trackPlaylist.clip_length(clipIndex);
2140 mlt_service_unlock(service.get_service());
2141 } else if (speed == 1.0 && strobe < 2) {
2142 mlt_service_lock(service.get_service());
2144 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2145 trackPlaylist.consolidate_blanks(0);
2147 // Check that the blank space is long enough for our new duration
2148 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2149 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2152 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2153 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2154 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2155 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2156 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2158 // move all effects to the correct producer
2159 mltPasteEffects(clip, cut);
2161 trackPlaylist.insert_at(startPos, cut, 1);
2164 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2165 newLength = trackPlaylist.clip_length(clipIndex);
2166 mlt_service_unlock(service.get_service());
2168 } else if (serv == "framebuffer") {
2169 mlt_service_lock(service.get_service());
2170 QString url = QString::fromUtf8(clipparent.get("resource"));
2171 url = url.section('?', 0, 0);
2172 url.append('?' + QString::number(speed));
2173 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2174 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2175 if (!slowprod || slowprod->get_producer() == NULL) {
2176 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2177 slowprod->set("strobe", strobe);
2178 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2179 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2180 slowprod->set("id", producerid.toUtf8().constData());
2181 // copy producer props
2182 double ar = original->parent().get_double("force_aspect_ratio");
2183 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2184 double fps = original->parent().get_double("force_fps");
2185 if (fps != 0.0) slowprod->set("force_fps", fps);
2186 if (original->parent().get("force_progressive"))
2187 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2188 if (original->parent().get("force_tff"))
2189 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2190 int threads = original->parent().get_int("threads");
2191 if (threads != 0) slowprod->set("threads", threads);
2192 int ix = original->parent().get_int("video_index");
2193 if (ix != 0) slowprod->set("video_index", ix);
2194 int colorspace = original->parent().get_int("force_colorspace");
2195 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2196 int full_luma = original->parent().get_int("set.force_full_luma");
2197 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2198 m_slowmotionProducers.insert(url, slowprod);
2200 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2201 trackPlaylist.consolidate_blanks(0);
2203 GenTime duration = speedIndependantInfo.cropDuration / speed;
2204 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2206 // Check that the blank space is long enough for our new duration
2207 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2208 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2211 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2212 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2213 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2214 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2216 // move all effects to the correct producer
2217 mltPasteEffects(clip, cut);
2219 trackPlaylist.insert_at(startPos, cut, 1);
2222 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2223 newLength = trackPlaylist.clip_length(clipIndex);
2225 mlt_service_unlock(service.get_service());
2228 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2229 m_isBlocked = false;
2233 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2235 Mlt::Service service(m_mltProducer->parent().get_service());
2236 bool success = false;
2237 Mlt::Tractor tractor(service);
2238 Mlt::Producer trackProducer(tractor.track(track));
2239 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2240 Mlt::Service clipService(trackPlaylist.get_service());
2243 mlt_service_lock(service.get_service());
2245 Mlt::Filter *filter = clipService.filter(ct);
2247 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2248 if (clipService.detach(*filter) == 0) success = true;
2249 } else if (updateIndex) {
2250 // Adjust the other effects index
2251 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2254 filter = clipService.filter(ct);
2256 m_isBlocked = false;
2257 mlt_service_unlock(service.get_service());
2262 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2264 if (position < GenTime()) {
2265 // Remove track effect
2266 return mltRemoveTrackEffect(track, index, updateIndex);
2268 Mlt::Service service(m_mltProducer->parent().get_service());
2269 bool success = false;
2270 Mlt::Tractor tractor(service);
2271 Mlt::Producer trackProducer(tractor.track(track));
2272 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2274 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2275 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2277 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2281 Mlt::Service clipService(clip->get_service());
2282 int duration = clip->get_playtime();
2284 // Check if clip is visible in monitor
2285 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2286 if (diff < 0 || diff > duration) doRefresh = false;
2290 // if (tag.startsWith("ladspa")) tag = "ladspa";
2292 mlt_service_lock(service.get_service());
2294 Mlt::Filter *filter = clipService.filter(ct);
2296 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2297 if (clipService.detach(*filter) == 0) success = true;
2298 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2299 } else if (updateIndex) {
2300 // Adjust the other effects index
2301 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2304 filter = clipService.filter(ct);
2306 m_isBlocked = false;
2307 mlt_service_unlock(service.get_service());
2308 if (doRefresh) refresh();
2312 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2314 Mlt::Service service(m_mltProducer->parent().get_service());
2315 Mlt::Tractor tractor(service);
2316 Mlt::Producer trackProducer(tractor.track(track));
2317 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2318 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2319 return mltAddEffect(trackService, params, 15000, true);
2323 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2326 Mlt::Service service(m_mltProducer->parent().get_service());
2328 Mlt::Tractor tractor(service);
2329 Mlt::Producer trackProducer(tractor.track(track));
2330 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2332 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2333 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2338 Mlt::Service clipService(clip->get_service());
2339 int duration = clip->get_playtime();
2341 // Check if clip is visible in monitor
2342 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2343 if (diff < 0 || diff > duration) doRefresh = false;
2346 return mltAddEffect(clipService, params, duration, doRefresh);
2349 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2351 bool updateIndex = false;
2352 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2353 const QString region = params.paramValue("region");
2356 mlt_service_lock(service.get_service());
2358 Mlt::Filter *filter = service.filter(ct);
2360 if (filter->get_int("kdenlive_ix") == filter_ix) {
2361 // A filter at that position already existed, so we will increase all indexes later
2366 filter = service.filter(ct);
2369 if (params.paramValue("id") == "speed") {
2370 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2372 filter = service.filter(ct);
2374 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2375 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2378 filter = service.filter(ct);
2380 m_isBlocked = false;
2381 mlt_service_unlock(service.get_service());
2382 if (doRefresh) refresh();
2387 // temporarily remove all effects after insert point
2388 QList <Mlt::Filter *> filtersList;
2390 filter = service.filter(ct);
2392 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2393 filtersList.append(filter);
2394 service.detach(*filter);
2396 filter = service.filter(ct);
2400 QString tag = params.paramValue("tag");
2401 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2402 if (tag.startsWith("ladspa")) tag = "ladspa";
2403 char *filterTag = qstrdup(tag.toUtf8().constData());
2404 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2405 QHash<QString, QString>::Iterator it;
2406 QString kfr = params.paramValue("keyframes");
2408 if (!kfr.isEmpty()) {
2409 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2410 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2411 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2412 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2413 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2414 //double max = params.paramValue("max").toDouble();
2415 double min = params.paramValue("min").toDouble();
2416 double factor = params.paramValue("factor", "1").toDouble();
2417 params.removeParam("starttag");
2418 params.removeParam("endtag");
2419 params.removeParam("keyframes");
2420 params.removeParam("min");
2421 params.removeParam("max");
2422 params.removeParam("factor");
2424 // Special case, only one keyframe, means we want a constant value
2425 if (keyFrames.count() == 1) {
2426 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2427 if (filter && filter->is_valid()) {
2428 filter->set("kdenlive_id", filterId);
2429 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2430 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2431 for (int j = 0; j < params.count(); j++) {
2432 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2434 filter->set("in", x1);
2435 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2436 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2437 service.attach(*filter);
2439 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2440 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2441 if (filter && filter->is_valid()) {
2442 filter->set("kdenlive_id", filterId);
2443 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2444 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2445 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2446 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2447 if (x2 == -1) x2 = duration;
2449 for (int j = 0; j < params.count(); j++) {
2450 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2453 filter->set("in", x1);
2454 filter->set("out", x2);
2455 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2456 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2457 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2458 service.attach(*filter);
2465 Mlt::Filter *filter;
2467 if (!region.isEmpty()) {
2468 filter = new Mlt::Filter(*m_mltProfile, "region");
2469 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2470 if (filter && filter->is_valid()) {
2471 filter->set("kdenlive_id", filterId);
2472 if (!region.isEmpty()) {
2473 filter->set("resource", region.toUtf8().constData());
2474 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2475 filter->set("filter0", filterTag);
2476 prefix = "filter0.";
2477 params.removeParam("id");
2478 params.removeParam("region");
2479 params.removeParam("kdenlive_ix");
2482 kDebug() << "filter is NULL";
2483 m_isBlocked = false;
2484 mlt_service_unlock(service.get_service());
2487 params.removeParam("kdenlive_id");
2489 for (int j = 0; j < params.count(); j++) {
2490 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2494 QString effectArgs = params.paramValue("id").section('_', 1);
2496 params.removeParam("id");
2497 params.removeParam("kdenlive_ix");
2498 params.removeParam("tag");
2499 params.removeParam("disable");
2500 params.removeParam("region");
2502 for (int j = 0; j < params.count(); j++) {
2503 effectArgs.append(' ' + params.at(j).value());
2505 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2506 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2509 if (params.paramValue("id") == "pan_zoom") {
2510 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2513 // attach filter to the clip
2514 service.attach(*filter);
2519 // re-add following filters
2520 for (int i = 0; i < filtersList.count(); i++) {
2521 Mlt::Filter *filter = filtersList.at(i);
2523 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2524 service.attach(*filter);
2526 m_isBlocked = false;
2527 mlt_service_unlock(service.get_service());
2528 if (doRefresh) refresh();
2532 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2534 Mlt::Service service(m_mltProducer->parent().get_service());
2535 Mlt::Tractor tractor(service);
2536 Mlt::Producer trackProducer(tractor.track(track));
2537 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2538 Mlt::Service clipService(trackPlaylist.get_service());
2541 QString index = params.paramValue("kdenlive_ix");
2542 QString tag = params.paramValue("tag");
2544 Mlt::Filter *filter = clipService.filter(ct);
2546 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2550 filter = clipService.filter(ct);
2554 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2555 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2557 bool success = false;//mltAddTrackEffect(track, params);
2558 m_isBlocked = false;
2562 QString ser = filter->get("mlt_service");
2563 if (ser == "region") prefix = "filter0.";
2564 mlt_service_lock(service.get_service());
2565 for (int j = 0; j < params.count(); j++) {
2566 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2568 mlt_service_unlock(service.get_service());
2570 m_isBlocked = false;
2576 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2578 QString index = params.paramValue("kdenlive_ix");
2579 QString tag = params.paramValue("tag");
2581 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2582 // This is a keyframe effect, to edit it, we remove it and re-add it.
2583 bool success = mltRemoveEffect(track, position, index, false);
2584 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2585 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2586 else success = mltAddEffect(track, position, params);
2587 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2590 if (position < GenTime()) {
2591 return mltEditTrackEffect(track, params);
2594 Mlt::Service service(m_mltProducer->parent().get_service());
2595 Mlt::Tractor tractor(service);
2596 Mlt::Producer trackProducer(tractor.track(track));
2597 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2599 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2600 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2602 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2606 Mlt::Service clipService(clip->get_service());
2607 int duration = clip->get_playtime();
2608 bool doRefresh = true;
2609 // Check if clip is visible in monitor
2610 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2611 if (diff < 0 || diff > duration) doRefresh = false;
2615 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2616 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2618 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2620 filter = clipService.filter(ct);
2622 kDebug() << "++++++++++++++++++++++++++";
2624 filter = clipService.filter(ct); */
2626 Mlt::Filter *filter = clipService.filter(ct);
2628 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2632 filter = clipService.filter(ct);
2636 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2637 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2639 bool success = mltAddEffect(track, position, params);
2640 m_isBlocked = false;
2644 QString ser = filter->get("mlt_service");
2645 if (ser == "region") prefix = "filter0.";
2646 mlt_service_lock(service.get_service());
2647 for (int j = 0; j < params.count(); j++) {
2648 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2650 mlt_service_unlock(service.get_service());
2652 m_isBlocked = false;
2653 if (doRefresh) refresh();
2657 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2659 Mlt::Service service(m_mltProducer->parent().get_service());
2660 Mlt::Tractor tractor(service);
2661 Mlt::Producer trackProducer(tractor.track(track));
2662 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2664 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2665 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2667 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2671 Mlt::Service clipService(clip->get_service());
2672 int duration = clip->get_playtime();
2673 bool doRefresh = true;
2674 // Check if clip is visible in monitor
2675 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2676 if (diff < 0 || diff > duration) doRefresh = false;
2681 Mlt::Filter *filter = clipService.filter(ct);
2683 int pos = filter->get_int("kdenlive_ix");
2684 if (pos == oldPos) {
2685 filter->set("kdenlive_ix", newPos);
2687 filter = clipService.filter(ct);
2690 m_isBlocked = false;
2691 if (doRefresh) refresh();
2694 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2696 if (position < GenTime()) {
2697 mltMoveTrackEffect(track, oldPos, newPos);
2700 Mlt::Service service(m_mltProducer->parent().get_service());
2701 Mlt::Tractor tractor(service);
2702 Mlt::Producer trackProducer(tractor.track(track));
2703 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2705 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2706 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2708 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2712 Mlt::Service clipService(clip->get_service());
2713 int duration = clip->get_playtime();
2714 bool doRefresh = true;
2715 // Check if clip is visible in monitor
2716 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2717 if (diff < 0 || diff > duration) doRefresh = false;
2722 QList <Mlt::Filter *> filtersList;
2723 Mlt::Filter *filter = clipService.filter(ct);
2725 if (newPos > oldPos) {
2727 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2728 filter->set("kdenlive_ix", newPos);
2729 filtersList.append(filter);
2730 clipService.detach(*filter);
2731 filter = clipService.filter(ct);
2732 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2733 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2735 filter = clipService.filter(ct);
2739 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2740 filtersList.append(filter);
2741 clipService.detach(*filter);
2743 filter = clipService.filter(ct);
2747 if (filter->get_int("kdenlive_ix") == oldPos) {
2748 filter->set("kdenlive_ix", newPos);
2749 filtersList.append(filter);
2750 clipService.detach(*filter);
2752 filter = clipService.filter(ct);
2756 filter = clipService.filter(ct);
2758 int pos = filter->get_int("kdenlive_ix");
2759 if (pos >= newPos) {
2760 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2761 filtersList.append(filter);
2762 clipService.detach(*filter);
2764 filter = clipService.filter(ct);
2768 for (int i = 0; i < filtersList.count(); i++) {
2769 clipService.attach(*(filtersList.at(i)));
2772 m_isBlocked = false;
2773 if (doRefresh) refresh();
2776 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2778 Mlt::Service service(m_mltProducer->parent().get_service());
2779 Mlt::Tractor tractor(service);
2780 Mlt::Producer trackProducer(tractor.track(track));
2781 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2783 Mlt::Service clipService(trackPlaylist.get_service());
2787 QList <Mlt::Filter *> filtersList;
2788 Mlt::Filter *filter = clipService.filter(ct);
2790 if (newPos > oldPos) {
2792 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2793 filter->set("kdenlive_ix", newPos);
2794 filtersList.append(filter);
2795 clipService.detach(*filter);
2796 filter = clipService.filter(ct);
2797 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2798 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2800 filter = clipService.filter(ct);
2804 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2805 filtersList.append(filter);
2806 clipService.detach(*filter);
2808 filter = clipService.filter(ct);
2812 if (filter->get_int("kdenlive_ix") == oldPos) {
2813 filter->set("kdenlive_ix", newPos);
2814 filtersList.append(filter);
2815 clipService.detach(*filter);
2817 filter = clipService.filter(ct);
2821 filter = clipService.filter(ct);
2823 int pos = filter->get_int("kdenlive_ix");
2824 if (pos >= newPos) {
2825 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2826 filtersList.append(filter);
2827 clipService.detach(*filter);
2829 filter = clipService.filter(ct);
2833 for (int i = 0; i < filtersList.count(); i++) {
2834 clipService.attach(*(filtersList.at(i)));
2836 m_isBlocked = false;
2840 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2843 Mlt::Service service(m_mltProducer->parent().get_service());
2844 Mlt::Tractor tractor(service);
2845 Mlt::Producer trackProducer(tractor.track(info.track));
2846 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2848 /* // Display playlist info
2849 kDebug()<<"//////////// BEFORE RESIZE";
2850 for (int i = 0; i < trackPlaylist.count(); i++) {
2851 int blankStart = trackPlaylist.clip_start(i);
2852 int blankDuration = trackPlaylist.clip_length(i) - 1;
2854 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2855 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2858 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2859 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2860 m_isBlocked = false;
2863 mlt_service_lock(service.get_service());
2864 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2865 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2866 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2868 int previousStart = clip->get_in();
2869 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2870 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2872 int currentOut = newDuration + previousStart;
2873 if (currentOut > clip->get_length()) {
2874 clip->parent().set("length", currentOut + 1);
2875 clip->parent().set("out", currentOut);
2876 clip->set("length", currentOut + 1);
2879 /*if (newDuration > clip->get_out()) {
2880 clip->parent().set_in_and_out(0, newDuration + 1);
2881 clip->set_in_and_out(0, newDuration + 1);
2884 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2885 trackPlaylist.consolidate_blanks(0);
2886 // skip to next clip
2888 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2890 // clip was made longer, trim next blank if there is one.
2891 if (clipIndex < trackPlaylist.count()) {
2892 // If this is not the last clip in playlist
2893 if (trackPlaylist.is_blank(clipIndex)) {
2894 int blankStart = trackPlaylist.clip_start(clipIndex);
2895 int blankDuration = trackPlaylist.clip_length(clipIndex);
2896 if (diff > blankDuration) {
2897 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2899 if (diff - blankDuration == 0) {
2900 trackPlaylist.remove(clipIndex);
2901 } else trackPlaylist.remove_region(blankStart, diff);
2903 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2906 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2907 trackPlaylist.consolidate_blanks(0);
2908 mlt_service_unlock(service.get_service());
2910 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2911 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2912 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2913 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2914 ItemInfo transpinfo;
2915 transpinfo.startPos = info.startPos;
2916 transpinfo.endPos = info.startPos + clipDuration;
2917 transpinfo.track = info.track;
2918 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2920 m_isBlocked = false;
2921 m_mltConsumer->set("refresh", 1);
2925 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2927 Mlt::Service service(m_mltProducer->parent().get_service());
2928 Mlt::Tractor tractor(service);
2929 Mlt::Producer trackProducer(tractor.track(track));
2932 if (blind) trackProducer.set("hide", 3);
2933 else trackProducer.set("hide", 2);
2935 trackProducer.set("hide", 1);
2937 trackProducer.set("hide", 0);
2939 tractor.multitrack()->refresh();
2945 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2947 Mlt::Service service(m_mltProducer->parent().get_service());
2948 int frameOffset = (int) diff.frames(m_fps);
2949 Mlt::Tractor tractor(service);
2950 Mlt::Producer trackProducer(tractor.track(info.track));
2951 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2952 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2953 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2956 mlt_service_lock(service.get_service());
2957 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2958 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2960 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2961 mlt_service_unlock(service.get_service());
2964 int previousStart = clip->get_in();
2965 int previousOut = clip->get_out();
2968 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2969 m_isBlocked = false;
2970 mlt_service_unlock(service.get_service());
2971 m_mltConsumer->set("refresh", 1);
2975 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2977 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2978 Mlt::Service service(m_mltProducer->parent().get_service());
2979 int moveFrame = (int) diff.frames(m_fps);
2980 Mlt::Tractor tractor(service);
2981 Mlt::Producer trackProducer(tractor.track(info.track));
2982 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2983 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2984 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2987 mlt_service_lock(service.get_service());
2988 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2989 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2990 if (clip == NULL || clip->is_blank()) {
2991 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2992 mlt_service_unlock(service.get_service());
2995 int previousStart = clip->get_in();
2996 int previousOut = clip->get_out();
2999 previousStart += moveFrame;
3001 int length = previousOut + 1;
3002 if (length > clip->get_length()) {
3003 clip->parent().set("length", length + 1);
3004 clip->parent().set("out", length);
3005 clip->set("length", length + 1);
3009 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
3010 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
3011 if (moveFrame > 0) {
3012 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
3014 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
3015 int blankIndex = clipIndex - 1;
3016 int blankLength = trackPlaylist.clip_length(blankIndex);
3017 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
3018 if (! trackPlaylist.is_blank(blankIndex)) {
3019 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3021 if (blankLength + moveFrame == 0)
3022 trackPlaylist.remove(blankIndex);
3024 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3026 trackPlaylist.consolidate_blanks(0);
3027 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3028 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3029 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3030 ItemInfo transpinfo;
3031 transpinfo.startPos = info.startPos + diff;
3032 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3033 transpinfo.track = info.track;
3034 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3036 m_isBlocked = false;
3037 //m_mltConsumer->set("refresh", 1);
3038 mlt_service_unlock(service.get_service());
3039 m_mltConsumer->set("refresh", 1);
3043 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3045 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3049 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3051 if (prod == NULL || !prod->is_valid()) {
3052 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3055 kDebug() << "NEW PROD ID: " << prod->get("id");
3057 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3058 Mlt::Service service(m_mltProducer->parent().get_service());
3059 if (service.type() != tractor_type) {
3060 kWarning() << "// TRACTOR PROBLEM";
3063 mlt_service_lock(service.get_service());
3064 Mlt::Tractor tractor(service);
3065 Mlt::Producer trackProducer(tractor.track(track));
3066 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3067 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3068 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3069 if (clipProducer == NULL || clipProducer->is_blank()) {
3070 kDebug() << "// ERROR UPDATING CLIP PROD";
3071 delete clipProducer;
3072 mlt_service_unlock(service.get_service());
3076 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3077 if (!clip || !clip->is_valid()) {
3078 if (clip) delete clip;
3079 delete clipProducer;
3080 mlt_service_unlock(service.get_service());
3084 // move all effects to the correct producer
3085 mltPasteEffects(clipProducer, clip);
3086 trackPlaylist.insert_at(pos, clip, 1);
3088 delete clipProducer;
3089 mlt_service_unlock(service.get_service());
3094 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3098 Mlt::Service service(m_mltProducer->parent().get_service());
3099 if (service.type() != tractor_type) {
3100 kWarning() << "// TRACTOR PROBLEM";
3104 Mlt::Tractor tractor(service);
3105 mlt_service_lock(service.get_service());
3106 Mlt::Producer trackProducer(tractor.track(startTrack));
3107 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3108 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3109 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3110 bool checkLength = false;
3111 if (endTrack == startTrack) {
3112 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3113 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3114 // error, destination is not empty
3116 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3117 delete clipProducer;
3119 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3120 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3121 mlt_service_unlock(service.get_service());
3125 trackPlaylist.consolidate_blanks(0);
3127 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3128 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3129 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3131 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3132 trackPlaylist.consolidate_blanks(1);
3133 delete clipProducer;
3134 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3135 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3137 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3139 //mlt_service_unlock(service.get_service());
3141 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3142 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3143 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3144 // error, destination is not empty
3145 mlt_service_unlock(service.get_service());
3149 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3150 if (!clipProducer || clipProducer->is_blank()) {
3151 // error, destination is not empty
3152 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3153 if (clipProducer) delete clipProducer;
3154 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3155 mlt_service_unlock(service.get_service());
3159 trackPlaylist.consolidate_blanks(0);
3160 destTrackPlaylist.consolidate_blanks(1);
3161 Mlt::Producer *clip;
3162 // check if we are moving a slowmotion producer
3163 QString serv = clipProducer->parent().get("mlt_service");
3164 QString currentid = clipProducer->parent().get("id");
3165 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3166 clip = clipProducer;
3169 // Special case: prod is null when using placeholder clips.
3170 // in that case, use the producer existing in playlist. Note that
3171 // it will bypass the one producer per track logic and might cause
3172 // Sound cracks if clip is moved so that it overlaps another copy of itself
3173 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3174 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3177 // move all effects to the correct producer
3178 mltPasteEffects(clipProducer, clip);
3181 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3182 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3183 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3186 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3188 if (clip == clipProducer) {
3193 delete clipProducer;
3195 destTrackPlaylist.consolidate_blanks(0);
3196 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3197 kDebug() << "//////// moving clip transparency";
3198 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3200 if (clipIndex > trackPlaylist.count()) checkLength = true;
3201 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3204 mlt_service_unlock(service.get_service());
3205 if (checkLength) mltCheckLength(&tractor);
3208 //m_mltConsumer->set("refresh", 1);
3213 QList <int> Render::checkTrackSequence(int track)
3216 Mlt::Service service(m_mltProducer->parent().get_service());
3217 if (service.type() != tractor_type) {
3218 kWarning() << "// TRACTOR PROBLEM";
3221 Mlt::Tractor tractor(service);
3222 mlt_service_lock(service.get_service());
3223 Mlt::Producer trackProducer(tractor.track(track));
3224 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3225 int clipNb = trackPlaylist.count();
3226 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3227 for (int i = 0; i < clipNb; i++) {
3228 Mlt::Producer *c = trackPlaylist.get_clip(i);
3229 int pos = trackPlaylist.clip_start(i);
3230 if (!list.contains(pos)) list.append(pos);
3231 pos += c->get_playtime();
3232 if (!list.contains(pos)) list.append(pos);
3238 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3240 int new_in = (int)newIn.frames(m_fps);
3241 int new_out = (int)newOut.frames(m_fps) - 1;
3242 if (new_in >= new_out) return false;
3243 int old_in = (int)oldIn.frames(m_fps);
3244 int old_out = (int)oldOut.frames(m_fps) - 1;
3246 Mlt::Service service(m_mltProducer->parent().get_service());
3247 Mlt::Tractor tractor(service);
3248 Mlt::Field *field = tractor.field();
3250 bool doRefresh = true;
3251 // Check if clip is visible in monitor
3252 int diff = old_out - m_mltProducer->position();
3253 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3255 diff = new_out - m_mltProducer->position();
3256 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3260 mlt_service_lock(service.get_service());
3262 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3263 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3264 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3265 QString resource = mlt_properties_get(properties, "mlt_service");
3266 int old_pos = (int)(old_in + old_out) / 2;
3269 while (mlt_type == "transition") {
3270 Mlt::Transition transition((mlt_transition) nextservice);
3271 int currentTrack = transition.get_b_track();
3272 int currentIn = (int) transition.get_in();
3273 int currentOut = (int) transition.get_out();
3275 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3277 if (newTrack - startTrack != 0) {
3278 Mlt::Properties trans_props(transition.get_properties());
3279 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3280 Mlt::Properties new_trans_props(new_transition.get_properties());
3281 new_trans_props.inherit(trans_props);
3282 new_transition.set_in_and_out(new_in, new_out);
3283 field->disconnect_service(transition);
3284 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3285 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3286 } else transition.set_in_and_out(new_in, new_out);
3289 nextservice = mlt_service_producer(nextservice);
3290 if (nextservice == NULL) break;
3291 properties = MLT_SERVICE_PROPERTIES(nextservice);
3292 mlt_type = mlt_properties_get(properties, "mlt_type");
3293 resource = mlt_properties_get(properties, "mlt_service");
3295 mlt_service_unlock(service.get_service());
3297 if (doRefresh) refresh();
3298 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3303 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3305 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3306 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3307 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3308 QString resource = mlt_properties_get(properties, "mlt_service");
3309 QList <Mlt::Transition *> trList;
3311 while (mlt_type == "transition") {
3312 Mlt::Transition transition((mlt_transition) nextservice);
3313 int aTrack = transition.get_a_track();
3314 int bTrack = transition.get_b_track();
3315 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3316 Mlt::Properties trans_props(transition.get_properties());
3317 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3318 Mlt::Properties new_trans_props(cp->get_properties());
3319 new_trans_props.inherit(trans_props);
3321 field->disconnect_service(transition);
3323 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3325 nextservice = mlt_service_producer(nextservice);
3326 if (nextservice == NULL) break;
3327 properties = MLT_SERVICE_PROPERTIES(nextservice);
3328 mlt_type = mlt_properties_get(properties, "mlt_type");
3329 resource = mlt_properties_get(properties, "mlt_service");
3332 field->plant_transition(tr, a_track, b_track);
3334 // re-add upper transitions
3335 for (int i = 0; i < trList.count(); i++) {
3336 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3337 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3341 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3343 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3345 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3346 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3349 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3352 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3354 mlt_service serv = m_mltProducer->parent().get_service();
3355 mlt_service_lock(serv);
3358 mlt_service nextservice = mlt_service_get_producer(serv);
3359 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3360 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3361 QString resource = mlt_properties_get(properties, "mlt_service");
3362 int in_pos = (int) in.frames(m_fps);
3363 int out_pos = (int) out.frames(m_fps) - 1;
3365 while (mlt_type == "transition") {
3366 mlt_transition tr = (mlt_transition) nextservice;
3367 int currentTrack = mlt_transition_get_b_track(tr);
3368 int currentBTrack = mlt_transition_get_a_track(tr);
3369 int currentIn = (int) mlt_transition_get_in(tr);
3370 int currentOut = (int) mlt_transition_get_out(tr);
3372 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3374 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3375 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3376 QMap<QString, QString>::Iterator it;
3378 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3380 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3381 if (currentId != xml.attribute("id")) {
3382 // The transition ID is not the same, so reset all properties
3383 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3384 // Cleanup previous properties
3385 QStringList permanentProps;
3386 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3387 permanentProps << "out" << "a_track" << "b_track";
3388 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3389 QString propName = mlt_properties_get_name(transproperties, i);
3390 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3391 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3396 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3397 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3399 if (currentBTrack != a_track) {
3400 mlt_properties_set_int(transproperties, "a_track", a_track);
3402 for (it = map.begin(); it != map.end(); ++it) {
3404 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3405 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3406 //filter->set("kdenlive_id", id);
3410 nextservice = mlt_service_producer(nextservice);
3411 if (nextservice == NULL) break;
3412 properties = MLT_SERVICE_PROPERTIES(nextservice);
3413 mlt_type = mlt_properties_get(properties, "mlt_type");
3414 resource = mlt_properties_get(properties, "mlt_service");
3416 mlt_service_unlock(serv);
3419 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3422 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3424 mlt_service serv = m_mltProducer->parent().get_service();
3426 mlt_service_lock(serv);
3428 Mlt::Service service(serv);
3429 Mlt::Tractor tractor(service);
3430 Mlt::Field *field = tractor.field();
3432 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3434 mlt_service nextservice = mlt_service_get_producer(serv);
3435 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3436 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3437 QString resource = mlt_properties_get(properties, "mlt_service");
3439 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3440 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3442 while (mlt_type == "transition") {
3443 mlt_transition tr = (mlt_transition) nextservice;
3444 int currentTrack = mlt_transition_get_b_track(tr);
3445 int currentIn = (int) mlt_transition_get_in(tr);
3446 int currentOut = (int) mlt_transition_get_out(tr);
3447 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3449 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3450 mlt_field_disconnect_service(field->get_field(), nextservice);
3453 nextservice = mlt_service_producer(nextservice);
3454 if (nextservice == NULL) break;
3455 properties = MLT_SERVICE_PROPERTIES(nextservice);
3456 mlt_type = mlt_properties_get(properties, "mlt_type");
3457 resource = mlt_properties_get(properties, "mlt_service");
3459 mlt_service_unlock(serv);
3462 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3465 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3467 QDomNodeList attribs = xml.elementsByTagName("parameter");
3468 QMap<QString, QString> map;
3469 for (int i = 0; i < attribs.count(); i++) {
3470 QDomElement e = attribs.item(i).toElement();
3471 QString name = e.attribute("name");
3472 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3473 map[name] = e.attribute("default");
3474 if (!e.attribute("value").isEmpty()) {
3475 map[name] = e.attribute("value");
3477 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3478 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3479 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3482 if (e.attribute("namedesc").contains(';')) {
3483 QString format = e.attribute("format");
3484 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3485 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3487 QTextStream txtNeu(&neu);
3488 if (values.size() > 0)
3489 txtNeu << (int)values[0].toDouble();
3491 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3492 txtNeu << separators[i];
3493 txtNeu << (int)(values[i+1].toDouble());
3495 if (i < separators.size())
3496 txtNeu << separators[i];
3497 map[e.attribute("name")] = neu;
3504 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3506 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3507 Mlt::Service service(m_mltProducer->parent().get_service());
3508 Mlt::Tractor tractor(service);
3509 Mlt::Field *field = tractor.field();
3511 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3512 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3513 transition->set("transparency", id);
3514 transition->set("fill", 1);
3515 transition->set("internal_added", 237);
3516 field->plant_transition(*transition, transitiontrack, info.track);
3520 void Render::mltDeleteTransparency(int pos, int track, int id)
3522 Mlt::Service service(m_mltProducer->parent().get_service());
3523 Mlt::Tractor tractor(service);
3524 Mlt::Field *field = tractor.field();
3526 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3527 mlt_service serv = m_mltProducer->parent().get_service();
3529 mlt_service nextservice = mlt_service_get_producer(serv);
3530 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3531 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3532 QString resource = mlt_properties_get(properties, "mlt_service");
3534 while (mlt_type == "transition") {
3535 mlt_transition tr = (mlt_transition) nextservice;
3536 int currentTrack = mlt_transition_get_b_track(tr);
3537 int currentIn = (int) mlt_transition_get_in(tr);
3538 int currentOut = (int) mlt_transition_get_out(tr);
3539 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3540 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3542 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3543 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3544 mlt_field_disconnect_service(field->get_field(), nextservice);
3547 nextservice = mlt_service_producer(nextservice);
3548 if (nextservice == NULL) break;
3549 properties = MLT_SERVICE_PROPERTIES(nextservice);
3550 mlt_type = mlt_properties_get(properties, "mlt_type");
3551 resource = mlt_properties_get(properties, "mlt_service");
3553 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3556 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3558 Mlt::Service service(m_mltProducer->parent().get_service());
3559 Mlt::Tractor tractor(service);
3561 mlt_service_lock(service.get_service());
3562 m_mltConsumer->set("refresh", 0);
3565 mlt_service serv = m_mltProducer->parent().get_service();
3566 mlt_service nextservice = mlt_service_get_producer(serv);
3567 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3568 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3569 QString resource = mlt_properties_get(properties, "mlt_service");
3570 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3571 while (mlt_type == "transition") {
3572 mlt_transition tr = (mlt_transition) nextservice;
3573 int currentTrack = mlt_transition_get_b_track(tr);
3574 int currentIn = (int) mlt_transition_get_in(tr);
3575 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3576 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3577 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3578 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3579 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3580 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3583 nextservice = mlt_service_producer(nextservice);
3584 if (nextservice == NULL) break;
3585 properties = MLT_SERVICE_PROPERTIES(nextservice);
3586 mlt_type = mlt_properties_get(properties, "mlt_type");
3587 resource = mlt_properties_get(properties, "mlt_service");
3589 mlt_service_unlock(service.get_service());
3591 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3595 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3597 Mlt::Service service(m_mltProducer->parent().get_service());
3598 Mlt::Tractor tractor(service);
3600 mlt_service_lock(service.get_service());
3601 m_mltConsumer->set("refresh", 0);
3604 mlt_service serv = m_mltProducer->parent().get_service();
3605 mlt_service nextservice = mlt_service_get_producer(serv);
3606 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3607 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3608 QString resource = mlt_properties_get(properties, "mlt_service");
3610 while (mlt_type == "transition") {
3611 mlt_transition tr = (mlt_transition) nextservice;
3612 int currentTrack = mlt_transition_get_b_track(tr);
3613 int currentaTrack = mlt_transition_get_a_track(tr);
3614 int currentIn = (int) mlt_transition_get_in(tr);
3615 int currentOut = (int) mlt_transition_get_out(tr);
3616 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3617 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3618 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3619 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3620 kDebug() << "//////MOVING";
3621 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3622 if (endTrack != startTrack) {
3623 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3624 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3625 mlt_properties_set_int(properties, "b_track", endTrack);
3629 nextservice = mlt_service_producer(nextservice);
3630 if (nextservice == NULL) break;
3631 properties = MLT_SERVICE_PROPERTIES(nextservice);
3632 mlt_type = mlt_properties_get(properties, "mlt_type");
3633 resource = mlt_properties_get(properties, "mlt_service");
3636 mlt_service_unlock(service.get_service());
3637 m_mltConsumer->set("refresh", 1);
3641 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3643 if (in >= out) return false;
3644 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3645 Mlt::Service service(m_mltProducer->parent().get_service());
3647 Mlt::Tractor tractor(service);
3648 Mlt::Field *field = tractor.field();
3650 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3651 if (out != GenTime())
3652 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3654 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3655 QMap<QString, QString>::Iterator it;
3657 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3658 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3659 if (xml.hasAttribute("id"))
3660 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3662 for (it = args.begin(); it != args.end(); ++it) {
3664 if (!it.value().isEmpty())
3665 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3666 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3668 // attach transition
3669 mltPlantTransition(field, *transition, a_track, b_track);
3670 // field->plant_transition(*transition, a_track, b_track);
3671 if (do_refresh) refresh();
3675 void Render::mltSavePlaylist()
3677 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3678 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3679 fileConsumer.set("resource", "/tmp/playlist.mlt");
3681 Mlt::Service service(m_mltProducer->get_service());
3683 fileConsumer.connect(service);
3684 fileConsumer.start();
3687 const QList <Mlt::Producer *> Render::producersList()
3689 QList <Mlt::Producer *> prods;
3690 if (m_mltProducer == NULL) return prods;
3691 Mlt::Service service(m_mltProducer->parent().get_service());
3692 if (service.type() != tractor_type) return prods;
3693 Mlt::Tractor tractor(service);
3696 int trackNb = tractor.count();
3697 for (int t = 1; t < trackNb; t++) {
3698 Mlt::Producer *tt = tractor.track(t);
3699 Mlt::Producer trackProducer(tt);
3701 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3702 int clipNb = trackPlaylist.count();
3703 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3704 for (int i = 0; i < clipNb; i++) {
3705 Mlt::Producer *c = trackPlaylist.get_clip(i);
3706 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3708 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3709 ids.append(nprod->get("id"));
3710 prods.append(nprod);
3711 } else delete nprod;
3719 void Render::fillSlowMotionProducers()
3721 if (m_mltProducer == NULL) return;
3722 Mlt::Service service(m_mltProducer->parent().get_service());
3723 if (service.type() != tractor_type) return;
3725 Mlt::Tractor tractor(service);
3727 int trackNb = tractor.count();
3728 for (int t = 1; t < trackNb; t++) {
3729 Mlt::Producer *tt = tractor.track(t);
3730 Mlt::Producer trackProducer(tt);
3732 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3733 int clipNb = trackPlaylist.count();
3734 for (int i = 0; i < clipNb; i++) {
3735 Mlt::Producer *c = trackPlaylist.get_clip(i);
3736 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3738 QString id = nprod->get("id");
3739 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3740 // this is a slowmotion producer, add it to the list
3741 QString url = QString::fromUtf8(nprod->get("resource"));
3742 int strobe = nprod->get_int("strobe");
3743 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3744 if (!m_slowmotionProducers.contains(url)) {
3745 m_slowmotionProducers.insert(url, nprod);
3747 } else delete nprod;
3754 void Render::mltInsertTrack(int ix, bool videoTrack)
3759 Mlt::Service service(m_mltProducer->parent().get_service());
3760 mlt_service_lock(service.get_service());
3761 if (service.type() != tractor_type) {
3762 kWarning() << "// TRACTOR PROBLEM";
3766 Mlt::Tractor tractor(service);
3768 Mlt::Playlist playlist;
3769 int ct = tractor.count();
3771 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3777 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3778 tractor.set_track(playlist, pos);
3779 Mlt::Producer newProd(tractor.track(pos));
3780 if (!videoTrack) newProd.set("hide", 1);
3782 for (; pos <= ct; pos++) {
3783 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3784 tractor.set_track(*prodToMove, pos);
3785 prodToMove = prodToMove2;
3788 tractor.set_track(playlist, ix);
3789 Mlt::Producer newProd(tractor.track(ix));
3790 if (!videoTrack) newProd.set("hide", 1);
3794 mlt_service serv = m_mltProducer->parent().get_service();
3795 mlt_service nextservice = mlt_service_get_producer(serv);
3796 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3797 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3798 QString resource = mlt_properties_get(properties, "mlt_service");
3800 while (mlt_type == "transition") {
3801 if (resource != "mix") {
3802 mlt_transition tr = (mlt_transition) nextservice;
3803 int currentTrack = mlt_transition_get_b_track(tr);
3804 int currentaTrack = mlt_transition_get_a_track(tr);
3805 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3807 if (currentTrack >= ix) {
3808 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3809 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3812 nextservice = mlt_service_producer(nextservice);
3813 if (nextservice == NULL) break;
3814 properties = MLT_SERVICE_PROPERTIES(nextservice);
3815 mlt_type = mlt_properties_get(properties, "mlt_type");
3816 resource = mlt_properties_get(properties, "mlt_service");
3819 // Add audio mix transition to last track
3820 Mlt::Field *field = tractor.field();
3821 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3822 transition->set("a_track", 1);
3823 transition->set("b_track", ct);
3824 transition->set("always_active", 1);
3825 transition->set("internal_added", 237);
3826 transition->set("combine", 1);
3827 field->plant_transition(*transition, 1, ct);
3828 //mlt_service_unlock(m_mltConsumer->get_service());
3829 mlt_service_unlock(service.get_service());
3830 //tractor.multitrack()->refresh();
3831 //tractor.refresh();
3833 blockSignals(false);
3837 void Render::mltDeleteTrack(int ix)
3840 doc.setContent(sceneList(), false);
3841 int tracksCount = doc.elementsByTagName("track").count() - 1;
3842 QDomNode track = doc.elementsByTagName("track").at(ix);
3843 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3844 QDomNodeList transitions = doc.elementsByTagName("transition");
3845 for (int i = 0; i < transitions.count(); i++) {
3846 QDomElement e = transitions.at(i).toElement();
3847 QDomNodeList props = e.elementsByTagName("property");
3848 QMap <QString, QString> mappedProps;
3849 for (int j = 0; j < props.count(); j++) {
3850 QDomElement f = props.at(j).toElement();
3851 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3853 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3854 tractor.removeChild(transitions.at(i));
3856 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3857 // Transition needs to be moved
3858 int a_track = mappedProps.value("a_track").toInt();
3859 int b_track = mappedProps.value("b_track").toInt();
3860 if (a_track > 0 && a_track >= ix) a_track --;
3861 if (b_track == ix) {
3862 // transition was on the deleted track, so remove it
3863 tractor.removeChild(transitions.at(i));
3867 if (b_track > 0 && b_track > ix) b_track --;
3868 for (int j = 0; j < props.count(); j++) {
3869 QDomElement f = props.at(j).toElement();
3870 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3871 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3876 tractor.removeChild(track);
3877 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3878 setSceneList(doc.toString(), m_framePosition);
3880 /* if (m_mltProducer != NULL) {
3881 Mlt::Producer parentProd(m_mltProducer->parent());
3882 if (parentProd.get_producer() != NULL) {
3883 Mlt::Service service(parentProd.get_service());
3884 if (service.type() == tractor_type) {
3885 Mlt::Tractor tractor(service);
3886 mltCheckLength(&tractor);
3893 void Render::updatePreviewSettings()
3895 kDebug() << "////// RESTARTING CONSUMER";
3896 if (!m_mltConsumer || !m_mltProducer) return;
3897 if (m_mltProducer->get_playtime() == 0) return;
3898 Mlt::Service service(m_mltProducer->parent().get_service());
3899 if (service.type() != tractor_type) return;
3901 //m_mltConsumer->set("refresh", 0);
3902 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3903 m_mltConsumer->purge();
3904 QString scene = sceneList();
3906 if (m_mltProducer) {
3907 pos = m_mltProducer->position();
3910 setSceneList(scene, pos);
3914 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3916 // Update all frame positions to the new fps value
3917 //WARNING: there are probably some effects or other that hold a frame value
3918 // as parameter and will also need to be updated here!
3920 doc.setContent(scene);
3922 double factor = new_fps / current_fps;
3923 QDomNodeList producers = doc.elementsByTagName("producer");
3924 for (int i = 0; i < producers.count(); i++) {
3925 QDomElement prod = producers.at(i).toElement();
3926 prod.removeAttribute("in");
3927 prod.removeAttribute("out");
3929 QDomNodeList props = prod.childNodes();
3930 for (int j = 0; j < props.count(); j++) {
3931 QDomElement param = props.at(j).toElement();
3932 QString paramName = param.attribute("name");
3933 if (paramName.startsWith("meta.") || paramName == "length") {
3934 prod.removeChild(props.at(j));
3940 QDomNodeList entries = doc.elementsByTagName("entry");
3941 for (int i = 0; i < entries.count(); i++) {
3942 QDomElement entry = entries.at(i).toElement();
3943 int in = entry.attribute("in").toInt();
3944 int out = entry.attribute("out").toInt();
3945 in = factor * in + 0.5;
3946 out = factor * out + 0.5;
3947 entry.setAttribute("in", in);
3948 entry.setAttribute("out", out);
3951 QDomNodeList blanks = doc.elementsByTagName("blank");
3952 for (int i = 0; i < blanks.count(); i++) {
3953 QDomElement blank = blanks.at(i).toElement();
3954 int length = blank.attribute("length").toInt();
3955 length = factor * length + 0.5;
3956 blank.setAttribute("length", QString::number(length));
3959 QDomNodeList filters = doc.elementsByTagName("filter");
3960 for (int i = 0; i < filters.count(); i++) {
3961 QDomElement filter = filters.at(i).toElement();
3962 int in = filter.attribute("in").toInt();
3963 int out = filter.attribute("out").toInt();
3964 in = factor * in + 0.5;
3965 out = factor * out + 0.5;
3966 filter.setAttribute("in", in);
3967 filter.setAttribute("out", out);
3970 QDomNodeList transitions = doc.elementsByTagName("transition");
3971 for (int i = 0; i < transitions.count(); i++) {
3972 QDomElement transition = transitions.at(i).toElement();
3973 int in = transition.attribute("in").toInt();
3974 int out = transition.attribute("out").toInt();
3975 in = factor * in + 0.5;
3976 out = factor * out + 0.5;
3977 transition.setAttribute("in", in);
3978 transition.setAttribute("out", out);
3979 QDomNodeList props = transition.childNodes();
3980 for (int j = 0; j < props.count(); j++) {
3981 QDomElement param = props.at(j).toElement();
3982 QString paramName = param.attribute("name");
3983 if (paramName == "geometry") {
3984 QString geom = param.firstChild().nodeValue();
3985 QStringList keys = geom.split(';');
3986 QStringList newKeys;
3987 for (int k = 0; k < keys.size(); ++k) {
3988 if (keys.at(k).contains('=')) {
3989 int pos = keys.at(k).section('=', 0, 0).toInt();
3990 pos = factor * pos + 0.5;
3991 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3992 } else newKeys.append(keys.at(k));
3994 param.firstChild().setNodeValue(newKeys.join(";"));
3998 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3999 int out = tractor.attribute("out").toInt();
4000 out = factor * out + 0.5;
4001 tractor.setAttribute("out", out);
4002 emit durationChanged(out);
4004 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
4005 return doc.toString();
4009 void Render::sendFrameUpdate()
4011 if (m_mltProducer) {
4012 Mlt::Frame * frame = m_mltProducer->get_frame();
4013 emitFrameUpdated(*frame);
4019 #include "renderer.moc"