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 (profile.isEmpty()) profile = KdenliveSettings::current_profile();
108 buildConsumer(profile);
110 m_mltProducer = m_blackClip->cut(0, 50);
111 m_mltConsumer->connect(*m_mltProducer);
112 m_mltProducer->set_speed(0.0);
122 void Render::closeMlt()
126 Mlt::Service service(m_mltProducer->parent().get_service());
127 mlt_service_lock(service.get_service());
129 if (service.type() == tractor_type) {
130 Mlt::Tractor tractor(service);
131 Mlt::Field *field = tractor.field();
132 mlt_service nextservice = mlt_service_get_producer(service.get_service());
133 mlt_service nextservicetodisconnect;
134 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
135 QString mlt_type = mlt_properties_get(properties, "mlt_type");
136 QString resource = mlt_properties_get(properties, "mlt_service");
137 // Delete all transitions
138 while (mlt_type == "transition") {
139 nextservicetodisconnect = nextservice;
140 nextservice = mlt_service_producer(nextservice);
141 mlt_field_disconnect_service(field->get_field(), nextservicetodisconnect);
142 nextservice = mlt_service_producer(nextservice);
143 if (nextservice == NULL) break;
144 properties = MLT_SERVICE_PROPERTIES(nextservice);
145 mlt_type = mlt_properties_get(properties, "mlt_type");
146 resource = mlt_properties_get(properties, "mlt_service");
149 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
150 Mlt::Producer trackProducer(tractor.track(trackNb));
151 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
152 if (trackPlaylist.type() == playlist_type) trackPlaylist.clear();
155 mlt_service_unlock(service.get_service());
158 kDebug() << "// // // CLOSE RENDERER " << m_name;
159 delete m_mltConsumer;
160 delete m_mltProducer;
165 void Render::slotSwitchFullscreen()
167 if (m_mltConsumer) m_mltConsumer->set("full_screen", 1);
170 void Render::buildConsumer(const QString profileName)
172 m_activeProfile = profileName;
173 char *tmp = qstrdup(m_activeProfile.toUtf8().constData());
174 setenv("MLT_PROFILE", tmp, 1);
178 //TODO: uncomment following line when everything is clean
179 //if (m_mltProfile) delete m_mltProfile;
180 m_mltProfile = new Mlt::Profile(tmp);
183 QString videoDriver = KdenliveSettings::videodrivername();
184 if (!videoDriver.isEmpty()) {
185 if (videoDriver == "x11_noaccel") {
186 setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1);
189 unsetenv("SDL_VIDEO_YUV_HWACCEL");
192 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
194 //m_mltConsumer->set("fullscreen", 1);
197 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_audio");
198 m_mltConsumer->set("preview_off", 1);
199 m_mltConsumer->set("preview_format", mlt_image_rgb24a);
200 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_gl_frame_show);
202 m_mltConsumer = new Mlt::Consumer(*m_mltProfile, "sdl_preview");
203 // FIXME: the event object returned by the listen gets leaked...
204 m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show);
205 m_mltConsumer->set("window_id", m_winid);
207 m_mltConsumer->set("resize", 1);
208 m_mltConsumer->set("terminate_on_pause", 1);
209 m_mltConsumer->set("window_background", KdenliveSettings::window_background().name().toUtf8().constData());
210 m_mltConsumer->set("rescale", "nearest");
211 mlt_log_set_callback(kdenlive_callback);
213 QString audioDevice = KdenliveSettings::audiodevicename();
214 if (!audioDevice.isEmpty())
215 m_mltConsumer->set("audio_device", audioDevice.toUtf8().constData());
217 if (!videoDriver.isEmpty())
218 m_mltConsumer->set("video_driver", videoDriver.toUtf8().constData());
220 QString audioDriver = KdenliveSettings::audiodrivername();
223 // Disabled because the "auto" detected driver was sometimes wrong
224 if (audioDriver.isEmpty())
225 audioDriver = KdenliveSettings::autoaudiodrivername();
228 if (!audioDriver.isEmpty())
229 m_mltConsumer->set("audio_driver", audioDriver.toUtf8().constData());
231 int volume = KdenliveSettings::volume();
232 m_mltConsumer->set("volume", (float)volume / 100);
234 m_mltConsumer->set("progressive", 1);
235 m_mltConsumer->set("audio_buffer", 1024);
236 m_mltConsumer->set("frequency", 48000);
238 m_blackClip = new Mlt::Producer(*m_mltProfile, "colour", "black");
239 m_blackClip->set("id", "black");
240 m_blackClip->set("mlt_type", "producer");
243 Mlt::Producer *Render::invalidProducer(const QString &id)
245 Mlt::Producer *clip = new Mlt::Producer(*m_mltProfile, "colour", "red");
246 clip->set("id", id.toUtf8().constData());
247 clip->set("mlt_type", "producer");
251 int Render::resetProfile(const QString profileName)
254 QString videoDriver = KdenliveSettings::videodrivername();
255 QString currentDriver = m_mltConsumer->get("video_driver");
256 if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel";
257 QString background = KdenliveSettings::window_background().name();
258 QString currentBackground = m_mltConsumer->get("window_background");
259 int volume = KdenliveSettings::volume();
260 int currentVolume = (int)(QString(m_mltConsumer->get("volume")).toDouble() * 100.0);
261 if (m_activeProfile == profileName && currentDriver == videoDriver && volume == currentVolume && background == currentBackground) {
262 kDebug() << "reset to same profile, nothing to do";
266 if (m_isSplitView) slotSplitView(false);
267 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
268 m_mltConsumer->purge();
269 delete m_mltConsumer;
270 m_mltConsumer = NULL;
272 QString scene = sceneList();
274 double current_fps = m_mltProfile->fps();
279 pos = m_mltProducer->position();
281 Mlt::Service service(m_mltProducer->get_service());
282 if (service.type() == tractor_type) {
283 Mlt::Tractor tractor(service);
284 for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) {
285 Mlt::Producer trackProducer(tractor.track(trackNb));
286 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
287 trackPlaylist.clear();
291 delete m_mltProducer;
293 m_mltProducer = NULL;
294 buildConsumer(profileName);
295 double new_fps = m_mltProfile->fps();
296 if (current_fps != new_fps) {
297 // fps changed, we must update the scenelist positions
298 scene = updateSceneListFps(current_fps, new_fps, scene);
300 //kDebug() << "//RESET WITHSCENE: " << scene;
301 setSceneList(scene, pos);
302 // producers have changed (different profile), so reset them...
303 emit refreshDocumentProducers();
304 /*Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "xml-string", scene.toUtf8().constData());
305 m_mltProducer = producer;
306 m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black");
307 m_mltProducer->optimise();
308 m_mltProducer->set_speed(0);
311 //delete m_mltProfile;
312 // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer());
313 //mlt_profile prof = m_mltProfile->get_profile();
314 //mlt_properties_set_data(properties, "_profile", prof, 0, (mlt_destructor)mlt_profile_close, NULL);
315 //mlt_properties_set(properties, "profile", "hdv_1080_50i");
316 //m_mltConsumer->set("profile", (char *) profile.toUtf8().data());
317 //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data());
319 //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties );
324 void Render::seek(GenTime time)
329 m_mltProducer->seek((int)(time.frames(m_fps)));
334 /*QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool border) {
335 QPixmap pix(width, height);
337 mlt_image_format format = mlt_image_rgb24a;
338 uint8_t *thumb = frame->get_image(format, width, height);
339 QImage image(thumb, width, height, QImage::Format_ARGB32);
341 if (!image.isNull()) {
342 pix = pix.fromImage(image);
344 QPainter painter(&pix);
345 painter.drawRect(0, 0, width - 1, height - 1);
347 } else pix.fill(Qt::black);
351 int Render::frameRenderWidth() const
353 return m_mltProfile->width();
356 int Render::renderWidth() const
358 return (int)(m_mltProfile->height() * m_mltProfile->dar() + 0.5);
361 int Render::renderHeight() const
363 return m_mltProfile->height();
366 QImage Render::extractFrame(int frame_position, int width, int height)
369 width = renderWidth();
370 height = renderHeight();
371 } else if (width % 2 == 1) width++;
373 if (!m_mltProducer) {
374 QImage pix(width, height, QImage::Format_RGB32);
378 return KThumb::getFrame(m_mltProducer, frame_position, width, height);
381 QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/)
385 if (url.fileName().startsWith(".all.")) { // check for slideshow
386 QString fileType = url.fileName().right(3);
388 QStringList::Iterator it;
390 QDir dir(url.directory());
392 filter << "*." + fileType;
393 filter << "*." + fileType.toUpper();
394 more = dir.entryList(filter, QDir::Files);
395 im.load(url.directory() + '/' + more.at(0));
396 } else im.load(url.path());
397 //pixmap = im.scaled(width, height);
401 double Render::consumerRatio() const
403 if (!m_mltConsumer) return 1.0;
404 return (m_mltConsumer->get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den"));
408 int Render::getLength()
412 // kDebug()<<"////// LENGTH: "<<mlt_producer_get_playtime(m_mltProducer->get_producer());
413 return mlt_producer_get_playtime(m_mltProducer->get_producer());
418 bool Render::isValid(KUrl url)
420 Mlt::Producer producer(*m_mltProfile, url.path().toUtf8().constData());
421 if (producer.is_blank())
427 double Render::dar() const
429 return m_mltProfile->dar();
433 void Render::slotSplitView(bool doit)
435 m_isSplitView = doit;
436 Mlt::Service service(m_mltProducer->parent().get_service());
437 Mlt::Tractor tractor(service);
438 if (service.type() != tractor_type || tractor.count() < 2) return;
439 Mlt::Field *field = tractor.field();
441 for (int i = 1, screen = 0; i < tractor.count() && screen < 4; i++) {
442 Mlt::Producer trackProducer(tractor.track(i));
443 kDebug() << "// TRACK: " << i << ", HIDE: " << trackProducer.get("hide");
444 if (QString(trackProducer.get("hide")).toInt() != 1) {
445 kDebug() << "// ADIDNG TRACK: " << i;
446 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
447 transition->set("mlt_service", "composite");
448 transition->set("a_track", 0);
449 transition->set("b_track", i);
450 transition->set("distort", 1);
451 transition->set("internal_added", "200");
458 tmp = "50%,0:50%x50%";
461 tmp = "0,50%:50%x50%";
465 tmp = "50%,50%:50%x50%";
468 transition->set("geometry", tmp);
469 transition->set("always_active", "1");
470 field->plant_transition(*transition, 0, i);
475 m_mltConsumer->set("refresh", 1);
477 mlt_service serv = m_mltProducer->parent().get_service();
478 mlt_service nextservice = mlt_service_get_producer(serv);
479 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
480 QString mlt_type = mlt_properties_get(properties, "mlt_type");
481 QString resource = mlt_properties_get(properties, "mlt_service");
483 while (mlt_type == "transition") {
484 QString added = mlt_properties_get(MLT_SERVICE_PROPERTIES(nextservice), "internal_added");
485 if (added == "200") {
486 mlt_field_disconnect_service(field->get_field(), nextservice);
488 nextservice = mlt_service_producer(nextservice);
489 if (nextservice == NULL) break;
490 properties = MLT_SERVICE_PROPERTIES(nextservice);
491 mlt_type = mlt_properties_get(properties, "mlt_type");
492 resource = mlt_properties_get(properties, "mlt_service");
493 m_mltConsumer->set("refresh", 1);
498 void Render::getFileProperties(const QDomElement xml, const QString &clipId, int imageHeight, bool replaceProducer)
500 KUrl url = KUrl(xml.attribute("resource", QString()));
501 Mlt::Producer *producer = NULL;
502 //kDebug() << "PROFILE WIDT: "<< xml.attribute("mlt_service") << ": "<< m_mltProfile->width() << "\n...................\n\n";
503 /*if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) {
504 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
507 if (xml.attribute("type").toInt() == COLOR) {
508 producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + xml.attribute("colour")).toUtf8().constData());
509 } else if (xml.attribute("type").toInt() == TEXT) {
510 producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + xml.attribute("resource")).toUtf8().constData());
511 if (producer && producer->is_valid() && xml.hasAttribute("xmldata"))
512 producer->set("xmldata", xml.attribute("xmldata").toUtf8().constData());
513 } else if (url.isEmpty()) {
515 QDomElement mlt = doc.createElement("mlt");
516 QDomElement play = doc.createElement("playlist");
517 doc.appendChild(mlt);
518 mlt.appendChild(play);
519 play.appendChild(doc.importNode(xml, true));
520 producer = new Mlt::Producer(*m_mltProfile, "xml-string", doc.toString().toUtf8().constData());
522 producer = new Mlt::Producer(*m_mltProfile, url.path().toUtf8().constData());
525 if (producer == NULL || producer->is_blank() || !producer->is_valid()) {
526 kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: ";
527 emit removeInvalidClip(clipId, replaceProducer);
532 if (xml.hasAttribute("force_aspect_ratio")) {
533 double aspect = xml.attribute("force_aspect_ratio").toDouble();
534 if (aspect > 0) producer->set("force_aspect_ratio", aspect);
537 if (xml.hasAttribute("force_fps")) {
538 double fps = xml.attribute("force_fps").toDouble();
539 if (fps > 0) producer->set("force_fps", fps);
542 if (xml.hasAttribute("force_progressive")) {
544 int progressive = xml.attribute("force_progressive").toInt(&ok);
545 if (ok) producer->set("force_progressive", progressive);
547 if (xml.hasAttribute("threads")) {
548 int threads = xml.attribute("threads").toInt();
549 if (threads != 1) producer->set("threads", threads);
551 if (xml.hasAttribute("video_index")) {
552 int vindex = xml.attribute("video_index").toInt();
553 if (vindex != 0) producer->set("video_index", vindex);
555 if (xml.hasAttribute("audio_index")) {
556 int aindex = xml.attribute("audio_index").toInt();
557 if (aindex != 0) producer->set("audio_index", aindex);
560 // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
561 if (xml.attribute("type").toInt() == COLOR || xml.attribute("type").toInt() == TEXT
562 || xml.attribute("type").toInt() == IMAGE || xml.attribute("type").toInt() == SLIDESHOW)
563 producer->set("length", xml.attribute("out").toInt() - xml.attribute("in").toInt() + 1);
565 if (xml.hasAttribute("out"))
566 producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt());
568 producer->set("id", clipId.toUtf8().constData());
570 if (xml.hasAttribute("templatetext"))
571 producer->set("templatetext", xml.attribute("templatetext").toUtf8().constData());
573 if (!replaceProducer && xml.hasAttribute("file_hash")) {
574 // Clip already has all properties
575 emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer);
579 int width = (int)(imageHeight * m_mltProfile->dar() + 0.5);
580 QMap < QString, QString > filePropertyMap;
581 QMap < QString, QString > metadataPropertyMap;
583 int frameNumber = xml.attribute("thumbnail", "0").toInt();
584 if (frameNumber != 0) producer->seek(frameNumber);
586 filePropertyMap["duration"] = QString::number(producer->get_playtime());
587 //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime();
589 Mlt::Frame *frame = producer->get_frame();
591 if (xml.attribute("type").toInt() == SLIDESHOW) {
592 int ttl = xml.hasAttribute("ttl") ? xml.attribute("ttl").toInt() : 0;
593 if (ttl) producer->set("ttl", ttl);
594 if (!xml.attribute("animation").isEmpty()) {
595 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "affine");
596 if (filter && filter->is_valid()) {
598 QString geometry = SlideshowClip::animationToGeometry(xml.attribute("animation"), cycle);
599 if (!geometry.isEmpty()) {
600 if (xml.attribute("animation").contains("low-pass")) {
601 Mlt::Filter *blur = new Mlt::Filter(*m_mltProfile, "boxblur");
602 if (blur && blur->is_valid())
603 producer->attach(*blur);
605 filter->set("transition.geometry", geometry.toUtf8().data());
606 filter->set("transition.cycle", cycle);
607 producer->attach(*filter);
611 if (xml.attribute("fade") == "1") {
612 // user wants a fade effect to slideshow
613 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma");
614 if (filter && filter->is_valid()) {
615 if (ttl) filter->set("cycle", ttl);
616 if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("duration", xml.attribute("luma_duration").toInt());
617 if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) {
618 filter->set("luma.resource", xml.attribute("luma_file").toUtf8().constData());
619 if (xml.hasAttribute("softness")) {
620 int soft = xml.attribute("softness").toInt();
621 filter->set("luma.softness", (double) soft / 100.0);
624 producer->attach(*filter);
627 if (xml.attribute("crop") == "1") {
628 // user wants to center crop the slides
629 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "crop");
630 if (filter && filter->is_valid()) {
631 filter->set("center", 1);
632 producer->attach(*filter);
637 if (producer->get_double("meta.media.frame_rate_den") > 0) {
638 filePropertyMap["fps"] = QString::number(producer->get_double("meta.media.frame_rate_num") / producer->get_double("meta.media.frame_rate_den"));
639 } else filePropertyMap["fps"] = producer->get("source_fps");
641 if (frame && frame->is_valid()) {
642 filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height"));
643 filePropertyMap["frequency"] = QString::number(frame->get_int("frequency"));
644 filePropertyMap["channels"] = QString::number(frame->get_int("channels"));
645 filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio");
647 if (frame->get_int("test_image") == 0) {
648 if (url.path().endsWith(".mlt") || url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) {
649 filePropertyMap["type"] = "playlist";
650 metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title"));
651 } else if (frame->get_int("test_audio") == 0)
652 filePropertyMap["type"] = "av";
654 filePropertyMap["type"] = "video";
656 mlt_image_format format = mlt_image_rgb24a;
657 int frame_width = width;
658 int frame_height = imageHeight;
659 uint8_t *data = frame->get_image(format, frame_width, frame_height, 0);
660 QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32_Premultiplied);
663 if (!image.isNull()) {
664 if (frame_width > (2 * width)) {
665 // there was a scaling problem, do it manually
666 QImage scaled = image.scaled(width, imageHeight);
667 pix = QPixmap::fromImage(scaled.rgbSwapped());
668 } else pix = QPixmap::fromImage(image.rgbSwapped());
672 emit replyGetImage(clipId, pix);
674 } else if (frame->get_int("test_audio") == 0) {
675 QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, imageHeight));
676 emit replyGetImage(clipId, pixmap);
677 filePropertyMap["type"] = "audio";
681 // Retrieve audio / video codec name
685 if (producer->get_int("video_index") > -1) {
686 /*if (context->duration == AV_NOPTS_VALUE) {
687 kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION";
688 emit removeInvalidClip(clipId);
692 // Get the video_index
693 int default_video = producer->get_int("video_index");
695 int default_audio = producer->get_int("audio_index");
698 // Find maximum stream index values
699 for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) {
700 snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
701 QString type = producer->get(property);
704 else if (type == "audio")
707 filePropertyMap["default_video"] = QString::number(default_video);
708 filePropertyMap["video_max"] = QString::number(video_max);
709 filePropertyMap["default_audio"] = QString::number(default_audio);
710 filePropertyMap["audio_max"] = QString::number(audio_max);
712 snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video);
713 if (producer->get(property)) {
714 filePropertyMap["videocodec"] = producer->get(property);
716 snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video);
717 if (producer->get(property))
718 filePropertyMap["videocodec"] = producer->get(property);
721 query = QString("meta.media.%1.codec.pix_fmt").arg(default_video);
722 filePropertyMap["pix_fmt"] = producer->get(query.toUtf8().constData());
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::Profile profile((mlt_profile) 0);
968 Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
969 m_mltProducer->optimise();
970 xmlConsumer.set("terminate_on_pause", 1);
971 Mlt::Producer prod(m_mltProducer->get_producer());
972 bool split = m_isSplitView;
973 if (split) slotSplitView(false);
974 xmlConsumer.connect(prod);
976 while (!xmlConsumer.is_stopped()) {}
977 playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist"));
978 if (split) slotSplitView(true);
982 bool Render::saveSceneList(QString path, QDomElement kdenliveData)
986 doc.setContent(sceneList(), false);
987 if (!kdenliveData.isNull()) {
988 // add Kdenlive specific tags
989 QDomNode mlt = doc.elementsByTagName("mlt").at(0);
990 mlt.appendChild(doc.importNode(kdenliveData, true));
992 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
993 kWarning() << "////// ERROR writing to file: " << path;
996 file.write(doc.toString().toUtf8());
997 if (file.error() != QFile::NoError) {
1005 void Render::saveZone(KUrl url, QString desc, QPoint zone)
1007 kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name;
1008 Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
1009 m_mltProducer->optimise();
1010 xmlConsumer.set("terminate_on_pause", 1);
1011 if (m_name == "clip") {
1012 Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
1014 list.insert_at(0, prod, 0);
1016 list.set("title", desc.toUtf8().constData());
1017 xmlConsumer.connect(list);
1020 //TODO: not working yet, save zone from timeline
1021 Mlt::Producer *p1 = new Mlt::Producer(m_mltProducer->get_producer());
1022 /* Mlt::Service service(p1->parent().get_service());
1023 if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM";*/
1025 //Mlt::Producer *prod = p1->cut(zone.x(), zone.y());
1026 //prod->set("title", desc.toUtf8().constData());
1027 xmlConsumer.connect(*p1); //list);
1030 xmlConsumer.start();
1033 double Render::fps() const
1038 int Render::connectPlaylist()
1040 if (!m_mltConsumer) return -1;
1041 //m_mltConsumer->set("refresh", "0");
1042 m_mltConsumer->connect(*m_mltProducer);
1043 m_mltProducer->set_speed(0);
1044 if (m_mltConsumer->start() == -1) {
1045 // ARGH CONSUMER BROKEN!!!!
1046 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."));
1047 delete m_mltConsumer;
1048 m_mltConsumer = NULL;
1051 emit durationChanged(m_mltProducer->get_playtime());
1056 void Render::refreshDisplay()
1059 if (!m_mltProducer) return;
1060 //m_mltConsumer->set("refresh", 0);
1062 //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1063 /*if (KdenliveSettings::osdtimecode()) {
1064 mlt_properties_set_int( properties, "meta.attr.timecode", 1);
1065 mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#");
1066 m_osdInfo->set("dynamic", "1");
1067 m_mltProducer->attach(*m_osdInfo);
1070 m_mltProducer->detach(*m_osdInfo);
1071 m_osdInfo->set("dynamic", "0");
1076 void Render::setVolume(double /*volume*/)
1078 if (!m_mltConsumer || !m_mltProducer) return;
1080 m_mltConsumer->set("refresh", 0);
1081 // Attach filter for on screen display of timecode
1082 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1083 mlt_properties_set_double( properties, "meta.volume", volume );
1084 mlt_properties_set_int( properties, "meta.attr.osdvolume", 1);
1085 mlt_properties_set( properties, "meta.attr.osdvolume.markup", i18n("Volume: ") + QString::number(volume * 100));
1087 if (!KdenliveSettings::osdtimecode()) {
1088 m_mltProducer->detach(*m_osdInfo);
1089 mlt_properties_set_int( properties, "meta.attr.timecode", 0);
1090 if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
1093 //m_osdTimer->setSingleShot(2500);
1096 void Render::slotOsdTimeout()
1098 mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer());
1099 mlt_properties_set_int(properties, "meta.attr.osdvolume", 0);
1100 mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL);
1101 //if (!KdenliveSettings::osdtimecode()) m_mltProducer->detach(*m_osdInfo);
1105 void Render::start()
1107 kDebug() << "----- STARTING MONITOR: " << m_name;
1108 if (m_winid == -1) {
1109 kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART";
1112 if (m_mltConsumer && m_mltConsumer->is_stopped()) {
1113 kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED";
1114 if (m_mltConsumer->start() == -1) {
1115 //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."));
1116 kDebug(QtWarningMsg) << "/ / / / CANNOT START MONITOR";
1118 kDebug() << "----- MONITOR: " << m_name << " REFRESH";
1119 m_isBlocked = false;
1123 m_isBlocked = false;
1128 if (m_mltProducer == NULL) return;
1129 if (m_mltConsumer && !m_mltConsumer->is_stopped()) {
1130 kDebug() << "///////////// RENDER STOPPED: " << m_name;
1132 //m_mltConsumer->set("refresh", 0);
1133 m_mltConsumer->stop();
1134 // delete m_mltConsumer;
1135 // m_mltConsumer = NULL;
1137 kDebug() << "///////////// RENDER STOP2-------";
1140 if (m_mltProducer) {
1141 if (m_isZoneMode) resetZoneMode();
1142 m_mltProducer->set_speed(0.0);
1143 //m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1144 //kDebug() << m_mltProducer->get_length();
1146 kDebug() << "///////////// RENDER STOP3-------";
1149 void Render::stop(const GenTime & startTime)
1152 kDebug() << "///////////// RENDER STOP-------2";
1153 if (m_mltProducer) {
1154 if (m_isZoneMode) resetZoneMode();
1155 m_mltProducer->set_speed(0.0);
1156 m_mltProducer->seek((int) startTime.frames(m_fps));
1158 m_mltConsumer->purge();
1161 void Render::pause()
1163 if (!m_mltProducer || !m_mltConsumer)
1165 if (m_mltProducer->get_speed() == 0.0) return;
1166 if (m_isZoneMode) resetZoneMode();
1168 m_mltConsumer->set("refresh", 0);
1169 m_mltProducer->set_speed(0.0);
1171 The 2 lines below create a flicker loop
1172 emit rendererPosition(m_framePosition);
1173 m_mltProducer->seek(m_framePosition);*/
1174 m_mltConsumer->purge();
1177 void Render::switchPlay()
1179 if (!m_mltProducer || !m_mltConsumer)
1181 if (m_isZoneMode) resetZoneMode();
1182 if (m_mltProducer->get_speed() == 0.0) {
1183 m_isBlocked = false;
1184 if (m_name == "clip" && m_framePosition == (int) m_mltProducer->get_out()) m_mltProducer->seek(0);
1185 m_mltProducer->set_speed(1.0);
1186 m_mltConsumer->set("refresh", 1);
1189 m_mltConsumer->set("refresh", 0);
1190 m_mltProducer->set_speed(0.0);
1191 //emit rendererPosition(m_framePosition);
1192 m_mltProducer->seek(m_framePosition);
1193 m_mltConsumer->purge();
1194 //kDebug()<<" ********* RENDER PAUSE: "<<m_mltProducer->get_speed();
1195 //m_mltConsumer->set("refresh", 0);
1196 /*mlt_position position = mlt_producer_position( m_mltProducer->get_producer() );
1197 m_mltProducer->set_speed(0);
1198 m_mltProducer->seek( position );
1199 //m_mltProducer->seek((int) m_framePosition);
1200 m_isBlocked = false;*/
1202 /*if (speed == 0.0) {
1203 m_mltProducer->seek((int) m_framePosition + 1);
1204 m_mltConsumer->purge();
1209 void Render::play(double speed)
1213 // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1);
1214 m_isBlocked = false;
1215 m_mltProducer->set_speed(speed);
1216 /*if (speed == 0.0) {
1217 m_mltProducer->seek((int) m_framePosition + 1);
1218 m_mltConsumer->purge();
1223 void Render::play(const GenTime & startTime)
1225 if (!m_mltProducer || !m_mltConsumer)
1227 m_isBlocked = false;
1228 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1229 m_mltProducer->set_speed(1.0);
1230 m_mltConsumer->set("refresh", 1);
1233 void Render::loopZone(const GenTime & startTime, const GenTime & stopTime)
1235 if (!m_mltProducer || !m_mltConsumer)
1237 //m_mltProducer->set("eof", "loop");
1238 m_isLoopMode = true;
1239 m_loopStart = startTime;
1240 playZone(startTime, stopTime);
1243 void Render::playZone(const GenTime & startTime, const GenTime & stopTime)
1245 if (!m_mltProducer || !m_mltConsumer)
1247 m_isBlocked = false;
1248 if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1;
1249 m_mltProducer->set("out", (int)(stopTime.frames(m_fps)));
1250 m_mltProducer->seek((int)(startTime.frames(m_fps)));
1251 m_mltProducer->set_speed(1.0);
1252 m_mltConsumer->set("refresh", 1);
1253 m_isZoneMode = true;
1256 void Render::resetZoneMode()
1258 if (!m_isZoneMode && !m_isLoopMode) return;
1259 m_mltProducer->set("out", m_originalOut);
1260 //m_mltProducer->set("eof", "pause");
1261 m_isZoneMode = false;
1262 m_isLoopMode = false;
1265 void Render::seekToFrame(int pos)
1267 //kDebug()<<" ********* RENDER SEEK TO POS";
1270 m_isBlocked = false;
1272 m_mltProducer->seek(pos);
1276 void Render::seekToFrameDiff(int diff)
1278 //kDebug()<<" ********* RENDER SEEK TO POS";
1281 m_isBlocked = false;
1283 m_mltProducer->seek(m_mltProducer->position() + diff);
1287 void Render::doRefresh()
1289 // Use a Timer so that we don't refresh too much
1290 if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1);
1293 void Render::refresh()
1295 if (!m_mltProducer || m_isBlocked)
1297 if (m_mltConsumer) {
1298 m_mltConsumer->set("refresh", 1);
1302 void Render::setDropFrames(bool show)
1304 if (m_mltConsumer) {
1306 if (show == false) dropFrames = 0;
1307 m_mltConsumer->stop();
1309 m_mltConsumer->set("real_time", dropFrames);
1311 m_mltConsumer->set("play.real_time", dropFrames);
1313 if (m_mltConsumer->start() == -1) {
1314 kDebug(QtWarningMsg) << "ERROR, Cannot start monitor";
1320 double Render::playSpeed()
1322 if (m_mltProducer) return m_mltProducer->get_speed();
1326 GenTime Render::seekPosition() const
1328 if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps);
1329 else return GenTime();
1332 int Render::seekFramePosition() const
1334 if (m_mltProducer) return (int) m_mltProducer->position();
1338 const QString & Render::rendererName() const
1343 void Render::emitFrameUpdated(Mlt::Frame& frame)
1345 mlt_image_format format = mlt_image_rgb24a;
1348 const uchar* image = frame.get_image(format, width, height);
1349 QImage qimage(width, height, QImage::Format_ARGB32);
1350 memcpy(qimage.bits(), image, width * height * 4);
1351 emit frameUpdated(qimage.rgbSwapped());
1354 void Render::emitFrameNumber(double position)
1356 m_framePosition = position;
1357 emit rendererPosition((int) position);
1360 void Render::emitConsumerStopped()
1362 // This is used to know when the playing stopped
1363 if (m_mltProducer) {
1364 double pos = m_mltProducer->position();
1365 if (m_isLoopMode) play(m_loopStart);
1366 else if (m_isZoneMode) resetZoneMode();
1367 emit rendererStopped((int) pos);
1371 void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/)
1373 KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive"));
1376 void Render::exportCurrentFrame(KUrl url, bool /*notify*/)
1378 if (!m_mltProducer) {
1379 KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame."));
1383 //int height = 1080;//KdenliveSettings::defaultheight();
1384 //int width = 1940; //KdenliveSettings::displaywidth();
1386 QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height);
1388 QPixmap pix(width, height);
1389 Mlt::Filter m_convert(*m_mltProfile, "avcolour_space");
1390 m_convert.set("forced", mlt_image_rgb24a);
1391 m_mltProducer->attach(m_convert);
1392 Mlt::Frame * frame = m_mltProducer->get_frame();
1393 m_mltProducer->detach(m_convert);
1395 pix = frameThumbnail(frame, width, height);
1398 pix.save(url.path(), "PNG");
1399 //if (notify) QApplication::postEvent(qApp->activeWindow(), new UrlEvent(url, 10003));
1403 void Render::showFrame(Mlt::Frame& frame)
1405 m_framePosition = qMax(frame.get_int("_position"), 0);
1406 emit rendererPosition((int) m_framePosition);
1407 mlt_image_format format = mlt_image_rgb24a;
1410 const uchar* image = frame.get_image(format, width, height);
1411 QImage qimage(width, height, QImage::Format_ARGB32_Premultiplied);
1412 memcpy(qimage.scanLine(0), image, width * height * 4);
1413 emit showImageSignal(qimage);
1415 if (sendFrameForAnalysis && frame.get_frame()->convert_image) {
1416 emit frameUpdated(qimage.rgbSwapped());
1420 void Render::showAudio(Mlt::Frame& frame)
1422 if (!frame.is_valid() || frame.get_int("test_audio") != 0) return;
1423 mlt_audio_format audio_format = mlt_audio_s16;
1425 int num_channels = 0;
1427 int16_t* data = (int16_t*)frame.get_audio(audio_format, freq, num_channels, samples);
1430 int num_samples = samples > 200 ? 200 : samples;
1431 QByteArray channels;
1432 for (int i = 0; i < num_channels; i++) {
1434 for (int s = 0; s < num_samples; s ++) {
1435 val += abs(data[i+s*num_channels] / 128);
1437 channels.append(val / num_samples);
1442 emit showAudioSignal(channels);
1444 emit showAudioSignal(QByteArray());
1448 * MLT playlist direct manipulation.
1451 void Render::mltCheckLength(Mlt::Tractor *tractor)
1453 //kDebug()<<"checking track length: "<<track<<"..........";
1455 int trackNb = tractor->count();
1459 Mlt::Producer trackProducer(tractor->track(0));
1460 duration = trackProducer.get_playtime() - 1;
1461 m_mltProducer->set("out", duration);
1462 emit durationChanged(duration);
1465 while (trackNb > 1) {
1466 Mlt::Producer trackProducer(tractor->track(trackNb - 1));
1467 trackDuration = trackProducer.get_playtime() - 1;
1468 // kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration;
1469 if (trackDuration > duration) duration = trackDuration;
1473 Mlt::Producer blackTrackProducer(tractor->track(0));
1475 if (blackTrackProducer.get_playtime() - 1 != duration) {
1476 Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service());
1477 Mlt::Producer *blackclip = blackTrackPlaylist.get_clip(0);
1478 if (blackclip && blackclip->is_blank()) {
1483 if (blackclip == NULL || blackTrackPlaylist.count() != 1) {
1484 blackTrackPlaylist.clear();
1485 m_blackClip->set("length", duration + 1);
1486 m_blackClip->set("out", duration);
1487 blackclip = m_blackClip->cut(0, duration);
1488 blackTrackPlaylist.insert_at(0, blackclip, 1);
1490 if (duration > blackclip->parent().get_length()) {
1491 blackclip->parent().set("length", duration + 1);
1492 blackclip->parent().set("out", duration);
1493 blackclip->set("length", duration + 1);
1495 blackTrackPlaylist.resize_clip(0, 0, duration);
1499 m_mltProducer->set("out", duration);
1500 emit durationChanged(duration);
1504 Mlt::Producer *Render::checkSlowMotionProducer(Mlt::Producer *prod, QDomElement element)
1506 if (element.attribute("speed", "1.0").toDouble() == 1.0 && element.attribute("strobe", "1").toInt() == 1) return prod;
1508 // We want a slowmotion producer
1509 double speed = element.attribute("speed", "1.0").toDouble();
1510 int strobe = element.attribute("strobe", "1").toInt();
1511 QString url = QString::fromUtf8(prod->get("resource"));
1512 url.append('?' + QString::number(speed));
1513 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
1514 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
1515 if (!slowprod || slowprod->get_producer() == NULL) {
1516 slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", url.toUtf8().constData());
1517 if (strobe > 1) slowprod->set("strobe", strobe);
1518 QString id = prod->get("id");
1519 if (id.contains('_')) id = id.section('_', 0, 0);
1520 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
1521 if (strobe > 1) producerid.append(':' + QString::number(strobe));
1522 slowprod->set("id", producerid.toUtf8().constData());
1523 m_slowmotionProducers.insert(url, slowprod);
1528 int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite, bool push)
1530 if (m_mltProducer == NULL) {
1531 kDebug() << "PLAYLIST NOT INITIALISED //////";
1535 kDebug() << "Cannot insert clip without producer //////";
1538 Mlt::Producer parentProd(m_mltProducer->parent());
1539 if (parentProd.get_producer() == NULL) {
1540 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1544 Mlt::Service service(parentProd.get_service());
1545 if (service.type() != tractor_type) {
1546 kWarning() << "// TRACTOR PROBLEM";
1549 Mlt::Tractor tractor(service);
1550 if (info.track > tractor.count() - 1) {
1551 kDebug() << "ERROR TRYING TO INSERT CLIP ON TRACK " << info.track << ", at POS: " << info.startPos.frames(25);
1554 mlt_service_lock(service.get_service());
1555 Mlt::Producer trackProducer(tractor.track(info.track));
1556 int trackDuration = trackProducer.get_playtime() - 1;
1557 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1558 //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
1559 prod = checkSlowMotionProducer(prod, element);
1560 if (prod == NULL || !prod->is_valid()) {
1561 mlt_service_unlock(service.get_service());
1565 int cutPos = (int) info.cropStart.frames(m_fps);
1566 if (cutPos < 0) cutPos = 0;
1567 int insertPos = (int) info.startPos.frames(m_fps);
1568 int cutDuration = (int)(info.endPos - info.startPos).frames(m_fps) - 1;
1569 Mlt::Producer *clip = prod->cut(cutPos, cutDuration + cutPos);
1570 if (overwrite && (insertPos < trackDuration)) {
1571 // Replace zone with blanks
1572 //trackPlaylist.split_at(insertPos, true);
1573 trackPlaylist.remove_region(insertPos, cutDuration + 1);
1574 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1575 trackPlaylist.insert_blank(clipIndex, cutDuration);
1577 trackPlaylist.split_at(insertPos, true);
1578 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1579 trackPlaylist.insert_blank(clipIndex, cutDuration);
1581 int newIndex = trackPlaylist.insert_at(insertPos, clip, 1);
1583 /*if (QString(prod->get("transparency")).toInt() == 1)
1584 mltAddClipTransparency(info, info.track - 1, QString(prod->get("id")).toInt());*/
1586 if (info.track != 0 && (newIndex + 1 == trackPlaylist.count())) mltCheckLength(&tractor);
1587 mlt_service_unlock(service.get_service());
1588 /*tractor.multitrack()->refresh();
1589 tractor.refresh();*/
1594 void Render::mltCutClip(int track, GenTime position)
1598 Mlt::Service service(m_mltProducer->parent().get_service());
1599 if (service.type() != tractor_type) {
1600 kWarning() << "// TRACTOR PROBLEM";
1604 Mlt::Tractor tractor(service);
1605 Mlt::Producer trackProducer(tractor.track(track));
1606 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1609 /* // Display playlist info
1610 kDebug()<<"//////////// BEFORE";
1611 for (int i = 0; i < trackPlaylist.count(); i++) {
1612 int blankStart = trackPlaylist.clip_start(i);
1613 int blankDuration = trackPlaylist.clip_length(i) - 1;
1615 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1616 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1619 int cutPos = (int) position.frames(m_fps);
1621 int clipIndex = trackPlaylist.get_clip_index_at(cutPos);
1622 if (trackPlaylist.is_blank(clipIndex)) {
1623 kDebug() << "// WARNING, TRYING TO CUT A BLANK";
1624 m_isBlocked = false;
1627 mlt_service_lock(service.get_service());
1628 int clipStart = trackPlaylist.clip_start(clipIndex);
1629 trackPlaylist.split(clipIndex, cutPos - clipStart - 1);
1630 mlt_service_unlock(service.get_service());
1632 // duplicate effects
1633 Mlt::Producer *original = trackPlaylist.get_clip_at(clipStart);
1634 Mlt::Producer *clip = trackPlaylist.get_clip_at(cutPos);
1636 if (original == NULL || clip == NULL) {
1637 kDebug() << "// ERROR GRABBING CLIP AFTER SPLIT";
1639 Mlt::Service clipService(original->get_service());
1640 Mlt::Service dupService(clip->get_service());
1644 Mlt::Filter *filter = clipService.filter(ct);
1646 // Only duplicate Kdenlive filters, and skip the fade in effects
1647 if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) {
1648 // looks like there is no easy way to duplicate a filter,
1649 // so we will create a new one and duplicate its properties
1650 Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service"));
1651 if (dup && dup->is_valid()) {
1652 Mlt::Properties entries(filter->get_properties());
1653 for (int i = 0; i < entries.count(); i++) {
1654 dup->set(entries.get_name(i), entries.get(i));
1656 dupService.attach(*dup);
1660 filter = clipService.filter(ct);
1663 /* // Display playlist info
1664 kDebug()<<"//////////// AFTER";
1665 for (int i = 0; i < trackPlaylist.count(); i++) {
1666 int blankStart = trackPlaylist.clip_start(i);
1667 int blankDuration = trackPlaylist.clip_length(i) - 1;
1669 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1670 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1673 m_isBlocked = false;
1676 bool Render::mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod)
1680 kDebug() << "Cannot update clip with null producer //////";
1683 Mlt::Service service(m_mltProducer->parent().get_service());
1684 if (service.type() != tractor_type) {
1685 kWarning() << "// TRACTOR PROBLEM";
1688 Mlt::Tractor tractor(service);
1689 Mlt::Producer trackProducer(tractor.track(info.track));
1690 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1691 int startPos = info.startPos.frames(m_fps);
1692 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
1693 if (trackPlaylist.is_blank(clipIndex)) {
1694 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << startPos;
1697 mlt_service_lock(service.get_service());
1698 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
1700 QList <Mlt::Filter *> filtersList;
1701 Mlt::Service sourceService(clip->get_service());
1703 Mlt::Filter *filter = sourceService.filter(ct);
1705 if (filter->get_int("kdenlive_ix") != 0) {
1706 filtersList.append(filter);
1709 filter = sourceService.filter(ct);
1712 trackPlaylist.replace_with_blank(clipIndex);
1714 //if (!mltRemoveClip(info.track, info.startPos)) return false;
1715 prod = checkSlowMotionProducer(prod, element);
1716 if (prod == NULL || !prod->is_valid()) {
1717 mlt_service_unlock(service.get_service());
1720 Mlt::Producer *clip2 = prod->cut(info.cropStart.frames(m_fps), (info.cropDuration + info.cropStart).frames(m_fps));
1721 trackPlaylist.insert_at(info.startPos.frames(m_fps), clip2, 1);
1725 //if (mltInsertClip(info, element, prod) == -1) return false;
1726 if (!filtersList.isEmpty()) {
1727 clipIndex = trackPlaylist.get_clip_index_at(startPos);
1728 Mlt::Producer *destclip = trackPlaylist.get_clip(clipIndex);
1729 Mlt::Service destService(destclip->get_service());
1731 for (int i = 0; i < filtersList.count(); i++)
1732 destService.attach(*(filtersList.at(i)));
1734 mlt_service_unlock(service.get_service());
1739 bool Render::mltRemoveClip(int track, GenTime position)
1741 Mlt::Service service(m_mltProducer->parent().get_service());
1742 if (service.type() != tractor_type) {
1743 kWarning() << "// TRACTOR PROBLEM";
1747 Mlt::Tractor tractor(service);
1748 mlt_service_lock(service.get_service());
1749 Mlt::Producer trackProducer(tractor.track(track));
1750 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1751 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
1753 // Display playlist info
1754 //kDebug() << "//// BEFORE -( " << position.frames(m_fps) << " )-------------------------------";
1755 /*for (int i = 0; i < trackPlaylist.count(); i++) {
1756 int blankStart = trackPlaylist.clip_start(i);
1757 int blankDuration = trackPlaylist.clip_length(i) - 1;
1759 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1760 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1762 if (trackPlaylist.is_blank(clipIndex)) {
1763 kDebug() << "// WARNING, TRYING TO REMOVE A BLANK: " << position.frames(25);
1764 mlt_service_unlock(service.get_service());
1767 //kDebug()<<"//// Deleting at: "<< (int) position.frames(m_fps) <<" --------------------------------------";
1769 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
1770 if (clip) delete clip;
1771 trackPlaylist.consolidate_blanks(0);
1772 /*if (QString(clip.parent().get("transparency")).toInt() == 1)
1773 mltDeleteTransparency((int) position.frames(m_fps), track, QString(clip.parent().get("id")).toInt());*/
1775 /* // Display playlist info
1776 kDebug()<<"//// AFTER";
1777 for (int i = 0; i < trackPlaylist.count(); i++) {
1778 int blankStart = trackPlaylist.clip_start(i);
1779 int blankDuration = trackPlaylist.clip_length(i) - 1;
1781 if (trackPlaylist.is_blank(i)) blk = "(blank)";
1782 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
1784 mlt_service_unlock(service.get_service());
1785 if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(&tractor);
1786 m_isBlocked = false;
1790 int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart)
1792 if (!m_mltProducer) {
1793 kDebug() << "PLAYLIST NOT INITIALISED //////";
1796 Mlt::Producer parentProd(m_mltProducer->parent());
1797 if (parentProd.get_producer() == NULL) {
1798 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1802 Mlt::Service service(parentProd.get_service());
1803 Mlt::Tractor tractor(service);
1804 int insertPos = pos.frames(m_fps);
1806 Mlt::Producer trackProducer(tractor.track(track));
1807 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1808 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1809 if (clipIndex == trackPlaylist.count()) {
1810 // We are after the end of the playlist
1813 if (!trackPlaylist.is_blank(clipIndex)) return 0;
1814 if (fromBlankStart) return trackPlaylist.clip_length(clipIndex);
1815 return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos;
1818 int Render::mltTrackDuration(int track)
1820 if (!m_mltProducer) {
1821 kDebug() << "PLAYLIST NOT INITIALISED //////";
1824 Mlt::Producer parentProd(m_mltProducer->parent());
1825 if (parentProd.get_producer() == NULL) {
1826 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1830 Mlt::Service service(parentProd.get_service());
1831 Mlt::Tractor tractor(service);
1833 Mlt::Producer trackProducer(tractor.track(track));
1834 return trackProducer.get_playtime() - 1;
1837 void Render::mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset)
1839 if (!m_mltProducer) {
1840 kDebug() << "PLAYLIST NOT INITIALISED //////";
1843 Mlt::Producer parentProd(m_mltProducer->parent());
1844 if (parentProd.get_producer() == NULL) {
1845 kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////";
1848 //kDebug()<<"// CLP STRT LST: "<<trackClipStartList;
1849 //kDebug()<<"// TRA STRT LST: "<<trackTransitionStartList;
1851 Mlt::Service service(parentProd.get_service());
1852 Mlt::Tractor tractor(service);
1853 mlt_service_lock(service.get_service());
1854 int diff = duration.frames(m_fps);
1855 int offset = timeOffset.frames(m_fps);
1859 // insert space in one track only
1860 Mlt::Producer trackProducer(tractor.track(track));
1861 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1862 insertPos = trackClipStartList.value(track);
1863 if (insertPos != -1) {
1864 insertPos += offset;
1865 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1867 trackPlaylist.insert_blank(clipIndex, diff - 1);
1869 if (!trackPlaylist.is_blank(clipIndex)) clipIndex --;
1870 if (!trackPlaylist.is_blank(clipIndex)) {
1871 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1873 int position = trackPlaylist.clip_start(clipIndex);
1874 int blankDuration = trackPlaylist.clip_length(clipIndex);
1876 if (blankDuration - diff == 0) {
1877 trackPlaylist.remove(clipIndex);
1878 } else trackPlaylist.remove_region(position, diff);
1880 trackPlaylist.consolidate_blanks(0);
1882 // now move transitions
1883 mlt_service serv = m_mltProducer->parent().get_service();
1884 mlt_service nextservice = mlt_service_get_producer(serv);
1885 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1886 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1887 QString resource = mlt_properties_get(properties, "mlt_service");
1889 while (mlt_type == "transition") {
1890 mlt_transition tr = (mlt_transition) nextservice;
1891 int currentTrack = mlt_transition_get_b_track(tr);
1892 int currentIn = (int) mlt_transition_get_in(tr);
1893 int currentOut = (int) mlt_transition_get_out(tr);
1894 insertPos = trackTransitionStartList.value(track);
1895 if (insertPos != -1) {
1896 insertPos += offset;
1897 if (track == currentTrack && currentOut > insertPos && resource != "mix") {
1898 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1901 nextservice = mlt_service_producer(nextservice);
1902 if (nextservice == NULL) break;
1903 properties = MLT_SERVICE_PROPERTIES(nextservice);
1904 mlt_type = mlt_properties_get(properties, "mlt_type");
1905 resource = mlt_properties_get(properties, "mlt_service");
1908 for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) {
1909 Mlt::Producer trackProducer(tractor.track(trackNb));
1910 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
1912 //int clipNb = trackPlaylist.count();
1913 insertPos = trackClipStartList.value(trackNb);
1914 if (insertPos != -1) {
1915 insertPos += offset;
1917 /* kDebug()<<"-------------\nTRACK "<<trackNb<<" HAS "<<clipNb<<" CLPIS";
1918 kDebug() << "INSERT SPACE AT: "<<insertPos<<", DIFF: "<<diff<<", TK: "<<trackNb;
1919 for (int i = 0; i < clipNb; i++) {
1920 kDebug()<<"CLIP "<<i<<", START: "<<trackPlaylist.clip_start(i)<<", END: "<<trackPlaylist.clip_start(i) + trackPlaylist.clip_length(i);
1921 if (trackPlaylist.is_blank(i)) kDebug()<<"++ BLANK ++ ";
1922 kDebug()<<"-------------";
1924 kDebug()<<"END-------------";*/
1927 int clipIndex = trackPlaylist.get_clip_index_at(insertPos);
1929 trackPlaylist.insert_blank(clipIndex, diff - 1);
1931 if (!trackPlaylist.is_blank(clipIndex)) {
1934 if (!trackPlaylist.is_blank(clipIndex)) {
1935 kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos;
1937 int position = trackPlaylist.clip_start(clipIndex);
1938 int blankDuration = trackPlaylist.clip_length(clipIndex);
1939 if (diff + blankDuration == 0) {
1940 trackPlaylist.remove(clipIndex);
1941 } else trackPlaylist.remove_region(position, - diff);
1943 trackPlaylist.consolidate_blanks(0);
1946 // now move transitions
1947 mlt_service serv = m_mltProducer->parent().get_service();
1948 mlt_service nextservice = mlt_service_get_producer(serv);
1949 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
1950 QString mlt_type = mlt_properties_get(properties, "mlt_type");
1951 QString resource = mlt_properties_get(properties, "mlt_service");
1953 while (mlt_type == "transition") {
1954 mlt_transition tr = (mlt_transition) nextservice;
1955 int currentIn = (int) mlt_transition_get_in(tr);
1956 int currentOut = (int) mlt_transition_get_out(tr);
1957 int currentTrack = mlt_transition_get_b_track(tr);
1958 insertPos = trackTransitionStartList.value(currentTrack);
1959 if (insertPos != -1) {
1960 insertPos += offset;
1961 if (currentOut > insertPos && resource != "mix") {
1962 mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff);
1965 nextservice = mlt_service_producer(nextservice);
1966 if (nextservice == NULL) break;
1967 properties = MLT_SERVICE_PROPERTIES(nextservice);
1968 mlt_type = mlt_properties_get(properties, "mlt_type");
1969 resource = mlt_properties_get(properties, "mlt_service");
1972 mlt_service_unlock(service.get_service());
1973 mltCheckLength(&tractor);
1974 m_mltConsumer->set("refresh", 1);
1978 void Render::mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest)
1980 if (source == dest) return;
1981 Mlt::Service sourceService(source->get_service());
1982 Mlt::Service destService(dest->get_service());
1984 // move all effects to the correct producer
1986 Mlt::Filter *filter = sourceService.filter(ct);
1988 if (filter->get_int("kdenlive_ix") != 0) {
1989 sourceService.detach(*filter);
1990 destService.attach(*filter);
1992 filter = sourceService.filter(ct);
1996 int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double /*oldspeed*/, int strobe, Mlt::Producer *prod)
2000 Mlt::Service service(m_mltProducer->parent().get_service());
2001 if (service.type() != tractor_type) {
2002 kWarning() << "// TRACTOR PROBLEM";
2005 //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1;
2006 Mlt::Tractor tractor(service);
2007 Mlt::Producer trackProducer(tractor.track(info.track));
2008 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2009 int startPos = info.startPos.frames(m_fps);
2010 int clipIndex = trackPlaylist.get_clip_index_at(startPos);
2011 int clipLength = trackPlaylist.clip_length(clipIndex);
2013 Mlt::Producer *original = trackPlaylist.get_clip(clipIndex);
2014 if (original == NULL) {
2017 if (!original->is_valid() || original->is_blank()) {
2022 Mlt::Producer clipparent = original->parent();
2023 if (!clipparent.is_valid() || clipparent.is_blank()) {
2029 QString serv = clipparent.get("mlt_service");
2030 QString id = clipparent.get("id");
2031 if (speed <= 0 && speed > -1) speed = 1.0;
2032 //kDebug() << "CLIP SERVICE: " << serv;
2033 if (serv == "avformat" && (speed != 1.0 || strobe > 1)) {
2034 mlt_service_lock(service.get_service());
2035 QString url = QString::fromUtf8(clipparent.get("resource"));
2036 url.append('?' + QString::number(speed));
2037 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2038 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2039 if (!slowprod || slowprod->get_producer() == NULL) {
2040 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2041 if (strobe > 1) slowprod->set("strobe", strobe);
2042 QString producerid = "slowmotion:" + id + ':' + QString::number(speed);
2043 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2044 slowprod->set("id", producerid.toUtf8().constData());
2045 // copy producer props
2046 double ar = original->parent().get_double("force_aspect_ratio");
2047 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2048 double fps = original->parent().get_double("force_fps");
2049 if (fps != 0.0) slowprod->set("force_fps", fps);
2050 int threads = original->parent().get_int("threads");
2051 if (threads != 0) slowprod->set("threads", threads);
2052 if (original->parent().get("force_progressive"))
2053 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2054 int ix = original->parent().get_int("video_index");
2055 if (ix != 0) slowprod->set("video_index", ix);
2056 m_slowmotionProducers.insert(url, slowprod);
2058 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2059 trackPlaylist.consolidate_blanks(0);
2061 // Check that the blank space is long enough for our new duration
2062 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2063 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2065 if (clipIndex + 1 < trackPlaylist.count() && (startPos + clipLength / speed > blankEnd)) {
2066 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2067 cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1));
2068 } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart.frames(m_fps) + clipLength) / speed - 1));
2070 // move all effects to the correct producer
2071 mltPasteEffects(clip, cut);
2072 trackPlaylist.insert_at(startPos, cut, 1);
2075 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2076 newLength = trackPlaylist.clip_length(clipIndex);
2077 mlt_service_unlock(service.get_service());
2078 } else if (speed == 1.0 && strobe < 2) {
2079 mlt_service_lock(service.get_service());
2081 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2082 trackPlaylist.consolidate_blanks(0);
2084 // Check that the blank space is long enough for our new duration
2085 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2086 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2089 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps));
2090 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + speedIndependantInfo.cropDuration).frames(m_fps) > blankEnd) {
2091 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2092 cut = prod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2093 } else cut = prod->cut(originalStart, (int)(originalStart + speedIndependantInfo.cropDuration.frames(m_fps)) - 1);
2095 // move all effects to the correct producer
2096 mltPasteEffects(clip, cut);
2098 trackPlaylist.insert_at(startPos, cut, 1);
2101 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2102 newLength = trackPlaylist.clip_length(clipIndex);
2103 mlt_service_unlock(service.get_service());
2105 } else if (serv == "framebuffer") {
2106 mlt_service_lock(service.get_service());
2107 QString url = QString::fromUtf8(clipparent.get("resource"));
2108 url = url.section('?', 0, 0);
2109 url.append('?' + QString::number(speed));
2110 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
2111 Mlt::Producer *slowprod = m_slowmotionProducers.value(url);
2112 if (!slowprod || slowprod->get_producer() == NULL) {
2113 slowprod = new Mlt::Producer(*m_mltProfile, 0, ("framebuffer:" + url).toUtf8().constData());
2114 slowprod->set("strobe", strobe);
2115 QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed);
2116 if (strobe > 1) producerid.append(':' + QString::number(strobe));
2117 slowprod->set("id", producerid.toUtf8().constData());
2118 // copy producer props
2119 double ar = original->parent().get_double("force_aspect_ratio");
2120 if (ar != 0.0) slowprod->set("force_aspect_ratio", ar);
2121 double fps = original->parent().get_double("force_fps");
2122 if (fps != 0.0) slowprod->set("force_fps", fps);
2123 if (original->parent().get("force_progressive"))
2124 slowprod->set("force_progressive", original->parent().get_int("force_progressive"));
2125 int threads = original->parent().get_int("threads");
2126 if (threads != 0) slowprod->set("threads", threads);
2127 int ix = original->parent().get_int("video_index");
2128 if (ix != 0) slowprod->set("video_index", ix);
2129 m_slowmotionProducers.insert(url, slowprod);
2131 Mlt::Producer *clip = trackPlaylist.replace_with_blank(clipIndex);
2132 trackPlaylist.consolidate_blanks(0);
2134 GenTime duration = speedIndependantInfo.cropDuration / speed;
2135 int originalStart = (int)(speedIndependantInfo.cropStart.frames(m_fps) / speed);
2137 // Check that the blank space is long enough for our new duration
2138 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2139 int blankEnd = trackPlaylist.clip_start(clipIndex) + trackPlaylist.clip_length(clipIndex);
2142 if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + duration).frames(m_fps) > blankEnd) {
2143 GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos;
2144 cut = slowprod->cut(originalStart, (int)(originalStart + maxLength.frames(m_fps) - 1));
2145 } else cut = slowprod->cut(originalStart, (int)(originalStart + duration.frames(m_fps)) - 1);
2147 // move all effects to the correct producer
2148 mltPasteEffects(clip, cut);
2150 trackPlaylist.insert_at(startPos, cut, 1);
2153 clipIndex = trackPlaylist.get_clip_index_at(startPos);
2154 newLength = trackPlaylist.clip_length(clipIndex);
2156 mlt_service_unlock(service.get_service());
2159 if (clipIndex + 1 == trackPlaylist.count()) mltCheckLength(&tractor);
2160 m_isBlocked = false;
2164 bool Render::mltRemoveTrackEffect(int track, QString index, bool updateIndex)
2166 Mlt::Service service(m_mltProducer->parent().get_service());
2167 bool success = false;
2168 Mlt::Tractor tractor(service);
2169 Mlt::Producer trackProducer(tractor.track(track));
2170 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2171 Mlt::Service clipService(trackPlaylist.get_service());
2174 mlt_service_lock(service.get_service());
2176 Mlt::Filter *filter = clipService.filter(ct);
2178 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {
2179 if (clipService.detach(*filter) == 0) success = true;
2180 } else if (updateIndex) {
2181 // Adjust the other effects index
2182 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2185 filter = clipService.filter(ct);
2187 m_isBlocked = false;
2188 mlt_service_unlock(service.get_service());
2193 bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh)
2195 if (position < GenTime()) {
2196 // Remove track effect
2197 return mltRemoveTrackEffect(track, index, updateIndex);
2199 Mlt::Service service(m_mltProducer->parent().get_service());
2200 bool success = false;
2201 Mlt::Tractor tractor(service);
2202 Mlt::Producer trackProducer(tractor.track(track));
2203 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2205 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2206 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2208 kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT";
2212 Mlt::Service clipService(clip->get_service());
2213 int duration = clip->get_playtime();
2215 // Check if clip is visible in monitor
2216 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2217 if (diff < 0 || diff > duration) doRefresh = false;
2221 // if (tag.startsWith("ladspa")) tag = "ladspa";
2223 mlt_service_lock(service.get_service());
2225 Mlt::Filter *filter = clipService.filter(ct);
2227 if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get_int("kdenlive_ix") == index.toInt()) {// && filter->get("kdenlive_id") == id) {
2228 if (clipService.detach(*filter) == 0) success = true;
2229 //kDebug()<<"Deleted filter id:"<<filter->get("kdenlive_id")<<", ix:"<<filter->get("kdenlive_ix")<<", SERVICE:"<<filter->get("mlt_service");
2230 } else if (updateIndex) {
2231 // Adjust the other effects index
2232 if (filter->get_int("kdenlive_ix") > index.toInt()) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2235 filter = clipService.filter(ct);
2237 m_isBlocked = false;
2238 mlt_service_unlock(service.get_service());
2239 if (doRefresh) refresh();
2243 bool Render::mltAddTrackEffect(int track, EffectsParameterList params)
2245 Mlt::Service service(m_mltProducer->parent().get_service());
2246 Mlt::Tractor tractor(service);
2247 Mlt::Producer trackProducer(tractor.track(track));
2248 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2249 Mlt::Service trackService(trackProducer.get_service()); //trackPlaylist
2250 return mltAddEffect(trackService, params, 15000, true);
2254 bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh)
2257 Mlt::Service service(m_mltProducer->parent().get_service());
2259 Mlt::Tractor tractor(service);
2260 Mlt::Producer trackProducer(tractor.track(track));
2261 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2263 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2264 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2269 Mlt::Service clipService(clip->get_service());
2270 int duration = clip->get_playtime();
2272 // Check if clip is visible in monitor
2273 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2274 if (diff < 0 || diff > duration) doRefresh = false;
2277 return mltAddEffect(clipService, params, duration, doRefresh);
2280 bool Render::mltAddEffect(Mlt::Service service, EffectsParameterList params, int duration, bool doRefresh)
2282 bool updateIndex = false;
2283 const int filter_ix = params.paramValue("kdenlive_ix").toInt();
2284 const QString region = params.paramValue("region");
2287 mlt_service_lock(service.get_service());
2289 Mlt::Filter *filter = service.filter(ct);
2291 if (filter->get_int("kdenlive_ix") == filter_ix) {
2292 // A filter at that position already existed, so we will increase all indexes later
2297 filter = service.filter(ct);
2300 if (params.paramValue("id") == "speed") {
2301 // special case, speed effect is not really inserted, we just update the other effects index (kdenlive_ix)
2303 filter = service.filter(ct);
2305 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2306 if (updateIndex) filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2309 filter = service.filter(ct);
2311 m_isBlocked = false;
2312 mlt_service_unlock(service.get_service());
2313 if (doRefresh) refresh();
2318 // temporarily remove all effects after insert point
2319 QList <Mlt::Filter *> filtersList;
2321 filter = service.filter(ct);
2323 if (filter->get_int("kdenlive_ix") >= filter_ix) {
2324 filtersList.append(filter);
2325 service.detach(*filter);
2327 filter = service.filter(ct);
2331 QString tag = params.paramValue("tag");
2332 kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region;
2333 if (tag.startsWith("ladspa")) tag = "ladspa";
2334 char *filterTag = qstrdup(tag.toUtf8().constData());
2335 char *filterId = qstrdup(params.paramValue("id").toUtf8().constData());
2336 QHash<QString, QString>::Iterator it;
2337 QString kfr = params.paramValue("keyframes");
2339 if (!kfr.isEmpty()) {
2340 QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts);
2341 kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes");
2342 char *starttag = qstrdup(params.paramValue("starttag", "start").toUtf8().constData());
2343 char *endtag = qstrdup(params.paramValue("endtag", "end").toUtf8().constData());
2344 kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag;
2345 //double max = params.paramValue("max").toDouble();
2346 double min = params.paramValue("min").toDouble();
2347 double factor = params.paramValue("factor", "1").toDouble();
2348 params.removeParam("starttag");
2349 params.removeParam("endtag");
2350 params.removeParam("keyframes");
2351 params.removeParam("min");
2352 params.removeParam("max");
2353 params.removeParam("factor");
2355 // Special case, only one keyframe, means we want a constant value
2356 if (keyFrames.count() == 1) {
2357 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2358 if (filter && filter->is_valid()) {
2359 filter->set("kdenlive_id", filterId);
2360 int x1 = keyFrames.at(0).section(':', 0, 0).toInt();
2361 double y1 = keyFrames.at(0).section(':', 1, 1).toDouble();
2362 for (int j = 0; j < params.count(); j++) {
2363 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2365 filter->set("in", x1);
2366 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2367 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2368 service.attach(*filter);
2370 } else for (int i = 0; i < keyFrames.size() - 1; ++i) {
2371 Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag);
2372 if (filter && filter->is_valid()) {
2373 filter->set("kdenlive_id", filterId);
2374 int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset;
2375 double y1 = keyFrames.at(i).section(':', 1, 1).toDouble();
2376 int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt();
2377 double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble();
2378 if (x2 == -1) x2 = duration;
2380 for (int j = 0; j < params.count(); j++) {
2381 filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData());
2384 filter->set("in", x1);
2385 filter->set("out", x2);
2386 //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<<max<<", "<<y1<<", factor: "<<factor;
2387 filter->set(starttag, QString::number((min + y1) / factor).toUtf8().data());
2388 filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data());
2389 service.attach(*filter);
2396 Mlt::Filter *filter;
2398 if (!region.isEmpty()) {
2399 filter = new Mlt::Filter(*m_mltProfile, "region");
2400 } else filter = new Mlt::Filter(*m_mltProfile, filterTag);
2401 if (filter && filter->is_valid()) {
2402 filter->set("kdenlive_id", filterId);
2403 if (!region.isEmpty()) {
2404 filter->set("resource", region.toUtf8().constData());
2405 filter->set("kdenlive_ix", params.paramValue("kdenlive_ix").toUtf8().constData());
2406 filter->set("filter0", filterTag);
2407 prefix = "filter0.";
2408 params.removeParam("id");
2409 params.removeParam("region");
2410 params.removeParam("kdenlive_ix");
2413 kDebug() << "filter is NULL";
2414 m_isBlocked = false;
2415 mlt_service_unlock(service.get_service());
2418 params.removeParam("kdenlive_id");
2420 for (int j = 0; j < params.count(); j++) {
2421 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2425 QString effectArgs = params.paramValue("id").section('_', 1);
2427 params.removeParam("id");
2428 params.removeParam("kdenlive_ix");
2429 params.removeParam("tag");
2430 params.removeParam("disable");
2431 params.removeParam("region");
2433 for (int j = 0; j < params.count(); j++) {
2434 effectArgs.append(' ' + params.at(j).value());
2436 //kDebug() << "SOX EFFECTS: " << effectArgs.simplified();
2437 filter->set("effect", effectArgs.simplified().toUtf8().constData());
2440 if (params.paramValue("id") == "pan_zoom") {
2441 filter->set_in_and_out(service.get_int("in"), service.get_int("out") + 1);
2444 // attach filter to the clip
2445 service.attach(*filter);
2450 // re-add following filters
2451 for (int i = 0; i < filtersList.count(); i++) {
2452 Mlt::Filter *filter = filtersList.at(i);
2454 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") + 1);
2455 service.attach(*filter);
2457 m_isBlocked = false;
2458 mlt_service_unlock(service.get_service());
2459 if (doRefresh) refresh();
2463 bool Render::mltEditTrackEffect(int track, EffectsParameterList params)
2465 Mlt::Service service(m_mltProducer->parent().get_service());
2466 Mlt::Tractor tractor(service);
2467 Mlt::Producer trackProducer(tractor.track(track));
2468 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2469 Mlt::Service clipService(trackPlaylist.get_service());
2472 QString index = params.paramValue("kdenlive_ix");
2473 QString tag = params.paramValue("tag");
2475 Mlt::Filter *filter = clipService.filter(ct);
2477 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2481 filter = clipService.filter(ct);
2485 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2486 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2488 bool success = false;//mltAddTrackEffect(track, params);
2489 m_isBlocked = false;
2493 QString ser = filter->get("mlt_service");
2494 if (ser == "region") prefix = "filter0.";
2495 mlt_service_lock(service.get_service());
2496 for (int j = 0; j < params.count(); j++) {
2497 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2499 mlt_service_unlock(service.get_service());
2501 m_isBlocked = false;
2507 bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params)
2509 QString index = params.paramValue("kdenlive_ix");
2510 QString tag = params.paramValue("tag");
2512 if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) {
2513 // This is a keyframe effect, to edit it, we remove it and re-add it.
2514 bool success = mltRemoveEffect(track, position, index, false);
2515 if (!success) kDebug() << "// ERROR Removing effect : " << index;
2516 if (position < GenTime()) success = mltAddTrackEffect(track, params);
2517 else success = mltAddEffect(track, position, params);
2518 if (!success) kDebug() << "// ERROR Adding effect : " << index;
2521 if (position < GenTime()) {
2522 return mltEditTrackEffect(track, params);
2525 Mlt::Service service(m_mltProducer->parent().get_service());
2526 Mlt::Tractor tractor(service);
2527 Mlt::Producer trackProducer(tractor.track(track));
2528 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2530 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2531 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2533 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2537 Mlt::Service clipService(clip->get_service());
2538 int duration = clip->get_playtime();
2539 bool doRefresh = true;
2540 // Check if clip is visible in monitor
2541 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2542 if (diff < 0 || diff > duration) doRefresh = false;
2546 /* kDebug() << "EDITING FILTER: "<<index <<", "<<tag;
2547 kDebug() << "EFFect stack: ++++++++++++++++++++++++++";
2549 kDebug() << "Filter: "<< filter->get("kdenlive_id") <<", IX: "<<filter->get("kdenlive_ix");
2551 filter = clipService.filter(ct);
2553 kDebug() << "++++++++++++++++++++++++++";
2555 filter = clipService.filter(ct); */
2557 Mlt::Filter *filter = clipService.filter(ct);
2559 if (filter->get_int("kdenlive_ix") == index.toInt()) {
2563 filter = clipService.filter(ct);
2567 kDebug() << "WARINIG, FILTER FOR EDITING NOT FOUND, ADDING IT! " << index << ", " << tag;
2568 // filter was not found, it was probably a disabled filter, so add it to the correct place...
2570 bool success = mltAddEffect(track, position, params);
2571 m_isBlocked = false;
2575 QString ser = filter->get("mlt_service");
2576 if (ser == "region") prefix = "filter0.";
2577 mlt_service_lock(service.get_service());
2578 for (int j = 0; j < params.count(); j++) {
2579 filter->set((prefix + params.at(j).name()).toUtf8().constData(), params.at(j).value().toUtf8().constData());
2581 mlt_service_unlock(service.get_service());
2583 m_isBlocked = false;
2584 if (doRefresh) refresh();
2588 void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos)
2590 Mlt::Service service(m_mltProducer->parent().get_service());
2591 Mlt::Tractor tractor(service);
2592 Mlt::Producer trackProducer(tractor.track(track));
2593 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2595 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2596 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2598 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2602 Mlt::Service clipService(clip->get_service());
2603 int duration = clip->get_playtime();
2604 bool doRefresh = true;
2605 // Check if clip is visible in monitor
2606 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2607 if (diff < 0 || diff > duration) doRefresh = false;
2612 Mlt::Filter *filter = clipService.filter(ct);
2614 int pos = filter->get_int("kdenlive_ix");
2615 if (pos == oldPos) {
2616 filter->set("kdenlive_ix", newPos);
2618 filter = clipService.filter(ct);
2621 m_isBlocked = false;
2622 if (doRefresh) refresh();
2625 void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos)
2627 if (position < GenTime()) {
2628 mltMoveTrackEffect(track, oldPos, newPos);
2631 Mlt::Service service(m_mltProducer->parent().get_service());
2632 Mlt::Tractor tractor(service);
2633 Mlt::Producer trackProducer(tractor.track(track));
2634 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2636 int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps));
2637 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2639 kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps);
2643 Mlt::Service clipService(clip->get_service());
2644 int duration = clip->get_playtime();
2645 bool doRefresh = true;
2646 // Check if clip is visible in monitor
2647 int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position();
2648 if (diff < 0 || diff > duration) doRefresh = false;
2653 QList <Mlt::Filter *> filtersList;
2654 Mlt::Filter *filter = clipService.filter(ct);
2656 if (newPos > oldPos) {
2658 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2659 filter->set("kdenlive_ix", newPos);
2660 filtersList.append(filter);
2661 clipService.detach(*filter);
2662 filter = clipService.filter(ct);
2663 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2664 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2666 filter = clipService.filter(ct);
2670 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2671 filtersList.append(filter);
2672 clipService.detach(*filter);
2674 filter = clipService.filter(ct);
2678 if (filter->get_int("kdenlive_ix") == oldPos) {
2679 filter->set("kdenlive_ix", newPos);
2680 filtersList.append(filter);
2681 clipService.detach(*filter);
2683 filter = clipService.filter(ct);
2687 filter = clipService.filter(ct);
2689 int pos = filter->get_int("kdenlive_ix");
2690 if (pos >= newPos) {
2691 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2692 filtersList.append(filter);
2693 clipService.detach(*filter);
2695 filter = clipService.filter(ct);
2699 for (int i = 0; i < filtersList.count(); i++) {
2700 clipService.attach(*(filtersList.at(i)));
2703 m_isBlocked = false;
2704 if (doRefresh) refresh();
2707 void Render::mltMoveTrackEffect(int track, int oldPos, int newPos)
2709 Mlt::Service service(m_mltProducer->parent().get_service());
2710 Mlt::Tractor tractor(service);
2711 Mlt::Producer trackProducer(tractor.track(track));
2712 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2714 Mlt::Service clipService(trackPlaylist.get_service());
2718 QList <Mlt::Filter *> filtersList;
2719 Mlt::Filter *filter = clipService.filter(ct);
2721 if (newPos > oldPos) {
2723 if (!found && filter->get_int("kdenlive_ix") == oldPos) {
2724 filter->set("kdenlive_ix", newPos);
2725 filtersList.append(filter);
2726 clipService.detach(*filter);
2727 filter = clipService.filter(ct);
2728 while (filter && filter->get_int("kdenlive_ix") <= newPos) {
2729 filter->set("kdenlive_ix", filter->get_int("kdenlive_ix") - 1);
2731 filter = clipService.filter(ct);
2735 if (filter && filter->get_int("kdenlive_ix") > newPos) {
2736 filtersList.append(filter);
2737 clipService.detach(*filter);
2739 filter = clipService.filter(ct);
2743 if (filter->get_int("kdenlive_ix") == oldPos) {
2744 filter->set("kdenlive_ix", newPos);
2745 filtersList.append(filter);
2746 clipService.detach(*filter);
2748 filter = clipService.filter(ct);
2752 filter = clipService.filter(ct);
2754 int pos = filter->get_int("kdenlive_ix");
2755 if (pos >= newPos) {
2756 if (pos < oldPos) filter->set("kdenlive_ix", pos + 1);
2757 filtersList.append(filter);
2758 clipService.detach(*filter);
2760 filter = clipService.filter(ct);
2764 for (int i = 0; i < filtersList.count(); i++) {
2765 clipService.attach(*(filtersList.at(i)));
2767 m_isBlocked = false;
2771 bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration)
2774 Mlt::Service service(m_mltProducer->parent().get_service());
2775 Mlt::Tractor tractor(service);
2776 Mlt::Producer trackProducer(tractor.track(info.track));
2777 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2779 /* // Display playlist info
2780 kDebug()<<"//////////// BEFORE RESIZE";
2781 for (int i = 0; i < trackPlaylist.count(); i++) {
2782 int blankStart = trackPlaylist.clip_start(i);
2783 int blankDuration = trackPlaylist.clip_length(i) - 1;
2785 if (trackPlaylist.is_blank(i)) blk = "(blank)";
2786 kDebug()<<"CLIP "<<i<<": ("<<blankStart<<'x'<<blankStart + blankDuration<<")"<<blk;
2789 if (trackPlaylist.is_blank_at((int) info.startPos.frames(m_fps))) {
2790 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2791 m_isBlocked = false;
2794 mlt_service_lock(service.get_service());
2795 int clipIndex = trackPlaylist.get_clip_index_at((int) info.startPos.frames(m_fps));
2796 //kDebug() << "// SELECTED CLIP START: " << trackPlaylist.clip_start(clipIndex);
2797 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2799 int previousStart = clip->get_in();
2800 int newDuration = (int) clipDuration.frames(m_fps) - 1;
2801 int diff = newDuration - (trackPlaylist.clip_length(clipIndex) - 1);
2803 int currentOut = newDuration + previousStart;
2804 if (currentOut > clip->get_length()) {
2805 clip->parent().set("length", currentOut + 1);
2806 clip->parent().set("out", currentOut);
2807 clip->set("length", currentOut + 1);
2810 /*if (newDuration > clip->get_out()) {
2811 clip->parent().set_in_and_out(0, newDuration + 1);
2812 clip->set_in_and_out(0, newDuration + 1);
2815 trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart);
2816 trackPlaylist.consolidate_blanks(0);
2817 // skip to next clip
2819 //kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count();
2821 // clip was made longer, trim next blank if there is one.
2822 if (clipIndex < trackPlaylist.count()) {
2823 // If this is not the last clip in playlist
2824 if (trackPlaylist.is_blank(clipIndex)) {
2825 int blankStart = trackPlaylist.clip_start(clipIndex);
2826 int blankDuration = trackPlaylist.clip_length(clipIndex);
2827 if (diff > blankDuration) {
2828 kDebug() << "// ERROR blank clip is not large enough to get back required space!!!";
2830 if (diff - blankDuration == 0) {
2831 trackPlaylist.remove(clipIndex);
2832 } else trackPlaylist.remove_region(blankStart, diff);
2834 kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex;
2837 } else if (clipIndex != trackPlaylist.count()) trackPlaylist.insert_blank(clipIndex, 0 - diff - 1);
2838 trackPlaylist.consolidate_blanks(0);
2839 mlt_service_unlock(service.get_service());
2841 if (info.track != 0 && clipIndex == trackPlaylist.count()) mltCheckLength(&tractor);
2842 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2843 //mltResizeTransparency(previousStart, previousStart, previousStart + newDuration, track, QString(clip->parent().get("id")).toInt());
2844 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2845 ItemInfo transpinfo;
2846 transpinfo.startPos = info.startPos;
2847 transpinfo.endPos = info.startPos + clipDuration;
2848 transpinfo.track = info.track;
2849 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2851 m_isBlocked = false;
2852 m_mltConsumer->set("refresh", 1);
2856 void Render::mltChangeTrackState(int track, bool mute, bool blind)
2858 Mlt::Service service(m_mltProducer->parent().get_service());
2859 Mlt::Tractor tractor(service);
2860 Mlt::Producer trackProducer(tractor.track(track));
2863 if (blind) trackProducer.set("hide", 3);
2864 else trackProducer.set("hide", 2);
2866 trackProducer.set("hide", 1);
2868 trackProducer.set("hide", 0);
2870 tractor.multitrack()->refresh();
2876 bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff)
2878 Mlt::Service service(m_mltProducer->parent().get_service());
2879 int frameOffset = (int) diff.frames(m_fps);
2880 Mlt::Tractor tractor(service);
2881 Mlt::Producer trackProducer(tractor.track(info.track));
2882 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2883 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2884 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2887 mlt_service_lock(service.get_service());
2888 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2889 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2891 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2892 mlt_service_unlock(service.get_service());
2895 int previousStart = clip->get_in();
2896 int previousOut = clip->get_out();
2899 trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset);
2900 m_isBlocked = false;
2901 mlt_service_unlock(service.get_service());
2902 m_mltConsumer->set("refresh", 1);
2906 bool Render::mltResizeClipStart(ItemInfo info, GenTime diff)
2908 //kDebug() << "//////// RSIZING CLIP from: "<<info.startPos.frames(25)<<" to "<<diff.frames(25);
2909 Mlt::Service service(m_mltProducer->parent().get_service());
2910 int moveFrame = (int) diff.frames(m_fps);
2911 Mlt::Tractor tractor(service);
2912 Mlt::Producer trackProducer(tractor.track(info.track));
2913 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2914 if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) {
2915 kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!";
2918 mlt_service_lock(service.get_service());
2919 int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps));
2920 Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex);
2921 if (clip == NULL || clip->is_blank()) {
2922 kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!";
2923 mlt_service_unlock(service.get_service());
2926 int previousStart = clip->get_in();
2927 int previousOut = clip->get_out();
2930 previousStart += moveFrame;
2932 int length = previousOut + 1;
2933 if (length > clip->get_length()) {
2934 clip->parent().set("length", length + 1);
2935 clip->parent().set("out", length);
2936 clip->set("length", length + 1);
2940 // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut;
2941 trackPlaylist.resize_clip(clipIndex, previousStart, previousOut);
2942 if (moveFrame > 0) {
2943 trackPlaylist.insert_blank(clipIndex, moveFrame - 1);
2945 //int midpos = info.startPos.frames(m_fps) + moveFrame - 1;
2946 int blankIndex = clipIndex - 1;
2947 int blankLength = trackPlaylist.clip_length(blankIndex);
2948 // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame;
2949 if (! trackPlaylist.is_blank(blankIndex)) {
2950 kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK";
2952 if (blankLength + moveFrame == 0)
2953 trackPlaylist.remove(blankIndex);
2955 trackPlaylist.resize_clip(blankIndex, 0, blankLength + moveFrame - 1);
2957 trackPlaylist.consolidate_blanks(0);
2958 /*if (QString(clip->parent().get("transparency")).toInt() == 1) {
2959 //mltResizeTransparency(previousStart, (int) moveEnd.frames(m_fps), (int) (moveEnd + out - in).frames(m_fps), track, QString(clip->parent().get("id")).toInt());
2960 mltDeleteTransparency(info.startPos.frames(m_fps), info.track, QString(clip->parent().get("id")).toInt());
2961 ItemInfo transpinfo;
2962 transpinfo.startPos = info.startPos + diff;
2963 transpinfo.endPos = info.startPos + diff + (info.endPos - info.startPos);
2964 transpinfo.track = info.track;
2965 mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt());
2967 m_isBlocked = false;
2968 //m_mltConsumer->set("refresh", 1);
2969 mlt_service_unlock(service.get_service());
2970 m_mltConsumer->set("refresh", 1);
2974 bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod, bool overwrite, bool insert)
2976 return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod, overwrite, insert);
2980 bool Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod)
2982 if (prod == NULL || !prod->is_valid()) {
2983 kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!";
2986 kDebug() << "NEW PROD ID: " << prod->get("id");
2988 kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track;
2989 Mlt::Service service(m_mltProducer->parent().get_service());
2990 if (service.type() != tractor_type) {
2991 kWarning() << "// TRACTOR PROBLEM";
2994 mlt_service_lock(service.get_service());
2995 Mlt::Tractor tractor(service);
2996 Mlt::Producer trackProducer(tractor.track(track));
2997 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
2998 int clipIndex = trackPlaylist.get_clip_index_at(pos);
2999 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3000 if (clipProducer == NULL || clipProducer->is_blank()) {
3001 kDebug() << "// ERROR UPDATING CLIP PROD";
3002 delete clipProducer;
3003 mlt_service_unlock(service.get_service());
3007 Mlt::Producer *clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3008 if (!clip || !clip->is_valid()) {
3009 if (clip) delete clip;
3010 delete clipProducer;
3011 mlt_service_unlock(service.get_service());
3015 // move all effects to the correct producer
3016 mltPasteEffects(clipProducer, clip);
3017 trackPlaylist.insert_at(pos, clip, 1);
3019 delete clipProducer;
3020 mlt_service_unlock(service.get_service());
3025 bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod, bool overwrite, bool /*insert*/)
3029 Mlt::Service service(m_mltProducer->parent().get_service());
3030 if (service.type() != tractor_type) {
3031 kWarning() << "// TRACTOR PROBLEM";
3035 Mlt::Tractor tractor(service);
3036 mlt_service_lock(service.get_service());
3037 Mlt::Producer trackProducer(tractor.track(startTrack));
3038 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3039 int clipIndex = trackPlaylist.get_clip_index_at(moveStart);
3040 kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex;
3041 bool checkLength = false;
3042 if (endTrack == startTrack) {
3043 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3044 if ((!overwrite && !trackPlaylist.is_blank_at(moveEnd)) || !clipProducer || !clipProducer->is_valid() || clipProducer->is_blank()) {
3045 // error, destination is not empty
3047 if (!trackPlaylist.is_blank_at(moveEnd) && clipProducer->is_valid()) trackPlaylist.insert_at(moveStart, clipProducer, 1);
3048 delete clipProducer;
3050 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3051 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3052 mlt_service_unlock(service.get_service());
3056 trackPlaylist.consolidate_blanks(0);
3058 trackPlaylist.remove_region(moveEnd, clipProducer->get_playtime());
3059 int clipIndex = trackPlaylist.get_clip_index_at(moveEnd);
3060 trackPlaylist.insert_blank(clipIndex, clipProducer->get_playtime() - 1);
3062 int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1);
3063 trackPlaylist.consolidate_blanks(1);
3064 delete clipProducer;
3065 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3066 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3068 if (newIndex + 1 == trackPlaylist.count()) checkLength = true;
3070 //mlt_service_unlock(service.get_service());
3072 Mlt::Producer destTrackProducer(tractor.track(endTrack));
3073 Mlt::Playlist destTrackPlaylist((mlt_playlist) destTrackProducer.get_service());
3074 if (!overwrite && !destTrackPlaylist.is_blank_at(moveEnd)) {
3075 // error, destination is not empty
3076 mlt_service_unlock(service.get_service());
3080 Mlt::Producer *clipProducer = trackPlaylist.replace_with_blank(clipIndex);
3081 if (!clipProducer || clipProducer->is_blank()) {
3082 // error, destination is not empty
3083 //int ix = trackPlaylist.get_clip_index_at(moveEnd);
3084 if (clipProducer) delete clipProducer;
3085 kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd;
3086 mlt_service_unlock(service.get_service());
3090 trackPlaylist.consolidate_blanks(0);
3091 destTrackPlaylist.consolidate_blanks(1);
3092 Mlt::Producer *clip;
3093 // check if we are moving a slowmotion producer
3094 QString serv = clipProducer->parent().get("mlt_service");
3095 QString currentid = clipProducer->parent().get("id");
3096 if (serv == "framebuffer" || currentid.endsWith("_video")) {
3097 clip = clipProducer;
3100 // Special case: prod is null when using placeholder clips.
3101 // in that case, use the producer existing in playlist. Note that
3102 // it will bypass the one producer per track logic and might cause
3103 // Sound cracks if clip is moved so that it overlaps another copy of itself
3104 clip = clipProducer->cut(clipProducer->get_in(), clipProducer->get_out());
3105 } else clip = prod->cut(clipProducer->get_in(), clipProducer->get_out());
3108 // move all effects to the correct producer
3109 mltPasteEffects(clipProducer, clip);
3112 destTrackPlaylist.remove_region(moveEnd, clip->get_playtime());
3113 int clipIndex = destTrackPlaylist.get_clip_index_at(moveEnd);
3114 destTrackPlaylist.insert_blank(clipIndex, clip->get_playtime() - 1);
3117 int newIndex = destTrackPlaylist.insert_at(moveEnd, clip, 1);
3119 if (clip == clipProducer) {
3124 delete clipProducer;
3126 destTrackPlaylist.consolidate_blanks(0);
3127 /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) {
3128 kDebug() << "//////// moving clip transparency";
3129 mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt());
3131 if (clipIndex > trackPlaylist.count()) checkLength = true;
3132 else if (newIndex + 1 == destTrackPlaylist.count()) checkLength = true;
3135 mlt_service_unlock(service.get_service());
3136 if (checkLength) mltCheckLength(&tractor);
3139 //m_mltConsumer->set("refresh", 1);
3144 QList <int> Render::checkTrackSequence(int track)
3147 Mlt::Service service(m_mltProducer->parent().get_service());
3148 if (service.type() != tractor_type) {
3149 kWarning() << "// TRACTOR PROBLEM";
3152 Mlt::Tractor tractor(service);
3153 mlt_service_lock(service.get_service());
3154 Mlt::Producer trackProducer(tractor.track(track));
3155 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3156 int clipNb = trackPlaylist.count();
3157 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3158 for (int i = 0; i < clipNb; i++) {
3159 Mlt::Producer *c = trackPlaylist.get_clip(i);
3160 int pos = trackPlaylist.clip_start(i);
3161 if (!list.contains(pos)) list.append(pos);
3162 pos += c->get_playtime();
3163 if (!list.contains(pos)) list.append(pos);
3169 bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut)
3171 int new_in = (int)newIn.frames(m_fps);
3172 int new_out = (int)newOut.frames(m_fps) - 1;
3173 if (new_in >= new_out) return false;
3174 int old_in = (int)oldIn.frames(m_fps);
3175 int old_out = (int)oldOut.frames(m_fps) - 1;
3177 Mlt::Service service(m_mltProducer->parent().get_service());
3178 Mlt::Tractor tractor(service);
3179 Mlt::Field *field = tractor.field();
3181 bool doRefresh = true;
3182 // Check if clip is visible in monitor
3183 int diff = old_out - m_mltProducer->position();
3184 if (diff < 0 || diff > old_out - old_in) doRefresh = false;
3186 diff = new_out - m_mltProducer->position();
3187 if (diff < 0 || diff > new_out - new_in) doRefresh = false;
3191 mlt_service_lock(service.get_service());
3193 mlt_service nextservice = mlt_service_get_producer(service.get_service());
3194 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3195 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3196 QString resource = mlt_properties_get(properties, "mlt_service");
3197 int old_pos = (int)(old_in + old_out) / 2;
3200 while (mlt_type == "transition") {
3201 Mlt::Transition transition((mlt_transition) nextservice);
3202 int currentTrack = transition.get_b_track();
3203 int currentIn = (int) transition.get_in();
3204 int currentOut = (int) transition.get_out();
3206 if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3208 if (newTrack - startTrack != 0) {
3209 Mlt::Properties trans_props(transition.get_properties());
3210 Mlt::Transition new_transition(*m_mltProfile, transition.get("mlt_service"));
3211 Mlt::Properties new_trans_props(new_transition.get_properties());
3212 new_trans_props.inherit(trans_props);
3213 new_transition.set_in_and_out(new_in, new_out);
3214 field->disconnect_service(transition);
3215 mltPlantTransition(field, new_transition, newTransitionTrack, newTrack);
3216 //field->plant_transition(new_transition, newTransitionTrack, newTrack);
3217 } else transition.set_in_and_out(new_in, new_out);
3220 nextservice = mlt_service_producer(nextservice);
3221 if (nextservice == NULL) break;
3222 properties = MLT_SERVICE_PROPERTIES(nextservice);
3223 mlt_type = mlt_properties_get(properties, "mlt_type");
3224 resource = mlt_properties_get(properties, "mlt_service");
3226 mlt_service_unlock(service.get_service());
3228 if (doRefresh) refresh();
3229 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3234 void Render::mltPlantTransition(Mlt::Field *field, Mlt::Transition &tr, int a_track, int b_track)
3236 mlt_service nextservice = mlt_service_get_producer(field->get_service());
3237 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3238 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3239 QString resource = mlt_properties_get(properties, "mlt_service");
3240 QList <Mlt::Transition *> trList;
3242 while (mlt_type == "transition") {
3243 Mlt::Transition transition((mlt_transition) nextservice);
3244 int aTrack = transition.get_a_track();
3245 int bTrack = transition.get_b_track();
3246 if (resource != "mix" && (aTrack < a_track || (aTrack == a_track && bTrack > b_track))) {
3247 Mlt::Properties trans_props(transition.get_properties());
3248 Mlt::Transition *cp = new Mlt::Transition(*m_mltProfile, transition.get("mlt_service"));
3249 Mlt::Properties new_trans_props(cp->get_properties());
3250 new_trans_props.inherit(trans_props);
3252 field->disconnect_service(transition);
3254 //else kDebug() << "// FOUND TRANS OK, "<<resource<< ", A_: " << aTrack << ", B_ "<<bTrack;
3256 nextservice = mlt_service_producer(nextservice);
3257 if (nextservice == NULL) break;
3258 properties = MLT_SERVICE_PROPERTIES(nextservice);
3259 mlt_type = mlt_properties_get(properties, "mlt_type");
3260 resource = mlt_properties_get(properties, "mlt_service");
3263 field->plant_transition(tr, a_track, b_track);
3265 // re-add upper transitions
3266 for (int i = 0; i < trList.count(); i++) {
3267 // kDebug()<< "REPLANT ON TK: "<<trList.at(i)->get_a_track()<<", "<<trList.at(i)->get_b_track();
3268 field->plant_transition(*trList.at(i), trList.at(i)->get_a_track(), trList.at(i)->get_b_track());
3272 void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool force)
3274 if (oldTag == tag && !force) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml);
3276 mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false);
3277 mltAddTransition(tag, a_track, b_track, in, out, xml, false);
3280 if (m_mltProducer->position() >= in.frames(m_fps) && m_mltProducer->position() <= out.frames(m_fps)) refresh();
3283 void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml)
3285 mlt_service serv = m_mltProducer->parent().get_service();
3286 mlt_service_lock(serv);
3289 mlt_service nextservice = mlt_service_get_producer(serv);
3290 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3291 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3292 QString resource = mlt_properties_get(properties, "mlt_service");
3293 int in_pos = (int) in.frames(m_fps);
3294 int out_pos = (int) out.frames(m_fps) - 1;
3296 while (mlt_type == "transition") {
3297 mlt_transition tr = (mlt_transition) nextservice;
3298 int currentTrack = mlt_transition_get_b_track(tr);
3299 int currentBTrack = mlt_transition_get_a_track(tr);
3300 int currentIn = (int) mlt_transition_get_in(tr);
3301 int currentOut = (int) mlt_transition_get_out(tr);
3303 // kDebug()<<"Looking for transition : " << currentIn <<'x'<<currentOut<< ", OLD oNE: "<<in_pos<<'x'<<out_pos;
3305 if (resource == type && b_track == currentTrack && currentIn == in_pos && currentOut == out_pos) {
3306 QMap<QString, QString> map = mltGetTransitionParamsFromXml(xml);
3307 QMap<QString, QString>::Iterator it;
3309 mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr);
3311 QString currentId = mlt_properties_get(transproperties, "kdenlive_id");
3312 if (currentId != xml.attribute("id")) {
3313 // The transition ID is not the same, so reset all properties
3314 mlt_properties_set(transproperties, "kdenlive_id", xml.attribute("id").toUtf8().constData());
3315 // Cleanup previous properties
3316 QStringList permanentProps;
3317 permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in";
3318 permanentProps << "out" << "a_track" << "b_track";
3319 for (int i = 0; i < mlt_properties_count(transproperties); i++) {
3320 QString propName = mlt_properties_get_name(transproperties, i);
3321 if (!propName.startsWith('_') && ! permanentProps.contains(propName)) {
3322 mlt_properties_set(transproperties, propName.toUtf8().constData(), "");
3327 mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt());
3328 mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt());
3330 if (currentBTrack != a_track) {
3331 mlt_properties_set_int(transproperties, "a_track", a_track);
3333 for (it = map.begin(); it != map.end(); ++it) {
3335 mlt_properties_set(transproperties, key.toUtf8().constData(), it.value().toUtf8().constData());
3336 //kDebug() << " ------ UPDATING TRANS PARAM: " << key.toUtf8().constData() << ": " << it.value().toUtf8().constData();
3337 //filter->set("kdenlive_id", id);
3341 nextservice = mlt_service_producer(nextservice);
3342 if (nextservice == NULL) break;
3343 properties = MLT_SERVICE_PROPERTIES(nextservice);
3344 mlt_type = mlt_properties_get(properties, "mlt_type");
3345 resource = mlt_properties_get(properties, "mlt_service");
3347 mlt_service_unlock(serv);
3350 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3353 void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/)
3355 mlt_service serv = m_mltProducer->parent().get_service();
3357 mlt_service_lock(serv);
3359 Mlt::Service service(serv);
3360 Mlt::Tractor tractor(service);
3361 Mlt::Field *field = tractor.field();
3363 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3365 mlt_service nextservice = mlt_service_get_producer(serv);
3366 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3367 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3368 QString resource = mlt_properties_get(properties, "mlt_service");
3370 const int old_pos = (int)((in + out).frames(m_fps) / 2);
3371 kDebug() << " del trans pos: " << in.frames(25) << "-" << out.frames(25);
3373 while (mlt_type == "transition") {
3374 mlt_transition tr = (mlt_transition) nextservice;
3375 int currentTrack = mlt_transition_get_b_track(tr);
3376 int currentIn = (int) mlt_transition_get_in(tr);
3377 int currentOut = (int) mlt_transition_get_out(tr);
3378 //kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3380 if (resource == tag && b_track == currentTrack && currentIn <= old_pos && currentOut >= old_pos) {
3381 mlt_field_disconnect_service(field->get_field(), nextservice);
3384 nextservice = mlt_service_producer(nextservice);
3385 if (nextservice == NULL) break;
3386 properties = MLT_SERVICE_PROPERTIES(nextservice);
3387 mlt_type = mlt_properties_get(properties, "mlt_type");
3388 resource = mlt_properties_get(properties, "mlt_service");
3390 mlt_service_unlock(serv);
3393 //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3396 QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
3398 QDomNodeList attribs = xml.elementsByTagName("parameter");
3399 QMap<QString, QString> map;
3400 for (int i = 0; i < attribs.count(); i++) {
3401 QDomElement e = attribs.item(i).toElement();
3402 QString name = e.attribute("name");
3403 //kDebug()<<"-- TRANSITION PARAM: "<<name<<" = "<< e.attribute("name")<<" / " << e.attribute("value");
3404 map[name] = e.attribute("default");
3405 if (!e.attribute("value").isEmpty()) {
3406 map[name] = e.attribute("value");
3408 if (!e.attribute("factor").isEmpty() && e.attribute("factor").toDouble() > 0) {
3409 map[name] = QString::number(map[name].toDouble() / e.attribute("factor").toDouble());
3410 //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . ,
3413 if (e.attribute("namedesc").contains(';')) {
3414 QString format = e.attribute("format");
3415 QStringList separators = format.split("%d", QString::SkipEmptyParts);
3416 QStringList values = e.attribute("value").split(QRegExp("[,:;x]"));
3418 QTextStream txtNeu(&neu);
3419 if (values.size() > 0)
3420 txtNeu << (int)values[0].toDouble();
3422 for (i = 0; i < separators.size() && i + 1 < values.size(); i++) {
3423 txtNeu << separators[i];
3424 txtNeu << (int)(values[i+1].toDouble());
3426 if (i < separators.size())
3427 txtNeu << separators[i];
3428 map[e.attribute("name")] = neu;
3435 void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id)
3437 kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25);
3438 Mlt::Service service(m_mltProducer->parent().get_service());
3439 Mlt::Tractor tractor(service);
3440 Mlt::Field *field = tractor.field();
3442 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "composite");
3443 transition->set_in_and_out((int) info.startPos.frames(m_fps), (int) info.endPos.frames(m_fps) - 1);
3444 transition->set("transparency", id);
3445 transition->set("fill", 1);
3446 transition->set("internal_added", 237);
3447 field->plant_transition(*transition, transitiontrack, info.track);
3451 void Render::mltDeleteTransparency(int pos, int track, int id)
3453 Mlt::Service service(m_mltProducer->parent().get_service());
3454 Mlt::Tractor tractor(service);
3455 Mlt::Field *field = tractor.field();
3457 //if (do_refresh) m_mltConsumer->set("refresh", 0);
3458 mlt_service serv = m_mltProducer->parent().get_service();
3460 mlt_service nextservice = mlt_service_get_producer(serv);
3461 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3462 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3463 QString resource = mlt_properties_get(properties, "mlt_service");
3465 while (mlt_type == "transition") {
3466 mlt_transition tr = (mlt_transition) nextservice;
3467 int currentTrack = mlt_transition_get_b_track(tr);
3468 int currentIn = (int) mlt_transition_get_in(tr);
3469 int currentOut = (int) mlt_transition_get_out(tr);
3470 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3471 kDebug() << "// FOUND EXISTING TRANS, IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack;
3473 if (resource == "composite" && track == currentTrack && currentIn == pos && transitionId == id) {
3474 //kDebug() << " / / / / /DELETE TRANS DOOOMNE";
3475 mlt_field_disconnect_service(field->get_field(), nextservice);
3478 nextservice = mlt_service_producer(nextservice);
3479 if (nextservice == NULL) break;
3480 properties = MLT_SERVICE_PROPERTIES(nextservice);
3481 mlt_type = mlt_properties_get(properties, "mlt_type");
3482 resource = mlt_properties_get(properties, "mlt_service");
3484 //if (do_refresh) m_mltConsumer->set("refresh", 1);
3487 void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id)
3489 Mlt::Service service(m_mltProducer->parent().get_service());
3490 Mlt::Tractor tractor(service);
3492 mlt_service_lock(service.get_service());
3493 m_mltConsumer->set("refresh", 0);
3496 mlt_service serv = m_mltProducer->parent().get_service();
3497 mlt_service nextservice = mlt_service_get_producer(serv);
3498 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3499 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3500 QString resource = mlt_properties_get(properties, "mlt_service");
3501 kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id;
3502 while (mlt_type == "transition") {
3503 mlt_transition tr = (mlt_transition) nextservice;
3504 int currentTrack = mlt_transition_get_b_track(tr);
3505 int currentIn = (int) mlt_transition_get_in(tr);
3506 //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr);
3507 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3508 kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ;
3509 if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) {
3510 kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd;
3511 mlt_transition_set_in_and_out(tr, newStart, newEnd);
3514 nextservice = mlt_service_producer(nextservice);
3515 if (nextservice == NULL) break;
3516 properties = MLT_SERVICE_PROPERTIES(nextservice);
3517 mlt_type = mlt_properties_get(properties, "mlt_type");
3518 resource = mlt_properties_get(properties, "mlt_service");
3520 mlt_service_unlock(service.get_service());
3522 if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
3526 void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id)
3528 Mlt::Service service(m_mltProducer->parent().get_service());
3529 Mlt::Tractor tractor(service);
3531 mlt_service_lock(service.get_service());
3532 m_mltConsumer->set("refresh", 0);
3535 mlt_service serv = m_mltProducer->parent().get_service();
3536 mlt_service nextservice = mlt_service_get_producer(serv);
3537 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3538 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3539 QString resource = mlt_properties_get(properties, "mlt_service");
3541 while (mlt_type == "transition") {
3542 mlt_transition tr = (mlt_transition) nextservice;
3543 int currentTrack = mlt_transition_get_b_track(tr);
3544 int currentaTrack = mlt_transition_get_a_track(tr);
3545 int currentIn = (int) mlt_transition_get_in(tr);
3546 int currentOut = (int) mlt_transition_get_out(tr);
3547 //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3548 int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt();
3549 //kDebug()<<" + TRANSITION "<<id<<" == "<<transitionId<<", START TMIE: "<<currentIn<<", LOOK FR: "<<startTime<<", TRACK: "<<currentTrack<<'x'<<startTrack;
3550 if (resource == "composite" && transitionId == id && startTime == currentIn && startTrack == currentTrack) {
3551 kDebug() << "//////MOVING";
3552 mlt_transition_set_in_and_out(tr, endTime, endTime + currentOut - currentIn);
3553 if (endTrack != startTrack) {
3554 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3555 mlt_properties_set_int(properties, "a_track", currentaTrack + endTrack - currentTrack);
3556 mlt_properties_set_int(properties, "b_track", endTrack);
3560 nextservice = mlt_service_producer(nextservice);
3561 if (nextservice == NULL) break;
3562 properties = MLT_SERVICE_PROPERTIES(nextservice);
3563 mlt_type = mlt_properties_get(properties, "mlt_type");
3564 resource = mlt_properties_get(properties, "mlt_service");
3567 mlt_service_unlock(service.get_service());
3568 m_mltConsumer->set("refresh", 1);
3572 bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh)
3574 if (in >= out) return false;
3575 QMap<QString, QString> args = mltGetTransitionParamsFromXml(xml);
3576 Mlt::Service service(m_mltProducer->parent().get_service());
3578 Mlt::Tractor tractor(service);
3579 Mlt::Field *field = tractor.field();
3581 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, tag.toUtf8().constData());
3582 if (out != GenTime())
3583 transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1);
3585 if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false;
3586 QMap<QString, QString>::Iterator it;
3588 if (xml.attribute("automatic") == "1") transition->set("automatic", 1);
3589 //kDebug() << " ------ ADDING TRANSITION PARAMs: " << args.count();
3590 if (xml.hasAttribute("id"))
3591 transition->set("kdenlive_id", xml.attribute("id").toUtf8().constData());
3593 for (it = args.begin(); it != args.end(); ++it) {
3595 if (!it.value().isEmpty())
3596 transition->set(key.toUtf8().constData(), it.value().toUtf8().constData());
3597 //kDebug() << " ------ ADDING TRANS PARAM: " << key << ": " << it.value();
3599 // attach transition
3600 mltPlantTransition(field, *transition, a_track, b_track);
3601 // field->plant_transition(*transition, a_track, b_track);
3602 if (do_refresh) refresh();
3606 void Render::mltSavePlaylist()
3608 kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++";
3609 Mlt::Consumer fileConsumer(*m_mltProfile, "xml");
3610 fileConsumer.set("resource", "/tmp/playlist.mlt");
3612 Mlt::Service service(m_mltProducer->get_service());
3614 fileConsumer.connect(service);
3615 fileConsumer.start();
3618 const QList <Mlt::Producer *> Render::producersList()
3620 QList <Mlt::Producer *> prods;
3621 if (m_mltProducer == NULL) return prods;
3622 Mlt::Service service(m_mltProducer->parent().get_service());
3623 if (service.type() != tractor_type) return prods;
3624 Mlt::Tractor tractor(service);
3627 int trackNb = tractor.count();
3628 for (int t = 1; t < trackNb; t++) {
3629 Mlt::Producer *tt = tractor.track(t);
3630 Mlt::Producer trackProducer(tt);
3632 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3633 int clipNb = trackPlaylist.count();
3634 //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb;
3635 for (int i = 0; i < clipNb; i++) {
3636 Mlt::Producer *c = trackPlaylist.get_clip(i);
3637 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3639 if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) {
3640 ids.append(nprod->get("id"));
3641 prods.append(nprod);
3642 } else delete nprod;
3650 void Render::fillSlowMotionProducers()
3652 if (m_mltProducer == NULL) return;
3653 Mlt::Service service(m_mltProducer->parent().get_service());
3654 if (service.type() != tractor_type) return;
3656 Mlt::Tractor tractor(service);
3658 int trackNb = tractor.count();
3659 for (int t = 1; t < trackNb; t++) {
3660 Mlt::Producer *tt = tractor.track(t);
3661 Mlt::Producer trackProducer(tt);
3663 Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
3664 int clipNb = trackPlaylist.count();
3665 for (int i = 0; i < clipNb; i++) {
3666 Mlt::Producer *c = trackPlaylist.get_clip(i);
3667 Mlt::Producer *nprod = new Mlt::Producer(c->get_parent());
3669 QString id = nprod->get("id");
3670 if (id.startsWith("slowmotion:") && !nprod->is_blank()) {
3671 // this is a slowmotion producer, add it to the list
3672 QString url = QString::fromUtf8(nprod->get("resource"));
3673 int strobe = nprod->get_int("strobe");
3674 if (strobe > 1) url.append("&strobe=" + QString::number(strobe));
3675 if (!m_slowmotionProducers.contains(url)) {
3676 m_slowmotionProducers.insert(url, nprod);
3678 } else delete nprod;
3685 void Render::mltInsertTrack(int ix, bool videoTrack)
3690 Mlt::Service service(m_mltProducer->parent().get_service());
3691 mlt_service_lock(service.get_service());
3692 if (service.type() != tractor_type) {
3693 kWarning() << "// TRACTOR PROBLEM";
3697 Mlt::Tractor tractor(service);
3699 Mlt::Playlist playlist;
3700 int ct = tractor.count();
3702 kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct;
3708 Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos));
3709 tractor.set_track(playlist, pos);
3710 Mlt::Producer newProd(tractor.track(pos));
3711 if (!videoTrack) newProd.set("hide", 1);
3713 for (; pos <= ct; pos++) {
3714 Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos));
3715 tractor.set_track(*prodToMove, pos);
3716 prodToMove = prodToMove2;
3719 tractor.set_track(playlist, ix);
3720 Mlt::Producer newProd(tractor.track(ix));
3721 if (!videoTrack) newProd.set("hide", 1);
3725 mlt_service serv = m_mltProducer->parent().get_service();
3726 mlt_service nextservice = mlt_service_get_producer(serv);
3727 mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice);
3728 QString mlt_type = mlt_properties_get(properties, "mlt_type");
3729 QString resource = mlt_properties_get(properties, "mlt_service");
3731 while (mlt_type == "transition") {
3732 if (resource != "mix") {
3733 mlt_transition tr = (mlt_transition) nextservice;
3734 int currentTrack = mlt_transition_get_b_track(tr);
3735 int currentaTrack = mlt_transition_get_a_track(tr);
3736 mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr);
3738 if (currentTrack >= ix) {
3739 mlt_properties_set_int(properties, "b_track", currentTrack + 1);
3740 mlt_properties_set_int(properties, "a_track", currentaTrack + 1);
3743 nextservice = mlt_service_producer(nextservice);
3744 if (nextservice == NULL) break;
3745 properties = MLT_SERVICE_PROPERTIES(nextservice);
3746 mlt_type = mlt_properties_get(properties, "mlt_type");
3747 resource = mlt_properties_get(properties, "mlt_service");
3750 // Add audio mix transition to last track
3751 Mlt::Field *field = tractor.field();
3752 Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix");
3753 transition->set("a_track", 1);
3754 transition->set("b_track", ct);
3755 transition->set("always_active", 1);
3756 transition->set("internal_added", 237);
3757 transition->set("combine", 1);
3758 field->plant_transition(*transition, 1, ct);
3759 //mlt_service_unlock(m_mltConsumer->get_service());
3760 mlt_service_unlock(service.get_service());
3761 //tractor.multitrack()->refresh();
3762 //tractor.refresh();
3764 blockSignals(false);
3768 void Render::mltDeleteTrack(int ix)
3771 doc.setContent(sceneList(), false);
3772 int tracksCount = doc.elementsByTagName("track").count() - 1;
3773 QDomNode track = doc.elementsByTagName("track").at(ix);
3774 QDomNode tractor = doc.elementsByTagName("tractor").at(0);
3775 QDomNodeList transitions = doc.elementsByTagName("transition");
3776 for (int i = 0; i < transitions.count(); i++) {
3777 QDomElement e = transitions.at(i).toElement();
3778 QDomNodeList props = e.elementsByTagName("property");
3779 QMap <QString, QString> mappedProps;
3780 for (int j = 0; j < props.count(); j++) {
3781 QDomElement f = props.at(j).toElement();
3782 mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue());
3784 if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) {
3785 tractor.removeChild(transitions.at(i));
3787 } else if (mappedProps.value("mlt_service") != "mix" && (mappedProps.value("b_track").toInt() >= ix || mappedProps.value("a_track").toInt() >= ix)) {
3788 // Transition needs to be moved
3789 int a_track = mappedProps.value("a_track").toInt();
3790 int b_track = mappedProps.value("b_track").toInt();
3791 if (a_track > 0 && a_track >= ix) a_track --;
3792 if (b_track == ix) {
3793 // transition was on the deleted track, so remove it
3794 tractor.removeChild(transitions.at(i));
3798 if (b_track > 0 && b_track > ix) b_track --;
3799 for (int j = 0; j < props.count(); j++) {
3800 QDomElement f = props.at(j).toElement();
3801 if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track));
3802 else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track));
3807 tractor.removeChild(track);
3808 //kDebug() << "/////////// RESULT SCENE: \n" << doc.toString();
3809 setSceneList(doc.toString(), m_framePosition);
3811 /* if (m_mltProducer != NULL) {
3812 Mlt::Producer parentProd(m_mltProducer->parent());
3813 if (parentProd.get_producer() != NULL) {
3814 Mlt::Service service(parentProd.get_service());
3815 if (service.type() == tractor_type) {
3816 Mlt::Tractor tractor(service);
3817 mltCheckLength(&tractor);
3824 void Render::updatePreviewSettings()
3826 kDebug() << "////// RESTARTING CONSUMER";
3827 if (!m_mltConsumer || !m_mltProducer) return;
3828 if (m_mltProducer->get_playtime() == 0) return;
3829 Mlt::Service service(m_mltProducer->parent().get_service());
3830 if (service.type() != tractor_type) return;
3832 //m_mltConsumer->set("refresh", 0);
3833 if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop();
3834 m_mltConsumer->purge();
3835 QString scene = sceneList();
3837 if (m_mltProducer) {
3838 pos = m_mltProducer->position();
3841 setSceneList(scene, pos);
3845 QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
3847 // Update all frame positions to the new fps value
3848 //WARNING: there are probably some effects or other that hold a frame value
3849 // as parameter and will also need to be updated here!
3851 doc.setContent(scene);
3853 double factor = new_fps / current_fps;
3854 QDomNodeList producers = doc.elementsByTagName("producer");
3855 for (int i = 0; i < producers.count(); i++) {
3856 QDomElement prod = producers.at(i).toElement();
3857 prod.removeAttribute("in");
3858 prod.removeAttribute("out");
3860 QDomNodeList props = prod.childNodes();
3861 for (int j = 0; j < props.count(); j++) {
3862 QDomElement param = props.at(j).toElement();
3863 QString paramName = param.attribute("name");
3864 if (paramName.startsWith("meta.") || paramName == "length") {
3865 prod.removeChild(props.at(j));
3871 QDomNodeList entries = doc.elementsByTagName("entry");
3872 for (int i = 0; i < entries.count(); i++) {
3873 QDomElement entry = entries.at(i).toElement();
3874 int in = entry.attribute("in").toInt();
3875 int out = entry.attribute("out").toInt();
3876 in = factor * in + 0.5;
3877 out = factor * out + 0.5;
3878 entry.setAttribute("in", in);
3879 entry.setAttribute("out", out);
3882 QDomNodeList blanks = doc.elementsByTagName("blank");
3883 for (int i = 0; i < blanks.count(); i++) {
3884 QDomElement blank = blanks.at(i).toElement();
3885 int length = blank.attribute("length").toInt();
3886 length = factor * length + 0.5;
3887 blank.setAttribute("length", QString::number(length));
3890 QDomNodeList filters = doc.elementsByTagName("filter");
3891 for (int i = 0; i < filters.count(); i++) {
3892 QDomElement filter = filters.at(i).toElement();
3893 int in = filter.attribute("in").toInt();
3894 int out = filter.attribute("out").toInt();
3895 in = factor * in + 0.5;
3896 out = factor * out + 0.5;
3897 filter.setAttribute("in", in);
3898 filter.setAttribute("out", out);
3901 QDomNodeList transitions = doc.elementsByTagName("transition");
3902 for (int i = 0; i < transitions.count(); i++) {
3903 QDomElement transition = transitions.at(i).toElement();
3904 int in = transition.attribute("in").toInt();
3905 int out = transition.attribute("out").toInt();
3906 in = factor * in + 0.5;
3907 out = factor * out + 0.5;
3908 transition.setAttribute("in", in);
3909 transition.setAttribute("out", out);
3910 QDomNodeList props = transition.childNodes();
3911 for (int j = 0; j < props.count(); j++) {
3912 QDomElement param = props.at(j).toElement();
3913 QString paramName = param.attribute("name");
3914 if (paramName == "geometry") {
3915 QString geom = param.firstChild().nodeValue();
3916 QStringList keys = geom.split(';');
3917 QStringList newKeys;
3918 for (int k = 0; k < keys.size(); ++k) {
3919 if (keys.at(k).contains('=')) {
3920 int pos = keys.at(k).section('=', 0, 0).toInt();
3921 pos = factor * pos + 0.5;
3922 newKeys.append(QString::number(pos) + '=' + keys.at(k).section('=', 1));
3923 } else newKeys.append(keys.at(k));
3925 param.firstChild().setNodeValue(newKeys.join(";"));
3929 QDomElement tractor = doc.elementsByTagName("tractor").at(0).toElement();
3930 int out = tractor.attribute("out").toInt();
3931 out = factor * out + 0.5;
3932 tractor.setAttribute("out", out);
3933 emit durationChanged(out);
3935 //kDebug() << "///////////////////////////// " << out << " \n" << doc.toString() << "\n-------------------------";
3936 return doc.toString();
3940 void Render::sendFrameUpdate()
3942 if (m_mltProducer) {
3943 Mlt::Frame * frame = m_mltProducer->get_frame();
3944 emitFrameUpdated(*frame);
3950 #include "renderer.moc"