2021-01-28 21:31:37 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2012-2021 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ardour/async_midi_port.h"
|
|
|
|
#include "ardour/audioengine.h"
|
2022-10-16 09:58:16 -04:00
|
|
|
#include "ardour/io_plug.h"
|
2021-01-28 21:31:37 -05:00
|
|
|
#include "ardour/profile.h"
|
|
|
|
#include "ardour/route.h"
|
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/track.h"
|
|
|
|
#include "ardour/user_bundle.h"
|
|
|
|
|
|
|
|
#include "gtkmm2ext/menu_elems.h"
|
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
#include "widgets/tooltips.h"
|
|
|
|
|
|
|
|
#include "ardour_message.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
#include "io_button.h"
|
|
|
|
#include "io_selector.h"
|
|
|
|
#include "route_ui.h"
|
|
|
|
#include "ui_config.h"
|
|
|
|
|
|
|
|
#include "pbd/i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace ArdourWidgets;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
IOButton::IOButton (bool input)
|
|
|
|
: _input (input)
|
|
|
|
, _route_ui (0)
|
|
|
|
{
|
|
|
|
set_text (input ? _("Input") : _("Output"));
|
|
|
|
set_name ("mixer strip button");
|
|
|
|
set_text_ellipsize (Pango::ELLIPSIZE_MIDDLE);
|
|
|
|
|
|
|
|
signal_button_press_event ().connect (sigc::mem_fun (*this, &IOButton::button_press), false);
|
|
|
|
signal_button_release_event ().connect (sigc::mem_fun (*this, &IOButton::button_release), false);
|
|
|
|
signal_size_allocate ().connect (sigc::mem_fun (*this, &IOButton::button_resized));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::set_route (boost::shared_ptr<ARDOUR::Route> rt, RouteUI* routeui)
|
|
|
|
{
|
|
|
|
_connections.drop_connections ();
|
2021-02-26 09:46:55 -05:00
|
|
|
_bundle_connections.drop_connections ();
|
2021-01-28 21:31:37 -05:00
|
|
|
|
|
|
|
_route = rt;
|
|
|
|
_route_ui = routeui;
|
|
|
|
|
|
|
|
if (!_route) {
|
|
|
|
_route_ui = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioEngine::instance ()->PortConnectedOrDisconnected.connect (_connections, invalidator (*this), boost::bind (&IOButton::port_connected_or_disconnected, this, _1, _3), gui_context ());
|
|
|
|
AudioEngine::instance ()->PortPrettyNameChanged.connect (_connections, invalidator (*this), boost::bind (&IOButton::port_pretty_name_changed, this, _1), gui_context ());
|
|
|
|
|
|
|
|
io ()->changed.connect (_connections, invalidator (*this), boost::bind (&IOButton::update, this), gui_context ());
|
2021-02-26 09:46:55 -05:00
|
|
|
/* We're really only interested in BundleRemoved when connected to that bundle */
|
|
|
|
_route->session ().BundleAddedOrRemoved.connect (_connections, invalidator (*this), boost::bind (&IOButton::update, this), gui_context ());
|
2021-01-28 21:31:37 -05:00
|
|
|
|
|
|
|
update ();
|
|
|
|
}
|
|
|
|
|
|
|
|
IOButton::~IOButton ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<IO>
|
|
|
|
IOButton::io () const
|
|
|
|
{
|
|
|
|
return _input ? _route->input () : _route->output ();
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<Track>
|
|
|
|
IOButton::track () const
|
|
|
|
{
|
|
|
|
return boost::dynamic_pointer_cast<Track> (_route);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::port_pretty_name_changed (std::string pn)
|
|
|
|
{
|
|
|
|
if (io ()->connected_to (pn)) {
|
|
|
|
update ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::port_connected_or_disconnected (boost::weak_ptr<Port> wa, boost::weak_ptr<Port> wb)
|
|
|
|
{
|
|
|
|
boost::shared_ptr<Port> a = wa.lock ();
|
|
|
|
boost::shared_ptr<Port> b = wb.lock ();
|
|
|
|
|
|
|
|
if ((a && io ()->has_port (a)) || (b && io ()->has_port (b))) {
|
|
|
|
update ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::bundle_chosen (boost::shared_ptr<ARDOUR::Bundle> c)
|
|
|
|
{
|
|
|
|
if (_input) {
|
|
|
|
_route->input ()->connect_ports_to_bundle (c, true, this);
|
|
|
|
} else {
|
|
|
|
_route->output ()->connect_ports_to_bundle (c, true, true, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::disconnect ()
|
|
|
|
{
|
|
|
|
io ()->disconnect (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::add_port (DataType t)
|
|
|
|
{
|
|
|
|
if (io ()->add_port ("", this, t) != 0) {
|
|
|
|
ArdourMessageDialog msg (_("It is not possible to add a port here."));
|
|
|
|
msg.set_title (_("Cannot add port"));
|
|
|
|
msg.run ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::button_resized (Gtk::Allocation& alloc)
|
|
|
|
{
|
|
|
|
set_layout_ellipsize_width (alloc.get_width () * PANGO_SCALE);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RouteCompareByName {
|
|
|
|
bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b)
|
|
|
|
{
|
|
|
|
return a->name ().compare (b->name ()) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
|
|
|
IOButton::button_release (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
if (!_route || !_route_ui) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ev->button == 3) {
|
|
|
|
if (_input) {
|
|
|
|
_route_ui->edit_input_configuration ();
|
|
|
|
} else {
|
|
|
|
_route_ui->edit_output_configuration ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IOButton::button_press (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
using namespace Gtk::Menu_Helpers;
|
|
|
|
|
|
|
|
if (!ARDOUR_UI_UTILS::engine_is_running () || !_route || !_route_ui) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuList& citems = _menu.items ();
|
|
|
|
_menu.set_name ("ArdourContextMenu");
|
|
|
|
citems.clear ();
|
|
|
|
|
|
|
|
if (_route->session ().actively_recording () && track () && track ()->rec_enable_control ()->get_value ()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ev->button) {
|
|
|
|
case 3:
|
|
|
|
/* don't handle the mouse-down here, parent handles mouse-up if needed. */
|
|
|
|
return false;
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* do nothing */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
citems.push_back (MenuElem (_("Disconnect"), sigc::mem_fun (*this, &IOButton::disconnect)));
|
|
|
|
citems.push_back (SeparatorElem ());
|
|
|
|
uint32_t const n_with_separator = citems.size ();
|
|
|
|
|
|
|
|
_menu_bundles.clear ();
|
|
|
|
ARDOUR::BundleList current = io ()->bundles_connected ();
|
|
|
|
boost::shared_ptr<ARDOUR::BundleList> b = _route->session ().bundles ();
|
|
|
|
|
|
|
|
if (_input) {
|
|
|
|
/* give user bundles first chance at being in the menu */
|
|
|
|
for (ARDOUR::BundleList::iterator i = b->begin (); i != b->end (); ++i) {
|
|
|
|
if (boost::dynamic_pointer_cast<UserBundle> (*i)) {
|
|
|
|
maybe_add_bundle_to_menu (*i, current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ARDOUR::BundleList::iterator i = b->begin (); i != b->end (); ++i) {
|
|
|
|
if (boost::dynamic_pointer_cast<UserBundle> (*i) == 0) {
|
|
|
|
maybe_add_bundle_to_menu (*i, current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* guess the user-intended main type of the route output */
|
2022-04-27 17:15:45 -04:00
|
|
|
DataType intended_type = guess_main_type (_input ? _route->input () : _route->output ());
|
2021-01-28 21:31:37 -05:00
|
|
|
|
|
|
|
/* try adding the master bus first */
|
|
|
|
boost::shared_ptr<Route> master = _route->session ().master_out ();
|
|
|
|
if (master) {
|
|
|
|
maybe_add_bundle_to_menu (master->input ()->bundle (), current, intended_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<ARDOUR::RouteList> routes = _route->session ().get_routes ();
|
|
|
|
RouteList copy = *routes;
|
|
|
|
copy.sort (RouteCompareByName ());
|
|
|
|
|
2021-03-24 20:54:48 -04:00
|
|
|
if (_input) {
|
|
|
|
/* other routes outputs */
|
|
|
|
for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
|
|
|
|
if ((*i)->is_foldbackbus ()) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-28 18:17:35 -04:00
|
|
|
if (_route->feeds (*i)) {
|
2021-03-24 20:54:48 -04:00
|
|
|
/* do not offer connections that would cause feedback */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
maybe_add_bundle_to_menu ((*i)->output ()->bundle (), current);
|
|
|
|
}
|
2022-10-16 15:44:52 -04:00
|
|
|
|
|
|
|
for (auto const& iop : *_route->session ().io_plugs ()) {
|
|
|
|
if (!iop->is_pre ()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
maybe_add_bundle_to_menu (iop->output ()->bundle (), current);
|
|
|
|
}
|
2021-03-24 20:54:48 -04:00
|
|
|
} else {
|
2022-04-27 17:15:45 -04:00
|
|
|
DataType intended_type = guess_main_type (_input ? _route->input () : _route->output ());
|
2021-03-24 20:54:48 -04:00
|
|
|
|
|
|
|
/* other routes inputs */
|
|
|
|
for (ARDOUR::RouteList::const_iterator i = copy.begin(); i != copy.end(); ++i) {
|
2021-03-25 21:33:56 -04:00
|
|
|
if ((*i)->is_foldbackbus () || _route->is_foldbackbus ()) {
|
2021-03-24 20:54:48 -04:00
|
|
|
continue;
|
|
|
|
}
|
2022-04-28 18:17:35 -04:00
|
|
|
if ((*i)->feeds (_route)) {
|
2021-03-24 20:54:48 -04:00
|
|
|
/* do not offer connections that would cause feedback */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
maybe_add_bundle_to_menu ((*i)->input()->bundle(), current, intended_type);
|
|
|
|
}
|
|
|
|
|
2021-01-28 21:31:37 -05:00
|
|
|
/* then try adding user output bundles, often labeled/grouped physical inputs */
|
|
|
|
for (ARDOUR::BundleList::iterator i = b->begin (); i != b->end (); ++i) {
|
|
|
|
if (boost::dynamic_pointer_cast<UserBundle> (*i)) {
|
|
|
|
maybe_add_bundle_to_menu (*i, current, intended_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fix typos in gtk2_ardour/ directory
Found via `codespell -q 3 -S *.po,./share/patchfiles,./libs -L ba,buss,busses,doubleclick,hsi,ontop,ro,seh,siz,sur,te,trough,ue`
2022-01-26 12:35:38 -05:00
|
|
|
/* then all other bundles, including physical outs or other software */
|
2021-01-28 21:31:37 -05:00
|
|
|
for (ARDOUR::BundleList::iterator i = b->begin (); i != b->end (); ++i) {
|
|
|
|
if (boost::dynamic_pointer_cast<UserBundle> (*i) == 0) {
|
|
|
|
maybe_add_bundle_to_menu (*i, current, intended_type);
|
|
|
|
}
|
|
|
|
}
|
2022-10-16 15:44:52 -04:00
|
|
|
|
|
|
|
for (auto const& iop : *_route->session ().io_plugs ()) {
|
|
|
|
if (iop->is_pre ()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
maybe_add_bundle_to_menu (iop->input ()->bundle (), current, intended_type);
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (citems.size () > n_with_separator) {
|
|
|
|
citems.push_back (SeparatorElem ());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_input || !ARDOUR::Profile->get_mixbus ()) {
|
|
|
|
bool need_separator = false;
|
|
|
|
for (DataType::iterator i = DataType::begin (); i != DataType::end (); ++i) {
|
|
|
|
if (!io ()->can_add_port (*i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
need_separator = true;
|
|
|
|
citems.push_back (
|
|
|
|
MenuElem (
|
|
|
|
string_compose (_("Add %1 port"), (*i).to_i18n_string ()),
|
|
|
|
sigc::bind (sigc::mem_fun (*this, &IOButton::add_port), *i)));
|
|
|
|
}
|
|
|
|
if (need_separator) {
|
|
|
|
citems.push_back (SeparatorElem ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_input) {
|
|
|
|
citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*_route_ui, &RouteUI::edit_input_configuration)));
|
|
|
|
} else {
|
|
|
|
citems.push_back (MenuElem (_("Routing Grid"), sigc::mem_fun (*_route_ui, &RouteUI::edit_output_configuration)));
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtkmm2ext::anchored_menu_popup (&_menu, this, "", 1, ev->time);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataType
|
2022-04-27 17:15:45 -04:00
|
|
|
IOButton::guess_main_type (boost::shared_ptr<IO> io)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
|
|
|
/* The heuristic follows these principles:
|
|
|
|
* A) If all ports that the user connected are of the same type, then he
|
|
|
|
* very probably intends to use the IO with that type. A common subcase
|
|
|
|
* is when the IO has only ports of the same type (connected or not).
|
|
|
|
* B) If several types of ports are connected, then we should guess based
|
|
|
|
* on the likeliness of the user wanting to use a given type.
|
|
|
|
* We assume that the DataTypes are ordered from the most likely to the
|
|
|
|
* least likely when iterating or comparing them with "<".
|
|
|
|
* C) If no port is connected, the same logic can be applied with all ports
|
|
|
|
* instead of connected ones. TODO: Try other ideas, for instance look at
|
|
|
|
* the last plugin output when |for_input| is false (note: when StrictIO
|
|
|
|
* the outs of the last plugin should be the same as the outs of the route
|
|
|
|
* modulo the panner which forwards non-audio anyway).
|
|
|
|
* All of these constraints are respected by the following algorithm that
|
|
|
|
* just returns the most likely datatype found in connected ports if any, or
|
|
|
|
* available ports if any (since if all ports are of the same type, the most
|
|
|
|
* likely found will be that one obviously). */
|
|
|
|
|
|
|
|
/* Find most likely type among connected ports */
|
2022-04-27 17:15:45 -04:00
|
|
|
DataType type = DataType::NIL; /* NIL is always last so least likely */
|
|
|
|
for (PortSet::iterator p = io->ports ().begin (); p != io->ports ().end (); ++p) {
|
|
|
|
if (p->connected () && p->type () < type)
|
|
|
|
type = p->type ();
|
|
|
|
}
|
|
|
|
if (type != DataType::NIL) {
|
|
|
|
/* There has been a connected port (necessarily non-NIL) */
|
|
|
|
return type;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Find most likely type among available ports.
|
|
|
|
* The iterator stops before NIL. */
|
|
|
|
for (DataType::iterator t = DataType::begin (); t != DataType::end (); ++t) {
|
|
|
|
if (io->n_ports ().n (*t) > 0)
|
|
|
|
return *t;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No port at all, return the most likely datatype by default */
|
|
|
|
return DataType::front ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output port labelling
|
|
|
|
*
|
|
|
|
* Case 1: Each output has one connection, all connections are to system:playback_%i
|
|
|
|
* out 1 -> system:playback_1
|
|
|
|
* out 2 -> system:playback_2
|
|
|
|
* out 3 -> system:playback_3
|
|
|
|
* Display as: 1/2/3
|
|
|
|
*
|
|
|
|
* Case 2: Each output has one connection, all connections are to ardour:track_x/in 1
|
|
|
|
* out 1 -> ardour:track_x/in 1
|
|
|
|
* out 2 -> ardour:track_x/in 2
|
|
|
|
* Display as: track_x
|
|
|
|
*
|
|
|
|
* Case 3: Each output has one connection, all connections are to Jack client "program x"
|
|
|
|
* out 1 -> program x:foo
|
|
|
|
* out 2 -> program x:foo
|
|
|
|
* Display as: program x
|
|
|
|
*
|
|
|
|
* Case 4: No connections (Disconnected)
|
|
|
|
* Display as: -
|
|
|
|
*
|
|
|
|
* Default case (unusual routing):
|
|
|
|
* Display as: *number of connections*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Tooltips
|
|
|
|
*
|
|
|
|
* .-----------------------------------------------.
|
|
|
|
* | Mixdown |
|
|
|
|
* | out 1 -> ardour:master/in 1, jamin:input/in 1 |
|
|
|
|
* | out 2 -> ardour:master/in 2, jamin:input/in 2 |
|
|
|
|
* '-----------------------------------------------'
|
|
|
|
* .-----------------------------------------------.
|
|
|
|
* | Guitar SM58 |
|
|
|
|
* | Disconnected |
|
|
|
|
* '-----------------------------------------------'
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::update ()
|
2022-04-27 17:15:45 -04:00
|
|
|
{
|
|
|
|
boost::shared_ptr<ARDOUR::Bundle> bundle;
|
|
|
|
_bundle_connections.drop_connections ();
|
|
|
|
|
|
|
|
set_label (*this, _route->session(), bundle, _input ? _route->input () : _route->output ());
|
|
|
|
|
|
|
|
if (bundle) {
|
|
|
|
bundle->Changed.connect (_bundle_connections, invalidator (*this), boost::bind (&IOButton::update, this), gui_context ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::set_label (ArdourWidgets::ArdourButton& self, ARDOUR::Session& session, boost::shared_ptr<ARDOUR::Bundle>& bndl, boost::shared_ptr<ARDOUR::IO> io)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
|
|
|
ostringstream tooltip;
|
|
|
|
ostringstream label;
|
|
|
|
bool have_label = false;
|
|
|
|
|
|
|
|
uint32_t total_connection_count = 0;
|
|
|
|
uint32_t typed_connection_count = 0;
|
|
|
|
bool each_typed_port_has_one_connection = true;
|
|
|
|
|
2022-04-27 17:15:45 -04:00
|
|
|
DataType dt = guess_main_type (io);
|
|
|
|
bool input = io->direction () == IO::Input;
|
|
|
|
string arrow = Gtkmm2ext::markup_escape_text (input ? " <- " : " -> ");
|
2021-02-26 09:46:55 -05:00
|
|
|
|
2021-01-28 21:31:37 -05:00
|
|
|
/* Fill in the tooltip. Also count:
|
|
|
|
* - The total number of connections.
|
|
|
|
* - The number of main-typed connections.
|
|
|
|
* - Whether each main-typed port has exactly one connection. */
|
2022-04-27 17:15:45 -04:00
|
|
|
if (input) {
|
2021-01-28 21:31:37 -05:00
|
|
|
tooltip << string_compose (_("<b>INPUT</b> to %1"),
|
2022-04-27 17:15:45 -04:00
|
|
|
Gtkmm2ext::markup_escape_text (io->name ()));
|
2021-01-28 21:31:37 -05:00
|
|
|
} else {
|
|
|
|
tooltip << string_compose (_("<b>OUTPUT</b> from %1"),
|
2022-04-27 17:15:45 -04:00
|
|
|
Gtkmm2ext::markup_escape_text (io->name ()));
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
vector<string> port_connections;
|
2022-04-27 17:15:45 -04:00
|
|
|
|
|
|
|
for (auto const& port : io->ports ()) {
|
2021-01-28 21:31:37 -05:00
|
|
|
port_connections.clear ();
|
|
|
|
port->get_connections (port_connections);
|
|
|
|
|
|
|
|
uint32_t port_connection_count = 0;
|
|
|
|
|
2022-04-27 17:15:45 -04:00
|
|
|
for (auto const& i : port_connections) {
|
2021-01-28 21:31:37 -05:00
|
|
|
++port_connection_count;
|
|
|
|
|
|
|
|
if (port_connection_count == 1) {
|
|
|
|
tooltip << endl
|
2022-04-27 17:15:45 -04:00
|
|
|
<< Gtkmm2ext::markup_escape_text (port->name ().substr (port->name ().find ("/") + 1));
|
2021-01-28 21:31:37 -05:00
|
|
|
tooltip << arrow;
|
|
|
|
} else {
|
|
|
|
tooltip << ", ";
|
|
|
|
}
|
|
|
|
|
2022-04-27 17:15:45 -04:00
|
|
|
tooltip << Gtkmm2ext::markup_escape_text (i);
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
total_connection_count += port_connection_count;
|
|
|
|
if (port->type () == dt) {
|
|
|
|
typed_connection_count += port_connection_count;
|
|
|
|
each_typed_port_has_one_connection &= (port_connection_count == 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total_connection_count == 0) {
|
|
|
|
tooltip << endl
|
|
|
|
<< _("Disconnected");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typed_connection_count == 0) {
|
|
|
|
label << "-";
|
|
|
|
have_label = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Are all main-typed channels connected to the same route ? */
|
|
|
|
if (!have_label) {
|
2022-04-27 17:15:45 -04:00
|
|
|
boost::shared_ptr<ARDOUR::RouteList> routes = session.get_routes ();
|
2021-01-28 21:31:37 -05:00
|
|
|
for (ARDOUR::RouteList::const_iterator route = routes->begin ();
|
|
|
|
route != routes->end ();
|
|
|
|
++route) {
|
2022-04-27 17:15:45 -04:00
|
|
|
boost::shared_ptr<IO> dest_io = input ? (*route)->output () : (*route)->input ();
|
|
|
|
if (io->bundle ()->connected_to (dest_io->bundle (), session.engine (), dt, true)) {
|
2021-01-28 21:31:37 -05:00
|
|
|
label << Gtkmm2ext::markup_escape_text ((*route)->name ());
|
|
|
|
have_label = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Are all main-typed channels connected to the same (user) bundle ? */
|
|
|
|
if (!have_label) {
|
2022-04-27 17:15:45 -04:00
|
|
|
boost::shared_ptr<ARDOUR::BundleList> bundles = session.bundles ();
|
|
|
|
boost::shared_ptr<ARDOUR::Port> ap = boost::dynamic_pointer_cast<ARDOUR::Port> (session.vkbd_output_port ());
|
2021-01-28 21:31:37 -05:00
|
|
|
std::string vkbd_portname = AudioEngine::instance ()->make_port_name_non_relative (ap->name ());
|
2022-04-27 17:15:45 -04:00
|
|
|
for (auto const& bundle : *bundles) {
|
|
|
|
if (boost::dynamic_pointer_cast<UserBundle> (bundle) == 0) {
|
|
|
|
if (!bundle->offers_port (vkbd_portname)) {
|
2021-01-28 21:31:37 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2022-04-27 17:15:45 -04:00
|
|
|
if (io->bundle ()->connected_to (bundle, session.engine (), dt, true)) {
|
|
|
|
label << Gtkmm2ext::markup_escape_text (bundle->name ());
|
2021-01-28 21:31:37 -05:00
|
|
|
have_label = true;
|
2022-04-27 17:15:45 -04:00
|
|
|
bndl = bundle;
|
2021-01-28 21:31:37 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is each main-typed channel only connected to a physical output ? */
|
|
|
|
if (!have_label && each_typed_port_has_one_connection) {
|
|
|
|
ostringstream temp_label;
|
|
|
|
vector<string> phys;
|
|
|
|
string playorcapture;
|
2022-04-27 17:15:45 -04:00
|
|
|
if (input) {
|
|
|
|
session.engine ().get_physical_inputs (dt, phys);
|
2021-01-28 21:31:37 -05:00
|
|
|
playorcapture = "capture_";
|
|
|
|
} else {
|
2022-04-27 17:15:45 -04:00
|
|
|
session.engine ().get_physical_outputs (dt, phys);
|
2021-01-28 21:31:37 -05:00
|
|
|
playorcapture = "playback_";
|
|
|
|
}
|
|
|
|
for (PortSet::iterator port = io->ports ().begin (dt);
|
|
|
|
port != io->ports ().end (dt);
|
|
|
|
++port) {
|
|
|
|
string pn = "";
|
2022-04-27 17:15:45 -04:00
|
|
|
for (auto const& s : phys) {
|
|
|
|
if (!port->connected_to (s)) {
|
2021-01-28 21:31:37 -05:00
|
|
|
continue;
|
|
|
|
}
|
2022-04-27 17:15:45 -04:00
|
|
|
pn = AudioEngine::instance ()->get_pretty_name_by_name (s);
|
2021-01-28 21:31:37 -05:00
|
|
|
if (pn.empty ()) {
|
2022-04-27 17:15:45 -04:00
|
|
|
string::size_type start = (s).find (playorcapture);
|
2021-01-28 21:31:37 -05:00
|
|
|
if (start != string::npos) {
|
2022-04-27 17:15:45 -04:00
|
|
|
pn = (s).substr (start + playorcapture.size ());
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pn.empty ()) {
|
|
|
|
temp_label.str (""); /* erase the failed attempt */
|
|
|
|
break;
|
|
|
|
}
|
2022-04-27 17:15:45 -04:00
|
|
|
if (port != io->ports ().begin (dt)) {
|
2021-01-28 21:31:37 -05:00
|
|
|
temp_label << "/";
|
2022-04-27 17:15:45 -04:00
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
temp_label << pn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!temp_label.str ().empty ()) {
|
|
|
|
label << temp_label.str ();
|
|
|
|
have_label = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 09:58:16 -04:00
|
|
|
/* check for direct connections to I/O Plugins */
|
|
|
|
if (!have_label) {
|
|
|
|
for (auto const& iop : *session.io_plugs ()) {
|
|
|
|
boost::shared_ptr<IO> i = input ? iop->output () : iop->input ();
|
|
|
|
if (!io->connected_to (i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* direct 1:1 connection to IOP */
|
|
|
|
if (io->bundle ()->connected_to (i->bundle (), session.engine (), dt, true)) {
|
|
|
|
label << iop->io_name();
|
|
|
|
have_label = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if IO is exclusively connected to a subset of this IOP's ports */
|
|
|
|
uint32_t n = 0;
|
|
|
|
uint32_t cnt = 0;
|
|
|
|
std::set<uint32_t> pn;
|
|
|
|
PortSet const& psa (i->ports ());
|
|
|
|
PortSet const& psb (io->ports ());
|
|
|
|
|
|
|
|
for (auto a = psa.begin (dt); a != psa.end (dt); ++a, ++n) {
|
|
|
|
for (auto b = psb.begin (dt); b != psb.end (dt); ++b) {
|
|
|
|
if (a->connected_to (b->name ())) {
|
|
|
|
++cnt;
|
|
|
|
pn.insert (n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt != typed_connection_count) {
|
|
|
|
/* IO has additional connections.
|
|
|
|
* No need to check other IOPs (they will produce
|
|
|
|
* the same result).
|
|
|
|
*/
|
|
|
|
assert (cnt > 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
have_label = true;
|
|
|
|
label << iop->io_name() << " ";
|
|
|
|
|
|
|
|
bool first = true;
|
|
|
|
for (auto const& num : pn) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
label << "+";
|
|
|
|
}
|
|
|
|
label << i->bundle()->channel_name (num);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO check for internal connection (port_is_mine), do not simply
|
|
|
|
// print "ardour" as client name
|
|
|
|
|
2021-01-28 21:31:37 -05:00
|
|
|
/* Is each main-typed channel connected to a single and different port with
|
|
|
|
* the same client name (e.g. another JACK client) ? */
|
|
|
|
if (!have_label && each_typed_port_has_one_connection) {
|
|
|
|
string maybe_client = "";
|
|
|
|
vector<string> connections;
|
|
|
|
for (PortSet::iterator port = io->ports ().begin (dt);
|
|
|
|
port != io->ports ().end (dt);
|
|
|
|
++port) {
|
|
|
|
port_connections.clear ();
|
|
|
|
port->get_connections (port_connections);
|
|
|
|
string connection = port_connections.front ();
|
|
|
|
|
|
|
|
vector<string>::iterator i = connections.begin ();
|
|
|
|
while (i != connections.end () && *i != connection) {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i != connections.end ()) {
|
|
|
|
break; /* duplicate connection */
|
|
|
|
}
|
|
|
|
connections.push_back (connection);
|
|
|
|
|
|
|
|
connection = connection.substr (0, connection.find (":"));
|
|
|
|
|
|
|
|
if (maybe_client.empty ()) {
|
|
|
|
maybe_client = connection;
|
|
|
|
}
|
|
|
|
if (maybe_client != connection) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (connections.size () == io->n_ports ().n (dt)) {
|
|
|
|
label << maybe_client;
|
|
|
|
have_label = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Odd configuration */
|
|
|
|
if (!have_label) {
|
|
|
|
label << "*" << total_connection_count << "*";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total_connection_count > typed_connection_count) {
|
|
|
|
label << "\u2295"; /* circled plus */
|
|
|
|
}
|
|
|
|
|
2022-04-27 17:15:45 -04:00
|
|
|
self.set_text (label.str ());
|
|
|
|
set_tooltip (&self, tooltip.str ());
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOButton::maybe_add_bundle_to_menu (boost::shared_ptr<Bundle> b, ARDOUR::BundleList const& /*current*/, ARDOUR::DataType type)
|
|
|
|
{
|
|
|
|
using namespace Gtk::Menu_Helpers;
|
|
|
|
|
|
|
|
if (_input) {
|
|
|
|
/* The bundle should be a source with matching inputs, but not ours */
|
|
|
|
if (b->ports_are_outputs () == false || b->nchannels () != _route->n_inputs () || *b == *_route->output ()->bundle ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* The bundle should be sink, but not ours */
|
|
|
|
if (b->ports_are_inputs () == false || *b == *_route->input ()->bundle ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't add the monitor input unless we are Master */
|
|
|
|
boost::shared_ptr<Route> monitor = _route->session ().monitor_out ();
|
|
|
|
if ((!_route->is_master ()) && monitor && b->has_same_ports (monitor->input ()->bundle ())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It should either match exactly our outputs (if |type| is DataType::NIL)
|
|
|
|
* or have the same number of |type| channels than our outputs. */
|
|
|
|
if (type == DataType::NIL) {
|
|
|
|
if (b->nchannels () != _route->n_outputs ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (b->nchannels ().n (type) != _route->n_outputs ().n (type))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Avoid adding duplicates */
|
2021-01-30 17:23:35 -05:00
|
|
|
list<boost::shared_ptr<Bundle> >::iterator i = _menu_bundles.begin ();
|
2021-01-28 21:31:37 -05:00
|
|
|
while (i != _menu_bundles.end () && b->has_same_ports (*i) == false) {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i != _menu_bundles.end ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally add the bundle to the menu */
|
|
|
|
_menu_bundles.push_back (b);
|
|
|
|
|
|
|
|
MenuList& citems = _menu.items ();
|
|
|
|
citems.push_back (MenuElemNoMnemonic (b->name (), sigc::bind (sigc::mem_fun (*this, &IOButton::bundle_chosen), b)));
|
|
|
|
}
|