Helper functions for setting formatting attributes of noteworthy strings including representation of timesteps, octaves and accidentals.

naturalize(notes, type = c("both", "flat", "sharp"))

sharpen_flat(notes)

flatten_sharp(notes)

note_set_key(notes, key = "c")

as_tick_octaves(notes)

as_integer_octaves(notes)

as_space_time(x)

as_vector_time(x)

pretty_notes(notes, ignore_octave = TRUE)

Arguments

notes

character, a noteworthy string, space-delimited or vector of individual entries.

type

character, type of note to naturalize.

key

character, key signature to coerce any accidentals to the appropriate form for the key. May also specify "sharp" or "flat".

x

for generic functions: notes, info or music string.

ignore_octave

logical, strip any octave notation that may be present, returning only the basic notes without explicit pitch.

Value

character

Details

For sharpen_flat and flatten_sharp, sharpening flats and flattening sharps refer to inverting their respective notation, not to raising or lowering a flatted or sharped note by one semitone. For the latter, use naturalize, which removes flat and/or sharp notation from a string. note_set_key is used for coercing a noteworthy string to a specific and consistent notation for accidentals based on a key signature. This is a wrapper around sharpen_flat and flatten_sharp. as_tick_octaves, as_integer_octaves, as_space_time and as_vector_time similarly affect octave and timestep format. For simultaneous control over the representation of timesteps, octave numbering and accidentals, all three are available as arguments to as_noteworthy.

A note on generic functions

as_space_time and as_vector_time are generic since they apply clearly to and are useful for not only noteworthy strings, but also note info and music objects. If x is still a simple character string, these functions attempt to guess which of the three it is. It is recommended to set the class before using these functions.

There are many package functions that operate on noteworthy strings that could in concept work on music objects, but the expectation is that sound and time/info are disentangled. The music class is convenient for data entry, e.g., for transcription purposes, but it is not sensible to perform data analysis with quantities like pitch and time tightly bound together. This would only lead to repetitive deconstructions and reconstructions of music class objects. Most functions that operate on noteworthy strings or note info strings strictly apply to one or the other. Generic functions are reserved for only the most fundamental and generally applicable metadata retrieval and format coercion.

See also

Examples

x <- "e_2 a_, b_, c#f#a# c#'f#'a#''" note_set_key(x, "f")
#> <Noteworthy string> #> Format: space-delimited time #> Values: e_, a_, b_, <d_g_b_> <d_'g_'b_''>
note_set_key(x, "g")
#> <Noteworthy string> #> Format: space-delimited time #> Values: d#, g#, a#, <c#f#a#> <c#'f#'a#''>
as_tick_octaves(x)
#> <Noteworthy string> #> Format: space-delimited time #> Values: e_, a_, b_, <d_g_b_> <d_'g_'b_''>
as_integer_octaves(x)
#> <Noteworthy string> #> Format: space-delimited time #> Values: e_2 a_2 b_2 <d_g_b_> <d_4g_4b_5>
y <- as_vector_time(x) is_vector_time(y)
#> [1] TRUE
is_space_time(as_space_time(y))
#> [1] TRUE
naturalize(x)
#> <Noteworthy string> #> Format: space-delimited time #> Values: e, a, b, <cfa> <c'f'a''>
naturalize(x, "sharp")
#> <Noteworthy string> #> Format: space-delimited time #> Values: e_, a_, b_, <cfa> <c'f'a''>
sharpen_flat(x)
#> <Noteworthy string> #> Format: space-delimited time #> Values: d#, g#, a#, <c#f#a#> <c#'f#'a#''>
flatten_sharp(x)
#> <Noteworthy string> #> Format: space-delimited time #> Values: e_, a_, b_, <d_g_b_> <d_'g_'b_''>
pretty_notes(x)
#> [1] "Eb Ab Bb C#F#A# C#F#A#"