valid-notes: Check note and chord validity

valid-notesR Documentation

Check note and chord validity

Description

Check if a string is comprised exclusively of valid note and/or chord syntax.

Usage

is_note(x, na.rm = FALSE)

is_chord(x, na.rm = FALSE)

noteworthy(x, na.rm = FALSE)

as_noteworthy(x, octaves = NULL, accidentals = NULL, format = NULL)

is_noteworthy(x)

Arguments

x

character, a noteworthy string.

na.rm

remove NAs.

octaves

NULL or character, "tick" or "integer" octave numbering in result.

accidentals

NULL or character, represent accidentals, "flat" or "sharp".

format

NULL or character, the timestep delimiter format, "space" or "vector".

Details

is_note() and is_chord() are vectorized and their positive results are mutually exclusive. noteworthy() is also vectorized and performs both checks, but it returns a scalar logical result indicating whether the entire set contains exclusively valid entries.

as_noteworthy() can be used to coerce to the noteworthy class. Coercion will fail if the string is not noteworthy. While many functions will work on simple character strings and, if their syntax is valid, coerce them to the 'noteworthy' class, it is recommended to use this class. Not all functions are so aggressive, and several generic methods are implemented for the class. It also offers its own print() and summary() methods for noteworthy strings. An added benefit to using as_noteworthy() is to conform all notes in a noteworthy string to specific formatting for accidentals and octave numbering. Functions that output a noteworthy string attach the noteworthy class.

When octaves, accidentals, and format are NULL, formatting is inferred from the noteworthy string input. When mixed formats are present, tick format is the default for octave numbering and flats are the default for accidentals.

Value

depends on the function

See Also

note-checks(), note-metadata(), note-summaries(), note-coerce()

Examples

x <- "a# b_ c, d'' e3 g_4 A m c2e_2g2 cegh" # includes invalid syntax
data.frame(
  x = strsplit(x, " ")[[1]],
  note = is_note(x),
  chord = is_chord(x),
  either = noteworthy(x))

is_diatonic("ace ac#e d e_", "c")

x <- "a# b_ c,~ c, d'' e3 g_4 c2e_2g2"
noteworthy(x) # is it noteworthy; a validity check for any string
x <- as_noteworthy(x) # coerce to 'noteworthy' class, conform formatting
is_noteworthy(x) # check for 'noteworthy' class
x

summary(x)

x <- as_noteworthy(x, format = "vector", octaves = "integer",
                   accidentals = "flat")
x

summary(x)

tabr documentation built on Sept. 12, 2024, 6:18 a.m.