optimize some performance bottlenecks; remove jack_nframes_t that crept back into...
[ardour.git] / libs / ardour / io.cc
index 57a89b2310613f269f6ac6939313ba35197586c6..67f365a400ab6b61316463f15b506bb2fb08b548 100644 (file)
@@ -27,6 +27,7 @@
 #include <glibmm/thread.h>
 
 #include <pbd/xml++.h>
+#include <pbd/replace_all.h>
 
 #include <ardour/audioengine.h>
 #include <ardour/io.h>
@@ -55,15 +56,14 @@ extern "C" int isnan (double);
 extern "C" int isinf (double);
 #endif
 
+#define BLOCK_PROCESS_CALLBACK() Glib::Mutex::Lock em (_session.engine().process_lock())
 
 using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
+nframes_t    IO::_automation_interval = 0;
 
-static float current_automation_version_number = 1.0;
-
-jack_nframes_t               IO::_automation_interval = 0;
 const string                 IO::state_node_name = "IO";
 bool                         IO::connecting_legal = false;
 bool                         IO::ports_legal = false;
@@ -105,7 +105,7 @@ IO::IO (Session& s, string name,
       _output_buffers(new BufferSet()),
          _name (name),
          _default_type(default_type),
-         _gain_control (*this),
+         _gain_control (X_("gaincontrol"), *this),
          _gain_automation_curve (0.0, 2.0, 1.0),
          _input_minimum (ChanCount::ZERO),
          _input_maximum (ChanCount::INFINITE),
@@ -138,7 +138,7 @@ IO::IO (Session& s, string name,
        deferred_state = 0;
 
        apply_gain_automation = false;
-
+       
        last_automation_snapshot = 0;
 
        _gain_automation_state = Off;
@@ -153,6 +153,43 @@ IO::IO (Session& s, string name,
        
        // Connect to our own MoreChannels signal to connect output buffers
        IO::MoreChannels.connect (mem_fun (*this, &IO::attach_buffers));
+
+       _session.add_controllable (&_gain_control);
+}
+
+IO::IO (Session& s, const XMLNode& node, DataType dt)
+       : _session (s),
+      _output_buffers(new BufferSet()),
+         _default_type (dt),
+         _gain_control (X_("gaincontrol"), *this),
+         _gain_automation_curve (0, 0, 0) // all reset in set_state()
+{
+       // FIXME: hack
+       _meter = new PeakMeter (_session);
+
+       _panner = 0;
+       deferred_state = 0;
+       no_panner_reset = false;
+       _desired_gain = 1.0;
+       _gain = 1.0;
+       _input_connection = 0;
+       _output_connection = 0;
+
+       apply_gain_automation = false;
+
+       set_state (node);
+
+       {
+               // IO::Meter is emitted from another thread so the
+               // Meter signal must be protected.
+               Glib::Mutex::Lock guard (m_meter_signal_lock);
+               m_meter_connection = Meter.connect (mem_fun (*this, &IO::meter));
+       }
+       
+       // Connect to our own MoreChannels signal to connect output buffers
+       IO::MoreChannels.connect (mem_fun (*this, &IO::attach_buffers));
+
+       _session.add_controllable (&_gain_control);
 }
 
 IO::~IO ()
@@ -177,7 +214,7 @@ IO::~IO ()
 }
 
 void
-IO::silence (jack_nframes_t nframes, jack_nframes_t offset)
+IO::silence (nframes_t nframes, nframes_t offset)
 {
        /* io_lock, not taken: function must be called from Session::process() calltree */
 
@@ -192,10 +229,9 @@ IO::silence (jack_nframes_t nframes, jack_nframes_t offset)
  * to the outputs, eg applying gain or pan or whatever else needs to be done.
  */
 void
-IO::deliver_output (BufferSet& bufs, jack_nframes_t start_frame, jack_nframes_t end_frame, jack_nframes_t nframes, jack_nframes_t offset)
+IO::deliver_output (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
 {
        // FIXME: type specific code doesn't actually need to be here, it will go away in time
-       
 
        /* ********** AUDIO ********** */
 
@@ -210,6 +246,7 @@ IO::deliver_output (BufferSet& bufs, jack_nframes_t start_frame, jack_nframes_t
                        if (dm.locked()) {
                                dg = _desired_gain;
                        }
+
                }
 
                Amp::run(bufs, nframes, _gain, dg, _phase_invert);
@@ -248,7 +285,7 @@ IO::deliver_output (BufferSet& bufs, jack_nframes_t start_frame, jack_nframes_t
 }
 
 void
-IO::collect_input (BufferSet& outs, jack_nframes_t nframes, jack_nframes_t offset)
+IO::collect_input (BufferSet& outs, nframes_t nframes, nframes_t offset)
 {
        assert(outs.available() >= n_inputs());
 
@@ -268,8 +305,8 @@ IO::collect_input (BufferSet& outs, jack_nframes_t nframes, jack_nframes_t offse
 }
 
 void
-IO::just_meter_input (jack_nframes_t start_frame, jack_nframes_t end_frame, 
-                     jack_nframes_t nframes, jack_nframes_t offset)
+IO::just_meter_input (nframes_t start_frame, nframes_t end_frame, 
+                     nframes_t nframes, nframes_t offset)
 {
        BufferSet& bufs = _session.get_scratch_buffers (n_inputs());
 
@@ -304,7 +341,7 @@ IO::disconnect_input (Port* our_port, string other_port, void* src)
        }
 
        { 
-               Glib::Mutex::Lock em (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                
                {
                        Glib::Mutex::Lock lm (io_lock);
@@ -340,7 +377,7 @@ IO::connect_input (Port* our_port, string other_port, void* src)
        }
 
        {
-               Glib::Mutex::Lock em(_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                
                {
                        Glib::Mutex::Lock lm (io_lock);
@@ -374,7 +411,7 @@ IO::disconnect_output (Port* our_port, string other_port, void* src)
        }
 
        {
-               Glib::Mutex::Lock em(_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                
                {
                        Glib::Mutex::Lock lm (io_lock);
@@ -409,7 +446,8 @@ IO::connect_output (Port* our_port, string other_port, void* src)
        }
 
        {
-               Glib::Mutex::Lock em(_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
+
                
                {
                        Glib::Mutex::Lock lm (io_lock);
@@ -468,7 +506,8 @@ IO::remove_output_port (Port* port, void* src)
        IOChange change (NoChange);
 
        {
-               Glib::Mutex::Lock em(_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
+
                
                {
                        Glib::Mutex::Lock lm (io_lock);
@@ -519,7 +558,8 @@ IO::add_output_port (string destination, void* src, DataType type)
                type = _default_type;
 
        {
-               Glib::Mutex::Lock em(_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
+
                
                { 
                        Glib::Mutex::Lock lm (io_lock);
@@ -570,7 +610,8 @@ IO::remove_input_port (Port* port, void* src)
        IOChange change (NoChange);
 
        {
-               Glib::Mutex::Lock em(_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
+
                
                {
                        Glib::Mutex::Lock lm (io_lock);
@@ -622,7 +663,7 @@ IO::add_input_port (string source, void* src, DataType type)
                type = _default_type;
 
        {
-               Glib::Mutex::Lock em (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                
                { 
                        Glib::Mutex::Lock lm (io_lock);
@@ -672,7 +713,7 @@ int
 IO::disconnect_inputs (void* src)
 {
        { 
-               Glib::Mutex::Lock em (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                
                {
                        Glib::Mutex::Lock lm (io_lock);
@@ -694,7 +735,7 @@ int
 IO::disconnect_outputs (void* src)
 {
        {
-               Glib::Mutex::Lock em (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                
                {
                        Glib::Mutex::Lock lm (io_lock);
@@ -758,7 +799,7 @@ IO::ensure_inputs_locked (ChanCount count, bool clear, void* src)
                                setup_peak_meters ();
                                reset_panner ();
                                /* pass it on */
-                               throw err;
+                               throw AudioEngine::PortRegistrationFailure();
                        }
 
                        _inputs.add (input_port);
@@ -810,7 +851,7 @@ IO::ensure_io (ChanCount in, ChanCount out, bool clear, void* src)
        }
 
        {
-               Glib::Mutex::Lock em (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                Glib::Mutex::Lock lm (io_lock);
 
                Port* port;
@@ -869,12 +910,12 @@ IO::ensure_io (ChanCount in, ChanCount out, bool clear, void* src)
                                                return -1;
                                        }
                                }
-
+                               
                                catch (AudioEngine::PortRegistrationFailure& err) {
                                        setup_peak_meters ();
                                        reset_panner ();
                                        /* pass it on */
-                                       throw err;
+                                       throw AudioEngine::PortRegistrationFailure();
                                }
 
                                _inputs.add (port);
@@ -906,7 +947,7 @@ IO::ensure_io (ChanCount in, ChanCount out, bool clear, void* src)
                                        setup_peak_meters ();
                                        reset_panner ();
                                        /* pass it on */
-                                       throw err;
+                                       throw AudioEngine::PortRegistrationFailure ();
                                }
 
                                _outputs.add (port);
@@ -963,7 +1004,7 @@ IO::ensure_inputs (ChanCount count, bool clear, bool lockit, void* src)
        }
 
        if (lockit) {
-               Glib::Mutex::Lock em (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                Glib::Mutex::Lock im (io_lock);
                changed = ensure_inputs_locked (count, clear, src);
        } else {
@@ -1060,7 +1101,7 @@ IO::ensure_outputs (ChanCount count, bool clear, bool lockit, void* src)
        /* XXX caller should hold io_lock, but generally doesn't */
 
        if (lockit) {
-               Glib::Mutex::Lock em (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                Glib::Mutex::Lock im (io_lock);
                changed = ensure_outputs_locked (count, clear, src);
        } else {
@@ -1138,7 +1179,7 @@ IO::state (bool full_state)
        Glib::Mutex::Lock lm (io_lock);
 
        node->add_property("name", _name);
-       id().print (buf);
+       id().print (buf, sizeof (buf));
        node->add_property("id", buf);
 
        str = "";
@@ -1220,6 +1261,7 @@ IO::state (bool full_state)
        }
 
        node->add_child_nocopy (_panner->state (full_state));
+       node->add_child_nocopy (_gain_control.get_state ());
 
        snprintf (buf, sizeof(buf), "%2.12f", gain());
        node->add_property ("gain", buf);
@@ -1237,66 +1279,20 @@ IO::state (bool full_state)
        /* automation */
 
        if (full_state) {
+
+               XMLNode* autonode = new XMLNode (X_("Automation"));
+               autonode->add_child_nocopy (get_automation_state());
+               node->add_child_nocopy (*autonode);
+
                snprintf (buf, sizeof (buf), "0x%x", (int) _gain_automation_curve.automation_state());
        } else {
                /* never store anything except Off for automation state in a template */
                snprintf (buf, sizeof (buf), "0x%x", ARDOUR::Off); 
        }
-       node->add_property ("automation-state", buf);
-       snprintf (buf, sizeof (buf), "0x%x", (int) _gain_automation_curve.automation_style());
-       node->add_property ("automation-style", buf);
-
-       /* XXX same for pan etc. */
 
        return *node;
 }
 
-int
-IO::connecting_became_legal ()
-{
-       int ret;
-
-       if (pending_state_node == 0) {
-               fatal << _("IO::connecting_became_legal() called without a pending state node") << endmsg;
-               /*NOTREACHED*/
-               return -1;
-       }
-
-       connection_legal_c.disconnect ();
-
-       ret = make_connections (*pending_state_node);
-
-       if (ports_legal) {
-               delete pending_state_node;
-               pending_state_node = 0;
-       }
-
-       return ret;
-}
-
-int
-IO::ports_became_legal ()
-{
-       int ret;
-
-       if (pending_state_node == 0) {
-               fatal << _("IO::ports_became_legal() called without a pending state node") << endmsg;
-               /*NOTREACHED*/
-               return -1;
-       }
-
-       port_legal_c.disconnect ();
-
-       ret = create_ports (*pending_state_node);
-
-       if (connecting_legal) {
-               delete pending_state_node;
-               pending_state_node = 0;
-       }
-
-       return ret;
-}
-
 int
 IO::set_state (const XMLNode& node)
 {
@@ -1315,7 +1311,7 @@ IO::set_state (const XMLNode& node)
 
        if ((prop = node.property ("name")) != 0) {
                _name = prop->value();
-               _panner->set_name (_name);
+               /* used to set panner name with this, but no more */
        } 
 
        if ((prop = node.property ("id")) != 0) {
@@ -1341,26 +1337,31 @@ IO::set_state (const XMLNode& node)
                _gain = _desired_gain;
        }
 
+       if ((prop = node.property ("automation-state")) != 0 || (prop = node.property ("automation-style")) != 0) {
+               /* old school automation handling */
+       }
+
        for (iter = node.children().begin(); iter != node.children().end(); ++iter) {
+
                if ((*iter)->name() == "Panner") {
+                       if (_panner == 0) {
+                               _panner = new Panner (_name, _session);
+                       }
                        _panner->set_state (**iter);
                }
-       }
 
-       if ((prop = node.property ("automation-state")) != 0) {
+               if ((*iter)->name() == X_("Automation")) {
 
-               long int x;
-               x = strtol (prop->value().c_str(), 0, 16);
-               set_gain_automation_state (AutoState (x));
-       }
-
-       if ((prop = node.property ("automation-style")) != 0) {
+                       set_automation_state (*(*iter)->children().front());
+               }
 
-              long int x;
-               x = strtol (prop->value().c_str(), 0, 16);
-               set_gain_automation_style (AutoStyle (x));
+               if ((*iter)->name() == X_("controllable")) {
+                       if ((prop = (*iter)->property("name")) != 0 && prop->value() == "gaincontrol") {
+                               _gain_control.set_state (**iter);
+                       }
+               }
        }
-       
+
        if (ports_legal) {
 
                if (create_ports (node)) {
@@ -1393,9 +1394,146 @@ IO::set_state (const XMLNode& node)
                pending_state_node = new XMLNode (node);
        }
 
+       last_automation_snapshot = 0;
+
        return 0;
 }
 
+int
+IO::set_automation_state (const XMLNode& node)
+{
+       return _gain_automation_curve.set_state (node);
+}
+
+XMLNode&
+IO::get_automation_state ()
+{
+       return (_gain_automation_curve.get_state ());
+}
+
+int
+IO::load_automation (string path)
+{
+       string fullpath;
+       ifstream in;
+       char line[128];
+       uint32_t linecnt = 0;
+       float version;
+       LocaleGuard lg (X_("POSIX"));
+
+       fullpath = _session.automation_dir();
+       fullpath += path;
+
+       in.open (fullpath.c_str());
+
+       if (!in) {
+               fullpath = _session.automation_dir();
+               fullpath += _session.snap_name();
+               fullpath += '-';
+               fullpath += path;
+
+               in.open (fullpath.c_str());
+
+               if (!in) {
+                       error << string_compose(_("%1: cannot open automation event file \"%2\""), _name, fullpath) << endmsg;
+                       return -1;
+               }
+       }
+
+       clear_automation ();
+
+       while (in.getline (line, sizeof(line), '\n')) {
+               char type;
+               nframes_t when;
+               double value;
+
+               if (++linecnt == 1) {
+                       if (memcmp (line, "version", 7) == 0) {
+                               if (sscanf (line, "version %f", &version) != 1) {
+                                       error << string_compose(_("badly formed version number in automation event file \"%1\""), path) << endmsg;
+                                       return -1;
+                               }
+                       } else {
+                               error << string_compose(_("no version information in automation event file \"%1\""), path) << endmsg;
+                               return -1;
+                       }
+
+                       continue;
+               }
+
+               if (sscanf (line, "%c %" PRIu32 " %lf", &type, &when, &value) != 3) {
+                       warning << string_compose(_("badly formatted automation event record at line %1 of %2 (ignored)"), linecnt, path) << endmsg;
+                       continue;
+               }
+
+               switch (type) {
+               case 'g':
+                       _gain_automation_curve.fast_simple_add (when, value);
+                       break;
+
+               case 's':
+                       break;
+
+               case 'm':
+                       break;
+
+               case 'p':
+                       /* older (pre-1.0) versions of ardour used this */
+                       break;
+
+               default:
+                       warning << _("dubious automation event found (and ignored)") << endmsg;
+               }
+       }
+
+       return 0;
+}
+
+int
+IO::connecting_became_legal ()
+{
+       int ret;
+
+       if (pending_state_node == 0) {
+               fatal << _("IO::connecting_became_legal() called without a pending state node") << endmsg;
+               /*NOTREACHED*/
+               return -1;
+       }
+
+       connection_legal_c.disconnect ();
+
+       ret = make_connections (*pending_state_node);
+
+       if (ports_legal) {
+               delete pending_state_node;
+               pending_state_node = 0;
+       }
+
+       return ret;
+}
+int
+IO::ports_became_legal ()
+{
+       int ret;
+
+       if (pending_state_node == 0) {
+               fatal << _("IO::ports_became_legal() called without a pending state node") << endmsg;
+               /*NOTREACHED*/
+               return -1;
+       }
+
+       port_legal_c.disconnect ();
+
+       ret = create_ports (*pending_state_node);
+
+       if (connecting_legal) {
+               delete pending_state_node;
+               pending_state_node = 0;
+       }
+
+       return ret;
+}
+
 int
 IO::create_ports (const XMLNode& node)
 {
@@ -1680,6 +1818,12 @@ IO::set_name (string name, void* src)
                return 0;
        }
 
+       /* replace all colons in the name. i wish we didn't have to do this */
+
+       if (replace_all (name, ":", "-")) {
+               warning << _("you cannot use colons to name objects with I/O connections") << endmsg;
+       }
+
        for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
                string current_name = i->short_name();
                current_name.replace (current_name.find (_name), _name.length(), name);
@@ -1698,42 +1842,6 @@ IO::set_name (string name, void* src)
         return 0;
 }
 
-void
-IO::set_input_minimum (int n)
-{
-       if (n < 0)
-               _input_minimum = ChanCount::ZERO;
-       else
-               _input_minimum = ChanCount(_default_type, n);
-}
-
-void
-IO::set_input_maximum (int n)
-{
-       if (n < 0)
-               _input_maximum = ChanCount::INFINITE;
-       else
-               _input_maximum = ChanCount(_default_type, n);
-}
-
-void
-IO::set_output_minimum (int n)
-{
-       if (n < 0)
-               _output_minimum = ChanCount::ZERO;
-       else
-               _output_minimum = ChanCount(_default_type, n);
-}
-
-void
-IO::set_output_maximum (int n)
-{
-       if (n < 0)
-               _output_maximum = ChanCount::INFINITE;
-       else
-               _output_maximum = ChanCount(_default_type, n);
-}
-
 void
 IO::set_input_minimum (ChanCount n)
 {
@@ -1759,7 +1867,7 @@ IO::set_output_maximum (ChanCount n)
 }
 
 void
-IO::set_port_latency (jack_nframes_t nframes)
+IO::set_port_latency (nframes_t nframes)
 {
        Glib::Mutex::Lock lm (io_lock);
 
@@ -1768,11 +1876,11 @@ IO::set_port_latency (jack_nframes_t nframes)
        }
 }
 
-jack_nframes_t
+nframes_t
 IO::output_latency () const
 {
-       jack_nframes_t max_latency;
-       jack_nframes_t latency;
+       nframes_t max_latency;
+       nframes_t latency;
 
        max_latency = 0;
 
@@ -1787,11 +1895,11 @@ IO::output_latency () const
        return max_latency;
 }
 
-jack_nframes_t
+nframes_t
 IO::input_latency () const
 {
-       jack_nframes_t max_latency;
-       jack_nframes_t latency;
+       nframes_t max_latency;
+       nframes_t latency;
 
        max_latency = 0;
 
@@ -1812,7 +1920,7 @@ IO::use_input_connection (Connection& c, void* src)
        uint32_t limit;
 
        {
-               Glib::Mutex::Lock lm (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                Glib::Mutex::Lock lm2 (io_lock);
                
                limit = c.nports();
@@ -1891,7 +1999,7 @@ IO::use_output_connection (Connection& c, void* src)
        uint32_t limit; 
 
        {
-               Glib::Mutex::Lock lm (_session.engine().process_lock());
+               BLOCK_PROCESS_CALLBACK ();
                Glib::Mutex::Lock lm2 (io_lock);
 
                limit = c.nports();
@@ -2043,25 +2151,6 @@ IO::GainControllable::get_value (void) const
        return direct_gain_to_control (io.effective_gain());
 }
 
-UndoAction
-IO::get_memento() const
-{
-  return sigc::bind (mem_fun (*(const_cast<IO *>(this)), &StateManager::use_state), _current_state_id);
-}
-
-Change
-IO::restore_state (StateManager::State& state)
-{
-       return Change (0);
-}
-
-StateManager::State*
-IO::state_factory (std::string why) const
-{
-       StateManager::State* state = new StateManager::State (why);
-       return state;
-}
-
 void
 IO::setup_peak_meters()
 {
@@ -2087,124 +2176,12 @@ IO::update_meters()
 void
 IO::meter ()
 {
-       // FIXME: Remove this function and just connect signal directly to PeakMeter::meter
+       // FIXME: Ugly.  Meter should manage the lock, if it's necessary
        
        Glib::Mutex::Lock lm (io_lock); // READER: meter thread.
        _meter->meter();
 }
 
-int
-IO::save_automation (const string& path)
-{
-       string fullpath;
-       ofstream out;
-
-       fullpath = _session.automation_dir();
-       fullpath += path;
-
-       out.open (fullpath.c_str());
-
-       if (!out) {
-               error << string_compose(_("%1: could not open automation event file \"%2\""), _name, fullpath) << endmsg;
-               return -1;
-       }
-
-       out << X_("version ") << current_automation_version_number << endl;
-
-       /* XXX use apply_to_points to get thread safety */
-       
-       for (AutomationList::iterator i = _gain_automation_curve.begin(); i != _gain_automation_curve.end(); ++i) {
-               out << "g " << (jack_nframes_t) floor ((*i)->when) << ' ' << (*i)->value << endl;
-       }
-
-       _panner->save ();
-
-       return 0;
-}
-
-int
-IO::load_automation (const string& path)
-{
-       string fullpath;
-       ifstream in;
-       char line[128];
-       uint32_t linecnt = 0;
-       float version;
-       LocaleGuard lg (X_("POSIX"));
-
-       fullpath = _session.automation_dir();
-       fullpath += path;
-
-       in.open (fullpath.c_str());
-
-       if (!in) {
-               fullpath = _session.automation_dir();
-               fullpath += _session.snap_name();
-               fullpath += '-';
-               fullpath += path;
-               in.open (fullpath.c_str());
-               if (!in) {
-                       error << string_compose(_("%1: cannot open automation event file \"%2\" (%2)"), _name, fullpath, strerror (errno)) << endmsg;
-                       return -1;
-               }
-       }
-
-       clear_automation ();
-
-       while (in.getline (line, sizeof(line), '\n')) {
-               char type;
-               jack_nframes_t when;
-               double value;
-
-               if (++linecnt == 1) {
-                       if (memcmp (line, "version", 7) == 0) {
-                               if (sscanf (line, "version %f", &version) != 1) {
-                                       error << string_compose(_("badly formed version number in automation event file \"%1\""), path) << endmsg;
-                                       return -1;
-                               }
-                       } else {
-                               error << string_compose(_("no version information in automation event file \"%1\""), path) << endmsg;
-                               return -1;
-                       }
-
-                       if (version != current_automation_version_number) {
-                               error << string_compose(_("mismatched automation event file version (%1)"), version) << endmsg;
-                               return -1;
-                       }
-
-                       continue;
-               }
-
-               if (sscanf (line, "%c %" PRIu32 " %lf", &type, &when, &value) != 3) {
-                       warning << string_compose(_("badly formatted automation event record at line %1 of %2 (ignored)"), linecnt, path) << endmsg;
-                       continue;
-               }
-
-               switch (type) {
-               case 'g':
-                       _gain_automation_curve.add (when, value, true);
-                       break;
-
-               case 's':
-                       break;
-
-               case 'm':
-                       break;
-
-               case 'p':
-                       /* older (pre-1.0) versions of ardour used this */
-                       break;
-
-               default:
-                       warning << _("dubious automation event found (and ignored)") << endmsg;
-               }
-       }
-
-       _gain_automation_curve.save_state (_("loaded from disk"));
-
-       return 0;
-}
-       
 void
 IO::clear_automation ()
 {
@@ -2322,7 +2299,7 @@ IO::end_pan_touch (uint32_t which)
 }
 
 void
-IO::automation_snapshot (jack_nframes_t now)
+IO::automation_snapshot (nframes_t now)
 {
        if (last_automation_snapshot > now || (now - last_automation_snapshot) > _automation_interval) {
 
@@ -2337,16 +2314,12 @@ IO::automation_snapshot (jack_nframes_t now)
 }
 
 void
-IO::transport_stopped (jack_nframes_t frame)
+IO::transport_stopped (nframes_t frame)
 {
        _gain_automation_curve.reposition_for_rt_add (frame);
 
        if (_gain_automation_curve.automation_state() != Off) {
                
-               if (gain_automation_recording()) {
-                       _gain_automation_curve.save_state (_("automation write/touch"));
-               }
-
                /* the src=0 condition is a special signal to not propagate 
                   automation gain changes into the mix group when locating.
                */