2016-06-09 12:58:31 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2016-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2016-2019 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.
|
|
|
|
*/
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <gtkmm/menu.h>
|
|
|
|
|
2016-09-20 22:58:56 -04:00
|
|
|
#include "pbd/string_convert.h"
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/stripable.h"
|
|
|
|
#include "ardour/types.h"
|
|
|
|
#include "ardour/vca.h"
|
|
|
|
#include "ardour/vca_manager.h"
|
|
|
|
|
|
|
|
#include "gtkmm2ext/gtk_ui.h"
|
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
|
|
|
#include "control_slave_ui.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2017-07-15 11:38:28 -04:00
|
|
|
using namespace ArdourWidgets;
|
2016-06-09 12:58:31 -04:00
|
|
|
using namespace Gtk;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
ControlSlaveUI::ControlSlaveUI (Session* s)
|
|
|
|
: SessionHandlePtr (s)
|
|
|
|
, initial_button (ArdourButton::default_elements)
|
2017-03-15 20:50:30 -04:00
|
|
|
, context_menu (0)
|
2016-06-09 12:58:31 -04:00
|
|
|
{
|
|
|
|
set_no_show_all (true);
|
|
|
|
|
2017-02-20 10:50:42 -05:00
|
|
|
Gtkmm2ext::UI::instance()->set_tip (*this, _("VCA Assign"));
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
initial_button.set_no_show_all (true);
|
2020-01-12 18:22:39 -05:00
|
|
|
initial_button.set_name (X_("vca assign button"));
|
2016-12-21 06:14:44 -05:00
|
|
|
initial_button.set_text (_("-VCAs-"));
|
2016-06-09 12:58:31 -04:00
|
|
|
initial_button.show ();
|
|
|
|
initial_button.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
|
|
|
|
initial_button.signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::vca_button_release), 0), false);
|
|
|
|
|
|
|
|
pack_start (initial_button, true, true);
|
|
|
|
}
|
|
|
|
|
2017-03-15 20:50:30 -04:00
|
|
|
ControlSlaveUI::~ControlSlaveUI ()
|
|
|
|
{
|
|
|
|
delete context_menu;
|
|
|
|
}
|
|
|
|
|
2016-06-09 12:58:31 -04:00
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
ControlSlaveUI::set_stripable (std::shared_ptr<Stripable> s)
|
2016-06-09 12:58:31 -04:00
|
|
|
{
|
|
|
|
connections.drop_connections ();
|
|
|
|
|
|
|
|
stripable = s;
|
|
|
|
|
|
|
|
if (stripable) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<GainControl> ac = stripable->gain_control();
|
2016-06-09 12:58:31 -04:00
|
|
|
assert (ac);
|
|
|
|
|
|
|
|
ac->MasterStatusChange.connect (connections,
|
|
|
|
invalidator (*this),
|
|
|
|
boost::bind (&ControlSlaveUI::update_vca_display, this),
|
|
|
|
gui_context());
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
stripable->DropReferences.connect (connections, invalidator (*this), boost::bind (&ControlSlaveUI::set_stripable, this, std::shared_ptr<Stripable>()), gui_context());
|
2016-06-09 12:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
update_vca_display ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlSlaveUI::update_vca_display ()
|
|
|
|
{
|
2016-06-09 15:35:56 -04:00
|
|
|
if (!_session || _session->deletion_in_progress()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-09 12:58:31 -04:00
|
|
|
VCAList vcas (_session->vca_manager().vcas());
|
|
|
|
bool any = false;
|
|
|
|
|
|
|
|
Gtkmm2ext::container_clear (*this);
|
2016-06-09 15:35:56 -04:00
|
|
|
master_connections.drop_connections ();
|
2016-06-09 12:58:31 -04:00
|
|
|
|
2016-06-12 13:07:18 -04:00
|
|
|
if (stripable) {
|
|
|
|
for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
|
2019-02-27 10:49:29 -05:00
|
|
|
if (stripable->slaved_to (*v)) {
|
2016-06-12 13:07:18 -04:00
|
|
|
add_vca_button (*v);
|
|
|
|
any = true;
|
|
|
|
}
|
2016-06-09 12:58:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!any) {
|
|
|
|
pack_start (initial_button, true, true);
|
2017-04-26 18:11:18 -04:00
|
|
|
initial_button.show ();
|
2016-06-09 12:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
show ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlSlaveUI::vca_menu_toggle (Gtk::CheckMenuItem* menuitem, uint32_t n)
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<VCA> vca = _session->vca_manager().vca_by_number (n);
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
if (!vca) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Slavable> sl = std::dynamic_pointer_cast<Slavable> (stripable);
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
if (!sl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!menuitem->get_active()) {
|
|
|
|
sl->unassign (vca);
|
|
|
|
} else {
|
2017-06-22 15:06:24 -04:00
|
|
|
sl->assign (vca);
|
2016-06-09 12:58:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ControlSlaveUI::unassign_all ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Slavable> sl = std::dynamic_pointer_cast<Slavable> (stripable);
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
if (!sl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
sl->unassign (std::shared_ptr<VCA>());
|
2016-06-09 12:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ControlSlaveUI::specific_vca_button_release (GdkEventButton* ev, uint32_t n)
|
|
|
|
{
|
|
|
|
return vca_button_release (ev, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ControlSlaveUI::vca_button_release (GdkEventButton* ev, uint32_t n)
|
|
|
|
{
|
|
|
|
using namespace Gtk::Menu_Helpers;
|
|
|
|
|
|
|
|
if (!_session) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* primary click only */
|
|
|
|
|
|
|
|
if (ev->button != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stripable) {
|
|
|
|
/* no route - nothing to do */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
VCAList vcas (_session->vca_manager().vcas());
|
|
|
|
|
|
|
|
if (vcas.empty()) {
|
|
|
|
/* the button should not have been visible under these conditions */
|
2020-03-11 10:13:18 -04:00
|
|
|
return false;
|
2016-06-09 12:58:31 -04:00
|
|
|
}
|
|
|
|
|
2017-03-15 20:50:30 -04:00
|
|
|
delete context_menu;
|
|
|
|
context_menu = new Menu;
|
|
|
|
MenuList& items = context_menu->items();
|
2016-06-09 13:12:04 -04:00
|
|
|
bool slaved = false;
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
|
2016-06-09 13:12:04 -04:00
|
|
|
|
2017-10-19 20:54:06 -04:00
|
|
|
if (stripable->assigned_to (_session->vca_manager_ptr (), *v)) {
|
|
|
|
/* master(stripable) is directly or indirectly controlled by slave (v) */
|
2016-06-09 13:12:04 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-09 12:58:31 -04:00
|
|
|
items.push_back (CheckMenuElem ((*v)->name()));
|
|
|
|
Gtk::CheckMenuItem* item = dynamic_cast<Gtk::CheckMenuItem*> (&items.back());
|
2016-06-09 13:12:04 -04:00
|
|
|
|
2019-02-27 10:49:29 -05:00
|
|
|
if (stripable->slaved_to (*v)) {
|
2016-06-09 12:58:31 -04:00
|
|
|
item->set_active (true);
|
2016-06-09 13:12:04 -04:00
|
|
|
slaved = true;
|
2016-06-09 12:58:31 -04:00
|
|
|
}
|
2016-06-09 13:12:04 -04:00
|
|
|
|
2016-06-09 12:58:31 -04:00
|
|
|
item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::vca_menu_toggle), item, (*v)->number()));
|
|
|
|
}
|
|
|
|
|
2016-06-09 13:12:04 -04:00
|
|
|
if (slaved) {
|
|
|
|
items.push_back (MenuElem (_("Unassign All"), sigc::mem_fun (*this, &ControlSlaveUI::unassign_all)));
|
|
|
|
}
|
2016-06-09 12:58:31 -04:00
|
|
|
|
2016-06-09 13:12:04 -04:00
|
|
|
if (!items.empty()) {
|
2023-10-31 15:10:49 -04:00
|
|
|
context_menu->popup (ev->button, ev->time);
|
2023-12-13 08:14:31 -05:00
|
|
|
return false;
|
2016-06-09 13:12:04 -04:00
|
|
|
}
|
2016-06-09 12:58:31 -04:00
|
|
|
|
2020-03-11 10:13:18 -04:00
|
|
|
return false;
|
2016-06-09 12:58:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
ControlSlaveUI::add_vca_button (std::shared_ptr<VCA> vca)
|
2016-06-09 12:58:31 -04:00
|
|
|
{
|
|
|
|
ArdourButton* vca_button = manage (new ArdourButton (ArdourButton::default_elements));
|
|
|
|
|
|
|
|
vca_button->set_no_show_all (true);
|
2020-01-12 18:22:39 -05:00
|
|
|
vca_button->set_name (X_("vca assign button"));
|
2016-06-09 12:58:31 -04:00
|
|
|
vca_button->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
|
|
|
|
vca_button->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::specific_vca_button_release), vca->number()), false);
|
2016-09-20 22:58:56 -04:00
|
|
|
vca_button->set_text (PBD::to_string (vca->number()));
|
2016-06-09 15:35:56 -04:00
|
|
|
vca_button->set_fixed_colors (vca->presentation_info().color(), vca->presentation_info().color ());
|
|
|
|
|
|
|
|
vca->presentation_info().PropertyChanged.connect (master_connections, invalidator (*this), boost::bind (&ControlSlaveUI::master_property_changed, this, _1), gui_context());
|
2016-06-09 12:58:31 -04:00
|
|
|
|
|
|
|
pack_start (*vca_button);
|
|
|
|
vca_button->show ();
|
|
|
|
}
|
2016-06-09 15:35:56 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
ControlSlaveUI::master_property_changed (PBD::PropertyChange const& /* what_changed */)
|
|
|
|
{
|
|
|
|
update_vca_display ();
|
|
|
|
}
|