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
91 class Choices {
92 public:
93 void Clear() { mStrings.Clear(); mIndex = -1; }
94 [[nodiscard]] bool Empty() const { return mStrings.empty(); }
95 std::optional<wxString> Get() const {
96 if (mIndex < 0 || mIndex >= mStrings.size())
97 return {};
98 return { mStrings[mIndex] };
99 }
100 wxString GetFirst() const {
101 if (!Empty())
102 return mStrings[0];
103 return {};
104 }
105 int GetSmallIntegerId() const {
106 return mIndex;
107 }
108 int Find(const wxString &name) const {
109 return make_iterator_range(mStrings).index(name);
110 }
111 bool Set(const wxString &name) {
112 auto index = make_iterator_range(mStrings).index(name);
113 if (index != -1) {
114 mIndex = index;
115 return true;
116 }
117 // else no state change
118 return false;
119 }
120 void Set(wxArrayString &&names) {
121 mStrings.swap(names);
122 mIndex = mStrings.empty() ? -1 : 0;
123 }
124 // id is just a small-integer index into the string array
125 bool Set(int id) {
126 if (id < 0 || id >= mStrings.size())
127 return false; // no change of state then
128 mIndex = id;
129 return true;
130 }
131 void AppendSubMenu(AudioSetupToolBar &toolBar,
132 wxMenu &menu, Callback callback, const wxString &title);
133
134 private:
136 int mIndex{ -1 };
137 };
138
143
145
146 public:
147
148 DECLARE_CLASS(AudioSetupToolBar)
149 DECLARE_EVENT_TABLE()
150};
151
152#endif
153
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:73
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.