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#include "Track.h"
18
19const std::function<ProjectAudioIO::OptionsFactory>
21{ return [] (AudacityProject &project, bool) {
22 auto &projectAudioIO = Get(project);
24 project.shared_from_this(), ProjectRate::Get(project).GetRate()
25 };
26 options.captureMeter = projectAudioIO.GetCaptureMeter();
27 options.playbackMeter = projectAudioIO.GetPlaybackMeter();
28 options.envelope =
30 // options.listener remains null
31 // boolean argument is ignored
32 return options;
33}; }
34
36 AudacityProject &project, bool newDefaults)
37{
38 return DefaultOptions::Call(project, newDefaults);
39}
40
42 []( AudacityProject &parent ){
43 return std::make_shared< ProjectAudioIO >( parent );
44 }
45};
46
48{
49 return project.AttachedObjects::Get< ProjectAudioIO >( sAudioIOKey );
50}
51
53{
54 return Get( const_cast<AudacityProject &>(project) );
55}
56
58: mProject{ project }
59{
60}
61
63{
64}
65
67{
68 return mAudioIOToken;
69}
70
72{
73 mAudioIOToken = token;
74}
75
77{
78 auto gAudioIO = AudioIOBase::Get();
79 return GetAudioIOToken() > 0 &&
80 gAudioIO->IsStreamActive(GetAudioIOToken());
81}
82
83const std::shared_ptr<Meter> &ProjectAudioIO::GetPlaybackMeter() const
84{
85 return mPlaybackMeter;
86}
87
89 const std::shared_ptr<Meter> &playback)
90{
91 auto &project = mProject;
92 mPlaybackMeter = playback;
93 auto gAudioIO = AudioIOBase::Get();
94 if (gAudioIO)
95 {
96 gAudioIO->SetPlaybackMeter( project.shared_from_this() , mPlaybackMeter );
97 }
98}
99
100const std::shared_ptr<Meter> &ProjectAudioIO::GetCaptureMeter() const
101{
102 return mCaptureMeter;
103}
104
106 const std::shared_ptr<Meter> &capture)
107{
108 auto &project = mProject;
109 mCaptureMeter = capture;
110
111 auto gAudioIO = AudioIOBase::Get();
112 if (gAudioIO)
113 {
114 gAudioIO->SetCaptureMeter( project.shared_from_this(), mCaptureMeter );
115 }
116}
117
119{
120 if (auto oldValue = GetPlaySpeed(); value != oldValue) {
121 mPlaySpeed.store( value, std::memory_order_relaxed );
122 Publish({});
123 }
124}
static const AudacityProject::AttachedObjects::RegisteredFactory sAudioIOKey
an object holding per-project preferred sample rate
declares abstract base class Track, TrackList, and iterators over TrackList
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:91
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
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
int GetAudioIOToken() const
ProjectAudioIO(AudacityProject &project)
static const std::function< OptionsFactory > DefaultOptionsFactory()
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 ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
Definition: AudioIOBase.h:44