Ardour  9.0-pre0-582-g084a23a80d
mididm.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
3  *
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.
8  *
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.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #pragma once
20 
21 #include "ardour/types.h"
23 
24 namespace ARDOUR {
25 
26 class PortEngine;
27 
29 {
30 public:
31 
32  MIDIDM (samplecnt_t sample_rate);
33 
34  int process (pframes_t nframes, PortEngine &pe, void *midi_in, void *midi_out);
35 
36  samplecnt_t latency (void) { return _cnt_total > 10 ? _avg_delay : 0; }
37  samplecnt_t processed (void) { return _cnt_total; }
38  double deviation (void) { return _cnt_total > 1 ? sqrt(_var_s / ((double)(_cnt_total - 1))) : 0; }
39  bool ok (void) { return _cnt_total > 200; }
40  bool have_signal (void) { return (_monotonic_cnt - _last_signal_tme) < (uint64_t) _sample_rate ; }
41 
42 private:
43  int64_t parse_mclk (uint8_t const * const buf, pframes_t timestamp) const;
44  int64_t parse_mtc (uint8_t const * const buf, pframes_t timestamp) const;
45 
47 
48  uint64_t _monotonic_cnt;
49  uint64_t _last_signal_tme;
50 
51  uint64_t _cnt_total;
52  uint64_t _dly_total;
53  uint32_t _min_delay;
54  uint32_t _max_delay;
55  double _avg_delay;
56  double _var_m;
57  double _var_s;
58 
59 };
60 
61 }
62 
uint64_t _dly_total
Definition: mididm.h:52
int64_t parse_mtc(uint8_t const *const buf, pframes_t timestamp) const
int64_t parse_mclk(uint8_t const *const buf, pframes_t timestamp) const
samplecnt_t latency(void)
Definition: mididm.h:36
bool ok(void)
Definition: mididm.h:39
MIDIDM(samplecnt_t sample_rate)
uint64_t _monotonic_cnt
Definition: mididm.h:48
double _var_m
Definition: mididm.h:56
int process(pframes_t nframes, PortEngine &pe, void *midi_in, void *midi_out)
samplecnt_t _sample_rate
Definition: mididm.h:46
double deviation(void)
Definition: mididm.h:38
uint64_t _cnt_total
Definition: mididm.h:51
uint32_t _max_delay
Definition: mididm.h:54
bool have_signal(void)
Definition: mididm.h:40
double _var_s
Definition: mididm.h:57
samplecnt_t processed(void)
Definition: mididm.h:37
uint64_t _last_signal_tme
Definition: mididm.h:49
uint32_t _min_delay
Definition: mididm.h:53
double _avg_delay
Definition: mididm.h:55
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t