Parker - A music theory library

Parker is a music theory library for python. It’s primary use is for music theory education and tooling. It is not a music composition tool, though it can be used for that purpose.

Tutorial

Features

  • Work with notes, chords, scales, and keys.
  • Generate all chords given a root note or generate chords from shorthand notation.
  • Generate scales using a root note using natural class names (Diatonic, Major, Minor, Dorian, Mixolydian, MajorPentatonic, etc)

Back to Index

Tutorial 01 - Notes

The basic building block of any music is the note. A note is defined by its name, octave, and accidentals following Scientific Pitch Notation. Let’s play with notes:

>>> from parker.notes import Note

Note objects

A note can be easily constructed from a valid note name. Let’s try a few:

>>> n = Note('C')
>>> print(n)
C4
>>> repr(n)
"Note('C4')"

You’ll notice immediately that the note that was returned says C4 instead of C. This is because the default octave will be the middle or fourth (4) octave of the scale. It also has no accidentals (sharps or flats).

There are a lot of valid notes that you can construct:

>>> note_list = ['C', 'C4', 'C#4', 'Cbb4']
>>> print([Note(note) for note in note_list])
[Note('C4'), Note('C4'), Note('C#4'), Note('Cbb4')]

Suprisingly you can use some very interesting notes:

>>> Note('C######bb')
Note('C####4')
>>> Note('C#b#bb##b##bb')
Note('C4')

You can use a convenience method to check if the format of the note is valid before constructing a note:

>>> from parker.notes import note_is_valid
>>> note_is_valid('C')
True
>>> note_is_valid('c')
False

Note Properties

As mentioned previously every Note object is constructed from a name, octave, and accidentals. You can get to these properties directly if desired:

>>> n = Note('C#4')
>>> n.base_name
>>> 'C'
>>> n.octave
>>> 4
>>> n.accidentals
>>> 1

The accidentals are captured as integer steps, or semitones, above the base note. The accidentals are changed internally into regognizable strings using a private method:

>>> n = Note('C#4')
>>> str(n.accidentals)
'#'

Notes as Numbers

Notes can also be represented as numbers:

>>> float(Note('C4'))
60.0

Or constructed from numbers:

>>> Note(60.0)
Note('C4')

Constructing Notes

You can construct notes using strings, integers, and other Note objects. As demonstrated all of these are valid:

>>> Note('C')
Note('C4')
>>> Note(60)
Note('C4')
>>> Note(Note('C'))
Note('C4')

Augment and Diminish Notes

Should you want to augment or diminish a note you can use easy convenience methods:

>>> n = Note('C4')
>>> n.augment()
Note('C#4')
>>> n.diminish()
Note('Cb4')
>>> n
Note('C4')

The methods to augment and diminish return new note objects instead of modifying the note in place. To modify in place you must use a different method:

>>> n = Note('C4')
>>> n.set_augment()
Note('C#4')
>>> n
Note('C#4')
>>> n.set_diminish()
Note('C4')
>>> n
Note('C4')

Other Reprentations

There are different use cases for representing a note. In some cases the note is needed without the octave in the string. This is called Generalization:

>>> n = Note('C####4')
>>> n.generalize()
'C####'

In other cases what is needed is the note in its most succinct form. This is called Normalization:

>>> n = Note('C####4')
>>> n.normalize()
'E'

Note Frequencies

Every note has a frequency. To access the frequency of a note simply ask:

>>> n = Note('C4')
>>> n.get_frequency()
261.6255653005985

This is a bit cumbersome so it can be managed by setting the desired digits:

>>> n = Note('C4')
>>> n.get_frequency(ndigits=3)
261.626

You can get a note object from a frequency by using a convenience method:

>>> from parker.notes import note_from_frequency
>>> note_from_frequency(261.626)
Note('C4')

This method will only get the closest note but will not tell how far out of tune the note is given the frequency.

Tutorial 02 - Intervals

Intervals can be described as the difference between two notes. You may ask for the minor third above a note or the octave below a note. Fortunately the Note object comes with a number of built-in methods for getting the interval you want using transposition features. Let’s get started:

>>> from parker.notes import Note

Tutorial 03 - Chords

>>> from parker.chords import *

Tutorial 04 - Scales

>>> from parker.scales import *

Tutorial 05 - Keys

>>> from parker.keys import *

Tutorial 06 - Progressions

>>> from parker.progressions import *

API Docs

parker.notes

notes.is_valid_note(note)

Determine if a note is valid from a given string representation.

notes.note_from_frequency(freq)

Return the closest note given a frequency value in Hz

This uses the forumula f = f0 * (a ** n)

