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
MidiFile
Parameters: mid ( MidiFile
) – object of classMidiFile
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)¶ 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 MidiFile
object, defaults to FalseReturns: file path or as a MidiFile
Return 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_on
ornote_off
) &df_notes
- (allnote_on
ornote_off
events).
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: 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.
pivot_notes_long
(dfw)¶ Write
note_on
andnote_off
events 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_on
ornote_off
events.Return type: DataFrame
-
miditapyr.mido_io.
pivot_notes_wide
(df_notes)¶ Write
note_on
andnote_off
events 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_on
ornote_off
events.Return type: DataFrame
-
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.
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_on
ornote_off
) &df_notes
- (allnote_on
ornote_off
events).
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: 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 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:
object
Class containing the
DataFrame
df
observing an object ofMidiFrameUnnested
.When the observed object
midi_frame_unnested
is updated withMidiFrameUnnested.update_unnested_mf()
,midi_frame_nested
is also automatically updated withMidiFrameNested.update_mf_nested()
.Parameters: midi_frame_unnested – DataFrame
resulting 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:
object
Class containing the
DataFrame
df
.df
can be updated withupdate_unnested_mf()
. This also triggers an update of objects of the observing classMidiFrameNested
.Parameters: midi_frame_raw – DataFrame
resulting 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:
object
Structure that reads in a midi file and has the following attributes:
Variables: - midi_file – The midi data as a
MidiFile
object. - midi_frame_raw –
DataFrame
returned byframe_midi()
. - midi_frame_unnested –
MidiFrameUnnested
object (containsmidi_frame_unnested.df
, aDataFrame
returned byunnest_midi()
). - midi_frame_nested –
MidiFrameNested
object (containsmidi_frame_nested.df
, aDataFrame
returned bynest_midi()
).
The dataframe
midi_frame_unnested.df
can be manipulated with the methodupdate_unnested_mf()
. This also triggers an update of the dataframemidi_frame_nested.df
with the methodupdate_mf_nested()
.When
update_unnested_mf()
was not called, the attributemidi_frame_nested.df
should be identical tomidi_frame_raw
. After callingupdate_unnested_mf()
,midi_frame_nested.df
should 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