Create diskstream before calling Route::set_state, the
[ardour.git] / libs / ardour / track.cc
1 /*
2     Copyright (C) 2006 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 #include "pbd/error.h"
19
20 #include "ardour/amp.h"
21 #include "ardour/debug.h"
22 #include "ardour/delivery.h"
23 #include "ardour/diskstream.h"
24 #include "ardour/io_processor.h"
25 #include "ardour/meter.h"
26 #include "ardour/playlist.h"
27 #include "ardour/port.h"
28 #include "ardour/processor.h"
29 #include "ardour/route_group_specialized.h"
30 #include "ardour/session.h"
31 #include "ardour/track.h"
32 #include "ardour/utils.h"
33
34 #include "i18n.h"
35
36 using namespace std;
37 using namespace ARDOUR;
38 using namespace PBD;
39
40 Track::Track (Session& sess, string name, Route::Flag flag, TrackMode mode, DataType default_type)
41         : Route (sess, name, flag, default_type)
42         , _saved_meter_point (_meter_point)
43         , _mode (mode)
44         , _monitoring (MonitorAuto)
45 {
46         _freeze_record.state = NoFreeze;
47         _declickable = true;
48
49         Config->ParameterChanged.connect_same_thread (*this, boost::bind (&Track::parameter_changed, this, _1));
50 }
51
52 Track::~Track ()
53 {
54         DEBUG_TRACE (DEBUG::Destruction, string_compose ("track %1 destructor\n", _name));
55 }
56
57 int
58 Track::init ()
59 {
60         if (Route::init ()) {
61                 return -1;
62         }
63
64         boost::shared_ptr<Route> rp (shared_from_this());
65         boost::shared_ptr<Track> rt = boost::dynamic_pointer_cast<Track> (rp);
66         _rec_enable_control = boost::shared_ptr<RecEnableControl> (new RecEnableControl(rt));
67         _rec_enable_control->set_flags (Controllable::Toggle);
68
69         /* don't add rec_enable_control to controls because we don't want it to
70          * appear as an automatable parameter
71          */
72
73         return 0;
74 }
75
76 void
77 Track::use_new_diskstream ()
78 {
79         boost::shared_ptr<Diskstream> ds = create_diskstream ();
80
81         ds->do_refill_with_alloc ();
82         ds->set_block_size (_session.get_block_size ());
83         ds->playlist()->set_orig_track_id (id());
84
85         set_diskstream (ds);
86 }
87
88 XMLNode&
89 Track::get_state ()
90 {
91         return state (true);
92 }
93
94 XMLNode&
95 Track::state (bool full)
96 {
97         XMLNode& root (Route::state (full));
98         root.add_property (X_("monitoring"), enum_2_string (_monitoring));
99         root.add_property (X_("saved-meter-point"), enum_2_string (_saved_meter_point));
100         root.add_child_nocopy (_rec_enable_control->get_state());
101         root.add_child_nocopy (_diskstream->get_state ());
102
103         if (!_deactivated_processors.empty ()) {
104                 XMLNode* node = new XMLNode (X_("DeactivatedProcessors"));
105                 for (list<boost::weak_ptr<Processor> >::iterator i = _deactivated_processors.begin(); i != _deactivated_processors.end(); ++i) {
106                         boost::shared_ptr<Processor> p = i->lock ();
107                         if (p) {
108                                 XMLNode* c = new XMLNode (X_("Processor"));
109                                 c->add_property (X_("id"), p->id().to_s());
110                                 node->add_child_nocopy (*c);
111                         }
112                 }
113                 root.add_child_nocopy (*node);
114         }
115         
116         return root;
117 }       
118
119 int
120 Track::set_state (const XMLNode& node, int version)
121 {
122         XMLNode* child;
123
124         /* Create the diskstream before calling Route::set_state, as MidiTrack
125            needs it if the track is muted (it ends up calling MidiTrack::get_channel_mask)
126         */
127            
128         if (version >= 3000) {
129                 if ((child = find_named_node (node, X_("Diskstream"))) != 0) {
130                         boost::shared_ptr<Diskstream> ds = diskstream_factory (*child);
131                         ds->do_refill_with_alloc ();
132                         set_diskstream (ds);
133                 }
134         }
135
136         if (Route::set_state (node, version)) {
137                 return -1;
138         }
139
140         if (_diskstream) {
141                 _diskstream->playlist()->set_orig_track_id (id());
142         }
143
144         /* set rec-enable control *AFTER* setting up diskstream, because it may
145            want to operate on the diskstream as it sets its own state
146         */
147
148         XMLNodeList nlist = node.children();
149         for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter) {
150                 child = *niter;
151
152                 XMLProperty* prop;
153                 if (child->name() == Controllable::xml_node_name && (prop = child->property ("name")) != 0) {
154                         if (prop->value() == X_("recenable")) {
155                                 _rec_enable_control->set_state (*child, version);
156                         }
157                 }
158
159                 if (child->name() == X_("DeactivatedProcessors")) {
160                         XMLNodeList dp = child->children ();
161                         for (XMLNodeConstIterator i = dp.begin(); i != dp.end(); ++i) {
162                                 assert ((*i)->name() == X_("Processor"));
163                                 XMLProperty* prop = (*i)->property (X_("id"));
164                                 boost::shared_ptr<Processor> p = processor_by_id (PBD::ID (prop->value ()));
165                                 if (p) {
166                                         _deactivated_processors.push_back (p);
167                                 }
168                         }
169                 }
170         }
171         
172         const XMLProperty* prop;
173
174         if ((prop = node.property (X_("monitoring"))) != 0) {
175                 _monitoring = MonitorChoice (string_2_enum (prop->value(), _monitoring));
176         } else {
177                 _monitoring = MonitorAuto;
178         }
179
180         if ((prop = node.property (X_("saved-meter-point"))) != 0) {
181                 _saved_meter_point = MeterPoint (string_2_enum (prop->value(), _saved_meter_point));
182         } else {
183                 _saved_meter_point = _meter_point;
184         }
185
186         return 0;
187 }
188
189 XMLNode&
190 Track::get_template ()
191 {
192         return state (false);
193 }
194
195 Track::FreezeRecord::~FreezeRecord ()
196 {
197         for (vector<FreezeRecordProcessorInfo*>::iterator i = processor_info.begin(); i != processor_info.end(); ++i) {
198                 delete *i;
199         }
200 }
201
202 Track::FreezeState
203 Track::freeze_state() const
204 {
205         return _freeze_record.state;
206 }
207
208 Track::RecEnableControl::RecEnableControl (boost::shared_ptr<Track> t)
209         : AutomationControl (t->session(), RecEnableAutomation, boost::shared_ptr<AutomationList>(), X_("recenable"))
210         , track (t)
211 {
212         boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(RecEnableAutomation)));
213         set_list (gl);
214 }
215
216 void
217 Track::RecEnableControl::set_value (double val)
218 {
219         boost::shared_ptr<Track> t = track.lock ();
220         if (!t) {
221                 return;
222         }
223         
224         t->set_record_enabled (val >= 0.5 ? true : false, this);
225 }
226
227 double
228 Track::RecEnableControl::get_value () const
229 {
230         boost::shared_ptr<Track> t = track.lock ();
231         if (!t) {
232                 return 0;
233         }
234         
235         return (t->record_enabled() ? 1.0 : 0.0);
236 }
237
238 bool
239 Track::record_enabled () const
240 {
241         return _diskstream && _diskstream->record_enabled ();
242 }
243
244 bool
245 Track::can_record()
246 {
247         bool will_record = true;
248         for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end() && will_record; ++i) {
249                 if (!i->connected())
250                         will_record = false;
251         }
252
253         return will_record;
254 }
255
256 /* Turn off visible processors (except Fader), keeping track of the old states */
257 void
258 Track::deactivate_visible_processors ()
259 {
260         _deactivated_processors.clear ();
261         Glib::RWLock::ReaderLock lm (_processor_lock);
262         
263         for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
264                 if ((*i)->active() && (*i)->display_to_user() && boost::dynamic_pointer_cast<Amp> (*i) == 0) {
265                         (*i)->deactivate ();
266                         _deactivated_processors.push_back (*i);
267                 }
268         }
269 }
270
271 /* Turn deactivated processors back on again */
272 void
273 Track::activate_deactivated_processors ()
274 {
275         for (list<boost::weak_ptr<Processor> >::iterator i = _deactivated_processors.begin(); i != _deactivated_processors.end(); ++i) {
276                 boost::shared_ptr<Processor> p = i->lock ();
277                 if (p) {
278                         p->activate ();
279                 }
280         }
281 }
282
283 void
284 Track::set_record_enabled (bool yn, void *src)
285 {
286         if (!_session.writable()) {
287                 return;
288         }
289
290         if (_freeze_record.state == Frozen) {
291                 return;
292         }
293
294         if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_recenable()) {
295                 _route_group->apply (&Track::set_record_enabled, yn, _route_group);
296                 return;
297         }
298
299         /* keep track of the meter point as it was before we rec-enabled */
300         if (!_diskstream->record_enabled()) {
301                 _saved_meter_point = _meter_point;
302         }
303
304         if (Config->get_do_not_record_plugins ()) {
305                 if (yn) {
306                         deactivate_visible_processors ();
307                 } else {
308                         activate_deactivated_processors ();
309                 }
310         }
311
312         _diskstream->set_record_enabled (yn);
313
314         if (_diskstream->record_enabled()) {
315                 if (_meter_point != MeterCustom) {
316                         set_meter_point (MeterInput);
317                 }
318         } else {
319                 set_meter_point (_saved_meter_point);
320         }
321
322         _rec_enable_control->Changed ();
323 }
324
325
326 bool
327 Track::set_name (const string& str)
328 {
329         bool ret;
330
331         if (record_enabled() && _session.actively_recording()) {
332                 /* this messes things up if done while recording */
333                 return false;
334         }
335
336         if (_diskstream->playlist()->all_regions_empty ()) {
337                 /* Only rename the diskstream (and therefore the playlist) if
338                    the playlist has never had a region added to it.  Otherwise
339                    people can get confused if, say, they have notes about a
340                    playlist with a given name and then it changes (see mantis
341                    #4759).
342                 */
343                 _diskstream->set_name (str);
344         }
345
346         /* save state so that the statefile fully reflects any filename changes */
347
348         if ((ret = Route::set_name (str)) == 0) {
349                 _session.save_state ("");
350         }
351
352         return ret;
353 }
354
355 void
356 Track::set_latency_compensation (framecnt_t longest_session_latency)
357 {
358         Route::set_latency_compensation (longest_session_latency);
359         _diskstream->set_roll_delay (_roll_delay);
360 }
361
362 int
363 Track::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
364 {
365         Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
366         if (!lm.locked()) {
367                 return 0;
368         }
369
370         bool can_record = _session.actively_recording ();
371
372         if (n_outputs().n_total() == 0) {
373                 return 0;
374         }
375
376         if (!_active) {
377                 silence (nframes);
378                 return 0;
379         }
380
381         if (session_state_changing) {
382                 if (_session.transport_speed() != 0.0f) {
383                         /* we're rolling but some state is changing (e.g. our diskstream contents)
384                            so we cannot use them. Be silent till this is over. Don't declick.
385
386                            XXX note the absurdity of ::no_roll() being called when we ARE rolling!
387                         */
388                         passthru_silence (start_frame, end_frame, nframes, 0);
389                         return 0;
390                 }
391                 /* we're really not rolling, so we're either delivery silence or actually
392                    monitoring, both of which are safe to do while session_state_changing is true.
393                 */
394         }
395
396         _diskstream->check_record_status (start_frame, can_record);
397
398         bool be_silent;
399
400         if (_have_internal_generator) {
401                 /* since the instrument has no input streams,
402                    there is no reason to send any signal
403                    into the route.
404                 */
405                 be_silent = true;
406         } else {
407                 MonitorState const s = monitoring_state ();
408                 /* we are not rolling, so be silent even if we are monitoring disk, as there
409                    will be no disk data coming in.
410                 */
411                 be_silent = (s == MonitoringSilence || s == MonitoringDisk);
412         }
413         
414         if (!_have_internal_generator && metering_state() == MeteringInput) {
415                 _input->process_input (_meter, start_frame, end_frame, nframes);
416         }
417
418         _amp->apply_gain_automation(false);
419
420         /* if have_internal_generator, or .. */
421         //_input->process_input (_meter, start_frame, end_frame, nframes);
422
423         if (be_silent) {
424
425                 passthru_silence (start_frame, end_frame, nframes, 0);
426
427         } else {
428
429                 /* we're sending signal, but we may still want to meter the input.
430                  */
431
432                 passthru (start_frame, end_frame, nframes, false);
433         }
434
435         for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
436                 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
437                 if (d) {
438                         d->flush_buffers (nframes);
439                 }
440         }
441
442         return 0;
443 }
444
445 int
446 Track::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& need_butler)
447 {
448         Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
449         if (!lm.locked()) {
450                 return 0;
451         }
452
453         if (n_outputs().n_total() == 0 && _processors.empty()) {
454                 return 0;
455         }
456
457         if (!_active) {
458                 silence (nframes);
459                 return 0;
460         }
461
462         _silent = true;
463         _amp->apply_gain_automation(false);
464
465         silence (nframes);
466
467         framecnt_t playback_distance;
468         int const dret = _diskstream->process (_session.transport_frame(), nframes, playback_distance);
469         need_butler = _diskstream->commit (playback_distance);
470         return dret;
471 }
472
473 void
474 Track::set_diskstream (boost::shared_ptr<Diskstream> ds)
475 {
476         _diskstream = ds;
477
478         ds->PlaylistChanged.connect_same_thread (*this, boost::bind (&Track::diskstream_playlist_changed, this));
479         diskstream_playlist_changed ();
480         ds->RecordEnableChanged.connect_same_thread (*this, boost::bind (&Track::diskstream_record_enable_changed, this));
481         ds->SpeedChanged.connect_same_thread (*this, boost::bind (&Track::diskstream_speed_changed, this));
482         ds->AlignmentStyleChanged.connect_same_thread (*this, boost::bind (&Track::diskstream_alignment_style_changed, this));
483 }
484
485 void
486 Track::diskstream_playlist_changed ()
487 {
488         PlaylistChanged (); /* EMIT SIGNAL */
489 }
490
491 void
492 Track::diskstream_record_enable_changed ()
493 {
494         RecordEnableChanged (); /* EMIT SIGNAL */
495 }
496
497 void
498 Track::diskstream_speed_changed ()
499 {
500         SpeedChanged (); /* EMIT SIGNAL */
501 }
502
503 void
504 Track::diskstream_alignment_style_changed ()
505 {
506         AlignmentStyleChanged (); /* EMIT SIGNAL */
507 }
508
509 boost::shared_ptr<Playlist>
510 Track::playlist ()
511 {
512         return _diskstream->playlist ();
513 }
514
515 void
516 Track::request_jack_monitors_input (bool m)
517 {
518         _diskstream->request_jack_monitors_input (m);
519 }
520
521 void
522 Track::ensure_jack_monitors_input (bool m)
523 {
524         _diskstream->ensure_jack_monitors_input (m);
525 }
526
527 bool
528 Track::destructive () const
529 {
530         return _diskstream->destructive ();
531 }
532
533 list<boost::shared_ptr<Source> > &
534 Track::last_capture_sources ()
535 {
536         return _diskstream->last_capture_sources ();
537 }
538
539 void
540 Track::set_capture_offset ()
541 {
542         _diskstream->set_capture_offset ();
543 }
544
545 list<boost::shared_ptr<Source> >
546 Track::steal_write_sources()
547 {
548         return _diskstream->steal_write_sources ();
549 }
550
551 void
552 Track::reset_write_sources (bool r, bool force)
553 {
554         _diskstream->reset_write_sources (r, force);
555 }
556
557 float
558 Track::playback_buffer_load () const
559 {
560         return _diskstream->playback_buffer_load ();
561 }
562
563 float
564 Track::capture_buffer_load () const
565 {
566         return _diskstream->capture_buffer_load ();
567 }
568
569 int
570 Track::do_refill ()
571 {
572         return _diskstream->do_refill ();
573 }
574
575 int
576 Track::do_flush (RunContext c, bool force)
577 {
578         return _diskstream->do_flush (c, force);
579 }
580
581 void
582 Track::set_pending_overwrite (bool o)
583 {
584         _diskstream->set_pending_overwrite (o);
585 }
586
587 int
588 Track::seek (framepos_t p, bool complete_refill)
589 {
590         return _diskstream->seek (p, complete_refill);
591 }
592
593 bool
594 Track::hidden () const
595 {
596         return _diskstream->hidden ();
597 }
598
599 int
600 Track::can_internal_playback_seek (framecnt_t p)
601 {
602         return _diskstream->can_internal_playback_seek (p);
603 }
604
605 int
606 Track::internal_playback_seek (framecnt_t p)
607 {
608         return _diskstream->internal_playback_seek (p);
609 }
610
611 void
612 Track::non_realtime_input_change ()
613 {
614         _diskstream->non_realtime_input_change ();
615 }
616
617 void
618 Track::non_realtime_locate (framepos_t p)
619 {
620         _diskstream->non_realtime_locate (p);
621 }
622
623 void
624 Track::non_realtime_set_speed ()
625 {
626         _diskstream->non_realtime_set_speed ();
627 }
628
629 int
630 Track::overwrite_existing_buffers ()
631 {
632         return _diskstream->overwrite_existing_buffers ();
633 }
634
635 framecnt_t
636 Track::get_captured_frames (uint32_t n) const
637 {
638         return _diskstream->get_captured_frames (n);
639 }
640
641 int
642 Track::set_loop (Location* l)
643 {
644         return _diskstream->set_loop (l);
645 }
646
647 void
648 Track::transport_looped (framepos_t p)
649 {
650         _diskstream->transport_looped (p);
651 }
652
653 bool
654 Track::realtime_set_speed (double s, bool g)
655 {
656         return _diskstream->realtime_set_speed (s, g);
657 }
658
659 void
660 Track::transport_stopped_wallclock (struct tm & n, time_t t, bool g)
661 {
662         _diskstream->transport_stopped_wallclock (n, t, g);
663 }
664
665 bool
666 Track::pending_overwrite () const
667 {
668         return _diskstream->pending_overwrite ();
669 }
670
671 double
672 Track::speed () const
673 {
674         return _diskstream->speed ();
675 }
676
677 void
678 Track::prepare_to_stop (framepos_t p)
679 {
680         _diskstream->prepare_to_stop (p);
681 }
682
683 void
684 Track::set_slaved (bool s)
685 {
686         _diskstream->set_slaved (s);
687 }
688
689 ChanCount
690 Track::n_channels ()
691 {
692         return _diskstream->n_channels ();
693 }
694
695 framepos_t
696 Track::get_capture_start_frame (uint32_t n) const
697 {
698         return _diskstream->get_capture_start_frame (n);
699 }
700
701 AlignStyle
702 Track::alignment_style () const
703 {
704         return _diskstream->alignment_style ();
705 }
706
707 AlignChoice
708 Track::alignment_choice () const
709 {
710         return _diskstream->alignment_choice ();
711 }
712
713 framepos_t
714 Track::current_capture_start () const
715 {
716         return _diskstream->current_capture_start ();
717 }
718
719 framepos_t
720 Track::current_capture_end () const
721 {
722         return _diskstream->current_capture_end ();
723 }
724
725 void
726 Track::playlist_modified ()
727 {
728         _diskstream->playlist_modified ();
729 }
730
731 int
732 Track::use_playlist (boost::shared_ptr<Playlist> p)
733 {
734         int ret = _diskstream->use_playlist (p);
735         if (ret == 0) {
736                 p->set_orig_track_id (id());
737         }
738         return ret;
739 }
740
741 int
742 Track::use_copy_playlist ()
743 {
744         int ret =  _diskstream->use_copy_playlist ();
745
746         if (ret == 0) {
747                 _diskstream->playlist()->set_orig_track_id (id());
748         }
749
750         return ret;
751 }
752
753 int
754 Track::use_new_playlist ()
755 {
756         int ret = _diskstream->use_new_playlist ();
757
758         if (ret == 0) {
759                 _diskstream->playlist()->set_orig_track_id (id());
760         }
761
762         return ret;
763 }
764
765 void
766 Track::set_align_style (AlignStyle s, bool force)
767 {
768         _diskstream->set_align_style (s, force);
769 }
770
771 void
772 Track::set_align_choice (AlignChoice s, bool force)
773 {
774         _diskstream->set_align_choice (s, force);
775 }
776
777 bool
778 Track::using_diskstream_id (PBD::ID id) const
779 {
780         return (id == _diskstream->id ());
781 }
782
783 void
784 Track::set_block_size (pframes_t n)
785 {
786         Route::set_block_size (n);
787         _diskstream->set_block_size (n);
788 }
789
790 void
791 Track::adjust_playback_buffering ()
792 {
793         if (_diskstream) {
794                 _diskstream->adjust_playback_buffering ();
795         }
796 }
797
798 void
799 Track::adjust_capture_buffering ()
800 {
801         if (_diskstream) {
802                 _diskstream->adjust_capture_buffering ();
803         }
804 }
805
806 MonitorState
807 Track::monitoring_state () const
808 {
809         /* Explicit requests */
810         
811         if (_monitoring & MonitorInput) {
812                 return MonitoringInput;
813         }
814                 
815         if (_monitoring & MonitorDisk) {
816                 return MonitoringDisk;
817         }
818
819         /* This is an implementation of the truth table in doc/monitor_modes.pdf;
820            I don't think it's ever going to be too pretty too look at.
821         */
822
823         bool const roll = _session.transport_rolling ();
824         bool const track_rec = _diskstream->record_enabled ();
825         bool const session_rec = _session.get_record_enabled ();
826         bool const auto_input = _session.config.get_auto_input ();
827         bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
828         bool const tape_machine_mode = Config->get_tape_machine_mode ();
829
830         if (track_rec) {
831
832                 if (!session_rec && roll && auto_input) {
833                         return MonitoringDisk;
834                 } else {
835                         return software_monitor ? MonitoringInput : MonitoringSilence;
836                 }
837
838         } else {
839
840                 if (tape_machine_mode) {
841
842                         return MonitoringDisk;
843
844                 } else {
845
846                         if (!roll && auto_input) {
847                                 return software_monitor ? MonitoringInput : MonitoringSilence;
848                         } else {
849                                 return MonitoringDisk;
850                         }
851                         
852                 }
853         }
854
855         /* NOTREACHED */
856         return MonitoringSilence;
857 }
858
859 void
860 Track::maybe_declick (BufferSet& bufs, framecnt_t nframes, int declick)
861 {
862         /* never declick if there is an internal generator - we just want it to
863            keep generating sound without interruption.
864
865            ditto if we are monitoring inputs.
866         */
867
868         if (_have_internal_generator || monitoring_choice() == MonitorInput) {
869                 return;
870         }
871
872         if (!declick) {
873                 declick = _pending_declick;
874         }
875
876         if (declick != 0) {
877                 Amp::declick (bufs, nframes, declick);
878         }
879 }
880
881 framecnt_t
882 Track::check_initial_delay (framecnt_t nframes, framepos_t& transport_frame)
883 {
884         if (_roll_delay > nframes) {
885
886                 _roll_delay -= nframes;
887                 silence_unlocked (nframes);
888                 /* transport frame is not legal for caller to use */
889                 return 0;
890
891         } else if (_roll_delay > 0) {
892
893                 nframes -= _roll_delay;
894                 silence_unlocked (_roll_delay);
895                 transport_frame += _roll_delay;
896
897                 /* shuffle all the port buffers for things that lead "out" of this Route
898                    to reflect that we just wrote _roll_delay frames of silence.
899                 */
900
901                 Glib::RWLock::ReaderLock lm (_processor_lock);
902                 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
903                         boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
904                         if (iop) {
905                                 iop->increment_port_buffer_offset (_roll_delay);
906                         }
907                 }
908                 _output->increment_port_buffer_offset (_roll_delay);
909
910                 _roll_delay = 0;
911
912         }
913
914         return nframes; 
915 }
916
917 void
918 Track::set_monitoring (MonitorChoice mc)
919 {
920         if (mc !=  _monitoring) {
921                 _monitoring = mc;
922
923                 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
924                         (*i)->monitoring_changed ();
925                 }
926
927                 MonitoringChanged (); /* EMIT SIGNAL */
928         }
929 }
930
931 void
932 Track::parameter_changed (string p)
933 {
934         if (p != "do-not-record-plugins") {
935                 return;
936         }
937
938         if (record_enabled ()) {
939                 if (Config->get_do_not_record_plugins ()) {
940                         deactivate_visible_processors ();
941                 } else {
942                         activate_deactivated_processors ();
943                 }
944         }
945 }
946         
947 MeterState
948 Track::metering_state () const
949 {
950         return _diskstream->record_enabled() ? MeteringInput : MeteringRoute;
951 }