X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderer.cpp;h=26791b5beae82497ee564a2f44ac87a28175b112;hb=405ebfa31dec2209eca7031b7ee781f5ca7be10d;hp=2a78c8e6cc88bb8f18ebbb696c42125da2d68503;hpb=6c43f987273f567fa7659d5a4ad3a5e73f6e5b73;p=kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp index 2a78c8e6..26791b5b 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -230,6 +230,8 @@ void Render::buildConsumer(const QString profileName) delete[] tmp; } + int volume = KdenliveSettings::volume(); + m_mltConsumer->set("volume", (float)volume / 100); m_mltConsumer->set("progressive", 1); m_mltConsumer->set("audio_buffer", 1024); @@ -257,7 +259,11 @@ int Render::resetProfile(const QString profileName) QString videoDriver = KdenliveSettings::videodrivername(); QString currentDriver = m_mltConsumer->get("video_driver"); if (getenv("SDL_VIDEO_YUV_HWACCEL") != NULL && currentDriver == "x11") currentDriver = "x11_noaccel"; - if (m_activeProfile == profileName && currentDriver == videoDriver) { + QString background = KdenliveSettings::window_background().name(); + QString currentBackground = m_mltConsumer->get("window_background"); + int volume = KdenliveSettings::volume(); + int currentVolume = (int)(QString(m_mltConsumer->get("volume")).toDouble() * 100.0); + if (m_activeProfile == profileName && currentDriver == videoDriver && volume == currentVolume && background == currentBackground) { kDebug() << "reset to same profile, nothing to do"; return 1; } @@ -280,7 +286,7 @@ int Render::resetProfile(const QString profileName) Mlt::Service service(m_mltProducer->get_service()); if (service.type() == tractor_type) { Mlt::Tractor tractor(service); - for (int trackNb = tractor.count() -1; trackNb >= 0; --trackNb) { + for (int trackNb = tractor.count() - 1; trackNb >= 0; --trackNb) { Mlt::Producer trackProducer(tractor.track(trackNb)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); trackPlaylist.clear(); @@ -744,10 +750,14 @@ void Render::getFileProperties(const QDomElement xml, const QString &clipId, int int frame_height = imageHeight; uint8_t *data = frame->get_image(format, frame_width, frame_height, 0); QImage image((uchar *)data, frame_width, frame_height, QImage::Format_ARGB32); - QPixmap pix(frame_width, frame_height); + QPixmap pix; if (!image.isNull()) { - pix = QPixmap::fromImage(image.rgbSwapped()); + if (frame_width > (2 * width)) { + // there was a scaling problem, do it manually + QImage scaled = image.scaled(width, imageHeight); + pix = QPixmap::fromImage(scaled.rgbSwapped()); + } else pix = QPixmap::fromImage(image.rgbSwapped()); } else pix.fill(Qt::black); @@ -917,7 +927,7 @@ int Render::setProducer(Mlt::Producer *producer, int position) if (position != -1) { m_mltProducer->seek(position); emit rendererPosition(position); - } + } else emit rendererPosition((int) m_mltProducer->position()); m_isBlocked = false; return error; } @@ -1430,9 +1440,12 @@ const QString & Render::rendererName() const void Render::emitFrameNumber(double position) { + if (position == m_framePosition) { + emit frameUpdated((int) position); + return; + } 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() @@ -1645,7 +1658,6 @@ int Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pro void Render::mltCutClip(int track, GenTime position) { - m_isBlocked = true; Mlt::Service service(m_mltProducer->parent().get_service()); @@ -1958,7 +1970,7 @@ void Render::mltInsertSpace(QMap trackClipStartList, QMap resource = mlt_properties_get(properties, "mlt_service"); } } else { - for(int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) { + for (int trackNb = tractor.count() - 1; trackNb >= 1; --trackNb) { Mlt::Producer trackProducer(tractor.track(trackNb)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); @@ -2081,6 +2093,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, dou QString serv = clipparent.get("mlt_service"); QString id = clipparent.get("id"); + if (speed <= 0 && speed > -1) speed = 1.0; //kDebug() << "CLIP SERVICE: " << serv; if (serv == "avformat" && (speed != 1.0 || strobe > 1)) { mlt_service_lock(service.get_service()); @@ -2228,14 +2241,23 @@ bool Render::mltRemoveEffect(int track, GenTime position, QString index, bool up 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(position.frames(m_fps)); - Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps)); + + int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps)); + Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); if (!clip) { kDebug() << " / / / CANNOT FIND CLIP TO REMOVE EFFECT"; - return success; + return false; } + Mlt::Service clipService(clip->get_service()); + int duration = clip->get_playtime(); + if (doRefresh) { + // Check if clip is visible in monitor + int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position(); + if (diff < 0 || diff > duration) doRefresh = false; + } delete clip; + // if (tag.startsWith("ladspa")) tag = "ladspa"; m_isBlocked = true; int ct = 0; @@ -2266,17 +2288,25 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para Mlt::Producer trackProducer(tractor.track(track)); Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service()); - Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps)); + int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps)); + Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); if (!clip) { return false; } + Mlt::Service clipService(clip->get_service()); m_isBlocked = true; int duration = clip->get_playtime(); bool updateIndex = false; + if (doRefresh) { + // Check if clip is visible in monitor + int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position(); + if (diff < 0 || diff > duration) doRefresh = false; + } delete clip; const int filter_ix = params.paramValue("kdenlive_ix").toInt(); + const QString region = params.paramValue("region"); int ct = 0; Mlt::Filter *filter = clipService.filter(ct); while (filter) { @@ -2320,7 +2350,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para // create filter QString tag = params.paramValue("tag"); - kDebug() << " / / INSERTING EFFECT: " << tag; + kDebug() << " / / INSERTING EFFECT: " << tag << ", REGI: " << region; if (tag.startsWith("ladspa")) tag = "ladspa"; char *filterTag = decodedString(tag); char *filterId = decodedString(params.paramValue("id")); @@ -2373,19 +2403,34 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para delete[] starttag; delete[] endtag; } else { - Mlt::Filter *filter = new Mlt::Filter(*m_mltProfile, filterTag); - if (filter && filter->is_valid()) + Mlt::Filter *filter; + QString prefix; + if (!region.isEmpty()) { + filter = new Mlt::Filter(*m_mltProfile, "region"); + } else filter = new Mlt::Filter(*m_mltProfile, filterTag); + if (filter && filter->is_valid()) { filter->set("kdenlive_id", filterId); - else { + if (!region.isEmpty()) { + char *tmp = decodedString(region); + filter->set("resource", tmp); + tmp = decodedString(params.paramValue("kdenlive_ix")); + filter->set("kdenlive_ix", tmp); + filter->set("filter0", filterTag); + prefix = "filter0."; + delete[] tmp; + params.removeParam("id"); + params.removeParam("region"); + params.removeParam("kdenlive_ix"); + } + } else { kDebug() << "filter is NULL"; m_isBlocked = false; return false; } - params.removeParam("kdenlive_id"); for (int j = 0; j < params.count(); j++) { - char *name = decodedString(params.at(j).name()); + char *name = decodedString(prefix + params.at(j).name()); char *value = decodedString(params.at(j).value()); filter->set(name, value); delete[] name; @@ -2399,6 +2444,7 @@ bool Render::mltAddEffect(int track, GenTime position, EffectsParameterList para params.removeParam("kdenlive_ix"); params.removeParam("tag"); params.removeParam("disable"); + params.removeParam("region"); for (int j = 0; j < params.count(); j++) { effectArgs.append(' ' + params.at(j).value()); @@ -2433,7 +2479,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par 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") { + if (!params.paramValue("keyframes").isEmpty() || /*it.key().startsWith("#") || */tag.startsWith("ladspa") || tag == "sox" || tag == "autotrack_rectangle" || params.hasParam("region")) { // This is a keyframe effect, to edit it, we remove it and re-add it. mltRemoveEffect(track, position, index, false); bool success = mltAddEffect(track, position, params); @@ -2442,24 +2488,27 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par // find filter 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()); - //int clipIndex = trackPlaylist.get_clip_index_at(position.frames(m_fps)); - Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps)); + + int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps)); + Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); if (!clip) { kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps); return false; } + Mlt::Service clipService(clip->get_service()); + int duration = clip->get_playtime(); + bool doRefresh = true; + // Check if clip is visible in monitor + int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position(); + if (diff < 0 || diff > duration) doRefresh = false; delete clip; m_isBlocked = true; int ct = 0; - Mlt::Filter *filter = clipService.filter(ct); - - /* - kDebug() << "EDITING FILTER: "<get("kdenlive_id") <<", IX: "<get("kdenlive_ix"); @@ -2467,9 +2516,10 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par filter = clipService.filter(ct); } kDebug() << "++++++++++++++++++++++++++"; - */ ct = 0; - filter = clipService.filter(ct); + filter = clipService.filter(ct); */ + + Mlt::Filter *filter = clipService.filter(ct); while (filter) { if (filter->get("kdenlive_ix") == index) { break; @@ -2486,9 +2536,12 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par m_isBlocked = false; return success; } + QString prefix; + QString ser = filter->get("mlt_service"); + if (ser == "region") prefix = "filter0."; mlt_service_lock(service.get_service()); for (int j = 0; j < params.count(); j++) { - char *name = decodedString(params.at(j).name()); + char *name = decodedString(prefix + params.at(j).name()); char *value = decodedString(params.at(j).value()); filter->set(name, value); delete[] name; @@ -2497,7 +2550,7 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par mlt_service_unlock(service.get_service()); m_isBlocked = false; - refresh(); + if (doRefresh) refresh(); return true; } @@ -2510,14 +2563,22 @@ void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, in 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(position.frames(m_fps)); - Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps)); + + int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps)); + Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); if (!clip) { kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps); return; } + Mlt::Service clipService(clip->get_service()); + int duration = clip->get_playtime(); + bool doRefresh = true; + // Check if clip is visible in monitor + int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position(); + if (diff < 0 || diff > duration) doRefresh = false; delete clip; + m_isBlocked = true; int ct = 0; Mlt::Filter *filter = clipService.filter(ct); @@ -2530,7 +2591,7 @@ void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, in } m_isBlocked = false; - refresh(); + if (doRefresh) refresh(); } void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) @@ -2542,14 +2603,22 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) 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(position.frames(m_fps)); - Mlt::Producer *clip = trackPlaylist.get_clip_at((int) position.frames(m_fps)); + + int clipIndex = trackPlaylist.get_clip_index_at((int) position.frames(m_fps)); + Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); if (!clip) { kDebug() << "WARINIG, CANNOT FIND CLIP ON track: " << track << ", AT POS: " << position.frames(m_fps); return; } + Mlt::Service clipService(clip->get_service()); + int duration = clip->get_playtime(); + bool doRefresh = true; + // Check if clip is visible in monitor + int diff = trackPlaylist.clip_start(clipIndex) + duration - m_mltProducer->position(); + if (diff < 0 || diff > duration) doRefresh = false; delete clip; + m_isBlocked = true; int ct = 0; QList filtersList; @@ -2603,7 +2672,7 @@ void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) } m_isBlocked = false; - refresh(); + if (doRefresh) refresh(); } bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) @@ -2727,10 +2796,10 @@ bool Render::mltResizeClipCrop(ItemInfo info, GenTime diff) return false; } int previousStart = clip->get_in(); + int previousOut = clip->get_out(); delete clip; - int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; m_isBlocked = true; - trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousStart + previousDuration + frameOffset); + trackPlaylist.resize_clip(clipIndex, previousStart + frameOffset, previousOut + frameOffset); m_isBlocked = false; mlt_service_unlock(service.get_service()); m_mltConsumer->set("refresh", 1); @@ -2751,22 +2820,30 @@ 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)); - if (trackPlaylist.is_blank(clipIndex)) { + Mlt::Producer *clip = trackPlaylist.get_clip(clipIndex); + if (clip == NULL || clip->is_blank()) { kDebug() << "//////// ERROR RSIZING NULL CLIP!!!!!!!!!!!"; mlt_service_unlock(service.get_service()); return false; } - int previousStart = trackPlaylist.clip_start(clipIndex); - int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; + int previousStart = clip->get_in(); + int previousOut = clip->get_out(); + delete clip; m_isBlocked = true; - kDebug() << "RESIZE, old start: " << previousStart + moveFrame << ", " << previousStart + previousDuration; - trackPlaylist.resize_clip(clipIndex, previousStart + moveFrame, previousStart + previousDuration); + previousStart += moveFrame; + if (previousStart < 0) { + // special case, in point becoming negative (resizing images) + previousOut -= previousStart; + previousStart = 0; + } + // kDebug() << "RESIZE, new start: " << previousStart << ", " << previousOut; + trackPlaylist.resize_clip(clipIndex, previousStart, previousOut); if (moveFrame > 0) trackPlaylist.insert_blank(clipIndex, moveFrame - 1); else { //int midpos = info.startPos.frames(m_fps) + moveFrame - 1; int blankIndex = clipIndex - 1; int blankLength = trackPlaylist.clip_length(blankIndex); - kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame; + // kDebug() << " + resizing blank length " << blankLength << ", SIZE DIFF: " << moveFrame; if (! trackPlaylist.is_blank(blankIndex)) { kDebug() << "WARNING, CLIP TO RESIZE IS NOT BLANK"; } @@ -2990,11 +3067,22 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n int new_in = (int)newIn.frames(m_fps); int new_out = (int)newOut.frames(m_fps) - 1; if (new_in >= new_out) return false; + int old_in = (int)oldIn.frames(m_fps); + int old_out = (int)oldOut.frames(m_fps) - 1; Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); Mlt::Field *field = tractor.field(); + bool doRefresh = true; + // Check if clip is visible in monitor + int diff = old_out - m_mltProducer->position(); + if (diff < 0 || diff > old_out - old_in) doRefresh = false; + if (doRefresh) { + diff = new_out - m_mltProducer->position(); + if (diff < 0 || diff > new_out - new_in) doRefresh = false; + } + m_isBlocked++; mlt_service_lock(service.get_service()); @@ -3002,7 +3090,7 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n mlt_properties properties = MLT_SERVICE_PROPERTIES(nextservice); QString mlt_type = mlt_properties_get(properties, "mlt_type"); QString resource = mlt_properties_get(properties, "mlt_service"); - int old_pos = (int)(oldIn.frames(m_fps) + oldOut.frames(m_fps)) / 2; + int old_pos = (int)(old_in + old_out) / 2; bool found = false; while (mlt_type == "transition") { @@ -3035,7 +3123,7 @@ bool Render::mltMoveTransition(QString type, int startTrack, int newTrack, int n } mlt_service_unlock(service.get_service()); m_isBlocked--; - refresh(); + if (doRefresh) refresh(); //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1); return found; } @@ -3088,8 +3176,8 @@ void Render::mltUpdateTransition(QString oldTag, QString tag, int a_track, int b mltDeleteTransition(oldTag, a_track, b_track, in, out, xml, false); mltAddTransition(tag, a_track, b_track, in, out, xml, false); } - refresh(); - //mltSavePlaylist(); + + if (m_mltProducer->position() > in.frames(m_fps) && m_mltProducer->position() < out.frames(m_fps)) refresh(); } void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml) @@ -3119,14 +3207,32 @@ void Render::mltUpdateTransitionParams(QString type, int a_track, int b_track, G QMap::Iterator it; QString key; mlt_properties transproperties = MLT_TRANSITION_PROPERTIES(tr); + + QString currentId = mlt_properties_get(transproperties, "kdenlive_id"); + if (currentId != xml.attribute("id")) { + // The transition ID is not the same, so reset all properties + char *tmp = decodedString(xml.attribute("id")); + mlt_properties_set(transproperties, "kdenlive_id", tmp); + delete[] tmp; + // Cleanup previous properties + QStringList permanentProps; + permanentProps << "factory" << "kdenlive_id" << "mlt_service" << "mlt_type" << "in"; + permanentProps << "out" << "a_track" << "b_track"; + for (int i = 0; i < mlt_properties_count(transproperties); i++) { + QString propName = mlt_properties_get_name(transproperties, i); + if (!propName.startsWith('_') && ! permanentProps.contains(propName)) { + tmp = decodedString(propName); + mlt_properties_set(transproperties, tmp, ""); + delete[] tmp; + } + } + } + mlt_properties_set_int(transproperties, "force_track", xml.attribute("force_track").toInt()); mlt_properties_set_int(transproperties, "automatic", xml.attribute("automatic", "0").toInt()); - // update the transition id in case it uses the same MLT service but different Kdenlive id - char *tmp = decodedString(xml.attribute("id")); - mlt_properties_set(transproperties, "kdenlive_id", tmp); - delete[] tmp; + if (currentBTrack != a_track) { - mlt_properties_set_int(properties, "a_track", a_track); + mlt_properties_set_int(transproperties, "a_track", a_track); } for (it = map.begin(); it != map.end(); ++it) { key = it.key(); @@ -3384,6 +3490,8 @@ bool Render::mltAddTransition(QString tag, int a_track, int b_track, GenTime in, 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) - 1); + + if (do_refresh && (m_mltProducer->position() < in.frames(m_fps) || m_mltProducer->position() > out.frames(m_fps))) do_refresh = false; QMap::Iterator it; QString key; if (xml.attribute("automatic") == "1") transition->set("automatic", 1);