MayaFlux 0.4.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)
10{
11 return TimeSpec { seconds };
12}
13
14std::shared_ptr<Nodes::Node> operator|(const TemporalWrapper<Nodes::Node>& wrapper, const CreationContext& ctx)
15{
16 auto node = wrapper.entity();
17 const auto& spec = wrapper.spec();
18 auto node_token = get_node_token(ctx.domain.value());
19 auto task_token = get_task_token(ctx.domain.value());
20
21 auto activation = std::make_shared<Kriya::TemporalActivation>(
23
24 if (ctx.channels.has_value()) {
25 activation->activate_node(node, spec.seconds, node_token, ctx.channels.value());
26 } else if (ctx.channel.has_value()) {
27 activation->activate_node(node, spec.seconds, node_token, { ctx.channel.value() });
28 } else {
29 activation->activate_node(node, spec.seconds, node_token);
30 }
31
32 static std::vector<std::shared_ptr<Kriya::TemporalActivation>> active_timers;
33 active_timers.push_back(activation);
34
35 if (active_timers.size() > 100) {
36 std::erase_if(active_timers, [](const std::shared_ptr<Kriya::TemporalActivation>& t) {
37 return !t->is_active();
38 });
39 }
40
41 return node;
42}
43
44std::shared_ptr<Buffers::Buffer> operator|(const TemporalWrapper<Buffers::Buffer>& wrapper, const CreationContext& ctx)
45{
46 auto buffer = wrapper.entity();
47 const auto& spec = wrapper.spec();
48 auto buffer_token = get_buffer_token(ctx.domain.value());
49 auto task_token = get_task_token(ctx.domain.value());
50
51 auto activation = std::make_shared<Kriya::TemporalActivation>(
53
54 if (ctx.channel.has_value()) {
55 activation->activate_buffer(buffer, spec.seconds, buffer_token, ctx.channel.value());
56 } else if (ctx.channels.has_value() && !ctx.channels.value().empty()) {
57 activation->activate_buffer(buffer, spec.seconds, buffer_token, ctx.channels.value()[0]);
58 } else {
59 activation->activate_buffer(buffer, spec.seconds, buffer_token);
60 }
61
62 static std::vector<std::shared_ptr<Kriya::TemporalActivation>> active_timers;
63 active_timers.push_back(activation);
64
65 if (active_timers.size() > 100) {
66 std::erase_if(active_timers, [](const std::shared_ptr<Kriya::TemporalActivation>& t) {
67 return !t->is_active();
68 });
69 }
70
71 return buffer;
72}
73
74std::shared_ptr<Nodes::Network::NodeNetwork> operator|(const TemporalWrapper<Nodes::Network::NodeNetwork>& wrapper, const CreationContext& ctx)
75{
76 auto network = wrapper.entity();
77 const auto& spec = wrapper.spec();
78 auto node_token = get_node_token(ctx.domain.value());
79 auto task_token = get_task_token(ctx.domain.value());
80
81 auto activation = std::make_shared<Kriya::TemporalActivation>(
83
84 activation->activate_network(network, spec.seconds, node_token);
85
86 static std::vector<std::shared_ptr<Kriya::TemporalActivation>> active_timers;
87 active_timers.push_back(activation);
88
89 if (active_timers.size() > 100) {
90 std::erase_if(active_timers, [](const std::shared_ptr<Kriya::TemporalActivation>& t) {
91 return !t->is_active();
92 });
93 }
94
95 return network;
96}
97
98} // namespace MayaFlux
Core::GlobalNetworkConfig network
Definition Config.cpp:37
MAYAFLUX_API Vruta::ProcessingToken get_task_token(Domain domain)
Extracts task processing token from domain.
Definition Domain.hpp:194
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
TimeSpec Time(double seconds)
Definition Temporal.cpp:9
std::shared_ptr< Buffers::BufferManager > get_buffer_manager()
Gets the buffer manager from the default engine.
Definition Graph.cpp:132
std::shared_ptr< Vruta::TaskScheduler > get_scheduler()
Gets the task scheduler from the default engine.
Definition Chronie.cpp:22
std::shared_ptr< T > operator|(std::shared_ptr< T > obj, const CreationContext &ctx)
Definition Creator.hpp:259
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 Runtime.cpp:12
std::optional< uint32_t > channel
Definition Creator.hpp:21
std::optional< std::vector< uint32_t > > channels
Definition Creator.hpp:22
std::optional< Domain > domain
Definition Creator.hpp:20