Create a dataframe with helpful timing metrics from a midi_df
Source:R/transform.R
make_metric_tibble.Rd
Create a dataframe with helpful timing metrics from a midi_df
Arguments
- df
A dataframe containing at least a 'time' column and a 'total_time' column. Usually the df from
copy_and_extend_midi_df()
- ticks_per_beat
Integer specifying the number of ticks per beat
- bars
Integer specifying the number of bars. If this parameter is NULL, it will compute it assuming 4/4 meter. Default is NULL.
- smallest_tick
Numeric. This is the smallest unit of time (in beats) represented in the output dataframe. If NULL, it will compute the smallest observed unit in the 'time' column. Default is NULL.
Value
A dataframe where each row represents one 'tick' (i.e., fundamental temporal unit), and columns represent the 'tick' timestamp (time_steps), its corresponding bar number (bars), and its step within the bar (bar_steps).
Details
MIDI files contain minimal timing information. This function computes additional timing metrics from a midi_df
that are useful for later transformations.
MIDI files and the the midi_df
imported by pyramidi::miditapyr$MidiFrames()
represent timing information in terms of relative time since the last message, not cumulative time. Messages in a MIDI file are ordered in chronological time. The first message sent occurs at tick 0. If the next message occurred 30 ticks later, its time would be recorded as 30. If the next message was 5 ticks later, its time would be recorded as 5. If another message was to be sent at the same time, it would be recorded in the next message with a time of 0, relative to the last message. MIDI files have a ticks per beat parameter. For example, one beat (or quarter note in 4/4 time) could have 96 MIDI ticks. It is possible to increase the resolution so that a single beat is given additional ticks.
This function attempts to compute additional timing information in a new tibble, such as cumulative ticks, bars, and intervals within a bar. This tibble can be joined to a midi_df to aid with various transformation tasks.
Examples
if (FALSE) {
copy_track <- copy_and_extend_midi_df(midi_df, track_num = 0)
metric_tibble <- make_metric_tibble(copy_track, ticks_per_beat = 96, bars=48,smallest_tick=8)
}