HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
ttauri
audio
audio_system.hpp
1
// Copyright Take Vos 2020.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5
#pragma once
6
7
#include "audio_system_delegate.hpp"
8
#include "audio_device.hpp"
9
#include "../unfair_recursive_mutex.hpp"
10
#include "../weak_or_unique_ptr.hpp"
11
#include <vector>
12
#include <memory>
13
14
namespace
tt {
15
19
class
audio_system
{
20
public
:
21
static
inline
unfair_recursive_mutex
mutex;
22
23
audio_system
(
weak_or_unique_ptr<audio_system_delegate>
delegate);
24
virtual
~audio_system
();
25
audio_system
(
audio_system
const
&) =
delete
;
26
audio_system
(
audio_system
&&) =
delete
;
27
audio_system
&operator=(
audio_system
const
&) =
delete
;
28
audio_system
&operator=(
audio_system
&&) =
delete
;
29
30
[[nodiscard]]
virtual
std::vector<std::shared_ptr<audio_device>
> devices()
noexcept
= 0;
31
32
virtual
void
init()
noexcept
;
33
virtual
void
deinit()
noexcept
;
34
35
void
set_delegate(
weak_or_unique_ptr<audio_system_delegate>
delegate)
noexcept
36
{
37
{
38
ttlet lock = std::scoped_lock(audio_system::mutex);
39
_delegate =
std::move
(delegate);
40
}
41
if
(
auto
d = delegate_lock()) {
42
d->audio_device_list_changed(*
this
);
43
}
44
}
45
46
[[nodiscard]]
std::shared_ptr<audio_system_delegate>
delegate_lock()
const
noexcept
47
{
48
ttlet lock = std::scoped_lock(audio_system::mutex);
49
return
_delegate.lock();
50
}
51
52
[[nodiscard]]
static
audio_system
&global()
noexcept
53
{
54
return
*start_subsystem_or_terminate(_global,
nullptr
, subsystem_init, subsystem_deinit);
55
}
56
57
protected
:
58
weak_or_unique_ptr<audio_system_delegate>
_delegate;
59
60
private
:
61
static
inline
std::atomic<audio_system *>
_global;
62
63
[[nodiscard]]
static
audio_system
*subsystem_init()
noexcept
;
64
static
void
subsystem_deinit()
noexcept
;
65
};
66
67
}
// namespace tt
tt::audio_system
Definition
audio_system.hpp:19
tt::unfair_recursive_mutex
An unfair recursive-mutex This is a fast implementation of a recursive-mutex which does not fairly ar...
Definition
unfair_recursive_mutex.hpp:32
tt::weak_or_unique_ptr
Class that hold either a weak_ptr or a unique_ptr This class is to hold a weak_ptr,...
Definition
weak_or_unique_ptr.hpp:25
std::atomic
std::move
T move(T... args)
std::shared_ptr
std::vector
Generated on Mon Apr 22 2024 12:53:38 for HikoGUI by
1.10.0