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