Example #1
0
 def file_processing(path, quantization, clip):
     reader_midi = Read_midi(path, quantization)
     # Read midi
     reader_midi.read_file()
     pianoroll = reader_midi.pianoroll
     # Clip
     if clip:
         pianoroll = clip_pr(pianoroll)
     return pianoroll, get_pianoroll_time(pianoroll)
Example #2
0
            # Little hack for a little problem i ran into :
            # harpsichord was only present as a mixed instrument in the database
            # Then it never appears in the instrument mapping though
            # it is a track name for valid names...
            if instru_name not in instru_mapping.keys():
                print instru_name + ' does not have pitch and indices ranges'
                continue
            # For pr_instrument, remove the column out of pitch_min and pitch_max
            pitch_min = instru_mapping[instru_name]['pitch_min']
            pitch_max = instru_mapping[instru_name]['pitch_max']

            # Determine thanks to instru_mapping the y_min and y_max in pr_big
            index_min = instru_mapping[instru_name]['index_min']
            index_max = instru_mapping[instru_name]['index_max']

            # Insert the small pr in the big one :)
            try:
                # Insertion is max between already written notes and new ones
                pr_big[t_min:t_max, index_min:index_max] = np.maximum(pr_big[t_min:t_max, index_min:index_max], pr_instru[:, pitch_min:pitch_max])
            except:
                import pdb; pdb.set_trace()

    return pr_big


if __name__=='__main__':
    name = 'DEBUG/test.mid'
    reader = Read_midi(name, 12)
    time = reader.get_time()
    pr = reader.read_file()
Example #3
0
def pitch_class(pr):
    nb_class = 12
    nb_pitch = pr.shape[1]
    if not nb_pitch == 128:
        raise Exception('Pitch dimension should be equal to 128')
    pr_red = np.zeros((pr.shape[0], nb_class))
    for p in range(nb_pitch):
        c = p % nb_class
        pr_red[:, c] += pr[:, p]
    # Binary
    pr_red_bin = (pr_red > 0).astype(int)
    return pr_red_bin


def extract_pianoroll_part(pianoroll, start_time, end_time):
    new_pr = {}
    # Start and end time are given in discrete frames
    for k, v in pianoroll.items():
        new_pr[k] = v[start_time:end_time]
    return new_pr


if __name__ == "__main__":
    from acidano.data_processing.midi.read_midi import Read_midi

    song_path = 'test.mid'
    midifile = Read_midi(song_path, 8)
    midifile.read_file()
    pr = midifile.pianoroll
    pr_class = pitch_class(pr)