示例#1
0
def tuples_to_packets(note_on_tuples, pps):
    packets = []
    i = 0
    seq = 0
    period = (1.0/pps)*(32000)
    packets.append(ds.create_packet(0, 0, int(period) >> 5, 0))
    while (i < len(note_on_tuples)):
        filtered = [x for x in note_on_tuples if x[2] == note_on_tuples[i][2]]
        drums = 0
        for x in range(note_on_tuples[i][3]):
            packets.append(ds.create_packet(seq % 4, 0, 0, drums))
            seq += 1
        for x in filtered:
            try:
                drum_index = supported_drums.index(x[0])
                drums |= 0x1 << drum_index
            except ValueError:
                print str(x[0]) + ' is not in the list of supported MIDI drums.'
        packets.append(ds.create_packet(seq % 4, 0, 0, drums))
        seq += 1
        i += len(filtered)
    return packets