forked from michaelforney/oscmix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsysex_osx.h
67 lines (54 loc) · 1.42 KB
/
sysex_osx.h
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
#ifndef SYSEX_H
#define SYSEX_H 1
#include <stdint.h>
#include <stddef.h> // For size_t
#ifdef __cplusplus
extern "C" {
#endif
struct sysex {
uint_least32_t mfrid;
unsigned char devid;
unsigned char subid;
unsigned char *data;
size_t datalen;
};
enum {
SYSEX_MFRID = 1,
SYSEX_DEVID = 2,
SYSEX_SUBID = 4,
};
size_t sysexenc(struct sysex *p, unsigned char *dst, int flags);
int sysexdec(struct sysex *p, const unsigned char *src, size_t len, int flags);
void base128enc(unsigned char *dst, const unsigned char *src, size_t len);
int base128dec(unsigned char *dst, const unsigned char *src, size_t len);
static inline uint_least32_t
getle32_7bit(const void *p)
{
// Cast to `const unsigned char*` for C++ compatibility (needed in tools/regtool_osx.cpp)
const unsigned char *b = reinterpret_cast<const unsigned char *>(p);
//const unsigned char *b = p;
uint_least32_t v;
v = b[0] & 0x7ful;
v |= (b[1] & 0x7ful) << 7;
v |= (b[2] & 0x7ful) << 14;
v |= (b[3] & 0x7ful) << 21;
v |= (b[4] & 0xful) << 28;
return v;
}
static inline void *
putle32_7bit(void *p, uint_least32_t v)
{
// Cast to `unsigned char*` for C++ compatibility (needed in tools/regtool_osx.cpp)
unsigned char *b = reinterpret_cast<unsigned char *>(p);
// unsigned char *b = p;
b[0] = v & 0x7f;
b[1] = (v >> 7) & 0x7f;
b[2] = (v >> 14) & 0x7f;
b[3] = (v >> 21) & 0x7f;
b[4] = (v >> 28) & 0x3f;
return b + 5;
}
#ifdef __cplusplus
}
#endif
#endif // SYSEX_H