Utilities to convert from ground-truth¶
-
asmd.convert_from_file.
_sort_lists
(*lists)[source]¶ Sort multiple lists in-place with reference to the first one
-
asmd.convert_from_file.
change_ext
(input_fn, new_ext, no_dot=False, remove_player=False)[source]¶ Return the input path input_fn with new_ext as extension and the part after the last ‘-’ removed. If no_dot is True, it will not add a dot before of the extension, otherwise it will add it if not present. remove_player can be used to remove the name of the player in the last part of the file name when: use this for the traditional_flute dataset; it will remove the last part after ‘_’.
-
asmd.convert_from_file.
convert
(exts, no_dot=True, remove_player=False)[source]¶ This function is designed to be used as decorators for functions which converts from a filetype to our JSON format.
Example of usage:
>>> @convert(['.myext'], no_dot=True, remove_player=False) ... def function_which_converts(...): ... pass
Parameters: - ext (*) – the possible extensions of the ground-truths to be converted, e.g. [‘.mid’, ‘.midi’]. You can also use this parameter to remove exceeding parts at the end of the filename (see from_bach10_mat and from_bach10_f0 source code)
- no_dot (*) – if True, don’t add a dot before of the extension, if False, add it if not present; this is useful if you are using the extension to remove other parts in the file name (see ext).
- remove_player (*) – if True, remove the name of the player in the last part of the file name: use this for the traditional_flute dataset; it will remove the part after the last ‘_’.
-
asmd.convert_from_file.
from_bach10_f0
(nmat_fn, sources=range(0, 4))[source]¶ Open a matlab mat file nmat_fn in the MIREX format (Bach10) for frame evaluation and convert it to our ground_truth representation. This fills: f0. sources is an iterable containing the indices of the sources to be considered, where the first source is 0. Returns a list of dictionary, one per source.
-
asmd.convert_from_file.
from_bach10_mat
(mat_fn, sources=range(0, 4))[source]¶ Open a txt file txt_fn in the MIREX format (Bach10) and convert it to our ground_truth representation. This fills: precise_alignment, pitches. sources is an iterable containing the indices of the sources to be considered, where the first source is 0. Returns a list of dictionary, one per source.
-
asmd.convert_from_file.
from_midi
(midi_fn, alignment='precise_alignment', pitches=True, velocities=True, merge=True, beats=False)[source]¶ Open a midi file midi_fn and convert it to our ground_truth representation. This fills velocities, pitches, beats, sustain, soft, sostenuto and alignment (default: precise_alignment). Returns a list containing a dictionary. alignment can also be None or False, in that case no alignment is filled. If merge is True, the returned list will contain a dictionary for each track. Beats are filled according to tempo changes.
This functions is decorated with 3 different sets of parameters:
- from_midi is the decorated version with remove_player=False
- from_midi_remove_player is the decorated version with remove_player=True
- from_midi_asap is the decorated version which accept extension ‘.score.mid’ which is used in the script to import scores from ASAP
N.B. To allow having some annotation for subgroups of a dataset, this function returns None when it cannot find the specified midi file; in this way, that file is not taken into account while merging the various annotations (e.g. asap group inside Maestro dataset)
-
asmd.convert_from_file.
from_midi_asap
(midi_fn, alignment='precise_alignment', pitches=True, velocities=True, merge=True, beats=False)¶ Open a midi file midi_fn and convert it to our ground_truth representation. This fills velocities, pitches, beats, sustain, soft, sostenuto and alignment (default: precise_alignment). Returns a list containing a dictionary. alignment can also be None or False, in that case no alignment is filled. If merge is True, the returned list will contain a dictionary for each track. Beats are filled according to tempo changes.
This functions is decorated with 3 different sets of parameters:
- from_midi is the decorated version with remove_player=False
- from_midi_remove_player is the decorated version with remove_player=True
- from_midi_asap is the decorated version which accept extension ‘.score.mid’ which is used in the script to import scores from ASAP
N.B. To allow having some annotation for subgroups of a dataset, this function returns None when it cannot find the specified midi file; in this way, that file is not taken into account while merging the various annotations (e.g. asap group inside Maestro dataset)
-
asmd.convert_from_file.
from_midi_remove_player
(midi_fn, alignment='precise_alignment', pitches=True, velocities=True, merge=True, beats=False)¶ Open a midi file midi_fn and convert it to our ground_truth representation. This fills velocities, pitches, beats, sustain, soft, sostenuto and alignment (default: precise_alignment). Returns a list containing a dictionary. alignment can also be None or False, in that case no alignment is filled. If merge is True, the returned list will contain a dictionary for each track. Beats are filled according to tempo changes.
This functions is decorated with 3 different sets of parameters:
- from_midi is the decorated version with remove_player=False
- from_midi_remove_player is the decorated version with remove_player=True
- from_midi_asap is the decorated version which accept extension ‘.score.mid’ which is used in the script to import scores from ASAP
N.B. To allow having some annotation for subgroups of a dataset, this function returns None when it cannot find the specified midi file; in this way, that file is not taken into account while merging the various annotations (e.g. asap group inside Maestro dataset)
-
asmd.convert_from_file.
from_musicnet_csv
(csv_fn, sr=44100.0)[source]¶ Open a csv file csv_fn and convert it to our ground_truth representation. This fills: broad_alignment, score, pitches. This returns a list containing only one dict. sr is the samplerate of the audio files (MusicNet csv contains the sample number as onset and offsets of each note) and it shold be a float.
N.B. MusicNet contains wav files at 44100 Hz as samplerate. N.B. Lowest in pitch in musicnet is 21, so we assume that they count pitch starting with 0 as in midi.org standard. N.B. score times are provided with BPM 60 for all the scores
-
asmd.convert_from_file.
from_phenicx_txt
(txt_fn)[source]¶ Open a txt file txt_fn in the PHENICX format and convert it to our ground_truth representation. This fills: broad_alignment.
-
asmd.convert_from_file.
from_sonic_visualizer
(gt_fn, alignment='precise_alignment')[source]¶ Takes a filename of a sonic visualizer output file exported as ‘csv’ and fills the ‘alignment’ specified
-
asmd.convert_from_file.
prototype_gt
= {'broad_alignment': {'notes': [], 'offsets': [], 'onsets': [], 'pitches': [], 'velocities': []}, 'extra': [], 'f0': [], 'instrument': 255, 'misaligned': {'notes': [], 'offsets': [], 'onsets': [], 'pitches': [], 'velocities': []}, 'missing': [], 'precise_alignment': {'notes': [], 'offsets': [], 'onsets': [], 'pitches': [], 'velocities': []}, 'score': {'beats': [], 'notes': [], 'offsets': [], 'onsets': [], 'pitches': [], 'velocities': []}, 'soft': {'times': [], 'values': []}, 'sostenuto': {'times': [], 'values': []}, 'sustain': {'times': [], 'values': []}}¶ The dictionary prototype for containing the ground_truth. use:
>>> from copy import deepcopy ... from convert_from_file import prototype_gt ... prototype_gt = deepcopy(prototype_gt)
>>> prototype_gt { "precise_alignment": { "onsets": [], "offsets": [], "pitches": [], "notes": [], "velocities": [] }, "misaligned": { "onsets": [], "offsets": [], "pitches": [], "notes": [], "velocities": [] }, "score": { "onsets": [], "offsets": [], "pitches": [], "notes": [], "velocities": [], "beats": [] }, "broad_alignment": { "onsets": [], "offsets": [], "pitches": [], "notes": [], "velocities": [] }, "f0": [], "soft": { "values": [], "times": [] }, "sostenuto": { "values": [], "times": [] }, "sustain": { "values": [], "times": [] }, "instrument": 255, }
Note:
pitches
,velocities
,sustain
,sostenuto
,soft
, and (if available)instrument
must be in range [0, 128)