Browse Source

small tweaks to mac messaging and VST windowing; added code to name the drawables after their 'id' tag when parsing SVG

tags/2021-05-28
jules 16 years ago
parent
commit
9992bb6790
4 changed files with 658 additions and 648 deletions
  1. +467
    -467
      build/macosx/platform_specific_code/juce_mac_MessageManager.mm
  2. +179
    -171
      extras/audio plugins/wrapper/VST/juce_VST_Wrapper.mm
  3. +11
    -10
      juce_amalgamated.cpp
  4. +1
    -0
      src/juce_appframework/gui/graphics/drawables/juce_SVGParser.cpp

+ 467
- 467
build/macosx/platform_specific_code/juce_mac_MessageManager.mm View File

@@ -1,467 +1,467 @@
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.
==============================================================================
*/
// (This file gets included by juce_mac_NativeCode.mm, rather than being
// compiled on its own).
#ifdef JUCE_INCLUDED_FILE
struct CallbackMessagePayload
{
MessageCallbackFunction* function;
void* parameter;
void* volatile result;
bool volatile hasBeenExecuted;
};
/* When you use multiple DLLs which share similarly-named obj-c classes - like
for example having more than one juce plugin loaded into a host, then when a
method is called, the actual code that runs might actually be in a different module
than the one you expect... So any calls to library functions or statics that are
made inside obj-c methods will probably end up getting executed in a different DLL's
memory space. Not a great thing to happen - this obviously leads to bizarre crashes.
To work around this insanity, I'm only allowing obj-c methods to make calls to
virtual methods of an object that's known to live inside the right module's space.
*/
class AppDelegateRedirector
{
public:
AppDelegateRedirector() {}
virtual ~AppDelegateRedirector() {}
virtual NSApplicationTerminateReply shouldTerminate()
{
if (JUCEApplication::getInstance() != 0)
{
JUCEApplication::getInstance()->systemRequestedQuit();
return NSTerminateCancel;
}
return NSTerminateNow;
}
virtual BOOL openFile (const NSString* filename)
{
if (JUCEApplication::getInstance() != 0)
{
JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
return YES;
}
return NO;
}
virtual void openFiles (NSArray* filenames)
{
StringArray files;
for (unsigned int i = 0; i < [filenames count]; ++i)
files.add (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
if (files.size() > 0 && JUCEApplication::getInstance() != 0)
{
JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
}
}
virtual void focusChanged()
{
juce_HandleProcessFocusChange();
}
virtual void deliverMessage (void* message)
{
// no need for an mm lock here - deliverMessage locks it
MessageManager::getInstance()->deliverMessage (message);
}
virtual void performCallback (CallbackMessagePayload* pl)
{
pl->result = (*pl->function) (pl->parameter);
pl->hasBeenExecuted = true;
}
virtual void deleteSelf()
{
delete this;
}
};
END_JUCE_NAMESPACE
using namespace JUCE_NAMESPACE;
#define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
static int numPendingMessages = 0;
@interface JuceAppDelegate : NSObject
{
@private
id oldDelegate;
AppDelegateRedirector* redirector;
bool flushingMessages;
}
- (JuceAppDelegate*) init;
- (void) dealloc;
- (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
- (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
- (void) applicationDidBecomeActive: (NSNotification*) aNotification;
- (void) applicationDidResignActive: (NSNotification*) aNotification;
- (void) applicationWillUnhide: (NSNotification*) aNotification;
- (void) customEvent: (id) data;
- (void) performCallback: (id) info;
- (void) dummyMethod;
@end
@implementation JuceAppDelegate
- (JuceAppDelegate*) init
{
[super init];
redirector = new AppDelegateRedirector();
numPendingMessages = 0;
flushingMessages = false;
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
if (JUCEApplication::getInstance() != 0)
{
oldDelegate = [NSApp delegate];
[NSApp setDelegate: self];
}
else
{
oldDelegate = 0;
[center addObserver: self selector: @selector (applicationDidResignActive:)
name: NSApplicationDidResignActiveNotification object: NSApp];
[center addObserver: self selector: @selector (applicationDidBecomeActive:)
name: NSApplicationDidBecomeActiveNotification object: NSApp];
[center addObserver: self selector: @selector (applicationWillUnhide:)
name: NSApplicationWillUnhideNotification object: NSApp];
}
return self;
}
- (void) dealloc
{
if (oldDelegate != 0)
[NSApp setDelegate: oldDelegate];
redirector->deleteSelf();
[super dealloc];
}
- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
{
return redirector->shouldTerminate();
}
- (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
{
return redirector->openFile (filename);
}
- (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
{
return redirector->openFiles (filenames);
}
- (void) applicationDidBecomeActive: (NSNotification*) aNotification
{
redirector->focusChanged();
}
- (void) applicationDidResignActive: (NSNotification*) aNotification
{
redirector->focusChanged();
}
- (void) applicationWillUnhide: (NSNotification*) aNotification
{
redirector->focusChanged();
}
- (void) customEvent: (id) n
{
atomicDecrement (numPendingMessages);
[self release];
NSData* data = (NSData*) n;
void* message = 0;
[data getBytes: &message length: sizeof (message)];
if (message != 0 && ! flushingMessages)
redirector->deliverMessage (message);
[data release];
}
- (void) performCallback: (id) info
{
if ([info isKindOfClass: [NSData class]])
{
CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
if (pl != 0)
redirector->performCallback (pl);
}
else
{
jassertfalse // should never get here!
}
}
- (void) dummyMethod {} // (used as a way of running a dummy thread)
@end
BEGIN_JUCE_NAMESPACE
static JuceAppDelegate* juceAppDelegate = 0;
void MessageManager::runDispatchLoop()
{
if (! quitMessagePosted) // check that the quit message wasn't already posted..
{
const ScopedAutoReleasePool pool;
// must only be called by the message thread!
jassert (isThisTheMessageThread());
[NSApp run];
}
}
void MessageManager::stopDispatchLoop()
{
quitMessagePosted = true;
[NSApp stop: nil];
[NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
}
static bool isEventBlockedByModalComps (NSEvent* e)
{
if (Component::getNumCurrentlyModalComponents() == 0)
return false;
NSWindow* const w = [e window];
if (w == 0 || [w worksWhenModal])
return false;
bool isKey = false, isInputAttempt = false;
switch ([e type])
{
case NSKeyDown:
case NSKeyUp:
isKey = isInputAttempt = true;
break;
case NSLeftMouseDown:
case NSRightMouseDown:
case NSOtherMouseDown:
isInputAttempt = true;
break;
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSLeftMouseUp:
case NSRightMouseUp:
case NSOtherMouseUp:
case NSOtherMouseDragged:
if (Component::getComponentUnderMouse() != 0)
return false;
break;
case NSMouseMoved:
case NSMouseEntered:
case NSMouseExited:
case NSCursorUpdate:
case NSScrollWheel:
case NSTabletPoint:
case NSTabletProximity:
break;
default:
return false;
}
for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
{
ComponentPeer* const peer = ComponentPeer::getPeer (i);
NSView* const compView = (NSView*) peer->getNativeHandle();
if ([compView window] == w)
{
if (isKey)
{
if (compView == [w firstResponder])
return false;
}
else
{
if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
[compView bounds]))
return false;
}
}
}
if (isInputAttempt)
{
if (! [NSApp isActive])
[NSApp activateIgnoringOtherApps: YES];
Component* const modal = Component::getCurrentlyModalComponent (0);
if (modal != 0)
modal->inputAttemptWhenModal();
}
return true;
}
bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
{
const ScopedAutoReleasePool pool;
jassert (isThisTheMessageThread()); // must only be called by the message thread
uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
while (Time::getMillisecondCounter() < endTime && ! quitMessagePosted)
{
const ScopedAutoReleasePool pool;
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: endDate];
NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
untilDate: endDate
inMode: NSDefaultRunLoopMode
dequeue: YES];
if (e != 0 && ! isEventBlockedByModalComps (e))
[NSApp sendEvent: e];
}
return ! quitMessagePosted;
}
//==============================================================================
void MessageManager::doPlatformSpecificInitialisation()
{
if (juceAppDelegate == 0)
juceAppDelegate = [[JuceAppDelegate alloc] init];
// This launches a dummy thread, which forces Cocoa to initialise NSThreads
// correctly (needed prior to 10.5)
if (! [NSThread isMultiThreaded])
[NSThread detachNewThreadSelector: @selector (dummyMethod)
toTarget: juceAppDelegate
withObject: nil];
initialiseMainMenu();
}
void MessageManager::doPlatformSpecificShutdown()
{
if (juceAppDelegate != 0)
{
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
[[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
// Annoyingly, cancelPerformSelectorsWithTarget can't actually cancel the messages
// sent by performSelectorOnMainThread, so need to manually flush these before quitting..
juceAppDelegate->flushingMessages = true;
if (JUCEApplication::getInstance() != 0) // (must avoid blocking here when running as a plugin)
for (int i = 100; --i >= 0 && numPendingMessages > 0;)
getInstance()->runDispatchLoopUntil (10);
[juceAppDelegate release];
juceAppDelegate = 0;
}
}
bool juce_postMessageToSystemQueue (void* message)
{
atomicIncrement (numPendingMessages);
[juceAppDelegate retain];
[juceAppDelegate performSelectorOnMainThread: @selector (customEvent:)
withObject: (id) [[NSData alloc] initWithBytes: &message
length: (int) sizeof (message)]
waitUntilDone: NO];
return true;
}
void MessageManager::broadcastMessage (const String& value) throw()
{
}
void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
void* data)
{
if (isThisTheMessageThread())
{
return (*callback) (data);
}
else
{
// If a thread has a MessageManagerLock and then tries to call this method, it'll
// deadlock because the message manager is blocked from running, so can never
// call your function..
jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
const ScopedAutoReleasePool pool;
CallbackMessagePayload cmp;
cmp.function = callback;
cmp.parameter = data;
cmp.result = 0;
cmp.hasBeenExecuted = false;
[juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
withObject: [NSData dataWithBytesNoCopy: &cmp
length: sizeof (cmp)
freeWhenDone: NO]
waitUntilDone: YES];
return cmp.result;
}
}
#endif
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.
==============================================================================
*/
// (This file gets included by juce_mac_NativeCode.mm, rather than being
// compiled on its own).
#ifdef JUCE_INCLUDED_FILE
struct CallbackMessagePayload
{
MessageCallbackFunction* function;
void* parameter;
void* volatile result;
bool volatile hasBeenExecuted;
};
/* When you use multiple DLLs which share similarly-named obj-c classes - like
for example having more than one juce plugin loaded into a host, then when a
method is called, the actual code that runs might actually be in a different module
than the one you expect... So any calls to library functions or statics that are
made inside obj-c methods will probably end up getting executed in a different DLL's
memory space. Not a great thing to happen - this obviously leads to bizarre crashes.
To work around this insanity, I'm only allowing obj-c methods to make calls to
virtual methods of an object that's known to live inside the right module's space.
*/
class AppDelegateRedirector
{
public:
AppDelegateRedirector() {}
virtual ~AppDelegateRedirector() {}
virtual NSApplicationTerminateReply shouldTerminate()
{
if (JUCEApplication::getInstance() != 0)
{
JUCEApplication::getInstance()->systemRequestedQuit();
return NSTerminateCancel;
}
return NSTerminateNow;
}
virtual BOOL openFile (const NSString* filename)
{
if (JUCEApplication::getInstance() != 0)
{
JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
return YES;
}
return NO;
}
virtual void openFiles (NSArray* filenames)
{
StringArray files;
for (unsigned int i = 0; i < [filenames count]; ++i)
files.add (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
if (files.size() > 0 && JUCEApplication::getInstance() != 0)
{
JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
}
}
virtual void focusChanged()
{
juce_HandleProcessFocusChange();
}
virtual void deliverMessage (void* message)
{
// no need for an mm lock here - deliverMessage locks it
MessageManager::getInstance()->deliverMessage (message);
}
virtual void performCallback (CallbackMessagePayload* pl)
{
pl->result = (*pl->function) (pl->parameter);
pl->hasBeenExecuted = true;
}
virtual void deleteSelf()
{
delete this;
}
};
END_JUCE_NAMESPACE
using namespace JUCE_NAMESPACE;
#define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
static int numPendingMessages = 0;
@interface JuceAppDelegate : NSObject
{
@private
id oldDelegate;
AppDelegateRedirector* redirector;
@public
bool flushingMessages;
}
- (JuceAppDelegate*) init;
- (void) dealloc;
- (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
- (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
- (void) applicationDidBecomeActive: (NSNotification*) aNotification;
- (void) applicationDidResignActive: (NSNotification*) aNotification;
- (void) applicationWillUnhide: (NSNotification*) aNotification;
- (void) customEvent: (id) data;
- (void) performCallback: (id) info;
- (void) dummyMethod;
@end
@implementation JuceAppDelegate
- (JuceAppDelegate*) init
{
[super init];
redirector = new AppDelegateRedirector();
numPendingMessages = 0;
flushingMessages = false;
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
if (JUCEApplication::getInstance() != 0)
{
oldDelegate = [NSApp delegate];
[NSApp setDelegate: self];
}
else
{
oldDelegate = 0;
[center addObserver: self selector: @selector (applicationDidResignActive:)
name: NSApplicationDidResignActiveNotification object: NSApp];
[center addObserver: self selector: @selector (applicationDidBecomeActive:)
name: NSApplicationDidBecomeActiveNotification object: NSApp];
[center addObserver: self selector: @selector (applicationWillUnhide:)
name: NSApplicationWillUnhideNotification object: NSApp];
}
return self;
}
- (void) dealloc
{
if (oldDelegate != 0)
[NSApp setDelegate: oldDelegate];
redirector->deleteSelf();
[super dealloc];
}
- (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
{
return redirector->shouldTerminate();
}
- (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
{
return redirector->openFile (filename);
}
- (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
{
return redirector->openFiles (filenames);
}
- (void) applicationDidBecomeActive: (NSNotification*) aNotification
{
redirector->focusChanged();
}
- (void) applicationDidResignActive: (NSNotification*) aNotification
{
redirector->focusChanged();
}
- (void) applicationWillUnhide: (NSNotification*) aNotification
{
redirector->focusChanged();
}
- (void) customEvent: (id) n
{
atomicDecrement (numPendingMessages);
NSData* data = (NSData*) n;
void* message = 0;
[data getBytes: &message length: sizeof (message)];
if (message != 0 && ! flushingMessages)
redirector->deliverMessage (message);
}
- (void) performCallback: (id) info
{
if ([info isKindOfClass: [NSData class]])
{
CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
if (pl != 0)
redirector->performCallback (pl);
}
else
{
jassertfalse // should never get here!
}
}
- (void) dummyMethod {} // (used as a way of running a dummy thread)
@end
BEGIN_JUCE_NAMESPACE
static JuceAppDelegate* juceAppDelegate = 0;
void MessageManager::runDispatchLoop()
{
if (! quitMessagePosted) // check that the quit message wasn't already posted..
{
const ScopedAutoReleasePool pool;
// must only be called by the message thread!
jassert (isThisTheMessageThread());
[NSApp run];
}
}
void MessageManager::stopDispatchLoop()
{
quitMessagePosted = true;
[NSApp stop: nil];
[NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
}
static bool isEventBlockedByModalComps (NSEvent* e)
{
if (Component::getNumCurrentlyModalComponents() == 0)
return false;
NSWindow* const w = [e window];
if (w == 0 || [w worksWhenModal])
return false;
bool isKey = false, isInputAttempt = false;
switch ([e type])
{
case NSKeyDown:
case NSKeyUp:
isKey = isInputAttempt = true;
break;
case NSLeftMouseDown:
case NSRightMouseDown:
case NSOtherMouseDown:
isInputAttempt = true;
break;
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSLeftMouseUp:
case NSRightMouseUp:
case NSOtherMouseUp:
case NSOtherMouseDragged:
if (Component::getComponentUnderMouse() != 0)
return false;
break;
case NSMouseMoved:
case NSMouseEntered:
case NSMouseExited:
case NSCursorUpdate:
case NSScrollWheel:
case NSTabletPoint:
case NSTabletProximity:
break;
default:
return false;
}
for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
{
ComponentPeer* const peer = ComponentPeer::getPeer (i);
NSView* const compView = (NSView*) peer->getNativeHandle();
if ([compView window] == w)
{
if (isKey)
{
if (compView == [w firstResponder])
return false;
}
else
{
if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
[compView bounds]))
return false;
}
}
}
if (isInputAttempt)
{
if (! [NSApp isActive])
[NSApp activateIgnoringOtherApps: YES];
Component* const modal = Component::getCurrentlyModalComponent (0);
if (modal != 0)
modal->inputAttemptWhenModal();
}
return true;
}
bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
{
const ScopedAutoReleasePool pool;
jassert (isThisTheMessageThread()); // must only be called by the message thread
uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
while (Time::getMillisecondCounter() < endTime && ! quitMessagePosted)
{
const ScopedAutoReleasePool pool;
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: endDate];
NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
untilDate: endDate
inMode: NSDefaultRunLoopMode
dequeue: YES];
if (e != 0 && ! isEventBlockedByModalComps (e))
[NSApp sendEvent: e];
}
return ! quitMessagePosted;
}
//==============================================================================
void MessageManager::doPlatformSpecificInitialisation()
{
if (juceAppDelegate == 0)
juceAppDelegate = [[JuceAppDelegate alloc] init];
// This launches a dummy thread, which forces Cocoa to initialise NSThreads
// correctly (needed prior to 10.5)
if (! [NSThread isMultiThreaded])
[NSThread detachNewThreadSelector: @selector (dummyMethod)
toTarget: juceAppDelegate
withObject: nil];
initialiseMainMenu();
}
void MessageManager::doPlatformSpecificShutdown()
{
if (juceAppDelegate != 0)
{
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
[[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
// Annoyingly, cancelPerformSelectorsWithTarget can't actually cancel the messages
// sent by performSelectorOnMainThread, so need to manually flush these before quitting..
juceAppDelegate->flushingMessages = true;
for (int i = 100; --i >= 0 && numPendingMessages > 0;)
{
const ScopedAutoReleasePool pool;
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: [NSDate dateWithTimeIntervalSinceNow: 5 * 0.001]];
}
[juceAppDelegate release];
juceAppDelegate = 0;
}
}
bool juce_postMessageToSystemQueue (void* message)
{
atomicIncrement (numPendingMessages);
[juceAppDelegate performSelectorOnMainThread: @selector (customEvent:)
withObject: (id) [NSData dataWithBytes: &message length: (int) sizeof (message)]
waitUntilDone: NO];
return true;
}
void MessageManager::broadcastMessage (const String& value) throw()
{
}
void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
void* data)
{
if (isThisTheMessageThread())
{
return (*callback) (data);
}
else
{
// If a thread has a MessageManagerLock and then tries to call this method, it'll
// deadlock because the message manager is blocked from running, so can never
// call your function..
jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
const ScopedAutoReleasePool pool;
CallbackMessagePayload cmp;
cmp.function = callback;
cmp.parameter = data;
cmp.result = 0;
cmp.hasBeenExecuted = false;
[juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
withObject: [NSData dataWithBytesNoCopy: &cmp
length: sizeof (cmp)
freeWhenDone: NO]
waitUntilDone: YES];
return cmp.result;
}
}
#endif

+ 179
- 171
extras/audio plugins/wrapper/VST/juce_VST_Wrapper.mm View File

@@ -1,171 +1,179 @@
/*
==============================================================================
This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.
------------------------------------------------------------------------------
JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
------------------------------------------------------------------------------
If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.
==============================================================================
*/
//==============================================================================
#include "../juce_IncludeCharacteristics.h"
#if JucePlugin_Build_VST
#include <Cocoa/Cocoa.h>
#define ADD_CARBON_BODGE 1 // see note below..
#if ADD_CARBON_BODGE
#include <Carbon/Carbon.h>
#endif
#include "../juce_PluginHeaders.h"
//==============================================================================
BEGIN_JUCE_NAMESPACE
#if ADD_CARBON_BODGE
/* When you wrap a WindowRef as an NSWindow, it seems to bugger up the HideWindow
function, so when the host tries (and fails) to hide the window, this catches
the event and does the job properly.
*/
static pascal OSStatus windowVisibilityBodge (EventHandlerCallRef, EventRef e, void* user)
{
NSWindow* hostWindow = (NSWindow*) user;
switch (GetEventKind (e))
{
case kEventWindowShown:
[hostWindow orderFront: nil];
break;
case kEventWindowHidden:
[hostWindow orderOut: nil];
break;
}
return eventNotHandledErr;
}
#endif
//==============================================================================
void initialiseMac()
{
NSApplicationLoad();
}
void* attachComponentToWindowRef (Component* comp, void* windowRef)
{
const ScopedAutoReleasePool pool;
NSWindow* hostWindow = [[NSWindow alloc] initWithWindowRef: windowRef];
[hostWindow retain];
[hostWindow setCanHide: YES];
[hostWindow setReleasedWhenClosed: YES];
NSView* content = [hostWindow contentView];
NSRect f = [content frame];
NSPoint windowPos = [hostWindow convertBaseToScreen: f.origin];
windowPos.y = [[NSScreen mainScreen] frame].size.height - (windowPos.y + f.size.height);
comp->setTopLeftPosition ((int) windowPos.x, (int) windowPos.y);
#if ! JucePlugin_EditorRequiresKeyboardFocus
comp->addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses);
#else
comp->addToDesktop (ComponentPeer::windowIsTemporary);
#endif
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];
#if ADD_CARBON_BODGE
// Adds a callback bodge to work around some problems with wrapped
// carbon windows..
const EventTypeSpec eventsToCatch[] = {
{ kEventClassWindow, kEventWindowShown },
{ kEventClassWindow, kEventWindowHidden }
};
InstallWindowEventHandler ((WindowRef) windowRef,
NewEventHandlerUPP (windowVisibilityBodge),
GetEventTypeCount (eventsToCatch), eventsToCatch,
(void*) hostWindow, 0);
#endif
return hostWindow;
}
void detachComponentFromWindowRef (Component* comp, void* nsWindow)
{
const ScopedAutoReleasePool pool;
NSWindow* hostWindow = (NSWindow*) nsWindow;
NSView* pluginView = (NSView*) comp->getWindowHandle();
NSWindow* pluginWindow = [pluginView window];
[hostWindow removeChildWindow: pluginWindow];
comp->removeFromDesktop();
[hostWindow release];
}
void setNativeHostWindowSize (void* nsWindow, Component* component, int newWidth, int newHeight)
{
NSWindow* hostWindow = (NSWindow*) nsWindow;
if (hostWindow != 0)
{
ScopedAutoReleasePool pool;
// Can't use the cocoa NSWindow resizing code, or it messes up in Live.
Rect r;
GetWindowBounds ((WindowRef) [hostWindow windowRef], kWindowContentRgn, &r);
r.right += newWidth - component->getWidth();
r.bottom += newHeight - component->getHeight();
SetWindowBounds ((WindowRef) [hostWindow windowRef], kWindowContentRgn, &r);
[[hostWindow contentView] setNeedsDisplay: YES];
}
}
void checkWindowVisibility (void* nsWindow, Component* comp)
{
NSWindow* hostWindow = (NSWindow*) nsWindow;
comp->setVisible ([hostWindow isVisible]);
}
END_JUCE_NAMESPACE
#endif
/*
==============================================================================

This file is part of the JUCE library - "Jules' Utility Class Extensions"
Copyright 2004-7 by Raw Material Software ltd.

------------------------------------------------------------------------------

JUCE can be redistributed and/or modified under the terms of the
GNU General Public License, as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

JUCE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with JUCE; if not, visit www.gnu.org/licenses or write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA

------------------------------------------------------------------------------

If you'd like to release a closed-source product which uses JUCE, commercial
licenses are also available: visit www.rawmaterialsoftware.com/juce for
more information.

==============================================================================
*/

//==============================================================================
#include "../juce_IncludeCharacteristics.h"

#if JucePlugin_Build_VST

#include <Cocoa/Cocoa.h>

#define ADD_CARBON_BODGE 1 // see note below..

#if ADD_CARBON_BODGE
#include <Carbon/Carbon.h>
#endif

#include "../juce_PluginHeaders.h"

//==============================================================================
BEGIN_JUCE_NAMESPACE

#if ADD_CARBON_BODGE
/* When you wrap a WindowRef as an NSWindow, it seems to bugger up the HideWindow
function, so when the host tries (and fails) to hide the window, this catches
the event and does the job properly.
*/

static pascal OSStatus windowVisibilityBodge (EventHandlerCallRef, EventRef e, void* user)
{
NSWindow* hostWindow = (NSWindow*) user;

switch (GetEventKind (e))
{
case kEventWindowShown:
[hostWindow orderFront: nil];
break;
case kEventWindowHidden:
[hostWindow orderOut: nil];
break;
}

return eventNotHandledErr;
}
#endif

//==============================================================================
void initialiseMac()
{
NSApplicationLoad();
}

void* attachComponentToWindowRef (Component* comp, void* windowRef)
{
const ScopedAutoReleasePool pool;

NSWindow* hostWindow = [[NSWindow alloc] initWithWindowRef: windowRef];
[hostWindow retain];
[hostWindow setCanHide: YES];
[hostWindow setReleasedWhenClosed: YES];

NSView* content = [hostWindow contentView];
NSRect f = [content frame];
NSPoint windowPos = [hostWindow convertBaseToScreen: f.origin];
windowPos.y = [[NSScreen mainScreen] frame].size.height - (windowPos.y + f.size.height);
comp->setTopLeftPosition ((int) windowPos.x, (int) windowPos.y);

#if ! JucePlugin_EditorRequiresKeyboardFocus
comp->addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses);
#else
comp->addToDesktop (ComponentPeer::windowIsTemporary);
#endif

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];

#if ADD_CARBON_BODGE
// Adds a callback bodge to work around some problems with wrapped
// carbon windows..
const EventTypeSpec eventsToCatch[] = {
{ kEventClassWindow, kEventWindowShown },
{ kEventClassWindow, kEventWindowHidden }
};

EventHandlerRef ref;
InstallWindowEventHandler ((WindowRef) windowRef,
NewEventHandlerUPP (windowVisibilityBodge),
GetEventTypeCount (eventsToCatch), eventsToCatch,
(void*) hostWindow, &ref);
comp->setComponentProperty ("carbonEventRef", String::toHexString ((pointer_sized_int) (void*) ref));
#endif

return hostWindow;
}

void detachComponentFromWindowRef (Component* comp, void* nsWindow)
{
const ScopedAutoReleasePool pool;

#if ADD_CARBON_BODGE
EventHandlerRef ref = (EventHandlerRef) (void*) (pointer_sized_int)
comp->getComponentProperty ("carbonEventRef", false, String::empty).getHexValue64();
RemoveEventHandler (ref);
#endif

NSWindow* hostWindow = (NSWindow*) nsWindow;
NSView* pluginView = (NSView*) comp->getWindowHandle();
NSWindow* pluginWindow = [pluginView window];

[hostWindow removeChildWindow: pluginWindow];
comp->removeFromDesktop();

[hostWindow release];
}

void setNativeHostWindowSize (void* nsWindow, Component* component, int newWidth, int newHeight)
{
NSWindow* hostWindow = (NSWindow*) nsWindow;
if (hostWindow != 0)
{
ScopedAutoReleasePool pool;

// Can't use the cocoa NSWindow resizing code, or it messes up in Live.
Rect r;
GetWindowBounds ((WindowRef) [hostWindow windowRef], kWindowContentRgn, &r);
r.right += newWidth - component->getWidth();
r.bottom += newHeight - component->getHeight();
SetWindowBounds ((WindowRef) [hostWindow windowRef], kWindowContentRgn, &r);

[[hostWindow contentView] setNeedsDisplay: YES];
}
}

void checkWindowVisibility (void* nsWindow, Component* comp)
{
NSWindow* hostWindow = (NSWindow*) nsWindow;
comp->setVisible ([hostWindow isVisible]);
}

END_JUCE_NAMESPACE

#endif

+ 11
- 10
juce_amalgamated.cpp View File

@@ -81703,6 +81703,7 @@ private:
}

DrawablePath* dp = new DrawablePath();
dp->setName (xml.getStringAttribute (T("id")));
dp->setSolidFill (Colours::transparentBlack);

path.applyTransform (transform);
@@ -272268,6 +272269,8 @@ static int numPendingMessages = 0;
@private
id oldDelegate;
AppDelegateRedirector* redirector;

@public
bool flushingMessages;
}

