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