Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@
- Write clear, readable code with descriptive names for variables, functions, and classes.
- Maintain consistency with the existing codebase style and patterns.
- Consider maintainability and future developers who will read the code.

## Audio Graph Architecture

- **IONodes** (audio/MIDI input/output) require a parent `GraphNode` to be set before ports can be properly initialized.
- `IONode::refreshPorts()` queries the parent graph's port count via `graph->getNumPorts()`. If the parent is null or has zero ports, the IONode will have zero ports.
- When adding IONodes, ensure the parent graph has a valid port count first using `graph->setNumPorts()`.
- Default port counts: 2 channels for audio (stereo), 1 channel for MIDI.
- Message flow for adding nodes: `AddPluginMessage` → `AddPluginAction::perform()` → `EngineService::addPlugin()` → `GraphManager::addNode()`.
14 changes: 14 additions & 0 deletions src/engine/ionode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ bool IONode::isOutput() const { return type == audioOutputNode || type == midiOu
void IONode::setParentGraph (GraphNode* const newGraph)
{
graph = newGraph;

// Ensure the parent graph has a minimum port count for this IONode's type.
// Default: 2 channels for audio (stereo), 1 channel for MIDI.
if (graph != nullptr)
{
const auto portType = getPortType();
const int currentCount = graph->getNumPorts (portType, isInput());
if (currentCount == 0)
{
const int defaultCount = (portType == PortType::Audio) ? 2 : 1;
graph->setNumPorts (portType, defaultCount, isInput(), false);
}
}

refreshPorts();
}

Expand Down
29 changes: 29 additions & 0 deletions test/audioroutingtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,4 +1032,33 @@ BOOST_AUTO_TEST_CASE (AudioFeedbackPrevention)
BOOST_REQUIRE (! feedbackAllowed);
}

BOOST_AUTO_TEST_CASE (IONodeMinimumAudioPortCount)
{
// Test that Audio I/O nodes get a minimum port count when added to a graph with zero audio ports
// This prevents the bug where Audio Input/Output nodes appear with zero ports

PreparedGraph fix;
GraphNode& graph = fix.graph;

fix.graph.clear();
graph.setNumPorts (PortType::Audio, 0, true, false);
graph.setNumPorts (PortType::Audio, 0, false, false);

// Verify graph starts with zero audio ports configured
BOOST_REQUIRE_EQUAL (graph.getNumPorts (PortType::Audio, true), 0);
BOOST_REQUIRE_EQUAL (graph.getNumPorts (PortType::Audio, false), 0);

// Add Audio Input node - should set graph audio inputs to minimum 2 (stereo)
auto* audioIn = new IONode (IONode::audioInputNode);
graph.addNode (audioIn);
BOOST_REQUIRE_EQUAL (graph.getNumPorts (PortType::Audio, true), 2);
BOOST_REQUIRE_EQUAL (audioIn->getNumPorts(), 2);

// Add Audio Output node - should set graph audio outputs to minimum 2 (stereo)
auto* audioOut = new IONode (IONode::audioOutputNode);
graph.addNode (audioOut);
BOOST_REQUIRE_EQUAL (graph.getNumPorts (PortType::Audio, false), 2);
BOOST_REQUIRE_EQUAL (audioOut->getNumPorts(), 2);
}

BOOST_AUTO_TEST_SUITE_END()
Loading