nodes: rewrote and simplified length signaling system

This commit is contained in:
itsmattkc
2021-07-15 21:00:18 -07:00
parent 8350ce300f
commit 4bbc75392a
20 changed files with 148 additions and 241 deletions
+24 -2
View File
@@ -22,6 +22,7 @@
#include <QDebug>
#include "core.h"
#include "node/output/track/track.h"
#include "transition/transition.h"
#include "widget/slider/floatslider.h"
@@ -29,6 +30,8 @@
namespace olive {
#define super Node
const QString Block::kLengthInput = QStringLiteral("length_in");
const QString Block::kMediaInInput = QStringLiteral("media_in_in");
const QString Block::kEnabledInput = QStringLiteral("enabled_in");
@@ -47,7 +50,6 @@ Block::Block() :
SetInputProperty(kLengthInput, QStringLiteral("min"), QVariant::fromValue(rational(0, 1)));
SetInputProperty(kLengthInput, QStringLiteral("view"), RationalSlider::kTime);
SetInputProperty(kLengthInput, QStringLiteral("viewlock"), true);
IgnoreInvalidationsFrom(kLengthInput);
IgnoreHashingFrom(kLengthInput);
AddInput(kMediaInInput, NodeValue::kRational, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
@@ -221,7 +223,7 @@ void Block::set_length_internal(const rational &length)
void Block::Retranslate()
{
Node::Retranslate();
super::Retranslate();
SetInputName(kLengthInput, tr("Length"));
SetInputName(kMediaInInput, tr("Media In"));
@@ -235,4 +237,24 @@ void Block::Hash(const QString &, QCryptographicHash &, const rational &, const
// A block does nothing by default, so we hash nothing
}
void Block::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options)
{
TimeRange r;
if (from == kLengthInput) {
// We must intercept the signal here
r = TimeRange(qMin(length(), last_length_), RATIONAL_MAX);
if (!Core::instance()->EffectsSliderIsBeingDragged()) {
last_length_ = length();
}
options.insert(QStringLiteral("lengthevent"), true);
} else {
r = range;
}
super::InvalidateCache(r, from, element, options);
}
}
+4
View File
@@ -155,6 +155,8 @@ public:
virtual void Hash(const QString& output, QCryptographicHash &hash, const rational &time, const VideoParams& video_params) const override;
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element = -1, InvalidateCacheOptions options = InvalidateCacheOptions()) override;
static const QString kLengthInput;
static const QString kMediaInInput;
static const QString kEnabledInput;
@@ -193,6 +195,8 @@ private:
QVector<Block*> block_links_;
rational last_length_;
};
}
+3 -3
View File
@@ -53,7 +53,7 @@ QString ClipBlock::Description() const
return tr("A time-based node that represents a media source.");
}
void ClipBlock::InvalidateCache(const TimeRange& range, const QString& from, int element)
void ClipBlock::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options)
{
Q_UNUSED(element)
@@ -63,10 +63,10 @@ void ClipBlock::InvalidateCache(const TimeRange& range, const QString& from, int
rational start = MediaToSequenceTime(range.in());
rational end = MediaToSequenceTime(range.out());
super::InvalidateCache(TimeRange(start, end), from, element);
super::InvalidateCache(TimeRange(start, end), from, element, options);
} else {
// Otherwise, pass signal along normally
super::InvalidateCache(range, from, element);
super::InvalidateCache(range, from, element, options);
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ public:
virtual QString id() const override;
virtual QString Description() const override;
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element) override;
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options) override;
virtual TimeRange InputTimeAdjustment(const QString& input, int element, const TimeRange& input_time) const override;
+4 -4
View File
@@ -1019,12 +1019,12 @@ NodeValueTable Node::Value(const QString& output, NodeValueDatabase &value) cons
return value.Merge();
}
void Node::InvalidateCache(const TimeRange &range, const QString &from, int element)
void Node::InvalidateCache(const TimeRange &range, const QString &from, int element, InvalidateCacheOptions options)
{
Q_UNUSED(from)
Q_UNUSED(element)
SendInvalidateCache(range);
SendInvalidateCache(range, options);
}
void Node::BeginOperation()
@@ -1173,14 +1173,14 @@ Node *Node::CopyNodeInGraph(const Node *node, MultiUndoCommand *command)
return copy;
}
void Node::SendInvalidateCache(const TimeRange &range)
void Node::SendInvalidateCache(const TimeRange &range, const InvalidateCacheOptions &options)
{
if (GetOperationStack() == 0) {
for (const OutputConnection& conn : output_connections_) {
// Send clear cache signal to the Node
const NodeInput& in = conn.second;
in.node()->InvalidateCache(range, in.input(), in.element());
in.node()->InvalidateCache(range, in.input(), in.element(), options);
}
}
}
+6 -4
View File
@@ -623,6 +623,8 @@ public:
*/
static T* ValueToPtr(const QVariant& ptr);
using InvalidateCacheOptions = QHash<QString, QVariant>;
/**
* @brief Signal all dependent Nodes that anything cached between start_range and end_range is now invalid and
* requires re-rendering
@@ -632,11 +634,11 @@ public:
* the DAG. Even if the time needs to be transformed somehow (e.g. converting media time to sequence time), you can
* call this function with transformed time and relay the signal that way.
*/
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element = -1);
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element = -1, InvalidateCacheOptions options = InvalidateCacheOptions());
void InvalidateCache(const TimeRange& range, const NodeInput& from)
void InvalidateCache(const TimeRange& range, const NodeInput& from, const InvalidateCacheOptions &options = InvalidateCacheOptions())
{
InvalidateCache(range, from.input(), from.element());
InvalidateCache(range, from.input(), from.element(), options);
}
/**
@@ -882,7 +884,7 @@ protected:
SetInputProperty(id, QStringLiteral("combo_str"), strings);
}
void SendInvalidateCache(const TimeRange &range);
void SendInvalidateCache(const TimeRange &range, const InvalidateCacheOptions &options);
/**
* @brief Don't send cache invalidation signals if `input` is connected or disconnected
+12 -49
View File
@@ -41,8 +41,6 @@ const QString Track::kMutedInput = QStringLiteral("muted_in");
Track::Track() :
track_type_(Track::kNone),
track_length_(0),
midop_track_length_(0),
preop_track_length_(0),
index_(-1),
locked_(false)
{
@@ -431,7 +429,7 @@ QVector<Block *> Track::BlocksAtTimeRange(const TimeRange &range) const
return list;
}
void Track::InvalidateCache(const TimeRange& range, const QString& from, int element)
void Track::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options)
{
if (GetOperationStack() != 0) {
return;
@@ -443,7 +441,8 @@ void Track::InvalidateCache(const TimeRange& range, const QString& from, int ele
if (from == kBlockInput
&& element >= 0
&& (b = dynamic_cast<const Block*>(GetConnectedOutput(from, element).node()))) {
&& (b = dynamic_cast<const Block*>(GetConnectedOutput(from, element).node()))
&& !options.value(QStringLiteral("lengthevent")).toBool()) {
// Limit the range signal to the corresponding block
if (range.out() <= b->in() || range.in() >= b->out()) {
return;
@@ -451,11 +450,14 @@ void Track::InvalidateCache(const TimeRange& range, const QString& from, int ele
limited = TimeRange(qMax(range.in(), b->in()), qMin(range.out(), b->out()));
} else {
limited = TimeRange(qMax(range.in(), rational(0)), qMin(range.out(), qMax(preop_track_length_, track_length())));
preop_track_length_ = track_length_;
limited = range;
}
Node::InvalidateCache(limited, from, element);
// NOTE: For now, I figure we drop this key, but we may find in the future that it's advantageous
// to keep it
options.remove(QStringLiteral("lengthevent"));
Node::InvalidateCache(limited, from, element, options);
}
void Track::InsertBlockBefore(Block* block, Block* after)
@@ -600,15 +602,6 @@ void Track::Hash(const QString &output, QCryptographicHash &hash, const rational
}
}
void Track::EndOperation()
{
super::EndOperation();
if (track_length_ != midop_track_length_) {
SetLengthInternal(midop_track_length_);
}
}
void Track::SetMuted(bool e)
{
SetStandardValue(kMutedInput, e);
@@ -658,21 +651,10 @@ int Track::GetCacheIndexFromArrayIndex(int index) const
return block_array_indexes_.indexOf(index);
}
void Track::SetLengthInternal(const rational &r, bool invalidate)
void Track::SetLengthInternal(const rational &r)
{
// Hold track length until operation stack is empty
midop_track_length_ = r;
if (GetOperationStack() == 0 && track_length_ != r) {
TimeRange invalidate_range(track_length_, r);
track_length_ = r;
preop_track_length_ = qMax(preop_track_length_, track_length_);
emit TrackLengthChanged();
if (invalidate) {
Node::InvalidateCache(invalidate_range, kBlockInput);
}
}
track_length_ = r;
emit TrackLengthChanged();
}
void Track::BlockLengthChanged()
@@ -680,26 +662,7 @@ void Track::BlockLengthChanged()
// Assumes sender is a Block
Block* b = static_cast<Block*>(sender());
rational old_out = b->out();
UpdateInOutFrom(blocks_.indexOf(b));
rational new_out = b->out();
TimeRange invalidate_region(qMin(old_out, new_out), track_length());
// The cache won't start while dragging, so we store up our invalidations if it's held down
// and release them once the mouse is no longer pressed
if (qApp->mouseButtons() & Qt::LeftButton) {
block_length_pending_invalidations_.insert(invalidate_region);
} else if (!block_length_pending_invalidations_.isEmpty()) {
foreach (const TimeRange& r, block_length_pending_invalidations_) {
Node::InvalidateCache(r, kBlockInput);
}
block_length_pending_invalidations_.clear();
}
Node::InvalidateCache(invalidate_region, kBlockInput);
}
uint qHash(const Track::Reference &r, uint seed)
+2 -8
View File
@@ -286,7 +286,7 @@ public:
return blocks_;
}
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element) override;
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options) override;
/**
* @brief Adds Block `block` at the very beginning of the Sequence before all other clips
@@ -345,8 +345,6 @@ public:
return waveform_;
}
virtual void EndOperation() override;
static const double kTrackHeightDefault;
static const double kTrackHeightMinimum;
static const double kTrackHeightInterval;
@@ -420,7 +418,7 @@ private:
int GetCacheIndexFromArrayIndex(int index) const;
void SetLengthInternal(const rational& r, bool invalidate = true);
void SetLengthInternal(const rational& r);
TimeRangeList block_length_pending_invalidations_;
@@ -431,10 +429,6 @@ private:
rational track_length_;
rational midop_track_length_;
rational preop_track_length_;
double track_height_;
int index_;
+2 -8
View File
@@ -222,7 +222,7 @@ void ViewerOutput::ShiftCache(const rational &from, const rational &to)
ShiftAudioCache(from, to);
}
void ViewerOutput::InvalidateCache(const TimeRange& range, const QString& from, int element)
void ViewerOutput::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options)
{
Q_UNUSED(element)
@@ -242,7 +242,7 @@ void ViewerOutput::InvalidateCache(const TimeRange& range, const QString& from,
VerifyLength();
super::InvalidateCache(range, from, element);
super::InvalidateCache(range, from, element, options);
}
QVector<QString> ViewerOutput::inputs_for_output(const QString &output) const
@@ -300,14 +300,8 @@ void ViewerOutput::Retranslate()
void ViewerOutput::VerifyLength()
{
video_length_ = VerifyLengthInternal(Track::kVideo);
if (video_cache_enabled_) {
video_frame_cache_.SetLength(video_length_);
}
audio_length_ = VerifyLengthInternal(Track::kAudio);
if (audio_cache_enabled_) {
audio_playback_cache_.SetLength(audio_length_);
}
rational subtitle_length = VerifyLengthInternal(Track::kSubtitle);
+4 -4
View File
@@ -66,7 +66,7 @@ public:
void ShiftAudioCache(const rational& from, const rational& to);
void ShiftCache(const rational& from, const rational& to);
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element) override;
virtual void InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options) override;
virtual QVector<QString> inputs_for_output(const QString& output) const override;
@@ -154,6 +154,9 @@ public:
virtual NodeOutput GetConnectedSampleOutput();
void SetViewerVideoCacheEnabled(bool e) { video_cache_enabled_ = e; }
void SetViewerAudioCacheEnabled(bool e) { audio_cache_enabled_ = e; }
static const QString kVideoParamsInput;
static const QString kAudioParamsInput;
@@ -202,9 +205,6 @@ protected:
int AddStream(Track::Type type, const QVariant &value);
void SetViewerVideoCacheEnabled(bool e) { video_cache_enabled_ = e; }
void SetViewerAudioCacheEnabled(bool e) { audio_cache_enabled_ = e; }
private:
rational last_length_;
rational video_length_;