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 filtersList.append(filter);
2143 clipService.detach(*filter);
2145 filter = clipService.filter(ct);
2149 QString tag = params.paramValue("tag");
2150 kDebug() << " / / INSERTING EFFECT: " << tag;
2151 if (tag.startsWith("ladspa")) tag = "ladspa";
2152 char *filterTag = decodedString(tag);
2153 char *filterId = decodedString(params.paramValue("id"));
2154 QHash<QString, QString>::Iterator it;
2155 QString kfr = params.paramValue("keyframes");
2157 if (!kfr.isEmpty()) {
2158 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2159 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2160 char *starttag = decodedString(params.paramValue("starttag", "start"));
2161 char *endtag = decodedString(params.paramValue("endtag", "end"));
2162 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2163 //double max = params.paramValue("max").toDouble();
2164 double min = params.paramValue("min").toDouble();
2165 double factor = params.paramValue("factor", "1").toDouble();
2166 params.removeParam("starttag");
2167 params.removeParam("endtag");
2168 params.removeParam("keyframes");
2169 params.removeParam("min");
2170 params.removeParam("max");
2171 params.removeParam("factor");
2173 for (int i = 0; i < keyFrames.size() - 1; ++i) {
2174 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2175 if (filter && filter->is_valid()) {
2176 filter->set("kdenlive_id", filterId);
2177 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2178 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2179 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2180 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2181 if (x2 == -1) x2 = duration;
2183 for (int j = 0; j < params.count(); j++) {
2184 char *name = decodedString(params.at(j).name());
2185 char *value = decodedString(params.at(j).value());
2186 filter->set(name, value);
2191 filter->set("in", x1);
2192 filter->set("out", x2);
2193 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2194 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2195 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2196 clipService.attach(*filter);
2203 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2204 if (filter && filter->is_valid())
2205 filter->set("kdenlive_id", filterId);
2207 kDebug() << "filter is NULL";
2208 m_isBlocked = false;
2212 params.removeParam("kdenlive_id");
2214 for (int j = 0; j < params.count(); j++) {
2215 char *name = decodedString(params.at(j).name());
2216 char *value = decodedString(params.at(j).value());
2217 filter->set(name, value);
2223 QString effectArgs = params.paramValue("id").section('_', 1);
2225 params.removeParam("id");
2226 params.removeParam("kdenlive_ix");
2227 params.removeParam("tag");
2228 params.removeParam("disabled");
2230 for (int j = 0; j < params.count(); j++) {
2231 effectArgs.append(' ' + params.at(j).value());
2233 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2234 char *value = decodedString(effectArgs.simplified());
2235 filter->set("effect", value);
2240 // attach filter to the clip
2241 clipService.attach(*filter);
2246 // re-add following filters
2247 for (int i = 0; i < filtersList.count(); i++) {
2248 clipService.attach(*(filtersList.at(i)));
2251 m_isBlocked = false;
2252 if (doRefresh) refresh();
2256 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2258 QString index = params.paramValue("kdenlive_ix");
2259 QString tag = params.paramValue("tag");
2261 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") {
2262 // This is a keyframe effect, to edit it, we remove it and re-add it.
2263 mltRemoveEffect(track, position, index, false);
2264 bool success = mltAddEffect(track, position, params);
2269 Mlt::Service service(m_mltProducer->parent().get_service());
2271 Mlt::Tractor tractor(service);
2272 Mlt::Producer trackProducer(tractor.track(track));
2273 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2274 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2275 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2277 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2280 Mlt::Service clipService(clip->get_service());
2284 Mlt::Filter *filter = clipService.filter(ct);
2286 if (filter->get("kdenlive_ix") == index) {
2290 filter = clipService.filter(ct);
2294 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT!!!!!";
2295 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2297 filter = clipService.filter(ct);
2298 QList <Mlt::Filter *> filtersList;
2300 if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) {
2301 filtersList.append(filter);
2302 clipService.detach(*filter);
2304 filter = clipService.filter(ct);
2306 bool success = mltAddEffect(track, position, params);
2308 for (int i = 0; i < filtersList.count(); i++) {
2309 clipService.attach(*(filtersList.at(i)));
2312 m_isBlocked = false;
2315 mlt_service_lock(service.get_service());
2316 for (int j = 0; j < params.count(); j++) {
2317 char *name = decodedString(params.at(j).name());
2318 char *value = decodedString(params.at(j).value());
2319 filter->set(name, value);
2323 mlt_service_unlock(service.get_service());
2325 m_isBlocked = false;
2330 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2333 kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos;
2334 Mlt::Service service(m_mltProducer->parent().get_service());
2336 Mlt::Tractor tractor(service);
2337 Mlt::Producer trackProducer(tractor.track(track));
2338 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2339 //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps));
2340 Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps));
2342 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2345 Mlt::Service clipService(clip->get_service());
2349 QList <Mlt::Filter *> filtersList;
2350 Mlt::Filter *filter = clipService.filter(ct);
2352 if (newPos > oldPos) {
2354 if (!found && QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2355 filter->set("kdenlive_ix", newPos);
2356 filtersList.append(filter);
2357 clipService.detach(*filter);
2358 filter = clipService.filter(ct);
2359 while (filter && QString(filter->get("kdenlive_ix")).toInt() <= newPos) {
2360 filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1);
2362 filter = clipService.filter(ct);
2366 if (filter && QString(filter->get("kdenlive_ix")).toInt() > newPos) {
2367 filtersList.append(filter);
2368 clipService.detach(*filter);
2370 filter = clipService.filter(ct);
2374 if (QString(filter->get("kdenlive_ix")).toInt() == oldPos) {
2375 filter->set("kdenlive_ix", newPos);
2376 filtersList.append(filter);
2377 clipService.detach(*filter);
2379 filter = clipService.filter(ct);
2383 filter = clipService.filter(ct);
2385 int pos = QString(filter->get("kdenlive_ix")).toInt();
2386 if (pos >= newPos) {
2387 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2388 filtersList.append(filter);
2389 clipService.detach(*filter);
2391 filter = clipService.filter(ct);
2395 for (int i = 0; i < filtersList.count(); i++) {
2396 clipService.attach(*(filtersList.at(i)));
2399 m_isBlocked = false;
2403 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2406 Mlt::Service service(m_mltProducer->parent().get_service());
2407 Mlt::Tractor tractor(service);
2408 Mlt::Producer trackProducer(tractor.track(info.track));
2409 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2411 /* // Display playlist info
2412 kDebug()<<"//////////// BEFORE RESIZE";
2413 for (int i = 0; i < trackPlaylist.count(); i++) {
2414 int blankStart = trackPlaylist.clip_start(i);
2415 int blankDuration = trackPlaylist.clip_length(i) - 1;
2417 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2418 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2421 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2422 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2423 m_isBlocked = false;
2426 mlt_service_lock(service.get_service());
2427 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2428 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2429 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2430 int previousStart = clip->get_in();
2431 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2432 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2433 if (newDuration > clip->get_length()) {
2434 clip->parent().set("length", newDuration + 1);
2435 clip->parent().set("out", newDuration);
2436 clip->set("length", newDuration + 1);
2438 if (newDuration > clip->get_out()) {
2439 clip->parent().set_in_and_out(0, newDuration + 1);
2440 clip->set_in_and_out(0, newDuration + 1);
2443 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2444 trackPlaylist.consolidate_blanks(0);
2445 // skip to next clip
2447 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2449 // clip was made longer, trim next blank if there is one.
2450 if (clipIndex < trackPlaylist.count()) {
2451 // If this is not the last clip in playlist
2452 if (trackPlaylist.is_blank(clipIndex)) {
2453 int blankStart = trackPlaylist.clip_start(clipIndex);
2454 int blankDuration = trackPlaylist.clip_length(clipIndex);
2455 if (diff > blankDuration) {
2456 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2458 if (diff - blankDuration == 0) {
2459 trackPlaylist.remove(clipIndex);
2460 } else trackPlaylist.remove_region(blankStart, diff);
2462 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2465 } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2466 trackPlaylist.consolidate_blanks(0);
2467 mlt_service_unlock(service.get_service());
2469 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2470 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2471 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2472 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2473 ItemInfo transpinfo;
2474 transpinfo.startPos = info.startPos;
2475 transpinfo.endPos = info.startPos + clipDuration;
2476 transpinfo.track = info.track;
2477 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2479 m_isBlocked = false;
2480 m_mltConsumer->set("refresh", 1);
2484 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2486 Mlt::Service service(m_mltProducer->parent().get_service());
2487 Mlt::Tractor tractor(service);
2488 Mlt::Producer trackProducer(tractor.track(track));
2491 if (blind) trackProducer.set("hide", 3);
2492 else trackProducer.set("hide", 2);
2494 trackProducer.set("hide", 1);
2496 trackProducer.set("hide", 0);
2498 tractor.multitrack()->refresh();
2504 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2506 Mlt::Service service(m_mltProducer->parent().get_service());
2507 int frameOffset = (int) diff.frames(m_fps);
2508 Mlt::Tractor tractor(service);
2509 Mlt::Producer trackProducer(tractor.track(info.track));
2510 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2511 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2512 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2515 mlt_service_lock(service.get_service());
2516 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2517 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2519 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2520 mlt_service_unlock(service.get_service());
2523 int previousStart = clip->get_in();
2525 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2527 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset);
2528 m_isBlocked = false;
2529 mlt_service_unlock(service.get_service());
2530 m_mltConsumer->set("refresh", 1);
2534 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2536 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2537 Mlt::Service service(m_mltProducer->parent().get_service());
2538 int moveFrame = (int) diff.frames(m_fps);
2539 Mlt::Tractor tractor(service);
2540 Mlt::Producer trackProducer(tractor.track(info.track));
2541 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2542 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2543 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2546 mlt_service_lock(service.get_service());
2547 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2548 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2550 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2551 mlt_service_unlock(service.get_service());
2554 int previousStart = clip->get_in();
2556 int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;
2558 kDebug() << "RESIZE, old start: " << previousStart << ", PREV DUR: " << previousDuration << ", DIFF: " << moveFrame;
2559 trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration);
2560 if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2562 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2563 int blankIndex = clipIndex - 1;
2564 int blankLength = trackPlaylist.clip_length(blankIndex);
2565 kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2566 if (! trackPlaylist.is_blank(blankIndex)) {
2567 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2569 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2570 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2572 trackPlaylist.consolidate_blanks(0);
2573 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2574 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2575 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2576 ItemInfo transpinfo;
2577 transpinfo.startPos = info.startPos + diff;
2578 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2579 transpinfo.track = info.track;
2580 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2582 m_isBlocked = false;
2583 //m_mltConsumer->set("refresh", 1);
2584 mlt_service_unlock(service.get_service());
2585 m_mltConsumer->set("refresh", 1);
2589 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod)
2591 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod);
2595 void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2597 if (prod == NULL || !prod->is_valid()) {
2598 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2601 kDebug() << "NEW PROD ID: " << prod->get("id");
2603 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2604 Mlt::Service service(m_mltProducer->parent().get_service());
2605 if (service.type() != tractor_type) {
2606 kWarning() << "// TRACTOR PROBLEM";
2609 mlt_service_lock(m_mltConsumer->get_service());
2611 Mlt::Tractor tractor(service);
2612 Mlt::Producer trackProducer(tractor.track(track));
2613 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2614 int clipIndex = trackPlaylist.get_clip_index_at(pos + 1);
2615 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2616 if (clipProducer->is_blank()) {
2617 kDebug() << "// ERROR UPDATING CLIP PROD";
2618 delete clipProducer;
2619 mlt_service_unlock(m_mltConsumer->get_service());
2623 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2625 // move all effects to the correct producer
2626 mltPasteEffects(clipProducer, clip);
2627 trackPlaylist.insert_at(pos, clip, 1);
2629 delete clipProducer;
2630 mlt_service_unlock(m_mltConsumer->get_service());
2634 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod)
2638 Mlt::Service service(m_mltProducer->parent().get_service());
2639 if (service.type() != tractor_type) {
2640 kWarning() << "// TRACTOR PROBLEM";
2644 Mlt::Tractor tractor(service);
2645 mlt_service_lock(service.get_service());
2646 Mlt::Producer trackProducer(tractor.track(startTrack));
2647 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2648 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
2649 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
2650 bool checkLength = false;
2651 if (endTrack == startTrack) {
2652 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2653 if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer->is_blank()) {
2654 // error, destination is not empty
2655 if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1);
2656 delete clipProducer;
2657 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2658 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2659 mlt_service_unlock(service.get_service());
2663 trackPlaylist.consolidate_blanks(0);
2664 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
2665 delete clipProducer;
2666 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2667 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2669 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
2671 //mlt_service_unlock(service.get_service());
2673 Mlt::Producer destTrackProducer(tractor.track(endTrack));
2674 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
2675 if (!destTrackPlaylist.is_blank_at(moveEnd)) {
2676 // error, destination is not empty
2677 mlt_service_unlock(service.get_service());
2681 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
2682 if (clipProducer->is_blank()) {
2683 // error, destination is not empty
2684 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
2685 delete clipProducer;
2686 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
2687 mlt_service_unlock(service.get_service());
2691 trackPlaylist.consolidate_blanks(0);
2692 destTrackPlaylist.consolidate_blanks(1);
2693 Mlt::Producer *clip;
2694 // check if we are moving a slowmotion producer
2695 QString serv = clipProducer->parent().get("mlt_service");
2696 QString currentid = clipProducer->parent().get("id");
2697 if (serv == "framebuffer" || currentid.endsWith("_video")) {
2698 clip = clipProducer;
2701 // Special case: prod is null when using placeholder clips.
2702 // in that case, use the producer existing in playlist. Note that
2703 // it will bypass the one producer per track logic and might cause
2704 // Sound cracks if clip is moved so that it overlaps another copy of itself
2705 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
2706 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
2709 // move all effects to the correct producer
2710 mltPasteEffects(clipProducer, clip);
2712 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
2713 if (clip == clipProducer) {
2718 delete clipProducer;
2720 destTrackPlaylist.consolidate_blanks(0);
2721 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
2722 kDebug() << "//////// moving clip transparency";
2723 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
2725 if (clipIndex > trackPlaylist.count()) checkLength = true;
2726 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
2729 mlt_service_unlock(service.get_service());
2730 if (checkLength) mltCheckLength(&tractor);
2733 //m_mltConsumer->set("refresh", 1);
2737 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
2739 int new_in = (int)newIn.frames(m_fps);
2740 int new_out = (int)newOut.frames(m_fps) - 1;
2741 if (new_in >= new_out) return false;
2743 mlt_service serv = m_mltProducer->parent().get_service();
2745 mlt_service_lock(serv);
2746 //m_mltConsumer->set("refresh", 0);
2749 mlt_service nextservice = mlt_service_get_producer(serv);
2750 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2751 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2752 QString resource = mlt_properties_get(properties, "mlt_service");
2753 int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2;
2755 while (mlt_type == "transition") {
2756 mlt_transition tr = (mlt_transition) nextservice;
2757 int currentTrack = mlt_transition_get_b_track(tr);
2758 int currentIn = (int) mlt_transition_get_in(tr);
2759 int currentOut = (int) mlt_transition_get_out(tr);
2761 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2762 mlt_transition_set_in_and_out(tr, new_in, new_out);
2763 if (newTrack - startTrack != 0) {
2764 //kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack;
2766 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
2767 mlt_properties_set_int(properties, "a_track", newTransitionTrack);
2768 mlt_properties_set_int(properties, "b_track", newTrack);
2769 //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);
2773 nextservice = mlt_service_producer(nextservice);
2774 if (nextservice == NULL) break;
2775 properties = MLT_SERVICE_PROPERTIES(nextservice);
2776 mlt_type = mlt_properties_get(properties, "mlt_type");
2777 resource = mlt_properties_get(properties, "mlt_service");
2779 mlt_service_unlock(serv);
2782 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2786 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2788 if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
2790 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
2791 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
2794 //mltSavePlaylist();
2797 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
2799 mlt_service serv = m_mltProducer->parent().get_service();
2800 mlt_service_lock(serv);
2803 mlt_service nextservice = mlt_service_get_producer(serv);
2804 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2805 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2806 QString resource = mlt_properties_get(properties, "mlt_service");
2807 int in_pos = (int) in.frames(m_fps);
2808 int out_pos = (int) out.frames(m_fps) - 1;
2810 while (mlt_type == "transition") {
2811 mlt_transition tr = (mlt_transition) nextservice;
2812 int currentTrack = mlt_transition_get_b_track(tr);
2813 int currentBTrack = mlt_transition_get_a_track(tr);
2814 int currentIn = (int) mlt_transition_get_in(tr);
2815 int currentOut = (int) mlt_transition_get_out(tr);
2817 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
2819 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
2820 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
2821 QMap<QString, QString>::Iterator it;
2823 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
2824 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
2825 // update the transition id in case it uses the same MLT service but different Kdenlive id
2826 char *tmp = decodedString(xml.attribute("id"));
2827 mlt_properties_set(transproperties, "kdenlive_id", tmp);
2829 if (currentBTrack != a_track) {
2830 mlt_properties_set_int(properties, "a_track", a_track);
2832 for (it = map.begin(); it != map.end(); ++it) {
2834 char *name = decodedString(key);
2835 char *value = decodedString(it.value());
2836 mlt_properties_set(transproperties, name, value);
2837 //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value;
2838 //filter->set("kdenlive_id", id);
2844 nextservice = mlt_service_producer(nextservice);
2845 if (nextservice == NULL) break;
2846 properties = MLT_SERVICE_PROPERTIES(nextservice);
2847 mlt_type = mlt_properties_get(properties, "mlt_type");
2848 resource = mlt_properties_get(properties, "mlt_service");
2850 mlt_service_unlock(serv);
2853 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2856 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
2858 mlt_service serv = m_mltProducer->parent().get_service();
2860 mlt_service_lock(serv);
2862 Mlt::Service service(serv);
2863 Mlt::Tractor tractor(service);
2864 Mlt::Field *field = tractor.field();
2866 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2868 mlt_service nextservice = mlt_service_get_producer(serv);
2869 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2870 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2871 QString resource = mlt_properties_get(properties, "mlt_service");
2873 const int old_pos = (int)((in + out).frames(m_fps) / 2);
2874 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
2876 while (mlt_type == "transition") {
2877 mlt_transition tr = (mlt_transition) nextservice;
2878 int currentTrack = mlt_transition_get_b_track(tr);
2879 int currentIn = (int) mlt_transition_get_in(tr);
2880 int currentOut = (int) mlt_transition_get_out(tr);
2881 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2883 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
2884 mlt_field_disconnect_service(field->get_field(), nextservice);
2887 nextservice = mlt_service_producer(nextservice);
2888 if (nextservice == NULL) break;
2889 properties = MLT_SERVICE_PROPERTIES(nextservice);
2890 mlt_type = mlt_properties_get(properties, "mlt_type");
2891 resource = mlt_properties_get(properties, "mlt_service");
2893 mlt_service_unlock(serv);
2896 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
2899 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
2901 QDomNodeList attribs = xml.elementsByTagName("parameter");
2902 QMap<QString, QString> map;
2903 for (int i = 0; i < attribs.count(); i++) {
2904 QDomElement e = attribs.item(i).toElement();
2905 QString name = e.attribute("name");
2906 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
2907 map[name] = e.attribute("default");
2908 if (!e.attribute("value").isEmpty()) {
2909 map[name] = e.attribute("value");
2911 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
2912 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
2913 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
2916 if (e.attribute("namedesc").contains(';')) {
2917 QString format = e.attribute("format");
2918 QStringList separators = format.split("%d", QString::SkipEmptyParts);
2919 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
2921 QTextStream txtNeu(&neu);
2922 if (values.size() > 0)
2923 txtNeu << (int)values[0].toDouble();
2925 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
2926 txtNeu << separators[i];
2927 txtNeu << (int)(values[i+1].toDouble());
2929 if (i < separators.size())
2930 txtNeu << separators[i];
2931 map[e.attribute("name")] = neu;
2938 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
2940 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
2941 Mlt::Service service(m_mltProducer->parent().get_service());
2942 Mlt::Tractor tractor(service);
2943 Mlt::Field *field = tractor.field();
2945 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
2946 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
2947 transition->set("transparency", id);
2948 transition->set("fill", 1);
2949 transition->set("internal_added", 237);
2950 field->plant_transition(*transition, transitiontrack, info.track);
2954 void Render::mltDeleteTransparency(int pos, int track, int id)
2956 Mlt::Service service(m_mltProducer->parent().get_service());
2957 Mlt::Tractor tractor(service);
2958 Mlt::Field *field = tractor.field();
2960 //if (do_refresh) m_mltConsumer->set("refresh", 0);
2961 mlt_service serv = m_mltProducer->parent().get_service();
2963 mlt_service nextservice = mlt_service_get_producer(serv);
2964 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
2965 QString mlt_type = mlt_properties_get(properties, "mlt_type");
2966 QString resource = mlt_properties_get(properties, "mlt_service");
2968 while (mlt_type == "transition") {
2969 mlt_transition tr = (mlt_transition) nextservice;
2970 int currentTrack = mlt_transition_get_b_track(tr);
2971 int currentIn = (int) mlt_transition_get_in(tr);
2972 int currentOut = (int) mlt_transition_get_out(tr);
2973 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
2974 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
2976 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
2977 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
2978 mlt_field_disconnect_service(field->get_field(), nextservice);
2981 nextservice = mlt_service_producer(nextservice);
2982 if (nextservice == NULL) break;
2983 properties = MLT_SERVICE_PROPERTIES(nextservice);
2984 mlt_type = mlt_properties_get(properties, "mlt_type");
2985 resource = mlt_properties_get(properties, "mlt_service");
2987 //if (do_refresh) m_mltConsumer->set("refresh", 1);
2990 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
2992 Mlt::Service service(m_mltProducer->parent().get_service());
2993 Mlt::Tractor tractor(service);
2995 mlt_service_lock(service.get_service());
2996 m_mltConsumer->set("refresh", 0);
2999 mlt_service serv = m_mltProducer->parent().get_service();
3000 mlt_service nextservice = mlt_service_get_producer(serv);
3001 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3002 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3003 QString resource = mlt_properties_get(properties, "mlt_service");
3004 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3005 while (mlt_type == "transition") {
3006 mlt_transition tr = (mlt_transition) nextservice;
3007 int currentTrack = mlt_transition_get_b_track(tr);
3008 int currentIn = (int) mlt_transition_get_in(tr);
3009 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3010 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3011 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3012 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3013 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3014 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3017 nextservice = mlt_service_producer(nextservice);
3018 if (nextservice == NULL) break;
3019 properties = MLT_SERVICE_PROPERTIES(nextservice);
3020 mlt_type = mlt_properties_get(properties, "mlt_type");
3021 resource = mlt_properties_get(properties, "mlt_service");
3023 mlt_service_unlock(service.get_service());
3025 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3029 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3031 Mlt::Service service(m_mltProducer->parent().get_service());
3032 Mlt::Tractor tractor(service);
3034 mlt_service_lock(service.get_service());
3035 m_mltConsumer->set("refresh", 0);
3038 mlt_service serv = m_mltProducer->parent().get_service();
3039 mlt_service nextservice = mlt_service_get_producer(serv);
3040 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3041 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3042 QString resource = mlt_properties_get(properties, "mlt_service");
3044 while (mlt_type == "transition") {
3045 mlt_transition tr = (mlt_transition) nextservice;
3046 int currentTrack = mlt_transition_get_b_track(tr);
3047 int currentaTrack = mlt_transition_get_a_track(tr);
3048 int currentIn = (int) mlt_transition_get_in(tr);
3049 int currentOut = (int) mlt_transition_get_out(tr);
3050 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3051 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3052 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3053 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3054 kDebug() << "//////MOVING";
3055 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3056 if (endTrack != startTrack) {
3057 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3058 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3059 mlt_properties_set_int(properties, "b_track", endTrack);
3063 nextservice = mlt_service_producer(nextservice);
3064 if (nextservice == NULL) break;
3065 properties = MLT_SERVICE_PROPERTIES(nextservice);
3066 mlt_type = mlt_properties_get(properties, "mlt_type");
3067 resource = mlt_properties_get(properties, "mlt_service");
3070 mlt_service_unlock(service.get_service());
3071 m_mltConsumer->set("refresh", 1);
3075 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3077 if (in >= out) return false;
3078 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3079 Mlt::Service service(m_mltProducer->parent().get_service());
3081 Mlt::Tractor tractor(service);
3082 Mlt::Field *field = tractor.field();
3084 char *transId = decodedString(tag);
3085 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId);
3086 if (out != GenTime())
3087 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3088 QMap<QString, QString>::Iterator it;
3090 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3091 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3092 if (xml.hasAttribute("id"))
3093 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3095 for (it = args.begin(); it != args.end(); ++it) {
3097 char *name = decodedString(key);
3098 char *value = decodedString(it.value());
3099 if (it.value().isEmpty() == false) transition->set(name, value);
3100 //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value;
3104 // attach filter to the clip
3105 field->plant_transition(*transition, a_track, b_track);
3107 if (do_refresh) refresh();
3111 void Render::mltSavePlaylist()
3113 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3114 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3115 fileConsumer.set("resource", "/tmp/playlist.mlt");
3117 Mlt::Service service(m_mltProducer->get_service());
3119 fileConsumer.connect(service);
3120 fileConsumer.start();
3123 const QList <Mlt::Producer *> Render::producersList()
3125 QList <Mlt::Producer *> prods;
3126 if (m_mltProducer == NULL) return prods;
3127 Mlt::Service service(m_mltProducer->parent().get_service());
3128 if (service.type() != tractor_type) return prods;
3129 Mlt::Tractor tractor(service);
3132 int trackNb = tractor.count();
3133 for (int t = 1; t < trackNb; t++) {
3134 Mlt::Producer *tt = tractor.track(t);
3135 Mlt::Producer trackProducer(tt);
3137 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3138 int clipNb = trackPlaylist.count();
3139 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3140 for (int i = 0; i < clipNb; i++) {
3141 Mlt::Producer *c = trackPlaylist.get_clip(i);
3142 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3144 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3145 ids.append(nprod->get("id"));
3146 prods.append(nprod);
3147 } else delete nprod;
3155 void Render::fillSlowMotionProducers()
3157 if (m_mltProducer == NULL) return;
3158 Mlt::Service service(m_mltProducer->parent().get_service());
3159 if (service.type() != tractor_type) return;
3161 Mlt::Tractor tractor(service);
3163 int trackNb = tractor.count();
3164 for (int t = 1; t < trackNb; t++) {
3165 Mlt::Producer *tt = tractor.track(t);
3166 Mlt::Producer trackProducer(tt);
3168 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3169 int clipNb = trackPlaylist.count();
3170 for (int i = 0; i < clipNb; i++) {
3171 Mlt::Producer *c = trackPlaylist.get_clip(i);
3172 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3174 QString id = nprod->get("id");
3175 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3176 // this is a slowmotion producer, add it to the list
3177 QString url = QString::fromUtf8(nprod->get("resource"));
3178 int strobe = nprod->get_int("strobe");
3179 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3180 if (!m_slowmotionProducers.contains(url)) {
3181 m_slowmotionProducers.insert(url, nprod);
3183 } else delete nprod;
3190 void Render::mltInsertTrack(int ix, bool videoTrack)
3195 Mlt::Service service(m_mltProducer->parent().get_service());
3196 mlt_service_lock(service.get_service());
3197 if (service.type() != tractor_type) {
3198 kWarning() << "// TRACTOR PROBLEM";
3202 Mlt::Tractor tractor(service);
3204 Mlt::Playlist playlist;
3205 int ct = tractor.count();
3207 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3213 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3214 tractor.set_track(playlist, pos);
3215 Mlt::Producer newProd(tractor.track(pos));
3216 if (!videoTrack) newProd.set("hide", 1);
3218 for (; pos <= ct; pos++) {
3219 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3220 tractor.set_track(*prodToMove, pos);
3221 prodToMove = prodToMove2;
3224 tractor.set_track(playlist, ix);
3225 Mlt::Producer newProd(tractor.track(ix));
3226 if (!videoTrack) newProd.set("hide", 1);
3230 mlt_service serv = m_mltProducer->parent().get_service();
3231 mlt_service nextservice = mlt_service_get_producer(serv);
3232 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3233 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3234 QString resource = mlt_properties_get(properties, "mlt_service");
3236 while (mlt_type == "transition") {
3237 if (resource != "mix") {
3238 mlt_transition tr = (mlt_transition) nextservice;
3239 int currentTrack = mlt_transition_get_b_track(tr);
3240 int currentaTrack = mlt_transition_get_a_track(tr);
3241 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3243 if (currentTrack >= ix) {
3244 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3245 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3248 nextservice = mlt_service_producer(nextservice);
3249 if (nextservice == NULL) break;
3250 properties = MLT_SERVICE_PROPERTIES(nextservice);
3251 mlt_type = mlt_properties_get(properties, "mlt_type");
3252 resource = mlt_properties_get(properties, "mlt_service");
3255 // Add audio mix transition to last track
3256 Mlt::Field *field = tractor.field();
3257 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3258 transition->set("a_track", 1);
3259 transition->set("b_track", ct);
3260 transition->set("always_active", 1);
3261 transition->set("internal_added", 237);
3262 transition->set("combine", 1);
3263 field->plant_transition(*transition, 1, ct);
3264 //mlt_service_unlock(m_mltConsumer->get_service());
3265 mlt_service_unlock(service.get_service());
3266 //tractor.multitrack()->refresh();
3267 //tractor.refresh();
3269 blockSignals(false);
3273 void Render::mltDeleteTrack(int ix)
3276 doc.setContent(sceneList(), false);
3277 int tracksCount = doc.elementsByTagName("track").count() - 1;
3278 QDomNode track = doc.elementsByTagName("track").at(ix);
3279 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3280 QDomNodeList transitions = doc.elementsByTagName("transition");
3281 for (int i = 0; i < transitions.count(); i++) {
3282 QDomElement e = transitions.at(i).toElement();
3283 QDomNodeList props = e.elementsByTagName("property");
3284 QMap <QString, QString> mappedProps;
3285 for (int j = 0; j < props.count(); j++) {
3286 QDomElement f = props.at(j).toElement();
3287 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3289 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3290 tractor.removeChild(transitions.at(i));
3292 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3293 // Transition needs to be moved
3294 int a_track = mappedProps.value("a_track").toInt();
3295 int b_track = mappedProps.value("b_track").toInt();
3296 if (a_track > 0 && a_track >= ix) a_track --;
3297 if (b_track > 0 && b_track >= ix) b_track --;
3298 for (int j = 0; j < props.count(); j++) {
3299 QDomElement f = props.at(j).toElement();
3300 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3301 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3306 tractor.removeChild(track);
3307 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3308 setSceneList(doc.toString(), m_framePosition);
3310 /* if (m_mltProducer != NULL) {
3311 Mlt::Producer parentProd(m_mltProducer->parent());
3312 if (parentProd.get_producer() != NULL) {
3313 Mlt::Service service(parentProd.get_service());
3314 if (service.type() == tractor_type) {
3315 Mlt::Tractor tractor(service);
3316 mltCheckLength(&tractor);
3323 void Render::updatePreviewSettings()
3325 kDebug() << "////// RESTARTING CONSUMER";
3326 if (!m_mltConsumer || !m_mltProducer) return;
3327 if (m_mltProducer->get_playtime() == 0) return;
3328 Mlt::Service service(m_mltProducer->parent().get_service());
3329 if (service.type() != tractor_type) return;
3331 //m_mltConsumer->set("refresh", 0);
3332 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3333 m_mltConsumer->purge();
3334 QString scene = sceneList();
3336 if (m_mltProducer) {
3337 pos = m_mltProducer->position();
3340 setSceneList(scene, pos);
3343 #include "renderer.moc"