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**********************************************************************/
11
12#include "Project.h"
13#include "ProjectHistory.h"
15#include "ProjectRate.h"
16#include "ProjectSnap.h"
18#include "Snap.h"
19#include "ViewInfo.h"
20
24 return std::make_shared< ProjectSelectionManager >( project );
25 }
26};
27
30{
31 return project.AttachedObjects::Get< ProjectSelectionManager >(
33}
34
37{
38 return Get( const_cast< AudacityProject & >( project ) );
39}
40
42 : mProject { project }
43 , mSnappingChangedSubscription { ProjectSnap::Get(project).Subscribe(
44 [this](auto&)
45 {
47 })}
48 , mTimeSignatureChangedSubscription {
50 { SnapSelection(); }) }
51 , mProjectRateChangedSubscription { ProjectRate::Get(project).Subscribe(
52 [this](auto&) { SnapSelection(); }) }
53
54{
55 // Be consistent with ProjectNumericFormats
56 auto &formats = ProjectNumericFormats::Get(mProject);
57 SetSelectionFormat(formats.GetSelectionFormat());
58 SetAudioTimeFormat(formats.GetAudioTimeFormat());
59 SetFrequencySelectionFormatName(formats.GetFrequencySelectionFormatName());
60 SetBandwidthSelectionFormatName(formats.GetBandwidthSelectionFormatName());
61
62 // And stay consistent
63 mFormatsSubscription = ProjectNumericFormats::Get(project)
65}
66
68
70{
71 auto& project = mProject;
72 auto& projectSnap = ProjectSnap::Get(mProject);
73
74 if (projectSnap.GetSnapMode() == SnapMode::SNAP_OFF)
75 return;
76
77 auto& viewInfo = ViewInfo::Get(project);
78 auto& selectedRegion = viewInfo.selectedRegion;
79
80 const double oldt0 = selectedRegion.t0();
81 const double oldt1 = selectedRegion.t1();
82
83 const double t0 = projectSnap.SnapTime(oldt0).time;
84 const double t1 = projectSnap.SnapTime(oldt1).time;
85
86 if (t0 != oldt0 || t1 != oldt1)
87 selectedRegion.setTimes(t0, t1);
88}
89
91{
92 auto &formats = ProjectNumericFormats::Get(mProject);
93 switch (evt.type) {
95 return SetSelectionFormat(formats.GetSelectionFormat());
97 return SetAudioTimeFormat(formats.GetAudioTimeFormat());
100 formats.GetFrequencySelectionFormatName());
103 formats.GetBandwidthSelectionFormatName());
104 default:
105 break;
106 }
107}
108
110{
111 gPrefs->Write(wxT("/SelectionFormat"), format);
112 gPrefs->Flush();
113}
114
116{
117 gPrefs->Write(wxT("/AudioTimeFormat"), format.GET());
118 gPrefs->Flush();
119}
120
122 double &start, double &end, bool done)
123{
124 auto &project = mProject;
125 auto &history = ProjectHistory::Get( project );
126 auto &viewInfo = ViewInfo::Get( project );
127 viewInfo.selectedRegion.setTimes(start, end);
128 if (done)
129 history.ModifyState(false);
130}
131
133 const NumericFormatID &formatName)
134{
135 gPrefs->Write(wxT("/FrequencySelectionFormatName"),
136 formatName.GET());
137 gPrefs->Flush();
138}
139
141 const NumericFormatID & formatName)
142{
143 gPrefs->Write(wxT("/BandwidthSelectionFormatName"), formatName.GET());
144 gPrefs->Flush();
145}
146
148 double &bottom, double &top, bool done)
149{
150#ifdef EXPERIMENTAL_SPECTRAL_EDITING
151 auto &project = mProject;
152 auto &history = ProjectHistory::Get(project);
153 auto &viewInfo = ViewInfo::Get(project);
154 if (bottom >= 0.0)
155 bottom = std::min(nyquist, bottom);
156 if (top >= 0.0)
157 top = std::min(nyquist, top);
158 viewInfo.selectedRegion.setFrequencies(bottom, top);
159 if (done)
160 history.ModifyState(false);
161#else
162 bottom; top; done;
163#endif
164}
165
wxT("CloseDown"))
int min(int a, int b)
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
an object holding per-project preferred sample rate
static AudacityProject::AttachedObjects::RegisteredFactory sProjectSelectionManagerKey
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
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:274
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static ProjectHistory & Get(AudacityProject &project)
static ProjectNumericFormats & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
This object is useful mostly as an observer of others in the project.
~ProjectSelectionManager() override
void SetSelectionFormat(const NumericFormatID &format)
void SetBandwidthSelectionFormatName(const NumericFormatID &formatName)
void OnFormatsChanged(ProjectNumericFormatsEvent)
void SetAudioTimeFormat(const NumericFormatID &format)
ProjectSelectionManager(AudacityProject &project)
void ModifySelection(double &start, double &end, bool done)
void ModifySpectralSelection(double nyquist, double &bottom, double &top, bool done)
static ProjectSelectionManager & Get(AudacityProject &project)
void SetFrequencySelectionFormatName(const NumericFormatID &formatName)
Project snapping settings.
Definition: ProjectSnap.h:29
static ProjectSnap & Get(AudacityProject &project)
Definition: ProjectSnap.cpp:27
static ProjectTimeSignature & Get(AudacityProject &project)
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
enum ProjectNumericFormatsEvent::Type type