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"
32 #include <mlt++/Mlt.h>
35 #include <KStandardDirs>
36 #include <KMessageBox>
38 #include <KTemporaryFile>
43 #include <QApplication>
50 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
52 if (level > MLT_LOG_ERROR) return;
54 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
59 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
61 // detect if the producer has finished playing. Is there a better way to do it?
62 if (self->m_isBlocked) return;
63 Mlt::Frame frame(frame_ptr);
64 if (!frame.is_valid()) return;
65 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
66 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
67 self->emitFrameUpdated(frame);
69 self->showAudio(frame);
70 if (frame.get_double("_speed") == 0.0) {
71 self->emitConsumerStopped();
72 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
74 self->emitConsumerStopped();
78 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
80 // detect if the producer has finished playing. Is there a better way to do it?
81 if (self->m_isBlocked) return;
82 Mlt::Frame frame(frame_ptr);
83 self->showFrame(frame);
84 if (frame.get_double("_speed") == 0.0) {
85 self->emitConsumerStopped();
86 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
88 self->emitConsumerStopped();
92 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
95 sendFrameForAnalysis(false),
103 m_isSplitView(false),
107 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
108 buildConsumer(profile);
110 m_mltProducer = m_blackClip->cut(0, 50);
111 m_mltConsumer->connect(*m_mltProducer);
112 m_mltProducer->set_speed(0.0);
122 void Render::closeMlt()
126 Mlt::Service service(m_mltProducer->parent().get_service());
127 mlt_service_lock(service.get_service());
129 if (service.type() == tractor_type) {
130 Mlt::Tractor tractor(service);
131 Mlt::Field *field = tractor.field();
132 mlt_service nextservice = mlt_service_get_producer(service.get_service());
133 mlt_service nextservicetodisconnect;
134 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
135 QString mlt_type = mlt_properties_get(properties, "mlt_type");
136 QString resource = mlt_properties_get(properties, "mlt_service");
137 // Delete all transitions
138 while (mlt_type == "transition") {
139 nextservicetodisconnect = nextservice;
140 nextservice = mlt_service_producer(nextservice);
141 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
142 nextservice = mlt_service_producer(nextservice);
143 if (nextservice == NULL) break;
144 properties = MLT_SERVICE_PROPERTIES(nextservice);
145 mlt_type = mlt_properties_get(properties, "mlt_type");
146 resource = mlt_properties_get(properties, "mlt_service");
149 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
150 Mlt::Producer trackProducer(tractor.track(trackNb));
151 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
152 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
155 mlt_service_unlock(service.get_service());
158 kDebug() << "// // // CLOSE RENDERER " << m_name;
159 delete m_mltConsumer;
160 delete m_mltProducer;
165 void Render::slotSwitchFullscreen()
167 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
170 void Render::buildConsumer(const QString profileName)
172 m_activeProfile = profileName;
173 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
174 setenv("MLT_PROFILE", tmp, 1);
178 //TODO: uncomment following line when everything is clean
179 //if (m_mltProfile) delete m_mltProfile;
180 m_mltProfile = new Mlt::Profile(tmp);
181 m_mltProfile->get_profile()->is_explicit = 1;
184 QString videoDriver = KdenliveSettings::videodrivername();
185 if (!videoDriver.isEmpty()) {
186 if (videoDriver == "x11_noaccel") {
187 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
190 unsetenv("SDL_VIDEO_YUV_HWACCEL");
193 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
195 //m_mltConsumer->set("fullscreen", 1);
198 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
199 m_mltConsumer->set("preview_off", 1);
200 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
201 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
203 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
204 // FIXME: the event object returned by the listen gets leaked...
205 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
206 m_mltConsumer->set("window_id", m_winid);
208 m_mltConsumer->set("resize", 1);
209 m_mltConsumer->set("terminate_on_pause", 1);
210 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
211 m_mltConsumer->set("rescale", "nearest");
212 mlt_log_set_callback(kdenlive_callback);
214 QString audioDevice = KdenliveSettings::audiodevicename();
215 if (!audioDevice.isEmpty())
216 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
218 if (!videoDriver.isEmpty())
219 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
221 QString audioDriver = KdenliveSettings::audiodrivername();
224 // Disabled because the "auto" detected driver was sometimes wrong
225 if (audioDriver.isEmpty())
226 audioDriver = KdenliveSettings::autoaudiodrivername();
229 if (!audioDriver.isEmpty())
230 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
232 m_mltConsumer->set("progressive", 1);
233 m_mltConsumer->set("audio_buffer", 1024);
234 m_mltConsumer->set("frequency", 48000);
236 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
237 m_blackClip->set("id", "black");
238 m_blackClip->set("mlt_type", "producer");
241 Mlt::Producer *Render::invalidProducer(const QString &id)
243 Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
244 clip->set("id", id.toUtf8().constData());
245 clip->set("mlt_type", "producer");
249 int Render::resetProfile(const QString profileName)
252 QString videoDriver = KdenliveSettings::videodrivername();
253 QString currentDriver = m_mltConsumer->get("video_driver");
254 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
255 QString background = KdenliveSettings::window_background().name();
256 QString currentBackground = m_mltConsumer->get("window_background");
257 if (m_activeProfile == profileName && currentDriver == videoDriver && background == currentBackground) {
258 kDebug() << "reset to same profile, nothing to do";
262 if (m_isSplitView) slotSplitView(false);
263 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
264 m_mltConsumer->purge();
265 delete m_mltConsumer;
266 m_mltConsumer = NULL;
268 QString scene = sceneList();
270 double current_fps = m_mltProfile->fps();
275 pos = m_mltProducer->position();
277 Mlt::Service service(m_mltProducer->get_service());
278 if (service.type() == tractor_type) {
279 Mlt::Tractor tractor(service);
280 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
281 Mlt::Producer trackProducer(tractor.track(trackNb));
282 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
283 trackPlaylist.clear();
287 delete m_mltProducer;
289 m_mltProducer = NULL;
290 buildConsumer(profileName);
291 double new_fps = m_mltProfile->fps();
292 if (current_fps != new_fps) {
293 // fps changed, we must update the scenelist positions
294 scene = updateSceneListFps(current_fps, new_fps, scene);
296 //kDebug() << "//RESET WITHSCENE: " << scene;
297 setSceneList(scene, pos);
298 // producers have changed (different profile), so reset them...
299 emit refreshDocumentProducers();
300 /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
301 m_mltProducer = producer;
302 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
303 m_mltProducer->optimise();
304 m_mltProducer->set_speed(0);
307 //delete m_mltProfile;
308 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
309 //mlt_profile prof = m_mltProfile->get_profile();
310 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
311 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
312 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
313 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
315 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
320 void Render::seek(GenTime time)
325 m_mltProducer->seek((int)(time.frames(m_fps)));
330 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
331 QPixmap pix(width, height);
333 mlt_image_format format = mlt_image_rgb24a;
334 uint8_t *thumb = frame->get_image(format, width, height);
335 QImage image(thumb, width, height, QImage::Format_ARGB32);
337 if (!image.isNull()) {
338 pix = pix.fromImage(image);
340 QPainter painter(&pix);
341 painter.drawRect(0, 0, width - 1, height - 1);
343 } else pix.fill(Qt::black);
347 int Render::frameRenderWidth() const
349 return m_mltProfile->width();
352 int Render::renderWidth() const
354 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
357 int Render::renderHeight() const
359 return m_mltProfile->height();
362 QImage Render::extractFrame(int frame_position, int width, int height)
365 width = renderWidth();
366 height = renderHeight();
367 } else if (width % 2 == 1) width++;
369 if (!m_mltProducer) {
370 QImage pix(width, height, QImage::Format_RGB32);
374 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
377 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
381 if (url.fileName().startsWith(".all.")) { // check for slideshow
382 QString fileType = url.fileName().right(3);
384 QStringList::Iterator it;
386 QDir dir(url.directory());
388 filter << "*." + fileType;
389 filter << "*." + fileType.toUpper();
390 more = dir.entryList(filter, QDir::Files);
391 im.load(url.directory() + '/' + more.at(0));
392 } else im.load(url.path());
393 //pixmap = im.scaled(width, height);
397 double Render::consumerRatio() const
399 if (!m_mltConsumer) return 1.0;
400 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
404 int Render::getLength()
408 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
409 return mlt_producer_get_playtime(m_mltProducer->get_producer());
414 bool Render::isValid(KUrl url)
416 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
417 if (producer.is_blank())
423 double Render::dar() const
425 return m_mltProfile->dar();
429 void Render::slotSplitView(bool doit)
431 m_isSplitView = doit;
432 Mlt::Service service(m_mltProducer->parent().get_service());
433 Mlt::Tractor tractor(service);
434 if (service.type() != tractor_type || tractor.count() < 2) return;
435 Mlt::Field *field = tractor.field();
437 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
438 Mlt::Producer trackProducer(tractor.track(i));
439 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
440 if (QString(trackProducer.get("hide")).toInt() != 1) {
441 kDebug() << "// ADIDNG TRACK: " << i;
442 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
443 transition->set("mlt_service", "composite");
444 transition->set("a_track", 0);
445 transition->set("b_track", i);
446 transition->set("distort", 1);
447 transition->set("internal_added", "200");
454 tmp = "50%,0:50%x50%";
457 tmp = "0,50%:50%x50%";
461 tmp = "50%,50%:50%x50%";
464 transition->set("geometry", tmp);
465 transition->set("always_active", "1");
466 field->plant_transition(*transition, 0, i);
471 m_mltConsumer->set("refresh", 1);
473 mlt_service serv = m_mltProducer->parent().get_service();
474 mlt_service nextservice = mlt_service_get_producer(serv);
475 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
476 QString mlt_type = mlt_properties_get(properties, "mlt_type");
477 QString resource = mlt_properties_get(properties, "mlt_service");
479 while (mlt_type == "transition") {
480 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
481 if (added == "200") {
482 mlt_field_disconnect_service(field->get_field(), nextservice);
484 nextservice = mlt_service_producer(nextservice);
485 if (nextservice == NULL) break;
486 properties = MLT_SERVICE_PROPERTIES(nextservice);
487 mlt_type = mlt_properties_get(properties, "mlt_type");
488 resource = mlt_properties_get(properties, "mlt_service");
489 m_mltConsumer->set("refresh", 1);
494 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
496 KUrl url = KUrl(xml.attribute("resource", QString()));
497 Mlt::Producer *producer = NULL;
498 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
499 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
500 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
503 if (xml.attribute("type").toInt() == COLOR) {
504 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
505 } else if (xml.attribute("type").toInt() == TEXT) {
506 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
507 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
508 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
509 } else if (url.isEmpty()) {
511 QDomElement mlt = doc.createElement("mlt");
512 QDomElement play = doc.createElement("playlist");
513 doc.appendChild(mlt);
514 mlt.appendChild(play);
515 play.appendChild(doc.importNode(xml, true));
516 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
518 producer = new Mlt::Producer(*m_mltProfile, url.path().toUtf8().constData());
521 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
522 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
523 emit removeInvalidClip(clipId, replaceProducer);
528 if (xml.hasAttribute("force_aspect_ratio")) {
529 double aspect = xml.attribute("force_aspect_ratio").toDouble();
530 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
533 if (xml.hasAttribute("force_aspect_num") && xml.hasAttribute("force_aspect_den")) {
534 int width = xml.attribute("frame_size").section('x', 0, 0).toInt();
535 int height = xml.attribute("frame_size").section('x', 1, 1).toInt();
536 int aspectNumerator = xml.attribute("force_aspect_num").toInt();
537 int aspectDenominator = xml.attribute("force_aspect_den").toInt();
538 if (aspectDenominator != 0 && width != 0)
539 producer->set("force_aspect_ratio", double(height) * aspectNumerator / aspectDenominator / width );
542 if (xml.hasAttribute("force_fps")) {
543 double fps = xml.attribute("force_fps").toDouble();
544 if (fps > 0) producer->set("force_fps", fps);
547 if (xml.hasAttribute("force_progressive")) {
549 int progressive = xml.attribute("force_progressive").toInt(&ok);
550 if (ok) producer->set("force_progressive", progressive);
552 if (xml.hasAttribute("force_tff")) {
554 int fieldOrder = xml.attribute("force_tff").toInt(&ok);
555 if (ok) producer->set("force_tff", fieldOrder);
557 if (xml.hasAttribute("threads")) {
558 int threads = xml.attribute("threads").toInt();
559 if (threads != 1) producer->set("threads", threads);
561 if (xml.hasAttribute("video_index")) {
562 int vindex = xml.attribute("video_index").toInt();
563 if (vindex != 0) producer->set("video_index", vindex);
565 if (xml.hasAttribute("audio_index")) {
566 int aindex = xml.attribute("audio_index").toInt();
567 if (aindex != 0) producer->set("audio_index", aindex);
569 if (xml.hasAttribute("force_colorspace")) {
570 int colorspace = xml.attribute("force_colorspace").toInt();
571 if (colorspace != 0) producer->set("force_colorspace", colorspace);
573 if (xml.hasAttribute("full_luma")) {
574 int full_luma = xml.attribute("full_luma").toInt();
575 if (full_luma != 0) producer->set("set.force_full_luma", full_luma);
578 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
579 if (xml.attribute("type").toInt() == COLOR || xml.attribute("type").toInt() == TEXT
580 || xml.attribute("type").toInt() == IMAGE || xml.attribute("type").toInt() == SLIDESHOW)
581 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
583 if (xml.hasAttribute("out"))
584 producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
586 producer->set("id", clipId.toUtf8().constData());
588 if (xml.hasAttribute("templatetext"))
589 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
591 if (!replaceProducer && xml.hasAttribute("file_hash")) {
592 // Clip already has all properties
593 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
597 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
598 QMap < QString, QString > filePropertyMap;
599 QMap < QString, QString > metadataPropertyMap;
601 int frameNumber = xml.attribute("thumbnail", "0").toInt();
602 if (frameNumber != 0) producer->seek(frameNumber);
604 filePropertyMap["duration"] = QString::number(producer->get_playtime());
605 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
607 Mlt::Frame *frame = producer->get_frame();
609 if (xml.attribute("type").toInt() == SLIDESHOW) {
610 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
611 if (ttl) producer->set("ttl", ttl);
612 if (!xml.attribute("animation").isEmpty()) {
613 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
614 if (filter && filter->is_valid()) {
616 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
617 if (!geometry.isEmpty()) {
618 if (xml.attribute("animation").contains("low-pass")) {
619 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
620 if (blur && blur->is_valid())
621 producer->attach(*blur);
623 filter->set("transition.geometry", geometry.toUtf8().data());
624 filter->set("transition.cycle", cycle);
625 producer->attach(*filter);
629 if (xml.attribute("fade") == "1") {
630 // user wants a fade effect to slideshow
631 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
632 if (filter && filter->is_valid()) {
633 if (ttl) filter->set("cycle", ttl);
634 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
635 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
636 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
637 if (xml.hasAttribute("softness")) {
638 int soft = xml.attribute("softness").toInt();
639 filter->set("luma.softness", (double) soft / 100.0);
642 producer->attach(*filter);
645 if (xml.attribute("crop") == "1") {
646 // user wants to center crop the slides
647 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
648 if (filter && filter->is_valid()) {
649 filter->set("center", 1);
650 producer->attach(*filter);
655 if (producer->get_double("meta.media.frame_rate_den") > 0) {
656 filePropertyMap["fps"] = QString::number(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
657 } else filePropertyMap["fps"] = producer->get("source_fps");
659 if (frame && frame->is_valid()) {
660 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
661 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
662 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
663 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
665 if (frame->get_int("test_image") == 0) {
666 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
667 filePropertyMap["type"] = "playlist";
668 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
669 } else if (frame->get_int("test_audio") == 0)
670 filePropertyMap["type"] = "av";
672 filePropertyMap["type"] = "video";
674 mlt_image_format format = mlt_image_rgb24a;
675 int frame_width = width;
676 int frame_height = imageHeight;
677 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
678 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied);
681 if (!image.isNull()) {
682 if (frame_width > (2 * width)) {
683 // there was a scaling problem, do it manually
684 QImage scaled = image.scaled(width, imageHeight);
685 pix = QPixmap::fromImage(scaled.rgbSwapped());
686 } else pix = QPixmap::fromImage(image.rgbSwapped());
690 emit replyGetImage(clipId, pix);
692 } else if (frame->get_int("test_audio") == 0) {
693 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
694 emit replyGetImage(clipId, pixmap);
695 filePropertyMap["type"] = "audio";
699 // Retrieve audio / video codec name
703 if (producer->get_int("video_index") > -1) {
704 /*if (context->duration == AV_NOPTS_VALUE) {
705 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
706 emit removeInvalidClip(clipId);
710 // Get the video_index
711 int default_video = producer->get_int("video_index");
713 int default_audio = producer->get_int("audio_index");
716 // Find maximum stream index values
717 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
718 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
719 QString type = producer->get(property);
722 else if (type == "audio")
725 filePropertyMap["default_video"] = QString::number(default_video);
726 filePropertyMap["video_max"] = QString::number(video_max);
727 filePropertyMap["default_audio"] = QString::number(default_audio);
728 filePropertyMap["audio_max"] = QString::number(audio_max);
730 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
731 if (producer->get(property)) {
732 filePropertyMap["videocodec"] = producer->get(property);
734 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
735 if (producer->get(property))
736 filePropertyMap["videocodec"] = producer->get(property);
739 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
740 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
741 filePropertyMap["colorspace"] = producer->get("meta.media.colorspace");
743 if (KdenliveSettings::dropbframes()) {
744 kDebug() << "// LOOKING FOR H264 on: " << default_video;
745 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
746 kDebug() << "PROP: " << property << " = " << producer->get(property);
747 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
748 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
749 producer->set("skip_loop_filter", "all");
750 producer->set("skip_frame", "bidir");
754 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
755 if (producer->get_int("audio_index") > -1) {
756 // Get the audio_index
757 int index = producer->get_int("audio_index");
759 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
760 if (producer->get(property)) {
761 filePropertyMap["audiocodec"] = producer->get(property);
763 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
764 if (producer->get(property))
765 filePropertyMap["audiocodec"] = producer->get(property);
770 Mlt::Properties metadata;
771 metadata.pass_values(*producer, "meta.attr.");
772 int count = metadata.count();
773 for (int i = 0; i < count; i ++) {
774 QString name = metadata.get_name(i);
775 QString value = QString::fromUtf8(metadata.get(i));
776 if (name.endsWith("markup") && !value.isEmpty())
777 metadataPropertyMap[ name.section('.', 0, -2)] = value;
780 kDebug() << "REquested fuile info for: " << url.path();
781 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
782 // FIXME: should delete this to avoid a leak...
788 /** Create the producer from the MLT XML QDomDocument */
789 void Render::initSceneList()
791 kDebug() << "-------- INIT SCENE LIST ------_";
793 QDomElement mlt = doc.createElement("mlt");
794 doc.appendChild(mlt);
795 QDomElement prod = doc.createElement("producer");
796 prod.setAttribute("resource", "colour");
797 prod.setAttribute("colour", "red");
798 prod.setAttribute("id", "black");
799 prod.setAttribute("in", "0");
800 prod.setAttribute("out", "0");
802 QDomElement tractor = doc.createElement("tractor");
803 QDomElement multitrack = doc.createElement("multitrack");
805 QDomElement playlist1 = doc.createElement("playlist");
806 playlist1.appendChild(prod);
807 multitrack.appendChild(playlist1);
808 QDomElement playlist2 = doc.createElement("playlist");
809 multitrack.appendChild(playlist2);
810 QDomElement playlist3 = doc.createElement("playlist");
811 multitrack.appendChild(playlist3);
812 QDomElement playlist4 = doc.createElement("playlist");
813 multitrack.appendChild(playlist4);
814 QDomElement playlist5 = doc.createElement("playlist");
815 multitrack.appendChild(playlist5);
816 tractor.appendChild(multitrack);
817 mlt.appendChild(tractor);
818 // kDebug()<<doc.toString();
820 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
821 setSceneList(doc, 0);
825 int Render::setProducer(Mlt::Producer *producer, int position)
827 if (m_winid == -1) return -1;
830 m_mltConsumer->stop();
833 m_mltConsumer->purge();
836 m_mltProducer->set_speed(0);
837 delete m_mltProducer;
838 m_mltProducer = NULL;
842 m_mltProducer = new Mlt::Producer(producer->get_producer());
843 } else m_mltProducer = m_blackClip->cut(0, 50);
845 /*if (KdenliveSettings::dropbframes()) {
846 m_mltProducer->set("skip_loop_filter", "all");
847 m_mltProducer->set("skip_frame", "bidir");
849 if (!m_mltProducer || !m_mltProducer->is_valid()) {
850 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
853 int volume = KdenliveSettings::volume();
854 m_mltProducer->set("meta.volume", (double)volume / 100);
855 m_fps = m_mltProducer->get_fps();
856 int error = connectPlaylist();
858 if (position != -1) {
859 m_mltProducer->seek(position);
860 emit rendererPosition(position);
861 } else emit rendererPosition((int) m_mltProducer->position());
866 int Render::setSceneList(QDomDocument list, int position)
868 return setSceneList(list.toString(), position);
871 int Render::setSceneList(QString playlist, int position)
873 if (m_winid == -1) return -1;
877 //kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
880 if (!m_mltConsumer->is_stopped()) {
881 m_mltConsumer->stop();
883 m_mltConsumer->set("refresh", 0);
885 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
890 m_mltProducer->set_speed(0);
891 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
894 Mlt::Service service(m_mltProducer->parent().get_service());
895 mlt_service_lock(service.get_service());
897 if (service.type() == tractor_type) {
898 Mlt::Tractor tractor(service);
899 Mlt::Field *field = tractor.field();
900 mlt_service nextservice = mlt_service_get_producer(service.get_service());
901 mlt_service nextservicetodisconnect;
902 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
903 QString mlt_type = mlt_properties_get(properties, "mlt_type");
904 QString resource = mlt_properties_get(properties, "mlt_service");
905 // Delete all transitions
906 while (mlt_type == "transition") {
907 nextservicetodisconnect = nextservice;
908 nextservice = mlt_service_producer(nextservice);
909 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
910 if (nextservice == NULL) break;
911 properties = MLT_SERVICE_PROPERTIES(nextservice);
912 mlt_type = mlt_properties_get(properties, "mlt_type");
913 resource = mlt_properties_get(properties, "mlt_service");
916 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
917 Mlt::Producer trackProducer(tractor.track(trackNb));
918 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
919 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
923 mlt_service_unlock(service.get_service());
925 qDeleteAll(m_slowmotionProducers.values());
926 m_slowmotionProducers.clear();
928 delete m_mltProducer;
929 m_mltProducer = NULL;
935 // TODO: Better way to do this
936 if (KdenliveSettings::projectloading_avformatnovalidate())
937 playlist.replace(">avformat</property>", ">avformat-novalidate</property>");
939 playlist.replace(">avformat-novalidate</property>", ">avformat</property>");
941 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
943 if (!m_mltProducer || !m_mltProducer->is_valid()) {
944 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
945 m_mltProducer = m_blackClip->cut(0, 50);
948 int volume = KdenliveSettings::volume();
949 m_mltProducer->set("meta.volume", (double)volume / 100);
950 m_mltProducer->optimise();
952 /*if (KdenliveSettings::osdtimecode()) {
953 // Attach filter for on screen display of timecode
955 QString attr = "attr_check";
956 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
957 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
958 mlt_producer_attach( m_mltProducer->get_producer(), filter );
959 mlt_filter_close( filter );
961 m_osdInfo = new Mlt::Filter("data_show");
962 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
963 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
964 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
965 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
966 m_osdInfo->set("dynamic", "1");
968 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
970 m_osdInfo->set("dynamic", "0");
973 m_fps = m_mltProducer->get_fps();
975 // Seek to correct place after opening project.
976 m_mltProducer->seek(position);
979 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
980 if (error == 0) error = connectPlaylist();
981 else connectPlaylist();
982 fillSlowMotionProducers();
988 //kDebug()<<"// SETSCN LST, POS: "<<position;
989 //if (position != 0) emit rendererPosition(position);
992 const QString Render::sceneList()
995 Mlt::Profile profile((mlt_profile) 0);
996 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
997 m_mltProducer->optimise();
998 xmlConsumer.set("terminate_on_pause", 1);
999 Mlt::Producer prod(m_mltProducer->get_producer());
1000 bool split = m_isSplitView;
1001 if (split) slotSplitView(false);
1002 xmlConsumer.connect(prod);
1003 xmlConsumer.start();
1004 while (!xmlConsumer.is_stopped()) {}
1005 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1006 if (split) slotSplitView(true);
1010 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1014 doc.setContent(sceneList(), false);
1015 if (!kdenliveData.isNull()) {
1016 // add Kdenlive specific tags
1017 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1018 mlt.appendChild(doc.importNode(kdenliveData, true));
1020 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1021 kWarning() << "////// ERROR writing to file: " << path;
1024 file.write(doc.toString().toUtf8());
1025 if (file.error() != QFile::NoError) {
1033 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1035 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1036 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1037 m_mltProducer->optimise();
1038 xmlConsumer.set("terminate_on_pause", 1);
1039 if (m_name == "clip") {
1040 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1042 list.insert_at(0, prod, 0);
1044 list.set("title", desc.toUtf8().constData());
1045 xmlConsumer.connect(list);
1048 //TODO: not working yet, save zone from timeline
1049 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1050 /* Mlt::Service service(p1->parent().get_service());
1051 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1053 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1054 //prod->set("title", desc.toUtf8().constData());
1055 xmlConsumer.connect(*p1); //list);
1058 xmlConsumer.start();
1061 double Render::fps() const
1066 int Render::connectPlaylist()
1068 if (!m_mltConsumer) return -1;
1069 //m_mltConsumer->set("refresh", "0");
1070 m_mltConsumer->connect(*m_mltProducer);
1071 m_mltProducer->set_speed(0);
1072 if (m_mltConsumer->start() == -1) {
1073 // ARGH CONSUMER BROKEN!!!!
1074 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."));
1075 delete m_mltConsumer;
1076 m_mltConsumer = NULL;
1079 emit durationChanged(m_mltProducer->get_playtime());
1084 void Render::refreshDisplay()
1087 if (!m_mltProducer) return;
1088 //m_mltConsumer->set("refresh", 0);
1090 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1091 /*if (KdenliveSettings::osdtimecode()) {
1092 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1093 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1094 m_osdInfo->set("dynamic", "1");
1095 m_mltProducer->attach(*m_osdInfo);
1098 m_mltProducer->detach(*m_osdInfo);
1099 m_osdInfo->set("dynamic", "0");
1104 int Render::volume() const
1106 if (!m_mltConsumer || !m_mltProducer) return -1;
1107 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1110 void Render::slotSetVolume(int volume)
1112 if (!m_mltConsumer || !m_mltProducer) return;
1113 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1116 m_mltConsumer->set("refresh", 0);
1117 // Attach filter for on screen display of timecode
1118 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1119 mlt_properties_set_double( properties, "meta.volume", volume );
1120 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1121 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1123 if (!KdenliveSettings::osdtimecode()) {
1124 m_mltProducer->detach(*m_osdInfo);
1125 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1126 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1129 //m_osdTimer->setSingleShot(2500);
1132 void Render::slotOsdTimeout()
1134 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1135 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1136 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1137 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1141 void Render::start()
1143 kDebug() << "----- STARTING MONITOR: " << m_name;
1144 if (m_winid == -1) {
1145 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1148 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1149 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1150 if (m_mltConsumer->start() == -1) {
1151 //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."));
1152 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1154 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1155 m_isBlocked = false;
1159 m_isBlocked = false;
1164 if (m_mltProducer == NULL) return;
1165 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1166 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1168 //m_mltConsumer->set("refresh", 0);
1169 m_mltConsumer->stop();
1170 // delete m_mltConsumer;
1171 // m_mltConsumer = NULL;
1173 kDebug() << "///////////// RENDER STOP2-------";
1176 if (m_mltProducer) {
1177 if (m_isZoneMode) resetZoneMode();
1178 m_mltProducer->set_speed(0.0);
1179 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1180 //kDebug() << m_mltProducer->get_length();
1182 kDebug() << "///////////// RENDER STOP3-------";
1185 void Render::stop(const GenTime & startTime)
1188 kDebug() << "///////////// RENDER STOP-------2";
1189 if (m_mltProducer) {
1190 if (m_isZoneMode) resetZoneMode();
1191 m_mltProducer->set_speed(0.0);
1192 m_mltProducer->seek((int) startTime.frames(m_fps));
1194 m_mltConsumer->purge();
1197 void Render::pause()
1199 if (!m_mltProducer || !m_mltConsumer)
1201 if (m_mltProducer->get_speed() == 0.0) return;
1202 if (m_isZoneMode) resetZoneMode();
1204 m_mltConsumer->set("refresh", 0);
1205 m_mltProducer->set_speed(0.0);
1207 The 2 lines below create a flicker loop
1208 emit rendererPosition(m_framePosition);
1209 m_mltProducer->seek(m_framePosition);*/
1210 m_mltConsumer->purge();
1213 void Render::switchPlay()
1215 if (!m_mltProducer || !m_mltConsumer)
1217 if (m_isZoneMode) resetZoneMode();
1218 if (m_mltProducer->get_speed() == 0.0) {
1219 m_isBlocked = false;
1220 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1221 m_mltProducer->set_speed(1.0);
1222 m_mltConsumer->set("refresh", 1);
1225 m_mltConsumer->set("refresh", 0);
1226 m_mltProducer->set_speed(0.0);
1227 //emit rendererPosition(m_framePosition);
1228 m_mltProducer->seek(m_framePosition);
1229 m_mltConsumer->purge();
1230 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1231 //m_mltConsumer->set("refresh", 0);
1232 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1233 m_mltProducer->set_speed(0);
1234 m_mltProducer->seek( position );
1235 //m_mltProducer->seek((int) m_framePosition);
1236 m_isBlocked = false;*/
1238 /*if (speed == 0.0) {
1239 m_mltProducer->seek((int) m_framePosition + 1);
1240 m_mltConsumer->purge();
1245 void Render::play(double speed)
1249 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1250 m_isBlocked = false;
1251 m_mltProducer->set_speed(speed);
1252 /*if (speed == 0.0) {
1253 m_mltProducer->seek((int) m_framePosition + 1);
1254 m_mltConsumer->purge();
1259 void Render::play(const GenTime & startTime)
1261 if (!m_mltProducer || !m_mltConsumer)
1263 m_isBlocked = false;
1264 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1265 m_mltProducer->set_speed(1.0);
1266 m_mltConsumer->set("refresh", 1);
1269 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1271 if (!m_mltProducer || !m_mltConsumer)
1273 //m_mltProducer->set("eof", "loop");
1274 m_isLoopMode = true;
1275 m_loopStart = startTime;
1276 playZone(startTime, stopTime);
1279 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1281 if (!m_mltProducer || !m_mltConsumer)
1283 m_isBlocked = false;
1284 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1285 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1286 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1287 m_mltProducer->set_speed(1.0);
1288 m_mltConsumer->set("refresh", 1);
1289 m_isZoneMode = true;
1292 void Render::resetZoneMode()
1294 if (!m_isZoneMode && !m_isLoopMode) return;
1295 m_mltProducer->set("out", m_originalOut);
1296 //m_mltProducer->set("eof", "pause");
1297 m_isZoneMode = false;
1298 m_isLoopMode = false;
1301 void Render::seekToFrame(int pos)
1303 //kDebug()<<" ********* RENDER SEEK TO POS";
1306 m_isBlocked = false;
1308 m_mltProducer->seek(pos);
1312 void Render::seekToFrameDiff(int diff)
1314 //kDebug()<<" ********* RENDER SEEK TO POS";
1317 m_isBlocked = false;
1319 m_mltProducer->seek(m_mltProducer->position() + diff);
1323 void Render::doRefresh()
1325 // Use a Timer so that we don't refresh too much
1326 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1329 void Render::refresh()
1331 if (!m_mltProducer || m_isBlocked)
1333 if (m_mltConsumer) {
1334 m_mltConsumer->set("refresh", 1);
1338 void Render::setDropFrames(bool show)
1340 if (m_mltConsumer) {
1342 if (show == false) dropFrames = 0;
1343 m_mltConsumer->stop();
1345 m_mltConsumer->set("real_time", dropFrames);
1347 m_mltConsumer->set("play.real_time", dropFrames);
1349 if (m_mltConsumer->start() == -1) {
1350 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1356 double Render::playSpeed()
1358 if (m_mltProducer) return m_mltProducer->get_speed();
1362 GenTime Render::seekPosition() const
1364 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1365 else return GenTime();
1368 int Render::seekFramePosition() const
1370 if (m_mltProducer) return (int) m_mltProducer->position();
1374 const QString & Render::rendererName() const
1379 void Render::emitFrameUpdated(Mlt::Frame& frame)
1381 mlt_image_format format = mlt_image_rgb24a;
1384 const uchar* image = frame.get_image(format, width, height);
1385 QImage qimage(width, height, QImage::Format_ARGB32);
1386 memcpy(qimage.bits(), image, width * height * 4);
1387 emit frameUpdated(qimage.rgbSwapped());
1390 void Render::emitFrameNumber(double position)
1392 m_framePosition = position;
1393 emit rendererPosition((int) position);
1396 void Render::emitConsumerStopped()
1398 // This is used to know when the playing stopped
1399 if (m_mltProducer) {
1400 double pos = m_mltProducer->position();
1401 if (m_isLoopMode) play(m_loopStart);
1402 else if (m_isZoneMode) resetZoneMode();
1403 emit rendererStopped((int) pos);
1407 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1409 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1412 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1414 if (!m_mltProducer) {
1415 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1419 //int height = 1080;//KdenliveSettings::defaultheight();
1420 //int width = 1940; //KdenliveSettings::displaywidth();
1422 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1424 QPixmap pix(width, height);
1425 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1426 m_convert.set("forced", mlt_image_rgb24a);
1427 m_mltProducer->attach(m_convert);
1428 Mlt::Frame * frame = m_mltProducer->get_frame();
1429 m_mltProducer->detach(m_convert);
1431 pix = frameThumbnail(frame, width, height);
1434 pix.save(url.path(), "PNG");
1435 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1439 void Render::showFrame(Mlt::Frame& frame)
1441 m_framePosition = qMax(frame.get_int("_position"), 0);
1442 emit rendererPosition((int) m_framePosition);
1443 mlt_image_format format = mlt_image_rgb24a;
1446 const uchar* image = frame.get_image(format, width, height);
1447 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1448 memcpy(qimage.scanLine(0), image, width * height * 4);
1449 emit showImageSignal(qimage);
1451 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1452 emit frameUpdated(qimage.rgbSwapped());
1456 void Render::showAudio(Mlt::Frame& frame)
1458 if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
1459 mlt_audio_format audio_format = mlt_audio_s16;
1461 int num_channels = 0;
1463 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1466 int num_samples = samples > 200 ? 200 : samples;
1467 QByteArray channels;
1468 for (int i = 0; i < num_channels; i++) {
1470 for (int s = 0; s < num_samples; s ++) {
1471 val += abs(data[i+s*num_channels] / 128);
1473 channels.append(val / num_samples);
1478 emit showAudioSignal(channels);
1480 emit showAudioSignal(QByteArray());
1484 * MLT playlist direct manipulation.
1487 void Render::mltCheckLength(Mlt::Tractor *tractor)
1489 //kDebug()<<"checking track length: "<<track<<"..........";
1491 int trackNb = tractor->count();
1495 Mlt::Producer trackProducer(tractor->track(0));
1496 duration = trackProducer.get_playtime() - 1;
1497 m_mltProducer->set("out", duration);
1498 emit durationChanged(duration);
1501 while (trackNb > 1) {
1502 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1503 trackDuration = trackProducer.get_playtime() - 1;
1504 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1505 if (trackDuration > duration) duration = trackDuration;
1509 Mlt::Producer blackTrackProducer(tractor->track(0));
1511 if (blackTrackProducer.get_playtime() - 1 != duration) {
1512 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1513 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1514 if (blackclip && blackclip->is_blank()) {
1519 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1520 blackTrackPlaylist.clear();
1521 m_blackClip->set("length", duration + 1);
1522 m_blackClip->set("out", duration);
1523 blackclip = m_blackClip->cut(0, duration);
1524 blackTrackPlaylist.insert_at(0, blackclip, 1);
1526 if (duration > blackclip->parent().get_length()) {
1527 blackclip->parent().set("length", duration + 1);
1528 blackclip->parent().set("out", duration);
1529 blackclip->set("length", duration + 1);
1531 blackTrackPlaylist.resize_clip(0, 0, duration);
1535 m_mltProducer->set("out", duration);
1536 emit durationChanged(duration);
1540 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1542 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1544 // We want a slowmotion producer
1545 double speed = element.attribute("speed", "1.0").toDouble();
1546 int strobe = element.attribute("strobe", "1").toInt();
1547 QString url = QString::fromUtf8(prod->get("resource"));
1548 url.append('?' + QString::number(speed));
1549 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1550 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1551 if (!slowprod || slowprod->get_producer() == NULL) {
1552 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1553 if (strobe > 1) slowprod->set("strobe", strobe);
1554 QString id = prod->get("id");
1555 if (id.contains('_')) id = id.section('_', 0, 0);
1556 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1557 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1558 slowprod->set("id", producerid.toUtf8().constData());
1559 m_slowmotionProducers.insert(url, slowprod);
1564 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1566 if (m_mltProducer == NULL) {
1567 kDebug() << "PLAYLIST NOT INITIALISED //////";
1571 kDebug() << "Cannot insert clip without producer //////";
1574 Mlt::Producer parentProd(m_mltProducer->parent());
1575 if (parentProd.get_producer() == NULL) {
1576 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1580 Mlt::Service service(parentProd.get_service());
1581 if (service.type() != tractor_type) {
1582 kWarning() << "// TRACTOR PROBLEM";
1585 Mlt::Tractor tractor(service);
1586 if (info.track > tractor.count() - 1) {
1587 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1590 mlt_service_lock(service.get_service());
1591 Mlt::Producer trackProducer(tractor.track(info.track));
1592 int trackDuration = trackProducer.get_playtime() - 1;
1593 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1594 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1595 prod = checkSlowMotionProducer(prod, element);
1596 if (prod == NULL || !prod->is_valid()) {
1597 mlt_service_unlock(service.get_service());
1601 int cutPos = (int) info.cropStart.frames(m_fps);
1602 if (cutPos < 0) cutPos = 0;
1603 int insertPos = (int) info.startPos.frames(m_fps);
1604 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1605 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1606 if (overwrite && (insertPos < trackDuration)) {
1607 // Replace zone with blanks
1608 //trackPlaylist.split_at(insertPos, true);
1609 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1610 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1611 trackPlaylist.insert_blank(clipIndex, cutDuration);
1613 trackPlaylist.split_at(insertPos, true);
1614 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1615 trackPlaylist.insert_blank(clipIndex, cutDuration);
1617 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1619 /*if (QString(prod->get("transparency")).toInt() == 1)
1620 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1622 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1623 mlt_service_unlock(service.get_service());
1624 /*tractor.multitrack()->refresh();
1625 tractor.refresh();*/
1630 void Render::mltCutClip(int track, GenTime position)
1634 Mlt::Service service(m_mltProducer->parent().get_service());
1635 if (service.type() != tractor_type) {
1636 kWarning() << "// TRACTOR PROBLEM";
1640 Mlt::Tractor tractor(service);
1641 Mlt::Producer trackProducer(tractor.track(track));
1642 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1645 /* // Display playlist info
1646 kDebug()<<"//////////// BEFORE";
1647 for (int i = 0; i < trackPlaylist.count(); i++) {
1648 int blankStart = trackPlaylist.clip_start(i);
1649 int blankDuration = trackPlaylist.clip_length(i) - 1;
1651 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1652 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1655 int cutPos = (int) position.frames(m_fps);
1657 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1658 if (trackPlaylist.is_blank(clipIndex)) {
1659 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1660 m_isBlocked = false;
1663 mlt_service_lock(service.get_service());
1664 int clipStart = trackPlaylist.clip_start(clipIndex);
1665 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1666 mlt_service_unlock(service.get_service());
1668 // duplicate effects
1669 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1670 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1672 if (original == NULL || clip == NULL) {
1673 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1675 Mlt::Service clipService(original->get_service());
1676 Mlt::Service dupService(clip->get_service());
1680 Mlt::Filter *filter = clipService.filter(ct);
1682 // Only duplicate Kdenlive filters, and skip the fade in effects
1683 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1684 // looks like there is no easy way to duplicate a filter,
1685 // so we will create a new one and duplicate its properties
1686 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1687 if (dup && dup->is_valid()) {
1688 Mlt::Properties entries(filter->get_properties());
1689 for (int i = 0; i < entries.count(); i++) {
1690 dup->set(entries.get_name(i), entries.get(i));
1692 dupService.attach(*dup);
1696 filter = clipService.filter(ct);
1699 /* // Display playlist info
1700 kDebug()<<"//////////// AFTER";
1701 for (int i = 0; i < trackPlaylist.count(); i++) {
1702 int blankStart = trackPlaylist.clip_start(i);
1703 int blankDuration = trackPlaylist.clip_length(i) - 1;
1705 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1706 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1709 m_isBlocked = false;
1712 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1716 kDebug() << "Cannot update clip with null producer //////";
1719 Mlt::Service service(m_mltProducer->parent().get_service());
1720 if (service.type() != tractor_type) {
1721 kWarning() << "// TRACTOR PROBLEM";
1724 Mlt::Tractor tractor(service);
1725 Mlt::Producer trackProducer(tractor.track(info.track));
1726 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1727 int startPos = info.startPos.frames(m_fps);
1728 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1729 if (trackPlaylist.is_blank(clipIndex)) {
1730 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1733 mlt_service_lock(service.get_service());
1734 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1736 QList <Mlt::Filter *> filtersList;
1737 Mlt::Service sourceService(clip->get_service());
1739 Mlt::Filter *filter = sourceService.filter(ct);
1741 if (filter->get_int("kdenlive_ix") != 0) {
1742 filtersList.append(filter);
1745 filter = sourceService.filter(ct);
1748 trackPlaylist.replace_with_blank(clipIndex);
1750 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1751 prod = checkSlowMotionProducer(prod, element);
1752 if (prod == NULL || !prod->is_valid()) {
1753 mlt_service_unlock(service.get_service());
1756 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1757 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1761 //if (mltInsertClip(info, element, prod) == -1) return false;
1762 if (!filtersList.isEmpty()) {
1763 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1764 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1765 Mlt::Service destService(destclip->get_service());
1767 for (int i = 0; i < filtersList.count(); i++)
1768 destService.attach(*(filtersList.at(i)));
1770 mlt_service_unlock(service.get_service());
1775 bool Render::mltRemoveClip(int track, GenTime position)
1777 Mlt::Service service(m_mltProducer->parent().get_service());
1778 if (service.type() != tractor_type) {
1779 kWarning() << "// TRACTOR PROBLEM";
1783 Mlt::Tractor tractor(service);
1784 mlt_service_lock(service.get_service());
1785 Mlt::Producer trackProducer(tractor.track(track));
1786 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1787 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1789 // Display playlist info
1790 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1791 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1792 int blankStart = trackPlaylist.clip_start(i);
1793 int blankDuration = trackPlaylist.clip_length(i) - 1;
1795 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1796 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1798 if (trackPlaylist.is_blank(clipIndex)) {
1799 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1800 mlt_service_unlock(service.get_service());
1803 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1805 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1806 if (clip) delete clip;
1807 trackPlaylist.consolidate_blanks(0);
1808 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1809 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1811 /* // Display playlist info
1812 kDebug()<<"//// AFTER";
1813 for (int i = 0; i < trackPlaylist.count(); i++) {
1814 int blankStart = trackPlaylist.clip_start(i);
1815 int blankDuration = trackPlaylist.clip_length(i) - 1;
1817 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1818 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1820 mlt_service_unlock(service.get_service());
1821 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1822 m_isBlocked = false;
1826 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1828 if (!m_mltProducer) {
1829 kDebug() << "PLAYLIST NOT INITIALISED //////";
1832 Mlt::Producer parentProd(m_mltProducer->parent());
1833 if (parentProd.get_producer() == NULL) {
1834 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1838 Mlt::Service service(parentProd.get_service());
1839 Mlt::Tractor tractor(service);
1840 int insertPos = pos.frames(m_fps);
1842 Mlt::Producer trackProducer(tractor.track(track));
1843 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1844 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1845 if (clipIndex == trackPlaylist.count()) {
1846 // We are after the end of the playlist
1849 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1850 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1851 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1854 int Render::mltTrackDuration(int track)
1856 if (!m_mltProducer) {
1857 kDebug() << "PLAYLIST NOT INITIALISED //////";
1860 Mlt::Producer parentProd(m_mltProducer->parent());
1861 if (parentProd.get_producer() == NULL) {
1862 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1866 Mlt::Service service(parentProd.get_service());
1867 Mlt::Tractor tractor(service);
1869 Mlt::Producer trackProducer(tractor.track(track));
1870 return trackProducer.get_playtime() - 1;
1873 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1875 if (!m_mltProducer) {
1876 kDebug() << "PLAYLIST NOT INITIALISED //////";
1879 Mlt::Producer parentProd(m_mltProducer->parent());
1880 if (parentProd.get_producer() == NULL) {
1881 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1884 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1885 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1887 Mlt::Service service(parentProd.get_service());
1888 Mlt::Tractor tractor(service);
1889 mlt_service_lock(service.get_service());
1890 int diff = duration.frames(m_fps);
1891 int offset = timeOffset.frames(m_fps);
1895 // insert space in one track only
1896 Mlt::Producer trackProducer(tractor.track(track));
1897 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1898 insertPos = trackClipStartList.value(track);
1899 if (insertPos != -1) {
1900 insertPos += offset;
1901 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1903 trackPlaylist.insert_blank(clipIndex, diff - 1);
1905 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1906 if (!trackPlaylist.is_blank(clipIndex)) {
1907 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1909 int position = trackPlaylist.clip_start(clipIndex);
1910 int blankDuration = trackPlaylist.clip_length(clipIndex);
1912 if (blankDuration - diff == 0) {
1913 trackPlaylist.remove(clipIndex);
1914 } else trackPlaylist.remove_region(position, diff);
1916 trackPlaylist.consolidate_blanks(0);
1918 // now move transitions
1919 mlt_service serv = m_mltProducer->parent().get_service();
1920 mlt_service nextservice = mlt_service_get_producer(serv);
1921 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1922 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1923 QString resource = mlt_properties_get(properties, "mlt_service");
1925 while (mlt_type == "transition") {
1926 mlt_transition tr = (mlt_transition) nextservice;
1927 int currentTrack = mlt_transition_get_b_track(tr);
1928 int currentIn = (int) mlt_transition_get_in(tr);
1929 int currentOut = (int) mlt_transition_get_out(tr);
1930 insertPos = trackTransitionStartList.value(track);
1931 if (insertPos != -1) {
1932 insertPos += offset;
1933 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1934 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1937 nextservice = mlt_service_producer(nextservice);
1938 if (nextservice == NULL) break;
1939 properties = MLT_SERVICE_PROPERTIES(nextservice);
1940 mlt_type = mlt_properties_get(properties, "mlt_type");
1941 resource = mlt_properties_get(properties, "mlt_service");
1944 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1945 Mlt::Producer trackProducer(tractor.track(trackNb));
1946 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1948 //int clipNb = trackPlaylist.count();
1949 insertPos = trackClipStartList.value(trackNb);
1950 if (insertPos != -1) {
1951 insertPos += offset;
1953 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1954 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1955 for (int i = 0; i < clipNb; i++) {
1956 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1957 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1958 kDebug()<<"-------------";
1960 kDebug()<<"END-------------";*/
1963 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1965 trackPlaylist.insert_blank(clipIndex, diff - 1);
1967 if (!trackPlaylist.is_blank(clipIndex)) {
1970 if (!trackPlaylist.is_blank(clipIndex)) {
1971 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1973 int position = trackPlaylist.clip_start(clipIndex);
1974 int blankDuration = trackPlaylist.clip_length(clipIndex);
1975 if (diff + blankDuration == 0) {
1976 trackPlaylist.remove(clipIndex);
1977 } else trackPlaylist.remove_region(position, - diff);
1979 trackPlaylist.consolidate_blanks(0);
1982 // now move transitions
1983 mlt_service serv = m_mltProducer->parent().get_service();
1984 mlt_service nextservice = mlt_service_get_producer(serv);
1985 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1986 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1987 QString resource = mlt_properties_get(properties, "mlt_service");
1989 while (mlt_type == "transition") {
1990 mlt_transition tr = (mlt_transition) nextservice;
1991 int currentIn = (int) mlt_transition_get_in(tr);
1992 int currentOut = (int) mlt_transition_get_out(tr);
1993 int currentTrack = mlt_transition_get_b_track(tr);
1994 insertPos = trackTransitionStartList.value(currentTrack);
1995 if (insertPos != -1) {
1996 insertPos += offset;
1997 if (currentOut > insertPos && resource != "mix") {
1998 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
2001 nextservice = mlt_service_producer(nextservice);
2002 if (nextservice == NULL) break;
2003 properties = MLT_SERVICE_PROPERTIES(nextservice);
2004 mlt_type = mlt_properties_get(properties, "mlt_type");
2005 resource = mlt_properties_get(properties, "mlt_service");
2008 mlt_service_unlock(service.get_service());
2009 mltCheckLength(&tractor);
2010 m_mltConsumer->set("refresh", 1);
2014 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2016 if (source == dest) return;
2017 Mlt::Service sourceService(source->get_service());
2018 Mlt::Service destService(dest->get_service());
2020 // move all effects to the correct producer
2022 Mlt::Filter *filter = sourceService.filter(ct);
2024 if (filter->get_int("kdenlive_ix") != 0) {
2025 sourceService.detach(*filter);
2026 destService.attach(*filter);
2028 filter = sourceService.filter(ct);
2032 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2036 Mlt::Service service(m_mltProducer->parent().get_service());
2037 if (service.type() != tractor_type) {
2038 kWarning() << "// TRACTOR PROBLEM";
2041 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2042 Mlt::Tractor tractor(service);
2043 Mlt::Producer trackProducer(tractor.track(info.track));
2044 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2045 int startPos = info.startPos.frames(m_fps);
2046 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2047 int clipLength = trackPlaylist.clip_length(clipIndex);
2049 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2050 if (original == NULL) {
2053 if (!original->is_valid() || original->is_blank()) {
2058 Mlt::Producer clipparent = original->parent();
2059 if (!clipparent.is_valid() || clipparent.is_blank()) {
2065 QString serv = clipparent.get("mlt_service");
2066 QString id = clipparent.get("id");
2067 if (speed <= 0 && speed > -1) speed = 1.0;
2068 //kDebug() << "CLIP SERVICE: " << serv;
2069 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2070 mlt_service_lock(service.get_service());
2071 QString url = QString::fromUtf8(clipparent.get("resource"));
2072 url.append('?' + QString::number(speed));
2073 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2074 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2075 if (!slowprod || slowprod->get_producer() == NULL) {
2076 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2077 if (strobe > 1) slowprod->set("strobe", strobe);
2078 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2079 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2080 slowprod->set("id", producerid.toUtf8().constData());
2081 // copy producer props
2082 double ar = original->parent().get_double("force_aspect_ratio");
2083 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2084 double fps = original->parent().get_double("force_fps");
2085 if (fps != 0.0) slowprod->set("force_fps", fps);
2086 int threads = original->parent().get_int("threads");
2087 if (threads != 0) slowprod->set("threads", threads);
2088 if (original->parent().get("force_progressive"))
2089 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2090 if (original->parent().get("force_tff"))
2091 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2092 int ix = original->parent().get_int("video_index");
2093 if (ix != 0) slowprod->set("video_index", ix);
2094 int colorspace = original->parent().get_int("force_colorspace");
2095 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2096 int full_luma = original->parent().get_int("set.force_full_luma");
2097 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2098 m_slowmotionProducers.insert(url, slowprod);
2100 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2101 trackPlaylist.consolidate_blanks(0);
2103 // Check that the blank space is long enough for our new duration
2104 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2105 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2107 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2108 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2109 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2110 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2112 // move all effects to the correct producer
2113 mltPasteEffects(clip, cut);
2114 trackPlaylist.insert_at(startPos, cut, 1);
2117 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2118 newLength = trackPlaylist.clip_length(clipIndex);
2119 mlt_service_unlock(service.get_service());
2120 } else if (speed == 1.0 && strobe < 2) {
2121 mlt_service_lock(service.get_service());
2123 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2124 trackPlaylist.consolidate_blanks(0);
2126 // Check that the blank space is long enough for our new duration
2127 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2128 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2131 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2132 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2133 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2134 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2135 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2137 // move all effects to the correct producer
2138 mltPasteEffects(clip, cut);
2140 trackPlaylist.insert_at(startPos, cut, 1);
2143 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2144 newLength = trackPlaylist.clip_length(clipIndex);
2145 mlt_service_unlock(service.get_service());
2147 } else if (serv == "framebuffer") {
2148 mlt_service_lock(service.get_service());
2149 QString url = QString::fromUtf8(clipparent.get("resource"));
2150 url = url.section('?', 0, 0);
2151 url.append('?' + QString::number(speed));
2152 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2153 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2154 if (!slowprod || slowprod->get_producer() == NULL) {
2155 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2156 slowprod->set("strobe", strobe);
2157 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2158 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2159 slowprod->set("id", producerid.toUtf8().constData());
2160 // copy producer props
2161 double ar = original->parent().get_double("force_aspect_ratio");
2162 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2163 double fps = original->parent().get_double("force_fps");
2164 if (fps != 0.0) slowprod->set("force_fps", fps);
2165 if (original->parent().get("force_progressive"))
2166 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2167 if (original->parent().get("force_tff"))
2168 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2169 int threads = original->parent().get_int("threads");
2170 if (threads != 0) slowprod->set("threads", threads);
2171 int ix = original->parent().get_int("video_index");
2172 if (ix != 0) slowprod->set("video_index", ix);
2173 int colorspace = original->parent().get_int("force_colorspace");
2174 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2175 int full_luma = original->parent().get_int("set.force_full_luma");
2176 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2177 m_slowmotionProducers.insert(url, slowprod);
2179 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2180 trackPlaylist.consolidate_blanks(0);
2182 GenTime duration = speedIndependantInfo.cropDuration / speed;
2183 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2185 // Check that the blank space is long enough for our new duration
2186 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2187 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2190 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2191 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2192 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2193 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2195 // move all effects to the correct producer
2196 mltPasteEffects(clip, cut);
2198 trackPlaylist.insert_at(startPos, cut, 1);
2201 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2202 newLength = trackPlaylist.clip_length(clipIndex);
2204 mlt_service_unlock(service.get_service());
2207 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2208 m_isBlocked = false;
2212 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2214 Mlt::Service service(m_mltProducer->parent().get_service());
2215 bool success = false;
2216 Mlt::Tractor tractor(service);
2217 Mlt::Producer trackProducer(tractor.track(track));
2218 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2219 Mlt::Service clipService(trackPlaylist.get_service());
2222 mlt_service_lock(service.get_service());
2224 Mlt::Filter *filter = clipService.filter(ct);
2226 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2227 if (clipService.detach(*filter) == 0) success = true;
2228 } else if (updateIndex) {
2229 // Adjust the other effects index
2230 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2233 filter = clipService.filter(ct);
2235 m_isBlocked = false;
2236 mlt_service_unlock(service.get_service());
2241 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2243 if (position < GenTime()) {
2244 // Remove track effect
2245 return mltRemoveTrackEffect(track, index, updateIndex);
2247 Mlt::Service service(m_mltProducer->parent().get_service());
2248 bool success = false;
2249 Mlt::Tractor tractor(service);
2250 Mlt::Producer trackProducer(tractor.track(track));
2251 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2253 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2254 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2256 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2260 Mlt::Service clipService(clip->get_service());
2261 int duration = clip->get_playtime();
2263 // Check if clip is visible in monitor
2264 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2265 if (diff < 0 || diff > duration) doRefresh = false;
2269 // if (tag.startsWith("ladspa")) tag = "ladspa";
2271 mlt_service_lock(service.get_service());
2273 Mlt::Filter *filter = clipService.filter(ct);
2275 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2276 if (clipService.detach(*filter) == 0) success = true;
2277 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2278 } else if (updateIndex) {
2279 // Adjust the other effects index
2280 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2283 filter = clipService.filter(ct);
2285 m_isBlocked = false;
2286 mlt_service_unlock(service.get_service());
2287 if (doRefresh) refresh();
2291 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2293 Mlt::Service service(m_mltProducer->parent().get_service());
2294 Mlt::Tractor tractor(service);
2295 Mlt::Producer trackProducer(tractor.track(track));
2296 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2297 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2298 return mltAddEffect(trackService, params, 15000, true);
2302 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2305 Mlt::Service service(m_mltProducer->parent().get_service());
2307 Mlt::Tractor tractor(service);
2308 Mlt::Producer trackProducer(tractor.track(track));
2309 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2311 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2312 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2317 Mlt::Service clipService(clip->get_service());
2318 int duration = clip->get_playtime();
2320 // Check if clip is visible in monitor
2321 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2322 if (diff < 0 || diff > duration) doRefresh = false;
2325 return mltAddEffect(clipService, params, duration, doRefresh);
2328 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2330 bool updateIndex = false;
2331 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2332 const QString region = params.paramValue("region");
2335 mlt_service_lock(service.get_service());
2337 Mlt::Filter *filter = service.filter(ct);
2339 if (filter->get_int("kdenlive_ix") == filter_ix) {
2340 // A filter at that position already existed, so we will increase all indexes later
2345 filter = service.filter(ct);
2348 if (params.paramValue("id") == "speed") {
2349 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2351 filter = service.filter(ct);
2353 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2354 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2357 filter = service.filter(ct);
2359 m_isBlocked = false;
2360 mlt_service_unlock(service.get_service());
2361 if (doRefresh) refresh();
2366 // temporarily remove all effects after insert point
2367 QList <Mlt::Filter *> filtersList;
2369 filter = service.filter(ct);
2371 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2372 filtersList.append(filter);
2373 service.detach(*filter);
2375 filter = service.filter(ct);
2379 QString tag = params.paramValue("tag");
2380 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2381 if (tag.startsWith("ladspa")) tag = "ladspa";
2382 char *filterTag = qstrdup(tag.toUtf8().constData());
2383 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2384 QHash<QString, QString>::Iterator it;
2385 QString kfr = params.paramValue("keyframes");
2387 if (!kfr.isEmpty()) {
2388 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2389 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2390 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2391 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2392 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2393 //double max = params.paramValue("max").toDouble();
2394 double min = params.paramValue("min").toDouble();
2395 double factor = params.paramValue("factor", "1").toDouble();
2396 params.removeParam("starttag");
2397 params.removeParam("endtag");
2398 params.removeParam("keyframes");
2399 params.removeParam("min");
2400 params.removeParam("max");
2401 params.removeParam("factor");
2403 // Special case, only one keyframe, means we want a constant value
2404 if (keyFrames.count() == 1) {
2405 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2406 if (filter && filter->is_valid()) {
2407 filter->set("kdenlive_id", filterId);
2408 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2409 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2410 for (int j = 0; j < params.count(); j++) {
2411 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2413 filter->set("in", x1);
2414 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2415 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2416 service.attach(*filter);
2418 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2419 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2420 if (filter && filter->is_valid()) {
2421 filter->set("kdenlive_id", filterId);
2422 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2423 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2424 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2425 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2426 if (x2 == -1) x2 = duration;
2428 for (int j = 0; j < params.count(); j++) {
2429 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2432 filter->set("in", x1);
2433 filter->set("out", x2);
2434 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2435 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2436 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2437 service.attach(*filter);
2444 Mlt::Filter *filter;
2446 if (!region.isEmpty()) {
2447 filter = new Mlt::Filter(*m_mltProfile, "region");
2448 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2449 if (filter && filter->is_valid()) {
2450 filter->set("kdenlive_id", filterId);
2451 if (!region.isEmpty()) {
2452 filter->set("resource", region.toUtf8().constData());
2453 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2454 filter->set("filter0", filterTag);
2455 prefix = "filter0.";
2456 params.removeParam("id");
2457 params.removeParam("region");
2458 params.removeParam("kdenlive_ix");
2461 kDebug() << "filter is NULL";
2462 m_isBlocked = false;
2463 mlt_service_unlock(service.get_service());
2466 params.removeParam("kdenlive_id");
2468 for (int j = 0; j < params.count(); j++) {
2469 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2473 QString effectArgs = params.paramValue("id").section('_', 1);
2475 params.removeParam("id");
2476 params.removeParam("kdenlive_ix");
2477 params.removeParam("tag");
2478 params.removeParam("disable");
2479 params.removeParam("region");
2481 for (int j = 0; j < params.count(); j++) {
2482 effectArgs.append(' ' + params.at(j).value());
2484 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2485 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2488 if (params.paramValue("id") == "pan_zoom") {
2489 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2492 // attach filter to the clip
2493 service.attach(*filter);
2498 // re-add following filters
2499 for (int i = 0; i < filtersList.count(); i++) {
2500 Mlt::Filter *filter = filtersList.at(i);
2502 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2503 service.attach(*filter);
2505 m_isBlocked = false;
2506 mlt_service_unlock(service.get_service());
2507 if (doRefresh) refresh();
2511 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2513 Mlt::Service service(m_mltProducer->parent().get_service());
2514 Mlt::Tractor tractor(service);
2515 Mlt::Producer trackProducer(tractor.track(track));
2516 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2517 Mlt::Service clipService(trackPlaylist.get_service());
2520 QString index = params.paramValue("kdenlive_ix");
2521 QString tag = params.paramValue("tag");
2523 Mlt::Filter *filter = clipService.filter(ct);
2525 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2529 filter = clipService.filter(ct);
2533 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2534 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2536 bool success = false;//mltAddTrackEffect(track, params);
2537 m_isBlocked = false;
2541 QString ser = filter->get("mlt_service");
2542 if (ser == "region") prefix = "filter0.";
2543 mlt_service_lock(service.get_service());
2544 for (int j = 0; j < params.count(); j++) {
2545 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2547 mlt_service_unlock(service.get_service());
2549 m_isBlocked = false;
2555 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2557 QString index = params.paramValue("kdenlive_ix");
2558 QString tag = params.paramValue("tag");
2560 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2561 // This is a keyframe effect, to edit it, we remove it and re-add it.
2562 bool success = mltRemoveEffect(track, position, index, false);
2563 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2564 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2565 else success = mltAddEffect(track, position, params);
2566 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2569 if (position < GenTime()) {
2570 return mltEditTrackEffect(track, params);
2573 Mlt::Service service(m_mltProducer->parent().get_service());
2574 Mlt::Tractor tractor(service);
2575 Mlt::Producer trackProducer(tractor.track(track));
2576 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2578 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2579 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2581 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2585 Mlt::Service clipService(clip->get_service());
2586 int duration = clip->get_playtime();
2587 bool doRefresh = true;
2588 // Check if clip is visible in monitor
2589 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2590 if (diff < 0 || diff > duration) doRefresh = false;
2594 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2595 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2597 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2599 filter = clipService.filter(ct);
2601 kDebug() << "++++++++++++++++++++++++++";
2603 filter = clipService.filter(ct); */
2605 Mlt::Filter *filter = clipService.filter(ct);
2607 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2611 filter = clipService.filter(ct);
2615 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2616 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2618 bool success = mltAddEffect(track, position, params);
2619 m_isBlocked = false;
2623 QString ser = filter->get("mlt_service");
2624 if (ser == "region") prefix = "filter0.";
2625 mlt_service_lock(service.get_service());
2626 for (int j = 0; j < params.count(); j++) {
2627 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2629 mlt_service_unlock(service.get_service());
2631 m_isBlocked = false;
2632 if (doRefresh) refresh();
2636 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2638 Mlt::Service service(m_mltProducer->parent().get_service());
2639 Mlt::Tractor tractor(service);
2640 Mlt::Producer trackProducer(tractor.track(track));
2641 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2643 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2644 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2646 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2650 Mlt::Service clipService(clip->get_service());
2651 int duration = clip->get_playtime();
2652 bool doRefresh = true;
2653 // Check if clip is visible in monitor
2654 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2655 if (diff < 0 || diff > duration) doRefresh = false;
2660 Mlt::Filter *filter = clipService.filter(ct);
2662 int pos = filter->get_int("kdenlive_ix");
2663 if (pos == oldPos) {
2664 filter->set("kdenlive_ix", newPos);
2666 filter = clipService.filter(ct);
2669 m_isBlocked = false;
2670 if (doRefresh) refresh();
2673 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2675 if (position < GenTime()) {
2676 mltMoveTrackEffect(track, oldPos, newPos);
2679 Mlt::Service service(m_mltProducer->parent().get_service());
2680 Mlt::Tractor tractor(service);
2681 Mlt::Producer trackProducer(tractor.track(track));
2682 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2684 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2685 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2687 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2691 Mlt::Service clipService(clip->get_service());
2692 int duration = clip->get_playtime();
2693 bool doRefresh = true;
2694 // Check if clip is visible in monitor
2695 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2696 if (diff < 0 || diff > duration) doRefresh = false;
2701 QList <Mlt::Filter *> filtersList;
2702 Mlt::Filter *filter = clipService.filter(ct);
2704 if (newPos > oldPos) {
2706 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2707 filter->set("kdenlive_ix", newPos);
2708 filtersList.append(filter);
2709 clipService.detach(*filter);
2710 filter = clipService.filter(ct);
2711 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2712 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2714 filter = clipService.filter(ct);
2718 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2719 filtersList.append(filter);
2720 clipService.detach(*filter);
2722 filter = clipService.filter(ct);
2726 if (filter->get_int("kdenlive_ix") == oldPos) {
2727 filter->set("kdenlive_ix", newPos);
2728 filtersList.append(filter);
2729 clipService.detach(*filter);
2731 filter = clipService.filter(ct);
2735 filter = clipService.filter(ct);
2737 int pos = filter->get_int("kdenlive_ix");
2738 if (pos >= newPos) {
2739 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2740 filtersList.append(filter);
2741 clipService.detach(*filter);
2743 filter = clipService.filter(ct);
2747 for (int i = 0; i < filtersList.count(); i++) {
2748 clipService.attach(*(filtersList.at(i)));
2751 m_isBlocked = false;
2752 if (doRefresh) refresh();
2755 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2757 Mlt::Service service(m_mltProducer->parent().get_service());
2758 Mlt::Tractor tractor(service);
2759 Mlt::Producer trackProducer(tractor.track(track));
2760 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2762 Mlt::Service clipService(trackPlaylist.get_service());
2766 QList <Mlt::Filter *> filtersList;
2767 Mlt::Filter *filter = clipService.filter(ct);
2769 if (newPos > oldPos) {
2771 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2772 filter->set("kdenlive_ix", newPos);
2773 filtersList.append(filter);
2774 clipService.detach(*filter);
2775 filter = clipService.filter(ct);
2776 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2777 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2779 filter = clipService.filter(ct);
2783 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2784 filtersList.append(filter);
2785 clipService.detach(*filter);
2787 filter = clipService.filter(ct);
2791 if (filter->get_int("kdenlive_ix") == oldPos) {
2792 filter->set("kdenlive_ix", newPos);
2793 filtersList.append(filter);
2794 clipService.detach(*filter);
2796 filter = clipService.filter(ct);
2800 filter = clipService.filter(ct);
2802 int pos = filter->get_int("kdenlive_ix");
2803 if (pos >= newPos) {
2804 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2805 filtersList.append(filter);
2806 clipService.detach(*filter);
2808 filter = clipService.filter(ct);
2812 for (int i = 0; i < filtersList.count(); i++) {
2813 clipService.attach(*(filtersList.at(i)));
2815 m_isBlocked = false;
2819 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2822 Mlt::Service service(m_mltProducer->parent().get_service());
2823 Mlt::Tractor tractor(service);
2824 Mlt::Producer trackProducer(tractor.track(info.track));
2825 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2827 /* // Display playlist info
2828 kDebug()<<"//////////// BEFORE RESIZE";
2829 for (int i = 0; i < trackPlaylist.count(); i++) {
2830 int blankStart = trackPlaylist.clip_start(i);
2831 int blankDuration = trackPlaylist.clip_length(i) - 1;
2833 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2834 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2837 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2838 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2839 m_isBlocked = false;
2842 mlt_service_lock(service.get_service());
2843 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2844 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2845 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2847 int previousStart = clip->get_in();
2848 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2849 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2851 int currentOut = newDuration + previousStart;
2852 if (currentOut > clip->get_length()) {
2853 clip->parent().set("length", currentOut + 1);
2854 clip->parent().set("out", currentOut);
2855 clip->set("length", currentOut + 1);
2858 /*if (newDuration > clip->get_out()) {
2859 clip->parent().set_in_and_out(0, newDuration + 1);
2860 clip->set_in_and_out(0, newDuration + 1);
2863 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2864 trackPlaylist.consolidate_blanks(0);
2865 // skip to next clip
2867 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2869 // clip was made longer, trim next blank if there is one.
2870 if (clipIndex < trackPlaylist.count()) {
2871 // If this is not the last clip in playlist
2872 if (trackPlaylist.is_blank(clipIndex)) {
2873 int blankStart = trackPlaylist.clip_start(clipIndex);
2874 int blankDuration = trackPlaylist.clip_length(clipIndex);
2875 if (diff > blankDuration) {
2876 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2878 if (diff - blankDuration == 0) {
2879 trackPlaylist.remove(clipIndex);
2880 } else trackPlaylist.remove_region(blankStart, diff);
2882 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2885 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2886 trackPlaylist.consolidate_blanks(0);
2887 mlt_service_unlock(service.get_service());
2889 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2890 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2891 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2892 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2893 ItemInfo transpinfo;
2894 transpinfo.startPos = info.startPos;
2895 transpinfo.endPos = info.startPos + clipDuration;
2896 transpinfo.track = info.track;
2897 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2899 m_isBlocked = false;
2900 m_mltConsumer->set("refresh", 1);
2904 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2906 Mlt::Service service(m_mltProducer->parent().get_service());
2907 Mlt::Tractor tractor(service);
2908 Mlt::Producer trackProducer(tractor.track(track));
2911 if (blind) trackProducer.set("hide", 3);
2912 else trackProducer.set("hide", 2);
2914 trackProducer.set("hide", 1);
2916 trackProducer.set("hide", 0);
2918 tractor.multitrack()->refresh();
2924 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2926 Mlt::Service service(m_mltProducer->parent().get_service());
2927 int frameOffset = (int) diff.frames(m_fps);
2928 Mlt::Tractor tractor(service);
2929 Mlt::Producer trackProducer(tractor.track(info.track));
2930 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2931 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2932 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2935 mlt_service_lock(service.get_service());
2936 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2937 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2939 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2940 mlt_service_unlock(service.get_service());
2943 int previousStart = clip->get_in();
2944 int previousOut = clip->get_out();
2947 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2948 m_isBlocked = false;
2949 mlt_service_unlock(service.get_service());
2950 m_mltConsumer->set("refresh", 1);
2954 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2956 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2957 Mlt::Service service(m_mltProducer->parent().get_service());
2958 int moveFrame = (int) diff.frames(m_fps);
2959 Mlt::Tractor tractor(service);
2960 Mlt::Producer trackProducer(tractor.track(info.track));
2961 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2962 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2963 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2966 mlt_service_lock(service.get_service());
2967 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2968 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2969 if (clip == NULL || clip->is_blank()) {
2970 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2971 mlt_service_unlock(service.get_service());
2974 int previousStart = clip->get_in();
2975 int previousOut = clip->get_out();
2978 previousStart += moveFrame;
2980 int length = previousOut + 1;
2981 if (length > clip->get_length()) {
2982 clip->parent().set("length", length + 1);
2983 clip->parent().set("out", length);
2984 clip->set("length", length + 1);
2988 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
2989 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
2990 if (moveFrame > 0) {
2991 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2993 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2994 int blankIndex = clipIndex - 1;
2995 int blankLength = trackPlaylist.clip_length(blankIndex);
2996 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2997 if (! trackPlaylist.is_blank(blankIndex)) {
2998 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
3000 if (blankLength + moveFrame == 0)
3001 trackPlaylist.remove(blankIndex);
3003 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
3005 trackPlaylist.consolidate_blanks(0);
3006 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
3007 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
3008 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
3009 ItemInfo transpinfo;
3010 transpinfo.startPos = info.startPos + diff;
3011 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
3012 transpinfo.track = info.track;
3013 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3015 m_isBlocked = false;
3016 //m_mltConsumer->set("refresh", 1);
3017 mlt_service_unlock(service.get_service());
3018 m_mltConsumer->set("refresh", 1);
3022 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3024 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3028 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3030 if (prod == NULL || !prod->is_valid()) {
3031 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3034 kDebug() << "NEW PROD ID: " << prod->get("id");
3036 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3037 Mlt::Service service(m_mltProducer->parent().get_service());
3038 if (service.type() != tractor_type) {
3039 kWarning() << "// TRACTOR PROBLEM";
3042 mlt_service_lock(service.get_service());
3043 Mlt::Tractor tractor(service);
3044 Mlt::Producer trackProducer(tractor.track(track));
3045 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3046 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3047 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3048 if (clipProducer == NULL || clipProducer->is_blank()) {
3049 kDebug() << "// ERROR UPDATING CLIP PROD";
3050 delete clipProducer;
3051 mlt_service_unlock(service.get_service());
3055 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3056 if (!clip || !clip->is_valid()) {
3057 if (clip) delete clip;
3058 delete clipProducer;
3059 mlt_service_unlock(service.get_service());
3063 // move all effects to the correct producer
3064 mltPasteEffects(clipProducer, clip);
3065 trackPlaylist.insert_at(pos, clip, 1);
3067 delete clipProducer;
3068 mlt_service_unlock(service.get_service());
3073 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3077 Mlt::Service service(m_mltProducer->parent().get_service());
3078 if (service.type() != tractor_type) {
3079 kWarning() << "// TRACTOR PROBLEM";
3083 Mlt::Tractor tractor(service);
3084 mlt_service_lock(service.get_service());
3085 Mlt::Producer trackProducer(tractor.track(startTrack));
3086 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3087 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3088 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3089 bool checkLength = false;
3090 if (endTrack == startTrack) {
3091 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3092 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3093 // error, destination is not empty
3095 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3096 delete clipProducer;
3098 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3099 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3100 mlt_service_unlock(service.get_service());
3104 trackPlaylist.consolidate_blanks(0);
3106 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3107 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3108 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3110 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3111 trackPlaylist.consolidate_blanks(1);
3112 delete clipProducer;
3113 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3114 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3116 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3118 //mlt_service_unlock(service.get_service());
3120 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3121 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3122 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3123 // error, destination is not empty
3124 mlt_service_unlock(service.get_service());
3128 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3129 if (!clipProducer || clipProducer->is_blank()) {
3130 // error, destination is not empty
3131 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3132 if (clipProducer) delete clipProducer;
3133 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3134 mlt_service_unlock(service.get_service());
3138 trackPlaylist.consolidate_blanks(0);
3139 destTrackPlaylist.consolidate_blanks(1);
3140 Mlt::Producer *clip;
3141 // check if we are moving a slowmotion producer
3142 QString serv = clipProducer->parent().get("mlt_service");
3143 QString currentid = clipProducer->parent().get("id");
3144 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3145 clip = clipProducer;
3148 // Special case: prod is null when using placeholder clips.
3149 // in that case, use the producer existing in playlist. Note that
3150 // it will bypass the one producer per track logic and might cause
3151 // Sound cracks if clip is moved so that it overlaps another copy of itself
3152 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3153 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3156 // move all effects to the correct producer
3157 mltPasteEffects(clipProducer, clip);
3160 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3161 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3162 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3165 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3167 if (clip == clipProducer) {
3172 delete clipProducer;
3174 destTrackPlaylist.consolidate_blanks(0);
3175 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3176 kDebug() << "//////// moving clip transparency";
3177 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3179 if (clipIndex > trackPlaylist.count()) checkLength = true;
3180 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3183 mlt_service_unlock(service.get_service());
3184 if (checkLength) mltCheckLength(&tractor);
3187 //m_mltConsumer->set("refresh", 1);
3192 QList <int> Render::checkTrackSequence(int track)
3195 Mlt::Service service(m_mltProducer->parent().get_service());
3196 if (service.type() != tractor_type) {
3197 kWarning() << "// TRACTOR PROBLEM";
3200 Mlt::Tractor tractor(service);
3201 mlt_service_lock(service.get_service());
3202 Mlt::Producer trackProducer(tractor.track(track));
3203 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3204 int clipNb = trackPlaylist.count();
3205 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3206 for (int i = 0; i < clipNb; i++) {
3207 Mlt::Producer *c = trackPlaylist.get_clip(i);
3208 int pos = trackPlaylist.clip_start(i);
3209 if (!list.contains(pos)) list.append(pos);
3210 pos += c->get_playtime();
3211 if (!list.contains(pos)) list.append(pos);
3217 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3219 int new_in = (int)newIn.frames(m_fps);
3220 int new_out = (int)newOut.frames(m_fps) - 1;
3221 if (new_in >= new_out) return false;
3222 int old_in = (int)oldIn.frames(m_fps);
3223 int old_out = (int)oldOut.frames(m_fps) - 1;
3225 Mlt::Service service(m_mltProducer->parent().get_service());
3226 Mlt::Tractor tractor(service);
3227 Mlt::Field *field = tractor.field();
3229 bool doRefresh = true;
3230 // Check if clip is visible in monitor
3231 int diff = old_out - m_mltProducer->position();
3232 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3234 diff = new_out - m_mltProducer->position();
3235 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3239 mlt_service_lock(service.get_service());
3241 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3242 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3243 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3244 QString resource = mlt_properties_get(properties, "mlt_service");
3245 int old_pos = (int)(old_in + old_out) / 2;
3248 while (mlt_type == "transition") {
3249 Mlt::Transition transition((mlt_transition) nextservice);
3250 int currentTrack = transition.get_b_track();
3251 int currentIn = (int) transition.get_in();
3252 int currentOut = (int) transition.get_out();
3254 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3256 if (newTrack - startTrack != 0) {
3257 Mlt::Properties trans_props(transition.get_properties());
3258 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3259 Mlt::Properties new_trans_props(new_transition.get_properties());
3260 new_trans_props.inherit(trans_props);
3261 new_transition.set_in_and_out(new_in, new_out);
3262 field->disconnect_service(transition);
3263 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3264 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3265 } else transition.set_in_and_out(new_in, new_out);
3268 nextservice = mlt_service_producer(nextservice);
3269 if (nextservice == NULL) break;
3270 properties = MLT_SERVICE_PROPERTIES(nextservice);
3271 mlt_type = mlt_properties_get(properties, "mlt_type");
3272 resource = mlt_properties_get(properties, "mlt_service");
3274 mlt_service_unlock(service.get_service());
3276 if (doRefresh) refresh();
3277 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3282 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3284 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3285 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3286 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3287 QString resource = mlt_properties_get(properties, "mlt_service");
3288 QList <Mlt::Transition *> trList;
3290 while (mlt_type == "transition") {
3291 Mlt::Transition transition((mlt_transition) nextservice);
3292 int aTrack = transition.get_a_track();
3293 int bTrack = transition.get_b_track();
3294 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3295 Mlt::Properties trans_props(transition.get_properties());
3296 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3297 Mlt::Properties new_trans_props(cp->get_properties());
3298 new_trans_props.inherit(trans_props);
3300 field->disconnect_service(transition);
3302 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3304 nextservice = mlt_service_producer(nextservice);
3305 if (nextservice == NULL) break;
3306 properties = MLT_SERVICE_PROPERTIES(nextservice);
3307 mlt_type = mlt_properties_get(properties, "mlt_type");
3308 resource = mlt_properties_get(properties, "mlt_service");
3311 field->plant_transition(tr, a_track, b_track);
3313 // re-add upper transitions
3314 for (int i = 0; i < trList.count(); i++) {
3315 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3316 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3320 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3322 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3324 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3325 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3328 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3331 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3333 mlt_service serv = m_mltProducer->parent().get_service();
3334 mlt_service_lock(serv);
3337 mlt_service nextservice = mlt_service_get_producer(serv);
3338 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3339 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3340 QString resource = mlt_properties_get(properties, "mlt_service");
3341 int in_pos = (int) in.frames(m_fps);
3342 int out_pos = (int) out.frames(m_fps) - 1;
3344 while (mlt_type == "transition") {
3345 mlt_transition tr = (mlt_transition) nextservice;
3346 int currentTrack = mlt_transition_get_b_track(tr);
3347 int currentBTrack = mlt_transition_get_a_track(tr);
3348 int currentIn = (int) mlt_transition_get_in(tr);
3349 int currentOut = (int) mlt_transition_get_out(tr);
3351 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3353 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3354 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3355 QMap<QString, QString>::Iterator it;
3357 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3359 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3360 if (currentId != xml.attribute("id")) {
3361 // The transition ID is not the same, so reset all properties
3362 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3363 // Cleanup previous properties
3364 QStringList permanentProps;
3365 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3366 permanentProps << "out" << "a_track" << "b_track";
3367 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3368 QString propName = mlt_properties_get_name(transproperties, i);
3369 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3370 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3375 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3376 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3378 if (currentBTrack != a_track) {
3379 mlt_properties_set_int(transproperties, "a_track", a_track);
3381 for (it = map.begin(); it != map.end(); ++it) {
3383 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3384 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3385 //filter->set("kdenlive_id", id);
3389 nextservice = mlt_service_producer(nextservice);
3390 if (nextservice == NULL) break;
3391 properties = MLT_SERVICE_PROPERTIES(nextservice);
3392 mlt_type = mlt_properties_get(properties, "mlt_type");
3393 resource = mlt_properties_get(properties, "mlt_service");
3395 mlt_service_unlock(serv);
3398 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3401 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3403 mlt_service serv = m_mltProducer->parent().get_service();
3405 mlt_service_lock(serv);
3407 Mlt::Service service(serv);
3408 Mlt::Tractor tractor(service);
3409 Mlt::Field *field = tractor.field();
3411 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3413 mlt_service nextservice = mlt_service_get_producer(serv);
3414 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3415 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3416 QString resource = mlt_properties_get(properties, "mlt_service");
3418 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3419 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3421 while (mlt_type == "transition") {
3422 mlt_transition tr = (mlt_transition) nextservice;
3423 int currentTrack = mlt_transition_get_b_track(tr);
3424 int currentIn = (int) mlt_transition_get_in(tr);
3425 int currentOut = (int) mlt_transition_get_out(tr);
3426 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3428 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3429 mlt_field_disconnect_service(field->get_field(), nextservice);
3432 nextservice = mlt_service_producer(nextservice);
3433 if (nextservice == NULL) break;
3434 properties = MLT_SERVICE_PROPERTIES(nextservice);
3435 mlt_type = mlt_properties_get(properties, "mlt_type");
3436 resource = mlt_properties_get(properties, "mlt_service");
3438 mlt_service_unlock(serv);
3441 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3444 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3446 QDomNodeList attribs = xml.elementsByTagName("parameter");
3447 QMap<QString, QString> map;
3448 for (int i = 0; i < attribs.count(); i++) {
3449 QDomElement e = attribs.item(i).toElement();
3450 QString name = e.attribute("name");
3451 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3452 map[name] = e.attribute("default");
3453 if (!e.attribute("value").isEmpty()) {
3454 map[name] = e.attribute("value");
3456 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3457 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3458 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3461 if (e.attribute("namedesc").contains(';')) {
3462 QString format = e.attribute("format");
3463 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3464 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3466 QTextStream txtNeu(&neu);
3467 if (values.size() > 0)
3468 txtNeu << (int)values[0].toDouble();
3470 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3471 txtNeu << separators[i];
3472 txtNeu << (int)(values[i+1].toDouble());
3474 if (i < separators.size())
3475 txtNeu << separators[i];
3476 map[e.attribute("name")] = neu;
3483 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3485 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3486 Mlt::Service service(m_mltProducer->parent().get_service());
3487 Mlt::Tractor tractor(service);
3488 Mlt::Field *field = tractor.field();
3490 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3491 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3492 transition->set("transparency", id);
3493 transition->set("fill", 1);
3494 transition->set("internal_added", 237);
3495 field->plant_transition(*transition, transitiontrack, info.track);
3499 void Render::mltDeleteTransparency(int pos, int track, int id)
3501 Mlt::Service service(m_mltProducer->parent().get_service());
3502 Mlt::Tractor tractor(service);
3503 Mlt::Field *field = tractor.field();
3505 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3506 mlt_service serv = m_mltProducer->parent().get_service();
3508 mlt_service nextservice = mlt_service_get_producer(serv);
3509 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3510 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3511 QString resource = mlt_properties_get(properties, "mlt_service");
3513 while (mlt_type == "transition") {
3514 mlt_transition tr = (mlt_transition) nextservice;
3515 int currentTrack = mlt_transition_get_b_track(tr);
3516 int currentIn = (int) mlt_transition_get_in(tr);
3517 int currentOut = (int) mlt_transition_get_out(tr);
3518 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3519 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3521 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3522 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3523 mlt_field_disconnect_service(field->get_field(), nextservice);
3526 nextservice = mlt_service_producer(nextservice);
3527 if (nextservice == NULL) break;
3528 properties = MLT_SERVICE_PROPERTIES(nextservice);
3529 mlt_type = mlt_properties_get(properties, "mlt_type");
3530 resource = mlt_properties_get(properties, "mlt_service");
3532 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3535 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3537 Mlt::Service service(m_mltProducer->parent().get_service());
3538 Mlt::Tractor tractor(service);
3540 mlt_service_lock(service.get_service());
3541 m_mltConsumer->set("refresh", 0);
3544 mlt_service serv = m_mltProducer->parent().get_service();
3545 mlt_service nextservice = mlt_service_get_producer(serv);
3546 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3547 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3548 QString resource = mlt_properties_get(properties, "mlt_service");
3549 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3550 while (mlt_type == "transition") {
3551 mlt_transition tr = (mlt_transition) nextservice;
3552 int currentTrack = mlt_transition_get_b_track(tr);
3553 int currentIn = (int) mlt_transition_get_in(tr);
3554 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3555 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3556 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3557 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3558 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3559 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3562 nextservice = mlt_service_producer(nextservice);
3563 if (nextservice == NULL) break;
3564 properties = MLT_SERVICE_PROPERTIES(nextservice);
3565 mlt_type = mlt_properties_get(properties, "mlt_type");
3566 resource = mlt_properties_get(properties, "mlt_service");
3568 mlt_service_unlock(service.get_service());
3570 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3574 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3576 Mlt::Service service(m_mltProducer->parent().get_service());
3577 Mlt::Tractor tractor(service);
3579 mlt_service_lock(service.get_service());
3580 m_mltConsumer->set("refresh", 0);
3583 mlt_service serv = m_mltProducer->parent().get_service();
3584 mlt_service nextservice = mlt_service_get_producer(serv);
3585 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3586 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3587 QString resource = mlt_properties_get(properties, "mlt_service");
3589 while (mlt_type == "transition") {
3590 mlt_transition tr = (mlt_transition) nextservice;
3591 int currentTrack = mlt_transition_get_b_track(tr);
3592 int currentaTrack = mlt_transition_get_a_track(tr);
3593 int currentIn = (int) mlt_transition_get_in(tr);
3594 int currentOut = (int) mlt_transition_get_out(tr);
3595 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3596 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3597 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3598 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3599 kDebug() << "//////MOVING";
3600 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3601 if (endTrack != startTrack) {
3602 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3603 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3604 mlt_properties_set_int(properties, "b_track", endTrack);
3608 nextservice = mlt_service_producer(nextservice);
3609 if (nextservice == NULL) break;
3610 properties = MLT_SERVICE_PROPERTIES(nextservice);
3611 mlt_type = mlt_properties_get(properties, "mlt_type");
3612 resource = mlt_properties_get(properties, "mlt_service");
3615 mlt_service_unlock(service.get_service());
3616 m_mltConsumer->set("refresh", 1);
3620 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3622 if (in >= out) return false;
3623 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3624 Mlt::Service service(m_mltProducer->parent().get_service());
3626 Mlt::Tractor tractor(service);
3627 Mlt::Field *field = tractor.field();
3629 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3630 if (out != GenTime())
3631 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3633 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3634 QMap<QString, QString>::Iterator it;
3636 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3637 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3638 if (xml.hasAttribute("id"))
3639 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3641 for (it = args.begin(); it != args.end(); ++it) {
3643 if (!it.value().isEmpty())
3644 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3645 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3647 // attach transition
3648 mltPlantTransition(field, *transition, a_track, b_track);
3649 // field->plant_transition(*transition, a_track, b_track);
3650 if (do_refresh) refresh();
3654 void Render::mltSavePlaylist()
3656 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3657 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3658 fileConsumer.set("resource", "/tmp/playlist.mlt");
3660 Mlt::Service service(m_mltProducer->get_service());
3662 fileConsumer.connect(service);
3663 fileConsumer.start();
3666 const QList <Mlt::Producer *> Render::producersList()
3668 QList <Mlt::Producer *> prods;
3669 if (m_mltProducer == NULL) return prods;
3670 Mlt::Service service(m_mltProducer->parent().get_service());
3671 if (service.type() != tractor_type) return prods;
3672 Mlt::Tractor tractor(service);
3675 int trackNb = tractor.count();
3676 for (int t = 1; t < trackNb; t++) {
3677 Mlt::Producer *tt = tractor.track(t);
3678 Mlt::Producer trackProducer(tt);
3680 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3681 int clipNb = trackPlaylist.count();
3682 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3683 for (int i = 0; i < clipNb; i++) {
3684 Mlt::Producer *c = trackPlaylist.get_clip(i);
3685 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3687 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3688 ids.append(nprod->get("id"));
3689 prods.append(nprod);
3690 } else delete nprod;
3698 void Render::fillSlowMotionProducers()
3700 if (m_mltProducer == NULL) return;
3701 Mlt::Service service(m_mltProducer->parent().get_service());
3702 if (service.type() != tractor_type) return;
3704 Mlt::Tractor tractor(service);
3706 int trackNb = tractor.count();
3707 for (int t = 1; t < trackNb; t++) {
3708 Mlt::Producer *tt = tractor.track(t);
3709 Mlt::Producer trackProducer(tt);
3711 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3712 int clipNb = trackPlaylist.count();
3713 for (int i = 0; i < clipNb; i++) {
3714 Mlt::Producer *c = trackPlaylist.get_clip(i);
3715 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3717 QString id = nprod->get("id");
3718 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3719 // this is a slowmotion producer, add it to the list
3720 QString url = QString::fromUtf8(nprod->get("resource"));
3721 int strobe = nprod->get_int("strobe");
3722 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3723 if (!m_slowmotionProducers.contains(url)) {
3724 m_slowmotionProducers.insert(url, nprod);
3726 } else delete nprod;
3733 void Render::mltInsertTrack(int ix, bool videoTrack)
3738 Mlt::Service service(m_mltProducer->parent().get_service());
3739 mlt_service_lock(service.get_service());
3740 if (service.type() != tractor_type) {
3741 kWarning() << "// TRACTOR PROBLEM";
3745 Mlt::Tractor tractor(service);
3747 Mlt::Playlist playlist;
3748 int ct = tractor.count();
3750 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3756 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3757 tractor.set_track(playlist, pos);
3758 Mlt::Producer newProd(tractor.track(pos));
3759 if (!videoTrack) newProd.set("hide", 1);
3761 for (; pos <= ct; pos++) {
3762 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3763 tractor.set_track(*prodToMove, pos);
3764 prodToMove = prodToMove2;
3767 tractor.set_track(playlist, ix);
3768 Mlt::Producer newProd(tractor.track(ix));
3769 if (!videoTrack) newProd.set("hide", 1);
3773 mlt_service serv = m_mltProducer->parent().get_service();
3774 mlt_service nextservice = mlt_service_get_producer(serv);
3775 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3776 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3777 QString resource = mlt_properties_get(properties, "mlt_service");
3779 while (mlt_type == "transition") {
3780 if (resource != "mix") {
3781 mlt_transition tr = (mlt_transition) nextservice;
3782 int currentTrack = mlt_transition_get_b_track(tr);
3783 int currentaTrack = mlt_transition_get_a_track(tr);
3784 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3786 if (currentTrack >= ix) {
3787 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3788 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3791 nextservice = mlt_service_producer(nextservice);
3792 if (nextservice == NULL) break;
3793 properties = MLT_SERVICE_PROPERTIES(nextservice);
3794 mlt_type = mlt_properties_get(properties, "mlt_type");
3795 resource = mlt_properties_get(properties, "mlt_service");
3798 // Add audio mix transition to last track
3799 Mlt::Field *field = tractor.field();
3800 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3801 transition->set("a_track", 1);
3802 transition->set("b_track", ct);
3803 transition->set("always_active", 1);
3804 transition->set("internal_added", 237);
3805 transition->set("combine", 1);
3806 field->plant_transition(*transition, 1, ct);
3807 //mlt_service_unlock(m_mltConsumer->get_service());
3808 mlt_service_unlock(service.get_service());
3809 //tractor.multitrack()->refresh();
3810 //tractor.refresh();
3812 blockSignals(false);
3816 void Render::mltDeleteTrack(int ix)
3819 doc.setContent(sceneList(), false);
3820 int tracksCount = doc.elementsByTagName("track").count() - 1;
3821 QDomNode track = doc.elementsByTagName("track").at(ix);
3822 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3823 QDomNodeList transitions = doc.elementsByTagName("transition");
3824 for (int i = 0; i < transitions.count(); i++) {
3825 QDomElement e = transitions.at(i).toElement();
3826 QDomNodeList props = e.elementsByTagName("property");
3827 QMap <QString, QString> mappedProps;
3828 for (int j = 0; j < props.count(); j++) {
3829 QDomElement f = props.at(j).toElement();
3830 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3832 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3833 tractor.removeChild(transitions.at(i));
3835 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3836 // Transition needs to be moved
3837 int a_track = mappedProps.value("a_track").toInt();
3838 int b_track = mappedProps.value("b_track").toInt();
3839 if (a_track > 0 && a_track >= ix) a_track --;
3840 if (b_track == ix) {
3841 // transition was on the deleted track, so remove it
3842 tractor.removeChild(transitions.at(i));
3846 if (b_track > 0 && b_track > ix) b_track --;
3847 for (int j = 0; j < props.count(); j++) {
3848 QDomElement f = props.at(j).toElement();
3849 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3850 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3855 tractor.removeChild(track);
3856 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3857 setSceneList(doc.toString(), m_framePosition);
3859 /* if (m_mltProducer != NULL) {
3860 Mlt::Producer parentProd(m_mltProducer->parent());
3861 if (parentProd.get_producer() != NULL) {
3862 Mlt::Service service(parentProd.get_service());
3863 if (service.type() == tractor_type) {
3864 Mlt::Tractor tractor(service);
3865 mltCheckLength(&tractor);
3872 void Render::updatePreviewSettings()
3874 kDebug() << "////// RESTARTING CONSUMER";
3875 if (!m_mltConsumer || !m_mltProducer) return;
3876 if (m_mltProducer->get_playtime() == 0) return;
3877 Mlt::Service service(m_mltProducer->parent().get_service());
3878 if (service.type() != tractor_type) return;
3880 //m_mltConsumer->set("refresh", 0);
3881 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3882 m_mltConsumer->purge();
3883 QString scene = sceneList();
3885 if (m_mltProducer) {
3886 pos = m_mltProducer->position();
3889 setSceneList(scene, pos);
3893 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3895 // Update all frame positions to the new fps value
3896 //WARNING: there are probably some effects or other that hold a frame value
3897 // as parameter and will also need to be updated here!
3899 doc.setContent(scene);
3901 double factor = new_fps / current_fps;
3902 QDomNodeList producers = doc.elementsByTagName("producer");
3903 for (int i = 0; i < producers.count(); i++) {
3904 QDomElement prod = producers.at(i).toElement();
3905 prod.removeAttribute("in");
3906 prod.removeAttribute("out");
3908 QDomNodeList props = prod.childNodes();
3909 for (int j = 0; j < props.count(); j++) {
3910 QDomElement param = props.at(j).toElement();
3911 QString paramName = param.attribute("name");
3912 if (paramName.startsWith("meta.") || paramName == "length") {
3913 prod.removeChild(props.at(j));
3919 QDomNodeList entries = doc.elementsByTagName("entry");
3920 for (int i = 0; i < entries.count(); i++) {
3921 QDomElement entry = entries.at(i).toElement();
3922 int in = entry.attribute("in").toInt();
3923 int out = entry.attribute("out").toInt();
3924 in = factor * in + 0.5;
3925 out = factor * out + 0.5;
3926 entry.setAttribute("in", in);
3927 entry.setAttribute("out", out);
3930 QDomNodeList blanks = doc.elementsByTagName("blank");
3931 for (int i = 0; i < blanks.count(); i++) {
3932 QDomElement blank = blanks.at(i).toElement();
3933 int length = blank.attribute("length").toInt();
3934 length = factor * length + 0.5;
3935 blank.setAttribute("length", QString::number(length));
3938 QDomNodeList filters = doc.elementsByTagName("filter");
3939 for (int i = 0; i < filters.count(); i++) {
3940 QDomElement filter = filters.at(i).toElement();
3941 int in = filter.attribute("in").toInt();
3942 int out = filter.attribute("out").toInt();
3943 in = factor * in + 0.5;
3944 out = factor * out + 0.5;
3945 filter.setAttribute("in", in);
3946 filter.setAttribute("out", out);
3949 QDomNodeList transitions = doc.elementsByTagName("transition");
3950 for (int i = 0; i < transitions.count(); i++) {
3951 QDomElement transition = transitions.at(i).toElement();
3952 int in = transition.attribute("in").toInt();
3953 int out = transition.attribute("out").toInt();
3954 in = factor * in + 0.5;
3955 out = factor * out + 0.5;
3956 transition.setAttribute("in", in);
3957 transition.setAttribute("out", out);
3958 QDomNodeList props = transition.childNodes();
3959 for (int j = 0; j < props.count(); j++) {
3960 QDomElement param = props.at(j).toElement();
3961 QString paramName = param.attribute("name");
3962 if (paramName == "geometry") {
3963 QString geom = param.firstChild().nodeValue();
3964 QStringList keys = geom.split(';');
3965 QStringList newKeys;
3966 for (int k = 0; k < keys.size(); ++k) {
3967 if (keys.at(k).contains('=')) {
3968 int pos = keys.at(k).section('=', 0, 0).toInt();
3969 pos = factor * pos + 0.5;
3970 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3971 } else newKeys.append(keys.at(k));
3973 param.firstChild().setNodeValue(newKeys.join(";"));
3977 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3978 int out = tractor.attribute("out").toInt();
3979 out = factor * out + 0.5;
3980 tractor.setAttribute("out", out);
3981 emit durationChanged(out);
3983 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3984 return doc.toString();
3988 void Render::sendFrameUpdate()
3990 if (m_mltProducer) {
3991 Mlt::Frame * frame = m_mltProducer->get_frame();
3992 emitFrameUpdated(*frame);
3998 #include "renderer.moc"