def count_scales(): # get all scales for every root note diatonic_scales, harmonic_scales, melodic_scales, blues_scales = get_scales() scale_cntr = Counter() other_cntr = Counter() for path, subdirs, files in os.walk(song_histo_folder): for name in files: _path = path.replace('\\', '/') + '/' _name = name.replace('\\', '/') song_histo = pickle.load(open(_path + _name, 'rb')) key = mf.histo_to_key(song_histo, key_n) if key in diatonic_scales: scale_cntr['diatonic'] +=1 elif key in harmonic_scales: scale_cntr['harmonic'] +=1 elif key in melodic_scales: scale_cntr['melodic'] +=1 elif key[:-1] in blues_scales: scale_cntr['blues'] +=1 else: scale_cntr['other'] += 1 other_cntr[key] +=1 return scale_cntr, other_cntr
def count_keys(): key_cntr = Counter() for path, subdirs, files in os.walk(song_histo_folder): for name in files: _path = path.replace('\\', '/') + '/' _name = name.replace('\\', '/') song_histo = pickle.load(open(_path + _name, 'rb')) key = mf.histo_to_key(song_histo, key_n) if key in key_cntr: key_cntr[key] +=1 else: key_cntr[key] = 1 return key_cntr
def shift_midi_files(song_histo_folder,tempo_folder,shifted_folder): for path, subdirs, files in os.walk(song_histo_folder): for name in files: _path = path.replace('\\', '/') + '/' _name = name.replace('\\', '/') tempo_path = tempo_folder+_path[len(song_histo_folder):] target_path = shifted_folder+_path[len(song_histo_folder):] song_histo = pickle.load(open(_path + _name, 'rb')) key = mf.histo_to_key(song_histo, key_n) shift = get_shift(key) _name = _name[:-7] if shift != 'other': if not os.path.exists(target_path): os.makedirs(target_path) try: mf.shift_midi(shift, _name, tempo_path, target_path) except (ValueError, EOFError, IndexError, OSError, KeyError, ZeroDivisionError) as e: exception_str = 'Unexpected error in ' + name + ':\n', e, sys.exc_info()[0] print(exception_str)