README.md

Representing harmony with the hrep package

lifecycle Travis build
status AppVeyor build
status Coverage
status DOI

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.

Resources

Installation

The hrep package may be installed from GitHub as follows:

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

Some functions require SoX to be installed. On MacOS you can use Homebrew to install SoX by running the following command:

brew install sox

Your RStudio installation may not recognise SoX by default because it does not have Homebrew on its path. To fix this, open /etc/paths:

sudo nano /etc/paths

and add the Homebrew directory as a new line to this file:

/opt/homebrew/bin 

Then restart RStudio. You can verify that SoX is recognised by running this in your R terminal:

system("sox help")

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


pmcharrison/hrep documentation built on Feb. 18, 2024, 2:33 a.m.