Audacity  3.0.3
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 "../effects/Effect.h"
44 #include "../ViewInfo.h"
45 #include "CommandContext.h"
46 
47 
49 { XO("Select Time") };
50 
52 
53 // Relative to project and relative to selection cover MOST options, since you can already
54 // set a selection to a clip.
55 const int nRelativeTos =6;
57 {
58  { wxT("ProjectStart"), XO("Project Start") },
59  { XO("Project") },
60  { wxT("ProjectEnd"), XO("Project End") },
61  { wxT("SelectionStart"), XO("Selection Start") },
62  { XO("Selection") },
63  { wxT("SelectionEnd"), XO("Selection End") }
64 };
65 
67  // Allow selection down to -ve 100seconds.
68  // Typically used to expand/contract selections by a small amount.
69  S.OptionalY( bHasT0 ).Define( mT0, wxT("Start"), 0.0, -100.0, (double)FLT_MAX);
70  S.OptionalY( bHasT1 ).Define( mT1, wxT("End"), 0.0, -100.0, (double)FLT_MAX);
72  return true;
73 }
74 
76 {
77  S.AddSpace(0, 5);
78 
79  S.StartMultiColumn(3, wxEXPAND);
80  {
81  S.SetStretchyCol( 2 );
82  S.Optional( bHasT0 ).TieTextBox(XXO("Start Time:"), mT0);
83  S.Optional( bHasT1 ).TieTextBox(XXO("End Time:"), mT1);
84  // Chooses what time is relative to.
86  XXO("Relative To:"),
88  }
89  S.EndMultiColumn();
90 }
91 
93  // Many commands need focus on track panel.
94  // No harm in setting it with a scripted select.
95  TrackPanel::Get( context.project ).SetFocus();
96  if( !bHasT0 && !bHasT1 )
97  return true;
98 
99  // Defaults if no value...
100  if( !bHasT0 )
101  mT0 = 0.0;
102  if( !bHasT1 )
103  mT1 = 0.0;
104  if( !bHasRelativeSpec )
105  mRelativeTo = 0;
106 
107  AudacityProject * p = &context.project;
108  double end = TrackList::Get( *p ).GetEndTime();
109  double t0;
110  double t1;
111 
112  auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
113  switch( bHasRelativeSpec ? mRelativeTo : 0 ){
114  default:
115  case 0: //project start
116  t0 = mT0;
117  t1 = mT1;
118  break;
119  case 1: //project
120  t0 = mT0;
121  t1 = end + mT1;
122  break;
123  case 2: //project end;
124  t0 = end - mT0;
125  t1 = end - mT1;
126  break;
127  case 3: //selection start
128  t0 = mT0 + selectedRegion.t0();
129  t1 = mT1 + selectedRegion.t0();
130  break;
131  case 4: //selection
132  t0 = mT0 + selectedRegion.t0();
133  t1 = mT1 + selectedRegion.t1();
134  break;
135  case 5: //selection end
136  t0 = selectedRegion.t1() - mT0;
137  t1 = selectedRegion.t1() - mT1;
138  break;
139  }
140 
141  selectedRegion.setTimes( t0, t1 );
142  return true;
143 }
144 
146 { XO("Select Frequencies") };
147 
149 
151  S.OptionalN( bHasTop ).Define( mTop, wxT("High"), 0.0, 0.0, (double)FLT_MAX);
152  S.OptionalN( bHasBottom ).Define( mBottom, wxT("Low"), 0.0, 0.0, (double)FLT_MAX);
153  return true;
154 }
155 
157 {
158  S.AddSpace(0, 5);
159 
160  S.StartMultiColumn(3, wxEXPAND);
161  {
162  S.SetStretchyCol( 2 );
163  S.Optional( bHasTop ).TieTextBox(XXO("High:"), mTop);
164  S.Optional( bHasBottom ).TieTextBox(XXO("Low:"), mBottom);
165  }
166  S.EndMultiColumn();
167 }
168 
170  if( !bHasBottom && !bHasTop )
171  return true;
172 
173  // Defaults if no value...
174  if( !bHasTop )
175  mTop = 0.0;
176  if( !bHasBottom )
177  mBottom = 0.0;
178 
180  mBottom, mTop, false);// false for not done.
181  return true;
182 }
183 
185 { XO("Select Tracks") };
186 
188 
189 const int nModes =3;
191 {
192  // These are acceptable dual purpose internal/visible names
193 
194  /* i18n-hint verb, imperative */
195  { XO("Set") },
196  { XO("Add") },
197  { XO("Remove") },
198 };
199 
201  S.OptionalN( bHasFirstTrack).Define( mFirstTrack, wxT("Track"), 0.0, 0.0, 100.0);
202  S.OptionalN( bHasNumTracks ).Define( mNumTracks, wxT("TrackCount"), 1.0, 0.0, 100.0);
203  S.OptionalY( bHasMode ).DefineEnum( mMode, wxT("Mode"), 0, kModes, nModes );
204 
205  return true;
206 }
207 
209 {
210  S.AddSpace(0, 5);
211 
212  S.StartMultiColumn(3, wxEXPAND);
213  {
214  S.SetStretchyCol( 2 );
215  S.Optional( bHasFirstTrack).TieTextBox(XXO("First Track:"),mFirstTrack);
216  S.Optional( bHasNumTracks).TieTextBox(XXO("Track Count:"),mNumTracks);
217  }
218  S.EndMultiColumn();
219  S.StartMultiColumn(2, wxALIGN_CENTER);
220  {
221  // Always used, so no check box.
222  S.TieChoice( XXO("Mode:"), mMode, Msgids( kModes, nModes ));
223  }
224  S.EndMultiColumn();
225 }
226 
228 {
229 
230  // Count selection as a do-nothing effect.
231  // Used to invalidate cached selection and tracks.
233  int index = 0;
234  auto &tracks = TrackList::Get( context.project );
235 
236  // Defaults if no value...
237  if( !bHasNumTracks )
238  mNumTracks = 1.0;
239  if( !bHasFirstTrack )
240  mFirstTrack = 0.0;
241 
242  // Multiple channels count as fractions of a track.
243  double last = mFirstTrack+mNumTracks;
244  double first = mFirstTrack;
245 
246  for (auto t : tracks.Leaders()) {
247  auto channels = TrackList::Channels(t);
248  double term = 0.0;
249  // Add 0.01 so we are free of rounding errors in comparisons.
250  constexpr double fudge = 0.01;
251  for (auto channel : channels) {
252  double track = index + fudge + term;
253  bool sel = first <= track && track <= last;
254  if( mMode == 0 ){ // Set
255  channel->SetSelected(sel);
256  }
257  else if( mMode == 1 && sel ){ // Add
258  channel->SetSelected(sel);
259  }
260  else if( mMode == 2 && sel ){ // Remove
261  channel->SetSelected(!sel);
262  }
263  term += 1.0 / channels.size();
264  }
265  ++index;
266  }
267  return true;
268 }
269 
271 { XO("Select") };
272 
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:162
SelectFrequenciesCommand::Apply
bool Apply(const CommandContext &context) override
Definition: SelectCommand.cpp:169
SelectTracksCommand::mNumTracks
double mNumTracks
Definition: SelectCommand.h:95
LoadCommands.h
SelectTimeCommand::mT0
double mT0
Definition: SelectCommand.h:47
SelectTimeCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: SelectCommand.cpp:66
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1467
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2421
SelectCommand.h
Declarations for SelectCommand and SelectCommandType classes.
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:222
XO
#define XO(s)
Definition: Internat.h:32
ShuttleParams
Shuttle that deals with parameters. This is a base class with lots of virtual functions that do nothi...
Definition: Shuttle.h:61
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1212
SelectTracksCommand::mFirstTrack
double mFirstTrack
Definition: SelectCommand.h:94
SelectTimeCommand::Apply
bool Apply(const CommandContext &context) override
Definition: SelectCommand.cpp:92
Effect::IncEffectCounter
static void IncEffectCounter()
Definition: Effect.h:278
ProjectSelectionManager::SSBL_ModifySpectralSelection
void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) override
Definition: ProjectSelectionManager.cpp:247
SelectFrequenciesCommand::mTop
double mTop
Definition: SelectCommand.h:72
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterface.h:60
ShuttleParams::OptionalN
virtual ShuttleParams & OptionalN(bool &var)
Definition: Shuttle.h:71
nModes
const int nModes
Definition: SelectCommand.cpp:189
ShuttleGuiBase::TieTextBox
wxTextCtrl * TieTextBox(const TranslatableString &Caption, wxString &Value, const int nChars=0)
Definition: ShuttleGui.cpp:1626
BuiltinCommandsModule::Registration
Definition: LoadCommands.h:41
TrackList::GetEndTime
double GetEndTime() const
Definition: Track.cpp:1026
SelectTracksCommand::mMode
int mMode
Definition: SelectCommand.h:96
SelectFrequenciesCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: SelectCommand.h:56
CommandContext.h
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:199
XXO
#define XXO(s)
Definition: Internat.h:45
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:22
ProjectSelectionManager::Get
static ProjectSelectionManager & Get(AudacityProject &project)
Definition: ProjectSelectionManager.cpp:34
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1203
SelectTimeCommand::bHasT0
bool bHasT0
Definition: SelectCommand.h:40
SelectTimeCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: SelectCommand.h:30
SelectTimeCommand::bHasT1
bool bHasT1
Definition: SelectCommand.h:43
ShuttleParams::DefineEnum
virtual void DefineEnum(int &var, const wxChar *key, const int vdefault, const EnumValueSymbol strings[], size_t nStrings)
Definition: Shuttle.cpp:339
Msgids
TranslatableStrings Msgids(const EnumValueSymbol strings[], size_t nStrings)
Definition: Internat.cpp:267
SelectTracksCommand::bHasMode
bool bHasMode
Definition: SelectCommand.h:92
SelectTracksCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: SelectCommand.cpp:200
ShuttleParams::OptionalY
virtual ShuttleParams & OptionalY(bool &var)
Definition: Shuttle.h:70
SelectTracksCommand::Apply
bool Apply(const CommandContext &context) override
Definition: SelectCommand.cpp:227
kRelativeTo
static const EnumValueSymbol kRelativeTo[nRelativeTos]
Definition: SelectCommand.cpp:56
kModes
static const EnumValueSymbol kModes[nModes]
Definition: SelectCommand.cpp:190
SelectCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: SelectCommand.h:103
SelectTracksCommand::bHasFirstTrack
bool bHasFirstTrack
Definition: SelectCommand.h:88
SelectFrequenciesCommand::DefineParams
bool DefineParams(ShuttleParams &S) override
Definition: SelectCommand.cpp:150
SelectTimeCommand::mT1
double mT1
Definition: SelectCommand.h:48
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:495
SelectTimeCommand::mRelativeTo
int mRelativeTo
Definition: SelectCommand.h:49
SelectFrequenciesCommand::bHasBottom
bool bHasBottom
Definition: SelectCommand.h:66
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
anonymous_namespace{SelectCommand.cpp}::reg
BuiltinCommandsModule::Registration< SelectTimeCommand > reg
Definition: SelectCommand.cpp:51
nRelativeTos
const int nRelativeTos
Definition: SelectCommand.cpp:55
ShuttleParams::Define
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:332
anonymous_namespace{SelectCommand.cpp}::reg4
BuiltinCommandsModule::Registration< SelectCommand > reg4
Definition: SelectCommand.cpp:273
SelectFrequenciesCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: SelectCommand.cpp:156
anonymous_namespace{SelectCommand.cpp}::reg3
BuiltinCommandsModule::Registration< SelectTracksCommand > reg3
Definition: SelectCommand.cpp:187
ShuttleGui::Optional
ShuttleGui & Optional(bool &bVar)
Definition: ShuttleGui.cpp:2254
SelectTracksCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: SelectCommand.cpp:208
SelectFrequenciesCommand::mBottom
double mBottom
Definition: SelectCommand.h:71
ShuttleGuiBase::SetStretchyCol
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:195
CommandContext::project
AudacityProject & project
Definition: CommandContext.h:52
ShuttleGuiBase::TieChoice
wxChoice * TieChoice(const TranslatableString &Prompt, TranslatableString &Selected, const TranslatableStrings &choices)
Definition: ShuttleGui.cpp:1701
anonymous_namespace{SelectCommand.cpp}::reg2
BuiltinCommandsModule::Registration< SelectFrequenciesCommand > reg2
Definition: SelectCommand.cpp:148
SelectTimeCommand::bHasRelativeSpec
bool bHasRelativeSpec
Definition: SelectCommand.h:45
SelectTracksCommand::Symbol
static const ComponentInterfaceSymbol Symbol
Definition: SelectCommand.h:79
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:638
SelectTimeCommand::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S) override
Definition: SelectCommand.cpp:75
SelectFrequenciesCommand::bHasTop
bool bHasTop
Definition: SelectCommand.h:69
SelectTracksCommand::bHasNumTracks
bool bHasNumTracks
Definition: SelectCommand.h:91