Large nasty commit in the form of a 5000 line patch chock-full of completely
[ardour.git] / libs / ardour / io.cc
index 2f04b7eaca380e595a9528ff20eaaf119f2aa6b2..82253964864757ad241058cb258c42eba5ee9ac4 100644 (file)
@@ -55,7 +55,8 @@ extern "C" int isinf (double);
 
 using namespace std;
 using namespace ARDOUR;
-//using namespace sigc;
+using namespace PBD;
+
 
 static float current_automation_version_number = 1.0;
 
@@ -96,11 +97,18 @@ static bool sort_ports_by_name (Port* a, Port* b)
 }
 
 
+/** The 'default_type' argument here isn't very good, but port creation is too 
+ * brufty and all over the place to make anything else feasible without massive
+ * changes.  The default typed passed is the type of port that will be created
+ * by ensure_io and friends.  This is a temporary compatibility hack to get
+ * multiple data types off the gound and should be removed.
+ */
 IO::IO (Session& s, string name,
-
-       int input_min, int input_max, int output_min, int output_max)
+       int input_min, int input_max, int output_min, int output_max,
+       Buffer::Type default_type)
        : _session (s),
          _name (name),
+         _default_type(default_type),
          _midi_gain_control (*this, _session.midi_port()),
          _gain_automation_curve (0.0, 2.0, 1.0),
          _input_minimum (input_min),
@@ -784,11 +792,20 @@ IO::remove_output_port (Port* port, void* src)
        return -1;
 }
 
+/** Add an output port.
+ *
+ * @param destination Name of input port to connect new port to.
+ * @param src Source for emitted ConfigurationChanged signal.
+ * @param type Data type of port.  Default value (Buffer::NIL) will use this IO's default type.
+ */
 int
-IO::add_output_port (string destination, void* src)
+IO::add_output_port (string destination, void* src, Buffer::Type type)
 {
        Port* our_port;
-       char buf[64];
+       char name[64];
+
+       if (type == Buffer::NIL)
+               type = _default_type;
 
        {
                Glib::Mutex::Lock em(_session.engine().process_lock());
@@ -802,14 +819,15 @@ IO::add_output_port (string destination, void* src)
                
                        /* Create a new output port */
                        
+                       // FIXME: naming scheme for differently typed ports?
                        if (_output_maximum == 1) {
-                               snprintf (buf, sizeof (buf), _("%s/out"), _name.c_str());
+                               snprintf (name, sizeof (name), _("%s/out"), _name.c_str());
                        } else {
-                               snprintf (buf, sizeof (buf), _("%s/out %u"), _name.c_str(), find_output_port_hole());
+                               snprintf (name, sizeof (name), _("%s/out %u"), _name.c_str(), find_output_port_hole());
                        }
                        
-                       if ((our_port = _session.engine().register_audio_output_port (buf)) == 0) {
-                               error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg;
+                       if ((our_port = _session.engine().register_output_port (type, name)) == 0) {
+                               error << string_compose(_("IO: cannot register output port %1"), name) << endmsg;
                                return -1;
                        }
                        
@@ -885,11 +903,21 @@ IO::remove_input_port (Port* port, void* src)
        return -1;
 }
 
+
+/** Add an input port.
+ *
+ * @param type Data type of port.  The appropriate Jack port type, and @ref Port will be created.
+ * @param destination Name of input port to connect new port to.
+ * @param src Source for emitted ConfigurationChanged signal.
+ */
 int
-IO::add_input_port (string source, void* src)
+IO::add_input_port (string source, void* src, Buffer::Type type)
 {
        Port* our_port;
-       char buf[64];
+       char name[64];
+       
+       if (type == Buffer::NIL)
+               type = _default_type;
 
        {
                Glib::Mutex::Lock em (_session.engine().process_lock());
@@ -903,14 +931,15 @@ IO::add_input_port (string source, void* src)
 
                        /* Create a new input port */
                        
+                       // FIXME: naming scheme for differently typed ports?
                        if (_input_maximum == 1) {
-                               snprintf (buf, sizeof (buf), _("%s/in"), _name.c_str());
+                               snprintf (name, sizeof (name), _("%s/in"), _name.c_str());
                        } else {
-                               snprintf (buf, sizeof (buf), _("%s/in %u"), _name.c_str(), find_input_port_hole());
+                               snprintf (name, sizeof (name), _("%s/in %u"), _name.c_str(), find_input_port_hole());
                        }
                        
-                       if ((our_port = _session.engine().register_audio_input_port (buf)) == 0) {
-                               error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg;
+                       if ((our_port = _session.engine().register_input_port (type, name)) == 0) {
+                               error << string_compose(_("IO: cannot register input port %1"), name) << endmsg;
                                return -1;
                        }
                        
@@ -1006,6 +1035,8 @@ IO::ensure_inputs_locked (uint32_t n, bool clear, void* src)
                
                /* Create a new input port */
                
+               // FIXME: of what type?
+
                if (_input_maximum == 1) {
                        snprintf (buf, sizeof (buf), _("%s/in"), _name.c_str());
                }
@@ -1015,7 +1046,7 @@ IO::ensure_inputs_locked (uint32_t n, bool clear, void* src)
                
                try {
                        
-                       if ((input_port = _session.engine().register_audio_input_port (buf)) == 0) {
+                       if ((input_port = _session.engine().register_input_port (_default_type, buf)) == 0) {
                                error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg;
                                return -1;
                        }
@@ -1106,6 +1137,8 @@ IO::ensure_io (uint32_t nin, uint32_t nout, bool clear, void* src)
                
                /* create any necessary new ports */
                
+               // FIXME: of what type?
+
                while (_ninputs < nin) {
                        
                        char buf[64];
@@ -1120,7 +1153,7 @@ IO::ensure_io (uint32_t nin, uint32_t nout, bool clear, void* src)
                        }
                        
                        try {
-                               if ((port = _session.engine().register_audio_input_port (buf)) == 0) {
+                               if ((port = _session.engine().register_input_port (_default_type, buf)) == 0) {
                                        error << string_compose(_("IO: cannot register input port %1"), buf) << endmsg;
                                        return -1;
                                }
@@ -1153,7 +1186,7 @@ IO::ensure_io (uint32_t nin, uint32_t nout, bool clear, void* src)
                        }
                        
                        try { 
-                               if ((port = _session.engine().register_audio_output_port (buf)) == 0) {
+                               if ((port = _session.engine().register_output_port (_default_type, buf)) == 0) {
                                        error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg;
                                        return -1;
                                }
@@ -1278,7 +1311,7 @@ IO::ensure_outputs_locked (uint32_t n, bool clear, void* src)
                        snprintf (buf, sizeof (buf), _("%s/out %u"), _name.c_str(), find_output_port_hole());
                }
                
-               if ((output_port = _session.engine().register_audio_output_port (buf)) == 0) {
+               if ((output_port = _session.engine().register_output_port (_default_type, buf)) == 0) {
                        error << string_compose(_("IO: cannot register output port %1"), buf) << endmsg;
                        return -1;
                }