Module Mu.Pitch

Pitches.

Absolute pitch

type abs = int

The type for absolute pitches in semitones on a chromatic 12-tone scale. The absolute pitch of middle C (C4) is 60. Constrained to the range [0;127] these values correspond to MIDI notes.

type rel = int

The type for relative pitches. This is an absolute pitch difference.

module Abs : sig ... end

Absolute pitches.

Pitch classes

module Class : sig ... end

Pitch classes.

Pitches

type octave = int

The type for octave numbers. Octave number 4 corresponds to the octave of middle C (C4).

type t = Class.t * octave

The type for pitches. A pitch class and an octave.

  • (`A, 4) is A440.
  • (`A, 0) to (`C, 8) is the range of a piano.
  • (`C, -1) to (`G, 9) is the the MIDI note range.
val a440 : t

a440 is (`A, 4), the standard pitch A440.

val midi_min : t

midi_min is (`C, -1), the lowest MIDI note.

val midi_max : t

midi_max is (`G, 9), the highest MIDI note.

Operations

val transp : rel -> t -> t

transp r p transposes pitch p by r relative semitones.

val succ : t -> t

succ p is transp 1 p.

val pred : t -> t

pred p is transp (-1) p.

Predicates and comparisons

val equal : t -> t -> bool

equal p0 p1 is true iff p0 and p1 have the same absolute pitch.

val compare : t -> t -> int

compare p0 p1 is a total order on pitches compatible with equal.

Converting

val to_abs : t -> abs

to_abs p is the absolute pitch of p.

val of_abs : abs -> t

of_abs ap is a pitch for the absolute pitch of ap.

Formatting

val pp : Stdlib.Format.formatter -> t -> unit

pp formats pitches.