| 1037 | } |
| 1038 | |
| 1039 | std::shared_ptr<EffectInstance> EffectUIHost::InitializeInstance() |
| 1040 | { |
| 1041 | // We are still constructing and the return initializes a const member |
| 1042 | std::shared_ptr<EffectInstance> result; |
| 1043 | |
| 1044 | auto mpState = mwState.lock(); |
| 1045 | |
| 1046 | bool priorState = (mpState != nullptr); |
| 1047 | if (!priorState) { |
| 1048 | auto gAudioIO = AudioIO::Get(); |
| 1049 | mCapturing = gAudioIO->IsStreamActive() && gAudioIO->GetNumCaptureChannels() > 0 && !gAudioIO->IsMonitoring(); |
| 1050 | } |
| 1051 | |
| 1052 | if (mSupportsRealtime && !mInitialized) { |
| 1053 | if (!priorState) |
| 1054 | mwState = mpState = mpTempProjectState = |
| 1055 | AudioIO::Get()->AddState(mProject, nullptr, GetID(mEffectUIHost)); |
| 1056 | if (mpState) { |
| 1057 | // Find the right instance to connect to the dialog |
| 1058 | if (!result) |
| 1059 | result = mpState->GetInstance(); |
| 1060 | |
| 1061 | mpAccess2 = mpState->GetAccess(); |
| 1062 | if (!(mpAccess2->IsSameAs(*mpAccess))) |
| 1063 | // Decorate the given access object |
| 1064 | mpAccess = std::make_shared<EffectSettingsAccessTee>( |
| 1065 | *mpAccess, mpAccess2); |
| 1066 | |
| 1067 | mEffectStateSubscription = mpState->Subscribe([this](RealtimeEffectStateChange state) { |
| 1068 | mEnabled = (state == RealtimeEffectStateChange::EffectOn); |
| 1069 | UpdateControls(); |
| 1070 | }); |
| 1071 | } |
| 1072 | |
| 1073 | if (!priorState) { |
| 1074 | mAudioIOSubscription = AudioIO::Get()->Subscribe([this](AudioIOEvent event){ |
| 1075 | switch (event.type) { |
| 1076 | case AudioIOEvent::CAPTURE: |
| 1077 | OnCapture(event); break; |
| 1078 | default: |
| 1079 | break; |
| 1080 | } |
| 1081 | }); |
| 1082 | } |
| 1083 | |
| 1084 | mInitialized = true; |
| 1085 | } |
| 1086 | else |
| 1087 | result = EffectBase::FindInstance(mEffectUIHost).value_or(nullptr); |
| 1088 | |
| 1089 | return result; |
| 1090 | } |
| 1091 | |
| 1092 | void EffectUIHost::CleanupRealtime() |
| 1093 | { |
nothing calls this directly
no test coverage detected