Audacity 3.2.0
RealtimeEffectState.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file RealtimeEffectState.h
6
7 Paul Licameli split from RealtimeEffectManager.cpp
8
9 *********************************************************************/
10
11#ifndef __AUDACITY_REALTIMEEFFECTSTATE_H__
12#define __AUDACITY_REALTIMEEFFECTSTATE_H__
13
14#include <atomic>
15#include <unordered_map>
16#include <vector>
17#include <cstddef>
18#include "EffectInterface.h"
19#include "GlobalVariable.h"
20#include "MemoryX.h"
21#include "PluginProvider.h" // for PluginID
22#include "XMLTagHandler.h"
23
25class Track;
26
28 : public XMLTagHandler
29 , public std::enable_shared_from_this<RealtimeEffectState>
30 , public SharedNonInterfering<RealtimeEffectState>
31{
32public:
33 struct AUDACITY_DLL_API EffectFactory : GlobalHook<EffectFactory,
34 const EffectInstanceFactory *(const PluginID &)
35 >{};
36
37 explicit RealtimeEffectState(const PluginID & id);
41
43
46 void SetID(const PluginID & id);
47 const PluginID& GetID() const noexcept;
51 const EffectInstanceFactory *GetEffect() const { return mPlugin; }
52
54
57 std::shared_ptr<EffectInstance> GetInstance();
58
60 std::shared_ptr<EffectInstance> Initialize(double rate);
62 std::shared_ptr<EffectInstance>
63 AddTrack(Track &track, unsigned chans, float sampleRate);
65
66 bool ProcessStart(bool running);
68 void Process(Track &track,
69 unsigned chans,
70 const float *const *inbuf,
71 float *const *outbuf,
72 size_t numSamples);
74 bool ProcessEnd();
75
76 const EffectSettings &GetSettings() const { return mMainSettings; }
77
79 bool IsEnabled() const noexcept;
80
82 bool IsActive() const noexcept;
83
85 bool Finalize() noexcept;
86
87 static const std::string &XMLTag();
88 bool HandleXMLTag(
89 const std::string_view &tag, const AttributesList &attrs) override;
90 void HandleXMLEndTag(const std::string_view &tag) override;
91 XMLTagHandler *HandleXMLChild(const std::string_view &tag) override;
92 void WriteXML(XMLWriter &xmlFile);
93
96
99 std::shared_ptr<EffectSettingsAccess> GetAccess();
100
101private:
102 std::shared_ptr<EffectInstance> EnsureInstance(double rate);
103
104 struct Access;
105 struct AccessState;
106
108 {
109 return mpAccessState.load(std::memory_order_relaxed);
110 }
112 {
113 return mpAccessState.load(std::memory_order_acquire);
114 }
115
121
124
127
129
139
141
147 std::weak_ptr<EffectInstance> mwInstance;
148
149 std::unordered_map<Track *, size_t> mGroups;
150
151 // This must not be reset to nullptr while a worker thread is running.
152 // In fact it is never yet reset to nullptr, before destruction.
153 // Destroy before mWorkerSettings:
155
156 wxString mParameters; // Used only during deserialization
157 size_t mCurrentProcessor{ 0 };
158 bool mInitialized{ false };
159
161};
162
163#endif // __AUDACITY_REALTIMEEFFECTSTATE_H__
wxString PluginID
Definition: EffectManager.h:30
Generalized interface for discovery of plug-ins for one protocol.
std::vector< Attribute > AttributesList
Definition: XMLTagHandler.h:40
Performs effect computation.
Global function-valued variable, adding a convenient Call()
Mediator of two-way inter-thread communication of changes of settings.
NonInterfering< EffectSettings > mMainSettings
Updated immediately by Access::Set in the main thread.
const EffectSettings & GetSettings() const
const EffectInstanceFactory * mPlugin
Stateless effect object.
void HandleXMLEndTag(const std::string_view &tag) override
std::shared_ptr< EffectInstance > GetInstance()
Expose a pointer to the state's instance (making one as needed).
std::shared_ptr< EffectSettingsAccess > GetAccess()
bool ProcessEnd()
Worker thread finishes a batch of samples.
AccessState * GetAccessState() const
AccessState * TestAccessState() const
static const std::string & XMLTag()
bool Finalize() noexcept
Main thread cleans up playback.
NonInterfering< EffectSettings > mWorkerSettings
std::shared_ptr< EffectInstance > EnsureInstance(double rate)
bool ProcessStart(bool running)
Worker thread begins a batch of samples.
bool IsEnabled() const noexcept
Test only in the main thread.
const PluginID & GetID() const noexcept
bool mLastActive
Assigned in the worker thread at the start of each processing scope.
std::shared_ptr< EffectInstance > AddTrack(Track &track, unsigned chans, float sampleRate)
Main thread sets up this state before adding it to lists.
void WriteXML(XMLWriter &xmlFile)
RealtimeEffectState(const PluginID &id)
bool IsActive() const noexcept
Test only in the worker thread, or else when there is no processing.
std::shared_ptr< EffectInstance > Initialize(double rate)
Main thread sets up for playback.
std::unordered_map< Track *, size_t > mGroups
const EffectInstanceFactory * GetEffect()
Initializes the effect on demand.
XMLTagHandler * HandleXMLChild(const std::string_view &tag) override
void SetID(const PluginID &id)
May be called with nonempty id at most once in the lifetime of a state.
std::weak_ptr< EffectInstance > mwInstance
Stateful instance made by the plug-in.
RealtimeEffectState & operator=(const RealtimeEffectState &other)=delete
AtomicUniquePointer< AccessState > mpAccessState
bool HandleXMLTag(const std::string_view &tag, const AttributesList &attrs) override
void Process(Track &track, unsigned chans, const float *const *inbuf, float *const *outbuf, size_t numSamples)
Worker thread processes part of a batch of samples.
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:225
This class is an interface which should be implemented by classes which wish to be able to load and s...
Definition: XMLTagHandler.h:42
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:26
STL namespace.
Externalized state of a plug-in.
Workaround for std::make_shared not working on macOs with over-alignment.
Definition: MemoryX.h:495