change audioengine's port container to a std::map to provide faster results from get_port_by_name()

git-svn-id: svn://localhost/ardour2/branches/3.0@11360 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2012-01-27 13:23:39 +00:00
parent 98ade9348a
commit 6a999b8287
3 changed files with 53 additions and 25 deletions

View File

@ -64,7 +64,7 @@ class ProcessThread;
class AudioEngine : public SessionHandlePtr
{
public:
typedef std::set<boost::shared_ptr<Port> > Ports;
typedef std::map<std::string,boost::shared_ptr<Port> > Ports;
AudioEngine (std::string client_name, std::string session_uuid);
virtual ~AudioEngine ();
@ -185,6 +185,7 @@ public:
void get_physical_inputs (DataType type, std::vector<std::string>&);
boost::shared_ptr<Port> get_port_by_name (const std::string &);
void port_renamed (const std::string&, const std::string&);
enum TransportState {
TransportStopped = JackTransportStopped,

View File

@ -383,10 +383,10 @@ AudioEngine::_connect_callback (jack_port_id_t id_a, jack_port_id_t id_b, int co
boost::shared_ptr<Ports> pr = ae->ports.reader ();
Ports::iterator i = pr->begin ();
while (i != pr->end() && (port_a == 0 || port_b == 0)) {
if (jack_port_a == (*i)->jack_port()) {
port_a = *i;
} else if (jack_port_b == (*i)->jack_port()) {
port_b = *i;
if (jack_port_a == i->second->jack_port()) {
port_a = i->second;
} else if (jack_port_b == i->second->jack_port()) {
port_b = i->second;
}
++i;
}
@ -410,7 +410,7 @@ AudioEngine::split_cycle (pframes_t offset)
boost::shared_ptr<Ports> p = ports.reader();
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
(*i)->cycle_split ();
i->second->cycle_split ();
}
}
@ -488,7 +488,7 @@ AudioEngine::process_callback (pframes_t nframes)
boost::shared_ptr<Ports> p = ports.reader();
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
(*i)->cycle_start (nframes);
i->second->cycle_start (nframes);
}
/* test if we are freewheeling and there are freewheel signals connected.
@ -526,12 +526,12 @@ AudioEngine::process_callback (pframes_t nframes)
bool x;
if ((*i)->last_monitor() != (x = (*i)->jack_monitoring_input ())) {
(*i)->set_last_monitor (x);
if (i->second->last_monitor() != (x = i->second->jack_monitoring_input ())) {
i->second->set_last_monitor (x);
/* XXX I think this is dangerous, due to
a likely mutex in the signal handlers ...
*/
(*i)->MonitorInputChanged (x); /* EMIT SIGNAL */
i->second->MonitorInputChanged (x); /* EMIT SIGNAL */
}
}
last_monitor_check = next_processed_frames;
@ -543,8 +543,8 @@ AudioEngine::process_callback (pframes_t nframes)
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
if ((*i)->sends_output()) {
(*i)->get_buffer(nframes).silence(nframes);
if (i->second->sends_output()) {
i->second->get_buffer(nframes).silence(nframes);
}
}
}
@ -552,7 +552,7 @@ AudioEngine::process_callback (pframes_t nframes)
// Finalize ports
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
(*i)->cycle_end (nframes);
i->second->cycle_end (nframes);
}
_processed_frames = next_processed_frames;
@ -643,7 +643,7 @@ AudioEngine::jack_bufsize_callback (pframes_t nframes)
boost::shared_ptr<Ports> p = ports.reader();
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
(*i)->reset();
i->second->reset();
}
}
@ -708,7 +708,7 @@ AudioEngine::set_session (Session *s)
boost::shared_ptr<Ports> p = ports.reader();
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
(*i)->cycle_start (blocksize);
i->second->cycle_start (blocksize);
}
_session->process (blocksize);
@ -721,7 +721,7 @@ AudioEngine::set_session (Session *s)
_session->process (blocksize);
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
(*i)->cycle_end (blocksize);
i->second->cycle_end (blocksize);
}
}
}
@ -784,7 +784,7 @@ AudioEngine::register_port (DataType dtype, const string& portname, bool input)
RCUWriter<Ports> writer (ports);
boost::shared_ptr<Ports> ps = writer.get_copy ();
ps->insert (ps->begin(), newport);
ps->insert (make_pair (make_port_name_relative (portname), newport));
/* writer goes out of scope, forces update */
@ -828,7 +828,11 @@ AudioEngine::unregister_port (boost::shared_ptr<Port> port)
{
RCUWriter<Ports> writer (ports);
boost::shared_ptr<Ports> ps = writer.get_copy ();
ps->erase (port);
Ports::iterator x = ps->find (make_port_name_relative (port->name()));
if (x != ps->end()) {
ps->erase (x);
}
/* writer goes out of scope, forces update */
}
@ -977,19 +981,40 @@ AudioEngine::get_port_by_name (const string& portname)
return boost::shared_ptr<Port> ();
}
std::string const rel = make_port_name_relative (portname);
boost::shared_ptr<Ports> pr = ports.reader();
std::string rel = make_port_name_relative (portname);
Ports::iterator x = pr->find (rel);
for (Ports::iterator i = pr->begin(); i != pr->end(); ++i) {
if (rel == (*i)->name()) {
return *i;
if (x != pr->end()) {
/* its possible that the port was renamed by some 3rd party and
we don't know about it. check for this (the check is quick
and cheap), and if so, rename the port (which will alter
the port map as a side effect).
*/
const std::string check = make_port_name_relative (jack_port_name (x->second->jack_port()));
if (check != rel) {
x->second->set_name (check);
}
return x->second;
}
return boost::shared_ptr<Port> ();
}
void
AudioEngine::port_renamed (const std::string& old_relative_name, const std::string& new_relative_name)
{
RCUWriter<Ports> writer (ports);
boost::shared_ptr<Ports> p = writer.get_copy();
Ports::iterator x = p->find (old_relative_name);
if (x != p->end()) {
boost::shared_ptr<Port> port = x->second;
p->erase (x);
p->insert (make_pair (new_relative_name, port));
}
}
const char **
AudioEngine::get_ports (const string& port_name_pattern, const string& type_name_pattern, uint32_t flags)
{
@ -1329,7 +1354,7 @@ AudioEngine::reconnect_to_jack ()
boost::shared_ptr<Ports> p = ports.reader ();
for (i = p->begin(); i != p->end(); ++i) {
if ((*i)->reestablish ()) {
if (i->second->reestablish ()) {
break;
}
}
@ -1364,7 +1389,7 @@ AudioEngine::reconnect_to_jack ()
/* re-establish connections */
for (i = p->begin(); i != p->end(); ++i) {
(*i)->reconnect ();
i->second->reconnect ();
}
MIDI::Manager::instance()->reconnect ();

View File

@ -472,9 +472,11 @@ Port::set_name (std::string const & n)
int const r = jack_port_set_name (_jack_port, n.c_str());
if (r == 0) {
_engine->port_renamed (_name, n);
_name = n;
}
return r;
}