Skip to content

Commit aee7728

Browse files
authored
Merge pull request #1040 from kushview/audio-io-no-ports
Ensure IONode's Parent Graph Has a Minimum Channel Count
2 parents db46de2 + ac7b829 commit aee7728

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

.github/copilot-instructions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@
1212
- Write clear, readable code with descriptive names for variables, functions, and classes.
1313
- Maintain consistency with the existing codebase style and patterns.
1414
- Consider maintainability and future developers who will read the code.
15+
16+
## Audio Graph Architecture
17+
18+
- **IONodes** (audio/MIDI input/output) require a parent `GraphNode` to be set before ports can be properly initialized.
19+
- `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.
20+
- When adding IONodes, ensure the parent graph has a valid port count first using `graph->setNumPorts()`.
21+
- Default port counts: 2 channels for audio (stereo), 1 channel for MIDI.
22+
- Message flow for adding nodes: `AddPluginMessage``AddPluginAction::perform()``EngineService::addPlugin()``GraphManager::addNode()`.

src/engine/ionode.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ bool IONode::isOutput() const { return type == audioOutputNode || type == midiOu
183183
void IONode::setParentGraph (GraphNode* const newGraph)
184184
{
185185
graph = newGraph;
186+
187+
// Ensure the parent graph has a minimum port count for this IONode's type.
188+
// Default: 2 channels for audio (stereo), 1 channel for MIDI.
189+
if (graph != nullptr)
190+
{
191+
const auto portType = getPortType();
192+
const int currentCount = graph->getNumPorts (portType, isInput());
193+
if (currentCount == 0)
194+
{
195+
const int defaultCount = (portType == PortType::Audio) ? 2 : 1;
196+
graph->setNumPorts (portType, defaultCount, isInput(), false);
197+
}
198+
}
199+
186200
refreshPorts();
187201
}
188202

test/audioroutingtests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,4 +1032,33 @@ BOOST_AUTO_TEST_CASE (AudioFeedbackPrevention)
10321032
BOOST_REQUIRE (! feedbackAllowed);
10331033
}
10341034

1035+
BOOST_AUTO_TEST_CASE (IONodeMinimumAudioPortCount)
1036+
{
1037+
// Test that Audio I/O nodes get a minimum port count when added to a graph with zero audio ports
1038+
// This prevents the bug where Audio Input/Output nodes appear with zero ports
1039+
1040+
PreparedGraph fix;
1041+
GraphNode& graph = fix.graph;
1042+
1043+
fix.graph.clear();
1044+
graph.setNumPorts (PortType::Audio, 0, true, false);
1045+
graph.setNumPorts (PortType::Audio, 0, false, false);
1046+
1047+
// Verify graph starts with zero audio ports configured
1048+
BOOST_REQUIRE_EQUAL (graph.getNumPorts (PortType::Audio, true), 0);
1049+
BOOST_REQUIRE_EQUAL (graph.getNumPorts (PortType::Audio, false), 0);
1050+
1051+
// Add Audio Input node - should set graph audio inputs to minimum 2 (stereo)
1052+
auto* audioIn = new IONode (IONode::audioInputNode);
1053+
graph.addNode (audioIn);
1054+
BOOST_REQUIRE_EQUAL (graph.getNumPorts (PortType::Audio, true), 2);
1055+
BOOST_REQUIRE_EQUAL (audioIn->getNumPorts(), 2);
1056+
1057+
// Add Audio Output node - should set graph audio outputs to minimum 2 (stereo)
1058+
auto* audioOut = new IONode (IONode::audioOutputNode);
1059+
graph.addNode (audioOut);
1060+
BOOST_REQUIRE_EQUAL (graph.getNumPorts (PortType::Audio, false), 2);
1061+
BOOST_REQUIRE_EQUAL (audioOut->getNumPorts(), 2);
1062+
}
1063+
10351064
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)