Representing harmony with the hrep package
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.
- Function-level documentation
- File an issue
- Music corpora
- Models of simultaneous consonance
- Automatic voicing of chord sequences
The hrep package may be installed from GitHub as follows:
if (!requireNamespace("devtools")) install.packages("devtools") devtools::install_github("pmcharrison/hrep")
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:
- A wave:
- A sparse pitch spectrum:
- A sparse pitch-class spectrum:
- A smooth pitch-class spectrum:
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:  0 7 as.integer(encode(pc_chord(x))) #>  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))) #>  145