note-coerce: Basic noteworthy strings formatting and coercion helpers

note-coerceR Documentation

Basic noteworthy strings formatting and coercion helpers

Description

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

Usage

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.

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().

Value

character

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

note-checks(), note-metadata(), note-summaries(), valid-notes()

Examples

x <- "e_2 a_, b_, c#f#a# c#'f#'a#''"
note_set_key(x, "f")
note_set_key(x, "g")
as_tick_octaves(x)
as_integer_octaves(x)
y <- as_vector_time(x)
is_vector_time(y)
is_space_time(as_space_time(y))

naturalize(x)
naturalize(x, "sharp")
sharpen_flat(x)
flatten_sharp(x)
pretty_notes(x)

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