The hrep R package provides utilities for representing and manipulating chord sequences for perceptually informed harmony modelling. The available representations include symbolic representations, acoustic representations, and sensory representations. Integer encodings are defined for several symbolic representations, allowing the user to efficiently express chord sequences as sequences of integers.

Installation

The hrep package may be installed from GitHub as follows:

if (!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("pmcharrison/hrep")

Example usage

Chords may be defined as sequences of integers, with each integer corresponding to a pitch or a pitch class. The following chord defines a C major triad in first inversion:

library(hrep)
x <- pi_chord(c(52, 60, 67))
print(x)
#> Pitch chord: 52 60 67

From this symbolic representation, it is possible to derive various acoustic and sensory representations, such as:

1) A wave:

plot(wave(x))

2) A sparse pitch spectrum:

plot(sparse_pi_spectrum(x))

3) A sparse pitch-class spectrum:

plot(sparse_pc_spectrum(x))

4) A smooth pitch-class spectrum:

plot(smooth_pc_spectrum(x))

Chords can be translated to various symbolic representations, which can be encoded to integer formats. For example, here we convert the chord to the pitch-class chord representation, and then encode it to an integer.

pc_chord((x))
#> Pitch-class chord: [4] 0 7
as.integer(encode(pc_chord(x)))
#> [1] 8210

Similarly, the following code expresses the chord as a pitch-class set, and then encodes the pitch-class set as an integer.

pc_set(x)
#> Pitch-class set: 0 4 7
as.integer(encode(pc_set(x)))
#> [1] 145