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

Function determine

mingus/core/progressions.py:98–212  ·  view source on GitHub ↗

Determine the harmonic function of chord in key. This function can also deal with lists of chords. Examples: >>> determine(['C', 'E', 'G'], 'C') ['tonic'] >>> determine(['G', 'B', 'D'], 'C') ['dominant'] >>> determine(['G', 'B', 'D', 'F'], 'C', True) ['V7'] >>>

(chord, key, shorthand=False)

Source from the content-addressed store, hash-verified

96
97
98def determine(chord, key, shorthand=False):
99 """Determine the harmonic function of chord in key.
100
101 This function can also deal with lists of chords.
102
103 Examples:
104 >>> determine(['C', 'E', 'G'], 'C')
105 ['tonic']
106 >>> determine(['G', 'B', 'D'], 'C')
107 ['dominant']
108 >>> determine(['G', 'B', 'D', 'F'], 'C', True)
109 ['V7']
110 >>> determine([['C', 'E', 'G'], ['G', 'B', 'D']], 'C', True)
111 [['I'], ['V']]
112 """
113 result = []
114
115 # Handle lists of chords
116 if isinstance(chord[0], list):
117 for c in chord:
118 result.append(determine(c, key, shorthand))
119 return result
120
121 func_dict = {
122 "I": "tonic",
123 "ii": "supertonic",
124 "iii": "mediant",
125 "IV": "subdominant",
126 "V": "dominant",
127 "vi": "submediant",
128 "vii": "subtonic",
129 }
130 expected_chord = [
131 ["I", "M", "M7"],
132 ["ii", "m", "m7"],
133 ["iii", "m", "m7"],
134 ["IV", "M", "M7"],
135 ["V", "M", "7"],
136 ["vi", "m", "m7"],
137 ["vii", "dim", "m7b5"],
138 ]
139 type_of_chord = chords.determine(chord, True, False, True)
140 for chord in type_of_chord:
141 name = chord[0]
142
143 # Get accidentals
144 a = 1
145 for n in chord[1:]:
146 if n == "b":
147 name += "b"
148 elif n == "#":
149 name += "#"
150 else:
151 break
152 a += 1
153 chord_type = chord[a:]
154
155 # Determine chord function

Callers

nothing calls this directly

Calls 1

determineMethod · 0.80

Tested by

no test coverage detected