2 Copyright (C) 2006 Paul Davis
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.
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.
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.
18 #include "pbd/error.h"
20 #include "ardour/amp.h"
21 #include "ardour/audioengine.h"
22 #include "ardour/debug.h"
23 #include "ardour/delivery.h"
24 #include "ardour/disk_reader.h"
25 #include "ardour/disk_writer.h"
26 #include "ardour/event_type_map.h"
27 #include "ardour/io_processor.h"
28 #include "ardour/meter.h"
29 #include "ardour/monitor_control.h"
30 #include "ardour/playlist.h"
31 #include "ardour/playlist_factory.h"
32 #include "ardour/port.h"
33 #include "ardour/processor.h"
34 #include "ardour/profile.h"
35 #include "ardour/record_enable_control.h"
36 #include "ardour/record_safe_control.h"
37 #include "ardour/route_group_specialized.h"
38 #include "ardour/session.h"
39 #include "ardour/session_playlists.h"
40 #include "ardour/track.h"
41 #include "ardour/types_convert.h"
42 #include "ardour/utils.h"
47 using namespace ARDOUR;
50 Track::Track (Session& sess, string name, PresentationInfo::Flag flag, TrackMode mode, DataType default_type)
51 : Route (sess, name, flag, default_type)
52 , _saved_meter_point (_meter_point)
54 , _alignment_choice (Automatic)
56 _freeze_record.state = NoFreeze;
62 DEBUG_TRACE (DEBUG::Destruction, string_compose ("track %1 destructor\n", _name));
72 DiskIOProcessor::Flag dflags = DiskIOProcessor::Recordable;
74 if (_mode == Destructive && !Profile->get_trx()) {
75 dflags = DiskIOProcessor::Flag (dflags | DiskIOProcessor::Destructive);
76 } else if (_mode == NonLayered){
77 dflags = DiskIOProcessor::Flag(dflags | DiskIOProcessor::NonLayered);
80 _disk_reader.reset (new DiskReader (_session, name(), dflags));
81 _disk_reader->set_block_size (_session.get_block_size ());
82 _disk_reader->set_route (boost::dynamic_pointer_cast<Route> (shared_from_this()));
84 _disk_writer.reset (new DiskWriter (_session, name(), dflags));
85 _disk_writer->set_block_size (_session.get_block_size ());
86 _disk_writer->set_route (boost::dynamic_pointer_cast<Route> (shared_from_this()));
90 /* ordering here is important, and needs to be generally maintained */
92 add_processor (_disk_writer, PreFader);
93 add_processor (_disk_reader, PreFader);
95 boost::shared_ptr<Route> rp (boost::dynamic_pointer_cast<Route> (shared_from_this()));
96 boost::shared_ptr<Track> rt = boost::dynamic_pointer_cast<Track> (rp);
98 _record_enable_control.reset (new RecordEnableControl (_session, EventTypeMap::instance().to_symbol (RecEnableAutomation), *this));
99 add_control (_record_enable_control);
101 _record_safe_control.reset (new RecordSafeControl (_session, EventTypeMap::instance().to_symbol (RecSafeAutomation), *this));
102 add_control (_record_safe_control);
104 _monitoring_control.reset (new MonitorControl (_session, EventTypeMap::instance().to_symbol (MonitoringAutomation), *this));
105 add_control (_monitoring_control);
107 _session.config.ParameterChanged.connect_same_thread (*this, boost::bind (&Track::parameter_changed, this, _1));
109 _monitoring_control->Changed.connect_same_thread (*this, boost::bind (&Track::monitoring_changed, this, _1, _2));
110 _record_safe_control->Changed.connect_same_thread (*this, boost::bind (&Track::record_safe_changed, this, _1, _2));
111 _record_enable_control->Changed.connect_same_thread (*this, boost::bind (&Track::record_enable_changed, this, _1, _2));
113 _input->changed.connect_same_thread (*this, boost::bind (&Track::input_changed, this));
119 Track::input_changed ()
121 if (_disk_writer && _alignment_choice == Automatic) {
122 set_align_choice_from_io ();
133 Track::state (bool full)
135 XMLNode& root (Route::state (full));
137 if (_playlists[DataType::AUDIO]) {
138 root.set_property (X_("audio-playlist"), _playlists[DataType::AUDIO]->id().to_s());
141 if (_playlists[DataType::MIDI]) {
142 root.set_property (X_("midi-playlist"), _playlists[DataType::MIDI]->id().to_s());
145 root.add_child_nocopy (_monitoring_control->get_state ());
146 root.add_child_nocopy (_record_safe_control->get_state ());
147 root.add_child_nocopy (_record_enable_control->get_state ());
149 root.set_property (X_("saved-meter-point"), _saved_meter_point);
150 root.set_property (X_("alignment-choice"), _alignment_choice);
156 Track::set_state (const XMLNode& node, int version)
158 if (Route::set_state (node, version)) {
164 if (version >= 3000 && version < 4000) {
165 if ((child = find_named_node (node, X_("Diskstream"))) != 0) {
166 /* XXX if we remember anything from stored DiskStream
167 state (older Ardour versions) that is needed by a
168 DiskReader or DiskWriter, we should cook up a new
169 XMLNode here, populate it with that information
170 (child nodes, properties, etc.) and then call
171 ::set_state() on the writer/reader.
173 But at present (June 2017), there's no such state.
178 std::string playlist_id;
180 if (node.get_property (X_("audio-playlist"), playlist_id)) {
181 find_and_use_playlist (DataType::AUDIO, PBD::ID (playlist_id));
184 if (node.get_property (X_("midi-playlist"), playlist_id)) {
185 find_and_use_playlist (DataType::MIDI, PBD::ID (playlist_id));
188 XMLNodeList nlist = node.children();
189 for (XMLNodeConstIterator niter = nlist.begin(); niter != nlist.end(); ++niter) {
192 if (child->name() == Controllable::xml_node_name) {
194 if (!child->get_property ("name", name)) {
198 if (name == _record_enable_control->name()) {
199 _record_enable_control->set_state (*child, version);
200 } else if (name == _record_safe_control->name()) {
201 _record_safe_control->set_state (*child, version);
202 } else if (name == _monitoring_control->name()) {
203 _monitoring_control->set_state (*child, version);
208 if (!node.get_property (X_("saved-meter-point"), _saved_meter_point)) {
209 _saved_meter_point = _meter_point;
214 if (node.get_property (X_("alignment-choice"), ac)) {
215 set_align_choice (ac, true);
222 Track::get_template ()
224 return state (false);
227 Track::FreezeRecord::~FreezeRecord ()
229 for (vector<FreezeRecordProcessorInfo*>::iterator i = processor_info.begin(); i != processor_info.end(); ++i) {
235 Track::freeze_state() const
237 return _freeze_record.state;
243 bool will_record = true;
244 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end() && will_record; ++i) {
253 Track::prep_record_enabled (bool yn)
255 if (yn && _record_safe_control->get_value()) {
259 if (!can_be_record_enabled()) {
263 /* keep track of the meter point as it was before we rec-enabled */
264 if (!_disk_writer->record_enabled()) {
265 _saved_meter_point = _meter_point;
271 will_follow = _disk_writer->prep_record_enable ();
273 will_follow = _disk_writer->prep_record_disable ();
278 if (_meter_point != MeterCustom) {
279 set_meter_point (MeterInput);
282 set_meter_point (_saved_meter_point);
290 Track::record_enable_changed (bool, Controllable::GroupControlDisposition)
292 _disk_writer->set_record_enabled (_record_enable_control->get_value());
296 Track::record_safe_changed (bool, Controllable::GroupControlDisposition)
298 _disk_writer->set_record_safe (_record_safe_control->get_value());
302 Track::can_be_record_safe ()
304 return !_record_enable_control->get_value() && _disk_writer && _session.writable() && (_freeze_record.state != Frozen);
308 Track::can_be_record_enabled ()
310 return !_record_safe_control->get_value() && _disk_writer && !_disk_writer->record_safe() && _session.writable() && (_freeze_record.state != Frozen);
314 Track::parameter_changed (string const & p)
316 if (p == "track-name-number") {
317 resync_track_name ();
319 else if (p == "track-name-take") {
320 resync_track_name ();
322 else if (p == "take-name") {
323 if (_session.config.get_track_name_take()) {
324 resync_track_name ();
330 Track::resync_track_name ()
336 Track::set_name (const string& str)
344 if (_record_enable_control->get_value()) {
345 /* when re-arm'ed the file (named after the track) is already ready to rolll */
349 string diskstream_name = "";
350 if (_session.config.get_track_name_take () && !_session.config.get_take_name ().empty()) {
351 // Note: any text is fine, legalize_for_path() fixes this later
352 diskstream_name += _session.config.get_take_name ();
353 diskstream_name += "_";
355 const int64_t tracknumber = track_number();
356 if (tracknumber > 0 && _session.config.get_track_name_number()) {
357 char num[64], fmt[10];
358 snprintf(fmt, sizeof(fmt), "%%0%d" PRId64, _session.track_number_decimals());
359 snprintf(num, sizeof(num), fmt, tracknumber);
360 diskstream_name += num;
361 diskstream_name += "_";
363 diskstream_name += str;
365 if (diskstream_name == _diskstream_name) {
368 _diskstream_name = diskstream_name;
370 _disk_writer->set_write_source_name (diskstream_name);
372 boost::shared_ptr<Track> me = boost::dynamic_pointer_cast<Track> (shared_from_this ());
374 if (_playlists[data_type()]->all_regions_empty () && _session.playlists->playlists_for_track (me).size() == 1) {
375 /* Only rename the diskstream (and therefore the playlist) if
376 a) the playlist has never had a region added to it and
377 b) there is only one playlist for this track.
379 If (a) is not followed, people can get confused if, say,
380 they have notes about a playlist with a given name and then
381 it changes (see mantis #4759).
383 If (b) is not followed, we rename the current playlist and not
384 the other ones, which is a bit confusing (see mantis #4977).
386 _disk_reader->set_name (str);
387 _disk_writer->set_name (str);
390 for (uint32_t n = 0; n < DataType::num_types; ++n) {
392 _playlists[n]->set_name (str);
396 /* save state so that the statefile fully reflects any filename changes */
398 if ((ret = Route::set_name (str)) == 0) {
399 _session.save_state ("");
406 Track::set_latency_compensation (framecnt_t longest_session_latency)
408 Route::set_latency_compensation (longest_session_latency);
409 _disk_reader->set_roll_delay (_roll_delay);
413 Track::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
415 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
421 bool can_record = _session.actively_recording ();
423 /* no outputs? nothing to do ... what happens if we have sends etc. ? */
425 if (n_outputs().n_total() == 0 && !ARDOUR::Profile->get_mixbus()) {
426 //Note: Mixbus has its own output mechanism, so we should operate even if no explicit outputs are assigned
430 /* not active ... do the minimum possible by just outputting silence */
434 if (_meter_point == MeterInput && ((_monitoring_control->monitoring_choice() & MonitorInput) || _disk_writer->record_enabled())) {
440 if (session_state_changing) {
441 if (_session.transport_speed() != 0.0f) {
442 /* we're rolling but some state is changing (e.g. our
443 disk reader contents) so we cannot use them. Be
444 silent till this is over. Don't declick.
446 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
448 passthru_silence (start_frame, end_frame, nframes, 0);
451 /* we're really not rolling, so we're either delivery silence or actually
452 monitoring, both of which are safe to do while session_state_changing is true.
456 _disk_writer->check_record_status (start_frame, can_record);
460 MonitorState const s = monitoring_state ();
461 /* we are not rolling, so be silent even if we are monitoring disk, as there
462 will be no disk data coming in.
465 case MonitoringSilence:
471 case MonitoringInput:
479 //if we have an internal generator, let it play regardless of monitoring state
480 if (_have_internal_generator) {
484 _amp->apply_gain_automation (false);
486 /* if have_internal_generator, or .. */
490 if (_meter_point == MeterInput) {
491 /* still need input monitoring and metering */
493 bool const track_rec = _disk_writer->record_enabled ();
494 bool const auto_input = _session.config.get_auto_input ();
495 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
496 bool const tape_machine_mode = Config->get_tape_machine_mode ();
497 bool no_meter = false;
499 /* this needs a proper K-map
500 * and should be separated into a function similar to monitoring_state()
501 * that also handles roll() states in audio_track.cc, midi_track.cc and route.cc
503 * see http://www.oofus.co.uk/ardour/Ardour3MonitorModesV3.pdf
505 if (!auto_input && !track_rec) {
508 else if (tape_machine_mode && !track_rec && auto_input) {
511 else if (!software_monitor && tape_machine_mode && !track_rec) {
514 else if (!software_monitor && !tape_machine_mode && !track_rec && !auto_input) {
519 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
520 _meter->run (bufs, start_frame, end_frame, 1.0, nframes, true);
521 _input->process_input (boost::shared_ptr<Processor>(), start_frame, end_frame, _session.transport_speed(), nframes);
523 _input->process_input (_meter, start_frame, end_frame, _session.transport_speed(), nframes);
527 passthru_silence (start_frame, end_frame, nframes, 0);
531 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
533 fill_buffers_with_input (bufs, _input, nframes);
535 if (_meter_point == MeterInput) {
536 _meter->run (bufs, start_frame, end_frame, _session.transport_speed(), nframes, true);
539 passthru (bufs, start_frame, end_frame, nframes, false);
542 flush_processor_buffers_locked (nframes);
548 Track::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& need_butler)
550 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
552 // XXX DISK reader needs to seek ahead the correct distance ?? OR DOES IT ?
553 //framecnt_t playback_distance = _disk_reader->calculate_playback_distance(nframes);
554 //if (can_internal_playback_seek(playback_distance)) {
555 // internal_playback_seek(playback_distance);
560 if (n_outputs().n_total() == 0 && _processors.empty()) {
570 _amp->apply_gain_automation(false);
573 flush_processor_buffers_locked (nframes);
575 //BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
576 // XXXX DISKWRITER/READER ADVANCE, SET need_butler
580 boost::shared_ptr<Playlist>
583 return _playlists[data_type()];
587 Track::request_input_monitoring (bool m)
589 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
590 AudioEngine::instance()->request_input_monitoring ((*i)->name(), m);
595 Track::ensure_input_monitoring (bool m)
597 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
598 AudioEngine::instance()->ensure_input_monitoring ((*i)->name(), m);
603 Track::destructive () const
605 return _disk_writer->destructive ();
608 list<boost::shared_ptr<Source> > &
609 Track::last_capture_sources ()
611 return _disk_writer->last_capture_sources ();
615 Track::set_capture_offset ()
617 _disk_writer->set_capture_offset ();
621 Track::steal_write_source_name()
623 return _disk_writer->steal_write_source_name ();
627 Track::reset_write_sources (bool r, bool force)
629 _disk_writer->reset_write_sources (r, force);
633 Track::playback_buffer_load () const
635 return _disk_reader->buffer_load ();
639 Track::capture_buffer_load () const
641 return _disk_writer->buffer_load ();
647 return _disk_reader->do_refill ();
651 Track::do_flush (RunContext c, bool force)
653 return _disk_writer->do_flush (c, force);
657 Track::set_pending_overwrite (bool o)
659 _disk_reader->set_pending_overwrite (o);
663 Track::seek (framepos_t p, bool complete_refill)
665 if (_disk_reader->seek (p, complete_refill)) {
668 return _disk_writer->seek (p, complete_refill);
672 Track::hidden () const
674 return _disk_writer->hidden () || _disk_reader->hidden();
678 Track::can_internal_playback_seek (framecnt_t p)
680 return _disk_reader->can_internal_playback_seek (p);
684 Track::internal_playback_seek (framecnt_t p)
686 return _disk_reader->internal_playback_seek (p);
690 Track::non_realtime_locate (framepos_t p)
692 Route::non_realtime_locate (p);
695 /* don't waste i/o cycles and butler calls
696 for hidden (secret) tracks
698 _disk_reader->non_realtime_locate (p);
699 _disk_writer->non_realtime_locate (p);
704 Track::non_realtime_speed_change ()
706 _disk_reader->non_realtime_speed_change ();
710 Track::overwrite_existing_buffers ()
712 return _disk_reader->overwrite_existing_buffers ();
716 Track::get_captured_frames (uint32_t n) const
718 return _disk_writer->get_captured_frames (n);
722 Track::set_loop (Location* l)
724 if (_disk_reader->set_loop (l)) {
727 return _disk_writer->set_loop (l);
731 Track::transport_looped (framepos_t p)
733 return _disk_writer->transport_looped (p);
737 Track::realtime_speed_change ()
739 if (_disk_reader->realtime_speed_change ()) {
742 return _disk_writer->realtime_speed_change ();
746 Track::realtime_handle_transport_stopped ()
748 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
754 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
755 (*i)->realtime_handle_transport_stopped ();
760 Track::transport_stopped_wallclock (struct tm & n, time_t t, bool g)
762 _disk_writer->transport_stopped_wallclock (n, t, g);
766 Track::pending_overwrite () const
768 return _disk_reader->pending_overwrite ();
772 Track::prepare_to_stop (framepos_t t, framepos_t a)
774 _disk_writer->prepare_to_stop (t, a);
778 Track::set_slaved (bool s)
780 _disk_reader->set_slaved (s);
781 _disk_writer->set_slaved (s);
787 return _disk_reader->output_streams();
791 Track::get_capture_start_frame (uint32_t n) const
793 return _disk_writer->get_capture_start_frame (n);
797 Track::alignment_style () const
799 return _disk_writer->alignment_style ();
803 Track::alignment_choice () const
805 return _disk_writer->alignment_choice ();
809 Track::current_capture_start () const
811 return _disk_writer->current_capture_start ();
815 Track::current_capture_end () const
817 return _disk_writer->current_capture_end ();
821 Track::playlist_modified ()
823 _disk_reader->playlist_modified ();
827 Track::find_and_use_playlist (DataType dt, PBD::ID const & id)
829 boost::shared_ptr<Playlist> playlist;
831 if ((playlist = _session.playlists->by_id (id)) == 0) {
836 error << string_compose(_("DiskIOProcessor: \"%1\" isn't an playlist"), id.to_s()) << endmsg;
840 return use_playlist (dt, playlist);
844 Track::use_playlist (DataType dt, boost::shared_ptr<Playlist> p)
848 if ((ret = _disk_reader->use_playlist (dt, p)) == 0) {
849 if ((ret = _disk_writer->use_playlist (dt, p)) == 0) {
850 p->set_orig_track_id (id());
862 Track::use_copy_playlist ()
864 assert (_playlists[data_type()]);
866 if (_playlists[data_type()] == 0) {
867 error << string_compose(_("DiskIOProcessor %1: there is no existing playlist to make a copy of!"), _name) << endmsg;
872 boost::shared_ptr<Playlist> playlist;
874 newname = Playlist::bump_name (_playlists[data_type()]->name(), _session);
876 if ((playlist = PlaylistFactory::create (_playlists[data_type()], newname)) == 0) {
880 playlist->reset_shares();
882 return use_playlist (data_type(), playlist);
886 Track::use_new_playlist ()
889 boost::shared_ptr<Playlist> playlist = _playlists[data_type()];
892 newname = Playlist::bump_name (playlist->name(), _session);
894 newname = Playlist::bump_name (_name, _session);
897 playlist = PlaylistFactory::create (data_type(), _session, newname, hidden());
903 return use_playlist (data_type(), playlist);
907 Track::set_align_choice (AlignChoice ac, bool force)
911 _alignment_choice = Automatic;
912 set_align_choice_from_io ();
918 _disk_writer->set_align_choice (ac, force);
919 _alignment_choice = ac;
923 Track::set_align_style (AlignStyle s, bool force)
925 _disk_writer->set_align_style (s, force);
929 Track::set_align_choice_from_io ()
931 bool have_physical = false;
935 vector<string> connections;
936 boost::shared_ptr<Port> p;
940 p = _input->nth (n++);
946 if (p->get_connections (connections) != 0) {
947 if (AudioEngine::instance()->port_is_physical (connections[0])) {
948 have_physical = true;
953 connections.clear ();
958 // compensate for latency when bouncing from master or mixbus.
959 // we need to use "ExistingMaterial" to pick up the master bus' latency
960 // see also Route::direct_feeds_according_to_reality
962 ios.push_back (_input);
963 if (_session.master_out() && ios.fed_by (_session.master_out()->output())) {
964 have_physical = true;
966 for (uint32_t n = 0; n < NUM_MIXBUSES && !have_physical; ++n) {
967 if (_session.get_mixbus (n) && ios.fed_by (_session.get_mixbus(n)->output())) {
968 have_physical = true;
974 _disk_writer->set_align_style (ExistingMaterial);
976 _disk_writer->set_align_style (CaptureTime);
981 Track::set_block_size (pframes_t n)
983 Route::set_block_size (n);
984 _disk_reader->set_block_size (n);
985 _disk_writer->set_block_size (n);
989 Track::adjust_playback_buffering ()
992 _disk_reader->adjust_buffering ();
997 Track::adjust_capture_buffering ()
1000 _disk_writer->adjust_buffering ();
1004 #ifdef USE_TRACKS_CODE_FEATURES
1006 /* This is the Tracks version of Track::monitoring_state().
1008 * Ardour developers: try to flag or fix issues if parts of the libardour API
1009 * change in ways that invalidate this
1013 Track::monitoring_state () const
1015 /* Explicit requests */
1017 if (_monitoring != MonitorInput) {
1018 return MonitoringInput;
1021 if (_monitoring & MonitorDisk) {
1022 return MonitoringDisk;
1025 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
1026 I don't think it's ever going to be too pretty too look at.
1029 // GZ: NOT USED IN TRACKS
1030 //bool const auto_input = _session.config.get_auto_input ();
1031 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
1032 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
1034 bool const roll = _session.transport_rolling ();
1035 bool const track_rec = _diskstream->record_enabled ();
1036 bool session_rec = _session.actively_recording ();
1040 if (!session_rec && roll) {
1041 return MonitoringDisk;
1043 return MonitoringInput;
1049 return MonitoringDisk;
1053 return MonitoringSilence;
1058 /* This is the Ardour/Mixbus version of Track::monitoring_state().
1060 * Tracks developers: do NOT modify this method under any circumstances.
1064 Track::monitoring_state () const
1066 /* Explicit requests */
1067 MonitorChoice m (_monitoring_control->monitoring_choice());
1069 if (m != MonitorAuto) {
1071 MonitorState ms ((MonitorState) 0);
1073 if (m & MonitorInput) {
1074 ms = MonitoringInput;
1077 if (m & MonitorDisk) {
1078 ms = MonitorState (ms | MonitoringDisk);
1084 switch (_session.config.get_session_monitoring ()) {
1086 return MonitoringDisk;
1089 return MonitoringInput;
1095 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
1096 I don't think it's ever going to be too pretty too look at.
1099 bool const roll = _session.transport_rolling ();
1100 bool const track_rec = _disk_writer->record_enabled ();
1101 bool const auto_input = _session.config.get_auto_input ();
1102 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
1103 bool const tape_machine_mode = Config->get_tape_machine_mode ();
1106 /* I suspect that just use actively_recording() is good enough all the
1107 * time, but just to keep the semantics the same as they were before
1108 * sept 26th 2012, we differentiate between the cases where punch is
1109 * enabled and those where it is not.
1111 * rg: I suspect this is not the case: monitoring may differ
1114 if (_session.config.get_punch_in() || _session.config.get_punch_out() || _session.preroll_record_punch_enabled ()) {
1115 session_rec = _session.actively_recording ();
1117 session_rec = _session.get_record_enabled();
1122 if (!session_rec && roll && auto_input) {
1123 return MonitoringDisk;
1125 return software_monitor ? MonitoringInput : MonitoringSilence;
1130 if (tape_machine_mode) {
1132 return MonitoringDisk;
1136 if (!roll && auto_input) {
1137 return software_monitor ? MonitoringInput : MonitoringSilence;
1139 return MonitoringDisk;
1145 abort(); /* NOTREACHED */
1146 return MonitoringSilence;
1152 Track::maybe_declick (BufferSet& bufs, framecnt_t nframes, int declick)
1154 /* never declick if there is an internal generator - we just want it to
1155 keep generating sound without interruption.
1157 ditto if we are monitoring inputs.
1160 if (_have_internal_generator || (_monitoring_control->monitoring_choice() == MonitorInput)) {
1165 declick = _pending_declick;
1169 Amp::declick (bufs, nframes, declick);
1174 Track::check_initial_delay (framecnt_t nframes, framepos_t& transport_frame)
1176 if (_roll_delay > nframes) {
1178 _roll_delay -= nframes;
1179 silence_unlocked (nframes);
1180 /* transport frame is not legal for caller to use */
1183 } else if (_roll_delay > 0) {
1185 nframes -= _roll_delay;
1186 silence_unlocked (_roll_delay);
1187 transport_frame += _roll_delay;
1189 /* shuffle all the port buffers for things that lead "out" of this Route
1190 to reflect that we just wrote _roll_delay frames of silence.
1193 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1194 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1195 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1197 iop->increment_port_buffer_offset (_roll_delay);
1200 _output->increment_port_buffer_offset (_roll_delay);
1210 Track::monitoring_changed (bool, Controllable::GroupControlDisposition)
1212 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1213 (*i)->monitoring_changed ();
1218 Track::metering_state () const
1221 if (_session.transport_rolling ()) {
1222 // audio_track.cc || midi_track.cc roll() runs meter IFF:
1223 rv = _meter_point == MeterInput && ((_monitoring_control->monitoring_choice() & MonitorInput) || _disk_writer->record_enabled());
1225 // track no_roll() always metering if
1226 rv = _meter_point == MeterInput;
1228 return rv ? MeteringInput : MeteringRoute;
1232 Track::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
1234 if (Route::set_processor_state (node, prop, new_order, must_configure)) {
1238 if (prop->value() == "diskreader") {
1240 _disk_reader->set_state (node, Stateful::current_state_version);
1241 new_order.push_back (_disk_reader);
1244 } else if (prop->value() == "diskwriter") {
1246 _disk_writer->set_state (node, Stateful::current_state_version);
1247 new_order.push_back (_disk_writer);
1252 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;