*** NEW CODING POLICY ***
[ardour.git] / libs / ardour / track.cc
index f81ef9de4dea364dba22b01acb58b0c88eff8529..8ec3a68a218cbdf46397965d96143f893af90627 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
-#include <pbd/error.h>
+#include "pbd/error.h"
 #include <sigc++/retype.h>
 #include <sigc++/retype_return.h>
 #include <sigc++/bind.h>
 
-#include <ardour/track.h>
-#include <ardour/diskstream.h>
-#include <ardour/session.h>
-#include <ardour/redirect.h>
-#include <ardour/audioregion.h>
-#include <ardour/audiosource.h>
-#include <ardour/route_group_specialized.h>
-#include <ardour/insert.h>
-#include <ardour/audioplaylist.h>
-#include <ardour/panner.h>
-#include <ardour/utils.h>
-#include <ardour/connection.h>
+#include "ardour/track.h"
+#include "ardour/diskstream.h"
+#include "ardour/session.h"
+#include "ardour/io_processor.h"
+#include "ardour/audioregion.h"
+#include "ardour/audiosource.h"
+#include "ardour/route_group_specialized.h"
+#include "ardour/processor.h"
+#include "ardour/audioplaylist.h"
+#include "ardour/panner.h"
+#include "ardour/utils.h"
+#include "ardour/port.h"
 
 #include "i18n.h"
 
@@ -41,8 +41,7 @@ using namespace PBD;
 
 Track::Track (Session& sess, string name, Route::Flag flag, TrackMode mode, DataType default_type)
        : Route (sess, name, 1, -1, -1, -1, flag, default_type)
-       , _diskstream (0)
-       ,  _rec_enable_control (*this)
+       , _rec_enable_control (new RecEnableControllable(*this))
 {
        _declickable = true;
        _freeze_record.state = NoFreeze;
@@ -51,9 +50,8 @@ Track::Track (Session& sess, string name, Route::Flag flag, TrackMode mode, Data
 }
 
 Track::Track (Session& sess, const XMLNode& node, DataType default_type)
-       : Route (sess, "to be renamed", 0, 0, -1, -1, Route::Flag(0), default_type)
-       , _diskstream (0)
-       , _rec_enable_control (*this)
+       : Route (sess, node)
+       , _rec_enable_control (new RecEnableControllable(*this))
 {
        _freeze_record.state = NoFreeze;
        _declickable = true;
@@ -62,9 +60,6 @@ Track::Track (Session& sess, const XMLNode& node, DataType default_type)
 
 Track::~Track ()
 {
-       if (_diskstream) {
-               _diskstream->unref();
-       }
 }
 
 void
@@ -88,31 +83,45 @@ Track::get_template ()
 void
 Track::toggle_monitor_input ()
 {
-       for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
-               (*i)->request_monitor_input(!(*i)->monitoring_input());
+       for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
+               i->ensure_monitor_input(!i->monitoring_input());
        }
 }
 
-jack_nframes_t
+ARDOUR::nframes_t
 Track::update_total_latency ()
 {
-       _own_latency = 0;
+       nframes_t old = _own_latency;
+
+       if (_user_latency) {
+               _own_latency = _user_latency;
+       } else {
+               _own_latency = 0;
 
-       for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
-               if ((*i)->active ()) {
-                       _own_latency += (*i)->latency ();
+               for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
+                       if ((*i)->active ()) {
+                               _own_latency += (*i)->signal_latency ();
+                       }
                }
        }
 
+#undef DEBUG_LATENCY
+#ifdef DEBUG_LATENCY
+       cerr << _name << ": internal redirect (final) latency = " << _own_latency << endl;
+#endif
+
        set_port_latency (_own_latency);
 
+       if (old != _own_latency) {
+               signal_latency_changed (); /* EMIT SIGNAL */
+       }
+
        return _own_latency;
 }
 
-
 Track::FreezeRecord::~FreezeRecord ()
 {
-       for (vector<FreezeRecordInsertInfo*>::iterator i = insert_info.begin(); i != insert_info.end(); ++i) {
+       for (vector<FreezeRecordProcessorInfo*>::iterator i = processor_info.begin(); i != processor_info.end(); ++i) {
                delete *i;
        }
 }
@@ -124,7 +133,7 @@ Track::freeze_state() const
 }
 
 Track::RecEnableControllable::RecEnableControllable (Track& s)
-       : track (s)
+       : Controllable (X_("recenable")), track (s)
 {
 }
 
@@ -152,8 +161,8 @@ bool
 Track::can_record()
 {
        bool will_record = true;
-       for (size_t i = 0; i < _inputs.size() && will_record; i++) {
-               if (!_inputs[i]->connected())
+       for (PortSet::iterator i = _inputs.begin(); i != _inputs.end() && will_record; ++i) {
+               if (!i->connected())
                        will_record = false;
        }
 
@@ -172,12 +181,6 @@ Track::set_record_enable (bool yn, void *src)
                return;
        }
 
-       // Do not set rec enabled if the track can't record.
-       if (yn && !can_record()) {
-               error << string_compose( _("Can not arm track '%1'. Check the input connections"), name() ) << endmsg;
-               return;
-       }
-
        /* keep track of the meter point as it was before we rec-enabled */
        if (!_diskstream->record_enabled()) {
                _saved_meter_point = _meter_point;
@@ -191,46 +194,35 @@ Track::set_record_enable (bool yn, void *src)
                set_meter_point (_saved_meter_point, this);
        }
 
-       _rec_enable_control.Changed ();
+       _rec_enable_control->Changed ();
 }
 
-void
-Track::set_mode (TrackMode m)
-{
-       if (_diskstream) {
-               if (_mode != m) {
-                       _mode = m;
-                       _diskstream->set_destructive (m == Destructive);
-                       ModeChanged();
-               }
-       }
-}
 
-int
-Track::set_name (string str, void *src)
+bool
+Track::set_name (const string& str)
 {
-       int ret;
+       bool ret;
 
        if (record_enabled() && _session.actively_recording()) {
                /* this messes things up if done while recording */
-               return -1;
+               return false;
        }
 
        if (_diskstream->set_name (str)) {
-               return -1;
+               return false;
        }
 
        /* save state so that the statefile fully reflects any filename changes */
 
-       if ((ret = IO::set_name (str, src)) == 0) {
+       if ((ret = IO::set_name (str)) == 0) {
                _session.save_state ("");
-                _session.save_history();
        }
+
        return ret;
 }
 
 void
-Track::set_latency_delay (jack_nframes_t longest_session_latency)
+Track::set_latency_delay (nframes_t longest_session_latency)
 {
        Route::set_latency_delay (longest_session_latency);
        _diskstream->set_roll_delay (_roll_delay);