def process(msd_id: str, counter: AtomicCounter) -> Optional[dict]: """ Processes the given MSD id and increments the counter. The method will call the get_tags and the extract_pianos method and write the resulting MIDI files to disk. :param msd_id: the MSD id to process :param counter: the counter to increment :return: the dictionary containing the MSD id, the PrettyMIDI pianos and the matching tags, raises an exception if the file cannot be processed """ try: with tables.open_file(msd_id_to_h5(msd_id, args.path_dataset_dir)) as h5: tags = get_tags(h5) matching_tags = [tag for tag in tags if tag in TAGS] if not matching_tags: return pm_pianos = extract_pianos(msd_id) for index, pm_piano in enumerate(pm_pianos): pm_piano.write( os.path.join(args.path_output_dir, f"{msd_id}_{index}.mid")) return { "msd_id": msd_id, "pm_pianos": pm_pianos, "tags": matching_tags } except Exception as e: print(f"Exception during processing of {msd_id}: {e}") finally: counter.increment()
def process(msd_id: str, counter: AtomicCounter) -> Optional[dict]: """ Processes the given MSD id and increments the counter. The method will find and return the artist. :param msd_id: the MSD id to process :param counter: the counter to increment :return: the dictionary containing the MSD id and the artist, raises an exception if the file cannot be processed """ try: with tables.open_file(msd_id_to_h5(msd_id, args.path_dataset_dir)) as h5: artist = h5.root.metadata.songs.cols.artist_name[0].decode("utf-8") return {"msd_id": msd_id, "artist": artist} except Exception as e: print(f"Exception during processing of {msd_id}: {e}") finally: counter.increment()
def process(msd_id: str, counter: AtomicCounter) -> Optional[dict]: """ Processes the given MSD id and increments the counter. The method will call the get_instrument_classes method. :param msd_id: the MSD id to process :param counter: the counter to increment :return: the dictionary containing the MSD id and the classes, raises an exception if the file cannot be processed """ try: with tables.open_file(msd_id_to_h5(msd_id, args.path_dataset_dir)) as h5: classes = get_instrument_classes(msd_id) return {"msd_id": msd_id, "classes": classes} except Exception as e: print(f"Exception during processing of {msd_id}: {e}") finally: counter.increment()
def process(msd_id: str, counter: AtomicCounter) -> Optional[dict]: """ Processes the given MSD id and increments the counter. The method will call the extract_drums method and write the resulting MIDI files to disk. :param msd_id: the MSD id to process :param counter: the counter to increment :return: the dictionary containing the MSD id and the PrettyMIDI drums; raises an exception if the file cannot be processed """ try: with tables.open_file(msd_id_to_h5(msd_id, args.path_dataset_dir)) as h5: pm_drums = extract_drums(msd_id) pm_drums.write(os.path.join(args.path_output_dir, f"{msd_id}.mid")) return {"msd_id": msd_id, "pm_drums": pm_drums} except Exception as e: print(f"Exception during processing of {msd_id}: {e}") finally: counter.increment()