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

AUv3: Ensure an editor is always available if possible

This commit is contained in:
Anthony Nicholls 2025-10-02 17:50:40 +01:00 committed by Anthony Nicholls
parent 7449867337
commit 32b4423ca8

View file

@ -910,11 +910,22 @@ private:
auto supportedViewIndices = [[NSMutableIndexSet alloc] init];
auto n = [configs count];
if (auto* editor = _this (self)->getAudioProcessor().createEditorIfNeeded())
const auto getEditor = [&]
{
if (auto* editor = _this (self)->getAudioProcessor().getActiveEditor())
return editor;
return _this (self)->getAudioProcessor().createEditorIfNeeded();
};
MessageManager::callSync ([&]
{
if (auto* editor = getEditor())
{
// If you hit this assertion then your plug-in's editor is reporting that it doesn't support
// any host MIDI controller configurations!
jassert (editor->supportsHostMIDIControllerPresence (true) || editor->supportsHostMIDIControllerPresence (false));
jassert ( editor->supportsHostMIDIControllerPresence (true)
|| editor->supportsHostMIDIControllerPresence (false));
for (auto i = 0u; i < n; ++i)
{
@ -929,7 +940,9 @@ private:
const auto maxLimits = std::numeric_limits<int>::max() / 2;
const Rectangle<int> requestedBounds { width, height };
auto modifiedBounds = requestedBounds;
constrainer->checkBounds (modifiedBounds, editor->getBounds().withZeroOrigin(), { maxLimits, maxLimits }, false, false, false, false);
constrainer->checkBounds (modifiedBounds,
editor->getBounds().withZeroOrigin(),
{ maxLimits, maxLimits }, false, false, false, false);
if (modifiedBounds == requestedBounds)
[supportedViewIndices addIndex: i];
@ -937,6 +950,7 @@ private:
}
}
}
});
return [supportedViewIndices autorelease];
});
@ -1972,14 +1986,14 @@ public:
//==============================================================================
AUAudioUnit* createAudioUnit (const AudioComponentDescription& descr, NSError** error)
{
const auto holder = [&]
const auto holder = std::invoke ([&]
{
if (auto initialisedHolder = processorHolder.get())
return initialisedHolder;
waitForExecutionOnMainThread ([this] { [myself view]; });
MessageManager::callSync ([this] { [myself view]; });
return processorHolder.get();
}();
});
if (holder == nullptr)
return nullptr;
@ -1988,25 +2002,6 @@ public:
}
private:
template <typename Callback>
static void waitForExecutionOnMainThread (Callback&& callback)
{
if (MessageManager::getInstance()->isThisTheMessageThread())
{
callback();
return;
}
std::promise<void> promise;
MessageManager::callAsync ([&]
{
callback();
promise.set_value();
});
promise.get_future().get();
}
// There's a chance that createAudioUnit will be called from a background
// thread while the processorHolder is being updated on the main thread.