Audacity 3.2.0
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
15#include "AudacityMessageBox.h"
16#include "AudioIO.h"
17#include "CommonCommandFlags.h"
18#include "Project.h"
19#include "ProjectAudioIO.h"
20#include "ProjectHistory.h"
22#include "ProjectWindows.h"
23#include "ProjectRate.h"
24#include "SelectionState.h"
25#include "SyncLock.h"
26#include "TimeDialog.h"
27#include "TrackFocus.h"
28#include "TrackPanel.h"
29#include "ViewInfo.h"
30#include "WaveTrack.h"
31
32#include "CommandManager.h"
33
34namespace {
35
36// Temporal selection (not TimeTrack selection)
37// potentially for all wave tracks.
39 AudacityProject &project, bool bAllTime, bool bAllTracks)
40{
42 auto &selectedRegion = ViewInfo::Get(project).selectedRegion;
43
44 if (bAllTime)
45 selectedRegion.setTimes(tracks.GetStartTime(), tracks.GetEndTime());
46
47 if (bAllTracks) {
48 // Unselect all tracks before selecting audio.
49 for (auto t : tracks)
50 t->SetSelected(false);
51 for (auto t : tracks.Any<WaveTrack>())
52 t->SetSelected(true);
54 }
55}
56
57}
58namespace 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(tracks.GetStartTime(), tracks.GetEndTime());
68
69 if( bAllTracks ) {
70 for (auto t : tracks)
71 t->SetSelected(true);
72
74 }
75}
76
78{
79 auto &tracks = TrackList::Get( project );
80 for (auto t : tracks)
81 t->SetSelected(false);
82
83 auto &trackPanel = TrackPanel::Get( project );
84 trackPanel.Refresh(false);
85}
86
87// Select the full time range, if no
88// time range is selected.
90{
91 auto &viewInfo = ViewInfo::Get( project );
93 if((flags & EditableTracksSelectedFlag()).none() ||
94 viewInfo.selectedRegion.isPoint())
96}
97
98// Select the full time range, if no time range is selected and
99// selecting is allowed. Returns "false" selecting not allowed.
101{
102 auto allowed = gPrefs->ReadBool(wxT("/GUI/SelectAllOnNone"), false);
103 auto &viewInfo = ViewInfo::Get( project );
105
106 if((flags & EditableTracksSelectedFlag()).none() ||
107 viewInfo.selectedRegion.isPoint()) {
108 if (!allowed) {
109 return false;
110 }
112 }
113 return true;
114}
115
117 AudacityProject &project, Track &t, bool shift, bool ctrl, bool modifyState)
118{
120 auto &selectionState = SelectionState::Get(project);
121 auto &viewInfo = ViewInfo::Get(project);
122 auto &window = GetProjectFrame(project);
123
124 auto isSyncLocked = SyncLockState::Get(project).IsSyncLocked();
125
126 selectionState.HandleListSelection(
127 tracks, viewInfo, t,
128 shift, ctrl, isSyncLocked);
129
130 if (!ctrl)
131 TrackFocus::Get(project).Set(&t);
132 window.Refresh(false);
133 if (modifyState)
135}
136
138{
139 DoSelectTimeAndTracks( project, true, true );
140}
141
143{
144 DoSelectTimeAndAudioTracks( project, true, true );
145}
146
147// This function selects all tracks if no tracks selected,
148// and all time if no time selected.
149// There is an argument for making it just count wave tracks,
150// However you could then not select a label and cut it,
151// without this function selecting all tracks.
153{
154 auto &tracks = TrackList::Get( project );
155 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
156
157 bool bTime = selectedRegion.isPoint();
158 bool bTracks = tracks.Selected().empty();
159
160 if (bTime || bTracks)
161 DoSelectTimeAndTracks(project, bTime, bTracks);
162}
163
165{
166 auto &viewInfo = ViewInfo::Get( project );
167 auto &playRegion = viewInfo.playRegion;
168 playRegion.SetActive( true );
169 if (playRegion.Empty()) {
170 auto &selectedRegion = viewInfo.selectedRegion;
171 if (!selectedRegion.isPoint())
172 playRegion.SetTimes(selectedRegion.t0(), selectedRegion.t1());
173 else
174 // Arbitrary first four seconds
175 playRegion.SetTimes(0.0, 4.0);
176 }
177
178 // Ensure the proper state of looping in the menu
180}
181
183{
184 auto &viewInfo = ViewInfo::Get( project );
185 auto &playRegion = viewInfo.playRegion;
186 auto &selectedRegion = viewInfo.selectedRegion;
187 // Set only the times that are fetched by the playback engine, but not
188 // the last-active times that are used for display.
189 playRegion.SetActive( false );
190 playRegion.SetTimes( selectedRegion.t0(), selectedRegion.t1() );
191
192 // Ensure the proper state of looping in the menu
194}
195
197{
198 auto &viewInfo = ViewInfo::Get( project );
199 auto &playRegion = viewInfo.playRegion;
200 if (playRegion.Active())
202 else
204}
205
207{
208 auto &viewInfo = ViewInfo::Get( project );
209 auto &playRegion = viewInfo.playRegion;
210 playRegion.Clear();
211
212 if (playRegion.Active())
214}
215
217{
218 auto &viewInfo = ViewInfo::Get( project );
219 auto &playRegion = viewInfo.playRegion;
220 auto &selectedRegion = viewInfo.selectedRegion;
221 playRegion.SetAllTimes( selectedRegion.t0(), selectedRegion.t1() );
222 if(!playRegion.Empty())
224}
225
227 bool left, bool selection, const TranslatableString &dialogTitle)
228{
230 auto &viewInfo = ViewInfo::Get( project );
231 auto &playRegion = viewInfo.playRegion;
232 auto &selectedRegion = viewInfo.selectedRegion;
233 const auto &formats = ProjectNumericFormats::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 = formats.GetSelectionFormat();
277
278 TimeDialog dlg(&window, dialogTitle,
279 fmt, project, getValue(), XO("Position"));
280
281 if (wxID_OK == dlg.ShowModal())
282 {
283 //Get the value from the dialog
284 setValue( std::max(0.0, dlg.GetTimeValue()) );
285 bSelChanged = true;
286 }
287 }
288
289 if (bSelChanged)
291}
292}
wxT("CloseDown"))
const ReservedCommandFlag & EditableTracksSelectedFlag()
@ none
Definition: Dither.h:20
XO("Cut/Copy/Paste")
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
an object holding per-project preferred sample rate
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 ...
accessors for certain important windows associated with each project
const auto tracks
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static AudioIO * Get()
Definition: AudioIO.cpp:126
static CommandManager & Get(AudacityProject &project)
CommandFlag GetUpdateFlags(bool quick=false) const
bool setTimes(double t0, double t1)
Definition: ViewInfo.cpp:51
bool isPoint() const
Definition: ViewInfo.h:40
int GetAudioIOToken() const
static ProjectAudioIO & Get(AudacityProject &project)
void ModifyState(bool bWantsAutoSave)
static ProjectHistory & Get(AudacityProject &project)
static ProjectNumericFormats & Get(AudacityProject &project)
static SelectionState & Get(AudacityProject &project)
bool IsSyncLocked() const
Definition: SyncLock.cpp:44
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:27
Dialog used to request a time value.
Definition: TimeDialog.h:25
const double GetTimeValue()
Definition: TimeDialog.cpp:94
Track * Get()
Definition: TrackFocus.cpp:156
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
Holds a msgid for the translation catalog; may also bind format arguments.
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
bool ReadBool(const wxString &key, bool defaultValue) const
Namespace for functions for Select menu.
void DoSelectSomething(AudacityProject &project)
void SelectNone(AudacityProject &project)
bool SelectAllIfNoneAndAllowed(AudacityProject &project)
void SetPlayRegionToSelection(AudacityProject &project)
void DoListSelection(AudacityProject &project, Track &t, bool shift, bool ctrl, bool modifyState)
void DoSelectAllAudio(AudacityProject &project)
void ActivatePlayRegion(AudacityProject &project)
void DoSelectAll(AudacityProject &project)
void OnSetRegion(AudacityProject &project, bool left, bool selection, const TranslatableString &dialogTitle)
Adjust left or right of selection or play region.
void InactivatePlayRegion(AudacityProject &project)
void SelectAllIfNone(AudacityProject &project)
void ClearPlayRegion(AudacityProject &project)
void TogglePlayRegion(AudacityProject &project)
void DoSelectTimeAndTracks(AudacityProject &project, bool bAllTime, bool bAllTracks)
void DoSelectTimeAndAudioTracks(AudacityProject &project, bool bAllTime, bool bAllTracks)