+ self.hard_clear_status_byte()
+
+ def handle_state(self, state, newbyte):
+ # 'newbyte' can either be:
+ # 1. Value between 0x00-0xff, deal with the byte normally.
+ # 2. Value of 'None' which means "flush any buffered data".
+ if state == 'HANDLE CHANNEL MSG':
+ self.handle_channel_msg(newbyte)
+ elif state == 'HANDLE SYSEX MSG':
+ self.handle_sysex_msg(newbyte)
+ elif state == 'HANDLE SYSCOMMON MSG':
+ self.handle_syscommon_msg(newbyte)
+ elif state == 'HANDLE SYSREALTIME MSG':
+ self.handle_sysrealtime_msg(newbyte)
+ elif state == 'BUFFER GARBAGE MSG':
+ self.handle_garbage_msg(newbyte)
+
+ def get_next_state(self, newbyte):
+ # 'newbyte' must be a valid byte between 0x00 and 0xff.
+ #
+ # Try to determine the state based off of the 'newbyte' parameter.
+ if newbyte in range(0x80, 0xef + 1):
+ return 'HANDLE CHANNEL MSG'
+ if newbyte == 0xf0:
+ return 'HANDLE SYSEX MSG'
+ if newbyte in range(0xf1, 0xf7):
+ return'HANDLE SYSCOMMON MSG'
+ if newbyte in range(0xf8, 0xff + 1):
+ return 'HANDLE SYSREALTIME MSG'
+ # Passing 0xf7 is an error; messages don't start with 0xf7.
+ if newbyte == 0xf7:
+ return 'BUFFER GARBAGE MSG'
+ # Next, base the state off of self.status_byte.
+ if self.status_byte < 0x80:
+ return 'BUFFER GARBAGE MSG'
+ return self.get_next_state(self.status_byte)