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