nodes: fix loop mode regression

This commit is contained in:
itsmattkc
2022-11-01 09:15:51 -07:00
parent c5a86af181
commit 5e92930de0
16 changed files with 111 additions and 86 deletions
+2
View File
@@ -453,6 +453,8 @@ void ClipBlock::InputValueChangedEvent(const QString &input, int element)
}
}
}
} else if (input == kLoopModeInput) {
emit PreviewChanged();
}
}
+3 -3
View File
@@ -188,12 +188,12 @@ public:
/**
* @brief Get currently set loop mode
*/
Decoder::LoopMode loop_mode() const
LoopMode loop_mode() const
{
return static_cast<Decoder::LoopMode>(GetStandardValue(kLoopModeInput).toInt());
return static_cast<LoopMode>(GetStandardValue(kLoopModeInput).toInt());
}
void set_loop_mode(Decoder::LoopMode l)
void set_loop_mode(LoopMode l)
{
SetStandardValue(kLoopModeInput, int(l));
}
+11 -2
View File
@@ -25,6 +25,7 @@
#include "common/timerange.h"
#include "render/audioparams.h"
#include "render/loopmode.h"
#include "render/videoparams.h"
namespace olive {
@@ -34,10 +35,16 @@ class NodeGlobals
public:
NodeGlobals(){}
NodeGlobals(const VideoParams &vparam, const AudioParams &aparam, const TimeRange &time) :
NodeGlobals(const VideoParams &vparam, const AudioParams &aparam, const TimeRange &time, LoopMode loop_mode) :
video_params_(vparam),
audio_params_(aparam),
time_(time)
time_(time),
loop_mode_(loop_mode)
{
}
NodeGlobals(const VideoParams &vparam, const AudioParams &aparam, const rational &time, LoopMode loop_mode) :
NodeGlobals(vparam, aparam, TimeRange(time, time + vparam.frame_rate_as_time_base()), loop_mode)
{
}
@@ -46,11 +53,13 @@ public:
const AudioParams &aparams() const { return audio_params_; }
const VideoParams &vparams() const { return video_params_; }
const TimeRange &time() const { return time_; }
LoopMode loop_mode() const { return loop_mode_; }
private:
VideoParams video_params_;
AudioParams audio_params_;
TimeRange time_;
LoopMode loop_mode_;
};
+5 -5
View File
@@ -265,7 +265,7 @@ void Footage::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeV
// Push each stream as a footage job
for (int i=0; i<GetTotalStreamCount(); i++) {
Track::Reference ref = GetReferenceFromRealIndex(i);
FootageJob job(globals.time(), decoder_, filename(), ref.type(), GetLength());
FootageJob job(globals.time(), decoder_, filename(), ref.type(), GetLength(), globals.loop_mode());
if (ref.type() == Track::kVideo) {
VideoParams vp = GetVideoParams(ref.index());
@@ -337,7 +337,7 @@ bool TimeIsOutOfBounds(const rational& time, const rational& length)
return time < 0 || time >= length;
}
rational Footage::AdjustTimeByLoopMode(rational time, Decoder::LoopMode loop_mode, const rational &length, VideoParams::Type type, const rational& timebase)
rational Footage::AdjustTimeByLoopMode(rational time, LoopMode loop_mode, const rational &length, VideoParams::Type type, const rational& timebase)
{
if (type == VideoParams::kVideoTypeStill) {
// No looping for still images
@@ -346,15 +346,15 @@ rational Footage::AdjustTimeByLoopMode(rational time, Decoder::LoopMode loop_mod
if (TimeIsOutOfBounds(time, length)) {
switch (loop_mode) {
case Decoder::kLoopModeOff:
case LoopMode::kLoopModeOff:
// Return no time to indicate no frame should be shown here
time = rational::NaN;
break;
case Decoder::kLoopModeClamp:
case LoopMode::kLoopModeClamp:
// Clamp footage time to length
time = clamp(time, rational(0), length - timebase);
break;
case Decoder::kLoopModeLoop:
case LoopMode::kLoopModeLoop:
// Loop footage time around job length
do {
if (time >= length) {
+1 -1
View File
@@ -173,7 +173,7 @@ public:
virtual Node *GetConnectedSampleOutput() override;
static rational AdjustTimeByLoopMode(rational time, Decoder::LoopMode loop_mode, const rational& length, VideoParams::Type type, const rational &timebase);
static rational AdjustTimeByLoopMode(rational time, LoopMode loop_mode, const rational& length, VideoParams::Type type, const rational &timebase);
virtual void LoadFinishedEvent() override;
+4 -9
View File
@@ -32,7 +32,7 @@ NodeValueDatabase NodeTraverser::GenerateDatabase(const Node* node, const TimeRa
NodeValueDatabase database;
// HACK: Pick up loop mode from clips
Decoder::LoopMode old_loop_mode = loop_mode_;
LoopMode old_loop_mode = loop_mode_;
if (const ClipBlock *clip = dynamic_cast<const ClipBlock*>(node)) {
loop_mode_ = clip->loop_mode();
}
@@ -184,11 +184,6 @@ void NodeTraverser::Transform(QTransform *transform, const Node *start, const No
transform_ = nullptr;
}
NodeGlobals NodeTraverser::GenerateGlobals(const VideoParams &vparams, const AudioParams &aparams, const TimeRange &time)
{
return NodeGlobals(vparams, aparams, time);
}
NodeValueTable NodeTraverser::ProcessInput(const Node* node, const QString& input, const TimeRange& range)
{
// If input is connected, retrieve value directly
@@ -259,7 +254,7 @@ void NodeTraverser::ProcessInputElement(NodeValueTableArray &array_tbl, const No
NodeTraverser::NodeTraverser() :
cancel_(nullptr),
transform_(nullptr),
loop_mode_(Decoder::kLoopModeOff)
loop_mode_(LoopMode::kLoopModeOff)
{
}
@@ -309,7 +304,7 @@ NodeValueTable NodeTraverser::GenerateTable(const Node *n, const TimeRange& rang
table = database.Merge();
// By this point, the node should have all the inputs it needs to render correctly
NodeGlobals globals = GenerateGlobals(video_params_, audio_params_, range);
NodeGlobals globals(video_params_, audio_params_, range, loop_mode_);
n->Value(row, globals, &table);
// `transform_now_` is the next node in the path that needs to be traversed. It only ever goes
@@ -430,7 +425,7 @@ void NodeTraverser::ResolveJobs(NodeValue &val)
} else if (FootageJob *fj = dynamic_cast<FootageJob*>(base_job)) {
rational footage_time = Footage::AdjustTimeByLoopMode(fj->time().in(), loop_mode_, fj->length(), fj->video_params().video_type(), fj->video_params().frame_rate_as_time_base());
rational footage_time = Footage::AdjustTimeByLoopMode(fj->time().in(), fj->loop_mode(), fj->length(), fj->video_params().video_type(), fj->video_params().frame_rate_as_time_base());
TexturePtr tex;
+2 -8
View File
@@ -54,12 +54,6 @@ public:
void Transform(QTransform *transform, const Node *start, const Node *end, const TimeRange &range);
static NodeGlobals GenerateGlobals(const VideoParams &vparams, const AudioParams &aparams, const TimeRange &time);
static NodeGlobals GenerateGlobals(const VideoParams &vparams, const AudioParams &aparams, const rational &time)
{
return GenerateGlobals(vparams, aparams, TimeRange(time, time + vparams.frame_rate_as_time_base()));
}
const VideoParams& GetCacheVideoParams() const
{
return video_params_;
@@ -144,7 +138,7 @@ protected:
return block_stack_.empty() ? nullptr : block_stack_.back();
}
Decoder::LoopMode loop_mode() const { return loop_mode_; }
LoopMode loop_mode() const { return loop_mode_; }
virtual bool UseCache() const { return false; }
@@ -163,7 +157,7 @@ private:
std::list<Block*> block_stack_;
Decoder::LoopMode loop_mode_;
LoopMode loop_mode_;
QHash<const Node*, QHash<TimeRange, NodeValueTable> > value_cache_;
QHash<Texture*, TexturePtr> resolved_texture_cache_;