Audacity 3.2.0
ProjectSelectionManager.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5ProjectSelectionManager.cpp
6
7Paul Licameli split from ProjectManager.cpp
8
9**********************************************************************/
10
12
13
14
15#include "Project.h"
16#include "ProjectHistory.h"
17#include "ProjectWindows.h"
18#include "ProjectRate.h"
19#include "ProjectSettings.h"
20#include "ProjectWindow.h"
21#include "Snap.h"
22#include "TrackPanel.h"
23#include "ViewInfo.h"
24#include "WaveTrack.h"
28
31 []( AudacityProject &project ) {
32 return std::make_shared< ProjectSelectionManager >( project );
33 }
34};
35
37 AudacityProject &project )
38{
39 return project.AttachedObjects::Get< ProjectSelectionManager >(
41}
42
44 const AudacityProject &project )
45{
46 return Get( const_cast< AudacityProject & >( project ) );
47}
48
50 : mProject{ project }
51{
52}
53
55
57{
58 auto &project = mProject;
59 auto &settings = ProjectSettings::Get( project );
60 auto &window = ProjectWindow::Get( project );
61 auto snapTo = settings.GetSnapTo();
62 if (snapTo != SNAP_OFF) {
63 auto &viewInfo = ViewInfo::Get( project );
64 auto &selectedRegion = viewInfo.selectedRegion;
66 settings.GetSelectionFormat(), 0, ProjectRate::Get(project).GetRate());
67 const bool nearest = (snapTo == SNAP_NEAREST);
68
69 const double oldt0 = selectedRegion.t0();
70 const double oldt1 = selectedRegion.t1();
71
72 nc.ValueToControls(oldt0, nearest);
73 nc.ControlsToValue();
74 const double t0 = nc.GetValue();
75
76 nc.ValueToControls(oldt1, nearest);
77 nc.ControlsToValue();
78 const double t1 = nc.GetValue();
79
80 if (t0 != oldt0 || t1 != oldt1) {
81 selectedRegion.setTimes(t0, t1);
82 return true;
83 }
84 }
85
86 return false;
87}
88
90{
92}
93
95{
96 auto &project = mProject;
97 ProjectRate::Get( project ).SetRate( rate );
98 SelectionBar::Get( project ).SetRate(rate);
99}
100
102{
103 auto &project = mProject;
104 auto &settings = ProjectSettings::Get( project );
105 return settings.GetSnapTo();
106}
107
109{
110 auto &project = mProject;
111 auto &settings = ProjectSettings::Get( project );
112 auto &window = ProjectWindow::Get( project );
113
114 settings.SetSnapTo( snap );
115
116// LLL: TODO - what should this be changed to???
117// GetCommandManager()->Check(wxT("Snap"), mSnapTo);
118 gPrefs->Write(wxT("/SnapTo"), snap);
119 gPrefs->Flush();
120
122
123 window.RedrawProject();
124
125 SelectionBar::Get( project ).SetSnapTo(snap);
126}
127
129{
130 auto &project = mProject;
131 auto &settings = ProjectSettings::Get( project );
132 return settings.GetSelectionFormat();
133}
134
137{
138 auto &project = mProject;
139 auto &settings = ProjectSettings::Get( project );
140 settings.SetSelectionFormat( format );
141
142 gPrefs->Write(wxT("/SelectionFormat"), format.Internal());
143 gPrefs->Flush();
144
145 if (SnapSelection())
146 TrackPanel::Get( project ).Refresh(false);
147
149}
150
152{
153 auto &project = mProject;
154 auto &settings = ProjectSettings::Get( project );
155 return settings.GetAudioTimeFormat();
156}
157
160{
161 auto &project = mProject;
162 auto &settings = ProjectSettings::Get( project );
163 settings.SetAudioTimeFormat( format );
164
165 gPrefs->Write(wxT("/AudioTimeFormat"), format.Internal());
166 gPrefs->Flush();
167
169}
170
172 double &start, double &end, bool done)
173{
174 auto &project = mProject;
175 auto &history = ProjectHistory::Get( project );
176 auto &trackPanel = TrackPanel::Get( project );
177 auto &viewInfo = ViewInfo::Get( project );
178 viewInfo.selectedRegion.setTimes(start, end);
179 trackPanel.Refresh(false);
180 if (done) {
181 history.ModifyState(false);
182 }
183}
184
186{
187 auto &project = mProject;
188 auto &tracks = TrackList::Get( project );
189 // Return maximum of project rate and all track rates.
190 return std::max( ProjectRate::Get( project ).GetRate(),
191 tracks.Any<const WaveTrack>().max( &WaveTrack::GetRate ) );
192}
193
196{
197 auto &project = mProject;
198 auto &settings = ProjectSettings::Get( project );
199 return settings.GetFrequencySelectionFormatName();
200}
201
203 const NumericFormatSymbol & formatName)
204{
205 auto &project = mProject;
206 auto &settings = ProjectSettings::Get( project );
207
208 settings.SetFrequencySelectionFormatName( formatName );
209
210 gPrefs->Write(wxT("/FrequencySelectionFormatName"),
211 formatName.Internal());
212 gPrefs->Flush();
213
214#ifdef EXPERIMENTAL_SPECTRAL_EDITING
216#endif
217}
218
221{
222 auto &project = mProject;
223 auto &settings = ProjectSettings::Get( project );
224 return settings.GetBandwidthSelectionFormatName();
225}
226
228 const NumericFormatSymbol & formatName)
229{
230 auto &project = mProject;
231 auto &settings = ProjectSettings::Get( project );
232
233 settings.SetBandwidthSelectionFormatName( formatName );
234
235 gPrefs->Write(wxT("/BandwidthSelectionFormatName"),
236 formatName.Internal());
237 gPrefs->Flush();
238
239#ifdef EXPERIMENTAL_SPECTRAL_EDITING
241#endif
242}
243
245 double &bottom, double &top, bool done)
246{
247#ifdef EXPERIMENTAL_SPECTRAL_EDITING
248 auto &project = mProject;
249 auto &history = ProjectHistory::Get( project );
250 auto &trackPanel = TrackPanel::Get( project );
251 auto &viewInfo = ViewInfo::Get( project );
252
253 double nyq = SSBL_GetRate() / 2.0;
254 if (bottom >= 0.0)
255 bottom = std::min(nyq, bottom);
256 if (top >= 0.0)
257 top = std::min(nyq, top);
258 viewInfo.selectedRegion.setFrequencies(bottom, top);
259 trackPanel.Refresh(false);
260 if (done) {
261 history.ModifyState(false);
262 }
263#else
264 bottom; top; done;
265#endif
266}
int min(int a, int b)
int format
Definition: ExportPCM.cpp:56
FileConfig * gPrefs
Definition: Prefs.cpp:71
an object holding per-project preferred sample rate
static AudacityProject::AttachedObjects::RegisteredFactory sProjectSelectionManagerKey
@ SNAP_NEAREST
@ SNAP_OFF
accessors for certain important windows associated with each project
static Settings & settings()
Definition: TrackInfo.cpp:87
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const wxString & Internal() const
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
virtual void ControlsToValue()
virtual void ValueToControls()
static ProjectHistory & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
void SetRate(double rate)
Definition: ProjectRate.cpp:58
double GetRate() const
Definition: ProjectRate.cpp:53
~ProjectSelectionManager() override
void TT_SetAudioTimeFormat(const NumericFormatSymbol &format) override
void AS_ModifySelection(double &start, double &end, bool done) override
void AS_SetSnapTo(int snap) override
void SSBL_SetBandwidthSelectionFormatName(const NumericFormatSymbol &formatName) override
const NumericFormatSymbol & SSBL_GetBandwidthSelectionFormatName() override
ProjectSelectionManager(AudacityProject &project)
const NumericFormatSymbol & SSBL_GetFrequencySelectionFormatName() override
const NumericFormatSymbol & AS_GetSelectionFormat() override
const NumericFormatSymbol & TT_GetAudioTimeFormat() override
static ProjectSelectionManager & Get(AudacityProject &project)
void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) override
double SSBL_GetRate() const override
void AS_SetSelectionFormat(const NumericFormatSymbol &format) override
void SSBL_SetFrequencySelectionFormatName(const NumericFormatSymbol &formatName) override
void AS_SetRate(double rate) override
static ProjectSettings & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)
void SetSelectionFormat(const NumericFormatSymbol &format)
void SetRate(double rate)
static SelectionBar & Get(AudacityProject &project)
void SetSnapTo(int)
void SetBandwidthSelectionFormatName(const NumericFormatSymbol &formatName)
static SpectralSelectionBar & Get(AudacityProject &project)
void SetFrequencySelectionFormatName(const NumericFormatSymbol &formatName)
void SetAudioTimeFormat(const NumericFormatSymbol &format)
static TimeToolBar & Get(AudacityProject &project)
Definition: TimeToolBar.cpp:65
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
void Refresh(bool eraseBackground=true, const wxRect *rect=(const wxRect *) NULL) override
Definition: TrackPanel.cpp:786
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:230
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
double GetRate() const override
Definition: WaveTrack.cpp:479
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159