Gather all ardour: ports so that a few more things are found to put in the port matrix.

git-svn-id: svn://localhost/ardour2/branches/3.0@4439 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2009-01-24 15:21:22 +00:00
parent df6680f45c
commit 4cd47cf253
4 changed files with 56 additions and 22 deletions

View File

@ -57,6 +57,25 @@ PortGroup::clear ()
ports.clear (); ports.clear ();
} }
bool
PortGroup::has_port (std::string const& p) const
{
for (vector<boost::shared_ptr<ARDOUR::Bundle> >::const_iterator i = bundles.begin(); i != bundles.end(); ++i) {
if ((*i)->offers_port_alone (p)) {
return true;
}
}
for (vector<std::string>::const_iterator i = ports.begin(); i != ports.end(); ++i) {
if (*i == p) {
return true;
}
}
return false;
}
/** PortGroupUI constructor. /** PortGroupUI constructor.
* @param m PortMatrix to work for. * @param m PortMatrix to work for.
* @Param g PortGroup to represent. * @Param g PortGroup to represent.
@ -159,9 +178,7 @@ PortGroupList::refresh ()
/* XXX: inserts, sends, plugin inserts? */ /* XXX: inserts, sends, plugin inserts? */
/* Now we need to find the non-ardour ports; we do this by first /* Now find all other ports that we haven't thought of yet */
finding all the ports that we can connect to.
*/
const char **ports = _session.engine().get_ports ("", _type.to_jack_type(), _offer_inputs ? const char **ports = _session.engine().get_ports ("", _type.to_jack_type(), _offer_inputs ?
JackPortIsInput : JackPortIsOutput); JackPortIsInput : JackPortIsOutput);
@ -174,31 +191,20 @@ PortGroupList::refresh ()
client_matching_string += ':'; client_matching_string += ':';
while (ports[n]) { while (ports[n]) {
std::string const p = ports[n]; std::string const p = ports[n];
if (p.substr(0, strlen ("system:")) == "system:" || p.substr (0, strlen ("alsa_pcm:")) == "alsa_pcm:") { if (!_system.has_port(p) && !_buss.has_port(p) && !_track.has_port(p) && !_other.has_port(p)) {
/* system: or alsa_pcm: prefix */
if (port_has_prefix (p, "system:") ||
/* see if this port is already in one of the system: bundles */ port_has_prefix (p, "alsa_pcm") ||
std::vector<boost::shared_ptr<ARDOUR::Bundle> >::iterator i = _system.bundles.begin(); port_has_prefix (p, "ardour:")) {
while (i != _system.bundles.end()) {
if ((*i)->uses_port (p)) {
break;
}
++i;
}
if (i == _system.bundles.end()) {
/* it's not already in there, so add it */
_system.add_port (p); _system.add_port (p);
} } else {
} else {
if (p.substr(0, client_matching_string.length()) != client_matching_string) {
/* other (non-ardour) prefix */
_other.add_port (p); _other.add_port (p);
} }
} }
++n; ++n;
} }
@ -211,6 +217,13 @@ PortGroupList::refresh ()
push_back (&_other); push_back (&_other);
} }
bool
PortGroupList::port_has_prefix (const std::string& n, const std::string& p) const
{
return n.substr (0, p.length()) == p;
}
void void
PortGroupList::set_type (ARDOUR::DataType t) PortGroupList::set_type (ARDOUR::DataType t)
{ {

View File

@ -64,6 +64,8 @@ public:
VisibilityChanged (); VisibilityChanged ();
} }
bool has_port (std::string const &) const;
sigc::signal<void> VisibilityChanged; sigc::signal<void> VisibilityChanged;
private: private:
@ -112,6 +114,7 @@ class PortGroupList : public std::list<PortGroup*>, public sigc::trackable
private: private:
void maybe_add_session_bundle (boost::shared_ptr<ARDOUR::Bundle>); void maybe_add_session_bundle (boost::shared_ptr<ARDOUR::Bundle>);
bool port_has_prefix (std::string const &, std::string const &) const;
std::string common_prefix (std::vector<std::string> const &) const; std::string common_prefix (std::vector<std::string> const &) const;
void visibility_changed (); void visibility_changed ();

View File

@ -90,6 +90,7 @@ class Bundle : public sigc::trackable
void remove_port_from_channel (uint32_t, std::string); void remove_port_from_channel (uint32_t, std::string);
bool port_attached_to_channel (uint32_t, std::string); bool port_attached_to_channel (uint32_t, std::string);
bool uses_port (std::string) const; bool uses_port (std::string) const;
bool offers_port_alone (std::string) const;
void remove_channel (uint32_t); void remove_channel (uint32_t);
void remove_channels (); void remove_channels ();

View File

@ -173,6 +173,23 @@ Bundle::uses_port (std::string p) const
return false; return false;
} }
/** @param p Port name.
* @return true if this bundle offers this port on its own on a channel.
*/
bool
Bundle::offers_port_alone (std::string p) const
{
Glib::Mutex::Lock lm (_channel_mutex);
for (std::vector<Channel>::const_iterator i = _channel.begin(); i != _channel.end(); ++i) {
if (i->ports.size() == 1 && i->ports[0] == p) {
return true;
}
}
return false;
}
std::string std::string
Bundle::channel_name (uint32_t ch) const Bundle::channel_name (uint32_t ch) const
{ {