forked from MaddyGuthridge/Novation-LaunchKey-Mk2-Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_LaunchKey_extension.py
167 lines (122 loc) · 4.41 KB
/
device_LaunchKey_extension.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# name=LaunchKey Mk2 Extension
# url=https://forum.image-line.com/viewtopic.php?f=1994&t=231871
# receiveFrom=LaunchKey Mk2
"""
device_LaunchKey_extension.py
This file is the controller file for port 2 of the LaunchKey Mk2.
It handles communication with the device, including colours.
Author: Miguel Guthridge [hdsq@outlook.com.au]
"""
#-------------------------------
# Edit this file at your own risk. All user-modifyable variables are found in 'config.py'.
#-------------------------------
import patterns
import channels
import mixer
import device
import transport
import arrangement
import general
import launchMapPages
import playlist
import ui
import screen
import midi
import utils
import time
# Other project files
import config
import internal
import internal.consts
import lighting
import eventconsts
import eventprocessor
import processorhelpers
initialisation_flag = False
initialisation_flag_response = False
class TGeneric():
def __init__(self):
return
def OnInit(self):
try:
if internal.state.SHARED_INIT_STATE is internal.consts.INIT_INCOMPLETE:
# Run shared init functions
internal.sharedInit()
# Set the device into Extended Mode
internal.extendedMode.setVal(True, force=True)
# Process inControl preferences | Say it's external since we want the settings to be applied regardless
if config.START_IN_INCONTROL_KNOBS == False: internal.extendedMode.setVal(False, eventconsts.INCONTROL_KNOBS, from_internal=False)
if config.START_IN_INCONTROL_FADERS == False: internal.extendedMode.setVal(False, eventconsts.INCONTROL_FADERS, from_internal=False)
if config.START_IN_INCONTROL_PADS == False: internal.extendedMode.setVal(False, eventconsts.INCONTROL_PADS, from_internal=False)
except Exception as e:
internal.errors.triggerError(e)
print('Initialisation complete')
print(internal.getLineBreak())
print(internal.getLineBreak())
print("")
print("")
def OnDeInit(self):
try:
# Return the device into Basic Mode
internal.extendedMode.setVal(False)
print('Deinitialisation complete')
print(internal.getLineBreak())
print(internal.getLineBreak())
print("")
print("")
except Exception as e:
internal.errors.triggerError(e)
def OnMidiIn(self, event):
event.handled = False
internal.performance.eventClock.start()
# Update active window (ui.onRefresh() isnt working properly)
internal.ActiveWindow = ui.getFocusedFormCaption()
# Process the event into ParsedEvent format
command = processorhelpers.ParsedEvent(event)
# Print event before processing
internal.printCommand(command)
# Check for shift button releases (return early)
if event.handled:
internal.printCommandOutput(command)
return
# Process command
eventprocessor.processExtended(command)
# If command was edited, update event object
if command.edited:
event.status = command.status
event.data1 = command.note
event.data2 = command.value
internal.performance.eventClock.stop()
# Print output of command
internal.printCommandOutput(command)
event.handled = True
def OnIdle(self):
internal.idleProcessor()
eventprocessor.redraw()
return
def OnRefresh(self, flags):
internal.refreshProcessor()
# Prevent idle lightshow when other parts of FL are being used
internal.window.resetIdleTick()
return
def OnUpdateBeatIndicator(self, beat):
eventprocessor.beatChange(beat)
# Prevent idle lightshow from being triggered during playback
internal.window.resetIdleTick()
def OnSendTempMsg(self, msg, duration):
internal.window.resetIdleTick()
Generic = TGeneric()
def OnInit():
Generic.OnInit()
def OnDeInit():
Generic.OnDeInit()
def OnMidiIn(event):
Generic.OnMidiIn(event)
def OnIdle():
Generic.OnIdle()
def OnRefresh(flags):
Generic.OnRefresh(flags)
def OnUpdateBeatIndicator(beat):
Generic.OnUpdateBeatIndicator(beat)
def OnSendTempMsg(msg, duration):
Generic.OnSendTempMsg(msg, duration)