@@ -272312,7 +272315,6 @@ static int numPendingMessages = 0;

[center addObserver: self selector: @selector (applicationWillUnhide:)
name: NSApplicationWillUnhideNotification object: NSApp];

}

return self;
@@ -272360,7 +272362,6 @@ static int numPendingMessages = 0;
- (void) customEvent: (id) n
{
atomicDecrement (numPendingMessages);
[self release];

NSData* data = (NSData*) n;
void* message = 0;
@@ -272368,8 +272369,6 @@ static int numPendingMessages = 0;

if (message != 0 && ! flushingMessages)
redirector->deliverMessage (message);

[data release];
}

- (void) performCallback: (id) info
@@ -272548,9 +272547,13 @@ void MessageManager::doPlatformSpecificShutdown()
// Annoyingly, cancelPerformSelectorsWithTarget can't actually cancel the messages
// sent by performSelectorOnMainThread, so need to manually flush these before quitting..
juceAppDelegate->flushingMessages = true;
if (JUCEApplication::getInstance() != 0) // (must avoid blocking here when running as a plugin)
for (int i = 100; --i >= 0 && numPendingMessages > 0;)
getInstance()->runDispatchLoopUntil (10);

for (int i = 100; --i >= 0 && numPendingMessages > 0;)
{
const ScopedAutoReleasePool pool;
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: [NSDate dateWithTimeIntervalSinceNow: 5 * 0.001]];
}

[juceAppDelegate release];
juceAppDelegate = 0;
@@ -272560,11 +272563,9 @@ void MessageManager::doPlatformSpecificShutdown()
bool juce_postMessageToSystemQueue (void* message)
{
atomicIncrement (numPendingMessages);
[juceAppDelegate retain];

[juceAppDelegate performSelectorOnMainThread: @selector (customEvent:)
withObject: (id) [[NSData alloc] initWithBytes: &message
length: (int) sizeof (message)]
withObject: (id) [NSData dataWithBytes: &message length: (int) sizeof (message)]
waitUntilDone: NO];
return true;
}


+ 1
- 0
src/juce_appframework/gui/graphics/drawables/juce_SVGParser.cpp View File

@@ -613,6 +613,7 @@ private:
}
DrawablePath* dp = new DrawablePath();
dp->setName (xml.getStringAttribute (T("id")));
dp->setSolidFill (Colours::transparentBlack);
path.applyTransform (transform);


Loading…
Cancel
Save