Library reference¶
Submodules¶
miditapyr.mido_io module¶
-
miditapyr.mido_io.add_abs_time(df)¶ Add a column of absolute time
Parameters: df ( DataFrame) – unnested midi frameReturns: Dataframe with absolute time column ‘t’ added. Return type: DataFrame
-
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)¶ Get the example midi file included in the
Parameters: as_string (bool, optional) – Should the midi file be returned as a file path or as a MidiFileobject, defaults to FalseReturns: file path or as a MidiFileReturn type: file path or as a MidiFile
-
miditapyr.mido_io.merge_midi_frames(df_meta, df_not_notes, df_notes)¶ Merge dataframes resulting of
split_midi_frame().df_meta- (containing all mido meta events),
df_not_notes- (non-meta events that are notnote_onornote_off) &df_notes- (allnote_onornote_offevents).
Parameters: Returns: unnested midi frame
Return type:
-
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.pivot_notes_long(dfw)¶ Write
note_onandnote_offevents in two lines (wide to long)Parameters: dfw ( DataFrame) – Transforms notes in wide dataframe format to long format.Returns: Dataframe with twice the number of rows, where the time & velocity columns occur in two rows for all note_onornote_offevents.Return type: DataFrame
-
miditapyr.mido_io.pivot_notes_wide(df_notes)¶ Write
note_onandnote_offevents in the same line (long to wide)Parameters: df_notes ( DataFrame) – Notes dataframe fromsplit_midi_frame()Returns: Dataframe with half the number of rows, but the time & velocity columns occur twice for all note_onornote_offevents.Return type: DataFrame
-
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.split_midi_frame(df_unnested)¶ Split unnested midi frame into 3 dataframes.
Parameters: df_unnested ( DataFrame) – result ofunnest_midi()Returns: (tuple) of 3 dataframes df_meta, df_not_notes & df_notes df_meta- (containing all mido meta events),df_not_notes- (non-meta events that are notnote_onornote_off) &df_notes- (allnote_onornote_offevents).
Return type: tuple of 3 DataFrame
-
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