Skip to content

Commit 5bc88cc

Browse files
authored
Merge pull request #21 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents f873915 + 0a1196e commit 5bc88cc

23 files changed

+668
-493
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_midi/__init__.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,16 @@ class MIDI:
6868
6969
"""
7070

71-
def __init__(self, midi_in=None, midi_out=None, *,
72-
in_channel=None, out_channel=0, in_buf_size=30, debug=False):
71+
def __init__(
72+
self,
73+
midi_in=None,
74+
midi_out=None,
75+
*,
76+
in_channel=None,
77+
out_channel=0,
78+
in_buf_size=30,
79+
debug=False
80+
):
7381
if midi_in is None and midi_out is None:
7482
raise ValueError("No midi_in or midi_out provided")
7583
self._midi_in = midi_in
@@ -135,8 +143,9 @@ def receive(self):
135143
self._in_buf.extend(bytes_in)
136144
del bytes_in
137145

138-
(msg, endplusone,
139-
skipped) = MIDIMessage.from_message_bytes(self._in_buf, self._in_channel)
146+
(msg, endplusone, skipped) = MIDIMessage.from_message_bytes(
147+
self._in_buf, self._in_channel
148+
)
140149
if endplusone != 0:
141150
# This is not particularly efficient as it's copying most of bytearray
142151
# and deleting old one

adafruit_midi/channel_pressure.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class ChannelPressure(MIDIMessage):
4545
:param int pressure: The pressure, 0-127.
4646
"""
4747

48-
_STATUS = 0xd0
49-
_STATUSMASK = 0xf0
48+
_STATUS = 0xD0
49+
_STATUSMASK = 0xF0
5050
LENGTH = 2
5151

5252
def __init__(self, pressure, *, channel=None):
@@ -56,11 +56,11 @@ def __init__(self, pressure, *, channel=None):
5656
raise self._EX_VALUEERROR_OOR
5757

5858
def __bytes__(self):
59-
return bytes([self._STATUS | (self.channel & self.CHANNELMASK),
60-
self.pressure])
59+
return bytes([self._STATUS | (self.channel & self.CHANNELMASK), self.pressure])
6160

6261
@classmethod
6362
def from_bytes(cls, msg_bytes):
6463
return cls(msg_bytes[1], channel=msg_bytes[0] & cls.CHANNELMASK)
6564

65+
6666
ChannelPressure.register_message_type()

adafruit_midi/control_change.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class ControlChange(MIDIMessage):
4747
4848
"""
4949

50-
_STATUS = 0xb0
51-
_STATUSMASK = 0xf0
50+
_STATUS = 0xB0
51+
_STATUSMASK = 0xF0
5252
LENGTH = 3
5353

5454
def __init__(self, control, value, *, channel=None):
@@ -59,12 +59,13 @@ def __init__(self, control, value, *, channel=None):
5959
raise self._EX_VALUEERROR_OOR
6060

6161
def __bytes__(self):
62-
return bytes([self._STATUS | (self.channel & self.CHANNELMASK),
63-
self.control, self.value])
62+
return bytes(
63+
[self._STATUS | (self.channel & self.CHANNELMASK), self.control, self.value]
64+
)
6465

6566
@classmethod
6667
def from_bytes(cls, msg_bytes):
67-
return cls(msg_bytes[1], msg_bytes[2],
68-
channel=msg_bytes[0] & cls.CHANNELMASK)
68+
return cls(msg_bytes[1], msg_bytes[2], channel=msg_bytes[0] & cls.CHANNELMASK)
69+
6970

7071
ControlChange.register_message_type()

adafruit_midi/midi_message.py

+40-34
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,12 @@ def note_parser(note):
8080
if not 0 <= noteidx <= 6:
8181
raise ValueError("Bad note")
8282
sharpen = 0
83-
if note[1] == '#':
83+
if note[1] == "#":
8484
sharpen = 1
85-
elif note[1] == 'b':
85+
elif note[1] == "b":
8686
sharpen = -1
8787
# int may throw exception here
88-
midi_note = (int(note[1 + abs(sharpen):]) * 12
89-
+ NOTE_OFFSET[noteidx]
90-
+ sharpen)
88+
midi_note = int(note[1 + abs(sharpen) :]) * 12 + NOTE_OFFSET[noteidx] + sharpen
9189

9290
return midi_note
9391

@@ -108,10 +106,11 @@ class MIDIMessage:
108106
109107
This is an *abstract* class.
110108
"""
109+
111110
_STATUS = None
112111
_STATUSMASK = None
113112
LENGTH = None
114-
CHANNELMASK = 0x0f
113+
CHANNELMASK = 0x0F
115114
ENDSTATUS = None
116115

