Helper functions for musical intervals defined by two notes.

```
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")
```

- 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.

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

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`

.

```
pitch_interval("b", "c4")
#> [1] 1
pitch_interval("c, e_, g_, a,", "e_, g_, a, c")
#> [1] 3 3 3 3
pitch_interval("c r", "dfa d")
#> [1] 2 NA
pitch_interval("c r", "dfa d", use_root = FALSE)
#> [1] NA NA
scale_interval("c", "e_")
#> [1] "m3"
scale_interval("ceg", "egd'")
#> [1] "M3"
x <- "a, b, c d e f g# ac'e' a c' e'"
pitch_diff(x)
#> [1] NA 2 1 2 2 1 3 1 0 3 4
pitch_diff(x, use_root = FALSE)
#> [1] NA 2 1 2 2 1 3 NA NA 3 4
scale_diff(x)
#> [1] NA "M2" "m2" "M2" "M2" "m2" "m3" "m2" "P1" "m3" "M3"
scale_diff(x, n = 2, trim = TRUE, use_root = FALSE)
#> [1] "m3" "m3" "M3" "m3" "M3" NA "m2" NA "P5"
# 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)
#> [1] NA 3 NA NA NA NA 7
scale_diff(x)
#> [1] NA "m3" NA NA NA NA "P5"
pitch_diff(x, n = 2)
#> [1] NA NA NA NA NA NA 10
scale_diff(x, n = 2)
#> [1] NA NA NA NA NA NA "m7"
pitch_diff(x, n = 2, trim = TRUE)
#> [1] NA NA NA NA 10
scale_diff(x, n = 2, trim = TRUE)
#> [1] NA NA NA NA "m7"
```