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 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
744 if (producer->get_int("audio_index") > -1) {
745 // Get the audio_index
746 int index = producer->get_int("audio_index");
748 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
749 if (producer->get(property)) {
750 filePropertyMap["audiocodec"] = producer->get(property);
752 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
753 if (producer->get(property))
754 filePropertyMap["audiocodec"] = producer->get(property);
759 Mlt::Properties metadata;
760 metadata.pass_values(*producer, "meta.attr.");
761 int count = metadata.count();
762 for (int i = 0; i < count; i ++) {
763 QString name = metadata.get_name(i);
764 QString value = QString::fromUtf8(metadata.get(i));
765 if (name.endsWith("markup") && !value.isEmpty())
766 metadataPropertyMap[ name.section('.', 0, -2)] = value;
769 kDebug() << "REquested fuile info for: " << url.path();
770 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
771 // FIXME: should delete this to avoid a leak...
777 /** Create the producer from the MLT XML QDomDocument */
778 void Render::initSceneList()
780 kDebug() << "-------- INIT SCENE LIST ------_";
782 QDomElement mlt = doc.createElement("mlt");
783 doc.appendChild(mlt);
784 QDomElement prod = doc.createElement("producer");
785 prod.setAttribute("resource", "colour");
786 prod.setAttribute("colour", "red");
787 prod.setAttribute("id", "black");
788 prod.setAttribute("in", "0");
789 prod.setAttribute("out", "0");
791 QDomElement tractor = doc.createElement("tractor");
792 QDomElement multitrack = doc.createElement("multitrack");
794 QDomElement playlist1 = doc.createElement("playlist");
795 playlist1.appendChild(prod);
796 multitrack.appendChild(playlist1);
797 QDomElement playlist2 = doc.createElement("playlist");
798 multitrack.appendChild(playlist2);
799 QDomElement playlist3 = doc.createElement("playlist");
800 multitrack.appendChild(playlist3);
801 QDomElement playlist4 = doc.createElement("playlist");
802 multitrack.appendChild(playlist4);
803 QDomElement playlist5 = doc.createElement("playlist");
804 multitrack.appendChild(playlist5);
805 tractor.appendChild(multitrack);
806 mlt.appendChild(tractor);
807 // kDebug()<<doc.toString();
809 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
810 setSceneList(doc, 0);
814 int Render::setProducer(Mlt::Producer *producer, int position)
816 if (m_winid == -1) return -1;
819 m_mltConsumer->stop();
822 m_mltConsumer->purge();
825 m_mltProducer->set_speed(0);
826 delete m_mltProducer;
827 m_mltProducer = NULL;
831 m_mltProducer = new Mlt::Producer(producer->get_producer());
832 } else m_mltProducer = m_blackClip->cut(0, 50);
834 if (!m_mltProducer || !m_mltProducer->is_valid()) {
835 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
838 int volume = KdenliveSettings::volume();
839 m_mltProducer->set("meta.volume", (double)volume / 100);
840 m_fps = m_mltProducer->get_fps();
841 int error = connectPlaylist();
843 if (position != -1) {
844 m_mltProducer->seek(position);
845 emit rendererPosition(position);
846 } else emit rendererPosition((int) m_mltProducer->position());
851 int Render::setSceneList(QDomDocument list, int position)
853 return setSceneList(list.toString(), position);
856 int Render::setSceneList(QString playlist, int position)
858 if (m_winid == -1) return -1;
862 //kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
865 if (!m_mltConsumer->is_stopped()) {
866 m_mltConsumer->stop();
868 m_mltConsumer->set("refresh", 0);
870 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
875 m_mltProducer->set_speed(0);
876 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
879 Mlt::Service service(m_mltProducer->parent().get_service());
880 mlt_service_lock(service.get_service());
882 if (service.type() == tractor_type) {
883 Mlt::Tractor tractor(service);
884 Mlt::Field *field = tractor.field();
885 mlt_service nextservice = mlt_service_get_producer(service.get_service());
886 mlt_service nextservicetodisconnect;
887 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
888 QString mlt_type = mlt_properties_get(properties, "mlt_type");
889 QString resource = mlt_properties_get(properties, "mlt_service");
890 // Delete all transitions
891 while (mlt_type == "transition") {
892 nextservicetodisconnect = nextservice;
893 nextservice = mlt_service_producer(nextservice);
894 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
895 if (nextservice == NULL) break;
896 properties = MLT_SERVICE_PROPERTIES(nextservice);
897 mlt_type = mlt_properties_get(properties, "mlt_type");
898 resource = mlt_properties_get(properties, "mlt_service");
901 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
902 Mlt::Producer trackProducer(tractor.track(trackNb));
903 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
904 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
908 mlt_service_unlock(service.get_service());
910 qDeleteAll(m_slowmotionProducers.values());
911 m_slowmotionProducers.clear();
913 delete m_mltProducer;
914 m_mltProducer = NULL;
920 // TODO: Better way to do this
921 if (KdenliveSettings::projectloading_avformatnovalidate())
922 playlist.replace(">avformat</property>", ">avformat-novalidate</property>");
924 playlist.replace(">avformat-novalidate</property>", ">avformat</property>");
926 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
928 if (!m_mltProducer || !m_mltProducer->is_valid()) {
929 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
930 m_mltProducer = m_blackClip->cut(0, 50);
933 int volume = KdenliveSettings::volume();
934 m_mltProducer->set("meta.volume", (double)volume / 100);
935 m_mltProducer->optimise();
937 /*if (KdenliveSettings::osdtimecode()) {
938 // Attach filter for on screen display of timecode
940 QString attr = "attr_check";
941 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
942 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
943 mlt_producer_attach( m_mltProducer->get_producer(), filter );
944 mlt_filter_close( filter );
946 m_osdInfo = new Mlt::Filter("data_show");
947 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
948 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
949 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
950 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
951 m_osdInfo->set("dynamic", "1");
953 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
955 m_osdInfo->set("dynamic", "0");
958 m_fps = m_mltProducer->get_fps();
960 // Seek to correct place after opening project.
961 m_mltProducer->seek(position);
964 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
965 if (error == 0) error = connectPlaylist();
966 else connectPlaylist();
967 fillSlowMotionProducers();
973 //kDebug()<<"// SETSCN LST, POS: "<<position;
974 //if (position != 0) emit rendererPosition(position);
977 const QString Render::sceneList()
980 Mlt::Profile profile((mlt_profile) 0);
981 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
982 m_mltProducer->optimise();
983 xmlConsumer.set("terminate_on_pause", 1);
984 Mlt::Producer prod(m_mltProducer->get_producer());
985 bool split = m_isSplitView;
986 if (split) slotSplitView(false);
987 xmlConsumer.connect(prod);
989 while (!xmlConsumer.is_stopped()) {}
990 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
991 if (split) slotSplitView(true);
995 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
999 doc.setContent(sceneList(), false);
1000 if (!kdenliveData.isNull()) {
1001 // add Kdenlive specific tags
1002 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1003 mlt.appendChild(doc.importNode(kdenliveData, true));
1005 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1006 kWarning() << "////// ERROR writing to file: " << path;
1009 file.write(doc.toString().toUtf8());
1010 if (file.error() != QFile::NoError) {
1018 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1020 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1021 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1022 m_mltProducer->optimise();
1023 xmlConsumer.set("terminate_on_pause", 1);
1024 if (m_name == "clip") {
1025 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1027 list.insert_at(0, prod, 0);
1029 list.set("title", desc.toUtf8().constData());
1030 xmlConsumer.connect(list);
1033 //TODO: not working yet, save zone from timeline
1034 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1035 /* Mlt::Service service(p1->parent().get_service());
1036 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1038 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1039 //prod->set("title", desc.toUtf8().constData());
1040 xmlConsumer.connect(*p1); //list);
1043 xmlConsumer.start();
1046 double Render::fps() const
1051 int Render::connectPlaylist()
1053 if (!m_mltConsumer) return -1;
1054 //m_mltConsumer->set("refresh", "0");
1055 m_mltConsumer->connect(*m_mltProducer);
1056 m_mltProducer->set_speed(0);
1057 if (m_mltConsumer->start() == -1) {
1058 // ARGH CONSUMER BROKEN!!!!
1059 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."));
1060 delete m_mltConsumer;
1061 m_mltConsumer = NULL;
1064 emit durationChanged(m_mltProducer->get_playtime());
1069 void Render::refreshDisplay()
1072 if (!m_mltProducer) return;
1073 //m_mltConsumer->set("refresh", 0);
1075 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1076 /*if (KdenliveSettings::osdtimecode()) {
1077 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1078 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1079 m_osdInfo->set("dynamic", "1");
1080 m_mltProducer->attach(*m_osdInfo);
1083 m_mltProducer->detach(*m_osdInfo);
1084 m_osdInfo->set("dynamic", "0");
1089 int Render::volume() const
1091 if (!m_mltConsumer || !m_mltProducer) return -1;
1092 return ((int) 100 * m_mltProducer->get_double("meta.volume"));
1095 void Render::slotSetVolume(int volume)
1097 if (!m_mltConsumer || !m_mltProducer) return;
1098 m_mltProducer->set("meta.volume", (double)volume / 100.0);
1101 m_mltConsumer->set("refresh", 0);
1102 // Attach filter for on screen display of timecode
1103 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1104 mlt_properties_set_double( properties, "meta.volume", volume );
1105 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1106 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1108 if (!KdenliveSettings::osdtimecode()) {
1109 m_mltProducer->detach(*m_osdInfo);
1110 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1111 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1114 //m_osdTimer->setSingleShot(2500);
1117 void Render::slotOsdTimeout()
1119 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1120 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1121 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1122 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1126 void Render::start()
1128 kDebug() << "----- STARTING MONITOR: " << m_name;
1129 if (m_winid == -1) {
1130 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1133 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1134 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1135 if (m_mltConsumer->start() == -1) {
1136 //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."));
1137 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1139 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1140 m_isBlocked = false;
1144 m_isBlocked = false;
1149 if (m_mltProducer == NULL) return;
1150 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1151 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1153 //m_mltConsumer->set("refresh", 0);
1154 m_mltConsumer->stop();
1155 // delete m_mltConsumer;
1156 // m_mltConsumer = NULL;
1158 kDebug() << "///////////// RENDER STOP2-------";
1161 if (m_mltProducer) {
1162 if (m_isZoneMode) resetZoneMode();
1163 m_mltProducer->set_speed(0.0);
1164 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1165 //kDebug() << m_mltProducer->get_length();
1167 kDebug() << "///////////// RENDER STOP3-------";
1170 void Render::stop(const GenTime & startTime)
1173 kDebug() << "///////////// RENDER STOP-------2";
1174 if (m_mltProducer) {
1175 if (m_isZoneMode) resetZoneMode();
1176 m_mltProducer->set_speed(0.0);
1177 m_mltProducer->seek((int) startTime.frames(m_fps));
1179 m_mltConsumer->purge();
1182 void Render::pause()
1184 if (!m_mltProducer || !m_mltConsumer)
1186 if (m_mltProducer->get_speed() == 0.0) return;
1187 if (m_isZoneMode) resetZoneMode();
1189 m_mltConsumer->set("refresh", 0);
1190 m_mltProducer->set_speed(0.0);
1192 The 2 lines below create a flicker loop
1193 emit rendererPosition(m_framePosition);
1194 m_mltProducer->seek(m_framePosition);*/
1195 m_mltConsumer->purge();
1198 void Render::switchPlay()
1200 if (!m_mltProducer || !m_mltConsumer)
1202 if (m_isZoneMode) resetZoneMode();
1203 if (m_mltProducer->get_speed() == 0.0) {
1204 m_isBlocked = false;
1205 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1206 m_mltProducer->set_speed(1.0);
1207 m_mltConsumer->set("refresh", 1);
1210 m_mltConsumer->set("refresh", 0);
1211 m_mltProducer->set_speed(0.0);
1212 //emit rendererPosition(m_framePosition);
1213 m_mltProducer->seek(m_framePosition);
1214 m_mltConsumer->purge();
1215 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1216 //m_mltConsumer->set("refresh", 0);
1217 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1218 m_mltProducer->set_speed(0);
1219 m_mltProducer->seek( position );
1220 //m_mltProducer->seek((int) m_framePosition);
1221 m_isBlocked = false;*/
1223 /*if (speed == 0.0) {
1224 m_mltProducer->seek((int) m_framePosition + 1);
1225 m_mltConsumer->purge();
1230 void Render::play(double speed)
1234 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1235 m_isBlocked = false;
1236 m_mltProducer->set_speed(speed);
1237 /*if (speed == 0.0) {
1238 m_mltProducer->seek((int) m_framePosition + 1);
1239 m_mltConsumer->purge();
1244 void Render::play(const GenTime & startTime)
1246 if (!m_mltProducer || !m_mltConsumer)
1248 m_isBlocked = false;
1249 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1250 m_mltProducer->set_speed(1.0);
1251 m_mltConsumer->set("refresh", 1);
1254 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1256 if (!m_mltProducer || !m_mltConsumer)
1258 //m_mltProducer->set("eof", "loop");
1259 m_isLoopMode = true;
1260 m_loopStart = startTime;
1261 playZone(startTime, stopTime);
1264 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1266 if (!m_mltProducer || !m_mltConsumer)
1268 m_isBlocked = false;
1269 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1270 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1271 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1272 m_mltProducer->set_speed(1.0);
1273 m_mltConsumer->set("refresh", 1);
1274 m_isZoneMode = true;
1277 void Render::resetZoneMode()
1279 if (!m_isZoneMode && !m_isLoopMode) return;
1280 m_mltProducer->set("out", m_originalOut);
1281 //m_mltProducer->set("eof", "pause");
1282 m_isZoneMode = false;
1283 m_isLoopMode = false;
1286 void Render::seekToFrame(int pos)
1288 //kDebug()<<" ********* RENDER SEEK TO POS";
1291 m_isBlocked = false;
1293 m_mltProducer->seek(pos);
1297 void Render::seekToFrameDiff(int diff)
1299 //kDebug()<<" ********* RENDER SEEK TO POS";
1302 m_isBlocked = false;
1304 m_mltProducer->seek(m_mltProducer->position() + diff);
1308 void Render::doRefresh()
1310 // Use a Timer so that we don't refresh too much
1311 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1314 void Render::refresh()
1316 if (!m_mltProducer || m_isBlocked)
1318 if (m_mltConsumer) {
1319 m_mltConsumer->set("refresh", 1);
1323 void Render::setDropFrames(bool show)
1325 if (m_mltConsumer) {
1327 if (show == false) dropFrames = 0;
1328 m_mltConsumer->stop();
1330 m_mltConsumer->set("real_time", dropFrames);
1332 m_mltConsumer->set("play.real_time", dropFrames);
1334 if (m_mltConsumer->start() == -1) {
1335 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1341 double Render::playSpeed()
1343 if (m_mltProducer) return m_mltProducer->get_speed();
1347 GenTime Render::seekPosition() const
1349 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1350 else return GenTime();
1353 int Render::seekFramePosition() const
1355 if (m_mltProducer) return (int) m_mltProducer->position();
1359 const QString & Render::rendererName() const
1364 void Render::emitFrameUpdated(Mlt::Frame& frame)
1366 mlt_image_format format = mlt_image_rgb24a;
1369 const uchar* image = frame.get_image(format, width, height);
1370 QImage qimage(width, height, QImage::Format_ARGB32);
1371 memcpy(qimage.bits(), image, width * height * 4);
1372 emit frameUpdated(qimage.rgbSwapped());
1375 void Render::emitFrameNumber(double position)
1377 m_framePosition = position;
1378 emit rendererPosition((int) position);
1381 void Render::emitConsumerStopped()
1383 // This is used to know when the playing stopped
1384 if (m_mltProducer) {
1385 double pos = m_mltProducer->position();
1386 if (m_isLoopMode) play(m_loopStart);
1387 else if (m_isZoneMode) resetZoneMode();
1388 emit rendererStopped((int) pos);
1392 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1394 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1397 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1399 if (!m_mltProducer) {
1400 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1404 //int height = 1080;//KdenliveSettings::defaultheight();
1405 //int width = 1940; //KdenliveSettings::displaywidth();
1407 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1409 QPixmap pix(width, height);
1410 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1411 m_convert.set("forced", mlt_image_rgb24a);
1412 m_mltProducer->attach(m_convert);
1413 Mlt::Frame * frame = m_mltProducer->get_frame();
1414 m_mltProducer->detach(m_convert);
1416 pix = frameThumbnail(frame, width, height);
1419 pix.save(url.path(), "PNG");
1420 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1424 void Render::showFrame(Mlt::Frame& frame)
1426 m_framePosition = qMax(frame.get_int("_position"), 0);
1427 emit rendererPosition((int) m_framePosition);
1428 mlt_image_format format = mlt_image_rgb24a;
1431 const uchar* image = frame.get_image(format, width, height);
1432 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1433 memcpy(qimage.scanLine(0), image, width * height * 4);
1434 emit showImageSignal(qimage);
1436 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1437 emit frameUpdated(qimage.rgbSwapped());
1441 void Render::showAudio(Mlt::Frame& frame)
1443 if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
1444 mlt_audio_format audio_format = mlt_audio_s16;
1446 int num_channels = 0;
1448 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1451 int num_samples = samples > 200 ? 200 : samples;
1452 QByteArray channels;
1453 for (int i = 0; i < num_channels; i++) {
1455 for (int s = 0; s < num_samples; s ++) {
1456 val += abs(data[i+s*num_channels] / 128);
1458 channels.append(val / num_samples);
1463 emit showAudioSignal(channels);
1465 emit showAudioSignal(QByteArray());
1469 * MLT playlist direct manipulation.
1472 void Render::mltCheckLength(Mlt::Tractor *tractor)
1474 //kDebug()<<"checking track length: "<<track<<"..........";
1476 int trackNb = tractor->count();
1480 Mlt::Producer trackProducer(tractor->track(0));
1481 duration = trackProducer.get_playtime() - 1;
1482 m_mltProducer->set("out", duration);
1483 emit durationChanged(duration);
1486 while (trackNb > 1) {
1487 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1488 trackDuration = trackProducer.get_playtime() - 1;
1489 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1490 if (trackDuration > duration) duration = trackDuration;
1494 Mlt::Producer blackTrackProducer(tractor->track(0));
1496 if (blackTrackProducer.get_playtime() - 1 != duration) {
1497 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1498 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1499 if (blackclip && blackclip->is_blank()) {
1504 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1505 blackTrackPlaylist.clear();
1506 m_blackClip->set("length", duration + 1);
1507 m_blackClip->set("out", duration);
1508 blackclip = m_blackClip->cut(0, duration);
1509 blackTrackPlaylist.insert_at(0, blackclip, 1);
1511 if (duration > blackclip->parent().get_length()) {
1512 blackclip->parent().set("length", duration + 1);
1513 blackclip->parent().set("out", duration);
1514 blackclip->set("length", duration + 1);
1516 blackTrackPlaylist.resize_clip(0, 0, duration);
1520 m_mltProducer->set("out", duration);
1521 emit durationChanged(duration);
1525 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1527 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1529 // We want a slowmotion producer
1530 double speed = element.attribute("speed", "1.0").toDouble();
1531 int strobe = element.attribute("strobe", "1").toInt();
1532 QString url = QString::fromUtf8(prod->get("resource"));
1533 url.append('?' + QString::number(speed));
1534 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1535 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1536 if (!slowprod || slowprod->get_producer() == NULL) {
1537 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1538 if (strobe > 1) slowprod->set("strobe", strobe);
1539 QString id = prod->get("id");
1540 if (id.contains('_')) id = id.section('_', 0, 0);
1541 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1542 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1543 slowprod->set("id", producerid.toUtf8().constData());
1544 m_slowmotionProducers.insert(url, slowprod);
1549 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1551 if (m_mltProducer == NULL) {
1552 kDebug() << "PLAYLIST NOT INITIALISED //////";
1556 kDebug() << "Cannot insert clip without producer //////";
1559 Mlt::Producer parentProd(m_mltProducer->parent());
1560 if (parentProd.get_producer() == NULL) {
1561 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1565 Mlt::Service service(parentProd.get_service());
1566 if (service.type() != tractor_type) {
1567 kWarning() << "// TRACTOR PROBLEM";
1570 Mlt::Tractor tractor(service);
1571 if (info.track > tractor.count() - 1) {
1572 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1575 mlt_service_lock(service.get_service());
1576 Mlt::Producer trackProducer(tractor.track(info.track));
1577 int trackDuration = trackProducer.get_playtime() - 1;
1578 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1579 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1580 prod = checkSlowMotionProducer(prod, element);
1581 if (prod == NULL || !prod->is_valid()) {
1582 mlt_service_unlock(service.get_service());
1586 int cutPos = (int) info.cropStart.frames(m_fps);
1587 if (cutPos < 0) cutPos = 0;
1588 int insertPos = (int) info.startPos.frames(m_fps);
1589 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1590 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1591 if (overwrite && (insertPos < trackDuration)) {
1592 // Replace zone with blanks
1593 //trackPlaylist.split_at(insertPos, true);
1594 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1595 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1596 trackPlaylist.insert_blank(clipIndex, cutDuration);
1598 trackPlaylist.split_at(insertPos, true);
1599 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1600 trackPlaylist.insert_blank(clipIndex, cutDuration);
1602 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1604 /*if (QString(prod->get("transparency")).toInt() == 1)
1605 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1607 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1608 mlt_service_unlock(service.get_service());
1609 /*tractor.multitrack()->refresh();
1610 tractor.refresh();*/
1615 void Render::mltCutClip(int track, GenTime position)
1619 Mlt::Service service(m_mltProducer->parent().get_service());
1620 if (service.type() != tractor_type) {
1621 kWarning() << "// TRACTOR PROBLEM";
1625 Mlt::Tractor tractor(service);
1626 Mlt::Producer trackProducer(tractor.track(track));
1627 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1630 /* // Display playlist info
1631 kDebug()<<"//////////// BEFORE";
1632 for (int i = 0; i < trackPlaylist.count(); i++) {
1633 int blankStart = trackPlaylist.clip_start(i);
1634 int blankDuration = trackPlaylist.clip_length(i) - 1;
1636 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1637 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1640 int cutPos = (int) position.frames(m_fps);
1642 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1643 if (trackPlaylist.is_blank(clipIndex)) {
1644 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1645 m_isBlocked = false;
1648 mlt_service_lock(service.get_service());
1649 int clipStart = trackPlaylist.clip_start(clipIndex);
1650 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1651 mlt_service_unlock(service.get_service());
1653 // duplicate effects
1654 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1655 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1657 if (original == NULL || clip == NULL) {
1658 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1660 Mlt::Service clipService(original->get_service());
1661 Mlt::Service dupService(clip->get_service());
1665 Mlt::Filter *filter = clipService.filter(ct);
1667 // Only duplicate Kdenlive filters, and skip the fade in effects
1668 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1669 // looks like there is no easy way to duplicate a filter,
1670 // so we will create a new one and duplicate its properties
1671 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1672 if (dup && dup->is_valid()) {
1673 Mlt::Properties entries(filter->get_properties());
1674 for (int i = 0; i < entries.count(); i++) {
1675 dup->set(entries.get_name(i), entries.get(i));
1677 dupService.attach(*dup);
1681 filter = clipService.filter(ct);
1684 /* // Display playlist info
1685 kDebug()<<"//////////// AFTER";
1686 for (int i = 0; i < trackPlaylist.count(); i++) {
1687 int blankStart = trackPlaylist.clip_start(i);
1688 int blankDuration = trackPlaylist.clip_length(i) - 1;
1690 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1691 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1694 m_isBlocked = false;
1697 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1701 kDebug() << "Cannot update clip with null producer //////";
1704 Mlt::Service service(m_mltProducer->parent().get_service());
1705 if (service.type() != tractor_type) {
1706 kWarning() << "// TRACTOR PROBLEM";
1709 Mlt::Tractor tractor(service);
1710 Mlt::Producer trackProducer(tractor.track(info.track));
1711 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1712 int startPos = info.startPos.frames(m_fps);
1713 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1714 if (trackPlaylist.is_blank(clipIndex)) {
1715 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1718 mlt_service_lock(service.get_service());
1719 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1721 QList <Mlt::Filter *> filtersList;
1722 Mlt::Service sourceService(clip->get_service());
1724 Mlt::Filter *filter = sourceService.filter(ct);
1726 if (filter->get_int("kdenlive_ix") != 0) {
1727 filtersList.append(filter);
1730 filter = sourceService.filter(ct);
1733 trackPlaylist.replace_with_blank(clipIndex);
1735 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1736 prod = checkSlowMotionProducer(prod, element);
1737 if (prod == NULL || !prod->is_valid()) {
1738 mlt_service_unlock(service.get_service());
1741 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1742 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1746 //if (mltInsertClip(info, element, prod) == -1) return false;
1747 if (!filtersList.isEmpty()) {
1748 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1749 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1750 Mlt::Service destService(destclip->get_service());
1752 for (int i = 0; i < filtersList.count(); i++)
1753 destService.attach(*(filtersList.at(i)));
1755 mlt_service_unlock(service.get_service());
1760 bool Render::mltRemoveClip(int track, GenTime position)
1762 Mlt::Service service(m_mltProducer->parent().get_service());
1763 if (service.type() != tractor_type) {
1764 kWarning() << "// TRACTOR PROBLEM";
1768 Mlt::Tractor tractor(service);
1769 mlt_service_lock(service.get_service());
1770 Mlt::Producer trackProducer(tractor.track(track));
1771 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1772 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1774 // Display playlist info
1775 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1776 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1777 int blankStart = trackPlaylist.clip_start(i);
1778 int blankDuration = trackPlaylist.clip_length(i) - 1;
1780 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1781 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1783 if (trackPlaylist.is_blank(clipIndex)) {
1784 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1785 mlt_service_unlock(service.get_service());
1788 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1790 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1791 if (clip) delete clip;
1792 trackPlaylist.consolidate_blanks(0);
1793 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1794 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1796 /* // Display playlist info
1797 kDebug()<<"//// AFTER";
1798 for (int i = 0; i < trackPlaylist.count(); i++) {
1799 int blankStart = trackPlaylist.clip_start(i);
1800 int blankDuration = trackPlaylist.clip_length(i) - 1;
1802 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1803 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1805 mlt_service_unlock(service.get_service());
1806 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1807 m_isBlocked = false;
1811 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1813 if (!m_mltProducer) {
1814 kDebug() << "PLAYLIST NOT INITIALISED //////";
1817 Mlt::Producer parentProd(m_mltProducer->parent());
1818 if (parentProd.get_producer() == NULL) {
1819 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1823 Mlt::Service service(parentProd.get_service());
1824 Mlt::Tractor tractor(service);
1825 int insertPos = pos.frames(m_fps);
1827 Mlt::Producer trackProducer(tractor.track(track));
1828 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1829 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1830 if (clipIndex == trackPlaylist.count()) {
1831 // We are after the end of the playlist
1834 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1835 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1836 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1839 int Render::mltTrackDuration(int track)
1841 if (!m_mltProducer) {
1842 kDebug() << "PLAYLIST NOT INITIALISED //////";
1845 Mlt::Producer parentProd(m_mltProducer->parent());
1846 if (parentProd.get_producer() == NULL) {
1847 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1851 Mlt::Service service(parentProd.get_service());
1852 Mlt::Tractor tractor(service);
1854 Mlt::Producer trackProducer(tractor.track(track));
1855 return trackProducer.get_playtime() - 1;
1858 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1860 if (!m_mltProducer) {
1861 kDebug() << "PLAYLIST NOT INITIALISED //////";
1864 Mlt::Producer parentProd(m_mltProducer->parent());
1865 if (parentProd.get_producer() == NULL) {
1866 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1869 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1870 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1872 Mlt::Service service(parentProd.get_service());
1873 Mlt::Tractor tractor(service);
1874 mlt_service_lock(service.get_service());
1875 int diff = duration.frames(m_fps);
1876 int offset = timeOffset.frames(m_fps);
1880 // insert space in one track only
1881 Mlt::Producer trackProducer(tractor.track(track));
1882 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1883 insertPos = trackClipStartList.value(track);
1884 if (insertPos != -1) {
1885 insertPos += offset;
1886 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1888 trackPlaylist.insert_blank(clipIndex, diff - 1);
1890 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1891 if (!trackPlaylist.is_blank(clipIndex)) {
1892 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1894 int position = trackPlaylist.clip_start(clipIndex);
1895 int blankDuration = trackPlaylist.clip_length(clipIndex);
1897 if (blankDuration - diff == 0) {
1898 trackPlaylist.remove(clipIndex);
1899 } else trackPlaylist.remove_region(position, diff);
1901 trackPlaylist.consolidate_blanks(0);
1903 // now move transitions
1904 mlt_service serv = m_mltProducer->parent().get_service();
1905 mlt_service nextservice = mlt_service_get_producer(serv);
1906 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1907 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1908 QString resource = mlt_properties_get(properties, "mlt_service");
1910 while (mlt_type == "transition") {
1911 mlt_transition tr = (mlt_transition) nextservice;
1912 int currentTrack = mlt_transition_get_b_track(tr);
1913 int currentIn = (int) mlt_transition_get_in(tr);
1914 int currentOut = (int) mlt_transition_get_out(tr);
1915 insertPos = trackTransitionStartList.value(track);
1916 if (insertPos != -1) {
1917 insertPos += offset;
1918 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1919 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1922 nextservice = mlt_service_producer(nextservice);
1923 if (nextservice == NULL) break;
1924 properties = MLT_SERVICE_PROPERTIES(nextservice);
1925 mlt_type = mlt_properties_get(properties, "mlt_type");
1926 resource = mlt_properties_get(properties, "mlt_service");
1929 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1930 Mlt::Producer trackProducer(tractor.track(trackNb));
1931 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1933 //int clipNb = trackPlaylist.count();
1934 insertPos = trackClipStartList.value(trackNb);
1935 if (insertPos != -1) {
1936 insertPos += offset;
1938 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1939 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1940 for (int i = 0; i < clipNb; i++) {
1941 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1942 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1943 kDebug()<<"-------------";
1945 kDebug()<<"END-------------";*/
1948 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1950 trackPlaylist.insert_blank(clipIndex, diff - 1);
1952 if (!trackPlaylist.is_blank(clipIndex)) {
1955 if (!trackPlaylist.is_blank(clipIndex)) {
1956 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1958 int position = trackPlaylist.clip_start(clipIndex);
1959 int blankDuration = trackPlaylist.clip_length(clipIndex);
1960 if (diff + blankDuration == 0) {
1961 trackPlaylist.remove(clipIndex);
1962 } else trackPlaylist.remove_region(position, - diff);
1964 trackPlaylist.consolidate_blanks(0);
1967 // now move transitions
1968 mlt_service serv = m_mltProducer->parent().get_service();
1969 mlt_service nextservice = mlt_service_get_producer(serv);
1970 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1971 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1972 QString resource = mlt_properties_get(properties, "mlt_service");
1974 while (mlt_type == "transition") {
1975 mlt_transition tr = (mlt_transition) nextservice;
1976 int currentIn = (int) mlt_transition_get_in(tr);
1977 int currentOut = (int) mlt_transition_get_out(tr);
1978 int currentTrack = mlt_transition_get_b_track(tr);
1979 insertPos = trackTransitionStartList.value(currentTrack);
1980 if (insertPos != -1) {
1981 insertPos += offset;
1982 if (currentOut > insertPos && resource != "mix") {
1983 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1986 nextservice = mlt_service_producer(nextservice);
1987 if (nextservice == NULL) break;
1988 properties = MLT_SERVICE_PROPERTIES(nextservice);
1989 mlt_type = mlt_properties_get(properties, "mlt_type");
1990 resource = mlt_properties_get(properties, "mlt_service");
1993 mlt_service_unlock(service.get_service());
1994 mltCheckLength(&tractor);
1995 m_mltConsumer->set("refresh", 1);
1999 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
2001 if (source == dest) return;
2002 Mlt::Service sourceService(source->get_service());
2003 Mlt::Service destService(dest->get_service());
2005 // move all effects to the correct producer
2007 Mlt::Filter *filter = sourceService.filter(ct);
2009 if (filter->get_int("kdenlive_ix") != 0) {
2010 sourceService.detach(*filter);
2011 destService.attach(*filter);
2013 filter = sourceService.filter(ct);
2017 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2021 Mlt::Service service(m_mltProducer->parent().get_service());
2022 if (service.type() != tractor_type) {
2023 kWarning() << "// TRACTOR PROBLEM";
2026 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2027 Mlt::Tractor tractor(service);
2028 Mlt::Producer trackProducer(tractor.track(info.track));
2029 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2030 int startPos = info.startPos.frames(m_fps);
2031 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2032 int clipLength = trackPlaylist.clip_length(clipIndex);
2034 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2035 if (original == NULL) {
2038 if (!original->is_valid() || original->is_blank()) {
2043 Mlt::Producer clipparent = original->parent();
2044 if (!clipparent.is_valid() || clipparent.is_blank()) {
2050 QString serv = clipparent.get("mlt_service");
2051 QString id = clipparent.get("id");
2052 if (speed <= 0 && speed > -1) speed = 1.0;
2053 //kDebug() << "CLIP SERVICE: " << serv;
2054 if ((serv == "avformat" || serv == "avformat-novalidate") && (speed != 1.0 || strobe > 1)) {
2055 mlt_service_lock(service.get_service());
2056 QString url = QString::fromUtf8(clipparent.get("resource"));
2057 url.append('?' + QString::number(speed));
2058 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2059 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2060 if (!slowprod || slowprod->get_producer() == NULL) {
2061 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2062 if (strobe > 1) slowprod->set("strobe", strobe);
2063 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2064 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2065 slowprod->set("id", producerid.toUtf8().constData());
2066 // copy producer props
2067 double ar = original->parent().get_double("force_aspect_ratio");
2068 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2069 double fps = original->parent().get_double("force_fps");
2070 if (fps != 0.0) slowprod->set("force_fps", fps);
2071 int threads = original->parent().get_int("threads");
2072 if (threads != 0) slowprod->set("threads", threads);
2073 if (original->parent().get("force_progressive"))
2074 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2075 if (original->parent().get("force_tff"))
2076 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2077 int ix = original->parent().get_int("video_index");
2078 if (ix != 0) slowprod->set("video_index", ix);
2079 int colorspace = original->parent().get_int("force_colorspace");
2080 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2081 int full_luma = original->parent().get_int("set.force_full_luma");
2082 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2083 m_slowmotionProducers.insert(url, slowprod);
2085 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2086 trackPlaylist.consolidate_blanks(0);
2088 // Check that the blank space is long enough for our new duration
2089 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2090 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2092 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2093 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2094 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2095 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2097 // move all effects to the correct producer
2098 mltPasteEffects(clip, cut);
2099 trackPlaylist.insert_at(startPos, cut, 1);
2102 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2103 newLength = trackPlaylist.clip_length(clipIndex);
2104 mlt_service_unlock(service.get_service());
2105 } else if (speed == 1.0 && strobe < 2) {
2106 mlt_service_lock(service.get_service());
2108 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2109 trackPlaylist.consolidate_blanks(0);
2111 // Check that the blank space is long enough for our new duration
2112 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2113 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2116 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2117 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2118 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2119 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2120 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2122 // move all effects to the correct producer
2123 mltPasteEffects(clip, cut);
2125 trackPlaylist.insert_at(startPos, cut, 1);
2128 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2129 newLength = trackPlaylist.clip_length(clipIndex);
2130 mlt_service_unlock(service.get_service());
2132 } else if (serv == "framebuffer") {
2133 mlt_service_lock(service.get_service());
2134 QString url = QString::fromUtf8(clipparent.get("resource"));
2135 url = url.section('?', 0, 0);
2136 url.append('?' + QString::number(speed));
2137 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2138 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2139 if (!slowprod || slowprod->get_producer() == NULL) {
2140 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2141 slowprod->set("strobe", strobe);
2142 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2143 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2144 slowprod->set("id", producerid.toUtf8().constData());
2145 // copy producer props
2146 double ar = original->parent().get_double("force_aspect_ratio");
2147 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2148 double fps = original->parent().get_double("force_fps");
2149 if (fps != 0.0) slowprod->set("force_fps", fps);
2150 if (original->parent().get("force_progressive"))
2151 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2152 if (original->parent().get("force_tff"))
2153 slowprod->set("force_tff", original->parent().get_int("force_tff"));
2154 int threads = original->parent().get_int("threads");
2155 if (threads != 0) slowprod->set("threads", threads);
2156 int ix = original->parent().get_int("video_index");
2157 if (ix != 0) slowprod->set("video_index", ix);
2158 int colorspace = original->parent().get_int("force_colorspace");
2159 if (colorspace != 0) slowprod->set("force_colorspace", colorspace);
2160 int full_luma = original->parent().get_int("set.force_full_luma");
2161 if (full_luma != 0) slowprod->set("set.force_full_luma", full_luma);
2162 m_slowmotionProducers.insert(url, slowprod);
2164 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2165 trackPlaylist.consolidate_blanks(0);
2167 GenTime duration = speedIndependantInfo.cropDuration / speed;
2168 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2170 // Check that the blank space is long enough for our new duration
2171 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2172 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2175 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2176 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2177 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2178 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2180 // move all effects to the correct producer
2181 mltPasteEffects(clip, cut);
2183 trackPlaylist.insert_at(startPos, cut, 1);
2186 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2187 newLength = trackPlaylist.clip_length(clipIndex);
2189 mlt_service_unlock(service.get_service());
2192 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2193 m_isBlocked = false;
2197 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2199 Mlt::Service service(m_mltProducer->parent().get_service());
2200 bool success = false;
2201 Mlt::Tractor tractor(service);
2202 Mlt::Producer trackProducer(tractor.track(track));
2203 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2204 Mlt::Service clipService(trackPlaylist.get_service());
2207 mlt_service_lock(service.get_service());
2209 Mlt::Filter *filter = clipService.filter(ct);
2211 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2212 if (clipService.detach(*filter) == 0) success = true;
2213 } else if (updateIndex) {
2214 // Adjust the other effects index
2215 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2218 filter = clipService.filter(ct);
2220 m_isBlocked = false;
2221 mlt_service_unlock(service.get_service());
2226 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2228 if (position < GenTime()) {
2229 // Remove track effect
2230 return mltRemoveTrackEffect(track, index, updateIndex);
2232 Mlt::Service service(m_mltProducer->parent().get_service());
2233 bool success = false;
2234 Mlt::Tractor tractor(service);
2235 Mlt::Producer trackProducer(tractor.track(track));
2236 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2238 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2239 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2241 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2245 Mlt::Service clipService(clip->get_service());
2246 int duration = clip->get_playtime();
2248 // Check if clip is visible in monitor
2249 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2250 if (diff < 0 || diff > duration) doRefresh = false;
2254 // if (tag.startsWith("ladspa")) tag = "ladspa";
2256 mlt_service_lock(service.get_service());
2258 Mlt::Filter *filter = clipService.filter(ct);
2260 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2261 if (clipService.detach(*filter) == 0) success = true;
2262 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2263 } else if (updateIndex) {
2264 // Adjust the other effects index
2265 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2268 filter = clipService.filter(ct);
2270 m_isBlocked = false;
2271 mlt_service_unlock(service.get_service());
2272 if (doRefresh) refresh();
2276 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2278 Mlt::Service service(m_mltProducer->parent().get_service());
2279 Mlt::Tractor tractor(service);
2280 Mlt::Producer trackProducer(tractor.track(track));
2281 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2282 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2283 return mltAddEffect(trackService, params, 15000, true);
2287 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2290 Mlt::Service service(m_mltProducer->parent().get_service());
2292 Mlt::Tractor tractor(service);
2293 Mlt::Producer trackProducer(tractor.track(track));
2294 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2296 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2297 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2302 Mlt::Service clipService(clip->get_service());
2303 int duration = clip->get_playtime();
2305 // Check if clip is visible in monitor
2306 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2307 if (diff < 0 || diff > duration) doRefresh = false;
2310 return mltAddEffect(clipService, params, duration, doRefresh);
2313 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2315 bool updateIndex = false;
2316 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2317 const QString region = params.paramValue("region");
2320 mlt_service_lock(service.get_service());
2322 Mlt::Filter *filter = service.filter(ct);
2324 if (filter->get_int("kdenlive_ix") == filter_ix) {
2325 // A filter at that position already existed, so we will increase all indexes later
2330 filter = service.filter(ct);
2333 if (params.paramValue("id") == "speed") {
2334 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2336 filter = service.filter(ct);
2338 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2339 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2342 filter = service.filter(ct);
2344 m_isBlocked = false;
2345 mlt_service_unlock(service.get_service());
2346 if (doRefresh) refresh();
2351 // temporarily remove all effects after insert point
2352 QList <Mlt::Filter *> filtersList;
2354 filter = service.filter(ct);
2356 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2357 filtersList.append(filter);
2358 service.detach(*filter);
2360 filter = service.filter(ct);
2364 QString tag = params.paramValue("tag");
2365 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2366 if (tag.startsWith("ladspa")) tag = "ladspa";
2367 char *filterTag = qstrdup(tag.toUtf8().constData());
2368 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2369 QHash<QString, QString>::Iterator it;
2370 QString kfr = params.paramValue("keyframes");
2372 if (!kfr.isEmpty()) {
2373 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2374 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2375 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2376 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2377 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2378 //double max = params.paramValue("max").toDouble();
2379 double min = params.paramValue("min").toDouble();
2380 double factor = params.paramValue("factor", "1").toDouble();
2381 params.removeParam("starttag");
2382 params.removeParam("endtag");
2383 params.removeParam("keyframes");
2384 params.removeParam("min");
2385 params.removeParam("max");
2386 params.removeParam("factor");
2388 // Special case, only one keyframe, means we want a constant value
2389 if (keyFrames.count() == 1) {
2390 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2391 if (filter && filter->is_valid()) {
2392 filter->set("kdenlive_id", filterId);
2393 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2394 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2395 for (int j = 0; j < params.count(); j++) {
2396 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2398 filter->set("in", x1);
2399 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2400 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2401 service.attach(*filter);
2403 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2404 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2405 if (filter && filter->is_valid()) {
2406 filter->set("kdenlive_id", filterId);
2407 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2408 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2409 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2410 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2411 if (x2 == -1) x2 = duration;
2413 for (int j = 0; j < params.count(); j++) {
2414 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2417 filter->set("in", x1);
2418 filter->set("out", x2);
2419 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2420 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2421 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2422 service.attach(*filter);
2429 Mlt::Filter *filter;
2431 if (!region.isEmpty()) {
2432 filter = new Mlt::Filter(*m_mltProfile, "region");
2433 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2434 if (filter && filter->is_valid()) {
2435 filter->set("kdenlive_id", filterId);
2436 if (!region.isEmpty()) {
2437 filter->set("resource", region.toUtf8().constData());
2438 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2439 filter->set("filter0", filterTag);
2440 prefix = "filter0.";
2441 params.removeParam("id");
2442 params.removeParam("region");
2443 params.removeParam("kdenlive_ix");
2446 kDebug() << "filter is NULL";
2447 m_isBlocked = false;
2448 mlt_service_unlock(service.get_service());
2451 params.removeParam("kdenlive_id");
2453 for (int j = 0; j < params.count(); j++) {
2454 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2458 QString effectArgs = params.paramValue("id").section('_', 1);
2460 params.removeParam("id");
2461 params.removeParam("kdenlive_ix");
2462 params.removeParam("tag");
2463 params.removeParam("disable");
2464 params.removeParam("region");
2466 for (int j = 0; j < params.count(); j++) {
2467 effectArgs.append(' ' + params.at(j).value());
2469 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2470 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2473 if (params.paramValue("id") == "pan_zoom") {
2474 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2477 // attach filter to the clip
2478 service.attach(*filter);
2483 // re-add following filters
2484 for (int i = 0; i < filtersList.count(); i++) {
2485 Mlt::Filter *filter = filtersList.at(i);
2487 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2488 service.attach(*filter);
2490 m_isBlocked = false;
2491 mlt_service_unlock(service.get_service());
2492 if (doRefresh) refresh();
2496 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2498 Mlt::Service service(m_mltProducer->parent().get_service());
2499 Mlt::Tractor tractor(service);
2500 Mlt::Producer trackProducer(tractor.track(track));
2501 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2502 Mlt::Service clipService(trackPlaylist.get_service());
2505 QString index = params.paramValue("kdenlive_ix");
2506 QString tag = params.paramValue("tag");
2508 Mlt::Filter *filter = clipService.filter(ct);
2510 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2514 filter = clipService.filter(ct);
2518 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2519 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2521 bool success = false;//mltAddTrackEffect(track, params);
2522 m_isBlocked = false;
2526 QString ser = filter->get("mlt_service");
2527 if (ser == "region") prefix = "filter0.";
2528 mlt_service_lock(service.get_service());
2529 for (int j = 0; j < params.count(); j++) {
2530 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2532 mlt_service_unlock(service.get_service());
2534 m_isBlocked = false;
2540 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2542 QString index = params.paramValue("kdenlive_ix");
2543 QString tag = params.paramValue("tag");
2545 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2546 // This is a keyframe effect, to edit it, we remove it and re-add it.
2547 bool success = mltRemoveEffect(track, position, index, false);
2548 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2549 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2550 else success = mltAddEffect(track, position, params);
2551 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2554 if (position < GenTime()) {
2555 return mltEditTrackEffect(track, params);
2558 Mlt::Service service(m_mltProducer->parent().get_service());
2559 Mlt::Tractor tractor(service);
2560 Mlt::Producer trackProducer(tractor.track(track));
2561 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2563 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2564 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2566 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2570 Mlt::Service clipService(clip->get_service());
2571 int duration = clip->get_playtime();
2572 bool doRefresh = true;
2573 // Check if clip is visible in monitor
2574 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2575 if (diff < 0 || diff > duration) doRefresh = false;
2579 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2580 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2582 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2584 filter = clipService.filter(ct);
2586 kDebug() << "++++++++++++++++++++++++++";
2588 filter = clipService.filter(ct); */
2590 Mlt::Filter *filter = clipService.filter(ct);
2592 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2596 filter = clipService.filter(ct);
2600 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2601 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2603 bool success = mltAddEffect(track, position, params);
2604 m_isBlocked = false;
2608 QString ser = filter->get("mlt_service");
2609 if (ser == "region") prefix = "filter0.";
2610 mlt_service_lock(service.get_service());
2611 for (int j = 0; j < params.count(); j++) {
2612 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2614 mlt_service_unlock(service.get_service());
2616 m_isBlocked = false;
2617 if (doRefresh) refresh();
2621 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2623 Mlt::Service service(m_mltProducer->parent().get_service());
2624 Mlt::Tractor tractor(service);
2625 Mlt::Producer trackProducer(tractor.track(track));
2626 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2628 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2629 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2631 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2635 Mlt::Service clipService(clip->get_service());
2636 int duration = clip->get_playtime();
2637 bool doRefresh = true;
2638 // Check if clip is visible in monitor
2639 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2640 if (diff < 0 || diff > duration) doRefresh = false;
2645 Mlt::Filter *filter = clipService.filter(ct);
2647 int pos = filter->get_int("kdenlive_ix");
2648 if (pos == oldPos) {
2649 filter->set("kdenlive_ix", newPos);
2651 filter = clipService.filter(ct);
2654 m_isBlocked = false;
2655 if (doRefresh) refresh();
2658 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2660 if (position < GenTime()) {
2661 mltMoveTrackEffect(track, oldPos, newPos);
2664 Mlt::Service service(m_mltProducer->parent().get_service());
2665 Mlt::Tractor tractor(service);
2666 Mlt::Producer trackProducer(tractor.track(track));
2667 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2669 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2670 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2672 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2676 Mlt::Service clipService(clip->get_service());
2677 int duration = clip->get_playtime();
2678 bool doRefresh = true;
2679 // Check if clip is visible in monitor
2680 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2681 if (diff < 0 || diff > duration) doRefresh = false;
2686 QList <Mlt::Filter *> filtersList;
2687 Mlt::Filter *filter = clipService.filter(ct);
2689 if (newPos > oldPos) {
2691 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2692 filter->set("kdenlive_ix", newPos);
2693 filtersList.append(filter);
2694 clipService.detach(*filter);
2695 filter = clipService.filter(ct);
2696 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2697 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2699 filter = clipService.filter(ct);
2703 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2704 filtersList.append(filter);
2705 clipService.detach(*filter);
2707 filter = clipService.filter(ct);
2711 if (filter->get_int("kdenlive_ix") == oldPos) {
2712 filter->set("kdenlive_ix", newPos);
2713 filtersList.append(filter);
2714 clipService.detach(*filter);
2716 filter = clipService.filter(ct);
2720 filter = clipService.filter(ct);
2722 int pos = filter->get_int("kdenlive_ix");
2723 if (pos >= newPos) {
2724 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2725 filtersList.append(filter);
2726 clipService.detach(*filter);
2728 filter = clipService.filter(ct);
2732 for (int i = 0; i < filtersList.count(); i++) {
2733 clipService.attach(*(filtersList.at(i)));
2736 m_isBlocked = false;
2737 if (doRefresh) refresh();
2740 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2742 Mlt::Service service(m_mltProducer->parent().get_service());
2743 Mlt::Tractor tractor(service);
2744 Mlt::Producer trackProducer(tractor.track(track));
2745 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2747 Mlt::Service clipService(trackPlaylist.get_service());
2751 QList <Mlt::Filter *> filtersList;
2752 Mlt::Filter *filter = clipService.filter(ct);
2754 if (newPos > oldPos) {
2756 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2757 filter->set("kdenlive_ix", newPos);
2758 filtersList.append(filter);
2759 clipService.detach(*filter);
2760 filter = clipService.filter(ct);
2761 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2762 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2764 filter = clipService.filter(ct);
2768 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2769 filtersList.append(filter);
2770 clipService.detach(*filter);
2772 filter = clipService.filter(ct);
2776 if (filter->get_int("kdenlive_ix") == oldPos) {
2777 filter->set("kdenlive_ix", newPos);
2778 filtersList.append(filter);
2779 clipService.detach(*filter);
2781 filter = clipService.filter(ct);
2785 filter = clipService.filter(ct);
2787 int pos = filter->get_int("kdenlive_ix");
2788 if (pos >= newPos) {
2789 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2790 filtersList.append(filter);
2791 clipService.detach(*filter);
2793 filter = clipService.filter(ct);
2797 for (int i = 0; i < filtersList.count(); i++) {
2798 clipService.attach(*(filtersList.at(i)));
2800 m_isBlocked = false;
2804 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2807 Mlt::Service service(m_mltProducer->parent().get_service());
2808 Mlt::Tractor tractor(service);
2809 Mlt::Producer trackProducer(tractor.track(info.track));
2810 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2812 /* // Display playlist info
2813 kDebug()<<"//////////// BEFORE RESIZE";
2814 for (int i = 0; i < trackPlaylist.count(); i++) {
2815 int blankStart = trackPlaylist.clip_start(i);
2816 int blankDuration = trackPlaylist.clip_length(i) - 1;
2818 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2819 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2822 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2823 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2824 m_isBlocked = false;
2827 mlt_service_lock(service.get_service());
2828 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2829 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2830 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2832 int previousStart = clip->get_in();
2833 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2834 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2836 int currentOut = newDuration + previousStart;
2837 if (currentOut > clip->get_length()) {
2838 clip->parent().set("length", currentOut + 1);
2839 clip->parent().set("out", currentOut);
2840 clip->set("length", currentOut + 1);
2843 /*if (newDuration > clip->get_out()) {
2844 clip->parent().set_in_and_out(0, newDuration + 1);
2845 clip->set_in_and_out(0, newDuration + 1);
2848 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2849 trackPlaylist.consolidate_blanks(0);
2850 // skip to next clip
2852 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2854 // clip was made longer, trim next blank if there is one.
2855 if (clipIndex < trackPlaylist.count()) {
2856 // If this is not the last clip in playlist
2857 if (trackPlaylist.is_blank(clipIndex)) {
2858 int blankStart = trackPlaylist.clip_start(clipIndex);
2859 int blankDuration = trackPlaylist.clip_length(clipIndex);
2860 if (diff > blankDuration) {
2861 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2863 if (diff - blankDuration == 0) {
2864 trackPlaylist.remove(clipIndex);
2865 } else trackPlaylist.remove_region(blankStart, diff);
2867 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2870 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2871 trackPlaylist.consolidate_blanks(0);
2872 mlt_service_unlock(service.get_service());
2874 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2875 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2876 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2877 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2878 ItemInfo transpinfo;
2879 transpinfo.startPos = info.startPos;
2880 transpinfo.endPos = info.startPos + clipDuration;
2881 transpinfo.track = info.track;
2882 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2884 m_isBlocked = false;
2885 m_mltConsumer->set("refresh", 1);
2889 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2891 Mlt::Service service(m_mltProducer->parent().get_service());
2892 Mlt::Tractor tractor(service);
2893 Mlt::Producer trackProducer(tractor.track(track));
2896 if (blind) trackProducer.set("hide", 3);
2897 else trackProducer.set("hide", 2);
2899 trackProducer.set("hide", 1);
2901 trackProducer.set("hide", 0);
2903 tractor.multitrack()->refresh();
2909 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2911 Mlt::Service service(m_mltProducer->parent().get_service());
2912 int frameOffset = (int) diff.frames(m_fps);
2913 Mlt::Tractor tractor(service);
2914 Mlt::Producer trackProducer(tractor.track(info.track));
2915 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2916 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2917 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2920 mlt_service_lock(service.get_service());
2921 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2922 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2924 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2925 mlt_service_unlock(service.get_service());
2928 int previousStart = clip->get_in();
2929 int previousOut = clip->get_out();
2932 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2933 m_isBlocked = false;
2934 mlt_service_unlock(service.get_service());
2935 m_mltConsumer->set("refresh", 1);
2939 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2941 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2942 Mlt::Service service(m_mltProducer->parent().get_service());
2943 int moveFrame = (int) diff.frames(m_fps);
2944 Mlt::Tractor tractor(service);
2945 Mlt::Producer trackProducer(tractor.track(info.track));
2946 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2947 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2948 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2951 mlt_service_lock(service.get_service());
2952 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2953 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2954 if (clip == NULL || clip->is_blank()) {
2955 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2956 mlt_service_unlock(service.get_service());
2959 int previousStart = clip->get_in();
2960 int previousOut = clip->get_out();
2963 previousStart += moveFrame;
2965 int length = previousOut + 1;
2966 if (length > clip->get_length()) {
2967 clip->parent().set("length", length + 1);
2968 clip->parent().set("out", length);
2969 clip->set("length", length + 1);
2973 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
2974 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
2975 if (moveFrame > 0) {
2976 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2978 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2979 int blankIndex = clipIndex - 1;
2980 int blankLength = trackPlaylist.clip_length(blankIndex);
2981 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2982 if (! trackPlaylist.is_blank(blankIndex)) {
2983 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2985 if (blankLength + moveFrame == 0)
2986 trackPlaylist.remove(blankIndex);
2988 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2990 trackPlaylist.consolidate_blanks(0);
2991 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2992 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2993 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2994 ItemInfo transpinfo;
2995 transpinfo.startPos = info.startPos + diff;
2996 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2997 transpinfo.track = info.track;
2998 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
3000 m_isBlocked = false;
3001 //m_mltConsumer->set("refresh", 1);
3002 mlt_service_unlock(service.get_service());
3003 m_mltConsumer->set("refresh", 1);
3007 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3009 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3013 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3015 if (prod == NULL || !prod->is_valid()) {
3016 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3019 kDebug() << "NEW PROD ID: " << prod->get("id");
3021 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3022 Mlt::Service service(m_mltProducer->parent().get_service());
3023 if (service.type() != tractor_type) {
3024 kWarning() << "// TRACTOR PROBLEM";
3027 mlt_service_lock(service.get_service());
3028 Mlt::Tractor tractor(service);
3029 Mlt::Producer trackProducer(tractor.track(track));
3030 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3031 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3032 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3033 if (clipProducer == NULL || clipProducer->is_blank()) {
3034 kDebug() << "// ERROR UPDATING CLIP PROD";
3035 delete clipProducer;
3036 mlt_service_unlock(service.get_service());
3040 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3041 if (!clip || !clip->is_valid()) {
3042 if (clip) delete clip;
3043 delete clipProducer;
3044 mlt_service_unlock(service.get_service());
3048 // move all effects to the correct producer
3049 mltPasteEffects(clipProducer, clip);
3050 trackPlaylist.insert_at(pos, clip, 1);
3052 delete clipProducer;
3053 mlt_service_unlock(service.get_service());
3058 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3062 Mlt::Service service(m_mltProducer->parent().get_service());
3063 if (service.type() != tractor_type) {
3064 kWarning() << "// TRACTOR PROBLEM";
3068 Mlt::Tractor tractor(service);
3069 mlt_service_lock(service.get_service());
3070 Mlt::Producer trackProducer(tractor.track(startTrack));
3071 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3072 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3073 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3074 bool checkLength = false;
3075 if (endTrack == startTrack) {
3076 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3077 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3078 // error, destination is not empty
3080 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3081 delete clipProducer;
3083 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3084 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3085 mlt_service_unlock(service.get_service());
3089 trackPlaylist.consolidate_blanks(0);
3091 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3092 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3093 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3095 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3096 trackPlaylist.consolidate_blanks(1);
3097 delete clipProducer;
3098 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3099 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3101 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3103 //mlt_service_unlock(service.get_service());
3105 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3106 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3107 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3108 // error, destination is not empty
3109 mlt_service_unlock(service.get_service());
3113 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3114 if (!clipProducer || clipProducer->is_blank()) {
3115 // error, destination is not empty
3116 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3117 if (clipProducer) delete clipProducer;
3118 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3119 mlt_service_unlock(service.get_service());
3123 trackPlaylist.consolidate_blanks(0);
3124 destTrackPlaylist.consolidate_blanks(1);
3125 Mlt::Producer *clip;
3126 // check if we are moving a slowmotion producer
3127 QString serv = clipProducer->parent().get("mlt_service");
3128 QString currentid = clipProducer->parent().get("id");
3129 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3130 clip = clipProducer;
3133 // Special case: prod is null when using placeholder clips.
3134 // in that case, use the producer existing in playlist. Note that
3135 // it will bypass the one producer per track logic and might cause
3136 // Sound cracks if clip is moved so that it overlaps another copy of itself
3137 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3138 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3141 // move all effects to the correct producer
3142 mltPasteEffects(clipProducer, clip);
3145 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3146 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3147 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3150 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3152 if (clip == clipProducer) {
3157 delete clipProducer;
3159 destTrackPlaylist.consolidate_blanks(0);
3160 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3161 kDebug() << "//////// moving clip transparency";
3162 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3164 if (clipIndex > trackPlaylist.count()) checkLength = true;
3165 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3168 mlt_service_unlock(service.get_service());
3169 if (checkLength) mltCheckLength(&tractor);
3172 //m_mltConsumer->set("refresh", 1);
3177 QList <int> Render::checkTrackSequence(int track)
3180 Mlt::Service service(m_mltProducer->parent().get_service());
3181 if (service.type() != tractor_type) {
3182 kWarning() << "// TRACTOR PROBLEM";
3185 Mlt::Tractor tractor(service);
3186 mlt_service_lock(service.get_service());
3187 Mlt::Producer trackProducer(tractor.track(track));
3188 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3189 int clipNb = trackPlaylist.count();
3190 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3191 for (int i = 0; i < clipNb; i++) {
3192 Mlt::Producer *c = trackPlaylist.get_clip(i);
3193 int pos = trackPlaylist.clip_start(i);
3194 if (!list.contains(pos)) list.append(pos);
3195 pos += c->get_playtime();
3196 if (!list.contains(pos)) list.append(pos);
3202 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3204 int new_in = (int)newIn.frames(m_fps);
3205 int new_out = (int)newOut.frames(m_fps) - 1;
3206 if (new_in >= new_out) return false;
3207 int old_in = (int)oldIn.frames(m_fps);
3208 int old_out = (int)oldOut.frames(m_fps) - 1;
3210 Mlt::Service service(m_mltProducer->parent().get_service());
3211 Mlt::Tractor tractor(service);
3212 Mlt::Field *field = tractor.field();
3214 bool doRefresh = true;
3215 // Check if clip is visible in monitor
3216 int diff = old_out - m_mltProducer->position();
3217 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3219 diff = new_out - m_mltProducer->position();
3220 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3224 mlt_service_lock(service.get_service());
3226 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3227 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3228 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3229 QString resource = mlt_properties_get(properties, "mlt_service");
3230 int old_pos = (int)(old_in + old_out) / 2;
3233 while (mlt_type == "transition") {
3234 Mlt::Transition transition((mlt_transition) nextservice);
3235 int currentTrack = transition.get_b_track();
3236 int currentIn = (int) transition.get_in();
3237 int currentOut = (int) transition.get_out();
3239 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3241 if (newTrack - startTrack != 0) {
3242 Mlt::Properties trans_props(transition.get_properties());
3243 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3244 Mlt::Properties new_trans_props(new_transition.get_properties());
3245 new_trans_props.inherit(trans_props);
3246 new_transition.set_in_and_out(new_in, new_out);
3247 field->disconnect_service(transition);
3248 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3249 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3250 } else transition.set_in_and_out(new_in, new_out);
3253 nextservice = mlt_service_producer(nextservice);
3254 if (nextservice == NULL) break;
3255 properties = MLT_SERVICE_PROPERTIES(nextservice);
3256 mlt_type = mlt_properties_get(properties, "mlt_type");
3257 resource = mlt_properties_get(properties, "mlt_service");
3259 mlt_service_unlock(service.get_service());
3261 if (doRefresh) refresh();
3262 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3267 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3269 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3270 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3271 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3272 QString resource = mlt_properties_get(properties, "mlt_service");
3273 QList <Mlt::Transition *> trList;
3275 while (mlt_type == "transition") {
3276 Mlt::Transition transition((mlt_transition) nextservice);
3277 int aTrack = transition.get_a_track();
3278 int bTrack = transition.get_b_track();
3279 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3280 Mlt::Properties trans_props(transition.get_properties());
3281 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3282 Mlt::Properties new_trans_props(cp->get_properties());
3283 new_trans_props.inherit(trans_props);
3285 field->disconnect_service(transition);
3287 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3289 nextservice = mlt_service_producer(nextservice);
3290 if (nextservice == NULL) break;
3291 properties = MLT_SERVICE_PROPERTIES(nextservice);
3292 mlt_type = mlt_properties_get(properties, "mlt_type");
3293 resource = mlt_properties_get(properties, "mlt_service");
3296 field->plant_transition(tr, a_track, b_track);
3298 // re-add upper transitions
3299 for (int i = 0; i < trList.count(); i++) {
3300 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3301 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3305 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3307 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3309 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3310 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3313 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3316 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3318 mlt_service serv = m_mltProducer->parent().get_service();
3319 mlt_service_lock(serv);
3322 mlt_service nextservice = mlt_service_get_producer(serv);
3323 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3324 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3325 QString resource = mlt_properties_get(properties, "mlt_service");
3326 int in_pos = (int) in.frames(m_fps);
3327 int out_pos = (int) out.frames(m_fps) - 1;
3329 while (mlt_type == "transition") {
3330 mlt_transition tr = (mlt_transition) nextservice;
3331 int currentTrack = mlt_transition_get_b_track(tr);
3332 int currentBTrack = mlt_transition_get_a_track(tr);
3333 int currentIn = (int) mlt_transition_get_in(tr);
3334 int currentOut = (int) mlt_transition_get_out(tr);
3336 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3338 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3339 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3340 QMap<QString, QString>::Iterator it;
3342 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3344 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3345 if (currentId != xml.attribute("id")) {
3346 // The transition ID is not the same, so reset all properties
3347 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3348 // Cleanup previous properties
3349 QStringList permanentProps;
3350 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3351 permanentProps << "out" << "a_track" << "b_track";
3352 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3353 QString propName = mlt_properties_get_name(transproperties, i);
3354 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3355 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3360 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3361 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3363 if (currentBTrack != a_track) {
3364 mlt_properties_set_int(transproperties, "a_track", a_track);
3366 for (it = map.begin(); it != map.end(); ++it) {
3368 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3369 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3370 //filter->set("kdenlive_id", id);
3374 nextservice = mlt_service_producer(nextservice);
3375 if (nextservice == NULL) break;
3376 properties = MLT_SERVICE_PROPERTIES(nextservice);
3377 mlt_type = mlt_properties_get(properties, "mlt_type");
3378 resource = mlt_properties_get(properties, "mlt_service");
3380 mlt_service_unlock(serv);
3383 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3386 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3388 mlt_service serv = m_mltProducer->parent().get_service();
3390 mlt_service_lock(serv);
3392 Mlt::Service service(serv);
3393 Mlt::Tractor tractor(service);
3394 Mlt::Field *field = tractor.field();
3396 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3398 mlt_service nextservice = mlt_service_get_producer(serv);
3399 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3400 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3401 QString resource = mlt_properties_get(properties, "mlt_service");
3403 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3404 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3406 while (mlt_type == "transition") {
3407 mlt_transition tr = (mlt_transition) nextservice;
3408 int currentTrack = mlt_transition_get_b_track(tr);
3409 int currentIn = (int) mlt_transition_get_in(tr);
3410 int currentOut = (int) mlt_transition_get_out(tr);
3411 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3413 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3414 mlt_field_disconnect_service(field->get_field(), nextservice);
3417 nextservice = mlt_service_producer(nextservice);
3418 if (nextservice == NULL) break;
3419 properties = MLT_SERVICE_PROPERTIES(nextservice);
3420 mlt_type = mlt_properties_get(properties, "mlt_type");
3421 resource = mlt_properties_get(properties, "mlt_service");
3423 mlt_service_unlock(serv);
3426 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3429 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3431 QDomNodeList attribs = xml.elementsByTagName("parameter");
3432 QMap<QString, QString> map;
3433 for (int i = 0; i < attribs.count(); i++) {
3434 QDomElement e = attribs.item(i).toElement();
3435 QString name = e.attribute("name");
3436 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3437 map[name] = e.attribute("default");
3438 if (!e.attribute("value").isEmpty()) {
3439 map[name] = e.attribute("value");
3441 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3442 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3443 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3446 if (e.attribute("namedesc").contains(';')) {
3447 QString format = e.attribute("format");
3448 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3449 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3451 QTextStream txtNeu(&neu);
3452 if (values.size() > 0)
3453 txtNeu << (int)values[0].toDouble();
3455 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3456 txtNeu << separators[i];
3457 txtNeu << (int)(values[i+1].toDouble());
3459 if (i < separators.size())
3460 txtNeu << separators[i];
3461 map[e.attribute("name")] = neu;
3468 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3470 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3471 Mlt::Service service(m_mltProducer->parent().get_service());
3472 Mlt::Tractor tractor(service);
3473 Mlt::Field *field = tractor.field();
3475 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3476 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3477 transition->set("transparency", id);
3478 transition->set("fill", 1);
3479 transition->set("internal_added", 237);
3480 field->plant_transition(*transition, transitiontrack, info.track);
3484 void Render::mltDeleteTransparency(int pos, int track, int id)
3486 Mlt::Service service(m_mltProducer->parent().get_service());
3487 Mlt::Tractor tractor(service);
3488 Mlt::Field *field = tractor.field();
3490 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3491 mlt_service serv = m_mltProducer->parent().get_service();
3493 mlt_service nextservice = mlt_service_get_producer(serv);
3494 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3495 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3496 QString resource = mlt_properties_get(properties, "mlt_service");
3498 while (mlt_type == "transition") {
3499 mlt_transition tr = (mlt_transition) nextservice;
3500 int currentTrack = mlt_transition_get_b_track(tr);
3501 int currentIn = (int) mlt_transition_get_in(tr);
3502 int currentOut = (int) mlt_transition_get_out(tr);
3503 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3504 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3506 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3507 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3508 mlt_field_disconnect_service(field->get_field(), nextservice);
3511 nextservice = mlt_service_producer(nextservice);
3512 if (nextservice == NULL) break;
3513 properties = MLT_SERVICE_PROPERTIES(nextservice);
3514 mlt_type = mlt_properties_get(properties, "mlt_type");
3515 resource = mlt_properties_get(properties, "mlt_service");
3517 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3520 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3522 Mlt::Service service(m_mltProducer->parent().get_service());
3523 Mlt::Tractor tractor(service);
3525 mlt_service_lock(service.get_service());
3526 m_mltConsumer->set("refresh", 0);
3529 mlt_service serv = m_mltProducer->parent().get_service();
3530 mlt_service nextservice = mlt_service_get_producer(serv);
3531 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3532 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3533 QString resource = mlt_properties_get(properties, "mlt_service");
3534 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3535 while (mlt_type == "transition") {
3536 mlt_transition tr = (mlt_transition) nextservice;
3537 int currentTrack = mlt_transition_get_b_track(tr);
3538 int currentIn = (int) mlt_transition_get_in(tr);
3539 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3540 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3541 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3542 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3543 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3544 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3547 nextservice = mlt_service_producer(nextservice);
3548 if (nextservice == NULL) break;
3549 properties = MLT_SERVICE_PROPERTIES(nextservice);
3550 mlt_type = mlt_properties_get(properties, "mlt_type");
3551 resource = mlt_properties_get(properties, "mlt_service");
3553 mlt_service_unlock(service.get_service());
3555 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3559 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3561 Mlt::Service service(m_mltProducer->parent().get_service());
3562 Mlt::Tractor tractor(service);
3564 mlt_service_lock(service.get_service());
3565 m_mltConsumer->set("refresh", 0);
3568 mlt_service serv = m_mltProducer->parent().get_service();
3569 mlt_service nextservice = mlt_service_get_producer(serv);
3570 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3571 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3572 QString resource = mlt_properties_get(properties, "mlt_service");
3574 while (mlt_type == "transition") {
3575 mlt_transition tr = (mlt_transition) nextservice;
3576 int currentTrack = mlt_transition_get_b_track(tr);
3577 int currentaTrack = mlt_transition_get_a_track(tr);
3578 int currentIn = (int) mlt_transition_get_in(tr);
3579 int currentOut = (int) mlt_transition_get_out(tr);
3580 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3581 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3582 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3583 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3584 kDebug() << "//////MOVING";
3585 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3586 if (endTrack != startTrack) {
3587 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3588 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3589 mlt_properties_set_int(properties, "b_track", endTrack);
3593 nextservice = mlt_service_producer(nextservice);
3594 if (nextservice == NULL) break;
3595 properties = MLT_SERVICE_PROPERTIES(nextservice);
3596 mlt_type = mlt_properties_get(properties, "mlt_type");
3597 resource = mlt_properties_get(properties, "mlt_service");
3600 mlt_service_unlock(service.get_service());
3601 m_mltConsumer->set("refresh", 1);
3605 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3607 if (in >= out) return false;
3608 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3609 Mlt::Service service(m_mltProducer->parent().get_service());
3611 Mlt::Tractor tractor(service);
3612 Mlt::Field *field = tractor.field();
3614 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3615 if (out != GenTime())
3616 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3618 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3619 QMap<QString, QString>::Iterator it;
3621 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3622 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3623 if (xml.hasAttribute("id"))
3624 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3626 for (it = args.begin(); it != args.end(); ++it) {
3628 if (!it.value().isEmpty())
3629 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3630 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3632 // attach transition
3633 mltPlantTransition(field, *transition, a_track, b_track);
3634 // field->plant_transition(*transition, a_track, b_track);
3635 if (do_refresh) refresh();
3639 void Render::mltSavePlaylist()
3641 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3642 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3643 fileConsumer.set("resource", "/tmp/playlist.mlt");
3645 Mlt::Service service(m_mltProducer->get_service());
3647 fileConsumer.connect(service);
3648 fileConsumer.start();
3651 const QList <Mlt::Producer *> Render::producersList()
3653 QList <Mlt::Producer *> prods;
3654 if (m_mltProducer == NULL) return prods;
3655 Mlt::Service service(m_mltProducer->parent().get_service());
3656 if (service.type() != tractor_type) return prods;
3657 Mlt::Tractor tractor(service);
3660 int trackNb = tractor.count();
3661 for (int t = 1; t < trackNb; t++) {
3662 Mlt::Producer *tt = tractor.track(t);
3663 Mlt::Producer trackProducer(tt);
3665 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3666 int clipNb = trackPlaylist.count();
3667 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3668 for (int i = 0; i < clipNb; i++) {
3669 Mlt::Producer *c = trackPlaylist.get_clip(i);
3670 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3672 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3673 ids.append(nprod->get("id"));
3674 prods.append(nprod);
3675 } else delete nprod;
3683 void Render::fillSlowMotionProducers()
3685 if (m_mltProducer == NULL) return;
3686 Mlt::Service service(m_mltProducer->parent().get_service());
3687 if (service.type() != tractor_type) return;
3689 Mlt::Tractor tractor(service);
3691 int trackNb = tractor.count();
3692 for (int t = 1; t < trackNb; t++) {
3693 Mlt::Producer *tt = tractor.track(t);
3694 Mlt::Producer trackProducer(tt);
3696 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3697 int clipNb = trackPlaylist.count();
3698 for (int i = 0; i < clipNb; i++) {
3699 Mlt::Producer *c = trackPlaylist.get_clip(i);
3700 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3702 QString id = nprod->get("id");
3703 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3704 // this is a slowmotion producer, add it to the list
3705 QString url = QString::fromUtf8(nprod->get("resource"));
3706 int strobe = nprod->get_int("strobe");
3707 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3708 if (!m_slowmotionProducers.contains(url)) {
3709 m_slowmotionProducers.insert(url, nprod);
3711 } else delete nprod;
3718 void Render::mltInsertTrack(int ix, bool videoTrack)
3723 Mlt::Service service(m_mltProducer->parent().get_service());
3724 mlt_service_lock(service.get_service());
3725 if (service.type() != tractor_type) {
3726 kWarning() << "// TRACTOR PROBLEM";
3730 Mlt::Tractor tractor(service);
3732 Mlt::Playlist playlist;
3733 int ct = tractor.count();
3735 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3741 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3742 tractor.set_track(playlist, pos);
3743 Mlt::Producer newProd(tractor.track(pos));
3744 if (!videoTrack) newProd.set("hide", 1);
3746 for (; pos <= ct; pos++) {
3747 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3748 tractor.set_track(*prodToMove, pos);
3749 prodToMove = prodToMove2;
3752 tractor.set_track(playlist, ix);
3753 Mlt::Producer newProd(tractor.track(ix));
3754 if (!videoTrack) newProd.set("hide", 1);
3758 mlt_service serv = m_mltProducer->parent().get_service();
3759 mlt_service nextservice = mlt_service_get_producer(serv);
3760 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3761 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3762 QString resource = mlt_properties_get(properties, "mlt_service");
3764 while (mlt_type == "transition") {
3765 if (resource != "mix") {
3766 mlt_transition tr = (mlt_transition) nextservice;
3767 int currentTrack = mlt_transition_get_b_track(tr);
3768 int currentaTrack = mlt_transition_get_a_track(tr);
3769 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3771 if (currentTrack >= ix) {
3772 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3773 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3776 nextservice = mlt_service_producer(nextservice);
3777 if (nextservice == NULL) break;
3778 properties = MLT_SERVICE_PROPERTIES(nextservice);
3779 mlt_type = mlt_properties_get(properties, "mlt_type");
3780 resource = mlt_properties_get(properties, "mlt_service");
3783 // Add audio mix transition to last track
3784 Mlt::Field *field = tractor.field();
3785 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3786 transition->set("a_track", 1);
3787 transition->set("b_track", ct);
3788 transition->set("always_active", 1);
3789 transition->set("internal_added", 237);
3790 transition->set("combine", 1);
3791 field->plant_transition(*transition, 1, ct);
3792 //mlt_service_unlock(m_mltConsumer->get_service());
3793 mlt_service_unlock(service.get_service());
3794 //tractor.multitrack()->refresh();
3795 //tractor.refresh();
3797 blockSignals(false);
3801 void Render::mltDeleteTrack(int ix)
3804 doc.setContent(sceneList(), false);
3805 int tracksCount = doc.elementsByTagName("track").count() - 1;
3806 QDomNode track = doc.elementsByTagName("track").at(ix);
3807 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3808 QDomNodeList transitions = doc.elementsByTagName("transition");
3809 for (int i = 0; i < transitions.count(); i++) {
3810 QDomElement e = transitions.at(i).toElement();
3811 QDomNodeList props = e.elementsByTagName("property");
3812 QMap <QString, QString> mappedProps;
3813 for (int j = 0; j < props.count(); j++) {
3814 QDomElement f = props.at(j).toElement();
3815 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3817 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3818 tractor.removeChild(transitions.at(i));
3820 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3821 // Transition needs to be moved
3822 int a_track = mappedProps.value("a_track").toInt();
3823 int b_track = mappedProps.value("b_track").toInt();
3824 if (a_track > 0 && a_track >= ix) a_track --;
3825 if (b_track == ix) {
3826 // transition was on the deleted track, so remove it
3827 tractor.removeChild(transitions.at(i));
3831 if (b_track > 0 && b_track > ix) b_track --;
3832 for (int j = 0; j < props.count(); j++) {
3833 QDomElement f = props.at(j).toElement();
3834 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3835 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3840 tractor.removeChild(track);
3841 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3842 setSceneList(doc.toString(), m_framePosition);
3844 /* if (m_mltProducer != NULL) {
3845 Mlt::Producer parentProd(m_mltProducer->parent());
3846 if (parentProd.get_producer() != NULL) {
3847 Mlt::Service service(parentProd.get_service());
3848 if (service.type() == tractor_type) {
3849 Mlt::Tractor tractor(service);
3850 mltCheckLength(&tractor);
3857 void Render::updatePreviewSettings()
3859 kDebug() << "////// RESTARTING CONSUMER";
3860 if (!m_mltConsumer || !m_mltProducer) return;
3861 if (m_mltProducer->get_playtime() == 0) return;
3862 Mlt::Service service(m_mltProducer->parent().get_service());
3863 if (service.type() != tractor_type) return;
3865 //m_mltConsumer->set("refresh", 0);
3866 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3867 m_mltConsumer->purge();
3868 QString scene = sceneList();
3870 if (m_mltProducer) {
3871 pos = m_mltProducer->position();
3874 setSceneList(scene, pos);
3878 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3880 // Update all frame positions to the new fps value
3881 //WARNING: there are probably some effects or other that hold a frame value
3882 // as parameter and will also need to be updated here!
3884 doc.setContent(scene);
3886 double factor = new_fps / current_fps;
3887 QDomNodeList producers = doc.elementsByTagName("producer");
3888 for (int i = 0; i < producers.count(); i++) {
3889 QDomElement prod = producers.at(i).toElement();
3890 prod.removeAttribute("in");
3891 prod.removeAttribute("out");
3893 QDomNodeList props = prod.childNodes();
3894 for (int j = 0; j < props.count(); j++) {
3895 QDomElement param = props.at(j).toElement();
3896 QString paramName = param.attribute("name");
3897 if (paramName.startsWith("meta.") || paramName == "length") {
3898 prod.removeChild(props.at(j));
3904 QDomNodeList entries = doc.elementsByTagName("entry");
3905 for (int i = 0; i < entries.count(); i++) {
3906 QDomElement entry = entries.at(i).toElement();
3907 int in = entry.attribute("in").toInt();
3908 int out = entry.attribute("out").toInt();
3909 in = factor * in + 0.5;
3910 out = factor * out + 0.5;
3911 entry.setAttribute("in", in);
3912 entry.setAttribute("out", out);
3915 QDomNodeList blanks = doc.elementsByTagName("blank");
3916 for (int i = 0; i < blanks.count(); i++) {
3917 QDomElement blank = blanks.at(i).toElement();
3918 int length = blank.attribute("length").toInt();
3919 length = factor * length + 0.5;
3920 blank.setAttribute("length", QString::number(length));
3923 QDomNodeList filters = doc.elementsByTagName("filter");
3924 for (int i = 0; i < filters.count(); i++) {
3925 QDomElement filter = filters.at(i).toElement();
3926 int in = filter.attribute("in").toInt();
3927 int out = filter.attribute("out").toInt();
3928 in = factor * in + 0.5;
3929 out = factor * out + 0.5;
3930 filter.setAttribute("in", in);
3931 filter.setAttribute("out", out);
3934 QDomNodeList transitions = doc.elementsByTagName("transition");
3935 for (int i = 0; i < transitions.count(); i++) {
3936 QDomElement transition = transitions.at(i).toElement();
3937 int in = transition.attribute("in").toInt();
3938 int out = transition.attribute("out").toInt();
3939 in = factor * in + 0.5;
3940 out = factor * out + 0.5;
3941 transition.setAttribute("in", in);
3942 transition.setAttribute("out", out);
3943 QDomNodeList props = transition.childNodes();
3944 for (int j = 0; j < props.count(); j++) {
3945 QDomElement param = props.at(j).toElement();
3946 QString paramName = param.attribute("name");
3947 if (paramName == "geometry") {
3948 QString geom = param.firstChild().nodeValue();
3949 QStringList keys = geom.split(';');
3950 QStringList newKeys;
3951 for (int k = 0; k < keys.size(); ++k) {
3952 if (keys.at(k).contains('=')) {
3953 int pos = keys.at(k).section('=', 0, 0).toInt();
3954 pos = factor * pos + 0.5;
3955 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3956 } else newKeys.append(keys.at(k));
3958 param.firstChild().setNodeValue(newKeys.join(";"));
3962 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3963 int out = tractor.attribute("out").toInt();
3964 out = factor * out + 0.5;
3965 tractor.setAttribute("out", out);
3966 emit durationChanged(out);
3968 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3969 return doc.toString();
3973 void Render::sendFrameUpdate()
3975 if (m_mltProducer) {
3976 Mlt::Frame * frame = m_mltProducer->get_frame();
3977 emitFrameUpdated(*frame);
3983 #include "renderer.moc"