Audacity 3.2.0
ProjectAudioManager.h
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5ProjectAudioManager.h
6
7Paul Licameli split from ProjectManager.h
8
9**********************************************************************/
10
11#ifndef __AUDACITY_PROJECT_AUDIO_MANAGER__
12#define __AUDACITY_PROJECT_AUDIO_MANAGER__
13
14#include <memory>
15#include <vector>
16
17#include "AudioIOListener.h" // to inherit
18#include "ClientData.h" // to inherit
19#include <wx/event.h> // to declare custom event type
20
21#include <atomic>
22
23constexpr int RATE_NOT_SELECTED{ -1 };
24
25class AudacityProject;
27class TrackList;
28class SelectedRegion;
29
30class WaveTrack;
31using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >;
32
33enum class PlayMode : int {
35 oneSecondPlay, // Disables auto-scrolling
36 loopedPlay, // Possibly looped play (not always); disables auto-scrolling
38};
39
40struct TransportTracks;
41
42enum StatusBarField : int;
43
45wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
46 EVT_RECORDING_DROPOUT, RecordingDropoutEvent);
47
49struct RecordingDropoutEvent : public wxCommandEvent
50{
52 using Interval = std::pair<double, double>;
53 using Intervals = std::vector<Interval>;
54
56 : wxCommandEvent{ EVT_RECORDING_DROPOUT }
58 {}
59
61
62 wxEvent *Clone() const override {
63 // wxWidgets will own the event object
64 return safenew RecordingDropoutEvent(*this); }
65
68};
69
70class AUDACITY_DLL_API ProjectAudioManager final
71 : public ClientData::Base
72 , public AudioIOListener
73 , public std::enable_shared_from_this< ProjectAudioManager >
74{
75public:
76 static ProjectAudioManager &Get( AudacityProject &project );
77 static const ProjectAudioManager &Get( const AudacityProject &project );
78
79 // Find suitable tracks to record into, or return an empty array.
80 static WaveTrackArray ChooseExistingRecordingTracks(
81 AudacityProject &proj, bool selectedOnly,
82 double targetRate = RATE_NOT_SELECTED);
83
84 static bool UseDuplex();
85
86 static TransportTracks GetAllPlaybackTracks(
87 TrackList &trackList, bool selectedOnly,
88 bool nonWaveToo = false
89 );
90
91 explicit ProjectAudioManager( AudacityProject &project );
95
96 bool IsTimerRecordCancelled() { return mTimerRecordCanceled; }
97 void SetTimerRecordCancelled() { mTimerRecordCanceled = true; }
98 void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; }
99
100 bool Paused() const;
101
102 bool Playing() const;
103
104 // Whether recording into this project (not just into some project) is
105 // active
106 bool Recording() const;
107
108 bool Stopping() const { return mStopping; }
109
110 // Whether the last attempt to start recording requested appending to tracks
111 bool Appending() const { return mAppending; }
112 // Whether potentially looping play (using new default PlaybackPolicy)
113 bool Looping() const { return mLooping; }
114 bool Cutting() const { return mCutting; }
115
116 // A project is only allowed to stop an audio stream that it owns.
117 bool CanStopAudioStream () const;
118
119 void OnRecord(bool altAppearance);
120
121 bool DoRecord(AudacityProject &project,
122 const TransportTracks &transportTracks, // If captureTracks is empty, then tracks are created
123 double t0, double t1,
124 bool altAppearance,
125 const AudioIOStartStreamOptions &options);
126
127 int PlayPlayRegion(const SelectedRegion &selectedRegion,
128 const AudioIOStartStreamOptions &options,
129 PlayMode playMode,
130 bool backwards = false);
131
132 // Play currently selected region, or if nothing selected,
133 // play from current cursor.
134 void PlayCurrentRegion(
135 bool newDefault = false,
136 bool cutpreview = false);
137
138 void OnPause();
139
140
141 // Stop playing or recording
142 void Stop(bool stopStream = true);
143
144 void StopIfPaused();
145
146 bool DoPlayStopSelect( bool click, bool shift );
147 void DoPlayStopSelect( );
148
149 PlayMode GetLastPlayMode() const { return mLastPlayMode; }
150
151private:
152
153 void TogglePaused();
154 void SetPausedOff();
155
156 void SetAppending( bool value ) { mAppending = value; }
157 void SetLooping( bool value ) { mLooping = value; }
158 void SetCutting( bool value ) { mCutting = value; }
159 void SetStopping( bool value ) { mStopping = value; }
160
161 // Cancel the addition of temporary recording tracks into the project
162 void CancelRecording();
163
164 // Audio IO callback methods
165 void OnAudioIORate(int rate) override;
166 void OnAudioIOStartRecording() override;
167 void OnAudioIOStopRecording() override;
168 void OnAudioIONewBlocks(const WaveTrackArray *tracks) override;
169 void OnCommitRecording() override;
170 void OnSoundActivationThreshold() override;
171
172 void OnCheckpointFailure(wxCommandEvent &evt);
173
175
177
178 //flag for cancellation of timer record.
179 bool mTimerRecordCanceled{ false };
180
181 // Using int as the type for this atomic flag, allows us to toggle its value
182 // with an atomic operation.
183 std::atomic<int> mPaused{ 0 };
184
185 bool mAppending{ false };
186 bool mLooping{ false };
187 bool mCutting{ false };
188 bool mStopping{ false };
189
190 int mDisplayedRate{ 0 };
191 static std::pair< TranslatableStrings, unsigned >
192 StatusWidthFunction(
193 const AudacityProject &project, StatusBarField field);
194};
195
196AUDACITY_DLL_API
198 AudacityProject &project,
199 bool newDefault = false
201);
203
205{
206 bool allSameRate{ false };
209};
210
211AUDACITY_DLL_API
213
214#include "commands/CommandFlag.h"
215
216extern AUDACITY_DLL_API const ReservedCommandFlag
218
219#endif
std::vector< std::shared_ptr< WaveTrack > > WaveTrackArray
Definition: AudioIO.h:49
Utility ClientData::Site to register hooks into a host class that attach client data.
#define field(n, t)
Definition: ImportAUP.cpp:167
#define safenew
Definition: MemoryX.h:10
@ cutPreviewPlay
AudioIOStartStreamOptions DefaultSpeedPlayOptions(AudacityProject &project)
AUDACITY_DLL_API const ReservedCommandFlag & CanStopAudioStreamFlag()
AUDACITY_DLL_API AudioIOStartStreamOptions DefaultPlayOptions(AudacityProject &project, bool newDefault=false)
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API, EVT_RECORDING_DROPOUT, RecordingDropoutEvent)
AUDACITY_DLL_API PropertiesOfSelected GetPropertiesOfSelected(const AudacityProject &proj)
constexpr int RATE_NOT_SELECTED
StatusBarField
Definition: ProjectStatus.h:24
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
Monitors record play start/stop and new sample blocks. Has callbacks for these events.
virtual void OnAudioIORate(int rate)=0
virtual void OnSoundActivationThreshold()=0
virtual void OnAudioIOStopRecording()=0
virtual void OnAudioIONewBlocks(const WaveTrackArray *tracks)=0
virtual void OnAudioIOStartRecording()=0
virtual void OnCommitRecording()=0
AudacityProject & mProject
void SetLooping(bool value)
void SetAppending(bool value)
void SetStopping(bool value)
PlayMode GetLastPlayMode() const
ProjectAudioManager(const ProjectAudioManager &) PROHIBITED
~ProjectAudioManager() override
ProjectAudioManager & operator=(const ProjectAudioManager &) PROHIBITED
void SetCutting(bool value)
Defines a selected portion of a project.
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1330
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
Definition: AudioIOBase.h:44
A convenient default parameter for class template Site.
Definition: ClientData.h:28
Notification, posted on the project, after recording has stopped, when dropouts have been detected.
const Intervals & intervals
Disjoint and sorted increasingly.
std::pair< double, double > Interval
Start time and duration.
RecordingDropoutEvent(const Intervals &intervals)
RecordingDropoutEvent(const RecordingDropoutEvent &)=default
wxEvent * Clone() const override
std::vector< Interval > Intervals