f0 - the reference frequency, which is A4 at 440 Hz a - the twelth root of 2, or 2 ** (1/12) n - the number of half steps between notes

Here we want the value of n, or the integer value of half steps distance from the reference note.

n = log(f / f0) / log(a)

This does not take into account out of tune notes. In the future it might make sense to return the cents above or below the note.

class parker.notes.Accidental(acc='')[source]
alter
name
set_augment()[source]
set_diminish()[source]
set_from_num(alter)[source]
set_from_str(acc)[source]
class parker.notes.Note(note=None, use_sharps=True)[source]

Representation of a single note.

accidentals
all_transpositions()

Create all available named transpositions

augment()
augmented_eleventh_down()
augmented_eleventh_up()
augmented_ninth_down()
augmented_ninth_up()
base_name
clone()
compound_augmented_fourth_down()
compound_augmented_fourth_up()
compound_augmented_second_down()
compound_augmented_second_up()
compound_major_second_down()
compound_major_second_up()
compound_major_sixth_down()
compound_major_sixth_up()
compound_major_third_down()
compound_major_third_up()
compound_minor_second_down()
compound_minor_second_up()
compound_minor_sixth_down()
compound_minor_sixth_up()
compound_minor_third_down()
compound_minor_third_up()
compound_perfect_fourth_down()
compound_perfect_fourth_up()
diminish()
generalize()[source]

Return the note without the octave component.

Example:
C4 -> C Cbb4 -> Cbb C###4 -> C###
get_frequency(ndigits=None)[source]

Return the frequency of the note.

This uses the forumula f = f0 * (a ** n)

f0 - the reference frequency, which is A4 at 440 Hz a - the twelth root of 2, or 2 ** (1/12) n - the number of half steps between notes

Should rounding be required you can set the number of digits to round to in the method.

Reference:
major_eleventh_down()
major_eleventh_up()
major_fifth_down()
major_fifth_up()
major_fourth_down()
major_fourth_up()
major_ninth_down()
major_ninth_up()
major_second_down()
major_second_up()
major_seventh_down()
major_seventh_up()
major_sixth_down()
major_sixth_up()
major_tenth_down()
major_tenth_up()
major_third_down()
major_third_up()
major_thirteenth_down()
major_thirteenth_up()
minor_fifth_down()
minor_fifth_up()
minor_ninth_down()
minor_ninth_up()
minor_second_down()
minor_second_up()
minor_seventh_down()
minor_seventh_up()
minor_sixth_down()
minor_sixth_up()
minor_tenth_down()
minor_tenth_up()
minor_third_down()
minor_third_up()
minor_thirteenth_down()
minor_thirteenth_up()
normalize(use_sharps=None)[source]

Return the note normalized and without the octave component. Set use_sharps to control the output.

Example:
C4 -> C Cbb4 -> Bb Cbb4 -> A# (use_sharps=True) C###4 -> D# C###4 => Eb (use_sharps=False)
octave
octave_down()
octave_up()
perfect_fifth_down()
perfect_fifth_up()
perfect_fourth_down()
perfect_fourth_up()
set_augment()[source]
set_diminish()[source]
set_transpose(amount)[source]

Modify the note by a given number of semitones.

In some instances the letters ‘t’ or ‘A’ may be used to designate a change of 10 pitch classes. Similarly ‘e’ or ‘B’ may be used to designate a change of 11 pitch classes.

References:
transpose(amount)
transpose_list(lst)
class parker.notes.NotesParser[source]

Parse notes of any type into a list of notes. Valid notes are: Note, NoteGroup, int, str, list, tuple, set.

static parse(notes)[source]
class parker.notes.NoteGroupBase[source]

Representation of a set of notes to be played at the same time. An example of a NoteGroup would be a chord (1, 3, 5) played on a piano.

The base class does not let you add notes.

all_transpositions()

Create all available named transpositions

