tabr (version 0.3.5)

scale-deg: Scale degrees and mappings

Description

These functions assist with mapping between scale degrees, notes and chords.

Usage

scale_degree(notes, key = "c", scale = "diatonic",
  naturalize = FALSE, roman = FALSE, ...)

scale_note(deg, key = "c", scale = "diatonic", collapse = FALSE, ...)

note_in_scale(notes, key = "c", scale = "diatonic", ...)

Arguments

notes

character, a string of notes.

key

character, key signature (or root note) for scale, depending on the type of scale.

scale

character, the suffix of a supported scale_* function.

naturalize

logical, whether to naturalize any sharps or flats before obtaiuning the scale degree.

roman

logical, return integer scale degrees as Roman numerals.

...

additional arguments passed to the scale function, e.g., sharp = FALSE for scale_chromatic.

deg

integer, roman class, or character roman, the scale degree.

collapse

logical, collapse result into a single string ready for phrase construction.

Value

integer, or roman class if roman = TRUE for scale_degree. character for scale_note.

Details

Obtain the scale degree of a note in a supported scale with scale_degree. This function also works with chords inside noteworthy strings. It only considers the first note in each space-delimited entry. notes may be a vector of single entries (non-delimited). Notes return NA if not explicitly in the scale. This includes cases where the note is in the scale but is notated as sharp or flat when the scale and/or key provide the opposite.

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.

note_in_scale performs a vectorized logical check if each note is in a given scale. This function strictly accepts single notes in noteworthy strings. To check if chords are diatonic to the scale, see chord_is_diatonic. To check generally if a noteworthy string is fully diatonic, see is_diatonic.

See Also

scale-helpers

Examples

Run this code
# NOT RUN {
scale_degree("c e g")
scale_degree("c e g", roman = TRUE)
scale_degree("c e g", key = "d")
scale_degree("c, e_3 g' f#ac#")
scale_degree("c, e_3 g' f#ac#", naturalize = TRUE)
scale_degree("c, e_3 g' f#ac#", scale = "chromatic")
scale_degree("c, e_3 g' f#ac#", scale = "chromatic", sharp = FALSE)

scale_note(1:3)
scale_note(c(1, 3, 8), "d", collapse = TRUE)
all(sapply(list(4, "IV", as.roman(4)), scale_note) == "f")
# }

Run the code above in your browser using DataLab