1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

StandaloneFilterWindow: Update implementation of getInstance to avoid iterating through desktop windows

This commit is contained in:
reuk 2024-11-03 19:53:22 +00:00
parent ec4dfe1556
commit a7e9edb2e9
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C

View file

@ -91,6 +91,10 @@ public:
channelConfiguration (channels),
autoOpenMidiDevices (shouldAutoOpenMidiDevices)
{
// Only one StandalonePluginHolder may be created at a time
jassert (currentInstance == nullptr);
currentInstance = this;
shouldMuteInput.addListener (this);
shouldMuteInput = ! isInterAppAudioConnected();
@ -128,6 +132,8 @@ public:
handleDeletePlugin();
shutDownAudioDevices();
currentInstance = nullptr;
}
//==============================================================================
@ -409,7 +415,10 @@ public:
return {};
}
static StandalonePluginHolder* getInstance();
static StandalonePluginHolder* getInstance()
{
return currentInstance;
}
//==============================================================================
OptionalScopedPointer<PropertySet> settings;
@ -432,6 +441,8 @@ public:
ScopedMessageBox messageBox;
private:
inline static StandalonePluginHolder* currentInstance = nullptr;
//==============================================================================
void handleCreatePlugin()
{
@ -1160,21 +1171,4 @@ private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (StandaloneFilterWindow)
};
inline StandalonePluginHolder* StandalonePluginHolder::getInstance()
{
#if JucePlugin_Enable_IAA || JucePlugin_Build_Standalone
if (PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_Standalone)
{
auto& desktop = Desktop::getInstance();
const int numTopLevelWindows = desktop.getNumComponents();
for (int i = 0; i < numTopLevelWindows; ++i)
if (auto window = dynamic_cast<StandaloneFilterWindow*> (desktop.getComponent (i)))
return window->getPluginHolder();
}
#endif
return nullptr;
}
} // namespace juce