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 #include "ardour/plugin_insert.h"
42 
43 #include "lv2_external_ui.h"
44 
45 #include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
46 
47 namespace ARDOUR {
48 	class PluginInsert;
49 	class LV2Plugin;
50 }
51 
52 class LV2PluginUI : public PlugUIBase, public Gtk::VBox
53 {
54 public:
55 	LV2PluginUI (boost::shared_ptr<ARDOUR::PluginInsert>,
56 			boost::shared_ptr<ARDOUR::LV2Plugin>);
57 	~LV2PluginUI ();
58 
59 	gint get_preferred_height ();
60 	gint get_preferred_width ();
61 	bool resizable ();
62 
63 	bool start_updating(GdkEventAny*);
64 	bool stop_updating(GdkEventAny*);
65 
66 	int package (Gtk::Window&);
67 	void grab_focus ();
68 
69 private:
70 
71 	void control_changed (uint32_t);
72 
73 	typedef boost::shared_ptr<ARDOUR::AutomationControl> ControllableRef;
74 
75 	boost::shared_ptr<ARDOUR::PluginInsert> _pi;
76 	boost::shared_ptr<ARDOUR::LV2Plugin> _lv2;
77 	std::vector<int>                     _output_ports;
78 	sigc::connection                     _screen_update_connection;
79 	sigc::connection                     _message_update_connection;
80 	Gtk::Widget*                         _gui_widget;
81 	/** a box containing the focus, bypass, delete, save / add preset buttons etc. */
82 	Gtk::HBox                            _ardour_buttons_box;
83 	float*                               _values_last_sent_to_ui;
84 	std::vector<ControllableRef>         _controllables;
85 	struct lv2_external_ui_host          _external_ui_host;
86 	LV2_Feature                          _external_ui_feature;
87 	LV2_Feature                          _external_kxui_feature;
88 #ifdef HAVE_LV2_1_17_2
89 	LV2UI_Request_Value                  _lv2ui_request_value;
90 	LV2_Feature                          _lv2ui_request_feature;
91 #endif
92 	struct lv2_external_ui*              _external_ui_ptr;
93 	LV2_Feature                          _parent_feature;
94 	void*                                _inst;
95 	typedef std::set<uint32_t> Updates;
96 	Updates                              _updates;
97 
98 	static void on_external_ui_closed(void* controller);
99 
100 	static void write_from_ui(void*       controller,
101 	                          uint32_t    port_index,
102 	                          uint32_t    buffer_size,
103 	                          uint32_t    format,
104 	                          const void* buffer);
105 
106 	static void write_to_ui(void*       controller,
107 	                        uint32_t    port_index,
108 	                        uint32_t    buffer_size,
109 	                        uint32_t    format,
110 	                        const void* buffer);
111 
112 	static uint32_t port_index(void* controller, const char* symbol);
113 
114 	static void touch(void*    controller,
115 	                  uint32_t port_index,
116 	                  bool     grabbed);
117 
118 #ifdef HAVE_LV2_1_17_2
119 	static LV2UI_Request_Value_Status
120 	request_value(void*                     handle,
121 	              LV2_URID                  key,
122 	              LV2_URID                  type,
123 	              const LV2_Feature* const* features);
124 #endif
125 
126 	void set_path_property (int,
127 	                        const ARDOUR::ParameterDescriptor&,
128 	                        Gtk::FileChooserDialog*);
129 	std::set<uint32_t> active_parameter_requests;
130 
131 	void update_timeout();
132 
133 	void lv2ui_instantiate(const std::string& title);
134 	void lv2ui_free();
135 
136 	void parameter_update(uint32_t, float);
137 	bool configure_handler (GdkEventConfigure*);
138 	void save_plugin_setting ();
139 	void output_update();
140 	void queue_port_update();
141 	bool is_update_wanted(uint32_t index);
142 
143 	virtual bool on_window_show(const std::string& title);
144 	virtual void on_window_hide();
145 };
146 
147 #endif /* __ardour_lv2_plugin_ui_h__ */
148