diff --git a/libs/ardour/session_events.cc b/libs/ardour/session_events.cc index 06c2228f23..22694c9a2d 100644 --- a/libs/ardour/session_events.cc +++ b/libs/ardour/session_events.cc @@ -230,7 +230,7 @@ SessionEventManager::merge_event (SessionEvent* ev) /* try to handle immediate events right here */ - if (ev->type == SessionEvent::Locate || ev->type == SessionEvent::LocateRoll) { + if (ev->type == SessionEvent::Locate || ev->type == SessionEvent::LocateRoll || ev->type == SessionEvent::EndRoll) { /* remove any existing Locates that are waiting to execute */ _clear_event_type (ev->type); } diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index 720fccd7a7..3ecf232ab3 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -899,8 +899,27 @@ Session::request_stop (bool abort, bool clear_state, TransportRequestSource orig solo_selection ( _soloSelection, false ); } - SessionEvent* ev = new SessionEvent (SessionEvent::EndRoll, SessionEvent::Add, SessionEvent::Immediate, audible_sample(), 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_sample(), _transport_sample)); + SessionEvent *ev; + + if (Config->get_stop_on_grid() && _global_quantization.type == AnyTime::BBT_Offset && _transport_sample != 0) { + /* XXX for now this only does anything if we are quantized to + * Beats. Other quantization settings require moving + * Editor::snap_to() code into libardour, which is not in-scope + * at the time this work is occuring. + */ + + TempoMap::SharedPtr tmap (TempoMap::use()); + BBT_Argument now = tmap->bbt_at (timepos_t (_transport_sample)); + BBT_Argument rounded = tmap->round_up_to_bar (now); + samplepos_t samples = tmap->sample_at (rounded); + + ev = new SessionEvent (SessionEvent::EndRoll, SessionEvent::Add, samples, samples, 0.0, abort, clear_state); + DEBUG_TRACE (DEBUG::Transport, string_compose ("Request transport stop @ %4 snapped to %1 => %2 => %3\n", samples, now, rounded, _transport_sample)); + } else { + ev = new SessionEvent (SessionEvent::EndRoll, SessionEvent::Add, SessionEvent::Immediate, audible_sample(), 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_sample(), _transport_sample)); + } + queue_event (ev); }