Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
23 
24 #include "pbd/signals.h"
25 
27 #include "ardour/types.h"
28 
29 namespace ARDOUR {
30 
32 public:
33  virtual ~HasLatency() {}
34  virtual samplecnt_t signal_latency() const = 0;
35 };
36 
38 public:
39  Latent ();
40  Latent (Latent const&);
41  virtual ~Latent() {}
42 
43 
44  /* effective latency to be used while processing */
46  if (_zero_latency) {
47  return 0;
48  } else if (_use_user_latency) {
49  return _user_latency;
50  } else {
51  return signal_latency ();
52  }
53  }
54 
55  /* custom user-set latency, if any */
57  if (_use_user_latency) {
58  return _user_latency;
59  } else {
60  return 0;
61  }
62  }
63 
65  _use_user_latency = false;
66  _user_latency = 0;
67  }
68 
69  virtual void set_user_latency (samplecnt_t val) {
70  _use_user_latency = true;
71  _user_latency = val;
72  }
73 
74  static void force_zero_latency (bool en) {
75  if (_zero_latency == en) {
76  return;
77  }
78  _zero_latency = en;
79  DisableSwitchChanged (); /* EMIT SIGNAL */
80  }
81 
82  static bool zero_latency () {
83  return _zero_latency;
84  }
85 
88 
89 protected:
90  int set_state (const XMLNode& node, int version);
91  void add_state (XMLNode*) const;
92 
93 private:
96 
97  static bool _zero_latency;
98 };
99 
100 } /* namespace */
101 
102 
virtual ~HasLatency()
Definition: latent.h:33
virtual samplecnt_t signal_latency() const =0
void unset_user_latency()
Definition: latent.h:64
samplecnt_t effective_latency() const
Definition: latent.h:45
samplecnt_t _user_latency
Definition: latent.h:95
virtual void set_user_latency(samplecnt_t val)
Definition: latent.h:69
void add_state(XMLNode *) const
virtual ~Latent()
Definition: latent.h:41
static void force_zero_latency(bool en)
Definition: latent.h:74
samplecnt_t _use_user_latency
Definition: latent.h:94
Latent(Latent const &)
PBD::Signal< void()> LatencyChanged
Definition: latent.h:87
samplecnt_t user_latency() const
Definition: latent.h:56
static PBD::Signal< void()> DisableSwitchChanged
Definition: latent.h:86
static bool zero_latency()
Definition: latent.h:82
int set_state(const XMLNode &node, int version)
static bool _zero_latency
Definition: latent.h:97
Definition: xml++.h:114
#define LIBARDOUR_API
Temporal::samplecnt_t samplecnt_t