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 "../Menus.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 "../ProjectSettings.h"
14#include "../ProjectWindow.h"
15#include "../ProjectWindows.h"
16#include "../ProjectSelectionManager.h"
17#include "RealtimeEffectPanel.h"
18#include "SampleTrack.h"
19#include "SyncLock.h"
20#include "../toolbars/ToolManager.h"
21#include "../toolbars/SelectionBar.h"
22#include "../TrackPanelAx.h"
23#include "TempDirectory.h"
24#include "UndoManager.h"
25#include "../commands/CommandContext.h"
26#include "../commands/CommandManager.h"
27#include "../effects/EffectManager.h"
28#include "../effects/EffectUI.h"
30#include "../prefs/PrefsDialog.h"
31#include "AudacityMessageBox.h"
32#include "MenuHelper.h"
33#include "prefs/EffectsPrefs.h"
34
35
36// private helper classes and functions
37namespace {
38
40 PluginManager &pm, wxWindow *parent)
41{
42 PluginRegistrationDialog dlg(parent);
43 return dlg.ShowModal() == wxID_OK;
44}
45
47{
48 auto &window = GetProjectFrame( project );
49 auto &pm = PluginManager::Get();
50 if (ShowManager(pm, &window))
52}
53
55{
56 auto &trackFocus = TrackFocus::Get(project);
57 auto &panel = RealtimeEffectPanel::Get(project);
58 if (panel.IsShown())
59 panel.HidePanel();
60 else if (auto pTrack = dynamic_cast<SampleTrack *>(trackFocus.Get()))
61 panel.ShowPanel(pTrack, true);
62}
63
64
65}
66
67namespace {
68
69// Menu handler functions
70
71void OnResetConfig(const CommandContext &context)
72{
73 auto &project = context.project;
74 auto &menuManager = MenuManager::Get(project);
75 menuManager.mLastAnalyzerRegistration = MenuCreator::repeattypenone;
76 menuManager.mLastToolRegistration = MenuCreator::repeattypenone;
77 menuManager.mLastGenerator = "";
78 menuManager.mLastEffect = "";
79 menuManager.mLastAnalyzer = "";
80 menuManager.mLastTool = "";
81
83
84 // Directory will be reset on next restart.
86
87 // There are many more things we could reset here.
88 // Beeds discussion as to which make sense to.
89 // Maybe in future versions?
90 // - Reset Effects
91 // - Reset Recording and Playback volumes
92 // - Reset Selection formats (and for spectral too)
93 // - Reset Play-at-speed speed to x1
94 // - Stop playback/recording and unapply pause.
95 // - Set Zoom sensibly.
99 gPrefs->Flush();
101
104
105 // These are necessary to preserve the newly correctly laid out toolbars.
106 // In particular the Device Toolbar ends up short on next restart,
107 // if they are left out.
108 gPrefs->Write(wxT("/PrefsVersion"), wxString(wxT(AUDACITY_PREFS_VERSION_STRING)));
109
110 // write out the version numbers to the prefs file for future checking
111 gPrefs->Write(wxT("/Version/Major"), AUDACITY_VERSION);
112 gPrefs->Write(wxT("/Version/Minor"), AUDACITY_RELEASE);
113 gPrefs->Write(wxT("/Version/Micro"), AUDACITY_REVISION);
114
115 gPrefs->Flush();
116
119
121 .SetRate(gPrefs->ReadDouble("/DefaultProjectSampleRate", 44100.0));
122}
123
125{
126 auto &project = context.project;
128}
129
130void OnEffect(const CommandContext &context)
131{
132 // using GET to interpret parameter as a PluginID
133 EffectUI::DoEffect(context.parameter.GET(), context, 0);
134}
135
136void OnManageEffects(const CommandContext &context)
137{
138 auto &project = context.project;
140}
141
143{
144 auto& project = context.project;
146}
147
148void OnAnalyzer2(wxCommandEvent& evt) { return; }
149
151{
152 auto& menuManager = MenuManager::Get(context.project);
153 auto lastEffect = menuManager.mLastGenerator;
154 if (!lastEffect.empty())
155 {
157 lastEffect, context, menuManager.mRepeatGeneratorFlags | EffectManager::kRepeatGen);
158 }
159}
160
162{
163 auto& menuManager = MenuManager::Get(context.project);
164 auto lastEffect = menuManager.mLastEffect;
165 if (!lastEffect.empty())
166 {
168 lastEffect, context, menuManager.mRepeatEffectFlags);
169 }
170}
171
173{
174 auto& menuManager = MenuManager::Get(context.project);
175 switch (menuManager.mLastAnalyzerRegistration) {
177 {
178 auto lastEffect = menuManager.mLastAnalyzer;
179 if (!lastEffect.empty())
180 {
182 lastEffect, context, menuManager.mRepeatAnalyzerFlags);
183 }
184 }
185 break;
188 menuManager.mLastAnalyzerRegisteredId);
189 break;
190 }
191}
192
194{
195 auto &project = context.project;
197}
198
199void OnManageTools(const CommandContext &context )
200{
201 auto &project = context.project;
203}
204
205void OnBenchmark(const CommandContext &context)
206{
207 auto &project = context.project;
208 CommandManager::Get(project).RegisterLastTool(context); //Register Run Benchmark as Last Tool
209 auto &window = GetProjectFrame( project );
210 ::RunBenchmark( &window, project);
211}
212
214{
215 auto &project = context.project;
216 auto &commandManager = CommandManager::Get( project );
217
218 auto gAudioIO = AudioIO::Get();
219 bool &setting = gAudioIO->mSimulateRecordingErrors;
220 commandManager.Check(wxT("SimulateRecordingErrors"), !setting);
221 setting = !setting;
222}
223
225{
226 auto &project = context.project;
227 auto &commandManager = CommandManager::Get( project );
228
229 auto gAudioIO = AudioIO::Get();
230 auto &setting = gAudioIO->mDetectUpstreamDropouts;
231 auto oldValue = setting.load(std::memory_order_relaxed);
232 commandManager.Check(wxT("DetectUpstreamDropouts"), !oldValue);
233 setting.store(!oldValue, std::memory_order_relaxed);
234}
235
237{
238 auto OnMessage =
239 /* i18n-hint a "journal" is a text file that records
240 the user's interactions with the application */
241 XO("A journal will be recorded after Audacity restarts.");
242 auto OffMessage =
243 /* i18n-hint a "journal" is a text file that records
244 the user's interactions with the application */
245 XO("No journal will be recorded after Audacity restarts.");
246
247 using namespace Journal;
248 bool enabled = RecordEnabled();
249 if ( SetRecordEnabled(!enabled) )
250 enabled = !enabled;
251 if ( enabled )
252 AudacityMessageBox( OnMessage );
253 else
254 AudacityMessageBox( OffMessage );
255}
256
257}
258
259// Menu definitions
260
261// Under /MenuBar
262using namespace MenuTable;
263
264namespace {
267 [](const AudacityProject &project){
268 return !MenuManager::Get( project ).mLastGenerator.empty();
269 }
270 }; return flag; }
271
273{
274 // All of this is a bit hacky until we can get more things connected into
275 // the plugin manager...sorry! :-(
276
278
279 static BaseItemSharedPtr menu{
280 Menu( wxT("Generate"), XXO("&Generate"),
281 Section( "Manage",
282 Command( wxT("ManageGenerators"), XXO("Plugin Manager"),
284 ),
285
286 Section("RepeatLast",
287 // Delayed evaluation:
289 {
290 const auto &lastGenerator = MenuManager::Get(project).mLastGenerator;
291 TranslatableString buildMenuLabel;
292 if (!lastGenerator.empty())
293 buildMenuLabel = XO("Repeat %s")
294 .Format(EffectManager::Get().GetCommandName(lastGenerator));
295 else
296 buildMenuLabel = XO("Repeat Last Generator");
297
298 return Command(wxT("RepeatLastGenerator"), buildMenuLabel,
302 Options{}.IsGlobal());
303 }
304 ),
305
306 Section( "Generators",
307 // Delayed evaluation:
308 [](AudacityProject &) {
309 auto result = Items("");
311 *result,
315 &OnEffect);
316 return result;
317 }
318 )
319 ) };
320 return menu;
321}
322
323static const ReservedCommandFlag
325 [](const AudacityProject &project){
327 }
328}; return flag; } //lll
329
331 wxT(""),
333};
334
337 [](const AudacityProject &project) {
338 return !MenuManager::Get(project).mLastEffect.empty();
339 }
340 }; return flag;
341}
342
343static const ReservedCommandFlag&
345 [](const AudacityProject &project) {
346 auto& trackFocus = TrackFocus::Get(const_cast<AudacityProject&>(project));
347 return (trackFocus.Get() != nullptr);
348 }
349 };
350 return flag;
351}
352
354{
355 // All of this is a bit hacky until we can get more things connected into
356 // the plugin manager...sorry! :-(
357
358 static BaseItemSharedPtr menu{
359 Menu( wxT("Effect"), XXO("Effe&ct"),
360 Section( "Manage",
361 Command( wxT("ManageEffects"), XXO("Plugin Manager"),
363 ),
364
365 Section( "RealtimeEffects",
366 Command ( wxT("AddRealtimeEffects"), XXO("Add Realtime Effects"),
368 ),
369
370 Section( "RepeatLast",
371 // Delayed evaluation:
373 {
374 const auto &lastEffect = MenuManager::Get(project).mLastEffect;
375 TranslatableString buildMenuLabel;
376 if (!lastEffect.empty())
377 buildMenuLabel = XO("Repeat %s")
378 .Format( EffectManager::Get().GetCommandName(lastEffect) );
379 else
380 buildMenuLabel = XO("Repeat Last Effect");
381
382 return Command( wxT("RepeatLastEffect"), buildMenuLabel,
386 wxT("Ctrl+R") );
387 }
388 ),
389
390 Section( "Effects",
391 // Delayed evaluation:
392 [](AudacityProject &) {
393 auto result = Items("");
395 *result,
399 &OnEffect);
400 return result;
401 }
402 )
403 ) };
404 return menu;
405}
406
408 wxT(""),
410};
411
414 [](const AudacityProject &project) {
416 return !MenuManager::Get(project).mLastAnalyzer.empty();
417 }
418 }; return flag;
419}
420
422{
423 // All of this is a bit hacky until we can get more things connected into
424 // the plugin manager...sorry! :-(
425
427
428 static BaseItemSharedPtr menu{
429 Menu( wxT("Analyze"), XXO("&Analyze"),
430 Section( "Manage",
431 Command( wxT("ManageAnalyzers"), XXO("Plugin Manager"),
433 ),
434
435 Section("RepeatLast",
436 // Delayed evaluation:
438 {
439 const auto &lastAnalyzer = MenuManager::Get(project).mLastAnalyzer;
440 TranslatableString buildMenuLabel;
441 if (!lastAnalyzer.empty())
442 buildMenuLabel = XO("Repeat %s")
443 .Format(EffectManager::Get().GetCommandName(lastAnalyzer));
444 else
445 buildMenuLabel = XO("Repeat Last Analyzer");
446
447 return Command(wxT("RepeatLastAnalyzer"), buildMenuLabel,
451 Options{}.IsGlobal());
452 }
453 ),
454
455 Section( "Analyzers",
456 Items( "Windows" ),
457
458 // Delayed evaluation:
459 [](AudacityProject &) {
460 auto result = Items("");
462 *result,
466 &OnEffect);
467 return result;
468 }
469 )
470 ) };
471 return menu;
472}
473
475 wxT(""),
477};
478
480{
482
483 static BaseItemSharedPtr menu{
484 Menu( wxT("Tools"), XXO("T&ools"),
485 Section( "Manage",
486 Command( wxT("ManageTools"), XXO("Plugin Manager"),
488
489 //Separator(),
490 ),
491
492 Section( "Other",
493 Command( wxT("ConfigReset"), XXO("Reset &Configuration"),
496
497 // PRL: team consensus for 2.2.0 was, we let end users have this diagnostic,
498 // as they used to in 1.3.x
499 //#ifdef IS_ALPHA
500 // TODO: What should we do here? Make benchmark a plug-in?
501 // Easy enough to do. We'd call it mod-self-test.
502 Command( wxT("Benchmark"), XXO("&Run Benchmark..."),
504 //#endif
505 ),
506
507 Section( "Tools",
508 // Delayed evaluation:
509 [](AudacityProject &) {
510 auto result = Items("");
512 *result,
516 &OnEffect);
517 return result;
518 }
519 )
520
521#ifdef IS_ALPHA
522 ,
523 Section( "",
524 Command( wxT("SimulateRecordingErrors"),
525 XXO("Simulate Recording Errors"),
529 [](AudacityProject&){
530 return AudioIO::Get()->mSimulateRecordingErrors; } ) ),
531 Command( wxT("DetectUpstreamDropouts"),
532 XXO("Detect Upstream Dropouts"),
536 [](AudacityProject&){
538 .load(std::memory_order_relaxed); } ) )
539 )
540#endif
541
542#if defined(IS_ALPHA) || defined(END_USER_JOURNALLING)
543 ,
544 Section( "",
545 Command( wxT("WriteJournal"),
546 /* i18n-hint a "journal" is a text file that records
547 the user's interactions with the application */
548 XXO("Write Journal"),
552 return Journal::RecordEnabled(); } ) )
553 )
554#endif
555
556 ) };
557 return menu;
558}
559
561 wxT(""),
563};
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:3305
AttachedItem sAttachment1
AttachedItem sAttachment3
AttachedItem sAttachment2
void RunBenchmark(wxWindow *parent, AudacityProject &project)
Definition: Benchmark.cpp:89
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:224
#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:63
EnumSetting< SnapMode > SnapModeSetting
Definition: SnapUtils.cpp:65
BoolSetting SyncLockTracks
Definition: SyncLock.cpp:173
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:123
bool mSimulateRecordingErrors
Definition: AudioIO.h:396
std::atomic< bool > mDetectUpstreamDropouts
Definition: AudioIO.h:400
wxString Read() const
Definition: Prefs.cpp:369
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
CommandParameter parameter
AudacityProject & project
void RegisterLastTool(const CommandContext &context)
void DoRepeatProcess(const CommandContext &context, int)
static CommandManager & Get(AudacityProject &project)
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()
Definition: Menus.cpp:614
PluginID mLastAnalyzer
Definition: Menus.h:53
int mLastAnalyzerRegistration
Definition: Menus.h:54
PluginID mLastGenerator
Definition: Menus.h:51
@ repeattypeplugin
Definition: Menus.h:61
@ repeattypenone
Definition: Menus.h:60
@ repeattypeunique
Definition: Menus.h:62
PluginID mLastEffect
Definition: Menus.h:52
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
PluginManager maintains a list of all plug ins. That covers modules, effects, generators,...
Definition: PluginManager.h:51
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 void OnResetWindow(const CommandContext &context)
static RealtimeEffectManager & Get(AudacityProject &project)
bool IsActive() const noexcept
To be called only from main thread.
static RealtimeEffectPanel & Get(AudacityProject &project)
bool Reset()
Reset to the default value.
Definition: Prefs.h:282
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:205
static void OnResetToolBars(const CommandContext &context)
Track * Get()
Holds a msgid for the translation catalog; may also bind format arguments.
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:1144
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:562
constexpr auto Section
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
constexpr auto Items
constexpr auto Command
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:113
std::shared_ptr< BaseItem > BaseItemSharedPtr
Definition: Registry.h:78
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:71
const ReservedCommandFlag & HasLastAnalyzerFlag()
static const ReservedCommandFlag & HasTrackFocusFlag()
void DoManagePluginsMenu(AudacityProject &project)
Definition: PluginMenus.cpp:46
void OnAnalyzer2(wxCommandEvent &evt)
bool ShowManager(PluginManager &pm, wxWindow *parent)
Definition: PluginMenus.cpp:39
void OnRepeatLastGenerator(const CommandContext &context)
void DoManageRealtimeEffectsSidePanel(AudacityProject &project)
Definition: PluginMenus.cpp:54
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 OnManageAnalyzers(const CommandContext &context)
void OnSimulateRecordingErrors(const CommandContext &context)
const ReservedCommandFlag & HasLastGeneratorFlag()
void OnAddRealtimeEffects(const CommandContext &context)
void OnManageGenerators(const CommandContext &context)
Options && CheckTest(const CheckFn &fn) &&
Options && IsGlobal() &&