MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Creator.cpp
Go to the documentation of this file.
1#include "Creator.hpp"
2
5
11
12namespace MayaFlux {
13
15
16void register_node(const std::shared_ptr<Nodes::Node>& node, const CreationContext& ctx)
17{
18 auto token = get_node_token(ctx.domain.value());
19
20 if (ctx.channel.has_value()) {
21 register_node(node, token, ctx.channel.value());
22 } else if (ctx.channels.has_value()) {
23 for (uint32_t ch : ctx.channels.value()) {
24 register_node(node, token, ch);
25 }
26 } else if (node->get_channel_mask() != 0) {
27 for (uint32_t ch = 0; ch < 32; ++ch) {
28 if (node->get_channel_mask() & (1 << ch)) {
29 register_node(node, token, ch);
30 }
31 }
32 } else {
33 register_node(node, token, 0);
34 }
35}
36
37void register_network(const std::shared_ptr<Nodes::NodeNetwork>& network, const CreationContext& ctx)
38{
39 auto token = get_node_token(ctx.domain.value());
40
42 if (network->get_output_mode() != Nodes::NodeNetwork::OutputMode::AUDIO_SINK) {
45 "Registering audio network in AUDIO_RATE domain without AUDIO_SINK output mode. Forcing AUDIO_SINK mode.");
46 network->set_output_mode(Nodes::NodeNetwork::OutputMode::AUDIO_SINK);
47 }
48 if (ctx.channel.has_value()) {
49 network->add_channel_usage(ctx.channel.value());
50 } else if (ctx.channels.has_value()) {
51 for (uint32_t ch : ctx.channels.value()) {
52 network->add_channel_usage(ch);
53 }
54 }
58 "Registering visual network in VISUAL_RATE domain without GRAPHICS_BIND output mode. Forcing GRAPHICS_BIND mode.");
59 network->set_output_mode(Nodes::NodeNetwork::OutputMode::GRAPHICS_BIND);
60 }
61
63}
64
65void register_buffer(const std::shared_ptr<Buffers::Buffer>& buffer, const CreationContext& ctx)
66{
67 auto token = get_buffer_token(ctx.domain.value());
68
69 if (auto audio_buffer = std::dynamic_pointer_cast<Buffers::AudioBuffer>(buffer)) {
70 if (ctx.channel.has_value()) {
71 register_audio_buffer(audio_buffer, ctx.channel.value());
72 } else if (ctx.channels.has_value()) {
73 clone_buffer_to_channels(audio_buffer, ctx.channels.value(), token);
74 }
75 return;
76 }
77
78 if (auto vk_buffer = std::dynamic_pointer_cast<Buffers::VKBuffer>(buffer)) {
80 return;
81 }
82}
83
84void register_container(const std::shared_ptr<Kakshya::SoundFileContainer>& container, const Domain& domain)
85{
86 if (auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container)) {
87 if (domain == Domain::AUDIO) {
90 }
91 }
92}
93
94std::shared_ptr<Kakshya::SoundFileContainer> Creator::load_container(const std::string& filepath)
95{
96 return load_audio_file(filepath);
97}
98
99std::vector<std::shared_ptr<Buffers::ContainerBuffer>> get_last_created_container_buffers()
100{
102}
103
104std::shared_ptr<Nodes::Node> operator|(const std::shared_ptr<Nodes::Node>& node, Domain d)
105{
106 CreationContext ctx(d);
107 register_node(node, ctx);
108 return node;
109}
110
111std::shared_ptr<Nodes::NodeNetwork> operator|(const std::shared_ptr<Nodes::NodeNetwork>& network, Domain d)
112{
113 CreationContext ctx(d);
114 register_network(network, ctx);
115 return network;
116}
117
118std::shared_ptr<Buffers::Buffer> operator|(const std::shared_ptr<Buffers::Buffer>& buffer, Domain d)
119{
120 CreationContext ctx(d);
121 register_buffer(buffer, ctx);
122 return buffer;
123}
124
125std::shared_ptr<Buffers::TextureBuffer> Creator::load_buffer(const std::string& filepath)
126{
127 return load_image_file(filepath);
128}
129
130} // namespace MayaFlux
#define MF_WARN(comp, ctx,...)
Audio file loading and container management API.
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
std::shared_ptr< Buffers::TextureBuffer > load_buffer(const std::string &filepath)
Definition Creator.cpp:125
std::shared_ptr< Kakshya::SoundFileContainer > load_container(const std::string &filepath)
Definition Creator.cpp:94
@ GRAPHICS_BIND
State available for visualization (read-only)
@ AUDIO_SINK
Aggregated audio samples sent to output.
@ Init
Engine/subsystem initialization.
@ API
MayaFlux/API Wrapper and convenience functions.
@ AUDIO_RATE
Nodes that process at the audio sample rate.
@ VISUAL_RATE
Nodes that process at the visual frame rate.
std::shared_ptr< MayaFlux::Kakshya::SoundFileContainer > load_audio_file(const std::string &filepath)
Loads an audio file into a SoundFileContainer with automatic format detection.
Definition Depot.cpp:18
Creator vega
Global Creator instance for creating nodes, buffers, and containers.
Definition Creator.cpp:14
void register_node(const std::shared_ptr< Nodes::Node > &node, const Nodes::ProcessingToken &token, uint32_t channel)
Definition Graph.cpp:72
void register_network(const std::shared_ptr< Nodes::NodeNetwork > &network, const CreationContext &ctx)
Definition Creator.cpp:37
MAYAFLUX_API Nodes::ProcessingToken get_node_token(Domain domain)
Extracts node processing token from domain.
Definition Domain.hpp:174
void register_buffer(const std::shared_ptr< Buffers::Buffer > &buffer, const CreationContext &ctx)
Definition Creator.cpp:65
void register_node_network(const std::shared_ptr< Nodes::NodeNetwork > &network, const Nodes::ProcessingToken &token)
Registers a node network with the default engine's node graph manager.
Definition Graph.cpp:126
std::shared_ptr< Nodes::Node > operator|(const std::shared_ptr< Nodes::Node > &node, Domain d)
Definition Creator.cpp:104
std::vector< std::shared_ptr< Buffers::AudioBuffer > > clone_buffer_to_channels(const std::shared_ptr< Buffers::AudioBuffer > &buffer, const std::vector< uint32_t > &channels)
Clones a buffer to multiple channels.
Definition Graph.cpp:192
static std::vector< std::shared_ptr< Buffers::ContainerBuffer > > s_last_created_container_buffers
Definition Creator.hpp:268
std::shared_ptr< Buffers::TextureBuffer > load_image_file(const std::string &filepath)
Loads an image file into a TextureBuffer.
Definition Depot.cpp:117
void register_audio_buffer(const std::shared_ptr< Buffers::AudioBuffer > &buffer, uint32_t channel)
Registers an AudioBuffer with the default engine's buffer manager.
Definition Graph.cpp:150
std::vector< std::shared_ptr< Buffers::ContainerBuffer > > get_last_created_container_buffers()
Retrieves the last created container buffers from the Creator.
Definition Creator.cpp:99
void register_container(const std::shared_ptr< Kakshya::SoundFileContainer > &container, const Domain &domain)
Definition Creator.cpp:84
Domain
Unified domain enum combining all three ProcessingToken subsystems.
Definition Domain.hpp:22
@ AUDIO
Standard real-time audio processing domain.
Definition Domain.hpp:33
std::vector< std::shared_ptr< Buffers::ContainerBuffer > > hook_sound_container_to_buffers(const std::shared_ptr< MayaFlux::Kakshya::SoundFileContainer > &container)
Connects a SoundFileContainer to the buffer system for immediate playback.
Definition Depot.cpp:84
void register_graphics_buffer(const std::shared_ptr< Buffers::VKBuffer > &buffer, Buffers::ProcessingToken token)
Registers a VKBuffer with the default engine's buffer manager.
Definition Graph.cpp:160
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
std::optional< uint32_t > channel
Definition Creator.hpp:10
std::optional< std::vector< uint32_t > > channels
Definition Creator.hpp:11
std::optional< Domain > domain
Definition Creator.hpp:9