def load_label(self, file_path, sample_rate=44100): midi = pretty_midi.PrettyMIDI(file_path) content = [] last_sec = 0 for inst in midi.instruments: inst_num = inst.program for note in inst.notes: cc = LabelFmt(note.start, note.end, note.pitch, inst_num) content.append(cc) last_sec = max(last_sec, note.end) return content, last_sec
def load_label_midi(self, file_path, **kwargs): midi = pretty_midi.PrettyMIDI(file_path) inst = midi.instruments[0] content = [] last_sec = 0 for note in inst.notes: onset = note.start offset = note.end pitch = note.pitch content.append(LabelFmt(onset, offset, pitch)) last_sec = max(last_sec, offset) return content, last_sec
def load_label(self, file_path, **kwargs): midi = pretty_midi.PrettyMIDI(file_path) inst = midi.instruments[0] # Assumed there only exits piano contents = [] last_sec = 0 for note in inst.notes: onset = note.start offset = note.end pitch = note.pitch contents.append(LabelFmt(onset, offset, pitch)) last_sec = max(last_sec, offset) return contents, last_sec
def load_label(self, file_path, sample_rate=44100): with open(file_path, "r") as ll_file: lines = ll_file.readlines() content = [] last_sec = 0 for i in range(1, len(lines)): if lines[i].strip() == "": continue onset, offset, note = lines[i].split("\t") onset, offset, note = float(onset), float(offset), int(note.strip()) content.append(LabelFmt(onset, offset, note)) last_sec = max(last_sec, offset) return content, last_sec
def load_label(self, file_path, sample_rate=44100): content = [] last_sec = 0 with open(file_path, 'r') as f: reader = csv.DictReader(f, delimiter=',') max_sample = 0 for label in reader: start_time = float(label['start_time']) / sample_rate end_time = float(label['end_time']) / sample_rate instrument = int(label['instrument']) note = int(label['note']) start_beat = float(label['start_beat']) end_beat = float(label['end_beat']) note_value = label['note_value'] cc = LabelFmt(start_time, end_time, note, instrument, start_beat, end_beat, note_value) content.append(cc) last_sec = max(last_sec, end_time) return content, last_sec