Audacity 3.2.0
ProjectAudioIO.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5ProjectAudioIO.cpp
6
7Paul Licameli split from AudacityProject.cpp
8
9**********************************************************************/
10
11#include "ProjectAudioIO.h"
12
13#include "AudioIOBase.h"
14#include "Mix.h"
15#include "Project.h"
16#include "ProjectRate.h"
17
20{
21 auto &projectAudioIO = Get(project);
23 project.shared_from_this(), ProjectRate::Get(project).GetRate()
24 };
25 options.captureMeter = projectAudioIO.GetCaptureMeter();
26 options.playbackMeter = projectAudioIO.GetPlaybackMeter();
27 options.envelope =
29 // options.listener remains null
30 // boolean argument is ignored
31 return options;
32}
33
35 AudacityProject &project, bool newDefaults)
36{
37 return DefaultOptions::Call(project, newDefaults);
38}
39
41 []( AudacityProject &parent ){
42 return std::make_shared< ProjectAudioIO >( parent );
43 }
44};
45
47{
48 return project.AttachedObjects::Get< ProjectAudioIO >( sAudioIOKey );
49}
50
52{
53 return Get( const_cast<AudacityProject &>(project) );
54}
55
57: mProject{ project }
58{
59}
60
62{
63}
64
66{
67 return mAudioIOToken;
68}
69
71{
72 mAudioIOToken = token;
73}
74
76{
77 auto gAudioIO = AudioIOBase::Get();
78 return GetAudioIOToken() > 0 &&
79 gAudioIO->IsStreamActive(GetAudioIOToken());
80}
81
82const std::shared_ptr<Meter> &ProjectAudioIO::GetPlaybackMeter() const
83{
84 return mPlaybackMeter;
85}
86
88 const std::shared_ptr<Meter> &playback)
89{
90 auto &project = mProject;
91 mPlaybackMeter = playback;
92 auto gAudioIO = AudioIOBase::Get();
93 if (gAudioIO)
94 {
95 gAudioIO->SetPlaybackMeter( project.shared_from_this() , mPlaybackMeter );
96 }
97}
98
99const std::shared_ptr<Meter> &ProjectAudioIO::GetCaptureMeter() const
100{
101 return mCaptureMeter;
102}
103
105 const std::shared_ptr<Meter> &capture)
106{
107 auto &project = mProject;
108 mCaptureMeter = capture;
109
110 auto gAudioIO = AudioIOBase::Get();
111 if (gAudioIO)
112 {
113 gAudioIO->SetCaptureMeter( project.shared_from_this(), mCaptureMeter );
114 }
115}
116
118{
119 if (auto oldValue = GetPlaySpeed(); value != oldValue) {
120 mPlaySpeed.store( value, std::memory_order_relaxed );
121 Publish({});
122 }
123}
static const AudacityProject::AttachedObjects::RegisteredFactory sAudioIOKey
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
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:94
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:275
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
CallbackReturn Publish(const SpeedChangeMessage &message)
Send a message to connected callbacks.
Definition: Observer.h:207
bool IsAudioActive() const
void SetCaptureMeter(const std::shared_ptr< Meter > &capture)
std::shared_ptr< Meter > mPlaybackMeter
const std::shared_ptr< Meter > & GetPlaybackMeter() const
double GetPlaySpeed() const
void SetPlaySpeed(double value)
std::atomic< double > mPlaySpeed
static AudioIOStartStreamOptions DefaultOptionsFactory(AudacityProject &project, bool newDefaults)
Default factory function ignores the second argument.
int GetAudioIOToken() const
ProjectAudioIO(AudacityProject &project)
AudacityProject & mProject
const std::shared_ptr< Meter > & GetCaptureMeter() const
void SetAudioIOToken(int token)
static AudioIOStartStreamOptions GetDefaultOptions(AudacityProject &project, bool newDefaults=false)
Invoke the global hook, supplying a default argument.
static ProjectAudioIO & Get(AudacityProject &project)
void SetPlaybackMeter(const std::shared_ptr< Meter > &playback)
std::shared_ptr< Meter > mCaptureMeter
static const ProjectAudioIO & Get(const AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
Definition: AudioIOBase.h:46