MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Constant.cpp
Go to the documentation of this file.
1#include "Constant.hpp"
2
3namespace MayaFlux::Nodes {
4
5Constant::Constant(double value)
6 : m_value(value)
7{
8 m_last_output = value;
9}
10
11//-----------------------------------------------------------------------------
12// Core processing
13//-----------------------------------------------------------------------------
14
15double Constant::process_sample(double /*input*/)
16{
18
21 }
22
23 return m_value;
24}
25
26std::vector<double> Constant::process_batch(unsigned int num_samples)
27{
28 std::vector<double> out(num_samples);
29 for (unsigned int i = 0; i < num_samples; ++i) {
30 out[i] = process_sample(0.0);
31 }
32 return out;
33}
34
35//-----------------------------------------------------------------------------
36// Parameter control
37//-----------------------------------------------------------------------------
38
39void Constant::set_constant(double value)
40{
41 m_value = value;
42 m_last_output = value;
43}
44
45//-----------------------------------------------------------------------------
46// State snapshot
47//-----------------------------------------------------------------------------
48
54
61
62//-----------------------------------------------------------------------------
63// Context / callbacks
64//-----------------------------------------------------------------------------
65
66void Constant::update_context(double value)
67{
68 m_context.value = value;
69}
70
75
76void Constant::notify_tick(double value)
77{
78 update_context(value);
79
80 for (auto& cb : m_callbacks) {
81 cb(m_context);
82 }
83 for (auto& [cb, cond] : m_conditional_callbacks) {
84 if (cond(m_context)) {
85 cb(m_context);
86 }
87 }
88}
89
90} // namespace MayaFlux::Nodes
void restore_state() override
Restore value from last save_state() call.
Definition Constant.cpp:55
void update_context(double value) override
Update m_context with the latest value.
Definition Constant.cpp:66
void save_state() override
Snapshot the current value for later restoration.
Definition Constant.cpp:49
Constant(double value=0.0)
Construct with an initial constant value.
Definition Constant.cpp:5
NodeContext & get_last_context() override
Return the cached NodeContext from the last process_sample() call.
Definition Constant.cpp:71
std::vector< double > process_batch(unsigned int num_samples) override
Fill a buffer with the constant value.
Definition Constant.cpp:26
ConstantContext m_context
Definition Constant.hpp:135
void notify_tick(double value) override
Fire all registered on_tick() and on_tick_if() callbacks.
Definition Constant.cpp:76
double process_sample(double input=0.0) override
Return the constant value, ignoring input.
Definition Constant.cpp:15
void set_constant(double value)
Update the emitted value.
Definition Constant.cpp:39
double value
Current sample value.
Definition Node.hpp:40
Base context class for node callbacks.
Definition Node.hpp:30
std::vector< NodeHook > m_callbacks
Collection of standard callback functions.
Definition Node.hpp:406
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
Definition Node.hpp:429
bool m_networked_node
Flag indicating if the node is part of a NodeNetwork This flag is used to disable event firing when t...
Definition Node.hpp:424
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:377
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:453
std::vector< std::pair< NodeHook, NodeCondition > > m_conditional_callbacks
Collection of conditional callback functions with their predicates.
Definition Node.hpp:416
Contains the node-based computational processing system components.
Definition Chronie.hpp:11