11#ifndef __AUDACITY_REALTIME_EFFECT_MANAGER__
12#define __AUDACITY_REALTIME_EFFECT_MANAGER__
19#include <unordered_map>
30 class InitializationScope;
31 class ProcessingScope;
52 using Latency = std::chrono::microseconds;
63 bool IsActive() const noexcept;
104 std::optional<
size_t> FindState(
107 bool GetSuspended()
const
108 {
return mSuspended.load(std::memory_order_relaxed); }
118 { mSuspended.store(value, std::memory_order_relaxed); }
123 std::shared_ptr<RealtimeEffectState>
133 const Track &track,
unsigned chans,
float rate);
135 void Finalize() noexcept;
147 void ProcessStart(
bool suspended);
149 size_t Process(
bool suspended,
const Track &track,
150 float *
const *buffers,
float *
const *scratch,
float *dummy,
151 unsigned nBuffers,
size_t numSamples);
152 void ProcessEnd(
bool suspended)
noexcept;
163 template<
typename StateVisitor>
173 template<
typename StateVisitor>
185 template<
typename StateVisitor>
192 for (
auto leader : mGroupLeaders)
199 std::atomic<bool> mSuspended{
true };
201 bool mActive{
false };
207 std::unordered_map<const Track *, double>
mRates;
216 std::weak_ptr<AudacityProject> wProject,
double sampleRate,
217 unsigned numPlaybackChannels
237 .
AddTrack(*
this, track, chans, rate);
261 std::weak_ptr<AudacityProject> wProject)
277 float *
const *buffers,
278 float *
const *scratch,
287 nBuffers, numSamples);
Utility ClientData::Site to register hooks into a host class that attach client data.
static RealtimeEffectState::EffectFactory::Scope scope
Inject a factory for realtime effects.
Generalized interface for discovery of plug-ins for one protocol.
static const AttachedProjectObjects::RegisteredFactory manager
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Performs effect computation.
An object that sends messages to an open-ended list of subscribed callbacks.
void Visit(const StateVisitor &func)
Apply the function to all states sequentially.
static RealtimeEffectList & Get(AudacityProject &project)
AudacityProject & mProject
void VisitGroup(const Track &leader, const StateVisitor &func)
std::unordered_map< const Track *, double > mRates
void VisitAll(const StateVisitor &func)
Visit the per-project states first, then all tracks from AddTrack.
void SetSuspended(bool value)
To be called only from main thread.
static RealtimeEffectManager & Get(AudacityProject &project)
void Initialize(RealtimeEffects::InitializationScope &scope, double sampleRate)
Main thread begins to define a set of tracks for playback.
void ProcessStart(bool suspended)
size_t Process(bool suspended, const Track &track, float *const *buffers, float *const *scratch, float *dummy, unsigned nBuffers, size_t numSamples)
void Finalize() noexcept
Main thread cleans up after playback.
RealtimeEffectManager & operator=(const RealtimeEffectManager &)=delete
void ProcessEnd(bool suspended) noexcept
std::vector< const Track * > mGroupLeaders
all are non-null
std::chrono::microseconds Latency
RealtimeEffectManager(const RealtimeEffectManager &)=delete
void AddTrack(RealtimeEffects::InitializationScope &scope, const Track &track, unsigned chans, float rate)
void VisitGroup(Track &leader, const StateVisitor &func)
Visit the per-project states first, then states for leader if not null.
Brackets processing setup and cleanup in the main thread.
InitializationScope(std::weak_ptr< AudacityProject > wProject, double sampleRate, unsigned numPlaybackChannels)
InitializationScope(InitializationScope &&other)=default
std::vector< std::shared_ptr< EffectInstance > > mInstances
std::weak_ptr< AudacityProject > mwProject
void AddTrack(const Track &track, unsigned chans, float rate)
unsigned mNumPlaybackChannels
InitializationScope & operator=(InitializationScope &&other)=default
Brackets one block of processing in one thread.
ProcessingScope & operator=(ProcessingScope &&other)=default
std::weak_ptr< AudacityProject > mwProject
size_t Process(const Track &track, float *const *buffers, float *const *scratch, float *dummy, unsigned nBuffers, size_t numSamples)
RealtimeEffectManager::AllListsLock mLocks
ProcessingScope(ProcessingScope &&other)=default
ProcessingScope(InitializationScope &, std::weak_ptr< AudacityProject > wProject)
Require a prior InializationScope to ensure correct nesting.
Abstract base class for an object holding data associated with points on a time axis.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
A convenient default parameter for class template Site.
Posted when effect is being added or removed to/from track or project.
std::shared_ptr< Track > track
null, if changes happened in the project scope