enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / backends / alsa / alsa_audiobackend.cc
index 8f8eaa75a393731d1543bff634bbaed8f543b9a8..5c267d6c7f320df44b9f8cc1237b0c487599a24a 100644 (file)
@@ -32,7 +32,7 @@
 #include "ardour/filesystem_paths.h"
 #include "ardour/port_manager.h"
 #include "ardouralsautil/devicelist.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 
@@ -1210,11 +1210,20 @@ AlsaAudioBackend::port_name_size () const
 int
 AlsaAudioBackend::set_port_name (PortEngine::PortHandle port, const std::string& name)
 {
+       std::string newname (_instance_name + ":" + name);
        if (!valid_port (port)) {
-               PBD::error << _("AlsaBackend::set_port_name: Invalid Port(s)") << endmsg;
+               PBD::error << _("AlsaBackend::set_port_name: Invalid Port") << endmsg;
                return -1;
        }
-       return static_cast<AlsaPort*>(port)->set_name (_instance_name + ":" + name);
+       if (find_port (newname)) {
+               PBD::error << _("AlsaBackend::set_port_name: Port with given name already exists") << endmsg;
+               return -1;
+       }
+
+       AlsaPort* p = static_cast<AlsaPort*>(port);
+       _portmap.erase (p->name());
+       _portmap.insert (make_pair (newname, p));
+       return p->set_name (newname);
 }
 
 std::string
@@ -1280,7 +1289,7 @@ AlsaAudioBackend::get_ports (
                }
        }
 
-       for (PortIndex::iterator i = _ports.begin (); i != _ports.end (); ++i) {
+       for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) {
                AlsaPort* port = *i;
                if ((port->type () == type) && flags == (port->flags () & flags)) {
                        if (!use_regexp || !regexec (&port_regex, port->name ().c_str (), 0, NULL, 0)) {
@@ -1353,7 +1362,7 @@ AlsaAudioBackend::unregister_port (PortEngine::PortHandle port_handle)
                return;
        }
        AlsaPort* port = static_cast<AlsaPort*>(port_handle);
-       PortIndex::iterator i = _ports.find (static_cast<AlsaPort*>(port_handle));
+       PortIndex::iterator i = std::find (_ports.begin(), _ports.end(), static_cast<AlsaPort*>(port_handle));
        if (i == _ports.end ()) {
                PBD::error << _("AlsaBackend::unregister_port: Failed to find port") << endmsg;
                return;
@@ -1805,7 +1814,7 @@ AlsaAudioBackend::n_physical_outputs () const
 {
        int n_midi = 0;
        int n_audio = 0;
-       for (PortIndex::iterator i = _ports.begin (); i != _ports.end (); ++i) {
+       for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) {
                AlsaPort* port = *i;
                if (port->is_output () && port->is_physical ()) {
                        switch (port->type ()) {
@@ -1826,7 +1835,7 @@ AlsaAudioBackend::n_physical_inputs () const
 {
        int n_midi = 0;
        int n_audio = 0;
-       for (PortIndex::iterator i = _ports.begin (); i != _ports.end (); ++i) {
+       for (PortIndex::const_iterator i = _ports.begin (); i != _ports.end (); ++i) {
                AlsaPort* port = *i;
                if (port->is_input () && port->is_physical ()) {
                        switch (port->type ()) {