pitchtypes
A library for handling musical pitches and intervals in a systematic way. For other (and mostly compatible) implementations see:
- Pitches.jl (Julia)
- musicology-pitch (Haskell)
- purescript-pitches (Purescript)
- pitches.rs (Rust)
The main goals of this library are:
- providing types and operations (such as arithmetics, printing and parsing) for common types of pitches and intervals, (in particular spelled pitches and intervals, which are often difficult to handle),
- providing a generic interface for writing code that is agnostic to the specific pitch or interval types.
Installation
pip install pitchtypes
Minimal Example
import pitchtypes as pt
# write a generic function
def transposeby(pitches, interval):
return [pitch + interval for pitch in pitches]
# use it with different pitch types
# spelled pitches correspond to written notes in Western notation
spelled_pitches = [pt.SpelledPitch(p)
for p in ["C4", "Eb4", "G#4"]]
print(transposeby(spelled_pitches, pt.SpelledInterval("m3:0"))
# spelled pitch classes work the same but they ignore octaves
spelled_pitch_classes = [pt.SpelledPitchClass(p)
for p in ["C", "Eb", "G#"]]
print(transposeby(spelled_pitches, pt.SpelledIntervalClass("m3"))
# enharmonic pitches correspond to keys on the piano
enharmonic_pitches = [pt.EnharmonicPitch(p)
for p in [60, 63, 68]]
print(transposeby(spelled_pitches, pt.EnharmonicInterval(3))
Output:
[Eb4, Gb4, B4]
[Eb, Gb, B]
[D#4, F#4, B4]
Old Example (delete/adapt?)
For instance, spelled pitch is handled correctly:
>>> from pitchtypes import SpelledPitchClass
>>> p1 = SpelledPitchClass("C#")
>>> p2 = SpelledPitchClass("Gb")
>>> i = p1 - p2
>>> type(i)
<class 'pitchtypes.datatypes.SpelledIntervalClass'>
>>> i
+AA4
Of course, you can also convert spelled pitches to their enharmonic equivalents:
>>> from pitchtypes import SpelledPitch, EnharmonicPitch
>>> spelled = SpelledPitch("C#4")
>>> enharmonic = spelled.convert_to(EnharmonicPitch)
>>> type(enharmonic)
<class 'pitchtypes.datatypes.EnharmonicPitch'>
>>> enharmonic.midi
61
>>> enharmonic.name('sharp')
C#4
>>> enharmonic.name('flat')
Db4
And used continuous log-frequency space (assuming twelve-tone equal temperament for enharmonic pitch):
>>> from pitchtypes import EnharmonicPitch, LogFreqPitch
>>> enharmonic = EnharmonicPitch("A4")
>>> logfreq = enharmonic.convert_to(LogFreqPitch)
>>> logfreq
440.Hz
For more examples, have a look at the Tutorial.ipynb!
Metadata
Release files for pitchtypes 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pitchtypes-0.4.0.tar.gz | 37.2 kB | Without provenance | Details for pitchtypes-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pitchtypes-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for pitchtypes-0.4.0-py3-none-any.whl |
Total release size: 76.5 kB
Release files / pitchtypes-0.4.0.tar.gz
| Download URL | pitchtypes-0.4.0.tar.gz |
|---|---|
| Size | 37.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a54223bebfbf8ef9a05bd60787aecf20a3d7c72f3e073362336ee89bab19bdab
|
|
BLAKE2b-256 checksum How to use checksums |
19063dc97f5b5a071b25c9a67c260caf7eed2c256d183f2921346bc1a322a406
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Release files / pitchtypes-0.4.0-py3-none-any.whl
| Download URL | pitchtypes-0.4.0-py3-none-any.whl |
|---|---|
| Size | 39.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a04e701245d6d810dc416dfa89fbbac2ad341829947ba0eab65473c2f3916a1d
|
|
BLAKE2b-256 checksum How to use checksums |
b5239f420fa06f1d66cbcde0dcd2021fc38fa925dc1951a2293bfbbcb9fa0a02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.0
|
Security for pitchtypes 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.