Remove redundant beat arg from TempoMap::add_meter
[ardour.git] / libs / ardour / track.cc
index 17a7c13295de391afc3bb8186d6b3c5e00fdde28..d7d9a0a9d14686b04ba78f8aba3521367b4d36e1 100644 (file)
 #include "ardour/debug.h"
 #include "ardour/delivery.h"
 #include "ardour/diskstream.h"
+#include "ardour/event_type_map.h"
 #include "ardour/io_processor.h"
 #include "ardour/meter.h"
 #include "ardour/monitor_control.h"
 #include "ardour/playlist.h"
 #include "ardour/port.h"
 #include "ardour/processor.h"
+#include "ardour/profile.h"
 #include "ardour/record_enable_control.h"
+#include "ardour/record_safe_control.h"
 #include "ardour/route_group_specialized.h"
 #include "ardour/session.h"
 #include "ardour/session_playlists.h"
 #include "ardour/track.h"
+#include "ardour/types_convert.h"
 #include "ardour/utils.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -61,18 +65,16 @@ Track::init ()
                 return -1;
         }
 
-       boost::shared_ptr<Route> rp (shared_from_this());
+        boost::shared_ptr<Route> rp (boost::dynamic_pointer_cast<Route> (shared_from_this()));
        boost::shared_ptr<Track> rt = boost::dynamic_pointer_cast<Track> (rp);
 
-       _record_enable_control.reset (new RecordEnableControl (_session, X_("recenable"), *this));
+       _record_enable_control.reset (new RecordEnableControl (_session, EventTypeMap::instance().to_symbol (RecEnableAutomation), *this));
        add_control (_record_enable_control);
 
-       _record_safe_control.reset (new AutomationControl (_session, RecSafeAutomation, ParameterDescriptor (RecSafeAutomation),
-                                                          boost::shared_ptr<AutomationList> (new AutomationList (Evoral::Parameter (RecSafeAutomation))),
-                                                          X_("recsafe")));
+       _record_safe_control.reset (new RecordSafeControl (_session, EventTypeMap::instance().to_symbol (RecSafeAutomation), *this));
        add_control (_record_safe_control);
 
-       _monitoring_control.reset (new MonitorControl (_session, X_("monitoring"), *this));
+       _monitoring_control.reset (new MonitorControl (_session, EventTypeMap::instance().to_symbol (MonitoringAutomation), *this));
        add_control (_monitoring_control);
 
        _session.config.ParameterChanged.connect_same_thread (*this, boost::bind (&Track::parameter_changed, this, _1));
