def sevenths(key): """Return all the sevenths chords in key in a list.""" if _sevenths_cache.has_key(key): return _sevenths_cache[key] res = map(lambda x: seventh(x, key), keys.get_notes(key)) _sevenths_cache[key] = res return res
def triads(key): """Return all the triads in key. Implemented using a cache. """ if _triads_cache.has_key(key): return _triads_cache[key] res = map(lambda x: triad(x, key), keys.get_notes(key)) _triads_cache[key] = res return res
def interval(key, start_note, interval): """Return the note found at the interval starting from start_note in the given key. Raise a KeyError exception if start_note is not a valid note. Example: >>> interval('C', 'D', 1) 'E' """ if not notes.is_valid_note(start_note): raise KeyError("The start note '%s' is not a valid note" % start_note) notes_in_key = keys.get_notes(key) for n in notes_in_key: if n[0] == start_note[0]: index = notes_in_key.index(n) return notes_in_key[(index + interval) % 7]
def get_interval(note, interval, key='C'): """Return the note an interval (in half notes) away from the given note. This will produce mostly theoretical sound results, but you should use the minor and major functions to work around the corner cases. """ intervals = map(lambda x: (notes.note_to_int(key) + x) % 12, [ 0, 2, 4, 5, 7, 9, 11, ]) key_notes = keys.get_notes(key) for x in key_notes: if x[0] == note[0]: result = (intervals[key_notes.index(x)] + interval) % 12 if result in intervals: return key_notes[intervals.index(result)] + note[1:] else: return notes.diminish(key_notes[intervals.index((result + 1) % 12)] + note[1:])
def main(): print(chords.from_shorthand("Cm/G")) print(keys.get_notes("C"))