Skip to content

Commit

Permalink
track: fixed issues from recent rework
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattkc committed Mar 2, 2023
1 parent 4fda521 commit d71359e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 28 deletions.
3 changes: 1 addition & 2 deletions app/node/block/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const QString Block::kLengthInput = QStringLiteral("length_in");
Block::Block() :
previous_(nullptr),
next_(nullptr),
track_(nullptr),
index_(-1)
track_(nullptr)
{
AddInput(kLengthInput, NodeValue::kRational, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable | kInputFlagHidden));
SetInputProperty(kLengthInput, QStringLiteral("min"), QVariant::fromValue(rational(0, 1)));
Expand Down
11 changes: 0 additions & 11 deletions app/node/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ class Block : public Node

virtual void Retranslate() override;

int index() const
{
return index_;
}

void set_index(int i)
{
index_ = i;
}

virtual void InvalidateCache(const TimeRange& range, const QString& from, int element = -1, InvalidateCacheOptions options = InvalidateCacheOptions()) override;

static const QString kLengthInput;
Expand Down Expand Up @@ -143,7 +133,6 @@ public slots:
rational in_point_;
rational out_point_;
Track* track_;
int index_;

rational last_length_;

Expand Down
32 changes: 29 additions & 3 deletions app/node/output/track/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Track::Track() :
locked_(false),
sequence_(nullptr),
ignore_arraymap_(0),
arraymap_invalid_(false)
arraymap_invalid_(false),
ignore_arraymap_set_(false)
{
AddInput(kBlockInput, NodeValue::kNone, InputFlags(kInputFlagArray | kInputFlagNotKeyframable | kInputFlagHidden | kInputFlagIgnoreInvalidations));

Expand Down Expand Up @@ -197,6 +198,8 @@ void Track::SetTrackHeight(const double &height)

bool Track::LoadCustom(QXmlStreamReader *reader, SerializedData *data)
{
ignore_arraymap_set_ = true;

while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("height")) {
this->SetTrackHeight(reader->readElementText().toDouble());
Expand All @@ -213,6 +216,12 @@ void Track::SaveCustom(QXmlStreamWriter *writer) const
writer->writeTextElement(QStringLiteral("height"), QString::number(this->GetTrackHeight()));
}

void Track::PostLoadEvent(SerializedData *data)
{
ignore_arraymap_set_ = false;
RefreshBlockCacheFromArrayMap();
}

void Track::InputValueChangedEvent(const QString &input, int element)
{
Q_UNUSED(element)
Expand Down Expand Up @@ -457,6 +466,8 @@ void Track::RippleRemoveBlock(Block *block)
Block::set_previous_next(previous, next);
block->set_previous(nullptr);
block->set_next(nullptr);
block->set_in(0);
block->set_out(block->length());

// Update in/outs
UpdateInOutFrom(index);
Expand Down Expand Up @@ -563,8 +574,6 @@ void Track::UpdateInOutFrom(int index)
last_out += b->length();

b->set_out(last_out);

b->set_index(i);
}

emit BlocksRefreshed();
Expand Down Expand Up @@ -731,6 +740,21 @@ void Track::UpdateArrayMap()

void Track::RefreshBlockCacheFromArrayMap()
{
if (ignore_arraymap_set_) {
return;
}

// Disconnecting any existing blocks
for (Block *b : blocks_) {
Q_ASSERT(b->track() == this);
b->set_track(nullptr);
b->set_previous(nullptr);
b->set_next(nullptr);
b->set_in(0);
b->set_out(b->length());
disconnect(b, &Block::LengthChanged, this, &Track::BlockLengthChanged);
}

QByteArray bytes = GetStandardValue(kArrayMapInput).toByteArray();
block_array_indexes_.resize(bytes.size() / sizeof(uint32_t));
memcpy(block_array_indexes_.data(), bytes.data(), bytes.size());
Expand All @@ -747,6 +771,8 @@ void Track::RefreshBlockCacheFromArrayMap()

if (b) {
b->set_track(this);
connect(b, &Block::LengthChanged, this, &Track::BlockLengthChanged);

blocks_.append(b);
prev = b;
} else {
Expand Down
2 changes: 2 additions & 0 deletions app/node/output/track/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Track : public Node

virtual bool LoadCustom(QXmlStreamReader *reader, SerializedData *data) override;
virtual void SaveCustom(QXmlStreamWriter *writer) const override;
virtual void PostLoadEvent(SerializedData *data);

static int InternalHeightToPixelHeight(double h)
{
Expand Down Expand Up @@ -484,6 +485,7 @@ public slots:

int ignore_arraymap_;
bool arraymap_invalid_;
bool ignore_arraymap_set_;

private slots:
void BlockLengthChanged();
Expand Down
20 changes: 10 additions & 10 deletions app/node/project/serializer/serializer230220.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,15 @@ ProjectSerializer230220::LoadData ProjectSerializer230220::Load(Project *project
}
}

PostConnect(load_data.nodes, &project_data);

// Resolve serialized properties (if any)
for (auto it=properties.cbegin(); it!=properties.cend(); it++) {
Node *node = project_data.node_ptrs.value(it.key());
if (node) {
load_data.properties.insert(node, it.value());
}
}

PostConnect(load_data.nodes, &project_data);
} else {
reader->skipCurrentElement();
}
Expand Down Expand Up @@ -452,14 +452,6 @@ void ProjectSerializer230220::Save(QXmlStreamWriter *writer, const SaveData &dat

void ProjectSerializer230220::PostConnect(const QVector<Node *> &nodes, SerializedData *project_data) const
{
for (auto it = nodes.cbegin(); it != nodes.cend(); it++){
Node *n = *it;

n->PostLoadEvent(project_data);

n->SetCachesEnabled(true);
}

foreach (const SerializedData::SerializedConnection& con, project_data->desired_connections) {
if (Node *out = project_data->node_ptrs.value(con.output_node)) {
Node::ConnectEdge(out, con.input);
Expand All @@ -472,6 +464,14 @@ void ProjectSerializer230220::PostConnect(const QVector<Node *> &nodes, Serializ

Node::Link(a, b);
}

for (auto it = nodes.cbegin(); it != nodes.cend(); it++){
Node *n = *it;

n->PostLoadEvent(project_data);

n->SetCachesEnabled(true);
}
}

}
Expand Down
4 changes: 2 additions & 2 deletions app/render/projectcopier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ void ProjectCopier::QueueEdgeRemove(Node *output, const NodeInput &input)

void ProjectCopier::QueueValueChange(const NodeInput &input)
{
for (auto it = graph_update_queue_.begin(); it != graph_update_queue_.end(); ) {
/*for (auto it = graph_update_queue_.begin(); it != graph_update_queue_.end(); ) {
if (it->type == QueuedJob::kValueChanged && it->input == input) {
it = graph_update_queue_.erase(it);
} else {
it++;
}
}
}*/

graph_update_queue_.push_back({QueuedJob::kValueChanged, nullptr, input, nullptr, QString(), QString()});
UpdateGraphChangeValue();
Expand Down

0 comments on commit d71359e

Please sign in to comment.