@@ -80,14 +80,12 @@ def note_parser(note):
80
80
if not 0 <= noteidx <= 6 :
81
81
raise ValueError ("Bad note" )
82
82
sharpen = 0
83
- if note [1 ] == '#' :
83
+ if note [1 ] == "#" :
84
84
sharpen = 1
85
- elif note [1 ] == 'b' :
85
+ elif note [1 ] == "b" :
86
86
sharpen = - 1
87
87
# 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
91
89
92
90
return midi_note
93
91
@@ -108,10 +106,11 @@ class MIDIMessage:
108
106
109
107
This is an *abstract* class.
110
108
"""
109
+
111
110
_STATUS = None
112
111
_STATUSMASK = None
113
112
LENGTH = None
114
- CHANNELMASK = 0x0f
113
+ CHANNELMASK = 0x0F
115
114
ENDSTATUS = None
116
115
117
116
# Commonly used exceptions to save memory
@@ -150,9 +149,9 @@ def register_message_type(cls):
150
149
insert_idx = idx
151
150
break
152
151
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
+ )
156
155
157
156
# pylint: disable=too-many-arguments
158
157
@classmethod
@@ -171,8 +170,7 @@ def _search_eom_status(cls, buf, eom_status, msgstartidx, msgendidxplusone, endi
171
170
else :
172
171
bad_termination = True
173
172
break
174
- else :
175
- msgendidxplusone += 1
173
+ msgendidxplusone += 1
176
174
177
175
if good_termination or bad_termination :
178
176
msgendidxplusone += 1
@@ -199,22 +197,27 @@ def _match_message_status(cls, buf, msgstartidx, msgendidxplusone, endidx):
199
197
break
200
198
201
199
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
+ )
209
207
if not terminated_msg :
210
208
complete_msg = False
211
- else : # fixed length message
209
+ else : # fixed length message
212
210
msgendidxplusone = msgstartidx + msgclass .LENGTH
213
211
break
214
212
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
+ )
218
221
219
222
# pylint: disable=too-many-locals,too-many-branches
220
223
@classmethod
@@ -247,23 +250,24 @@ def from_message_bytes(cls, midibytes, channel_in):
247
250
return (None , endidx + 1 , skipped )
248
251
249
252
# 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
+ )
259
263
channel_match_orna = True
260
264
if complete_message and not bad_termination :
261
265
try :
262
266
msg = msgclass .from_bytes (midibytes [msgstartidx :msgendidxplusone ])
263
267
if msg .channel is not None :
264
268
channel_match_orna = channel_filter (msg .channel , channel_in )
265
269
266
- except (ValueError , TypeError ) as ex :
270
+ except (ValueError , TypeError ) as ex :
267
271
msg = MIDIBadEvent (midibytes [msgstartidx :msgendidxplusone ], ex )
268
272
269
273
# break out of while loop for a complete message on good channel
@@ -272,8 +276,8 @@ def from_message_bytes(cls, midibytes, channel_in):
272
276
if complete_message :
273
277
if channel_match_orna :
274
278
break
275
- else : # advance to next message
276
- msgstartidx = msgendidxplusone
279
+ # advance to next message
280
+ msgstartidx = msgendidxplusone
277
281
else :
278
282
# Important case of a known message but one that is not
279
283
# yet complete - leave bytes in buffer and wait for more
@@ -314,6 +318,7 @@ class MIDIUnknownEvent(MIDIMessage):
314
318
This can either occur because there is no class representing the message
315
319
or because it is not imported.
316
320
"""
321
+
317
322
LENGTH = - 1
318
323
319
324
def __init__ (self , status ):
@@ -331,6 +336,7 @@ class MIDIBadEvent(MIDIMessage):
331
336
This could be due to status bytes appearing where data bytes are expected.
332
337
The channel property will not be set.
333
338
"""
339
+
334
340
LENGTH = - 1
335
341
336
342
def __init__ (self , msg_bytes , exception ):
0 commit comments