Skip to main content

musically meaningful pitch types

Project description

pitchtypes

docs (development version)

build PyPI version

tests codecov

License: GPL v3

A library for handling musical pitches and intervals in a systematic way. For other (and mostly compatible) implementations see:

The main goals of this library are:

  • providing types and operations (such as arithmetics, printing and parsing) for common types of pitches and intervals
  • 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pitchtypes-0.3.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

pitchtypes-0.3.0-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file pitchtypes-0.3.0.tar.gz.

File metadata

  • Download URL: pitchtypes-0.3.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for pitchtypes-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e6783dbc088446e0a98c21f21397502cd90cef2914313e6693a49ed81b2e7025
MD5 6bcbcf0e60b0bf3fce5d9698518cf664
BLAKE2b-256 6db653930b137b1ce95f3869684538f017e44a85959cc636d97b903eaeba7924

See more details on using hashes here.

File details

Details for the file pitchtypes-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pitchtypes-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for pitchtypes-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 feb8db466fd888776d88f92a04d60826a0cf802f933ae7a522eeb1a0bd676971
MD5 8e07076e02251f5905a069a7937b6e64
BLAKE2b-256 dc3e2d47b0eb1795c8698c27d35af1bc65c179140a90ca7288ff232623282abc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page