MusicPitch[p]
returns a musical pitch parsed from the pitch specification p.
MusicPitch[p,properties]
returns a musical pitch with the specified property association properties.
MusicPitch[music,p,properties]
returns a musical pitch with properties inherited from another musical pitch music.
MusicPitch
MusicPitch[p]
returns a musical pitch parsed from the pitch specification p.
MusicPitch[p,properties]
returns a musical pitch with the specified property association properties.
MusicPitch[music,p,properties]
returns a musical pitch with properties inherited from another musical pitch music.
Details
- MusicPitch represents a pitch symbolically, with information such as pitch class, octave and frequency, for pitch manipulation, comparison and computation.
- MusicPitch is used to represent the pitch of MusicNote, MusicChord and MusicScale objects.
- The pitch p can be specified using:
-
name a string represanting a named pitch (e.g. "C4") int an integer representing a MIDI pitch (middle C is 60) freq a frequency Quantity (with unit compatible to "Hz") sound a SoundNote object note a MusicNote object - The association properties can contain the following keys:
-
"Accidental" alteration in semitones given as an integer or name "CentDeviation" deviation from an equal temperament pitch in cents "Frequency" frequency in Hertz "Key" named key without accidental "MIDINumber" MIDI pitch value "Name" pitch name including key and accidental "NameWithOctave" pitch name including key, accidental and octave "Octave" octave number in scientific pitch notation "PitchClass" pitch class with accidental "SoundNoteNumber" SoundNote pitch value "TuningStandardA" the frequency of A4 in 12-tone equal temperament - For a music pitch object obj, any of the above properties can be obtained using obj["prop"]. Use obj["PropertyAssociation"] to retrieve the values of all available properties.
- Subtracting two MusicPitch objects yields a MusicInterval object.
- The "PitchClass" property represents the pitch without any octave information. Its value is an integer between 0 ("C") and 11 ("B").
- The "Frequency" property is computed from the "MIDINumber", "TuningStandardA" and "CentDeviation" properties.
- By default, MusicPitch objects represent pitches in the 12-tone equal temperament system. That means that the ratio between the frequencies of two notes one octave apart is 2 (equivalent to 1200 cents), and the ratio between the frequencies of two notes a semitone apart is
(equivalent to 100 cents). To represent pitches in different temperaments, use the "CentDeviation" property to express the deviation from the equal temperament pitch.
Examples
open all close allBasic Examples (3)
MusicPitch["G3"]Construct the pitch with properties specified in an Association:
MusicPitch[<|"PitchClass" -> 7, "CentDeviation" -> 20|>]Construct the pitch with default properties inherited from another MusicPitch object:
MusicPitch[MusicPitch[54], "Gb"]Scope (9)
List all available properties:
MusicPitch["C"]["Properties"]Retrieve all available properties and their values:
MusicPitch["C"]["PropertyAssociation"]//DatasetConstruct a named pitch in different octaves:
MusicPitch["G3"]
MusicPitch["G4"]Construct the pitch using properties extracted from the given MusicNote:
MusicPitch[MusicNote["G3"]]Construct the pitch using properties extracted from the given SoundNote:
MusicPitch[SoundNote[0]]Construct the pitch from the given MIDI note number:
MusicPitch[55]Construct the note pitch with a specified frequency:
MusicPitch[Quantity[200, "Hertz"]]Specify the reference frequency of A4:
MusicPitch[Quantity[200, "Hertz"], <|"TuningStandardA" -> 447|>]Specify the "Key" and "Accidental" properties:
MusicPitch[<|"Key" -> "G", "Accidental" -> 1|>]Infer the appropriate enharmonic key from the specified accidental and "PitchClass":
MusicPitch[<|"PitchClass" -> %["PitchClass"], "Accidental" -> -1|>]["Key"]Specify the "Octave" property:
MusicPitch[<|"PitchClass" -> 6, "Octave" -> 5|>]Specify the "CentDeviation" property:
MusicPitch[<|"Name" -> "C4", "CentDeviation" -> -5|>]Generalizations & Extensions (1)
Perform addition and subtraction with MusicInterval:
MusicPitch["G"] + MusicInterval[2]MusicPitch["G"] - MusicInterval[2]Subtracting two MusicPitch objects will yield a MusicInterval object:
MusicPitch["G"] - MusicPitch["C"]The interval is directed: the difference from "G" down to "C" means lowering the pitch by seven semitones. Adding that interval to "C" will lower the pitch by seven semitones again, yielding an "F" in the lower octave:
MusicPitch["C"] + %Applications (2)
Create a melody by adding random intervals to a pitch:
start = MusicPitch["E4"]Nest a function that adds a random interval to the last pitch:
MusicScore@NestList[# + MusicInterval[RandomInteger[{-5, 5}]]&, start, 12]Create a function that returns pitches in diatonic just intonation:
deviations = <|0 -> 0, 2 -> 4, 4 -> -14, 5 -> -2, 7 -> 2, 9 -> -16, 11 -> -12|>;
justPitch[in_] := Module[
{pitch = MusicPitch[in]},
MusicPitch[pitch, <|"CentDeviation" -> deviations[pitch["PitchClass"]]|>]
]Compare a major chord in equal temperament and in just intonation:
MusicScore@{MusicChord[{MusicPitch["C"], MusicPitch["E"], MusicPitch["G"]}, 1], MusicChord[{justPitch["C"], justPitch["E"], justPitch["G"]}, 1]}Properties & Relations (5)
Retrieve the pitch from a MusicNote object:
MusicNote["G4"]["Pitch"]Retrieve the list of pitches from a MusicChord object:
MusicChord["FMinor"]["PitchList"]Retrieve the list of pitches from a MusicScale object:
MusicScale["DMinor"]["PitchList"]Add or subtract a MusicInterval to transpose a pitch:
MusicPitch["G"] + MusicInterval["MinorThird"]Use MusicTransform to sort a list of pitches:
MusicTransform[{MusicPitch["Gb"], MusicPitch["F#"], MusicPitch["A"]}, "SortByPitch"]Use MusicMeasurements to test for enharmonic equivalence between pitches:
MusicMeasurements[MusicPitch["Gb"], {"EnharmonicQ", MusicPitch["F#"]}]Related Guides
History
Text
Wolfram Research (2026), MusicPitch, Wolfram Language function, https://reference.wolfram.com/language/ref/MusicPitch.html.
CMS
Wolfram Language. 2026. "MusicPitch." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/MusicPitch.html.
APA
Wolfram Language. (2026). MusicPitch. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MusicPitch.html
BibTeX
@misc{reference.wolfram_2026_musicpitch, author="Wolfram Research", title="{MusicPitch}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/MusicPitch.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_musicpitch, organization={Wolfram Research}, title={MusicPitch}, year={2026}, url={https://reference.wolfram.com/language/ref/MusicPitch.html}, note=[Accessed: 12-June-2026]}