X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderer.cpp;h=db3e7ac1e57fc0a3d35128b4d856821a2e08b76e;hb=dc7c415e20b76b4f1ac90054ab2ad976b8e7dec0;hp=55deb9a48de327a570ba01f1f03dd4fd85e78744;hpb=9a6dc5f7c53f0af2e6148d703c00cf0e3fd438e3;p=kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp index 55deb9a4..db3e7ac1 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -22,18 +22,11 @@ * * ***************************************************************************/ -// ffmpeg Header files - -extern "C" { -#include -} - #include #include #include #include -#include #include #include @@ -48,12 +41,6 @@ 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 - - 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 ? @@ -126,6 +113,7 @@ 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); m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); m_mltConsumer->set("rescale", "nearest"); @@ -174,7 +162,7 @@ int Render::resetProfile() { m_mltProfile = NULL; buildConsumer(); - kDebug() << "//RESET WITHSCENE: " << scene; + //kDebug() << "//RESET WITHSCENE: " << scene; setSceneList(scene); char *tmp = decodedString(scene); @@ -518,13 +506,15 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { } //} } - if (xml.hasAttribute("out")) producer->set_in_and_out(xml.attribute("in").toInt(), xml.attribute("out").toInt()); - if (producer->is_blank()) { + if (producer == NULL || producer->is_blank() || !producer->is_valid()) { kDebug() << " / / / / / / / /ERRROR / / / / // CANNOT LOAD PRODUCER: "; emit removeInvalidClip(clipId); return; } + + 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; @@ -542,19 +532,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); } } @@ -570,7 +562,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 @@ -606,80 +598,64 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { // 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"; emit removeInvalidClip(clipId); 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); - -#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; - } + 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); + } } 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; } @@ -770,12 +746,15 @@ void Render::setSceneList(QString playlist, int position) { if (m_winid == -1) return; m_isBlocked = true; - kWarning() << "////// RENDER, SET SCENE LIST: " << playlist; + //kWarning() << "////// RENDER, SET SCENE LIST: " << playlist; if (m_mltConsumer) { m_mltConsumer->stop(); //m_mltConsumer->set("refresh", 0); - } else return; + } else { + m_isBlocked = false; + return; + } if (m_mltProducer) { m_mltProducer->set_speed(0); @@ -786,6 +765,7 @@ void Render::setSceneList(QString playlist, int position) { emit stopped(); } + blockSignals(true); char *tmp = decodedString(playlist); m_mltProducer = new Mlt::Producer(*m_mltProfile, "westley-xml", tmp); delete[] tmp; @@ -826,11 +806,11 @@ void Render::setSceneList(QString playlist, int position) { if (position != 0) { //TODO: seek to correct place after opening project. // Needs to be done from another place since it crashes here. - //m_mltProducer->seek(position); - //emit rendererPosition(position); + m_mltProducer->seek(position); } m_isBlocked = false; - + blockSignals(false); + emit rendererPosition(position); } /** Create the producer from the Westley QDomDocument */ @@ -845,7 +825,7 @@ QString Render::sceneList() { westleyConsumer.connect(prod); westleyConsumer.start(); while (!westleyConsumer.is_stopped()) {} - playlist = westleyConsumer.get("kdenlive_playlist"); + playlist = QString::fromUtf8(westleyConsumer.get("kdenlive_playlist")); if (split) slotSplitView(true); return playlist; } @@ -1366,15 +1346,17 @@ void Render::mltCutClip(int track, GenTime position) { int ct = 0; Mlt::Filter *filter = clipService.filter(ct); while (filter) { - if (filter->get("kdenlive_id") != "") { + if (filter->is_valid() && filter->get("kdenlive_id") != "") { // 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); @@ -1440,11 +1422,162 @@ bool Render::mltRemoveClip(int track, GenTime position) { kDebug()<<"CLIP "< clipIndex) mltCheckLength(); + if (track != 0 && trackPlaylist.count() <= clipIndex) mltCheckLength(); m_isBlocked = false; return true; } +int Render::mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart) { + 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); + int insertPos = pos.frames(m_fps); + + 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(clipIndex)) return -1; + if (fromBlankStart) return trackPlaylist.clip_length(clipIndex); + return trackPlaylist.clip_length(clipIndex) + trackPlaylist.clip_start(clipIndex) - insertPos; +} + + +void Render::mltInsertSpace(QMap trackClipStartList, QMap trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset) { + if (!m_mltProducer) { + kDebug() << "PLAYLIST NOT INITIALISED //////"; + return; + } + Mlt::Producer parentProd(m_mltProducer->parent()); + if (parentProd.get_producer() == NULL) { + kDebug() << "PLAYLIST BROKEN, CANNOT INSERT CLIP //////"; + return; + } + //kDebug()<<"// CLP STRT LST: "< 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); + } + // now 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") { + mlt_transition tr = (mlt_transition) nextservice; + int currentTrack = mlt_transition_get_b_track(tr); + int currentIn = (int) mlt_transition_get_in(tr); + int currentOut = (int) mlt_transition_get_out(tr); + 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; + properties = MLT_SERVICE_PROPERTIES(nextservice); + mlt_type = mlt_properties_get(properties, "mlt_type"); + resource = mlt_properties_get(properties, "mlt_service"); + } + } else { + int trackNb = tractor.count(); + while (trackNb > 1) { + Mlt::Producer trackProducer(tractor.track(trackNb - 1)); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + + + 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); + } + trackNb--; + } + // now 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") { + mlt_transition tr = (mlt_transition) nextservice; + int currentIn = (int) mlt_transition_get_in(tr); + int currentOut = (int) mlt_transition_get_out(tr); + 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; + properties = MLT_SERVICE_PROPERTIES(nextservice); + mlt_type = mlt_properties_get(properties, "mlt_type"); + resource = mlt_properties_get(properties, "mlt_service"); + } + } + mlt_service_unlock(service.get_service()); + mltCheckLength(); + m_mltConsumer->set("refresh", 1); +} + int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod) { m_isBlocked = true; int newLength = 0; @@ -1587,7 +1720,7 @@ 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()); @@ -1604,11 +1737,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++; @@ -1616,54 +1749,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")); + 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; @@ -1677,13 +1813,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); } @@ -1700,14 +1857,14 @@ 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); + bool success = mltAddEffect(track, position, params); return success; } @@ -1748,7 +1905,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))); @@ -1758,14 +1915,14 @@ 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; @@ -1905,6 +2062,7 @@ 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; } @@ -1912,7 +2070,7 @@ 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); @@ -1979,6 +2137,7 @@ 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; } @@ -1987,6 +2146,46 @@ bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTim } +void Render::mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod) { + kDebug() << "NEW PROD ID: " << prod->get("id"); + m_mltConsumer->set("refresh", 0); + kDebug() << "// TRYING TO UPDATE CLIP at: " << pos << ", TK: " << track; + mlt_service_lock(m_mltConsumer->get_service()); + Mlt::Service service(m_mltProducer->parent().get_service()); + if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; + + Mlt::Tractor tractor(service); + Mlt::Producer trackProducer(tractor.track(track)); + Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); + int clipIndex = trackPlaylist.get_clip_index_at(pos + 1); + Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex)); + if (clipProducer.is_blank()) { + kDebug() << "// ERROR UPDATING CLIP PROD"; + mlt_service_unlock(m_mltConsumer->get_service()); + m_isBlocked = false; + return; + } + Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out()); + + // move all effects to the correct producer + Mlt::Service clipService(clipProducer.get_service()); + Mlt::Service newClipService(clip->get_service()); + + int ct = 0; + Mlt::Filter *filter = clipService.filter(ct); + while (filter) { + if (filter->get("kdenlive_ix") != 0) { + clipService.detach(*filter); + newClipService.attach(*filter); + } else ct++; + filter = clipService.filter(ct); + } + + trackPlaylist.insert_at(pos, clip, 1); + mlt_service_unlock(m_mltConsumer->get_service()); + m_isBlocked = false; +} + bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEnd, Mlt::Producer *prod) { m_isBlocked = true; @@ -2004,8 +2203,7 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn if (endTrack == startTrack) { //mlt_service_lock(service.get_service()); Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex)); - - if (!trackPlaylist.is_blank_at(moveEnd)) { + if (!trackPlaylist.is_blank_at(moveEnd) || clipProducer.is_blank()) { // error, destination is not empty //int ix = trackPlaylist.get_clip_index_at(moveEnd); kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd; @@ -2016,7 +2214,7 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn trackPlaylist.consolidate_blanks(0); int newIndex = trackPlaylist.insert_at(moveEnd, clipProducer, 1); /*if (QString(clipProducer.parent().get("transparency")).toInt() == 1) { - mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt()); + mltMoveTransparency(moveStart, moveEnd, startTrack, endTrack, QString(clipProducer.parent().get("id")).toInt()); }*/ if (newIndex + 1 == trackPlaylist.count()) checkLength = true; } @@ -2031,9 +2229,22 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn return false; } else { Mlt::Producer clipProducer(trackPlaylist.replace_with_blank(clipIndex)); + if (clipProducer.is_blank()) { + // error, destination is not empty + //int ix = trackPlaylist.get_clip_index_at(moveEnd); + kDebug() << "// ERROR MOVING CLIP TO : " << moveEnd; + mlt_service_unlock(m_mltConsumer->get_service()); + m_isBlocked = false; + return false; + } trackPlaylist.consolidate_blanks(0); destTrackPlaylist.consolidate_blanks(1); - Mlt::Producer *clip = prod->cut(clipProducer.get_in(), clipProducer.get_out()); + Mlt::Producer *clip; + // check if we are moving a slowmotion producer + QString serv = clipProducer.parent().get("mlt_service"); + if (serv == "framebuffer") { + clip = &clipProducer; + } else clip = prod->cut(clipProducer.get_in(), clipProducer.get_out()); // move all effects to the correct producer Mlt::Service clipService(clipProducer.get_service()); @@ -2068,7 +2279,6 @@ bool Render::mltMoveClip(int startTrack, int endTrack, int moveStart, int moveEn } void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut) { - Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Field *field = tractor.field(); @@ -2085,7 +2295,7 @@ void Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n 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); + int new_out = (int)newOut.frames(m_fps) - 1; while (mlt_type == "transition") { mlt_transition tr = (mlt_transition) nextservice; @@ -2128,7 +2338,6 @@ void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b 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(); @@ -2141,11 +2350,12 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G QString mlt_type = mlt_properties_get(properties, "mlt_type"); QString resource = mlt_properties_get(properties, "mlt_service"); int in_pos = (int) in.frames(m_fps); - int out_pos = (int) out.frames(m_fps); + int out_pos = (int) out.frames(m_fps) - 1; while (mlt_type == "transition") { mlt_transition tr = (mlt_transition) nextservice; int currentTrack = mlt_transition_get_b_track(tr); + int currentBTrack = mlt_transition_get_a_track(tr); int currentIn = (int) mlt_transition_get_in(tr); int currentOut = (int) mlt_transition_get_out(tr); @@ -2156,7 +2366,10 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G QMap::Iterator it; QString key; mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr); - + mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt()); + if (currentBTrack != a_track) { + mlt_properties_set_int(properties, "a_track", a_track); + } for (it = map.begin(); it != map.end(); ++it) { key = it.key(); char *name = decodedString(key); @@ -2398,7 +2611,7 @@ void Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, char *transId = decodedString(tag); Mlt::Transition *transition = new Mlt::Transition(*m_mltProfile, transId); if (out != GenTime()) - transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps)); + transition->set_in_and_out((int) in.frames(m_fps), (int) out.frames(m_fps) - 1); QMap::Iterator it; QString key; if (xml.attribute("automatic") == "1") transition->set("automatic", 1); @@ -2432,11 +2645,10 @@ void Render::mltSavePlaylist() { } QList Render::producersList() { - QList prods; + QList prods = QList (); QStringList ids; Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); - Mlt::Field *field = tractor.field(); int trackNb = tractor.count(); for (int t = 1; t < trackNb; t++) { @@ -2457,5 +2669,186 @@ QList Render::producersList() { return prods; } +void Render::mltInsertTrack(int ix, bool videoTrack) { + blockSignals(true); + m_isBlocked = true; + + m_mltConsumer->set("refresh", 0); + mlt_service_lock(m_mltConsumer->get_service()); + Mlt::Service service(m_mltProducer->parent().get_service()); + if (service.type() != tractor_type) kWarning() << "// TRACTOR PROBLEM"; + + Mlt::Tractor tractor(service); + + Mlt::Playlist playlist;// = new Mlt::Playlist(); + int ct = tractor.count(); + // kDebug() << "// TRACK INSERT: " << ix << ", MAX: " << ct; + int pos = ix; + if (pos < ct) { + Mlt::Producer *prodToMove = new Mlt::Producer(tractor.track(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); + Mlt::Producer newProd(tractor.track(ix)); + if (!videoTrack) newProd.set("hide", 1); + } + + // 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"); + } + + // 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); +} + + +void Render::mltDeleteTrack(int ix) { + QDomDocument doc; + doc.setContent(sceneList(), false); + int tracksCount = doc.elementsByTagName("track").count() - 1; + QDomNode track = doc.elementsByTagName("track").at(ix); + QDomNode tractor = doc.elementsByTagName("tractor").at(0); + QDomNodeList transitions = doc.elementsByTagName("transition"); + for (int i = 0; i < transitions.count(); i++) { + QDomElement e = transitions.at(i).toElement(); + QDomNodeList props = e.elementsByTagName("property"); + QMap mappedProps; + for (int j = 0; j < props.count(); j++) { + QDomElement f = props.at(j).toElement(); + mappedProps.insert(f.attribute("name"), f.firstChild().nodeValue()); + } + if (mappedProps.value("mlt_service") == "mix" && mappedProps.value("b_track").toInt() == tracksCount) { + tractor.removeChild(transitions.at(i)); + } else if (mappedProps.value("mlt_service") != "mix" && mappedProps.value("b_track").toInt() >= ix) { + // Transition needs to be moved + int a_track = mappedProps.value("a_track").toInt(); + int b_track = mappedProps.value("b_track").toInt(); + if (a_track > 0) a_track --; + if (b_track > 0) b_track --; + for (int j = 0; j < props.count(); j++) { + QDomElement f = props.at(j).toElement(); + if (f.attribute("name") == "a_track") f.firstChild().setNodeValue(QString::number(a_track)); + else if (f.attribute("name") == "b_track") f.firstChild().setNodeValue(QString::number(b_track)); + } + + } + } + tractor.removeChild(track); + setSceneList(doc.toString(), m_framePosition); + return; + + blockSignals(true); + m_isBlocked = true; + + m_mltConsumer->set("refresh", 0); + mlt_service_lock(m_mltConsumer->get_service()); + 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(); + + + 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"); + } + + // 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); +} + #include "renderer.moc"