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 <wx/string.h>
36#include <float.h>
37
38#include "LoadCommands.h"
39#include "../ProjectSelectionManager.h"
40#include "../TrackPanel.h"
41#include "../Shuttle.h"
42#include "../ShuttleGui.h"
43#include "Track.h"
44#include "../effects/Effect.h"
45#include "ViewInfo.h"
46#include "CommandContext.h"
47
48
50{ XO("Select Time") };
51
53
54// Relative to project and relative to selection cover MOST options, since you can already
55// set a selection to a clip.
56const int nRelativeTos =6;
58{
59 { wxT("ProjectStart"), XO("Project Start") },
60 { XO("Project") },
61 { wxT("ProjectEnd"), XO("Project End") },
62 { wxT("SelectionStart"), XO("Selection Start") },
63 { XO("Selection") },
64 { wxT("SelectionEnd"), XO("Selection End") }
65};
66
67template<bool Const>
69 // Allow selection down to -ve 100seconds.
70 // Typically used to expand/contract selections by a small amount.
71 S.OptionalY( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -100.0, (double)FLT_MAX);
72 S.OptionalY( bHasT1 ).Define( mT1, wxT("End"), 0.0, -100.0, (double)FLT_MAX);
73 S.OptionalN( bHasRelativeSpec ).DefineEnum( mRelativeTo, wxT("RelativeTo"), 0, kRelativeTo, nRelativeTos );
74 return true;
75}
76
78 { return VisitSettings<false>(S); }
79
81 { return VisitSettings<true>(S); }
82
84{
85 S.AddSpace(0, 5);
86
87 S.StartMultiColumn(3, wxEXPAND);
88 {
89 S.SetStretchyCol( 2 );
90 S.Optional( bHasT0 ).TieTextBox(XXO("Start Time:"), mT0);
91 S.Optional( bHasT1 ).TieTextBox(XXO("End Time:"), mT1);
92 // Chooses what time is relative to.
93 S.Optional( bHasRelativeSpec ).TieChoice(
94 XXO("Relative To:"),
96 }
97 S.EndMultiColumn();
98}
99
101 // Many commands need focus on track panel.
102 // No harm in setting it with a scripted select.
103 TrackPanel::Get( context.project ).SetFocus();
104 if( !bHasT0 && !bHasT1 )
105 return true;
106
107 // Defaults if no value...
108 if( !bHasT0 )
109 mT0 = 0.0;
110 if( !bHasT1 )
111 mT1 = 0.0;
112 if( !bHasRelativeSpec )
113 mRelativeTo = 0;
114
115 AudacityProject * p = &context.project;
116 double end = TrackList::Get( *p ).GetEndTime();
117 double t0;
118 double t1;
119
120 auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
121 switch( bHasRelativeSpec ? mRelativeTo : 0 ){
122 default:
123 case 0: //project start
124 t0 = mT0;
125 t1 = mT1;
126 break;
127 case 1: //project
128 t0 = mT0;
129 t1 = end + mT1;
130 break;
131 case 2: //project end;
132 t0 = end - mT0;
133 t1 = end - mT1;
134 break;
135 case 3: //selection start
136 t0 = mT0 + selectedRegion.t0();
137 t1 = mT1 + selectedRegion.t0();
138 break;
139 case 4: //selection
140 t0 = mT0 + selectedRegion.t0();
141 t1 = mT1 + selectedRegion.t1();
142 break;
143 case 5: //selection end
144 t0 = selectedRegion.t1() - mT0;
145 t1 = selectedRegion.t1() - mT1;
146 break;
147 }
148
149 selectedRegion.setTimes( t0, t1 );
150 return true;
151}
152
154{ XO("Select Frequencies") };
155
157
158template<bool Const>
160 S.OptionalN( bHasTop ).Define( mTop, wxT("High"), 0.0, 0.0, (double)FLT_MAX);
161 S.OptionalN( bHasBottom ).Define( mBottom, wxT("Low"), 0.0, 0.0, (double)FLT_MAX);
162 return true;
163}
164
166 { return VisitSettings<false>(S); }
167
169 { return VisitSettings<true>(S); }
170
172{
173 S.AddSpace(0, 5);
174
175 S.StartMultiColumn(3, wxEXPAND);
176 {
177 S.SetStretchyCol( 2 );
178 S.Optional( bHasTop ).TieTextBox(XXO("High:"), mTop);
179 S.Optional( bHasBottom ).TieTextBox(XXO("Low:"), mBottom);
180 }
181 S.EndMultiColumn();
182}
183
185 if( !bHasBottom && !bHasTop )
186 return true;
187
188 // Defaults if no value...
189 if( !bHasTop )
190 mTop = 0.0;
191 if( !bHasBottom )
192 mBottom = 0.0;
193
195 mBottom, mTop, false);// false for not done.
196 return true;
197}
198
200{ XO("Select Tracks") };
201
203
204const int nModes =3;
206{
207 // These are acceptable dual purpose internal/visible names
208
209 /* i18n-hint verb, imperative */
210 { XO("Set") },
211 { XO("Add") },
212 { XO("Remove") },
213};
214
215template<bool Const>
217 S.OptionalN( bHasFirstTrack).Define( mFirstTrack, wxT("Track"), 0.0, 0.0, 100.0);
218 S.OptionalN( bHasNumTracks ).Define( mNumTracks, wxT("TrackCount"), 1.0, 0.0, 100.0);
219 S.OptionalY( bHasMode ).DefineEnum( mMode, wxT("Mode"), 0, kModes, nModes );
220
221 return true;
222}
223
225 { return VisitSettings<false>(S); }
226
228 { return VisitSettings<true>(S); }
229
231{
232 S.AddSpace(0, 5);
233
234 S.StartMultiColumn(3, wxEXPAND);
235 {
236 S.SetStretchyCol( 2 );
237 S.Optional( bHasFirstTrack).TieTextBox(XXO("First Track:"),mFirstTrack);
238 S.Optional( bHasNumTracks).TieTextBox(XXO("Track Count:"),mNumTracks);
239 }
240 S.EndMultiColumn();
241 S.StartMultiColumn(2, wxALIGN_CENTER);
242 {
243 // Always used, so no check box.
244 S.TieChoice( XXO("Mode:"), mMode, Msgids( kModes, nModes ));
245 }
246 S.EndMultiColumn();
247}
248
250{
251
252 // Count selection as a do-nothing effect.
253 // Used to invalidate cached selection and tracks.
255 int index = 0;
256 auto &tracks = TrackList::Get( context.project );
257
258 // Defaults if no value...
259 if( !bHasNumTracks )
260 mNumTracks = 1.0;
261 if( !bHasFirstTrack )
262 mFirstTrack = 0.0;
263
264 // Multiple channels count as fractions of a track.
265 double last = mFirstTrack+mNumTracks;
266 double first = mFirstTrack;
267
268 for (auto t : tracks.Leaders()) {
269 auto channels = TrackList::Channels(t);
270 double term = 0.0;
271 // Add 0.01 so we are free of rounding errors in comparisons.
272 constexpr double fudge = 0.01;
273 for (auto channel : channels) {
274 double track = index + fudge + term;
275 bool sel = first <= track && track <= last;
276 if( mMode == 0 ){ // Set
277 channel->SetSelected(sel);
278 }
279 else if( mMode == 1 && sel ){ // Add
280 channel->SetSelected(sel);
281 }
282 else if( mMode == 2 && sel ){ // Remove
283 channel->SetSelected(!sel);
284 }
285 term += 1.0 / channels.size();
286 }
287 ++index;
288 }
289 return true;
290}
291
293{ XO("Select") };
294
296
297template<bool Const>
299{
300 return
304}
305
307{
308 return VisitSettings<false>(S);
309}
310
312{
313 return VisitSettings<true>(S);
314}
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
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:89
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:145
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 ...
Definition: Shuttle.h:115
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
double GetEndTime() const
Definition: Track.cpp:1048
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1539
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:230
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
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