This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmidi_event.py
69 lines (46 loc) · 2.02 KB
/
midi_event.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
from collections import namedtuple
class MidiEvent(object):
"""Container for a MIDI message and a timing tick.
Bascially like a two-item named tuple, but we overwrite the comparison
operators, so that they (except when testing for equality) use only the
timing ticks.
"""
__slots__ = ("tick", "message")
def __init__(self, tick, message):
self.tick = tick
self.message = message
def __repr__(self):
return "@ %05i %r" % (self.tick, self.message)
def __eq__(self, other):
return self.tick == other.tick and self.message == other.message
def __lt__(self, other):
return self.tick < other.tick
def __le__(self, other):
return self.tick <= other.tick
def __gt__(self, other):
return self.tick > other.tick
def __ge__(self, other):
return self.tick >= other.tick
class SysexEvent(namedtuple("Sysex", ["type", "control", "state", "data"])):
"""Container for precessed sysEx messages from PK device.
Arguments:
type {string} -- group representation of controller (button / knob / pad),
control {int} -- parameter description,
state {int/string} -- event type (for buttons/pads: pressed or released) (default: {1}),
data {int/tuple} (optional) -- transmitted value/s (default: {None}).
Returns:
namedtuple object
"""
__slots__ = ()
def __new__(cls, type, control, state=1, data=None):
return super(SysexEvent, cls).__new__(cls, type, control, state, data)
def __eq__(self, other):
return self.control == other.control and self.state == other.state
def __lt__(self, other):
return self.control == other.control and self.data < other.data
def __le__(self, other):
return self.control == other.control and self.data <= other.data
def __gt__(self, other):
return self.control == other.control and self.data > other.data
def __ge__(self, other):
return self.control == other.control and self.data >= other.data