Musical Classes

Note

class chordparser.Note(letter, symbol)

A class representing a musical note.

The Note class consists of notation A-G with optional unicode accidental symbols ♭, ♯, 𝄫, or 𝄪. It is created by the NoteEditor. When printed, only the value of the Note is displayed.

Parameters:
  • letter (str) – The letter part of the Note’s notation. Consists of A-G.
  • symbol (str) – The accidental part of the Note’s notation. Consists of the unicode characters ♭, ♯, 𝄫, or 𝄪. If there are no accidentals, it is an empty string.
letter

The letter part of the Note’s notation.

Type:str
symbol

The accidental part of the Note’s notation.

Type:str
__eq__(other)

Compare between other Notes and strings.

Checks if the other Note’s value or the string is the same as this Note.

Parameters:other – The object to be compared with.
Returns:The outcome of the value comparison.
Return type:boolean

Examples

>>> NE = NoteEditor()
>>> d = NE.create_note("D")
>>> d2 = NE.create_note("D")
>>> d_str = "D"
>>> d == d2
True
>>> d == d_str
True

Note that symbols are converted to their unicode characters when a Note is created.

>>> NE = NoteEditor()
>>> ds = NE.create_note("D#")
>>> ds_str = "D#"
>>> ds_str_2 = "D♯"
>>> ds == ds_str
False
>>> ds == ds_str_2
True
accidental(value)

Change a Note’s accidental by specifying a value from -2 to 2.

The range of values [-2, 2] correspond to the values a symbol can take, from doubleflat (-2) to doublesharp (2).

Parameters:value (int) – The accidental’s integer value.
Raises:ValueError – If value is not in the range of [-2, 2].

Examples

>>> NE = NoteEditor()
>>> d_sharp = NE.create_note("D#")
>>> d_sharp.accidental(-1)
D♭ note
letter_value()

Return the Note’s letter as an integer value (basis: C = 0).

The value is based on the number of scale degrees above C.

Returns:The letter’s value.
Return type:int

Examples

>>> NE = NoteEditor()
>>> d = NE.create_note("D")
>>> d.letter_value()
1
num_value()

Return the Note’s numerical value (basis: C = 0).

The numerical value is based on the number of semitones above C.

Returns:The numerical value.
Return type:int

Examples

>>> NE = NoteEditor()
>>> d = NE.create_note("D")
>>> d.num_value()
2
shift_l(value)

Shift a Note’s letter.

The value corresponds to the change in scale degree of the Note.

Parameters:value (int) – The value of the letter shift.

Examples

>>> NE = NoteEditor()
>>> d_sharp = NE.create_note("D#")
>>> d_sharp.shift_l(3)
G♯ note
shift_s(value)

Shift a Note’s accidental.

The Note’s symbol_value() must be in the range of [-2, 2] after the shift, which corresponds to the values a symbol can take from doubleflat (-2) to doublesharp (2).

Parameters:value (int) – The value of the shift in accidentals.
Raises:ValueError – If the Note’s symbol_value() is not in the range of [-2, 2] after the shift.

Examples

>>> NE = NoteEditor()
>>> d_sharp = NE.create_note("D#")
>>> d_sharp.shift_s(-1)
D note
symbol_value()

Return the Note’s symbol as an integer value (basis: natural = 0).

The value is based on the number of semitones away from the natural Note.

Returns:The symbol’s value.
Return type:int

Examples

>>> NE = NoteEditor()
>>> d_sharp = NE.create_note("D#")
>>> d_sharp.symbol_value()
1
transpose(semitones, letters)

Transpose a Note according to semitone and letter intervals.

Parameters:
  • semitones – The difference in semitones to the new transposed Note.
  • letters – The difference in scale degrees to the new transposed Note.

Examples

>>> NE = NoteEditor()
>>> c = NE.create_note("C")
>>> c.transpose(6, 3)
F♯ note
>>> c.transpose(0, 1)
G♭ note
transpose_simple(semitones, use_flats=False)

Transpose a Note according to semitone intervals.

Parameters:
  • semitones (int) – The difference in semitones to the new transposed Note.
  • use_flats (boolean, Optional) – Selector to use flats or sharps for black keys. Default False when optional.

Examples

>>> NE = NoteEditor()
>>> c = NE.create_note("C")
>>> c.transpose_simple(6)
F♯ note
>>> c.transpose(2, use_flats=True)
A♭ note
value

The full notation of the Note.

Type:str

Key

