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 "Observer.h"
20#include "Observer.h"
21
22#include <atomic>
23
24constexpr int RATE_NOT_SELECTED{ -1 };
25
26class AudacityProject;
28class TrackList;
29class SelectedRegion;
32 std::vector< std::shared_ptr< WritableSampleTrack > >;
33
34enum class PlayMode : int {
36 oneSecondPlay, // Disables auto-scrolling
37 loopedPlay, // Possibly looped play (not always); disables auto-scrolling
39};
40
41struct TransportTracks;
42
43enum StatusBarField : int;
44enum class ProjectFileIOMessage : int;
45
49 using Interval = std::pair<double, double>;
50 using Intervals = std::vector<Interval>;
51
54 {}
55
58};
59
60class AUDACITY_DLL_API ProjectAudioManager final
61 : public ClientData::Base
62 , public AudioIOListener
63 , public std::enable_shared_from_this< ProjectAudioManager >
64 , public Observer::Publisher<RecordingDropoutEvent>
65{
66public:
67 static ProjectAudioManager &Get( AudacityProject &project );
68 static const ProjectAudioManager &Get( const AudacityProject &project );
69
70 // Find suitable tracks to record into, or return an empty array.
71 static WritableSampleTrackArray ChooseExistingRecordingTracks(
72 AudacityProject &proj, bool selectedOnly,
73 double targetRate = RATE_NOT_SELECTED);
74
75 static bool UseDuplex();
76
77 explicit ProjectAudioManager( AudacityProject &project );
81
82 bool IsTimerRecordCancelled() { return mTimerRecordCanceled; }
83 void SetTimerRecordCancelled() { mTimerRecordCanceled = true; }
84 void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; }
85
86 bool Paused() const;
87
88 bool Playing() const;
89
90 // Whether recording into this project (not just into some project) is
91 // active
92 bool Recording() const;
93
94 bool Stopping() const { return mStopping; }
95
96 // Whether the last attempt to start recording requested appending to tracks
97 bool Appending() const { return mAppending; }
98 // Whether potentially looping play (using new default PlaybackPolicy)
99 bool Looping() const { return mLooping; }
100 bool Cutting() const { return mCutting; }
101
102 // A project is only allowed to stop an audio stream that it owns.
103 bool CanStopAudioStream () const;
104
105 void OnRecord(bool altAppearance);
106
107 bool DoRecord(AudacityProject &project,
108 const TransportTracks &transportTracks, // If captureTracks is empty, then tracks are created
109 double t0, double t1,
110 bool altAppearance,
111 const AudioIOStartStreamOptions &options);
112
113 int PlayPlayRegion(const SelectedRegion &selectedRegion,
114 const AudioIOStartStreamOptions &options,
115 PlayMode playMode,
116 bool backwards = false);
117
118 // Play currently selected region, or if nothing selected,
119 // play from current cursor.
120 void PlayCurrentRegion(
121 bool newDefault = false,
122 bool cutpreview = false);
123
124 void OnPause();
125
126
127 // Stop playing or recording
128 void Stop(bool stopStream = true);
129
130 void StopIfPaused();
131
132 bool DoPlayStopSelect( bool click, bool shift );
133 void DoPlayStopSelect( );
134
135 PlayMode GetLastPlayMode() const { return mLastPlayMode; }
136
137private:
138
139 void TogglePaused();
140 void SetPausedOff();
141
142 void SetAppending( bool value ) { mAppending = value; }
143 void SetLooping( bool value ) { mLooping = value; }
144 void SetCutting( bool value ) { mCutting = value; }
145 void SetStopping( bool value ) { mStopping = value; }
146
147 // Cancel the addition of temporary recording tracks into the project
148 void CancelRecording();
149
150 // Audio IO callback methods
151 void OnAudioIORate(int rate) override;
152 void OnAudioIOStartRecording() override;
153 void OnAudioIOStopRecording() override;
154 void OnAudioIONewBlocks(const WritableSampleTrackArray *tracks) override;
155 void OnCommitRecording() override;
156 void OnSoundActivationThreshold() override;
157
158 void OnCheckpointFailure(ProjectFileIOMessage);
159
162
164
165 //flag for cancellation of timer record.
166 bool mTimerRecordCanceled{ false };
167
168 // Using int as the type for this atomic flag, allows us to toggle its value
169 // with an atomic operation.
170 std::atomic<int> mPaused{ 0 };
171
172 bool mAppending{ false };
173 bool mLooping{ false };
174 bool mCutting{ false };
175 bool mStopping{ false };
176
177 int mDisplayedRate{ 0 };
178 static std::pair< TranslatableStrings, unsigned >
179 StatusWidthFunction(
180 const AudacityProject &project, StatusBarField field);
181};
182
184
186{
187 bool allSameRate{ false };
190};
191
192AUDACITY_DLL_API
194
195#include "commands/CommandFlag.h"
196
197extern AUDACITY_DLL_API const ReservedCommandFlag
199
200#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
#define field(n, t)
Definition: ImportAUP.cpp:166
@ cutPreviewPlay
std::vector< std::shared_ptr< WritableSampleTrack > > WritableSampleTrackArray
AudioIOStartStreamOptions DefaultSpeedPlayOptions(AudacityProject &project)
AUDACITY_DLL_API const ReservedCommandFlag & CanStopAudioStreamFlag()
AUDACITY_DLL_API PropertiesOfSelected GetPropertiesOfSelected(const AudacityProject &proj)
constexpr int RATE_NOT_SELECTED
ProjectFileIOMessage
Subscribe to ProjectFileIO to receive messages; always in idle time.
Definition: ProjectFileIO.h:49
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:90
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 OnAudioIOStartRecording()=0
virtual void OnCommitRecording()=0
virtual void OnAudioIONewBlocks(const WritableSampleTrackArray *tracks)=0
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
Observer::Subscription mCheckpointFailureSubcription
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:1338
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:194
void OnRecord(const CommandContext &context)
void OnPause(const CommandContext &context)
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, 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)
std::vector< Interval > Intervals