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 "Menus.h"
19#include "Project.h"
20#include "ProjectAudioIO.h"
21#include "ProjectHistory.h"
23#include "ProjectWindows.h"
24#include "ProjectRate.h"
25#include "ProjectSettings.h"
26#include "SelectionState.h"
27#include "SyncLock.h"
28#include "TimeDialog.h"
29#include "TrackPanelAx.h"
30#include "TrackPanel.h"
31#include "ViewInfo.h"
32#include "WaveTrack.h"
33
35
36namespace {
37
38// Temporal selection (not TimeTrack selection)
39// potentially for all wave tracks.
41(AudacityProject &project, bool bAllTime, bool bAllTracks)
42{
43 auto &tracks = TrackList::Get( project );
44 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
45
46 if( bAllTime )
47 selectedRegion.setTimes(
48 tracks.GetMinOffset(), tracks.GetEndTime());
49
50 if( bAllTracks ) {
51 // Unselect all tracks before selecting audio.
52 for (auto t : tracks.Leaders())
53 t->SetSelected(false);
54 for (auto t : tracks.Leaders<WaveTrack>())
55 t->SetSelected(true);
56
57 ProjectHistory::Get( project ).ModifyState(false);
58 }
59}
60
61}
62namespace SelectUtilities {
63
65(AudacityProject &project, bool bAllTime, bool bAllTracks)
66{
67 auto &tracks = TrackList::Get( project );
68 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
69
70 if( bAllTime )
71 selectedRegion.setTimes(
72 tracks.GetMinOffset(), tracks.GetEndTime());
73
74 if( bAllTracks ) {
75 for (auto t : tracks.Leaders())
76 t->SetSelected(true);
77
78 ProjectHistory::Get( project ).ModifyState(false);
79 }
80}
81
83{
84 auto &tracks = TrackList::Get( project );
85 for (auto t : tracks.Leaders())
86 t->SetSelected(false);
87
88 auto &trackPanel = TrackPanel::Get( project );
89 trackPanel.Refresh(false);
90}
91
92// Select the full time range, if no
93// time range is selected.
95{
96 auto &viewInfo = ViewInfo::Get( project );
97 auto flags = MenuManager::Get( project ).GetUpdateFlags();
98 if((flags & EditableTracksSelectedFlag()).none() ||
99 viewInfo.selectedRegion.isPoint())
100 DoSelectAllAudio( project );
101}
102
103// Select the full time range, if no time range is selected and
104// selecting is allowed. Returns "false" selecting not allowed.
106{
107 auto allowed = gPrefs->ReadBool(wxT("/GUI/SelectAllOnNone"), false);
108 auto &viewInfo = ViewInfo::Get( project );
109 auto flags = MenuManager::Get( project ).GetUpdateFlags();
110
111 if((flags & EditableTracksSelectedFlag()).none() ||
112 viewInfo.selectedRegion.isPoint()) {
113 if (!allowed) {
114 return false;
115 }
116 DoSelectAllAudio( project );
117 }
118 return true;
119}
120
122(AudacityProject &project, Track *t, bool shift, bool ctrl, bool modifyState)
123{
124 auto &tracks = TrackList::Get( project );
125 auto &selectionState = SelectionState::Get( project );
126 auto &viewInfo = ViewInfo::Get( project );
127 auto &window = GetProjectFrame( project );
128
129 auto isSyncLocked = SyncLockState::Get(project).IsSyncLocked();
130
131 selectionState.HandleListSelection(
132 tracks, viewInfo, *t,
133 shift, ctrl, isSyncLocked );
134
135 if (! ctrl )
136 TrackFocus::Get( project ).Set( t );
137 window.Refresh(false);
138 if (modifyState)
139 ProjectHistory::Get( project ).ModifyState(true);
140}
141
143{
144 DoSelectTimeAndTracks( project, true, true );
145}
146
148{
149 DoSelectTimeAndAudioTracks( project, true, true );
150}
151
152// This function selects all tracks if no tracks selected,
153// and all time if no time selected.
154// There is an argument for making it just count wave tracks,
155// However you could then not select a label and cut it,
156// without this function selecting all tracks.
158{
159 auto &tracks = TrackList::Get( project );
160 auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
161
162 bool bTime = selectedRegion.isPoint();
163 bool bTracks = tracks.Selected().empty();
164
165 if( bTime || bTracks )
166 DoSelectTimeAndTracks( project, bTime, bTracks );
167}
168
170{
171 auto &tracks = TrackList::Get( project );
172
173 auto &viewInfo = ViewInfo::Get( project );
174 auto &playRegion = viewInfo.playRegion;
175 playRegion.SetActive( true );
176 if (playRegion.Empty()) {
177 auto &selectedRegion = viewInfo.selectedRegion;
178 if (!selectedRegion.isPoint())
179 playRegion.SetTimes(selectedRegion.t0(), selectedRegion.t1());
180 else
181 // Arbitrary first four seconds
182 playRegion.SetTimes(0.0, 4.0);
183 }
184
185 // Ensure the proper state of looping in the menu
186 CommandManager::Get( project ).UpdateCheckmarks( project );
187}
188
190{
191 auto &viewInfo = ViewInfo::Get( project );
192 auto &playRegion = viewInfo.playRegion;
193 auto &selectedRegion = viewInfo.selectedRegion;
194 // Set only the times that are fetched by the playback engine, but not
195 // the last-active times that are used for display.
196 playRegion.SetActive( false );
197 playRegion.SetTimes( selectedRegion.t0(), selectedRegion.t1() );
198
199 // Ensure the proper state of looping in the menu
200 CommandManager::Get( project ).UpdateCheckmarks( project );
201}
202
204{
205 auto &viewInfo = ViewInfo::Get( project );
206 auto &playRegion = viewInfo.playRegion;
207 if (playRegion.Active())
208 InactivatePlayRegion(project);
209 else
210 ActivatePlayRegion(project);
211}
212
214{
215 auto &viewInfo = ViewInfo::Get( project );
216 auto &playRegion = viewInfo.playRegion;
217 playRegion.Clear();
218}
219
221{
222 auto &viewInfo = ViewInfo::Get( project );
223 auto &playRegion = viewInfo.playRegion;
224 auto &selectedRegion = viewInfo.selectedRegion;
225 playRegion.SetAllTimes( selectedRegion.t0(), selectedRegion.t1() );
226}
227
229 bool left, bool selection, const TranslatableString &dialogTitle)
230{
231 auto token = ProjectAudioIO::Get( project ).GetAudioIOToken();
232 auto &viewInfo = ViewInfo::Get( project );
233 auto &playRegion = viewInfo.playRegion;
234 auto &selectedRegion = viewInfo.selectedRegion;
235 const auto &formats = ProjectNumericFormats::Get( project );
236 auto &window = GetProjectFrame( project );
237
238 const auto getValue = [&]() -> double {
239 if (selection) {
240 if (left)
241 return selectedRegion.t0();
242 else
243 return selectedRegion.t1();
244 }
245 else {
246 if (left)
247 return playRegion.GetStart();
248 else
249 return playRegion.GetEnd();
250 }
251 };
252
253 const auto setValue = [&](double value){
254 if (selection) {
255 if (left)
256 selectedRegion.setT0(value, false);
257 else
258 selectedRegion.setT1(value, false);
259 }
260 else {
261 if (left)
262 playRegion.SetStart(value);
263 else
264 playRegion.SetEnd(value);
265 }
266 };
267
268 bool bSelChanged = false;
269 auto gAudioIO = AudioIO::Get();
270 if ((token > 0) && gAudioIO->IsStreamActive(token))
271 {
272 double indicator = gAudioIO->GetStreamTime();
273 setValue(indicator);
274 bSelChanged = true;
275 }
276 else
277 {
278 auto fmt = formats.GetSelectionFormat();
279
280 TimeDialog dlg(&window, dialogTitle,
281 fmt, project, getValue(), XO("Position"));
282
283 if (wxID_OK == dlg.ShowModal())
284 {
285 //Get the value from the dialog
286 setValue( std::max(0.0, dlg.GetTimeValue()) );
287 bSelChanged = true;
288 }
289 }
290
291 if (bSelChanged)
292 ProjectHistory::Get( project ).ModifyState(false);
293}
294}
wxT("CloseDown"))
const ReservedCommandFlag & EditableTracksSelectedFlag()
@ none
Definition: Dither.h:20
XO("Cut/Copy/Paste")
FileConfig * gPrefs
Definition: Prefs.cpp:70
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
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
void UpdateCheckmarks(AudacityProject &project)
static CommandManager & Get(AudacityProject &project)
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:539
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()
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:162
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:385
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:231
Holds a msgid for the translation catalog; may also bind format arguments.
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
Namespace for functions for Select menu.
void DoListSelection(AudacityProject &project, Track *t, bool shift, bool ctrl, bool modifyState)
void DoSelectSomething(AudacityProject &project)
void SelectNone(AudacityProject &project)
bool SelectAllIfNoneAndAllowed(AudacityProject &project)
void SetPlayRegionToSelection(AudacityProject &project)
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)