14#ifdef MAYAFLUX_PLATFORM_MACOS
15#include <CoreFoundation/CoreFoundation.h>
19#ifdef MAYAFLUX_PLATFORM_WINDOWS
30 : m_stochastic_engine(new Kinesis::Stochastic::Stochastic(Kinesis::Stochastic::Algorithm::UNIFORM))
40 : m_stream_info(other.m_stream_info)
41 , m_graphics_config(other.m_graphics_config)
42 , m_is_paused(other.m_is_paused)
43 , m_is_initialized(other.m_is_initialized)
44 , m_should_shutdown(other.m_should_shutdown.load())
45 , m_scheduler(std::move(other.m_scheduler))
46 , m_node_graph_manager(std::move(other.m_node_graph_manager))
47 , m_buffer_manager(std::move(other.m_buffer_manager))
48 , m_subsystem_manager(std::move(other.m_subsystem_manager))
49 , m_window_manager(std::move(other.m_window_manager))
50 , m_event_manager(std::move(other.m_event_manager))
51 , m_input_manager(std::move(other.m_input_manager))
52 , m_io_manager(std::move(other.m_io_manager))
53 , m_stochastic_engine(std::move(other.m_stochastic_engine))
55 other.m_is_initialized =
false;
56 other.m_is_paused =
false;
64 m_stream_info = other.m_stream_info;
65 m_graphics_config = other.m_graphics_config;
67 m_subsystem_manager = std::move(other.m_subsystem_manager);
68 m_node_graph_manager = std::move(other.m_node_graph_manager);
69 m_buffer_manager = std::move(other.m_buffer_manager);
70 m_scheduler = std::move(other.m_scheduler);
71 m_window_manager = std::move(other.m_window_manager);
72 m_event_manager = std::move(other.m_event_manager);
73 m_input_manager = std::move(other.m_input_manager);
74 m_io_manager = std::move(other.m_io_manager);
75 m_stochastic_engine = std::move(other.m_stochastic_engine);
77 m_is_initialized = other.m_is_initialized;
78 m_is_paused = other.m_is_paused;
79 m_should_shutdown = other.m_should_shutdown.load();
81 other.m_is_initialized =
false;
82 other.m_is_paused =
false;
89#ifdef MAYAFLUX_PLATFORM_WINDOWS
90 if (Parallel::g_MainThreadId == 0) {
91 Parallel::g_MainThreadId = GetCurrentThreadId();
184 for (
const auto& [type, readiness] : status) {
185 const auto& [is_ready,
is_running] = readiness;
196#ifdef MAYAFLUX_PLATFORM_MACOS
197 run_macos_event_loop();
198#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
199 run_windows_event_loop();
208 "Shutdown requested, awaiting all subsystem termination ......");
215#ifdef MAYAFLUX_PLATFORM_MACOS
216 CFRunLoopStop(CFRunLoopGetMain());
217#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
218 PostThreadMessage(Parallel::g_MainThreadId, WM_QUIT, 0, 0);
227#ifdef MAYAFLUX_PLATFORM_MACOS
228void Engine::run_macos_event_loop()
230 CFRunLoopRef runLoop = CFRunLoopGetMain();
232 dispatch_source_t stdinSource = dispatch_source_create(
233 DISPATCH_SOURCE_TYPE_READ,
236 dispatch_get_main_queue());
238 dispatch_source_set_event_handler(stdinSource, ^{
240 ssize_t bytes_read = read(STDIN_FILENO, buf,
sizeof(buf));
241 if (bytes_read > 0) {
246 dispatch_resume(stdinSource);
251 "Main thread event loop running (polling at {}fps)",
255 CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeout_seconds,
false);
258 dispatch_source_cancel(stdinSource);
259 dispatch_release(stdinSource);
262 "Main thread event loop exiting");
266#ifdef MAYAFLUX_PLATFORM_WINDOWS
267void Engine::run_windows_event_loop()
270 PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
272 auto stdinSource = std::thread([
this]() {
278 "Main thread event loop running");
281 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
282 if (msg.message == WM_QUIT) {
287 if (msg.message == MAYAFLUX_WM_DISPATCH) {
288 auto* task =
reinterpret_cast<std::function<
void()
>*>(msg.lParam);
294 TranslateMessage(&msg);
295 DispatchMessage(&msg);
299 std::this_thread::sleep_for(std::chrono::milliseconds(1));
302 if (stdinSource.joinable()) {
303 stdinSource.detach();
307 "Main thread event loop exiting");
336 for (
auto& window : windows) {
#define MF_INFO(comp, ctx,...)
#define MF_PRINT(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
void Init()
Initializes all system components and prepares for processing.
std::shared_ptr< SubsystemManager > m_subsystem_manager
void await_shutdown()
Blocks until shutdown is requested (main thread event loop)
std::shared_ptr< IO::IOManager > m_io_manager
IO manager for video/audio loading and dispatch.
GlobalGraphicsConfig m_graphics_config
Graphics/windowing configuration.
void request_shutdown()
Request shutdown from any thread.
void Resume()
Resumes processing from paused state.
std::shared_ptr< Vruta::EventManager > m_event_manager
Event manager (currently only glfw events)
std::shared_ptr< Buffers::BufferManager > m_buffer_manager
Buffer manager.
void set_node_config(const Nodes::NodeConfig &config)
Sets the node processing configuration.
GlobalStreamInfo m_stream_info
Stream configuration.
bool is_running() const
Checks if the coordinated processing system is currently active.
void Start()
Starts the coordinated processing of all subsystems.
Nodes::NodeConfig & get_node_config()
Gets the current node processing configuration.
std::atomic< bool > m_should_shutdown
void Pause()
Pauses all processing while maintaining system state.
bool m_is_paused
Pause state flag.
std::shared_ptr< WindowManager > m_window_manager
Window manager (Windowing subsystem)
Engine()
Constructs a new Engine instance.
std::shared_ptr< Vruta::TaskScheduler > m_scheduler
Task scheduler.
std::shared_ptr< InputManager > m_input_manager
Input manager (HID/MIDI/etc.)
Nodes::NodeConfig m_node_config
Node processing configuration.
~Engine()
Destroys the Engine instance and cleans up resources.
bool is_shutdown_requested() const
Check if shutdown has been requested.
void End()
Stops all processing and performs clean shutdown.
std::shared_ptr< Nodes::NodeGraphManager > m_node_graph_manager
Node graph manager.
Engine & operator=(const Engine &)=delete
GlobalInputConfig m_input_config
Input configuration.
Central lifecycle manager and component orchestrator for the MayaFlux processing system.
@ Init
Engine/subsystem initialization.
@ Runtime
General runtime operations (default fallback)
@ Core
Core engine, backend, subsystems.
void End()
Stops and cleans up the default engine.
@ NONE
No windowing (offscreen rendering only)
uint32_t target_frame_rate
Target frame rate for visual processing (Hz)
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.
Configuration settings for individual audio nodes.