From: Robin Gareus Date: Tue, 26 Apr 2016 00:26:20 +0000 (+0200) Subject: keep portmap & portindex in sync when renaming ports X-Git-Tag: 5.0-pre0~815 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=2169de3975e8276233e2640391c8b526ec9e97fd;hp=11a69068af7b5ea182996a2ddba15f5131aa003b;p=ardour.git keep portmap & portindex in sync when renaming ports Fixes crash on session re-load (introduced in 800c8182 and fde99e68) --- diff --git a/libs/backends/alsa/alsa_audiobackend.cc b/libs/backends/alsa/alsa_audiobackend.cc index 8f8eaa75a3..a3ba3f36c4 100644 --- a/libs/backends/alsa/alsa_audiobackend.cc +++ b/libs/backends/alsa/alsa_audiobackend.cc @@ -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(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(port); + _portmap.erase (p->name()); + _portmap.insert (make_pair (newname, p)); + return p->set_name (newname); } std::string diff --git a/libs/backends/coreaudio/coreaudio_backend.cc b/libs/backends/coreaudio/coreaudio_backend.cc index 0047721d81..b1721dd2d5 100644 --- a/libs/backends/coreaudio/coreaudio_backend.cc +++ b/libs/backends/coreaudio/coreaudio_backend.cc @@ -902,11 +902,20 @@ CoreAudioBackend::port_name_size () const int CoreAudioBackend::set_port_name (PortEngine::PortHandle port, const std::string& name) { + std::string newname (_instance_name + ":" + name); if (!valid_port (port)) { PBD::warning << _("CoreAudioBackend::set_port_name: Invalid Port(s)") << endmsg; return -1; } - return static_cast(port)->set_name (_instance_name + ":" + name); + if (find_port (newname)) { + PBD::error << _("CoreAudioBackend::set_port_name: Port with given name already exists") << endmsg; + return -1; + } + + CoreBackendPort* p = static_cast(port); + _portmap.erase (p->name()); + _portmap.insert (make_pair (newname, p)); + return p->set_name (newname); } std::string diff --git a/libs/backends/dummy/dummy_audiobackend.cc b/libs/backends/dummy/dummy_audiobackend.cc index 94ed1a0fd7..91efd79a49 100644 --- a/libs/backends/dummy/dummy_audiobackend.cc +++ b/libs/backends/dummy/dummy_audiobackend.cc @@ -432,6 +432,9 @@ DummyAudioBackend::_start (bool /*for_latency_measurement*/) for (PortIndex::const_iterator it = _ports.begin (); it != _ports.end (); ++it) { PBD::info << _("DummyAudioBackend: port '") << (*it)->name () << "' exists." << endmsg; } + for (PortMap::const_iterator it = _portmap.begin (); it != _portmap.end (); ++it) { + PBD::info << _("DummyAudioBackend: portmap '") << (*it).first << "' exists." << endmsg; + } _system_inputs.clear(); _system_outputs.clear(); _system_midi_in.clear(); @@ -643,11 +646,22 @@ DummyAudioBackend::port_name_size () const int DummyAudioBackend::set_port_name (PortEngine::PortHandle port, const std::string& name) { + std::string newname (_instance_name + ":" + name); + if (!valid_port (port)) { PBD::error << _("DummyBackend::set_port_name: Invalid Port(s)") << endmsg; return -1; } - return static_cast(port)->set_name (_instance_name + ":" + name); + + if (find_port (newname)) { + PBD::error << _("DummyBackend::set_port_name: Port with given name already exists") << endmsg; + return -1; + } + + DummyPort* p = static_cast(port); + _portmap.erase (p->name()); + _portmap.insert (make_pair (newname, p)); + return p->set_name (newname); } std::string