Learn R Programming

tabr (version 0.3.0)

note-helpers: Note and pitch helpers

Description

Helper functions for manipulating individual note and pitch strings.

Usage

note_is_natural(notes)

note_is_accidental(notes)

note_is_flat(notes)

note_is_sharp(notes)

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

sharpen_flat(notes, ignore_octave = FALSE)

flatten_sharp(notes, ignore_octave = FALSE)

note_set_key(notes, key = "c")

note_rotate(notes, n = 0)

note_shift(notes, n = 0)

note_arpeggiate(notes, n = 0, ...)

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.

ignore_octave

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

key

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

n

integer, degree of rotation.

...

additional arguments to transpose, specifically key and style.

Value

character

Details

In this context, sharpening flats and flattening sharps refers to inverting their notation, not raising and lowering a flatted or sharped note by one semitone. For the latter, use naturalize, which removes flat and/or sharp notation from a string.

Due to its simplicity, for note_rotate the strings may include chords. It simply rotates anything space-delimited or vectorized in place. Octave numbering is ignored if present.

By contrast, for note_shift the entire sequence is shifted up or down, as if inverting a broken chord. In this case notes is strictly interpreted and may not include chords. Octave numbering applies, though large, multi-octave gaps will be condensed in the process. Given the context of note_shift, the notes sequence should be ordered by increasing pitch. If it is not, ordering will be forced with each inversion during the n shifts.

note_arpeggiate also allows notes only. It is similar to note_shift, except that instead of a moving window, it grows from the original set of notes by n in the direction of the sign of n.

Examples

Run this code
# NOT RUN {
x <- "a_ a a#"
note_is_natural(x)
note_is_accidental(x)
note_is_flat(x)
note_is_sharp(x)
note_set_key(x, "f")
note_set_key(x, "g")

x <- "e_2 a_, c#f#a#"
naturalize(x)
naturalize(x, "sharp")
sharpen_flat(x)
flatten_sharp(x)
pretty_notes(x)

note_rotate(x, 1)
note_shift("c e g", 1)
note_shift("c e g", -4)
note_arpeggiate("c e g", 5)
note_arpeggiate("c e g", -5)
# }

Run the code above in your browser using DataLab