VST3: Plugin GUI support

This commit is contained in:
Robin Gareus
2020-08-10 01:25:10 +02:00
parent 6b4dc3268f
commit 1759ba96b6
11 changed files with 1150 additions and 1 deletions

View File

@@ -66,6 +66,14 @@
#endif
#ifdef VST3_SUPPORT
#include "ardour/vst3_plugin.h"
# ifdef PLATFORM_WINDOWS
# include "vst3_hwnd_plugin_ui.h"
# elif defined (__APPLE__)
# include "vst3_plugin_ui.h"
extern VST3PluginUI* create_mac_vst3_gui (boost::shared_ptr<ARDOUR::PluginInsert>, Gtk::VBox**);
# else
# include "vst3_x11_plugin_ui.h"
# endif
#endif
#include "ardour_window.h"
@@ -138,7 +146,7 @@ PluginUIWindow::PluginUIWindow (
break;
case ARDOUR::VST3:
have_gui = false; // TODO
have_gui = create_vst3_editor (insert);
break;
default:
@@ -323,6 +331,41 @@ PluginUIWindow::create_mac_vst_editor (boost::shared_ptr<PluginInsert>)
#endif
}
bool
#ifdef VST3_SUPPORT
PluginUIWindow::create_vst3_editor (boost::shared_ptr<PluginInsert> insert)
#else
PluginUIWindow::create_vst3_editor (boost::shared_ptr<PluginInsert>)
#endif
{
#ifndef VST3_SUPPORT
return false;
#else
boost::shared_ptr<VST3Plugin> vst3;
if ((vst3 = boost::dynamic_pointer_cast<VST3Plugin> (insert->plugin())) == 0) {
error << _("create_vst3_editor called on non-VST3 plugin") << endmsg;
throw failed_constructor ();
} else {
#ifdef PLATFORM_WINDOWS
VST3HWNDPluginUI* pui = new VST3HWNDPluginUI (insert, vst3);
add (*pui);
#elif defined (__APPLE__)
VBox* box;
VST3PluginUI* pui = create_mac_vst3_gui (insert, &box);
add (*box);
Application::instance()->ActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
#else
VST3X11PluginUI* pui = new VST3X11PluginUI (insert, vst3);
add (*pui);
#endif
_pluginui = pui;
pui->package (*this);
_pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
}
return true;
#endif
}
bool
#ifdef AUDIOUNIT_SUPPORT

View File

@@ -383,6 +383,7 @@ private:
bool create_mac_vst_editor(boost::shared_ptr<ARDOUR::PluginInsert>);
bool create_audiounit_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
bool create_lv2_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
bool create_vst3_editor (boost::shared_ptr<ARDOUR::PluginInsert>);
};
#ifdef MACVST_SUPPORT

View File

