Move panner bypass state up to the PannerShell so that it is preserved even when...
[ardour2.git] / libs / ardour / track.cc
bloba45f37f422a50fec17f59f9c1447def9d2ceb2a1
1 /*
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/audioplaylist.h"
22 #include "ardour/audioregion.h"
23 #include "ardour/audiosource.h"
24 #include "ardour/debug.h"
25 #include "ardour/delivery.h"
26 #include "ardour/diskstream.h"
27 #include "ardour/io_processor.h"
28 #include "ardour/meter.h"
29 #include "ardour/port.h"
30 #include "ardour/processor.h"
31 #include "ardour/route_group_specialized.h"
32 #include "ardour/session.h"
33 #include "ardour/track.h"
34 #include "ardour/utils.h"
36 #include "i18n.h"
38 using namespace std;
39 using namespace ARDOUR;
40 using namespace PBD;
42 Track::Track (Session& sess, string name, Route::Flag flag, TrackMode mode, DataType default_type)
43 : Route (sess, name, flag, default_type)
44 , _saved_meter_point (_meter_point)
45 , _mode (mode)
46 , _rec_enable_control (new RecEnableControllable(*this))
48 _freeze_record.state = NoFreeze;
49 _declickable = true;
52 Track::~Track ()
54 DEBUG_TRACE (DEBUG::Destruction, string_compose ("track %1 destructor\n", _name));
57 int
58 Track::init ()
60 if (Route::init ()) {
61 return -1;
64 return 0;
66 XMLNode&
67 Track::get_state ()
69 return state (true);
74 XMLNode&
75 Track::get_template ()
77 return state (false);
80 void
81 Track::toggle_monitor_input ()
83 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
84 i->ensure_monitor_input(!i->monitoring_input());
88 Track::FreezeRecord::~FreezeRecord ()
90 for (vector<FreezeRecordProcessorInfo*>::iterator i = processor_info.begin(); i != processor_info.end(); ++i) {
91 delete *i;
95 Track::FreezeState
96 Track::freeze_state() const
98 return _freeze_record.state;
101 Track::RecEnableControllable::RecEnableControllable (Track& s)
102 : Controllable (X_("recenable")), track (s)
106 void
107 Track::RecEnableControllable::set_value (double val)
109 bool bval = ((val >= 0.5) ? true: false);
110 track.set_record_enabled (bval, this);
113 double
114 Track::RecEnableControllable::get_value (void) const
116 if (track.record_enabled()) { return 1.0; }
117 return 0.0;
120 bool
121 Track::record_enabled () const
123 return _diskstream && _diskstream->record_enabled ();
126 bool
127 Track::can_record()
129 bool will_record = true;
130 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end() && will_record; ++i) {
131 if (!i->connected())
132 will_record = false;
135 return will_record;
138 void
139 Track::set_record_enabled (bool yn, void *src)
141 if (!_session.writable()) {
142 return;
145 if (_freeze_record.state == Frozen) {
146 return;
149 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_recenable()) {
150 _route_group->apply (&Track::set_record_enabled, yn, _route_group);
151 return;
154 /* keep track of the meter point as it was before we rec-enabled */
155 if (!_diskstream->record_enabled()) {
156 _saved_meter_point = _meter_point;
159 _diskstream->set_record_enabled (yn);
161 if (_diskstream->record_enabled()) {
162 if (_meter_point != MeterCustom) {
163 set_meter_point (MeterInput);
165 } else {
166 set_meter_point (_saved_meter_point);
169 _rec_enable_control->Changed ();
173 bool
174 Track::set_name (const string& str)
176 bool ret;
178 if (record_enabled() && _session.actively_recording()) {
179 /* this messes things up if done while recording */
180 return false;
183 _diskstream->set_name (str);
185 /* save state so that the statefile fully reflects any filename changes */
187 if ((ret = Route::set_name (str)) == 0) {
188 _session.save_state ("");
191 return ret;
194 void
195 Track::set_latency_compensation (framecnt_t longest_session_latency)
197 Route::set_latency_compensation (longest_session_latency);
198 _diskstream->set_roll_delay (_roll_delay);
201 void
202 Track::zero_diskstream_id_in_xml (XMLNode& node)
204 if (node.property ("diskstream-id")) {
205 node.add_property ("diskstream-id", "0");
210 Track::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame,
211 bool session_state_changing, bool can_record, bool /*rec_monitors_input*/)
213 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
214 if (!lm.locked()) {
215 return 0;
218 if (n_outputs().n_total() == 0) {
219 return 0;
222 if (!_active) {
223 silence (nframes);
224 return 0;
227 if (session_state_changing) {
228 if (_session.transport_speed() != 0.0f) {
229 /* we're rolling but some state is changing (e.g. our diskstream contents)
230 so we cannot use them. Be silent till this is over. Don't declick.
232 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
234 passthru_silence (start_frame, end_frame, nframes, 0);
235 return 0;
237 /* we're really not rolling, so we're either delivery silence or actually
238 monitoring, both of which are safe to do while session_state_changing is true.
242 _diskstream->check_record_status (start_frame, can_record);
244 bool be_silent;
246 if (_have_internal_generator) {
247 /* since the instrument has no input streams,
248 there is no reason to send any signal
249 into the route.
251 be_silent = true;
252 } else {
253 be_silent = send_silence ();
256 _amp->apply_gain_automation(false);
258 if (be_silent) {
260 /* if we're sending silence, but we want the meters to show levels for the signal,
261 meter right here.
264 if (_have_internal_generator) {
265 passthru_silence (start_frame, end_frame, nframes, 0);
266 } else {
267 if (_meter_point == MeterInput) {
268 _input->process_input (_meter, start_frame, end_frame, nframes);
270 passthru_silence (start_frame, end_frame, nframes, 0);
273 } else {
275 /* we're sending signal, but we may still want to meter the input.
278 passthru (start_frame, end_frame, nframes, false);
281 _main_outs->flush_buffers (nframes, end_frame - start_frame - 1);
283 return 0;
287 Track::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/,
288 bool can_record, bool rec_monitors_input, bool& need_butler)
290 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
291 if (!lm.locked()) {
292 return 0;
295 if (n_outputs().n_total() == 0 && _processors.empty()) {
296 return 0;
299 if (!_active) {
300 silence (nframes);
301 return 0;
304 _silent = true;
305 _amp->apply_gain_automation(false);
307 silence (nframes);
309 return _diskstream->process (_session.transport_frame(), nframes, can_record, rec_monitors_input, need_butler);
312 void
313 Track::set_diskstream (boost::shared_ptr<Diskstream> ds)
315 _diskstream = ds;
317 ds->PlaylistChanged.connect_same_thread (*this, boost::bind (&Track::diskstream_playlist_changed, this));
318 diskstream_playlist_changed ();
319 ds->RecordEnableChanged.connect_same_thread (*this, boost::bind (&Track::diskstream_record_enable_changed, this));
320 ds->SpeedChanged.connect_same_thread (*this, boost::bind (&Track::diskstream_speed_changed, this));
321 ds->AlignmentStyleChanged.connect_same_thread (*this, boost::bind (&Track::diskstream_alignment_style_changed, this));
324 void
325 Track::diskstream_playlist_changed ()
327 PlaylistChanged (); /* EMIT SIGNAL */
330 void
331 Track::diskstream_record_enable_changed ()
333 RecordEnableChanged (); /* EMIT SIGNAL */
336 void
337 Track::diskstream_speed_changed ()
339 SpeedChanged (); /* EMIT SIGNAL */
342 void
343 Track::diskstream_alignment_style_changed ()
345 AlignmentStyleChanged (); /* EMIT SIGNAL */
348 boost::shared_ptr<Playlist>
349 Track::playlist ()
351 return _diskstream->playlist ();
354 void
355 Track::monitor_input (bool m)
357 _diskstream->monitor_input (m);
360 bool
361 Track::destructive () const
363 return _diskstream->destructive ();
366 list<boost::shared_ptr<Source> > &
367 Track::last_capture_sources ()
369 return _diskstream->last_capture_sources ();
372 void
373 Track::set_capture_offset ()
375 _diskstream->set_capture_offset ();
378 list<boost::shared_ptr<Source> >
379 Track::steal_write_sources()
381 return _diskstream->steal_write_sources ();
384 void
385 Track::reset_write_sources (bool r, bool force)
387 _diskstream->reset_write_sources (r, force);
390 float
391 Track::playback_buffer_load () const
393 return _diskstream->playback_buffer_load ();
396 float
397 Track::capture_buffer_load () const
399 return _diskstream->capture_buffer_load ();
403 Track::do_refill ()
405 return _diskstream->do_refill ();
409 Track::do_flush (RunContext c, bool force)
411 return _diskstream->do_flush (c, force);
414 void
415 Track::set_pending_overwrite (bool o)
417 _diskstream->set_pending_overwrite (o);
421 Track::seek (framepos_t p, bool complete_refill)
423 return _diskstream->seek (p, complete_refill);
426 bool
427 Track::hidden () const
429 return _diskstream->hidden ();
433 Track::can_internal_playback_seek (framepos_t p)
435 return _diskstream->can_internal_playback_seek (p);
439 Track::internal_playback_seek (framepos_t p)
441 return _diskstream->internal_playback_seek (p);
444 void
445 Track::non_realtime_input_change ()
447 _diskstream->non_realtime_input_change ();
450 void
451 Track::non_realtime_locate (framepos_t p)
453 _diskstream->non_realtime_locate (p);
456 void
457 Track::non_realtime_set_speed ()
459 _diskstream->non_realtime_set_speed ();
463 Track::overwrite_existing_buffers ()
465 return _diskstream->overwrite_existing_buffers ();
468 framecnt_t
469 Track::get_captured_frames (uint32_t n) const
471 return _diskstream->get_captured_frames (n);
475 Track::set_loop (Location* l)
477 return _diskstream->set_loop (l);
480 void
481 Track::transport_looped (framepos_t p)
483 _diskstream->transport_looped (p);
486 bool
487 Track::realtime_set_speed (double s, bool g)
489 return _diskstream->realtime_set_speed (s, g);
492 void
493 Track::transport_stopped_wallclock (struct tm & n, time_t t, bool g)
495 _diskstream->transport_stopped_wallclock (n, t, g);
498 bool
499 Track::pending_overwrite () const
501 return _diskstream->pending_overwrite ();
504 double
505 Track::speed () const
507 return _diskstream->speed ();
510 void
511 Track::prepare_to_stop (framepos_t p)
513 _diskstream->prepare_to_stop (p);
516 void
517 Track::set_slaved (bool s)
519 _diskstream->set_slaved (s);
522 ChanCount
523 Track::n_channels ()
525 return _diskstream->n_channels ();
528 framepos_t
529 Track::get_capture_start_frame (uint32_t n) const
531 return _diskstream->get_capture_start_frame (n);
534 AlignStyle
535 Track::alignment_style () const
537 return _diskstream->alignment_style ();
540 AlignChoice
541 Track::alignment_choice () const
543 return _diskstream->alignment_choice ();
546 framepos_t
547 Track::current_capture_start () const
549 return _diskstream->current_capture_start ();
552 framepos_t
553 Track::current_capture_end () const
555 return _diskstream->current_capture_end ();
558 void
559 Track::playlist_modified ()
561 _diskstream->playlist_modified ();
565 Track::use_playlist (boost::shared_ptr<Playlist> p)
567 return _diskstream->use_playlist (p);
571 Track::use_copy_playlist ()
573 return _diskstream->use_copy_playlist ();
577 Track::use_new_playlist ()
579 return _diskstream->use_new_playlist ();
582 uint32_t
583 Track::read_data_count () const
585 return _diskstream->read_data_count ();
588 void
589 Track::set_align_style (AlignStyle s, bool force)
591 _diskstream->set_align_style (s, force);
594 void
595 Track::set_align_choice (AlignChoice s, bool force)
597 _diskstream->set_align_choice (s, force);
600 uint32_t
601 Track::write_data_count () const
603 return _diskstream->write_data_count ();
606 PBD::ID const &
607 Track::diskstream_id () const
609 return _diskstream->id ();
612 void
613 Track::set_block_size (pframes_t n)
615 Route::set_block_size (n);
616 _diskstream->set_block_size (n);
619 void
620 Track::adjust_playback_buffering ()
622 if (_diskstream) {
623 _diskstream->adjust_playback_buffering ();
627 void
628 Track::adjust_capture_buffering ()
630 if (_diskstream) {
631 _diskstream->adjust_capture_buffering ();
635 bool
636 Track::send_silence () const
639 ADATs work in a strange way..
640 they monitor input always when stopped.and auto-input is engaged.
642 Other machines switch to input on stop if the track is record enabled,
643 regardless of the auto input setting (auto input only changes the
644 monitoring state when the transport is rolling)
647 bool send_silence;
649 if (!Config->get_tape_machine_mode()) {
651 ADATs work in a strange way..
652 they monitor input always when stopped.and auto-input is engaged.
654 if ((Config->get_monitoring_model() == SoftwareMonitoring)
655 && (_session.config.get_auto_input () || _diskstream->record_enabled())) {
656 send_silence = false;
657 } else {
658 send_silence = true;
660 } else {
662 Other machines switch to input on stop if the track is record enabled,
663 regardless of the auto input setting (auto input only changes the
664 monitoring state when the transport is rolling)
666 if ((Config->get_monitoring_model() == SoftwareMonitoring)
667 && _diskstream->record_enabled()) {
668 send_silence = false;
669 } else {
670 send_silence = true;
674 return send_silence;
677 void
678 Track::maybe_declick (BufferSet& bufs, framecnt_t nframes, int declick)
680 /* never declick if there is an internal generator - we just want it to
681 keep generating sound without interruption.
684 if (_have_internal_generator) {
685 return;
688 if (!declick) {
689 declick = _pending_declick;
692 if (declick != 0) {
693 Amp::declick (bufs, nframes, declick);