HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
surround_mode.hpp
1// Copyright Take Vos 2022.
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 "speaker_mapping.hpp"
8#include "../text/hikogui_icon.hpp"
9#include "../enum_metadata.hpp"
10#include "../cast.hpp"
11#include "../label.hpp"
12#include "../generator.hpp"
13#include <cstdint>
14
15namespace hi::inline v1 {
16
17enum class surround_mode : uint64_t {
18 none = 0,
19 mono_1_0 = uint64_t{1} << 0,
20 stereo_2_0 = uint64_t{1} << 1,
21
22 // Music configuration
23 stereo_2_1 = uint64_t{1} << 2,
24 stereo_3_0 = uint64_t{1} << 3,
25 stereo_3_1 = uint64_t{1} << 4,
26 quad_4_0 = uint64_t{1} << 5,
27 quad_side_4_0 = uint64_t{1} << 6,
28 hexagonal_6_0 = uint64_t{1} << 7,
29 hexagonal_6_1 = uint64_t{1} << 8,
30 octagonal_8_0 = uint64_t{1} << 9,
31
32 // Standard surround sound
33 surround_3_0 = uint64_t{1} << 10,
34 surround_4_0 = uint64_t{1} << 11,
35 surround_4_1 = uint64_t{1} << 12,
36 surround_5_0 = uint64_t{1} << 13,
37 surround_5_1 = uint64_t{1} << 14,
38 surround_7_0 = uint64_t{1} << 15,
39 surround_7_1 = uint64_t{1} << 16,
40 surround_9_0 = uint64_t{1} << 17,
41 surround_9_1 = uint64_t{1} << 18,
42 surround_11_0 = uint64_t{1} << 19,
43 surround_11_1 = uint64_t{1} << 20,
44
45 // Surround sound with side speakers instead of left/right back speakers.
46 surround_side_5_0 = uint64_t{1} << 21,
47 surround_side_5_1 = uint64_t{1} << 22,
48 surround_side_6_0 = uint64_t{1} << 23,
49 surround_side_6_1 = uint64_t{1} << 24,
50 surround_side_7_0 = uint64_t{1} << 25,
51 surround_side_7_1 = uint64_t{1} << 26,
52
53 // Surround sound with extra front speakers.
54 surround_wide_6_0 = uint64_t{1} << 27,
55 surround_wide_6_1 = uint64_t{1} << 28,
56 surround_wide_7_0 = uint64_t{1} << 29,
57 surround_wide_7_1 = uint64_t{1} << 30,
58
59 // Surround with extra top speakers
60 surround_atmos_5_1_4 = uint64_t{1} << 31,
61 surround_atmos_7_1_4 = uint64_t{1} << 32,
62};
63
64// clang-format off
65constexpr auto surround_mode_icons = enum_metadata{
66 surround_mode::none, hikogui_icon::none_0_0,
67 surround_mode::mono_1_0, hikogui_icon::mono_1_0,
68 surround_mode::stereo_2_0, hikogui_icon::stereo_2_0,
69 surround_mode::stereo_2_1, hikogui_icon::stereo_2_1,
70 surround_mode::stereo_3_0, hikogui_icon::stereo_3_0,
71 surround_mode::stereo_3_1, hikogui_icon::stereo_3_1,
72 surround_mode::quad_4_0, hikogui_icon::quad_4_0,
73 surround_mode::quad_side_4_0, hikogui_icon::quad_side_4_0,
74 surround_mode::hexagonal_6_0, hikogui_icon::hexagonal_6_0,
75 surround_mode::hexagonal_6_1, hikogui_icon::hexagonal_6_1,
76 surround_mode::octagonal_8_0, hikogui_icon::octagonal_8_0,
77 surround_mode::surround_3_0, hikogui_icon::surround_3_0,
78 surround_mode::surround_4_0, hikogui_icon::surround_4_0,
79 surround_mode::surround_4_1, hikogui_icon::surround_4_1,
80 surround_mode::surround_5_0, hikogui_icon::surround_5_0,
81 surround_mode::surround_5_1, hikogui_icon::surround_5_1,
82 surround_mode::surround_7_0, hikogui_icon::surround_7_0,
83 surround_mode::surround_7_1, hikogui_icon::surround_7_1,
84 surround_mode::surround_9_0, hikogui_icon::surround_9_0,
85 surround_mode::surround_9_1, hikogui_icon::surround_9_1,
86 surround_mode::surround_11_0, hikogui_icon::surround_11_0,
87 surround_mode::surround_11_1, hikogui_icon::surround_11_1,
88 surround_mode::surround_side_5_0, hikogui_icon::surround_side_5_0,
89 surround_mode::surround_side_5_1, hikogui_icon::surround_side_5_1,
90 surround_mode::surround_side_6_0, hikogui_icon::surround_side_6_0,
91 surround_mode::surround_side_6_1, hikogui_icon::surround_side_6_1,
92 surround_mode::surround_side_7_0, hikogui_icon::surround_side_7_0,
93 surround_mode::surround_side_7_1, hikogui_icon::surround_side_7_1,
94 surround_mode::surround_wide_6_0, hikogui_icon::surround_wide_6_0,
95 surround_mode::surround_wide_6_1, hikogui_icon::surround_wide_6_1,
96 surround_mode::surround_wide_7_0, hikogui_icon::surround_wide_7_0,
97 surround_mode::surround_wide_7_1, hikogui_icon::surround_wide_7_1,
98 surround_mode::surround_atmos_5_1_4, hikogui_icon::surround_atmos_5_1_4,
99 surround_mode::surround_atmos_7_1_4, hikogui_icon::surround_atmos_7_1_4,
100};
101
102constexpr auto surround_mode_names = enum_metadata{
103 surround_mode::none, "none",
104 surround_mode::mono_1_0, "mono",
105 surround_mode::stereo_2_0, "stereo",
106 surround_mode::stereo_2_1, "stereo 2.1",
107 surround_mode::stereo_3_0, "stereo 3.0",
108 surround_mode::stereo_3_1, "stereo 3.1",
109 surround_mode::quad_4_0, "quad",
110 surround_mode::quad_side_4_0, "quad-side",
111 surround_mode::hexagonal_6_0, "hexagonal",
112 surround_mode::hexagonal_6_1, "hexagonal 6.1",
113 surround_mode::octagonal_8_0, "octagonal",
114 surround_mode::surround_3_0, "surround 3.0",
115 surround_mode::surround_4_0, "surround 4.0",
116 surround_mode::surround_4_1, "surround 4.1",
117 surround_mode::surround_5_0, "surround 5.0",
118 surround_mode::surround_5_1, "surround 5.1",
119 surround_mode::surround_7_0, "surround 7.0",
120 surround_mode::surround_7_1, "surround 7.1",
121 surround_mode::surround_9_0, "surround 9.0",
122 surround_mode::surround_9_1, "surround 9.1",
123 surround_mode::surround_11_0, "surround 11.0",
124 surround_mode::surround_11_1, "surround 11.1",
125 surround_mode::surround_side_5_0, "surround-side 5.0",
126 surround_mode::surround_side_5_1, "surround-side 5.1",
127 surround_mode::surround_side_6_0, "surround-side 6.0",
128 surround_mode::surround_side_6_1, "surround-side 6.1",
129 surround_mode::surround_side_7_0, "surround-side 7.0",
130 surround_mode::surround_side_7_1, "surround-side 7.1",
131 surround_mode::surround_wide_6_0, "surround-wide 6.0",
132 surround_mode::surround_wide_6_1, "surround-wide 6.1",
133 surround_mode::surround_wide_7_0, "surround-wide 7.0",
134 surround_mode::surround_wide_7_1, "surround-wide 7.1",
135 surround_mode::surround_atmos_5_1_4, "surround-atmos 5.1.4",
136 surround_mode::surround_atmos_7_1_4, "surround-atmos 7.1.4",
137};
138
139constexpr auto surround_mode_short_names = enum_metadata{
140 surround_mode::none, "0.0",
141 surround_mode::mono_1_0, "1.0",
142 surround_mode::stereo_2_0, "2.0",
143 surround_mode::stereo_2_1, "2.1",
144 surround_mode::stereo_3_0, "3.0m",
145 surround_mode::stereo_3_1, "3.1m",
146 surround_mode::quad_4_0, "4.0m",
147 surround_mode::quad_side_4_0, "4.0s",
148 surround_mode::hexagonal_6_0, "6.0m",
149 surround_mode::hexagonal_6_1, "6.1m",
150 surround_mode::octagonal_8_0, "8.0m",
151 surround_mode::surround_3_0, "3.0",
152 surround_mode::surround_4_0, "4.0",
153 surround_mode::surround_4_1, "4.1",
154 surround_mode::surround_5_0, "5.0",
155 surround_mode::surround_5_1, "5.1",
156 surround_mode::surround_7_0, "7.0",
157 surround_mode::surround_7_1, "7.1",
158 surround_mode::surround_9_0, "9.0",
159 surround_mode::surround_9_1, "9.1",
160 surround_mode::surround_11_0, "11.0",
161 surround_mode::surround_11_1, "11.1",
162 surround_mode::surround_side_5_0, "5.0s",
163 surround_mode::surround_side_5_1, "5.1s",
164 surround_mode::surround_side_6_0, "6.0s",
165 surround_mode::surround_side_6_1, "6.1s",
166 surround_mode::surround_side_7_0, "7.0s",
167 surround_mode::surround_side_7_1, "7.1s",
168 surround_mode::surround_wide_6_0, "6.0w",
169 surround_mode::surround_wide_6_1, "6.1w",
170 surround_mode::surround_wide_7_0, "7.0w",
171 surround_mode::surround_wide_7_1, "7.1w",
172 surround_mode::surround_atmos_5_1_4, "5.1.4",
173 surround_mode::surround_atmos_7_1_4, "7.1.4",
174};
175
176constexpr auto surround_mode_speaker_mappings = enum_metadata{
177 surround_mode::mono_1_0, speaker_mapping::mono_1_0,
178 surround_mode::stereo_2_0, speaker_mapping::stereo_2_0,
179 surround_mode::stereo_2_1, speaker_mapping::stereo_2_1,
180 surround_mode::stereo_3_0, speaker_mapping::stereo_3_0,
181 surround_mode::stereo_3_1, speaker_mapping::stereo_3_1,
182 surround_mode::quad_4_0, speaker_mapping::quad_4_0,
183 surround_mode::quad_side_4_0, speaker_mapping::quad_side_4_0,
184 surround_mode::hexagonal_6_0, speaker_mapping::hexagonal_6_0,
185 surround_mode::hexagonal_6_1, speaker_mapping::hexagonal_6_1,
186 surround_mode::octagonal_8_0, speaker_mapping::octagonal_8_0,
187 surround_mode::surround_3_0, speaker_mapping::surround_3_0,
188 surround_mode::surround_4_0, speaker_mapping::surround_4_0,
189 surround_mode::surround_4_1, speaker_mapping::surround_4_1,
190 surround_mode::surround_5_0, speaker_mapping::surround_5_0,
191 surround_mode::surround_5_1, speaker_mapping::surround_5_1,
192 surround_mode::surround_7_0, speaker_mapping::surround_7_0,
193 surround_mode::surround_7_1, speaker_mapping::surround_7_1,
194 surround_mode::surround_9_0, speaker_mapping::surround_9_0,
195 surround_mode::surround_9_1, speaker_mapping::surround_9_1,
196 surround_mode::surround_11_0, speaker_mapping::surround_11_0,
197 surround_mode::surround_11_1, speaker_mapping::surround_11_1,
198 surround_mode::surround_side_5_0, speaker_mapping::surround_side_5_0,
199 surround_mode::surround_side_5_1, speaker_mapping::surround_side_5_1,
200 surround_mode::surround_side_6_0, speaker_mapping::surround_side_6_0,
201 surround_mode::surround_side_6_1, speaker_mapping::surround_side_6_1,
202 surround_mode::surround_side_7_0, speaker_mapping::surround_side_7_0,
203 surround_mode::surround_side_7_1, speaker_mapping::surround_side_7_1,
204 surround_mode::surround_wide_6_0, speaker_mapping::surround_wide_6_0,
205 surround_mode::surround_wide_6_1, speaker_mapping::surround_wide_6_1,
206 surround_mode::surround_wide_7_0, speaker_mapping::surround_wide_7_0,
207 surround_mode::surround_wide_7_1, speaker_mapping::surround_wide_7_1,
208 surround_mode::surround_atmos_5_1_4, speaker_mapping::surround_atmos_5_1_4,
209 surround_mode::surround_atmos_7_1_4, speaker_mapping::surround_atmos_7_1_4
210};
211
212// clang-format on
213
214[[nodiscard]] constexpr surround_mode operator&(surround_mode const& lhs, surround_mode const& rhs) noexcept
215{
216 return static_cast<surround_mode>(to_underlying(lhs) & to_underlying(rhs));
217}
218
219[[nodiscard]] constexpr surround_mode operator|(surround_mode const& lhs, surround_mode const& rhs) noexcept
220{
221 return static_cast<surround_mode>(to_underlying(lhs) | to_underlying(rhs));
222}
223
224constexpr surround_mode& operator|=(surround_mode& lhs, surround_mode const& rhs) noexcept
225{
226 return lhs = lhs | rhs;
227}
228
229[[nodiscard]] constexpr bool to_bool(surround_mode const& rhs) noexcept
230{
231 return to_bool(to_underlying(rhs));
232}
233
234[[nodiscard]] constexpr speaker_mapping to_speaker_mapping(surround_mode const& rhs) noexcept
235{
236 return surround_mode_speaker_mappings[rhs];
237}
238
239[[nodiscard]] inline generator<surround_mode> enumerate_surround_modes() noexcept
240{
241 hilet begin = to_underlying(surround_mode::mono_1_0);
242 hilet end = to_underlying(surround_mode::surround_atmos_7_1_4) << 1;
243
244 for (uint64_t i = begin; i != end; i <<= 1) {
245 hilet mode = static_cast<surround_mode>(i);
246 co_yield mode;
247 }
248}
249
250[[nodiscard]] constexpr std::string_view to_string_view_one(surround_mode const& mode) noexcept
251{
252 return surround_mode_short_names[mode];
253}
254
255[[nodiscard]] constexpr std::string to_string(surround_mode const& mask) noexcept
256{
257 switch (std::popcount(to_underlying(mask))) {
258 case 0:
259 return std::string{"-"};
260 case 1:
261 return std::string{to_string_view_one(mask)};
262 default:
263 {
264 hilet begin = to_underlying(surround_mode::mono_1_0);
265 hilet end = to_underlying(surround_mode::surround_atmos_7_1_4) << 1;
266
267 auto r = std::string{};
268 for (uint64_t i = begin; i != end; i <<= 1) {
269 hilet mode = static_cast<surround_mode>(i);
270 if (to_bool(mode & mask)) {
271 if (not r.empty()) {
272 r += ',';
273 }
274 r += to_string_view_one(mode);
275 }
276 }
277 return r;
278 }
279 }
280}
281
282} // namespace hi::inline v1
283
284template<typename CharT>
285struct std::formatter<hi::surround_mode, CharT> : std::formatter<std::string_view, CharT> {
286 auto format(hi::surround_mode const& t, auto& fc)
287 {
288 return std::formatter<std::string_view, CharT>::format(hi::to_string(t), fc);
289 }
290};
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
Functionality for labels, text and icons.
constexpr std::string to_string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:215
DOXYGEN BUG.
Definition algorithm.hpp:15
constexpr alignment operator|(horizontal_alignment lhs, vertical_alignment rhs) noexcept
Combine vertical and horizontal alignment.
Definition alignment.hpp:216
The HikoGUI namespace.
Definition ascii.hpp:19
T begin(T... args)
T end(T... args)
T to_string(T... args)