From ccdd99afcec1118c3a3080e6d109ebae55665336 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 10 Nov 2009 17:34:33 +0000 Subject: 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 --- gtk2_ardour/redirect_box.cc | 22 +++++++++++++++++----- libs/ardour/ardour/route.h | 2 ++ libs/ardour/ardour/session.h | 4 +++- libs/ardour/route.cc | 18 ++++++++++++++++++ libs/ardour/session.cc | 20 +++++++++++++++++++- libs/gtkmm2ext/gtk_ui.cc | 2 +- libs/gtkmm2ext/gtkmm2ext/gtk_ui.h | 2 +- 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) 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 void foreach_route (T *obj, void (T::*func)(boost::shared_ptr)); template void foreach_route (T *obj, void (T::*func)(Route&, A), A arg); - boost::shared_ptr route_by_name (string); + bool io_name_is_legal (const std::string&); + + boost::shared_ptr route_by_name (const std::string&); boost::shared_ptr route_by_id (PBD::ID); boost::shared_ptr 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 (*i) || + boost::dynamic_pointer_cast (*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 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 -Session::route_by_name (string name) +Session::route_by_name (const std::string& name) { shared_ptr 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 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 *); -- cgit v1.2.3