add session-scope selection ops for Stripables
[ardour.git] / gtk2_ardour / au_pluginui.h
1 /*
2     Copyright (C) 2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __gtk2_ardour_auplugin_ui_h__
21 #define __gtk2_ardour_auplugin_ui_h__
22
23 #include <vector>
24 #include <string>
25
26 #include <stdint.h>
27
28 #include <AppKit/AppKit.h>
29 #include <Carbon/Carbon.h>
30 #include <AudioUnit/AudioUnitCarbonView.h>
31 #include <AudioUnit/AudioUnit.h>
32
33 /* fix up stupid apple macros */
34
35 #undef check
36 #undef require
37 #undef verify
38
39 #ifdef YES
40 #undef YES
41 #endif
42 #ifdef NO
43 #undef NO
44 #endif
45
46 #include <gtkmm/box.h>
47 #include <gtkmm/eventbox.h>
48 #include <gtkmm/combobox.h>
49 #include <gtkmm/button.h>
50 #include <gtkmm/label.h>
51
52 #include "plugin_ui.h"
53
54 namespace ARDOUR {
55         class AUPlugin;
56         class PluginInsert;
57         class IOProcessor;
58 }
59
60 class AUPluginUI;
61
62 @interface NotificationObject : NSObject {
63         @private
64                 AUPluginUI* plugin_ui;
65                 NSWindow* cocoa_parent;
66                 NSWindow* top_level_parent;
67 }
68 @end
69
70 @interface LiveResizeNotificationObject : NSObject {
71         @private
72                 AUPluginUI* plugin_ui;
73 }
74 @end
75
76 class AUPluginUI : public PlugUIBase, public Gtk::VBox
77 {
78   public:
79         AUPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>);
80         ~AUPluginUI ();
81
82         gint get_preferred_width () { return req_width; }
83         gint get_preferred_height () { return req_height; }
84         bool start_updating(GdkEventAny*);
85         bool stop_updating(GdkEventAny*);
86
87         void activate ();
88         void deactivate ();
89
90         bool non_gtk_gui() const { return true; }
91
92         void lower_box_realized ();
93         bool lower_box_visibility_notify (GdkEventVisibility*);
94
95         void lower_box_map ();
96         void lower_box_unmap ();
97         void lower_box_size_request (GtkRequisition*);
98         void lower_box_size_allocate (Gtk::Allocation&);
99
100         void cocoa_view_resized ();
101         void on_realize ();
102         void grab_focus();
103         void forward_key_event (GdkEventKey*);
104
105         bool on_window_show (const std::string& /*title*/);
106         void on_window_hide ();
107
108         OSStatus carbon_event (EventHandlerCallRef nextHandlerRef, EventRef event);
109
110         void start_live_resize ();
111         void end_live_resize ();
112
113   private:
114         WindowRef wr;
115         boost::shared_ptr<ARDOUR::AUPlugin> au;
116         int prefheight;
117         int prefwidth;
118
119         Gtk::HBox     top_box;
120         Gtk::EventBox low_box;
121         Gtk::VBox vpacker;
122         Gtk::Label automation_mode_label;
123         Gtk::ComboBoxText automation_mode_selector;
124         Gtk::Label preset_label;
125
126         static std::vector<std::string> automation_mode_strings;
127
128         bool resizable;
129         int  req_width;
130         int  req_height;
131
132         /* Cocoa */
133
134         NSWindow*           cocoa_window;
135         NSView*             au_view;
136         NSRect              last_au_frame;
137         bool                in_live_resize;
138         uint32_t            plugin_requested_resize;
139
140         /* Carbon */
141
142         NSWindow*            cocoa_parent;
143         ComponentDescription carbon_descriptor;
144         AudioUnitCarbonView  editView;
145         WindowRef            carbon_window;
146         EventHandlerRef      carbon_event_handler;
147         bool                 _activating_from_app;
148
149         /* Generic */
150
151         NotificationObject* _notify;
152         LiveResizeNotificationObject* _resize_notify;
153
154         bool test_cocoa_view_support ();
155         bool test_carbon_view_support ();
156         int  create_carbon_view ();
157         int  create_cocoa_view ();
158
159         int parent_carbon_window ();
160         int parent_cocoa_window ();
161         NSWindow* get_nswindow();
162
163         void update_view_size ();
164
165         bool plugin_class_valid (Class pluginClass);
166
167         friend void au_cf_timer_callback (CFRunLoopTimerRef timer, void* info);
168         static CFRunLoopTimerRef   cf_timer;
169         static void cf_timer_callback ();
170         static int64_t last_timer;
171         static bool timer_needed;
172         static uint64_t timer_callbacks;
173         static uint64_t timer_out_of_range;
174
175         static bool timer_callback ();
176         static sigc::connection timer_connection;
177
178   public:
179         static void start_cf_timer ();
180         static void stop_cf_timer ();
181 };
182
183 #endif /* __gtk2_ardour_auplugin_ui_h__  */