class chordparser.Key(root, mode, submode)

A class representing a musical key.

The Key class composes of a Note class as its root as well as the attributes mode and submode. It is created by the KeyEditor. Keys can use the same methods as Notes to manipulate their root.

Parameters:
  • root (Note) – The root note of the Key.
  • mode ({'major', 'minor', 'ionian', 'dorian', 'phrygian', 'lydian', 'mixolydian', 'aeolian', 'locrian'}) – The mode of the Key.
  • submode ({None, 'natural', 'harmonic', 'melodic'}) – The submode of the Key. If the mode is not ‘minor’/ ‘aeolian’, submode is None. Else, submode is one of the strings.
root

The root note of the Key.

Type:Note
mode

The mode of the Key.

Type:{‘major’, ‘minor’, ‘ionian’, ‘dorian’, ‘phrygian’, ‘lydian’, ‘mixolydian’, ‘aeolian’, ‘locrian’}
submode

The submode of the Key. If the mode is not ‘minor’/ ‘aeolian’, submode is None. Else, submode is one of the strings.

Type:{None, ‘natural’, ‘harmonic’, ‘melodic’}
__eq__(other)

Compare between other Keys.

Checks if the other Key has the same attributes.

Parameters:other – The object to be compared with.
Returns:The outcome of the comparison.
Return type:boolean

Examples

>>> KE = KeyEditor()
>>> d = KE.create_key("D", "minor")
>>> d2 = KE.create_key("D", "minor", "natural")
>>> d == d2
True
>>> d3 = KE.create_key("D", "minor", "harmonic")
>>> d == d3
False

Note that the major mode is the same as ionian, and the minor mode is the same as aeolian.

>>> KE = KeyEditor()
>>> e = KE.create_key("E", "major")
>>> e2 = KE.create_key("E", "ionian")
>>> e == e2
True
>>> f = KE.create_key("F", "minor")
>>> f2 = KE.create_key("F", "aeolian")
>>> f == f2
True
__getattr__(attribute)

Allow Note methods to be used on the Key’s root.

See also

chordparser.Note()
For a list of Note methods.

Scale

class chordparser.Scale(key)

A class representing a musical scale.

The Scale composes of a Key on which it is based on, and a tuple of Notes as part of its notes attribute.

Parameters:key (Key) – The Key which the Scale is based on.
key

The Key which the Scale is based on.

Type:Key
notes

A two-octave tuple of Notes of the Scale.

Type:tuple
scale_intervals

The semitone intervals between notes.

Type:tuple
__eq__(other)

Compare between other Scales.

Checks if the other Scale has the same Key and notes.

Parameters:other – The object to be compared with.
Returns:The outcome of the value comparison.
Return type:boolean

Examples

>>> SE = ScaleEditor()
>>> d = SE.create_scale("D", "minor")
>>> d2 = SE.create_scale("D", "minor")
>>> d == d2
True
>>> d3 = SE.create_scale("D", "minor", "harmonic")
>>> d == d3
False
build()

Build the Scale from its Key.

This method does not need to be used if Scale adjustments are done through the proper channels (i.e. ScaleEditor or using other Scale methods), since those would build the Scale automatically.

transpose(semitones, letter)

Transpose a Scale according to semitone and letter intervals.

Parameters:
  • semitones – The difference in semitones to the new transposed root of the Scale’s Key.
  • letters – The difference in scale degrees to the new transposed root of the Scale’s Key.

Examples

>>> SE = ScaleEditor()
>>> c = SE.create_scale("C", "major")
>>> c.transpose(6, 3)
F♯ major scale
>>> c.transpose(0, 1)
G♭ major scale
transpose_simple(semitones, use_flats=False)

Transpose a Scale according to semitone intervals.

Parameters:
  • semitones (int) – The difference in semitones to the new transposed root of the Scale’s Key.
  • use_flats (boolean, Optional) – Selector to use flats or sharps for black keys. Default False when optional.

Examples

>>> SE = ScaleEditor()
>>> c = SE.create_scale("C", "minor")
>>> c.transpose_simple(6)
F♯ natural minor scale
>>> c.transpose(2, use_flats=True)
A♭ natural minor scale

Chord

class chordparser.Chord(root, quality, add=None, bass=None, string=None)

A musical class representing a chord.

The Chord is composed of a root Note, quality, optional add Notes and an optional bass Note. It automatically builds its notes from these components. When printed, a standardised short notation meant for chord sheets is displayed.

Parameters:
  • root (Note) – The root note.
  • quality (Quality) – The Chord quality.
  • add (list of (str, int), Optional) – List of added notes. The str is the accidental and the int is the scale degree of each added note.
  • bass (Note, Optional) – Bass note.
  • string (str, Optional) – The Chord notation string input.
root

The root note.

Type:Note
quality

The Chord quality.

Type:Quality
add

List of added notes.

Type:list of (str, int), Optional
bass

Bass note.

Type:Note, Optional
string

The Chord notation string input.

Type:str, Optional
base_intervals

The intervals of the Chord solely based on its quality.

Type:tuple of int
base_degrees

The scale degrees of the Chord solely based on its quality.

Type:tuple of int
base_symbols

The accidentals of the Chord solely based on its quality.

Type:tuple of str
intervals

The intervals of the Chord.

Type:tuple of int
degrees

The scale degrees of the Chord.

Type:tuple of int
symbols

The accidentals of the Chord.

Type:tuple of str
notes

The tuple of Notes in the Chord.

Type:tuple of Note
__eq__(other)

Compare between other Chords.

Checks if the other Chord has the same attributes. Since the attributes and not the notation is being compared, Chords with different notation but same structure are equal (see Examples).

Parameters:other – The object to be compared with.
Returns:The outcome of the value comparison.
Return type:boolean

Examples

>>> CE = ChordEditor()
>>> d = CE.create_chord("Dsus")
>>> d2 = CE.create_chord("Dsus4")
>>> d == d2
True
>>> d3 = CE.create_chord("Dsus2")
>>> d == d3
False

Another example of the same Chord with different notation:

>>> CE = ChordEditor()
>>> e = CE.create_chord("Eaug7")
>>> e2 = CE.create_chord("E7#5")
>>> e == e2
True
build()

Build the Chord from its attributes.

This method does not need to be used if Chord adjustments are done through the proper channels (i.e. ChordEditor or using other Chord methods), since those would build the Chord automatically.

transpose(semitones, letter)

Transpose a Chord according to semitone and letter intervals.

Parameters:
  • semitones – The difference in semitones to the new transposed root of the Chord.
  • letters – The difference in scale degrees to the new transposed root of the Chord.

Examples

>>> CE = ChordEditor()
>>> c = CE.create_chord("Csus")
>>> c.transpose(6, 3)
F♯sus chord
>>> c.transpose(0, 1)
G♭sus chord
transpose_simple(semitones, use_flats=False)

Transpose a Chord according to semitone intervals.

Parameters:
  • semitones (int) – The difference in semitones to the new transposed root of the Chord.
  • use_flats (boolean, Optional) – Selector to use flats or sharps for black keys. Default False when optional.

Examples

>>> CE = ChordEditor()
>>> c = CE.create_chord("Cm")
>>> c.transpose_simple(6)
F♯m chord
>>> c.transpose(2, use_flats=True)
A♭m chord

Roman

class chordparser.Roman(root, quality, inversion)

A class representing Roman numeral notation.

The Roman is composed of its root, quality and inversion. When printed, the standard Roman numeral notation is displayed.

Parameters:
  • root (str) – The scale degree of the Roman. Uppercase if major/augmented and lowercase if minor/diminished.
  • quality (str) – The quality of the Roman.
  • inversion (tuple of int) – The inversion of the Roman in figured bass notation (e.g. (6, 4) for second inversion).
root

The scale degree of the Roman. Uppercase if major/augmented and lowercase if minor/diminished.

Type:str
quality

The quality of the Roman.

Type:str
inversion

The inversion of the Roman in figured bass notation (e.g. (6, 4) for second inversion).

Type:tuple of int
__eq__(other)

Compare between other Romans.

Checks if the other Roman has the same root, quality and inversion.

Parameters:other – The object to be compared with.
Returns:The outcome of the value comparison.
Return type:boolean

Examples

>>> KE = KeyEditor()
>>> SE = ScaleEditor()
>>> CE = ChordEditor()
>>> CRC = ChordRomanConverter()
>>> c_key = KE.create_key("C")
>>> c_scale = SE.create_scale(c_key)
>>> d = CE.create_diatonic(c_scale, 2)
>>> r = CRC.to_roman(d, c_key)
>>> r2 = CRC.to_roman(d, c_key)
>>> r == r2
True
>>> e = CE.create_diatonic(c_scale, 3)
>>> r3 = CRC.to_roman(e, c_key)
>>> r == r3
False