fix comment indentation
[ardour.git] / libs / ardour / midi_track.cc
1 /*
2     Copyright (C) 2006 Paul Davis
3     Author: David Robillard
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "pbd/enumwriter.h"
21 #include "pbd/convert.h"
22 #include "evoral/midi_util.h"
23
24 #include "ardour/buffer_set.h"
25 #include "ardour/debug.h"
26 #include "ardour/delivery.h"
27 #include "ardour/meter.h"
28 #include "ardour/midi_diskstream.h"
29 #include "ardour/midi_playlist.h"
30 #include "ardour/midi_port.h"
31 #include "ardour/midi_track.h"
32 #include "ardour/port.h"
33 #include "ardour/processor.h"
34 #include "ardour/session.h"
35 #include "ardour/session_playlists.h"
36 #include "ardour/utils.h"
37
38 #include "i18n.h"
39
40 namespace ARDOUR {
41 class InterThreadInfo;
42 class MidiSource;
43 class Region;
44 class SMFSource;
45 }
46
47 using namespace std;
48 using namespace ARDOUR;
49 using namespace PBD;
50
51 MidiTrack::MidiTrack (Session& sess, string name, Route::Flag flag, TrackMode mode)
52         : Track (sess, name, flag, mode, DataType::MIDI)
53         , _immediate_events(1024) // FIXME: size?
54         , _step_edit_ring_buffer(64) // FIXME: size?
55         , _note_mode(Sustained)
56         , _step_editing (false)
57         , _input_active (true)
58 {
59 }
60
61 MidiTrack::~MidiTrack ()
62 {
63 }
64
65 int
66 MidiTrack::init ()
67 {
68         if (Track::init ()) {
69                 return -1;
70         }
71
72         _input->changed.connect_same_thread (*this, boost::bind (&MidiTrack::track_input_active, this, _1, _2));
73
74         return 0;
75 }
76
77 boost::shared_ptr<Diskstream>
78 MidiTrack::create_diskstream ()
79 {
80         MidiDiskstream::Flag dflags = MidiDiskstream::Flag (0);
81
82         if (_flags & Hidden) {
83                 dflags = MidiDiskstream::Flag (dflags | MidiDiskstream::Hidden);
84         } else {
85                 dflags = MidiDiskstream::Flag (dflags | MidiDiskstream::Recordable);
86         }
87
88         assert(_mode != Destructive);
89
90         return boost::shared_ptr<Diskstream> (new MidiDiskstream (_session, name(), dflags));
91 }
92
93
94 void
95 MidiTrack::set_record_enabled (bool yn, void *src)
96 {
97         if (_step_editing) {
98                 return;
99         }
100
101         Track::set_record_enabled (yn, src);
102 }
103
104 void
105 MidiTrack::set_diskstream (boost::shared_ptr<Diskstream> ds)
106 {
107         /* We have to do this here, as Track::set_diskstream will cause a buffer refill,
108            and the diskstream must be set up to fill its buffers using the correct _note_mode.
109         */
110         boost::shared_ptr<MidiDiskstream> mds = boost::dynamic_pointer_cast<MidiDiskstream> (ds);
111         mds->set_note_mode (_note_mode);
112         
113         Track::set_diskstream (ds);
114
115         mds->reset_tracker ();  
116
117         _diskstream->set_track (this);
118         _diskstream->set_destructive (_mode == Destructive);
119         _diskstream->set_record_enabled (false);
120
121         _diskstream_data_recorded_connection.disconnect ();
122         mds->DataRecorded.connect_same_thread (
123                 _diskstream_data_recorded_connection,
124                 boost::bind (&MidiTrack::diskstream_data_recorded, this, _1));
125
126         DiskstreamChanged (); /* EMIT SIGNAL */
127 }
128
129 boost::shared_ptr<MidiDiskstream>
130 MidiTrack::midi_diskstream() const
131 {
132         return boost::dynamic_pointer_cast<MidiDiskstream>(_diskstream);
133 }
134
135 int
136 MidiTrack::set_state (const XMLNode& node, int version)
137 {
138         const XMLProperty *prop;
139
140         /* This must happen before Track::set_state(), as there will be a buffer
141            fill during that call, and we must fill buffers using the correct
142            _note_mode.
143         */
144         if ((prop = node.property (X_("note-mode"))) != 0) {
145                 _note_mode = NoteMode (string_2_enum (prop->value(), _note_mode));
146         } else {
147                 _note_mode = Sustained;
148         }
149
150         if (Track::set_state (node, version)) {
151                 return -1;
152         }
153
154         // No destructive MIDI tracks (yet?)
155         _mode = Normal;
156
157         if ((prop = node.property ("input-active")) != 0) {
158                 set_input_active (string_is_affirmative (prop->value()));
159         }
160
161         pending_state = const_cast<XMLNode*> (&node);
162
163         if (_session.state_of_the_state() & Session::Loading) {
164                 _session.StateReady.connect_same_thread (
165                         *this, boost::bind (&MidiTrack::set_state_part_two, this));
166         } else {
167                 set_state_part_two ();
168         }
169
170         return 0;
171 }
172
173 XMLNode&
174 MidiTrack::state(bool full_state)
175 {
176         XMLNode& root (Track::state(full_state));
177         XMLNode* freeze_node;
178         char buf[64];
179
180         if (_freeze_record.playlist) {
181                 XMLNode* inode;
182
183                 freeze_node = new XMLNode (X_("freeze-info"));
184                 freeze_node->add_property ("playlist", _freeze_record.playlist->name());
185                 freeze_node->add_property ("state", enum_2_string (_freeze_record.state));
186
187                 for (vector<FreezeRecordProcessorInfo*>::iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
188                         inode = new XMLNode (X_("processor"));
189                         (*i)->id.print (buf, sizeof(buf));
190                         inode->add_property (X_("id"), buf);
191                         inode->add_child_copy ((*i)->state);
192
193                         freeze_node->add_child_nocopy (*inode);
194                 }
195
196                 root.add_child_nocopy (*freeze_node);
197         }
198
199         root.add_property (X_("note-mode"), enum_2_string (_note_mode));
200
201         root.add_property ("step-editing", (_step_editing ? "yes" : "no"));
202         root.add_property ("note-mode", enum_2_string (_note_mode));
203         root.add_property ("input-active", (_input_active ? "yes" : "no"));
204
205         return root;
206 }
207
208 void
209 MidiTrack::set_state_part_two ()
210 {
211         XMLNode* fnode;
212         XMLProperty* prop;
213         LocaleGuard lg (X_("POSIX"));
214
215         /* This is called after all session state has been restored but before
216            have been made ports and connections are established.
217         */
218
219         if (pending_state == 0) {
220                 return;
221         }
222
223         if ((fnode = find_named_node (*pending_state, X_("freeze-info"))) != 0) {
224
225                 _freeze_record.state = Frozen;
226
227                 for (vector<FreezeRecordProcessorInfo*>::iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
228                         delete *i;
229                 }
230                 _freeze_record.processor_info.clear ();
231
232                 if ((prop = fnode->property (X_("playlist"))) != 0) {
233                         boost::shared_ptr<Playlist> pl = _session.playlists->by_name (prop->value());
234                         if (pl) {
235                                 _freeze_record.playlist = boost::dynamic_pointer_cast<MidiPlaylist> (pl);
236                         } else {
237                                 _freeze_record.playlist.reset();
238                                 _freeze_record.state = NoFreeze;
239                         return;
240                         }
241                 }
242
243                 if ((prop = fnode->property (X_("state"))) != 0) {
244                         _freeze_record.state = FreezeState (string_2_enum (prop->value(), _freeze_record.state));
245                 }
246
247                 XMLNodeConstIterator citer;
248                 XMLNodeList clist = fnode->children();
249
250                 for (citer = clist.begin(); citer != clist.end(); ++citer) {
251                         if ((*citer)->name() != X_("processor")) {
252                                 continue;
253                         }
254
255                         if ((prop = (*citer)->property (X_("id"))) == 0) {
256                                 continue;
257                         }
258
259                         FreezeRecordProcessorInfo* frii = new FreezeRecordProcessorInfo (*((*citer)->children().front()),
260                                                                                    boost::shared_ptr<Processor>());
261                         frii->id = prop->value ();
262                         _freeze_record.processor_info.push_back (frii);
263                 }
264         }
265
266         if (midi_diskstream ()) {
267                 midi_diskstream()->set_block_size (_session.get_block_size ());
268         }
269
270         return;
271 }
272
273 /** @param need_butler to be set to true if this track now needs the butler, otherwise it can be left alone
274  *  or set to false.
275  */
276 int
277 MidiTrack::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& need_butler)
278 {
279         Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
280         if (!lm.locked()) {
281                 return 0;
282         }
283
284         boost::shared_ptr<MidiDiskstream> diskstream = midi_diskstream();
285
286         automation_snapshot (start_frame);
287
288         if (n_outputs().n_total() == 0 && _processors.empty()) {
289                 return 0;
290         }
291
292         if (!_active) {
293                 silence (nframes);
294                 return 0;
295         }
296
297         framepos_t transport_frame = _session.transport_frame();
298
299         int dret;
300         framecnt_t playback_distance;
301
302         if ((nframes = check_initial_delay (nframes, transport_frame)) == 0) {
303                 /* need to do this so that the diskstream sets its
304                    playback distance to zero, thus causing diskstream::commit
305                    to do nothing.
306                    */
307                 dret = diskstream->process (transport_frame, 0, playback_distance);
308                 need_butler = diskstream->commit (playback_distance);
309                 return dret;
310         }
311
312         _silent = false;
313
314         if ((dret = diskstream->process (transport_frame, nframes, playback_distance)) != 0) {
315                 need_butler = diskstream->commit (playback_distance);
316                 silence (nframes);
317                 return dret;
318         }
319
320         /* special condition applies */
321
322         if (_meter_point == MeterInput) {
323                 _input->process_input (_meter, start_frame, end_frame, nframes);
324         }
325
326         if (monitoring_state() == MonitoringInput) {
327
328                 /* not actually recording, but we want to hear the input material anyway,
329                    at least potentially (depending on monitoring options)
330                 */
331
332                 passthru (start_frame, end_frame, nframes, 0);
333
334         } else {
335                 /*
336                    XXX is it true that the earlier test on n_outputs()
337                    means that we can avoid checking it again here? i think
338                    so, because changing the i/o configuration of an IO
339                    requires holding the AudioEngine lock, which we hold
340                    while in the process() tree.
341                    */
342
343
344                 /* copy the diskstream data to all output buffers */
345
346                 //const size_t limit = n_process_buffers().n_audio();
347                 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
348                 MidiBuffer& mbuf (bufs.get_midi (0));
349
350                 /* we are a MIDI track, so we always start the chain with a single-channel diskstream */
351                 ChanCount c;
352                 c.set_audio (0);
353                 c.set_midi (1);
354                 bufs.set_count (c);
355
356                 diskstream->get_playback (mbuf, nframes);
357
358                 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
359
360                 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
361
362                 /* final argument: don't waste time with automation if we're recording or we've just stopped (yes it can happen) */
363
364                 process_output_buffers (
365                         bufs, start_frame, end_frame, nframes,
366                         declick, (!diskstream->record_enabled() && !_session.transport_stopped())
367                         );
368         }
369
370         for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
371                 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
372                 if (d) {
373                         d->flush_buffers (nframes);
374                 }
375         }
376
377         need_butler = diskstream->commit (playback_distance);
378         
379         return 0;
380 }
381
382 int
383 MidiTrack::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool state_changing)
384 {
385         int ret = Track::no_roll (nframes, start_frame, end_frame, state_changing);
386
387         if (ret == 0 && _step_editing) {
388                 push_midi_input_to_step_edit_ringbuffer (nframes);
389         }
390
391         return ret;
392 }
393
394 void
395 MidiTrack::realtime_locate ()
396 {
397         Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
398
399         if (!lm.locked ()) {
400                 return;
401         }
402
403         for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
404                 (*i)->realtime_locate ();
405         }
406
407         midi_diskstream()->reset_tracker ();
408 }
409
410 void
411 MidiTrack::realtime_handle_transport_stopped ()
412 {
413         Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
414
415         if (!lm.locked ()) {
416                 return;
417         }
418
419         for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
420                 (*i)->realtime_handle_transport_stopped ();
421         }
422 }
423
424 void
425 MidiTrack::push_midi_input_to_step_edit_ringbuffer (framecnt_t nframes)
426 {
427         PortSet& ports (_input->ports());
428
429         for (PortSet::iterator p = ports.begin(DataType::MIDI); p != ports.end(DataType::MIDI); ++p) {
430
431                 Buffer& b (p->get_buffer (nframes));
432                 const MidiBuffer* const mb = dynamic_cast<MidiBuffer*>(&b);
433                 assert (mb);
434
435                 for (MidiBuffer::const_iterator e = mb->begin(); e != mb->end(); ++e) {
436
437                         const Evoral::MIDIEvent<framepos_t> ev(*e, false);
438
439                         /* note on, since for step edit, note length is determined
440                            elsewhere
441                         */
442
443                         if (ev.is_note_on()) {
444                                 /* we don't care about the time for this purpose */
445                                 _step_edit_ring_buffer.write (0, ev.type(), ev.size(), ev.buffer());
446                         }
447                 }
448         }
449 }
450
451 void
452 MidiTrack::write_out_of_band_data (BufferSet& bufs, framepos_t /*start*/, framepos_t /*end*/, framecnt_t nframes)
453 {
454         MidiBuffer& buf (bufs.get_midi (0));
455
456         // Append immediate events
457
458         if (_immediate_events.read_space()) {
459
460                 DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n",
461                                                             name(), _immediate_events.read_space()));
462
463                 /* write as many of the immediate events as we can, but give "true" as
464                  * the last argument ("stop on overflow in destination") so that we'll
465                  * ship the rest out next time.
466                  *
467                  * the (nframes-1) argument puts all these events at the last
468                  * possible position of the output buffer, so that we do not
469                  * violate monotonicity when writing.
470                  */
471
472                 _immediate_events.read (buf, 0, 1, nframes-1, true);
473         }
474 }
475
476 int
477 MidiTrack::export_stuff (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framecnt_t /*nframes*/, 
478                          boost::shared_ptr<Processor> /*endpoint*/, bool /*include_endpoint*/, bool /*forexport*/)
479 {
480         return -1;
481 }
482
483 boost::shared_ptr<Region>
484 MidiTrack::bounce (InterThreadInfo& /*itt*/)
485 {
486         std::cerr << "MIDI bounce currently unsupported" << std::endl;
487         return boost::shared_ptr<Region> ();
488 }
489
490
491 boost::shared_ptr<Region>
492 MidiTrack::bounce_range (framepos_t /*start*/, framepos_t /*end*/, InterThreadInfo& /*itt*/,
493                          boost::shared_ptr<Processor> /*endpoint*/, bool /*include_endpoint*/)
494 {
495         std::cerr << "MIDI bounce range currently unsupported" << std::endl;
496         return boost::shared_ptr<Region> ();
497 }
498
499 void
500 MidiTrack::freeze_me (InterThreadInfo& /*itt*/)
501 {
502         std::cerr << "MIDI freeze currently unsupported" << std::endl;
503 }
504
505 void
506 MidiTrack::unfreeze ()
507 {
508         _freeze_record.state = UnFrozen;
509         FreezeChange (); /* EMIT SIGNAL */
510 }
511
512 void
513 MidiTrack::set_note_mode (NoteMode m)
514 {
515         _note_mode = m;
516         midi_diskstream()->set_note_mode(m);
517 }
518
519 void
520 MidiTrack::midi_panic()
521 {
522         DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers panic data\n", name()));
523         for (uint8_t channel = 0; channel <= 0xF; channel++) {
524                 uint8_t ev[3] = { ((uint8_t) (MIDI_CMD_CONTROL | channel)), ((uint8_t) MIDI_CTL_SUSTAIN), 0 };
525                 write_immediate_event(3, ev);
526                 ev[1] = MIDI_CTL_ALL_NOTES_OFF;
527                 write_immediate_event(3, ev);
528                 ev[1] = MIDI_CTL_RESET_CONTROLLERS;
529                 write_immediate_event(3, ev);
530         }
531 }
532
533 /** \return true on success, false on failure (no buffer space left)
534  */
535 bool
536 MidiTrack::write_immediate_event(size_t size, const uint8_t* buf)
537 {
538         if (!Evoral::midi_event_is_valid(buf, size)) {
539                 cerr << "WARNING: Ignoring illegal immediate MIDI event" << endl;
540                 return false;
541         }
542         const uint32_t type = EventTypeMap::instance().midi_event_type(buf[0]);
543         return (_immediate_events.write(0, type, size, buf) == size);
544 }
545
546 void
547 MidiTrack::MidiControl::set_value(double val)
548 {
549         bool valid = false;
550         if (std::isinf(val)) {
551                 cerr << "MIDIControl value is infinity" << endl;
552         } else if (std::isnan(val)) {
553                 cerr << "MIDIControl value is NaN" << endl;
554         } else if (val < _list->parameter().min()) {
555                 cerr << "MIDIControl value is < " << _list->parameter().min() << endl;
556         } else if (val > _list->parameter().max()) {
557                 cerr << "MIDIControl value is > " << _list->parameter().max() << endl;
558         } else {
559                 valid = true;
560         }
561
562         if (!valid) {
563                 return;
564         }
565
566         assert(val <= _list->parameter().max());
567         if ( ! automation_playback()) {
568                 size_t size = 3;
569                 uint8_t ev[3] = { _list->parameter().channel(), uint8_t (val), 0 };
570                 switch(_list->parameter().type()) {
571                 case MidiCCAutomation:
572                         ev[0] += MIDI_CMD_CONTROL;
573                         ev[1] = _list->parameter().id();
574                         ev[2] = int(val);
575                         break;
576
577                 case MidiPgmChangeAutomation:
578                         size = 2;
579                         ev[0] += MIDI_CMD_PGM_CHANGE;
580                         ev[1] = int(val);
581                         break;
582
583                 case MidiChannelPressureAutomation:
584                         size = 2;
585                         ev[0] += MIDI_CMD_CHANNEL_PRESSURE;
586                         ev[1] = int(val);
587                         break;
588
589                 case MidiPitchBenderAutomation:
590                         ev[0] += MIDI_CMD_BENDER;
591                         ev[1] = 0x7F & int(val);
592                         ev[2] = 0x7F & (int(val) >> 7);
593                         break;
594
595                 default:
596                         assert(false);
597                 }
598                 _route->write_immediate_event(size,  ev);
599         }
600
601         AutomationControl::set_value(val);
602 }
603
604 void
605 MidiTrack::set_step_editing (bool yn)
606 {
607         if (_session.record_status() != Session::Disabled) {
608                 return;
609         }
610
611         if (yn != _step_editing) {
612                 _step_editing = yn;
613                 StepEditStatusChange (yn);
614         }
615 }
616
617 boost::shared_ptr<SMFSource>
618 MidiTrack::write_source (uint32_t)
619 {
620         return midi_diskstream()->write_source ();
621 }
622
623 void
624 MidiTrack::set_channel_mode (ChannelMode mode, uint16_t mask)
625 {
626         midi_diskstream()->set_channel_mode (mode, mask);
627 }
628
629 ChannelMode
630 MidiTrack::get_channel_mode ()
631 {
632         return midi_diskstream()->get_channel_mode ();
633 }
634
635 uint16_t
636 MidiTrack::get_channel_mask ()
637 {
638         return midi_diskstream()->get_channel_mask ();
639 }
640
641 boost::shared_ptr<MidiPlaylist>
642 MidiTrack::midi_playlist ()
643 {
644         return midi_diskstream()->midi_playlist ();
645 }
646
647 void
648 MidiTrack::diskstream_data_recorded (boost::weak_ptr<MidiSource> src)
649 {
650         DataRecorded (src); /* EMIT SIGNAL */
651 }
652
653 bool
654 MidiTrack::input_active () const
655 {
656         return _input_active;
657 }
658
659 void
660 MidiTrack::set_input_active (bool yn)
661 {
662         if (yn != _input_active) {
663                 _input_active = yn;
664                 map_input_active (yn);
665                 InputActiveChanged (); /* EMIT SIGNAL */
666         }
667 }
668
669 void
670 MidiTrack::map_input_active (bool yn)
671 {
672         if (!_input) {
673                 return;
674         }
675
676         PortSet& ports (_input->ports());
677
678         for (PortSet::iterator p = ports.begin(DataType::MIDI); p != ports.end(DataType::MIDI); ++p) {
679                 boost::shared_ptr<MidiPort> mp = boost::dynamic_pointer_cast<MidiPort> (*p);
680                 if (yn != mp->input_active()) {
681                         mp->set_input_active (yn);
682                 }
683         }
684 }
685
686 void
687 MidiTrack::track_input_active (IOChange change, void* /* src */)
688 {
689         if (change.type & IOChange::ConfigurationChanged) {
690                 map_input_active (_input_active);
691         }
692 }
693
694 boost::shared_ptr<Diskstream>
695 MidiTrack::diskstream_factory (XMLNode const & node)
696 {
697         return boost::shared_ptr<Diskstream> (new MidiDiskstream (_session, node));
698 }
699
700 boost::shared_ptr<MidiBuffer>
701 MidiTrack::get_gui_feed_buffer () const
702 {
703         return midi_diskstream()->get_gui_feed_buffer ();
704 }
705
706 void
707 MidiTrack::act_on_mute ()
708 {
709         /* this is called right after our mute status has changed.
710            if we are now muted, send suitable output to shutdown
711            all our notes.
712
713            XXX we should should also stop all relevant note trackers.
714         */
715
716         if (muted()) {
717                 /* only send messages for channels we are using */
718
719                 uint16_t mask = get_channel_mask();
720
721                 for (uint8_t channel = 0; channel <= 0xF; channel++) {
722
723                         if ((1<<channel) & mask) {
724
725                                 DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers mute message to channel %2\n", name(), channel+1));
726                                 uint8_t ev[3] = { ((uint8_t) (MIDI_CMD_CONTROL | channel)), MIDI_CTL_SUSTAIN, 0 };
727                                 write_immediate_event (3, ev);
728                                 ev[1] = MIDI_CTL_ALL_NOTES_OFF;
729                                 write_immediate_event (3, ev);
730                         }
731                 }
732         }
733 }
734         
735 void
736 MidiTrack::set_monitoring (MonitorChoice mc)
737 {
738         Track::set_monitoring (mc);
739
740         boost::shared_ptr<MidiDiskstream> md (midi_diskstream());
741
742         if (md) {
743                 md->reset_tracker ();
744         }
745 }
746
747 MonitorState
748 MidiTrack::monitoring_state () const
749 {
750         /* Explicit requests */
751         
752         if (_monitoring & MonitorInput) {
753                 return MonitoringInput;
754         }
755                 
756         if (_monitoring & MonitorDisk) {
757                 return MonitoringDisk;
758         }
759
760         if (_session.transport_rolling()) {
761                 return MonitoringDisk;
762         } 
763
764         /* the return value here doesn't mean that we're actually monitoring
765          * input, let alone input *audio*. but it means that we are NOT 
766          * monitoring silence. this allows us to still hear any audio generated
767          * by using internal generation techniques
768          */
769
770         return MonitoringInput;
771 }