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