Ardour  8.12
latent.h
Go to the documentation of this file.
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 
28 #include "ardour/types.h"
29 
30 namespace ARDOUR {
31 
33 public:
34  virtual ~HasLatency() {}
35  virtual samplecnt_t signal_latency() const = 0;
36 };
37 
39 public:
40  Latent ();
41  Latent (Latent const&);
42  virtual ~Latent() {}
43 
44 
45  /* effective latency to be used while processing */
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 */
58  if (_use_user_latency) {
59  return _user_latency;
60  } else {
61  return 0;
62  }
63  }
64 
66  _use_user_latency = false;
67  _user_latency = 0;
68  }
69 
70  virtual void set_user_latency (samplecnt_t val) {
71  _use_user_latency = true;
72  _user_latency = val;
73  }
74 
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 
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:
97 
98  static bool _zero_latency;
99 };
100 
101 } /* namespace */
102 
103 
104 #endif /* __ardour_latent_h__*/
virtual ~HasLatency()
Definition: latent.h:34
virtual samplecnt_t signal_latency() const =0
void unset_user_latency()
Definition: latent.h:65
samplecnt_t effective_latency() const
Definition: latent.h:46
samplecnt_t _user_latency
Definition: latent.h:96
virtual void set_user_latency(samplecnt_t val)
Definition: latent.h:70
PBD::Signal0< void > LatencyChanged
Definition: latent.h:88
void add_state(XMLNode *) const
static PBD::Signal0< void > DisableSwitchChanged
Definition: latent.h:87
virtual ~Latent()
Definition: latent.h:42
static void force_zero_latency(bool en)
Definition: latent.h:75
samplecnt_t _use_user_latency
Definition: latent.h:95
Latent(Latent const &)
samplecnt_t user_latency() const
Definition: latent.h:57
static bool zero_latency()
Definition: latent.h:83
int set_state(const XMLNode &node, int version)
static bool _zero_latency
Definition: latent.h:98
Definition: xml++.h:114
#define LIBARDOUR_API
Temporal::samplecnt_t samplecnt_t