From 598ff1cb9a8e7a4ebf7f375a48a0b33efd94a323 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 24 Mar 2024 18:54:32 +0100 Subject: [PATCH] Separate PluginWindowProxy into public class --- gtk2_ardour/io_plugin_window.cc | 110 +-------------------- gtk2_ardour/io_plugin_window.h | 37 +------ gtk2_ardour/plugin_window_proxy.cc | 154 +++++++++++++++++++++++++++++ gtk2_ardour/plugin_window_proxy.h | 72 ++++++++++++++ gtk2_ardour/wscript | 1 + 5 files changed, 231 insertions(+), 143 deletions(-) create mode 100644 gtk2_ardour/plugin_window_proxy.cc create mode 100644 gtk2_ardour/plugin_window_proxy.h diff --git a/gtk2_ardour/io_plugin_window.cc b/gtk2_ardour/io_plugin_window.cc index d94c386373..a435789216 100644 --- a/gtk2_ardour/io_plugin_window.cc +++ b/gtk2_ardour/io_plugin_window.cc @@ -42,6 +42,7 @@ #include "mixer_ui.h" #include "plugin_selector.h" #include "plugin_ui.h" +#include "plugin_window_proxy.h" #include "ui_config.h" #include "pbd/i18n.h" @@ -299,7 +300,7 @@ IOPluginWindow::IOPlugUI::IOPlugUI (std::shared_ptr iop) _window_proxy = dynamic_cast (iop->window_proxy ()); assert (_window_proxy); } else { - _window_proxy = new PluginWindowProxy (string_compose ("IOP-%1", _iop->id ()), _iop); + _window_proxy = new PluginWindowProxy (string_compose ("IOP-%1", _iop->id ()), "I/O", _iop); const XMLNode* ui_xml = _iop->session ().extra_xml (X_("UI")); if (ui_xml) { @@ -373,113 +374,6 @@ IOPluginWindow::IOPlugUI::button_resized (Gtk::Allocation& alloc) _btn_ioplug.set_layout_ellipsize_width (alloc.get_width () * PANGO_SCALE); } -/* ****************************************************************************/ - -IOPluginWindow::PluginWindowProxy::PluginWindowProxy (std::string const& name, std::weak_ptr plugin) - : WM::ProxyBase (name, std::string ()) - , _pib (plugin) - , _is_custom (true) - , _want_custom (true) -{ - std::shared_ptr p = _pib.lock (); - if (!p) { - return; - } - p->DropReferences.connect (_going_away_connection, MISSING_INVALIDATOR, boost::bind (&IOPluginWindow::PluginWindowProxy::plugin_going_away, this), gui_context ()); -} - -IOPluginWindow::PluginWindowProxy::~PluginWindowProxy () -{ - _window = 0; -} - -Gtk::Window* -IOPluginWindow::PluginWindowProxy::get (bool create) -{ - std::shared_ptr p = _pib.lock (); - if (!p) { - return 0; - } - - if (_window && (_is_custom != _want_custom)) { - set_state_mask (WindowProxy::StateMask (state_mask () & ~WindowProxy::Size)); - drop_window (); - } - - if (!_window) { - if (!create) { - return 0; - } - - _is_custom = _want_custom; - _window = new PluginUIWindow (p, false, _is_custom); - - if (_window) { - std::shared_ptr iop = std::dynamic_pointer_cast (p); - assert (iop); - _window->set_title (iop->name ()); - setup (); - _window->show_all (); - } - } - return _window; -} - -void -IOPluginWindow::PluginWindowProxy::show_the_right_window () -{ - if (_window && (_is_custom != _want_custom)) { - set_state_mask (WindowProxy::StateMask (state_mask () & ~WindowProxy::Size)); - drop_window (); - } - - if (_window) { - _window->unset_transient_for (); - } - toggle (); -} - -int -IOPluginWindow::PluginWindowProxy::set_state (const XMLNode& node, int) -{ - XMLNodeList children = node.children (); - XMLNodeList::const_iterator i = children.begin (); - while (i != children.end ()) { - std::string name; - if ((*i)->name () == X_("Window") && (*i)->get_property (X_("name"), name) && name == _name) { - break; - } - ++i; - } - - if (i != children.end ()) { - (*i)->get_property (X_("custom-ui"), _want_custom); - } - - return ProxyBase::set_state (node, 0); -} - -XMLNode& -IOPluginWindow::PluginWindowProxy::get_state () const -{ - XMLNode* node; - node = &ProxyBase::get_state (); - node->set_property (X_("custom-ui"), _is_custom); - return *node; -} - -void -IOPluginWindow::PluginWindowProxy::plugin_going_away () -{ - delete _window; - _window = 0; - WM::Manager::instance ().remove (this); - _going_away_connection.disconnect (); - delete this; -} - -/* ****************************************************************************/ - IOPluginWindow::IOButton::IOButton (std::shared_ptr io, bool pre) : _io (io) , _pre (pre) diff --git a/gtk2_ardour/io_plugin_window.h b/gtk2_ardour/io_plugin_window.h index 683357daec..1d3572689d 100644 --- a/gtk2_ardour/io_plugin_window.h +++ b/gtk2_ardour/io_plugin_window.h @@ -35,11 +35,11 @@ namespace ARDOUR { class IO; class IOPlug; - class PlugInsertBase; class Port; } class IOSelectorWindow; +class PluginWindowProxy; class IOPluginWindow : public ArdourWindow { @@ -48,39 +48,6 @@ public: void set_session (ARDOUR::Session*); - class PluginWindowProxy : public WM::ProxyBase - { - public: - PluginWindowProxy (std::string const&, std::weak_ptr); - ~PluginWindowProxy (); - Gtk::Window* get (bool create = false); - - void show_the_right_window (); - - ARDOUR::SessionHandlePtr* session_handle () - { - return 0; - } - - void set_custom_ui_mode (bool use_custom) - { - _want_custom = use_custom; - } - - int set_state (const XMLNode&, int); - XMLNode& get_state () const; - - private: - void plugin_going_away (); - - std::weak_ptr _pib; - - bool _is_custom; - bool _want_custom; - - PBD::ScopedConnection _going_away_connection; - }; - protected: void on_show (); void on_hide (); @@ -147,7 +114,7 @@ private: IOButton _btn_output; ArdourWidgets::ArdourButton _btn_ioplug; PluginWindowProxy* _window_proxy; - std::shared_ptr _iop; + std::shared_ptr _iop; PBD::ScopedConnection _going_away_connection; }; diff --git a/gtk2_ardour/plugin_window_proxy.cc b/gtk2_ardour/plugin_window_proxy.cc new file mode 100644 index 0000000000..d58d04b81c --- /dev/null +++ b/gtk2_ardour/plugin_window_proxy.cc @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2022 Robin Gareus + * + * 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 "ardour/plug_insert_base.h" +#include "ardour/plugin_manager.h" + +#include "gui_thread.h" +#include "plugin_ui.h" +#include "plugin_window_proxy.h" + +#include "pbd/i18n.h" + +using namespace ARDOUR; +using namespace Gtk; +using namespace Gtkmm2ext; + +PluginWindowProxy::PluginWindowProxy (std::string const& name, std::string const& title, std::weak_ptr plugin) + : WM::ProxyBase (name, std::string ()) + , _pib (plugin) + , _title (title) + , _is_custom (true) + , _want_custom (true) +{ + std::shared_ptr p = _pib.lock (); + if (!p) { + return; + } + p->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&PluginWindowProxy::plugin_going_away, this), gui_context ()); +} + +PluginWindowProxy::~PluginWindowProxy () +{ + _window = 0; +} + +Gtk::Window* +PluginWindowProxy::get (bool create) +{ + std::shared_ptr p = _pib.lock (); + if (!p) { + return 0; + } + + if (_window && (_is_custom != _want_custom)) { + set_state_mask (WindowProxy::StateMask (state_mask () & ~WindowProxy::Size)); + drop_window (); + } + + if (!_window) { + if (!create) { + return 0; + } + + _is_custom = _want_custom; + _window = new PluginUIWindow (p, false, _is_custom); + + if (_window) { + _window->set_title (generate_processor_title (p)); + setup (); + _window->show_all (); + } + } + return _window; +} + +void +PluginWindowProxy::show_the_right_window () +{ + if (_window && (_is_custom != _want_custom)) { + set_state_mask (WindowProxy::StateMask (state_mask () & ~WindowProxy::Size)); + drop_window (); + } + + if (_window) { + _window->unset_transient_for (); + } + toggle (); +} + +int +PluginWindowProxy::set_state (const XMLNode& node, int) +{ + XMLNodeList children = node.children (); + XMLNodeList::const_iterator i = children.begin (); + while (i != children.end ()) { + std::string name; + if ((*i)->name () == X_("Window") && (*i)->get_property (X_("name"), name) && name == _name) { + break; + } + ++i; + } + + if (i != children.end ()) { + (*i)->get_property (X_("custom-ui"), _want_custom); + } + + return ProxyBase::set_state (node, 0); +} + +XMLNode& +PluginWindowProxy::get_state () const +{ + XMLNode* node; + node = &ProxyBase::get_state (); + node->set_property (X_("custom-ui"), _is_custom); + return *node; +} + +void +PluginWindowProxy::plugin_going_away () +{ + delete _window; + _window = 0; + WM::Manager::instance ().remove (this); + drop_connections (); + delete this; +} + +std::string +PluginWindowProxy::generate_processor_title (std::shared_ptr p) +{ + std::string maker = p->plugin()->maker() ? p->plugin()->maker() : ""; + std::string::size_type email_pos; + + if ((email_pos = maker.find_first_of ('<')) != std::string::npos) { + maker = maker.substr (0, email_pos - 1); + } + + if (maker.length() > 32) { + maker = maker.substr (0, 32); + maker += " ..."; + } + + std::string type = PluginManager::plugin_type_name (p->type ()); + auto so = std::dynamic_pointer_cast (p); + assert (so); + + return string_compose(_("%1: %2 (by %3) [%4]"), _title, so->name(), maker, type); +} diff --git a/gtk2_ardour/plugin_window_proxy.h b/gtk2_ardour/plugin_window_proxy.h new file mode 100644 index 0000000000..5770bc66a4 --- /dev/null +++ b/gtk2_ardour/plugin_window_proxy.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2022,2024 Robin Gareus + * + * 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 _gtkardour_plugin_window_proxy_h_ +#define _gtkardour_plugin_window_proxy_h_ + +#include "ardour_window.h" +#include "window_manager.h" + +#include "pbd/signals.h" + +namespace Gtk +{ + class Window; +} + +namespace ARDOUR +{ + class PlugInsertBase; +} + +class PluginWindowProxy : public WM::ProxyBase, public PBD::ScopedConnectionList +{ +public: + PluginWindowProxy (std::string const&, std::string const&, std::weak_ptr); + ~PluginWindowProxy (); + + Gtk::Window* get (bool create = false); + + void show_the_right_window (); + + ARDOUR::SessionHandlePtr* session_handle () + { + return 0; + } + + void set_custom_ui_mode (bool use_custom) + { + _want_custom = use_custom; + } + + int set_state (const XMLNode&, int); + XMLNode& get_state () const; + + std::string generate_processor_title (std::shared_ptr); + +private: + void plugin_going_away (); + + std::weak_ptr _pib; + + std::string _title; + bool _is_custom; + bool _want_custom; +}; + +#endif diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 0869f99a23..fafcc4f185 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -219,6 +219,7 @@ gtk2_ardour_sources = [ 'plugin_ui.cc', 'plugin_dspload_ui.cc', 'plugin_dspload_window.cc', + 'plugin_window_proxy.cc', 'port_group.cc', 'port_insert_ui.cc', 'port_matrix.cc',