ngscopeclient 0.1-dev+51fbda87c
FlowGraphNode.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
36#ifndef FlowGraphNode_h
37#define FlowGraphNode_h
38
40class WaveformBase;
42
43#include "FilterParameter.h"
44#include "Waveform.h"
45#include "Stream.h"
46
54{
55public:
57 virtual ~FlowGraphNode();
58
59 void DetachInputs();
60
61 //Inputs
62public:
63 size_t GetInputCount();
64 std::string GetInputName(size_t i);
65
66 void SetInput(size_t i, StreamDescriptor stream, bool force = false);
67 void SetInput(const std::string& name, StreamDescriptor stream, bool force = false);
68 virtual bool ValidateChannel(size_t i, StreamDescriptor stream);
69
70 StreamDescriptor GetInput(size_t i);
71
72protected:
73 virtual void OnInputChanged(size_t i);
74
75 //Parameters
76public:
77 FilterParameter& GetParameter(std::string s);
78
80 typedef std::map<std::string, FilterParameter> ParameterMapType;
81
89 bool HasParameter(std::string s)
90 { return (m_parameters.find(s) != m_parameters.end()); }
91
93 ParameterMapType::iterator GetParamBegin()
94 { return m_parameters.begin(); }
95
97 ParameterMapType::iterator GetParamEnd()
98 { return m_parameters.end(); }
99
102 { return m_parameters.size(); }
103
109 virtual YAML::Node SerializeConfiguration(IDTable& table);
110
114 virtual void LoadParameters(const YAML::Node& node, IDTable& table);
115 virtual void LoadInputs(const YAML::Node& node, IDTable& table);
116
117 bool IsDownstreamOf(std::set<FlowGraphNode*> nodes);
118
120 // Accelerated waveform accessors
121
122 enum DataLocation
123 {
124 LOC_CPU,
125 LOC_GPU,
126 LOC_DONTCARE
127 };
128
129 virtual DataLocation GetInputLocation();
130
132 // Filter evaluation
133 [[deprecated]]
134 virtual void Refresh();
135
136 //Filter evaluation (GPU accelerated)
137 virtual void Refresh(vk::raii::CommandBuffer& cmdBuf, std::shared_ptr<QueueHandle> queue);
138
139 //Input handling helpers
140protected:
141
147 WaveformBase* GetInputWaveform(size_t i); //implementation in FlowGraphNode_inlines.h
148
151 { return dynamic_cast<SparseAnalogWaveform*>(GetInputWaveform(i)); }
152
155 { return dynamic_cast<UniformAnalogWaveform*>(GetInputWaveform(i)); }
156
159 { return dynamic_cast<SparseDigitalWaveform*>(GetInputWaveform(i)); }
160
163 { return dynamic_cast<UniformDigitalWaveform*>(GetInputWaveform(i)); }
164
167 { return dynamic_cast<SparseDigitalBusWaveform*>(GetInputWaveform(i)); }
168
169 void CreateInput(const std::string& name);
170
171 std::string GetInputDisplayName(size_t i);
172
173protected:
175 std::vector<std::string> m_signalNames;
176
178 std::vector<StreamDescriptor> m_inputs;
179
180 //Parameters
181 ParameterMapType m_parameters;
182
183public:
184
185 sigc::signal<void()> signal_parametersChanged()
186 { return m_parametersChangedSignal; }
187
188 sigc::signal<void()> signal_inputsChanged()
189 { return m_inputsChangedSignal; }
190
191protected:
192
194 sigc::signal<void()> m_parametersChangedSignal;
195
197 sigc::signal<void()> m_inputsChangedSignal;
198};
199
200#endif
Declaration of FilterParameter.
Declaration of Stream.
Declaration of WaveformBase, SparseWaveformBase, UniformWaveformBase.
A parameter to a filter.
Definition: FilterParameter.h:86
Abstract base class for a node in the signal flow graph.
Definition: FlowGraphNode.h:54
void CreateInput(const std::string &name)
Creates and names an input signal.
Definition: FlowGraphNode.cpp:279
StreamDescriptor GetInput(size_t i)
Gets the descriptor for one of our inputs.
Definition: FlowGraphNode.cpp:249
bool HasParameter(std::string s)
Checks if we have a parameter with a given name.
Definition: FlowGraphNode.h:89
ParameterMapType::iterator GetParamEnd()
Returns an iterator to the end of our parameter map.
Definition: FlowGraphNode.h:97
ParameterMapType::iterator GetParamBegin()
Returns an iterator to the beginning of our parameter map.
Definition: FlowGraphNode.h:93
virtual YAML::Node SerializeConfiguration(IDTable &table)
Serializes this trigger's configuration to a YAML string.
Definition: FlowGraphNode.cpp:317
std::vector< StreamDescriptor > m_inputs
The channel (if any) connected to each of our inputs.
Definition: FlowGraphNode.h:178
sigc::signal< void()> m_parametersChangedSignal
Signal emitted when the set of parameters changes.
Definition: FlowGraphNode.h:194
SparseAnalogWaveform * GetSparseAnalogInputWaveform(size_t i)
Gets the analog waveform attached to the specified input.
Definition: FlowGraphNode.h:150
size_t GetParamCount()
Returns the number of parameter we have.
Definition: FlowGraphNode.h:101
SparseDigitalWaveform * GetSparseDigitalInputWaveform(size_t i)
Gets the digital waveform attached to the specified input.
Definition: FlowGraphNode.h:158
std::string GetInputDisplayName(size_t i)
Gets the display name for one of our inputs.
Definition: FlowGraphNode.cpp:265
WaveformBase * GetInputWaveform(size_t i)
Gets the waveform attached to the specified input.
Definition: FlowGraphNode_inlines.h:51
bool IsDownstreamOf(std::set< FlowGraphNode * > nodes)
Determines if this node is downstream of any of the specified other nodes.
Definition: FlowGraphNode.cpp:298
sigc::signal< void()> m_inputsChangedSignal
Signal emitted when the set of inputs changes.
Definition: FlowGraphNode.h:197
std::map< std::string, FilterParameter > ParameterMapType
Short name for a map of strings to parameters.
Definition: FlowGraphNode.h:80
std::vector< std::string > m_signalNames
Names of signals we take as input.
Definition: FlowGraphNode.h:175
UniformAnalogWaveform * GetUniformAnalogInputWaveform(size_t i)
Gets the analog waveform attached to the specified input.
Definition: FlowGraphNode.h:154
virtual void Refresh()
Evaluates a filter graph node.
Definition: FlowGraphNode.cpp:87
virtual void OnInputChanged(size_t i)
Called when a new input is connected to the node.
Definition: FlowGraphNode.cpp:149
void SetInput(size_t i, StreamDescriptor stream, bool force=false)
Connects a stream to the input of this node.
Definition: FlowGraphNode.cpp:161
virtual DataLocation GetInputLocation()
Gets the desired location of the nodes's input data.
Definition: FlowGraphNode.cpp:110
SparseDigitalBusWaveform * GetSparseDigitalBusInputWaveform(size_t i)
Gets the digital bus waveform attached to the specified input.
Definition: FlowGraphNode.h:166
UniformDigitalWaveform * GetUniformDigitalInputWaveform(size_t i)
Gets the digital waveform attached to the specified input.
Definition: FlowGraphNode.h:162
void DetachInputs()
Disconnects all inputs from the node without releasing them.
Definition: FlowGraphNode.cpp:72
virtual void LoadParameters(const YAML::Node &node, IDTable &table)
Load configuration from a save file.
Definition: FlowGraphNode.cpp:350
Bidirectional table mapping integer IDs in scopesession files to object pointers.
Definition: IDTable.h:49
A single channel on an oscilloscope.
Definition: OscilloscopeChannel.h:49
A waveform sampled at irregular intervals.
Definition: Waveform.h:460
Descriptor for a single stream coming off a channel.
Definition: StreamDescriptor.h:46
A waveform sampled at uniform intervals.
Definition: Waveform.h:365
Base class for all Waveform specializations.
Definition: Waveform.h:59