MayaFlux 0.2.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
12
15
16namespace MayaFlux {
17
19
20void register_node(const std::shared_ptr<Nodes::Node>& node, const CreationContext& ctx)
21{
22 auto token = get_node_token(ctx.domain.value());
23
24 if (ctx.channel.has_value()) {
25 register_node(node, token, ctx.channel.value());
26 } else if (ctx.channels.has_value()) {
27 for (uint32_t ch : ctx.channels.value()) {
28 register_node(node, token, ch);
29 }
30 } else if (node->get_channel_mask() != 0) {
31 for (uint32_t ch = 0; ch < 32; ++ch) {
32 if (node->get_channel_mask() & (1 << ch)) {
33 register_node(node, token, ch);
34 }
35 }
36 } else {
37 register_node(node, token, 0);
38 }
39}
40
41void register_network(const std::shared_ptr<Nodes::Network::NodeNetwork>& network, const CreationContext& ctx)
42{
43 auto token = get_node_token(ctx.domain.value());
44
46 if (network->get_output_mode() != Nodes::Network::NodeNetwork::OutputMode::AUDIO_SINK) {
49 "Registering audio network in AUDIO_RATE domain without AUDIO_SINK output mode. Forcing AUDIO_SINK mode.");
51 }
52 if (ctx.channel.has_value()) {
53 network->add_channel_usage(ctx.channel.value());
54 } else if (ctx.channels.has_value()) {
55 for (uint32_t ch : ctx.channels.value()) {
56 network->add_channel_usage(ch);
57 }
58 }
59 } else if (token == Nodes::ProcessingToken::VISUAL_RATE && network->get_output_mode() != Nodes::Network::NodeNetwork::OutputMode::GRAPHICS_BIND) {
62 "Registering visual network in VISUAL_RATE domain without GRAPHICS_BIND output mode. Forcing GRAPHICS_BIND mode.");
64 }
65
66 register_node_network(network, token);
67}
68
69void register_buffer(const std::shared_ptr<Buffers::Buffer>& buffer, const CreationContext& ctx)
70{
71 auto token = get_buffer_token(ctx.domain.value());
72
73 if (auto audio_buffer = std::dynamic_pointer_cast<Buffers::AudioBuffer>(buffer)) {
74 if (ctx.channel.has_value()) {
75 register_audio_buffer(audio_buffer, ctx.channel.value());
76 } else if (ctx.channels.has_value()) {
77 clone_buffer_to_channels(audio_buffer, ctx.channels.value(), token);
78 }
79 return;
80 }
81
82 if (auto vk_buffer = std::dynamic_pointer_cast<Buffers::VKBuffer>(buffer)) {
83 register_graphics_buffer(vk_buffer, token);
84 return;
85 }
86}
87
88void register_container(const std::shared_ptr<Kakshya::SoundFileContainer>& container, const Domain& domain)
89{
90 if (auto sound_container = std::dynamic_pointer_cast<Kakshya::SoundFileContainer>(container)) {
91 if (domain == Domain::AUDIO) {
94 }
95 }
96}
97
98std::shared_ptr<Kakshya::SoundFileContainer> Creator::load_container(const std::string& filepath)
99{
100 return load_audio_file(filepath);
101}
102
103std::vector<std::shared_ptr<Buffers::SoundContainerBuffer>> get_last_created_container_buffers()
104{
106}
107
108std::shared_ptr<Nodes::Node> operator|(const std::shared_ptr<Nodes::Node>& node, Domain d)
109{
110 CreationContext ctx(d);
111 register_node(node, ctx);
112 return node;
113}
114
115std::shared_ptr<Nodes::Network::NodeNetwork> operator|(const std::shared_ptr<Nodes::Network::NodeNetwork>& network, Domain d)
116{
117 CreationContext ctx(d);
118 register_network(network, ctx);
119 return network;
120}
121
122std::shared_ptr<Buffers::Buffer> operator|(const std::shared_ptr<Buffers::Buffer>& buffer, Domain d)
123{
124 CreationContext ctx(d);
125 register_buffer(buffer, ctx);
126 return buffer;
127}
128
129std::shared_ptr<Buffers::TextureBuffer> Creator::load_buffer(const std::string& filepath)
130{
131 return load_image_file(filepath);
132}
133
134std::shared_ptr<Nodes::Input::HIDNode> Creator::read_hid(
135 const Nodes::Input::HIDConfig& config,
136 const Core::InputBinding& binding)
137{
138 auto node = std::make_shared<Nodes::Input::HIDNode>(config);
139 register_input_node(node, binding);
140 return node;
141}
142
143std::shared_ptr<Nodes::Input::MIDINode> Creator::read_midi(
144 const Nodes::Input::MIDIConfig& config,
145 const Core::InputBinding& binding)
146{
147 auto node = std::make_shared<Nodes::Input::MIDINode>(config);
148 register_input_node(node, binding);
149 return node;
150}
151
152std::shared_ptr<Nodes::Input::InputNode> Creator::read_input(
153 const Nodes::Input::InputConfig& config,
154 const Core::InputBinding& binding)
155{
156 switch (binding.backend) {
158 return read_hid(static_cast<const Nodes::Input::HIDConfig&>(config), binding);
160 return read_midi(static_cast<const Nodes::Input::MIDIConfig&>(config), binding);
161 default:
163 "Input type {} not yet implemented",
164 static_cast<int>(binding.backend));
165 return nullptr;
166 }
167}
168
169} // 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:152
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:134
std::shared_ptr< Buffers::TextureBuffer > load_buffer(const std::string &filepath)
Definition Creator.cpp:129
std::shared_ptr< Kakshya::SoundFileContainer > load_container(const std::string &filepath)
Definition Creator.cpp:98
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:143
@ GRAPHICS_BIND
State available for visualization (read-only)
@ AUDIO_SINK
Aggregated audio samples sent to output.
@ HID
Generic HID devices (game controllers, custom hardware)
@ MIDI
MIDI controllers and instruments.
@ 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
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
std::vector< std::shared_ptr< Buffers::SoundContainerBuffer > > get_last_created_container_buffers()
Retrieves the last created container buffers from the Creator.
Definition Creator.cpp:103
Creator vega
Global Creator instance for creating nodes, buffers, and containers.
Definition Creator.cpp:18
void register_node(const std::shared_ptr< Nodes::Node > &node, const Nodes::ProcessingToken &token, uint32_t channel)
Definition Graph.cpp:102
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:69
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:156
std::shared_ptr< Nodes::Node > operator|(const std::shared_ptr< Nodes::Node > &node, Domain d)
Definition Creator.cpp:108
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:217
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:175
void register_container(const std::shared_ptr< Kakshya::SoundFileContainer > &container, const Domain &domain)
Definition Creator.cpp:88
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:185
std::vector< std::shared_ptr< Buffers::SoundContainerBuffer > > 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_network(const std::shared_ptr< Nodes::Network::NodeNetwork > &network, const CreationContext &ctx)
Definition Creator.cpp:41
static std::vector< std::shared_ptr< Buffers::SoundContainerBuffer > > s_last_created_container_buffers
Definition Creator.hpp:302
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