Audacity  3.0.3
ExtraMenus.cpp
Go to the documentation of this file.
1 #include "../CommonCommandFlags.h"
2 #include "../Menus.h"
3 #include "Prefs.h"
4 #include "Project.h"
5 #include "ProjectWindows.h"
6 #include "../commands/CommandContext.h"
7 #include "../commands/CommandManager.h"
8 #include "../toolbars/MixerToolBar.h"
9 #include "../toolbars/DeviceToolBar.h"
10 
11 #include <wx/frame.h>
12 
13 // helper functions and classes
14 namespace {
15 }
16 
18 namespace ExtraActions {
19 
20 // exported helper functions
21 // none
22 
23 // Menu handler functions
24 
26 
27 void OnOutputGain(const CommandContext &context)
28 {
29  auto &project = context.project;
30  auto tb = &MixerToolBar::Get( project );
31 
32  if (tb) {
33  tb->ShowOutputGainDialog();
34  }
35 }
36 
37 void OnOutputGainInc(const CommandContext &context)
38 {
39  auto &project = context.project;
40  auto tb = &MixerToolBar::Get( project );
41 
42  if (tb) {
43  tb->AdjustOutputGain(1);
44  }
45 }
46 
47 void OnOutputGainDec(const CommandContext &context)
48 {
49  auto &project = context.project;
50  auto tb = &MixerToolBar::Get( project );
51 
52  if (tb) {
53  tb->AdjustOutputGain(-1);
54  }
55 }
56 
57 void OnInputGain(const CommandContext &context)
58 {
59  auto &project = context.project;
60  auto tb = &MixerToolBar::Get( project );
61 
62  if (tb) {
63  tb->ShowInputGainDialog();
64  }
65 }
66 
67 void OnInputGainInc(const CommandContext &context)
68 {
69  auto &project = context.project;
70  auto tb = &MixerToolBar::Get( project );
71 
72  if (tb) {
73  tb->AdjustInputGain(1);
74  }
75 }
76 
77 void OnInputGainDec(const CommandContext &context)
78 {
79  auto &project = context.project;
80  auto tb = &MixerToolBar::Get( project );
81 
82  if (tb) {
83  tb->AdjustInputGain(-1);
84  }
85 }
86 
87 void OnInputDevice(const CommandContext &context)
88 {
89  auto &project = context.project;
90  auto &tb = DeviceToolBar::Get( project );
91  tb.ShowInputDialog();
92 }
93 
94 void OnOutputDevice(const CommandContext &context)
95 {
96  auto &project = context.project;
97  auto &tb = DeviceToolBar::Get( project );
98  tb.ShowOutputDialog();
99 }
100 
101 void OnInputChannels(const CommandContext &context)
102 {
103  auto &project = context.project;
104  auto &tb = DeviceToolBar::Get( project );
105  tb.ShowChannelsDialog();
106 }
107 
108 void OnAudioHost(const CommandContext &context)
109 {
110  auto &project = context.project;
111  auto &tb = DeviceToolBar::Get( project );
112  tb.ShowHostDialog();
113 }
114 
115 void OnFullScreen(const CommandContext &context)
116 {
117  auto &project = context.project;
118  auto &window = GetProjectFrame( project );
119 
120  bool bChecked = !window.wxTopLevelWindow::IsFullScreen();
121  window.wxTopLevelWindow::ShowFullScreen(bChecked);
122 
123  MenuManager::Get(project).ModifyToolbarMenus(project);
124 }
125 
126 }; // struct Handler
127 
128 } // namespace
129 
131  // Handler is not stateful. Doesn't need a factory registered with
132  // AudacityProject.
133  static ExtraActions::Handler instance;
134  return instance;
135 };
136 
137 // Menu definitions
138 
139 #define FN(X) (& ExtraActions::Handler :: X)
140 
141 namespace {
142 using namespace MenuTable;
143 
146 
148 {
149  // Table of menu factories.
150  // TODO: devise a registration system instead.
151  static BaseItemSharedPtr extraItems{ Items( wxEmptyString,
152  Section( "Part1",
154  , ExtraDeviceMenu()
155  ),
156 
157  Section( "Part2" )
158  ) };
159 
160  static const auto pred =
161  []{ return gPrefs->ReadBool(wxT("/GUI/ShowExtraMenus"), false); };
162  static BaseItemSharedPtr menu{
163  ConditionalItems( wxT("Optional"),
164  pred, Menu( wxT("Extra"), XXO("Ext&ra"), extraItems ) )
165  };
166  return menu;
167 }
168 
170  wxT(""),
171  Shared( ExtraMenu() )
172 };
173 
174 // Under /MenuBar/Optional/Extra/Part1
176 {
177  static BaseItemSharedPtr menu{
179  Menu( wxT("Mixer"), XXO("Mi&xer"),
180  Command( wxT("OutputGain"), XXO("Ad&just Playback Volume..."),
181  FN(OnOutputGain), AlwaysEnabledFlag ),
182  Command( wxT("OutputGainInc"), XXO("&Increase Playback Volume"),
183  FN(OnOutputGainInc), AlwaysEnabledFlag ),
184  Command( wxT("OutputGainDec"), XXO("&Decrease Playback Volume"),
185  FN(OnOutputGainDec), AlwaysEnabledFlag ),
186  Command( wxT("InputGain"), XXO("Adj&ust Recording Volume..."),
187  FN(OnInputGain), AlwaysEnabledFlag ),
188  Command( wxT("InputGainInc"), XXO("I&ncrease Recording Volume"),
189  FN(OnInputGainInc), AlwaysEnabledFlag ),
190  Command( wxT("InputGainDec"), XXO("D&ecrease Recording Volume"),
191  FN(OnInputGainDec), AlwaysEnabledFlag )
192  ) ) };
193  return menu;
194 }
195 
196 // Under /MenuBar/Optional/Extra/Part1
198 {
199  static BaseItemSharedPtr menu{
201  Menu( wxT("Device"), XXO("De&vice"),
202  Command( wxT("InputDevice"), XXO("Change &Recording Device..."),
203  FN(OnInputDevice),
204  AudioIONotBusyFlag(), wxT("Shift+I") ),
205  Command( wxT("OutputDevice"), XXO("Change &Playback Device..."),
206  FN(OnOutputDevice),
207  AudioIONotBusyFlag(), wxT("Shift+O") ),
208  Command( wxT("AudioHost"), XXO("Change Audio &Host..."), FN(OnAudioHost),
209  AudioIONotBusyFlag(), wxT("Shift+H") ),
210  Command( wxT("InputChannels"), XXO("Change Recording Cha&nnels..."),
211  FN(OnInputChannels),
212  AudioIONotBusyFlag(), wxT("Shift+N") )
213  ) ) };
214  return menu;
215 }
216 
217 // Under /MenuBar/Optional/Extra/Part2
219 {
221 
222  // Not a menu.
223  static BaseItemSharedPtr items{
224  Items( wxT("Misc"),
225  // Delayed evaluation
226  []( AudacityProject &project ) {
227 
228  static const auto key =
229 #ifdef __WXMAC__
230  wxT("Ctrl+/")
231 #else
232  wxT("F11")
233 #endif
234  ;
235 
236  return (
238  // Accel key is not bindable.
239  Command( wxT("FullScreenOnOff"), XXO("&Full Screen (on/off)"),
240  FN(OnFullScreen),
242  Options{ key }.CheckTest( []( const AudacityProject &project ) {
243  return GetProjectFrame( project )
244  .wxTopLevelWindow::IsFullScreen(); } ) )
245  );
246  }
247  ) };
248  return items;
249 }
250 
252  Placement{ wxT("Optional/Extra/Part2"), { OrderingHint::End } },
254 };
255 
256 }
257 
258 #undef FN
Registry::OrderingHint::End
@ End
Definition: Registry.h:30
MenuTable::FinderScope
Definition: CommandManager.h:485
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
DeviceToolBar::Get
static DeviceToolBar & Get(AudacityProject &project)
Definition: DeviceToolBar.cpp:86
Project.h
AudioIONotBusyFlag
const ReservedCommandFlag & AudioIONotBusyFlag()
Definition: CommonCommandFlags.cpp:127
anonymous_namespace{ExtraMenus.cpp}::sAttachment2
AttachedItem sAttachment2
Definition: ExtraMenus.cpp:251
ExtraActions::Handler
Definition: ExtraMenus.cpp:25
Registry::Shared
std::unique_ptr< SharedItem > Shared(const BaseItemSharedPtr &ptr)
Definition: Registry.h:93
anonymous_namespace{ExtraMenus.cpp}::ExtraDeviceMenu
BaseItemSharedPtr ExtraDeviceMenu()
Definition: ExtraMenus.cpp:197
anonymous_namespace{ExtraMenus.cpp}::ExtraMiscItems
BaseItemSharedPtr ExtraMiscItems()
Definition: ExtraMenus.cpp:218
AlwaysEnabledFlag
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:35
MenuTable::AttachedItem
Definition: CommandManager.h:708
Registry::Placement
Definition: Registry.h:219
MenuTable::ConditionalItems
std::unique_ptr< ConditionalGroupItem > ConditionalItems(const Identifier &internalName, ConditionalGroupItem::Condition condition, Args &&... args)
Definition: CommandManager.h:639
ExtraActions::Handler::OnInputDevice
void OnInputDevice(const CommandContext &context)
Definition: ExtraMenus.cpp:87
XXO
#define XXO(s)
Definition: Internat.h:44
MixerToolBar::Get
static MixerToolBar & Get(AudacityProject &project)
Definition: MixerToolBar.cpp:71
anonymous_namespace{ExtraMenus.cpp}::ExtraMenu
BaseItemSharedPtr ExtraMenu()
Definition: ExtraMenus.cpp:147
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
ExtraActions::Handler::OnOutputGain
void OnOutputGain(const CommandContext &context)
Definition: ExtraMenus.cpp:27
Registry::BaseItemSharedPtr
std::shared_ptr< BaseItem > BaseItemSharedPtr
Definition: Registry.h:72
ExtraActions::Handler::OnInputGainDec
void OnInputGainDec(const CommandContext &context)
Definition: ExtraMenus.cpp:77
MenuTable::Items
std::unique_ptr< MenuItems > Items(const Identifier &internalName, Args &&... args)
Definition: CommandManager.h:600
ExtraActions::Handler::OnInputGain
void OnInputGain(const CommandContext &context)
Definition: ExtraMenus.cpp:57
ExtraActions::Handler::OnOutputGainDec
void OnOutputGainDec(const CommandContext &context)
Definition: ExtraMenus.cpp:47
ExtraActions::Handler::OnOutputDevice
void OnOutputDevice(const CommandContext &context)
Definition: ExtraMenus.cpp:94
ProjectWindows.h
accessors for certain important windows associated with each project
ExtraActions::Handler::OnFullScreen
void OnFullScreen(const CommandContext &context)
Definition: ExtraMenus.cpp:115
ExtraActions::Handler::OnInputGainInc
void OnInputGainInc(const CommandContext &context)
Definition: ExtraMenus.cpp:67
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
MenuTable::Command
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
Definition: CommandManager.h:675
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
GetProjectFrame
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
Definition: ProjectWindows.cpp:72
MenuManager::Get
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:70
CommandHandlerObject
wxEvtHandler CommandHandlerObject
Definition: CommandFunctors.h:28
MenuTable::Menu
std::unique_ptr< MenuItem > Menu(const Identifier &internalName, const TranslatableString &title, Args &&... args)
Definition: CommandManager.h:623
ExtraActions::Handler::OnOutputGainInc
void OnOutputGainInc(const CommandContext &context)
Definition: ExtraMenus.cpp:37
FN
#define FN(X)
Definition: ExtraMenus.cpp:139
MenuTable::Section
std::unique_ptr< MenuPart > Section(const Identifier &internalName, Args &&... args)
Definition: CommandManager.h:611
anonymous_namespace{ExtraMenus.cpp}::ExtraMixerMenu
BaseItemSharedPtr ExtraMixerMenu()
Definition: ExtraMenus.cpp:175
Prefs.h
MenuTable
Definition: CommandManager.h:416
ExtraActions
Namespace for helper functions for Extra menu.
Definition: ExtraMenus.cpp:18
CommandContext::project
AudacityProject & project
Definition: CommandContext.h:64
anonymous_namespace{Menus.cpp}::Options
std::vector< CommandFlagOptions > & Options()
Definition: Menus.cpp:527
anonymous_namespace{ExtraMenus.cpp}::sAttachment1
AttachedItem sAttachment1
Definition: ExtraMenus.cpp:169
MenuManager::ModifyToolbarMenus
static void ModifyToolbarMenus(AudacityProject &project)
Definition: Menus.cpp:592
ExtraActions::Handler::OnInputChannels
void OnInputChannels(const CommandContext &context)
Definition: ExtraMenus.cpp:101
findCommandHandler
static CommandHandlerObject & findCommandHandler(AudacityProject &)
Definition: ExtraMenus.cpp:130
ExtraActions::Handler::OnAudioHost
void OnAudioHost(const CommandContext &context)
Definition: ExtraMenus.cpp:108