Audacity 3.2.0
NumericConverterFormatterContext.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 @file NumericConverterFormatterContext.cpp
7
8 Dmitry Vedenko
9
10 **********************************************************************/
12
13#include "Project.h"
14#include "ProjectRate.h"
15
16
18 : mProject(project.weak_from_this())
19{
20}
21
23 : mProjectRate { sampleRate }
24{
25}
26
28{
29 return {};
30}
31
34{
35 return FormatterContext { project };
36}
37
39{
41}
42
44{
45}
46
48{
49 return !mProject.expired();
50}
51
52std::shared_ptr<const AudacityProject> FormatterContext::GetProject() const
53{
54 return mProject.lock();
55}
56
58{
59 return HasProject() || mProjectRate.has_value();
60}
61
62double FormatterContext::GetSampleRate(double defaultSampleRate) const
63{
64 auto project = GetProject();
65
66 if (project)
67 return ProjectRate::Get(*project).GetRate();
68
69 if (mProjectRate.has_value())
70 return *mProjectRate;
71
72 return defaultSampleRate;
73}
an object holding per-project preferred sample rate
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
A context in which formatter operates.
static FormatterContext EmptyContext()
static FormatterContext ProjectContext(const AudacityProject &project)
FormatterContext()=default
bool HasProject() const
Returns true if the reference to the project is valid at this moment.
std::optional< double > mProjectRate
static FormatterContext SampleRateContext(double sampleRate)
std::shared_ptr< const AudacityProject > GetProject() const
Returns a potentially null pointer to the project.
std::weak_ptr< const AudacityProject > mProject
double GetSampleRate(double defaultSampleRate=44100.0) const
Returns a sample rate from this context.
bool HasSampleRate() const
Returns true if it is possible to get a sample rate from this context.
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53