MCPcopy Create free account
hub / github.com/bspaans/python-mingus / to_chords

Function to_chords

mingus/core/progressions.py:42–95  ·  view source on GitHub ↗

Convert a list of chord functions or a string to a list of chords. Examples: >>> to_chords(['I', 'V7']) [['C', 'E', 'G'], ['G', 'B', 'D', 'F']] >>> to_chords('I7') [['C', 'E', 'G', 'B']] Any number of accidentals can be used as prefix to augment or diminish; for example

(progression, key="C")

Source from the content-addressed store, hash-verified

40
41
42def to_chords(progression, key="C"):
43 """Convert a list of chord functions or a string to a list of chords.
44
45 Examples:
46 >>> to_chords(['I', 'V7'])
47 [['C', 'E', 'G'], ['G', 'B', 'D', 'F']]
48 >>> to_chords('I7')
49 [['C', 'E', 'G', 'B']]
50
51 Any number of accidentals can be used as prefix to augment or diminish;
52 for example: bIV or #I.
53
54 All the chord abbreviations in the chord module can be used as suffixes;
55 for example: Im7, IVdim7, etc.
56
57 You can combine prefixes and suffixes to manage complex progressions:
58 #vii7, #iidim7, iii7, etc.
59
60 Using 7 as suffix is ambiguous, since it is classicly used to denote the
61 seventh chord when talking about progressions instead of just the
62 dominant seventh chord. We have taken the classic route; I7 will get
63 you a major seventh chord. If you specifically want a dominanth seventh,
64 use Idom7.
65 """
66 if isinstance(progression, six.string_types):
67 progression = [progression]
68 result = []
69 for chord in progression:
70 # strip preceding accidentals from the string
71 (roman_numeral, acc, suffix) = parse_string(chord)
72
73 # There is no roman numeral parsing, just a simple check. Sorry to
74 # disappoint. warning Should throw exception
75 if roman_numeral not in numerals:
76 return []
77
78 # These suffixes don't need any post processing
79 if suffix == "7" or suffix == "":
80 roman_numeral += suffix
81
82 # ahh Python. Everything is a dict.
83 r = chords.__dict__[roman_numeral](key)
84 else:
85 r = chords.__dict__[roman_numeral](key)
86 r = chords.chord_shorthand[suffix](r[0])
87
88 while acc < 0:
89 r = [notes.diminish(x) for x in r]
90 acc += 1
91 while acc > 0:
92 r = [notes.augment(x) for x in r]
93 acc -= 1
94 result.append(r)
95 return result
96
97
98def determine(chord, key, shorthand=False):

Callers

nothing calls this directly

Calls 3

parse_stringFunction · 0.85
diminishMethod · 0.45
augmentMethod · 0.45

Tested by

no test coverage detected