1 /***************************************************************************
2 krender.cpp - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 copyright : (C) 2005 Lucio Flavio Correa
8 email : lucio.correa@gmail.com
9 copyright : (C) Marco Gittler
10 email : g.marco@freenet.de
11 copyright : (C) 2006 Jean-Baptiste Mardelle
12 email : jb@kdenlive.org
14 ***************************************************************************/
16 /***************************************************************************
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 ***************************************************************************/
27 #include "kdenlivesettings.h"
29 #include "definitions.h"
30 #include "slideshowclip.h"
32 #include <mlt++/Mlt.h>
35 #include <KStandardDirs>
36 #include <KMessageBox>
38 #include <KTemporaryFile>
43 #include <QApplication>
50 static void kdenlive_callback(void* /*ptr*/, int level, const char* fmt, va_list vl)
52 if (level > MLT_LOG_ERROR) return;
54 QApplication::postEvent(qApp->activeWindow(), new MltErrorEvent(error.vsprintf(fmt, vl).simplified()));
59 static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
61 // detect if the producer has finished playing. Is there a better way to do it?
62 if (self->m_isBlocked) return;
63 Mlt::Frame frame(frame_ptr);
64 if (!frame.is_valid()) return;
65 self->emitFrameNumber(mlt_frame_get_position(frame_ptr));
66 if (self->sendFrameForAnalysis && frame_ptr->convert_image) {
67 self->emitFrameUpdated(frame);
69 self->showAudio(frame);
70 if (frame.get_double("_speed") == 0.0) {
71 self->emitConsumerStopped();
72 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
74 self->emitConsumerStopped();
78 static void consumer_gl_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr)
80 // detect if the producer has finished playing. Is there a better way to do it?
81 if (self->m_isBlocked) return;
82 Mlt::Frame frame(frame_ptr);
83 self->showFrame(frame);
84 if (frame.get_double("_speed") == 0.0) {
85 self->emitConsumerStopped();
86 } else if (frame.get_double("_speed") < 0.0 && mlt_frame_get_position(frame_ptr) <= 0) {
88 self->emitConsumerStopped();
92 Render::Render(const QString & rendererName, int winid, QString profile, QWidget *parent) :
95 sendFrameForAnalysis(false),
103 m_isSplitView(false),
107 /*if (rendererName == "project") m_monitorId = 10000;
108 else m_monitorId = 10001;*/
109 /*m_osdTimer = new QTimer(this);
110 connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout()));*/
111 if (profile.isEmpty()) profile = KdenliveSettings::current_profile();
112 buildConsumer(profile);
114 m_mltProducer = m_blackClip->cut(0, 50);
115 m_mltConsumer->connect(*m_mltProducer);
116 m_mltProducer->set_speed(0.0);
126 void Render::closeMlt()
130 Mlt::Service service(m_mltProducer->parent().get_service());
131 mlt_service_lock(service.get_service());
133 if (service.type() == tractor_type) {
134 Mlt::Tractor tractor(service);
135 Mlt::Field *field = tractor.field();
136 mlt_service nextservice = mlt_service_get_producer(service.get_service());
137 mlt_service nextservicetodisconnect;
138 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
139 QString mlt_type = mlt_properties_get(properties, "mlt_type");
140 QString resource = mlt_properties_get(properties, "mlt_service");
141 // Delete all transitions
142 while (mlt_type == "transition") {
143 nextservicetodisconnect = nextservice;
144 nextservice = mlt_service_producer(nextservice);
145 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
146 nextservice = mlt_service_producer(nextservice);
147 if (nextservice == NULL) break;
148 properties = MLT_SERVICE_PROPERTIES(nextservice);
149 mlt_type = mlt_properties_get(properties, "mlt_type");
150 resource = mlt_properties_get(properties, "mlt_service");
153 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
154 Mlt::Producer trackProducer(tractor.track(trackNb));
155 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
156 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
159 mlt_service_unlock(service.get_service());
162 kDebug() << "// // // CLOSE RENDERER " << m_name;
163 delete m_mltConsumer;
164 delete m_mltProducer;
169 void Render::slotSwitchFullscreen()
171 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
174 void Render::buildConsumer(const QString profileName)
176 m_activeProfile = profileName;
177 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
178 setenv("MLT_PROFILE", tmp, 1);
182 //TODO: uncomment following line when everything is clean
183 //if (m_mltProfile) delete m_mltProfile;
184 m_mltProfile = new Mlt::Profile(tmp);
187 QString videoDriver = KdenliveSettings::videodrivername();
188 if (!videoDriver.isEmpty()) {
189 if (videoDriver == "x11_noaccel") {
190 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
193 unsetenv("SDL_VIDEO_YUV_HWACCEL");
196 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
198 //m_mltConsumer->set("fullscreen", 1);
201 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
202 m_mltConsumer->set("preview_off", 1);
203 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
204 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
206 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
207 // FIXME: the event object returned by the listen gets leaked...
208 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
209 m_mltConsumer->set("window_id", m_winid);
211 m_mltConsumer->set("resize", 1);
212 m_mltConsumer->set("terminate_on_pause", 1);
213 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
214 m_mltConsumer->set("rescale", "nearest");
215 mlt_log_set_callback(kdenlive_callback);
217 QString audioDevice = KdenliveSettings::audiodevicename();
218 if (!audioDevice.isEmpty())
219 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
221 if (!videoDriver.isEmpty())
222 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
224 QString audioDriver = KdenliveSettings::audiodrivername();
227 // Disabled because the "auto" detected driver was sometimes wrong
228 if (audioDriver.isEmpty())
229 audioDriver = KdenliveSettings::autoaudiodrivername();
232 if (!audioDriver.isEmpty())
233 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
235 int volume = KdenliveSettings::volume();
236 m_mltConsumer->set("volume", (float)volume / 100);
238 m_mltConsumer->set("progressive", 1);
239 m_mltConsumer->set("audio_buffer", 1024);
240 m_mltConsumer->set("frequency", 48000);
242 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
243 m_blackClip->set("id", "black");
244 m_blackClip->set("mlt_type", "producer");
247 Mlt::Producer *Render::invalidProducer(const QString &id)
249 Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
250 clip->set("id", id.toUtf8().constData());
251 clip->set("mlt_type", "producer");
255 int Render::resetProfile(const QString profileName)
258 QString videoDriver = KdenliveSettings::videodrivername();
259 QString currentDriver = m_mltConsumer->get("video_driver");
260 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
261 QString background = KdenliveSettings::window_background().name();
262 QString currentBackground = m_mltConsumer->get("window_background");
263 int volume = KdenliveSettings::volume();
264 int currentVolume = (int)(QString(m_mltConsumer->get("volume")).toDouble() * 100.0);
265 if (m_activeProfile == profileName && currentDriver == videoDriver && volume == currentVolume && background == currentBackground) {
266 kDebug() << "reset to same profile, nothing to do";
270 if (m_isSplitView) slotSplitView(false);
271 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
272 m_mltConsumer->purge();
273 delete m_mltConsumer;
274 m_mltConsumer = NULL;
276 QString scene = sceneList();
278 double current_fps = m_mltProfile->fps();
283 pos = m_mltProducer->position();
285 Mlt::Service service(m_mltProducer->get_service());
286 if (service.type() == tractor_type) {
287 Mlt::Tractor tractor(service);
288 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
289 Mlt::Producer trackProducer(tractor.track(trackNb));
290 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
291 trackPlaylist.clear();
295 delete m_mltProducer;
297 m_mltProducer = NULL;
298 buildConsumer(profileName);
299 double new_fps = m_mltProfile->fps();
300 if (current_fps != new_fps) {
301 // fps changed, we must update the scenelist positions
302 scene = updateSceneListFps(current_fps, new_fps, scene);
304 //kDebug() << "//RESET WITHSCENE: " << scene;
305 setSceneList(scene, pos);
306 // producers have changed (different profile), so reset them...
307 emit refreshDocumentProducers();
308 /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
309 m_mltProducer = producer;
310 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
311 m_mltProducer->optimise();
312 m_mltProducer->set_speed(0);
315 //delete m_mltProfile;
316 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
317 //mlt_profile prof = m_mltProfile->get_profile();
318 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
319 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
320 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
321 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
323 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
328 void Render::seek(GenTime time)
333 m_mltProducer->seek((int)(time.frames(m_fps)));
338 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
339 QPixmap pix(width, height);
341 mlt_image_format format = mlt_image_rgb24a;
342 uint8_t *thumb = frame->get_image(format, width, height);
343 QImage image(thumb, width, height, QImage::Format_ARGB32);
345 if (!image.isNull()) {
346 pix = pix.fromImage(image);
348 QPainter painter(&pix);
349 painter.drawRect(0, 0, width - 1, height - 1);
351 } else pix.fill(Qt::black);
355 int Render::frameRenderWidth() const
357 return m_mltProfile->width();
360 int Render::renderWidth() const
362 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
365 int Render::renderHeight() const
367 return m_mltProfile->height();
370 QImage Render::extractFrame(int frame_position, int width, int height)
373 width = renderWidth();
374 height = renderHeight();
375 } else if (width % 2 == 1) width++;
377 if (!m_mltProducer) {
378 QImage pix(width, height, QImage::Format_RGB32);
382 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
385 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
389 if (url.fileName().startsWith(".all.")) { // check for slideshow
390 QString fileType = url.fileName().right(3);
392 QStringList::Iterator it;
394 QDir dir(url.directory());
396 filter << "*." + fileType;
397 filter << "*." + fileType.toUpper();
398 more = dir.entryList(filter, QDir::Files);
399 im.load(url.directory() + '/' + more.at(0));
400 } else im.load(url.path());
401 //pixmap = im.scaled(width, height);
405 double Render::consumerRatio() const
407 if (!m_mltConsumer) return 1.0;
408 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
412 int Render::getLength()
416 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
417 return mlt_producer_get_playtime(m_mltProducer->get_producer());
422 bool Render::isValid(KUrl url)
424 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
425 if (producer.is_blank())
431 double Render::dar() const
433 return m_mltProfile->dar();
437 void Render::slotSplitView(bool doit)
439 m_isSplitView = doit;
440 Mlt::Service service(m_mltProducer->parent().get_service());
441 Mlt::Tractor tractor(service);
442 if (service.type() != tractor_type || tractor.count() < 2) return;
443 Mlt::Field *field = tractor.field();
445 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
446 Mlt::Producer trackProducer(tractor.track(i));
447 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
448 if (QString(trackProducer.get("hide")).toInt() != 1) {
449 kDebug() << "// ADIDNG TRACK: " << i;
450 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
451 transition->set("mlt_service", "composite");
452 transition->set("a_track", 0);
453 transition->set("b_track", i);
454 transition->set("distort", 1);
455 transition->set("internal_added", "200");
462 tmp = "50%,0:50%x50%";
465 tmp = "0,50%:50%x50%";
469 tmp = "50%,50%:50%x50%";
472 transition->set("geometry", tmp);
473 transition->set("always_active", "1");
474 field->plant_transition(*transition, 0, i);
479 m_mltConsumer->set("refresh", 1);
481 mlt_service serv = m_mltProducer->parent().get_service();
482 mlt_service nextservice = mlt_service_get_producer(serv);
483 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
484 QString mlt_type = mlt_properties_get(properties, "mlt_type");
485 QString resource = mlt_properties_get(properties, "mlt_service");
487 while (mlt_type == "transition") {
488 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
489 if (added == "200") {
490 mlt_field_disconnect_service(field->get_field(), nextservice);
492 nextservice = mlt_service_producer(nextservice);
493 if (nextservice == NULL) break;
494 properties = MLT_SERVICE_PROPERTIES(nextservice);
495 mlt_type = mlt_properties_get(properties, "mlt_type");
496 resource = mlt_properties_get(properties, "mlt_service");
497 m_mltConsumer->set("refresh", 1);
502 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
504 KUrl url = KUrl(xml.attribute("resource", QString()));
505 Mlt::Producer *producer = NULL;
506 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
507 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
508 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
511 if (xml.attribute("type").toInt() == COLOR) {
512 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
513 } else if (xml.attribute("type").toInt() == TEXT) {
514 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
515 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
516 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
517 } else if (url.isEmpty()) {
519 QDomElement mlt = doc.createElement("mlt");
520 QDomElement play = doc.createElement("playlist");
521 doc.appendChild(mlt);
522 mlt.appendChild(play);
523 play.appendChild(doc.importNode(xml, true));
524 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
526 producer = new Mlt::Producer(*m_mltProfile, url.path().toUtf8().constData());
529 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
530 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
531 emit removeInvalidClip(clipId, replaceProducer);
536 if (xml.hasAttribute("force_aspect_ratio")) {
537 double aspect = xml.attribute("force_aspect_ratio").toDouble();
538 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
541 if (xml.hasAttribute("force_fps")) {
542 double fps = xml.attribute("force_fps").toDouble();
543 if (fps > 0) producer->set("force_fps", fps);
546 if (xml.hasAttribute("force_progressive")) {
548 int progressive = xml.attribute("force_progressive").toInt(&ok);
549 if (ok) producer->set("force_progressive", progressive);
551 if (xml.hasAttribute("threads")) {
552 int threads = xml.attribute("threads").toInt();
553 if (threads != 1) producer->set("threads", threads);
555 if (xml.hasAttribute("video_index")) {
556 int vindex = xml.attribute("video_index").toInt();
557 if (vindex != 0) producer->set("video_index", vindex);
559 if (xml.hasAttribute("audio_index")) {
560 int aindex = xml.attribute("audio_index").toInt();
561 if (aindex != 0) producer->set("audio_index", aindex);
564 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
565 if (xml.attribute("type").toInt() == COLOR || xml.attribute("type").toInt() == TEXT
566 || xml.attribute("type").toInt() == IMAGE || xml.attribute("type").toInt() == SLIDESHOW)
567 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
569 if (xml.hasAttribute("out"))
570 producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
572 producer->set("id", clipId.toUtf8().constData());
574 if (xml.hasAttribute("templatetext"))
575 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
577 if (!replaceProducer && xml.hasAttribute("file_hash")) {
578 // Clip already has all properties
579 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
583 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
584 QMap < QString, QString > filePropertyMap;
585 QMap < QString, QString > metadataPropertyMap;
587 int frameNumber = xml.attribute("thumbnail", "0").toInt();
588 if (frameNumber != 0) producer->seek(frameNumber);
590 filePropertyMap["duration"] = QString::number(producer->get_playtime());
591 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
593 Mlt::Frame *frame = producer->get_frame();
595 if (xml.attribute("type").toInt() == SLIDESHOW) {
596 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
597 if (ttl) producer->set("ttl", ttl);
598 if (!xml.attribute("animation").isEmpty()) {
599 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
600 if (filter && filter->is_valid()) {
602 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
603 if (!geometry.isEmpty()) {
604 if (xml.attribute("animation").contains("low-pass")) {
605 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
606 if (blur && blur->is_valid())
607 producer->attach(*blur);
609 filter->set("transition.geometry", geometry.toUtf8().data());
610 filter->set("transition.cycle", cycle);
611 producer->attach(*filter);
615 if (xml.attribute("fade") == "1") {
616 // user wants a fade effect to slideshow
617 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
618 if (filter && filter->is_valid()) {
619 if (ttl) filter->set("cycle", ttl);
620 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
621 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
622 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
623 if (xml.hasAttribute("softness")) {
624 int soft = xml.attribute("softness").toInt();
625 filter->set("luma.softness", (double) soft / 100.0);
628 producer->attach(*filter);
631 if (xml.attribute("crop") == "1") {
632 // user wants to center crop the slides
633 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
634 if (filter && filter->is_valid()) {
635 filter->set("center", 1);
636 producer->attach(*filter);
642 filePropertyMap["fps"] = producer->get("source_fps");
644 if (frame && frame->is_valid()) {
645 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
646 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
647 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
648 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
650 if (frame->get_int("test_image") == 0) {
651 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
652 filePropertyMap["type"] = "playlist";
653 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
654 } else if (frame->get_int("test_audio") == 0)
655 filePropertyMap["type"] = "av";
657 filePropertyMap["type"] = "video";
659 mlt_image_format format = mlt_image_rgb24a;
660 int frame_width = width;
661 int frame_height = imageHeight;
662 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
663 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied);
666 if (!image.isNull()) {
667 if (frame_width > (2 * width)) {
668 // there was a scaling problem, do it manually
669 QImage scaled = image.scaled(width, imageHeight);
670 pix = QPixmap::fromImage(scaled.rgbSwapped());
671 } else pix = QPixmap::fromImage(image.rgbSwapped());
675 emit replyGetImage(clipId, pix);
677 } else if (frame->get_int("test_audio") == 0) {
678 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
679 emit replyGetImage(clipId, pixmap);
680 filePropertyMap["type"] = "audio";
684 // Retrieve audio / video codec name
688 if (producer->get_int("video_index") > -1) {
689 /*if (context->duration == AV_NOPTS_VALUE) {
690 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
691 emit removeInvalidClip(clipId);
695 // Get the video_index
696 int default_video = producer->get_int("video_index");
698 int default_audio = producer->get_int("audio_index");
701 // Find maximum stream index values
702 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
703 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
704 QString type = producer->get(property);
707 else if (type == "audio")
710 filePropertyMap["default_video"] = QString::number(default_video);
711 filePropertyMap["video_max"] = QString::number(video_max);
712 filePropertyMap["default_audio"] = QString::number(default_audio);
713 filePropertyMap["audio_max"] = QString::number(audio_max);
715 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
716 if (producer->get(property)) {
717 filePropertyMap["videocodec"] = producer->get(property);
719 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
720 if (producer->get(property))
721 filePropertyMap["videocodec"] = producer->get(property);
724 if (KdenliveSettings::dropbframes()) {
725 kDebug() << "// LOOKING FOR H264 on: " << default_video;
726 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
727 kDebug() << "PROP: " << property << " = " << producer->get(property);
728 if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) {
729 kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS";
730 producer->set("skip_loop_filter", "all");
731 producer->set("skip_frame", "bidir");
735 } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!";
736 if (producer->get_int("audio_index") > -1) {
737 // Get the audio_index
738 int index = producer->get_int("audio_index");
740 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index);
741 if (producer->get(property)) {
742 filePropertyMap["audiocodec"] = producer->get(property);
744 snprintf(property, sizeof(property), "meta.media.%d.codec.name", index);
745 if (producer->get(property))
746 filePropertyMap["audiocodec"] = producer->get(property);
751 Mlt::Properties metadata;
752 metadata.pass_values(*producer, "meta.attr.");
753 int count = metadata.count();
754 for (int i = 0; i < count; i ++) {
755 QString name = metadata.get_name(i);
756 QString value = QString::fromUtf8(metadata.get(i));
757 if (name.endsWith("markup") && !value.isEmpty())
758 metadataPropertyMap[ name.section('.', 0, -2)] = value;
761 kDebug() << "REquested fuile info for: " << url.path();
762 emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer);
763 // FIXME: should delete this to avoid a leak...
769 /** Create the producer from the MLT XML QDomDocument */
770 void Render::initSceneList()
772 kDebug() << "-------- INIT SCENE LIST ------_";
774 QDomElement mlt = doc.createElement("mlt");
775 doc.appendChild(mlt);
776 QDomElement prod = doc.createElement("producer");
777 prod.setAttribute("resource", "colour");
778 prod.setAttribute("colour", "red");
779 prod.setAttribute("id", "black");
780 prod.setAttribute("in", "0");
781 prod.setAttribute("out", "0");
783 QDomElement tractor = doc.createElement("tractor");
784 QDomElement multitrack = doc.createElement("multitrack");
786 QDomElement playlist1 = doc.createElement("playlist");
787 playlist1.appendChild(prod);
788 multitrack.appendChild(playlist1);
789 QDomElement playlist2 = doc.createElement("playlist");
790 multitrack.appendChild(playlist2);
791 QDomElement playlist3 = doc.createElement("playlist");
792 multitrack.appendChild(playlist3);
793 QDomElement playlist4 = doc.createElement("playlist");
794 multitrack.appendChild(playlist4);
795 QDomElement playlist5 = doc.createElement("playlist");
796 multitrack.appendChild(playlist5);
797 tractor.appendChild(multitrack);
798 mlt.appendChild(tractor);
799 // kDebug()<<doc.toString();
801 QString tmp = QString("<mlt><producer resource=\"colour\" colour=\"red\" id=\"red\" /><tractor><multitrack><playlist></playlist><playlist></playlist><playlist /><playlist /><playlist></playlist></multitrack></tractor></mlt>");*/
802 setSceneList(doc, 0);
806 int Render::setProducer(Mlt::Producer *producer, int position)
808 if (m_winid == -1) return -1;
811 m_mltConsumer->stop();
814 m_mltConsumer->purge();
818 m_mltProducer->set_speed(0);
819 delete m_mltProducer;
820 m_mltProducer = NULL;
824 m_mltProducer = new Mlt::Producer(producer->get_producer());
825 } else m_mltProducer = m_blackClip->cut(0, 50);
826 /*if (KdenliveSettings::dropbframes()) {
827 m_mltProducer->set("skip_loop_filter", "all");
828 m_mltProducer->set("skip_frame", "bidir");
830 if (!m_mltProducer || !m_mltProducer->is_valid()) {
831 kDebug() << " WARNING - - - - -INVALID PLAYLIST: ";
835 m_fps = m_mltProducer->get_fps();
836 int error = connectPlaylist();
838 if (position != -1) {
839 m_mltProducer->seek(position);
840 emit rendererPosition(position);
841 } else emit rendererPosition((int) m_mltProducer->position());
846 int Render::setSceneList(QDomDocument list, int position)
848 return setSceneList(list.toString(), position);
851 int Render::setSceneList(QString playlist, int position)
853 if (m_winid == -1) return -1;
857 kDebug() << "////// RENDER, SET SCENE LIST: " << playlist;
860 if (!m_mltConsumer->is_stopped()) {
861 m_mltConsumer->stop();
863 m_mltConsumer->set("refresh", 0);
865 kWarning() << "/////// ERROR, TRYING TO USE NULL MLT CONSUMER";
870 m_mltProducer->set_speed(0);
871 //if (KdenliveSettings::osdtimecode() && m_osdInfo) m_mltProducer->detach(*m_osdInfo);
874 Mlt::Service service(m_mltProducer->parent().get_service());
875 mlt_service_lock(service.get_service());
877 if (service.type() == tractor_type) {
878 Mlt::Tractor tractor(service);
879 Mlt::Field *field = tractor.field();
880 mlt_service nextservice = mlt_service_get_producer(service.get_service());
881 mlt_service nextservicetodisconnect;
882 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
883 QString mlt_type = mlt_properties_get(properties, "mlt_type");
884 QString resource = mlt_properties_get(properties, "mlt_service");
885 // Delete all transitions
886 while (mlt_type == "transition") {
887 nextservicetodisconnect = nextservice;
888 nextservice = mlt_service_producer(nextservice);
889 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
890 if (nextservice == NULL) break;
891 properties = MLT_SERVICE_PROPERTIES(nextservice);
892 mlt_type = mlt_properties_get(properties, "mlt_type");
893 resource = mlt_properties_get(properties, "mlt_service");
896 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
897 Mlt::Producer trackProducer(tractor.track(trackNb));
898 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
899 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
903 mlt_service_unlock(service.get_service());
905 qDeleteAll(m_slowmotionProducers.values());
906 m_slowmotionProducers.clear();
908 delete m_mltProducer;
909 m_mltProducer = NULL;
914 m_mltProducer = new Mlt::Producer(*m_mltProfile, "xml-string", playlist.toUtf8().constData());
916 if (!m_mltProducer || !m_mltProducer->is_valid()) {
917 kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << playlist.toUtf8().constData();
918 m_mltProducer = m_blackClip->cut(0, 50);
922 m_mltProducer->optimise();
924 /*if (KdenliveSettings::osdtimecode()) {
925 // Attach filter for on screen display of timecode
927 QString attr = "attr_check";
928 mlt_filter filter = mlt_factory_filter( "data_feed", (char*) attr.ascii() );
929 mlt_properties_set_int( MLT_FILTER_PROPERTIES( filter ), "_loader", 1 );
930 mlt_producer_attach( m_mltProducer->get_producer(), filter );
931 mlt_filter_close( filter );
933 m_osdInfo = new Mlt::Filter("data_show");
934 m_osdInfo->set("resource", m_osdProfile.toUtf8().constData());
935 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
936 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
937 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
938 m_osdInfo->set("dynamic", "1");
940 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
942 m_osdInfo->set("dynamic", "0");
945 m_fps = m_mltProducer->get_fps();
947 // Seek to correct place after opening project.
948 m_mltProducer->seek(position);
951 kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime();
952 if (error == 0) error = connectPlaylist();
953 else connectPlaylist();
954 fillSlowMotionProducers();
960 //kDebug()<<"// SETSCN LST, POS: "<<position;
961 //if (position != 0) emit rendererPosition(position);
964 const QString Render::sceneList()
967 Mlt::Consumer xmlConsumer(*m_mltProfile, "xml:kdenlive_playlist");
968 m_mltProducer->optimise();
969 xmlConsumer.set("terminate_on_pause", 1);
970 Mlt::Producer prod(m_mltProducer->get_producer());
971 bool split = m_isSplitView;
972 if (split) slotSplitView(false);
973 xmlConsumer.connect(prod);
975 while (!xmlConsumer.is_stopped()) {}
976 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
977 if (split) slotSplitView(true);
981 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
985 doc.setContent(sceneList(), false);
986 if (!kdenliveData.isNull()) {
987 // add Kdenlive specific tags
988 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
989 mlt.appendChild(doc.importNode(kdenliveData, true));
991 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
992 kWarning() << "////// ERROR writing to file: " << path;
995 file.write(doc.toString().toUtf8());
996 if (file.error() != QFile::NoError) {
1004 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1006 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1007 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1008 m_mltProducer->optimise();
1009 xmlConsumer.set("terminate_on_pause", 1);
1010 if (m_name == "clip") {
1011 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1013 list.insert_at(0, prod, 0);
1015 list.set("title", desc.toUtf8().constData());
1016 xmlConsumer.connect(list);
1019 //TODO: not working yet, save zone from timeline
1020 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1021 /* Mlt::Service service(p1->parent().get_service());
1022 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1024 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1025 //prod->set("title", desc.toUtf8().constData());
1026 xmlConsumer.connect(*p1); //list);
1029 xmlConsumer.start();
1032 double Render::fps() const
1037 int Render::connectPlaylist()
1039 if (!m_mltConsumer) return -1;
1040 //m_mltConsumer->set("refresh", "0");
1041 m_mltConsumer->connect(*m_mltProducer);
1042 m_mltProducer->set_speed(0);
1043 if (m_mltConsumer->start() == -1) {
1044 // ARGH CONSUMER BROKEN!!!!
1045 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."));
1046 delete m_mltConsumer;
1047 m_mltConsumer = NULL;
1050 emit durationChanged(m_mltProducer->get_playtime());
1055 void Render::refreshDisplay()
1058 if (!m_mltProducer) return;
1059 //m_mltConsumer->set("refresh", 0);
1061 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1062 /*if (KdenliveSettings::osdtimecode()) {
1063 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1064 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1065 m_osdInfo->set("dynamic", "1");
1066 m_mltProducer->attach(*m_osdInfo);
1069 m_mltProducer->detach(*m_osdInfo);
1070 m_osdInfo->set("dynamic", "0");
1075 void Render::setVolume(double /*volume*/)
1077 if (!m_mltConsumer || !m_mltProducer) return;
1079 m_mltConsumer->set("refresh", 0);
1080 // Attach filter for on screen display of timecode
1081 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1082 mlt_properties_set_double( properties, "meta.volume", volume );
1083 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1084 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1086 if (!KdenliveSettings::osdtimecode()) {
1087 m_mltProducer->detach(*m_osdInfo);
1088 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1089 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1092 //m_osdTimer->setSingleShot(2500);
1095 void Render::slotOsdTimeout()
1097 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1098 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1099 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1100 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1104 void Render::start()
1106 kDebug() << "----- STARTING MONITOR: " << m_name;
1107 if (m_winid == -1) {
1108 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1111 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1112 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1113 if (m_mltConsumer->start() == -1) {
1114 //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."));
1115 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1117 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1118 m_isBlocked = false;
1122 m_isBlocked = false;
1127 if (m_mltProducer == NULL) return;
1128 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1129 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1131 //m_mltConsumer->set("refresh", 0);
1132 m_mltConsumer->stop();
1133 // delete m_mltConsumer;
1134 // m_mltConsumer = NULL;
1136 kDebug() << "///////////// RENDER STOP2-------";
1139 if (m_mltProducer) {
1140 if (m_isZoneMode) resetZoneMode();
1141 m_mltProducer->set_speed(0.0);
1142 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1143 //kDebug() << m_mltProducer->get_length();
1145 kDebug() << "///////////// RENDER STOP3-------";
1148 void Render::stop(const GenTime & startTime)
1151 kDebug() << "///////////// RENDER STOP-------2";
1152 if (m_mltProducer) {
1153 if (m_isZoneMode) resetZoneMode();
1154 m_mltProducer->set_speed(0.0);
1155 m_mltProducer->seek((int) startTime.frames(m_fps));
1157 m_mltConsumer->purge();
1160 void Render::pause()
1162 if (!m_mltProducer || !m_mltConsumer)
1164 if (m_mltProducer->get_speed() == 0.0) return;
1165 if (m_isZoneMode) resetZoneMode();
1167 m_mltConsumer->set("refresh", 0);
1168 m_mltProducer->set_speed(0.0);
1170 The 2 lines below create a flicker loop
1171 emit rendererPosition(m_framePosition);
1172 m_mltProducer->seek(m_framePosition);*/
1173 m_mltConsumer->purge();
1176 void Render::switchPlay()
1178 if (!m_mltProducer || !m_mltConsumer)
1180 if (m_isZoneMode) resetZoneMode();
1181 if (m_mltProducer->get_speed() == 0.0) {
1182 m_isBlocked = false;
1183 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1184 m_mltProducer->set_speed(1.0);
1185 m_mltConsumer->set("refresh", 1);
1188 m_mltConsumer->set("refresh", 0);
1189 m_mltProducer->set_speed(0.0);
1190 //emit rendererPosition(m_framePosition);
1191 m_mltProducer->seek(m_framePosition);
1192 m_mltConsumer->purge();
1193 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1194 //m_mltConsumer->set("refresh", 0);
1195 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1196 m_mltProducer->set_speed(0);
1197 m_mltProducer->seek( position );
1198 //m_mltProducer->seek((int) m_framePosition);
1199 m_isBlocked = false;*/
1201 /*if (speed == 0.0) {
1202 m_mltProducer->seek((int) m_framePosition + 1);
1203 m_mltConsumer->purge();
1208 void Render::play(double speed)
1212 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1213 m_isBlocked = false;
1214 m_mltProducer->set_speed(speed);
1215 /*if (speed == 0.0) {
1216 m_mltProducer->seek((int) m_framePosition + 1);
1217 m_mltConsumer->purge();
1222 void Render::play(const GenTime & startTime)
1224 if (!m_mltProducer || !m_mltConsumer)
1226 m_isBlocked = false;
1227 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1228 m_mltProducer->set_speed(1.0);
1229 m_mltConsumer->set("refresh", 1);
1232 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1234 if (!m_mltProducer || !m_mltConsumer)
1236 //m_mltProducer->set("eof", "loop");
1237 m_isLoopMode = true;
1238 m_loopStart = startTime;
1239 playZone(startTime, stopTime);
1242 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1244 if (!m_mltProducer || !m_mltConsumer)
1246 m_isBlocked = false;
1247 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1248 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1249 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1250 m_mltProducer->set_speed(1.0);
1251 m_mltConsumer->set("refresh", 1);
1252 m_isZoneMode = true;
1255 void Render::resetZoneMode()
1257 if (!m_isZoneMode && !m_isLoopMode) return;
1258 m_mltProducer->set("out", m_originalOut);
1259 //m_mltProducer->set("eof", "pause");
1260 m_isZoneMode = false;
1261 m_isLoopMode = false;
1264 void Render::seekToFrame(int pos)
1266 //kDebug()<<" ********* RENDER SEEK TO POS";
1269 m_isBlocked = false;
1271 m_mltProducer->seek(pos);
1275 void Render::seekToFrameDiff(int diff)
1277 //kDebug()<<" ********* RENDER SEEK TO POS";
1280 m_isBlocked = false;
1282 m_mltProducer->seek(m_mltProducer->position() + diff);
1286 void Render::doRefresh()
1288 // Use a Timer so that we don't refresh too much
1289 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1292 void Render::refresh()
1294 if (!m_mltProducer || m_isBlocked)
1296 if (m_mltConsumer) {
1297 m_mltConsumer->set("refresh", 1);
1301 void Render::setDropFrames(bool show)
1303 if (m_mltConsumer) {
1305 if (show == false) dropFrames = 0;
1306 m_mltConsumer->stop();
1308 m_mltConsumer->set("real_time", dropFrames);
1310 m_mltConsumer->set("play.real_time", dropFrames);
1312 if (m_mltConsumer->start() == -1) {
1313 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1319 double Render::playSpeed()
1321 if (m_mltProducer) return m_mltProducer->get_speed();
1325 GenTime Render::seekPosition() const
1327 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1328 else return GenTime();
1331 int Render::seekFramePosition() const
1333 if (m_mltProducer) return (int) m_mltProducer->position();
1337 const QString & Render::rendererName() const
1342 void Render::emitFrameUpdated(Mlt::Frame& frame)
1344 mlt_image_format format = mlt_image_rgb24a;
1347 const uchar* image = frame.get_image(format, width, height);
1348 QImage qimage(width, height, QImage::Format_ARGB32);
1349 memcpy(qimage.bits(), image, width * height * 4);
1350 emit frameUpdated(qimage.rgbSwapped());
1353 void Render::emitFrameNumber(double position)
1355 m_framePosition = position;
1356 emit rendererPosition((int) position);
1359 void Render::emitConsumerStopped()
1361 // This is used to know when the playing stopped
1362 if (m_mltProducer) {
1363 double pos = m_mltProducer->position();
1364 if (m_isLoopMode) play(m_loopStart);
1365 else if (m_isZoneMode) resetZoneMode();
1366 emit rendererStopped((int) pos);
1367 //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent(GenTime((int) pos, m_fps), m_monitorId + 100));
1368 //new QCustomEvent(10002));
1372 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1374 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1377 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1379 if (!m_mltProducer) {
1380 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1384 //int height = 1080;//KdenliveSettings::defaultheight();
1385 //int width = 1940; //KdenliveSettings::displaywidth();
1387 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1389 QPixmap pix(width, height);
1390 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1391 m_convert.set("forced", mlt_image_rgb24a);
1392 m_mltProducer->attach(m_convert);
1393 Mlt::Frame * frame = m_mltProducer->get_frame();
1394 m_mltProducer->detach(m_convert);
1396 pix = frameThumbnail(frame, width, height);
1399 pix.save(url.path(), "PNG");
1400 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1404 void Render::showFrame(Mlt::Frame& frame)
1406 m_framePosition = qMax(frame.get_int("_position"), 0);
1407 emit rendererPosition((int) m_framePosition);
1408 mlt_image_format format = mlt_image_rgb24a;
1411 const uchar* image = frame.get_image(format, width, height);
1412 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1413 memcpy(qimage.scanLine(0), image, width * height * 4);
1414 emit showImageSignal(qimage);
1416 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1417 emit frameUpdated(qimage.rgbSwapped());
1421 void Render::showAudio(Mlt::Frame& frame)
1423 if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
1424 mlt_audio_format audio_format = mlt_audio_pcm;
1426 int num_channels = 0;
1428 uint8_t* data = (uint8_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1432 QByteArray channels;
1433 for (int i = 0; i < num_channels; i++) {
1434 /* switch (audio_format)
1437 value=( ( (uint8_t*)data) [i] );
1440 value=( ( (uint16_t*)data) [i] >> 8 );
1443 value=( ((uint32_t*)data) [i] >> 16 );
1446 value=( ((float*)data) [i]*255);
1453 int num_samples = 20;
1454 for (int s = 0; s < samples; s += samples / num_samples) {
1455 val += (data[i+s*num_channels] - 127);
1457 channels.append(val / num_samples);
1462 emit showAudioSignal(channels);
1466 * MLT playlist direct manipulation.
1469 void Render::mltCheckLength(Mlt::Tractor *tractor)
1471 //kDebug()<<"checking track length: "<<track<<"..........";
1473 int trackNb = tractor->count();
1477 Mlt::Producer trackProducer(tractor->track(0));
1478 duration = trackProducer.get_playtime() - 1;
1479 m_mltProducer->set("out", duration);
1480 emit durationChanged(duration);
1483 while (trackNb > 1) {
1484 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1485 trackDuration = trackProducer.get_playtime() - 1;
1486 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1487 if (trackDuration > duration) duration = trackDuration;
1491 Mlt::Producer blackTrackProducer(tractor->track(0));
1493 if (blackTrackProducer.get_playtime() - 1 != duration) {
1494 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1495 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1496 if (blackclip && blackclip->is_blank()) {
1501 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1502 blackTrackPlaylist.clear();
1503 m_blackClip->set("length", duration + 1);
1504 m_blackClip->set("out", duration);
1505 blackclip = m_blackClip->cut(0, duration);
1506 blackTrackPlaylist.insert_at(0, blackclip, 1);
1508 if (duration > blackclip->parent().get_length()) {
1509 blackclip->parent().set("length", duration + 1);
1510 blackclip->parent().set("out", duration);
1511 blackclip->set("length", duration + 1);
1513 blackTrackPlaylist.resize_clip(0, 0, duration);
1517 m_mltProducer->set("out", duration);
1518 emit durationChanged(duration);
1522 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1524 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1526 // We want a slowmotion producer
1527 double speed = element.attribute("speed", "1.0").toDouble();
1528 int strobe = element.attribute("strobe", "1").toInt();
1529 QString url = QString::fromUtf8(prod->get("resource"));
1530 url.append('?' + QString::number(speed));
1531 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1532 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1533 if (!slowprod || slowprod->get_producer() == NULL) {
1534 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1535 if (strobe > 1) slowprod->set("strobe", strobe);
1536 QString id = prod->get("id");
1537 if (id.contains('_')) id = id.section('_', 0, 0);
1538 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1539 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1540 slowprod->set("id", producerid.toUtf8().constData());
1541 m_slowmotionProducers.insert(url, slowprod);
1546 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1548 if (m_mltProducer == NULL) {
1549 kDebug() << "PLAYLIST NOT INITIALISED //////";
1553 kDebug() << "Cannot insert clip without producer //////";
1556 Mlt::Producer parentProd(m_mltProducer->parent());
1557 if (parentProd.get_producer() == NULL) {
1558 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1562 Mlt::Service service(parentProd.get_service());
1563 if (service.type() != tractor_type) {
1564 kWarning() << "// TRACTOR PROBLEM";
1567 Mlt::Tractor tractor(service);
1568 if (info.track > tractor.count() - 1) {
1569 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1572 mlt_service_lock(service.get_service());
1573 Mlt::Producer trackProducer(tractor.track(info.track));
1574 int trackDuration = trackProducer.get_playtime() - 1;
1575 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1576 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1577 prod = checkSlowMotionProducer(prod, element);
1578 if (prod == NULL || !prod->is_valid()) {
1579 mlt_service_unlock(service.get_service());
1583 int cutPos = (int) info.cropStart.frames(m_fps);
1584 if (cutPos < 0) cutPos = 0;
1585 int insertPos = (int) info.startPos.frames(m_fps);
1586 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1587 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1588 if (overwrite && (insertPos < trackDuration)) {
1589 // Replace zone with blanks
1590 //trackPlaylist.split_at(insertPos, true);
1591 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1592 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1593 trackPlaylist.insert_blank(clipIndex, cutDuration);
1595 trackPlaylist.split_at(insertPos, true);
1596 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1597 trackPlaylist.insert_blank(clipIndex, cutDuration);
1599 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1601 /*if (QString(prod->get("transparency")).toInt() == 1)
1602 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1604 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1605 mlt_service_unlock(service.get_service());
1606 /*tractor.multitrack()->refresh();
1607 tractor.refresh();*/
1612 void Render::mltCutClip(int track, GenTime position)
1616 Mlt::Service service(m_mltProducer->parent().get_service());
1617 if (service.type() != tractor_type) {
1618 kWarning() << "// TRACTOR PROBLEM";
1622 Mlt::Tractor tractor(service);
1623 Mlt::Producer trackProducer(tractor.track(track));
1624 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1627 /* // Display playlist info
1628 kDebug()<<"//////////// BEFORE";
1629 for (int i = 0; i < trackPlaylist.count(); i++) {
1630 int blankStart = trackPlaylist.clip_start(i);
1631 int blankDuration = trackPlaylist.clip_length(i) - 1;
1633 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1634 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1637 int cutPos = (int) position.frames(m_fps);
1639 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1640 if (trackPlaylist.is_blank(clipIndex)) {
1641 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1642 m_isBlocked = false;
1645 mlt_service_lock(service.get_service());
1646 int clipStart = trackPlaylist.clip_start(clipIndex);
1647 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1648 mlt_service_unlock(service.get_service());
1650 // duplicate effects
1651 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1652 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1654 if (original == NULL || clip == NULL) {
1655 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1657 Mlt::Service clipService(original->get_service());
1658 Mlt::Service dupService(clip->get_service());
1662 Mlt::Filter *filter = clipService.filter(ct);
1664 // Only duplicate Kdenlive filters, and skip the fade in effects
1665 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1666 // looks like there is no easy way to duplicate a filter,
1667 // so we will create a new one and duplicate its properties
1668 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1669 if (dup && dup->is_valid()) {
1670 Mlt::Properties entries(filter->get_properties());
1671 for (int i = 0; i < entries.count(); i++) {
1672 dup->set(entries.get_name(i), entries.get(i));
1674 dupService.attach(*dup);
1678 filter = clipService.filter(ct);
1681 /* // Display playlist info
1682 kDebug()<<"//////////// AFTER";
1683 for (int i = 0; i < trackPlaylist.count(); i++) {
1684 int blankStart = trackPlaylist.clip_start(i);
1685 int blankDuration = trackPlaylist.clip_length(i) - 1;
1687 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1688 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1691 m_isBlocked = false;
1694 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1698 kDebug() << "Cannot update clip with null producer //////";
1701 Mlt::Service service(m_mltProducer->parent().get_service());
1702 if (service.type() != tractor_type) {
1703 kWarning() << "// TRACTOR PROBLEM";
1706 Mlt::Tractor tractor(service);
1707 Mlt::Producer trackProducer(tractor.track(info.track));
1708 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1709 int startPos = info.startPos.frames(m_fps);
1710 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1711 if (trackPlaylist.is_blank(clipIndex)) {
1712 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1715 mlt_service_lock(service.get_service());
1716 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1718 QList <Mlt::Filter *> filtersList;
1719 Mlt::Service sourceService(clip->get_service());
1721 Mlt::Filter *filter = sourceService.filter(ct);
1723 if (filter->get_int("kdenlive_ix") != 0) {
1724 filtersList.append(filter);
1727 filter = sourceService.filter(ct);
1730 trackPlaylist.replace_with_blank(clipIndex);
1732 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1733 prod = checkSlowMotionProducer(prod, element);
1734 if (prod == NULL || !prod->is_valid()) {
1735 mlt_service_unlock(service.get_service());
1738 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1739 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1743 //if (mltInsertClip(info, element, prod) == -1) return false;
1744 if (!filtersList.isEmpty()) {
1745 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1746 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1747 Mlt::Service destService(destclip->get_service());
1749 for (int i = 0; i < filtersList.count(); i++)
1750 destService.attach(*(filtersList.at(i)));
1752 mlt_service_unlock(service.get_service());
1757 bool Render::mltRemoveClip(int track, GenTime position)
1759 Mlt::Service service(m_mltProducer->parent().get_service());
1760 if (service.type() != tractor_type) {
1761 kWarning() << "// TRACTOR PROBLEM";
1765 Mlt::Tractor tractor(service);
1766 mlt_service_lock(service.get_service());
1767 Mlt::Producer trackProducer(tractor.track(track));
1768 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1769 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1771 // Display playlist info
1772 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1773 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1774 int blankStart = trackPlaylist.clip_start(i);
1775 int blankDuration = trackPlaylist.clip_length(i) - 1;
1777 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1778 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1780 if (trackPlaylist.is_blank(clipIndex)) {
1781 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1782 mlt_service_unlock(service.get_service());
1785 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1787 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1788 if (clip) delete clip;
1789 trackPlaylist.consolidate_blanks(0);
1790 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1791 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1793 /* // Display playlist info
1794 kDebug()<<"//// AFTER";
1795 for (int i = 0; i < trackPlaylist.count(); i++) {
1796 int blankStart = trackPlaylist.clip_start(i);
1797 int blankDuration = trackPlaylist.clip_length(i) - 1;
1799 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1800 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1802 mlt_service_unlock(service.get_service());
1803 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1804 m_isBlocked = false;
1808 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1810 if (!m_mltProducer) {
1811 kDebug() << "PLAYLIST NOT INITIALISED //////";
1814 Mlt::Producer parentProd(m_mltProducer->parent());
1815 if (parentProd.get_producer() == NULL) {
1816 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1820 Mlt::Service service(parentProd.get_service());
1821 Mlt::Tractor tractor(service);
1822 int insertPos = pos.frames(m_fps);
1824 Mlt::Producer trackProducer(tractor.track(track));
1825 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1826 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1827 if (clipIndex == trackPlaylist.count()) {
1828 // We are after the end of the playlist
1831 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1832 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1833 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1836 int Render::mltTrackDuration(int track)
1838 if (!m_mltProducer) {
1839 kDebug() << "PLAYLIST NOT INITIALISED //////";
1842 Mlt::Producer parentProd(m_mltProducer->parent());
1843 if (parentProd.get_producer() == NULL) {
1844 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1848 Mlt::Service service(parentProd.get_service());
1849 Mlt::Tractor tractor(service);
1851 Mlt::Producer trackProducer(tractor.track(track));
1852 return trackProducer.get_playtime() - 1;
1855 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1857 if (!m_mltProducer) {
1858 kDebug() << "PLAYLIST NOT INITIALISED //////";
1861 Mlt::Producer parentProd(m_mltProducer->parent());
1862 if (parentProd.get_producer() == NULL) {
1863 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1866 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1867 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1869 Mlt::Service service(parentProd.get_service());
1870 Mlt::Tractor tractor(service);
1871 mlt_service_lock(service.get_service());
1872 int diff = duration.frames(m_fps);
1873 int offset = timeOffset.frames(m_fps);
1877 // insert space in one track only
1878 Mlt::Producer trackProducer(tractor.track(track));
1879 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1880 insertPos = trackClipStartList.value(track);
1881 if (insertPos != -1) {
1882 insertPos += offset;
1883 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1885 trackPlaylist.insert_blank(clipIndex, diff - 1);
1887 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1888 if (!trackPlaylist.is_blank(clipIndex)) {
1889 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1891 int position = trackPlaylist.clip_start(clipIndex);
1892 int blankDuration = trackPlaylist.clip_length(clipIndex);
1894 if (blankDuration - diff == 0) {
1895 trackPlaylist.remove(clipIndex);
1896 } else trackPlaylist.remove_region(position, diff);
1898 trackPlaylist.consolidate_blanks(0);
1900 // now move transitions
1901 mlt_service serv = m_mltProducer->parent().get_service();
1902 mlt_service nextservice = mlt_service_get_producer(serv);
1903 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1904 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1905 QString resource = mlt_properties_get(properties, "mlt_service");
1907 while (mlt_type == "transition") {
1908 mlt_transition tr = (mlt_transition) nextservice;
1909 int currentTrack = mlt_transition_get_b_track(tr);
1910 int currentIn = (int) mlt_transition_get_in(tr);
1911 int currentOut = (int) mlt_transition_get_out(tr);
1912 insertPos = trackTransitionStartList.value(track);
1913 if (insertPos != -1) {
1914 insertPos += offset;
1915 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1916 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1919 nextservice = mlt_service_producer(nextservice);
1920 if (nextservice == NULL) break;
1921 properties = MLT_SERVICE_PROPERTIES(nextservice);
1922 mlt_type = mlt_properties_get(properties, "mlt_type");
1923 resource = mlt_properties_get(properties, "mlt_service");
1926 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1927 Mlt::Producer trackProducer(tractor.track(trackNb));
1928 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1930 //int clipNb = trackPlaylist.count();
1931 insertPos = trackClipStartList.value(trackNb);
1932 if (insertPos != -1) {
1933 insertPos += offset;
1935 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1936 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1937 for (int i = 0; i < clipNb; i++) {
1938 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1939 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1940 kDebug()<<"-------------";
1942 kDebug()<<"END-------------";*/
1945 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1947 trackPlaylist.insert_blank(clipIndex, diff - 1);
1949 if (!trackPlaylist.is_blank(clipIndex)) {
1952 if (!trackPlaylist.is_blank(clipIndex)) {
1953 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1955 int position = trackPlaylist.clip_start(clipIndex);
1956 int blankDuration = trackPlaylist.clip_length(clipIndex);
1957 if (diff + blankDuration == 0) {
1958 trackPlaylist.remove(clipIndex);
1959 } else trackPlaylist.remove_region(position, - diff);
1961 trackPlaylist.consolidate_blanks(0);
1964 // now move transitions
1965 mlt_service serv = m_mltProducer->parent().get_service();
1966 mlt_service nextservice = mlt_service_get_producer(serv);
1967 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1968 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1969 QString resource = mlt_properties_get(properties, "mlt_service");
1971 while (mlt_type == "transition") {
1972 mlt_transition tr = (mlt_transition) nextservice;
1973 int currentIn = (int) mlt_transition_get_in(tr);
1974 int currentOut = (int) mlt_transition_get_out(tr);
1975 int currentTrack = mlt_transition_get_b_track(tr);
1976 insertPos = trackTransitionStartList.value(currentTrack);
1977 if (insertPos != -1) {
1978 insertPos += offset;
1979 if (currentOut > insertPos && resource != "mix") {
1980 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1983 nextservice = mlt_service_producer(nextservice);
1984 if (nextservice == NULL) break;
1985 properties = MLT_SERVICE_PROPERTIES(nextservice);
1986 mlt_type = mlt_properties_get(properties, "mlt_type");
1987 resource = mlt_properties_get(properties, "mlt_service");
1990 mlt_service_unlock(service.get_service());
1991 mltCheckLength(&tractor);
1992 m_mltConsumer->set("refresh", 1);
1996 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1998 if (source == dest) return;
1999 Mlt::Service sourceService(source->get_service());
2000 Mlt::Service destService(dest->get_service());
2002 // move all effects to the correct producer
2004 Mlt::Filter *filter = sourceService.filter(ct);
2006 if (filter->get_int("kdenlive_ix") != 0) {
2007 sourceService.detach(*filter);
2008 destService.attach(*filter);
2010 filter = sourceService.filter(ct);
2014 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2018 Mlt::Service service(m_mltProducer->parent().get_service());
2019 if (service.type() != tractor_type) {
2020 kWarning() << "// TRACTOR PROBLEM";
2023 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2024 Mlt::Tractor tractor(service);
2025 Mlt::Producer trackProducer(tractor.track(info.track));
2026 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2027 int startPos = info.startPos.frames(m_fps);
2028 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2029 int clipLength = trackPlaylist.clip_length(clipIndex);
2031 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2032 if (original == NULL) {
2035 if (!original->is_valid() || original->is_blank()) {
2040 Mlt::Producer clipparent = original->parent();
2041 if (!clipparent.is_valid() || clipparent.is_blank()) {
2047 QString serv = clipparent.get("mlt_service");
2048 QString id = clipparent.get("id");
2049 if (speed <= 0 && speed > -1) speed = 1.0;
2050 //kDebug() << "CLIP SERVICE: " << serv;
2051 if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
2052 mlt_service_lock(service.get_service());
2053 QString url = QString::fromUtf8(clipparent.get("resource"));
2054 url.append('?' + QString::number(speed));
2055 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2056 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2057 if (!slowprod || slowprod->get_producer() == NULL) {
2058 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2059 if (strobe > 1) slowprod->set("strobe", strobe);
2060 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2061 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2062 slowprod->set("id", producerid.toUtf8().constData());
2063 // copy producer props
2064 double ar = original->parent().get_double("force_aspect_ratio");
2065 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2066 double fps = original->parent().get_double("force_fps");
2067 if (fps != 0.0) slowprod->set("force_fps", fps);
2068 int threads = original->parent().get_int("threads");
2069 if (threads != 0) slowprod->set("threads", threads);
2070 if (original->parent().get("force_progressive"))
2071 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2072 int ix = original->parent().get_int("video_index");
2073 if (ix != 0) slowprod->set("video_index", ix);
2074 m_slowmotionProducers.insert(url, slowprod);
2076 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2077 trackPlaylist.consolidate_blanks(0);
2079 // Check that the blank space is long enough for our new duration
2080 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2081 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2083 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2084 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2085 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2086 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2088 // move all effects to the correct producer
2089 mltPasteEffects(clip, cut);
2090 trackPlaylist.insert_at(startPos, cut, 1);
2093 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2094 newLength = trackPlaylist.clip_length(clipIndex);
2095 mlt_service_unlock(service.get_service());
2096 } else if (speed == 1.0 && strobe < 2) {
2097 mlt_service_lock(service.get_service());
2099 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2100 trackPlaylist.consolidate_blanks(0);
2102 // Check that the blank space is long enough for our new duration
2103 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2104 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2107 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2108 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2109 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2110 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2111 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2113 // move all effects to the correct producer
2114 mltPasteEffects(clip, cut);
2116 trackPlaylist.insert_at(startPos, cut, 1);
2119 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2120 newLength = trackPlaylist.clip_length(clipIndex);
2121 mlt_service_unlock(service.get_service());
2123 } else if (serv == "framebuffer") {
2124 mlt_service_lock(service.get_service());
2125 QString url = QString::fromUtf8(clipparent.get("resource"));
2126 url = url.section('?', 0, 0);
2127 url.append('?' + QString::number(speed));
2128 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2129 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2130 if (!slowprod || slowprod->get_producer() == NULL) {
2131 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2132 slowprod->set("strobe", strobe);
2133 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2134 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2135 slowprod->set("id", producerid.toUtf8().constData());
2136 // copy producer props
2137 double ar = original->parent().get_double("force_aspect_ratio");
2138 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2139 double fps = original->parent().get_double("force_fps");
2140 if (fps != 0.0) slowprod->set("force_fps", fps);
2141 if (original->parent().get("force_progressive"))
2142 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2143 int threads = original->parent().get_int("threads");
2144 if (threads != 0) slowprod->set("threads", threads);
2145 int ix = original->parent().get_int("video_index");
2146 if (ix != 0) slowprod->set("video_index", ix);
2147 m_slowmotionProducers.insert(url, slowprod);
2149 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2150 trackPlaylist.consolidate_blanks(0);
2152 GenTime duration = speedIndependantInfo.cropDuration / speed;
2153 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2155 // Check that the blank space is long enough for our new duration
2156 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2157 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2160 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2161 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2162 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2163 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2165 // move all effects to the correct producer
2166 mltPasteEffects(clip, cut);
2168 trackPlaylist.insert_at(startPos, cut, 1);
2171 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2172 newLength = trackPlaylist.clip_length(clipIndex);
2174 mlt_service_unlock(service.get_service());
2177 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2178 m_isBlocked = false;
2182 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2184 Mlt::Service service(m_mltProducer->parent().get_service());
2185 bool success = false;
2186 Mlt::Tractor tractor(service);
2187 Mlt::Producer trackProducer(tractor.track(track));
2188 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2189 Mlt::Service clipService(trackPlaylist.get_service());
2192 mlt_service_lock(service.get_service());
2194 Mlt::Filter *filter = clipService.filter(ct);
2196 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2197 if (clipService.detach(*filter) == 0) success = true;
2198 } else if (updateIndex) {
2199 // Adjust the other effects index
2200 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2203 filter = clipService.filter(ct);
2205 m_isBlocked = false;
2206 mlt_service_unlock(service.get_service());
2211 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2213 if (position < GenTime()) {
2214 // Remove track effect
2215 return mltRemoveTrackEffect(track, index, updateIndex);
2217 Mlt::Service service(m_mltProducer->parent().get_service());
2218 bool success = false;
2219 Mlt::Tractor tractor(service);
2220 Mlt::Producer trackProducer(tractor.track(track));
2221 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2223 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2224 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2226 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2230 Mlt::Service clipService(clip->get_service());
2231 int duration = clip->get_playtime();
2233 // Check if clip is visible in monitor
2234 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2235 if (diff < 0 || diff > duration) doRefresh = false;
2239 // if (tag.startsWith("ladspa")) tag = "ladspa";
2241 mlt_service_lock(service.get_service());
2243 Mlt::Filter *filter = clipService.filter(ct);
2245 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2246 if (clipService.detach(*filter) == 0) success = true;
2247 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2248 } else if (updateIndex) {
2249 // Adjust the other effects index
2250 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2253 filter = clipService.filter(ct);
2255 m_isBlocked = false;
2256 mlt_service_unlock(service.get_service());
2257 if (doRefresh) refresh();
2261 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2263 Mlt::Service service(m_mltProducer->parent().get_service());
2264 Mlt::Tractor tractor(service);
2265 Mlt::Producer trackProducer(tractor.track(track));
2266 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2267 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2268 return mltAddEffect(trackService, params, 15000, true);
2272 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2275 Mlt::Service service(m_mltProducer->parent().get_service());
2277 Mlt::Tractor tractor(service);
2278 Mlt::Producer trackProducer(tractor.track(track));
2279 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2281 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2282 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2287 Mlt::Service clipService(clip->get_service());
2288 int duration = clip->get_playtime();
2290 // Check if clip is visible in monitor
2291 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2292 if (diff < 0 || diff > duration) doRefresh = false;
2295 return mltAddEffect(clipService, params, duration, doRefresh);
2298 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2300 bool updateIndex = false;
2301 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2302 const QString region = params.paramValue("region");
2305 mlt_service_lock(service.get_service());
2307 Mlt::Filter *filter = service.filter(ct);
2309 if (filter->get_int("kdenlive_ix") == filter_ix) {
2310 // A filter at that position already existed, so we will increase all indexes later
2315 filter = service.filter(ct);
2318 if (params.paramValue("id") == "speed") {
2319 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2321 filter = service.filter(ct);
2323 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2324 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2327 filter = service.filter(ct);
2329 m_isBlocked = false;
2330 mlt_service_unlock(service.get_service());
2331 if (doRefresh) refresh();
2336 // temporarily remove all effects after insert point
2337 QList <Mlt::Filter *> filtersList;
2339 filter = service.filter(ct);
2341 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2342 filtersList.append(filter);
2343 service.detach(*filter);
2345 filter = service.filter(ct);
2349 QString tag = params.paramValue("tag");
2350 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2351 if (tag.startsWith("ladspa")) tag = "ladspa";
2352 char *filterTag = qstrdup(tag.toUtf8().constData());
2353 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2354 QHash<QString, QString>::Iterator it;
2355 QString kfr = params.paramValue("keyframes");
2357 if (!kfr.isEmpty()) {
2358 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2359 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2360 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2361 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2362 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2363 //double max = params.paramValue("max").toDouble();
2364 double min = params.paramValue("min").toDouble();
2365 double factor = params.paramValue("factor", "1").toDouble();
2366 params.removeParam("starttag");
2367 params.removeParam("endtag");
2368 params.removeParam("keyframes");
2369 params.removeParam("min");
2370 params.removeParam("max");
2371 params.removeParam("factor");
2373 // Special case, only one keyframe, means we want a constant value
2374 if (keyFrames.count() == 1) {
2375 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2376 if (filter && filter->is_valid()) {
2377 filter->set("kdenlive_id", filterId);
2378 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2379 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2380 for (int j = 0; j < params.count(); j++) {
2381 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2383 filter->set("in", x1);
2384 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2385 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2386 service.attach(*filter);
2388 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2389 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2390 if (filter && filter->is_valid()) {
2391 filter->set("kdenlive_id", filterId);
2392 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2393 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2394 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2395 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2396 if (x2 == -1) x2 = duration;
2398 for (int j = 0; j < params.count(); j++) {
2399 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2402 filter->set("in", x1);
2403 filter->set("out", x2);
2404 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2405 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2406 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2407 service.attach(*filter);
2414 Mlt::Filter *filter;
2416 if (!region.isEmpty()) {
2417 filter = new Mlt::Filter(*m_mltProfile, "region");
2418 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2419 if (filter && filter->is_valid()) {
2420 filter->set("kdenlive_id", filterId);
2421 if (!region.isEmpty()) {
2422 filter->set("resource", region.toUtf8().constData());
2423 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2424 filter->set("filter0", filterTag);
2425 prefix = "filter0.";
2426 params.removeParam("id");
2427 params.removeParam("region");
2428 params.removeParam("kdenlive_ix");
2431 kDebug() << "filter is NULL";
2432 m_isBlocked = false;
2433 mlt_service_unlock(service.get_service());
2436 params.removeParam("kdenlive_id");
2438 for (int j = 0; j < params.count(); j++) {
2439 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2443 QString effectArgs = params.paramValue("id").section('_', 1);
2445 params.removeParam("id");
2446 params.removeParam("kdenlive_ix");
2447 params.removeParam("tag");
2448 params.removeParam("disable");
2449 params.removeParam("region");
2451 for (int j = 0; j < params.count(); j++) {
2452 effectArgs.append(' ' + params.at(j).value());
2454 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2455 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2458 if (params.paramValue("id") == "pan_zoom") {
2459 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2462 // attach filter to the clip
2463 service.attach(*filter);
2468 // re-add following filters
2469 for (int i = 0; i < filtersList.count(); i++) {
2470 Mlt::Filter *filter = filtersList.at(i);
2472 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2473 service.attach(*filter);
2475 m_isBlocked = false;
2476 mlt_service_unlock(service.get_service());
2477 if (doRefresh) refresh();
2481 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2483 Mlt::Service service(m_mltProducer->parent().get_service());
2484 Mlt::Tractor tractor(service);
2485 Mlt::Producer trackProducer(tractor.track(track));
2486 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2487 Mlt::Service clipService(trackPlaylist.get_service());
2490 QString index = params.paramValue("kdenlive_ix");
2491 QString tag = params.paramValue("tag");
2493 Mlt::Filter *filter = clipService.filter(ct);
2495 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2499 filter = clipService.filter(ct);
2503 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2504 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2506 bool success = false;//mltAddTrackEffect(track, params);
2507 m_isBlocked = false;
2511 QString ser = filter->get("mlt_service");
2512 if (ser == "region") prefix = "filter0.";
2513 mlt_service_lock(service.get_service());
2514 for (int j = 0; j < params.count(); j++) {
2515 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2517 mlt_service_unlock(service.get_service());
2519 m_isBlocked = false;
2525 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2527 QString index = params.paramValue("kdenlive_ix");
2528 QString tag = params.paramValue("tag");
2530 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2531 // This is a keyframe effect, to edit it, we remove it and re-add it.
2532 bool success = mltRemoveEffect(track, position, index, false);
2533 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2534 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2535 else success = mltAddEffect(track, position, params);
2536 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2539 if (position < GenTime()) {
2540 return mltEditTrackEffect(track, params);
2543 Mlt::Service service(m_mltProducer->parent().get_service());
2544 Mlt::Tractor tractor(service);
2545 Mlt::Producer trackProducer(tractor.track(track));
2546 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2548 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2549 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2551 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2555 Mlt::Service clipService(clip->get_service());
2556 int duration = clip->get_playtime();
2557 bool doRefresh = true;
2558 // Check if clip is visible in monitor
2559 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2560 if (diff < 0 || diff > duration) doRefresh = false;
2564 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2565 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2567 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2569 filter = clipService.filter(ct);
2571 kDebug() << "++++++++++++++++++++++++++";
2573 filter = clipService.filter(ct); */
2575 Mlt::Filter *filter = clipService.filter(ct);
2577 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2581 filter = clipService.filter(ct);
2585 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2586 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2588 bool success = mltAddEffect(track, position, params);
2589 m_isBlocked = false;
2593 QString ser = filter->get("mlt_service");
2594 if (ser == "region") prefix = "filter0.";
2595 mlt_service_lock(service.get_service());
2596 for (int j = 0; j < params.count(); j++) {
2597 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2599 mlt_service_unlock(service.get_service());
2601 m_isBlocked = false;
2602 if (doRefresh) refresh();
2606 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2608 Mlt::Service service(m_mltProducer->parent().get_service());
2609 Mlt::Tractor tractor(service);
2610 Mlt::Producer trackProducer(tractor.track(track));
2611 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2613 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2614 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2616 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2620 Mlt::Service clipService(clip->get_service());
2621 int duration = clip->get_playtime();
2622 bool doRefresh = true;
2623 // Check if clip is visible in monitor
2624 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2625 if (diff < 0 || diff > duration) doRefresh = false;
2630 Mlt::Filter *filter = clipService.filter(ct);
2632 int pos = filter->get_int("kdenlive_ix");
2633 if (pos == oldPos) {
2634 filter->set("kdenlive_ix", newPos);
2636 filter = clipService.filter(ct);
2639 m_isBlocked = false;
2640 if (doRefresh) refresh();
2643 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2645 if (position < GenTime()) {
2646 mltMoveTrackEffect(track, oldPos, newPos);
2649 Mlt::Service service(m_mltProducer->parent().get_service());
2650 Mlt::Tractor tractor(service);
2651 Mlt::Producer trackProducer(tractor.track(track));
2652 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2654 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2655 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2657 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2661 Mlt::Service clipService(clip->get_service());
2662 int duration = clip->get_playtime();
2663 bool doRefresh = true;
2664 // Check if clip is visible in monitor
2665 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2666 if (diff < 0 || diff > duration) doRefresh = false;
2671 QList <Mlt::Filter *> filtersList;
2672 Mlt::Filter *filter = clipService.filter(ct);
2674 if (newPos > oldPos) {
2676 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2677 filter->set("kdenlive_ix", newPos);
2678 filtersList.append(filter);
2679 clipService.detach(*filter);
2680 filter = clipService.filter(ct);
2681 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2682 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2684 filter = clipService.filter(ct);
2688 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2689 filtersList.append(filter);
2690 clipService.detach(*filter);
2692 filter = clipService.filter(ct);
2696 if (filter->get_int("kdenlive_ix") == oldPos) {
2697 filter->set("kdenlive_ix", newPos);
2698 filtersList.append(filter);
2699 clipService.detach(*filter);
2701 filter = clipService.filter(ct);
2705 filter = clipService.filter(ct);
2707 int pos = filter->get_int("kdenlive_ix");
2708 if (pos >= newPos) {
2709 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2710 filtersList.append(filter);
2711 clipService.detach(*filter);
2713 filter = clipService.filter(ct);
2717 for (int i = 0; i < filtersList.count(); i++) {
2718 clipService.attach(*(filtersList.at(i)));
2721 m_isBlocked = false;
2722 if (doRefresh) refresh();
2725 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2727 Mlt::Service service(m_mltProducer->parent().get_service());
2728 Mlt::Tractor tractor(service);
2729 Mlt::Producer trackProducer(tractor.track(track));
2730 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2732 Mlt::Service clipService(trackPlaylist.get_service());
2736 QList <Mlt::Filter *> filtersList;
2737 Mlt::Filter *filter = clipService.filter(ct);
2739 if (newPos > oldPos) {
2741 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2742 filter->set("kdenlive_ix", newPos);
2743 filtersList.append(filter);
2744 clipService.detach(*filter);
2745 filter = clipService.filter(ct);
2746 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2747 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2749 filter = clipService.filter(ct);
2753 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2754 filtersList.append(filter);
2755 clipService.detach(*filter);
2757 filter = clipService.filter(ct);
2761 if (filter->get_int("kdenlive_ix") == oldPos) {
2762 filter->set("kdenlive_ix", newPos);
2763 filtersList.append(filter);
2764 clipService.detach(*filter);
2766 filter = clipService.filter(ct);
2770 filter = clipService.filter(ct);
2772 int pos = filter->get_int("kdenlive_ix");
2773 if (pos >= newPos) {
2774 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2775 filtersList.append(filter);
2776 clipService.detach(*filter);
2778 filter = clipService.filter(ct);
2782 for (int i = 0; i < filtersList.count(); i++) {
2783 clipService.attach(*(filtersList.at(i)));
2785 m_isBlocked = false;
2789 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2792 Mlt::Service service(m_mltProducer->parent().get_service());
2793 Mlt::Tractor tractor(service);
2794 Mlt::Producer trackProducer(tractor.track(info.track));
2795 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2797 /* // Display playlist info
2798 kDebug()<<"//////////// BEFORE RESIZE";
2799 for (int i = 0; i < trackPlaylist.count(); i++) {
2800 int blankStart = trackPlaylist.clip_start(i);
2801 int blankDuration = trackPlaylist.clip_length(i) - 1;
2803 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2804 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2807 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2808 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2809 m_isBlocked = false;
2812 mlt_service_lock(service.get_service());
2813 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2814 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2815 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2817 int previousStart = clip->get_in();
2818 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2819 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2822 if (info.cropStart < GenTime())
2823 currentOut = newDuration - info.cropStart.frames(m_fps);
2825 currentOut = newDuration + previousStart;
2826 if (currentOut > clip->get_length()) {
2827 clip->parent().set("length", currentOut + 1);
2828 clip->parent().set("out", currentOut);
2829 clip->set("length", currentOut + 1);
2832 /*if (newDuration > clip->get_out()) {
2833 clip->parent().set_in_and_out(0, newDuration + 1);
2834 clip->set_in_and_out(0, newDuration + 1);
2837 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2838 trackPlaylist.consolidate_blanks(0);
2839 // skip to next clip
2841 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2843 // clip was made longer, trim next blank if there is one.
2844 if (clipIndex < trackPlaylist.count()) {
2845 // If this is not the last clip in playlist
2846 if (trackPlaylist.is_blank(clipIndex)) {
2847 int blankStart = trackPlaylist.clip_start(clipIndex);
2848 int blankDuration = trackPlaylist.clip_length(clipIndex);
2849 if (diff > blankDuration) {
2850 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2852 if (diff - blankDuration == 0) {
2853 trackPlaylist.remove(clipIndex);
2854 } else trackPlaylist.remove_region(blankStart, diff);
2856 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2859 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2860 trackPlaylist.consolidate_blanks(0);
2861 mlt_service_unlock(service.get_service());
2863 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2864 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2865 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2866 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2867 ItemInfo transpinfo;
2868 transpinfo.startPos = info.startPos;
2869 transpinfo.endPos = info.startPos + clipDuration;
2870 transpinfo.track = info.track;
2871 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2873 m_isBlocked = false;
2874 m_mltConsumer->set("refresh", 1);
2878 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2880 Mlt::Service service(m_mltProducer->parent().get_service());
2881 Mlt::Tractor tractor(service);
2882 Mlt::Producer trackProducer(tractor.track(track));
2885 if (blind) trackProducer.set("hide", 3);
2886 else trackProducer.set("hide", 2);
2888 trackProducer.set("hide", 1);
2890 trackProducer.set("hide", 0);
2892 tractor.multitrack()->refresh();
2898 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2900 Mlt::Service service(m_mltProducer->parent().get_service());
2901 int frameOffset = (int) diff.frames(m_fps);
2902 Mlt::Tractor tractor(service);
2903 Mlt::Producer trackProducer(tractor.track(info.track));
2904 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2905 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2906 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2909 mlt_service_lock(service.get_service());
2910 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2911 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2913 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2914 mlt_service_unlock(service.get_service());
2917 int previousStart = clip->get_in();
2918 int previousOut = clip->get_out();
2921 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2922 m_isBlocked = false;
2923 mlt_service_unlock(service.get_service());
2924 m_mltConsumer->set("refresh", 1);
2928 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2930 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2931 Mlt::Service service(m_mltProducer->parent().get_service());
2932 int moveFrame = (int) diff.frames(m_fps);
2933 Mlt::Tractor tractor(service);
2934 Mlt::Producer trackProducer(tractor.track(info.track));
2935 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2936 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2937 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2940 mlt_service_lock(service.get_service());
2941 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2942 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2943 if (clip == NULL || clip->is_blank()) {
2944 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2945 mlt_service_unlock(service.get_service());
2948 int previousStart = clip->get_in();
2949 int previousOut = clip->get_out();
2952 previousStart += moveFrame;
2953 if (previousStart < 0) {
2954 // special case, in point becoming negative (resizing images)
2955 previousOut -= previousStart;
2959 int length = previousOut + 1;
2960 if (length > clip->get_length()) {
2961 clip->parent().set("length", length + 1);
2962 clip->parent().set("out", length);
2963 clip->set("length", length + 1);
2967 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
2968 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
2969 if (moveFrame > 0) {
2970 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2972 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2973 int blankIndex = clipIndex - 1;
2974 int blankLength = trackPlaylist.clip_length(blankIndex);
2975 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2976 if (! trackPlaylist.is_blank(blankIndex)) {
2977 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2979 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2980 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2982 trackPlaylist.consolidate_blanks(0);
2983 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2984 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2985 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2986 ItemInfo transpinfo;
2987 transpinfo.startPos = info.startPos + diff;
2988 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2989 transpinfo.track = info.track;
2990 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2992 m_isBlocked = false;
2993 //m_mltConsumer->set("refresh", 1);
2994 mlt_service_unlock(service.get_service());
2995 m_mltConsumer->set("refresh", 1);
2999 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
3001 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
3005 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
3007 if (prod == NULL || !prod->is_valid()) {
3008 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
3011 kDebug() << "NEW PROD ID: " << prod->get("id");
3013 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
3014 Mlt::Service service(m_mltProducer->parent().get_service());
3015 if (service.type() != tractor_type) {
3016 kWarning() << "// TRACTOR PROBLEM";
3019 mlt_service_lock(service.get_service());
3020 Mlt::Tractor tractor(service);
3021 Mlt::Producer trackProducer(tractor.track(track));
3022 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3023 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3024 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3025 if (clipProducer == NULL || clipProducer->is_blank()) {
3026 kDebug() << "// ERROR UPDATING CLIP PROD";
3027 delete clipProducer;
3028 mlt_service_unlock(service.get_service());
3032 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3033 if (!clip || !clip->is_valid()) {
3034 if (clip) delete clip;
3035 delete clipProducer;
3036 mlt_service_unlock(service.get_service());
3040 // move all effects to the correct producer
3041 mltPasteEffects(clipProducer, clip);
3042 trackPlaylist.insert_at(pos, clip, 1);
3044 delete clipProducer;
3045 mlt_service_unlock(service.get_service());
3050 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3054 Mlt::Service service(m_mltProducer->parent().get_service());
3055 if (service.type() != tractor_type) {
3056 kWarning() << "// TRACTOR PROBLEM";
3060 Mlt::Tractor tractor(service);
3061 mlt_service_lock(service.get_service());
3062 Mlt::Producer trackProducer(tractor.track(startTrack));
3063 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3064 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3065 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3066 bool checkLength = false;
3067 if (endTrack == startTrack) {
3068 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3069 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3070 // error, destination is not empty
3072 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3073 delete clipProducer;
3075 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3076 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3077 mlt_service_unlock(service.get_service());
3081 trackPlaylist.consolidate_blanks(0);
3083 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3084 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3085 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3087 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3088 trackPlaylist.consolidate_blanks(1);
3089 delete clipProducer;
3090 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3091 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3093 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3095 //mlt_service_unlock(service.get_service());
3097 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3098 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3099 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3100 // error, destination is not empty
3101 mlt_service_unlock(service.get_service());
3105 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3106 if (!clipProducer || clipProducer->is_blank()) {
3107 // error, destination is not empty
3108 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3109 if (clipProducer) delete clipProducer;
3110 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3111 mlt_service_unlock(service.get_service());
3115 trackPlaylist.consolidate_blanks(0);
3116 destTrackPlaylist.consolidate_blanks(1);
3117 Mlt::Producer *clip;
3118 // check if we are moving a slowmotion producer
3119 QString serv = clipProducer->parent().get("mlt_service");
3120 QString currentid = clipProducer->parent().get("id");
3121 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3122 clip = clipProducer;
3125 // Special case: prod is null when using placeholder clips.
3126 // in that case, use the producer existing in playlist. Note that
3127 // it will bypass the one producer per track logic and might cause
3128 // Sound cracks if clip is moved so that it overlaps another copy of itself
3129 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3130 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3133 // move all effects to the correct producer
3134 mltPasteEffects(clipProducer, clip);
3137 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3138 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3139 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3142 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3144 if (clip == clipProducer) {
3149 delete clipProducer;
3151 destTrackPlaylist.consolidate_blanks(0);
3152 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3153 kDebug() << "//////// moving clip transparency";
3154 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3156 if (clipIndex > trackPlaylist.count()) checkLength = true;
3157 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3160 mlt_service_unlock(service.get_service());
3161 if (checkLength) mltCheckLength(&tractor);
3164 //m_mltConsumer->set("refresh", 1);
3169 QList <int> Render::checkTrackSequence(int track)
3172 Mlt::Service service(m_mltProducer->parent().get_service());
3173 if (service.type() != tractor_type) {
3174 kWarning() << "// TRACTOR PROBLEM";
3177 Mlt::Tractor tractor(service);
3178 mlt_service_lock(service.get_service());
3179 Mlt::Producer trackProducer(tractor.track(track));
3180 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3181 int clipNb = trackPlaylist.count();
3182 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3183 for (int i = 0; i < clipNb; i++) {
3184 Mlt::Producer *c = trackPlaylist.get_clip(i);
3185 int pos = trackPlaylist.clip_start(i);
3186 if (!list.contains(pos)) list.append(pos);
3187 pos += c->get_playtime();
3188 if (!list.contains(pos)) list.append(pos);
3194 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3196 int new_in = (int)newIn.frames(m_fps);
3197 int new_out = (int)newOut.frames(m_fps) - 1;
3198 if (new_in >= new_out) return false;
3199 int old_in = (int)oldIn.frames(m_fps);
3200 int old_out = (int)oldOut.frames(m_fps) - 1;
3202 Mlt::Service service(m_mltProducer->parent().get_service());
3203 Mlt::Tractor tractor(service);
3204 Mlt::Field *field = tractor.field();
3206 bool doRefresh = true;
3207 // Check if clip is visible in monitor
3208 int diff = old_out - m_mltProducer->position();
3209 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3211 diff = new_out - m_mltProducer->position();
3212 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3216 mlt_service_lock(service.get_service());
3218 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3219 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3220 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3221 QString resource = mlt_properties_get(properties, "mlt_service");
3222 int old_pos = (int)(old_in + old_out) / 2;
3225 while (mlt_type == "transition") {
3226 Mlt::Transition transition((mlt_transition) nextservice);
3227 int currentTrack = transition.get_b_track();
3228 int currentIn = (int) transition.get_in();
3229 int currentOut = (int) transition.get_out();
3231 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3233 if (newTrack - startTrack != 0) {
3234 Mlt::Properties trans_props(transition.get_properties());
3235 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3236 Mlt::Properties new_trans_props(new_transition.get_properties());
3237 new_trans_props.inherit(trans_props);
3238 new_transition.set_in_and_out(new_in, new_out);
3239 field->disconnect_service(transition);
3240 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3241 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3242 } else transition.set_in_and_out(new_in, new_out);
3245 nextservice = mlt_service_producer(nextservice);
3246 if (nextservice == NULL) break;
3247 properties = MLT_SERVICE_PROPERTIES(nextservice);
3248 mlt_type = mlt_properties_get(properties, "mlt_type");
3249 resource = mlt_properties_get(properties, "mlt_service");
3251 mlt_service_unlock(service.get_service());
3253 if (doRefresh) refresh();
3254 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3259 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3261 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3262 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3263 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3264 QString resource = mlt_properties_get(properties, "mlt_service");
3265 QList <Mlt::Transition *> trList;
3267 while (mlt_type == "transition") {
3268 Mlt::Transition transition((mlt_transition) nextservice);
3269 int aTrack = transition.get_a_track();
3270 int bTrack = transition.get_b_track();
3271 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3272 Mlt::Properties trans_props(transition.get_properties());
3273 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3274 Mlt::Properties new_trans_props(cp->get_properties());
3275 new_trans_props.inherit(trans_props);
3277 field->disconnect_service(transition);
3279 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3281 nextservice = mlt_service_producer(nextservice);
3282 if (nextservice == NULL) break;
3283 properties = MLT_SERVICE_PROPERTIES(nextservice);
3284 mlt_type = mlt_properties_get(properties, "mlt_type");
3285 resource = mlt_properties_get(properties, "mlt_service");
3288 field->plant_transition(tr, a_track, b_track);
3290 // re-add upper transitions
3291 for (int i = 0; i < trList.count(); i++) {
3292 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3293 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3297 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3299 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3301 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3302 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3305 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3308 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3310 mlt_service serv = m_mltProducer->parent().get_service();
3311 mlt_service_lock(serv);
3314 mlt_service nextservice = mlt_service_get_producer(serv);
3315 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3316 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3317 QString resource = mlt_properties_get(properties, "mlt_service");
3318 int in_pos = (int) in.frames(m_fps);
3319 int out_pos = (int) out.frames(m_fps) - 1;
3321 while (mlt_type == "transition") {
3322 mlt_transition tr = (mlt_transition) nextservice;
3323 int currentTrack = mlt_transition_get_b_track(tr);
3324 int currentBTrack = mlt_transition_get_a_track(tr);
3325 int currentIn = (int) mlt_transition_get_in(tr);
3326 int currentOut = (int) mlt_transition_get_out(tr);
3328 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3330 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3331 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3332 QMap<QString, QString>::Iterator it;
3334 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3336 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3337 if (currentId != xml.attribute("id")) {
3338 // The transition ID is not the same, so reset all properties
3339 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3340 // Cleanup previous properties
3341 QStringList permanentProps;
3342 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3343 permanentProps << "out" << "a_track" << "b_track";
3344 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3345 QString propName = mlt_properties_get_name(transproperties, i);
3346 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3347 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3352 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3353 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3355 if (currentBTrack != a_track) {
3356 mlt_properties_set_int(transproperties, "a_track", a_track);
3358 for (it = map.begin(); it != map.end(); ++it) {
3360 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3361 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3362 //filter->set("kdenlive_id", id);
3366 nextservice = mlt_service_producer(nextservice);
3367 if (nextservice == NULL) break;
3368 properties = MLT_SERVICE_PROPERTIES(nextservice);
3369 mlt_type = mlt_properties_get(properties, "mlt_type");
3370 resource = mlt_properties_get(properties, "mlt_service");
3372 mlt_service_unlock(serv);
3375 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3378 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3380 mlt_service serv = m_mltProducer->parent().get_service();
3382 mlt_service_lock(serv);
3384 Mlt::Service service(serv);
3385 Mlt::Tractor tractor(service);
3386 Mlt::Field *field = tractor.field();
3388 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3390 mlt_service nextservice = mlt_service_get_producer(serv);
3391 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3392 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3393 QString resource = mlt_properties_get(properties, "mlt_service");
3395 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3396 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3398 while (mlt_type == "transition") {
3399 mlt_transition tr = (mlt_transition) nextservice;
3400 int currentTrack = mlt_transition_get_b_track(tr);
3401 int currentIn = (int) mlt_transition_get_in(tr);
3402 int currentOut = (int) mlt_transition_get_out(tr);
3403 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3405 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3406 mlt_field_disconnect_service(field->get_field(), nextservice);
3409 nextservice = mlt_service_producer(nextservice);
3410 if (nextservice == NULL) break;
3411 properties = MLT_SERVICE_PROPERTIES(nextservice);
3412 mlt_type = mlt_properties_get(properties, "mlt_type");
3413 resource = mlt_properties_get(properties, "mlt_service");
3415 mlt_service_unlock(serv);
3418 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3421 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3423 QDomNodeList attribs = xml.elementsByTagName("parameter");
3424 QMap<QString, QString> map;
3425 for (int i = 0; i < attribs.count(); i++) {
3426 QDomElement e = attribs.item(i).toElement();
3427 QString name = e.attribute("name");
3428 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3429 map[name] = e.attribute("default");
3430 if (!e.attribute("value").isEmpty()) {
3431 map[name] = e.attribute("value");
3433 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3434 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3435 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3438 if (e.attribute("namedesc").contains(';')) {
3439 QString format = e.attribute("format");
3440 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3441 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3443 QTextStream txtNeu(&neu);
3444 if (values.size() > 0)
3445 txtNeu << (int)values[0].toDouble();
3447 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3448 txtNeu << separators[i];
3449 txtNeu << (int)(values[i+1].toDouble());
3451 if (i < separators.size())
3452 txtNeu << separators[i];
3453 map[e.attribute("name")] = neu;
3460 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3462 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3463 Mlt::Service service(m_mltProducer->parent().get_service());
3464 Mlt::Tractor tractor(service);
3465 Mlt::Field *field = tractor.field();
3467 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3468 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3469 transition->set("transparency", id);
3470 transition->set("fill", 1);
3471 transition->set("internal_added", 237);
3472 field->plant_transition(*transition, transitiontrack, info.track);
3476 void Render::mltDeleteTransparency(int pos, int track, int id)
3478 Mlt::Service service(m_mltProducer->parent().get_service());
3479 Mlt::Tractor tractor(service);
3480 Mlt::Field *field = tractor.field();
3482 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3483 mlt_service serv = m_mltProducer->parent().get_service();
3485 mlt_service nextservice = mlt_service_get_producer(serv);
3486 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3487 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3488 QString resource = mlt_properties_get(properties, "mlt_service");
3490 while (mlt_type == "transition") {
3491 mlt_transition tr = (mlt_transition) nextservice;
3492 int currentTrack = mlt_transition_get_b_track(tr);
3493 int currentIn = (int) mlt_transition_get_in(tr);
3494 int currentOut = (int) mlt_transition_get_out(tr);
3495 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3496 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3498 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3499 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3500 mlt_field_disconnect_service(field->get_field(), nextservice);
3503 nextservice = mlt_service_producer(nextservice);
3504 if (nextservice == NULL) break;
3505 properties = MLT_SERVICE_PROPERTIES(nextservice);
3506 mlt_type = mlt_properties_get(properties, "mlt_type");
3507 resource = mlt_properties_get(properties, "mlt_service");
3509 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3512 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3514 Mlt::Service service(m_mltProducer->parent().get_service());
3515 Mlt::Tractor tractor(service);
3517 mlt_service_lock(service.get_service());
3518 m_mltConsumer->set("refresh", 0);
3521 mlt_service serv = m_mltProducer->parent().get_service();
3522 mlt_service nextservice = mlt_service_get_producer(serv);
3523 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3524 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3525 QString resource = mlt_properties_get(properties, "mlt_service");
3526 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3527 while (mlt_type == "transition") {
3528 mlt_transition tr = (mlt_transition) nextservice;
3529 int currentTrack = mlt_transition_get_b_track(tr);
3530 int currentIn = (int) mlt_transition_get_in(tr);
3531 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3532 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3533 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3534 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3535 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3536 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3539 nextservice = mlt_service_producer(nextservice);
3540 if (nextservice == NULL) break;
3541 properties = MLT_SERVICE_PROPERTIES(nextservice);
3542 mlt_type = mlt_properties_get(properties, "mlt_type");
3543 resource = mlt_properties_get(properties, "mlt_service");
3545 mlt_service_unlock(service.get_service());
3547 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3551 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3553 Mlt::Service service(m_mltProducer->parent().get_service());
3554 Mlt::Tractor tractor(service);
3556 mlt_service_lock(service.get_service());
3557 m_mltConsumer->set("refresh", 0);
3560 mlt_service serv = m_mltProducer->parent().get_service();
3561 mlt_service nextservice = mlt_service_get_producer(serv);
3562 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3563 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3564 QString resource = mlt_properties_get(properties, "mlt_service");
3566 while (mlt_type == "transition") {
3567 mlt_transition tr = (mlt_transition) nextservice;
3568 int currentTrack = mlt_transition_get_b_track(tr);
3569 int currentaTrack = mlt_transition_get_a_track(tr);
3570 int currentIn = (int) mlt_transition_get_in(tr);
3571 int currentOut = (int) mlt_transition_get_out(tr);
3572 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3573 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3574 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3575 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3576 kDebug() << "//////MOVING";
3577 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3578 if (endTrack != startTrack) {
3579 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3580 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3581 mlt_properties_set_int(properties, "b_track", endTrack);
3585 nextservice = mlt_service_producer(nextservice);
3586 if (nextservice == NULL) break;
3587 properties = MLT_SERVICE_PROPERTIES(nextservice);
3588 mlt_type = mlt_properties_get(properties, "mlt_type");
3589 resource = mlt_properties_get(properties, "mlt_service");
3592 mlt_service_unlock(service.get_service());
3593 m_mltConsumer->set("refresh", 1);
3597 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3599 if (in >= out) return false;
3600 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3601 Mlt::Service service(m_mltProducer->parent().get_service());
3603 Mlt::Tractor tractor(service);
3604 Mlt::Field *field = tractor.field();
3606 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3607 if (out != GenTime())
3608 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3610 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3611 QMap<QString, QString>::Iterator it;
3613 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3614 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3615 if (xml.hasAttribute("id"))
3616 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3618 for (it = args.begin(); it != args.end(); ++it) {
3620 if (!it.value().isEmpty())
3621 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3622 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3624 // attach transition
3625 mltPlantTransition(field, *transition, a_track, b_track);
3626 // field->plant_transition(*transition, a_track, b_track);
3627 if (do_refresh) refresh();
3631 void Render::mltSavePlaylist()
3633 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3634 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3635 fileConsumer.set("resource", "/tmp/playlist.mlt");
3637 Mlt::Service service(m_mltProducer->get_service());
3639 fileConsumer.connect(service);
3640 fileConsumer.start();
3643 const QList <Mlt::Producer *> Render::producersList()
3645 QList <Mlt::Producer *> prods;
3646 if (m_mltProducer == NULL) return prods;
3647 Mlt::Service service(m_mltProducer->parent().get_service());
3648 if (service.type() != tractor_type) return prods;
3649 Mlt::Tractor tractor(service);
3652 int trackNb = tractor.count();
3653 for (int t = 1; t < trackNb; t++) {
3654 Mlt::Producer *tt = tractor.track(t);
3655 Mlt::Producer trackProducer(tt);
3657 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3658 int clipNb = trackPlaylist.count();
3659 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3660 for (int i = 0; i < clipNb; i++) {
3661 Mlt::Producer *c = trackPlaylist.get_clip(i);
3662 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3664 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3665 ids.append(nprod->get("id"));
3666 prods.append(nprod);
3667 } else delete nprod;
3675 void Render::fillSlowMotionProducers()
3677 if (m_mltProducer == NULL) return;
3678 Mlt::Service service(m_mltProducer->parent().get_service());
3679 if (service.type() != tractor_type) return;
3681 Mlt::Tractor tractor(service);
3683 int trackNb = tractor.count();
3684 for (int t = 1; t < trackNb; t++) {
3685 Mlt::Producer *tt = tractor.track(t);
3686 Mlt::Producer trackProducer(tt);
3688 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3689 int clipNb = trackPlaylist.count();
3690 for (int i = 0; i < clipNb; i++) {
3691 Mlt::Producer *c = trackPlaylist.get_clip(i);
3692 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3694 QString id = nprod->get("id");
3695 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3696 // this is a slowmotion producer, add it to the list
3697 QString url = QString::fromUtf8(nprod->get("resource"));
3698 int strobe = nprod->get_int("strobe");
3699 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3700 if (!m_slowmotionProducers.contains(url)) {
3701 m_slowmotionProducers.insert(url, nprod);
3703 } else delete nprod;
3710 void Render::mltInsertTrack(int ix, bool videoTrack)
3715 Mlt::Service service(m_mltProducer->parent().get_service());
3716 mlt_service_lock(service.get_service());
3717 if (service.type() != tractor_type) {
3718 kWarning() << "// TRACTOR PROBLEM";
3722 Mlt::Tractor tractor(service);
3724 Mlt::Playlist playlist;
3725 int ct = tractor.count();
3727 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3733 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3734 tractor.set_track(playlist, pos);
3735 Mlt::Producer newProd(tractor.track(pos));
3736 if (!videoTrack) newProd.set("hide", 1);
3738 for (; pos <= ct; pos++) {
3739 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3740 tractor.set_track(*prodToMove, pos);
3741 prodToMove = prodToMove2;
3744 tractor.set_track(playlist, ix);
3745 Mlt::Producer newProd(tractor.track(ix));
3746 if (!videoTrack) newProd.set("hide", 1);
3750 mlt_service serv = m_mltProducer->parent().get_service();
3751 mlt_service nextservice = mlt_service_get_producer(serv);
3752 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3753 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3754 QString resource = mlt_properties_get(properties, "mlt_service");
3756 while (mlt_type == "transition") {
3757 if (resource != "mix") {
3758 mlt_transition tr = (mlt_transition) nextservice;
3759 int currentTrack = mlt_transition_get_b_track(tr);
3760 int currentaTrack = mlt_transition_get_a_track(tr);
3761 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3763 if (currentTrack >= ix) {
3764 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3765 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3768 nextservice = mlt_service_producer(nextservice);
3769 if (nextservice == NULL) break;
3770 properties = MLT_SERVICE_PROPERTIES(nextservice);
3771 mlt_type = mlt_properties_get(properties, "mlt_type");
3772 resource = mlt_properties_get(properties, "mlt_service");
3775 // Add audio mix transition to last track
3776 Mlt::Field *field = tractor.field();
3777 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3778 transition->set("a_track", 1);
3779 transition->set("b_track", ct);
3780 transition->set("always_active", 1);
3781 transition->set("internal_added", 237);
3782 transition->set("combine", 1);
3783 field->plant_transition(*transition, 1, ct);
3784 //mlt_service_unlock(m_mltConsumer->get_service());
3785 mlt_service_unlock(service.get_service());
3786 //tractor.multitrack()->refresh();
3787 //tractor.refresh();
3789 blockSignals(false);
3793 void Render::mltDeleteTrack(int ix)
3796 doc.setContent(sceneList(), false);
3797 int tracksCount = doc.elementsByTagName("track").count() - 1;
3798 QDomNode track = doc.elementsByTagName("track").at(ix);
3799 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3800 QDomNodeList transitions = doc.elementsByTagName("transition");
3801 for (int i = 0; i < transitions.count(); i++) {
3802 QDomElement e = transitions.at(i).toElement();
3803 QDomNodeList props = e.elementsByTagName("property");
3804 QMap <QString, QString> mappedProps;
3805 for (int j = 0; j < props.count(); j++) {
3806 QDomElement f = props.at(j).toElement();
3807 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3809 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3810 tractor.removeChild(transitions.at(i));
3812 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3813 // Transition needs to be moved
3814 int a_track = mappedProps.value("a_track").toInt();
3815 int b_track = mappedProps.value("b_track").toInt();
3816 if (a_track > 0 && a_track >= ix) a_track --;
3817 if (b_track == ix) {
3818 // transition was on the deleted track, so remove it
3819 tractor.removeChild(transitions.at(i));
3823 if (b_track > 0 && b_track > ix) b_track --;
3824 for (int j = 0; j < props.count(); j++) {
3825 QDomElement f = props.at(j).toElement();
3826 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3827 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3832 tractor.removeChild(track);
3833 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3834 setSceneList(doc.toString(), m_framePosition);
3836 /* if (m_mltProducer != NULL) {
3837 Mlt::Producer parentProd(m_mltProducer->parent());
3838 if (parentProd.get_producer() != NULL) {
3839 Mlt::Service service(parentProd.get_service());
3840 if (service.type() == tractor_type) {
3841 Mlt::Tractor tractor(service);
3842 mltCheckLength(&tractor);
3849 void Render::updatePreviewSettings()
3851 kDebug() << "////// RESTARTING CONSUMER";
3852 if (!m_mltConsumer || !m_mltProducer) return;
3853 if (m_mltProducer->get_playtime() == 0) return;
3854 Mlt::Service service(m_mltProducer->parent().get_service());
3855 if (service.type() != tractor_type) return;
3857 //m_mltConsumer->set("refresh", 0);
3858 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3859 m_mltConsumer->purge();
3860 QString scene = sceneList();
3862 if (m_mltProducer) {
3863 pos = m_mltProducer->position();
3866 setSceneList(scene, pos);
3870 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3872 // Update all frame positions to the new fps value
3873 //WARNING: there are probably some effects or other that hold a frame value
3874 // as parameter and will also need to be updated here!
3876 doc.setContent(scene);
3878 double factor = new_fps / current_fps;
3879 QDomNodeList producers = doc.elementsByTagName("producer");
3880 for (int i = 0; i < producers.count(); i++) {
3881 QDomElement prod = producers.at(i).toElement();
3882 prod.removeAttribute("in");
3883 prod.removeAttribute("out");
3885 QDomNodeList props = prod.childNodes();
3886 for (int j = 0; j < props.count(); j++) {
3887 QDomElement param = props.at(j).toElement();
3888 QString paramName = param.attribute("name");
3889 if (paramName.startsWith("meta.") || paramName == "length") {
3890 prod.removeChild(props.at(j));
3896 QDomNodeList entries = doc.elementsByTagName("entry");
3897 for (int i = 0; i < entries.count(); i++) {
3898 QDomElement entry = entries.at(i).toElement();
3899 int in = entry.attribute("in").toInt();
3900 int out = entry.attribute("out").toInt();
3901 in = factor * in + 0.5;
3902 out = factor * out + 0.5;
3903 entry.setAttribute("in", in);
3904 entry.setAttribute("out", out);
3907 QDomNodeList blanks = doc.elementsByTagName("blank");
3908 for (int i = 0; i < blanks.count(); i++) {
3909 QDomElement blank = blanks.at(i).toElement();
3910 int length = blank.attribute("length").toInt();
3911 length = factor * length + 0.5;
3912 blank.setAttribute("length", QString::number(length));
3915 QDomNodeList filters = doc.elementsByTagName("filter");
3916 for (int i = 0; i < filters.count(); i++) {
3917 QDomElement filter = filters.at(i).toElement();
3918 int in = filter.attribute("in").toInt();
3919 int out = filter.attribute("out").toInt();
3920 in = factor * in + 0.5;
3921 out = factor * out + 0.5;
3922 filter.setAttribute("in", in);
3923 filter.setAttribute("out", out);
3926 QDomNodeList transitions = doc.elementsByTagName("transition");
3927 for (int i = 0; i < transitions.count(); i++) {
3928 QDomElement transition = transitions.at(i).toElement();
3929 int in = transition.attribute("in").toInt();
3930 int out = transition.attribute("out").toInt();
3931 in = factor * in + 0.5;
3932 out = factor * out + 0.5;
3933 transition.setAttribute("in", in);
3934 transition.setAttribute("out", out);
3935 QDomNodeList props = transition.childNodes();
3936 for (int j = 0; j < props.count(); j++) {
3937 QDomElement param = props.at(j).toElement();
3938 QString paramName = param.attribute("name");
3939 if (paramName == "geometry") {
3940 QString geom = param.firstChild().nodeValue();
3941 QStringList keys = geom.split(';');
3942 QStringList newKeys;
3943 for (int k = 0; k < keys.size(); ++k) {
3944 if (keys.at(k).contains('=')) {
3945 int pos = keys.at(k).section('=', 0, 0).toInt();
3946 pos = factor * pos + 0.5;
3947 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3948 } else newKeys.append(keys.at(k));
3950 param.firstChild().setNodeValue(newKeys.join(";"));
3954 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3955 int out = tractor.attribute("out").toInt();
3956 out = factor * out + 0.5;
3957 tractor.setAttribute("out", out);
3958 emit durationChanged(out);
3960 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3961 return doc.toString();
3965 void Render::sendFrameUpdate()
3967 if (m_mltProducer) {
3968 Mlt::Frame * frame = m_mltProducer->get_frame();
3969 emitFrameUpdated(*frame);
3975 #include "renderer.moc"