Browse Source

VSTWindowUtilities: Remove unused JUCE_32BIT checks in VSTWindowUtilities

v7.0.9
reuk 2 years ago
parent
commit
22c8f0fe7e
No known key found for this signature in database GPG Key ID: FCB43929F012EE5C
4 changed files with 14 additions and 315 deletions
  1. +3
    -39
      modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp
  2. +2
    -8
      modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp
  3. +3
    -23
      modules/juce_audio_plugin_client/detail/juce_VSTWindowUtilities.h
  4. +6
    -245
      modules/juce_audio_plugin_client/detail/juce_VSTWindowUtilities.mm

+ 3
- 39
modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp View File

@@ -795,9 +795,6 @@ public:
chunkMemoryTime = 0; chunkMemoryTime = 0;
} }
} }
if (editorComp != nullptr)
editorComp->checkVisibility();
} }
void setHasEditorFlag (bool shouldSetHasEditor) void setHasEditorFlag (bool shouldSetHasEditor)
@@ -1009,7 +1006,7 @@ public:
startTimer (500); startTimer (500);
#endif #endif
#elif JUCE_MAC #elif JUCE_MAC
hostWindow = detail::VSTWindowUtilities::attachComponentToWindowRefVST (this, desktopFlags, args.ptr, wrapper.useNSView);
hostWindow = detail::VSTWindowUtilities::attachComponentToWindowRefVST (this, desktopFlags, args.ptr);
#endif #endif
setVisible (true); setVisible (true);
@@ -1019,20 +1016,12 @@ public:
{ {
#if JUCE_MAC #if JUCE_MAC
if (hostWindow != nullptr) if (hostWindow != nullptr)
detail::VSTWindowUtilities::detachComponentFromWindowRefVST (this, hostWindow, wrapper.useNSView);
detail::VSTWindowUtilities::detachComponentFromWindowRefVST (this, hostWindow);
#endif #endif
hostWindow = {}; hostWindow = {};
} }
void checkVisibility()
{
#if JUCE_MAC
if (hostWindow != nullptr)
detail::VSTWindowUtilities::checkWindowVisibilityVST (hostWindow, this, wrapper.useNSView);
#endif
}
AudioProcessorEditor* getEditorComp() const noexcept AudioProcessorEditor* getEditorComp() const noexcept
{ {
return dynamic_cast<AudioProcessorEditor*> (getChildComponent (0)); return dynamic_cast<AudioProcessorEditor*> (getChildComponent (0));
@@ -1056,11 +1045,6 @@ public:
updateWindowSize(); updateWindowSize();
} }
#if JUCE_MAC && ! JUCE_64BIT
if (! wrapper.useNSView)
updateEditorCompBoundsVST (this);
#endif
} }
void parentSizeChanged() override void parentSizeChanged() override
@@ -1118,7 +1102,7 @@ public:
const ScopedValueSetter<bool> resizingParentSetter (resizingParent, true); const ScopedValueSetter<bool> resizingParentSetter (resizingParent, true);
#if JUCE_MAC #if JUCE_MAC
detail::VSTWindowUtilities::setNativeHostWindowSizeVST (hostWindow, this, newWidth, newHeight, wrapper.useNSView);
detail::VSTWindowUtilities::setNativeHostWindowSizeVST (hostWindow, this, newWidth, newHeight);
#elif JUCE_LINUX || JUCE_BSD #elif JUCE_LINUX || JUCE_BSD
// (Currently, all linux hosts support sizeWindow, so this should never need to happen) // (Currently, all linux hosts support sizeWindow, so this should never need to happen)
setSize (newWidth, newHeight); setSize (newWidth, newHeight);
@@ -1224,15 +1208,6 @@ public:
#endif #endif
#endif #endif
#if JUCE_MAC
bool keyPressed (const KeyPress&) override
{
// If we have an unused keypress, move the key-focus to a host window
// and re-inject the event..
return detail::VSTWindowUtilities::forwardCurrentKeyEventToHostVST (this, wrapper.useNSView);
}
#endif
private: private:
void updateWindowSize() void updateWindowSize()
{ {
@@ -1900,7 +1875,6 @@ private:
#if JUCE_MAC #if JUCE_MAC
if (matches ("hasCockosViewAsConfig")) if (matches ("hasCockosViewAsConfig"))
{ {
useNSView = true;
return (int32) 0xbeef0000; return (int32) 0xbeef0000;
} }
#endif #endif
@@ -2104,14 +2078,6 @@ private:
bool isProcessing = false, isBypassed = false, hasShutdown = false; bool isProcessing = false, isBypassed = false, hasShutdown = false;
bool firstProcessCallback = true, shouldDeleteEditor = false; bool firstProcessCallback = true, shouldDeleteEditor = false;
#if JUCE_MAC
#if JUCE_64BIT
bool useNSView = true;
#else
bool useNSView = false;
#endif
#endif
VstTempBuffers<float> floatTempBuffers; VstTempBuffers<float> floatTempBuffers;
VstTempBuffers<double> doubleTempBuffers; VstTempBuffers<double> doubleTempBuffers;
int maxNumInChannels = 0, maxNumOutChannels = 0; int maxNumInChannels = 0, maxNumOutChannels = 0;
@@ -2181,14 +2147,12 @@ JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wmissing-prototypes")
JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster); JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster);
JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster) JUCE_EXPORTED_FUNCTION Vst2::AEffect* VSTPluginMain (Vst2::audioMasterCallback audioMaster)
{ {
detail::VSTWindowUtilities::initialiseMacVST();
return pluginEntryPoint (audioMaster); return pluginEntryPoint (audioMaster);
} }
JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_macho (Vst2::audioMasterCallback audioMaster); JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_macho (Vst2::audioMasterCallback audioMaster);
JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_macho (Vst2::audioMasterCallback audioMaster) JUCE_EXPORTED_FUNCTION Vst2::AEffect* main_macho (Vst2::audioMasterCallback audioMaster)
{ {
detail::VSTWindowUtilities::initialiseMacVST();
return pluginEntryPoint (audioMaster); return pluginEntryPoint (audioMaster);
} }


