Audacity 3.2.0
Classes | Public Member Functions | Public Attributes | List of all members
RealtimeEffectState::AccessState Class Reference

Mediator of two-way inter-thread communication of changes of settings. More...

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

Classes

struct  CounterAndOutputs
 
struct  FromMainSlot
 
struct  ToMainSlot
 

Public Member Functions

 AccessState (const EffectSettingsManager &effect, RealtimeEffectState &state)
 
void Initialize (const EffectSettings &settings, const EffectInstance::Message *pMessage, const EffectOutputs *pOutputs)
 
void MainRead ()
 
void MainWrite (SettingsAndCounter &&settings, std::unique_ptr< EffectInstance::Message > pMessage)
 
void MainWrite (SettingsAndCounter::Counter counter, std::unique_ptr< EffectInstance::Message > pMessage)
 
void WorkerRead ()
 
void WorkerWrite ()
 

Public Attributes

const EffectSettingsManagermEffect
 
RealtimeEffectStatemState
 
MessageBuffer< FromMainSlotmChannelFromMain
 
Response::Counter mCounter
 
SettingsAndCounter mLastSettings
 
MessageBuffer< ToMainSlotmChannelToMain
 
std::mutex mLockForCV
 
std::condition_variable mCV
 
std::thread::id mMainThreadId
 

Detailed Description

Mediator of two-way inter-thread communication of changes of settings.

Definition at line 24 of file RealtimeEffectState.cpp.

Constructor & Destructor Documentation

◆ AccessState()

RealtimeEffectState::AccessState::AccessState ( const EffectSettingsManager effect,
RealtimeEffectState state 
)
inline

Definition at line 26 of file RealtimeEffectState.cpp.

27 : mEffect{ effect }
28 , mState{ state }
29 {
30 // Clean initial state of the counter
31 state.mMainSettings.counter = 0;
32 Initialize(state.mMainSettings.settings,
33 state.mMessage.get(), state.mMovedOutputs.get());
34 }
void Initialize(const EffectSettings &settings, const EffectInstance::Message *pMessage, const EffectOutputs *pOutputs)
const EffectSettingsManager & mEffect
NonInterfering< SettingsAndCounter > mMainSettings
Updated immediately by Access::Set in the main thread.
std::unique_ptr< EffectInstance::Message > mMessage
std::unique_ptr< EffectOutputs > mMovedOutputs

References Initialize(), RealtimeEffectState::mMainSettings, RealtimeEffectState::mMessage, and RealtimeEffectState::mMovedOutputs.

Here is the call graph for this function:

Member Function Documentation

◆ Initialize()

void RealtimeEffectState::AccessState::Initialize ( const EffectSettings settings,
const EffectInstance::Message pMessage,
const EffectOutputs pOutputs 
)
inline

Definition at line 36 of file RealtimeEffectState.cpp.

39 {
40 mLastSettings = { settings, 0 };
41 // Initialize each message buffer with two copies
42 mChannelToMain.Write(ToMainSlot{ { 0,
43 pOutputs ? pOutputs->Clone() : nullptr } });
44 mChannelToMain.Write(ToMainSlot{ { 0,
45 pOutputs ? pOutputs->Clone() : nullptr } });
46 mChannelFromMain.Write(FromMainSlot{ settings, pMessage });
47 mChannelFromMain.Write(FromMainSlot{ settings, pMessage });
48
49 mMainThreadId = std::this_thread::get_id();
50 }
static Settings & settings()
Definition: TrackInfo.cpp:51
virtual std::unique_ptr< EffectOutputs > Clone() const =0
MessageBuffer< ToMainSlot > mChannelToMain
MessageBuffer< FromMainSlot > mChannelFromMain

References EffectOutputs::Clone(), mChannelFromMain, mChannelToMain, mLastSettings, mMainThreadId, and settings().

Referenced by AccessState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MainRead()

void RealtimeEffectState::AccessState::MainRead ( )
inline

Definition at line 52 of file RealtimeEffectState.cpp.

52 {
53 mChannelToMain.Read<ToMainSlot::Reader>(mState.mMovedOutputs.get(),
54 mCounter);
55 }

