MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Utils.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux::Utils {
4
5enum AudioBackendType : uint8_t {
7};
8
9enum class WindowingBackendType : uint8_t {
10 GLFW
11};
12
13enum class distribution : uint8_t {
14 UNIFORM,
15 NORMAL,
17 POISSON,
18 // PERLIN,
19 // GENDY
20};
21
22enum ActionType : uint8_t {
26};
27
28enum NodeState : uint32_t {
29 INACTIVE = 0x00, ///< Engine is not processing this node
30 ACTIVE = 0x01, ///< Engine is processing this node
31 PENDING_REMOVAL = 0x02, ///< Node is marked for removal
32
33 MOCK_PROCESS = 0x04, ///< Node should be processed but output ignored
34 PROCESSED = 0x08, ///< Node has been processed this cycle
35
36 ENGINE_PROCESSED = ACTIVE | PROCESSED, ///< Engine has processed this node
37 EXTERMAL_PROCESSED = INACTIVE | PROCESSED, ///< External source has processed this node
38 ENGINE_MOCK_PROCESSED = ACTIVE | MOCK_PROCESS | PROCESSED, ///< Engine has mock processed this node
39};
40
41/**
42 * @enum NodeChainSemantics
43 * @brief Defines how to handle existing nodes when creating a new chain
44 */
45enum NodeChainSemantics : uint8_t {
46 REPLACE_TARGET, ///< Unregister the target and register with the new chain node
47 PRESERVE_BOTH, ///< Preserve both nodes in the chain, add new chain node to root, i.e doubling the target signal
48 ONLY_CHAIN ///< Only keep the new chain node, unregistering the source and target
49};
50
51/**
52 * @enum NodeMixSemantics
53 * @brief Defines how to handle existing nodes when creating a new mix
54 */
55enum NodeBinaryOpSemantics : uint8_t {
56 REPLACE, ///< Unregister both nodes and register with the new binary op node
57 KEEP ///< Preserve both nodes in the binary op, add new binary op node to root, i.e doubling the signal
58};
59
60/**
61 * @enum ComplexConversionStrategy
62 * @brief Strategy for converting complex numbers to real values
63 */
64enum class ComplexConversionStrategy : uint8_t {
65 MAGNITUDE, ///< |z| = sqrt(real² + imag²)
66 REAL_PART, ///< z.real()
67 IMAG_PART, ///< z.imag()
68 SQUARED_MAGNITUDE ///< |z|² = real² + imag²
69};
70
71std::any safe_get_parameter(const std::string& parameter_name, const std::map<std::string, std::any> parameters);
72
73/**
74 * @brief Convert frames to seconds at a given frame rate
75 * @param frames Number of frames
76 * @param frame_rate Frame rate in Hz
77 * @return Time duration in seconds
78 */
79inline uint64_t frames_to_seconds(uint64_t frames, uint32_t frame_rate)
80{
81 return frames / frame_rate;
82}
83
84/**
85 * @brief Get duration of a single frame at given frame rate
86 * @param frame_rate Frame rate in Hz
87 * @return Duration in milliseconds
88 */
89inline std::chrono::milliseconds frame_duration_ms(uint32_t frame_rate)
90{
91 return std::chrono::milliseconds(1000 / frame_rate);
92}
93
94/**
95 * @brief Get duration of a single frame at given frame rate (high precision)
96 * @param frame_rate Frame rate in Hz
97 * @return Duration in microseconds
98 */
99inline std::chrono::microseconds frame_duration_us(uint32_t frame_rate)
100{
101 return std::chrono::microseconds(1000000 / frame_rate);
102}
103
104/**
105 * @brief Get duration for N frames at given frame rate
106 * @param num_frames Number of frames
107 * @param frame_rate Frame rate in Hz
108 * @return Duration in milliseconds
109 */
110inline std::chrono::milliseconds frames_duration_ms(uint64_t num_frames, uint32_t frame_rate)
111{
112 return std::chrono::milliseconds((num_frames * 1000) / frame_rate);
113}
114
115/**
116 * @brief Get duration for N frames at given frame rate (high precision)
117 * @param num_frames Number of frames
118 * @param frame_rate Frame rate in Hz
119 * @return Duration in microseconds
120 */
121inline std::chrono::microseconds frames_duration_us(uint64_t num_frames, uint32_t frame_rate)
122{
123 return std::chrono::microseconds((num_frames * 1000000) / frame_rate);
124}
125
126/** * @brief Convert samples to seconds at a given sample rate
127 * @param samples Number of samples
128 * @param sample_rate Sample rate in Hz
129 * @return Time duration in seconds
130 */
131inline uint64_t samples_to_seconds(uint64_t samples, uint32_t sample_rate)
132{
133 return samples / sample_rate;
134}
135
136/**
137 * @brief Convert frames to samples at a given sample rate and frame rate
138 * @param frames Number of frames
139 * @param sample_rate Sample rate in Hz
140 * @param frame_rate Frame rate in Hz
141 * @return Number of samples
142 */
143inline uint64_t frames_to_samples(uint64_t frames, uint32_t sample_rate, uint32_t frame_rate)
144{
145 return (frames * sample_rate) / frame_rate;
146}
147
148/**
149 * @brief Convert samples to frames at a given sample rate and frame rate
150 * @param samples Number of samples
151 * @param sample_rate Sample rate in Hz
152 * @param frame_rate Frame rate in Hz
153 * @return Number of frames
154 */
155inline uint64_t samples_to_frames(uint64_t samples, uint32_t sample_rate, uint32_t frame_rate)
156{
157 return (samples * frame_rate) / sample_rate;
158}
159
160/**
161 * @brief Convert seconds to samples at a given sample rate
162 * @param seconds Time duration in seconds
163 * @param sample_rate Sample rate in Hz
164 * @return Number of samples
165 */
166inline uint64_t seconds_to_samples(double seconds, uint32_t sample_rate)
167{
168 return static_cast<uint64_t>(seconds * sample_rate);
169}
170
171/**
172 * @brief Convert seconds to frames at a given frame rate
173 * @param seconds Time duration in seconds
174 * @param frame_rate Frame rate in Hz
175 * @return Number of frames
176 */
177inline uint64_t seconds_to_frames(double seconds, uint32_t frame_rate)
178{
179 return static_cast<uint64_t>(seconds * frame_rate);
180}
181
182/**
183 * @brief Convert seconds to processing units for any rate
184 * @param seconds Time duration in seconds
185 * @param rate Processing rate (samples/sec, frames/sec, etc.)
186 * @return Number of processing units
187 */
188inline uint64_t seconds_to_units(double seconds, uint32_t rate)
189{
190 return static_cast<uint64_t>(seconds * rate);
191}
192
193/**
194 * @brief Convert processing units to seconds for any rate
195 * @param units Number of processing units
196 * @param rate Processing rate (samples/sec, frames/sec, etc.)
197 * @return Time duration in seconds
198 */
199inline double units_to_seconds(uint64_t units, uint32_t rate)
200{
201 return static_cast<double>(units) / rate;
202}
203
204}
uint64_t frames_to_seconds(uint64_t frames, uint32_t frame_rate)
Convert frames to seconds at a given frame rate.
Definition Utils.hpp:79
std::chrono::microseconds frames_duration_us(uint64_t num_frames, uint32_t frame_rate)
Get duration for N frames at given frame rate (high precision)
Definition Utils.hpp:121
double units_to_seconds(uint64_t units, uint32_t rate)
Convert processing units to seconds for any rate.
Definition Utils.hpp:199
std::any safe_get_parameter(const std::string &parameter_name, const std::map< std::string, std::any > parameters)
Definition Utils.cpp:5
uint64_t samples_to_frames(uint64_t samples, uint32_t sample_rate, uint32_t frame_rate)
Convert samples to frames at a given sample rate and frame rate.
Definition Utils.hpp:155
NodeChainSemantics
Defines how to handle existing nodes when creating a new chain.
Definition Utils.hpp:45
@ PRESERVE_BOTH
Preserve both nodes in the chain, add new chain node to root, i.e doubling the target signal.
Definition Utils.hpp:47
@ REPLACE_TARGET
Unregister the target and register with the new chain node.
Definition Utils.hpp:46
@ ONLY_CHAIN
Only keep the new chain node, unregistering the source and target.
Definition Utils.hpp:48
@ KEEP
Preserve both nodes in the binary op, add new binary op node to root, i.e doubling the signal.
Definition Utils.hpp:57
@ REPLACE
Unregister both nodes and register with the new binary op node.
Definition Utils.hpp:56
std::chrono::milliseconds frames_duration_ms(uint64_t num_frames, uint32_t frame_rate)
Get duration for N frames at given frame rate.
Definition Utils.hpp:110
std::chrono::milliseconds frame_duration_ms(uint32_t frame_rate)
Get duration of a single frame at given frame rate.
Definition Utils.hpp:89
uint64_t seconds_to_units(double seconds, uint32_t rate)
Convert seconds to processing units for any rate.
Definition Utils.hpp:188
@ PENDING_REMOVAL
Node is marked for removal.
Definition Utils.hpp:31
@ EXTERMAL_PROCESSED
External source has processed this node.
Definition Utils.hpp:37
@ INACTIVE
Engine is not processing this node.
Definition Utils.hpp:29
@ ENGINE_MOCK_PROCESSED
Engine has mock processed this node.
Definition Utils.hpp:38
@ ACTIVE
Engine is processing this node.
Definition Utils.hpp:30
@ MOCK_PROCESS
Node should be processed but output ignored.
Definition Utils.hpp:33
@ ENGINE_PROCESSED
Engine has processed this node.
Definition Utils.hpp:36
@ PROCESSED
Node has been processed this cycle.
Definition Utils.hpp:34
std::chrono::microseconds frame_duration_us(uint32_t frame_rate)
Get duration of a single frame at given frame rate (high precision)
Definition Utils.hpp:99
uint64_t seconds_to_samples(double seconds, uint32_t sample_rate)
Convert seconds to samples at a given sample rate.
Definition Utils.hpp:166
uint64_t seconds_to_frames(double seconds, uint32_t frame_rate)
Convert seconds to frames at a given frame rate.
Definition Utils.hpp:177
uint64_t frames_to_samples(uint64_t frames, uint32_t sample_rate, uint32_t frame_rate)
Convert frames to samples at a given sample rate and frame rate.
Definition Utils.hpp:143
ComplexConversionStrategy
Strategy for converting complex numbers to real values.
Definition Utils.hpp:64
@ SQUARED_MAGNITUDE
|z|² = real² + imag²
@ MAGNITUDE
|z| = sqrt(real² + imag²)
uint64_t samples_to_seconds(uint64_t samples, uint32_t sample_rate)
Convert samples to seconds at a given sample rate.
Definition Utils.hpp:131