MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Generator.cpp
Go to the documentation of this file.
1#include "Generator.hpp"
2
4
6
7void Generator::enable_mock_process(bool mock_process)
8{
9 if (mock_process) {
11 } else {
13 }
14}
15
17{
18 return m_state.load() & NodeState::MOCK_PROCESS;
19}
20
35
36void Generator::set_amplitude(double amplitude)
37{
38 m_amplitude = amplitude;
39}
40
42{
43 return m_amplitude;
44}
45
50
52{
53 if (is_gpu_compatible()) {
54 return m_context_gpu;
55 }
56 return m_context;
57}
58
59void operator*(const std::shared_ptr<Node>& node, double value)
60{
61 if (auto gen = std::dynamic_pointer_cast<Generator>(node)) {
62 gen->set_amplitude(value);
63 } else {
65 "Cannot multiply non-generator node by a scalar. "
66 "Use set_[params] methods or create a BinaryOpNode.");
67 }
68}
69
70void Generator::notify_tick(double value)
71{
72 update_context(value);
73 auto& ctx = get_last_context();
74 for (auto& cb : m_callbacks) {
75 cb(ctx);
76 }
77 for (auto& [cb, cond] : m_conditional_callbacks) {
78 if (cond(ctx)) {
79 cb(ctx);
80 }
81 }
82}
83
85{
86 m_callbacks.emplace_back([callback](NodeContext& ctx) {
87 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
88 callback(static_cast<GeneratorContext&>(ctx));
89 });
90}
91
93{
94 m_conditional_callbacks.emplace_back([callback](NodeContext& ctx) {
95 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
96 callback(static_cast<GeneratorContext&>(ctx));
97 },
98 condition);
99}
100
101} // namespace MayaFlux::Nodes::Generator
#define MF_ERROR(comp, ctx,...)
double frequency
double amplitude
Current amplitude of the generator.
Definition Generator.hpp:57
double phase
Current phase of the generator.
Definition Generator.hpp:62
float frequency
Current frequency of the generator.
Definition Generator.hpp:52
Specialized context for generator node callbacks.
Definition Generator.hpp:24
void notify_tick(double value) override
Notifies all registered callbacks with the current context.
Definition Generator.cpp:70
virtual void set_frequency(float frequency)
Sets the generator's frequency.
Definition Generator.cpp:46
virtual bool should_mock_process() const
Checks if the generator should mock process.
Definition Generator.cpp:16
virtual double get_amplitude() const
Gets the current base amplitude.
Definition Generator.cpp:41
virtual void set_amplitude(double amplitude)
Sets the generator's amplitude.
Definition Generator.cpp:36
float m_frequency
Base frequency of the generator.
NodeContext & get_last_context() override
Gets the last created context object.
Definition Generator.cpp:51
double m_amplitude
Base amplitude of the generator.
void on_tick_if(const NodeCondition &condition, const TypedHook< GeneratorContext > &callback)
Registers a conditional typed callback receiving GeneratorContext directly.
Definition Generator.cpp:92
virtual void update_context(double value) override
Updates the context object for callbacks.
Definition Generator.cpp:21
virtual void enable_mock_process(bool mock_process)
Allows RootNode to process the Generator without using the processed sample.
Definition Generator.cpp:7
void on_tick(const TypedHook< GeneratorContext > &callback)
Registers a typed callback receiving GeneratorContext directly.
Definition Generator.cpp:84
double m_phase
Current phase of the generator.
double value
Current sample value.
Definition Node.hpp:63
Base context class for node callbacks.
Definition Node.hpp:53
std::vector< NodeHook > m_callbacks
Collection of standard callback functions.
Definition Node.hpp:434
std::atomic< NodeState > m_state
Atomic state flag tracking the node's processing status.
Definition Node.hpp:502
bool is_gpu_compatible() const
Checks if the node supports GPU processing.
Definition Node.hpp:354
std::vector< std::pair< NodeHook, NodeCondition > > m_conditional_callbacks
Collection of conditional callback functions with their predicates.
Definition Node.hpp:444
bool m_gpu_compatible
Flag indicating if the node supports GPU processing This flag is set by derived classes to indicate w...
Definition Node.hpp:414
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ API
MayaFlux/API Wrapper and convenience functions.
void operator*(const std::shared_ptr< Node > &node, double value)
Sets the generator's amplitude.
Definition Generator.cpp:59
@ MOCK_PROCESS
Node should be processed but output ignored.
Definition NodeSpec.hpp:48
void atomic_add_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically adds a flag to a node state.
Definition NodeUtils.cpp:60
std::function< void(ContextT &)> TypedHook
Callback function type for node processing events, parameterised on context type.
Definition NodeUtils.hpp:28
void atomic_remove_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically removes a flag from a node state.
Definition NodeUtils.cpp:71
std::function< bool(NodeContext &)> NodeCondition
Predicate function type for conditional callbacks.
Definition NodeUtils.hpp:54