Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
ProjectSelectionManager Class Referencefinal

This object is useful mostly as an observer of others in the project. More...

#include <ProjectSelectionManager.h>

Inheritance diagram for ProjectSelectionManager:
[legend]
Collaboration diagram for ProjectSelectionManager:
[legend]

Public Member Functions

 ProjectSelectionManager (AudacityProject &project)
 
 ProjectSelectionManager (const ProjectSelectionManager &)=delete
 
ProjectSelectionManageroperator= (const ProjectSelectionManager &)=delete
 
 ~ProjectSelectionManager () override
 
void ModifySelection (double &start, double &end, bool done)
 
void ModifySpectralSelection (double nyquist, double &bottom, double &top, bool done)
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 

Static Public Member Functions

static ProjectSelectionManagerGet (AudacityProject &project)
 
static const ProjectSelectionManagerGet (const AudacityProject &project)
 

Private Member Functions

void OnFormatsChanged (ProjectNumericFormatsEvent)
 
void SetSelectionFormat (const NumericFormatID &format)
 
void SetAudioTimeFormat (const NumericFormatID &format)
 
void SetFrequencySelectionFormatName (const NumericFormatID &formatName)
 
void SetBandwidthSelectionFormatName (const NumericFormatID &formatName)
 
void SnapSelection ()
 

Private Attributes

Observer::Subscription mFormatsSubscription
 
AudacityProjectmProject
 
Observer::Subscription mSnappingChangedSubscription
 
Observer::Subscription mTimeSignatureChangedSubscription
 
Observer::Subscription mProjectRateChangedSubscription
 

Detailed Description

This object is useful mostly as an observer of others in the project.

It listens for changes of selection formats and snap-to choices, and reacts by updating persistent preferences, and updating the time selection to be consistent with those choices.

Definition at line 28 of file ProjectSelectionManager.h.

Constructor & Destructor Documentation

◆ ProjectSelectionManager() [1/2]

ProjectSelectionManager::ProjectSelectionManager ( AudacityProject project)
explicit

Definition at line 41 of file ProjectSelectionManager.cpp.

42 : mProject { project }
44 [this](auto&)
45 {
47 })}
50 { SnapSelection(); }) }
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
65}
const auto project
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static ProjectNumericFormats & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
void SetSelectionFormat(const NumericFormatID &format)
void SetBandwidthSelectionFormatName(const NumericFormatID &formatName)
void OnFormatsChanged(ProjectNumericFormatsEvent)
void SetAudioTimeFormat(const NumericFormatID &format)
Observer::Subscription mSnappingChangedSubscription
Observer::Subscription mProjectRateChangedSubscription
Observer::Subscription mFormatsSubscription
Observer::Subscription mTimeSignatureChangedSubscription
void SetFrequencySelectionFormatName(const NumericFormatID &formatName)
static ProjectSnap & Get(AudacityProject &project)
Definition: ProjectSnap.cpp:27
static ProjectTimeSignature & Get(AudacityProject &project)

References SnapSelection().

Here is the call graph for this function:

◆ ProjectSelectionManager() [2/2]

ProjectSelectionManager::ProjectSelectionManager ( const ProjectSelectionManager )
delete

◆ ~ProjectSelectionManager()

ProjectSelectionManager::~ProjectSelectionManager ( )
overridedefault

Member Function Documentation

◆ Get() [1/2]

ProjectSelectionManager & ProjectSelectionManager::Get ( AudacityProject project)
static

Definition at line 28 of file ProjectSelectionManager.cpp.

30{
31 return project.AttachedObjects::Get< ProjectSelectionManager >(
33}
static AudacityProject::AttachedObjects::RegisteredFactory sProjectSelectionManagerKey
This object is useful mostly as an observer of others in the project.

References project, and sProjectSelectionManagerKey.

Referenced by SelectFrequenciesCommand::Apply(), Get(), and SelectionBar::ModifySelection().

Here is the caller graph for this function:

◆ Get() [2/2]

const ProjectSelectionManager & ProjectSelectionManager::Get ( const AudacityProject project)
static

Definition at line 35 of file ProjectSelectionManager.cpp.

37{
38 return Get( const_cast< AudacityProject & >( project ) );
39}
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 ProjectSelectionManager & Get(AudacityProject &project)

References Get(), and project.

Here is the call graph for this function:

◆ ModifySelection()

void ProjectSelectionManager::ModifySelection ( double &  start,
double &  end,
bool  done 
)

Definition at line 121 of file ProjectSelectionManager.cpp.

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}
static ProjectHistory & Get(AudacityProject &project)
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References PackedArray::end(), ProjectHistory::Get(), ViewInfo::Get(), mProject, and project.

