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
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
71 static WritableSampleTrackArray ChooseExistingRecordingTracks(
72 AudacityProject &proj, bool selectedOnly,
73 double targetRate = RATE_NOT_SELECTED);
74
75 static bool UseDuplex();
76
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,
109 const TransportSequences &transportSequences,
110 double t0, double t1,
111 bool altAppearance,
112 const AudioIOStartStreamOptions &options);
113
114 int PlayPlayRegion(const SelectedRegion &selectedRegion,
115 const AudioIOStartStreamOptions &options,
116 PlayMode playMode,
117 bool backwards = false);
118
119 // Play currently selected region, or if nothing selected,
120 // play from current cursor.
121 void PlayCurrentRegion(
122 bool newDefault = false,
123 bool cutpreview = false);
124
125 void OnPause();
126
127
128 // Stop playing or recording
129 void Stop(bool stopStream = true);
130
131 void StopIfPaused();
132
133 bool DoPlayStopSelect( bool click, bool shift );
134 void DoPlayStopSelect( );
135
136 PlayMode GetLastPlayMode() const { return mLastPlayMode; }
137
138private:
139
140 void TogglePaused();
141 void SetPausedOff();
142
143 void SetAppending( bool value ) { mAppending = value; }
144 void SetLooping( bool value ) { mLooping = value; }
145 void SetCutting( bool value ) { mCutting = value; }
146 void SetStopping( bool value ) { mStopping = value; }
147
148 // Cancel the addition of temporary recording tracks into the project
149 void CancelRecording();
150
151 // Audio IO callback methods
152 void OnAudioIORate(int rate) override;
153 void OnAudioIOStartRecording() override;
154 void OnAudioIOStopRecording() override;
155 void OnAudioIONewBlocks() override;
156 void OnCommitRecording() override;
157 void OnSoundActivationThreshold() override;
158
159 void OnCheckpointFailure(ProjectFileIOMessage);
160
163
165
166 //flag for cancellation of timer record.
167 bool mTimerRecordCanceled{ false };
168
169 // Using int as the type for this atomic flag, allows us to toggle its value
170 // with an atomic operation.
171 std::atomic<int> mPaused{ 0 };
172
173 bool mAppending{ false };
174 bool mLooping{ false };
175 bool mCutting{ false };
176 bool mStopping{ false };
177
178 int mDisplayedRate{ 0 };
179 static std::pair< TranslatableStrings, unsigned >
180 StatusWidthFunction(
182};
183
185
187{
188 bool allSameRate{ false };
190 bool anySelected{ false };
191};
192
193AUDACITY_DLL_API
195
196#include "CommandFlag.h"
197
198extern AUDACITY_DLL_API const ReservedCommandFlag
200
201#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
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 explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
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:850
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
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:46
A convenient default parameter for class template Site.
Definition: ClientData.h:29
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