Audacity  3.0.3
ProjectSelectionManager.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 ProjectSelectionManager.cpp
6 
7 Paul 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"
25 #include "toolbars/SelectionBar.h"
27 #include "toolbars/TimeToolBar.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 
121  SnapSelection();
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 
136  const NumericFormatSymbol & format)
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 
159  const NumericFormatSymbol & format)
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 
194 const NumericFormatSymbol &
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 
219 const NumericFormatSymbol &
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 }
SelectionBar::Get
static SelectionBar & Get(AudacityProject &project)
Definition: SelectionBar.cpp:137
WaveTrack.h
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:161
ProjectSelectionManager::AS_GetRate
double AS_GetRate() override
Definition: ProjectSelectionManager.cpp:89
SNAP_OFF
@ SNAP_OFF
Definition: ProjectSettings.h:29
ProjectSelectionManager.h
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
ProjectSelectionManager::TT_SetAudioTimeFormat
void TT_SetAudioTimeFormat(const NumericFormatSymbol &format) override
Definition: ProjectSelectionManager.cpp:158
ProjectSelectionManager
Definition: ProjectSelectionManager.h:26
ProjectSelectionManager::TT_GetAudioTimeFormat
const NumericFormatSymbol & TT_GetAudioTimeFormat() override
Definition: ProjectSelectionManager.cpp:151
SelectionBar.h
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
SpectralSelectionBar.h
Project.h
ProjectRate::Get
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:42
ProjectSelectionManager::AS_ModifySelection
void AS_ModifySelection(double &start, double &end, bool done) override
Definition: ProjectSelectionManager.cpp:171
ProjectSelectionManager::SSBL_GetFrequencySelectionFormatName
const NumericFormatSymbol & SSBL_GetFrequencySelectionFormatName() override
Definition: ProjectSelectionManager.cpp:195
SelectionBar::SetRate
void SetRate(double rate)
Definition: SelectionBar.cpp:720
ProjectSelectionManager::AS_SetRate
void AS_SetRate(double rate) override
Definition: ProjectSelectionManager.cpp:94
TrackPanel.h
ProjectSelectionManager::SSBL_SetFrequencySelectionFormatName
void SSBL_SetFrequencySelectionFormatName(const NumericFormatSymbol &formatName) override
Definition: ProjectSelectionManager.cpp:202
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:41
ProjectSelectionManager::SSBL_SetBandwidthSelectionFormatName
void SSBL_SetBandwidthSelectionFormatName(const NumericFormatSymbol &formatName) override
Definition: ProjectSelectionManager.cpp:227
ProjectRate::SetRate
void SetRate(double rate)
Definition: ProjectRate.cpp:73
ProjectSettings.h
ProjectWindow::Get
static ProjectWindow & Get(AudacityProject &project)
Definition: ProjectWindow.cpp:535
ProjectSelectionManager::ProjectSelectionManager
ProjectSelectionManager(AudacityProject &project)
Definition: ProjectSelectionManager.cpp:49
SpectralSelectionBar::SetFrequencySelectionFormatName
void SetFrequencySelectionFormatName(const NumericFormatSymbol &formatName)
NumericConverter::ValueToControls
virtual void ValueToControls()
Definition: NumericTextCtrl.cpp:947
ProjectSelectionManager::AS_GetSelectionFormat
const NumericFormatSymbol & AS_GetSelectionFormat() override
Definition: ProjectSelectionManager.cpp:128
ProjectSelectionManager::SnapSelection
bool SnapSelection()
Definition: ProjectSelectionManager.cpp:56
ProjectSelectionManager::SSBL_ModifySpectralSelection
void SSBL_ModifySpectralSelection(double &bottom, double &top, bool done) override
Definition: ProjectSelectionManager.cpp:244
ClientData::Site::RegisteredFactory
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ProjectSelectionManager::SSBL_GetRate
double SSBL_GetRate() const override
Definition: ProjectSelectionManager.cpp:185
sProjectSelectionManagerKey
static AudacityProject::AttachedObjects::RegisteredFactory sProjectSelectionManagerKey
Definition: ProjectSelectionManager.cpp:30
SNAP_NEAREST
@ SNAP_NEAREST
Definition: ProjectSettings.h:30
SpectralSelectionBar::SetBandwidthSelectionFormatName
void SetBandwidthSelectionFormatName(const NumericFormatSymbol &formatName)
NumericConverter::ControlsToValue
virtual void ControlsToValue()
Definition: NumericTextCtrl.cpp:1058
ProjectSelectionManager::AS_SetSnapTo
void AS_SetSnapTo(int snap) override
Definition: ProjectSelectionManager.cpp:108
ProjectSelectionManager::Get
static ProjectSelectionManager & Get(AudacityProject &project)
Definition: ProjectSelectionManager.cpp:36
Snap.h
SpectralSelectionBar::Get
static SpectralSelectionBar & Get(AudacityProject &project)
anonymous_namespace{TimeTrack.cpp}::GetRate
double GetRate()
Definition: TimeTrack.cpp:175
NumericConverter::TIME
@ TIME
Definition: NumericTextCtrl.h:52
SelectionBar::SetSelectionFormat
void SetSelectionFormat(const NumericFormatSymbol &format)
Definition: SelectionBar.cpp:707
format
int format
Definition: ExportPCM.cpp:56
ProjectSelectionManager::AS_GetSnapTo
int AS_GetSnapTo() override
Definition: ProjectSelectionManager.cpp:101
ProjectRate::GetRate
double GetRate() const
Definition: ProjectRate.cpp:68
TimeToolBar::Get
static TimeToolBar & Get(AudacityProject &project)
Definition: TimeToolBar.cpp:64
ViewInfo.h
TimeToolBar.h
ProjectWindows.h
accessors for certain important windows associated with each project
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
TimeToolBar::SetAudioTimeFormat
void SetAudioTimeFormat(const NumericFormatSymbol &format)
Definition: TimeToolBar.cpp:195
ProjectSelectionManager::~ProjectSelectionManager
~ProjectSelectionManager() override
ProjectSelectionManager::AS_SetSelectionFormat
void AS_SetSelectionFormat(const NumericFormatSymbol &format) override
Definition: ProjectSelectionManager.cpp:135
NumericConverter
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
Definition: NumericTextCtrl.h:48
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:506
TrackPanel::Refresh
void Refresh(bool eraseBackground=true, const wxRect *rect=(const wxRect *) NULL) override
Definition: TrackPanel.cpp:793
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
ProjectSelectionManager::SSBL_GetBandwidthSelectionFormatName
const NumericFormatSymbol & SSBL_GetBandwidthSelectionFormatName() override
Definition: ProjectSelectionManager.cpp:220
ComponentInterfaceSymbol::Internal
const wxString & Internal() const
Definition: ComponentInterfaceSymbol.h:55
ProjectHistory.h
ProjectRate.h
an object holding per-project preferred sample rate
ProjectSelectionManager::mProject
AudacityProject & mProject
Definition: ProjectSelectionManager.h:62
ProjectWindow.h
settings
static Settings & settings()
Definition: TrackInfo.cpp:86
NumericConverter::GetValue
double GetValue()
Definition: NumericTextCtrl.cpp:1172
SelectionBar::SetSnapTo
void SetSnapTo(int)
Definition: SelectionBar.cpp:702
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
WaveTrack::GetRate
double GetRate() const
Definition: WaveTrack.cpp:452