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 "ProjectFileIO.h"
24#include "ProjectHistory.h"
25#include "ProjectSettings.h"
26#include "ProjectWindows.h"
27#include "UndoManager.h"
28#include "ViewInfo.h"
29#include "WaveTrack.h"
31
32/*
33
34This file registers functions implementing many of the tests for enabling of
35menu items. Sequence of a few of them has minor significance, but for most
36there is little reason to keep them in one file. Flags used only by one
37other file might instead be defined only where used.
38
39They are collected here because Menus.cpp is too low level to have the
40dependencies implied by the include directives above -- it would make dependency
41cycles.
42
43*/
44
45// Strong predicate excludes tracks that do not support basic editing.
47{
48 auto range = TrackList::Get( project ).Selected()
49 - []( const Track *pTrack ){
50 return !pTrack->SupportsBasicEditing(); };
51 return !range.empty();
52};
53
54// Weaker predicate.
56{
57 auto range = TrackList::Get( project ).Selected();
58 return !range.empty();
59};
60
61bool AudioIOBusyPred( const AudacityProject &project )
62{
64 ProjectAudioIO::Get( project ).GetAudioIOToken());
65};
66
67bool TimeSelectedPred( const AudacityProject &project )
68{
69 // This is equivalent to check if there is a valid selection,
70 // so it's used for Zoom to Selection too
71 return !ViewInfo::Get( project ).selectedRegion.isPoint();
72};
73
75static CommandFlagOptions result{
76// In reporting the issue with cut or copy, we don't tell the user they could also select some text in a label.
77 []( const TranslatableString &Name ) {
78 // PRL: These strings have hard-coded mention of a certain shortcut key,
79 // thus assuming the default shortcuts. That is questionable.
81#ifdef EXPERIMENTAL_DA
82 // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
83 format = XO("You must first select some audio for '%s' to act on.\n\nCtrl + A selects all audio.");
84#else
85#ifdef __WXMAC__
86 // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
87 format = XO("Select the audio for %s to use (for example, Cmd + A to Select All) then try again."
88 // No need to explain what a help button is for.
89 // "\n\nClick the Help button to learn more about selection methods."
90 );
91
92#else
93 // i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
94 format = XO("Select the audio for %s to use (for example, Ctrl + A to Select All) then try again."
95 // No need to explain what a help button is for.
96 // "\n\nClick the Help button to learn more about selection methods."
97 );
98#endif
99#endif
100 return format.Format( Name );
101 },
102 "Selecting_Audio_-_the_basics",
103 XO("No Audio Selected")
104};
105return result;
106}
107
108// Noise Reduction has a custom error message, when nothing selected.
110 []( const TranslatableString &Name ) {
111 // i18n-hint: %s will be replaced by the name of an effect, usually 'Noise Reduction'.
112 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.");
113 return format.Format( Name, Name, Name );
114 },
115 "Noise_Reduction",
116 XO("No Audio Selected")
117};
118
119
120 // The sequence of these definitions has a minor significance in determining
121 // which user error message has precedence if more than one might apply, so
122 // they should be kept in this sequence in one .cpp file if it is important
123 // to preserve that behavior. If they are dispersed to more than one file,
124 // then the precedence will be unspecified.
125 // The ordering of the flags that only disable the default message is not
126 // significant.
129 [](const AudacityProject &project ){
130 return !AudioIOBusyPred( project );
131 },
132 CommandFlagOptions{ []( const TranslatableString& ) { return
133 // This reason will not be shown, because options that require it will be greyed out.
134 XO("You can only do this when playing and recording are\nstopped. (Pausing is not sufficient.)");
135 } ,"FAQ:Errors:Audio Must Be Stopped"}
136 .QuickTest()
137 .Priority( 1 )
138 }; return flag; }//lll
141 [](const AudacityProject &project){
142 // True iff at least one stereo track is selected, i.e., at least
143 // one right channel is selected.
144 // TODO: more-than-two-channels
145 auto range = TrackList::Get( project ).Selected<const WaveTrack>()
147 return !range.empty();
148 },
149 { []( const TranslatableString& ) { return
150 // This reason will not be shown, because the stereo-to-mono is greyed out if not allowed.
151 XO("You must first select some stereo audio to perform this\naction. (You cannot use this with mono.)");
152 } ,"Audacity_Selection"}
153 }; return flag; } //lda
158 }; return flag; }
163 }; return flag; }
166 [](const AudacityProject &project){
167 return !TrackList::Get( project ).Selected<const WaveTrack>().empty();
168 },
169 { []( const TranslatableString& ) { return
170 XO("You must first select some audio to perform this action.\n(Selecting other kinds of track won't work.)");
171 } ,"Audacity_Selection"}
172 }; return flag; }
175 [](const AudacityProject &project){
176 return !TrackList::Get( project ).Any().empty();
177 },
179 }; return flag; }
183 { []( const TranslatableString &Name ){ return
184 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
185 XO("\"%s\" requires one or more tracks to be selected.").Format( Name );
186 },"Audacity_Selection" }
187 }; return flag; }
191 { []( const TranslatableString &Name ){ return
192 // i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
193 XO("\"%s\" requires one or more tracks to be selected.").Format( Name );
194 },"Audacity_Selection" }
195 }; return flag; }
198 [](const AudacityProject &project){
199 for (auto w = wxWindow::FindFocus(); w; w = w->GetParent()) {
200 if (dynamic_cast<const NonKeystrokeInterceptingWindow*>(w))
201 return true;
202 }
203 return false;
204 },
206 }; return flag; }; //lll
207
212 }; return flag; } //lll
215 [](const AudacityProject &){
216 auto gAudioIO = AudioIO::Get();
217 return !(
218 gAudioIO->IsBusy() &&
219 gAudioIO->GetNumCaptureChannels() > 0
220 );
221 }
222 }; return flag; };
223
226 [](const AudacityProject &project){
227 return !TrackList::Get( project ).Any<const LabelTrack>().empty();
228 }
229 }; return flag; }
232 [](const AudacityProject &project){
233 auto &undoManager = UndoManager::Get( project );
234 return
235 undoManager.UnsavedChanges()
236 ||
237 ProjectFileIO::Get( project ).IsModified()
238 ;
239 }
240 }; return flag; }
243 [](const AudacityProject &project){
244 return ProjectHistory::Get( project ).UndoAvailable();
245 }
246 }; return flag; }
249 [](const AudacityProject &project){
250 return ProjectHistory::Get( project ).RedoAvailable();
251 }
252 }; return flag; }
255 [](const AudacityProject &project){
256 return
257 ViewInfo::Get( project ).ZoomInAvailable()
258 &&
259 !TrackList::Get( project ).Any().empty()
260 ;
261 }
262 }; return flag; }
265 [](const AudacityProject &project){
266 return
268 &&
269 !TrackList::Get( project ).Any().empty()
270 ;
271 }
272 }; return flag; }
275 [](const AudacityProject &project){
276 return !TrackList::Get( project ).Any<const WaveTrack>().empty();
277 }
278 }; return flag; }
281 [](const AudacityProject &project){
282 return !ProjectSettings::Get( project ).IsSyncLocked();
283 }
284 }; return flag; } //awd
287 [](const AudacityProject &project){
288 return ProjectSettings::Get( project ).IsSyncLocked();
289 }
290 }; return flag; } //awd
293 [](const AudacityProject &project){
294 const wxWindow *focus = FindProjectFrame( &project );
295 if (focus) {
296 while (focus && focus->GetParent())
297 focus = focus->GetParent();
298 }
299 return (focus &&
300 !static_cast<const wxTopLevelWindow*>(focus)->IsIconized()
301 );
302 },
304 }; return flag; } // prl
307 [](const AudacityProject&){
308 return AudioIOBase::Get()->IsPaused();
309 },
311 }; return flag; }
314 [](const AudacityProject &){ return true; }
315 }; return flag; } // jkc
316;
317
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 & UnsavedChangesFlag()
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)
int format
Definition: ExportPCM.cpp:56
#define XO(s)
Definition: Internat.h:31
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
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:89
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:91
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:133
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:89
bool isPoint() const
Definition: ViewInfo.h:39
static ProjectAudioIO & Get(AudacityProject &project)
static ProjectFileIO & Get(AudacityProject &project)
bool IsModified() const
bool UndoAvailable() const
bool RedoAvailable() const
static ProjectHistory & Get(AudacityProject &project)
static ProjectSettings & Get(AudacityProject &project)
bool IsSyncLocked() const
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
bool IsLeader() const
Definition: Track.cpp:405
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1435
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1452
Holds a msgid for the translation catalog; may also bind format arguments.
static UndoManager & Get(AudacityProject &project)
Definition: UndoManager.cpp:67
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
bool ZoomInAvailable() const
Definition: ZoomInfo.cpp:72
bool ZoomOutAvailable() const
Definition: ZoomInfo.cpp:77
CommandFlagOptions && DisableDefaultMessage() &&
Definition: CommandFlag.h:54
CommandFlagOptions && QuickTest() &&
Definition: CommandFlag.h:52