mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-09 08:14:58 +01:00
PortInsert: emit signal when latency changes, cache I/O latency
This commit is contained in:
parent
0213fa6cc7
commit
40ea071873
2 changed files with 65 additions and 9 deletions
|
|
@ -81,6 +81,10 @@ public:
|
||||||
void set_measured_latency (samplecnt_t);
|
void set_measured_latency (samplecnt_t);
|
||||||
samplecnt_t latency () const;
|
samplecnt_t latency () const;
|
||||||
|
|
||||||
|
samplecnt_t measured_latency () const {
|
||||||
|
return _measured_latency;
|
||||||
|
}
|
||||||
|
|
||||||
static std::string name_and_id_new_insert (Session&, uint32_t&);
|
static std::string name_and_id_new_insert (Session&, uint32_t&);
|
||||||
|
|
||||||
boost::shared_ptr<AutomationControl> send_polarity_control () const {
|
boost::shared_ptr<AutomationControl> send_polarity_control () const {
|
||||||
|
|
@ -125,12 +129,17 @@ private:
|
||||||
/* disallow copy construction */
|
/* disallow copy construction */
|
||||||
PortInsert (const PortInsert&);
|
PortInsert (const PortInsert&);
|
||||||
|
|
||||||
|
void io_changed (IOChange change, void*);
|
||||||
|
void latency_changed ();
|
||||||
|
|
||||||
boost::shared_ptr<Delivery> _out;
|
boost::shared_ptr<Delivery> _out;
|
||||||
boost::shared_ptr<Amp> _amp;
|
boost::shared_ptr<Amp> _amp;
|
||||||
boost::shared_ptr<GainControl> _gain_control;
|
boost::shared_ptr<GainControl> _gain_control;
|
||||||
boost::shared_ptr<PeakMeter> _send_meter;
|
boost::shared_ptr<PeakMeter> _send_meter;
|
||||||
boost::shared_ptr<PeakMeter> _return_meter;
|
boost::shared_ptr<PeakMeter> _return_meter;
|
||||||
bool _metering;
|
bool _metering;
|
||||||
|
uint32_t _io_latency;
|
||||||
|
uint32_t _signal_latency;
|
||||||
|
|
||||||
MTDM* _mtdm;
|
MTDM* _mtdm;
|
||||||
bool _latency_detect;
|
bool _latency_detect;
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ PortInsert::PortInsert (Session& s, boost::shared_ptr<Pannable> pannable, boost:
|
||||||
: IOProcessor (s, true, true, name_and_id_new_insert (s, _bitslot), "", DataType::AUDIO, true)
|
: IOProcessor (s, true, true, name_and_id_new_insert (s, _bitslot), "", DataType::AUDIO, true)
|
||||||
, _out (new Delivery (s, _output, pannable, mm, _name, Delivery::Insert))
|
, _out (new Delivery (s, _output, pannable, mm, _name, Delivery::Insert))
|
||||||
, _metering (false)
|
, _metering (false)
|
||||||
|
, _signal_latency (0)
|
||||||
, _mtdm (0)
|
, _mtdm (0)
|
||||||
, _latency_detect (false)
|
, _latency_detect (false)
|
||||||
, _latency_flush_samples (0)
|
, _latency_flush_samples (0)
|
||||||
|
|
@ -69,6 +70,11 @@ PortInsert::PortInsert (Session& s, boost::shared_ptr<Pannable> pannable, boost:
|
||||||
add_control (_out->gain_control ());
|
add_control (_out->gain_control ());
|
||||||
add_control (_out->polarity_control ());
|
add_control (_out->polarity_control ());
|
||||||
add_control (_gain_control);
|
add_control (_gain_control);
|
||||||
|
|
||||||
|
_io_latency = _session.engine().samples_per_cycle();
|
||||||
|
|
||||||
|
input ()->changed.connect_same_thread (*this, boost::bind (&PortInsert::io_changed, this, _1, _2));
|
||||||
|
output ()->changed.connect_same_thread (*this, boost::bind (&PortInsert::io_changed, this, _1, _2));
|
||||||
}
|
}
|
||||||
|
|
||||||
PortInsert::~PortInsert ()
|
PortInsert::~PortInsert ()
|
||||||
|
|
@ -84,9 +90,20 @@ PortInsert::set_pre_fader (bool p)
|
||||||
_out->set_pre_fader (p);
|
_out->set_pre_fader (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PortInsert::latency_changed ()
|
||||||
|
{
|
||||||
|
LatencyChanged (); /* EMIT SIGNAL */
|
||||||
|
assert (owner ());
|
||||||
|
static_cast<Route*>(owner ())->processor_latency_changed (); /* EMIT SIGNAL */
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PortInsert::start_latency_detection ()
|
PortInsert::start_latency_detection ()
|
||||||
{
|
{
|
||||||
|
if (_latency_detect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
delete _mtdm;
|
delete _mtdm;
|
||||||
_mtdm = new MTDM (_session.sample_rate());
|
_mtdm = new MTDM (_session.sample_rate());
|
||||||
_latency_flush_samples = 0;
|
_latency_flush_samples = 0;
|
||||||
|
|
@ -97,6 +114,9 @@ PortInsert::start_latency_detection ()
|
||||||
void
|
void
|
||||||
PortInsert::stop_latency_detection ()
|
PortInsert::stop_latency_detection ()
|
||||||
{
|
{
|
||||||
|
if (!_latency_detect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
_latency_flush_samples = effective_latency() + _session.engine().samples_per_cycle();
|
_latency_flush_samples = effective_latency() + _session.engine().samples_per_cycle();
|
||||||
_latency_detect = false;
|
_latency_detect = false;
|
||||||
}
|
}
|
||||||
|
|
@ -108,9 +128,6 @@ PortInsert::set_measured_latency (samplecnt_t n)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_measured_latency = n;
|
_measured_latency = n;
|
||||||
LatencyChanged (); /* EMIT SIGNAL */
|
|
||||||
assert (owner ());
|
|
||||||
static_cast<Route*>(owner ())->processor_latency_changed (); /* EMIT SIGNAL */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
samplecnt_t
|
samplecnt_t
|
||||||
|
|
@ -133,6 +150,12 @@ PortInsert::latency() const
|
||||||
void
|
void
|
||||||
PortInsert::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool)
|
PortInsert::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool)
|
||||||
{
|
{
|
||||||
|
const samplecnt_t l = effective_latency ();
|
||||||
|
if (_signal_latency != l) {
|
||||||
|
_signal_latency = l;
|
||||||
|
latency_changed ();
|
||||||
|
}
|
||||||
|
|
||||||
if (_output->n_ports().n_total() == 0) {
|
if (_output->n_ports().n_total() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -251,8 +274,10 @@ PortInsert::set_state (const XMLNode& node, int version)
|
||||||
uint32_t blocksize = 0;
|
uint32_t blocksize = 0;
|
||||||
node.get_property ("block-size", blocksize);
|
node.get_property ("block-size", blocksize);
|
||||||
|
|
||||||
//if the jack period is the same as when the value was saved, we can recall our latency..
|
/* If the period is the same as when the value was saved,
|
||||||
if ( (_session.get_block_size() == blocksize) ) {
|
* we can recall our latency.
|
||||||
|
*/
|
||||||
|
if (_session.engine().samples_per_cycle () == blocksize && blocksize > 0) {
|
||||||
node.get_property ("latency", _measured_latency);
|
node.get_property ("latency", _measured_latency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -289,15 +314,25 @@ PortInsert::signal_latency() const
|
||||||
* need to take that into account too.
|
* need to take that into account too.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (_measured_latency == 0) {
|
if (_measured_latency == 0 || _latency_detect) {
|
||||||
return _session.engine().samples_per_cycle()
|
return _io_latency;
|
||||||
+ _input->connected_latency (false)
|
|
||||||
+ _output->connected_latency (true);
|
|
||||||
} else {
|
} else {
|
||||||
return _measured_latency;
|
return _measured_latency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PortInsert::io_changed (IOChange change, void*)
|
||||||
|
{
|
||||||
|
if (change.type & IOChange::ConnectionsChanged) {
|
||||||
|
if (output ()->connected () && input ()->connected ()) {
|
||||||
|
_io_latency = _input->connected_latency (false) + _output->connected_latency (true);
|
||||||
|
} else {
|
||||||
|
_io_latency = _session.engine().samples_per_cycle ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Caller must hold process lock */
|
/** Caller must hold process lock */
|
||||||
bool
|
bool
|
||||||
PortInsert::configure_io (ChanCount in, ChanCount out)
|
PortInsert::configure_io (ChanCount in, ChanCount out)
|
||||||
|
|
@ -358,6 +393,12 @@ PortInsert::activate ()
|
||||||
_return_meter->activate ();
|
_return_meter->activate ();
|
||||||
_amp->activate ();
|
_amp->activate ();
|
||||||
_out->activate ();
|
_out->activate ();
|
||||||
|
|
||||||
|
const samplecnt_t l = effective_latency ();
|
||||||
|
if (_signal_latency != l) {
|
||||||
|
_signal_latency = l;
|
||||||
|
latency_changed ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -373,4 +414,10 @@ PortInsert::deactivate ()
|
||||||
|
|
||||||
_amp->deactivate ();
|
_amp->deactivate ();
|
||||||
_out->deactivate ();
|
_out->deactivate ();
|
||||||
|
|
||||||
|
const samplecnt_t l = effective_latency ();
|
||||||
|
if (_signal_latency != l) {
|
||||||
|
_signal_latency = l;
|
||||||
|
latency_changed ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue