This repository was archived by the owner on Mar 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathe2_syx_codec.py
75 lines (54 loc) · 1.83 KB
/
e2_syx_codec.py
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
# Encode/decode bytes to/from SysEx for Electribe 2
"""
The dump data conversion
DATA ( 1set = 8bit x 7Byte )
b7 ~ b0 b7 ~ b0 b7 ~~ b0 b7 ~ b0
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-~~-+-+-+ +-+-+-+-+-+-+-+-+
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-~~-+-+-+ +-+-+-+-+-+-+-+-+
7n+0 7n+1 7n+2 ~~ 7n+5 7n+6
MIDI DATA ( 1set = 7bit x 8Byte )
b7b7b7b7b7b7b7 b6 ~ b0 b6 ~~ b0 b6 ~ b0
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-~~-+-+-+ +-+-+-+-+-+-+-+-+
|0| | | | | | | | |0| | | | | | | | |0| | | | | |0| | | | | | | |
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-~~-+-+-+ +-+-+-+-+-+-+-+-+
7n+6,5,4,3,2,1,0 7n+0 7n+1 ~~ 7n+5 7n+6
"""
def syx_enc(byt):
lng = len(byt)
lst = []
tmp = []
b = 0
cnt = 7
lim = 0
for i,e in enumerate(byt):
if lng < 7:
lim = 7 - lng
a = e & ~0b10000000
b |= ((e & 0b10000000)>>cnt)
tmp.append(a)
cnt -= 1
if cnt == lim:
lst.append([b])
lst.append(tmp)
tmp = []
b = 0
cnt = 7
if (lng - i) < 7:
lim = 7 - (lng - i) + 1
syx = [item for sublist in lst for item in sublist]
return syx
def syx_dec(syx):
chk = [syx[i:i + 8] for i in range(0, len(syx), 8)]
lst = []
tmp = []
a = 0
for l in chk:
for i in range(len(l)-1):
a = l[i+1]
a |= ((l[0] & (1<<i))>>i)<<7
tmp.append(a)
lst.append(tmp)
tmp = []
byt = [item for sublist in lst for item in sublist]
return byt