From a31cadaa18e7cfe8a9cfe49de464d098e49458be Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 31 Mar 2025 12:21:40 +0100 Subject: [PATCH] AudioProcessorGraph: Add constexpr annotations --- .../processors/juce_AudioProcessorGraph.cpp | 48 ++++------------- .../processors/juce_AudioProcessorGraph.h | 53 +++++++++++++------ 2 files changed, 46 insertions(+), 55 deletions(-) diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp index 7359c13fe2..0a353903ad 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.cpp @@ -1035,20 +1035,20 @@ private: { NodeAndChannel channel; - static AssignedBuffer createReadOnlyEmpty() noexcept { return { { zeroNodeID(), 0 } }; } - static AssignedBuffer createFree() noexcept { return { { freeNodeID(), 0 } }; } + static constexpr AssignedBuffer createReadOnlyEmpty() noexcept { return { { zeroNodeID, 0 } }; } + static constexpr AssignedBuffer createFree() noexcept { return { { freeNodeID, 0 } }; } - bool isReadOnlyEmpty() const noexcept { return channel.nodeID == zeroNodeID(); } - bool isFree() const noexcept { return channel.nodeID == freeNodeID(); } - bool isAssigned() const noexcept { return ! (isReadOnlyEmpty() || isFree()); } + constexpr bool isReadOnlyEmpty() const noexcept { return channel.nodeID == zeroNodeID; } + constexpr bool isFree() const noexcept { return channel.nodeID == freeNodeID; } + constexpr bool isAssigned() const noexcept { return ! (isReadOnlyEmpty() || isFree()); } - void setFree() noexcept { channel = { freeNodeID(), 0 }; } - void setAssignedToNonExistentNode() noexcept { channel = { anonNodeID(), 0 }; } + constexpr void setFree() noexcept { channel = { freeNodeID, 0 }; } + constexpr void setAssignedToNonExistentNode() noexcept { channel = { anonNodeID, 0 }; } private: - static NodeID anonNodeID() { return NodeID (0x7ffffffd); } - static NodeID zeroNodeID() { return NodeID (0x7ffffffe); } - static NodeID freeNodeID() { return NodeID (0x7fffffff); } + constexpr static inline NodeID anonNodeID { 0x7ffffffd }; + constexpr static inline NodeID zeroNodeID { 0x7ffffffe }; + constexpr static inline NodeID freeNodeID { 0x7fffffff }; }; Array audioBuffers, midiBuffers; @@ -1676,34 +1676,6 @@ private: bool isNew = false; }; -//============================================================================== -AudioProcessorGraph::Connection::Connection (NodeAndChannel src, NodeAndChannel dst) noexcept - : source (src), destination (dst) -{ -} - -bool AudioProcessorGraph::Connection::operator== (const Connection& other) const noexcept -{ - return source == other.source && destination == other.destination; -} - -bool AudioProcessorGraph::Connection::operator!= (const Connection& c) const noexcept -{ - return ! operator== (c); -} - -bool AudioProcessorGraph::Connection::operator< (const Connection& other) const noexcept -{ - const auto tie = [] (auto& x) - { - return std::tie (x.source.nodeID, - x.destination.nodeID, - x.source.channelIndex, - x.destination.channelIndex); - }; - return tie (*this) < tie (other); -} - //============================================================================== class AudioProcessorGraph::Pimpl { diff --git a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h index 987d980a95..48983bdf35 100644 --- a/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h +++ b/modules/juce_audio_processors/processors/juce_AudioProcessorGraph.h @@ -67,14 +67,14 @@ public: /** Each node in the graph has a UID of this type. */ struct NodeID { - NodeID() {} - explicit NodeID (uint32 i) : uid (i) {} + constexpr NodeID() = default; + explicit constexpr NodeID (uint32 i) : uid (i) {} uint32 uid = 0; - bool operator== (const NodeID& other) const noexcept { return uid == other.uid; } - bool operator!= (const NodeID& other) const noexcept { return uid != other.uid; } - bool operator< (const NodeID& other) const noexcept { return uid < other.uid; } + constexpr bool operator== (const NodeID& other) const noexcept { return uid == other.uid; } + constexpr bool operator!= (const NodeID& other) const noexcept { return uid != other.uid; } + constexpr bool operator< (const NodeID& other) const noexcept { return uid < other.uid; } }; //============================================================================== @@ -91,17 +91,17 @@ public: */ class NodeAndChannel { - auto tie() const { return std::tie (nodeID, channelIndex); } + constexpr auto tie() const { return std::tie (nodeID, channelIndex); } public: NodeID nodeID; int channelIndex; - bool isMIDI() const noexcept { return channelIndex == midiChannelIndex; } + constexpr bool isMIDI() const noexcept { return channelIndex == midiChannelIndex; } - bool operator== (const NodeAndChannel& other) const noexcept { return tie() == other.tie(); } - bool operator!= (const NodeAndChannel& other) const noexcept { return tie() != other.tie(); } - bool operator< (const NodeAndChannel& other) const noexcept { return tie() < other.tie(); } + constexpr bool operator== (const NodeAndChannel& other) const noexcept { return tie() == other.tie(); } + constexpr bool operator!= (const NodeAndChannel& other) const noexcept { return tie() != other.tie(); } + constexpr bool operator< (const NodeAndChannel& other) const noexcept { return tie() < other.tie(); } }; //============================================================================== @@ -192,15 +192,34 @@ public: struct JUCE_API Connection { //============================================================================== - Connection() = default; - Connection (NodeAndChannel source, NodeAndChannel destination) noexcept; + constexpr Connection() = default; + constexpr Connection (NodeAndChannel sourceIn, NodeAndChannel destinationIn) noexcept + : source (sourceIn), destination (destinationIn) {} - Connection (const Connection&) = default; - Connection& operator= (const Connection&) = default; + constexpr Connection (const Connection&) = default; + constexpr Connection& operator= (const Connection&) = default; - bool operator== (const Connection&) const noexcept; - bool operator!= (const Connection&) const noexcept; - bool operator< (const Connection&) const noexcept; + constexpr bool operator== (const Connection& other) const noexcept + { + return source == other.source && destination == other.destination; + } + + constexpr bool operator!= (const Connection& other) const noexcept + { + return ! operator== (other); + } + + constexpr bool operator< (const Connection& other) const noexcept + { + const auto tie = [] (auto& x) + { + return std::tie (x.source.nodeID, + x.destination.nodeID, + x.source.channelIndex, + x.destination.channelIndex); + }; + return tie (*this) < tie (other); + } //============================================================================== /** The channel and node which is the input source for this connection. */