+ 2
- 8
modules/juce_audio_plugin_client/VST3/juce_VST3_Wrapper.cpp View File

@@ -1799,8 +1799,7 @@ private:
#endif #endif
#else #else
isNSView = (strcmp (type, kPlatformTypeNSView) == 0);
macHostWindow = detail::VSTWindowUtilities::attachComponentToWindowRefVST (component.get(), desktopFlags, parent, isNSView);
macHostWindow = detail::VSTWindowUtilities::attachComponentToWindowRefVST (component.get(), desktopFlags, parent);
#endif #endif
component->resizeHostWindow(); component->resizeHostWindow();
@@ -1822,7 +1821,7 @@ private:
#elif JUCE_MAC #elif JUCE_MAC
if (macHostWindow != nullptr) if (macHostWindow != nullptr)
{ {
detail::VSTWindowUtilities::detachComponentFromWindowRefVST (component.get(), macHostWindow, isNSView);
detail::VSTWindowUtilities::detachComponentFromWindowRefVST (component.get(), macHostWindow);
macHostWindow = nullptr; macHostWindow = nullptr;
} }
#endif #endif
@@ -2288,7 +2287,6 @@ private:
#if JUCE_MAC #if JUCE_MAC
void* macHostWindow = nullptr; void* macHostWindow = nullptr;
bool isNSView = false;
// On macOS Cubase 10 resizes the host window after calling onSize() resulting in the peer // On macOS Cubase 10 resizes the host window after calling onSize() resulting in the peer
// bounds being a step behind the plug-in. Calling updateBounds() asynchronously seems to fix things... // bounds being a step behind the plug-in. Calling updateBounds() asynchronously seems to fix things...
@@ -3852,10 +3850,6 @@ JUCE_END_IGNORE_WARNINGS_GCC_LIKE
bool initModule(); bool initModule();
bool initModule() bool initModule()
{ {
#if JUCE_MAC
detail::VSTWindowUtilities::initialiseMacVST();
#endif
return true; return true;
} }


