Package jazzparser :: Package utils :: Module chords
[hide private]
[frames] | no frames]

Module chords

source code

Chord processing utilities.

A library of utility functions used throughout the Jazz Parser relating to chord processing in the input.


Author: Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>

Classes [hide private]
  ChordError
Raised when there's a problem recognising or processing a chord.
Functions [hide private]
 
chord_numeral_to_int(chord_numeral, strict=False)
Given a chord numeral (e.g.
source code
 
pitch_class_to_int(chord_numeral)
Like chord_numeral_to_int, but for pitch class labels.
source code
 
int_to_chord_numeral(chord_int)
Given an internal integer representation of a chord root (i.e.
source code
 
int_to_pitch_class(chord_int)
Like int_to_chord_numeral, but outputs a pitch class name instead of roman numeral.
source code
 
generalise_chord_name(chord_name)
The grammar generalises over chord names, using X to mean "any roman numeral chord root".
source code
 
interval_observation_from_chord_string_pair(chord1, chord2, type_mapping=None)
Given two strings representing chords, produces a string representing a chord observation of the form x-t, where x is the interval between the chords (numeric) and t is the type of the first chord.
source code
Variables [hide private]
  logger = logging.getLogger("main_logger")
  ly_note_to_int = {'A': 9, 'B': 11, 'C': 0, 'D': 2, 'E': 4, 'F'...
  ly_note_to_base_int = {'A': 5, 'B': 6, 'C': 0, 'D': 1, 'E': 2,...
  int_to_ly_note = {None: 'r', 0: 'c', 1: 'cis', 2: 'd', 3: 'dis...
  int_to_note_name = {0: 'C', 1: 'Db', 2: 'D', 3: 'Eb', 4: 'E', ...
  ROMAN_NUMERALS = {0: 'I', 1: 'bII', 2: 'II', 3: 'bIII', 4: 'II...
  __package__ = 'jazzparser.utils'
Function Details [hide private]

chord_numeral_to_int(chord_numeral, strict=False)

source code 

Given a chord numeral (e.g. "I" or "bVII"), returns the integer that corresponds to this chord root. Returns None if input is either a chord variable ("X", "Y") or itself None. If strict is set, doesn't allow variable names.

int_to_chord_numeral(chord_int)

source code 

Given an internal integer representation of a chord root (i.e. a note of the scale), returns the roman numeral as a string. This will always use the same convention for #s and bs, so may not be the same as the numeral that generated the note number.

The input numbers 0-11 correspond to I-VII in the scale. The input need to be in this range. Outside it, numbers will be mapped into this range by "% 12".

Returns "X" if input is None.

int_to_pitch_class(chord_int)

source code 

Like int_to_chord_numeral, but outputs a pitch class name instead of roman numeral. Returns "X" if input is None.

generalise_chord_name(chord_name)

source code 

The grammar generalises over chord names, using X to mean "any roman numeral chord root". When a chord name comes as input to the parser, say "IIm", we look up not "IIm", but "Xm".

Given any chord name, this function returns the generalised chord name to look up in the grammar.


Variables Details [hide private]

ly_note_to_int

Value:
{'A': 9,
 'B': 11,
 'C': 0,
 'D': 2,
 'E': 4,
 'F': 5,
 'G': 7,
 'a': 9,
...

ly_note_to_base_int

Value:
{'A': 5,
 'B': 6,
 'C': 0,
 'D': 1,
 'E': 2,
 'F': 3,
 'G': 4,
 'a': 5,
...

int_to_ly_note

Value:
{None: 'r',
 0: 'c',
 1: 'cis',
 2: 'd',
 3: 'dis',
 4: 'e',
 5: 'f',
 6: 'fis',
...

int_to_note_name

Value:
{0: 'C',
 1: 'Db',
 2: 'D',
 3: 'Eb',
 4: 'E',
 5: 'F',
 6: 'Gb',
 7: 'G',
...

ROMAN_NUMERALS

Value:
{0: 'I',
 1: 'bII',
 2: 'II',
 3: 'bIII',
 4: 'III',
 5: 'IV',
 6: '#IV',
 7: 'V',
...