replace ::cast_dynamic() with relevant ActionManager::get_*_action() calls
[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 #ifndef __gtk2_ardour_auplugin_ui_h__
20 #define __gtk2_ardour_auplugin_ui_h__
21
22 #include <vector>
23 #include <string>
24
25 #include <stdint.h>
26
27 #include <AppKit/AppKit.h>
28 #include <Carbon/Carbon.h>
29 #include <AudioUnit/AudioUnitCarbonView.h>
30 #include <AudioUnit/AudioUnit.h>
31
32 /* fix up stupid apple macros */
33
34 #undef check
35 #undef require
36 #undef verify
37
38 #ifdef YES
39 #undef YES
40 #endif
41 #ifdef NO
42 #undef NO
43 #endif
44
45 #include <gtkmm/box.h>
46 #include <gtkmm/eventbox.h>
47 #include <gtkmm/combobox.h>
48 #include <gtkmm/button.h>
49 #include <gtkmm/label.h>
50
51 #include "plugin_ui.h"
52
53 namespace ARDOUR {
54         class AUPlugin;
55         class PluginInsert;
56         class IOProcessor;
57 }
58
59 class AUPluginUI;
60
61 @interface NotificationObject : NSObject {
62         @private
63                 AUPluginUI* plugin_ui;
64                 NSWindow* cocoa_parent;
65                 NSWindow* top_level_parent;
66 }
67 @end
68
69 @interface LiveResizeNotificationObject : NSObject {
70         @private
71                 AUPluginUI* plugin_ui;
72 }
73 @end
74
75 class AUPluginUI : public PlugUIBase, public Gtk::VBox
76 {
77 public:
78         AUPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>);
79         ~AUPluginUI ();
80
81         gint get_preferred_width () { return req_width; }
82         gint get_preferred_height () { return req_height; }
83         bool start_updating(GdkEventAny*);
84         bool stop_updating(GdkEventAny*);
85
86         void activate ();
87         void deactivate ();
88
89         bool non_gtk_gui() const { return true; }
90
91         void lower_box_realized ();
92         bool lower_box_visibility_notify (GdkEventVisibility*);
93
94         void lower_box_map ();
95         void lower_box_unmap ();
96         void lower_box_size_request (GtkRequisition*);
97         void lower_box_size_allocate (Gtk::Allocation&);
98
99         void cocoa_view_resized ();
100         void on_realize ();
101         void grab_focus();
102         void forward_key_event (GdkEventKey*);
103
104         bool on_window_show (const std::string& /*title*/);
105         void on_window_hide ();
106
107         OSStatus carbon_event (EventHandlerCallRef nextHandlerRef, EventRef event);
108
109         void start_live_resize ();
110         void end_live_resize ();
111
112 private:
113         WindowRef wr;
114         boost::shared_ptr<ARDOUR::AUPlugin> au;
115         int prefheight;
116         int prefwidth;
117
118         Gtk::HBox     top_box;
119         Gtk::EventBox low_box;
120         Gtk::VBox vpacker;
121         Gtk::Label automation_mode_label;
122         Gtk::ComboBoxText automation_mode_selector;
123         Gtk::Label preset_label;
124
125         static std::vector<std::string> automation_mode_strings;
126
127         bool resizable;
128         int  req_width;
129         int  req_height;
130
131         /* Cocoa */
132
133         NSWindow*           cocoa_window;
134         NSView*             au_view;
135         NSRect              last_au_frame;
136         bool                in_live_resize;
137         uint32_t            plugin_requested_resize;
138
139         /* Carbon */
140
141         NSWindow*            cocoa_parent;
142         ComponentDescription carbon_descriptor;
143         AudioUnitCarbonView  editView;
144         WindowRef            carbon_window;
145         EventHandlerRef      carbon_event_handler;
146         bool                 _activating_from_app;
147
148         /* Generic */
149
150         NotificationObject* _notify;
151         LiveResizeNotificationObject* _resize_notify;
152
153         bool test_cocoa_view_support ();
154         bool test_carbon_view_support ();
155         int  create_carbon_view ();
156         int  create_cocoa_view ();
157
158         int parent_carbon_window ();
159         int parent_cocoa_window ();
160         NSWindow* get_nswindow();
161
162         void update_view_size ();
163
164         bool plugin_class_valid (Class pluginClass);
165
166         friend void au_cf_timer_callback (CFRunLoopTimerRef timer, void* info);
167         static CFRunLoopTimerRef   cf_timer;
168         static void cf_timer_callback ();
169         static int64_t last_timer;
170         static bool timer_needed;
171         static uint64_t timer_callbacks;
172         static uint64_t timer_out_of_range;
173
174         static bool timer_callback ();
175         static sigc::connection timer_connection;
176
177 public:
178         static void start_cf_timer ();
179         static void stop_cf_timer ();
180 };
181
182 #endif /* __gtk2_ardour_auplugin_ui_h__  */