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