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
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:
68 static const ProjectAudioManager &Get( const AudacityProject &project );
69
72 static WritableSampleTrackArray ChooseExistingRecordingTracks(
73 AudacityProject &proj, bool selectedOnly,
74 double targetRate = RATE_NOT_SELECTED);
75
76 static bool UseDuplex();
77
82
83 bool IsTimerRecordCancelled() { return mTimerRecordCanceled; }
84 void SetTimerRecordCancelled() { mTimerRecordCanceled = true; }
85 void ResetTimerRecordCancelled() { mTimerRecordCanceled = false; }
86
87 bool Paused() const;
88
89 bool Playing() const;
90
91 // Whether recording into this project (not just into some project) is
92 // active
93 bool Recording() const;
94
95 bool Stopping() const { return mStopping; }
96
97 // Whether the last attempt to start recording requested appending to tracks
98 bool Appending() const { return mAppending; }
99 // Whether potentially looping play (using new default PlaybackPolicy)
100 bool Looping() const { return mLooping; }
101 bool Cutting() const { return mCutting; }
102
103 // A project is only allowed to stop an audio stream that it owns.
104 bool CanStopAudioStream () const;
105
106 void OnRecord(bool altAppearance);
107
108 bool DoRecord(AudacityProject &project,
110 const TransportSequences &transportSequences,
111 double t0, double t1,
112 bool altAppearance,
113 const AudioIOStartStreamOptions &options);
114
115 int PlayPlayRegion(const SelectedRegion &selectedRegion,
116 const AudioIOStartStreamOptions &options,
117 PlayMode playMode,
118 bool backwards = false);
119
120 // Play currently selected region, or if nothing selected,
121 // play from current cursor.
122 void PlayCurrentRegion(
123 bool newDefault = false,
124 bool cutpreview = false);
125
126 void OnPause();
127
128
129 // Stop playing or recording
130 void Stop(bool stopStream = true);
131
132 void StopIfPaused();
133
134 bool DoPlayStopSelect( bool click, bool shift );
135 void DoPlayStopSelect( );
136
137 PlayMode GetLastPlayMode() const { return mLastPlayMode; }
138
139private:
140
141 void TogglePaused();
142 void SetPausedOff();
143
144 void SetAppending( bool value ) { mAppending = value; }
145 void SetLooping( bool value ) { mLooping = value; }
146 void SetCutting( bool value ) { mCutting = value; }
147 void SetStopping( bool value ) { mStopping = value; }
148
149 // Cancel the addition of temporary recording tracks into the project
150 void CancelRecording();
151
152 // Audio IO callback methods
153 void OnAudioIORate(int rate) override;
154 void OnAudioIOStartRecording() override;
155 void OnAudioIOStopRecording() override;
156 void OnAudioIONewBlocks() override;
157 void OnCommitRecording() override;
158 void OnSoundActivationThreshold() override;
159
160 void OnCheckpointFailure(ProjectFileIOMessage);
161
164
166
167 //flag for cancellation of timer record.
168 bool mTimerRecordCanceled{ false };
169
170 // Using int as the type for this atomic flag, allows us to toggle its value
171 // with an atomic operation.
172 std::atomic<int> mPaused{ 0 };
173
174 bool mAppending{ false };
175 bool mLooping{ false };
176 bool mCutting{ false };
177 bool mStopping{ false };
178
179 int mDisplayedRate{ 0 };
180 static std::pair< TranslatableStrings, unsigned >
181 StatusWidthFunction(
183};
184
186
188{
189 bool allSameRate{ false };
191 bool anySelected{ false };
192};
193
194AUDACITY_DLL_API
196
197#include "CommandFlag.h"
198
199extern AUDACITY_DLL_API const ReservedCommandFlag
201
202#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
#define field(n, t)
Definition: ImportAUP.cpp:165
@ 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:50
StatusBarField
Definition: ProjectStatus.h:24
const auto project
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 OnAudioIONewBlocks()=0
virtual void OnAudioIOStartRecording()=0
virtual void OnCommitRecording()=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
AudacityProject & mProject
void SetLooping(bool value)
ProjectAudioManager(const ProjectAudioManager &)=delete
void SetAppending(bool value)
void SetStopping(bool value)
PlayMode GetLastPlayMode() const
ProjectAudioManager & operator=(const ProjectAudioManager &)=delete
~ProjectAudioManager() override
void SetCutting(bool value)
Observer::Subscription mCheckpointFailureSubscription
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:975
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
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