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