Welcome to pitchtools’s documentation!
pitchtools Package
Set of routines to work with musical pitches, convert to and from frequencies, notenames, etc. Microtones are fully supported, both as fractional midinotes and as notenames.
Features
convert between frequencies, midinotes and notenames
microtones are fully supported
split a pitch into its multiple components (pitch class, octave, microtonal deviation, etc.)
transpose a pitch taking its spelling into consideration
create custom pitch converters to work with custom reference frequencies, or modify the reference frequency globally
Microtonal notation
Some shortcuts are used for round microtones:
Symbol |
Cents |
---|---|
|
+50 |
|
-50 |
|
+25 |
|
-25 |
There is some flexibility regarding notenames: the octave can be placed before the note or after, and the pitch-class is case-insensitive.
Some example notenames
Midinote |
Notename |
Alternative notation |
---|---|---|
60.25 |
4C+25 / 4C> |
c4+25 / c>4 |
60.45 |
4C+45 |
C4+45 |
60.5 |
4C |
c4 |
60.75 |
4Db-25 |
Db4-25 / db4-25 |
61.5 |
4D- |
d4- |
61.80 |
4D-20 |
D4 |
63 |
4D# |
d#4 |
63.5 |
4D#+ |
d#+4 |
63.7 |
4E-30 |
E4-30 |
Global settings vs Converter objects
To convert to and from frequencies a reference frequency (A4
) is needed.
In pitchtools there are set of global functions (m2f()
, f2m()
,
n2f()
, etc) which rely on a global reference. This reference can be
modified via set_reference_freq()
.
It is also possible to create an ad-hoc converter (PitchConverter
).
This makes it possible to customize the reference frequency without any side-effects
Example
# Set the value globally
>>> set_reference_freq(443)
>>> n2f("A4")
443.0
# Create a Converter object
>>> cnv = PitchConverter(a4=435)
>>> print(cnv.n2f("4C"))
258.7
Functions
|
The name of the accidental corresponding to the given cents |
|
Convert an alteration to its corresponding cents deviation |
|
convert amp (0, 1) to dB |
|
Tries to interpret x as a list of pitches, returns these as midinotes |
|
Convert a deviation in cents to the corresponding value as pitchbend. |
|
Return the string representation of cents |
|
Utility function to construct a valid notename |
|
convert dB to amplitude (0, 1) |
|
Returns the enharmonic variant of notename |
|
Generates all enharmonic variations of the given notes |
|
Convert a frequency in Hz to a midi-note |
|
Return the notename corresponding to the given freq |
|
Convert a frequency to its place in the mel-scale :rtype: |
|
Round the freq. |
Get the reference frequency for this converter |
|
|
Convert a semitone interval to a ratio between 2 freqs. |
|
Convert a semitone interval to a ratio between 2 freqs. |
|
Returns true if notename is valid |
|
Convert a midi-note to a frequency |
|
Convert midinote to notename |
|
Convert a position in the mel-scale to its corresponding frequency |
|
Convert a midinote into its parts as a note |
|
Convert a notename to its corresponding frequency |
|
Convert a notename to a midinote |
|
Convert notename to its canonical form |
|
Gives information regarding the notated interval between n0 and n1 |
|
Convert a note or a (fractional) midinote to a NotatedPitch |
|
Convert from 4eb to 4Eb or from eb4 to Eb4 |
|
Find the ratio between n1 and n2 |
|
Round midinote to the next (possibly microtonal) note |
|
Convert a MIDI pitchbend to its corresponding deviation in cents |
|
Returns the pitchclass of a given note, rounded to the nearest semitone division |
|
Quantize midinote to the next semitone division |
|
Quantize notename to the next semitone divisions |
|
Convert the ratio between 2 freqs. |
|
Convert the ratio between 2 freqs. |
Set the reference freq. |
|
|
Split a notename into the chromatic note and the cents deviation. |
|
For a pitch given as 4Eb-14hz, returns ('4Eb', -14) |
|
Splits a notename into octave, letter, alteration and cents |
|
Accepts all that n2m accepts but with the addition of frequencies |
|
Transpose a note by an interval taking spelling into account |
|
Return the vertical notated position of a note |
Given a vertical position as an integer, returns the corresponding (diatonic) note |
Classes
|
A parsed notename to be queried in relation to its musical notation |
|
Represents the parts of a notename |
|
Convert between midinote, frequency and notename. |