2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2002-2007 Paul Davis
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
#include <gtkmm/messagedialog.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
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/port_insert.h"
|
2007-10-10 14:37:13 -04:00
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/io.h"
|
|
|
|
#include "ardour/audioengine.h"
|
2007-10-12 08:13:11 -04:00
|
|
|
#include "ardour/track.h"
|
2007-10-12 10:49:07 -04:00
|
|
|
#include "ardour/audio_track.h"
|
|
|
|
#include "ardour/midi_track.h"
|
2010-03-16 11:33:04 -04:00
|
|
|
#include "ardour/mtdm.h"
|
2007-10-12 10:49:07 -04:00
|
|
|
#include "ardour/data_type.h"
|
2009-01-20 21:27:21 -05:00
|
|
|
#include "ardour/port.h"
|
2009-01-20 09:46:00 -05:00
|
|
|
#include "ardour/bundle.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"
|
|
|
|
#include "i18n.h"
|
|
|
|
|
2008-09-10 11:03:30 -04:00
|
|
|
using namespace ARDOUR;
|
|
|
|
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 ();
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
2010-06-29 22:59:13 -04:00
|
|
|
_ports[_other].gather (_session, type(), _find_inputs_for_io_outputs, false);
|
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
|
|
|
|
2010-11-26 13:28:42 -05:00
|
|
|
Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock());
|
|
|
|
|
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) {
|
|
|
|
|
2009-12-04 22:04:54 -05:00
|
|
|
Port* f = _session->engine().get_port_by_name (*i);
|
2009-01-20 09:46:00 -05:00
|
|
|
if (!f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s) {
|
2009-06-09 16:21:19 -04:00
|
|
|
_io->connect (f, *j, 0);
|
2009-01-20 09:46:00 -05:00
|
|
|
} else {
|
2009-06-09 16:21:19 -04:00
|
|
|
_io->disconnect (f, *j, 0);
|
2009-01-20 09:46:00 -05: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
|
|
|
{
|
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) {
|
|
|
|
|
2009-12-04 22:04:54 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-05-07 21:20:33 -04:00
|
|
|
string
|
|
|
|
IOSelector::disassociation_verb () const
|
|
|
|
{
|
|
|
|
return _("Disconnect");
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
|
|
|
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*/)
|
2009-07-21 21:28:31 -04:00
|
|
|
: _selector (this, session, io)
|
2007-10-10 14:37:13 -04:00
|
|
|
{
|
|
|
|
set_name ("IOSelectorWindow2");
|
2009-07-17 18:54:45 -04:00
|
|
|
set_title (_("I/O selector"));
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-07-26 22:10:27 -04:00
|
|
|
add (_selector);
|
2006-11-19 11:45:16 -05:00
|
|
|
|
2007-10-10 14:37:13 -04:00
|
|
|
set_position (Gtk::WIN_POS_MOUSE);
|
2006-11-19 11:45:16 -05: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);
|
|
|
|
hide ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 ();
|
|
|
|
pair<uint32_t, uint32_t> const pm_max = _selector.max_size ();
|
|
|
|
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)
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-30 10:18:15 -04:00
|
|
|
string title;
|
|
|
|
|
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
|
|
|
|