X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderer.cpp;h=a4559e7cbd8b9db7f891528aa9fe47df6b720dd2;hb=2bb3e6b046c0ecd26ced536bd2bfd0487bc7fb06;hp=e519a8d346581ca9dc113dd03be649151a681aa1;hpb=17d296dfa42270a57fb197aad3e34ad23e54b761;p=kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp index e519a8d3..a4559e7c 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -114,6 +114,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("window_background", decodedString(KdenliveSettings::window_background().name())); m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); m_mltConsumer->set("rescale", "nearest"); @@ -460,7 +461,7 @@ void Render::slotSplitView(bool doit) { } } -void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { +void Render::getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer) { int height = 50; int width = (int)(height * m_mltProfile->dar()); QMap < QString, QString > filePropertyMap; @@ -469,7 +470,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { KUrl url = KUrl(xml.attribute("resource", QString::null)); Mlt::Producer *producer = NULL; if (xml.attribute("type").toInt() == TEXT && !QFile::exists(url.path())) { - emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap); + emit replyGetFileProperties(clipId, producer, filePropertyMap, metadataPropertyMap, replaceProducer); return; } if (xml.attribute("type").toInt() == COLOR) { @@ -598,11 +599,11 @@ 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"; } } @@ -683,7 +684,7 @@ void Render::getFileProperties(const QDomElement &xml, const QString &clipId) { 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; @@ -845,7 +846,7 @@ void Render::setSceneList(QString playlist, int position) { } /** Create the producer from the Westley QDomDocument */ -QString Render::sceneList() { +const QString Render::sceneList() { QString playlist; Mlt::Consumer westleyConsumer(*m_mltProfile , "westley:kdenlive_playlist"); m_mltProducer->optimise(); @@ -1022,7 +1023,7 @@ 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; @@ -1128,6 +1129,7 @@ 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); @@ -1136,7 +1138,8 @@ void Render::playZone(const GenTime & startTime, const GenTime & stopTime) { } void Render::resetZoneMode() { - m_mltProducer->set("out", m_mltProducer->get_length() - 1); + if (!m_isZoneMode && !m_isLoopMode) return; + m_mltProducer->set("out", m_originalOut); //m_mltProducer->set("eof", "pause"); m_isZoneMode = false; m_isLoopMode = false; @@ -1636,7 +1639,7 @@ int Render::mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt 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()); @@ -1645,12 +1648,21 @@ 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"); + QString url = clipparent.get("resource"); url.append("?" + QString::number(speed)); Mlt::Producer *slowprod = m_slowmotionProducers.value(url); if (!slowprod || slowprod->get_producer() == NULL) { @@ -1701,7 +1713,7 @@ 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"); + QString url = clipparent.get("resource"); url = url.section("?", 0, 0); url.append("?" + QString::number(speed)); Mlt::Producer *slowprod = m_slowmotionProducers.value(url); @@ -1728,7 +1740,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); @@ -2087,21 +2099,25 @@ bool Render::mltResizeClipEnd(ItemInfo info, GenTime clipDuration) { int previousDuration = trackPlaylist.clip_length(clipIndex) - 1; int newDuration = (int) clipDuration.frames(m_fps) - 1; trackPlaylist.resize_clip(clipIndex, previousStart, newDuration + previousStart); - //trackPlaylist.consolidate_blanks(0); + trackPlaylist.consolidate_blanks(0); // skip to next clip clipIndex++; int diff = newDuration - previousDuration; - kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration; + kDebug() << "//////// RESIZE CLIP: " << clipIndex << "( pos: " << info.startPos.frames(25) << "), DIFF: " << diff << ", CURRENT DUR: " << previousDuration << ", NEW DUR: " << newDuration << ", IX: " << clipIndex << ", MAX: " << trackPlaylist.count(); if (diff > 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); @@ -2141,6 +2157,35 @@ void Render::mltChangeTrackState(int track, bool mute, bool blind) { refresh(); } + +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()); @@ -2154,16 +2199,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; @@ -2204,6 +2245,10 @@ bool Render::mltMoveClip(int startTrack, int endTrack, GenTime moveStart, GenTim 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; @@ -2863,6 +2908,7 @@ void Render::mltDeleteTrack(int ix) { } tractor.removeChild(track); setSceneList(doc.toString(), m_framePosition); + mltCheckLength(); return; blockSignals(true); @@ -2940,10 +2986,11 @@ void Render::mltDeleteTrack(int ix) { 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) return; - m_mltConsumer->set("refresh", 0); + //m_mltConsumer->set("refresh", 0); if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); m_mltConsumer->purge(); QString scene = sceneList();