Audacity 3.2.0
PluginMenus.cpp
Go to the documentation of this file.
1#include "AudioIO.h"
2#include "../Benchmark.h"
3#include "../commands/CommandDispatch.h"
4#include "../CommonCommandFlags.h"
5#include "Journal.h"
6#include "../MenuCreator.h"
7#include "PluginManager.h"
8#include "../PluginRegistrationDialog.h"
9#include "Prefs.h"
10#include "Project.h"
11#include "ProjectRate.h"
12#include "ProjectSnap.h"
13#include "../ProjectWindows.h"
14#include "RealtimeEffectPanel.h"
15#include "SampleTrack.h"
16#include "SyncLock.h"
17#include "../toolbars/ToolManager.h"
18#include "../toolbars/SelectionBar.h"
19#include "TrackFocus.h"
20#include "TempDirectory.h"
21#include "UndoManager.h"
22#include "Viewport.h"
23#include "CommandContext.h"
24#include "CommandManager.h"
25#include "../effects/EffectManager.h"
26#include "../effects/EffectUI.h"
28#include "../prefs/PrefsDialog.h"
29#include "AudacityMessageBox.h"
30#include "MenuHelper.h"
31#include "prefs/EffectsPrefs.h"
32
33
34// private helper classes and functions
35namespace {
36
37bool ShowManager(wxWindow *parent, int effectsCategory)
38{
39 PluginRegistrationDialog dlg(parent, effectsCategory);
40 return dlg.ShowModal() == wxID_OK;
41}
42
43void DoManagePluginsMenu(AudacityProject &project, int effectsCategory)
44{
45 auto &window = GetProjectFrame( project );
46 auto &pm = PluginManager::Get();
47 if (ShowManager(&window, effectsCategory))
49}
50
52{
53 auto &trackFocus = TrackFocus::Get(project);
54 auto &panel = RealtimeEffectPanel::Get(project);
55 if (panel.IsShown())
56 panel.HidePanel();
57 else if (auto pTrack = dynamic_cast<SampleTrack *>(trackFocus.Get()))
58 panel.ShowPanel(pTrack, true);
59}
60
61
62}
63
64namespace {
65
66// Menu handler functions
67
68void OnResetConfig(const CommandContext &context)
69{
70 auto &project = context.project;
71 auto &commandManager = CommandManager::Get(project);
72 commandManager.mLastAnalyzerRegistration = CommandManager::repeattypenone;
73 commandManager.mLastToolRegistration = CommandManager::repeattypenone;
74 commandManager.mLastGenerator = "";
75 commandManager.mLastEffect = "";
76 commandManager.mLastAnalyzer = "";
77 commandManager.mLastTool = "";
78
80
81 // Directory will be reset on next restart.
83
84 // There are many more things we could reset here.
85 // Beeds discussion as to which make sense to.
86 // Maybe in future versions?
87 // - Reset Effects
88 // - Reset Recording and Playback volumes
89 // - Reset Selection formats (and for spectral too)
90 // - Reset Play-at-speed speed to x1
91 // - Stop playback/recording and unapply pause.
92 // - Set Zoom sensibly.
96 gPrefs->Flush();
98
101
102 // These are necessary to preserve the newly correctly laid out toolbars.
103 // In particular the Device Toolbar ends up short on next restart,
104 // if they are left out.
105 gPrefs->Write(wxT("/PrefsVersion"), wxString(wxT(AUDACITY_PREFS_VERSION_STRING)));
106
107 // write out the version numbers to the prefs file for future checking
108 gPrefs->Write(wxT("/Version/Major"), AUDACITY_VERSION);
109 gPrefs->Write(wxT("/Version/Minor"), AUDACITY_RELEASE);
110 gPrefs->Write(wxT("/Version/Micro"), AUDACITY_REVISION);
111
112 gPrefs->Flush();
113
116
118 .SetRate(gPrefs->ReadDouble("/DefaultProjectSampleRate", 44100.0));
119}
120
122{
123 auto &project = context.project;
125}
126
127void OnEffect(const CommandContext &context)
128{
129 // using GET to interpret parameter as a PluginID
130 EffectUI::DoEffect(context.parameter.GET(), context, 0);
131}
132
133void OnManageEffects(const CommandContext &context)
134{
135 auto &project = context.project;
137}
138
140{
141 auto& project = context.project;
143}
144
145void OnAnalyzer2(wxCommandEvent& evt) { return; }
146
148{
149 auto& commandManager = CommandManager::Get(context.project);
150 auto lastEffect = commandManager.mLastGenerator;
151 if (!lastEffect.empty())
152 {
154 lastEffect, context, commandManager.mRepeatGeneratorFlags | EffectManager::kRepeatGen);
155 }
156}
157
159{
160 auto& commandManager = CommandManager::Get(context.project);
161 auto lastEffect = commandManager.mLastEffect;
162 if (!lastEffect.empty())
163 {
165 lastEffect, context, commandManager.mRepeatEffectFlags);
166 }
167}
168
170{
171 auto& commandManager = CommandManager::Get(context.project);
172 switch (commandManager.mLastAnalyzerRegistration) {
174 {
175 auto lastEffect = commandManager.mLastAnalyzer;
176 if (!lastEffect.empty())
177 {
179 lastEffect, context, commandManager.mRepeatAnalyzerFlags);
180 }
181 }
182 break;
185 commandManager.mLastAnalyzerRegisteredId);
186 break;
187 }
188}
189
191{
192 auto &project = context.project;
194}
195
196void OnManageTools(const CommandContext &context )
197{
198 auto &project = context.project;
200}
201
202void OnBenchmark(const CommandContext &context)
203{
204 auto &project = context.project;
205 CommandManager::Get(project).RegisterLastTool(context); //Register Run Benchmark as Last Tool
206 auto &window = GetProjectFrame( project );
207 ::RunBenchmark( &window, project);
208}
209
211{
212 auto &project = context.project;
213 auto &commandManager = CommandManager::Get( project );
214
215 auto gAudioIO = AudioIO::Get();
216 bool &setting = gAudioIO->mSimulateRecordingErrors;
217 commandManager.Check(wxT("SimulateRecordingErrors"), !setting);
218 setting = !setting;
219}
220
222{
223 auto &project = context.project;
224 auto &commandManager = CommandManager::Get( project );
225
226 auto gAudioIO = AudioIO::Get();
227 auto &setting = gAudioIO->mDetectUpstreamDropouts;
228 auto oldValue = setting.load(std::memory_order_relaxed);
229 commandManager.Check(wxT("DetectUpstreamDropouts"), !oldValue);
230 setting.store(!oldValue, std::memory_order_relaxed);
231}
232
234{
235 auto OnMessage =
236 /* i18n-hint a "journal" is a text file that records
237 the user's interactions with the application */
238 XO("A journal will be recorded after Audacity restarts.");
239 auto OffMessage =
240 /* i18n-hint a "journal" is a text file that records
241 the user's interactions with the application */
242 XO("No journal will be recorded after Audacity restarts.");
243
244 using namespace Journal;
245 bool enabled = RecordEnabled();
246 if ( SetRecordEnabled(!enabled) )
247 enabled = !enabled;
248 if ( enabled )
249 AudacityMessageBox( OnMessage );
250 else
251 AudacityMessageBox( OffMessage );
252}
253
254}
255
256// Menu definitions
257
258// Under /MenuBar
259using namespace MenuRegistry;
260
261namespace {
264 [](const AudacityProject &project){
265 return !CommandManager::Get( project ).mLastGenerator.empty();
266 }
267 }; return flag; }
268
270{
271 // All of this is a bit hacky until we can get more things connected into
272 // the plugin manager...sorry! :-(
273 static auto menu = std::shared_ptr{
274 Menu( wxT("Generate"), XXO("&Generate"),
275 Section( "Manage",
276 Command( wxT("ManageGenerators"), XXO("Plugin Manager"),
278 ),
279
280 Section("RepeatLast",
281 // Delayed evaluation:
283 {
284 const auto &lastGenerator =
286 TranslatableString buildMenuLabel;
287 if (!lastGenerator.empty())
288 buildMenuLabel = XO("Repeat %s")
289 .Format(EffectManager::Get().GetCommandName(lastGenerator));
290 else
291 buildMenuLabel = XO("Repeat Last Generator");
292
293 return Command(wxT("RepeatLastGenerator"), buildMenuLabel,
297 Options{}.IsGlobal());
298 }
299 ),
300
301 Section( "Generators",
302 // Delayed evaluation:
303 [](AudacityProject &) {
304 auto result = Items("");
306 *result,
310 &OnEffect);
311 return result;
312 }
313 )
314 ) };
315 return menu;
316}
317
318static const ReservedCommandFlag
320 [](const AudacityProject &project){
322 }
323}; return flag; } //lll
324
326
329 [](const AudacityProject &project) {
330 return !CommandManager::Get(project).mLastEffect.empty();
331 }
332 }; return flag;
333}
334
335static const ReservedCommandFlag&
337 [](const AudacityProject &project) {
338 auto& trackFocus = TrackFocus::Get(const_cast<AudacityProject&>(project));
339 return (trackFocus.Get() != nullptr);
340 }
341 };
342 return flag;
343}
344
346{
347 // All of this is a bit hacky until we can get more things connected into
348 // the plugin manager...sorry! :-(
349 static auto menu = std::shared_ptr{
350 Menu( wxT("Effect"), XXO("Effe&ct"),
351 Section( "Manage",
352 Command( wxT("ManageEffects"), XXO("Plugin Manager"),
354 ),
355
356 Section( "RealtimeEffects",
357 Command ( wxT("AddRealtimeEffects"), XXO("Add Realtime Effects"),
359 ),
360
361 Section( "RepeatLast",
362 // Delayed evaluation:
364 {
365 const auto &lastEffect = CommandManager::Get(project).mLastEffect;
366 TranslatableString buildMenuLabel;
367 if (!lastEffect.empty())
368 buildMenuLabel = XO("Repeat %s")
369 .Format( EffectManager::Get().GetCommandName(lastEffect) );
370 else
371 buildMenuLabel = XO("Repeat Last Effect");
372
373 return Command( wxT("RepeatLastEffect"), buildMenuLabel,
377 wxT("Ctrl+R") );
378 }
379 ),
380
381 Section( "Effects",
382 // Delayed evaluation:
383 [](AudacityProject &) {
384 auto result = Items("");
386 *result,
390 &OnEffect);
391 return result;
392 }
393 )
394 ) };
395 return menu;
396}
397
399
402 [](const AudacityProject &project) {
405 return true;
407 }
408 }; return flag;
409}
410
412{
413 // All of this is a bit hacky until we can get more things connected into
414 // the plugin manager...sorry! :-(
415 static auto menu = std::shared_ptr{
416 Menu( wxT("Analyze"), XXO("&Analyze"),
417 Section( "Manage",
418 Command( wxT("ManageAnalyzers"), XXO("Plugin Manager"),
420 ),
421
422 Section("RepeatLast",
423 // Delayed evaluation:
425 {
426 const auto &lastAnalyzer =
428 TranslatableString buildMenuLabel;
429 if (!lastAnalyzer.empty())
430 buildMenuLabel = XO("Repeat %s")
431 .Format(EffectManager::Get().GetCommandName(lastAnalyzer));
432 else
433 buildMenuLabel = XO("Repeat Last Analyzer");
434
435 return Command(wxT("RepeatLastAnalyzer"), buildMenuLabel,
439 Options{}.IsGlobal());
440 }
441 ),
442
443 Section( "Analyzers",
444 Items( "Windows" ),
445
446 // Delayed evaluation:
447 [](AudacityProject &) {
448 auto result = Items("");
450 *result,
454 &OnEffect);
455 return result;
456 }
457 )
458 ) };
459 return menu;
460}
461
463
465{
466 static auto menu = std::shared_ptr{
467 Menu( wxT("Tools"), XXO("T&ools"),
468 Section( "Manage",
469 Command( wxT("ManageTools"), XXO("Plugin Manager"),
471
472 //Separator(),
473 ),
474
475 Section( "Other",
476 Command( wxT("ConfigReset"), XXO("Reset &Configuration"),
479
480 // PRL: team consensus for 2.2.0 was, we let end users have this diagnostic,
481 // as they used to in 1.3.x
482 //#ifdef IS_ALPHA
483 // TODO: What should we do here? Make benchmark a plug-in?
484 // Easy enough to do. We'd call it mod-self-test.
485 Command( wxT("Benchmark"), XXO("&Run Benchmark..."),
487 //#endif
488 ),
489
490 Section( "Tools",
491 // Delayed evaluation:
492 [](AudacityProject &) {
493 auto result = Items("");
495 *result,
499 &OnEffect);
500 return result;
501 }
502 )
503
504#ifdef IS_ALPHA
505 ,
506 Section( "",
507 Command( wxT("SimulateRecordingErrors"),
508 XXO("Simulate Recording Errors"),
512 [](AudacityProject&){
513 return AudioIO::Get()->mSimulateRecordingErrors; } ) ),
514 Command( wxT("DetectUpstreamDropouts"),
515 XXO("Detect Upstream Dropouts"),
519 [](AudacityProject&){
521 .load(std::memory_order_relaxed); } ) )
522 )
523#endif
524
525#if defined(IS_ALPHA) || defined(END_USER_JOURNALLING)
526 ,
527 Section( "",
528 Command( wxT("WriteJournal"),
529 /* i18n-hint a "journal" is a text file that records
530 the user's interactions with the application */
531 XXO("Write Journal"),
535 return Journal::RecordEnabled(); } ) )
536 )
537#endif
538
539 ) };
540 return menu;
541}
542
544
545}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
BoolSetting SoundActivatedRecord
Definition: AudioIO.cpp:3354
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")
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:396
std::atomic< bool > mDetectUpstreamDropouts
Definition: AudioIO.h:400
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
static EffectManager & Get()
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:761
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
AUDACITY_DLL_API bool DoEffect(const PluginID &ID, const CommandContext &context, unsigned flags)
'Repeat Last Effect'.
Definition: EffectUI.cpp:1148
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:68
bool ShowManager(wxWindow *parent, int effectsCategory)
Definition: PluginMenus.cpp:37
const ReservedCommandFlag & HasLastAnalyzerFlag()
static const ReservedCommandFlag & HasTrackFocusFlag()
void OnAnalyzer2(wxCommandEvent &evt)
void OnRepeatLastGenerator(const CommandContext &context)
void DoManageRealtimeEffectsSidePanel(AudacityProject &project)
Definition: PluginMenus.cpp:51
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:43
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