reset DiskReader "no disk output" flag in a couple of exceptional cases
[ardour.git] / libs / ardour / session_process.cc
index c1230fc09eb0b1ea811be26ade6c80cddfae4a64..b642a0bb0d38a49aa2a1af6d3f0cc13fcb40df88 100644 (file)
@@ -32,6 +32,7 @@
 #include "ardour/butler.h"
 #include "ardour/cycle_timer.h"
 #include "ardour/debug.h"
+#include "ardour/disk_reader.h"
 #include "ardour/graph.h"
 #include "ardour/port.h"
 #include "ardour/process_thread.h"
@@ -192,6 +193,8 @@ Session::process_routes (pframes_t nframes, bool& need_butler)
                (*i)->automation_run (start_frame, nframes);
        }
 
+       _global_locate_pending = locate_pending ();
+
        if (_process_graph) {
                DEBUG_TRACE(DEBUG::ProcessThreads,"calling graph/process-routes\n");
                if (_process_graph->process_routes (nframes, start_frame, end_frame, declick, need_butler) < 0) {
@@ -227,49 +230,6 @@ Session::process_routes (pframes_t nframes, bool& need_butler)
        return 0;
 }
 
-/** @param need_butler to be set to true by this method if it needs the butler,
- *  otherwise it must be left alone.
- */
-int
-Session::silent_process_routes (pframes_t nframes, bool& need_butler)
-{
-       boost::shared_ptr<RouteList> r = routes.reader ();
-
-       const framepos_t start_frame = _transport_frame;
-       const framepos_t end_frame = _transport_frame + lrintf(nframes * _transport_speed);
-
-       VCAList v = _vca_manager->vcas ();
-       for (VCAList::const_iterator i = v.begin(); i != v.end(); ++i) {
-               (*i)->automation_run (start_frame, nframes);
-       }
-
-       if (_process_graph) {
-               _process_graph->silent_process_routes (nframes, start_frame, end_frame, need_butler);
-       } else {
-               for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
-
-                       int ret;
-
-                       if ((*i)->is_auditioner()) {
-                               continue;
-                       }
-
-                       bool b = false;
-
-                       if ((ret = (*i)->silent_roll (nframes, start_frame, end_frame, b)) < 0) {
-                               stop_transport ();
-                               return -1;
-                       }
-
-                       if (b) {
-                               need_butler = true;
-                       }
-               }
-       }
-
-       return 0;
-}
-
 void
 Session::get_track_statistics ()
 {
@@ -281,7 +241,7 @@ Session::get_track_statistics ()
 
                boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
 
-               if (!tr || tr->hidden()) {
+               if (!tr || tr->is_private_route()) {
                        continue;
                }
 
@@ -569,6 +529,7 @@ Session::reset_slave_state ()
        delta_accumulator_cnt = 0;
        have_first_delta_accumulator = false;
        _slave_state = Stopped;
+       DiskReader::set_no_disk_output (false);
 }
 
 bool
@@ -638,7 +599,7 @@ Session::follow_slave (pframes_t nframes)
                */
 
                if (_slave_state == Running) {
-                       calculate_moving_average_of_slave_delta(dir, this_delta);
+                       calculate_moving_average_of_slave_delta(dir, abs(this_delta));
                }
        }
 
@@ -648,9 +609,9 @@ Session::follow_slave (pframes_t nframes)
                                                   _slave_state, slave_transport_frame, slave_speed, this_delta, average_slave_delta));
 
 
-       if (_slave_state == Running && !_slave->is_always_synced() &&
-                       !(Config->get_timecode_source_is_synced() && (dynamic_cast<TimecodeSlave*>(_slave)) != 0)
-                       ) {
+       if (_slave_state == Running && !_slave->is_always_synced() && !(Config->get_timecode_source_is_synced() && (dynamic_cast<TimecodeSlave*>(_slave)) != 0)) {
+
+               /* may need to varispeed to sync with slave */
 
                if (_transport_speed != 0.0f) {
 
@@ -691,25 +652,34 @@ Session::follow_slave (pframes_t nframes)
                                                                           slave_speed));
                        }
 
-#if 1
-                       if (!actively_recording() && (framecnt_t) abs(average_slave_delta) > _slave->resolution()) {
-                               cerr << "average slave delta greater than slave resolution (" << _slave->resolution() << "), going to silent motion\n";
-                               goto silent_motion;
+                       if (!actively_recording() && (framecnt_t) average_slave_delta > _slave->resolution()) {
+                               DEBUG_TRACE (DEBUG::Slave, string_compose ("average slave delta %1 greater than slave resolution %2 => silent motion\n", average_slave_delta, _slave->resolution()));
+                               /* run routes as normal, but no disk output */
+                               DiskReader::set_no_disk_output (true);
+                               return true;
+                       }
+
+                       if (!have_first_delta_accumulator) {
+                               DEBUG_TRACE (DEBUG::Slave, "waiting for first slave delta accumulator to be ready\n");
+                               /* run routes as normal, but no disk output */
+                               DiskReader::set_no_disk_output (true);
+                               return true;
                        }
-#endif
                }
        }
 
 
-       if (_slave_state == Running && 0 == (post_transport_work () & ~PostTransportSpeed)) {
+       if (!have_first_delta_accumulator) {
+               DiskReader::set_no_disk_output (true);
+       } else {
+               DiskReader::set_no_disk_output (false);
+       }
+
+       if ((_slave_state == Running) && (0 == (post_transport_work () & ~PostTransportSpeed))) {
                /* speed is set, we're locked, and good to go */
                return true;
        }
 
-  silent_motion:
-       DEBUG_TRACE (DEBUG::Slave, "silent motion\n")
-       follow_slave_silently (nframes, slave_speed);
-
   noroll:
        /* don't move at all */
        DEBUG_TRACE (DEBUG::Slave, "no roll\n")
@@ -737,7 +707,7 @@ Session::calculate_moving_average_of_slave_delta (int dir, framecnt_t this_delta
                average_slave_delta /= (int32_t) delta_accumulator_size;
                if (average_slave_delta < 0L) {
                        average_dir = -1;
-                       average_slave_delta = abs(average_slave_delta);
+                       average_slave_delta = average_slave_delta;
                } else {
                        average_dir = 1;
                }
@@ -853,45 +823,6 @@ Session::track_slave_state (float slave_speed, framepos_t slave_transport_frame,
        }
 }
 
-void
-Session::follow_slave_silently (pframes_t nframes, float slave_speed)
-{
-       if (slave_speed && _transport_speed) {
-
-               /* something isn't right, but we should move with the master
-                  for now.
-               */
-
-               bool need_butler = false;
-
-               silent_process_routes (nframes, need_butler);
-
-               get_track_statistics ();
-
-               if (need_butler) {
-                       DEBUG_TRACE (DEBUG::Butler, "f-slave-silently: session needs butler, call it\n");
-                       _butler->summon ();
-               }
-
-               int32_t frames_moved;
-
-               if (locate_pending()) {
-                       frames_moved = 0;
-               } else {
-                       frames_moved = (int32_t) floor (_transport_speed * nframes);
-               }
-
-               if (frames_moved < 0) {
-                       decrement_transport_position (-frames_moved);
-               } else if (frames_moved) {
-                       increment_transport_position (frames_moved);
-               }
-
-               framepos_t const stop_limit = compute_stop_limit ();
-               maybe_stop (stop_limit);
-       }
-}
-
 void
 Session::process_without_events (pframes_t nframes)
 {