117116
# Commonly used exceptions to save memory
@@ -150,9 +149,9 @@ def register_message_type(cls):
150149
insert_idx = idx
151150
break
152151

153-
MIDIMessage._statusandmask_to_class.insert(insert_idx,
154-
((cls._STATUS, cls._STATUSMASK), cls))
155-
152+
MIDIMessage._statusandmask_to_class.insert(
153+
insert_idx, ((cls._STATUS, cls._STATUSMASK), cls)
154+
)
156155

157156
# pylint: disable=too-many-arguments
158157
@classmethod
@@ -171,8 +170,7 @@ def _search_eom_status(cls, buf, eom_status, msgstartidx, msgendidxplusone, endi
171170
else:
172171
bad_termination = True
173172
break
174-
else:
175-
msgendidxplusone += 1
173+
msgendidxplusone += 1
176174

177175
if good_termination or bad_termination:
178176
msgendidxplusone += 1
@@ -199,22 +197,27 @@ def _match_message_status(cls, buf, msgstartidx, msgendidxplusone, endidx):
199197
break
200198

201199
if msgclass.LENGTH < 0: # indicator of variable length message
202-
(msgendidxplusone,
203-
terminated_msg,
204-
bad_termination) = cls._search_eom_status(buf,
205-
msgclass.ENDSTATUS,
206-
msgstartidx,
207-
msgendidxplusone,
208-
endidx)
200+
(
201+
msgendidxplusone,
202+
terminated_msg,
203+
bad_termination,
204+
) = cls._search_eom_status(
205+
buf, msgclass.ENDSTATUS, msgstartidx, msgendidxplusone, endidx
206+
)
209207
if not terminated_msg:
210208
complete_msg = False
211-
else: # fixed length message
209+
else: # fixed length message
212210
msgendidxplusone = msgstartidx + msgclass.LENGTH
213211
break
214212

215-
return (msgclass, status,
216-
known_msg, complete_msg, bad_termination,
217-
msgendidxplusone)
213+
return (
214+
msgclass,
215+
status,
216+
known_msg,
217+
complete_msg,
218+
bad_termination,
219+
msgendidxplusone,
220+
)
218221

219222
# pylint: disable=too-many-locals,too-many-branches
220223
@classmethod
@@ -247,23 +250,24 @@ def from_message_bytes(cls, midibytes, channel_in):
247250
return (None, endidx + 1, skipped)
248251

249252
# Try and match the status byte found in midibytes
250-
(msgclass,
251-
status,
252-
known_message,
253-
complete_message,
254-
bad_termination,
255-
msgendidxplusone) = cls._match_message_status(midibytes,
256-
msgstartidx,
257-
msgendidxplusone,
258-
endidx)
253+
(
254+
msgclass,
255+
status,
256+
known_message,
257+
complete_message,
258+
bad_termination,
259+
msgendidxplusone,
260+
) = cls._match_message_status(
261+
midibytes, msgstartidx, msgendidxplusone, endidx
262+
)
259263
channel_match_orna = True
260264
if complete_message and not bad_termination:
261265
try:
262266
msg = msgclass.from_bytes(midibytes[msgstartidx:msgendidxplusone])
263267
if msg.channel is not None:
264268
channel_match_orna = channel_filter(msg.channel, channel_in)
265269

266-
except(ValueError, TypeError) as ex:
270+
except (ValueError, TypeError) as ex:
267271
msg = MIDIBadEvent(midibytes[msgstartidx:msgendidxplusone], ex)
268272

269273
# break out of while loop for a complete message on good channel
@@ -272,8 +276,8 @@ def from_message_bytes(cls, midibytes, channel_in):
272276
if complete_message:
273277
if channel_match_orna:
274278
break
275-
else: # advance to next message
276-
msgstartidx = msgendidxplusone
279+
# advance to next message
280+
msgstartidx = msgendidxplusone
277281
else:
278282
# Important case of a known message but one that is not
279283
# yet complete - leave bytes in buffer and wait for more
@@ -314,6 +318,7 @@ class MIDIUnknownEvent(MIDIMessage):
314318
This can either occur because there is no class representing the message
315319
or because it is not imported.
316320
"""
321+
317322
LENGTH = -1
318323

319324
def __init__(self, status):
@@ -331,6 +336,7 @@ class MIDIBadEvent(MIDIMessage):
331336
This could be due to status bytes appearing where data bytes are expected.
332337
The channel property will not be set.
333338
"""
339+
334340
LENGTH = -1
335341

336342
def __init__(self, msg_bytes, exception):

adafruit_midi/note_off.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class NoteOff(MIDIMessage):
4949
"""
5050

5151
_STATUS = 0x80
52-
_STATUSMASK = 0xf0
52+
_STATUSMASK = 0xF0
5353
LENGTH = 3
5454

5555
def __init__(self, note, velocity=0, *, channel=None):
@@ -60,12 +60,13 @@ def __init__(self, note, velocity=0, *, channel=None):
6060
raise self._EX_VALUEERROR_OOR
6161

6262
def __bytes__(self):
63-
return bytes([self._STATUS | (self.channel & self.CHANNELMASK),
64-
self.note, self.velocity])
63+
return bytes(
64+
[self._STATUS | (self.channel & self.CHANNELMASK), self.note, self.velocity]
65+
)
6566

6667
@classmethod
6768
def from_bytes(cls, msg_bytes):
68-
return cls(msg_bytes[1], msg_bytes[2],
69-
channel=msg_bytes[0] & cls.CHANNELMASK)
69+
return cls(msg_bytes[1], msg_bytes[2], channel=msg_bytes[0] & cls.CHANNELMASK)
70+
7071

7172
NoteOff.register_message_type()

adafruit_midi/note_on.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class NoteOn(MIDIMessage):
4949
"""
5050

5151
_STATUS = 0x90
52-
_STATUSMASK = 0xf0
52+
_STATUSMASK = 0xF0
5353
LENGTH = 3
5454

5555
def __init__(self, note, velocity=127, *, channel=None):
@@ -60,12 +60,13 @@ def __init__(self, note, velocity=127, *, channel=None):
6060
raise self._EX_VALUEERROR_OOR
6161

6262
def __bytes__(self):
63-
return bytes([self._STATUS | (self.channel & self.CHANNELMASK),
64-
self.note, self.velocity])
63+
return bytes(
64+
[self._STATUS | (self.channel & self.CHANNELMASK), self.note, self.velocity]
65+
)
6566

6667
@classmethod
6768
def from_bytes(cls, msg_bytes):
68-
return cls(msg_bytes[1], msg_bytes[2],
69-
channel=msg_bytes[0] & cls.CHANNELMASK)
69+
return cls(msg_bytes[1], msg_bytes[2], channel=msg_bytes[0] & cls.CHANNELMASK)
70+
7071

7172
NoteOn.register_message_type()

adafruit_midi/pitch_bend.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class PitchBend(MIDIMessage):
4646
bend from 0 through 8192 (midpoint, no bend) to 16383.
4747
"""
4848

49-
_STATUS = 0xe0
50-
_STATUSMASK = 0xf0
49+
_STATUS = 0xE0
50+
_STATUSMASK = 0xF0
5151
LENGTH = 3
5252

5353
def __init__(self, pitch_bend, *, channel=None):
@@ -57,13 +57,19 @@ def __init__(self, pitch_bend, *, channel=None):
5757
raise self._EX_VALUEERROR_OOR
5858

5959
def __bytes__(self):
60-
return bytes([self._STATUS | (self.channel & self.CHANNELMASK),
61-
self.pitch_bend & 0x7f,
62-
(self.pitch_bend >> 7) & 0x7f])
60+
return bytes(
61+
[
62+
self._STATUS | (self.channel & self.CHANNELMASK),
63+
self.pitch_bend & 0x7F,
64+
(self.pitch_bend >> 7) & 0x7F,
65+
]
66+
)
6367

6468
@classmethod
6569
def from_bytes(cls, msg_bytes):
66-
return cls(msg_bytes[2] << 7 | msg_bytes[1],
67-
channel=msg_bytes[0] & cls.CHANNELMASK)
70+
return cls(
71+
msg_bytes[2] << 7 | msg_bytes[1], channel=msg_bytes[0] & cls.CHANNELMASK
72+
)
73+
6874

6975
PitchBend.register_message_type()

adafruit_midi/polyphonic_key_pressure.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class PolyphonicKeyPressure(MIDIMessage):
4747
:param int pressure: The pressure, 0-127.
4848
"""
4949

50-
_STATUS = 0xa0
51-
_STATUSMASK = 0xf0
50+
_STATUS = 0xA0
51+
_STATUSMASK = 0xF0
5252
LENGTH = 3
5353

5454
def __init__(self, note, pressure, *, channel=None):
@@ -59,12 +59,13 @@ def __init__(self, note, pressure, *, channel=None):
5959
raise self._EX_VALUEERROR_OOR
6060

6161
def __bytes__(self):
62-
return bytes([self._STATUS | (self.channel & self.CHANNELMASK),
63-
self.note, self.pressure])
62+
return bytes(
63+
[self._STATUS | (self.channel & self.CHANNELMASK), self.note, self.pressure]
64+
)
6465

6566
@classmethod
6667
def from_bytes(cls, msg_bytes):
67-
return cls(msg_bytes[1], msg_bytes[2],
68-
channel=msg_bytes[0] & cls.CHANNELMASK)
68+
return cls(msg_bytes[1], msg_bytes[2], channel=msg_bytes[0] & cls.CHANNELMASK)
69+
6970

7071
PolyphonicKeyPressure.register_message_type()

adafruit_midi/program_change.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class ProgramChange(MIDIMessage):
4545
:param int patch: The new program/patch number to use, 0-127.
4646
"""
4747

48-
_STATUS = 0xc0
49-
_STATUSMASK = 0xf0
48+
_STATUS = 0xC0
49+
_STATUSMASK = 0xF0
5050
LENGTH = 2
5151

5252
def __init__(self, patch, *, channel=None):
@@ -56,11 +56,11 @@ def __init__(self, patch, *, channel=None):
5656
raise self._EX_VALUEERROR_OOR
5757

5858
def __bytes__(self):
59-
return bytes([self._STATUS | (self.channel & self.CHANNELMASK),
60-
self.patch])
59+
return bytes([self._STATUS | (self.channel & self.CHANNELMASK), self.patch])
6160

6261
@classmethod
6362
def from_bytes(cls, msg_bytes):
6463
return cls(msg_bytes[1], channel=msg_bytes[0] & cls.CHANNELMASK)
6564

65+
6666
ProgramChange.register_message_type()

0 commit comments

Comments
 (0)