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 example | type | printed representation |
---|---|---|
midi(15) | MidiInterval | i15 |
midic(15) | MidiIC | ic3 |
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.MidiInterval
— TypeMidiInterval <: Interval
Intervals represented as chromatic integers. 60
is Middle C.
Pitches.MidiIC
— TypeMidiIC <: IntervalClass
Interval classes represented as cromatic integers in Z_12, where 0
is C.
Constructors
Pitches.midi
— Functionmidi(interval)
Creates a MidiInterval
from an integer.
Pitches.midic
— Functionmidic(interval)
Creates a MidiIC
from an integer.
Pitches.midip
— Functionmidip(n)
Creates a midi pitch (Pitch{MidiInterval}
) from an integer.
Pitches.midipc
— Functionmidipc(n)
Creates a midi pitch class (Pitch{MidiIC}
) from an integer.
Pitches.@midi
— Macro@midi expr
Replaces all Int
s 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.
Pitches.@midic
— Macro@midic expr
Replaces all Int
s 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.
Pitches.@midip
— Macro@midip expr
Replaces all Int
s 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.
Pitches.@midipc
— Macro@midipc expr
Replaces all Int
s 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.
Conversion
Pitches.tomidi
— Functiontomidi(i [, ...])
tomidi(p [, ...])
Converts a pitch or interval to the corresponding midi type. Depending on the input type, this might require additional parameters.