Library reference

Submodules

miditapyr.mido_io module

miditapyr.mido_io.frame_midi(mid)

Function to create a dataframe containing the information parsed by MidiFile

Parameters:mid (MidiFile) – object of class MidiFile
Returns:a dataframe, containing 3 columns:
Return type:DataFrame

The function nest_midi() returns a dataframe of the same format. This dataframe contains these columns:

  • i_track: the track number
  • msg: the (meta) event information in MidiFile in a list of dictionaries
  • meta: whether the event in ‘msg’ is a mido meta event
miditapyr.mido_io.get_test_midi_file(as_string=False)
miditapyr.mido_io.nest_midi(df, repair_reticulate_conversion=False)

Function to transform the dataframe returned by unnest_midi() back to a format as in the result of unnest_midi()

Parameters:df – Dataframe returned by unnest_midi()
Returns:a dataframe, containing 3 columns
Return type:DataFrame

The function miditapyr.mido_io.frame_midi() returns a dataframe of the same format. This dataframe contains these columns:

  • i_track: the track number
  • msg: the (meta) event information in MidiFile (see here) in a list of dictionaries
  • meta: whether the event in ‘msg’ is a mido meta event
miditapyr.mido_io.split_df(df)

Function to create a tuple of 2 dataframes containing the information in MidiFile

Parameters:df – dataframe returned by unnest_midi()
Returns:a tuple of 2 dataframes, containing the meta / note information
Return type:tuple
miditapyr.mido_io.unnest_midi(dfc)

Function to transform the dataframe returned by frame_midi() in a tidy format (cf. https://r4ds.had.co.nz/tidy-data.html)

Parameters:dfc (DataFrame) – Dataframe returned by frame_midi()
Returns:a dataframe
Return type:DataFrame

The returned dataframe with the columns i_track and meta of unnest_midi(). The msg column is exploded and each key in the dicts in the msg column of frame_midi() is stored in its own column.

miditapyr.mido_io.write_midi(dfc, ticks_per_beat, filename)

Function to write midi dataframes returned by nest_midi() back to a midi file

Parameters:
  • dfc (DataFrame) – dataframe containing the meta event information returned by unnest_midi()
  • ticks_per_beat (integer) – integer containing the ticks_per_beat information in MidiFile
  • filename (string) – string containing the name of the midi file to be written

miditapyr.midi_frame module

class miditapyr.midi_frame.MidiFrameNested(midi_frame_unnested=None)

Bases: object

Class containing the DataFrame df observing an object of MidiFrameUnnested.

When the observed object midi_frame_unnested is updated with MidiFrameUnnested.update_unnested_mf(), midi_frame_nested is also automatically updated with MidiFrameNested.update_mf_nested().

Parameters:midi_frame_unnestedDataFrame resulting of unnest_midi().
calc_df(midi_frame_unnested)
df
update_mf_nested(midi_frame_unnested, unnested_mf_mod)
class miditapyr.midi_frame.MidiFrameUnnested(midi_frame_raw=None)

Bases: object

Class containing the DataFrame df.

df can be updated with update_unnested_mf(). This also triggers an update of objects of the observing class MidiFrameNested.

Parameters:midi_frame_rawDataFrame resulting of frame_midi().
calc_df(midi_frame_raw)
df
register_observer(observer)
update_unnested_mf(unnested_mf_mod)
class miditapyr.midi_frame.MidiFrames(midi_file_string=None)

Bases: object

Structure that reads in a midi file and has the following attributes:

Variables:

The dataframe midi_frame_unnested.df can be manipulated with the method update_unnested_mf(). This also triggers an update of the dataframe midi_frame_nested.df with the method update_mf_nested().

When update_unnested_mf() was not called, the attribute midi_frame_nested.df should be identical to midi_frame_raw. After calling update_unnested_mf(), midi_frame_nested.df should also contain the changes made to midi_frame_unnested.df.

You can write back the midi data to a midi file by calling the method write_file().

Parameters:midi_file_string – String containing the path to the input midi file.
calc_attributes(midi_file_string)
midi_file
midi_frame_nested
midi_frame_raw
midi_frame_unnested
write_file(out_file_string)

Write midi data back to midi file

Parameters:out_file_string – midi file path where the file should be stored.

Module contents