HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
audio_device.hpp
1// Copyright Take Vos 2019-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 "../bigint.hpp"
8#include "audio_device_delegate.hpp"
9#include "audio_stream_config.hpp"
10#include "audio_channel.hpp"
11#include "audio_direction.hpp"
12#include "speaker_mapping.hpp"
13#include "audio_device_id.hpp"
14#include "../label.hpp"
15#include <string>
16#include <memory>
17#include <ostream>
18
19namespace tt {
20
21enum class audio_device_state { active, disabled, not_present, unplugged };
22
23[[nodiscard]] constexpr char const *to_const_string(audio_device_state const &rhs) noexcept
24{
25 switch (rhs) {
26 case audio_device_state::active: return "active";
27 case audio_device_state::disabled: return "disabled";
28 case audio_device_state::not_present: return "not_present";
29 case audio_device_state::unplugged: return "unplugged";
30 default: tt_no_default();
31 }
32}
33
34[[nodiscard]] inline std::string to_string(audio_device_state const &rhs) noexcept
35{
36 return {to_const_string(rhs)};
37}
38
39inline std::ostream &operator<<(std::ostream &lhs, audio_device_state const &rhs)
40{
41 return lhs << to_const_string(rhs);
42}
43
53public:
54 audio_device() noexcept = default;
55 virtual ~audio_device() = default;
56
60
65 [[nodiscard]] virtual std::string name() const noexcept = 0;
66
71 [[nodiscard]] virtual label label() const noexcept = 0;
72
75 [[nodiscard]] virtual audio_device_state state() const noexcept = 0;
76
77 [[nodiscard]] virtual audio_direction direction() const noexcept = 0;
78
83 [[nodiscard]] virtual bool exclusive() const noexcept = 0;
84
99 virtual void set_exclusive(bool exclusive) noexcept = 0;
100
106 [[nodiscard]] virtual double sample_rate() const noexcept = 0;
107
111 virtual void set_sample_rate(double sample_rate) noexcept = 0;
112
117 [[nodiscard]] virtual tt::speaker_mapping input_speaker_mapping() const noexcept = 0;
118
123 virtual void set_input_speaker_mapping(tt::speaker_mapping speaker_mapping) noexcept = 0;
124
129 [[nodiscard]] virtual std::vector<tt::speaker_mapping> available_input_speaker_mappings() const noexcept = 0;
130
135 [[nodiscard]] virtual tt::speaker_mapping output_speaker_mapping() const noexcept = 0;
136
141 virtual void set_output_speaker_mapping(tt::speaker_mapping speaker_mapping) noexcept = 0;
142
147 [[nodiscard]] virtual std::vector<tt::speaker_mapping> available_output_speaker_mappings() const noexcept = 0;
148
163 // virtual void start_stream(std::string id, std::string name) = 0;
164
168 // virtual void stop_stream() noexcept = 0;
169
170private:
171 std::shared_ptr<audio_device_delegate> delegate = {};
172};
173
174} // namespace tt
175
176namespace std {
177
178template<typename CharT>
179struct formatter<tt::audio_device_state, CharT> : formatter<char const *, CharT> {
180 auto format(tt::audio_device_state const &t, auto &fc)
181 {
182 return formatter<char const *, CharT>::format(tt::to_const_string(t), fc);
183 }
184};
185
186} // namespace std
STL namespace.
A set of audio channels which can be rendered and/or captures at the same time.
Definition audio_device.hpp:52
virtual bool exclusive() const noexcept=0
Check if the device is in exclusive mode.
virtual audio_device_state state() const noexcept=0
Get the current state of the audio device.
virtual void set_exclusive(bool exclusive) noexcept=0
Set the device in exclusive or shared mode.
virtual void set_input_speaker_mapping(tt::speaker_mapping speaker_mapping) noexcept=0
Set the input speaker mapping.
virtual double sample_rate() const noexcept=0
Get the currently configured sample rate.
virtual std::vector< tt::speaker_mapping > available_input_speaker_mappings() const noexcept=0
Speaker mapping that are available in the current configuration.
virtual tt::speaker_mapping input_speaker_mapping() const noexcept=0
Get the currently configured input speaker mapping.
virtual void set_sample_rate(double sample_rate) noexcept=0
Set the sample rate.
virtual tt::speaker_mapping output_speaker_mapping() const noexcept=0
Get the currently configured output speaker mapping.
virtual std::string name() const noexcept=0
Get a user friendly name of the audio device.
virtual std::vector< tt::speaker_mapping > available_output_speaker_mappings() const noexcept=0
Speaker mapping that are available in the current configuration.
virtual void set_output_speaker_mapping(tt::speaker_mapping speaker_mapping) noexcept=0
Set the output speaker mapping.
audio_device_id id
The nonephemeral unique id that for an audio device on the system.
Definition audio_device.hpp:59
Definition audio_device_delegate.hpp:11
Definition audio_device_id.hpp:14
A label consisting of localizable text and an icon.
Definition label.hpp:27
T to_string(T... args)