diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 4e2bc5d80c..4e155a3a75 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -2,6 +2,30 @@ # develop +## Change + +The NodeID argument to AudioProcessorGraph::addNode() has been changed to take +a std::optional. + +**Possible Issues** + +The behavior of any code calling AudioProcessorGraph::addNode(), that explicitly +passes a default constructed NodeID or a NodeID constructed with a value of 0, +will change. Previously these values would have been treated as a null value +resulting in the actual NodeID being automatically determined. These will now +be treated as requests for an explicit value. + +**Workaround** + +Either remove the explicit NodeID argument and rely on the default argument or +pass a std::nullopt instead. + +**Rationale** + +The previous version prevented users from specifying a NodeID of 0 and resulted +in unexpected behavior. + + ## Change The signature of DynamicObject::writeAsJSON() has been changed to accept a diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp index 6f80d24a80..00c1e3990b 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp @@ -1694,7 +1694,7 @@ public: } Node::Ptr addNode (std::unique_ptr newProcessor, - const NodeID nodeID, + std::optional nodeID, UpdateKind updateKind) { if (newProcessor.get() == owner) @@ -1703,7 +1703,7 @@ public: return nullptr; } - const auto idToUse = nodeID == NodeID() ? NodeID { ++(lastNodeID.uid) } : nodeID; + const auto idToUse = nodeID.value_or (NodeID { lastNodeID.uid + 1 }); auto added = nodes.addNode (std::move (newProcessor), idToUse); @@ -1957,7 +1957,7 @@ bool AudioProcessorGraph::isAnInputTo (const Node& source, const Node& destinati bool AudioProcessorGraph::isAnInputTo (NodeID source, NodeID destination) const noexcept { return pimpl->isAnInputTo (source, destination); } AudioProcessorGraph::Node::Ptr AudioProcessorGraph::addNode (std::unique_ptr newProcessor, - NodeID nodeId, + std::optional nodeId, UpdateKind updateKind) { return pimpl->addNode (std::move (newProcessor), nodeId, updateKind); diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h index 62dda07de4..7533a933e7 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h @@ -252,7 +252,7 @@ public: If this succeeds, it returns a pointer to the newly-created node. */ - Node::Ptr addNode (std::unique_ptr newProcessor, NodeID nodeId = {}, UpdateKind = UpdateKind::sync); + Node::Ptr addNode (std::unique_ptr newProcessor, std::optional nodeId = std::nullopt, UpdateKind = UpdateKind::sync); /** Deletes a node within the graph which has the specified ID. This will also delete any connections that are attached to this node.