|
| 1 | +/* |
| 2 | + ============================================================================== |
| 3 | +
|
| 4 | + This file is part of the YUP library. |
| 5 | + Copyright (c) 2026 - kunitoki@gmail.com |
| 6 | +
|
| 7 | + YUP is an open source library subject to open-source licensing. |
| 8 | +
|
| 9 | + The code included in this file is provided under the terms of the ISC license |
| 10 | + http://www.isc.org/downloads/software-support-policy/isc-license. Permission |
| 11 | + to use, copy, modify, and/or distribute this software for any purpose with or |
| 12 | + without fee is hereby granted provided that the above copyright notice and |
| 13 | + this permission notice appear in all copies. |
| 14 | +
|
| 15 | + YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER |
| 16 | + EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE |
| 17 | + DISCLAIMED. |
| 18 | +
|
| 19 | + ============================================================================== |
| 20 | +*/ |
| 21 | + |
| 22 | +namespace yup |
| 23 | +{ |
| 24 | + |
| 25 | +//============================================================================== |
| 26 | +/** |
| 27 | + Describes one routable audio or MIDI endpoint in an AudioGraphProcessor. |
| 28 | +
|
| 29 | + Source endpoints are graphInput() and nodeOutput(). Destination endpoints are |
| 30 | + graphOutput() and nodeInput(). The bus index refers to the AudioBusLayout of the |
| 31 | + graph or the addressed processor node. |
| 32 | +*/ |
| 33 | +class AudioGraphEndpoint |
| 34 | +{ |
| 35 | +public: |
| 36 | + /** The endpoint owner and direction. */ |
| 37 | + enum class Kind |
| 38 | + { |
| 39 | + graphInput, |
| 40 | + graphOutput, |
| 41 | + nodeInput, |
| 42 | + nodeOutput |
| 43 | + }; |
| 44 | + |
| 45 | + /** Creates an invalid graph input endpoint. */ |
| 46 | + AudioGraphEndpoint() = default; |
| 47 | + |
| 48 | + /** Creates a source endpoint for one graph input bus. */ |
| 49 | + static AudioGraphEndpoint graphInput (int busIndex) noexcept |
| 50 | + { |
| 51 | + return AudioGraphEndpoint (Kind::graphInput, AudioGraphNodeID::invalid(), busIndex); |
| 52 | + } |
| 53 | + |
| 54 | + /** Creates a destination endpoint for one graph output bus. */ |
| 55 | + static AudioGraphEndpoint graphOutput (int busIndex) noexcept |
| 56 | + { |
| 57 | + return AudioGraphEndpoint (Kind::graphOutput, AudioGraphNodeID::invalid(), busIndex); |
| 58 | + } |
| 59 | + |
| 60 | + /** Creates a destination endpoint for one node input bus. */ |
| 61 | + static AudioGraphEndpoint nodeInput (AudioGraphNodeID nodeID, int busIndex) noexcept |
| 62 | + { |
| 63 | + return AudioGraphEndpoint (Kind::nodeInput, nodeID, busIndex); |
| 64 | + } |
| 65 | + |
| 66 | + /** Creates a source endpoint for one node output bus. */ |
| 67 | + static AudioGraphEndpoint nodeOutput (AudioGraphNodeID nodeID, int busIndex) noexcept |
| 68 | + { |
| 69 | + return AudioGraphEndpoint (Kind::nodeOutput, nodeID, busIndex); |
| 70 | + } |
| 71 | + |
| 72 | + /** Returns the endpoint kind. */ |
| 73 | + Kind getKind() const noexcept { return kind; } |
| 74 | + |
| 75 | + /** Returns the addressed node, or an invalid ID for graph endpoints. */ |
| 76 | + AudioGraphNodeID getNodeID() const noexcept { return nodeID; } |
| 77 | + |
| 78 | + /** Returns the bus index on the graph or processor layout. */ |
| 79 | + int getBusIndex() const noexcept { return busIndex; } |
| 80 | + |
| 81 | + /** Returns true when this endpoint can appear as a connection source. */ |
| 82 | + bool isSource() const noexcept { return kind == Kind::graphInput || kind == Kind::nodeOutput; } |
| 83 | + |
| 84 | + /** Returns true when this endpoint can appear as a connection destination. */ |
| 85 | + bool isDestination() const noexcept { return kind == Kind::graphOutput || kind == Kind::nodeInput; } |
| 86 | + |
| 87 | + bool operator== (const AudioGraphEndpoint& other) const noexcept |
| 88 | + { |
| 89 | + return kind == other.kind && nodeID == other.nodeID && busIndex == other.busIndex; |
| 90 | + } |
| 91 | + |
| 92 | + bool operator!= (const AudioGraphEndpoint& other) const noexcept { return ! (*this == other); } |
| 93 | + |
| 94 | +private: |
| 95 | + AudioGraphEndpoint (Kind endpointKind, AudioGraphNodeID endpointNodeID, int endpointBusIndex) noexcept |
| 96 | + : kind (endpointKind) |
| 97 | + , nodeID (endpointNodeID) |
| 98 | + , busIndex (endpointBusIndex) |
| 99 | + { |
| 100 | + } |
| 101 | + |
| 102 | + Kind kind = Kind::graphInput; |
| 103 | + AudioGraphNodeID nodeID; |
| 104 | + int busIndex = -1; |
| 105 | +}; |
| 106 | + |
| 107 | +} // namespace yup |
0 commit comments