Audacity 3.2.0
Public Member Functions | Public Attributes | List of all members
RealtimeEffectState::Access Struct Referencefinal

Main thread's interface to inter-thread communication of changes of settings. More...

Inheritance diagram for RealtimeEffectState::Access:
[legend]
Collaboration diagram for RealtimeEffectState::Access:
[legend]

Public Member Functions

 Access ()=default
 
 Access (RealtimeEffectState &state)
 
 ~Access () override=default
 
const EffectSettingsGet () override
 
void Set (EffectSettings &&settings, std::unique_ptr< Message > pMessage) override
 
void Set (std::unique_ptr< Message > pMessage) override
 Message-only overload of Set(). In future, this should be the only one. More...
 
void Flush () override
 Make the last Set changes "persistent" in underlying storage. More...
 
bool IsSameAs (const EffectSettingsAccess &other) const override
 
- Public Member Functions inherited from EffectSettingsAccess
virtual ~EffectSettingsAccess ()
 
virtual const EffectSettingsGet ()=0
 
virtual void Set (EffectSettings &&settings, std::unique_ptr< Message > pMessage=nullptr)=0
 
virtual void Set (std::unique_ptr< Message > pMessage=nullptr)=0
 Message-only overload of Set(). In future, this should be the only one. More...
 
virtual void Flush ()=0
 Make the last Set changes "persistent" in underlying storage. More...
 
virtual bool IsSameAs (const EffectSettingsAccess &other) const =0
 
template<typename Function >
void ModifySettings (Function &&function)
 Do a correct read-modify-write of settings. More...
 

Public Attributes

std::weak_ptr< RealtimeEffectStatemwState
 Store no state here but this weak pointer, so IsSameAs isn't lying. More...
 

Detailed Description

Main thread's interface to inter-thread communication of changes of settings.

Definition at line 192 of file RealtimeEffectState.cpp.

Constructor & Destructor Documentation

◆ Access() [1/2]

RealtimeEffectState::Access::Access ( )
default

◆ Access() [2/2]

RealtimeEffectState::Access::Access ( RealtimeEffectState state)
inlineexplicit

Definition at line 194 of file RealtimeEffectState.cpp.

195 : mwState{ state.weak_from_this() }
196 {
197 }
std::weak_ptr< RealtimeEffectState > mwState
Store no state here but this weak pointer, so IsSameAs isn't lying.

◆ ~Access()

RealtimeEffectState::Access::~Access ( )
overridedefault

Member Function Documentation

◆ Flush()

void RealtimeEffectState::Access::Flush ( )
inlineoverridevirtual

Make the last Set changes "persistent" in underlying storage.

Precondition
called on the main thread only

Implements EffectSettingsAccess.

Definition at line 278 of file RealtimeEffectState.cpp.

278 {
279 if (auto pState = mwState.lock()) {
280 if (auto pAccessState = pState->GetAccessState()) {
281 assert(pAccessState->mMainThreadId == std::this_thread::get_id());
282
283 if (pAccessState->mState.mInitialized)
284 {
285 std::unique_lock lk(pAccessState->mLockForCV);
286 pAccessState->mCV.wait(lk,
287 [&] {
288 auto& lastSettings = pAccessState->mLastSettings;
289 pAccessState->MainRead();
290 return pAccessState->mCounter == lastSettings.counter;
291 }
292 );
293 }
294
295 // Update what GetSettings() will return, during play and before
296 // Finalize(), but after it is confirmed that any worker thread has
297 // seen the values given to the last Set(). These values will also
298 // be returned by Get().
299 pState->mMainSettings.Set(pAccessState->mLastSettings);
300 }
301 }
302 }

References mwState.

◆ Get()

const EffectSettings & RealtimeEffectState::Access::Get ( )
inlineoverridevirtual

Implements EffectSettingsAccess.

Definition at line 201 of file RealtimeEffectState.cpp.

