MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
StreamReaderNode.cpp
Go to the documentation of this file.
2
3namespace MayaFlux::Nodes {
4
9
25
26std::vector<double> StreamReaderNode::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
43
52
53bool StreamReaderNode::set_data(std::span<const double> data, const void* owner)
54{
55 const void* current = m_owner.load(std::memory_order_acquire);
56
57 if (current == nullptr) {
58 m_owner.compare_exchange_strong(current, owner, std::memory_order_acq_rel);
59 } else if (current != owner) {
60 return false;
61 }
62
63 m_data.assign(data.begin(), data.end());
64 m_read_head = 0;
65 return true;
66}
67
68void StreamReaderNode::release_owner(const void* owner)
69{
70 const void* expected = owner;
71 m_owner.compare_exchange_strong(expected, nullptr, std::memory_order_acq_rel);
72}
73
74size_t StreamReaderNode::remaining() const noexcept
75{
76 return m_read_head < m_data.size() ? m_data.size() - m_read_head : 0;
77}
78
80{
81 m_read_head = 0;
82}
83
85{
86 m_context.value = value;
87}
88
93
95{
96 update_context(value);
97
98 for (auto& cb : m_callbacks) {
99 cb(m_context);
100 }
101 for (auto& [cb, cond] : m_conditional_callbacks) {
102 if (cond(m_context)) {
103 cb(m_context);
104 }
105 }
106}
107
108} // namespace MayaFlux::Nodes
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
void release_owner(const void *owner)
Release ownership so another feeder can write.
double process_sample(double input=0.0) override
Processes a single data sample.
std::vector< double > process_batch(unsigned int num_samples) override
Processes multiple samples at once.
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
void update_context(double value) override
Updates the context object with the current node state.
size_t remaining() const noexcept
Number of unread samples remaining.
std::atomic< const void * > m_owner
void notify_tick(double value) override
Notifies all registered callbacks with the current context.
NodeContext & get_last_context() override
Retrieves the last created context object.
bool set_data(std::span< const double > data, const void *owner=nullptr)
Replace the internal data and reset read head to 0.
void rewind() noexcept
Reset read head to 0 without changing data.
Contains the node-based computational processing system components.
Definition Chronie.hpp:11