def sample_midi()

in ai-judge/inference.py [0:0]


def sample_midi(midi, offset=0, step=2, bar_num=8, bar_len=96, num_samples=1):
    '''
    Sample fixed length from midi file
    8 bars = 768 -> 1 bar = 96
    '''
    
    samples = []
    
    count = 0
    total_midi_len = len(midi)
    sample_len = bar_num * bar_len
    
    while count < num_samples:
        # Beginning timestep of new sample
        cur_begin = count * step * bar_len + offset
        if cur_begin + sample_len <= total_midi_len:
            samples.append(midi[cur_begin : cur_begin + sample_len])
            count += 1
        else:
            break
    
    return samples