@@ -0,0 +1,166 @@
/*
* 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.
*/
#ifdef WAF_BUILD
#include "gtk2ardour-config.h"
#endif
#include <glibmm/main.h>
#include "ardour/plugin_insert.h"
#include "ardour/vst3_plugin.h"
#include "gtkmm2ext/gui_thread.h"
#include "vst3_hwnd_plugin_ui.h"
#include <gdk/gdkwin32.h>
using namespace ARDOUR;
using namespace Steinberg;
VST3HWNDPluginUI::VST3HWNDPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VST3Plugin> vst3)
: VST3PluginUI (pi, vst3)
{
/* TODO register window class, implement wndproc etc */
pack_start (_gui_widget, true, true);
_gui_widget.signal_realize().connect (mem_fun (this, &VST3HWNDPluginUI::view_realized));
_gui_widget.signal_size_request ().connect (mem_fun (this, &VST3HWNDPluginUI::view_size_request));
_gui_widget.signal_size_allocate ().connect (mem_fun (this, &VST3HWNDPluginUI::view_size_allocate));
_gui_widget.signal_scroll_event ().connect (sigc::mem_fun (*this, &VST3HWNDPluginUI::forward_scroll_event), false);
_gui_widget.show ();
}
VST3HWNDPluginUI::~VST3HWNDPluginUI ()
{
}
void
VST3HWNDPluginUI::view_realized ()
{
IPlugView* view = _vst3->view ();
HWND hwnd = (HWND) gdk_win32_drawable_get_handle (GTK_WIDGET(_gui_widget.gobj())->window);
// SetWindowLongPtr (hwnd, GWLP_USERDATA, (__int3264) (LONG_PTR)this);
if (kResultOk != view->attached (reinterpret_cast<void*> (hwnd), "HWND")) {
assert (0);
}
ViewRect rect;
if (view->getSize (&rect) == kResultOk) {
_req_width = rect.right - rect.left;
_req_height = rect.bottom - rect.top;
}
}
void
VST3HWNDPluginUI::view_size_request (GtkRequisition* requisition)
{
requisition->width = _req_width;
requisition->height = _req_height;
}
void
VST3HWNDPluginUI::view_size_allocate (Gtk::Allocation& allocation)
{
IPlugView* view = _vst3->view ();
if (!view) {
return;
}
ViewRect rect;
if (view->getSize (&rect) == kResultOk) {
rect.right = rect.left + allocation.get_width ();
rect.bottom = rect.top + allocation.get_height ();
#if 0
if (view->checkSizeConstraint (&rect) != kResultTrue) {
view->getSize (&rect);
}
allocation.set_width (rect.right - rect.left);
allocation.set_height (rect.bottom - rect.top);
#endif
if (view->canResize() == kResultTrue) {
view->onSize (&rect);
}
}
}
void
VST3HWNDPluginUI::resize_callback (int width, int height)
{
//printf ("VST3HWNDPluginUI::resize_callback %d x %d\n", width, height);
#if 0
HWND hwnd = gdk_win32_drawable_get_handle (_gui_widget.window);
WINDOWINFO windowInfo;
GetWindowInfo (hwnd, &windowInfo);
RECT clientRect {};
clientRect.right = newSize.width;
clientRect.bottom = newSize.height;
AdjustWindowRectEx (&clientRect, windowInfo.dwStyle, false, windowInfo.dwExStyle);
SetWindowPos (hwnd, HWND_TOP, 0, 0, clientRect.right - clientRect.left,
clientRect.bottom - clientRect.top, SWP_NOMOVE | SWP_NOCOPYBITS | SWP_NOACTIVATE);
#else
IPlugView* view = _vst3->view ();
if (view->canResize() == kResultTrue) {
gint xx, yy;
if (gtk_widget_translate_coordinates (
GTK_WIDGET(_gui_widget.gobj()),
GTK_WIDGET(get_toplevel()->gobj()),
0, 0, &xx, &yy))
{
get_window()->resize (width + xx, height + yy);
}
} else {
_req_width = width;
_req_height = height;
_gui_widget.queue_resize ();
}
#endif
}
bool
VST3HWNDPluginUI::on_window_show (const std::string& /*title*/)
{
IPlugView* view = _vst3->view ();
if (!view) {
return false;
}
gtk_widget_realize (GTK_WIDGET(_gui_widget.gobj()));
_gui_widget.show ();
return true;
}
void
VST3HWNDPluginUI::on_window_hide ()
{
_gui_widget.hide ();
}
void
VST3HWNDPluginUI::grab_focus ()
{
#if 0
IPlugView* view = _vst3->view ();
if (view) {
view->onFocus (true);
}
#endif
}

View File

@@ -0,0 +1,49 @@
/*
* 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.
*/
#ifndef __ardour_vst3_hwnd_plugin_ui_h__
#define __ardour_vst3_hwnd_plugin_ui_h__
#ifdef VST3_SUPPORT
#include <gtkmm/widget.h>
#include <gtkmm/eventbox.h>
#include "vst3_plugin_ui.h"
class VST3HWNDPluginUI : public VST3PluginUI
{
public:
VST3HWNDPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VST3Plugin>);
~VST3HWNDPluginUI ();
bool on_window_show(const std::string&);
void on_window_hide ();
void grab_focus();
private:
void view_realized ();
void view_size_request (GtkRequisition*);
void view_size_allocate (Gtk::Allocation&);
void resize_callback (int, int);
Gtk::EventBox _gui_widget;
};
#endif // VST3_SUPPORT
#endif

