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 // Substitute the leader to satisfy precondition
126 auto pT = *tracks.Find(&t);
127 if (!pT)
128 return;
129
130 selectionState.HandleListSelection(
131 tracks, viewInfo, *pT,
132 shift, ctrl, isSyncLocked);
133
134 if (!ctrl)
135 TrackFocus::Get(project).Set(&t);
136 window.Refresh(false);
137 if (modifyState)
139}
140
142{
143 DoSelectTimeAndTracks( project, true, true );
144}
145
147{
148 DoSelectTimeAndAudioTracks( project, true, true );
149}
150
151// This function selects all tracks if no tracks selected,
152// and all time if no time selected.
153// There is an argument for making it just count wave tracks,
154// However you could then not select a label and cut it,
155// without this function selecting all tracks.
157{
158 auto &tracks = TrackList::Get( project );
159 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
160
161 bool bTime = selectedRegion.isPoint();
162 bool bTracks = tracks.Selected().empty();
163
164 if (bTime || bTracks)
165 DoSelectTimeAndTracks(project, bTime, bTracks);
166}
167
169{
170 auto &tracks = TrackList::Get( project );
171
172 auto &viewInfo = ViewInfo::Get( project );
173 auto &playRegion = viewInfo.playRegion;
174 playRegion.SetActive( true );
175 if (playRegion.Empty()) {
176 auto &selectedRegion = viewInfo.selectedRegion;
177 if (!selectedRegion.isPoint())
178 playRegion.SetTimes(selectedRegion.t0(), selectedRegion.t1());
179 else
180 // Arbitrary first four seconds
181 playRegion.SetTimes(0.0, 4.0);
182 }
183
184 // Ensure the proper state of looping in the menu
186}
187
189{
190 auto &viewInfo = ViewInfo::Get( project );
191 auto &playRegion = viewInfo.playRegion;
192 auto &selectedRegion = viewInfo.selectedRegion;
193 // Set only the times that are fetched by the playback engine, but not
194 // the last-active times that are used for display.
195 playRegion.SetActive( false );
196 playRegion.SetTimes( selectedRegion.t0(), selectedRegion.t1() );
197
198 // Ensure the proper state of looping in the menu
200}
201
203{
204 auto &viewInfo = ViewInfo::Get( project );
205 auto &playRegion = viewInfo.playRegion;
206 if (playRegion.Active())
208 else
210}
211
213{
214 auto &viewInfo = ViewInfo::Get( project );
215 auto &playRegion = viewInfo.playRegion;
216 playRegion.Clear();
217
218 if (playRegion.Active())
220}
221
223{
224 auto &viewInfo = ViewInfo::Get( project );
225 auto &playRegion = viewInfo.playRegion;
226 auto &selectedRegion = viewInfo.selectedRegion;
227 playRegion.SetAllTimes( selectedRegion.t0(), selectedRegion.t1() );
228}
229
231 bool left, bool selection, const TranslatableString &dialogTitle)
232{
234 auto &viewInfo = ViewInfo::Get( project );
235 auto &playRegion = viewInfo.playRegion;
236 auto &selectedRegion = viewInfo.selectedRegion;
237 const auto &formats = ProjectNumericFormats::Get( project );
238 auto &window = GetProjectFrame( project );
239
240 const auto getValue = [&]() -> double {
241 if (selection) {
242 if (left)
243 return selectedRegion.t0();
244 else
245 return selectedRegion.t1();
246 }
247 else {
248 if (left)
249 return playRegion.GetStart();
250 else
251 return playRegion.GetEnd();
252 }
253 };
254
255 const auto setValue = [&](double value){
256 if (selection) {
257 if (left)
258 selectedRegion.setT0(value, false);
259 else
260 selectedRegion.setT1(value, false);
261 }
262 else {
263 if (left)
264 playRegion.SetStart(value);
265 else
266 playRegion.SetEnd(value);
267 }
268 };
269
270 bool bSelChanged = false;
271 auto gAudioIO = AudioIO::Get();
272 if ((token > 0) && gAudioIO->IsStreamActive(token))
273 {
274 double indicator = gAudioIO->GetStreamTime();
275 setValue(indicator);
276 bSelChanged = true;
277 }
278 else
279 {
280 auto fmt = formats.GetSelectionFormat();
281
282 TimeDialog dlg(&window, dialogTitle,
283 fmt, project, getValue(), XO("Position"));
284
285 if (wxID_OK == dlg.ShowModal())
286 {
287 //Get the value from the dialog
288 setValue( std::max(0.0, dlg.GetTimeValue()) );
289 bSelChanged = true;
290 }
291 }
292
293 if (bSelChanged)
295}
296}
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:43
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26
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:122
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:233
Holds a msgid for the translation catalog; may also bind format arguments.
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:222
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)