-#include <pbd/error.h>
-#include <ardour/audio_unit.h>
-#include <ardour/insert.h>
+#include <gtkmm/stock.h>
+#undef Marker
+#define Marker FuckYouAppleAndYourLackOfNameSpaces
+
+#include "pbd/convert.h"
+#include "pbd/error.h"
+#include "ardour/audio_unit.h"
+#include "ardour/plugin_insert.h"
+
+#undef check // stupid gtk, stupid apple
+
+#include <gtkmm/button.h>
#include <gdk/gdkquartz.h>
+#include <gtkmm2ext/utils.h>
+
#include "au_pluginui.h"
#include "gui_thread.h"
-#include <appleutility/CAAudioUnit.h>
-#include <appleutility/CAComponent.h>
+#include "appleutility/CAAudioUnit.h"
+#include "appleutility/CAComponent.h"
#import <AudioUnit/AUCocoaUIView.h>
#import <CoreAudioKit/AUGenericView.h>
+#undef Marker
+
+#include "keyboard.h"
+#include "utils.h"
+#include "public_editor.h"
#include "i18n.h"
using namespace ARDOUR;
using namespace Gtk;
+using namespace Gtkmm2ext;
using namespace sigc;
using namespace std;
using namespace PBD;
-static const float kOffsetForAUView_X = 220;
-static const float kOffsetForAUView_Y = 90;
+vector<string> AUPluginUI::automation_mode_strings;
+
+static const gchar* _automation_mode_strings[] = {
+ X_("Manual"),
+ X_("Play"),
+ X_("Write"),
+ X_("Touch"),
+ 0
+};
+
+@implementation NotificationObject
+
+- (NotificationObject*) initWithPluginUI: (AUPluginUI*) apluginui andCocoaParent: (NSWindow*) cp andTopLevelParent: (NSWindow*) tlp
+{
+ self = [ super init ];
+
+ if (self) {
+ plugin_ui = apluginui;
+ cocoa_parent = cp;
+ top_level_parent = tlp;
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(cocoaParentActivationHandler:)
+ name:NSWindowDidBecomeMainNotification
+ object:nil];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(cocoaParentBecameKeyHandler:)
+ name:NSWindowDidBecomeKeyNotification
+ object:nil];
+ }
+
+ 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;
+{
+ (void) notification;
+ plugin_ui->cocoa_view_resized();
+}
+
+@end
AUPluginUI::AUPluginUI (boost::shared_ptr<PluginInsert> insert)
: PlugUIBase (insert)
+ , automation_mode_label (_("Automation"))
+ , preset_label (_("Presets"))
+
{
+ 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());
+
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 ();
}
- bool has_carbon;
- bool has_cocoa;
+ /* stuff some stuff into the top of the window */
+
+ HBox* smaller_hbox = manage (new HBox);
+
+ smaller_hbox->set_spacing (6);
+ smaller_hbox->pack_start (preset_label, false, false, 4);
+ smaller_hbox->pack_start (_preset_box, false, false);
+ smaller_hbox->pack_start (save_button, false, false);
+#if 0
+ /* one day these might be useful with an AU plugin, but not yet */
+ smaller_hbox->pack_start (automation_mode_label, false, false);
+ smaller_hbox->pack_start (automation_mode_selector, false, false);
+#endif
+ 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);
+ top_box.set_spacing (6);
+ top_box.set_border_width (6);
+
+ top_box.pack_end (*v2_box, false, false);
+ top_box.pack_end (*v1_box, false, false);
+
+ set_spacing (6);
+ pack_start (top_box, false, false);
+ pack_start (low_box, false, false);
+
+ preset_label.show ();
+ _preset_combo.show ();
+ automation_mode_label.show ();
+ automation_mode_selector.show ();
+ bypass_button.show ();
+ top_box.show ();
+ low_box.show ();
_activating_from_app = false;
- carbon_parented = false;
- cocoa_parented = false;
cocoa_parent = 0;
+ _notify = 0;
cocoa_window = 0;
au_view = 0;
+ editView = 0;
- test_view_support (has_carbon, has_cocoa);
+ /* prefer cocoa, fall back to cocoa, but use carbon if its there */
- if (has_cocoa) {
+ if (test_cocoa_view_support()) {
create_cocoa_view ();
- } else if (has_carbon) {
- create_carbon_view (has_carbon);
+ } else if (test_carbon_view_support()) {
+ create_carbon_view ();
} else {
- /* fallback to cocoa */
create_cocoa_view ();
}
-}
+ low_box.signal_realize().connect (mem_fun (this, &AUPluginUI::lower_box_realized));
+}
AUPluginUI::~AUPluginUI ()
{
- if (carbon_parented) {
+ if (cocoa_parent) {
NSWindow* win = get_nswindow();
- RemoveEventHandler(carbon_event_handler);
+ [[NSNotificationCenter defaultCenter] removeObserver:_notify];
[win removeChildWindow:cocoa_parent];
+
+ }
+
+ if (carbon_window) {
+ /* not parented, just overlaid on top of our window */
+ DisposeWindow (carbon_window);
}
-}
-void
-AUPluginUI::test_view_support (bool& has_carbon, bool& has_cocoa)
-{
- has_carbon = test_carbon_view_support();
- has_cocoa = test_cocoa_view_support();
+ if (editView) {
+ CloseComponent (editView);
+ }
+
+ if (au_view) {
+ /* remove whatever we packed into low_box so that GTK doesn't
+ mess with it.
+ */
+
+ [au_view removeFromSuperview];
+ }
}
bool
UInt32 dataSize;
Boolean isWritable;
NSString* factoryClassName = 0;
- NSURL* CocoaViewBundlePath;
+ NSURL* CocoaViewBundlePath = NULL;
OSStatus result = AudioUnitGetPropertyInfo (*au->get_au(),
kAudioUnitProperty_CocoaUI,
}
if (!wasAbleToLoadCustomView) {
- // [B] Otherwise show generic Cocoa view
+ // load generic Cocoa view
au_view = [[AUGenericView alloc] initWithAudioUnit:*au->get_au()];
[(AUGenericView *)au_view setShowsExpertParameters:YES];
}
- /* make a child cocoa window */
+ // watch for size changes of the view
- cocoa_window = [[NSWindow alloc]
- initWithContentRect:crect
- styleMask:NSBorderlessWindowMask
- backing:NSBackingStoreBuffered
- defer:NO];
+ [[NSNotificationCenter defaultCenter] addObserver:_notify
+ selector:@selector(auViewResized:) name:NSWindowDidResizeNotification
+ object:au_view];
+ // Get the size of the new AU View's frame
+
+ NSRect packFrame;
+ packFrame = [au_view frame];
+ prefwidth = packFrame.size.width;
+ prefheight = packFrame.size.height;
+ low_box.set_size_request (prefwidth, prefheight);
+
return 0;
}
+void
+AUPluginUI::cocoa_view_resized ()
+{
+ NSRect packFrame = [au_view frame];
+}
+
int
-AUPluginUI::create_carbon_view (bool generic)
+AUPluginUI::create_carbon_view ()
{
OSStatus err;
ControlRef root_control;
kWindowNoShadowAttribute|
kWindowNoTitleBarAttribute);
- if ((err = CreateNewWindow(kFloatingWindowClass, attr, &r, &carbon_window)) != noErr) {
+ if ((err = CreateNewWindow(kDocumentWindowClass, attr, &r, &carbon_window)) != noErr) {
error << string_compose (_("AUPluginUI: cannot create carbon window (err: %1)"), err) << endmsg;
+ CloseComponent (editView);
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;
+ DisposeWindow (carbon_window);
+ CloseComponent (editView);
return -1;
}
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;
+ DisposeWindow (carbon_window);
+ CloseComponent (editView);
return -1;
}
GetControlBounds(viewPane, &bounds);
size.x = bounds.right-bounds.left;
size.y = bounds.bottom-bounds.top;
- SizeWindow(carbon_window, (short) (size.x + 0.5), (short) (size.y + 0.5), true);
prefwidth = (int) (size.x + 0.5);
prefheight = (int) (size.y + 0.5);
-#if 0
- mViewPaneResizer->WantEventTypes (GetControlEventTarget(mAUViewPane), GetEventTypeCount(resizeEvent), resizeEvent);
-#endif
+ SizeWindow (carbon_window, prefwidth, prefheight, true);
+ low_box.set_size_request (prefwidth, prefheight);
+
return 0;
}
void
AUPluginUI::activate ()
{
- NSWindow* win = get_nswindow ();
- [win setLevel:NSFloatingWindowLevel];
-
- if (carbon_parented) {
- [cocoa_parent makeKeyAndOrderFront:nil];
- cerr << "APP activated, activate carbon window\n";
- _activating_from_app = true;
- ActivateWindow (carbon_window, TRUE);
- _activating_from_app = false;
- }
+ ActivateWindow (carbon_window, TRUE);
+ // [cocoa_parent makeKeyAndOrderFront:nil];
}
void
AUPluginUI::deactivate ()
{
- /* nothing to do here */
-}
-
-
-OSStatus
-_carbon_event (EventHandlerCallRef nextHandlerRef, EventRef event, void *userData)
-{
- return ((AUPluginUI*)userData)->carbon_event (nextHandlerRef, event);
-}
-
-OSStatus
-AUPluginUI::carbon_event (EventHandlerCallRef nextHandlerRef, EventRef event)
-{
- UInt32 eventKind = GetEventKind(event);
- ClickActivationResult howToHandleClick;
- NSWindow* win = get_nswindow ();
-
- cerr << "window " << win << " carbon event type " << eventKind << endl;
-
- switch (eventKind) {
- case kEventWindowHandleActivate:
- cerr << "carbon window activated\n";
- if (_activating_from_app) {
- cerr << "app activation, ignore window activation\n";
- return noErr;
- }
- [win makeMainWindow];
- return eventNotHandledErr;
- break;
-
- case kEventWindowHandleDeactivate:
- cerr << "carbon window deactivated\n";
- return eventNotHandledErr;
- break;
-
- case kEventWindowGetClickActivation:
- cerr << "carbon window CLICK activated\n";
- howToHandleClick = kActivateAndHandleClick;
- SetEventParameter(event, kEventParamClickActivation, typeClickActivationResult,
- sizeof(ClickActivationResult), &howToHandleClick);
- break;
- }
-
- return noErr;
+ ActivateWindow (carbon_window, FALSE);
}
int
int titlebar_height = wm_frame.size.height - content_frame.size.height;
- MoveWindow (carbon_window, x, y + titlebar_height, false);
+ int packing_extra = 6; // this is the total vertical packing in our top level window
+
+ MoveWindow (carbon_window, x, y + titlebar_height + top_box.get_height() + packing_extra, false);
ShowWindow (carbon_window);
// create the cocoa window for the carbon one and make it visible
cocoa_parent = [[NSWindow alloc] initWithWindowRef: carbon_window];
- EventTypeSpec windowEventTypes[] = {
- {kEventClassWindow, kEventWindowGetClickActivation },
- {kEventClassWindow, kEventWindowHandleDeactivate },
- {kEventClassWindow, kEventWindowHandleActivate }
- };
-
- EventHandlerUPP ehUPP = NewEventHandlerUPP(_carbon_event);
- OSStatus result = InstallWindowEventHandler (carbon_window, ehUPP,
- sizeof(windowEventTypes) / sizeof(EventTypeSpec),
- windowEventTypes, this, &carbon_event_handler);
- if (result != noErr) {
- return -1;
- }
+ SetWindowActivationScope (carbon_window, kWindowActivationScopeNone);
+
+ _notify = [ [NotificationObject alloc] initWithPluginUI:this andCocoaParent:cocoa_parent andTopLevelParent:win ];
[win addChildWindow:cocoa_parent ordered:NSWindowAbove];
- [win setLevel:NSFloatingWindowLevel];
- [win setHidesOnDeactivate:YES];
- carbon_parented = true;
-
return 0;
}
return -1;
}
+ [win setAutodisplay:YES]; // turn of GTK stuff for this window
+
Gtk::Container* toplevel = get_toplevel();
if (!toplevel || !toplevel->is_toplevel()) {
error << _("AUPluginUI: no top level window!") << endmsg;
return -1;
}
-
- // Get the size of the new AU View's frame
- NSRect au_view_frame = [au_view frame];
- if (au_view_frame.size.width > 500 || au_view_frame.size.height > 500) {
-
- /* its too big - use a scrollview */
-
- NSRect frameRect = [[cocoa_window contentView] frame];
- scroll_view = [[[NSScrollView alloc] initWithFrame:frameRect] autorelease];
- [scroll_view setDrawsBackground:NO];
- [scroll_view setHasHorizontalScroller:YES];
- [scroll_view setHasVerticalScroller:YES];
-
- NSSize frameSize = [NSScrollView frameSizeForContentSize:au_view_frame.size
- hasHorizontalScroller:[scroll_view hasHorizontalScroller]
- hasVerticalScroller:[scroll_view hasVerticalScroller]
- borderType:[scroll_view borderType]];
-
- // Create a new frame with same origin as current
- // frame but size equal to the size of the new view
- NSRect newFrame;
- newFrame.origin = [scroll_view frame].origin;
- newFrame.size = frameSize;
-
- // Set the new frame and document views on the scroll view
- NSRect currentFrame = [scroll_view frame];
- [scroll_view setFrame:newFrame];
- [scroll_view setDocumentView:au_view];
-
- cerr << "scroll view size is " << newFrame.size.width << " x " << newFrame.size.height << endl;
-
- NSSize oldContentSize = [[cocoa_window contentView] frame].size;
- NSSize newContentSize = oldContentSize;
-
- cerr << "original size is " << newContentSize.width << " x " << newContentSize.height << endl;
-
- newContentSize.width += (newFrame.size.width - currentFrame.size.width);
- newContentSize.height += (newFrame.size.height - currentFrame.size.height);
-
-#ifdef PACK_COCOA_INTO_GTK_WINDOW
- NSView* view = [win contentView];
-
- [win setContentSize:newContentSize];
- [view addSubview:scroll_view];
-#else
- [cocoa_window setContentSize:newContentSize];
- [cocoa_window setContentView:scroll_view];
-#endif
-
- } else {
+ NSView* view = gdk_quartz_window_get_nsview (get_toplevel()->get_window()->gobj());
+ GtkRequisition a = top_box.size_request ();
-#ifdef PACK_COCOA_INTO_GTK_WINDOW
- NSView* view = [win contentView];
+ /* move the au_view down so that it doesn't overlap the top_box contents */
- [win setContentSize:au_view_frame.size];
- [view addSubview:au_view];
-#else
- [cocoa_window setContentSize:au_view_frame.size];
- [cocoa_window setContentView:au_view];
-#endif
+ NSPoint origin = { 0, a.height };
- }
+ [au_view setFrameOrigin:origin];
+ [view addSubview:au_view];
- /* compute how tall the title bar is, because we have to offset the position of the child 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;
-
- // move cocoa window into position relative to the toplevel window
-
- NSRect view_frame = [[cocoa_window contentView] frame];
- view_frame.origin.x = content_frame.origin.x;
- view_frame.origin.y = content_frame.origin.y;
+ return 0;
+}
- [cocoa_window setFrame:view_frame display:NO];
+static void
+dump_view_tree (NSView* view, int depth)
+{
+ NSArray* subviews = [view subviews];
+ unsigned long cnt = [subviews count];
- /* make top level window big enough to hold cocoa window and titlebar */
-
- content_frame.size.width = view_frame.size.width;
- content_frame.size.height = view_frame.size.height + titlebar_height;
+ for (int d = 0; d < depth; d++) {
+ cerr << '\t';
+ }
+ cerr << " view @ " << view << endl;
+
+ for (unsigned long i = 0; i < cnt; ++i) {
+ NSView* subview = [subviews objectAtIndex:i];
+ dump_view_tree (subview, depth+1);
+ }
+}
- [win setFrame:content_frame display:NO];
+void
+AUPluginUI::forward_key_event (GdkEventKey* ev)
+{
+ NSEvent* nsevent = gdk_quartz_event_get_nsevent ((GdkEvent*)ev);
- /* now make cocoa window a child of this top level */
-
- [win addChildWindow:cocoa_window ordered:NSWindowAbove];
- [win setLevel:NSFloatingWindowLevel];
- [win setHidesOnDeactivate:YES];
+ if (au_view && nsevent) {
- cocoa_parented = true;
+ /* 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
+ */
- return 0;
+ 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];
+ }
+ }
}
void
{
VBox::on_realize ();
- if (au_view) {
-
- if (parent_cocoa_window ()) {
- }
+ /* our windows should not have that resize indicator */
- } else if (carbon_window) {
-
- if (parent_carbon_window ()) {
- // ShowWindow (carbon_window);
- }
+ NSWindow* win = get_nswindow ();
+ if (win) {
+ [win setShowsResizeIndicator:NO];
}
}
void
-AUPluginUI::on_hide ()
+AUPluginUI::lower_box_realized ()
{
- // VBox::on_hide ();
- cerr << "AU plugin window hidden\n";
+ if (au_view) {
+ parent_cocoa_window ();
+ } else if (carbon_window) {
+ parent_carbon_window ();
+ }
}
bool
-AUPluginUI::on_map_event (GdkEventAny* ev)
+AUPluginUI::on_map_event (GdkEventAny*)
{
- cerr << "AU plugin map event\n";
-
- if (au_view) {
- show_all ();
- } else if (carbon_window) {
- [cocoa_parent setIsVisible:YES];
- ShowWindow (carbon_window);
- }
return false;
}
void
-AUPluginUI::on_show ()
+AUPluginUI::on_window_hide ()
{
- cerr << "AU plugin window shown\n";
+ if (carbon_window) {
+ HideWindow (carbon_window);
+ ActivateWindow (carbon_window, FALSE);
+ }
- VBox::on_show ();
+ hide_all ();
+}
- if (au_view) {
- show_all ();
- } else if (carbon_window) {
- [cocoa_parent setIsVisible:YES];
+bool
+AUPluginUI::on_window_show (const string& /*title*/)
+{
+ /* this is idempotent so just call it every time we show the window */
+
+ gtk_widget_realize (GTK_WIDGET(low_box.gobj()));
+
+ show_all ();
+
+ if (carbon_window) {
ShowWindow (carbon_window);
+ ActivateWindow (carbon_window, TRUE);
}
+
+ return true;
}
bool
-AUPluginUI::start_updating (GdkEventAny* any)
+AUPluginUI::start_updating (GdkEventAny*)
{
return false;
}
bool
-AUPluginUI::stop_updating (GdkEventAny* any)
+AUPluginUI::stop_updating (GdkEventAny*)
{
return false;
}
}
bool
-AUPluginUI::on_focus_in_event (GdkEventFocus* ev)
+AUPluginUI::on_focus_in_event (GdkEventFocus*)
{
- cerr << "au plugin focus in\n";
+ //cerr << "au plugin focus in\n";
+ //Keyboard::magic_widget_grab_focus ();
return false;
}
bool
-AUPluginUI::on_focus_out_event (GdkEventFocus* ev)
+AUPluginUI::on_focus_out_event (GdkEventFocus*)
{
- cerr << "au plugin focus out\n";
+ //cerr << "au plugin focus out\n";
+ //Keyboard::magic_widget_drop_focus ();
return false;
}
+