+ 3
- 23
modules/juce_audio_plugin_client/detail/juce_VSTWindowUtilities.h View File

@@ -36,37 +36,17 @@ struct VSTWindowUtilities
{ {
VSTWindowUtilities() = delete; VSTWindowUtilities() = delete;
#if ! JUCE_64BIT
static void updateEditorCompBoundsVST (Component* comp);
static pascal OSStatus viewBoundsChangedEvent (EventHandlerCallRef, EventRef, void* user);
static bool shouldManuallyCloseHostWindow();
#endif
static void* attachComponentToWindowRefVST (Component* comp, static void* attachComponentToWindowRefVST (Component* comp,
int desktopFlags, int desktopFlags,
void* parentWindowOrView,
bool isNSView);
void* parentWindowOrView);
static void detachComponentFromWindowRefVST (Component* comp, static void detachComponentFromWindowRefVST (Component* comp,
void* window,
bool isNSView);
static void initialiseMacVST();
void* window);
static void setNativeHostWindowSizeVST (void* window, static void setNativeHostWindowSizeVST (void* window,
Component* component, Component* component,
int newWidth, int newWidth,
int newHeight,
bool isNSView);
static void checkWindowVisibilityVST (void* window,
Component* comp,
bool isNSView);
static bool forwardCurrentKeyEventToHostVST (Component* comp,
bool isNSView);
int newHeight);
}; };
} // namespace juce::detail } // namespace juce::detail


+ 6
- 245
modules/juce_audio_plugin_client/detail/juce_VSTWindowUtilities.mm View File

