moved input signals to graph to prevent signal desyncs

This commit is contained in:
itsmattkc
2021-01-14 10:32:42 +11:00
parent ad0cefecaf
commit b83677e319
8 changed files with 74 additions and 30 deletions
+33
View File
@@ -44,15 +44,48 @@ void NodeGraph::childEvent(QChildEvent *event)
if (event->type() == QEvent::ChildAdded) {
node_children_.append(node);
// Connect to each input
foreach (NodeInput* input, node->parameters()) {
connect(input, &NodeInput::InputConnected, this, &NodeGraph::SignalInputConnected);
connect(input, &NodeInput::InputDisconnected, this, &NodeGraph::SignalInputDisconnected);
connect(input, &NodeInput::ValueChanged, this, &NodeGraph::SignalValueChanged);
}
emit NodeAdded(node);
} else if (event->type() == QEvent::ChildRemoved) {
node_children_.removeOne(node);
// Disconnect from inputs
foreach (NodeInput* input, node->parameters()) {
disconnect(input, &NodeInput::InputConnected, this, &NodeGraph::SignalInputConnected);
disconnect(input, &NodeInput::InputDisconnected, this, &NodeGraph::SignalInputDisconnected);
disconnect(input, &NodeInput::ValueChanged, this, &NodeGraph::SignalValueChanged);
}
emit NodeRemoved(node);
}
}
}
void NodeGraph::SignalInputConnected(Node *output, int element)
{
emit InputConnected(output, static_cast<NodeInput*>(sender()), element);
}
void NodeGraph::SignalInputDisconnected(Node *output, int element)
{
emit InputDisconnected(output, static_cast<NodeInput*>(sender()), element);
}
void NodeGraph::SignalValueChanged(const TimeRange &range, int element)
{
Q_UNUSED(range)
emit ValueChanged(static_cast<NodeInput*>(sender()), element);
}
}
+13
View File
@@ -65,12 +65,25 @@ signals:
*/
void NodeRemoved(Node* node);
void InputConnected(Node* output, NodeInput* input, int element);
void InputDisconnected(Node* output, NodeInput* input, int element);
void ValueChanged(NodeInput* input, int element);
protected:
virtual void childEvent(QChildEvent* event) override;
private:
QVector<Node*> node_children_;
private slots:
void SignalInputConnected(Node* output, int element);
void SignalInputDisconnected(Node* output, int element);
void SignalValueChanged(const TimeRange& range, int element);
};
}
+9 -3
View File
@@ -100,9 +100,8 @@ TimeRange Track::InputTimeAdjustment(NodeInput *input, int element, const TimeRa
{
if (input == block_input_ && element >= 0) {
int cache_index = GetCacheIndexFromArrayIndex(element);
const rational& block_in = blocks_.at(cache_index)->in();
return input_time - block_in;
return TransformRangeForBlock(blocks_.at(cache_index), input_time);
}
return Node::InputTimeAdjustment(input, element, input_time);
@@ -120,6 +119,11 @@ TimeRange Track::OutputTimeAdjustment(NodeInput *input, int element, const TimeR
return Node::OutputTimeAdjustment(input, element, input_time);
}
TimeRange Track::TransformRangeForBlock(Block *block, const TimeRange &range)
{
return range - block->in();
}
const double &Track::GetTrackHeight() const
{
return track_height_;
@@ -229,7 +233,9 @@ Block *Track::BlockAtTime(const rational &time) const
return nullptr;
}
foreach (Block* block, blocks_) {
for (int i=0; i<blocks_.size(); i++) {
Block* block = blocks_.at(i);
if (block
&& block->in() <= time
&& block->out() > time) {
+2
View File
@@ -60,6 +60,8 @@ public:
virtual TimeRange OutputTimeAdjustment(NodeInput* input, int element, const TimeRange& input_time) const override;
static TimeRange TransformRangeForBlock(Block* block, const TimeRange& range);
const double& GetTrackHeight() const;
void SetTrackHeight(const double& height);
+1 -1
View File
@@ -128,7 +128,7 @@ NodeValueTable NodeTraverser::GenerateBlockTable(const Track *track, const TimeR
NodeValueTable table;
if (active_block) {
table = GenerateTable(active_block, range);
table = GenerateTable(active_block, Track::TransformRangeForBlock(active_block, range));
}
return table;
+12 -22
View File
@@ -294,13 +294,6 @@ void PreviewAutoCacher::AddNode(Node *node)
// Copy parameters
Node::CopyInputs(node, copy, false);
// Connect to each input
foreach (NodeInput* input, node->parameters()) {
connect(input, &NodeInput::InputConnected, this, &PreviewAutoCacher::EdgeAdded);
connect(input, &NodeInput::InputDisconnected, this, &PreviewAutoCacher::EdgeRemoved);
connect(input, &NodeInput::ValueChanged, this, &PreviewAutoCacher::ValueChanged);
}
}
void PreviewAutoCacher::RemoveNode(Node *node)
@@ -310,13 +303,6 @@ void PreviewAutoCacher::RemoveNode(Node *node)
// Delete it
delete copy;
// Disconnect from inputs
foreach (NodeInput* input, node->parameters()) {
disconnect(input, &NodeInput::InputConnected, this, &PreviewAutoCacher::EdgeAdded);
disconnect(input, &NodeInput::InputDisconnected, this, &PreviewAutoCacher::EdgeRemoved);
disconnect(input, &NodeInput::ValueChanged, this, &PreviewAutoCacher::ValueChanged);
}
}
void PreviewAutoCacher::AddEdge(Node *output, NodeInput *input, int element)
@@ -445,21 +431,19 @@ void PreviewAutoCacher::NodeRemoved(Node *node)
graph_update_queue_.append({QueuedJob::kNodeRemoved, node, nullptr, -1});
}
void PreviewAutoCacher::EdgeAdded(Node *output, int element)
void PreviewAutoCacher::EdgeAdded(Node *output, NodeInput *input, int element)
{
graph_update_queue_.append({QueuedJob::kEdgeAdded, output, static_cast<NodeInput*>(sender()), element});
graph_update_queue_.append({QueuedJob::kEdgeAdded, output, input, element});
}
void PreviewAutoCacher::EdgeRemoved(Node *output, int element)
void PreviewAutoCacher::EdgeRemoved(Node *output, NodeInput *input, int element)
{
graph_update_queue_.append({QueuedJob::kEdgeRemoved, output, static_cast<NodeInput*>(sender()), element});
graph_update_queue_.append({QueuedJob::kEdgeRemoved, output, input, element});
}
void PreviewAutoCacher::ValueChanged(const TimeRange &range, int element)
void PreviewAutoCacher::ValueChanged(NodeInput *input, int element)
{
Q_UNUSED(range)
graph_update_queue_.append({QueuedJob::kValueChanged, nullptr, static_cast<NodeInput*>(sender()), element});
graph_update_queue_.append({QueuedJob::kValueChanged, nullptr, input, element});
}
void PreviewAutoCacher::VideoParamsChanged()
@@ -647,6 +631,9 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
disconnect(graph, &NodeGraph::NodeAdded, this, &PreviewAutoCacher::NodeAdded);
disconnect(graph, &NodeGraph::NodeRemoved, this, &PreviewAutoCacher::NodeRemoved);
disconnect(graph, &NodeGraph::InputConnected, this, &PreviewAutoCacher::EdgeAdded);
disconnect(graph, &NodeGraph::InputDisconnected, this, &PreviewAutoCacher::EdgeRemoved);
disconnect(graph, &NodeGraph::ValueChanged, this, &PreviewAutoCacher::ValueChanged);
// Disconnect signal (will be a no-op if the signal was never connected)
disconnect(viewer_node_,
@@ -702,6 +689,9 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
// Connect signals for future node additions/deletions
connect(graph, &NodeGraph::NodeAdded, this, &PreviewAutoCacher::NodeAdded);
connect(graph, &NodeGraph::NodeRemoved, this, &PreviewAutoCacher::NodeRemoved);
connect(graph, &NodeGraph::InputConnected, this, &PreviewAutoCacher::EdgeAdded);
connect(graph, &NodeGraph::InputDisconnected, this, &PreviewAutoCacher::EdgeRemoved);
connect(graph, &NodeGraph::ValueChanged, this, &PreviewAutoCacher::ValueChanged);
// Copy invalidated ranges - used to determine which frames need hashing
invalidated_video_ = viewer_node_->video_frame_cache()->GetInvalidatedRanges();
+3 -3
View File
@@ -201,11 +201,11 @@ private slots:
void NodeRemoved(Node* node);
void EdgeAdded(Node* output, int element);
void EdgeAdded(Node* output, NodeInput* input, int element);
void EdgeRemoved(Node* output, int element);
void EdgeRemoved(Node* output, NodeInput* input, int element);
void ValueChanged(const TimeRange& range, int element);
void ValueChanged(NodeInput* input, int element);
void VideoParamsChanged();
+1 -1
View File
@@ -210,7 +210,7 @@ NodeValueTable RenderProcessor::GenerateBlockTable(const Track *track, const Tim
int max_dest_sz = audio_params.time_to_samples(range_for_block.length());
// Destination buffer
NodeValueTable table = GenerateTable(b, range_for_block);
NodeValueTable table = GenerateTable(b, Track::TransformRangeForBlock(b, range_for_block));
SampleBufferPtr samples_from_this_block = table.Take(NodeValue::kSamples).value<SampleBufferPtr>();
if (!samples_from_this_block) {