2008-12-12 09:43:24 -05:00
|
|
|
#undef Marker
|
|
|
|
#define Marker FuckYouAppleAndYourLackOfNameSpaces
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
#include "pbd/convert.h"
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "pbd/error.h"
|
2011-11-09 20:32:34 -05:00
|
|
|
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "ardour/audio_unit.h"
|
2011-11-09 20:32:34 -05:00
|
|
|
#include "ardour/debug.h"
|
2010-11-13 00:14:48 -05:00
|
|
|
#include "ardour/plugin_insert.h"
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
#undef check // stupid gtk, stupid apple
|
|
|
|
|
|
|
|
#include <gtkmm/button.h>
|
2008-01-10 16:20:59 -05:00
|
|
|
#include <gdk/gdkquartz.h>
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
#include <gtkmm2ext/utils.h>
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
#include "au_pluginui.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
#include "appleutility/CAAudioUnit.h"
|
|
|
|
#include "appleutility/CAComponent.h"
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
#import <AudioUnit/AUCocoaUIView.h>
|
|
|
|
#import <CoreAudioKit/AUGenericView.h>
|
|
|
|
|
2008-12-12 09:43:24 -05:00
|
|
|
#undef Marker
|
|
|
|
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "public_editor.h"
|
2008-01-10 16:20:59 -05:00
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace Gtk;
|
2008-02-16 17:43:18 -05:00
|
|
|
using namespace Gtkmm2ext;
|
2008-01-10 16:20:59 -05:00
|
|
|
using namespace sigc;
|
|
|
|
using namespace std;
|
|
|
|
using namespace PBD;
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
vector<string> AUPluginUI::automation_mode_strings;
|
|
|
|
|
|
|
|
static const gchar* _automation_mode_strings[] = {
|
|
|
|
X_("Manual"),
|
|
|
|
X_("Play"),
|
|
|
|
X_("Write"),
|
|
|
|
X_("Touch"),
|
|
|
|
0
|
|
|
|
};
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2013-05-01 18:41:28 -04:00
|
|
|
static void
|
|
|
|
dump_view_tree (NSView* view, int depth)
|
|
|
|
{
|
|
|
|
NSArray* subviews = [view subviews];
|
|
|
|
unsigned long cnt = [subviews count];
|
|
|
|
|
|
|
|
for (int d = 0; d < depth; d++) {
|
|
|
|
cerr << '\t';
|
|
|
|
}
|
|
|
|
NSRect frame = [view frame];
|
|
|
|
cerr << " view @ " << frame.origin.x << ", " << frame.origin.y
|
|
|
|
<< ' ' << frame.size.width << " x " << frame.size.height
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
for (unsigned long i = 0; i < cnt; ++i) {
|
|
|
|
NSView* subview = [subviews objectAtIndex:i];
|
|
|
|
dump_view_tree (subview, depth+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
@implementation NotificationObject
|
|
|
|
|
|
|
|
- (NotificationObject*) initWithPluginUI: (AUPluginUI*) apluginui andCocoaParent: (NSWindow*) cp andTopLevelParent: (NSWindow*) tlp
|
|
|
|
{
|
|
|
|
self = [ super init ];
|
|
|
|
|
|
|
|
if (self) {
|
2012-06-01 18:27:10 -04:00
|
|
|
plugin_ui = apluginui;
|
2010-11-13 00:14:48 -05:00
|
|
|
top_level_parent = tlp;
|
2012-06-01 18:27:10 -04:00
|
|
|
|
|
|
|
if (cp) {
|
|
|
|
cocoa_parent = cp;
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(cocoaParentActivationHandler:)
|
|
|
|
name:NSWindowDidBecomeMainNotification
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(cocoaParentBecameKeyHandler:)
|
|
|
|
name:NSWindowDidBecomeKeyNotification
|
|
|
|
object:nil];
|
|
|
|
}
|
|
|
|
}
|
2010-11-13 00:14:48 -05:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)cocoaParentActivationHandler:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSWindow* notification_window = (NSWindow *)[notification object];
|
|
|
|
|
|
|
|
if (top_level_parent == notification_window || cocoa_parent == notification_window) {
|
|
|
|
if ([notification_window isMainWindow]) {
|
|
|
|
plugin_ui->activate();
|
|
|
|
} else {
|
|
|
|
plugin_ui->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)cocoaParentBecameKeyHandler:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSWindow* notification_window = (NSWindow *)[notification object];
|
|
|
|
|
|
|
|
if (top_level_parent == notification_window || cocoa_parent == notification_window) {
|
|
|
|
if ([notification_window isKeyWindow]) {
|
|
|
|
plugin_ui->activate();
|
|
|
|
} else {
|
|
|
|
plugin_ui->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)auViewResized:(NSNotification *)notification;
|
|
|
|
{
|
2012-06-01 18:27:10 -04:00
|
|
|
(void) notification; // stop complaints about unusued argument
|
2010-11-13 00:14:48 -05:00
|
|
|
plugin_ui->cocoa_view_resized();
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
AUPluginUI::AUPluginUI (boost::shared_ptr<PluginInsert> insert)
|
|
|
|
: PlugUIBase (insert)
|
2008-02-16 17:43:18 -05:00
|
|
|
, automation_mode_label (_("Automation"))
|
|
|
|
, preset_label (_("Presets"))
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
{
|
2008-02-16 17:43:18 -05:00
|
|
|
if (automation_mode_strings.empty()) {
|
|
|
|
automation_mode_strings = I18N (_automation_mode_strings);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_popdown_strings (automation_mode_selector, automation_mode_strings);
|
|
|
|
automation_mode_selector.set_active_text (automation_mode_strings.front());
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
if ((au = boost::dynamic_pointer_cast<AUPlugin> (insert->plugin())) == 0) {
|
|
|
|
error << _("unknown type of editor-supplying plugin (note: no AudioUnit support in this version of ardour)") << endmsg;
|
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
/* stuff some stuff into the top of the window */
|
|
|
|
|
2008-12-12 09:43:24 -05:00
|
|
|
HBox* smaller_hbox = manage (new HBox);
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
smaller_hbox->set_spacing (6);
|
|
|
|
smaller_hbox->pack_start (preset_label, false, false, 4);
|
2011-12-02 15:42:27 -05:00
|
|
|
smaller_hbox->pack_start (_preset_combo, false, false);
|
2008-12-12 09:43:24 -05:00
|
|
|
smaller_hbox->pack_start (save_button, false, false);
|
2010-11-13 00:14:48 -05:00
|
|
|
#if 0
|
|
|
|
/* one day these might be useful with an AU plugin, but not yet */
|
2008-12-12 09:43:24 -05:00
|
|
|
smaller_hbox->pack_start (automation_mode_label, false, false);
|
|
|
|
smaller_hbox->pack_start (automation_mode_selector, false, false);
|
2010-11-13 00:14:48 -05:00
|
|
|
#endif
|
2008-12-12 09:43:24 -05:00
|
|
|
smaller_hbox->pack_start (bypass_button, false, true);
|
|
|
|
|
|
|
|
VBox* v1_box = manage (new VBox);
|
|
|
|
VBox* v2_box = manage (new VBox);
|
|
|
|
|
|
|
|
v1_box->pack_start (*smaller_hbox, false, true);
|
|
|
|
v2_box->pack_start (focus_button, false, true);
|
|
|
|
|
|
|
|
top_box.set_homogeneous (false);
|
2008-02-16 17:43:18 -05:00
|
|
|
top_box.set_spacing (6);
|
|
|
|
top_box.set_border_width (6);
|
|
|
|
|
2008-12-12 09:43:24 -05:00
|
|
|
top_box.pack_end (*v2_box, false, false);
|
|
|
|
top_box.pack_end (*v1_box, false, false);
|
2008-02-16 17:43:18 -05:00
|
|
|
|
|
|
|
set_spacing (6);
|
|
|
|
pack_start (top_box, false, false);
|
|
|
|
pack_start (low_box, false, false);
|
|
|
|
|
|
|
|
preset_label.show ();
|
2011-09-30 13:55:14 -04:00
|
|
|
_preset_combo.show ();
|
2008-02-16 17:43:18 -05:00
|
|
|
automation_mode_label.show ();
|
|
|
|
automation_mode_selector.show ();
|
|
|
|
bypass_button.show ();
|
|
|
|
top_box.show ();
|
|
|
|
low_box.show ();
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
cocoa_parent = 0;
|
|
|
|
cocoa_window = 0;
|
2013-04-30 11:15:23 -04:00
|
|
|
|
|
|
|
#ifdef WITH_CARBBON
|
|
|
|
_activating_from_app = false;
|
|
|
|
_notify = 0;
|
2008-01-19 00:06:33 -05:00
|
|
|
au_view = 0;
|
2010-11-13 00:14:48 -05:00
|
|
|
editView = 0;
|
2013-04-30 11:15:23 -04:00
|
|
|
carbon_window = 0;
|
|
|
|
#endif
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
/* prefer cocoa, fall back to cocoa, but use carbon if its there */
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
if (test_cocoa_view_support()) {
|
2008-01-10 16:20:59 -05:00
|
|
|
create_cocoa_view ();
|
2011-12-02 15:42:27 -05:00
|
|
|
#ifdef WITH_CARBON
|
2008-02-16 17:43:18 -05:00
|
|
|
} else if (test_carbon_view_support()) {
|
|
|
|
create_carbon_view ();
|
2011-12-02 15:42:27 -05:00
|
|
|
#endif
|
2008-01-10 16:20:59 -05:00
|
|
|
} else {
|
|
|
|
create_cocoa_view ();
|
|
|
|
}
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
low_box.signal_realize().connect (mem_fun (this, &AUPluginUI::lower_box_realized));
|
|
|
|
}
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
AUPluginUI::~AUPluginUI ()
|
|
|
|
{
|
2012-06-02 12:01:18 -04:00
|
|
|
if (_notify) {
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:_notify];
|
|
|
|
}
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
if (cocoa_parent) {
|
2008-01-10 16:20:59 -05:00
|
|
|
NSWindow* win = get_nswindow();
|
|
|
|
[win removeChildWindow:cocoa_parent];
|
2010-11-13 00:14:48 -05:00
|
|
|
}
|
|
|
|
|
2011-12-02 15:42:27 -05:00
|
|
|
#ifdef WITH_CARBON
|
2010-11-13 00:14:48 -05:00
|
|
|
if (carbon_window) {
|
|
|
|
/* not parented, just overlaid on top of our window */
|
2008-02-16 17:43:18 -05:00
|
|
|
DisposeWindow (carbon_window);
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
2011-12-02 15:42:27 -05:00
|
|
|
#endif
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
if (editView) {
|
|
|
|
CloseComponent (editView);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (au_view) {
|
2009-07-12 20:26:28 -04:00
|
|
|
/* remove whatever we packed into low_box so that GTK doesn't
|
|
|
|
mess with it.
|
|
|
|
*/
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
[au_view removeFromSuperview];
|
2008-04-11 10:06:50 -04:00
|
|
|
}
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AUPluginUI::test_carbon_view_support ()
|
|
|
|
{
|
2013-04-30 11:15:23 -04:00
|
|
|
#ifdef WITH_CARBON
|
2008-01-10 16:20:59 -05:00
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
carbon_descriptor.componentType = kAudioUnitCarbonViewComponentType;
|
|
|
|
carbon_descriptor.componentSubType = 'gnrc';
|
|
|
|
carbon_descriptor.componentManufacturer = 'appl';
|
|
|
|
carbon_descriptor.componentFlags = 0;
|
|
|
|
carbon_descriptor.componentFlagsMask = 0;
|
|
|
|
|
|
|
|
OSStatus err;
|
|
|
|
|
|
|
|
// ask the AU for its first editor component
|
|
|
|
UInt32 propertySize;
|
|
|
|
err = AudioUnitGetPropertyInfo(*au->get_au(), kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global, 0, &propertySize, NULL);
|
|
|
|
if (!err) {
|
|
|
|
int nEditors = propertySize / sizeof(ComponentDescription);
|
|
|
|
ComponentDescription *editors = new ComponentDescription[nEditors];
|
|
|
|
err = AudioUnitGetProperty(*au->get_au(), kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global, 0, editors, &propertySize);
|
|
|
|
if (!err) {
|
|
|
|
// just pick the first one for now
|
|
|
|
carbon_descriptor = editors[0];
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
delete[] editors;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-04-30 11:15:23 -04:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AUPluginUI::test_cocoa_view_support ()
|
|
|
|
{
|
|
|
|
UInt32 dataSize = 0;
|
|
|
|
Boolean isWritable = 0;
|
|
|
|
OSStatus err = AudioUnitGetPropertyInfo(*au->get_au(),
|
|
|
|
kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
|
|
|
|
0, &dataSize, &isWritable);
|
|
|
|
|
|
|
|
return dataSize > 0 && err == noErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AUPluginUI::plugin_class_valid (Class pluginClass)
|
|
|
|
{
|
|
|
|
if([pluginClass conformsToProtocol: @protocol(AUCocoaUIBase)]) {
|
|
|
|
if([pluginClass instancesRespondToSelector: @selector(interfaceVersion)] &&
|
|
|
|
[pluginClass instancesRespondToSelector: @selector(uiViewForAudioUnit:withSize:)]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
AUPluginUI::create_cocoa_view ()
|
|
|
|
{
|
2013-04-30 11:15:23 -04:00
|
|
|
bool wasAbleToLoadCustomView = false;
|
2008-01-10 16:20:59 -05:00
|
|
|
AudioUnitCocoaViewInfo* cocoaViewInfo = NULL;
|
|
|
|
UInt32 numberOfClasses = 0;
|
|
|
|
UInt32 dataSize;
|
|
|
|
Boolean isWritable;
|
|
|
|
NSString* factoryClassName = 0;
|
2011-09-30 13:55:14 -04:00
|
|
|
NSURL* CocoaViewBundlePath = NULL;
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
OSStatus result = AudioUnitGetPropertyInfo (*au->get_au(),
|
|
|
|
kAudioUnitProperty_CocoaUI,
|
|
|
|
kAudioUnitScope_Global,
|
|
|
|
0,
|
|
|
|
&dataSize,
|
|
|
|
&isWritable );
|
|
|
|
|
|
|
|
numberOfClasses = (dataSize - sizeof(CFURLRef)) / sizeof(CFStringRef);
|
2011-11-09 20:32:34 -05:00
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
// Does view have custom Cocoa UI?
|
|
|
|
|
|
|
|
if ((result == noErr) && (numberOfClasses > 0) ) {
|
2011-11-09 20:32:34 -05:00
|
|
|
|
|
|
|
DEBUG_TRACE(DEBUG::AudioUnits,
|
|
|
|
string_compose ( "based on %1, there are %2 cocoa UI classes\n", dataSize, numberOfClasses));
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
cocoaViewInfo = (AudioUnitCocoaViewInfo *)malloc(dataSize);
|
2012-06-01 18:27:10 -04:00
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
if(AudioUnitGetProperty(*au->get_au(),
|
|
|
|
kAudioUnitProperty_CocoaUI,
|
|
|
|
kAudioUnitScope_Global,
|
|
|
|
0,
|
|
|
|
cocoaViewInfo,
|
|
|
|
&dataSize) == noErr) {
|
|
|
|
|
|
|
|
CocoaViewBundlePath = (NSURL *)cocoaViewInfo->mCocoaAUViewBundleLocation;
|
2011-11-09 20:32:34 -05:00
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
// we only take the first view in this example.
|
|
|
|
factoryClassName = (NSString *)cocoaViewInfo->mCocoaAUViewClass[0];
|
2011-11-09 20:32:34 -05:00
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("the factory name is %1 bundle is %2\n",
|
2012-06-01 18:27:10 -04:00
|
|
|
[factoryClassName UTF8String], CocoaViewBundlePath));
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
} else {
|
|
|
|
|
2011-11-09 20:32:34 -05:00
|
|
|
DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("No cocoaUI property cocoaViewInfo = %1\n", cocoaViewInfo));
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
if (cocoaViewInfo != NULL) {
|
|
|
|
free (cocoaViewInfo);
|
|
|
|
cocoaViewInfo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// [A] Show custom UI if view has it
|
|
|
|
|
|
|
|
if (CocoaViewBundlePath && factoryClassName) {
|
|
|
|
NSBundle *viewBundle = [NSBundle bundleWithPath:[CocoaViewBundlePath path]];
|
2011-11-09 20:32:34 -05:00
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("tried to create bundle, result = %1\n", viewBundle));
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
if (viewBundle == nil) {
|
|
|
|
error << _("AUPluginUI: error loading AU view's bundle") << endmsg;
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
Class factoryClass = [viewBundle classNamed:factoryClassName];
|
2011-11-09 20:32:34 -05:00
|
|
|
DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("tried to create factory class, result = %1\n", factoryClass));
|
2008-01-10 16:20:59 -05:00
|
|
|
if (!factoryClass) {
|
|
|
|
error << _("AUPluginUI: error getting AU view's factory class from bundle") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure 'factoryClass' implements the AUCocoaUIBase protocol
|
|
|
|
if (!plugin_class_valid (factoryClass)) {
|
|
|
|
error << _("AUPluginUI: U view's factory class does not properly implement the AUCocoaUIBase protocol") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
// make a factory
|
2012-06-01 18:27:10 -04:00
|
|
|
id factory = [[[factoryClass alloc] init] autorelease];
|
|
|
|
if (factory == nil) {
|
2008-01-10 16:20:59 -05:00
|
|
|
error << _("AUPluginUI: Could not create an instance of the AU view factory") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-11-09 20:32:34 -05:00
|
|
|
DEBUG_TRACE (DEBUG::AudioUnits, "got a factory instance\n");
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
// make a view
|
2012-06-01 18:27:10 -04:00
|
|
|
au_view = [factory uiViewForAudioUnit:*au->get_au() withSize:NSZeroSize];
|
2011-11-09 20:32:34 -05:00
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("view created @ %1\n", au_view));
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
[CocoaViewBundlePath release];
|
|
|
|
if (cocoaViewInfo) {
|
|
|
|
UInt32 i;
|
|
|
|
for (i = 0; i < numberOfClasses; i++)
|
|
|
|
CFRelease(cocoaViewInfo->mCocoaAUViewClass[i]);
|
|
|
|
|
|
|
|
free (cocoaViewInfo);
|
|
|
|
}
|
2013-04-30 11:15:23 -04:00
|
|
|
wasAbleToLoadCustomView = true;
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wasAbleToLoadCustomView) {
|
2008-02-16 17:43:18 -05:00
|
|
|
// load generic Cocoa view
|
2011-11-09 20:32:34 -05:00
|
|
|
DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("Loading generic view using %1 -> %2\n", au,
|
|
|
|
au->get_au()));
|
2008-01-10 16:20:59 -05:00
|
|
|
au_view = [[AUGenericView alloc] initWithAudioUnit:*au->get_au()];
|
2011-11-09 20:32:34 -05:00
|
|
|
DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("view created @ %1\n", au_view));
|
2013-04-30 11:15:23 -04:00
|
|
|
[(AUGenericView *)au_view setShowsExpertParameters:1];
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
|
2012-06-01 18:27:10 -04:00
|
|
|
// Get the initial size of the new AU View's frame
|
2010-11-13 00:14:48 -05:00
|
|
|
|
2012-06-01 18:27:10 -04:00
|
|
|
NSRect rect = [au_view frame];
|
2013-04-30 11:15:23 -04:00
|
|
|
prefheight = rect.size.height;
|
|
|
|
prefwidth = rect.size.width;
|
2012-06-01 18:27:10 -04:00
|
|
|
low_box.set_size_request (rect.size.width, rect.size.height);
|
2013-04-30 11:15:23 -04:00
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
void
|
|
|
|
AUPluginUI::cocoa_view_resized ()
|
|
|
|
{
|
2012-06-01 18:27:10 -04:00
|
|
|
GtkRequisition topsize = top_box.size_request ();
|
|
|
|
NSWindow* window = get_nswindow ();
|
|
|
|
NSRect windowFrame= [window frame];
|
2013-05-01 18:41:28 -04:00
|
|
|
NSRect new_frame = [au_view frame];
|
2013-04-30 11:15:23 -04:00
|
|
|
|
2013-05-01 18:41:28 -04:00
|
|
|
float dy = last_au_frame.size.height - new_frame.size.height;
|
|
|
|
float dx = last_au_frame.size.width - new_frame.size.width;
|
2012-06-01 18:27:10 -04:00
|
|
|
|
|
|
|
windowFrame.origin.y += dy;
|
|
|
|
windowFrame.origin.x += dx;
|
|
|
|
windowFrame.size.height -= dy;
|
|
|
|
windowFrame.size.width -= dx;
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:_notify
|
|
|
|
name:NSViewFrameDidChangeNotification
|
|
|
|
object:au_view];
|
|
|
|
|
|
|
|
NSUInteger old_auto_resize = [au_view autoresizingMask];
|
|
|
|
|
|
|
|
[au_view setAutoresizingMask:NSViewNotSizable];
|
2013-04-30 11:15:23 -04:00
|
|
|
[window setFrame:windowFrame display:1];
|
2013-05-01 18:41:28 -04:00
|
|
|
|
|
|
|
/* Some stupid AU Views change the origin of the original AU View
|
|
|
|
when they are resized (I'm looking at you AUSampler). If the origin
|
|
|
|
has been moved, move it back.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (last_au_frame.origin.x != new_frame.origin.x ||
|
|
|
|
last_au_frame.origin.y != new_frame.origin.y) {
|
|
|
|
new_frame.origin = last_au_frame.origin;
|
|
|
|
[au_view setFrame:new_frame];
|
|
|
|
/* also be sure to redraw the topbox because this can
|
|
|
|
also go wrong.
|
|
|
|
*/
|
|
|
|
top_box.queue_draw ();
|
|
|
|
}
|
|
|
|
|
2012-06-01 18:27:10 -04:00
|
|
|
[au_view setAutoresizingMask:old_auto_resize];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:_notify
|
|
|
|
selector:@selector(auViewResized:) name:NSViewFrameDidChangeNotification
|
|
|
|
object:au_view];
|
2013-05-01 18:41:28 -04:00
|
|
|
|
|
|
|
last_au_frame = new_frame;
|
2010-11-13 00:14:48 -05:00
|
|
|
}
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
int
|
2008-02-16 17:43:18 -05:00
|
|
|
AUPluginUI::create_carbon_view ()
|
2008-01-10 16:20:59 -05:00
|
|
|
{
|
2011-12-02 15:42:27 -05:00
|
|
|
#ifdef WITH_CARBON
|
2008-01-10 16:20:59 -05:00
|
|
|
OSStatus err;
|
|
|
|
ControlRef root_control;
|
|
|
|
|
|
|
|
Component editComponent = FindNextComponent(NULL, &carbon_descriptor);
|
|
|
|
|
|
|
|
OpenAComponent(editComponent, &editView);
|
|
|
|
if (!editView) {
|
|
|
|
error << _("AU Carbon view: cannot open AU Component") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect r = { 100, 100, 100, 100 };
|
|
|
|
WindowAttributes attr = WindowAttributes (kWindowStandardHandlerAttribute |
|
|
|
|
kWindowCompositingAttribute|
|
|
|
|
kWindowNoShadowAttribute|
|
|
|
|
kWindowNoTitleBarAttribute);
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
if ((err = CreateNewWindow(kDocumentWindowClass, attr, &r, &carbon_window)) != noErr) {
|
2008-01-10 16:20:59 -05:00
|
|
|
error << string_compose (_("AUPluginUI: cannot create carbon window (err: %1)"), err) << endmsg;
|
2010-11-13 00:14:48 -05:00
|
|
|
CloseComponent (editView);
|
2008-01-10 16:20:59 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = GetRootControl(carbon_window, &root_control)) != noErr) {
|
|
|
|
error << string_compose (_("AUPlugin: cannot get root control of carbon window (err: %1)"), err) << endmsg;
|
2010-11-13 00:14:48 -05:00
|
|
|
DisposeWindow (carbon_window);
|
|
|
|
CloseComponent (editView);
|
2008-01-10 16:20:59 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlRef viewPane;
|
|
|
|
Float32Point location = { 0.0, 0.0 };
|
|
|
|
Float32Point size = { 0.0, 0.0 } ;
|
|
|
|
|
|
|
|
if ((err = AudioUnitCarbonViewCreate (editView, *au->get_au(), carbon_window, root_control, &location, &size, &viewPane)) != noErr) {
|
|
|
|
error << string_compose (_("AUPluginUI: cannot create carbon plugin view (err: %1)"), err) << endmsg;
|
2010-11-13 00:14:48 -05:00
|
|
|
DisposeWindow (carbon_window);
|
|
|
|
CloseComponent (editView);
|
2008-01-10 16:20:59 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// resize window
|
|
|
|
|
|
|
|
Rect bounds;
|
|
|
|
GetControlBounds(viewPane, &bounds);
|
|
|
|
size.x = bounds.right-bounds.left;
|
|
|
|
size.y = bounds.bottom-bounds.top;
|
|
|
|
|
|
|
|
prefwidth = (int) (size.x + 0.5);
|
|
|
|
prefheight = (int) (size.y + 0.5);
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
SizeWindow (carbon_window, prefwidth, prefheight, true);
|
|
|
|
low_box.set_size_request (prefwidth, prefheight);
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
return 0;
|
2011-12-02 15:42:27 -05:00
|
|
|
#else
|
|
|
|
error << _("AU Carbon GUI is not supported.") << endmsg;
|
|
|
|
return -1;
|
|
|
|
#endif
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
NSWindow*
|
|
|
|
AUPluginUI::get_nswindow ()
|
|
|
|
{
|
|
|
|
Gtk::Container* toplevel = get_toplevel();
|
|
|
|
|
|
|
|
if (!toplevel || !toplevel->is_toplevel()) {
|
|
|
|
error << _("AUPluginUI: no top level window!") << endmsg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSWindow* true_parent = gdk_quartz_window_get_nswindow (toplevel->get_window()->gobj());
|
|
|
|
|
|
|
|
if (!true_parent) {
|
|
|
|
error << _("AUPluginUI: no top level window!") << endmsg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AUPluginUI::activate ()
|
|
|
|
{
|
2011-12-02 15:42:27 -05:00
|
|
|
#ifdef WITH_CARBON
|
2010-11-13 00:14:48 -05:00
|
|
|
ActivateWindow (carbon_window, TRUE);
|
2011-12-02 15:42:27 -05:00
|
|
|
#endif
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AUPluginUI::deactivate ()
|
|
|
|
{
|
2011-12-02 15:42:27 -05:00
|
|
|
#ifdef WITH_CARBON
|
2008-02-16 17:43:18 -05:00
|
|
|
ActivateWindow (carbon_window, FALSE);
|
2011-12-02 15:42:27 -05:00
|
|
|
#endif
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
AUPluginUI::parent_carbon_window ()
|
|
|
|
{
|
2011-12-02 15:42:27 -05:00
|
|
|
#ifdef WITH_CARBON
|
2008-01-10 16:20:59 -05:00
|
|
|
NSWindow* win = get_nswindow ();
|
2012-07-23 10:22:27 -04:00
|
|
|
Rect windowStructureBoundsRect;
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
if (!win) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::Container* toplevel = get_toplevel();
|
|
|
|
|
|
|
|
if (!toplevel || !toplevel->is_toplevel()) {
|
|
|
|
error << _("AUPluginUI: no top level window!") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-23 10:22:27 -04:00
|
|
|
/* figure out where the cocoa parent window is in carbon-coordinate space, which
|
|
|
|
differs from both cocoa-coordinate space and GTK-coordinate space
|
|
|
|
*/
|
|
|
|
|
|
|
|
GetWindowBounds((WindowRef) [win windowRef], kWindowStructureRgn, &windowStructureBoundsRect);
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
/* compute how tall the title bar is, because we have to offset the position of the carbon window
|
|
|
|
by that much.
|
|
|
|
*/
|
|
|
|
|
|
|
|
NSRect content_frame = [NSWindow contentRectForFrameRect:[win frame] styleMask:[win styleMask]];
|
|
|
|
NSRect wm_frame = [NSWindow frameRectForContentRect:content_frame styleMask:[win styleMask]];
|
|
|
|
|
|
|
|
int titlebar_height = wm_frame.size.height - content_frame.size.height;
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
int packing_extra = 6; // this is the total vertical packing in our top level window
|
|
|
|
|
2012-07-23 10:22:27 -04:00
|
|
|
/* move into position, based on parent window position */
|
|
|
|
MoveWindow (carbon_window,
|
|
|
|
windowStructureBoundsRect.left,
|
|
|
|
windowStructureBoundsRect.top + titlebar_height + top_box.get_height() + packing_extra,
|
|
|
|
false);
|
|
|
|
ShowWindow (carbon_window);
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
// create the cocoa window for the carbon one and make it visible
|
|
|
|
cocoa_parent = [[NSWindow alloc] initWithWindowRef: carbon_window];
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
SetWindowActivationScope (carbon_window, kWindowActivationScopeNone);
|
|
|
|
|
|
|
|
_notify = [ [NotificationObject alloc] initWithPluginUI:this andCocoaParent:cocoa_parent andTopLevelParent:win ];
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
[win addChildWindow:cocoa_parent ordered:NSWindowAbove];
|
|
|
|
|
|
|
|
return 0;
|
2011-12-02 15:42:27 -05:00
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
AUPluginUI::parent_cocoa_window ()
|
|
|
|
{
|
|
|
|
NSWindow* win = get_nswindow ();
|
|
|
|
|
|
|
|
if (!win) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-30 11:15:23 -04:00
|
|
|
[win setAutodisplay:1]; // turn of GTK stuff for this window
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
Gtk::Container* toplevel = get_toplevel();
|
|
|
|
|
|
|
|
if (!toplevel || !toplevel->is_toplevel()) {
|
|
|
|
error << _("AUPluginUI: no top level window!") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
NSView* view = gdk_quartz_window_get_nsview (get_toplevel()->get_window()->gobj());
|
|
|
|
GtkRequisition a = top_box.size_request ();
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
/* move the au_view down so that it doesn't overlap the top_box contents */
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2013-07-15 17:35:20 -04:00
|
|
|
NSPoint origin = { 0, static_cast<CGFloat> (a.height) };
|
2010-11-13 00:14:48 -05:00
|
|
|
|
|
|
|
[au_view setFrameOrigin:origin];
|
2013-04-30 11:15:23 -04:00
|
|
|
[view addSubview:au_view positioned:NSWindowBelow relativeTo:nil];
|
2012-06-01 18:27:10 -04:00
|
|
|
|
2013-05-01 18:41:28 -04:00
|
|
|
last_au_frame = [au_view frame];
|
|
|
|
|
2012-06-01 18:27:10 -04:00
|
|
|
// watch for size changes of the view
|
|
|
|
|
|
|
|
_notify = [ [NotificationObject alloc] initWithPluginUI:this andCocoaParent:nil andTopLevelParent:win ];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:_notify
|
|
|
|
selector:@selector(auViewResized:) name:NSViewFrameDidChangeNotification
|
|
|
|
object:au_view];
|
2008-01-10 16:20:59 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
void
|
|
|
|
AUPluginUI::forward_key_event (GdkEventKey* ev)
|
|
|
|
{
|
|
|
|
NSEvent* nsevent = gdk_quartz_event_get_nsevent ((GdkEvent*)ev);
|
|
|
|
|
|
|
|
if (au_view && nsevent) {
|
|
|
|
|
|
|
|
/* filter on nsevent type here because GDK massages FlagsChanged
|
|
|
|
messages into GDK_KEY_{PRESS,RELEASE} but Cocoa won't
|
|
|
|
handle a FlagsChanged message as a keyDown or keyUp
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ([nsevent type] == NSKeyDown) {
|
|
|
|
[[[au_view window] firstResponder] keyDown:nsevent];
|
|
|
|
} else if ([nsevent type] == NSKeyUp) {
|
|
|
|
[[[au_view window] firstResponder] keyUp:nsevent];
|
|
|
|
} else if ([nsevent type] == NSFlagsChanged) {
|
|
|
|
[[[au_view window] firstResponder] flagsChanged:nsevent];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-10 16:20:59 -05:00
|
|
|
void
|
|
|
|
AUPluginUI::on_realize ()
|
|
|
|
{
|
|
|
|
VBox::on_realize ();
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
/* our windows should not have that resize indicator */
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
NSWindow* win = get_nswindow ();
|
|
|
|
if (win) {
|
2013-04-30 11:15:23 -04:00
|
|
|
[win setShowsResizeIndicator:0];
|
2008-02-16 17:43:18 -05:00
|
|
|
}
|
|
|
|
}
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
void
|
|
|
|
AUPluginUI::lower_box_realized ()
|
|
|
|
{
|
|
|
|
if (au_view) {
|
|
|
|
parent_cocoa_window ();
|
|
|
|
} else if (carbon_window) {
|
|
|
|
parent_carbon_window ();
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-13 00:14:48 -05:00
|
|
|
AUPluginUI::on_window_hide ()
|
2008-01-10 16:20:59 -05:00
|
|
|
{
|
2011-12-02 15:42:27 -05:00
|
|
|
#ifdef WITH_CARBON
|
2010-11-13 00:14:48 -05:00
|
|
|
if (carbon_window) {
|
|
|
|
HideWindow (carbon_window);
|
|
|
|
ActivateWindow (carbon_window, FALSE);
|
|
|
|
}
|
2011-12-02 15:42:27 -05:00
|
|
|
#endif
|
2010-11-13 00:14:48 -05:00
|
|
|
hide_all ();
|
2013-05-01 18:41:28 -04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
NSArray* wins = [NSApp windows];
|
|
|
|
for (uint32_t i = 0; i < [wins count]; i++) {
|
|
|
|
id win = [wins objectAtIndex:i];
|
|
|
|
}
|
|
|
|
#endif
|
2010-11-13 00:14:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AUPluginUI::on_window_show (const string& /*title*/)
|
|
|
|
{
|
|
|
|
/* this is idempotent so just call it every time we show the window */
|
2008-01-10 16:20:59 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
gtk_widget_realize (GTK_WIDGET(low_box.gobj()));
|
|
|
|
|
2010-11-13 00:14:48 -05:00
|
|
|
show_all ();
|
|
|
|
|
2011-12-02 15:42:27 -05:00
|
|
|
#ifdef WITH_CARBON
|
2010-11-13 00:14:48 -05:00
|
|
|
if (carbon_window) {
|
2008-01-19 00:06:33 -05:00
|
|
|
ShowWindow (carbon_window);
|
2010-11-13 00:14:48 -05:00
|
|
|
ActivateWindow (carbon_window, TRUE);
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
2011-12-02 15:42:27 -05:00
|
|
|
#endif
|
2010-11-13 00:14:48 -05:00
|
|
|
|
|
|
|
return true;
|
2008-01-10 16:20:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-11-13 00:14:48 -05:00
|
|
|
AUPluginUI::start_updating (GdkEventAny*)
|
2008-01-10 16:20:59 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-11-13 00:14:48 -05:00
|
|
|
AUPluginUI::stop_updating (GdkEventAny*)
|
2008-01-10 16:20:59 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlugUIBase*
|
|
|
|
create_au_gui (boost::shared_ptr<PluginInsert> plugin_insert, VBox** box)
|
|
|
|
{
|
|
|
|
AUPluginUI* aup = new AUPluginUI (plugin_insert);
|
|
|
|
(*box) = aup;
|
|
|
|
return aup;
|
|
|
|
}
|
2008-01-19 00:06:33 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
|