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

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".

Value

depends on the function

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.

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))
#>          x  note chord either
#> 1       a#  TRUE FALSE  FALSE
#> 2       b_  TRUE FALSE  FALSE
#> 3       c,  TRUE FALSE  FALSE
#> 4      d''  TRUE FALSE  FALSE
#> 5       e3  TRUE FALSE  FALSE
#> 6      g_4  TRUE FALSE  FALSE
#> 7        A FALSE FALSE  FALSE
#> 8        m FALSE FALSE  FALSE
#> 9  c2e_2g2 FALSE  TRUE  FALSE
#> 10    cegh FALSE FALSE  FALSE

is_diatonic("ace ac#e d e_", "c")
#> [1]  TRUE FALSE  TRUE FALSE

x <- "a# b_ c,~ c, d'' e3 g_4 c2e_2g2"
noteworthy(x) # is it noteworthy; a validity check for any string
#> [1] TRUE
x <- as_noteworthy(x) # coerce to 'noteworthy' class, conform formatting
is_noteworthy(x) # check for 'noteworthy' class
#> [1] TRUE
x
#> <Noteworthy string>
#>   Format: space-delimited time
#>   Values: b_ b_ c,~ c, d'' e g_' <c,e_,g,>

summary(x)
#> <Noteworthy string>
#>   Timesteps: 8 (7 notes, 1 chord)
#>   Octaves: tick
#>   Accidentals: flat
#>   Format: space-delimited time
#>   Values: b_ b_ c,~ c, d'' e g_' <c,e_,g,>

x <- as_noteworthy(x, format = "vector", octaves = "integer",
                   accidentals = "flat")
x
#> <Noteworthy string>
#>   Format: vectorized time
#>   Values: b_ b_ c2~ c2 d5 e g_4 <c2e_2g2>

summary(x)
#> <Noteworthy string>
#>   Timesteps: 8 (7 notes, 1 chord)
#>   Octaves: integer
#>   Accidentals: flat
#>   Format: vectorized time
#>   Values: b_ b_ c2~ c2 d5 e g_4 <c2e_2g2>