Skeleton for NI Maschine2 Surface
[ardour.git] / libs / surfaces / maschine2 / m2device.h
1 /*
2  * Copyright (C) 2016 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, or (at your option)
7  * 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 Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #ifndef _ardour_surfaces_maschine2hardware_h_
20 #define _ardour_surfaces_maschine2hardware_h_
21
22 #include <hidapi.h>
23 #include <cairomm/refptr.h>
24 #include <cairomm/surface.h>
25 #include "pbd/signals.h"
26
27 namespace ArdourSurface {
28
29 class M2Contols;
30
31 /** Abstraction for various variants:
32  *  - NI Maschine Mikro
33  *  - NI Maschine
34  *  - NI Maschine Studio
35  */
36
37 class M2Device
38 {
39         public:
40                 M2Device ()
41                         : _splashcnt (0)
42                         , _blink_counter (0)
43                         , _blink_shade (0.f)
44                         {}
45                 virtual ~M2Device () {}
46
47                 virtual void clear (bool splash = false) {
48                         if (splash) {
49                                 _splashcnt = 0;
50                         } else {
51                                 _splashcnt = _splashtime;
52                         }
53                         _blink_counter = 0;
54                         _blink_shade = 0.f;
55                 }
56
57                 virtual void read (hid_device*, M2Contols*) = 0;
58                 virtual void write (hid_device*, M2Contols*) = 0;
59                 virtual Cairo::RefPtr<Cairo::ImageSurface> surface () = 0;
60
61                 PBD::Signal0<bool> vblank;
62
63         protected:
64                 void bump_blink () {
65                         _blink_counter = (_blink_counter + 1) % 12;
66                         _blink_shade = fabsf (1.f - _blink_counter / 6.f);
67                 }
68
69                 uint32_t _splashcnt;
70                 static const uint32_t _splashtime = 25 * 3;
71                 unsigned int _blink_counter;
72                 float        _blink_shade;
73 };
74
75 } /* namespace */
76 #endif /* _ardour_surfaces_maschine2_h_*/