DSPatch v.9.3.2
Loading...
Searching...
No Matches
Component.h
1/******************************************************************************
2DSPatch - The Refreshingly Simple C++ Dataflow Framework
3Copyright (c) 2023, Marcus Tomlinson
4
5BSD 2-Clause License
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are met:
9
101. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27******************************************************************************/
28
29#pragma once
30
31#include <dspatch/SignalBus.h>
32
33#include <string>
34#include <vector>
35
36namespace DSPatch
37{
38
39namespace internal
40{
41class Component;
42class ComponentThread;
43} // namespace internal
44
46
74class DLLEXPORT Component
75{
76public:
77 NONCOPYABLE( Component );
78
79 using SPtr = std::shared_ptr<Component>;
80 using SCPtr = std::shared_ptr<const Component>;
81
82 enum class ProcessOrder
83 {
84 InOrder,
85 OutOfOrder
86 };
87
88 enum class TickMode
89 {
90 Series,
91 Parallel
92 };
93
94 Component( ProcessOrder processOrder = ProcessOrder::InOrder );
95 virtual ~Component();
96
97 bool ConnectInput( const Component::SPtr& fromComponent, int fromOutput, int toInput );
98
99 void DisconnectInput( int inputNo );
100 void DisconnectInput( const Component::SCPtr& fromComponent );
101 void DisconnectAllInputs();
102
103 int GetInputCount() const;
104 int GetOutputCount() const;
105
106 std::string GetInputName( int inputNo ) const;
107 std::string GetOutputName( int outputNo ) const;
108
109 void SetBufferCount( int bufferCount );
110 int GetBufferCount() const;
111
112 void Tick( TickMode mode = TickMode::Series, int bufferNo = 0 );
113 void Reset( TickMode mode = TickMode::Series, int bufferNo = 0 );
114
115protected:
116 virtual void Process_( SignalBus&, SignalBus& ) = 0;
117
118 void SetInputCount_( int inputCount, const std::vector<std::string>& inputNames = {} );
119 void SetOutputCount_( int outputCount, const std::vector<std::string>& outputNames = {} );
120
121private:
122 friend class internal::ComponentThread;
123 void _DoTick( Component::TickMode mode, int bufferNo );
124
125 internal::Component* p;
126};
127
128} // namespace DSPatch
Abstract base class for DSPatch components.
Definition: Component.h:75
Signal container.
Definition: SignalBus.h:48
Thread class for asynchronously ticking a single circuit component.