MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Engine.cpp
Go to the documentation of this file.
1#include "Engine.hpp"
2
9
11
12namespace MayaFlux::Core {
13
14//-------------------------------------------------------------------------
15// Initialization and Lifecycle
16//-------------------------------------------------------------------------
17
19 : m_rng(new Nodes::Generator::Stochastics::Random())
20{
21}
22
24{
25 End();
26}
27
28Engine::Engine(Engine&& other) noexcept
29 : m_stream_info(other.m_stream_info)
30 , m_graphics_config(other.m_graphics_config)
31 , m_is_paused(other.m_is_paused)
32 , m_is_initialized(other.m_is_initialized)
33 , m_should_shutdown(other.m_should_shutdown.load())
34 , m_scheduler(std::move(other.m_scheduler))
35 , m_node_graph_manager(std::move(other.m_node_graph_manager))
36 , m_buffer_manager(std::move(other.m_buffer_manager))
37 , m_subsystem_manager(std::move(other.m_subsystem_manager))
38 , m_window_manager(std::move(other.m_window_manager))
39 , m_event_manager(std::move(other.m_event_manager))
40 , m_rng(std::move(other.m_rng))
41{
42 other.m_is_initialized = false;
43 other.m_is_paused = false;
44}
45
47{
48 if (this != &other) {
49 End();
50
51 m_stream_info = other.m_stream_info;
52 m_graphics_config = other.m_graphics_config;
53
54 m_subsystem_manager = std::move(other.m_subsystem_manager);
55 m_node_graph_manager = std::move(other.m_node_graph_manager);
56 m_buffer_manager = std::move(other.m_buffer_manager);
57 m_scheduler = std::move(other.m_scheduler);
58 m_window_manager = std::move(other.m_window_manager);
59 m_event_manager = std::move(other.m_event_manager);
60 m_rng = std::move(other.m_rng);
61
62 m_is_initialized = other.m_is_initialized;
63 m_is_paused = other.m_is_paused;
64 m_should_shutdown = other.m_should_shutdown.load();
65
66 other.m_is_initialized = false;
67 other.m_is_paused = false;
68 }
69 return *this;
70}
71
76
77void Engine::Init(const GlobalStreamInfo& streamInfo)
78{
79 Init(streamInfo, m_graphics_config);
80}
81
82void Engine::Init(const GlobalStreamInfo& streamInfo, const GlobalGraphicsConfig& graphics_config)
83{
85 m_stream_info = streamInfo;
86 m_graphics_config = graphics_config;
87
88 m_scheduler = std::make_shared<Vruta::TaskScheduler>(m_stream_info.sample_rate);
89 m_event_manager = std::make_shared<Vruta::EventManager>();
90
91 m_buffer_manager = std::make_shared<Buffers::BufferManager>(
95
96 m_node_graph_manager = std::make_shared<Nodes::NodeGraphManager>();
97
99 m_window_manager = std::make_shared<WindowManager>(m_graphics_config);
100 } else {
101 MF_WARN(Journal::Component::Core, Journal::Context::Init, "No windowing backend selected - running in audio-only mode");
102 }
103
104 m_subsystem_manager = std::make_shared<SubsystemManager>(
106
108
109 m_subsystem_manager->create_graphics_subsystem(m_graphics_config);
110
111 m_buffer_manager->initialize_buffer_service();
112
113 m_is_initialized = true;
114
115 MF_PRINT(Journal::Component::Core, Journal::Context::Init, "Audio backend: RtAudio, Sample rate: {}", m_stream_info.sample_rate);
116}
117
119{
120 if (!m_is_initialized) {
121 Init();
122 }
123 m_subsystem_manager->start_all_subsystems();
124}
125
127{
129 return;
130 }
131
132 m_subsystem_manager->pause_all_subsystems();
133 m_is_paused = true;
134}
135
137{
138 if (!m_is_paused || !m_is_initialized) {
139 return;
140 }
141
142 m_subsystem_manager->resume_all_subsystems();
143 m_is_paused = false;
144}
145
147{
149 m_subsystem_manager->shutdown();
150 }
151
152 m_is_initialized = false;
153 m_is_paused = false;
154
155 if (m_buffer_manager) {
156 m_buffer_manager->terminate_active_buffers();
157 m_buffer_manager.reset();
158 }
159
161 for (auto token : m_node_graph_manager->get_active_tokens()) {
162 for (auto root : m_node_graph_manager->get_all_root_nodes(token)) {
163 if (root != nullptr) {
164 root->clear_all_nodes();
165 }
166 }
167 }
168 }
169
170 if (m_window_manager) {
171 auto windows = m_window_manager->get_windows();
172 for (auto& window : windows) {
173 m_window_manager->destroy_window(window);
174 }
175 m_window_manager.reset();
176 }
177}
178
180{
182 return false;
183 }
184
185 if (m_is_initialized) {
186 auto status = m_subsystem_manager->query_subsystem_status();
187 for (const auto& [type, readiness] : status) {
188 const auto& [is_ready, is_running] = readiness;
189 if (is_ready && is_running) {
190 return true;
191 }
192 }
193 }
194 return false;
195}
196
197} // namespace MayaFlux::Core
#define MF_PRINT(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
void Init()
Initializes all system components and prepares for processing.
Definition Engine.cpp:72
std::shared_ptr< SubsystemManager > m_subsystem_manager
Definition Engine.hpp:316
GlobalGraphicsConfig m_graphics_config
Graphics/windowing configuration.
Definition Engine.hpp:302
void Resume()
Resumes processing from paused state.
Definition Engine.cpp:136
std::shared_ptr< Vruta::EventManager > m_event_manager
Event manager (currently only glfw events)
Definition Engine.hpp:318
std::shared_ptr< Buffers::BufferManager > m_buffer_manager
Buffer manager.
Definition Engine.hpp:315
GlobalStreamInfo m_stream_info
Stream configuration.
Definition Engine.hpp:301
bool is_running() const
Checks if the coordinated processing system is currently active.
Definition Engine.cpp:179
void Start()
Starts the coordinated processing of all subsystems.
Definition Engine.cpp:118
void Pause()
Pauses all processing while maintaining system state.
Definition Engine.cpp:126
bool m_is_paused
Pause state flag.
Definition Engine.hpp:304
std::shared_ptr< WindowManager > m_window_manager
Window manager (Windowing subsystem)
Definition Engine.hpp:317
Engine()
Constructs a new Engine instance.
Definition Engine.cpp:18
std::shared_ptr< Vruta::TaskScheduler > m_scheduler
Task scheduler.
Definition Engine.hpp:313
~Engine()
Destroys the Engine instance and cleans up resources.
Definition Engine.cpp:23
void End()
Stops all processing and performs clean shutdown.
Definition Engine.cpp:146
std::shared_ptr< Nodes::NodeGraphManager > m_node_graph_manager
Node graph manager.
Definition Engine.hpp:314
Engine & operator=(const Engine &)=delete
Central lifecycle manager and component orchestrator for the MayaFlux processing system.
Definition Engine.hpp:77
@ Init
Engine/subsystem initialization.
@ Core
Core engine, backend, subsystems.
void End()
Stops and cleans up the default engine.
Definition Core.cpp:133
@ NONE
No windowing (offscreen rendering only)
WindowingBackend windowing_backend
Selected windowing backend.
uint32_t channels
Number of discrete channels in this set.
bool enabled
Whether this channel set is active in the stream.
uint32_t buffer_size
Number of samples per processing block.
ChannelConfig input
Configuration for input signal channels (disabled by default)
uint32_t sample_rate
Number of samples processed per second (Hz)
ChannelConfig output
Configuration for output signal channels.
Comprehensive configuration for digital audio stream processing.