MayaFlux 0.4.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
17
18namespace MayaFlux {
19
21
22void register_node(const std::shared_ptr<Nodes::Node>& node, const CreationContext& ctx)
23{
24 auto token = get_node_token(ctx.domain.value());
25
26 if (ctx.channel.has_value()) {
27 register_node(node, token, ctx.channel.value());
28 } else if (ctx.channels.has_value()) {
29 for (uint32_t ch : ctx.channels.value()) {
30 register_node(node, token, ch);
31 }
32 } else if (node->get_channel_mask() != 0) {
33 for (uint32_t ch = 0; ch < 32; ++ch) {
34 if (node->get_channel_mask() & (1 << ch)) {
35 register_node(node, token, ch);
36 }
37 }
38 } else {
39 register_node(node, token, 0);
40 }
41}
42
43void register_network(const std::shared_ptr<Nodes::Network::NodeNetwork>& network, const CreationContext& ctx)
44{
45 auto token = get_node_token(ctx.domain.value());
46
48 if (
49 network->get_output_mode() != Nodes::Network::OutputMode::AUDIO_SINK
50 && network->get_output_mode() != Nodes::Network::OutputMode::AUDIO_COMPUTE) {
53 "Registering audio network in AUDIO_RATE domain without AUDIO_SINK or AUDIO_COMPUTE mode. Forcing AUDIO_SINK mode.");
54 network->set_output_mode(Nodes::Network::OutputMode::AUDIO_SINK);
55 }
56 if (ctx.channel.has_value()) {
57 network->add_channel_usage(ctx.channel.value());
58 } else if (ctx.channels.has_value()) {
59 for (uint32_t ch : ctx.channels.value()) {
60 network->add_channel_usage(ch);
61 }
62 }
63 } else if (token == Nodes::ProcessingToken::VISUAL_RATE && network->get_output_mode() != Nodes::Network::OutputMode::GRAPHICS_BIND) {
66 "Registering visual network in VISUAL_RATE domain without GRAPHICS_BIND output mode. Forcing GRAPHICS_BIND mode.");
67 network->set_output_mode(Nodes::Network::OutputMode::GRAPHICS_BIND);
68 }
69
70 register_node_network(network, token);
71}
72
73void register_buffer(const std::shared_ptr<Buffers::Buffer>& buffer, const CreationContext& ctx)
74{
75 auto token = get_buffer_token(ctx.domain.value());
76
77 if (auto audio_buffer = std::dynamic_pointer_cast<Buffers::AudioBuffer>(buffer)) {
78 if (ctx.channel.has_value()) {
79 register_audio_buffer(audio_buffer, ctx.channel.value());
80 } else if (ctx.channels.has_value()) {
81 register_audio_buffer(audio_buffer, ctx.channels.value()[0]);
82 for (size_t i = 1; i < ctx.channels.value().size(); ++i) {
83 clone_buffer_to_channels(audio_buffer, { static_cast<uint32_t>(i) }, token);
84 }
85 } else {
86 register_audio_buffer(audio_buffer, audio_buffer->get_channel_id());
87 }
88 return;
89 }
90
91 if (auto vk_buffer = std::dynamic_pointer_cast<Buffers::VKBuffer>(buffer)) {
92 register_graphics_buffer(vk_buffer, token);
93 return;
94 }
95}
96
97void register_container(const std::shared_ptr<Kakshya::SoundFileContainer>& container, const Domain& domain)
98{
99 if (auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container)) {
100 if (domain == Domain::AUDIO) {
101 (void)get_io_manager()->hook_audio_container_to_buffers(sound_container);
102 }
103 }
104}
105
106std::shared_ptr<Kakshya::SoundFileContainer> Creator::load_sound_container(const std::string& filepath)
107{
108 return get_io_manager()->load_audio(filepath);
109}
110
112 std::vector<std::shared_ptr<Buffers::MeshBuffer>> buffers)
113 : m_buffers(std::move(buffers))
114{
115}
116
118
120{
121 CreationContext ctx(d);
122 for (const auto& buf : m_buffers) {
124 std::static_pointer_cast<Buffers::Buffer>(buf), ctx);
125 }
126 return *this;
127}
128
129std::shared_ptr<Buffers::TextureBuffer> Creator::load_image_buffer(const std::string& filepath)
130{
131 return get_io_manager()->load_image(filepath);
132}
133
134std::vector<std::shared_ptr<Buffers::MeshBuffer>> Creator::load_mesh_buffers(const std::string& filepath)
135{
136 return get_io_manager()->load_mesh(filepath);
137}
138
139std::shared_ptr<Nodes::Network::MeshNetwork>
140Creator::load_mesh_network(const std::string& filepath, IO::TextureResolver resolver)
141{
142 return get_io_manager()->load_mesh_network(filepath, std::move(resolver));
143}
144
145std::shared_ptr<Nodes::Input::HIDNode> Creator::read_hid(
146 const Nodes::Input::HIDConfig& config,
147 const Core::InputBinding& binding)
148{
149 auto node = std::make_shared<Nodes::Input::HIDNode>(config);
150 register_input_node(node, binding);
151 return node;
152}
153
154std::shared_ptr<Nodes::Input::MIDINode> Creator::read_midi(
155 const Nodes::Input::MIDIConfig& config,
156 const Core::InputBinding& binding)
157{
158 auto node = std::make_shared<Nodes::Input::MIDINode>(config);
159 register_input_node(node, binding);
160 return node;
161}
162
163std::shared_ptr<Nodes::Input::OSCNode> Creator::read_osc(
164 const Nodes::Input::OSCConfig& config,
165 const Core::InputBinding& binding)
166{
167 auto node = std::make_shared<Nodes::Input::OSCNode>(config);
168 register_input_node(node, binding);
169 return node;
170}
171
172std::shared_ptr<Nodes::Input::InputNode> Creator::read_input(
173 const Nodes::Input::InputConfig& config,
174 const Core::InputBinding& binding)
175{
176 switch (binding.backend) {
178 return read_hid(static_cast<const Nodes::Input::HIDConfig&>(config), binding);
180 return read_midi(static_cast<const Nodes::Input::MIDIConfig&>(config), binding);
182 return read_osc(static_cast<const Nodes::Input::OSCConfig&>(config), binding);
183 default:
185 "Input type {} not yet implemented",
186 static_cast<int>(binding.backend));
187 return nullptr;
188 }
189}
190
191} // namespace MayaFlux
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
Audio file loading and container management API.
Range size
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:172
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:145
std::vector< std::shared_ptr< Buffers::MeshBuffer > > load_mesh_buffers(const std::string &filepath)
Definition Creator.cpp:134
std::shared_ptr< Nodes::Input::OSCNode > read_osc(const Nodes::Input::OSCConfig &config, const Core::InputBinding &binding)
Create and register OSC input node.
Definition Creator.cpp:163
std::shared_ptr< Kakshya::SoundFileContainer > load_sound_container(const std::string &filepath)
Definition Creator.cpp:106
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:154
std::shared_ptr< Nodes::Network::MeshNetwork > load_mesh_network(const std::string &filepath, IO::TextureResolver resolver)
Definition Creator.cpp:140
std::shared_ptr< Buffers::TextureBuffer > load_image_buffer(const std::string &filepath)
Definition Creator.cpp:129
std::vector< std::shared_ptr< Buffers::MeshBuffer > > m_buffers
Definition Creator.hpp:102
MeshGroupHandle & operator|(Domain d)
Definition Creator.cpp:119
MeshGroupHandle(std::vector< std::shared_ptr< Buffers::MeshBuffer > > buffers)
Definition Creator.cpp:111
@ OSC
Open Sound Control (network)
@ HID
Generic HID devices (game controllers, custom hardware)
@ MIDI
MIDI controllers and instruments.
std::function< std::shared_ptr< Core::VKImage >(const std::string &path)> TextureResolver
Callable that maps a raw material texture path to a GPU image.
Definition Creator.hpp:17
@ 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.
Definition Creator.cpp:20
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:73
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:193
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:272
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:230
void register_container(const std::shared_ptr< Kakshya::SoundFileContainer > &container, const Domain &domain)
Definition Creator.cpp:97
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:240
std::shared_ptr< IO::IOManager > get_io_manager()
Retrieves the global IOManager instance for file loading and buffer management.
Definition Depot.cpp:79
void register_network(const std::shared_ptr< Nodes::Network::NodeNetwork > &network, const CreationContext &ctx)
Definition Creator.cpp:43
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
InputType backend
Which backend type.
Specifies what input an InputNode wants to receive.
std::optional< uint32_t > channel
Definition Creator.hpp:22
std::optional< std::vector< uint32_t > > channels
Definition Creator.hpp:23
std::optional< Domain > domain
Definition Creator.hpp:21
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
Configuration for OSC input node argument extraction.
Definition OSCNode.hpp:16