View File

@@ -0,0 +1,72 @@
/*
* 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.
*/
#ifndef __ardour_vst3_nsview_plugin_ui_h__
#define __ardour_vst3_nsview_plugin_ui_h__
#ifdef VST3_SUPPORT
#include <AppKit/AppKit.h>
/* fix up stupid apple macros */
#undef check
#undef require
#undef verify
#ifdef YES
#undef YES
#endif
#ifdef NO
#undef NO
#endif
#include <gtkmm/widget.h>
#include <gtkmm/eventbox.h>
#include "vst3_plugin_ui.h"
class VST3NSViewPluginUI : public VST3PluginUI
{
public:
VST3NSViewPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VST3Plugin>);
~VST3NSViewPluginUI ();
bool on_window_show(const std::string&);
void on_window_hide ();
void grab_focus();
private:
void view_realized ();
void view_size_request (GtkRequisition*);
void view_size_allocate (Gtk::Allocation&);
void resize_callback (int, int);
bool view_visibility_notify (GdkEventVisibility*);
void view_map ();
void view_unmap ();
NSWindow* get_nswindow();
Gtk::EventBox _gui_widget;
NSView* _ns_view;
};
#endif // VST3_SUPPORT
#endif

View File

@@ -0,0 +1,240 @@
/*
* 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.
*/
#ifdef WAF_BUILD
#include "gtk2ardour-config.h"
#endif
#include <gtkmm.h>
#include <gtk/gtk.h>
#include <gdk/gdkquartz.h>
#include "pbd/convert.h"
#include "pbd/error.h"
#include "ardour/plugin_insert.h"
#include "ardour/vst3_plugin.h"
#include "gtkmm2ext/gui_thread.h"
#include "gui_thread.h"
#include "vst3_nsview_plugin_ui.h"
#include "pbd/i18n.h"
using namespace PBD;
using namespace ARDOUR;
using namespace Steinberg;
VST3PluginUI*
create_mac_vst3_gui (boost::shared_ptr<PluginInsert> plugin_insert, Gtk::VBox** box)
{
VST3NSViewPluginUI* v = new VST3NSViewPluginUI (plugin_insert, boost::dynamic_pointer_cast<VST3Plugin> (plugin_insert->plugin()));
*box = v;
return v;
}
VST3NSViewPluginUI::VST3NSViewPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VST3Plugin> vst3)
: VST3PluginUI (pi, vst3)
{
pack_start (_gui_widget, true, true);
_gui_widget.add_events (Gdk::VISIBILITY_NOTIFY_MASK | Gdk::EXPOSURE_MASK);
_gui_widget.signal_realize().connect (mem_fun (this, &VST3NSViewPluginUI::view_realized));
_gui_widget.signal_visibility_notify_event ().connect (mem_fun (this, &VST3NSViewPluginUI::view_visibility_notify));
_gui_widget.signal_size_request ().connect (mem_fun (this, &VST3NSViewPluginUI::view_size_request));
_gui_widget.signal_size_allocate ().connect (mem_fun (this, &VST3NSViewPluginUI::view_size_allocate));
_gui_widget.signal_map ().connect (mem_fun (this, &VST3NSViewPluginUI::view_map));
_gui_widget.signal_unmap ().connect (mem_fun (this, &VST3NSViewPluginUI::view_unmap));
_gui_widget.signal_scroll_event ().connect (sigc::mem_fun (*this, &VST3NSViewPluginUI::forward_scroll_event), false);
//vst->LoadPresetProgram.connect (_program_connection, invalidator (*this), boost::bind (&VST3NSViewPluginUI::set_program, this), gui_context());
_ns_view = [[NSView new] retain];
IPlugView* view = _vst3->view ();
if (!view) {
printf ("FAILED TO get view.\n");
return;
}
if (kResultOk != view->attached (reinterpret_cast<void*> (_ns_view), "NSView")) {
printf ("FAILED TO ATTACH..\n");
}
ViewRect rect;
if (view->getSize (&rect) == kResultOk) {
_req_width = rect.right - rect.left;
_req_height = rect.bottom - rect.top;
}
_gui_widget.show ();
}
VST3NSViewPluginUI::~VST3NSViewPluginUI ()
{
[_ns_view removeFromSuperview];
[_ns_view release];
}
void
VST3NSViewPluginUI::view_size_request (GtkRequisition* requisition)
{
requisition->width = _req_width + 8;
requisition->height = _req_height + 6;
}
void
VST3NSViewPluginUI::view_size_allocate (Gtk::Allocation& allocation)
{
IPlugView* view = _vst3->view ();
if (!view) {
return;
}
gint xx = 0;
gint yy = 0;
gtk_widget_translate_coordinates(
GTK_WIDGET(_gui_widget.gobj()),
GTK_WIDGET(_gui_widget.get_parent()->gobj()),
0, 0, &xx, &yy);
ViewRect rect;
if (view->getSize (&rect) == kResultOk) {
rect.left = xx;
rect.top = yy;
rect.right = rect.left + allocation.get_width ();
rect.bottom = rect.top + allocation.get_height ();
#if 0
if (view->checkSizeConstraint (&rect) != kResultTrue) {
view->getSize (&rect);
}
allocation.set_width (rect.right - rect.left);
allocation.set_height (rect.bottom - rect.top);
#endif
if (view->canResize() == kResultTrue) {
view->onSize (&rect);
}
}
[_ns_view setFrame:NSMakeRect (xx, yy, allocation.get_width (), allocation.get_height ())];
NSArray* subviews = [_ns_view subviews];
for (unsigned long i = 0; i < [subviews count]; ++i) {
NSView* subview = [subviews objectAtIndex:i];
[subview setFrame:NSMakeRect (0, 0, allocation.get_width (), allocation.get_height ())];
}
}
void
VST3NSViewPluginUI::resize_callback (int width, int height)
{
//printf ("VST3NSViewPluginUI::resize_callback %d x %d\n", width, height);
IPlugView* view = _vst3->view ();
if (!view) {
return;
}
if (view->canResize() == kResultTrue) {
gint xx, yy;
if (gtk_widget_translate_coordinates (
GTK_WIDGET(_gui_widget.gobj()),
GTK_WIDGET(get_toplevel()->gobj()),
0, 0, &xx, &yy))
{
get_window()->resize (width + xx, height + yy);
}
} else {
_req_width = width;
_req_height = height;
_gui_widget.queue_resize ();
}
}
void
VST3NSViewPluginUI::view_realized ()
{
NSWindow* win = get_nswindow ();
if (!win) {
printf ("NO WINDOW!\n");
return;
}
[win setAutodisplay:1]; // turn off GTK stuff for this window
NSView* nsview = gdk_quartz_window_get_nsview (_gui_widget.get_window()->gobj());
[nsview addSubview:_ns_view];
_gui_widget.queue_resize ();
}
bool
VST3NSViewPluginUI::view_visibility_notify (GdkEventVisibility* ev)
{
return false;
}
void
VST3NSViewPluginUI::view_map ()
{
[_ns_view setHidden:0];
}
void
VST3NSViewPluginUI::view_unmap ()
{
[_ns_view setHidden:1];
}
bool
VST3NSViewPluginUI::on_window_show (const std::string& /*title*/)
{
gtk_widget_realize (GTK_WIDGET(_gui_widget.gobj()));
show_all ();
return true;
}
void
VST3NSViewPluginUI::on_window_hide ()
{
hide_all ();
}
void
VST3NSViewPluginUI::grab_focus ()
{
[_ns_view becomeFirstResponder];
}
NSWindow*
VST3NSViewPluginUI::get_nswindow ()
{
Gtk::Container* toplevel = get_toplevel();
if (!toplevel || !toplevel->is_toplevel()) {
error << _("VST3NSViewPluginUI: no top level window!") << endmsg;
return 0;
}
NSWindow* true_parent = gdk_quartz_window_get_nswindow (toplevel->get_window()->gobj());
if (!true_parent) {
error << _("VST3NSViewPluginUI: no top level window!") << endmsg;
return 0;
}
return true_parent;
}