201 {
202 if (auto pState = mwState.lock()) {
203 if (auto pAccessState = pState->GetAccessState()) {
204 if (pAccessState->mState.mInitialized)
205 {
206 // try once
207 assert(pAccessState->mState.mInitialized);
208 auto& lastSettings = pAccessState->mLastSettings;
209 // Assigns to mCounter
210 pAccessState->MainRead();
211 }
212 else {
213 // Not yet waiting on the other thread's progress
214 // Not necessarily values yet in the state's Settings objects
215 }
216 return pAccessState->mLastSettings.settings;
217 }
218 }
219 // Non-modal dialog may have outlived the RealtimeEffectState
220 static EffectSettings empty;
221 return empty;
222 }
Externalized state of a plug-in.

References mwState.

◆ IsSameAs()

bool RealtimeEffectState::Access::IsSameAs ( const EffectSettingsAccess other) const
inlineoverridevirtual
Returns
whether this and the other give access to the same settings

Implements EffectSettingsAccess.

Definition at line 303 of file RealtimeEffectState.cpp.

303 {
304 if (auto pOther = dynamic_cast<const Access*>(&other)) {
305 auto &mine = mwState;
306 auto &theirs = pOther->mwState;
307 auto less = std::owner_less{};
308 return !(less(mine, theirs) || less(theirs, mine));
309 }
310 return false;
311 }

References mwState.

◆ Set() [1/2]

void RealtimeEffectState::Access::Set ( EffectSettings &&  settings,
std::unique_ptr< Message pMessage 
)
inlineoverridevirtual

Implements EffectSettingsAccess.

Definition at line 223 of file RealtimeEffectState.cpp.

224 {
225 if (auto pState = mwState.lock()) {
226 if (auto pAccessState = pState->GetAccessState()) {
227 if (pMessage && !pAccessState->mState.mInitialized) {
228 // Other thread isn't processing.
229 // Let the instance consume the message directly.
230 if (auto pInstance = pState->mwInstance.lock()) {
231 auto &stateSettings = pState->mMainSettings.settings;
232 stateSettings = std::move(settings);
234 stateSettings, pMessage.get()
235 };
236 pInstance->RealtimeProcessStart(package);
237 pInstance->RealtimeProcessEnd(stateSettings);
238 pAccessState->mLastSettings.settings = stateSettings;
239 return;
240 }
241 }
242 auto &lastSettings = pAccessState->mLastSettings;
243 // move to remember values here
244 lastSettings.settings = std::move(settings);
245 ++lastSettings.counter;
246 // move a copy to there
247 pAccessState->MainWrite(
248 SettingsAndCounter{ lastSettings }, std::move(pMessage));
249 }
250 }
251 }
static Settings & settings()
Definition: TrackInfo.cpp:51

References mwState, EffectInstance::MessagePackage::settings, and settings().

Here is the call graph for this function:

◆ Set() [2/2]

void RealtimeEffectState::Access::Set ( std::unique_ptr< Message pMessage)
inlineoverridevirtual

Message-only overload of Set(). In future, this should be the only one.

Implements EffectSettingsAccess.

Definition at line 252 of file RealtimeEffectState.cpp.

253 {
254 if (auto pState = mwState.lock()) {
255 if (auto pAccessState = pState->GetAccessState()) {
256 if (pMessage && !pAccessState->mState.mInitialized) {
257 // Other thread isn't processing.
258 // Let the instance consume the message directly.
259 if (auto pInstance = pState->mwInstance.lock()) {
260 auto &stateSettings = pState->mMainSettings.settings;
262 stateSettings, pMessage.get()
263 };
264 pInstance->RealtimeProcessStart(package);
265 pInstance->RealtimeProcessEnd(stateSettings);
266 // Don't need to update pAccessState->mLastSettings
267 return;
268 }
269 }
270 auto &lastSettings = pAccessState->mLastSettings;
271 // Don't update settings, but do count
272 ++lastSettings.counter;
273 pAccessState->MainWrite(
274 lastSettings.counter, std::move(pMessage));
275 }
276 }
277 }

References mwState.

Member Data Documentation

◆ mwState

std::weak_ptr<RealtimeEffectState> RealtimeEffectState::Access::mwState

Store no state here but this weak pointer, so IsSameAs isn't lying.

Definition at line 313 of file RealtimeEffectState.cpp.

Referenced by Flush(), Get(), IsSameAs(), and Set().


The documentation for this struct was generated from the following file: