-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdevice_arturia_keylab_mkii.py
73 lines (54 loc) · 2.46 KB
/
device_arturia_keylab_mkii.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
# name=Arturia Keylab mkII DAW (MIDIIN2/MIDIOUT2)
# url=https://github.com/rjuang/flstudio-arturia-keylab-mk2
# receiveFrom=Arturia Keylab mkII (MIDI)
import version
from arturia import ArturiaController
from arturia_processor import ArturiaMidiProcessor
import arturia_midi
import config
import ui
WELCOME_DISPLAY_INTERVAL_MS = 1500
# --------------------[ Global state for MIDI Script ] ------------------------------------------
_controller = ArturiaController()
_processor = ArturiaMidiProcessor(_controller)
_payload_buffer = []
# --------------------[ MIDI Script Integration Events for FL Studio ]---------------------------
def OnInit():
global _controller
print('Loaded MIDI script for Arturia Keylab mkII (ver %d)' % version.CHANGE_DATE)
_controller.Sync(0xFFFF)
_controller.paged_display().SetPageLines('welcome', line1='Connected to ', line2=' FL Studio')
_controller.paged_display().SetActivePage('main')
_controller.paged_display().SetActivePage('welcome', expires=WELCOME_DISPLAY_INTERVAL_MS)
ui.setHintMsg('Script version: %d' % version.CHANGE_DATE)
def OnDeInit():
print('Unloading plugin...')
def OnIdle():
_controller.Idle()
def OnMidiMsg(event):
global _payload_buffer, _processor
if event.status == arturia_midi.INTER_SCRIPT_STATUS_BYTE:
if event.data1 == arturia_midi.INTER_SCRIPT_DATA1_BEGIN_PAYLOAD_CMD:
_payload_buffer = []
elif event.data1 == arturia_midi.INTER_SCRIPT_DATA1_END_PAYLOAD_CMD:
arturia_midi.send_to_device(_payload_buffer)
_payload_buffer = []
elif event.data1 == arturia_midi.INTER_SCRIPT_DATA1_UPDATE_STATE:
if event.data2 == arturia_midi.INTER_SCRIPT_DATA2_STATE_PAD_RECORD_START:
_processor.NotifyPadRecordingState(True)
elif event.data2 == arturia_midi.INTER_SCRIPT_DATA2_STATE_PAD_RECORD_STOP:
_processor.NotifyPadRecordingState(False)
elif event.data2 == arturia_midi.INTER_SCRIPT_DATA2_STATE_IDLE_AVAILABLE:
_controller.DisableInterscriptIdle()
event.handled = True
elif event.status == arturia_midi.PAYLOAD_STATUS_BYTE:
_payload_buffer.append(event.data1)
_payload_buffer.append(event.data2)
event.handled = True
else:
_processor.ProcessEvent(event)
_controller.RefreshDisplay()
def OnRefresh(flags):
_controller.Sync(flags)
def OnUpdateBeatIndicator(value):
_controller.metronome().ProcessBeat(value)