View File

@@ -0,0 +1,159 @@
/*
* 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)
{
_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;
}

View File

@@ -0,0 +1,68 @@
/*
* 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.
*/
#ifndef __ardour_vst3_plugin_ui_h__
#define __ardour_vst3_plugin_ui_h__
#ifdef VST3_SUPPORT
#include "plugin_ui.h"
namespace ARDOUR {
class PluginInsert;
class VST3Plugin;
}
class VST3PluginUI : public PlugUIBase, public Gtk::VBox
{
public:
VST3PluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VST3Plugin>);
virtual ~VST3PluginUI ();
gint get_preferred_height ();
gint get_preferred_width ();
bool resizable ();
void forward_key_event (GdkEventKey*);
bool non_gtk_gui() const;
int package (Gtk::Window&);
bool start_updating (GdkEventAny*);
bool stop_updating (GdkEventAny*);
protected:
virtual void resize_callback (int, int) = 0;
bool forward_scroll_event (GdkEventScroll*);
boost::shared_ptr<ARDOUR::PluginInsert> _pi;
boost::shared_ptr<ARDOUR::VST3Plugin> _vst3;
Gtk::HBox _ardour_buttons_box;
int _req_width;
int _req_height;
private:
void parameter_update ();
PBD::ScopedConnection _resize_connection;
sigc::connection _update_connection;
};
#endif // VST3_SUPPORT
#endif

