Consistent AU factory Preset IDs
[ardour.git] / libs / ardour / port_manager.cc
index 98b85e03b7f40e687564e009a5c73cb2fa4beafc..f5304f4961a59d4505e96fc51947f07269061dbe 100644 (file)
@@ -192,37 +192,51 @@ PortManager::port_is_physical (const std::string& portname) const
 void
 PortManager::filter_midi_ports (vector<string>& ports, MidiPortFlags include, MidiPortFlags exclude)
 {
+
        if (!include && !exclude) {
                return;
        }
 
-       for (vector<string>::iterator si = ports.begin(); si != ports.end(); ) {
+       {
+               Glib::Threads::Mutex::Lock lm (midi_port_info_mutex);
+
+               fill_midi_port_info_locked ();
 
-               PortManager::MidiPortInformation mpi = midi_port_information (*si);
+               for (vector<string>::iterator si = ports.begin(); si != ports.end(); ) {
 
-               if (mpi.pretty_name.empty()) {
-                       /* no information !!! */
-                       ++si;
-                       continue;
-               }
+                       MidiPortInfo::iterator x = midi_port_info.find (*si);
 
-               if (include) {
-                       if ((mpi.properties & include) != include) {
-                               /* properties do not include requested ones */
-                               si = ports.erase (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;
+               }
        }
 }
 
@@ -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,
@@ -755,7 +783,7 @@ PortManager::cycle_start (pframes_t nframes, Session* s)
 
        /* TODO optimize
         *  - when speed == 1.0, the resampler copies data without processing
-        *   it may be more efficient to just run all in sequence
+        *   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.
@@ -766,8 +794,13 @@ PortManager::cycle_start (pframes_t nframes, Session* s)
         *    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 */) {
+       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));
@@ -784,7 +817,7 @@ void
 PortManager::cycle_end (pframes_t nframes, Session* s)
 {
        // see optimzation note in ::cycle_start()
-       if (s && s->rt_tasklist () /* && fabs (Port::speed_ratio ()) != 1.0 */) {
+       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));
@@ -887,7 +920,7 @@ void
 PortManager::cycle_end_fade_out (gain_t base_gain, gain_t gain_step, pframes_t nframes, Session* s)
 {
        // see optimzation note in ::cycle_start()
-       if (s && s->rt_tasklist () /* && fabs (Port::speed_ratio ()) != 1.0 */) {
+       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));
@@ -944,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 = "(";
@@ -1251,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;
                }
        }