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, bool useMidi = false);
60 
61  explicit ProjectAudioManager( AudacityProject &project );
65 
66  bool IsTimerRecordCancelled() { return mTimerRecordCanceled; }
67  void SetTimerRecordCancelled() { mTimerRecordCanceled = true; }
68  void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; }
69 
70  bool Paused() const { return mPaused; }
71 
72  bool Playing() const;
73 
74  // Whether recording into this project (not just into some project) is
75  // active
76  bool Recording() const;
77 
78  bool Stopping() const { return mStopping; }
79 
80  // Whether the last attempt to start recording requested appending to tracks
81  bool Appending() const { return mAppending; }
82  bool Looping() const { return mLooping; }
83  bool Cutting() const { return mCutting; }
84 
85  // A project is only allowed to stop an audio stream that it owns.
86  bool CanStopAudioStream () const;
87 
88  void OnRecord(bool altAppearance);
89 
90  bool DoRecord(AudacityProject &project,
91  const TransportTracks &transportTracks, // If captureTracks is empty, then tracks are created
92  double t0, double t1,
93  bool altAppearance,
94  const AudioIOStartStreamOptions &options);
95 
96  int PlayPlayRegion(const SelectedRegion &selectedRegion,
97  const AudioIOStartStreamOptions &options,
98  PlayMode playMode,
99  bool backwards = false,
100  // Allow t0 and t1 to be beyond end of tracks
101  bool playWhiteSpace = false);
102 
103  // Play currently selected region, or if nothing selected,
104  // play from current cursor.
105  void PlayCurrentRegion(bool looped = false, bool cutpreview = false);
106 
107  void OnPause();
108 
109  // Pause - used by AudioIO to pause sound activate recording
110  void Pause();
111 
112  // Stop playing or recording
113  void Stop(bool stopStream = true);
114 
115  void StopIfPaused();
116 
117  bool DoPlayStopSelect( bool click, bool shift );
118  void DoPlayStopSelect( );
119 
120  PlayMode GetLastPlayMode() const { return mLastPlayMode; }
121 
122 private:
123  void SetPaused( bool value ) { mPaused = value; }
124  void SetAppending( bool value ) { mAppending = value; }
125  void SetLooping( bool value ) { mLooping = value; }
126  void SetCutting( bool value ) { mCutting = value; }
127  void SetStopping( bool value ) { mStopping = value; }
128 
129  void SetupCutPreviewTracks(double playStart, double cutStart,
130  double cutEnd, double playEnd);
131  void ClearCutPreviewTracks();
132 
133  // Cancel the addition of temporary recording tracks into the project
134  void CancelRecording();
135 
136  // Audio IO callback methods
137  void OnAudioIORate(int rate) override;
138  void OnAudioIOStartRecording() override;
139  void OnAudioIOStopRecording() override;
140  void OnAudioIONewBlocks(const WaveTrackArray *tracks) override;
141  void OnCommitRecording() override;
142  void OnSoundActivationThreshold() override;
143 
144  void OnCheckpointFailure(wxCommandEvent &evt);
145 
147 
148  std::shared_ptr<TrackList> mCutPreviewTracks;
149 
150  PlayMode mLastPlayMode{ PlayMode::normalPlay };
151 
152  //flag for cancellation of timer record.
153  bool mTimerRecordCanceled{ false };
154 
155  bool mPaused{ false };
156  bool mAppending{ false };
157  bool mLooping{ false };
158  bool mCutting{ false };
159  bool mStopping{ false };
160 
161  int mDisplayedRate{ 0 };
162  static std::pair< TranslatableStrings, unsigned >
163  StatusWidthFunction(
164  const AudacityProject &project, StatusBarField field);
165 };
166 
167 AUDACITY_DLL_API
169 AUDACITY_DLL_API
171 
173 {
174  bool allSameRate{ false };
177 };
178 
179 AUDACITY_DLL_API
181 
182 #include "commands/CommandFlag.h"
183 
184 extern AUDACITY_DLL_API const ReservedCommandFlag
186 
187 #endif
PropertiesOfSelected::allSameRate
bool allSameRate
Definition: ProjectAudioManager.h:174
WaveTrackArray
std::vector< std::shared_ptr< WaveTrack > > WaveTrackArray
Definition: AudioIO.h:58
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:166
AudioIOListener.h
PropertiesOfSelected::numberOfSelected
int numberOfSelected
Definition: ProjectAudioManager.h:176
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:127
ProjectAudioManager::SetCutting
void SetCutting(bool value)
Definition: ProjectAudioManager.h:126
CanStopAudioStreamFlag
AUDACITY_DLL_API const ReservedCommandFlag & CanStopAudioStreamFlag()
Definition: ProjectAudioManager.cpp:991
ProjectAudioManager::SetAppending
void SetAppending(bool value)
Definition: ProjectAudioManager.h:124
TrackList
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1264
StatusBarField
StatusBarField
Definition: ProjectStatus.h:24
ReservedCommandFlag
Definition: CommandFlag.h:89
GetPropertiesOfSelected
AUDACITY_DLL_API PropertiesOfSelected GetPropertiesOfSelected(const AudacityProject &proj)
Definition: ProjectAudioManager.cpp:1153
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:83
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:81
ProjectAudioManager::ResetTimerRecordCancelled
void ResetTimerRecordCancelled()
Definition: ProjectAudioManager.h:68
DefaultSpeedPlayOptions
AUDACITY_DLL_API AudioIOStartStreamOptions DefaultSpeedPlayOptions(AudacityProject &project)
Definition: ProjectAudioManager.cpp:1014
PlayMode::normalPlay
@ normalPlay
ProjectAudioManager::SetPaused
void SetPaused(bool value)
Definition: ProjectAudioManager.h:123
ProjectAudioManager::GetLastPlayMode
PlayMode GetLastPlayMode() const
Definition: ProjectAudioManager.h:120
ProjectAudioManager::IsTimerRecordCancelled
bool IsTimerRecordCancelled()
Definition: ProjectAudioManager.h:66
DefaultPlayOptions
AUDACITY_DLL_API AudioIOStartStreamOptions DefaultPlayOptions(AudacityProject &project)
Definition: ProjectAudioManager.cpp:1000
ProjectAudioManager::Paused
bool Paused() const
Definition: ProjectAudioManager.h:70
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:173
AudioIOListener::OnAudioIORate
virtual void OnAudioIORate(int rate)=0
ProjectAudioManager::SetLooping
void SetLooping(bool value)
Definition: ProjectAudioManager.h:125
AudioIOStartStreamOptions
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
Definition: AudioIOBase.h:77
AudioIOListener::OnCommitRecording
virtual void OnCommitRecording()=0
TransportTracks
Definition: AudioIO.h:87
AudioIOListener::OnAudioIOStopRecording
virtual void OnAudioIOStopRecording()=0
ProjectAudioManager::mCutPreviewTracks
std::shared_ptr< TrackList > mCutPreviewTracks
Definition: ProjectAudioManager.h:148
RATE_NOT_SELECTED
constexpr int RATE_NOT_SELECTED
Definition: ProjectAudioManager.h:21
ProjectAudioManager::SetTimerRecordCancelled
void SetTimerRecordCancelled()
Definition: ProjectAudioManager.h:67
ProjectAudioManager::mProject
AudacityProject & mProject
Definition: ProjectAudioManager.h:146
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:113
ProjectAudioManager
Definition: ProjectAudioManager.h:46
PlayMode::oneSecondPlay
@ oneSecondPlay
ProjectAudioManager::Stopping
bool Stopping() const
Definition: ProjectAudioManager.h:78
PlayMode::loopedPlay
@ loopedPlay
ProjectAudioManager::Looping
bool Looping() const
Definition: ProjectAudioManager.h:82
PropertiesOfSelected::rateOfSelected
int rateOfSelected
Definition: ProjectAudioManager.h:175
CommandFlag.h
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:38