MayaFlux 0.1.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 std::recursive_mutex engine_mutex;
17
19 {
20 std::lock_guard<std::recursive_mutex> lock(engine_mutex);
21 if (engine_ref) {
22 if (initialized) {
23 if (engine_ref->is_running()) {
24 engine_ref->Pause();
25 }
26 engine_ref->End();
28 }
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 initialized = true;
42 return *engine_ref;
43 }
44
45}
46
47//-------------------------------------------------------------------------
48// Engine Management
49//-------------------------------------------------------------------------
50
52{
54}
55
60
62{
63 bool is_same_instance = false;
64
65 {
66 std::lock_guard<std::recursive_mutex> lock(internal::engine_mutex);
67 is_same_instance = (&instance == internal::engine_ref.get());
68 if (internal::engine_ref && !is_same_instance && internal::engine_ref->is_running()) {
69 internal::engine_ref->Pause();
70 }
71 }
72
73 if (internal::engine_ref && !is_same_instance) {
75 }
76
77 if (!is_same_instance) {
78 std::lock_guard<std::recursive_mutex> lock(internal::engine_mutex);
79 internal::engine_ref = std::make_unique<Core::Engine>(std::move(instance));
81 }
82}
83
84void Init()
85{
86 auto& engine = internal::get_or_create_engine();
87 engine.Init();
88}
89
90void Init(uint32_t sample_rate, uint32_t buffer_size, uint32_t num_out_channels, uint32_t num_in_channels)
91{
92 auto& engine = internal::get_or_create_engine();
93 auto& stream_info = engine.get_stream_info();
94
95 stream_info.sample_rate = sample_rate;
96 stream_info.buffer_size = buffer_size;
97 stream_info.output.channels = num_out_channels;
98 stream_info.input.channels = num_in_channels;
99 engine.Init();
100}
101
103{
104 auto& engine = internal::get_or_create_engine();
105 engine.Init(stream_info);
106}
107
109{
110 auto& engine = internal::get_or_create_engine();
111 engine.Init(stream_info, graphics_config);
112}
113
114void Start()
115{
116 get_context().Start();
117}
118
119void Pause()
120{
122 get_context().Pause();
123 }
124}
125
126void Resume()
127{
130 }
131}
132
133void End()
134{
137 }
138}
139
140}
Core engine lifecycle and configuration API.
void Resume()
Resumes processing from paused state.
Definition Engine.cpp:136
void Start()
Starts the coordinated processing of all subsystems.
Definition Engine.cpp:118
void Pause()
Pauses all processing while maintaining system state.
Definition Engine.cpp:126
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:16
void cleanup_engine()
Definition Core.cpp:18
std::unique_ptr< Core::Engine > engine_ref
Definition Core.cpp:14
Core::Engine & get_or_create_engine()
Definition Core.cpp:34
void Resume()
Resumes audio processing on the default engine.
Definition Core.cpp:126
void Start()
Starts audio processing on the default engine.
Definition Core.cpp:114
void Pause()
Pauses audio processing on the default engine.
Definition Core.cpp:119
void Init()
Initializes the default engine with default settings.
Definition Core.cpp:84
void set_and_transfer_context(Core::Engine instance)
Replaces the default engine with a new instance.
Definition Core.cpp:61
Core::Engine & get_context()
Gets the default engine instance.
Definition Core.cpp:56
bool is_initialized()
Checks if the default engine has been initialized.
Definition Core.cpp:51
void End()
Stops and cleans up the default engine.
Definition Core.cpp:133
Main namespace for the Maya Flux audio engine.
Definition LiveAid.hpp:6
Comprehensive configuration for digital audio stream processing.