Ardour  8.12
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 #ifndef __libardour_mididm_h__
20 #define __libardour_mididm_h__
21 
22 #include "ardour/types.h"
24 
25 namespace ARDOUR {
26 
27 class PortEngine;
28 
30 {
31 public:
32 
33  MIDIDM (samplecnt_t sample_rate);
34 
35  int process (pframes_t nframes, PortEngine &pe, void *midi_in, void *midi_out);
36 
37  samplecnt_t latency (void) { return _cnt_total > 10 ? _avg_delay : 0; }
38  samplecnt_t processed (void) { return _cnt_total; }
39  double deviation (void) { return _cnt_total > 1 ? sqrt(_var_s / ((double)(_cnt_total - 1))) : 0; }
40  bool ok (void) { return _cnt_total > 200; }
41  bool have_signal (void) { return (_monotonic_cnt - _last_signal_tme) < (uint64_t) _sample_rate ; }
42 
43 private:
44  int64_t parse_mclk (uint8_t const * const buf, pframes_t timestamp) const;
45  int64_t parse_mtc (uint8_t const * const buf, pframes_t timestamp) const;
46 
48 
49  uint64_t _monotonic_cnt;
50  uint64_t _last_signal_tme;
51 
52  uint64_t _cnt_total;
53  uint64_t _dly_total;
54  uint32_t _min_delay;
55  uint32_t _max_delay;
56  double _avg_delay;
57  double _var_m;
58  double _var_s;
59 
60 };
61 
62 }
63 
64 #endif /* __libardour_mididm_h__ */
uint64_t _dly_total
Definition: mididm.h:53
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:37
bool ok(void)
Definition: mididm.h:40
MIDIDM(samplecnt_t sample_rate)
uint64_t _monotonic_cnt
Definition: mididm.h:49
double _var_m
Definition: mididm.h:57
int process(pframes_t nframes, PortEngine &pe, void *midi_in, void *midi_out)
samplecnt_t _sample_rate
Definition: mididm.h:47
double deviation(void)
Definition: mididm.h:39
uint64_t _cnt_total
Definition: mididm.h:52
uint32_t _max_delay
Definition: mididm.h:55
bool have_signal(void)
Definition: mididm.h:41
double _var_s
Definition: mididm.h:58
samplecnt_t processed(void)
Definition: mididm.h:38
uint64_t _last_signal_tme
Definition: mididm.h:50
uint32_t _min_delay
Definition: mididm.h:54
double _avg_delay
Definition: mididm.h:56
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t