1 /* 2 * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com> 3 * Copyright (C) 2009 David Robillard <d@drobilla.net> 4 * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net> 5 * Copyright (C) 2019 Robin Gareus <robin@gareus.org> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program; if not, write to the Free Software Foundation, Inc., 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 */ 21 22 #ifndef __ardour_latent_h__ 23 #define __ardour_latent_h__ 24 25 #include "pbd/signals.h" 26 27 #include "ardour/libardour_visibility.h" 28 #include "ardour/types.h" 29 30 namespace ARDOUR { 31 32 class LIBARDOUR_API HasLatency { 33 public: ~HasLatency()34 virtual ~HasLatency() {} 35 virtual samplecnt_t signal_latency() const = 0; 36 }; 37 38 class LIBARDOUR_API Latent : public HasLatency { 39 public: 40 Latent (); 41 Latent (Latent const&); ~Latent()42 virtual ~Latent() {} 43 44 45 /* effective latency to be used while processing */ effective_latency()46 samplecnt_t effective_latency() const { 47 if (_zero_latency) { 48 return 0; 49 } else if (_use_user_latency) { 50 return _user_latency; 51 } else { 52 return signal_latency (); 53 } 54 } 55 56 /* custom user-set latency, if any */ user_latency()57 samplecnt_t user_latency () const { 58 if (_use_user_latency) { 59 return _user_latency; 60 } else { 61 return 0; 62 } 63 } 64 unset_user_latency()65 void unset_user_latency () { 66 _use_user_latency = false; 67 _user_latency = 0; 68 } 69 set_user_latency(samplecnt_t val)70 virtual void set_user_latency (samplecnt_t val) { 71 _use_user_latency = true; 72 _user_latency = val; 73 } 74 force_zero_latency(bool en)75 static void force_zero_latency (bool en) { 76 if (_zero_latency == en) { 77 return; 78 } 79 _zero_latency = en; 80 DisableSwitchChanged (); /* EMIT SIGNAL */ 81 } 82 zero_latency()83 static bool zero_latency () { 84 return _zero_latency; 85 } 86 87 static PBD::Signal0<void> DisableSwitchChanged; 88 PBD::Signal0<void> LatencyChanged; 89 90 protected: 91 int set_state (const XMLNode& node, int version); 92 void add_state (XMLNode*) const; 93 94 private: 95 samplecnt_t _use_user_latency; 96 samplecnt_t _user_latency; 97 98 static bool _zero_latency; 99 }; 100 101 } /* namespace */ 102 103 104 #endif /* __ardour_latent_h__*/ 105