-
Notifications
You must be signed in to change notification settings - Fork 4
/
RekordJog_AllenAndHeath.py
146 lines (118 loc) · 3.42 KB
/
RekordJog_AllenAndHeath.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os
import mido
import math
from functions.check_config import check_config
from functions.rekordjog_start_sequence import rekordjog_start_sequence
# The JOG_MULTIPLIER is required for smooth jog operation.
# Pioneer controllers seem to be sending MIDI signal at a much higher rate than XONE:4D.
# If you send one fake Pioneer message for each Xone jog message, scratching sounds unnatural.
# You need to test different values for other controllers.
JOG_MULTIPLIER = 15
CONV_J_VAL = {
1:65, #0
2:66, #1
4:67, #1
7:69, #2
11:71, #2
16:73, #2
20:75, #2
30:80, #5
127:63,
126:62,
124:61,
121:59,
117:57,
112:55,
108:53,
98:48
}
tempo_values = [
[63, 63],
[63, 63],
[63, 63],
[63, 63],
]
JOG_CODES = {
(0xBF, 0x25):0,
(0xBF, 0x2D):1,
(0xBE, 0x25):2,
(0xBE, 0x2D):3,
}
TOUCH_ON_CODES = {
(0x9F, 0x26):0,
(0x9F, 0x46):1,
(0x9E, 0x26):2,
(0x9E, 0x46):3,
}
TOUCH_OFF_CODES = {
(0x8F, 0x26):0,
(0x8F, 0x46):1,
(0x8E, 0x26):2,
(0x8E, 0x46):3,
}
TEMPO_BIG_CODES = {
(0xbf, 0x11):0,
(0xbe, 0x11):1,
(0xbf, 0x1f):2,
(0xbe, 0x1f):3,
(0xbf, 0x13):4,
(0xbe, 0x13):5,
(0xbf, 0x1d):6,
(0xbe, 0x1d):7,
}
TEMPO_SMALL_CODES = {
(0xbf, 0x10):0,
(0xbe, 0x10):1,
(0xbf, 0x1e):2,
(0xbe, 0x1e):3,
(0xbf, 0x12):4,
(0xbe, 0x12):5,
(0xbf, 0x1c):6,
(0xbe, 0x1c):7,
}
def jog(midi_out, msg):
id = JOG_CODES[tuple(msg.bytes()[:2])]
v = CONV_J_VAL[msg.bytes()[2]]
ms = mido.Message.from_bytes([176+id, 0x22, v])
for i in range(JOG_MULTIPLIER):
midi_out.send(ms)
def tempo(midi_out, id):
msb = mido.Message.from_bytes([0xB0+id, 0x00, tempo_values[id][0]])
lsb = mido.Message.from_bytes([0xB0+id, 0x20, tempo_values[id][1]])
midi_out.send(msb)
midi_out.send(lsb)
def main():
midi_inp, midi_out = check_config()
try:
midi_inp_conf, midi_out_conf = check_config()
midi_inp = mido.open_input(midi_inp_conf)
if os.name == 'nt':
midi_out = mido.open_output(midi_out_conf)
else:
midi_out = mido.open_output("Pioneer DDJ-SX", True)
rekordjog_start_sequence()
while True:
ims = midi_inp.receive()
ims_2b = tuple(ims.bytes()[:2])
if ims_2b in JOG_CODES:
jog(midi_out, ims)
elif ims_2b in TOUCH_ON_CODES:
deck_id = TOUCH_ON_CODES[ims_2b]
touch = mido.Message.from_bytes([0x90+deck_id, 0x36, 0x7F])
midi_out.send(touch)
elif ims_2b in TOUCH_OFF_CODES:
deck_id = TOUCH_OFF_CODES[ims_2b]
release = mido.Message.from_bytes([0x90+deck_id, 0x36, 0x00])
midi_out.send(release)
elif ims_2b in TEMPO_BIG_CODES:
deck_id = math.floor(TEMPO_BIG_CODES[ims_2b] / 2)
tempo_values[deck_id][0] = 127 - ims.bytes()[2]
tempo(midi_out, deck_id)
elif ims_2b in TEMPO_SMALL_CODES:
deck_id = math.floor(TEMPO_SMALL_CODES[ims_2b] / 2)
tempo_values[deck_id][1] = 127 - ims.bytes()[2]
tempo(midi_out, deck_id)
except KeyboardInterrupt:
print("\nClosing RekordJog, bye.")
if __name__ == "__main__":
main()