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_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
120 QString mlt_type = mlt_properties_get(properties, "mlt_type");
121 QString resource = mlt_properties_get(properties, "mlt_service");
122 // Delete all transitions
123 while (mlt_type == "transition") {
124 mlt_field_disconnect_service(field->get_field(), nextservice);
125 nextservice = mlt_service_producer(nextservice);
126 if (nextservice == NULL) break;
127 properties = MLT_SERVICE_PROPERTIES(nextservice);
128 mlt_type = mlt_properties_get(properties, "mlt_type");
129 resource = mlt_properties_get(properties, "mlt_service");
132 int trackNb = tractor.count();
133 while (trackNb > 0) {
134 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
135 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
136 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
140 mlt_service_unlock(service.get_service());
143 kDebug() << "// // // CLOSE RENDERER " << m_name;
144 delete m_mltConsumer;
145 delete m_mltProducer;
151 void Render::buildConsumer()
154 m_activeProfile = KdenliveSettings::current_profile();
155 tmp = decodedString(m_activeProfile);
156 setenv("MLT_PROFILE", tmp, 1);
160 //TODO: uncomment following line when everything is clean
161 //if (m_mltProfile) delete m_mltProfile;
162 m_mltProfile = new Mlt::Profile(tmp);
165 QString videoDriver = KdenliveSettings::videodrivername();
166 if (!videoDriver.isEmpty()) {
167 if (videoDriver == "x11_noaccel") {
168 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
171 unsetenv("SDL_VIDEO_YUV_HWACCEL");
174 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
177 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_audio");
178 m_mltConsumer->set("preview_off", 1);
179 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
181 m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview");
183 m_mltConsumer->set("resize", 1);
184 m_mltConsumer->set("window_id", m_winid);
185 m_mltConsumer->set("terminate_on_pause", 1);
186 tmp = decodedString(KdenliveSettings::window_background().name());
187 m_mltConsumer->set("window_background", tmp);
190 // FIXME: the event object returned by the listen gets leaked...
191 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
192 m_mltConsumer->set("rescale", "nearest");
193 mlt_log_set_callback(kdenlive_callback);
195 QString audioDevice = KdenliveSettings::audiodevicename();
196 if (!audioDevice.isEmpty()) {
197 tmp = decodedString(audioDevice);
198 m_mltConsumer->set("audio_device", tmp);
202 if (!videoDriver.isEmpty()) {
203 tmp = decodedString(videoDriver);
204 m_mltConsumer->set("video_driver", tmp);
208 QString audioDriver = KdenliveSettings::audiodrivername();
211 // Disabled because the "auto" detected driver was sometimes wrong
212 if (audioDriver.isEmpty())
213 audioDriver = KdenliveSettings::autoaudiodrivername();
216 if (!audioDriver.isEmpty()) {
217 tmp = decodedString(audioDriver);
218 m_mltConsumer->set("audio_driver", tmp);
223 m_mltConsumer->set("progressive", 1);
224 m_mltConsumer->set("audio_buffer", 1024);
225 m_mltConsumer->set("frequency", 48000);
227 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
228 m_blackClip->set("id", "black");
232 int Render::resetProfile()
234 if (!m_mltConsumer) return 0;
235 if (m_activeProfile == KdenliveSettings::current_profile()) {
236 kDebug() << "reset to same profile, nothing to do";
239 kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile();
240 if (m_isSplitView) slotSplitView(false);
241 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
242 m_mltConsumer->purge();
243 delete m_mltConsumer;
244 m_mltConsumer = NULL;
245 QString scene = sceneList();
252 pos = m_mltProducer->position();
254 Mlt::Service service(m_mltProducer->get_service());
255 if (service.type() == tractor_type) {
256 Mlt::Tractor tractor(service);
257 int trackNb = tractor.count();
258 while (trackNb > 0) {
259 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
260 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
261 trackPlaylist.clear();
266 delete m_mltProducer;
268 m_mltProducer = NULL;
272 //kDebug() << "//RESET WITHSCENE: " << scene;
273 setSceneList(scene, pos);
275 /*char *tmp = decodedString(scene);
276 Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", tmp);
278 m_mltProducer = producer;
279 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
280 m_mltProducer->optimise();
281 m_mltProducer->set_speed(0);
284 //delete m_mltProfile;
285 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
286 //mlt_profile prof = m_mltProfile->get_profile();
287 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
288 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
289 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
290 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
292 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
297 /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */
298 void Render::seek(GenTime time)
303 m_mltProducer->seek((int)(time.frames(m_fps)));
308 char *Render::decodedString(QString str)
310 /*QCString fn = QFile::encodeName(str);
311 char *t = new char[fn.length() + 1];
312 strcpy(t, (const char *)fn);*/
314 return (char *) qstrdup(str.toUtf8().data()); //toLatin1
318 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
319 QPixmap pix(width, height);
321 mlt_image_format format = mlt_image_rgb24a;
322 uint8_t *thumb = frame->get_image(format, width, height);
323 QImage image(thumb, width, height, QImage::Format_ARGB32);
325 if (!image.isNull()) {
326 pix = pix.fromImage(image);
328 QPainter painter(&pix);
329 painter.drawRect(0, 0, width - 1, height - 1);
331 } else pix.fill(Qt::black);
335 int Render::renderWidth() const
337 return (int)(m_mltProfile->height() * m_mltProfile->dar());
340 int Render::renderHeight() const
342 return m_mltProfile->height();
345 QPixmap Render::extractFrame(int frame_position, int width, int height)
348 width = renderWidth();
349 height = renderHeight();
350 } else if (width % 2 == 1) width++;
351 QPixmap pix(width, height);
352 if (!m_mltProducer) {
356 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
359 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
363 if (url.fileName().startsWith(".all.")) { // check for slideshow
364 QString fileType = url.fileName().right(3);
366 QStringList::Iterator it;
368 QDir dir(url.directory());
370 filter << "*." + fileType;
371 filter << "*." + fileType.toUpper();
372 more = dir.entryList(filter, QDir::Files);
373 im.load(url.directory() + '/' + more.at(0));
374 } else im.load(url.path());
375 //pixmap = im.scaled(width, height);
380 QPixmap Render::getVideoThumbnail(char *profile, QString file, int frame_position, int width, int height) {
381 QPixmap pix(width, height);
382 char *tmp = decodedString(file);
383 Mlt::Profile *prof = new Mlt::Profile(profile);
384 Mlt::Producer m_producer(*prof, tmp);
386 if (m_producer.is_blank()) {
391 Mlt::Filter m_convert(*prof, "avcolour_space");
392 m_convert.set("forced", mlt_image_rgb24a);
393 m_producer.attach(m_convert);
394 m_producer.seek(frame_position);
395 Mlt::Frame * frame = m_producer.get_frame();
397 pix = frameThumbnail(frame, width, height, true);
400 if (prof) delete prof;
405 void Render::getImage(KUrl url, int frame_position, QPoint size)
407 char *tmp = decodedString(url.path());
408 Mlt::Producer m_producer(tmp);
410 if (m_producer.is_blank()) {
413 Mlt::Filter m_convert("avcolour_space");
414 m_convert.set("forced", mlt_image_rgb24a);
415 m_producer.attach(m_convert);
416 m_producer.seek(frame_position);
418 Mlt::Frame * frame = m_producer.get_frame();
421 QPixmap pix = frameThumbnail(frame, size.x(), size.y(), true);
423 emit replyGetImage(url, frame_position, pix, size.x(), size.y());
427 /* Create thumbnail for color */
428 /*void Render::getImage(int id, QString color, QPoint size)
430 QPixmap pixmap(size.x() - 2, size.y() - 2);
431 color = color.replace(0, 2, "#");
432 color = color.left(7);
433 pixmap.fill(QColor(color));
434 QPixmap result(size.x(), size.y());
435 result.fill(Qt::black);
436 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
437 emit replyGetImage(id, result, size.x(), size.y());
441 /* Create thumbnail for image */
442 /*void Render::getImage(KUrl url, QPoint size)
446 if (url.fileName().startsWith(".all.")) { // check for slideshow
447 QString fileType = url.fileName().right(3);
449 QStringList::Iterator it;
451 QDir dir( url.directory() );
452 more = dir.entryList( QDir::Files );
453 for ( it = more.begin() ; it != more.end() ; ++it ) {
454 if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) {
455 if (!im.load(url.directory() + '/' + *it))
456 kDebug()<<"++ ERROR LOADIN IMAGE: "<<url.directory() + '/' + *it;
461 else im.load(url.path());
463 //pixmap = im.smoothScale(size.x() - 2, size.y() - 2);
464 QPixmap result(size.x(), size.y());
465 result.fill(Qt::black);
466 //copyBlt(&result, 1, 1, &pixmap, 0, 0, size.x() - 2, size.y() - 2);
467 emit replyGetImage(url, 1, result, size.x(), size.y());
471 double Render::consumerRatio() const
473 if (!m_mltConsumer) return 1.0;
474 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
478 int Render::getLength()
482 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
483 return mlt_producer_get_playtime(m_mltProducer->get_producer());
488 bool Render::isValid(KUrl url)
490 char *tmp = decodedString(url.path());
491 Mlt::Producer producer(*m_mltProfile, tmp);
493 if (producer.is_blank())
499 double Render::dar() const
501 return m_mltProfile->dar();
504 void Render::slotSplitView(bool doit)
506 m_isSplitView = doit;
507 Mlt::Service service(m_mltProducer->parent().get_service());
508 Mlt::Tractor tractor(service);
509 if (service.type() != tractor_type || tractor.count() < 2) return;
510 Mlt::Field *field = tractor.field();
513 for (int i = 1; i < tractor.count() && screen < 4; i++) {
514 Mlt::Producer trackProducer(tractor.track(i));
515 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
516 if (QString(trackProducer.get("hide")).toInt() != 1) {
517 kDebug() << "// ADIDNG TRACK: " << i;
518 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
519 transition->set("mlt_service", "composite");
520 transition->set("a_track", 0);
521 transition->set("b_track", i);
522 transition->set("distort", 1);
523 transition->set("internal_added", "200");
530 tmp = "50%,0:50%x50%";
533 tmp = "0,50%:50%x50%";
537 tmp = "50%,50%:50%x50%";
540 transition->set("geometry", tmp);
541 transition->set("always_active", "1");
542 field->plant_transition(*transition, 0, i);
547 m_mltConsumer->set("refresh", 1);
549 mlt_service serv = m_mltProducer->parent().get_service();
550 mlt_service nextservice = mlt_service_get_producer(serv);
551 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
552 QString mlt_type = mlt_properties_get(properties, "mlt_type");
553 QString resource = mlt_properties_get(properties, "mlt_service");
555 while (mlt_type == "transition") {
556 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
557 if (added == "200") {
558 mlt_field_disconnect_service(field->get_field(), nextservice);
560 nextservice = mlt_service_producer(nextservice);
561 if (nextservice == NULL) break;
562 properties = MLT_SERVICE_PROPERTIES(nextservice);
563 mlt_type = mlt_properties_get(properties, "mlt_type");
564 resource = mlt_properties_get(properties, "mlt_service");
565 m_mltConsumer->set("refresh", 1);
570 void Render::getFileProperties(const QDomElement xml, const QString &clipId, bool replaceProducer)
572 KUrl url = KUrl(xml.attribute("resource", QString()));
573 Mlt::Producer *producer = NULL;
574 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
575 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
576 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
579 if (xml.attribute("type").toInt() == COLOR) {
580 char *tmp = decodedString("colour:" + xml.attribute("colour"));
581 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
583 } else if (xml.attribute("type").toInt() == TEXT) {
584 char *tmp = decodedString("kdenlivetitle:" + xml.attribute("resource"));
585 producer = new Mlt::Producer(*m_mltProfile, 0, tmp);
587 if (xml.hasAttribute("xmldata")) {
588 char *tmp = decodedString(xml.attribute("xmldata"));
589 producer->set("xmldata", tmp);
592 } else if (url.isEmpty()) {
594 QDomElement mlt = doc.createElement("mlt");
595 QDomElement play = doc.createElement("playlist");
596 doc.appendChild(mlt);
597 mlt.appendChild(play);
598 play.appendChild(doc.importNode(xml, true));
599 char *tmp = decodedString(doc.toString());
600 producer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
603 char *tmp = decodedString(url.path());
604 producer = new Mlt::Producer(*m_mltProfile, tmp);
608 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
609 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
610 emit removeInvalidClip(clipId, replaceProducer);
615 if (xml.hasAttribute("force_aspect_ratio")) {
616 double aspect = xml.attribute("force_aspect_ratio").toDouble();
617 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
619 if (xml.hasAttribute("threads")) {
620 int threads = xml.attribute("threads").toInt();
621 if (threads != 1) producer->set("threads", threads);
623 if (xml.hasAttribute("video_index")) {
624 int vindex = xml.attribute("video_index").toInt();
625 if (vindex != 0) producer->set("video_index", vindex);
627 if (xml.hasAttribute("audio_index")) {
628 int aindex = xml.attribute("audio_index").toInt();
629 if (aindex != 0) producer->set("audio_index", aindex);
632 if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
634 char *tmp = decodedString(clipId);
635 producer->set("id", tmp);
638 if (!replaceProducer && xml.hasAttribute("file_hash")) {
639 // Clip already has all properties
640 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
645 int width = (int)(height * m_mltProfile->dar());
646 QMap < QString, QString > filePropertyMap;
647 QMap < QString, QString > metadataPropertyMap;
649 int frameNumber = xml.attribute("thumbnail", "0").toInt();
650 if (frameNumber != 0) producer->seek(frameNumber);
652 filePropertyMap["duration"] = QString::number(producer->get_playtime());
653 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
655 Mlt::Frame *frame = producer->get_frame();
657 if (xml.attribute("type").toInt() == SLIDESHOW) {
658 if (xml.hasAttribute("ttl")) producer->set("ttl", xml.attribute("ttl").toInt());
659 if (xml.attribute("fade") == "1") {
660 // user wants a fade effect to slideshow
661 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
662 if (filter && filter->is_valid()) {
663 if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1);
664 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt());
665 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
666 char *tmp = decodedString(xml.attribute("luma_file"));
667 filter->set("luma.resource", tmp);
669 if (xml.hasAttribute("softness")) {
670 int soft = xml.attribute("softness").toInt();
671 filter->set("luma.softness", (double) soft / 100.0);
674 Mlt::Service clipService(producer->get_service());
675 clipService.attach(*filter);
681 filePropertyMap["fps"] = producer->get("source_fps");
683 if (frame && frame->is_valid()) {
684 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
685 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
686 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
687 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
689 if (frame->get_int("test_image") == 0) {
690 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
691 filePropertyMap["type"] = "playlist";
692 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
693 } else if (frame->get_int("test_audio") == 0)
694 filePropertyMap["type"] = "av";
696 filePropertyMap["type"] = "video";
698 mlt_image_format format = mlt_image_rgb24a;
699 int frame_width = width;
700 int frame_height = height;
701 QPixmap pix(width, height);
702 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
703 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32);
705 if (!image.isNull()) {
706 pix = QPixmap::fromImage(image.rgbSwapped());
710 emit replyGetImage(clipId, pix);
712 } else if (frame->get_int("test_audio") == 0) {
713 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height));
714 emit replyGetImage(clipId, pixmap);
715 filePropertyMap["type"] = "audio";
719 // Retrieve audio / video codec name
723 if (producer->get_int("video_index") > -1) {
724 /*if (context->duration == AV_NOPTS_VALUE) {
725 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
726 emit removeInvalidClip(clipId);
730 // Get the video_index
731 int default_video = producer->get_int("video_index");
733 int default_audio = producer->get_int("audio_index");
736 // Find maximum stream index values
737 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
738 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
739 QString type = producer->get(property);
742 else if (type == "audio")
745 filePropertyMap["default_video"] = QString::number(default_video);
746 filePropertyMap["video_max"] = QString::number(video_max);
747 filePropertyMap["default_audio"] = QString::number(default_audio);
748 filePropertyMap["audio_max"] = QString::number(audio_max);
750 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
751 if (producer->get(property)) {
752 filePropertyMap["videocodec"] = producer->get(property);
754 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
755 if (producer->get(property))
756 filePropertyMap["videocodec"] = producer->get(property);
759 if (KdenliveSettings::dropbframes()) {
760 kDebug() << "// LOOKING FOR H264 on: " << default_video;
761 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
762 kDebug() << "PROP: " << property << " = " << producer->get(property);
763 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
764 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
765 producer->set("skip_loop_filter", "all");
766 producer->set("skip_frame", "bidir");
770 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
771 if (producer->get_int("audio_index") > -1) {
772 // Get the audio_index
773 int index = producer->get_int("audio_index");
775 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
776 if (producer->get(property)) {
777 filePropertyMap["audiocodec"] = producer->get(property);
779 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
780 if (producer->get(property))
781 filePropertyMap["audiocodec"] = producer->get(property);
786 Mlt::Properties metadata;
787 metadata.pass_values(*producer, "meta.attr.");
788 int count = metadata.count();
789 for (int i = 0; i < count; i ++) {
790 QString name = metadata.get_name(i);
791 QString value = QString::fromUtf8(metadata.get(i));
792 if (name.endsWith("markup") && !value.isEmpty())
793 metadataPropertyMap[ name.section('.', 0, -2)] = value;
796 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
797 kDebug() << "REquested fuile info for: " << url.path();
799 // FIXME: should delete this to avoid a leak...
804 /** Create the producer from the MLT XML QDomDocument */
806 void Render::initSceneList()
808 kDebug() << "-------- INIT SCENE LIST ------_";
810 QDomElement mlt = doc.createElement("mlt");
811 doc.appendChild(mlt);
812 QDomElement prod = doc.createElement("producer");
813 prod.setAttribute("resource", "colour");
814 prod.setAttribute("colour", "red");
815 prod.setAttribute("id", "black");
816 prod.setAttribute("in", "0");
817 prod.setAttribute("out", "0");
819 QDomElement tractor = doc.createElement("tractor");
820 QDomElement multitrack = doc.createElement("multitrack");
822 QDomElement playlist1 = doc.createElement("playlist");
823 playlist1.appendChild(prod);
824 multitrack.appendChild(playlist1);
825 QDomElement playlist2 = doc.createElement("playlist");
826 multitrack.appendChild(playlist2);
827 QDomElement playlist3 = doc.createElement("playlist");
828 multitrack.appendChild(playlist3);
829 QDomElement playlist4 = doc.createElement("playlist");
830 multitrack.appendChild(playlist4);
831 QDomElement playlist5 = doc.createElement("playlist");
832 multitrack.appendChild(playlist5);
833 tractor.appendChild(multitrack);
834 mlt.appendChild(tractor);
835 // kDebug()<<doc.toString();
837 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
838 setSceneList(doc, 0);
844 /** Create the producer from the MLT XML QDomDocument */
845 int Render::setProducer(Mlt::Producer *producer, int position)
847 if (m_winid == -1) return -1;
850 m_mltConsumer->stop();
853 m_mltConsumer->purge();
857 m_mltProducer->set_speed(0);
858 delete m_mltProducer;
859 m_mltProducer = NULL;
863 m_mltProducer = new Mlt::Producer(producer->get_producer());
864 } else m_mltProducer = m_blackClip->cut(0, 50);
865 /*if (KdenliveSettings::dropbframes()) {
866 m_mltProducer->set("skip_loop_filter", "all");
867 m_mltProducer->set("skip_frame", "bidir");
869 if (!m_mltProducer || !m_mltProducer->is_valid()) {
870 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
874 m_fps = m_mltProducer->get_fps();
875 int error = connectPlaylist();
876 if (position != -1) {
877 m_mltProducer->seek(position);
878 emit rendererPosition(position);
886 /** Create the producer from the MLT XML QDomDocument */
887 int Render::setSceneList(QDomDocument list, int position)
889 return setSceneList(list.toString(), position);
892 /** Create the producer from the MLT XML QDomDocument */
893 int Render::setSceneList(QString playlist, int position)
895 if (m_winid == -1) return -1;
899 //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist;
901 if (m_mltConsumer == NULL) {
902 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
907 if (!m_mltConsumer->is_stopped()) {
908 m_mltConsumer->stop();
910 m_mltConsumer->set("refresh", 0);
913 m_mltProducer->set_speed(0);
914 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
917 Mlt::Service service(m_mltProducer->parent().get_service());
918 mlt_service_lock(service.get_service());
920 if (service.type() == tractor_type) {
921 Mlt::Tractor tractor(service);
922 Mlt::Field *field = tractor.field();
923 mlt_service nextservice = mlt_service_get_producer(service.get_service());
924 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
925 QString mlt_type = mlt_properties_get(properties, "mlt_type");
926 QString resource = mlt_properties_get(properties, "mlt_service");
927 // Delete all transitions
928 while (mlt_type == "transition") {
929 mlt_field_disconnect_service(field->get_field(), nextservice);
930 nextservice = mlt_service_producer(nextservice);
931 if (nextservice == NULL) break;
932 properties = MLT_SERVICE_PROPERTIES(nextservice);
933 mlt_type = mlt_properties_get(properties, "mlt_type");
934 resource = mlt_properties_get(properties, "mlt_service");
937 int trackNb = tractor.count();
938 while (trackNb > 0) {
939 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
940 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
941 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
945 mlt_service_unlock(service.get_service());
947 qDeleteAll(m_slowmotionProducers.values());
948 m_slowmotionProducers.clear();
950 delete m_mltProducer;
951 m_mltProducer = NULL;
956 char *tmp = decodedString(playlist);
957 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", tmp);
959 if (!m_mltProducer || !m_mltProducer->is_valid()) {
960 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp;
961 m_mltProducer = m_blackClip->cut(0, 50);
965 m_mltProducer->optimise();
967 /*if (KdenliveSettings::osdtimecode()) {
968 // Attach filter for on screen display of timecode
970 QString attr = "attr_check";
971 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
972 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
973 mlt_producer_attach( m_mltProducer->get_producer(), filter );
974 mlt_filter_close( filter );
976 m_osdInfo = new Mlt::Filter("data_show");
977 tmp = decodedString(m_osdProfile);
978 m_osdInfo->set("resource", tmp);
980 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
981 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
982 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
983 m_osdInfo->set("dynamic", "1");
985 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
987 m_osdInfo->set("dynamic", "0");
990 m_fps = m_mltProducer->get_fps();
992 // Seek to correct place after opening project.
993 m_mltProducer->seek(position);
996 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
997 error = connectPlaylist();
998 fillSlowMotionProducers();
1000 m_isBlocked = false;
1001 blockSignals(false);
1002 emit refreshDocumentProducers();
1004 //kDebug()<<"// SETSCN LST, POS: "<<position;
1005 //if (position != 0) emit rendererPosition(position);
1008 /** Create the producer from the MLT XML QDomDocument */
1009 const QString Render::sceneList()
1012 Mlt::Consumer xmlConsumer(*m_mltProfile , "xml:kdenlive_playlist");
1013 m_mltProducer->optimise();
1014 xmlConsumer.set("terminate_on_pause", 1);
1015 Mlt::Producer prod(m_mltProducer->get_producer());
1016 bool split = m_isSplitView;
1017 if (split) slotSplitView(false);
1018 xmlConsumer.connect(prod);
1019 xmlConsumer.start();
1020 while (!xmlConsumer.is_stopped()) {}
1021 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
1022 if (split) slotSplitView(true);
1026 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
1030 doc.setContent(sceneList(), false);
1031 if (!kdenliveData.isNull()) {
1032 // add Kdenlive specific tags
1033 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
1034 mlt.appendChild(doc.importNode(kdenliveData, true));
1036 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1037 kWarning() << "////// ERROR writing to file: " << path;
1040 file.write(doc.toString().toUtf8());
1041 if (file.error() != QFile::NoError) {
1050 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1052 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1053 char *tmppath = decodedString("xml:" + url.path());
1054 Mlt::Consumer xmlConsumer(*m_mltProfile , tmppath);
1055 m_mltProducer->optimise();
1057 xmlConsumer.set("terminate_on_pause", 1);
1058 if (m_name == "clip") {
1059 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1060 tmppath = decodedString(desc);
1062 list.insert_at(0, prod, 0);
1064 list.set("title", tmppath);
1066 xmlConsumer.connect(list);
1069 //TODO: not working yet, save zone from timeline
1070 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1071 /* Mlt::Service service(p1->parent().get_service());
1072 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1074 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1075 tmppath = decodedString(desc);
1076 //prod->set("title", tmppath);
1078 xmlConsumer.connect(*p1); //list);
1081 xmlConsumer.start();
1084 double Render::fps() const
1089 int Render::connectPlaylist()
1091 if (!m_mltConsumer) return -1;
1092 //m_mltConsumer->set("refresh", "0");
1093 m_mltConsumer->connect(*m_mltProducer);
1094 m_mltProducer->set_speed(0);
1095 if (m_mltConsumer->start() == -1) {
1096 // ARGH CONSUMER BROKEN!!!!
1097 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."));
1098 emit blockMonitors();
1099 delete m_mltProducer;
1100 m_mltProducer = NULL;
1103 emit durationChanged(m_mltProducer->get_playtime());
1108 void Render::refreshDisplay()
1111 if (!m_mltProducer) return;
1112 //m_mltConsumer->set("refresh", 0);
1114 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1115 /*if (KdenliveSettings::osdtimecode()) {
1116 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1117 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1118 m_osdInfo->set("dynamic", "1");
1119 m_mltProducer->attach(*m_osdInfo);
1122 m_mltProducer->detach(*m_osdInfo);
1123 m_osdInfo->set("dynamic", "0");
1128 void Render::setVolume(double /*volume*/)
1130 if (!m_mltConsumer || !m_mltProducer) return;
1132 m_mltConsumer->set("refresh", 0);
1133 // Attach filter for on screen display of timecode
1134 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1135 mlt_properties_set_double( properties, "meta.volume", volume );
1136 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1137 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1139 if (!KdenliveSettings::osdtimecode()) {
1140 m_mltProducer->detach(*m_osdInfo);
1141 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1142 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1145 //m_osdTimer->setSingleShot(2500);
1148 void Render::slotOsdTimeout()
1150 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1151 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1152 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1153 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1157 void Render::start()
1159 kDebug() << "----- STARTING MONITOR: " << m_name;
1160 if (m_winid == -1) {
1161 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1164 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1165 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1166 if (m_mltConsumer->start() == -1) {
1167 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."));
1168 emit blockMonitors();
1169 delete m_mltProducer;
1170 m_mltProducer = NULL;
1172 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1173 m_isBlocked = false;
1177 m_isBlocked = false;
1182 if (m_mltProducer == NULL) return;
1183 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1184 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1186 //m_mltConsumer->set("refresh", 0);
1187 m_mltConsumer->stop();
1188 // delete m_mltConsumer;
1189 // m_mltConsumer = NULL;
1191 kDebug() << "///////////// RENDER STOP2-------";
1194 if (m_mltProducer) {
1195 if (m_isZoneMode) resetZoneMode();
1196 m_mltProducer->set_speed(0.0);
1197 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1198 //kDebug() << m_mltProducer->get_length();
1200 kDebug() << "///////////// RENDER STOP3-------";
1203 void Render::stop(const GenTime & startTime)
1206 kDebug() << "///////////// RENDER STOP-------2";
1207 if (m_mltProducer) {
1208 if (m_isZoneMode) resetZoneMode();
1209 m_mltProducer->set_speed(0.0);
1210 m_mltProducer->seek((int) startTime.frames(m_fps));
1212 m_mltConsumer->purge();
1215 void Render::pause()
1217 if (!m_mltProducer || !m_mltConsumer)
1219 if (m_mltProducer->get_speed() == 0.0) return;
1220 if (m_isZoneMode) resetZoneMode();
1222 m_mltConsumer->set("refresh", 0);
1223 m_mltProducer->set_speed(0.0);
1224 emit rendererPosition(m_framePosition);
1225 m_mltProducer->seek(m_framePosition);
1226 m_mltConsumer->purge();
1229 void Render::switchPlay()
1231 if (!m_mltProducer || !m_mltConsumer)
1233 if (m_isZoneMode) resetZoneMode();
1234 if (m_mltProducer->get_speed() == 0.0) {
1235 m_isBlocked = false;
1236 m_mltProducer->set_speed(1.0);
1237 m_mltConsumer->set("refresh", 1);
1240 m_mltConsumer->set("refresh", 0);
1241 m_mltProducer->set_speed(0.0);
1242 emit rendererPosition(m_framePosition);
1243 m_mltProducer->seek(m_framePosition);
1244 m_mltConsumer->purge();
1245 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1246 //m_mltConsumer->set("refresh", 0);
1247 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1248 m_mltProducer->set_speed(0);
1249 m_mltProducer->seek( position );
1250 //m_mltProducer->seek((int) m_framePosition);
1251 m_isBlocked = false;*/
1253 /*if (speed == 0.0) {
1254 m_mltProducer->seek((int) m_framePosition + 1);
1255 m_mltConsumer->purge();
1260 void Render::play(double speed)
1264 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1265 m_isBlocked = false;
1266 m_mltProducer->set_speed(speed);
1267 /*if (speed == 0.0) {
1268 m_mltProducer->seek((int) m_framePosition + 1);
1269 m_mltConsumer->purge();
1274 void Render::play(const GenTime & startTime)
1276 if (!m_mltProducer || !m_mltConsumer)
1278 m_isBlocked = false;
1279 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1280 m_mltProducer->set_speed(1.0);
1281 m_mltConsumer->set("refresh", 1);
1284 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1286 if (!m_mltProducer || !m_mltConsumer)
1288 //m_mltProducer->set("eof", "loop");
1289 m_isLoopMode = true;
1290 m_loopStart = startTime;
1291 playZone(startTime, stopTime);
1294 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1296 if (!m_mltProducer || !m_mltConsumer)
1298 m_isBlocked = false;
1299 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1300 m_mltProducer->set("out", stopTime.frames(m_fps));
1301 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1302 m_mltProducer->set_speed(1.0);
1303 m_mltConsumer->set("refresh", 1);
1304 m_isZoneMode = true;
1307 void Render::resetZoneMode()
1309 if (!m_isZoneMode && !m_isLoopMode) return;
1310 m_mltProducer->set("out", m_originalOut);
1311 //m_mltProducer->set("eof", "pause");
1312 m_isZoneMode = false;
1313 m_isLoopMode = false;
1316 void Render::seekToFrame(int pos)
1318 //kDebug()<<" ********* RENDER SEEK TO POS";
1321 m_isBlocked = false;
1323 m_mltProducer->seek(pos);
1327 void Render::seekToFrameDiff(int diff)
1329 //kDebug()<<" ********* RENDER SEEK TO POS";
1332 m_isBlocked = false;
1334 m_mltProducer->seek(m_mltProducer->position() + diff);
1338 void Render::doRefresh()
1340 // Use a Timer so that we don't refresh too much
1341 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1344 void Render::refresh()
1346 if (!m_mltProducer || m_isBlocked)
1348 if (m_mltConsumer) {
1349 m_mltConsumer->set("refresh", 1);
1353 void Render::setDropFrames(bool show)
1355 if (m_mltConsumer) {
1357 if (show == false) dropFrames = 0;
1358 m_mltConsumer->stop();
1359 m_mltConsumer->set("play.real_time", dropFrames);
1360 if (m_mltConsumer->start() == -1) {
1361 emit blockMonitors();
1362 delete m_mltProducer;
1363 m_mltProducer = NULL;
1369 double Render::playSpeed()
1371 if (m_mltProducer) return m_mltProducer->get_speed();
1375 GenTime Render::seekPosition() const
1377 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1378 else return GenTime();
1381 int Render::seekFramePosition() const
1383 if (m_mltProducer) return (int) m_mltProducer->position();
1387 const QString & Render::rendererName() const
1393 void Render::emitFrameNumber(double position)
1395 m_framePosition = position;
1396 emit rendererPosition((int) position);
1397 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId));
1400 void Render::emitConsumerStopped()
1402 // This is used to know when the playing stopped
1403 if (m_mltProducer) {
1404 double pos = m_mltProducer->position();
1405 if (m_isLoopMode) play(m_loopStart);
1406 else if (m_isZoneMode) resetZoneMode();
1407 emit rendererStopped((int) pos);
1408 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1409 //new QCustomEvent(10002));
1415 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1417 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1421 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1423 if (!m_mltProducer) {
1424 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1428 //int height = 1080;//KdenliveSettings::defaultheight();
1429 //int width = 1940; //KdenliveSettings::displaywidth();
1431 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1433 QPixmap pix(width, height);
1434 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1435 m_convert.set("forced", mlt_image_rgb24a);
1436 m_mltProducer->attach(m_convert);
1437 Mlt::Frame * frame = m_mltProducer->get_frame();
1438 m_mltProducer->detach(m_convert);
1440 pix = frameThumbnail(frame, width, height);
1443 pix.save(url.path(), "PNG");
1444 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1448 void Render::showFrame(Mlt::Frame& frame)
1450 mlt_image_format format = mlt_image_rgb24a;
1453 const uchar* image = frame.get_image(format, width, height);
1454 QImage qimage(width, height, QImage::Format_ARGB32);
1455 memcpy(qimage.scanLine(0), image, width * height * 4);
1456 emit showImageSignal(qimage);
1460 /** MLT PLAYLIST DIRECT MANIPULATON **/
1463 void Render::mltCheckLength(Mlt::Tractor *tractor)
1465 //kDebug()<<"checking track length: "<<track<<"..........";
1467 int trackNb = tractor->count();
1471 Mlt::Producer trackProducer(tractor->track(0));
1472 duration = trackProducer.get_playtime() - 1;
1473 m_mltProducer->set("out", duration);
1474 emit durationChanged(duration);
1477 while (trackNb > 1) {
1478 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1479 trackDuration = trackProducer.get_playtime() - 1;
1480 //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1481 if (trackDuration > duration) duration = trackDuration;
1485 Mlt::Producer blackTrackProducer(tractor->track(0));
1487 if (blackTrackProducer.get_playtime() - 1 != duration) {
1488 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1489 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1490 if (blackclip && blackclip->is_blank()) {
1495 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1496 blackTrackPlaylist.clear();
1497 m_blackClip->set("length", duration);
1498 m_blackClip->set("out", duration - 1);
1499 blackclip = m_blackClip->cut(0, duration - 1);
1500 blackTrackPlaylist.insert_at(0, blackclip, 1);
1502 if (duration > blackclip->parent().get_length()) {
1503 blackclip->parent().set("length", duration);
1504 blackclip->parent().set("out", duration - 1);
1505 blackclip->set("length", duration);
1507 blackTrackPlaylist.resize_clip(0, 0, duration - 1);
1511 m_mltProducer->set("out", duration);
1512 emit durationChanged(duration);
1516 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1518 if (m_mltProducer == NULL) {
1519 kDebug() << "PLAYLIST NOT INITIALISED //////";
1522 Mlt::Producer parentProd(m_mltProducer->parent());
1523 if (parentProd.get_producer() == NULL) {
1524 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1528 Mlt::Service service(parentProd.get_service());
1529 if (service.type() != tractor_type) {
1530 kWarning() << "// TRACTOR PROBLEM";
1533 Mlt::Tractor tractor(service);
1534 if (info.track > tractor.count() - 1) {
1535 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1538 mlt_service_lock(service.get_service());
1539 Mlt::Producer trackProducer(tractor.track(info.track));
1540 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1541 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1543 if (element.attribute("speed", "1.0").toDouble() != 1.0 || element.attribute("strobe", "1").toInt() > 1) {
1544 // We want a slowmotion producer
1545 double speed = element.attribute("speed", "1.0").toDouble();
1546 int strobe = element.attribute("strobe", "1").toInt();
1547 QString url = QString::fromUtf8(prod->get("resource"));
1548 url.append('?' + QString::number(speed));
1549 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1550 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1551 if (!slowprod || slowprod->get_producer() == NULL) {
1552 char *tmp = decodedString(url);
1553 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1554 if (strobe > 1) slowprod->set("strobe", strobe);
1556 QString id = prod->get("id");
1557 if (id.contains('_')) id = id.section('_', 0, 0);
1558 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1559 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1560 tmp = decodedString(producerid);
1561 slowprod->set("id", tmp);
1563 m_slowmotionProducers.insert(url, slowprod);
1568 Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
1569 int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), clip, 1);
1571 /*if (QString(prod->get("transparency")).toInt() == 1)
1572 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1574 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1575 mlt_service_unlock(service.get_service());
1576 /*tractor.multitrack()->refresh();
1577 tractor.refresh();*/
1582 void Render::mltCutClip(int track, GenTime position)
1587 Mlt::Service service(m_mltProducer->parent().get_service());
1588 if (service.type() != tractor_type) {
1589 kWarning() << "// TRACTOR PROBLEM";
1593 Mlt::Tractor tractor(service);
1594 Mlt::Producer trackProducer(tractor.track(track));
1595 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1598 /* // Display playlist info
1599 kDebug()<<"//////////// BEFORE";
1600 for (int i = 0; i < trackPlaylist.count(); i++) {
1601 int blankStart = trackPlaylist.clip_start(i);
1602 int blankDuration = trackPlaylist.clip_length(i) - 1;
1604 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1605 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1608 int cutPos = (int) position.frames(m_fps);
1610 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1611 if (trackPlaylist.is_blank(clipIndex)) {
1612 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1613 m_isBlocked = false;
1616 mlt_service_lock(service.get_service());
1617 int clipStart = trackPlaylist.clip_start(clipIndex);
1618 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1619 mlt_service_unlock(service.get_service());
1621 // duplicate effects
1622 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1623 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1625 if (original == NULL || clip == NULL) {
1626 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1628 Mlt::Service clipService(original->get_service());
1629 Mlt::Service dupService(clip->get_service());
1633 Mlt::Filter *filter = clipService.filter(ct);
1635 // Only duplicate Kdenlive filters, and skip the fade in effects
1636 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1637 // looks like there is no easy way to duplicate a filter,
1638 // so we will create a new one and duplicate its properties
1639 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1640 if (dup && dup->is_valid()) {
1641 Mlt::Properties entries(filter->get_properties());
1642 for (int i = 0; i < entries.count(); i++) {
1643 dup->set(entries.get_name(i), entries.get(i));
1645 dupService.attach(*dup);
1649 filter = clipService.filter(ct);
1652 /* // Display playlist info
1653 kDebug()<<"//////////// AFTER";
1654 for (int i = 0; i < trackPlaylist.count(); i++) {
1655 int blankStart = trackPlaylist.clip_start(i);
1656 int blankDuration = trackPlaylist.clip_length(i) - 1;
1658 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1659 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1662 m_isBlocked = false;
1665 void Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1668 mltRemoveClip(info.track, info.startPos);
1669 mltInsertClip(info, element, prod);
1673 bool Render::mltRemoveClip(int track, GenTime position)
1675 Mlt::Service service(m_mltProducer->parent().get_service());
1676 if (service.type() != tractor_type) {
1677 kWarning() << "// TRACTOR PROBLEM";
1681 Mlt::Tractor tractor(service);
1682 mlt_service_lock(service.get_service());
1683 Mlt::Producer trackProducer(tractor.track(track));
1684 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1685 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1687 // Display playlist info
1688 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1689 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1690 int blankStart = trackPlaylist.clip_start(i);
1691 int blankDuration = trackPlaylist.clip_length(i) - 1;
1693 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1694 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1696 if (trackPlaylist.is_blank(clipIndex)) {
1697 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1698 mlt_service_unlock(service.get_service());
1701 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1703 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1704 if (clip) delete clip;
1705 trackPlaylist.consolidate_blanks(0);
1706 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1707 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1709 /* // Display playlist info
1710 kDebug()<<"//// AFTER";
1711 for (int i = 0; i < trackPlaylist.count(); i++) {
1712 int blankStart = trackPlaylist.clip_start(i);
1713 int blankDuration = trackPlaylist.clip_length(i) - 1;
1715 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1716 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1718 mlt_service_unlock(service.get_service());
1719 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1720 m_isBlocked = false;
1724 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1726 if (!m_mltProducer) {
1727 kDebug() << "PLAYLIST NOT INITIALISED //////";
1730 Mlt::Producer parentProd(m_mltProducer->parent());
1731 if (parentProd.get_producer() == NULL) {
1732 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1736 Mlt::Service service(parentProd.get_service());
1737 Mlt::Tractor tractor(service);
1738 int insertPos = pos.frames(m_fps);
1740 Mlt::Producer trackProducer(tractor.track(track));
1741 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1742 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1743 if (!trackPlaylist.is_blank(clipIndex)) return -1;
1744 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1745 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1748 int Render::mltTrackDuration(int track)
1750 if (!m_mltProducer) {
1751 kDebug() << "PLAYLIST NOT INITIALISED //////";
1754 Mlt::Producer parentProd(m_mltProducer->parent());
1755 if (parentProd.get_producer() == NULL) {
1756 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1760 Mlt::Service service(parentProd.get_service());
1761 Mlt::Tractor tractor(service);
1763 Mlt::Producer trackProducer(tractor.track(track));
1764 return trackProducer.get_playtime() - 1;
1767 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
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 //////";
1778 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1779 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1781 Mlt::Service service(parentProd.get_service());
1782 Mlt::Tractor tractor(service);
1783 mlt_service_lock(service.get_service());
1784 int diff = duration.frames(m_fps);
1785 int offset = timeOffset.frames(m_fps);
1789 // insert space in one track only
1790 Mlt::Producer trackProducer(tractor.track(track));
1791 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1792 insertPos = trackClipStartList.value(track);
1793 if (insertPos != -1) {
1794 insertPos += offset;
1795 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1797 trackPlaylist.insert_blank(clipIndex, diff - 1);
1799 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1800 if (!trackPlaylist.is_blank(clipIndex)) {
1801 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1803 int position = trackPlaylist.clip_start(clipIndex);
1804 int blankDuration = trackPlaylist.clip_length(clipIndex);
1806 if (blankDuration - diff == 0) {
1807 trackPlaylist.remove(clipIndex);
1808 } else trackPlaylist.remove_region(position, diff);
1810 trackPlaylist.consolidate_blanks(0);
1812 // now move transitions
1813 mlt_service serv = m_mltProducer->parent().get_service();
1814 mlt_service nextservice = mlt_service_get_producer(serv);
1815 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1816 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1817 QString resource = mlt_properties_get(properties, "mlt_service");
1819 while (mlt_type == "transition") {
1820 mlt_transition tr = (mlt_transition) nextservice;
1821 int currentTrack = mlt_transition_get_b_track(tr);
1822 int currentIn = (int) mlt_transition_get_in(tr);
1823 int currentOut = (int) mlt_transition_get_out(tr);
1824 insertPos = trackTransitionStartList.value(track);
1825 if (insertPos != -1) {
1826 insertPos += offset;
1827 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1828 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1831 nextservice = mlt_service_producer(nextservice);
1832 if (nextservice == NULL) break;
1833 properties = MLT_SERVICE_PROPERTIES(nextservice);
1834 mlt_type = mlt_properties_get(properties, "mlt_type");
1835 resource = mlt_properties_get(properties, "mlt_service");
1838 int trackNb = tractor.count();
1839 while (trackNb > 1) {
1840 Mlt::Producer trackProducer(tractor.track(trackNb - 1));
1841 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1844 //int clipNb = trackPlaylist.count();
1845 insertPos = trackClipStartList.value(trackNb - 1);
1846 if (insertPos != -1) {
1847 insertPos += offset;
1849 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1850 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1851 for (int i = 0; i < clipNb; i++) {
1852 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1853 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1854 kDebug()<<"-------------";
1856 kDebug()<<"END-------------";*/
1859 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1861 trackPlaylist.insert_blank(clipIndex, diff - 1);
1863 if (!trackPlaylist.is_blank(clipIndex)) {
1866 if (!trackPlaylist.is_blank(clipIndex)) {
1867 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1869 int position = trackPlaylist.clip_start(clipIndex);
1870 int blankDuration = trackPlaylist.clip_length(clipIndex);
1871 if (diff + blankDuration == 0) {
1872 trackPlaylist.remove(clipIndex);
1873 } else trackPlaylist.remove_region(position, - diff);
1875 trackPlaylist.consolidate_blanks(0);
1879 // now move transitions
1880 mlt_service serv = m_mltProducer->parent().get_service();
1881 mlt_service nextservice = mlt_service_get_producer(serv);
1882 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1883 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1884 QString resource = mlt_properties_get(properties, "mlt_service");
1886 while (mlt_type == "transition") {
1887 mlt_transition tr = (mlt_transition) nextservice;
1888 int currentIn = (int) mlt_transition_get_in(tr);
1889 int currentOut = (int) mlt_transition_get_out(tr);
1890 int currentTrack = mlt_transition_get_b_track(tr);
1891 insertPos = trackTransitionStartList.value(currentTrack);
1892 if (insertPos != -1) {
1893 insertPos += offset;
1894 if (currentOut > insertPos && resource != "mix") {
1895 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1898 nextservice = mlt_service_producer(nextservice);
1899 if (nextservice == NULL) break;
1900 properties = MLT_SERVICE_PROPERTIES(nextservice);
1901 mlt_type = mlt_properties_get(properties, "mlt_type");
1902 resource = mlt_properties_get(properties, "mlt_service");
1905 mlt_service_unlock(service.get_service());
1906 mltCheckLength(&tractor);
1907 m_mltConsumer->set("refresh", 1);
1911 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1913 Mlt::Service sourceService(source->get_service());
1914 Mlt::Service destService(dest->get_service());
1916 // move all effects to the correct producer
1918 Mlt::Filter *filter = sourceService.filter(ct);
1920 if (filter->get("kdenlive_ix") != 0) {
1921 sourceService.detach(*filter);
1922 destService.attach(*filter);
1924 filter = sourceService.filter(ct);
1928 int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, int strobe, Mlt::Producer *prod)
1932 Mlt::Service service(m_mltProducer->parent().get_service());
1933 if (service.type() != tractor_type) {
1934 kWarning() << "// TRACTOR PROBLEM";
1937 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
1938 Mlt::Tractor tractor(service);
1939 Mlt::Producer trackProducer(tractor.track(info.track));
1940 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1941 int startPos = info.startPos.frames(m_fps);
1942 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1943 int clipLength = trackPlaylist.clip_length(clipIndex);
1945 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1949 if (!clip->is_valid() || clip->is_blank()) {
1954 Mlt::Producer clipparent = clip->parent();
1955 if (!clipparent.is_valid() || clipparent.is_blank()) {
1961 QString serv = clipparent.get("mlt_service");
1962 QString id = clipparent.get("id");
1963 //kDebug() << "CLIP SERVICE: " << serv;
1964 if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
1965 mlt_service_lock(service.get_service());
1966 QString url = QString::fromUtf8(clipparent.get("resource"));
1967 url.append('?' + QString::number(speed));
1968 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1969 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1970 if (!slowprod || slowprod->get_producer() == NULL) {
1971 char *tmp = decodedString(url);
1972 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
1973 if (strobe > 1) slowprod->set("strobe", strobe);
1975 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1976 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1977 tmp = decodedString(producerid);
1978 slowprod->set("id", tmp);
1980 m_slowmotionProducers.insert(url, slowprod);
1982 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1983 trackPlaylist.consolidate_blanks(0);
1984 // Check that the blank space is long enough for our new duration
1985 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1986 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
1988 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
1989 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
1990 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
1991 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
1993 // move all effects to the correct producer
1994 mltPasteEffects(clip, cut);
1995 trackPlaylist.insert_at(startPos, cut, 1);
1998 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1999 newLength = trackPlaylist.clip_length(clipIndex);
2000 mlt_service_unlock(service.get_service());
2001 } else if (speed == 1.0 && strobe < 2) {
2002 mlt_service_lock(service.get_service());
2004 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2005 trackPlaylist.consolidate_blanks(0);
2007 // Check that the blank space is long enough for our new duration
2008 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2009 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2012 GenTime oldDuration = GenTime(clipLength, m_fps);
2013 GenTime newDuration = oldDuration * oldspeed;
2014 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
2015 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2016 cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1));
2017 } else cut = prod->cut((int)(info.cropStart.frames(m_fps)), (int)((info.cropStart + newDuration).frames(m_fps)) - 1);
2019 // move all effects to the correct producer
2020 mltPasteEffects(clip, cut);
2022 trackPlaylist.insert_at(startPos, cut, 1);
2025 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2026 newLength = trackPlaylist.clip_length(clipIndex);
2027 mlt_service_unlock(service.get_service());
2029 } else if (serv == "framebuffer") {
2030 mlt_service_lock(service.get_service());
2031 QString url = QString::fromUtf8(clipparent.get("resource"));
2032 url = url.section('?', 0, 0);
2033 url.append('?' + QString::number(speed));
2034 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2035 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2036 if (!slowprod || slowprod->get_producer() == NULL) {
2037 char *tmp = decodedString(url);
2038 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp);
2040 slowprod->set("strobe", strobe);
2041 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2042 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2043 tmp = decodedString(producerid);
2044 slowprod->set("id", tmp);
2046 m_slowmotionProducers.insert(url, slowprod);
2048 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2049 trackPlaylist.consolidate_blanks(0);
2051 GenTime oldDuration = GenTime(clipLength, m_fps);
2052 GenTime newDuration = oldDuration * (oldspeed / speed);
2054 // Check that the blank space is long enough for our new duration
2055 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2056 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2059 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) {
2060 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2061 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2062 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1));
2064 // move all effects to the correct producer
2065 mltPasteEffects(clip, cut);
2067 trackPlaylist.insert_at(startPos, cut, 1);
2070 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2071 newLength = trackPlaylist.clip_length(clipIndex);
2073 mlt_service_unlock(service.get_service());
2077 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2078 m_isBlocked = false;
2082 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2084 Mlt::Service service(m_mltProducer->parent().get_service());
2085 bool success = false;
2086 Mlt::Tractor tractor(service);
2087 Mlt::Producer trackProducer(tractor.track(track));
2088 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2089 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2090 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2092 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2095 Mlt::Service clipService(clip->get_service());
2097 // if (tag.startsWith("ladspa")) tag = "ladspa";
2100 Mlt::Filter *filter = clipService.filter(ct);
2102 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) {
2103 if (clipService.detach(*filter) == 0) success = true;
2104 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2105 } else if (updateIndex) {
2106 // Adjust the other effects index
2107 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2110 filter = clipService.filter(ct);
2112 m_isBlocked = false;
2113 if (doRefresh) refresh();
2118 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2121 Mlt::Service service(m_mltProducer->parent().get_service());
2123 Mlt::Tractor tractor(service);
2124 Mlt::Producer trackProducer(tractor.track(track));
2125 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2127 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2131 Mlt::Service clipService(clip->get_service());
2133 int duration = clip->get_playtime();
2135 // temporarily remove all effects after insert point
2136 QList <Mlt::Filter *> filtersList;
2137 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2139 Mlt::Filter *filter = clipService.filter(ct);
2141 if (QString(filter->get("kdenlive_ix")).toInt() >= filter_ix) {
2142 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() + 1);
2143 filtersList.append(filter);
2144 clipService.detach(*filter);
2146 filter = clipService.filter(ct);
2150 QString tag = params.paramValue("tag");
2151 kDebug() << " / / INSERTING EFFECT: " << tag;
2152 if (tag.startsWith("ladspa")) tag = "ladspa";
2153 char *filterTag = decodedString(tag);
2154 char *filterId = decodedString(params.paramValue("id"));
2155 QHash<QString, QString>::Iterator it;
2156 QString kfr = params.paramValue("keyframes");
2158 if (!kfr.isEmpty()) {
2159 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2160 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2161 char *starttag = decodedString(params.paramValue("starttag", "start"));
2162 char *endtag = decodedString(params.paramValue("endtag", "end"));
2163 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2164 //double max = params.paramValue("max").toDouble();
2165 double min = params.paramValue("min").toDouble();
2166 double factor = params.paramValue("factor", "1").toDouble();
2167 params.removeParam("starttag");
2168 params.removeParam("endtag");
2169 params.removeParam("keyframes");
2170 params.removeParam("min");
2171 params.removeParam("max");
2172 params.removeParam("factor");
2174 for (int i = 0; i < keyFrames.size() - 1; ++i) {
2175 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2176 if (filter && filter->is_valid()) {
2177 filter->set("kdenlive_id", filterId);
2178 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2179 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2180 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2181 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2182 if (x2 == -1) x2 = duration;
2184 for (int j = 0; j < params.count(); j++) {
2185 char *name = decodedString(params.at(j).name());
2186 char *value = decodedString(params.at(j).value());
2187 filter->set(name, value);
2192 filter->set("in", x1);
2193 filter->set("out", x2);
2194 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2195 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2196 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2197 clipService.attach(*filter);
2204 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2205 if (filter && filter->is_valid())
2206 filter->set("kdenlive_id", filterId);
2208 kDebug() << "filter is NULL";
2209 m_isBlocked = false;
2213 params.removeParam("kdenlive_id");
2215 for (int j = 0; j < params.count(); j++) {
2216 char *name = decodedString(params.at(j).name());
2217 char *value = decodedString(params.at(j).value());
2218 filter->set(name, value);
2224 QString effectArgs = params.paramValue("id").section('_', 1);
2226 params.removeParam("id");
2227 params.removeParam("kdenlive_ix");
2228 params.removeParam("tag");
2229 params.removeParam("disabled");
2231 for (int j = 0; j < params.count(); j++) {
2232 effectArgs.append(' ' + params.at(j).value());
2234 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2235 char *value = decodedString(effectArgs.simplified());
2236 filter->set("effect", value);
2241 // attach filter to the clip
2242 clipService.attach(*filter);
2247 // re-add following filters
2248 for (int i = 0; i < filtersList.count(); i++) {
2249 clipService.attach(*(filtersList.at(i)));
2252 m_isBlocked = false;
2253 if (doRefresh) refresh();
2257 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2259 QString index = params.paramValue("kdenlive_ix");
2260 QString tag = params.paramValue("tag");
2262 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2263 // This is a keyframe effect, to edit it, we remove it and re-add it.
2264 mltRemoveEffect(track, position, index, false);
2265 bool success = mltAddEffect(track, position, params);
2270 Mlt::Service service(m_mltProducer->parent().get_service());
2272 Mlt::Tractor tractor(service);
2273 Mlt::Producer trackProducer(tractor.track(track));
2274 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2275 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2276 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2278 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2281 Mlt::Service clipService(clip->get_service());
2285 Mlt::Filter *filter = clipService.filter(ct);
2287 if (filter->get("kdenlive_ix") == index) {
2291 filter = clipService.filter(ct);
2295 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2296 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2298 filter = clipService.filter(ct);
2299 QList <Mlt::Filter *> filtersList;
2301 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2302 filtersList.append(filter);
2303 clipService.detach(*filter);
2305 filter = clipService.filter(ct);
2307 bool success = mltAddEffect(track, position, params);
2309 for (int i = 0; i < filtersList.count(); i++) {
2310 clipService.attach(*(filtersList.at(i)));
2313 m_isBlocked = false;
2316 mlt_service_lock(service.get_service());
2317 for (int j = 0; j < params.count(); j++) {
2318 char *name = decodedString(params.at(j).name());
2319 char *value = decodedString(params.at(j).value());
2320 filter->set(name, value);
2324 mlt_service_unlock(service.get_service());
2326 m_isBlocked = false;
2331 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2334 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2335 Mlt::Service service(m_mltProducer->parent().get_service());
2337 Mlt::Tractor tractor(service);
2338 Mlt::Producer trackProducer(tractor.track(track));
2339 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2340 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2341 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2343 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2346 Mlt::Service clipService(clip->get_service());
2350 QList <Mlt::Filter *> filtersList;
2351 Mlt::Filter *filter = clipService.filter(ct);
2353 if (newPos > oldPos) {
2355 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2356 filter->set("kdenlive_ix", newPos);
2357 filtersList.append(filter);
2358 clipService.detach(*filter);
2359 filter = clipService.filter(ct);
2360 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2361 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2363 filter = clipService.filter(ct);
2367 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2368 filtersList.append(filter);
2369 clipService.detach(*filter);
2371 filter = clipService.filter(ct);
2375 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2376 filter->set("kdenlive_ix", newPos);
2377 filtersList.append(filter);
2378 clipService.detach(*filter);
2380 filter = clipService.filter(ct);
2384 filter = clipService.filter(ct);
2386 int pos = QString(filter->get("kdenlive_ix")).toInt();
2387 if (pos >= newPos) {
2388 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2389 filtersList.append(filter);
2390 clipService.detach(*filter);
2392 filter = clipService.filter(ct);
2396 for (int i = 0; i < filtersList.count(); i++) {
2397 clipService.attach(*(filtersList.at(i)));
2400 m_isBlocked = false;
2404 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2407 Mlt::Service service(m_mltProducer->parent().get_service());
2408 Mlt::Tractor tractor(service);
2409 Mlt::Producer trackProducer(tractor.track(info.track));
2410 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2412 /* // Display playlist info
2413 kDebug()<<"//////////// BEFORE RESIZE";
2414 for (int i = 0; i < trackPlaylist.count(); i++) {
2415 int blankStart = trackPlaylist.clip_start(i);
2416 int blankDuration = trackPlaylist.clip_length(i) - 1;
2418 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2419 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2422 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2423 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2424 m_isBlocked = false;
2427 mlt_service_lock(service.get_service());
2428 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2429 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2430 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2431 int previousStart = clip->get_in();
2432 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2433 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2434 if (newDuration > clip->get_length()) {
2435 clip->parent().set("length", newDuration + 1);
2436 clip->parent().set("out", newDuration);
2437 clip->set("length", newDuration + 1);
2439 if (newDuration > clip->get_out()) {
2440 clip->parent().set_in_and_out(0, newDuration + 1);
2441 clip->set_in_and_out(0, newDuration + 1);
2444 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2445 trackPlaylist.consolidate_blanks(0);
2446 // skip to next clip
2448 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2450 // clip was made longer, trim next blank if there is one.
2451 if (clipIndex < trackPlaylist.count()) {
2452 // If this is not the last clip in playlist
2453 if (trackPlaylist.is_blank(clipIndex)) {
2454 int blankStart = trackPlaylist.clip_start(clipIndex);
2455 int blankDuration = trackPlaylist.clip_length(clipIndex);
2456 if (diff > blankDuration) {
2457 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2459 if (diff - blankDuration == 0) {
2460 trackPlaylist.remove(clipIndex);
2461 } else trackPlaylist.remove_region(blankStart, diff);
2463 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2466 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2467 trackPlaylist.consolidate_blanks(0);
2468 mlt_service_unlock(service.get_service());
2470 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2471 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2472 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2473 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2474 ItemInfo transpinfo;
2475 transpinfo.startPos = info.startPos;
2476 transpinfo.endPos = info.startPos + clipDuration;
2477 transpinfo.track = info.track;
2478 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2480 m_isBlocked = false;
2481 m_mltConsumer->set("refresh", 1);
2485 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2487 Mlt::Service service(m_mltProducer->parent().get_service());
2488 Mlt::Tractor tractor(service);
2489 Mlt::Producer trackProducer(tractor.track(track));
2492 if (blind) trackProducer.set("hide", 3);
2493 else trackProducer.set("hide", 2);
2495 trackProducer.set("hide", 1);
2497 trackProducer.set("hide", 0);
2499 tractor.multitrack()->refresh();
2505 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2507 Mlt::Service service(m_mltProducer->parent().get_service());
2508 int frameOffset = (int) diff.frames(m_fps);
2509 Mlt::Tractor tractor(service);
2510 Mlt::Producer trackProducer(tractor.track(info.track));
2511 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2512 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2513 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2516 mlt_service_lock(service.get_service());
2517 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2518 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2520 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2521 mlt_service_unlock(service.get_service());
2524 int previousStart = clip->get_in();
2526 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2528 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2529 m_isBlocked = false;
2530 mlt_service_unlock(service.get_service());
2531 m_mltConsumer->set("refresh", 1);
2535 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2537 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2538 Mlt::Service service(m_mltProducer->parent().get_service());
2539 int moveFrame = (int) diff.frames(m_fps);
2540 Mlt::Tractor tractor(service);
2541 Mlt::Producer trackProducer(tractor.track(info.track));
2542 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2543 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2544 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2547 mlt_service_lock(service.get_service());
2548 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2549 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2551 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2552 mlt_service_unlock(service.get_service());
2555 int previousStart = clip->get_in();
2557 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2559 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2560 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2561 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2563 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2564 int blankIndex = clipIndex - 1;
2565 int blankLength = trackPlaylist.clip_length(blankIndex);
2566 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2567 if (! trackPlaylist.is_blank(blankIndex)) {
2568 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2570 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2571 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2573 trackPlaylist.consolidate_blanks(0);
2574 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2575 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2576 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2577 ItemInfo transpinfo;
2578 transpinfo.startPos = info.startPos + diff;
2579 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2580 transpinfo.track = info.track;
2581 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2583 m_isBlocked = false;
2584 //m_mltConsumer->set("refresh", 1);
2585 mlt_service_unlock(service.get_service());
2586 m_mltConsumer->set("refresh", 1);
2590 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2592 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2596 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2598 if (prod == NULL || !prod->is_valid()) {
2599 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2602 kDebug() << "NEW PROD ID: " << prod->get("id");
2604 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2605 Mlt::Service service(m_mltProducer->parent().get_service());
2606 if (service.type() != tractor_type) {
2607 kWarning() << "// TRACTOR PROBLEM";
2610 mlt_service_lock(m_mltConsumer->get_service());
2612 Mlt::Tractor tractor(service);
2613 Mlt::Producer trackProducer(tractor.track(track));
2614 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2615 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2616 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2617 if (clipProducer->is_blank()) {
2618 kDebug() << "// ERROR UPDATING CLIP PROD";
2619 delete clipProducer;
2620 mlt_service_unlock(m_mltConsumer->get_service());
2624 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2626 // move all effects to the correct producer
2627 mltPasteEffects(clipProducer, clip);
2628 trackPlaylist.insert_at(pos, clip, 1);
2630 delete clipProducer;
2631 mlt_service_unlock(m_mltConsumer->get_service());
2635 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2639 Mlt::Service service(m_mltProducer->parent().get_service());
2640 if (service.type() != tractor_type) {
2641 kWarning() << "// TRACTOR PROBLEM";
2645 Mlt::Tractor tractor(service);
2646 mlt_service_lock(service.get_service());
2647 Mlt::Producer trackProducer(tractor.track(startTrack));
2648 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2649 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
2650 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2651 bool checkLength = false;
2652 if (endTrack == startTrack) {
2653 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2654 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer->is_blank()) {
2655 // error, destination is not empty
2656 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2657 delete clipProducer;
2658 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2659 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2660 mlt_service_unlock(service.get_service());
2664 trackPlaylist.consolidate_blanks(0);
2665 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2666 delete clipProducer;
2667 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2668 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2670 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2672 //mlt_service_unlock(service.get_service());
2674 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2675 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2676 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2677 // error, destination is not empty
2678 mlt_service_unlock(service.get_service());
2682 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2683 if (clipProducer->is_blank()) {
2684 // error, destination is not empty
2685 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2686 delete clipProducer;
2687 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2688 mlt_service_unlock(service.get_service());
2692 trackPlaylist.consolidate_blanks(0);
2693 destTrackPlaylist.consolidate_blanks(1);
2694 Mlt::Producer *clip;
2695 // check if we are moving a slowmotion producer
2696 QString serv = clipProducer->parent().get("mlt_service");
2697 QString currentid = clipProducer->parent().get("id");
2698 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2699 clip = clipProducer;
2702 // Special case: prod is null when using placeholder clips.
2703 // in that case, use the producer existing in playlist. Note that
2704 // it will bypass the one producer per track logic and might cause
2705 // Sound cracks if clip is moved so that it overlaps another copy of itself
2706 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
2707 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2710 // move all effects to the correct producer
2711 mltPasteEffects(clipProducer, clip);
2713 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2714 if (clip == clipProducer) {
2719 delete clipProducer;
2721 destTrackPlaylist.consolidate_blanks(0);
2722 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2723 kDebug() << "//////// moving clip transparency";
2724 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2726 if (clipIndex > trackPlaylist.count()) checkLength = true;
2727 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2730 mlt_service_unlock(service.get_service());
2731 if (checkLength) mltCheckLength(&tractor);
2734 //m_mltConsumer->set("refresh", 1);
2738 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2740 int new_in = (int)newIn.frames(m_fps);
2741 int new_out = (int)newOut.frames(m_fps) - 1;
2742 if (new_in >= new_out) return false;
2744 mlt_service serv = m_mltProducer->parent().get_service();
2746 mlt_service_lock(serv);
2747 //m_mltConsumer->set("refresh", 0);
2750 mlt_service nextservice = mlt_service_get_producer(serv);
2751 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2752 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2753 QString resource = mlt_properties_get(properties, "mlt_service");
2754 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2756 while (mlt_type == "transition") {
2757 mlt_transition tr = (mlt_transition) nextservice;
2758 int currentTrack = mlt_transition_get_b_track(tr);
2759 int currentIn = (int) mlt_transition_get_in(tr);
2760 int currentOut = (int) mlt_transition_get_out(tr);
2762 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2763 mlt_transition_set_in_and_out(tr, new_in, new_out);
2764 if (newTrack - startTrack != 0) {
2765 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2767 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2768 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2769 mlt_properties_set_int(properties, "b_track", newTrack);
2770 //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);
2774 nextservice = mlt_service_producer(nextservice);
2775 if (nextservice == NULL) break;
2776 properties = MLT_SERVICE_PROPERTIES(nextservice);
2777 mlt_type = mlt_properties_get(properties, "mlt_type");
2778 resource = mlt_properties_get(properties, "mlt_service");
2780 mlt_service_unlock(serv);
2783 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2787 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2789 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2791 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2792 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
2795 //mltSavePlaylist();
2798 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2800 mlt_service serv = m_mltProducer->parent().get_service();
2801 mlt_service_lock(serv);
2804 mlt_service nextservice = mlt_service_get_producer(serv);
2805 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2806 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2807 QString resource = mlt_properties_get(properties, "mlt_service");
2808 int in_pos = (int) in.frames(m_fps);
2809 int out_pos = (int) out.frames(m_fps) - 1;
2811 while (mlt_type == "transition") {
2812 mlt_transition tr = (mlt_transition) nextservice;
2813 int currentTrack = mlt_transition_get_b_track(tr);
2814 int currentBTrack = mlt_transition_get_a_track(tr);
2815 int currentIn = (int) mlt_transition_get_in(tr);
2816 int currentOut = (int) mlt_transition_get_out(tr);
2818 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2820 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2821 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2822 QMap<QString, QString>::Iterator it;
2824 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2825 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2826 // update the transition id in case it uses the same MLT service but different Kdenlive id
2827 char *tmp = decodedString(xml.attribute("id"));
2828 mlt_properties_set(transproperties, "kdenlive_id", tmp);
2830 if (currentBTrack != a_track) {
2831 mlt_properties_set_int(properties, "a_track", a_track);
2833 for (it = map.begin(); it != map.end(); ++it) {
2835 char *name = decodedString(key);
2836 char *value = decodedString(it.value());
2837 mlt_properties_set(transproperties, name, value);
2838 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2839 //filter->set("kdenlive_id", id);
2845 nextservice = mlt_service_producer(nextservice);
2846 if (nextservice == NULL) break;
2847 properties = MLT_SERVICE_PROPERTIES(nextservice);
2848 mlt_type = mlt_properties_get(properties, "mlt_type");
2849 resource = mlt_properties_get(properties, "mlt_service");
2851 mlt_service_unlock(serv);
2854 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2857 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2859 mlt_service serv = m_mltProducer->parent().get_service();
2861 mlt_service_lock(serv);
2863 Mlt::Service service(serv);
2864 Mlt::Tractor tractor(service);
2865 Mlt::Field *field = tractor.field();
2867 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2869 mlt_service nextservice = mlt_service_get_producer(serv);
2870 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2871 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2872 QString resource = mlt_properties_get(properties, "mlt_service");
2874 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2875 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2877 while (mlt_type == "transition") {
2878 mlt_transition tr = (mlt_transition) nextservice;
2879 int currentTrack = mlt_transition_get_b_track(tr);
2880 int currentIn = (int) mlt_transition_get_in(tr);
2881 int currentOut = (int) mlt_transition_get_out(tr);
2882 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2884 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2885 mlt_field_disconnect_service(field->get_field(), nextservice);
2888 nextservice = mlt_service_producer(nextservice);
2889 if (nextservice == NULL) break;
2890 properties = MLT_SERVICE_PROPERTIES(nextservice);
2891 mlt_type = mlt_properties_get(properties, "mlt_type");
2892 resource = mlt_properties_get(properties, "mlt_service");
2894 mlt_service_unlock(serv);
2897 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2900 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2902 QDomNodeList attribs = xml.elementsByTagName("parameter");
2903 QMap<QString, QString> map;
2904 for (int i = 0; i < attribs.count(); i++) {
2905 QDomElement e = attribs.item(i).toElement();
2906 QString name = e.attribute("name");
2907 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2908 map[name] = e.attribute("default");
2909 if (!e.attribute("value").isEmpty()) {
2910 map[name] = e.attribute("value");
2912 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2913 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2914 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2917 if (e.attribute("namedesc").contains(';')) {
2918 QString format = e.attribute("format");
2919 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2920 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2922 QTextStream txtNeu(&neu);
2923 if (values.size() > 0)
2924 txtNeu << (int)values[0].toDouble();
2926 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
2927 txtNeu << separators[i];
2928 txtNeu << (int)(values[i+1].toDouble());
2930 if (i < separators.size())
2931 txtNeu << separators[i];
2932 map[e.attribute("name")] = neu;
2939 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2941 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2942 Mlt::Service service(m_mltProducer->parent().get_service());
2943 Mlt::Tractor tractor(service);
2944 Mlt::Field *field = tractor.field();
2946 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2947 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2948 transition->set("transparency", id);
2949 transition->set("fill", 1);
2950 transition->set("internal_added", 237);
2951 field->plant_transition(*transition, transitiontrack, info.track);
2955 void Render::mltDeleteTransparency(int pos, int track, int id)
2957 Mlt::Service service(m_mltProducer->parent().get_service());
2958 Mlt::Tractor tractor(service);
2959 Mlt::Field *field = tractor.field();
2961 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2962 mlt_service serv = m_mltProducer->parent().get_service();
2964 mlt_service nextservice = mlt_service_get_producer(serv);
2965 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2966 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2967 QString resource = mlt_properties_get(properties, "mlt_service");
2969 while (mlt_type == "transition") {
2970 mlt_transition tr = (mlt_transition) nextservice;
2971 int currentTrack = mlt_transition_get_b_track(tr);
2972 int currentIn = (int) mlt_transition_get_in(tr);
2973 int currentOut = (int) mlt_transition_get_out(tr);
2974 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2975 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2977 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2978 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2979 mlt_field_disconnect_service(field->get_field(), nextservice);
2982 nextservice = mlt_service_producer(nextservice);
2983 if (nextservice == NULL) break;
2984 properties = MLT_SERVICE_PROPERTIES(nextservice);
2985 mlt_type = mlt_properties_get(properties, "mlt_type");
2986 resource = mlt_properties_get(properties, "mlt_service");
2988 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2991 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2993 Mlt::Service service(m_mltProducer->parent().get_service());
2994 Mlt::Tractor tractor(service);
2996 mlt_service_lock(service.get_service());
2997 m_mltConsumer->set("refresh", 0);
3000 mlt_service serv = m_mltProducer->parent().get_service();
3001 mlt_service nextservice = mlt_service_get_producer(serv);
3002 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3003 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3004 QString resource = mlt_properties_get(properties, "mlt_service");
3005 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3006 while (mlt_type == "transition") {
3007 mlt_transition tr = (mlt_transition) nextservice;
3008 int currentTrack = mlt_transition_get_b_track(tr);
3009 int currentIn = (int) mlt_transition_get_in(tr);
3010 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3011 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3012 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3013 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3014 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3015 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3018 nextservice = mlt_service_producer(nextservice);
3019 if (nextservice == NULL) break;
3020 properties = MLT_SERVICE_PROPERTIES(nextservice);
3021 mlt_type = mlt_properties_get(properties, "mlt_type");
3022 resource = mlt_properties_get(properties, "mlt_service");
3024 mlt_service_unlock(service.get_service());
3026 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3030 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3032 Mlt::Service service(m_mltProducer->parent().get_service());
3033 Mlt::Tractor tractor(service);
3035 mlt_service_lock(service.get_service());
3036 m_mltConsumer->set("refresh", 0);
3039 mlt_service serv = m_mltProducer->parent().get_service();
3040 mlt_service nextservice = mlt_service_get_producer(serv);
3041 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3042 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3043 QString resource = mlt_properties_get(properties, "mlt_service");
3045 while (mlt_type == "transition") {
3046 mlt_transition tr = (mlt_transition) nextservice;
3047 int currentTrack = mlt_transition_get_b_track(tr);
3048 int currentaTrack = mlt_transition_get_a_track(tr);
3049 int currentIn = (int) mlt_transition_get_in(tr);
3050 int currentOut = (int) mlt_transition_get_out(tr);
3051 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3052 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3053 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3054 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3055 kDebug() << "//////MOVING";
3056 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3057 if (endTrack != startTrack) {
3058 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3059 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3060 mlt_properties_set_int(properties, "b_track", endTrack);
3064 nextservice = mlt_service_producer(nextservice);
3065 if (nextservice == NULL) break;
3066 properties = MLT_SERVICE_PROPERTIES(nextservice);
3067 mlt_type = mlt_properties_get(properties, "mlt_type");
3068 resource = mlt_properties_get(properties, "mlt_service");
3071 mlt_service_unlock(service.get_service());
3072 m_mltConsumer->set("refresh", 1);
3076 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3078 if (in >= out) return false;
3079 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3080 Mlt::Service service(m_mltProducer->parent().get_service());
3082 Mlt::Tractor tractor(service);
3083 Mlt::Field *field = tractor.field();
3085 char *transId = decodedString(tag);
3086 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
3087 if (out != GenTime())
3088 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3089 QMap<QString, QString>::Iterator it;
3091 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3092 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3093 if (xml.hasAttribute("id"))
3094 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3096 for (it = args.begin(); it != args.end(); ++it) {
3098 char *name = decodedString(key);
3099 char *value = decodedString(it.value());
3100 if (it.value().isEmpty() == false) transition->set(name, value);
3101 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
3105 // attach filter to the clip
3106 field->plant_transition(*transition, a_track, b_track);
3108 if (do_refresh) refresh();
3112 void Render::mltSavePlaylist()
3114 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3115 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3116 fileConsumer.set("resource", "/tmp/playlist.mlt");
3118 Mlt::Service service(m_mltProducer->get_service());
3120 fileConsumer.connect(service);
3121 fileConsumer.start();
3124 const QList <Mlt::Producer *> Render::producersList()
3126 QList <Mlt::Producer *> prods;
3127 if (m_mltProducer == NULL) return prods;
3128 Mlt::Service service(m_mltProducer->parent().get_service());
3129 if (service.type() != tractor_type) return prods;
3130 Mlt::Tractor tractor(service);
3133 int trackNb = tractor.count();
3134 for (int t = 1; t < trackNb; t++) {
3135 Mlt::Producer *tt = tractor.track(t);
3136 Mlt::Producer trackProducer(tt);
3138 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3139 int clipNb = trackPlaylist.count();
3140 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3141 for (int i = 0; i < clipNb; i++) {
3142 Mlt::Producer *c = trackPlaylist.get_clip(i);
3143 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3145 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3146 ids.append(nprod->get("id"));
3147 prods.append(nprod);
3148 } else delete nprod;
3156 void Render::fillSlowMotionProducers()
3158 if (m_mltProducer == NULL) return;
3159 Mlt::Service service(m_mltProducer->parent().get_service());
3160 if (service.type() != tractor_type) return;
3162 Mlt::Tractor tractor(service);
3164 int trackNb = tractor.count();
3165 for (int t = 1; t < trackNb; t++) {
3166 Mlt::Producer *tt = tractor.track(t);
3167 Mlt::Producer trackProducer(tt);
3169 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3170 int clipNb = trackPlaylist.count();
3171 for (int i = 0; i < clipNb; i++) {
3172 Mlt::Producer *c = trackPlaylist.get_clip(i);
3173 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3175 QString id = nprod->get("id");
3176 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3177 // this is a slowmotion producer, add it to the list
3178 QString url = QString::fromUtf8(nprod->get("resource"));
3179 int strobe = nprod->get_int("strobe");
3180 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3181 if (!m_slowmotionProducers.contains(url)) {
3182 m_slowmotionProducers.insert(url, nprod);
3184 } else delete nprod;
3191 void Render::mltInsertTrack(int ix, bool videoTrack)
3196 Mlt::Service service(m_mltProducer->parent().get_service());
3197 mlt_service_lock(service.get_service());
3198 if (service.type() != tractor_type) {
3199 kWarning() << "// TRACTOR PROBLEM";
3203 Mlt::Tractor tractor(service);
3205 Mlt::Playlist playlist;
3206 int ct = tractor.count();
3208 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3214 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3215 tractor.set_track(playlist, pos);
3216 Mlt::Producer newProd(tractor.track(pos));
3217 if (!videoTrack) newProd.set("hide", 1);
3219 for (; pos <= ct; pos++) {
3220 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3221 tractor.set_track(*prodToMove, pos);
3222 prodToMove = prodToMove2;
3225 tractor.set_track(playlist, ix);
3226 Mlt::Producer newProd(tractor.track(ix));
3227 if (!videoTrack) newProd.set("hide", 1);
3231 mlt_service serv = m_mltProducer->parent().get_service();
3232 mlt_service nextservice = mlt_service_get_producer(serv);
3233 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3234 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3235 QString resource = mlt_properties_get(properties, "mlt_service");
3237 while (mlt_type == "transition") {
3238 if (resource != "mix") {
3239 mlt_transition tr = (mlt_transition) nextservice;
3240 int currentTrack = mlt_transition_get_b_track(tr);
3241 int currentaTrack = mlt_transition_get_a_track(tr);
3242 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3244 if (currentTrack >= ix) {
3245 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3246 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3249 nextservice = mlt_service_producer(nextservice);
3250 if (nextservice == NULL) break;
3251 properties = MLT_SERVICE_PROPERTIES(nextservice);
3252 mlt_type = mlt_properties_get(properties, "mlt_type");
3253 resource = mlt_properties_get(properties, "mlt_service");
3256 // Add audio mix transition to last track
3257 Mlt::Field *field = tractor.field();
3258 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3259 transition->set("a_track", 1);
3260 transition->set("b_track", ct);
3261 transition->set("always_active", 1);
3262 transition->set("internal_added", 237);
3263 transition->set("combine", 1);
3264 field->plant_transition(*transition, 1, ct);
3265 //mlt_service_unlock(m_mltConsumer->get_service());
3266 mlt_service_unlock(service.get_service());
3267 //tractor.multitrack()->refresh();
3268 //tractor.refresh();
3270 blockSignals(false);
3274 void Render::mltDeleteTrack(int ix)
3277 doc.setContent(sceneList(), false);
3278 int tracksCount = doc.elementsByTagName("track").count() - 1;
3279 QDomNode track = doc.elementsByTagName("track").at(ix);
3280 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3281 QDomNodeList transitions = doc.elementsByTagName("transition");
3282 for (int i = 0; i < transitions.count(); i++) {
3283 QDomElement e = transitions.at(i).toElement();
3284 QDomNodeList props = e.elementsByTagName("property");
3285 QMap <QString, QString> mappedProps;
3286 for (int j = 0; j < props.count(); j++) {
3287 QDomElement f = props.at(j).toElement();
3288 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3290 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3291 tractor.removeChild(transitions.at(i));
3293 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3294 // Transition needs to be moved
3295 int a_track = mappedProps.value("a_track").toInt();
3296 int b_track = mappedProps.value("b_track").toInt();
3297 if (a_track > 0 && a_track >= ix) a_track --;
3298 if (b_track > 0 && b_track >= ix) b_track --;
3299 for (int j = 0; j < props.count(); j++) {
3300 QDomElement f = props.at(j).toElement();
3301 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3302 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3307 tractor.removeChild(track);
3308 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3309 setSceneList(doc.toString(), m_framePosition);
3311 /* if (m_mltProducer != NULL) {
3312 Mlt::Producer parentProd(m_mltProducer->parent());
3313 if (parentProd.get_producer() != NULL) {
3314 Mlt::Service service(parentProd.get_service());
3315 if (service.type() == tractor_type) {
3316 Mlt::Tractor tractor(service);
3317 mltCheckLength(&tractor);
3324 void Render::updatePreviewSettings()
3326 kDebug() << "////// RESTARTING CONSUMER";
3327 if (!m_mltConsumer || !m_mltProducer) return;
3328 if (m_mltProducer->get_playtime() == 0) return;
3329 Mlt::Service service(m_mltProducer->parent().get_service());
3330 if (service.type() != tractor_type) return;
3332 //m_mltConsumer->set("refresh", 0);
3333 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3334 m_mltConsumer->purge();
3335 QString scene = sceneList();
3337 if (m_mltProducer) {
3338 pos = m_mltProducer->position();
3341 setSceneList(scene, pos);
3344 #include "renderer.moc"