Create melody dataframe#
To extract the melody and time in seconds (needed for animation) from the pyramidi output took only a small bit of wrangling. I used a little modulo operation so that I could pivote the notes into a wide format I could experiment with in gganimate
.
pyramidi_raw %>%
dplyr::mutate(
status = dplyr::if_else(time == 0, 'on', 'off'),
ii_note = (i_note + 1) %/% 2,
note_name = stringr::str_remove(note_name, '\\d+')
) %>% dplyr::select(ii_note, note, note_name, t, status) %>%
tidyr::pivot_wider(names_from = status, values_from = t)
readRDS(url('https://github.com/softloud/digmus/raw/main/outputs/step-output/melody_df.rds'))
ii_note | note | note_name | on | off |
---|---|---|---|---|
<dbl> | <dbl> | <chr> | <dbl> | <dbl> |
1 | 62 | D | 0.0 | 1.2 |
1 | 69 | A | 1.2 | 2.4 |
1 | 65 | F | 2.4 | 3.6 |
2 | 62 | D | 3.6 | 4.8 |
1 | 61 | C# | 4.8 | 6.0 |
3 | 62 | D | 6.0 | 6.6 |
1 | 64 | E | 6.6 | 7.2 |
2 | 65 | F | 7.2 | 8.7 |
1 | 67 | G | 8.7 | 9.0 |
3 | 65 | F | 9.0 | 9.3 |
2 | 64 | E | 9.3 | 9.6 |
4 | 62 | D | 9.6 | 10.2 |