Audacity  3.0.3
ProjectAudioManager.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 ProjectAudioManager.h
6 
7 Paul 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 constexpr int RATE_NOT_SELECTED{ -1 };
22 
23 class AudacityProject;
25 class TrackList;
26 class SelectedRegion;
27 
28 class WaveTrack;
29 using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >;
30 
31 enum class PlayMode : int {
32  normalPlay,
33  oneSecondPlay, // Disables auto-scrolling
34  loopedPlay, // Disables auto-scrolling
36 };
37 
38 struct TransportTracks;
39 
40 enum StatusBarField : int;
41 
42 class AUDACITY_DLL_API ProjectAudioManager final
43  : public ClientData::Base
44  , public AudioIOListener
45  , public std::enable_shared_from_this< ProjectAudioManager >
46 {
47 public:
48  static ProjectAudioManager &Get( AudacityProject &project );
49  static const ProjectAudioManager &Get( const AudacityProject &project );
50 
51  // Find suitable tracks to record into, or return an empty array.
52  static WaveTrackArray ChooseExistingRecordingTracks(
53  AudacityProject &proj, bool selectedOnly,
54  double targetRate = RATE_NOT_SELECTED);
55 
56  static bool UseDuplex();
57 
58  static TransportTracks GetAllPlaybackTracks(
59  TrackList &trackList, bool selectedOnly,
60  bool nonWaveToo = false
61  );
62 
63  explicit ProjectAudioManager( AudacityProject &project );
67 
68  bool IsTimerRecordCancelled() { return mTimerRecordCanceled; }
69  void SetTimerRecordCancelled() { mTimerRecordCanceled = true; }
70  void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; }
71 
72  bool Paused() const { return mPaused; }
73 
74  bool Playing() const;
75 
76  // Whether recording into this project (not just into some project) is
77  // active
78  bool Recording() const;
79 
80  bool Stopping() const { return mStopping; }
81 
82  // Whether the last attempt to start recording requested appending to tracks
83  bool Appending() const { return mAppending; }
84  bool Looping() const { return mLooping; }
85  bool Cutting() const { return mCutting; }
86 
87  // A project is only allowed to stop an audio stream that it owns.
88  bool CanStopAudioStream () const;
89 
90  void OnRecord(bool altAppearance);
91 
92  bool DoRecord(AudacityProject &project,
93  const TransportTracks &transportTracks, // If captureTracks is empty, then tracks are created
94  double t0, double t1,
95  bool altAppearance,
96  const AudioIOStartStreamOptions &options);
97 
98  int PlayPlayRegion(const SelectedRegion &selectedRegion,
99  const AudioIOStartStreamOptions &options,
100  PlayMode playMode,
101  bool backwards = false,
102  // Allow t0 and t1 to be beyond end of tracks
103  bool playWhiteSpace = false);
104 
105  // Play currently selected region, or if nothing selected,
106  // play from current cursor.
107  void PlayCurrentRegion(bool looped = false, bool cutpreview = false);
108 
109  void OnPause();
110 
111  // Pause - used by AudioIO to pause sound activate recording
112  void Pause();
113 
114  // Stop playing or recording
115  void Stop(bool stopStream = true);
116 
117  void StopIfPaused();
118 
119  bool DoPlayStopSelect( bool click, bool shift );
120  void DoPlayStopSelect( );
121 
122  PlayMode GetLastPlayMode() const { return mLastPlayMode; }
123 
124 private:
125  void SetPaused( bool value ) { mPaused = value; }
126  void SetAppending( bool value ) { mAppending = value; }
127  void SetLooping( bool value ) { mLooping = value; }
128  void SetCutting( bool value ) { mCutting = value; }
129  void SetStopping( bool value ) { mStopping = value; }
130 
131  // Cancel the addition of temporary recording tracks into the project
132  void CancelRecording();
133 
134  // Audio IO callback methods
135  void OnAudioIORate(int rate) override;
136  void OnAudioIOStartRecording() override;
137  void OnAudioIOStopRecording() override;
138  void OnAudioIONewBlocks(const WaveTrackArray *tracks) override;
139  void OnCommitRecording() override;
140  void OnSoundActivationThreshold() override;
141 
142  void OnCheckpointFailure(wxCommandEvent &evt);
143 
145 
146  PlayMode mLastPlayMode{ PlayMode::normalPlay };
147 
148  //flag for cancellation of timer record.
149  bool mTimerRecordCanceled{ false };
150 
151  bool mPaused{ false };
152  bool mAppending{ false };
153  bool mLooping{ false };
154  bool mCutting{ false };
155  bool mStopping{ false };
156 
157  int mDisplayedRate{ 0 };
158  static std::pair< TranslatableStrings, unsigned >
159  StatusWidthFunction(
160  const AudacityProject &project, StatusBarField field);
161 };
162 
163 AUDACITY_DLL_API
165  AudacityProject &project, bool looped = false );
167 
169 {
170  bool allSameRate{ false };
173 };
174 
175 AUDACITY_DLL_API
177 
178 #include "commands/CommandFlag.h"
179 
180 extern AUDACITY_DLL_API const ReservedCommandFlag
182 
183 #endif
PropertiesOfSelected::allSameRate
bool allSameRate
Definition: ProjectAudioManager.h:170
WaveTrackArray
std::vector< std::shared_ptr< WaveTrack > > WaveTrackArray
Definition: AudioIO.h:48
AudioIOListener
Monitors record play start/stop and new sample blocks. Has callbacks for these events.
Definition: AudioIOListener.h:22
PlayMode::cutPreviewPlay
@ cutPreviewPlay
AudioIOListener::OnAudioIONewBlocks
virtual void OnAudioIONewBlocks(const WaveTrackArray *tracks)=0
field
#define field(n, t)
Definition: ImportAUP.cpp:167
AudioIOListener.h
PropertiesOfSelected::numberOfSelected
int numberOfSelected
Definition: ProjectAudioManager.h:172
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
PlayMode
PlayMode
Definition: ProjectAudioManager.h:31
ProjectAudioManager::SetStopping
void SetStopping(bool value)
Definition: ProjectAudioManager.h:129
ProjectAudioManager::SetCutting
void SetCutting(bool value)
Definition: ProjectAudioManager.h:128
CanStopAudioStreamFlag
AUDACITY_DLL_API const ReservedCommandFlag & CanStopAudioStreamFlag()
Definition: ProjectAudioManager.cpp:1153
ProjectAudioManager::SetAppending
void SetAppending(bool value)
Definition: ProjectAudioManager.h:126
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1280
StatusBarField
StatusBarField
Definition: ProjectStatus.h:24
ReservedCommandFlag
Definition: CommandFlag.h:89
GetPropertiesOfSelected
AUDACITY_DLL_API PropertiesOfSelected GetPropertiesOfSelected(const AudacityProject &proj)
Definition: ProjectAudioManager.cpp:1311
ProjectAudioManager::~ProjectAudioManager
~ProjectAudioManager() override
ClientData::Base
A convenient default parameter for class template Site.
Definition: ClientData.h:28
ProjectAudioManager::Cutting
bool Cutting() const
Definition: ProjectAudioManager.h:85
ClientData.h
Utility ClientData::Site to register hooks into a host class that attach client data.
AudioIOListener::OnAudioIOStartRecording
virtual void OnAudioIOStartRecording()=0
ProjectAudioManager::ProjectAudioManager
ProjectAudioManager(const ProjectAudioManager &) PROHIBITED
ProjectAudioManager::Appending
bool Appending() const
Definition: ProjectAudioManager.h:83
ProjectAudioManager::ResetTimerRecordCancelled
void ResetTimerRecordCancelled()
Definition: ProjectAudioManager.h:70
PlayMode::normalPlay
@ normalPlay
ProjectAudioManager::SetPaused
void SetPaused(bool value)
Definition: ProjectAudioManager.h:125
ProjectAudioManager::GetLastPlayMode
PlayMode GetLastPlayMode() const
Definition: ProjectAudioManager.h:122
ProjectAudioManager::IsTimerRecordCancelled
bool IsTimerRecordCancelled()
Definition: ProjectAudioManager.h:68
ProjectAudioManager::Paused
bool Paused() const
Definition: ProjectAudioManager.h:72
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
ProjectAudioManager::operator=
ProjectAudioManager & operator=(const ProjectAudioManager &) PROHIBITED
AudioIOListener::OnSoundActivationThreshold
virtual void OnSoundActivationThreshold()=0
PropertiesOfSelected
Definition: ProjectAudioManager.h:169
AudioIOListener::OnAudioIORate
virtual void OnAudioIORate(int rate)=0
ProjectAudioManager::SetLooping
void SetLooping(bool value)
Definition: ProjectAudioManager.h:127
AudioIOStartStreamOptions
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
Definition: AudioIOBase.h:44
AudioIOListener::OnCommitRecording
virtual void OnCommitRecording()=0
DefaultSpeedPlayOptions
AudioIOStartStreamOptions DefaultSpeedPlayOptions(AudacityProject &project)
Definition: ProjectAudioManager.cpp:1180
TransportTracks
Definition: AudioIO.h:64
AudioIOListener::OnAudioIOStopRecording
virtual void OnAudioIOStopRecording()=0
RATE_NOT_SELECTED
constexpr int RATE_NOT_SELECTED
Definition: ProjectAudioManager.h:21
ProjectAudioManager::SetTimerRecordCancelled
void SetTimerRecordCancelled()
Definition: ProjectAudioManager.h:69
ProjectAudioManager::mProject
AudacityProject & mProject
Definition: ProjectAudioManager.h:144
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
ProjectAudioManager
Definition: ProjectAudioManager.h:46
PlayMode::oneSecondPlay
@ oneSecondPlay
ProjectAudioManager::Stopping
bool Stopping() const
Definition: ProjectAudioManager.h:80
PlayMode::loopedPlay
@ loopedPlay
ProjectAudioManager::Looping
bool Looping() const
Definition: ProjectAudioManager.h:84
PropertiesOfSelected::rateOfSelected
int rateOfSelected
Definition: ProjectAudioManager.h:171
DefaultPlayOptions
AUDACITY_DLL_API AudioIOStartStreamOptions DefaultPlayOptions(AudacityProject &project, bool looped=false)
Definition: ProjectAudioManager.cpp:1162
CommandFlag.h
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35