summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorSampo Savolainen <v2@iki.fi>2008-02-09 10:32:45 +0000
committerSampo Savolainen <v2@iki.fi>2008-02-09 10:32:45 +0000
commit3ee550573c2ae3e37d0e3bd7eedb6c64e13c3ebc (patch)
tree58f18ba3dab0d7dd95f3c8cbbefc0451b0996328 /libs/ardour
parent22c05e56a6a3a0d3e8a56185e004b1550fbdba08 (diff)
Make sure buses and tracks have unique names.
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3033 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/ardour/playlist.h1
-rw-r--r--libs/ardour/ardour/route.h2
-rw-r--r--libs/ardour/ardour/utils.h2
-rw-r--r--libs/ardour/io.cc14
-rw-r--r--libs/ardour/playlist.cc40
-rw-r--r--libs/ardour/route.cc14
-rw-r--r--libs/ardour/utils.cc39
7 files changed, 70 insertions, 42 deletions
diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h
index c80330c04a..0e7bf4eff9 100644
--- a/libs/ardour/ardour/playlist.h
+++ b/libs/ardour/ardour/playlist.h
@@ -124,7 +124,6 @@ class Playlist : public PBD::StatefulDestructible, public boost::enable_shared_f
sigc::signal<void> LayeringChanged;
static string bump_name (string old_name, Session&);
- static string bump_name_once (string old_name);
void freeze ();
void thaw ();
diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h
index 5b927d255f..e4fb003e09 100644
--- a/libs/ardour/ardour/route.h
+++ b/libs/ardour/ardour/route.h
@@ -74,6 +74,8 @@ class Route : public IO
Route (Session&, const XMLNode&, DataType default_type = DataType::AUDIO);
virtual ~Route();
+ static std::string ensure_track_or_route_name(std::string, Session &);
+
std::string comment() { return _comment; }
void set_comment (std::string str, void *src);
diff --git a/libs/ardour/ardour/utils.h b/libs/ardour/ardour/utils.h
index 0d4ce08adc..5f392ca5b4 100644
--- a/libs/ardour/ardour/utils.h
+++ b/libs/ardour/ardour/utils.h
@@ -46,6 +46,8 @@ static inline float f_max(float x, float a) {
return (x);
}
+std::string bump_name_once(std::string s);
+
int cmp_nocase (const std::string& s, const std::string& s2);
int tokenize_fullpath (std::string fullpath, std::string& path, std::string& name);
diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc
index b3bfd82271..4f74b70e57 100644
--- a/libs/ardour/io.cc
+++ b/libs/ardour/io.cc
@@ -32,6 +32,7 @@
#include <ardour/audioengine.h>
#include <ardour/io.h>
+#include <ardour/route.h>
#include <ardour/port.h>
#include <ardour/connection.h>
#include <ardour/session.h>
@@ -2056,12 +2057,21 @@ IO::parse_gain_string (const string& str, vector<string>& ports)
}
int
-IO::set_name (string name, void* src)
+IO::set_name (string requested_name, void* src)
{
- if (name == _name) {
+ if (requested_name == _name) {
return 0;
}
+ string name;
+ Route *rt;
+ if ( (rt = dynamic_cast<Route *>(this))) {
+ name = Route::ensure_track_or_route_name(requested_name, _session);
+ } else {
+ name = requested_name;
+ }
+
+
/* replace all colons in the name. i wish we didn't have to do this */
if (replace_all (name, ":", "-")) {
diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc
index aa79812f98..3aa14a0558 100644
--- a/libs/ardour/playlist.cc
+++ b/libs/ardour/playlist.cc
@@ -1796,50 +1796,12 @@ Playlist::bump_name (string name, Session &session)
string newname = name;
do {
- newname = Playlist::bump_name_once (newname);
+ newname = bump_name_once (newname);
} while (session.playlist_by_name (newname)!=NULL);
return newname;
}
-string
-Playlist::bump_name_once (string name)
-{
- string::size_type period;
- string newname;
-
- if ((period = name.find_last_of ('.')) == string::npos) {
- newname = name;
- newname += ".1";
- } else {
- int isnumber = 1;
- const char *last_element = name.c_str() + period + 1;
- for (size_t i = 0; i < strlen(last_element); i++) {
- if (!isdigit(last_element[i])) {
- isnumber = 0;
- break;
- }
- }
-
- errno = 0;
- long int version = strtol (name.c_str()+period+1, (char **)NULL, 10);
-
- if (isnumber == 0 || errno != 0) {
- // last_element is not a number, or is too large
- newname = name;
- newname += ".1";
- } else {
- char buf[32];
-
- snprintf (buf, sizeof(buf), "%ld", version+1);
-
- newname = name.substr (0, period+1);
- newname += buf;
- }
- }
-
- return newname;
-}
layer_t
Playlist::top_layer() const
diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc
index f1953af386..95571bd3da 100644
--- a/libs/ardour/route.cc
+++ b/libs/ardour/route.cc
@@ -184,6 +184,20 @@ Route::sync_order_keys ()
}
}
+string
+Route::ensure_track_or_route_name(string name, Session &session)
+{
+ string newname = name;
+
+ while (session.route_by_name (newname)!=NULL)
+ {
+ newname = bump_name_once (newname);
+ }
+
+ return newname;
+}
+
+
void
Route::inc_gain (gain_t fraction, void *src)
{
diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc
index e34fdd75a1..948b409986 100644
--- a/libs/ardour/utils.cc
+++ b/libs/ardour/utils.cc
@@ -125,6 +125,45 @@ legalize_for_path (string str)
}
#endif
+string bump_name_once(std::string name)
+{
+ string::size_type period;
+ string newname;
+
+ if ((period = name.find_last_of ('.')) == string::npos) {
+ newname = name;
+ newname += ".1";
+ } else {
+ int isnumber = 1;
+ const char *last_element = name.c_str() + period + 1;
+ for (size_t i = 0; i < strlen(last_element); i++) {
+ if (!isdigit(last_element[i])) {
+ isnumber = 0;
+ break;
+ }
+ }
+
+ errno = 0;
+ long int version = strtol (name.c_str()+period+1, (char **)NULL, 10);
+
+ if (isnumber == 0 || errno != 0) {
+ // last_element is not a number, or is too large
+ newname = name;
+ newname += ".1";
+ } else {
+ char buf[32];
+
+ snprintf (buf, sizeof(buf), "%ld", version+1);
+
+ newname = name.substr (0, period+1);
+ newname += buf;
+ }
+ }
+
+ return newname;
+
+}
+
ostream&
operator<< (ostream& o, const BBT_Time& bbt)
{