ardour/gtk2_ardour/route_properties_box.cc

293 lines
7.9 KiB
C++
Raw Normal View History

/*
* Copyright (C) 2011-2017 Paul Davis <paul@linuxaudiosystems.com>
* Copyright (C) 2024 Ben Loftis <ben@harrisonconsoles.com>
*
* 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.
*/
2024-11-19 17:20:57 +01:00
#include <cassert>
#include <ytkmm/widget.h>
2024-11-19 17:20:57 +01:00
#include "pbd/compose.h"
#include "ardour/audio_track.h"
2024-11-19 17:20:57 +01:00
#include "ardour/plugin_insert.h"
#include "ardour/port_insert.h"
#include "ardour/route.h"
#include "ardour/session.h"
#include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/utils.h"
#include "ardour_ui.h"
#include "mixer_ui.h"
2024-11-19 17:20:57 +01:00
#include "plugin_selector.h"
#include "plugin_ui.h"
#include "port_insert_ui.h"
#include "route_properties_box.h"
2024-11-19 17:20:57 +01:00
#include "timers.h"
2024-11-26 23:07:18 +01:00
#include "ui_config.h"
#include "pbd/i18n.h"
using namespace Gtk;
using namespace ARDOUR;
using namespace ArdourWidgets;
RoutePropertiesBox::RoutePropertiesBox ()
: _insert_box (nullptr)
, _show_insert (false)
, _idle_refill_processors_id (-1)
{
2024-11-19 17:20:57 +01:00
_scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER);
_scroller.add (_box);
_box.set_spacing (4);
_insert_frame.set_no_show_all ();
2024-11-19 17:20:57 +01:00
pack_start (_insert_frame, false, false, 4);
2024-11-19 17:20:57 +01:00
pack_start (_scroller, true, true);
show_all();
ARDOUR_UI::instance()->ActionsReady.connect_same_thread (_forever_connections, std::bind (&RoutePropertiesBox::ui_actions_ready, this));
}
RoutePropertiesBox::~RoutePropertiesBox ()
{
}
void
RoutePropertiesBox::ui_actions_ready ()
{
Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("show-editor-mixer"));
tact->signal_toggled().connect (sigc::mem_fun (*this, &RoutePropertiesBox::update_processor_box_visibility));
}
void
2024-11-19 17:20:57 +01:00
RoutePropertiesBox::session_going_away ()
{
ENSURE_GUI_THREAD (*this, &RoutePropertiesBox::session_going_away);
SessionHandlePtr::session_going_away ();
_insert_frame.remove ();
2024-11-19 17:20:57 +01:00
drop_plugin_uis ();
drop_route ();
delete _insert_box;
_insert_box = nullptr;
}
void
RoutePropertiesBox::set_session (ARDOUR::Session* s) {
SessionHandlePtr::set_session (s);
if (!s) {
return;
}
delete _insert_box;
_insert_box = new ProcessorBox (_session, std::bind (&Mixer_UI::plugin_selector, Mixer_UI::instance()), Mixer_UI::instance()->selection(), 0);
_insert_box->show_all ();
float ui_scale = std::max<float> (1.f, UIConfiguration::instance().get_ui_scale());
_insert_frame.remove ();
_insert_frame.add (*_insert_box);
_insert_frame.set_padding (4);
_insert_frame.set_size_request (144 * ui_scale, 236 * ui_scale);
_session->SurroundMasterAddedOrRemoved.connect (_session_connections, invalidator (*this), std::bind (&RoutePropertiesBox::surround_master_added_or_removed, this), gui_context());
}
void
RoutePropertiesBox::surround_master_added_or_removed ()
{
set_route (_route, true);
2024-11-19 17:20:57 +01:00
}
void
RoutePropertiesBox::set_route (std::shared_ptr<Route> r, bool force_update)
{
if (r == _route && !force_update) {
2024-11-23 10:54:02 +01:00
return;
}
2025-08-24 15:01:35 +02:00
if (!r) {
drop_route ();
return;
}
2024-11-19 17:20:57 +01:00
_route = r;
_route_connections.drop_connections ();
_route->processors_changed.connect (_route_connections, invalidator (*this), std::bind (&RoutePropertiesBox::idle_refill_processors, this), gui_context());
2024-11-19 17:20:57 +01:00
_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());
std::shared_ptr<AudioTrack> at = std::dynamic_pointer_cast<AudioTrack>(_route);
if (at) {
at->FreezeChange.connect (_route_connections, invalidator (*this), std::bind (&RoutePropertiesBox::map_frozen, this), gui_context());
}
_insert_box->set_route (r);
2024-11-19 17:20:57 +01:00
refill_processors ();
}
void
RoutePropertiesBox::map_frozen ()
{
ENSURE_GUI_THREAD (*this, &RoutePropertiesBox::map_frozen)
std::shared_ptr<AudioTrack> at = std::dynamic_pointer_cast<AudioTrack>(_route);
if (at && _insert_box) {
switch (at->freeze_state()) {
case AudioTrack::Frozen:
_insert_box->set_sensitive (false);
break;
default:
_insert_box->set_sensitive (true);
break;
}
}
}
void
RoutePropertiesBox::update_processor_box_visibility ()
{
_show_insert = !ActionManager::get_toggle_action (X_("Editor"), X_("show-editor-mixer"))->get_active ();
if (!_show_insert || _proc_uis.empty ()) {
_insert_frame.hide ();
} else {
_insert_frame.show ();
}
#ifndef MIXBUS
if (_show_insert || !_proc_uis.empty ()) {
float ui_scale = std::max<float> (1.f, UIConfiguration::instance().get_ui_scale());
set_size_request (-1, 365 * ui_scale); // match with SelectionPropertiesBox
} else {
set_size_request (-1, -1);
}
#endif
}
void
RoutePropertiesBox::property_changed (const PBD::PropertyChange& what_changed)
{
2024-11-19 17:20:57 +01:00
}
2024-11-19 17:20:57 +01:00
void
RoutePropertiesBox::drop_route ()
{
drop_plugin_uis ();
_route.reset ();
_route_connections.drop_connections ();
if (_idle_refill_processors_id >= 0) {
g_source_destroy (g_main_context_find_source_by_id (NULL, _idle_refill_processors_id));
_idle_refill_processors_id = -1;
}
2024-11-19 17:20:57 +01:00
}
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 ();
_insert_frame.hide ();
2024-11-19 17:20:57 +01:00
}
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;
}
#ifdef MIXBUS
2024-11-26 23:07:18 +01:00
if (std::dynamic_pointer_cast<PluginInsert> (pib)->channelstrip () != Processor::None) {
2024-11-25 23:20:49 +01:00
return;
}
#endif
2024-11-19 17:20:57 +01:00
GenericPluginUI* plugin_ui = new GenericPluginUI (pib, true, true);
if (plugin_ui->empty ()) {
delete plugin_ui;
return;
}
//pib->DropReferences.connect (_processor_connections, invalidator (*this), std::bind (&RoutePropertiesBox::refill_processors, this), gui_context());
2024-11-19 17:20:57 +01:00
_proc_uis.push_back (plugin_ui);
ArdourWidgets::Frame* frame = new ArdourWidgets::Frame ();
frame->set_label (p->display_name ());
frame->add (*plugin_ui);
2024-11-26 23:07:18 +01:00
frame->set_padding (0);
2024-11-19 17:20:57 +01:00
_box.pack_start (*frame, false, false);
plugin_ui->show ();
}
int
RoutePropertiesBox::_idle_refill_processors (gpointer arg)
{
static_cast<RoutePropertiesBox*>(arg)->refill_processors ();
return 0;
}
void
RoutePropertiesBox::idle_refill_processors ()
{
if (_idle_refill_processors_id < 0) {
_idle_refill_processors_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, _idle_refill_processors, this, NULL);
}
}
2024-11-19 17:20:57 +01:00
void
RoutePropertiesBox::refill_processors ()
{
if (!_session || _session->deletion_in_progress()) {
return;
}
drop_plugin_uis ();
2024-11-19 17:20:57 +01:00
assert (_route);
if (!_route) {
_idle_refill_processors_id = -1;
return;
}
2024-11-19 17:20:57 +01:00
_route->foreach_processor (sigc::mem_fun (*this, &RoutePropertiesBox::add_processor_to_display));
if (_proc_uis.empty ()) {
_scroller.hide ();
} else {
2024-11-26 23:07:18 +01:00
float ui_scale = std::max<float> (1.f, UIConfiguration::instance().get_ui_scale());
int h = 100 * ui_scale;
2024-11-19 17:20:57 +01:00
for (auto const& ui : _proc_uis) {
h = std::max<int> (h, ui->get_preferred_height () + /* frame label */ 34 * ui_scale);
2024-11-19 17:20:57 +01:00
}
2024-11-26 23:07:18 +01:00
h = std::min<int> (h, 300 * ui_scale);
_box.set_size_request (-1, h);
2024-11-19 17:20:57 +01:00
_scroller.show_all ();
}
update_processor_box_visibility ();
_idle_refill_processors_id = -1;
}