27 #include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
29 #include <lilv/lilv.h>
30 #include <suil/suil.h>
38 #define NS_UI "http://lv2plug.in/ns/extensions/ui#"
43 LV2PluginUI::write_from_ui(
void* controller,
49 LV2PluginUI* me = (LV2PluginUI*)controller;
51 if (port_index >= me->_controllables.size()) {
61 const int cnt = me->_pi->get_count();
62 for (
int i=0; i < cnt; i++ ) {
64 lv2i->
write_from_ui(port_index, format, buffer_size, (
const uint8_t*)buffer);
70 LV2PluginUI::write_to_ui(
void* controller,
76 LV2PluginUI* me = (LV2PluginUI*)controller;
78 suil_instance_port_event((SuilInstance*)me->_inst,
79 port_index, buffer_size, format, buffer);
84 LV2PluginUI::port_index(
void* controller,
const char* symbol)
86 return ((LV2PluginUI*)controller)->_lv2->port_index(symbol);
90 LV2PluginUI::touch(
void* controller,
94 LV2PluginUI* me = (LV2PluginUI*)controller;
95 if (port_index >= me->_controllables.size()) {
99 ControllableRef control = me->_controllables[port_index];
101 control->start_touch(control->session().transport_frame());
103 control->stop_touch(
false, control->session().transport_frame());
108 LV2PluginUI::update_timeout()
110 _lv2->emit_to_ui(
this, &LV2PluginUI::write_to_ui);
114 LV2PluginUI::on_external_ui_closed(
void* controller)
117 LV2PluginUI* me = (LV2PluginUI*)controller;
118 me->_screen_update_connection.disconnect();
119 me->_external_ui_ptr = NULL;
123 LV2PluginUI::parameter_changed(uint32_t port_index,
float val)
127 if (val != _values[port_index]) {
128 parameter_update(port_index, val);
133 LV2PluginUI::parameter_update(uint32_t port_index,
float val)
139 suil_instance_port_event((SuilInstance*)_inst, port_index, 4, 0, &val);
140 _values[port_index] = val;
144 LV2PluginUI::start_updating(GdkEventAny*)
146 if (!_output_ports.empty()) {
147 _screen_update_connection.disconnect();
149 (sigc::mem_fun(*
this, &LV2PluginUI::output_update));
155 LV2PluginUI::stop_updating(GdkEventAny*)
159 if (!_output_ports.empty()) {
160 _screen_update_connection.disconnect();
166 LV2PluginUI::output_update()
169 if (_external_ui_ptr) {
171 if (_lv2->is_external_kx() && !_external_ui_ptr) {
176 _message_update_connection.disconnect();
178 suil_instance_free((SuilInstance*)_inst);
181 _external_ui_ptr = NULL;
187 uint32_t nports = _output_ports.size();
188 for (uint32_t i = 0; i < nports; ++i) {
189 uint32_t index = _output_ports[i];
190 parameter_changed(index, _lv2->get_parameter(index));
202 , _external_ui_ptr(NULL)
205 _ardour_buttons_box.set_spacing (6);
206 _ardour_buttons_box.set_border_width (6);
207 _ardour_buttons_box.pack_end (focus_button,
false,
false);
208 _ardour_buttons_box.pack_end (bypass_button,
false,
false, 4);
209 _ardour_buttons_box.pack_end (reset_button,
false,
false, 4);
210 _ardour_buttons_box.pack_end (delete_button,
false,
false);
211 _ardour_buttons_box.pack_end (save_button,
false,
false);
212 _ardour_buttons_box.pack_end (add_button,
false,
false);
213 _ardour_buttons_box.pack_end (_preset_combo,
false,
false);
214 _ardour_buttons_box.pack_end (_preset_modified,
false,
false);
218 LV2PluginUI::lv2ui_instantiate(
const std::string& title)
220 bool is_external_ui = _lv2->is_external_ui();
221 LV2_Feature** features_src =
const_cast<LV2_Feature**
>(_lv2->features());
222 LV2_Feature** features =
const_cast<LV2_Feature**
>(_lv2->features());
223 size_t features_count = 0;
224 while (*features++) {
228 Gtk::Alignment* container = NULL;
229 if (is_external_ui) {
230 _external_ui_host.ui_closed = LV2PluginUI::on_external_ui_closed;
231 _external_ui_host.plugin_human_id = strdup(title.c_str());
234 _external_ui_feature.data = &_external_ui_host;
237 _external_kxui_feature.data = &_external_ui_host;
240 features = (LV2_Feature**)malloc(
241 sizeof(LV2_Feature*) * (features_count + 2));
242 for (
size_t i = 0; i < features_count - 2; ++i) {
243 features[i] = features_src[i];
245 features[features_count - 2] = &_external_kxui_feature;
246 features[features_count - 1] = &_external_ui_feature;
247 features[features_count] = NULL;
249 if (_ardour_buttons_box.get_parent()) {
250 _ardour_buttons_box.get_parent()->remove(_ardour_buttons_box);
252 pack_start(_ardour_buttons_box,
false,
false);
253 _ardour_buttons_box.show_all();
255 _gui_widget = Gtk::manage((container =
new Gtk::Alignment()));
256 pack_start(*_gui_widget,
true,
true);
259 _parent_feature.URI = LV2_UI__parent;
260 _parent_feature.data = _gui_widget->gobj();
263 features = (LV2_Feature**)malloc(
264 sizeof(LV2_Feature*) * (features_count + 1));
265 for (
size_t i = 0; i < features_count - 1; ++i) {
266 features[i] = features_src[i];
268 features[features_count - 1] = &_parent_feature;
269 features[features_count] = NULL;
273 ui_host = suil_host_new(LV2PluginUI::write_from_ui,
274 LV2PluginUI::port_index,
276 suil_host_set_touch_func(
ui_host, LV2PluginUI::touch);
278 const char* container_type = (is_external_ui)
282 if (_lv2->has_message_output()) {
283 _lv2->enable_ui_emission();
286 const LilvUI*
ui = (
const LilvUI*)_lv2->c_ui();
287 const LilvNode* bundle = lilv_ui_get_bundle_uri(ui);
288 const LilvNode* binary = lilv_ui_get_binary_uri(ui);
289 #ifdef HAVE_LILV_0_21_3
290 char* ui_bundle_path = lilv_file_uri_parse(lilv_node_as_uri(bundle), NULL);
291 char* ui_binary_path = lilv_file_uri_parse(lilv_node_as_uri(binary), NULL);
293 char* ui_bundle_path = strdup(lilv_uri_to_path(lilv_node_as_uri(bundle)));
294 char* ui_binary_path = strdup(lilv_uri_to_path(lilv_node_as_uri(binary)));
296 if (!ui_bundle_path || !ui_binary_path) {
297 error <<
_(
"failed to get path for UI bindle or binary") <<
endmsg;
298 free(ui_bundle_path);
299 free(ui_binary_path);
304 _inst = suil_instance_new(
309 lilv_node_as_uri(lilv_ui_get_uri(ui)),
310 lilv_node_as_uri((
const LilvNode*)_lv2->c_ui_type()),
315 free(ui_bundle_path);
316 free(ui_binary_path);
319 #define GET_WIDGET(inst) suil_instance_get_widget((SuilInstance*)inst);
321 const uint32_t num_ports = _lv2->num_ports();
322 for (uint32_t i = 0; i < num_ports; ++i) {
323 if (_lv2->parameter_is_output(i)
324 && _lv2->parameter_is_control(i)
325 && is_update_wanted(i)) {
326 _output_ports.push_back(i);
330 _external_ui_ptr = NULL;
332 if (!is_external_ui) {
333 GtkWidget* c_widget = (GtkWidget*)
GET_WIDGET(_inst);
336 suil_instance_free((SuilInstance*)_inst);
340 if (!container->get_child()) {
342 container->add(*Gtk::manage(Glib::wrap(c_widget)));
344 container->show_all();
345 gtk_widget_set_can_focus(c_widget,
true);
346 gtk_widget_grab_focus(c_widget);
352 _values =
new float[num_ports];
353 _controllables.resize(num_ports);
354 for (uint32_t i = 0; i < num_ports; ++i) {
356 uint32_t port = _lv2->nth_parameter(i, ok);
358 _values[port] = _lv2->get_parameter(port);
362 if (_lv2->parameter_is_control(port) && _lv2->parameter_is_input(port)) {
363 parameter_update(port, _values[port]);
368 if (_lv2->has_message_output()) {
370 sigc::mem_fun(*
this, &LV2PluginUI::update_timeout));
375 LV2PluginUI::grab_focus()
377 if (_inst && !_lv2->is_external_ui()) {
378 GtkWidget* c_widget = (GtkWidget*)
GET_WIDGET(_inst);
379 gtk_widget_grab_focus(c_widget);
384 LV2PluginUI::lv2ui_free()
389 remove (*_gui_widget);
394 suil_instance_free((SuilInstance*)_inst);
399 LV2PluginUI::~LV2PluginUI ()
405 _message_update_connection.disconnect();
406 _screen_update_connection.disconnect();
408 if (_external_ui_ptr && _lv2->is_external_kx()) {
412 _external_ui_ptr = NULL;
416 LV2PluginUI::get_preferred_height()
418 Gtk::Requisition r = size_request();
423 LV2PluginUI::get_preferred_width()
425 Gtk::Requisition r = size_request();
430 LV2PluginUI::resizable()
432 return _lv2->ui_is_resizable();
436 LV2PluginUI::package(Gtk::Window& win)
438 if (_external_ui_ptr) {
442 win.signal_configure_event().connect(
443 sigc::mem_fun(*
this, &LV2PluginUI::configure_handler));
444 win.signal_map_event().connect(
445 sigc::mem_fun(*
this, &LV2PluginUI::start_updating));
446 win.signal_unmap_event().connect(
447 sigc::mem_fun(*
this, &LV2PluginUI::stop_updating));
453 LV2PluginUI::configure_handler(GdkEventConfigure*)
455 std::cout <<
"CONFIGURE" << std::endl;
460 LV2PluginUI::is_update_wanted(uint32_t )
469 LV2PluginUI::on_window_show(
const std::string& title)
473 if (_lv2->is_external_ui()) {
474 if (_external_ui_ptr) {
475 _screen_update_connection.disconnect();
476 _message_update_connection.disconnect();
479 (sigc::mem_fun(*
this, &LV2PluginUI::output_update));
480 if (_lv2->has_message_output()) {
482 sigc::mem_fun(*
this, &LV2PluginUI::update_timeout));
486 lv2ui_instantiate(title);
487 if (!_external_ui_ptr) {
491 _screen_update_connection.disconnect();
492 _message_update_connection.disconnect();
495 (sigc::mem_fun(*
this, &LV2PluginUI::output_update));
496 if (_lv2->has_message_output()) {
498 sigc::mem_fun(*
this, &LV2PluginUI::update_timeout));
502 lv2ui_instantiate(
"gtk2gui");
509 LV2PluginUI::on_window_hide()
513 if (_lv2->is_external_ui()) {
514 if (!_external_ui_ptr) {
return; }
516 if (!_lv2->is_external_kx()) { return ; }
517 _message_update_connection.disconnect();
518 _screen_update_connection.disconnect();
519 _external_ui_ptr = NULL;
520 suil_instance_free((SuilInstance*)_inst);
sigc::connection super_rapid_connect(const sigc::slot< void > &slot)
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r)
LIBPBD_API Transmitter error
std::ostream & endmsg(std::ostream &ostr)
static URIMap & instance()
#define LV2_EXTERNAL_UI_RUN(ptr)
#define LV2_EXTERNAL_UI_KX__Host
static SuilHost * ui_host
#define LV2_EXTERNAL_UI_URI
bool write_from_ui(uint32_t index, uint32_t protocol, uint32_t size, const uint8_t *body)
#define LV2_EXTERNAL_UI_HIDE(ptr)
virtual void parameter_changed(uint32_t, float)
#define LV2_EXTERNAL_UI_SHOW(ptr)