MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Core.cpp
Go to the documentation of this file.
1#include "Core.hpp"
3
5
6namespace MayaFlux {
7
8//-------------------------------------------------------------------------
9// Internal Functions and Data
10//-------------------------------------------------------------------------
11
12namespace internal {
13
14 std::unique_ptr<Core::Engine> engine_ref;
15 bool initialized = false;
16 bool terminating = false;
17 std::recursive_mutex engine_mutex;
18
20 {
21 std::lock_guard<std::recursive_mutex> lock(engine_mutex);
22 if (engine_ref) {
23 if (initialized) {
24 engine_ref->End();
26 }
27 engine_ref.reset();
28 initialized = false;
29 }
30 }
31
33 {
34 std::lock_guard<std::recursive_mutex> lock(engine_mutex);
35 if (!engine_ref) {
36 engine_ref = std::make_unique<Core::Engine>();
37 std::atexit(cleanup_engine);
38 }
39 terminating = false;
40 initialized = true;
41 return *engine_ref;
42 }
43
44}
45
46//-------------------------------------------------------------------------
47// Engine Management
48//-------------------------------------------------------------------------
49
51{
53 return false;
54 }
56}
57
62
64{
65 bool is_same_instance = false;
66
67 {
68 std::lock_guard<std::recursive_mutex> lock(internal::engine_mutex);
69 is_same_instance = (&instance == internal::engine_ref.get());
70 if (internal::engine_ref && !is_same_instance && internal::engine_ref->is_running()) {
71 internal::engine_ref->Pause();
72 }
73 }
74
75 if (internal::engine_ref && !is_same_instance) {
77 }
78
79 if (!is_same_instance) {
80 std::lock_guard<std::recursive_mutex> lock(internal::engine_mutex);
81 internal::engine_ref = std::make_unique<Core::Engine>(std::move(instance));
83 }
84}
85
86void Init()
87{
88 auto& engine = internal::get_or_create_engine();
89 engine.Init();
90}
91
92void Init(uint32_t sample_rate, uint32_t buffer_size, uint32_t num_out_channels, uint32_t num_in_channels)
93{
94 auto& engine = internal::get_or_create_engine();
95 auto& stream_info = engine.get_stream_info();
96
97 stream_info.sample_rate = sample_rate;
98 stream_info.buffer_size = buffer_size;
99 stream_info.output.channels = num_out_channels;
100 stream_info.input.channels = num_in_channels;
101 engine.Init();
102}
103
105{
106 auto& engine = internal::get_or_create_engine();
107 engine.Init(stream_info);
108}
109
111{
112 auto& engine = internal::get_or_create_engine();
113 engine.Init(stream_info, graphics_config);
114}
115
116void Start()
117{
118 get_context().Start();
119}
120
121void Pause()
122{
124 get_context().Pause();
125 }
126}
127
128void Resume()
129{
132 }
133}
134
135void Await()
136{
139 }
140}
141
142void End()
143{
147 }
148}
149
150}
Core engine lifecycle and configuration API.
void await_shutdown()
Blocks until shutdown is requested (main thread event loop)
Definition Engine.cpp:169
void Resume()
Resumes processing from paused state.
Definition Engine.cpp:141
void Start()
Starts the coordinated processing of all subsystems.
Definition Engine.cpp:123
void Pause()
Pauses all processing while maintaining system state.
Definition Engine.cpp:131
Central lifecycle manager and component orchestrator for the MayaFlux processing system.
Definition Engine.hpp:77
static void shutdown()
Shutdown the logging system.
std::recursive_mutex engine_mutex
Definition Core.cpp:17
void cleanup_engine()
Definition Core.cpp:19
std::unique_ptr< Core::Engine > engine_ref
Definition Core.cpp:14
Core::Engine & get_or_create_engine()
Definition Core.cpp:32
void Resume()
Resumes audio processing on the default engine.
Definition Core.cpp:128
void Start()
Starts audio processing on the default engine.
Definition Core.cpp:116
void Pause()
Pauses audio processing on the default engine.
Definition Core.cpp:121
void Init()
Initializes the default engine with default settings.
Definition Core.cpp:86
void set_and_transfer_context(Core::Engine instance)
Replaces the default engine with a new instance.
Definition Core.cpp:63
Core::Engine & get_context()
Gets the default engine instance.
Definition Core.cpp:58
void Await()
Blocks launcher until user input (optional convenience function)
Definition Core.cpp:135
bool is_initialized()
Checks if the default engine has been initialized.
Definition Core.cpp:50
void End()
Stops and cleans up the default engine.
Definition Core.cpp:142
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6
Comprehensive configuration for digital audio stream processing.