MayaFlux
0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Constant.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
MayaFlux/Nodes/Node.hpp
"
4
5
namespace
MayaFlux::Nodes
{
6
7
/**
8
* @class Constant
9
* @brief Zero-overhead scalar source node that emits a fixed value on every tick
10
*
11
* Constant is the identity element of the node graph: it ignores all input,
12
* holds a single double, and returns it unconditionally from every processing
13
* call. No state history, no coefficient arrays, no oscillator phase —
14
* just a number in, number out.
15
*
16
* Primary uses:
17
* - bias a signal by a fixed amount (DC offset injection)
18
* - Static parameter supply for parameter-mapping systems (e.g., feed a fixed
19
* - frequency into ResonatorNetwork::map_parameter("frequency", ...))
20
* - Push constants into GPU shader pipelines via NodeTextureBuffer
21
* - Test fixture / mock node that stands in for any scalar source
22
* - Sentinel value in node graphs during live-coding sessions where a real
23
* source node has not yet been wired in
24
*
25
* The node is intentionally minimal. save_state()/restore_state() snapshot the
26
* value so that buffer snapshot cycles remain consistent. notify_tick() fires
27
* the standard callback chain so that on_tick() listeners work identically to
28
* any other node.
29
*/
30
class
MAYAFLUX_API
Constant
final :
public
Node
{
31
public
:
32
//-------------------------------------------------------------------------
33
// Construction
34
//-------------------------------------------------------------------------
35
36
/**
37
* @brief Construct with an initial constant value
38
* @param value Scalar to emit on every process_sample() / process_batch() call
39
*/
40
explicit
Constant
(
double
value = 0.0);
41
42
//-------------------------------------------------------------------------
43
// Core processing
44
//-------------------------------------------------------------------------
45
46
/**
47
* @brief Return the constant value, ignoring input
48
* @param input Ignored; present only to satisfy the Node interface
49
* @return The stored constant
50
*
51
* Updates m_last_output, fires notify_tick(), and returns the value.
52
* The input parameter is accepted but never read: Constant is a pure source.
53
*/
54
double
process_sample(
double
input = 0.0)
override
;
55
56
/**
57
* @brief Fill a buffer with the constant value
58
* @param num_samples Number of samples to generate
59
* @return Vector of num_samples copies of the constant
60
*
61
* Each element is produced via process_sample(0.0) so that per-sample
62
* callbacks fire correctly for every position in the batch.
63
*/
64
std::vector<double> process_batch(
unsigned
int
num_samples)
override
;
65
66
//-------------------------------------------------------------------------
67
// Parameter control
68
//-------------------------------------------------------------------------
69
70
/**
71
* @brief Update the emitted value
72
* @param value New constant to emit from the next process call onward
73
*/
74
void
set_constant(
double
value);
75
76
/**
77
* @brief Read the current constant value without triggering processing
78
*/
79
[[nodiscard]]
double
get_constant
()
const
{
return
m_value; }
80
81
//-------------------------------------------------------------------------
82
// State snapshot (used by buffer processing chains)
83
//-------------------------------------------------------------------------
84
85
/**
86
* @brief Snapshot the current value for later restoration
87
*
88
* Stores m_value so that isolated buffer processing
89
* (NodeSourceProcessor, FilterProcessor snapshot paths) does not corrupt
90
* the live value seen by other consumers.
91
*/
92
void
save_state()
override
;
93
94
/**
95
* @brief Restore value from last save_state() call
96
*/
97
void
restore_state()
override
;
98
99
//-------------------------------------------------------------------------
100
// Context / callback support
101
//-------------------------------------------------------------------------
102
103
/**
104
* @brief Return the cached NodeContext from the last process_sample() call
105
*/
106
NodeContext
& get_last_context()
override
;
107
108
protected
:
109
/**
110
* @brief Update m_context with the latest value
111
* @param value Most recently emitted sample
112
*/
113
void
update_context(
double
value)
override
;
114
115
/**
116
* @brief Fire all registered on_tick() and on_tick_if() callbacks
117
* @param value Most recently emitted sample
118
*/
119
void
notify_tick(
double
value)
override
;
120
121
private
:
122
/**
123
* @brief Minimal concrete context for Constant — no extra fields beyond the base
124
*/
125
struct
ConstantContext
final :
NodeContext
{
126
ConstantContext
()
127
:
NodeContext
(0.0, typeid(
Constant
).name())
128
{
129
}
130
};
131
132
double
m_value
;
133
double
m_saved_value {};
134
135
ConstantContext
m_context
;
136
};
137
138
}
// namespace MayaFlux::Nodes
Node.hpp
MayaFlux::Nodes::Constant::get_constant
double get_constant() const
Read the current constant value without triggering processing.
Definition
Constant.hpp:79
MayaFlux::Nodes::Constant::m_context
ConstantContext m_context
Definition
Constant.hpp:135
MayaFlux::Nodes::Constant::m_value
double m_value
Definition
Constant.hpp:132
MayaFlux::Nodes::Constant
Zero-overhead scalar source node that emits a fixed value on every tick.
Definition
Constant.hpp:30
MayaFlux::Nodes::NodeContext
Base context class for node callbacks.
Definition
Node.hpp:30
MayaFlux::Nodes::Node
Base interface for all computational processing nodes.
Definition
Node.hpp:109
MayaFlux::Nodes
Contains the node-based computational processing system components.
Definition
Chronie.hpp:11
MayaFlux::Nodes::Constant::ConstantContext::ConstantContext
ConstantContext()
Definition
Constant.hpp:126
MayaFlux::Nodes::Constant::ConstantContext
Minimal concrete context for Constant — no extra fields beyond the base.
Definition
Constant.hpp:125
src
MayaFlux
Nodes
Conduit
Constant.hpp
Generated by
1.9.8