MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Temporal.cpp
Go to the documentation of this file.
1#include "Temporal.hpp"
2
6
7namespace MayaFlux {
8
9TimeSpec Time(double seconds, uint32_t channel)
10{
11 return { seconds, channel };
12}
13
14TimeSpec Time(double seconds, std::vector<uint32_t> channels)
15{
16 return { seconds, std::move(channels) };
17}
18
19std::shared_ptr<Nodes::Node> operator|(const TemporalWrapper<Nodes::Node>& wrapper, Domain domain)
20{
21 auto node = wrapper.entity();
22 const auto& spec = wrapper.spec();
23 auto node_token = get_node_token(domain);
24
25 auto activation = std::make_shared<Kriya::TemporalActivation>(*get_scheduler(), *get_node_graph_manager(), *get_buffer_manager());
26
27 if (spec.channels.has_value()) {
28 activation->activate_node(node, spec.seconds, node_token, spec.channels.value());
29 } else {
30 activation->activate_node(node, spec.seconds, node_token);
31 }
32
33 static std::vector<std::shared_ptr<Kriya::TemporalActivation>> active_timers;
34 active_timers.push_back(activation);
35
36 if (active_timers.size() > 100) {
37 std::erase_if(active_timers, [](const std::shared_ptr<Kriya::TemporalActivation>& t) {
38 return !t->is_active();
39 });
40 }
41
42 return node;
43}
44
45std::shared_ptr<Buffers::Buffer> operator|(const TemporalWrapper<Buffers::Buffer>& wrapper, Domain domain)
46{
47 auto buffer = wrapper.entity();
48 const auto& spec = wrapper.spec();
49 auto buffer_token = get_buffer_token(domain);
50
51 auto activation = std::make_shared<Kriya::TemporalActivation>(*get_scheduler(), *get_node_graph_manager(), *get_buffer_manager());
52
53 if (spec.channels.has_value() && !spec.channels.value().empty()) {
54 activation->activate_buffer(buffer, spec.seconds, buffer_token, spec.channels.value()[0]);
55 } else {
56 activation->activate_buffer(buffer, spec.seconds, buffer_token);
57 }
58
59 static std::vector<std::shared_ptr<Kriya::TemporalActivation>> active_timers;
60 active_timers.push_back(activation);
61
62 if (active_timers.size() > 100) {
63 std::erase_if(active_timers, [](const std::shared_ptr<Kriya::TemporalActivation>& t) {
64 return !t->is_active();
65 });
66 }
67
68 return buffer;
69}
70
71std::shared_ptr<Nodes::Network::NodeNetwork> operator|(const TemporalWrapper<Nodes::Network::NodeNetwork>& wrapper, Domain domain)
72{
73 auto network = wrapper.entity();
74 const auto& spec = wrapper.spec();
75 auto node_token = get_node_token(domain);
76
77 auto activation = std::make_shared<Kriya::TemporalActivation>(*get_scheduler(), *get_node_graph_manager(), *get_buffer_manager());
78 activation->activate_network(network, spec.seconds, node_token);
79
80 static std::vector<std::shared_ptr<Kriya::TemporalActivation>> active_timers;
81 active_timers.push_back(activation);
82
83 if (active_timers.size() > 100) {
84 std::erase_if(active_timers, [](const std::shared_ptr<Kriya::TemporalActivation>& t) {
85 return !t->is_active();
86 });
87 }
88
89 return network;
90}
91
92}
static const auto node_token
Definition Chain.cpp:9
const TimeSpec & spec() const
Definition Temporal.hpp:100
std::shared_ptr< T > entity() const
Definition Temporal.hpp:99
Wraps an entity with a TimeSpec for temporal activation.
Definition Temporal.hpp:83
MAYAFLUX_API Nodes::ProcessingToken get_node_token(Domain domain)
Extracts node processing token from domain.
Definition Domain.hpp:174
std::shared_ptr< Nodes::NodeGraphManager > get_node_graph_manager()
Gets the node graph manager from the default engine.
Definition Graph.cpp:35
std::shared_ptr< Nodes::Node > operator|(const std::shared_ptr< Nodes::Node > &node, Domain d)
Definition Creator.cpp:105
TimeSpec Time(double seconds, uint32_t channel)
Creates a TimeSpec with the specified duration and a single channel.
Definition Temporal.cpp:9
Domain
Unified domain enum combining all three ProcessingToken subsystems.
Definition Domain.hpp:22
std::shared_ptr< Buffers::BufferManager > get_buffer_manager()
Gets the buffer manager from the default engine.
Definition Graph.cpp:133
std::shared_ptr< Vruta::TaskScheduler > get_scheduler()
Gets the task scheduler from the default engine.
Definition Chronie.cpp:20
MAYAFLUX_API Buffers::ProcessingToken get_buffer_token(Domain domain)
Extracts buffer processing token from domain.
Definition Domain.hpp:184
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6
Represents a timed activation operation for processing nodes, buffers, or networks.
Definition Temporal.hpp:31