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 "CommandManager.h"
39#include "../CommonCommandFlags.h"
40#include "LoadCommands.h"
41#include "../ProjectSelectionManager.h"
42#include "../TrackPanel.h"
43#include "SettingsVisitor.h"
44#include "ShuttleGui.h"
45#include "Track.h"
46#include "Effect.h"
47#include "ViewInfo.h"
48#include "CommandContext.h"
49
50
52{ XO("Select Time") };
53
55
56// Relative to project and relative to selection cover MOST options, since you can already
57// set a selection to a clip.
58const int nRelativeTos =6;
60{
61 { wxT("ProjectStart"), XO("Project Start") },
62 { XO("Project") },
63 { wxT("ProjectEnd"), XO("Project End") },
64 { wxT("SelectionStart"), XO("Selection Start") },
65 { XO("Selection") },
66 { wxT("SelectionEnd"), XO("Selection End") }
67};
68
69template<bool Const>
71 // Allow selection down to -ve 100seconds.
72 // Typically used to expand/contract selections by a small amount.
73 S.OptionalY( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -100.0, (double)FLT_MAX);
74 S.OptionalY( bHasT1 ).Define( mT1, wxT("End"), 0.0, -100.0, (double)FLT_MAX);
75 S.OptionalN( bHasRelativeSpec ).DefineEnum( mRelativeTo, wxT("RelativeTo"), 0, kRelativeTo, nRelativeTos );
76 return true;
77}
78
80 { return VisitSettings<false>(S); }
81
83 { return VisitSettings<true>(S); }
84
86{
87 S.AddSpace(0, 5);
88
89 S.StartMultiColumn(3, wxEXPAND);
90 {
91 S.SetStretchyCol( 2 );
92 S.Optional( bHasT0 ).TieTextBox(XXO("Start Time:"), mT0);
93 S.Optional( bHasT1 ).TieTextBox(XXO("End Time:"), mT1);
94 // Chooses what time is relative to.
95 S.Optional( bHasRelativeSpec ).TieChoice(
96 XXO("Relative To:"),
98 }
99 S.EndMultiColumn();
100}
101
103 // Many commands need focus on track panel.
104 // No harm in setting it with a scripted select.
105 TrackPanel::Get( context.project ).SetFocus();
106 if( !bHasT0 && !bHasT1 )
107 return true;
108
109 // Defaults if no value...
110 if( !bHasT0 )
111 mT0 = 0.0;
112 if( !bHasT1 )
113 mT1 = 0.0;
114 if( !bHasRelativeSpec )
115 mRelativeTo = 0;
116
117 AudacityProject * p = &context.project;
118 double end = TrackList::Get( *p ).GetEndTime();
119 double t0;
120 double t1;
121
122 auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
123 switch( bHasRelativeSpec ? mRelativeTo : 0 ){
124 default:
125 case 0: //project start
126 t0 = mT0;
127 t1 = mT1;
128 break;
129 case 1: //project
130 t0 = mT0;
131 t1 = end + mT1;
132 break;
133 case 2: //project end;
134 t0 = end - mT0;
135 t1 = end - mT1;
136 break;
137 case 3: //selection start
138 t0 = mT0 + selectedRegion.t0();
139 t1 = mT1 + selectedRegion.t0();
140 break;
141 case 4: //selection
142 t0 = mT0 + selectedRegion.t0();
143 t1 = mT1 + selectedRegion.t1();
144 break;
145 case 5: //selection end
146 t0 = selectedRegion.t1() - mT0;
147 t1 = selectedRegion.t1() - mT1;
148 break;
149 }
150
151 selectedRegion.setTimes( t0, t1 );
152 return true;
153}
154
156{ XO("Select Frequencies") };
157
159
160template<bool Const>
162 S.OptionalN( bHasTop ).Define( mTop, wxT("High"), 0.0, 0.0, (double)FLT_MAX);
163 S.OptionalN( bHasBottom ).Define( mBottom, wxT("Low"), 0.0, 0.0, (double)FLT_MAX);
164 return true;
165}
166
168 { return VisitSettings<false>(S); }
169
171 { return VisitSettings<true>(S); }
172
174{
175 S.AddSpace(0, 5);
176
177 S.StartMultiColumn(3, wxEXPAND);
178 {
179 S.SetStretchyCol( 2 );
180 S.Optional( bHasTop ).TieTextBox(XXO("High:"), mTop);
181 S.Optional( bHasBottom ).TieTextBox(XXO("Low:"), mBottom);
182 }
183 S.EndMultiColumn();
184}
185
187 if( !bHasBottom && !bHasTop )
188 return true;
189
190 // Defaults if no value...
191 if( !bHasTop )
192 mTop = 0.0;
193 if( !bHasBottom )
194 mBottom = 0.0;
195
197 mBottom, mTop, false);// false for not done.
198 return true;
199}
200
202{ XO("Select Tracks") };
203
205
206const int nModes =3;
208{
209 // These are acceptable dual purpose internal/visible names
210
211 /* i18n-hint verb, imperative */
212 { XO("Set") },
213 { XO("Add") },
214 { XO("Remove") },
215};
216
217template<bool Const>
219 S.OptionalN( bHasFirstTrack).Define( mFirstTrack, wxT("Track"), 0.0, 0.0, 100.0);
220 S.OptionalN( bHasNumTracks ).Define( mNumTracks, wxT("TrackCount"), 1.0, 0.0, 100.0);
221 S.OptionalY( bHasMode ).DefineEnum( mMode, wxT("Mode"), 0, kModes, nModes );
222
223 return true;
224}
225
227 { return VisitSettings<false>(S); }
228
230 { return VisitSettings<true>(S); }
231
233{
234 S.AddSpace(0, 5);
235
236 S.StartMultiColumn(3, wxEXPAND);
237 {
238 S.SetStretchyCol( 2 );
239 S.Optional( bHasFirstTrack).TieTextBox(XXO("First Track:"),mFirstTrack);
240 S.Optional( bHasNumTracks).TieTextBox(XXO("Track Count:"),mNumTracks);
241 }
242 S.EndMultiColumn();
243 S.StartMultiColumn(2, wxALIGN_CENTER);
244 {
245 // Always used, so no check box.
246 S.TieChoice( XXO("Mode:"), mMode, Msgids( kModes, nModes ));
247 }
248 S.EndMultiColumn();
249}
250
252{
253
254 // Count selection as a do-nothing effect.
255 // Used to invalidate cached selection and tracks.
257 int index = 0;
258 auto &tracks = TrackList::Get( context.project );
259
260 // Defaults if no value...
261 if( !bHasNumTracks )
262 mNumTracks = 1.0;
263 if( !bHasFirstTrack )
264 mFirstTrack = 0.0;
265
266 // Multiple channels count as fractions of a track.
267 double last = mFirstTrack+mNumTracks;
268 double first = mFirstTrack;
269
270 for (auto t : tracks.Leaders()) {
271 auto channels = TrackList::Channels(t);
272 double term = 0.0;
273 // Add 0.01 so we are free of rounding errors in comparisons.
274 constexpr double fudge = 0.01;
275 for (auto channel : channels) {
276 double track = index + fudge + term;
277 bool sel = first <= track && track <= last;
278 if( mMode == 0 ){ // Set
279 channel->SetSelected(sel);
280 }
281 else if( mMode == 1 && sel ){ // Add
282 channel->SetSelected(sel);
283 }
284 else if( mMode == 2 && sel ){ // Remove
285 channel->SetSelected(!sel);
286 }
287 term += 1.0 / channels.size();
288 }
289 ++index;
290 }
291 return true;
292}
293
295{ XO("Select") };
296
298
299template<bool Const>
301{
302 return
306}
307
309{
310 return VisitSettings<false>(S);
311}
312
314{
315 return VisitSettings<true>(S);
316}
317
318namespace {
319using namespace MenuTable;
320
321// Register menu items
322
324 wxT("Optional/Extra/Part2/Scriptables1"),
325 Items( wxT(""),
326 // Note that the PLUGIN_SYMBOL must have a space between words,
327 // whereas the short-form used here must not.
328 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
329 // you would have to use "CompareAudio" here.)
330 Command( wxT("SelectTime"), XXO("Select Time..."),
332 Command( wxT("SelectFrequencies"), XXO("Select Frequencies..."),
334 Command( wxT("SelectTracks"), XXO("Select Tracks..."),
336 )
337};
338
340 wxT("Optional/Extra/Part2/Scriptables2"),
341 // Note that the PLUGIN_SYMBOL must have a space between words,
342 // whereas the short-form used here must not.
343 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
344 // you would have to use "CompareAudio" here.)
345 Command( wxT("Select"), XXO("Select..."),
347};
348}
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.
#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()
Definition: Effect.h:110
static ProjectSelectionManager & Get(AudacityProject &project)
void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) override
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:625
double GetEndTime() const
Definition: Track.cpp:1053
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:487
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1544
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:231
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
std::unique_ptr< MenuItems > Items(const Identifier &internalName, Args &&... args)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
BuiltinCommandsModule::Registration< SelectTracksCommand > reg3
BuiltinCommandsModule::Registration< SelectTimeCommand > reg
BuiltinCommandsModule::Registration< SelectFrequenciesCommand > reg2
BuiltinCommandsModule::Registration< SelectCommand > reg4