@@ -106,7 +108,12 @@ XMLNode&
 Track::state (bool full)
 {
        XMLNode& root (Route::state (full));
-       root.add_property (X_("saved-meter-point"), enum_2_string (_saved_meter_point));
+
+       root.add_child_nocopy (_monitoring_control->get_state ());
+       root.add_child_nocopy (_record_safe_control->get_state ());
+       root.add_child_nocopy (_record_enable_control->get_state ());
+
+       root.set_property (X_("saved-meter-point"), _saved_meter_point);
        root.add_child_nocopy (_diskstream->get_state ());
 
        return root;
@@ -141,19 +148,32 @@ Track::set_state (const XMLNode& node, int version)
        for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter) {
                child = *niter;
 
-               XMLProperty const * prop;
-               if (child->name() == Controllable::xml_node_name && (prop = child->property ("name")) != 0) {
-                       if (prop->value() == X_("recenable")) {
+               if (child->name() == Controllable::xml_node_name) {
+                       std::string name;
+                       if (!child->get_property ("name", name)) {
+                               continue;
+                       }
+
+                       if (name == _record_enable_control->name()) {
                                _record_enable_control->set_state (*child, version);
+                       } else if (name == _record_safe_control->name()) {
+                               _record_safe_control->set_state (*child, version);
+                       } else if (name == _monitoring_control->name()) {
+                               _monitoring_control->set_state (*child, version);
                        }
                }
        }
 
-       XMLProperty const * prop;
+       /* convert old 3001 state */
+       MonitorChoice monitoring;
+       if (node.get_property (X_("monitoring"), monitoring)) {
+               XMLNode mon_node ("backwardscompat");
+               mon_node.set_property (X_("monitoring"), monitoring);
+               mon_node.set_property (X_("value"), (int) monitoring);
+               _monitoring_control->set_state (mon_node, version);
+       }
 
-       if ((prop = node.property (X_("saved-meter-point"))) != 0) {
-               _saved_meter_point = MeterPoint (string_2_enum (prop->value(), _saved_meter_point));
-       } else {
+       if (!node.get_property (X_("saved-meter-point"), _saved_meter_point)) {
                _saved_meter_point = _meter_point;
        }
 
@@ -241,27 +261,15 @@ Track::record_safe_changed (bool, Controllable::GroupControlDisposition)
 }
 
 bool
-Track::record_safe () const
+Track::can_be_record_safe ()
 {
-       return _diskstream && _diskstream->record_safe ();
+       return !_record_enable_control->get_value() && _diskstream && _session.writable() && (_freeze_record.state != Frozen);
 }
 
-void
-Track::set_record_safe (bool yn, Controllable::GroupControlDisposition group_override)
+bool
+Track::can_be_record_enabled ()
 {
-       if (!_session.writable()) {
-               return;
-       }
-
-       if (_freeze_record.state == Frozen) {
-               return;
-       }
-
-       if (record_enabled ()) {
-               return;
-       }
-
-       _rec_safe_control->set_value (yn, group_override);
+       return !_record_safe_control->get_value() && _diskstream && !_diskstream->record_safe() && _session.writable() && (_freeze_record.state != Frozen);
 }
 
 void
@@ -291,8 +299,12 @@ Track::set_name (const string& str)
 {
        bool ret;
 
-       if (_record_enable_control->get_value() && _session.actively_recording()) {
-               /* this messes things up if done while recording */
+       if (str.empty ()) {
+               return false;
+       }
+
+       if (_record_enable_control->get_value()) {
+               /* when re-arm'ed the file (named after the track) is already ready to rolll */
                return false;
        }
 
@@ -364,7 +376,8 @@ Track::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
 
        /* no outputs? nothing to do ... what happens if we have sends etc. ? */
 
-       if (n_outputs().n_total() == 0) {
+       if (n_outputs().n_total() == 0 && !ARDOUR::Profile->get_mixbus()) {
+               //Note: Mixbus has its own output mechanism, so we should operate even if no explicit outputs are assigned
                return 0;
        }
 
@@ -457,10 +470,10 @@ Track::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
 
                        if (no_meter) {
                                BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
-                               _meter->run (bufs, 0, 0, nframes, true);
-                               _input->process_input (boost::shared_ptr<Processor>(), start_frame, end_frame, nframes);
+                               _meter->run (bufs, start_frame, end_frame, 1.0, nframes, true);
+                               _input->process_input (boost::shared_ptr<Processor>(), start_frame, end_frame, speed(), nframes);
                        } else {
-                               _input->process_input (_meter, start_frame, end_frame, nframes);
+                               _input->process_input (_meter, start_frame, end_frame, speed(), nframes);
                        }
                }
 
@@ -473,18 +486,13 @@ Track::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
                fill_buffers_with_input (bufs, _input, nframes);
 
                if (_meter_point == MeterInput) {
-                       _meter->run (bufs, start_frame, end_frame, nframes, true);
+                       _meter->run (bufs, start_frame, end_frame, 1.0 /*speed()*/, nframes, true);
                }
 
                passthru (bufs, start_frame, end_frame, nframes, false);
        }
 
-       for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
-               boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
-               if (d) {
-                       d->flush_buffers (nframes);
-               }
-       }
+       flush_processor_buffers_locked (nframes);
 
        return 0;
 }
@@ -514,6 +522,7 @@ Track::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*
        _amp->apply_gain_automation(false);
 
        silence (nframes);
+       flush_processor_buffers_locked (nframes);
 
        framecnt_t playback_distance;
 
@@ -930,6 +939,17 @@ Track::monitoring_state () const
                return MonitoringDisk;
        }
 
+       switch (_session.config.get_session_monitoring ()) {
+               case MonitorDisk:
+                       return MonitoringDisk;
+                       break;
+               case MonitorInput:
+                       return MonitoringInput;
+                       break;
+               default:
+                       break;
+       }
+
        /* This is an implementation of the truth table in doc/monitor_modes.pdf;
           I don't think it's ever going to be too pretty too look at.
        */
@@ -945,9 +965,11 @@ Track::monitoring_state () const
         * time, but just to keep the semantics the same as they were before
         * sept 26th 2012, we differentiate between the cases where punch is
         * enabled and those where it is not.
+        *
+        * rg: I suspect this is not the case: monitoring may differ
         */
 
-       if (_session.config.get_punch_in() || _session.config.get_punch_out()) {
+       if (_session.config.get_punch_in() || _session.config.get_punch_out() || _session.preroll_record_punch_enabled ()) {
                session_rec = _session.actively_recording ();
        } else {
                session_rec = _session.get_record_enabled();