tab_measures: Tabulate measure related data in the midi event data

View source: R/measures.R

tab_measuresR Documentation

Tabulate measure related data in the midi event data

Description

This function mainly adds ticks which is the absolute value of mido's time (measured in ticks) for every track. Furthermore, this absolute time value is translated to the further columns of beats (quarter notes; "b"), measures (bars; "m") and the time in seconds ("t"). The function outputs these additional columns only if they are specified in the argument columns_to_add (see details).

Usage

tab_measures(df, ticks_per_beat, columns_to_add = "b")

Arguments

df

Note event data.frame resulting of miditapyr$unnest_midi()

ticks_per_beat

integer resulting of miditapyr$mido_midi_df()

columns_to_add

Character vector of the columns to be added to the result (see section "Details"). Subset of c("m", "b", "t", "time").

Details

The function transforms the unnested midi frame by first transforming the midi time (measured in ticks passed relative to the previous event) to absolute time for every track. Also the auxiliary variable i_note is added (indexing the occurrence of each note for every track). This is needed to allow to pivot the notes to wide format and back to long with pivot_wide_notes() and pivot_long_notes().

  • m: measure (bar)

  • b: beat (quarter note)

  • t: time in seconds

Value

A data.frame with the following columns added: ticks, i_note and the columns specified in columns_to_add.

Examples

## Not run: 
mid_file_str <- system.file("extdata", "test_midi_file.mid", package = "pyramidi")
mido_mid_file <- mido$MidiFile(mid_file_str)
dfc <- miditapyr$frame_midi(mido_mid_file)
ticks_per_beat = mido_mid_file$ticks_per_beat
df <- dfc %>%
  miditapyr$unnest_midi()

## End(Not run)
## Not run: 
tab_measures(df, ticks_per_beat)

## End(Not run)

urswilke/pyramidi documentation built on March 7, 2024, 3:48 p.m.