Small steps towards rolling backwards..
[ardour.git] / libs / ardour / port_manager.cc
index b99337a891dc831decadd74a3cb1bfb771f9f479..2b038142f89d30db6f1f61f6750f3c00442866ea 100644 (file)
@@ -27,7 +27,6 @@
 #include <glibmm/fileutils.h>
 #include <glibmm/miscutils.h>
 
-#include "pbd/convert.h"
 #include "pbd/error.h"
 
 #include "ardour/async_midi_port.h"
@@ -39,7 +38,9 @@
 #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"
 
 #include "pbd/i18n.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
@@ -270,7 +271,6 @@ PortManager::n_physical_inputs () const
 /** @param name Full or short name of port
  *  @return Corresponding Port or 0.
  */
-
 boost::shared_ptr<Port>
 PortManager::get_port_by_name (const string& portname)
 {
@@ -278,10 +278,10 @@ PortManager::get_port_by_name (const string& portname)
                return boost::shared_ptr<Port>();
        }
 
-        if (!port_is_mine (portname)) {
-                /* not an ardour port */
-                return boost::shared_ptr<Port> ();
-        }
+       if (!port_is_mine (portname)) {
+               /* not an ardour port */
+               return boost::shared_ptr<Port> ();
+       }
 
        boost::shared_ptr<Ports> pr = ports.reader();
        std::string rel = make_port_name_relative (portname);
@@ -289,10 +289,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 +300,7 @@ PortManager::get_port_by_name (const string& portname)
                return x->second;
        }
 
-        return boost::shared_ptr<Port> ();
+       return boost::shared_ptr<Port> ();
 }
 
 void
@@ -746,23 +746,39 @@ 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_framecnt (nframes);
+       Port::set_cycle_samplecnt (nframes);
 
        _cycle_ports = ports.reader ();
 
-       for (Ports::iterator p = _cycle_ports->begin(); p != _cycle_ports->end(); ++p) {
-               p->second->cycle_start (nframes);
+       if (s && s->rt_tasklist ()) {
+               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);
+       if (s && s->rt_tasklist ()) {
+               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) {
@@ -853,13 +869,26 @@ 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) {
+       if (s && s->rt_tasklist ()) {
+               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<AudioPort> ap = boost::dynamic_pointer_cast<AudioPort> (i->second);
+                       boost::shared_ptr<AudioPort> ap = boost::dynamic_pointer_cast<AudioPort> (p->second);
                        if (ap) {
                                Sample* s = ap->engine_get_whole_audio_buffer ();
                                gain_t g = base_gain;
@@ -871,6 +900,8 @@ PortManager::fade_out (gain_t base_gain, gain_t gain_step, pframes_t nframes)
                        }
                }
        }
+       _cycle_ports.reset ();
+       /* we are done */
 }
 
 PortEngine&
@@ -896,6 +927,7 @@ PortManager::port_is_control_only (std::string const& name)
                const char * const control_only_ports[] = {
                        X_(".*Ableton Push.*"),
                        X_(".*FaderPort .*"),
+                       X_(".*FaderPort8 .*"),
                };
 
                pattern = "(";
@@ -1068,9 +1100,9 @@ PortManager::save_midi_port_info ()
 
                for (MidiPortInfo::iterator i = midi_port_info.begin(); i != midi_port_info.end(); ++i) {
                        XMLNode* node = new XMLNode (X_("port"));
-                       node->add_property (X_("name"), i->first);
-                       node->add_property (X_("input"), i->second.input ? X_("yes") : X_("no"));
-                       node->add_property (X_("properties"), enum_2_string (i->second.properties));
+                       node->set_property (X_("name"), i->first);
+                       node->set_property (X_("input"), i->second.input);
+                       node->set_property (X_("properties"), i->second.properties);
                        root->add_child_nocopy (*node);
                }
        }
@@ -1102,26 +1134,14 @@ PortManager::load_midi_port_info ()
        midi_port_info.clear ();
 
        for (XMLNodeConstIterator i = tree.root()->children().begin(); i != tree.root()->children().end(); ++i) {
-               XMLProperty const* prop;
                MidiPortInformation mpi;
                string name;
 
-               if ((prop = (*i)->property (X_("name"))) == 0) {
-                       continue;
-               }
-
-               name = prop->value ();
-
-               if ((prop = (*i)->property (X_("input"))) == 0) {
+               if (!(*i)->get_property (X_("name"), name) ||
+                   !(*i)->get_property (X_("input"), mpi.input) ||
+                   !(*i)->get_property (X_("properties"), mpi.properties)) {
                        continue;
                }
-               mpi.input = string_is_affirmative (prop->value());
-
-               if ((prop = (*i)->property (X_("properties"))) == 0) {
-                       continue;
-               }
-
-               mpi.properties = (MidiPortFlags) string_2_enum (prop->value(), mpi.properties);
 
                midi_port_info.insert (make_pair (name, mpi));
        }
@@ -1203,22 +1223,34 @@ PortManager::fill_midi_port_info_locked ()
         * PortManager
         */
 
+       // rg: I don't understand what this attempts to solve
+       //
+       // Naming ports should be left to the backend:
+       // Ardour cannot associate numeric IDs with corresponding hardware.
+       // (see also 7dde6c3b)
+
        for (MidiPortInfo::iterator x = midi_port_info.begin(); x != midi_port_info.end(); ++x) {
                PortEngine::PortHandle ph = _backend->get_port_by_name (x->first);
 
-               if (x->second.pretty_name != x->first) {
+               if (!ph) {
+                       /* port info saved from some condition where this port
+                        * existed, but no longer does (i.e. device unplugged
+                        * at present)
+                        */
+                       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 */
-                       if (ph) {
-                               string value;
-                               string type;
-                               if (0 == _backend->get_port_property (ph,
-                                                                     "http://jackaudio.org/metadata/pretty-name",
-                                                                     value, type)) {
-                                       x->second.pretty_name = value;
-                               }
+                       string value;
+                       string type;
+                       if (0 == _backend->get_port_property (ph,
+                                                             "http://jackaudio.org/metadata/pretty-name",
+                                                             value, type)) {
+                               x->second.pretty_name = value;
                        }
                }
        }