Audacity 3.2.0
AudioSetupToolBar.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 AudioSetupToolBar.h
6
7 K. Soze
8
9 **********************************************************************/
10#ifndef __AUDACITY_AUDIO_SETUP_TOOLBAR__
11#define __AUDACITY_AUDIO_SETUP_TOOLBAR__
12
13#include <optional>
14#include <vector>
15#include <wx/menu.h>
16#include "IteratorX.h"
17#include "ToolBar.h"
18#include "Observer.h"
19
20enum class DeviceChangeMessage : char;
21
22class wxMenu;
23class wxString;
24struct DeviceSourceMap;
25
26class AudioSetupToolBar final : public ToolBar {
27 static constexpr int kAudioSettings = 15800;
28 static constexpr int kAudioDeviceRescan = 15801;
29
30 public:
31 static Identifier ID();
32
34 virtual ~AudioSetupToolBar();
35
37 static const AudioSetupToolBar &Get( const AudacityProject &project );
38
39 void Create(wxWindow * parent) override;
40
41 void UpdatePrefs() override;
42 void UpdateSelectedPrefs( int ) override;
43
44 void DeinitChildren();
45 void Populate() override;
46 void Repaint(wxDC* dc) override;
47 void EnableDisableButtons() override;
48 void ReCreateButtons() override;
49 void OnFocus(wxFocusEvent &event);
50 void OnAudioSetup(wxCommandEvent &event);
51
52 private:
54 void OnHost(int id);
55 void OnInput(int id);
56 void OnChannels(int id);
57 void OnOutput(int id);
58 void OnAudioDeviceRescan(wxCommandEvent&);
59 void OnSettings(wxCommandEvent& event);
60 void CommonMenuItemSteps(bool audioSettingsChosen);
61
62 bool ChangeHost(int hostId);
63 class Choices;
64 void ChangeDeviceLabel(int deviceId, Choices &choices, bool isInput);
65 void RepopulateMenus();
66 void FillHosts();
67 void FillHostDevices();
68 void FillInputChannels();
69 void SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out);
70 void RegenerateTooltips() override;
71
73 void ArrangeButtons();
74
75 using Callback = void (AudioSetupToolBar::*)(int id);
76 // Append submenu with one radio item group
77 // Bind menu items to lambdas that invoke callback,
78 // with successive ids from 0
79 // Check the item with given index, or disable the submenu when that is < 0
80 static void AppendSubMenu(AudioSetupToolBar &toolbar, wxMenu& menu,
81 const wxArrayString &labels, int checkedItem,
82 Callback callback, const wxString& title);
83
84 enum {
87 };
88
90 wxBoxSizer *mSizer{};
91
92 class Choices {
93 public:
94 void Clear() { mStrings.Clear(); mIndex = -1; }
95 [[nodiscard]] bool Empty() const { return mStrings.empty(); }
96 std::optional<wxString> Get() const {
97 if (mIndex < 0 || mIndex >= mStrings.size())
98 return {};
99 return { mStrings[mIndex] };
100 }
101 wxString GetFirst() const {
102 if (!Empty())
103 return mStrings[0];
104 return {};
105 }
106 int GetSmallIntegerId() const {
107 return mIndex;
108 }
109 int Find(const wxString &name) const {
110 return make_iterator_range(mStrings).index(name);
111 }
112 bool Set(const wxString &name) {
113 auto index = make_iterator_range(mStrings).index(name);
114 if (index != -1) {
115 mIndex = index;
116 return true;
117 }
118 // else no state change
119 return false;
120 }
121 void Set(wxArrayString &&names) {
122 mStrings.swap(names);
123 mIndex = mStrings.empty() ? -1 : 0;
124 }
125 // id is just a small-integer index into the string array
126 bool Set(int id) {
127 if (id < 0 || id >= mStrings.size())
128 return false; // no change of state then
129 mIndex = id;
130 return true;
131 }
132 void AppendSubMenu(AudioSetupToolBar &toolBar,
133 wxMenu &menu, Callback callback, const wxString &title);
134
135 private:
137 int mIndex{ -1 };
138 };
139
144
146
147 public:
148
149 DECLARE_CLASS(AudioSetupToolBar)
150 DECLARE_EVENT_TABLE()
151};
152
153#endif
154
DeviceChangeMessage
Definition: DeviceChange.h:16
const TranslatableString name
Definition: Distortion.cpp:76
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: IteratorX.h:210
static const auto title
static TranslatableStrings names
Definition: TagsEditor.cpp:153
const auto project
int id
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
void Set(wxArrayString &&names)
bool Set(const wxString &name)
std::optional< wxString > Get() const
void AppendSubMenu(AudioSetupToolBar &toolBar, wxMenu &menu, Callback callback, const wxString &title)
int Find(const wxString &name) const
A toolbar to allow easier changing of input and output devices .
void(AudioSetupToolBar::*)(int id) Callback
void SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out)
void UpdateSelectedPrefs(int) override
void CommonMenuItemSteps(bool audioSettingsChosen)
void RegenerateTooltips() override
void Populate() override
void OnAudioSetup(wxCommandEvent &event)
void OnAudioDeviceRescan(wxCommandEvent &)
static constexpr int kAudioDeviceRescan
static AudioSetupToolBar & Get(AudacityProject &project)
static void AppendSubMenu(AudioSetupToolBar &toolbar, wxMenu &menu, const wxArrayString &labels, int checkedItem, Callback callback, const wxString &title)
void EnableDisableButtons() override
void Repaint(wxDC *dc) override
static constexpr int kAudioSettings
void OnRescannedDevices(DeviceChangeMessage)
void OnSettings(wxCommandEvent &event)
void Create(wxWindow *parent) override
void ChangeDeviceLabel(int deviceId, Choices &choices, bool isInput)
Observer::Subscription mSubscription
void ReCreateButtons() override
static Identifier ID()
Methods for AudioSetupToolBar.
bool ChangeHost(int hostId)
void OnFocus(wxFocusEvent &event)
AudioSetupToolBar(AudacityProject &project)
void UpdatePrefs() override
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:74
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.