def handle(self): while True: self.data = self.rfile.readline() # DO NOT REMOVE '\n' print("Data is {}.".format(self.data)) if self.data == b'': # Connection reset by peer print('Connection reset by peer.') return self.data = self.data.strip(b'\n') # REMOVE '\n' if self.data == b'': # Empty Line break if self.data == b'\x1b': # ESC break print("From {0}, Received: '{1}'.".format(self.client_address, self.data)) try: mydata = self.data.decode('UTF-8') # 1-8 except UnicodeDecodeError: # Not valid unicode(utf-8) input continue try: intdata = int(mydata) except ValueError: # Not valid value continue if intdata >= 1 and intdata <= 9: # valid playing data keyboardplay.kp_play_note_once(intdata) if intdata == 0: # 0 Will be omitted as a testing for connectivity print('Testing 9 received, ignoring...') print('Connection closed by me.') return
def _playWrapper(self, playplan_fragment, schedule): """ A Wrapper to play notes. Will check for stop_flag and cancel all jobs if flag is set. """ keyboardplay.kp_play_note_once(eval(playplan_fragment["note"])) if self.stop_flag == True: # Cancel future jobs for i in schedule.queue: schedule.cancel(i)
def play(self): print("Now i have {}.".format(self.playplan)) for i in self.playplan: keyboardplay.kp_play_note_once(i["note"]) time.sleep(i["time"]) return