Library reference¶
Submodules¶
miditapyr.mido_io module¶
-
miditapyr.mido_io.frame_midi(mid)¶ Function to create a dataframe containing the information parsed by
MidiFileParameters: mid ( MidiFile) – object of classMidiFileReturns: a dataframe, containing 3 columns: Return type: DataFrameThe 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
MidiFilein 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 ofunnest_midi()Parameters: df – Dataframe returned by unnest_midi()Returns: a dataframe, containing 3 columns Return type: DataFrameThe 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
MidiFileParameters: 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 byframe_midi()Returns: a dataframe Return type: DataFrameThe 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 offrame_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 fileParameters: - dfc (
DataFrame) – dataframe containing the meta event information returned byunnest_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
- dfc (
miditapyr.midi_frame module¶
-
class
miditapyr.midi_frame.MidiFrameNested(midi_frame_unnested=None)¶ Bases:
objectClass containing the
DataFramedfobserving an object ofMidiFrameUnnested.When the observed object
midi_frame_unnestedis updated withMidiFrameUnnested.update_unnested_mf(),midi_frame_nestedis also automatically updated withMidiFrameNested.update_mf_nested().Parameters: midi_frame_unnested – DataFrameresulting ofunnest_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:
objectClass containing the
DataFramedf.dfcan be updated withupdate_unnested_mf(). This also triggers an update of objects of the observing classMidiFrameNested.Parameters: midi_frame_raw – DataFrameresulting offrame_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:
objectStructure that reads in a midi file and has the following attributes:
Variables: - midi_file – The midi data as a
MidiFileobject. - midi_frame_raw –
DataFramereturned byframe_midi(). - midi_frame_unnested –
MidiFrameUnnestedobject (containsmidi_frame_unnested.df, aDataFramereturned byunnest_midi()). - midi_frame_nested –
MidiFrameNestedobject (containsmidi_frame_nested.df, aDataFramereturned bynest_midi()).
The dataframe
midi_frame_unnested.dfcan be manipulated with the methodupdate_unnested_mf(). This also triggers an update of the dataframemidi_frame_nested.dfwith the methodupdate_mf_nested().When
update_unnested_mf()was not called, the attributemidi_frame_nested.dfshould be identical tomidi_frame_raw. After callingupdate_unnested_mf(),midi_frame_nested.dfshould also contain the changes made tomidi_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.
- midi_file – The midi data as a