+ for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
+ if (!extra_system[*i].empty()) {
+ boost::shared_ptr<Bundle> b = make_bundle_from_ports (extra_system[*i], *i, inputs);
+ boost::shared_ptr<Bundle> bt = bundle_for_type (b, type);
+ if (bt->nchannels() != ChanCount::ZERO) {
+ system->add_bundle (bt);
+ }
+ }
+ }
+
+ for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
+ if (!extra_other[*i].empty()) {
+ boost::shared_ptr<Bundle> b = make_bundle_from_ports (extra_other[*i], *i, inputs);
+ boost::shared_ptr<Bundle> bt = bundle_for_type (b, type);
+ if (bt->nchannels() != ChanCount::ZERO) {
+ other->add_bundle (bt);
+ }
+ }
+ }
+
+ if (!allow_dups) {
+ system->remove_duplicates ();
+ }
+
+ add_group_if_not_empty (other);
+ add_group_if_not_empty (bus);
+ add_group_if_not_empty (track);
+ add_group_if_not_empty (ardour);
+ add_group_if_not_empty (system);
+
+ emit_changed ();
+}
+
+boost::shared_ptr<Bundle>
+PortGroupList::make_bundle_from_ports (std::vector<std::string> const & p, ARDOUR::DataType type, bool inputs) const
+{
+ boost::shared_ptr<Bundle> b (new Bundle ("", inputs));
+
+ std::string const pre = common_prefix (p);
+ if (!pre.empty()) {
+ b->set_name (pre.substr (0, pre.length() - 1));
+ }
+
+ for (uint32_t j = 0; j < p.size(); ++j) {
+ b->add_channel (p[j].substr (pre.length()), type);
+ b->set_port (j, p[j]);
+ }
+
+ return b;
+}
+
+bool
+PortGroupList::port_has_prefix (const std::string& n, const std::string& p) const
+{
+ return n.substr (0, p.length()) == p;
+}
+
+std::string
+PortGroupList::common_prefix_before (std::vector<std::string> const & p, std::string const & s) const
+{
+ /* we must have some strings and the first must contain the separator string */
+ if (p.empty() || p[0].find_first_of (s) == std::string::npos) {
+ return "";
+ }
+
+ /* prefix of the first string */
+ std::string const fp = p[0].substr (0, p[0].find_first_of (s) + 1);
+
+ /* see if the other strings also start with fp */
+ uint32_t j = 1;
+ while (j < p.size()) {
+ if (p[j].substr (0, fp.length()) != fp) {
+ break;
+ }
+ ++j;
+ }
+
+ if (j != p.size()) {
+ return "";
+ }
+
+ return fp;
+}
+
+
+std::string
+PortGroupList::common_prefix (std::vector<std::string> const & p) const
+{
+ /* common prefix before '/' ? */
+ std::string cp = common_prefix_before (p, "/");
+ if (!cp.empty()) {
+ return cp;
+ }
+
+ cp = common_prefix_before (p, ":");
+ if (!cp.empty()) {
+ return cp;
+ }
+
+ return "";