Skip to content

Commit

Permalink
Stop node monitors when node disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Jan 21, 2024
1 parent cc27f47 commit f9cb5dc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions source/include/signalflow/core/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AudioGraph

/**--------------------------------------------------------------------------------
* Remove all nodes from the graph.
* Also removes NodeMonitors.
*
**--------------------------------------------------------------------------------*/
void clear();
Expand Down
4 changes: 2 additions & 2 deletions source/include/signalflow/node/node-monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NodeMonitor
* @param label The label to use when printing the output
* @param frequency How often to print, in seconds
*-----------------------------------------------------------------------*/
NodeMonitor(NodeRef node, std::string label, float frequency);
NodeMonitor(Node *node, std::string label, float frequency);

/**------------------------------------------------------------------------
* Start monitoring.
Expand All @@ -37,7 +37,7 @@ class NodeMonitor

private:
void run_thread();
NodeRef node;
Node *node;
float frequency;
bool running;
std::string label;
Expand Down
5 changes: 5 additions & 0 deletions source/src/core/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ void AudioGraph::reset_graph()
*--------------------------------------------------------------------------------*/
for (auto node : nodes_to_remove)
{
/*--------------------------------------------------------------------------------
* Stop any monitoring running on the node.
*--------------------------------------------------------------------------------*/
node->poll(0);

while (node->outputs.size() > 0)
{
auto output = *(node->outputs.begin());
Expand Down
2 changes: 1 addition & 1 deletion source/src/node/node-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace signalflow
{

NodeMonitor::NodeMonitor(NodeRef node, std::string label, float frequency)
NodeMonitor::NodeMonitor(Node *node, std::string label, float frequency)
: node(node), frequency(frequency), label(label)
{
if (label == "")
Expand Down
4 changes: 4 additions & 0 deletions source/src/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ Node::Node()

Node::~Node()
{
if (this->monitor)
{
this->monitor->stop();
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit f9cb5dc

Please sign in to comment.