13
0
livetrax/gtk2_ardour/vst3_plugin_ui.cc
Robin Gareus 67b1481c12
VST3: work-around endless/recursive resize requests
Some plugins correct their own size when resized which can lead
to endlessly growing GUIs. In particular this issue exists
if Ardour's plugin-toolbar forces a plugin to grow in size to fill
the allocated space. While the plugin aims for fixed aspect-ratio.

This will need a proper solution involving VST's checkSizeConstraint,
however GTK+2 does not have an appropriate API...
2020-09-18 02:11:25 +02:00

161 lines
3.9 KiB
C++

/*
* Copyright (C) 2020 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.
*/
#include <glibmm/main.h>
#include "ardour/plugin_insert.h"
#include "ardour/vst3_plugin.h"
#include "gtkmm2ext/gui_thread.h"
#include "timers.h"
#include "vst3_plugin_ui.h"
using namespace ARDOUR;
using namespace Steinberg;
VST3PluginUI::VST3PluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VST3Plugin> vst3)
: PlugUIBase (pi)
, _pi (pi)
, _vst3 (vst3)
, _req_width (0)
, _req_height (0)
, _resize_in_progress (false)
{
_ardour_buttons_box.set_spacing (6);
_ardour_buttons_box.set_border_width (6);
add_common_widgets (&_ardour_buttons_box);
_vst3->OnResizeView.connect (_resize_connection, invalidator (*this), boost::bind (&VST3PluginUI::resize_callback, this, _1, _2), gui_context());
//pi->plugin()->PresetLoaded.connect (*this, invalidator (*this), boost::bind (&VST3PluginUI::queue_port_update, this), gui_context ());
pack_start (_ardour_buttons_box, false, false);
_ardour_buttons_box.show_all ();
}
VST3PluginUI::~VST3PluginUI ()
{
_vst3->close_view ();
}
gint
VST3PluginUI::get_preferred_height ()
{
IPlugView* view = _vst3->view ();
ViewRect rect;
if (view && view->getSize (&rect) == kResultOk){
return rect.bottom - rect.top;
}
return 0;
}
gint
VST3PluginUI::get_preferred_width ()
{
IPlugView* view = _vst3->view ();
ViewRect rect;
if (view && view->getSize (&rect) == kResultOk){
return rect.right - rect.left;
}
return 0;
}
bool
VST3PluginUI::resizable ()
{
IPlugView* view = _vst3->view ();
return view && view->canResize () == kResultTrue;
}
bool
VST3PluginUI::non_gtk_gui() const
{
// return true to enable forward_key_event
return false;
}
int
VST3PluginUI::package (Gtk::Window& win)
{
win.signal_map_event().connect (sigc::mem_fun(*this, &VST3PluginUI::start_updating));
win.signal_unmap_event().connect (sigc::mem_fun(*this, &VST3PluginUI::stop_updating));
return 0;
}
bool
VST3PluginUI::start_updating (GdkEventAny*)
{
_update_connection.disconnect();
_update_connection = Timers::super_rapid_connect (sigc::mem_fun(*this, &VST3PluginUI::parameter_update));
return false;
}
bool
VST3PluginUI::stop_updating (GdkEventAny*)
{
_update_connection.disconnect();
return false;
}
void
VST3PluginUI::parameter_update ()
{
// XXX replicated plugins, too ?!
_vst3->update_contoller_param ();
}
void
VST3PluginUI::forward_key_event (GdkEventKey* ev)
{
#if 0
IPlugView* view = _vst3->view ();
switch (gdk_key->type) {
case GDK_KEY_PRESS:
/* key: unicode code of key
* keyCode: virtual keycode for non ascii keys - see VirtualKeyCodes in keycodes.h
* modifiers : any combination of modifiers - see KeyModifier in keycodes.h
*/
view->onKeyDown (ev->keyval, ev->hardware_keycode, ev->state);
break;
case GDK_KEY_RELEASE:
//view->onKeyUp (key, keyCode, modifiers);
break;
break;
default:
return;
}
#endif
}
bool
VST3PluginUI::forward_scroll_event (GdkEventScroll* ev)
{
IPlugView* view = _vst3->view ();
switch (ev->direction) {
case GDK_SCROLL_UP:
case GDK_SCROLL_LEFT:
return view->onWheel (-1) == kResultTrue;
break;
case GDK_SCROLL_DOWN:
case GDK_SCROLL_RIGHT:
return view->onWheel (-1) == kResultTrue;
break;
}
return false;
}