These functions assist with mapping between scale degrees, notes and chords.
scale_degree(
notes,
key = "c",
scale = "diatonic",
use_root = TRUE,
strict_accidentals = TRUE,
naturalize = FALSE,
roman = FALSE
)
scale_note(deg, key = "c", scale = "diatonic", collapse = FALSE, ...)
note_in_scale(
notes,
key = "c",
scale = "diatonic",
use_root = TRUE,
strict_accidentals = TRUE
)
chord_degree(
notes,
key = "c",
scale = "diatonic",
strict_accidentals = TRUE,
naturalize = FALSE,
roman = FALSE
)
is_in_scale(notes, key = "c", scale = "diatonic", strict_accidentals = TRUE)
character, a string of notes.
character, key signature (or root note) for scale, depending on
the type of scale
.
character, the suffix of a supported scale_*
function.
logical, use lowest pitch in chord. Otherwise yield an
NA
in output.
logical, whether representation must match key and scale. See details.
logical, whether to naturalize any sharps or flats before obtaiuning the scale degree.
logical, return integer scale degrees as Roman numerals.
integer, roman class, or character roman, the scale degree.
logical, collapse result into a single string ready for phrase construction.
additional arguments passed to the scale function, e.g.,
sharp = FALSE
for scale_chromatic()
.
integer, or roman class if roman = TRUE
for scale_degree()
;
character for scale_note()
.
Obtain the scale degree of a note in a supported scale with scale_degree()
.
This function works on any noteworthy string. It ignores octave numbering.
Rests and any note not explicitly in the scale return NA
. If deg
is
greater than the number of degrees in the scale, it is recycled, e.g., in C
major 8 starts over as C.
By default, flats and sharps checked strictly against the scale. Setting
strict_accidentals = FALSE
will convert any flats or sharps present,
if necessary based on the combination of key
signature and
scale
. The chromatic scale is a special case where strict accidental
is always ignored.
Not any arbitrary combination of valid key
and valid scale
is valid. For
example, key = "am"
and scale = "harmonic"
is valid, but not with
key = "a"
.
note_in_scale()
is a wrapper around scale_degree()
. To check if full
chords are diatonic to the scale, see is_diatonic()
.
The inverse of scale_degree()
is scale_note()
, for obtaining the note
associated with a scale degree. This could be done simply by calling a
scale_*
function and indexing its output directly, but this wrapper is
provided to complement scale_degree()
.
Additionally, it accepts the common Roman numeral input for the degree.
This can be with the roman
class or as a character string.
Degrees return NA
if outside the scale degree range.
scale_degree("r c, e3 g~ g s g# ceg")
#> [1] NA 1 3 5 5 NA NA 1
note_in_scale("r c, e3 g~ g s g# ceg")
#> [1] NA TRUE TRUE TRUE TRUE NA FALSE TRUE
scale_degree("c e g", roman = TRUE)
#> [1] I III V
scale_degree("c c# d_ e", key = "d")
#> [1] NA 7 NA 2
scale_degree("c c# d_ e", key = "d", strict_accidentals = FALSE)
#> [1] NA 7 7 2
scale_degree("c, e_3 g' f#ac#", use_root = FALSE)
#> [1] 1 NA 5 NA
scale_degree("c, e_3 g' f#ac#", naturalize = TRUE) # lowest chord pitch: c#
#> [1] 1 3 5 1
scale_degree("c# d_ e_' e4 f f# g", key = "c#", scale = "chromatic")
#> [1] 1 1 3 4 5 6 7
scale_note(1:3, key = "am")
#> <Noteworthy string>
#> Format: vectorized time
#> Values: a b c
scale_note(c(1, 3, 8), "d", collapse = TRUE)
#> <Noteworthy string>
#> Format: space-delimited time
#> Values: d f# d
all(sapply(list(4, "IV", as.roman(4)), scale_note) == "f")
#> [1] TRUE
x <- "d dfa df#a f#ac#"
chord_degree(x, "d")
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 1 NA 5
#>
#> [[3]]
#> [1] 1 3 5
#>
#> [[4]]
#> [1] 3 5 7
#>
is_in_scale(x, "d")
#> [1] TRUE FALSE TRUE TRUE