Audacity 3.2.0
SelectCommand.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2009 Audacity Team
5 License: wxwidgets
6
7 Dan Horgan
8 James Crook
9
10******************************************************************//*******************************************************************/
31
32
33#include "SelectCommand.h"
34
35#include <float.h>
36
37#include "CommandDispatch.h"
38#include "MenuRegistry.h"
39#include "../CommonCommandFlags.h"
40#include "EffectOutputTracks.h"
41#include "LoadCommands.h"
43#include "../TrackPanel.h"
44#include "SettingsVisitor.h"
45#include "ShuttleGui.h"
46#include "Track.h"
47#include "Effect.h"
48#include "ViewInfo.h"
49#include "CommandContext.h"
50#include "WaveTrack.h"
51
52
54{ XO("Select Time") };
55
57
58// Relative to project and relative to selection cover MOST options, since you can already
59// set a selection to a clip.
60const int nRelativeTos =6;
62{
63 { wxT("ProjectStart"), XO("Project Start") },
64 { XO("Project") },
65 { wxT("ProjectEnd"), XO("Project End") },
66 { wxT("SelectionStart"), XO("Selection Start") },
67 { XO("Selection") },
68 { wxT("SelectionEnd"), XO("Selection End") }
69};
70
71template<bool Const>
73 // Allow selection down to -ve 100seconds.
74 // Typically used to expand/contract selections by a small amount.
75 S.OptionalY( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -100.0, (double)FLT_MAX);
76 S.OptionalY( bHasT1 ).Define( mT1, wxT("End"), 0.0, -100.0, (double)FLT_MAX);
77 S.OptionalN( bHasRelativeSpec ).DefineEnum( mRelativeTo, wxT("RelativeTo"), 0, kRelativeTo, nRelativeTos );
78 return true;
79}
80
82 { return VisitSettings<false>(S); }
83
85 { return VisitSettings<true>(S); }
86
88{
89 S.AddSpace(0, 5);
90
91 S.StartMultiColumn(3, wxEXPAND);
92 {
93 S.SetStretchyCol( 2 );
94 S.Optional( bHasT0 ).TieTextBox(XXO("Start Time:"), mT0);
95 S.Optional( bHasT1 ).TieTextBox(XXO("End Time:"), mT1);
96 // Chooses what time is relative to.
97 S.Optional( bHasRelativeSpec ).TieChoice(
98 XXO("Relative To:"),
100 }
101 S.EndMultiColumn();
102}
103
105 // Many commands need focus on track panel.
106 // No harm in setting it with a scripted select.
107 TrackPanel::Get( context.project ).SetFocus();
108 if( !bHasT0 && !bHasT1 )
109 return true;
110
111 // Defaults if no value...
112 if( !bHasT0 )
113 mT0 = 0.0;
114 if( !bHasT1 )
115 mT1 = 0.0;
116 if( !bHasRelativeSpec )
117 mRelativeTo = 0;
118
119 AudacityProject * p = &context.project;
120 double end = TrackList::Get(*p).GetEndTime();
121 double t0;
122 double t1;
123
124 auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
125 switch( bHasRelativeSpec ? mRelativeTo : 0 ){
126 default:
127 case 0: //project start
128 t0 = mT0;
129 t1 = mT1;
130 break;
131 case 1: //project
132 t0 = mT0;
133 t1 = end + mT1;
134 break;
135 case 2: //project end;
136 t0 = end - mT0;
137 t1 = end - mT1;
138 break;
139 case 3: //selection start
140 t0 = mT0 + selectedRegion.t0();
141 t1 = mT1 + selectedRegion.t0();
142 break;
143 case 4: //selection
144 t0 = mT0 + selectedRegion.t0();
145 t1 = mT1 + selectedRegion.t1();
146 break;
147 case 5: //selection end
148 t0 = selectedRegion.t1() - mT0;
149 t1 = selectedRegion.t1() - mT1;
150 break;
151 }
152
153 selectedRegion.setTimes( t0, t1 );
154 return true;
155}
156
158{ XO("Select Frequencies") };
159
161
162template<bool Const>
164 S.OptionalN( bHasTop ).Define( mTop, wxT("High"), 0.0, 0.0, (double)FLT_MAX);
165 S.OptionalN( bHasBottom ).Define( mBottom, wxT("Low"), 0.0, 0.0, (double)FLT_MAX);
166 return true;
167}
168
170 { return VisitSettings<false>(S); }
171
173 { return VisitSettings<true>(S); }
174
176{
177 S.AddSpace(0, 5);
178
179 S.StartMultiColumn(3, wxEXPAND);
180 {
181 S.SetStretchyCol( 2 );
182 S.Optional( bHasTop ).TieTextBox(XXO("High:"), mTop);
183 S.Optional( bHasBottom ).TieTextBox(XXO("Low:"), mBottom);
184 }
185 S.EndMultiColumn();
186}
187
189 if( !bHasBottom && !bHasTop )
190 return true;
191
192 // Defaults if no value...
193 if( !bHasTop )
194 mTop = 0.0;
195 if( !bHasBottom )
196 mBottom = 0.0;
197
200 mBottom, mTop, false);// false for not done.
201 return true;
202}
203
205{ XO("Select Tracks") };
206
208
209const int nModes =3;
211{
212 // These are acceptable dual purpose internal/visible names
213
214 /* i18n-hint verb, imperative */
215 { XO("Set") },
216 { XO("Add") },
217 { XO("Remove") },
218};
219
220template<bool Const>
222 S.OptionalN( bHasFirstTrack).Define( mFirstTrack, wxT("Track"), 0.0, 0.0, 100.0);
223 S.OptionalN( bHasNumTracks ).Define( mNumTracks, wxT("TrackCount"), 1.0, 0.0, 100.0);
224 S.OptionalY( bHasMode ).DefineEnum( mMode, wxT("Mode"), 0, kModes, nModes );
225
226 return true;
227}
228
230 { return VisitSettings<false>(S); }
231
233 { return VisitSettings<true>(S); }
234
236{
237 S.AddSpace(0, 5);
238
239 S.StartMultiColumn(3, wxEXPAND);
240 {
241 S.SetStretchyCol( 2 );
242 S.Optional( bHasFirstTrack).TieTextBox(XXO("First Track:"),mFirstTrack);
243 S.Optional( bHasNumTracks).TieTextBox(XXO("Track Count:"),mNumTracks);
244 }
245 S.EndMultiColumn();
246 S.StartMultiColumn(2, wxALIGN_CENTER);
247 {
248 // Always used, so no check box.
249 S.TieChoice( XXO("Mode:"), mMode, Msgids( kModes, nModes ));
250 }
251 S.EndMultiColumn();
252}
253
255{
256
257 // Count selection as a do-nothing effect.
258 // Used to invalidate cached selection and tracks.
260 int index = 0;
261 auto &tracks = TrackList::Get( context.project );
262
263 // Defaults if no value...
264 if( !bHasNumTracks )
265 mNumTracks = 1.0;
266 if( !bHasFirstTrack )
267 mFirstTrack = 0.0;
268
269 // Multiple channels count as fractions of a track.
270 double last = mFirstTrack + mNumTracks;
271 double first = mFirstTrack;
272
273 for (auto t : tracks) {
274 const bool sel = first <= index && index < last;
275 if (mMode == 0) // Set
276 t->SetSelected(sel);
277 else if(mMode == 1 && sel) // Add
278 t->SetSelected(sel);
279 else if(mMode == 2 && sel) // Remove
280 t->SetSelected(!sel);
281 ++index;
282 }
283 return true;
284}
285
287{ XO("Select") };
288
290
291template<bool Const>
293{
294 return
298}
299
301{
302 return VisitSettings<false>(S);
303}
304
306{
307 return VisitSettings<true>(S);
308}
309
310namespace {
311using namespace MenuRegistry;
312
313// Register menu items
314
316 Items( wxT(""),
317 // Note that the PLUGIN_SYMBOL must have a space between words,
318 // whereas the short-form used here must not.
319 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
320 // you would have to use "CompareAudio" here.)
321 Command( wxT("SelectTime"), XXO("Select Time..."),
323 Command( wxT("SelectFrequencies"), XXO("Select Frequencies..."),
325 Command( wxT("SelectTracks"), XXO("Select Tracks..."),
327 ),
328 wxT("Optional/Extra/Part2/Scriptables1")
329};
330
332 // Note that the PLUGIN_SYMBOL must have a space between words,
333 // whereas the short-form used here must not.
334 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
335 // you would have to use "CompareAudio" here.)
336 Command( wxT("Select"), XXO("Select..."),
338 wxT("Optional/Extra/Part2/Scriptables2")
339};
340}
wxT("CloseDown"))
AttachedItem sAttachment1
AttachedItem sAttachment2
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
static const EnumValueSymbol kRelativeTo[nRelativeTos]
const int nRelativeTos
static const EnumValueSymbol kModes[nModes]
const int nModes
Declarations for SelectCommand and SelectCommandType classes.
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Convenience function often useful when adding choice controls.
const auto tracks
#define S(N)
Definition: ToChars.cpp:64
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
static void IncEffectCounter()
void ModifySpectralSelection(double nyquist, double &bottom, double &top, bool done)
static ProjectSelectionManager & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
bool VisitSettings(SettingsVisitorBase< Const > &S)
SelectFrequenciesCommand mSelFreq
SelectTracksCommand mSelTracks
static const ComponentInterfaceSymbol Symbol
SelectTimeCommand mSelTime
bool Apply(const CommandContext &context) override
void PopulateOrExchange(ShuttleGui &S) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
static const ComponentInterfaceSymbol Symbol
Definition: SelectCommand.h:58
bool Apply(const CommandContext &context) override
void PopulateOrExchange(ShuttleGui &S) override
static const ComponentInterfaceSymbol Symbol
Definition: SelectCommand.h:30
bool VisitSettings(SettingsVisitorBase< Const > &S)
bool VisitSettings(SettingsVisitorBase< Const > &S)
static const ComponentInterfaceSymbol Symbol
Definition: SelectCommand.h:83
bool Apply(const CommandContext &context) override
void PopulateOrExchange(ShuttleGui &S) override
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
double GetEndTime() const
Return the greatest end time of the tracks, or 0 when no tracks.
Definition: Track.cpp:784
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static double ProjectNyquistFrequency(const AudacityProject &project)
Definition: WaveTrack.cpp:356
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456
BuiltinCommandsModule::Registration< SelectTracksCommand > reg3
BuiltinCommandsModule::Registration< SelectTimeCommand > reg
BuiltinCommandsModule::Registration< SelectFrequenciesCommand > reg2
BuiltinCommandsModule::Registration< SelectCommand > reg4
const char * end(const char *str) noexcept
Definition: StringUtils.h:106