2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2005-2007 Doug McLain <doug@nostar.net>
|
|
|
|
* Copyright (C) 2005-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
|
|
|
|
* Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2008 Hans Baier <hansfbaier@googlemail.com>
|
|
|
|
* Copyright (C) 2013-2015 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.
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2012-05-24 02:09:29 -04:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2007-10-10 14:37:13 -04:00
|
|
|
#include <glibmm/objectbase.h>
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2005-09-25 16:33:00 -04:00
|
|
|
#include <gtkmm2ext/doi.h>
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2007-10-10 14:37:13 -04:00
|
|
|
#include "ardour/audioengine.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/bundle.h"
|
2007-10-12 10:49:07 -04:00
|
|
|
#include "ardour/data_type.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/io.h"
|
2009-01-20 21:27:21 -05:00
|
|
|
#include "ardour/port.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/session.h"
|
2008-09-10 11:03:30 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "io_selector.h"
|
2007-10-10 14:37:13 -04:00
|
|
|
#include "utils.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "gui_thread.h"
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
using namespace ARDOUR;
|
2014-06-25 15:27:37 -04:00
|
|
|
using namespace ARDOUR_UI_UTILS;
|
2008-09-10 11:03:30 -04:00
|
|
|
using namespace Gtk;
|
|
|
|
|
2009-12-04 22:04:54 -05:00
|
|
|
IOSelector::IOSelector (Gtk::Window* p, ARDOUR::Session* session, boost::shared_ptr<ARDOUR::IO> io)
|
2010-06-30 21:14:14 -04:00
|
|
|
: PortMatrix (p, session, DataType::NIL)
|
2008-12-14 04:35:23 -05:00
|
|
|
, _io (io)
|
2007-10-12 20:58:03 -04:00
|
|
|
{
|
2010-07-26 22:09:51 -04:00
|
|
|
setup_type ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
/* signal flow from 0 to 1 */
|
2009-06-09 16:21:19 -04:00
|
|
|
|
|
|
|
_find_inputs_for_io_outputs = (_io->direction() == IO::Output);
|
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
if (_find_inputs_for_io_outputs) {
|
|
|
|
_other = 1;
|
|
|
|
_ours = 0;
|
|
|
|
} else {
|
|
|
|
_other = 0;
|
|
|
|
_ours = 1;
|
|
|
|
}
|
|
|
|
|
2009-11-18 08:35:31 -05:00
|
|
|
_port_group.reset (new PortGroup (io->name()));
|
2009-01-30 10:08:09 -05:00
|
|
|
_ports[_ours].add_group (_port_group);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-07-26 22:09:51 -04:00
|
|
|
io->changed.connect (_io_connection, invalidator (*this), boost::bind (&IOSelector::io_changed_proxy, this), gui_context ());
|
|
|
|
|
2009-02-08 22:18:10 -05:00
|
|
|
setup_all_ports ();
|
2009-11-18 08:35:31 -05:00
|
|
|
init ();
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
2008-12-14 04:35:23 -05:00
|
|
|
|
2010-07-26 22:09:51 -04:00
|
|
|
void
|
|
|
|
IOSelector::setup_type ()
|
|
|
|
{
|
|
|
|
/* set type according to what's in the IO */
|
|
|
|
|
|
|
|
int N = 0;
|
|
|
|
DataType type_with_ports = DataType::NIL;
|
|
|
|
for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
|
|
|
|
if (_io->ports().num_ports (*i)) {
|
|
|
|
type_with_ports = *i;
|
|
|
|
++N;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (N <= 1) {
|
|
|
|
set_type (type_with_ports);
|
|
|
|
} else {
|
|
|
|
set_type (DataType::NIL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOSelector::io_changed_proxy ()
|
|
|
|
{
|
|
|
|
/* The IO's changed signal is emitted from code that holds its route's processor lock,
|
|
|
|
so we can't call setup_all_ports (which results in a call to Route::foreach_processor)
|
|
|
|
without a deadlock unless we break things up with this idle handler.
|
|
|
|
*/
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-07-26 22:09:51 -04:00
|
|
|
Glib::signal_idle().connect_once (sigc::mem_fun (*this, &IOSelector::io_changed));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IOSelector::io_changed ()
|
|
|
|
{
|
|
|
|
setup_type ();
|
|
|
|
setup_all_ports ();
|
|
|
|
}
|
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
void
|
2009-02-08 22:18:10 -05:00
|
|
|
IOSelector::setup_ports (int dim)
|
2009-01-20 09:46:00 -05:00
|
|
|
{
|
2009-12-04 22:04:54 -05:00
|
|
|
if (!_session) {
|
|
|
|
return;
|
|
|
|
}
|
2010-07-26 22:09:51 -04:00
|
|
|
|
2009-02-08 22:18:10 -05:00
|
|
|
_ports[dim].suspend_signals ();
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-02-08 22:18:10 -05:00
|
|
|
if (dim == _other) {
|
|
|
|
|
2012-05-20 17:56:28 -04:00
|
|
|
_ports[_other].gather (_session, type(), _find_inputs_for_io_outputs, false, show_only_bundles ());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-29 09:34:35 -04:00
|
|
|
} else {
|
2008-12-14 04:35:23 -05:00
|
|
|
|
2009-02-08 22:18:10 -05:00
|
|
|
_port_group->clear ();
|
2009-07-19 20:22:09 -04:00
|
|
|
_port_group->add_bundle (_io->bundle (), _io);
|
2007-10-12 20:58:03 -04:00
|
|
|
}
|
2009-01-12 20:15:19 -05:00
|
|
|
|
2009-02-08 22:18:10 -05:00
|
|
|
_ports[dim].resume_signals ();
|
2007-10-10 14:37:13 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2007-10-10 14:37:13 -04:00
|
|
|
void
|
2009-01-30 10:08:09 -05:00
|
|
|
IOSelector::set_state (ARDOUR::BundleChannel c[2], bool s)
|
2007-10-10 14:37:13 -04:00
|
|
|
{
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel);
|
|
|
|
ARDOUR::Bundle::PortList const & other_ports = c[_other].bundle->channel_ports (c[_other].channel);
|
2009-01-20 09:46:00 -05:00
|
|
|
|
|
|
|
for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
|
|
|
|
for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
|
|
|
|
|
2011-10-28 13:04:09 -04:00
|
|
|
boost::shared_ptr<Port> f = _session->engine().get_port_by_name (*i);
|
2009-01-20 09:46:00 -05:00
|
|
|
if (!f) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (s) {
|
2011-11-09 17:26:16 -05:00
|
|
|
if (!f->connected_to (*j)) {
|
|
|
|
_io->connect (f, *j, 0);
|
|
|
|
}
|
2017-07-01 12:42:24 -04:00
|
|
|
} else {
|
2011-11-09 17:26:16 -05:00
|
|
|
if (f->connected_to (*j)) {
|
|
|
|
_io->disconnect (f, *j, 0);
|
|
|
|
}
|
2017-07-01 12:42:24 -04:00
|
|
|
}
|
2008-10-07 18:24:00 -04:00
|
|
|
}
|
|
|
|
}
|
2007-10-10 14:37:13 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
PortMatrixNode::State
|
2009-01-30 10:08:09 -05:00
|
|
|
IOSelector::get_state (ARDOUR::BundleChannel c[2]) const
|
2007-10-10 14:37:13 -04:00
|
|
|
{
|
2011-08-19 10:45:08 -04:00
|
|
|
if (c[0].bundle->nchannels() == ChanCount::ZERO || c[1].bundle->nchannels() == ChanCount::ZERO) {
|
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
|
|
|
}
|
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
ARDOUR::Bundle::PortList const & our_ports = c[_ours].bundle->channel_ports (c[_ours].channel);
|
|
|
|
ARDOUR::Bundle::PortList const & other_ports = c[_other].bundle->channel_ports (c[_other].channel);
|
2007-10-31 14:24:43 -04:00
|
|
|
|
2010-08-16 15:58:34 -04:00
|
|
|
if (!_session || our_ports.empty() || other_ports.empty()) {
|
2009-02-14 15:17:45 -05:00
|
|
|
/* we're looking at a bundle with no parts associated with this channel,
|
|
|
|
so nothing to connect */
|
2009-11-16 17:32:58 -05:00
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
2009-02-14 15:17:45 -05:00
|
|
|
}
|
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
|
|
|
|
for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
|
|
|
|
|
2011-10-28 13:04:09 -04:00
|
|
|
boost::shared_ptr<Port> f = _session->engine().get_port_by_name (*i);
|
2009-01-20 09:46:00 -05:00
|
|
|
|
2009-01-21 12:44:41 -05:00
|
|
|
/* since we are talking about an IO, our ports should all have an associated Port *,
|
|
|
|
so the above call should never fail */
|
|
|
|
assert (f);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-01-20 09:46:00 -05:00
|
|
|
if (!f->connected_to (*j)) {
|
|
|
|
/* if any one thing is not connected, all bets are off */
|
2009-05-03 10:31:42 -04:00
|
|
|
return PortMatrixNode::NOT_ASSOCIATED;
|
2009-01-20 09:46:00 -05:00
|
|
|
}
|
|
|
|
}
|
2007-10-31 14:24:43 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-05-03 10:31:42 -04:00
|
|
|
return PortMatrixNode::ASSOCIATED;
|
2007-10-10 14:37:13 -04:00
|
|
|
}
|
2006-11-19 11:45:16 -05:00
|
|
|
|
2007-10-19 09:30:07 -04:00
|
|
|
uint32_t
|
2009-01-30 10:08:09 -05:00
|
|
|
IOSelector::n_io_ports () const
|
2007-10-10 14:37:13 -04:00
|
|
|
{
|
2009-01-30 10:08:09 -05:00
|
|
|
if (!_find_inputs_for_io_outputs) {
|
2009-06-09 16:21:19 -04:00
|
|
|
return _io->n_ports().get (_io->default_type());
|
2007-10-19 09:30:07 -04:00
|
|
|
} else {
|
2009-06-09 16:21:19 -04:00
|
|
|
return _io->n_ports().get (_io->default_type());
|
2007-10-12 08:13:11 -04:00
|
|
|
}
|
2007-10-12 20:58:03 -04:00
|
|
|
}
|
2006-11-19 11:45:16 -05:00
|
|
|
|
2009-02-08 22:18:10 -05:00
|
|
|
bool
|
|
|
|
IOSelector::list_is_global (int dim) const
|
|
|
|
{
|
|
|
|
return (dim == _other);
|
|
|
|
}
|
|
|
|
|
2012-05-24 02:09:29 -04:00
|
|
|
std::string
|
2010-05-07 21:20:33 -04:00
|
|
|
IOSelector::disassociation_verb () const
|
|
|
|
{
|
|
|
|
return _("Disconnect");
|
|
|
|
}
|
|
|
|
|
2012-05-24 02:09:29 -04:00
|
|
|
std::string
|
2010-05-07 21:20:33 -04:00
|
|
|
IOSelector::channel_noun () const
|
|
|
|
{
|
|
|
|
return _("port");
|
|
|
|
}
|
|
|
|
|
2009-12-04 22:04:54 -05:00
|
|
|
IOSelectorWindow::IOSelectorWindow (ARDOUR::Session* session, boost::shared_ptr<ARDOUR::IO> io, bool /*can_cancel*/)
|
2011-11-18 16:56:01 -05:00
|
|
|
: ArdourWindow (_("I/O selector"))
|
|
|
|
, _selector (this, session, io)
|
2007-10-10 14:37:13 -04:00
|
|
|
{
|
|
|
|
set_name ("IOSelectorWindow2");
|
2006-11-19 11:45:16 -05:00
|
|
|
|
2011-11-18 16:56:01 -05:00
|
|
|
add (_selector);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2008-09-30 10:18:15 -04:00
|
|
|
io_name_changed (this);
|
2008-10-01 05:18:30 -04:00
|
|
|
|
2007-10-10 14:37:13 -04:00
|
|
|
show_all ();
|
2006-11-19 11:45:16 -05:00
|
|
|
|
2009-12-11 18:29:48 -05:00
|
|
|
signal_delete_event().connect (sigc::mem_fun (*this, &IOSelectorWindow::wm_delete));
|
2007-10-10 14:37:13 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-09-12 22:03:04 -04:00
|
|
|
bool
|
|
|
|
IOSelectorWindow::wm_delete (GdkEventAny* /*event*/)
|
|
|
|
{
|
|
|
|
_selector.Finished (IOSelector::Accepted);
|
2013-07-07 16:24:15 -04:00
|
|
|
return false;
|
2009-09-12 22:03:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-10 14:37:13 -04:00
|
|
|
void
|
|
|
|
IOSelectorWindow::on_map ()
|
|
|
|
{
|
2009-02-08 22:18:10 -05:00
|
|
|
_selector.setup_all_ports ();
|
2007-10-10 14:37:13 -04:00
|
|
|
Window::on_map ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2009-08-29 16:48:11 -04:00
|
|
|
void
|
|
|
|
IOSelectorWindow::on_show ()
|
|
|
|
{
|
|
|
|
Gtk::Window::on_show ();
|
2012-05-24 02:09:29 -04:00
|
|
|
std::pair<uint32_t, uint32_t> const pm_max = _selector.max_size ();
|
2009-08-29 16:48:11 -04:00
|
|
|
resize_window_to_proportion_of_monitor (this, pm_max.first, pm_max.second);
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2009-08-29 16:48:11 -04:00
|
|
|
|
2008-09-30 10:18:15 -04:00
|
|
|
void
|
2010-11-13 00:14:48 -05:00
|
|
|
IOSelectorWindow::io_name_changed (void*)
|
2008-09-30 10:18:15 -04:00
|
|
|
{
|
2009-12-11 18:29:48 -05:00
|
|
|
ENSURE_GUI_THREAD (*this, &IOSelectorWindow::io_name_changed, src)
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-05-24 02:09:29 -04:00
|
|
|
std::string title;
|
2008-09-30 10:18:15 -04:00
|
|
|
|
2009-01-30 10:08:09 -05:00
|
|
|
if (!_selector.find_inputs_for_io_outputs()) {
|
2008-09-30 10:18:15 -04:00
|
|
|
title = string_compose(_("%1 input"), _selector.io()->name());
|
|
|
|
} else {
|
|
|
|
title = string_compose(_("%1 output"), _selector.io()->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
set_title (title);
|
|
|
|
}
|
2007-10-10 14:37:13 -04:00
|
|
|
|