2008-09-10 17:27:39 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2008-2018 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2012-2018 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-09-10 17:27:39 -04:00
|
|
|
|
2020-02-16 16:32:47 -05:00
|
|
|
#ifdef WAF_BUILD
|
|
|
|
#include "gtk2ardour-config.h"
|
|
|
|
#endif
|
|
|
|
|
2018-11-22 09:02:35 -05:00
|
|
|
#include <gtkmm/stock.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/lv2_plugin.h"
|
2012-04-11 00:53:47 -04:00
|
|
|
#include "ardour/session.h"
|
2012-05-23 22:50:36 -04:00
|
|
|
#include "pbd/error.h"
|
2015-10-20 10:12:51 -04:00
|
|
|
#include "pbd/stacktrace.h"
|
2008-09-10 17:27:39 -04:00
|
|
|
|
2015-10-20 10:12:51 -04:00
|
|
|
#include "gui_thread.h"
|
2008-09-10 17:27:39 -04:00
|
|
|
#include "lv2_plugin_ui.h"
|
2014-12-25 10:02:00 -05:00
|
|
|
#include "timers.h"
|
2008-09-10 17:27:39 -04:00
|
|
|
|
2018-11-20 20:26:33 -05:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2012-04-19 21:00:45 -04:00
|
|
|
#include "lv2/lv2plug.in/ns/extensions/ui/ui.h"
|
2011-04-22 04:08:37 -04:00
|
|
|
|
2011-05-15 19:10:13 -04:00
|
|
|
#include <lilv/lilv.h>
|
2011-05-14 17:05:26 -04:00
|
|
|
#include <suil/suil.h>
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2012-05-23 22:50:36 -04:00
|
|
|
|
2008-09-10 17:27:39 -04:00
|
|
|
using namespace ARDOUR;
|
2012-02-25 04:19:03 -05:00
|
|
|
using namespace Gtk;
|
2008-09-10 17:27:39 -04:00
|
|
|
using namespace PBD;
|
|
|
|
|
2011-05-14 15:55:46 -04:00
|
|
|
#define NS_UI "http://lv2plug.in/ns/extensions/ui#"
|
|
|
|
|
2011-05-14 17:05:26 -04:00
|
|
|
static SuilHost* ui_host = NULL;
|
2011-03-08 15:14:45 -05:00
|
|
|
|
2008-09-10 17:27:39 -04:00
|
|
|
void
|
2012-02-25 03:43:23 -05:00
|
|
|
LV2PluginUI::write_from_ui(void* controller,
|
|
|
|
uint32_t port_index,
|
|
|
|
uint32_t buffer_size,
|
|
|
|
uint32_t format,
|
|
|
|
const void* buffer)
|
2008-09-10 17:27:39 -04:00
|
|
|
{
|
2011-03-06 15:23:15 -05:00
|
|
|
LV2PluginUI* me = (LV2PluginUI*)controller;
|
2012-02-25 03:43:23 -05:00
|
|
|
if (format == 0) {
|
|
|
|
if (port_index >= me->_controllables.size()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-31 11:00:19 -05:00
|
|
|
|
2012-02-25 03:43:23 -05:00
|
|
|
boost::shared_ptr<AutomationControl> ac = me->_controllables[port_index];
|
2015-10-20 19:57:16 -04:00
|
|
|
|
|
|
|
me->_updates.insert (port_index);
|
|
|
|
|
2012-02-25 03:43:23 -05:00
|
|
|
if (ac) {
|
2016-01-02 04:58:23 -05:00
|
|
|
ac->set_value(*(const float*)buffer, Controllable::NoGroup);
|
2012-02-25 03:43:23 -05:00
|
|
|
}
|
2014-11-01 23:29:10 -04:00
|
|
|
} else if (format == URIMap::instance().urids.atom_eventTransfer) {
|
2012-08-28 11:42:42 -04:00
|
|
|
|
|
|
|
const int cnt = me->_pi->get_count();
|
|
|
|
for (int i=0; i < cnt; i++ ) {
|
|
|
|
boost::shared_ptr<LV2Plugin> lv2i = boost::dynamic_pointer_cast<LV2Plugin> (me->_pi->plugin(i));
|
|
|
|
lv2i->write_from_ui(port_index, format, buffer_size, (const uint8_t*)buffer);
|
|
|
|
}
|
2012-01-31 11:00:19 -05:00
|
|
|
}
|
2012-02-25 03:43:23 -05:00
|
|
|
}
|
2012-01-31 11:00:19 -05:00
|
|
|
|
2012-02-25 03:43:23 -05:00
|
|
|
void
|
|
|
|
LV2PluginUI::write_to_ui(void* controller,
|
|
|
|
uint32_t port_index,
|
|
|
|
uint32_t buffer_size,
|
|
|
|
uint32_t format,
|
|
|
|
const void* buffer)
|
|
|
|
{
|
|
|
|
LV2PluginUI* me = (LV2PluginUI*)controller;
|
2012-03-27 17:08:11 -04:00
|
|
|
if (me->_inst) {
|
|
|
|
suil_instance_port_event((SuilInstance*)me->_inst,
|
|
|
|
port_index, buffer_size, format, buffer);
|
|
|
|
}
|
2012-02-25 03:43:23 -05:00
|
|
|
}
|
2011-04-07 13:20:30 -04:00
|
|
|
|
2012-04-11 00:53:47 -04:00
|
|
|
uint32_t
|
|
|
|
LV2PluginUI::port_index(void* controller, const char* symbol)
|
|
|
|
{
|
|
|
|
return ((LV2PluginUI*)controller)->_lv2->port_index(symbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LV2PluginUI::touch(void* controller,
|
|
|
|
uint32_t port_index,
|
|
|
|
bool grabbed)
|
|
|
|
{
|
2012-04-12 00:03:14 -04:00
|
|
|
LV2PluginUI* me = (LV2PluginUI*)controller;
|
|
|
|
if (port_index >= me->_controllables.size()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-28 15:34:21 -04:00
|
|
|
if (!me->_lv2->parameter_is_control(port_index) || !me->_lv2->parameter_is_input(port_index)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-04-12 00:03:14 -04:00
|
|
|
|
2012-04-11 00:53:47 -04:00
|
|
|
ControllableRef control = me->_controllables[port_index];
|
|
|
|
if (grabbed) {
|
2017-09-18 12:39:17 -04:00
|
|
|
control->start_touch(control->session().transport_sample());
|
2012-04-11 00:53:47 -04:00
|
|
|
} else {
|
2017-09-18 12:39:17 -04:00
|
|
|
control->stop_touch(control->session().transport_sample());
|
2012-04-11 00:53:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-22 09:02:35 -05:00
|
|
|
void
|
|
|
|
LV2PluginUI::set_path_property (int response,
|
|
|
|
const ParameterDescriptor& desc,
|
|
|
|
Gtk::FileChooserDialog* widget)
|
|
|
|
{
|
|
|
|
if (response == Gtk::RESPONSE_ACCEPT) {
|
|
|
|
plugin->set_property (desc.key, Variant (Variant::PATH, widget->get_filename()));
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
widget->hide ();
|
|
|
|
delete_when_idle (widget);
|
|
|
|
#else
|
|
|
|
delete widget;
|
|
|
|
#endif
|
|
|
|
active_parameter_requests.erase (desc.key);
|
|
|
|
}
|
|
|
|
|
2020-02-16 16:32:47 -05:00
|
|
|
#ifdef HAVE_LV2_1_17_2
|
|
|
|
LV2UI_Request_Value_Status
|
|
|
|
LV2PluginUI::request_value(void* handle,
|
|
|
|
LV2_URID key,
|
|
|
|
LV2_URID type,
|
|
|
|
const LV2_Feature* const* features)
|
2018-11-20 20:26:33 -05:00
|
|
|
{
|
|
|
|
LV2PluginUI* me = (LV2PluginUI*)handle;
|
|
|
|
|
|
|
|
const ParameterDescriptor& desc (me->_lv2->get_property_descriptor(key));
|
2020-02-16 16:32:47 -05:00
|
|
|
if (desc.key == (uint32_t)-1) {
|
|
|
|
return LV2UI_REQUEST_VALUE_ERR_UNKNOWN;
|
|
|
|
} else if (desc.datatype != Variant::PATH) {
|
|
|
|
return LV2UI_REQUEST_VALUE_ERR_UNSUPPORTED;
|
|
|
|
} else if (me->active_parameter_requests.count (key)) {
|
|
|
|
return LV2UI_REQUEST_VALUE_BUSY;
|
2018-11-22 09:02:35 -05:00
|
|
|
}
|
|
|
|
me->active_parameter_requests.insert (key);
|
|
|
|
|
|
|
|
Gtk::FileChooserDialog* lv2ui_file_dialog = new Gtk::FileChooserDialog(desc.label, FILE_CHOOSER_ACTION_OPEN);
|
|
|
|
Gtkmm2ext::add_volume_shortcuts (*lv2ui_file_dialog);
|
|
|
|
lv2ui_file_dialog->add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
|
|
|
lv2ui_file_dialog->add_button (Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
|
|
|
|
lv2ui_file_dialog->set_default_response(Gtk::RESPONSE_ACCEPT);
|
|
|
|
|
|
|
|
/* this assumes announce_property_values() was called, or
|
|
|
|
* the plugin has previously sent a patch:Set */
|
|
|
|
const Variant& value = me->_lv2->get_property_value (desc.key);
|
|
|
|
if (value.type() == Variant::PATH) {
|
|
|
|
lv2ui_file_dialog->set_filename (value.get_path());
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 // TODO mime-type, file-extension filter, get from LV2 Parameter Property
|
2018-11-20 20:26:33 -05:00
|
|
|
FileFilter file_ext_filter;
|
|
|
|
file_ext_filter.add_pattern ("*.foo");
|
|
|
|
file_ext_filter.set_name ("Foo File");
|
|
|
|
lv2ui_file_dialog.add_filter (file_ext_filter);
|
|
|
|
#endif
|
|
|
|
|
2018-11-22 09:02:35 -05:00
|
|
|
lv2ui_file_dialog->signal_response().connect (sigc::bind (sigc::mem_fun (*me, &LV2PluginUI::set_path_property), desc, lv2ui_file_dialog));
|
|
|
|
lv2ui_file_dialog->present();
|
2020-02-16 16:32:47 -05:00
|
|
|
return LV2UI_REQUEST_VALUE_SUCCESS;
|
2018-11-20 20:26:33 -05:00
|
|
|
}
|
2020-02-16 16:32:47 -05:00
|
|
|
#endif
|
2018-11-20 20:26:33 -05:00
|
|
|
|
2012-02-25 15:43:14 -05:00
|
|
|
void
|
2012-02-25 03:43:23 -05:00
|
|
|
LV2PluginUI::update_timeout()
|
|
|
|
{
|
|
|
|
_lv2->emit_to_ui(this, &LV2PluginUI::write_to_ui);
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 15:23:15 -05:00
|
|
|
void
|
2011-04-22 04:08:37 -04:00
|
|
|
LV2PluginUI::on_external_ui_closed(void* controller)
|
2009-10-01 12:28:02 -04:00
|
|
|
{
|
2013-08-29 07:05:11 -04:00
|
|
|
//printf("LV2PluginUI::on_external_ui_closed\n");
|
2009-10-01 12:28:02 -04:00
|
|
|
LV2PluginUI* me = (LV2PluginUI*)controller;
|
2013-09-02 10:57:46 -04:00
|
|
|
me->_screen_update_connection.disconnect();
|
|
|
|
me->_external_ui_ptr = NULL;
|
2008-09-10 17:27:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-10-20 10:12:51 -04:00
|
|
|
LV2PluginUI::control_changed (uint32_t port_index)
|
2008-09-10 17:27:39 -04:00
|
|
|
{
|
2015-10-20 10:12:51 -04:00
|
|
|
/* Must run in GUI thread because we modify _updates with no lock */
|
2015-10-21 08:10:25 -04:00
|
|
|
if (_lv2->get_parameter (port_index) != _values_last_sent_to_ui[port_index]) {
|
2015-10-20 10:12:51 -04:00
|
|
|
/* current plugin parameter does not match last value received
|
|
|
|
from GUI, so queue an update to push it to the GUI during
|
|
|
|
our regular timeout.
|
|
|
|
*/
|
|
|
|
_updates.insert (port_index);
|
2008-09-10 17:27:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-14 17:14:15 -05:00
|
|
|
bool
|
2009-07-21 11:55:17 -04:00
|
|
|
LV2PluginUI::start_updating(GdkEventAny*)
|
2008-11-14 17:14:15 -05:00
|
|
|
{
|
2016-01-03 14:28:16 -05:00
|
|
|
_screen_update_connection.disconnect();
|
|
|
|
_screen_update_connection = Timers::super_rapid_connect
|
|
|
|
(sigc::mem_fun(*this, &LV2PluginUI::output_update));
|
2008-11-14 17:14:15 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-07-21 11:55:17 -04:00
|
|
|
LV2PluginUI::stop_updating(GdkEventAny*)
|
2008-11-14 17:14:15 -05:00
|
|
|
{
|
2009-10-01 12:28:02 -04:00
|
|
|
//cout << "stop_updating" << endl;
|
2016-01-03 14:28:16 -05:00
|
|
|
_screen_update_connection.disconnect();
|
2008-11-14 17:14:15 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-27 23:06:14 -04:00
|
|
|
void
|
|
|
|
LV2PluginUI::queue_port_update()
|
|
|
|
{
|
|
|
|
const uint32_t num_ports = _lv2->num_ports();
|
|
|
|
for (uint32_t i = 0; i < num_ports; ++i) {
|
|
|
|
bool ok;
|
|
|
|
uint32_t port = _lv2->nth_parameter(i, ok);
|
|
|
|
if (ok) {
|
|
|
|
_updates.insert (port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-14 17:14:15 -05:00
|
|
|
void
|
|
|
|
LV2PluginUI::output_update()
|
|
|
|
{
|
2009-10-01 12:28:02 -04:00
|
|
|
//cout << "output_update" << endl;
|
|
|
|
if (_external_ui_ptr) {
|
|
|
|
LV2_EXTERNAL_UI_RUN(_external_ui_ptr);
|
2013-08-29 07:05:11 -04:00
|
|
|
if (_lv2->is_external_kx() && !_external_ui_ptr) {
|
|
|
|
// clean up external UI if it closes itself via
|
|
|
|
// on_external_ui_closed() during run()
|
|
|
|
//printf("LV2PluginUI::output_update -- UI was closed\n");
|
2013-09-02 10:57:46 -04:00
|
|
|
//_screen_update_connection.disconnect();
|
2013-08-29 07:05:11 -04:00
|
|
|
_message_update_connection.disconnect();
|
|
|
|
if (_inst) {
|
|
|
|
suil_instance_free((SuilInstance*)_inst);
|
|
|
|
}
|
|
|
|
_inst = NULL;
|
|
|
|
_external_ui_ptr = NULL;
|
|
|
|
return;
|
|
|
|
}
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
|
|
|
|
2015-10-20 11:28:53 -04:00
|
|
|
if (!_inst) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-20 11:31:18 -04:00
|
|
|
|
2015-10-20 11:28:53 -04:00
|
|
|
/* output ports (values set by DSP) need propagating to GUI */
|
|
|
|
|
|
|
|
uint32_t nports = _output_ports.size();
|
|
|
|
for (uint32_t i = 0; i < nports; ++i) {
|
|
|
|
uint32_t index = _output_ports[i];
|
2015-10-20 11:39:56 -04:00
|
|
|
float val = _lv2->get_parameter (index);
|
|
|
|
|
2015-10-21 08:10:25 -04:00
|
|
|
if (val != _values_last_sent_to_ui[index]) {
|
2015-10-20 11:39:56 -04:00
|
|
|
/* Send to GUI */
|
|
|
|
suil_instance_port_event ((SuilInstance*)_inst, index, 4, 0, &val);
|
|
|
|
/* Cache current value */
|
2015-10-21 08:10:25 -04:00
|
|
|
_values_last_sent_to_ui[index] = val;
|
2015-10-20 11:39:56 -04:00
|
|
|
}
|
2008-11-14 17:14:15 -05:00
|
|
|
}
|
2015-10-20 11:28:53 -04:00
|
|
|
|
2015-10-20 11:31:18 -04:00
|
|
|
/* Input ports marked for update because the control value changed
|
|
|
|
since the last redisplay.
|
|
|
|
*/
|
|
|
|
|
2015-10-20 11:28:53 -04:00
|
|
|
for (Updates::iterator i = _updates.begin(); i != _updates.end(); ++i) {
|
|
|
|
float val = _lv2->get_parameter (*i);
|
|
|
|
/* push current value to the GUI */
|
|
|
|
suil_instance_port_event ((SuilInstance*)_inst, (*i), 4, 0, &val);
|
2015-10-21 08:10:25 -04:00
|
|
|
_values_last_sent_to_ui[(*i)] = val;
|
2015-10-20 11:28:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_updates.clear ();
|
2008-11-14 17:14:15 -05:00
|
|
|
}
|
|
|
|
|
2011-03-06 15:23:15 -05:00
|
|
|
LV2PluginUI::LV2PluginUI(boost::shared_ptr<PluginInsert> pi,
|
|
|
|
boost::shared_ptr<LV2Plugin> lv2p)
|
|
|
|
: PlugUIBase(pi)
|
2012-08-28 11:42:42 -04:00
|
|
|
, _pi(pi)
|
2008-09-10 17:27:39 -04:00
|
|
|
, _lv2(lv2p)
|
2011-05-30 22:00:16 -04:00
|
|
|
, _gui_widget(NULL)
|
2015-10-21 08:10:25 -04:00
|
|
|
, _values_last_sent_to_ui(NULL)
|
2009-10-01 12:28:02 -04:00
|
|
|
, _external_ui_ptr(NULL)
|
2011-04-22 04:08:37 -04:00
|
|
|
, _inst(NULL)
|
2009-10-01 12:28:02 -04:00
|
|
|
{
|
2013-08-03 07:45:27 -04:00
|
|
|
_ardour_buttons_box.set_spacing (6);
|
|
|
|
_ardour_buttons_box.set_border_width (6);
|
|
|
|
_ardour_buttons_box.pack_end (focus_button, false, false);
|
2015-05-04 14:52:48 -04:00
|
|
|
_ardour_buttons_box.pack_end (bypass_button, false, false, 4);
|
2017-09-08 14:54:19 -04:00
|
|
|
if (pi->controls().size() > 0) {
|
|
|
|
_ardour_buttons_box.pack_end (reset_button, false, false, 4);
|
|
|
|
}
|
2019-10-10 18:13:07 -04:00
|
|
|
if (has_descriptive_presets ()) {
|
|
|
|
_ardour_buttons_box.pack_end (preset_browser_button, false, false);
|
|
|
|
}
|
2013-08-03 07:45:27 -04:00
|
|
|
_ardour_buttons_box.pack_end (delete_button, false, false);
|
|
|
|
_ardour_buttons_box.pack_end (save_button, false, false);
|
|
|
|
_ardour_buttons_box.pack_end (add_button, false, false);
|
|
|
|
_ardour_buttons_box.pack_end (_preset_combo, false, false);
|
|
|
|
_ardour_buttons_box.pack_end (_preset_modified, false, false);
|
2016-08-04 20:35:51 -04:00
|
|
|
_ardour_buttons_box.pack_end (pin_management_button, false, false);
|
2020-03-14 01:39:20 -04:00
|
|
|
_ardour_buttons_box.pack_start (latency_button, false, false, 4);
|
2015-10-27 23:06:14 -04:00
|
|
|
|
|
|
|
plugin->PresetLoaded.connect (*this, invalidator (*this), boost::bind (&LV2PluginUI::queue_port_update, this), gui_context ());
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-09-14 12:51:02 -04:00
|
|
|
LV2PluginUI::lv2ui_instantiate(const std::string& title)
|
2008-09-10 17:27:39 -04:00
|
|
|
{
|
2012-08-21 15:29:19 -04:00
|
|
|
bool is_external_ui = _lv2->is_external_ui();
|
|
|
|
LV2_Feature** features_src = const_cast<LV2_Feature**>(_lv2->features());
|
|
|
|
LV2_Feature** features = const_cast<LV2_Feature**>(_lv2->features());
|
|
|
|
size_t features_count = 0;
|
|
|
|
while (*features++) {
|
2018-11-20 20:26:33 -05:00
|
|
|
++features_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_external_ui) {
|
|
|
|
features = (LV2_Feature**)malloc(sizeof(LV2_Feature*) * (features_count + 4));
|
|
|
|
} else {
|
|
|
|
features = (LV2_Feature**)malloc(sizeof(LV2_Feature*) * (features_count + 3));
|
2012-08-21 15:29:19 -04:00
|
|
|
}
|
2009-10-01 12:28:02 -04:00
|
|
|
|
2018-11-20 20:26:33 -05:00
|
|
|
size_t fi = 0;
|
|
|
|
for (; fi < features_count; ++fi) {
|
|
|
|
features[fi] = features_src[fi];
|
|
|
|
}
|
|
|
|
|
2020-02-16 16:32:47 -05:00
|
|
|
#ifdef HAVE_LV2_1_17_2
|
|
|
|
_lv2ui_request_value.handle = this;
|
|
|
|
_lv2ui_request_value.request = LV2PluginUI::request_value;
|
|
|
|
_lv2ui_request_feature.URI = LV2_UI__requestValue;
|
|
|
|
_lv2ui_request_feature.data = &_lv2ui_request_value;
|
2018-11-20 20:26:33 -05:00
|
|
|
|
|
|
|
features[fi++] = &_lv2ui_request_feature;
|
2020-02-15 08:15:29 -05:00
|
|
|
#endif
|
2018-11-20 20:26:33 -05:00
|
|
|
|
2012-08-21 15:29:19 -04:00
|
|
|
Gtk::Alignment* container = NULL;
|
2009-10-01 12:28:02 -04:00
|
|
|
if (is_external_ui) {
|
2011-03-06 15:23:15 -05:00
|
|
|
_external_ui_host.ui_closed = LV2PluginUI::on_external_ui_closed;
|
2009-10-01 12:28:02 -04:00
|
|
|
_external_ui_host.plugin_human_id = strdup(title.c_str());
|
|
|
|
|
2011-03-06 15:23:15 -05:00
|
|
|
_external_ui_feature.URI = LV2_EXTERNAL_UI_URI;
|
2009-10-01 12:28:02 -04:00
|
|
|
_external_ui_feature.data = &_external_ui_host;
|
|
|
|
|
2013-08-25 10:20:27 -04:00
|
|
|
_external_kxui_feature.URI = LV2_EXTERNAL_UI_KX__Host;
|
|
|
|
_external_kxui_feature.data = &_external_ui_host;
|
|
|
|
|
2018-11-20 20:26:33 -05:00
|
|
|
features[fi++] = &_external_kxui_feature;
|
|
|
|
features[fi++] = &_external_ui_feature;
|
2009-10-01 12:28:02 -04:00
|
|
|
} else {
|
2013-08-03 07:45:27 -04:00
|
|
|
if (_ardour_buttons_box.get_parent()) {
|
|
|
|
_ardour_buttons_box.get_parent()->remove(_ardour_buttons_box);
|
|
|
|
}
|
|
|
|
pack_start(_ardour_buttons_box, false, false);
|
|
|
|
_ardour_buttons_box.show_all();
|
2012-08-21 15:29:19 -04:00
|
|
|
|
|
|
|
_gui_widget = Gtk::manage((container = new Gtk::Alignment()));
|
|
|
|
pack_start(*_gui_widget, true, true);
|
|
|
|
_gui_widget->show();
|
|
|
|
|
|
|
|
_parent_feature.URI = LV2_UI__parent;
|
|
|
|
_parent_feature.data = _gui_widget->gobj();
|
|
|
|
|
2018-11-20 20:26:33 -05:00
|
|
|
features[fi++] = &_parent_feature;
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
|
|
|
|
2018-11-20 20:26:33 -05:00
|
|
|
features[fi] = NULL;
|
2020-02-16 16:32:47 -05:00
|
|
|
#ifdef HAVE_LV2_1_17_2
|
|
|
|
assert (fi == features_count + (is_external_ui ? 3 : 1));
|
|
|
|
#else
|
2020-02-15 08:15:29 -05:00
|
|
|
assert (fi == features_count + (is_external_ui ? 2 : 1));
|
2020-02-16 16:32:47 -05:00
|
|
|
#endif
|
2018-11-20 20:26:33 -05:00
|
|
|
|
2011-05-14 17:05:26 -04:00
|
|
|
if (!ui_host) {
|
2012-04-11 00:53:47 -04:00
|
|
|
ui_host = suil_host_new(LV2PluginUI::write_from_ui,
|
|
|
|
LV2PluginUI::port_index,
|
|
|
|
NULL, NULL);
|
|
|
|
suil_host_set_touch_func(ui_host, LV2PluginUI::touch);
|
2011-03-08 15:14:45 -05:00
|
|
|
}
|
2011-05-14 15:55:46 -04:00
|
|
|
const char* container_type = (is_external_ui)
|
|
|
|
? NS_UI "external"
|
|
|
|
: NS_UI "GtkUI";
|
|
|
|
|
2013-08-29 07:05:11 -04:00
|
|
|
if (_lv2->has_message_output()) {
|
2014-10-31 03:29:26 -04:00
|
|
|
_lv2->enable_ui_emission();
|
2013-08-29 07:05:11 -04:00
|
|
|
}
|
|
|
|
|
2015-02-13 21:59:11 -05:00
|
|
|
const LilvUI* ui = (const LilvUI*)_lv2->c_ui();
|
|
|
|
const LilvNode* bundle = lilv_ui_get_bundle_uri(ui);
|
|
|
|
const LilvNode* binary = lilv_ui_get_binary_uri(ui);
|
|
|
|
char* ui_bundle_path = lilv_file_uri_parse(lilv_node_as_uri(bundle), NULL);
|
|
|
|
char* ui_binary_path = lilv_file_uri_parse(lilv_node_as_uri(binary), NULL);
|
|
|
|
if (!ui_bundle_path || !ui_binary_path) {
|
|
|
|
error << _("failed to get path for UI bindle or binary") << endmsg;
|
2015-02-19 14:39:26 -05:00
|
|
|
free(ui_bundle_path);
|
|
|
|
free(ui_binary_path);
|
|
|
|
free(features);
|
2015-02-13 21:59:11 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-22 04:08:37 -04:00
|
|
|
_inst = suil_instance_new(
|
2011-05-14 17:05:26 -04:00
|
|
|
ui_host,
|
2011-04-22 04:08:37 -04:00
|
|
|
this,
|
2011-05-14 15:55:46 -04:00
|
|
|
container_type,
|
2011-05-15 19:10:13 -04:00
|
|
|
_lv2->uri(),
|
|
|
|
lilv_node_as_uri(lilv_ui_get_uri(ui)),
|
|
|
|
lilv_node_as_uri((const LilvNode*)_lv2->c_ui_type()),
|
2015-02-13 21:59:11 -05:00
|
|
|
ui_bundle_path,
|
|
|
|
ui_binary_path,
|
2012-08-21 15:29:19 -04:00
|
|
|
features);
|
2009-10-01 12:28:02 -04:00
|
|
|
|
2015-02-13 21:59:11 -05:00
|
|
|
free(ui_bundle_path);
|
|
|
|
free(ui_binary_path);
|
2012-08-21 15:29:19 -04:00
|
|
|
free(features);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2015-09-06 13:32:13 -04:00
|
|
|
if (!_inst) {
|
|
|
|
error << _("failed to instantiate LV2 GUI") << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-14 17:05:26 -04:00
|
|
|
#define GET_WIDGET(inst) suil_instance_get_widget((SuilInstance*)inst);
|
2011-04-22 04:08:37 -04:00
|
|
|
|
2011-05-14 17:05:26 -04:00
|
|
|
const uint32_t num_ports = _lv2->num_ports();
|
2008-11-14 17:14:15 -05:00
|
|
|
for (uint32_t i = 0; i < num_ports; ++i) {
|
2011-03-06 15:23:15 -05:00
|
|
|
if (_lv2->parameter_is_output(i)
|
|
|
|
&& _lv2->parameter_is_control(i)
|
|
|
|
&& is_update_wanted(i)) {
|
2008-11-14 17:14:15 -05:00
|
|
|
_output_ports.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
2009-10-01 12:28:02 -04:00
|
|
|
|
|
|
|
_external_ui_ptr = NULL;
|
2015-09-06 13:32:13 -04:00
|
|
|
if (!is_external_ui) {
|
|
|
|
GtkWidget* c_widget = (GtkWidget*)GET_WIDGET(_inst);
|
|
|
|
if (!c_widget) {
|
|
|
|
error << _("failed to get LV2 UI widget") << endmsg;
|
|
|
|
suil_instance_free((SuilInstance*)_inst);
|
|
|
|
_inst = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!container->get_child()) {
|
|
|
|
// Suil didn't add the UI to the container for us, so do it now
|
|
|
|
container->add(*Gtk::manage(Glib::wrap(c_widget)));
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
2015-09-06 13:32:13 -04:00
|
|
|
container->show_all();
|
|
|
|
gtk_widget_set_can_focus(c_widget, true);
|
|
|
|
gtk_widget_grab_focus(c_widget);
|
|
|
|
} else {
|
|
|
|
_external_ui_ptr = (struct lv2_external_ui*)GET_WIDGET(_inst);
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2015-10-21 08:10:25 -04:00
|
|
|
_values_last_sent_to_ui = new float[num_ports];
|
2011-03-06 15:23:15 -05:00
|
|
|
_controllables.resize(num_ports);
|
2015-10-20 11:39:56 -04:00
|
|
|
|
2008-09-10 17:27:39 -04:00
|
|
|
for (uint32_t i = 0; i < num_ports; ++i) {
|
2011-03-06 15:23:15 -05:00
|
|
|
bool ok;
|
2009-10-01 12:28:02 -04:00
|
|
|
uint32_t port = _lv2->nth_parameter(i, ok);
|
2009-01-14 10:47:58 -05:00
|
|
|
if (ok) {
|
2015-10-20 11:39:56 -04:00
|
|
|
/* Cache initial value of the parameter, regardless of
|
|
|
|
whether it is input or output
|
|
|
|
*/
|
|
|
|
|
2015-10-21 08:10:25 -04:00
|
|
|
_values_last_sent_to_ui[port] = _lv2->get_parameter(port);
|
2011-03-04 18:14:16 -05:00
|
|
|
_controllables[port] = boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (
|
2011-03-06 15:23:15 -05:00
|
|
|
insert->control(Evoral::Parameter(PluginAutomation, 0, port)));
|
|
|
|
|
2015-10-20 11:28:53 -04:00
|
|
|
if (_lv2->parameter_is_control(port) && _lv2->parameter_is_input(port)) {
|
|
|
|
if (_controllables[port]) {
|
|
|
|
_controllables[port]->Changed.connect (control_connections, invalidator (*this), boost::bind (&LV2PluginUI::control_changed, this, port), gui_context());
|
|
|
|
}
|
2009-01-14 10:47:58 -05:00
|
|
|
}
|
2015-10-20 11:39:56 -04:00
|
|
|
|
|
|
|
/* queue for first update ("push") to GUI */
|
|
|
|
_updates.insert (port);
|
2009-01-14 10:47:58 -05:00
|
|
|
}
|
2008-09-10 17:27:39 -04:00
|
|
|
}
|
2012-02-25 03:43:23 -05:00
|
|
|
|
2012-02-25 15:43:14 -05:00
|
|
|
if (_lv2->has_message_output()) {
|
2014-12-25 10:02:00 -05:00
|
|
|
_message_update_connection = Timers::super_rapid_connect (
|
2012-02-25 15:43:14 -05:00
|
|
|
sigc::mem_fun(*this, &LV2PluginUI::update_timeout));
|
|
|
|
}
|
2008-09-10 17:27:39 -04:00
|
|
|
}
|
|
|
|
|
2015-02-20 21:16:04 -05:00
|
|
|
void
|
|
|
|
LV2PluginUI::grab_focus()
|
|
|
|
{
|
|
|
|
if (_inst && !_lv2->is_external_ui()) {
|
|
|
|
GtkWidget* c_widget = (GtkWidget*)GET_WIDGET(_inst);
|
|
|
|
gtk_widget_grab_focus(c_widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-30 22:00:16 -04:00
|
|
|
void
|
|
|
|
LV2PluginUI::lv2ui_free()
|
2008-09-10 17:27:39 -04:00
|
|
|
{
|
2011-06-13 20:20:31 -04:00
|
|
|
stop_updating (0);
|
2011-06-13 17:00:53 -04:00
|
|
|
|
|
|
|
if (_gui_widget) {
|
|
|
|
remove (*_gui_widget);
|
2012-04-23 15:54:31 -04:00
|
|
|
_gui_widget = NULL;
|
2011-06-13 17:00:53 -04:00
|
|
|
}
|
2011-05-30 22:00:16 -04:00
|
|
|
|
2012-04-23 15:54:31 -04:00
|
|
|
if (_inst) {
|
|
|
|
suil_instance_free((SuilInstance*)_inst);
|
|
|
|
_inst = NULL;
|
|
|
|
}
|
2011-05-30 22:00:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
LV2PluginUI::~LV2PluginUI ()
|
|
|
|
{
|
2015-10-21 08:10:25 -04:00
|
|
|
delete [] _values_last_sent_to_ui;
|
2011-05-30 22:00:16 -04:00
|
|
|
|
2013-09-02 10:21:12 -04:00
|
|
|
_message_update_connection.disconnect();
|
|
|
|
_screen_update_connection.disconnect();
|
|
|
|
|
|
|
|
if (_external_ui_ptr && _lv2->is_external_kx()) {
|
|
|
|
LV2_EXTERNAL_UI_HIDE(_external_ui_ptr);
|
|
|
|
}
|
|
|
|
lv2ui_free();
|
|
|
|
_external_ui_ptr = NULL;
|
2008-09-10 17:27:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-03-06 15:23:15 -05:00
|
|
|
LV2PluginUI::get_preferred_height()
|
2008-09-10 17:27:39 -04:00
|
|
|
{
|
|
|
|
Gtk::Requisition r = size_request();
|
|
|
|
return r.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-03-06 15:23:15 -05:00
|
|
|
LV2PluginUI::get_preferred_width()
|
2008-09-10 17:27:39 -04:00
|
|
|
{
|
|
|
|
Gtk::Requisition r = size_request();
|
|
|
|
return r.width;
|
|
|
|
}
|
|
|
|
|
2012-03-25 13:17:40 -04:00
|
|
|
bool
|
|
|
|
LV2PluginUI::resizable()
|
|
|
|
{
|
|
|
|
return _lv2->ui_is_resizable();
|
|
|
|
}
|
|
|
|
|
2008-09-10 17:27:39 -04:00
|
|
|
int
|
2011-03-06 15:23:15 -05:00
|
|
|
LV2PluginUI::package(Gtk::Window& win)
|
2008-09-10 17:27:39 -04:00
|
|
|
{
|
2020-01-09 12:20:20 -05:00
|
|
|
if (!_external_ui_ptr) {
|
2009-10-01 12:28:02 -04:00
|
|
|
/* forward configure events to plugin window */
|
2011-03-06 15:23:15 -05:00
|
|
|
win.signal_configure_event().connect(
|
|
|
|
sigc::mem_fun(*this, &LV2PluginUI::configure_handler));
|
|
|
|
win.signal_map_event().connect(
|
|
|
|
sigc::mem_fun(*this, &LV2PluginUI::start_updating));
|
|
|
|
win.signal_unmap_event().connect(
|
|
|
|
sigc::mem_fun(*this, &LV2PluginUI::stop_updating));
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
2008-09-10 17:27:39 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-03-06 15:23:15 -05:00
|
|
|
LV2PluginUI::configure_handler(GdkEventConfigure*)
|
2008-09-10 17:27:39 -04:00
|
|
|
{
|
2009-05-12 15:10:31 -04:00
|
|
|
std::cout << "CONFIGURE" << std::endl;
|
2008-09-10 17:27:39 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-11-14 17:14:15 -05:00
|
|
|
bool
|
2009-07-21 11:55:17 -04:00
|
|
|
LV2PluginUI::is_update_wanted(uint32_t /*index*/)
|
2008-11-14 17:14:15 -05:00
|
|
|
{
|
2011-03-06 15:23:15 -05:00
|
|
|
/* FIXME: use port notification properties
|
|
|
|
and/or new UI extension subscription methods
|
|
|
|
*/
|
2008-11-14 17:14:15 -05:00
|
|
|
return true;
|
|
|
|
}
|
2009-10-01 12:28:02 -04:00
|
|
|
|
|
|
|
bool
|
2010-09-14 12:51:02 -04:00
|
|
|
LV2PluginUI::on_window_show(const std::string& title)
|
2009-10-01 12:28:02 -04:00
|
|
|
{
|
|
|
|
//cout << "on_window_show - " << title << endl; flush(cout);
|
|
|
|
|
|
|
|
if (_lv2->is_external_ui()) {
|
|
|
|
if (_external_ui_ptr) {
|
2013-08-29 07:05:11 -04:00
|
|
|
_screen_update_connection.disconnect();
|
|
|
|
_message_update_connection.disconnect();
|
2009-10-01 12:28:02 -04:00
|
|
|
LV2_EXTERNAL_UI_SHOW(_external_ui_ptr);
|
2014-12-25 10:02:00 -05:00
|
|
|
_screen_update_connection = Timers::super_rapid_connect
|
2013-08-29 07:05:11 -04:00
|
|
|
(sigc::mem_fun(*this, &LV2PluginUI::output_update));
|
|
|
|
if (_lv2->has_message_output()) {
|
2014-12-25 10:02:00 -05:00
|
|
|
_message_update_connection = Timers::super_rapid_connect (
|
2013-08-29 07:05:11 -04:00
|
|
|
sigc::mem_fun(*this, &LV2PluginUI::update_timeout));
|
|
|
|
}
|
2009-10-01 12:28:02 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
lv2ui_instantiate(title);
|
|
|
|
if (!_external_ui_ptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_screen_update_connection.disconnect();
|
2013-08-29 07:05:11 -04:00
|
|
|
_message_update_connection.disconnect();
|
|
|
|
LV2_EXTERNAL_UI_SHOW(_external_ui_ptr);
|
2014-12-25 10:02:00 -05:00
|
|
|
_screen_update_connection = Timers::super_rapid_connect
|
2013-08-29 07:05:11 -04:00
|
|
|
(sigc::mem_fun(*this, &LV2PluginUI::output_update));
|
|
|
|
if (_lv2->has_message_output()) {
|
2014-12-25 10:02:00 -05:00
|
|
|
_message_update_connection = Timers::super_rapid_connect (
|
2013-08-29 07:05:11 -04:00
|
|
|
sigc::mem_fun(*this, &LV2PluginUI::update_timeout));
|
|
|
|
}
|
2009-10-01 12:28:02 -04:00
|
|
|
return false;
|
2011-05-30 22:00:16 -04:00
|
|
|
} else {
|
|
|
|
lv2ui_instantiate("gtk2gui");
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
|
|
|
|
2015-09-06 13:32:13 -04:00
|
|
|
return _inst ? true : false;
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LV2PluginUI::on_window_hide()
|
|
|
|
{
|
2013-08-29 07:05:11 -04:00
|
|
|
//printf("LV2PluginUI::on_window_hide\n");
|
2009-10-01 12:28:02 -04:00
|
|
|
|
2013-08-29 07:05:11 -04:00
|
|
|
if (_lv2->is_external_ui()) {
|
|
|
|
if (!_external_ui_ptr) { return; }
|
2013-09-02 10:57:46 -04:00
|
|
|
LV2_EXTERNAL_UI_HIDE(_external_ui_ptr);
|
2013-09-02 10:21:12 -04:00
|
|
|
if (!_lv2->is_external_kx()) { return ; }
|
2013-11-04 20:06:20 -05:00
|
|
|
_message_update_connection.disconnect();
|
2013-08-25 09:54:43 -04:00
|
|
|
_screen_update_connection.disconnect();
|
|
|
|
_external_ui_ptr = NULL;
|
|
|
|
suil_instance_free((SuilInstance*)_inst);
|
|
|
|
_inst = NULL;
|
2011-05-30 22:00:16 -04:00
|
|
|
} else {
|
|
|
|
lv2ui_free();
|
2009-10-01 12:28:02 -04:00
|
|
|
}
|
|
|
|
}
|