MayaFlux 0.5.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
21
22void Generator::set_amplitude(double amplitude)
23{
24 m_amplitude = amplitude;
25}
26
28{
29 return m_amplitude;
30}
31
36
38{
39 if (is_gpu_compatible()) {
40 return m_context_gpu;
41 }
42 return m_context;
43}
44
45void operator*(const std::shared_ptr<Node>& node, double value)
46{
47 if (auto gen = std::dynamic_pointer_cast<Generator>(node)) {
48 gen->set_amplitude(value);
49 } else {
51 "Cannot multiply non-generator node by a scalar. "
52 "Use set_[params] methods or create a BinaryOpNode.");
53 }
54}
55
57{
59 auto& ctx = get_last_context();
60 for (auto& cb : m_callbacks) {
61 cb(ctx);
62 }
63 for (auto& [cb, cond] : m_conditional_callbacks) {
64 if (cond(ctx)) {
65 cb(ctx);
66 }
67 }
68}
69
71{
72 m_callbacks.emplace_back([callback](NodeContext& ctx) {
73 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
74 callback(static_cast<GeneratorContext&>(ctx));
75 });
76}
77
79{
80 m_conditional_callbacks.emplace_back([callback](NodeContext& ctx) {
81 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
82 callback(static_cast<GeneratorContext&>(ctx));
83 },
84 condition);
85}
86
87} // namespace MayaFlux::Nodes::Generator
#define MF_ERROR(comp, ctx,...)
double frequency
float value
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:56
virtual void set_frequency(float frequency)
Sets the generator's frequency.
Definition Generator.cpp:32
virtual double get_amplitude() const
Gets the current base amplitude.
Definition Generator.cpp:27
virtual void set_amplitude(double amplitude)
Sets the generator's amplitude.
Definition Generator.cpp:22
float m_frequency
Base frequency of the generator.
NodeContext & get_last_context() override
Gets the last created context object.
Definition Generator.cpp:37
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:78
virtual void update_context(double value) override
Updates the context object for callbacks.
Definition Generator.cpp:7
void on_tick(const TypedHook< GeneratorContext > &callback)
Registers a typed callback receiving GeneratorContext directly.
Definition Generator.cpp:70
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:454
bool is_gpu_compatible() const
Checks if the node supports GPU processing.
Definition Node.hpp:374
std::vector< std::pair< NodeHook, NodeCondition > > m_conditional_callbacks
Collection of conditional callback functions with their predicates.
Definition Node.hpp:464
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:434
@ 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:45
std::function< void(ContextT &)> TypedHook
Callback function type for node processing events, parameterised on context type.
Definition NodeUtils.hpp:28
std::function< bool(NodeContext &)> NodeCondition
Predicate function type for conditional callbacks.
Definition NodeUtils.hpp:54