HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
speaker_mapping.hpp
1// Copyright Take Vos 2021-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 "../utility/utility.hpp"
8#include "../codec/codec.hpp"
9#include "../font/font.hpp"
10#include "../macros.hpp"
11#include <array>
12#include <string>
13#include <iostream>
14
15hi_export_module(hikogui.audio.speaker_mapping);
16
17hi_export namespace hi { inline namespace v1 {
18
19hi_export enum class speaker_mapping : uint32_t {
20 none = 0,
21 front_left = 0x0'0001,
22 front_right = 0x0'0002,
23 front_center = 0x0'0004,
24 low_frequency = 0x0'0008,
25 back_left = 0x0'0010,
26 back_right = 0x0'0020,
27 front_left_of_center = 0x0'0040,
28 front_right_of_center = 0x0'0080,
29 back_center = 0x0'0100,
30 side_left = 0x0'0200,
31 side_right = 0x0'0400,
32 top_center = 0x0'0800,
33 top_front_left = 0x0'1000,
34 top_front_center = 0x0'2000,
35 top_front_right = 0x0'4000,
36 top_back_left = 0x0'8000,
37 top_back_center = 0x1'0000,
38 top_back_right = 0x2'0000,
39
40 // Standard
41 mono_1_0 = front_center,
42 stereo_2_0 = front_left | front_right,
43
44 // Music configuration
45 stereo_2_1 = stereo_2_0 | low_frequency,
46 stereo_3_0 = stereo_2_0 | front_center,
47 stereo_3_1 = stereo_3_0 | low_frequency,
48 quad_4_0 = stereo_2_0 | back_left | back_right,
49 quad_side_4_0 = stereo_2_0 | side_left | side_right,
50 hexagonal_6_0 = quad_4_0 | front_center | back_center,
51 hexagonal_6_1 = hexagonal_6_0 | low_frequency,
52 octagonal_8_0 = hexagonal_6_0 | side_left | side_right,
53
54 // Standard surround sound
55 surround_3_0 = stereo_2_0 | back_center,
56 surround_4_0 = surround_3_0 | front_center,
57 surround_4_1 = surround_4_0 | low_frequency,
58 surround_5_0 = quad_4_0 | front_center,
59 surround_5_1 = surround_5_0 | low_frequency,
60 surround_7_0 = surround_5_0 | side_left | side_right,
61 surround_7_1 = surround_7_0 | low_frequency,
62 surround_9_0 = surround_7_0 | top_front_left | top_front_right,
63 surround_9_1 = surround_9_0 | low_frequency,
64 surround_11_0 = surround_9_0 | front_left_of_center | front_right_of_center,
65 surround_11_1 = surround_11_0 | low_frequency,
66
67 // Surround sound with side speakers instead of left/right back speakers.
68 surround_side_5_0 = quad_side_4_0 | front_center,
69 surround_side_5_1 = surround_side_5_0 | low_frequency,
70 surround_side_6_0 = surround_side_5_0 | back_center,
71 surround_side_6_1 = surround_side_6_0 | low_frequency,
72 surround_side_7_0 = surround_side_5_0 | front_left_of_center | front_right_of_center,
73 surround_side_7_1 = surround_side_7_0 | low_frequency,
74
75 // Surround sound with extra front speakers.
76 surround_wide_6_0 = surround_4_0 | front_left_of_center | front_right_of_center,
77 surround_wide_6_1 = surround_wide_6_0 | low_frequency,
78 surround_wide_7_0 = surround_5_0 | front_left_of_center | front_right_of_center,
79 surround_wide_7_1 = surround_wide_7_0 | low_frequency,
80
81 // Surround with extra top speakers
82 surround_atmos_5_1_4 = surround_5_1 | top_front_left | top_front_right | top_back_left | top_back_right,
83 surround_atmos_7_1_4 = surround_7_1 | top_front_left | top_front_right | top_back_left | top_back_right,
84};
85
86hi_export [[nodiscard]] constexpr bool to_bool(speaker_mapping const& rhs) noexcept
87{
88 return to_bool(std::to_underlying(rhs));
89}
90
91hi_export [[nodiscard]] constexpr unsigned int popcount(speaker_mapping const &rhs) noexcept
92{
93 return std::popcount(std::to_underlying(rhs));
94}
95
96hi_export [[nodiscard]] constexpr speaker_mapping operator|(speaker_mapping const &lhs, speaker_mapping const &rhs) noexcept
97{
98 return static_cast<speaker_mapping>(std::to_underlying(lhs) | std::to_underlying(rhs));
99}
100
101hi_export [[nodiscard]] constexpr speaker_mapping operator&(speaker_mapping const& lhs, speaker_mapping const& rhs) noexcept
102{
103 return static_cast<speaker_mapping>(std::to_underlying(lhs) & std::to_underlying(rhs));
104}
105
106hi_export constexpr speaker_mapping &operator|=(speaker_mapping &lhs, speaker_mapping const &rhs) noexcept
107{
108 return lhs = lhs | rhs;
109}
110
111hi_export constexpr speaker_mapping &operator&=(speaker_mapping &lhs, speaker_mapping const &rhs) noexcept
112{
113 return lhs = lhs & rhs;
114}
115
116hi_export template<>
117struct pickle<speaker_mapping> {
118 [[nodiscard]] datum encode(speaker_mapping const &rhs) const noexcept
119 {
120 return datum{narrow_cast<long long>(std::to_underlying(rhs))};
121 }
122
123 [[nodiscard]] speaker_mapping decode(long long rhs) const
124 {
125 hi_check(rhs >= 0, "Expect speaker mapping to be encoded as a natural number, got {}.", rhs);
126 return static_cast<speaker_mapping>(rhs);
127 }
128
129 [[nodiscard]] speaker_mapping decode(datum const &rhs) const
130 {
131 if (auto *i = get_if<long long>(rhs)) {
132 return decode(*i);
133 } else {
134 throw parse_error(std::format("Expect speaker mapping to be encoded as a integer, got {}", rhs));
135 }
136 }
137};
138
139hi_export [[nodiscard]] inline std::string to_string(speaker_mapping rhs) noexcept{
140 auto r = std::string{};
141
142 if (to_bool(rhs & speaker_mapping::front_left)) {
143 r += ",fl";
144 }
145 if (to_bool(rhs & speaker_mapping::front_right)) {
146 r += ",fr";
147 }
148 if (to_bool(rhs & speaker_mapping::front_center)) {
149 r += ",fc";
150 }
151 if (to_bool(rhs & speaker_mapping::low_frequency)) {
152 r += ",lfe";
153 }
154 if (to_bool(rhs & speaker_mapping::back_left)) {
155 r += ",bl";
156 }
157 if (to_bool(rhs & speaker_mapping::back_right)) {
158 r += ",br";
159 }
160 if (to_bool(rhs & speaker_mapping::front_left_of_center)) {
161 r += ",flc";
162 }
163 if (to_bool(rhs & speaker_mapping::front_right_of_center)) {
164 r += ",frc";
165 }
166 if (to_bool(rhs & speaker_mapping::back_center)) {
167 r += ",bc";
168 }
169 if (to_bool(rhs & speaker_mapping::side_left)) {
170 r += ",sl";
171 }
172 if (to_bool(rhs & speaker_mapping::side_right)) {
173 r += ",sr";
174 }
175 if (to_bool(rhs & speaker_mapping::top_center)) {
176 r += ",tc";
177 }
178 if (to_bool(rhs & speaker_mapping::top_front_left)) {
179 r += ",tfl";
180 }
181 if (to_bool(rhs & speaker_mapping::top_front_center)) {
182 r += ",tfc";
183 }
184 if (to_bool(rhs & speaker_mapping::top_front_right)) {
185 r += ",tfr";
186 }
187 if (to_bool(rhs & speaker_mapping::top_back_left)) {
188 r += ",tbl";
189 }
190 if (to_bool(rhs & speaker_mapping::top_back_center)) {
191 r += ",tbc";
192 }
193 if (to_bool(rhs & speaker_mapping::top_back_right)) {
194 r += ",tbr";
195 }
196
197 if (r.empty()) {
198 r += '[';
199 } else {
200 // replace the first comma.
201 r[0] = '[';
202 }
203
204 r += ']';
205 return r;
206}
207
208}} // namespace hi::inline v1
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
A dynamic data type.
Definition datum.hpp:198
Encode and decode a type to and from a UTF-8 string.
Definition pickle.hpp:24
T decode(datum rhs) const
Decode a UTF-8 string into a value of a given type.
Definition pickle.hpp:48
datum encode(T const &rhs) const noexcept
Encode the value of a type into a UTF-8 string.
Definition pickle.hpp:30
Exception thrown during parsing on an error.
Definition exception_intf.hpp:48