diff --git a/gtk2_ardour/route_properties_box.cc b/gtk2_ardour/route_properties_box.cc index 8820abc17e..46ecd63c7b 100644 --- a/gtk2_ardour/route_properties_box.cc +++ b/gtk2_ardour/route_properties_box.cc @@ -17,35 +17,41 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "pbd/compose.h" -#include +#include +#include + +#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/utils.h" -#include "ardour/location.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 "widgets/frame.h" +#include "plugin_selector.h" +#include "plugin_ui.h" +#include "port_insert_ui.h" #include "route_properties_box.h" +#include "timers.h" #include "pbd/i18n.h" using namespace Gtk; using namespace ARDOUR; using namespace ArdourWidgets; -using std::max; -using std::min; 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(); } @@ -54,15 +60,98 @@ RoutePropertiesBox::~RoutePropertiesBox () } void -RoutePropertiesBox::set_route (std::shared_ptr rt) +RoutePropertiesBox::session_going_away () { - //TODO: route properties -// rt->PropertyChanged.connect (state_connection, invalidator (*this), boost::bind (&RoutePropertiesBox::region_changed, this, _1), gui_context ()); + ENSURE_GUI_THREAD (*this, &RoutePropertiesBox::session_going_away); + SessionHandlePtr::session_going_away (); + + drop_plugin_uis (); + drop_route (); +} + +void +RoutePropertiesBox::set_route (std::shared_ptr 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 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 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 w) +{ + std::shared_ptr p = w.lock (); + std::shared_ptr pib = std::dynamic_pointer_cast (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 (h, ui->get_preferred_height () + /* frame label */ 22); + } + h = std::min (h, 300); + _scroller.set_size_request (-1, h); + _scroller.show_all (); + } } diff --git a/gtk2_ardour/route_properties_box.h b/gtk2_ardour/route_properties_box.h index bedb5dacc9..9ee1556fbd 100644 --- a/gtk2_ardour/route_properties_box.h +++ b/gtk2_ardour/route_properties_box.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2021 Paul Davis * Copyright (C) 2024 Ben Loftis + * Copyright (C) 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 @@ -19,44 +20,45 @@ #pragma once -#include +#include #include -#include -#include +#include #include "ardour/ardour.h" #include "ardour/session_handle.h" -#include "widgets/ardour_button.h" - -#include "gtkmm2ext/cairo_packer.h" - -#include "region_editor.h" -#include "audio_clock.h" - -namespace ARDOUR -{ +namespace ARDOUR { + class Route; + class Processor; class Session; - class Location; } +class GenericPluginUI; + class RoutePropertiesBox : public Gtk::HBox, public ARDOUR::SessionHandlePtr { public: RoutePropertiesBox (); ~RoutePropertiesBox (); - virtual void set_route (std::shared_ptr); - -protected: - std::shared_ptr _route; - - Gtk::Label _header_label; + void set_route (std::shared_ptr); private: 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 w); - PBD::ScopedConnection state_connection; + Gtk::ScrolledWindow _scroller; + Gtk::HBox _box; + + std::shared_ptr _route; + std::vector _proc_uis; + + PBD::ScopedConnectionList _processor_connections; + PBD::ScopedConnectionList _route_connections; };