+ /* only count-in when going to roll at speed 1.0 */
+ if (_transport_speed != 1.0 && _count_in_samples > 0) {
+ _count_in_samples = 0;
+ }
+ if (_transport_speed == 0.0) {
+ _remaining_latency_preroll = 0;
+ }
+
+ assert (_count_in_samples == 0 || _remaining_latency_preroll == 0 || _count_in_samples == _remaining_latency_preroll);
+
+ while (_count_in_samples > 0 || _remaining_latency_preroll > 0) {
+ samplecnt_t ns;
+
+ if (_remaining_latency_preroll > 0) {
+ ns = std::min ((samplecnt_t)nframes, _remaining_latency_preroll);
+ } else {
+ 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);
+ _count_in_samples -= ns;
+ }
+
+ if (_remaining_latency_preroll > 0) {
+ if (_count_in_samples == 0) {
+ click (_transport_sample - _remaining_latency_preroll, ns);
+ }
+ if (process_routes (ns, session_needs_butler)) {
+ fail_roll (ns);
+ }
+ } else {
+ no_roll (ns);
+ }
+
+ if (_remaining_latency_preroll > 0) {
+ assert (_remaining_latency_preroll >= ns);
+ _remaining_latency_preroll -= ns;
+ }
+
+ nframes -= ns;
+
+ /* process events.. */
+ if (!events.empty() && next_event != events.end()) {
+ SessionEvent* this_event = *next_event;
+ Events::iterator the_next_one = next_event;
+ ++the_next_one;
+
+ while (this_event && this_event->action_sample == _transport_sample) {
+ process_event (this_event);
+ if (the_next_one == events.end()) {
+ this_event = 0;
+ } else {
+ this_event = *the_next_one;
+ ++the_next_one;
+ }
+ }
+ set_next_event ();
+ }
+
+ if (nframes == 0) {
+ return;
+ } else {
+ _engine.split_cycle (ns);
+ }
+ }
+