augment()
augmented_eleventh_down()
augmented_eleventh_up()
augmented_ninth_down()
augmented_ninth_up()
clone()
compound_augmented_fourth_down()
compound_augmented_fourth_up()
compound_augmented_second_down()
compound_augmented_second_up()
compound_major_second_down()
compound_major_second_up()
compound_major_sixth_down()
compound_major_sixth_up()
compound_major_third_down()
compound_major_third_up()
compound_minor_second_down()
compound_minor_second_up()
compound_minor_sixth_down()
compound_minor_sixth_up()
compound_minor_third_down()
compound_minor_third_up()
compound_perfect_fourth_down()
compound_perfect_fourth_up()
diminish()
get_notes()[source]
highest_note()
lowest_note()
major_eleventh_down()
major_eleventh_up()
major_fifth_down()
major_fifth_up()
major_fourth_down()
major_fourth_up()
major_ninth_down()
major_ninth_up()
major_second_down()
major_second_up()
major_seventh_down()
major_seventh_up()
major_sixth_down()
major_sixth_up()
major_tenth_down()
major_tenth_up()
major_third_down()
major_third_up()
major_thirteenth_down()
major_thirteenth_up()
minor_fifth_down()
minor_fifth_up()
minor_ninth_down()
minor_ninth_up()
minor_second_down()
minor_second_up()
minor_seventh_down()
minor_seventh_up()
minor_sixth_down()
minor_sixth_up()
minor_tenth_down()
minor_tenth_up()
minor_third_down()
minor_third_up()
minor_thirteenth_down()
minor_thirteenth_up()
notes = []
octave_down()
octave_up()
perfect_fifth_down()
perfect_fifth_up()
perfect_fourth_down()
perfect_fourth_up()
root = None
set_augment()[source]
set_diminish()[source]
set_transpose(amount)[source]
transpose(amount)
transpose_list(lst)
walk(func)
class parker.notes.NoteGroup(notes=None)[source]

A mutable set of notes to be played at the same time.

add(notes)[source]
append(item)[source]

parker.chords

class parker.chords.Chord(chord=None, octave=None)[source]

Source Material: https://en.wikipedia.org/wiki/Chord_(music)

all_transpositions()

Create all available named transpositions

augment()
augmented_eleventh_down()
augmented_eleventh_up()
augmented_ninth_down()
augmented_ninth_up()
clone()
compound_augmented_fourth_down()
compound_augmented_fourth_up()
compound_augmented_second_down()
compound_augmented_second_up()
compound_major_second_down()
compound_major_second_up()
compound_major_sixth_down()
compound_major_sixth_up()
compound_major_third_down()
compound_major_third_up()
compound_minor_second_down()
compound_minor_second_up()
compound_minor_sixth_down()
compound_minor_sixth_up()
compound_minor_third_down()
compound_minor_third_up()
compound_perfect_fourth_down()
compound_perfect_fourth_up()
diminish()
get_notes()
get_octave_construction()
get_scale()[source]
highest_note()
lowest_note()
major_eleventh_down()
major_eleventh_up()
major_fifth_down()
major_fifth_up()
major_fourth_down()
major_fourth_up()
major_ninth_down()
major_ninth_up()
major_second_down()
major_second_up()
major_seventh_down()
major_seventh_up()
major_sixth_down()
major_sixth_up()
major_tenth_down()
major_tenth_up()
major_third_down()
major_third_up()
major_thirteenth_down()
major_thirteenth_up()
minor_fifth_down()
minor_fifth_up()
minor_ninth_down()
minor_ninth_up()
minor_second_down()
minor_second_up()
minor_seventh_down()
minor_seventh_up()
minor_sixth_down()
minor_sixth_up()
minor_tenth_down()
minor_tenth_up()
minor_third_down()
minor_third_up()
minor_thirteenth_down()
minor_thirteenth_up()
notes = []
octave_down()
octave_up()
perfect_fifth_down()
perfect_fifth_up()
perfect_fourth_down()
perfect_fourth_up()
root = None
set_augment()
set_diminish()
set_transpose(amount)
transpose(amount)
transpose_list(lst)
walk(func)
chords.produce_all_chords(root)

Produce all chords given a root note.

Returns a dictionary of chord names as the key and the chord object as the value.

parker.scales

class parker.scales.Scale(root, order=None)[source]

Source: https://en.wikipedia.org/wiki/Scale_(music)

ASCENDING = 'ascending'
DESCENDING = 'descending'
ORDER_CHOICES = ['ascending', 'descending']
all_transpositions()

Create all available named transpositions

augment()
augmented_eleventh_down()
augmented_eleventh_up()
augmented_ninth_down()
augmented_ninth_up()
build_scale()[source]
clone()
compound_augmented_fourth_down()
compound_augmented_fourth_up()
compound_augmented_second_down()
compound_augmented_second_up()
compound_major_second_down()
compound_major_second_up()
compound_major_sixth_down()
compound_major_sixth_up()
compound_major_third_down()
compound_major_third_up()
compound_minor_second_down()
compound_minor_second_up()
compound_minor_sixth_down()
compound_minor_sixth_up()
compound_minor_third_down()
compound_minor_third_up()
compound_perfect_fourth_down()
compound_perfect_fourth_up()
diminish()
generic_notes = []
get_notes()
get_octave_construction()
get_tone_semitone_construction()[source]
get_whole_half_construction()[source]
highest_note()
intervals
is_generic_note_in_scale(note)[source]
lowest_note()
major_eleventh_down()
major_eleventh_up()
major_fifth_down()
major_fifth_up()
major_fourth_down()
major_fourth_up()
major_ninth_down()
major_ninth_up()
major_second_down()
major_second_up()
major_seventh_down()
major_seventh_up()
major_sixth_down()
major_sixth_up()
major_tenth_down()
major_tenth_up()
major_third_down()
major_third_up()
major_thirteenth_down()
major_thirteenth_up()
minor_fifth_down()
minor_fifth_up()
minor_ninth_down()
minor_ninth_up()
minor_second_down()
minor_second_up()
minor_seventh_down()
minor_seventh_up()
minor_sixth_down()
minor_sixth_up()
minor_tenth_down()
minor_tenth_up()
minor_third_down()
minor_third_up()
minor_thirteenth_down()
minor_thirteenth_up()
notes = []
octave_down()
octave_up()
perfect_fifth_down()
perfect_fifth_up()
perfect_fourth_down()
perfect_fourth_up()
root = None
set_augment()
set_diminish()
set_transpose(amount)
transpose(amount)
transpose_list(lst)
walk(func)
class parker.scales.Diatonic(root, order=None)[source]
class parker.scales.Ionian(root, order=None)[source]
intervals
class parker.scales.Major(root, order=None)[source]
class parker.scales.HarmonicMajor(root, order=None)[source]
intervals
class parker.scales.Dorian(root, order=None)[source]
intervals
class parker.scales.Phrygian(root, order=None)[source]
intervals
class parker.scales.MedievalLydian(root, order=None)[source]
intervals
class parker.scales.Lydian(root, order=None)[source]

The Lydian scale can be described as a major scale with the fourth scale degree raised a semitone, e.g., a C-major scale with an F# rather than F-natural.

Source: https://en.wikipedia.org/wiki/Lydian_mode

intervals
class parker.scales.Mixolydian(root, order=None)[source]
intervals
class parker.scales.Dominant(root, order=None)[source]
class parker.scales.Aeolian(root, order=None)[source]
intervals
class parker.scales.Minor(root, order=None)[source]
class parker.scales.HarmonicMinor(root, order=None)[source]
intervals
class parker.scales.Locrian(root, order=None)[source]
intervals
class parker.scales.SuperLocrian(root, order=None)[source]
intervals
class parker.scales.MajorPentatonic(root, order=None)[source]

Major Pentatonic drops 4th and 7th from the Diatonic Major and consists of only 5 notes.

intervals
class parker.scales.MinorPentatonic(root, order=None)[source]

Minor Pentatonic drops 2nd and 6th from the Diatonic Minor and consists of only 5 notes.

intervals
class parker.scales.MajorBlues(root, order=None)[source]

Major Blues is the same as the Major Pentatonic but it adds a diminished 4th and consists of 6 notes.

intervals
class parker.scales.MinorBlues(root, order=None)[source]

Minor Blues is the same as the Minor Pentatonic but it adds an augmented 5th and consists of 6 notes.

intervals
class parker.scales.Altered(root, order=None)[source]
intervals
class parker.scales.DiminishedWholeTone(root, order=None)[source]
class parker.scales.Chromatic(root, order=None)[source]
intervals
class parker.scales.Octatonic(root, order=None)[source]
class parker.scales.OctatonicModeOne(root, order=None)[source]
intervals
class parker.scales.OctatonicModeTwo(root, order=None)[source]
intervals
scales.circle_of_fifths()
scales.circle_of_fourths()
scales._scale_creator(scale_cls, root='C4')
scales.dorian_scales(root='C4')
scales.mixolydian_scales(root='C4')
scales.major_scales(root='C4')
scales.minor_scales(root='C4')
scales.major_pentatonic_scales(root='C4')
scales.minor_pentatonic_scales(root='C4')
scales.major_blues_scales(root='C4')
scales.minor_blues_scales(root='C4')

parker.keys

class parker.keys.Key(key='C')[source]

Reference: https://en.wikipedia.org/wiki/Key_(music)

MAJOR = 'major'
MINOR = 'minor'
get_accidental_notes()[source]
get_scale()[source]
is_major()[source]
is_minor()[source]

parker.progressions

class parker.progressions.Progression(root, scale_cls=<class 'parker.scales.Major'>)[source]

Reference: https://en.wikipedia.org/wiki/Roman_numeral_analysis

all_progressions()[source]
from_list(prog_list, as_map=False)[source]

Take a list of progressions and return the list of chords.

Setting as_map to True will return the progressions as a dictionary where the keys are the progressions passed in and the values are the chords.

from_string(progression)[source]

Take a string representation of a progression and return the chord that it represents.

standard_sevenths()[source]
standard_triads()[source]

Indices and tables