intervals: Interval helpers

intervalsR Documentation

Interval helpers

Description

Helper functions for musical intervals defined by two notes.

Usage

pitch_interval(notes1, notes2, use_root = TRUE)

pitch_diff(notes, use_root = TRUE, n = 1, trim = FALSE)

scale_interval(
  notes1,
  notes2,
  use_root = TRUE,
  format = c("mmp_abb", "mmp", "ad_abb", "ad")
)

scale_diff(
  notes,
  use_root = TRUE,
  n = 1,
  trim = FALSE,
  format = c("mmp_abb", "mmp", "ad_abb", "ad")
)

tuning_intervals(tuning = "standard")

Arguments

use_root

logical, use lowest pitch in chord for pitch intervals or scale intervals between adjacent timesteps. Otherwise intervals involving chords are NA.

notes, notes1, notes2

character, a noteworthy string. notes1 and notes2 must have equal number of timesteps.

n

integer, size of lag.

trim

logical, trim the n leading NA values from lagged intervals.

format

character, format of the scale notation: major/minor/perfect, augmented/diminished, and respective abbreviations. See argument options in defaults.

tuning

character, string tuning.

Details

Numeric intervals are directional. pitch_interval() returns the signed number of semitones defining the distance between two notes. Named scale intervals are names only. Use pitch for direction.

scale_interval() returns a character string that provides the named main interval, simple or compound, defined by the two notes. This function returns NA for any uncommon out of range large interval not listed as a named interval in mainIntervals().

pitch_interval() and scale_interval() compute intervals element-wise between two noteworthy strings. pitch_diff() and scale_diff() work similarly but compute lagged intervals on the elements in notes.

Value

a musical interval, integer or character depending on the function.

See Also

mainIntervals()

Examples

pitch_interval("b", "c4")
pitch_interval("c, e_, g_, a,", "e_, g_, a, c")
pitch_interval("c r", "dfa d")
pitch_interval("c r", "dfa d", use_root = FALSE)
scale_interval("c", "e_")
scale_interval("ceg", "egd'")

x <- "a, b, c d e f g# ac'e' a c' e'"
pitch_diff(x)
pitch_diff(x, use_root = FALSE)
scale_diff(x)
scale_diff(x, n = 2, trim = TRUE, use_root = FALSE)

# Lagged intervals respect rest timesteps.
# All timestep position including rests are retained.
# But the lag-n difference skips rest entries.
x <- "a, c r r r r g"
pitch_diff(x)
scale_diff(x)
pitch_diff(x, n = 2)
scale_diff(x, n = 2)
pitch_diff(x, n = 2, trim = TRUE)
scale_diff(x, n = 2, trim = TRUE)

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