Fix DSP load sorting with inactive plugins
[ardour.git] / gtk2_ardour / lv2_plugin_ui.h
1 /*
2  * Copyright (C) 2008-2012 David Robillard <d@drobilla.net>
3  * Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2012-2018 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef __ardour_lv2_plugin_ui_h__
23 #define __ardour_lv2_plugin_ui_h__
24
25 #ifdef WAF_BUILD
26 #include "gtk2ardour-config.h"
27 #endif
28
29 #include <list>
30 #include <map>
31 #include <set>
32 #include <vector>
33
34 #include <gtkmm/widget.h>
35 #include <sigc++/signal.h>
36
37 #include "ardour_dialog.h"
38 #include "ardour/types.h"
39 #include "plugin_ui.h"
40
41 #ifdef LV2_SUPPORT
42 #include "ardour/plugin_insert.h"
43
44 #include "lv2_external_ui.h"
45
46 #include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
47 #ifndef LV2_1_14_0
48 typedef struct _LV2UI_Request_Parameter {
49         LV2UI_Feature_Handle handle;
50         uint32_t (*request)(LV2UI_Feature_Handle handle, LV2_URID key);
51 }LV2UI_Request_Parameter;
52 #endif
53
54 namespace ARDOUR {
55         class PluginInsert;
56         class LV2Plugin;
57 }
58
59 class LV2PluginUI : public PlugUIBase, public Gtk::VBox
60 {
61 public:
62         LV2PluginUI (boost::shared_ptr<ARDOUR::PluginInsert>,
63                         boost::shared_ptr<ARDOUR::LV2Plugin>);
64         ~LV2PluginUI ();
65
66         gint get_preferred_height ();
67         gint get_preferred_width ();
68         bool resizable ();
69
70         bool start_updating(GdkEventAny*);
71         bool stop_updating(GdkEventAny*);
72
73         int package (Gtk::Window&);
74         void grab_focus ();
75
76 private:
77
78         void control_changed (uint32_t);
79
80         typedef boost::shared_ptr<ARDOUR::AutomationControl> ControllableRef;
81
82         boost::shared_ptr<ARDOUR::PluginInsert> _pi;
83         boost::shared_ptr<ARDOUR::LV2Plugin> _lv2;
84         std::vector<int>                     _output_ports;
85         sigc::connection                     _screen_update_connection;
86         sigc::connection                     _message_update_connection;
87         Gtk::Widget*                         _gui_widget;
88         /** a box containing the focus, bypass, delete, save / add preset buttons etc. */
89         Gtk::HBox                            _ardour_buttons_box;
90         float*                               _values_last_sent_to_ui;
91         std::vector<ControllableRef>         _controllables;
92         struct lv2_external_ui_host          _external_ui_host;
93         LV2_Feature                          _external_ui_feature;
94         LV2_Feature                          _external_kxui_feature;
95         LV2UI_Request_Parameter              _lv2ui_request_paramater;
96         LV2_Feature                          _lv2ui_request_feature;
97         struct lv2_external_ui*              _external_ui_ptr;
98         LV2_Feature                          _parent_feature;
99         Gtk::Window*                         _win_ptr;
100         void*                                _inst;
101         typedef std::set<uint32_t> Updates;
102         Updates                              _updates;
103
104         static void on_external_ui_closed(void* controller);
105
106         static void write_from_ui(void*       controller,
107                                   uint32_t    port_index,
108                                   uint32_t    buffer_size,
109                                   uint32_t    format,
110                                   const void* buffer);
111
112         static void write_to_ui(void*       controller,
113                                 uint32_t    port_index,
114                                 uint32_t    buffer_size,
115                                 uint32_t    format,
116                                 const void* buffer);
117
118         static uint32_t port_index(void* controller, const char* symbol);
119
120         static void touch(void*    controller,
121                           uint32_t port_index,
122                           bool     grabbed);
123
124         static uint32_t request_parameter (void* handle, LV2_URID key);
125         void set_path_property (int,
126                                 const ARDOUR::ParameterDescriptor&,
127                                 Gtk::FileChooserDialog*);
128         std::set<uint32_t> active_parameter_requests;
129
130         void update_timeout();
131
132         void lv2ui_instantiate(const std::string& title);
133         void lv2ui_free();
134
135         void parameter_update(uint32_t, float);
136         bool configure_handler (GdkEventConfigure*);
137         void save_plugin_setting ();
138         void output_update();
139         void queue_port_update();
140         bool is_update_wanted(uint32_t index);
141
142         virtual bool on_window_show(const std::string& title);
143         virtual void on_window_hide();
144 };
145
146 #endif // LV2_SUPPORT
147
148 #endif /* __ardour_lv2_plugin_ui_h__ */
149