Audacity 3.2.0
CommonCommandFlags.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5CommonCommandFlags.cpp
6
7Paul Licameli split from Menus.cpp
8
9**********************************************************************/
10
11
12#include "CommonCommandFlags.h"
13
14
15
16#include <wx/frame.h>
17
18#include "AudioIO.h"
19#include "LabelTrack.h"
20#include "Menus.h"
21#include "Project.h"
22#include "ProjectAudioIO.h"
23#include "ProjectHistory.h"
24#include "ProjectWindows.h"
25#include "SyncLock.h"
26#include "UndoManager.h"
27#include "ViewInfo.h"
28#include "WaveTrack.h"
30
31/*
32
33This file registers functions implementing many of the tests for enabling of
34menu items. Sequence of a few of them has minor significance, but for most
35there is little reason to keep them in one file. Flags used only by one
36other file might instead be defined only where used.
37
38They are collected here because Menus.cpp is too low level to have the
39dependencies implied by the include directives above -- it would make dependency
40cycles.
41
42*/
43
44// Strong predicate excludes tracks that do not support basic editing.
46{
47 auto range = TrackList::Get(project).Selected()
48 - [](const Track *pTrack){
49 return !pTrack->SupportsBasicEditing(); };
50 return !range.empty();
51};
52
53// Weaker predicate.
55{
56 auto range = TrackList::Get(project).Selected();
57 return !range.empty();
58};
59
61{
63 ProjectAudioIO::Get( project ).GetAudioIOToken());
64};
65
67{
68 // This is equivalent to check if there is a valid selection,
69 // so it's used for Zoom to Selection too
71};
72
74static CommandFlagOptions result{
75// In reporting the issue with cut or copy, we don't tell the user they could also select some text in a label.
76 []( const TranslatableString &Name ) {
77 // PRL: These strings have hard-coded mention of a certain shortcut key,
78 // thus assuming the default shortcuts. That is questionable.
80#ifdef EXPERIMENTAL_DA
81 // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
82 format = XO("You must first select some audio for '%s' to act on.\n\nCtrl + A selects all audio.");
83#else
84#ifdef __WXMAC__
85 // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
86 format = XO("Select the audio for %s to use (for example, Cmd + A to Select All) then try again."
87 // No need to explain what a help button is for.
88 // "\n\nClick the Help button to learn more about selection methods."
89 );
90
91#else
92 // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
93 format = XO("Select the audio for %s to use (for example, Ctrl + A to Select All) then try again."
94 // No need to explain what a help button is for.
95 // "\n\nClick the Help button to learn more about selection methods."
96 );
97#endif
98#endif
99 return format.Format( Name );
100 },
101 "Selecting_Audio_-_the_basics",
102 XO("No Audio Selected")
103};
104return result;
105}
106
107// Noise Reduction has a custom error message, when nothing selected.
109 []( const TranslatableString &Name ) {
110 // i18n-hint: %s will be replaced by the name of an effect, usually 'Noise Reduction'.
111 auto format = XO("Select the audio for %s to use.\n\n1. Select audio that represents noise and use %s to get your 'noise profile'.\n\n2. When you have got your noise profile, select the audio you want to change\nand use %s to change that audio.");
112 return format.Format( Name, Name, Name );
113 },
114 "Noise_Reduction",
115 XO("No Audio Selected")
116};
117
118
119 // The sequence of these definitions has a minor significance in determining
120 // which user error message has precedence if more than one might apply, so
121 // they should be kept in this sequence in one .cpp file if it is important
122 // to preserve that behavior. If they are dispersed to more than one file,
123 // then the precedence will be unspecified.
124 // The ordering of the flags that only disable the default message is not
125 // significant.
128 [](const AudacityProject &project ){
129 return !AudioIOBusyPred( project );
130 },
131 CommandFlagOptions{ []( const TranslatableString& ) { return
132 // This reason will not be shown, because options that require it will be greyed out.
133 XO("You can only do this when playing and recording are\nstopped. (Pausing is not sufficient.)");
134 } ,"FAQ:Errors:Audio Must Be Stopped"}
135 .QuickTest()
136 .Priority( 1 )
137 }; return flag; }//lll
140 [](const AudacityProject &project){
141 // TODO: more-than-two-channels
142 auto range =
144 return std::any_of(range.begin(), range.end(),
145 [](auto pTrack){ return pTrack->NChannels() > 1; });
146 },
147 { []( const TranslatableString& ) { return
148 // This reason will not be shown, because the stereo-to-mono is greyed out if not allowed.
149 XO("You must first select some stereo audio to perform this\naction. (You cannot use this with mono.)");
150 } ,"Audacity_Selection"}
151 }; return flag; } //lda
156 }; return flag; }
161 }; return flag; }
164 [](const AudacityProject &project){
165 return
166 !TrackList::Get(project).Selected<const WaveTrack>().empty();
167 },
168 { [](const TranslatableString&) { return
169 XO("You must first select some audio to perform this action.\n(Selecting other kinds of track won't work.)");
170 } ,"Audacity_Selection"}
171 }; return flag; }
174 [](const AudacityProject &project){
175 return !TrackList::Get(project).Any().empty();
176 },
178 }; return flag; }
182 { []( const TranslatableString &Name ){ return
183 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
184 XO("\"%s\" requires one or more tracks to be selected.").Format( Name );
185 },"Audacity_Selection" }
186 }; return flag; }
190 { []( const TranslatableString &Name ){ return
191 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
192 XO("\"%s\" requires one or more tracks to be selected.").Format( Name );
193 },"Audacity_Selection" }
194 }; return flag; }
197 [](const AudacityProject &project){
198 for (auto w = wxWindow::FindFocus(); w; w = w->GetParent()) {
199 if (dynamic_cast<const NonKeystrokeInterceptingWindow*>(w))
200 return true;
201 }
202 return false;
203 },
205 }; return flag; }; //lll
206
211 }; return flag; } //lll
214 [](const AudacityProject &){
215 auto gAudioIO = AudioIO::Get();
216 return !(
217 gAudioIO->IsBusy() &&
218 gAudioIO->GetNumCaptureChannels() > 0
219 );
220 }
221 }; return flag; };
222
225 [](const AudacityProject &project){
226 return !TrackList::Get(project)
227 .Selected<const LabelTrack>().empty();
228 }
229 }; return flag; }
232 [](const AudacityProject &project){
234 }
235 }; return flag; }
238 [](const AudacityProject &project){
240 }
241 }; return flag; }
244 [](const AudacityProject &project){
245 return
247 &&
248 !TrackList::Get(project).Any().empty()
249 ;
250 }
251 }; return flag; }
254 [](const AudacityProject &project){
255 return
257 &&
258 !TrackList::Get(project).Any().empty()
259 ;
260 }
261 }; return flag; }
264 [](const AudacityProject &project){
265 return !TrackList::Get(project).Any<const WaveTrack>().empty();
266 }
267 }; return flag; }
270 [](const AudacityProject &project){
272 }
273 }; return flag; } //awd
276 [](const AudacityProject &project){
278 }
279 }; return flag; } //awd
282 [](const AudacityProject &project){
283 const wxWindow *focus = FindProjectFrame( &project );
284 if (focus) {
285 while (focus && focus->GetParent())
286 focus = focus->GetParent();
287 }
288 return (focus &&
289 !static_cast<const wxTopLevelWindow*>(focus)->IsIconized()
290 );
291 },
293 }; return flag; } // prl
296 [](const AudacityProject&){
297 return AudioIOBase::Get()->IsPaused();
298 },
300 }; return flag; }
303 [](const AudacityProject &){ return true; }
304 }; return flag; } // jkc
305;
306
const ReservedCommandFlag & NoAutoSelect()
const CommandFlagOptions noiseReductionOptions
const ReservedCommandFlag & CaptureNotBusyFlag()
const ReservedCommandFlag & NoiseReductionTimeSelectedFlag()
const ReservedCommandFlag & AudioIOBusyFlag()
bool EditableTracksSelectedPred(const AudacityProject &project)
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & ZoomInAvailableFlag()
const ReservedCommandFlag & NotMinimizedFlag()
const ReservedCommandFlag & UndoAvailableFlag()
const ReservedCommandFlag & RedoAvailableFlag()
const ReservedCommandFlag & ZoomOutAvailableFlag()
const ReservedCommandFlag & IsSyncLockedFlag()
const ReservedCommandFlag & StereoRequiredFlag()
bool AudioIOBusyPred(const AudacityProject &project)
const ReservedCommandFlag & LabelTracksExistFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & EditableTracksSelectedFlag()
bool AnyTracksSelectedPred(const AudacityProject &project)
const ReservedCommandFlag & AnyTracksSelectedFlag()
const CommandFlagOptions & cutCopyOptions()
const ReservedCommandFlag & TracksExistFlag()
const ReservedCommandFlag & PausedFlag()
const ReservedCommandFlag & IsNotSyncLockedFlag()
const ReservedCommandFlag & WaveTracksExistFlag()
const ReservedCommandFlag & WaveTracksSelectedFlag()
const ReservedCommandFlag & TrackPanelHasFocus()
bool TimeSelectedPred(const AudacityProject &project)
XO("Cut/Copy/Paste")
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
accessors for certain important windows associated with each project
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 AudioIOBase * Get()
Definition: AudioIOBase.cpp:93
bool IsAudioTokenActive(int token) const
Returns true if the stream is active, or even if audio I/O is busy cleaning up its data or writing to...
bool IsPaused() const
Find out if playback / recording is currently paused.
static AudioIO * Get()
Definition: AudioIO.cpp:123
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:87
bool isPoint() const
Definition: ViewInfo.h:40
static ProjectAudioIO & Get(AudacityProject &project)
bool UndoAvailable() const
bool RedoAvailable() const
static ProjectHistory & Get(AudacityProject &project)
bool IsSyncLocked() const
Definition: SyncLock.cpp:43
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:123
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1091
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:354
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1108
Holds a msgid for the translation catalog; may also bind format arguments.
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:220
bool ZoomInAvailable() const
Definition: ZoomInfo.cpp:66
bool ZoomOutAvailable() const
Definition: ZoomInfo.cpp:71
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:343
CommandFlagOptions && DisableDefaultMessage() &&
Definition: CommandFlag.h:53
CommandFlagOptions && QuickTest() &&
Definition: CommandFlag.h:51