Audacity 3.2.0
PluginMenus.cpp
Go to the documentation of this file.
1#include "../Benchmark.h"
2#include "../CommonCommandFlags.h"
3#include "../MenuCreator.h"
4#include "../PluginRegistrationDialog.h"
5#include "../ProjectWindows.h"
6#include "../commands/CommandDispatch.h"
7#include "../effects/EffectUI.h"
8#include "../prefs/PrefsDialog.h"
9#include "../toolbars/SelectionBar.h"
10#include "../toolbars/ToolManager.h"
11#include "AudacityMessageBox.h"
12#include "AudioIO.h"
13#include "CommandContext.h"
14#include "CommandManager.h"
15#include "EffectManager.h"
16#include "HelpSystem.h"
17#include "Journal.h"
18#include "MenuHelper.h"
19#include "PluginManager.h"
20#include "Prefs.h"
21#include "Project.h"
22#include "ProjectRate.h"
23#include "ProjectSnap.h"
25#include "RealtimeEffectPanel.h"
26#include "SampleTrack.h"
27#include "SyncLock.h"
28#include "TempDirectory.h"
29#include "TrackFocus.h"
30#include "UndoManager.h"
31#include "Viewport.h"
32#include "prefs/EffectsPrefs.h"
33#include "DoEffect.h"
34#include "prefs/GUIPrefs.h"
35
36// private helper classes and functions
37namespace {
38
39bool ShowManager(wxWindow *parent, int effectsCategory)
40{
41 PluginRegistrationDialog dlg(parent, effectsCategory);
42 return dlg.ShowModal() == wxID_OK;
43}
44
45void DoManagePluginsMenu(AudacityProject &project, int effectsCategory)
46{
47 auto &window = GetProjectFrame( project );
48 auto &pm = PluginManager::Get();
49 if (ShowManager(&window, effectsCategory))
51}
52
54{
55 auto &trackFocus = TrackFocus::Get(project);
56 auto &panel = RealtimeEffectPanel::Get(project);
57 if (panel.IsShown())
58 panel.HidePanel();
59 else if (auto pTrack = dynamic_cast<SampleTrack *>(trackFocus.Get()))
60 panel.ShowPanel(pTrack, true);
61}
62
63
64}
65
66namespace {
67
68// Menu handler functions
69
70void OnResetConfig(const CommandContext &context)
71{
72 auto &project = context.project;
73 auto &commandManager = CommandManager::Get(project);
74 commandManager.mLastAnalyzerRegistration = CommandManager::repeattypenone;
75 commandManager.mLastToolRegistration = CommandManager::repeattypenone;
76 commandManager.mLastGenerator = "";
77 commandManager.mLastEffect = "";
78 commandManager.mLastAnalyzer = "";
79 commandManager.mLastTool = "";
80
82
83 // Directory will be reset on next restart.
85
86 // There are many more things we could reset here.
87 // Beeds discussion as to which make sense to.
88 // Maybe in future versions?
89 // - Reset Effects
90 // - Reset Recording and Playback volumes
91 // - Reset Selection formats (and for spectral too)
92 // - Reset Play-at-speed speed to x1
93 // - Stop playback/recording and unapply pause.
94 // - Set Zoom sensibly.
98
101
102 gPrefs->Flush();
103
105
108
109 // These are necessary to preserve the newly correctly laid out toolbars.
110 // In particular the Device Toolbar ends up short on next restart,
111 // if they are left out.
112 gPrefs->Write(wxT("/PrefsVersion"), wxString(wxT(AUDACITY_PREFS_VERSION_STRING)));
113
114 // write out the version numbers to the prefs file for future checking
115 gPrefs->Write(wxT("/Version/Major"), AUDACITY_VERSION);
116 gPrefs->Write(wxT("/Version/Minor"), AUDACITY_RELEASE);
117 gPrefs->Write(wxT("/Version/Micro"), AUDACITY_REVISION);
118
119 gPrefs->Flush();
120
123
125 .SetRate(gPrefs->ReadDouble("/DefaultProjectSampleRate", 44100.0));
126}
127
129{
130 auto &project = context.project;
132}
133
134void OnEffect(const CommandContext &context)
135{
136 // using GET to interpret parameter as a PluginID
137 EffectUI::DoEffect(context.parameter.GET(), context.project, 0);
138}
139
140void OnManageEffects(const CommandContext &context)
141{
142 auto &project = context.project;
144}
145
147{
148 auto& project = context.project;
150}
151
152void OnAnalyzer2(wxCommandEvent& evt) { return; }
153
155{
156 auto& commandManager = CommandManager::Get(context.project);
157 auto lastEffect = commandManager.mLastGenerator;
158 if (!lastEffect.empty())
160 lastEffect, context.project,
161 commandManager.mRepeatGeneratorFlags | EffectManager::kRepeatGen);
162}
163
165{
166 auto& commandManager = CommandManager::Get(context.project);
167 auto lastEffect = commandManager.mLastEffect;
168 if (!lastEffect.empty())
169 EffectUI::DoEffect(lastEffect, context.project, commandManager.mRepeatEffectFlags);
170}
171
173{
174 auto& commandManager = CommandManager::Get(context.project);
175 switch (commandManager.mLastAnalyzerRegistration) {
177 {
178 auto lastEffect = commandManager.mLastAnalyzer;
179 if (!lastEffect.empty())
181 lastEffect, context.project, commandManager.mRepeatAnalyzerFlags);
182 }
183 break;
186 commandManager.mLastAnalyzerRegisteredId);
187 break;
188 }
189}
190
192{
193 auto &project = context.project;
195}
196
197void OnManageTools(const CommandContext &context )
198{
199 auto &project = context.project;
201}
202
203void OnBenchmark(const CommandContext &context)
204{
205 auto &project = context.project;
206 CommandManager::Get(project).RegisterLastTool(context); //Register Run Benchmark as Last Tool
207 auto &window = GetProjectFrame( project );
208 ::RunBenchmark( &window, project);
209}
210
212{
213 auto &project = context.project;
214 auto &commandManager = CommandManager::Get( project );
215
216 auto gAudioIO = AudioIO::Get();
217 bool &setting = gAudioIO->mSimulateRecordingErrors;
218 commandManager.Check(wxT("SimulateRecordingErrors"), !setting);
219 setting = !setting;
220}
221
223{
224 auto &project = context.project;
225 auto &commandManager = CommandManager::Get( project );
226
227 auto gAudioIO = AudioIO::Get();
228 auto &setting = gAudioIO->mDetectUpstreamDropouts;
229 auto oldValue = setting.load(std::memory_order_relaxed);
230 commandManager.Check(wxT("DetectUpstreamDropouts"), !oldValue);
231 setting.store(!oldValue, std::memory_order_relaxed);
232}
233
235{
236 auto OnMessage =
237 /* i18n-hint a "journal" is a text file that records
238 the user's interactions with the application */
239 XO("A journal will be recorded after Audacity restarts.");
240 auto OffMessage =
241 /* i18n-hint a "journal" is a text file that records
242 the user's interactions with the application */
243 XO("No journal will be recorded after Audacity restarts.");
244
245 using namespace Journal;
246 bool enabled = RecordEnabled();
247 if ( SetRecordEnabled(!enabled) )
248 enabled = !enabled;
249 if ( enabled )
250 AudacityMessageBox( OnMessage );
251 else
252 AudacityMessageBox( OffMessage );
253}
254
255}
256
257// Menu definitions
258
259// Under /MenuBar
260using namespace MenuRegistry;
261
262namespace {
265 [](const AudacityProject &project){
266 return !CommandManager::Get( project ).mLastGenerator.empty();
267 }
268 }; return flag; }
269
271{
272 // All of this is a bit hacky until we can get more things connected into
273 // the plugin manager...sorry! :-(
274 static auto menu = std::shared_ptr{
275 Menu( wxT("Generate"), XXO("&Generate"),
276 Section( "Manage",
277 Command( wxT("ManageGenerators"), XXO("Plugin Manager"),
279 ),
280
281 Section("RepeatLast",
282 // Delayed evaluation:
284 {
285 const auto &lastGenerator =
287 TranslatableString buildMenuLabel;
288 if (!lastGenerator.empty())
289 buildMenuLabel =
290 XO("Repeat %s")
291 .Format(PluginManager::Get().GetName(lastGenerator));
292 else
293 buildMenuLabel = XO("Repeat Last Generator");
294
295 return Command(wxT("RepeatLastGenerator"), buildMenuLabel,
299 Options{}.IsGlobal());
300 }
301 ),
302
303 Section( "Generators",
304 // Delayed evaluation:
305 [](AudacityProject &) {
306 auto result = Items("");
308 *result,
312 &OnEffect);
313 return result;
314 }
315 )
316 ) };
317 return menu;
318}
319
320static const ReservedCommandFlag
322 [](const AudacityProject &project){
324 }
325}; return flag; } //lll
326
328
331 [](const AudacityProject &project) {
332 return !CommandManager::Get(project).mLastEffect.empty();
333 }
334 }; return flag;
335}
336
337static const ReservedCommandFlag&
339 [](const AudacityProject &project) {
340 auto& trackFocus = TrackFocus::Get(const_cast<AudacityProject&>(project));
341 return (trackFocus.Get() != nullptr);
342 }
343 };
344 return flag;
345}
346
348{
349 // All of this is a bit hacky until we can get more things connected into
350 // the plugin manager...sorry! :-(
351 static auto menu = std::shared_ptr { Menu(
352 wxT("Effect"), XXO("Effe&ct"),
353 Section(
354 "Manage", Command(
355 wxT("ManageEffects"), XXO("Plugin Manager"),
357
358 Section(
359 "RealtimeEffects",
360 Command(
361 wxT("AddRealtimeEffects"), XXO("Add Realtime Effects"),
363#if defined(__WXMSW__) || defined(__WXMAC__)
364 , Command(
365 wxT("GetMoreEffects"), XXO("Get more effects..."),
366 [](const CommandContext&) {
367 OpenInDefaultBrowser("https://www.musehub.com");
368 },
370#endif
371#if defined(__WXMSW__)
372 , Command(
373 wxT("GetAIEffects"), XXO("Get AI effects..."),
374 [](const CommandContext&) {
375 OpenInDefaultBrowser("https://audacityteam.org/download/openvino");
376 },
378#endif
379 ),
380 Section(
381 "RepeatLast",
382 // Delayed evaluation:
384 const auto &lastEffect = CommandManager::Get(project).mLastEffect;
385 TranslatableString buildMenuLabel;
386 if (!lastEffect.empty())
387 buildMenuLabel =
388 XO("Repeat %s")
389 .Format(PluginManager::Get().GetName(lastEffect));
390 else
391 buildMenuLabel = XO("Repeat Last Effect");
392
393 return Command( wxT("RepeatLastEffect"), buildMenuLabel,
397 wxT("Ctrl+R") );
398 }),
399
400 Section(
401 "Effects",
402 // Delayed evaluation:
403 [](AudacityProject&) {
404 auto result = Items("");
406 *result,
410 &OnEffect);
411 return result;
412 }))
413 };
414 return menu;
415}
416
418
421 [](const AudacityProject &project) {
424 return true;
426 }
427 }; return flag;
428}
429
431{
432 // All of this is a bit hacky until we can get more things connected into
433 // the plugin manager...sorry! :-(
434 static auto menu = std::shared_ptr{
435 Menu( wxT("Analyze"), XXO("&Analyze"),
436 Section( "Manage",
437 Command( wxT("ManageAnalyzers"), XXO("Plugin Manager"),
439 ),
440
441 Section("RepeatLast",
442 // Delayed evaluation:
444 {
445 const auto &lastAnalyzer =
447 TranslatableString buildMenuLabel;
448 if (!lastAnalyzer.empty())
449 buildMenuLabel =
450 XO("Repeat %s")
451 .Format(PluginManager::Get().GetName(lastAnalyzer));
452 else
453 buildMenuLabel = XO("Repeat Last Analyzer");
454
455 return Command(wxT("RepeatLastAnalyzer"), buildMenuLabel,
459 Options{}.IsGlobal());
460 }
461 ),
462
463 Section( "Analyzers",
464 Items( "Windows" ),
465
466 // Delayed evaluation:
467 [](AudacityProject &) {
468 auto result = Items("");
470 *result,
474 &OnEffect);
475 return result;
476 }
477 )
478 ) };
479 return menu;
480}
481
483
485{
486 static auto menu = std::shared_ptr{
487 Menu( wxT("Tools"), XXO("T&ools"),
488 Section( "Manage",
489 Command( wxT("ManageTools"), XXO("Plugin Manager"),
491
492 //Separator(),
493 ),
494
495 Section( "Other",
496 Command( wxT("ConfigReset"), XXO("Reset &Configuration"),
499
500 // PRL: team consensus for 2.2.0 was, we let end users have this diagnostic,
501 // as they used to in 1.3.x
502 //#ifdef IS_ALPHA
503 // TODO: What should we do here? Make benchmark a plug-in?
504 // Easy enough to do. We'd call it mod-self-test.
505 Command( wxT("Benchmark"), XXO("&Run Benchmark..."),
507 //#endif
508 ),
509
510 Section( "Tools",
511 // Delayed evaluation:
512 [](AudacityProject &) {
513 auto result = Items("");
515 *result,
519 &OnEffect);
520 return result;
521 }
522 )
523
524#ifdef IS_ALPHA
525 ,
526 Section( "",
527 Command( wxT("SimulateRecordingErrors"),
528 XXO("Simulate Recording Errors"),
532 [](AudacityProject&){
533 return AudioIO::Get()->mSimulateRecordingErrors; } ) ),
534 Command( wxT("DetectUpstreamDropouts"),
535 XXO("Detect Upstream Dropouts"),
539 [](AudacityProject&){
541 .load(std::memory_order_relaxed); } ) )
542 )
543#endif
544
545#if defined(IS_ALPHA) || defined(END_USER_JOURNALLING)
546 ,
547 Section( "",
548 Command( wxT("WriteJournal"),
549 /* i18n-hint a "journal" is a text file that records
550 the user's interactions with the application */
551 XXO("Write Journal"),
555 return Journal::RecordEnabled(); } ) )
556 )
557#endif
558
559 ) };
560 return menu;
561}
562
564
565}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
BoolSetting SoundActivatedRecord
Definition: AudioIO.cpp:3370
AttachedItem sAttachment1
AttachedItem sAttachment3
AttachedItem sAttachment2
void RunBenchmark(wxWindow *parent, AudacityProject &project)
Definition: Benchmark.cpp:91
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & WaveTracksSelectedFlag()
@ EffectTypeAnalyze
@ EffectTypeGenerate
@ EffectTypeTool
@ EffectTypeProcess
ChoiceSetting EffectsGroupBy
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
BoolSetting & ShowRMSPref()
Definition: GUIPrefs.cpp:190
BoolSetting & ShowClippingPref()
Definition: GUIPrefs.cpp:196
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
void ResetPreferences()
Call this to reset preferences to an (almost)-"new" default state.
Definition: Prefs.cpp:253
#define AUDACITY_PREFS_VERSION_STRING
Definition: Prefs.h:39
void DoReloadPreferences(AudacityProject &project)
an object holding per-project preferred sample rate
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 ...
IntSetting SelectionToolbarMode
StringSetting SnapToSetting
Definition: SnapUtils.cpp:29
EnumSetting< SnapMode > SnapModeSetting
Definition: SnapUtils.cpp:31
BoolSetting SyncLockTracks
Definition: SyncLock.cpp:163
const auto project
static std::once_flag flag
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static AudioIO * Get()
Definition: AudioIO.cpp:126
bool mSimulateRecordingErrors
Definition: AudioIO.h:388
std::atomic< bool > mDetectUpstreamDropouts
Definition: AudioIO.h:392
wxString Read() const
Definition: Prefs.cpp:388
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
CommandParameter parameter
AudacityProject & project
PluginID mLastGenerator
void RegisterLastTool(const CommandContext &context)
void DoRepeatProcess(const CommandContext &context, int)
static CommandManager & Get(AudacityProject &project)
PluginID mLastEffect
PluginID mLastAnalyzer
int mLastAnalyzerRegistration
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
static void RebuildAllMenuBars()
static PluginManager & Get()
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
void SetRate(double rate)
Definition: ProjectRate.cpp:58
void SetSnapMode(SnapMode mode)
Definition: ProjectSnap.cpp:41
void SetSnapTo(Identifier snap)
Definition: ProjectSnap.cpp:59
static ProjectSnap & Get(AudacityProject &project)
Definition: ProjectSnap.cpp:27
static RealtimeEffectManager & Get(AudacityProject &project)
bool IsActive() const noexcept
To be called only from main thread.
static RealtimeEffectPanel & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
bool Reset()
Reset to the default value.
Definition: Prefs.h:284
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
static void OnResetToolBars(const CommandContext &context)
Track * Get()
Definition: TrackFocus.cpp:156
Holds a msgid for the translation catalog; may also bind format arguments.
void SetToDefaultSize()
Send a message to the main window PARENT of the viewport, to resize.
Definition: Viewport.cpp:765
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33
virtual bool Flush() noexcept=0
double ReadDouble(const wxString &key, double defaultValue) const
virtual bool Write(const wxString &key, bool value)=0
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Definition: BasicUI.cpp:246
bool DoEffect(const PluginID &ID, AudacityProject &project, unsigned flags)
Definition: DoEffect.cpp:30
FILES_API void UpdateDefaultPath(Operation op, const FilePath &path)
Facilities for recording and playback of sequences of user interaction.
bool SetRecordEnabled(bool value)
Definition: Journal.cpp:209
bool RecordEnabled()
Definition: Journal.cpp:204
void PopulateEffectsMenu(Group &menuItems, EffectType type, CommandFlag batchflags, const wxString &groupby, void(*onMenuCommand)(const CommandContext &), std::function< bool(const PluginDescriptor &)> pred={})
Definition: MenuHelper.cpp:563
constexpr auto Section
Definition: MenuRegistry.h:436
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175
FILES_API const FilePath & DefaultTempDir()
void OnRepeatLastEffect(const CommandContext &context)
void OnWriteJournal(const CommandContext &)
const ReservedCommandFlag & HasLastEffectFlag()
void OnResetConfig(const CommandContext &context)
Definition: PluginMenus.cpp:70
bool ShowManager(wxWindow *parent, int effectsCategory)
Definition: PluginMenus.cpp:39
const ReservedCommandFlag & HasLastAnalyzerFlag()
static const ReservedCommandFlag & HasTrackFocusFlag()
void OnAnalyzer2(wxCommandEvent &evt)
void OnRepeatLastGenerator(const CommandContext &context)
void DoManageRealtimeEffectsSidePanel(AudacityProject &project)
Definition: PluginMenus.cpp:53
void OnRepeatLastAnalyzer(const CommandContext &context)
void OnEffect(const CommandContext &context)
static const ReservedCommandFlag & IsRealtimeNotActiveFlag()
void OnManageTools(const CommandContext &context)
void OnDetectUpstreamDropouts(const CommandContext &context)
void OnBenchmark(const CommandContext &context)
void OnManageEffects(const CommandContext &context)
void DoManagePluginsMenu(AudacityProject &project, int effectsCategory)
Definition: PluginMenus.cpp:45
void OnManageAnalyzers(const CommandContext &context)
void OnSimulateRecordingErrors(const CommandContext &context)
const ReservedCommandFlag & HasLastGeneratorFlag()
void OnAddRealtimeEffects(const CommandContext &context)
void OnManageGenerators(const CommandContext &context)
Options && IsGlobal() &&
Definition: MenuRegistry.h:56
Options && CheckTest(const CheckFn &fn) &&
Definition: MenuRegistry.h:74