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
38 PluginManager &pm, wxWindow *parent)
39{
40 PluginRegistrationDialog dlg(parent);
41 return dlg.ShowModal() == wxID_OK;
42}
43
45{
46 auto &window = GetProjectFrame( project );
47 auto &pm = PluginManager::Get();
48 if (ShowManager(pm, &window))
50}
51
53{
54 auto &trackFocus = TrackFocus::Get(project);
55 auto &panel = RealtimeEffectPanel::Get(project);
56 if (panel.IsShown())
57 panel.HidePanel();
58 else if (auto pTrack = dynamic_cast<SampleTrack *>(trackFocus.Get()))
59 panel.ShowPanel(pTrack, true);
60}
61
62
63}
64
65namespace {
66
67// Menu handler functions
68
69void OnResetConfig(const CommandContext &context)
70{
71 auto &project = context.project;
72 auto &commandManager = CommandManager::Get(project);
73 commandManager.mLastAnalyzerRegistration = CommandManager::repeattypenone;
74 commandManager.mLastToolRegistration = CommandManager::repeattypenone;
75 commandManager.mLastGenerator = "";
76 commandManager.mLastEffect = "";
77 commandManager.mLastAnalyzer = "";
78 commandManager.mLastTool = "";
79
81
82 // Directory will be reset on next restart.
84
85 // There are many more things we could reset here.
86 // Beeds discussion as to which make sense to.
87 // Maybe in future versions?
88 // - Reset Effects
89 // - Reset Recording and Playback volumes
90 // - Reset Selection formats (and for spectral too)
91 // - Reset Play-at-speed speed to x1
92 // - Stop playback/recording and unapply pause.
93 // - Set Zoom sensibly.
97 gPrefs->Flush();
99
102
103 // These are necessary to preserve the newly correctly laid out toolbars.
104 // In particular the Device Toolbar ends up short on next restart,
105 // if they are left out.
106 gPrefs->Write(wxT("/PrefsVersion"), wxString(wxT(AUDACITY_PREFS_VERSION_STRING)));
107
108 // write out the version numbers to the prefs file for future checking
109 gPrefs->Write(wxT("/Version/Major"), AUDACITY_VERSION);
110 gPrefs->Write(wxT("/Version/Minor"), AUDACITY_RELEASE);
111 gPrefs->Write(wxT("/Version/Micro"), AUDACITY_REVISION);
112
113 gPrefs->Flush();
114
117
119 .SetRate(gPrefs->ReadDouble("/DefaultProjectSampleRate", 44100.0));
120}
121
123{
124 auto &project = context.project;
126}
127
128void OnEffect(const CommandContext &context)
129{
130 // using GET to interpret parameter as a PluginID
131 EffectUI::DoEffect(context.parameter.GET(), context, 0);
132}
133
134void OnManageEffects(const CommandContext &context)
135{
136 auto &project = context.project;
138}
139
141{
142 auto& project = context.project;
144}
145
146void OnAnalyzer2(wxCommandEvent& evt) { return; }
147
149{
150 auto& commandManager = CommandManager::Get(context.project);
151 auto lastEffect = commandManager.mLastGenerator;
152 if (!lastEffect.empty())
153 {
155 lastEffect, context, commandManager.mRepeatGeneratorFlags | EffectManager::kRepeatGen);
156 }
157}
158
160{
161 auto& commandManager = CommandManager::Get(context.project);
162 auto lastEffect = commandManager.mLastEffect;
163 if (!lastEffect.empty())
164 {
166 lastEffect, context, commandManager.mRepeatEffectFlags);
167 }
168}
169
171{
172 auto& commandManager = CommandManager::Get(context.project);
173 switch (commandManager.mLastAnalyzerRegistration) {
175 {
176 auto lastEffect = commandManager.mLastAnalyzer;
177 if (!lastEffect.empty())
178 {
180 lastEffect, context, commandManager.mRepeatAnalyzerFlags);
181 }
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 = XO("Repeat %s")
290 .Format(EffectManager::Get().GetCommandName(lastGenerator));
291 else
292 buildMenuLabel = XO("Repeat Last Generator");
293
294 return Command(wxT("RepeatLastGenerator"), buildMenuLabel,
298 Options{}.IsGlobal());
299 }
300 ),
301
302 Section( "Generators",
303 // Delayed evaluation:
304 [](AudacityProject &) {
305 auto result = Items("");
307 *result,
311 &OnEffect);
312 return result;
313 }
314 )
315 ) };
316 return menu;
317}
318
319static const ReservedCommandFlag
321 [](const AudacityProject &project){
323 }
324}; return flag; } //lll
325
327
330 [](const AudacityProject &project) {
331 return !CommandManager::Get(project).mLastEffect.empty();
332 }
333 }; return flag;
334}
335
336static const ReservedCommandFlag&
338 [](const AudacityProject &project) {
339 auto& trackFocus = TrackFocus::Get(const_cast<AudacityProject&>(project));
340 return (trackFocus.Get() != nullptr);
341 }
342 };
343 return flag;
344}
345
347{
348 // All of this is a bit hacky until we can get more things connected into
349 // the plugin manager...sorry! :-(
350 static auto menu = std::shared_ptr{
351 Menu( wxT("Effect"), XXO("Effe&ct"),
352 Section( "Manage",
353 Command( wxT("ManageEffects"), XXO("Plugin Manager"),
355 ),
356
357 Section( "RealtimeEffects",
358 Command ( wxT("AddRealtimeEffects"), XXO("Add Realtime Effects"),
360 ),
361
362 Section( "RepeatLast",
363 // Delayed evaluation:
365 {
366 const auto &lastEffect = CommandManager::Get(project).mLastEffect;
367 TranslatableString buildMenuLabel;
368 if (!lastEffect.empty())
369 buildMenuLabel = XO("Repeat %s")
370 .Format( EffectManager::Get().GetCommandName(lastEffect) );
371 else
372 buildMenuLabel = XO("Repeat Last Effect");
373
374 return Command( wxT("RepeatLastEffect"), buildMenuLabel,
378 wxT("Ctrl+R") );
379 }
380 ),
381
382 Section( "Effects",
383 // Delayed evaluation:
384 [](AudacityProject &) {
385 auto result = Items("");
387 *result,
391 &OnEffect);
392 return result;
393 }
394 )
395 ) };
396 return menu;
397}
398
400
403 [](const AudacityProject &project) {
406 return true;
408 }
409 }; return flag;
410}
411
413{
414 // All of this is a bit hacky until we can get more things connected into
415 // the plugin manager...sorry! :-(
416 static auto menu = std::shared_ptr{
417 Menu( wxT("Analyze"), XXO("&Analyze"),
418 Section( "Manage",
419 Command( wxT("ManageAnalyzers"), XXO("Plugin Manager"),
421 ),
422
423 Section("RepeatLast",
424 // Delayed evaluation:
426 {
427 const auto &lastAnalyzer =
429 TranslatableString buildMenuLabel;
430 if (!lastAnalyzer.empty())
431 buildMenuLabel = XO("Repeat %s")
432 .Format(EffectManager::Get().GetCommandName(lastAnalyzer));
433 else
434 buildMenuLabel = XO("Repeat Last Analyzer");
435
436 return Command(wxT("RepeatLastAnalyzer"), buildMenuLabel,
440 Options{}.IsGlobal());
441 }
442 ),
443
444 Section( "Analyzers",
445 Items( "Windows" ),
446
447 // Delayed evaluation:
448 [](AudacityProject &) {
449 auto result = Items("");
451 *result,
455 &OnEffect);
456 return result;
457 }
458 )
459 ) };
460 return menu;
461}
462
464
466{
467 static auto menu = std::shared_ptr{
468 Menu( wxT("Tools"), XXO("T&ools"),
469 Section( "Manage",
470 Command( wxT("ManageTools"), XXO("Plugin Manager"),
472
473 //Separator(),
474 ),
475
476 Section( "Other",
477 Command( wxT("ConfigReset"), XXO("Reset &Configuration"),
480
481 // PRL: team consensus for 2.2.0 was, we let end users have this diagnostic,
482 // as they used to in 1.3.x
483 //#ifdef IS_ALPHA
484 // TODO: What should we do here? Make benchmark a plug-in?
485 // Easy enough to do. We'd call it mod-self-test.
486 Command( wxT("Benchmark"), XXO("&Run Benchmark..."),
488 //#endif
489 ),
490
491 Section( "Tools",
492 // Delayed evaluation:
493 [](AudacityProject &) {
494 auto result = Items("");
496 *result,
500 &OnEffect);
501 return result;
502 }
503 )
504
505#ifdef IS_ALPHA
506 ,
507 Section( "",
508 Command( wxT("SimulateRecordingErrors"),
509 XXO("Simulate Recording Errors"),
513 [](AudacityProject&){
514 return AudioIO::Get()->mSimulateRecordingErrors; } ) ),
515 Command( wxT("DetectUpstreamDropouts"),
516 XXO("Detect Upstream Dropouts"),
520 [](AudacityProject&){
522 .load(std::memory_order_relaxed); } ) )
523 )
524#endif
525
526#if defined(IS_ALPHA) || defined(END_USER_JOURNALLING)
527 ,
528 Section( "",
529 Command( wxT("WriteJournal"),
530 /* i18n-hint a "journal" is a text file that records
531 the user's interactions with the application */
532 XXO("Write Journal"),
536 return Journal::RecordEnabled(); } ) )
537 )
538#endif
539
540 ) };
541 return menu;
542}
543
545
546}
wxT("CloseDown"))
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
BoolSetting SoundActivatedRecord
Definition: AudioIO.cpp:3356
AttachedItem sAttachment1
AttachedItem sAttachment3
AttachedItem sAttachment2
void RunBenchmark(wxWindow *parent, AudacityProject &project)
Definition: Benchmark.cpp:90
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: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: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()
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 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:760
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:32
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:69
const ReservedCommandFlag & HasLastAnalyzerFlag()
static const ReservedCommandFlag & HasTrackFocusFlag()
void DoManagePluginsMenu(AudacityProject &project)
Definition: PluginMenus.cpp:44
void OnAnalyzer2(wxCommandEvent &evt)
bool ShowManager(PluginManager &pm, wxWindow *parent)
Definition: PluginMenus.cpp:37
void OnRepeatLastGenerator(const CommandContext &context)
void DoManageRealtimeEffectsSidePanel(AudacityProject &project)
Definition: PluginMenus.cpp:52
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 && IsGlobal() &&
Definition: MenuRegistry.h:56
Options && CheckTest(const CheckFn &fn) &&
Definition: MenuRegistry.h:74