return;
}
- _capture_offset = _io->latency();
- DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose ("%1: using IO latency, capture offset set to %2\n", name(), _capture_offset));
+ switch (_alignment_style) {
+ case ExistingMaterial:
+ _capture_offset = _io->latency();
+ break;
+
+ case CaptureTime:
+ default:
+ _capture_offset = 0;
+ break;
+ }
+
+ DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose ("%1: using IO latency, capture offset set to %2 with style = %3\n", name(), _capture_offset, enum_2_string (_alignment_style)));
}
if ((a != _alignment_style) || force) {
_alignment_style = a;
+ set_capture_offset ();
AlignmentStyleChanged ();
}
}
return;
}
- framecnt_t existing_material_offset = _session.worst_playback_latency();
+ const framecnt_t existing_material_offset = _session.worst_playback_latency();
if (possibly_recording == fully_rec_enabled) {
}
void
-Diskstream::prepare_to_stop (framepos_t pos)
+Diskstream::prepare_to_stop (framepos_t transport_frame, framepos_t audible_frame)
{
- last_recordable_frame = pos + _capture_offset;
+ switch (_alignment_style) {
+ case ExistingMaterial:
+ last_recordable_frame = transport_frame + _capture_offset;
+ DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose("%1: prepare to stop sets last recordable frame to %2 + %3 = %4\n", _name, transport_frame, _capture_offset, last_recordable_frame));
+ break;
+
+ case CaptureTime:
+ last_recordable_frame = audible_frame; // note that capture_offset is zero
+ /* we may already have captured audio before the last_recordable_frame (audible frame),
+ so deal with this.
+ */
+ if (last_recordable_frame > capture_start_frame) {
+ capture_captured = min (capture_captured, last_recordable_frame - capture_start_frame);
+ }
+ DEBUG_TRACE (DEBUG::CaptureAlignment, string_compose("%1: prepare to stop sets last recordable frame to audible frame @ %2\n", _name, audible_frame));
+ break;
+ }
+
}
void
void
Session::request_stop (bool abort, bool clear_state)
{
- SessionEvent* ev = new SessionEvent (SessionEvent::SetTransportSpeed, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0, abort, clear_state);
- DEBUG_TRACE (DEBUG::Transport, string_compose ("Request transport stop, abort = %1, clear state = %2\n", abort, clear_state));
+ SessionEvent* ev = new SessionEvent (SessionEvent::SetTransportSpeed, SessionEvent::Add, SessionEvent::Immediate, audible_frame(), 0.0, abort, clear_state);
+ DEBUG_TRACE (DEBUG::Transport, string_compose ("Request transport stop, audible %3 transport %4 abort = %1, clear state = %2\n", abort, clear_state, audible_frame(), _transport_frame));
queue_event (ev);
}
for (RouteList::iterator i = r->begin (); i != r->end(); ++i) {
(*i)->realtime_handle_transport_stopped ();
}
+
+ DEBUG_TRACE (DEBUG::Transport, string_compose ("stop complete, auto-return scheduled for return to %1\n", _requested_return_frame));
- if (actively_recording()) {
-
- /* move the transport position back to where the
- request for a stop was noticed. we rolled
- past that point to pick up delayed input (and/or to delick)
- */
-
- if (worst_playback_latency() > current_block_size) {
- /* we rolled past the stop point to pick up data that had
- not yet arrived. move back to where the stop occured.
- */
- decrement_transport_position (current_block_size + (worst_input_latency() - current_block_size));
- } else {
- decrement_transport_position (current_block_size);
- }
-
- /* the duration change is not guaranteed to have happened, but is likely */
-
- todo = PostTransportWork (todo | PostTransportDuration);
- }
+ /* the duration change is not guaranteed to have happened, but is likely */
+
+ todo = PostTransportWork (todo | PostTransportDuration);
if (abort) {
todo = PostTransportWork (todo | PostTransportAbort);
start_locate (pending_locate_frame, pending_locate_roll, pending_locate_flush);
transport_sub_state &= ~(PendingDeclickOut|PendingLocate);
} else {
- stop_transport (pending_abort);
- transport_sub_state &= ~(PendingDeclickOut|PendingLocate);
+ if (!(transport_sub_state & StopPendingCapture)) {
+ stop_transport (pending_abort);
+ transport_sub_state &= ~(PendingDeclickOut|PendingLocate);
+ }
}
} else if (transport_sub_state & PendingLoopDeclickOut) {
if (!force && _transport_frame == target_frame && !loop_changing && !for_seamless_loop) {
if (with_roll) {
- set_transport_speed (1.0, false);
+ set_transport_speed (1.0, 0, false);
}
loop_changing = false;
Located (); /* EMIT SIGNAL */
* @param speed New speed
*/
void
-Session::set_transport_speed (double speed, bool abort, bool clear_state, bool as_default)
+Session::set_transport_speed (double speed, framepos_t destination_frame, bool abort, bool clear_state, bool as_default)
{
DEBUG_TRACE (DEBUG::Transport, string_compose ("@ %5 Set transport speed to %1, abort = %2 clear_state = %3, current = %4 as_default %6\n",
speed, abort, clear_state, _transport_speed, _transport_frame, as_default));
if (Config->get_monitoring_model() == HardwareMonitoring) {
set_track_monitor_input_status (true);
}
-
+
if (synced_to_engine ()) {
if (clear_state) {
/* do this here because our response to the slave won't
}
_engine.transport_stop ();
} else {
+ bool const auto_return_enabled = (!config.get_external_sync() && (config.get_auto_return() || abort));
+
+ if (!auto_return_enabled) {
+ _requested_return_frame = destination_frame;
+ }
+
stop_transport (abort);
}
return;
}
- if (actively_recording() && !(transport_sub_state & StopPendingCapture) && worst_input_latency() > current_block_size) {
+ if (!get_transport_declick_required()) {
+
+ /* stop has not yet been scheduled */
boost::shared_ptr<RouteList> rl = routes.reader();
+ framepos_t stop_target = audible_frame();
+
for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
if (tr) {
- tr->prepare_to_stop (_transport_frame);
+ tr->prepare_to_stop (_transport_frame, stop_target);
}
}
- /* we need to capture the audio that has still not yet been received by the system
- at the time the stop is requested, so we have to roll past that time.
-
- we want to declick before stopping, so schedule the autostop for one
- block before the actual end. we'll declick in the subsequent block,
- and then we'll really be stopped.
- */
-
- DEBUG_TRACE (DEBUG::Transport, string_compose ("stop transport requested @ %1, scheduled for + %2 - %3 = %4, abort = %5\n",
- _transport_frame, _worst_input_latency, current_block_size,
- _transport_frame - _worst_input_latency - current_block_size,
- abort));
-
- SessionEvent *ev = new SessionEvent (SessionEvent::StopOnce, SessionEvent::Replace,
- _transport_frame + _worst_input_latency - current_block_size,
- 0, 0, abort);
-
- merge_event (ev);
- transport_sub_state |= StopPendingCapture;
- pending_abort = abort;
- return;
- }
-
- if ((transport_sub_state & PendingDeclickOut) == 0) {
+ SubState new_bits;
+
+ if (actively_recording() && /* we are recording */
+ worst_input_latency() > current_block_size) { /* input latency exceeds block size, so simple 1 cycle delay before stop is not enough */
+
+ /* we need to capture the audio that is still somewhere in the pipeline between
+ wherever it was generated and the process callback. This means that even though
+ the user (or something else) has asked us to stop, we have to roll
+ past this point and then reset the playhead/transport location to
+ the position at which the stop was requested.
+
+ we still need playback to "stop" now, however, which is why we schedule
+ a declick below.
+ */
+
+ DEBUG_TRACE (DEBUG::Transport, string_compose ("stop transport requested @ %1, scheduled for + %2 = %3, abort = %4\n",
+ _transport_frame, _worst_input_latency,
+ _transport_frame + _worst_input_latency,
+ abort));
+
+ SessionEvent *ev = new SessionEvent (SessionEvent::StopOnce, SessionEvent::Replace,
+ _transport_frame + _worst_input_latency,
+ 0, 0, abort);
+
+ merge_event (ev);
- if (!(transport_sub_state & StopPendingCapture)) {
- boost::shared_ptr<RouteList> rl = routes.reader();
- for (RouteList::iterator i = rl->begin(); i != rl->end(); ++i) {
- boost::shared_ptr<Track> tr = boost::dynamic_pointer_cast<Track> (*i);
- if (tr) {
- tr->prepare_to_stop (_transport_frame);
- }
- }
+ /* request a declick at the start of the next process cycle() so that playback ceases.
+ It will remain silent until we actually stop (at the StopOnce event somewhere in
+ the future). The extra flag (StopPendingCapture) is set to ensure that check_declick_out()
+ does not stop the transport too early.
+ */
+ new_bits = SubState (PendingDeclickOut|StopPendingCapture);
+
+ } else {
+
+ /* Not recording, schedule a declick in the next process() cycle and then stop at its end */
+
+ new_bits = PendingDeclickOut;
}
- transport_sub_state |= PendingDeclickOut;
+
/* we'll be called again after the declick */
+ transport_sub_state = SubState (transport_sub_state|new_bits);
pending_abort = abort;
+
return;
- }
- realtime_stop (abort, clear_state);
- _butler->schedule_transport_work ();
+ } else {
+
+ /* declick was scheduled, but we've been called again, which means it is really time to stop
+
+ XXX: we should probably split this off into its own method and call it explicitly.
+ */
+
+ realtime_stop (abort, clear_state);
+ _butler->schedule_transport_work ();
+ }
}
/** Called from the process thread */