X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderer.cpp;h=110f4122c6fa6713b054e7b6905e19e4e048edb2;hb=05d5da65489ab125958e4f62ded8987bcf4989aa;hp=581adff37320c2b70f5ddc26043dc656f5480a1b;hpb=d0070c8b69f037794945fbca8ea856aa592eea1a;p=kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp index 581adff3..110f4122 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -22,23 +22,6 @@ * * ***************************************************************************/ -// ffmpeg Header files - -extern "C" { -#include -} - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include #include "renderer.h" #include "kdenlivesettings.h" @@ -47,15 +30,21 @@ extern "C" { #include -#if LIBAVCODEC_VERSION_MAJOR > 51 || (LIBAVCODEC_VERSION_MAJOR > 50 && LIBAVCODEC_VERSION_MINOR > 54) -// long_name was added in FFmpeg avcodec version 51.55 -#define ENABLE_FFMPEG_CODEC_DESCRIPTION 1 -#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include -static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) { - // detect if the producer has finished playing. Is there a better way to do it ? +static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr) +{ + // detect if the producer has finished playing. Is there a better way to do it? if (self->m_isBlocked) return; if (mlt_properties_get_double(MLT_FRAME_PROPERTIES(frame_ptr), "_speed") == 0.0) { self->emitConsumerStopped(); @@ -64,52 +53,64 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr } } -Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(winid), m_externalwinid(extid), m_framePosition(0), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false), m_isZoneMode(false), m_isLoopMode(false) { +Render::Render(const QString & rendererName, int winid, int /* extid */, QWidget *parent) : + QObject(parent), + m_isBlocked(true), + m_name(rendererName), + m_mltConsumer(NULL), + m_mltProducer(NULL), + m_framePosition(0), + m_isZoneMode(false), + m_isLoopMode(false), + m_isSplitView(false), + m_blackClip(NULL), + m_winid(winid) +{ kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data(); - refreshTimer = new QTimer(this); - connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); + m_refreshTimer = new QTimer(this); + connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); /*if (rendererName == "project") m_monitorId = 10000; else m_monitorId = 10001;*/ - osdTimer = new QTimer(this); - connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout())); + m_osdTimer = new QTimer(this); + connect(m_osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout())); - m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties"); buildConsumer(); - Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black"); - m_mltProducer = producer; - if (m_blackClip) delete m_blackClip; - m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black"); - m_blackClip->set("id", "black"); + m_mltProducer = m_blackClip->cut(0, 50); m_mltConsumer->connect(*m_mltProducer); m_mltProducer->set_speed(0.0); } -Render::~Render() { +Render::~Render() +{ closeMlt(); } -void Render::closeMlt() { - delete osdTimer; - delete refreshTimer; - if (m_mltConsumer) - delete m_mltConsumer; - if (m_mltProducer) - delete m_mltProducer; - if (m_blackClip) delete m_blackClip; +void Render::closeMlt() +{ + delete m_osdTimer; + delete m_refreshTimer; + delete m_mltConsumer; + delete m_mltProducer; + delete m_blackClip; //delete m_osdInfo; } -void Render::buildConsumer() { +void Render::buildConsumer() +{ char *tmp; - tmp = decodedString(KdenliveSettings::current_profile()); + m_activeProfile = KdenliveSettings::current_profile(); + tmp = decodedString(m_activeProfile); + setenv("MLT_PROFILE", tmp, 1); + delete m_blackClip; + m_blackClip = NULL; + m_mltProfile = new Mlt::Profile(tmp); delete[] tmp; - QString videoDriver = KdenliveSettings::videodrivername(); if (!videoDriver.isEmpty()) { if (videoDriver == "x11_noaccel") { @@ -125,7 +126,11 @@ void Render::buildConsumer() { m_mltConsumer->set("resize", 1); m_mltConsumer->set("window_id", m_winid); m_mltConsumer->set("terminate_on_pause", 1); - //m_mltConsumer->set("fullscreen", 1); + tmp = decodedString(KdenliveSettings::window_background().name()); + m_mltConsumer->set("window_background", tmp); + delete [] tmp; + + // FIXME: the event object returned by the listen gets leaked... m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); m_mltConsumer->set("rescale", "nearest"); @@ -153,39 +158,50 @@ void Render::buildConsumer() { m_mltConsumer->set("progressive", 1); m_mltConsumer->set("audio_buffer", 1024); m_mltConsumer->set("frequency", 48000); + + m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black"); + m_blackClip->set("id", "black"); + } -int Render::resetProfile() { +int Render::resetProfile() +{ if (!m_mltConsumer) return 0; - QString currentProfile = getenv("MLT_PROFILE"); - if (currentProfile == KdenliveSettings::current_profile()) { + if (m_activeProfile == KdenliveSettings::current_profile()) { kDebug() << "reset to same profile, nothing to do"; return 1; } + kDebug() << "// RESETTING PROFILE FROM: " << m_activeProfile << " TO: " << KdenliveSettings::current_profile(); if (m_isSplitView) slotSplitView(false); if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); m_mltConsumer->purge(); delete m_mltConsumer; m_mltConsumer = NULL; QString scene = sceneList(); - if (m_mltProducer) delete m_mltProducer; + int pos = 0; + if (m_mltProducer) { + pos = m_mltProducer->position(); + delete m_mltProducer; + } m_mltProducer = NULL; - if (m_mltProfile) delete m_mltProfile; - m_mltProfile = NULL; + + //WARNING: Trying to delete the profile will crash when trying to display a clip afterwards... + /*if (m_mltProfile) delete m_mltProfile; + m_mltProfile = NULL;*/ + buildConsumer(); //kDebug() << "//RESET WITHSCENE: " << scene; - setSceneList(scene); + setSceneList(scene, pos); - char *tmp = decodedString(scene); + /*char *tmp = decodedString(scene); Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp); delete[] tmp; m_mltProducer = producer; - if (m_blackClip) delete m_blackClip; m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black"); m_mltProducer->optimise(); m_mltProducer->set_speed(0); - connectPlaylist(); + connectPlaylist();*/ //delete m_mltProfile; // mlt_properties properties = MLT_CONSUMER_PROPERTIES(m_mltConsumer->get_consumer()); @@ -201,7 +217,8 @@ int Render::resetProfile() { } /** Wraps the VEML command of the same name; Seeks the renderer clip to the given time. */ -void Render::seek(GenTime time) { +void Render::seek(GenTime time) +{ if (!m_mltProducer) return; m_isBlocked = false; @@ -210,7 +227,8 @@ void Render::seek(GenTime time) { } //static -char *Render::decodedString(QString str) { +char *Render::decodedString(QString str) +{ /*QCString fn = QFile::encodeName(str); char *t = new char[fn.length() + 1]; strcpy(t, (const char *)fn);*/ @@ -236,15 +254,18 @@ char *Render::decodedString(QString str) { return pix; } */ -const int Render::renderWidth() const { +int Render::renderWidth() const +{ return (int)(m_mltProfile->height() * m_mltProfile->dar()); } -const int Render::renderHeight() const { +int Render::renderHeight() const +{ return m_mltProfile->height(); } -QPixmap Render::extractFrame(int frame_position, int width, int height) { +QPixmap Render::extractFrame(int frame_position, int width, int height) +{ if (width == -1) { width = renderWidth(); height = renderHeight(); @@ -257,7 +278,8 @@ QPixmap Render::extractFrame(int frame_position, int width, int height) { return KThumb::getFrame(m_mltProducer, frame_position, width, height); } -QPixmap Render::getImageThumbnail(KUrl url, int width, int height) { +QPixmap Render::getImageThumbnail(KUrl url, int /*width*/, int /*height*/) +{ QImage im; QPixmap pixmap; if (url.fileName().startsWith(".all.")) { // check for slideshow @@ -270,7 +292,7 @@ QPixmap Render::getImageThumbnail(KUrl url, int width, int height) { filter << "*." + fileType; filter << "*." + fileType.toUpper(); more = dir.entryList(filter, QDir::Files); - im.load(url.directory() + "/" + more.at(0)); + im.load(url.directory() + '/' + more.at(0)); } else im.load(url.path()); //pixmap = im.scaled(width, height); return pixmap; @@ -352,8 +374,8 @@ void Render::getImage(KUrl url, int frame_position, QPoint size) more = dir.entryList( QDir::Files ); for ( it = more.begin() ; it != more.end() ; ++it ) { if ((*it).endsWith("."+fileType, Qt::CaseInsensitive)) { - if (!im.load(url.directory() + "/" + *it)) - kDebug()<<"++ ERROR LOADIN IMAGE: "<get_double("aspect_ratio_num") / m_mltConsumer->get_double("aspect_ratio_den")); } -int Render::getLength() { +int Render::getLength() +{ if (m_mltProducer) { // kDebug()<<"////// LENGTH: "<get_producer()); @@ -383,7 +407,8 @@ int Render::getLength() { return 0; } -bool Render::isValid(KUrl url) { +bool Render::isValid(KUrl url) +{ char *tmp = decodedString(url.path()); Mlt::Producer producer(*m_mltProfile, tmp); delete[] tmp; @@ -393,11 +418,13 @@ bool Render::isValid(KUrl url) { return true; } -const double Render::dar() const { +double Render::dar() const +{ return m_mltProfile->dar(); } -void Render::slotSplitView(bool doit) { +void Render::slotSplitView(bool doit) +{ m_isSplitView = doit; Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); @@ -428,6 +455,7 @@ void Render::slotSplitView(bool doit) { tmp = "0,50%:50%x50%"; break; case 3: + default: tmp = "50%,50%:50%x50%"; break; } @@ -461,16 +489,12 @@ void Render::slotSplitView(bool doit) { } } -void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { - int height = 50; - int width = (int)(height * m_mltProfile->dar()); - QMap < QString, QString > filePropertyMap; - QMap < QString, QString > metadataPropertyMap; - - KUrl url = KUrl(xml.attribute("resource", QString::null)); +void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer) +{ + KUrl url = KUrl(xml.attribute("resource", QString())); Mlt::Producer *producer = NULL; if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) { - emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap); + emit replyGetFileProperties(clipId, producer, QMap < QString, QString >(), QMap < QString, QString >(), replaceProducer); return; } if (xml.attribute("type").toInt() == COLOR) { @@ -488,51 +512,48 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { producer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp); delete[] tmp; } else { - QString urlpath = url.path(); - /*if (urlpath.contains(':')) { - if (!urlpath.startsWith("file:")) urlpath.prepend("file:"); - char *tmp = decodedString(urlpath); - producer = new Mlt::Producer(*m_mltProfile, "avformat", tmp); - delete[] tmp; - } - else {*/ - char *tmp = decodedString(urlpath); + char *tmp = decodedString(url.path()); producer = new Mlt::Producer(*m_mltProfile, tmp); delete[] tmp; - - if (xml.hasAttribute("force_aspect_ratio")) { - double aspect = xml.attribute("force_aspect_ratio").toDouble(); - if (aspect > 0) producer->set("force_aspect_ratio", aspect); - } - if (xml.hasAttribute("threads")) { - int threads = xml.attribute("threads").toInt(); - if (threads != 1) producer->set("threads", threads); - } - if (xml.hasAttribute("video_index")) { - int vindex = xml.attribute("video_index").toInt(); - if (vindex != 0) producer->set("video_index", vindex); - } - if (xml.hasAttribute("audio_index")) { - int aindex = xml.attribute("audio_index").toInt(); - if (aindex != 0) producer->set("audio_index", aindex); - } - //} } if (producer == NULL || producer->is_blank() || !producer->is_valid()) { - kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: "; - emit removeInvalidClip(clipId); + kDebug() << " / / / / / / / / ERROR / / / / // CANNOT LOAD PRODUCER: "; + emit removeInvalidClip(clipId, replaceProducer); + delete producer; return; } + if (xml.hasAttribute("force_aspect_ratio")) { + double aspect = xml.attribute("force_aspect_ratio").toDouble(); + if (aspect > 0) producer->set("force_aspect_ratio", aspect); + } + if (xml.hasAttribute("threads")) { + int threads = xml.attribute("threads").toInt(); + if (threads != 1) producer->set("threads", threads); + } + if (xml.hasAttribute("video_index")) { + int vindex = xml.attribute("video_index").toInt(); + if (vindex != 0) producer->set("video_index", vindex); + } + if (xml.hasAttribute("audio_index")) { + int aindex = xml.attribute("audio_index").toInt(); + if (aindex != 0) producer->set("audio_index", aindex); + } + if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt()); char *tmp = decodedString(clipId); producer->set("id", tmp); delete[] tmp; + + int height = 50; + int width = (int)(height * m_mltProfile->dar()); + QMap < QString, QString > filePropertyMap; + QMap < QString, QString > metadataPropertyMap; + int frameNumber = xml.attribute("thumbnail", "0").toInt(); if (frameNumber != 0) producer->seek(frameNumber); - mlt_properties properties = MLT_PRODUCER_PROPERTIES(producer->get_producer()); filePropertyMap["duration"] = QString::number(producer->get_playtime()); //kDebug() << "/////// PRODUCER: " << url.path() << " IS: " << producer.get_playtime(); @@ -544,19 +565,21 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { if (xml.attribute("fade") == "1") { // user wants a fade effect to slideshow Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, "luma"); - if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1); - if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt()); - if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) { - char *tmp = decodedString(xml.attribute("luma_file")); - filter->set("luma.resource", tmp); - delete[] tmp; - if (xml.hasAttribute("softness")) { - int soft = xml.attribute("softness").toInt(); - filter->set("luma.softness", (double) soft / 100.0); + if (filter && filter->is_valid()) { + if (xml.hasAttribute("ttl")) filter->set("period", xml.attribute("ttl").toInt() - 1); + if (xml.hasAttribute("luma_duration") && !xml.attribute("luma_duration").isEmpty()) filter->set("luma.out", xml.attribute("luma_duration").toInt()); + if (xml.hasAttribute("luma_file") && !xml.attribute("luma_file").isEmpty()) { + char *tmp = decodedString(xml.attribute("luma_file")); + filter->set("luma.resource", tmp); + delete[] tmp; + if (xml.hasAttribute("softness")) { + int soft = xml.attribute("softness").toInt(); + filter->set("luma.softness", (double) soft / 100.0); + } } + Mlt::Service clipService(producer->get_service()); + clipService.attach(*filter); } - Mlt::Service clipService(producer->get_service()); - clipService.attach(*filter); } } @@ -564,7 +587,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { filePropertyMap["fps"] = producer->get("source_fps"); if (frame && frame->is_valid()) { - filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + "x" + QString::number(frame->get_int("height")); + filePropertyMap["frame_size"] = QString::number(frame->get_int("width")) + 'x' + QString::number(frame->get_int("height")); filePropertyMap["frequency"] = QString::number(frame->get_int("frequency")); filePropertyMap["channels"] = QString::number(frame->get_int("channels")); filePropertyMap["aspect_ratio"] = frame->get("aspect_ratio"); @@ -572,7 +595,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { if (frame->get_int("test_image") == 0) { if (url.path().endsWith(".westley") || url.path().endsWith(".kdenlive")) { filePropertyMap["type"] = "playlist"; - metadataPropertyMap["comment"] = QString::fromUtf8(mlt_properties_get(MLT_SERVICE_PROPERTIES(producer->get_service()), "title")); + metadataPropertyMap["comment"] = QString::fromUtf8(producer->get("title")); } else if (frame->get_int("test_audio") == 0) filePropertyMap["type"] = "av"; else @@ -597,105 +620,104 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { pix.fill(Qt::black); mlt_pool_release(new_image); - emit replyGetImage(clipId, 0, pix, width, height); + emit replyGetImage(clipId, pix); } else if (frame->get_int("test_audio") == 0) { QPixmap pixmap = KIcon("audio-x-generic").pixmap(QSize(width, height)); - emit replyGetImage(clipId, 0, pixmap, width, height); + emit replyGetImage(clipId, pixmap); filePropertyMap["type"] = "audio"; } } // Retrieve audio / video codec name - // Fetch the video_context -#if 1 - - AVFormatContext *context = (AVFormatContext *) mlt_properties_get_data(properties, "video_context", NULL); - if (context != NULL) { + // If there is a + char property[200]; + if (producer->get_int("video_index") > -1) { /*if (context->duration == AV_NOPTS_VALUE) { - kDebug() << " / / / / / / / /ERRROR / / / CLIP HAS UNKNOWN DURATION"; + kDebug() << " / / / / / / / /ERROR / / / CLIP HAS UNKNOWN DURATION"; emit removeInvalidClip(clipId); + delete producer; return; }*/ // Get the video_index - int index = mlt_properties_get_int(properties, "video_index"); - int default_video = -1; + int default_video = producer->get_int("video_index"); int video_max = 0; - int default_audio = -1; + int default_audio = producer->get_int("audio_index"); int audio_max = 0; - // Find default audio stream (borrowed from MLT) - for (int ix = 0; ix < context->nb_streams; ix++) { - // Get the codec context - AVCodecContext *codec_context = context->streams[ ix ]->codec; - - if (avcodec_find_decoder(codec_context->codec_id) == NULL) - continue; - // Determine the type and obtain the first index of each type - switch (codec_context->codec_type) { - case CODEC_TYPE_VIDEO: - if (default_video < 0) default_video = ix; + + // Find maximum stream index values + for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ix++) { + snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix); + QString type = producer->get(property); + if (type == "video") video_max = ix; - break; - case CODEC_TYPE_AUDIO: - if (default_audio < 0) default_audio = ix; + else if (type == "audio") audio_max = ix; - break; - default: - break; - } } filePropertyMap["default_video"] = QString::number(default_video); filePropertyMap["video_max"] = QString::number(video_max); filePropertyMap["default_audio"] = QString::number(default_audio); filePropertyMap["audio_max"] = QString::number(audio_max); + snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", default_video); + if (producer->get(property)) { + filePropertyMap["videocodec"] = producer->get(property); + } else { + snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video); + if (producer->get(property)) + filePropertyMap["videocodec"] = producer->get(property); + } -#if ENABLE_FFMPEG_CODEC_DESCRIPTION - if (index > -1 && context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) { - filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->long_name; - } else -#endif - if (index > -1 && context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) { - filePropertyMap["videocodec"] = context->streams[ index ]->codec->codec->name; + if (KdenliveSettings::dropbframes()) { + kDebug() << "// LOOKING FOR H264 on: " << default_video; + snprintf(property, sizeof(property), "meta.media.%d.codec.name", default_video); + kDebug() << "PROP: " << property << " = " << producer->get(property); + if (producer->get(property) && strcmp(producer->get(property), "h264") == 0) { + kDebug() << "// GOT H264 CLIP, SETTING FAST PROPS"; + producer->set("skip_loop_filter", "all"); + producer->set("skip_frame", "bidir"); } + } + } else kDebug() << " / / / / /WARNING, VIDEO CONTEXT IS NULL!!!!!!!!!!!!!!"; - context = (AVFormatContext *) mlt_properties_get_data(properties, "audio_context", NULL); - if (context != NULL) { + if (producer->get_int("audio_index") > -1) { // Get the audio_index - int index = mlt_properties_get_int(properties, "audio_index"); + int index = producer->get_int("audio_index"); -#if ENABLE_FFMPEG_CODEC_DESCRIPTION - if (index > -1 && context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->long_name) - filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->long_name; - else -#endif - if (index > -1 && context->streams && context->streams [index] && context->streams[ index ]->codec && context->streams[ index ]->codec->codec->name) - filePropertyMap["audiocodec"] = context->streams[ index ]->codec->codec->name; + snprintf(property, sizeof(property), "meta.media.%d.codec.long_name", index); + if (producer->get(property)) { + filePropertyMap["audiocodec"] = producer->get(property); + } else { + snprintf(property, sizeof(property), "meta.media.%d.codec.name", index); + if (producer->get(property)) + filePropertyMap["audiocodec"] = producer->get(property); + } } -#endif - // metadata - mlt_properties metadata = mlt_properties_new(); - mlt_properties_pass(metadata, properties, "meta.attr."); - int count = mlt_properties_count(metadata); + // metadata + Mlt::Properties metadata; + metadata.pass_values(*producer, "meta.attr."); + int count = metadata.count(); for (int i = 0; i < count; i ++) { - QString name = mlt_properties_get_name(metadata, i); - QString value = QString::fromUtf8(mlt_properties_get_value(metadata, i)); + QString name = metadata.get_name(i); + QString value = QString::fromUtf8(metadata.get(i)); if (name.endsWith("markup") && !value.isEmpty()) - metadataPropertyMap[ name.section(".", 0, -2)] = value; + metadataPropertyMap[ name.section('.', 0, -2)] = value; } - emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap); + emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer); kDebug() << "REquested fuile info for: " << url.path(); - if (frame) delete frame; - //if (producer) delete producer; + delete frame; + // FIXME: should delete this to avoid a leak... + //delete producer; } /** Create the producer from the Westley QDomDocument */ #if 0 -void Render::initSceneList() { +void Render::initSceneList() +{ kDebug() << "-------- INIT SCENE LIST ------_"; QDomDocument doc; QDomElement westley = doc.createElement("westley"); @@ -733,13 +755,16 @@ void Render::initSceneList() { /** Create the producer from the Westley QDomDocument */ -void Render::setProducer(Mlt::Producer *producer, int position) { +void Render::setProducer(Mlt::Producer *producer, int position) +{ if (m_winid == -1) return; if (m_mltConsumer) { m_mltConsumer->stop(); } else return; + m_mltConsumer->purge(); + m_isBlocked = true; if (m_mltProducer) { m_mltProducer->set_speed(0); @@ -747,8 +772,13 @@ void Render::setProducer(Mlt::Producer *producer, int position) { m_mltProducer = NULL; emit stopped(); } - if (producer) m_mltProducer = new Mlt::Producer(producer->get_producer()); - else m_mltProducer = new Mlt::Producer(); + if (producer) { + m_mltProducer = new Mlt::Producer(producer->get_producer()); + } else m_mltProducer = m_blackClip->cut(0, 50); + /*if (KdenliveSettings::dropbframes()) { + m_mltProducer->set("skip_loop_filter", "all"); + m_mltProducer->set("skip_frame", "bidir"); + }*/ if (!m_mltProducer || !m_mltProducer->is_valid()) kDebug() << " WARNING - - - - -INVALID PLAYLIST: "; m_fps = m_mltProducer->get_fps(); @@ -763,14 +793,18 @@ void Render::setProducer(Mlt::Producer *producer, int position) { /** Create the producer from the Westley QDomDocument */ -void Render::setSceneList(QDomDocument list, int position) { +void Render::setSceneList(QDomDocument list, int position) +{ setSceneList(list.toString(), position); } /** Create the producer from the Westley QDomDocument */ -void Render::setSceneList(QString playlist, int position) { +void Render::setSceneList(QString playlist, int position) +{ if (m_winid == -1) return; m_isBlocked = true; + qDeleteAll(m_slowmotionProducers.values()); + m_slowmotionProducers.clear(); //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist; @@ -794,13 +828,13 @@ void Render::setSceneList(QString playlist, int position) { blockSignals(true); char *tmp = decodedString(playlist); m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp); - delete[] tmp; - if (m_blackClip) delete m_blackClip; - m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black"); - m_blackClip->set("id", "black"); + if (!m_mltProducer || !m_mltProducer->is_valid()) { kDebug() << " WARNING - - - - -INVALID PLAYLIST: " << tmp; + m_mltProducer = m_blackClip->cut(0, 50); } + delete[] tmp; + m_mltProducer->optimise(); /*if (KdenliveSettings::osdtimecode()) { @@ -829,6 +863,7 @@ void Render::setSceneList(QString playlist, int position) { m_fps = m_mltProducer->get_fps(); kDebug() << "// NEW SCENE LIST DURATION SET TO: " << m_mltProducer->get_playtime(); connectPlaylist(); + fillSlowMotionProducers(); if (position != 0) { //TODO: seek to correct place after opening project. // Needs to be done from another place since it crashes here. @@ -836,11 +871,14 @@ void Render::setSceneList(QString playlist, int position) { } m_isBlocked = false; blockSignals(false); - emit rendererPosition(position); + emit refreshDocumentProducers(); + //kDebug()<<"// SETSCN LST, POS: "<optimise(); @@ -856,7 +894,8 @@ QString Render::sceneList() { return playlist; } -void Render::saveSceneList(QString path, QDomElement kdenliveData) { +bool Render::saveSceneList(QString path, QDomElement kdenliveData) +{ QFile file(path); QDomDocument doc; doc.setContent(sceneList(), false); @@ -867,15 +906,20 @@ void Render::saveSceneList(QString path, QDomElement kdenliveData) { } if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { kWarning() << "////// ERROR writing to file: " << path; - return; + return false; + } + file.write(doc.toString().toUtf8()); + if (file.error() != QFile::NoError) { + file.close(); + return false; } - QTextStream out(&file); - out << doc.toString(); file.close(); + return true; } -void Render::saveZone(KUrl url, QString desc, QPoint zone) { +void Render::saveZone(KUrl url, QString desc, QPoint zone) +{ kDebug() << "// SAVING CLIP ZONE, RENDER: " << m_name; char *tmppath = decodedString("westley:" + url.path()); Mlt::Consumer westleyConsumer(*m_mltProfile , tmppath); @@ -907,11 +951,13 @@ void Render::saveZone(KUrl url, QString desc, QPoint zone) { westleyConsumer.start(); } -const double Render::fps() const { +double Render::fps() const +{ return m_fps; } -void Render::connectPlaylist() { +void Render::connectPlaylist() +{ if (!m_mltConsumer) return; //m_mltConsumer->set("refresh", "0"); m_mltConsumer->connect(*m_mltProducer); @@ -922,6 +968,7 @@ void Render::connectPlaylist() { /* if (m_mltConsumer->start() == -1) { 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.")); + delete m_mltConsumer; m_mltConsumer = NULL; } else { @@ -929,12 +976,13 @@ void Render::connectPlaylist() { }*/ } -void Render::refreshDisplay() { +void Render::refreshDisplay() +{ if (!m_mltProducer) return; //m_mltConsumer->set("refresh", 0); - mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); + //mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); /*if (KdenliveSettings::osdtimecode()) { mlt_properties_set_int( properties, "meta.attr.timecode", 1); mlt_properties_set( properties, "meta.attr.timecode.markup", "#timecode#"); @@ -948,7 +996,8 @@ void Render::refreshDisplay() { refresh(); } -void Render::setVolume(double volume) { +void Render::setVolume(double /*volume*/) +{ if (!m_mltConsumer || !m_mltProducer) return; /*osdTimer->stop(); m_mltConsumer->set("refresh", 0); @@ -964,10 +1013,11 @@ void Render::setVolume(double volume) { if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter"; }*/ refresh(); - osdTimer->setSingleShot(2500); + m_osdTimer->setSingleShot(2500); } -void Render::slotOsdTimeout() { +void Render::slotOsdTimeout() +{ mlt_properties properties = MLT_PRODUCER_PROPERTIES(m_mltProducer->get_producer()); mlt_properties_set_int(properties, "meta.attr.osdvolume", 0); mlt_properties_set(properties, "meta.attr.osdvolume.markup", NULL); @@ -975,7 +1025,8 @@ void Render::slotOsdTimeout() { refresh(); } -void Render::start() { +void Render::start() +{ kDebug() << "----- STARTING MONITOR: " << m_name; if (m_winid == -1) { kDebug() << "----- BROKEN MONITOR: " << m_name << ", RESTART"; @@ -986,6 +1037,7 @@ void Render::start() { kDebug() << "----- MONITOR: " << m_name << " WAS STOPPED"; if (m_mltConsumer->start() == -1) { 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.")); + delete m_mltConsumer; m_mltConsumer = NULL; return; } else { @@ -997,7 +1049,8 @@ void Render::start() { m_isBlocked = false; } -void Render::clear() { +void Render::clear() +{ kDebug() << " ********* RENDER CLEAR"; if (m_mltConsumer) { //m_mltConsumer->set("refresh", 0); @@ -1013,11 +1066,12 @@ void Render::clear() { } } -void Render::stop() { +void Render::stop() +{ if (m_mltConsumer && !m_mltConsumer->is_stopped()) { kDebug() << "///////////// RENDER STOPPED: " << m_name; m_isBlocked = true; - m_mltConsumer->set("refresh", 0); + //m_mltConsumer->set("refresh", 0); m_mltConsumer->stop(); // delete m_mltConsumer; // m_mltConsumer = NULL; @@ -1034,7 +1088,8 @@ void Render::stop() { kDebug() << "///////////// RENDER STOP3-------"; } -void Render::stop(const GenTime & startTime) { +void Render::stop(const GenTime & startTime) +{ kDebug() << "///////////// RENDER STOP-------2"; if (m_mltProducer) { @@ -1045,7 +1100,8 @@ void Render::stop(const GenTime & startTime) { m_mltConsumer->purge(); } -void Render::pause() { +void Render::pause() +{ if (!m_mltProducer || !m_mltConsumer) return; if (m_mltProducer->get_speed() == 0.0) return; @@ -1058,7 +1114,8 @@ void Render::pause() { m_mltConsumer->purge(); } -void Render::switchPlay() { +void Render::switchPlay() +{ if (!m_mltProducer || !m_mltConsumer) return; if (m_isZoneMode) resetZoneMode(); @@ -1088,7 +1145,8 @@ void Render::switchPlay() { //refresh(); } -void Render::play(double speed) { +void Render::play(double speed) +{ if (!m_mltProducer) return; // if (speed == 0.0) m_mltProducer->set("out", m_mltProducer->get_length() - 1); @@ -1101,7 +1159,8 @@ void Render::play(double speed) { refresh(); } -void Render::play(const GenTime & startTime) { +void Render::play(const GenTime & startTime) +{ if (!m_mltProducer || !m_mltConsumer) return; m_isBlocked = false; @@ -1110,7 +1169,8 @@ void Render::play(const GenTime & startTime) { m_mltConsumer->set("refresh", 1); } -void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) { +void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) +{ if (!m_mltProducer || !m_mltConsumer) return; //m_mltProducer->set("eof", "loop"); @@ -1119,10 +1179,12 @@ void Render::loopZone(const GenTime & startTime, const GenTime & stopTime) { playZone(startTime, stopTime); } -void Render::playZone(const GenTime & startTime, const GenTime & stopTime) { +void Render::playZone(const GenTime & startTime, const GenTime & stopTime) +{ if (!m_mltProducer || !m_mltConsumer) return; m_isBlocked = false; + if (!m_isZoneMode) m_originalOut = m_mltProducer->get_playtime() - 1; m_mltProducer->set("out", stopTime.frames(m_fps)); m_mltProducer->seek((int)(startTime.frames(m_fps))); m_mltProducer->set_speed(1.0); @@ -1130,14 +1192,17 @@ void Render::playZone(const GenTime & startTime, const GenTime & stopTime) { m_isZoneMode = true; } -void Render::resetZoneMode() { - m_mltProducer->set("out", m_mltProducer->get_length() - 1); +void Render::resetZoneMode() +{ + if (!m_isZoneMode && !m_isLoopMode) return; + m_mltProducer->set("out", m_originalOut); //m_mltProducer->set("eof", "pause"); m_isZoneMode = false; m_isLoopMode = false; } -void Render::seekToFrame(int pos) { +void Render::seekToFrame(int pos) +{ //kDebug()<<" ********* RENDER SEEK TO POS"; if (!m_mltProducer) return; @@ -1147,48 +1212,56 @@ void Render::seekToFrame(int pos) { refresh(); } -void Render::askForRefresh() { +void Render::askForRefresh() +{ // Use a Timer so that we don't refresh too much - refreshTimer->start(200); + m_refreshTimer->start(200); } -void Render::doRefresh() { +void Render::doRefresh() +{ // Use a Timer so that we don't refresh too much if (!m_isBlocked && m_mltConsumer) m_mltConsumer->set("refresh", 1); } -void Render::refresh() { +void Render::refresh() +{ if (!m_mltProducer || m_isBlocked) return; - refreshTimer->stop(); + m_refreshTimer->stop(); if (m_mltConsumer) { m_mltConsumer->set("refresh", 1); } } -double Render::playSpeed() { +double Render::playSpeed() +{ if (m_mltProducer) return m_mltProducer->get_speed(); return 0.0; } -GenTime Render::seekPosition() const { +GenTime Render::seekPosition() const +{ if (m_mltProducer) return GenTime((int) m_mltProducer->position(), m_fps); else return GenTime(); } -const QString & Render::rendererName() const { +const QString & Render::rendererName() const +{ return m_name; } -void Render::emitFrameNumber(double position) { +void Render::emitFrameNumber(double position) +{ m_framePosition = position; emit rendererPosition((int) position); //if (qApp->activeWindow()) QApplication::postEvent(qApp->activeWindow(), new PositionChangeEvent( GenTime((int) position, m_fps), m_monitorId)); } -void Render::emitConsumerStopped() { +void Render::emitConsumerStopped() +{ // This is used to know when the playing stopped if (m_mltProducer) { double pos = m_mltProducer->position(); @@ -1202,19 +1275,21 @@ void Render::emitConsumerStopped() { -void Render::exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime) { +void Render::exportFileToFirewire(QString /*srcFileName*/, int /*port*/, GenTime /*startTime*/, GenTime /*endTime*/) +{ KMessageBox::sorry(0, i18n("Firewire is not enabled on your system.\n Please install Libiec61883 and recompile Kdenlive")); } -void Render::exportCurrentFrame(KUrl url, bool notify) { +void Render::exportCurrentFrame(KUrl url, bool /*notify*/) +{ if (!m_mltProducer) { KMessageBox::sorry(qApp->activeWindow(), i18n("There is no clip, cannot extract frame.")); return; } - int height = 1080;//KdenliveSettings::defaultheight(); - int width = 1940; //KdenliveSettings::displaywidth(); + //int height = 1080;//KdenliveSettings::defaultheight(); + //int width = 1940; //KdenliveSettings::displaywidth(); //TODO: rewrite QPixmap pix; // = KThumb::getFrame(m_mltProducer, -1, width, height); /* @@ -1235,27 +1310,26 @@ void Render::exportCurrentFrame(KUrl url, bool notify) { /** MLT PLAYLIST DIRECT MANIPULATON **/ -void Render::mltCheckLength(bool reload) { +void Render::mltCheckLength() +{ //kDebug()<<"checking track length: "<get_service()); Mlt::Tractor tractor(service); int trackNb = tractor.count(); - double duration = 0; - double trackDuration; + int duration = 0; + int trackDuration; if (trackNb == 1) { Mlt::Producer trackProducer(tractor.track(0)); - Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); - duration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1; + duration = trackProducer.get_playtime() - 1; m_mltProducer->set("out", duration); - emit durationChanged((int) duration); + emit durationChanged(duration); return; } while (trackNb > 1) { Mlt::Producer trackProducer(tractor.track(trackNb - 1)); - Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); - trackDuration = Mlt::Producer(trackPlaylist.get_producer()).get_playtime() - 1; + trackDuration = trackProducer.get_playtime() - 1; //kDebug() << " / / /DURATON FOR TRACK " << trackNb - 1 << " = " << trackDuration; if (trackDuration > duration) duration = trackDuration; @@ -1263,38 +1337,26 @@ void Render::mltCheckLength(bool reload) { } Mlt::Producer blackTrackProducer(tractor.track(0)); - Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service()); - double blackDuration = Mlt::Producer(blackTrackPlaylist.get_producer()).get_playtime() - 1; + int blackDuration = blackTrackProducer.get_playtime() - 1; if (blackDuration != duration) { - blackTrackPlaylist.remove_region(0, (int)blackDuration); - int i = 0; - int dur = (int)duration; - QDomDocument doc; - QDomElement black = doc.createElement("producer"); - black.setAttribute("mlt_service", "colour"); - black.setAttribute("colour", "black"); - black.setAttribute("id", "black"); - ItemInfo info; - info.track = 0; + Mlt::Playlist blackTrackPlaylist((mlt_playlist) blackTrackProducer.get_service()); + blackTrackPlaylist.clear(); + int dur = duration; while (dur > 14000) { - info.startPos = GenTime(i * 14000, m_fps); - info.endPos = info.startPos + GenTime(13999, m_fps); - mltInsertClip(info, black, m_blackClip); + blackTrackPlaylist.append(*m_blackClip, 0, 13999); dur = dur - 14000; - i++; } if (dur > 0) { - info.startPos = GenTime(i * 14000, m_fps); - info.endPos = info.startPos + GenTime(dur, m_fps); - mltInsertClip(info, black, m_blackClip); + blackTrackPlaylist.append(*m_blackClip, 0, dur); } m_mltProducer->set("out", duration); - emit durationChanged((int)duration); + emit durationChanged(duration); } } -void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) { +void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod) +{ if (!m_mltProducer) { kDebug() << "PLAYLIST NOT INITIALISED //////"; return; @@ -1311,6 +1373,28 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr Mlt::Producer trackProducer(tractor.track(info.track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); //kDebug()<<"/// INSERT cLIP: "<get("resource")); + url.append('?' + QString::number(speed)); + Mlt::Producer *slowprod = m_slowmotionProducers.value(url); + if (!slowprod || slowprod->get_producer() == NULL) { + char *tmp = decodedString(url); + slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp); + delete[] tmp; + QString id = prod->get("id"); + if (id.contains('_')) id = id.section('_', 0, 0); + QString producerid = "slowmotion:" + id + ':' + QString::number(speed); + tmp = decodedString(producerid); + slowprod->set("id", tmp); + delete[] tmp; + m_slowmotionProducers.insert(url, slowprod); + } + prod = slowprod; + } + Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1); int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1); @@ -1325,7 +1409,8 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr } -void Render::mltCutClip(int track, GenTime position) { +void Render::mltCutClip(int track, GenTime position) +{ m_isBlocked = true; @@ -1344,7 +1429,7 @@ void Render::mltCutClip(int track, GenTime position) { int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; if (trackPlaylist.is_blank(i)) blk = "(blank)"; - kDebug()<<"CLIP "<get("kdenlive_id") != "") { + // Only duplicate Kdenlive filters, and skip the fade in effects + if (filter->is_valid() && strcmp(filter->get("kdenlive_id"), "") && strcmp(filter->get("kdenlive_id"), "fadein") && strcmp(filter->get("kdenlive_id"), "fade_from_black")) { // looks like there is no easy way to duplicate a filter, // so we will create a new one and duplicate its properties Mlt::Filter *dup = new Mlt::Filter(*m_mltProfile, filter->get("mlt_service")); - Mlt::Properties entries(filter->get_properties()); - for (int i = 0;i < entries.count();i++) { - dup->set(entries.get_name(i), entries.get(i)); + if (dup && dup->is_valid()) { + Mlt::Properties entries(filter->get_properties()); + for (int i = 0;i < entries.count();i++) { + dup->set(entries.get_name(i), entries.get(i)); + } + dupService.attach(*dup); } - dupService.attach(*dup); } ct++; filter = clipService.filter(ct); @@ -1393,20 +1481,22 @@ void Render::mltCutClip(int track, GenTime position) { int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; if (trackPlaylist.is_blank(i)) blk = "(blank)"; - kDebug()<<"CLIP "<parent().get_service()); if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; @@ -1422,7 +1512,7 @@ bool Render::mltRemoveClip(int track, GenTime position) { int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; if (trackPlaylist.is_blank(i)) blk = "(blank)"; - kDebug()<<"CLIP "< clipIndex) mltCheckLength(); + if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(); m_isBlocked = false; return true; } -int Render::mltGetSpaceLength(const GenTime pos, int track) { +int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) +{ if (!m_mltProducer) { kDebug() << "PLAYLIST NOT INITIALISED //////"; return -1; @@ -1469,12 +1560,32 @@ int Render::mltGetSpaceLength(const GenTime pos, int track) { Mlt::Producer trackProducer(tractor.track(track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); int clipIndex = trackPlaylist.get_clip_index_at(insertPos); - if (!trackPlaylist.is_blank_at(clipIndex)) return -1; - return trackPlaylist.clip_length(clipIndex); + if (!trackPlaylist.is_blank(clipIndex)) return -1; + if (fromBlankStart) return trackPlaylist.clip_length(clipIndex); + return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos; } +int Render::mltTrackDuration(int track) +{ + if (!m_mltProducer) { + kDebug() << "PLAYLIST NOT INITIALISED //////"; + return -1; + } + Mlt::Producer parentProd(m_mltProducer->parent()); + if (parentProd.get_producer() == NULL) { + kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////"; + return -1; + } + + Mlt::Service service(parentProd.get_service()); + Mlt::Tractor tractor(service); + + Mlt::Producer trackProducer(tractor.track(track)); + return trackProducer.get_playtime() - 1; +} -void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration) { +void Render::mltInsertSpace(QMap trackClipStartList, QMap trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) +{ if (!m_mltProducer) { kDebug() << "PLAYLIST NOT INITIALISED //////"; return; @@ -1484,25 +1595,33 @@ void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////"; return; } + //kDebug()<<"// CLP STRT LST: "< 0) trackPlaylist.insert_blank(clipIndex, diff - 1); - else { - int position = trackPlaylist.clip_start(clipIndex); - trackPlaylist.remove_region(position, -diff - 1); + insertPos = trackClipStartList.value(track); + if (insertPos != -1) { + insertPos += offset; + int clipIndex = trackPlaylist.get_clip_index_at(insertPos); + if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1); + else { + if (!trackPlaylist.is_blank(clipIndex)) clipIndex --; + if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos; + int position = trackPlaylist.clip_start(clipIndex); + trackPlaylist.remove_region(position, - diff - 1); + } + trackPlaylist.consolidate_blanks(0); } - trackPlaylist.consolidate_blanks(0); - // now move transitions mlt_service serv = m_mltProducer->parent().get_service(); mlt_service nextservice = mlt_service_get_producer(serv); @@ -1515,9 +1634,12 @@ void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration int currentTrack = mlt_transition_get_b_track(tr); int currentIn = (int) mlt_transition_get_in(tr); int currentOut = (int) mlt_transition_get_out(tr); - - if (track == currentTrack && currentOut > insertPos && resource != "mix") { - mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff); + insertPos = trackTransitionStartList.value(track); + if (insertPos != -1) { + insertPos += offset; + if (track == currentTrack && currentOut > insertPos && resource != "mix") { + mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff); + } } nextservice = mlt_service_producer(nextservice); if (nextservice == NULL) break; @@ -1530,13 +1652,33 @@ void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration while (trackNb > 1) { Mlt::Producer trackProducer(tractor.track(trackNb - 1)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); - int clipIndex = trackPlaylist.get_clip_index_at(insertPos); - if (diff > 0) trackPlaylist.insert_blank(clipIndex, diff - 1); - else { - int position = trackPlaylist.clip_start(clipIndex); - trackPlaylist.remove_region(position, -diff - 1); + + + //int clipNb = trackPlaylist.count(); + insertPos = trackClipStartList.value(trackNb - 1); + if (insertPos != -1) { + insertPos += offset; + + /* kDebug()<<"-------------\nTRACK "< 0) trackPlaylist.insert_blank(clipIndex, diff - 1); + else { + if (!trackPlaylist.is_blank(clipIndex)) clipIndex --; + if (!trackPlaylist.is_blank(clipIndex)) kDebug() << "//// ERROR TRYING TO DELETE SPACE FROM " << insertPos; + int position = trackPlaylist.clip_start(clipIndex); + trackPlaylist.remove_region(position, - diff - 1); + } + trackPlaylist.consolidate_blanks(0); } - trackPlaylist.consolidate_blanks(0); trackNb--; } // now move transitions @@ -1550,9 +1692,13 @@ void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration mlt_transition tr = (mlt_transition) nextservice; int currentIn = (int) mlt_transition_get_in(tr); int currentOut = (int) mlt_transition_get_out(tr); - - if (currentOut > insertPos && resource != "mix") { - mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff); + int currentTrack = mlt_transition_get_b_track(tr); + insertPos = trackTransitionStartList.value(currentTrack); + if (insertPos != -1) { + insertPos += offset; + if (currentOut > insertPos && resource != "mix") { + mlt_transition_set_in_and_out(tr, currentIn + diff, currentOut + diff); + } } nextservice = mlt_service_producer(nextservice); if (nextservice == NULL) break; @@ -1562,14 +1708,17 @@ void Render::mltInsertSpace(const GenTime pos, int track, const GenTime duration } } mlt_service_unlock(service.get_service()); + mltCheckLength(); + m_mltConsumer->set("refresh", 1); } -int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) { +int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) +{ m_isBlocked = true; int newLength = 0; Mlt::Service service(m_mltProducer->parent().get_service()); if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; - kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1; + //kDebug() << "Changing clip speed, set in and out: " << info.cropStart.frames(m_fps) << " to " << (info.endPos - info.startPos).frames(m_fps) - 1; Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(info.track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); @@ -1578,19 +1727,28 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt int clipLength = trackPlaylist.clip_length(clipIndex); Mlt::Producer clip(trackPlaylist.get_clip(clipIndex)); - QString serv = clip.parent().get("mlt_service"); - QString id = clip.parent().get("id"); - kDebug() << "CLIP SERVICE: " << clip.parent().get("mlt_service"); + if (!clip.is_valid() || clip.is_blank()) { + // invalid clip + return -1; + } + Mlt::Producer clipparent = clip.parent(); + if (!clipparent.is_valid() || clipparent.is_blank()) { + // invalid clip + return -1; + } + QString serv = clipparent.get("mlt_service"); + QString id = clipparent.get("id"); + //kDebug() << "CLIP SERVICE: " << serv; if (serv == "avformat" && speed != 1.0) { mlt_service_lock(service.get_service()); - QString url = clip.parent().get("resource"); - url.append("?" + QString::number(speed)); + QString url = QString::fromUtf8(clipparent.get("resource")); + url.append('?' + QString::number(speed)); Mlt::Producer *slowprod = m_slowmotionProducers.value(url); if (!slowprod || slowprod->get_producer() == NULL) { char *tmp = decodedString(url); slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp); delete[] tmp; - QString producerid = "slowmotion:" + id + ":" + QString::number(speed); + QString producerid = "slowmotion:" + id + ':' + QString::number(speed); tmp = decodedString(producerid); slowprod->set("id", tmp); delete[] tmp; @@ -1634,15 +1792,15 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt } else if (serv == "framebuffer") { mlt_service_lock(service.get_service()); - QString url = clip.parent().get("resource"); - url = url.section("?", 0, 0); - url.append("?" + QString::number(speed)); + QString url = QString::fromUtf8(clipparent.get("resource")); + url = url.section('?', 0, 0); + url.append('?' + QString::number(speed)); Mlt::Producer *slowprod = m_slowmotionProducers.value(url); if (!slowprod || slowprod->get_producer() == NULL) { char *tmp = decodedString(url); slowprod = new Mlt::Producer(*m_mltProfile, "framebuffer", tmp); delete[] tmp; - QString producerid = "slowmotion:" + id.section(":", 1, 1) + ":" + QString::number(speed); + QString producerid = "slowmotion:" + id.section(':', 1, 1) + ':' + QString::number(speed); tmp = decodedString(producerid); slowprod->set("id", tmp); delete[] tmp; @@ -1661,7 +1819,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt Mlt::Producer *cut; if (clipIndex + 1 < trackPlaylist.count() && (info.startPos + newDuration).frames(m_fps) > blankEnd) { GenTime maxLength = GenTime(blankEnd, m_fps) - info.startPos; - cut = slowprod->cut((int)(info.cropStart.frames(m_fps)), (int)(info.cropStart.frames(m_fps) + maxLength.frames(m_fps) - 1)); + cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)(info.cropStart.frames(m_fps) / speed + maxLength.frames(m_fps) - 1)); } else cut = slowprod->cut((int)(info.cropStart.frames(m_fps) / speed), (int)((info.cropStart / speed + newDuration).frames(m_fps) - 1)); trackPlaylist.insert_at(startPos, *cut, 1); @@ -1675,8 +1833,9 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt return newLength; } -bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh) { - +bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh) +{ + kDebug() << "// TRYing to remove effect at: " << index; Mlt::Service service(m_mltProducer->parent().get_service()); bool success = false; Mlt::Tractor tractor(service); @@ -1694,9 +1853,13 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool do int ct = 0; Mlt::Filter *filter = clipService.filter(ct); while (filter) { - if ((index == "-1" && filter->get("kdenlive_id") != "") || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) { + if ((index == "-1" && strcmp(filter->get("kdenlive_id"), "")) || filter->get("kdenlive_ix") == index) {// && filter->get("kdenlive_id") == id) { if (clipService.detach(*filter) == 0) success = true; kDebug() << " / / / DLEETED EFFECT: " << ct; + } else if (updateIndex) { + // Adjust the other effects index + if (QString(filter->get("kdenlive_ix")).toInt() > index.toInt()) filter->set("kdenlive_ix", QString(filter->get("kdenlive_ix")).toInt() - 1); + ct++; } else ct++; filter = clipService.filter(ct); } @@ -1706,7 +1869,8 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool do } -bool Render::mltAddEffect(int track, GenTime position, QHash args, bool doRefresh) { +bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh) +{ Mlt::Service service(m_mltProducer->parent().get_service()); @@ -1723,11 +1887,11 @@ bool Render::mltAddEffect(int track, GenTime position, QHash // temporarily remove all effects after insert point QList filtersList; - const int filer_ix = QString(args.value("kdenlive_ix")).toInt(); + const int filter_ix = params.paramValue("kdenlive_ix").toInt(); int ct = 0; Mlt::Filter *filter = clipService.filter(ct); while (filter) { - if (QString(filter->get("kdenlive_ix")).toInt() > filer_ix) { + if (QString(filter->get("kdenlive_ix")).toInt() > filter_ix) { filtersList.append(filter); clipService.detach(*filter); } else ct++; @@ -1735,54 +1899,57 @@ bool Render::mltAddEffect(int track, GenTime position, QHash } // create filter - QString tag = args.value("tag"); + QString tag = params.paramValue("tag"); kDebug() << " / / INSERTING EFFECT: " << tag; if (tag.startsWith("ladspa")) tag = "ladspa"; char *filterTag = decodedString(tag); - char *filterId = decodedString(args.value("id")); + char *filterId = decodedString(params.paramValue("id")); QHash::Iterator it; - QString kfr = args.value("keyframes"); + QString kfr = params.paramValue("keyframes"); if (!kfr.isEmpty()) { - QStringList keyFrames = kfr.split(";", QString::SkipEmptyParts); - kDebug() << "// ADDING KEYFRAME EFFECT: " << args.value("keyframes"); - char *starttag = decodedString(args.value("starttag", "start")); - char *endtag = decodedString(args.value("endtag", "end")); + QStringList keyFrames = kfr.split(';', QString::SkipEmptyParts); + kDebug() << "// ADDING KEYFRAME EFFECT: " << params.paramValue("keyframes"); + char *starttag = decodedString(params.paramValue("starttag", "start")); + char *endtag = decodedString(params.paramValue("endtag", "end")); kDebug() << "// ADDING KEYFRAME TAGS: " << starttag << ", " << endtag; int duration = clip->get_playtime(); - double max = args.value("max").toDouble(); - double min = args.value("min").toDouble(); - double factor = args.value("factor", "1").toDouble(); - args.remove("starttag"); - args.remove("endtag"); - args.remove("keyframes"); - args.remove("min"); - args.remove("max"); - args.remove("factor"); + //double max = params.paramValue("max").toDouble(); + double min = params.paramValue("min").toDouble(); + double factor = params.paramValue("factor", "1").toDouble(); + params.removeParam("starttag"); + params.removeParam("endtag"); + params.removeParam("keyframes"); + params.removeParam("min"); + params.removeParam("max"); + params.removeParam("factor"); int offset = 0; for (int i = 0; i < keyFrames.size() - 1; ++i) { Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag); - filter->set("kdenlive_id", filterId); - int x1 = keyFrames.at(i).section(":", 0, 0).toInt() + offset; - double y1 = keyFrames.at(i).section(":", 1, 1).toDouble(); - int x2 = keyFrames.at(i + 1).section(":", 0, 0).toInt(); - double y2 = keyFrames.at(i + 1).section(":", 1, 1).toDouble(); - if (x2 == -1) x2 = duration; - for (it = args.begin(); it != args.end(); ++it) { - char *name = decodedString(it.key()); - char *value = decodedString(it.value()); - filter->set(name, value); - delete[] name; - delete[] value; - } + if (filter && filter->is_valid()) { + filter->set("kdenlive_id", filterId); + int x1 = keyFrames.at(i).section(':', 0, 0).toInt() + offset; + double y1 = keyFrames.at(i).section(':', 1, 1).toDouble(); + int x2 = keyFrames.at(i + 1).section(':', 0, 0).toInt(); + double y2 = keyFrames.at(i + 1).section(':', 1, 1).toDouble(); + if (x2 == -1) x2 = duration; + + for (int j = 0; j < params.count(); j++) { + char *name = decodedString(params.at(j).name()); + char *value = decodedString(params.at(j).value()); + filter->set(name, value); + delete[] name; + delete[] value; + } - filter->set("in", x1); - filter->set("out", x2); - //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<set(starttag, QString::number((min + y1) / factor).toUtf8().data()); - filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data()); - clipService.attach(*filter); - offset = 1; + filter->set("in", x1); + filter->set("out", x2); + //kDebug() << "// ADDING KEYFRAME vals: " << min<<" / "<set(starttag, QString::number((min + y1) / factor).toUtf8().data()); + filter->set(endtag, QString::number((min + y2) / factor).toUtf8().data()); + clipService.attach(*filter); + offset = 1; + } } delete[] starttag; delete[] endtag; @@ -1796,13 +1963,34 @@ bool Render::mltAddEffect(int track, GenTime position, QHash return false; } - for (it = args.begin(); it != args.end(); ++it) { - char *name = decodedString(it.key()); - char *value = decodedString(it.value()); + params.removeParam("kdenlive_id"); + + for (int j = 0; j < params.count(); j++) { + char *name = decodedString(params.at(j).name()); + char *value = decodedString(params.at(j).value()); filter->set(name, value); delete[] name; delete[] value; } + + if (tag == "sox") { + QString effectArgs = params.paramValue("id").section('_', 1); + + params.removeParam("id"); + params.removeParam("kdenlive_ix"); + params.removeParam("tag"); + params.removeParam("disabled"); + + for (int j = 0; j < params.count(); j++) { + effectArgs.append(' ' + params.at(j).value()); + } + //kDebug() << "SOX EFFECTS: " << effectArgs.simplified(); + char *value = decodedString(effectArgs.simplified()); + filter->set("effect", value); + delete[] value; + } + + // attach filter to the clip clipService.attach(*filter); } @@ -1819,14 +2007,15 @@ bool Render::mltAddEffect(int track, GenTime position, QHash return true; } -bool Render::mltEditEffect(int track, GenTime position, QHash args) { - QString index = args.value("kdenlive_ix"); - QString tag = args.value("tag"); - QHash::Iterator it = args.begin(); - if (!args.value("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") { +bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) +{ + QString index = params.paramValue("kdenlive_ix"); + QString tag = params.paramValue("tag"); + + if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle") { // This is a keyframe effect, to edit it, we remove it and re-add it. - mltRemoveEffect(track, position, index); - bool success = mltAddEffect(track, position, args); + mltRemoveEffect(track, position, index, true); + bool success = mltAddEffect(track, position, params); return success; } @@ -1867,7 +2056,7 @@ bool Render::mltEditEffect(int track, GenTime position, QHash } else ct++; filter = clipService.filter(ct); } - bool success = mltAddEffect(track, position, args); + bool success = mltAddEffect(track, position, params); for (int i = 0; i < filtersList.count(); i++) { clipService.attach(*(filtersList.at(i))); @@ -1877,20 +2066,21 @@ bool Render::mltEditEffect(int track, GenTime position, QHash return success; } - for (it = args.begin(); it != args.end(); ++it) { - kDebug() << " / / EDITING EFFECT ARGS: " << it.key() << ": " << it.value(); - char *name = decodedString(it.key()); - char *value = decodedString(it.value()); + for (int j = 0; j < params.count(); j++) { + char *name = decodedString(params.at(j).name()); + char *value = decodedString(params.at(j).value()); filter->set(name, value); delete[] name; delete[] value; } + m_isBlocked = false; refresh(); return true; } -void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) { +void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) +{ kDebug() << "MOVING EFFECT FROM " << oldPos << ", TO: " << newPos; Mlt::Service service(m_mltProducer->parent().get_service()); @@ -1961,7 +2151,8 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) refresh(); } -bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) { +bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) +{ m_isBlocked = true; Mlt::Service service(m_mltProducer->parent().get_service()); @@ -1977,7 +2168,7 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) { int blankDuration = trackPlaylist.clip_length(i) - 1; QString blk; if (trackPlaylist.is_blank(i)) blk = "(blank)"; - kDebug()<<"CLIP "< 0) { // clip was made longer, trim next blank if there is one. - if (trackPlaylist.is_blank(clipIndex)) { - int blankStart = trackPlaylist.clip_start(clipIndex); - int blankDuration = trackPlaylist.clip_length(clipIndex) - 1; - if (diff - blankDuration == 1) { - trackPlaylist.remove(clipIndex); - } else trackPlaylist.resize_clip(clipIndex, blankStart, blankStart + blankDuration - diff); - } else { - kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex; + if (clipIndex < trackPlaylist.count()) { + // If this is not the last clip in playlist + if (trackPlaylist.is_blank(clipIndex)) { + int blankStart = trackPlaylist.clip_start(clipIndex); + int blankDuration = trackPlaylist.clip_length(clipIndex) - 1; + if (diff > blankDuration) kDebug() << "// ERROR blank clip is not large enough to get back required space!!!"; + if (diff - blankDuration == 1) { + trackPlaylist.remove(clipIndex); + } else trackPlaylist.remove_region(blankStart, diff - 1); + } else { + kDebug() << "/// RESIZE ERROR, NXT CLIP IS NOT BLK: " << clipIndex; + } } } else trackPlaylist.insert_blank(clipIndex, 0 - diff - 1); @@ -2024,14 +2219,16 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) { mltAddClipTransparency(transpinfo, info.track - 1, QString(clip->parent().get("id")).toInt()); }*/ m_isBlocked = false; + m_mltConsumer->set("refresh", 1); return true; } -void Render::mltChangeTrackState(int track, bool mute, bool blind) { +void Render::mltChangeTrackState(int track, bool mute, bool blind) +{ Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Producer trackProducer(tractor.track(track)); - Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + if (mute) { if (blind) trackProducer.set("hide", 3); else trackProducer.set("hide", 2); @@ -2045,7 +2242,38 @@ void Render::mltChangeTrackState(int track, bool mute, bool blind) { refresh(); } -bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) { + +bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) +{ + Mlt::Service service(m_mltProducer->parent().get_service()); + int frameOffset = (int) diff.frames(m_fps); + Mlt::Tractor tractor(service); + Mlt::Producer trackProducer(tractor.track(info.track)); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + if (trackPlaylist.is_blank_at(info.startPos.frames(m_fps))) { + kDebug() << "//////// ERROR RSIZING BLANK CLIP!!!!!!!!!!!"; + return false; + } + mlt_service_lock(service.get_service()); + int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps)); + Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); + if (clip == NULL) { + kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!"; + mlt_service_unlock(service.get_service()); + return false; + } + int previousStart = clip->get_in(); + int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; + m_isBlocked = true; + trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset); + m_isBlocked = false; + mlt_service_unlock(service.get_service()); + m_mltConsumer->set("refresh", 1); + return true; +} + +bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) +{ //kDebug() << "//////// RSIZING CLIP from: "<parent().get_service()); int moveFrame = (int) diff.frames(m_fps); @@ -2058,16 +2286,12 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) { } mlt_service_lock(service.get_service()); int clipIndex = trackPlaylist.get_clip_index_at(info.startPos.frames(m_fps)); - /*int previousStart = trackPlaylist.clip_start(clipIndex); - int previousDuration = trackPlaylist.clip_length(clipIndex) - 1;*/ - //kDebug() << " ** RESIZING CLIP START:" << clipIndex << " on track:" << track << ", mid pos: " << pos.frames(25) << ", moving: " << moveFrame << ", in: " << in.frames(25) << ", out: " << out.frames(25); Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); if (clip == NULL) { kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!"; mlt_service_unlock(service.get_service()); return false; } - //m_mltConsumer->set("refresh", 0); int previousStart = clip->get_in(); int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; m_isBlocked = true; @@ -2098,15 +2322,22 @@ bool Render::mltResizeClipStart(ItemInfo info, GenTime diff) { m_isBlocked = false; //m_mltConsumer->set("refresh", 1); mlt_service_unlock(service.get_service()); + m_mltConsumer->set("refresh", 1); return true; } -bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) { +bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTime moveEnd, Mlt::Producer *prod) +{ return mltMoveClip(startTrack, endTrack, (int) moveStart.frames(m_fps), (int) moveEnd.frames(m_fps), prod); } -void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) { +void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) +{ + if (prod == NULL || !prod->is_valid()) { + kDebug() << "// Warning, CLIP on track " << track << ", at: " << pos << " is invalid, cannot update it!!!"; + return; + } kDebug() << "NEW PROD ID: " << prod->get("id"); m_mltConsumer->set("refresh", 0); kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track; @@ -2146,7 +2377,8 @@ void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) { m_isBlocked = false; } -bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) { +bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) +{ m_isBlocked = true; m_mltConsumer->set("refresh", 0); @@ -2161,10 +2393,10 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn kDebug() << "////// LOOKING FOR CLIP TO MOVE, INDEX: " << clipIndex; bool checkLength = false; if (endTrack == startTrack) { - //mlt_service_lock(service.get_service()); Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex)); if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) { // error, destination is not empty + if (!trackPlaylist.is_blank_at(moveEnd)) trackPlaylist.insert_at(moveStart, clipProducer, 1); //int ix = trackPlaylist.get_clip_index_at(moveEnd); kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd; mlt_service_unlock(m_mltConsumer->get_service()); @@ -2202,9 +2434,18 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn Mlt::Producer *clip; // check if we are moving a slowmotion producer QString serv = clipProducer.parent().get("mlt_service"); - if (serv == "framebuffer") { + QString currentid = clipProducer.parent().get("id"); + if (serv == "framebuffer" || currentid.endsWith("_video")) { clip = &clipProducer; - } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out()); + } else { + if (prod == NULL) { + // Special case: prod is null when using placeholder clips. + // in that case, use the producer existing in playlist. Note that + // it will bypass the one producer per track logic and might cause + // Sound cracks if clip is moved so that it overlaps another copy of itself + clip = clipProducer.cut(clipProducer.get_in(), clipProducer.get_out()); + } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out()); + } // move all effects to the correct producer Mlt::Service clipService(clipProducer.get_service()); @@ -2238,10 +2479,14 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn return true; } -void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) { +bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) +{ + int new_in = (int)newIn.frames(m_fps); + int new_out = (int)newOut.frames(m_fps) - 1; + if (new_in >= new_out) return false; + Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); - Mlt::Field *field = tractor.field(); mlt_service_lock(service.get_service()); m_mltConsumer->set("refresh", 0); @@ -2254,9 +2499,6 @@ void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n QString resource = mlt_properties_get(properties, "mlt_service"); int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2; - int new_in = (int)newIn.frames(m_fps); - int new_out = (int)newOut.frames(m_fps) - 1; - while (mlt_type == "transition") { mlt_transition tr = (mlt_transition) nextservice; int currentTrack = mlt_transition_get_b_track(tr); @@ -2266,12 +2508,12 @@ void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n if (resource == type && startTrack == currentTrack && currentIn <= old_pos && currentOut >= old_pos) { mlt_transition_set_in_and_out(tr, new_in, new_out); if (newTrack - startTrack != 0) { - kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << "x" << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << "x" << newTransitionTrack; + kDebug() << "///// TRANSITION CHANGE TRACK. CUrrent (b): " << currentTrack << 'x' << mlt_transition_get_a_track(tr) << ", NEw: " << newTrack << 'x' << newTransitionTrack; mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr); mlt_properties_set_int(properties, "a_track", newTransitionTrack); mlt_properties_set_int(properties, "b_track", newTrack); - //kDebug() << "set new start & end :" << new_in << new_out<< "TR OFFSET: "<set("refresh", 1); + return true; } -void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) { +void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) +{ // kDebug() << "update transition" << tag << " at pos " << in.frames(25); if (oldTag == tag) mltUpdateTransitionParams(tag, a_track, b_track, in, out, xml); else { @@ -2296,11 +2540,11 @@ void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b //mltSavePlaylist(); } -void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) { +void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) +{ m_isBlocked = true; Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); - Mlt::Field *field = tractor.field(); //m_mltConsumer->set("refresh", 0); mlt_service serv = m_mltProducer->parent().get_service(); @@ -2319,7 +2563,7 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G int currentIn = (int) mlt_transition_get_in(tr); int currentOut = (int) mlt_transition_get_out(tr); - // kDebug()<<"Looking for transition : " << currentIn <<"x"< map = mltGetTransitionParamsFromXml(xml); @@ -2335,7 +2579,7 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G char *name = decodedString(key); char *value = decodedString(it.value()); mlt_properties_set(transproperties, name, value); - kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value; + //kDebug() << " ------ UPDATING TRANS PARAM: " << name << ": " << value; //filter->set("kdenlive_id", id); delete[] name; delete[] value; @@ -2352,7 +2596,8 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G m_mltConsumer->set("refresh", 1); } -void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool do_refresh) { +void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenTime in, GenTime out, QDomElement /*xml*/, bool /*do_refresh*/) +{ Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Field *field = tractor.field(); @@ -2387,7 +2632,8 @@ void Render::mltDeleteTransition(QString tag, int a_track, int b_track, GenTime //if (do_refresh) m_mltConsumer->set("refresh", 1); } -QMap Render::mltGetTransitionParamsFromXml(QDomElement xml) { +QMap Render::mltGetTransitionParamsFromXml(QDomElement xml) +{ QDomNodeList attribs = xml.elementsByTagName("parameter"); QMap map; for (int i = 0;i < attribs.count();i++) { @@ -2403,7 +2649,7 @@ QMap Render::mltGetTransitionParamsFromXml(QDomElement xml) { //map[name]=map[name].replace(".",","); //FIXME how to solve locale conversion of . , } - if (e.attribute("namedesc").contains(";")) { + if (e.attribute("namedesc").contains(';')) { QString format = e.attribute("format"); QStringList separators = format.split("%d", QString::SkipEmptyParts); QStringList values = e.attribute("value").split(QRegExp("[,:;x]")); @@ -2425,7 +2671,8 @@ QMap Render::mltGetTransitionParamsFromXml(QDomElement xml) { return map; } -void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) { +void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) +{ kDebug() << "///////// ADDING CLIP TRANSPARENCY AT: " << info.startPos.frames(25); Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); @@ -2440,7 +2687,8 @@ void Render::mltAddClipTransparency(ItemInfo info, int transitiontrack, int id) refresh(); } -void Render::mltDeleteTransparency(int pos, int track, int id) { +void Render::mltDeleteTransparency(int pos, int track, int id) +{ Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Field *field = tractor.field(); @@ -2475,10 +2723,10 @@ void Render::mltDeleteTransparency(int pos, int track, int id) { //if (do_refresh) m_mltConsumer->set("refresh", 1); } -void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) { +void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id) +{ Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); - Mlt::Field *field = tractor.field(); mlt_service_lock(service.get_service()); m_mltConsumer->set("refresh", 0); @@ -2489,16 +2737,16 @@ void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int t mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice); QString mlt_type = mlt_properties_get(properties, "mlt_type"); QString resource = mlt_properties_get(properties, "mlt_service"); - kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << "x" << newEnd << ", " << track << ", " << id; + kDebug() << "// resize transpar from: " << oldStart << ", TO: " << newStart << 'x' << newEnd << ", " << track << ", " << id; while (mlt_type == "transition") { mlt_transition tr = (mlt_transition) nextservice; int currentTrack = mlt_transition_get_b_track(tr); int currentIn = (int) mlt_transition_get_in(tr); //mlt_properties props = MLT_TRANSITION_PROPERTIES(tr); int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt(); - kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << "x" << transitionId ; + kDebug() << "// resize transpar current in: " << currentIn << ", Track: " << currentTrack << ", id: " << id << 'x' << transitionId ; if (resource == "composite" && track == currentTrack && currentIn == oldStart && transitionId == id) { - kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << "x" << newEnd; + kDebug() << " / / / / /RESIZE TRANS TO: " << newStart << 'x' << newEnd; mlt_transition_set_in_and_out(tr, newStart, newEnd); break; } @@ -2514,10 +2762,10 @@ void Render::mltResizeTransparency(int oldStart, int newStart, int newEnd, int t } -void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) { +void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id) +{ Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); - Mlt::Field *field = tractor.field(); mlt_service_lock(service.get_service()); m_mltConsumer->set("refresh", 0); @@ -2537,7 +2785,7 @@ void Render::mltMoveTransparency(int startTime, int endTime, int startTrack, int int currentOut = (int) mlt_transition_get_out(tr); //mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr); int transitionId = QString(mlt_properties_get(properties, "transparency")).toInt(); - //kDebug()<<" + TRANSITION "<= out) return false; QMap args = mltGetTransitionParamsFromXml(xml); Mlt::Service service(m_mltProducer->parent().get_service()); @@ -2581,8 +2830,8 @@ void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, key = it.key(); char *name = decodedString(key); char *value = decodedString(it.value()); - transition->set(name, value); - kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value; + if (it.value().isEmpty() == false) transition->set(name, value); + //kDebug() << " ------ ADDING TRANS PARAM: " << name << ": " << value; //filter->set("kdenlive_id", id); delete[] name; delete[] value; @@ -2591,9 +2840,11 @@ void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, field->plant_transition(*transition, a_track, b_track); delete[] transId; refresh(); + return true; } -void Render::mltSavePlaylist() { +void Render::mltSavePlaylist() +{ kWarning() << "// UPDATING PLAYLIST TO DISK++++++++++++++++"; Mlt::Consumer fileConsumer(*m_mltProfile, "westley"); fileConsumer.set("resource", "/tmp/playlist.westley"); @@ -2604,33 +2855,71 @@ void Render::mltSavePlaylist() { fileConsumer.start(); } -QList Render::producersList() { +QList Render::producersList() +{ QList prods; - QStringList ids; Mlt::Service service(m_mltProducer->parent().get_service()); + if (service.type() != tractor_type) return prods; Mlt::Tractor tractor(service); - Mlt::Field *field = tractor.field(); + QStringList ids; int trackNb = tractor.count(); for (int t = 1; t < trackNb; t++) { - Mlt::Producer trackProducer(tractor.track(t)); + Mlt::Producer *tt = tractor.track(t); + Mlt::Producer trackProducer(tt); + delete tt; Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); int clipNb = trackPlaylist.count(); - kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb; + //kDebug() << "// PARSING SCENE TRACK: " << t << ", CLIPS: " << clipNb; for (int i = 0; i < clipNb; i++) { - Mlt::Producer *prod = trackPlaylist.get_clip(i); - Mlt::Producer *nprod = new Mlt::Producer(prod->get_parent()); - //kDebug()<<"PROD: "<get("producer")<<", ID: "<get("id")<get("resource"); - if (nprod && !nprod->is_blank() && !ids.contains(nprod->get("id"))) { - ids.append(nprod->get("id")); - prods.append(nprod); + Mlt::Producer *c = trackPlaylist.get_clip(i); + Mlt::Producer *nprod = new Mlt::Producer(c->get_parent()); + if (nprod) { + if (!nprod->is_blank() && !ids.contains(nprod->get("id"))) { + ids.append(nprod->get("id")); + prods.append(nprod); + } else delete nprod; } + delete c; } } return prods; } -void Render::mltInsertTrack(int ix) { +void Render::fillSlowMotionProducers() +{ + Mlt::Service service(m_mltProducer->parent().get_service()); + if (service.type() != tractor_type) return; + + Mlt::Tractor tractor(service); + + int trackNb = tractor.count(); + for (int t = 1; t < trackNb; t++) { + Mlt::Producer *tt = tractor.track(t); + Mlt::Producer trackProducer(tt); + delete tt; + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + int clipNb = trackPlaylist.count(); + for (int i = 0; i < clipNb; i++) { + Mlt::Producer *c = trackPlaylist.get_clip(i); + Mlt::Producer *nprod = new Mlt::Producer(c->get_parent()); + if (nprod) { + QString id = nprod->get("id"); + if (id.startsWith("slowmotion:") && !nprod->is_blank()) { + // this is a slowmotion producer, add it to the list + QString url = QString::fromUtf8(nprod->get("resource")); + if (!m_slowmotionProducers.contains(url)) { + m_slowmotionProducers.insert(url, nprod); + } + } else delete nprod; + } + delete c; + } + } +} + +void Render::mltInsertTrack(int ix, bool videoTrack) +{ blockSignals(true); m_isBlocked = true; @@ -2640,20 +2929,31 @@ void Render::mltInsertTrack(int ix) { if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; Mlt::Tractor tractor(service); - Mlt::Playlist *playlist = new Mlt::Playlist(); + + Mlt::Playlist playlist; int ct = tractor.count(); - kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct; + if (ix > ct) { + kDebug() << "// ERROR, TRYING TO insert TRACK " << ix << ", max: " << ct; + ix = ct; + } + int pos = ix; if (pos < ct) { Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos)); - tractor.set_track(*playlist, pos); + tractor.set_track(playlist, pos); + Mlt::Producer newProd(tractor.track(pos)); + if (!videoTrack) newProd.set("hide", 1); pos++; for (; pos <= ct; pos++) { Mlt::Producer *prodToMove2 = new Mlt::Producer(tractor.track(pos)); tractor.set_track(*prodToMove, pos); prodToMove = prodToMove2; } - } else tractor.set_track(*playlist, ix); + } else { + tractor.set_track(playlist, ix); + Mlt::Producer newProd(tractor.track(ix)); + if (!videoTrack) newProd.set("hide", 1); + } // Move transitions mlt_service serv = m_mltProducer->parent().get_service(); @@ -2698,7 +2998,8 @@ void Render::mltInsertTrack(int ix) { } -void Render::mltDeleteTrack(int ix) { +void Render::mltDeleteTrack(int ix) +{ QDomDocument doc; doc.setContent(sceneList(), false); int tracksCount = doc.elementsByTagName("track").count() - 1; @@ -2731,77 +3032,29 @@ void Render::mltDeleteTrack(int ix) { } tractor.removeChild(track); setSceneList(doc.toString(), m_framePosition); - return; + mltCheckLength(); +} - blockSignals(true); - m_isBlocked = true; - m_mltConsumer->set("refresh", 0); - mlt_service_lock(m_mltConsumer->get_service()); +void Render::updatePreviewSettings() +{ + kDebug() << "////// RESTARTING CONSUMER"; + if (!m_mltConsumer || !m_mltProducer) return; + if (m_mltProducer->get_playtime() == 0) return; Mlt::Service service(m_mltProducer->parent().get_service()); - if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; - - /*Mlt::Tractor tractor(service); - - - Mlt::Multitrack *multi = tractor.multitrack(); - + if (service.type() != tractor_type) return; - int ct = tractor.count(); - kDebug() << "// TRACK REMOVE: " << ix << ", MAX: " << ct; - int pos = ix; - for (; pos < ct ; pos++) { - Mlt::Service *lastTrack = new Mlt::Service(tractor.track(pos)->get_service()); - //mlt_service_close(lastTrack->get_service()); - delete lastTrack; - Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(pos + 1)); - Mlt::Producer *prodToClose = new Mlt::Producer(tractor.track(pos)); - mlt_service_close(prodToMove->get_service()); - mlt_service_close(prodToClose->get_service()); - tractor.set_track(*prodToMove, pos); - }*/ - - // Move transitions - /*mlt_service serv = m_mltProducer->parent().get_service(); - mlt_service nextservice = mlt_service_get_producer(serv); - mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice); - QString mlt_type = mlt_properties_get(properties, "mlt_type"); - QString resource = mlt_properties_get(properties, "mlt_service"); - - while (mlt_type == "transition") { - if (resource != "mix") { - mlt_transition tr = (mlt_transition) nextservice; - int currentTrack = mlt_transition_get_b_track(tr); - int currentaTrack = mlt_transition_get_a_track(tr); - mlt_properties properties = MLT_TRANSITION_PROPERTIES(tr); - - if (currentTrack >= ix) { - mlt_properties_set_int(properties, "b_track", currentTrack + 1); - mlt_properties_set_int(properties, "a_track", currentaTrack + 1); - } - } - nextservice = mlt_service_producer(nextservice); - if (nextservice == NULL) break; - properties = MLT_SERVICE_PROPERTIES(nextservice); - mlt_type = mlt_properties_get(properties, "mlt_type"); - resource = mlt_properties_get(properties, "mlt_service"); + //m_mltConsumer->set("refresh", 0); + if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); + m_mltConsumer->purge(); + QString scene = sceneList(); + int pos = 0; + if (m_mltProducer) { + pos = m_mltProducer->position(); + delete m_mltProducer; } - - // Add audio mix transition to last track - Mlt::Field *field = tractor.field(); - Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, "mix"); - //transition->set("mlt_service", "mix"); - transition->set("a_track", 1); - transition->set("b_track", ct); - transition->set("always_active", 1); - transition->set("internal_added", 237); - transition->set("combine", 1); - field->plant_transition(*transition, 1, ct); - */ - - mlt_service_unlock(m_mltConsumer->get_service()); - m_isBlocked = false; - blockSignals(false); + m_mltProducer = NULL; + setSceneList(scene, pos); } #include "renderer.moc"