X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fardour%2Fport_manager.cc;h=f5304f4961a59d4505e96fc51947f07269061dbe;hb=b285559767e21aae4467270590f048c3263fd742;hp=6d3336cabbc909dec0b294c9520d810fc7840884;hpb=927788a0b0bf6a621e7cee60365f4e8cbd67d829;p=ardour.git diff --git a/libs/ardour/port_manager.cc b/libs/ardour/port_manager.cc index 6d3336cabb..f5304f4961 100644 --- a/libs/ardour/port_manager.cc +++ b/libs/ardour/port_manager.cc @@ -38,6 +38,7 @@ #include "ardour/midiport_manager.h" #include "ardour/port_manager.h" #include "ardour/profile.h" +#include "ardour/rt_tasklist.h" #include "ardour/session.h" #include "ardour/types_convert.h" @@ -166,11 +167,11 @@ PortManager::port_is_mine (const string& portname) const if (portname.find_first_of (':') != string::npos) { if (portname.substr (0, self.length ()) != self) { - return false; - } - } + return false; + } + } - return true; + return true; } bool @@ -191,37 +192,51 @@ PortManager::port_is_physical (const std::string& portname) const void PortManager::filter_midi_ports (vector& ports, MidiPortFlags include, MidiPortFlags exclude) { + if (!include && !exclude) { return; } - for (vector::iterator si = ports.begin(); si != ports.end(); ) { + { + Glib::Threads::Mutex::Lock lm (midi_port_info_mutex); - PortManager::MidiPortInformation mpi = midi_port_information (*si); + fill_midi_port_info_locked (); - if (mpi.pretty_name.empty()) { - /* no information !!! */ - ++si; - continue; - } + for (vector::iterator si = ports.begin(); si != ports.end(); ) { - if (include) { - if ((mpi.properties & include) != include) { - /* properties do not include requested ones */ - si = ports.erase (si); + MidiPortInfo::iterator x = midi_port_info.find (*si); + + if (x == midi_port_info.end()) { + ++si; continue; } - } - if (exclude) { - if ((mpi.properties & exclude)) { - /* properties include ones to avoid */ - si = ports.erase (si); + MidiPortInformation& mpi (x->second); + + if (mpi.pretty_name.empty()) { + /* no information !!! */ + ++si; continue; } - } - ++si; + if (include) { + if ((mpi.properties & include) != include) { + /* properties do not include requested ones */ + si = ports.erase (si); + continue; + } + } + + if (exclude) { + if ((mpi.properties & exclude)) { + /* properties include ones to avoid */ + si = ports.erase (si); + continue; + } + } + + ++si; + } } } @@ -270,7 +285,6 @@ PortManager::n_physical_inputs () const /** @param name Full or short name of port * @return Corresponding Port or 0. */ - boost::shared_ptr PortManager::get_port_by_name (const string& portname) { @@ -278,10 +292,10 @@ PortManager::get_port_by_name (const string& portname) return boost::shared_ptr(); } - if (!port_is_mine (portname)) { - /* not an ardour port */ - return boost::shared_ptr (); - } + if (!port_is_mine (portname)) { + /* not an ardour port */ + return boost::shared_ptr (); + } boost::shared_ptr pr = ports.reader(); std::string rel = make_port_name_relative (portname); @@ -289,10 +303,10 @@ PortManager::get_port_by_name (const string& portname) 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). - */ + * 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 (_backend->get_port_name (x->second->port_handle())); if (check != rel) { x->second->set_name (check); @@ -300,7 +314,7 @@ PortManager::get_port_by_name (const string& portname) return x->second; } - return boost::shared_ptr (); + return boost::shared_ptr (); } void @@ -656,6 +670,20 @@ PortManager::connect_callback (const string& a, const string& b, bool conn) port_b = x->second; } + if (conn) { + if (port_a && !port_b) { + port_a->increment_external_connections (); + } else if (port_b && !port_a) { + port_b->increment_external_connections (); + } + } else { + if (port_a && !port_b) { + port_a->decrement_external_connections (); + } else if (port_b && !port_a) { + port_b->decrement_external_connections (); + } + } + PortConnectedOrDisconnected ( port_a, a, port_b, b, @@ -746,24 +774,59 @@ PortManager::graph_order_callback () } void -PortManager::cycle_start (pframes_t nframes) +PortManager::cycle_start (pframes_t nframes, Session* s) { Port::set_global_port_buffer_offset (0); Port::set_cycle_samplecnt (nframes); _cycle_ports = ports.reader (); - // TODO parallelize - for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { - p->second->cycle_start (nframes); + /* TODO optimize + * - when speed == 1.0, the resampler copies data without processing + * it may (or may not) be more efficient to just run all in sequence. + * + * - single sequential task for 'lightweight' tasks would make sense + * (run it in parallel with 'heavy' resampling. + * * output ports (sends_output()) only set a flag + * * midi-ports only scale event timestamps + * + * - a threshold parallel vs searial processing may be appropriate. + * amount of work (how many connected ports are there, how + * many resamplers need to run) vs. available CPU cores and semaphore + * synchronization overhead. + * + * - input ports: it would make sense to resample each input only once + * (rather than resample into each ardour-owned input port). + * A single external source-port may be connected to many ardour + * input-ports. Currently re-sampling is per input. + */ + if (s && s->rt_tasklist () && fabs (Port::speed_ratio ()) != 1.0) { + RTTaskList::TaskList tl; + for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { + tl.push_back (boost::bind (&Port::cycle_start, p->second, nframes)); + } + s->rt_tasklist()->process (tl); + } else { + for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { + p->second->cycle_start (nframes); + } } } void -PortManager::cycle_end (pframes_t nframes) +PortManager::cycle_end (pframes_t nframes, Session* s) { - for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { - p->second->cycle_end (nframes); + // see optimzation note in ::cycle_start() + if (s && s->rt_tasklist () && fabs (Port::speed_ratio ()) != 1.0) { + RTTaskList::TaskList tl; + for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { + tl.push_back (boost::bind (&Port::cycle_end, p->second, nframes)); + } + s->rt_tasklist()->process (tl); + } else { + for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { + p->second->cycle_end (nframes); + } } for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { @@ -854,13 +917,27 @@ PortManager::check_monitoring () } void -PortManager::fade_out (gain_t base_gain, gain_t gain_step, pframes_t nframes) +PortManager::cycle_end_fade_out (gain_t base_gain, gain_t gain_step, pframes_t nframes, Session* s) { - for (Ports::iterator i = _cycle_ports->begin(); i != _cycle_ports->end(); ++i) { + // see optimzation note in ::cycle_start() + if (s && s->rt_tasklist () && fabs (Port::speed_ratio ()) != 1.0) { + RTTaskList::TaskList tl; + for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { + tl.push_back (boost::bind (&Port::cycle_end, p->second, nframes)); + } + s->rt_tasklist()->process (tl); + } else { + for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { + p->second->cycle_end (nframes); + } + } - if (i->second->sends_output()) { + for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) { + p->second->flush_buffers (nframes); + + if (p->second->sends_output()) { - boost::shared_ptr ap = boost::dynamic_pointer_cast (i->second); + boost::shared_ptr ap = boost::dynamic_pointer_cast (p->second); if (ap) { Sample* s = ap->engine_get_whole_audio_buffer (); gain_t g = base_gain; @@ -872,6 +949,8 @@ PortManager::fade_out (gain_t base_gain, gain_t gain_step, pframes_t nframes) } } } + _cycle_ports.reset (); + /* we are done */ } PortEngine& @@ -898,6 +977,10 @@ PortManager::port_is_control_only (std::string const& name) X_(".*Ableton Push.*"), X_(".*FaderPort .*"), X_(".*FaderPort8 .*"), + X_(".*FaderPort16 .*"), + X_(".*FaderPort2 .*"), + X_(".*US-2400 .*"), + X_(".*Mackie .*"), }; pattern = "("; @@ -1205,23 +1288,19 @@ PortManager::fill_midi_port_info_locked () if (!ph) { /* port info saved from some condition where this port * existed, but no longer does (i.e. device unplugged - * at present) + * at present). We don't remove it from midi_port_info. */ continue; } - if (!x->second.pretty_name.empty () && x->second.pretty_name != x->first) { - /* name set in port info ... propagate */ - _backend->set_port_property (ph, "http://jackaudio.org/metadata/pretty-name", x->second.pretty_name, string()); - } else { - /* check with backend for pre-existing pretty name */ - string value; - string type; - if (0 == _backend->get_port_property (ph, - "http://jackaudio.org/metadata/pretty-name", - value, type)) { - x->second.pretty_name = value; - } + /* check with backend for pre-existing pretty name */ + string value; + string type; + + if (0 == _backend->get_port_property (ph, + "http://jackaudio.org/metadata/pretty-name", + value, type)) { + x->second.pretty_name = value; } }