Clean up handling of add/remove/rename channels in the port matrix. Hence make it possible to do these things for any bundle (give or take). Clean up port matrix context menu.

git-svn-id: svn://localhost/ardour2/branches/3.0@5393 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2009-07-20 00:22:09 +00:00
parent de58b257ae
commit 23f86529fd
11 changed files with 285 additions and 193 deletions

View file

@ -30,8 +30,11 @@
#include "bundle_manager.h" #include "bundle_manager.h"
#include "i18n.h" #include "i18n.h"
using namespace std;
using namespace ARDOUR;
BundleEditorMatrix::BundleEditorMatrix ( BundleEditorMatrix::BundleEditorMatrix (
ARDOUR::Session& session, boost::shared_ptr<ARDOUR::Bundle> bundle Session& session, boost::shared_ptr<Bundle> bundle
) )
: PortMatrix (session, bundle->type()), : PortMatrix (session, bundle->type()),
_bundle (bundle) _bundle (bundle)
@ -55,10 +58,10 @@ BundleEditorMatrix::setup_ports (int dim)
} }
void void
BundleEditorMatrix::set_state (ARDOUR::BundleChannel c[2], bool s) BundleEditorMatrix::set_state (BundleChannel c[2], bool s)
{ {
ARDOUR::Bundle::PortList const& pl = c[OTHER].bundle->channel_ports (c[OTHER].channel); Bundle::PortList const& pl = c[OTHER].bundle->channel_ports (c[OTHER].channel);
for (ARDOUR::Bundle::PortList::const_iterator i = pl.begin(); i != pl.end(); ++i) { for (Bundle::PortList::const_iterator i = pl.begin(); i != pl.end(); ++i) {
if (s) { if (s) {
c[OURS].bundle->add_port_to_channel (c[OURS].channel, *i); c[OURS].bundle->add_port_to_channel (c[OURS].channel, *i);
} else { } else {
@ -68,10 +71,10 @@ BundleEditorMatrix::set_state (ARDOUR::BundleChannel c[2], bool s)
} }
PortMatrixNode::State PortMatrixNode::State
BundleEditorMatrix::get_state (ARDOUR::BundleChannel c[2]) const BundleEditorMatrix::get_state (BundleChannel c[2]) const
{ {
ARDOUR::Bundle::PortList const& pl = c[OTHER].bundle->channel_ports (c[OTHER].channel); Bundle::PortList const& pl = c[OTHER].bundle->channel_ports (c[OTHER].channel);
for (ARDOUR::Bundle::PortList::const_iterator i = pl.begin(); i != pl.end(); ++i) { for (Bundle::PortList::const_iterator i = pl.begin(); i != pl.end(); ++i) {
if (!c[OURS].bundle->port_attached_to_channel (c[OURS].channel, *i)) { if (!c[OURS].bundle->port_attached_to_channel (c[OURS].channel, *i)) {
return PortMatrixNode::NOT_ASSOCIATED; return PortMatrixNode::NOT_ASSOCIATED;
} }
@ -80,15 +83,21 @@ BundleEditorMatrix::get_state (ARDOUR::BundleChannel c[2]) const
return PortMatrixNode::ASSOCIATED; return PortMatrixNode::ASSOCIATED;
} }
std::string bool
BundleEditorMatrix::add_channel_name () const BundleEditorMatrix::can_add_channel (boost::shared_ptr<Bundle> b) const
{ {
return _bundle->name (); if (b == _bundle) {
return true;
}
return PortMatrix::can_add_channel (b);
} }
void void
BundleEditorMatrix::add_channel () BundleEditorMatrix::add_channel (boost::shared_ptr<Bundle> b)
{ {
if (b == _bundle) {
NameChannelDialog d; NameChannelDialog d;
d.set_position (Gtk::WIN_POS_MOUSE); d.set_position (Gtk::WIN_POS_MOUSE);
@ -98,17 +107,43 @@ BundleEditorMatrix::add_channel ()
_bundle->add_channel (d.get_name()); _bundle->add_channel (d.get_name());
setup_ports (OURS); setup_ports (OURS);
} else {
PortMatrix::add_channel (b);
}
}
bool
BundleEditorMatrix::can_remove_channels (boost::shared_ptr<Bundle> b) const
{
if (b == _bundle) {
return true;
}
return PortMatrix::can_remove_channels (b);
} }
void void
BundleEditorMatrix::remove_channel (ARDOUR::BundleChannel bc) BundleEditorMatrix::remove_channel (BundleChannel bc)
{ {
bc.bundle->remove_channel (bc.channel); bc.bundle->remove_channel (bc.channel);
setup_ports (OURS); setup_ports (OURS);
} }
bool
BundleEditorMatrix::can_rename_channels (boost::shared_ptr<Bundle> b) const
{
if (b == _bundle) {
return true;
}
return PortMatrix::can_rename_channels (b);
}
void void
BundleEditorMatrix::rename_channel (ARDOUR::BundleChannel bc) BundleEditorMatrix::rename_channel (BundleChannel bc)
{ {
NameChannelDialog d (bc.bundle, bc.channel); NameChannelDialog d (bc.bundle, bc.channel);
d.set_position (Gtk::WIN_POS_MOUSE); d.set_position (Gtk::WIN_POS_MOUSE);
@ -126,7 +161,7 @@ BundleEditorMatrix::list_is_global (int dim) const
return (dim == OTHER); return (dim == OTHER);
} }
BundleEditor::BundleEditor (ARDOUR::Session& session, boost::shared_ptr<ARDOUR::UserBundle> bundle, bool add) BundleEditor::BundleEditor (Session& session, boost::shared_ptr<UserBundle> bundle, bool add)
: ArdourDialog (_("Edit Bundle")), _matrix (session, bundle), _bundle (bundle) : ArdourDialog (_("Edit Bundle")), _matrix (session, bundle), _bundle (bundle)
{ {
Gtk::Table* t = new Gtk::Table (3, 2); Gtk::Table* t = new Gtk::Table (3, 2);
@ -170,10 +205,10 @@ BundleEditor::BundleEditor (ARDOUR::Session& session, boost::shared_ptr<ARDOUR::
_type.append_text (_("MIDI")); _type.append_text (_("MIDI"));
switch (bundle->type ()) { switch (bundle->type ()) {
case ARDOUR::DataType::AUDIO: case DataType::AUDIO:
_type.set_active_text (_("Audio")); _type.set_active_text (_("Audio"));
break; break;
case ARDOUR::DataType::MIDI: case DataType::MIDI:
_type.set_active_text (_("MIDI")); _type.set_active_text (_("MIDI"));
break; break;
} }
@ -212,8 +247,8 @@ BundleEditor::type_changed ()
{ {
_bundle->remove_ports_from_channels (); _bundle->remove_ports_from_channels ();
ARDOUR::DataType const t = _type.get_active_text() == _("Audio") ? DataType const t = _type.get_active_text() == _("Audio") ?
ARDOUR::DataType::AUDIO : ARDOUR::DataType::MIDI; DataType::AUDIO : DataType::MIDI;
_bundle->set_type (t); _bundle->set_type (t);
_matrix.set_type (t); _matrix.set_type (t);
@ -227,7 +262,7 @@ BundleEditor::on_map ()
} }
BundleManager::BundleManager (ARDOUR::Session& session) BundleManager::BundleManager (Session& session)
: ArdourDialog (_("Bundle manager")), _session (session), edit_button (_("Edit")), delete_button (_("Delete")) : ArdourDialog (_("Bundle manager")), _session (session), edit_button (_("Edit")), delete_button (_("Delete"))
{ {
_list_model = Gtk::ListStore::create (_list_model_columns); _list_model = Gtk::ListStore::create (_list_model_columns);
@ -235,8 +270,8 @@ BundleManager::BundleManager (ARDOUR::Session& session)
_tree_view.append_column (_("Name"), _list_model_columns.name); _tree_view.append_column (_("Name"), _list_model_columns.name);
_tree_view.set_headers_visible (false); _tree_view.set_headers_visible (false);
boost::shared_ptr<ARDOUR::BundleList> bundles = _session.bundles (); boost::shared_ptr<BundleList> bundles = _session.bundles ();
for (ARDOUR::BundleList::iterator i = bundles->begin(); i != bundles->end(); ++i) { for (BundleList::iterator i = bundles->begin(); i != bundles->end(); ++i) {
add_bundle (*i); add_bundle (*i);
} }
@ -286,7 +321,7 @@ BundleManager::set_button_sensitivity ()
void void
BundleManager::new_clicked () BundleManager::new_clicked ()
{ {
boost::shared_ptr<ARDOUR::UserBundle> b (new ARDOUR::UserBundle ("")); boost::shared_ptr<UserBundle> b (new UserBundle (""));
/* Start off with a single channel */ /* Start off with a single channel */
b->add_channel (""); b->add_channel ("");
@ -304,7 +339,7 @@ BundleManager::edit_clicked ()
{ {
Gtk::TreeModel::iterator i = _tree_view.get_selection()->get_selected(); Gtk::TreeModel::iterator i = _tree_view.get_selection()->get_selected();
if (i) { if (i) {
boost::shared_ptr<ARDOUR::UserBundle> b = (*i)[_list_model_columns.bundle]; boost::shared_ptr<UserBundle> b = (*i)[_list_model_columns.bundle];
BundleEditor e (_session, b, false); BundleEditor e (_session, b, false);
if (e.run () == Gtk::RESPONSE_ACCEPT) { if (e.run () == Gtk::RESPONSE_ACCEPT) {
_session.set_dirty (); _session.set_dirty ();
@ -317,16 +352,16 @@ BundleManager::delete_clicked ()
{ {
Gtk::TreeModel::iterator i = _tree_view.get_selection()->get_selected(); Gtk::TreeModel::iterator i = _tree_view.get_selection()->get_selected();
if (i) { if (i) {
boost::shared_ptr<ARDOUR::UserBundle> b = (*i)[_list_model_columns.bundle]; boost::shared_ptr<UserBundle> b = (*i)[_list_model_columns.bundle];
_session.remove_bundle (b); _session.remove_bundle (b);
_list_model->erase (i); _list_model->erase (i);
} }
} }
void void
BundleManager::add_bundle (boost::shared_ptr<ARDOUR::Bundle> b) BundleManager::add_bundle (boost::shared_ptr<Bundle> b)
{ {
boost::shared_ptr<ARDOUR::UserBundle> u = boost::dynamic_pointer_cast<ARDOUR::UserBundle> (b); boost::shared_ptr<UserBundle> u = boost::dynamic_pointer_cast<UserBundle> (b);
if (u == 0) { if (u == 0) {
return; return;
} }
@ -339,15 +374,15 @@ BundleManager::add_bundle (boost::shared_ptr<ARDOUR::Bundle> b)
} }
void void
BundleManager::bundle_changed (ARDOUR::Bundle::Change c, boost::shared_ptr<ARDOUR::UserBundle> b) BundleManager::bundle_changed (Bundle::Change c, boost::shared_ptr<UserBundle> b)
{ {
if ((c & ARDOUR::Bundle::NameChanged) == 0) { if ((c & Bundle::NameChanged) == 0) {
return; return;
} }
Gtk::TreeModel::iterator i = _list_model->children().begin (); Gtk::TreeModel::iterator i = _list_model->children().begin ();
while (i != _list_model->children().end()) { while (i != _list_model->children().end()) {
boost::shared_ptr<ARDOUR::UserBundle> t = (*i)[_list_model_columns.bundle]; boost::shared_ptr<UserBundle> t = (*i)[_list_model_columns.bundle];
if (t == b) { if (t == b) {
break; break;
} }
@ -367,7 +402,7 @@ NameChannelDialog::NameChannelDialog ()
setup (); setup ();
} }
NameChannelDialog::NameChannelDialog (boost::shared_ptr<ARDOUR::Bundle> b, uint32_t c) NameChannelDialog::NameChannelDialog (boost::shared_ptr<Bundle> b, uint32_t c)
: ArdourDialog (_("Rename channel")), : ArdourDialog (_("Rename channel")),
_bundle (b), _bundle (b),
_channel (c), _channel (c),
@ -398,7 +433,7 @@ NameChannelDialog::setup ()
set_default_response (Gtk::RESPONSE_ACCEPT); set_default_response (Gtk::RESPONSE_ACCEPT);
} }
std::string string
NameChannelDialog::get_name () const NameChannelDialog::get_name () const
{ {
return _name.get_text (); return _name.get_text ();

View file

@ -39,15 +39,13 @@ class BundleEditorMatrix : public PortMatrix
void set_state (ARDOUR::BundleChannel c[2], bool s); void set_state (ARDOUR::BundleChannel c[2], bool s);
PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const; PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const;
std::string add_channel_name () const;
void add_channel (); bool can_add_channel (boost::shared_ptr<ARDOUR::Bundle>) const;
bool can_remove_channels (int d) const {
return d == OURS; void add_channel (boost::shared_ptr<ARDOUR::Bundle>);
} bool can_remove_channels (boost::shared_ptr<ARDOUR::Bundle>) const;
void remove_channel (ARDOUR::BundleChannel); void remove_channel (ARDOUR::BundleChannel);
bool can_rename_channels (int d) const { bool can_rename_channels (boost::shared_ptr<ARDOUR::Bundle>) const;
return d == OURS;
}
void rename_channel (ARDOUR::BundleChannel); void rename_channel (ARDOUR::BundleChannel);
void setup_ports (int); void setup_ports (int);
bool list_is_global (int) const; bool list_is_global (int) const;

View file

@ -36,18 +36,14 @@ public:
void set_state (ARDOUR::BundleChannel c[2], bool); void set_state (ARDOUR::BundleChannel c[2], bool);
PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const; PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const;
bool can_remove_channels (int d) const {
return false;
}
void remove_channel (ARDOUR::BundleChannel) {}
bool can_rename_channels (int d) const {
return false;
}
std::string disassociation_verb () const { std::string disassociation_verb () const {
return _("Disconnect"); return _("Disconnect");
} }
std::string channel_noun () const {
return _("port");
}
bool list_is_global (int) const { bool list_is_global (int) const {
return true; return true;
} }

View file

@ -75,7 +75,7 @@ IOSelector::setup_ports (int dim)
} else { } else {
_port_group->clear (); _port_group->clear ();
_port_group->add_bundle (_io->bundle ()); _port_group->add_bundle (_io->bundle (), _io);
} }
_ports[dim].resume_signals (); _ports[dim].resume_signals ();
@ -145,39 +145,6 @@ IOSelector::n_io_ports () const
} }
} }
string
IOSelector::add_channel_name () const
{
return _io->name ();
}
void
IOSelector::add_channel ()
{
// The IO selector only works for single typed IOs
const ARDOUR::DataType t = _io->default_type ();
try {
_io->add_port ("", this);
}
catch (AudioEngine::PortRegistrationFailure& err) {
MessageDialog msg (_("There are no more JACK ports available."));
msg.run ();
}
}
void
IOSelector::remove_channel (ARDOUR::BundleChannel bc)
{
Port* f = _session.engine().get_port_by_name (bc.bundle->channel_ports(bc.channel)[0]);
if (!f) {
return;
}
_io->remove_port (f, this);
}
bool bool
IOSelector::list_is_global (int dim) const IOSelector::list_is_global (int dim) const
{ {

View file

@ -36,19 +36,6 @@ class IOSelector : public PortMatrix
void set_state (ARDOUR::BundleChannel c[2], bool); void set_state (ARDOUR::BundleChannel c[2], bool);
PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const; PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const;
std::string add_channel_name () const;
void add_channel ();
bool can_remove_channels (int d) const {
return d == _ours;
}
void remove_channel (ARDOUR::BundleChannel);
bool can_rename_channels (int d) const {
return false;
}
std::string disassociation_verb () const { std::string disassociation_verb () const {
return _("Disconnect"); return _("Disconnect");
} }

View file

@ -50,16 +50,23 @@ PortGroup::PortGroup (std::string const & n)
} }
void
PortGroup::add_bundle (boost::shared_ptr<Bundle> b)
{
add_bundle (b, boost::shared_ptr<IO> ());
}
/** Add a bundle to a group. /** Add a bundle to a group.
* @param b Bundle. * @param b Bundle.
*/ */
void void
PortGroup::add_bundle (boost::shared_ptr<Bundle> b) PortGroup::add_bundle (boost::shared_ptr<Bundle> b, boost::shared_ptr<IO> io)
{ {
assert (b.get()); assert (b.get());
BundleRecord r; BundleRecord r;
r.bundle = b; r.bundle = b;
r.io = io;
r.has_colour = false; r.has_colour = false;
r.changed_connection = b->Changed.connect (sigc::mem_fun (*this, &PortGroup::bundle_changed)); r.changed_connection = b->Changed.connect (sigc::mem_fun (*this, &PortGroup::bundle_changed));
@ -73,12 +80,13 @@ PortGroup::add_bundle (boost::shared_ptr<Bundle> b)
* @param c Colour to represent the group with. * @param c Colour to represent the group with.
*/ */
void void
PortGroup::add_bundle (boost::shared_ptr<Bundle> b, Gdk::Color c) PortGroup::add_bundle (boost::shared_ptr<Bundle> b, boost::shared_ptr<IO> io, Gdk::Color c)
{ {
assert (b.get()); assert (b.get());
BundleRecord r; BundleRecord r;
r.bundle = b; r.bundle = b;
r.io = io;
r.colour = c; r.colour = c;
r.has_colour = true; r.has_colour = true;
r.changed_connection = b->Changed.connect (sigc::mem_fun (*this, &PortGroup::bundle_changed)); r.changed_connection = b->Changed.connect (sigc::mem_fun (*this, &PortGroup::bundle_changed));
@ -157,6 +165,22 @@ PortGroup::total_channels () const
return n; return n;
} }
boost::shared_ptr<IO>
PortGroup::io_from_bundle (boost::shared_ptr<ARDOUR::Bundle> b) const
{
BundleList::const_iterator i = _bundles.begin ();
while (i != _bundles.end() && i->bundle != b) {
++i;
}
if (i == _bundles.end()) {
return boost::shared_ptr<IO> ();
}
return i->io;
}
/** PortGroupList constructor. /** PortGroupList constructor.
*/ */
PortGroupList::PortGroupList () PortGroupList::PortGroupList ()
@ -250,9 +274,9 @@ PortGroupList::gather (ARDOUR::Session& session, bool inputs)
TimeAxisView* tv = PublicEditor::instance().axis_view_from_route (i->get()); TimeAxisView* tv = PublicEditor::instance().axis_view_from_route (i->get());
if (tv) { if (tv) {
g->add_bundle (rb, tv->color ()); g->add_bundle (rb, io, tv->color ());
} else { } else {
g->add_bundle (rb); g->add_bundle (rb, io);
} }
} }
} }
@ -493,6 +517,22 @@ PortGroupList::resume_signals ()
_signals_suspended = false; _signals_suspended = false;
} }
boost::shared_ptr<IO>
PortGroupList::io_from_bundle (boost::shared_ptr<ARDOUR::Bundle> b) const
{
List::const_iterator i = _groups.begin ();
while (i != _groups.end()) {
boost::shared_ptr<IO> io = (*i)->io_from_bundle (b);
if (io) {
return io;
}
++i;
}
return boost::shared_ptr<IO> ();
}
RouteBundle::RouteBundle (boost::shared_ptr<Bundle> r) RouteBundle::RouteBundle (boost::shared_ptr<Bundle> r)
: _route (r) : _route (r)
{ {

View file

@ -50,11 +50,13 @@ public:
PortGroup (std::string const & n); PortGroup (std::string const & n);
void add_bundle (boost::shared_ptr<ARDOUR::Bundle>); void add_bundle (boost::shared_ptr<ARDOUR::Bundle>);
void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, Gdk::Color); void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO> io);
void add_bundle (boost::shared_ptr<ARDOUR::Bundle>, boost::shared_ptr<ARDOUR::IO>, Gdk::Color);
void remove_bundle (boost::shared_ptr<ARDOUR::Bundle>); void remove_bundle (boost::shared_ptr<ARDOUR::Bundle>);
boost::shared_ptr<ARDOUR::Bundle> only_bundle (); boost::shared_ptr<ARDOUR::Bundle> only_bundle ();
void clear (); void clear ();
uint32_t total_channels () const; uint32_t total_channels () const;
boost::shared_ptr<ARDOUR::IO> io_from_bundle (boost::shared_ptr<ARDOUR::Bundle>) const;
std::string name; ///< name for the group std::string name; ///< name for the group
@ -74,6 +76,7 @@ public:
struct BundleRecord { struct BundleRecord {
boost::shared_ptr<ARDOUR::Bundle> bundle; boost::shared_ptr<ARDOUR::Bundle> bundle;
boost::shared_ptr<ARDOUR::IO> io;
Gdk::Color colour; Gdk::Color colour;
bool has_colour; bool has_colour;
sigc::connection changed_connection; sigc::connection changed_connection;
@ -110,6 +113,7 @@ class PortGroupList : public sigc::trackable
uint32_t size () const { uint32_t size () const {
return _groups.size(); return _groups.size();
} }
boost::shared_ptr<ARDOUR::IO> io_from_bundle (boost::shared_ptr<ARDOUR::Bundle>) const;
void suspend_signals (); void suspend_signals ();
void resume_signals (); void resume_signals ();

View file

@ -36,12 +36,13 @@
using namespace std; using namespace std;
using namespace sigc; using namespace sigc;
using namespace Gtk; using namespace Gtk;
using namespace ARDOUR;
/** PortMatrix constructor. /** PortMatrix constructor.
* @param session Our session. * @param session Our session.
* @param type Port type that we are handling. * @param type Port type that we are handling.
*/ */
PortMatrix::PortMatrix (ARDOUR::Session& session, ARDOUR::DataType type) PortMatrix::PortMatrix (Session& session, DataType type)
: Table (2, 2), : Table (2, 2),
_session (session), _session (session),
_type (type), _type (type),
@ -95,8 +96,8 @@ PortMatrix::reconnect_to_routes ()
} }
_route_connections.clear (); _route_connections.clear ();
boost::shared_ptr<ARDOUR::RouteList> routes = _session.get_routes (); boost::shared_ptr<RouteList> routes = _session.get_routes ();
for (ARDOUR::RouteList::iterator i = routes->begin(); i != routes->end(); ++i) { for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
_route_connections.push_back ( _route_connections.push_back (
(*i)->processors_changed.connect (mem_fun (*this, &PortMatrix::setup_global_ports)) (*i)->processors_changed.connect (mem_fun (*this, &PortMatrix::setup_global_ports))
); );
@ -127,7 +128,7 @@ PortMatrix::setup ()
} }
void void
PortMatrix::set_type (ARDOUR::DataType t) PortMatrix::set_type (DataType t)
{ {
_type = t; _type = t;
_ports[0].set_type (_type); _ports[0].set_type (_type);
@ -178,9 +179,9 @@ PortMatrix::disassociate_all ()
for (PortGroup::BundleList::iterator k = b.begin(); k != b.end(); ++k) { for (PortGroup::BundleList::iterator k = b.begin(); k != b.end(); ++k) {
for (uint32_t l = 0; l < k->bundle->nchannels(); ++l) { for (uint32_t l = 0; l < k->bundle->nchannels(); ++l) {
ARDOUR::BundleChannel c[2] = { BundleChannel c[2] = {
ARDOUR::BundleChannel (i->bundle, j), BundleChannel (i->bundle, j),
ARDOUR::BundleChannel (k->bundle, l) BundleChannel (k->bundle, l)
}; };
if (get_state (c) == PortMatrixNode::ASSOCIATED) { if (get_state (c) == PortMatrixNode::ASSOCIATED) {
@ -240,8 +241,8 @@ PortMatrix::rows () const
void void
PortMatrix::popup_menu ( PortMatrix::popup_menu (
pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> column, pair<boost::shared_ptr<PortGroup>, BundleChannel> column,
pair<boost::shared_ptr<PortGroup>, ARDOUR::BundleChannel> row, pair<boost::shared_ptr<PortGroup>, BundleChannel> row,
uint32_t t uint32_t t
) )
{ {
@ -258,18 +259,68 @@ PortMatrix::popup_menu (
pg[_column_index] = column.first; pg[_column_index] = column.first;
pg[_row_index] = row.first; pg[_row_index] = row.first;
ARDOUR::BundleChannel bc[2]; BundleChannel bc[2];
bc[_column_index] = column.second; bc[_column_index] = column.second;
bc[_row_index] = row.second; bc[_row_index] = row.second;
char buf [64]; char buf [64];
std::string const n = add_channel_name ();
if (!n.empty()) { for (int dim = 0; dim < 2; ++dim) {
snprintf (buf, sizeof (buf), _("Add %s to '%s'"), channel_noun().c_str(), n.c_str());
items.push_back (MenuElem (buf, mem_fun (*this, &PortMatrix::add_channel))); if (bc[dim].bundle) {
Menu* m = manage (new Menu);
MenuList& sub = m->items ();
boost::weak_ptr<Bundle> w (bc[dim].bundle);
if (can_add_channel (bc[dim].bundle)) {
snprintf (buf, sizeof (buf), _("Add %s"), channel_noun().c_str());
sub.push_back (MenuElem (buf, bind (mem_fun (*this, &PortMatrix::add_channel_proxy), w)));
} }
if (can_remove_channels (bc[dim].bundle)) {
snprintf (buf, sizeof (buf), _("Remove '%s'"), bc[dim].bundle->channel_name (bc[dim].channel).c_str());
sub.push_back (
MenuElem (
buf,
bind (mem_fun (*this, &PortMatrix::remove_channel_proxy), w, bc[dim].channel)
)
);
}
if (can_rename_channels (bc[dim].bundle)) {
snprintf (buf, sizeof (buf), _("Rename '%s'..."), bc[dim].bundle->channel_name (bc[dim].channel).c_str());
sub.push_back (
MenuElem (
buf,
bind (mem_fun (*this, &PortMatrix::rename_channel_proxy), w, bc[dim].channel)
)
);
}
if (_show_only_bundles) {
snprintf (buf, sizeof (buf), _("%s all"), disassociation_verb().c_str());
} else {
snprintf (
buf, sizeof (buf), _("%s all from '%s'"),
disassociation_verb().c_str(),
bc[dim].bundle->channel_name (bc[dim].channel).c_str()
);
}
sub.push_back (
MenuElem (buf, bind (mem_fun (*this, &PortMatrix::disassociate_all_on_channel), w, bc[dim].channel, dim))
);
items.push_back (MenuElem (bc[dim].bundle->name().c_str(), *m));
}
}
items.push_back (SeparatorElem ());
for (int dim = 0; dim < 2; ++dim) { for (int dim = 0; dim < 2; ++dim) {
if (pg[dim]) { if (pg[dim]) {
@ -293,46 +344,6 @@ PortMatrix::popup_menu (
items.push_back (MenuElem (buf, bind (mem_fun (*this, &PortMatrix::show_group), wp))); items.push_back (MenuElem (buf, bind (mem_fun (*this, &PortMatrix::show_group), wp)));
} }
} }
if (bc[dim].bundle) {
boost::weak_ptr<ARDOUR::Bundle> w (bc[dim].bundle);
if (can_remove_channels (dim)) {
snprintf (buf, sizeof (buf), _("Remove '%s'"), bc[dim].bundle->channel_name (bc[dim].channel).c_str());
items.push_back (
MenuElem (
buf,
bind (mem_fun (*this, &PortMatrix::remove_channel_proxy), w, bc[dim].channel)
)
);
}
if (can_rename_channels (dim)) {
snprintf (buf, sizeof (buf), _("Rename '%s'..."), bc[dim].bundle->channel_name (bc[dim].channel).c_str());
items.push_back (
MenuElem (
buf,
bind (mem_fun (*this, &PortMatrix::rename_channel_proxy), w, bc[dim].channel)
)
);
}
if (_show_only_bundles) {
snprintf (buf, sizeof (buf), _("%s all from '%s'"), disassociation_verb().c_str(), bc[dim].bundle->name().c_str());
} else {
snprintf (
buf, sizeof (buf), _("%s all from '%s/%s'"),
disassociation_verb().c_str(),
bc[dim].bundle->name().c_str(),
bc[dim].bundle->channel_name (bc[dim].channel).c_str()
);
}
items.push_back (
MenuElem (buf, bind (mem_fun (*this, &PortMatrix::disassociate_all_on_channel), w, bc[dim].channel, dim))
);
}
} }
items.push_back (SeparatorElem ()); items.push_back (SeparatorElem ());
@ -348,32 +359,32 @@ PortMatrix::popup_menu (
} }
void void
PortMatrix::remove_channel_proxy (boost::weak_ptr<ARDOUR::Bundle> b, uint32_t c) PortMatrix::remove_channel_proxy (boost::weak_ptr<Bundle> b, uint32_t c)
{ {
boost::shared_ptr<ARDOUR::Bundle> sb = b.lock (); boost::shared_ptr<Bundle> sb = b.lock ();
if (!sb) { if (!sb) {
return; return;
} }
remove_channel (ARDOUR::BundleChannel (sb, c)); remove_channel (BundleChannel (sb, c));
} }
void void
PortMatrix::rename_channel_proxy (boost::weak_ptr<ARDOUR::Bundle> b, uint32_t c) PortMatrix::rename_channel_proxy (boost::weak_ptr<Bundle> b, uint32_t c)
{ {
boost::shared_ptr<ARDOUR::Bundle> sb = b.lock (); boost::shared_ptr<Bundle> sb = b.lock ();
if (!sb) { if (!sb) {
return; return;
} }
rename_channel (ARDOUR::BundleChannel (sb, c)); rename_channel (BundleChannel (sb, c));
} }
void void
PortMatrix::disassociate_all_on_channel (boost::weak_ptr<ARDOUR::Bundle> bundle, uint32_t channel, int dim) PortMatrix::disassociate_all_on_channel (boost::weak_ptr<Bundle> bundle, uint32_t channel, int dim)
{ {
boost::shared_ptr<ARDOUR::Bundle> sb = bundle.lock (); boost::shared_ptr<Bundle> sb = bundle.lock ();
if (!sb) { if (!sb) {
return; return;
} }
@ -383,9 +394,9 @@ PortMatrix::disassociate_all_on_channel (boost::weak_ptr<ARDOUR::Bundle> bundle,
for (PortGroup::BundleList::iterator i = a.begin(); i != a.end(); ++i) { for (PortGroup::BundleList::iterator i = a.begin(); i != a.end(); ++i) {
for (uint32_t j = 0; j < i->bundle->nchannels(); ++j) { for (uint32_t j = 0; j < i->bundle->nchannels(); ++j) {
ARDOUR::BundleChannel c[2]; BundleChannel c[2];
c[dim] = ARDOUR::BundleChannel (sb, channel); c[dim] = BundleChannel (sb, channel);
c[1-dim] = ARDOUR::BundleChannel (i->bundle, j); c[1-dim] = BundleChannel (i->bundle, j);
if (get_state (c) == PortMatrixNode::ASSOCIATED) { if (get_state (c) == PortMatrixNode::ASSOCIATED) {
set_state (c, false); set_state (c, false);
@ -488,3 +499,60 @@ PortMatrix::on_scroll_event (GdkEventScroll* ev)
return true; return true;
} }
boost::shared_ptr<IO>
PortMatrix::io_from_bundle (boost::shared_ptr<Bundle> b) const
{
boost::shared_ptr<IO> io = _ports[0].io_from_bundle (b);
if (!io) {
io = _ports[1].io_from_bundle (b);
}
return io;
}
bool
PortMatrix::can_add_channel (boost::shared_ptr<Bundle> b) const
{
return io_from_bundle (b);
}
void
PortMatrix::add_channel (boost::shared_ptr<Bundle> b)
{
boost::shared_ptr<IO> io = io_from_bundle (b);
if (io) {
io->add_port ("", this, _type);
}
}
bool
PortMatrix::can_remove_channels (boost::shared_ptr<Bundle> b) const
{
return io_from_bundle (b);
}
void
PortMatrix::remove_channel (ARDOUR::BundleChannel b)
{
boost::shared_ptr<IO> io = io_from_bundle (b.bundle);
if (io) {
Port* p = io->nth (b.channel);
if (p) {
io->remove_port (p, this);
}
}
}
void
PortMatrix::add_channel_proxy (boost::weak_ptr<Bundle> w)
{
boost::shared_ptr<Bundle> b = w.lock ();
if (!b) {
return;
}
add_channel (b);
}

View file

@ -125,15 +125,13 @@ public:
virtual PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const = 0; virtual PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const = 0;
virtual bool list_is_global (int) const = 0; virtual bool list_is_global (int) const = 0;
/** If adding a channel is allowed in this situation, return the name of the virtual bool can_add_channel (boost::shared_ptr<ARDOUR::Bundle>) const;
* thing that it would be added to. virtual void add_channel (boost::shared_ptr<ARDOUR::Bundle>);
* @return Name. virtual bool can_remove_channels (boost::shared_ptr<ARDOUR::Bundle>) const;
*/ virtual void remove_channel (ARDOUR::BundleChannel);
virtual std::string add_channel_name () const { return ""; } virtual bool can_rename_channels (boost::shared_ptr<ARDOUR::Bundle>) const {
virtual void add_channel () {} return false;
virtual bool can_remove_channels (int) const = 0; }
virtual void remove_channel (ARDOUR::BundleChannel) = 0;
virtual bool can_rename_channels (int) const = 0;
virtual void rename_channel (ARDOUR::BundleChannel) {} virtual void rename_channel (ARDOUR::BundleChannel) {}
virtual std::string disassociation_verb () const = 0; virtual std::string disassociation_verb () const = 0;
virtual std::string channel_noun () const { return _("channel"); } virtual std::string channel_noun () const { return _("channel"); }
@ -163,6 +161,7 @@ private:
void routes_changed (); void routes_changed ();
void reconnect_to_routes (); void reconnect_to_routes ();
void select_arrangement (); void select_arrangement ();
void add_channel_proxy (boost::weak_ptr<ARDOUR::Bundle>);
void remove_channel_proxy (boost::weak_ptr<ARDOUR::Bundle>, uint32_t); void remove_channel_proxy (boost::weak_ptr<ARDOUR::Bundle>, uint32_t);
void rename_channel_proxy (boost::weak_ptr<ARDOUR::Bundle>, uint32_t); void rename_channel_proxy (boost::weak_ptr<ARDOUR::Bundle>, uint32_t);
void disassociate_all_on_channel (boost::weak_ptr<ARDOUR::Bundle>, uint32_t, int); void disassociate_all_on_channel (boost::weak_ptr<ARDOUR::Bundle>, uint32_t, int);
@ -171,6 +170,7 @@ private:
void show_group (boost::weak_ptr<PortGroup>); void show_group (boost::weak_ptr<PortGroup>);
void toggle_show_only_bundles (); void toggle_show_only_bundles ();
bool on_scroll_event (GdkEventScroll *); bool on_scroll_event (GdkEventScroll *);
boost::shared_ptr<ARDOUR::IO> io_from_bundle (boost::shared_ptr<ARDOUR::Bundle>) const;
/// port type that we are working with /// port type that we are working with
ARDOUR::DataType _type; ARDOUR::DataType _type;

View file

@ -88,18 +88,15 @@ public:
return PortMatrixNode::NOT_ASSOCIATED; return PortMatrixNode::NOT_ASSOCIATED;
} }
bool list_is_global (int dim) const bool list_is_global (int dim) const {
{
return (dim == OTHER); return (dim == OTHER);
} }
bool can_remove_channels (int) const { bool can_remove_channels (boost::shared_ptr<Bundle>) const {
return false; return false;
} }
void remove_channel (ARDOUR::BundleChannel) {} void remove_channel (ARDOUR::BundleChannel) {}
bool can_rename_channels (int) const {
return false;
}
std::string disassociation_verb () const { std::string disassociation_verb () const {
return _("Disassociate"); return _("Disassociate");

View file

@ -260,7 +260,7 @@ IO::remove_port (Port* port, void* src)
PortCountChanged (n_ports()); /* EMIT SIGNAL */ PortCountChanged (n_ports()); /* EMIT SIGNAL */
} }
if (change == ConfigurationChanged) { if (change & ConfigurationChanged) {
setup_bundles (); setup_bundles ();
} }