timeline: automate waveform resizing

Now each UndoCommand won't have to handle it (unless it can introduce
specific optimizations).
This commit is contained in:
itsmattkc
2020-06-01 14:54:14 +10:00
parent a62960ecc0
commit 1fce380cc6
7 changed files with 103 additions and 72 deletions
+19 -2
View File
@@ -101,7 +101,11 @@ void Block::set_length_and_media_out(const rational &length)
return;
}
length_input_->set_standard_value(QVariant::fromValue(length));
rational old_length = this->length();
set_length_internal(length);
LengthChangedEvent(old_length, length, Timeline::kTrimOut);
}
void Block::set_length_and_media_in(const rational &length)
@@ -115,8 +119,12 @@ void Block::set_length_and_media_in(const rational &length)
// Calculate media_in adjustment
set_media_in(media_in() + (this->length() - length) * speed());
rational old_length = this->length();
// Set the length without setting media out
set_length_and_media_out(length);
set_length_internal(length);
LengthChangedEvent(old_length, length, Timeline::kTrimIn);
}
Block *Block::previous()
@@ -246,6 +254,15 @@ QList<NodeInput *> Block::GetInputsToHash() const
return inputs;
}
void Block::LengthChangedEvent(const rational &, const rational &, const Timeline::MovementMode &)
{
}
void Block::set_length_internal(const rational &length)
{
length_input_->set_standard_value(QVariant::fromValue(length));
}
void Block::LengthInputChanged()
{
emit LengthChanged(length());
+7
View File
@@ -22,6 +22,7 @@
#define BLOCK_H
#include "node/node.h"
#include "timeline/timelinecommon.h"
OLIVE_NAMESPACE_ENTER
@@ -130,10 +131,16 @@ protected:
virtual QList<NodeInput*> GetInputsToHash() const override;
virtual void LengthChangedEvent(const rational& old_length,
const rational& new_length,
const Timeline::MovementMode& mode);
Block* previous_;
Block* next_;
private:
void set_length_internal(const rational &length);
NodeInput* name_input_;
NodeInput* length_input_;
NodeInput* media_in_input_;
+20
View File
@@ -59,6 +59,26 @@ NodeInput *ClipBlock::texture_input() const
return texture_input_;
}
void ClipBlock::LengthChangedEvent(const rational &old_length, const rational &new_length, const Timeline::MovementMode &mode)
{
// Positive if made longer, negative if made shorter
rational diff = new_length - old_length;
if (diff < rational()) {
if (mode == Timeline::kTrimIn) {
waveform().TrimIn(-diff);
} else {
waveform().TrimOut(-diff);
}
} else {
if (mode == Timeline::kTrimIn) {
waveform().PrependSilence(diff);
} else {
waveform().AppendSilence(diff);
}
}
}
void ClipBlock::InvalidateCache(const TimeRange &range, NodeInput *from, NodeInput *source)
{
// If signal is from texture input, transform all times from media time to sequence time
+5
View File
@@ -72,6 +72,11 @@ public:
signals:
void PreviewUpdated();
protected:
virtual void LengthChangedEvent(const rational& old_length,
const rational& new_length,
const Timeline::MovementMode& mode) override;
private:
NodeInput* texture_input_;