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
11#ifndef __AUDACITY_AUDIO_SETUP_TOOLBAR__
12#define __AUDACITY_AUDIO_SETUP_TOOLBAR__
13
14#include <optional>
15#include <vector>
16#include <wx/menu.h>
17#include "ToolBar.h"
18#include "Observer.h"
19#include "MemoryX.h"
20
21enum class DeviceChangeMessage : char;
22
23class wxMenu;
24class wxString;
25struct DeviceSourceMap;
26
27class AudioSetupToolBar final : public ToolBar {
28 static constexpr int kAudioSettings = 15800;
29 static constexpr int kAudioDeviceRescan = 15801;
30
31 public:
32 static Identifier ID();
33
35 virtual ~AudioSetupToolBar();
36
38 static const AudioSetupToolBar &Get( const AudacityProject &project );
39
40 void Create(wxWindow * parent) override;
41
42 void UpdatePrefs() override;
43 void UpdateSelectedPrefs( int ) override;
44
45 void DeinitChildren();
46 void Populate() override;
47 void Repaint(wxDC* dc) override;
48 void EnableDisableButtons() override;
49 void ReCreateButtons() override;
50 void OnFocus(wxFocusEvent &event);
51 void OnAudioSetup(wxCommandEvent &event);
52
53 private:
55 void OnHost(int id);
56 void OnInput(int id);
57 void OnChannels(int id);
58 void OnOutput(int id);
59 void OnAudioDeviceRescan(wxCommandEvent&);
60 void OnSettings(wxCommandEvent& event);
61 void CommonMenuItemSteps(bool audioSettingsChosen);
62
63 bool ChangeHost(int hostId);
64 class Choices;
65 void ChangeDeviceLabel(int deviceId, Choices &choices, bool isInput);
66 void RepopulateMenus();
67 void FillHosts();
68 void FillHostDevices();
69 void FillInputChannels();
70 void SetDevices(const DeviceSourceMap *in, const DeviceSourceMap *out);
71 void RegenerateTooltips() override;
72
74 void ArrangeButtons();
75
76 using Callback = void (AudioSetupToolBar::*)(int id);
77 // Append submenu with one radio item group
78 // Bind menu items to lambdas that invoke callback,
79 // with successive ids from 0
80 // Check the item with given index, or disable the submenu when that is < 0
81 static void AppendSubMenu(AudioSetupToolBar &toolbar, wxMenu& menu,
82 const wxArrayString &labels, int checkedItem,
83 Callback callback, const wxString& title);
84
85 enum {
88 };
89
91 wxBoxSizer *mSizer{};
92
93 class Choices {
94 public:
95 void Clear() { mStrings.Clear(); mIndex = -1; }
96 [[nodiscard]] bool Empty() const { return mStrings.empty(); }
97 std::optional<wxString> Get() const {
98 if (mIndex < 0 || mIndex >= mStrings.size())
99 return {};
100 return { mStrings[mIndex] };
101 }
102 wxString GetFirst() const {
103 if (!Empty())
104 return mStrings[0];
105 return {};
106 }
107 int GetSmallIntegerId() const {
108 return mIndex;
109 }
110 int Find(const wxString &name) const {
111 return make_iterator_range(mStrings).index(name);
112 }
113 bool Set(const wxString &name) {
114 auto index = make_iterator_range(mStrings).index(name);
115 if (index != -1) {
116 mIndex = index;
117 return true;
118 }
119 // else no state change
120 return false;
121 }
122 void Set(wxArrayString &&names) {
123 mStrings.swap(names);
124 mIndex = mStrings.empty() ? -1 : 0;
125 }
126 // id is just a small-integer index into the string array
127 bool Set(int id) {
128 if (id < 0 || id >= mStrings.size())
129 return false; // no change of state then
130 mIndex = id;
131 return true;
132 }
133 void AppendSubMenu(AudioSetupToolBar &toolBar,
134 wxMenu &menu, Callback callback, const wxString &title);
135
136 private:
138 int mIndex{ -1 };
139 };
140
145
147
148 public:
149
150 DECLARE_CLASS(AudioSetupToolBar)
151 DECLARE_EVENT_TABLE()
152};
153
154#endif
155
DeviceChangeMessage
Definition: DeviceChange.h:16
const TranslatableString name
Definition: Distortion.cpp:76
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:448
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.