summaryrefslogtreecommitdiff
path: root/libs/surfaces/maschine2/m2device.h
blob: b52383213b0fbacf8979a2ed9a0edee44ae4db96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef _ardour_surfaces_maschine2hardware_h_
#define _ardour_surfaces_maschine2hardware_h_

#include <hidapi.h>
#include <cairomm/refptr.h>
#include <cairomm/surface.h>
#include "pbd/signals.h"

namespace ArdourSurface {

class M2Contols;

/** Abstraction for various variants:
 *  - NI Maschine Mikro
 *  - NI Maschine
 *  - NI Maschine Studio
 */

class M2Device
{
	public:
		M2Device ()
			: _splashcnt (0)
			, _blink_counter (0)
			, _blink_shade (0.f)
			{}
		virtual ~M2Device () {}

		virtual void clear (bool splash = false) {
			if (splash) {
				_splashcnt = 0;
			} else {
				_splashcnt = _splashtime;
			}
			_blink_counter = 0;
			_blink_shade = 0.f;
		}

		virtual void read (hid_device*, M2Contols*) = 0;
		virtual void write (hid_device*, M2Contols*) = 0;
		virtual Cairo::RefPtr<Cairo::ImageSurface> surface () = 0;

		PBD::Signal0<bool> vblank;

	protected:
		void bump_blink () {
			_blink_counter = (_blink_counter + 1) % 12;
			_blink_shade = fabsf (1.f - _blink_counter / 6.f);
		}

		uint32_t _splashcnt;
		static const uint32_t _splashtime = 25 * 3;
		unsigned int _blink_counter;
		float        _blink_shade;
};

} /* namespace */
#endif /* _ardour_surfaces_maschine2_h_*/