Skip to main content

Utilities to work with pitches, convert between midinotes, frequency and notenames

Project description

pitchtools provides a set of functions to work with musical pitches.

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

Documentation

https://pitchtools.readthedocs.io/en/latest/

Examples

Convert some note names to frequencies

>>> from pitchtools import *
>>> eflat_scale = "4Eb 4F 4G 4Ab 4Bb 5C 5D".split()
>>> for note in eflat_scale:
...     # convert notename to frequency using the default reference frequency (442 Hz)
...     freq = n2f(note)
...     # convert frequency to midi
...     midinote = f2m(freq)
...     print(f"{note} = {freq:.1f}Hz (midi = {midinote})")
4Eb = 312.5 Hz (midi = 63.0)
4F  = 350.8 Hz (midi = 65.0)
4G  = 393.7 Hz (midi = 67.0)
4Ab = 417.2 Hz (midi = 68.0)
4Bb = 468.3 Hz (midi = 70.0)
5C  = 525.6 Hz (midi = 72.0)
5D  = 590.0 Hz (midi = 74.0)

The same but with a different reference frequency

from pitchtools import *
ebscale = "4Eb 4F 4G 4Ab 4Bb 5C 5D".split()
cnv = PitchConverter(a4=435)
for note in ebscale:
    # Convert to frequency with default a4=442 Hz
    freq = cnv.n2f(note)
    midinote = cnv.[Of2m(freq)
    print(f"{note} = {freq} Hz (midinote = {midinote})")

Microtones

Microtones are fully supported, either as fractional midinotes or as notenames.

>>> from pitchtools import *
>>> n2m("4C+")
60.5
>>> n2m("4Db-10")
60.9
>>> m2n(61.2)
4C#+20

Microtonal notation

Midinote

Notename

60.25

4C+25 / 4C>

60.45

4C+45

60.5

4C

60.75

4Db-25

61.5

4D-

61.80

4D-20

63

4D#

63.5

4D#+

63.7

4E-30


Installation

pip install pitchtools

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

pitchtools-1.15.0.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

pitchtools-1.15.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file pitchtools-1.15.0.tar.gz.

File metadata

  • Download URL: pitchtools-1.15.0.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pitchtools-1.15.0.tar.gz
Algorithm Hash digest
SHA256 2feda2a45c70084b1676d3e914f7d27d24bb00f1f220da80838acc6fbc989746
MD5 fb0b9a5a26e246d4c95df01d014e092c
BLAKE2b-256 11b8863971de1f35e9c2ced03c047be82687c925f83829d246e039428b9e9bd1

See more details on using hashes here.

File details

Details for the file pitchtools-1.15.0-py3-none-any.whl.

File metadata

  • Download URL: pitchtools-1.15.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pitchtools-1.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 094fb709742811be891db05ac1333e0090fef0a8378421d28bb4e17b9007646b
MD5 b9074a9444f924d317bb7d51f1cf1dc8
BLAKE2b-256 a84e93d0afb0992b1ae3de4e7d50eb47d8b0f1eccae1ee71a077306329941f86

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