block: reimplemented reversing

This commit is contained in:
itsmattkc
2021-04-12 11:05:45 +10:00
parent da9cdbd29e
commit 7701e9331f
3 changed files with 47 additions and 11 deletions
+31 -9
View File
@@ -32,6 +32,7 @@ const QString Block::kLengthInput = QStringLiteral("length_in");
const QString Block::kMediaInInput = QStringLiteral("media_in_in");
const QString Block::kEnabledInput = QStringLiteral("enabled_in");
const QString Block::kSpeedInput = QStringLiteral("speed_in");
const QString Block::kReverseInput = QStringLiteral("reverse_in");
Block::Block() :
previous_(nullptr),
@@ -55,6 +56,9 @@ Block::Block() :
SetInputProperty(kSpeedInput, QStringLiteral("min"), 0.0);
IgnoreHashingFrom(kSpeedInput);
AddInput(kReverseInput, NodeValue::kBoolean, false, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
IgnoreHashingFrom(kReverseInput);
// A block's length must be greater than 0
set_length_and_media_out(1);
}
@@ -77,6 +81,11 @@ void Block::set_length_and_media_out(const rational &length)
return;
}
if (reverse()) {
// Calculate media_in adjustment
set_media_in(SequenceToMediaTime(length - this->length(), true));
}
set_length_internal(length);
}
@@ -88,8 +97,10 @@ void Block::set_length_and_media_in(const rational &length)
return;
}
// Calculate media_in adjustment
set_media_in(SequenceToMediaTime(this->length() - length));
if (!reverse()) {
// Calculate media_in adjustment
set_media_in(SequenceToMediaTime(this->length() - length));
}
// Set the length without setting media out
set_length_internal(length);
@@ -117,7 +128,7 @@ void Block::set_enabled(bool e)
emit EnabledChanged();
}
rational Block::SequenceToMediaTime(const rational &sequence_time) const
rational Block::SequenceToMediaTime(const rational &sequence_time, bool ignore_reverse) const
{
// These constants are not considered "values" per se, so we don't modify them
if (sequence_time == RATIONAL_MIN || sequence_time == RATIONAL_MAX) {
@@ -126,8 +137,7 @@ rational Block::SequenceToMediaTime(const rational &sequence_time) const
rational local_time = sequence_time;
// FIXME: Doesn't handle reversing
double speed_value = GetStandardValue(kSpeedInput).toDouble();
double speed_value = speed();
if (qIsNull(speed_value)) {
// Effectively holds the frame at the in point
@@ -137,7 +147,13 @@ rational Block::SequenceToMediaTime(const rational &sequence_time) const
local_time = rational::fromDouble(local_time.toDouble() * speed_value);
}
return local_time + media_in();
rational media_time = local_time + media_in();
if (reverse() && !ignore_reverse) {
media_time = length() - media_time;
}
return media_time;
}
rational Block::MediaToSequenceTime(const rational &media_time) const
@@ -147,10 +163,15 @@ rational Block::MediaToSequenceTime(const rational &media_time) const
return media_time;
}
rational sequence_time = media_time - media_in();
rational sequence_time = media_time;
// FIXME: Doesn't handle reversing
double speed_value = GetStandardValue(kSpeedInput).toDouble();
if (reverse()) {
sequence_time = length() - sequence_time;
}
sequence_time -= media_in();
double speed_value = speed();
if (qIsNull(speed_value)) {
// Effectively holds the frame at the in point, also prevents divide by zero
@@ -200,6 +221,7 @@ void Block::Retranslate()
SetInputName(kMediaInInput, tr("Media In"));
SetInputName(kEnabledInput, tr("Enabled"));
SetInputName(kSpeedInput, tr("Speed"));
SetInputName(kReverseInput, tr("Reverse"));
}
void Block::Hash(const QString &, QCryptographicHash &, const rational &) const