Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
SpectrumView::SpectralDataSaver Class Reference
Inheritance diagram for SpectrumView::SpectralDataSaver:
[legend]
Collaboration diagram for SpectrumView::SpectralDataSaver:
[legend]

Public Member Functions

 SpectralDataSaver (SpectrumView &view)
 
void Init (AudacityProject &project, bool clearAll) override
 
 ~SpectralDataSaver () override
 
- Public Member Functions inherited from BrushHandle::StateSaver
virtual ~StateSaver ()
 
virtual void Init (AudacityProject &project, bool clearAll)=0
 
void Commit ()
 

Private Attributes

SpectrumViewmView
 
AudacityProjectmpProject = nullptr
 

Additional Inherited Members

- Protected Attributes inherited from BrushHandle::StateSaver
bool mCommitted = false
 

Detailed Description

Definition at line 74 of file SpectrumView.cpp.

Constructor & Destructor Documentation

◆ SpectralDataSaver()

SpectrumView::SpectralDataSaver::SpectralDataSaver ( SpectrumView view)
inlineexplicit

Definition at line 76 of file SpectrumView.cpp.

77 : mView{ view }
78 {}

◆ ~SpectralDataSaver()

SpectrumView::SpectralDataSaver::~SpectralDataSaver ( )
inlineoverride

Definition at line 104 of file SpectrumView.cpp.

105 {
106 if (mpProject)
107 ForAll( *mpProject, [this](SpectrumView &view){
108 if (mCommitted) {
109 // Discard all backups
110 view.mpBackupSpectralData = {};
111 }
112 else {
113 // Restore all
114 if (auto &pBackupData = view.mpBackupSpectralData) {
115 view.mpSpectralData->CopyFrom(*pBackupData);
116 pBackupData.reset();
117 }
118 }
119 });
120 }
static void ForAll(AudacityProject &project, std::function< void(SpectrumView &view)> fn)
std::shared_ptr< SpectralData > mpBackupSpectralData
Definition: SpectrumView.h:148

References SpectrumView::ForAll(), BrushHandle::StateSaver::mCommitted, SpectrumView::mpBackupSpectralData, and mpProject.

Here is the call graph for this function:

Member Function Documentation

◆ Init()

void SpectrumView::SpectralDataSaver::Init ( AudacityProject project,
bool  clearAll 
)
inlineoverridevirtual

Implements BrushHandle::StateSaver.

Definition at line 80 of file SpectrumView.cpp.

81 {
83 ForAll( project, [this, clearAll](SpectrumView &view){
84 auto pOldData = view.mpSpectralData;
85 if (clearAll) {
86 auto &pNewData = view.mpBackupSpectralData =
87 std::make_shared<SpectralData>(pOldData->GetSR());
88 pNewData->CopyFrom(*pOldData);
89 pOldData->clearAllData();
90 }
91 else {
92 // Back up one view only
93 if (&mView == &view) {
94 auto &pNewData = view.mpBackupSpectralData =
95 std::make_shared<SpectralData>(pOldData->GetSR());
96 pNewData->CopyFrom( *pOldData );
97 }
98 else
99 view.mpBackupSpectralData = {};
100 }
101 });
102 }
const auto project
std::shared_ptr< SpectralData > mpSpectralData
Definition: SpectrumView.h:148

References SpectrumView::ForAll(), SpectrumView::mpBackupSpectralData, mpProject, SpectrumView::mpSpectralData, mView, and project.

Here is the call graph for this function:

Member Data Documentation

◆ mpProject

AudacityProject* SpectrumView::SpectralDataSaver::mpProject = nullptr
private

Definition at line 124 of file SpectrumView.cpp.

Referenced by Init(), and ~SpectralDataSaver().

◆ mView

SpectrumView& SpectrumView::SpectralDataSaver::mView
private

Definition at line 123 of file SpectrumView.cpp.

Referenced by Init().


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