Audacity 3.2.0
ProjectRate.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3Audacity: A Digital Audio Editor
4
5@file ProjectRate.cpp
6
7Paul Licameli split from ProjectSettings.cpp
8
9**********************************************************************/
10
11#include "ProjectRate.h"
12
13#include "AudioIOBase.h"
14#include "Prefs.h"
15#include "Project.h"
16#include "QualitySettings.h"
17#include "XMLWriter.h"
19
23 auto result = std::make_shared< ProjectRate >(project);
24 return result;
25 }
26};
27
29{
30 return project.AttachedObjects::Get< ProjectRate >( sKey );
31}
32
34{
35 return Get( const_cast< AudacityProject & >( project ) );
36}
37
39{
40 int intRate = 0;
41 bool wasDefined = QualitySettings::DefaultSampleRate.Read( &intRate );
42 mRate = intRate;
43 if ( !wasDefined ) {
44 // The default given above can vary with host/devices. So unless there is
45 // an entry for the default sample rate in audacity.cfg, Audacity can open
46 // with a rate which is different from the rate with which it closed.
47 // See bug 1879.
49 gPrefs->Flush();
50 }
51}
52
54{
55 return mRate;
56}
57
58void ProjectRate::SetRate(double rate)
59{
60 if (rate != mRate) {
61 mRate = rate;
62 Publish(rate);
63 }
64}
65
67[](const AudacityProject &project, XMLWriter &xmlFile){
68 xmlFile.WriteAttr(wxT("rate"), ProjectRate::Get(project).GetRate());
69}
70};
71
73// Just a pointer to function, but needing overload resolution as non-const:
75 { "rate", [](auto &settings, auto value){
76 double rate = value.Get(settings.GetRate());
77 settings.SetRate( rate );
78 } },
79} };
wxT("CloseDown"))
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
static const AudacityProject::AttachedObjects::RegisteredFactory sKey
Definition: ProjectRate.cpp:21
static ProjectFileIORegistry::AttributeWriterEntry entry
Definition: ProjectRate.cpp:66
static ProjectFileIORegistry::AttributeReaderEntries entries
Definition: ProjectRate.cpp:72
an object holding per-project preferred sample rate
const auto project
static Settings & settings()
Definition: TrackInfo.cpp:51
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:275
CallbackReturn Publish(const double &message)
Send a message to connected callbacks.
Definition: Observer.h:207
Holds project sample rate.
Definition: ProjectRate.h:24
ProjectRate(AudacityProject &project)
Definition: ProjectRate.cpp:38
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
void SetRate(double rate)
Definition: ProjectRate.cpp:58
double GetRate() const
Definition: ProjectRate.cpp:53
double mRate
Definition: ProjectRate.h:37
bool Write(const T &value)
Write value to config and return true if successful.
Definition: Prefs.h:259
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:207
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
virtual bool Flush() noexcept=0
PROJECT_RATE_API IntSetting DefaultSampleRate
Typically statically constructed.