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 "../assert.hpp"
8#include "../cast.hpp"
9#include "../pickle.hpp"
10#include "../text/hikogui_icon.hpp"
11#include <array>
12#include <string>
13#include <iostream>
14
15namespace hi::inline v1 {
16
17enum class speaker_mapping : uint32_t {
18 none = 0,
19 front_left = 0x0'0001,
20 front_right = 0x0'0002,
21 front_center = 0x0'0004,
22 low_frequency = 0x0'0008,
23 back_left = 0x0'0010,
24 back_right = 0x0'0020,
25 front_left_of_center = 0x0'0040,
26 front_right_of_center = 0x0'0080,
27 back_center = 0x0'0100,
28 side_left = 0x0'0200,
29 side_right = 0x0'0400,
30 top_center = 0x0'0800,
31 top_front_left = 0x0'1000,
32 top_front_center = 0x0'2000,
33 top_front_right = 0x0'4000,
34 top_back_left = 0x0'8000,
35 top_back_center = 0x1'0000,
36 top_back_right = 0x2'0000,
37
38 // Standard
39 mono_1_0 = front_center,
40 stereo_2_0 = front_left | front_right,
41
42 // Music configuration
43 stereo_2_1 = stereo_2_0 | low_frequency,
44 stereo_3_0 = stereo_2_0 | front_center,
45 stereo_3_1 = stereo_3_0 | low_frequency,
46 quad_4_0 = stereo_2_0 | back_left | back_right,
47 quad_side_4_0 = stereo_2_0 | side_left | side_right,
48 hexagonal_6_0 = quad_4_0 | front_center | back_center,
49 hexagonal_6_1 = hexagonal_6_0 | low_frequency,
50 octagonal_8_0 = hexagonal_6_0 | side_left | side_right,
51
52 // Standard surround sound
53 surround_3_0 = stereo_2_0 | back_center,
54 surround_4_0 = surround_3_0 | front_center,
55 surround_4_1 = surround_4_0 | low_frequency,
56 surround_5_0 = quad_4_0 | front_center,
57 surround_5_1 = surround_5_0 | low_frequency,
58 surround_7_0 = surround_5_0 | side_left | side_right,
59 surround_7_1 = surround_7_0 | low_frequency,
60 surround_9_0 = surround_7_0 | top_front_left | top_front_right,
61 surround_9_1 = surround_9_0 | low_frequency,
62 surround_11_0 = surround_9_0 | front_left_of_center | front_right_of_center,
63 surround_11_1 = surround_11_0 | low_frequency,
64
65 // Surround sound with side speakers instead of left/right back speakers.
66 surround_side_5_0 = quad_side_4_0 | front_center,
67 surround_side_5_1 = surround_side_5_0 | low_frequency,
68 surround_side_6_0 = surround_side_5_0 | back_center,
69 surround_side_6_1 = surround_side_6_0 | low_frequency,
70 surround_side_7_0 = surround_side_5_0 | front_left_of_center | front_right_of_center,
71 surround_side_7_1 = surround_side_7_0 | low_frequency,
72
73 // Surround sound with extra front speakers.
74 surround_wide_6_0 = surround_4_0 | front_left_of_center | front_right_of_center,
75 surround_wide_6_1 = surround_wide_6_0 | low_frequency,
76 surround_wide_7_0 = surround_5_0 | front_left_of_center | front_right_of_center,
77 surround_wide_7_1 = surround_wide_7_0 | low_frequency,
78
79 // Surround with extra top speakers
80 surround_atmos_5_1_4 = surround_5_1 | top_front_left | top_front_right | top_back_left | top_back_right,
81 surround_atmos_7_1_4 = surround_7_1 | top_front_left | top_front_right | top_back_left | top_back_right,
82};
83
84[[nodiscard]] constexpr bool to_bool(speaker_mapping const& rhs) noexcept
85{
86 return to_bool(to_underlying(rhs));
87}
88
89[[nodiscard]] constexpr unsigned int popcount(speaker_mapping const &rhs) noexcept
90{
91 return std::popcount(to_underlying(rhs));
92}
93
94[[nodiscard]] constexpr speaker_mapping operator|(speaker_mapping const &lhs, speaker_mapping const &rhs) noexcept
95{
96 return static_cast<speaker_mapping>(to_underlying(lhs) | to_underlying(rhs));
97}
98
99[[nodiscard]] constexpr speaker_mapping operator&(speaker_mapping const& lhs, speaker_mapping const& rhs) noexcept
100{
101 return static_cast<speaker_mapping>(to_underlying(lhs) & to_underlying(rhs));
102}
103
104constexpr speaker_mapping &operator|=(speaker_mapping &lhs, speaker_mapping const &rhs) noexcept
105{
106 return lhs = lhs | rhs;
107}
108
109constexpr speaker_mapping &operator&=(speaker_mapping &lhs, speaker_mapping const &rhs) noexcept
110{
111 return lhs = lhs & rhs;
112}
113
114template<>
115struct pickle<speaker_mapping> {
116 [[nodiscard]] datum encode(speaker_mapping const &rhs) const noexcept
117 {
118 return datum{narrow_cast<long long>(to_underlying(rhs))};
119 }
120
121 [[nodiscard]] speaker_mapping decode(long long rhs) const
122 {
123 hi_parse_check(rhs >= 0, "Expect speaker mapping to be encoded as a natural number, got {}.", rhs);
124 return static_cast<speaker_mapping>(rhs);
125 }
126
127 [[nodiscard]] speaker_mapping decode(datum const &rhs) const
128 {
129 if (auto *i = get_if<long long>(rhs)) {
130 return decode(*i);
131 } else {
132 throw parse_error(std::format("Expect speaker mapping to be encoded as a integer, got {}", rhs));
133 }
134 }
135};
136
137[[nodiscard]] std::string to_string(speaker_mapping rhs) noexcept;
138
139} // namespace hi::inline v1
Utilities to assert and bound check.
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
A dynamic data type.
Definition datum.hpp:224
Encode and decode a type to and from a UTF-8 string.
Definition pickle.hpp:23