References mChannelToMain, mCounter, RealtimeEffectState::mMovedOutputs, and mState.

◆ MainWrite() [1/2]

void RealtimeEffectState::AccessState::MainWrite ( SettingsAndCounter &&  settings,
std::unique_ptr< EffectInstance::Message pMessage 
)
inline

Definition at line 56 of file RealtimeEffectState.cpp.

57 {
58 // Main thread may simply swap new content into place
60 std::move(settings.settings), settings.counter, std::move(pMessage) });
61 }
TranslatableString Message(unsigned trackCount)

References mChannelFromMain, and settings().

Here is the call graph for this function:

◆ MainWrite() [2/2]

void RealtimeEffectState::AccessState::MainWrite ( SettingsAndCounter::Counter  counter,
std::unique_ptr< EffectInstance::Message pMessage 
)
inline

Definition at line 62 of file RealtimeEffectState.cpp.

63 {
64 mChannelFromMain.Write(FromMainSlot::ShortMessage{
65 counter, std::move(pMessage) });
66 }

References mChannelFromMain.

◆ WorkerRead()

void RealtimeEffectState::AccessState::WorkerRead ( )
inline

Definition at line 72 of file RealtimeEffectState.cpp.

72 {
73 // Worker thread avoids memory allocation. It copies the contents of any
74 mChannelFromMain.Read<FromMainSlot::Reader>(mEffect, mState);
75 }

References mChannelFromMain, mEffect, and mState.

◆ WorkerWrite()

void RealtimeEffectState::AccessState::WorkerWrite ( )
inline

Definition at line 76 of file RealtimeEffectState.cpp.

76 {
77
78 {
79 std::unique_lock lk(mLockForCV);
80
81 // Worker thread avoids memory allocation.
82 mChannelToMain.Write(CounterAndOutputs{
83 mState.mWorkerSettings.counter, mState.mOutputs.get() });
84 }
85 mCV.notify_one();
86 }
NonInterfering< SettingsAndCounter > mWorkerSettings
std::unique_ptr< EffectOutputs > mOutputs

References mChannelToMain, mCV, mLockForCV, RealtimeEffectState::mOutputs, mState, and RealtimeEffectState::mWorkerSettings.

Member Data Documentation

◆ mChannelFromMain

MessageBuffer<FromMainSlot> RealtimeEffectState::AccessState::mChannelFromMain

Definition at line 179 of file RealtimeEffectState.cpp.

Referenced by Initialize(), MainWrite(), and WorkerRead().

◆ mChannelToMain

MessageBuffer<ToMainSlot> RealtimeEffectState::AccessState::mChannelToMain

Definition at line 183 of file RealtimeEffectState.cpp.

Referenced by Initialize(), MainRead(), and WorkerWrite().

◆ mCounter

Response::Counter RealtimeEffectState::AccessState::mCounter

Definition at line 180 of file RealtimeEffectState.cpp.

Referenced by MainRead().

◆ mCV

std::condition_variable RealtimeEffectState::AccessState::mCV

Definition at line 186 of file RealtimeEffectState.cpp.

Referenced by WorkerWrite().

◆ mEffect

const EffectSettingsManager& RealtimeEffectState::AccessState::mEffect

Definition at line 176 of file RealtimeEffectState.cpp.

Referenced by WorkerRead().

◆ mLastSettings

SettingsAndCounter RealtimeEffectState::AccessState::mLastSettings

Definition at line 181 of file RealtimeEffectState.cpp.

Referenced by Initialize().

◆ mLockForCV

std::mutex RealtimeEffectState::AccessState::mLockForCV

Definition at line 185 of file RealtimeEffectState.cpp.

Referenced by WorkerWrite().

◆ mMainThreadId

std::thread::id RealtimeEffectState::AccessState::mMainThreadId

Definition at line 188 of file RealtimeEffectState.cpp.

Referenced by Initialize().

◆ mState

RealtimeEffectState& RealtimeEffectState::AccessState::mState

Definition at line 177 of file RealtimeEffectState.cpp.

Referenced by MainRead(), WorkerRead(), and WorkerWrite().


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