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 "Project.h"
15
16wxDEFINE_EVENT( EVT_PLAY_SPEED_CHANGE, wxCommandEvent);
17
19 []( AudacityProject &parent ){
20 return std::make_shared< ProjectAudioIO >( parent );
21 }
22};
23
25{
26 return project.AttachedObjects::Get< ProjectAudioIO >( sAudioIOKey );
27}
28
30{
31 return Get( const_cast<AudacityProject &>(project) );
32}
33
35: mProject{ project }
36{
37}
38
40{
41}
42
44{
45 return mAudioIOToken;
46}
47
49{
50 mAudioIOToken = token;
51}
52
54{
55 auto gAudioIO = AudioIOBase::Get();
56 return GetAudioIOToken() > 0 &&
57 gAudioIO->IsStreamActive(GetAudioIOToken());
58}
59
60const std::shared_ptr<Meter> &ProjectAudioIO::GetPlaybackMeter() const
61{
62 return mPlaybackMeter;
63}
64
66 const std::shared_ptr<Meter> &playback)
67{
68 auto &project = mProject;
69 mPlaybackMeter = playback;
70 auto gAudioIO = AudioIOBase::Get();
71 if (gAudioIO)
72 {
73 gAudioIO->SetPlaybackMeter( project.shared_from_this() , mPlaybackMeter );
74 }
75}
76
77const std::shared_ptr<Meter> &ProjectAudioIO::GetCaptureMeter() const
78{
79 return mCaptureMeter;
80}
81
83 const std::shared_ptr<Meter> &capture)
84{
85 auto &project = mProject;
86 mCaptureMeter = capture;
87
88 auto gAudioIO = AudioIOBase::Get();
89 if (gAudioIO)
90 {
91 gAudioIO->SetCaptureMeter( project.shared_from_this(), mCaptureMeter );
92 }
93}
94
96{
97 if (auto oldValue = GetPlaySpeed(); value != oldValue) {
98 mPlaySpeed.store( value, std::memory_order_relaxed );
99 wxCommandEvent evt{ EVT_PLAY_SPEED_CHANGE };
100 mProject.ProcessEvent(evt);
101 }
102}
wxDEFINE_EVENT(EVT_PLAY_SPEED_CHANGE, wxCommandEvent)
static const AudacityProject::AttachedObjects::RegisteredFactory sAudioIOKey
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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
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)
AudacityProject & mProject
const std::shared_ptr< Meter > & GetCaptureMeter() const
void SetAudioIOToken(int token)
static ProjectAudioIO & Get(AudacityProject &project)
void SetPlaybackMeter(const std::shared_ptr< Meter > &playback)
std::shared_ptr< Meter > mCaptureMeter