Audacity  3.0.3
SelectUtilities.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  SelectUtilities.cpp
6 
7  Paul Licameli split from SelectMenus.cpp
8 
9  **********************************************************************/
10 
11 #include "SelectUtilities.h"
12 
13 #include <wx/frame.h>
14 
16 #include "AudioIO.h"
17 #include "CommonCommandFlags.h"
18 #include "Menus.h"
19 #include "Project.h"
20 #include "ProjectAudioIO.h"
21 #include "ProjectHistory.h"
22 #include "ProjectWindows.h"
23 #include "ProjectRate.h"
24 #include "ProjectSettings.h"
25 #include "SelectionState.h"
26 #include "TimeDialog.h"
27 #include "TrackPanelAx.h"
28 #include "TrackPanel.h"
29 #include "ViewInfo.h"
30 #include "WaveTrack.h"
31 
32 namespace {
33 
34 // Temporal selection (not TimeTrack selection)
35 // potentially for all wave tracks.
37 (AudacityProject &project, bool bAllTime, bool bAllTracks)
38 {
39  auto &tracks = TrackList::Get( project );
40  auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
41 
42  if( bAllTime )
43  selectedRegion.setTimes(
44  tracks.GetMinOffset(), tracks.GetEndTime());
45 
46  if( bAllTracks ) {
47  // Unselect all tracks before selecting audio.
48  for (auto t : tracks.Any())
49  t->SetSelected(false);
50  for (auto t : tracks.Any<WaveTrack>())
51  t->SetSelected(true);
52 
53  ProjectHistory::Get( project ).ModifyState(false);
54  }
55 }
56 
57 }
58 namespace SelectUtilities {
59 
61 (AudacityProject &project, bool bAllTime, bool bAllTracks)
62 {
63  auto &tracks = TrackList::Get( project );
64  auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
65 
66  if( bAllTime )
67  selectedRegion.setTimes(
68  tracks.GetMinOffset(), tracks.GetEndTime());
69 
70  if( bAllTracks ) {
71  for (auto t : tracks.Any())
72  t->SetSelected(true);
73 
74  ProjectHistory::Get( project ).ModifyState(false);
75  }
76 }
77 
78 void SelectNone( AudacityProject &project )
79 {
80  auto &tracks = TrackList::Get( project );
81  for (auto t : tracks.Any())
82  t->SetSelected(false);
83 
84  auto &trackPanel = TrackPanel::Get( project );
85  trackPanel.Refresh(false);
86 }
87 
88 // Select the full time range, if no
89 // time range is selected.
91 {
92  auto &viewInfo = ViewInfo::Get( project );
93  auto flags = MenuManager::Get( project ).GetUpdateFlags();
94  if((flags & EditableTracksSelectedFlag()).none() ||
95  viewInfo.selectedRegion.isPoint())
96  DoSelectAllAudio( project );
97 }
98 
99 // Select the full time range, if no time range is selected and
100 // selecting is allowed. Returns "false" selecting not allowed.
102 {
103  auto allowed = gPrefs->ReadBool(wxT("/GUI/SelectAllOnNone"), false);
104  auto &viewInfo = ViewInfo::Get( project );
105  auto flags = MenuManager::Get( project ).GetUpdateFlags();
106 
107  if((flags & EditableTracksSelectedFlag()).none() ||
108  viewInfo.selectedRegion.isPoint()) {
109  if (!allowed) {
110  return false;
111  }
112  DoSelectAllAudio( project );
113  }
114  return true;
115 }
116 
118 (AudacityProject &project, Track *t, bool shift, bool ctrl, bool modifyState)
119 {
120  auto &tracks = TrackList::Get( project );
121  auto &selectionState = SelectionState::Get( project );
122  const auto &settings = ProjectSettings::Get( project );
123  auto &viewInfo = ViewInfo::Get( project );
124  auto &window = GetProjectFrame( project );
125 
126  auto isSyncLocked = settings.IsSyncLocked();
127 
128  selectionState.HandleListSelection(
129  tracks, viewInfo, *t,
130  shift, ctrl, isSyncLocked );
131 
132  if (! ctrl )
133  TrackFocus::Get( project ).Set( t );
134  window.Refresh(false);
135  if (modifyState)
136  ProjectHistory::Get( project ).ModifyState(true);
137 }
138 
140 {
141  DoSelectTimeAndTracks( project, true, true );
142 }
143 
145 {
146  DoSelectTimeAndAudioTracks( project, true, true );
147 }
148 
149 // This function selects all tracks if no tracks selected,
150 // and all time if no time selected.
151 // There is an argument for making it just count wave tracks,
152 // However you could then not select a label and cut it,
153 // without this function selecting all tracks.
155 {
156  auto &tracks = TrackList::Get( project );
157  auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
158 
159  bool bTime = selectedRegion.isPoint();
160  bool bTracks = tracks.Selected().empty();
161 
162  if( bTime || bTracks )
163  DoSelectTimeAndTracks( project, bTime, bTracks );
164 }
165 
167 {
168  auto &tracks = TrackList::Get( project );
169 
170  auto &viewInfo = ViewInfo::Get( project );
171  auto &playRegion = viewInfo.playRegion;
172  if (playRegion.GetStart() >= tracks.GetEndTime()) {
174  XO("Cannot lock region beyond\nend of project."),
175  XO("Error"));
176  }
177  else {
178  playRegion.SetActive( true );
179  if (playRegion.Empty()) {
180  auto &selectedRegion = viewInfo.selectedRegion;
181  if (!selectedRegion.isPoint())
182  playRegion.SetTimes(selectedRegion.t0(), selectedRegion.t1());
183  else
184  // Arbitrary first four seconds
185  playRegion.SetTimes(0.0, 4.0);
186  }
187  }
188 }
189 
191 {
192  auto &viewInfo = ViewInfo::Get( project );
193  auto &playRegion = viewInfo.playRegion;
194  auto &selectedRegion = viewInfo.selectedRegion;
195  // Set only the times that are fetched by the playback engine, but not
196  // the last-active times that are used for display.
197  playRegion.SetActive( false );
198  playRegion.SetTimes( selectedRegion.t0(), selectedRegion.t1() );
199 }
200 
202 {
203  auto &viewInfo = ViewInfo::Get( project );
204  auto &playRegion = viewInfo.playRegion;
205  if (playRegion.Active())
206  InactivatePlayRegion(project);
207  else
208  ActivatePlayRegion(project);
209 }
210 
212 {
213  auto &viewInfo = ViewInfo::Get( project );
214  auto &playRegion = viewInfo.playRegion;
215  playRegion.SetAllTimes(-1, -1);
216 }
217 
219 {
220  auto &viewInfo = ViewInfo::Get( project );
221  auto &playRegion = viewInfo.playRegion;
222  auto &selectedRegion = viewInfo.selectedRegion;
223  playRegion.SetAllTimes( selectedRegion.t0(), selectedRegion.t1() );
224 }
225 
227  bool left, bool selection, const TranslatableString &dialogTitle)
228 {
229  auto token = ProjectAudioIO::Get( project ).GetAudioIOToken();
230  auto &viewInfo = ViewInfo::Get( project );
231  auto &playRegion = viewInfo.playRegion;
232  auto &selectedRegion = viewInfo.selectedRegion;
233  const auto &settings = ProjectSettings::Get( project );
234  auto &window = GetProjectFrame( project );
235 
236  const auto getValue = [&]() -> double {
237  if (selection) {
238  if (left)
239  return selectedRegion.t0();
240  else
241  return selectedRegion.t1();
242  }
243  else {
244  if (left)
245  return playRegion.GetStart();
246  else
247  return playRegion.GetEnd();
248  }
249  };
250 
251  const auto setValue = [&](double value){
252  if (selection) {
253  if (left)
254  selectedRegion.setT0(value, false);
255  else
256  selectedRegion.setT1(value, false);
257  }
258  else {
259  if (left)
260  playRegion.SetStart(value);
261  else
262  playRegion.SetEnd(value);
263  }
264  };
265 
266  bool bSelChanged = false;
267  auto gAudioIO = AudioIO::Get();
268  if ((token > 0) && gAudioIO->IsStreamActive(token))
269  {
270  double indicator = gAudioIO->GetStreamTime();
271  setValue(indicator);
272  bSelChanged = true;
273  }
274  else
275  {
276  auto fmt = settings.GetSelectionFormat();
277  auto rate = ProjectRate::Get(project).GetRate();
278 
279  TimeDialog dlg(&window, dialogTitle,
280  fmt, rate, getValue(), XO("Position"));
281 
282  if (wxID_OK == dlg.ShowModal())
283  {
284  //Get the value from the dialog
285  setValue( std::max(0.0, dlg.GetTimeValue()) );
286  bSelChanged = true;
287  }
288  }
289 
290  if (bSelChanged)
291  ProjectHistory::Get( project ).ModifyState(false);
292 }
293 }
WaveTrack.h
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:241
SelectUtilities::ClearPlayRegion
void ClearPlayRegion(AudacityProject &project)
Definition: SelectUtilities.cpp:211
SelectUtilities::DoSelectSomething
void DoSelectSomething(AudacityProject &project)
Definition: SelectUtilities.cpp:154
ProjectAudioIO::GetAudioIOToken
int GetAudioIOToken() const
Definition: ProjectAudioIO.cpp:41
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
anonymous_namespace{SelectUtilities.cpp}::DoSelectTimeAndAudioTracks
void DoSelectTimeAndAudioTracks(AudacityProject &project, bool bAllTime, bool bAllTracks)
Definition: SelectUtilities.cpp:37
TimeDialog.h
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Definition: AudacityMessageBox.cpp:17
SelectionState.h
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
Project.h
TimeDialog::GetTimeValue
const double GetTimeValue()
Definition: TimeDialog.cpp:97
ProjectRate::Get
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:42
SelectUtilities::OnSetRegion
void OnSetRegion(AudacityProject &project, bool left, bool selection, const TranslatableString &dialogTitle)
Adjust left or right of selection or play region.
Definition: SelectUtilities.cpp:226
TrackPanel.h
TrackPanelAx.h
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
XO
#define XO(s)
Definition: Internat.h:31
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:44
SelectUtilities::SetPlayRegionToSelection
void SetPlayRegionToSelection(AudacityProject &project)
Definition: SelectUtilities.cpp:218
ProjectSettings.h
SelectUtilities::DoSelectAllAudio
void DoSelectAllAudio(AudacityProject &project)
Definition: SelectUtilities.cpp:144
ProjectAudioIO::Get
static ProjectAudioIO & Get(AudacityProject &project)
Definition: ProjectAudioIO.cpp:22
EditableTracksSelectedFlag
const ReservedCommandFlag & EditableTracksSelectedFlag()
Definition: CommonCommandFlags.cpp:180
SelectUtilities::SelectAllIfNoneAndAllowed
bool SelectAllIfNoneAndAllowed(AudacityProject &project)
Definition: SelectUtilities.cpp:101
NotifyingSelectedRegion::setTimes
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:62
TimeDialog
Dialog used to request a time value.
Definition: TimeDialog.h:24
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:229
SelectUtilities::InactivatePlayRegion
void InactivatePlayRegion(AudacityProject &project)
Definition: SelectUtilities.cpp:190
none
@ none
Definition: Dither.h:20
SelectUtilities
Namespace for functions for Select menu.
Definition: SelectUtilities.cpp:58
SelectUtilities::SelectAllIfNone
void SelectAllIfNone(AudacityProject &project)
Definition: SelectUtilities.cpp:90
SelectUtilities::ActivatePlayRegion
void ActivatePlayRegion(AudacityProject &project)
Definition: SelectUtilities.cpp:166
TrackFocus::Get
Track * Get()
Definition: TrackPanelAx.cpp:755
ProjectRate::GetRate
double GetRate() const
Definition: ProjectRate.cpp:68
ViewInfo.h
Menus.h
ProjectWindows.h
accessors for certain important windows associated with each project
SelectionState::Get
static SelectionState & Get(AudacityProject &project)
Definition: SelectionState.cpp:20
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:506
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
AudioIO.h
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
SelectUtilities::SelectNone
void SelectNone(AudacityProject &project)
Definition: SelectUtilities.cpp:78
AudacityMessageBox.h
GetProjectFrame
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
Definition: ProjectWindows.cpp:72
MenuManager::Get
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:70
ProjectHistory.h
ProjectRate.h
an object holding per-project preferred sample rate
SelectUtilities::TogglePlayRegion
void TogglePlayRegion(AudacityProject &project)
Definition: SelectUtilities.cpp:201
SelectUtilities::DoSelectAll
void DoSelectAll(AudacityProject &project)
Definition: SelectUtilities.cpp:139
NotifyingSelectedRegion::isPoint
bool isPoint() const
Definition: ViewInfo.h:52
SelectUtilities::DoSelectTimeAndTracks
void DoSelectTimeAndTracks(AudacityProject &project, bool bAllTime, bool bAllTracks)
Definition: SelectUtilities.cpp:61
SelectUtilities::DoListSelection
void DoListSelection(AudacityProject &project, Track *t, bool shift, bool ctrl, bool modifyState)
Definition: SelectUtilities.cpp:118
AudioIO::Get
static AudioIO * Get()
Definition: AudioIO.cpp:141
settings
static Settings & settings()
Definition: TrackInfo.cpp:86
CommonCommandFlags.h
SelectUtilities.h
ProjectAudioIO.h
MenuManager::GetUpdateFlags
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:545
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26