@@ -36,158 +36,17 @@
namespace juce::detail namespace juce::detail
{ {
#if JUCE_32BIT
class EventReposter : private CallbackMessage
{
public:
EventReposter() : e ([[NSApp currentEvent] retain]) {}
~EventReposter() override { [e release]; }
static void repostCurrentNSEvent()
{
(new EventReposter())->post();
}
private:
void messageCallback() override
{
[NSApp postEvent: e atStart: YES];
}
NSEvent* e;
};
void VSTWindowUtilities::updateEditorCompBoundsVST (Component* comp)
{
HIViewRef dummyView = (HIViewRef) (void*) (pointer_sized_int)
comp->getProperties() ["dummyViewRef"].toString().getHexValue64();
HIRect r;
HIViewGetFrame (dummyView, &r);
HIViewRef root;
HIViewFindByID (HIViewGetRoot (HIViewGetWindow (dummyView)), kHIViewWindowContentID, &root);
HIViewConvertRect (&r, HIViewGetSuperview (dummyView), root);
Rect windowPos;
GetWindowBounds (HIViewGetWindow (dummyView), kWindowContentRgn, &windowPos);
comp->setTopLeftPosition ((int) (windowPos.left + r.origin.x),
(int) (windowPos.top + r.origin.y));
}
pascal OSStatus VSTWindowUtilities::viewBoundsChangedEvent (EventHandlerCallRef, EventRef, void* user)
{
updateEditorCompBoundsVST ((Component*) user);
return noErr;
}
bool VSTWindowUtilities::shouldManuallyCloseHostWindow()
{
return getHostType().isCubase7orLater()
|| getHostType().isRenoise()
|| ((SystemStats::getOperatingSystemType() & 0xff) >= 12);
}
#endif
void* VSTWindowUtilities::attachComponentToWindowRefVST (Component* comp, void* VSTWindowUtilities::attachComponentToWindowRefVST (Component* comp,
int desktopFlags, int desktopFlags,
void* parentWindowOrView,
[[maybe_unused]] bool isNSView)
void* parentWindowOrView)
{ {
JUCE_AUTORELEASEPOOL JUCE_AUTORELEASEPOOL
{ {
#if ! JUCE_64BIT
if (! isNSView)
{
NSWindow* hostWindow = [[NSWindow alloc] initWithWindowRef: parentWindowOrView];
if (shouldManuallyCloseHostWindow())
{
[hostWindow setReleasedWhenClosed: NO];
}
else
{
[hostWindow retain];
[hostWindow setReleasedWhenClosed: YES];
}
[hostWindow setCanHide: YES];
HIViewRef parentView = 0;
WindowAttributes attributes;
GetWindowAttributes ((WindowRef) parentWindowOrView, &attributes);
if ((attributes & kWindowCompositingAttribute) != 0)
{
HIViewRef root = HIViewGetRoot ((WindowRef) parentWindowOrView);
HIViewFindByID (root, kHIViewWindowContentID, &parentView);
if (parentView == 0)
parentView = root;
}
else
{
GetRootControl ((WindowRef) parentWindowOrView, (ControlRef*) &parentView);
if (parentView == 0)
CreateRootControl ((WindowRef) parentWindowOrView, (ControlRef*) &parentView);
}
// It seems that the only way to successfully position our overlaid window is by putting a dummy
// HIView into the host's carbon window, and then catching events to see when it gets repositioned
HIViewRef dummyView = 0;
HIImageViewCreate (0, &dummyView);
HIRect r = { {0, 0}, { (float) comp->getWidth(), (float) comp->getHeight()} };
HIViewSetFrame (dummyView, &r);
HIViewAddSubview (parentView, dummyView);
comp->getProperties().set ("dummyViewRef", String::toHexString ((pointer_sized_int) (void*) dummyView));
EventHandlerRef ref;
const EventTypeSpec kControlBoundsChangedEvent = { kEventClassControl, kEventControlBoundsChanged };
InstallEventHandler (GetControlEventTarget (dummyView),
NewEventHandlerUPP (viewBoundsChangedEvent),
1,
&kControlBoundsChangedEvent,
(void*) comp,
&ref);
comp->getProperties().set ("boundsEventRef", String::toHexString ((pointer_sized_int) (void*) ref));
updateEditorCompBoundsVST (comp);
const auto defaultFlags =
#if ! JucePlugin_EditorRequiresKeyboardFocus
ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses;
#else
ComponentPeer::windowIsTemporary;
#endif
comp->addToDesktop (desktopFlags | defaultFlags);
comp->setVisible (true);
comp->toFront (false);
NSView* pluginView = (NSView*) comp->getWindowHandle();
NSWindow* pluginWindow = [pluginView window];
[pluginWindow setExcludedFromWindowsMenu: YES];
[pluginWindow setCanHide: YES];
[hostWindow addChildWindow: pluginWindow
ordered: NSWindowAbove];
[hostWindow orderFront: nil];
[pluginWindow orderFront: nil];
return hostWindow;
}
#endif
NSView* parentView = [(NSView*) parentWindowOrView retain]; NSView* parentView = [(NSView*) parentWindowOrView retain];
const auto defaultFlags =
#if JucePlugin_EditorRequiresKeyboardFocus
0;
#else
ComponentPeer::windowIgnoresKeyPresses;
#endif
const auto defaultFlags = JucePlugin_EditorRequiresKeyboardFocus
? 0
: ComponentPeer::windowIgnoresKeyPresses;
comp->addToDesktop (desktopFlags | defaultFlags, parentView); comp->addToDesktop (desktopFlags | defaultFlags, parentView);
// (this workaround is because Wavelab provides a zero-size parent view..) // (this workaround is because Wavelab provides a zero-size parent view..)
@@ -202,94 +61,22 @@ void* VSTWindowUtilities::attachComponentToWindowRefVST (Component* comp,
} }
} }
void VSTWindowUtilities::detachComponentFromWindowRefVST (Component* comp,
void* window,
[[maybe_unused]] bool isNSView)
void VSTWindowUtilities::detachComponentFromWindowRefVST (Component* comp, void* window)
{ {
JUCE_AUTORELEASEPOOL JUCE_AUTORELEASEPOOL
{ {
#if ! JUCE_64BIT
if (! isNSView)
{
EventHandlerRef ref = (EventHandlerRef) (void*) (pointer_sized_int)
comp->getProperties() ["boundsEventRef"].toString().getHexValue64();
RemoveEventHandler (ref);
CFUniquePtr<HIViewRef> dummyView ((HIViewRef) (void*) (pointer_sized_int)
comp->getProperties() ["dummyViewRef"].toString().getHexValue64());
if (HIViewIsValid (dummyView.get()))
dummyView = nullptr;
NSWindow* hostWindow = (NSWindow*) window;
NSView* pluginView = (NSView*) comp->getWindowHandle();
NSWindow* pluginWindow = [pluginView window];
[pluginView retain];
[hostWindow removeChildWindow: pluginWindow];
[pluginWindow close];
comp->removeFromDesktop();
[pluginView release];
if (shouldManuallyCloseHostWindow())
[hostWindow close];
else
[hostWindow release];
#if JUCE_MODAL_LOOPS_PERMITTED
static bool needToRunMessageLoop = ! getHostType().isReaper();
// The event loop needs to be run between closing the window and deleting the plugin,
// presumably to let the cocoa objects get tidied up. Leaving out this line causes crashes
// in Live when you delete the plugin with its window open.
// (Doing it this way rather than using a single longer timeout means that we can guarantee
// how many messages will be dispatched, which seems to be vital in Reaper)
if (needToRunMessageLoop)
for (int i = 20; --i >= 0;)
MessageManager::getInstance()->runDispatchLoopUntil (1);
#endif
return;
}
#endif
comp->removeFromDesktop(); comp->removeFromDesktop();
[(id) window release]; [(id) window release];
} }
} }
void VSTWindowUtilities::initialiseMacVST()
{
#if ! JUCE_64BIT
NSApplicationLoad();
#endif
}
void VSTWindowUtilities::setNativeHostWindowSizeVST (void* window, void VSTWindowUtilities::setNativeHostWindowSizeVST (void* window,
Component* component, Component* component,
int newWidth, int newWidth,
int newHeight,
[[maybe_unused]] bool isNSView)
int newHeight)
{ {
JUCE_AUTORELEASEPOOL JUCE_AUTORELEASEPOOL
{ {
#if ! JUCE_64BIT
if (! isNSView)
{
if (HIViewRef dummyView = (HIViewRef) (void*) (pointer_sized_int)
component->getProperties() ["dummyViewRef"].toString().getHexValue64())
{
HIRect frameRect;
HIViewGetFrame (dummyView, &frameRect);
frameRect.size.width = newWidth;
frameRect.size.height = newHeight;
HIViewSetFrame (dummyView, &frameRect);
}
return;
}
#endif
if (NSView* hostView = (NSView*) window) if (NSView* hostView = (NSView*) window)
{ {
const int dx = newWidth - component->getWidth(); const int dx = newWidth - component->getWidth();
@@ -304,32 +91,6 @@ void VSTWindowUtilities::setNativeHostWindowSizeVST (void* window,
} }
} }
void VSTWindowUtilities::checkWindowVisibilityVST ([[maybe_unused]] void* window,
[[maybe_unused]] Component* comp,
[[maybe_unused]] bool isNSView)
{
#if ! JUCE_64BIT
if (! isNSView)
comp->setVisible ([((NSWindow*) window) isVisible]);
#endif
}
bool VSTWindowUtilities::forwardCurrentKeyEventToHostVST ([[maybe_unused]] Component* comp,
[[maybe_unused]] bool isNSView)
{
#if ! JUCE_64BIT
if (! isNSView)
{
NSWindow* win = [(NSView*) comp->getWindowHandle() window];
[[win parentWindow] makeKeyWindow];
EventReposter::repostCurrentNSEvent();
return true;
}
#endif
return false;
}
} // namespace juce::detail } // namespace juce::detail
#endif #endif

Loading…
Cancel
Save