MIDI Pitch

Overview

MIDI pitches and intervals are specified in 12-TET semitones, with 60 as Middle C. Both MIDI pitches and intervals can be represented by integers. However, we provides lightweight wrapper types around Int to distinguish the different interpretations as pitches and intervals (and their respective class variants). Midi pitches can be easily created using the midi* constructors, all of which take integers.

constructor exampletypeprinted representation
midi(15)MidiIntervali15
midic(15)MidiICic3
midip(60)Pitch{MidiInterval}p60
midipc(60)Pitch{MidiIC}pc0

For quick experiments on the REPL, using these constructors every time can be cumbersome. For those cases, we provide a set of macros with the same names at the constructors that turn all integer literals in the subsequent expression into the respective pitch or interval type. You can use parentheses to limit the scope of the macros.

julia> @midi [1,2,3], [2,3,4]
(MidiInterval[i1, i2, i3], MidiInterval[i2, i3, i4])

julia> @midi([1,2,3]), [2,3,4]
(MidiInterval[i1, i2, i3], [2, 3, 4])

julia> (@midi [1,2,3]), [2,3,4]
(MidiInterval[i1, i2, i3], [2, 3, 4])

Reference

Types

Pitches.MidiICType
MidiIC <: IntervalClass

Interval classes represented as cromatic integers in Z_12, where 0 is C.

source

Constructors

Pitches.midipFunction
midip(n)

Creates a midi pitch (Pitch{MidiInterval}) from an integer.

source
Pitches.midipcFunction
midipc(n)

Creates a midi pitch class (Pitch{MidiIC}) from an integer.

source
Pitches.@midiMacro
@midi expr

Replaces all Ints in expr with a call to midi(::Int). This allows the user to write integers where midi intervals are required. Does not work when expr contains integers that should not be converted or intervals that are not written as literal integers.

source
Pitches.@midicMacro
@midic expr

Replaces all Ints in expr with a call to midi(::Int). This allows the user to write integers where midi intervals are required. Does not work when expr contains integers that should not be converted or intervals that are not written as literal integers.

source
Pitches.@midipMacro
@midip expr

Replaces all Ints in expr with a call to midip(::Int). This allows the user to write integers where midi intervals are required. Does not work when expr contains integers that should not be converted or intervals that are not written as literal integers.

source
Pitches.@midipcMacro
@midipc expr

Replaces all Ints in expr with a call to midipc(::Int). This allows the user to write integers where midi intervals are required. Does not work when expr contains integers that should not be converted or intervals that are not written as literal integers.

source

Conversion

Pitches.tomidiFunction
tomidi(i [, ...])
tomidi(p [, ...])

Converts a pitch or interval to the corresponding midi type. Depending on the input type, this might require additional parameters.

source