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;
|
|
|
|
|
|
|
|
void
|
2022-10-20 11:23:37 -04:00
|
|
|
IOButtonBase::maybe_update (PropertyChange const& what_changed)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
2022-10-20 11:23:37 -04:00
|
|
|
if (what_changed.contains (ARDOUR::Properties::name)) {
|
|
|
|
update ();
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
static bool
|
2023-02-16 18:33:28 -05:00
|
|
|
exclusively_connected (std::shared_ptr<IO> dest_io, std::shared_ptr<IO> io, DataType dt, uint32_t tcnt, std::string const& name, ostringstream& label)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
2022-10-20 11:23:37 -04:00
|
|
|
/* check if IO is exclusively connected to a subset of this Route's ports */
|
|
|
|
uint32_t n = 0;
|
|
|
|
uint32_t cnt = 0;
|
|
|
|
std::set<uint32_t> pn;
|
|
|
|
|
2024-06-24 14:41:43 -04:00
|
|
|
std::shared_ptr<PortSet const> psa (dest_io->ports ());
|
|
|
|
std::shared_ptr<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) {
|
2022-10-20 11:23:37 -04:00
|
|
|
if (a->connected_to (b->name ())) {
|
|
|
|
++cnt;
|
|
|
|
pn.insert (n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (cnt != tcnt) {
|
|
|
|
/* IO has additional connections.
|
|
|
|
* No need to check other Routes/IOPs (they will produce
|
|
|
|
* the same result).
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
label << Gtkmm2ext::markup_escape_text (name) << " ";
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
bool first = true;
|
|
|
|
for (auto const& num : pn) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
label << "+";
|
|
|
|
}
|
|
|
|
label << dest_io->bundle ()->channel_name (num);
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
return true;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
DataType
|
2023-02-16 18:33:28 -05:00
|
|
|
IOButtonBase::guess_main_type (std::shared_ptr<IO> io)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
2022-10-20 11:23:37 -04: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). */
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* Find most likely type among connected ports */
|
|
|
|
DataType type = DataType::NIL; /* NIL is always last so least likely */
|
2024-06-24 14:41:43 -04:00
|
|
|
for (auto const& p : *io->ports ()) {
|
2022-10-20 11:23:37 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04: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;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* No port at all, return the most likely datatype by default */
|
|
|
|
return DataType::front ();
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* out 1 -> ardour:track_x/in 1
|
|
|
|
* out 2 -> ardour:track_x/in 2
|
|
|
|
* Display as: track_x
|
|
|
|
*
|
|
|
|
* Case 2b: Some outputs are connected, but all connections are to ardour:track_x
|
|
|
|
* out 1 -> ardour:track_x/in 1
|
|
|
|
* out 2 -> N/C
|
|
|
|
* Display as: track_x 1
|
|
|
|
*
|
|
|
|
* Case 3, 3a:
|
|
|
|
* same as 2, but for I/O Plugins (not routes)
|
|
|
|
*
|
|
|
|
* Case 4: 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
|
|
|
|
* this include internal one to many connections which show as "ardour"
|
|
|
|
*
|
|
|
|
* 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 |
|
|
|
|
* '-----------------------------------------------'
|
|
|
|
*/
|
2021-01-28 21:31:37 -05:00
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
IOButtonBase::set_label (IOButtonBase& self, ARDOUR::Session& session, std::shared_ptr<ARDOUR::Bundle>& bndl, std::shared_ptr<ARDOUR::IO> io)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
2022-10-20 11:23:37 -04:00
|
|
|
ostringstream tooltip;
|
|
|
|
ostringstream label;
|
|
|
|
bool have_label = false;
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
uint32_t total_connection_count = 0;
|
|
|
|
uint32_t typed_connection_count = 0;
|
|
|
|
bool each_typed_port_has_one_connection = true;
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
DataType dt = guess_main_type (io);
|
|
|
|
bool input = io->direction () == IO::Input;
|
|
|
|
string arrow = Gtkmm2ext::markup_escape_text (input ? " <- " : " -> ");
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04: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. */
|
|
|
|
if (input) {
|
|
|
|
tooltip << string_compose (_("<b>INPUT</b> to %1"),
|
|
|
|
Gtkmm2ext::markup_escape_text (io->name ()));
|
|
|
|
} else {
|
|
|
|
tooltip << string_compose (_("<b>OUTPUT</b> from %1"),
|
|
|
|
Gtkmm2ext::markup_escape_text (io->name ()));
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
vector<string> port_connections;
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2024-06-24 14:41:43 -04:00
|
|
|
for (auto const& port : *io->ports ()) {
|
2022-10-20 11:23:37 -04:00
|
|
|
port_connections.clear ();
|
|
|
|
port->get_connections (port_connections);
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
uint32_t port_connection_count = 0;
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
for (auto const& i : port_connections) {
|
|
|
|
++port_connection_count;
|
|
|
|
|
|
|
|
if (port_connection_count == 1) {
|
|
|
|
tooltip << endl
|
|
|
|
<< Gtkmm2ext::markup_escape_text (port->name ().substr (port->name ().find ("/") + 1));
|
|
|
|
tooltip << arrow;
|
|
|
|
} else {
|
|
|
|
tooltip << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltip << Gtkmm2ext::markup_escape_text (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (total_connection_count == 0) {
|
|
|
|
tooltip << endl
|
|
|
|
<< _("Disconnected");
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (typed_connection_count == 0) {
|
|
|
|
label << "-";
|
|
|
|
have_label = true;
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* Are all main-typed channels connected to the same route ? */
|
|
|
|
if (!have_label) {
|
2023-04-07 17:33:13 -04:00
|
|
|
std::shared_ptr<ARDOUR::RouteList const> routes = session.get_routes ();
|
2022-10-20 11:23:37 -04:00
|
|
|
for (auto const& route : *routes) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<IO> dest_io = input ? route->output () : route->input ();
|
2022-10-20 11:23:37 -04:00
|
|
|
if (io->bundle ()->connected_to (dest_io->bundle (), session.engine (), dt, true)) {
|
|
|
|
label << Gtkmm2ext::markup_escape_text (route->name ());
|
|
|
|
have_label = true;
|
|
|
|
route->PropertyChanged.connect (self._bundle_connections, invalidator (self), boost::bind (&IOButtonBase::maybe_update, &self, _1), gui_context ());
|
|
|
|
break;
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (!io->connected_to (dest_io)) {
|
|
|
|
continue;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (exclusively_connected (dest_io, io, dt, typed_connection_count, route->name (), label)) {
|
|
|
|
have_label = true;
|
|
|
|
route->PropertyChanged.connect (self._bundle_connections, invalidator (self), boost::bind (&IOButtonBase::maybe_update, &self, _1), gui_context ());
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
break;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* Are all main-typed channels connected to the same (user) bundle ? */
|
|
|
|
if (!have_label) {
|
2023-04-07 17:33:13 -04:00
|
|
|
std::shared_ptr<ARDOUR::BundleList const> bundles = session.bundles ();
|
|
|
|
std::shared_ptr<ARDOUR::Port> ap = std::dynamic_pointer_cast<ARDOUR::Port> (session.vkbd_output_port ());
|
|
|
|
std::string vkbd_portname = AudioEngine::instance ()->make_port_name_non_relative (ap->name ());
|
2022-10-20 11:23:37 -04:00
|
|
|
for (auto const& bundle : *bundles) {
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::dynamic_pointer_cast<UserBundle> (bundle) == 0) {
|
2022-10-20 11:23:37 -04:00
|
|
|
if (!bundle->offers_port (vkbd_portname)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (io->bundle ()->connected_to (bundle, session.engine (), dt, true)) {
|
|
|
|
label << Gtkmm2ext::markup_escape_text (bundle->name ());
|
|
|
|
have_label = true;
|
|
|
|
bndl = bundle;
|
|
|
|
break;
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* 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;
|
|
|
|
if (input) {
|
|
|
|
session.engine ().get_physical_inputs (dt, phys);
|
|
|
|
playorcapture = "capture_";
|
|
|
|
} else {
|
|
|
|
session.engine ().get_physical_outputs (dt, phys);
|
|
|
|
playorcapture = "playback_";
|
|
|
|
}
|
2024-06-24 14:41:43 -04:00
|
|
|
std::shared_ptr<PortSet> ps (io->ports ());
|
|
|
|
for (PortSet::iterator port = ps->begin (dt);
|
|
|
|
port != ps->end (dt);
|
2022-10-20 11:23:37 -04:00
|
|
|
++port) {
|
|
|
|
string pn = "";
|
|
|
|
for (auto const& s : phys) {
|
|
|
|
if (!port->connected_to (s)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pn = AudioEngine::instance ()->get_pretty_name_by_name (s);
|
|
|
|
if (pn.empty ()) {
|
|
|
|
string::size_type start = (s).find (playorcapture);
|
|
|
|
if (start != string::npos) {
|
|
|
|
pn = (s).substr (start + playorcapture.size ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (pn.empty ()) {
|
|
|
|
temp_label.str (""); /* erase the failed attempt */
|
|
|
|
break;
|
2021-03-24 20:54:48 -04:00
|
|
|
}
|
2024-06-24 14:41:43 -04:00
|
|
|
if (port != ps->begin (dt)) {
|
2022-10-20 11:23:37 -04:00
|
|
|
temp_label << "/";
|
2021-03-24 20:54:48 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
temp_label << pn;
|
2021-03-24 20:54:48 -04:00
|
|
|
}
|
2022-10-16 15:44:52 -04:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (!temp_label.str ().empty ()) {
|
|
|
|
label << temp_label.str ();
|
|
|
|
have_label = true;
|
2022-10-16 15:44:52 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
2021-03-24 20:54:48 -04:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* check for direct connections to I/O Plugins */
|
|
|
|
if (!have_label) {
|
|
|
|
for (auto const& iop : *session.io_plugs ()) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<IO> i = input ? iop->output () : iop->input ();
|
2022-10-20 11:23:37 -04:00
|
|
|
if (!io->connected_to (i)) {
|
2021-03-24 20:54:48 -04:00
|
|
|
continue;
|
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
|
|
|
|
/* direct 1:1 connection to IOP */
|
|
|
|
if (io->bundle ()->connected_to (i->bundle (), session.engine (), dt, true)) {
|
|
|
|
label << Gtkmm2ext::markup_escape_text (iop->io_name ());
|
|
|
|
have_label = true;
|
|
|
|
break;
|
2021-03-24 20:54:48 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
|
|
|
|
if (exclusively_connected (i, io, dt, typed_connection_count, iop->io_name (), label)) {
|
|
|
|
have_label = true;
|
|
|
|
}
|
|
|
|
break;
|
2021-03-24 20:54:48 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
2021-03-24 20:54:48 -04:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
// TODO check for internal connection (port_is_mine), do not simply
|
|
|
|
// print "ardour" as client name
|
|
|
|
|
|
|
|
/* 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) {
|
2024-06-24 14:41:43 -04:00
|
|
|
string maybe_client = "";
|
|
|
|
vector<string> connections;
|
|
|
|
std::shared_ptr<PortSet> ps (io->ports ());
|
|
|
|
for (PortSet::iterator port = ps->begin (dt);
|
|
|
|
port != ps->end (dt);
|
2022-10-20 11:23:37 -04:00
|
|
|
++port) {
|
|
|
|
port_connections.clear ();
|
|
|
|
port->get_connections (port_connections);
|
2023-06-09 13:15:58 -04:00
|
|
|
if (port_connections.empty ()) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
string connection = port_connections.front ();
|
|
|
|
|
|
|
|
vector<string>::iterator i = connections.begin ();
|
|
|
|
while (i != connections.end () && *i != connection) {
|
|
|
|
++i;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
if (i != connections.end ()) {
|
|
|
|
break; /* duplicate connection */
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
connections.push_back (connection);
|
2022-10-16 15:44:52 -04:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
connection = connection.substr (0, connection.find (":"));
|
|
|
|
|
|
|
|
if (maybe_client.empty ()) {
|
|
|
|
maybe_client = connection;
|
2022-10-16 15:44:52 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
if (maybe_client != connection) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (connections.size () == io->n_ports ().n (dt)) {
|
|
|
|
label << Gtkmm2ext::markup_escape_text (maybe_client);
|
|
|
|
have_label = true;
|
2022-10-16 15:44:52 -04:00
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* Odd configuration */
|
|
|
|
if (!have_label) {
|
|
|
|
label << "*" << total_connection_count << "*";
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (total_connection_count > typed_connection_count) {
|
2023-01-16 15:41:22 -05:00
|
|
|
label << u8"\u2295"; /* circled plus */
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
self.set_text (label.str ());
|
|
|
|
set_tooltip (&self, tooltip.str ());
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* ****************************************************************************/
|
|
|
|
|
|
|
|
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));
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
IOButton::set_route (std::shared_ptr<ARDOUR::Route> rt, RouteUI* routeui)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
2022-10-20 11:23:37 -04:00
|
|
|
_connections.drop_connections ();
|
|
|
|
_bundle_connections.drop_connections ();
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
_route = rt;
|
|
|
|
_route_ui = routeui;
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (!_route) {
|
|
|
|
_route_ui = NULL;
|
|
|
|
return;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
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 ());
|
|
|
|
/* 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 ());
|
|
|
|
|
|
|
|
update ();
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
IOButton::~IOButton ()
|
|
|
|
{
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<IO>
|
2022-10-20 11:23:37 -04:00
|
|
|
IOButton::io () const
|
2022-04-27 17:15:45 -04:00
|
|
|
{
|
2022-10-20 11:23:37 -04:00
|
|
|
return _input ? _route->input () : _route->output ();
|
|
|
|
}
|
2022-04-27 17:15:45 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Track>
|
2022-10-20 11:23:37 -04:00
|
|
|
IOButton::track () const
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
return std::dynamic_pointer_cast<Track> (_route);
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
2022-04-27 17:15:45 -04:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
void
|
|
|
|
IOButton::port_pretty_name_changed (std::string pn)
|
|
|
|
{
|
|
|
|
if (io ()->connected_to (pn)) {
|
|
|
|
update ();
|
2022-04-27 17:15:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
IOButton::port_connected_or_disconnected (std::weak_ptr<Port> wa, std::weak_ptr<Port> wb)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
2023-07-14 13:03:32 -04:00
|
|
|
if (!_route) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Port> a = wa.lock ();
|
|
|
|
std::shared_ptr<Port> b = wb.lock ();
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if ((a && io ()->has_port (a)) || (b && io ()->has_port (b))) {
|
|
|
|
update ();
|
|
|
|
}
|
|
|
|
}
|
2021-02-26 09:46:55 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
IOButton::bundle_chosen (std::shared_ptr<ARDOUR::Bundle> c)
|
2022-10-20 11:23:37 -04:00
|
|
|
{
|
|
|
|
if (_input) {
|
|
|
|
_route->input ()->connect_ports_to_bundle (c, true, this);
|
2021-01-28 21:31:37 -05:00
|
|
|
} else {
|
2022-10-20 11:23:37 -04:00
|
|
|
_route->output ()->connect_ports_to_bundle (c, true, true, this);
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
void
|
|
|
|
IOButton::disconnect ()
|
|
|
|
{
|
|
|
|
io ()->disconnect (this);
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
void
|
|
|
|
IOButton::button_resized (Gtk::Allocation& alloc)
|
|
|
|
{
|
|
|
|
set_layout_ellipsize_width (alloc.get_width () * PANGO_SCALE);
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
struct RouteCompareByName {
|
2023-02-16 18:33:28 -05:00
|
|
|
bool operator() (std::shared_ptr<Route> a, std::shared_ptr<Route> b)
|
2022-10-20 11:23:37 -04:00
|
|
|
{
|
|
|
|
return a->name ().compare (b->name ()) < 0;
|
|
|
|
}
|
|
|
|
};
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
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 ();
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
bool
|
|
|
|
IOButton::button_press (GdkEventButton* ev)
|
|
|
|
{
|
|
|
|
using namespace Gtk::Menu_Helpers;
|
|
|
|
|
|
|
|
if (!ARDOUR_UI_UTILS::engine_is_running () || !_route || !_route_ui) {
|
|
|
|
return true;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
MenuList& citems = _menu.items ();
|
|
|
|
_menu.set_name ("ArdourContextMenu");
|
|
|
|
citems.clear ();
|
|
|
|
|
|
|
|
if (_route->session ().actively_recording () && track () && track ()->rec_enable_control ()->get_value ()) {
|
|
|
|
return true;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
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;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
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 ();
|
2023-04-07 17:33:13 -04:00
|
|
|
ARDOUR::BundleList current = io ()->bundles_connected ();
|
|
|
|
std::shared_ptr<ARDOUR::BundleList const> b = _route->session ().bundles ();
|
2022-10-20 11:23:37 -04:00
|
|
|
|
|
|
|
if (_input) {
|
|
|
|
/* give user bundles first chance at being in the menu */
|
2023-04-07 17:33:13 -04:00
|
|
|
for (auto const& i : *b) {
|
|
|
|
if (std::dynamic_pointer_cast<UserBundle> (i)) {
|
|
|
|
maybe_add_bundle_to_menu (i, current);
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-07 17:33:13 -04:00
|
|
|
for (auto const& i : *b) {
|
|
|
|
if (std::dynamic_pointer_cast<UserBundle> (i) == 0) {
|
|
|
|
maybe_add_bundle_to_menu (i, current);
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
} else {
|
|
|
|
/* guess the user-intended main type of the route output */
|
|
|
|
DataType intended_type = guess_main_type (_input ? _route->input () : _route->output ());
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* try adding the master bus first */
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Route> master = _route->session ().master_out ();
|
2023-05-24 01:02:52 -04:00
|
|
|
if (master && !_route->is_monitor ()) {
|
2022-10-20 11:23:37 -04:00
|
|
|
maybe_add_bundle_to_menu (master->input ()->bundle (), current, intended_type);
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2023-04-07 17:33:13 -04:00
|
|
|
RouteList copy = *_route->session ().get_routes ();
|
2022-10-20 11:23:37 -04:00
|
|
|
copy.sort (RouteCompareByName ());
|
|
|
|
|
|
|
|
if (_input) {
|
|
|
|
/* other routes outputs */
|
|
|
|
for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
|
|
|
|
if ((*i)->is_foldbackbus ()) {
|
|
|
|
continue;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
if (_route->feeds (*i)) {
|
|
|
|
/* do not offer connections that would cause feedback */
|
|
|
|
continue;
|
2022-04-27 17:15:45 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
maybe_add_bundle_to_menu ((*i)->output ()->bundle (), current);
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -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-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
} else {
|
|
|
|
DataType intended_type = guess_main_type (_input ? _route->input () : _route->output ());
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* other routes inputs */
|
|
|
|
for (ARDOUR::RouteList::const_iterator i = copy.begin (); i != copy.end (); ++i) {
|
|
|
|
if ((*i)->is_foldbackbus () || _route->is_foldbackbus ()) {
|
2022-10-16 09:58:16 -04:00
|
|
|
continue;
|
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
if ((*i)->feeds (_route)) {
|
|
|
|
/* do not offer connections that would cause feedback */
|
|
|
|
continue;
|
2022-10-16 09:58:16 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
maybe_add_bundle_to_menu ((*i)->input ()->bundle (), current, intended_type);
|
|
|
|
}
|
2022-10-16 09:58:16 -04:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* then try adding user output bundles, often labeled/grouped physical inputs */
|
2023-04-07 17:33:13 -04:00
|
|
|
for (auto const& i : *b) {
|
|
|
|
if (std::dynamic_pointer_cast<UserBundle> (i)) {
|
|
|
|
maybe_add_bundle_to_menu (i, current, intended_type);
|
2022-10-16 09:58:16 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
2022-10-16 09:58:16 -04:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
/* then all other bundles, including physical outs or other software */
|
2023-04-07 17:33:13 -04:00
|
|
|
for (auto const& i : *b) {
|
|
|
|
if (std::dynamic_pointer_cast<UserBundle> (i) == 0) {
|
|
|
|
maybe_add_bundle_to_menu (i, current, intended_type);
|
2022-10-16 09:58:16 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
}
|
2022-10-16 09:58:16 -04:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
for (auto const& iop : *_route->session ().io_plugs ()) {
|
|
|
|
if (iop->is_pre ()) {
|
|
|
|
continue;
|
2022-10-16 09:58:16 -04:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
maybe_add_bundle_to_menu (iop->input ()->bundle (), current, intended_type);
|
2022-10-16 09:58:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
if (citems.size () > n_with_separator) {
|
|
|
|
citems.push_back (SeparatorElem ());
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
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;
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
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)));
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
2022-10-20 11:23:37 -04:00
|
|
|
if (need_separator) {
|
|
|
|
citems.push_back (SeparatorElem ());
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
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)));
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
Gtkmm2ext::anchored_menu_popup (&_menu, this, "", 1, ev->time);
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
void
|
|
|
|
IOButton::update ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::Bundle> bundle;
|
2022-10-20 11:23:37 -04:00
|
|
|
_bundle_connections.drop_connections ();
|
|
|
|
|
2023-07-14 13:03:32 -04:00
|
|
|
if (!_route) {
|
|
|
|
/* There may still be a signal queued before `set_route (0)` unsets the route
|
|
|
|
* and unsubscribes. invalidation only happens when the button is destroyed. */
|
|
|
|
set_text (_input ? _("Input") : _("Output"));
|
|
|
|
set_tooltip (this, "");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-20 11:23:37 -04:00
|
|
|
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 ());
|
|
|
|
}
|
2021-01-28 21:31:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
IOButton::maybe_add_bundle_to_menu (std::shared_ptr<Bundle> b, ARDOUR::BundleList const& /*current*/, ARDOUR::DataType type)
|
2021-01-28 21:31:37 -05:00
|
|
|
{
|
|
|
|
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 */
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Route> monitor = _route->session ().monitor_out ();
|
2021-01-28 21:31:37 -05:00
|
|
|
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 */
|
2023-02-16 18:33:28 -05:00
|
|
|
list<std::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)));
|
|
|
|
}
|