-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdevice_universal.py
75 lines (58 loc) · 2.06 KB
/
device_universal.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
# name=Universal Controller
# url=https://github.com/MiguelGuthridge/Universal-Controller-Script
# receiveFrom=Universal Event Forwarder
"""device_universal.py
The entrypoint for the universal controller script.
It is responsible for event parsing, forwarding, script initialisation, and
contains a context object used throughout the script.
This entire script is licensed under GPL v3. Refer to the `LICENSE` file for a
full copy.
Refer to module `common.consts` for a list of authors for the project
"""
# Add our additional includes to the Python environment
import include
# Get context, and context reset wrapper
from common import getContext, catchContextResetException, getVersionString
# Function to allow user to reset context
from common.contextmanager import unsafeResetContext as reset
# Import constants and logger
from common import consts, log, verbosity, ExtensionManager
# Import verbosities
from common.logger.verbosity import *
# Import console helpers
from common.util.consolehelpers import *
class OverallDevice:
@catchContextResetException
def onInit(self) -> None:
getContext().initialise()
@catchContextResetException
def onMidiIn(self, event) -> None:
getContext().processEvent(event)
@catchContextResetException
def onIdle(self) -> None:
getContext().tick()
@catchContextResetException
def bootstrap(self):
log("bootstrap.initialize", "Load success", verbosity.INFO)
print(consts.ASCII_HEADER_ART)
print(f"Universal Controller Script: v{getVersionString()}")
print(ExtensionManager.getInfo())
print("Type `help` for help using the script\n")
device = OverallDevice()
def OnInit():
device.onInit()
def OnMidiIn(event):
device.onMidiIn(event)
idle_uncalled = True
def OnIdle():
global idle_uncalled
if idle_uncalled:
log("device.idle", "OnIdle() called", verbosity.INFO)
idle_uncalled = False
device.onIdle()
def OnRefresh(flags: int):
device.onIdle()
def bootstrap():
device.bootstrap()
if __name__ == "__main__":
bootstrap()