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