17#ifdef MAYAFLUX_PLATFORM_MACOS
18#include <CoreFoundation/CoreFoundation.h>
22#ifdef MAYAFLUX_PLATFORM_WINDOWS
26#ifdef MAYAFLUX_PLATFORM_LINUX
37 : m_stochastic_engine(new Kinesis::Stochastic::Stochastic(Kinesis::Stochastic::Algorithm::UNIFORM))
47 : m_stream_info(other.m_stream_info)
48 , m_graphics_config(other.m_graphics_config)
49 , m_is_paused(other.m_is_paused)
50 , m_is_initialized(other.m_is_initialized)
51 , m_should_shutdown(other.m_should_shutdown.load())
52 , m_scheduler(std::move(other.m_scheduler))
53 , m_node_graph_manager(std::move(other.m_node_graph_manager))
54 , m_buffer_manager(std::move(other.m_buffer_manager))
55 , m_subsystem_manager(std::move(other.m_subsystem_manager))
56 , m_window_manager(std::move(other.m_window_manager))
57 , m_event_manager(std::move(other.m_event_manager))
58 , m_input_manager(std::move(other.m_input_manager))
59 , m_io_manager(std::move(other.m_io_manager))
60 , m_stochastic_engine(std::move(other.m_stochastic_engine))
62 other.m_is_initialized =
false;
63 other.m_is_paused =
false;
71 m_stream_info = other.m_stream_info;
72 m_graphics_config = other.m_graphics_config;
74 m_subsystem_manager = std::move(other.m_subsystem_manager);
75 m_node_graph_manager = std::move(other.m_node_graph_manager);
76 m_buffer_manager = std::move(other.m_buffer_manager);
77 m_scheduler = std::move(other.m_scheduler);
78 m_window_manager = std::move(other.m_window_manager);
79 m_event_manager = std::move(other.m_event_manager);
80 m_input_manager = std::move(other.m_input_manager);
81 m_io_manager = std::move(other.m_io_manager);
82 m_stochastic_engine = std::move(other.m_stochastic_engine);
84 m_is_initialized = other.m_is_initialized;
85 m_is_paused = other.m_is_paused;
86 m_should_shutdown = other.m_should_shutdown.load();
88 other.m_is_initialized =
false;
89 other.m_is_paused =
false;
191 for (
const auto& [type, readiness] : status) {
192 const auto& [is_ready,
is_running] = readiness;
203#ifdef MAYAFLUX_PLATFORM_MACOS
204 run_macos_event_loop();
205#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
206 static std::atomic<bool> s_signal_received {
false };
207 s_signal_received.store(
false, std::memory_order_relaxed);
209 SetConsoleCtrlHandler([](DWORD type) -> BOOL {
210 if (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT || type == CTRL_CLOSE_EVENT) {
211 s_signal_received.store(
true, std::memory_order_release);
218 HANDLE h_stdin = GetStdHandle(STD_INPUT_HANDLE);
219 bool has_console = h_stdin != INVALID_HANDLE_VALUE && GetFileType(h_stdin) == FILE_TYPE_CHAR;
222 while (!s_signal_received.load(std::memory_order_acquire)
224 if (WaitForSingleObject(h_stdin, 100) == WAIT_OBJECT_0) {
227 if (ReadConsoleInputW(h_stdin, &rec, 1, &read) && read > 0
228 && rec.EventType == KEY_EVENT
229 && rec.Event.KeyEvent.bKeyDown
230 && rec.Event.KeyEvent.wVirtualKeyCode == VK_RETURN) {
239 static std::atomic<bool> s_signal_received {
false };
240 s_signal_received.store(
false, std::memory_order_relaxed);
242 struct sigaction sa {};
243 sa.sa_handler = [](int) { s_signal_received.store(
true, std::memory_order_release); };
244 sigaction(SIGINT, &sa,
nullptr);
245 sigaction(SIGTERM, &sa,
nullptr);
247 bool has_tty = isatty(STDIN_FILENO);
249 while (!s_signal_received.load(std::memory_order_acquire)) {
252 FD_SET(STDIN_FILENO, &fds);
253 timeval tv { .tv_sec = 0, .tv_usec = 100000 };
254 if (select(1, &fds,
nullptr,
nullptr, &tv) > 0) {
256 if (read(STDIN_FILENO, &c, 1) > 0 && c ==
'\n')
263 sigdelset(&mask, SIGINT);
264 sigdelset(&mask, SIGTERM);
273 "Shutdown requested, awaiting all subsystem termination ......");
280#ifdef MAYAFLUX_PLATFORM_MACOS
281 CFRunLoopStop(CFRunLoopGetMain());
290#ifdef MAYAFLUX_PLATFORM_MACOS
291void Engine::run_macos_event_loop()
293 CFRunLoopRef runLoop = CFRunLoopGetMain();
295 dispatch_source_t stdinSource = dispatch_source_create(
296 DISPATCH_SOURCE_TYPE_READ,
299 dispatch_get_main_queue());
301 dispatch_source_set_event_handler(stdinSource, ^{
303 ssize_t bytes_read = read(STDIN_FILENO, buf,
sizeof(buf));
304 if (bytes_read > 0) {
309 dispatch_resume(stdinSource);
314 "Main thread event loop running (polling at {}fps)",
318 CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeout_seconds,
false);
321 dispatch_source_cancel(stdinSource);
322 dispatch_release(stdinSource);
325 "Main thread event loop exiting");
360 for (
auto& window : windows) {
#define MF_INFO(comp, ctx,...)
#define MF_LOG(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.
GlobalNetworkConfig m_network_config
Network configuration.
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.
bool initialize()
Initialize Portal::System.
constexpr std::string_view enum_to_string(EnumType value) noexcept
Universal enum to string converter using magic_enum (original case)
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.
Configuration for the NetworkSubsystem.
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.