13
0

Show plugin UIs in Route Property Box

This commit is contained in:
Robin Gareus 2024-11-19 17:20:57 +01:00
parent 49c7464b9c
commit 2a620c64e9
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 130 additions and 39 deletions

View File

@ -17,35 +17,41 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "pbd/compose.h" #include <cassert>
#include <algorithm> #include <gtkmm/widget.h>
#include "pbd/compose.h"
#include "ardour/plugin_insert.h"
#include "ardour/port_insert.h"
#include "ardour/route.h"
#include "ardour/session.h"
#include "gtkmm2ext/actions.h"
#include "gtkmm2ext/gui_thread.h" #include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/utils.h" #include "gtkmm2ext/utils.h"
#include "ardour/location.h" #include "widgets/frame.h"
#include "ardour/profile.h"
#include "ardour/session.h"
#include "audio_clock.h"
#include "automation_line.h"
#include "control_point.h"
#include "editor.h"
#include "region_view.h"
#include "plugin_selector.h"
#include "plugin_ui.h"
#include "port_insert_ui.h"
#include "route_properties_box.h" #include "route_properties_box.h"
#include "timers.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
using namespace Gtk; using namespace Gtk;
using namespace ARDOUR; using namespace ARDOUR;
using namespace ArdourWidgets; using namespace ArdourWidgets;
using std::max;
using std::min;
RoutePropertiesBox::RoutePropertiesBox () RoutePropertiesBox::RoutePropertiesBox ()
{ {
_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER);
_scroller.add (_box);
_box.set_spacing (4);
pack_start (_scroller, true, true);
show_all(); show_all();
} }
@ -54,15 +60,98 @@ RoutePropertiesBox::~RoutePropertiesBox ()
} }
void void
RoutePropertiesBox::set_route (std::shared_ptr<ARDOUR::Route> rt) RoutePropertiesBox::session_going_away ()
{ {
//TODO: route properties ENSURE_GUI_THREAD (*this, &RoutePropertiesBox::session_going_away);
// rt->PropertyChanged.connect (state_connection, invalidator (*this), boost::bind (&RoutePropertiesBox::region_changed, this, _1), gui_context ()); SessionHandlePtr::session_going_away ();
drop_plugin_uis ();
drop_route ();
}
void
RoutePropertiesBox::set_route (std::shared_ptr<Route> r)
{
assert (r);
_route = r;
_route_connections.drop_connections ();
_route->processors_changed.connect (_route_connections, invalidator (*this), std::bind (&RoutePropertiesBox::refill_processors, this), gui_context());
_route->PropertyChanged.connect (_route_connections, invalidator (*this), std::bind (&RoutePropertiesBox::property_changed, this, _1), gui_context ());
_route->DropReferences.connect (_route_connections, invalidator (*this), std::bind (&RoutePropertiesBox::drop_route, this), gui_context());
refill_processors ();
} }
void void
RoutePropertiesBox::property_changed (const PBD::PropertyChange& what_changed) RoutePropertiesBox::property_changed (const PBD::PropertyChange& what_changed)
{ {
}
void
RoutePropertiesBox::drop_route ()
{
drop_plugin_uis ();
_route.reset ();
_route_connections.drop_connections ();
}
void
RoutePropertiesBox::drop_plugin_uis ()
{
std::list<Gtk::Widget*> children = _box.get_children ();
for (auto const& child : children) {
child->hide ();
_box.remove (*child);
delete child;
}
for (auto const& ui : _proc_uis) {
ui->stop_updating (0);
delete ui;
}
_processor_connections.drop_connections ();
_proc_uis.clear ();
}
void
RoutePropertiesBox::add_processor_to_display (std::weak_ptr<Processor> w)
{
std::shared_ptr<Processor> p = w.lock ();
std::shared_ptr<PlugInsertBase> pib = std::dynamic_pointer_cast<PlugInsertBase> (p);
if (!pib) {
return;
}
GenericPluginUI* plugin_ui = new GenericPluginUI (pib, true, true);
pib->DropReferences.connect (_processor_connections, invalidator (*this), std::bind (&RoutePropertiesBox::refill_processors, this), gui_context());
_proc_uis.push_back (plugin_ui);
ArdourWidgets::Frame* frame = new ArdourWidgets::Frame ();
frame->set_label (p->display_name ());
frame->add (*plugin_ui);
_box.pack_start (*frame, false, false);
plugin_ui->show ();
}
void
RoutePropertiesBox::refill_processors ()
{
if (!_session || _session->deletion_in_progress()) {
return;
}
drop_plugin_uis ();
assert (_route);
_route->foreach_processor (sigc::mem_fun (*this, &RoutePropertiesBox::add_processor_to_display));
if (_proc_uis.empty ()) {
_scroller.hide ();
} else {
int h = 60;
for (auto const& ui : _proc_uis) {
h = std::max<int> (h, ui->get_preferred_height () + /* frame label */ 22);
}
h = std::min<int> (h, 300);
_scroller.set_size_request (-1, h);
_scroller.show_all ();
}
} }

View File

@ -1,6 +1,7 @@
/* /*
* Copyright (C) 2021 Paul Davis <paul@linuxaudiosystems.com> * Copyright (C) 2021 Paul Davis <paul@linuxaudiosystems.com>
* Copyright (C) 2024 Ben Loftis <ben@harrisonconsoles.com> * Copyright (C) 2024 Ben Loftis <ben@harrisonconsoles.com>
* Copyright (C) 2024 Robin Gareus <robin@gareus.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -19,44 +20,45 @@
#pragma once #pragma once
#include <map> #include <vector>
#include <gtkmm/box.h> #include <gtkmm/box.h>
#include <gtkmm/label.h> #include <gtkmm/scrolledwindow.h>
#include <gtkmm/table.h>
#include "ardour/ardour.h" #include "ardour/ardour.h"
#include "ardour/session_handle.h" #include "ardour/session_handle.h"
#include "widgets/ardour_button.h" namespace ARDOUR {
class Route;
#include "gtkmm2ext/cairo_packer.h" class Processor;
#include "region_editor.h"
#include "audio_clock.h"
namespace ARDOUR
{
class Session; class Session;
class Location;
} }
class GenericPluginUI;
class RoutePropertiesBox : public Gtk::HBox, public ARDOUR::SessionHandlePtr class RoutePropertiesBox : public Gtk::HBox, public ARDOUR::SessionHandlePtr
{ {
public: public:
RoutePropertiesBox (); RoutePropertiesBox ();
~RoutePropertiesBox (); ~RoutePropertiesBox ();
virtual void set_route (std::shared_ptr<ARDOUR::Route>); void set_route (std::shared_ptr<ARDOUR::Route>);
protected:
std::shared_ptr<ARDOUR::Region> _route;
Gtk::Label _header_label;
private: private:
void property_changed (const PBD::PropertyChange& what_changed); void property_changed (const PBD::PropertyChange& what_changed);
void session_going_away ();
void drop_route ();
void drop_plugin_uis ();
void refill_processors ();
void add_processor_to_display (std::weak_ptr<ARDOUR::Processor> w);
PBD::ScopedConnection state_connection; Gtk::ScrolledWindow _scroller;
Gtk::HBox _box;
std::shared_ptr<ARDOUR::Route> _route;
std::vector <GenericPluginUI*> _proc_uis;
PBD::ScopedConnectionList _processor_connections;
PBD::ScopedConnectionList _route_connections;
}; };