ba66d3ea2d8e93ad9f2834414c3a546bc2dd8458
[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, send an MTC Full Frame (SMPTE) message.
282          * This is sent whether rolling or not, to give slaves an idea of ardour time
283          * on locates (and allow slow slaves to position and prepare for rolling)
284          */
285         if (_send_smpte_update) {
286                 send_full_time_code(nframes);
287         }
288
289         if (!process_can_proceed()) {
290                 no_roll (nframes, 0);
291                 return;
292         }
293
294         if (events.empty() || next_event == events.end()) {
295                 process_without_events (nframes);
296                 return;
297         }
298
299         end_frame = _transport_frame + nframes;
300
301         {
302                 TentativeRWLockMonitor rm (route_lock, false, __LINE__, __FILE__);
303                 TentativeRWLockMonitor dsm (diskstream_lock, false, __LINE__, __FILE__);
304         
305                 Event* this_event;
306                 Events::iterator the_next_one;
307
308                 if (!rm.locked() || !dsm.locked() || (post_transport_work & (PostTransportLocate|PostTransportStop))) {
309                         no_roll (nframes, 0);
310                         return;
311                 }
312                 
313                 if (!_exporting && _slave) {
314                         if (!follow_slave (nframes, 0)) {
315                                 return;
316                         }
317                 } 
318
319                 if (_transport_speed == 0) {
320                         no_roll (nframes, 0);
321                         return;
322                 }
323         
324                 send_midi_time_code_for_cycle(nframes);
325
326                 if (actively_recording()) {
327                         stop_limit = max_frames;
328                 } else {
329
330                         if (Config->get_stop_at_session_end()) {
331                                 stop_limit = current_end_frame();
332                         } else {
333                                 stop_limit = max_frames;
334                         }
335                 }
336
337                 if (maybe_stop (stop_limit)) {
338                         no_roll (nframes, 0);
339                         return;
340                 } 
341
342                 this_event = *next_event;
343                 the_next_one = next_event;
344                 ++the_next_one;
345
346                 offset = 0;
347
348                 while (nframes) {
349
350                         if (this_event == 0 || this_event->action_frame > end_frame || this_event->action_frame < _transport_frame) {
351
352                                 this_nframes = nframes;
353                                 
354                         } else {
355                                 
356                                 /* compute nframes to next event */
357
358                                 if (this_event->action_frame < end_frame) {
359                                         this_nframes = nframes - (end_frame - this_event->action_frame);
360                                 } else {
361                                         this_nframes = nframes;
362                                 }
363                         }
364
365                         if (this_nframes) {
366                                 
367                                 click (_transport_frame, nframes, offset);
368                                 
369                                 /* now process frames between now and the first event in this block */
370                                 prepare_diskstreams ();
371
372                                 if (process_routes (this_nframes, offset)) {
373                                         no_roll (nframes, 0);
374                                         return;
375                                 }
376                                 
377                                 commit_diskstreams (this_nframes, session_needs_butler);
378
379                                 nframes -= this_nframes;
380                                 offset += this_nframes;
381                                 
382                                 frames_moved = (jack_nframes_t) floor (_transport_speed * this_nframes);
383                         
384                                 if (frames_moved < 0) {
385                                         decrement_transport_position (-frames_moved);
386                                 } else {
387                                         increment_transport_position (frames_moved);
388                                 }
389
390                                 maybe_stop (stop_limit);
391                                 check_declick_out ();
392                         }
393
394                         /* now handle this event and all others scheduled for the same time */
395                         
396                         while (this_event && this_event->action_frame == _transport_frame) {
397                                 process_event (this_event);
398
399                                 if (the_next_one == events.end()) {
400                                         this_event = 0;
401                                 } else {
402                                         this_event = *the_next_one;
403                                         ++the_next_one;
404                                 }
405                         } 
406
407                         /* if an event left our state changing, do the right thing */
408
409                         if (non_realtime_work_pending()) {
410                                 no_roll (nframes, offset);
411                                 break;
412                         }
413
414                         /* this is necessary to handle the case of seamless looping */
415                         /* not sure if it will work in conjuction with varispeed */
416                         end_frame = _transport_frame + nframes;
417                         
418                 }
419
420                 set_next_event ();
421
422         } /* implicit release of route lock */
423
424         if (session_needs_butler)
425                 summon_butler ();
426 }
427
428 void
429 Session::reset_slave_state ()
430 {
431         average_slave_delta = 1800;
432         delta_accumulator_cnt = 0;
433         have_first_delta_accumulator = false;
434         slave_state = Stopped;
435 }
436
437 bool
438 Session::transport_locked () const
439 {
440         Slave* sl = _slave;
441
442         if (!locate_pending() && ((_slave_type == None) || (sl && sl->ok() && sl->locked()))) {
443                 return true;
444         }
445
446         return false;
447 }
448
449 bool
450 Session::follow_slave (jack_nframes_t nframes, jack_nframes_t offset)
451 {
452         float slave_speed;
453         jack_nframes_t slave_transport_frame;
454         jack_nframes_t this_delta;
455         int dir;
456         bool starting;
457
458         if (!_slave->ok()) {
459                 stop_transport ();
460                 set_slave_source (None, 0);
461                 goto noroll;
462         }
463         
464         _slave->speed_and_position (slave_speed, slave_transport_frame);
465
466         if (!_slave->locked()) {
467                 goto noroll;
468         }
469
470         if (slave_transport_frame > _transport_frame) {
471                 this_delta = slave_transport_frame - _transport_frame;
472                 dir = 1;
473         } else {
474                 this_delta = _transport_frame - slave_transport_frame;
475                 dir = -1;
476         }
477
478         if ((starting = _slave->starting())) {
479                 slave_speed = 0.0f;
480         }
481
482 #if 0
483         cerr << "delta = " << (int) (dir * this_delta)
484              << " speed = " << slave_speed 
485              << " ts = " << _transport_speed 
486              << " M@"<< slave_transport_frame << " S@" << _transport_frame 
487              << " avgdelta = " << average_slave_delta 
488              << endl;
489 #endif  
490
491         if (Config->get_timecode_source_is_synced()) {
492
493                 /* if the TC source is synced, then we assume that its 
494                    speed is binary: 0.0 or 1.0
495                 */
496
497                 if (slave_speed != 0.0f) {
498                         slave_speed = 1.0f;
499                 } 
500
501         } else {
502
503                 /* TC source is able to drift relative to us (slave)
504                    so we need to keep track of the drift and adjust
505                    our speed to remain locked.
506                 */
507
508                 if (delta_accumulator_cnt >= delta_accumulator_size) {
509                         have_first_delta_accumulator = true;
510                         delta_accumulator_cnt = 0;
511                 }
512
513                 if (delta_accumulator_cnt != 0 || this_delta < _current_frame_rate) {
514                         delta_accumulator[delta_accumulator_cnt++] = dir*this_delta;
515                 }
516                 
517                 if (have_first_delta_accumulator) {
518                         average_slave_delta = 0;
519                         for (int i = 0; i < delta_accumulator_size; ++i) {
520                                 average_slave_delta += delta_accumulator[i];
521                         }
522                         average_slave_delta /= delta_accumulator_size;
523                         if (average_slave_delta < 0) {
524                                 average_dir = -1;
525                                 average_slave_delta = -average_slave_delta;
526                         } else {
527                                 average_dir = 1;
528                         }
529                         // cerr << "avgdelta = " << average_slave_delta*average_dir << endl;
530                 }
531         }
532
533         if (slave_speed != 0.0f) {
534
535                 /* slave is running */
536
537                 switch (slave_state) {
538                 case Stopped:
539                         if (_slave->requires_seekahead()) {
540                                 slave_wait_end = slave_transport_frame + _current_frame_rate;
541                                 locate (slave_wait_end, false, false);
542                                 slave_state = Waiting;
543                                 starting = true;
544
545                         } else {
546
547                                 slave_state = Running;
548
549                                 Location* al = _locations.auto_loop_location();
550
551                                 if (al && auto_loop && (slave_transport_frame < al->start() || slave_transport_frame > al->end())) {
552                                         // cancel looping
553                                         request_auto_loop(false);
554                                 }
555
556                                 if (slave_transport_frame != _transport_frame) {
557                                         locate (slave_transport_frame, false, false);
558                                 }
559                         }
560                         break;
561
562                 case Waiting:
563                         break;
564
565                 default:
566                         break;
567
568                 }
569
570                 if (slave_state == Waiting) {
571
572                         // cerr << "waiting at " << slave_transport_frame << endl;
573                         TentativeRWLockMonitor dsm (diskstream_lock, false, __LINE__, __FILE__);
574                                 
575                         if (dsm.locked() && slave_transport_frame >= slave_wait_end) {
576                                 // cerr << "\tstart at " << _transport_frame << endl;
577
578                                 slave_state = Running;
579
580                                 bool ok = true;
581                                 jack_nframes_t frame_delta = slave_transport_frame - _transport_frame;
582                                 
583                                 for (DiskStreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
584                                         if (!(*i)->can_internal_playback_seek (frame_delta)) {
585                                                 ok = false;
586                                                 break;
587                                         }
588                                 }
589
590                                 if (ok) {
591                                         for (DiskStreamList::iterator i = diskstreams.begin(); i != diskstreams.end(); ++i) {
592                                                 (*i)->internal_playback_seek (frame_delta);
593                                         }
594                                         _transport_frame += frame_delta;
595                                        
596                                 } else {
597                                         // cerr << "cannot micro-seek\n";
598                                         /* XXX what? */
599                                 }
600
601                                 memset (delta_accumulator, 0, sizeof (jack_nframes_t) * delta_accumulator_size);
602                                 average_slave_delta = 0;
603                                 this_delta = 0;
604                         }
605                 }
606                 
607                 if (slave_state == Running && _transport_speed == 0.0f) {
608                         
609                         // cerr << "slave starts transport\n";
610                         
611                         start_transport ();
612                 } 
613
614         } else {
615
616                 /* slave has stopped */
617
618                 if (_transport_speed != 0.0f) {
619
620                         // cerr << "slave stops transport: " << slave_speed << " frame: " << slave_transport_frame 
621                         // << " tf = " << _transport_frame
622                         // << endl;
623                         
624                         if (_slave_type == JACK) {
625                                 last_stop_frame = _transport_frame;
626                         }
627
628                         stop_transport();
629                 }
630
631                 if (slave_transport_frame != _transport_frame) {
632                         // cerr << "slave stopped, move to " << slave_transport_frame << endl;
633                         force_locate (slave_transport_frame, false);
634                 }
635
636                 slave_state = Stopped;
637         }
638
639         if (slave_state == Running && !Config->get_timecode_source_is_synced()) {
640
641
642                 if (_transport_speed != 0.0f) {
643                         
644                         /* 
645                            note that average_dir is +1 or -1 
646                         */
647                         
648                         const float adjust_seconds = 1.0f;
649                         float delta;
650
651                         //if (average_slave_delta == 0) {
652                                 delta = this_delta;
653                                 delta *= dir;
654 //                      } else {
655 //                              delta = average_slave_delta;
656 //                              delta *= average_dir;
657 //                      }
658
659                         float adjusted_speed = slave_speed +
660                                 (delta / (adjust_seconds * _current_frame_rate));
661                         
662                         // cerr << "adjust using " << delta
663                         // << " towards " << adjusted_speed
664                         // << " ratio = " << adjusted_speed / slave_speed
665                         // << " current = " << _transport_speed
666                         // << " slave @ " << slave_speed
667                         // << endl;
668                         
669                         request_transport_speed (adjusted_speed);
670                         
671 #if 1
672                         if ((jack_nframes_t) average_slave_delta > _slave->resolution()) {
673                                 // cerr << "not locked\n";
674                                 goto silent_motion;
675                         }
676 #endif
677                 }
678         } 
679
680         if (!starting && !non_realtime_work_pending()) {
681                 /* speed is set, we're locked, and good to go */
682                 return true;
683         }
684
685   silent_motion:
686
687         if (slave_speed && _transport_speed) {
688
689                 /* something isn't right, but we should move with the master
690                    for now.
691                 */
692
693                 bool need_butler;
694                 
695                 TentativeRWLockMonitor dsm (diskstream_lock, false, __LINE__, __FILE__);
696                 if (!dsm.locked()) {
697                         goto noroll;
698                 }
699
700                 
701                 prepare_diskstreams ();
702                 silent_process_routes (nframes, offset);
703                 commit_diskstreams (nframes, need_butler);
704
705                 if (need_butler) {
706                         summon_butler ();
707                 }
708                 
709                 jack_nframes_t frames_moved = (long) floor (_transport_speed * nframes);
710                 
711                 if (frames_moved < 0) {
712                         decrement_transport_position (-frames_moved);
713                 } else {
714                         increment_transport_position (frames_moved);
715                 }
716                 
717                 jack_nframes_t stop_limit;
718                 
719                 if (actively_recording()) {
720                         stop_limit = max_frames;
721                 } else {
722                         if (Config->get_stop_at_session_end()) {
723                                 stop_limit = current_end_frame();
724                         } else {
725                                 stop_limit = max_frames;
726                         }
727                 }
728
729                 maybe_stop (stop_limit);
730         }
731
732   noroll:
733         /* don't move at all */
734         no_roll (nframes, 0);
735         return false;
736 }
737
738 void
739 Session::process_without_events (jack_nframes_t nframes)
740 {
741         bool session_needs_butler = false;
742         jack_nframes_t stop_limit;
743         long frames_moved;
744         
745         {
746                 TentativeRWLockMonitor rm (route_lock, false, __LINE__, __FILE__);
747                 TentativeRWLockMonitor dsm (diskstream_lock, false, __LINE__, __FILE__);
748
749                 if (!rm.locked() || !dsm.locked() || (post_transport_work & (PostTransportLocate|PostTransportStop))) {
750                         no_roll (nframes, 0);
751                         return;
752                 }
753
754                 if (!_exporting && _slave) {
755                         if (!follow_slave (nframes, 0)) {
756                                 return;
757                         }
758                 } 
759
760                 if (_transport_speed == 0) {
761                         no_roll (nframes, 0);
762                         return;
763                 }
764         
765                 send_midi_time_code_for_cycle(nframes);
766                 
767                 if (actively_recording()) {
768                         stop_limit = max_frames;
769                 } else {
770                         if (Config->get_stop_at_session_end()) {
771                                 stop_limit = current_end_frame();
772                         } else {
773                                 stop_limit = max_frames;
774                         }
775                 }
776                 
777                 if (maybe_stop (stop_limit)) {
778                         no_roll (nframes, 0);
779                         return;
780                 } 
781
782                 click (_transport_frame, nframes, 0);
783
784                 prepare_diskstreams ();
785         
786                 frames_moved = (long) floor (_transport_speed * nframes);
787
788                 if (process_routes (nframes, 0)) {
789                         no_roll (nframes, 0);
790                         return;
791                 }
792
793                 commit_diskstreams (nframes, session_needs_butler);
794
795                 if (frames_moved < 0) {
796                         decrement_transport_position (-frames_moved);
797                 } else {
798                         increment_transport_position (frames_moved);
799                 }
800                 
801                 maybe_stop (stop_limit);
802                 check_declick_out ();
803
804         } /* implicit release of route lock */
805
806         if (session_needs_butler)
807                 summon_butler ();
808 }
809
810 void
811 Session::process_audition (jack_nframes_t nframes)
812 {
813         TentativeRWLockMonitor rm (route_lock, false, __LINE__, __FILE__);
814         Event* ev;
815
816         if (rm.locked()) {
817                 for (RouteList::iterator i = routes.begin(); i != routes.end(); ++i) {
818                         if (!(*i)->hidden()) {
819                                 (*i)->silence (nframes, 0);
820                         }
821                 }
822         }
823         
824         if (auditioner->play_audition (nframes) > 0) {
825                 summon_butler ();
826         } 
827
828         while (pending_events.read (&ev, 1) == 1) {
829                 merge_event (ev);
830         }
831
832         /* if we are not in the middle of a state change,
833            and there are immediate events queued up,
834            process them. 
835         */
836
837         while (!non_realtime_work_pending() && !immediate_events.empty()) {
838                 Event *ev = immediate_events.front ();
839                 immediate_events.pop_front ();
840                 process_event (ev);
841         }
842
843         if (!auditioner->active()) {
844                 process_function = &Session::process_with_events;
845         }
846 }
847