View File

@@ -0,0 +1,283 @@
/*
* 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.
*/
#ifdef WAF_BUILD
#include "gtk2ardour-config.h"
#endif
#include <boost/unordered_map.hpp>
#include <glibmm/main.h>
#include <gtkmm/socket.h>
#include "ardour/plugin_insert.h"
#include "ardour/vst3_plugin.h"
#include "gtkmm2ext/gui_thread.h"
#include "vst3_x11_plugin_ui.h"
#include <gdk/gdkx.h> /* must come later than glibmm/object.h */
using namespace ARDOUR;
using namespace Steinberg;
class VST3X11Runloop : public Linux::IRunLoop
{
private:
struct EventHandler
{
EventHandler (Linux::IEventHandler* handler = 0, GIOChannel* gio_channel = 0, guint source_id = 0)
: _handler (handler)
, _gio_channel (gio_channel)
, _source_id (source_id)
{}
bool operator== (EventHandler const& other) {
return other._handler == _handler && other._gio_channel == _gio_channel && other._source_id == _source_id;
}
Linux::IEventHandler* _handler;
GIOChannel* _gio_channel;
guint _source_id;
};
boost::unordered_map<FileDescriptor, EventHandler> _event_handlers;
boost::unordered_map<guint, Linux::ITimerHandler*> _timer_handlers;
static gboolean event (GIOChannel* source, GIOCondition condition, gpointer data)
{
Linux::IEventHandler* handler = reinterpret_cast<Linux::IEventHandler*> (data);
handler->onFDIsSet (g_io_channel_unix_get_fd (source));
if (condition & ~G_IO_IN) {
/* remove on error */
return false;
} else {
return true;
}
}
static gboolean timeout (gpointer data)
{
Linux::ITimerHandler* handler = reinterpret_cast<Linux::ITimerHandler*> (data);
handler->onTimer ();
return true;
}
public:
~VST3X11Runloop ()
{
for (boost::unordered_map<FileDescriptor, EventHandler>::iterator it = _event_handlers.begin (); it != _event_handlers.end (); ++it) {
g_source_remove (it->second._source_id);
g_io_channel_unref (it->second._gio_channel);
}
for (boost::unordered_map<guint, Linux::ITimerHandler*>::iterator it = _timer_handlers.begin (); it != _timer_handlers.end (); ++it) {
g_source_remove (it->first);
}
}
/* VST3 IRunLoop interface */
tresult registerEventHandler (Linux::IEventHandler* handler, FileDescriptor fd) SMTG_OVERRIDE
{
GIOChannel* gio_channel = g_io_channel_unix_new (fd);
guint id = g_io_add_watch (gio_channel, (GIOCondition) (G_IO_IN /*| G_IO_OUT*/ | G_IO_ERR | G_IO_HUP), event, handler);
_event_handlers[fd] = EventHandler (handler, gio_channel, id);
return kResultTrue;
}
tresult unregisterEventHandler (Linux::IEventHandler* handler) SMTG_OVERRIDE
{
if (!handler) {
return kInvalidArgument;
}
for (boost::unordered_map<FileDescriptor, EventHandler>::iterator it = _event_handlers.begin (); it != _event_handlers.end (); ++it) {
if (it->second._handler == handler) {
g_source_remove (it->second._source_id);
g_io_channel_unref (it->second._gio_channel);
_event_handlers.erase (it);
return kResultTrue;
}
}
return kResultFalse;
}
tresult registerTimer (Linux::ITimerHandler* handler, TimerInterval milliseconds) SMTG_OVERRIDE
{
if (!handler || milliseconds == 0) {
return kInvalidArgument;
}
guint id = g_timeout_add_full (G_PRIORITY_HIGH_IDLE, milliseconds, timeout, handler, NULL);
_timer_handlers[id] = handler;
return kResultTrue;
}
tresult unregisterTimer (Linux::ITimerHandler* handler) SMTG_OVERRIDE
{
if (!handler) {
return kInvalidArgument;
}
for (boost::unordered_map<guint, Linux::ITimerHandler*>::iterator it = _timer_handlers.begin (); it != _timer_handlers.end (); ++it) {
if (it->second == handler) {
g_source_remove (it->first);
_timer_handlers.erase (it);
return kResultTrue;
}
}
return kResultFalse;
}
uint32 PLUGIN_API addRef () SMTG_OVERRIDE { return 1; }
uint32 PLUGIN_API release () SMTG_OVERRIDE { return 1; }
tresult queryInterface (const TUID, void**) SMTG_OVERRIDE { return kNoInterface; }
};
VST3X11Runloop static_runloop;
VST3X11PluginUI::VST3X11PluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VST3Plugin> vst3)
: VST3PluginUI (pi, vst3)
//, _runloop (new VST3X11Runloop)
{
_vst3->set_runloop (&static_runloop);
pack_start (_gui_widget, true, true);
_gui_widget.signal_realize().connect (mem_fun (this, &VST3X11PluginUI::view_realized));
_gui_widget.signal_size_request ().connect (mem_fun (this, &VST3X11PluginUI::view_size_request));
_gui_widget.signal_size_allocate ().connect (mem_fun (this, &VST3X11PluginUI::view_size_allocate));
_gui_widget.signal_scroll_event ().connect (sigc::mem_fun (*this, &VST3X11PluginUI::forward_scroll_event), false);
#if 0
_gui_widget.add_events (Gdk::POINTER_MOTION_HINT_MASK | Gdk::SCROLL_MASK | Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK | Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK|Gdk::SCROLL_MASK);
#endif
_gui_widget.show ();
}
VST3X11PluginUI::~VST3X11PluginUI ()
{
}
void
VST3X11PluginUI::view_realized ()
{
IPlugView* view = _vst3->view ();
if (!view) {
return;
}
Window window = _gui_widget.get_id ();
if (kResultOk != view->attached (reinterpret_cast<void*> (window), "X11EmbedWindowID")) {
assert (0);
}
#if 0
_gui_widget.set_sensitive (true);
_gui_widget.set_can_focus (true);
_gui_widget.grab_focus ();
#endif
ViewRect rect;
if (view->getSize (&rect) == kResultOk) {
_req_width = rect.right - rect.left;
_req_height = rect.bottom - rect.top;
}
}
void
VST3X11PluginUI::view_size_request (GtkRequisition* requisition)
{
requisition->width = _req_width;
requisition->height = _req_height;
}
void
VST3X11PluginUI::view_size_allocate (Gtk::Allocation& allocation)
{
IPlugView* view = _vst3->view ();
if (!view) {
return;
}
ViewRect rect;
if (view->getSize (&rect) == kResultOk) {
rect.right = rect.left + allocation.get_width ();
rect.bottom = rect.top + allocation.get_height ();
#if 0
if (view->checkSizeConstraint (&rect) != kResultTrue) {
view->getSize (&rect);
}
allocation.set_width (rect.right - rect.left);
allocation.set_height (rect.bottom - rect.top);
#endif
if (view->canResize() == kResultTrue) {
view->onSize (&rect);
}
}
}
void
VST3X11PluginUI::resize_callback (int width, int height)
{
// printf ("VST3X11PluginUI::resize_callback %d x %d\n", width, height);
IPlugView* view = _vst3->view ();
if (!view) {
return;
}
if (view->canResize() == kResultTrue) {
gint xx, yy;
if (gtk_widget_translate_coordinates (
GTK_WIDGET(_gui_widget.gobj()),
GTK_WIDGET(get_toplevel()->gobj()),
0, 0, &xx, &yy))
{
get_window()->resize (width + xx, height + yy);
}
} else {
_req_width = width;
_req_height = height;
_gui_widget.queue_resize ();
}
}
bool
VST3X11PluginUI::on_window_show (const std::string& /*title*/)
{
IPlugView* view = _vst3->view ();
if (!view) {
return false;
}
gtk_widget_realize (GTK_WIDGET(_gui_widget.gobj()));
_gui_widget.show ();
return true;
}
void
VST3X11PluginUI::on_window_hide ()
{
_gui_widget.hide ();
}
void
VST3X11PluginUI::grab_focus ()
{
#if 1
IPlugView* view = _vst3->view ();
if (view) {
view->onFocus (true);
}
#endif
}

