summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2009-11-10 17:34:33 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2009-11-10 17:34:33 +0000
commitccdd99afcec1118c3a3080e6d109ebae55665336 (patch)
tree270af57263cff23f1b3cecefd529af608ac5ae31
parent39a4068e36f632f2ff8abf99881d40e26d7e5183 (diff)
when renaming redirects, scan all routes AND sends AND port inserts for the name to avoid JACK port duplicate names
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@6052 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r--gtk2_ardour/redirect_box.cc22
-rw-r--r--libs/ardour/ardour/route.h2
-rw-r--r--libs/ardour/ardour/session.h4
-rw-r--r--libs/ardour/route.cc18
-rw-r--r--libs/ardour/session.cc20
-rw-r--r--libs/gtkmm2ext/gtk_ui.cc2
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/gtk_ui.h2
7 files changed, 61 insertions, 9 deletions
diff --git a/gtk2_ardour/redirect_box.cc b/gtk2_ardour/redirect_box.cc
index c309809cef..cb6adb9224 100644
--- a/gtk2_ardour/redirect_box.cc
+++ b/gtk2_ardour/redirect_box.cc
@@ -925,12 +925,24 @@ RedirectBox::rename_redirect (boost::shared_ptr<Redirect> redirect)
case Gtk::RESPONSE_ACCEPT:
name_prompter.get_result (result);
if (result.length()) {
- if (_session.route_by_name (result)) {
- ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
- return;
+ int tries = 0;
+ string test = result;
+
+ while (tries < 100) {
+ if (_session.io_name_is_legal (test)) {
+ result = test;
+ break;
+ }
+ tries++;
+ test = string_compose ("%1-%2", result, tries);
+ }
+
+ if (tries < 100) {
+ redirect->set_name (result, this);
+ } else {
+ ARDOUR_UI::instance()->popup_error
+ (string_compose (_("At least 100 IO objects exist with a name like %1 - name not changed"), result));
}
-
- redirect->set_name (result, this);
}
break;
}
diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h
index 5e7cb8fc5f..c3883969aa 100644
--- a/libs/ardour/ardour/route.h
+++ b/libs/ardour/ardour/route.h
@@ -167,6 +167,8 @@ class Route : public IO
return *i;
}
}
+
+ bool has_io_redirect_named (const std::string&);
uint32_t max_redirect_outs () const { return redirect_max_outs; }
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index 9831d57829..8cf3ce7c31 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -326,7 +326,9 @@ class Session : public PBD::StatefulDestructible
template<class T> void foreach_route (T *obj, void (T::*func)(boost::shared_ptr<Route>));
template<class T, class A> void foreach_route (T *obj, void (T::*func)(Route&, A), A arg);
- boost::shared_ptr<Route> route_by_name (string);
+ bool io_name_is_legal (const std::string&);
+
+ boost::shared_ptr<Route> route_by_name (const std::string&);
boost::shared_ptr<Route> route_by_id (PBD::ID);
boost::shared_ptr<Route> route_by_remote_id (uint32_t id);
diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc
index 5d3fecf724..4e19b9c23e 100644
--- a/libs/ardour/route.cc
+++ b/libs/ardour/route.cc
@@ -2712,3 +2712,21 @@ Route::set_name (string str, void* src)
}
return ret;
}
+
+bool
+Route::has_io_redirect_named (const string& name)
+{
+ Glib::RWLock::ReaderLock lm (redirect_lock);
+ RedirectList::iterator i;
+
+ for (i = _redirects.begin(); i != _redirects.end(); ++i) {
+ if (boost::dynamic_pointer_cast<Send> (*i) ||
+ boost::dynamic_pointer_cast<PortInsert> (*i)) {
+ if ((*i)->name() == name) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index c2141e62e6..2b235dae28 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -2531,8 +2531,26 @@ Session::catch_up_on_solo_mute_override ()
}
}
+bool
+Session::io_name_is_legal (const std::string& name)
+{
+ shared_ptr<RouteList> r = routes.reader ();
+
+ for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+ if ((*i)->name() == name) {
+ return false;
+ }
+
+ if ((*i)->has_io_redirect_named (name)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
shared_ptr<Route>
-Session::route_by_name (string name)
+Session::route_by_name (const std::string& name)
{
shared_ptr<RouteList> r = routes.reader ();
diff --git a/libs/gtkmm2ext/gtk_ui.cc b/libs/gtkmm2ext/gtk_ui.cc
index 8b7830ad18..33f6bbc864 100644
--- a/libs/gtkmm2ext/gtk_ui.cc
+++ b/libs/gtkmm2ext/gtk_ui.cc
@@ -570,7 +570,7 @@ UI::handle_fatal (const char *message)
}
void
-UI::popup_error (const char *text)
+UI::popup_error (const std::string& text)
{
if (!caller_is_ui_thread()) {
error << "non-UI threads can't use UI::popup_error"
diff --git a/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h b/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h
index 91b6fa48ca..cf7db9f1b2 100644
--- a/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h
+++ b/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h
@@ -113,7 +113,7 @@ class UI : public Receiver, public AbstractUI<UIRequest>
void run (Receiver &old_receiver);
void set_state (Gtk::Widget *w, Gtk::StateType state);
- void popup_error (const char *text);
+ void popup_error (const std::string&);
void flush_pending ();
void toggle_errors ();
void touch_display (Touchable *);