CSV Tools (synctoolbox.feature.csv_tools)¶
- synctoolbox.feature.csv_tools.df_to_pitch_features(df: DataFrame, feature_rate: float, midi_min: int = 21, midi_max: int = 108, transpose: int = 0, ignore_velocity: bool = False, ignore_percussion: bool = False, visualize: bool = False, visualization_title: str = 'Pitch features') ndarray [source]¶
Computes pitch-based features for a dataframe containing symbolic music. The resulting features have the same format as the output of ‘audio_to_pitch_features’ for audio.
- Parameters
df (pd.DataFrame) – Dataframe of symbolic music piece. Can be loaded with ‘read_csv_to_df’. WARNING! Column names are supposed to be lowercase.
feature_rate (float) – Desired features per second of the output representation
midi_min (int) – Minimum MIDI index (indices below
midi_min
are filled with zero in the output)midi_max (int) – Maximum MIDI index (indices above
midi_max
are filled with zero in the output)transpose (int) – Number of semi-tones the symbolic information should be transposed
ignore_velocity (bool) – If True, STMSP values aren’t set based on MIDI velocities, just uses 0 and 1.
ignore_percussion (bool) – Ignores percussion. If True, no features are generated for percussive events.
visualize (bool) – Set True to activate the visualization of features
visualization_title (str) – Title for the visualization plot. Only relevant if ‘visualize’ is True
- Returns
f_pitch (np.ndarray) – Matrix of size 128xN containing the extracted pitch-based features
- synctoolbox.feature.csv_tools.df_to_pitch_onset_features(df: DataFrame, midi_min: int = 21, midi_max: int = 108, transpose: int = 0, ignore_percussion: bool = False, peak_height_scale_factor: float = 1000000.0, visualize: bool = False, visualization_title: str = 'Pitch features') dict [source]¶
Computes pitch-based onset features for a dataframe containing symbolic music. The resulting features have the same format as the output of ‘audio_to_pitch_onset_features’ for audio.
- Parameters
df (pd.Dataframe) – Dataframe of symbolic music piece. Can be loaded with ‘read_csv_to_df’. WARNING! Column names are supposed to be lowercase.
midi_min (int) – Minimum MIDI index (indices below ‘midi_min’ will raise an error)
midi_max (int) – Maximum MIDI index (indices above ‘midi_max’ will raise an error)
transpose (int) – Number of semi-tones the midi information should be transposed
ignore_percussion (bool) – Ignores percussion. If True, no features are generated for percussive events.
peak_height_scale_factor (float) – Scales the midi velocity so the resulting feature values are in a similar range than the peak features from an audio file So 1e6 is more or less arbitrary.
visualize (bool) – Set True to activate the visualization of features
visualization_title (str) – Title for the visualization plot. Only relevant if ‘visualize’ is True
- Returns
f_peaks (dict) – A dictionary of onset peaks, see ‘audio_to_pitch_onset_features’ for the exact format
- synctoolbox.feature.csv_tools.midi_to_music_xml_musescore(midi_filepath: str, musescore_executable: str = 'musescore')[source]¶
Convert a midi file to a music xml score using musescore. This only works for score-based midis, not performed midis. Even for score-based midis, errors may occur. The resulting music xml should always be checked manually. For this method to work, musescore must be installed on the system.
- Parameters
midi_filepath (Path to the midi file. A corresponding .mxl file of the same name will be created in the same directory.)
musescore_executable (Path to or name of the musescore executable.)
- synctoolbox.feature.csv_tools.music_xml_to_csv_musical_time(xml, csv_filepath: str)[source]¶
Convert a music xml file to a list of note events, with starts and durations as fractions of measures, and stores it as a csv file in libfmp format.
- Parameters
xml (str or music21.stream.Score) – Either a path to a music xml file or a music21.stream.Score
csv_filepath – str Filepath to the .csv file.
- synctoolbox.feature.csv_tools.read_csv_to_df(csv_filepath: str = '', csv_delimiter: str = ';') DataFrame [source]¶
Reads .csv file containing symbolic music into a pandas DataFrame. Column names are normalized to be lower case.
- Parameters
csv_filepath (str) – Filepath to the .csv file.
csv_delimiter (str) – Delimiter of the .csv file (default: ‘;’)
- Returns
df (pd.Dataframe) – Annotations in pandas Dataframe format.