mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
AUv3: Ensure an editor is always available if possible
This commit is contained in:
parent
7449867337
commit
32b4423ca8
1 changed files with 34 additions and 39 deletions
|
|
@ -910,33 +910,47 @@ private:
|
||||||
auto supportedViewIndices = [[NSMutableIndexSet alloc] init];
|
auto supportedViewIndices = [[NSMutableIndexSet alloc] init];
|
||||||
auto n = [configs count];
|
auto n = [configs count];
|
||||||
|
|
||||||
if (auto* editor = _this (self)->getAudioProcessor().createEditorIfNeeded())
|
const auto getEditor = [&]
|
||||||
{
|
{
|
||||||
// If you hit this assertion then your plug-in's editor is reporting that it doesn't support
|
if (auto* editor = _this (self)->getAudioProcessor().getActiveEditor())
|
||||||
// any host MIDI controller configurations!
|
return editor;
|
||||||
jassert (editor->supportsHostMIDIControllerPresence (true) || editor->supportsHostMIDIControllerPresence (false));
|
|
||||||
|
|
||||||
for (auto i = 0u; i < n; ++i)
|
return _this (self)->getAudioProcessor().createEditorIfNeeded();
|
||||||
|
};
|
||||||
|
|
||||||
|
MessageManager::callSync ([&]
|
||||||
|
{
|
||||||
|
if (auto* editor = getEditor())
|
||||||
{
|
{
|
||||||
if (auto viewConfiguration = [configs objectAtIndex: i])
|
// 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));
|
||||||
|
|
||||||
|
for (auto i = 0u; i < n; ++i)
|
||||||
{
|
{
|
||||||
if (editor->supportsHostMIDIControllerPresence ([viewConfiguration hostHasController] == YES))
|
if (auto viewConfiguration = [configs objectAtIndex: i])
|
||||||
{
|
{
|
||||||
auto* constrainer = editor->getConstrainer();
|
if (editor->supportsHostMIDIControllerPresence ([viewConfiguration hostHasController] == YES))
|
||||||
auto height = (int) [viewConfiguration height];
|
{
|
||||||
auto width = (int) [viewConfiguration width];
|
auto* constrainer = editor->getConstrainer();
|
||||||
|
auto height = (int) [viewConfiguration height];
|
||||||
|
auto width = (int) [viewConfiguration width];
|
||||||
|
|
||||||
const auto maxLimits = std::numeric_limits<int>::max() / 2;
|
const auto maxLimits = std::numeric_limits<int>::max() / 2;
|
||||||
const Rectangle<int> requestedBounds { width, height };
|
const Rectangle<int> requestedBounds { width, height };
|
||||||
auto modifiedBounds = requestedBounds;
|
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)
|
if (modifiedBounds == requestedBounds)
|
||||||
[supportedViewIndices addIndex: i];
|
[supportedViewIndices addIndex: i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return [supportedViewIndices autorelease];
|
return [supportedViewIndices autorelease];
|
||||||
});
|
});
|
||||||
|
|
@ -1972,14 +1986,14 @@ public:
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
AUAudioUnit* createAudioUnit (const AudioComponentDescription& descr, NSError** error)
|
AUAudioUnit* createAudioUnit (const AudioComponentDescription& descr, NSError** error)
|
||||||
{
|
{
|
||||||
const auto holder = [&]
|
const auto holder = std::invoke ([&]
|
||||||
{
|
{
|
||||||
if (auto initialisedHolder = processorHolder.get())
|
if (auto initialisedHolder = processorHolder.get())
|
||||||
return initialisedHolder;
|
return initialisedHolder;
|
||||||
|
|
||||||
waitForExecutionOnMainThread ([this] { [myself view]; });
|
MessageManager::callSync ([this] { [myself view]; });
|
||||||
return processorHolder.get();
|
return processorHolder.get();
|
||||||
}();
|
});
|
||||||
|
|
||||||
if (holder == nullptr)
|
if (holder == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
@ -1988,25 +2002,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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
|
// There's a chance that createAudioUnit will be called from a background
|
||||||
// thread while the processorHolder is being updated on the main thread.
|
// thread while the processorHolder is being updated on the main thread.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue