Skip to main content

Various tables (dicts) and functions for converting between note names, midi

Project description

midi_notes

Provides various tables (dicts) and functions for converting between note names, midi note numbers, frequencies, plus a single "Note" class which allows you to switch seamlessly between pitch/note name/frequency representations.

Note class

You can construct a Note with either a (str) note name, (int) midi pitch, or (float) frequency.

from midi_notes import *

note = Note('C4')
print(f'"{note.name}" has midi pitch {note.pitch}')
print(f'"{note.name}" is in octave {note.octave}, and has a value of {note.interval_above_c}')
print(f'"{note.name}" has a frequency of {note.frequency}Hz')

frequency = 444.4
note = Note(frequency)
print(f'"{note.name}" with a frequency of {note.frequency}Hz is closest to {frequency}Hz')

... prints:

"C4" has MIDI pitch 60
"C4" is in octave 4, and has a value of 0
"C4" has a frequency of 261.626Hz
"A4" with a frequency of 440.0Hz is closest to 444.4Hz

When getting the "name" property of a Note which is an incidental, you can decide whether to retrieve the "sharp" or "flat" version of the note name ("D♯" is the same pitch as "E♭") by setting the "prefer_flats" property.

note = Note('D#5')
print(f'MIDI pitch {note.pitch} is "{note.name}"')
note.prefer_flats = True
print(f'MIDI pitch {note.pitch} is also "{note.name}"')

... prints:

MIDI pitch 75 is "D#5"
MIDI pitch 75 is also "Eb5"

You can also choose how to render incidentals:

note = Note('D#5')
note.incidentals_style = Note.INCIDENTAL_ASCII
print(f'INCIDENTAL_ASCII: "{note.name}"')
note.incidentals_style = Note.INCIDENTAL_UNICODE
print(f'INCIDENTAL_UNICODE: "{note.name}"')
note.incidentals_style = Note.INCIDENTAL_NAMES
print(f'INCIDENTAL_NAMES: "{note.name}"')

... prints:

INCIDENTAL_ASCII: "Eb5"
INCIDENTAL_UNICODE: "E♭5"
INCIDENTAL_NAMES: "E flat 5"

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

midi_notes-1.0.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

midi_notes-1.0.0-py2.py3-none-any.whl (21.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file midi_notes-1.0.0.tar.gz.

File metadata

  • Download URL: midi_notes-1.0.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for midi_notes-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4b358e1fb1e14a30bddedcaf781cfe5f55a94ab5b75146f527b0a472d54d1330
MD5 599a63c3e26cca9b05b05c701aeaf455
BLAKE2b-256 689fdba84f72a876798abd26a8b6aed58bca4502ffb70bdf3b063ae5687e2599

See more details on using hashes here.

File details

Details for the file midi_notes-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: midi_notes-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for midi_notes-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d875486f57b4c1f36fd501686359e91223e04fe5df643cb21dd0d0aaf75550b0
MD5 70de70aae2a9785c76c2f1f0d3ae2944
BLAKE2b-256 6c09feb67e1fc4ee89c3ddd33c0c0783dc6fa02f51f52c1bc39351fcea94e477

See more details on using hashes here.

Supported by

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