Convert a noteworthy string to a tibble data frame and include additional derivative variables.
as_music_df( notes, info = NULL, key = NULL, scale = "diatonic", chords = c("root", "list", "character"), si_format = c("mmp_abb", "mmp", "ad_abb", "ad") )
notes | character, a noteworthy string. Alternatively, a music object
or a phrase object, in which case |
---|---|
info |
|
key | character, key signature, only required for inclusion of scale degrees. |
scale | character, defaults to |
chords | character, how to structure columns containing multiple values per chord/row of data frame. See details. |
si_format | character, format for scale intervals. See
|
a tibble data frame
If info
is provided or notes
is a phrase object, the
resulting data frame also contains note durations and other info variables.
The duration
column is always included in the output even as a vector
of NA
s when info = NULL
. This makes it more explicit that a
given music data frame was generated without any time information for the
timesteps. Other note info columns are not included in this case.
For some derived column variables the root note (lowest pitch) in chord is used. This is done for pitch intervals and scale intervals between adjacent timesteps. This also occurs for scale degrees.
chord = "root"
additionally collapses columns like semitone, octave,
and frequency to the value for the root note so that all rows contain one
numeric value. chord = "list"
retains full information as list
columns. chord = "character"
collapses into strings so that values are
readily visible when printing the table, but information is not stripped and
can be recovered without recomputing from the original pitches.
x <- "a, b, c d e f g# a r ac'e' a c' e' c' r r r a" as_music_df(x, key = "c", scale = "major")#> # A tibble: 18 x 11 #> duration pitch note semitone octave freq key scale scale_deg pitch_int #> <chr> <chr> <chr> <int> <int> <dbl> <chr> <chr> <int> <int> #> 1 NA a, a 57 2 110. c major 6 NA #> 2 NA b, b 59 2 123. c major 7 2 #> 3 NA c c 48 3 131. c major 1 1 #> 4 NA d d 50 3 147. c major 2 2 #> 5 NA e e 52 3 165. c major 3 2 #> 6 NA f f 53 3 175. c major 4 1 #> 7 NA g# g# 56 3 208. c major NA 3 #> 8 NA a a 57 3 220. c major 6 1 #> 9 NA r r NA NA NA c major NA NA #> 10 NA ac'e' ace 57 3 220. c major 1 0 #> 11 NA a a 57 3 220. c major 6 0 #> 12 NA c' c 48 4 262. c major 1 3 #> 13 NA e' e 52 4 330. c major 3 4 #> 14 NA c' c 48 4 262. c major 1 -4 #> 15 NA r r NA NA NA c major NA NA #> 16 NA r r NA NA NA c major NA NA #> 17 NA r r NA NA NA c major NA NA #> 18 NA a a 57 3 220. c major 6 -3 #> # ... with 1 more variable: scale_int <chr>as_music_df(x, key = "am", scale = "harmonic_minor", si_format = "ad_abb")#> # A tibble: 18 x 11 #> duration pitch note semitone octave freq key scale scale_deg pitch_int #> <chr> <chr> <chr> <int> <int> <dbl> <chr> <chr> <int> <int> #> 1 NA a, a 57 2 110. am harm~ 1 NA #> 2 NA b, b 59 2 123. am harm~ 2 2 #> 3 NA c c 48 3 131. am harm~ 3 1 #> 4 NA d d 50 3 147. am harm~ 4 2 #> 5 NA e e 52 3 165. am harm~ 5 2 #> 6 NA f f 53 3 175. am harm~ 6 1 #> 7 NA g# g# 56 3 208. am harm~ 7 3 #> 8 NA a a 57 3 220. am harm~ 1 1 #> 9 NA r r NA NA NA am harm~ NA NA #> 10 NA ac'e' ace 57 3 220. am harm~ 3 0 #> 11 NA a a 57 3 220. am harm~ 1 0 #> 12 NA c' c 48 4 262. am harm~ 3 3 #> 13 NA e' e 52 4 330. am harm~ 5 4 #> 14 NA c' c 48 4 262. am harm~ 3 -4 #> 15 NA r r NA NA NA am harm~ NA NA #> 16 NA r r NA NA NA am harm~ NA NA #> 17 NA r r NA NA NA am harm~ NA NA #> 18 NA a a 57 3 220. am harm~ 1 -3 #> # ... with 1 more variable: scale_int <chr>a <- notate("8", "Start here.") time <- paste(a, "8^*2 16-_ 4.. 16( 16)( 2) 2 4. t8- t8 t8- 8[accent]*4 1") d1 <- as_music_df(x, time) d1#> # A tibble: 18 x 14 #> duration pitch note semitone octave freq pitch_int scale_int slur slide #> <chr> <chr> <chr> <int> <int> <dbl> <int> <chr> <chr> <lgl> #> 1 8 a, a 57 2 110. NA NA NA FALSE #> 2 8 b, b 59 2 123. 2 M2 NA FALSE #> 3 8 c c 48 3 131. 1 m2 NA FALSE #> 4 16 d d 50 3 147. 2 M2 NA FALSE #> 5 4.. e e 52 3 165. 2 M2 NA FALSE #> 6 16 f f 53 3 175. 1 m2 on FALSE #> 7 16 g# g# 56 3 208. 3 m3 hold FALSE #> 8 2 a a 57 3 220. 1 m2 off FALSE #> 9 2 r r NA NA NA NA NA NA FALSE #> 10 4. ac'e' ace 57 3 220. 0 P1 NA FALSE #> 11 t8 a a 57 3 220. 0 P1 NA TRUE #> 12 t8 c' c 48 4 262. 3 m3 NA FALSE #> 13 t8 e' e 52 4 330. 4 M3 NA TRUE #> 14 8 c' c 48 4 262. -4 M3 NA FALSE #> 15 8 r r NA NA NA NA NA NA FALSE #> 16 8 r r NA NA NA NA NA NA FALSE #> 17 8 r r NA NA NA NA NA NA FALSE #> 18 1 a a 57 3 220. -3 m3 NA FALSE #> # ... with 4 more variables: bend <lgl>, dotted <int>, articulation <chr>, #> # annotation <chr># Go directly from music object to data frame m1 <- as_music(x, time) d2 <- as_music_df(m1) identical(d1, d2)#> [1] TRUE# Go directly from phrase object to data frame p1 <- phrase("a b cgc'", "4-+ 4[accent] 2", 5) identical(as_music_df(as_music("a4-+;5 b[accent] cgc'2")), as_music_df(p1))#> [1] TRUE