id_t becomes a fully-fledged object, UUID's used for IDs, generic MIDI now owns bindi...
[ardour.git] / libs / ardour / session_process.cc
1 /*
2     Copyright (C) 1999-2002 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #include <cmath>
22 #include <cerrno>
23 #include <algorithm>
24 #include <unistd.h>
25
26 #include <pbd/error.h>
27  
28 #include <glibmm/thread.h>
29
30 #include <ardour/ardour.h>
31 #include <ardour/session.h>
32 #include <ardour/timestamps.h>
33 #include <ardour/audio_diskstream.h>
34 #include <ardour/audioengine.h>
35 #include <ardour/slave.h>
36 #include <ardour/auditioner.h>
37 #include <ardour/cycles.h>
38 #include <ardour/cycle_timer.h>
39
40 #include "i18n.h"
41
42 using namespace ARDOUR;
43 using namespace PBD;
44 using namespace std;
45
46 void
47 Session::process (jack_nframes_t nframes)
48 {
49         if (synced_to_jack() && waiting_to_start) {
50                 if ( _engine.transport_state() == AudioEngine::TransportRolling) {
51                         actually_start_transport ();
52                 }
53         }
54
55         if (non_realtime_work_pending()) {
56                 if (g_atomic_int_get (&butler_should_do_transport_work) == 0) {
57                         post_transport ();
58                 } 
59         } 
60         
61         (this->*process_function) (nframes);
62
63         SendFeedback (); /* EMIT SIGNAL */
64 }
65
66 void
67 Session::prepare_diskstreams ()
68 {
69         for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
70                 (*i)->prepare ();
71         }
72 }
73
74 int
75 Session::no_roll (jack_nframes_t nframes, jack_nframes_t offset)
76 {
77         jack_nframes_t end_frame = _transport_frame + nframes;
78         int ret = 0;
79         bool declick = get_transport_declick_required();
80
81         if (_click_io) {
82                 _click_io->silence (nframes, offset);
83         }
84
85         /* XXX we're supposed to have the route_lock while doing this.
86            this is really bad ...
87         */
88
89         if (g_atomic_int_get (&processing_prohibited)) {
90                 for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
91                         (*i)->silence (nframes, offset);
92                 }
93                 return 0;
94         }
95
96         for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
97                 
98                 if ((*i)->hidden()) {
99                         continue;
100                 }
101                 
102                 (*i)->set_pending_declick (declick);
103                 
104                 if ((*i)->no_roll (nframes, _transport_frame, end_frame, offset, non_realtime_work_pending(), 
105                                    actively_recording(), declick)) {
106                         error << string_compose(_("Session: error in no roll for %1"), (*i)->name()) << endmsg;
107                         ret = -1;
108                         break;
109                 }
110         }
111
112         return ret;
113 }
114
115 int
116 Session::process_routes (jack_nframes_t nframes, jack_nframes_t offset)
117 {
118         bool record_active;
119         int  declick = get_transport_declick_required();
120         bool rec_monitors = get_rec_monitors_input();
121
122         if (transport_sub_state & StopPendingCapture) {
123                 /* force a declick out */
124                 declick = -1;
125         }
126
127         record_active = actively_recording(); // || (get_record_enabled() && get_punch_in());
128
129         for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
130
131                 int ret;
132
133                 if ((*i)->hidden()) {
134                         continue;
135                 }
136
137                 (*i)->set_pending_declick (declick);
138
139                 if ((ret = (*i)->roll (nframes, _transport_frame, _transport_frame + nframes, offset, declick, record_active, rec_monitors)) < 0) {
140
141                         /* we have to do this here. Route::roll() for an AudioTrack will have called AudioDiskstream::process(),
142                            and the DS will expect AudioDiskstream::commit() to be called. but we're aborting from that
143                            call path, so make sure we release any outstanding locks here before we return failure.
144                         */
145
146                         for (AudioDiskstreamList::iterator ids = audio_diskstreams.begin(); ids != audio_diskstreams.end(); ++ids) {
147                                 (*ids)->recover ();
148                         }
149
150                         stop_transport ();
151                         return -1;
152                 } 
153         }
154
155         return 0;
156 }
157
158 int
159 Session::silent_process_routes (jack_nframes_t nframes, jack_nframes_t offset)
160 {
161         bool record_active = actively_recording();
162         int  declick = get_transport_declick_required();
163         bool rec_monitors = get_rec_monitors_input();
164
165         if (transport_sub_state & StopPendingCapture) {
166                 /* force a declick out */
167                 declick = -1;
168         }
169
170         for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
171
172                 int ret;
173
174                 if ((*i)->hidden()) {
175                         continue;
176                 }
177
178                 if ((ret = (*i)->silent_roll (nframes, _transport_frame, _transport_frame + nframes, offset, record_active, rec_monitors)) < 0) {
179                         
180                         /* we have to do this here. Route::roll() for an AudioTrack will have called AudioDiskstream::process(),
181                            and the DS will expect AudioDiskstream::commit() to be called. but we're aborting from that
182                            call path, so make sure we release any outstanding locks here before we return failure.
183                         */
184
185                         for (AudioDiskstreamList::iterator ids = audio_diskstreams.begin(); ids != audio_diskstreams.end(); ++ids) {
186                                 (*ids)->recover ();
187                         }
188
189                         stop_transport ();
190                         return -1;
191                 } 
192         }
193
194         return 0;
195 }
196
197 void
198 Session::commit_diskstreams (jack_nframes_t nframes, bool &needs_butler)
199 {
200         int dret;
201         float pworst = 1.0f;
202         float cworst = 1.0f;
203
204         for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
205
206                 if ((*i)->hidden()) {
207                         continue;
208                 }
209                 
210                 /* force all diskstreams not handled by a Route to call do their stuff.
211                  */
212
213                 if ((dret = (*i)->process (_transport_frame, nframes, 0, actively_recording(), get_rec_monitors_input())) == 0) {
214                         if ((*i)->commit (nframes)) {
215                                 needs_butler = true;
216                         }
217
218                 } else if (dret < 0) {
219                         (*i)->recover();
220                 }
221                 
222                 pworst = min (pworst, (*i)->playback_buffer_load());
223                 cworst = min (cworst, (*i)->capture_buffer_load());
224         }
225
226         uint32_t pmin = g_atomic_int_get (&_playback_load);
227         uint32_t pminold = g_atomic_int_get (&_playback_load_min);
228         uint32_t cmin = g_atomic_int_get (&_capture_load);
229         uint32_t cminold = g_atomic_int_get (&_capture_load_min);
230
231         g_atomic_int_set (&_playback_load, (uint32_t) floor (pworst * 100.0f));
232         g_atomic_int_set (&_capture_load, (uint32_t) floor (cworst * 100.0f));
233         g_atomic_int_set (&_playback_load_min, min (pmin, pminold));
234         g_atomic_int_set (&_capture_load_min, min (cmin, cminold));
235
236         if (actively_recording()) {
237                 set_dirty();
238         }
239 }
240
241 void
242 Session::process_with_events (jack_nframes_t nframes)
243 {
244         Event* ev;
245         jack_nframes_t this_nframes;
246         jack_nframes_t end_frame;
247         jack_nframes_t offset;
248         bool session_needs_butler = false;
249         jack_nframes_t stop_limit;
250         long           frames_moved;
251
252         if (auditioner) {
253                 auditioner->silence (nframes, 0);
254         }
255
256         while (pending_events.read (&ev, 1) == 1) {
257                 merge_event (ev);
258         }
259
260         /* if we are not in the middle of a state change,
261            and there are immediate events queued up,
262            process them. 
263         */
264
265         while (!non_realtime_work_pending() && !immediate_events.empty()) {
266                 Event *ev = immediate_events.front ();
267                 immediate_events.pop_front ();
268                 process_event (ev);
269         }
270
271         if (!process_can_proceed()) {
272                 no_roll (nframes, 0);
273                 return;
274         }
275                 
276         if (events.empty() || next_event == events.end()) {
277                 process_without_events (nframes);
278                 return;
279         }
280
281         end_frame = _transport_frame + nframes;
282
283         {
284                 Glib::RWLock::ReaderLock rm (route_lock, Glib::TRY_LOCK);
285                 Glib::RWLock::ReaderLock dsm (diskstream_lock, Glib::TRY_LOCK);
286         
287                 Event* this_event;
288                 Events::iterator the_next_one;
289
290                 if (!rm.locked() || !dsm.locked() || (post_transport_work & (PostTransportLocate|PostTransportStop))) {
291                         no_roll (nframes, 0);
292                         return;
293                 }
294                 
295                 if (!_exporting && _slave) {
296                         if (!follow_slave (nframes, 0)) {
297                                 return;
298                         }
299                 } 
300
301                 if (_transport_speed == 0) {
302                         no_roll (nframes, 0);
303                         return;
304                 }
305
306                 if (actively_recording()) {
307                         stop_limit = max_frames;
308                 } else {
309
310                         if (Config->get_stop_at_session_end()) {
311                                 stop_limit = current_end_frame();
312                         } else {
313                                 stop_limit = max_frames;
314                         }
315                 }
316
317                 if (maybe_stop (stop_limit)) {
318                         no_roll (nframes, 0);
319                         return;
320                 } 
321
322                 this_event = *next_event;
323                 the_next_one = next_event;
324                 ++the_next_one;
325
326                 offset = 0;
327
328                 while (nframes) {
329
330                         if (this_event == 0 || this_event->action_frame > end_frame || this_event->action_frame < _transport_frame) {
331
332                                 this_nframes = nframes;
333                                 
334                         } else {
335                                 
336                                 /* compute nframes to next event */
337
338                                 if (this_event->action_frame < end_frame) {
339                                         this_nframes = nframes - (end_frame - this_event->action_frame);
340                                 } else {
341                                         this_nframes = nframes;
342                                 }
343                         }
344
345                         if (this_nframes) {
346                                 
347                                 click (_transport_frame, nframes, offset);
348                                 
349                                 /* now process frames between now and the first event in this block */
350                                 prepare_diskstreams ();
351
352                                 if (process_routes (this_nframes, offset)) {
353                                         no_roll (nframes, 0);
354                                         return;
355                                 }
356                                 
357                                 commit_diskstreams (this_nframes, session_needs_butler);
358
359                                 nframes -= this_nframes;
360                                 offset += this_nframes;
361                                 
362                                 frames_moved = (jack_nframes_t) floor (_transport_speed * this_nframes);
363                         
364                                 if (frames_moved < 0) {
365                                         decrement_transport_position (-frames_moved);
366                                 } else {
367                                         increment_transport_position (frames_moved);
368                                 }
369
370                                 maybe_stop (stop_limit);
371                                 check_declick_out ();
372                         }
373
374                         /* now handle this event and all others scheduled for the same time */
375                         
376                         while (this_event && this_event->action_frame == _transport_frame) {
377                                 process_event (this_event);
378
379                                 if (the_next_one == events.end()) {
380                                         this_event = 0;
381                                 } else {
382                                         this_event = *the_next_one;
383                                         ++the_next_one;
384                                 }
385                         } 
386
387                         /* if an event left our state changing, do the right thing */
388
389                         if (non_realtime_work_pending()) {
390                                 no_roll (nframes, offset);
391                                 break;
392                         }
393
394                         /* this is necessary to handle the case of seamless looping */
395                         /* not sure if it will work in conjuction with varispeed */
396                         end_frame = _transport_frame + nframes;
397                         
398                 }
399
400                 set_next_event ();
401
402         } /* implicit release of route lock */
403
404
405         if (session_needs_butler) {
406                 summon_butler ();
407         } 
408         
409         if (!_engine.freewheeling() && send_mtc) {
410                 send_midi_time_code_in_another_thread ();
411         }
412
413         return;
414 }               
415
416 void
417 Session::reset_slave_state ()
418 {
419         average_slave_delta = 1800;
420         delta_accumulator_cnt = 0;
421         have_first_delta_accumulator = false;
422         slave_state = Stopped;
423 }
424
425 bool
426 Session::transport_locked () const
427 {
428         Slave* sl = _slave;
429
430         if (!locate_pending() && ((_slave_type == None) || (sl && sl->ok() && sl->locked()))) {
431                 return true;
432         }
433
434         return false;
435 }
436
437 bool
438 Session::follow_slave (jack_nframes_t nframes, jack_nframes_t offset)
439 {
440         float slave_speed;
441         jack_nframes_t slave_transport_frame;
442         jack_nframes_t this_delta;
443         int dir;
444         bool starting;
445
446         if (!_slave->ok()) {
447                 stop_transport ();
448                 set_slave_source (None, 0);
449                 goto noroll;
450         }
451         
452         _slave->speed_and_position (slave_speed, slave_transport_frame);
453
454         if (!_slave->locked()) {
455                 goto noroll;
456         }
457
458         if (slave_transport_frame > _transport_frame) {
459                 this_delta = slave_transport_frame - _transport_frame;
460                 dir = 1;
461         } else {
462                 this_delta = _transport_frame - slave_transport_frame;
463                 dir = -1;
464         }
465
466         if ((starting = _slave->starting())) {
467                 slave_speed = 0.0f;
468         }
469
470 #if 0
471         cerr << "delta = " << (int) (dir * this_delta)
472              << " speed = " << slave_speed 
473              << " ts = " << _transport_speed 
474              << " M@"<< slave_transport_frame << " S@" << _transport_frame 
475              << " avgdelta = " << average_slave_delta 
476              << endl;
477 #endif  
478
479         if (Config->get_timecode_source_is_synced()) {
480
481                 /* if the TC source is synced, then we assume that its 
482                    speed is binary: 0.0 or 1.0
483                 */
484
485                 if (slave_speed != 0.0f) {
486                         slave_speed = 1.0f;
487                 } 
488
489         } else {
490
491                 /* TC source is able to drift relative to us (slave)
492                    so we need to keep track of the drift and adjust
493                    our speed to remain locked.
494                 */
495
496                 if (delta_accumulator_cnt >= delta_accumulator_size) {
497                         have_first_delta_accumulator = true;
498                         delta_accumulator_cnt = 0;
499                 }
500
501                 if (delta_accumulator_cnt != 0 || this_delta < _current_frame_rate) {
502                         delta_accumulator[delta_accumulator_cnt++] = dir*this_delta;
503                 }
504                 
505                 if (have_first_delta_accumulator) {
506                         average_slave_delta = 0;
507                         for (int i = 0; i < delta_accumulator_size; ++i) {
508                                 average_slave_delta += delta_accumulator[i];
509                         }
510                         average_slave_delta /= delta_accumulator_size;
511                         if (average_slave_delta < 0) {
512                                 average_dir = -1;
513                                 average_slave_delta = -average_slave_delta;
514                         } else {
515                                 average_dir = 1;
516                         }
517                         // cerr << "avgdelta = " << average_slave_delta*average_dir << endl;
518                 }
519         }
520
521         if (slave_speed != 0.0f) {
522
523                 /* slave is running */
524
525                 switch (slave_state) {
526                 case Stopped:
527                         if (_slave->requires_seekahead()) {
528                                 slave_wait_end = slave_transport_frame + _current_frame_rate;
529                                 locate (slave_wait_end, false, false);
530                                 slave_state = Waiting;
531                                 starting = true;
532
533                         } else {
534
535                                 slave_state = Running;
536
537                                 Location* al = _locations.auto_loop_location();
538
539                                 if (al && auto_loop && (slave_transport_frame < al->start() || slave_transport_frame > al->end())) {
540                                         // cancel looping
541                                         request_auto_loop(false);
542                                 }
543
544                                 if (slave_transport_frame != _transport_frame) {
545                                         locate (slave_transport_frame, false, false);
546                                 }
547                         }
548                         break;
549
550                 case Waiting:
551                         break;
552
553                 default:
554                         break;
555
556                 }
557
558                 if (slave_state == Waiting) {
559
560                         // cerr << "waiting at " << slave_transport_frame << endl;
561                         Glib::RWLock::ReaderLock dsm (diskstream_lock, Glib::TRY_LOCK);
562                                 
563                         if (dsm.locked() && slave_transport_frame >= slave_wait_end) {
564                                 // cerr << "\tstart at " << _transport_frame << endl;
565
566                                 slave_state = Running;
567
568                                 bool ok = true;
569                                 jack_nframes_t frame_delta = slave_transport_frame - _transport_frame;
570                                 
571                                 for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
572                                         if (!(*i)->can_internal_playback_seek (frame_delta)) {
573                                                 ok = false;
574                                                 break;
575                                         }
576                                 }
577
578                                 if (ok) {
579                                         for (AudioDiskstreamList::iterator i = audio_diskstreams.begin(); i != audio_diskstreams.end(); ++i) {
580                                                 (*i)->internal_playback_seek (frame_delta);
581                                         }
582                                         _transport_frame += frame_delta;
583                                        
584                                 } else {
585                                         // cerr << "cannot micro-seek\n";
586                                         /* XXX what? */
587                                 }
588
589                                 memset (delta_accumulator, 0, sizeof (jack_nframes_t) * delta_accumulator_size);
590                                 average_slave_delta = 0;
591                                 this_delta = 0;
592                         }
593                 }
594                 
595                 if (slave_state == Running && _transport_speed == 0.0f) {
596                         
597                         // cerr << "slave starts transport\n";
598                         
599                         start_transport ();
600                 } 
601
602         } else {
603
604                 /* slave has stopped */
605
606                 if (_transport_speed != 0.0f) {
607
608                         // cerr << "slave stops transport: " << slave_speed << " frame: " << slave_transport_frame 
609                         // << " tf = " << _transport_frame
610                         // << endl;
611                         
612                         if (_slave_type == JACK) {
613                                 last_stop_frame = _transport_frame;
614                         }
615
616                         stop_transport();
617                 }
618
619                 if (slave_transport_frame != _transport_frame) {
620                         // cerr << "slave stopped, move to " << slave_transport_frame << endl;
621                         force_locate (slave_transport_frame, false);
622                 }
623
624                 slave_state = Stopped;
625         }
626
627         if (slave_state == Running && !Config->get_timecode_source_is_synced()) {
628
629
630                 if (_transport_speed != 0.0f) {
631                         
632                         /* 
633                            note that average_dir is +1 or -1 
634                         */
635                         
636                         const float adjust_seconds = 1.0f;
637                         float delta;
638
639                         //if (average_slave_delta == 0) {
640                                 delta = this_delta;
641                                 delta *= dir;
642 //                      } else {
643 //                              delta = average_slave_delta;
644 //                              delta *= average_dir;
645 //                      }
646
647                         float adjusted_speed = slave_speed +
648                                 (delta / (adjust_seconds * _current_frame_rate));
649                         
650                         // cerr << "adjust using " << delta
651                         // << " towards " << adjusted_speed
652                         // << " ratio = " << adjusted_speed / slave_speed
653                         // << " current = " << _transport_speed
654                         // << " slave @ " << slave_speed
655                         // << endl;
656                         
657                         request_transport_speed (adjusted_speed);
658                         
659 #if 1
660                         if ((jack_nframes_t) average_slave_delta > _slave->resolution()) {
661                                 // cerr << "not locked\n";
662                                 goto silent_motion;
663                         }
664 #endif
665                 }
666         } 
667
668         if (!starting && !non_realtime_work_pending()) {
669                 /* speed is set, we're locked, and good to go */
670                 return true;
671         }
672
673   silent_motion:
674
675         if (slave_speed && _transport_speed) {
676
677                 /* something isn't right, but we should move with the master
678                    for now.
679                 */
680
681                 bool need_butler;
682                 
683                 Glib::RWLock::ReaderLock dsm (diskstream_lock, Glib::TRY_LOCK);
684                 if (!dsm.locked()) {
685                         goto noroll;
686                 }
687
688                 
689                 prepare_diskstreams ();
690                 silent_process_routes (nframes, offset);
691                 commit_diskstreams (nframes, need_butler);
692
693                 if (need_butler) {
694                         summon_butler ();
695                 }
696                 
697                 jack_nframes_t frames_moved = (long) floor (_transport_speed * nframes);
698                 
699                 if (frames_moved < 0) {
700                         decrement_transport_position (-frames_moved);
701                 } else {
702                         increment_transport_position (frames_moved);
703                 }
704                 
705                 jack_nframes_t stop_limit;
706                 
707                 if (actively_recording()) {
708                         stop_limit = max_frames;
709                 } else {
710                         if (Config->get_stop_at_session_end()) {
711                                 stop_limit = current_end_frame();
712                         } else {
713                                 stop_limit = max_frames;
714                         }
715                 }
716
717                 maybe_stop (stop_limit);
718         }
719
720   noroll:
721         /* don't move at all */
722         no_roll (nframes, 0);
723         return false;
724 }
725
726 void
727 Session::process_without_events (jack_nframes_t nframes)
728 {
729         bool session_needs_butler = false;
730         jack_nframes_t stop_limit;
731         long frames_moved;
732         
733         {
734                 Glib::RWLock::ReaderLock rm (route_lock, Glib::TRY_LOCK);
735                 Glib::RWLock::ReaderLock dsm (diskstream_lock, Glib::TRY_LOCK);
736
737                 if (!rm.locked() || !dsm.locked() || (post_transport_work & (PostTransportLocate|PostTransportStop))) {
738                         no_roll (nframes, 0);
739                         return;
740                 }
741
742                 if (!_exporting && _slave) {
743                         if (!follow_slave (nframes, 0)) {
744                                 return;
745                         }
746                 } 
747
748                 if (_transport_speed == 0) {
749                         no_roll (nframes, 0);
750                         return;
751                 }
752                 
753                 if (actively_recording()) {
754                         stop_limit = max_frames;
755                 } else {
756                         if (Config->get_stop_at_session_end()) {
757                                 stop_limit = current_end_frame();
758                         } else {
759                                 stop_limit = max_frames;
760                         }
761                 }
762                 
763                 if (maybe_stop (stop_limit)) {
764                         no_roll (nframes, 0);
765                         return;
766                 } 
767
768                 click (_transport_frame, nframes, 0);
769
770                 prepare_diskstreams ();
771         
772                 frames_moved = (long) floor (_transport_speed * nframes);
773
774                 if (process_routes (nframes, 0)) {
775                         no_roll (nframes, 0);
776                         return;
777                 }
778
779                 commit_diskstreams (nframes, session_needs_butler);
780
781                 if (frames_moved < 0) {
782                         decrement_transport_position (-frames_moved);
783                 } else {
784                         increment_transport_position (frames_moved);
785                 }
786                 
787                 maybe_stop (stop_limit);
788                 check_declick_out ();
789
790         } /* implicit release of route lock */
791
792         if (session_needs_butler) {
793                 summon_butler ();
794         } 
795         
796         if (!_engine.freewheeling() && send_mtc) {
797                 send_midi_time_code_in_another_thread ();
798         }
799
800         return;
801 }               
802
803 void
804 Session::process_audition (jack_nframes_t nframes)
805 {
806         Glib::RWLock::ReaderLock rm (route_lock, Glib::TRY_LOCK);
807         Event* ev;
808
809         if (rm.locked()) {
810                 for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
811                         if (!(*i)->hidden()) {
812                                 (*i)->silence (nframes, 0);
813                         }
814                 }
815         }
816         
817         if (auditioner->play_audition (nframes) > 0) {
818                 summon_butler ();
819         } 
820
821         while (pending_events.read (&ev, 1) == 1) {
822                 merge_event (ev);
823         }
824
825         /* if we are not in the middle of a state change,
826            and there are immediate events queued up,
827            process them. 
828         */
829
830         while (!non_realtime_work_pending() && !immediate_events.empty()) {
831                 Event *ev = immediate_events.front ();
832                 immediate_events.pop_front ();
833                 process_event (ev);
834         }
835
836         if (!auditioner->active()) {
837                 process_function = &Session::process_with_events;
838         }
839 }
840