MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Operators.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Timers.hpp"
4
5namespace MayaFlux::Kriya {
6
7/**
8 * @class NodeTimeSpec
9 * @brief Represents a timed activation operation for processing nodes
10 *
11 * The NodeTimeSpec class encapsulates the concept of activating a processing node
12 * for a specific duration. It's designed to be used with the stream operator (>>)
13 * to create a fluent, expressive syntax for computational flow programming.
14 *
15 * This approach is inspired by flow-based programming paradigms, which use
16 * operators to express data flow and timing relationships. It allows for a more
17 * intuitive, declarative way of expressing temporal operations compared to traditional
18 * function calls.
19 *
20 * Example usage:
21 * ```cpp
22 * // Activate a processing node for 2 seconds
23 * process_node >> Time(2.0);
24 *
25 * // Equivalent to:
26 * // NodeTimer timer(*scheduler, *graph_manager);
27 * // timer.play_for(process_node, 2.0);
28 * ```
29 *
30 * The NodeTimeSpec is part of a broader pattern of using operator overloading
31 * to create a domain-specific language for computational flow programming within C++.
32 */
33class MAYAFLUX_API NodeTimeSpec {
34public:
35 /**
36 * @brief Constructs a NodeTimeSpec with the specified duration
37 * @param seconds Duration of the operation in seconds
38 * @param channels Optional list of channels to activate; if not provided, all active channels are used
39 *
40 * This constructor is typically used internally by the Time() factory function.
41 * It creates a NodeTimeSpec that will use the global scheduler and graph manager.
42 */
43 NodeTimeSpec(double seconds, std::optional<std::vector<uint32_t>> channels = std::nullopt);
44
45 /**
46 * @brief Constructs a NodeTimeSpec with explicit scheduler and graph manager
47 * @param seconds Duration of the operation in seconds
48 * @param scheduler The TaskScheduler to use for timing
49 * @param graph_manager The NodeGraphManager to use for node connections
50 *
51 * This constructor allows for more control over which scheduler and graph manager
52 * are used, which is useful in contexts where multiple processing engines might exist.
53 */
54 NodeTimeSpec(double seconds, Vruta::TaskScheduler& scheduler, Nodes::NodeGraphManager& graph_manager);
55
56 /**
57 * @brief Gets the duration of this operation
58 * @return Duration in seconds
59 *
60 * This method returns the time duration associated with this operation,
61 * which determines how long a node will remain active when connected to this operation.
62 */
63 [[nodiscard]] inline double get_seconds() const { return m_seconds; }
64
65 /**
66 * @brief Checks if explicit channels were specified
67 * @return True if specific channels were provided, false if all active channels should be used
68 *
69 * This method indicates whether the operation was created with an explicit
70 * list of channels to activate. If false, the operation will use all channels
71 * that the node is currently active on.
72 */
73 [[nodiscard]] bool has_explicit_channels() const { return m_channels.has_value(); }
74
75 /**
76 * @brief Gets the list of channels to activate
77 * @return Reference to the vector of channel indices
78 *
79 * This method returns the list of channels that were specified when creating
80 * this operation. If no channels were specified, this method should not be called.
81 */
82 [[nodiscard]] const std::vector<uint32_t>& get_channels() const { return m_channels.value(); }
83
84private:
85 /**
86 * @brief Duration of the operation in seconds
87 *
88 * This value determines how long a node will remain active when connected to this operation.
89 */
90 double m_seconds;
91
92 /**
93 * @brief Reference to the scheduler that will manage timing
94 *
95 * The scheduler provides the timing infrastructure needed for
96 * precise control of node activation durations.
97 */
99
100 /**
101 * @brief Reference to the graph manager that will manage node connections
102 *
103 * The graph manager provides the infrastructure for connecting
104 * and disconnecting nodes from the processing graph.
105 */
107
108 std::optional<std::vector<uint32_t>> m_channels;
109
110 /**
111 * @brief Grants the stream operator access to private members
112 *
113 * This friendship declaration allows the stream operator to access
114 * the private members of NodeTimeSpec, which is necessary for
115 * implementing the node >> time syntax.
116 */
117 friend void operator>>(std::shared_ptr<Nodes::Node>, const NodeTimeSpec&);
118};
119
120/**
121 * @class OutputTerminal
122 * @brief Represents a terminal output sink in the processing graph
123 *
124 * The OutputTerminal class is a singleton that represents the final output of the system.
125 * It's designed to be used with the stream operator (>>) to create a fluent,
126 * expressive syntax for connecting nodes to the system output.
127 *
128 * This approach is inspired by flow-based programming paradigms, which use
129 * similar concepts to represent terminal sinks. It allows for a more
130 * intuitive way of expressing data flow compared to traditional function calls.
131 *
132 * Example usage:
133 * ```cpp
134 * // Connect a processing node to the system output
135 * process_node >> OutputTerminal::instance();
136 *
137 * // Connect to a specific output channel
138 * OutputTerminal::instance().channel = 1;
139 * process_node >> OutputTerminal::instance();
140 * ```
141 *
142 * The OutputTerminal is part of a broader pattern of using operator overloading to create
143 * a domain-specific language for computational flow programming within C++.
144 */
145class MAYAFLUX_API DAC {
146public:
147 /**
148 * @brief Gets the singleton instance of OutputTerminal
149 * @return Reference to the OutputTerminal singleton
150 *
151 * This method provides access to the singleton instance of OutputTerminal,
152 * which represents the system output.
153 */
154 static DAC& instance()
155 {
156 static DAC dac;
157 return dac;
158 }
159
160 /**
161 * @brief The output channel to connect to
162 *
163 * This value determines which system output channel a node will be
164 * connected to when using the stream operator. The default is 0,
165 * which typically corresponds to the primary output channel.
166 */
167 unsigned int channel = 0;
168
169private:
170 /**
171 * @brief Private constructor to enforce singleton pattern
172 *
173 * The OutputTerminal constructor is private to prevent direct instantiation,
174 * enforcing the singleton pattern through the instance() method.
175 */
176 DAC() = default;
177};
178
179/**
180 * @brief Connects a processing node to the system output
181 * @param node The processing node to connect
182 * @param terminal The OutputTerminal instance representing the system output
183 *
184 * This operator overload implements the node >> OutputTerminal syntax, which connects
185 * a processing node to the system's output. It's a more expressive way
186 * of representing data flow compared to traditional function calls.
187 *
188 * Example usage:
189 * ```cpp
190 * // Connect a processing node to the system output
191 * process_node >> OutputTerminal::instance();
192 * ```
193 *
194 * This is part of a broader pattern of using operator overloading to create
195 * a domain-specific language for computational flow programming within C++.
196 */
197void operator>>(std::shared_ptr<Nodes::Node> node, DAC& terminal);
198
199/**
200 * @brief Activates a processing node for a specific duration
201 * @param node The processing node to activate
202 * @param time_op The NodeTimeSpec specifying the duration
203 *
204 * This operator overload implements the node >> Time(seconds) syntax, which
205 * activates a processing node for a specific duration. It's a more expressive way
206 * of representing timed activation compared to traditional function calls.
207 *
208 * Example usage:
209 * ```cpp
210 * // Activate a processing node for 2 seconds
211 * process_node >> Time(2.0);
212 * ```
213 *
214 * This is part of a broader pattern of using operator overloading to create
215 * a domain-specific language for computational flow programming within C++.
216 */
217void operator>>(std::shared_ptr<Nodes::Node> node, const NodeTimeSpec& time_op);
218
219/**
220 * @brief Creates a NodeTimeSpec with the specified duration
221 * @param seconds Duration in seconds
222 * @param channels Optional list of channels to activate
223 * @param channel Optional single channel to activate
224 * @return A NodeTimeSpec object representing the specified duration
225 *
226 * This factory function creates a NodeTimeSpec with the specified duration,
227 * using the global scheduler and graph manager. It's designed to be used
228 * with the stream operator to create a fluent, expressive syntax for
229 * timed node activation.
230 *
231 * Example usage:
232 * ```cpp
233 * // Activate a processing node for 2 seconds
234 * process_node >> Time(2.0);
235 * ```
236 *
237 * This function is part of a broader pattern of using operator overloading
238 * to create a domain-specific language for computational flow programming within C++.
239 */
240NodeTimeSpec Time(double seconds, std::vector<uint32_t> channels);
241NodeTimeSpec Time(double seconds, uint32_t channel);
242NodeTimeSpec Time(double seconds);
243
244}
static DAC & instance()
Gets the singleton instance of OutputTerminal.
DAC()=default
Private constructor to enforce singleton pattern.
std::optional< std::vector< uint32_t > > m_channels
bool has_explicit_channels() const
Checks if explicit channels were specified.
Definition Operators.hpp:73
Vruta::TaskScheduler & m_scheduler
Reference to the scheduler that will manage timing.
Definition Operators.hpp:98
Nodes::NodeGraphManager & m_graph_manager
Reference to the graph manager that will manage node connections.
double get_seconds() const
Gets the duration of this operation.
Definition Operators.hpp:63
const std::vector< uint32_t > & get_channels() const
Gets the list of channels to activate.
Definition Operators.hpp:82
double m_seconds
Duration of the operation in seconds.
Definition Operators.hpp:90
Represents a timed activation operation for processing nodes.
Definition Operators.hpp:33
Central manager for the computational processing node graph.
Token-based multimodal task scheduling system for unified coroutine processing.
Definition Scheduler.hpp:51
NodeTimeSpec Time(double seconds)
Definition Operators.cpp:52
std::shared_ptr< BufferPipeline > operator>>(std::shared_ptr< BufferPipeline > pipeline, BufferOperation &&operation)