# 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()