Add Lua bindings for MIDI-parser and Async ports
[ardour.git] / libs / ardour / session_process.cc
index ed5422cf07a189f5c8495d01d0ff350719f9a8e3..7acc3a57daf64483a033aa5691b638dbdf668f5f 100644 (file)
@@ -302,7 +302,7 @@ Session::process_with_events (pframes_t nframes)
 
        assert (_count_in_samples == 0 || _remaining_latency_preroll == 0 || _count_in_samples == _remaining_latency_preroll);
 
-       if (_count_in_samples > 0 || _remaining_latency_preroll > 0) {
+       while (_count_in_samples > 0 || _remaining_latency_preroll > 0) {
                samplecnt_t ns;
 
                if (_remaining_latency_preroll > 0) {
@@ -311,6 +311,22 @@ Session::process_with_events (pframes_t nframes)
                        ns = std::min ((samplecnt_t)nframes, _count_in_samples);
                }
 
+               boost::shared_ptr<RouteList> r = routes.reader ();
+               for (RouteList::iterator i = r->begin(); i != r->end(); ++i) {
+                       samplecnt_t route_offset = (*i)->playback_latency ();
+                       if (_remaining_latency_preroll > route_offset + ns) {
+                               /* route will no-roll for complete pre-roll cycle */
+                               continue;
+                       }
+                       if (_remaining_latency_preroll > route_offset) {
+                               /* route may need partial no-roll and partial roll from
+                               * (_transport_sample - _remaining_latency_preroll) ..  +ns.
+                               * shorten and split the cycle.
+                               */
+                               ns = std::min (ns, (_remaining_latency_preroll - route_offset));
+                       }
+               }
+
                if (_count_in_samples > 0) {
                        run_click (_transport_sample - _count_in_samples, ns);
                        assert (_count_in_samples >= ns);
@@ -417,13 +433,9 @@ Session::process_with_events (pframes_t nframes)
                }
        }
 
-       if (_transport_speed == 1.0) {
-               samples_moved = (samplecnt_t) nframes;
-       } else {
-               interpolation.set_target_speed (_target_transport_speed);
-               interpolation.set_speed (_transport_speed);
-               samples_moved = (samplecnt_t) interpolation.interpolate (0, nframes, 0, 0);
-       }
+       assert (_transport_speed == 0 || _transport_speed == 1.0 || _transport_speed == -1.0);
+
+       samples_moved = (samplecnt_t) nframes * _transport_speed;
 
        end_sample = _transport_sample + samples_moved;
 
@@ -871,9 +883,8 @@ Session::process_without_events (pframes_t nframes)
        if (_transport_speed == 1.0) {
                samples_moved = (samplecnt_t) nframes;
        } else {
-               interpolation.set_target_speed (_target_transport_speed);
                interpolation.set_speed (_transport_speed);
-               samples_moved = (samplecnt_t) interpolation.interpolate (0, nframes, 0, 0);
+               samples_moved = interpolation.distance (nframes);
        }
 
        if (!_exporting && !timecode_transmission_suspended()) {
@@ -1146,7 +1157,7 @@ Session::process_event (SessionEvent* ev)
 
        case SessionEvent::PunchIn:
                // cerr << "PunchIN at " << transport_sample() << endl;
-               if (config.get_punch_in() && record_status() == Enabled && !preroll_record_punch_enabled()) {
+               if (config.get_punch_in() && record_status() == Enabled) {
                        enable_record ();
                }
                remove = false;
@@ -1155,21 +1166,13 @@ Session::process_event (SessionEvent* ev)
 
        case SessionEvent::PunchOut:
                // cerr << "PunchOUT at " << transport_sample() << endl;
-               if (config.get_punch_out() && !preroll_record_punch_enabled()) {
+               if (config.get_punch_out()) {
                        step_back_from_record ();
                }
                remove = false;
                del = false;
                break;
 
-       case SessionEvent::RecordStart:
-               if (preroll_record_punch_enabled() && record_status() == Enabled) {
-                       enable_record ();
-               }
-               remove = false;
-               del = false;
-               break;
-
        case SessionEvent::StopOnce:
                if (!non_realtime_work_pending()) {
                        _clear_event_type (SessionEvent::StopOnce);
@@ -1260,10 +1263,6 @@ Session::compute_stop_limit () const
                return max_samplepos;
        }
 
-       if (preroll_record_punch_enabled ()) {
-               return max_samplepos;
-       }
-
        bool const punching_in = (config.get_punch_in () && _locations->auto_punch_location());
        bool const punching_out = (config.get_punch_out () && _locations->auto_punch_location());