17#ifdef MAYAFLUX_PLATFORM_MACOS
18#include <CoreFoundation/CoreFoundation.h>
24#ifdef MAYAFLUX_PLATFORM_WINDOWS
28#ifdef MAYAFLUX_PLATFORM_LINUX
40 : m_stochastic_engine(new Kinesis::Stochastic::Stochastic(Kinesis::Stochastic::Algorithm::UNIFORM))
50 : m_stream_info(other.m_stream_info)
51 , m_graphics_config(other.m_graphics_config)
52 , m_is_paused(other.m_is_paused)
53 , m_is_initialized(other.m_is_initialized)
54 , m_should_shutdown(other.m_should_shutdown.load())
55 , m_scheduler(std::move(other.m_scheduler))
56 , m_node_graph_manager(std::move(other.m_node_graph_manager))
57 , m_buffer_manager(std::move(other.m_buffer_manager))
58 , m_subsystem_manager(std::move(other.m_subsystem_manager))
59 , m_window_manager(std::move(other.m_window_manager))
60 , m_event_manager(std::move(other.m_event_manager))
61 , m_input_manager(std::move(other.m_input_manager))
62 , m_io_manager(std::move(other.m_io_manager))
63 , m_stochastic_engine(std::move(other.m_stochastic_engine))
65 other.m_is_initialized =
false;
66 other.m_is_paused =
false;
74 m_stream_info = other.m_stream_info;
75 m_graphics_config = other.m_graphics_config;
77 m_subsystem_manager = std::move(other.m_subsystem_manager);
78 m_node_graph_manager = std::move(other.m_node_graph_manager);
79 m_buffer_manager = std::move(other.m_buffer_manager);
80 m_scheduler = std::move(other.m_scheduler);
81 m_window_manager = std::move(other.m_window_manager);
82 m_event_manager = std::move(other.m_event_manager);
83 m_input_manager = std::move(other.m_input_manager);
84 m_io_manager = std::move(other.m_io_manager);
85 m_stochastic_engine = std::move(other.m_stochastic_engine);
87 m_is_initialized = other.m_is_initialized;
88 m_is_paused = other.m_is_paused;
89 m_should_shutdown = other.m_should_shutdown.load();
91 other.m_is_initialized =
false;
92 other.m_is_paused =
false;
194 for (
const auto& [
type, readiness] : status) {
195 const auto& [is_ready,
is_running] = readiness;
206#ifdef MAYAFLUX_PLATFORM_MACOS
207 run_macos_event_loop();
208#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
209 static HANDLE s_shutdown_event = CreateEventW(
nullptr, TRUE, FALSE,
nullptr);
210 if (!s_shutdown_event) {
212 "Failed to create shutdown event (GetLastError={}), cannot await Ctrl-C", GetLastError());
215 ResetEvent(s_shutdown_event);
217 SetConsoleCtrlHandler([](DWORD
type) -> BOOL {
218 if (
type == CTRL_C_EVENT ||
type == CTRL_BREAK_EVENT ||
type == CTRL_CLOSE_EVENT) {
219 SetEvent(s_shutdown_event);
226 WaitForSingleObject(s_shutdown_event, INFINITE);
228 static std::atomic<bool> s_signal_received {
false };
229 s_signal_received.store(
false, std::memory_order_relaxed);
231 sigset_t block_mask, orig_mask;
232 sigemptyset(&block_mask);
233 sigaddset(&block_mask, SIGINT);
234 sigaddset(&block_mask, SIGTERM);
235 pthread_sigmask(SIG_BLOCK, &block_mask, &orig_mask);
237 struct sigaction sa {};
238 sigemptyset(&sa.sa_mask);
239 sa.sa_handler = [](int) { s_signal_received.store(
true, std::memory_order_release); };
240 sigaction(SIGINT, &sa,
nullptr);
241 sigaction(SIGTERM, &sa,
nullptr);
243 while (!s_signal_received.load(std::memory_order_acquire)) {
244 sigsuspend(&orig_mask);
247 pthread_sigmask(SIG_SETMASK, &orig_mask,
nullptr);
253 "Shutdown requested, awaiting all subsystem termination ......");
260#ifdef MAYAFLUX_PLATFORM_MACOS
261 CFRunLoopStop(CFRunLoopGetMain());
270#ifdef MAYAFLUX_PLATFORM_MACOS
271void Engine::run_macos_event_loop()
273 CFRunLoopRef runLoop = CFRunLoopGetMain();
275 signal(SIGINT, SIG_IGN);
276 signal(SIGTERM, SIG_IGN);
278 dispatch_source_t sigintSource = dispatch_source_create(
279 DISPATCH_SOURCE_TYPE_SIGNAL,
282 dispatch_get_main_queue());
284 dispatch_source_t sigtermSource = dispatch_source_create(
285 DISPATCH_SOURCE_TYPE_SIGNAL,
288 dispatch_get_main_queue());
290 dispatch_source_set_event_handler(sigintSource, ^{
294 dispatch_source_set_event_handler(sigtermSource, ^{
298 dispatch_resume(sigintSource);
299 dispatch_resume(sigtermSource);
304 "Main thread event loop running (polling at {}fps)",
308 CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeout_seconds,
false);
311 dispatch_source_cancel(sigintSource);
312 dispatch_release(sigintSource);
313 dispatch_source_cancel(sigtermSource);
314 dispatch_release(sigtermSource);
317 "Main thread event loop exiting");
327#ifdef MAYAFLUX_PLATFORM_MACOS
328 if (CFRunLoopGetCurrent() == CFRunLoopGetMain()) {
329 auto stopped = std::async(std::launch::async, [
this]() {
332 while (stopped.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready) {
333 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.01,
false);
382 for (
auto&
window : windows) {
#define MF_INFO(comp, ctx,...)
#define MF_LOG(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
std::weak_ptr< Core::Window > window
vk::PhysicalDeviceType type
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.
void stop_subsystems()
Stops subsystems while servicing required main thread work on macOS.
std::shared_ptr< Vruta::EventManager > m_event_manager
Event manager.
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.
void shutdown()
Shutdown Portal::System and release all resources.
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.