From 14d39d71fb43ebdd29ea8dd202d6462f39d8a990 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 26 May 2015 09:19:51 +0200 Subject: [PATCH] Separate class define/implementation of OSX audio processor utils --- .../juce_audio_processors.cpp | 98 +++++++++++-------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/modules/juce_audio_processors/juce_audio_processors.cpp b/modules/juce_audio_processors/juce_audio_processors.cpp index d1f1679fba..2957e0dad6 100644 --- a/modules/juce_audio_processors/juce_audio_processors.cpp +++ b/modules/juce_audio_processors/juce_audio_processors.cpp @@ -79,61 +79,73 @@ static inline bool arrayContainsPlugin (const OwnedArray& lis #if JUCE_MAC //============================================================================== -struct AutoResizingNSViewComponent : public NSViewComponent, - private AsyncUpdater -{ - AutoResizingNSViewComponent() : recursive (false) {} - - void childBoundsChanged (Component*) override - { - if (recursive) - { - triggerAsyncUpdate(); - } - else - { - recursive = true; - resizeToFitView(); - recursive = true; - } - } - - void handleAsyncUpdate() override { resizeToFitView(); } - + +struct AutoResizingNSViewComponent : public NSViewComponent, + private AsyncUpdater { + AutoResizingNSViewComponent(); + void childBoundsChanged(Component*) override; + void handleAsyncUpdate() override; bool recursive; }; +struct AutoResizingNSViewComponentWithParent : public AutoResizingNSViewComponent, + private Timer { + AutoResizingNSViewComponentWithParent(); + NSView* getChildView() const; + void timerCallback() override; +}; + //============================================================================== -struct AutoResizingNSViewComponentWithParent : public AutoResizingNSViewComponent, - private Timer + +AutoResizingNSViewComponent::AutoResizingNSViewComponent() + : recursive (false) {} + +void AutoResizingNSViewComponent::childBoundsChanged(Component*) { - AutoResizingNSViewComponentWithParent() + if (recursive) { - NSView* v = [[NSView alloc] init]; - setView (v); - [v release]; - - startTimer (30); + triggerAsyncUpdate(); } - - NSView* getChildView() const + else { - if (NSView* parent = (NSView*) getView()) - if ([[parent subviews] count] > 0) - return [[parent subviews] objectAtIndex: 0]; - - return nil; + recursive = true; + resizeToFitView(); + recursive = true; } +} - void timerCallback() override +void AutoResizingNSViewComponent::handleAsyncUpdate() +{ + resizeToFitView(); +} + +AutoResizingNSViewComponentWithParent::AutoResizingNSViewComponentWithParent() +{ + NSView* v = [[NSView alloc] init]; + setView (v); + [v release]; + + startTimer(500); +} + +NSView* AutoResizingNSViewComponentWithParent::getChildView() const +{ + if (NSView* parent = (NSView*)getView()) + if ([[parent subviews] count] > 0) + return [[parent subviews] objectAtIndex: 0]; + + return nil; +} + +void AutoResizingNSViewComponentWithParent::timerCallback() +{ + if (NSView* child = getChildView()) { - if (NSView* child = getChildView()) - { - stopTimer(); - setView (child); - } + stopTimer(); + setView(child); } -}; +} + #endif #if JUCE_CLANG