-
Notifications
You must be signed in to change notification settings - Fork 2
/
xtouch_davinci_resolve.ahk
500 lines (455 loc) · 8.11 KB
/
xtouch_davinci_resolve.ahk
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
/*
*
* Behringer X-TOUCH Mini MIDI 2 Davinci Resolve ShortCut using ahk
*
* (C) 2021 by Folke Ashberg, github.com/fashberg
*
*/
#include AutoHotkey-Midi/Midi.ahk
#include miditools.ahk
#Persistent
; for compiling
; compile: 'C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe' /in xtouch_davinci_resolve.ahk
;@Ahk2Exe-SetProductName XTouchMini-Davinci-Resolve-Midi-Adapter
;@Ahk2Exe-SetInternalName XTouchMini-Davinci-Resolve-Midi-Adapter
;@Ahk2Exe-SetDescription XTouchMini-Davinci-Resolve-Midi-Adapter
;@Ahk2Exe-SetCompanyName github.com/fashberg
;@Ahk2Exe-SetLegalTrademarks github.com/fashberg
;@Ahk2Exe-SetCopyright github.com/fashberg
;@Ahk2Exe-SetFileVersion 1.0.0.0
;@Ahk2Exe-SetProductVersion 1.0.0.0
midi := new Midi()
ok:=true
if (midi.OpenMidiOutByName( "X-TOUCH MINI" )<0){
ok:=false
}
if (midi.OpenMidiInByName( "X-TOUCH MINI" )<0){
ok:=false
}
if (!ok){
MsgBox, Cannot open MIDI Device
midi.Destroy()
ExitApp, 1
}
; switch to standard mode (versus MC-Mode)
midi.MidiOut("CC", 1, 127, 0)
; clear all buttons and say hello
; Layer A
midi.MidiOut("PC", 1, 0, 0)
Loop 2 {
int:=0
Loop 16 {
; button on
midi.MidiOut("N1", 1, int, 1)
int++
sleep 20
}
int:=0
Loop 16 {
; button off
midi.MidiOut("N1", 1, int, 0)
int++
sleep 20
}
; Layer B
midi.MidiOut("PC", 1, 1, 0)
}
; Layer A
midi.MidiOut("PC", 1, 0, 0)
Gosub, ProcessSound
;ProcessSound,
isShift := false
knob1 := new MidiKnob("knob1")
knob2 := new MidiKnob("knob2")
knob3 := new MidiKnob("knob3")
knob4 := new MidiKnob("knob4")
knob5 := new MidiKnob("knob5")
knob6 := new MidiKnob("knob6")
knob7 := new MidiKnob("knob7")
knob8 := new MidiKnob("knob8")
keyrepeatJ := new MidiRepeat("keyrepeatJ")
keyrepeatK := new MidiRepeat("keyrepeatK")
keyrepeatL := new MidiRepeat("keyrepeatL")
oldSound:=0
SetTimer, ProcessSound, 1800, -1000
Return ; end of MAIN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; called periodically by timer
; reads master volume and sets knob
ProcessSound:
;; get current master volume and set wheel 8
SoundGet, master_volume
snd := master_volume/100*127
if (snd!=oldSound){
OutputDebug, Sound Vol: %master_volume% / %snd%`r`n
midi.MidiOut("CC", 11, 8, snd)
oldSound:=snd
}
Return
; KNOBS
; KNOB 1
; JOG
MidiControlChange1:
knob1.CalledCC(midi.MidiIn())
Return
knob1left(midi){
global isShift
if (!isShift){
Send {left}
} else {
Send +{left}
}
}
knob1right(midi){
global isShift
if (!isShift){
Send {right}
} else {
Send +{right}
}
}
; KNOB 2
; JOG-LONG
MidiControlChange2:
knob2.CalledCC(midi.MidiIn())
Return
knob2left(midi){
global isShift
if (!isShift){
Send {Shift down}{left}{Shift up}
} else {
Send +{left 30}
}
}
knob2right(midi){
global isShift
if (!isShift){
Send {Shift down}{right}{Shift up}
} else {
Send +{right 30}
}
}
; KNOB 3
; JOG-CUT
MidiControlChange3:
knob3.CalledCC(midi.MidiIn())
Return
knob3left(midi){
global isShift
if (!isShift){
Send {Up}
} else {
Send ^{WheelDown}
}
}
knob3right(midi){
global isShift
if (!isShift){
Send {Down}
} else {
Send ^{WheelUp}
}
}
; KNOB 4
; MOVE
MidiControlChange4:
knob4.CalledCC(midi.MidiIn())
Return
knob4left(midi){
global isShift
if (!isShift){
Send {,}
} else {
Send +{,}
}
}
knob4right(midi){
global isShift
if (!isShift){
Send {.}
} else {
Send +{.}
}
}
; KNOB 5
; UNUSED
MidiControlChange5:
knob5.CalledCC(midi.MidiIn())
Return
knob5left(midi){
global isShift
if (!isShift){
Send ^+{Down}
} else {
Send ^!{Down}
}
}
knob5right(midi){
global isShift
if (!isShift){
Send ^+{Up}
} else {
Send ^!{Up}
}
}
; KNOB 6
; JOG
MidiControlChange6:
knob6.CalledCC(midi.MidiIn())
Return
knob6left(midi){
global isShift
if (!isShift){
Send {Numpad4}
} else {
Send {Numpad2}
}
}
knob6right(midi){
global isShift
if (!isShift){
Send {Numpad6}
} else {
Send {Numpad8}
}
}
; KNOB 7
; ZOOM
MidiControlChange7:
knob7.CalledCC(midi.MidiIn())
Return
knob7left(midi){
global isShift
if (!isShift){
Send {Ctrl down}{-}{Ctrl up}
} else {
Send +{WheelUp}
}
}
knob7right(midi){
global isShift
if (!isShift){
Send {Ctrl down}{=}{Ctrl up}
} else {
Send +{WheelDown}
}
}
; KNOB 7 pressed: reset zoom
MidiNoteOn6:
Send {Shift down}z{Shift up}
Return
; KNOB 8
; VOLUME
; Not using MidiKnob, because we want absolute value
MidiControlChange8:
cc := midi.MidiIn()
ccValue := cc.value
OutputDebug, CC8 %ccValue%`r`n
SoundSet ccValue/127 * 100
Return
; Row1 Key1
; Select MODE
;
MidiNoteOn8:
if (!isShift){
Send a
; switch row1/key2 off
midi.MidiOut("N0", 1, 1, 0)
} else {
}
Return
MidiNoteOff8:
if (!isShift){
; switch row1/key1 on
midi.MidiOut("N1", 1, 0, 1)
} else {
}
Return
; Row1 Key2
; TRIM MODE
;
MidiNoteOn9:
if (!isShift){
Send t
; switch row1/key1 off
midi.MidiOut("N0", 1, 0, 0)
} else {
}
Return
MidiNoteOff9:
if (!isShift){
; switch row1/key2 on
midi.MidiOut("N1", 1, 1, 1)
} else {
}
Return
; Row1 Key3
; SLIP MODE
;
MidiNoteOn10:
if (!isShift){
Send {w}
if (!oldW){
midi.MidiOut("N0", 1, 2, 0)
}
oldW:=!oldW
} else {
}
Return
MidiNoteOff10:
if (!isShift){
if (oldW){
midi.MidiOut("N1", 1, 2, 1)
}
} else {
}
Return
; Row1 Key4
; SPLIT
; JOIN
MidiNoteOn11:
if (!isShift){
Send {Ctrl down}\{Ctrl up}
} else {
Send {Alt down}\{Alt up}
}
Return
; Row1 Key5
; INSERT
;
MidiNoteOn12:
if (!isShift){
Send {F9}
} else {
}
Return
; Row1 Key6
; INSERT
;
MidiNoteOn13:
if (!isShift){
Send {F10}
} else {
Send {Shift down}{F10}{shift up}
}
Return
; Row1 Key7
; INSERT
;
MidiNoteOn14:
if (!isShift){
Send {F11}
} else {
Send {Shift down}{F11}{shift up}
}
Return
; Row1 Key8
; INSERT
;
MidiNoteOn15:
if (!isShift){
Send {F12}
} else {
Send {Shift down}{F12}{shift up}
}
Return
; Row2 Key1
; SHIFT
MidiNoteOn16:
isShift:=true
Return
MidiNoteOff16:
isShift:=false
Return
; Row2 Key2
; Select nearest CLIP
; Select nearest TRANSITION
MidiNoteOn17:
if (!isShift){
Send {Shift down}v{shift up}
} else {
Send v
}
Return
; Row2 Key3
; SET IN
; CLEAR IN
MidiNoteOn18:
if (!isShift){
Send i
} else {
Send {Alt down}i{Alt up}
}
Return
; Row2 Key4
; SET OUT
; CLEAR OUT
MidiNoteOn19:
if (!isShift){
Send o
} else {
Send {Alt down}o{Alt up}
}
Return
; Row2 Key5
; UNDO
; REDO
MidiNoteOn20:
if (!isShift){
Send {Ctrl down}z{Ctrl up}
} else {
Send {Ctrl down}{Shift down}z{Shift up}{Ctrl up}
}
Return
; keys JKL need to repeat
; Row2 Key6
; Reverse (J)
MidiNoteOn21:
keyrepeatJ.calledNoteOn(midi.MidiIn())
Return
MidiNoteOff21:
keyrepeatJ.calledNoteOff(midi.MidiIn())
Return
keyrepeatJfirst(midi){
Send {j down}
}
keyrepeatJrepeat(midi){
Send {j down}
}
keyrepeatJstop(midi){
Send {j up}
}
; Row2 Key7
; STOP (K)
MidiNoteOn22:
keyrepeatK.calledNoteOn(midi.MidiIn())
Return
MidiNoteOff22:
keyrepeatK.calledNoteOff(midi.MidiIn())
Return
keyrepeatKfirst(midi){
Send {k down}
}
keyrepeatKrepeat(midi){
Send {k down}
}
keyrepeatKstop(midi){
Send {k up}
}
; Row2 Key8
; Forward/PLAY (L)
MidiNoteOn23:
keyrepeatL.calledNoteOn(midi.MidiIn())
Return
MidiNoteOff23:
keyrepeatL.calledNoteOff(midi.MidiIn())
Return
keyrepeatLfirst(midi){
Send {l down}
}
keyrepeatLrepeat(midi){
Send {l down}
}
keyrepeatLstop(midi){
Send {l up}
}