HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
audio_device_widget.hpp
Go to the documentation of this file.
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
9#pragma once
10
11#include "selection_widget.hpp"
12#include "grid_widget.hpp"
13#include "../audio/audio.hpp"
14#include "../l10n/l10n.hpp"
15#include "../macros.hpp"
16#include <memory>
17#include <string>
18#include <array>
19#include <optional>
20#include <future>
21
22namespace hi { inline namespace v1 {
23
28public:
29 using super = widget;
30
33 observer<std::string> device_id;
34
37 observer<audio_direction> direction = audio_direction::bidirectional;
38
39 virtual ~audio_device_widget() {}
40
42 {
43 _grid_widget = std::make_unique<grid_widget>(this);
44 _device_selection_widget = &_grid_widget->make_widget<selection_widget>("A1", device_id, _device_list);
45
46 _sync_device_list_task = sync_device_list();
47 }
48
50 [[nodiscard]] generator<widget_intf&> children(bool include_invisible) noexcept override
51 {
52 co_yield *_grid_widget;
53 }
54
55 [[nodiscard]] box_constraints update_constraints() noexcept override
56 {
57 _layout = {};
58 _grid_constraints = _grid_widget->update_constraints();
59 return _grid_constraints;
60 }
61
62 void set_layout(widget_layout const& context) noexcept override
63 {
64 if (compare_store(_layout, context)) {
65 hilet grid_rectangle = context.rectangle();
66 _grid_shape = {_grid_constraints, grid_rectangle, theme().baseline_adjustment()};
67 }
68
69 _grid_widget->set_layout(context.transform(_grid_shape));
70 }
71
72 void draw(draw_context const& context) noexcept override
73 {
75 _grid_widget->draw(context);
76 }
77 }
78
79 hitbox hitbox_test(point2 position) const noexcept override
80 {
81 if (*mode >= widget_mode::partial) {
82 auto r = hitbox{};
83 r = _grid_widget->hitbox_test_from_parent(position, r);
84 return r;
85 } else {
86 return hitbox{};
87 }
88 }
89
90 [[nodiscard]] bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override
91 {
92 if (*mode >= widget_mode::partial) {
93 return _grid_widget->accepts_keyboard_focus(group);
94 } else {
95 return false;
96 }
97 }
99private:
102 std::unique_ptr<grid_widget> _grid_widget;
103 box_constraints _grid_constraints;
104 box_shape _grid_shape;
105
108 selection_widget *_device_selection_widget = nullptr;
109
111
112 hi::scoped_task<> _sync_device_list_task;
113
114 [[nodiscard]] hi::scoped_task<> sync_device_list() noexcept
115 {
116 while (true) {
117 {
118 auto proxy = _device_list.copy();
119 proxy->clear();
120 for (auto& device : audio_devices(hi::audio_device_state::active, *direction)) {
121 proxy->emplace_back(device.id(), device.label());
122 }
123 }
124
125 co_await when_any(audio_system::global(), direction);
126 }
127 }
128};
129
130}} // namespace hi::v1
Defines selection_widget.
Defines grid_widget.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:56
generator< audio_device & > audio_devices(Filters &&...filters) noexcept
Get audio devices matching the filter arguments.
Definition audio_system.hpp:102
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
static audio_system & global() noexcept
Create an audio system object specific for the current operating system.
Definition audio_system_win32.hpp:229
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:28
Audio device configuration widget.
Definition audio_device_widget.hpp:27
observer< audio_direction > direction
The audio direction (input or output) of devices is should show.
Definition audio_device_widget.hpp:37
observer< std::string > device_id
The audio device this widget has selected and is configuring.
Definition audio_device_widget.hpp:33
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition selection_widget.hpp:45
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget(widget *parent) noexcept
Definition widget.hpp:87
observer< widget_mode > mode
The widget mode.
Definition widget.hpp:42