@@ -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 ):
0 commit comments