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#include <coroutine>
22
23hi_export_module(hikogui.widgets.audio_device_widget);
24
25hi_export namespace hi { inline namespace v1 {
26
31public:
32 using super = widget;
33
37
40 observer<audio_direction> direction = audio_direction::bidirectional;
41
42 virtual ~audio_device_widget() {}
43
44 audio_device_widget(widget_intf const* parent) noexcept : super(parent)
45 {
46 _grid_widget = std::make_unique<grid_widget>(this);
47 _device_selection_widget = &_grid_widget->emplace<selection_widget>("A1", device_id, _device_list);
48
49 _sync_device_list_task = sync_device_list();
50 }
51
53 [[nodiscard]] generator<widget_intf&> children(bool include_invisible) noexcept override
54 {
55 co_yield *_grid_widget;
56 }
57
58 [[nodiscard]] box_constraints update_constraints() noexcept override
59 {
60 _layout = {};
61 _grid_constraints = _grid_widget->update_constraints();
62 return _grid_constraints;
63 }
64
65 void set_layout(widget_layout const& context) noexcept override
66 {
67 if (compare_store(_layout, context)) {
68 auto const grid_rectangle = context.rectangle();
69 _grid_shape = {_grid_constraints, grid_rectangle, theme().baseline_adjustment()};
70 }
71
72 _grid_widget->set_layout(context.transform(_grid_shape, transform_command::level));
73 }
74
75 void draw(draw_context const& context) noexcept override
76 {
77 if (mode() > widget_mode::invisible) {
78 _grid_widget->draw(context);
79 }
80 }
81
82 hitbox hitbox_test(point2 position) const noexcept override
83 {
84 if (mode() >= widget_mode::partial) {
85 auto r = hitbox{};
86 r = _grid_widget->hitbox_test_from_parent(position, r);
87 return r;
88 } else {
89 return hitbox{};
90 }
91 }
92
93 [[nodiscard]] bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override
94 {
95 if (mode() >= widget_mode::partial) {
96 return _grid_widget->accepts_keyboard_focus(group);
97 } else {
98 return false;
99 }
100 }
102private:
105 std::unique_ptr<grid_widget> _grid_widget;
106 box_constraints _grid_constraints;
107 box_shape _grid_shape;
108
111 selection_widget *_device_selection_widget = nullptr;
112
113 observer<std::vector<std::pair<std::string, label>>> _device_list;
114
115 hi::scoped_task<> _sync_device_list_task;
116
117 [[nodiscard]] hi::scoped_task<> sync_device_list() noexcept
118 {
119 while (true) {
120 {
121 auto proxy = _device_list.get();
122 proxy->clear();
123 for (auto& device : audio_devices(hi::audio_device_state::active, *direction)) {
124 proxy->emplace_back(device.id(), device.label());
125 }
126 }
127
129 }
130 }
131};
132
133}} // namespace hi::v1
Defines selection_widget.
Defines grid_widget.
@ partial
A widget is partially enabled.
@ invisible
The widget is invisible.
The HikoGUI namespace.
Definition array_generic.hpp:20
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:53
generator< audio_device & > audio_devices(Filters &&...filters) noexcept
Get audio devices matching the filter arguments.
Definition audio_system.hpp:101
@ level
The child widget stays at the same elevation and layer.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
auto when_any(Args const &...args)
await on a set of objects which can be converted to an awaitable.
Definition when_any.hpp:173
static audio_system & global() noexcept
Create an audio system object specific for the current operating system.
Definition audio_system_win32.hpp:230
Definition widget_intf.hpp:24
widget_intf * parent
Pointer to the parent widget.
Definition widget_intf.hpp:35
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
Audio device configuration widget.
Definition audio_device_widget.hpp:30
observer< audio_direction > direction
The audio direction (input or output) of devices is should show.
Definition audio_device_widget.hpp:40
observer< std::string > device_id
The audio device this widget has selected and is configuring.
Definition audio_device_widget.hpp:36
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition selection_widget.hpp:48
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:55
T get(T... args)