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