import pretty_midi import jsonpickle def vocal_midi2note(midi): """ """ notes=[] for note in midi: pretty_note =pretty_midi.Note(velocity=100, start=note[0], end=note[1], pitch=note[2]) notes.append(pretty_note) return notes def quantize(notes, beat_times, downbeat_start, chord_time_gap): """ 어떤 Note가 몇번째 Bar의 몇번째 timing부터 몇번째 timing까지 나타나는지를 return해서 준다. Pianoroll의 Index를 넘겨준다? 라고 생각하면 적당히 맞다. ex) 1마디가 1초인 곡에서 연주 시간이 4.25~4.75인 음이 있고, 1마디를 48분 음표까지 고려한다면 5번째 마디에 12~35까지 연주함.. 이라는 정보를 건네줌 """ first_beat = downbeat_start one_beat_time = beat_times[1]-beat_times[0] #그냥 1비트 quantize_48th_time = one_beat_time/12 beat_num = chord_time_gap//one_beat_time * 12 # 4박자 곡이면 48, 3박자 곡이면 36 -> 이거 24나오면.. 시각화 망가지겠네? max_idx=0 for note in notes: start_idx = round((note.start-downbeat_start)/quantize_48th_time) end_idx = round((note.end-downbeat_start)/quantize_48th_time) if max_idx downbeat_start: # 극초반의 일부 음표가 생략될 수도 있긴합니다. start_idx = round((note.start-downbeat_start)/quantize_48th_time) end_idx = round((note.end-downbeat_start)/quantize_48th_time) if end_idx == start_idx: end_idx+=1 note_start = start_idx * quantize_48th_time + first_beat note_end = end_idx * quantize_48th_time + first_beat note_pitch = note.pitch note_velocity = note.velocity bar_idx = int(start_idx // beat_num) bar_pos = start_idx % beat_num bar_pos_end = end_idx % beat_num # 이거 때문에, 음 길이가 한 마디를 못넘어 감 *** 예를들어 beatnum이 48이고 35~67이라 하면 35 ~ 19 되었다가 if문 타면서 35~47됨. if bar_pos_end bar_idx: bar_pos_end = (int(end_idx//beat_num) - bar_idx) * beat_num # 이제는 구현 함. 나중에 index에러 반드시 날거임 if bar_pos_end