MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Nodes/Generators/Random.cpp
Go to the documentation of this file.
1#include "Random.hpp"
2
4
6 : m_generator(type)
7 , m_type(type)
8 , m_context(0.0, type, 1.0, m_current_start, m_current_end, m_normal_spread)
9 , m_context_gpu(0.0, type, 1.0, m_current_start, m_current_end, m_normal_spread, get_gpu_data_buffer())
10{
11}
12
18
30
31std::vector<double> Random::process_batch(unsigned int num_samples)
32{
33 auto samples = m_generator.batch(m_current_start, m_current_end, num_samples);
34
35 for (auto& sample : samples) {
36 sample *= m_amplitude;
37 }
38
39 return samples;
40}
41
42void Random::set_normal_spread(double spread)
43{
44 m_generator.configure("spread", spread);
45}
46
47void Random::set_range(double start, double end)
48{
49 m_current_start = start;
50 m_current_end = end;
51}
52
75
76void Random::notify_tick(double value)
77{
78 update_context(value);
79 auto& ctx = get_last_context();
80
81 for (auto& callback : m_callbacks) {
82 callback(ctx);
83 }
84 for (auto& [callback, condition] : m_conditional_callbacks) {
85 if (condition(ctx)) {
86 callback(ctx);
87 }
88 }
89}
90
92{
93 if (m_gpu_compatible) {
94 return m_context_gpu;
95 }
96 return m_context;
97}
98
99}
void configure(const std::string &key, std::any value)
Configures algorithm-specific parameters.
std::vector< double > batch(double min, double max, size_t count)
Batch generation.
Algorithm get_algorithm() const
Gets current algorithm.
void set_algorithm(Algorithm algo)
Changes active algorithm.
double m_amplitude
Base amplitude of the generator.
double normal_spread
Current variance parameter for normal distribution.
double amplitude
Current amplitude scaling factor.
double range_end
Current upper bound of the range.
double range_start
Current lower bound of the range.
Kinesis::Stochastic::Algorithm distribution_type
Current distribution type.
void notify_tick(double value) override
Notifies all registered callbacks about a new value.
Kinesis::Stochastic::Stochastic m_generator
Core stochastic generator instance.
void set_range(double start, double end)
Sets the output value range.
double m_normal_spread
Variance parameter for normal distribution.
Kinesis::Stochastic::Algorithm m_type
Current probability distribution algorithm.
NodeContext & get_last_context() override
Gets the last created context object.
Random(Kinesis::Stochastic::Algorithm type=Kinesis::Stochastic::Algorithm::UNIFORM)
Constructor for the stochastic generator.
std::vector< double > process_batch(unsigned int num_samples) override
Generates multiple stochastic values at once.
double m_current_start
Lower bound of the current output range.
void set_normal_spread(double spread)
Sets the variance parameter for normal distribution.
void set_type(Kinesis::Stochastic::Algorithm type)
Changes the probability distribution type.
double process_sample(double input=0.) override
Generates a single stochastic value.
void update_context(double value) override
Updates the context object with the current node state.
double m_current_end
Upper bound of the current output range.
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
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:386
Algorithm
Stochastic and procedural generation algorithms.