remove shifts, operations, and make caches node-agnostic

This commit is contained in:
itsmattkc
2022-05-16 19:53:38 -07:00
parent 70a4f7e749
commit e0bb31b199
26 changed files with 124 additions and 708 deletions
-24
View File
@@ -406,10 +406,6 @@ QVector<Block *> Track::BlocksAtTimeRange(const TimeRange &range) const
void Track::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options)
{
if (GetOperationStack() != 0) {
return;
}
TimeRange limited;
const Block* b;
@@ -465,69 +461,49 @@ void Track::InsertBlockAfter(Block *block, Block *before)
void Track::PrependBlock(Block *block)
{
BeginOperation();
InputArrayPrepend(kBlockInput);
Node::ConnectEdge(block, NodeInput(this, kBlockInput, 0));
EndOperation();
// Everything has shifted at this point
Node::InvalidateCache(TimeRange(0, track_length()), kBlockInput);
}
void Track::InsertBlockAtIndex(Block *block, int index)
{
BeginOperation();
int insert_index = GetArrayIndexFromCacheIndex(index);
InputArrayInsert(kBlockInput, insert_index);
Node::ConnectEdge(block, NodeInput(this, kBlockInput, insert_index));
EndOperation();
Node::InvalidateCache(TimeRange(block->in(), track_length()), kBlockInput);
}
void Track::AppendBlock(Block *block)
{
BeginOperation();
InputArrayAppend(kBlockInput);
Node::ConnectEdge(block, NodeInput(this, kBlockInput, InputArraySize(kBlockInput) - 1));
EndOperation();
// Invalidate area that block was added to
Node::InvalidateCache(TimeRange(block->in(), block->out()), kBlockInput);
}
void Track::RippleRemoveBlock(Block *block)
{
BeginOperation();
rational remove_in = block->in();
rational remove_out = block->out();
InputArrayRemove(kBlockInput, GetArrayIndexFromBlock(block));
EndOperation();
Node::InvalidateCache(TimeRange(remove_in, qMax(track_length(), remove_out)), kBlockInput);
}
void Track::ReplaceBlock(Block *old, Block *replace)
{
BeginOperation();
int index_of_old_block = GetArrayIndexFromBlock(old);
DisconnectEdge(old, NodeInput(this, kBlockInput, index_of_old_block));
ConnectEdge(replace, NodeInput(this, kBlockInput, index_of_old_block));
EndOperation();
if (old->length() == replace->length()) {
Node::InvalidateCache(TimeRange(replace->in(), replace->out()), kBlockInput);
} else {