| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 
 | import time
 
 import mido
 from mido import MidiFile
 
 from serial_communication import SerialCommunication
 
 
 
 
 key_dict = {
 
 24: 'Z',
 
 26: 'X',
 
 28: 'C',
 29: 'V',
 
 31: 'B',
 
 33: 'M',
 
 35: 'N',
 36: 'Z',
 
 38: 'X',
 
 40: 'C',
 41: 'V',
 
 43: 'B',
 
 45: 'M',
 
 47: 'N',
 48: 'A',
 
 50: 'S',
 
 52: 'D',
 53: 'F',
 
 55: 'G',
 
 57: 'H',
 
 59: 'J',
 60: 'Q',
 
 62: 'W',
 
 64: 'E',
 65: 'R',
 
 67: 'T',
 
 69: 'Y',
 
 71: 'U',
 72: 'Q',
 
 74: 'W',
 
 76: 'E',
 77: 'R',
 
 79: 'T',
 
 81: 'Y',
 
 83: 'U',
 84: 'A',
 
 86: 'S',
 88: 'D',
 89: 'F',
 
 91: 'G',
 93: 'H',
 94: 'J',
 
 }
 
 if __name__ == '__main__':
 virtual_key_board = SerialCommunication("COM17", 115200, 1)
 mid = MidiFile("input_mid.mid")
 tempo = mido.bpm2tempo(131)
 time.sleep(3)
 unsupport = set()
 for i, track in enumerate(mid.tracks):
 print('Track {}: {}'.format(i, track.name))
 passed_time = 0
 for msg in track:
 ab_time = mido.tick2second(msg.time, mid.ticks_per_beat, tempo)
 real_time = ab_time + passed_time
 passed_time += ab_time
 
 if msg.type == "note_on":
 if msg.note in key_dict.keys():
 virtual_key_board.execute(key_dict[msg.note])
 pass
 else:
 unsupport.add(str(msg.note))
 print("skip note:{}".format(msg.note))
 time.sleep(msg.time*0.001)
 print(unsupport)
 
 
 |