MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Creator.cpp
Go to the documentation of this file.
1#include "Creator.hpp"
2
6
13
16
17namespace MayaFlux {
18
20
21void register_node(const std::shared_ptr<Nodes::Node>& node, const CreationContext& ctx)
22{
23 auto token = get_node_token(ctx.domain.value());
24
25 if (ctx.channel.has_value()) {
26 register_node(node, token, ctx.channel.value());
27 } else if (ctx.channels.has_value()) {
28 for (uint32_t ch : ctx.channels.value()) {
29 register_node(node, token, ch);
30 }
31 } else if (node->get_channel_mask() != 0) {
32 for (uint32_t ch = 0; ch < 32; ++ch) {
33 if (node->get_channel_mask() & (1 << ch)) {
34 register_node(node, token, ch);
35 }
36 }
37 } else {
38 register_node(node, token, 0);
39 }
40}
41
42void register_network(const std::shared_ptr<Nodes::Network::NodeNetwork>& network, const CreationContext& ctx)
43{
44 auto token = get_node_token(ctx.domain.value());
45
47 if (
48 network->get_output_mode() != Nodes::Network::OutputMode::AUDIO_SINK
49 && network->get_output_mode() != Nodes::Network::OutputMode::AUDIO_COMPUTE) {
52 "Registering audio network in AUDIO_RATE domain without AUDIO_SINK or AUDIO_COMPUTE mode. Forcing AUDIO_SINK mode.");
53 network->set_output_mode(Nodes::Network::OutputMode::AUDIO_SINK);
54 }
55 if (ctx.channel.has_value()) {
56 network->add_channel_usage(ctx.channel.value());
57 } else if (ctx.channels.has_value()) {
58 for (uint32_t ch : ctx.channels.value()) {
59 network->add_channel_usage(ch);
60 }
61 }
62 } else if (token == Nodes::ProcessingToken::VISUAL_RATE && network->get_output_mode() != Nodes::Network::OutputMode::GRAPHICS_BIND) {
65 "Registering visual network in VISUAL_RATE domain without GRAPHICS_BIND output mode. Forcing GRAPHICS_BIND mode.");
66 network->set_output_mode(Nodes::Network::OutputMode::GRAPHICS_BIND);
67 }
68
69 register_node_network(network, token);
70}
71
72void register_buffer(const std::shared_ptr<Buffers::Buffer>& buffer, const CreationContext& ctx)
73{
74 auto token = get_buffer_token(ctx.domain.value());
75
76 if (auto audio_buffer = std::dynamic_pointer_cast<Buffers::AudioBuffer>(buffer)) {
77 if (ctx.channel.has_value()) {
78 register_audio_buffer(audio_buffer, ctx.channel.value());
79 } else if (ctx.channels.has_value()) {
80 clone_buffer_to_channels(audio_buffer, ctx.channels.value(), token);
81 }
82 return;
83 }
84
85 if (auto vk_buffer = std::dynamic_pointer_cast<Buffers::VKBuffer>(buffer)) {
86 register_graphics_buffer(vk_buffer, token);
87 return;
88 }
89}
90
91void register_container(const std::shared_ptr<Kakshya::SoundFileContainer>& container, const Domain& domain)
92{
93 if (auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container)) {
94 if (domain == Domain::AUDIO) {
95 (void)get_io_manager()->hook_audio_container_to_buffers(sound_container);
96 }
97 }
98}
99
100std::shared_ptr<Kakshya::SoundFileContainer> Creator::load_sound_container(const std::string& filepath)
101{
102 return get_io_manager()->load_audio(filepath);
103}
104
105std::shared_ptr<Nodes::Node> operator|(const std::shared_ptr<Nodes::Node>& node, Domain d)
106{
107 CreationContext ctx(d);
108 register_node(node, ctx);
109 return node;
110}
111
112std::shared_ptr<Nodes::Network::NodeNetwork> operator|(const std::shared_ptr<Nodes::Network::NodeNetwork>& network, Domain d)
113{
114 CreationContext ctx(d);
115 register_network(network, ctx);
116 return network;
117}
118
119std::shared_ptr<Buffers::Buffer> operator|(const std::shared_ptr<Buffers::Buffer>& buffer, Domain d)
120{
121 CreationContext ctx(d);
122 register_buffer(buffer, ctx);
123 return buffer;
124}
125
126std::shared_ptr<Buffers::TextureBuffer> Creator::load_buffer(const std::string& filepath)
127{
128 return get_io_manager()->load_image(filepath);
129}
130
131std::shared_ptr<Nodes::Input::HIDNode> Creator::read_hid(
132 const Nodes::Input::HIDConfig& config,
133 const Core::InputBinding& binding)
134{
135 auto node = std::make_shared<Nodes::Input::HIDNode>(config);
136 register_input_node(node, binding);
137 return node;
138}
139
140std::shared_ptr<Nodes::Input::MIDINode> Creator::read_midi(
141 const Nodes::Input::MIDIConfig& config,
142 const Core::InputBinding& binding)
143{
144 auto node = std::make_shared<Nodes::Input::MIDINode>(config);
145 register_input_node(node, binding);
146 return node;
147}
148
149std::shared_ptr<Nodes::Input::InputNode> Creator::read_input(
150 const Nodes::Input::InputConfig& config,
151 const Core::InputBinding& binding)
152{
153 switch (binding.backend) {
155 return read_hid(static_cast<const Nodes::Input::HIDConfig&>(config), binding);
157 return read_midi(static_cast<const Nodes::Input::MIDIConfig&>(config), binding);
158 default:
160 "Input type {} not yet implemented",
161 static_cast<int>(binding.backend));
162 return nullptr;
163 }
164}
165
166} // namespace MayaFlux
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
Audio file loading and container management API.
std::shared_ptr< Nodes::Input::InputNode > read_input(const Nodes::Input::InputConfig &config, const Core::InputBinding &binding)
Create and register generic input node.
Definition Creator.cpp:149
std::shared_ptr< Nodes::Input::HIDNode > read_hid(const Nodes::Input::HIDConfig &config, const Core::InputBinding &binding)
Create and register HID input node.
Definition Creator.cpp:131
std::shared_ptr< Buffers::TextureBuffer > load_buffer(const std::string &filepath)
Definition Creator.cpp:126
std::shared_ptr< Kakshya::SoundFileContainer > load_sound_container(const std::string &filepath)
Definition Creator.cpp:100
std::shared_ptr< Nodes::Input::MIDINode > read_midi(const Nodes::Input::MIDIConfig &config, const Core::InputBinding &binding)
Create and register MIDI input node.
Definition Creator.cpp:140
@ HID
Generic HID devices (game controllers, custom hardware)
@ MIDI
MIDI controllers and instruments.
@ Init
Engine/subsystem initialization.
@ API
MayaFlux/API Wrapper and convenience functions.
@ GRAPHICS_BIND
State available for visualization (read-only)
@ AUDIO_COMPUTE
processed each cycle but not sent to output
@ AUDIO_SINK
Aggregated audio samples sent to output.
@ AUDIO_RATE
Nodes that process at the audio sample rate.
@ VISUAL_RATE
Nodes that process at the visual frame rate.
void register_input_node(const std::shared_ptr< Nodes::Input::InputNode > &node, const Core::InputBinding &binding)
Register an input node with specified binding.
Definition Input.cpp:21
Creator vega
Global Creator instance for creating nodes, buffers, and containers.
Definition Creator.cpp:19
void register_node(const std::shared_ptr< Nodes::Node > &node, const Nodes::ProcessingToken &token, uint32_t channel)
Definition Graph.cpp:124
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:72
void register_node_network(const std::shared_ptr< Nodes::Network::NodeNetwork > &network, const Nodes::ProcessingToken &token)
Registers a node network with the default engine's node graph manager.
Definition Graph.cpp:178
std::shared_ptr< Nodes::Node > operator|(const std::shared_ptr< Nodes::Node > &node, Domain d)
Definition Creator.cpp:105
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:257
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:215
void register_container(const std::shared_ptr< Kakshya::SoundFileContainer > &container, const Domain &domain)
Definition Creator.cpp:91
Domain
Unified domain enum combining all three ProcessingToken subsystems.
Definition Domain.hpp:22
@ AUDIO
Standard real-time audio processing domain.
Definition Domain.hpp:33
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:225
std::shared_ptr< IO::IOManager > get_io_manager()
Retrieves the global IOManager instance for file loading and buffer management.
Definition Depot.cpp:50
void register_network(const std::shared_ptr< Nodes::Network::NodeNetwork > &network, const CreationContext &ctx)
Definition Creator.cpp:42
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
InputType backend
Which backend type.
Specifies what input an InputNode wants to receive.
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
Unified configuration for all HID input types.
Definition HIDNode.hpp:21
Configuration for InputNode behavior.
Definition InputNode.hpp:79
MIDI input node configuration.
Definition MIDINode.hpp:10