HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
audio_format_range.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 "pcm_format.hpp"
8#include "audio_stream_format.hpp"
9#include "surround_mode.hpp"
10#include "../macros.hpp"
11#include <compare>
12
13hi_export_module(hikogui.audio.audio_format_range);
14
15hi_export namespace hi { inline namespace v1 {
16
17hi_export class audio_format_range {
18public:
19 pcm_format format = {};
20 uint16_t num_channels = 0;
21 uint32_t min_sample_rate = 0;
22 uint32_t max_sample_rate = 0;
23 surround_mode surround_mode_mask = surround_mode::none;
24
25 constexpr audio_format_range() noexcept = default;
26 constexpr audio_format_range(audio_format_range&&) noexcept = default;
27 constexpr audio_format_range(audio_format_range const&) noexcept = default;
28 constexpr audio_format_range& operator=(audio_format_range&&) noexcept = default;
29 constexpr audio_format_range& operator=(audio_format_range const&) noexcept = default;
30 [[nodiscard]] constexpr friend bool operator==(audio_format_range const&, audio_format_range const&) noexcept = default;
31
32 [[nodiscard]] constexpr friend auto operator<=>(audio_format_range const& lhs, audio_format_range const& rhs) noexcept
33 {
34 if (auto tmp = lhs.num_channels <=> rhs.num_channels; tmp != std::strong_ordering::equal) {
35 return tmp;
36 }
37 if (auto tmp = lhs.min_sample_rate <=> rhs.min_sample_rate; tmp != std::strong_ordering::equal) {
38 return tmp;
39 }
40 if (auto tmp = lhs.surround_mode_mask <=> rhs.surround_mode_mask; tmp != std::strong_ordering::equal) {
41 return tmp;
42 }
43 return lhs.format <=> rhs.format;
44 }
45
46 [[nodiscard]] constexpr friend bool
47 equal_except_bit_depth(audio_format_range const& lhs, audio_format_range const& rhs) noexcept
48 {
49 return std::tie(lhs.num_channels, lhs.min_sample_rate, lhs.max_sample_rate, lhs.surround_mode_mask) ==
50 std::tie(rhs.num_channels, rhs.min_sample_rate, rhs.max_sample_rate, rhs.surround_mode_mask) and
51 equal_except_bit_depth(lhs.format, rhs.format);
52 }
53
54 constexpr audio_format_range(
55 pcm_format format,
56 uint16_t num_channels,
57 uint32_t min_sample_rate,
58 uint32_t max_sample_rate,
59 surround_mode surround_mode_mask) noexcept :
60 format(format),
61 num_channels(num_channels),
62 min_sample_rate(min_sample_rate),
63 max_sample_rate(max_sample_rate),
64 surround_mode_mask(surround_mode_mask)
65 {
66 }
67
68 [[nodiscard]] constexpr bool empty() const noexcept
69 {
70 return format.empty();
71 }
72
73 constexpr explicit operator bool() const noexcept
74 {
75 return not empty();
76 }
77
78 [[nodiscard]] friend std::string to_string(audio_format_range const& rhs) noexcept
79 {
80 return std::format(
81 "format={}, ch={}, rate={}:{}, surround={}",
82 rhs.format,
83 rhs.num_channels,
84 rhs.min_sample_rate,
85 rhs.max_sample_rate,
86 rhs.surround_mode_mask);
87 }
88};
89
90}} // namespace hi::inline v1
91
92// XXX #617 MSVC bug does not handle partial specialization in modules.
93hi_export template<>
94struct std::formatter<hi::audio_format_range, char> : std::formatter<std::string_view, char> {
95 auto format(hi::audio_format_range const& t, auto& fc) const
96 {
97 return std::formatter<std::string_view, char>::format(to_string(t), fc);
98 }
99};
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition audio_format_range.hpp:17
Definition pcm_format.hpp:18
T tie(T... args)
T to_string(T... args)