Here is the call graph for this function:

◆ ModifySpectralSelection()

void ProjectSelectionManager::ModifySpectralSelection ( double  nyquist,
double &  bottom,
double &  top,
bool  done 
)

Definition at line 147 of file ProjectSelectionManager.cpp.

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}
int min(int a, int b)

References ProjectHistory::Get(), ViewInfo::Get(), min(), mProject, and project.

Referenced by SelectFrequenciesCommand::Apply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnFormatsChanged()

void ProjectSelectionManager::OnFormatsChanged ( ProjectNumericFormatsEvent  evt)
private

Definition at line 90 of file ProjectSelectionManager.cpp.

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}
enum ProjectNumericFormatsEvent::Type type

References ProjectNumericFormatsEvent::ChangedAudioTimeFormat, ProjectNumericFormatsEvent::ChangedBandwidthFormat, ProjectNumericFormatsEvent::ChangedFrequencyFormat, ProjectNumericFormatsEvent::ChangedSelectionFormat, ProjectNumericFormats::Get(), mProject, SetAudioTimeFormat(), SetBandwidthSelectionFormatName(), SetFrequencySelectionFormatName(), SetSelectionFormat(), and ProjectNumericFormatsEvent::type.

Here is the call graph for this function:

◆ operator=()

ProjectSelectionManager & ProjectSelectionManager::operator= ( const ProjectSelectionManager )
delete

◆ SetAudioTimeFormat()

void ProjectSelectionManager::SetAudioTimeFormat ( const NumericFormatID format)
private

Definition at line 115 of file ProjectSelectionManager.cpp.

116{
117 gPrefs->Write(wxT("/AudioTimeFormat"), format.GET());
118 gPrefs->Flush();
119}
wxT("CloseDown"))
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0

References audacity::BasicSettings::Flush(), anonymous_namespace{ExportPCM.cpp}::format, gPrefs, audacity::BasicSettings::Write(), and wxT().

Referenced by OnFormatsChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetBandwidthSelectionFormatName()

void ProjectSelectionManager::SetBandwidthSelectionFormatName ( const NumericFormatID formatName)
private

Definition at line 140 of file ProjectSelectionManager.cpp.

142{
143 gPrefs->Write(wxT("/BandwidthSelectionFormatName"), formatName.GET());
144 gPrefs->Flush();
145}
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

References audacity::BasicSettings::Flush(), Identifier::GET(), gPrefs, audacity::BasicSettings::Write(), and wxT().

Referenced by OnFormatsChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFrequencySelectionFormatName()

void ProjectSelectionManager::SetFrequencySelectionFormatName ( const NumericFormatID formatName)
private

Definition at line 132 of file ProjectSelectionManager.cpp.

134{
135 gPrefs->Write(wxT("/FrequencySelectionFormatName"),
136 formatName.GET());
137 gPrefs->Flush();
138}

References audacity::BasicSettings::Flush(), Identifier::GET(), gPrefs, audacity::BasicSettings::Write(), and wxT().

Referenced by OnFormatsChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSelectionFormat()

void ProjectSelectionManager::SetSelectionFormat ( const NumericFormatID format)
private

Definition at line 109 of file ProjectSelectionManager.cpp.

110{
111 gPrefs->Write(wxT("/SelectionFormat"), format);
112 gPrefs->Flush();
113}

References audacity::BasicSettings::Flush(), anonymous_namespace{ExportPCM.cpp}::format, gPrefs, audacity::BasicSettings::Write(), and wxT().

Referenced by OnFormatsChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SnapSelection()

void ProjectSelectionManager::SnapSelection ( )
private

Definition at line 69 of file ProjectSelectionManager.cpp.

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}

References ProjectSnap::Get(), ViewInfo::Get(), mProject, project, and SNAP_OFF.

Referenced by ProjectSelectionManager().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mFormatsSubscription

Observer::Subscription ProjectSelectionManager::mFormatsSubscription
private

Definition at line 57 of file ProjectSelectionManager.h.

◆ mProject

AudacityProject& ProjectSelectionManager::mProject
private

◆ mProjectRateChangedSubscription

Observer::Subscription ProjectSelectionManager::mProjectRateChangedSubscription
private

Definition at line 62 of file ProjectSelectionManager.h.

◆ mSnappingChangedSubscription

Observer::Subscription ProjectSelectionManager::mSnappingChangedSubscription
private

Definition at line 60 of file ProjectSelectionManager.h.

◆ mTimeSignatureChangedSubscription

Observer::Subscription ProjectSelectionManager::mTimeSignatureChangedSubscription
private

Definition at line 61 of file ProjectSelectionManager.h.


The documentation for this class was generated from the following files: