save version string with session for informational purposes
[ardour.git] / libs / ardour / ardour / mididm.h
1 /*
2  * Copyright (C) 2013-2014 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
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #ifndef __libardour_mididm_h__
20 #define __libardour_mididm_h__
21
22 #include "ardour/types.h"
23 #include "ardour/libardour_visibility.h"
24
25 namespace ARDOUR {
26
27 class PortEngine;
28
29 class LIBARDOUR_API MIDIDM
30 {
31 public:
32
33         MIDIDM (framecnt_t sample_rate);
34
35         int process (pframes_t nframes, PortEngine &pe, void *midi_in, void *midi_out);
36
37         framecnt_t latency (void) { return _cnt_total > 10 ? _avg_delay : 0; }
38         framecnt_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* buf, pframes_t timestamp) const;
45         int64_t parse_mtc  (uint8_t* buf, pframes_t timestamp) const;
46
47         framecnt_t _sample_rate;
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__ */