implemented media out value to allow speed changes in clips
This commit is contained in:
@@ -38,6 +38,11 @@ Block::Block() :
|
||||
media_in_input_->SetConnectable(false);
|
||||
media_in_input_->set_data_type(NodeParam::kRational);
|
||||
AddInput(media_in_input_);
|
||||
|
||||
media_out_input_ = new NodeInput("media_out_in");
|
||||
media_out_input_->SetConnectable(false);
|
||||
media_out_input_->set_data_type(NodeParam::kRational);
|
||||
AddInput(media_out_input_);
|
||||
}
|
||||
|
||||
QString Block::Category() const
|
||||
@@ -81,12 +86,31 @@ void Block::set_length(const rational &length)
|
||||
length_input_->set_value_at_time(0, QVariant::fromValue(length));
|
||||
}
|
||||
|
||||
void Block::set_length_and_media_out(const rational &length)
|
||||
{
|
||||
Q_ASSERT(length > 0);
|
||||
|
||||
if (length == this->length()) {
|
||||
return;
|
||||
}
|
||||
|
||||
set_media_out(media_out() + (length - this->length()));
|
||||
|
||||
set_length(length);
|
||||
}
|
||||
|
||||
void Block::set_length_and_media_in(const rational &length)
|
||||
{
|
||||
Q_ASSERT(length > 0);
|
||||
|
||||
if (length == this->length()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate media_in adjustment
|
||||
set_media_in(media_in() + (this->length() - length));
|
||||
|
||||
// Set the length
|
||||
// Set the length without setting media out
|
||||
set_length(length);
|
||||
}
|
||||
|
||||
@@ -120,6 +144,21 @@ void Block::set_media_in(const rational &media_in)
|
||||
media_in_input_->set_value_at_time(0, QVariant::fromValue(media_in));
|
||||
}
|
||||
|
||||
rational Block::media_out() const
|
||||
{
|
||||
return media_out_input_->get_value_at_time(0).value<rational>();
|
||||
}
|
||||
|
||||
void Block::set_media_out(const rational &media_out)
|
||||
{
|
||||
media_out_input_->set_value_at_time(0, QVariant::fromValue(media_out));
|
||||
}
|
||||
|
||||
rational Block::media_length() const
|
||||
{
|
||||
return media_out() - media_in();
|
||||
}
|
||||
|
||||
const QString &Block::block_name() const
|
||||
{
|
||||
return block_name_;
|
||||
@@ -137,7 +176,7 @@ rational Block::SequenceToMediaTime(const rational &sequence_time) const
|
||||
return sequence_time;
|
||||
}
|
||||
|
||||
return sequence_time - in() + media_in();
|
||||
return (sequence_time - in() + media_in()) * media_length() / length();
|
||||
}
|
||||
|
||||
rational Block::MediaToSequenceTime(const rational &media_time) const
|
||||
@@ -147,7 +186,7 @@ rational Block::MediaToSequenceTime(const rational &media_time) const
|
||||
return media_time;
|
||||
}
|
||||
|
||||
return media_time - media_in() + in();
|
||||
return media_time * length() / media_length() - media_in() + in();
|
||||
}
|
||||
|
||||
void Block::CopyParameters(const Block *source, Block *dest)
|
||||
@@ -161,7 +200,7 @@ void Block::CopyParameters(const Block *source, Block *dest)
|
||||
|
||||
dst_t->set_in_and_out_offset(src_t->in_offset(), src_t->out_offset());
|
||||
} else {
|
||||
dest->set_length(source->length());
|
||||
dest->set_length_and_media_out(source->length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
|
||||
rational length() const;
|
||||
virtual void set_length(const rational &length);
|
||||
virtual void set_length_and_media_out(const rational &length);
|
||||
virtual void set_length_and_media_in(const rational &length);
|
||||
|
||||
Block* previous();
|
||||
@@ -67,6 +68,11 @@ public:
|
||||
rational media_in() const;
|
||||
void set_media_in(const rational& media_in);
|
||||
|
||||
rational media_out() const;
|
||||
void set_media_out(const rational& media_out);
|
||||
|
||||
rational media_length() const;
|
||||
|
||||
const QString& block_name() const;
|
||||
void set_block_name(const QString& name);
|
||||
|
||||
@@ -106,6 +112,7 @@ protected:
|
||||
private:
|
||||
NodeInput* length_input_;
|
||||
NodeInput* media_in_input_;
|
||||
NodeInput* media_out_input_;
|
||||
|
||||
rational in_point_;
|
||||
rational out_point_;
|
||||
|
||||
@@ -37,7 +37,7 @@ void TransitionBlock::Retranslate()
|
||||
in_block_input_->set_name(tr("To"));
|
||||
}
|
||||
|
||||
void TransitionBlock::set_length(const rational &length)
|
||||
void TransitionBlock::set_length_and_media_out(const rational &length)
|
||||
{
|
||||
Q_UNUSED(length)
|
||||
qCritical() << "Set length is not permitted on a transition";
|
||||
@@ -70,5 +70,5 @@ void TransitionBlock::set_in_and_out_offset(const rational &in_offset, const rat
|
||||
|
||||
void TransitionBlock::RecalculateLength()
|
||||
{
|
||||
Block::set_length(in_offset_ + out_offset_);
|
||||
Block::set_length_and_media_out(in_offset_ + out_offset_);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
|
||||
virtual void Retranslate() override;
|
||||
|
||||
virtual void set_length(const rational &length) override;
|
||||
virtual void set_length_and_media_out(const rational &length) override;
|
||||
virtual void set_length_and_media_in(const rational &length) override;
|
||||
|
||||
const rational& in_offset() const;
|
||||
|
||||
Reference in New Issue
Block a user