Skip to contents

This function modifies a copy of the dataframe df by adding new columns related to time markers and bars from a metric_tibble. Rows in the dataframe are iterated upon to set values for these new columns based on matching time_steps in the metric_tibble.

Usage

add_bars_to_copy_df(df, metric_tibble)

Arguments

df

A data frame that needs additional time marker and bar related data. The columns in the data frame can vary, but must contain a 'total_time' column. Usually received from copy_and_extend_midi_df().

metric_tibble

A tibble having columns 'time_steps', 'bars', and 'bar_steps'. This tibble provides the metrics that are used to add new marker and bar data to the data frame df. Created from make_metric_tibble().

Value

A data frame which is a copy of the input data frame df, but with three additional columns: 'time_markers', 'bars', and 'bar_steps'. 'time_markers' is populated by the index of the match between the 'total_time' of df and 'time_steps' of metric_tibble. bars' and 'bar_steps' are populated from corresponding values in metric_tibble based on matching 'time_steps'.

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)
copy_track <- add_bars_to_copy_df(copy_track,metric_tibble)
}