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"
31 #include <mlt++/Mlt.h>
34 #include <KStandardDirs>
35 #include <KMessageBox>
37 #include <KTemporaryFile>
41 #include <QApplication>
47 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
49 if (level > MLT_LOG_ERROR) return;
51 QApplication::postEvent(qApp->activeWindow() , new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
55 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
57 // detect if the producer has finished playing. Is there a better way to do it?
58 if (self->m_isBlocked) return;
59 Mlt::Frame frame(frame_ptr);
61 self->showFrame(frame);
63 if (frame.get_double("_speed") == 0.0) {
64 self->emitConsumerStopped();
66 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
70 Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget *parent) :
87 kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data();
89 /*if (rendererName == "project") m_monitorId = 10000;
90 else m_monitorId = 10001;*/
91 /*m_osdTimer = new QTimer(this);
92 connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));*/
96 m_mltProducer = m_blackClip->cut(0, 50);
97 m_mltConsumer->connect(*m_mltProducer);
98 m_mltProducer->set_speed(0.0);
108 void Render::closeMlt()
112 Mlt::Service service(m_mltProducer->parent().get_service());
113 mlt_service_lock(service.get_service());
115 if (service.type() == tractor_type) {
116 Mlt::Tractor tractor(service);
117 Mlt::Field *field = tractor.field();
118 mlt_service nextservice = mlt_service_get_producer(service.get_service());
119 mlt_service nextservicetodisconnect;
120 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
121 QString mlt_type = mlt_properties_get(properties, "mlt_type");
122 QString resource = mlt_properties_get(properties, "mlt_service");
123 // Delete all transitions
124 while (mlt_type == "transition") {
125 nextservicetodisconnect = nextservice;
126 nextservice = mlt_service_producer(nextservice);
127 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
128 nextservice = mlt_service_producer(nextservice);
129 if (nextservice == NULL) break;
130 properties = MLT_SERVICE_PROPERTIES(nextservice);
131 mlt_type = mlt_properties_get(properties, "mlt_type");
132 resource = mlt_properties_get(properties, "mlt_service");
135 int trackNb = tractor.count();
136 while (trackNb > 0) {
137 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
138 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
139 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
143 mlt_service_unlock(service.get_service());
146 kDebug() << "// // // CLOSE RENDERER " << m_name;
147 delete m_mltConsumer;
148 delete m_mltProducer;
154 void Render::buildConsumer()
157 m_activeProfile = KdenliveSettings::current_profile();
158 tmp = decodedString(m_activeProfile);
159 setenv("MLT_PROFILE", tmp, 1);
163 //TODO: uncomment following line when everything is clean
164 //if (m_mltProfile) delete m_mltProfile;
165 m_mltProfile = new Mlt::Profile(tmp);
168 QString videoDriver = KdenliveSettings::videodrivername();
169 if (!videoDriver.isEmpty()) {
170 if (videoDriver == "x11_noaccel") {
171 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
174 unsetenv("SDL_VIDEO_YUV_HWACCEL");
177 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
180 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_audio");
181 m_mltConsumer->set("preview_off", 1);
182 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
184 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
186 m_mltConsumer->set("resize", 1);
187 m_mltConsumer->set("window_id", m_winid);
188 m_mltConsumer->set("terminate_on_pause", 1);
189 tmp = decodedString(KdenliveSettings::window_background().name());
190 m_mltConsumer->set("window_background", tmp);
193 // FIXME: the event object returned by the listen gets leaked...
194 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
195 m_mltConsumer->set("rescale", "nearest");
196 mlt_log_set_callback(kdenlive_callback);
198 QString audioDevice = KdenliveSettings::audiodevicename();
199 if (!audioDevice.isEmpty()) {
200 tmp = decodedString(audioDevice);
201 m_mltConsumer->set("audio_device", tmp);
205 if (!videoDriver.isEmpty()) {
206 tmp = decodedString(videoDriver);
207 m_mltConsumer->set("video_driver", tmp);
211 QString audioDriver = KdenliveSettings::audiodrivername();
214 // Disabled because the "auto" detected driver was sometimes wrong
215 if (audioDriver.isEmpty())
216 audioDriver = KdenliveSettings::autoaudiodrivername();
219 if (!audioDriver.isEmpty()) {
220 tmp = decodedString(audioDriver);
221 m_mltConsumer->set("audio_driver", tmp);
226 m_mltConsumer->set("progressive", 1);
227 m_mltConsumer->set("audio_buffer", 1024);
228 m_mltConsumer->set("frequency", 48000);
230 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
231 m_blackClip->set("id", "black");
235 int Render::resetProfile()
237 if (!m_mltConsumer) return 0;
238 if (m_activeProfile == KdenliveSettings::current_profile()) {
239 kDebug() << "reset to same profile, nothing to do";
242 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
243 if (m_isSplitView) slotSplitView(false);
244 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
245 m_mltConsumer->purge();
246 delete m_mltConsumer;
247 m_mltConsumer = NULL;
248 QString scene = sceneList();
250 double current_fps = m_mltProfile->fps();
255 pos = m_mltProducer->position();
257 Mlt::Service service(m_mltProducer->get_service());
258 if (service.type() == tractor_type) {
259 Mlt::Tractor tractor(service);
260 int trackNb = tractor.count();
261 while (trackNb > 0) {
262 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
263 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
264 trackPlaylist.clear();
269 delete m_mltProducer;
271 m_mltProducer = NULL;
274 double new_fps = m_mltProfile->fps();
275 if (current_fps != new_fps) {
276 // fps changed, we must update the scenelist positions
277 scene = updateSceneListFps(current_fps, new_fps, scene);
279 //kDebug() << "//RESET WITHSCENE: " << scene;
280 setSceneList(scene, pos);
282 /*char *tmp = decodedString(scene);
283 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
285 m_mltProducer = producer;
286 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
287 m_mltProducer->optimise();
288 m_mltProducer->set_speed(0);
291 //delete m_mltProfile;
292 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
293 //mlt_profile prof = m_mltProfile->get_profile();
294 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
295 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
296 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
297 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
299 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
304 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
305 void Render::seek(GenTime time)
310 m_mltProducer->seek((int)(time.frames(m_fps)));
315 char *Render::decodedString(QString str)
317 /*QCString fn = QFile::encodeName(str);
318 char *t = new char[fn.length() + 1];
319 strcpy(t, (const char *)fn);*/
321 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
325 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
326 QPixmap pix(width, height);
328 mlt_image_format format = mlt_image_rgb24a;
329 uint8_t *thumb = frame->get_image(format, width, height);
330 QImage image(thumb, width, height, QImage::Format_ARGB32);
332 if (!image.isNull()) {
333 pix = pix.fromImage(image);
335 QPainter painter(&pix);
336 painter.drawRect(0, 0, width - 1, height - 1);
338 } else pix.fill(Qt::black);
342 int Render::renderWidth() const
344 return (int)(m_mltProfile->height() * m_mltProfile->dar());
347 int Render::renderHeight() const
349 return m_mltProfile->height();
352 QPixmap Render::extractFrame(int frame_position, int width, int height)
355 width = renderWidth();
356 height = renderHeight();
357 } else if (width % 2 == 1) width++;
358 QPixmap pix(width, height);
359 if (!m_mltProducer) {
363 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
366 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
370 if (url.fileName().startsWith(".all.")) { // check for slideshow
371 QString fileType = url.fileName().right(3);
373 QStringList::Iterator it;
375 QDir dir(url.directory());
377 filter << "*." + fileType;
378 filter << "*." + fileType.toUpper();
379 more = dir.entryList(filter, QDir::Files);
380 im.load(url.directory() + '/' + more.at(0));
381 } else im.load(url.path());
382 //pixmap = im.scaled(width, height);
387 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
388 QPixmap pix(width, height);
389 char *tmp = decodedString(file);
390 Mlt::Profile *prof = new Mlt::Profile(profile);
391 Mlt::Producer m_producer(*prof, tmp);
393 if (m_producer.is_blank()) {
398 Mlt::Filter m_convert(*prof, "avcolour_space");
399 m_convert.set("forced", mlt_image_rgb24a);
400 m_producer.attach(m_convert);
401 m_producer.seek(frame_position);
402 Mlt::Frame * frame = m_producer.get_frame();
404 pix = frameThumbnail(frame, width, height, true);
407 if (prof) delete prof;
412 void Render::getImage(KUrl url, int frame_position, QPoint size)
414 char *tmp = decodedString(url.path());
415 Mlt::Producer m_producer(tmp);
417 if (m_producer.is_blank()) {
420 Mlt::Filter m_convert("avcolour_space");
421 m_convert.set("forced", mlt_image_rgb24a);
422 m_producer.attach(m_convert);
423 m_producer.seek(frame_position);
425 Mlt::Frame * frame = m_producer.get_frame();
428 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
430 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
434 /* Create thumbnail for color */
435 /*void Render::getImage(int id, QString color, QPoint size)
437 QPixmap pixmap(size.x() - 2, size.y() - 2);
438 color = color.replace(0, 2, "#");
439 color = color.left(7);
440 pixmap.fill(QColor(color));
441 QPixmap result(size.x(), size.y());
442 result.fill(Qt::black);
443 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
444 emit replyGetImage(id, result, size.x(), size.y());
448 /* Create thumbnail for image */
449 /*void Render::getImage(KUrl url, QPoint size)
453 if (url.fileName().startsWith(".all.")) { // check for slideshow
454 QString fileType = url.fileName().right(3);
456 QStringList::Iterator it;
458 QDir dir( url.directory() );
459 more = dir.entryList( QDir::Files );
460 for ( it = more.begin() ; it != more.end() ; ++it ) {
461 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
462 if (!im.load(url.directory() + '/' + *it))
463 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
468 else im.load(url.path());
470 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
471 QPixmap result(size.x(), size.y());
472 result.fill(Qt::black);
473 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
474 emit replyGetImage(url, 1, result, size.x(), size.y());
478 double Render::consumerRatio() const
480 if (!m_mltConsumer) return 1.0;
481 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
485 int Render::getLength()
489 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
490 return mlt_producer_get_playtime(m_mltProducer->get_producer());
495 bool Render::isValid(KUrl url)
497 char *tmp = decodedString(url.path());
498 Mlt::Producer producer(*m_mltProfile, tmp);
500 if (producer.is_blank())
506 double Render::dar() const
508 return m_mltProfile->dar();
511 void Render::slotSplitView(bool doit)
513 m_isSplitView = doit;
514 Mlt::Service service(m_mltProducer->parent().get_service());
515 Mlt::Tractor tractor(service);
516 if (service.type() != tractor_type || tractor.count() < 2) return;
517 Mlt::Field *field = tractor.field();
520 for (int i = 1; i < tractor.count() && screen < 4; i++) {
521 Mlt::Producer trackProducer(tractor.track(i));
522 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
523 if (QString(trackProducer.get("hide")).toInt() != 1) {
524 kDebug() << "// ADIDNG TRACK: " << i;
525 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
526 transition->set("mlt_service", "composite");
527 transition->set("a_track", 0);
528 transition->set("b_track", i);
529 transition->set("distort", 1);
530 transition->set("internal_added", "200");
537 tmp = "50%,0:50%x50%";
540 tmp = "0,50%:50%x50%";
544 tmp = "50%,50%:50%x50%";
547 transition->set("geometry", tmp);
548 transition->set("always_active", "1");
549 field->plant_transition(*transition, 0, i);
554 m_mltConsumer->set("refresh", 1);
556 mlt_service serv = m_mltProducer->parent().get_service();
557 mlt_service nextservice = mlt_service_get_producer(serv);
558 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
559 QString mlt_type = mlt_properties_get(properties, "mlt_type");
560 QString resource = mlt_properties_get(properties, "mlt_service");
562 while (mlt_type == "transition") {
563 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
564 if (added == "200") {
565 mlt_field_disconnect_service(field->get_field(), nextservice);
567 nextservice = mlt_service_producer(nextservice);
568 if (nextservice == NULL) break;
569 properties = MLT_SERVICE_PROPERTIES(nextservice);
570 mlt_type = mlt_properties_get(properties, "mlt_type");
571 resource = mlt_properties_get(properties, "mlt_service");
572 m_mltConsumer->set("refresh", 1);
577 void Render::getFileProperties(const QDomElement xml, const QString &clipId, bool replaceProducer)
579 KUrl url = KUrl(xml.attribute("resource", QString()));
580 Mlt::Producer *producer = NULL;
581 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
582 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
583 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
586 if (xml.attribute("type").toInt() == COLOR) {
587 char *tmp = decodedString("colour:" + xml.attribute("colour"));
588 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
590 } else if (xml.attribute("type").toInt() == TEXT) {
591 char *tmp = decodedString("kdenlivetitle:" + xml.attribute("resource"));
592 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
594 if (xml.hasAttribute("xmldata")) {
595 char *tmp = decodedString(xml.attribute("xmldata"));
596 producer->set("xmldata", tmp);
599 } else if (url.isEmpty()) {
601 QDomElement mlt = doc.createElement("mlt");
602 QDomElement play = doc.createElement("playlist");
603 doc.appendChild(mlt);
604 mlt.appendChild(play);
605 play.appendChild(doc.importNode(xml, true));
606 char *tmp = decodedString(doc.toString());
607 producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
610 char *tmp = decodedString(url.path());
611 producer = new Mlt::Producer(*m_mltProfile, tmp);
615 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
616 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
617 emit removeInvalidClip(clipId, replaceProducer);
622 if (xml.hasAttribute("force_aspect_ratio")) {
623 double aspect = xml.attribute("force_aspect_ratio").toDouble();
624 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
626 if (xml.hasAttribute("threads")) {
627 int threads = xml.attribute("threads").toInt();
628 if (threads != 1) producer->set("threads", threads);
630 if (xml.hasAttribute("video_index")) {
631 int vindex = xml.attribute("video_index").toInt();
632 if (vindex != 0) producer->set("video_index", vindex);
634 if (xml.hasAttribute("audio_index")) {
635 int aindex = xml.attribute("audio_index").toInt();
636 if (aindex != 0) producer->set("audio_index", aindex);
639 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
641 char *tmp = decodedString(clipId);
642 producer->set("id", tmp);
645 if (xml.hasAttribute("templatetext")) {
646 char *tmp = decodedString(xml.attribute("templatetext"));
647 producer->set("templatetext", tmp);
651 if (!replaceProducer && xml.hasAttribute("file_hash")) {
652 // Clip already has all properties
653 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
658 int width = (int)(height * m_mltProfile->dar());
659 QMap < QString, QString > filePropertyMap;
660 QMap < QString, QString > metadataPropertyMap;
662 int frameNumber = xml.attribute("thumbnail", "0").toInt();
663 if (frameNumber != 0) producer->seek(frameNumber);
665 filePropertyMap["duration"] = QString::number(producer->get_playtime());
666 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
668 Mlt::Frame *frame = producer->get_frame();
670 if (xml.attribute("type").toInt() == SLIDESHOW) {
671 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
672 if (xml.attribute("fade") == "1") {
673 // user wants a fade effect to slideshow
674 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
675 if (filter && filter->is_valid()) {
676 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
677 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
678 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
679 char *tmp = decodedString(xml.attribute("luma_file"));
680 filter->set("luma.resource", tmp);
682 if (xml.hasAttribute("softness")) {
683 int soft = xml.attribute("softness").toInt();
684 filter->set("luma.softness", (double) soft / 100.0);
687 Mlt::Service clipService(producer->get_service());
688 clipService.attach(*filter);
694 filePropertyMap["fps"] = producer->get("source_fps");
696 if (frame && frame->is_valid()) {
697 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
698 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
699 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
700 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
702 if (frame->get_int("test_image") == 0) {
703 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
704 filePropertyMap["type"] = "playlist";
705 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
706 } else if (frame->get_int("test_audio") == 0)
707 filePropertyMap["type"] = "av";
709 filePropertyMap["type"] = "video";
711 mlt_image_format format = mlt_image_rgb24a;
712 int frame_width = width;
713 int frame_height = height;
714 QPixmap pix(width, height);
715 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
716 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32);
718 if (!image.isNull()) {
719 pix = QPixmap::fromImage(image.rgbSwapped());
723 emit replyGetImage(clipId, pix);
725 } else if (frame->get_int("test_audio") == 0) {
726 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
727 emit replyGetImage(clipId, pixmap);
728 filePropertyMap["type"] = "audio";
732 // Retrieve audio / video codec name
736 if (producer->get_int("video_index") > -1) {
737 /*if (context->duration == AV_NOPTS_VALUE) {
738 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
739 emit removeInvalidClip(clipId);
743 // Get the video_index
744 int default_video = producer->get_int("video_index");
746 int default_audio = producer->get_int("audio_index");
749 // Find maximum stream index values
750 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
751 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
752 QString type = producer->get(property);
755 else if (type == "audio")
758 filePropertyMap["default_video"] = QString::number(default_video);
759 filePropertyMap["video_max"] = QString::number(video_max);
760 filePropertyMap["default_audio"] = QString::number(default_audio);
761 filePropertyMap["audio_max"] = QString::number(audio_max);
763 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
764 if (producer->get(property)) {
765 filePropertyMap["videocodec"] = producer->get(property);
767 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
768 if (producer->get(property))
769 filePropertyMap["videocodec"] = producer->get(property);
772 if (KdenliveSettings::dropbframes()) {
773 kDebug() << "// LOOKING FOR H264 on: " << default_video;
774 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
775 kDebug() << "PROP: " << property << " = " << producer->get(property);
776 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
777 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
778 producer->set("skip_loop_filter", "all");
779 producer->set("skip_frame", "bidir");
783 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
784 if (producer->get_int("audio_index") > -1) {
785 // Get the audio_index
786 int index = producer->get_int("audio_index");
788 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
789 if (producer->get(property)) {
790 filePropertyMap["audiocodec"] = producer->get(property);
792 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
793 if (producer->get(property))
794 filePropertyMap["audiocodec"] = producer->get(property);
799 Mlt::Properties metadata;
800 metadata.pass_values(*producer, "meta.attr.");
801 int count = metadata.count();
802 for (int i = 0; i < count; i ++) {
803 QString name = metadata.get_name(i);
804 QString value = QString::fromUtf8(metadata.get(i));
805 if (name.endsWith("markup") && !value.isEmpty())
806 metadataPropertyMap[ name.section('.', 0, -2)] = value;
809 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
810 kDebug() << "REquested fuile info for: " << url.path();
812 // FIXME: should delete this to avoid a leak...
817 /** Create the producer from the MLT XML QDomDocument */
819 void Render::initSceneList()
821 kDebug() << "-------- INIT SCENE LIST ------_";
823 QDomElement mlt = doc.createElement("mlt");
824 doc.appendChild(mlt);
825 QDomElement prod = doc.createElement("producer");
826 prod.setAttribute("resource", "colour");
827 prod.setAttribute("colour", "red");
828 prod.setAttribute("id", "black");
829 prod.setAttribute("in", "0");
830 prod.setAttribute("out", "0");
832 QDomElement tractor = doc.createElement("tractor");
833 QDomElement multitrack = doc.createElement("multitrack");
835 QDomElement playlist1 = doc.createElement("playlist");
836 playlist1.appendChild(prod);
837 multitrack.appendChild(playlist1);
838 QDomElement playlist2 = doc.createElement("playlist");
839 multitrack.appendChild(playlist2);
840 QDomElement playlist3 = doc.createElement("playlist");
841 multitrack.appendChild(playlist3);
842 QDomElement playlist4 = doc.createElement("playlist");
843 multitrack.appendChild(playlist4);
844 QDomElement playlist5 = doc.createElement("playlist");
845 multitrack.appendChild(playlist5);
846 tractor.appendChild(multitrack);
847 mlt.appendChild(tractor);
848 // kDebug()<<doc.toString();
850 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
851 setSceneList(doc, 0);
857 /** Create the producer from the MLT XML QDomDocument */
858 int Render::setProducer(Mlt::Producer *producer, int position)
860 if (m_winid == -1) return -1;
863 m_mltConsumer->stop();
866 m_mltConsumer->purge();
870 m_mltProducer->set_speed(0);
871 delete m_mltProducer;
872 m_mltProducer = NULL;
876 m_mltProducer = new Mlt::Producer(producer->get_producer());
877 } else m_mltProducer = m_blackClip->cut(0, 50);
878 /*if (KdenliveSettings::dropbframes()) {
879 m_mltProducer->set("skip_loop_filter", "all");
880 m_mltProducer->set("skip_frame", "bidir");
882 if (!m_mltProducer || !m_mltProducer->is_valid()) {
883 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
887 m_fps = m_mltProducer->get_fps();
888 int error = connectPlaylist();
889 if (position != -1) {
890 m_mltProducer->seek(position);
891 emit rendererPosition(position);
899 /** Create the producer from the MLT XML QDomDocument */
900 int Render::setSceneList(QDomDocument list, int position)
902 return setSceneList(list.toString(), position);
905 /** Create the producer from the MLT XML QDomDocument */
906 int Render::setSceneList(QString playlist, int position)
908 if (m_winid == -1) return -1;
912 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
914 if (m_mltConsumer == NULL) {
915 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
920 if (!m_mltConsumer->is_stopped()) {
921 m_mltConsumer->stop();
923 m_mltConsumer->set("refresh", 0);
926 m_mltProducer->set_speed(0);
927 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
930 Mlt::Service service(m_mltProducer->parent().get_service());
931 mlt_service_lock(service.get_service());
933 if (service.type() == tractor_type) {
934 Mlt::Tractor tractor(service);
935 Mlt::Field *field = tractor.field();
936 mlt_service nextservice = mlt_service_get_producer(service.get_service());
937 mlt_service nextservicetodisconnect;
938 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
939 QString mlt_type = mlt_properties_get(properties, "mlt_type");
940 QString resource = mlt_properties_get(properties, "mlt_service");
941 // Delete all transitions
942 while (mlt_type == "transition") {
943 nextservicetodisconnect = nextservice;
944 nextservice = mlt_service_producer(nextservice);
945 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
946 if (nextservice == NULL) break;
947 properties = MLT_SERVICE_PROPERTIES(nextservice);
948 mlt_type = mlt_properties_get(properties, "mlt_type");
949 resource = mlt_properties_get(properties, "mlt_service");
952 int trackNb = tractor.count();
953 while (trackNb > 0) {
954 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
955 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
956 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
960 mlt_service_unlock(service.get_service());
962 qDeleteAll(m_slowmotionProducers.values());
963 m_slowmotionProducers.clear();
965 delete m_mltProducer;
966 m_mltProducer = NULL;
971 char *tmp = decodedString(playlist);
972 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
974 if (!m_mltProducer || !m_mltProducer->is_valid()) {
975 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
976 m_mltProducer = m_blackClip->cut(0, 50);
980 m_mltProducer->optimise();
982 /*if (KdenliveSettings::osdtimecode()) {
983 // Attach filter for on screen display of timecode
985 QString attr = "attr_check";
986 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
987 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
988 mlt_producer_attach( m_mltProducer->get_producer(), filter );
989 mlt_filter_close( filter );
991 m_osdInfo = new Mlt::Filter("data_show");
992 tmp = decodedString(m_osdProfile);
993 m_osdInfo->set("resource", tmp);
995 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
996 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
997 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
998 m_osdInfo->set("dynamic", "1");
1000 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1002 m_osdInfo->set("dynamic", "0");
1005 m_fps = m_mltProducer->get_fps();
1006 if (position != 0) {
1007 // Seek to correct place after opening project.
1008 m_mltProducer->seek(position);
1011 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
1012 error = connectPlaylist();
1013 fillSlowMotionProducers();
1015 m_isBlocked = false;
1016 blockSignals(false);
1017 emit refreshDocumentProducers();
1019 //kDebug()<<"// SETSCN LST, POS: "<<position;
1020 //if (position != 0) emit rendererPosition(position);
1023 /** Create the producer from the MLT XML QDomDocument */
1024 const QString Render::sceneList()
1027 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
1028 m_mltProducer->optimise();
1029 xmlConsumer.set("terminate_on_pause", 1);
1030 Mlt::Producer prod(m_mltProducer->get_producer());
1031 bool split = m_isSplitView;
1032 if (split) slotSplitView(false);
1033 xmlConsumer.connect(prod);
1034 xmlConsumer.start();
1035 while (!xmlConsumer.is_stopped()) {}
1036 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1037 if (split) slotSplitView(true);
1041 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1045 doc.setContent(sceneList(), false);
1046 if (!kdenliveData.isNull()) {
1047 // add Kdenlive specific tags
1048 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1049 mlt.appendChild(doc.importNode(kdenliveData, true));
1051 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1052 kWarning() << "////// ERROR writing to file: " << path;
1055 file.write(doc.toString().toUtf8());
1056 if (file.error() != QFile::NoError) {
1065 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1067 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1068 char *tmppath = decodedString("xml:" + url.path());
1069 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
1070 m_mltProducer->optimise();
1072 xmlConsumer.set("terminate_on_pause", 1);
1073 if (m_name == "clip") {
1074 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1075 tmppath = decodedString(desc);
1077 list.insert_at(0, prod, 0);
1079 list.set("title", tmppath);
1081 xmlConsumer.connect(list);
1084 //TODO: not working yet, save zone from timeline
1085 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1086 /* Mlt::Service service(p1->parent().get_service());
1087 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1089 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1090 tmppath = decodedString(desc);
1091 //prod->set("title", tmppath);
1093 xmlConsumer.connect(*p1); //list);
1096 xmlConsumer.start();
1099 double Render::fps() const
1104 int Render::connectPlaylist()
1106 if (!m_mltConsumer) return -1;
1107 //m_mltConsumer->set("refresh", "0");
1108 m_mltConsumer->connect(*m_mltProducer);
1109 m_mltProducer->set_speed(0);
1110 if (m_mltConsumer->start() == -1) {
1111 // ARGH CONSUMER BROKEN!!!!
1112 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."));
1113 emit blockMonitors();
1114 delete m_mltProducer;
1115 m_mltProducer = NULL;
1118 emit durationChanged(m_mltProducer->get_playtime());
1123 void Render::refreshDisplay()
1126 if (!m_mltProducer) return;
1127 //m_mltConsumer->set("refresh", 0);
1129 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1130 /*if (KdenliveSettings::osdtimecode()) {
1131 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1132 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1133 m_osdInfo->set("dynamic", "1");
1134 m_mltProducer->attach(*m_osdInfo);
1137 m_mltProducer->detach(*m_osdInfo);
1138 m_osdInfo->set("dynamic", "0");
1143 void Render::setVolume(double /*volume*/)
1145 if (!m_mltConsumer || !m_mltProducer) return;
1147 m_mltConsumer->set("refresh", 0);
1148 // Attach filter for on screen display of timecode
1149 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1150 mlt_properties_set_double( properties, "meta.volume", volume );
1151 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1152 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1154 if (!KdenliveSettings::osdtimecode()) {
1155 m_mltProducer->detach(*m_osdInfo);
1156 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1157 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1160 //m_osdTimer->setSingleShot(2500);
1163 void Render::slotOsdTimeout()
1165 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1166 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1167 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1168 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1172 void Render::start()
1174 kDebug() << "----- STARTING MONITOR: " << m_name;
1175 if (m_winid == -1) {
1176 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1179 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1180 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1181 if (m_mltConsumer->start() == -1) {
1182 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."));
1183 emit blockMonitors();
1184 delete m_mltProducer;
1185 m_mltProducer = NULL;
1187 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1188 m_isBlocked = false;
1192 m_isBlocked = false;
1197 if (m_mltProducer == NULL) return;
1198 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1199 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1201 //m_mltConsumer->set("refresh", 0);
1202 m_mltConsumer->stop();
1203 // delete m_mltConsumer;
1204 // m_mltConsumer = NULL;
1206 kDebug() << "///////////// RENDER STOP2-------";
1209 if (m_mltProducer) {
1210 if (m_isZoneMode) resetZoneMode();
1211 m_mltProducer->set_speed(0.0);
1212 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1213 //kDebug() << m_mltProducer->get_length();
1215 kDebug() << "///////////// RENDER STOP3-------";
1218 void Render::stop(const GenTime & startTime)
1221 kDebug() << "///////////// RENDER STOP-------2";
1222 if (m_mltProducer) {
1223 if (m_isZoneMode) resetZoneMode();
1224 m_mltProducer->set_speed(0.0);
1225 m_mltProducer->seek((int) startTime.frames(m_fps));
1227 m_mltConsumer->purge();
1230 void Render::pause()
1232 if (!m_mltProducer || !m_mltConsumer)
1234 if (m_mltProducer->get_speed() == 0.0) return;
1235 if (m_isZoneMode) resetZoneMode();
1237 m_mltConsumer->set("refresh", 0);
1238 m_mltProducer->set_speed(0.0);
1239 emit rendererPosition(m_framePosition);
1240 m_mltProducer->seek(m_framePosition);
1241 m_mltConsumer->purge();
1244 void Render::switchPlay()
1246 if (!m_mltProducer || !m_mltConsumer)
1248 if (m_isZoneMode) resetZoneMode();
1249 if (m_mltProducer->get_speed() == 0.0) {
1250 m_isBlocked = false;
1251 m_mltProducer->set_speed(1.0);
1252 m_mltConsumer->set("refresh", 1);
1255 m_mltConsumer->set("refresh", 0);
1256 m_mltProducer->set_speed(0.0);
1257 emit rendererPosition(m_framePosition);
1258 m_mltProducer->seek(m_framePosition);
1259 m_mltConsumer->purge();
1260 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1261 //m_mltConsumer->set("refresh", 0);
1262 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1263 m_mltProducer->set_speed(0);
1264 m_mltProducer->seek( position );
1265 //m_mltProducer->seek((int) m_framePosition);
1266 m_isBlocked = false;*/
1268 /*if (speed == 0.0) {
1269 m_mltProducer->seek((int) m_framePosition + 1);
1270 m_mltConsumer->purge();
1275 void Render::play(double speed)
1279 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1280 m_isBlocked = false;
1281 m_mltProducer->set_speed(speed);
1282 /*if (speed == 0.0) {
1283 m_mltProducer->seek((int) m_framePosition + 1);
1284 m_mltConsumer->purge();
1289 void Render::play(const GenTime & startTime)
1291 if (!m_mltProducer || !m_mltConsumer)
1293 m_isBlocked = false;
1294 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1295 m_mltProducer->set_speed(1.0);
1296 m_mltConsumer->set("refresh", 1);
1299 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1301 if (!m_mltProducer || !m_mltConsumer)
1303 //m_mltProducer->set("eof", "loop");
1304 m_isLoopMode = true;
1305 m_loopStart = startTime;
1306 playZone(startTime, stopTime);
1309 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1311 if (!m_mltProducer || !m_mltConsumer)
1313 m_isBlocked = false;
1314 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1315 m_mltProducer->set("out", stopTime.frames(m_fps));
1316 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1317 m_mltProducer->set_speed(1.0);
1318 m_mltConsumer->set("refresh", 1);
1319 m_isZoneMode = true;
1322 void Render::resetZoneMode()
1324 if (!m_isZoneMode && !m_isLoopMode) return;
1325 m_mltProducer->set("out", m_originalOut);
1326 //m_mltProducer->set("eof", "pause");
1327 m_isZoneMode = false;
1328 m_isLoopMode = false;
1331 void Render::seekToFrame(int pos)
1333 //kDebug()<<" ********* RENDER SEEK TO POS";
1336 m_isBlocked = false;
1338 m_mltProducer->seek(pos);
1342 void Render::seekToFrameDiff(int diff)
1344 //kDebug()<<" ********* RENDER SEEK TO POS";
1347 m_isBlocked = false;
1349 m_mltProducer->seek(m_mltProducer->position() + diff);
1353 void Render::doRefresh()
1355 // Use a Timer so that we don't refresh too much
1356 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1359 void Render::refresh()
1361 if (!m_mltProducer || m_isBlocked)
1363 if (m_mltConsumer) {
1364 m_mltConsumer->set("refresh", 1);
1368 void Render::setDropFrames(bool show)
1370 if (m_mltConsumer) {
1372 if (show == false) dropFrames = 0;
1373 m_mltConsumer->stop();
1375 m_mltConsumer->set("real_time", dropFrames);
1377 m_mltConsumer->set("play.real_time", dropFrames);
1379 if (m_mltConsumer->start() == -1) {
1380 emit blockMonitors();
1381 delete m_mltProducer;
1382 m_mltProducer = NULL;
1388 double Render::playSpeed()
1390 if (m_mltProducer) return m_mltProducer->get_speed();
1394 GenTime Render::seekPosition() const
1396 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1397 else return GenTime();
1400 int Render::seekFramePosition() const
1402 if (m_mltProducer) return (int) m_mltProducer->position();
1406 const QString & Render::rendererName() const
1412 void Render::emitFrameNumber(double position)
1414 m_framePosition = position;
1415 emit rendererPosition((int) position);
1416 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1419 void Render::emitConsumerStopped()
1421 // This is used to know when the playing stopped
1422 if (m_mltProducer) {
1423 double pos = m_mltProducer->position();
1424 if (m_isLoopMode) play(m_loopStart);
1425 else if (m_isZoneMode) resetZoneMode();
1426 emit rendererStopped((int) pos);
1427 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1428 //new QCustomEvent(10002));
1434 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1436 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1440 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1442 if (!m_mltProducer) {
1443 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1447 //int height = 1080;//KdenliveSettings::defaultheight();
1448 //int width = 1940; //KdenliveSettings::displaywidth();
1450 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1452 QPixmap pix(width, height);
1453 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1454 m_convert.set("forced", mlt_image_rgb24a);
1455 m_mltProducer->attach(m_convert);
1456 Mlt::Frame * frame = m_mltProducer->get_frame();
1457 m_mltProducer->detach(m_convert);
1459 pix = frameThumbnail(frame, width, height);
1462 pix.save(url.path(), "PNG");
1463 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1467 void Render::showFrame(Mlt::Frame& frame)
1469 mlt_image_format format = mlt_image_rgb24a;
1472 const uchar* image = frame.get_image(format, width, height);
1473 QImage qimage(width, height, QImage::Format_ARGB32);
1474 memcpy(qimage.scanLine(0), image, width * height * 4);
1475 emit showImageSignal(qimage);
1479 /** MLT PLAYLIST DIRECT MANIPULATON **/
1482 void Render::mltCheckLength(Mlt::Tractor *tractor)
1484 //kDebug()<<"checking track length: "<<track<<"..........";
1486 int trackNb = tractor->count();
1490 Mlt::Producer trackProducer(tractor->track(0));
1491 duration = trackProducer.get_playtime() - 1;
1492 m_mltProducer->set("out", duration);
1493 emit durationChanged(duration);
1496 while (trackNb > 1) {
1497 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1498 trackDuration = trackProducer.get_playtime() - 1;
1499 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1500 if (trackDuration > duration) duration = trackDuration;
1504 Mlt::Producer blackTrackProducer(tractor->track(0));
1506 if (blackTrackProducer.get_playtime() - 1 != duration) {
1507 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1508 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1509 if (blackclip && blackclip->is_blank()) {
1514 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1515 blackTrackPlaylist.clear();
1516 m_blackClip->set("length", duration);
1517 m_blackClip->set("out", duration - 1);
1518 blackclip = m_blackClip->cut(0, duration - 1);
1519 blackTrackPlaylist.insert_at(0, blackclip, 1);
1521 if (duration > blackclip->parent().get_length()) {
1522 blackclip->parent().set("length", duration);
1523 blackclip->parent().set("out", duration - 1);
1524 blackclip->set("length", duration);
1526 blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1530 m_mltProducer->set("out", duration);
1531 emit durationChanged(duration);
1535 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1537 if (m_mltProducer == NULL) {
1538 kDebug() << "PLAYLIST NOT INITIALISED //////";
1541 Mlt::Producer parentProd(m_mltProducer->parent());
1542 if (parentProd.get_producer() == NULL) {
1543 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1547 Mlt::Service service(parentProd.get_service());
1548 if (service.type() != tractor_type) {
1549 kWarning() << "// TRACTOR PROBLEM";
1552 Mlt::Tractor tractor(service);
1553 if (info.track > tractor.count() - 1) {
1554 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1557 mlt_service_lock(service.get_service());
1558 Mlt::Producer trackProducer(tractor.track(info.track));
1559 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1560 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1562 if (element.attribute("speed", "1.0").toDouble() != 1.0 || element.attribute("strobe", "1").toInt() > 1) {
1563 // We want a slowmotion producer
1564 double speed = element.attribute("speed", "1.0").toDouble();
1565 int strobe = element.attribute("strobe", "1").toInt();
1566 QString url = QString::fromUtf8(prod->get("resource"));
1567 url.append('?' + QString::number(speed));
1568 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1569 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1570 if (!slowprod || slowprod->get_producer() == NULL) {
1571 char *tmp = decodedString(url);
1572 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1573 if (strobe > 1) slowprod->set("strobe", strobe);
1575 QString id = prod->get("id");
1576 if (id.contains('_')) id = id.section('_', 0, 0);
1577 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1578 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1579 tmp = decodedString(producerid);
1580 slowprod->set("id", tmp);
1582 m_slowmotionProducers.insert(url, slowprod);
1587 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1588 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), clip, 1);
1590 /*if (QString(prod->get("transparency")).toInt() == 1)
1591 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1593 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1594 mlt_service_unlock(service.get_service());
1595 /*tractor.multitrack()->refresh();
1596 tractor.refresh();*/
1601 void Render::mltCutClip(int track, GenTime position)
1606 Mlt::Service service(m_mltProducer->parent().get_service());
1607 if (service.type() != tractor_type) {
1608 kWarning() << "// TRACTOR PROBLEM";
1612 Mlt::Tractor tractor(service);
1613 Mlt::Producer trackProducer(tractor.track(track));
1614 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1617 /* // Display playlist info
1618 kDebug()<<"//////////// BEFORE";
1619 for (int i = 0; i < trackPlaylist.count(); i++) {
1620 int blankStart = trackPlaylist.clip_start(i);
1621 int blankDuration = trackPlaylist.clip_length(i) - 1;
1623 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1624 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1627 int cutPos = (int) position.frames(m_fps);
1629 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1630 if (trackPlaylist.is_blank(clipIndex)) {
1631 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1632 m_isBlocked = false;
1635 mlt_service_lock(service.get_service());
1636 int clipStart = trackPlaylist.clip_start(clipIndex);
1637 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1638 mlt_service_unlock(service.get_service());
1640 // duplicate effects
1641 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1642 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1644 if (original == NULL || clip == NULL) {
1645 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1647 Mlt::Service clipService(original->get_service());
1648 Mlt::Service dupService(clip->get_service());
1652 Mlt::Filter *filter = clipService.filter(ct);
1654 // Only duplicate Kdenlive filters, and skip the fade in effects
1655 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1656 // looks like there is no easy way to duplicate a filter,
1657 // so we will create a new one and duplicate its properties
1658 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1659 if (dup && dup->is_valid()) {
1660 Mlt::Properties entries(filter->get_properties());
1661 for (int i = 0; i < entries.count(); i++) {
1662 dup->set(entries.get_name(i), entries.get(i));
1664 dupService.attach(*dup);
1668 filter = clipService.filter(ct);
1671 /* // Display playlist info
1672 kDebug()<<"//////////// AFTER";
1673 for (int i = 0; i < trackPlaylist.count(); i++) {
1674 int blankStart = trackPlaylist.clip_start(i);
1675 int blankDuration = trackPlaylist.clip_length(i) - 1;
1677 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1678 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1681 m_isBlocked = false;
1684 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1687 mltRemoveClip(info.track, info.startPos);
1688 mltInsertClip(info, element, prod);
1692 bool Render::mltRemoveClip(int track, GenTime position)
1694 Mlt::Service service(m_mltProducer->parent().get_service());
1695 if (service.type() != tractor_type) {
1696 kWarning() << "// TRACTOR PROBLEM";
1700 Mlt::Tractor tractor(service);
1701 mlt_service_lock(service.get_service());
1702 Mlt::Producer trackProducer(tractor.track(track));
1703 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1704 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1706 // Display playlist info
1707 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1708 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1709 int blankStart = trackPlaylist.clip_start(i);
1710 int blankDuration = trackPlaylist.clip_length(i) - 1;
1712 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1713 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1715 if (trackPlaylist.is_blank(clipIndex)) {
1716 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1717 mlt_service_unlock(service.get_service());
1720 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1722 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1723 if (clip) delete clip;
1724 trackPlaylist.consolidate_blanks(0);
1725 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1726 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1728 /* // Display playlist info
1729 kDebug()<<"//// AFTER";
1730 for (int i = 0; i < trackPlaylist.count(); i++) {
1731 int blankStart = trackPlaylist.clip_start(i);
1732 int blankDuration = trackPlaylist.clip_length(i) - 1;
1734 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1735 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1737 mlt_service_unlock(service.get_service());
1738 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1739 m_isBlocked = false;
1743 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1745 if (!m_mltProducer) {
1746 kDebug() << "PLAYLIST NOT INITIALISED //////";
1749 Mlt::Producer parentProd(m_mltProducer->parent());
1750 if (parentProd.get_producer() == NULL) {
1751 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1755 Mlt::Service service(parentProd.get_service());
1756 Mlt::Tractor tractor(service);
1757 int insertPos = pos.frames(m_fps);
1759 Mlt::Producer trackProducer(tractor.track(track));
1760 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1761 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1762 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1763 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1764 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1767 int Render::mltTrackDuration(int track)
1769 if (!m_mltProducer) {
1770 kDebug() << "PLAYLIST NOT INITIALISED //////";
1773 Mlt::Producer parentProd(m_mltProducer->parent());
1774 if (parentProd.get_producer() == NULL) {
1775 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1779 Mlt::Service service(parentProd.get_service());
1780 Mlt::Tractor tractor(service);
1782 Mlt::Producer trackProducer(tractor.track(track));
1783 return trackProducer.get_playtime() - 1;
1786 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1788 if (!m_mltProducer) {
1789 kDebug() << "PLAYLIST NOT INITIALISED //////";
1792 Mlt::Producer parentProd(m_mltProducer->parent());
1793 if (parentProd.get_producer() == NULL) {
1794 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1797 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1798 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1800 Mlt::Service service(parentProd.get_service());
1801 Mlt::Tractor tractor(service);
1802 mlt_service_lock(service.get_service());
1803 int diff = duration.frames(m_fps);
1804 int offset = timeOffset.frames(m_fps);
1808 // insert space in one track only
1809 Mlt::Producer trackProducer(tractor.track(track));
1810 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1811 insertPos = trackClipStartList.value(track);
1812 if (insertPos != -1) {
1813 insertPos += offset;
1814 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1816 trackPlaylist.insert_blank(clipIndex, diff - 1);
1818 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1819 if (!trackPlaylist.is_blank(clipIndex)) {
1820 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1822 int position = trackPlaylist.clip_start(clipIndex);
1823 int blankDuration = trackPlaylist.clip_length(clipIndex);
1825 if (blankDuration - diff == 0) {
1826 trackPlaylist.remove(clipIndex);
1827 } else trackPlaylist.remove_region(position, diff);
1829 trackPlaylist.consolidate_blanks(0);
1831 // now move transitions
1832 mlt_service serv = m_mltProducer->parent().get_service();
1833 mlt_service nextservice = mlt_service_get_producer(serv);
1834 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1835 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1836 QString resource = mlt_properties_get(properties, "mlt_service");
1838 while (mlt_type == "transition") {
1839 mlt_transition tr = (mlt_transition) nextservice;
1840 int currentTrack = mlt_transition_get_b_track(tr);
1841 int currentIn = (int) mlt_transition_get_in(tr);
1842 int currentOut = (int) mlt_transition_get_out(tr);
1843 insertPos = trackTransitionStartList.value(track);
1844 if (insertPos != -1) {
1845 insertPos += offset;
1846 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1847 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1850 nextservice = mlt_service_producer(nextservice);
1851 if (nextservice == NULL) break;
1852 properties = MLT_SERVICE_PROPERTIES(nextservice);
1853 mlt_type = mlt_properties_get(properties, "mlt_type");
1854 resource = mlt_properties_get(properties, "mlt_service");
1857 int trackNb = tractor.count();
1858 while (trackNb > 1) {
1859 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1860 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1863 //int clipNb = trackPlaylist.count();
1864 insertPos = trackClipStartList.value(trackNb - 1);
1865 if (insertPos != -1) {
1866 insertPos += offset;
1868 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1869 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1870 for (int i = 0; i < clipNb; i++) {
1871 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1872 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1873 kDebug()<<"-------------";
1875 kDebug()<<"END-------------";*/
1878 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1880 trackPlaylist.insert_blank(clipIndex, diff - 1);
1882 if (!trackPlaylist.is_blank(clipIndex)) {
1885 if (!trackPlaylist.is_blank(clipIndex)) {
1886 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1888 int position = trackPlaylist.clip_start(clipIndex);
1889 int blankDuration = trackPlaylist.clip_length(clipIndex);
1890 if (diff + blankDuration == 0) {
1891 trackPlaylist.remove(clipIndex);
1892 } else trackPlaylist.remove_region(position, - diff);
1894 trackPlaylist.consolidate_blanks(0);
1898 // now move transitions
1899 mlt_service serv = m_mltProducer->parent().get_service();
1900 mlt_service nextservice = mlt_service_get_producer(serv);
1901 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1902 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1903 QString resource = mlt_properties_get(properties, "mlt_service");
1905 while (mlt_type == "transition") {
1906 mlt_transition tr = (mlt_transition) nextservice;
1907 int currentIn = (int) mlt_transition_get_in(tr);
1908 int currentOut = (int) mlt_transition_get_out(tr);
1909 int currentTrack = mlt_transition_get_b_track(tr);
1910 insertPos = trackTransitionStartList.value(currentTrack);
1911 if (insertPos != -1) {
1912 insertPos += offset;
1913 if (currentOut > insertPos && resource != "mix") {
1914 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1917 nextservice = mlt_service_producer(nextservice);
1918 if (nextservice == NULL) break;
1919 properties = MLT_SERVICE_PROPERTIES(nextservice);
1920 mlt_type = mlt_properties_get(properties, "mlt_type");
1921 resource = mlt_properties_get(properties, "mlt_service");
1924 mlt_service_unlock(service.get_service());
1925 mltCheckLength(&tractor);
1926 m_mltConsumer->set("refresh", 1);
1930 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1932 Mlt::Service sourceService(source->get_service());
1933 Mlt::Service destService(dest->get_service());
1935 // move all effects to the correct producer
1937 Mlt::Filter *filter = sourceService.filter(ct);
1939 if (filter->get("kdenlive_ix") != 0) {
1940 sourceService.detach(*filter);
1941 destService.attach(*filter);
1943 filter = sourceService.filter(ct);
1947 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, int strobe, Mlt::Producer *prod)
1951 Mlt::Service service(m_mltProducer->parent().get_service());
1952 if (service.type() != tractor_type) {
1953 kWarning() << "// TRACTOR PROBLEM";
1956 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1957 Mlt::Tractor tractor(service);
1958 Mlt::Producer trackProducer(tractor.track(info.track));
1959 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1960 int startPos = info.startPos.frames(m_fps);
1961 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1962 int clipLength = trackPlaylist.clip_length(clipIndex);
1964 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1968 if (!clip->is_valid() || clip->is_blank()) {
1973 Mlt::Producer clipparent = clip->parent();
1974 if (!clipparent.is_valid() || clipparent.is_blank()) {
1980 QString serv = clipparent.get("mlt_service");
1981 QString id = clipparent.get("id");
1982 //kDebug() << "CLIP SERVICE: " << serv;
1983 if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
1984 mlt_service_lock(service.get_service());
1985 QString url = QString::fromUtf8(clipparent.get("resource"));
1986 url.append('?' + QString::number(speed));
1987 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1988 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1989 if (!slowprod || slowprod->get_producer() == NULL) {
1990 char *tmp = decodedString(url);
1991 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1992 if (strobe > 1) slowprod->set("strobe", strobe);
1994 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1995 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1996 tmp = decodedString(producerid);
1997 slowprod->set("id", tmp);
1999 m_slowmotionProducers.insert(url, slowprod);
2001 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2002 trackPlaylist.consolidate_blanks(0);
2003 // Check that the blank space is long enough for our new duration
2004 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2005 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2007 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2008 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2009 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2010 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2012 // move all effects to the correct producer
2013 mltPasteEffects(clip, cut);
2014 trackPlaylist.insert_at(startPos, cut, 1);
2017 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2018 newLength = trackPlaylist.clip_length(clipIndex);
2019 mlt_service_unlock(service.get_service());
2020 } else if (speed == 1.0 && strobe < 2) {
2021 mlt_service_lock(service.get_service());
2023 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2024 trackPlaylist.consolidate_blanks(0);
2026 // Check that the blank space is long enough for our new duration
2027 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2028 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2031 GenTime oldDuration = GenTime(clipLength, m_fps);
2032 GenTime newDuration = oldDuration * oldspeed;
2033 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
2034 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2035 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
2036 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
2038 // move all effects to the correct producer
2039 mltPasteEffects(clip, cut);
2041 trackPlaylist.insert_at(startPos, cut, 1);
2044 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2045 newLength = trackPlaylist.clip_length(clipIndex);
2046 mlt_service_unlock(service.get_service());
2048 } else if (serv == "framebuffer") {
2049 mlt_service_lock(service.get_service());
2050 QString url = QString::fromUtf8(clipparent.get("resource"));
2051 url = url.section('?', 0, 0);
2052 url.append('?' + QString::number(speed));
2053 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2054 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2055 if (!slowprod || slowprod->get_producer() == NULL) {
2056 char *tmp = decodedString(url);
2057 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
2059 slowprod->set("strobe", strobe);
2060 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2061 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2062 tmp = decodedString(producerid);
2063 slowprod->set("id", tmp);
2065 m_slowmotionProducers.insert(url, slowprod);
2067 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2068 trackPlaylist.consolidate_blanks(0);
2070 GenTime oldDuration = GenTime(clipLength, m_fps);
2071 GenTime newDuration = oldDuration * (oldspeed / speed);
2073 // Check that the blank space is long enough for our new duration
2074 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2075 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2078 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
2079 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2080 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2081 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
2083 // move all effects to the correct producer
2084 mltPasteEffects(clip, cut);
2086 trackPlaylist.insert_at(startPos, cut, 1);
2089 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2090 newLength = trackPlaylist.clip_length(clipIndex);
2092 mlt_service_unlock(service.get_service());
2096 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2097 m_isBlocked = false;
2101 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2103 Mlt::Service service(m_mltProducer->parent().get_service());
2104 bool success = false;
2105 Mlt::Tractor tractor(service);
2106 Mlt::Producer trackProducer(tractor.track(track));
2107 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2108 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2109 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2111 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2114 Mlt::Service clipService(clip->get_service());
2116 // if (tag.startsWith("ladspa")) tag = "ladspa";
2119 Mlt::Filter *filter = clipService.filter(ct);
2121 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2122 if (clipService.detach(*filter) == 0) success = true;
2123 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2124 } else if (updateIndex) {
2125 // Adjust the other effects index
2126 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2129 filter = clipService.filter(ct);
2131 m_isBlocked = false;
2132 if (doRefresh) refresh();
2137 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2140 Mlt::Service service(m_mltProducer->parent().get_service());
2142 Mlt::Tractor tractor(service);
2143 Mlt::Producer trackProducer(tractor.track(track));
2144 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2146 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2150 Mlt::Service clipService(clip->get_service());
2152 int duration = clip->get_playtime();
2154 // temporarily remove all effects after insert point
2155 QList <Mlt::Filter *> filtersList;
2156 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2158 Mlt::Filter *filter = clipService.filter(ct);
2160 if (QString(filter->get("kdenlive_ix")).toInt() >= filter_ix) {
2161 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
2162 filtersList.append(filter);
2163 clipService.detach(*filter);
2165 filter = clipService.filter(ct);
2169 QString tag = params.paramValue("tag");
2170 kDebug() << " / / INSERTING EFFECT: " << tag;
2171 if (tag.startsWith("ladspa")) tag = "ladspa";
2172 char *filterTag = decodedString(tag);
2173 char *filterId = decodedString(params.paramValue("id"));
2174 QHash<QString, QString>::Iterator it;
2175 QString kfr = params.paramValue("keyframes");
2177 if (!kfr.isEmpty()) {
2178 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2179 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2180 char *starttag = decodedString(params.paramValue("starttag", "start"));
2181 char *endtag = decodedString(params.paramValue("endtag", "end"));
2182 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2183 //double max = params.paramValue("max").toDouble();
2184 double min = params.paramValue("min").toDouble();
2185 double factor = params.paramValue("factor", "1").toDouble();
2186 params.removeParam("starttag");
2187 params.removeParam("endtag");
2188 params.removeParam("keyframes");
2189 params.removeParam("min");
2190 params.removeParam("max");
2191 params.removeParam("factor");
2193 for (int i = 0; i < keyFrames.size() - 1; ++i) {
2194 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2195 if (filter && filter->is_valid()) {
2196 filter->set("kdenlive_id", filterId);
2197 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2198 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2199 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2200 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2201 if (x2 == -1) x2 = duration;
2203 for (int j = 0; j < params.count(); j++) {
2204 char *name = decodedString(params.at(j).name());
2205 char *value = decodedString(params.at(j).value());
2206 filter->set(name, value);
2211 filter->set("in", x1);
2212 filter->set("out", x2);
2213 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2214 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2215 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2216 clipService.attach(*filter);
2223 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2224 if (filter && filter->is_valid())
2225 filter->set("kdenlive_id", filterId);
2227 kDebug() << "filter is NULL";
2228 m_isBlocked = false;
2232 params.removeParam("kdenlive_id");
2234 for (int j = 0; j < params.count(); j++) {
2235 char *name = decodedString(params.at(j).name());
2236 char *value = decodedString(params.at(j).value());
2237 filter->set(name, value);
2243 QString effectArgs = params.paramValue("id").section('_', 1);
2245 params.removeParam("id");
2246 params.removeParam("kdenlive_ix");
2247 params.removeParam("tag");
2248 params.removeParam("disabled");
2250 for (int j = 0; j < params.count(); j++) {
2251 effectArgs.append(' ' + params.at(j).value());
2253 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2254 char *value = decodedString(effectArgs.simplified());
2255 filter->set("effect", value);
2260 // attach filter to the clip
2261 clipService.attach(*filter);
2266 // re-add following filters
2267 for (int i = 0; i < filtersList.count(); i++) {
2268 clipService.attach(*(filtersList.at(i)));
2271 m_isBlocked = false;
2272 if (doRefresh) refresh();
2276 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2278 QString index = params.paramValue("kdenlive_ix");
2279 QString tag = params.paramValue("tag");
2281 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2282 // This is a keyframe effect, to edit it, we remove it and re-add it.
2283 mltRemoveEffect(track, position, index, false);
2284 bool success = mltAddEffect(track, position, params);
2289 Mlt::Service service(m_mltProducer->parent().get_service());
2291 Mlt::Tractor tractor(service);
2292 Mlt::Producer trackProducer(tractor.track(track));
2293 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2294 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2295 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2297 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2300 Mlt::Service clipService(clip->get_service());
2304 Mlt::Filter *filter = clipService.filter(ct);
2306 if (filter->get("kdenlive_ix") == index) {
2310 filter = clipService.filter(ct);
2314 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2315 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2317 filter = clipService.filter(ct);
2318 QList <Mlt::Filter *> filtersList;
2320 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2321 filtersList.append(filter);
2322 clipService.detach(*filter);
2324 filter = clipService.filter(ct);
2326 bool success = mltAddEffect(track, position, params);
2328 for (int i = 0; i < filtersList.count(); i++) {
2329 clipService.attach(*(filtersList.at(i)));
2332 m_isBlocked = false;
2335 mlt_service_lock(service.get_service());
2336 for (int j = 0; j < params.count(); j++) {
2337 char *name = decodedString(params.at(j).name());
2338 char *value = decodedString(params.at(j).value());
2339 filter->set(name, value);
2343 mlt_service_unlock(service.get_service());
2345 m_isBlocked = false;
2350 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2353 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2354 Mlt::Service service(m_mltProducer->parent().get_service());
2356 Mlt::Tractor tractor(service);
2357 Mlt::Producer trackProducer(tractor.track(track));
2358 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2359 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2360 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2362 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2365 Mlt::Service clipService(clip->get_service());
2369 QList <Mlt::Filter *> filtersList;
2370 Mlt::Filter *filter = clipService.filter(ct);
2372 if (newPos > oldPos) {
2374 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2375 filter->set("kdenlive_ix", newPos);
2376 filtersList.append(filter);
2377 clipService.detach(*filter);
2378 filter = clipService.filter(ct);
2379 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2380 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2382 filter = clipService.filter(ct);
2386 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2387 filtersList.append(filter);
2388 clipService.detach(*filter);
2390 filter = clipService.filter(ct);
2394 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2395 filter->set("kdenlive_ix", newPos);
2396 filtersList.append(filter);
2397 clipService.detach(*filter);
2399 filter = clipService.filter(ct);
2403 filter = clipService.filter(ct);
2405 int pos = QString(filter->get("kdenlive_ix")).toInt();
2406 if (pos >= newPos) {
2407 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2408 filtersList.append(filter);
2409 clipService.detach(*filter);
2411 filter = clipService.filter(ct);
2415 for (int i = 0; i < filtersList.count(); i++) {
2416 clipService.attach(*(filtersList.at(i)));
2419 m_isBlocked = false;
2423 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2426 Mlt::Service service(m_mltProducer->parent().get_service());
2427 Mlt::Tractor tractor(service);
2428 Mlt::Producer trackProducer(tractor.track(info.track));
2429 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2431 /* // Display playlist info
2432 kDebug()<<"//////////// BEFORE RESIZE";
2433 for (int i = 0; i < trackPlaylist.count(); i++) {
2434 int blankStart = trackPlaylist.clip_start(i);
2435 int blankDuration = trackPlaylist.clip_length(i) - 1;
2437 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2438 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2441 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2442 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2443 m_isBlocked = false;
2446 mlt_service_lock(service.get_service());
2447 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2448 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2449 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2450 int previousStart = clip->get_in();
2451 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2452 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2453 if (newDuration > clip->get_length()) {
2454 clip->parent().set("length", newDuration + 1);
2455 clip->parent().set("out", newDuration);
2456 clip->set("length", newDuration + 1);
2458 if (newDuration > clip->get_out()) {
2459 clip->parent().set_in_and_out(0, newDuration + 1);
2460 clip->set_in_and_out(0, newDuration + 1);
2463 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2464 trackPlaylist.consolidate_blanks(0);
2465 // skip to next clip
2467 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2469 // clip was made longer, trim next blank if there is one.
2470 if (clipIndex < trackPlaylist.count()) {
2471 // If this is not the last clip in playlist
2472 if (trackPlaylist.is_blank(clipIndex)) {
2473 int blankStart = trackPlaylist.clip_start(clipIndex);
2474 int blankDuration = trackPlaylist.clip_length(clipIndex);
2475 if (diff > blankDuration) {
2476 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2478 if (diff - blankDuration == 0) {
2479 trackPlaylist.remove(clipIndex);
2480 } else trackPlaylist.remove_region(blankStart, diff);
2482 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2485 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2486 trackPlaylist.consolidate_blanks(0);
2487 mlt_service_unlock(service.get_service());
2489 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2490 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2491 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2492 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2493 ItemInfo transpinfo;
2494 transpinfo.startPos = info.startPos;
2495 transpinfo.endPos = info.startPos + clipDuration;
2496 transpinfo.track = info.track;
2497 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2499 m_isBlocked = false;
2500 m_mltConsumer->set("refresh", 1);
2504 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2506 Mlt::Service service(m_mltProducer->parent().get_service());
2507 Mlt::Tractor tractor(service);
2508 Mlt::Producer trackProducer(tractor.track(track));
2511 if (blind) trackProducer.set("hide", 3);
2512 else trackProducer.set("hide", 2);
2514 trackProducer.set("hide", 1);
2516 trackProducer.set("hide", 0);
2518 tractor.multitrack()->refresh();
2524 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2526 Mlt::Service service(m_mltProducer->parent().get_service());
2527 int frameOffset = (int) diff.frames(m_fps);
2528 Mlt::Tractor tractor(service);
2529 Mlt::Producer trackProducer(tractor.track(info.track));
2530 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2531 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2532 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2535 mlt_service_lock(service.get_service());
2536 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2537 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2539 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2540 mlt_service_unlock(service.get_service());
2543 int previousStart = clip->get_in();
2545 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2547 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2548 m_isBlocked = false;
2549 mlt_service_unlock(service.get_service());
2550 m_mltConsumer->set("refresh", 1);
2554 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2556 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2557 Mlt::Service service(m_mltProducer->parent().get_service());
2558 int moveFrame = (int) diff.frames(m_fps);
2559 Mlt::Tractor tractor(service);
2560 Mlt::Producer trackProducer(tractor.track(info.track));
2561 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2562 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2563 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2566 mlt_service_lock(service.get_service());
2567 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2568 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2570 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2571 mlt_service_unlock(service.get_service());
2574 int previousStart = clip->get_in();
2576 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2578 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2579 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2580 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2582 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2583 int blankIndex = clipIndex - 1;
2584 int blankLength = trackPlaylist.clip_length(blankIndex);
2585 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2586 if (! trackPlaylist.is_blank(blankIndex)) {
2587 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2589 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2590 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2592 trackPlaylist.consolidate_blanks(0);
2593 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2594 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2595 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2596 ItemInfo transpinfo;
2597 transpinfo.startPos = info.startPos + diff;
2598 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2599 transpinfo.track = info.track;
2600 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2602 m_isBlocked = false;
2603 //m_mltConsumer->set("refresh", 1);
2604 mlt_service_unlock(service.get_service());
2605 m_mltConsumer->set("refresh", 1);
2609 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2611 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2615 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2617 if (prod == NULL || !prod->is_valid()) {
2618 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2621 kDebug() << "NEW PROD ID: " << prod->get("id");
2623 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2624 Mlt::Service service(m_mltProducer->parent().get_service());
2625 if (service.type() != tractor_type) {
2626 kWarning() << "// TRACTOR PROBLEM";
2629 mlt_service_lock(m_mltConsumer->get_service());
2631 Mlt::Tractor tractor(service);
2632 Mlt::Producer trackProducer(tractor.track(track));
2633 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2634 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2635 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2636 if (clipProducer->is_blank()) {
2637 kDebug() << "// ERROR UPDATING CLIP PROD";
2638 delete clipProducer;
2639 mlt_service_unlock(m_mltConsumer->get_service());
2643 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2645 // move all effects to the correct producer
2646 mltPasteEffects(clipProducer, clip);
2647 trackPlaylist.insert_at(pos, clip, 1);
2649 delete clipProducer;
2650 mlt_service_unlock(m_mltConsumer->get_service());
2654 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2658 Mlt::Service service(m_mltProducer->parent().get_service());
2659 if (service.type() != tractor_type) {
2660 kWarning() << "// TRACTOR PROBLEM";
2664 Mlt::Tractor tractor(service);
2665 mlt_service_lock(service.get_service());
2666 Mlt::Producer trackProducer(tractor.track(startTrack));
2667 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2668 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
2669 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2670 bool checkLength = false;
2671 if (endTrack == startTrack) {
2672 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2673 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer->is_blank()) {
2674 // error, destination is not empty
2675 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2676 delete clipProducer;
2677 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2678 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2679 mlt_service_unlock(service.get_service());
2683 trackPlaylist.consolidate_blanks(0);
2684 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2685 delete clipProducer;
2686 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2687 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2689 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2691 //mlt_service_unlock(service.get_service());
2693 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2694 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2695 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2696 // error, destination is not empty
2697 mlt_service_unlock(service.get_service());
2701 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2702 if (clipProducer->is_blank()) {
2703 // error, destination is not empty
2704 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2705 delete clipProducer;
2706 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2707 mlt_service_unlock(service.get_service());
2711 trackPlaylist.consolidate_blanks(0);
2712 destTrackPlaylist.consolidate_blanks(1);
2713 Mlt::Producer *clip;
2714 // check if we are moving a slowmotion producer
2715 QString serv = clipProducer->parent().get("mlt_service");
2716 QString currentid = clipProducer->parent().get("id");
2717 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2718 clip = clipProducer;
2721 // Special case: prod is null when using placeholder clips.
2722 // in that case, use the producer existing in playlist. Note that
2723 // it will bypass the one producer per track logic and might cause
2724 // Sound cracks if clip is moved so that it overlaps another copy of itself
2725 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
2726 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2729 // move all effects to the correct producer
2730 mltPasteEffects(clipProducer, clip);
2732 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2733 if (clip == clipProducer) {
2738 delete clipProducer;
2740 destTrackPlaylist.consolidate_blanks(0);
2741 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2742 kDebug() << "//////// moving clip transparency";
2743 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2745 if (clipIndex > trackPlaylist.count()) checkLength = true;
2746 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2749 mlt_service_unlock(service.get_service());
2750 if (checkLength) mltCheckLength(&tractor);
2753 //m_mltConsumer->set("refresh", 1);
2757 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2759 int new_in = (int)newIn.frames(m_fps);
2760 int new_out = (int)newOut.frames(m_fps) - 1;
2761 if (new_in >= new_out) return false;
2763 mlt_service serv = m_mltProducer->parent().get_service();
2765 mlt_service_lock(serv);
2766 //m_mltConsumer->set("refresh", 0);
2769 mlt_service nextservice = mlt_service_get_producer(serv);
2770 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2771 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2772 QString resource = mlt_properties_get(properties, "mlt_service");
2773 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2775 while (mlt_type == "transition") {
2776 mlt_transition tr = (mlt_transition) nextservice;
2777 int currentTrack = mlt_transition_get_b_track(tr);
2778 int currentIn = (int) mlt_transition_get_in(tr);
2779 int currentOut = (int) mlt_transition_get_out(tr);
2781 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2782 mlt_transition_set_in_and_out(tr, new_in, new_out);
2783 if (newTrack - startTrack != 0) {
2784 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2786 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2787 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2788 mlt_properties_set_int(properties, "b_track", newTrack);
2789 //kDebug() << "set new start & end :" << new_in << new_out<< "TR OFFSET: "<<trackOffset<<", TRACKS: "<<mlt_transition_get_a_track(tr)<<'x'<<mlt_transition_get_b_track(tr);
2793 nextservice = mlt_service_producer(nextservice);
2794 if (nextservice == NULL) break;
2795 properties = MLT_SERVICE_PROPERTIES(nextservice);
2796 mlt_type = mlt_properties_get(properties, "mlt_type");
2797 resource = mlt_properties_get(properties, "mlt_service");
2799 mlt_service_unlock(serv);
2802 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2806 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2808 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2810 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2811 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
2814 //mltSavePlaylist();
2817 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2819 mlt_service serv = m_mltProducer->parent().get_service();
2820 mlt_service_lock(serv);
2823 mlt_service nextservice = mlt_service_get_producer(serv);
2824 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2825 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2826 QString resource = mlt_properties_get(properties, "mlt_service");
2827 int in_pos = (int) in.frames(m_fps);
2828 int out_pos = (int) out.frames(m_fps) - 1;
2830 while (mlt_type == "transition") {
2831 mlt_transition tr = (mlt_transition) nextservice;
2832 int currentTrack = mlt_transition_get_b_track(tr);
2833 int currentBTrack = mlt_transition_get_a_track(tr);
2834 int currentIn = (int) mlt_transition_get_in(tr);
2835 int currentOut = (int) mlt_transition_get_out(tr);
2837 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2839 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2840 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2841 QMap<QString, QString>::Iterator it;
2843 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2844 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2845 // update the transition id in case it uses the same MLT service but different Kdenlive id
2846 char *tmp = decodedString(xml.attribute("id"));
2847 mlt_properties_set(transproperties, "kdenlive_id", tmp);
2849 if (currentBTrack != a_track) {
2850 mlt_properties_set_int(properties, "a_track", a_track);
2852 for (it = map.begin(); it != map.end(); ++it) {
2854 char *name = decodedString(key);
2855 char *value = decodedString(it.value());
2856 mlt_properties_set(transproperties, name, value);
2857 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2858 //filter->set("kdenlive_id", id);
2864 nextservice = mlt_service_producer(nextservice);
2865 if (nextservice == NULL) break;
2866 properties = MLT_SERVICE_PROPERTIES(nextservice);
2867 mlt_type = mlt_properties_get(properties, "mlt_type");
2868 resource = mlt_properties_get(properties, "mlt_service");
2870 mlt_service_unlock(serv);
2873 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2876 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2878 mlt_service serv = m_mltProducer->parent().get_service();
2880 mlt_service_lock(serv);
2882 Mlt::Service service(serv);
2883 Mlt::Tractor tractor(service);
2884 Mlt::Field *field = tractor.field();
2886 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2888 mlt_service nextservice = mlt_service_get_producer(serv);
2889 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2890 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2891 QString resource = mlt_properties_get(properties, "mlt_service");
2893 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2894 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2896 while (mlt_type == "transition") {
2897 mlt_transition tr = (mlt_transition) nextservice;
2898 int currentTrack = mlt_transition_get_b_track(tr);
2899 int currentIn = (int) mlt_transition_get_in(tr);
2900 int currentOut = (int) mlt_transition_get_out(tr);
2901 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2903 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2904 mlt_field_disconnect_service(field->get_field(), nextservice);
2907 nextservice = mlt_service_producer(nextservice);
2908 if (nextservice == NULL) break;
2909 properties = MLT_SERVICE_PROPERTIES(nextservice);
2910 mlt_type = mlt_properties_get(properties, "mlt_type");
2911 resource = mlt_properties_get(properties, "mlt_service");
2913 mlt_service_unlock(serv);
2916 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2919 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2921 QDomNodeList attribs = xml.elementsByTagName("parameter");
2922 QMap<QString, QString> map;
2923 for (int i = 0; i < attribs.count(); i++) {
2924 QDomElement e = attribs.item(i).toElement();
2925 QString name = e.attribute("name");
2926 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2927 map[name] = e.attribute("default");
2928 if (!e.attribute("value").isEmpty()) {
2929 map[name] = e.attribute("value");
2931 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2932 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2933 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2936 if (e.attribute("namedesc").contains(';')) {
2937 QString format = e.attribute("format");
2938 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2939 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2941 QTextStream txtNeu(&neu);
2942 if (values.size() > 0)
2943 txtNeu << (int)values[0].toDouble();
2945 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
2946 txtNeu << separators[i];
2947 txtNeu << (int)(values[i+1].toDouble());
2949 if (i < separators.size())
2950 txtNeu << separators[i];
2951 map[e.attribute("name")] = neu;
2958 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2960 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2961 Mlt::Service service(m_mltProducer->parent().get_service());
2962 Mlt::Tractor tractor(service);
2963 Mlt::Field *field = tractor.field();
2965 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2966 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2967 transition->set("transparency", id);
2968 transition->set("fill", 1);
2969 transition->set("internal_added", 237);
2970 field->plant_transition(*transition, transitiontrack, info.track);
2974 void Render::mltDeleteTransparency(int pos, int track, int id)
2976 Mlt::Service service(m_mltProducer->parent().get_service());
2977 Mlt::Tractor tractor(service);
2978 Mlt::Field *field = tractor.field();
2980 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2981 mlt_service serv = m_mltProducer->parent().get_service();
2983 mlt_service nextservice = mlt_service_get_producer(serv);
2984 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2985 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2986 QString resource = mlt_properties_get(properties, "mlt_service");
2988 while (mlt_type == "transition") {
2989 mlt_transition tr = (mlt_transition) nextservice;
2990 int currentTrack = mlt_transition_get_b_track(tr);
2991 int currentIn = (int) mlt_transition_get_in(tr);
2992 int currentOut = (int) mlt_transition_get_out(tr);
2993 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2994 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2996 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2997 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2998 mlt_field_disconnect_service(field->get_field(), nextservice);
3001 nextservice = mlt_service_producer(nextservice);
3002 if (nextservice == NULL) break;
3003 properties = MLT_SERVICE_PROPERTIES(nextservice);
3004 mlt_type = mlt_properties_get(properties, "mlt_type");
3005 resource = mlt_properties_get(properties, "mlt_service");
3007 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3010 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3012 Mlt::Service service(m_mltProducer->parent().get_service());
3013 Mlt::Tractor tractor(service);
3015 mlt_service_lock(service.get_service());
3016 m_mltConsumer->set("refresh", 0);
3019 mlt_service serv = m_mltProducer->parent().get_service();
3020 mlt_service nextservice = mlt_service_get_producer(serv);
3021 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3022 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3023 QString resource = mlt_properties_get(properties, "mlt_service");
3024 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3025 while (mlt_type == "transition") {
3026 mlt_transition tr = (mlt_transition) nextservice;
3027 int currentTrack = mlt_transition_get_b_track(tr);
3028 int currentIn = (int) mlt_transition_get_in(tr);
3029 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3030 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3031 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3032 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3033 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3034 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3037 nextservice = mlt_service_producer(nextservice);
3038 if (nextservice == NULL) break;
3039 properties = MLT_SERVICE_PROPERTIES(nextservice);
3040 mlt_type = mlt_properties_get(properties, "mlt_type");
3041 resource = mlt_properties_get(properties, "mlt_service");
3043 mlt_service_unlock(service.get_service());
3045 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3049 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3051 Mlt::Service service(m_mltProducer->parent().get_service());
3052 Mlt::Tractor tractor(service);
3054 mlt_service_lock(service.get_service());
3055 m_mltConsumer->set("refresh", 0);
3058 mlt_service serv = m_mltProducer->parent().get_service();
3059 mlt_service nextservice = mlt_service_get_producer(serv);
3060 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3061 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3062 QString resource = mlt_properties_get(properties, "mlt_service");
3064 while (mlt_type == "transition") {
3065 mlt_transition tr = (mlt_transition) nextservice;
3066 int currentTrack = mlt_transition_get_b_track(tr);
3067 int currentaTrack = mlt_transition_get_a_track(tr);
3068 int currentIn = (int) mlt_transition_get_in(tr);
3069 int currentOut = (int) mlt_transition_get_out(tr);
3070 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3071 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3072 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3073 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3074 kDebug() << "//////MOVING";
3075 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3076 if (endTrack != startTrack) {
3077 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3078 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3079 mlt_properties_set_int(properties, "b_track", endTrack);
3083 nextservice = mlt_service_producer(nextservice);
3084 if (nextservice == NULL) break;
3085 properties = MLT_SERVICE_PROPERTIES(nextservice);
3086 mlt_type = mlt_properties_get(properties, "mlt_type");
3087 resource = mlt_properties_get(properties, "mlt_service");
3090 mlt_service_unlock(service.get_service());
3091 m_mltConsumer->set("refresh", 1);
3095 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3097 if (in >= out) return false;
3098 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3099 Mlt::Service service(m_mltProducer->parent().get_service());
3101 Mlt::Tractor tractor(service);
3102 Mlt::Field *field = tractor.field();
3104 char *transId = decodedString(tag);
3105 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
3106 if (out != GenTime())
3107 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3108 QMap<QString, QString>::Iterator it;
3110 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3111 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3112 if (xml.hasAttribute("id"))
3113 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3115 for (it = args.begin(); it != args.end(); ++it) {
3117 char *name = decodedString(key);
3118 char *value = decodedString(it.value());
3119 if (it.value().isEmpty() == false) transition->set(name, value);
3120 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
3124 // attach filter to the clip
3125 field->plant_transition(*transition, a_track, b_track);
3127 if (do_refresh) refresh();
3131 void Render::mltSavePlaylist()
3133 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3134 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3135 fileConsumer.set("resource", "/tmp/playlist.mlt");
3137 Mlt::Service service(m_mltProducer->get_service());
3139 fileConsumer.connect(service);
3140 fileConsumer.start();
3143 const QList <Mlt::Producer *> Render::producersList()
3145 QList <Mlt::Producer *> prods;
3146 if (m_mltProducer == NULL) return prods;
3147 Mlt::Service service(m_mltProducer->parent().get_service());
3148 if (service.type() != tractor_type) return prods;
3149 Mlt::Tractor tractor(service);
3152 int trackNb = tractor.count();
3153 for (int t = 1; t < trackNb; t++) {
3154 Mlt::Producer *tt = tractor.track(t);
3155 Mlt::Producer trackProducer(tt);
3157 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3158 int clipNb = trackPlaylist.count();
3159 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3160 for (int i = 0; i < clipNb; i++) {
3161 Mlt::Producer *c = trackPlaylist.get_clip(i);
3162 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3164 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3165 ids.append(nprod->get("id"));
3166 prods.append(nprod);
3167 } else delete nprod;
3175 void Render::fillSlowMotionProducers()
3177 if (m_mltProducer == NULL) return;
3178 Mlt::Service service(m_mltProducer->parent().get_service());
3179 if (service.type() != tractor_type) return;
3181 Mlt::Tractor tractor(service);
3183 int trackNb = tractor.count();
3184 for (int t = 1; t < trackNb; t++) {
3185 Mlt::Producer *tt = tractor.track(t);
3186 Mlt::Producer trackProducer(tt);
3188 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3189 int clipNb = trackPlaylist.count();
3190 for (int i = 0; i < clipNb; i++) {
3191 Mlt::Producer *c = trackPlaylist.get_clip(i);
3192 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3194 QString id = nprod->get("id");
3195 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3196 // this is a slowmotion producer, add it to the list
3197 QString url = QString::fromUtf8(nprod->get("resource"));
3198 int strobe = nprod->get_int("strobe");
3199 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3200 if (!m_slowmotionProducers.contains(url)) {
3201 m_slowmotionProducers.insert(url, nprod);
3203 } else delete nprod;
3210 void Render::mltInsertTrack(int ix, bool videoTrack)
3215 Mlt::Service service(m_mltProducer->parent().get_service());
3216 mlt_service_lock(service.get_service());
3217 if (service.type() != tractor_type) {
3218 kWarning() << "// TRACTOR PROBLEM";
3222 Mlt::Tractor tractor(service);
3224 Mlt::Playlist playlist;
3225 int ct = tractor.count();
3227 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3233 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3234 tractor.set_track(playlist, pos);
3235 Mlt::Producer newProd(tractor.track(pos));
3236 if (!videoTrack) newProd.set("hide", 1);
3238 for (; pos <= ct; pos++) {
3239 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3240 tractor.set_track(*prodToMove, pos);
3241 prodToMove = prodToMove2;
3244 tractor.set_track(playlist, ix);
3245 Mlt::Producer newProd(tractor.track(ix));
3246 if (!videoTrack) newProd.set("hide", 1);
3250 mlt_service serv = m_mltProducer->parent().get_service();
3251 mlt_service nextservice = mlt_service_get_producer(serv);
3252 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3253 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3254 QString resource = mlt_properties_get(properties, "mlt_service");
3256 while (mlt_type == "transition") {
3257 if (resource != "mix") {
3258 mlt_transition tr = (mlt_transition) nextservice;
3259 int currentTrack = mlt_transition_get_b_track(tr);
3260 int currentaTrack = mlt_transition_get_a_track(tr);
3261 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3263 if (currentTrack >= ix) {
3264 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3265 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3268 nextservice = mlt_service_producer(nextservice);
3269 if (nextservice == NULL) break;
3270 properties = MLT_SERVICE_PROPERTIES(nextservice);
3271 mlt_type = mlt_properties_get(properties, "mlt_type");
3272 resource = mlt_properties_get(properties, "mlt_service");
3275 // Add audio mix transition to last track
3276 Mlt::Field *field = tractor.field();
3277 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3278 transition->set("a_track", 1);
3279 transition->set("b_track", ct);
3280 transition->set("always_active", 1);
3281 transition->set("internal_added", 237);
3282 transition->set("combine", 1);
3283 field->plant_transition(*transition, 1, ct);
3284 //mlt_service_unlock(m_mltConsumer->get_service());
3285 mlt_service_unlock(service.get_service());
3286 //tractor.multitrack()->refresh();
3287 //tractor.refresh();
3289 blockSignals(false);
3293 void Render::mltDeleteTrack(int ix)
3296 doc.setContent(sceneList(), false);
3297 int tracksCount = doc.elementsByTagName("track").count() - 1;
3298 QDomNode track = doc.elementsByTagName("track").at(ix);
3299 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3300 QDomNodeList transitions = doc.elementsByTagName("transition");
3301 for (int i = 0; i < transitions.count(); i++) {
3302 QDomElement e = transitions.at(i).toElement();
3303 QDomNodeList props = e.elementsByTagName("property");
3304 QMap <QString, QString> mappedProps;
3305 for (int j = 0; j < props.count(); j++) {
3306 QDomElement f = props.at(j).toElement();
3307 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3309 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3310 tractor.removeChild(transitions.at(i));
3312 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3313 // Transition needs to be moved
3314 int a_track = mappedProps.value("a_track").toInt();
3315 int b_track = mappedProps.value("b_track").toInt();
3316 if (a_track > 0 && a_track >= ix) a_track --;
3317 if (b_track > 0 && b_track >= ix) b_track --;
3318 for (int j = 0; j < props.count(); j++) {
3319 QDomElement f = props.at(j).toElement();
3320 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3321 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3326 tractor.removeChild(track);
3327 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3328 setSceneList(doc.toString(), m_framePosition);
3330 /* if (m_mltProducer != NULL) {
3331 Mlt::Producer parentProd(m_mltProducer->parent());
3332 if (parentProd.get_producer() != NULL) {
3333 Mlt::Service service(parentProd.get_service());
3334 if (service.type() == tractor_type) {
3335 Mlt::Tractor tractor(service);
3336 mltCheckLength(&tractor);
3343 void Render::updatePreviewSettings()
3345 kDebug() << "////// RESTARTING CONSUMER";
3346 if (!m_mltConsumer || !m_mltProducer) return;
3347 if (m_mltProducer->get_playtime() == 0) return;
3348 Mlt::Service service(m_mltProducer->parent().get_service());
3349 if (service.type() != tractor_type) return;
3351 //m_mltConsumer->set("refresh", 0);
3352 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3353 m_mltConsumer->purge();
3354 QString scene = sceneList();
3356 if (m_mltProducer) {
3357 pos = m_mltProducer->position();
3360 setSceneList(scene, pos);
3364 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3366 // Update all frame positions to the new fps value
3367 //WARNING: there are probably some effects or other that hold a frame value
3368 // as parameter and will also need to be updated here!
3370 doc.setContent(scene);
3372 double factor = new_fps / current_fps;
3373 QDomNodeList producers = doc.elementsByTagName("producer");
3374 for (int i = 0; i < producers.count(); i++) {
3375 QDomElement prod = producers.at(i).toElement();
3376 prod.removeAttribute("in");
3377 prod.removeAttribute("out");
3379 QDomNodeList props = prod.childNodes();
3380 for (int j = 0; j < props.count(); j++) {
3381 QDomElement param = props.at(j).toElement();
3382 QString paramName = param.attribute("name");
3383 if (paramName.startsWith("meta.") || paramName == "length") {
3384 prod.removeChild(props.at(j));
3390 QDomNodeList entries = doc.elementsByTagName("entry");
3391 for (int i = 0; i < entries.count(); i++) {
3392 QDomElement entry = entries.at(i).toElement();
3393 int in = entry.attribute("in").toInt();
3394 int out = entry.attribute("out").toInt();
3395 in = factor * in + 0.5;
3396 out = factor * out + 0.5;
3397 entry.setAttribute("in", in);
3398 entry.setAttribute("out", out);
3401 QDomNodeList blanks = doc.elementsByTagName("blank");
3402 for (int i = 0; i < blanks.count(); i++) {
3403 QDomElement blank = blanks.at(i).toElement();
3404 int length = blank.attribute("length").toInt();
3405 length = factor * length + 0.5;
3406 blank.setAttribute("length", QString::number(length));
3409 QDomNodeList filters = doc.elementsByTagName("filter");
3410 for (int i = 0; i < filters.count(); i++) {
3411 QDomElement filter = filters.at(i).toElement();
3412 int in = filter.attribute("in").toInt();
3413 int out = filter.attribute("out").toInt();
3414 in = factor * in + 0.5;
3415 out = factor * out + 0.5;
3416 filter.setAttribute("in", in);
3417 filter.setAttribute("out", out);
3420 QDomNodeList transitions = doc.elementsByTagName("transition");
3421 for (int i = 0; i < transitions.count(); i++) {
3422 QDomElement transition = transitions.at(i).toElement();
3423 int in = transition.attribute("in").toInt();
3424 int out = transition.attribute("out").toInt();
3425 in = factor * in + 0.5;
3426 out = factor * out + 0.5;
3427 transition.setAttribute("in", in);
3428 transition.setAttribute("out", out);
3429 QDomNodeList props = transition.childNodes();
3430 for (int j = 0; j < props.count(); j++) {
3431 QDomElement param = props.at(j).toElement();
3432 QString paramName = param.attribute("name");
3433 if (paramName == "geometry") {
3434 QString geom = param.firstChild().nodeValue();
3435 QStringList keys = geom.split(';');
3436 QStringList newKeys;
3437 for (int k = 0; k < keys.size(); ++k) {
3438 if (keys.at(k).contains('=')) {
3439 int pos = keys.at(k).section('=', 0, 0).toInt();
3440 pos = factor * pos + 0.5;
3441 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3442 } else newKeys.append(keys.at(k));
3444 param.firstChild().setNodeValue(newKeys.join(";"));
3448 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3449 int out = tractor.attribute("out").toInt();
3450 out = factor * out + 0.5;
3451 tractor.setAttribute("out", out);
3452 emit durationChanged(out);
3454 kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3455 return doc.toString();
3458 #include "renderer.moc"