ChordalPy
A simple python library to ingest and manipulate musical chords stored in plaintext format according to Christopher Harte's 2010 thesis.
Installation
python -m pip install ChordalPy
The format
The chords that this library can parse are in a specific plaintext format detailed here; however, here's a quick and dirty run down.
Each chord has three parts: the root, the intervals, and the bass. They are seperated with a colon and a slash like so
root:intervals/bass
Root
The root is simply any letter name. It could be 'C' or 'G#' or 'Fbbbbb'.
Intervals
The intervals section consists of a shorthand abbreviation for a common set of intervals followed by any changes to those intervals in parantheses. For example, a major triad with an added sharp sixth would be maj(#6). The added intervals can do one of:
- Add an interval to the existing shorthand.
- Modify (sharp or flat) an interval in the existing shorthand.
- Remove an interval in the existing shorthand (notated with a
*before the interval to be removed).
The list of shorthands can be found on page 105 of the earlier referenced PDF.
Bass
The bass is an interval degree (any digit 1-9) along with 0 or more modifiers (# or b)
A note on intervals
There is an interesting quick to musical intervals that means they cannot be entirely expressed with only one digit. Rather, they requrie a tuple of two integers.
When looking through the source of this library, you will often find intervals notated as such. The first integer represents the number of letter names between the notes (for instance, in the interval from C to G the first integer would be 5) and the second integer is the number of half steps (so in the interval from C to G the second integer would be 7).
Using this method you can see how you would distiniguish between two enharmonic pitches. For example, C to E and C to Fb. The interval from C to E would be (3, 4) while the interval from C to Fb would be (4, 4).
Library Usage
Parse a chord and print its members
import ChordalPy
my_chord = ChordalPy.parse_chord("C:maj")
spelling = my_chord.get_spelling()
print("C:maj has notes %s" % spelling)
Instantiate a chord directly
import ChordalPy
# C major in first inversion (C:maj/3)
root = "C"
intervals = [(1, 0), (3, 4), (5, 7)]
bass = "E"
my_chord = ChordalPy.Chord(root, intervals, bass)
Chord Class
Print a string representation of a chord
print(str(my_chord))
# C:[(1, 0), (3, 4), (5, 7)]/E
Print the spelling of a chord
print(my_chord.get_spelling())
# ['C', 'E', 'G']
Print a binary note array of a chord
print(my_chord.get_note_array())
# [1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0]
Print a pseudohash of a chord's intervals
print(my_chord.get_pseudo_hash())
# ecca
Find the note a given interval above a chord's root
print(my_chord.note_from_interval([5, 8]))
# ecca
See Also
Projects
Chordgen.com - A web tool that uses machine learning to generate chord progressions. The machine learning model was trained on data created with this library.
Datasets
A non-exhaustive list of datasets that use a format parsable by this library:
Metadata
Release files for ChordalPy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ChordalPy-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ChordalPy-0.1.0-py3-none-any.whl |
Release files / ChordalPy-0.1.0-py3-none-any.whl
| Download URL | ChordalPy-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b13dc0ca37b26c8dfc344235705669b20e3b0bbc41f1ce115155f30ddf6e29d
|
|
BLAKE2b-256 checksum How to use checksums |
e024221cca41cd3604a5e5f84be5603ec0d75e3b5d925cc2a20a05c36efbf014
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4
|
Security for ChordalPy 0.1.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.