View File

@@ -0,0 +1,50 @@
/*
* 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.
*/
#ifndef __ardour_vst3_x11_plugin_ui_h__
#define __ardour_vst3_x11_plugin_ui_h__
#ifdef VST3_SUPPORT
#include <gtkmm/widget.h>
#include <gtkmm/socket.h>
#include "vst3_plugin_ui.h"
class VST3X11PluginUI : public VST3PluginUI
{
public:
VST3X11PluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VST3Plugin>);
~VST3X11PluginUI ();
bool on_window_show(const std::string&);
void on_window_hide ();
void grab_focus();
private:
void view_realized ();
void view_size_request (GtkRequisition*);
void view_size_allocate (Gtk::Allocation&);
void resize_callback (int, int);
Gtk::Socket _gui_widget;
};
#endif // VST3_SUPPORT
#endif

View File

@@ -536,6 +536,15 @@ def build(bld):
obj.defines += [ 'LXVST_SUPPORT' ]
obj.use += [ 'X11' ]
if bld.is_defined('VST3_SUPPORT'):
obj.source += [ 'vst3_plugin_ui.cc' ]
if sys.platform == 'darwin':
obj.source += [ 'vst3_nsview_plugin_ui.mm' ]
elif bld.env['build_target'] == 'mingw':
obj.source += [ 'vst3_hwnd_plugin_ui.cc' ]
else:
obj.source += [ 'vst3_x11_plugin_ui.cc' ]
# # Tool to test libcanvas
# if re.search ("linux", sys.platform) != None and bld.env['CANVASTESTUI']:
# obj = bld (features = 'cxx c cxxprogram')
@@ -704,6 +713,15 @@ def build(bld):
if bld.is_defined('AUDIOUNIT_SUPPORT'):
obj.source += [ 'au_pluginui.mm' ]
if bld.is_defined('VST3_SUPPORT'):
obj.source += [ 'vst3_plugin_ui.cc' ]
if sys.platform == 'darwin':
obj.source += [ 'vst3_nsview_plugin_ui.mm' ]
elif bld.env['build_target'] == 'mingw':
obj.source += [ 'vst3_hwnd_plugin_ui.cc' ]
else:
obj.source += [ 'vst3_x11_plugin_ui.cc' ]
# Wrappers
wrapper_subst_dict = {