Fixed unique source name algorithm

This commit is contained in:
Bruno
2021-04-26 23:51:47 +02:00
parent c7d6d37a8e
commit be36662efc
3 changed files with 7 additions and 8 deletions

View File

@@ -658,14 +658,11 @@ void Mixer::renameSource(Source *s, const std::string &newname)
// tentative new name
std::string tentativename = s->name();
std::list<std::string> others = session_->getNameList();
others.remove(tentativename);
// try the given new name if valid
if ( !newname.empty() )
tentativename = newname;
tentativename = BaseToolkit::uniqueName(tentativename, others);
tentativename = BaseToolkit::uniqueName(tentativename, session_->getNameList(s->id()));
// ok to rename
s->setName(tentativename);

View File

@@ -287,12 +287,14 @@ SourceIdList Session::getIdList() const
return ids(sources_);
}
std::list<std::string> Session::getNameList() const
std::list<std::string> Session::getNameList(uint64_t exceptid) const
{
std::list<std::string> namelist;
for( SourceList::const_iterator it = sources_.cbegin(); it != sources_.cend(); ++it)
for( SourceList::const_iterator it = sources_.cbegin(); it != sources_.cend(); ++it) {
if ( (*it)->id() != exceptid )
namelist.push_back( (*it)->name() );
}
return namelist;
}

View File

@@ -66,7 +66,7 @@ public:
SourceList::iterator find (uint64_t id);
SourceIdList getIdList() const;
std::list<std::string> getNameList() const;
std::list<std::string> getNameList(uint64_t exceptid=0) const;
SourceList::iterator at (int index);
int index (SourceList::iterator it) const;