mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-24 07:27:44 +01:00
Make sure buses and tracks have unique names.
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3033 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
22c05e56a6
commit
3ee550573c
7 changed files with 70 additions and 42 deletions
|
|
@ -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 ();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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, ":", "-")) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue