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_s16;
1426 int num_channels = 0;
1428 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1431 int num_samples = samples>200?200:samples;
1432 QByteArray channels;
1433 for (int i = 0; i < num_channels; i++) {
1435 for (int s = 0; s < num_samples; s ++ ) {
1436 val += abs(data[i+s*num_channels]/128);
1438 channels.append(val/num_samples);
1443 emit showAudioSignal(channels);
1445 emit showAudioSignal(QByteArray());
1449 * MLT playlist direct manipulation.
1452 void Render::mltCheckLength(Mlt::Tractor *tractor)
1454 //kDebug()<<"checking track length: "<<track<<"..........";
1456 int trackNb = tractor->count();
1460 Mlt::Producer trackProducer(tractor->track(0));
1461 duration = trackProducer.get_playtime() - 1;
1462 m_mltProducer->set("out", duration);
1463 emit durationChanged(duration);
1466 while (trackNb > 1) {
1467 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1468 trackDuration = trackProducer.get_playtime() - 1;
1469 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1470 if (trackDuration > duration) duration = trackDuration;
1474 Mlt::Producer blackTrackProducer(tractor->track(0));
1476 if (blackTrackProducer.get_playtime() - 1 != duration) {
1477 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1478 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1479 if (blackclip && blackclip->is_blank()) {
1484 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1485 blackTrackPlaylist.clear();
1486 m_blackClip->set("length", duration + 1);
1487 m_blackClip->set("out", duration);
1488 blackclip = m_blackClip->cut(0, duration);
1489 blackTrackPlaylist.insert_at(0, blackclip, 1);
1491 if (duration > blackclip->parent().get_length()) {
1492 blackclip->parent().set("length", duration + 1);
1493 blackclip->parent().set("out", duration);
1494 blackclip->set("length", duration + 1);
1496 blackTrackPlaylist.resize_clip(0, 0, duration);
1500 m_mltProducer->set("out", duration);
1501 emit durationChanged(duration);
1505 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1507 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1509 // We want a slowmotion producer
1510 double speed = element.attribute("speed", "1.0").toDouble();
1511 int strobe = element.attribute("strobe", "1").toInt();
1512 QString url = QString::fromUtf8(prod->get("resource"));
1513 url.append('?' + QString::number(speed));
1514 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1515 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1516 if (!slowprod || slowprod->get_producer() == NULL) {
1517 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1518 if (strobe > 1) slowprod->set("strobe", strobe);
1519 QString id = prod->get("id");
1520 if (id.contains('_')) id = id.section('_', 0, 0);
1521 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1522 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1523 slowprod->set("id", producerid.toUtf8().constData());
1524 m_slowmotionProducers.insert(url, slowprod);
1529 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1531 if (m_mltProducer == NULL) {
1532 kDebug() << "PLAYLIST NOT INITIALISED //////";
1536 kDebug() << "Cannot insert clip without producer //////";
1539 Mlt::Producer parentProd(m_mltProducer->parent());
1540 if (parentProd.get_producer() == NULL) {
1541 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1545 Mlt::Service service(parentProd.get_service());
1546 if (service.type() != tractor_type) {
1547 kWarning() << "// TRACTOR PROBLEM";
1550 Mlt::Tractor tractor(service);
1551 if (info.track > tractor.count() - 1) {
1552 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1555 mlt_service_lock(service.get_service());
1556 Mlt::Producer trackProducer(tractor.track(info.track));
1557 int trackDuration = trackProducer.get_playtime() - 1;
1558 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1559 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1560 prod = checkSlowMotionProducer(prod, element);
1561 if (prod == NULL || !prod->is_valid()) {
1562 mlt_service_unlock(service.get_service());
1566 int cutPos = (int) info.cropStart.frames(m_fps);
1567 if (cutPos < 0) cutPos = 0;
1568 int insertPos = (int) info.startPos.frames(m_fps);
1569 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1570 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1571 if (overwrite && (insertPos < trackDuration)) {
1572 // Replace zone with blanks
1573 //trackPlaylist.split_at(insertPos, true);
1574 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1575 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1576 trackPlaylist.insert_blank(clipIndex, cutDuration);
1578 trackPlaylist.split_at(insertPos, true);
1579 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1580 trackPlaylist.insert_blank(clipIndex, cutDuration);
1582 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1584 /*if (QString(prod->get("transparency")).toInt() == 1)
1585 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1587 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1588 mlt_service_unlock(service.get_service());
1589 /*tractor.multitrack()->refresh();
1590 tractor.refresh();*/
1595 void Render::mltCutClip(int track, GenTime position)
1599 Mlt::Service service(m_mltProducer->parent().get_service());
1600 if (service.type() != tractor_type) {
1601 kWarning() << "// TRACTOR PROBLEM";
1605 Mlt::Tractor tractor(service);
1606 Mlt::Producer trackProducer(tractor.track(track));
1607 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1610 /* // Display playlist info
1611 kDebug()<<"//////////// BEFORE";
1612 for (int i = 0; i < trackPlaylist.count(); i++) {
1613 int blankStart = trackPlaylist.clip_start(i);
1614 int blankDuration = trackPlaylist.clip_length(i) - 1;
1616 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1617 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1620 int cutPos = (int) position.frames(m_fps);
1622 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1623 if (trackPlaylist.is_blank(clipIndex)) {
1624 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1625 m_isBlocked = false;
1628 mlt_service_lock(service.get_service());
1629 int clipStart = trackPlaylist.clip_start(clipIndex);
1630 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1631 mlt_service_unlock(service.get_service());
1633 // duplicate effects
1634 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1635 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1637 if (original == NULL || clip == NULL) {
1638 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1640 Mlt::Service clipService(original->get_service());
1641 Mlt::Service dupService(clip->get_service());
1645 Mlt::Filter *filter = clipService.filter(ct);
1647 // Only duplicate Kdenlive filters, and skip the fade in effects
1648 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1649 // looks like there is no easy way to duplicate a filter,
1650 // so we will create a new one and duplicate its properties
1651 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1652 if (dup && dup->is_valid()) {
1653 Mlt::Properties entries(filter->get_properties());
1654 for (int i = 0; i < entries.count(); i++) {
1655 dup->set(entries.get_name(i), entries.get(i));
1657 dupService.attach(*dup);
1661 filter = clipService.filter(ct);
1664 /* // Display playlist info
1665 kDebug()<<"//////////// AFTER";
1666 for (int i = 0; i < trackPlaylist.count(); i++) {
1667 int blankStart = trackPlaylist.clip_start(i);
1668 int blankDuration = trackPlaylist.clip_length(i) - 1;
1670 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1671 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1674 m_isBlocked = false;
1677 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1681 kDebug() << "Cannot update clip with null producer //////";
1684 Mlt::Service service(m_mltProducer->parent().get_service());
1685 if (service.type() != tractor_type) {
1686 kWarning() << "// TRACTOR PROBLEM";
1689 Mlt::Tractor tractor(service);
1690 Mlt::Producer trackProducer(tractor.track(info.track));
1691 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1692 int startPos = info.startPos.frames(m_fps);
1693 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1694 if (trackPlaylist.is_blank(clipIndex)) {
1695 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1698 mlt_service_lock(service.get_service());
1699 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1701 QList <Mlt::Filter *> filtersList;
1702 Mlt::Service sourceService(clip->get_service());
1704 Mlt::Filter *filter = sourceService.filter(ct);
1706 if (filter->get_int("kdenlive_ix") != 0) {
1707 filtersList.append(filter);
1710 filter = sourceService.filter(ct);
1713 trackPlaylist.replace_with_blank(clipIndex);
1715 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1716 prod = checkSlowMotionProducer(prod, element);
1717 if (prod == NULL || !prod->is_valid()) {
1718 mlt_service_unlock(service.get_service());
1721 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1722 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1726 //if (mltInsertClip(info, element, prod) == -1) return false;
1727 if (!filtersList.isEmpty()) {
1728 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1729 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1730 Mlt::Service destService(destclip->get_service());
1732 for (int i = 0; i < filtersList.count(); i++)
1733 destService.attach(*(filtersList.at(i)));
1735 mlt_service_unlock(service.get_service());
1740 bool Render::mltRemoveClip(int track, GenTime position)
1742 Mlt::Service service(m_mltProducer->parent().get_service());
1743 if (service.type() != tractor_type) {
1744 kWarning() << "// TRACTOR PROBLEM";
1748 Mlt::Tractor tractor(service);
1749 mlt_service_lock(service.get_service());
1750 Mlt::Producer trackProducer(tractor.track(track));
1751 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1752 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1754 // Display playlist info
1755 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1756 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1757 int blankStart = trackPlaylist.clip_start(i);
1758 int blankDuration = trackPlaylist.clip_length(i) - 1;
1760 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1761 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1763 if (trackPlaylist.is_blank(clipIndex)) {
1764 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1765 mlt_service_unlock(service.get_service());
1768 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1770 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1771 if (clip) delete clip;
1772 trackPlaylist.consolidate_blanks(0);
1773 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1774 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1776 /* // Display playlist info
1777 kDebug()<<"//// AFTER";
1778 for (int i = 0; i < trackPlaylist.count(); i++) {
1779 int blankStart = trackPlaylist.clip_start(i);
1780 int blankDuration = trackPlaylist.clip_length(i) - 1;
1782 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1783 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1785 mlt_service_unlock(service.get_service());
1786 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1787 m_isBlocked = false;
1791 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1793 if (!m_mltProducer) {
1794 kDebug() << "PLAYLIST NOT INITIALISED //////";
1797 Mlt::Producer parentProd(m_mltProducer->parent());
1798 if (parentProd.get_producer() == NULL) {
1799 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1803 Mlt::Service service(parentProd.get_service());
1804 Mlt::Tractor tractor(service);
1805 int insertPos = pos.frames(m_fps);
1807 Mlt::Producer trackProducer(tractor.track(track));
1808 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1809 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1810 if (clipIndex == trackPlaylist.count()) {
1811 // We are after the end of the playlist
1814 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1815 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1816 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1819 int Render::mltTrackDuration(int track)
1821 if (!m_mltProducer) {
1822 kDebug() << "PLAYLIST NOT INITIALISED //////";
1825 Mlt::Producer parentProd(m_mltProducer->parent());
1826 if (parentProd.get_producer() == NULL) {
1827 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1831 Mlt::Service service(parentProd.get_service());
1832 Mlt::Tractor tractor(service);
1834 Mlt::Producer trackProducer(tractor.track(track));
1835 return trackProducer.get_playtime() - 1;
1838 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1840 if (!m_mltProducer) {
1841 kDebug() << "PLAYLIST NOT INITIALISED //////";
1844 Mlt::Producer parentProd(m_mltProducer->parent());
1845 if (parentProd.get_producer() == NULL) {
1846 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1849 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1850 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1852 Mlt::Service service(parentProd.get_service());
1853 Mlt::Tractor tractor(service);
1854 mlt_service_lock(service.get_service());
1855 int diff = duration.frames(m_fps);
1856 int offset = timeOffset.frames(m_fps);
1860 // insert space in one track only
1861 Mlt::Producer trackProducer(tractor.track(track));
1862 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1863 insertPos = trackClipStartList.value(track);
1864 if (insertPos != -1) {
1865 insertPos += offset;
1866 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1868 trackPlaylist.insert_blank(clipIndex, diff - 1);
1870 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1871 if (!trackPlaylist.is_blank(clipIndex)) {
1872 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1874 int position = trackPlaylist.clip_start(clipIndex);
1875 int blankDuration = trackPlaylist.clip_length(clipIndex);
1877 if (blankDuration - diff == 0) {
1878 trackPlaylist.remove(clipIndex);
1879 } else trackPlaylist.remove_region(position, diff);
1881 trackPlaylist.consolidate_blanks(0);
1883 // now move transitions
1884 mlt_service serv = m_mltProducer->parent().get_service();
1885 mlt_service nextservice = mlt_service_get_producer(serv);
1886 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1887 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1888 QString resource = mlt_properties_get(properties, "mlt_service");
1890 while (mlt_type == "transition") {
1891 mlt_transition tr = (mlt_transition) nextservice;
1892 int currentTrack = mlt_transition_get_b_track(tr);
1893 int currentIn = (int) mlt_transition_get_in(tr);
1894 int currentOut = (int) mlt_transition_get_out(tr);
1895 insertPos = trackTransitionStartList.value(track);
1896 if (insertPos != -1) {
1897 insertPos += offset;
1898 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1899 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1902 nextservice = mlt_service_producer(nextservice);
1903 if (nextservice == NULL) break;
1904 properties = MLT_SERVICE_PROPERTIES(nextservice);
1905 mlt_type = mlt_properties_get(properties, "mlt_type");
1906 resource = mlt_properties_get(properties, "mlt_service");
1909 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1910 Mlt::Producer trackProducer(tractor.track(trackNb));
1911 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1913 //int clipNb = trackPlaylist.count();
1914 insertPos = trackClipStartList.value(trackNb);
1915 if (insertPos != -1) {
1916 insertPos += offset;
1918 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1919 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1920 for (int i = 0; i < clipNb; i++) {
1921 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1922 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1923 kDebug()<<"-------------";
1925 kDebug()<<"END-------------";*/
1928 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1930 trackPlaylist.insert_blank(clipIndex, diff - 1);
1932 if (!trackPlaylist.is_blank(clipIndex)) {
1935 if (!trackPlaylist.is_blank(clipIndex)) {
1936 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1938 int position = trackPlaylist.clip_start(clipIndex);
1939 int blankDuration = trackPlaylist.clip_length(clipIndex);
1940 if (diff + blankDuration == 0) {
1941 trackPlaylist.remove(clipIndex);
1942 } else trackPlaylist.remove_region(position, - diff);
1944 trackPlaylist.consolidate_blanks(0);
1947 // now move transitions
1948 mlt_service serv = m_mltProducer->parent().get_service();
1949 mlt_service nextservice = mlt_service_get_producer(serv);
1950 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1951 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1952 QString resource = mlt_properties_get(properties, "mlt_service");
1954 while (mlt_type == "transition") {
1955 mlt_transition tr = (mlt_transition) nextservice;
1956 int currentIn = (int) mlt_transition_get_in(tr);
1957 int currentOut = (int) mlt_transition_get_out(tr);
1958 int currentTrack = mlt_transition_get_b_track(tr);
1959 insertPos = trackTransitionStartList.value(currentTrack);
1960 if (insertPos != -1) {
1961 insertPos += offset;
1962 if (currentOut > insertPos && resource != "mix") {
1963 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1966 nextservice = mlt_service_producer(nextservice);
1967 if (nextservice == NULL) break;
1968 properties = MLT_SERVICE_PROPERTIES(nextservice);
1969 mlt_type = mlt_properties_get(properties, "mlt_type");
1970 resource = mlt_properties_get(properties, "mlt_service");
1973 mlt_service_unlock(service.get_service());
1974 mltCheckLength(&tractor);
1975 m_mltConsumer->set("refresh", 1);
1979 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1981 if (source == dest) return;
1982 Mlt::Service sourceService(source->get_service());
1983 Mlt::Service destService(dest->get_service());
1985 // move all effects to the correct producer
1987 Mlt::Filter *filter = sourceService.filter(ct);
1989 if (filter->get_int("kdenlive_ix") != 0) {
1990 sourceService.detach(*filter);
1991 destService.attach(*filter);
1993 filter = sourceService.filter(ct);
1997 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2001 Mlt::Service service(m_mltProducer->parent().get_service());
2002 if (service.type() != tractor_type) {
2003 kWarning() << "// TRACTOR PROBLEM";
2006 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2007 Mlt::Tractor tractor(service);
2008 Mlt::Producer trackProducer(tractor.track(info.track));
2009 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2010 int startPos = info.startPos.frames(m_fps);
2011 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2012 int clipLength = trackPlaylist.clip_length(clipIndex);
2014 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2015 if (original == NULL) {
2018 if (!original->is_valid() || original->is_blank()) {
2023 Mlt::Producer clipparent = original->parent();
2024 if (!clipparent.is_valid() || clipparent.is_blank()) {
2030 QString serv = clipparent.get("mlt_service");
2031 QString id = clipparent.get("id");
2032 if (speed <= 0 && speed > -1) speed = 1.0;
2033 //kDebug() << "CLIP SERVICE: " << serv;
2034 if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
2035 mlt_service_lock(service.get_service());
2036 QString url = QString::fromUtf8(clipparent.get("resource"));
2037 url.append('?' + QString::number(speed));
2038 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2039 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2040 if (!slowprod || slowprod->get_producer() == NULL) {
2041 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2042 if (strobe > 1) slowprod->set("strobe", strobe);
2043 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2044 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2045 slowprod->set("id", producerid.toUtf8().constData());
2046 // copy producer props
2047 double ar = original->parent().get_double("force_aspect_ratio");
2048 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2049 double fps = original->parent().get_double("force_fps");
2050 if (fps != 0.0) slowprod->set("force_fps", fps);
2051 int threads = original->parent().get_int("threads");
2052 if (threads != 0) slowprod->set("threads", threads);
2053 if (original->parent().get("force_progressive"))
2054 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2055 int ix = original->parent().get_int("video_index");
2056 if (ix != 0) slowprod->set("video_index", ix);
2057 m_slowmotionProducers.insert(url, slowprod);
2059 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2060 trackPlaylist.consolidate_blanks(0);
2062 // Check that the blank space is long enough for our new duration
2063 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2064 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2066 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2067 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2068 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2069 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2071 // move all effects to the correct producer
2072 mltPasteEffects(clip, cut);
2073 trackPlaylist.insert_at(startPos, cut, 1);
2076 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2077 newLength = trackPlaylist.clip_length(clipIndex);
2078 mlt_service_unlock(service.get_service());
2079 } else if (speed == 1.0 && strobe < 2) {
2080 mlt_service_lock(service.get_service());
2082 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2083 trackPlaylist.consolidate_blanks(0);
2085 // Check that the blank space is long enough for our new duration
2086 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2087 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2090 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2091 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2092 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2093 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2094 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2096 // move all effects to the correct producer
2097 mltPasteEffects(clip, cut);
2099 trackPlaylist.insert_at(startPos, cut, 1);
2102 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2103 newLength = trackPlaylist.clip_length(clipIndex);
2104 mlt_service_unlock(service.get_service());
2106 } else if (serv == "framebuffer") {
2107 mlt_service_lock(service.get_service());
2108 QString url = QString::fromUtf8(clipparent.get("resource"));
2109 url = url.section('?', 0, 0);
2110 url.append('?' + QString::number(speed));
2111 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2112 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2113 if (!slowprod || slowprod->get_producer() == NULL) {
2114 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2115 slowprod->set("strobe", strobe);
2116 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2117 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2118 slowprod->set("id", producerid.toUtf8().constData());
2119 // copy producer props
2120 double ar = original->parent().get_double("force_aspect_ratio");
2121 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2122 double fps = original->parent().get_double("force_fps");
2123 if (fps != 0.0) slowprod->set("force_fps", fps);
2124 if (original->parent().get("force_progressive"))
2125 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2126 int threads = original->parent().get_int("threads");
2127 if (threads != 0) slowprod->set("threads", threads);
2128 int ix = original->parent().get_int("video_index");
2129 if (ix != 0) slowprod->set("video_index", ix);
2130 m_slowmotionProducers.insert(url, slowprod);
2132 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2133 trackPlaylist.consolidate_blanks(0);
2135 GenTime duration = speedIndependantInfo.cropDuration / speed;
2136 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2138 // Check that the blank space is long enough for our new duration
2139 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2140 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2143 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2144 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2145 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2146 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2148 // move all effects to the correct producer
2149 mltPasteEffects(clip, cut);
2151 trackPlaylist.insert_at(startPos, cut, 1);
2154 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2155 newLength = trackPlaylist.clip_length(clipIndex);
2157 mlt_service_unlock(service.get_service());
2160 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2161 m_isBlocked = false;
2165 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2167 Mlt::Service service(m_mltProducer->parent().get_service());
2168 bool success = false;
2169 Mlt::Tractor tractor(service);
2170 Mlt::Producer trackProducer(tractor.track(track));
2171 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2172 Mlt::Service clipService(trackPlaylist.get_service());
2175 mlt_service_lock(service.get_service());
2177 Mlt::Filter *filter = clipService.filter(ct);
2179 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2180 if (clipService.detach(*filter) == 0) success = true;
2181 } else if (updateIndex) {
2182 // Adjust the other effects index
2183 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2186 filter = clipService.filter(ct);
2188 m_isBlocked = false;
2189 mlt_service_unlock(service.get_service());
2194 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2196 if (position < GenTime()) {
2197 // Remove track effect
2198 return mltRemoveTrackEffect(track, index, updateIndex);
2200 Mlt::Service service(m_mltProducer->parent().get_service());
2201 bool success = false;
2202 Mlt::Tractor tractor(service);
2203 Mlt::Producer trackProducer(tractor.track(track));
2204 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2206 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2207 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2209 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2213 Mlt::Service clipService(clip->get_service());
2214 int duration = clip->get_playtime();
2216 // Check if clip is visible in monitor
2217 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2218 if (diff < 0 || diff > duration) doRefresh = false;
2222 // if (tag.startsWith("ladspa")) tag = "ladspa";
2224 mlt_service_lock(service.get_service());
2226 Mlt::Filter *filter = clipService.filter(ct);
2228 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2229 if (clipService.detach(*filter) == 0) success = true;
2230 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2231 } else if (updateIndex) {
2232 // Adjust the other effects index
2233 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2236 filter = clipService.filter(ct);
2238 m_isBlocked = false;
2239 mlt_service_unlock(service.get_service());
2240 if (doRefresh) refresh();
2244 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2246 Mlt::Service service(m_mltProducer->parent().get_service());
2247 Mlt::Tractor tractor(service);
2248 Mlt::Producer trackProducer(tractor.track(track));
2249 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2250 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2251 return mltAddEffect(trackService, params, 15000, true);
2255 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2258 Mlt::Service service(m_mltProducer->parent().get_service());
2260 Mlt::Tractor tractor(service);
2261 Mlt::Producer trackProducer(tractor.track(track));
2262 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2264 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2265 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2270 Mlt::Service clipService(clip->get_service());
2271 int duration = clip->get_playtime();
2273 // Check if clip is visible in monitor
2274 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2275 if (diff < 0 || diff > duration) doRefresh = false;
2278 return mltAddEffect(clipService, params, duration, doRefresh);
2281 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2283 bool updateIndex = false;
2284 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2285 const QString region = params.paramValue("region");
2288 mlt_service_lock(service.get_service());
2290 Mlt::Filter *filter = service.filter(ct);
2292 if (filter->get_int("kdenlive_ix") == filter_ix) {
2293 // A filter at that position already existed, so we will increase all indexes later
2298 filter = service.filter(ct);
2301 if (params.paramValue("id") == "speed") {
2302 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2304 filter = service.filter(ct);
2306 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2307 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2310 filter = service.filter(ct);
2312 m_isBlocked = false;
2313 mlt_service_unlock(service.get_service());
2314 if (doRefresh) refresh();
2319 // temporarily remove all effects after insert point
2320 QList <Mlt::Filter *> filtersList;
2322 filter = service.filter(ct);
2324 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2325 filtersList.append(filter);
2326 service.detach(*filter);
2328 filter = service.filter(ct);
2332 QString tag = params.paramValue("tag");
2333 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2334 if (tag.startsWith("ladspa")) tag = "ladspa";
2335 char *filterTag = qstrdup(tag.toUtf8().constData());
2336 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2337 QHash<QString, QString>::Iterator it;
2338 QString kfr = params.paramValue("keyframes");
2340 if (!kfr.isEmpty()) {
2341 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2342 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2343 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2344 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2345 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2346 //double max = params.paramValue("max").toDouble();
2347 double min = params.paramValue("min").toDouble();
2348 double factor = params.paramValue("factor", "1").toDouble();
2349 params.removeParam("starttag");
2350 params.removeParam("endtag");
2351 params.removeParam("keyframes");
2352 params.removeParam("min");
2353 params.removeParam("max");
2354 params.removeParam("factor");
2356 // Special case, only one keyframe, means we want a constant value
2357 if (keyFrames.count() == 1) {
2358 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2359 if (filter && filter->is_valid()) {
2360 filter->set("kdenlive_id", filterId);
2361 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2362 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2363 for (int j = 0; j < params.count(); j++) {
2364 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2366 filter->set("in", x1);
2367 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2368 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2369 service.attach(*filter);
2371 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2372 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2373 if (filter && filter->is_valid()) {
2374 filter->set("kdenlive_id", filterId);
2375 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2376 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2377 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2378 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2379 if (x2 == -1) x2 = duration;
2381 for (int j = 0; j < params.count(); j++) {
2382 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2385 filter->set("in", x1);
2386 filter->set("out", x2);
2387 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2388 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2389 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2390 service.attach(*filter);
2397 Mlt::Filter *filter;
2399 if (!region.isEmpty()) {
2400 filter = new Mlt::Filter(*m_mltProfile, "region");
2401 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2402 if (filter && filter->is_valid()) {
2403 filter->set("kdenlive_id", filterId);
2404 if (!region.isEmpty()) {
2405 filter->set("resource", region.toUtf8().constData());
2406 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2407 filter->set("filter0", filterTag);
2408 prefix = "filter0.";
2409 params.removeParam("id");
2410 params.removeParam("region");
2411 params.removeParam("kdenlive_ix");
2414 kDebug() << "filter is NULL";
2415 m_isBlocked = false;
2416 mlt_service_unlock(service.get_service());
2419 params.removeParam("kdenlive_id");
2421 for (int j = 0; j < params.count(); j++) {
2422 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2426 QString effectArgs = params.paramValue("id").section('_', 1);
2428 params.removeParam("id");
2429 params.removeParam("kdenlive_ix");
2430 params.removeParam("tag");
2431 params.removeParam("disable");
2432 params.removeParam("region");
2434 for (int j = 0; j < params.count(); j++) {
2435 effectArgs.append(' ' + params.at(j).value());
2437 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2438 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2441 if (params.paramValue("id") == "pan_zoom") {
2442 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2445 // attach filter to the clip
2446 service.attach(*filter);
2451 // re-add following filters
2452 for (int i = 0; i < filtersList.count(); i++) {
2453 Mlt::Filter *filter = filtersList.at(i);
2455 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2456 service.attach(*filter);
2458 m_isBlocked = false;
2459 mlt_service_unlock(service.get_service());
2460 if (doRefresh) refresh();
2464 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2466 Mlt::Service service(m_mltProducer->parent().get_service());
2467 Mlt::Tractor tractor(service);
2468 Mlt::Producer trackProducer(tractor.track(track));
2469 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2470 Mlt::Service clipService(trackPlaylist.get_service());
2473 QString index = params.paramValue("kdenlive_ix");
2474 QString tag = params.paramValue("tag");
2476 Mlt::Filter *filter = clipService.filter(ct);
2478 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2482 filter = clipService.filter(ct);
2486 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2487 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2489 bool success = false;//mltAddTrackEffect(track, params);
2490 m_isBlocked = false;
2494 QString ser = filter->get("mlt_service");
2495 if (ser == "region") prefix = "filter0.";
2496 mlt_service_lock(service.get_service());
2497 for (int j = 0; j < params.count(); j++) {
2498 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2500 mlt_service_unlock(service.get_service());
2502 m_isBlocked = false;
2508 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2510 QString index = params.paramValue("kdenlive_ix");
2511 QString tag = params.paramValue("tag");
2513 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2514 // This is a keyframe effect, to edit it, we remove it and re-add it.
2515 bool success = mltRemoveEffect(track, position, index, false);
2516 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2517 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2518 else success = mltAddEffect(track, position, params);
2519 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2522 if (position < GenTime()) {
2523 return mltEditTrackEffect(track, params);
2526 Mlt::Service service(m_mltProducer->parent().get_service());
2527 Mlt::Tractor tractor(service);
2528 Mlt::Producer trackProducer(tractor.track(track));
2529 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2531 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2532 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2534 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2538 Mlt::Service clipService(clip->get_service());
2539 int duration = clip->get_playtime();
2540 bool doRefresh = true;
2541 // Check if clip is visible in monitor
2542 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2543 if (diff < 0 || diff > duration) doRefresh = false;
2547 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2548 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2550 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2552 filter = clipService.filter(ct);
2554 kDebug() << "++++++++++++++++++++++++++";
2556 filter = clipService.filter(ct); */
2558 Mlt::Filter *filter = clipService.filter(ct);
2560 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2564 filter = clipService.filter(ct);
2568 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2569 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2571 bool success = mltAddEffect(track, position, params);
2572 m_isBlocked = false;
2576 QString ser = filter->get("mlt_service");
2577 if (ser == "region") prefix = "filter0.";
2578 mlt_service_lock(service.get_service());
2579 for (int j = 0; j < params.count(); j++) {
2580 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2582 mlt_service_unlock(service.get_service());
2584 m_isBlocked = false;
2585 if (doRefresh) refresh();
2589 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2591 Mlt::Service service(m_mltProducer->parent().get_service());
2592 Mlt::Tractor tractor(service);
2593 Mlt::Producer trackProducer(tractor.track(track));
2594 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2596 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2597 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2599 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2603 Mlt::Service clipService(clip->get_service());
2604 int duration = clip->get_playtime();
2605 bool doRefresh = true;
2606 // Check if clip is visible in monitor
2607 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2608 if (diff < 0 || diff > duration) doRefresh = false;
2613 Mlt::Filter *filter = clipService.filter(ct);
2615 int pos = filter->get_int("kdenlive_ix");
2616 if (pos == oldPos) {
2617 filter->set("kdenlive_ix", newPos);
2619 filter = clipService.filter(ct);
2622 m_isBlocked = false;
2623 if (doRefresh) refresh();
2626 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2628 if (position < GenTime()) {
2629 mltMoveTrackEffect(track, oldPos, newPos);
2632 Mlt::Service service(m_mltProducer->parent().get_service());
2633 Mlt::Tractor tractor(service);
2634 Mlt::Producer trackProducer(tractor.track(track));
2635 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2637 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2638 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2640 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2644 Mlt::Service clipService(clip->get_service());
2645 int duration = clip->get_playtime();
2646 bool doRefresh = true;
2647 // Check if clip is visible in monitor
2648 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2649 if (diff < 0 || diff > duration) doRefresh = false;
2654 QList <Mlt::Filter *> filtersList;
2655 Mlt::Filter *filter = clipService.filter(ct);
2657 if (newPos > oldPos) {
2659 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2660 filter->set("kdenlive_ix", newPos);
2661 filtersList.append(filter);
2662 clipService.detach(*filter);
2663 filter = clipService.filter(ct);
2664 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2665 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2667 filter = clipService.filter(ct);
2671 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2672 filtersList.append(filter);
2673 clipService.detach(*filter);
2675 filter = clipService.filter(ct);
2679 if (filter->get_int("kdenlive_ix") == oldPos) {
2680 filter->set("kdenlive_ix", newPos);
2681 filtersList.append(filter);
2682 clipService.detach(*filter);
2684 filter = clipService.filter(ct);
2688 filter = clipService.filter(ct);
2690 int pos = filter->get_int("kdenlive_ix");
2691 if (pos >= newPos) {
2692 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2693 filtersList.append(filter);
2694 clipService.detach(*filter);
2696 filter = clipService.filter(ct);
2700 for (int i = 0; i < filtersList.count(); i++) {
2701 clipService.attach(*(filtersList.at(i)));
2704 m_isBlocked = false;
2705 if (doRefresh) refresh();
2708 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2710 Mlt::Service service(m_mltProducer->parent().get_service());
2711 Mlt::Tractor tractor(service);
2712 Mlt::Producer trackProducer(tractor.track(track));
2713 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2715 Mlt::Service clipService(trackPlaylist.get_service());
2719 QList <Mlt::Filter *> filtersList;
2720 Mlt::Filter *filter = clipService.filter(ct);
2722 if (newPos > oldPos) {
2724 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2725 filter->set("kdenlive_ix", newPos);
2726 filtersList.append(filter);
2727 clipService.detach(*filter);
2728 filter = clipService.filter(ct);
2729 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2730 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2732 filter = clipService.filter(ct);
2736 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2737 filtersList.append(filter);
2738 clipService.detach(*filter);
2740 filter = clipService.filter(ct);
2744 if (filter->get_int("kdenlive_ix") == oldPos) {
2745 filter->set("kdenlive_ix", newPos);
2746 filtersList.append(filter);
2747 clipService.detach(*filter);
2749 filter = clipService.filter(ct);
2753 filter = clipService.filter(ct);
2755 int pos = filter->get_int("kdenlive_ix");
2756 if (pos >= newPos) {
2757 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2758 filtersList.append(filter);
2759 clipService.detach(*filter);
2761 filter = clipService.filter(ct);
2765 for (int i = 0; i < filtersList.count(); i++) {
2766 clipService.attach(*(filtersList.at(i)));
2768 m_isBlocked = false;
2772 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2775 Mlt::Service service(m_mltProducer->parent().get_service());
2776 Mlt::Tractor tractor(service);
2777 Mlt::Producer trackProducer(tractor.track(info.track));
2778 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2780 /* // Display playlist info
2781 kDebug()<<"//////////// BEFORE RESIZE";
2782 for (int i = 0; i < trackPlaylist.count(); i++) {
2783 int blankStart = trackPlaylist.clip_start(i);
2784 int blankDuration = trackPlaylist.clip_length(i) - 1;
2786 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2787 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2790 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2791 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2792 m_isBlocked = false;
2795 mlt_service_lock(service.get_service());
2796 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2797 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2798 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2800 int previousStart = clip->get_in();
2801 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2802 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2805 if (info.cropStart < GenTime())
2806 currentOut = newDuration - info.cropStart.frames(m_fps);
2808 currentOut = newDuration + previousStart;
2809 if (currentOut > clip->get_length()) {
2810 clip->parent().set("length", currentOut + 1);
2811 clip->parent().set("out", currentOut);
2812 clip->set("length", currentOut + 1);
2815 /*if (newDuration > clip->get_out()) {
2816 clip->parent().set_in_and_out(0, newDuration + 1);
2817 clip->set_in_and_out(0, newDuration + 1);
2820 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2821 trackPlaylist.consolidate_blanks(0);
2822 // skip to next clip
2824 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2826 // clip was made longer, trim next blank if there is one.
2827 if (clipIndex < trackPlaylist.count()) {
2828 // If this is not the last clip in playlist
2829 if (trackPlaylist.is_blank(clipIndex)) {
2830 int blankStart = trackPlaylist.clip_start(clipIndex);
2831 int blankDuration = trackPlaylist.clip_length(clipIndex);
2832 if (diff > blankDuration) {
2833 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2835 if (diff - blankDuration == 0) {
2836 trackPlaylist.remove(clipIndex);
2837 } else trackPlaylist.remove_region(blankStart, diff);
2839 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2842 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2843 trackPlaylist.consolidate_blanks(0);
2844 mlt_service_unlock(service.get_service());
2846 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2847 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2848 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2849 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2850 ItemInfo transpinfo;
2851 transpinfo.startPos = info.startPos;
2852 transpinfo.endPos = info.startPos + clipDuration;
2853 transpinfo.track = info.track;
2854 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2856 m_isBlocked = false;
2857 m_mltConsumer->set("refresh", 1);
2861 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2863 Mlt::Service service(m_mltProducer->parent().get_service());
2864 Mlt::Tractor tractor(service);
2865 Mlt::Producer trackProducer(tractor.track(track));
2868 if (blind) trackProducer.set("hide", 3);
2869 else trackProducer.set("hide", 2);
2871 trackProducer.set("hide", 1);
2873 trackProducer.set("hide", 0);
2875 tractor.multitrack()->refresh();
2881 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2883 Mlt::Service service(m_mltProducer->parent().get_service());
2884 int frameOffset = (int) diff.frames(m_fps);
2885 Mlt::Tractor tractor(service);
2886 Mlt::Producer trackProducer(tractor.track(info.track));
2887 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2888 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2889 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2892 mlt_service_lock(service.get_service());
2893 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2894 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2896 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2897 mlt_service_unlock(service.get_service());
2900 int previousStart = clip->get_in();
2901 int previousOut = clip->get_out();
2904 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2905 m_isBlocked = false;
2906 mlt_service_unlock(service.get_service());
2907 m_mltConsumer->set("refresh", 1);
2911 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2913 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2914 Mlt::Service service(m_mltProducer->parent().get_service());
2915 int moveFrame = (int) diff.frames(m_fps);
2916 Mlt::Tractor tractor(service);
2917 Mlt::Producer trackProducer(tractor.track(info.track));
2918 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2919 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2920 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2923 mlt_service_lock(service.get_service());
2924 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2925 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2926 if (clip == NULL || clip->is_blank()) {
2927 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2928 mlt_service_unlock(service.get_service());
2931 int previousStart = clip->get_in();
2932 int previousOut = clip->get_out();
2935 previousStart += moveFrame;
2936 if (previousStart < 0) {
2937 // special case, in point becoming negative (resizing images)
2938 previousOut -= previousStart;
2942 int length = previousOut + 1;
2943 if (length > clip->get_length()) {
2944 clip->parent().set("length", length + 1);
2945 clip->parent().set("out", length);
2946 clip->set("length", length + 1);
2950 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
2951 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
2952 if (moveFrame > 0) {
2953 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2955 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2956 int blankIndex = clipIndex - 1;
2957 int blankLength = trackPlaylist.clip_length(blankIndex);
2958 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2959 if (! trackPlaylist.is_blank(blankIndex)) {
2960 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2962 if (blankLength + moveFrame == 0) trackPlaylist.remove(blankIndex);
2963 else trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2965 trackPlaylist.consolidate_blanks(0);
2966 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2967 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2968 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2969 ItemInfo transpinfo;
2970 transpinfo.startPos = info.startPos + diff;
2971 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2972 transpinfo.track = info.track;
2973 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2975 m_isBlocked = false;
2976 //m_mltConsumer->set("refresh", 1);
2977 mlt_service_unlock(service.get_service());
2978 m_mltConsumer->set("refresh", 1);
2982 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
2984 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
2988 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2990 if (prod == NULL || !prod->is_valid()) {
2991 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2994 kDebug() << "NEW PROD ID: " << prod->get("id");
2996 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2997 Mlt::Service service(m_mltProducer->parent().get_service());
2998 if (service.type() != tractor_type) {
2999 kWarning() << "// TRACTOR PROBLEM";
3002 mlt_service_lock(service.get_service());
3003 Mlt::Tractor tractor(service);
3004 Mlt::Producer trackProducer(tractor.track(track));
3005 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3006 int clipIndex = trackPlaylist.get_clip_index_at(pos);
3007 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3008 if (clipProducer == NULL || clipProducer->is_blank()) {
3009 kDebug() << "// ERROR UPDATING CLIP PROD";
3010 delete clipProducer;
3011 mlt_service_unlock(service.get_service());
3015 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3016 if (!clip || !clip->is_valid()) {
3017 if (clip) delete clip;
3018 delete clipProducer;
3019 mlt_service_unlock(service.get_service());
3023 // move all effects to the correct producer
3024 mltPasteEffects(clipProducer, clip);
3025 trackPlaylist.insert_at(pos, clip, 1);
3027 delete clipProducer;
3028 mlt_service_unlock(service.get_service());
3033 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3037 Mlt::Service service(m_mltProducer->parent().get_service());
3038 if (service.type() != tractor_type) {
3039 kWarning() << "// TRACTOR PROBLEM";
3043 Mlt::Tractor tractor(service);
3044 mlt_service_lock(service.get_service());
3045 Mlt::Producer trackProducer(tractor.track(startTrack));
3046 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3047 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3048 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3049 bool checkLength = false;
3050 if (endTrack == startTrack) {
3051 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3052 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3053 // error, destination is not empty
3055 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3056 delete clipProducer;
3058 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3059 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3060 mlt_service_unlock(service.get_service());
3064 trackPlaylist.consolidate_blanks(0);
3066 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3067 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3068 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3070 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3071 trackPlaylist.consolidate_blanks(1);
3072 delete clipProducer;
3073 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3074 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3076 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3078 //mlt_service_unlock(service.get_service());
3080 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3081 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3082 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3083 // error, destination is not empty
3084 mlt_service_unlock(service.get_service());
3088 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3089 if (!clipProducer || clipProducer->is_blank()) {
3090 // error, destination is not empty
3091 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3092 if (clipProducer) delete clipProducer;
3093 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3094 mlt_service_unlock(service.get_service());
3098 trackPlaylist.consolidate_blanks(0);
3099 destTrackPlaylist.consolidate_blanks(1);
3100 Mlt::Producer *clip;
3101 // check if we are moving a slowmotion producer
3102 QString serv = clipProducer->parent().get("mlt_service");
3103 QString currentid = clipProducer->parent().get("id");
3104 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3105 clip = clipProducer;
3108 // Special case: prod is null when using placeholder clips.
3109 // in that case, use the producer existing in playlist. Note that
3110 // it will bypass the one producer per track logic and might cause
3111 // Sound cracks if clip is moved so that it overlaps another copy of itself
3112 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3113 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3116 // move all effects to the correct producer
3117 mltPasteEffects(clipProducer, clip);
3120 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3121 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3122 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3125 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3127 if (clip == clipProducer) {
3132 delete clipProducer;
3134 destTrackPlaylist.consolidate_blanks(0);
3135 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3136 kDebug() << "//////// moving clip transparency";
3137 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3139 if (clipIndex > trackPlaylist.count()) checkLength = true;
3140 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3143 mlt_service_unlock(service.get_service());
3144 if (checkLength) mltCheckLength(&tractor);
3147 //m_mltConsumer->set("refresh", 1);
3152 QList <int> Render::checkTrackSequence(int track)
3155 Mlt::Service service(m_mltProducer->parent().get_service());
3156 if (service.type() != tractor_type) {
3157 kWarning() << "// TRACTOR PROBLEM";
3160 Mlt::Tractor tractor(service);
3161 mlt_service_lock(service.get_service());
3162 Mlt::Producer trackProducer(tractor.track(track));
3163 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3164 int clipNb = trackPlaylist.count();
3165 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3166 for (int i = 0; i < clipNb; i++) {
3167 Mlt::Producer *c = trackPlaylist.get_clip(i);
3168 int pos = trackPlaylist.clip_start(i);
3169 if (!list.contains(pos)) list.append(pos);
3170 pos += c->get_playtime();
3171 if (!list.contains(pos)) list.append(pos);
3177 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3179 int new_in = (int)newIn.frames(m_fps);
3180 int new_out = (int)newOut.frames(m_fps) - 1;
3181 if (new_in >= new_out) return false;
3182 int old_in = (int)oldIn.frames(m_fps);
3183 int old_out = (int)oldOut.frames(m_fps) - 1;
3185 Mlt::Service service(m_mltProducer->parent().get_service());
3186 Mlt::Tractor tractor(service);
3187 Mlt::Field *field = tractor.field();
3189 bool doRefresh = true;
3190 // Check if clip is visible in monitor
3191 int diff = old_out - m_mltProducer->position();
3192 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3194 diff = new_out - m_mltProducer->position();
3195 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3199 mlt_service_lock(service.get_service());
3201 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3202 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3203 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3204 QString resource = mlt_properties_get(properties, "mlt_service");
3205 int old_pos = (int)(old_in + old_out) / 2;
3208 while (mlt_type == "transition") {
3209 Mlt::Transition transition((mlt_transition) nextservice);
3210 int currentTrack = transition.get_b_track();
3211 int currentIn = (int) transition.get_in();
3212 int currentOut = (int) transition.get_out();
3214 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3216 if (newTrack - startTrack != 0) {
3217 Mlt::Properties trans_props(transition.get_properties());
3218 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3219 Mlt::Properties new_trans_props(new_transition.get_properties());
3220 new_trans_props.inherit(trans_props);
3221 new_transition.set_in_and_out(new_in, new_out);
3222 field->disconnect_service(transition);
3223 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3224 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3225 } else transition.set_in_and_out(new_in, new_out);
3228 nextservice = mlt_service_producer(nextservice);
3229 if (nextservice == NULL) break;
3230 properties = MLT_SERVICE_PROPERTIES(nextservice);
3231 mlt_type = mlt_properties_get(properties, "mlt_type");
3232 resource = mlt_properties_get(properties, "mlt_service");
3234 mlt_service_unlock(service.get_service());
3236 if (doRefresh) refresh();
3237 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3242 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3244 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3245 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3246 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3247 QString resource = mlt_properties_get(properties, "mlt_service");
3248 QList <Mlt::Transition *> trList;
3250 while (mlt_type == "transition") {
3251 Mlt::Transition transition((mlt_transition) nextservice);
3252 int aTrack = transition.get_a_track();
3253 int bTrack = transition.get_b_track();
3254 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3255 Mlt::Properties trans_props(transition.get_properties());
3256 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3257 Mlt::Properties new_trans_props(cp->get_properties());
3258 new_trans_props.inherit(trans_props);
3260 field->disconnect_service(transition);
3262 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3264 nextservice = mlt_service_producer(nextservice);
3265 if (nextservice == NULL) break;
3266 properties = MLT_SERVICE_PROPERTIES(nextservice);
3267 mlt_type = mlt_properties_get(properties, "mlt_type");
3268 resource = mlt_properties_get(properties, "mlt_service");
3271 field->plant_transition(tr, a_track, b_track);
3273 // re-add upper transitions
3274 for (int i = 0; i < trList.count(); i++) {
3275 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3276 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3280 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3282 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3284 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3285 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3288 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3291 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3293 mlt_service serv = m_mltProducer->parent().get_service();
3294 mlt_service_lock(serv);
3297 mlt_service nextservice = mlt_service_get_producer(serv);
3298 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3299 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3300 QString resource = mlt_properties_get(properties, "mlt_service");
3301 int in_pos = (int) in.frames(m_fps);
3302 int out_pos = (int) out.frames(m_fps) - 1;
3304 while (mlt_type == "transition") {
3305 mlt_transition tr = (mlt_transition) nextservice;
3306 int currentTrack = mlt_transition_get_b_track(tr);
3307 int currentBTrack = mlt_transition_get_a_track(tr);
3308 int currentIn = (int) mlt_transition_get_in(tr);
3309 int currentOut = (int) mlt_transition_get_out(tr);
3311 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3313 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3314 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3315 QMap<QString, QString>::Iterator it;
3317 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3319 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3320 if (currentId != xml.attribute("id")) {
3321 // The transition ID is not the same, so reset all properties
3322 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3323 // Cleanup previous properties
3324 QStringList permanentProps;
3325 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3326 permanentProps << "out" << "a_track" << "b_track";
3327 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3328 QString propName = mlt_properties_get_name(transproperties, i);
3329 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3330 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3335 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3336 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3338 if (currentBTrack != a_track) {
3339 mlt_properties_set_int(transproperties, "a_track", a_track);
3341 for (it = map.begin(); it != map.end(); ++it) {
3343 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3344 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3345 //filter->set("kdenlive_id", id);
3349 nextservice = mlt_service_producer(nextservice);
3350 if (nextservice == NULL) break;
3351 properties = MLT_SERVICE_PROPERTIES(nextservice);
3352 mlt_type = mlt_properties_get(properties, "mlt_type");
3353 resource = mlt_properties_get(properties, "mlt_service");
3355 mlt_service_unlock(serv);
3358 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3361 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3363 mlt_service serv = m_mltProducer->parent().get_service();
3365 mlt_service_lock(serv);
3367 Mlt::Service service(serv);
3368 Mlt::Tractor tractor(service);
3369 Mlt::Field *field = tractor.field();
3371 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3373 mlt_service nextservice = mlt_service_get_producer(serv);
3374 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3375 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3376 QString resource = mlt_properties_get(properties, "mlt_service");
3378 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3379 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3381 while (mlt_type == "transition") {
3382 mlt_transition tr = (mlt_transition) nextservice;
3383 int currentTrack = mlt_transition_get_b_track(tr);
3384 int currentIn = (int) mlt_transition_get_in(tr);
3385 int currentOut = (int) mlt_transition_get_out(tr);
3386 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3388 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3389 mlt_field_disconnect_service(field->get_field(), nextservice);
3392 nextservice = mlt_service_producer(nextservice);
3393 if (nextservice == NULL) break;
3394 properties = MLT_SERVICE_PROPERTIES(nextservice);
3395 mlt_type = mlt_properties_get(properties, "mlt_type");
3396 resource = mlt_properties_get(properties, "mlt_service");
3398 mlt_service_unlock(serv);
3401 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3404 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3406 QDomNodeList attribs = xml.elementsByTagName("parameter");
3407 QMap<QString, QString> map;
3408 for (int i = 0; i < attribs.count(); i++) {
3409 QDomElement e = attribs.item(i).toElement();
3410 QString name = e.attribute("name");
3411 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3412 map[name] = e.attribute("default");
3413 if (!e.attribute("value").isEmpty()) {
3414 map[name] = e.attribute("value");
3416 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3417 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3418 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3421 if (e.attribute("namedesc").contains(';')) {
3422 QString format = e.attribute("format");
3423 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3424 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3426 QTextStream txtNeu(&neu);
3427 if (values.size() > 0)
3428 txtNeu << (int)values[0].toDouble();
3430 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3431 txtNeu << separators[i];
3432 txtNeu << (int)(values[i+1].toDouble());
3434 if (i < separators.size())
3435 txtNeu << separators[i];
3436 map[e.attribute("name")] = neu;
3443 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3445 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3446 Mlt::Service service(m_mltProducer->parent().get_service());
3447 Mlt::Tractor tractor(service);
3448 Mlt::Field *field = tractor.field();
3450 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3451 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3452 transition->set("transparency", id);
3453 transition->set("fill", 1);
3454 transition->set("internal_added", 237);
3455 field->plant_transition(*transition, transitiontrack, info.track);
3459 void Render::mltDeleteTransparency(int pos, int track, int id)
3461 Mlt::Service service(m_mltProducer->parent().get_service());
3462 Mlt::Tractor tractor(service);
3463 Mlt::Field *field = tractor.field();
3465 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3466 mlt_service serv = m_mltProducer->parent().get_service();
3468 mlt_service nextservice = mlt_service_get_producer(serv);
3469 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3470 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3471 QString resource = mlt_properties_get(properties, "mlt_service");
3473 while (mlt_type == "transition") {
3474 mlt_transition tr = (mlt_transition) nextservice;
3475 int currentTrack = mlt_transition_get_b_track(tr);
3476 int currentIn = (int) mlt_transition_get_in(tr);
3477 int currentOut = (int) mlt_transition_get_out(tr);
3478 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3479 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3481 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3482 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3483 mlt_field_disconnect_service(field->get_field(), nextservice);
3486 nextservice = mlt_service_producer(nextservice);
3487 if (nextservice == NULL) break;
3488 properties = MLT_SERVICE_PROPERTIES(nextservice);
3489 mlt_type = mlt_properties_get(properties, "mlt_type");
3490 resource = mlt_properties_get(properties, "mlt_service");
3492 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3495 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3497 Mlt::Service service(m_mltProducer->parent().get_service());
3498 Mlt::Tractor tractor(service);
3500 mlt_service_lock(service.get_service());
3501 m_mltConsumer->set("refresh", 0);
3504 mlt_service serv = m_mltProducer->parent().get_service();
3505 mlt_service nextservice = mlt_service_get_producer(serv);
3506 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3507 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3508 QString resource = mlt_properties_get(properties, "mlt_service");
3509 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3510 while (mlt_type == "transition") {
3511 mlt_transition tr = (mlt_transition) nextservice;
3512 int currentTrack = mlt_transition_get_b_track(tr);
3513 int currentIn = (int) mlt_transition_get_in(tr);
3514 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3515 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3516 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3517 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3518 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3519 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3522 nextservice = mlt_service_producer(nextservice);
3523 if (nextservice == NULL) break;
3524 properties = MLT_SERVICE_PROPERTIES(nextservice);
3525 mlt_type = mlt_properties_get(properties, "mlt_type");
3526 resource = mlt_properties_get(properties, "mlt_service");
3528 mlt_service_unlock(service.get_service());
3530 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3534 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3536 Mlt::Service service(m_mltProducer->parent().get_service());
3537 Mlt::Tractor tractor(service);
3539 mlt_service_lock(service.get_service());
3540 m_mltConsumer->set("refresh", 0);
3543 mlt_service serv = m_mltProducer->parent().get_service();
3544 mlt_service nextservice = mlt_service_get_producer(serv);
3545 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3546 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3547 QString resource = mlt_properties_get(properties, "mlt_service");
3549 while (mlt_type == "transition") {
3550 mlt_transition tr = (mlt_transition) nextservice;
3551 int currentTrack = mlt_transition_get_b_track(tr);
3552 int currentaTrack = mlt_transition_get_a_track(tr);
3553 int currentIn = (int) mlt_transition_get_in(tr);
3554 int currentOut = (int) mlt_transition_get_out(tr);
3555 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3556 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3557 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3558 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3559 kDebug() << "//////MOVING";
3560 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3561 if (endTrack != startTrack) {
3562 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3563 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3564 mlt_properties_set_int(properties, "b_track", endTrack);
3568 nextservice = mlt_service_producer(nextservice);
3569 if (nextservice == NULL) break;
3570 properties = MLT_SERVICE_PROPERTIES(nextservice);
3571 mlt_type = mlt_properties_get(properties, "mlt_type");
3572 resource = mlt_properties_get(properties, "mlt_service");
3575 mlt_service_unlock(service.get_service());
3576 m_mltConsumer->set("refresh", 1);
3580 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3582 if (in >= out) return false;
3583 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3584 Mlt::Service service(m_mltProducer->parent().get_service());
3586 Mlt::Tractor tractor(service);
3587 Mlt::Field *field = tractor.field();
3589 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3590 if (out != GenTime())
3591 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3593 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3594 QMap<QString, QString>::Iterator it;
3596 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3597 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3598 if (xml.hasAttribute("id"))
3599 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3601 for (it = args.begin(); it != args.end(); ++it) {
3603 if (!it.value().isEmpty())
3604 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3605 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3607 // attach transition
3608 mltPlantTransition(field, *transition, a_track, b_track);
3609 // field->plant_transition(*transition, a_track, b_track);
3610 if (do_refresh) refresh();
3614 void Render::mltSavePlaylist()
3616 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3617 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3618 fileConsumer.set("resource", "/tmp/playlist.mlt");
3620 Mlt::Service service(m_mltProducer->get_service());
3622 fileConsumer.connect(service);
3623 fileConsumer.start();
3626 const QList <Mlt::Producer *> Render::producersList()
3628 QList <Mlt::Producer *> prods;
3629 if (m_mltProducer == NULL) return prods;
3630 Mlt::Service service(m_mltProducer->parent().get_service());
3631 if (service.type() != tractor_type) return prods;
3632 Mlt::Tractor tractor(service);
3635 int trackNb = tractor.count();
3636 for (int t = 1; t < trackNb; t++) {
3637 Mlt::Producer *tt = tractor.track(t);
3638 Mlt::Producer trackProducer(tt);
3640 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3641 int clipNb = trackPlaylist.count();
3642 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3643 for (int i = 0; i < clipNb; i++) {
3644 Mlt::Producer *c = trackPlaylist.get_clip(i);
3645 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3647 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3648 ids.append(nprod->get("id"));
3649 prods.append(nprod);
3650 } else delete nprod;
3658 void Render::fillSlowMotionProducers()
3660 if (m_mltProducer == NULL) return;
3661 Mlt::Service service(m_mltProducer->parent().get_service());
3662 if (service.type() != tractor_type) return;
3664 Mlt::Tractor tractor(service);
3666 int trackNb = tractor.count();
3667 for (int t = 1; t < trackNb; t++) {
3668 Mlt::Producer *tt = tractor.track(t);
3669 Mlt::Producer trackProducer(tt);
3671 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3672 int clipNb = trackPlaylist.count();
3673 for (int i = 0; i < clipNb; i++) {
3674 Mlt::Producer *c = trackPlaylist.get_clip(i);
3675 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3677 QString id = nprod->get("id");
3678 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3679 // this is a slowmotion producer, add it to the list
3680 QString url = QString::fromUtf8(nprod->get("resource"));
3681 int strobe = nprod->get_int("strobe");
3682 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3683 if (!m_slowmotionProducers.contains(url)) {
3684 m_slowmotionProducers.insert(url, nprod);
3686 } else delete nprod;
3693 void Render::mltInsertTrack(int ix, bool videoTrack)
3698 Mlt::Service service(m_mltProducer->parent().get_service());
3699 mlt_service_lock(service.get_service());
3700 if (service.type() != tractor_type) {
3701 kWarning() << "// TRACTOR PROBLEM";
3705 Mlt::Tractor tractor(service);
3707 Mlt::Playlist playlist;
3708 int ct = tractor.count();
3710 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3716 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3717 tractor.set_track(playlist, pos);
3718 Mlt::Producer newProd(tractor.track(pos));
3719 if (!videoTrack) newProd.set("hide", 1);
3721 for (; pos <= ct; pos++) {
3722 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3723 tractor.set_track(*prodToMove, pos);
3724 prodToMove = prodToMove2;
3727 tractor.set_track(playlist, ix);
3728 Mlt::Producer newProd(tractor.track(ix));
3729 if (!videoTrack) newProd.set("hide", 1);
3733 mlt_service serv = m_mltProducer->parent().get_service();
3734 mlt_service nextservice = mlt_service_get_producer(serv);
3735 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3736 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3737 QString resource = mlt_properties_get(properties, "mlt_service");
3739 while (mlt_type == "transition") {
3740 if (resource != "mix") {
3741 mlt_transition tr = (mlt_transition) nextservice;
3742 int currentTrack = mlt_transition_get_b_track(tr);
3743 int currentaTrack = mlt_transition_get_a_track(tr);
3744 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3746 if (currentTrack >= ix) {
3747 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3748 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3751 nextservice = mlt_service_producer(nextservice);
3752 if (nextservice == NULL) break;
3753 properties = MLT_SERVICE_PROPERTIES(nextservice);
3754 mlt_type = mlt_properties_get(properties, "mlt_type");
3755 resource = mlt_properties_get(properties, "mlt_service");
3758 // Add audio mix transition to last track
3759 Mlt::Field *field = tractor.field();
3760 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3761 transition->set("a_track", 1);
3762 transition->set("b_track", ct);
3763 transition->set("always_active", 1);
3764 transition->set("internal_added", 237);
3765 transition->set("combine", 1);
3766 field->plant_transition(*transition, 1, ct);
3767 //mlt_service_unlock(m_mltConsumer->get_service());
3768 mlt_service_unlock(service.get_service());
3769 //tractor.multitrack()->refresh();
3770 //tractor.refresh();
3772 blockSignals(false);
3776 void Render::mltDeleteTrack(int ix)
3779 doc.setContent(sceneList(), false);
3780 int tracksCount = doc.elementsByTagName("track").count() - 1;
3781 QDomNode track = doc.elementsByTagName("track").at(ix);
3782 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3783 QDomNodeList transitions = doc.elementsByTagName("transition");
3784 for (int i = 0; i < transitions.count(); i++) {
3785 QDomElement e = transitions.at(i).toElement();
3786 QDomNodeList props = e.elementsByTagName("property");
3787 QMap <QString, QString> mappedProps;
3788 for (int j = 0; j < props.count(); j++) {
3789 QDomElement f = props.at(j).toElement();
3790 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3792 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3793 tractor.removeChild(transitions.at(i));
3795 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3796 // Transition needs to be moved
3797 int a_track = mappedProps.value("a_track").toInt();
3798 int b_track = mappedProps.value("b_track").toInt();
3799 if (a_track > 0 && a_track >= ix) a_track --;
3800 if (b_track == ix) {
3801 // transition was on the deleted track, so remove it
3802 tractor.removeChild(transitions.at(i));
3806 if (b_track > 0 && b_track > ix) b_track --;
3807 for (int j = 0; j < props.count(); j++) {
3808 QDomElement f = props.at(j).toElement();
3809 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3810 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3815 tractor.removeChild(track);
3816 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3817 setSceneList(doc.toString(), m_framePosition);
3819 /* if (m_mltProducer != NULL) {
3820 Mlt::Producer parentProd(m_mltProducer->parent());
3821 if (parentProd.get_producer() != NULL) {
3822 Mlt::Service service(parentProd.get_service());
3823 if (service.type() == tractor_type) {
3824 Mlt::Tractor tractor(service);
3825 mltCheckLength(&tractor);
3832 void Render::updatePreviewSettings()
3834 kDebug() << "////// RESTARTING CONSUMER";
3835 if (!m_mltConsumer || !m_mltProducer) return;
3836 if (m_mltProducer->get_playtime() == 0) return;
3837 Mlt::Service service(m_mltProducer->parent().get_service());
3838 if (service.type() != tractor_type) return;
3840 //m_mltConsumer->set("refresh", 0);
3841 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3842 m_mltConsumer->purge();
3843 QString scene = sceneList();
3845 if (m_mltProducer) {
3846 pos = m_mltProducer->position();
3849 setSceneList(scene, pos);
3853 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3855 // Update all frame positions to the new fps value
3856 //WARNING: there are probably some effects or other that hold a frame value
3857 // as parameter and will also need to be updated here!
3859 doc.setContent(scene);
3861 double factor = new_fps / current_fps;
3862 QDomNodeList producers = doc.elementsByTagName("producer");
3863 for (int i = 0; i < producers.count(); i++) {
3864 QDomElement prod = producers.at(i).toElement();
3865 prod.removeAttribute("in");
3866 prod.removeAttribute("out");
3868 QDomNodeList props = prod.childNodes();
3869 for (int j = 0; j < props.count(); j++) {
3870 QDomElement param = props.at(j).toElement();
3871 QString paramName = param.attribute("name");
3872 if (paramName.startsWith("meta.") || paramName == "length") {
3873 prod.removeChild(props.at(j));
3879 QDomNodeList entries = doc.elementsByTagName("entry");
3880 for (int i = 0; i < entries.count(); i++) {
3881 QDomElement entry = entries.at(i).toElement();
3882 int in = entry.attribute("in").toInt();
3883 int out = entry.attribute("out").toInt();
3884 in = factor * in + 0.5;
3885 out = factor * out + 0.5;
3886 entry.setAttribute("in", in);
3887 entry.setAttribute("out", out);
3890 QDomNodeList blanks = doc.elementsByTagName("blank");
3891 for (int i = 0; i < blanks.count(); i++) {
3892 QDomElement blank = blanks.at(i).toElement();
3893 int length = blank.attribute("length").toInt();
3894 length = factor * length + 0.5;
3895 blank.setAttribute("length", QString::number(length));
3898 QDomNodeList filters = doc.elementsByTagName("filter");
3899 for (int i = 0; i < filters.count(); i++) {
3900 QDomElement filter = filters.at(i).toElement();
3901 int in = filter.attribute("in").toInt();
3902 int out = filter.attribute("out").toInt();
3903 in = factor * in + 0.5;
3904 out = factor * out + 0.5;
3905 filter.setAttribute("in", in);
3906 filter.setAttribute("out", out);
3909 QDomNodeList transitions = doc.elementsByTagName("transition");
3910 for (int i = 0; i < transitions.count(); i++) {
3911 QDomElement transition = transitions.at(i).toElement();
3912 int in = transition.attribute("in").toInt();
3913 int out = transition.attribute("out").toInt();
3914 in = factor * in + 0.5;
3915 out = factor * out + 0.5;
3916 transition.setAttribute("in", in);
3917 transition.setAttribute("out", out);
3918 QDomNodeList props = transition.childNodes();
3919 for (int j = 0; j < props.count(); j++) {
3920 QDomElement param = props.at(j).toElement();
3921 QString paramName = param.attribute("name");
3922 if (paramName == "geometry") {
3923 QString geom = param.firstChild().nodeValue();
3924 QStringList keys = geom.split(';');
3925 QStringList newKeys;
3926 for (int k = 0; k < keys.size(); ++k) {
3927 if (keys.at(k).contains('=')) {
3928 int pos = keys.at(k).section('=', 0, 0).toInt();
3929 pos = factor * pos + 0.5;
3930 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3931 } else newKeys.append(keys.at(k));
3933 param.firstChild().setNodeValue(newKeys.join(";"));
3937 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3938 int out = tractor.attribute("out").toInt();
3939 out = factor * out + 0.5;
3940 tractor.setAttribute("out", out);
3941 emit durationChanged(out);
3943 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3944 return doc.toString();
3948 void Render::sendFrameUpdate()
3950 if (m_mltProducer) {
3951 Mlt::Frame * frame = m_mltProducer->get_frame();
3952 emitFrameUpdated(*frame);
3958 #include "renderer.moc"